Index: llvm/include/llvm/IR/Instruction.h =================================================================== --- llvm/include/llvm/IR/Instruction.h +++ llvm/include/llvm/IR/Instruction.h @@ -332,9 +332,6 @@ /// 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); } Index: llvm/lib/IR/Instruction.cpp =================================================================== --- llvm/lib/IR/Instruction.cpp +++ llvm/lib/IR/Instruction.cpp @@ -774,12 +774,3 @@ New->copyMetadata(*this); return New; } - -void Instruction::setProfWeight(uint64_t W) { - assert(isa(this) && - "Can only set weights for call like instructions"); - SmallVector Weights; - Weights.push_back(W); - MDBuilder MDB(getContext()); - setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights)); -} Index: llvm/lib/Transforms/IPO/ArgumentPromotion.cpp =================================================================== --- llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -336,10 +336,7 @@ 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(); Index: llvm/lib/Transforms/IPO/Attributor.cpp =================================================================== --- llvm/lib/Transforms/IPO/Attributor.cpp +++ llvm/lib/Transforms/IPO/Attributor.cpp @@ -1568,11 +1568,8 @@ } // 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(), Index: llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp =================================================================== --- llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -205,10 +205,7 @@ } 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 @@ } 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(); Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -4957,9 +4957,7 @@ // 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); + NewCall->copyMetadata(*Caller, {LLVMContext::MD_prof}); // Insert a cast of the return type as necessary. Instruction *NC = NewCall; Index: llvm/test/Transforms/InstCombine/cast-call-combine-prof.ll =================================================================== --- llvm/test/Transforms/InstCombine/cast-call-combine-prof.ll +++ llvm/test/Transforms/InstCombine/cast-call-combine-prof.ll @@ -32,7 +32,7 @@ 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}