[llvm-branch-commits] [llvm][IR] Extend BranchWeightMetadata to track provenance of weights (PR #86609)
Paul Kirth via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Apr 22 09:09:33 PDT 2024
================
@@ -1210,12 +1210,22 @@ Instruction *Instruction::cloneImpl() const {
void Instruction::swapProfMetadata() {
MDNode *ProfileData = getBranchWeightMDNode(*this);
- if (!ProfileData || ProfileData->getNumOperands() != 3)
+ if (!isBranchWeightMD(ProfileData))
return;
- // The first operand is the name. Fetch them backwards and build a new one.
- Metadata *Ops[] = {ProfileData->getOperand(0), ProfileData->getOperand(2),
- ProfileData->getOperand(1)};
+ SmallVector<Metadata *, 4> Ops;
+ unsigned int FirstIdx = getBranchWeightOffset(ProfileData);
+ unsigned int SecondIdx = FirstIdx + 1;
+ // If there are more weights past the second, we can't swap them
+ if (ProfileData->getNumOperands() > SecondIdx + 1)
+ return;
+ Ops.push_back(ProfileData->getOperand(0));
+ if (hasExpectedProvenance(ProfileData)) {
+ Ops.push_back(ProfileData->getOperand(1));
+ }
----------------
ilovepi wrote:
That's a good suggestion. I'll update the patch to reflect.
https://github.com/llvm/llvm-project/pull/86609
More information about the llvm-branch-commits
mailing list