Skip to content
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] Add structure of CDSplit to SplitFunctions #73430

Merged

Conversation

ShatianWang
Copy link
Contributor

@ShatianWang ShatianWang commented Nov 26, 2023

This commit establishes the general structure of the CDSplit strategy in SplitFunctions without incorporating the exact splitting logic. With -split-functions -split-strategy=cdsplit, the SplitFunctions pass will run twice: the first time is before function reordering and functions are hot-cold split; the second time is after function reordering and functions are hot-warm-cold split based on the fixed function ordering. Currently, all functions are hot-warm split after the entry block in the second splitting pass. Subsequent commits will introduce the precise splitting logic. NFC.

@ShatianWang ShatianWang marked this pull request as ready for review November 26, 2023 06:51
@ShatianWang
Copy link
Contributor Author

A test will be added in a later PR with the complete CDSplit logic.

This commit establishes the general structure of the CDSplit
strategy in SplitFunctions without incorporating the exact
splitting logic. With -split-functions -split-strategy=cdsplit,
the SplitFunctions pass will run twice: the first time is before
function reordering and functions are hot-cold split; the second
time is after function reordering and functions are hot-warm-cold
split based on the fixed function ordering. Currently, all
functions are hot-warm split after the entry block in the second
splitting pass. Subsequent commits will introduce the precise
splitting logic.
@ShatianWang ShatianWang force-pushed the 112523Commit2/3_SetupCDSplitStructure branch from 4f1d6e9 to e9e9c2d Compare November 27, 2023 06:19
@@ -136,6 +149,55 @@ struct SplitProfile2 final : public SplitStrategy {
}
};

struct SplitCacheDirected final : public SplitStrategy {
BinaryContext &BC;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need BinaryContext member? We can always access it via BinaryFunction::getBinaryContext().

return BF.hasValidProfile() && hasFullProfile(BF) && !allBlocksCold(BF);
}

bool keepEmpty() override { return true; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a comment on why we need keepEmpty() for this strategy?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool compactFragments() override { return false; }?

@@ -409,8 +487,10 @@ void SplitFunctions::splitFunction(BinaryFunction &BF, SplitStrategy &S) {
LLVM_DEBUG(dbgs() << "Estimated size for function " << BF
<< " post-split is <0x" << Twine::utohexstr(HotSize)
<< ", 0x" << Twine::utohexstr(ColdSize) << ">\n");
if (alignTo(OriginalHotSize, opts::SplitAlignThreshold) <=
alignTo(HotSize, opts::SplitAlignThreshold) + opts::SplitThreshold) {
if (S.autoReversal() &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to run calculateEmittedSize() above even when autoReversal() is off?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed autoReversal() per our offline discussion.

@ShatianWang
Copy link
Contributor Author

Based on comments from and offline discussion with @maksfb, added fixup! [BOLT] Add structure of CDSplit to SplitFunctions

@@ -430,6 +430,8 @@ void BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
Manager.registerPass(
std::make_unique<ReorderFunctions>(PrintReorderedFunctions));

Manager.registerPass(std::make_unique<SplitFunctions>(PrintSplit));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a brief comment why we need another pass of SplitFunctions here too.

return BF.hasValidProfile() && hasFullProfile(BF) && !allBlocksCold(BF);
}

bool keepEmpty() override { return true; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool compactFragments() override { return false; }?

@ShatianWang
Copy link
Contributor Author

New fixup addressing the new comments by @maksfb .

Copy link
Contributor

@maksfb maksfb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@ShatianWang ShatianWang merged commit 076bd22 into llvm:main Nov 29, 2023
3 checks passed
@ShatianWang ShatianWang deleted the 112523Commit2/3_SetupCDSplitStructure branch November 29, 2023 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants