forked from OSchip/llvm-project
[Instruction] Remove setProfWeight()
Remove the function Instruction::setProfWeight() and make use of Instruction::copyMetadata(.., {LLVMContext::MD_prof}). This is correct for all use cases of setProfWeight() as it is applied to CallBase instructions only. This change results in prof metadata copied intact even if the source has "VP". The old pair of calls extractProfTotalWeight() + setProfWeight() resulted in setting branch_weights if the source had "VP" data. Reviewers: yamauchi, davidxl Tags: #llvm Differential Revision: https://reviews.llvm.org/D80987
This commit is contained in:
parent
2f671c4225
commit
417bcb8827
|
@ -332,9 +332,6 @@ public:
|
|||
/// Returns false if no metadata was found.
|
||||
bool extractProfTotalWeight(uint64_t &TotalVal) const;
|
||||
|
||||
/// Sets the branch_weights metadata to \p W for CallInst.
|
||||
void setProfWeight(uint64_t W);
|
||||
|
||||
/// Set the debug location information for this instruction.
|
||||
void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); }
|
||||
|
||||
|
|
|
@ -774,12 +774,3 @@ Instruction *Instruction::clone() const {
|
|||
New->copyMetadata(*this);
|
||||
return New;
|
||||
}
|
||||
|
||||
void Instruction::setProfWeight(uint64_t W) {
|
||||
assert(isa<CallBase>(this) &&
|
||||
"Can only set weights for call like instructions");
|
||||
SmallVector<uint32_t, 1> Weights;
|
||||
Weights.push_back(W);
|
||||
MDBuilder MDB(getContext());
|
||||
setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));
|
||||
}
|
||||
|
|
|
@ -336,10 +336,7 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
|
|||
NewCS->setAttributes(
|
||||
AttributeList::get(F->getContext(), CallPAL.getFnAttributes(),
|
||||
CallPAL.getRetAttributes(), ArgAttrVec));
|
||||
NewCS->setDebugLoc(CB.getDebugLoc());
|
||||
uint64_t W;
|
||||
if (CB.extractProfTotalWeight(W))
|
||||
NewCS->setProfWeight(W);
|
||||
NewCS->copyMetadata(CB, {LLVMContext::MD_prof, LLVMContext::MD_dbg});
|
||||
Args.clear();
|
||||
ArgAttrVec.clear();
|
||||
|
||||
|
|
|
@ -1568,11 +1568,8 @@ ChangeStatus Attributor::rewriteFunctionSignatures(
|
|||
}
|
||||
|
||||
// Copy over various properties and the new attributes.
|
||||
uint64_t W;
|
||||
if (OldCB->extractProfTotalWeight(W))
|
||||
NewCB->setProfWeight(W);
|
||||
NewCB->copyMetadata(*OldCB, {LLVMContext::MD_prof, LLVMContext::MD_dbg});
|
||||
NewCB->setCallingConv(OldCB->getCallingConv());
|
||||
NewCB->setDebugLoc(OldCB->getDebugLoc());
|
||||
NewCB->takeName(OldCB);
|
||||
NewCB->setAttributes(AttributeList::get(
|
||||
Ctx, OldCallAttributeList.getFnAttributes(),
|
||||
|
|
|
@ -205,10 +205,7 @@ bool DeadArgumentEliminationPass::DeleteDeadVarargs(Function &Fn) {
|
|||
}
|
||||
NewCB->setCallingConv(CB->getCallingConv());
|
||||
NewCB->setAttributes(PAL);
|
||||
NewCB->setDebugLoc(CB->getDebugLoc());
|
||||
uint64_t W;
|
||||
if (CB->extractProfTotalWeight(W))
|
||||
NewCB->setProfWeight(W);
|
||||
NewCB->copyMetadata(*CB, {LLVMContext::MD_prof, LLVMContext::MD_dbg});
|
||||
|
||||
Args.clear();
|
||||
|
||||
|
@ -936,10 +933,7 @@ bool DeadArgumentEliminationPass::RemoveDeadStuffFromFunction(Function *F) {
|
|||
}
|
||||
NewCB->setCallingConv(CB.getCallingConv());
|
||||
NewCB->setAttributes(NewCallPAL);
|
||||
NewCB->setDebugLoc(CB.getDebugLoc());
|
||||
uint64_t W;
|
||||
if (CB.extractProfTotalWeight(W))
|
||||
NewCB->setProfWeight(W);
|
||||
NewCB->copyMetadata(CB, {LLVMContext::MD_prof, LLVMContext::MD_dbg});
|
||||
Args.clear();
|
||||
ArgAttrVec.clear();
|
||||
|
||||
|
|
|
@ -4955,11 +4955,8 @@ bool InstCombiner::transformConstExprCastCall(CallBase &Call) {
|
|||
NewCall->setCallingConv(Call.getCallingConv());
|
||||
NewCall->setAttributes(NewCallerPAL);
|
||||
|
||||
// Preserve the weight metadata for the new call instruction. The metadata
|
||||
// is used by SamplePGO to check callsite's hotness.
|
||||
uint64_t W;
|
||||
if (Caller->extractProfTotalWeight(W))
|
||||
NewCall->setProfWeight(W);
|
||||
// Preserve prof metadata if any.
|
||||
NewCall->copyMetadata(*Caller, {LLVMContext::MD_prof});
|
||||
|
||||
// Insert a cast of the return type as necessary.
|
||||
Instruction *NC = NewCall;
|
||||
|
|
|
@ -32,7 +32,7 @@ lpad:
|
|||
unreachable
|
||||
}
|
||||
|
||||
; CHECK: ![[$PROF]] = !{!"branch_weights", i32 2000}
|
||||
; CHECK: ![[$PROF]] = !{!"VP", i32 0, i64 2000, i64 -3913987384944532146, i64 2000}
|
||||
!0 = !{!"VP", i32 0, i64 2000, i64 -3913987384944532146, i64 2000}
|
||||
|
||||
!llvm.module.flags = !{!1}
|
||||
|
|
Loading…
Reference in New Issue