[lld] r266578 - Make CreateTargetMachine as small as possible.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 17 16:20:13 PDT 2016
Author: rafael
Date: Sun Apr 17 18:20:08 2016
New Revision: 266578
URL: http://llvm.org/viewvc/llvm-project?rev=266578&view=rev
Log:
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.
Modified:
lld/trunk/ELF/LTO.cpp
lld/trunk/ELF/LTO.h
Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=266578&r1=266577&r2=266578&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Sun Apr 17 18:20:08 2016
@@ -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>>
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>>
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);
}
Modified: lld/trunk/ELF/LTO.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.h?rev=266578&r1=266577&r2=266578&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.h (original)
+++ lld/trunk/ELF/LTO.h Sun Apr 17 18:20:08 2016
@@ -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;
More information about the llvm-commits
mailing list