Index: include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h =================================================================== --- include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h +++ include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h @@ -278,9 +278,9 @@ /// Checks if the target legalizer info has specified anything about the /// instruction, or if unsupported. bool isInstUnsupported(const LegalityQuery &Query) const { + using namespace LegalizeActions; auto Step = LI.getAction(Query); - return Step.Action == LegalizerInfo::LegalizeAction::Unsupported || - Step.Action == LegalizerInfo::LegalizeAction::NotFound; + return Step.Action == Unsupported || Step.Action == NotFound; } }; Index: include/llvm/CodeGen/GlobalISel/LegalizerInfo.h =================================================================== --- include/llvm/CodeGen/GlobalISel/LegalizerInfo.h +++ include/llvm/CodeGen/GlobalISel/LegalizerInfo.h @@ -34,6 +34,55 @@ class MachineIRBuilder; class MachineRegisterInfo; +namespace LegalizeActions { +enum LegalizeAction : std::uint8_t { + /// The operation is expected to be selectable directly by the target, and + /// no transformation is necessary. + Legal, + + /// The operation should be synthesized from multiple instructions acting on + /// a narrower scalar base-type. For example a 64-bit add might be + /// implemented in terms of 32-bit add-with-carry. + NarrowScalar, + + /// The operation should be implemented in terms of a wider scalar + /// base-type. For example a <2 x s8> add could be implemented as a <2 + /// x s32> add (ignoring the high bits). + WidenScalar, + + /// The (vector) operation should be implemented by splitting it into + /// sub-vectors where the operation is legal. For example a <8 x s64> add + /// might be implemented as 4 separate <2 x s64> adds. + FewerElements, + + /// The (vector) operation should be implemented by widening the input + /// vector and ignoring the lanes added by doing so. For example <2 x i8> is + /// rarely legal, but you might perform an <8 x i8> and then only look at + /// the first two results. + MoreElements, + + /// The operation itself must be expressed in terms of simpler actions on + /// this target. E.g. a SREM replaced by an SDIV and subtraction. + Lower, + + /// The operation should be implemented as a call to some kind of runtime + /// support library. For example this usually happens on machines that don't + /// support floating-point operations natively. + Libcall, + + /// The target wants to do something special with this combination of + /// operand and type. A callback will be issued when it is needed. + Custom, + + /// This operation is completely unsupported on the target. A programming + /// error has occurred. + Unsupported, + + /// Sentinel value for when no action was found in the specified table. + NotFound, +}; +} // end namespace LegalizeActions + /// Legalization is decided based on an instruction's opcode, which type slot /// we're considering, and what the existing type is. These aspects are gathered /// together for convenience in the InstrAspect class. @@ -65,65 +114,18 @@ class LegalizerInfo { public: - enum LegalizeAction : std::uint8_t { - /// The operation is expected to be selectable directly by the target, and - /// no transformation is necessary. - Legal, - - /// The operation should be synthesized from multiple instructions acting on - /// a narrower scalar base-type. For example a 64-bit add might be - /// implemented in terms of 32-bit add-with-carry. - NarrowScalar, - - /// The operation should be implemented in terms of a wider scalar - /// base-type. For example a <2 x s8> add could be implemented as a <2 - /// x s32> add (ignoring the high bits). - WidenScalar, - - /// The (vector) operation should be implemented by splitting it into - /// sub-vectors where the operation is legal. For example a <8 x s64> add - /// might be implemented as 4 separate <2 x s64> adds. - FewerElements, - - /// The (vector) operation should be implemented by widening the input - /// vector and ignoring the lanes added by doing so. For example <2 x i8> is - /// rarely legal, but you might perform an <8 x i8> and then only look at - /// the first two results. - MoreElements, - - /// The operation itself must be expressed in terms of simpler actions on - /// this target. E.g. a SREM replaced by an SDIV and subtraction. - Lower, - - /// The operation should be implemented as a call to some kind of runtime - /// support library. For example this usually happens on machines that don't - /// support floating-point operations natively. - Libcall, - - /// The target wants to do something special with this combination of - /// operand and type. A callback will be issued when it is needed. - Custom, - - /// This operation is completely unsupported on the target. A programming - /// error has occurred. - Unsupported, - - /// Sentinel value for when no action was found in the specified table. - NotFound, - }; - /// The result of a query. It either indicates a final answer of Legal or /// Unsupported or describes an action that must be taken to make an operation /// more legal. struct LegalizeActionStep { /// The action to take or the final answer. - LegalizeAction Action; + LegalizeActions::LegalizeAction Action; /// If describing an action, the type index to change. Otherwise zero. unsigned TypeIdx; /// If describing an action, the new type for TypeIdx. Otherwise LLT{}. LLT NewType; - LegalizeActionStep(LegalizeAction Action, unsigned TypeIdx, + LegalizeActionStep(LegalizeActions::LegalizeAction Action, unsigned TypeIdx, const LLT &NewType) : Action(Action), TypeIdx(TypeIdx), NewType(NewType) {} @@ -141,7 +143,9 @@ /// before any query is made or incorrect results may be returned. void computeTables(); - static bool needsLegalizingToDifferentSize(const LegalizeAction Action) { + static bool + needsLegalizingToDifferentSize(const LegalizeActions::LegalizeAction Action) { + using namespace LegalizeActions; switch (Action) { case NarrowScalar: case WidenScalar: @@ -154,7 +158,7 @@ } } - typedef std::pair SizeAndAction; + typedef std::pair SizeAndAction; typedef std::vector SizeAndActionsVec; using SizeChangeStrategy = std::function; @@ -163,7 +167,8 @@ /// representation. /// The LegalizeAction must be one for which NeedsLegalizingToDifferentSize /// returns false. - void setAction(const InstrAspect &Aspect, LegalizeAction Action) { + void setAction(const InstrAspect &Aspect, + LegalizeActions::LegalizeAction Action) { assert(!needsLegalizingToDifferentSize(Action)); TablesInitialized = false; const unsigned OpcodeIdx = Aspect.Opcode - FirstOp; @@ -219,8 +224,9 @@ /// and Unsupported for all other scalar types T. static SizeAndActionsVec unsupportedForDifferentSizes(const SizeAndActionsVec &v) { + using namespace LegalizeActions; return increaseToLargerTypesAndDecreaseToLargest(v, Unsupported, - Unsupported); + Unsupported); } /// A SizeChangeStrategy for the common case where legalization for a @@ -229,32 +235,36 @@ /// largest legal type. static SizeAndActionsVec widenToLargerTypesAndNarrowToLargest(const SizeAndActionsVec &v) { + using namespace LegalizeActions; assert(v.size() > 0 && "At least one size that can be legalized towards is needed" " for this SizeChangeStrategy"); return increaseToLargerTypesAndDecreaseToLargest(v, WidenScalar, - NarrowScalar); + NarrowScalar); } static SizeAndActionsVec widenToLargerTypesUnsupportedOtherwise(const SizeAndActionsVec &v) { + using namespace LegalizeActions; return increaseToLargerTypesAndDecreaseToLargest(v, WidenScalar, - Unsupported); + Unsupported); } static SizeAndActionsVec narrowToSmallerAndUnsupportedIfTooSmall(const SizeAndActionsVec &v) { + using namespace LegalizeActions; return decreaseToSmallerTypesAndIncreaseToSmallest(v, NarrowScalar, - Unsupported); + Unsupported); } static SizeAndActionsVec narrowToSmallerAndWidenToSmallest(const SizeAndActionsVec &v) { + using namespace LegalizeActions; assert(v.size() > 0 && "At least one size that can be legalized towards is needed" " for this SizeChangeStrategy"); return decreaseToSmallerTypesAndIncreaseToSmallest(v, NarrowScalar, - WidenScalar); + WidenScalar); } /// A SizeChangeStrategy for the common case where legalization for a @@ -277,20 +287,21 @@ /// (FewerElements, vector(4,32)). static SizeAndActionsVec moreToWiderTypesAndLessToWidest(const SizeAndActionsVec &v) { + using namespace LegalizeActions; return increaseToLargerTypesAndDecreaseToLargest(v, MoreElements, - FewerElements); + FewerElements); } /// Helper function to implement many typical SizeChangeStrategy functions. - static SizeAndActionsVec - increaseToLargerTypesAndDecreaseToLargest(const SizeAndActionsVec &v, - LegalizeAction IncreaseAction, - LegalizeAction DecreaseAction); + static SizeAndActionsVec increaseToLargerTypesAndDecreaseToLargest( + const SizeAndActionsVec &v, + LegalizeActions::LegalizeAction IncreaseAction, + LegalizeActions::LegalizeAction DecreaseAction); /// Helper function to implement many typical SizeChangeStrategy functions. - static SizeAndActionsVec - decreaseToSmallerTypesAndIncreaseToSmallest(const SizeAndActionsVec &v, - LegalizeAction DecreaseAction, - LegalizeAction IncreaseAction); + static SizeAndActionsVec decreaseToSmallerTypesAndIncreaseToSmallest( + const SizeAndActionsVec &v, + LegalizeActions::LegalizeAction DecreaseAction, + LegalizeActions::LegalizeAction IncreaseAction); /// Determine what action should be taken to legalize the described /// instruction. Requires computeTables to have been called. @@ -318,7 +329,7 @@ /// /// \returns a pair consisting of the kind of legalization that should be /// performed and the destination type. - std::pair + std::pair getAspectAction(const InstrAspect &Aspect) const; /// The SizeAndActionsVec is a representation mapping between all natural @@ -388,6 +399,7 @@ /// A partial SizeAndActionsVec potentially doesn't cover all bit sizes, /// i.e. it's OK if it doesn't start from size 1. static void checkPartialSizeAndActionsVector(const SizeAndActionsVec& v) { + using namespace LegalizeActions; #ifndef NDEBUG // The sizes should be in increasing order int prev_size = -1; @@ -468,18 +480,18 @@ /// {32, Lower}, // bit sizes [32, 33[ /// {33, NarrowScalar} // bit sizes [65, +inf[ /// }); - std::pair + std::pair findScalarLegalAction(const InstrAspect &Aspect) const; /// Returns the next action needed towards legalizing the vector type. - std::pair + std::pair findVectorLegalAction(const InstrAspect &Aspect) const; static const int FirstOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_START; static const int LastOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_END; // Data structures used temporarily during construction of legality data: - typedef DenseMap TypeMap; + typedef DenseMap TypeMap; SmallVector SpecifiedActions[LastOp - FirstOp + 1]; SmallVector ScalarSizeChangeStrategies[LastOp - FirstOp + 1]; Index: lib/CodeGen/GlobalISel/LegalizerHelper.cpp =================================================================== --- lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -26,6 +26,7 @@ #define DEBUG_TYPE "legalizer" using namespace llvm; +using namespace LegalizeActions; LegalizerHelper::LegalizerHelper(MachineFunction &MF) : MRI(MF.getRegInfo()), LI(*MF.getSubtarget().getLegalizerInfo()) { @@ -38,25 +39,25 @@ auto Step = LI.getAction(MI, MRI); switch (Step.Action) { - case LegalizerInfo::Legal: + case Legal: DEBUG(dbgs() << ".. Already legal\n"); return AlreadyLegal; - case LegalizerInfo::Libcall: + case Libcall: DEBUG(dbgs() << ".. Convert to libcall\n"); return libcall(MI); - case LegalizerInfo::NarrowScalar: + case NarrowScalar: DEBUG(dbgs() << ".. Narrow scalar\n"); return narrowScalar(MI, Step.TypeIdx, Step.NewType); - case LegalizerInfo::WidenScalar: + case WidenScalar: DEBUG(dbgs() << ".. Widen scalar\n"); return widenScalar(MI, Step.TypeIdx, Step.NewType); - case LegalizerInfo::Lower: + case Lower: DEBUG(dbgs() << ".. Lower\n"); return lower(MI, Step.TypeIdx, Step.NewType); - case LegalizerInfo::FewerElements: + case FewerElements: DEBUG(dbgs() << ".. Reduce number of elements\n"); return fewerElementsVector(MI, Step.TypeIdx, Step.NewType); - case LegalizerInfo::Custom: + case Custom: DEBUG(dbgs() << ".. Custom legalization\n"); return LI.legalizeCustom(MI, MRI, MIRBuilder) ? Legalized : UnableToLegalize; @@ -870,7 +871,7 @@ // Lower (G_FSUB LHS, RHS) to (G_FADD LHS, (G_FNEG RHS)). // First, check if G_FNEG is marked as Lower. If so, we may // end up with an infinite loop as G_FSUB is used to legalize G_FNEG. - if (LI.getAction({G_FNEG, {Ty}}).Action == LegalizerInfo::Lower) + if (LI.getAction({G_FNEG, {Ty}}).Action == Lower) return UnableToLegalize; unsigned Res = MI.getOperand(0).getReg(); unsigned LHS = MI.getOperand(1).getReg(); Index: lib/CodeGen/GlobalISel/LegalizerInfo.cpp =================================================================== --- lib/CodeGen/GlobalISel/LegalizerInfo.cpp +++ lib/CodeGen/GlobalISel/LegalizerInfo.cpp @@ -29,7 +29,9 @@ #include "llvm/Support/MathExtras.h" #include #include + using namespace llvm; +using namespace LegalizeActions; LegalizerInfo::LegalizerInfo() : TablesInitialized(false) { // Set defaults. @@ -162,7 +164,7 @@ // probably going to need specialized lookup structures for various types before // we have any hope of doing well with something like <13 x i3>. Even the common // cases should do better than what we have now. -std::pair +std::pair LegalizerInfo::getAspectAction(const InstrAspect &Aspect) const { assert(TablesInitialized && "backend forgot to call computeTables"); // These *have* to be implemented for now, they're the fundamental basis of @@ -326,7 +328,7 @@ llvm_unreachable("Action has an unknown enum value"); } -std::pair +std::pair LegalizerInfo::findScalarLegalAction(const InstrAspect &Aspect) const { assert(Aspect.Type.isScalar() || Aspect.Type.isPointer()); if (Aspect.Opcode < FirstOp || Aspect.Opcode > LastOp) @@ -355,7 +357,7 @@ SizeAndAction.first)}; } -std::pair +std::pair LegalizerInfo::findVectorLegalAction(const InstrAspect &Aspect) const { assert(Aspect.Type.isVector()); // First legalize the vector element size, then legalize the number of Index: lib/Target/AArch64/AArch64LegalizerInfo.cpp =================================================================== --- lib/Target/AArch64/AArch64LegalizerInfo.cpp +++ lib/Target/AArch64/AArch64LegalizerInfo.cpp @@ -23,6 +23,7 @@ #include "llvm/IR/Type.h" using namespace llvm; +using namespace LegalizeActions; /// FIXME: The following static functions are SizeChangeStrategy functions /// that are meant to temporarily mimic the behaviour of the old legalization @@ -40,7 +41,7 @@ result.push_back(v[i]); if (i + 1 < v[i].first && i + 1 < v.size() && v[i + 1].first != v[i].first + 1) - result.push_back({v[i].first + 1, LegalizerInfo::Unsupported}); + result.push_back({v[i].first + 1, Unsupported}); } } @@ -48,14 +49,14 @@ widen_1_narrow_128_ToLargest(const LegalizerInfo::SizeAndActionsVec &v) { assert(v.size() >= 1); assert(v[0].first > 2); - LegalizerInfo::SizeAndActionsVec result = {{1, LegalizerInfo::WidenScalar}, - {2, LegalizerInfo::Unsupported}}; + LegalizerInfo::SizeAndActionsVec result = {{1, WidenScalar}, + {2, Unsupported}}; addAndInterleaveWithUnsupported(result, v); auto Largest = result.back().first; assert(Largest + 1 < 128); - result.push_back({Largest + 1, LegalizerInfo::Unsupported}); - result.push_back({128, LegalizerInfo::NarrowScalar}); - result.push_back({129, LegalizerInfo::Unsupported}); + result.push_back({Largest + 1, Unsupported}); + result.push_back({128, NarrowScalar}); + result.push_back({129, Unsupported}); return result; } @@ -63,12 +64,12 @@ widen_16(const LegalizerInfo::SizeAndActionsVec &v) { assert(v.size() >= 1); assert(v[0].first > 17); - LegalizerInfo::SizeAndActionsVec result = {{1, LegalizerInfo::Unsupported}, - {16, LegalizerInfo::WidenScalar}, - {17, LegalizerInfo::Unsupported}}; + LegalizerInfo::SizeAndActionsVec result = {{1, Unsupported}, + {16, WidenScalar}, + {17, Unsupported}}; addAndInterleaveWithUnsupported(result, v); auto Largest = result.back().first; - result.push_back({Largest + 1, LegalizerInfo::Unsupported}); + result.push_back({Largest + 1, Unsupported}); return result; } @@ -77,11 +78,11 @@ assert(v.size() >= 1); assert(v[0].first > 9); LegalizerInfo::SizeAndActionsVec result = { - {1, LegalizerInfo::WidenScalar}, {2, LegalizerInfo::Unsupported}, - {8, LegalizerInfo::WidenScalar}, {9, LegalizerInfo::Unsupported}}; + {1, WidenScalar}, {2, Unsupported}, + {8, WidenScalar}, {9, Unsupported}}; addAndInterleaveWithUnsupported(result, v); auto Largest = result.back().first; - result.push_back({Largest + 1, LegalizerInfo::Unsupported}); + result.push_back({Largest + 1, Unsupported}); return result; } @@ -90,12 +91,12 @@ assert(v.size() >= 1); assert(v[0].first > 17); LegalizerInfo::SizeAndActionsVec result = { - {1, LegalizerInfo::WidenScalar}, {2, LegalizerInfo::Unsupported}, - {8, LegalizerInfo::WidenScalar}, {9, LegalizerInfo::Unsupported}, - {16, LegalizerInfo::WidenScalar}, {17, LegalizerInfo::Unsupported}}; + {1, WidenScalar}, {2, Unsupported}, + {8, WidenScalar}, {9, Unsupported}, + {16, WidenScalar}, {17, Unsupported}}; addAndInterleaveWithUnsupported(result, v); auto Largest = result.back().first; - result.push_back({Largest + 1, LegalizerInfo::Unsupported}); + result.push_back({Largest + 1, Unsupported}); return result; } @@ -104,12 +105,12 @@ assert(v.size() >= 1); assert(v[0].first > 17); LegalizerInfo::SizeAndActionsVec result = { - {1, LegalizerInfo::WidenScalar}, {2, LegalizerInfo::Unsupported}, - {8, LegalizerInfo::WidenScalar}, {9, LegalizerInfo::Unsupported}, - {16, LegalizerInfo::WidenScalar}, {17, LegalizerInfo::Unsupported}}; + {1, WidenScalar}, {2, Unsupported}, + {8, WidenScalar}, {9, Unsupported}, + {16, WidenScalar}, {17, Unsupported}}; addAndInterleaveWithUnsupported(result, v); auto Largest = result.back().first; - result.push_back({Largest + 1, LegalizerInfo::NarrowScalar}); + result.push_back({Largest + 1, NarrowScalar}); return result; } @@ -118,13 +119,13 @@ assert(v.size() >= 1); assert(v[0].first > 33); LegalizerInfo::SizeAndActionsVec result = { - {1, LegalizerInfo::WidenScalar}, {2, LegalizerInfo::Unsupported}, - {8, LegalizerInfo::WidenScalar}, {9, LegalizerInfo::Unsupported}, - {16, LegalizerInfo::WidenScalar}, {17, LegalizerInfo::Unsupported}, - {32, LegalizerInfo::WidenScalar}, {33, LegalizerInfo::Unsupported}}; + {1, WidenScalar}, {2, Unsupported}, + {8, WidenScalar}, {9, Unsupported}, + {16, WidenScalar}, {17, Unsupported}, + {32, WidenScalar}, {33, Unsupported}}; addAndInterleaveWithUnsupported(result, v); auto Largest = result.back().first; - result.push_back({Largest + 1, LegalizerInfo::Unsupported}); + result.push_back({Largest + 1, Unsupported}); return result; } Index: unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp =================================================================== --- unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp +++ unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp @@ -12,22 +12,23 @@ #include "gtest/gtest.h" using namespace llvm; +using namespace LegalizeActions; // Define a couple of pretty printers to help debugging when things go wrong. namespace llvm { std::ostream & -operator<<(std::ostream &OS, const llvm::LegalizerInfo::LegalizeAction Act) { +operator<<(std::ostream &OS, const LegalizeAction Act) { switch (Act) { - case LegalizerInfo::Lower: OS << "Lower"; break; - case LegalizerInfo::Legal: OS << "Legal"; break; - case LegalizerInfo::NarrowScalar: OS << "NarrowScalar"; break; - case LegalizerInfo::WidenScalar: OS << "WidenScalar"; break; - case LegalizerInfo::FewerElements: OS << "FewerElements"; break; - case LegalizerInfo::MoreElements: OS << "MoreElements"; break; - case LegalizerInfo::Libcall: OS << "Libcall"; break; - case LegalizerInfo::Custom: OS << "Custom"; break; - case LegalizerInfo::Unsupported: OS << "Unsupported"; break; - case LegalizerInfo::NotFound: OS << "NotFound"; + case Lower: OS << "Lower"; break; + case Legal: OS << "Legal"; break; + case NarrowScalar: OS << "NarrowScalar"; break; + case WidenScalar: OS << "WidenScalar"; break; + case FewerElements: OS << "FewerElements"; break; + case MoreElements: OS << "MoreElements"; break; + case Libcall: OS << "Libcall"; break; + case Custom: OS << "Custom"; break; + case Unsupported: OS << "Unsupported"; break; + case NotFound: OS << "NotFound"; } return OS; } @@ -51,7 +52,7 @@ // Typical RISCy set of operations based on AArch64. for (unsigned Op : {G_ADD, G_SUB}) { for (unsigned Size : {32, 64}) - L.setAction({Op, 0, LLT::scalar(Size)}, LegalizerInfo::Legal); + L.setAction({Op, 0, LLT::scalar(Size)}, Legal); L.setLegalizeScalarToDifferentSizeStrategy( Op, 0, LegalizerInfo::widenToLargerTypesAndNarrowToLargest); } @@ -61,28 +62,28 @@ for (unsigned opcode : {G_ADD, G_SUB}) { // Check we infer the correct types and actually do what we're told. ASSERT_EQ(L.getAction({opcode, {LLT::scalar(8)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(32))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(32))); ASSERT_EQ(L.getAction({opcode, {LLT::scalar(16)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(32))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(32))); ASSERT_EQ(L.getAction({opcode, {LLT::scalar(32)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::Legal, 0, LLT{})); + LegalizerInfo::LegalizeActionStep(Legal, 0, LLT{})); ASSERT_EQ(L.getAction({opcode, {LLT::scalar(64)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::Legal, 0, LLT{})); + LegalizerInfo::LegalizeActionStep(Legal, 0, LLT{})); // Make sure the default for over-sized types applies. ASSERT_EQ(L.getAction({opcode, {LLT::scalar(128)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::NarrowScalar, 0, LLT::scalar(64))); + LegalizerInfo::LegalizeActionStep(NarrowScalar, 0, LLT::scalar(64))); // Make sure we also handle unusual sizes ASSERT_EQ(L.getAction({opcode, {LLT::scalar(1)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(32))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(32))); ASSERT_EQ(L.getAction({opcode, {LLT::scalar(31)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(32))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(32))); ASSERT_EQ(L.getAction({opcode, {LLT::scalar(33)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(64))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(64))); ASSERT_EQ(L.getAction({opcode, {LLT::scalar(63)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(64))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(64))); ASSERT_EQ(L.getAction({opcode, {LLT::scalar(65)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::NarrowScalar, 0, LLT::scalar(64))); + LegalizerInfo::LegalizeActionStep(NarrowScalar, 0, LLT::scalar(64))); } } @@ -90,35 +91,35 @@ using namespace TargetOpcode; LegalizerInfo L; // Typical RISCy set of operations based on ARM. - L.setAction({G_ADD, LLT::vector(8, 8)}, LegalizerInfo::Legal); - L.setAction({G_ADD, LLT::vector(16, 8)}, LegalizerInfo::Legal); - L.setAction({G_ADD, LLT::vector(4, 16)}, LegalizerInfo::Legal); - L.setAction({G_ADD, LLT::vector(8, 16)}, LegalizerInfo::Legal); - L.setAction({G_ADD, LLT::vector(2, 32)}, LegalizerInfo::Legal); - L.setAction({G_ADD, LLT::vector(4, 32)}, LegalizerInfo::Legal); + L.setAction({G_ADD, LLT::vector(8, 8)}, Legal); + L.setAction({G_ADD, LLT::vector(16, 8)}, Legal); + L.setAction({G_ADD, LLT::vector(4, 16)}, Legal); + L.setAction({G_ADD, LLT::vector(8, 16)}, Legal); + L.setAction({G_ADD, LLT::vector(2, 32)}, Legal); + L.setAction({G_ADD, LLT::vector(4, 32)}, Legal); L.setLegalizeVectorElementToDifferentSizeStrategy( G_ADD, 0, LegalizerInfo::widenToLargerTypesUnsupportedOtherwise); - L.setAction({G_ADD, 0, LLT::scalar(32)}, LegalizerInfo::Legal); + L.setAction({G_ADD, 0, LLT::scalar(32)}, Legal); L.computeTables(); // Check we infer the correct types and actually do what we're told for some // simple cases. ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(8, 8)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::Legal, 0, LLT{})); + LegalizerInfo::LegalizeActionStep(Legal, 0, LLT{})); ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(8, 7)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::vector(8, 8))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::vector(8, 8))); ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(2, 8)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::MoreElements, 0, LLT::vector(8, 8))); + LegalizerInfo::LegalizeActionStep(MoreElements, 0, LLT::vector(8, 8))); ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(8, 32)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::FewerElements, 0, LLT::vector(4, 32))); + LegalizerInfo::LegalizeActionStep(FewerElements, 0, LLT::vector(4, 32))); // Check a few non-power-of-2 sizes: ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(3, 3)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::vector(3, 8))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::vector(3, 8))); ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(3, 8)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::MoreElements, 0, LLT::vector(8, 8))); + LegalizerInfo::LegalizeActionStep(MoreElements, 0, LLT::vector(8, 8))); } TEST(LegalizerInfoTest, MultipleTypes) { @@ -128,8 +129,8 @@ LLT s64 = LLT::scalar(64); // Typical RISCy set of operations based on AArch64. - L.setAction({G_PTRTOINT, 0, s64}, LegalizerInfo::Legal); - L.setAction({G_PTRTOINT, 1, p0}, LegalizerInfo::Legal); + L.setAction({G_PTRTOINT, 0, s64}, Legal); + L.setAction({G_PTRTOINT, 1, p0}, Legal); L.setLegalizeScalarToDifferentSizeStrategy( G_PTRTOINT, 0, LegalizerInfo::widenToLargerTypesAndNarrowToLargest); @@ -138,15 +139,15 @@ // Check we infer the correct types and actually do what we're told. ASSERT_EQ(L.getAction({G_PTRTOINT, {s64, p0}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::Legal, 0, LLT{})); + LegalizerInfo::LegalizeActionStep(Legal, 0, LLT{})); // Make sure we also handle unusual sizes ASSERT_EQ( L.getAction({G_PTRTOINT, {LLT::scalar(65), s64}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::NarrowScalar, 0, s64)); + LegalizerInfo::LegalizeActionStep(NarrowScalar, 0, s64)); ASSERT_EQ( L.getAction({G_PTRTOINT, {s64, LLT::pointer(0, 32)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::Unsupported, 1, LLT::pointer(0, 32))); + LegalizerInfo::LegalizeActionStep(Unsupported, 1, LLT::pointer(0, 32))); } TEST(LegalizerInfoTest, MultipleSteps) { @@ -157,22 +158,22 @@ L.setLegalizeScalarToDifferentSizeStrategy( G_UREM, 0, LegalizerInfo::widenToLargerTypesUnsupportedOtherwise); - L.setAction({G_UREM, 0, s32}, LegalizerInfo::Lower); - L.setAction({G_UREM, 0, s64}, LegalizerInfo::Lower); + L.setAction({G_UREM, 0, s32}, Lower); + L.setAction({G_UREM, 0, s64}, Lower); L.computeTables(); ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(16)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(32))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(32))); ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(32)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::Lower, 0, LLT::scalar(32))); + LegalizerInfo::LegalizeActionStep(Lower, 0, LLT::scalar(32))); } TEST(LegalizerInfoTest, SizeChangeStrategy) { using namespace TargetOpcode; LegalizerInfo L; for (unsigned Size : {1, 8, 16, 32}) - L.setAction({G_UREM, 0, LLT::scalar(Size)}, LegalizerInfo::Legal); + L.setAction({G_UREM, 0, LLT::scalar(Size)}, Legal); L.setLegalizeScalarToDifferentSizeStrategy( G_UREM, 0, LegalizerInfo::widenToLargerTypesUnsupportedOtherwise); @@ -181,19 +182,19 @@ // Check we infer the correct types and actually do what we're told. for (unsigned Size : {1, 8, 16, 32}) { ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(Size)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::Legal, 0, LLT{})); + LegalizerInfo::LegalizeActionStep(Legal, 0, LLT{})); } ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(2)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(8))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(8))); ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(7)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(8))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(8))); ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(9)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(16))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(16))); ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(17)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(32))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(32))); ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(31)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0, LLT::scalar(32))); + LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(32))); ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(33)}}), - LegalizerInfo::LegalizeActionStep(LegalizerInfo::Unsupported, 0, LLT::scalar(33))); + LegalizerInfo::LegalizeActionStep(Unsupported, 0, LLT::scalar(33))); } }