Index: llvm/trunk/include/llvm/LTO/legacy/LTOModule.h =================================================================== --- llvm/trunk/include/llvm/LTO/legacy/LTOModule.h +++ llvm/trunk/include/llvm/LTO/legacy/LTOModule.h @@ -19,6 +19,7 @@ #include "llvm/ADT/StringSet.h" #include "llvm/IR/Module.h" #include "llvm/Object/IRObjectFile.h" +#include "llvm/Object/ModuleSymbolTable.h" #include "llvm/Target/TargetMachine.h" #include #include @@ -47,7 +48,9 @@ std::string LinkerOpts; - std::unique_ptr IRFile; + std::unique_ptr Mod; + MemoryBufferRef MBRef; + ModuleSymbolTable SymTab; std::unique_ptr _target; std::vector _symbols; @@ -56,7 +59,8 @@ StringMap _undefines; std::vector _asm_undefines; - LTOModule(std::unique_ptr Obj, TargetMachine *TM); + LTOModule(std::unique_ptr M, MemoryBufferRef MBRef, + TargetMachine *TM); public: ~LTOModule(); @@ -108,14 +112,10 @@ size_t length, const TargetOptions &options, StringRef path); - const Module &getModule() const { - return const_cast(this)->getModule(); - } - Module &getModule() { - return IRFile->getModule(); - } + const Module &getModule() const { return *Mod; } + Module &getModule() { return *Mod; } - std::unique_ptr takeModule() { return IRFile->takeModule(); } + std::unique_ptr takeModule() { return std::move(Mod); } /// Return the Module's target triple. const std::string &getTargetTriple() { @@ -166,7 +166,7 @@ void parseSymbols(); /// Add a symbol which isn't defined just yet to a list to be resolved later. - void addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym, + void addPotentialUndefinedSymbol(ModuleSymbolTable::Symbol Sym, bool isFunc); /// Add a defined symbol to the list. @@ -174,11 +174,11 @@ bool isFunction); /// Add a data symbol as defined to the list. - void addDefinedDataSymbol(const object::BasicSymbolRef &Sym); + void addDefinedDataSymbol(ModuleSymbolTable::Symbol Sym); void addDefinedDataSymbol(StringRef Name, const GlobalValue *v); /// Add a function symbol as defined to the list. - void addDefinedFunctionSymbol(const object::BasicSymbolRef &Sym); + void addDefinedFunctionSymbol(ModuleSymbolTable::Symbol Sym); void addDefinedFunctionSymbol(StringRef Name, const Function *F); /// Add a global symbol from module-level ASM to the defined list. Index: llvm/trunk/lib/LTO/LTOModule.cpp =================================================================== --- llvm/trunk/lib/LTO/LTOModule.cpp +++ llvm/trunk/lib/LTO/LTOModule.cpp @@ -48,9 +48,11 @@ using namespace llvm; using namespace llvm::object; -LTOModule::LTOModule(std::unique_ptr Obj, +LTOModule::LTOModule(std::unique_ptr M, MemoryBufferRef MBRef, llvm::TargetMachine *TM) - : IRFile(std::move(Obj)), _target(TM) {} + : Mod(std::move(M)), MBRef(MBRef), _target(TM) { + SymTab.addModule(Mod.get()); +} LTOModule::~LTOModule() {} @@ -76,7 +78,7 @@ bool LTOModule::isThinLTO() { // Right now the detection is only based on the summary presence. We may want // to add a dedicated flag at some point. - Expected Result = hasGlobalValueSummary(IRFile->getMemoryBufferRef()); + Expected Result = hasGlobalValueSummary(MBRef); if (!Result) { logAllUnhandledErrors(Result.takeError(), errs(), ""); return false; @@ -233,10 +235,7 @@ march->createTargetMachine(TripleStr, CPU, FeatureStr, options, None); M->setDataLayout(target->createDataLayout()); - std::unique_ptr IRObj( - new object::IRObjectFile(Buffer, std::move(M))); - - std::unique_ptr Ret(new LTOModule(std::move(IRObj), target)); + std::unique_ptr Ret(new LTOModule(std::move(M), Buffer, target)); Ret->parseSymbols(); Ret->parseMetadata(); @@ -344,15 +343,15 @@ info.symbol = clgv; } -void LTOModule::addDefinedDataSymbol(const object::BasicSymbolRef &Sym) { +void LTOModule::addDefinedDataSymbol(ModuleSymbolTable::Symbol Sym) { SmallString<64> Buffer; { raw_svector_ostream OS(Buffer); - Sym.printName(OS); + SymTab.printSymbolName(OS, Sym); Buffer.c_str(); } - const GlobalValue *V = IRFile->getSymbolGV(Sym.getRawDataRefImpl()); + const GlobalValue *V = Sym.get(); addDefinedDataSymbol(Buffer, V); } @@ -406,16 +405,15 @@ } } -void LTOModule::addDefinedFunctionSymbol(const object::BasicSymbolRef &Sym) { +void LTOModule::addDefinedFunctionSymbol(ModuleSymbolTable::Symbol Sym) { SmallString<64> Buffer; { raw_svector_ostream OS(Buffer); - Sym.printName(OS); + SymTab.printSymbolName(OS, Sym); Buffer.c_str(); } - const Function *F = - cast(IRFile->getSymbolGV(Sym.getRawDataRefImpl())); + const Function *F = cast(Sym.get()); addDefinedFunctionSymbol(Buffer, F); } @@ -546,12 +544,12 @@ } /// Add a symbol which isn't defined just yet to a list to be resolved later. -void LTOModule::addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym, +void LTOModule::addPotentialUndefinedSymbol(ModuleSymbolTable::Symbol Sym, bool isFunc) { SmallString<64> name; { raw_svector_ostream OS(name); - Sym.printName(OS); + SymTab.printSymbolName(OS, Sym); name.c_str(); } @@ -565,7 +563,7 @@ info.name = IterBool.first->first(); - const GlobalValue *decl = IRFile->getSymbolGV(Sym.getRawDataRefImpl()); + const GlobalValue *decl = Sym.dyn_cast(); if (decl->hasExternalWeakLinkage()) info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF; @@ -577,9 +575,9 @@ } void LTOModule::parseSymbols() { - for (auto &Sym : IRFile->symbols()) { - const GlobalValue *GV = IRFile->getSymbolGV(Sym.getRawDataRefImpl()); - uint32_t Flags = Sym.getFlags(); + for (auto Sym : SymTab.symbols()) { + auto *GV = Sym.dyn_cast(); + uint32_t Flags = SymTab.getSymbolFlags(Sym); if (Flags & object::BasicSymbolRef::SF_FormatSpecific) continue; @@ -589,7 +587,7 @@ SmallString<64> Buffer; { raw_svector_ostream OS(Buffer); - Sym.printName(OS); + SymTab.printSymbolName(OS, Sym); Buffer.c_str(); } StringRef Name(Buffer);