This is an archive of the discontinued LLVM Phabricator instance.

Win64: Don't emit unwind info for "leaf" functions (PR30337)
ClosedPublic

Authored by hans on Sep 19 2016, 4:59 PM.

Details

Summary

According to MSDN (see the PR), functions which don't touch any callee-saved registers (including %rsp) don't need any unwind info.

This patch takes a stab at not emitting unwind info for such functions, to save binary space. This is an area I don't now much about, so all input is welcome.

I originally wanted to put 'HasWinCFI' on X86MachineFunctionInfo, but then we wouldn't be able to check it from WinException, so it ended up on MachineFunction. I'm not sure what a better place would be. MachineFrameInfo maybe?

Diff Detail

Event Timeline

hans updated this revision to Diff 71891.Sep 19 2016, 4:59 PM
hans retitled this revision from to Win64: Don't emit unwind info for "leaf" functions (PR30337).
hans updated this object.
hans added reviewers: rnk, majnemer.
hans added a subscriber: llvm-commits.
hans added a comment.Sep 21 2016, 9:14 AM

I tried this out on Chrome, and it saves 376 KB (0.6%) on chrome_child.dll, so it seems worth doing. I need your expert review though :-)

majnemer added inline comments.Sep 21 2016, 12:54 PM
include/llvm/CodeGen/MachineFunction.h
378–379

I'd sleep a little easier at night if HasWinCFI was an optional bool. This way we can make sure that nobody is trying to access it before we calculate the state the function is in.

test/CodeGen/X86/coalescer-win64.ll
14

Maybe we should have a CHECK-NOT here?

16

ditto.

test/CodeGen/X86/pr24374.ll
33

Maybe we can keep the CHECK-LABEL? There should be a UD2 here too, right?

test/CodeGen/X86/win64_eh.ll
5–14

Why did this test get removed?

rnk edited edge metadata.Sep 21 2016, 1:57 PM

+1 to David's comments, otherwise looks good

include/llvm/CodeGen/MachineFunction.h
378–379

This is a good idea, we should do this more often.

hans marked 3 inline comments as done.Sep 21 2016, 3:03 PM
hans added inline comments.
include/llvm/CodeGen/MachineFunction.h
378–379

That's a great idea. Done.

test/CodeGen/X86/win64_eh.ll
5–14

I wasn't sure what to do with it now that we don't emit anything special for it. I'll put it back and check it's there and has the ret.

hans updated this revision to Diff 72112.Sep 21 2016, 3:03 PM
hans edited edge metadata.

Addressing review comments.

majnemer added inline comments.Sep 22 2016, 9:56 AM
test/CodeGen/X86/pr24374.ll
34–35

Should we make these CHECK-NOT ? Should we do the same for the other tests?

hans added inline comments.Sep 22 2016, 10:35 AM
test/CodeGen/X86/pr24374.ll
34–35

test/CodeGen/X86/win64_eh_leaf.ll checks that we don't emit these directives for leaf functions, and I'm not sure there's any benefit to add check-nots in other test just to check for the same thing.

I'm happy to add it here though if you think there's really a benefit to it.

majnemer added inline comments.Sep 22 2016, 10:39 AM
test/CodeGen/X86/pr24374.ll
34–35

I guess I feel most strongly about win64_eh.ll. It contains examples of increasing complexity with the varied results we'd expect from the compiler, I feel like it'd be useful to include the CHECK-NOTs for pedagogical purposes.

hans added inline comments.Sep 22 2016, 10:50 AM
test/CodeGen/X86/pr24374.ll
34–35

Makes sense, I'll add them.

hans updated this revision to Diff 72196.Sep 22 2016, 10:50 AM

CHECK-NOTs in win64_eh.ll

majnemer accepted this revision.Sep 22 2016, 11:06 AM
majnemer edited edge metadata.

Thanks, LGTM!

This revision is now accepted and ready to land.Sep 22 2016, 11:06 AM
This revision was automatically updated to reflect the committed changes.