diff options
author | Stephen Hines <srhines@google.com> | 2014-04-23 16:57:46 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-04-24 15:53:16 -0700 |
commit | 36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch) | |
tree | e6cfb69fbbd937f450eeb83bfb83b9da3b01275a /lib/LTO | |
parent | 69a8640022b04415ae9fac62f8ab090601d8f889 (diff) | |
download | external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2 |
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
Diffstat (limited to 'lib/LTO')
-rw-r--r-- | lib/LTO/LLVMBuild.txt | 2 | ||||
-rw-r--r-- | lib/LTO/LTOCodeGenerator.cpp | 98 | ||||
-rw-r--r-- | lib/LTO/LTOModule.cpp | 224 |
3 files changed, 220 insertions, 104 deletions
diff --git a/lib/LTO/LLVMBuild.txt b/lib/LTO/LLVMBuild.txt index 38c1170..c9b5212 100644 --- a/lib/LTO/LLVMBuild.txt +++ b/lib/LTO/LLVMBuild.txt @@ -19,4 +19,4 @@ type = Library name = LTO parent = Libraries -required_libraries = Analysis BitReader BitWriter Core IPO Linker MC MCParser Scalar Support Target Vectorize
\ No newline at end of file +required_libraries = BitReader BitWriter Core IPA IPO InstCombine Linker MC MCParser ObjCARC Scalar Support Target TransformUtils diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 2b3648e..51d0899 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -13,20 +13,23 @@ //===----------------------------------------------------------------------===// #include "llvm/LTO/LTOCodeGenerator.h" -#include "llvm/LTO/LTOModule.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Analysis/Passes.h" -#include "llvm/Analysis/Verifier.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/CodeGen/RuntimeLibcalls.h" #include "llvm/Config/config.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/DiagnosticInfo.h" +#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Verifier.h" #include "llvm/InitializePasses.h" -#include "llvm/Linker.h" +#include "llvm/LTO/LTOModule.h" +#include "llvm/Linker/Linker.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/SubtargetFeature.h" @@ -40,12 +43,12 @@ #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/system_error.h" #include "llvm/Target/TargetLibraryInfo.h" #include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetRegisterInfo.h" -#include "llvm/Target/Mangler.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/ObjCARC.h" @@ -62,7 +65,8 @@ const char* LTOCodeGenerator::getVersionString() { LTOCodeGenerator::LTOCodeGenerator() : Context(getGlobalContext()), Linker(new Module("ld-temp.o", Context)), TargetMach(NULL), EmitDwarfDebugInfo(false), ScopeRestrictionsDone(false), - CodeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), NativeObjectFile(NULL) { + CodeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), NativeObjectFile(NULL), + DiagHandler(NULL), DiagContext(NULL) { initializeLTOPasses(); } @@ -82,8 +86,7 @@ LTOCodeGenerator::~LTOCodeGenerator() { // Initialize LTO passes. Please keep this funciton in sync with // PassManagerBuilder::populateLTOPassManager(), and make sure all LTO -// passes are initialized. -// +// passes are initialized. void LTOCodeGenerator::initializeLTOPasses() { PassRegistry &R = *PassRegistry::getPassRegistry(); @@ -175,7 +178,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, // create output file std::string ErrInfo; - tool_output_file Out(path, ErrInfo, sys::fs::F_Binary); + tool_output_file Out(path, ErrInfo, sys::fs::F_None); if (!ErrInfo.empty()) { errMsg = "could not open bitcode file for writing: "; errMsg += path; @@ -197,7 +200,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, return true; } -bool LTOCodeGenerator::compile_to_file(const char** name, +bool LTOCodeGenerator::compile_to_file(const char** name, bool disableOpt, bool disableInline, bool disableGVNLoadPRE, @@ -248,13 +251,13 @@ const void* LTOCodeGenerator::compile(size_t* length, delete NativeObjectFile; // read .o file into memory buffer - OwningPtr<MemoryBuffer> BuffPtr; + std::unique_ptr<MemoryBuffer> BuffPtr; if (error_code ec = MemoryBuffer::getFile(name, BuffPtr, -1, false)) { errMsg = ec.message(); sys::fs::remove(NativeObjectPath); return NULL; } - NativeObjectFile = BuffPtr.take(); + NativeObjectFile = BuffPtr.release(); // remove temp files sys::fs::remove(NativeObjectPath); @@ -305,6 +308,8 @@ bool LTOCodeGenerator::determineTarget(std::string &errMsg) { MCpu = "core2"; else if (Triple.getArch() == llvm::Triple::x86) MCpu = "yonah"; + else if (Triple.getArch() == llvm::Triple::arm64) + MCpu = "cyclone"; } TargetMach = march->createTargetMachine(TripleStr, MCpu, FeatureStr, Options, @@ -319,11 +324,17 @@ applyRestriction(GlobalValue &GV, std::vector<const char*> &MustPreserveList, SmallPtrSet<GlobalValue*, 8> &AsmUsed, Mangler &Mangler) { - SmallString<64> Buffer; - Mangler.getNameWithPrefix(Buffer, &GV, false); - + // There are no restrictions to apply to declarations. if (GV.isDeclaration()) return; + + // There is nothing more restrictive than private linkage. + if (GV.hasPrivateLinkage()) + return; + + SmallString<64> Buffer; + TargetMach->getNameWithPrefix(Buffer, &GV, Mangler); + if (MustPreserveSymbols.count(Buffer)) MustPreserveList.push_back(GV.getName().data()); if (AsmUndefinedRefs.count(Buffer)) @@ -387,7 +398,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { passes.add(createVerifierPass()); // mark which symbols can not be internalized - Mangler Mangler(TargetMach); + Mangler Mangler(TargetMach->getDataLayout()); std::vector<const char*> MustPreserveList; SmallPtrSet<GlobalValue*, 8> AsmUsed; std::vector<StringRef> Libcalls; @@ -459,7 +470,12 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, passes.add(createVerifierPass()); // Add an appropriate DataLayout instance for this module... - passes.add(new DataLayout(*TargetMach->getDataLayout())); + mergedModule->setDataLayout(TargetMach->getDataLayout()); + passes.add(new DataLayoutPass(mergedModule)); + + // Add appropriate TargetLibraryInfo for this module. + passes.add(new TargetLibraryInfo(Triple(TargetMach->getTargetTriple()))); + TargetMach->addAnalysisPasses(passes); // Enabling internalize here would use its AllButMain variant. It @@ -476,8 +492,7 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, PassManager codeGenPasses; - codeGenPasses.add(new DataLayout(*TargetMach->getDataLayout())); - TargetMach->addAnalysisPasses(codeGenPasses); + codeGenPasses.add(new DataLayoutPass(mergedModule)); formatted_raw_ostream Out(out); @@ -519,3 +534,50 @@ void LTOCodeGenerator::parseCodeGenDebugOptions() { cl::ParseCommandLineOptions(CodegenOptions.size(), const_cast<char **>(&CodegenOptions[0])); } + +void LTOCodeGenerator::DiagnosticHandler(const DiagnosticInfo &DI, + void *Context) { + ((LTOCodeGenerator *)Context)->DiagnosticHandler2(DI); +} + +void LTOCodeGenerator::DiagnosticHandler2(const DiagnosticInfo &DI) { + // Map the LLVM internal diagnostic severity to the LTO diagnostic severity. + lto_codegen_diagnostic_severity_t Severity; + switch (DI.getSeverity()) { + case DS_Error: + Severity = LTO_DS_ERROR; + break; + case DS_Warning: + Severity = LTO_DS_WARNING; + break; + case DS_Remark: + Severity = LTO_DS_REMARK; + break; + case DS_Note: + Severity = LTO_DS_NOTE; + break; + } + // Create the string that will be reported to the external diagnostic handler. + std::string MsgStorage; + raw_string_ostream Stream(MsgStorage); + DiagnosticPrinterRawOStream DP(Stream); + DI.print(DP); + Stream.flush(); + + // If this method has been called it means someone has set up an external + // diagnostic handler. Assert on that. + assert(DiagHandler && "Invalid diagnostic handler"); + (*DiagHandler)(Severity, MsgStorage.c_str(), DiagContext); +} + +void +LTOCodeGenerator::setDiagnosticHandler(lto_diagnostic_handler_t DiagHandler, + void *Ctxt) { + this->DiagHandler = DiagHandler; + this->DiagContext = Ctxt; + if (!DiagHandler) + return Context.setDiagnosticHandler(NULL, NULL); + // Register the LTOCodeGenerator stub in the LLVMContext to forward the + // diagnostic to the external DiagHandler. + Context.setDiagnosticHandler(LTOCodeGenerator::DiagnosticHandler, this); +} diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp index 65416be..567da04 100644 --- a/lib/LTO/LTOModule.cpp +++ b/lib/LTO/LTOModule.cpp @@ -13,38 +13,45 @@ //===----------------------------------------------------------------------===// #include "llvm/LTO/LTOModule.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/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCParser/MCAsmParser.h" +#include "llvm/MC/MCSection.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/Support/CommandLine.h" -#include "llvm/Support/Host.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Host.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/Target/TargetLowering.h" +#include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Transforms/Utils/GlobalStatus.h" using namespace llvm; LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t) : _module(m), _target(t), - _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL), - _mangler(t) {} + _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), &ObjFileInfo), + _mangler(t->getDataLayout()) { + ObjFileInfo.InitMCObjectFileInfo(t->getTargetTriple(), + t->getRelocationModel(), t->getCodeModel(), + _context); +} /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM /// bitcode. @@ -72,10 +79,10 @@ bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length, bool LTOModule::isBitcodeFileForTarget(const char *path, const char *triplePrefix) { - OwningPtr<MemoryBuffer> buffer; + std::unique_ptr<MemoryBuffer> buffer; if (MemoryBuffer::getFile(path, buffer)) return false; - return isTargetMatch(buffer.take(), triplePrefix); + return isTargetMatch(buffer.release(), triplePrefix); } /// isTargetMatch - Returns 'true' if the memory buffer is for the specified @@ -90,12 +97,12 @@ bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) { /// the buffer. LTOModule *LTOModule::makeLTOModule(const char *path, TargetOptions options, std::string &errMsg) { - OwningPtr<MemoryBuffer> buffer; + std::unique_ptr<MemoryBuffer> buffer; if (error_code ec = MemoryBuffer::getFile(path, buffer)) { errMsg = ec.message(); return NULL; } - return makeLTOModule(buffer.take(), options, errMsg); + return makeLTOModule(buffer.release(), options, errMsg); } LTOModule *LTOModule::makeLTOModule(int fd, const char *path, @@ -109,34 +116,36 @@ LTOModule *LTOModule::makeLTOModule(int fd, const char *path, off_t offset, TargetOptions options, std::string &errMsg) { - OwningPtr<MemoryBuffer> buffer; + std::unique_ptr<MemoryBuffer> buffer; if (error_code ec = MemoryBuffer::getOpenFileSlice(fd, path, buffer, map_size, offset)) { errMsg = ec.message(); return NULL; } - return makeLTOModule(buffer.take(), options, errMsg); + return makeLTOModule(buffer.release(), options, errMsg); } LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length, TargetOptions options, - std::string &errMsg) { - OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length)); + std::string &errMsg, StringRef path) { + std::unique_ptr<MemoryBuffer> buffer(makeBuffer(mem, length, path)); if (!buffer) return NULL; - return makeLTOModule(buffer.take(), options, errMsg); + return makeLTOModule(buffer.release(), options, errMsg); } LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, TargetOptions options, std::string &errMsg) { // parse bitcode buffer - OwningPtr<Module> m(getLazyBitcodeModule(buffer, getGlobalContext(), - &errMsg)); - if (!m) { + ErrorOr<Module *> ModuleOrErr = + getLazyBitcodeModule(buffer, getGlobalContext()); + if (error_code EC = ModuleOrErr.getError()) { + errMsg = EC.message(); delete buffer; return NULL; } + std::unique_ptr<Module> m(ModuleOrErr.get()); std::string TripleStr = m->getTargetTriple(); if (TripleStr.empty()) @@ -159,25 +168,40 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, CPU = "core2"; else if (Triple.getArch() == llvm::Triple::x86) CPU = "yonah"; + else if (Triple.getArch() == llvm::Triple::arm64) + CPU = "cyclone"; } TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr, options); - m->MaterializeAllPermanently(); + m->materializeAllPermanently(); + + LTOModule *Ret = new LTOModule(m.release(), target); + + // We need a MCContext set up in order to get mangled names of private + // symbols. It is a bit odd that we need to report uses and definitions + // of private symbols, but it does look like ld64 expects to be informed + // of at least the ones with an 'l' prefix. + MCContext &Context = Ret->_context; + const TargetLoweringObjectFile &TLOF = + target->getTargetLowering()->getObjFileLowering(); + const_cast<TargetLoweringObjectFile &>(TLOF).Initialize(Context, *target); - LTOModule *Ret = new LTOModule(m.take(), target); if (Ret->parseSymbols(errMsg)) { delete Ret; return NULL; } + Ret->parseMetadata(); + return Ret; } -/// makeBuffer - Create a MemoryBuffer from a memory range. -MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) { +/// Create a MemoryBuffer from a memory range with an optional name. +MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length, + StringRef name) { const char *startPtr = (const char*)mem; - return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false); + return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), name, false); } /// objcClassNameFromExpression - Get string that the data pointer points to. @@ -337,6 +361,7 @@ void LTOModule::addDefinedFunctionSymbol(const Function *f) { } static bool canBeHidden(const GlobalValue *GV) { + // FIXME: this is duplicated with another static function in AsmPrinter.cpp GlobalValue::LinkageTypes L = GV->getLinkage(); if (L != GlobalValue::LinkOnceODRLinkage) @@ -345,6 +370,13 @@ static bool canBeHidden(const GlobalValue *GV) { if (GV->hasUnnamedAddr()) return true; + // If it is a non constant variable, it needs to be uniqued across shared + // objects. + if (const GlobalVariable *Var = dyn_cast<GlobalVariable>(GV)) { + if (!Var->isConstant()) + return false; + } + GlobalStatus GS; if (GlobalStatus::analyzeGlobal(GV, GS)) return false; @@ -360,7 +392,7 @@ void LTOModule::addDefinedSymbol(const GlobalValue *def, bool isFunction) { // string is owned by _defines SmallString<64> Buffer; - _mangler.getNameWithPrefix(Buffer, def, false); + _target->getNameWithPrefix(Buffer, def, _mangler); // set alignment part log2() can have rounding errors uint32_t align = def->getAlignment(); @@ -378,8 +410,7 @@ void LTOModule::addDefinedSymbol(const GlobalValue *def, bool isFunction) { } // set definition part - if (def->hasWeakLinkage() || def->hasLinkOnceLinkage() || - def->hasLinkerPrivateWeakLinkage()) + if (def->hasWeakLinkage() || def->hasLinkOnceLinkage()) attr |= LTO_SYMBOL_DEFINITION_WEAK; else if (def->hasCommonLinkage()) attr |= LTO_SYMBOL_DEFINITION_TENTATIVE; @@ -394,8 +425,7 @@ void LTOModule::addDefinedSymbol(const GlobalValue *def, bool isFunction) { else if (canBeHidden(def)) attr |= LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN; else if (def->hasExternalLinkage() || def->hasWeakLinkage() || - def->hasLinkOnceLinkage() || def->hasCommonLinkage() || - def->hasLinkerPrivateWeakLinkage()) + def->hasLinkOnceLinkage() || def->hasCommonLinkage()) attr |= LTO_SYMBOL_SCOPE_DEFAULT; else attr |= LTO_SYMBOL_SCOPE_INTERNAL; @@ -496,7 +526,7 @@ LTOModule::addPotentialUndefinedSymbol(const GlobalValue *decl, bool isFunc) { return; SmallString<64> name; - _mangler.getNameWithPrefix(name, decl, false); + _target->getNameWithPrefix(name, decl, _mangler); StringMap<NameAndAttributes>::value_type &entry = _undefines.GetOrCreateValue(name); @@ -521,6 +551,7 @@ LTOModule::addPotentialUndefinedSymbol(const GlobalValue *decl, bool isFunc) { } namespace { + class RecordStreamer : public MCStreamer { public: enum State { NeverSeen, Global, Defined, DefinedGlobal, Used }; @@ -610,79 +641,79 @@ namespace { return Symbols.end(); } - RecordStreamer(MCContext &Context) : MCStreamer(Context, 0) {} + RecordStreamer(MCContext &Context) : MCStreamer(Context) {} - virtual void EmitInstruction(const MCInst &Inst) { + void EmitInstruction(const MCInst &Inst, + const MCSubtargetInfo &STI) override { // Scan for values. for (unsigned i = Inst.getNumOperands(); i--; ) if (Inst.getOperand(i).isExpr()) AddValueSymbols(Inst.getOperand(i).getExpr()); } - virtual void EmitLabel(MCSymbol *Symbol) { + void EmitLabel(MCSymbol *Symbol) override { Symbol->setSection(*getCurrentSection().first); markDefined(*Symbol); } - virtual void EmitDebugLabel(MCSymbol *Symbol) { + void EmitDebugLabel(MCSymbol *Symbol) override { EmitLabel(Symbol); } - virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { + void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override { // FIXME: should we handle aliases? markDefined(*Symbol); + AddValueSymbols(Value); } - virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) { + bool EmitSymbolAttribute(MCSymbol *Symbol, + MCSymbolAttr Attribute) override { if (Attribute == MCSA_Global) markGlobal(*Symbol); return true; } - virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol, - uint64_t Size , unsigned ByteAlignment) { + void EmitZerofill(const MCSection *Section, MCSymbol *Symbol, + uint64_t Size , unsigned ByteAlignment) override { markDefined(*Symbol); } - virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment) { + void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, + unsigned ByteAlignment) override { markDefined(*Symbol); } - virtual void EmitBundleAlignMode(unsigned AlignPow2) {} - virtual void EmitBundleLock(bool AlignToEnd) {} - virtual void EmitBundleUnlock() {} + void EmitBundleAlignMode(unsigned AlignPow2) override {} + void EmitBundleLock(bool AlignToEnd) override {} + void EmitBundleUnlock() override {} // Noop calls. - 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) {} - virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {} - virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {} - virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {} - virtual void EmitCOFFSymbolStorageClass(int StorageClass) {} - virtual void EmitCOFFSymbolType(int Type) {} - virtual void EndCOFFSymbolDef() {} - virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {} - virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment) {} - virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, - uint64_t Size, unsigned ByteAlignment) {} - 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, - unsigned ValueSize, - unsigned MaxBytesToEmit) {} - virtual void EmitCodeAlignment(unsigned ByteAlignment, - unsigned MaxBytesToEmit) {} - virtual bool EmitValueToOffset(const MCExpr *Offset, - unsigned char Value ) { return false; } - virtual void EmitFileDirective(StringRef Filename) {} - virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta, - const MCSymbol *LastLabel, - const MCSymbol *Label, - unsigned PointerSize) {} - virtual void FinishImpl() {} - virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) { + void ChangeSection(const MCSection *Section, + const MCExpr *Subsection) override {} + void EmitAssemblerFlag(MCAssemblerFlag Flag) override {} + void EmitThumbFunc(MCSymbol *Func) override {} + void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override {} + void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override {} + void BeginCOFFSymbolDef(const MCSymbol *Symbol) override {} + void EmitCOFFSymbolStorageClass(int StorageClass) override {} + void EmitCOFFSymbolType(int Type) override {} + void EndCOFFSymbolDef() override {} + void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override {} + void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, + unsigned ByteAlignment) override {} + void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, + uint64_t Size, unsigned ByteAlignment) override {} + void EmitBytes(StringRef Data) override {} + void EmitValueImpl(const MCExpr *Value, unsigned Size) override {} + void EmitULEB128Value(const MCExpr *Value) override {} + void EmitSLEB128Value(const MCExpr *Value) override {} + void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value, + unsigned ValueSize, + unsigned MaxBytesToEmit) override {} + void EmitCodeAlignment(unsigned ByteAlignment, + unsigned MaxBytesToEmit) override {} + bool EmitValueToOffset(const MCExpr *Offset, + unsigned char Value) override { return false; } + void EmitFileDirective(StringRef Filename) override {} + void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, + const MCSymbol *Label, + unsigned PointerSize) override {} + void FinishImpl() override {} + void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override { RecordProcEnd(Frame); } }; @@ -695,20 +726,19 @@ bool LTOModule::addAsmGlobalSymbols(std::string &errMsg) { if (inlineAsm.empty()) return false; - OwningPtr<RecordStreamer> Streamer(new RecordStreamer(_context)); + std::unique_ptr<RecordStreamer> Streamer(new RecordStreamer(_context)); MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(inlineAsm); SourceMgr SrcMgr; SrcMgr.AddNewSourceBuffer(Buffer, SMLoc()); - OwningPtr<MCAsmParser> Parser(createMCAsmParser(SrcMgr, - _context, *Streamer, - *_target->getMCAsmInfo())); + std::unique_ptr<MCAsmParser> Parser( + createMCAsmParser(SrcMgr, _context, *Streamer, *_target->getMCAsmInfo())); const Target &T = _target->getTarget(); - OwningPtr<MCInstrInfo> MCII(T.createMCInstrInfo()); - OwningPtr<MCSubtargetInfo> - STI(T.createMCSubtargetInfo(_target->getTargetTriple(), - _target->getTargetCPU(), - _target->getTargetFeatureString())); - OwningPtr<MCTargetAsmParser> TAP(T.createMCAsmParser(*STI, *Parser.get(), *MCII)); + std::unique_ptr<MCInstrInfo> MCII(T.createMCInstrInfo()); + std::unique_ptr<MCSubtargetInfo> STI(T.createMCSubtargetInfo( + _target->getTargetTriple(), _target->getTargetCPU(), + _target->getTargetFeatureString())); + std::unique_ptr<MCTargetAsmParser> TAP( + T.createMCAsmParser(*STI, *Parser.get(), *MCII)); if (!TAP) { errMsg = "target " + std::string(T.getName()) + " does not define AsmParser."; @@ -792,3 +822,27 @@ bool LTOModule::parseSymbols(std::string &errMsg) { return false; } + +/// parseMetadata - Parse metadata from the module +void LTOModule::parseMetadata() { + // Linker Options + if (Value *Val = _module->getModuleFlag("Linker Options")) { + MDNode *LinkerOptions = cast<MDNode>(Val); + for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) { + MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i)); + for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) { + MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii)); + StringRef Op = _linkeropt_strings. + GetOrCreateValue(MDOption->getString()).getKey(); + StringRef DepLibName = _target->getTargetLowering()-> + getObjFileLowering().getDepLibFromLinkerOpt(Op); + if (!DepLibName.empty()) + _deplibs.push_back(DepLibName.data()); + else if (!Op.empty()) + _linkeropts.push_back(Op.data()); + } + } + } + + // Add other interesting metadata here. +} |