summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-03-11 16:11:47 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-03-11 16:11:47 +0000
commit9b3acf9098607047211559b7e2771b18b5e3dce7 (patch)
tree1ae7f3fea4a989930aabfff4e9335e1cb20a6ef4
parent7423f40674b16c746dfaa94dfc4b3f962dd6b156 (diff)
downloadbcm5719-llvm-9b3acf9098607047211559b7e2771b18b5e3dce7.tar.gz
bcm5719-llvm-9b3acf9098607047211559b7e2771b18b5e3dce7.zip
Avoid calling getNamedValue.
In lld we usually avoid hash lookups. In addition to that, IR names are not fully mangled, so it is best to avoid using them whenever possible. llvm-svn: 263248
-rw-r--r--lld/ELF/InputFiles.cpp84
-rw-r--r--lld/ELF/InputFiles.h15
-rw-r--r--lld/ELF/SymbolTable.cpp38
3 files changed, 76 insertions, 61 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 4f3b812e741..fcc05c2a2c6 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -436,6 +436,50 @@ static uint8_t getGvVisibility(const GlobalValue *GV) {
llvm_unreachable("Unknown visibility");
}
+SymbolBody *
+BitcodeFile::createSymbolBody(const DenseSet<const Comdat *> &KeptComdats,
+ const IRObjectFile &Obj,
+ const BasicSymbolRef &Sym) {
+ const GlobalValue *GV = Obj.getSymbolGV(Sym.getRawDataRefImpl());
+ assert(GV);
+ if (const Comdat *C = GV->getComdat())
+ if (!KeptComdats.count(C))
+ return nullptr;
+
+ uint8_t Visibility = getGvVisibility(GV);
+
+ SmallString<64> Name;
+ raw_svector_ostream OS(Name);
+ Sym.printName(OS);
+ StringRef NameRef = Saver.save(StringRef(Name));
+
+ const Module &M = Obj.getModule();
+ SymbolBody *Body;
+ uint32_t Flags = Sym.getFlags();
+ bool IsWeak = Flags & BasicSymbolRef::SF_Weak;
+ if (Flags & BasicSymbolRef::SF_Undefined) {
+ Body = new (Alloc) Undefined(NameRef, IsWeak, Visibility, false);
+ } else if (Flags & BasicSymbolRef::SF_Common) {
+ const DataLayout &DL = M.getDataLayout();
+ uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+ Body = new (Alloc)
+ DefinedCommon(NameRef, Size, GV->getAlignment(), IsWeak, Visibility);
+ } else {
+ Body = new (Alloc) DefinedBitcode(NameRef, IsWeak, Visibility);
+ }
+ Body->IsTls = GV->isThreadLocal();
+ return Body;
+}
+
+bool BitcodeFile::shouldSkip(const BasicSymbolRef &Sym) {
+ uint32_t Flags = Sym.getFlags();
+ if (!(Flags & BasicSymbolRef::SF_Global))
+ return true;
+ if (Flags & BasicSymbolRef::SF_FormatSpecific)
+ return true;
+ return false;
+}
+
void BitcodeFile::parse(DenseSet<StringRef> &ComdatGroups) {
LLVMContext Context;
std::unique_ptr<IRObjectFile> Obj = check(IRObjectFile::create(MB, Context));
@@ -448,43 +492,9 @@ void BitcodeFile::parse(DenseSet<StringRef> &ComdatGroups) {
KeptComdats.insert(&P.second);
}
- for (const BasicSymbolRef &Sym : Obj->symbols()) {
- const GlobalValue *GV = Obj->getSymbolGV(Sym.getRawDataRefImpl());
- assert(GV);
- uint32_t Flags = Sym.getFlags();
- if (const Comdat *C = GV->getComdat())
- if (!KeptComdats.count(C))
- continue;
- if (!(Flags & BasicSymbolRef::SF_Global))
- continue;
- if (GV->hasAppendingLinkage()) {
- ExtraKeeps.push_back(GV->getName().copy(Alloc));
- continue;
- }
- if (Flags & BasicSymbolRef::SF_FormatSpecific)
- continue;
- uint8_t Visibility = getGvVisibility(GV);
-
- SmallString<64> Name;
- raw_svector_ostream OS(Name);
- Sym.printName(OS);
- StringRef NameRef = Saver.save(StringRef(Name));
-
- SymbolBody *Body;
- bool IsWeak = Flags & BasicSymbolRef::SF_Weak;
- if (Flags & BasicSymbolRef::SF_Undefined) {
- Body = new (Alloc) Undefined(NameRef, IsWeak, Visibility, false);
- } else if (Flags & BasicSymbolRef::SF_Common) {
- const DataLayout &DL = M.getDataLayout();
- uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
- Body = new (Alloc)
- DefinedCommon(NameRef, Size, GV->getAlignment(), IsWeak, Visibility);
- } else {
- Body = new (Alloc) DefinedBitcode(NameRef, IsWeak, Visibility);
- }
- Body->IsTls = GV->isThreadLocal();
- SymbolBodies.push_back(Body);
- }
+ for (const BasicSymbolRef &Sym : Obj->symbols())
+ if (!shouldSkip(Sym))
+ SymbolBodies.push_back(createSymbolBody(KeptComdats, *Obj, Sym));
}
template <typename T>
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index 9019241015a..5cd9df16ccc 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -18,8 +18,10 @@
#include "lld/Core/LLVM.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/IR/Comdat.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/ELF.h"
+#include "llvm/Object/IRObjectFile.h"
#include "llvm/Support/StringSaver.h"
namespace lld {
@@ -180,19 +182,16 @@ public:
static bool classof(const InputFile *F);
void parse(llvm::DenseSet<StringRef> &ComdatGroups);
ArrayRef<SymbolBody *> getSymbols() { return SymbolBodies; }
- ArrayRef<StringRef> getExtraKeeps() { return ExtraKeeps; }
+ static bool shouldSkip(const llvm::object::BasicSymbolRef &Sym);
private:
std::vector<SymbolBody *> SymbolBodies;
- // Some symbols like llvm.global_ctors are internal to the IR and so
- // don't show up in SymbolBodies, but must be kept when creating the
- // combined LTO module. We track them here.
- // We currently use a different Module for creating SymbolBody's vs when
- // we are creating the combined LTO module, and so we can't store IR
- // pointers directly and must rely on the IR names.
- std::vector<StringRef> ExtraKeeps;
llvm::BumpPtrAllocator Alloc;
llvm::StringSaver Saver{Alloc};
+ SymbolBody *
+ createSymbolBody(const llvm::DenseSet<const llvm::Comdat *> &KeptComdats,
+ const llvm::object::IRObjectFile &Obj,
+ const llvm::object::BasicSymbolRef &Sym);
};
// .so file.
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index 1c980469f64..1cb9d7dfe7a 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -84,7 +84,8 @@ void SymbolTable<ELFT>::addFile(std::unique_ptr<InputFile> File) {
BitcodeFiles.emplace_back(cast<BitcodeFile>(File.release()));
F->parse(ComdatGroups);
for (SymbolBody *B : F->getSymbols())
- resolve(B);
+ if (B)
+ resolve(B);
return;
}
@@ -139,28 +140,33 @@ std::unique_ptr<InputFile> SymbolTable<ELFT>::codegen(Module &M) {
static void addBitcodeFile(IRMover &Mover, BitcodeFile &F,
LLVMContext &Context) {
- std::unique_ptr<MemoryBuffer> Buffer =
- MemoryBuffer::getMemBuffer(F.MB, false);
- std::unique_ptr<Module> M =
- check(getLazyBitcodeModule(std::move(Buffer), Context,
- /*ShouldLazyLoadMetadata*/ false));
+
+ std::unique_ptr<IRObjectFile> Obj =
+ check(IRObjectFile::create(F.MB, Context));
std::vector<GlobalValue *> Keep;
- for (SymbolBody *B : F.getSymbols()) {
- if (&B->repl() != B)
+ unsigned BodyIndex = 0;
+ ArrayRef<SymbolBody *> Bodies = F.getSymbols();
+
+ for (const BasicSymbolRef &Sym : Obj->symbols()) {
+ GlobalValue *GV = Obj->getSymbolGV(Sym.getRawDataRefImpl());
+ assert(GV);
+ if (GV->hasAppendingLinkage()) {
+ Keep.push_back(GV);
+ continue;
+ }
+ if (BitcodeFile::shouldSkip(Sym))
+ continue;
+ SymbolBody *B = Bodies[BodyIndex++];
+ if (!B || &B->repl() != B)
continue;
auto *DB = dyn_cast<DefinedBitcode>(B);
if (!DB)
continue;
- GlobalValue *GV = M->getNamedValue(B->getName());
- assert(GV);
Keep.push_back(GV);
}
- for (StringRef S : F.getExtraKeeps()) {
- GlobalValue *GV = M->getNamedValue(S);
- assert(GV);
- Keep.push_back(GV);
- }
- Mover.move(std::move(M), Keep, [](GlobalValue &, IRMover::ValueAdder) {});
+
+ Mover.move(Obj->takeModule(), Keep,
+ [](GlobalValue &, IRMover::ValueAdder) {});
}
// This is for use when debugging LTO.
OpenPOWER on IntegriCloud