summaryrefslogtreecommitdiffstats
path: root/llvm/lib/LTO
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/LTO')
-rw-r--r--llvm/lib/LTO/LTO.cpp42
-rw-r--r--llvm/lib/LTO/LTOBackend.cpp20
2 files changed, 32 insertions, 30 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 30317b9376a..bab8e10a8fa 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -350,19 +350,19 @@ unsigned LTO::getMaxTasks() const {
return RegularLTO.ParallelCodeGenParallelismLevel + ThinLTO.ModuleMap.size();
}
-Error LTO::run(AddStreamFn AddStream) {
+Error LTO::run(AddOutputFn AddOutput) {
// Invoke regular LTO if there was a regular LTO module to start with,
// or if there are any hooks that the linker may have used to add
// its own resolved symbols to the combined module.
if (RegularLTO.HasModule || Conf.PreOptModuleHook ||
Conf.PostInternalizeModuleHook || Conf.PostOptModuleHook ||
Conf.PreCodeGenModuleHook)
- if (auto E = runRegularLTO(AddStream))
+ if (auto E = runRegularLTO(AddOutput))
return E;
- return runThinLTO(AddStream);
+ return runThinLTO(AddOutput);
}
-Error LTO::runRegularLTO(AddStreamFn AddStream) {
+Error LTO::runRegularLTO(AddOutputFn AddOutput) {
if (Conf.PreOptModuleHook &&
!Conf.PreOptModuleHook(0, *RegularLTO.CombinedModule))
return Error();
@@ -388,7 +388,7 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
!Conf.PostInternalizeModuleHook(0, *RegularLTO.CombinedModule))
return Error();
- return backend(Conf, AddStream, RegularLTO.ParallelCodeGenParallelismLevel,
+ return backend(Conf, AddOutput, RegularLTO.ParallelCodeGenParallelismLevel,
std::move(RegularLTO.CombinedModule));
}
@@ -397,14 +397,14 @@ class lto::ThinBackendProc {
protected:
Config &Conf;
ModuleSummaryIndex &CombinedIndex;
- AddStreamFn AddStream;
+ AddOutputFn AddOutput;
StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries;
public:
ThinBackendProc(Config &Conf, ModuleSummaryIndex &CombinedIndex,
- AddStreamFn AddStream,
+ AddOutputFn AddOutput,
StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries)
- : Conf(Conf), CombinedIndex(CombinedIndex), AddStream(AddStream),
+ : Conf(Conf), CombinedIndex(CombinedIndex), AddOutput(AddOutput),
ModuleToDefinedGVSummaries(ModuleToDefinedGVSummaries) {}
virtual ~ThinBackendProc() {}
@@ -424,13 +424,13 @@ public:
InProcessThinBackend(Config &Conf, ModuleSummaryIndex &CombinedIndex,
unsigned ThinLTOParallelismLevel,
StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
- AddStreamFn AddStream)
- : ThinBackendProc(Conf, CombinedIndex, AddStream,
+ AddOutputFn AddOutput)
+ : ThinBackendProc(Conf, CombinedIndex, AddOutput,
ModuleToDefinedGVSummaries),
BackendThreadPool(ThinLTOParallelismLevel) {}
Error
- runThinLTOBackendThread(AddStreamFn AddStream, unsigned Task,
+ runThinLTOBackendThread(AddOutputFn AddOutput, unsigned Task,
MemoryBufferRef MBRef,
ModuleSummaryIndex &CombinedIndex,
const FunctionImporter::ImportMapTy &ImportList,
@@ -442,7 +442,7 @@ public:
parseBitcodeFile(MBRef, BackendContext);
assert(MOrErr && "Unable to load module in thread?");
- return thinBackend(Conf, Task, AddStream, **MOrErr, CombinedIndex,
+ return thinBackend(Conf, Task, AddOutput, **MOrErr, CombinedIndex,
ImportList, DefinedGlobals, ModuleMap);
}
@@ -456,7 +456,7 @@ public:
GVSummaryMapTy &DefinedGlobals,
MapVector<StringRef, MemoryBufferRef> &ModuleMap) {
Error E =
- runThinLTOBackendThread(AddStream, Task, MBRef, CombinedIndex,
+ runThinLTOBackendThread(AddOutput, Task, MBRef, CombinedIndex,
ImportList, DefinedGlobals, ModuleMap);
if (E) {
std::unique_lock<std::mutex> L(ErrMu);
@@ -483,10 +483,10 @@ public:
ThinBackend lto::createInProcessThinBackend(unsigned ParallelismLevel) {
return [=](Config &Conf, ModuleSummaryIndex &CombinedIndex,
StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
- AddStreamFn AddStream) {
+ AddOutputFn AddOutput) {
return llvm::make_unique<InProcessThinBackend>(
Conf, CombinedIndex, ParallelismLevel, ModuleToDefinedGVSummaries,
- AddStream);
+ AddOutput);
};
}
@@ -500,10 +500,10 @@ class WriteIndexesThinBackend : public ThinBackendProc {
public:
WriteIndexesThinBackend(Config &Conf, ModuleSummaryIndex &CombinedIndex,
StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
- AddStreamFn AddStream, std::string OldPrefix,
+ AddOutputFn AddOutput, std::string OldPrefix,
std::string NewPrefix, bool ShouldEmitImportsFiles,
std::string LinkedObjectsFileName)
- : ThinBackendProc(Conf, CombinedIndex, AddStream,
+ : ThinBackendProc(Conf, CombinedIndex, AddOutput,
ModuleToDefinedGVSummaries),
OldPrefix(OldPrefix), NewPrefix(NewPrefix),
ShouldEmitImportsFiles(ShouldEmitImportsFiles),
@@ -572,14 +572,14 @@ ThinBackend lto::createWriteIndexesThinBackend(std::string OldPrefix,
std::string LinkedObjectsFile) {
return [=](Config &Conf, ModuleSummaryIndex &CombinedIndex,
StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
- AddStreamFn AddStream) {
+ AddOutputFn AddOutput) {
return llvm::make_unique<WriteIndexesThinBackend>(
- Conf, CombinedIndex, ModuleToDefinedGVSummaries, AddStream, OldPrefix,
+ Conf, CombinedIndex, ModuleToDefinedGVSummaries, AddOutput, OldPrefix,
NewPrefix, ShouldEmitImportsFiles, LinkedObjectsFile);
};
}
-Error LTO::runThinLTO(AddStreamFn AddStream) {
+Error LTO::runThinLTO(AddOutputFn AddOutput) {
if (ThinLTO.ModuleMap.empty())
return Error();
@@ -622,7 +622,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream) {
[](StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes) {});
std::unique_ptr<ThinBackendProc> BackendProc = ThinLTO.Backend(
- Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries, AddStream);
+ Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries, AddOutput);
// Partition numbers for ThinLTO jobs start at 1 (see comments for
// GlobalResolution in LTO.h). Task numbers, however, start at
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 8844199e7fc..e80aa7b349a 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -19,6 +19,7 @@
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/LegacyPassManager.h"
+#include "llvm/LTO/LTO.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
@@ -144,12 +145,13 @@ bool opt(Config &C, TargetMachine *TM, unsigned Task, Module &M,
return true;
}
-void codegen(Config &C, TargetMachine *TM, AddStreamFn AddStream, unsigned Task,
+void codegen(Config &C, TargetMachine *TM, AddOutputFn AddOutput, unsigned Task,
Module &M) {
if (C.PreCodeGenModuleHook && !C.PreCodeGenModuleHook(Task, M))
return;
- std::unique_ptr<raw_pwrite_stream> OS = AddStream(Task);
+ auto Output = AddOutput(Task);
+ std::unique_ptr<raw_pwrite_stream> OS = Output->getStream();
legacy::PassManager CodeGenPasses;
if (TM->addPassesToEmitFile(CodeGenPasses, *OS,
TargetMachine::CGFT_ObjectFile))
@@ -157,7 +159,7 @@ void codegen(Config &C, TargetMachine *TM, AddStreamFn AddStream, unsigned Task,
CodeGenPasses.run(M);
}
-void splitCodeGen(Config &C, TargetMachine *TM, AddStreamFn AddStream,
+void splitCodeGen(Config &C, TargetMachine *TM, AddOutputFn AddOutput,
unsigned ParallelCodeGenParallelismLevel,
std::unique_ptr<Module> M) {
ThreadPool CodegenThreadPool(ParallelCodeGenParallelismLevel);
@@ -190,7 +192,7 @@ void splitCodeGen(Config &C, TargetMachine *TM, AddStreamFn AddStream,
std::unique_ptr<TargetMachine> TM =
createTargetMachine(C, MPartInCtx->getTargetTriple(), T);
- codegen(C, TM.get(), AddStream, ThreadId, *MPartInCtx);
+ codegen(C, TM.get(), AddOutput, ThreadId, *MPartInCtx);
},
// Pass BC using std::move to ensure that it get moved rather than
// copied into the thread's context.
@@ -214,7 +216,7 @@ Expected<const Target *> initAndLookupTarget(Config &C, Module &M) {
}
-Error lto::backend(Config &C, AddStreamFn AddStream,
+Error lto::backend(Config &C, AddOutputFn AddOutput,
unsigned ParallelCodeGenParallelismLevel,
std::unique_ptr<Module> M) {
Expected<const Target *> TOrErr = initAndLookupTarget(C, *M);
@@ -228,14 +230,14 @@ Error lto::backend(Config &C, AddStreamFn AddStream,
return Error();
if (ParallelCodeGenParallelismLevel == 1)
- codegen(C, TM.get(), AddStream, 0, *M);
+ codegen(C, TM.get(), AddOutput, 0, *M);
else
- splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel,
+ splitCodeGen(C, TM.get(), AddOutput, ParallelCodeGenParallelismLevel,
std::move(M));
return Error();
}
-Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream,
+Error lto::thinBackend(Config &Conf, unsigned Task, AddOutputFn AddOutput,
Module &Mod, ModuleSummaryIndex &CombinedIndex,
const FunctionImporter::ImportMapTy &ImportList,
const GVSummaryMapTy &DefinedGlobals,
@@ -281,6 +283,6 @@ Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream,
if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLto=*/true))
return Error();
- codegen(Conf, TM.get(), AddStream, Task, Mod);
+ codegen(Conf, TM.get(), AddOutput, Task, Mod);
return Error();
}
OpenPOWER on IntegriCloud