1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|* *|
3|* SPIRVPreLegalizerCombinerImpl Combiner Match Table *|
4|* *|
5|* Automatically generated file, do not edit! *|
6|* *|
7\*===----------------------------------------------------------------------===*/
8
9#ifdef GET_GICOMBINER_DEPS
10#include "llvm/ADT/SparseBitVector.h"
11namespace llvm {
12extern cl::OptionCategory GICombinerOptionCategory;
13} // end namespace llvm
14#endif // ifdef GET_GICOMBINER_DEPS
15
16#ifdef GET_GICOMBINER_TYPES
17struct SPIRVPreLegalizerCombinerImplRuleConfig {
18 SparseBitVector<> DisabledRules;
19
20 bool isRuleEnabled(unsigned RuleID) const;
21 bool parseCommandLineOption();
22 bool setRuleEnabled(StringRef RuleIdentifier);
23 bool setRuleDisabled(StringRef RuleIdentifier);
24};
25
26static std::optional<uint64_t> getRuleIdxForIdentifier(StringRef RuleIdentifier) {
27 uint64_t I;
28 // getAtInteger(...) returns false on success
29 bool Parsed = !RuleIdentifier.getAsInteger(0, I);
30 if (Parsed)
31 return I;
32
33#ifndef NDEBUG
34 switch (RuleIdentifier.size()) {
35 default: break;
36 case 24: // 1 string to match.
37 if (memcmp(RuleIdentifier.data()+0, "matrix_multiply_lowering", 24) != 0)
38 break;
39 return 3; // "matrix_multiply_lowering"
40 case 25: // 1 string to match.
41 if (memcmp(RuleIdentifier.data()+0, "matrix_transpose_lowering", 25) != 0)
42 break;
43 return 2; // "matrix_transpose_lowering"
44 case 37: // 1 string to match.
45 if (memcmp(RuleIdentifier.data()+0, "vector_select_to_faceforward_lowering", 37) != 0)
46 break;
47 return 1; // "vector_select_to_faceforward_lowering"
48 case 38: // 1 string to match.
49 if (memcmp(RuleIdentifier.data()+0, "vector_length_sub_to_distance_lowering", 38) != 0)
50 break;
51 return 0; // "vector_length_sub_to_distance_lowering"
52 }
53#endif // ifndef NDEBUG
54
55 return std::nullopt;
56}
57static std::optional<std::pair<uint64_t, uint64_t>> getRuleRangeForIdentifier(StringRef RuleIdentifier) {
58 std::pair<StringRef, StringRef> RangePair = RuleIdentifier.split('-');
59 if (!RangePair.second.empty()) {
60 const auto First = getRuleIdxForIdentifier(RangePair.first);
61 const auto Last = getRuleIdxForIdentifier(RangePair.second);
62 if (!First || !Last)
63 return std::nullopt;
64 if (First >= Last)
65 report_fatal_error("Beginning of range should be before end of range");
66 return {{*First, *Last + 1}};
67 }
68 if (RangePair.first == "*") {
69 return {{0, 4}};
70 }
71 const auto I = getRuleIdxForIdentifier(RangePair.first);
72 if (!I)
73 return std::nullopt;
74 return {{*I, *I + 1}};
75}
76
77bool SPIRVPreLegalizerCombinerImplRuleConfig::setRuleEnabled(StringRef RuleIdentifier) {
78 auto MaybeRange = getRuleRangeForIdentifier(RuleIdentifier);
79 if (!MaybeRange)
80 return false;
81 for (auto I = MaybeRange->first; I < MaybeRange->second; ++I)
82 DisabledRules.reset(I);
83 return true;
84}
85
86bool SPIRVPreLegalizerCombinerImplRuleConfig::setRuleDisabled(StringRef RuleIdentifier) {
87 auto MaybeRange = getRuleRangeForIdentifier(RuleIdentifier);
88 if (!MaybeRange)
89 return false;
90 for (auto I = MaybeRange->first; I < MaybeRange->second; ++I)
91 DisabledRules.set(I);
92 return true;
93}
94
95static std::vector<std::string> SPIRVPreLegalizerCombinerOption;
96static cl::list<std::string> SPIRVPreLegalizerCombinerDisableOption(
97 "spirvprelegalizercombiner-disable-rule",
98 cl::desc("Disable one or more combiner rules temporarily in the SPIRVPreLegalizerCombiner pass"),
99 cl::CommaSeparated,
100 cl::Hidden,
101 cl::cat(GICombinerOptionCategory),
102 cl::callback([](const std::string &Str) {
103 SPIRVPreLegalizerCombinerOption.push_back(Str);
104 }));
105static cl::list<std::string> SPIRVPreLegalizerCombinerOnlyEnableOption(
106 "spirvprelegalizercombiner-only-enable-rule",
107 cl::desc("Disable all rules in the SPIRVPreLegalizerCombiner pass then re-enable the specified ones"),
108 cl::Hidden,
109 cl::cat(GICombinerOptionCategory),
110 cl::callback([](const std::string &CommaSeparatedArg) {
111 StringRef Str = CommaSeparatedArg;
112 SPIRVPreLegalizerCombinerOption.push_back("*");
113 do {
114 auto X = Str.split(",");
115 SPIRVPreLegalizerCombinerOption.push_back(("!" + X.first).str());
116 Str = X.second;
117 } while (!Str.empty());
118 }));
119
120
121bool SPIRVPreLegalizerCombinerImplRuleConfig::isRuleEnabled(unsigned RuleID) const {
122 return !DisabledRules.test(RuleID);
123}
124bool SPIRVPreLegalizerCombinerImplRuleConfig::parseCommandLineOption() {
125 for (StringRef Identifier : SPIRVPreLegalizerCombinerOption) {
126 bool Enabled = Identifier.consume_front("!");
127 if (Enabled && !setRuleEnabled(Identifier))
128 return false;
129 if (!Enabled && !setRuleDisabled(Identifier))
130 return false;
131 }
132 return true;
133}
134
135#endif // ifdef GET_GICOMBINER_TYPES
136
137#ifdef GET_GICOMBINER_TYPES
138const unsigned MAX_SUBTARGET_PREDICATES = 0;
139using PredicateBitset = llvm::Bitset<MAX_SUBTARGET_PREDICATES>;
140#endif // ifdef GET_GICOMBINER_TYPES
141
142#ifdef GET_GICOMBINER_CLASS_MEMBERS
143PredicateBitset AvailableModuleFeatures;
144mutable PredicateBitset AvailableFunctionFeatures;
145PredicateBitset getAvailableFeatures() const {
146 return AvailableModuleFeatures | AvailableFunctionFeatures;
147}
148PredicateBitset
149computeAvailableModuleFeatures(const SPIRVSubtarget *Subtarget) const;
150PredicateBitset
151computeAvailableFunctionFeatures(const SPIRVSubtarget *Subtarget,
152 const MachineFunction *MF) const;
153void setupGeneratedPerFunctionState(MachineFunction &MF) override;
154#endif // ifdef GET_GICOMBINER_CLASS_MEMBERS
155#ifdef GET_GICOMBINER_CLASS_MEMBERS
156 mutable MatcherState State;
157 typedef ComplexRendererFns(SPIRVPreLegalizerCombinerImpl::*ComplexMatcherMemFn)(MachineOperand &) const;
158 typedef void(SPIRVPreLegalizerCombinerImpl::*CustomRendererFn)(MachineInstrBuilder &, const MachineInstr &, int) const;
159 const ExecInfoTy<PredicateBitset, ComplexMatcherMemFn, CustomRendererFn> ExecInfo;
160 static SPIRVPreLegalizerCombinerImpl::ComplexMatcherMemFn ComplexPredicateFns[];
161 static SPIRVPreLegalizerCombinerImpl::CustomRendererFn CustomRenderers[];
162 bool testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const override;
163 bool testImmPredicate_APInt(unsigned PredicateID, const APInt &Imm) const override;
164 bool testImmPredicate_APFloat(unsigned PredicateID, const APFloat &Imm) const override;
165 const uint8_t *getMatchTable() const override;
166 bool testMIPredicate_MI(unsigned PredicateID, const MachineInstr &MI, const MatcherState &State) const override;
167 bool testMOPredicate_MO(unsigned PredicateID, const MachineOperand &MO, const MatcherState &State) const override;
168 bool testSimplePredicate(unsigned PredicateID) const override;
169 bool runCustomAction(unsigned FnID, const MatcherState &State, NewMIVector &OutMIs) const override;
170#endif // ifdef GET_GICOMBINER_CLASS_MEMBERS
171
172#ifdef GET_GICOMBINER_IMPL
173// LLT Objects.
174enum {
175 GILLT_s1,
176};
177const static size_t NumTypeObjects = 1;
178const static LLT TypeObjects[] = {
179 LLT::scalar(1),
180};
181
182// Bits for subtarget features that participate in instruction matching.
183enum SubtargetFeatureBits : uint8_t {
184};
185
186PredicateBitset SPIRVPreLegalizerCombinerImpl::
187computeAvailableModuleFeatures(const SPIRVSubtarget *Subtarget) const {
188 PredicateBitset Features{};
189 return Features;
190}
191
192void SPIRVPreLegalizerCombinerImpl::setupGeneratedPerFunctionState(MachineFunction &MF) {
193 AvailableFunctionFeatures = computeAvailableFunctionFeatures((const SPIRVSubtarget *)&MF.getSubtarget(), &MF);
194}
195PredicateBitset SPIRVPreLegalizerCombinerImpl::
196computeAvailableFunctionFeatures(const SPIRVSubtarget *Subtarget, const MachineFunction *MF) const {
197 PredicateBitset Features{};
198 return Features;
199}
200
201// Feature bitsets.
202enum {
203 GIFBS_Invalid,
204};
205constexpr static PredicateBitset FeatureBitsets[] {
206 {}, // GIFBS_Invalid
207};
208
209// ComplexPattern predicates.
210enum {
211 GICP_Invalid,
212};
213// See constructor for table contents
214
215SPIRVPreLegalizerCombinerImpl::ComplexMatcherMemFn
216SPIRVPreLegalizerCombinerImpl::ComplexPredicateFns[] = {
217 nullptr, // GICP_Invalid
218};
219
220bool SPIRVPreLegalizerCombinerImpl::testMIPredicate_MI(unsigned PredicateID, const MachineInstr & MI, const MatcherState &State) const {
221 llvm_unreachable("Unknown predicate");
222 return false;
223}
224bool SPIRVPreLegalizerCombinerImpl::testMOPredicate_MO(unsigned PredicateID, const MachineOperand & MO, const MatcherState &State) const {
225 llvm_unreachable("Unknown predicate");
226 return false;
227}
228bool SPIRVPreLegalizerCombinerImpl::testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const {
229 llvm_unreachable("Unknown predicate");
230 return false;
231}
232bool SPIRVPreLegalizerCombinerImpl::testImmPredicate_APFloat(unsigned PredicateID, const APFloat & Imm) const {
233 llvm_unreachable("Unknown predicate");
234 return false;
235}
236bool SPIRVPreLegalizerCombinerImpl::testImmPredicate_APInt(unsigned PredicateID, const APInt & Imm) const {
237 llvm_unreachable("Unknown predicate");
238 return false;
239}
240enum {
241 GICXXPred_Simple_IsRule0Enabled = GICXXPred_Invalid + 1,
242 GICXXPred_Simple_IsRule1Enabled,
243 GICXXPred_Simple_IsRule2Enabled,
244 GICXXPred_Simple_IsRule3Enabled,
245};
246
247bool SPIRVPreLegalizerCombinerImpl::testSimplePredicate(unsigned Predicate) const {
248 return RuleConfig.isRuleEnabled(Predicate - GICXXPred_Invalid - 1);
249}
250// Custom renderers.
251enum {
252 GICR_Invalid,
253};
254SPIRVPreLegalizerCombinerImpl::CustomRendererFn
255SPIRVPreLegalizerCombinerImpl::CustomRenderers[] = {
256 nullptr, // GICR_Invalid
257};
258
259bool SPIRVPreLegalizerCombinerImpl::tryCombineAllImpl(MachineInstr &I) const {
260 const TargetSubtargetInfo &ST = MF.getSubtarget();
261 const PredicateBitset AvailableFeatures = getAvailableFeatures();
262 B.setInstrAndDebugLoc(I);
263 State.MIs.clear();
264 State.MIs.push_back(&I);
265 if (executeMatchTable(*this, State, ExecInfo, B, getMatchTable(), *ST.getInstrInfo(), MRI, *MRI.getTargetRegisterInfo(), *ST.getRegBankInfo(), AvailableFeatures, /*CoverageInfo*/ nullptr)) {
266 return true;
267 }
268
269 return false;
270}
271
272enum {
273 GICXXCustomAction_GICombiner0 = GICXXCustomAction_Invalid + 1,
274 GICXXCustomAction_GICombiner1,
275 GICXXCustomAction_GICombiner2,
276 GICXXCustomAction_GICombiner3,
277};
278bool SPIRVPreLegalizerCombinerImpl::runCustomAction(unsigned ApplyID, const MatcherState &State, NewMIVector &OutMIs) const {
279 Helper.getBuilder().setInstrAndDebugLoc(*State.MIs[0]);
280 switch(ApplyID) {
281 case GICXXCustomAction_GICombiner0:{
282 // Match Patterns
283 if(![&](){return Helper.matchLengthToDistance(*State.MIs[0]);}()) {
284 return false;
285 }
286 // Apply Patterns
287 Helper.applySPIRVDistance(*State.MIs[0]);
288 return true;
289 }
290 case GICXXCustomAction_GICombiner1:{
291 // Match Patterns
292 if(![&](){return Helper.matchSelectToFaceForward(*State.MIs[0]);}()) {
293 return false;
294 }
295 // Apply Patterns
296 Helper.applySPIRVFaceForward(*State.MIs[0]);
297 return true;
298 }
299 case GICXXCustomAction_GICombiner2:{
300 // Match Patterns
301 if(![&](){return Helper.matchMatrixTranspose(*State.MIs[0]);}()) {
302 return false;
303 }
304 // Apply Patterns
305 Helper.applyMatrixTranspose(*State.MIs[0]);
306 return true;
307 }
308 case GICXXCustomAction_GICombiner3:{
309 // Match Patterns
310 if(![&](){return Helper.matchMatrixMultiply(*State.MIs[0]);}()) {
311 return false;
312 }
313 // Apply Patterns
314 Helper.applyMatrixMultiply(*State.MIs[0]);
315 return true;
316 }
317 }
318 llvm_unreachable("Unknown Apply Action");
319}
320#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
321#define GIMT_Encode2(Val) uint8_t(Val), uint8_t((Val) >> 8)
322#define GIMT_Encode4(Val) uint8_t(Val), uint8_t((Val) >> 8), uint8_t((Val) >> 16), uint8_t((Val) >> 24)
323#define GIMT_Encode8(Val) uint8_t(Val), uint8_t((Val) >> 8), uint8_t((Val) >> 16), uint8_t((Val) >> 24), uint8_t(uint64_t(Val) >> 32), uint8_t(uint64_t(Val) >> 40), uint8_t(uint64_t(Val) >> 48), uint8_t(uint64_t(Val) >> 56)
324#else
325#define GIMT_Encode2(Val) uint8_t((Val) >> 8), uint8_t(Val)
326#define GIMT_Encode4(Val) uint8_t((Val) >> 24), uint8_t((Val) >> 16), uint8_t((Val) >> 8), uint8_t(Val)
327#define GIMT_Encode8(Val) uint8_t(uint64_t(Val) >> 56), uint8_t(uint64_t(Val) >> 48), uint8_t(uint64_t(Val) >> 40), uint8_t(uint64_t(Val) >> 32), uint8_t((Val) >> 24), uint8_t((Val) >> 16), uint8_t((Val) >> 8), uint8_t(Val)
328#endif
329const uint8_t *SPIRVPreLegalizerCombinerImpl::getMatchTable() const {
330 constexpr static uint8_t MatchTable0[] = {
331 /* 0 */ GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(135), GIMT_Encode2(163), /*)*//*default:*//*Label 2*/ GIMT_Encode4(168),
332 /* 10 */ /*TargetOpcode::G_INTRINSIC*//*Label 0*/ GIMT_Encode4(122), 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),
333 /* 118 */ /*TargetOpcode::G_SELECT*//*Label 1*/ GIMT_Encode4(156),
334 /* 122 */ // Label 0: @122
335 /* 122 */ GIM_Try, /*On fail goto*//*Label 3*/ GIMT_Encode4(133), // Rule ID 0 //
336 /* 127 */ GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule0Enabled),
337 /* 130 */ // Combiner Rule #0: vector_length_sub_to_distance_lowering; wip_match_opcode 'G_INTRINSIC'
338 /* 130 */ GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner0),
339 /* 133 */ // Label 3: @133
340 /* 133 */ GIM_Try, /*On fail goto*//*Label 4*/ GIMT_Encode4(144), // Rule ID 2 //
341 /* 138 */ GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule2Enabled),
342 /* 141 */ // Combiner Rule #2: matrix_transpose_lowering; wip_match_opcode 'G_INTRINSIC'
343 /* 141 */ GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner2),
344 /* 144 */ // Label 4: @144
345 /* 144 */ GIM_Try, /*On fail goto*//*Label 5*/ GIMT_Encode4(155), // Rule ID 3 //
346 /* 149 */ GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule3Enabled),
347 /* 152 */ // Combiner Rule #3: matrix_multiply_lowering; wip_match_opcode 'G_INTRINSIC'
348 /* 152 */ GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner3),
349 /* 155 */ // Label 5: @155
350 /* 155 */ GIM_Reject,
351 /* 156 */ // Label 1: @156
352 /* 156 */ GIM_Try, /*On fail goto*//*Label 6*/ GIMT_Encode4(167), // Rule ID 1 //
353 /* 161 */ GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule1Enabled),
354 /* 164 */ // Combiner Rule #1: vector_select_to_faceforward_lowering; wip_match_opcode 'G_SELECT'
355 /* 164 */ GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner1),
356 /* 167 */ // Label 6: @167
357 /* 167 */ GIM_Reject,
358 /* 168 */ // Label 2: @168
359 /* 168 */ GIM_Reject,
360 /* 169 */ }; // Size: 169 bytes
361 return MatchTable0;
362}
363#undef GIMT_Encode2
364#undef GIMT_Encode4
365#undef GIMT_Encode8
366
367#endif // ifdef GET_GICOMBINER_IMPL
368
369#ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
370AvailableModuleFeatures(computeAvailableModuleFeatures(&STI)),
371AvailableFunctionFeatures()
372#endif // ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
373#ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
374, State(0),
375ExecInfo(TypeObjects, NumTypeObjects, FeatureBitsets, ComplexPredicateFns, CustomRenderers)
376#endif // ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
377
378