diff options
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 0d5bd9e9429..d66ec8f8d45 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -1120,20 +1120,24 @@ void BranchInst::swapSuccessors() { MDNode::get(ProfileData->getContext(), Ops)); } -bool BranchInst::extractProfMetadata(uint64_t &ProbTrue, uint64_t &ProbFalse) { +bool BranchInst::extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal) { assert(isConditional() && "Looking for probabilities on unconditional branch?"); auto *ProfileData = getMetadata(LLVMContext::MD_prof); if (!ProfileData || ProfileData->getNumOperands() != 3) return false; + auto *ProfDataName = dyn_cast<MDString>(ProfileData->getOperand(0)); + if (!ProfDataName || !ProfDataName->getString().equals("branch_weights")) + return false; + auto *CITrue = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(1)); auto *CIFalse = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(2)); if (!CITrue || !CIFalse) return false; - ProbTrue = CITrue->getValue().getZExtValue(); - ProbFalse = CIFalse->getValue().getZExtValue(); + TrueVal = CITrue->getValue().getZExtValue(); + FalseVal = CIFalse->getValue().getZExtValue(); return true; } |