[lld] r267921 - Use a single context for lto.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 28 12:30:41 PDT 2016
Author: rafael
Date: Thu Apr 28 14:30:41 2016
New Revision: 267921
URL: http://llvm.org/viewvc/llvm-project?rev=267921&view=rev
Log:
Use a single context for lto.
Using multiple context used to be a really big memory saving because we
could free memory from each file while the linker proceeded with the
symbol resolution. We are getting lazier about reading data from the
bitcode, so I was curious if this was still a good tradeoff.
One thing that is a bit annoying is that we still have to copy the
symbol names. The problem is that the names are stored in the Module and
get freed when we move the module bits during linking.
Long term I think the solution is to add a symbol table to the bitcode.
That way IRObject file will not need to use a Module or a Context and we
can drop it while still keeping a StringRef to the names.
This patch is still be an interesting medium term improvement.
When linking llvm-as without debug info this patch is a small speedup:
master: 29.861877513 seconds
patch: 29.814533787 seconds
With debug info the numbers are
master: 34.765181469 seconds
patch: 34.563351584 seconds
The peak memory usage when linking llvm-as with debug info was
master: 599.10MB
patch: 600.13MB
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Driver.h
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/LTO.cpp
lld/trunk/ELF/LTO.h
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=267921&r1=267920&r2=267921&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Apr 28 14:30:41 2016
@@ -170,6 +170,12 @@ static void initLLVM(opt::InputArgList &
InitializeAllAsmPrinters();
InitializeAllAsmParsers();
+ // This is a flag to discard all but GlobalValue names.
+ // We want to enable it by default because it saves memory.
+ // Disable it only when a developer option (-save-temps) is given.
+ Driver->Context.setDiscardValueNames(!Config->SaveTemps);
+ Driver->Context.enableDebugTypeODRUniquing();
+
// Parse and evaluate -mllvm options.
std::vector<const char *> V;
V.push_back("lld (LLVM option parsing)");
@@ -259,8 +265,8 @@ void LinkerDriver::main(ArrayRef<const c
return;
}
- initLLVM(Args);
readConfigs(Args);
+ initLLVM(Args);
if (!Config->Reproduce.empty())
logCommandline(ArgsArr);
Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=267921&r1=267920&r2=267921&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Thu Apr 28 14:30:41 2016
@@ -27,6 +27,7 @@ public:
void main(ArrayRef<const char *> Args);
void addFile(StringRef Path);
void addLibrary(StringRef Name);
+ llvm::LLVMContext Context;
private:
std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB);
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=267921&r1=267920&r2=267921&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Apr 28 14:30:41 2016
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "InputFiles.h"
+#include "Driver.h"
#include "Error.h"
#include "InputSection.h"
#include "Symbols.h"
@@ -15,7 +16,6 @@
#include "llvm/CodeGen/Analysis.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
-#include "llvm/Object/IRObjectFile.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -591,8 +591,7 @@ bool BitcodeFile::shouldSkip(const Basic
}
void BitcodeFile::parse(DenseSet<StringRef> &ComdatGroups) {
- LLVMContext Context;
- std::unique_ptr<IRObjectFile> Obj = check(IRObjectFile::create(MB, Context));
+ Obj = check(IRObjectFile::create(MB, Driver->Context));
const Module &M = Obj->getModule();
DenseSet<const Comdat *> KeptComdats;
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=267921&r1=267920&r2=267921&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Thu Apr 28 14:30:41 2016
@@ -224,6 +224,7 @@ public:
void parse(llvm::DenseSet<StringRef> &ComdatGroups);
ArrayRef<SymbolBody *> getSymbols() { return SymbolBodies; }
static bool shouldSkip(const llvm::object::BasicSymbolRef &Sym);
+ std::unique_ptr<llvm::object::IRObjectFile> Obj;
private:
std::vector<SymbolBody *> SymbolBodies;
Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=267921&r1=267920&r2=267921&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Thu Apr 28 14:30:41 2016
@@ -9,6 +9,7 @@
#include "LTO.h"
#include "Config.h"
+#include "Driver.h"
#include "Error.h"
#include "InputFiles.h"
#include "Symbols.h"
@@ -86,18 +87,11 @@ static bool shouldInternalize(const Smal
}
BitcodeCompiler::BitcodeCompiler()
- : Combined(new llvm::Module("ld-temp.o", Context)), Mover(*Combined) {
- // This is a flag to discard all but GlobalValue names.
- // We want to enable it by default because it saves memory.
- // Disable it only when a developer option (-save-temps) is given.
- Context.setDiscardValueNames(!Config->SaveTemps);
-
- Context.enableDebugTypeODRUniquing();
-}
+ : Combined(new llvm::Module("ld-temp.o", Driver->Context)),
+ Mover(*Combined) {}
void BitcodeCompiler::add(BitcodeFile &F) {
- std::unique_ptr<IRObjectFile> Obj =
- check(IRObjectFile::create(F.MB, Context));
+ std::unique_ptr<IRObjectFile> Obj = std::move(F.Obj);
std::vector<GlobalValue *> Keep;
unsigned BodyIndex = 0;
ArrayRef<SymbolBody *> Bodies = F.getSymbols();
Modified: lld/trunk/ELF/LTO.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.h?rev=267921&r1=267920&r2=267921&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.h (original)
+++ lld/trunk/ELF/LTO.h Thu Apr 28 14:30:41 2016
@@ -24,7 +24,6 @@
#include "lld/Core/LLVM.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSet.h"
-#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Linker/IRMover.h"
@@ -44,7 +43,6 @@ private:
std::vector<std::unique_ptr<InputFile>> runSplitCodegen(
const std::function<std::unique_ptr<llvm::TargetMachine>()> &TMFactory);
- llvm::LLVMContext Context;
std::unique_ptr<llvm::Module> Combined;
llvm::IRMover Mover;
std::vector<SmallString<0>> OwningData;
More information about the llvm-commits
mailing list