-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[GlobalISel][TableGen] MIR Pattern Variadics #100563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
de9e0f1
0228658
55115ea
656de90
7b85b21
3928160
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,19 +28,48 @@ def InstTest3 : GICombineRule< | |
(match (G_UNMERGE_VALUES $a, $b, $c, $d)), | ||
(apply [{ APPLY }])>; | ||
|
||
def VariadicTypeTestCxx : GICombineRule< | ||
(defs root:$a), | ||
(match (G_BUILD_VECTOR $a, GIVariadic<2, 4>:$b)), | ||
(apply [{ ${b} }])>; | ||
|
||
def VariadicTypeTestReuse : GICombineRule< | ||
(defs root:$a), | ||
(match (G_BUILD_VECTOR $a, $c, GIVariadic<2, 4>:$b)), | ||
(apply (G_MERGE_VALUES $a, $b, $c))>; | ||
|
||
def MyCombiner: GICombiner<"GenMyCombiner", [ | ||
InstTest0, | ||
InstTest1, | ||
InstTest2, | ||
InstTest3 | ||
InstTest3, | ||
VariadicTypeTestCxx, | ||
VariadicTypeTestReuse | ||
]>; | ||
|
||
// CHECK: bool GenMyCombiner::runCustomAction(unsigned ApplyID, const MatcherState &State, NewMIVector &OutMIs) const { | ||
// CHECK-NEXT: Helper.getBuilder().setInstrAndDebugLoc(*State.MIs[0]); | ||
// CHECK-NEXT: switch(ApplyID) { | ||
// CHECK-NEXT: case GICXXCustomAction_GICombiner0:{ | ||
// CHECK-NEXT: // Apply Patterns | ||
// CHECK-NEXT: APPLY | ||
// CHECK-NEXT: return true; | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: case GICXXCustomAction_GICombiner1:{ | ||
// CHECK-NEXT: // Apply Patterns | ||
// CHECK-NEXT: getRemainingOperands(*State.MIs[0], 1) | ||
// CHECK-NEXT: return true; | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: llvm_unreachable("Unknown Apply Action"); | ||
// CHECK-NEXT: } | ||
|
||
// CHECK: const uint8_t *GenMyCombiner::getMatchTable() const { | ||
// CHECK-NEXT: constexpr static uint8_t MatchTable0[] = { | ||
// CHECK-NEXT: GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2([[#LOWER:]]), GIMT_Encode2([[#UPPER:]]), /*)*//*default:*//*Label 2*/ GIMT_Encode4([[#DEFAULT:]]), | ||
// CHECK-NEXT: GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(70), GIMT_Encode2(74), /*)*//*default:*//*Label 2*/ GIMT_Encode4(127), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change from using a "regex" to hard coding the numbers is causing the test to fail in our downstream repo. Is there a reason why we cannot update the previous test variables instead of just hard coding values in here for this test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no reason, I just forgot that those tests were changed to use regexes and I generally update them by copy-pasting the output of tblgen. I will make a patch to fix it. |
||
// CHECK-NEXT: /*TargetOpcode::G_UNMERGE_VALUES*//*Label 0*/ GIMT_Encode4(26), GIMT_Encode4(0), GIMT_Encode4(0), | ||
// CHECK-NEXT: /*TargetOpcode::G_BUILD_VECTOR*//*Label 1*/ GIMT_Encode4(55), | ||
// CHECK-NEXT: // Label 0: @[[#%u, mul(UPPER-LOWER, 4) + 10]] | ||
// CHECK-NEXT: // Label 0: @26 | ||
// CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 3*/ GIMT_Encode4(40), // Rule ID 2 // | ||
// CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule2Enabled), | ||
// CHECK-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/2, | ||
|
@@ -77,7 +106,35 @@ def MyCombiner: GICombiner<"GenMyCombiner", [ | |
// CHECK-NEXT: // Combiner Rule #1: InstTest1 | ||
// CHECK-NEXT: GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner0), | ||
// CHECK-NEXT: // Label 5: @69 | ||
// CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 6*/ GIMT_Encode4(83), // Rule ID 0 // | ||
// CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 6*/ GIMT_Encode4(86), // Rule ID 4 // | ||
// CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule4Enabled), | ||
// CHECK-NEXT: GIM_CheckNumOperandsGE, /*MI*/0, /*Expected*/3, | ||
// CHECK-NEXT: GIM_CheckNumOperandsLE, /*MI*/0, /*Expected*/5, | ||
// CHECK-NEXT: // MIs[0] a | ||
// CHECK-NEXT: // No operand predicates | ||
// CHECK-NEXT: // MIs[0] b | ||
// CHECK-NEXT: // No operand predicates | ||
// CHECK-NEXT: // Combiner Rule #4: VariadicTypeTestCxx | ||
// CHECK-NEXT: GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner1), | ||
// CHECK-NEXT: // Label 6: @86 | ||
// CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 7*/ GIMT_Encode4(112), // Rule ID 5 // | ||
// CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule5Enabled), | ||
// CHECK-NEXT: GIM_CheckNumOperandsGE, /*MI*/0, /*Expected*/4, | ||
// CHECK-NEXT: GIM_CheckNumOperandsLE, /*MI*/0, /*Expected*/6, | ||
// CHECK-NEXT: // MIs[0] a | ||
// CHECK-NEXT: // No operand predicates | ||
// CHECK-NEXT: // MIs[0] c | ||
// CHECK-NEXT: // No operand predicates | ||
// CHECK-NEXT: // MIs[0] b | ||
// CHECK-NEXT: // No operand predicates | ||
// CHECK-NEXT: // Combiner Rule #5: VariadicTypeTestReuse | ||
// CHECK-NEXT: GIR_BuildRootMI, /*Opcode*/GIMT_Encode2(TargetOpcode::G_MERGE_VALUES), | ||
// CHECK-NEXT: GIR_RootToRootCopy, /*OpIdx*/0, // a | ||
// CHECK-NEXT: GIR_CopyRemaining, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/2, // b | ||
// CHECK-NEXT: GIR_RootToRootCopy, /*OpIdx*/1, // c | ||
// CHECK-NEXT: GIR_EraseRootFromParent_Done, | ||
// CHECK-NEXT: // Label 7: @112 | ||
// CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 8*/ GIMT_Encode4(126), // Rule ID 0 // | ||
// CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule0Enabled), | ||
// CHECK-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/4, | ||
// CHECK-NEXT: // MIs[0] a | ||
|
@@ -90,10 +147,10 @@ def MyCombiner: GICombiner<"GenMyCombiner", [ | |
// CHECK-NEXT: // No operand predicates | ||
// CHECK-NEXT: // Combiner Rule #0: InstTest0 | ||
// CHECK-NEXT: GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner0), | ||
// CHECK-NEXT: // Label 6: @83 | ||
// CHECK-NEXT: // Label 8: @126 | ||
// CHECK-NEXT: GIM_Reject, | ||
// CHECK-NEXT: // Label 2: @[[#%u, DEFAULT]] | ||
// CHECK-NEXT: // Label 2: @127 | ||
// CHECK-NEXT: GIM_Reject, | ||
// CHECK-NEXT: }; // Size: [[#%u, DEFAULT + 1]] bytes | ||
// CHECK-NEXT: }; // Size: 128 bytes | ||
// CHECK-NEXT: return MatchTable0; | ||
// CHECK-NEXT: } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include an example of unpacking the first N args? Like
G_BUILD_VECTOR $root, $srca, $srcb, ...:$remainder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not yet implemented for MIR patterns. In C++ you can just convert the iterator_range to an ArrayRef I think.
I need some ideas on how to proceed
What kind of operations do we want?
Coming up with some example patterns would greatly help. I'm not sure how unpacking would be used in practice, because we don't have loops, so we can't do things like "for each element, emit this"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that what's going in in VariadicTypeTestReuse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that just takes the N matched operands and puts them at a different position in the output instruction.
So
$b
can represent 2 to 4 operands, and the output instruction has $a, $b (so 2 to 4 operands being put here), and $cIt's a test to check that in apply patterns, a matched variadic can go anywhere, but in a match pattern it can only go at the end
Note that this whole thing is very much a prototype implementation, I put it up for review to discuss things like this and refine it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you spell out the signature of
checkBuildVectorToUnmerge
? In particular, I am interested in the argument type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought
ArrayRef<MachineOperand>
would work out of the box but to my surprise,ArrayRef
did not have a constructor fromiterator_range
. I tried adding one, but after 10 minutes of fighting templates (because we'd need one for both const and non-const ranges, and it apparently doesn't work), I gave up and made a helper function to do the conversion.So now it's really just a
ArrayRef<MachineOperand>
, created throughGIMatchTableExecutor::getVariadicOperands
.