mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 06:32:24 +00:00
Change ET-Forest to automatically recalculate its DFSnum's if too many slow
queries are made. Patch by Daniel Berlin! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25323 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b47fad9892
commit
25abb1dc09
@ -397,16 +397,17 @@ public:
|
|||||||
///
|
///
|
||||||
struct ETForestBase : public DominatorBase {
|
struct ETForestBase : public DominatorBase {
|
||||||
ETForestBase(bool isPostDom) : DominatorBase(isPostDom), Nodes(),
|
ETForestBase(bool isPostDom) : DominatorBase(isPostDom), Nodes(),
|
||||||
DFSInfoValid(false) {}
|
DFSInfoValid(false), SlowQueries(0) {}
|
||||||
|
|
||||||
virtual void releaseMemory() { reset(); }
|
virtual void releaseMemory() { reset(); }
|
||||||
|
|
||||||
typedef std::map<BasicBlock*, ETNode*> ETMapType;
|
typedef std::map<BasicBlock*, ETNode*> ETMapType;
|
||||||
|
|
||||||
|
void updateDFSNumbers();
|
||||||
|
|
||||||
/// dominates - Return true if A dominates B.
|
/// dominates - Return true if A dominates B.
|
||||||
///
|
///
|
||||||
inline bool dominates(BasicBlock *A, BasicBlock *B) const {
|
inline bool dominates(BasicBlock *A, BasicBlock *B) {
|
||||||
if (A == B)
|
if (A == B)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -415,13 +416,21 @@ struct ETForestBase : public DominatorBase {
|
|||||||
|
|
||||||
if (DFSInfoValid)
|
if (DFSInfoValid)
|
||||||
return NodeB->DominatedBy(NodeA);
|
return NodeB->DominatedBy(NodeA);
|
||||||
else
|
else {
|
||||||
|
// If we end up with too many slow queries, just update the
|
||||||
|
// DFS numbers on the theory that we are going to keep querying.
|
||||||
|
SlowQueries++;
|
||||||
|
if (SlowQueries > 32) {
|
||||||
|
updateDFSNumbers();
|
||||||
|
return NodeB->DominatedBy(NodeA);
|
||||||
|
}
|
||||||
return NodeB->DominatedBySlow(NodeA);
|
return NodeB->DominatedBySlow(NodeA);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// properlyDominates - Return true if A dominates B and A != B.
|
/// properlyDominates - Return true if A dominates B and A != B.
|
||||||
///
|
///
|
||||||
bool properlyDominates(BasicBlock *A, BasicBlock *B) const {
|
bool properlyDominates(BasicBlock *A, BasicBlock *B) {
|
||||||
return dominates(A, B) && A != B;
|
return dominates(A, B) && A != B;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,6 +483,7 @@ protected:
|
|||||||
void reset();
|
void reset();
|
||||||
ETMapType Nodes;
|
ETMapType Nodes;
|
||||||
bool DFSInfoValid;
|
bool DFSInfoValid;
|
||||||
|
unsigned int SlowQueries;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -297,8 +297,8 @@ public:
|
|||||||
|
|
||||||
static void stub(); // Noop
|
static void stub(); // Noop
|
||||||
private:
|
private:
|
||||||
void Calculate(const ETForest &EF);
|
void Calculate(ETForest &EF);
|
||||||
Loop *ConsiderForLoop(BasicBlock *BB, const ETForest &EF);
|
Loop *ConsiderForLoop(BasicBlock *BB, ETForest &EF);
|
||||||
void MoveSiblingLoopInto(Loop *NewChild, Loop *NewParent);
|
void MoveSiblingLoopInto(Loop *NewChild, Loop *NewParent);
|
||||||
void InsertLoopInto(Loop *L, Loop *Parent);
|
void InsertLoopInto(Loop *L, Loop *Parent);
|
||||||
};
|
};
|
||||||
|
@ -104,7 +104,7 @@ void LoopInfo::releaseMemory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LoopInfo::Calculate(const ETForest &EF) {
|
void LoopInfo::Calculate(ETForest &EF) {
|
||||||
BasicBlock *RootNode = EF.getRoot();
|
BasicBlock *RootNode = EF.getRoot();
|
||||||
|
|
||||||
for (df_iterator<BasicBlock*> NI = df_begin(RootNode),
|
for (df_iterator<BasicBlock*> NI = df_begin(RootNode),
|
||||||
@ -135,7 +135,7 @@ static bool isNotAlreadyContainedIn(Loop *SubLoop, Loop *ParentLoop) {
|
|||||||
return isNotAlreadyContainedIn(SubLoop->getParentLoop(), ParentLoop);
|
return isNotAlreadyContainedIn(SubLoop->getParentLoop(), ParentLoop);
|
||||||
}
|
}
|
||||||
|
|
||||||
Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const ETForest &EF) {
|
Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, ETForest &EF) {
|
||||||
if (BBMap.find(BB) != BBMap.end()) return 0; // Haven't processed this node?
|
if (BBMap.find(BB) != BBMap.end()) return 0; // Haven't processed this node?
|
||||||
|
|
||||||
std::vector<BasicBlock *> TodoStack;
|
std::vector<BasicBlock *> TodoStack;
|
||||||
|
@ -812,6 +812,21 @@ void ETForestBase::reset() {
|
|||||||
Nodes.clear();
|
Nodes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ETForestBase::updateDFSNumbers()
|
||||||
|
{
|
||||||
|
int dfsnum = 0;
|
||||||
|
// Iterate over all nodes in depth first order.
|
||||||
|
for (unsigned i = 0, e = Roots.size(); i != e; ++i)
|
||||||
|
for (df_iterator<BasicBlock*> I = df_begin(Roots[i]),
|
||||||
|
E = df_end(Roots[i]); I != E; ++I) {
|
||||||
|
BasicBlock *BB = *I;
|
||||||
|
if (!getNode(BB)->hasFather())
|
||||||
|
getNode(BB)->assignDFSNumber(dfsnum);
|
||||||
|
}
|
||||||
|
SlowQueries = 0;
|
||||||
|
DFSInfoValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
ETNode *ETForest::getNodeForBlock(BasicBlock *BB) {
|
ETNode *ETForest::getNodeForBlock(BasicBlock *BB) {
|
||||||
ETNode *&BBNode = Nodes[BB];
|
ETNode *&BBNode = Nodes[BB];
|
||||||
if (BBNode) return BBNode;
|
if (BBNode) return BBNode;
|
||||||
@ -855,12 +870,14 @@ void ETForest::calculate(const ImmediateDominators &ID) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int dfsnum = 0;
|
// Make sure we've got nodes around for every block
|
||||||
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
|
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
|
||||||
if (!getNodeForBlock(I)->hasFather())
|
ETNode *&BBNode = Nodes[I];
|
||||||
getNodeForBlock(I)->assignDFSNumber(dfsnum);
|
if (!BBNode)
|
||||||
|
BBNode = new ETNode(I);
|
||||||
}
|
}
|
||||||
DFSInfoValid = true;
|
|
||||||
|
updateDFSNumbers ();
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user