@@ -3566,10 +3566,10 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
3566
3566
if (EnableExtTspBlockPlacement &&
3567
3567
(ApplyExtTspWithoutProfile || MF.getFunction ().hasProfileData ()) &&
3568
3568
MF.size () <= ExtTspBlockPlacementMaxBlocks) {
3569
- applyExtTsp (false );
3569
+ applyExtTsp (/* OptForSize= */ false );
3570
3570
createCFGChainExtTsp ();
3571
3571
} else if (UseExtTspForSize) {
3572
- applyExtTsp (true );
3572
+ applyExtTsp (/* OptForSize= */ true );
3573
3573
createCFGChainExtTsp ();
3574
3574
}
3575
3575
}
@@ -3607,9 +3607,9 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
3607
3607
CurrentBlockOrder.push_back (&MBB);
3608
3608
}
3609
3609
3610
- std::vector <uint64_t > BlockCounts (F->size ());
3611
- std::vector <uint64_t > BlockSizes (F->size ());
3612
- std::vector <codelayout::EdgeCount> JumpCounts;
3610
+ SmallVector <uint64_t , 0 > BlockCounts (F->size ());
3611
+ SmallVector <uint64_t , 0 > BlockSizes (F->size ());
3612
+ SmallVector <codelayout::EdgeCount, 0 > JumpCounts;
3613
3613
SmallVector<MachineOperand, 4 > Cond; // For analyzeBranch.
3614
3614
SmallVector<const MachineBasicBlock *, 4 > Succs;
3615
3615
for (MachineBasicBlock &MBB : *F) {
@@ -3626,23 +3626,18 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
3626
3626
instructionsWithoutDebug (MBB.instr_begin (), MBB.instr_end ());
3627
3627
size_t NumInsts = std::distance (NonDbgInsts.begin (), NonDbgInsts.end ());
3628
3628
BlockSizes[BlockIndex[&MBB]] = 4 * NumInsts;
3629
- // Getting jump frequencies.
3630
3629
3631
- if (!OptForSize) {
3632
- for (MachineBasicBlock *Succ : MBB.successors ()) {
3633
- auto EP = MBPI->getEdgeProbability (&MBB, Succ);
3634
- BlockFrequency JumpFreq = BlockFreq * EP;
3635
- JumpCounts.push_back (
3636
- {BlockIndex[&MBB], BlockIndex[Succ], JumpFreq.getFrequency ()});
3637
- }
3638
- } else {
3630
+ // Getting jump frequencies.
3631
+ if (OptForSize) {
3639
3632
Cond.clear ();
3640
3633
MachineBasicBlock *TBB = nullptr , *FBB = nullptr ; // For analyzeBranch.
3641
3634
if (TII->analyzeBranch (MBB, TBB, FBB, Cond))
3642
3635
continue ;
3643
3636
3644
3637
const MachineBasicBlock *FTB = MBB.getFallThrough ();
3645
-
3638
+ // Succs is a collection of distinct destinations of the block reachable
3639
+ // from MBB via a jump instruction; initialize the list using the three
3640
+ // (non-necessarily distinct) blocks, FTB, TBB, and FBB.
3646
3641
Succs.clear ();
3647
3642
if (TBB && TBB != FTB)
3648
3643
Succs.push_back (TBB);
@@ -3654,17 +3649,23 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
3654
3649
// optimization; prioritize slightly jumps with a single successor, since
3655
3650
// the corresponding jump instruction will be removed from the binary.
3656
3651
const uint64_t Freq = Succs.size () == 1 ? 110 : 100 ;
3657
- for (const MachineBasicBlock *Succ : Succs) {
3652
+ for (const MachineBasicBlock *Succ : Succs)
3658
3653
JumpCounts.push_back ({BlockIndex[&MBB], BlockIndex[Succ], Freq});
3654
+ } else {
3655
+ for (MachineBasicBlock *Succ : MBB.successors ()) {
3656
+ auto EP = MBPI->getEdgeProbability (&MBB, Succ);
3657
+ BlockFrequency JumpFreq = BlockFreq * EP;
3658
+ JumpCounts.push_back (
3659
+ {BlockIndex[&MBB], BlockIndex[Succ], JumpFreq.getFrequency ()});
3659
3660
}
3660
3661
}
3661
3662
}
3662
3663
3663
3664
LLVM_DEBUG (dbgs () << " Applying ext-tsp layout for |V| = " << F->size ()
3664
3665
<< " with profile = " << F->getFunction ().hasProfileData ()
3665
- << " (" << F->getName (). str () << " )" << " \n " );
3666
+ << " (" << F->getName () << " )" << " \n " );
3666
3667
3667
- const double OrgScore = calcExtTspScore (BlockSizes, BlockCounts, JumpCounts);
3668
+ const double OrgScore = calcExtTspScore (BlockSizes, JumpCounts);
3668
3669
LLVM_DEBUG (dbgs () << format (" original layout score: %0.2f\n " , OrgScore));
3669
3670
3670
3671
// Run the layout algorithm.
@@ -3674,8 +3675,7 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
3674
3675
for (uint64_t Node : NewOrder) {
3675
3676
NewBlockOrder.push_back (CurrentBlockOrder[Node]);
3676
3677
}
3677
- const double OptScore =
3678
- calcExtTspScore (NewOrder, BlockSizes, BlockCounts, JumpCounts);
3678
+ const double OptScore = calcExtTspScore (NewOrder, BlockSizes, JumpCounts);
3679
3679
LLVM_DEBUG (dbgs () << format (" optimized layout score: %0.2f\n " , OptScore));
3680
3680
3681
3681
// If the optimization is unsuccessful, fall back to the original block order.
0 commit comments