Skip to content

Commit f4f826f

Browse files
committed
[BlockPlacement] Add flag to disable profile usage
1 parent e40915b commit f4f826f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

llvm/lib/CodeGen/MachineBlockPlacement.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ static cl::opt<unsigned> ExtTspBlockPlacementMaxBlocks(
219219
"block placement."),
220220
cl::init(UINT_MAX), cl::Hidden);
221221

222+
static cl::opt<bool>
223+
UseProfileData("block-placement-use-profile", cl::init(true), cl::Hidden,
224+
cl::desc("Use profile data to do precise benefit analysis"));
225+
222226
namespace llvm {
223227
extern cl::opt<bool> EnableExtTspBlockPlacement;
224228
extern cl::opt<bool> ApplyExtTspWithoutProfile;
@@ -1220,7 +1224,7 @@ bool MachineBlockPlacement::canTailDuplicateUnplacedPreds(
12201224

12211225
// If profile information is available, findDuplicateCandidates can do more
12221226
// precise benefit analysis.
1223-
if (F->getFunction().hasProfileData())
1227+
if (UseProfileData && F->getFunction().hasProfileData())
12241228
return true;
12251229

12261230
// This is mainly for function exit BB.
@@ -1388,7 +1392,7 @@ void MachineBlockPlacement::precomputeTriangleChains() {
13881392
// When profile is available, we need to handle the triangle-shape CFG.
13891393
static BranchProbability getLayoutSuccessorProbThreshold(
13901394
const MachineBasicBlock *BB) {
1391-
if (!BB->getParent()->getFunction().hasProfileData())
1395+
if (!UseProfileData || !BB->getParent()->getFunction().hasProfileData())
13921396
return BranchProbability(StaticLikelyProb, 100);
13931397
if (BB->succ_size() == 2) {
13941398
const MachineBasicBlock *Succ1 = *BB->succ_begin();
@@ -2621,7 +2625,8 @@ MachineBlockPlacement::collectLoopBlockSet(const MachineLoop &L) {
26212625
// will be merged into the first outer loop chain for which this block is not
26222626
// cold anymore. This needs precise profile data and we only do this when
26232627
// profile data is available.
2624-
if (F->getFunction().hasProfileData() || ForceLoopColdBlock) {
2628+
if ((UseProfileData && F->getFunction().hasProfileData()) ||
2629+
ForceLoopColdBlock) {
26252630
BlockFrequency LoopFreq(0);
26262631
for (auto *LoopPred : L.getHeader()->predecessors())
26272632
if (!L.contains(LoopPred))
@@ -2670,8 +2675,8 @@ void MachineBlockPlacement::buildLoopChains(const MachineLoop &L) {
26702675
// this loop by modeling costs more precisely which requires the profile data
26712676
// for better layout.
26722677
bool RotateLoopWithProfile =
2673-
ForcePreciseRotationCost ||
2674-
(PreciseRotationCost && F->getFunction().hasProfileData());
2678+
ForcePreciseRotationCost || (PreciseRotationCost && UseProfileData &&
2679+
F->getFunction().hasProfileData());
26752680

26762681
// First check to see if there is an obviously preferable top block for the
26772682
// loop. This will default to the header, but may end up as one of the
@@ -3208,7 +3213,7 @@ bool MachineBlockPlacement::maybeTailDuplicateBlock(
32083213
bool IsSimple = TailDup.isSimpleBB(BB);
32093214
SmallVector<MachineBasicBlock *, 8> CandidatePreds;
32103215
SmallVectorImpl<MachineBasicBlock *> *CandidatePtr = nullptr;
3211-
if (F->getFunction().hasProfileData()) {
3216+
if (UseProfileData && F->getFunction().hasProfileData()) {
32123217
// We can do partial duplication with precise profile information.
32133218
findDuplicateCandidates(CandidatePreds, BB, BlockFilter);
32143219
if (CandidatePreds.size() == 0)
@@ -3409,7 +3414,7 @@ void MachineBlockPlacement::findDuplicateCandidates(
34093414

34103415
void MachineBlockPlacement::initDupThreshold() {
34113416
DupThreshold = BlockFrequency(0);
3412-
if (!F->getFunction().hasProfileData())
3417+
if (!UseProfileData || !F->getFunction().hasProfileData())
34133418
return;
34143419

34153420
// We prefer to use prifile count.
@@ -3529,7 +3534,8 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
35293534

35303535
// Apply a post-processing optimizing block placement.
35313536
if (MF.size() >= 3 && EnableExtTspBlockPlacement &&
3532-
(ApplyExtTspWithoutProfile || MF.getFunction().hasProfileData()) &&
3537+
(ApplyExtTspWithoutProfile ||
3538+
(UseProfileData && MF.getFunction().hasProfileData())) &&
35333539
MF.size() <= ExtTspBlockPlacementMaxBlocks) {
35343540
// Find a new placement and modify the layout of the blocks in the function.
35353541
applyExtTsp();

0 commit comments

Comments
 (0)