diff options
author | Paul Kirth <paulkirth@google.com> | 2024-06-06 21:13:56 +0000 |
---|---|---|
committer | Paul Kirth <paulkirth@google.com> | 2024-06-06 21:13:56 +0000 |
commit | 5ced677c322a917d6370beb421b39c6e9a3952ad (patch) | |
tree | 56fe2229d026b70317911825907af78c8ee43b0e | |
parent | 6e54349847e867f39db31c795181b4d27743976e (diff) | |
parent | ee0267bc397227423f3c153fd41cf314c9a99675 (diff) |
Created using spr 1.3.4
-rw-r--r-- | llvm/include/llvm/IR/ProfDataUtils.h | 4 | ||||
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/IR/Metadata.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/IR/ProfDataUtils.cpp | 14 | ||||
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/MisExpect.cpp | 2 |
8 files changed, 24 insertions, 25 deletions
diff --git a/llvm/include/llvm/IR/ProfDataUtils.h b/llvm/include/llvm/IR/ProfDataUtils.h index 7008d3240fed..0bea517df832 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 5bd1f137272f..3c3acabc2663 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; } unsigned getNumBranchWeights(const MDNode &ProfileData) { @@ -212,7 +212,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 3ed547808767..956f87d01280 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 NumBranchWeights = getNumBranchWeights(*MD); if (isa<InvokeInst>(&I)) { Check(NumBranchWeights == 1 || NumBranchWeights == 2, @@ -4831,8 +4831,8 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) { CheckFailed("!prof branch_weights are not allowed for this instruction", MD); - Check(NumBranchWeights == ExpectedNumOperands, - "Wrong number of operands", MD); + Check(NumBranchWeights == ExpectedNumOperands, "Wrong number of operands", + MD); } for (unsigned i = getBranchWeightOffset(MD); i < MD->getNumOperands(); ++i) { 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)) |