14#ifndef LLVM_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
15#define LLVM_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
39class MachineRegisterInfo;
42namespace LegalizeActions {
123 Ordering(MMO.getSuccessOrdering()) {}
136 raw_ostream &
print(raw_ostream &
OS)
const;
195 std::tie(
RHS.Action,
RHS.TypeIdx,
RHS.NewType);
201 std::function<std::pair<unsigned, LLT>(
const LegalityQuery &)>;
203namespace LegalityPredicates {
227template<
typename Predicate>
228Predicate
all(Predicate P0, Predicate P1) {
230 return P0(Query) && P1(Query);
234template<
typename Predicate,
typename... Args>
235Predicate
all(Predicate P0, Predicate P1, Args...
args) {
240template<
typename Predicate>
241Predicate
any(Predicate P0, Predicate P1) {
243 return P0(Query) || P1(Query);
247template<
typename Predicate,
typename... Args>
248Predicate
any(Predicate P0, Predicate P1, Args...
args) {
256 std::initializer_list<LLT> TypesInit);
261 return Query.Types[TypeIdx] !=
Type;
269 std::initializer_list<std::pair<LLT, LLT>> TypesInit);
273 unsigned TypeIdx0,
unsigned TypeIdx1,
unsigned MMOIdx,
274 std::initializer_list<TypePairAndMemDesc> TypesAndMemDescInit);
347namespace LegalizeMutations {
395 LegalizeAction Action;
405 return Predicate(Query);
414 return std::make_pair(0,
LLT{});
420 unsigned AliasOf = 0;
422 bool IsAliasedByAnother =
false;
439 unsigned typeIdx(
unsigned TypeIdx) {
442 "Type Index is out of bounds");
444 TypeIdxsCovered.
set(TypeIdx);
449 void markAllIdxsAsCovered() {
451 TypeIdxsCovered.
set();
452 ImmIdxsCovered.
set();
458 "RuleSet is aliased, change the representative opcode instead");
468 add({Predicate, Action});
481 std::initializer_list<LLT> Types) {
482 using namespace LegalityPredicates;
483 return actionIf(Action, typeInSet(typeIdx(0), Types));
488 std::initializer_list<LLT> Types,
490 using namespace LegalityPredicates;
491 return actionIf(Action, typeInSet(typeIdx(0), Types),
Mutation);
497 std::initializer_list<std::pair<LLT, LLT>> Types) {
498 using namespace LegalityPredicates;
499 return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types));
505 std::initializer_list<std::pair<LLT, LLT>> Types,
507 using namespace LegalityPredicates;
508 return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types),
515 std::initializer_list<LLT> Types) {
516 using namespace LegalityPredicates;
518 return actionIf(Action, typeInSet(typeIdx(0), Types));
522 LegalizeAction Action, std::initializer_list<std::pair<LLT, LLT>> Types) {
523 using namespace LegalityPredicates;
525 return actionIf(Action, typePairInSet(typeIdx(0), typeIdx(1), Types));
532 std::initializer_list<LLT> Types) {
533 using namespace LegalityPredicates;
534 return actionIf(Action, all(typeInSet(typeIdx(0), Types),
535 typeInSet(typeIdx(1), Types)));
542 actionForCartesianProduct(LegalizeAction Action,
543 std::initializer_list<LLT> Types0,
544 std::initializer_list<LLT> Types1) {
545 using namespace LegalityPredicates;
546 return actionIf(Action, all(typeInSet(typeIdx(0), Types0),
547 typeInSet(typeIdx(1), Types1)));
554 LegalizeAction Action, std::initializer_list<LLT> Types0,
555 std::initializer_list<LLT> Types1, std::initializer_list<LLT> Types2) {
556 using namespace LegalityPredicates;
557 return actionIf(Action, all(typeInSet(typeIdx(0), Types0),
558 all(typeInSet(typeIdx(1), Types1),
559 typeInSet(typeIdx(2), Types2))));
568 assert((AliasOf == 0 || AliasOf == Opcode) &&
569 "Opcode is already aliased to another opcode");
570 assert(Rules.
empty() &&
"Aliasing will discard rules");
578 "Imm Index is out of bounds");
580 ImmIdxsCovered.
set(ImmIdx);
589 markAllIdxsAsCovered();
590 return actionIf(LegalizeAction::Legal, Predicate);
594 return actionFor(LegalizeAction::Legal, Types);
599 return actionFor(LegalizeAction::Legal, Types);
604 markAllIdxsAsCovered();
605 return actionForTypeWithAnyImm(LegalizeAction::Legal, Types);
609 std::initializer_list<std::pair<LLT, LLT>> Types) {
610 markAllIdxsAsCovered();
611 return actionForTypeWithAnyImm(LegalizeAction::Legal, Types);
617 std::initializer_list<LegalityPredicates::TypePairAndMemDesc>
619 return actionIf(LegalizeAction::Legal,
621 typeIdx(0), typeIdx(1), 0, TypesAndMemDesc));
626 return actionForCartesianProduct(LegalizeAction::Legal, Types);
631 std::initializer_list<LLT> Types1) {
632 return actionForCartesianProduct(LegalizeAction::Legal, Types0, Types1);
637 std::initializer_list<LLT> Types1,
638 std::initializer_list<LLT> Types2) {
639 return actionForCartesianProduct(LegalizeAction::Legal, Types0, Types1,
644 using namespace LegalizeMutations;
645 markAllIdxsAsCovered();
646 return actionIf(LegalizeAction::Legal, always);
654 markAllIdxsAsCovered();
655 return actionIf(LegalizeAction::Bitcast, Predicate,
Mutation);
660 using namespace LegalizeMutations;
663 markAllIdxsAsCovered();
664 return actionIf(LegalizeAction::Lower, always);
669 using namespace LegalizeMutations;
672 markAllIdxsAsCovered();
673 return actionIf(LegalizeAction::Lower, Predicate);
680 markAllIdxsAsCovered();
681 return actionIf(LegalizeAction::Lower, Predicate,
Mutation);
686 return actionFor(LegalizeAction::Lower, Types);
692 return actionFor(LegalizeAction::Lower, Types,
Mutation);
697 return actionFor(LegalizeAction::Lower, Types);
703 return actionFor(LegalizeAction::Lower, Types,
Mutation);
708 std::initializer_list<LLT> Types1) {
709 using namespace LegalityPredicates;
710 return actionForCartesianProduct(LegalizeAction::Lower, Types0, Types1);
715 std::initializer_list<LLT> Types1,
716 std::initializer_list<LLT> Types2) {
717 using namespace LegalityPredicates;
718 return actionForCartesianProduct(LegalizeAction::Lower, Types0, Types1,
724 using namespace LegalizeMutations;
727 markAllIdxsAsCovered();
728 return actionIf(LegalizeAction::Libcall, always);
735 markAllIdxsAsCovered();
736 return actionIf(LegalizeAction::Libcall, Predicate);
739 return actionFor(LegalizeAction::Libcall, Types);
742 libcallFor(std::initializer_list<std::pair<LLT, LLT>> Types) {
743 return actionFor(LegalizeAction::Libcall, Types);
747 return actionForCartesianProduct(LegalizeAction::Libcall, Types);
751 std::initializer_list<LLT> Types1) {
752 return actionForCartesianProduct(LegalizeAction::Libcall, Types0, Types1);
761 markAllIdxsAsCovered();
762 return actionIf(LegalizeAction::WidenScalar, Predicate,
Mutation);
770 markAllIdxsAsCovered();
771 return actionIf(LegalizeAction::NarrowScalar, Predicate,
Mutation);
778 return actionFor(LegalizeAction::NarrowScalar, Types,
Mutation);
787 markAllIdxsAsCovered();
788 return actionIf(LegalizeAction::MoreElements, Predicate,
Mutation);
796 markAllIdxsAsCovered();
797 return actionIf(LegalizeAction::FewerElements, Predicate,
Mutation);
802 markAllIdxsAsCovered();
803 return actionIf(LegalizeAction::Unsupported, always);
806 return actionIf(LegalizeAction::Unsupported, Predicate);
810 return actionFor(LegalizeAction::Unsupported, Types);
814 return actionIf(LegalizeAction::Unsupported,
822 return actionIf(LegalizeAction::Lower,
830 return actionIf(LegalizeAction::Lower,
837 markAllIdxsAsCovered();
838 return actionIf(LegalizeAction::Custom, Predicate);
841 return actionFor(LegalizeAction::Custom, Types);
847 return actionFor(LegalizeAction::Custom, Types);
851 return actionForCartesianProduct(LegalizeAction::Custom, Types);
857 std::initializer_list<LLT> Types1) {
858 return actionForCartesianProduct(LegalizeAction::Custom, Types0, Types1);
864 std::initializer_list<LLT> Types1,
865 std::initializer_list<LLT> Types2) {
866 return actionForCartesianProduct(LegalizeAction::Custom, Types0, Types1,
878 unsigned MinSize = 0) {
879 using namespace LegalityPredicates;
881 LegalizeAction::WidenScalar, sizeNotPow2(typeIdx(TypeIdx)),
889 using namespace LegalityPredicates;
891 LegalizeAction::WidenScalar, sizeNotMultipleOf(typeIdx(TypeIdx),
Size),
898 unsigned MinSize = 0) {
899 using namespace LegalityPredicates;
901 LegalizeAction::WidenScalar, scalarOrEltSizeNotPow2(typeIdx(TypeIdx)),
906 using namespace LegalityPredicates;
907 return actionIf(LegalizeAction::NarrowScalar, isScalar(typeIdx(TypeIdx)),
912 using namespace LegalityPredicates;
913 return actionIf(LegalizeAction::FewerElements, isVector(typeIdx(TypeIdx)),
918 using namespace LegalityPredicates;
919 return actionIf(LegalizeAction::FewerElements,
920 all(Predicate, isVector(typeIdx(TypeIdx))),
926 using namespace LegalityPredicates;
927 using namespace LegalizeMutations;
928 return actionIf(LegalizeAction::WidenScalar,
930 changeElementTo(typeIdx(TypeIdx), Ty));
935 unsigned TypeIdx,
const LLT Ty) {
936 using namespace LegalityPredicates;
937 using namespace LegalizeMutations;
938 return actionIf(LegalizeAction::WidenScalar,
939 all(Predicate, scalarOrEltNarrowerThan(
941 changeElementTo(typeIdx(TypeIdx), Ty));
946 using namespace LegalityPredicates;
947 using namespace LegalizeMutations;
948 return actionIf(LegalizeAction::WidenScalar,
950 changeTo(typeIdx(TypeIdx), Ty));
956 using namespace LegalityPredicates;
957 using namespace LegalizeMutations;
959 LegalizeAction::WidenScalar,
961 const LLT QueryTy = Query.
Types[TypeIdx];
966 changeTo(typeIdx(TypeIdx), Ty));
971 using namespace LegalityPredicates;
972 using namespace LegalizeMutations;
973 return actionIf(LegalizeAction::NarrowScalar,
975 changeElementTo(typeIdx(TypeIdx), Ty));
980 using namespace LegalityPredicates;
981 using namespace LegalizeMutations;
982 return actionIf(LegalizeAction::NarrowScalar,
984 changeTo(typeIdx(TypeIdx), Ty));
992 using namespace LegalityPredicates;
993 using namespace LegalizeMutations;
995 LegalizeAction::NarrowScalar,
997 const LLT QueryTy = Query.
Types[TypeIdx];
1002 changeElementTo(typeIdx(TypeIdx), Ty));
1023 return Query.
Types[LargeTypeIdx].getScalarSizeInBits() >
1024 Query.
Types[TypeIdx].getSizeInBits();
1034 return Query.
Types[NarrowTypeIdx].getScalarSizeInBits() <
1035 Query.
Types[TypeIdx].getSizeInBits();
1049 unsigned TypeIdx,
unsigned LargeTypeIdx) {
1053 return Query.
Types[LargeTypeIdx].getScalarSizeInBits() >
1054 Query.
Types[TypeIdx].getScalarSizeInBits() &&
1059 if (
T.isVector() &&
T.getElementType().isPointer())
1061 return std::make_pair(TypeIdx,
T);
1068 unsigned SmallTypeIdx) {
1072 return Query.
Types[SmallTypeIdx].getScalarSizeInBits() <
1073 Query.
Types[TypeIdx].getScalarSizeInBits() &&
1078 return std::make_pair(TypeIdx,
T);
1086 using namespace LegalityPredicates;
1087 return actionIf(LegalizeAction::MoreElements,
1088 numElementsNotPow2(typeIdx(TypeIdx)),
1094 unsigned MinElements) {
1098 LegalizeAction::MoreElements,
1106 return std::make_pair(
1116 LegalizeAction::MoreElements,
1125 return std::make_pair(
1132 unsigned MaxElements) {
1136 LegalizeAction::FewerElements,
1146 return std::make_pair(TypeIdx, NewTy);
1158 "Expected element types to agree");
1181 add({always, LegalizeAction::UseLegacyRules});
1261 return Action == LegalizeAction::Legal || Action == LegalizeAction::Custom;
1290 static const int FirstOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_START;
1291 static const int LastOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_END;
unsigned const MachineRegisterInfo * MRI
Atomic ordering constants.
Given that RA is a live value
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the SmallBitVector class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
static constexpr ElementCount getFixed(ScalarTy MinVal)
constexpr unsigned getScalarSizeInBits() const
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 bool isVector() const
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.
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 & maxScalarSameAs(unsigned TypeIdx, unsigned NarrowTypeIdx)
Narrow the scalar to match the size of another.
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 & 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)
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 & 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 & 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 & 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 & 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 & 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 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 & alwaysLegal()
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 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)
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.
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
virtual bool legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI) const
Called for instructions with the Custom LegalizationAction.
LegalizeRuleSet & getActionDefinitionsBuilder(unsigned Opcode)
Get the action definition builder for the given opcode.
const LegacyLegalizerInfo & getLegacyLegalizerInfo() const
virtual unsigned getExtOpcodeForWideningConstant(LLT SmallTy) const
Return the opcode (SEXT/ZEXT/ANYEXT) that should be performed while widening a constant of type Small...
LegacyLegalizerInfo & getLegacyLegalizerInfo()
bool isLegalOrCustom(const LegalityQuery &Query) const
void aliasActionDefinitions(unsigned OpcodeTo, unsigned OpcodeFrom)
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 ...
void push_back(const T &Elt)
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.
@ Bitcast
Perform the operation on a different, but equivalently sized type.
@ MoreElements
The (vector) operation should be implemented by widening the input vector and ignoring the lanes adde...
@ Legal
The operation is expected to be selectable directly by the target, and no transformation is necessary...
@ FewerElements
The (vector) operation should be implemented by splitting it into sub-vectors where the operation is ...
@ Unsupported
This operation is completely unsupported on the target.
@ NarrowScalar
The operation should be synthesized from multiple instructions acting on a narrower scalar base-type.
@ Lower
The operation itself must be expressed in terms of simpler actions on this target.
@ 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.
@ WidenScalar
The operation should be implemented in terms of a wider scalar base-type.
@ Libcall
The operation should be implemented as a call to some kind of runtime support library.
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 ...
LegalityPredicate isScalar(unsigned TypeIdx)
True iff the specified type index is a scalar.
LegalityPredicate memSizeInBytesNotPow2(unsigned MMOIdx)
True iff the specified MMO index has a size (rounded to bytes) that is not a power of 2.
LegalityPredicate numElementsNotPow2(unsigned TypeIdx)
True iff the specified type index is a vector whose element count is not a power of 2.
LegalityPredicate isPointer(unsigned TypeIdx)
True iff the specified type index is a pointer (with any address space).
LegalityPredicate typeInSet(unsigned TypeIdx, std::initializer_list< LLT > TypesInit)
True iff the given type index is one of the specified types.
LegalityPredicate smallerThan(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the first type index has a smaller total bit size than second type index.
LegalityPredicate atomicOrderingAtLeastOrStrongerThan(unsigned MMOIdx, AtomicOrdering Ordering)
True iff the specified MMO index has at an atomic ordering of at Ordering or stronger.
LegalityPredicate scalarOrEltSizeNotPow2(unsigned TypeIdx)
True iff the specified type index is a scalar or vector whose element size is not a power of 2.
LegalityPredicate largerThan(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the first type index has a larger total bit size than second type index.
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.
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.
LegalityPredicate elementTypeIs(unsigned TypeIdx, LLT EltTy)
True if the type index is a vector with element type EltTy.
LegalityPredicate sameSize(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the specified type indices are both the same bit size.
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...
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.
LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
LegalityPredicate sizeNotPow2(unsigned TypeIdx)
True iff the specified type index is a scalar whose size is not a power of.
Predicate all(Predicate P0, Predicate P1)
True iff P0 and P1 are true.
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.
LegalityPredicate sizeNotMultipleOf(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar whose size is not a multiple of Size.
LegalityPredicate typeIs(unsigned TypeIdx, LLT TypesInit)
True iff the given type index is the specified type.
LegalityPredicate scalarWiderThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that's wider than the given size.
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...
LegalizeMutation moreElementsToNextPow2(unsigned TypeIdx, unsigned Min=0)
Add more elements to the type for the given type index to the next power of.
LegalizeMutation changeElementCountTo(unsigned TypeIdx, unsigned FromTypeIdx)
Keep the same scalar or element type as TypeIdx, but take the number of elements from FromTypeIdx.
LegalizeMutation scalarize(unsigned TypeIdx)
Break up the vector type for the given type index into the element type.
LegalizeMutation changeElementTo(unsigned TypeIdx, unsigned FromTypeIdx)
Keep the same scalar or element type as the given type index.
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.
LegalizeMutation changeTo(unsigned TypeIdx, LLT Ty)
Select this specific type for the given type index.
LegalizeMutation widenScalarOrEltToNextMultipleOf(unsigned TypeIdx, unsigned Size)
Widen the scalar type or vector element type for the given type index to next multiple of Size.
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.
bool getAlign(const Function &F, unsigned index, unsigned &align)
cl::opt< bool > DisableGISelLegalityCheck
std::function< std::pair< unsigned, LLT >(const LegalityQuery &)> LegalizeMutation
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.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
std::function< bool(const LegalityQuery &)> LegalityPredicate
This struct is a compact representation of a valid (non-zero power of two) alignment.
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)
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
constexpr LegalityQuery(unsigned Opcode, const ArrayRef< LLT > Types)
constexpr LegalityQuery(unsigned Opcode, const ArrayRef< LLT > Types, const ArrayRef< MemDesc > MMODescrs)
ArrayRef< MemDesc > MMODescrs
Operations which require memory can use this to place requirements on the memory type for each MMO.
raw_ostream & print(raw_ostream &OS) const
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