summaryrefslogtreecommitdiff
path: root/llvm/tools/opt/NewPMDriver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/opt/NewPMDriver.cpp')
-rw-r--r--llvm/tools/opt/NewPMDriver.cpp135
1 files changed, 88 insertions, 47 deletions
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index ac04a32d93fd5..b94c58decdda2 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -14,6 +14,7 @@
#include "NewPMDriver.h"
#include "PassPrinters.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/CGSCCPassManager.h"
@@ -100,6 +101,9 @@ static cl::opt<std::string> OptimizerLastEPPipeline(
"the OptimizerLast extension point into default pipelines"),
cl::Hidden);
+// Individual pipeline tuning options.
+extern cl::opt<bool> DisableLoopUnrolling;
+
extern cl::opt<PGOKind> PGOKindFlag;
extern cl::opt<std::string> ProfileFile;
extern cl::opt<CSPGOKind> CSPGOKindFlag;
@@ -194,7 +198,7 @@ static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass,
});
if (tryParsePipelineText<FunctionPassManager>(PB, OptimizerLastEPPipeline))
PB.registerOptimizerLastEPCallback(
- [&PB, VerifyEachPass, DebugLogging](FunctionPassManager &PM,
+ [&PB, VerifyEachPass, DebugLogging](ModulePassManager &PM,
PassBuilder::OptimizationLevel) {
ExitOnError Err("Unable to parse OptimizerLastEP pipeline: ");
Err(PB.parsePassPipeline(PM, OptimizerLastEPPipeline, VerifyEachPass,
@@ -209,57 +213,63 @@ static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass,
bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut,
ToolOutputFile *OptRemarkFile,
- StringRef PassPipeline, OutputKind OK,
- VerifierKind VK,
+ StringRef PassPipeline, ArrayRef<StringRef> Passes,
+ OutputKind OK, VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder,
bool ShouldPreserveBitcodeUseListOrder,
bool EmitSummaryIndex, bool EmitModuleHash,
- bool EnableDebugify) {
+ bool EnableDebugify, bool Coroutines) {
bool VerifyEachPass = VK == VK_VerifyEachPass;
Optional<PGOOptions> P;
switch (PGOKindFlag) {
- case InstrGen:
- P = PGOOptions(ProfileFile, "", "", PGOOptions::IRInstr);
- break;
- case InstrUse:
- P = PGOOptions(ProfileFile, "", ProfileRemappingFile, PGOOptions::IRUse);
- break;
- case SampleUse:
- P = PGOOptions(ProfileFile, "", ProfileRemappingFile,
- PGOOptions::SampleUse);
- break;
- case NoPGO:
- if (DebugInfoForProfiling)
- P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
- true);
- else
- P = None;
- }
- if (CSPGOKindFlag != NoCSPGO) {
- if (P && (P->Action == PGOOptions::IRInstr ||
- P->Action == PGOOptions::SampleUse))
- errs() << "CSPGOKind cannot be used with IRInstr or SampleUse";
- if (CSPGOKindFlag == CSInstrGen) {
- if (CSProfileGenFile.empty())
- errs() << "CSInstrGen needs to specify CSProfileGenFile";
- if (P) {
- P->CSAction = PGOOptions::CSIRInstr;
- P->CSProfileGenFile = CSProfileGenFile;
- } else
- P = PGOOptions("", CSProfileGenFile, ProfileRemappingFile,
- PGOOptions::NoAction, PGOOptions::CSIRInstr);
- } else /* CSPGOKindFlag == CSInstrUse */ {
- if (!P)
- errs() << "CSInstrUse needs to be together with InstrUse";
- P->CSAction = PGOOptions::CSIRUse;
- }
+ case InstrGen:
+ P = PGOOptions(ProfileFile, "", "", PGOOptions::IRInstr);
+ break;
+ case InstrUse:
+ P = PGOOptions(ProfileFile, "", ProfileRemappingFile, PGOOptions::IRUse);
+ break;
+ case SampleUse:
+ P = PGOOptions(ProfileFile, "", ProfileRemappingFile,
+ PGOOptions::SampleUse);
+ break;
+ case NoPGO:
+ if (DebugInfoForProfiling)
+ P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
+ true);
+ else
+ P = None;
+ }
+ if (CSPGOKindFlag != NoCSPGO) {
+ if (P && (P->Action == PGOOptions::IRInstr ||
+ P->Action == PGOOptions::SampleUse))
+ errs() << "CSPGOKind cannot be used with IRInstr or SampleUse";
+ if (CSPGOKindFlag == CSInstrGen) {
+ if (CSProfileGenFile.empty())
+ errs() << "CSInstrGen needs to specify CSProfileGenFile";
+ if (P) {
+ P->CSAction = PGOOptions::CSIRInstr;
+ P->CSProfileGenFile = CSProfileGenFile;
+ } else
+ P = PGOOptions("", CSProfileGenFile, ProfileRemappingFile,
+ PGOOptions::NoAction, PGOOptions::CSIRInstr);
+ } else /* CSPGOKindFlag == CSInstrUse */ {
+ if (!P)
+ errs() << "CSInstrUse needs to be together with InstrUse";
+ P->CSAction = PGOOptions::CSIRUse;
}
+ }
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI;
SI.registerCallbacks(PIC);
- PassBuilder PB(TM, PipelineTuningOptions(), P, &PIC);
+ PipelineTuningOptions PTO;
+ // LoopUnrolling defaults on to true and DisableLoopUnrolling is initialized
+ // to false above so we shouldn't necessarily need to check whether or not the
+ // option has been enabled.
+ PTO.LoopUnrolling = !DisableLoopUnrolling;
+ PTO.Coroutines = Coroutines;
+ PassBuilder PB(TM, PTO, P, &PIC);
registerEPCallbacks(PB, VerifyEachPass, DebugPM);
// Load requested pass plugins and let them register pass builder callbacks
@@ -295,9 +305,26 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
// Specially handle the alias analysis manager so that we can register
// a custom pipeline of AA passes with it.
AAManager AA;
- if (auto Err = PB.parseAAPipeline(AA, AAPipeline)) {
- errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
- return false;
+ if (!AAPipeline.empty()) {
+ assert(Passes.empty() &&
+ "--aa-pipeline and -foo-pass should not both be specified");
+ if (auto Err = PB.parseAAPipeline(AA, AAPipeline)) {
+ errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
+ return false;
+ }
+ }
+ // For compatibility with legacy pass manager.
+ // Alias analyses are not specially specified when using the legacy PM.
+ SmallVector<StringRef, 4> NonAAPasses;
+ for (auto PassName : Passes) {
+ if (PB.isAAPassName(PassName)) {
+ if (auto Err = PB.parseAAPipeline(AA, PassName)) {
+ errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
+ return false;
+ }
+ } else {
+ NonAAPasses.push_back(PassName);
+ }
}
LoopAnalysisManager LAM(DebugPM);
@@ -321,10 +348,24 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
if (EnableDebugify)
MPM.addPass(NewPMDebugifyPass());
- if (auto Err =
- PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) {
- errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
- return false;
+ if (!PassPipeline.empty()) {
+ assert(Passes.empty() &&
+ "PassPipeline and Passes should not both contain passes");
+ if (auto Err =
+ PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) {
+ errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
+ return false;
+ }
+ }
+ for (auto PassName : NonAAPasses) {
+ std::string ModifiedPassName(PassName.begin(), PassName.end());
+ if (PB.isAnalysisPassName(PassName))
+ ModifiedPassName = "require<" + ModifiedPassName + ">";
+ if (auto Err = PB.parsePassPipeline(MPM, ModifiedPassName, VerifyEachPass,
+ DebugPM)) {
+ errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
+ return false;
+ }
}
if (VK > VK_NoVerifier)