X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FLTO%2FLTOModule.cpp;h=53ed4175f8e35463e9826858ff84efdf5046a6d8;hb=26be2142324893e254ec9ba91da3a54694936498;hp=49aa97d532ec2b007ad42bfbcfc2d1fda8129b92;hpb=cd67bbf07f2af4fc745e492cbd31f5849f289a53;p=oota-llvm.git diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp index 49aa97d532e..53ed4175f8e 100644 --- a/lib/LTO/LTOModule.cpp +++ b/lib/LTO/LTOModule.cpp @@ -19,6 +19,7 @@ #include "llvm/IR/Constants.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Mangler.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/MC/MCExpr.h" @@ -147,9 +148,10 @@ LTOModule *LTOModule::createInContext(const void *mem, size_t length, return makeLTOModule(Buffer, options, errMsg, Context); } -static Module *parseBitcodeFileImpl(MemoryBufferRef Buffer, - LLVMContext &Context, bool ShouldBeLazy, - std::string &ErrMsg) { +static std::unique_ptr parseBitcodeFileImpl(MemoryBufferRef Buffer, + LLVMContext &Context, + bool ShouldBeLazy, + std::string &ErrMsg) { // Find the buffer. ErrorOr MBOrErr = @@ -168,22 +170,22 @@ static Module *parseBitcodeFileImpl(MemoryBufferRef Buffer, if (!ShouldBeLazy) { // Parse the full file. - ErrorOr M = + ErrorOr> M = parseBitcodeFile(*MBOrErr, Context, DiagnosticHandler); if (!M) return nullptr; - return *M; + return std::move(*M); } // Parse lazily. std::unique_ptr LightweightBuf = MemoryBuffer::getMemBuffer(*MBOrErr, false); - ErrorOr M = getLazyBitcodeModule(std::move(LightweightBuf), Context, - DiagnosticHandler, - true/*ShouldLazyLoadMetadata*/); + ErrorOr> M = + getLazyBitcodeModule(std::move(LightweightBuf), Context, + DiagnosticHandler, true /*ShouldLazyLoadMetadata*/); if (!M) return nullptr; - return *M; + return std::move(*M); } LTOModule *LTOModule::makeLTOModule(MemoryBufferRef Buffer, @@ -197,9 +199,9 @@ LTOModule *LTOModule::makeLTOModule(MemoryBufferRef Buffer, // If we own a context, we know this is being used only for symbol // extraction, not linking. Be lazy in that case. - std::unique_ptr M(parseBitcodeFileImpl( + std::unique_ptr M = parseBitcodeFileImpl( Buffer, *Context, - /* ShouldBeLazy */ static_cast(OwnedContext), errMsg)); + /* ShouldBeLazy */ static_cast(OwnedContext), errMsg); if (!M) return nullptr; @@ -267,7 +269,7 @@ LTOModule::objcClassNameFromExpression(const Constant *c, std::string &name) { Constant *cn = gvn->getInitializer(); if (ConstantDataArray *ca = dyn_cast(cn)) { if (ca->isCString()) { - name = ".objc_class_name_" + ca->getAsCString().str(); + name = (".objc_class_name_" + ca->getAsCString()).str(); return true; } } @@ -468,6 +470,12 @@ void LTOModule::addDefinedSymbol(const char *Name, const GlobalValue *def, else attr |= LTO_SYMBOL_SCOPE_DEFAULT; + if (def->hasComdat()) + attr |= LTO_SYMBOL_COMDAT; + + if (isa(def)) + attr |= LTO_SYMBOL_ALIAS; + auto Iter = _defines.insert(Name).first; // fill information structure @@ -638,6 +646,8 @@ bool LTOModule::parseSymbols(std::string &errMsg) { /// parseMetadata - Parse metadata from the module void LTOModule::parseMetadata() { + raw_string_ostream OS(LinkerOpts); + // Linker Options if (Metadata *Val = getModule().getModuleFlag("Linker Options")) { MDNode *LinkerOptions = cast(Val); @@ -645,20 +655,19 @@ void LTOModule::parseMetadata() { MDNode *MDOptions = cast(LinkerOptions->getOperand(i)); for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) { MDString *MDOption = cast(MDOptions->getOperand(ii)); - // FIXME: Make StringSet::insert match Self-Associative Container - // requirements, returning rather than bool, and use that - // here. - StringRef Op = - _linkeropt_strings.insert(MDOption->getString()).first->first(); - StringRef DepLibName = - _target->getObjFileLowering()->getDepLibFromLinkerOpt(Op); - if (!DepLibName.empty()) - _deplibs.push_back(DepLibName.data()); - else if (!Op.empty()) - _linkeropts.push_back(Op.data()); + OS << " " << MDOption->getString(); } } } + // Globals + Mangler Mang; + for (const NameAndAttributes &Sym : _symbols) { + if (!Sym.symbol) + continue; + _target->getObjFileLowering()->emitLinkerFlagsForGlobal(OS, Sym.symbol, + Mang); + } + // Add other interesting metadata here. }