LLVM: include/llvm/CodeGen/GlobalISel/LegacyLegalizerInfo.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_CODEGEN_GLOBALISEL_LEGACYLEGALIZERINFO_H
16#define LLVM_CODEGEN_GLOBALISEL_LEGACYLEGALIZERINFO_H
17
22#include <unordered_map>
23#include
24
25namespace llvm {
27
30
31
33
34
35
36
38
39
40
41
43
44
45
46
48
49
50
51
52
54
55
57
58
59
61
62
63
64
66
67
68
70
71
72
74
75
77};
78}
81
82
83
84
98
99
100
101
103
105
107
109
113
116 std::tie(RHS.Action, RHS.TypeIdx, RHS.NewType);
117 }
118};
119
120
122public:
124 std::pair<uint16_t, LegacyLegalizeActions::LegacyLegalizeAction>;
128
130
134 switch (Action) {
135 case NarrowScalar:
136 case WidenScalar:
137 case FewerElements:
138 case MoreElements:
139 case Unsupported:
140 return true;
141 default:
142 return false;
143 }
144 }
145
146
147
148
150
151
152
153
154
158 TablesInitialized = false;
159 const unsigned OpcodeIdx = Aspect.Opcode - FirstOp;
160 if (SpecifiedActions[OpcodeIdx].size() <= Aspect.Idx)
161 SpecifiedActions[OpcodeIdx].resize(Aspect.Idx + 1);
162 SpecifiedActions[OpcodeIdx][Aspect.Idx][Aspect.Type] = Action;
163 }
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
182 const unsigned TypeIdx,
184 const unsigned OpcodeIdx = Opcode - FirstOp;
185 if (ScalarSizeChangeStrategies[OpcodeIdx].size() <= TypeIdx)
186 ScalarSizeChangeStrategies[OpcodeIdx].resize(TypeIdx + 1);
187 ScalarSizeChangeStrategies[OpcodeIdx][TypeIdx] = S;
188 }
189
190
191
193 const unsigned TypeIdx,
195 const unsigned OpcodeIdx = Opcode - FirstOp;
196 if (VectorElementSizeChangeStrategies[OpcodeIdx].size() <= TypeIdx)
197 VectorElementSizeChangeStrategies[OpcodeIdx].resize(TypeIdx + 1);
198 VectorElementSizeChangeStrategies[OpcodeIdx][TypeIdx] = S;
199 }
200
201
202
203
204
205
206
207
208
209
216
217
218
219
220
224 assert(v.size() > 0 &&
225 "At least one size that can be legalized towards is needed"
226 " for this SizeChangeStrategy");
228 NarrowScalar);
229 }
230
237
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
267 FewerElements);
268 }
269
270
275
280
282
284
285private:
286
287
288
289
290
291
292 std::pair<LegacyLegalizeActions::LegacyLegalizeAction, LLT>
293 getAspectAction(const InstrAspect &Aspect) const;
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312 void setScalarAction(const unsigned Opcode, const unsigned TypeIndex,
314 const unsigned OpcodeIdx = Opcode - FirstOp;
316 setActions(TypeIndex, Actions, SizeAndActions);
317 }
318 void setPointerAction(const unsigned Opcode, const unsigned TypeIndex,
321 const unsigned OpcodeIdx = Opcode - FirstOp;
322 SmallVector<SizeAndActionsVec, 1> &Actions =
323 AddrSpace2PointerActions[OpcodeIdx][AddressSpace];
324 setActions(TypeIndex, Actions, SizeAndActions);
325 }
326
327
328
329
330
331
332 void setScalarInVectorAction(const unsigned Opcode, const unsigned TypeIndex,
334 unsigned OpcodeIdx = Opcode - FirstOp;
335 SmallVector<SizeAndActionsVec, 1> &Actions =
336 ScalarInVectorActions[OpcodeIdx];
337 setActions(TypeIndex, Actions, SizeAndActions);
338 }
339
340
341
342
343 void setVectorNumElementAction(const unsigned Opcode,
344 const unsigned TypeIndex,
345 const unsigned ElementSize,
347 const unsigned OpcodeIdx = Opcode - FirstOp;
348 SmallVector<SizeAndActionsVec, 1> &Actions =
349 NumElements2Actions[OpcodeIdx][ElementSize];
350 setActions(TypeIndex, Actions, SizeAndActions);
351 }
352
353
354
355 static void checkPartialSizeAndActionsVector(const SizeAndActionsVec& v) {
356 using namespace LegacyLegalizeActions;
357#ifndef NDEBUG
358
359 int prev_size = -1;
363 }
364
365
366
367
368
369 int SmallestNarrowIdx = -1;
370 int LargestWidenIdx = -1;
371 int SmallestLegalizableToSameSizeIdx = -1;
372 int LargestLegalizableToSameSizeIdx = -1;
373 for(size_t i=0; i<v.size(); ++i) {
374 switch (v[i].second) {
377 if (SmallestNarrowIdx == -1)
378 SmallestNarrowIdx = i;
379 break;
382 LargestWidenIdx = i;
383 break;
385 break;
386 default:
387 if (SmallestLegalizableToSameSizeIdx == -1)
388 SmallestLegalizableToSameSizeIdx = i;
389 LargestLegalizableToSameSizeIdx = i;
390 }
391 }
392 if (SmallestNarrowIdx != -1) {
393 assert(SmallestLegalizableToSameSizeIdx != -1);
394 assert(SmallestNarrowIdx > SmallestLegalizableToSameSizeIdx);
395 }
396 if (LargestWidenIdx != -1)
397 assert(LargestWidenIdx < LargestLegalizableToSameSizeIdx);
398#endif
399 }
400
401
402
403 static void checkFullSizeAndActionsVector(const SizeAndActionsVec& v) {
404#ifndef NDEBUG
405
407 assert(v[0].first == 1);
408 checkPartialSizeAndActionsVector(v);
409#endif
410 }
411
412
413
414 void setActions(unsigned TypeIndex,
415 SmallVector<SizeAndActionsVec, 1> &Actions,
417 checkFullSizeAndActionsVector(SizeAndActions);
418 if (Actions.size() <= TypeIndex)
419 Actions.resize(TypeIndex + 1);
420 Actions[TypeIndex] = SizeAndActions;
421 }
422
424 const uint32_t Size);
425
426
427
428
429
430
431
432
433
434
435
436
437 std::pair<LegacyLegalizeActions::LegacyLegalizeAction, LLT>
438 findScalarLegalAction(const InstrAspect &Aspect) const;
439
440
441 std::pair<LegacyLegalizeActions::LegacyLegalizeAction, LLT>
442 findVectorLegalAction(const InstrAspect &Aspect) const;
443
444 static const int FirstOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_START;
445 static const int LastOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_END;
446
447
448 using TypeMap = DenseMap<LLT, LegacyLegalizeActions::LegacyLegalizeAction>;
450 SmallVector<SizeChangeStrategy, 1>
451 ScalarSizeChangeStrategies[LastOp - FirstOp + 1];
452 SmallVector<SizeChangeStrategy, 1>
453 VectorElementSizeChangeStrategies[LastOp - FirstOp + 1];
454 bool TablesInitialized = false;
455
456
457 SmallVector<SizeAndActionsVec, 1> ScalarActions[LastOp - FirstOp + 1];
458 SmallVector<SizeAndActionsVec, 1> ScalarInVectorActions[LastOp - FirstOp + 1];
459 std::unordered_map<uint16_t, SmallVector<SizeAndActionsVec, 1>>
460 AddrSpace2PointerActions[LastOp - FirstOp + 1];
461 std::unordered_map<uint16_t, SmallVector<SizeAndActionsVec, 1>>
462 NumElements2Actions[LastOp - FirstOp + 1];
463};
464
465}
466
467#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
Implement a low-level type suitable for MachineInstr level instruction selection.
std::function< SizeAndActionsVec(const SizeAndActionsVec &v)> SizeChangeStrategy
Definition LegacyLegalizerInfo.h:126
static LLVM_ABI SizeAndActionsVec decreaseToSmallerTypesAndIncreaseToSmallest(const SizeAndActionsVec &v, LegacyLegalizeActions::LegacyLegalizeAction DecreaseAction, LegacyLegalizeActions::LegacyLegalizeAction IncreaseAction)
Helper function to implement many typical SizeChangeStrategy functions.
static SizeAndActionsVec widenToLargerTypesUnsupportedOtherwise(const SizeAndActionsVec &v)
Definition LegacyLegalizerInfo.h:232
static SizeAndActionsVec moreToWiderTypesAndLessToWidest(const SizeAndActionsVec &v)
A SizeChangeStrategy for the common case where legalization for a particular vector operation consist...
Definition LegacyLegalizerInfo.h:264
LLVM_ABI void computeTables()
Compute any ancillary tables needed to quickly decide how an operation should be handled.
std::vector< SizeAndAction > SizeAndActionsVec
Definition LegacyLegalizerInfo.h:125
static bool needsLegalizingToDifferentSize(const LegacyLegalizeActions::LegacyLegalizeAction Action)
Definition LegacyLegalizerInfo.h:131
LLVM_ABI unsigned getOpcodeIdxForOpcode(unsigned Opcode) const
static SizeAndActionsVec widenToLargerTypesAndNarrowToLargest(const SizeAndActionsVec &v)
A SizeChangeStrategy for the common case where legalization for a particular operation consists of wi...
Definition LegacyLegalizerInfo.h:222
void setAction(const InstrAspect &Aspect, LegacyLegalizeActions::LegacyLegalizeAction Action)
More friendly way to set an action for common types that have an LLT representation.
Definition LegacyLegalizerInfo.h:155
LLVM_ABI LegacyLegalizeActionStep getAction(const LegalityQuery &Query) const
void setLegalizeScalarToDifferentSizeStrategy(const unsigned Opcode, const unsigned TypeIdx, SizeChangeStrategy S)
The setAction calls record the non-size-changing legalization actions to take on specificly-sized typ...
Definition LegacyLegalizerInfo.h:181
void setLegalizeVectorElementToDifferentSizeStrategy(const unsigned Opcode, const unsigned TypeIdx, SizeChangeStrategy S)
See also setLegalizeScalarToDifferentSizeStrategy.
Definition LegacyLegalizerInfo.h:192
std::pair< uint16_t, LegacyLegalizeActions::LegacyLegalizeAction > SizeAndAction
Definition LegacyLegalizerInfo.h:123
static SizeAndActionsVec unsupportedForDifferentSizes(const SizeAndActionsVec &v)
A SizeChangeStrategy for the common case where legalization for a particular operation consists of on...
Definition LegacyLegalizerInfo.h:211
static LLVM_ABI SizeAndActionsVec increaseToLargerTypesAndDecreaseToLargest(const SizeAndActionsVec &v, LegacyLegalizeActions::LegacyLegalizeAction IncreaseAction, LegacyLegalizeActions::LegacyLegalizeAction DecreaseAction)
Helper function to implement many typical SizeChangeStrategy functions.
static SizeAndActionsVec narrowToSmallerAndUnsupportedIfTooSmall(const SizeAndActionsVec &v)
Definition LegacyLegalizerInfo.h:239
LLVM_ABI LegacyLegalizerInfo()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LegacyLegalizeAction
Definition LegacyLegalizerInfo.h:29
@ Bitcast
Perform the operation on a different, but equivalently sized type.
Definition LegacyLegalizerInfo.h:56
@ MoreElements
The (vector) operation should be implemented by widening the input vector and ignoring the lanes adde...
Definition LegacyLegalizerInfo.h:53
@ Legal
The operation is expected to be selectable directly by the target, and no transformation is necessary...
Definition LegacyLegalizerInfo.h:32
@ FewerElements
The (vector) operation should be implemented by splitting it into sub-vectors where the operation is ...
Definition LegacyLegalizerInfo.h:47
@ Unsupported
This operation is completely unsupported on the target.
Definition LegacyLegalizerInfo.h:73
@ NarrowScalar
The operation should be synthesized from multiple instructions acting on a narrower scalar base-type.
Definition LegacyLegalizerInfo.h:37
@ Lower
The operation itself must be expressed in terms of simpler actions on this target.
Definition LegacyLegalizerInfo.h:60
@ Custom
The target wants to do something special with this combination of operand and type.
Definition LegacyLegalizerInfo.h:69
@ NotFound
Sentinel value for when no action was found in the specified table.
Definition LegacyLegalizerInfo.h:76
@ WidenScalar
The operation should be implemented in terms of a wider scalar base-type.
Definition LegacyLegalizerInfo.h:42
@ Libcall
The operation should be implemented as a call to some kind of runtime support library.
Definition LegacyLegalizerInfo.h:65
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Legalization is decided based on an instruction's opcode, which type slot we're considering,...
Definition LegacyLegalizerInfo.h:85
bool operator==(const InstrAspect &RHS) const
Definition LegacyLegalizerInfo.h:94
unsigned Idx
Definition LegacyLegalizerInfo.h:87
LLT Type
Definition LegacyLegalizerInfo.h:88
InstrAspect(unsigned Opcode, LLT Type)
Definition LegacyLegalizerInfo.h:90
unsigned Opcode
Definition LegacyLegalizerInfo.h:86
InstrAspect(unsigned Opcode, unsigned Idx, LLT Type)
Definition LegacyLegalizerInfo.h:91
The result of a query.
Definition LegacyLegalizerInfo.h:102
bool operator==(const LegacyLegalizeActionStep &RHS) const
Definition LegacyLegalizerInfo.h:114
LegacyLegalizeActions::LegacyLegalizeAction Action
The action to take or the final answer.
Definition LegacyLegalizerInfo.h:104
unsigned TypeIdx
If describing an action, the type index to change. Otherwise zero.
Definition LegacyLegalizerInfo.h:106
LegacyLegalizeActionStep(LegacyLegalizeActions::LegacyLegalizeAction Action, unsigned TypeIdx, const LLT NewType)
Definition LegacyLegalizerInfo.h:110
LLT NewType
If describing an action, the new type for TypeIdx. Otherwise LLT{}.
Definition LegacyLegalizerInfo.h:108
The LegalityQuery object bundles together all the information that's needed to decide whether a given...