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