Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions llvm/include/llvm/IR/ProfDataUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ LLVM_ABI void setExplicitlyUnknownBranchWeights(Instruction &I,
/// Like setExplicitlyUnknownBranchWeights(...), but only sets unknown branch
/// weights in the new instruction if the parent function of the original
/// instruction has an entry count. This is to not confuse users by injecting
/// profile data into non-profiled functions.
LLVM_ABI void setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I,
Function &F,
StringRef PassName);
/// profile data into non-profiled functions. If \p F is nullptr, we will fetch
/// the function from \p I.
LLVM_ABI void
setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I, StringRef PassName,
const Function *F = nullptr);

/// Analogous to setExplicitlyUnknownBranchWeights, but for functions and their
/// entry counts.
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/IR/IRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,7 @@ Value *IRBuilderBase::CreateSelectWithUnknownProfile(Value *C, Value *True,
const Twine &Name) {
Value *Ret = CreateSelectFMF(C, True, False, {}, Name);
if (auto *SI = dyn_cast<SelectInst>(Ret)) {
setExplicitlyUnknownBranchWeightsIfProfiled(
*SI, *SI->getParent()->getParent(), PassName);
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, PassName);
}
return Ret;
}
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/IR/ProfDataUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@ void llvm::setExplicitlyUnknownBranchWeights(Instruction &I,
}

void llvm::setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I,
Function &F,
StringRef PassName) {
if (std::optional<Function::ProfileCount> EC = F.getEntryCount();
StringRef PassName,
const Function *F) {
F = F ? F : I.getFunction();
if (std::optional<Function::ProfileCount> EC = F->getEntryCount();
EC && EC->getCount() > 0)
setExplicitlyUnknownBranchWeights(I, PassName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1378,8 +1378,7 @@ static bool foldMemChr(CallInst *Call, DomTreeUpdater *DTU,
IRB.CreateTrunc(Call->getArgOperand(1), ByteTy), BBNext, N);
// We can't know the precise weights here, as they would depend on the value
// distribution of Call->getArgOperand(1). So we just mark it as "unknown".
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, *Call->getFunction(),
DEBUG_TYPE);
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, DEBUG_TYPE);
Type *IndexTy = DL.getIndexType(Call->getType());
SmallVector<DominatorTree::UpdateType, 8> Updates;

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
const Twine &NameStr = "",
InsertPosition InsertBefore = nullptr) {
auto *Sel = SelectInst::Create(C, S1, S2, NameStr, InsertBefore, nullptr);
setExplicitlyUnknownBranchWeightsIfProfiled(*Sel, F, DEBUG_TYPE);
setExplicitlyUnknownBranchWeightsIfProfiled(*Sel, DEBUG_TYPE, &F);
return Sel;
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ static void buildPartialUnswitchConditionalBranch(
HasBranchWeights ? ComputeProfFrom.getMetadata(LLVMContext::MD_prof)
: nullptr);
if (!HasBranchWeights)
setExplicitlyUnknownBranchWeightsIfProfiled(
*BR, *BR->getParent()->getParent(), DEBUG_TYPE);
setExplicitlyUnknownBranchWeightsIfProfiled(*BR, DEBUG_TYPE);
}

/// Copy a set of loop invariant values, and conditionally branch on them.
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5212,8 +5212,7 @@ bool SimplifyCFGOpt::simplifyBranchOnICmpChain(BranchInst *BI,
// We don't have any info about this condition.
auto *Br = TrueWhenEqual ? Builder.CreateCondBr(ExtraCase, EdgeBB, NewBB)
: Builder.CreateCondBr(ExtraCase, NewBB, EdgeBB);
setExplicitlyUnknownBranchWeightsIfProfiled(*Br, *NewBB->getParent(),
DEBUG_TYPE);
setExplicitlyUnknownBranchWeightsIfProfiled(*Br, DEBUG_TYPE);

OldTI->eraseFromParent();

Expand Down