@@ -219,6 +219,10 @@ static cl::opt<unsigned> ExtTspBlockPlacementMaxBlocks(
219
219
" block placement." ),
220
220
cl::init(UINT_MAX), cl::Hidden);
221
221
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
+
222
226
namespace llvm {
223
227
extern cl::opt<bool > EnableExtTspBlockPlacement;
224
228
extern cl::opt<bool > ApplyExtTspWithoutProfile;
@@ -1220,7 +1224,7 @@ bool MachineBlockPlacement::canTailDuplicateUnplacedPreds(
1220
1224
1221
1225
// If profile information is available, findDuplicateCandidates can do more
1222
1226
// precise benefit analysis.
1223
- if (F->getFunction ().hasProfileData ())
1227
+ if (UseProfileData && F->getFunction ().hasProfileData ())
1224
1228
return true ;
1225
1229
1226
1230
// This is mainly for function exit BB.
@@ -1388,7 +1392,7 @@ void MachineBlockPlacement::precomputeTriangleChains() {
1388
1392
// When profile is available, we need to handle the triangle-shape CFG.
1389
1393
static BranchProbability getLayoutSuccessorProbThreshold (
1390
1394
const MachineBasicBlock *BB) {
1391
- if (!BB->getParent ()->getFunction ().hasProfileData ())
1395
+ if (!UseProfileData || ! BB->getParent ()->getFunction ().hasProfileData ())
1392
1396
return BranchProbability (StaticLikelyProb, 100 );
1393
1397
if (BB->succ_size () == 2 ) {
1394
1398
const MachineBasicBlock *Succ1 = *BB->succ_begin ();
@@ -2621,7 +2625,8 @@ MachineBlockPlacement::collectLoopBlockSet(const MachineLoop &L) {
2621
2625
// will be merged into the first outer loop chain for which this block is not
2622
2626
// cold anymore. This needs precise profile data and we only do this when
2623
2627
// profile data is available.
2624
- if (F->getFunction ().hasProfileData () || ForceLoopColdBlock) {
2628
+ if ((UseProfileData && F->getFunction ().hasProfileData ()) ||
2629
+ ForceLoopColdBlock) {
2625
2630
BlockFrequency LoopFreq (0 );
2626
2631
for (auto *LoopPred : L.getHeader ()->predecessors ())
2627
2632
if (!L.contains (LoopPred))
@@ -2670,8 +2675,8 @@ void MachineBlockPlacement::buildLoopChains(const MachineLoop &L) {
2670
2675
// this loop by modeling costs more precisely which requires the profile data
2671
2676
// for better layout.
2672
2677
bool RotateLoopWithProfile =
2673
- ForcePreciseRotationCost ||
2674
- (PreciseRotationCost && F->getFunction ().hasProfileData ());
2678
+ ForcePreciseRotationCost || (PreciseRotationCost && UseProfileData &&
2679
+ F->getFunction ().hasProfileData ());
2675
2680
2676
2681
// First check to see if there is an obviously preferable top block for the
2677
2682
// loop. This will default to the header, but may end up as one of the
@@ -3208,7 +3213,7 @@ bool MachineBlockPlacement::maybeTailDuplicateBlock(
3208
3213
bool IsSimple = TailDup.isSimpleBB (BB);
3209
3214
SmallVector<MachineBasicBlock *, 8 > CandidatePreds;
3210
3215
SmallVectorImpl<MachineBasicBlock *> *CandidatePtr = nullptr ;
3211
- if (F->getFunction ().hasProfileData ()) {
3216
+ if (UseProfileData && F->getFunction ().hasProfileData ()) {
3212
3217
// We can do partial duplication with precise profile information.
3213
3218
findDuplicateCandidates (CandidatePreds, BB, BlockFilter);
3214
3219
if (CandidatePreds.size () == 0 )
@@ -3409,7 +3414,7 @@ void MachineBlockPlacement::findDuplicateCandidates(
3409
3414
3410
3415
void MachineBlockPlacement::initDupThreshold () {
3411
3416
DupThreshold = BlockFrequency (0 );
3412
- if (!F->getFunction ().hasProfileData ())
3417
+ if (!UseProfileData || ! F->getFunction ().hasProfileData ())
3413
3418
return ;
3414
3419
3415
3420
// We prefer to use prifile count.
@@ -3529,7 +3534,8 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
3529
3534
3530
3535
// Apply a post-processing optimizing block placement.
3531
3536
if (MF.size () >= 3 && EnableExtTspBlockPlacement &&
3532
- (ApplyExtTspWithoutProfile || MF.getFunction ().hasProfileData ()) &&
3537
+ (ApplyExtTspWithoutProfile ||
3538
+ (UseProfileData && MF.getFunction ().hasProfileData ())) &&
3533
3539
MF.size () <= ExtTspBlockPlacementMaxBlocks) {
3534
3540
// Find a new placement and modify the layout of the blocks in the function.
3535
3541
applyExtTsp ();
0 commit comments