[BOLT] Set valid index for functions with profiles

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

Differential Revision: https://reviews.llvm.org/D127223
This commit is contained in:
Vladislav Khmelevsky 2022-06-07 18:40:04 +03:00
parent a0fc94ab61
commit fd9604952d
2 changed files with 8 additions and 2 deletions

View File

@ -1211,8 +1211,7 @@ void AssignSections::runOnFunctions(BinaryContext &BC) {
continue;
}
if (!UseColdSection || Function.hasValidIndex() ||
Function.hasValidProfile())
if (!UseColdSection || Function.hasValidIndex())
Function.setCodeSectionName(BC.getMainCodeSectionName());
else
Function.setCodeSectionName(BC.getColdCodeSectionName());

View File

@ -128,6 +128,13 @@ void ReorderFunctions::reorder(std::vector<Cluster> &&Clusters,
}
}
// Assign valid index for functions with valid profile.
for (auto &It : BFs) {
BinaryFunction &BF = It.second;
if (!BF.hasValidIndex() && BF.hasValidProfile())
BF.setIndex(Index++);
}
if (opts::ReorderFunctions == RT_NONE)
return;