[PATCH] D65599: Add MCRegister and use it in MCRegisterClass::contains()

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 2 12:37:00 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL367711: Add MCRegister and use it in MCRegisterClass::contains() (authored by dsanders, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D65599?vs=212877&id=213112#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65599/new/

https://reviews.llvm.org/D65599

Files:
  llvm/trunk/include/llvm/CodeGen/Register.h
  llvm/trunk/include/llvm/MC/MCRegister.h
  llvm/trunk/include/llvm/MC/MCRegisterInfo.h


Index: llvm/trunk/include/llvm/MC/MCRegister.h
===================================================================
--- llvm/trunk/include/llvm/MC/MCRegister.h
+++ llvm/trunk/include/llvm/MC/MCRegister.h
@@ -14,10 +14,12 @@
 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 @@
     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: llvm/trunk/include/llvm/MC/MCRegisterInfo.h
===================================================================
--- llvm/trunk/include/llvm/MC/MCRegisterInfo.h
+++ llvm/trunk/include/llvm/MC/MCRegisterInfo.h
@@ -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 @@
 
   /// 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);
   }
 
Index: llvm/trunk/include/llvm/CodeGen/Register.h
===================================================================
--- llvm/trunk/include/llvm/CodeGen/Register.h
+++ llvm/trunk/include/llvm/CodeGen/Register.h
@@ -105,6 +105,10 @@
     return Reg;
   }
 
+  operator MCRegister() const {
+    return MCRegister(Reg);
+  }
+
   bool isValid() const {
     return Reg != 0;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65599.213112.patch
Type: text/x-patch
Size: 2715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190802/2a17ac17/attachment.bin>


More information about the llvm-commits mailing list