]> granicus.if.org Git - llvm/commitdiff
[MIR-Canon] Skip the first N vreg names lazily.
authorPuyan Lotfi <puyan@puyan.org>
Fri, 31 May 2019 06:02:38 +0000 (06:02 +0000)
committerPuyan Lotfi <puyan@puyan.org>
Fri, 31 May 2019 06:02:38 +0000 (06:02 +0000)
This consolidates the vreg skip code into one function (SkipVRegs()).
SkipVRegs() now knows if it should skip as if it is the first initialization or
subsequent skips.

The first skip is also done the first time createVirtualRegister is called by
the cursor instead of by the cursor's constructor. This prevents verifier
errors on machine functions that have no vregs (where the verifier will
complain that there are vregs when the function uses none).

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

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

lib/CodeGen/MIRCanonicalizerPass.cpp
test/CodeGen/MIR/AArch64/multiple-lhs-operands.mir

index d36c0c89ba0b13169f945c353c36e9ab6fb014fa..a4097232d7d5921b0b59a0d7c6fb499926f3415d 100644 (file)
@@ -483,18 +483,14 @@ class NamedVRegCursor {
   unsigned virtualVRegNumber;
 
 public:
-  NamedVRegCursor(MachineRegisterInfo &MRI) : MRI(MRI) {
-    unsigned VRegGapIndex = 0;
-    const unsigned VR_GAP = (++VRegGapIndex * 1000);
-
-    unsigned I = MRI.createIncompleteVirtualRegister();
-    const unsigned E = (((I + VR_GAP) / VR_GAP) + 1) * VR_GAP;
-
-    virtualVRegNumber = E;
-  }
+  NamedVRegCursor(MachineRegisterInfo &MRI) : MRI(MRI), virtualVRegNumber(0) {}
 
   void SkipVRegs() {
     unsigned VRegGapIndex = 1;
+    if (!virtualVRegNumber) {
+      VRegGapIndex = 0;
+      virtualVRegNumber = MRI.createIncompleteVirtualRegister();
+    }
     const unsigned VR_GAP = (++VRegGapIndex * 1000);
 
     unsigned I = virtualVRegNumber;
@@ -511,6 +507,8 @@ public:
   }
 
   unsigned createVirtualRegister(unsigned VReg) {
+    if (!virtualVRegNumber)
+      SkipVRegs();
     std::string S;
     raw_string_ostream OS(S);
     OS << "namedVReg" << (virtualVRegNumber & ~0x80000000);
index 5f4bd9897d8b7ffd386cbca38f7218781bf7e303..1437e975596d8e1fb1bf311ae50674e11a81cbab 100644 (file)
@@ -2,6 +2,9 @@
 # This test ensures that the MIR parser can parse multiple register machine
 # operands before '='.
 
+# This tests that a MIR file with no vregs does not get altered by mir-canon.
+# RUN: llc -mtriple=aarch64 -o - -run-pass mir-canonicalizer -verify-machineinstrs %s
+
 --- |
 
   declare void @foo()