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 38: // 1 string to match.
37 if (memcmp(RuleIdentifier.data()+0, "vector_length_sub_to_distance_lowering", 38) != 0)
38 break;
39 return 0; // "vector_length_sub_to_distance_lowering"
40 }
41#endif // ifndef NDEBUG
42
43 return std::nullopt;
44}
45static std::optional<std::pair<uint64_t, uint64_t>> getRuleRangeForIdentifier(StringRef RuleIdentifier) {
46 std::pair<StringRef, StringRef> RangePair = RuleIdentifier.split('-');
47 if (!RangePair.second.empty()) {
48 const auto First = getRuleIdxForIdentifier(RangePair.first);
49 const auto Last = getRuleIdxForIdentifier(RangePair.second);
50 if (!First || !Last)
51 return std::nullopt;
52 if (First >= Last)
53 report_fatal_error("Beginning of range should be before end of range");
54 return {{*First, *Last + 1}};
55 }
56 if (RangePair.first == "*") {
57 return {{0, 1}};
58 }
59 const auto I = getRuleIdxForIdentifier(RangePair.first);
60 if (!I)
61 return std::nullopt;
62 return {{*I, *I + 1}};
63}
64
65bool SPIRVPreLegalizerCombinerImplRuleConfig::setRuleEnabled(StringRef RuleIdentifier) {
66 auto MaybeRange = getRuleRangeForIdentifier(RuleIdentifier);
67 if (!MaybeRange)
68 return false;
69 for (auto I = MaybeRange->first; I < MaybeRange->second; ++I)
70 DisabledRules.reset(I);
71 return true;
72}
73
74bool SPIRVPreLegalizerCombinerImplRuleConfig::setRuleDisabled(StringRef RuleIdentifier) {
75 auto MaybeRange = getRuleRangeForIdentifier(RuleIdentifier);
76 if (!MaybeRange)
77 return false;
78 for (auto I = MaybeRange->first; I < MaybeRange->second; ++I)
79 DisabledRules.set(I);
80 return true;
81}
82
83static std::vector<std::string> SPIRVPreLegalizerCombinerOption;
84static cl::list<std::string> SPIRVPreLegalizerCombinerDisableOption(
85 "spirvprelegalizercombiner-disable-rule",
86 cl::desc("Disable one or more combiner rules temporarily in the SPIRVPreLegalizerCombiner pass"),
87 cl::CommaSeparated,
88 cl::Hidden,
89 cl::cat(GICombinerOptionCategory),
90 cl::callback([](const std::string &Str) {
91 SPIRVPreLegalizerCombinerOption.push_back(Str);
92 }));
93static cl::list<std::string> SPIRVPreLegalizerCombinerOnlyEnableOption(
94 "spirvprelegalizercombiner-only-enable-rule",
95 cl::desc("Disable all rules in the SPIRVPreLegalizerCombiner pass then re-enable the specified ones"),
96 cl::Hidden,
97 cl::cat(GICombinerOptionCategory),
98 cl::callback([](const std::string &CommaSeparatedArg) {
99 StringRef Str = CommaSeparatedArg;
100 SPIRVPreLegalizerCombinerOption.push_back("*");
101 do {
102 auto X = Str.split(",");
103 SPIRVPreLegalizerCombinerOption.push_back(("!" + X.first).str());
104 Str = X.second;
105 } while (!Str.empty());
106 }));
107
108
109bool SPIRVPreLegalizerCombinerImplRuleConfig::isRuleEnabled(unsigned RuleID) const {
110 return !DisabledRules.test(RuleID);
111}
112bool SPIRVPreLegalizerCombinerImplRuleConfig::parseCommandLineOption() {
113 for (StringRef Identifier : SPIRVPreLegalizerCombinerOption) {
114 bool Enabled = Identifier.consume_front("!");
115 if (Enabled && !setRuleEnabled(Identifier))
116 return false;
117 if (!Enabled && !setRuleDisabled(Identifier))
118 return false;
119 }
120 return true;
121}
122
123#endif // ifdef GET_GICOMBINER_TYPES
124
125#ifdef GET_GICOMBINER_TYPES
126const unsigned MAX_SUBTARGET_PREDICATES = 0;
127using PredicateBitset = llvm::Bitset<MAX_SUBTARGET_PREDICATES>;
128#endif // ifdef GET_GICOMBINER_TYPES
129
130#ifdef GET_GICOMBINER_CLASS_MEMBERS
131PredicateBitset AvailableModuleFeatures;
132mutable PredicateBitset AvailableFunctionFeatures;
133PredicateBitset getAvailableFeatures() const {
134 return AvailableModuleFeatures | AvailableFunctionFeatures;
135}
136PredicateBitset
137computeAvailableModuleFeatures(const SPIRVSubtarget *Subtarget) const;
138PredicateBitset
139computeAvailableFunctionFeatures(const SPIRVSubtarget *Subtarget,
140 const MachineFunction *MF) const;
141void setupGeneratedPerFunctionState(MachineFunction &MF) override;
142#endif // ifdef GET_GICOMBINER_CLASS_MEMBERS
143#ifdef GET_GICOMBINER_CLASS_MEMBERS
144 mutable MatcherState State;
145 typedef ComplexRendererFns(SPIRVPreLegalizerCombinerImpl::*ComplexMatcherMemFn)(MachineOperand &) const;
146 typedef void(SPIRVPreLegalizerCombinerImpl::*CustomRendererFn)(MachineInstrBuilder &, const MachineInstr &, int) const;
147 const ExecInfoTy<PredicateBitset, ComplexMatcherMemFn, CustomRendererFn> ExecInfo;
148 static SPIRVPreLegalizerCombinerImpl::ComplexMatcherMemFn ComplexPredicateFns[];
149 static SPIRVPreLegalizerCombinerImpl::CustomRendererFn CustomRenderers[];
150 bool testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const override;
151 bool testImmPredicate_APInt(unsigned PredicateID, const APInt &Imm) const override;
152 bool testImmPredicate_APFloat(unsigned PredicateID, const APFloat &Imm) const override;
153 const uint8_t *getMatchTable() const override;
154 bool testMIPredicate_MI(unsigned PredicateID, const MachineInstr &MI, const MatcherState &State) const override;
155 bool testMOPredicate_MO(unsigned PredicateID, const MachineOperand &MO, const MatcherState &State) const override;
156 bool testSimplePredicate(unsigned PredicateID) const override;
157 bool runCustomAction(unsigned FnID, const MatcherState &State, NewMIVector &OutMIs) const override;
158#endif // ifdef GET_GICOMBINER_CLASS_MEMBERS
159
160#ifdef GET_GICOMBINER_IMPL
161// LLT Objects.
162enum {
163 GILLT_s1,
164};
165const static size_t NumTypeObjects = 1;
166const static LLT TypeObjects[] = {
167 LLT::scalar(1),
168};
169
170// Bits for subtarget features that participate in instruction matching.
171enum SubtargetFeatureBits : uint8_t {
172};
173
174PredicateBitset SPIRVPreLegalizerCombinerImpl::
175computeAvailableModuleFeatures(const SPIRVSubtarget *Subtarget) const {
176 PredicateBitset Features{};
177 return Features;
178}
179
180void SPIRVPreLegalizerCombinerImpl::setupGeneratedPerFunctionState(MachineFunction &MF) {
181 AvailableFunctionFeatures = computeAvailableFunctionFeatures((const SPIRVSubtarget *)&MF.getSubtarget(), &MF);
182}
183PredicateBitset SPIRVPreLegalizerCombinerImpl::
184computeAvailableFunctionFeatures(const SPIRVSubtarget *Subtarget, const MachineFunction *MF) const {
185 PredicateBitset Features{};
186 return Features;
187}
188
189// Feature bitsets.
190enum {
191 GIFBS_Invalid,
192};
193constexpr static PredicateBitset FeatureBitsets[] {
194 {}, // GIFBS_Invalid
195};
196
197// ComplexPattern predicates.
198enum {
199 GICP_Invalid,
200};
201// See constructor for table contents
202
203SPIRVPreLegalizerCombinerImpl::ComplexMatcherMemFn
204SPIRVPreLegalizerCombinerImpl::ComplexPredicateFns[] = {
205 nullptr, // GICP_Invalid
206};
207
208bool SPIRVPreLegalizerCombinerImpl::testMIPredicate_MI(unsigned PredicateID, const MachineInstr & MI, const MatcherState &State) const {
209 llvm_unreachable("Unknown predicate");
210 return false;
211}
212bool SPIRVPreLegalizerCombinerImpl::testMOPredicate_MO(unsigned PredicateID, const MachineOperand & MO, const MatcherState &State) const {
213 llvm_unreachable("Unknown predicate");
214 return false;
215}
216bool SPIRVPreLegalizerCombinerImpl::testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const {
217 llvm_unreachable("Unknown predicate");
218 return false;
219}
220bool SPIRVPreLegalizerCombinerImpl::testImmPredicate_APFloat(unsigned PredicateID, const APFloat & Imm) const {
221 llvm_unreachable("Unknown predicate");
222 return false;
223}
224bool SPIRVPreLegalizerCombinerImpl::testImmPredicate_APInt(unsigned PredicateID, const APInt & Imm) const {
225 llvm_unreachable("Unknown predicate");
226 return false;
227}
228enum {
229 GICXXPred_Simple_IsRule0Enabled = GICXXPred_Invalid + 1,
230};
231
232bool SPIRVPreLegalizerCombinerImpl::testSimplePredicate(unsigned Predicate) const {
233 return RuleConfig.isRuleEnabled(Predicate - GICXXPred_Invalid - 1);
234}
235// Custom renderers.
236enum {
237 GICR_Invalid,
238};
239SPIRVPreLegalizerCombinerImpl::CustomRendererFn
240SPIRVPreLegalizerCombinerImpl::CustomRenderers[] = {
241 nullptr, // GICR_Invalid
242};
243
244bool SPIRVPreLegalizerCombinerImpl::tryCombineAllImpl(MachineInstr &I) const {
245 const TargetSubtargetInfo &ST = MF.getSubtarget();
246 const PredicateBitset AvailableFeatures = getAvailableFeatures();
247 B.setInstrAndDebugLoc(I);
248 State.MIs.clear();
249 State.MIs.push_back(&I);
250 if (executeMatchTable(*this, State, ExecInfo, B, getMatchTable(), *ST.getInstrInfo(), MRI, *MRI.getTargetRegisterInfo(), *ST.getRegBankInfo(), AvailableFeatures, /*CoverageInfo*/ nullptr)) {
251 return true;
252 }
253
254 return false;
255}
256
257enum {
258 GICXXCustomAction_GICombiner0 = GICXXCustomAction_Invalid + 1,
259};
260bool SPIRVPreLegalizerCombinerImpl::runCustomAction(unsigned ApplyID, const MatcherState &State, NewMIVector &OutMIs) const {
261 Helper.getBuilder().setInstrAndDebugLoc(*State.MIs[0]);
262 switch(ApplyID) {
263 case GICXXCustomAction_GICombiner0:{
264 // Match Patterns
265 if(![&](){return matchLengthToDistance(*State.MIs[0], MRI);}()) {
266 return false;
267 }
268 // Apply Patterns
269 applySPIRVDistance(*State.MIs[0], MRI, B);
270 return true;
271 }
272 }
273 llvm_unreachable("Unknown Apply Action");
274}
275#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
276#define GIMT_Encode2(Val) uint8_t(Val), uint8_t((uint16_t)Val >> 8)
277#define GIMT_Encode4(Val) uint8_t(Val), uint8_t((uint32_t)Val >> 8), uint8_t((uint32_t)Val >> 16), uint8_t((uint32_t)Val >> 24)
278#define GIMT_Encode8(Val) uint8_t(Val), uint8_t((uint64_t)Val >> 8), uint8_t((uint64_t)Val >> 16), uint8_t((uint64_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)
279#else
280#define GIMT_Encode2(Val) uint8_t((uint16_t)Val >> 8), uint8_t(Val)
281#define GIMT_Encode4(Val) uint8_t((uint32_t)Val >> 24), uint8_t((uint32_t)Val >> 16), uint8_t((uint32_t)Val >> 8), uint8_t(Val)
282#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((uint64_t)Val >> 24), uint8_t((uint64_t)Val >> 16), uint8_t((uint64_t)Val >> 8), uint8_t(Val)
283#endif
284const uint8_t *SPIRVPreLegalizerCombinerImpl::getMatchTable() const {
285 constexpr static uint8_t MatchTable0[] = {
286 /* 0 */ GIM_Try, /*On fail goto*//*Label 0*/ GIMT_Encode4(15), // Rule ID 0 //
287 /* 5 */ GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule0Enabled),
288 /* 8 */ GIM_CheckOpcode, /*MI*/0, GIMT_Encode2(TargetOpcode::G_INTRINSIC),
289 /* 12 */ // Combiner Rule #0: vector_length_sub_to_distance_lowering; wip_match_opcode 'G_INTRINSIC'
290 /* 12 */ GIR_DoneWithCustomAction, /*Fn*/GIMT_Encode2(GICXXCustomAction_GICombiner0),
291 /* 15 */ // Label 0: @15
292 /* 15 */ GIM_Reject,
293 /* 16 */ }; // Size: 16 bytes
294 return MatchTable0;
295}
296#undef GIMT_Encode2
297#undef GIMT_Encode4
298#undef GIMT_Encode8
299
300#endif // ifdef GET_GICOMBINER_IMPL
301
302#ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
303AvailableModuleFeatures(computeAvailableModuleFeatures(&STI)),
304AvailableFunctionFeatures()
305#endif // ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
306#ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
307, State(0),
308ExecInfo(TypeObjects, NumTypeObjects, FeatureBitsets, ComplexPredicateFns, CustomRenderers)
309#endif // ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
310
311