[llvm] r323669 - [globalisel] Make LegalizerInfo::LegalizeAction available outside of LegalizerInfo. NFC

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 09:37:29 PST 2018


Author: dsanders
Date: Mon Jan 29 09:37:29 2018
New Revision: 323669

URL: http://llvm.org/viewvc/llvm-project?rev=323669&view=rev
Log:
[globalisel] Make LegalizerInfo::LegalizeAction available outside of LegalizerInfo. NFC

Summary:
The improvements to the LegalizerInfo discussed in D42244 require that
LegalizerInfo::LegalizeAction be available for use in other classes. As such,
it needs to be moved out of LegalizerInfo. This has been done separately to the
next patch to minimize the noise in that patch.


Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
    llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
    llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
    llvm/trunk/lib/CodeGen/GlobalISel/LegalizerInfo.cpp
    llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp
    llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
    llvm/trunk/lib/Target/ARM/ARMLegalizerInfo.cpp
    llvm/trunk/lib/Target/X86/X86LegalizerInfo.cpp
    llvm/trunk/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h?rev=323669&r1=323668&r2=323669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h Mon Jan 29 09:37:29 2018
@@ -278,9 +278,9 @@ private:
   /// 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;
   }
 };
 

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h?rev=323669&r1=323668&r2=323669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h Mon Jan 29 09:37:29 2018
@@ -34,6 +34,57 @@ class MachineInstr;
 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
+
+using LegalizeActions::LegalizeAction;
+
 /// 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.
@@ -62,53 +113,6 @@ struct LegalityQuery {
 
 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.
@@ -139,6 +143,7 @@ public:
   void computeTables();
 
   static bool needsLegalizingToDifferentSize(const LegalizeAction Action) {
+    using namespace LegalizeActions;
     switch (Action) {
     case NarrowScalar:
     case WidenScalar:
@@ -216,8 +221,9 @@ public:
   /// 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
@@ -226,32 +232,36 @@ public:
   /// 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
@@ -274,8 +284,9 @@ public:
   ///       (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.
@@ -385,6 +396,7 @@ private:
   /// 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;

Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp?rev=323669&r1=323668&r2=323669&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp Mon Jan 29 09:37:29 2018
@@ -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 @@ LegalizerHelper::legalizeInstrStep(Machi
 
   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;
@@ -941,7 +942,7 @@ LegalizerHelper::lower(MachineInstr &MI,
     // 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();

Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalizerInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalizerInfo.cpp?rev=323669&r1=323668&r2=323669&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalizerInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalizerInfo.cpp Mon Jan 29 09:37:29 2018
@@ -29,7 +29,9 @@
 #include "llvm/Support/MathExtras.h"
 #include <algorithm>
 #include <map>
+
 using namespace llvm;
+using namespace LegalizeActions;
 
 LegalizerInfo::LegalizerInfo() : TablesInitialized(false) {
   // Set defaults.
@@ -162,7 +164,7 @@ void LegalizerInfo::computeTables() {
 // 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<LegalizerInfo::LegalizeAction, LLT>
+std::pair<LegalizeAction, LLT>
 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 @@ LegalizerInfo::findAction(const SizeAndA
   llvm_unreachable("Action has an unknown enum value");
 }
 
-std::pair<LegalizerInfo::LegalizeAction, LLT>
+std::pair<LegalizeAction, LLT>
 LegalizerInfo::findScalarLegalAction(const InstrAspect &Aspect) const {
   assert(Aspect.Type.isScalar() || Aspect.Type.isPointer());
   if (Aspect.Opcode < FirstOp || Aspect.Opcode > LastOp)
@@ -355,7 +357,7 @@ LegalizerInfo::findScalarLegalAction(con
                                                 SizeAndAction.first)};
 }
 
-std::pair<LegalizerInfo::LegalizeAction, LLT>
+std::pair<LegalizeAction, LLT>
 LegalizerInfo::findVectorLegalAction(const InstrAspect &Aspect) const {
   assert(Aspect.Type.isVector());
   // First legalize the vector element size, then legalize the number of

Modified: llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp?rev=323669&r1=323668&r2=323669&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp Mon Jan 29 09:37:29 2018
@@ -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 @@ addAndInterleaveWithUnsupported(Legalize
     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 @@ static LegalizerInfo::SizeAndActionsVec
 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 @@ static LegalizerInfo::SizeAndActionsVec
 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 @@ widen_1_8(const LegalizerInfo::SizeAndAc
   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 @@ widen_1_8_16(const LegalizerInfo::SizeAn
   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 @@ widen_1_8_16_narrowToLargest(const Legal
   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 @@ widen_1_8_16_32(const LegalizerInfo::Siz
   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;
 }
 

Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp?rev=323669&r1=323668&r2=323669&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp Mon Jan 29 09:37:29 2018
@@ -20,6 +20,7 @@
 #include "llvm/Support/Debug.h"
 
 using namespace llvm;
+using namespace LegalizeActions;
 
 AMDGPULegalizerInfo::AMDGPULegalizerInfo() {
   using namespace TargetOpcode;

Modified: llvm/trunk/lib/Target/ARM/ARMLegalizerInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMLegalizerInfo.cpp?rev=323669&r1=323668&r2=323669&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMLegalizerInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMLegalizerInfo.cpp Mon Jan 29 09:37:29 2018
@@ -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 @@ addAndInterleaveWithUnsupported(Legalize
     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,13 +49,14 @@ static LegalizerInfo::SizeAndActionsVec
 widen_8_16(const LegalizerInfo::SizeAndActionsVec &v) {
   assert(v.size() >= 1);
   assert(v[0].first > 17);
-  LegalizerInfo::SizeAndActionsVec result = {
-      {1, LegalizerInfo::Unsupported},
-      {8, LegalizerInfo::WidenScalar},  {9, LegalizerInfo::Unsupported},
-      {16, LegalizerInfo::WidenScalar}, {17, LegalizerInfo::Unsupported}};
+  LegalizerInfo::SizeAndActionsVec result = {{1, 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;
 }
 
@@ -63,12 +65,12 @@ widen_1_8_16_narrowToLargest(const Legal
   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;
 }
 

Modified: llvm/trunk/lib/Target/X86/X86LegalizerInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86LegalizerInfo.cpp?rev=323669&r1=323668&r2=323669&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86LegalizerInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86LegalizerInfo.cpp Mon Jan 29 09:37:29 2018
@@ -21,6 +21,7 @@
 
 using namespace llvm;
 using namespace TargetOpcode;
+using namespace LegalizeActions;
 
 /// FIXME: The following static functions are SizeChangeStrategy functions
 /// that are meant to temporarily mimic the behaviour of the old legalization
@@ -38,7 +39,7 @@ addAndInterleaveWithUnsupported(Legalize
     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});
   }
 }
 
@@ -46,11 +47,11 @@ static LegalizerInfo::SizeAndActionsVec
 widen_1(const LegalizerInfo::SizeAndActionsVec &v) {
   assert(v.size() >= 1);
   assert(v[0].first > 1);
-  LegalizerInfo::SizeAndActionsVec result = {{1, LegalizerInfo::WidenScalar},
-                                             {2, LegalizerInfo::Unsupported}};
+  LegalizerInfo::SizeAndActionsVec result = {{1, WidenScalar},
+                                             {2, Unsupported}};
   addAndInterleaveWithUnsupported(result, v);
   auto Largest = result.back().first;
-  result.push_back({Largest + 1, LegalizerInfo::Unsupported});
+  result.push_back({Largest + 1, Unsupported});
   return result;
 }
 

Modified: llvm/trunk/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp?rev=323669&r1=323668&r2=323669&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp Mon Jan 29 09:37:29 2018
@@ -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 @@ TEST(LegalizerInfoTest, ScalarRISC) {
   // 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,38 +62,34 @@ TEST(LegalizerInfoTest, ScalarRISC) {
   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)));
-    ASSERT_EQ(
-        L.getAction({opcode, {LLT::scalar(32)}}),
-        LegalizerInfo::LegalizeActionStep(LegalizerInfo::Legal, 0, LLT{}));
-    ASSERT_EQ(
-        L.getAction({opcode, {LLT::scalar(64)}}),
-        LegalizerInfo::LegalizeActionStep(LegalizerInfo::Legal, 0, LLT{}));
+              LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
+    ASSERT_EQ(L.getAction({opcode, {LLT::scalar(32)}}),
+              LegalizerInfo::LegalizeActionStep(Legal, 0, LLT{}));
+    ASSERT_EQ(L.getAction({opcode, {LLT::scalar(64)}}),
+              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)));
+    ASSERT_EQ(
+        L.getAction({opcode, {LLT::scalar(128)}}),
+        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)));
-    ASSERT_EQ(L.getAction({opcode, {LLT::scalar(31)}}),
-              LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0,
-                                                LLT::scalar(32)));
-    ASSERT_EQ(L.getAction({opcode, {LLT::scalar(33)}}),
-              LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0,
-                                                LLT::scalar(64)));
-    ASSERT_EQ(L.getAction({opcode, {LLT::scalar(63)}}),
-              LegalizerInfo::LegalizeActionStep(LegalizerInfo::WidenScalar, 0,
-                                                LLT::scalar(64)));
-    ASSERT_EQ(L.getAction({opcode, {LLT::scalar(65)}}),
-              LegalizerInfo::LegalizeActionStep(LegalizerInfo::NarrowScalar, 0,
-                                                LLT::scalar(64)));
+    ASSERT_EQ(
+        L.getAction({opcode, {LLT::scalar(1)}}),
+        LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
+    ASSERT_EQ(
+        L.getAction({opcode, {LLT::scalar(31)}}),
+        LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
+    ASSERT_EQ(
+        L.getAction({opcode, {LLT::scalar(33)}}),
+        LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(64)));
+    ASSERT_EQ(
+        L.getAction({opcode, {LLT::scalar(63)}}),
+        LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::scalar(64)));
+    ASSERT_EQ(
+        L.getAction({opcode, {LLT::scalar(65)}}),
+        LegalizerInfo::LegalizeActionStep(NarrowScalar, 0, LLT::scalar(64)));
   }
 }
 
@@ -100,40 +97,40 @@ TEST(LegalizerInfoTest, VectorRISC) {
   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{}));
-  ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(8, 7)}}),
-            LegalizerInfo::LegalizeActionStep(LegalizerInfo::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)));
-  ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(8, 32)}}),
-            LegalizerInfo::LegalizeActionStep(LegalizerInfo::FewerElements, 0,
-                                              LLT::vector(4, 32)));
+            LegalizerInfo::LegalizeActionStep(Legal, 0, LLT{}));
+  ASSERT_EQ(
+      L.getAction({G_ADD, {LLT::vector(8, 7)}}),
+      LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::vector(8, 8)));
+  ASSERT_EQ(
+      L.getAction({G_ADD, {LLT::vector(2, 8)}}),
+      LegalizerInfo::LegalizeActionStep(MoreElements, 0, LLT::vector(8, 8)));
+  ASSERT_EQ(
+      L.getAction({G_ADD, {LLT::vector(8, 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)));
-  ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(3, 8)}}),
-            LegalizerInfo::LegalizeActionStep(LegalizerInfo::MoreElements, 0,
-                                              LLT::vector(8, 8)));
+  ASSERT_EQ(
+      L.getAction({G_ADD, {LLT::vector(3, 3)}}),
+      LegalizerInfo::LegalizeActionStep(WidenScalar, 0, LLT::vector(3, 8)));
+  ASSERT_EQ(
+      L.getAction({G_ADD, {LLT::vector(3, 8)}}),
+      LegalizerInfo::LegalizeActionStep(MoreElements, 0, LLT::vector(8, 8)));
 }
 
 TEST(LegalizerInfoTest, MultipleTypes) {
@@ -143,8 +140,8 @@ TEST(LegalizerInfoTest, MultipleTypes) {
   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);
@@ -153,15 +150,15 @@ TEST(LegalizerInfoTest, MultipleTypes) {
 
   // 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));
-  ASSERT_EQ(L.getAction({G_PTRTOINT, {s64, LLT::pointer(0, 32)}}),
-            LegalizerInfo::LegalizeActionStep(LegalizerInfo::Unsupported, 1,
-                                              LLT::pointer(0, 32)));
+      LegalizerInfo::LegalizeActionStep(NarrowScalar, 0, s64));
+  ASSERT_EQ(
+      L.getAction({G_PTRTOINT, {s64, LLT::pointer(0, 32)}}),
+      LegalizerInfo::LegalizeActionStep(Unsupported, 1, LLT::pointer(0, 32)));
 }
 
 TEST(LegalizerInfoTest, MultipleSteps) {
@@ -172,24 +169,22 @@ TEST(LegalizerInfoTest, MultipleSteps) {
 
   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);
@@ -197,27 +192,20 @@ TEST(LegalizerInfoTest, SizeChangeStrate
 
   // 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{}));
+    ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(Size)}}),
+              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)));
 }
 }




More information about the llvm-commits mailing list