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