This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Add option to randomize function split point
ClosedPublic

Authored by FPar on Jun 28 2022, 5:06 PM.

Details

Summary

For test purposes, we want to split functions at a random split point
to be able to test different layouts without relying on the profile.
This patch introduces an option, that randomly chooses a split point
to partition blocks of a function into hot and cold regions.

Diff Detail

Event Timeline

FPar created this revision.Jun 28 2022, 5:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2022, 5:06 PM
Herald added a subscriber: ayermolo. · View Herald Transcript
FPar requested review of this revision.Jun 28 2022, 5:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2022, 5:06 PM
Amir added a comment.Jun 29 2022, 1:11 AM

Thank you for working on this!

bolt/lib/Passes/SplitFunctions.cpp
147–150

As a matter of preference - I try to wrap LLVM_DEBUG body with curly braces to indent it just like a regular code block.

bolt/test/X86/split-random.s
7

The test looks good and very clean! There's just one concern with regards to our NFC testing - I think we should specify the seed as an option to ensure identical binaries between runs.

FPar updated this revision to Diff 441036.Jun 29 2022, 8:52 AM

Fix seed for test

FPar marked 2 inline comments as done.Jun 29 2022, 8:56 AM

Thanks for your suggestions! @Amir

bolt/lib/Passes/SplitFunctions.cpp
147–150

I see your point. However, the majority of our code base seems to omit curly braces in this place. So if you don't mind, I'll keep it like that for now.

Amir accepted this revision.Jun 29 2022, 9:28 AM

LGTM

This revision is now accepted and ready to land.Jun 29 2022, 9:28 AM
yota9 added inline comments.Jun 29 2022, 9:30 AM
bolt/lib/Passes/SplitFunctions.cpp
174

It seems that it could be moved under proper WorkFun

FPar marked 2 inline comments as done.Jun 29 2022, 10:45 AM
FPar added inline comments.
bolt/lib/Passes/SplitFunctions.cpp
174

If the generator is moved into the lambda and each function uses its own generator, all functions generate the same split point, depending on the seed. To get an actually random looking distribution of splits across functions, the work-function needs access to a shared random number generator.

FPar marked an inline comment as done.Jun 29 2022, 10:46 AM
yota9 accepted this revision.Jun 29 2022, 10:49 AM

Thanks @FPar !

This revision was automatically updated to reflect the committed changes.