[llvm] r289576 - LTO: Port the legacy LTO API to ModuleSymbolTable.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 12:01:59 PST 2016
Author: pcc
Date: Tue Dec 13 14:01:58 2016
New Revision: 289576
URL: http://llvm.org/viewvc/llvm-project?rev=289576&view=rev
Log:
LTO: Port the legacy LTO API to ModuleSymbolTable.
Differential Revision: https://reviews.llvm.org/D27078
Modified:
llvm/trunk/include/llvm/LTO/legacy/LTOModule.h
llvm/trunk/lib/LTO/LTOModule.cpp
Modified: llvm/trunk/include/llvm/LTO/legacy/LTOModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/legacy/LTOModule.h?rev=289576&r1=289575&r2=289576&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/legacy/LTOModule.h (original)
+++ llvm/trunk/include/llvm/LTO/legacy/LTOModule.h Tue Dec 13 14:01:58 2016
@@ -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 <string>
#include <vector>
@@ -47,7 +48,9 @@ private:
std::string LinkerOpts;
- std::unique_ptr<object::IRObjectFile> IRFile;
+ std::unique_ptr<Module> Mod;
+ MemoryBufferRef MBRef;
+ ModuleSymbolTable SymTab;
std::unique_ptr<TargetMachine> _target;
std::vector<NameAndAttributes> _symbols;
@@ -56,7 +59,8 @@ private:
StringMap<NameAndAttributes> _undefines;
std::vector<StringRef> _asm_undefines;
- LTOModule(std::unique_ptr<object::IRObjectFile> Obj, TargetMachine *TM);
+ LTOModule(std::unique_ptr<Module> M, MemoryBufferRef MBRef,
+ TargetMachine *TM);
public:
~LTOModule();
@@ -108,14 +112,10 @@ public:
size_t length, const TargetOptions &options,
StringRef path);
- const Module &getModule() const {
- return const_cast<LTOModule*>(this)->getModule();
- }
- Module &getModule() {
- return IRFile->getModule();
- }
+ const Module &getModule() const { return *Mod; }
+ Module &getModule() { return *Mod; }
- std::unique_ptr<Module> takeModule() { return IRFile->takeModule(); }
+ std::unique_ptr<Module> takeModule() { return std::move(Mod); }
/// Return the Module's target triple.
const std::string &getTargetTriple() {
@@ -166,7 +166,7 @@ private:
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 @@ private:
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.
Modified: llvm/trunk/lib/LTO/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOModule.cpp?rev=289576&r1=289575&r2=289576&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOModule.cpp (original)
+++ llvm/trunk/lib/LTO/LTOModule.cpp Tue Dec 13 14:01:58 2016
@@ -48,9 +48,11 @@
using namespace llvm;
using namespace llvm::object;
-LTOModule::LTOModule(std::unique_ptr<object::IRObjectFile> Obj,
+LTOModule::LTOModule(std::unique_ptr<Module> 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::isBitcodeFile(StringRef
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<bool> Result = hasGlobalValueSummary(IRFile->getMemoryBufferRef());
+ Expected<bool> Result = hasGlobalValueSummary(MBRef);
if (!Result) {
logAllUnhandledErrors(Result.takeError(), errs(), "");
return false;
@@ -233,10 +235,7 @@ LTOModule::makeLTOModule(MemoryBufferRef
march->createTargetMachine(TripleStr, CPU, FeatureStr, options, None);
M->setDataLayout(target->createDataLayout());
- std::unique_ptr<object::IRObjectFile> IRObj(
- new object::IRObjectFile(Buffer, std::move(M)));
-
- std::unique_ptr<LTOModule> Ret(new LTOModule(std::move(IRObj), target));
+ std::unique_ptr<LTOModule> Ret(new LTOModule(std::move(M), Buffer, target));
Ret->parseSymbols();
Ret->parseMetadata();
@@ -344,15 +343,15 @@ void LTOModule::addObjCClassRef(const Gl
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<GlobalValue *>();
addDefinedDataSymbol(Buffer, V);
}
@@ -406,16 +405,15 @@ void LTOModule::addDefinedDataSymbol(Str
}
}
-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<Function>(IRFile->getSymbolGV(Sym.getRawDataRefImpl()));
+ const Function *F = cast<Function>(Sym.get<GlobalValue *>());
addDefinedFunctionSymbol(Buffer, F);
}
@@ -546,12 +544,12 @@ void LTOModule::addAsmGlobalSymbolUndef(
}
/// 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 @@ void LTOModule::addPotentialUndefinedSym
info.name = IterBool.first->first();
- const GlobalValue *decl = IRFile->getSymbolGV(Sym.getRawDataRefImpl());
+ const GlobalValue *decl = Sym.dyn_cast<GlobalValue *>();
if (decl->hasExternalWeakLinkage())
info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF;
@@ -577,9 +575,9 @@ void LTOModule::addPotentialUndefinedSym
}
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<GlobalValue *>();
+ uint32_t Flags = SymTab.getSymbolFlags(Sym);
if (Flags & object::BasicSymbolRef::SF_FormatSpecific)
continue;
@@ -589,7 +587,7 @@ void LTOModule::parseSymbols() {
SmallString<64> Buffer;
{
raw_svector_ostream OS(Buffer);
- Sym.printName(OS);
+ SymTab.printSymbolName(OS, Sym);
Buffer.c_str();
}
StringRef Name(Buffer);
More information about the llvm-commits
mailing list