LLVM 22.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
23#include "llvm/MC/MCInstrDesc.h"
27#include <cassert>
28#include <cstdint>
29#include <tuple>
30#include <utility>
31
32namespace llvm {
33
35
36class MachineFunction;
37class raw_ostream;
38class LegalizerHelper;
40class MachineInstr;
42class MCInstrInfo;
43
44namespace LegalizeActions {
45enum 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. There can be a leftover
63 /// if there are not enough elements for last sub-vector e.g. <7 x s64> add
64 /// will be implemented as 3 separate <2 x s64> adds and one s64 add. Leftover
65 /// types can be avoided by doing MoreElements first.
67
68 /// The (vector) operation should be implemented by widening the input
69 /// vector and ignoring the lanes added by doing so. For example <2 x i8> is
70 /// rarely legal, but you might perform an <8 x i8> and then only look at
71 /// the first two results.
73
74 /// Perform the operation on a different, but equivalently sized type.
76
77 /// The operation itself must be expressed in terms of simpler actions on
78 /// this target. E.g. a SREM replaced by an SDIV and subtraction.
80
81 /// The operation should be implemented as a call to some kind of runtime
82 /// support library. For example this usually happens on machines that don't
83 /// support floating-point operations natively.
85
86 /// The target wants to do something special with this combination of
87 /// operand and type. A callback will be issued when it is needed.
89
90 /// This operation is completely unsupported on the target. A programming
91 /// error has occurred.
93
94 /// Sentinel value for when no action was found in the specified table.
96
97 /// Fall back onto the old rules.
98 /// TODO: Remove this once we've migrated
100};
101} // end namespace LegalizeActions
102LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
104
106
107/// The LegalityQuery object bundles together all the information that's needed
108/// to decide whether a given operation is legal or not.
109/// For efficiency, it doesn't make a copy of Types so care must be taken not
110/// to free it before using the query.
112 unsigned Opcode;
114
115 struct MemDesc {
118 AtomicOrdering Ordering; //< For cmpxchg this is the success ordering.
119 AtomicOrdering FailureOrdering; //< For cmpxchg, otherwise NotAtomic.
120
121 MemDesc() = default;
127 : MemDesc(MMO.getMemoryType(), MMO.getAlign().value() * 8,
128 MMO.getSuccessOrdering(), MMO.getFailureOrdering()) {}
129 };
130
131 /// Operations which require memory can use this to place requirements on the
132 /// memory type for each MMO.
134
137 : Opcode(Opcode), Types(Types), MMODescrs(MMODescrs) {}
138
139 LLVM_ABI raw_ostream &print(raw_ostream &OS) const;
140};
141
142/// The result of a query. It either indicates a final answer of Legal or
143/// Unsupported or describes an action that must be taken to make an operation
144/// more legal.
146 /// The action to take or the final answer.
148 /// If describing an action, the type index to change. Otherwise zero.
149 unsigned TypeIdx;
150 /// If describing an action, the new type for TypeIdx. Otherwise LLT{}.
152
156
158 : TypeIdx(Step.TypeIdx), NewType(Step.NewType) {
159 switch (Step.Action) {
160 case LegacyLegalizeActions::Legal:
161 Action = LegalizeActions::Legal;
162 break;
163 case LegacyLegalizeActions::NarrowScalar:
164 Action = LegalizeActions::NarrowScalar;
165 break;
166 case LegacyLegalizeActions::WidenScalar:
167 Action = LegalizeActions::WidenScalar;
168 break;
169 case LegacyLegalizeActions::FewerElements:
170 Action = LegalizeActions::FewerElements;
171 break;
172 case LegacyLegalizeActions::MoreElements:
173 Action = LegalizeActions::MoreElements;
174 break;
175 case LegacyLegalizeActions::Bitcast:
176 Action = LegalizeActions::Bitcast;
177 break;
178 case LegacyLegalizeActions::Lower:
179 Action = LegalizeActions::Lower;
180 break;
181 case LegacyLegalizeActions::Libcall:
182 Action = LegalizeActions::Libcall;
183 break;
184 case LegacyLegalizeActions::Custom:
185 Action = LegalizeActions::Custom;
186 break;
187 case LegacyLegalizeActions::Unsupported:
188 Action = LegalizeActions::Unsupported;
189 break;
190 case LegacyLegalizeActions::NotFound:
191 Action = LegalizeActions::NotFound;
192 break;
193 }
194 }
195
196 bool operator==(const LegalizeActionStep &RHS) const {
197 return std::tie(Action, TypeIdx, NewType) ==
198 std::tie(RHS.Action, RHS.TypeIdx, RHS.NewType);
199 }
200};
201
202using LegalityPredicate = std::function<bool (const LegalityQuery &)>;
204 std::function<std::pair<unsigned, LLT>(const LegalityQuery &)>;
205
212
214 return Type0 == Other.Type0 && Type1 == Other.Type1 &&
215 Align == Other.Align && MemTy == Other.MemTy;
216 }
217
218 /// \returns true if this memory access is legal with for the access described
219 /// by \p Other (The alignment is sufficient for the size and result type).
221 return Type0 == Other.Type0 && Type1 == Other.Type1 &&
222 Align >= Other.Align &&
223 // FIXME: This perhaps should be stricter, but the current legality
224 // rules are written only considering the size.
225 MemTy.getSizeInBits() == Other.MemTy.getSizeInBits();
226 }
227};
228
229/// True iff P is false.
230template <typename Predicate> Predicate predNot(Predicate P) {
231 return [=](const LegalityQuery &Query) { return !P(Query); };
232}
233
234/// True iff P0 and P1 are true.
235template<typename Predicate>
237 return [=](const LegalityQuery &Query) {
238 return P0(Query) && P1(Query);
239 };
240}
241/// True iff all given predicates are true.
242template<typename Predicate, typename... Args>
244 return all(all(P0, P1), args...);
245}
246
247/// True iff P0 or P1 are true.
248template<typename Predicate>
250 return [=](const LegalityQuery &Query) {
251 return P0(Query) || P1(Query);
252 };
253}
254/// True iff any given predicates are true.
255template<typename Predicate, typename... Args>
257 return any(any(P0, P1), args...);
258}
259
260/// True iff the given type index is the specified type.
261LLVM_ABI LegalityPredicate typeIs(unsigned TypeIdx, LLT TypesInit);
262/// True iff the given type index is one of the specified types.
263LLVM_ABI LegalityPredicate typeInSet(unsigned TypeIdx,
264 std::initializer_list<LLT> TypesInit);
265
266/// True iff the given type index is not the specified type.
267inline LegalityPredicate typeIsNot(unsigned TypeIdx, LLT Type) {
268 return [=](const LegalityQuery &Query) {
269 return Query.Types[TypeIdx] != Type;
270 };
271}
272
273/// True iff the given types for the given pair of type indexes is one of the
274/// specified type pairs.
276typePairInSet(unsigned TypeIdx0, unsigned TypeIdx1,
277 std::initializer_list<std::pair<LLT, LLT>> TypesInit);
278/// True iff the given types for the given tuple of type indexes is one of the
279/// specified type tuple.
281typeTupleInSet(unsigned TypeIdx0, unsigned TypeIdx1, unsigned Type2,
282 std::initializer_list<std::tuple<LLT, LLT, LLT>> TypesInit);
283/// True iff the given types for the given pair of type indexes is one of the
284/// specified type pairs.
286 unsigned TypeIdx0, unsigned TypeIdx1, unsigned MMOIdx,
287 std::initializer_list<TypePairAndMemDesc> TypesAndMemDescInit);
288/// True iff the specified type index is a scalar.
289LLVM_ABI LegalityPredicate isScalar(unsigned TypeIdx);
290/// True iff the specified type index is a vector.
291LLVM_ABI LegalityPredicate isVector(unsigned TypeIdx);
292/// True iff the specified type index is a pointer (with any address space).
293LLVM_ABI LegalityPredicate isPointer(unsigned TypeIdx);
294/// True iff the specified type index is a pointer with the specified address
295/// space.
296LLVM_ABI LegalityPredicate isPointer(unsigned TypeIdx, unsigned AddrSpace);
297/// True iff the specified type index is a vector of pointers (with any address
298/// space).
300
301/// True if the type index is a vector with element type \p EltTy
302LLVM_ABI LegalityPredicate elementTypeIs(unsigned TypeIdx, LLT EltTy);
303
304/// True iff the specified type index is a scalar that's narrower than the given
305/// size.
306LLVM_ABI LegalityPredicate scalarNarrowerThan(unsigned TypeIdx, unsigned Size);
307
308/// True iff the specified type index is a scalar that's wider than the given
309/// size.
310LLVM_ABI LegalityPredicate scalarWiderThan(unsigned TypeIdx, unsigned Size);
311
312/// True iff the specified type index is a scalar or vector with an element type
313/// that's narrower than the given size.
315 unsigned Size);
316
317/// True iff the specified type index is a scalar or a vector with an element
318/// type that's wider than the given size.
320 unsigned Size);
321
322/// True iff the specified type index is a scalar whose size is not a multiple
323/// of Size.
324LLVM_ABI LegalityPredicate sizeNotMultipleOf(unsigned TypeIdx, unsigned Size);
325
326/// True iff the specified type index is a scalar whose size is not a power of
327/// 2.
328LLVM_ABI LegalityPredicate sizeNotPow2(unsigned TypeIdx);
329
330/// True iff the specified type index is a scalar or vector whose element size
331/// is not a power of 2.
333
334/// True if the total bitwidth of the specified type index is \p Size bits.
335LLVM_ABI LegalityPredicate sizeIs(unsigned TypeIdx, unsigned Size);
336
337/// True iff the specified type indices are both the same bit size.
338LLVM_ABI LegalityPredicate sameSize(unsigned TypeIdx0, unsigned TypeIdx1);
339
340/// True iff the first type index has a larger total bit size than second type
341/// index.
342LLVM_ABI LegalityPredicate largerThan(unsigned TypeIdx0, unsigned TypeIdx1);
343
344/// True iff the first type index has a smaller total bit size than second type
345/// index.
346LLVM_ABI LegalityPredicate smallerThan(unsigned TypeIdx0, unsigned TypeIdx1);
347
348/// True iff the specified MMO index has a size (rounded to bytes) that is not a
349/// power of 2.
351
352/// True iff the specified MMO index has a size that is not an even byte size,
353/// or that even byte size is not a power of 2.
355
356/// True iff the specified type index is a vector whose element count is not a
357/// power of 2.
359/// True iff the specified MMO index has at an atomic ordering of at Ordering or
360/// stronger.
362atomicOrderingAtLeastOrStrongerThan(unsigned MMOIdx, AtomicOrdering Ordering);
363} // end namespace LegalityPredicates
364
366/// Select this specific type for the given type index.
367LLVM_ABI LegalizeMutation changeTo(unsigned TypeIdx, LLT Ty);
368
369/// Keep the same type as the given type index.
370LLVM_ABI LegalizeMutation changeTo(unsigned TypeIdx, unsigned FromTypeIdx);
371
372/// Keep the same scalar or element type as the given type index.
374 unsigned FromTypeIdx);
375
376/// Keep the same scalar or element type as the given type.
377LLVM_ABI LegalizeMutation changeElementTo(unsigned TypeIdx, LLT Ty);
378
379/// Keep the same scalar or element type as \p TypeIdx, but take the number of
380/// elements from \p FromTypeIdx.
382 unsigned FromTypeIdx);
383
384/// Keep the same scalar or element type as \p TypeIdx, but take the number of
385/// elements from \p Ty.
387
388/// Change the scalar size or element size to have the same scalar size as type
389/// index \p FromIndex. Unlike changeElementTo, this discards pointer types and
390/// only changes the size.
392 unsigned FromTypeIdx);
393
394/// Widen the scalar type or vector element type for the given type index to the
395/// next power of 2.
397 unsigned Min = 0);
398
399/// Widen the scalar type or vector element type for the given type index to
400/// next multiple of \p Size.
402 unsigned Size);
403
404/// Add more elements to the type for the given type index to the next power of
405/// 2.
407 unsigned Min = 0);
408/// Break up the vector type for the given type index into the element type.
409LLVM_ABI LegalizeMutation scalarize(unsigned TypeIdx);
410} // end namespace LegalizeMutations
411
412/// A single rule in a legalizer info ruleset.
413/// The specified action is chosen when the predicate is true. Where appropriate
414/// for the action (e.g. for WidenScalar) the new type is selected using the
415/// given mutator.
417 LegalityPredicate Predicate;
418 LegalizeAction Action;
419 LegalizeMutation Mutation;
420
421public:
423 LegalizeMutation Mutation = nullptr)
424 : Predicate(Predicate), Action(Action), Mutation(Mutation) {}
425
426 /// Test whether the LegalityQuery matches.
427 bool match(const LegalityQuery &Query) const {
428 return Predicate(Query);
429 }
430
431 LegalizeAction getAction() const { return Action; }
432
433 /// Determine the change to make.
434 std::pair<unsigned, LLT> determineMutation(const LegalityQuery &Query) const {
435 if (Mutation)
436 return Mutation(Query);
437 return std::make_pair(0, LLT{});
438 }
439};
440
442 /// When non-zero, the opcode we are an alias of
443 unsigned AliasOf = 0;
444 /// If true, there is another opcode that aliases this one
445 bool IsAliasedByAnother = false;
447
448#ifndef NDEBUG
449 /// If bit I is set, this rule set contains a rule that may handle (predicate
450 /// or perform an action upon (or both)) the type index I. The uncertainty
451 /// comes from free-form rules executing user-provided lambda functions. We
452 /// conservatively assume such rules do the right thing and cover all type
453 /// indices. The bitset is intentionally 1 bit wider than it absolutely needs
454 /// to be to distinguish such cases from the cases where all type indices are
455 /// individually handled.
460#endif
461
462 unsigned typeIdx(unsigned TypeIdx) {
463 assert(TypeIdx <=
465 "Type Index is out of bounds");
466#ifndef NDEBUG
467 TypeIdxsCovered.set(TypeIdx);
468#endif
469 return TypeIdx;
470 }
471
472 void markAllIdxsAsCovered() {
473#ifndef NDEBUG
474 TypeIdxsCovered.set();
475 ImmIdxsCovered.set();
476#endif
477 }
478
479 void add(const LegalizeRule &Rule) {
480 assert(AliasOf == 0 &&
481 "RuleSet is aliased, change the representative opcode instead");
482 Rules.push_back(Rule);
483 }
484
485 static bool always(const LegalityQuery &) { return true; }
486
487 /// Use the given action when the predicate is true.
488 /// Action should not be an action that requires mutation.
489 LegalizeRuleSet &actionIf(LegalizeAction Action,
491 add({Predicate, Action});
492 return *this;
493 }
494 /// Use the given action when the predicate is true.
495 /// Action should be an action that requires mutation.
498 add({Predicate, Action, Mutation});
499 return *this;
500 }
501 /// Use the given action when type index 0 is any type in the given list.
502 /// Action should not be an action that requires mutation.
503 LegalizeRuleSet &actionFor(LegalizeAction Action,
504 std::initializer_list<LLT> Types) {
505 using namespace LegalityPredicates;
506 return actionIf(Action, typeInSet(typeIdx(0), Types));
507 }
508 /// Use the given action when type index 0 is any type in the given list.
509 /// Action should be an action that requires mutation.
510 LegalizeRuleSet &actionFor(LegalizeAction Action,
511 std::initializer_list<LLT> Types,
513 using namespace LegalityPredicates;
514 return actionIf(Action, typeInSet(typeIdx(0), Types), Mutation);
515 }
516 /// Use the given action when type indexes 0 and 1 is any type pair in the
517 /// given list.
518 /// Action should not be an action that requires mutation.
519 LegalizeRuleSet &actionFor(LegalizeAction Action,
520 std::initializer_list<std::pair<LLT, LLT>> Types) {
521 using namespace LegalityPredicates;
522 return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types));
523 }
524
526 actionFor(LegalizeAction Action,
527 std::initializer_list<std::tuple<LLT, LLT, LLT>> Types) {
528 using namespace LegalityPredicates;
529 return actionIf(Action,
530 typeTupleInSet(typeIdx(0), typeIdx(1), typeIdx(2), Types));
531 }
532
533 /// Use the given action when type indexes 0 and 1 is any type pair in the
534 /// given list.
535 /// Action should be an action that requires mutation.
536 LegalizeRuleSet &actionFor(LegalizeAction Action,
537 std::initializer_list<std::pair<LLT, LLT>> Types,
539 using namespace LegalityPredicates;
540 return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types),
541 Mutation);
542 }
543 /// Use the given action when type index 0 is any type in the given list and
544 /// imm index 0 is anything. Action should not be an action that requires
545 /// mutation.
546 LegalizeRuleSet &actionForTypeWithAnyImm(LegalizeAction Action,
547 std::initializer_list<LLT> Types) {
548 using namespace LegalityPredicates;
549 immIdx(0); // Inform verifier imm idx 0 is handled.
550 return actionIf(Action, typeInSet(typeIdx(0), Types));
551 }
552
553 LegalizeRuleSet &actionForTypeWithAnyImm(
554 LegalizeAction Action, std::initializer_list<std::pair<LLT, LLT>> Types) {
555 using namespace LegalityPredicates;
556 immIdx(0); // Inform verifier imm idx 0 is handled.
557 return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types));
558 }
559
560 /// Use the given action when type indexes 0 and 1 are both in the given list.
561 /// That is, the type pair is in the cartesian product of the list.
562 /// Action should not be an action that requires mutation.
563 LegalizeRuleSet &actionForCartesianProduct(LegalizeAction Action,
564 std::initializer_list<LLT> Types) {
565 using namespace LegalityPredicates;
566 return actionIf(Action, all(typeInSet(typeIdx(0), Types),
567 typeInSet(typeIdx(1), Types)));
568 }
569 /// Use the given action when type indexes 0 and 1 are both in their
570 /// respective lists.
571 /// That is, the type pair is in the cartesian product of the lists
572 /// Action should not be an action that requires mutation.
574 actionForCartesianProduct(LegalizeAction Action,
575 std::initializer_list<LLT> Types0,
576 std::initializer_list<LLT> Types1) {
577 using namespace LegalityPredicates;
578 return actionIf(Action, all(typeInSet(typeIdx(0), Types0),
579 typeInSet(typeIdx(1), Types1)));
580 }
581 /// Use the given action when type indexes 0, 1, and 2 are all in their
582 /// respective lists.
583 /// That is, the type triple is in the cartesian product of the lists
584 /// Action should not be an action that requires mutation.
585 LegalizeRuleSet &actionForCartesianProduct(
586 LegalizeAction Action, std::initializer_list<LLT> Types0,
587 std::initializer_list<LLT> Types1, std::initializer_list<LLT> Types2) {
588 using namespace LegalityPredicates;
589 return actionIf(Action, all(typeInSet(typeIdx(0), Types0),
590 all(typeInSet(typeIdx(1), Types1),
591 typeInSet(typeIdx(2), Types2))));
592 }
593
594public:
595 LegalizeRuleSet() = default;
596
597 bool isAliasedByAnother() { return IsAliasedByAnother; }
598 void setIsAliasedByAnother() { IsAliasedByAnother = true; }
599 void aliasTo(unsigned Opcode) {
600 assert((AliasOf == 0 || AliasOf == Opcode) &&
601 "Opcode is already aliased to another opcode");
602 assert(Rules.empty() && "Aliasing will discard rules");
603 AliasOf = Opcode;
604 }
605 unsigned getAlias() const { return AliasOf; }
606
607 unsigned immIdx(unsigned ImmIdx) {
610 "Imm Index is out of bounds");
611#ifndef NDEBUG
612 ImmIdxsCovered.set(ImmIdx);
613#endif
614 return ImmIdx;
615 }
616
617 /// The instruction is legal if predicate is true.
619 // We have no choice but conservatively assume that the free-form
620 // user-provided Predicate properly handles all type indices:
621 markAllIdxsAsCovered();
622 return actionIf(LegalizeAction::Legal, Predicate);
623 }
624 /// The instruction is legal when type index 0 is any type in the given list.
625 LegalizeRuleSet &legalFor(std::initializer_list<LLT> Types) {
626 return actionFor(LegalizeAction::Legal, Types);
627 }
628 LegalizeRuleSet &legalFor(bool Pred, std::initializer_list<LLT> Types) {
629 if (!Pred)
630 return *this;
631 return actionFor(LegalizeAction::Legal, Types);
632 }
633 /// The instruction is legal when type indexes 0 and 1 is any type pair in the
634 /// given list.
635 LegalizeRuleSet &legalFor(std::initializer_list<std::pair<LLT, LLT>> Types) {
636 return actionFor(LegalizeAction::Legal, Types);
637 }
639 std::initializer_list<std::pair<LLT, LLT>> Types) {
640 if (!Pred)
641 return *this;
642 return actionFor(LegalizeAction::Legal, Types);
643 }
645 legalFor(bool Pred, std::initializer_list<std::tuple<LLT, LLT, LLT>> Types) {
646 if (!Pred)
647 return *this;
648 return actionFor(LegalizeAction::Legal, Types);
649 }
650 /// The instruction is legal when type index 0 is any type in the given list
651 /// and imm index 0 is anything.
652 LegalizeRuleSet &legalForTypeWithAnyImm(std::initializer_list<LLT> Types) {
653 markAllIdxsAsCovered();
654 return actionForTypeWithAnyImm(LegalizeAction::Legal, Types);
655 }
656
658 std::initializer_list<std::pair<LLT, LLT>> Types) {
659 markAllIdxsAsCovered();
660 return actionForTypeWithAnyImm(LegalizeAction::Legal, Types);
661 }
662
663 /// The instruction is legal when type indexes 0 and 1 along with the memory
664 /// size and minimum alignment is any type and size tuple in the given list.
666 std::initializer_list<LegalityPredicates::TypePairAndMemDesc>
667 TypesAndMemDesc) {
668 return actionIf(LegalizeAction::Legal,
670 typeIdx(0), typeIdx(1), /*MMOIdx*/ 0, TypesAndMemDesc));
671 }
672 /// The instruction is legal when type indexes 0 and 1 are both in the given
673 /// list. That is, the type pair is in the cartesian product of the list.
674 LegalizeRuleSet &legalForCartesianProduct(std::initializer_list<LLT> Types) {
675 return actionForCartesianProduct(LegalizeAction::Legal, Types);
676 }
677 /// The instruction is legal when type indexes 0 and 1 are both their
678 /// respective lists.
679 LegalizeRuleSet &legalForCartesianProduct(std::initializer_list<LLT> Types0,
680 std::initializer_list<LLT> Types1) {
681 return actionForCartesianProduct(LegalizeAction::Legal, Types0, Types1);
682 }
683 /// The instruction is legal when type indexes 0, 1, and 2 are both their
684 /// respective lists.
685 LegalizeRuleSet &legalForCartesianProduct(std::initializer_list<LLT> Types0,
686 std::initializer_list<LLT> Types1,
687 std::initializer_list<LLT> Types2) {
688 return actionForCartesianProduct(LegalizeAction::Legal, Types0, Types1,
689 Types2);
690 }
691
693 using namespace LegalizeMutations;
694 markAllIdxsAsCovered();
695 return actionIf(LegalizeAction::Legal, always);
696 }
697
698 /// The specified type index is coerced if predicate is true.
701 // We have no choice but conservatively assume that lowering with a
702 // free-form user provided Predicate properly handles all type indices:
703 markAllIdxsAsCovered();
704 return actionIf(LegalizeAction::Bitcast, Predicate, Mutation);
705 }
706
707 /// The instruction is lowered.
709 using namespace LegalizeMutations;
710 // We have no choice but conservatively assume that predicate-less lowering
711 // properly handles all type indices by design:
712 markAllIdxsAsCovered();
713 return actionIf(LegalizeAction::Lower, always);
714 }
715 /// The instruction is lowered if predicate is true. Keep type index 0 as the
716 /// same type.
718 using namespace LegalizeMutations;
719 // We have no choice but conservatively assume that lowering with a
720 // free-form user provided Predicate properly handles all type indices:
721 markAllIdxsAsCovered();
722 return actionIf(LegalizeAction::Lower, Predicate);
723 }
724 /// The instruction is lowered if predicate is true.
727 // We have no choice but conservatively assume that lowering with a
728 // free-form user provided Predicate properly handles all type indices:
729 markAllIdxsAsCovered();
730 return actionIf(LegalizeAction::Lower, Predicate, Mutation);
731 }
732 /// The instruction is lowered when type index 0 is any type in the given
733 /// list. Keep type index 0 as the same type.
734 LegalizeRuleSet &lowerFor(std::initializer_list<LLT> Types) {
735 return actionFor(LegalizeAction::Lower, Types);
736 }
737 /// The instruction is lowered when type index 0 is any type in the given
738 /// list.
739 LegalizeRuleSet &lowerFor(std::initializer_list<LLT> Types,
741 return actionFor(LegalizeAction::Lower, Types, Mutation);
742 }
743 /// The instruction is lowered when type indexes 0 and 1 is any type pair in
744 /// the given list. Keep type index 0 as the same type.
745 LegalizeRuleSet &lowerFor(std::initializer_list<std::pair<LLT, LLT>> Types) {
746 return actionFor(LegalizeAction::Lower, Types);
747 }
748 /// The instruction is lowered when type indexes 0 and 1 is any type pair in
749 /// the given list.
750 LegalizeRuleSet &lowerFor(std::initializer_list<std::pair<LLT, LLT>> Types,
752 return actionFor(LegalizeAction::Lower, Types, Mutation);
753 }
754 /// The instruction is lowered when type indexes 0 and 1 are both in their
755 /// respective lists.
756 LegalizeRuleSet &lowerForCartesianProduct(std::initializer_list<LLT> Types0,
757 std::initializer_list<LLT> Types1) {
758 using namespace LegalityPredicates;
759 return actionForCartesianProduct(LegalizeAction::Lower, Types0, Types1);
760 }
761 /// The instruction is lowered when type indexes 0, 1, and 2 are all in
762 /// their respective lists.
763 LegalizeRuleSet &lowerForCartesianProduct(std::initializer_list<LLT> Types0,
764 std::initializer_list<LLT> Types1,
765 std::initializer_list<LLT> Types2) {
766 using namespace LegalityPredicates;
767 return actionForCartesianProduct(LegalizeAction::Lower, Types0, Types1,
768 Types2);
769 }
770
771 /// The instruction is emitted as a library call.
773 using namespace LegalizeMutations;
774 // We have no choice but conservatively assume that predicate-less lowering
775 // properly handles all type indices by design:
776 markAllIdxsAsCovered();
777 return actionIf(LegalizeAction::Libcall, always);
778 }
779
780 /// Like legalIf, but for the Libcall action.
782 // We have no choice but conservatively assume that a libcall with a
783 // free-form user provided Predicate properly handles all type indices:
784 markAllIdxsAsCovered();
785 return actionIf(LegalizeAction::Libcall, Predicate);
786 }
787 LegalizeRuleSet &libcallFor(std::initializer_list<LLT> Types) {
788 return actionFor(LegalizeAction::Libcall, Types);
789 }
790 LegalizeRuleSet &libcallFor(bool Pred, std::initializer_list<LLT> Types) {
791 if (!Pred)
792 return *this;
793 return actionFor(LegalizeAction::Libcall, Types);
794 }
796 libcallFor(std::initializer_list<std::pair<LLT, LLT>> Types) {
797 return actionFor(LegalizeAction::Libcall, Types);
798 }
800 libcallFor(bool Pred, std::initializer_list<std::pair<LLT, LLT>> Types) {
801 if (!Pred)
802 return *this;
803 return actionFor(LegalizeAction::Libcall, Types);
804 }
806 libcallForCartesianProduct(std::initializer_list<LLT> Types) {
807 return actionForCartesianProduct(LegalizeAction::Libcall, Types);
808 }
810 libcallForCartesianProduct(std::initializer_list<LLT> Types0,
811 std::initializer_list<LLT> Types1) {
812 return actionForCartesianProduct(LegalizeAction::Libcall, Types0, Types1);
813 }
814
815 /// Widen the scalar to the one selected by the mutation if the predicate is
816 /// true.
819 // We have no choice but conservatively assume that an action with a
820 // free-form user provided Predicate properly handles all type indices:
821 markAllIdxsAsCovered();
822 return actionIf(LegalizeAction::WidenScalar, Predicate, Mutation);
823 }
824 /// Narrow the scalar to the one selected by the mutation if the predicate is
825 /// true.
828 // We have no choice but conservatively assume that an action with a
829 // free-form user provided Predicate properly handles all type indices:
830 markAllIdxsAsCovered();
831 return actionIf(LegalizeAction::NarrowScalar, Predicate, Mutation);
832 }
833 /// Narrow the scalar, specified in mutation, when type indexes 0 and 1 is any
834 /// type pair in the given list.
836 narrowScalarFor(std::initializer_list<std::pair<LLT, LLT>> Types,
838 return actionFor(LegalizeAction::NarrowScalar, Types, Mutation);
839 }
840
841 /// Add more elements to reach the type selected by the mutation if the
842 /// predicate is true.
845 // We have no choice but conservatively assume that an action with a
846 // free-form user provided Predicate properly handles all type indices:
847 markAllIdxsAsCovered();
848 return actionIf(LegalizeAction::MoreElements, Predicate, Mutation);
849 }
850 /// Remove elements to reach the type selected by the mutation if the
851 /// predicate is true.
854 // We have no choice but conservatively assume that an action with a
855 // free-form user provided Predicate properly handles all type indices:
856 markAllIdxsAsCovered();
857 return actionIf(LegalizeAction::FewerElements, Predicate, Mutation);
858 }
859
860 /// The instruction is unsupported.
862 markAllIdxsAsCovered();
863 return actionIf(LegalizeAction::Unsupported, always);
864 }
866 return actionIf(LegalizeAction::Unsupported, Predicate);
867 }
868
869 LegalizeRuleSet &unsupportedFor(std::initializer_list<LLT> Types) {
870 return actionFor(LegalizeAction::Unsupported, Types);
871 }
872
874 return actionIf(LegalizeAction::Unsupported,
876 }
877
878 /// Lower a memory operation if the memory size, rounded to bytes, is not a
879 /// power of 2. For example, this will not trigger for s1 or s7, but will for
880 /// s24.
882 return actionIf(LegalizeAction::Lower,
884 }
885
886 /// Lower a memory operation if the memory access size is not a round power of
887 /// 2 byte size. This is stricter than lowerIfMemSizeNotPow2, and more likely
888 /// what you want (e.g. this will lower s1, s7 and s24).
890 return actionIf(LegalizeAction::Lower,
892 }
893
895 // We have no choice but conservatively assume that a custom action with a
896 // free-form user provided Predicate properly handles all type indices:
897 markAllIdxsAsCovered();
898 return actionIf(LegalizeAction::Custom, Predicate);
899 }
900 LegalizeRuleSet &customFor(std::initializer_list<LLT> Types) {
901 return actionFor(LegalizeAction::Custom, Types);
902 }
903 LegalizeRuleSet &customFor(bool Pred, std::initializer_list<LLT> Types) {
904 if (!Pred)
905 return *this;
906 return actionFor(LegalizeAction::Custom, Types);
907 }
908
909 /// The instruction is custom when type indexes 0 and 1 is any type pair in
910 /// the given list.
911 LegalizeRuleSet &customFor(std::initializer_list<std::pair<LLT, LLT>> Types) {
912 return actionFor(LegalizeAction::Custom, Types);
913 }
915 std::initializer_list<std::pair<LLT, LLT>> Types) {
916 if (!Pred)
917 return *this;
918 return actionFor(LegalizeAction::Custom, Types);
919 }
920
921 LegalizeRuleSet &customForCartesianProduct(std::initializer_list<LLT> Types) {
922 return actionForCartesianProduct(LegalizeAction::Custom, Types);
923 }
924 /// The instruction is custom when type indexes 0 and 1 are both in their
925 /// respective lists.
927 customForCartesianProduct(std::initializer_list<LLT> Types0,
928 std::initializer_list<LLT> Types1) {
929 return actionForCartesianProduct(LegalizeAction::Custom, Types0, Types1);
930 }
931 /// The instruction is custom when type indexes 0, 1, and 2 are all in
932 /// their respective lists.
934 customForCartesianProduct(std::initializer_list<LLT> Types0,
935 std::initializer_list<LLT> Types1,
936 std::initializer_list<LLT> Types2) {
937 return actionForCartesianProduct(LegalizeAction::Custom, Types0, Types1,
938 Types2);
939 }
940
941 /// The instruction is custom when the predicate is true and type indexes 0
942 /// and 1 are all in their respective lists.
944 customForCartesianProduct(bool Pred, std::initializer_list<LLT> Types0,
945 std::initializer_list<LLT> Types1) {
946 if (!Pred)
947 return *this;
948 return actionForCartesianProduct(LegalizeAction::Custom, Types0, Types1);
949 }
950
951 /// Unconditionally custom lower.
953 return customIf(always);
954 }
955
956 /// Widen the scalar to the next power of two that is at least MinSize.
957 /// No effect if the type is a power of two, except if the type is smaller
958 /// than MinSize, or if the type is a vector type.
960 unsigned MinSize = 0) {
961 using namespace LegalityPredicates;
962 return actionIf(
963 LegalizeAction::WidenScalar, sizeNotPow2(typeIdx(TypeIdx)),
965 }
966
967 /// Widen the scalar to the next multiple of Size. No effect if the
968 /// type is not a scalar or is a multiple of Size.
970 unsigned Size) {
971 using namespace LegalityPredicates;
972 return actionIf(
973 LegalizeAction::WidenScalar, sizeNotMultipleOf(typeIdx(TypeIdx), Size),
975 }
976
977 /// Widen the scalar or vector element type to the next power of two that is
978 /// at least MinSize. No effect if the scalar size is a power of two.
980 unsigned MinSize = 0) {
981 using namespace LegalityPredicates;
982 return actionIf(
983 LegalizeAction::WidenScalar, scalarOrEltSizeNotPow2(typeIdx(TypeIdx)),
985 }
986
987 /// Widen the scalar or vector element type to the next power of two that is
988 /// at least MinSize. No effect if the scalar size is a power of two.
990 unsigned MinSize = 0) {
991 using namespace LegalityPredicates;
992 return actionIf(
993 LegalizeAction::WidenScalar,
994 any(scalarOrEltNarrowerThan(TypeIdx, MinSize),
995 scalarOrEltSizeNotPow2(typeIdx(TypeIdx))),
997 }
998
1000 using namespace LegalityPredicates;
1001 return actionIf(LegalizeAction::NarrowScalar, isScalar(typeIdx(TypeIdx)),
1002 Mutation);
1003 }
1004
1005 LegalizeRuleSet &scalarize(unsigned TypeIdx) {
1006 using namespace LegalityPredicates;
1007 return actionIf(LegalizeAction::FewerElements, isVector(typeIdx(TypeIdx)),
1009 }
1010
1012 using namespace LegalityPredicates;
1013 return actionIf(LegalizeAction::FewerElements,
1014 all(Predicate, isVector(typeIdx(TypeIdx))),
1016 }
1017
1018 /// Ensure the scalar or element is at least as wide as Ty.
1019 LegalizeRuleSet &minScalarOrElt(unsigned TypeIdx, const LLT Ty) {
1020 using namespace LegalityPredicates;
1021 using namespace LegalizeMutations;
1022 return actionIf(LegalizeAction::WidenScalar,
1023 scalarOrEltNarrowerThan(TypeIdx, Ty.getScalarSizeInBits()),
1024 changeElementTo(typeIdx(TypeIdx), Ty));
1025 }
1026
1027 /// Ensure the scalar or element is at least as wide as Ty.
1029 unsigned TypeIdx, const LLT Ty) {
1030 using namespace LegalityPredicates;
1031 using namespace LegalizeMutations;
1032 return actionIf(LegalizeAction::WidenScalar,
1033 all(Predicate, scalarOrEltNarrowerThan(
1034 TypeIdx, Ty.getScalarSizeInBits())),
1035 changeElementTo(typeIdx(TypeIdx), Ty));
1036 }
1037
1038 /// Ensure the vector size is at least as wide as VectorSize by promoting the
1039 /// element.
1041 unsigned VectorSize) {
1042 using namespace LegalityPredicates;
1043 using namespace LegalizeMutations;
1044 return actionIf(
1045 LegalizeAction::WidenScalar,
1046 [=](const LegalityQuery &Query) {
1047 const LLT VecTy = Query.Types[TypeIdx];
1048 return VecTy.isFixedVector() && VecTy.getSizeInBits() < VectorSize;
1049 },
1050 [=](const LegalityQuery &Query) {
1051 const LLT VecTy = Query.Types[TypeIdx];
1052 unsigned NumElts = VecTy.getNumElements();
1053 unsigned MinSize = VectorSize / NumElts;
1054 LLT NewTy = LLT::fixed_vector(NumElts, LLT::scalar(MinSize));
1055 return std::make_pair(TypeIdx, NewTy);
1056 });
1057 }
1058
1059 /// Ensure the scalar is at least as wide as Ty.
1060 LegalizeRuleSet &minScalar(unsigned TypeIdx, const LLT Ty) {
1061 using namespace LegalityPredicates;
1062 using namespace LegalizeMutations;
1063 return actionIf(LegalizeAction::WidenScalar,
1064 scalarNarrowerThan(TypeIdx, Ty.getSizeInBits()),
1065 changeTo(typeIdx(TypeIdx), Ty));
1066 }
1067 LegalizeRuleSet &minScalar(bool Pred, unsigned TypeIdx, const LLT Ty) {
1068 if (!Pred)
1069 return *this;
1070 return minScalar(TypeIdx, Ty);
1071 }
1072
1073 /// Ensure the scalar is at least as wide as Ty if condition is met.
1075 const LLT Ty) {
1076 using namespace LegalityPredicates;
1077 using namespace LegalizeMutations;
1078 return actionIf(
1079 LegalizeAction::WidenScalar,
1080 [=](const LegalityQuery &Query) {
1081 const LLT QueryTy = Query.Types[TypeIdx];
1082 return QueryTy.isScalar() &&
1083 QueryTy.getSizeInBits() < Ty.getSizeInBits() &&
1084 Predicate(Query);
1085 },
1086 changeTo(typeIdx(TypeIdx), Ty));
1087 }
1088
1089 /// Ensure the scalar is at most as wide as Ty.
1090 LegalizeRuleSet &maxScalarOrElt(unsigned TypeIdx, const LLT Ty) {
1091 using namespace LegalityPredicates;
1092 using namespace LegalizeMutations;
1093 return actionIf(LegalizeAction::NarrowScalar,
1094 scalarOrEltWiderThan(TypeIdx, Ty.getScalarSizeInBits()),
1095 changeElementTo(typeIdx(TypeIdx), Ty));
1096 }
1097
1098 /// Ensure the scalar is at most as wide as Ty.
1099 LegalizeRuleSet &maxScalar(unsigned TypeIdx, const LLT Ty) {
1100 using namespace LegalityPredicates;
1101 using namespace LegalizeMutations;
1102 return actionIf(LegalizeAction::NarrowScalar,
1103 scalarWiderThan(TypeIdx, Ty.getSizeInBits()),
1104 changeTo(typeIdx(TypeIdx), Ty));
1105 }
1106
1107 /// Conditionally limit the maximum size of the scalar.
1108 /// For example, when the maximum size of one type depends on the size of
1109 /// another such as extracting N bits from an M bit container.
1111 const LLT Ty) {
1112 using namespace LegalityPredicates;
1113 using namespace LegalizeMutations;
1114 return actionIf(
1115 LegalizeAction::NarrowScalar,
1116 [=](const LegalityQuery &Query) {
1117 const LLT QueryTy = Query.Types[TypeIdx];
1118 return QueryTy.isScalar() &&
1119 QueryTy.getSizeInBits() > Ty.getSizeInBits() &&
1120 Predicate(Query);
1121 },
1122 changeElementTo(typeIdx(TypeIdx), Ty));
1123 }
1124
1125 /// Limit the range of scalar sizes to MinTy and MaxTy.
1126 LegalizeRuleSet &clampScalar(unsigned TypeIdx, const LLT MinTy,
1127 const LLT MaxTy) {
1128 assert(MinTy.isScalar() && MaxTy.isScalar() && "Expected scalar types");
1129 return minScalar(TypeIdx, MinTy).maxScalar(TypeIdx, MaxTy);
1130 }
1131
1132 LegalizeRuleSet &clampScalar(bool Pred, unsigned TypeIdx, const LLT MinTy,
1133 const LLT MaxTy) {
1134 if (!Pred)
1135 return *this;
1136 return clampScalar(TypeIdx, MinTy, MaxTy);
1137 }
1138
1139 /// Limit the range of scalar sizes to MinTy and MaxTy.
1140 LegalizeRuleSet &clampScalarOrElt(unsigned TypeIdx, const LLT MinTy,
1141 const LLT MaxTy) {
1142 return minScalarOrElt(TypeIdx, MinTy).maxScalarOrElt(TypeIdx, MaxTy);
1143 }
1144
1145 /// Widen the scalar to match the size of another.
1146 LegalizeRuleSet &minScalarSameAs(unsigned TypeIdx, unsigned LargeTypeIdx) {
1147 typeIdx(TypeIdx);
1148 return actionIf(
1149 LegalizeAction::WidenScalar,
1150 [=](const LegalityQuery &Query) {
1151 return Query.Types[LargeTypeIdx].getScalarSizeInBits() >
1152 Query.Types[TypeIdx].getSizeInBits();
1153 },
1154 LegalizeMutations::changeElementSizeTo(TypeIdx, LargeTypeIdx));
1155 }
1156
1157 /// Narrow the scalar to match the size of another.
1158 LegalizeRuleSet &maxScalarSameAs(unsigned TypeIdx, unsigned NarrowTypeIdx) {
1159 typeIdx(TypeIdx);
1160 return actionIf(
1161 LegalizeAction::NarrowScalar,
1162 [=](const LegalityQuery &Query) {
1163 return Query.Types[NarrowTypeIdx].getScalarSizeInBits() <
1164 Query.Types[TypeIdx].getSizeInBits();
1165 },
1166 LegalizeMutations::changeElementSizeTo(TypeIdx, NarrowTypeIdx));
1167 }
1168
1169 /// Change the type \p TypeIdx to have the same scalar size as type \p
1170 /// SameSizeIdx.
1171 LegalizeRuleSet &scalarSameSizeAs(unsigned TypeIdx, unsigned SameSizeIdx) {
1172 return minScalarSameAs(TypeIdx, SameSizeIdx)
1173 .maxScalarSameAs(TypeIdx, SameSizeIdx);
1174 }
1175
1176 /// Conditionally widen the scalar or elt to match the size of another.
1178 unsigned TypeIdx, unsigned LargeTypeIdx) {
1179 typeIdx(TypeIdx);
1180 return widenScalarIf(
1181 [=](const LegalityQuery &Query) {
1182 return Query.Types[LargeTypeIdx].getScalarSizeInBits() >
1183 Query.Types[TypeIdx].getScalarSizeInBits() &&
1184 Predicate(Query);
1185 },
1186 [=](const LegalityQuery &Query) {
1187 LLT T = Query.Types[LargeTypeIdx];
1188 if (T.isPointerVector())
1189 T = T.changeElementType(LLT::scalar(T.getScalarSizeInBits()));
1190 return std::make_pair(TypeIdx, T);
1191 });
1192 }
1193
1194 /// Conditionally narrow the scalar or elt to match the size of another.
1196 unsigned TypeIdx,
1197 unsigned SmallTypeIdx) {
1198 typeIdx(TypeIdx);
1199 return narrowScalarIf(
1200 [=](const LegalityQuery &Query) {
1201 return Query.Types[SmallTypeIdx].getScalarSizeInBits() <
1202 Query.Types[TypeIdx].getScalarSizeInBits() &&
1203 Predicate(Query);
1204 },
1205 [=](const LegalityQuery &Query) {
1206 LLT T = Query.Types[SmallTypeIdx];
1207 return std::make_pair(TypeIdx, T);
1208 });
1209 }
1210
1211 /// Add more elements to the vector to reach the next power of two.
1212 /// No effect if the type is not a vector or the element count is a power of
1213 /// two.
1215 using namespace LegalityPredicates;
1216 return actionIf(LegalizeAction::MoreElements,
1217 numElementsNotPow2(typeIdx(TypeIdx)),
1219 }
1220
1221 /// Limit the number of elements in EltTy vectors to at least MinElements.
1222 LegalizeRuleSet &clampMinNumElements(unsigned TypeIdx, const LLT EltTy,
1223 unsigned MinElements) {
1224 // Mark the type index as covered:
1225 typeIdx(TypeIdx);
1226 return actionIf(
1227 LegalizeAction::MoreElements,
1228 [=](const LegalityQuery &Query) {
1229 LLT VecTy = Query.Types[TypeIdx];
1230 return VecTy.isFixedVector() && VecTy.getElementType() == EltTy &&
1231 VecTy.getNumElements() < MinElements;
1232 },
1233 [=](const LegalityQuery &Query) {
1234 LLT VecTy = Query.Types[TypeIdx];
1235 return std::make_pair(
1236 TypeIdx, LLT::fixed_vector(MinElements, VecTy.getElementType()));
1237 });
1238 }
1239
1240 /// Set number of elements to nearest larger multiple of NumElts.
1241 LegalizeRuleSet &alignNumElementsTo(unsigned TypeIdx, const LLT EltTy,
1242 unsigned NumElts) {
1243 typeIdx(TypeIdx);
1244 return actionIf(
1245 LegalizeAction::MoreElements,
1246 [=](const LegalityQuery &Query) {
1247 LLT VecTy = Query.Types[TypeIdx];
1248 return VecTy.isFixedVector() && VecTy.getElementType() == EltTy &&
1249 (VecTy.getNumElements() % NumElts != 0);
1250 },
1251 [=](const LegalityQuery &Query) {
1252 LLT VecTy = Query.Types[TypeIdx];
1253 unsigned NewSize = alignTo(VecTy.getNumElements(), NumElts);
1254 return std::make_pair(
1255 TypeIdx, LLT::fixed_vector(NewSize, VecTy.getElementType()));
1256 });
1257 }
1258
1259 /// Limit the number of elements in EltTy vectors to at most MaxElements.
1260 LegalizeRuleSet &clampMaxNumElements(unsigned TypeIdx, const LLT EltTy,
1261 unsigned MaxElements) {
1262 // Mark the type index as covered:
1263 typeIdx(TypeIdx);
1264 return actionIf(
1265 LegalizeAction::FewerElements,
1266 [=](const LegalityQuery &Query) {
1267 LLT VecTy = Query.Types[TypeIdx];
1268 return VecTy.isFixedVector() && VecTy.getElementType() == EltTy &&
1269 VecTy.getNumElements() > MaxElements;
1270 },
1271 [=](const LegalityQuery &Query) {
1272 LLT VecTy = Query.Types[TypeIdx];
1273 LLT NewTy = LLT::scalarOrVector(ElementCount::getFixed(MaxElements),
1274 VecTy.getElementType());
1275 return std::make_pair(TypeIdx, NewTy);
1276 });
1277 }
1278 /// Limit the number of elements for the given vectors to at least MinTy's
1279 /// number of elements and at most MaxTy's number of elements.
1280 ///
1281 /// No effect if the type is not a vector or does not have the same element
1282 /// type as the constraints.
1283 /// The element type of MinTy and MaxTy must match.
1284 LegalizeRuleSet &clampNumElements(unsigned TypeIdx, const LLT MinTy,
1285 const LLT MaxTy) {
1286 assert(MinTy.getElementType() == MaxTy.getElementType() &&
1287 "Expected element types to agree");
1288
1289 assert((!MinTy.isScalableVector() && !MaxTy.isScalableVector()) &&
1290 "Unexpected scalable vectors");
1291
1292 const LLT EltTy = MinTy.getElementType();
1293 return clampMinNumElements(TypeIdx, EltTy, MinTy.getNumElements())
1294 .clampMaxNumElements(TypeIdx, EltTy, MaxTy.getNumElements());
1295 }
1296
1297 /// Express \p EltTy vectors strictly using vectors with \p NumElts elements
1298 /// (or scalars when \p NumElts equals 1).
1299 /// First pad with undef elements to nearest larger multiple of \p NumElts.
1300 /// Then perform split with all sub-instructions having the same type.
1301 /// Using clampMaxNumElements (non-strict) can result in leftover instruction
1302 /// with different type (fewer elements then \p NumElts or scalar).
1303 /// No effect if the type is not a vector.
1304 LegalizeRuleSet &clampMaxNumElementsStrict(unsigned TypeIdx, const LLT EltTy,
1305 unsigned NumElts) {
1306 return alignNumElementsTo(TypeIdx, EltTy, NumElts)
1307 .clampMaxNumElements(TypeIdx, EltTy, NumElts);
1308 }
1309
1310 /// Fallback on the previous implementation. This should only be used while
1311 /// porting a rule.
1313 add({always, LegalizeAction::UseLegacyRules});
1314 return *this;
1315 }
1316
1317 /// Check if there is no type index which is obviously not handled by the
1318 /// LegalizeRuleSet in any way at all.
1319 /// \pre Type indices of the opcode form a dense [0, \p NumTypeIdxs) set.
1320 LLVM_ABI bool verifyTypeIdxsCoverage(unsigned NumTypeIdxs) const;
1321 /// Check if there is no imm index which is obviously not handled by the
1322 /// LegalizeRuleSet in any way at all.
1323 /// \pre Type indices of the opcode form a dense [0, \p NumTypeIdxs) set.
1324 LLVM_ABI bool verifyImmIdxsCoverage(unsigned NumImmIdxs) const;
1325
1326 /// Apply the ruleset to the given LegalityQuery.
1327 LLVM_ABI LegalizeActionStep apply(const LegalityQuery &Query) const;
1328};
1329
1331public:
1332 virtual ~LegalizerInfo() = default;
1333
1335 return LegacyInfo;
1336 }
1338
1339 unsigned getOpcodeIdxForOpcode(unsigned Opcode) const;
1340 unsigned getActionDefinitionsIdx(unsigned Opcode) const;
1341
1342 /// Perform simple self-diagnostic and assert if there is anything obviously
1343 /// wrong with the actions set up.
1344 void verify(const MCInstrInfo &MII) const;
1345
1346 /// Get the action definitions for the given opcode. Use this to run a
1347 /// LegalityQuery through the definitions.
1348 const LegalizeRuleSet &getActionDefinitions(unsigned Opcode) const;
1349
1350 /// Get the action definition builder for the given opcode. Use this to define
1351 /// the action definitions.
1352 ///
1353 /// It is an error to request an opcode that has already been requested by the
1354 /// multiple-opcode variant.
1355 LegalizeRuleSet &getActionDefinitionsBuilder(unsigned Opcode);
1356
1357 /// Get the action definition builder for the given set of opcodes. Use this
1358 /// to define the action definitions for multiple opcodes at once. The first
1359 /// opcode given will be considered the representative opcode and will hold
1360 /// the definitions whereas the other opcodes will be configured to refer to
1361 /// the representative opcode. This lowers memory requirements and very
1362 /// slightly improves performance.
1363 ///
1364 /// It would be very easy to introduce unexpected side-effects as a result of
1365 /// this aliasing if it were permitted to request different but intersecting
1366 /// sets of opcodes but that is difficult to keep track of. It is therefore an
1367 /// error to request the same opcode twice using this API, to request an
1368 /// opcode that already has definitions, or to use the single-opcode API on an
1369 /// opcode that has already been requested by this API.
1371 getActionDefinitionsBuilder(std::initializer_list<unsigned> Opcodes);
1372 void aliasActionDefinitions(unsigned OpcodeTo, unsigned OpcodeFrom);
1373
1374 /// Determine what action should be taken to legalize the described
1375 /// instruction. Requires computeTables to have been called.
1376 ///
1377 /// \returns a description of the next legalization step to perform.
1378 LegalizeActionStep getAction(const LegalityQuery &Query) const;
1379
1380 /// Determine what action should be taken to legalize the given generic
1381 /// instruction.
1382 ///
1383 /// \returns a description of the next legalization step to perform.
1384 LegalizeActionStep getAction(const MachineInstr &MI,
1385 const MachineRegisterInfo &MRI) const;
1386
1387 bool isLegal(const LegalityQuery &Query) const {
1388 return getAction(Query).Action == LegalizeAction::Legal;
1389 }
1390
1391 bool isLegalOrCustom(const LegalityQuery &Query) const {
1392 auto Action = getAction(Query).Action;
1393 return Action == LegalizeAction::Legal || Action == LegalizeAction::Custom;
1394 }
1395
1396 bool isLegal(const MachineInstr &MI, const MachineRegisterInfo &MRI) const;
1397 bool isLegalOrCustom(const MachineInstr &MI,
1398 const MachineRegisterInfo &MRI) const;
1399
1400 /// Called for instructions with the Custom LegalizationAction.
1402 LostDebugLocObserver &LocObserver) const {
1403 llvm_unreachable("must implement this if custom action is used");
1404 }
1405
1406 /// \returns true if MI is either legal or has been legalized and false if not
1407 /// legal.
1408 /// Return true if MI is either legal or has been legalized and false
1409 /// if not legal.
1411 MachineInstr &MI) const {
1412 return true;
1413 }
1414
1415 /// Return the opcode (SEXT/ZEXT/ANYEXT) that should be performed while
1416 /// widening a constant of type SmallTy which targets can override.
1417 /// For eg, the DAG does (SmallTy.isByteSized() ? G_SEXT : G_ZEXT) which
1418 /// will be the default.
1419 virtual unsigned getExtOpcodeForWideningConstant(LLT SmallTy) const;
1420
1421private:
1422 static const int FirstOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_START;
1423 static const int LastOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_END;
1424
1425 LegalizeRuleSet RulesForOpcode[LastOp - FirstOp + 1];
1426 LegacyLegalizerInfo LegacyInfo;
1427};
1428
1429#ifndef NDEBUG
1430/// Checks that MIR is fully legal, returns an illegal instruction if it's not,
1431/// nullptr otherwise
1432const MachineInstr *machineFunctionIsIllegal(const MachineFunction &MF);
1433#endif
1434
1435} // end namespace llvm.
1436
1437#endif // LLVM_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Atomic ordering constants.
#define LLVM_ABI
Definition Compiler.h:213
IRTranslator LLVM IR MI
Interface for Targets to specify which operations they can successfully select and how the others sho...
Implement a low-level type suitable for MachineInstr level instruction selection.
#define T
nvptx lower args
#define P(N)
ppc ctr loops verify
PowerPC VSX FMA Mutation
This file implements the SmallBitVector class.
This file defines the SmallVector class.
Value * RHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:310
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
constexpr bool isScalar() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
static constexpr LLT scalarOrVector(ElementCount EC, LLT ScalarTy)
LegalizeRuleSet & minScalar(unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at least as wide as Ty.
LegalizeRuleSet & clampScalar(bool Pred, unsigned TypeIdx, const LLT MinTy, const LLT MaxTy)
LegalizeRuleSet & maxScalarSameAs(unsigned TypeIdx, unsigned NarrowTypeIdx)
Narrow the scalar to match the size of another.
LegalizeRuleSet & widenScalarOrEltToNextPow2OrMinSize(unsigned TypeIdx, unsigned MinSize=0)
Widen the scalar or vector element type to the next power of two that is at least MinSize.
LegalizeRuleSet & customForCartesianProduct(bool Pred, std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1)
The instruction is custom when the predicate is true and type indexes 0 and 1 are all in their respec...
LegalizeRuleSet & legalFor(std::initializer_list< LLT > Types)
The instruction is legal when type index 0 is any type in the given list.
LegalizeRuleSet & maxScalarEltSameAsIf(LegalityPredicate Predicate, unsigned TypeIdx, unsigned SmallTypeIdx)
Conditionally narrow the scalar or elt to match the size of another.
LegalizeRuleSet & unsupported()
The instruction is unsupported.
LegalizeRuleSet & legalFor(bool Pred, std::initializer_list< std::tuple< LLT, LLT, LLT > > Types)
LegalizeRuleSet & scalarSameSizeAs(unsigned TypeIdx, unsigned SameSizeIdx)
Change the type TypeIdx to have the same scalar size as type SameSizeIdx.
LegalizeRuleSet & fewerElementsIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
Remove elements to reach the type selected by the mutation if the predicate is true.
LegalizeRuleSet & clampScalarOrElt(unsigned TypeIdx, const LLT MinTy, const LLT MaxTy)
Limit the range of scalar sizes to MinTy and MaxTy.
void aliasTo(unsigned Opcode)
LegalizeRuleSet & bitcastIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
The specified type index is coerced if predicate is true.
LegalizeRuleSet & libcall()
The instruction is emitted as a library call.
LegalizeRuleSet & libcallFor(std::initializer_list< LLT > Types)
LLVM_ABI 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...
LegalizeRuleSet & maxScalar(unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at most as wide as Ty.
LegalizeRuleSet & minScalarOrElt(unsigned TypeIdx, const LLT Ty)
Ensure the scalar or element is at least as wide as Ty.
LegalizeRuleSet & clampMaxNumElements(unsigned TypeIdx, const LLT EltTy, unsigned MaxElements)
Limit the number of elements in EltTy vectors to at most MaxElements.
LegalizeRuleSet & clampMinNumElements(unsigned TypeIdx, const LLT EltTy, unsigned MinElements)
Limit the number of elements in EltTy vectors to at least MinElements.
LegalizeRuleSet & libcallForCartesianProduct(std::initializer_list< LLT > Types)
LegalizeRuleSet & unsupportedFor(std::initializer_list< LLT > Types)
LegalizeRuleSet & legalFor(bool Pred, std::initializer_list< LLT > Types)
LegalizeRuleSet & widenVectorEltsToVectorMinSize(unsigned TypeIdx, unsigned VectorSize)
Ensure the vector size is at least as wide as VectorSize by promoting the element.
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.
LegalizeRuleSet & lowerIfMemSizeNotPow2()
Lower a memory operation if the memory size, rounded to bytes, is not a power of 2.
LegalizeRuleSet & lowerFor(std::initializer_list< LLT > Types, LegalizeMutation Mutation)
The instruction is lowered when type index 0 is any type in the given list.
LegalizeRuleSet & minScalarEltSameAsIf(LegalityPredicate Predicate, unsigned TypeIdx, unsigned LargeTypeIdx)
Conditionally widen the scalar or elt to match the size of another.
LegalizeRuleSet & customForCartesianProduct(std::initializer_list< LLT > Types)
LegalizeRuleSet & lowerIfMemSizeNotByteSizePow2()
Lower a memory operation if the memory access size is not a round power of 2 byte size.
LegalizeRuleSet & minScalar(bool Pred, unsigned TypeIdx, const LLT Ty)
LegalizeRuleSet & moreElementsToNextPow2(unsigned TypeIdx)
Add more elements to the vector to reach the next power of two.
LegalizeRuleSet & customForCartesianProduct(std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1)
The instruction is custom when type indexes 0 and 1 are both in their respective lists.
LegalizeRuleSet & legalForTypeWithAnyImm(std::initializer_list< std::pair< LLT, LLT > > Types)
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.
LegalizeRuleSet & narrowScalarIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
Narrow the scalar to the one selected by the mutation if the predicate is true.
LegalizeRuleSet & lower()
The instruction is lowered.
LegalizeRuleSet & moreElementsIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
Add more elements to reach the type selected by the mutation if the predicate is true.
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...
LegalizeRuleSet & narrowScalar(unsigned TypeIdx, LegalizeMutation Mutation)
LegalizeRuleSet & customFor(bool Pred, std::initializer_list< std::pair< LLT, LLT > > Types)
LegalizeRuleSet & lowerFor(std::initializer_list< LLT > Types)
The instruction is lowered when type index 0 is any type in the given list.
LegalizeRuleSet & scalarizeIf(LegalityPredicate Predicate, unsigned TypeIdx)
LegalizeRuleSet & lowerIf(LegalityPredicate Predicate)
The instruction is lowered if predicate is true.
LegalizeRuleSet & clampScalar(unsigned TypeIdx, const LLT MinTy, const LLT MaxTy)
Limit the range of scalar sizes to MinTy and MaxTy.
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.
LegalizeRuleSet & alignNumElementsTo(unsigned TypeIdx, const LLT EltTy, unsigned NumElts)
Set number of elements to nearest larger multiple of NumElts.
LegalizeRuleSet & custom()
Unconditionally custom lower.
LegalizeRuleSet & libcallForCartesianProduct(std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1)
LegalizeRuleSet & clampMaxNumElementsStrict(unsigned TypeIdx, const LLT EltTy, unsigned NumElts)
Express EltTy vectors strictly using vectors with NumElts elements (or scalars when NumElts equals 1)...
LegalizeRuleSet & minScalarSameAs(unsigned TypeIdx, unsigned LargeTypeIdx)
Widen the scalar to match the size of another.
LegalizeRuleSet & unsupportedIf(LegalityPredicate Predicate)
LegalizeRuleSet & minScalarOrEltIf(LegalityPredicate Predicate, unsigned TypeIdx, const LLT Ty)
Ensure the scalar or element is at least as wide as Ty.
LegalizeRuleSet & widenScalarIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
Widen the scalar to the one selected by the mutation if the predicate is true.
LegalizeRuleSet & libcallFor(std::initializer_list< std::pair< LLT, LLT > > Types)
LegalizeRuleSet & customFor(bool Pred, std::initializer_list< LLT > Types)
LegalizeRuleSet & fallback()
Fallback on the previous implementation.
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.
LegalizeRuleSet & lowerForCartesianProduct(std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1, std::initializer_list< LLT > Types2)
The instruction is lowered when type indexes 0, 1, and 2 are all in their respective lists.
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.
LegalizeRuleSet & libcallFor(bool Pred, std::initializer_list< LLT > Types)
LegalizeRuleSet & libcallFor(bool Pred, std::initializer_list< std::pair< LLT, LLT > > Types)
LegalizeRuleSet & alwaysLegal()
LegalizeRuleSet & legalFor(bool Pred, std::initializer_list< std::pair< LLT, LLT > > Types)
unsigned getAlias() const
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...
LegalizeRuleSet & unsupportedIfMemSizeNotPow2()
LegalizeRuleSet & maxScalarIf(LegalityPredicate Predicate, unsigned TypeIdx, const LLT Ty)
Conditionally limit the maximum size of the scalar.
LegalizeRuleSet & customIf(LegalityPredicate Predicate)
LegalizeRuleSet & customForCartesianProduct(std::initializer_list< LLT > Types0, std::initializer_list< LLT > Types1, std::initializer_list< LLT > Types2)
The instruction is custom when type indexes 0, 1, and 2 are all in their respective lists.
LegalizeRuleSet & widenScalarToNextPow2(unsigned TypeIdx, unsigned MinSize=0)
Widen the scalar to the next power of two that is at least MinSize.
LegalizeRuleSet & scalarize(unsigned TypeIdx)
LegalizeRuleSet & legalForCartesianProduct(std::initializer_list< LLT > Types)
The instruction is legal when type indexes 0 and 1 are both in the given list.
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.
LegalizeRuleSet & lowerIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
The instruction is lowered if predicate is true.
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...
LegalizeRuleSet & libcallIf(LegalityPredicate Predicate)
Like legalIf, but for the Libcall action.
LegalizeRuleSet & maxScalarOrElt(unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at most as wide as Ty.
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.
LegalizeRuleSet & minScalarIf(LegalityPredicate Predicate, unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at least as wide as Ty if condition is met.
unsigned immIdx(unsigned ImmIdx)
LLVM_ABI 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...
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.
LLVM_ABI LegalizeActionStep apply(const LegalityQuery &Query) const
Apply the ruleset to the given LegalityQuery.
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.
LegalizeRuleSet & legalIf(LegalityPredicate Predicate)
The instruction is legal if predicate is true.
LegalizeRuleSet & customFor(std::initializer_list< LLT > Types)
LegalizeRuleSet & widenScalarToNextMultipleOf(unsigned TypeIdx, unsigned Size)
Widen the scalar to the next multiple of Size.
A single rule in a legalizer info ruleset.
std::pair< unsigned, LLT > determineMutation(const LegalityQuery &Query) const
Determine the change to make.
bool match(const LegalityQuery &Query) const
Test whether the LegalityQuery matches.
LegalizeRule(LegalityPredicate Predicate, LegalizeAction Action, LegalizeMutation Mutation=nullptr)
LegalizeAction getAction() const
virtual ~LegalizerInfo()=default
const LegacyLegalizerInfo & getLegacyLegalizerInfo() const
LegacyLegalizerInfo & getLegacyLegalizerInfo()
bool isLegalOrCustom(const LegalityQuery &Query) const
virtual bool legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI, LostDebugLocObserver &LocObserver) const
Called for instructions with the Custom LegalizationAction.
bool isLegal(const LegalityQuery &Query) const
virtual bool legalizeIntrinsic(LegalizerHelper &Helper, MachineInstr &MI) const
LegalizeActionStep getAction(const LegalityQuery &Query) const
Determine what action should be taken to legalize the described instruction.
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
Representation of each machine instruction.
A description of a memory reference used in the backend.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI 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 ...
LLVM_ABI LegalityPredicate isScalar(unsigned TypeIdx)
True iff the specified type index is a scalar.
LLVM_ABI LegalityPredicate memSizeInBytesNotPow2(unsigned MMOIdx)
True iff the specified MMO index has a size (rounded to bytes) that is not a power of 2.
LLVM_ABI LegalityPredicate numElementsNotPow2(unsigned TypeIdx)
True iff the specified type index is a vector whose element count is not a power of 2.
LLVM_ABI LegalityPredicate isPointerVector(unsigned TypeIdx)
True iff the specified type index is a vector of pointers (with any address space).
LLVM_ABI LegalityPredicate isPointer(unsigned TypeIdx)
True iff the specified type index is a pointer (with any address space).
LLVM_ABI LegalityPredicate typeInSet(unsigned TypeIdx, std::initializer_list< LLT > TypesInit)
True iff the given type index is one of the specified types.
LLVM_ABI LegalityPredicate smallerThan(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the first type index has a smaller total bit size than second type index.
LLVM_ABI LegalityPredicate atomicOrderingAtLeastOrStrongerThan(unsigned MMOIdx, AtomicOrdering Ordering)
True iff the specified MMO index has at an atomic ordering of at Ordering or stronger.
LLVM_ABI LegalityPredicate scalarOrEltSizeNotPow2(unsigned TypeIdx)
True iff the specified type index is a scalar or vector whose element size is not a power of 2.
LLVM_ABI LegalityPredicate largerThan(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the first type index has a larger total bit size than second type index.
LLVM_ABI 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.
LLVM_ABI LegalityPredicate memSizeNotByteSizePow2(unsigned MMOIdx)
True iff the specified MMO index has a size that is not an even byte size, or that even byte size is ...
Predicate any(Predicate P0, Predicate P1)
True iff P0 or P1 are true.
LLVM_ABI LegalityPredicate elementTypeIs(unsigned TypeIdx, LLT EltTy)
True if the type index is a vector with element type EltTy.
LLVM_ABI LegalityPredicate sameSize(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the specified type indices are both the same bit size.
LLVM_ABI 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...
LLVM_ABI LegalityPredicate sizeIs(unsigned TypeIdx, unsigned Size)
True if the total bitwidth of the specified type index is Size bits.
LegalityPredicate typeIsNot(unsigned TypeIdx, LLT Type)
True iff the given type index is not the specified type.
LLVM_ABI LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
LLVM_ABI LegalityPredicate sizeNotPow2(unsigned TypeIdx)
True iff the specified type index is a scalar whose size is not a power of.
LLVM_ABI LegalityPredicate typeTupleInSet(unsigned TypeIdx0, unsigned TypeIdx1, unsigned Type2, std::initializer_list< std::tuple< LLT, LLT, LLT > > TypesInit)
True iff the given types for the given tuple of type indexes is one of the specified type tuple.
Predicate all(Predicate P0, Predicate P1)
True iff P0 and P1 are true.
LLVM_ABI 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.
LLVM_ABI LegalityPredicate sizeNotMultipleOf(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar whose size is not a multiple of Size.
LLVM_ABI LegalityPredicate typeIs(unsigned TypeIdx, LLT TypesInit)
True iff the given type index is the specified type.
Predicate predNot(Predicate P)
True iff P is false.
LLVM_ABI LegalityPredicate scalarWiderThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that's wider than the given size.
LLVM_ABI LegalityPredicate scalarNarrowerThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that's narrower than the given size.
@ FewerElements
The (vector) operation should be implemented by splitting it into sub-vectors where the operation is ...
@ Legal
The operation is expected to be selectable directly by the target, and no transformation is necessary...
@ Libcall
The operation should be implemented as a call to some kind of runtime support library.
@ Unsupported
This operation is completely unsupported on the target.
@ Lower
The operation itself must be expressed in terms of simpler actions on this target.
@ UseLegacyRules
Fall back onto the old rules.
@ WidenScalar
The operation should be implemented in terms of a wider scalar base-type.
@ Bitcast
Perform the operation on a different, but equivalently sized type.
@ NarrowScalar
The operation should be synthesized from multiple instructions acting on a narrower scalar base-type.
@ Custom
The target wants to do something special with this combination of operand and type.
@ NotFound
Sentinel value for when no action was found in the specified table.
@ MoreElements
The (vector) operation should be implemented by widening the input vector and ignoring the lanes adde...
LLVM_ABI LegalizeMutation moreElementsToNextPow2(unsigned TypeIdx, unsigned Min=0)
Add more elements to the type for the given type index to the next power of.
LLVM_ABI LegalizeMutation changeElementCountTo(unsigned TypeIdx, unsigned FromTypeIdx)
Keep the same scalar or element type as TypeIdx, but take the number of elements from FromTypeIdx.
LLVM_ABI LegalizeMutation scalarize(unsigned TypeIdx)
Break up the vector type for the given type index into the element type.
LLVM_ABI LegalizeMutation changeElementTo(unsigned TypeIdx, unsigned FromTypeIdx)
Keep the same scalar or element type as the given type index.
LLVM_ABI 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.
LLVM_ABI LegalizeMutation changeTo(unsigned TypeIdx, LLT Ty)
Select this specific type for the given type index.
LLVM_ABI LegalizeMutation widenScalarOrEltToNextMultipleOf(unsigned TypeIdx, unsigned Size)
Widen the scalar type or vector element type for the given type index to next multiple of Size.
LLVM_ABI LegalizeMutation changeElementSizeTo(unsigned TypeIdx, unsigned FromTypeIdx)
Change the scalar size or element size to have the same scalar size as type index FromIndex.
@ OPERAND_LAST_GENERIC
Definition MCInstrDesc.h:74
@ OPERAND_FIRST_GENERIC
Definition MCInstrDesc.h:67
@ OPERAND_FIRST_GENERIC_IMM
Definition MCInstrDesc.h:76
@ OPERAND_LAST_GENERIC_IMM
Definition MCInstrDesc.h:78
This is an optimization pass for GlobalISel generic memory operations.
MaybeAlign getAlign(const CallInst &I, unsigned Index)
std::function< std::pair< unsigned, LLT >(const LegalityQuery &)> LegalizeMutation
std::function< bool(const LegalityQuery &)> LegalityPredicate
LLVM_ABI cl::opt< bool > DisableGISelLegalityCheck
const MachineInstr * machineFunctionIsIllegal(const MachineFunction &MF)
Checks that MIR is fully legal, returns an illegal instruction if it's not, nullptr otherwise.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Other
Any other memory.
Definition ModRef.h:68
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
LegacyLegalizeActions::LegacyLegalizeAction Action
The action to take or the final answer.
bool operator==(const TypePairAndMemDesc &Other) const
bool isCompatible(const TypePairAndMemDesc &Other) const
MemDesc(const MachineMemOperand &MMO)
MemDesc(LLT MemoryTy, uint64_t AlignInBits, AtomicOrdering Ordering, AtomicOrdering FailureOrdering)
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
ArrayRef< MemDesc > MMODescrs
Operations which require memory can use this to place requirements on the memory type for each MMO.
ArrayRef< LLT > Types
LLVM_ABI raw_ostream & print(raw_ostream &OS) const
constexpr LegalityQuery(unsigned Opcode, ArrayRef< LLT > Types, ArrayRef< MemDesc > MMODescrs={})
The result of a query.
LegalizeAction Action
The action to take or the final answer.
LegalizeActionStep(LegacyLegalizeActionStep Step)
LLT NewType
If describing an action, the new type for TypeIdx. Otherwise LLT{}.
unsigned TypeIdx
If describing an action, the type index to change. Otherwise zero.
LegalizeActionStep(LegalizeAction Action, unsigned TypeIdx, const LLT NewType)
bool operator==(const LegalizeActionStep &RHS) const