1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

Use iterative while loop instead of recursive function call.

llvm-svn: 36694
This commit is contained in:
Devang Patel 2007-05-03 20:55:18 +00:00
parent d28d0bac2a
commit e0b9bd0e49
2 changed files with 34 additions and 14 deletions

View File

@ -225,7 +225,7 @@ private:
void calculate(Function& F);
Node *getNodeForBlock(BasicBlock *BB);
unsigned DFSPass(BasicBlock *V, InfoRec &VInfo, unsigned N);
void Compress(BasicBlock *V, InfoRec &VInfo);
void Compress(BasicBlock *V);
BasicBlock *Eval(BasicBlock *v);
void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
inline BasicBlock *getIDom(BasicBlock *BB) const {

View File

@ -124,20 +124,40 @@ unsigned DominatorTree::DFSPass(BasicBlock *V, InfoRec &VInfo,
return N;
}
void DominatorTree::Compress(BasicBlock *V, InfoRec &VInfo) {
BasicBlock *VAncestor = VInfo.Ancestor;
InfoRec &VAInfo = Info[VAncestor];
if (VAInfo.Ancestor == 0)
return;
void DominatorTree::Compress(BasicBlock *VIn) {
Compress(VAncestor, VAInfo);
std::vector<BasicBlock *> Work;
std::set<BasicBlock *> Visited;
InfoRec &VInInfo = Info[VIn];
BasicBlock *VInAncestor = VInInfo.Ancestor;
InfoRec &VInVAInfo = Info[VInAncestor];
BasicBlock *VAncestorLabel = VAInfo.Label;
BasicBlock *VLabel = VInfo.Label;
if (Info[VAncestorLabel].Semi < Info[VLabel].Semi)
VInfo.Label = VAncestorLabel;
if (VInVAInfo.Ancestor != 0)
Work.push_back(VIn);
while (!Work.empty()) {
BasicBlock *V = Work.back();
InfoRec &VInfo = Info[V];
BasicBlock *VAncestor = VInfo.Ancestor;
InfoRec &VAInfo = Info[VAncestor];
VInfo.Ancestor = VAInfo.Ancestor;
// Process Ancestor first
if (Visited.count(VAncestor) == 0 && VAInfo.Ancestor != 0) {
Work.push_back(VAncestor);
Visited.insert(VAncestor);
continue;
}
Work.pop_back();
// Update VINfo based on Ancestor info
if (VAInfo.Ancestor == 0)
continue;
BasicBlock *VAncestorLabel = VAInfo.Label;
BasicBlock *VLabel = VInfo.Label;
if (Info[VAncestorLabel].Semi < Info[VLabel].Semi)
VInfo.Label = VAncestorLabel;
VInfo.Ancestor = VAInfo.Ancestor;
}
}
BasicBlock *DominatorTree::Eval(BasicBlock *V) {
@ -146,13 +166,13 @@ BasicBlock *DominatorTree::Eval(BasicBlock *V) {
// Higher-complexity but faster implementation
if (VInfo.Ancestor == 0)
return V;
Compress(V, VInfo);
Compress(V);
return VInfo.Label;
#else
// Lower-complexity but slower implementation
if (VInfo.Ancestor == 0)
return VInfo.Label;
Compress(V, VInfo);
Compress(V);
BasicBlock *VLabel = VInfo.Label;
BasicBlock *VAncestorLabel = Info[VInfo.Ancestor].Label;