diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-04-23 20:01:22 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-04-23 20:01:22 +0000 |
commit | dc88bd6e1fc483d6927604e6b2dc58f9d4d06316 (patch) | |
tree | 9963b5030c58af2b3510fde489e4b99baeed8d93 /llvm/lib/IR | |
parent | 179d1f5dadbbd4a338ea7c5954bb917ca043b99b (diff) | |
download | bcm5719-llvm-dc88bd6e1fc483d6927604e6b2dc58f9d4d06316.tar.gz bcm5719-llvm-dc88bd6e1fc483d6927604e6b2dc58f9d4d06316.zip |
replace duplicated static functions for profile metadata access with BranchInst member function; NFCI
llvm-svn: 267295
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 8ad9c070a4e..0ac65f1e371 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -1120,6 +1120,24 @@ void BranchInst::swapSuccessors() { MDNode::get(ProfileData->getContext(), Ops)); } +bool BranchInst::extractProfMetadata(uint64_t &ProbTrue, uint64_t &ProbFalse) { + assert(isConditional() && + "Looking for probabilities on unconditional branch?"); + auto *ProfileData = getMetadata(LLVMContext::MD_prof); + if (!ProfileData || ProfileData->getNumOperands() != 3) + 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(); + + return true; +} + BasicBlock *BranchInst::getSuccessorV(unsigned idx) const { return getSuccessor(idx); } |