This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Fixing relative ordering of cold sections under multi-way function splitting
ClosedPublic

Authored by shatianw_mt on Jun 14 2023, 11:33 AM.

Details

Summary

Order code sections with names in the form of ".text.cold.i" based on the value of i

[Context] SplitFunctions.cpp implements splitting strategies that can potentially split each function into maximum N>2 fragments.
When such N-way splitting happens, new code sections with names ".text.cold.1", ..., ".text.cold.i", ... "text.cold.N-2" will be created
A section with name ".text.cold.i" contains the the (i+2)th fragment of each function.
As an example, if each function is splitted into N=3 fragments: hot, warm, cold, then code sections will now include

  • a section with name ".text" containing hot fragments
  • a section with name ".text.cold" containing warm fragments
  • a section with name ".text.cold.1" containing cold fragments

The order of these new sections in the output binary currently depends on the order in which they are encountered by the emitter.
For example, under N=3-way splitting, if the first function is 2-way splitted into hot and cold and the second function is 3-way splitted into hot, warm, and cold
then the cold fragment is encountered first, resulting in the final section to be in the following order
.text (hot), .text.cold.1 (cold), .text.cold (warm)

The above is suboptimal because the distance of jumps/calls between the hot and the warm sections will be much bigger than when ordering the sections as follows
.text (hot), .text.cold (warm), .text.cold.1 (cold)

This diff orders the sections with names in the form of ".text.cold" or ".text.cold.i" based on the value of i (assuming the i-value of ".text.cold" is 0).

Diff Detail

Event Timeline

shatianw_mt created this revision.Jun 14 2023, 11:33 AM
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
shatianw_mt requested review of this revision.Jun 14 2023, 11:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2023, 11:33 AM

Remove unnecessary print statements...

ran git clang-format

This revision is now accepted and ready to land.Jun 20 2023, 4:26 PM

Added missing {} for the outer if statement. Without it we get undesirable behavior such as mover section being placed after text sections. Thanks rafauler for catching this.