summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Instructions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r--llvm/lib/IR/Instructions.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index f4c6a289b80..5ea45357864 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -805,6 +805,26 @@ void BranchInst::swapSuccessors() {
MDNode::get(ProfileData->getContext(), Ops));
}
+bool BranchInst::getBranchWeights(uint64_t &TrueWeight,
+ uint64_t &FalseWeight) const {
+ if (isUnconditional())
+ return false;
+
+ auto *MD = getMetadata(LLVMContext::MD_prof);
+ if (!MD || MD->getNumOperands() != 3)
+ return false;
+
+ auto *TrueCI = dyn_cast<ConstantInt>(MD->getOperand(1));
+ auto *FalseCI = dyn_cast<ConstantInt>(MD->getOperand(2));
+ if (!TrueCI || !FalseCI)
+ return false;
+
+ TrueWeight = TrueCI->getValue().getZExtValue();
+ FalseWeight = FalseCI->getValue().getZExtValue();
+
+ return true;
+}
+
BasicBlock *BranchInst::getSuccessorV(unsigned idx) const {
return getSuccessor(idx);
}
OpenPOWER on IntegriCloud