Skip to content

Commit 321b9d1

Browse files
committed
[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.
1 parent b00588f commit 321b9d1

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -970,14 +970,17 @@ class VPIRMetadata {
970970
/// Add all metadata to \p I.
971971
void applyMetadata(Instruction &I) const;
972972

973-
/// Add metadata with kind \p Kind and \p Node.
974-
void addMetadata(unsigned Kind, MDNode *Node) {
975-
assert(none_of(Metadata,
976-
[Kind](const std::pair<unsigned, MDNode *> &P) {
977-
return P.first == Kind;
978-
}) &&
979-
"Kind must appear at most once in Metadata");
980-
Metadata.emplace_back(Kind, Node);
973+
/// Set metadata with kind \p Kind to \p Node. If metadata with \p Kind
974+
/// already exists, it will be replaced. Otherwise, it will be added.
975+
void setMetadata(unsigned Kind, MDNode *Node) {
976+
auto It =
977+
llvm::find_if(Metadata, [Kind](const std::pair<unsigned, MDNode *> &P) {
978+
return P.first == Kind;
979+
});
980+
if (It != Metadata.end())
981+
It->second = Node;
982+
else
983+
Metadata.emplace_back(Kind, Node);
981984
}
982985

983986
/// Intersect this VPIRMetada object with \p MD, keeping only metadata

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ void VPlanTransforms::attachCheckBlock(VPlan &Plan, Value *Cond,
672672
MDBuilder MDB(Plan.getContext());
673673
MDNode *BranchWeights =
674674
MDB.createBranchWeights(CheckBypassWeights, /*IsExpected=*/false);
675-
Term->addMetadata(LLVMContext::MD_prof, BranchWeights);
675+
Term->setMetadata(LLVMContext::MD_prof, BranchWeights);
676676
}
677677
}
678678

@@ -756,7 +756,7 @@ void VPlanTransforms::addMinimumIterationCheck(
756756
MDBuilder MDB(Plan.getContext());
757757
MDNode *BranchWeights = MDB.createBranchWeights(
758758
ArrayRef(MinItersBypassWeights, 2), /*IsExpected=*/false);
759-
Term->addMetadata(LLVMContext::MD_prof, BranchWeights);
759+
Term->setMetadata(LLVMContext::MD_prof, BranchWeights);
760760
}
761761
}
762762

@@ -793,7 +793,7 @@ void VPlanTransforms::addMinimumVectorEpilogueIterationCheck(
793793
MDBuilder MDB(Plan.getContext());
794794
MDNode *BranchWeights =
795795
MDB.createBranchWeights(Weights, /*IsExpected=*/false);
796-
Branch->addMetadata(LLVMContext::MD_prof, BranchWeights);
796+
Branch->setMetadata(LLVMContext::MD_prof, BranchWeights);
797797
}
798798

799799
/// If \p RedPhiR is used by a ComputeReductionResult recipe, return it.

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4458,7 +4458,7 @@ void VPlanTransforms::addBranchWeightToMiddleTerminator(
44584458
MDBuilder MDB(Plan.getContext());
44594459
MDNode *BranchWeights =
44604460
MDB.createBranchWeights({1, VectorStep - 1}, /*IsExpected=*/false);
4461-
MiddleTerm->addMetadata(LLVMContext::MD_prof, BranchWeights);
4461+
MiddleTerm->setMetadata(LLVMContext::MD_prof, BranchWeights);
44624462
}
44634463

44644464
/// Create and return a ResumePhi for \p WideIV, unless it is truncated. If the

0 commit comments

Comments
 (0)