mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
Switch the internal "Info" map from an std::map to a DenseMap. This
speeds up idom by about 45% and postidom by about 33%. Some extra precautions must be taken not to invalidate densemap iterators. llvm-svn: 40827
This commit is contained in:
parent
5912537997
commit
a5a692b9bb
@ -127,7 +127,7 @@ protected:
|
|||||||
std::vector<BasicBlock*> Vertex;
|
std::vector<BasicBlock*> Vertex;
|
||||||
|
|
||||||
// Info - Collection of information used during the computation of idoms.
|
// Info - Collection of information used during the computation of idoms.
|
||||||
std::map<BasicBlock*, InfoRec> Info;
|
DenseMap<BasicBlock*, InfoRec> Info;
|
||||||
|
|
||||||
void updateDFSNumbers();
|
void updateDFSNumbers();
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void calculate(Function& F);
|
void calculate(Function& F);
|
||||||
DomTreeNode *getNodeForBlock(BasicBlock *BB);
|
DomTreeNode *getNodeForBlock(BasicBlock *BB);
|
||||||
unsigned DFSPass(BasicBlock *V, InfoRec &VInfo, unsigned N);
|
unsigned DFSPass(BasicBlock *V, unsigned N);
|
||||||
void Compress(BasicBlock *V);
|
void Compress(BasicBlock *V);
|
||||||
BasicBlock *Eval(BasicBlock *v);
|
BasicBlock *Eval(BasicBlock *v);
|
||||||
void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
|
void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
|
||||||
|
@ -39,7 +39,7 @@ struct PostDominatorTree : public DominatorTreeBase {
|
|||||||
private:
|
private:
|
||||||
void calculate(Function &F);
|
void calculate(Function &F);
|
||||||
DomTreeNode *getNodeForBlock(BasicBlock *BB);
|
DomTreeNode *getNodeForBlock(BasicBlock *BB);
|
||||||
unsigned DFSPass(BasicBlock *V, InfoRec &VInfo,unsigned N);
|
unsigned DFSPass(BasicBlock *V, unsigned N);
|
||||||
void Compress(BasicBlock *V, InfoRec &VInfo);
|
void Compress(BasicBlock *V, InfoRec &VInfo);
|
||||||
BasicBlock *Eval(BasicBlock *V);
|
BasicBlock *Eval(BasicBlock *V);
|
||||||
void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
|
void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
|
||||||
|
@ -27,28 +27,25 @@ char PostDominanceFrontier::ID = 0;
|
|||||||
static RegisterPass<PostDominatorTree>
|
static RegisterPass<PostDominatorTree>
|
||||||
F("postdomtree", "Post-Dominator Tree Construction", true);
|
F("postdomtree", "Post-Dominator Tree Construction", true);
|
||||||
|
|
||||||
unsigned PostDominatorTree::DFSPass(BasicBlock *V, InfoRec &VInfo,
|
unsigned PostDominatorTree::DFSPass(BasicBlock *V, unsigned N) {
|
||||||
unsigned N) {
|
std::vector<BasicBlock *> workStack;
|
||||||
std::vector<std::pair<BasicBlock *, InfoRec *> > workStack;
|
|
||||||
std::set<BasicBlock *> visited;
|
std::set<BasicBlock *> visited;
|
||||||
workStack.push_back(std::make_pair(V, &VInfo));
|
workStack.push_back(V);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
BasicBlock *currentBB = workStack.back().first;
|
BasicBlock *currentBB = workStack.back();
|
||||||
InfoRec *currentVInfo = workStack.back().second;
|
InfoRec &CurVInfo = Info[currentBB];
|
||||||
|
|
||||||
// Visit each block only once.
|
// Visit each block only once.
|
||||||
if (visited.count(currentBB) == 0) {
|
if (visited.insert(currentBB).second) {
|
||||||
|
CurVInfo.Semi = ++N;
|
||||||
visited.insert(currentBB);
|
CurVInfo.Label = currentBB;
|
||||||
currentVInfo->Semi = ++N;
|
|
||||||
currentVInfo->Label = currentBB;
|
|
||||||
|
|
||||||
Vertex.push_back(currentBB); // Vertex[n] = current;
|
Vertex.push_back(currentBB); // Vertex[n] = current;
|
||||||
// Info[currentBB].Ancestor = 0;
|
// Info[currentBB].Ancestor = 0;
|
||||||
// Ancestor[n] = 0
|
// Ancestor[n] = 0
|
||||||
// Child[currentBB] = 0;
|
// Child[currentBB] = 0;
|
||||||
currentVInfo->Size = 1; // Size[currentBB] = 1
|
CurVInfo.Size = 1; // Size[currentBB] = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visit children
|
// Visit children
|
||||||
@ -58,8 +55,8 @@ unsigned PostDominatorTree::DFSPass(BasicBlock *V, InfoRec &VInfo,
|
|||||||
InfoRec &SuccVInfo = Info[*PI];
|
InfoRec &SuccVInfo = Info[*PI];
|
||||||
if (SuccVInfo.Semi == 0) {
|
if (SuccVInfo.Semi == 0) {
|
||||||
SuccVInfo.Parent = currentBB;
|
SuccVInfo.Parent = currentBB;
|
||||||
if (visited.count (*PI) == 0) {
|
if (!visited.count(*PI)) {
|
||||||
workStack.push_back(std::make_pair(*PI, &SuccVInfo));
|
workStack.push_back(*PI);
|
||||||
visitChild = true;
|
visitChild = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +127,7 @@ void PostDominatorTree::calculate(Function &F) {
|
|||||||
// in later stages of the algorithm.
|
// in later stages of the algorithm.
|
||||||
unsigned N = 0;
|
unsigned N = 0;
|
||||||
for (unsigned i = 0, e = Roots.size(); i != e; ++i)
|
for (unsigned i = 0, e = Roots.size(); i != e; ++i)
|
||||||
N = DFSPass(Roots[i], Info[Roots[i]], N);
|
N = DFSPass(Roots[i], N);
|
||||||
|
|
||||||
for (unsigned i = N; i >= 2; --i) {
|
for (unsigned i = N; i >= 2; --i) {
|
||||||
BasicBlock *W = Vertex[i];
|
BasicBlock *W = Vertex[i];
|
||||||
|
@ -146,12 +146,12 @@ void DominatorTree::splitBlock(BasicBlock *NewBB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned DominatorTree::DFSPass(BasicBlock *V, InfoRec &VInfo,
|
unsigned DominatorTree::DFSPass(BasicBlock *V, unsigned N) {
|
||||||
unsigned N) {
|
|
||||||
// This is more understandable as a recursive algorithm, but we can't use the
|
// This is more understandable as a recursive algorithm, but we can't use the
|
||||||
// recursive algorithm due to stack depth issues. Keep it here for
|
// recursive algorithm due to stack depth issues. Keep it here for
|
||||||
// documentation purposes.
|
// documentation purposes.
|
||||||
#if 0
|
#if 0
|
||||||
|
InfoRec &VInfo = Info[Roots[i]];
|
||||||
VInfo.Semi = ++N;
|
VInfo.Semi = ++N;
|
||||||
VInfo.Label = V;
|
VInfo.Label = V;
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ unsigned DominatorTree::DFSPass(BasicBlock *V, InfoRec &VInfo,
|
|||||||
InfoRec &SuccVInfo = Info[*SI];
|
InfoRec &SuccVInfo = Info[*SI];
|
||||||
if (SuccVInfo.Semi == 0) {
|
if (SuccVInfo.Semi == 0) {
|
||||||
SuccVInfo.Parent = V;
|
SuccVInfo.Parent = V;
|
||||||
N = DFSPass(*SI, SuccVInfo, N);
|
N = DFSPass(*SI, N);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -313,7 +313,7 @@ void DominatorTree::Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DominatorTree::calculate(Function& F) {
|
void DominatorTree::calculate(Function &F) {
|
||||||
BasicBlock* Root = Roots[0];
|
BasicBlock* Root = Roots[0];
|
||||||
|
|
||||||
// Add a node for the root...
|
// Add a node for the root...
|
||||||
@ -323,9 +323,7 @@ void DominatorTree::calculate(Function& F) {
|
|||||||
|
|
||||||
// Step #1: Number blocks in depth-first order and initialize variables used
|
// Step #1: Number blocks in depth-first order and initialize variables used
|
||||||
// in later stages of the algorithm.
|
// in later stages of the algorithm.
|
||||||
unsigned N = 0;
|
unsigned N = DFSPass(Root, 0);
|
||||||
for (unsigned i = 0, e = Roots.size(); i != e; ++i)
|
|
||||||
N = DFSPass(Roots[i], Info[Roots[i]], 0);
|
|
||||||
|
|
||||||
for (unsigned i = N; i >= 2; --i) {
|
for (unsigned i = N; i >= 2; --i) {
|
||||||
BasicBlock *W = Vertex[i];
|
BasicBlock *W = Vertex[i];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user