[PATCH] D88705: [MC] Assert that MCRegUnitIterator operates over MCRegisters

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 13:18:44 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG0a3523299dec: [MC] Assert that MCRegUnitIterator operates over MCRegisters (authored by mtrofin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88705

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


Index: llvm/include/llvm/MC/MCRegisterInfo.h
===================================================================
--- llvm/include/llvm/MC/MCRegisterInfo.h
+++ llvm/include/llvm/MC/MCRegisterInfo.h
@@ -675,6 +675,7 @@
 
   MCRegUnitIterator(MCRegister Reg, const MCRegisterInfo *MCRI) {
     assert(Reg && "Null register has no regunits");
+    assert(MCRegister::isPhysicalRegister(Reg.id()));
     // Decode the RegUnits MCRegisterDesc field.
     unsigned RU = MCRI->get(Reg).RegUnits;
     unsigned Scale = RU & 15;
Index: llvm/include/llvm/MC/MCRegister.h
===================================================================
--- llvm/include/llvm/MC/MCRegister.h
+++ llvm/include/llvm/MC/MCRegister.h
@@ -68,6 +68,12 @@
     return Reg;
   }
 
+  /// Check the provided unsigned value is a valid MCRegister.
+  static MCRegister from(unsigned Val) {
+    assert(Val == NoRegister || isPhysicalRegister(Val));
+    return MCRegister(Val);
+  }
+
   unsigned id() const {
     return Reg;
   }
Index: llvm/include/llvm/CodeGen/Register.h
===================================================================
--- llvm/include/llvm/CodeGen/Register.h
+++ llvm/include/llvm/CodeGen/Register.h
@@ -110,6 +110,15 @@
     return MCRegister(Reg);
   }
 
+  /// Utility to check-convert this value to a MCRegister. The caller is
+  /// expected to have already validated that this Register is, indeed,
+  /// physical.
+  MCRegister asMCReg() const {
+    assert(Reg == MCRegister::NoRegister ||
+           MCRegister::isPhysicalRegister(Reg));
+    return MCRegister(Reg);
+  }
+
   bool isValid() const { return Reg != MCRegister::NoRegister; }
 
   /// Comparisons between register objects


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88705.296003.patch
Type: text/x-patch
Size: 1685 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201003/c3d1d9b3/attachment.bin>


More information about the llvm-commits mailing list