mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-26 09:18:56 +00:00
Add MachineTraceMetrics::verify().
This function verifies the consistency of cached data in the MachineTraceMetrics analysis. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160976 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -586,11 +586,13 @@ void EarlyIfConverter::updateLoops(ArrayRef<MachineBasicBlock*> Removed) {
|
|||||||
|
|
||||||
/// Invalidate MachineTraceMetrics before if-conversion.
|
/// Invalidate MachineTraceMetrics before if-conversion.
|
||||||
void EarlyIfConverter::invalidateTraces() {
|
void EarlyIfConverter::invalidateTraces() {
|
||||||
|
Traces->verify();
|
||||||
Traces->invalidate(IfConv.Head);
|
Traces->invalidate(IfConv.Head);
|
||||||
Traces->invalidate(IfConv.Tail);
|
Traces->invalidate(IfConv.Tail);
|
||||||
Traces->invalidate(IfConv.TBB);
|
Traces->invalidate(IfConv.TBB);
|
||||||
Traces->invalidate(IfConv.FBB);
|
Traces->invalidate(IfConv.FBB);
|
||||||
DEBUG(if (MinInstr) MinInstr->print(dbgs()));
|
DEBUG(if (MinInstr) MinInstr->print(dbgs()));
|
||||||
|
Traces->verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply cost model and heuristics to the if-conversion in IfConv.
|
/// Apply cost model and heuristics to the if-conversion in IfConv.
|
||||||
|
@@ -44,13 +44,13 @@ void MachineTraceMetrics::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||||||
MachineFunctionPass::getAnalysisUsage(AU);
|
MachineFunctionPass::getAnalysisUsage(AU);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MachineTraceMetrics::runOnMachineFunction(MachineFunction &MF) {
|
bool MachineTraceMetrics::runOnMachineFunction(MachineFunction &Func) {
|
||||||
TII = MF.getTarget().getInstrInfo();
|
MF = &Func;
|
||||||
TRI = MF.getTarget().getRegisterInfo();
|
TII = MF->getTarget().getInstrInfo();
|
||||||
MRI = &MF.getRegInfo();
|
TRI = MF->getTarget().getRegisterInfo();
|
||||||
|
MRI = &MF->getRegInfo();
|
||||||
Loops = &getAnalysis<MachineLoopInfo>();
|
Loops = &getAnalysis<MachineLoopInfo>();
|
||||||
unsigned NumBlocks = MF.getNumBlockIDs();
|
BlockInfo.resize(MF->getNumBlockIDs());
|
||||||
BlockInfo.resize(NumBlocks);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,8 +128,8 @@ MachineTraceMetrics::Ensemble::Ensemble(MachineTraceMetrics *ct)
|
|||||||
// Virtual destructor serves as an anchor.
|
// Virtual destructor serves as an anchor.
|
||||||
MachineTraceMetrics::Ensemble::~Ensemble() {}
|
MachineTraceMetrics::Ensemble::~Ensemble() {}
|
||||||
|
|
||||||
MachineLoop*
|
const MachineLoop*
|
||||||
MachineTraceMetrics::Ensemble::getLoopFor(const MachineBasicBlock *MBB) {
|
MachineTraceMetrics::Ensemble::getLoopFor(const MachineBasicBlock *MBB) const {
|
||||||
return CT.Loops->getLoopFor(MBB);
|
return CT.Loops->getLoopFor(MBB);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ const MachineBasicBlock*
|
|||||||
MinInstrCountEnsemble::pickTracePred(const MachineBasicBlock *MBB) {
|
MinInstrCountEnsemble::pickTracePred(const MachineBasicBlock *MBB) {
|
||||||
if (MBB->pred_empty())
|
if (MBB->pred_empty())
|
||||||
return 0;
|
return 0;
|
||||||
MachineLoop *CurLoop = getLoopFor(MBB);
|
const MachineLoop *CurLoop = getLoopFor(MBB);
|
||||||
// Don't leave loops, and never follow back-edges.
|
// Don't leave loops, and never follow back-edges.
|
||||||
if (CurLoop && MBB == CurLoop->getHeader())
|
if (CurLoop && MBB == CurLoop->getHeader())
|
||||||
return 0;
|
return 0;
|
||||||
@@ -258,7 +258,7 @@ const MachineBasicBlock*
|
|||||||
MinInstrCountEnsemble::pickTraceSucc(const MachineBasicBlock *MBB) {
|
MinInstrCountEnsemble::pickTraceSucc(const MachineBasicBlock *MBB) {
|
||||||
if (MBB->pred_empty())
|
if (MBB->pred_empty())
|
||||||
return 0;
|
return 0;
|
||||||
MachineLoop *CurLoop = getLoopFor(MBB);
|
const MachineLoop *CurLoop = getLoopFor(MBB);
|
||||||
const MachineBasicBlock *Best = 0;
|
const MachineBasicBlock *Best = 0;
|
||||||
unsigned BestHeight = 0;
|
unsigned BestHeight = 0;
|
||||||
for (MachineBasicBlock::const_succ_iterator
|
for (MachineBasicBlock::const_succ_iterator
|
||||||
@@ -306,6 +306,15 @@ void MachineTraceMetrics::invalidate(const MachineBasicBlock *MBB) {
|
|||||||
Ensembles[i]->invalidate(MBB);
|
Ensembles[i]->invalidate(MBB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MachineTraceMetrics::verify() const {
|
||||||
|
#ifndef NDEBUG
|
||||||
|
assert(BlockInfo.size() == MF->getNumBlockIDs() && "Outdated BlockInfo size");
|
||||||
|
for (unsigned i = 0; i != TS_NumStrategies; ++i)
|
||||||
|
if (Ensembles[i])
|
||||||
|
Ensembles[i]->verify();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Trace building
|
// Trace building
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@@ -460,6 +469,33 @@ MachineTraceMetrics::Ensemble::invalidate(const MachineBasicBlock *BadMBB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MachineTraceMetrics::Ensemble::verify() const {
|
||||||
|
#ifndef NDEBUG
|
||||||
|
assert(BlockInfo.size() == CT.MF->getNumBlockIDs() &&
|
||||||
|
"Outdated BlockInfo size");
|
||||||
|
for (unsigned Num = 0, e = BlockInfo.size(); Num != e; ++Num) {
|
||||||
|
const TraceBlockInfo &TBI = BlockInfo[Num];
|
||||||
|
if (TBI.hasValidDepth() && TBI.Pred) {
|
||||||
|
const MachineBasicBlock *MBB = CT.MF->getBlockNumbered(Num);
|
||||||
|
assert(MBB->isPredecessor(TBI.Pred) && "CFG doesn't match trace");
|
||||||
|
assert(BlockInfo[TBI.Pred->getNumber()].hasValidDepth() &&
|
||||||
|
"Trace is broken, depth should have been invalidated.");
|
||||||
|
const MachineLoop *Loop = getLoopFor(MBB);
|
||||||
|
assert(!(Loop && MBB == Loop->getHeader()) && "Trace contains backedge");
|
||||||
|
}
|
||||||
|
if (TBI.hasValidHeight() && TBI.Succ) {
|
||||||
|
const MachineBasicBlock *MBB = CT.MF->getBlockNumbered(Num);
|
||||||
|
assert(MBB->isSuccessor(TBI.Succ) && "CFG doesn't match trace");
|
||||||
|
assert(BlockInfo[TBI.Succ->getNumber()].hasValidHeight() &&
|
||||||
|
"Trace is broken, height should have been invalidated.");
|
||||||
|
const MachineLoop *Loop = getLoopFor(MBB);
|
||||||
|
const MachineLoop *SuccLoop = getLoopFor(TBI.Succ);
|
||||||
|
assert(!(Loop && Loop == SuccLoop && TBI.Succ == Loop->getHeader()) &&
|
||||||
|
"Trace contains backedge");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
MachineTraceMetrics::Trace
|
MachineTraceMetrics::Trace
|
||||||
MachineTraceMetrics::Ensemble::getTrace(const MachineBasicBlock *MBB) {
|
MachineTraceMetrics::Ensemble::getTrace(const MachineBasicBlock *MBB) {
|
||||||
|
@@ -61,6 +61,7 @@ class MachineLoop;
|
|||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
|
|
||||||
class MachineTraceMetrics : public MachineFunctionPass {
|
class MachineTraceMetrics : public MachineFunctionPass {
|
||||||
|
const MachineFunction *MF;
|
||||||
const TargetInstrInfo *TII;
|
const TargetInstrInfo *TII;
|
||||||
const TargetRegisterInfo *TRI;
|
const TargetRegisterInfo *TRI;
|
||||||
const MachineRegisterInfo *MRI;
|
const MachineRegisterInfo *MRI;
|
||||||
@@ -178,7 +179,7 @@ public:
|
|||||||
virtual const MachineBasicBlock *pickTracePred(const MachineBasicBlock*) =0;
|
virtual const MachineBasicBlock *pickTracePred(const MachineBasicBlock*) =0;
|
||||||
virtual const MachineBasicBlock *pickTraceSucc(const MachineBasicBlock*) =0;
|
virtual const MachineBasicBlock *pickTraceSucc(const MachineBasicBlock*) =0;
|
||||||
explicit Ensemble(MachineTraceMetrics*);
|
explicit Ensemble(MachineTraceMetrics*);
|
||||||
MachineLoop *getLoopFor(const MachineBasicBlock*);
|
const MachineLoop *getLoopFor(const MachineBasicBlock*) const;
|
||||||
const TraceBlockInfo *getDepthResources(const MachineBasicBlock*) const;
|
const TraceBlockInfo *getDepthResources(const MachineBasicBlock*) const;
|
||||||
const TraceBlockInfo *getHeightResources(const MachineBasicBlock*) const;
|
const TraceBlockInfo *getHeightResources(const MachineBasicBlock*) const;
|
||||||
|
|
||||||
@@ -187,6 +188,7 @@ public:
|
|||||||
virtual const char *getName() const =0;
|
virtual const char *getName() const =0;
|
||||||
void print(raw_ostream&) const;
|
void print(raw_ostream&) const;
|
||||||
void invalidate(const MachineBasicBlock *MBB);
|
void invalidate(const MachineBasicBlock *MBB);
|
||||||
|
void verify() const;
|
||||||
|
|
||||||
/// Get the trace that passes through MBB.
|
/// Get the trace that passes through MBB.
|
||||||
/// The trace is computed on demand.
|
/// The trace is computed on demand.
|
||||||
@@ -210,6 +212,10 @@ public:
|
|||||||
/// is erased, or the CFG is otherwise changed.
|
/// is erased, or the CFG is otherwise changed.
|
||||||
void invalidate(const MachineBasicBlock *MBB);
|
void invalidate(const MachineBasicBlock *MBB);
|
||||||
|
|
||||||
|
/// Verify the internal consistency of cached data.
|
||||||
|
/// This does nothing in NDEBUG builds.
|
||||||
|
void verify() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// One entry per basic block, indexed by block number.
|
// One entry per basic block, indexed by block number.
|
||||||
SmallVector<FixedBlockInfo, 4> BlockInfo;
|
SmallVector<FixedBlockInfo, 4> BlockInfo;
|
||||||
|
Reference in New Issue
Block a user