[llvm] r352143 - GlobalISel: Add convenience mutatations to scalarize

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 24 16:51:00 PST 2019


Author: arsenm
Date: Thu Jan 24 16:51:00 2019
New Revision: 352143

URL: http://llvm.org/viewvc/llvm-project?rev=352143&view=rev
Log:
GlobalISel: Add convenience mutatations to scalarize

Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
    llvm/trunk/lib/CodeGen/GlobalISel/LegalityPredicates.cpp
    llvm/trunk/lib/CodeGen/GlobalISel/LegalizeMutations.cpp
    llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp
    llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

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=352143&r1=352142&r2=352143&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h Thu Jan 24 16:51:00 2019
@@ -204,6 +204,8 @@ LegalityPredicate typePairAndMemSizeInSe
     std::initializer_list<TypePairAndMemSize> TypesAndMemSizeInit);
 /// True iff the specified type index is a scalar.
 LegalityPredicate isScalar(unsigned TypeIdx);
+/// True iff the specified type index is a vector.
+LegalityPredicate isVector(unsigned TypeIdx);
 /// True iff the specified type index is a pointer (with any address space).
 LegalityPredicate isPointer(unsigned TypeIdx);
 /// True iff the specified type index is a pointer with the specified address
@@ -240,6 +242,8 @@ LegalizeMutation widenScalarToNextPow2(u
 /// Add more elements to the type for the given type index to the next power of
 /// 2.
 LegalizeMutation moreElementsToNextPow2(unsigned TypeIdx, unsigned Min = 0);
+/// Break up the vector type for the given type index into the element type.
+LegalizeMutation scalarize(unsigned TypeIdx);
 } // end namespace LegalizeMutations
 
 /// A single rule in a legalizer info ruleset.
@@ -617,6 +621,12 @@ public:
                     Mutation);
   }
 
+  LegalizeRuleSet &scalarize(unsigned TypeIdx) {
+    using namespace LegalityPredicates;
+    return actionIf(LegalizeAction::FewerElements, isVector(typeIdx(TypeIdx)),
+                    LegalizeMutations::scalarize(TypeIdx));
+  }
+
   /// Ensure the scalar is at least as wide as Ty.
   LegalizeRuleSet &minScalar(unsigned TypeIdx, const LLT &Ty) {
     using namespace LegalityPredicates;

Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalityPredicates.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalityPredicates.cpp?rev=352143&r1=352142&r2=352143&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalityPredicates.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalityPredicates.cpp Thu Jan 24 16:51:00 2019
@@ -56,6 +56,12 @@ LegalityPredicate LegalityPredicates::is
   };
 }
 
+LegalityPredicate LegalityPredicates::isVector(unsigned TypeIdx) {
+  return [=](const LegalityQuery &Query) {
+    return Query.Types[TypeIdx].isVector();
+  };
+}
+
 LegalityPredicate LegalityPredicates::isPointer(unsigned TypeIdx) {
   return [=](const LegalityQuery &Query) {
     return Query.Types[TypeIdx].isPointer();

Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalizeMutations.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalizeMutations.cpp?rev=352143&r1=352142&r2=352143&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalizeMutations.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalizeMutations.cpp Thu Jan 24 16:51:00 2019
@@ -48,3 +48,9 @@ LegalizeMutation LegalizeMutations::more
         TypeIdx, LLT::vector(NewNumElements, VecTy.getScalarSizeInBits()));
   };
 }
+
+LegalizeMutation LegalizeMutations::scalarize(unsigned TypeIdx) {
+  return [=](const LegalityQuery &Query) {
+    return std::make_pair(TypeIdx, Query.Types[TypeIdx].getElementType());
+  };
+}

Modified: llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp?rev=352143&r1=352142&r2=352143&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp Thu Jan 24 16:51:00 2019
@@ -23,6 +23,7 @@
 
 using namespace llvm;
 using namespace LegalizeActions;
+using namespace LegalizeMutations;
 using namespace LegalityPredicates;
 
 AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST) {
@@ -358,11 +359,6 @@ AArch64LegalizerInfo::AArch64LegalizerIn
       }
       return false;
     };
-    auto scalarize =
-        [](const LegalityQuery &Query, unsigned TypeIdx) {
-          const LLT &Ty = Query.Types[TypeIdx];
-          return std::make_pair(TypeIdx, Ty.getElementType());
-        };
 
     // FIXME: This rule is horrible, but specifies the same as what we had
     // before with the particularly strange definitions removed (e.g.
@@ -376,10 +372,10 @@ AArch64LegalizerInfo::AArch64LegalizerIn
         // Break up vectors with weird elements into scalars
         .fewerElementsIf(
             [=](const LegalityQuery &Query) { return notValidElt(Query, 0); },
-            [=](const LegalityQuery &Query) { return scalarize(Query, 0); })
+            scalarize(0))
         .fewerElementsIf(
             [=](const LegalityQuery &Query) { return notValidElt(Query, 1); },
-            [=](const LegalityQuery &Query) { return scalarize(Query, 1); })
+            scalarize(1))
         // Clamp the big scalar to s8-s512 and make it either a power of 2, 192,
         // or 384.
         .clampScalar(BigTyIdx, s8, s512)
@@ -420,16 +416,8 @@ AArch64LegalizerInfo::AArch64LegalizerIn
           return BigTy.getSizeInBits() % LitTy.getSizeInBits() == 0;
         })
         // Any vectors left are the wrong size. Scalarize them.
-        .fewerElementsIf([](const LegalityQuery &Query) { return true; },
-                         [](const LegalityQuery &Query) {
-                           return std::make_pair(
-                               0, Query.Types[0].getElementType());
-                         })
-        .fewerElementsIf([](const LegalityQuery &Query) { return true; },
-                         [](const LegalityQuery &Query) {
-                           return std::make_pair(
-                               1, Query.Types[1].getElementType());
-                         });
+      .scalarize(0)
+      .scalarize(1);
   }
 
   getActionDefinitionsBuilder(G_EXTRACT_VECTOR_ELT)

Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp?rev=352143&r1=352142&r2=352143&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp Thu Jan 24 16:51:00 2019
@@ -22,17 +22,13 @@
 
 using namespace llvm;
 using namespace LegalizeActions;
+using namespace LegalizeMutations;
 using namespace LegalityPredicates;
 
 AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST,
                                          const GCNTargetMachine &TM) {
   using namespace TargetOpcode;
 
-  auto scalarize = [=](const LegalityQuery &Query, unsigned TypeIdx) {
-    const LLT &Ty = Query.Types[TypeIdx];
-    return std::make_pair(TypeIdx, Ty.getElementType());
-  };
-
   auto GetAddrSpacePtr = [&TM](unsigned AS) {
     return LLT::pointer(AS, TM.getPointerSizeInBits(AS));
   };
@@ -144,9 +140,7 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo
 
   getActionDefinitionsBuilder({G_FADD, G_FMUL, G_FNEG, G_FABS, G_FMA})
       .legalFor({S32, S64})
-      .fewerElementsIf(
-          [=](const LegalityQuery &Query) { return Query.Types[0].isVector(); },
-          [=](const LegalityQuery &Query) { return scalarize(Query, 0); })
+      .scalarize(0)
       .clampScalar(0, S32, S64);
 
   getActionDefinitionsBuilder(G_FPTRUNC)
@@ -161,9 +155,7 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo
       .legalFor({S32})
       // Must use fadd + fneg
       .lowerFor({S64, S16, V2S16})
-      .fewerElementsIf(
-          [=](const LegalityQuery &Query) { return Query.Types[0].isVector(); },
-          [=](const LegalityQuery &Query) { return scalarize(Query, 0); })
+      .scalarize(0)
       .clampScalar(0, S32, S64);
 
   setAction({G_FCMP, S1}, Legal);
@@ -272,7 +264,8 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo
   // TODO: Pointer types, any 32-bit or 64-bit vector
   getActionDefinitionsBuilder(G_SELECT)
     .legalFor({{S32, S1}, {S64, S1}, {V2S32, S1}, {V2S16, S1}})
-    .clampScalar(0, S32, S64);
+    .clampScalar(0, S32, S64)
+    .scalarize(0);
 
   // TODO: Only the low 4/5/6 bits of the shift amount are observed, so we can
   // be more flexible with the shift amount type.
@@ -367,10 +360,10 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo
       // Break up vectors with weird elements into scalars
       .fewerElementsIf(
         [=](const LegalityQuery &Query) { return notValidElt(Query, 0); },
-        [=](const LegalityQuery &Query) { return scalarize(Query, 0); })
+        scalarize(0))
       .fewerElementsIf(
         [=](const LegalityQuery &Query) { return notValidElt(Query, 1); },
-        [=](const LegalityQuery &Query) { return scalarize(Query, 1); })
+        scalarize(1))
       .clampScalar(BigTyIdx, S32, S512)
       .widenScalarIf(
         [=](const LegalityQuery &Query) {
@@ -410,21 +403,8 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo
                  BigTy.getSizeInBits() <= 512;
         })
       // Any vectors left are the wrong size. Scalarize them.
-      .fewerElementsIf([](const LegalityQuery &Query) {
-          return Query.Types[0].isVector();
-        },
-        [](const LegalityQuery &Query) {
-          return std::make_pair(
-            0, Query.Types[0].getElementType());
-        })
-      .fewerElementsIf([](const LegalityQuery &Query) {
-          return Query.Types[1].isVector();
-        },
-        [](const LegalityQuery &Query) {
-          return std::make_pair(
-            1, Query.Types[1].getElementType());
-        });
-
+      .scalarize(0)
+      .scalarize(1);
   }
 
   computeTables();




More information about the llvm-commits mailing list