-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BOLT] CDSplit: A New 3-Way Function Splitting Algorithm #72225
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit modifies BinaryContext::calculateEmittedSize to update the BinaryBasicBlock::OutputAddressRange for each basic block in the input BF. The modification is done in place, where BB.OutputAddressRange.second less BB.OutputAddressRange.first now gives the emitted size of the basic block.
This commit updates SplitFunctions.h and SplitFunctions.cpp to enable the reuse of createEHTrampolines, mergeEHTrampolines, hasFullProfile, and allBlocksCold by a distinct function splitting pass (CDSplit).
ShatianWang
force-pushed
the
111323UpstreamCDSplit
branch
from
November 15, 2023 21:09
d091050
to
be3565a
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
This commit establishes the general structure of the CDSplit implementation without incorporating the exact splitting logic. Currently, all functions undergo hot-cold splitting based on the decisions made by the SplitFunctions pass. Subsequent commits will introduce the precise splitting logic.
ShatianWang
force-pushed
the
111323UpstreamCDSplit
branch
from
November 15, 2023 22:30
be3565a
to
0bf25f6
Compare
This commit explicitly adds a warm code section, .text.warm, when the -use-cdsplit=1 flag is set. This replaces the previous approach of using .text.cold.0 as warm and .text.cold.1 as cold in 3-way splitting.
This diff defines and initializes auxiliary variables used by CDSplit.
The first diff in a series of 3 that implements the main logic of CDSplit. Under X86, function splitting can lead to block size increase. This is because conditional and unconditional branch instructions whose offset is under 8 bits can be encoded with 2 bytes. If the offset is greater than 8 bits, then they need 6 and 5 bytes respectively. Splitting a short conditional / unconditional branch will thus increase the size of the src basic block by 4 and 3 bytes respectively. CDSplit takes into account the potential block size increase when it makes splitting decisions. This diff implements a function estimatePostSplitBBAddress in CDSplit that approximates the block level size increase at the given split index of the given function.
The second diff in a series of 3 that implements the main logic of CDSplit. When the function order is [... X ... BF ... Y ...], a main benefit of splitting the hot fragment of BF further into a hot and a warm fragment is that function calls in the form of X->Y or Y->X will become shorter (i.e., SrcBB and DstBB will become closer to each other) as long as the new hot fragment of BF is smaller in size compared to the original hot fragment. This diff implements a function that finds all such "shortenable" calls in the form of X->Y or Y->X for the given function BF.
The third diff in a series of 3 that implements the main logic of CDSplit. CDSplit processes functions in a binary in parallel. For each function BF, it assumes that all other functions are hot-cold split. For each possible hot-warm split point of BF, it computes its corresponding SplitScore, and chooses the split point with the best SplitScore. The SplitScore of each split point is computed in the following way: each call edge or jump edge has an edge score that is proportional to its execution count, and inversely proportional to its distance. The SplitScore of a split point is a sum of edge scores over a fixed set of edges whose distance can change due to hot-warm splitting BF. This set contains all cover calls in the form of X->Y or Y->X given function order [... X ... BF ... Y ...]; we refer to the sum of edge scores over the set of cover calls as CoverCallScore. This set also contains all jump edges (branches) within BF as well as all call edges originated from BF; we refer to the sum of edge scores over this set of edges as LocalScore. CDSplit finds the split index maximizing CoverCallScore + LocalScore.
Test the control of aggressiveness of 3-way splitting by -call-scale. When -call-scale=0.0, the tested function is 2-way splitted. When -call-scale=1.0, the tested function is 3-way splitted with 5 blocks in warm because of the increased benefit of shortening the call edges. When -call-scale=1000.0, the tested function is 3-way splitted with 7 blocks in warm because of the strong benefit of shortening the call edges.
Test the correctness of section names and function symbol names post cdsplit. Warm section should have name .text.warm and warm function fragments should have symbol names ending in warm.
ShatianWang
force-pushed
the
111323UpstreamCDSplit
branch
from
November 16, 2023 14:38
0bf25f6
to
841e1ef
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A stack of 8 diffs to upstream a new 3-way function splitting algorithm, CDSplit, that splits each function into a hot, a warm, and a cold fragment.