]> granicus.if.org Git - llvm/commitdiff
Add MCRegister and use it in MCRegisterClass::contains()
authorDaniel Sanders <daniel_l_sanders@apple.com>
Fri, 2 Aug 2019 19:37:17 +0000 (19:37 +0000)
committerDaniel Sanders <daniel_l_sanders@apple.com>
Fri, 2 Aug 2019 19:37:17 +0000 (19:37 +0000)
Summary:
Register can cast to MCRegister and we may want to consider asserting
!isValid() || isPhysical() when expensive checks are on.

Depends on D65554

Reviewers: arsenm

Subscribers: wdng, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65599

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

include/llvm/CodeGen/Register.h
include/llvm/MC/MCRegister.h
include/llvm/MC/MCRegisterInfo.h

index 8c06150f9600ab3a908f29162bef8a42cf381322..b83a6264c80acc18581386c2c993bf699d202309 100644 (file)
@@ -105,6 +105,10 @@ public:
     return Reg;
   }
 
+  operator MCRegister() const {
+    return MCRegister(Reg);
+  }
+
   bool isValid() const {
     return Reg != 0;
   }
index 57a4f43d431839d5bcd9163fe14a9454dd60dd3d..bcb9f387111ecd3e435cfb17f1b02ded68ade538 100644 (file)
 namespace llvm {
 
 /// Wrapper class representing physical registers. Should be passed by value.
-/// Note that this class is not fully implemented at this time. A more complete
-/// implementation will follow.
 class MCRegister {
+  unsigned Reg;
+
 public:
+  MCRegister(unsigned Val = 0): Reg(Val) {}
+
   // Register numbers can represent physical registers, virtual registers, and
   // sometimes stack slots. The unsigned values are divided into these ranges:
   //
@@ -46,9 +48,22 @@ public:
     assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
     return int(Reg) > 0;
   }
+
+  /// Return true if the specified register number is in the physical register
+  /// namespace.
+  bool isPhysical() const {
+    return isPhysicalRegister(Reg);
+  }
+
+  operator unsigned() const {
+    return Reg;
+  }
+
+  bool isValid() const {
+    return Reg != 0;
+  }
 };
 
 }
 
 #endif // ifndef LLVM_MC_REGISTER_H
-
index 92d39c3fcfb7e3fd70a0bc5e42c7527e64daf843..4db7619df61ae2c61ea6f709627642bf9b10170d 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/MC/LaneBitmask.h"
+#include "llvm/MC/MCRegister.h"
 #include <cassert>
 #include <cstdint>
 #include <utility>
@@ -65,16 +66,17 @@ public:
 
   /// contains - Return true if the specified register is included in this
   /// register class.  This does not include virtual registers.
-  bool contains(unsigned Reg) const {
-    unsigned InByte = Reg % 8;
-    unsigned Byte = Reg / 8;
+  bool contains(MCRegister Reg) const {
+    unsigned RegNo = unsigned(Reg);
+    unsigned InByte = RegNo % 8;
+    unsigned Byte = RegNo / 8;
     if (Byte >= RegSetSize)
       return false;
     return (RegSet[Byte] & (1 << InByte)) != 0;
   }
 
   /// contains - Return true if both registers are in this class.
-  bool contains(unsigned Reg1, unsigned Reg2) const {
+  bool contains(MCRegister Reg1, MCRegister Reg2) const {
     return contains(Reg1) && contains(Reg2);
   }