mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-05 09:44:02 +00:00
Allow multiple ifcvt candidates to share children blocks; add some debugging code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37379 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
243f348c2a
commit
5f70218c75
@ -11,7 +11,8 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#define DEBUG_TYPE "ifconversion"
|
#define DEBUG_TYPE "ifcvt"
|
||||||
|
#include "llvm/Function.h"
|
||||||
#include "llvm/CodeGen/Passes.h"
|
#include "llvm/CodeGen/Passes.h"
|
||||||
#include "llvm/CodeGen/MachineModuleInfo.h"
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
||||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||||
@ -105,6 +106,12 @@ namespace {
|
|||||||
std::vector<MachineOperand> &Cond,
|
std::vector<MachineOperand> &Cond,
|
||||||
bool IgnoreTerm = false);
|
bool IgnoreTerm = false);
|
||||||
void MergeBlocks(BBInfo &TrueBBI, BBInfo &FalseBBI);
|
void MergeBlocks(BBInfo &TrueBBI, BBInfo &FalseBBI);
|
||||||
|
|
||||||
|
// IfcvtCandidateCmp - Used to sort if-conversion candidates.
|
||||||
|
static bool IfcvtCandidateCmp(BBInfo* C1, BBInfo* C2){
|
||||||
|
// Favor diamond over triangle, etc.
|
||||||
|
return (unsigned)C1->Kind < (unsigned)C2->Kind;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
char IfConverter::ID = 0;
|
char IfConverter::ID = 0;
|
||||||
}
|
}
|
||||||
@ -116,9 +123,10 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
TII = MF.getTarget().getInstrInfo();
|
TII = MF.getTarget().getInstrInfo();
|
||||||
if (!TII) return false;
|
if (!TII) return false;
|
||||||
|
|
||||||
|
DOUT << "\nIfcvt: function \'" << MF.getFunction()->getName() << "\'\n";
|
||||||
|
|
||||||
MF.RenumberBlocks();
|
MF.RenumberBlocks();
|
||||||
unsigned NumBBs = MF.getNumBlockIDs();
|
BBAnalysis.resize(MF.getNumBlockIDs());
|
||||||
BBAnalysis.resize(NumBBs);
|
|
||||||
|
|
||||||
// Look for root nodes, i.e. blocks without successors.
|
// Look for root nodes, i.e. blocks without successors.
|
||||||
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
|
||||||
@ -139,13 +147,19 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
switch (BBI.Kind) {
|
switch (BBI.Kind) {
|
||||||
default: assert(false && "Unexpected!");
|
default: assert(false && "Unexpected!");
|
||||||
break;
|
break;
|
||||||
|
case ICReAnalyze:
|
||||||
|
// One or more of 'childrean' have been modified, abort!
|
||||||
|
break;
|
||||||
case ICEarlyExit:
|
case ICEarlyExit:
|
||||||
|
DOUT << "Ifcvt (Early exit): BB#" << BBI.BB->getNumber() << "\n";
|
||||||
Change |= IfConvertEarlyExit(BBI);
|
Change |= IfConvertEarlyExit(BBI);
|
||||||
break;
|
break;
|
||||||
case ICTriangle:
|
case ICTriangle:
|
||||||
|
DOUT << "Ifcvt (Triangle): BB#" << BBI.BB->getNumber() << "\n";
|
||||||
Change |= IfConvertTriangle(BBI);
|
Change |= IfConvertTriangle(BBI);
|
||||||
break;
|
break;
|
||||||
case ICDiamond:
|
case ICDiamond:
|
||||||
|
DOUT << "Ifcvt (Diamond): BB#" << BBI.BB->getNumber() << "\n";
|
||||||
Change |= IfConvertDiamond(BBI);
|
Change |= IfConvertDiamond(BBI);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -198,8 +212,6 @@ void IfConverter::StructuralAnalysis(MachineBasicBlock *BB) {
|
|||||||
// Not a candidate if 'true' block is going to be if-converted.
|
// Not a candidate if 'true' block is going to be if-converted.
|
||||||
StructuralAnalysis(BBI.TrueBB);
|
StructuralAnalysis(BBI.TrueBB);
|
||||||
BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
|
BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
|
||||||
if (TrueBBI.Kind != ICNotClassfied)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// TODO: Only handle very simple cases for now.
|
// TODO: Only handle very simple cases for now.
|
||||||
if (TrueBBI.FalseBB || TrueBBI.BrCond.size())
|
if (TrueBBI.FalseBB || TrueBBI.BrCond.size())
|
||||||
@ -214,8 +226,6 @@ void IfConverter::StructuralAnalysis(MachineBasicBlock *BB) {
|
|||||||
// Not a candidate if 'false' block is going to be if-converted.
|
// Not a candidate if 'false' block is going to be if-converted.
|
||||||
StructuralAnalysis(BBI.FalseBB);
|
StructuralAnalysis(BBI.FalseBB);
|
||||||
BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
|
BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
|
||||||
if (FalseBBI.Kind != ICNotClassfied)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// TODO: Only handle very simple cases for now.
|
// TODO: Only handle very simple cases for now.
|
||||||
if (FalseBBI.FalseBB || FalseBBI.BrCond.size())
|
if (FalseBBI.FalseBB || FalseBBI.BrCond.size())
|
||||||
@ -338,6 +348,9 @@ bool IfConverter::AnalyzeBlocks(MachineFunction &MF,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort to favor more complex ifcvt scheme.
|
||||||
|
std::stable_sort(Candidates.begin(), Candidates.end(), IfcvtCandidateCmp);
|
||||||
|
|
||||||
return Change;
|
return Change;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user