From: Dan Gohman Date: Fri, 20 Nov 2015 02:33:24 +0000 (+0000) Subject: [WebAssembly] Add asserts that the expression stack is used in stack order. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=74a34413f8b2ccd9b1f75d362919a6fb253d7441 [WebAssembly] Add asserts that the expression stack is used in stack order. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253638 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp b/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp index b6f20378221..5ba7c314908 100644 --- a/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp +++ b/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp @@ -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 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; }