Skip to content

Commit e1f7b3a

Browse files
committed
Implement -debug-pass-list for New Pass Manager
1 parent e3e949c commit e1f7b3a

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

llvm/lib/Passes/StandardInstrumentations.cpp

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ static cl::opt<bool> VerifyAnalysisInvalidation("verify-analysis-invalidation",
6161
#endif
6262
);
6363

64+
static cl::opt<bool> DebugPassList(
65+
"debug-pass-list", // This will be the command-line flag, e.g., -debug-pass-list
66+
cl::Hidden, // Keep it hidden like other developer debug flags
67+
cl::desc("Print all pass names in a simple list (New PM)"));
68+
69+
70+
6471
// An option that supports the -print-changed option. See
6572
// the description for -print-changed for an explanation of the use
6673
// of this option. Note that this option has no effect without -print-changed.
@@ -2520,6 +2527,50 @@ void StandardInstrumentations::registerCallbacks(
25202527
OptPassGate.registerCallbacks(PIC);
25212528
PrintChangedIR.registerCallbacks(PIC);
25222529
PseudoProbeVerification.registerCallbacks(PIC);
2530+
2531+
// Your new logic for DebugPassList
2532+
if (DebugPassList) { // Ensure DebugPassList is accessible here
2533+
PIC.registerBeforeNonSkippedPassCallback( // Changed from registerBeforeNonContainerPassCallback
2534+
[](llvm::StringRef PassID, llvm::Any IR) {
2535+
// Heuristic filter to identify transformation passes.
2536+
// This attempts to exclude common analysis, utility, verifier, and manager passes.
2537+
// You may need to adjust this list based on your specific needs and LLVM version.
2538+
bool isLikelyTransformation = true;
2539+
2540+
// Filter out Pass Managers first, as registerBeforeNonSkippedPassCallback might call for them
2541+
if (PassID.contains("Manager") ||
2542+
PassID.ends_with("ManagerPass") || // Changed from endswith
2543+
PassID == "PassManager") { // Changed from equals
2544+
isLikelyTransformation = false;
2545+
} else if ( // Else if, to avoid re-evaluating if already identified as a manager
2546+
PassID.contains("Analysis") ||
2547+
PassID.contains("Info") || // Catches LoopInfo, TargetLibraryInfo, etc.
2548+
PassID.contains("Printer") ||
2549+
PassID.contains("Verifier") ||
2550+
PassID.contains("Checker") ||
2551+
PassID.contains("DomTree") || // DominatorTreeWrapperPass
2552+
PassID.contains("ScalarEvolution") ||
2553+
PassID.contains("AssumptionCache") || // AssumptionCacheTracker
2554+
PassID.contains("ProfileSummary") ||
2555+
PassID.contains("MemorySSA") ||
2556+
PassID.contains("MemorySanitizer") ||
2557+
PassID.contains("AddressSanitizer") ||
2558+
PassID.contains("ThreadSanitizer") ||
2559+
PassID.contains("HWAddressSanitizer") ||
2560+
PassID.contains("AA") || // Alias Analysis related passes
2561+
PassID == "ForceFunctionAttrsPass" || // Changed from equals
2562+
PassID == "InferFunctionAttrsPass" // Changed from equals
2563+
// Add other specific non-transformation pass names or patterns here
2564+
) {
2565+
isLikelyTransformation = false;
2566+
}
2567+
2568+
if (isLikelyTransformation) {
2569+
llvm::errs() << PassID << "\n";
2570+
}
2571+
});
2572+
}
2573+
25232574
if (VerifyEach)
25242575
Verify.registerCallbacks(PIC, MAM);
25252576
PrintChangedDiff.registerCallbacks(PIC);
@@ -2531,11 +2582,7 @@ void StandardInstrumentations::registerCallbacks(
25312582
PreservedCFGChecker.registerCallbacks(PIC, *MAM);
25322583

25332584
// TimeProfiling records the pass running time cost.
2534-
// Its 'BeforePassCallback' can be appended at the tail of all the
2535-
// BeforeCallbacks by calling `registerCallbacks` in the end.
2536-
// Its 'AfterPassCallback' is put at the front of all the
2537-
// AfterCallbacks by its `registerCallbacks`. This is necessary
2538-
// to ensure that other callbacks are not included in the timings.
2585+
// ... (rest of the comment and code)
25392586
TimeProfilingPasses.registerCallbacks(PIC);
25402587
}
25412588

0 commit comments

Comments
 (0)