diff --git a/llvm/include/llvm/Target/GlobalISel/Combine.td b/llvm/include/llvm/Target/GlobalISel/Combine.td index b41185133d77..7803ce1b51ab 100644 --- a/llvm/include/llvm/Target/GlobalISel/Combine.td +++ b/llvm/include/llvm/Target/GlobalISel/Combine.td @@ -27,6 +27,11 @@ class GICombineGroup rules> : GICombine { let Rules = rules; } +class GICombinerHelperArg { + string Type = type; + string Name = name; +} + // Declares a combiner helper class class GICombinerHelper rules> : GICombineGroup { @@ -35,6 +40,9 @@ class GICombinerHelper rules> // The name of a run-time compiler option that will be generated to disable // specific rules within this combiner. string DisableRuleOption = ?; + // Any additional arguments that should be appended to the tryCombine*(). + list AdditionalArguments = + [GICombinerHelperArg<"CombinerHelper &", "Helper">]; } class GICombineRule : GICombine { /// Defines the external interface of the match rule. This includes: diff --git a/llvm/utils/TableGen/GICombinerEmitter.cpp b/llvm/utils/TableGen/GICombinerEmitter.cpp index 8c70ed157a58..761ca4b52614 100644 --- a/llvm/utils/TableGen/GICombinerEmitter.cpp +++ b/llvm/utils/TableGen/GICombinerEmitter.cpp @@ -841,6 +841,13 @@ void GICombinerEmitter::generateCodeForTree(raw_ostream &OS, OS << Indent << "return false;\n"; } +static void emitAdditionalHelperMethodArguments(raw_ostream &OS, + Record *Combiner) { + for (Record *Arg : Combiner->getValueAsListOfDefs("AdditionalArguments")) + OS << ",\n " << Arg->getValueAsString("Type") + << Arg->getValueAsString("Name"); +} + void GICombinerEmitter::run(raw_ostream &OS) { gatherRules(Rules, Combiner->getValueAsListOfDefs("Rules")); if (StopAfterParse) { @@ -901,9 +908,10 @@ void GICombinerEmitter::run(raw_ostream &OS) { << " bool tryCombineAll(\n" << " GISelChangeObserver &Observer,\n" << " MachineInstr &MI,\n" - << " MachineIRBuilder &B,\n" - << " CombinerHelper &Helper) const;\n" - << "};\n\n"; + << " MachineIRBuilder &B"; + emitAdditionalHelperMethodArguments(OS, Combiner); + OS << ") const;\n"; + OS << "};\n\n"; emitNameMatcher(OS); @@ -958,8 +966,9 @@ void GICombinerEmitter::run(raw_ostream &OS) { OS << "bool " << getClassName() << "::tryCombineAll(\n" << " GISelChangeObserver &Observer,\n" << " MachineInstr &MI,\n" - << " MachineIRBuilder &B,\n" - << " CombinerHelper &Helper) const {\n" + << " MachineIRBuilder &B"; + emitAdditionalHelperMethodArguments(OS, Combiner); + OS << ") const {\n" << " MachineBasicBlock *MBB = MI.getParent();\n" << " MachineFunction *MF = MBB->getParent();\n" << " MachineRegisterInfo &MRI = MF->getRegInfo();\n"