forked from OSchip/llvm-project
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
This commit is contained in:
parent
221e1c2b1f
commit
abf6c650ac
|
@ -142,7 +142,8 @@ static void internalize(GlobalValue &GV) {
|
||||||
GV.setLinkage(GlobalValue::InternalLinkage);
|
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;
|
unsigned NumThreads = Config->LtoJobs;
|
||||||
OwningData.resize(NumThreads);
|
OwningData.resize(NumThreads);
|
||||||
|
|
||||||
|
@ -153,8 +154,7 @@ std::vector<std::unique_ptr<InputFile>> BitcodeCompiler::runSplitCodegen() {
|
||||||
OSPtrs.push_back(&OSs.back());
|
OSPtrs.push_back(&OSs.back());
|
||||||
}
|
}
|
||||||
|
|
||||||
splitCodeGen(std::move(Combined), OSPtrs, {},
|
splitCodeGen(std::move(Combined), OSPtrs, {}, TMFactory);
|
||||||
[this]() { return getTargetMachine(); });
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<InputFile>> ObjFiles;
|
std::vector<std::unique_ptr<InputFile>> ObjFiles;
|
||||||
for (SmallString<0> &Obj : OwningData)
|
for (SmallString<0> &Obj : OwningData)
|
||||||
|
@ -181,19 +181,20 @@ std::vector<std::unique_ptr<InputFile>> BitcodeCompiler::compile() {
|
||||||
if (Config->SaveTemps)
|
if (Config->SaveTemps)
|
||||||
saveBCFile(*Combined, ".lto.bc");
|
saveBCFile(*Combined, ".lto.bc");
|
||||||
|
|
||||||
std::unique_ptr<TargetMachine> TM(getTargetMachine());
|
|
||||||
runLTOPasses(*Combined, *TM);
|
|
||||||
|
|
||||||
return runSplitCodegen();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<TargetMachine> BitcodeCompiler::getTargetMachine() {
|
|
||||||
std::string Msg;
|
std::string Msg;
|
||||||
const Target *T = TargetRegistry::lookupTarget(TheTriple, Msg);
|
const Target *T = TargetRegistry::lookupTarget(TheTriple, Msg);
|
||||||
if (!T)
|
if (!T)
|
||||||
fatal("target not found: " + Msg);
|
fatal("target not found: " + Msg);
|
||||||
TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
|
TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
|
||||||
Reloc::Model R = Config->Pic ? Reloc::PIC_ : Reloc::Static;
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<InputFile>> runSplitCodegen();
|
std::vector<std::unique_ptr<InputFile>> runSplitCodegen(
|
||||||
std::unique_ptr<llvm::TargetMachine> getTargetMachine();
|
const std::function<std::unique_ptr<llvm::TargetMachine>()> &TMFactory);
|
||||||
|
|
||||||
llvm::LLVMContext Context;
|
llvm::LLVMContext Context;
|
||||||
std::unique_ptr<llvm::Module> Combined;
|
std::unique_ptr<llvm::Module> Combined;
|
||||||
|
|
Loading…
Reference in New Issue