mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-24 13:18:17 +00:00
Thread the determination of branch prediction hit rates back through the if-conversion heuristic APIs. For now,
stick with a constant estimate of 90% (branch predictors are good!), but we might find that we want to provide more nuanced estimates in the future. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115364 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -170,9 +170,11 @@ namespace {
|
||||
|
||||
private:
|
||||
bool ReverseBranchCondition(BBInfo &BBI);
|
||||
bool ValidSimple(BBInfo &TrueBBI, unsigned &Dups, float Prediction) const;
|
||||
bool ValidSimple(BBInfo &TrueBBI, unsigned &Dups,
|
||||
float Prediction, float Confidence) const;
|
||||
bool ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI,
|
||||
bool FalseBranch, unsigned &Dups) const;
|
||||
bool FalseBranch, unsigned &Dups,
|
||||
float Prediction, float Confidence) const;
|
||||
bool ValidDiamond(BBInfo &TrueBBI, BBInfo &FalseBBI,
|
||||
unsigned &Dups1, unsigned &Dups2) const;
|
||||
void ScanInstructions(BBInfo &BBI);
|
||||
@@ -198,15 +200,17 @@ namespace {
|
||||
void MergeBlocks(BBInfo &ToBBI, BBInfo &FromBBI, bool AddEdges = true);
|
||||
|
||||
bool MeetIfcvtSizeLimit(MachineBasicBlock &BB, unsigned Size,
|
||||
float Prediction) const {
|
||||
return Size > 0 && TII->isProfitableToIfCvt(BB, Size, Prediction);
|
||||
float Prediction, float Confidence) const {
|
||||
return Size > 0 && TII->isProfitableToIfCvt(BB, Size,
|
||||
Prediction, Confidence);
|
||||
}
|
||||
|
||||
bool MeetIfcvtSizeLimit(MachineBasicBlock &TBB, unsigned TSize,
|
||||
MachineBasicBlock &FBB, unsigned FSize,
|
||||
float Prediction) const {
|
||||
float Prediction, float Confidence) const {
|
||||
return TSize > 0 && FSize > 0 &&
|
||||
TII->isProfitableToIfCvt(TBB, TSize, FBB, FSize, Prediction);
|
||||
TII->isProfitableToIfCvt(TBB, TSize, FBB, FSize,
|
||||
Prediction, Confidence);
|
||||
}
|
||||
|
||||
// blockAlwaysFallThrough - Block ends without a terminator.
|
||||
@@ -445,7 +449,7 @@ static inline MachineBasicBlock *getNextBlock(MachineBasicBlock *BB) {
|
||||
/// number of instructions that the ifcvt would need to duplicate if performed
|
||||
/// in Dups.
|
||||
bool IfConverter::ValidSimple(BBInfo &TrueBBI, unsigned &Dups,
|
||||
float Prediction) const {
|
||||
float Prediction, float Confidence) const {
|
||||
Dups = 0;
|
||||
if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone)
|
||||
return false;
|
||||
@@ -456,7 +460,7 @@ bool IfConverter::ValidSimple(BBInfo &TrueBBI, unsigned &Dups,
|
||||
if (TrueBBI.BB->pred_size() > 1) {
|
||||
if (TrueBBI.CannotBeCopied ||
|
||||
!TII->isProfitableToDupForIfCvt(*TrueBBI.BB, TrueBBI.NonPredSize,
|
||||
Prediction))
|
||||
Prediction, Confidence))
|
||||
return false;
|
||||
Dups = TrueBBI.NonPredSize;
|
||||
}
|
||||
@@ -471,7 +475,8 @@ bool IfConverter::ValidSimple(BBInfo &TrueBBI, unsigned &Dups,
|
||||
/// returns the number of instructions that the ifcvt would need to duplicate
|
||||
/// if performed in 'Dups'.
|
||||
bool IfConverter::ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI,
|
||||
bool FalseBranch, unsigned &Dups) const {
|
||||
bool FalseBranch, unsigned &Dups,
|
||||
float Prediction, float Confidence) const {
|
||||
Dups = 0;
|
||||
if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone)
|
||||
return false;
|
||||
@@ -493,7 +498,8 @@ bool IfConverter::ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI,
|
||||
++Size;
|
||||
}
|
||||
}
|
||||
if (!TII->isProfitableToDupForIfCvt(*TrueBBI.BB, Size, 0.5))
|
||||
if (!TII->isProfitableToDupForIfCvt(*TrueBBI.BB, Size,
|
||||
Prediction, Confidence))
|
||||
return false;
|
||||
Dups = Size;
|
||||
}
|
||||
@@ -786,7 +792,9 @@ IfConverter::BBInfo &IfConverter::AnalyzeBlock(MachineBasicBlock *BB,
|
||||
// General heuristics are:
|
||||
// - backedge -> 90% taken
|
||||
// - early exit -> 20% taken
|
||||
// - branch predictor confidence -> 90%
|
||||
float Prediction = 0.5f;
|
||||
float Confidence = 0.9f;
|
||||
MachineLoop *Loop = MLI->getLoopFor(BB);
|
||||
if (Loop) {
|
||||
if (TrueBBI.BB == Loop->getHeader())
|
||||
@@ -805,7 +813,7 @@ IfConverter::BBInfo &IfConverter::AnalyzeBlock(MachineBasicBlock *BB,
|
||||
if (CanRevCond && ValidDiamond(TrueBBI, FalseBBI, Dups, Dups2) &&
|
||||
MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize - (Dups + Dups2),
|
||||
*FalseBBI.BB, FalseBBI.NonPredSize - (Dups + Dups2),
|
||||
Prediction) &&
|
||||
Prediction, Confidence) &&
|
||||
FeasibilityAnalysis(TrueBBI, BBI.BrCond) &&
|
||||
FeasibilityAnalysis(FalseBBI, RevCond)) {
|
||||
// Diamond:
|
||||
@@ -821,8 +829,9 @@ IfConverter::BBInfo &IfConverter::AnalyzeBlock(MachineBasicBlock *BB,
|
||||
Enqueued = true;
|
||||
}
|
||||
|
||||
if (ValidTriangle(TrueBBI, FalseBBI, false, Dups) &&
|
||||
MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize, Prediction) &&
|
||||
if (ValidTriangle(TrueBBI, FalseBBI, false, Dups, Prediction, Confidence) &&
|
||||
MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize,
|
||||
Prediction, Confidence) &&
|
||||
FeasibilityAnalysis(TrueBBI, BBI.BrCond, true)) {
|
||||
// Triangle:
|
||||
// EBB
|
||||
@@ -835,15 +844,17 @@ IfConverter::BBInfo &IfConverter::AnalyzeBlock(MachineBasicBlock *BB,
|
||||
Enqueued = true;
|
||||
}
|
||||
|
||||
if (ValidTriangle(TrueBBI, FalseBBI, true, Dups) &&
|
||||
MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize, Prediction) &&
|
||||
if (ValidTriangle(TrueBBI, FalseBBI, true, Dups, Prediction, Confidence) &&
|
||||
MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize,
|
||||
Prediction, Confidence) &&
|
||||
FeasibilityAnalysis(TrueBBI, BBI.BrCond, true, true)) {
|
||||
Tokens.push_back(new IfcvtToken(BBI, ICTriangleRev, TNeedSub, Dups));
|
||||
Enqueued = true;
|
||||
}
|
||||
|
||||
if (ValidSimple(TrueBBI, Dups, Prediction) &&
|
||||
MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize, Prediction) &&
|
||||
if (ValidSimple(TrueBBI, Dups, Prediction, Confidence) &&
|
||||
MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize,
|
||||
Prediction, Confidence) &&
|
||||
FeasibilityAnalysis(TrueBBI, BBI.BrCond)) {
|
||||
// Simple (split, no rejoin):
|
||||
// EBB
|
||||
@@ -858,22 +869,27 @@ IfConverter::BBInfo &IfConverter::AnalyzeBlock(MachineBasicBlock *BB,
|
||||
|
||||
if (CanRevCond) {
|
||||
// Try the other path...
|
||||
if (ValidTriangle(FalseBBI, TrueBBI, false, Dups) &&
|
||||
MeetIfcvtSizeLimit(*FalseBBI.BB, FalseBBI.NonPredSize,1.0-Prediction) &&
|
||||
if (ValidTriangle(FalseBBI, TrueBBI, false, Dups,
|
||||
1.0-Prediction, Confidence) &&
|
||||
MeetIfcvtSizeLimit(*FalseBBI.BB, FalseBBI.NonPredSize,
|
||||
1.0-Prediction, Confidence) &&
|
||||
FeasibilityAnalysis(FalseBBI, RevCond, true)) {
|
||||
Tokens.push_back(new IfcvtToken(BBI, ICTriangleFalse, FNeedSub, Dups));
|
||||
Enqueued = true;
|
||||
}
|
||||
|
||||
if (ValidTriangle(FalseBBI, TrueBBI, true, Dups) &&
|
||||
MeetIfcvtSizeLimit(*FalseBBI.BB, FalseBBI.NonPredSize,1.0-Prediction) &&
|
||||
if (ValidTriangle(FalseBBI, TrueBBI, true, Dups,
|
||||
1.0-Prediction, Confidence) &&
|
||||
MeetIfcvtSizeLimit(*FalseBBI.BB, FalseBBI.NonPredSize,
|
||||
1.0-Prediction, Confidence) &&
|
||||
FeasibilityAnalysis(FalseBBI, RevCond, true, true)) {
|
||||
Tokens.push_back(new IfcvtToken(BBI, ICTriangleFRev, FNeedSub, Dups));
|
||||
Enqueued = true;
|
||||
}
|
||||
|
||||
if (ValidSimple(FalseBBI, Dups, 1.0-Prediction) &&
|
||||
MeetIfcvtSizeLimit(*FalseBBI.BB, FalseBBI.NonPredSize,1.0-Prediction) &&
|
||||
if (ValidSimple(FalseBBI, Dups, 1.0-Prediction, Confidence) &&
|
||||
MeetIfcvtSizeLimit(*FalseBBI.BB, FalseBBI.NonPredSize,
|
||||
1.0-Prediction, Confidence) &&
|
||||
FeasibilityAnalysis(FalseBBI, RevCond)) {
|
||||
Tokens.push_back(new IfcvtToken(BBI, ICSimpleFalse, FNeedSub, Dups));
|
||||
Enqueued = true;
|
||||
|
||||
Reference in New Issue
Block a user