#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"
#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"
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) {
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);
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");
*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);
; RUN: opt -module-summary %s -o %t1.bc
; RUN: llvm-lto2 run %t1.bc -o %t.o \
; RUN: -r=%t1.bc,_tinkywinky,pxl \
-; RUN: -use-new-pm
+; RUN: -debug-pass-manager \
+; RUN: -use-new-pm 2>&1 | FileCheck --check-prefix=NEWPM %s
+
+; RUN: llvm-lto -thinlto-action=run -exported-symbol tinkywinky \
+; RUN: -use-new-pm \
+; RUN: -debug-pass-manager \
+; RUN: %t1.bc 2>&1 | FileCheck --check-prefix=NEWPM %s
+
+; RUN: llvm-lto -thinlto-action=run -exported-symbol tinkywinky \
+; RUN: -use-new-pm=false \
+; RUN: -debug-pass-manager \
+; RUN: -debug-pass=Structure \
+; RUN: %t1.bc 2>&1 | FileCheck --check-prefix=LEGACYPM %s
+
+; Check that the selected pass manager is used for middle-end optimizations by
+; checking the debug output for IPSCCP.
+
+; NEWPM-NOT: Interprocedural Sparse Conditional Constant Propagation
+; NEWPM: Running pass: IPSCCPPass on [module]
+; NEWPM-NOT: Interprocedural Sparse Conditional Constant Propagation
+
+; LEGACYPM-NOT: IPSCCPPass
+; LEGACYPM: Interprocedural Sparse Conditional Constant Propagation
+; LEGACYPM-NOT: IPSCCPPass
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"