X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Flto%2FLTOModule.cpp;h=18123460774157d259e4e9eb9b9766360d5ebcb4;hb=1c9cd021c8999d9c2c0786dff074d1e75bbd0eb2;hp=c5b3d10db71b2b85f3641f974fec5b436d0c99c1;hpb=5682527882aa3ddc74d0b283496fedd069a8e55d;p=oota-llvm.git diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index c5b3d10db71..18123460774 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -13,29 +13,30 @@ //===----------------------------------------------------------------------===// #include "LTOModule.h" -#include "llvm/Constants.h" -#include "llvm/LLVMContext.h" -#include "llvm/Module.h" +#include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/Triple.h" #include "llvm/Bitcode/ReaderWriter.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCParser/MCAsmParser.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCTargetAsmParser.h" #include "llvm/MC/SubtargetFeature.h" -#include "llvm/MC/MCParser/MCAsmParser.h" -#include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Host.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/system_error.h" -#include "llvm/ADT/OwningPtr.h" -#include "llvm/ADT/Triple.h" +#include "llvm/Target/TargetRegisterInfo.h" using namespace llvm; static cl::opt @@ -48,11 +49,6 @@ DisableFPElim("disable-fp-elim", cl::desc("Disable frame pointer elimination optimization"), cl::init(false)); -static cl::opt -DisableFPElimNonLeaf("disable-non-leaf-fp-elim", - cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"), - cl::init(false)); - static cl::opt EnableUnsafeFPMath("enable-unsafe-fp-math", cl::desc("Enable optimizations that may decrease FP precision"), @@ -125,11 +121,6 @@ OverrideStackAlignment("stack-alignment", cl::desc("Override default stack alignment"), cl::init(0)); -static cl::opt -EnableRealignStack("realign-stack", - cl::desc("Realign stack if needed"), - cl::init(true)); - static cl::opt TrapFuncName("trap-func", cl::Hidden, cl::desc("Emit a call to trap function rather than a trap instruction"), @@ -152,18 +143,21 @@ UseInitArray("use-init-array", LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t) : _module(m), _target(t), - _context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL), - _mangler(_context, *_target->getTargetData()) {} + _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL), + _mangler(_context, t) {} /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM /// bitcode. bool LTOModule::isBitcodeFile(const void *mem, size_t length) { - return llvm::sys::IdentifyFileType((char*)mem, length) - == llvm::sys::Bitcode_FileType; + return sys::fs::identify_magic(StringRef((const char *)mem, length)) == + sys::fs::file_magic::bitcode; } bool LTOModule::isBitcodeFile(const char *path) { - return llvm::sys::Path(path).isBitcodeFile(); + sys::fs::file_magic type; + if (sys::fs::identify_magic(path, type)) + return false; + return type == sys::fs::file_magic::bitcode; } /// isBitcodeFileForTarget - Returns 'true' if the file (or memory contents) is @@ -205,17 +199,16 @@ LTOModule *LTOModule::makeLTOModule(const char *path, std::string &errMsg) { LTOModule *LTOModule::makeLTOModule(int fd, const char *path, size_t size, std::string &errMsg) { - return makeLTOModule(fd, path, size, size, 0, errMsg); + return makeLTOModule(fd, path, size, 0, errMsg); } LTOModule *LTOModule::makeLTOModule(int fd, const char *path, - size_t file_size, size_t map_size, off_t offset, std::string &errMsg) { OwningPtr buffer; - if (error_code ec = MemoryBuffer::getOpenFile(fd, path, buffer, file_size, - map_size, offset, false)) { + if (error_code ec = + MemoryBuffer::getOpenFileSlice(fd, path, buffer, map_size, offset)) { errMsg = ec.message(); return NULL; } @@ -233,7 +226,6 @@ LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length, void LTOModule::getTargetOptions(TargetOptions &Options) { Options.LessPreciseFPMADOption = EnableFPMAD; Options.NoFramePointerElim = DisableFPElim; - Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf; Options.AllowFPOpFusion = FuseFPOps; Options.UnsafeFPMath = EnableUnsafeFPMath; Options.NoInfsFPMath = EnableNoInfsFPMath; @@ -247,7 +239,6 @@ void LTOModule::getTargetOptions(TargetOptions &Options) { Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt; Options.DisableTailCalls = DisableTailCalls; Options.StackAlignmentOverride = OverrideStackAlignment; - Options.RealignStack = EnableRealignStack; Options.TrapFuncName = TrapFuncName; Options.PositionIndependentExecutable = EnablePIE; Options.EnableSegmentedStacks = SegmentedStacks; @@ -272,23 +263,31 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, return NULL; } - std::string Triple = m->getTargetTriple(); - if (Triple.empty()) - Triple = sys::getDefaultTargetTriple(); + std::string TripleStr = m->getTargetTriple(); + if (TripleStr.empty()) + TripleStr = sys::getDefaultTargetTriple(); + llvm::Triple Triple(TripleStr); // find machine architecture for this module - const Target *march = TargetRegistry::lookupTarget(Triple, errMsg); + const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg); if (!march) return NULL; // construct LTOModule, hand over ownership of module and target SubtargetFeatures Features; - Features.getDefaultSubtargetFeatures(llvm::Triple(Triple)); + Features.getDefaultSubtargetFeatures(Triple); std::string FeatureStr = Features.getString(); + // Set a default CPU for Darwin triples. std::string CPU; + if (Triple.isOSDarwin()) { + if (Triple.getArch() == llvm::Triple::x86_64) + CPU = "core2"; + else if (Triple.getArch() == llvm::Triple::x86) + CPU = "yonah"; + } TargetOptions Options; getTargetOptions(Options); - TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr, + TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr, Options); LTOModule *Ret = new LTOModule(m.take(), target); if (Ret->parseSymbols(errMsg)) { @@ -301,13 +300,14 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, /// makeBuffer - Create a MemoryBuffer from a memory range. MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) { - const char *startPtr = (char*)mem; + const char *startPtr = (const char*)mem; return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false); } /// objcClassNameFromExpression - Get string that the data pointer points to. -bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) { - if (ConstantExpr *ce = dyn_cast(c)) { +bool +LTOModule::objcClassNameFromExpression(const Constant *c, std::string &name) { + if (const ConstantExpr *ce = dyn_cast(c)) { Constant *op = ce->getOperand(0); if (GlobalVariable *gvn = dyn_cast(op)) { Constant *cn = gvn->getInitializer(); @@ -323,8 +323,8 @@ bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) { } /// addObjCClass - Parse i386/ppc ObjC class data structure. -void LTOModule::addObjCClass(GlobalVariable *clgv) { - ConstantStruct *c = dyn_cast(clgv->getInitializer()); +void LTOModule::addObjCClass(const GlobalVariable *clgv) { + const ConstantStruct *c = dyn_cast(clgv->getInitializer()); if (!c) return; // second slot in __OBJC,__class is pointer to superclass name @@ -360,8 +360,8 @@ void LTOModule::addObjCClass(GlobalVariable *clgv) { } /// addObjCCategory - Parse i386/ppc ObjC category data structure. -void LTOModule::addObjCCategory(GlobalVariable *clgv) { - ConstantStruct *c = dyn_cast(clgv->getInitializer()); +void LTOModule::addObjCCategory(const GlobalVariable *clgv) { + const ConstantStruct *c = dyn_cast(clgv->getInitializer()); if (!c) return; // second slot in __OBJC,__category is pointer to target class name @@ -385,7 +385,7 @@ void LTOModule::addObjCCategory(GlobalVariable *clgv) { } /// addObjCClassRef - Parse i386/ppc ObjC class list data structure. -void LTOModule::addObjCClassRef(GlobalVariable *clgv) { +void LTOModule::addObjCClassRef(const GlobalVariable *clgv) { std::string targetclassName; if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) return; @@ -405,7 +405,7 @@ void LTOModule::addObjCClassRef(GlobalVariable *clgv) { } /// addDefinedDataSymbol - Add a data symbol as defined to the list. -void LTOModule::addDefinedDataSymbol(GlobalValue *v) { +void LTOModule::addDefinedDataSymbol(const GlobalValue *v) { // Add to list of defined symbols. addDefinedSymbol(v, false); @@ -434,34 +434,34 @@ void LTOModule::addDefinedDataSymbol(GlobalValue *v) { // special case if this data blob is an ObjC class definition if (v->getSection().compare(0, 15, "__OBJC,__class,") == 0) { - if (GlobalVariable *gv = dyn_cast(v)) { + if (const GlobalVariable *gv = dyn_cast(v)) { addObjCClass(gv); } } // special case if this data blob is an ObjC category definition else if (v->getSection().compare(0, 18, "__OBJC,__category,") == 0) { - if (GlobalVariable *gv = dyn_cast(v)) { + if (const GlobalVariable *gv = dyn_cast(v)) { addObjCCategory(gv); } } // special case if this data blob is the list of referenced classes else if (v->getSection().compare(0, 18, "__OBJC,__cls_refs,") == 0) { - if (GlobalVariable *gv = dyn_cast(v)) { + if (const GlobalVariable *gv = dyn_cast(v)) { addObjCClassRef(gv); } } } /// addDefinedFunctionSymbol - Add a function symbol as defined to the list. -void LTOModule::addDefinedFunctionSymbol(Function *f) { +void LTOModule::addDefinedFunctionSymbol(const Function *f) { // add to list of defined symbols addDefinedSymbol(f, true); } /// addDefinedSymbol - Add a defined symbol to the list. -void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) { +void LTOModule::addDefinedSymbol(const GlobalValue *def, bool isFunction) { // ignore all llvm.* symbols if (def->getName().startswith("llvm.")) return; @@ -472,13 +472,13 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) { // set alignment part log2() can have rounding errors uint32_t align = def->getAlignment(); - uint32_t attr = align ? CountTrailingZeros_32(def->getAlignment()) : 0; + uint32_t attr = align ? countTrailingZeros(def->getAlignment()) : 0; // set permissions part if (isFunction) { attr |= LTO_SYMBOL_PERMISSIONS_CODE; } else { - GlobalVariable *gv = dyn_cast(def); + const GlobalVariable *gv = dyn_cast(def); if (gv && gv->isConstant()) attr |= LTO_SYMBOL_PERMISSIONS_RODATA; else @@ -487,8 +487,7 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) { // set definition part if (def->hasWeakLinkage() || def->hasLinkOnceLinkage() || - def->hasLinkerPrivateWeakLinkage() || - def->hasLinkerPrivateWeakDefAutoLinkage()) + def->hasLinkerPrivateWeakLinkage()) attr |= LTO_SYMBOL_DEFINITION_WEAK; else if (def->hasCommonLinkage()) attr |= LTO_SYMBOL_DEFINITION_TENTATIVE; @@ -504,7 +503,7 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) { def->hasLinkOnceLinkage() || def->hasCommonLinkage() || def->hasLinkerPrivateWeakLinkage()) attr |= LTO_SYMBOL_SCOPE_DEFAULT; - else if (def->hasLinkerPrivateWeakDefAutoLinkage()) + else if (def->hasLinkOnceODRAutoHideLinkage()) attr |= LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN; else attr |= LTO_SYMBOL_SCOPE_INTERNAL; @@ -594,7 +593,8 @@ void LTOModule::addAsmGlobalSymbolUndef(const char *name) { /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet to a /// list to be resolved later. -void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, bool isFunc) { +void +LTOModule::addPotentialUndefinedSymbol(const GlobalValue *decl, bool isFunc) { // ignore all llvm.* symbols if (decl->getName().startswith("llvm.")) return; @@ -718,7 +718,8 @@ namespace { return Symbols.end(); } - RecordStreamer(MCContext &Context) : MCStreamer(Context) {} + RecordStreamer(MCContext &Context) + : MCStreamer(SK_RecordStreamer, Context) {} virtual void EmitInstruction(const MCInst &Inst) { // Scan for values. @@ -727,16 +728,20 @@ namespace { AddValueSymbols(Inst.getOperand(i).getExpr()); } virtual void EmitLabel(MCSymbol *Symbol) { - Symbol->setSection(*getCurrentSection()); + Symbol->setSection(*getCurrentSection().first); markDefined(*Symbol); } + virtual void EmitDebugLabel(MCSymbol *Symbol) { + EmitLabel(Symbol); + } virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { // FIXME: should we handle aliases? markDefined(*Symbol); } - virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) { + virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) { if (Attribute == MCSA_Global) markGlobal(*Symbol); + return true; } virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol, uint64_t Size , unsigned ByteAlignment) { @@ -747,8 +752,14 @@ namespace { markDefined(*Symbol); } + virtual void EmitBundleAlignMode(unsigned AlignPow2) {} + virtual void EmitBundleLock(bool AlignToEnd) {} + virtual void EmitBundleUnlock() {} + // Noop calls. - virtual void ChangeSection(const MCSection *Section) {} + virtual void ChangeSection(const MCSection *Section, + const MCExpr *Subsection) {} + virtual void InitToTextSection() {} virtual void InitSections() {} virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {} virtual void EmitThumbFunc(MCSymbol *Func) {} @@ -763,9 +774,8 @@ namespace { unsigned ByteAlignment) {} virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) {} - virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {} - virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, - unsigned AddrSpace) {} + virtual void EmitBytes(StringRef Data) {} + virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) {} virtual void EmitULEB128Value(const MCExpr *Value) {} virtual void EmitSLEB128Value(const MCExpr *Value) {} virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value, @@ -781,6 +791,10 @@ namespace { const MCSymbol *Label, unsigned PointerSize) {} virtual void FinishImpl() {} + + static bool classof(const MCStreamer *S) { + return S->getKind() == SK_RecordStreamer; + } }; } // end anonymous namespace