@@ -3513,10 +3513,17 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
3513
3513
const bool OptForSize =
3514
3514
MF.getFunction ().hasOptSize () ||
3515
3515
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
+ }
3520
3527
3521
3528
// Apply tail duplication.
3522
3529
if (allowTailDupPlacement ()) {
@@ -3562,16 +3569,12 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
3562
3569
// Apply a post-processing optimizing block placement:
3563
3570
// - find a new placement and modify the layout of the blocks in the function;
3564
3571
// - 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 ();
3575
3578
}
3576
3579
3577
3580
optimizeBranches ();
0 commit comments