This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Set valid index for functions with profiles
ClosedPublic

Authored by yota9 on Jun 7 2022, 8:45 AM.

Details

Summary

Some of the passes that calculates tentative layout like LongJmp and
Golang are expecting that only functions with valid index will be
located in hot text section. But currently functions with valid profiles
and not set index are breaking this logic, to fix this we can move the
hasValidProfile() condition from AssignSections pass to ReorderFunctions.

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei

Diff Detail

Event Timeline

yota9 created this revision.Jun 7 2022, 8:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 8:45 AM
yota9 requested review of this revision.Jun 7 2022, 8:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 8:45 AM
yota9 updated this revision to Diff 434837.Jun 7 2022, 8:46 AM

Fix comment

maksfb added a comment.Jun 7 2022, 2:04 PM

Some of the passes that calculates tentative layout like LongJmp and Golang are expecting that only functions with valid index will be located in hot text section.

Do these passes care about functions written to cold text at all? I wonder if we need to assign indices to all functions regardless of the profile.

bolt/lib/Passes/ReorderFunctions.cpp
132

Or KV.

yota9 marked an inline comment as done.Jun 7 2022, 2:13 PM

Some of the passes that calculates tentative layout like LongJmp and Golang are expecting that only functions with valid index will be located in hot text section.

Do these passes care about functions written to cold text at all? I wonder if we need to assign indices to all functions regardless of the profile.

Sure, they are. E.g. we need to know exact layout to perform all the relaxations in jumps/calls in/to hot/cold sections.
We don't need to assign indices to cold functions since we get them from getSortedFunctions() vector one by one. But we need to know the boundaries between hot and cold parts and should know exactly in which section the function goest to or its part. Using the indices we easily see that the first part of the sorted functions vector contains hot/split functions and the second part only cold functions and easily can perform right layout calculations.

yota9 updated this revision to Diff 434948.Jun 7 2022, 2:13 PM

address comment

maksfb accepted this revision.Jun 7 2022, 3:07 PM

We were considering adding another level of "hotness" for basic blocks and maybe for functions. I.e. potentially we might have hot/cold/frozen split if it proves to be beneficial. Then relying on implicit assumptions about indices will become too fragile. Something to keep in mind.

This revision is now accepted and ready to land.Jun 7 2022, 3:07 PM
This revision was automatically updated to reflect the committed changes.