[PATCH] D32074: [mips] Change the machine verifier to allow nested call sequences.

Sagar Thakur via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 13 23:22:32 PDT 2017


slthakur created this revision.
Herald added a subscriber: arichardson.

The call to the function f2 in the test largeimmprinting.ll has a large size argument passed by value. This causes the lowering implementation to create a call to memcpy for coping the large sized argument in the argument build area.

This results in a nested call sequence which was not allowed by the machine verifier before. This patch adds a stack to save the sizes of the stack adjustments and checks if there is any mismatch.


Repository:
  rL LLVM

https://reviews.llvm.org/D32074

Files:
  lib/CodeGen/MachineVerifier.cpp
  test/CodeGen/Mips/largeimmprinting.ll


Index: test/CodeGen/Mips/largeimmprinting.ll
===================================================================
--- test/CodeGen/Mips/largeimmprinting.ll
+++ test/CodeGen/Mips/largeimmprinting.ll
@@ -1,7 +1,7 @@
-; RUN: llc -march=mipsel -relocation-model=pic < %s | FileCheck %s -check-prefix=32
-; RUN: llc -march=mips64el -mcpu=mips4 -target-abi=n64 -relocation-model=pic < %s | \
+; RUN: llc -march=mipsel -relocation-model=pic -verify-machineinstrs < %s | FileCheck %s -check-prefix=32
+; RUN: llc -march=mips64el -mcpu=mips4 -target-abi=n64 -relocation-model=pic -verify-machineinstrs < %s | \
 ; RUN:     FileCheck %s -check-prefix=64
-; RUN: llc -march=mips64el -mcpu=mips64 -target-abi=n64 -relocation-model=pic < %s | \
+; RUN: llc -march=mips64el -mcpu=mips64 -target-abi=n64 -relocation-model=pic -verify-machineinstrs < %s | \
 ; RUN:     FileCheck %s -check-prefix=64
 
 %struct.S1 = type { [65536 x i8] }
Index: lib/CodeGen/MachineVerifier.cpp
===================================================================
--- lib/CodeGen/MachineVerifier.cpp
+++ lib/CodeGen/MachineVerifier.cpp
@@ -2019,6 +2019,7 @@
     int ExitValue;
     bool EntryIsSetup;
     bool ExitIsSetup;
+    std::stack<int> FrameSetupSize;
   };
 }
 
@@ -2050,6 +2051,7 @@
       BBState.EntryIsSetup = SPState[StackPred->getNumber()].ExitIsSetup;
       BBState.ExitValue = BBState.EntryValue;
       BBState.ExitIsSetup = BBState.EntryIsSetup;
+      BBState.FrameSetupSize = SPState[StackPred->getNumber()].FrameSetupSize;
     }
 
     // Update stack state by checking contents of MBB.
@@ -2060,27 +2062,28 @@
         assert(Size >= 0 &&
           "Value should be non-negative in FrameSetup and FrameDestroy.\n");
 
-        if (BBState.ExitIsSetup)
-          report("FrameSetup is after another FrameSetup", &I);
         BBState.ExitValue -= Size;
         BBState.ExitIsSetup = true;
+        BBState.FrameSetupSize.push(Size);
       }
 
       if (I.getOpcode() == FrameDestroyOpcode) {
         // The first operand of a FrameOpcode should be i32.
         int Size = I.getOperand(0).getImm();
         assert(Size >= 0 &&
           "Value should be non-negative in FrameSetup and FrameDestroy.\n");
 
-        if (!BBState.ExitIsSetup)
-          report("FrameDestroy is not after a FrameSetup", &I);
-        int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
-                                               BBState.ExitValue;
-        if (BBState.ExitIsSetup && AbsSPAdj != Size) {
-          report("FrameDestroy <n> is after FrameSetup <m>", &I);
-          errs() << "FrameDestroy <" << Size << "> is after FrameSetup <"
-              << AbsSPAdj << ">.\n";
+        if (!BBState.FrameSetupSize.empty())
+        {
+          if (BBState.FrameSetupSize.top() != Size) {
+            report("FrameDestroy <n> is after FrameSetup <m>", &I);
+            errs() << "FrameDestroy <" << Size << "> is after FrameSetup <"
+                << BBState.FrameSetupSize.top() << ">.\n";
+          }
+          BBState.FrameSetupSize.pop();
         }
+        else
+          report("FrameDestroy is not after a FrameSetup", &I);
         BBState.ExitValue += Size;
         BBState.ExitIsSetup = false;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32074.95272.patch
Type: text/x-patch
Size: 3221 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170414/44027018/attachment.bin>


More information about the llvm-commits mailing list