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

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 10:46:42 PDT 2020


mtrofin created this revision.
mtrofin added reviewers: qcolombet, dsanders.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
mtrofin requested review of this revision.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88598

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


Index: llvm/include/llvm/MC/MCRegister.h
===================================================================
--- llvm/include/llvm/MC/MCRegister.h
+++ llvm/include/llvm/MC/MCRegister.h
@@ -46,9 +46,6 @@
   /// 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 @@
   /// 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
Index: llvm/include/llvm/CodeGen/Register.h
===================================================================
--- llvm/include/llvm/CodeGen/Register.h
+++ llvm/include/llvm/CodeGen/Register.h
@@ -40,10 +40,6 @@
   /// 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 @@
   /// 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88598.295351.patch
Type: text/x-patch
Size: 2230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200930/34001ef1/attachment.bin>


More information about the llvm-commits mailing list