diff options
author | Bardia Mahjour <bmahjour@ca.ibm.com> | 2019-10-01 19:32:42 +0000 |
---|---|---|
committer | Bardia Mahjour <bmahjour@ca.ibm.com> | 2019-10-01 19:32:42 +0000 |
commit | 91b62d5c89ef7ca5b1101e8006513a0af88ccb96 (patch) | |
tree | 3924143c702513e96cec53eca9edf91a5b1b4891 /llvm/lib/Analysis/DependenceGraphBuilder.cpp | |
parent | bcab95182b3745960851c723c018268c2534d6a3 (diff) | |
download | bcm5719-llvm-91b62d5c89ef7ca5b1101e8006513a0af88ccb96.tar.gz bcm5719-llvm-91b62d5c89ef7ca5b1101e8006513a0af88ccb96.zip |
[DDG] Data Dependence Graph - Root Node
Summary:
This patch adds Root Node to the DDG. The purpose of the root node is to create a single entry node that allows graph walk iterators to iterate through all nodes of the graph, making sure that no node is left unvisited during a graph walk (eg. SCC or DFS). Once the DDG is fully constructed it will have exactly one root node. Every node in the graph is reachable from the root. The algorithm for connecting the root node is based on depth-first-search that keeps track of visited nodes to try to avoid creating unnecessary edges.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto, ppc-slack
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D67970
llvm-svn: 373386
Diffstat (limited to 'llvm/lib/Analysis/DependenceGraphBuilder.cpp')
-rw-r--r-- | llvm/lib/Analysis/DependenceGraphBuilder.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/DependenceGraphBuilder.cpp b/llvm/lib/Analysis/DependenceGraphBuilder.cpp index ed21cc7134f..ed1d8351b2f 100644 --- a/llvm/lib/Analysis/DependenceGraphBuilder.cpp +++ b/llvm/lib/Analysis/DependenceGraphBuilder.cpp @@ -46,6 +46,34 @@ void AbstractDependenceGraphBuilder<G>::createFineGrainedNodes() { } } +template <class G> +void AbstractDependenceGraphBuilder<G>::createAndConnectRootNode() { + // Create a root node that connects to every connected component of the graph. + // This is done to allow graph iterators to visit all the disjoint components + // of the graph, in a single walk. + // + // This algorithm works by going through each node of the graph and for each + // node N, do a DFS starting from N. A rooted edge is established between the + // root node and N (if N is not yet visited). All the nodes reachable from N + // are marked as visited and are skipped in the DFS of subsequent nodes. + // + // Note: This algorithm tries to limit the number of edges out of the root + // node to some extent, but there may be redundant edges created depending on + // the iteration order. For example for a graph {A -> B}, an edge from the + // root node is added to both nodes if B is visited before A. While it does + // not result in minimal number of edges, this approach saves compile-time + // while keeping the number of edges in check. + auto &RootNode = createRootNode(); + df_iterator_default_set<const NodeType *, 4> Visited; + for (auto *N : Graph) { + if (*N == RootNode) + continue; + for (auto I : depth_first_ext(N, Visited)) + if (I == N) + createRootedEdge(RootNode, *N); + } +} + template <class G> void AbstractDependenceGraphBuilder<G>::createDefUseEdges() { for (NodeType *N : Graph) { InstructionListType SrcIList; |