[llvm] r265113 - Add a libLTO API to stop/restart ThinLTO between optimizations and CodeGen
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 31 23:47:03 PDT 2016
Author: mehdi_amini
Date: Fri Apr 1 01:47:02 2016
New Revision: 265113
URL: http://llvm.org/viewvc/llvm-project?rev=265113&view=rev
Log:
Add a libLTO API to stop/restart ThinLTO between optimizations and CodeGen
This allows the linker to instruct ThinLTO to perform only the
optimization part or only the codegen part of the process.
From: Mehdi Amini <mehdi.amini at apple.com>
Modified:
llvm/trunk/include/llvm-c/lto.h
llvm/trunk/include/llvm/LTO/ThinLTOCodeGenerator.h
llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
llvm/trunk/tools/lto/lto.cpp
llvm/trunk/tools/lto/lto.exports
Modified: llvm/trunk/include/llvm-c/lto.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/lto.h?rev=265113&r1=265112&r2=265113&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/lto.h (original)
+++ llvm/trunk/include/llvm-c/lto.h Fri Apr 1 01:47:02 2016
@@ -44,7 +44,8 @@ typedef bool lto_bool_t;
* @{
*/
-#define LTO_API_VERSION 18
+#define LTO_API_VERSION 19
+
/**
* \since prior to LTO_API_VERSION=3
*/
@@ -718,6 +719,23 @@ extern void thinlto_codegen_set_savetemp
extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu);
/**
+ * Disable CodeGen, only run the stages till codegen and stop. The output will
+ * be bitcode.
+ *
+ * \since LTO_API_VERSION=19
+ */
+extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg,
+ lto_bool_t disable);
+
+/**
+ * Perform CodeGen only: disable all other stages.
+ *
+ * \since LTO_API_VERSION=19
+ */
+extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg,
+ lto_bool_t codegen_only);
+
+/**
* Parse -mllvm style debug options.
*
* \since LTO_API_VERSION=18
Modified: llvm/trunk/include/llvm/LTO/ThinLTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/ThinLTOCodeGenerator.h?rev=265113&r1=265112&r2=265113&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/ThinLTOCodeGenerator.h (original)
+++ llvm/trunk/include/llvm/LTO/ThinLTOCodeGenerator.h Fri Apr 1 01:47:02 2016
@@ -169,6 +169,13 @@ public:
TMBuilder.CGOptLevel = CGOptLevel;
}
+ /// Disable CodeGen, only run the stages till codegen and stop. The output
+ /// will be bitcode.
+ void disableCodeGen(bool Disable) { DisableCodeGen = Disable; }
+
+ /// Perform CodeGen only: disable all other stages.
+ void setCodeGenOnly(bool CGOnly) { CodeGenOnly = CGOnly; }
+
/**@}*/
/**
@@ -228,6 +235,14 @@ private:
/// Path to a directory to save the temporary bitcode files.
std::string SaveTempsDir;
+
+ /// Flag to enable/disable CodeGen. When set to true, the process stops after
+ /// optimizations and a bitcode is produced.
+ bool DisableCodeGen;
+
+ /// Flag to indicate that only the CodeGen will be performed, no cross-module
+ /// importing or optimization.
+ bool CodeGenOnly;
};
}
#endif
Modified: llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp?rev=265113&r1=265112&r2=265113&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp Fri Apr 1 01:47:02 2016
@@ -188,7 +188,8 @@ ProcessThinLTOModule(Module &TheModule,
StringMap<MemoryBufferRef> &ModuleMap, TargetMachine &TM,
const FunctionImporter::ImportMapTy &ImportList,
ThinLTOCodeGenerator::CachingOptions CacheOptions,
- StringRef SaveTempsDir, unsigned count) {
+ bool DisableCodeGen, StringRef SaveTempsDir,
+ unsigned count) {
// Save temps: after IPO.
saveTempBitcode(TheModule, SaveTempsDir, count, ".1.IPO.bc");
@@ -212,6 +213,16 @@ ProcessThinLTOModule(Module &TheModule,
saveTempBitcode(TheModule, SaveTempsDir, count, ".3.opt.bc");
+ if (DisableCodeGen) {
+ // Configured to stop before CodeGen, serialize the bitcode and return.
+ SmallVector<char, 128> OutputBuffer;
+ {
+ raw_svector_ostream OS(OutputBuffer);
+ WriteBitcodeToFile(&TheModule, OS, true, true);
+ }
+ return make_unique<ObjectMemoryBuffer>(std::move(OutputBuffer));
+ }
+
return codegenModule(TheModule, TM);
}
@@ -348,6 +359,28 @@ std::unique_ptr<MemoryBuffer> ThinLTOCod
// Main entry point for the ThinLTO processing
void ThinLTOCodeGenerator::run() {
+ if (CodeGenOnly) {
+ // Perform only parallel codegen and return.
+ ThreadPool Pool;
+ assert(ProducedBinaries.empty() && "The generator should not be reused");
+ ProducedBinaries.resize(Modules.size());
+ int count = 0;
+ for (auto &ModuleBuffer : Modules) {
+ Pool.async([&](int count) {
+ LLVMContext Context;
+ Context.setDiscardValueNames(LTODiscardValueNames);
+
+ // Parse module now
+ auto TheModule = loadModuleFromBuffer(ModuleBuffer, Context, false);
+
+ // CodeGen
+ ProducedBinaries[count] = codegen(*TheModule);
+ }, count++);
+ }
+
+ return;
+ }
+
// Sequential linking phase
auto Index = linkCombinedIndex();
@@ -396,7 +429,7 @@ void ThinLTOCodeGenerator::run() {
auto &ImportList = ImportLists[TheModule->getModuleIdentifier()];
ProducedBinaries[count] = ProcessThinLTOModule(
*TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList,
- CacheOptions, SaveTempsDir, count);
+ CacheOptions, DisableCodeGen, SaveTempsDir, count);
}, count);
count++;
}
Modified: llvm/trunk/tools/lto/lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=265113&r1=265112&r2=265113&view=diff
==============================================================================
--- llvm/trunk/tools/lto/lto.cpp (original)
+++ llvm/trunk/tools/lto/lto.cpp Fri Apr 1 01:47:02 2016
@@ -473,6 +473,16 @@ LTOObjectBuffer thinlto_module_get_objec
MemBuffer->getBufferSize()};
}
+void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg,
+ lto_bool_t disable) {
+ unwrap(cg)->disableCodeGen(disable);
+}
+
+void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg,
+ lto_bool_t CodeGenOnly) {
+ unwrap(cg)->setCodeGenOnly(CodeGenOnly);
+}
+
void thinlto_debug_options(const char *const *options, int number) {
// if options were requested, set them
if (number && options) {
@@ -483,7 +493,7 @@ void thinlto_debug_options(const char *c
}
}
-bool lto_module_is_thinlto(lto_module_t mod) {
+lto_bool_t lto_module_is_thinlto(lto_module_t mod) {
return unwrap(mod)->isThinLTO();
}
Modified: llvm/trunk/tools/lto/lto.exports
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.exports?rev=265113&r1=265112&r2=265113&view=diff
==============================================================================
--- llvm/trunk/tools/lto/lto.exports (original)
+++ llvm/trunk/tools/lto/lto.exports Fri Apr 1 01:47:02 2016
@@ -61,4 +61,6 @@ thinlto_debug_options
lto_module_is_thinlto
thinlto_codegen_add_must_preserve_symbol
thinlto_codegen_add_cross_referenced_symbol
-thinlto_codegen_set_final_cache_size_relative_to_available_space
\ No newline at end of file
+thinlto_codegen_set_final_cache_size_relative_to_available_space
+thinlto_codegen_set_codegen_only
+thinlto_codegen_disable_codegen
\ No newline at end of file
More information about the llvm-commits
mailing list