This is an archive of the discontinued LLVM Phabricator instance.

Split EH code by default
ClosedPublic

Authored by iamarchit123 on Aug 12 2022, 7:45 PM.

Details

Summary

The current machine function splitter is reliant on profile data to do profile summary analysis to split blocks into cold section. This may sometimes limit the usage of machine function splitter especially in cases where we could do some form of static analysis to split out cold blocks if profile data is absent or profile data which may be faulty (Consider Sample PGO).

Of all code that could statically be marked cold Exception handling blocks are one of them (In fact BFI framework also tends to mark them as cold), and the most in size contribution. In my experiments I found out Exception handling pads and all code reachable from there account for up to 6-8% of the .text section on modern production binaries. This patch introduces a flag to split out all Exception handling blocks and blocks only reachable from Exceptional Handling pad to cold section. This flag has shown to give a performance win of up to 0.1% in terms of average cycles and instructions executed on internal facebook search service.

Diff Detail

Event Timeline

iamarchit123 created this revision.Aug 12 2022, 7:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2022, 7:45 PM
iamarchit123 updated this revision to Diff 452363.EditedAug 12 2022, 7:47 PM

Split all EH code if a flag mfs-split-ehcode is passed.

iamarchit123 edited the summary of this revision. (Show Details)Aug 12 2022, 8:03 PM
iamarchit123 added reviewers: hoy, modimo.
iamarchit123 removed subscribers: hiraditya, pengfei.
iamarchit123 published this revision for review.Aug 12 2022, 8:04 PM
iamarchit123 removed a subscriber: wenlei.
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2022, 8:05 PM
iamarchit123 added a reviewer: rahmanl.
snehasish added inline comments.Aug 15 2022, 4:51 PM
llvm/lib/CodeGen/MachineFunctionSplitter.cpp
86

I think it would be safer to capture MachineFunction& MF here instead of relying on the user to pass MF.front(). Then you can initialize StartBlock to MF.front() in this function.

88
129

nit: Avoid comments which simply state whats going on if its clear from the code.

170–171

Update the comment here to say that we can also split EH dominated blocks if requested.

221

Can we use MachineDominatorTree::getDescendants here instead?

iamarchit123 added inline comments.Aug 15 2022, 5:17 PM
llvm/lib/CodeGen/MachineFunctionSplitter.cpp
221

Hi Snehashish,
What about blocks that may not be dominated by single EH pad but by two EH pads? Like reachable from both EH1 and EH2. Won't we miss those blocks?

snehasish added inline comments.Aug 15 2022, 5:39 PM
llvm/lib/CodeGen/MachineFunctionSplitter.cpp
102

Please add a comment here to describe the PredStatus > Status check.

221

Yes we will, this approach makes sense. Can you document this and add a descriptive function comment for setDescendantEHBlocksCold?

iamarchit123 edited the summary of this revision. (Show Details)

Address review comments and add descriptive comments.

iamarchit123 marked 6 inline comments as done.Aug 15 2022, 7:03 PM
iamarchit123 added inline comments.Aug 15 2022, 7:06 PM
llvm/lib/CodeGen/MachineFunctionSplitter.cpp
88

Done

102

Done

129

Removed comment

170–171

Updated description to include static splitting of EH code

221

Added comments for setDescendantEHBlocksCold above function definition

snehasish accepted this revision.Aug 16 2022, 3:48 PM

lgtm, thanks!

llvm/lib/CodeGen/MachineFunctionSplitter.cpp
92

"blocks via"

This revision is now accepted and ready to land.Aug 16 2022, 3:48 PM
modimo added inline comments.Aug 16 2022, 4:28 PM
llvm/lib/CodeGen/MachineFunctionSplitter.cpp
86

s/sampling/profile/d

123

nit: successors. Same with line below

Fix minor spellings/comments.

iamarchit123 marked 2 inline comments as done.Aug 16 2022, 4:44 PM
This revision was landed with ongoing or failed builds.Aug 17 2022, 12:42 PM
Closed by commit rGe170d955fe57: Split EH code by default (authored by iamarchit123, committed by modimo). · Explain Why
This revision was automatically updated to reflect the committed changes.