Skip to content

Commit cac3bb6

Browse files
author
spupyrev
committed
addressing comments
1 parent 38e1ce8 commit cac3bb6

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

llvm/lib/CodeGen/MachineBlockPlacement.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3566,10 +3566,10 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
35663566
if (EnableExtTspBlockPlacement &&
35673567
(ApplyExtTspWithoutProfile || MF.getFunction().hasProfileData()) &&
35683568
MF.size() <= ExtTspBlockPlacementMaxBlocks) {
3569-
applyExtTsp(false);
3569+
applyExtTsp(/*OptForSize=*/false);
35703570
createCFGChainExtTsp();
35713571
} else if (UseExtTspForSize) {
3572-
applyExtTsp(true);
3572+
applyExtTsp(/*OptForSize=*/true);
35733573
createCFGChainExtTsp();
35743574
}
35753575
}
@@ -3607,9 +3607,9 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
36073607
CurrentBlockOrder.push_back(&MBB);
36083608
}
36093609

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;
36133613
SmallVector<MachineOperand, 4> Cond; // For analyzeBranch.
36143614
SmallVector<const MachineBasicBlock *, 4> Succs;
36153615
for (MachineBasicBlock &MBB : *F) {
@@ -3626,23 +3626,18 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
36263626
instructionsWithoutDebug(MBB.instr_begin(), MBB.instr_end());
36273627
size_t NumInsts = std::distance(NonDbgInsts.begin(), NonDbgInsts.end());
36283628
BlockSizes[BlockIndex[&MBB]] = 4 * NumInsts;
3629-
// Getting jump frequencies.
36303629

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) {
36393632
Cond.clear();
36403633
MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For analyzeBranch.
36413634
if (TII->analyzeBranch(MBB, TBB, FBB, Cond))
36423635
continue;
36433636

36443637
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.
36463641
Succs.clear();
36473642
if (TBB && TBB != FTB)
36483643
Succs.push_back(TBB);
@@ -3654,17 +3649,23 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
36543649
// optimization; prioritize slightly jumps with a single successor, since
36553650
// the corresponding jump instruction will be removed from the binary.
36563651
const uint64_t Freq = Succs.size() == 1 ? 110 : 100;
3657-
for (const MachineBasicBlock *Succ : Succs) {
3652+
for (const MachineBasicBlock *Succ : Succs)
36583653
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()});
36593660
}
36603661
}
36613662
}
36623663

36633664
LLVM_DEBUG(dbgs() << "Applying ext-tsp layout for |V| = " << F->size()
36643665
<< " with profile = " << F->getFunction().hasProfileData()
3665-
<< " (" << F->getName().str() << ")" << "\n");
3666+
<< " (" << F->getName() << ")" << "\n");
36663667

3667-
const double OrgScore = calcExtTspScore(BlockSizes, BlockCounts, JumpCounts);
3668+
const double OrgScore = calcExtTspScore(BlockSizes, JumpCounts);
36683669
LLVM_DEBUG(dbgs() << format(" original layout score: %0.2f\n", OrgScore));
36693670

36703671
// Run the layout algorithm.
@@ -3674,8 +3675,7 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
36743675
for (uint64_t Node : NewOrder) {
36753676
NewBlockOrder.push_back(CurrentBlockOrder[Node]);
36763677
}
3677-
const double OptScore =
3678-
calcExtTspScore(NewOrder, BlockSizes, BlockCounts, JumpCounts);
3678+
const double OptScore = calcExtTspScore(NewOrder, BlockSizes, JumpCounts);
36793679
LLVM_DEBUG(dbgs() << format(" optimized layout score: %0.2f\n", OptScore));
36803680

36813681
// If the optimization is unsuccessful, fall back to the original block order.

llvm/test/CodeGen/X86/code_placement_ext_tsp_size.ll

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: llc -mcpu=corei7 -mtriple=x86_64-linux -apply-ext-tsp-for-size=true < %s | FileCheck %s
2-
; RUN: llc -mcpu=corei7 -mtriple=x86_64-linux -apply-ext-tsp-for-size=false < %s | FileCheck %s -check-prefix=CHECK2
1+
; RUN: llc -mcpu=corei7 -mtriple=x86_64-linux -apply-ext-tsp-for-size=true < %s | FileCheck %s -check-prefix=CHECK-PERF
2+
; RUN: llc -mcpu=corei7 -mtriple=x86_64-linux -apply-ext-tsp-for-size=false < %s | FileCheck %s -check-prefix=CHECK-SIZE
33

44
define void @func1() minsize {
55
;
@@ -19,15 +19,15 @@ define void @func1() minsize {
1919
; | b2 | <+
2020
; +-----+
2121
;
22-
; CHECK-LABEL: func1:
23-
; CHECK: %b0
24-
; CHECK: %b1
25-
; CHECK: %b2
22+
; CHECK-PERF-LABEL: func1:
23+
; CHECK-PERF: %b0
24+
; CHECK-PERF: %b1
25+
; CHECK-PERF: %b2
2626
;
27-
; CHECK2-LABEL: func1:
28-
; CHECK2: %b0
29-
; CHECK2: %b2
30-
; CHECK2: %b1
27+
; CHECK-SIZE-LABEL: func1:
28+
; CHECK-SIZE: %b0
29+
; CHECK-SIZE: %b2
30+
; CHECK-SIZE: %b1
3131

3232
b0:
3333
%call = call zeroext i1 @a()
@@ -75,21 +75,21 @@ define void @func_loop() minsize !prof !9 {
7575
; | end |
7676
; +--------+
7777
;
78-
; CHECK-LABEL: func_loop:
79-
; CHECK: %entry
80-
; CHECK: %header
81-
; CHECK: %if.then
82-
; CHECK: %if.else
83-
; CHECK: %if.end
84-
; CHECK: %end
78+
; CHECK-PERF-LABEL: func_loop:
79+
; CHECK-PERF: %entry
80+
; CHECK-PERF: %header
81+
; CHECK-PERF: %if.then
82+
; CHECK-PERF: %if.else
83+
; CHECK-PERF: %if.end
84+
; CHECK-PERF: %end
8585
;
86-
; CHECK2-LABEL: func_loop:
87-
; CHECK2: %entry
88-
; CHECK2: %header
89-
; CHECK2: %if.else
90-
; CHECK2: %if.end
91-
; CHECK2: %if.then
92-
; CHECK2: %end
86+
; CHECK-SIZE-LABEL: func_loop:
87+
; CHECK-SIZE: %entry
88+
; CHECK-SIZE: %header
89+
; CHECK-SIZE: %if.else
90+
; CHECK-SIZE: %if.end
91+
; CHECK-SIZE: %if.then
92+
; CHECK-SIZE: %end
9393

9494
entry:
9595
br label %header

0 commit comments

Comments
 (0)