diff options
Diffstat (limited to 'lib/LTO/ThinLTOCodeGenerator.cpp')
-rw-r--r-- | lib/LTO/ThinLTOCodeGenerator.cpp | 59 |
1 files changed, 19 insertions, 40 deletions
diff --git a/lib/LTO/ThinLTOCodeGenerator.cpp b/lib/LTO/ThinLTOCodeGenerator.cpp index 40537e4fa784..0d845a26d0c2 100644 --- a/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/lib/LTO/ThinLTOCodeGenerator.cpp @@ -14,10 +14,6 @@ #include "llvm/LTO/legacy/ThinLTOCodeGenerator.h" -#ifdef HAVE_LLVM_REVISION -#include "LLVMLTORevision.h" -#endif - #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Analysis/ModuleSummaryAnalysis.h" @@ -47,6 +43,7 @@ #include "llvm/Support/ThreadPool.h" #include "llvm/Support/Threading.h" #include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/VCSRevision.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/FunctionImport.h" @@ -73,27 +70,6 @@ namespace { static cl::opt<int> ThreadCount("threads", cl::init(llvm::heavyweight_hardware_concurrency())); -Expected<std::unique_ptr<tool_output_file>> -setupOptimizationRemarks(LLVMContext &Ctx, int Count) { - if (LTOPassRemarksWithHotness) - Ctx.setDiagnosticHotnessRequested(true); - - if (LTORemarksFilename.empty()) - return nullptr; - - std::string FileName = - LTORemarksFilename + ".thin." + llvm::utostr(Count) + ".yaml"; - std::error_code EC; - auto DiagnosticOutputFile = - llvm::make_unique<tool_output_file>(FileName, EC, sys::fs::F_None); - if (EC) - return errorCodeToError(EC); - Ctx.setDiagnosticsOutputFile( - llvm::make_unique<yaml::Output>(DiagnosticOutputFile->os())); - DiagnosticOutputFile->keep(); - return std::move(DiagnosticOutputFile); -} - // Simple helper to save temporary files for debug. static void saveTempBitcode(const Module &TheModule, StringRef TempDir, unsigned count, StringRef Suffix) { @@ -208,10 +184,12 @@ crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index, } static void optimizeModule(Module &TheModule, TargetMachine &TM, - unsigned OptLevel) { + unsigned OptLevel, bool Freestanding) { // Populate the PassManager PassManagerBuilder PMB; PMB.LibraryInfo = new TargetLibraryInfoImpl(TM.getTargetTriple()); + if (Freestanding) + PMB.LibraryInfo->disableAllFunctions(); PMB.Inliner = createFunctionInliningPass(); // FIXME: should get it from the bitcode? PMB.OptLevel = OptLevel; @@ -285,7 +263,7 @@ public: const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR, const GVSummaryMapTy &DefinedFunctions, const DenseSet<GlobalValue::GUID> &PreservedSymbols, unsigned OptLevel, - const TargetMachineBuilder &TMBuilder) { + bool Freestanding, const TargetMachineBuilder &TMBuilder) { if (CachePath.empty()) return; @@ -323,7 +301,7 @@ public: // Start with the compiler revision Hasher.update(LLVM_VERSION_STRING); -#ifdef HAVE_LLVM_REVISION +#ifdef LLVM_REVISION Hasher.update(LLVM_REVISION); #endif @@ -342,6 +320,7 @@ public: AddUnsigned(*TMBuilder.RelocModel); AddUnsigned(TMBuilder.CGOptLevel); AddUnsigned(OptLevel); + AddUnsigned(Freestanding); Hasher.update(ArrayRef<uint8_t>((uint8_t *)&ModHash[0], sizeof(ModHash))); for (auto F : ExportList) @@ -369,7 +348,10 @@ public: ArrayRef<uint8_t>((const uint8_t *)&Entry, sizeof(GlobalValue::GUID))); } - sys::path::append(EntryPath, CachePath, toHex(Hasher.result())); + // This choice of file name allows the cache to be pruned (see pruneCache() + // in include/llvm/Support/CachePruning.h). + sys::path::append(EntryPath, CachePath, + "llvmcache-" + toHex(Hasher.result())); } // Access the path to this entry in the cache. @@ -422,7 +404,7 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index, const GVSummaryMapTy &DefinedGlobals, const ThinLTOCodeGenerator::CachingOptions &CacheOptions, bool DisableCodeGen, StringRef SaveTempsDir, - unsigned OptLevel, unsigned count) { + bool Freestanding, unsigned OptLevel, unsigned count) { // "Benchmark"-like optimization: single-source case bool SingleModule = (ModuleMap.size() == 1); @@ -454,7 +436,7 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index, saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc"); } - optimizeModule(TheModule, TM, OptLevel); + optimizeModule(TheModule, TM, OptLevel, Freestanding); saveTempBitcode(TheModule, SaveTempsDir, count, ".4.opt.bc"); @@ -780,7 +762,7 @@ void ThinLTOCodeGenerator::optimize(Module &TheModule) { initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple())); // Optimize now - optimizeModule(TheModule, *TMBuilder.create(), OptLevel); + optimizeModule(TheModule, *TMBuilder.create(), OptLevel, Freestanding); } /** @@ -966,7 +948,7 @@ void ThinLTOCodeGenerator::run() { ImportLists[ModuleIdentifier], ExportList, ResolvedODR[ModuleIdentifier], DefinedFunctions, GUIDPreservedSymbols, - OptLevel, TMBuilder); + OptLevel, Freestanding, TMBuilder); auto CacheEntryPath = CacheEntry.getEntryPath(); { @@ -990,7 +972,8 @@ void ThinLTOCodeGenerator::run() { LLVMContext Context; Context.setDiscardValueNames(LTODiscardValueNames); Context.enableDebugTypeODRUniquing(); - auto DiagFileOrErr = setupOptimizationRemarks(Context, count); + auto DiagFileOrErr = lto::setupOptimizationRemarks( + Context, LTORemarksFilename, LTOPassRemarksWithHotness, count); if (!DiagFileOrErr) { errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n"; report_fatal_error("ThinLTO: Can't get an output file for the " @@ -1011,7 +994,7 @@ void ThinLTOCodeGenerator::run() { *TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList, ExportList, GUIDPreservedSymbols, ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions, - DisableCodeGen, SaveTempsDir, OptLevel, count); + DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count); // Commit to the cache (if enabled) CacheEntry.write(*OutputBuffer); @@ -1043,11 +1026,7 @@ void ThinLTOCodeGenerator::run() { } } - CachePruning(CacheOptions.Path) - .setPruningInterval(std::chrono::seconds(CacheOptions.PruningInterval)) - .setEntryExpiration(std::chrono::seconds(CacheOptions.Expiration)) - .setMaxSize(CacheOptions.MaxPercentageOfAvailableSpace) - .prune(); + pruneCache(CacheOptions.Path, CacheOptions.Policy); // If statistics were requested, print them out now. if (llvm::AreStatisticsEnabled()) |