summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kirth <paulkirth@google.com>2024-06-06 21:13:53 +0000
committerPaul Kirth <paulkirth@google.com>2024-06-06 21:13:53 +0000
commitee0267bc397227423f3c153fd41cf314c9a99675 (patch)
treea4441ff953d34b81192aef0eb368c9d9a9b92c6c
parent76928786a9fa72e73edc4fdc8845ce0b9c406584 (diff)
Created using spr 1.3.4 [skip ci]
-rw-r--r--llvm/include/llvm/IR/ProfDataUtils.h4
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp9
-rw-r--r--llvm/lib/IR/Metadata.cpp8
-rw-r--r--llvm/lib/IR/ProfDataUtils.cpp14
-rw-r--r--llvm/lib/IR/Verifier.cpp2
-rw-r--r--llvm/lib/Transforms/Scalar/JumpThreading.cpp4
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp2
-rw-r--r--llvm/lib/Transforms/Utils/MisExpect.cpp2
8 files changed, 22 insertions, 23 deletions
diff --git a/llvm/include/llvm/IR/ProfDataUtils.h b/llvm/include/llvm/IR/ProfDataUtils.h
index 3c761bdc1bf3..1d7c97d9be95 100644
--- a/llvm/include/llvm/IR/ProfDataUtils.h
+++ b/llvm/include/llvm/IR/ProfDataUtils.h
@@ -57,11 +57,11 @@ MDNode *getValidBranchWeightMDNode(const Instruction &I);
/// Check if Branch Weight Metadata has an "expected" field from an llvm.expect*
/// intrinsic
-bool hasBranchWeightProvenance(const Instruction &I);
+bool hasBranchWeightOrigin(const Instruction &I);
/// Check if Branch Weight Metadata has an "expected" field from an llvm.expect*
/// intrinsic
-bool hasBranchWeightProvenance(const MDNode *ProfileData);
+bool hasBranchWeightOrigin(const MDNode *ProfileData);
/// Return the offset to the first branch weight data
unsigned getBranchWeightOffset(const MDNode *ProfileData);
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index ce11caca3898..0e01080bd75c 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -8864,11 +8864,10 @@ bool CodeGenPrepare::splitBranchCondition(Function &F, ModifyDT &ModifiedDT) {
uint64_t NewTrueWeight = TrueWeight;
uint64_t NewFalseWeight = TrueWeight + 2 * FalseWeight;
scaleWeights(NewTrueWeight, NewFalseWeight);
- Br1->setMetadata(
- LLVMContext::MD_prof,
- MDBuilder(Br1->getContext())
- .createBranchWeights(TrueWeight, FalseWeight,
- hasBranchWeightProvenance(*Br1)));
+ Br1->setMetadata(LLVMContext::MD_prof,
+ MDBuilder(Br1->getContext())
+ .createBranchWeights(TrueWeight, FalseWeight,
+ hasBranchWeightOrigin(*Br1)));
NewTrueWeight = TrueWeight;
NewFalseWeight = 2 * FalseWeight;
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index b6c932495a14..5f42ce22f72f 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -1196,10 +1196,10 @@ MDNode *MDNode::mergeDirectCallProfMetadata(MDNode *A, MDNode *B,
StringRef AProfName = AMDS->getString();
StringRef BProfName = BMDS->getString();
if (AProfName == "branch_weights" && BProfName == "branch_weights") {
- ConstantInt *AInstrWeight =
- mdconst::dyn_extract<ConstantInt>(A->getOperand(1));
- ConstantInt *BInstrWeight =
- mdconst::dyn_extract<ConstantInt>(B->getOperand(1));
+ ConstantInt *AInstrWeight = mdconst::dyn_extract<ConstantInt>(
+ A->getOperand(getBranchWeightOffset(A)));
+ ConstantInt *BInstrWeight = mdconst::dyn_extract<ConstantInt>(
+ B->getOperand(getBranchWeightOffset(B)));
assert(AInstrWeight && BInstrWeight && "verified by LLVM verifier");
return MDNode::get(Ctx,
{MDHelper.createString("branch_weights"),
diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp
index af536d2110ea..c4b1ed55de8a 100644
--- a/llvm/lib/IR/ProfDataUtils.cpp
+++ b/llvm/lib/IR/ProfDataUtils.cpp
@@ -121,24 +121,24 @@ bool hasValidBranchWeightMD(const Instruction &I) {
return getValidBranchWeightMDNode(I);
}
-bool hasBranchWeightProvenance(const Instruction &I) {
+bool hasBranchWeightOrigin(const Instruction &I) {
auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
- return hasBranchWeightProvenance(ProfileData);
+ return hasBranchWeightOrigin(ProfileData);
}
-bool hasBranchWeightProvenance(const MDNode *ProfileData) {
+bool hasBranchWeightOrigin(const MDNode *ProfileData) {
if (!isBranchWeightMD(ProfileData))
return false;
auto *ProfDataName = dyn_cast<MDString>(ProfileData->getOperand(1));
// NOTE: if we ever have more types of branch weight provenance,
// we need to check the string value is "expected". For now, we
// supply a more generic API, and avoid the spurious comparisons.
- assert(ProfDataName->getString() == "expected");
- return ProfDataName;
+ assert(ProfDataName == nullptr || ProfDataName->getString() == "expected");
+ return ProfDataName != nullptr;
}
unsigned getBranchWeightOffset(const MDNode *ProfileData) {
- return hasBranchWeightProvenance(ProfileData) ? 2 : 1;
+ return hasBranchWeightOrigin(ProfileData) ? 2 : 1;
}
MDNode *getBranchWeightMDNode(const Instruction &I) {
@@ -210,7 +210,7 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
if (!ProfDataName)
return false;
- if (ProfDataName->getString().equals("branch_weights")) {
+ if (ProfDataName->getString() == "branch_weights") {
unsigned Offset = getBranchWeightOffset(ProfileData);
for (unsigned Idx = Offset; Idx < ProfileData->getNumOperands(); ++Idx) {
auto *V = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(Idx));
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 39185905a151..e0fde2b7d90d 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -4808,7 +4808,7 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
StringRef ProfName = MDS->getString();
// Check consistency of !prof branch_weights metadata.
- if (ProfName.equals("branch_weights")) {
+ if (ProfName == "branch_weights") {
unsigned int Offset = getBranchWeightOffset(MD);
if (isa<InvokeInst>(&I)) {
Check(MD->getNumOperands() == (1 + Offset) ||
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 88307b8b074e..b9583836aea0 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -231,7 +231,7 @@ static void updatePredecessorProfileMetadata(PHINode *PN, BasicBlock *BB) {
Weights[0] = BP.getCompl().getNumerator();
Weights[1] = BP.getNumerator();
}
- setBranchWeights(*PredBr, Weights, hasBranchWeightProvenance(*PredBr));
+ setBranchWeights(*PredBr, Weights, hasBranchWeightOrigin(*PredBr));
}
}
@@ -2618,7 +2618,7 @@ void JumpThreadingPass::updateBlockFreqAndEdgeWeight(BasicBlock *PredBB,
Weights.push_back(Prob.getNumerator());
auto TI = BB->getTerminator();
- setBranchWeights(*TI, Weights, hasBranchWeightProvenance(*TI));
+ setBranchWeights(*TI, Weights, hasBranchWeightOrigin(*TI));
}
}
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 8f116c42d3d7..12229123675e 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -231,7 +231,7 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
// Remove weight for this case.
std::swap(Weights[Idx + 1], Weights.back());
Weights.pop_back();
- setBranchWeights(*SI, Weights, hasBranchWeightProvenance(MD));
+ setBranchWeights(*SI, Weights, hasBranchWeightOrigin(MD));
}
// Remove this entry.
BasicBlock *ParentBB = SI->getParent();
diff --git a/llvm/lib/Transforms/Utils/MisExpect.cpp b/llvm/lib/Transforms/Utils/MisExpect.cpp
index 59e13795f0f2..aef9d82db042 100644
--- a/llvm/lib/Transforms/Utils/MisExpect.cpp
+++ b/llvm/lib/Transforms/Utils/MisExpect.cpp
@@ -185,7 +185,7 @@ void checkBackendInstrumentation(Instruction &I,
// times, leading to an invalid assumption in our checking. Backend checks
// should only operate on branch weights that carry the "!expected" field,
// since they are guaranteed to be added by the LowerExpectIntrinsic pass.
- if (!hasBranchWeightProvenance(I))
+ if (!hasBranchWeightOrigin(I))
return;
SmallVector<uint32_t> ExpectedWeights;
if (!extractBranchWeights(I, ExpectedWeights))