summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-04-17 23:20:08 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-04-17 23:20:08 +0000
commitabf6c650ac8d20f9774787e4571f82a7ea8eb2b8 (patch)
tree9fbda19b84782afe233f1fc6b84a5fa629e8c3d4
parent221e1c2b1ffab2d403ea85eed3c4f69658054ec3 (diff)
downloadbcm5719-llvm-abf6c650ac8d20f9774787e4571f82a7ea8eb2b8.tar.gz
bcm5719-llvm-abf6c650ac8d20f9774787e4571f82a7ea8eb2b8.zip
Make CreateTargetMachine as small as possible.
It is a pity that we have to create a TargetMachine once per thread, so at least make that code as small as possible. llvm-svn: 266578
-rw-r--r--lld/ELF/LTO.cpp25
-rw-r--r--lld/ELF/LTO.h4
2 files changed, 15 insertions, 14 deletions
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 6fe4e1169ad..0d3593844f0 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -142,7 +142,8 @@ static void internalize(GlobalValue &GV) {
GV.setLinkage(GlobalValue::InternalLinkage);
}
-std::vector<std::unique_ptr<InputFile>> BitcodeCompiler::runSplitCodegen() {
+std::vector<std::unique_ptr<InputFile>> BitcodeCompiler::runSplitCodegen(
+ const std::function<std::unique_ptr<TargetMachine>()> &TMFactory) {
unsigned NumThreads = Config->LtoJobs;
OwningData.resize(NumThreads);
@@ -153,8 +154,7 @@ std::vector<std::unique_ptr<InputFile>> BitcodeCompiler::runSplitCodegen() {
OSPtrs.push_back(&OSs.back());
}
- splitCodeGen(std::move(Combined), OSPtrs, {},
- [this]() { return getTargetMachine(); });
+ splitCodeGen(std::move(Combined), OSPtrs, {}, TMFactory);
std::vector<std::unique_ptr<InputFile>> ObjFiles;
for (SmallString<0> &Obj : OwningData)
@@ -181,19 +181,20 @@ std::vector<std::unique_ptr<InputFile>> BitcodeCompiler::compile() {
if (Config->SaveTemps)
saveBCFile(*Combined, ".lto.bc");
- std::unique_ptr<TargetMachine> TM(getTargetMachine());
- runLTOPasses(*Combined, *TM);
-
- return runSplitCodegen();
-}
-
-std::unique_ptr<TargetMachine> BitcodeCompiler::getTargetMachine() {
std::string Msg;
const Target *T = TargetRegistry::lookupTarget(TheTriple, Msg);
if (!T)
fatal("target not found: " + Msg);
TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
Reloc::Model R = Config->Pic ? Reloc::PIC_ : Reloc::Static;
- return std::unique_ptr<TargetMachine>(
- T->createTargetMachine(TheTriple, "", "", Options, R));
+
+ auto CreateTargetMachine = [&]() {
+ return std::unique_ptr<TargetMachine>(
+ T->createTargetMachine(TheTriple, "", "", Options, R));
+ };
+
+ std::unique_ptr<TargetMachine> TM = CreateTargetMachine();
+ runLTOPasses(*Combined, *TM);
+
+ return runSplitCodegen(CreateTargetMachine);
}
diff --git a/lld/ELF/LTO.h b/lld/ELF/LTO.h
index c06c49e8324..2208891a584 100644
--- a/lld/ELF/LTO.h
+++ b/lld/ELF/LTO.h
@@ -45,8 +45,8 @@ public:
}
private:
- std::vector<std::unique_ptr<InputFile>> runSplitCodegen();
- std::unique_ptr<llvm::TargetMachine> getTargetMachine();
+ 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;
OpenPOWER on IntegriCloud