LLVM  13.0.0git
LegalizerInfo.h
Go to the documentation of this file.
1 //===- llvm/CodeGen/GlobalISel/LegalizerInfo.h ------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// Interface for Targets to specify which operations they can successfully
10 /// select and how the others should be expanded most efficiently.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
15 #define LLVM_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
16 
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/None.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SmallVector.h"
28 #include <cassert>
29 #include <cstdint>
30 #include <tuple>
31 #include <unordered_map>
32 #include <utility>
33 
34 namespace llvm {
35 
36 extern cl::opt<bool> DisableGISelLegalityCheck;
37 
38 class LegalizerHelper;
39 class MachineInstr;
40 class MachineRegisterInfo;
41 class MCInstrInfo;
42 class GISelChangeObserver;
43 
44 namespace LegalizeActions {
45 enum LegalizeAction : std::uint8_t {
46  /// The operation is expected to be selectable directly by the target, and
47  /// no transformation is necessary.
49 
50  /// The operation should be synthesized from multiple instructions acting on
51  /// a narrower scalar base-type. For example a 64-bit add might be
52  /// implemented in terms of 32-bit add-with-carry.
54 
55  /// The operation should be implemented in terms of a wider scalar
56  /// base-type. For example a <2 x s8> add could be implemented as a <2
57  /// x s32> add (ignoring the high bits).
59 
60  /// The (vector) operation should be implemented by splitting it into
61  /// sub-vectors where the operation is legal. For example a <8 x s64> add
62  /// might be implemented as 4 separate <2 x s64> adds.
64 
65  /// The (vector) operation should be implemented by widening the input
66  /// vector and ignoring the lanes added by doing so. For example <2 x i8> is
67  /// rarely legal, but you might perform an <8 x i8> and then only look at
68  /// the first two results.
70 
71  /// Perform the operation on a different, but equivalently sized type.
73 
74  /// The operation itself must be expressed in terms of simpler actions on
75  /// this target. E.g. a SREM replaced by an SDIV and subtraction.
77 
78  /// The operation should be implemented as a call to some kind of runtime
79  /// support library. For example this usually happens on machines that don't
80  /// support floating-point operations natively.
82 
83  /// The target wants to do something special with this combination of
84  /// operand and type. A callback will be issued when it is needed.
86 
87  /// This operation is completely unsupported on the target. A programming
88  /// error has occurred.
90 
91  /// Sentinel value for when no action was found in the specified table.
93 
94  /// Fall back onto the old rules.
95  /// TODO: Remove this once we've migrated
97 };
98 } // end namespace LegalizeActions
99 raw_ostream &operator<<(raw_ostream &OS, LegalizeActions::LegalizeAction Action);
100 
102 
103 /// Legalization is decided based on an instruction's opcode, which type slot
104 /// we're considering, and what the existing type is. These aspects are gathered
105 /// together for convenience in the InstrAspect class.
106 struct InstrAspect {
107  unsigned Opcode;
108  unsigned Idx = 0;
110 
112  InstrAspect(unsigned Opcode, unsigned Idx, LLT Type)
113  : Opcode(Opcode), Idx(Idx), Type(Type) {}
114 
115  bool operator==(const InstrAspect &RHS) const {
116  return Opcode == RHS.Opcode && Idx == RHS.Idx && Type == RHS.Type;
117  }
118 };
119 
120 /// The LegalityQuery object bundles together all the information that's needed
121 /// to decide whether a given operation is legal or not.
122 /// For efficiency, it doesn't make a copy of Types so care must be taken not
123 /// to free it before using the query.
125  unsigned Opcode;
127 
128  struct MemDesc {
129  uint64_t SizeInBits;
130  uint64_t AlignInBits;
132  };
133 
134  /// Operations which require memory can use this to place requirements on the
135  /// memory type for each MMO.
137 
138  constexpr LegalityQuery(unsigned Opcode, const ArrayRef<LLT> Types,
141  constexpr LegalityQuery(unsigned Opcode, const ArrayRef<LLT> Types)
142  : LegalityQuery(Opcode, Types, {}) {}
143 
144  raw_ostream &print(raw_ostream &OS) const;
145 };
146 
147 /// The result of a query. It either indicates a final answer of Legal or
148 /// Unsupported or describes an action that must be taken to make an operation
149 /// more legal.
151  /// The action to take or the final answer.
153  /// If describing an action, the type index to change. Otherwise zero.
154  unsigned TypeIdx;
155  /// If describing an action, the new type for TypeIdx. Otherwise LLT{}.
157 
159  const LLT NewType)
161 
162  bool operator==(const LegalizeActionStep &RHS) const {
163  return std::tie(Action, TypeIdx, NewType) ==
164  std::tie(RHS.Action, RHS.TypeIdx, RHS.NewType);
165  }
166 };
167 
169 using LegalizeMutation =
170  std::function<std::pair<unsigned, LLT>(const LegalityQuery &)>;
171 
172 namespace LegalityPredicates {
176  uint64_t MemSize;
177  uint64_t Align;
178 
179  bool operator==(const TypePairAndMemDesc &Other) const {
180  return Type0 == Other.Type0 && Type1 == Other.Type1 &&
181  Align == Other.Align &&
182  MemSize == Other.MemSize;
183  }
184 
185  /// \returns true if this memory access is legal with for the access described
186  /// by \p Other (The alignment is sufficient for the size and result type).
187  bool isCompatible(const TypePairAndMemDesc &Other) const {
188  return Type0 == Other.Type0 && Type1 == Other.Type1 &&
189  Align >= Other.Align &&
190  MemSize == Other.MemSize;
191  }
192 };
193 
194 /// True iff P0 and P1 are true.
195 template<typename Predicate>
197  return [=](const LegalityQuery &Query) {
198  return P0(Query) && P1(Query);
199  };
200 }
201 /// True iff all given predicates are true.
202 template<typename Predicate, typename... Args>
204  return all(all(P0, P1), args...);
205 }
206 
207 /// True iff P0 or P1 are true.
208 template<typename Predicate>
210  return [=](const LegalityQuery &Query) {
211  return P0(Query) || P1(Query);
212  };
213 }
214 /// True iff any given predicates are true.
215 template<typename Predicate, typename... Args>
217  return any(any(P0, P1), args...);
218 }
219 
220 /// True iff the given type index is the specified type.
221 LegalityPredicate typeIs(unsigned TypeIdx, LLT TypesInit);
222 /// True iff the given type index is one of the specified types.
223 LegalityPredicate typeInSet(unsigned TypeIdx,
224  std::initializer_list<LLT> TypesInit);
225 
226 /// True iff the given type index is not the specified type.
227 inline LegalityPredicate typeIsNot(unsigned TypeIdx, LLT Type) {
228  return [=](const LegalityQuery &Query) {
229  return Query.Types[TypeIdx] != Type;
230  };
231 }
232 
233 /// True iff the given types for the given pair of type indexes is one of the
234 /// specified type pairs.
236 typePairInSet(unsigned TypeIdx0, unsigned TypeIdx1,
237  std::initializer_list<std::pair<LLT, LLT>> TypesInit);
238 /// True iff the given types for the given pair of type indexes is one of the
239 /// specified type pairs.
241  unsigned TypeIdx0, unsigned TypeIdx1, unsigned MMOIdx,
242  std::initializer_list<TypePairAndMemDesc> TypesAndMemDescInit);
243 /// True iff the specified type index is a scalar.
244 LegalityPredicate isScalar(unsigned TypeIdx);
245 /// True iff the specified type index is a vector.
246 LegalityPredicate isVector(unsigned TypeIdx);
247 /// True iff the specified type index is a pointer (with any address space).
248 LegalityPredicate isPointer(unsigned TypeIdx);
249 /// True iff the specified type index is a pointer with the specified address
250 /// space.
251 LegalityPredicate isPointer(unsigned TypeIdx, unsigned AddrSpace);
252 
253 /// True if the type index is a vector with element type \p EltTy
254 LegalityPredicate elementTypeIs(unsigned TypeIdx, LLT EltTy);
255 
256 /// True iff the specified type index is a scalar that's narrower than the given
257 /// size.
258 LegalityPredicate scalarNarrowerThan(unsigned TypeIdx, unsigned Size);
259 
260 /// True iff the specified type index is a scalar that's wider than the given
261 /// size.
262 LegalityPredicate scalarWiderThan(unsigned TypeIdx, unsigned Size);
263 
264 /// True iff the specified type index is a scalar or vector with an element type
265 /// that's narrower than the given size.
266 LegalityPredicate scalarOrEltNarrowerThan(unsigned TypeIdx, unsigned Size);
267 
268 /// True iff the specified type index is a scalar or a vector with an element
269 /// type that's wider than the given size.
270 LegalityPredicate scalarOrEltWiderThan(unsigned TypeIdx, unsigned Size);
271 
272 /// True iff the specified type index is a scalar whose size is not a power of
273 /// 2.
274 LegalityPredicate sizeNotPow2(unsigned TypeIdx);
275 
276 /// True iff the specified type index is a scalar or vector whose element size
277 /// is not a power of 2.
278 LegalityPredicate scalarOrEltSizeNotPow2(unsigned TypeIdx);
279 
280 /// True if the total bitwidth of the specified type index is \p Size bits.
281 LegalityPredicate sizeIs(unsigned TypeIdx, unsigned Size);
282 
283 /// True iff the specified type indices are both the same bit size.
284 LegalityPredicate sameSize(unsigned TypeIdx0, unsigned TypeIdx1);
285 
286 /// True iff the first type index has a larger total bit size than second type
287 /// index.
288 LegalityPredicate largerThan(unsigned TypeIdx0, unsigned TypeIdx1);
289 
290 /// True iff the first type index has a smaller total bit size than second type
291 /// index.
292 LegalityPredicate smallerThan(unsigned TypeIdx0, unsigned TypeIdx1);
293 
294 /// True iff the specified MMO index has a size that is not a power of 2
296 /// True iff the specified type index is a vector whose element count is not a
297 /// power of 2.
298 LegalityPredicate numElementsNotPow2(unsigned TypeIdx);
299 /// True iff the specified MMO index has at an atomic ordering of at Ordering or
300 /// stronger.
302  AtomicOrdering Ordering);
303 } // end namespace LegalityPredicates
304 
305 namespace LegalizeMutations {
306 /// Select this specific type for the given type index.
307 LegalizeMutation changeTo(unsigned TypeIdx, LLT Ty);
308 
309 /// Keep the same type as the given type index.
310 LegalizeMutation changeTo(unsigned TypeIdx, unsigned FromTypeIdx);
311 
312 /// Keep the same scalar or element type as the given type index.
313 LegalizeMutation changeElementTo(unsigned TypeIdx, unsigned FromTypeIdx);
314 
315 /// Keep the same scalar or element type as the given type.
316 LegalizeMutation changeElementTo(unsigned TypeIdx, LLT Ty);
317 
318 /// Change the scalar size or element size to have the same scalar size as type
319 /// index \p FromIndex. Unlike changeElementTo, this discards pointer types and
320 /// only changes the size.
321 LegalizeMutation changeElementSizeTo(unsigned TypeIdx, unsigned FromTypeIdx);
322 
323 /// Widen the scalar type or vector element type for the given type index to the
324 /// next power of 2.
325 LegalizeMutation widenScalarOrEltToNextPow2(unsigned TypeIdx, unsigned Min = 0);
326 
327 /// Add more elements to the type for the given type index to the next power of
328 /// 2.
329 LegalizeMutation moreElementsToNextPow2(unsigned TypeIdx, unsigned Min = 0);
330 /// Break up the vector type for the given type index into the element type.
331 LegalizeMutation scalarize(unsigned TypeIdx);
332 } // end namespace LegalizeMutations
333 
334 /// A single rule in a legalizer info ruleset.
335 /// The specified action is chosen when the predicate is true. Where appropriate
336 /// for the action (e.g. for WidenScalar) the new type is selected using the
337 /// given mutator.
339  LegalityPredicate Predicate;
340  LegalizeAction Action;
341  LegalizeMutation Mutation;
342 
343 public:
345  LegalizeMutation Mutation = nullptr)
346  : Predicate(Predicate), Action(Action), Mutation(Mutation) {}
347 
348  /// Test whether the LegalityQuery matches.
349  bool match(const LegalityQuery &Query) const {
350  return Predicate(Query);
351  }
352 
353  LegalizeAction getAction() const { return Action; }
354 
355  /// Determine the change to make.
356  std::pair<unsigned, LLT> determineMutation(const LegalityQuery &Query) const {
357  if (Mutation)
358  return Mutation(Query);
359  return std::make_pair(0, LLT{});
360  }
361 };
362 
364  /// When non-zero, the opcode we are an alias of
365  unsigned AliasOf;
366  /// If true, there is another opcode that aliases this one
367  bool IsAliasedByAnother;
369 
370 #ifndef NDEBUG
371  /// If bit I is set, this rule set contains a rule that may handle (predicate
372  /// or perform an action upon (or both)) the type index I. The uncertainty
373  /// comes from free-form rules executing user-provided lambda functions. We
374  /// conservatively assume such rules do the right thing and cover all type
375  /// indices. The bitset is intentionally 1 bit wider than it absolutely needs
376  /// to be to distinguish such cases from the cases where all type indices are
377  /// individually handled.
382 #endif
383 
384  unsigned typeIdx(unsigned TypeIdx) {
385  assert(TypeIdx <=
387  "Type Index is out of bounds");
388 #ifndef NDEBUG
389  TypeIdxsCovered.set(TypeIdx);
390 #endif
391  return TypeIdx;
392  }
393 
394  unsigned immIdx(unsigned ImmIdx) {
397  "Imm Index is out of bounds");
398 #ifndef NDEBUG
399  ImmIdxsCovered.set(ImmIdx);
400 #endif
401  return ImmIdx;
402  }
403 
404  void markAllIdxsAsCovered() {
405 #ifndef NDEBUG
406  TypeIdxsCovered.set();
407  ImmIdxsCovered.set();
408 #endif
409  }
410 
411  void add(const LegalizeRule &Rule) {
412  assert(AliasOf == 0 &&
413  "RuleSet is aliased, change the representative opcode instead");
414  Rules.push_back(Rule);
415  }
416 
417  static bool always(const LegalityQuery &) { return true; }
418 
419  /// Use the given action when the predicate is true.
420  /// Action should not be an action that requires mutation.
421  LegalizeRuleSet &actionIf(LegalizeAction Action,
423  add({Predicate, Action});
424  return *this;
425  }
426  /// Use the given action when the predicate is true.
427  /// Action should be an action that requires mutation.
430  add({Predicate, Action, Mutation});
431  return *this;
432  }
433  /// Use the given action when type index 0 is any type in the given list.
434  /// Action should not be an action that requires mutation.
435  LegalizeRuleSet &actionFor(LegalizeAction Action,
436  std::initializer_list<LLT> Types) {
437  using namespace LegalityPredicates;
438  return actionIf(Action, typeInSet(typeIdx(0), Types));
439  }
440  /// Use the given action when type index 0 is any type in the given list.
441  /// Action should be an action that requires mutation.
442  LegalizeRuleSet &actionFor(LegalizeAction Action,
443  std::initializer_list<LLT> Types,
445  using namespace LegalityPredicates;
446  return actionIf(Action, typeInSet(typeIdx(0), Types), Mutation);
447  }
448  /// Use the given action when type indexes 0 and 1 is any type pair in the
449  /// given list.
450  /// Action should not be an action that requires mutation.
451  LegalizeRuleSet &actionFor(LegalizeAction Action,
452  std::initializer_list<std::pair<LLT, LLT>> Types) {
453  using namespace LegalityPredicates;
454  return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types));
455  }
456  /// Use the given action when type indexes 0 and 1 is any type pair in the
457  /// given list.
458  /// Action should be an action that requires mutation.
459  LegalizeRuleSet &actionFor(LegalizeAction Action,
460  std::initializer_list<std::pair<LLT, LLT>> Types,
462  using namespace LegalityPredicates;
463  return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types),
464  Mutation);
465  }
466  /// Use the given action when type index 0 is any type in the given list and
467  /// imm index 0 is anything. Action should not be an action that requires
468  /// mutation.
469  LegalizeRuleSet &actionForTypeWithAnyImm(LegalizeAction Action,
470  std::initializer_list<LLT> Types) {
471  using namespace LegalityPredicates;
472  immIdx(0); // Inform verifier imm idx 0 is handled.
473  return actionIf(Action, typeInSet(typeIdx(0), Types));
474  }
475 
476  LegalizeRuleSet &actionForTypeWithAnyImm(
477  LegalizeAction Action, std::initializer_list<std::pair<LLT, LLT>> Types) {
478  using namespace LegalityPredicates;
479  immIdx(0); // Inform verifier imm idx 0 is handled.
480  return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types));
481  }
482 
483  /// Use the given action when type indexes 0 and 1 are both in the given list.
484  /// That is, the type pair is in the cartesian product of the list.
485  /// Action should not be an action that requires mutation.
486  LegalizeRuleSet &actionForCartesianProduct(LegalizeAction Action,
487  std::initializer_list<LLT> Types) {
488  using namespace LegalityPredicates;
489  return actionIf(Action, all(typeInSet(typeIdx(0), Types),
490  typeInSet(typeIdx(1), Types)));
491  }
492  /// Use the given action when type indexes 0 and 1 are both in their
493  /// respective lists.
494  /// That is, the type pair is in the cartesian product of the lists
495  /// Action should not be an action that requires mutation.
497  actionForCartesianProduct(LegalizeAction Action,
498  std::initializer_list<LLT> Types0,
499  std::initializer_list<LLT> Types1) {
500  using namespace LegalityPredicates;
501  return actionIf(Action, all(typeInSet(typeIdx(0), Types0),
502  typeInSet(typeIdx(1), Types1)));
503  }
504  /// Use the given action when type indexes 0, 1, and 2 are all in their
505  /// respective lists.
506  /// That is, the type triple is in the cartesian product of the lists
507  /// Action should not be an action that requires mutation.
508  LegalizeRuleSet &actionForCartesianProduct(
509  LegalizeAction Action, std::initializer_list<LLT> Types0,
510  std::initializer_list<LLT> Types1, std::initializer_list<LLT> Types2) {
511  using namespace LegalityPredicates;
512  return actionIf(Action, all(typeInSet(typeIdx(0), Types0),
513  all(typeInSet(typeIdx(1), Types1),
514  typeInSet(typeIdx(2), Types2))));
515  }
516 
517 public:
518  LegalizeRuleSet() : AliasOf(0), IsAliasedByAnother(false), Rules() {}
519 
520  bool isAliasedByAnother() { return IsAliasedByAnother; }
521  void setIsAliasedByAnother() { IsAliasedByAnother = true; }
522  void aliasTo(unsigned Opcode) {
523  assert((AliasOf == 0 || AliasOf == Opcode) &&
524  "Opcode is already aliased to another opcode");
525  assert(Rules.empty() && "Aliasing will discard rules");
526  AliasOf = Opcode;
527  }
528  unsigned getAlias() const { return AliasOf; }
529 
530  /// The instruction is legal if predicate is true.
532  // We have no choice but conservatively assume that the free-form
533  // user-provided Predicate properly handles all type indices:
534  markAllIdxsAsCovered();
535  return actionIf(LegalizeAction::Legal, Predicate);
536  }
537  /// The instruction is legal when type index 0 is any type in the given list.
538  LegalizeRuleSet &legalFor(std::initializer_list<LLT> Types) {
539  return actionFor(LegalizeAction::Legal, Types);
540  }
541  /// The instruction is legal when type indexes 0 and 1 is any type pair in the
542  /// given list.
543  LegalizeRuleSet &legalFor(std::initializer_list<std::pair<LLT, LLT>> Types) {
544  return actionFor(LegalizeAction::Legal, Types);
545  }
546  /// The instruction is legal when type index 0 is any type in the given list
547  /// and imm index 0 is anything.
548  LegalizeRuleSet &legalForTypeWithAnyImm(std::initializer_list<LLT> Types) {
549  markAllIdxsAsCovered();
550  return actionForTypeWithAnyImm(LegalizeAction::Legal, Types);
551  }
552 
554  std::initializer_list<std::pair<LLT, LLT>> Types) {
555  markAllIdxsAsCovered();
556  return actionForTypeWithAnyImm(LegalizeAction::Legal, Types);
557  }
558 
559  /// The instruction is legal when type indexes 0 and 1 along with the memory
560  /// size and minimum alignment is any type and size tuple in the given list.
562  std::initializer_list<LegalityPredicates::TypePairAndMemDesc>
563  TypesAndMemDesc) {
564  return actionIf(LegalizeAction::Legal,
566  typeIdx(0), typeIdx(1), /*MMOIdx*/ 0, TypesAndMemDesc));
567  }
568  /// The instruction is legal when type indexes 0 and 1 are both in the given
569  /// list. That is, the type pair is in the cartesian product of the list.
570  LegalizeRuleSet &legalForCartesianProduct(std::initializer_list<LLT> Types) {
571  return actionForCartesianProduct(LegalizeAction::Legal, Types);
572  }
573  /// The instruction is legal when type indexes 0 and 1 are both their
574  /// respective lists.
575  LegalizeRuleSet &legalForCartesianProduct(std::initializer_list<LLT> Types0,
576  std::initializer_list<LLT> Types1) {
577  return actionForCartesianProduct(LegalizeAction::Legal, Types0, Types1);
578  }
579  /// The instruction is legal when type indexes 0, 1, and 2 are both their
580  /// respective lists.
581  LegalizeRuleSet &legalForCartesianProduct(std::initializer_list<LLT> Types0,
582  std::initializer_list<LLT> Types1,
583  std::initializer_list<LLT> Types2) {
584  return actionForCartesianProduct(LegalizeAction::Legal, Types0, Types1,
585  Types2);
586  }
587 
589  using namespace LegalizeMutations;
590  markAllIdxsAsCovered();
591  return actionIf(LegalizeAction::Legal, always);
592  }
593 
594  /// The specified type index is coerced if predicate is true.
597  // We have no choice but conservatively assume that lowering with a
598  // free-form user provided Predicate properly handles all type indices:
599  markAllIdxsAsCovered();
600  return actionIf(LegalizeAction::Bitcast, Predicate, Mutation);
601  }
602 
603  /// The instruction is lowered.
605  using namespace LegalizeMutations;
606  // We have no choice but conservatively assume that predicate-less lowering
607  // properly handles all type indices by design:
608  markAllIdxsAsCovered();
609  return actionIf(LegalizeAction::Lower, always);
610  }
611  /// The instruction is lowered if predicate is true. Keep type index 0 as the
612  /// same type.
614  using namespace LegalizeMutations;
615  // We have no choice but conservatively assume that lowering with a
616  // free-form user provided Predicate properly handles all type indices:
617  markAllIdxsAsCovered();
618  return actionIf(LegalizeAction::Lower, Predicate);
619  }
620  /// The instruction is lowered if predicate is true.
623  // We have no choice but conservatively assume that lowering with a
624  // free-form user provided Predicate properly handles all type indices:
625  markAllIdxsAsCovered();
626  return actionIf(LegalizeAction::Lower, Predicate, Mutation);
627  }
628  /// The instruction is lowered when type index 0 is any type in the given
629  /// list. Keep type index 0 as the same type.
630  LegalizeRuleSet &lowerFor(std::initializer_list<LLT> Types) {
631  return actionFor(LegalizeAction::Lower, Types);
632  }
633  /// The instruction is lowered when type index 0 is any type in the given
634  /// list.
635  LegalizeRuleSet &lowerFor(std::initializer_list<LLT> Types,
637  return actionFor(LegalizeAction::Lower, Types, Mutation);
638  }
639  /// The instruction is lowered when type indexes 0 and 1 is any type pair in
640  /// the given list. Keep type index 0 as the same type.
641  LegalizeRuleSet &lowerFor(std::initializer_list<std::pair<LLT, LLT>> Types) {
642  return actionFor(LegalizeAction::Lower, Types);
643  }
644  /// The instruction is lowered when type indexes 0 and 1 is any type pair in
645  /// the given list.
646  LegalizeRuleSet &lowerFor(std::initializer_list<std::pair<LLT, LLT>> Types,
648  return actionFor(LegalizeAction::Lower, Types, Mutation);
649  }
650  /// The instruction is lowered when type indexes 0 and 1 are both in their
651  /// respective lists.
652  LegalizeRuleSet &lowerForCartesianProduct(std::initializer_list<LLT> Types0,
653  std::initializer_list<LLT> Types1) {
654  using namespace LegalityPredicates;
655  return actionForCartesianProduct(LegalizeAction::Lower, Types0, Types1);
656  }
657  /// The instruction is lowered when when type indexes 0, 1, and 2 are all in
658  /// their respective lists.
659  LegalizeRuleSet &lowerForCartesianProduct(std::initializer_list<LLT> Types0,
660  std::initializer_list<LLT> Types1,
661  std::initializer_list<LLT> Types2) {
662  using namespace LegalityPredicates;
663  return actionForCartesianProduct(LegalizeAction::Lower, Types0, Types1,
664  Types2);
665  }
666 
667  /// The instruction is emitted as a library call.
669  using namespace LegalizeMutations;
670  // We have no choice but conservatively assume that predicate-less lowering
671  // properly handles all type indices by design:
672  markAllIdxsAsCovered();
673  return actionIf(LegalizeAction::Libcall, always);
674  }
675 
676  /// Like legalIf, but for the Libcall action.
678  // We have no choice but conservatively assume that a libcall with a
679  // free-form user provided Predicate properly handles all type indices:
680  markAllIdxsAsCovered();
681  return actionIf(LegalizeAction::Libcall, Predicate);
682  }
683  LegalizeRuleSet &libcallFor(std::initializer_list<LLT> Types) {
684  return actionFor(LegalizeAction::Libcall, Types);
685  }
687  libcallFor(std::initializer_list<std::pair<LLT, LLT>> Types) {
688  return actionFor(LegalizeAction::Libcall, Types);
689  }
691  libcallForCartesianProduct(std::initializer_list<LLT> Types) {
692  return actionForCartesianProduct(LegalizeAction::Libcall, Types);
693  }
695  libcallForCartesianProduct(std::initializer_list<LLT> Types0,
696  std::initializer_list<LLT> Types1) {
697  return actionForCartesianProduct(LegalizeAction::Libcall, Types0, Types1);
698  }
699 
700  /// Widen the scalar to the one selected by the mutation if the predicate is
701  /// true.
704  // We have no choice but conservatively assume that an action with a
705  // free-form user provided Predicate properly handles all type indices:
706  markAllIdxsAsCovered();
708  }
709  /// Narrow the scalar to the one selected by the mutation if the predicate is
710  /// true.
713  // We have no choice but conservatively assume that an action with a
714  // free-form user provided Predicate properly handles all type indices:
715  markAllIdxsAsCovered();
717  }
718  /// Narrow the scalar, specified in mutation, when type indexes 0 and 1 is any
719  /// type pair in the given list.
721  narrowScalarFor(std::initializer_list<std::pair<LLT, LLT>> Types,
723  return actionFor(LegalizeAction::NarrowScalar, Types, Mutation);
724  }
725 
726  /// Add more elements to reach the type selected by the mutation if the
727  /// predicate is true.
730  // We have no choice but conservatively assume that an action with a
731  // free-form user provided Predicate properly handles all type indices:
732  markAllIdxsAsCovered();
734  }
735  /// Remove elements to reach the type selected by the mutation if the
736  /// predicate is true.
739  // We have no choice but conservatively assume that an action with a
740  // free-form user provided Predicate properly handles all type indices:
741  markAllIdxsAsCovered();
743  }
744 
745  /// The instruction is unsupported.
747  markAllIdxsAsCovered();
748  return actionIf(LegalizeAction::Unsupported, always);
749  }
751  return actionIf(LegalizeAction::Unsupported, Predicate);
752  }
753 
754  LegalizeRuleSet &unsupportedFor(std::initializer_list<LLT> Types) {
755  return actionFor(LegalizeAction::Unsupported, Types);
756  }
757 
759  return actionIf(LegalizeAction::Unsupported,
761  }
763  return actionIf(LegalizeAction::Lower,
765  }
766 
768  // We have no choice but conservatively assume that a custom action with a
769  // free-form user provided Predicate properly handles all type indices:
770  markAllIdxsAsCovered();
771  return actionIf(LegalizeAction::Custom, Predicate);
772  }
773  LegalizeRuleSet &customFor(std::initializer_list<LLT> Types) {
774  return actionFor(LegalizeAction::Custom, Types);
775  }
776 
777  /// The instruction is custom when type indexes 0 and 1 is any type pair in the
778  /// given list.
779  LegalizeRuleSet &customFor(std::initializer_list<std::pair<LLT, LLT>> Types) {
780  return actionFor(LegalizeAction::Custom, Types);
781  }
782 
783  LegalizeRuleSet &customForCartesianProduct(std::initializer_list<LLT> Types) {
784  return actionForCartesianProduct(LegalizeAction::Custom, Types);
785  }
787  customForCartesianProduct(std::initializer_list<LLT> Types0,
788  std::initializer_list<LLT> Types1) {
789  return actionForCartesianProduct(LegalizeAction::Custom, Types0, Types1);
790  }
791 
792  /// Unconditionally custom lower.
794  return customIf(always);
795  }
796 
797  /// Widen the scalar to the next power of two that is at least MinSize.
798  /// No effect if the type is not a scalar or is a power of two.
800  unsigned MinSize = 0) {
801  using namespace LegalityPredicates;
802  return actionIf(
803  LegalizeAction::WidenScalar, sizeNotPow2(typeIdx(TypeIdx)),
805  }
806 
807  /// Widen the scalar or vector element type to the next power of two that is
808  /// at least MinSize. No effect if the scalar size is a power of two.
810  unsigned MinSize = 0) {
811  using namespace LegalityPredicates;
812  return actionIf(
815  }
816 
818  using namespace LegalityPredicates;
819  return actionIf(LegalizeAction::NarrowScalar, isScalar(typeIdx(TypeIdx)),
820  Mutation);
821  }
822 
823  LegalizeRuleSet &scalarize(unsigned TypeIdx) {
824  using namespace LegalityPredicates;
825  return actionIf(LegalizeAction::FewerElements, isVector(typeIdx(TypeIdx)),
827  }
828 
830  using namespace LegalityPredicates;
831  return actionIf(LegalizeAction::FewerElements,
832  all(Predicate, isVector(typeIdx(TypeIdx))),
834  }
835 
836  /// Ensure the scalar or element is at least as wide as Ty.
837  LegalizeRuleSet &minScalarOrElt(unsigned TypeIdx, const LLT Ty) {
838  using namespace LegalityPredicates;
839  using namespace LegalizeMutations;
840  return actionIf(LegalizeAction::WidenScalar,
842  changeElementTo(typeIdx(TypeIdx), Ty));
843  }
844 
845  /// Ensure the scalar or element is at least as wide as Ty.
847  unsigned TypeIdx, const LLT Ty) {
848  using namespace LegalityPredicates;
849  using namespace LegalizeMutations;
850  return actionIf(LegalizeAction::WidenScalar,
852  TypeIdx, Ty.getScalarSizeInBits())),
853  changeElementTo(typeIdx(TypeIdx), Ty));
854  }
855 
856  /// Ensure the scalar is at least as wide as Ty.
857  LegalizeRuleSet &minScalar(unsigned TypeIdx, const LLT Ty) {
858  using namespace LegalityPredicates;
859  using namespace LegalizeMutations;
860  return actionIf(LegalizeAction::WidenScalar,
861  scalarNarrowerThan(TypeIdx, Ty.getSizeInBits()),
862  changeTo(typeIdx(TypeIdx), Ty));
863  }
864 
865  /// Ensure the scalar is at most as wide as Ty.
866  LegalizeRuleSet &maxScalarOrElt(unsigned TypeIdx, const LLT Ty) {
867  using namespace LegalityPredicates;
868  using namespace LegalizeMutations;
869  return actionIf(LegalizeAction::NarrowScalar,
871  changeElementTo(typeIdx(TypeIdx), Ty));
872  }
873 
874  /// Ensure the scalar is at most as wide as Ty.
875  LegalizeRuleSet &maxScalar(unsigned TypeIdx, const LLT Ty) {
876  using namespace LegalityPredicates;
877  using namespace LegalizeMutations;
878  return actionIf(LegalizeAction::NarrowScalar,
879  scalarWiderThan(TypeIdx, Ty.getSizeInBits()),
880  changeTo(typeIdx(TypeIdx), Ty));
881  }
882 
883  /// Conditionally limit the maximum size of the scalar.
884  /// For example, when the maximum size of one type depends on the size of
885  /// another such as extracting N bits from an M bit container.
887  const LLT Ty) {
888  using namespace LegalityPredicates;
889  using namespace LegalizeMutations;
890  return actionIf(
892  [=](const LegalityQuery &Query) {
893  const LLT QueryTy = Query.Types[TypeIdx];
894  return QueryTy.isScalar() &&
895  QueryTy.getSizeInBits() > Ty.getSizeInBits() &&
896  Predicate(Query);
897  },
898  changeElementTo(typeIdx(TypeIdx), Ty));
899  }
900 
901  /// Limit the range of scalar sizes to MinTy and MaxTy.
902  LegalizeRuleSet &clampScalar(unsigned TypeIdx, const LLT MinTy,
903  const LLT MaxTy) {
904  assert(MinTy.isScalar() && MaxTy.isScalar() && "Expected scalar types");
905  return minScalar(TypeIdx, MinTy).maxScalar(TypeIdx, MaxTy);
906  }
907 
908  /// Limit the range of scalar sizes to MinTy and MaxTy.
909  LegalizeRuleSet &clampScalarOrElt(unsigned TypeIdx, const LLT MinTy,
910  const LLT MaxTy) {
911  return minScalarOrElt(TypeIdx, MinTy).maxScalarOrElt(TypeIdx, MaxTy);
912  }
913 
914  /// Widen the scalar to match the size of another.
915  LegalizeRuleSet &minScalarSameAs(unsigned TypeIdx, unsigned LargeTypeIdx) {
916  typeIdx(TypeIdx);
917  return widenScalarIf(
918  [=](const LegalityQuery &Query) {
919  return Query.Types[LargeTypeIdx].getScalarSizeInBits() >
920  Query.Types[TypeIdx].getSizeInBits();
921  },
922  LegalizeMutations::changeElementSizeTo(TypeIdx, LargeTypeIdx));
923  }
924 
925  /// Narrow the scalar to match the size of another.
926  LegalizeRuleSet &maxScalarSameAs(unsigned TypeIdx, unsigned NarrowTypeIdx) {
927  typeIdx(TypeIdx);
928  return narrowScalarIf(
929  [=](const LegalityQuery &Query) {
930  return Query.Types[NarrowTypeIdx].getScalarSizeInBits() <
931  Query.Types[TypeIdx].getSizeInBits();
932  },
933  LegalizeMutations::changeElementSizeTo(TypeIdx, NarrowTypeIdx));
934  }
935 
936  /// Change the type \p TypeIdx to have the same scalar size as type \p
937  /// SameSizeIdx.
938  LegalizeRuleSet &scalarSameSizeAs(unsigned TypeIdx, unsigned SameSizeIdx) {
939  return minScalarSameAs(TypeIdx, SameSizeIdx)
940  .maxScalarSameAs(TypeIdx, SameSizeIdx);
941  }
942 
943  /// Conditionally widen the scalar or elt to match the size of another.
945  unsigned TypeIdx, unsigned LargeTypeIdx) {
946  typeIdx(TypeIdx);
947  return widenScalarIf(
948  [=](const LegalityQuery &Query) {
949  return Query.Types[LargeTypeIdx].getScalarSizeInBits() >
950  Query.Types[TypeIdx].getScalarSizeInBits() &&
951  Predicate(Query);
952  },
953  [=](const LegalityQuery &Query) {
954  LLT T = Query.Types[LargeTypeIdx];
955  return std::make_pair(TypeIdx, T);
956  });
957  }
958 
959  /// Conditionally narrow the scalar or elt to match the size of another.
961  unsigned TypeIdx,
962  unsigned SmallTypeIdx) {
963  typeIdx(TypeIdx);
964  return narrowScalarIf(
965  [=](const LegalityQuery &Query) {
966  return Query.Types[SmallTypeIdx].getScalarSizeInBits() <
967  Query.Types[TypeIdx].getScalarSizeInBits() &&
968  Predicate(Query);
969  },
970  [=](const LegalityQuery &Query) {
971  LLT T = Query.Types[SmallTypeIdx];
972  return std::make_pair(TypeIdx, T);
973  });
974  }
975 
976  /// Add more elements to the vector to reach the next power of two.
977  /// No effect if the type is not a vector or the element count is a power of
978  /// two.
980  using namespace LegalityPredicates;
981  return actionIf(LegalizeAction::MoreElements,
982  numElementsNotPow2(typeIdx(TypeIdx)),
984  }
985 
986  /// Limit the number of elements in EltTy vectors to at least MinElements.
987  LegalizeRuleSet &clampMinNumElements(unsigned TypeIdx, const LLT EltTy,
988  unsigned MinElements) {
989  // Mark the type index as covered:
990  typeIdx(TypeIdx);
991  return actionIf(
993  [=](const LegalityQuery &Query) {
994  LLT VecTy = Query.Types[TypeIdx];
995  return VecTy.isVector() && VecTy.getElementType() == EltTy &&
996  VecTy.getNumElements() < MinElements;
997  },
998  [=](const LegalityQuery &Query) {
999  LLT VecTy = Query.Types[TypeIdx];
1000  return std::make_pair(
1001  TypeIdx, LLT::vector(MinElements, VecTy.getElementType()));
1002  });
1003  }
1004  /// Limit the number of elements in EltTy vectors to at most MaxElements.
1005  LegalizeRuleSet &clampMaxNumElements(unsigned TypeIdx, const LLT EltTy,
1006  unsigned MaxElements) {
1007  // Mark the type index as covered:
1008  typeIdx(TypeIdx);
1009  return actionIf(
1011  [=](const LegalityQuery &Query) {
1012  LLT VecTy = Query.Types[TypeIdx];
1013  return VecTy.isVector() && VecTy.getElementType() == EltTy &&
1014  VecTy.getNumElements() > MaxElements;
1015  },
1016  [=](const LegalityQuery &Query) {
1017  LLT VecTy = Query.Types[TypeIdx];
1018  LLT NewTy = LLT::scalarOrVector(MaxElements, VecTy.getElementType());
1019  return std::make_pair(TypeIdx, NewTy);
1020  });
1021  }
1022  /// Limit the number of elements for the given vectors to at least MinTy's
1023  /// number of elements and at most MaxTy's number of elements.
1024  ///
1025  /// No effect if the type is not a vector or does not have the same element
1026  /// type as the constraints.
1027  /// The element type of MinTy and MaxTy must match.
1028  LegalizeRuleSet &clampNumElements(unsigned TypeIdx, const LLT MinTy,
1029  const LLT MaxTy) {
1030  assert(MinTy.getElementType() == MaxTy.getElementType() &&
1031  "Expected element types to agree");
1032 
1033  const LLT EltTy = MinTy.getElementType();
1034  return clampMinNumElements(TypeIdx, EltTy, MinTy.getNumElements())
1035  .clampMaxNumElements(TypeIdx, EltTy, MaxTy.getNumElements());
1036  }
1037 
1038  /// Fallback on the previous implementation. This should only be used while
1039  /// porting a rule.
1042  return *this;
1043  }
1044 
1045  /// Check if there is no type index which is obviously not handled by the
1046  /// LegalizeRuleSet in any way at all.
1047  /// \pre Type indices of the opcode form a dense [0, \p NumTypeIdxs) set.
1048  bool verifyTypeIdxsCoverage(unsigned NumTypeIdxs) const;
1049  /// Check if there is no imm index which is obviously not handled by the
1050  /// LegalizeRuleSet in any way at all.
1051  /// \pre Type indices of the opcode form a dense [0, \p NumTypeIdxs) set.
1052  bool verifyImmIdxsCoverage(unsigned NumImmIdxs) const;
1053 
1054  /// Apply the ruleset to the given LegalityQuery.
1055  LegalizeActionStep apply(const LegalityQuery &Query) const;
1056 };
1057 
1059 public:
1060  LegalizerInfo();
1061  virtual ~LegalizerInfo() = default;
1062 
1063  unsigned getOpcodeIdxForOpcode(unsigned Opcode) const;
1064  unsigned getActionDefinitionsIdx(unsigned Opcode) const;
1065 
1066  /// Compute any ancillary tables needed to quickly decide how an operation
1067  /// should be handled. This must be called after all "set*Action"methods but
1068  /// before any query is made or incorrect results may be returned.
1069  void computeTables();
1070 
1071  /// Perform simple self-diagnostic and assert if there is anything obviously
1072  /// wrong with the actions set up.
1073  void verify(const MCInstrInfo &MII) const;
1074 
1076  using namespace LegalizeActions;
1077  switch (Action) {
1078  case NarrowScalar:
1079  case WidenScalar:
1080  case FewerElements:
1081  case MoreElements:
1082  case Unsupported:
1083  return true;
1084  default:
1085  return false;
1086  }
1087  }
1088 
1089  using SizeAndAction = std::pair<uint16_t, LegalizeAction>;
1090  using SizeAndActionsVec = std::vector<SizeAndAction>;
1091  using SizeChangeStrategy =
1093 
1094  /// More friendly way to set an action for common types that have an LLT
1095  /// representation.
1096  /// The LegalizeAction must be one for which NeedsLegalizingToDifferentSize
1097  /// returns false.
1098  void setAction(const InstrAspect &Aspect, LegalizeAction Action) {
1099  assert(!needsLegalizingToDifferentSize(Action));
1100  TablesInitialized = false;
1101  const unsigned OpcodeIdx = Aspect.Opcode - FirstOp;
1102  if (SpecifiedActions[OpcodeIdx].size() <= Aspect.Idx)
1103  SpecifiedActions[OpcodeIdx].resize(Aspect.Idx + 1);
1104  SpecifiedActions[OpcodeIdx][Aspect.Idx][Aspect.Type] = Action;
1105  }
1106 
1107  /// The setAction calls record the non-size-changing legalization actions
1108  /// to take on specificly-sized types. The SizeChangeStrategy defines what
1109  /// to do when the size of the type needs to be changed to reach a legally
1110  /// sized type (i.e., one that was defined through a setAction call).
1111  /// e.g.
1112  /// setAction ({G_ADD, 0, LLT::scalar(32)}, Legal);
1113  /// setLegalizeScalarToDifferentSizeStrategy(
1114  /// G_ADD, 0, widenToLargerTypesAndNarrowToLargest);
1115  /// will end up defining getAction({G_ADD, 0, T}) to return the following
1116  /// actions for different scalar types T:
1117  /// LLT::scalar(1)..LLT::scalar(31): {WidenScalar, 0, LLT::scalar(32)}
1118  /// LLT::scalar(32): {Legal, 0, LLT::scalar(32)}
1119  /// LLT::scalar(33)..: {NarrowScalar, 0, LLT::scalar(32)}
1120  ///
1121  /// If no SizeChangeAction gets defined, through this function,
1122  /// the default is unsupportedForDifferentSizes.
1123  void setLegalizeScalarToDifferentSizeStrategy(const unsigned Opcode,
1124  const unsigned TypeIdx,
1126  const unsigned OpcodeIdx = Opcode - FirstOp;
1127  if (ScalarSizeChangeStrategies[OpcodeIdx].size() <= TypeIdx)
1128  ScalarSizeChangeStrategies[OpcodeIdx].resize(TypeIdx + 1);
1129  ScalarSizeChangeStrategies[OpcodeIdx][TypeIdx] = S;
1130  }
1131 
1132  /// See also setLegalizeScalarToDifferentSizeStrategy.
1133  /// This function allows to set the SizeChangeStrategy for vector elements.
1135  const unsigned TypeIdx,
1137  const unsigned OpcodeIdx = Opcode - FirstOp;
1138  if (VectorElementSizeChangeStrategies[OpcodeIdx].size() <= TypeIdx)
1139  VectorElementSizeChangeStrategies[OpcodeIdx].resize(TypeIdx + 1);
1140  VectorElementSizeChangeStrategies[OpcodeIdx][TypeIdx] = S;
1141  }
1142 
1143  /// A SizeChangeStrategy for the common case where legalization for a
1144  /// particular operation consists of only supporting a specific set of type
1145  /// sizes. E.g.
1146  /// setAction ({G_DIV, 0, LLT::scalar(32)}, Legal);
1147  /// setAction ({G_DIV, 0, LLT::scalar(64)}, Legal);
1148  /// setLegalizeScalarToDifferentSizeStrategy(
1149  /// G_DIV, 0, unsupportedForDifferentSizes);
1150  /// will result in getAction({G_DIV, 0, T}) to return Legal for s32 and s64,
1151  /// and Unsupported for all other scalar types T.
1152  static SizeAndActionsVec
1154  using namespace LegalizeActions;
1155  return increaseToLargerTypesAndDecreaseToLargest(v, Unsupported,
1156  Unsupported);
1157  }
1158 
1159  /// A SizeChangeStrategy for the common case where legalization for a
1160  /// particular operation consists of widening the type to a large legal type,
1161  /// unless there is no such type and then instead it should be narrowed to the
1162  /// largest legal type.
1163  static SizeAndActionsVec
1165  using namespace LegalizeActions;
1166  assert(v.size() > 0 &&
1167  "At least one size that can be legalized towards is needed"
1168  " for this SizeChangeStrategy");
1169  return increaseToLargerTypesAndDecreaseToLargest(v, WidenScalar,
1170  NarrowScalar);
1171  }
1172 
1173  static SizeAndActionsVec
1175  using namespace LegalizeActions;
1176  return increaseToLargerTypesAndDecreaseToLargest(v, WidenScalar,
1177  Unsupported);
1178  }
1179 
1180  static SizeAndActionsVec
1182  using namespace LegalizeActions;
1183  return decreaseToSmallerTypesAndIncreaseToSmallest(v, NarrowScalar,
1184  Unsupported);
1185  }
1186 
1187  static SizeAndActionsVec
1189  using namespace LegalizeActions;
1190  assert(v.size() > 0 &&
1191  "At least one size that can be legalized towards is needed"
1192  " for this SizeChangeStrategy");
1193  return decreaseToSmallerTypesAndIncreaseToSmallest(v, NarrowScalar,
1194  WidenScalar);
1195  }
1196 
1197  /// A SizeChangeStrategy for the common case where legalization for a
1198  /// particular vector operation consists of having more elements in the
1199  /// vector, to a type that is legal. Unless there is no such type and then
1200  /// instead it should be legalized towards the widest vector that's still
1201  /// legal. E.g.
1202  /// setAction({G_ADD, LLT::vector(8, 8)}, Legal);
1203  /// setAction({G_ADD, LLT::vector(16, 8)}, Legal);
1204  /// setAction({G_ADD, LLT::vector(2, 32)}, Legal);
1205  /// setAction({G_ADD, LLT::vector(4, 32)}, Legal);
1206  /// setLegalizeVectorElementToDifferentSizeStrategy(
1207  /// G_ADD, 0, moreToWiderTypesAndLessToWidest);
1208  /// will result in the following getAction results:
1209  /// * getAction({G_ADD, LLT::vector(8,8)}) returns
1210  /// (Legal, vector(8,8)).
1211  /// * getAction({G_ADD, LLT::vector(9,8)}) returns
1212  /// (MoreElements, vector(16,8)).
1213  /// * getAction({G_ADD, LLT::vector(8,32)}) returns
1214  /// (FewerElements, vector(4,32)).
1215  static SizeAndActionsVec
1217  using namespace LegalizeActions;
1218  return increaseToLargerTypesAndDecreaseToLargest(v, MoreElements,
1219  FewerElements);
1220  }
1221 
1222  /// Helper function to implement many typical SizeChangeStrategy functions.
1223  static SizeAndActionsVec
1224  increaseToLargerTypesAndDecreaseToLargest(const SizeAndActionsVec &v,
1225  LegalizeAction IncreaseAction,
1226  LegalizeAction DecreaseAction);
1227  /// Helper function to implement many typical SizeChangeStrategy functions.
1228  static SizeAndActionsVec
1229  decreaseToSmallerTypesAndIncreaseToSmallest(const SizeAndActionsVec &v,
1230  LegalizeAction DecreaseAction,
1231  LegalizeAction IncreaseAction);
1232 
1233  /// Get the action definitions for the given opcode. Use this to run a
1234  /// LegalityQuery through the definitions.
1235  const LegalizeRuleSet &getActionDefinitions(unsigned Opcode) const;
1236 
1237  /// Get the action definition builder for the given opcode. Use this to define
1238  /// the action definitions.
1239  ///
1240  /// It is an error to request an opcode that has already been requested by the
1241  /// multiple-opcode variant.
1242  LegalizeRuleSet &getActionDefinitionsBuilder(unsigned Opcode);
1243 
1244  /// Get the action definition builder for the given set of opcodes. Use this
1245  /// to define the action definitions for multiple opcodes at once. The first
1246  /// opcode given will be considered the representative opcode and will hold
1247  /// the definitions whereas the other opcodes will be configured to refer to
1248  /// the representative opcode. This lowers memory requirements and very
1249  /// slightly improves performance.
1250  ///
1251  /// It would be very easy to introduce unexpected side-effects as a result of
1252  /// this aliasing if it were permitted to request different but intersecting
1253  /// sets of opcodes but that is difficult to keep track of. It is therefore an
1254  /// error to request the same opcode twice using this API, to request an
1255  /// opcode that already has definitions, or to use the single-opcode API on an
1256  /// opcode that has already been requested by this API.
1257  LegalizeRuleSet &
1258  getActionDefinitionsBuilder(std::initializer_list<unsigned> Opcodes);
1259  void aliasActionDefinitions(unsigned OpcodeTo, unsigned OpcodeFrom);
1260 
1261  /// Determine what action should be taken to legalize the described
1262  /// instruction. Requires computeTables to have been called.
1263  ///
1264  /// \returns a description of the next legalization step to perform.
1265  LegalizeActionStep getAction(const LegalityQuery &Query) const;
1266 
1267  /// Determine what action should be taken to legalize the given generic
1268  /// instruction.
1269  ///
1270  /// \returns a description of the next legalization step to perform.
1271  LegalizeActionStep getAction(const MachineInstr &MI,
1272  const MachineRegisterInfo &MRI) const;
1273 
1274  bool isLegal(const LegalityQuery &Query) const {
1275  return getAction(Query).Action == LegalizeAction::Legal;
1276  }
1277 
1278  bool isLegalOrCustom(const LegalityQuery &Query) const {
1279  auto Action = getAction(Query).Action;
1280  return Action == LegalizeAction::Legal || Action == LegalizeAction::Custom;
1281  }
1282 
1283  bool isLegal(const MachineInstr &MI, const MachineRegisterInfo &MRI) const;
1284  bool isLegalOrCustom(const MachineInstr &MI,
1285  const MachineRegisterInfo &MRI) const;
1286 
1287  /// Called for instructions with the Custom LegalizationAction.
1288  virtual bool legalizeCustom(LegalizerHelper &Helper,
1289  MachineInstr &MI) const {
1290  llvm_unreachable("must implement this if custom action is used");
1291  }
1292 
1293  /// \returns true if MI is either legal or has been legalized and false if not
1294  /// legal.
1295  /// Return true if MI is either legal or has been legalized and false
1296  /// if not legal.
1297  virtual bool legalizeIntrinsic(LegalizerHelper &Helper,
1298  MachineInstr &MI) const {
1299  return true;
1300  }
1301 
1302  /// Return the opcode (SEXT/ZEXT/ANYEXT) that should be performed while
1303  /// widening a constant of type SmallTy which targets can override.
1304  /// For eg, the DAG does (SmallTy.isByteSized() ? G_SEXT : G_ZEXT) which
1305  /// will be the default.
1306  virtual unsigned getExtOpcodeForWideningConstant(LLT SmallTy) const;
1307 
1308 private:
1309  /// Determine what action should be taken to legalize the given generic
1310  /// instruction opcode, type-index and type. Requires computeTables to have
1311  /// been called.
1312  ///
1313  /// \returns a pair consisting of the kind of legalization that should be
1314  /// performed and the destination type.
1315  std::pair<LegalizeAction, LLT>
1316  getAspectAction(const InstrAspect &Aspect) const;
1317 
1318  /// The SizeAndActionsVec is a representation mapping between all natural
1319  /// numbers and an Action. The natural number represents the bit size of
1320  /// the InstrAspect. For example, for a target with native support for 32-bit
1321  /// and 64-bit additions, you'd express that as:
1322  /// setScalarAction(G_ADD, 0,
1323  /// {{1, WidenScalar}, // bit sizes [ 1, 31[
1324  /// {32, Legal}, // bit sizes [32, 33[
1325  /// {33, WidenScalar}, // bit sizes [33, 64[
1326  /// {64, Legal}, // bit sizes [64, 65[
1327  /// {65, NarrowScalar} // bit sizes [65, +inf[
1328  /// });
1329  /// It may be that only 64-bit pointers are supported on your target:
1330  /// setPointerAction(G_PTR_ADD, 0, LLT:pointer(1),
1331  /// {{1, Unsupported}, // bit sizes [ 1, 63[
1332  /// {64, Legal}, // bit sizes [64, 65[
1333  /// {65, Unsupported}, // bit sizes [65, +inf[
1334  /// });
1335  void setScalarAction(const unsigned Opcode, const unsigned TypeIndex,
1336  const SizeAndActionsVec &SizeAndActions) {
1337  const unsigned OpcodeIdx = Opcode - FirstOp;
1338  SmallVector<SizeAndActionsVec, 1> &Actions = ScalarActions[OpcodeIdx];
1339  setActions(TypeIndex, Actions, SizeAndActions);
1340  }
1341  void setPointerAction(const unsigned Opcode, const unsigned TypeIndex,
1342  const unsigned AddressSpace,
1343  const SizeAndActionsVec &SizeAndActions) {
1344  const unsigned OpcodeIdx = Opcode - FirstOp;
1345  if (AddrSpace2PointerActions[OpcodeIdx].find(AddressSpace) ==
1346  AddrSpace2PointerActions[OpcodeIdx].end())
1347  AddrSpace2PointerActions[OpcodeIdx][AddressSpace] = {{}};
1348  SmallVector<SizeAndActionsVec, 1> &Actions =
1349  AddrSpace2PointerActions[OpcodeIdx].find(AddressSpace)->second;
1350  setActions(TypeIndex, Actions, SizeAndActions);
1351  }
1352 
1353  /// If an operation on a given vector type (say <M x iN>) isn't explicitly
1354  /// specified, we proceed in 2 stages. First we legalize the underlying scalar
1355  /// (so that there's at least one legal vector with that scalar), then we
1356  /// adjust the number of elements in the vector so that it is legal. The
1357  /// desired action in the first step is controlled by this function.
1358  void setScalarInVectorAction(const unsigned Opcode, const unsigned TypeIndex,
1359  const SizeAndActionsVec &SizeAndActions) {
1360  unsigned OpcodeIdx = Opcode - FirstOp;
1361  SmallVector<SizeAndActionsVec, 1> &Actions =
1362  ScalarInVectorActions[OpcodeIdx];
1363  setActions(TypeIndex, Actions, SizeAndActions);
1364  }
1365 
1366  /// See also setScalarInVectorAction.
1367  /// This function let's you specify the number of elements in a vector that
1368  /// are legal for a legal element size.
1369  void setVectorNumElementAction(const unsigned Opcode,
1370  const unsigned TypeIndex,
1371  const unsigned ElementSize,
1372  const SizeAndActionsVec &SizeAndActions) {
1373  const unsigned OpcodeIdx = Opcode - FirstOp;
1374  if (NumElements2Actions[OpcodeIdx].find(ElementSize) ==
1375  NumElements2Actions[OpcodeIdx].end())
1376  NumElements2Actions[OpcodeIdx][ElementSize] = {{}};
1377  SmallVector<SizeAndActionsVec, 1> &Actions =
1378  NumElements2Actions[OpcodeIdx].find(ElementSize)->second;
1379  setActions(TypeIndex, Actions, SizeAndActions);
1380  }
1381 
1382  /// A partial SizeAndActionsVec potentially doesn't cover all bit sizes,
1383  /// i.e. it's OK if it doesn't start from size 1.
1384  static void checkPartialSizeAndActionsVector(const SizeAndActionsVec& v) {
1385  using namespace LegalizeActions;
1386 #ifndef NDEBUG
1387  // The sizes should be in increasing order
1388  int prev_size = -1;
1389  for(auto SizeAndAction: v) {
1390  assert(SizeAndAction.first > prev_size);
1391  prev_size = SizeAndAction.first;
1392  }
1393  // - for every Widen action, there should be a larger bitsize that
1394  // can be legalized towards (e.g. Legal, Lower, Libcall or Custom
1395  // action).
1396  // - for every Narrow action, there should be a smaller bitsize that
1397  // can be legalized towards.
1398  int SmallestNarrowIdx = -1;
1399  int LargestWidenIdx = -1;
1400  int SmallestLegalizableToSameSizeIdx = -1;
1401  int LargestLegalizableToSameSizeIdx = -1;
1402  for(size_t i=0; i<v.size(); ++i) {
1403  switch (v[i].second) {
1404  case FewerElements:
1405  case NarrowScalar:
1406  if (SmallestNarrowIdx == -1)
1407  SmallestNarrowIdx = i;
1408  break;
1409  case WidenScalar:
1410  case MoreElements:
1411  LargestWidenIdx = i;
1412  break;
1413  case Unsupported:
1414  break;
1415  default:
1416  if (SmallestLegalizableToSameSizeIdx == -1)
1417  SmallestLegalizableToSameSizeIdx = i;
1418  LargestLegalizableToSameSizeIdx = i;
1419  }
1420  }
1421  if (SmallestNarrowIdx != -1) {
1422  assert(SmallestLegalizableToSameSizeIdx != -1);
1423  assert(SmallestNarrowIdx > SmallestLegalizableToSameSizeIdx);
1424  }
1425  if (LargestWidenIdx != -1)
1426  assert(LargestWidenIdx < LargestLegalizableToSameSizeIdx);
1427 #endif
1428  }
1429 
1430  /// A full SizeAndActionsVec must cover all bit sizes, i.e. must start with
1431  /// from size 1.
1432  static void checkFullSizeAndActionsVector(const SizeAndActionsVec& v) {
1433 #ifndef NDEBUG
1434  // Data structure invariant: The first bit size must be size 1.
1435  assert(v.size() >= 1);
1436  assert(v[0].first == 1);
1437  checkPartialSizeAndActionsVector(v);
1438 #endif
1439  }
1440 
1441  /// Sets actions for all bit sizes on a particular generic opcode, type
1442  /// index and scalar or pointer type.
1443  void setActions(unsigned TypeIndex,
1444  SmallVector<SizeAndActionsVec, 1> &Actions,
1445  const SizeAndActionsVec &SizeAndActions) {
1446  checkFullSizeAndActionsVector(SizeAndActions);
1447  if (Actions.size() <= TypeIndex)
1448  Actions.resize(TypeIndex + 1);
1449  Actions[TypeIndex] = SizeAndActions;
1450  }
1451 
1452  static SizeAndAction findAction(const SizeAndActionsVec &Vec,
1453  const uint32_t Size);
1454 
1455  /// Returns the next action needed to get the scalar or pointer type closer
1456  /// to being legal
1457  /// E.g. findLegalAction({G_REM, 13}) should return
1458  /// (WidenScalar, 32). After that, findLegalAction({G_REM, 32}) will
1459  /// probably be called, which should return (Lower, 32).
1460  /// This is assuming the setScalarAction on G_REM was something like:
1461  /// setScalarAction(G_REM, 0,
1462  /// {{1, WidenScalar}, // bit sizes [ 1, 31[
1463  /// {32, Lower}, // bit sizes [32, 33[
1464  /// {33, NarrowScalar} // bit sizes [65, +inf[
1465  /// });
1466  std::pair<LegalizeAction, LLT>
1467  findScalarLegalAction(const InstrAspect &Aspect) const;
1468 
1469  /// Returns the next action needed towards legalizing the vector type.
1470  std::pair<LegalizeAction, LLT>
1471  findVectorLegalAction(const InstrAspect &Aspect) const;
1472 
1473  static const int FirstOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_START;
1474  static const int LastOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_END;
1475 
1476  // Data structures used temporarily during construction of legality data:
1477  using TypeMap = DenseMap<LLT, LegalizeAction>;
1478  SmallVector<TypeMap, 1> SpecifiedActions[LastOp - FirstOp + 1];
1479  SmallVector<SizeChangeStrategy, 1>
1480  ScalarSizeChangeStrategies[LastOp - FirstOp + 1];
1481  SmallVector<SizeChangeStrategy, 1>
1482  VectorElementSizeChangeStrategies[LastOp - FirstOp + 1];
1483  bool TablesInitialized;
1484 
1485  // Data structures used by getAction:
1486  SmallVector<SizeAndActionsVec, 1> ScalarActions[LastOp - FirstOp + 1];
1487  SmallVector<SizeAndActionsVec, 1> ScalarInVectorActions[LastOp - FirstOp + 1];
1488  std::unordered_map<uint16_t, SmallVector<SizeAndActionsVec, 1>>
1489  AddrSpace2PointerActions[LastOp - FirstOp + 1];
1490  std::unordered_map<uint16_t, SmallVector<SizeAndActionsVec, 1>>
1491  NumElements2Actions[LastOp - FirstOp + 1];
1492 
1493  LegalizeRuleSet RulesForOpcode[LastOp - FirstOp + 1];
1494 };
1495 
1496 #ifndef NDEBUG
1497 /// Checks that MIR is fully legal, returns an illegal instruction if it's not,
1498 /// nullptr otherwise
1499 const MachineInstr *machineFunctionIsIllegal(const MachineFunction &MF);
1500 #endif
1501 
1502 } // end namespace llvm.
1503 
1504 #endif // LLVM_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::LegalizeRuleSet::maxScalarOrElt
LegalizeRuleSet & maxScalarOrElt(unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at most as wide as Ty.
Definition: LegalizerInfo.h:866
i
i
Definition: README.txt:29
llvm::LegalizeRuleSet::unsupported
LegalizeRuleSet & unsupported()
The instruction is unsupported.
Definition: LegalizerInfo.h:746
llvm::SmallBitVector::set
SmallBitVector & set()
Definition: SmallBitVector.h:363
llvm::InstrAspect
Legalization is decided based on an instruction's opcode, which type slot we're considering,...
Definition: LegalizerInfo.h:106
llvm::LegalizeRuleSet::widenScalarToNextPow2
LegalizeRuleSet & widenScalarToNextPow2(unsigned TypeIdx, unsigned MinSize=0)
Widen the scalar to the next power of two that is at least MinSize.
Definition: LegalizerInfo.h:799
llvm::LegalizeRuleSet::bitcastIf
LegalizeRuleSet & bitcastIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
The specified type index is coerced if predicate is true.
Definition: LegalizerInfo.h:595
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:100
llvm::LegalizeRule::match
bool match(const LegalityQuery &Query) const
Test whether the LegalityQuery matches.
Definition: LegalizerInfo.h:349
llvm
Definition: AllocatorList.h:23
llvm::LegalityPredicates::scalarOrEltWiderThan
LegalityPredicate scalarOrEltWiderThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar or a vector with an element type that's wider than the ...
Definition: LegalityPredicates.cpp:141
llvm::MCOI::OPERAND_FIRST_GENERIC_IMM
@ OPERAND_FIRST_GENERIC_IMM
Definition: MCInstrDesc.h:72
Optional.h
llvm::LLT::getScalarSizeInBits
unsigned getScalarSizeInBits() const
Definition: LowLevelTypeImpl.h:163
llvm::LegalizerInfo::setLegalizeScalarToDifferentSizeStrategy
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: LegalizerInfo.h:1123
llvm::LegalizeRuleSet::unsupportedIfMemSizeNotPow2
LegalizeRuleSet & unsupportedIfMemSizeNotPow2()
Definition: LegalizerInfo.h:758
llvm::LegalizeActions::MoreElements
@ MoreElements
The (vector) operation should be implemented by widening the input vector and ignoring the lanes adde...
Definition: LegalizerInfo.h:69
llvm::LegalizeRuleSet::maxScalarSameAs
LegalizeRuleSet & maxScalarSameAs(unsigned TypeIdx, unsigned NarrowTypeIdx)
Narrow the scalar to match the size of another.
Definition: LegalizerInfo.h:926
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::LegalizeActionStep::Action
LegalizeAction Action
The action to take or the final answer.
Definition: LegalizerInfo.h:152
llvm::LegalizeRuleSet::customFor
LegalizeRuleSet & customFor(std::initializer_list< std::pair< LLT, LLT >> Types)
The instruction is custom when type indexes 0 and 1 is any type pair in the given list.
Definition: LegalizerInfo.h:779
llvm::LegalizeRuleSet::minScalarEltSameAsIf
LegalizeRuleSet & minScalarEltSameAsIf(LegalityPredicate Predicate, unsigned TypeIdx, unsigned LargeTypeIdx)
Conditionally widen the scalar or elt to match the size of another.
Definition: LegalizerInfo.h:944
llvm::LegalizeRuleSet::maxScalarIf
LegalizeRuleSet & maxScalarIf(LegalityPredicate Predicate, unsigned TypeIdx, const LLT Ty)
Conditionally limit the maximum size of the scalar.
Definition: LegalizerInfo.h:886
llvm::LegalizeActionStep
The result of a query.
Definition: LegalizerInfo.h:150
llvm::LegalizerInfo::unsupportedForDifferentSizes
static SizeAndActionsVec unsupportedForDifferentSizes(const SizeAndActionsVec &v)
A SizeChangeStrategy for the common case where legalization for a particular operation consists of on...
Definition: LegalizerInfo.h:1153
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::LegalizeRuleSet::customFor
LegalizeRuleSet & customFor(std::initializer_list< LLT > Types)
Definition: LegalizerInfo.h:773
llvm::LegalizeRuleSet::libcall
LegalizeRuleSet & libcall()
The instruction is emitted as a library call.
Definition: LegalizerInfo.h:668
llvm::LegalizeRule::determineMutation
std::pair< unsigned, LLT > determineMutation(const LegalityQuery &Query) const
Determine the change to make.
Definition: LegalizerInfo.h:356
llvm::LegalizeRuleSet::clampNumElements
LegalizeRuleSet & clampNumElements(unsigned TypeIdx, const LLT MinTy, const LLT MaxTy)
Limit the number of elements for the given vectors to at least MinTy's number of elements and at most...
Definition: LegalizerInfo.h:1028
llvm::LegalizeActions::NarrowScalar
@ NarrowScalar
The operation should be synthesized from multiple instructions acting on a narrower scalar base-type.
Definition: LegalizerInfo.h:53
llvm::LegalizeRuleSet::lowerFor
LegalizeRuleSet & lowerFor(std::initializer_list< LLT > Types, LegalizeMutation Mutation)
The instruction is lowered when type index 0 is any type in the given list.
Definition: LegalizerInfo.h:635
llvm::LegalityPredicates::typeIsNot
LegalityPredicate typeIsNot(unsigned TypeIdx, LLT Type)
True iff the given type index is not the specified type.
Definition: LegalizerInfo.h:227
llvm::LegalizeRuleSet::minScalarOrEltIf
LegalizeRuleSet & minScalarOrEltIf(LegalityPredicate Predicate, unsigned TypeIdx, const LLT Ty)
Ensure the scalar or element is at least as wide as Ty.
Definition: LegalizerInfo.h:846
llvm::DisableGISelLegalityCheck
cl::opt< bool > DisableGISelLegalityCheck
llvm::LegalizerInfo::SizeChangeStrategy
std::function< SizeAndActionsVec(const SizeAndActionsVec &v)> SizeChangeStrategy
Definition: LegalizerInfo.h:1092
llvm::LegalizerInfo::narrowToSmallerAndWidenToSmallest
static SizeAndActionsVec narrowToSmallerAndWidenToSmallest(const SizeAndActionsVec &v)
Definition: LegalizerInfo.h:1188
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
DenseMap.h
llvm::LegalityPredicates::largerThan
LegalityPredicate largerThan(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the first type index has a larger total bit size than second type index.
Definition: LegalityPredicates.cpp:125
llvm::LegalityQuery::MemDesc
Definition: LegalizerInfo.h:128
llvm::LegalityPredicates::scalarNarrowerThan
LegalityPredicate scalarNarrowerThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that's narrower than the given size.
Definition: LegalityPredicates.cpp:101
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
llvm::LegalityPredicates::elementTypeIs
LegalityPredicate elementTypeIs(unsigned TypeIdx, LLT EltTy)
True if the type index is a vector with element type EltTy.
Definition: LegalityPredicates.cpp:93
llvm::LegalizeRuleSet::maxScalar
LegalizeRuleSet & maxScalar(unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at most as wide as Ty.
Definition: LegalizerInfo.h:875
llvm::LegalizeActions::WidenScalar
@ WidenScalar
The operation should be implemented in terms of a wider scalar base-type.
Definition: LegalizerInfo.h:58
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::LegalityPredicates::TypePairAndMemDesc::operator==
bool operator==(const TypePairAndMemDesc &Other) const
Definition: LegalizerInfo.h:179
llvm::LLT::scalarOrVector
static LLT scalarOrVector(uint16_t NumElements, LLT ScalarTy)
Definition: LowLevelTypeImpl.h:74
llvm::LegalizeActions::UseLegacyRules
@ UseLegacyRules
Fall back onto the old rules.
Definition: LegalizerInfo.h:96
llvm::LegalizeRuleSet::widenScalarIf
LegalizeRuleSet & widenScalarIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
Widen the scalar to the one selected by the mutation if the predicate is true.
Definition: LegalizerInfo.h:702
llvm::LegalityQuery::LegalityQuery
constexpr LegalityQuery(unsigned Opcode, const ArrayRef< LLT > Types, const ArrayRef< MemDesc > MMODescrs)
Definition: LegalizerInfo.h:138
llvm::InstrAspect::operator==
bool operator==(const InstrAspect &RHS) const
Definition: LegalizerInfo.h:115
llvm::LegalizeRuleSet::scalarizeIf
LegalizeRuleSet & scalarizeIf(LegalityPredicate Predicate, unsigned TypeIdx)
Definition: LegalizerInfo.h:829
STLExtras.h
llvm::LegalizeRuleSet::narrowScalar
LegalizeRuleSet & narrowScalar(unsigned TypeIdx, LegalizeMutation Mutation)
Definition: LegalizerInfo.h:817
llvm::LegalizeRuleSet::minScalarOrElt
LegalizeRuleSet & minScalarOrElt(unsigned TypeIdx, const LLT Ty)
Ensure the scalar or element is at least as wide as Ty.
Definition: LegalizerInfo.h:837
llvm::LegalizeRuleSet::scalarize
LegalizeRuleSet & scalarize(unsigned TypeIdx)
Definition: LegalizerInfo.h:823
llvm::LegalizeRuleSet::lower
LegalizeRuleSet & lower()
The instruction is lowered.
Definition: LegalizerInfo.h:604
llvm::LegalizerHelper
Definition: LegalizerHelper.h:37
llvm::LegalizeMutations::changeTo
LegalizeMutation changeTo(unsigned TypeIdx, LLT Ty)
Select this specific type for the given type index.
Definition: LegalizeMutations.cpp:17
llvm::LegalizerInfo::SizeAndAction
std::pair< uint16_t, LegalizeAction > SizeAndAction
Definition: LegalizerInfo.h:1089
llvm::LegalityPredicates::isPointer
LegalityPredicate isPointer(unsigned TypeIdx)
True iff the specified type index is a pointer (with any address space).
Definition: LegalityPredicates.cpp:79
llvm::MCOI::OPERAND_LAST_GENERIC_IMM
@ OPERAND_LAST_GENERIC_IMM
Definition: MCInstrDesc.h:74
llvm::LegalityPredicates::any
Predicate any(Predicate P0, Predicate P1)
True iff P0 or P1 are true.
Definition: LegalizerInfo.h:209
llvm::LegalityPredicates::atomicOrderingAtLeastOrStrongerThan
LegalityPredicate atomicOrderingAtLeastOrStrongerThan(unsigned MMOIdx, AtomicOrdering Ordering)
True iff the specified MMO index has at an atomic ordering of at Ordering or stronger.
Definition: LegalityPredicates.cpp:190
llvm::MCOI::OPERAND_LAST_GENERIC
@ OPERAND_LAST_GENERIC
Definition: MCInstrDesc.h:70
llvm::LegalizeRuleSet::libcallIf
LegalizeRuleSet & libcallIf(LegalityPredicate Predicate)
Like legalIf, but for the Libcall action.
Definition: LegalizerInfo.h:677
llvm::InstrAspect::InstrAspect
InstrAspect(unsigned Opcode, LLT Type)
Definition: LegalizerInfo.h:111
llvm::LegalizeRuleSet::legalIf
LegalizeRuleSet & legalIf(LegalityPredicate Predicate)
The instruction is legal if predicate is true.
Definition: LegalizerInfo.h:531
llvm::LegalizeRuleSet::legalFor
LegalizeRuleSet & legalFor(std::initializer_list< std::pair< LLT, LLT >> Types)
The instruction is legal when type indexes 0 and 1 is any type pair in the given list.
Definition: LegalizerInfo.h:543
llvm::LegalizeRuleSet::minScalar
LegalizeRuleSet & minScalar(unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at least as wide as Ty.
Definition: LegalizerInfo.h:857
always
bar al al movzbl eax ret Missed when stored in a memory are stored as single byte objects the value of which is always(false) or 1(true). We are not using this fact
Definition: README.txt:1412
llvm::LegalizeRuleSet::apply
LegalizeActionStep apply(const LegalityQuery &Query) const
Apply the ruleset to the given LegalityQuery.
Definition: LegalizerInfo.cpp:190
llvm::SmallBitVector
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
Definition: SmallBitVector.h:34
CommandLine.h
llvm::LegalizerInfo::widenToLargerTypesAndNarrowToLargest
static SizeAndActionsVec widenToLargerTypesAndNarrowToLargest(const SizeAndActionsVec &v)
A SizeChangeStrategy for the common case where legalization for a particular operation consists of wi...
Definition: LegalizerInfo.h:1164
llvm::LegalizeRuleSet::LegalizeRuleSet
LegalizeRuleSet()
Definition: LegalizerInfo.h:518
llvm::LegalizeRuleSet::widenScalarOrEltToNextPow2
LegalizeRuleSet & widenScalarOrEltToNextPow2(unsigned TypeIdx, unsigned MinSize=0)
Widen the scalar or vector element type to the next power of two that is at least MinSize.
Definition: LegalizerInfo.h:809
llvm::LegalizeRuleSet::clampMinNumElements
LegalizeRuleSet & clampMinNumElements(unsigned TypeIdx, const LLT EltTy, unsigned MinElements)
Limit the number of elements in EltTy vectors to at least MinElements.
Definition: LegalizerInfo.h:987
llvm::LegalizeRuleSet::customIf
LegalizeRuleSet & customIf(LegalityPredicate Predicate)
Definition: LegalizerInfo.h:767
llvm::LegalityPredicates::typeIs
LegalityPredicate typeIs(unsigned TypeIdx, LLT TypesInit)
True iff the given type index is the specified type.
Definition: LegalityPredicates.cpp:28
llvm::LegalizerInfo::widenToLargerTypesUnsupportedOtherwise
static SizeAndActionsVec widenToLargerTypesUnsupportedOtherwise(const SizeAndActionsVec &v)
Definition: LegalizerInfo.h:1174
llvm::MCOI::OPERAND_FIRST_GENERIC
@ OPERAND_FIRST_GENERIC
Definition: MCInstrDesc.h:63
llvm::LegalizeRuleSet::lowerIf
LegalizeRuleSet & lowerIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
The instruction is lowered if predicate is true.
Definition: LegalizerInfo.h:621
llvm::LegalizeRule
A single rule in a legalizer info ruleset.
Definition: LegalizerInfo.h:338
llvm::LegalizeRuleSet::aliasTo
void aliasTo(unsigned Opcode)
Definition: LegalizerInfo.h:522
llvm::LegalizeActions::NotFound
@ NotFound
Sentinel value for when no action was found in the specified table.
Definition: LegalizerInfo.h:92
llvm::LegalityPredicates::smallerThan
LegalityPredicate smallerThan(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the first type index has a smaller total bit size than second type index.
Definition: LegalityPredicates.cpp:117
llvm::LegalityPredicates::TypePairAndMemDesc::MemSize
uint64_t MemSize
Definition: LegalizerInfo.h:176
llvm::LegalizeRuleSet::moreElementsIf
LegalizeRuleSet & moreElementsIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
Add more elements to reach the type selected by the mutation if the predicate is true.
Definition: LegalizerInfo.h:728
llvm::LLT::getSizeInBits
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
Definition: LowLevelTypeImpl.h:109
llvm::LegalityQuery::MemDesc::AlignInBits
uint64_t AlignInBits
Definition: LegalizerInfo.h:130
llvm::LegalityPredicates::scalarOrEltSizeNotPow2
LegalityPredicate scalarOrEltSizeNotPow2(unsigned TypeIdx)
True iff the specified type index is a scalar or vector whose element size is not a power of 2.
Definition: LegalityPredicates.cpp:149
llvm::LegalizeRuleSet::legalForCartesianProduct
LegalizeRuleSet & legalForCartesianProduct(std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1, std::initializer_list< LLT > Types2)
The instruction is legal when type indexes 0, 1, and 2 are both their respective lists.
Definition: LegalizerInfo.h:581
llvm::LegalizeRuleSet::libcallForCartesianProduct
LegalizeRuleSet & libcallForCartesianProduct(std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1)
Definition: LegalizerInfo.h:695
llvm::LegalizeRuleSet::lowerIfMemSizeNotPow2
LegalizeRuleSet & lowerIfMemSizeNotPow2()
Definition: LegalizerInfo.h:762
llvm::LegalizeRuleSet::fewerElementsIf
LegalizeRuleSet & fewerElementsIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
Remove elements to reach the type selected by the mutation if the predicate is true.
Definition: LegalizerInfo.h:737
false
Definition: StackSlotColoring.cpp:142
TargetOpcodes.h
llvm::LegalizeRuleSet::legalForTypeWithAnyImm
LegalizeRuleSet & legalForTypeWithAnyImm(std::initializer_list< std::pair< LLT, LLT >> Types)
Definition: LegalizerInfo.h:553
llvm::LegalizeRuleSet
Definition: LegalizerInfo.h:363
llvm::machineFunctionIsIllegal
const MachineInstr * machineFunctionIsIllegal(const MachineFunction &MF)
Checks that MIR is fully legal, returns an illegal instruction if it's not, nullptr otherwise.
Definition: LegalizerInfo.cpp:739
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
llvm::LegalizeActions::Libcall
@ Libcall
The operation should be implemented as a call to some kind of runtime support library.
Definition: LegalizerInfo.h:81
llvm::LLT::vector
static LLT vector(uint16_t NumElements, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
Definition: LowLevelTypeImpl.h:58
llvm::LegalizeRuleSet::clampMaxNumElements
LegalizeRuleSet & clampMaxNumElements(unsigned TypeIdx, const LLT EltTy, unsigned MaxElements)
Limit the number of elements in EltTy vectors to at most MaxElements.
Definition: LegalizerInfo.h:1005
llvm::LegalizeActions::Custom
@ Custom
The target wants to do something special with this combination of operand and type.
Definition: LegalizerInfo.h:85
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::LegalizeRuleSet::maxScalarEltSameAsIf
LegalizeRuleSet & maxScalarEltSameAsIf(LegalityPredicate Predicate, unsigned TypeIdx, unsigned SmallTypeIdx)
Conditionally narrow the scalar or elt to match the size of another.
Definition: LegalizerInfo.h:960
llvm::AddressSpace
AddressSpace
Definition: NVPTXBaseInfo.h:21
llvm::LegalizeActions::Legal
@ Legal
The operation is expected to be selectable directly by the target, and no transformation is necessary...
Definition: LegalizerInfo.h:48
llvm::LegalizeRuleSet::libcallForCartesianProduct
LegalizeRuleSet & libcallForCartesianProduct(std::initializer_list< LLT > Types)
Definition: LegalizerInfo.h:691
LowLevelTypeImpl.h
llvm::LegalityQuery::MemDesc::SizeInBits
uint64_t SizeInBits
Definition: LegalizerInfo.h:129
llvm::LegalizeRule::LegalizeRule
LegalizeRule(LegalityPredicate Predicate, LegalizeAction Action, LegalizeMutation Mutation=nullptr)
Definition: LegalizerInfo.h:344
llvm::LegalizerInfo::moreToWiderTypesAndLessToWidest
static SizeAndActionsVec moreToWiderTypesAndLessToWidest(const SizeAndActionsVec &v)
A SizeChangeStrategy for the common case where legalization for a particular vector operation consist...
Definition: LegalizerInfo.h:1216
llvm::AtomicOrdering
AtomicOrdering
Atomic ordering for LLVM's memory model.
Definition: AtomicOrdering.h:56
llvm::LegalizeRuleSet::getAlias
unsigned getAlias() const
Definition: LegalizerInfo.h:528
llvm::PPC::Predicate
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Definition: PPCPredicates.h:26
llvm::LegalizerInfo::legalizeIntrinsic
virtual bool legalizeIntrinsic(LegalizerHelper &Helper, MachineInstr &MI) const
Definition: LegalizerInfo.h:1297
llvm::LegalityQuery::MemDesc::Ordering
AtomicOrdering Ordering
Definition: LegalizerInfo.h:131
llvm::LegalizeMutations::scalarize
LegalizeMutation scalarize(unsigned TypeIdx)
Break up the vector type for the given type index into the element type.
Definition: LegalizeMutations.cpp:77
llvm::LegalizeRuleSet::lowerIf
LegalizeRuleSet & lowerIf(LegalityPredicate Predicate)
The instruction is lowered if predicate is true.
Definition: LegalizerInfo.h:613
llvm::LegalizeMutations::changeElementTo
LegalizeMutation changeElementTo(unsigned TypeIdx, LLT Ty)
Keep the same scalar or element type as the given type.
Definition: LegalizeMutations.cpp:38
llvm::InstrAspect::Opcode
unsigned Opcode
Definition: LegalizerInfo.h:107
llvm::LegalizeRuleSet::legalFor
LegalizeRuleSet & legalFor(std::initializer_list< LLT > Types)
The instruction is legal when type index 0 is any type in the given list.
Definition: LegalizerInfo.h:538
llvm::LegalizerInfo::setAction
void setAction(const InstrAspect &Aspect, LegalizeAction Action)
More friendly way to set an action for common types that have an LLT representation.
Definition: LegalizerInfo.h:1098
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::LegalityPredicates::TypePairAndMemDesc::isCompatible
bool isCompatible(const TypePairAndMemDesc &Other) const
Definition: LegalizerInfo.h:187
llvm::find
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1502
llvm::LegalityPredicates::all
Predicate all(Predicate P0, Predicate P1)
True iff P0 and P1 are true.
Definition: LegalizerInfo.h:196
llvm::LegalizeMutations::changeElementSizeTo
LegalizeMutation changeElementSizeTo(unsigned TypeIdx, unsigned FromTypeIdx)
Change the scalar size or element size to have the same scalar size as type index FromIndex.
Definition: LegalizeMutations.cpp:46
llvm::LegalizeActions::Bitcast
@ Bitcast
Perform the operation on a different, but equivalently sized type.
Definition: LegalizerInfo.h:72
llvm::LegalizeRuleSet::setIsAliasedByAnother
void setIsAliasedByAnother()
Definition: LegalizerInfo.h:521
llvm::LegalizeMutations::changeTo
LegalizeMutation changeTo(unsigned TypeIdx, unsigned FromTypeIdx)
Keep the same type as the given type index.
Definition: LegalizeMutations.cpp:22
llvm::LLT::isVector
bool isVector() const
Definition: LowLevelTypeImpl.h:96
llvm::LegalizeRuleSet::clampScalar
LegalizeRuleSet & clampScalar(unsigned TypeIdx, const LLT MinTy, const LLT MaxTy)
Limit the range of scalar sizes to MinTy and MaxTy.
Definition: LegalizerInfo.h:902
llvm::LLT::getNumElements
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
Definition: LowLevelTypeImpl.h:100
llvm::LegalizeRuleSet::lowerFor
LegalizeRuleSet & lowerFor(std::initializer_list< LLT > Types)
The instruction is lowered when type index 0 is any type in the given list.
Definition: LegalizerInfo.h:630
llvm::LegalizeRuleSet::verifyImmIdxsCoverage
bool verifyImmIdxsCoverage(unsigned NumImmIdxs) const
Check if there is no imm index which is obviously not handled by the LegalizeRuleSet in any way at al...
Definition: LegalizerInfo.cpp:237
llvm::LegalityPredicates::all
Predicate all(Predicate P0, Predicate P1, Args... args)
True iff all given predicates are true.
Definition: LegalizerInfo.h:203
llvm::LegalizeRuleSet::legalForCartesianProduct
LegalizeRuleSet & legalForCartesianProduct(std::initializer_list< LLT > Types)
The instruction is legal when type indexes 0 and 1 are both in the given list.
Definition: LegalizerInfo.h:570
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::LegalityPredicate
std::function< bool(const LegalityQuery &)> LegalityPredicate
Definition: LegalizerInfo.h:168
llvm::LegalityPredicates::typeInSet
LegalityPredicate typeInSet(unsigned TypeIdx, std::initializer_list< LLT > TypesInit)
True iff the given type index is one of the specified types.
Definition: LegalityPredicates.cpp:34
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::LegalizeActions::LegalizeAction
LegalizeAction
Definition: LegalizerInfo.h:45
llvm::LegalizerInfo::SizeAndActionsVec
std::vector< SizeAndAction > SizeAndActionsVec
Definition: LegalizerInfo.h:1090
llvm::LLT::isScalar
bool isScalar() const
Definition: LowLevelTypeImpl.h:92
llvm::LegalityPredicates::TypePairAndMemDesc::Align
uint64_t Align
Definition: LegalizerInfo.h:177
llvm::LegalizeRuleSet::lowerFor
LegalizeRuleSet & lowerFor(std::initializer_list< std::pair< LLT, LLT >> Types)
The instruction is lowered when type indexes 0 and 1 is any type pair in the given list.
Definition: LegalizerInfo.h:641
llvm::LegalityQuery::Opcode
unsigned Opcode
Definition: LegalizerInfo.h:125
llvm::size
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.
Definition: STLExtras.h:1463
llvm::LegalizeRuleSet::narrowScalarFor
LegalizeRuleSet & narrowScalarFor(std::initializer_list< std::pair< LLT, LLT >> Types, LegalizeMutation Mutation)
Narrow the scalar, specified in mutation, when type indexes 0 and 1 is any type pair in the given lis...
Definition: LegalizerInfo.h:721
llvm::LegalityQuery
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
Definition: LegalizerInfo.h:124
llvm::InstrAspect::InstrAspect
InstrAspect(unsigned Opcode, unsigned Idx, LLT Type)
Definition: LegalizerInfo.h:112
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::LegalizeRuleSet::legalForTypeWithAnyImm
LegalizeRuleSet & legalForTypeWithAnyImm(std::initializer_list< LLT > Types)
The instruction is legal when type index 0 is any type in the given list and imm index 0 is anything.
Definition: LegalizerInfo.h:548
None.h
llvm::LegalizeRuleSet::customForCartesianProduct
LegalizeRuleSet & customForCartesianProduct(std::initializer_list< LLT > Types)
Definition: LegalizerInfo.h:783
llvm::LegalizerInfo::needsLegalizingToDifferentSize
static bool needsLegalizingToDifferentSize(const LegalizeAction Action)
Definition: LegalizerInfo.h:1075
llvm::LegalizeRuleSet::clampScalarOrElt
LegalizeRuleSet & clampScalarOrElt(unsigned TypeIdx, const LLT MinTy, const LLT MaxTy)
Limit the range of scalar sizes to MinTy and MaxTy.
Definition: LegalizerInfo.h:909
llvm::LegalizeMutations::changeElementTo
LegalizeMutation changeElementTo(unsigned TypeIdx, unsigned FromTypeIdx)
Keep the same scalar or element type as the given type index.
Definition: LegalizeMutations.cpp:29
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
uint32_t
verify
ppc ctr loops verify
Definition: PPCCTRLoops.cpp:76
llvm::LegalityPredicates::typePairInSet
LegalityPredicate typePairInSet(unsigned TypeIdx0, unsigned TypeIdx1, std::initializer_list< std::pair< LLT, LLT >> TypesInit)
True iff the given types for the given pair of type indexes is one of the specified type pairs.
Definition: LegalityPredicates.cpp:42
llvm::LegalizeRuleSet::libcallFor
LegalizeRuleSet & libcallFor(std::initializer_list< std::pair< LLT, LLT >> Types)
Definition: LegalizerInfo.h:687
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
Mutation
PowerPC VSX FMA Mutation
Definition: PPCVSXFMAMutate.cpp:391
llvm::LegalityPredicates::sizeNotPow2
LegalityPredicate sizeNotPow2(unsigned TypeIdx)
True iff the specified type index is a scalar whose size is not a power of.
Definition: LegalityPredicates.cpp:156
llvm::LegalizeMutations::widenScalarOrEltToNextPow2
LegalizeMutation widenScalarOrEltToNextPow2(unsigned TypeIdx, unsigned Min=0)
Widen the scalar type or vector element type for the given type index to the next power of 2.
Definition: LegalizeMutations.cpp:56
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::LegalityPredicates::isScalar
LegalityPredicate isScalar(unsigned TypeIdx)
True iff the specified type index is a scalar.
Definition: LegalityPredicates.cpp:67
llvm::LegalizeActionStep::NewType
LLT NewType
If describing an action, the new type for TypeIdx. Otherwise LLT{}.
Definition: LegalizerInfo.h:156
llvm::LegalizeActionStep::LegalizeActionStep
LegalizeActionStep(LegalizeAction Action, unsigned TypeIdx, const LLT NewType)
Definition: LegalizerInfo.h:158
llvm::LegalityPredicates::scalarOrEltNarrowerThan
LegalityPredicate scalarOrEltNarrowerThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar or vector with an element type that's narrower than the...
Definition: LegalityPredicates.cpp:133
llvm::LegalizeRuleSet::narrowScalarIf
LegalizeRuleSet & narrowScalarIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
Narrow the scalar to the one selected by the mutation if the predicate is true.
Definition: LegalizerInfo.h:711
llvm::LegalizeRuleSet::lowerFor
LegalizeRuleSet & lowerFor(std::initializer_list< std::pair< LLT, LLT >> Types, LegalizeMutation Mutation)
The instruction is lowered when type indexes 0 and 1 is any type pair in the given list.
Definition: LegalizerInfo.h:646
llvm::LegalityPredicates::TypePairAndMemDesc::Type0
LLT Type0
Definition: LegalizerInfo.h:174
llvm::LegalityPredicates::sizeIs
LegalityPredicate sizeIs(unsigned TypeIdx, unsigned Size)
True if the total bitwidth of the specified type index is Size bits.
Definition: LegalityPredicates.cpp:163
llvm::LegalizeRuleSet::isAliasedByAnother
bool isAliasedByAnother()
Definition: LegalizerInfo.h:520
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:25
llvm::LegalizeRuleSet::alwaysLegal
LegalizeRuleSet & alwaysLegal()
Definition: LegalizerInfo.h:588
llvm::LegalizeRule::getAction
LegalizeAction getAction() const
Definition: LegalizerInfo.h:353
llvm::LegalityPredicates::memSizeInBytesNotPow2
LegalityPredicate memSizeInBytesNotPow2(unsigned MMOIdx)
True iff the specified MMO index has a size that is not a power of 2.
Definition: LegalityPredicates.cpp:177
llvm::LegalizeRuleSet::verifyTypeIdxsCoverage
bool verifyTypeIdxsCoverage(unsigned NumTypeIdxs) const
Check if there is no type index which is obviously not handled by the LegalizeRuleSet in any way at a...
Definition: LegalizerInfo.cpp:214
llvm::LegalityPredicates::scalarWiderThan
LegalityPredicate scalarWiderThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that's wider than the given size.
Definition: LegalityPredicates.cpp:109
llvm::LegalityQuery::MMODescrs
ArrayRef< MemDesc > MMODescrs
Operations which require memory can use this to place requirements on the memory type for each MMO.
Definition: LegalizerInfo.h:136
llvm::LegalizeRuleSet::unsupportedIf
LegalizeRuleSet & unsupportedIf(LegalityPredicate Predicate)
Definition: LegalizerInfo.h:750
llvm::LegalityPredicates::TypePairAndMemDesc
Definition: LegalizerInfo.h:173
llvm::LegalizeActions::FewerElements
@ FewerElements
The (vector) operation should be implemented by splitting it into sub-vectors where the operation is ...
Definition: LegalizerInfo.h:63
llvm::LegalizeRuleSet::legalForCartesianProduct
LegalizeRuleSet & legalForCartesianProduct(std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1)
The instruction is legal when type indexes 0 and 1 are both their respective lists.
Definition: LegalizerInfo.h:575
llvm::LegalizeRuleSet::minScalarSameAs
LegalizeRuleSet & minScalarSameAs(unsigned TypeIdx, unsigned LargeTypeIdx)
Widen the scalar to match the size of another.
Definition: LegalizerInfo.h:915
llvm::LegalizerInfo::narrowToSmallerAndUnsupportedIfTooSmall
static SizeAndActionsVec narrowToSmallerAndUnsupportedIfTooSmall(const SizeAndActionsVec &v)
Definition: LegalizerInfo.h:1181
llvm::LegalizeRuleSet::lowerForCartesianProduct
LegalizeRuleSet & lowerForCartesianProduct(std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1)
The instruction is lowered when type indexes 0 and 1 are both in their respective lists.
Definition: LegalizerInfo.h:652
Predicate
llvm::LegalityQuery::print
raw_ostream & print(raw_ostream &OS) const
Definition: LegalizerInfo.cpp:87
llvm::LegalityPredicates::numElementsNotPow2
LegalityPredicate numElementsNotPow2(unsigned TypeIdx)
True iff the specified type index is a vector whose element count is not a power of 2.
Definition: LegalityPredicates.cpp:183
llvm::LegalityPredicates::isVector
LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
Definition: LegalityPredicates.cpp:73
llvm::LegalizeActionStep::operator==
bool operator==(const LegalizeActionStep &RHS) const
Definition: LegalizerInfo.h:162
llvm::LegalizeActionStep::TypeIdx
unsigned TypeIdx
If describing an action, the type index to change. Otherwise zero.
Definition: LegalizerInfo.h:154
llvm::LegalityPredicates::typePairAndMemDescInSet
LegalityPredicate typePairAndMemDescInSet(unsigned TypeIdx0, unsigned TypeIdx1, unsigned MMOIdx, std::initializer_list< TypePairAndMemDesc > TypesAndMemDescInit)
True iff the given types for the given pair of type indexes is one of the specified type pairs.
Definition: LegalityPredicates.cpp:52
SmallVector.h
llvm::InstrAspect::Type
LLT Type
Definition: LegalizerInfo.h:109
llvm::LegalityQuery::Types
ArrayRef< LLT > Types
Definition: LegalizerInfo.h:126
llvm::LegalizeRuleSet::fallback
LegalizeRuleSet & fallback()
Fallback on the previous implementation.
Definition: LegalizerInfo.h:1040
llvm::LegalizeRuleSet::moreElementsToNextPow2
LegalizeRuleSet & moreElementsToNextPow2(unsigned TypeIdx)
Add more elements to the vector to reach the next power of two.
Definition: LegalizerInfo.h:979
llvm::LegalizerInfo::isLegalOrCustom
bool isLegalOrCustom(const LegalityQuery &Query) const
Definition: LegalizerInfo.h:1278
SmallBitVector.h
llvm::LegalizeRuleSet::custom
LegalizeRuleSet & custom()
Unconditionally custom lower.
Definition: LegalizerInfo.h:793
llvm::LegalizeActions::Unsupported
@ Unsupported
This operation is completely unsupported on the target.
Definition: LegalizerInfo.h:89
llvm::LegalizeRuleSet::unsupportedFor
LegalizeRuleSet & unsupportedFor(std::initializer_list< LLT > Types)
Definition: LegalizerInfo.h:754
llvm::LegalizeMutation
std::function< std::pair< unsigned, LLT >(const LegalityQuery &)> LegalizeMutation
Definition: LegalizerInfo.h:170
llvm::LegalizeMutations::moreElementsToNextPow2
LegalizeMutation moreElementsToNextPow2(unsigned TypeIdx, unsigned Min=0)
Add more elements to the type for the given type index to the next power of.
Definition: LegalizeMutations.cpp:66
llvm::LegalizerInfo
Definition: LegalizerInfo.h:1058
llvm::LegalizeRuleSet::lowerForCartesianProduct
LegalizeRuleSet & lowerForCartesianProduct(std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1, std::initializer_list< LLT > Types2)
The instruction is lowered when when type indexes 0, 1, and 2 are all in their respective lists.
Definition: LegalizerInfo.h:659
llvm::LegalizeRuleSet::scalarSameSizeAs
LegalizeRuleSet & scalarSameSizeAs(unsigned TypeIdx, unsigned SameSizeIdx)
Change the type TypeIdx to have the same scalar size as type SameSizeIdx.
Definition: LegalizerInfo.h:938
llvm::LegalizerInfo::legalizeCustom
virtual bool legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI) const
Called for instructions with the Custom LegalizationAction.
Definition: LegalizerInfo.h:1288
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::LLT::getElementType
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
Definition: LowLevelTypeImpl.h:188
raw_ostream.h
llvm::LegalizeRuleSet::libcallFor
LegalizeRuleSet & libcallFor(std::initializer_list< LLT > Types)
Definition: LegalizerInfo.h:683
llvm::LegalityPredicates::TypePairAndMemDesc::Type1
LLT Type1
Definition: LegalizerInfo.h:175
MachineFunction.h
llvm::InstrAspect::Idx
unsigned Idx
Definition: LegalizerInfo.h:108
llvm::LegalizeActions::Lower
@ Lower
The operation itself must be expressed in terms of simpler actions on this target.
Definition: LegalizerInfo.h:76
llvm::LegalizeRuleSet::customForCartesianProduct
LegalizeRuleSet & customForCartesianProduct(std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1)
Definition: LegalizerInfo.h:787
llvm::LegalityPredicates::sameSize
LegalityPredicate sameSize(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the specified type indices are both the same bit size.
Definition: LegalityPredicates.cpp:169
llvm::LegalityQuery::LegalityQuery
constexpr LegalityQuery(unsigned Opcode, const ArrayRef< LLT > Types)
Definition: LegalizerInfo.h:141
llvm::LegalizerInfo::setLegalizeVectorElementToDifferentSizeStrategy
void setLegalizeVectorElementToDifferentSizeStrategy(const unsigned Opcode, const unsigned TypeIdx, SizeChangeStrategy S)
See also setLegalizeScalarToDifferentSizeStrategy.
Definition: LegalizerInfo.h:1134
llvm::LegalizerInfo::isLegal
bool isLegal(const LegalityQuery &Query) const
Definition: LegalizerInfo.h:1274
llvm::LegalizeRuleSet::legalForTypesWithMemDesc
LegalizeRuleSet & legalForTypesWithMemDesc(std::initializer_list< LegalityPredicates::TypePairAndMemDesc > TypesAndMemDesc)
The instruction is legal when type indexes 0 and 1 along with the memory size and minimum alignment i...
Definition: LegalizerInfo.h:561
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1168
llvm::LLT
Definition: LowLevelTypeImpl.h:40