Skip to content

Commit 20440c3

Browse files
committed
[ProfCheck][NFC] Remove Function argument from branch weight setter
1 parent b7e922a commit 20440c3

File tree

7 files changed

+14
-16
lines changed

7 files changed

+14
-16
lines changed

llvm/include/llvm/IR/ProfDataUtils.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,11 @@ LLVM_ABI void setExplicitlyUnknownBranchWeights(Instruction &I,
194194
/// Like setExplicitlyUnknownBranchWeights(...), but only sets unknown branch
195195
/// weights in the new instruction if the parent function of the original
196196
/// instruction has an entry count. This is to not confuse users by injecting
197-
/// profile data into non-profiled functions.
198-
LLVM_ABI void setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I,
199-
Function &F,
200-
StringRef PassName);
197+
/// profile data into non-profiled functions. If \p F is nullptr, we will fetch
198+
/// the function from \p I.
199+
LLVM_ABI void
200+
setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I, StringRef PassName,
201+
const Function *F = nullptr);
201202

202203
/// Analogous to setExplicitlyUnknownBranchWeights, but for functions and their
203204
/// entry counts.

llvm/lib/IR/IRBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,7 @@ Value *IRBuilderBase::CreateSelectWithUnknownProfile(Value *C, Value *True,
10191019
const Twine &Name) {
10201020
Value *Ret = CreateSelectFMF(C, True, False, {}, Name);
10211021
if (auto *SI = dyn_cast<SelectInst>(Ret)) {
1022-
setExplicitlyUnknownBranchWeightsIfProfiled(
1023-
*SI, *SI->getParent()->getParent(), PassName);
1022+
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, PassName);
10241023
}
10251024
return Ret;
10261025
}

llvm/lib/IR/ProfDataUtils.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,10 @@ void llvm::setExplicitlyUnknownBranchWeights(Instruction &I,
274274
}
275275

276276
void llvm::setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I,
277-
Function &F,
278-
StringRef PassName) {
279-
if (std::optional<Function::ProfileCount> EC = F.getEntryCount();
277+
StringRef PassName,
278+
const Function *F) {
279+
F = F ? F : I.getFunction();
280+
if (std::optional<Function::ProfileCount> EC = F->getEntryCount();
280281
EC && EC->getCount() > 0)
281282
setExplicitlyUnknownBranchWeights(I, PassName);
282283
}

llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,8 +1378,7 @@ static bool foldMemChr(CallInst *Call, DomTreeUpdater *DTU,
13781378
IRB.CreateTrunc(Call->getArgOperand(1), ByteTy), BBNext, N);
13791379
// We can't know the precise weights here, as they would depend on the value
13801380
// distribution of Call->getArgOperand(1). So we just mark it as "unknown".
1381-
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, *Call->getFunction(),
1382-
DEBUG_TYPE);
1381+
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, DEBUG_TYPE);
13831382
Type *IndexTy = DL.getIndexType(Call->getType());
13841383
SmallVector<DominatorTree::UpdateType, 8> Updates;
13851384

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
479479
const Twine &NameStr = "",
480480
InsertPosition InsertBefore = nullptr) {
481481
auto *Sel = SelectInst::Create(C, S1, S2, NameStr, InsertBefore, nullptr);
482-
setExplicitlyUnknownBranchWeightsIfProfiled(*Sel, F, DEBUG_TYPE);
482+
setExplicitlyUnknownBranchWeightsIfProfiled(*Sel, DEBUG_TYPE, &F);
483483
return Sel;
484484
}
485485

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ static void buildPartialUnswitchConditionalBranch(
329329
HasBranchWeights ? ComputeProfFrom.getMetadata(LLVMContext::MD_prof)
330330
: nullptr);
331331
if (!HasBranchWeights)
332-
setExplicitlyUnknownBranchWeightsIfProfiled(
333-
*BR, *BR->getParent()->getParent(), DEBUG_TYPE);
332+
setExplicitlyUnknownBranchWeightsIfProfiled(*BR, DEBUG_TYPE);
334333
}
335334

336335
/// Copy a set of loop invariant values, and conditionally branch on them.

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5212,8 +5212,7 @@ bool SimplifyCFGOpt::simplifyBranchOnICmpChain(BranchInst *BI,
52125212
// We don't have any info about this condition.
52135213
auto *Br = TrueWhenEqual ? Builder.CreateCondBr(ExtraCase, EdgeBB, NewBB)
52145214
: Builder.CreateCondBr(ExtraCase, NewBB, EdgeBB);
5215-
setExplicitlyUnknownBranchWeightsIfProfiled(*Br, *NewBB->getParent(),
5216-
DEBUG_TYPE);
5215+
setExplicitlyUnknownBranchWeightsIfProfiled(*Br, DEBUG_TYPE);
52175216

52185217
OldTI->eraseFromParent();
52195218

0 commit comments

Comments
 (0)