[llvm] r268679 - [WebAssembly] Don't emit epilogue code in the middle of stackified code.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Thu May 5 13:41:16 PDT 2016
Author: djg
Date: Thu May 5 15:41:15 2016
New Revision: 268679
URL: http://llvm.org/viewvc/llvm-project?rev=268679&view=rev
Log:
[WebAssembly] Don't emit epilogue code in the middle of stackified code.
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp
llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp?rev=268679&r1=268678&r2=268679&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp Thu May 5 15:41:15 2016
@@ -72,6 +72,7 @@ bool WebAssemblyFrameLowering::needsSP(c
/// 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::emitEpilo
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
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp?rev=268679&r1=268678&r2=268679&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp Thu May 5 15:41:15 2016
@@ -108,7 +108,8 @@ bool WebAssemblyRegNumbering::runOnMachi
}
}
// 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++);
Modified: llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll?rev=268679&r1=268678&r2=268679&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll Thu May 5 15:41:15 2016
@@ -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}
More information about the llvm-commits
mailing list