summaryrefslogtreecommitdiffstats
path: root/llvm/lib/LTO/LTO.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-10-25 12:02:03 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-10-25 12:02:03 +0000
commit7912110ddc368f932d20bc82a951371bf9d48ae9 (patch)
treeacfa388a9c1ac9a76623df75c0427bde655bb174 /llvm/lib/LTO/LTO.cpp
parent63c6989d70ed1f94fc6a2a074fe703730e0a00a8 (diff)
downloadbcm5719-llvm-7912110ddc368f932d20bc82a951371bf9d48ae9.tar.gz
bcm5719-llvm-7912110ddc368f932d20bc82a951371bf9d48ae9.zip
Make the LTO comdat api more symbol table friendly.
In an IR symbol table I would expect the comdats to be represented as: - A table of strings, one for each comdat name. - Each symbol has an optional index into that table. The natural api for accessing that would be InputFile: ArrayRef<StringRef> getComdatTable() const; Symbol: int getComdatIndex() const; This patch implements an API as close to that as possible. The implementation on top of the current IRObjectFile is a bit hackish, but should map just fine over a symbol table and is very convenient to use. llvm-svn: 285061
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r--llvm/lib/LTO/LTO.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index b4efb4a4db6..d43b4d56ff1 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -218,9 +218,36 @@ Expected<std::unique_ptr<InputFile>> InputFile::create(MemoryBufferRef Object) {
File->Ctx.setDiagnosticHandler(nullptr, nullptr);
+ for (const auto &C : File->Obj->getModule().getComdatSymbolTable()) {
+ auto P =
+ File->ComdatMap.insert(std::make_pair(&C.second, File->Comdats.size()));
+ assert(P.second);
+ File->Comdats.push_back(C.first());
+ }
+
return std::move(File);
}
+Expected<int> InputFile::Symbol::getComdatIndex() const {
+ if (!GV)
+ return -1;
+ const GlobalObject *GO;
+ if (auto *GA = dyn_cast<GlobalAlias>(GV)) {
+ GO = GA->getBaseObject();
+ if (!GO)
+ return make_error<StringError>("Unable to determine comdat of alias!",
+ inconvertibleErrorCode());
+ } else {
+ GO = cast<GlobalObject>(GV);
+ }
+ if (const Comdat *C = GO->getComdat()) {
+ auto I = File->ComdatMap.find(C);
+ assert(I != File->ComdatMap.end());
+ return I->second;
+ }
+ return -1;
+}
+
LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
Config &Conf)
: ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel),
@@ -332,8 +359,8 @@ Error LTO::addRegularLTO(std::unique_ptr<InputFile> Input,
auto ResI = Res.begin();
for (const InputFile::Symbol &Sym :
- make_range(InputFile::symbol_iterator(Obj->symbol_begin()),
- InputFile::symbol_iterator(Obj->symbol_end()))) {
+ make_range(InputFile::symbol_iterator(Obj->symbol_begin(), nullptr),
+ InputFile::symbol_iterator(Obj->symbol_end(), nullptr))) {
assert(ResI != Res.end());
SymbolResolution Res = *ResI++;
addSymbolToGlobalRes(Obj.get(), Used, Sym, Res, 0);
OpenPOWER on IntegriCloud