diff options
author | Heejin Ahn <aheejin@gmail.com> | 2018-08-21 21:23:07 +0000 |
---|---|---|
committer | Heejin Ahn <aheejin@gmail.com> | 2018-08-21 21:23:07 +0000 |
commit | 78d191089182842f6360547c48993e44de9e1437 (patch) | |
tree | 4c74fb81a64effca22778f64765ad7585e9630b6 /llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp | |
parent | 1d78503f6a3c71d9862d5009224cba27b237a883 (diff) | |
download | bcm5719-llvm-78d191089182842f6360547c48993e44de9e1437.tar.gz bcm5719-llvm-78d191089182842f6360547c48993e44de9e1437.zip |
[WebAssembly] Restore __stack_pointer after catch instructions
Summary:
After the stack is unwound due to a thrown exception, the
`__stack_pointer` global can point to an invalid address. This inserts
instructions that restore `__stack_pointer` global.
Reviewers: jgravelle-google, dschuff
Subscribers: mgorny, sbc100, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D50980
llvm-svn: 340339
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp index ace2f0ecc20..9e33ed75f93 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp @@ -30,6 +30,7 @@ #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineModuleInfoImpls.h" #include "llvm/CodeGen/MachineRegisterInfo.h" +#include "llvm/MC/MCAsmInfo.h" #include "llvm/Support/Debug.h" using namespace llvm; @@ -78,13 +79,23 @@ bool WebAssemblyFrameLowering::hasReservedCallFrame( return !MF.getFrameInfo().hasVarSizedObjects(); } +// In function with EH pads, we need to make a copy of the value of +// __stack_pointer global in SP32 register, in order to use it when restoring +// __stack_pointer after an exception is caught. +bool WebAssemblyFrameLowering::needsPrologForEH( + const MachineFunction &MF) const { + auto EHType = MF.getTarget().getMCAsmInfo()->getExceptionHandlingType(); + return EHType == ExceptionHandling::Wasm && + MF.getFunction().hasPersonalityFn() && MF.getFrameInfo().hasCalls(); +} /// Returns true if this function needs a local user-space stack pointer. /// Unlike a machine stack pointer, the wasm user stack pointer is a global /// variable, so it is loaded into a register in the prolog. bool WebAssemblyFrameLowering::needsSP(const MachineFunction &MF, const MachineFrameInfo &MFI) const { - return MFI.getStackSize() || MFI.adjustsStack() || hasFP(MF); + return MFI.getStackSize() || MFI.adjustsStack() || hasFP(MF) || + needsPrologForEH(MF); } /// Returns true if the local user-space stack pointer needs to be written back @@ -97,10 +108,9 @@ bool WebAssemblyFrameLowering::needsSPWriteback( MF.getFunction().hasFnAttribute(Attribute::NoRedZone); } -static void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF, - MachineBasicBlock &MBB, - MachineBasicBlock::iterator &InsertStore, - const DebugLoc &DL) { +void WebAssemblyFrameLowering::writeSPToGlobal( + unsigned SrcReg, MachineFunction &MF, MachineBasicBlock &MBB, + MachineBasicBlock::iterator &InsertStore, const DebugLoc &DL) const { const auto *TII = MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo(); const char *ES = "__stack_pointer"; |