]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Don't emit epilogue code in the middle of stackified code.
authorDan Gohman <dan433584@gmail.com>
Thu, 5 May 2016 20:41:15 +0000 (20:41 +0000)
committerDan Gohman <dan433584@gmail.com>
Thu, 5 May 2016 20:41:15 +0000 (20:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268679 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp
test/CodeGen/WebAssembly/reg-stackify.ll

index 549958158eb82d51a57605b2015781b43a104d7e..2e50c7e6c9fa6481e4e9dd3be56baaf26c1f67c2 100644 (file)
@@ -72,6 +72,7 @@ bool WebAssemblyFrameLowering::needsSP(const MachineFunction &MF,
 /// false, the stack red zone can be used and only a local SP is needed.
 bool WebAssemblyFrameLowering::needsSPWriteback(
     const MachineFunction &MF, const MachineFrameInfo &MFI) const {
+  assert(needsSP(MF, MFI));
   return MFI.getStackSize() > RedZoneSize || MFI.hasCalls() ||
          MF.getFunction()->hasFnAttribute(Attribute::NoRedZone);
 }
@@ -190,6 +191,13 @@ void WebAssemblyFrameLowering::emitEpilogue(MachineFunction &MF,
 
   if (InsertPt != MBB.end()) {
     DL = InsertPt->getDebugLoc();
+
+    // If code has been stackified with the return, disconnect it so that we
+    // don't break the tree when we insert code just before the return.
+    if (InsertPt->isReturn() && InsertPt->getNumExplicitOperands() != 0) {
+      WebAssemblyFunctionInfo &MFI = *MF.getInfo<WebAssemblyFunctionInfo>();
+      MFI.unstackifyVReg(InsertPt->getOperand(0).getReg());
+    }
   }
 
   // Restore the stack pointer. If we had fixed-size locals, add the offset
index 76ea0d72f6db686e145e5b1c281d916fd1325e83..d508d448d71f964bd7e6ae97bc1c1183b4ae869a 100644 (file)
@@ -108,7 +108,8 @@ bool WebAssemblyRegNumbering::runOnMachineFunction(MachineFunction &MF) {
     }
   }
   // Allocate locals for used physical registers
-  bool HasFP = MF.getSubtarget().getFrameLowering()->hasFP(MF);
+  bool HasFP =
+      MF.getSubtarget<WebAssemblySubtarget>().getFrameLowering()->hasFP(MF);
   if (FrameInfo.getStackSize() > 0 || FrameInfo.adjustsStack() || HasFP) {
     DEBUG(dbgs() << "PReg SP " << CurReg << "\n");
     MFI.addPReg(WebAssembly::SP32, CurReg++);
index c9814cce3506587cf401e9c8e1e57f6e56b56172..4c667d58eb94e4ec6e64505cde5fb8ba6b11caeb 100644 (file)
@@ -357,6 +357,18 @@ define void @ignore_dbg_value() {
   unreachable
 }
 
+; Don't stackify an expression that might use the stack into a return, since we
+; might insert a prologue before the return.
+
+; CHECK-LABEL: no_stackify_past_epilogue:
+; CHECK: return ${{[0-9]+}}{{$}}
+declare i32 @use_memory(i32*)
+define i32 @no_stackify_past_epilogue() {
+  %x = alloca i32
+  %call = call i32 @use_memory(i32* %x)
+  ret i32 %call
+}
+
 !llvm.module.flags = !{!0}
 !llvm.dbg.cu = !{!1}