diff options
Diffstat (limited to 'llvm/lib/LTO/ThinLTOCodeGenerator.cpp')
| -rw-r--r-- | llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 86 |
1 files changed, 81 insertions, 5 deletions
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index 38f49693b62e..8f0fa933a6a1 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -16,6 +16,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/ModuleSummaryAnalysis.h" #include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h" @@ -37,6 +38,8 @@ #include "llvm/LTO/SummaryBasedOptimizations.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/Object/IRObjectFile.h" +#include "llvm/Passes/PassBuilder.h" +#include "llvm/Passes/StandardInstrumentations.h" #include "llvm/Remarks/HotnessThresholdParser.h" #include "llvm/Support/CachePruning.h" #include "llvm/Support/Debug.h" @@ -262,6 +265,68 @@ static void optimizeModule(Module &TheModule, TargetMachine &TM, PM.run(TheModule); } +static void optimizeModuleNewPM(Module &TheModule, TargetMachine &TM, + unsigned OptLevel, bool Freestanding, + bool DebugPassManager, + ModuleSummaryIndex *Index) { + Optional<PGOOptions> PGOOpt; + LoopAnalysisManager LAM; + FunctionAnalysisManager FAM; + CGSCCAnalysisManager CGAM; + ModuleAnalysisManager MAM; + + PassInstrumentationCallbacks PIC; + StandardInstrumentations SI(DebugPassManager); + SI.registerCallbacks(PIC, &FAM); + PipelineTuningOptions PTO; + PTO.LoopVectorization = true; + PTO.SLPVectorization = true; + PassBuilder PB(&TM, PTO, PGOOpt, &PIC); + + std::unique_ptr<TargetLibraryInfoImpl> TLII( + new TargetLibraryInfoImpl(Triple(TM.getTargetTriple()))); + if (Freestanding) + TLII->disableAllFunctions(); + FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); }); + + AAManager AA = PB.buildDefaultAAPipeline(); + + // Register the AA manager first so that our version is the one used. + FAM.registerPass([&] { return std::move(AA); }); + + // Register all the basic analyses with the managers. + PB.registerModuleAnalyses(MAM); + PB.registerCGSCCAnalyses(CGAM); + PB.registerFunctionAnalyses(FAM); + PB.registerLoopAnalyses(LAM); + PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); + + ModulePassManager MPM; + + PassBuilder::OptimizationLevel OL; + + switch (OptLevel) { + default: + llvm_unreachable("Invalid optimization level"); + case 0: + OL = PassBuilder::OptimizationLevel::O0; + break; + case 1: + OL = PassBuilder::OptimizationLevel::O1; + break; + case 2: + OL = PassBuilder::OptimizationLevel::O2; + break; + case 3: + OL = PassBuilder::OptimizationLevel::O3; + break; + } + + MPM.addPass(PB.buildThinLTODefaultPipeline(OL, Index)); + + MPM.run(TheModule, MAM); +} + static void addUsedSymbolToPreservedGUID(const lto::InputFile &File, DenseSet<GlobalValue::GUID> &PreservedGUID) { @@ -421,7 +486,8 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index, const GVSummaryMapTy &DefinedGlobals, const ThinLTOCodeGenerator::CachingOptions &CacheOptions, bool DisableCodeGen, StringRef SaveTempsDir, - bool Freestanding, unsigned OptLevel, unsigned count) { + bool Freestanding, unsigned OptLevel, unsigned count, + bool UseNewPM, bool DebugPassManager) { // "Benchmark"-like optimization: single-source case bool SingleModule = (ModuleMap.size() == 1); @@ -461,7 +527,11 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index, saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc"); } - optimizeModule(TheModule, TM, OptLevel, Freestanding, &Index); + if (UseNewPM) + optimizeModuleNewPM(TheModule, TM, OptLevel, Freestanding, DebugPassManager, + &Index); + else + optimizeModule(TheModule, TM, OptLevel, Freestanding, &Index); saveTempBitcode(TheModule, SaveTempsDir, count, ".4.opt.bc"); @@ -507,7 +577,9 @@ static void resolvePrevailingInIndex( ResolvedODR[ModuleIdentifier][GUID] = NewLinkage; }; - thinLTOResolvePrevailingInIndex(Index, isPrevailing, recordNewLinkage, + // TODO Conf.VisibilityScheme can be lto::Config::ELF for ELF. + lto::Config Conf; + thinLTOResolvePrevailingInIndex(Conf, Index, isPrevailing, recordNewLinkage, GUIDPreservedSymbols); } @@ -1007,7 +1079,10 @@ void ThinLTOCodeGenerator::run() { // linker option in the old LTO API, but this call allows it to be specified // via the internal option. Must be done before WPD below. updateVCallVisibilityInIndex(*Index, - /* WholeProgramVisibilityEnabledInLTO */ false); + /* WholeProgramVisibilityEnabledInLTO */ false, + // FIXME: This needs linker information via a + // TBD new interface. + /* DynamicExportSymbols */ {}); // Perform index-based WPD. This will return immediately if there are // no index entries in the typeIdMetadata map (e.g. if we are instead @@ -1127,7 +1202,8 @@ void ThinLTOCodeGenerator::run() { *TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList, ExportList, GUIDPreservedSymbols, ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions, - DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count); + DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count, + UseNewPM, DebugPassManager); // Commit to the cache (if enabled) CacheEntry.write(*OutputBuffer); |
