Skip to content

Commit

Permalink
[gicombiner] Allow generated CombinerHelpers to have additional argum…
Browse files Browse the repository at this point in the history
…ents

Summary:
This allows combiners to delegate to other helpers or depend
on additional information. It's not great as an overall
solution though as callers must provide the argument on every call, even for
static data like an additional helper. Another patch will follow to
support additional members of the generated combiner.

Reviewers: aditya_nandakumar, bogner, aemerson, paquette, volkan, arsenm

Reviewed By: aditya_nandakumar

Subscribers: wdng, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81862
  • Loading branch information
dsandersllvm committed Jun 16, 2020
1 parent 6f2943f commit 28ebdf1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 8 additions & 0 deletions llvm/include/llvm/Target/GlobalISel/Combine.td
Expand Up @@ -27,6 +27,11 @@ class GICombineGroup<list<GICombine> rules> : GICombine {
let Rules = rules;
}

class GICombinerHelperArg<string type, string name> {
string Type = type;
string Name = name;
}

// Declares a combiner helper class
class GICombinerHelper<string classname, list<GICombine> rules>
: GICombineGroup<rules> {
Expand All @@ -35,6 +40,9 @@ class GICombinerHelper<string classname, list<GICombine> 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<GICombinerHelperArg> AdditionalArguments =
[GICombinerHelperArg<"CombinerHelper &", "Helper">];
}
class GICombineRule<dag defs, dag match, dag apply> : GICombine {
/// Defines the external interface of the match rule. This includes:
Expand Down
19 changes: 14 additions & 5 deletions llvm/utils/TableGen/GICombinerEmitter.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 28ebdf1

Please sign in to comment.