Skip to content

Commit 0b9b221

Browse files
author
spupyrev
committed
adjusting ext-tsp checks as suggested
1 parent 8666e12 commit 0b9b221

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

llvm/lib/CodeGen/MachineBlockPlacement.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,10 +3513,17 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
35133513
const bool OptForSize =
35143514
MF.getFunction().hasOptSize() ||
35153515
llvm::shouldOptimizeForSize(&MF, PSI, &MBFI->getMBFI());
3516-
// Use ext-tsp for size optimization is possible only when the function
3517-
// contains more than two basic blocks.
3518-
const bool UseExtTspForSize =
3519-
OptForSize && ApplyExtTspForSize && MF.size() >= 3;
3516+
// Determine whether to use ext-tsp for perf/size optimization. The method
3517+
// is beneficial only for instances with at least 3 basic blocks and it can be
3518+
// disabled for huge functions (exceeding a certain size).
3519+
bool UseExtTspForPerf = false;
3520+
bool UseExtTspForSize = false;
3521+
if (3 <= MF.size() && MF.size() <= ExtTspBlockPlacementMaxBlocks) {
3522+
UseExtTspForPerf =
3523+
EnableExtTspBlockPlacement &&
3524+
(ApplyExtTspWithoutProfile || MF.getFunction().hasProfileData());
3525+
UseExtTspForSize = OptForSize && ApplyExtTspForSize;
3526+
}
35203527

35213528
// Apply tail duplication.
35223529
if (allowTailDupPlacement()) {
@@ -3562,16 +3569,12 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
35623569
// Apply a post-processing optimizing block placement:
35633570
// - find a new placement and modify the layout of the blocks in the function;
35643571
// - re-create CFG chains so that we can optimizeBranches and alignBlocks.
3565-
if (MF.size() >= 3) {
3566-
if (EnableExtTspBlockPlacement &&
3567-
(ApplyExtTspWithoutProfile || MF.getFunction().hasProfileData()) &&
3568-
MF.size() <= ExtTspBlockPlacementMaxBlocks) {
3569-
applyExtTsp(/*OptForSize=*/false);
3570-
createCFGChainExtTsp();
3571-
} else if (UseExtTspForSize) {
3572-
applyExtTsp(/*OptForSize=*/true);
3573-
createCFGChainExtTsp();
3574-
}
3572+
if (UseExtTspForPerf || UseExtTspForSize) {
3573+
assert(
3574+
!(UseExtTspForPerf && UseExtTspForSize) &&
3575+
"UseExtTspForPerf and UseExtTspForSize can not be set simultaneosly");
3576+
applyExtTsp(/*OptForSize=*/UseExtTspForSize);
3577+
createCFGChainExtTsp();
35753578
}
35763579

35773580
optimizeBranches();

0 commit comments

Comments
 (0)