1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

LTO: Port the legacy LTO API to ModuleSymbolTable.

Differential Revision: https://reviews.llvm.org/D27078

llvm-svn: 289576
This commit is contained in:
Peter Collingbourne 2016-12-13 20:01:58 +00:00
parent de03bdaaae
commit 0c5b257466
2 changed files with 31 additions and 33 deletions

View File

@ -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.

View File

@ -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 Path) {
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 Buffer, const TargetOptions &options,
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 GlobalVariable *clgv) {
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(StringRef Name, const GlobalValue *v) {
}
}
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(StringRef name) {
}
/// 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::addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym,
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::addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym,
}
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);