This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Support passing fragments to code emission
ClosedPublic

Authored by FPar on Jul 18 2022, 4:40 PM.

Details

Summary

This changes code emission such that it can emit specific function
fragments instead of scanning all basic blocks of a function and just
emitting those that are hot or cold.

To implement this, FunctionLayout explicitly distinguishes the "main"
fragment (i.e. the one that contains the entry block and is associated
with the original symbol) from "split" fragments. Additionally,
BinaryFunction receives support for multiple cold symbols - one for
each split fragment.

Diff Detail

Event Timeline

FPar created this revision.Jul 18 2022, 4:40 PM
Herald added a reviewer: Amir. · View Herald Transcript
Herald added a reviewer: maksfb. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: ayermolo. · View Herald Transcript
FPar added a reviewer: yota9.Jul 18 2022, 4:43 PM
FPar retitled this revision from [BOLT] Make code emission multi fragment aware to [BOLT] Support passing fragments to code emission.Jul 25 2022, 2:39 PM
FPar edited the summary of this revision. (Show Details)
FPar updated this revision to Diff 447479.Jul 25 2022, 2:40 PM

Clean diff up

FPar published this revision for review.Jul 25 2022, 2:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2022, 2:41 PM
FPar removed a subscriber: ayermolo.
FPar updated this revision to Diff 447888.Jul 26 2022, 5:05 PM

Fix cold fragment size calculation

FPar updated this revision to Diff 449061.Aug 1 2022, 9:56 AM

Add assertion messages

FPar updated this revision to Diff 449134.Aug 1 2022, 2:46 PM

Fix fragment size calculation

Emitting label before switching section led to undefined values.

FPar updated this revision to Diff 449478.Aug 2 2022, 4:34 PM

Support multiple fragments for addExtraSymbols

FPar updated this revision to Diff 453113.Aug 16 2022, 1:45 PM

Rebase on earlier commit

There's some weird handling of fragment images, but I guess the idea is to implement them in future diffs - maybe https://reviews.llvm.org/D130521 ? We need to coordinate this well so we don't lose track of everything that needs to be updated after this diff lands. I have some comments in the parts of the code that are reading a bit odd to me at the moment.

bolt/lib/Core/BinaryEmitter.cpp
381

I guess the fact that we don't have individual end labels for each fragment is going to be a problem for determining the correct size of these symbols in emitELFSize. But according to 247b4181a306aff348c1d2d8c3847280866a7f32, this symbol table isn't terribly important. But I would rather not have incorrect code.

bolt/lib/Rewrite/RewriteInstance.cpp
3189

Move outside of the loop / under "if Function->isSplit"?

3726–3757

Emitting the same coldPart over and over for each fragment?

4541–4542

Same image for all fragments? I guess this will be implemented in a follow-up diff? ps: I don't see that implemented in https://reviews.llvm.org/D130521

rafauler added inline comments.Aug 16 2022, 6:48 PM
bolt/lib/Core/BinaryEmitter.cpp
381

I see this is implemented in https://reviews.llvm.org/D130520 now.

FPar updated this revision to Diff 453357.Aug 17 2022, 11:20 AM

Update ColdCodeSectionName after loop

FPar added a comment.Aug 17 2022, 11:49 AM

I am aware that the ordering of diffs not ideal. The diffs D130052, D130520 and D130521 are the baseline of changes required to get simple programs running. I tried to group related changes, but they all depend on each other in some way.

bolt/lib/Core/BinaryEmitter.cpp
381

Correct.

bolt/lib/Rewrite/RewriteInstance.cpp
3189

Moved to getLayout().isSplit(), because Function->isSplit() is a slightly different check.

3726–3757

This is addressed in D132051. This diff only takes care that ColdSection has the right output address.

4541–4542

Yes. Again, D132051.

This revision is now accepted and ready to land.Aug 17 2022, 5:04 PM
This revision was automatically updated to reflect the committed changes.