1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

[NewPM] Add options to PrintPassInstrumentation

To bring D99599's implementation in line with the existing
PrintPassInstrumentation, and to fix a FIXME, add more customizability
to PrintPassInstrumentation.

Introduce three new options. The first takes over the existing
"-debug-pass-manager-verbose" cl::opt.

The second and third option are specific to -fdebug-pass-structure. They
allow indentation, and also don't print analysis queries.

To avoid more golden file tests than necessary, prune down the
-fdebug-pass-structure tests.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D102196
This commit is contained in:
Arthur Eubanks 2021-05-07 14:32:20 -07:00
parent 9e6695ba98
commit 99f72113f5
6 changed files with 84 additions and 252 deletions

View File

@ -80,27 +80,28 @@ public:
void registerCallbacks(PassInstrumentationCallbacks &PIC);
};
struct PrintPassOptions {
/// Print adaptors and pass managers.
bool Verbose = false;
/// Don't print information for analyses.
bool SkipAnalyses = false;
/// Indent based on hierarchy.
bool Indent = false;
};
// Debug logging for transformation and analysis passes.
class PrintPassInstrumentation {
void printWithIdent(bool Expand, const Twine &Msg);
raw_ostream &print();
public:
PrintPassInstrumentation(bool DebugLogging) : DebugLogging(DebugLogging) {}
PrintPassInstrumentation(bool Enabled, PrintPassOptions Opts)
: Enabled(Enabled), Opts(Opts) {}
void registerCallbacks(PassInstrumentationCallbacks &PIC);
private:
bool DebugLogging;
int Ident = 0;
};
// Pass structure dumper
class PassStructurePrinter {
int Ident = 0;
void printWithIdent(bool Expand, const Twine &Msg);
public:
PassStructurePrinter() {}
void registerCallbacks(PassInstrumentationCallbacks &PIC);
bool Enabled;
PrintPassOptions Opts;
int Indent = 0;
};
class PreservedCFGCheckerInstrumentation {
@ -414,7 +415,6 @@ public:
class StandardInstrumentations {
PrintIRInstrumentation PrintIR;
PrintPassInstrumentation PrintPass;
PassStructurePrinter StructurePrinter;
TimePassesHandler TimePasses;
OptNoneInstrumentation OptNone;
OptBisectInstrumentation OptBisect;
@ -427,7 +427,8 @@ class StandardInstrumentations {
bool VerifyEach;
public:
StandardInstrumentations(bool DebugLogging, bool VerifyEach = false);
StandardInstrumentations(bool DebugLogging, bool VerifyEach = false,
PrintPassOptions PrintPassOpts = PrintPassOptions());
// Register all the standard instrumentation callbacks. If \p FAM is nullptr
// then PreservedCFGChecker is not enabled.

View File

@ -45,17 +45,6 @@ cl::opt<bool> PreservedCFGCheckerInstrumentation::VerifyPreservedCFG(
cl::init(true));
#endif
// FIXME: Change `-debug-pass-manager` from boolean to enum type. Similar to
// `-debug-pass` in legacy PM.
static cl::opt<bool>
DebugPMVerbose("debug-pass-manager-verbose", cl::Hidden, cl::init(false),
cl::desc("Print all pass management debugging information. "
"`-debug-pass-manager` must also be specified"));
static cl::opt<bool>
DebugPassStructure("debug-pass-structure", cl::Hidden, cl::init(false),
cl::desc("Print pass structure information."));
// An option that prints out the IR after passes, similar to
// -print-after-all except that it only prints the IR after passes that
// change the IR. Those passes that do not make changes to the IR are
@ -871,77 +860,73 @@ void OptBisectInstrumentation::registerCallbacks(
});
}
raw_ostream &PrintPassInstrumentation::print() {
if (Opts.Indent) {
assert(Indent >= 0);
dbgs().indent(Indent);
}
return dbgs();
}
void PrintPassInstrumentation::registerCallbacks(
PassInstrumentationCallbacks &PIC) {
if (!DebugLogging)
if (!Enabled)
return;
std::vector<StringRef> SpecialPasses;
if (!DebugPMVerbose) {
if (!Opts.Verbose) {
SpecialPasses.emplace_back("PassManager");
SpecialPasses.emplace_back("PassAdaptor");
}
PIC.registerBeforeSkippedPassCallback(
[SpecialPasses](StringRef PassID, Any IR) {
[this, SpecialPasses](StringRef PassID, Any IR) {
assert(!isSpecialPass(PassID, SpecialPasses) &&
"Unexpectedly skipping special pass");
dbgs() << "Skipping pass: " << PassID << " on " << getIRName(IR)
<< "\n";
print() << "Skipping pass: " << PassID << " on " << getIRName(IR)
<< "\n";
});
PIC.registerBeforeNonSkippedPassCallback([this, SpecialPasses](
StringRef PassID, Any IR) {
if (isSpecialPass(PassID, SpecialPasses))
return;
PIC.registerBeforeNonSkippedPassCallback(
[SpecialPasses](StringRef PassID, Any IR) {
print() << "Running pass: " << PassID << " on " << getIRName(IR) << "\n";
Indent += 2;
});
PIC.registerAfterPassCallback(
[this, SpecialPasses](StringRef PassID, Any IR,
const PreservedAnalyses &) {
if (isSpecialPass(PassID, SpecialPasses))
return;
dbgs() << "Running pass: " << PassID << " on " << getIRName(IR) << "\n";
Indent -= 2;
});
PIC.registerBeforeAnalysisCallback([](StringRef PassID, Any IR) {
dbgs() << "Running analysis: " << PassID << " on " << getIRName(IR) << "\n";
});
PIC.registerAnalysisInvalidatedCallback([](StringRef PassID, Any IR) {
dbgs() << "Invalidating analysis: " << PassID << " on " << getIRName(IR)
<< "\n";
});
PIC.registerAnalysesClearedCallback([](StringRef IRName) {
dbgs() << "Clearing all analysis results for: " << IRName << "\n";
});
}
void PassStructurePrinter::printWithIdent(bool Expand, const Twine &Msg) {
if (!Msg.isTriviallyEmpty())
dbgs().indent(Ident) << Msg << "\n";
Ident = Expand ? Ident + 2 : Ident - 2;
assert(Ident >= 0);
}
void PassStructurePrinter::registerCallbacks(
PassInstrumentationCallbacks &PIC) {
if (!DebugPassStructure)
return;
PIC.registerBeforeNonSkippedPassCallback([this](StringRef PassID, Any IR) {
printWithIdent(true, PassID + " on " + getIRName(IR));
});
PIC.registerAfterPassCallback(
[this](StringRef PassID, Any IR, const PreservedAnalyses &) {
printWithIdent(false, Twine());
});
PIC.registerAfterPassInvalidatedCallback(
[this](StringRef PassID, const PreservedAnalyses &) {
printWithIdent(false, Twine());
[this, SpecialPasses](StringRef PassID, Any IR) {
if (isSpecialPass(PassID, SpecialPasses))
return;
Indent -= 2;
});
PIC.registerBeforeAnalysisCallback([this](StringRef PassID, Any IR) {
printWithIdent(true, PassID + " analysis on " + getIRName(IR));
});
PIC.registerAfterAnalysisCallback(
[this](StringRef PassID, Any IR) { printWithIdent(false, Twine()); });
if (!Opts.SkipAnalyses) {
PIC.registerBeforeAnalysisCallback([this](StringRef PassID, Any IR) {
print() << "Running analysis: " << PassID << " on " << getIRName(IR)
<< "\n";
Indent += 2;
});
PIC.registerAfterAnalysisCallback(
[this](StringRef PassID, Any IR) { Indent -= 2; });
PIC.registerAnalysisInvalidatedCallback([this](StringRef PassID, Any IR) {
print() << "Invalidating analysis: " << PassID << " on " << getIRName(IR)
<< "\n";
});
PIC.registerAnalysesClearedCallback([this](StringRef IRName) {
print() << "Clearing all analysis results for: " << IRName << "\n";
});
}
}
PreservedCFGCheckerInstrumentation::CFG::CFG(const Function *F,
@ -1227,9 +1212,9 @@ void InLineChangePrinter::registerCallbacks(PassInstrumentationCallbacks &PIC) {
TextChangeReporter<ChangedIRData>::registerRequiredCallbacks(PIC);
}
StandardInstrumentations::StandardInstrumentations(bool DebugLogging,
bool VerifyEach)
: PrintPass(DebugLogging), OptNone(DebugLogging),
StandardInstrumentations::StandardInstrumentations(
bool DebugLogging, bool VerifyEach, PrintPassOptions PrintPassOpts)
: PrintPass(DebugLogging, PrintPassOpts), OptNone(DebugLogging),
PrintChangedIR(PrintChanged == ChangePrinter::PrintChangedVerbose),
PrintChangedDiff(
PrintChanged == ChangePrinter::PrintChangedDiffVerbose ||
@ -1242,7 +1227,6 @@ void StandardInstrumentations::registerCallbacks(
PassInstrumentationCallbacks &PIC, FunctionAnalysisManager *FAM) {
PrintIR.registerCallbacks(PIC);
PrintPass.registerCallbacks(PIC);
StructurePrinter.registerCallbacks(PIC);
TimePasses.registerCallbacks(PIC);
OptNone.registerCallbacks(PIC);
OptBisect.registerCallbacks(PIC);

View File

@ -1,6 +1,6 @@
; RUN: opt %s -disable-verify -disable-output -passes='default<O2>' -debug-pass-manager -debug-pass-manager-verbose -cgscc-npm-no-fp-rerun=1 \
; RUN: opt %s -disable-verify -disable-output -passes='default<O2>' -debug-pass-manager=verbose -cgscc-npm-no-fp-rerun=1 \
; RUN: 2>&1 | FileCheck %s -check-prefixes=CHECK,NOREPS
; RUN: opt %s -disable-verify -disable-output -passes='default<O2>' -debug-pass-manager -debug-pass-manager-verbose -cgscc-npm-no-fp-rerun=0 \
; RUN: opt %s -disable-verify -disable-output -passes='default<O2>' -debug-pass-manager=verbose -cgscc-npm-no-fp-rerun=0 \
; RUN: 2>&1 | FileCheck %s -check-prefixes=CHECK,REPS
; Pre-attribute the functions to avoid the PostOrderFunctionAttrsPass cause

View File

@ -1,5 +1,4 @@
; RUN: opt -enable-new-pm=0 -mtriple=x86_64-- -O3 -debug-pass=Structure < %s -o /dev/null 2>&1 | FileCheck --check-prefixes=CHECK,%llvmcheckext %s
; RUN: opt -enable-new-pm=1 -mtriple=x86_64-- -O3 -debug-pass-structure < %s -o /dev/null 2>&1 | FileCheck --check-prefixes=NEWPM,%llvmcheckext %s
; REQUIRES: asserts
@ -336,169 +335,6 @@
; CHECK-NEXT: Branch Probability Analysis
; CHECK-NEXT: Block Frequency Analysis
; NEWPM: VerifierPass on [module]
; NEWPM-NEXT: VerifierAnalysis analysis on [module]
; NEWPM-NEXT: Annotation2MetadataPass on [module]
; NEWPM-NEXT: ForceFunctionAttrsPass on [module]
; NEWPM-NEXT: InferFunctionAttrsPass on [module]
; NEWPM-NEXT: InnerAnalysisManagerProxy<{{.*}}> analysis on [module]
; NEWPM-NEXT: ModuleToFunctionPassAdaptor on [module]
; NEWPM-NEXT: PassManager<{{.*}}> on f
; NEWPM-NEXT: PreservedCFGCheckerAnalysis analysis on f
; NEWPM-NEXT: LowerExpectIntrinsicPass on f
; NEWPM-NEXT: SimplifyCFGPass on f
; NEWPM-NEXT: TargetIRAnalysis analysis on f
; NEWPM-NEXT: AssumptionAnalysis analysis on f
; NEWPM-NEXT: SROA on f
; NEWPM-NEXT: DominatorTreeAnalysis analysis on f
; NEWPM-NEXT: EarlyCSEPass on f
; NEWPM-NEXT: TargetLibraryAnalysis analysis on f
; NEWPM-NEXT: CallSiteSplittingPass on f
; NEWPM-NEXT: OpenMPOptPass on [module]
; NEWPM-NEXT: IPSCCPPass on [module]
; NEWPM-NEXT: CalledValuePropagationPass on [module]
; NEWPM-NEXT: GlobalOptPass on [module]
; NEWPM-NEXT: ModuleToFunctionPassAdaptor on [module]
; NEWPM-NEXT: InnerAnalysisManagerProxy<{{.*}}> analysis on [module]
; NEWPM-NEXT: PromotePass on f
; NEWPM-NEXT: PreservedCFGCheckerAnalysis analysis on f
; NEWPM-NEXT: DominatorTreeAnalysis analysis on f
; NEWPM-NEXT: AssumptionAnalysis analysis on f
; NEWPM-NEXT: DeadArgumentEliminationPass on [module]
; NEWPM-NEXT: ModuleToFunctionPassAdaptor on [module]
; NEWPM-NEXT: PassManager<{{.*}}> on f
; NEWPM-NEXT: InstCombinePass on f
; NEWPM-NEXT: TargetLibraryAnalysis analysis on f
; NEWPM-NEXT: OptimizationRemarkEmitterAnalysis analysis on f
; NEWPM-NEXT: TargetIRAnalysis analysis on f
; NEWPM-NEXT: AAManager analysis on f
; NEWPM-NEXT: BasicAA analysis on f
; NEWPM-NEXT: OuterAnalysisManagerProxy<{{.*}}> analysis on f
; NEWPM-NEXT: SimplifyCFGPass on f
; NEWPM-NEXT: ModuleInlinerWrapperPass on [module]
; NEWPM-NEXT: InlineAdvisorAnalysis analysis on [module]
; NEWPM-NEXT: RequireAnalysisPass<{{.*}}> on [module]
; NEWPM-NEXT: GlobalsAA analysis on [module]
; NEWPM-NEXT: CallGraphAnalysis analysis on [module]
; NEWPM-NEXT: ModuleToFunctionPassAdaptor on [module]
; NEWPM-NEXT: InvalidateAnalysisPass<{{.*}}> on f
; NEWPM-NEXT: RequireAnalysisPass<{{.*}}> on [module]
; NEWPM-NEXT: ProfileSummaryAnalysis analysis on [module]
; NEWPM-NEXT: ModuleToPostOrderCGSCCPassAdaptor on [module]
; NEWPM-NEXT: InnerAnalysisManagerProxy<{{.*}}> analysis on [module]
; NEWPM-NEXT: LazyCallGraphAnalysis analysis on [module]
; NEWPM-NEXT: FunctionAnalysisManagerCGSCCProxy analysis on (f)
; NEWPM-NEXT: OuterAnalysisManagerProxy<{{.*}}> analysis on (f)
; NEWPM-NEXT: DevirtSCCRepeatedPass on (f)
; NEWPM-NEXT: PassManager<{{.*}}> on (f)
; NEWPM-NEXT: InlinerPass on (f)
; NEWPM-NEXT: InlinerPass on (f)
; NEWPM-NEXT: PostOrderFunctionAttrsPass on (f)
; NEWPM-NEXT: AAManager analysis on f
; NEWPM-NEXT: ArgumentPromotionPass on (f)
; NEWPM-NEXT: OpenMPOptCGSCCPass on (f)
; NEWPM-NEXT: CGSCCToFunctionPassAdaptor on (f)
; NEWPM-NEXT: PassManager<{{.*}}> on f
; NEWPM-NEXT: SROA on f
; NEWPM-NEXT: EarlyCSEPass on f
; NEWPM-NEXT: MemorySSAAnalysis analysis on f
; NEWPM-NEXT: SpeculativeExecutionPass on f
; NEWPM-NEXT: JumpThreadingPass on f
; NEWPM-NEXT: LazyValueAnalysis analysis on f
; NEWPM-NEXT: CorrelatedValuePropagationPass on f
; NEWPM-NEXT: SimplifyCFGPass on f
; NEWPM-NEXT: AggressiveInstCombinePass on f
; NEWPM-NEXT: InstCombinePass on f
; NEWPM-NEXT: LibCallsShrinkWrapPass on f
; NEWPM-NEXT: TailCallElimPass on f
; NEWPM-NEXT: SimplifyCFGPass on f
; NEWPM-NEXT: ReassociatePass on f
; NEWPM-NEXT: RequireAnalysisPass<{{.*}}> on f
; NEWPM-NEXT: FunctionToLoopPassAdaptor on f
; NEWPM-NEXT: PassManager<{{.*}}> on f
; NEWPM-NEXT: LoopSimplifyPass on f
; NEWPM-NEXT: LoopAnalysis analysis on f
; NEWPM-NEXT: LCSSAPass on f
; NEWPM-NEXT: SimplifyCFGPass on f
; NEWPM-NEXT: InstCombinePass on f
; NEWPM-NEXT: FunctionToLoopPassAdaptor on f
; NEWPM-NEXT: PassManager<{{.*}}> on f
; NEWPM-NEXT: LoopSimplifyPass on f
; NEWPM-NEXT: LCSSAPass on f
; NEWPM-NEXT: SROA on f
; NEWPM-NEXT: MergedLoadStoreMotionPass on f
; NEWPM-NEXT: GVN on f
; NEWPM-NEXT: MemoryDependenceAnalysis analysis on f
; NEWPM-NEXT: PhiValuesAnalysis analysis on f
; NEWPM-NEXT: SCCPPass on f
; NEWPM-NEXT: BDCEPass on f
; NEWPM-NEXT: DemandedBitsAnalysis analysis on f
; NEWPM-NEXT: InstCombinePass on f
; NEWPM-NEXT: JumpThreadingPass on f
; NEWPM-NEXT: LazyValueAnalysis analysis on f
; NEWPM-NEXT: CorrelatedValuePropagationPass on f
; NEWPM-NEXT: ADCEPass on f
; NEWPM-NEXT: PostDominatorTreeAnalysis analysis on f
; NEWPM-NEXT: MemCpyOptPass on f
; NEWPM-NEXT: DSEPass on f
; NEWPM-NEXT: FunctionToLoopPassAdaptor on f
; NEWPM-NEXT: PassManager<{{.*}}> on f
; NEWPM-NEXT: LoopSimplifyPass on f
; NEWPM-NEXT: LCSSAPass on f
; NEWPM-NEXT: SimplifyCFGPass on f
; NEWPM-NEXT: InstCombinePass on f
; NEWPM-NEXT: GlobalOptPass on [module]
; NEWPM-NEXT: GlobalDCEPass on [module]
; NEWPM-NEXT: EliminateAvailableExternallyPass on [module]
; NEWPM-NEXT: ReversePostOrderFunctionAttrsPass on [module]
; NEWPM-NEXT: CallGraphAnalysis analysis on [module]
; NEWPM-NEXT: RequireAnalysisPass<{{.*}}> on [module]
; NEWPM-NEXT: ModuleToFunctionPassAdaptor on [module]
; NEWPM-NEXT: PassManager<{{.*}}> on f
; NEWPM-NEXT: Float2IntPass on f
; NEWPM-NEXT: LowerConstantIntrinsicsPass on f
; NEWPM-NEXT: FunctionToLoopPassAdaptor on f
; NEWPM-NEXT: PassManager<{{.*}}> on f
; NEWPM-NEXT: LoopSimplifyPass on f
; NEWPM-NEXT: LCSSAPass on f
; NEWPM-NEXT: LoopDistributePass on f
; NEWPM-NEXT: ScalarEvolutionAnalysis analysis on f
; NEWPM-NEXT: InnerAnalysisManagerProxy<{{.*}}> analysis on f
; NEWPM-NEXT: InjectTLIMappings on f
; NEWPM-NEXT: LoopVectorizePass on f
; NEWPM-NEXT: BlockFrequencyAnalysis analysis on f
; NEWPM-NEXT: BranchProbabilityAnalysis analysis on f
; NEWPM-NEXT: LoopLoadEliminationPass on f
; NEWPM-NEXT: InstCombinePass on f
; NEWPM-NEXT: SimplifyCFGPass on f
; NEWPM-NEXT: SLPVectorizerPass on f
; NEWPM-NEXT: VectorCombinePass on f
; NEWPM-NEXT: InstCombinePass on f
; NEWPM-NEXT: LoopUnrollPass on f
; NEWPM-NEXT: WarnMissedTransformationsPass on f
; NEWPM-NEXT: InstCombinePass on f
; NEWPM-NEXT: RequireAnalysisPass<{{.*}}> on f
; NEWPM-NEXT: FunctionToLoopPassAdaptor on f
; NEWPM-NEXT: PassManager<{{.*}}> on f
; NEWPM-NEXT: LoopSimplifyPass on f
; NEWPM-NEXT: LCSSAPass on f
; NEWPM-NEXT: AlignmentFromAssumptionsPass on f
; NEWPM-NEXT: LoopSinkPass on f
; NEWPM-NEXT: InstSimplifyPass on f
; NEWPM-NEXT: DivRemPairsPass on f
; NEWPM-NEXT: SimplifyCFGPass on f
; NEWPM-NEXT: SpeculateAroundPHIsPass on f
; NEWPM-NEXT: CGProfilePass on [module]
; NEWPM-NEXT: GlobalDCEPass on [module]
; NEWPM-NEXT: ConstantMergePass on [module]
; NEWPM-NEXT: RelLookupTableConverterPass on [module]
; NEWPM-NEXT: ModuleToFunctionPassAdaptor on [module]
; NEWPM-NEXT: PassManager<{{.*}}> on f
; NEWPM-NEXT: AnnotationRemarksPass on f
; NEWPM-NEXT: VerifierPass on [module]
; NEWPM-NEXT: VerifierAnalysis analysis on [module]
; NEWPM-NEXT: BitcodeWriterPass on [module]
define void @f() {
ret void
}

View File

@ -142,7 +142,7 @@
; RUN: | FileCheck %s --check-prefix=CHECK-NESTED-FP-LP
; CHECK-NESTED-FP-LP: Running pass: NoOpLoopPass
; RUN: opt -disable-output -debug-pass-manager -debug-pass-manager-verbose \
; RUN: opt -disable-output -debug-pass-manager=verbose \
; RUN: -passes='module(no-op-function,no-op-loop,no-op-cgscc,cgscc(no-op-function,no-op-loop),function(no-op-loop))' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-ADAPTORS
; CHECK-ADAPTORS: Running pass: ModuleToFunctionPassAdaptor
@ -167,7 +167,7 @@
; RUN: opt -disable-output -debug-pass-manager \
; RUN: -passes='module(function(no-op-function,loop(no-op-loop,no-op-loop)))' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-MANAGERS-NO-VERBOSE
; RUN: opt -disable-output -debug-pass-manager -debug-pass-manager-verbose \
; RUN: opt -disable-output -debug-pass-manager=verbose \
; RUN: -passes='module(function(no-op-function,loop(no-op-loop,no-op-loop)))' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-MANAGERS
; CHECK-MANAGERS: Running pass: PassManager{{.*}}Function

View File

@ -52,9 +52,17 @@ cl::opt<std::string>
cl::value_desc("filename"));
} // namespace llvm
static cl::opt<bool>
DebugPM("debug-pass-manager", cl::Hidden,
cl::desc("Print pass management debugging information"));
enum class DebugLogging { None, Normal, Verbose };
static cl::opt<DebugLogging> DebugPM(
"debug-pass-manager", cl::Hidden, cl::ValueOptional,
cl::desc("Print pass management debugging information"),
cl::init(DebugLogging::None),
cl::values(
clEnumValN(DebugLogging::Normal, "", ""),
clEnumValN(
DebugLogging::Verbose, "verbose",
"Print extra information about adaptors and pass managers")));
static cl::list<std::string>
PassPlugins("load-pass-plugin",
@ -283,7 +291,10 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
ModuleAnalysisManager MAM;
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(DebugPM, VerifyEachPass);
PrintPassOptions PrintPassOpts;
PrintPassOpts.Verbose = DebugPM == DebugLogging::Verbose;
StandardInstrumentations SI(DebugPM != DebugLogging::None, VerifyEachPass,
PrintPassOpts);
SI.registerCallbacks(PIC, &FAM);
DebugifyEachInstrumentation Debugify;
if (DebugifyEach)