[llvm] 17640c5 - [NFC] Let (MC)Register APIs check isStackSlot

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 09:55:35 PDT 2020


Author: Mircea Trofin
Date: 2020-10-01T09:55:20-07:00
New Revision: 17640c5aac649c154959ca1075953f0d252a4a5b

URL: https://github.com/llvm/llvm-project/commit/17640c5aac649c154959ca1075953f0d252a4a5b
DIFF: https://github.com/llvm/llvm-project/commit/17640c5aac649c154959ca1075953f0d252a4a5b.diff

LOG: [NFC] Let (MC)Register APIs check isStackSlot

The user is expected to make the isStackSlot check before calling isPhysicalRegister
or isVirtualRegister. The APIs assert otherwise. We can improve the usability
of these APIs by carrying out the check in the 2 APIs: they become a
complete "source of truth" and remove an extra responsibility from the
user.

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

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/Register.h
    llvm/include/llvm/MC/MCRegister.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/Register.h b/llvm/include/llvm/CodeGen/Register.h
index 054040cd29a1..884c8bc7dc2e 100644
--- a/llvm/include/llvm/CodeGen/Register.h
+++ b/llvm/include/llvm/CodeGen/Register.h
@@ -40,10 +40,6 @@ class Register {
   /// frame index in a variable that normally holds a register. isStackSlot()
   /// returns true if Reg is in the range used for stack slots.
   ///
-  /// Note that isVirtualRegister() and isPhysicalRegister() cannot handle stack
-  /// slots, so if a variable may contains a stack slot, always check
-  /// isStackSlot() first.
-  ///
   static bool isStackSlot(unsigned Reg) {
     return MCRegister::isStackSlot(Reg);
   }
@@ -69,8 +65,7 @@ class Register {
   /// Return true if the specified register number is in
   /// the virtual register namespace.
   static bool isVirtualRegister(unsigned Reg) {
-    assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
-    return Reg & MCRegister::VirtualRegFlag;
+    return Reg & MCRegister::VirtualRegFlag && !isStackSlot(Reg);
   }
 
   /// Convert a virtual register number to a 0-based index.

diff  --git a/llvm/include/llvm/MC/MCRegister.h b/llvm/include/llvm/MC/MCRegister.h
index 1f3c4b8494cc..5f2e31b70fd8 100644
--- a/llvm/include/llvm/MC/MCRegister.h
+++ b/llvm/include/llvm/MC/MCRegister.h
@@ -46,9 +46,6 @@ class MCRegister {
   /// register. StackSlot values do not exist in the MC layer, see
   /// Register::isStackSlot() for the more information on them.
   ///
-  /// Note that isVirtualRegister() and isPhysicalRegister() cannot handle stack
-  /// slots, so if a variable may contains a stack slot, always check
-  /// isStackSlot() first.
   static bool isStackSlot(unsigned Reg) {
     return !(Reg & VirtualRegFlag) &&
            uint32_t(Reg & ~VirtualRegFlag) >= FirstStackSlot;
@@ -57,8 +54,8 @@ class MCRegister {
   /// Return true if the specified register number is in
   /// the physical register namespace.
   static bool isPhysicalRegister(unsigned Reg) {
-    assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
-    return Reg >= FirstPhysicalReg && !(Reg & VirtualRegFlag);
+    return Reg >= FirstPhysicalReg && !(Reg & VirtualRegFlag) &&
+           !isStackSlot(Reg);
   }
 
   /// Return true if the specified register number is in the physical register


        


More information about the llvm-commits mailing list