[llvm] [PassBuilder] Table-drive pass name printing (PR #202656)
David Zbarsky via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 9 07:01:38 PDT 2026
https://github.com/dzbarsky created https://github.com/llvm/llvm-project/pull/202656
Replace the macro-expanded raw_ostream operations in PassBuilder::printPassNames with static pass-name arrays and two shared noinline printing loops. Preserve the generated category order and the exact spelling of parameterized pass names.
The change only executes when a client requests the pass-name listing; normal pipeline parsing and optimization do not access the new tables or helpers.
A stripped opt binary shrinks from 115,493,720 to 115,394,640 bytes, saving 99,080 bytes. The linked __TEXT section shrinks by 98,304 bytes.
Validate byte-identical opt --print-passes output, compile PassBuilder.cpp, and compare the linked stripped opt binaries. Normal optimization performance is unaffected because printPassNames is not called by optimization pipelines.
Work towards #202616
>From a1fdc751e221c70c27e25c2e23f8f9180b19c634 Mon Sep 17 00:00:00 2001
From: David Zbarsky <dzbarsky at gmail.com>
Date: Mon, 8 Jun 2026 23:39:29 -0400
Subject: [PATCH] [PassBuilder] Table-drive pass name printing
Replace the macro-expanded raw_ostream operations in PassBuilder::printPassNames with static pass-name arrays and two shared noinline printing loops. Preserve the generated category order and the exact spelling of parameterized pass names.
The change only executes when a client requests the pass-name listing; normal pipeline parsing and optimization do not access the new tables or helpers.
A stripped opt binary shrinks from 115,493,720 to 115,394,640 bytes, saving 99,080 bytes. The linked __TEXT section shrinks by 98,304 bytes.
Validate byte-identical opt --print-passes output, compile PassBuilder.cpp, and compare the linked stripped opt binaries. Normal optimization performance is unaffected because printPassNames is not called by optimization pipelines.
---
llvm/lib/Passes/PassBuilder.cpp | 109 +++++++++++++++++++++++++-------
1 file changed, 86 insertions(+), 23 deletions(-)
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index f7db63ef8bf74..96e6a2099a209 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -2796,92 +2796,155 @@ PassBuilder::parseRegAllocFilter(StringRef FilterName) {
return std::nullopt;
}
-static void printPassName(StringRef PassName, raw_ostream &OS) {
- OS << " " << PassName << "\n";
+struct PassNameWithParams {
+ StringLiteral Name;
+ StringLiteral Params;
+};
+
+LLVM_ATTRIBUTE_NOINLINE static void
+printPassNameList(ArrayRef<StringLiteral> PassNames, raw_ostream &OS) {
+ for (StringRef PassName : PassNames)
+ OS << " " << PassName << "\n";
}
-static void printPassName(StringRef PassName, StringRef Params,
- raw_ostream &OS) {
- OS << " " << PassName << "<" << Params << ">\n";
+
+LLVM_ATTRIBUTE_NOINLINE static void
+printPassNameList(ArrayRef<PassNameWithParams> PassNames, raw_ostream &OS) {
+ for (const PassNameWithParams &PassName : PassNames)
+ OS << " " << PassName.Name << "<" << PassName.Params << ">\n";
}
void PassBuilder::printPassNames(raw_ostream &OS) {
// TODO: print pass descriptions when they are available
OS << "Module passes:\n";
-#define MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral ModulePassNames[] = {
+#define MODULE_PASS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(ModulePassNames, OS);
OS << "Module passes with params:\n";
+ static constexpr PassNameWithParams ModulePassNamesWithParams[] = {
#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
- printPassName(NAME, PARAMS, OS);
+ {NAME, PARAMS},
#include "PassRegistry.def"
+ };
+ printPassNameList(ModulePassNamesWithParams, OS);
OS << "Module analyses:\n";
-#define MODULE_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral ModuleAnalysisNames[] = {
+#define MODULE_ANALYSIS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(ModuleAnalysisNames, OS);
OS << "Module alias analyses:\n";
-#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral ModuleAliasAnalysisNames[] = {
+#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(ModuleAliasAnalysisNames, OS);
OS << "CGSCC passes:\n";
-#define CGSCC_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral CGSCCPassNames[] = {
+#define CGSCC_PASS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(CGSCCPassNames, OS);
OS << "CGSCC passes with params:\n";
+ static constexpr PassNameWithParams CGSCCPassNamesWithParams[] = {
#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
- printPassName(NAME, PARAMS, OS);
+ {NAME, PARAMS},
#include "PassRegistry.def"
+ };
+ printPassNameList(CGSCCPassNamesWithParams, OS);
OS << "CGSCC analyses:\n";
-#define CGSCC_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral CGSCCAnalysisNames[] = {
+#define CGSCC_ANALYSIS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(CGSCCAnalysisNames, OS);
OS << "Function passes:\n";
-#define FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral FunctionPassNames[] = {
+#define FUNCTION_PASS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(FunctionPassNames, OS);
OS << "Function passes with params:\n";
+ static constexpr PassNameWithParams FunctionPassNamesWithParams[] = {
#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
- printPassName(NAME, PARAMS, OS);
+ {NAME, PARAMS},
#include "PassRegistry.def"
+ };
+ printPassNameList(FunctionPassNamesWithParams, OS);
OS << "Function analyses:\n";
-#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral FunctionAnalysisNames[] = {
+#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(FunctionAnalysisNames, OS);
OS << "Function alias analyses:\n";
-#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral FunctionAliasAnalysisNames[] = {
+#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(FunctionAliasAnalysisNames, OS);
OS << "LoopNest passes:\n";
-#define LOOPNEST_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral LoopNestPassNames[] = {
+#define LOOPNEST_PASS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(LoopNestPassNames, OS);
OS << "Loop passes:\n";
-#define LOOP_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral LoopPassNames[] = {
+#define LOOP_PASS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(LoopPassNames, OS);
OS << "Loop passes with params:\n";
+ static constexpr PassNameWithParams LoopPassNamesWithParams[] = {
#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
- printPassName(NAME, PARAMS, OS);
+ {NAME, PARAMS},
#include "PassRegistry.def"
+ };
+ printPassNameList(LoopPassNamesWithParams, OS);
OS << "Loop analyses:\n";
-#define LOOP_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral LoopAnalysisNames[] = {
+#define LOOP_ANALYSIS(NAME, CREATE_PASS) NAME,
#include "PassRegistry.def"
+ };
+ printPassNameList(LoopAnalysisNames, OS);
OS << "Machine module passes (WIP):\n";
-#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral MachineModulePassNames[] = {
+#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) NAME,
#include "llvm/Passes/MachinePassRegistry.def"
+ ""};
+ printPassNameList(ArrayRef(MachineModulePassNames).drop_back(), OS);
OS << "Machine function passes (WIP):\n";
-#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral MachineFunctionPassNames[] = {
+#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) NAME,
#include "llvm/Passes/MachinePassRegistry.def"
+ };
+ printPassNameList(MachineFunctionPassNames, OS);
OS << "Machine function analyses (WIP):\n";
-#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
+ static constexpr StringLiteral MachineFunctionAnalysisNames[] = {
+#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) NAME,
#include "llvm/Passes/MachinePassRegistry.def"
+ };
+ printPassNameList(MachineFunctionAnalysisNames, OS);
}
void PassBuilder::registerParseTopLevelPipelineCallback(
More information about the llvm-commits
mailing list