]> granicus.if.org Git - llvm/commitdiff
Implement LaneBitmask::getNumLanes and LaneBitmask::getHighestLane
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Thu, 20 Jul 2017 19:43:19 +0000 (19:43 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Thu, 20 Jul 2017 19:43:19 +0000 (19:43 +0000)
This should eliminate most uses of countPopulation and Log2_32 on
the lane mask values.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308658 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/LaneBitmask.h
lib/CodeGen/SplitKit.cpp
lib/Target/AMDGPU/GCNRegPressure.cpp
lib/Target/AMDGPU/SIRegisterInfo.cpp
utils/TableGen/CodeGenRegisters.cpp

index 73b987b074dba1a2747adb8ba96e676f3665df80..35f472d817a082ae7c1699d8db46a066ddc4c337 100644 (file)
@@ -73,6 +73,13 @@ namespace llvm {
 
     constexpr Type getAsInteger() const { return Mask; }
 
+    unsigned getNumLanes() const {
+      return countPopulation(Mask);
+    }
+    unsigned getHighestLane() const {
+      return Log2_32(Mask);
+    }
+
     static LaneBitmask getNone() { return LaneBitmask(0); }
     static LaneBitmask getAll()  { return ~LaneBitmask(0); }
     static LaneBitmask getLane(unsigned Lane) {
index 323045fd2aaae12b2fec94873f12a8c4a1e9187f..aaaa342b520b1a8e55554c9ce1ca438f7e52500c 100644 (file)
@@ -552,7 +552,7 @@ SlotIndex SplitEditor::buildCopy(unsigned FromReg, unsigned ToReg,
     if ((SubRegMask & ~LaneMask).any())
       continue;
 
-    unsigned PopCount = countPopulation(SubRegMask.getAsInteger());
+    unsigned PopCount = SubRegMask.getNumLanes();
     PossibleIndexes.push_back(Idx);
     if (PopCount > BestCover) {
       BestCover = PopCount;
@@ -583,8 +583,8 @@ SlotIndex SplitEditor::buildCopy(unsigned FromReg, unsigned ToReg,
 
       // Try to cover as much of the remaining lanes as possible but
       // as few of the already covered lanes as possible.
-      int Cover = countPopulation((SubRegMask & LanesLeft).getAsInteger())
-                - countPopulation((SubRegMask & ~LanesLeft).getAsInteger());
+      int Cover = (SubRegMask & LanesLeft).getNumLanes()
+                - (SubRegMask & ~LanesLeft).getNumLanes();
       if (Cover > BestCover) {
         BestCover = Cover;
         BestIdx = Idx;
index 09cac8c2c8f1f9cc720d5977113239eab234776d..0384340174febc49d8bf43b71c4eb67159cb942a 100644 (file)
@@ -107,7 +107,7 @@ void GCNRegPressure::inc(unsigned Reg,
     assert(PrevMask < NewMask);
 
     Value[Kind == SGPR_TUPLE ? SGPR32 : VGPR32] +=
-      Sign * countPopulation((~PrevMask & NewMask).getAsInteger());
+      Sign * (~PrevMask & NewMask).getNumLanes();
 
     if (PrevMask.none()) {
       assert(NewMask.any());
index 4a3fbb4593bb34dd1c02586605f5ccc10aa2ec86..d9a5ce338bfe83ea5882973e847ae77f1d359dbc 100644 (file)
@@ -1275,8 +1275,7 @@ const TargetRegisterClass *SIRegisterInfo::getSubRegClass(
     return RC;
 
   // We can assume that each lane corresponds to one 32-bit register.
-  LaneBitmask::Type Mask = getSubRegIndexLaneMask(SubIdx).getAsInteger();
-  unsigned Count = countPopulation(Mask);
+  unsigned Count = getSubRegIndexLaneMask(SubIdx).getNumLanes();
   if (isSGPRClass(RC)) {
     switch (Count) {
     case 1:
index 6399fb5ec1ddc78108d6868cb89caec8324c4865..77450aef9a5ca4b8761f9bd2a574ae8359d70df5 100644 (file)
@@ -1295,9 +1295,7 @@ void CodeGenRegBank::computeSubRegLaneMasks() {
       // Moving from a class with no subregisters we just had a single lane:
       // The subregister must be a leaf subregister and only occupies 1 bit.
       // Move the bit from the class without subregisters into that position.
-      static_assert(sizeof(Idx.LaneMask.getAsInteger()) == 4,
-                    "Change Log2_32 to a proper one");
-      unsigned DstBit = Log2_32(Idx.LaneMask.getAsInteger());
+      unsigned DstBit = Idx.LaneMask.getHighestLane();
       assert(Idx.LaneMask == LaneBitmask::getLane(DstBit) &&
              "Must be a leaf subregister");
       MaskRolPair MaskRol = { LaneBitmask::getLane(0), (uint8_t)DstBit };
@@ -1328,9 +1326,7 @@ void CodeGenRegBank::computeSubRegLaneMasks() {
         assert(Composite->getComposites().empty());
 
         // Create Mask+Rotate operation and merge with existing ops if possible.
-        static_assert(sizeof(Composite->LaneMask.getAsInteger()) == 4,
-                      "Change Log2_32 to a proper one");
-        unsigned DstBit = Log2_32(Composite->LaneMask.getAsInteger());
+        unsigned DstBit = Composite->LaneMask.getHighestLane();
         int Shift = DstBit - SrcBit;
         uint8_t RotateLeft = Shift >= 0 ? (uint8_t)Shift
                                         : LaneBitmask::BitWidth + Shift;