5353#include " deltas/StripDebugInfo.h"
5454#include " llvm/ADT/SmallSet.h"
5555#include " llvm/Support/CommandLine.h"
56+ #include " DeltaPass.h"
57+ #include " llvm/ADT/ArrayRef.h"
5658
5759using namespace llvm ;
5860
@@ -71,91 +73,77 @@ static cl::list<std::string>
7173 " default, run all delta passes." ),
7274 cl::cat(LLVMReduceOptions), cl::CommaSeparated);
7375
74- #define DELTA_PASSES \
75- do { \
76- DELTA_PASS (" strip-debug-info" , stripDebugInfoDeltaPass) \
77- DELTA_PASS (" functions" , reduceFunctionsDeltaPass) \
78- DELTA_PASS (" function-bodies" , reduceFunctionBodiesDeltaPass) \
79- DELTA_PASS (" special-globals" , reduceSpecialGlobalsDeltaPass) \
80- DELTA_PASS (" aliases" , reduceAliasesDeltaPass) \
81- DELTA_PASS (" ifuncs" , reduceIFuncsDeltaPass) \
82- DELTA_PASS (" simplify-conditionals-true" , reduceConditionalsTrueDeltaPass) \
83- DELTA_PASS (" simplify-conditionals-false" , \
84- reduceConditionalsFalseDeltaPass) \
85- DELTA_PASS (" invokes" , reduceInvokesDeltaPass) \
86- DELTA_PASS (" unreachable-basic-blocks" , \
87- reduceUnreachableBasicBlocksDeltaPass) \
88- DELTA_PASS (" basic-blocks" , reduceBasicBlocksDeltaPass) \
89- DELTA_PASS (" simplify-cfg" , reduceUsingSimplifyCFGDeltaPass) \
90- DELTA_PASS (" function-data" , reduceFunctionDataDeltaPass) \
91- DELTA_PASS (" global-values" , reduceGlobalValuesDeltaPass) \
92- DELTA_PASS (" global-objects" , reduceGlobalObjectsDeltaPass) \
93- DELTA_PASS (" global-initializers" , reduceGlobalsInitializersDeltaPass) \
94- DELTA_PASS (" global-variables" , reduceGlobalsDeltaPass) \
95- DELTA_PASS (" di-metadata" , reduceDIMetadataDeltaPass) \
96- DELTA_PASS (" dbg-records" , reduceDbgRecordDeltaPass) \
97- DELTA_PASS (" distinct-metadata" , reduceDistinctMetadataDeltaPass) \
98- DELTA_PASS (" metadata" , reduceMetadataDeltaPass) \
99- DELTA_PASS (" named-metadata" , reduceNamedMetadataDeltaPass) \
100- DELTA_PASS (" arguments" , reduceArgumentsDeltaPass) \
101- DELTA_PASS (" instructions" , reduceInstructionsDeltaPass) \
102- DELTA_PASS (" simplify-instructions" , simplifyInstructionsDeltaPass) \
103- DELTA_PASS (" ir-passes" , runIRPassesDeltaPass) \
104- DELTA_PASS (" operands-zero" , reduceOperandsZeroDeltaPass) \
105- DELTA_PASS (" operands-one" , reduceOperandsOneDeltaPass) \
106- DELTA_PASS (" operands-nan" , reduceOperandsNaNDeltaPass) \
107- DELTA_PASS (" operands-to-args" , reduceOperandsToArgsDeltaPass) \
108- DELTA_PASS (" operands-skip" , reduceOperandsSkipDeltaPass) \
109- DELTA_PASS (" operand-bundles" , reduceOperandBundesDeltaPass) \
110- DELTA_PASS (" attributes" , reduceAttributesDeltaPass) \
111- DELTA_PASS (" module-data" , reduceModuleDataDeltaPass) \
112- DELTA_PASS (" opcodes" , reduceOpcodesDeltaPass) \
113- DELTA_PASS (" volatile" , reduceVolatileInstructionsDeltaPass) \
114- DELTA_PASS (" atomic-ordering" , reduceAtomicOrderingDeltaPass) \
115- DELTA_PASS (" syncscopes" , reduceAtomicSyncScopesDeltaPass) \
116- DELTA_PASS (" instruction-flags" , reduceInstructionFlagsDeltaPass) \
117- } while (false )
118-
119- #define DELTA_PASSES_MIR \
120- do { \
121- DELTA_PASS (" instructions" , reduceInstructionsMIRDeltaPass) \
122- DELTA_PASS (" ir-instruction-references" , \
123- reduceIRInstructionReferencesDeltaPass) \
124- DELTA_PASS (" ir-block-references" , reduceIRBlockReferencesDeltaPass) \
125- DELTA_PASS (" ir-function-references" , reduceIRFunctionReferencesDeltaPass) \
126- DELTA_PASS (" instruction-flags" , reduceInstructionFlagsMIRDeltaPass) \
127- DELTA_PASS (" register-uses" , reduceRegisterUsesMIRDeltaPass) \
128- DELTA_PASS (" register-defs" , reduceRegisterDefsMIRDeltaPass) \
129- DELTA_PASS (" register-hints" , reduceVirtualRegisterHintsDeltaPass) \
130- DELTA_PASS (" register-masks" , reduceRegisterMasksMIRDeltaPass) \
131- } while (false )
76+ // Generate two separate Pass lists: IR_Passes and MIR_Passes
77+ static const DeltaPass IR_Passes[] = {
78+ #undef DELTA_PASS_IR
79+ #undef DELTA_PASS_MIR
80+ #define DELTA_PASS_IR (NAME, FUNC, DESC ) {NAME, FUNC, DESC},
81+ #include " DeltaPasses.def"
82+ #undef DELTA_PASS_IR
83+ };
84+
85+ static const DeltaPass MIR_Passes[] = {
86+ #undef DELTA_PASS_IR
87+ #undef DELTA_PASS_MIR
88+ #define DELTA_PASS_MIR (NAME, FUNC, DESC ) {NAME, FUNC, DESC},
89+ #include " DeltaPasses.def"
90+ #undef DELTA_PASS_MIR
91+ };
92+
13293
13394static void runAllDeltaPasses (TestRunner &Tester,
13495 const SmallStringSet &SkipPass) {
135- #define DELTA_PASS (NAME, FUNC ) \
136- if (!SkipPass.count (NAME)) { \
137- FUNC (Tester); \
138- }
13996 if (Tester.getProgram ().isMIR ()) {
140- DELTA_PASSES_MIR;
97+ for (const DeltaPass &Pass : MIR_Passes) {
98+ if (!SkipPass.count (Pass.Name )) {
99+ SmallString<64 > Message;
100+ Message += Pass.Desc ;
101+ Message += " (" ;
102+ Message += Pass.Name ;
103+ Message += " )" ;
104+ Pass.Func (Tester,Message);
105+ }
106+ }
141107 } else {
142- DELTA_PASSES;
108+ for (const DeltaPass &Pass : IR_Passes) {
109+ if (!SkipPass.count (Pass.Name )) {
110+ SmallString<64 > Message;
111+ Message += Pass.Desc ;
112+ Message += " (" ;
113+ Message += Pass.Name ;
114+ Message += " )" ;
115+ Pass.Func (Tester,Message);
116+ }
117+ }
143118 }
144- #undef DELTA_PASS
145119}
146120
147121static void runDeltaPassName (TestRunner &Tester, StringRef PassName) {
148- #define DELTA_PASS (NAME, FUNC ) \
149- if (PassName == NAME) { \
150- FUNC (Tester); \
151- return ; \
152- }
153122 if (Tester.getProgram ().isMIR ()) {
154- DELTA_PASSES_MIR;
123+ for (const DeltaPass &Pass : MIR_Passes) {
124+ if (PassName == Pass.Name ) {
125+ SmallString<64 > Message;
126+ Message += Pass.Desc ;
127+ Message += " (" ;
128+ Message += Pass.Name ;
129+ Message += " )" ;
130+ Pass.Func (Tester,Message);
131+ return ;
132+ }
133+ }
155134 } else {
156- DELTA_PASSES;
135+ for (const DeltaPass &Pass : IR_Passes) {
136+ if (PassName == Pass.Name ) {
137+ SmallString<64 > Message;
138+ Message += Pass.Desc ;
139+ Message += " (" ;
140+ Message += Pass.Name ;
141+ Message += " )" ;
142+ Pass.Func (Tester,Message);
143+ return ;
144+ }
145+ }
157146 }
158- #undef DELTA_PASS
159147
160148 // We should have errored on unrecognized passes before trying to run
161149 // anything.
@@ -164,24 +152,25 @@ static void runDeltaPassName(TestRunner &Tester, StringRef PassName) {
164152
165153void llvm::printDeltaPasses (raw_ostream &OS) {
166154 OS << " Delta passes (pass to `--delta-passes=` as a comma separated list):\n " ;
167- #define DELTA_PASS (NAME, FUNC ) OS << " " << NAME << " \n " ;
168155 OS << " IR:\n " ;
169- DELTA_PASSES;
156+ for (const DeltaPass &Pass : IR_Passes) {
157+ OS << " " << Pass.Name << " \n " ;
158+ }
170159 OS << " MIR:\n " ;
171- DELTA_PASSES_MIR;
172- #undef DELTA_PASS
160+ for (const DeltaPass &Pass : MIR_Passes) {
161+ OS << " " << Pass.Name << " \n " ;
162+ }
173163}
174164
175165// Built a set of available delta passes.
176166static void collectPassNames (const TestRunner &Tester,
177167 SmallStringSet &NameSet) {
178- # define DELTA_PASS ( NAME, FUNC ) NameSet.insert(NAME);
179- if (Tester. getProgram (). isMIR ()) {
180- DELTA_PASSES_MIR;
181- } else {
182- DELTA_PASSES ;
168+ for ( const DeltaPass &Pass : MIR_Passes) {
169+ NameSet. insert (Pass. Name );
170+ }
171+ for ( const DeltaPass &Pass : IR_Passes) {
172+ NameSet. insert (Pass. Name ) ;
183173 }
184- #undef DELTA_PASS
185174}
186175
187176// / Verify all requested or skipped passes are valid names, and return them in a
0 commit comments