mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-21 06:30:16 +00:00
BranchProbabilityInfo: floating point equality is unlikely.
This is from the same paper from Ball and Larus as the rest of the currently implemented heuristics. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142677 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cdcfa28056
commit
c888aa47bd
@ -76,6 +76,9 @@ class BranchProbabilityAnalysis {
|
|||||||
static const uint32_t ZH_TAKEN_WEIGHT = 20;
|
static const uint32_t ZH_TAKEN_WEIGHT = 20;
|
||||||
static const uint32_t ZH_NONTAKEN_WEIGHT = 12;
|
static const uint32_t ZH_NONTAKEN_WEIGHT = 12;
|
||||||
|
|
||||||
|
static const uint32_t FPH_TAKEN_WEIGHT = 20;
|
||||||
|
static const uint32_t FPH_NONTAKEN_WEIGHT = 12;
|
||||||
|
|
||||||
// Standard weight value. Used when none of the heuristics set weight for
|
// Standard weight value. Used when none of the heuristics set weight for
|
||||||
// the edge.
|
// the edge.
|
||||||
static const uint32_t NORMAL_WEIGHT = 16;
|
static const uint32_t NORMAL_WEIGHT = 16;
|
||||||
@ -131,9 +134,12 @@ public:
|
|||||||
// Loop Branch Heuristics
|
// Loop Branch Heuristics
|
||||||
bool calcLoopBranchHeuristics(BasicBlock *BB);
|
bool calcLoopBranchHeuristics(BasicBlock *BB);
|
||||||
|
|
||||||
// Zero Heurestics
|
// Zero Heuristics
|
||||||
bool calcZeroHeuristics(BasicBlock *BB);
|
bool calcZeroHeuristics(BasicBlock *BB);
|
||||||
|
|
||||||
|
// Floating Point Heuristics
|
||||||
|
bool calcFloatingPointHeuristics(BasicBlock *BB);
|
||||||
|
|
||||||
bool runOnFunction(Function &F);
|
bool runOnFunction(Function &F);
|
||||||
};
|
};
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
@ -378,6 +384,29 @@ bool BranchProbabilityAnalysis::calcZeroHeuristics(BasicBlock *BB) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BranchProbabilityAnalysis::calcFloatingPointHeuristics(BasicBlock *BB) {
|
||||||
|
BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator());
|
||||||
|
if (!BI || !BI->isConditional())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Value *Cond = BI->getCondition();
|
||||||
|
FCmpInst *FCmp = dyn_cast<FCmpInst>(Cond);
|
||||||
|
if (!FCmp || !FCmp->isEquality())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
BasicBlock *Taken = BI->getSuccessor(0);
|
||||||
|
BasicBlock *NonTaken = BI->getSuccessor(1);
|
||||||
|
|
||||||
|
// f1 == f2 -> Unlikely
|
||||||
|
// f1 != f2 -> Likely
|
||||||
|
if (FCmp->isTrueWhenEqual())
|
||||||
|
std::swap(Taken, NonTaken);
|
||||||
|
|
||||||
|
BP->setEdgeWeight(BB, Taken, FPH_TAKEN_WEIGHT);
|
||||||
|
BP->setEdgeWeight(BB, NonTaken, FPH_NONTAKEN_WEIGHT);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool BranchProbabilityAnalysis::runOnFunction(Function &F) {
|
bool BranchProbabilityAnalysis::runOnFunction(Function &F) {
|
||||||
|
|
||||||
@ -396,7 +425,10 @@ bool BranchProbabilityAnalysis::runOnFunction(Function &F) {
|
|||||||
if (calcPointerHeuristics(BB))
|
if (calcPointerHeuristics(BB))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
calcZeroHeuristics(BB);
|
if (calcZeroHeuristics(BB))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
calcFloatingPointHeuristics(BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user