|
| 1 | +// RUN: llvm-tblgen -I %p/../../../include -gen-global-isel-combiner \ |
| 2 | +// RUN: -combiners=MyCombiner %s | \ |
| 3 | +// RUN: FileCheck %s |
| 4 | + |
| 5 | +include "llvm/Target/Target.td" |
| 6 | +include "llvm/Target/GlobalISel/Combine.td" |
| 7 | + |
| 8 | +def MyTargetISA : InstrInfo; |
| 9 | +def MyTarget : Target { let InstructionSet = MyTargetISA; } |
| 10 | + |
| 11 | +def OneMatchOneApply : GICombineRule< |
| 12 | + (defs root:$a), |
| 13 | + (match (G_FABS $a, $b), "return MATCH0;"), |
| 14 | + (apply "APPLY0")>; |
| 15 | + |
| 16 | +def TwoMatchTwoApply : GICombineRule< |
| 17 | + (defs root:$a), |
| 18 | + (match (G_FNEG $a, $b), "return MATCH0;", "return MATCH1;"), |
| 19 | + (apply "APPLY0", "APPLY1")>; |
| 20 | + |
| 21 | +def TwoMatchNoApply : GICombineRule< |
| 22 | + (defs root:$a), |
| 23 | + (match (G_STORE $x, $y):$a, "return MATCH0;", "return MATCH1;"), |
| 24 | + (apply (GIEraseRoot))>; |
| 25 | + |
| 26 | +def NoMatchTwoApply : GICombineRule< |
| 27 | + (defs root:$a), |
| 28 | + (match (G_SEXT $a, $y)), |
| 29 | + (apply "APPLY0", "APPLY1")>; |
| 30 | + |
| 31 | +def MyCombiner: GICombiner<"GenMyCombiner", [ |
| 32 | + OneMatchOneApply, |
| 33 | + TwoMatchTwoApply, |
| 34 | + TwoMatchNoApply, |
| 35 | + NoMatchTwoApply |
| 36 | +]>; |
| 37 | + |
| 38 | +// CHECK: bool GenMyCombiner::testMIPredicate_MI(unsigned PredicateID, const MachineInstr & MI, const MatcherState &State) const { |
| 39 | +// CHECK-NEXT: switch (PredicateID) { |
| 40 | +// CHECK-NEXT: case GICXXPred_MI_Predicate_GICombiner0: { |
| 41 | +// CHECK-NEXT: return MATCH0; |
| 42 | +// CHECK-NEXT: } |
| 43 | +// CHECK-NEXT: case GICXXPred_MI_Predicate_GICombiner1: { |
| 44 | +// CHECK-NEXT: return MATCH1; |
| 45 | +// CHECK-NEXT: } |
| 46 | +// CHECK-NEXT: } |
| 47 | +// CHECK-NEXT: llvm_unreachable("Unknown predicate"); |
| 48 | +// CHECK-NEXT: return false; |
| 49 | +// CHECK-NEXT: } |
| 50 | + |
| 51 | +// CHECK: bool GenMyCombiner::runCustomAction(unsigned ApplyID, const MatcherState &State, NewMIVector &OutMIs) const { |
| 52 | +// CHECK-NEXT: Helper.getBuilder().setInstrAndDebugLoc(*State.MIs[0]); |
| 53 | +// CHECK-NEXT: switch(ApplyID) { |
| 54 | +// CHECK-NEXT: case GICXXCustomAction_GICombiner0:{ |
| 55 | +// CHECK-NEXT: // Match Patterns |
| 56 | +// CHECK-NEXT: if(![&](){return MATCH0;}()) { |
| 57 | +// CHECK-NEXT: return false; |
| 58 | +// CHECK-NEXT: } |
| 59 | +// CHECK-NEXT: // Apply Patterns |
| 60 | +// CHECK-NEXT: APPLY0 |
| 61 | +// CHECK-NEXT: return true; |
| 62 | +// CHECK-NEXT: } |
| 63 | +// CHECK-NEXT: case GICXXCustomAction_GICombiner1:{ |
| 64 | +// CHECK-NEXT: // Match Patterns |
| 65 | +// CHECK-NEXT: if(![&](){return MATCH0;}()) { |
| 66 | +// CHECK-NEXT: return false; |
| 67 | +// CHECK-NEXT: } |
| 68 | +// CHECK-NEXT: if(![&](){return MATCH1;}()) { |
| 69 | +// CHECK-NEXT: return false; |
| 70 | +// CHECK-NEXT: } |
| 71 | +// CHECK-NEXT: // Apply Patterns |
| 72 | +// CHECK-NEXT: APPLY0 |
| 73 | +// CHECK-NEXT: APPLY1 |
| 74 | +// CHECK-NEXT: return true; |
| 75 | +// CHECK-NEXT: } |
| 76 | +// CHECK-NEXT: case GICXXCustomAction_GICombiner2:{ |
| 77 | +// CHECK-NEXT: // Apply Patterns |
| 78 | +// CHECK-NEXT: APPLY0 |
| 79 | +// CHECK-NEXT: APPLY1 |
| 80 | +// CHECK-NEXT: return true; |
| 81 | +// CHECK-NEXT: } |
| 82 | +// CHECK-NEXT: } |
| 83 | +// CHECK-NEXT: llvm_unreachable("Unknown Apply Action"); |
| 84 | +// CHECK-NEXT: } |
| 85 | + |
| 86 | +// CHECK: const uint8_t *GenMyCombiner::getMatchTable() const { |
| 87 | +// CHECK-NEXT: constexpr static uint8_t MatchTable0[] = { |
| 88 | +// CHECK-NEXT: GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(94), GIMT_Encode2(194), /*)*//*default:*//*Label 4*/ GIMT_Encode4(464), |
| 89 | +// CHECK-NEXT: /*TargetOpcode::G_STORE*//*Label 0*/ GIMT_Encode4(410), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), |
| 90 | +// CHECK-NEXT: /*TargetOpcode::G_SEXT*//*Label 1*/ GIMT_Encode4(428), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), |
| 91 | +// CHECK-NEXT: /*TargetOpcode::G_FNEG*//*Label 2*/ GIMT_Encode4(440), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), |
| 92 | +// CHECK-NEXT: /*TargetOpcode::G_FABS*//*Label 3*/ GIMT_Encode4(452), |
| 93 | +// CHECK-NEXT: // Label 0: @410 |
| 94 | +// CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 5*/ GIMT_Encode4(427), // Rule ID 2 // |
| 95 | +// CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule2Enabled), |
| 96 | +// CHECK-NEXT: // MIs[0] x |
| 97 | +// CHECK-NEXT: // No operand predicates |
| 98 | +// CHECK-NEXT: // MIs[0] y |
| 99 | +// CHECK-NEXT: // No operand predicates |
| 100 | +// CHECK-NEXT: GIM_CheckCxxInsnPredicate, /*MI*/0, /*FnId*/GIMT_Encode2(GICXXPred_MI_Predicate_GICombiner0), |
| 101 | +// CHECK-NEXT: GIM_CheckCxxInsnPredicate, /*MI*/0, /*FnId*/GIMT_Encode2(GICXXPred_MI_Predicate_GICombiner1), |
| 102 | +// CHECK-NEXT: // Combiner Rule #2: TwoMatchNoApply |
| 103 | +// CHECK-NEXT: GIR_EraseRootFromParent_Done, |
| 104 | +// CHECK-NEXT: // Label 5: @427 |
| 105 | +// CHECK-NEXT: GIM_Reject, |
| 106 | +// CHECK-NEXT: // Label 1: @428 |
| 107 | +// CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 6*/ GIMT_Encode4(439), // Rule ID 3 // |
| 108 | +// CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule3Enabled), |
| 109 | +// CHECK-NEXT: // MIs[0] a |
| 110 | +// CHECK-NEXT: // No operand predicates |
| 111 | +// CHECK-NEXT: // MIs[0] y |
| 112 | +// CHECK-NEXT: // No operand predicates |
| 113 | +// CHECK-NEXT: // Combiner Rule #3: NoMatchTwoApply |
| 114 | +// CHECK-NEXT: GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner2), |
| 115 | +// CHECK-NEXT: // Label 6: @439 |
| 116 | +// CHECK-NEXT: GIM_Reject, |
| 117 | +// CHECK-NEXT: // Label 2: @440 |
| 118 | +// CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 7*/ GIMT_Encode4(451), // Rule ID 1 // |
| 119 | +// CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule1Enabled), |
| 120 | +// CHECK-NEXT: // MIs[0] a |
| 121 | +// CHECK-NEXT: // No operand predicates |
| 122 | +// CHECK-NEXT: // MIs[0] b |
| 123 | +// CHECK-NEXT: // No operand predicates |
| 124 | +// CHECK-NEXT: // Combiner Rule #1: TwoMatchTwoApply |
| 125 | +// CHECK-NEXT: GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner1), |
| 126 | +// CHECK-NEXT: // Label 7: @451 |
| 127 | +// CHECK-NEXT: GIM_Reject, |
| 128 | +// CHECK-NEXT: // Label 3: @452 |
| 129 | +// CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 8*/ GIMT_Encode4(463), // Rule ID 0 // |
| 130 | +// CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule0Enabled), |
| 131 | +// CHECK-NEXT: // MIs[0] a |
| 132 | +// CHECK-NEXT: // No operand predicates |
| 133 | +// CHECK-NEXT: // MIs[0] b |
| 134 | +// CHECK-NEXT: // No operand predicates |
| 135 | +// CHECK-NEXT: // Combiner Rule #0: OneMatchOneApply |
| 136 | +// CHECK-NEXT: GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner0), |
| 137 | +// CHECK-NEXT: // Label 8: @463 |
| 138 | +// CHECK-NEXT: GIM_Reject, |
| 139 | +// CHECK-NEXT: // Label 4: @464 |
| 140 | +// CHECK-NEXT: GIM_Reject, |
| 141 | +// CHECK-NEXT: }; // Size: 465 bytes |
| 142 | +// CHECK-NEXT: return MatchTable0; |
| 143 | +// CHECK-NEXT: } |
0 commit comments