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 uint32_t getRootFlagsToDrop() const override;
158
159#endif // GET_GICOMBINER_CLASS_MEMBERS
160
161#ifdef GET_GICOMBINER_CLASS_MEMBERS
162
163PredicateBitset AvailableModuleFeatures;
164mutable PredicateBitset AvailableFunctionFeatures;
165PredicateBitset getAvailableFeatures() const {
166 return AvailableModuleFeatures | AvailableFunctionFeatures;
167}
168PredicateBitset
169computeAvailableModuleFeatures(const SPIRVSubtarget *Subtarget) const;
170PredicateBitset
171computeAvailableFunctionFeatures(const SPIRVSubtarget *Subtarget,
172 const MachineFunction *MF) const;
173void setupGeneratedPerFunctionState(MachineFunction &MF) override;
174
175#endif // GET_GICOMBINER_CLASS_MEMBERS
176
177#ifdef GET_GICOMBINER_CLASS_MEMBERS
178
179 mutable MatcherState State;
180 typedef ComplexRendererFns(SPIRVPreLegalizerCombinerImpl::*ComplexMatcherMemFn)(MachineOperand &) const;
181 typedef void(SPIRVPreLegalizerCombinerImpl::*CustomRendererFn)(MachineInstrBuilder &, const MachineInstr &, int) const;
182 const ExecInfoTy<PredicateBitset, ComplexMatcherMemFn, CustomRendererFn> ExecInfo;
183 static SPIRVPreLegalizerCombinerImpl::ComplexMatcherMemFn ComplexPredicateFns[];
184 static SPIRVPreLegalizerCombinerImpl::CustomRendererFn CustomRenderers[];
185 bool testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const override;
186 bool testImmPredicate_APInt(unsigned PredicateID, const APInt &Imm) const override;
187 bool testImmPredicate_APFloat(unsigned PredicateID, const APFloat &Imm) const override;
188 const uint8_t *getMatchTable() const override;
189 bool testMIPredicate_MI(unsigned PredicateID, const MachineInstr &MI, const MatcherState &State) const override;
190 bool testMOPredicate_MO(unsigned PredicateID, const MachineOperand &MO, const MatcherState &State) const override;
191 bool testSimplePredicate(unsigned PredicateID) const override;
192 bool runCustomAction(unsigned FnID, const MatcherState &State, NewMIVector &OutMIs) const override;
193
194#endif // GET_GICOMBINER_CLASS_MEMBERS
195
196#ifdef GET_GICOMBINER_IMPL
197
198// LLT Objects.
199enum {
200 GILLT_s1,
201};
202const static size_t NumTypeObjects = 1;
203const static LLT TypeObjects[] = {
204 LLT::scalar(1),
205};
206
207// Bits for subtarget features that participate in instruction matching.
208enum SubtargetFeatureBits : uint8_t {
209};
210
211PredicateBitset SPIRVPreLegalizerCombinerImpl::
212computeAvailableModuleFeatures(const SPIRVSubtarget *Subtarget) const {
213 PredicateBitset Features{};
214 return Features;
215}
216
217void SPIRVPreLegalizerCombinerImpl::setupGeneratedPerFunctionState(MachineFunction &MF) {
218 AvailableFunctionFeatures = computeAvailableFunctionFeatures((const SPIRVSubtarget *)&MF.getSubtarget(), &MF);
219}
220PredicateBitset SPIRVPreLegalizerCombinerImpl::
221computeAvailableFunctionFeatures(const SPIRVSubtarget *Subtarget, const MachineFunction *MF) const {
222 PredicateBitset Features{};
223 return Features;
224}
225
226// Feature bitsets.
227enum {
228 GIFBS_Invalid,
229};
230constexpr static PredicateBitset FeatureBitsets[] {
231 {}, // GIFBS_Invalid
232};
233
234// ComplexPattern predicates.
235enum {
236 GICP_Invalid,
237};
238// See constructor for table contents
239
240SPIRVPreLegalizerCombinerImpl::ComplexMatcherMemFn
241SPIRVPreLegalizerCombinerImpl::ComplexPredicateFns[] = {
242 nullptr, // GICP_Invalid
243};
244
245bool SPIRVPreLegalizerCombinerImpl::testMIPredicate_MI(unsigned PredicateID, const MachineInstr & MI, const MatcherState &State) const {
246 llvm_unreachable("Unknown predicate");
247 return false;
248}
249bool SPIRVPreLegalizerCombinerImpl::testMOPredicate_MO(unsigned PredicateID, const MachineOperand & MO, const MatcherState &State) const {
250 llvm_unreachable("Unknown predicate");
251 return false;
252}
253bool SPIRVPreLegalizerCombinerImpl::testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const {
254 llvm_unreachable("Unknown predicate");
255 return false;
256}
257bool SPIRVPreLegalizerCombinerImpl::testImmPredicate_APFloat(unsigned PredicateID, const APFloat & Imm) const {
258 llvm_unreachable("Unknown predicate");
259 return false;
260}
261bool SPIRVPreLegalizerCombinerImpl::testImmPredicate_APInt(unsigned PredicateID, const APInt & Imm) const {
262 llvm_unreachable("Unknown predicate");
263 return false;
264}
265enum {
266 GICXXPred_Simple_IsRule0Enabled = GICXXPred_Invalid + 1,
267 GICXXPred_Simple_IsRule1Enabled,
268 GICXXPred_Simple_IsRule2Enabled,
269 GICXXPred_Simple_IsRule3Enabled,
270 GICXXPred_Simple_IsRule4Enabled,
271};
272
273bool SPIRVPreLegalizerCombinerImpl::testSimplePredicate(unsigned Predicate) const {
274 return RuleConfig.isRuleEnabled(Predicate - GICXXPred_Invalid - 1);
275}
276// Custom renderers.
277enum {
278 GICR_Invalid,
279};
280SPIRVPreLegalizerCombinerImpl::CustomRendererFn
281SPIRVPreLegalizerCombinerImpl::CustomRenderers[] = {
282 nullptr, // GICR_Invalid
283};
284
285bool SPIRVPreLegalizerCombinerImpl::canMatchOpcode(unsigned Opc) const {
286 switch (Opc) {
287 case TargetOpcode::G_FDIV:
288 case TargetOpcode::G_INTRINSIC:
289 case TargetOpcode::G_SELECT:
290 return true;
291 default:
292 return false;
293 }
294}
295
296uint32_t SPIRVPreLegalizerCombinerImpl::getRootFlagsToDrop() const {
297 return MachineInstr::getPoisonGeneratingFlags();
298}
299
300bool SPIRVPreLegalizerCombinerImpl::tryCombineAllImpl(MachineInstr &I) const {
301 const PredicateBitset AvailableFeatures = getAvailableFeatures();
302 State.MIs.clear();
303 State.MIs.push_back(&I);
304 if (executeMatchTable(*this, State, ExecInfo, B, getMatchTable(), Helper.getTII(), MRI, Helper.getTRI(), Helper.getRBI(), AvailableFeatures, /*CoverageInfo*/ nullptr)) {
305 return true;
306 }
307
308 return false;
309}
310
311enum {
312 GICXXCustomAction_GICombiner0 = GICXXCustomAction_Invalid + 1,
313 GICXXCustomAction_GICombiner1,
314 GICXXCustomAction_GICombiner2,
315 GICXXCustomAction_GICombiner3,
316 GICXXCustomAction_GICombiner4,
317};
318bool SPIRVPreLegalizerCombinerImpl::runCustomAction(unsigned ApplyID, const MatcherState &State, NewMIVector &OutMIs) const {
319 Helper.getBuilder().setInstrAndDebugLoc(*State.MIs[0]);
320 switch(ApplyID) {
321 case GICXXCustomAction_GICombiner0:{
322 // Match Patterns
323 if(![&](){return Helper.matchLengthToDistance(*State.MIs[0]);}()) {
324 return false;
325 }
326 // Apply Patterns
327 Helper.applySPIRVDistance(*State.MIs[0]);
328 return true;
329 }
330 case GICXXCustomAction_GICombiner1:{
331 // Match Patterns
332 if(![&](){return Helper.matchFDivToNormalize(*State.MIs[0]);}()) {
333 return false;
334 }
335 // Apply Patterns
336 Helper.applySPIRVNormalize(*State.MIs[0]);
337 return true;
338 }
339 case GICXXCustomAction_GICombiner2:{
340 // Match Patterns
341 if(![&](){return Helper.matchSelectToFaceForward(*State.MIs[0]);}()) {
342 return false;
343 }
344 // Apply Patterns
345 Helper.applySPIRVFaceForward(*State.MIs[0]);
346 return true;
347 }
348 case GICXXCustomAction_GICombiner3:{
349 // Match Patterns
350 if(![&](){return mi_match(*State.MIs[0], MRI,
351 m_GIntrinsic<Intrinsic::matrix_transpose>());}()) {
352 return false;
353 }
354 // Apply Patterns
355 Helper.applyMatrixTranspose(*State.MIs[0]);
356 return true;
357 }
358 case GICXXCustomAction_GICombiner4:{
359 // Match Patterns
360 if(![&](){return mi_match(*State.MIs[0], MRI,
361 m_GIntrinsic<Intrinsic::matrix_multiply>());}()) {
362 return false;
363 }
364 // Apply Patterns
365 Helper.applyMatrixMultiply(*State.MIs[0]);
366 return true;
367 }
368 }
369 llvm_unreachable("Unknown Apply Action");
370}
371#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
372#define GIMT_Encode2(Val) uint8_t(Val), uint8_t((Val) >> 8)
373#define GIMT_Encode4(Val) uint8_t(Val), uint8_t((Val) >> 8), uint8_t((Val) >> 16), uint8_t((Val) >> 24)
374#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)
375#else
376#define GIMT_Encode2(Val) uint8_t((Val) >> 8), uint8_t(Val)
377#define GIMT_Encode4(Val) uint8_t((Val) >> 24), uint8_t((Val) >> 16), uint8_t((Val) >> 8), uint8_t(Val)
378#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)
379#endif
380const uint8_t *SPIRVPreLegalizerCombinerImpl::getMatchTable() const {
381 constexpr static uint8_t MatchTable0[] = {
382 /* 0 */ GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(139), GIMT_Encode2(199), /*)*//*default:*//*Label 3*/ GIMT_Encode4(308),
383 /* 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),
384 /* 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),
385 /* 246 */ /*TargetOpcode::G_FDIV*//*Label 2*/ GIMT_Encode4(296),
386 /* 250 */ // Label 0: @250
387 /* 250 */ GIM_Try, /*On fail goto*//*Label 4*/ GIMT_Encode4(261), // Rule ID 0 //
388 /* 255 */ GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule0Enabled),
389 /* 258 */ // Combiner Rule #0: vector_length_sub_to_distance_lowering; wip_match_opcode 'G_INTRINSIC'
390 /* 258 */ GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner0),
391 /* 261 */ // Label 4: @261
392 /* 261 */ GIM_Try, /*On fail goto*//*Label 5*/ GIMT_Encode4(272), // Rule ID 3 //
393 /* 266 */ GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule3Enabled),
394 /* 269 */ // Combiner Rule #3: matrix_transpose_lowering; wip_match_opcode 'G_INTRINSIC'
395 /* 269 */ GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner3),
396 /* 272 */ // Label 5: @272
397 /* 272 */ GIM_Try, /*On fail goto*//*Label 6*/ GIMT_Encode4(283), // Rule ID 4 //
398 /* 277 */ GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule4Enabled),
399 /* 280 */ // Combiner Rule #4: matrix_multiply_lowering; wip_match_opcode 'G_INTRINSIC'
400 /* 280 */ GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner4),
401 /* 283 */ // Label 6: @283
402 /* 283 */ GIM_Reject,
403 /* 284 */ // Label 1: @284
404 /* 284 */ GIM_Try, /*On fail goto*//*Label 7*/ GIMT_Encode4(295), // Rule ID 2 //
405 /* 289 */ GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule2Enabled),
406 /* 292 */ // Combiner Rule #2: vector_select_to_faceforward_lowering; wip_match_opcode 'G_SELECT'
407 /* 292 */ GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner2),
408 /* 295 */ // Label 7: @295
409 /* 295 */ GIM_Reject,
410 /* 296 */ // Label 2: @296
411 /* 296 */ GIM_Try, /*On fail goto*//*Label 8*/ GIMT_Encode4(307), // Rule ID 1 //
412 /* 301 */ GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule1Enabled),
413 /* 304 */ // Combiner Rule #1: vector_fdiv_length_to_normalize_lowering; wip_match_opcode 'G_FDIV'
414 /* 304 */ GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner1),
415 /* 307 */ // Label 8: @307
416 /* 307 */ GIM_Reject,
417 /* 308 */ // Label 3: @308
418 /* 308 */ GIM_Reject,
419 /* 309 */ }; // Size: 309 bytes
420 return MatchTable0;
421}
422#undef GIMT_Encode2
423#undef GIMT_Encode4
424#undef GIMT_Encode8
425
426
427#endif // GET_GICOMBINER_IMPL
428
429#ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
430
431AvailableModuleFeatures(computeAvailableModuleFeatures(&STI)),
432AvailableFunctionFeatures()
433
434#endif // GET_GICOMBINER_CONSTRUCTOR_INITS
435
436#ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
437
438, State(0),
439ExecInfo(TypeObjects, NumTypeObjects, FeatureBitsets, ComplexPredicateFns, CustomRenderers)
440
441#endif // GET_GICOMBINER_CONSTRUCTOR_INITS
442
443