[WebAssembly] Add asserts that the expression stack is used in stack order.
authorDan Gohman <dan433584@gmail.com>
Fri, 20 Nov 2015 02:33:24 +0000 (02:33 +0000)
committerDan Gohman <dan433584@gmail.com>
Fri, 20 Nov 2015 02:33:24 +0000 (02:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253638 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyRegStackify.cpp

index b6f2037..5ba7c31 100644 (file)
@@ -177,5 +177,28 @@ bool WebAssemblyRegStackify::runOnMachineFunction(MachineFunction &MF) {
       MBB.addLiveIn(WebAssembly::EXPR_STACK);
   }
 
+#ifndef NDEBUG
+  // Verify that pushes and pops are performed in FIFO order.
+  SmallVector<unsigned, 0> Stack;
+  for (MachineBasicBlock &MBB : MF) {
+    for (MachineInstr &MI : MBB) {
+      for (MachineOperand &MO : reverse(MI.explicit_operands())) {
+        if (!MO.isReg()) continue;
+        unsigned VReg = MO.getReg();
+
+        if (MFI.isVRegStackified(VReg)) {
+          if (MO.isDef())
+            Stack.push_back(VReg);
+          else
+            assert(Stack.pop_back_val() == VReg);
+        }
+      }
+    }
+    // TODO: Generalize this code to support keeping values on the stack across
+    // basic block boundaries.
+    assert(Stack.empty());
+  }
+#endif
+
   return Changed;
 }