This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Don't write SP back when prolog is generated only for EH
ClosedPublic

Authored by aheejin on Aug 22 2018, 11:17 AM.

Details

Summary

When we don't actually have stack-allocated variables but needs SP only
to support EH, we don't need to write SP back in the epilog, because we
don't bump down the stack pointer.

Diff Detail

Repository
rL LLVM

Event Timeline

aheejin created this revision.Aug 22 2018, 11:17 AM
dschuff added inline comments.Aug 22 2018, 11:25 AM
lib/Target/WebAssembly/WebAssemblyEHRestoreStackPointer.cpp
73 ↗(On Diff #162006)

__stack_pointer

75 ↗(On Diff #162006)

can't leaf functions have try/catch blocks, even if there are no calls? I think the real issue is that leaf functions do not to restore the stack pointer on catch, because it won't have been updated by any callees.

lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
115 ↗(On Diff #162006)

Another possible way:
bool NeedsSPForLocalFrame = MFI.getStackSize() || !MFI.adjustsStack() || hasFP(MF);

which would avoid so many nots...

Actually, even better may be to turn NeedsSPForLocalFrame() into a function (that can be called by needsSP()). Then you can reuse it here instead of duplicating the logic?

aheejin updated this revision to Diff 162048.Aug 22 2018, 2:01 PM
aheejin marked 2 inline comments as done.

Address comments

aheejin added inline comments.Aug 22 2018, 2:02 PM
lib/Target/WebAssembly/WebAssemblyEHRestoreStackPointer.cpp
75 ↗(On Diff #162006)

Right, good point.

aheejin marked an inline comment as done.Aug 22 2018, 2:02 PM
dschuff accepted this revision.Aug 22 2018, 2:06 PM
This revision is now accepted and ready to land.Aug 22 2018, 2:06 PM
This revision was automatically updated to reflect the committed changes.