1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[Dominators] Move number to node mapping out of DominatorTreeBase

Summary: Number to node mapping in DominatorTreeBase is used only during calculation, so there is no point keeping is as a member variable. This patch moves this mapping to Calculate function and passes it to helper functions. It also makes the name more descriptive.

Reviewers: sanjoy, dberlin, davide, chandlerc

Reviewed By: dberlin

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D34295

llvm-svn: 306562
This commit is contained in:
Jakub Kuderski 2017-06-28 16:54:34 +00:00
parent 4ca37431f8
commit 7a0cc0a004
2 changed files with 38 additions and 36 deletions

View File

@ -229,7 +229,6 @@ template <class NodeT> class DominatorTreeBase : public DominatorBase<NodeT> {
void wipe() {
DomTreeNodes.clear();
IDoms.clear();
Vertex.clear();
Info.clear();
RootNode = nullptr;
}
@ -254,9 +253,6 @@ protected:
DenseMap<NodeT *, NodeT *> IDoms;
// Vertex - Map the DFS number to the NodeT*
std::vector<NodeT *> Vertex;
// Info - Collection of information used during the computation of idoms.
DenseMap<NodeT *, InfoRec> Info;
@ -264,7 +260,6 @@ protected:
DomTreeNodes.clear();
IDoms.clear();
this->Roots.clear();
Vertex.clear();
RootNode = nullptr;
DFSInfoValid = false;
SlowQueries = 0;
@ -338,8 +333,9 @@ public:
DomTreeNodes(std::move(Arg.DomTreeNodes)),
RootNode(std::move(Arg.RootNode)),
DFSInfoValid(std::move(Arg.DFSInfoValid)),
SlowQueries(std::move(Arg.SlowQueries)), IDoms(std::move(Arg.IDoms)),
Vertex(std::move(Arg.Vertex)), Info(std::move(Arg.Info)) {
SlowQueries(std::move(Arg.SlowQueries)),
IDoms(std::move(Arg.IDoms)),
Info(std::move(Arg.Info)) {
Arg.wipe();
}
@ -351,7 +347,6 @@ public:
DFSInfoValid = std::move(RHS.DFSInfoValid);
SlowQueries = std::move(RHS.SlowQueries);
IDoms = std::move(RHS.IDoms);
Vertex = std::move(RHS.Vertex);
Info = std::move(RHS.Info);
RHS.wipe();
return *this;
@ -675,17 +670,21 @@ public:
protected:
template <class GraphT>
friend typename GraphT::NodeRef
Eval(DominatorTreeBaseByGraphTraits<GraphT> &DT, typename GraphT::NodeRef V,
friend typename GraphT::NodeRef Eval(
DominatorTreeBaseByGraphTraits<GraphT> &DT, typename GraphT::NodeRef V,
const std::vector<typename GraphT::NodeRef> &NumToNode,
unsigned LastLinked);
template <class GraphT>
friend unsigned ReverseDFSPass(DominatorTreeBaseByGraphTraits<GraphT> &DT,
typename GraphT::NodeRef V, unsigned N);
friend unsigned ReverseDFSPass(
DominatorTreeBaseByGraphTraits<GraphT> &DT, typename GraphT::NodeRef V,
std::vector<typename GraphT::NodeRef> &NumToNode, unsigned N);
template <class GraphT>
friend unsigned DFSPass(DominatorTreeBaseByGraphTraits<GraphT> &DT,
typename GraphT::NodeRef V, unsigned N);
typename GraphT::NodeRef V,
std::vector<typename GraphT::NodeRef> &NumToNode,
unsigned N);
template <class FuncT, class N>
friend void Calculate(DominatorTreeBaseByGraphTraits<GraphTraits<N>> &DT,
@ -767,7 +766,6 @@ public:
template <class FT> void recalculate(FT &F) {
using TraitsTy = GraphTraits<FT *>;
reset();
Vertex.push_back(nullptr);
if (!this->IsPostDominators) {
// Initialize root

View File

@ -51,7 +51,9 @@ private:
template <class GraphT>
unsigned ReverseDFSPass(DominatorTreeBaseByGraphTraits<GraphT> &DT,
typename GraphT::NodeRef V, unsigned N) {
typename GraphT::NodeRef V,
std::vector<typename GraphT::NodeRef> &NumToNode,
unsigned N) {
df_iterator_dom_storage<
typename GraphT::NodeRef,
typename DominatorTreeBaseByGraphTraits<GraphT>::InfoRec>
@ -67,7 +69,7 @@ unsigned ReverseDFSPass(DominatorTreeBaseByGraphTraits<GraphT> &DT,
// and is 1 based, so we subtract to account for both of these.
if (I.getPathLength() > 1)
BBInfo.Parent = DT.Info[I.getPath(I.getPathLength() - 2)].DFSNum;
DT.Vertex.push_back(BB); // Vertex[n] = V;
NumToNode.push_back(BB); // NumToNode[n] = V;
if (IsChildOfArtificialExit)
BBInfo.Parent = 1;
@ -78,7 +80,8 @@ unsigned ReverseDFSPass(DominatorTreeBaseByGraphTraits<GraphT> &DT,
}
template <class GraphT>
unsigned DFSPass(DominatorTreeBaseByGraphTraits<GraphT> &DT,
typename GraphT::NodeRef V, unsigned N) {
typename GraphT::NodeRef V,
std::vector<typename GraphT::NodeRef> &NumToNode, unsigned N) {
df_iterator_dom_storage<
typename GraphT::NodeRef,
typename DominatorTreeBaseByGraphTraits<GraphT>::InfoRec>
@ -93,14 +96,15 @@ unsigned DFSPass(DominatorTreeBaseByGraphTraits<GraphT> &DT,
// and is 1 based, so we subtract to account for both of these.
if (I.getPathLength() > 1)
BBInfo.Parent = DT.Info[I.getPath(I.getPathLength() - 2)].DFSNum;
DT.Vertex.push_back(BB); // Vertex[n] = V;
NumToNode.push_back(BB); // NumToNode[n] = V;
}
return N;
}
template <class GraphT>
typename GraphT::NodeRef Eval(DominatorTreeBaseByGraphTraits<GraphT> &DT,
typename GraphT::NodeRef VIn,
typename GraphT::NodeRef Eval(
DominatorTreeBaseByGraphTraits<GraphT> &DT, typename GraphT::NodeRef VIn,
const std::vector<typename GraphT::NodeRef> &NumToNode,
unsigned LastLinked) {
using NodePtr = typename GraphT::NodeRef;
@ -117,7 +121,7 @@ typename GraphT::NodeRef Eval(DominatorTreeBaseByGraphTraits<GraphT> &DT,
while (!Work.empty()) {
NodePtr V = Work.back();
auto &VInfo = DT.Info[V];
NodePtr VAncestor = DT.Vertex[VInfo.Parent];
NodePtr VAncestor = NumToNode[VInfo.Parent];
// Process Ancestor first
if (Visited.insert(VAncestor).second && VInfo.Parent >= LastLinked) {
@ -151,13 +155,15 @@ void Calculate(DominatorTreeBaseByGraphTraits<GraphTraits<NodeT>> &DT,
using NodeType = typename std::remove_pointer<NodePtr>::type;
unsigned N = 0;
std::vector<NodePtr> NumToNode = {nullptr};
bool MultipleRoots = (DT.Roots.size() > 1);
if (MultipleRoots) {
auto &BBInfo = DT.Info[nullptr];
BBInfo.DFSNum = BBInfo.Semi = ++N;
BBInfo.Label = nullptr;
DT.Vertex.push_back(nullptr); // Vertex[n] = V;
NumToNode.push_back(nullptr); // NumToNode[n] = V;
}
// Step #1: Number blocks in depth-first order and initialize variables used
@ -165,9 +171,9 @@ void Calculate(DominatorTreeBaseByGraphTraits<GraphTraits<NodeT>> &DT,
if (DT.isPostDominator()){
for (unsigned i = 0, e = static_cast<unsigned>(DT.Roots.size());
i != e; ++i)
N = ReverseDFSPass<GraphT>(DT, DT.Roots[i], N);
N = ReverseDFSPass<GraphT>(DT, DT.Roots[i], NumToNode, N);
} else {
N = DFSPass<GraphT>(DT, DT.Roots[0], N);
N = DFSPass<GraphT>(DT, DT.Roots[0], NumToNode, N);
}
// It might be that some blocks did not get a DFS number (e.g., blocks of
@ -176,20 +182,20 @@ void Calculate(DominatorTreeBaseByGraphTraits<GraphTraits<NodeT>> &DT,
// Initialize IDoms to spanning tree parents.
for (unsigned i = 1; i <= N; ++i) {
const NodePtr V = DT.Vertex[i];
DT.IDoms[V] = DT.Vertex[DT.Info[V].Parent];
const NodePtr V = NumToNode[i];
DT.IDoms[V] = NumToNode[DT.Info[V].Parent];
}
// Step #2: Calculate the semidominators of all vertices.
for (unsigned i = N; i >= 2; --i) {
NodePtr W = DT.Vertex[i];
NodePtr W = NumToNode[i];
auto &WInfo = DT.Info[W];
// Initialize the semi dominator to point to the parent node.
WInfo.Semi = WInfo.Parent;
for (const auto &N : inverse_children<NodeT>(W))
if (DT.Info.count(N)) { // Only if this predecessor is reachable!
unsigned SemiU = DT.Info[Eval<GraphT>(DT, N, i + 1)].Semi;
unsigned SemiU = DT.Info[Eval<GraphT>(DT, N, NumToNode, i + 1)].Semi;
if (SemiU < WInfo.Semi)
WInfo.Semi = SemiU;
}
@ -201,9 +207,9 @@ void Calculate(DominatorTreeBaseByGraphTraits<GraphTraits<NodeT>> &DT,
// Note that the parents were stored in IDoms and later got invalidated during
// path compression in Eval.
for (unsigned i = 2; i <= N; ++i) {
const NodePtr W = DT.Vertex[i];
const NodePtr W = NumToNode[i];
const auto &WInfo = DT.Info[W];
const unsigned SDomNum = DT.Info[DT.Vertex[WInfo.Semi]].DFSNum;
const unsigned SDomNum = DT.Info[NumToNode[WInfo.Semi]].DFSNum;
NodePtr WIDomCandidate = DT.IDoms[W];
while (DT.Info[WIDomCandidate].DFSNum > SDomNum)
WIDomCandidate = DT.IDoms[WIDomCandidate];
@ -226,7 +232,7 @@ void Calculate(DominatorTreeBaseByGraphTraits<GraphTraits<NodeT>> &DT,
// Loop over all of the reachable blocks in the function...
for (unsigned i = 2; i <= N; ++i) {
NodePtr W = DT.Vertex[i];
NodePtr W = NumToNode[i];
// Don't replace this with 'count', the insertion side effect is important
if (DT.DomTreeNodes[W])
@ -248,8 +254,6 @@ void Calculate(DominatorTreeBaseByGraphTraits<GraphTraits<NodeT>> &DT,
// Free temporary memory used to construct idom's
DT.IDoms.clear();
DT.Info.clear();
DT.Vertex.clear();
DT.Vertex.shrink_to_fit();
DT.updateDFSNumbers();
}