summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2016-04-23 20:01:22 +0000
committerSanjay Patel <spatel@rotateright.com>2016-04-23 20:01:22 +0000
commitdc88bd6e1fc483d6927604e6b2dc58f9d4d06316 (patch)
tree9963b5030c58af2b3510fde489e4b99baeed8d93 /llvm/lib/CodeGen/CodeGenPrepare.cpp
parent179d1f5dadbbd4a338ea7c5954bb917ca043b99b (diff)
downloadbcm5719-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/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp27
1 files changed, 2 insertions, 25 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index e34233a5c15..9ba93a956fa 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -5427,29 +5427,6 @@ bool CodeGenPrepare::sinkAndCmp(Function &F) {
return MadeChange;
}
-/// \brief Retrieve the probabilities of a conditional branch. Returns true on
-/// success, or returns false if no or invalid metadata was found.
-static bool extractBranchMetadata(BranchInst *BI,
- uint64_t &ProbTrue, uint64_t &ProbFalse) {
- assert(BI->isConditional() &&
- "Looking for probabilities on unconditional branch?");
- auto *ProfileData = BI->getMetadata(LLVMContext::MD_prof);
- if (!ProfileData || ProfileData->getNumOperands() != 3)
- return false;
-
- const auto *CITrue =
- mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(1));
- const auto *CIFalse =
- mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(2));
- if (!CITrue || !CIFalse)
- return false;
-
- ProbTrue = CITrue->getValue().getZExtValue();
- ProbFalse = CIFalse->getValue().getZExtValue();
-
- return true;
-}
-
/// \brief Scale down both weights to fit into uint32_t.
static void scaleWeights(uint64_t &NewTrue, uint64_t &NewFalse) {
uint64_t NewMax = (NewTrue > NewFalse) ? NewTrue : NewFalse;
@@ -5595,7 +5572,7 @@ bool CodeGenPrepare::splitBranchCondition(Function &F) {
// Another choice is to assume TrueProb for BB1 equals to TrueProb for
// TmpBB, but the math is more complicated.
uint64_t TrueWeight, FalseWeight;
- if (extractBranchMetadata(Br1, TrueWeight, FalseWeight)) {
+ if (Br1->extractProfMetadata(TrueWeight, FalseWeight)) {
uint64_t NewTrueWeight = TrueWeight;
uint64_t NewFalseWeight = TrueWeight + 2 * FalseWeight;
scaleWeights(NewTrueWeight, NewFalseWeight);
@@ -5628,7 +5605,7 @@ bool CodeGenPrepare::splitBranchCondition(Function &F) {
// assumes that
// FalseProb for BB1 == TrueProb for BB1 * FalseProb for TmpBB.
uint64_t TrueWeight, FalseWeight;
- if (extractBranchMetadata(Br1, TrueWeight, FalseWeight)) {
+ if (Br1->extractProfMetadata(TrueWeight, FalseWeight)) {
uint64_t NewTrueWeight = 2 * TrueWeight + FalseWeight;
uint64_t NewFalseWeight = FalseWeight;
scaleWeights(NewTrueWeight, NewFalseWeight);
OpenPOWER on IntegriCloud