14#ifndef LLVM_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
15#define LLVM_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
123 MMO.getSuccessOrdering(), MMO.getFailureOrdering()) {}
158 std::tie(
RHS.Action,
RHS.TypeIdx,
RHS.NewType);
164 std::function<std::pair<unsigned, LLT>(
const LegalityQuery &)>;
185 MemTy.getSizeInBits() ==
Other.MemTy.getSizeInBits();
195template<
typename Predicate>
198 return P0(Query) && P1(Query);
202template<
typename Predicate,
typename... Args>
208template<
typename Predicate>
211 return P0(Query) || P1(Query);
215template<
typename Predicate,
typename... Args>
224 std::initializer_list<LLT> TypesInit);
229 return Query.Types[TypeIdx] !=
Type;
237 std::initializer_list<std::pair<LLT, LLT>> TypesInit);
241typeTupleInSet(
unsigned TypeIdx0,
unsigned TypeIdx1,
unsigned Type2,
242 std::initializer_list<std::tuple<LLT, LLT, LLT>> TypesInit);
246 unsigned TypeIdx0,
unsigned TypeIdx1,
unsigned MMOIdx,
247 std::initializer_list<TypePairAndMemDesc> TypesAndMemDescInit);
338 std::initializer_list<int64_t> ImmsInit);
352 unsigned FromTypeIdx);
360 unsigned FromTypeIdx);
371 unsigned FromTypeIdx);
408 : Predicate(Predicate), Action(Action), Mutation(Mutation) {}
412 return Predicate(Query);
421 return std::make_pair(0,
LLT{});
427 unsigned AliasOf = 0;
429 bool IsAliasedByAnother =
false;
446 unsigned typeIdx(
unsigned TypeIdx) {
449 "Type Index is out of bounds");
451 TypeIdxsCovered.set(TypeIdx);
456 void markAllIdxsAsCovered() {
458 TypeIdxsCovered.set();
459 ImmIdxsCovered.set();
465 "RuleSet is aliased, change the representative opcode instead");
466 Rules.push_back(Rule);
488 std::initializer_list<LLT> Types) {
490 return actionIf(Action, typeInSet(typeIdx(0), Types));
495 std::initializer_list<LLT> Types,
498 return actionIf(Action, typeInSet(typeIdx(0), Types),
Mutation);
504 std::initializer_list<std::pair<LLT, LLT>> Types) {
506 return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types));
511 std::initializer_list<std::tuple<LLT, LLT, LLT>> Types) {
513 return actionIf(Action,
514 typeTupleInSet(typeIdx(0), typeIdx(1), typeIdx(2), Types));
521 std::initializer_list<std::pair<LLT, LLT>> Types,
524 return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types),
531 std::initializer_list<LLT> Types) {
534 return actionIf(Action, typeInSet(typeIdx(0), Types));
538 LegalizeAction Action, std::initializer_list<std::pair<LLT, LLT>> Types) {
541 return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types));
548 std::initializer_list<LLT> Types) {
550 return actionIf(Action, all(typeInSet(typeIdx(0), Types),
551 typeInSet(typeIdx(1), Types)));
559 std::initializer_list<LLT> Types0,
560 std::initializer_list<LLT> Types1) {
562 return actionIf(Action, all(typeInSet(typeIdx(0), Types0),
563 typeInSet(typeIdx(1), Types1)));
571 std::initializer_list<LLT> Types1, std::initializer_list<LLT> Types2) {
573 return actionIf(Action, all(typeInSet(typeIdx(0), Types0),
574 all(typeInSet(typeIdx(1), Types1),
575 typeInSet(typeIdx(2), Types2))));
584 assert((AliasOf == 0 || AliasOf == Opcode) &&
585 "Opcode is already aliased to another opcode");
586 assert(Rules.empty() &&
"Aliasing will discard rules");
594 "Imm Index is out of bounds");
596 ImmIdxsCovered.set(ImmIdx);
605 markAllIdxsAsCovered();
606 return actionIf(LegalizeAction::Legal,
Predicate);
610 return actionFor(LegalizeAction::Legal, Types);
615 return actionFor(LegalizeAction::Legal, Types);
620 return actionFor(LegalizeAction::Legal, Types);
623 std::initializer_list<std::pair<LLT, LLT>> Types) {
626 return actionFor(LegalizeAction::Legal, Types);
629 legalFor(
bool Pred, std::initializer_list<std::tuple<LLT, LLT, LLT>> Types) {
632 return actionFor(LegalizeAction::Legal, Types);
637 markAllIdxsAsCovered();
638 return actionForTypeWithAnyImm(LegalizeAction::Legal, Types);
642 std::initializer_list<std::pair<LLT, LLT>> Types) {
643 markAllIdxsAsCovered();
644 return actionForTypeWithAnyImm(LegalizeAction::Legal, Types);
650 std::initializer_list<LegalityPredicates::TypePairAndMemDesc>
652 return actionIf(LegalizeAction::Legal,
654 typeIdx(0), typeIdx(1), 0, TypesAndMemDesc));
657 bool Pred, std::initializer_list<LegalityPredicates::TypePairAndMemDesc>
661 return actionIf(LegalizeAction::Legal,
663 typeIdx(0), typeIdx(1), 0, TypesAndMemDesc));
668 return actionForCartesianProduct(LegalizeAction::Legal, Types);
673 std::initializer_list<LLT> Types1) {
674 return actionForCartesianProduct(LegalizeAction::Legal, Types0, Types1);
679 std::initializer_list<LLT> Types1,
680 std::initializer_list<LLT> Types2) {
681 return actionForCartesianProduct(LegalizeAction::Legal, Types0, Types1,
687 markAllIdxsAsCovered();
688 return actionIf(LegalizeAction::Legal, always);
696 markAllIdxsAsCovered();
705 markAllIdxsAsCovered();
706 return actionIf(LegalizeAction::Lower, always);
714 markAllIdxsAsCovered();
715 return actionIf(LegalizeAction::Lower,
Predicate);
722 markAllIdxsAsCovered();
728 return actionFor(LegalizeAction::Lower, Types);
734 return actionFor(LegalizeAction::Lower, Types,
Mutation);
739 return actionFor(LegalizeAction::Lower, Types);
744 std::initializer_list<std::pair<LLT, LLT>> Types) {
747 return actionFor(LegalizeAction::Lower, Types);
753 return actionFor(LegalizeAction::Lower, Types,
Mutation);
758 std::initializer_list<LLT> Types1) {
760 return actionForCartesianProduct(LegalizeAction::Lower, Types0, Types1);
765 std::initializer_list<LLT> Types1,
766 std::initializer_list<LLT> Types2) {
768 return actionForCartesianProduct(LegalizeAction::Lower, Types0, Types1,
777 markAllIdxsAsCovered();
778 return actionIf(LegalizeAction::Libcall, always);
785 markAllIdxsAsCovered();
786 return actionIf(LegalizeAction::Libcall,
Predicate);
789 return actionFor(LegalizeAction::Libcall, Types);
794 return actionFor(LegalizeAction::Libcall, Types);
797 libcallFor(std::initializer_list<std::pair<LLT, LLT>> Types) {
798 return actionFor(LegalizeAction::Libcall, Types);
801 libcallFor(
bool Pred, std::initializer_list<std::pair<LLT, LLT>> Types) {
804 return actionFor(LegalizeAction::Libcall, Types);
808 return actionForCartesianProduct(LegalizeAction::Libcall, Types);
812 std::initializer_list<LLT> Types1) {
813 return actionForCartesianProduct(LegalizeAction::Libcall, Types0, Types1);
822 markAllIdxsAsCovered();
829 return actionFor(LegalizeAction::WidenScalar, Types,
Mutation);
836 return actionFor(LegalizeAction::WidenScalar, Types,
Mutation);
845 markAllIdxsAsCovered();
853 return actionFor(LegalizeAction::NarrowScalar, Types,
Mutation);
862 markAllIdxsAsCovered();
871 markAllIdxsAsCovered();
877 markAllIdxsAsCovered();
878 return actionIf(LegalizeAction::Unsupported, always);
881 return actionIf(LegalizeAction::Unsupported,
Predicate);
885 return actionFor(LegalizeAction::Unsupported, Types);
889 return actionIf(LegalizeAction::Unsupported,
897 return actionIf(LegalizeAction::Lower,
905 return actionIf(LegalizeAction::Lower,
912 markAllIdxsAsCovered();
913 return actionIf(LegalizeAction::Custom,
Predicate);
916 return actionFor(LegalizeAction::Custom, Types);
921 return actionFor(LegalizeAction::Custom, Types);
927 return actionFor(LegalizeAction::Custom, Types);
930 std::initializer_list<std::pair<LLT, LLT>> Types) {
933 return actionFor(LegalizeAction::Custom, Types);
937 return actionForCartesianProduct(LegalizeAction::Custom, Types);
943 std::initializer_list<LLT> Types1) {
944 return actionForCartesianProduct(LegalizeAction::Custom, Types0, Types1);
950 std::initializer_list<LLT> Types1,
951 std::initializer_list<LLT> Types2) {
952 return actionForCartesianProduct(LegalizeAction::Custom, Types0, Types1,
960 std::initializer_list<LLT> Types1) {
963 return actionForCartesianProduct(LegalizeAction::Custom, Types0, Types1);
975 unsigned MinSize = 0) {
978 LegalizeAction::WidenScalar, sizeNotPow2(typeIdx(TypeIdx)),
988 LegalizeAction::WidenScalar, sizeNotMultipleOf(typeIdx(TypeIdx),
Size),
995 unsigned MinSize = 0) {
998 LegalizeAction::WidenScalar, scalarOrEltSizeNotPow2(typeIdx(TypeIdx)),
1005 unsigned MinSize = 0) {
1008 LegalizeAction::WidenScalar,
1009 any(scalarOrEltNarrowerThan(TypeIdx, MinSize),
1010 scalarOrEltSizeNotPow2(typeIdx(TypeIdx))),
1016 return actionIf(LegalizeAction::NarrowScalar, isScalar(typeIdx(TypeIdx)),
1022 return actionIf(LegalizeAction::FewerElements, isVector(typeIdx(TypeIdx)),
1028 return actionIf(LegalizeAction::FewerElements,
1029 all(
Predicate, isVector(typeIdx(TypeIdx))),
1037 return actionIf(LegalizeAction::WidenScalar,
1038 scalarOrEltNarrowerThan(TypeIdx, Ty.getScalarSizeInBits()),
1039 changeElementSizeTo(typeIdx(TypeIdx), Ty));
1044 unsigned TypeIdx,
const LLT Ty) {
1047 return actionIf(LegalizeAction::WidenScalar,
1049 TypeIdx, Ty.getScalarSizeInBits())),
1050 changeElementSizeTo(typeIdx(TypeIdx), Ty));
1056 unsigned VectorSize) {
1060 LegalizeAction::WidenScalar,
1062 const LLT VecTy = Query.
Types[TypeIdx];
1066 const LLT VecTy = Query.
Types[TypeIdx];
1068 unsigned MinSize = VectorSize / NumElts;
1071 return std::make_pair(TypeIdx, NewTy);
1079 return actionIf(LegalizeAction::WidenScalar,
1080 scalarNarrowerThan(TypeIdx, Ty.getSizeInBits()),
1081 changeElementSizeTo(typeIdx(TypeIdx), Ty));
1095 LegalizeAction::WidenScalar,
1097 const LLT QueryTy = Query.
Types[TypeIdx];
1102 changeElementSizeTo(typeIdx(TypeIdx), Ty));
1109 return actionIf(LegalizeAction::NarrowScalar,
1110 scalarOrEltWiderThan(TypeIdx, Ty.getScalarSizeInBits()),
1111 changeElementSizeTo(typeIdx(TypeIdx), Ty));
1118 return actionIf(LegalizeAction::NarrowScalar,
1119 scalarWiderThan(TypeIdx, Ty.getSizeInBits()),
1120 changeElementSizeTo(typeIdx(TypeIdx), Ty));
1131 LegalizeAction::NarrowScalar,
1133 const LLT QueryTy = Query.
Types[TypeIdx];
1138 changeElementSizeTo(typeIdx(TypeIdx), Ty));
1165 LegalizeAction::WidenScalar,
1167 return Query.
Types[LargeTypeIdx].getScalarSizeInBits() >
1168 Query.
Types[TypeIdx].getSizeInBits();
1177 LegalizeAction::NarrowScalar,
1179 return Query.
Types[NarrowTypeIdx].getScalarSizeInBits() <
1180 Query.
Types[TypeIdx].getSizeInBits();
1194 unsigned TypeIdx,
unsigned LargeTypeIdx) {
1198 return Query.
Types[LargeTypeIdx].getScalarSizeInBits() >
1199 Query.
Types[TypeIdx].getScalarSizeInBits() &&
1203 LLT T = Query.
Types[TypeIdx].changeElementSize(
1204 Query.
Types[LargeTypeIdx].getScalarSizeInBits());
1205 return std::make_pair(TypeIdx,
T);
1212 unsigned SmallTypeIdx) {
1216 return Query.
Types[SmallTypeIdx].getScalarSizeInBits() <
1217 Query.
Types[TypeIdx].getScalarSizeInBits() &&
1222 return std::make_pair(TypeIdx,
T);
1231 return actionIf(LegalizeAction::MoreElements,
1232 numElementsNotPow2(typeIdx(TypeIdx)),
1238 unsigned MinElements) {
1242 LegalizeAction::MoreElements,
1250 return std::make_pair(
1260 LegalizeAction::MoreElements,
1269 return std::make_pair(
1276 unsigned MaxElements) {
1280 LegalizeAction::FewerElements,
1290 return std::make_pair(TypeIdx, NewTy);
1302 "Expected element types to agree");
1305 "Unexpected scalable vectors");
1391 return getAction(Query).Action == LegalizeAction::Legal;
1396 return Action == LegalizeAction::Legal || Action == LegalizeAction::Custom;
1422 virtual unsigned getExtOpcodeForWideningConstant(
LLT SmallTy)
const;
1425 static const int FirstOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_START;
1426 static const int LastOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_END;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Atomic ordering constants.
static MaybeAlign getAlign(Value *Ptr)
Implement a low-level type suitable for MachineInstr level instruction selection.
This file implements the SmallBitVector class.
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
static constexpr ElementCount getFixed(ScalarTy MinVal)
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
constexpr bool isScalar() const
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.
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.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
static constexpr LLT scalarOrVector(ElementCount EC, LLT ScalarTy)
LLT changeElementSize(unsigned NewEltSize) const
If this type is a vector, return a vector with the same number of elements but the new element size.
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 & lowerFor(bool Pred, 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 & 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()=default
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 & widenScalarFor(std::initializer_list< LLT > Types, LegalizeMutation Mutation)
Widen the scalar, specified in mutation, when type index 0 is any type in the given list.
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.
bool isAliasedByAnother()
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 & widenScalarFor(std::initializer_list< std::pair< LLT, LLT > > Types, LegalizeMutation Mutation)
Widen the scalar, specified in mutation, when type indexes 0 and 1 is any type pair in the given list...
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 & 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 & legalForTypesWithMemDesc(bool Pred, std::initializer_list< LegalityPredicates::TypePairAndMemDesc > TypesAndMemDesc)
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)
void setIsAliasedByAnother()
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
const LegalizeRuleSet & getActionDefinitions(unsigned Opcode) const
Get the action definitions for the given opcode.
virtual ~LegalizerInfo()=default
LegalizeRuleSet & getActionDefinitionsBuilder(unsigned Opcode)
Get the action definition builder for the given opcode.
bool isLegalOrCustom(const LegalityQuery &Query) const
void aliasActionDefinitions(unsigned OpcodeTo, unsigned OpcodeFrom)
virtual bool legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI, LostDebugLocObserver &LocObserver) const
Called for instructions with the Custom LegalizationAction.
unsigned getOpcodeIdxForOpcode(unsigned Opcode) const
bool isLegal(const LegalityQuery &Query) const
unsigned getActionDefinitionsIdx(unsigned Opcode) 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.
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.
This class implements an extremely fast bulk output stream that can only output to a stream.
#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 vectorElementCountIsLessThanOrEqualTo(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a vector with a number of elements that's less than or equal to ...
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 immIs(unsigned ImmIdx, int64_t Imm)
True iff the immediate at the given index has the specified value.
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 vectorElementCountIsGreaterThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a vector with a number of elements that's greater than the given...
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 immIsNot(unsigned ImmIdx, int64_t Imm)
True iff the immediate at the given index does not have the specified value.
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 immInSet(unsigned ImmIdx, std::initializer_list< int64_t > ImmsInit)
True iff the immediate at the given index has one of the specified values.
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.
@ 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_FIRST_GENERIC_IMM
@ OPERAND_LAST_GENERIC_IMM
This is an optimization pass for GlobalISel generic memory operations.
std::function< std::pair< unsigned, LLT >(const LegalityQuery &)> LegalizeMutation
std::function< bool(const LegalityQuery &)> LegalityPredicate
LLVM_ABI cl::opt< bool > DisableGISelLegalityCheck
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
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.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
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)
AtomicOrdering FailureOrdering
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
ArrayRef< int64_t > Immediates
ArrayRef< MemDesc > MMODescrs
Operations which require memory can use this to place requirements on the memory type for each MMO.
constexpr LegalityQuery(unsigned Opcode, ArrayRef< LLT > Types, ArrayRef< MemDesc > MMODescrs={}, ArrayRef< int64_t > Immediates={})
LLVM_ABI raw_ostream & print(raw_ostream &OS) const
LegalizeAction Action
The action to take or the final answer.
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