[llvm] 321b9d1 - [VPlan] Replace VPIRMetadata::addMetadata with setMetadata. (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 17 12:57:31 PST 2025
Author: Florian Hahn
Date: 2025-11-17T20:55:18Z
New Revision: 321b9d190b32c2c10bbd59761e34ef0305bdb954
URL: https://github.com/llvm/llvm-project/commit/321b9d190b32c2c10bbd59761e34ef0305bdb954
DIFF: https://github.com/llvm/llvm-project/commit/321b9d190b32c2c10bbd59761e34ef0305bdb954.diff
LOG: [VPlan] Replace VPIRMetadata::addMetadata with setMetadata. (NFC)
Replace addMetadata with setMetadata, which sets metadata, updating
existing entries or adding a new entry otherwise.
This isn't strictly needed at the moment, but will be needed for
follow-up patches.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 0932922c07126..67fa294d095bd 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -970,14 +970,17 @@ class VPIRMetadata {
/// Add all metadata to \p I.
void applyMetadata(Instruction &I) const;
- /// Add metadata with kind \p Kind and \p Node.
- void addMetadata(unsigned Kind, MDNode *Node) {
- assert(none_of(Metadata,
- [Kind](const std::pair<unsigned, MDNode *> &P) {
- return P.first == Kind;
- }) &&
- "Kind must appear at most once in Metadata");
- Metadata.emplace_back(Kind, Node);
+ /// Set metadata with kind \p Kind to \p Node. If metadata with \p Kind
+ /// already exists, it will be replaced. Otherwise, it will be added.
+ void setMetadata(unsigned Kind, MDNode *Node) {
+ auto It =
+ llvm::find_if(Metadata, [Kind](const std::pair<unsigned, MDNode *> &P) {
+ return P.first == Kind;
+ });
+ if (It != Metadata.end())
+ It->second = Node;
+ else
+ Metadata.emplace_back(Kind, Node);
}
/// Intersect this VPIRMetada object with \p MD, keeping only metadata
diff --git a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
index 4ffd5577d31a4..aed85271350c8 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
@@ -672,7 +672,7 @@ void VPlanTransforms::attachCheckBlock(VPlan &Plan, Value *Cond,
MDBuilder MDB(Plan.getContext());
MDNode *BranchWeights =
MDB.createBranchWeights(CheckBypassWeights, /*IsExpected=*/false);
- Term->addMetadata(LLVMContext::MD_prof, BranchWeights);
+ Term->setMetadata(LLVMContext::MD_prof, BranchWeights);
}
}
@@ -756,7 +756,7 @@ void VPlanTransforms::addMinimumIterationCheck(
MDBuilder MDB(Plan.getContext());
MDNode *BranchWeights = MDB.createBranchWeights(
ArrayRef(MinItersBypassWeights, 2), /*IsExpected=*/false);
- Term->addMetadata(LLVMContext::MD_prof, BranchWeights);
+ Term->setMetadata(LLVMContext::MD_prof, BranchWeights);
}
}
@@ -793,7 +793,7 @@ void VPlanTransforms::addMinimumVectorEpilogueIterationCheck(
MDBuilder MDB(Plan.getContext());
MDNode *BranchWeights =
MDB.createBranchWeights(Weights, /*IsExpected=*/false);
- Branch->addMetadata(LLVMContext::MD_prof, BranchWeights);
+ Branch->setMetadata(LLVMContext::MD_prof, BranchWeights);
}
/// If \p RedPhiR is used by a ComputeReductionResult recipe, return it.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index bbeb447de45cb..3e2c47e4556a6 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -4458,7 +4458,7 @@ void VPlanTransforms::addBranchWeightToMiddleTerminator(
MDBuilder MDB(Plan.getContext());
MDNode *BranchWeights =
MDB.createBranchWeights({1, VectorStep - 1}, /*IsExpected=*/false);
- MiddleTerm->addMetadata(LLVMContext::MD_prof, BranchWeights);
+ MiddleTerm->setMetadata(LLVMContext::MD_prof, BranchWeights);
}
/// Create and return a ResumePhi for \p WideIV, unless it is truncated. If the
More information about the llvm-commits
mailing list