Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
//===- llvm/Analysis/DDG.h --------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the Data-Dependence Graph (DDG).
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_DDG_H
|
|
|
|
#define LLVM_ANALYSIS_DDG_H
|
|
|
|
|
[DDG] Data Dependence Graph - Pi Block
Summary:
This patch adds Pi Blocks to the DDG. A pi-block represents a group of DDG
nodes that are part of a strongly-connected component of the graph.
Replacing all the SCCs with pi-blocks results in an acyclic representation
of the DDG. For example if we have:
{a -> b}, {b -> c, d}, {c -> a}
the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
{p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
In this implementation the edges between nodes that are part of the pi-block
are preserved. The crossing edges (edges where one end of the edge is in the
set of nodes belonging to an SCC and the other end is outside that set) are
replaced with corresponding edges to/from the pi-block node instead.
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/D68827
2019-11-08 21:05:06 +01:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
#include "llvm/ADT/DirectedGraph.h"
|
|
|
|
#include "llvm/Analysis/DependenceAnalysis.h"
|
|
|
|
#include "llvm/Analysis/DependenceGraphBuilder.h"
|
2019-09-18 20:04:45 +02:00
|
|
|
#include "llvm/Analysis/LoopAnalysisManager.h"
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class DDGNode;
|
|
|
|
class DDGEdge;
|
|
|
|
using DDGNodeBase = DGNode<DDGNode, DDGEdge>;
|
|
|
|
using DDGEdgeBase = DGEdge<DDGNode, DDGEdge>;
|
|
|
|
using DDGBase = DirectedGraph<DDGNode, DDGEdge>;
|
2019-09-18 20:04:45 +02:00
|
|
|
class LPMUpdater;
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
|
|
|
|
/// Data Dependence Graph Node
|
|
|
|
/// The graph can represent the following types of nodes:
|
|
|
|
/// 1. Single instruction node containing just one instruction.
|
|
|
|
/// 2. Multiple instruction node where two or more instructions from
|
|
|
|
/// the same basic block are merged into one node.
|
[DDG] Data Dependence Graph - Pi Block
Summary:
This patch adds Pi Blocks to the DDG. A pi-block represents a group of DDG
nodes that are part of a strongly-connected component of the graph.
Replacing all the SCCs with pi-blocks results in an acyclic representation
of the DDG. For example if we have:
{a -> b}, {b -> c, d}, {c -> a}
the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
{p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
In this implementation the edges between nodes that are part of the pi-block
are preserved. The crossing edges (edges where one end of the edge is in the
set of nodes belonging to an SCC and the other end is outside that set) are
replaced with corresponding edges to/from the pi-block node instead.
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/D68827
2019-11-08 21:05:06 +01:00
|
|
|
/// 3. Pi-block node which is a group of other DDG nodes that are part of a
|
|
|
|
/// strongly-connected component of the graph.
|
|
|
|
/// A pi-block node contains more than one single or multiple instruction
|
|
|
|
/// nodes. The root node cannot be part of a pi-block.
|
|
|
|
/// 4. Root node is a special node that connects to all components such that
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
/// there is always a path from it to any node in the graph.
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
class DDGNode : public DDGNodeBase {
|
|
|
|
public:
|
|
|
|
using InstructionListType = SmallVectorImpl<Instruction *>;
|
|
|
|
|
|
|
|
enum class NodeKind {
|
|
|
|
Unknown,
|
|
|
|
SingleInstruction,
|
|
|
|
MultiInstruction,
|
[DDG] Data Dependence Graph - Pi Block
Summary:
This patch adds Pi Blocks to the DDG. A pi-block represents a group of DDG
nodes that are part of a strongly-connected component of the graph.
Replacing all the SCCs with pi-blocks results in an acyclic representation
of the DDG. For example if we have:
{a -> b}, {b -> c, d}, {c -> a}
the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
{p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
In this implementation the edges between nodes that are part of the pi-block
are preserved. The crossing edges (edges where one end of the edge is in the
set of nodes belonging to an SCC and the other end is outside that set) are
replaced with corresponding edges to/from the pi-block node instead.
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/D68827
2019-11-08 21:05:06 +01:00
|
|
|
PiBlock,
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
Root,
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
DDGNode() = delete;
|
|
|
|
DDGNode(const NodeKind K) : DDGNodeBase(), Kind(K) {}
|
|
|
|
DDGNode(const DDGNode &N) : DDGNodeBase(N), Kind(N.Kind) {}
|
|
|
|
DDGNode(DDGNode &&N) : DDGNodeBase(std::move(N)), Kind(N.Kind) {}
|
|
|
|
virtual ~DDGNode() = 0;
|
|
|
|
|
|
|
|
DDGNode &operator=(const DDGNode &N) {
|
|
|
|
DGNode::operator=(N);
|
|
|
|
Kind = N.Kind;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
DDGNode &operator=(DDGNode &&N) {
|
|
|
|
DGNode::operator=(std::move(N));
|
|
|
|
Kind = N.Kind;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Getter for the kind of this node.
|
|
|
|
NodeKind getKind() const { return Kind; }
|
|
|
|
|
|
|
|
/// Collect a list of instructions, in \p IList, for which predicate \p Pred
|
|
|
|
/// evaluates to true when iterating over instructions of this node. Return
|
|
|
|
/// true if at least one instruction was collected, and false otherwise.
|
|
|
|
bool collectInstructions(llvm::function_ref<bool(Instruction *)> const &Pred,
|
|
|
|
InstructionListType &IList) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/// Setter for the kind of this node.
|
|
|
|
void setKind(NodeKind K) { Kind = K; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
NodeKind Kind;
|
|
|
|
};
|
|
|
|
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
/// Subclass of DDGNode representing the root node of the graph.
|
|
|
|
/// There should only be one such node in a given graph.
|
|
|
|
class RootDDGNode : public DDGNode {
|
|
|
|
public:
|
|
|
|
RootDDGNode() : DDGNode(NodeKind::Root) {}
|
|
|
|
RootDDGNode(const RootDDGNode &N) = delete;
|
|
|
|
RootDDGNode(RootDDGNode &&N) : DDGNode(std::move(N)) {}
|
|
|
|
~RootDDGNode() {}
|
|
|
|
|
|
|
|
/// Define classof to be able to use isa<>, cast<>, dyn_cast<>, etc.
|
|
|
|
static bool classof(const DDGNode *N) {
|
|
|
|
return N->getKind() == NodeKind::Root;
|
|
|
|
}
|
|
|
|
static bool classof(const RootDDGNode *N) { return true; }
|
|
|
|
};
|
|
|
|
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
/// Subclass of DDGNode representing single or multi-instruction nodes.
|
|
|
|
class SimpleDDGNode : public DDGNode {
|
[DDG] Data Dependence Graph - Graph Simplification
Summary:
This is the last functional patch affecting the representation of DDG.
Here we try to simplify the DDG to reduce the number of nodes and edges by
iteratively merging pairs of nodes that satisfy the following conditions,
until no such pair can be identified. A pair of nodes consisting of a and b
can be merged if:
1. the only edge from a is a def-use edge to b and
2. the only edge to b is a def-use edge from a and
3. there is no cyclic edge from b to a and
4. all instructions in a and b belong to the same basic block and
5. both a and b are simple (single or multi instruction) nodes.
These criteria allow us to fold many uninteresting def-use edges that
commonly exist in the graph while avoiding the risk of introducing
dependencies that didn't exist before.
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
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72350
2020-02-18 22:38:10 +01:00
|
|
|
friend class DDGBuilder;
|
|
|
|
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
public:
|
|
|
|
SimpleDDGNode() = delete;
|
|
|
|
SimpleDDGNode(Instruction &I);
|
|
|
|
SimpleDDGNode(const SimpleDDGNode &N);
|
|
|
|
SimpleDDGNode(SimpleDDGNode &&N);
|
|
|
|
~SimpleDDGNode();
|
|
|
|
|
|
|
|
SimpleDDGNode &operator=(const SimpleDDGNode &N) {
|
|
|
|
DDGNode::operator=(N);
|
|
|
|
InstList = N.InstList;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleDDGNode &operator=(SimpleDDGNode &&N) {
|
|
|
|
DDGNode::operator=(std::move(N));
|
|
|
|
InstList = std::move(N.InstList);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the list of instructions in this node.
|
|
|
|
const InstructionListType &getInstructions() const {
|
|
|
|
assert(!InstList.empty() && "Instruction List is empty.");
|
|
|
|
return InstList;
|
|
|
|
}
|
|
|
|
InstructionListType &getInstructions() {
|
|
|
|
return const_cast<InstructionListType &>(
|
|
|
|
static_cast<const SimpleDDGNode *>(this)->getInstructions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the first/last instruction in the node.
|
|
|
|
Instruction *getFirstInstruction() const { return getInstructions().front(); }
|
|
|
|
Instruction *getLastInstruction() const { return getInstructions().back(); }
|
|
|
|
|
|
|
|
/// Define classof to be able to use isa<>, cast<>, dyn_cast<>, etc.
|
|
|
|
static bool classof(const DDGNode *N) {
|
|
|
|
return N->getKind() == NodeKind::SingleInstruction ||
|
|
|
|
N->getKind() == NodeKind::MultiInstruction;
|
|
|
|
}
|
|
|
|
static bool classof(const SimpleDDGNode *N) { return true; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Append the list of instructions in \p Input to this node.
|
|
|
|
void appendInstructions(const InstructionListType &Input) {
|
|
|
|
setKind((InstList.size() == 0 && Input.size() == 1)
|
|
|
|
? NodeKind::SingleInstruction
|
|
|
|
: NodeKind::MultiInstruction);
|
|
|
|
InstList.insert(InstList.end(), Input.begin(), Input.end());
|
|
|
|
}
|
|
|
|
void appendInstructions(const SimpleDDGNode &Input) {
|
|
|
|
appendInstructions(Input.getInstructions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// List of instructions associated with a single or multi-instruction node.
|
|
|
|
SmallVector<Instruction *, 2> InstList;
|
|
|
|
};
|
|
|
|
|
[DDG] Data Dependence Graph - Pi Block
Summary:
This patch adds Pi Blocks to the DDG. A pi-block represents a group of DDG
nodes that are part of a strongly-connected component of the graph.
Replacing all the SCCs with pi-blocks results in an acyclic representation
of the DDG. For example if we have:
{a -> b}, {b -> c, d}, {c -> a}
the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
{p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
In this implementation the edges between nodes that are part of the pi-block
are preserved. The crossing edges (edges where one end of the edge is in the
set of nodes belonging to an SCC and the other end is outside that set) are
replaced with corresponding edges to/from the pi-block node instead.
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/D68827
2019-11-08 21:05:06 +01:00
|
|
|
/// Subclass of DDGNode representing a pi-block. A pi-block represents a group
|
|
|
|
/// of DDG nodes that are part of a strongly-connected component of the graph.
|
|
|
|
/// Replacing all the SCCs with pi-blocks results in an acyclic representation
|
|
|
|
/// of the DDG. For example if we have:
|
|
|
|
/// {a -> b}, {b -> c, d}, {c -> a}
|
|
|
|
/// the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
|
|
|
|
/// {p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
|
|
|
|
class PiBlockDDGNode : public DDGNode {
|
|
|
|
public:
|
|
|
|
using PiNodeList = SmallVector<DDGNode *, 4>;
|
|
|
|
|
|
|
|
PiBlockDDGNode() = delete;
|
|
|
|
PiBlockDDGNode(const PiNodeList &List);
|
|
|
|
PiBlockDDGNode(const PiBlockDDGNode &N);
|
|
|
|
PiBlockDDGNode(PiBlockDDGNode &&N);
|
|
|
|
~PiBlockDDGNode();
|
|
|
|
|
|
|
|
PiBlockDDGNode &operator=(const PiBlockDDGNode &N) {
|
|
|
|
DDGNode::operator=(N);
|
|
|
|
NodeList = N.NodeList;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
PiBlockDDGNode &operator=(PiBlockDDGNode &&N) {
|
|
|
|
DDGNode::operator=(std::move(N));
|
|
|
|
NodeList = std::move(N.NodeList);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the list of nodes in this pi-block.
|
|
|
|
const PiNodeList &getNodes() const {
|
|
|
|
assert(!NodeList.empty() && "Node list is empty.");
|
|
|
|
return NodeList;
|
|
|
|
}
|
|
|
|
PiNodeList &getNodes() {
|
|
|
|
return const_cast<PiNodeList &>(
|
|
|
|
static_cast<const PiBlockDDGNode *>(this)->getNodes());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Define classof to be able to use isa<>, cast<>, dyn_cast<>, etc.
|
|
|
|
static bool classof(const DDGNode *N) {
|
|
|
|
return N->getKind() == NodeKind::PiBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// List of nodes in this pi-block.
|
|
|
|
PiNodeList NodeList;
|
|
|
|
};
|
|
|
|
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
/// Data Dependency Graph Edge.
|
|
|
|
/// An edge in the DDG can represent a def-use relationship or
|
|
|
|
/// a memory dependence based on the result of DependenceAnalysis.
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
/// A rooted edge connects the root node to one of the components
|
|
|
|
/// of the graph.
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
class DDGEdge : public DDGEdgeBase {
|
|
|
|
public:
|
|
|
|
/// The kind of edge in the DDG
|
[DDG] Data Dependence Graph - Pi Block
Summary:
This patch adds Pi Blocks to the DDG. A pi-block represents a group of DDG
nodes that are part of a strongly-connected component of the graph.
Replacing all the SCCs with pi-blocks results in an acyclic representation
of the DDG. For example if we have:
{a -> b}, {b -> c, d}, {c -> a}
the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
{p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
In this implementation the edges between nodes that are part of the pi-block
are preserved. The crossing edges (edges where one end of the edge is in the
set of nodes belonging to an SCC and the other end is outside that set) are
replaced with corresponding edges to/from the pi-block node instead.
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/D68827
2019-11-08 21:05:06 +01:00
|
|
|
enum class EdgeKind {
|
|
|
|
Unknown,
|
|
|
|
RegisterDefUse,
|
|
|
|
MemoryDependence,
|
|
|
|
Rooted,
|
|
|
|
Last = Rooted // Must be equal to the largest enum value.
|
|
|
|
};
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
|
|
|
|
explicit DDGEdge(DDGNode &N) = delete;
|
|
|
|
DDGEdge(DDGNode &N, EdgeKind K) : DDGEdgeBase(N), Kind(K) {}
|
|
|
|
DDGEdge(const DDGEdge &E) : DDGEdgeBase(E), Kind(E.getKind()) {}
|
|
|
|
DDGEdge(DDGEdge &&E) : DDGEdgeBase(std::move(E)), Kind(E.Kind) {}
|
|
|
|
DDGEdge &operator=(const DDGEdge &E) {
|
|
|
|
DDGEdgeBase::operator=(E);
|
|
|
|
Kind = E.Kind;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
DDGEdge &operator=(DDGEdge &&E) {
|
|
|
|
DDGEdgeBase::operator=(std::move(E));
|
|
|
|
Kind = E.Kind;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the edge kind
|
|
|
|
EdgeKind getKind() const { return Kind; };
|
|
|
|
|
|
|
|
/// Return true if this is a def-use edge, and false otherwise.
|
|
|
|
bool isDefUse() const { return Kind == EdgeKind::RegisterDefUse; }
|
|
|
|
|
|
|
|
/// Return true if this is a memory dependence edge, and false otherwise.
|
|
|
|
bool isMemoryDependence() const { return Kind == EdgeKind::MemoryDependence; }
|
|
|
|
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
/// Return true if this is an edge stemming from the root node, and false
|
|
|
|
/// otherwise.
|
|
|
|
bool isRooted() const { return Kind == EdgeKind::Rooted; }
|
|
|
|
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
private:
|
|
|
|
EdgeKind Kind;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Encapsulate some common data and functionality needed for different
|
|
|
|
/// variations of data dependence graphs.
|
|
|
|
template <typename NodeType> class DependenceGraphInfo {
|
|
|
|
public:
|
|
|
|
using DependenceList = SmallVector<std::unique_ptr<Dependence>, 1>;
|
|
|
|
|
|
|
|
DependenceGraphInfo() = delete;
|
|
|
|
DependenceGraphInfo(const DependenceGraphInfo &G) = delete;
|
|
|
|
DependenceGraphInfo(const std::string &N, const DependenceInfo &DepInfo)
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
: Name(N), DI(DepInfo), Root(nullptr) {}
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
DependenceGraphInfo(DependenceGraphInfo &&G)
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
: Name(std::move(G.Name)), DI(std::move(G.DI)), Root(G.Root) {}
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
virtual ~DependenceGraphInfo() {}
|
|
|
|
|
|
|
|
/// Return the label that is used to name this graph.
|
|
|
|
const StringRef getName() const { return Name; }
|
|
|
|
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
/// Return the root node of the graph.
|
|
|
|
NodeType &getRoot() const {
|
|
|
|
assert(Root && "Root node is not available yet. Graph construction may "
|
|
|
|
"still be in progress\n");
|
|
|
|
return *Root;
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:33:46 +02:00
|
|
|
/// Collect all the data dependency infos coming from any pair of memory
|
|
|
|
/// accesses from \p Src to \p Dst, and store them into \p Deps. Return true
|
|
|
|
/// if a dependence exists, and false otherwise.
|
|
|
|
bool getDependencies(const NodeType &Src, const NodeType &Dst,
|
|
|
|
DependenceList &Deps) const;
|
|
|
|
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
protected:
|
|
|
|
// Name of the graph.
|
|
|
|
std::string Name;
|
|
|
|
|
|
|
|
// Store a copy of DependenceInfo in the graph, so that individual memory
|
|
|
|
// dependencies don't need to be stored. Instead when the dependence is
|
|
|
|
// queried it is recomputed using @DI.
|
|
|
|
const DependenceInfo DI;
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
|
|
|
|
// A special node in the graph that has an edge to every connected component of
|
|
|
|
// the graph, to ensure all nodes are reachable in a graph walk.
|
|
|
|
NodeType *Root = nullptr;
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
using DDGInfo = DependenceGraphInfo<DDGNode>;
|
|
|
|
|
|
|
|
/// Data Dependency Graph
|
|
|
|
class DataDependenceGraph : public DDGBase, public DDGInfo {
|
[DDG] Data Dependence Graph - Topological Sort (Memory Leak Fix)
Summary:
This fixes the memory leak in bec37c3fc766a7b97f8c52c181c325fd47b75259
and re-delivers the reverted patch.
In this patch the DDG DAG is sorted topologically to put the
nodes in the graph in the order that would satisfy all
dependencies. This helps transformations that would like to
generate code based on the DDG. Since the DDG is a DAG a
reverse-post-order traversal would give us the topological
ordering. This patch also sorts the basic blocks passed to
the builder based on program order to ensure that the
dependencies are computed in the correct direction.
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
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70609
2019-12-02 21:23:26 +01:00
|
|
|
friend AbstractDependenceGraphBuilder<DataDependenceGraph>;
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
friend class DDGBuilder;
|
|
|
|
|
|
|
|
public:
|
|
|
|
using NodeType = DDGNode;
|
|
|
|
using EdgeType = DDGEdge;
|
|
|
|
|
|
|
|
DataDependenceGraph() = delete;
|
|
|
|
DataDependenceGraph(const DataDependenceGraph &G) = delete;
|
|
|
|
DataDependenceGraph(DataDependenceGraph &&G)
|
|
|
|
: DDGBase(std::move(G)), DDGInfo(std::move(G)) {}
|
|
|
|
DataDependenceGraph(Function &F, DependenceInfo &DI);
|
[DDG] Data Dependence Graph - Topological Sort (Memory Leak Fix)
Summary:
This fixes the memory leak in bec37c3fc766a7b97f8c52c181c325fd47b75259
and re-delivers the reverted patch.
In this patch the DDG DAG is sorted topologically to put the
nodes in the graph in the order that would satisfy all
dependencies. This helps transformations that would like to
generate code based on the DDG. Since the DDG is a DAG a
reverse-post-order traversal would give us the topological
ordering. This patch also sorts the basic blocks passed to
the builder based on program order to ensure that the
dependencies are computed in the correct direction.
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
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70609
2019-12-02 21:23:26 +01:00
|
|
|
DataDependenceGraph(Loop &L, LoopInfo &LI, DependenceInfo &DI);
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
~DataDependenceGraph();
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
|
[DDG] Data Dependence Graph - Pi Block
Summary:
This patch adds Pi Blocks to the DDG. A pi-block represents a group of DDG
nodes that are part of a strongly-connected component of the graph.
Replacing all the SCCs with pi-blocks results in an acyclic representation
of the DDG. For example if we have:
{a -> b}, {b -> c, d}, {c -> a}
the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
{p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
In this implementation the edges between nodes that are part of the pi-block
are preserved. The crossing edges (edges where one end of the edge is in the
set of nodes belonging to an SCC and the other end is outside that set) are
replaced with corresponding edges to/from the pi-block node instead.
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/D68827
2019-11-08 21:05:06 +01:00
|
|
|
/// If node \p N belongs to a pi-block return a pointer to the pi-block,
|
|
|
|
/// otherwise return null.
|
|
|
|
const PiBlockDDGNode *getPiBlock(const NodeType &N) const;
|
|
|
|
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
protected:
|
[DDG] Data Dependence Graph - Pi Block
Summary:
This patch adds Pi Blocks to the DDG. A pi-block represents a group of DDG
nodes that are part of a strongly-connected component of the graph.
Replacing all the SCCs with pi-blocks results in an acyclic representation
of the DDG. For example if we have:
{a -> b}, {b -> c, d}, {c -> a}
the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
{p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
In this implementation the edges between nodes that are part of the pi-block
are preserved. The crossing edges (edges where one end of the edge is in the
set of nodes belonging to an SCC and the other end is outside that set) are
replaced with corresponding edges to/from the pi-block node instead.
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/D68827
2019-11-08 21:05:06 +01:00
|
|
|
/// Add node \p N to the graph, if it's not added yet, and keep track of the
|
|
|
|
/// root node as well as pi-blocks and their members. Return true if node is
|
|
|
|
/// successfully added.
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
bool addNode(NodeType &N);
|
|
|
|
|
[DDG] Data Dependence Graph - Pi Block
Summary:
This patch adds Pi Blocks to the DDG. A pi-block represents a group of DDG
nodes that are part of a strongly-connected component of the graph.
Replacing all the SCCs with pi-blocks results in an acyclic representation
of the DDG. For example if we have:
{a -> b}, {b -> c, d}, {c -> a}
the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
{p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
In this implementation the edges between nodes that are part of the pi-block
are preserved. The crossing edges (edges where one end of the edge is in the
set of nodes belonging to an SCC and the other end is outside that set) are
replaced with corresponding edges to/from the pi-block node instead.
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/D68827
2019-11-08 21:05:06 +01:00
|
|
|
private:
|
|
|
|
using PiBlockMapType = DenseMap<const NodeType *, const PiBlockDDGNode *>;
|
|
|
|
|
|
|
|
/// Mapping from graph nodes to their containing pi-blocks. If a node is not
|
|
|
|
/// part of a pi-block, it will not appear in this map.
|
|
|
|
PiBlockMapType PiBlockMap;
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Concrete implementation of a pure data dependence graph builder. This class
|
|
|
|
/// provides custom implementation for the pure-virtual functions used in the
|
|
|
|
/// generic dependence graph build algorithm.
|
|
|
|
///
|
|
|
|
/// For information about time complexity of the build algorithm see the
|
|
|
|
/// comments near the declaration of AbstractDependenceGraphBuilder.
|
|
|
|
class DDGBuilder : public AbstractDependenceGraphBuilder<DataDependenceGraph> {
|
|
|
|
public:
|
|
|
|
DDGBuilder(DataDependenceGraph &G, DependenceInfo &D,
|
|
|
|
const BasicBlockListType &BBs)
|
|
|
|
: AbstractDependenceGraphBuilder(G, D, BBs) {}
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
DDGNode &createRootNode() final override {
|
|
|
|
auto *RN = new RootDDGNode();
|
|
|
|
assert(RN && "Failed to allocate memory for DDG root node.");
|
|
|
|
Graph.addNode(*RN);
|
|
|
|
return *RN;
|
|
|
|
}
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
DDGNode &createFineGrainedNode(Instruction &I) final override {
|
|
|
|
auto *SN = new SimpleDDGNode(I);
|
|
|
|
assert(SN && "Failed to allocate memory for simple DDG node.");
|
|
|
|
Graph.addNode(*SN);
|
|
|
|
return *SN;
|
|
|
|
}
|
[DDG] Data Dependence Graph - Pi Block
Summary:
This patch adds Pi Blocks to the DDG. A pi-block represents a group of DDG
nodes that are part of a strongly-connected component of the graph.
Replacing all the SCCs with pi-blocks results in an acyclic representation
of the DDG. For example if we have:
{a -> b}, {b -> c, d}, {c -> a}
the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
{p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
In this implementation the edges between nodes that are part of the pi-block
are preserved. The crossing edges (edges where one end of the edge is in the
set of nodes belonging to an SCC and the other end is outside that set) are
replaced with corresponding edges to/from the pi-block node instead.
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/D68827
2019-11-08 21:05:06 +01:00
|
|
|
DDGNode &createPiBlock(const NodeListType &L) final override {
|
|
|
|
auto *Pi = new PiBlockDDGNode(L);
|
|
|
|
assert(Pi && "Failed to allocate memory for pi-block node.");
|
|
|
|
Graph.addNode(*Pi);
|
|
|
|
return *Pi;
|
|
|
|
}
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
DDGEdge &createDefUseEdge(DDGNode &Src, DDGNode &Tgt) final override {
|
|
|
|
auto *E = new DDGEdge(Tgt, DDGEdge::EdgeKind::RegisterDefUse);
|
|
|
|
assert(E && "Failed to allocate memory for edge");
|
|
|
|
Graph.connect(Src, Tgt, *E);
|
|
|
|
return *E;
|
|
|
|
}
|
|
|
|
DDGEdge &createMemoryEdge(DDGNode &Src, DDGNode &Tgt) final override {
|
|
|
|
auto *E = new DDGEdge(Tgt, DDGEdge::EdgeKind::MemoryDependence);
|
|
|
|
assert(E && "Failed to allocate memory for edge");
|
|
|
|
Graph.connect(Src, Tgt, *E);
|
|
|
|
return *E;
|
|
|
|
}
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
DDGEdge &createRootedEdge(DDGNode &Src, DDGNode &Tgt) final override {
|
|
|
|
auto *E = new DDGEdge(Tgt, DDGEdge::EdgeKind::Rooted);
|
|
|
|
assert(E && "Failed to allocate memory for edge");
|
|
|
|
assert(isa<RootDDGNode>(Src) && "Expected root node");
|
|
|
|
Graph.connect(Src, Tgt, *E);
|
|
|
|
return *E;
|
|
|
|
}
|
|
|
|
|
[DDG] Data Dependence Graph - Topological Sort (Memory Leak Fix)
Summary:
This fixes the memory leak in bec37c3fc766a7b97f8c52c181c325fd47b75259
and re-delivers the reverted patch.
In this patch the DDG DAG is sorted topologically to put the
nodes in the graph in the order that would satisfy all
dependencies. This helps transformations that would like to
generate code based on the DDG. Since the DDG is a DAG a
reverse-post-order traversal would give us the topological
ordering. This patch also sorts the basic blocks passed to
the builder based on program order to ensure that the
dependencies are computed in the correct direction.
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
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70609
2019-12-02 21:23:26 +01:00
|
|
|
const NodeListType &getNodesInPiBlock(const DDGNode &N) final override {
|
|
|
|
auto *PiNode = dyn_cast<const PiBlockDDGNode>(&N);
|
|
|
|
assert(PiNode && "Expected a pi-block node.");
|
|
|
|
return PiNode->getNodes();
|
|
|
|
}
|
|
|
|
|
[DDG] Data Dependence Graph - Graph Simplification
Summary:
This is the last functional patch affecting the representation of DDG.
Here we try to simplify the DDG to reduce the number of nodes and edges by
iteratively merging pairs of nodes that satisfy the following conditions,
until no such pair can be identified. A pair of nodes consisting of a and b
can be merged if:
1. the only edge from a is a def-use edge to b and
2. the only edge to b is a def-use edge from a and
3. there is no cyclic edge from b to a and
4. all instructions in a and b belong to the same basic block and
5. both a and b are simple (single or multi instruction) nodes.
These criteria allow us to fold many uninteresting def-use edges that
commonly exist in the graph while avoiding the risk of introducing
dependencies that didn't exist before.
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
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72350
2020-02-18 22:38:10 +01:00
|
|
|
/// Return true if the two nodes \pSrc and \pTgt are both simple nodes and
|
|
|
|
/// the consecutive instructions after merging belong to the same basic block.
|
|
|
|
bool areNodesMergeable(const DDGNode &Src,
|
|
|
|
const DDGNode &Tgt) const final override;
|
|
|
|
void mergeNodes(DDGNode &Src, DDGNode &Tgt) final override;
|
|
|
|
bool shouldSimplify() const final override;
|
[DDG] Data Dependence Graph - Pi Block
Summary:
This patch adds Pi Blocks to the DDG. A pi-block represents a group of DDG
nodes that are part of a strongly-connected component of the graph.
Replacing all the SCCs with pi-blocks results in an acyclic representation
of the DDG. For example if we have:
{a -> b}, {b -> c, d}, {c -> a}
the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
{p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
In this implementation the edges between nodes that are part of the pi-block
are preserved. The crossing edges (edges where one end of the edge is in the
set of nodes belonging to an SCC and the other end is outside that set) are
replaced with corresponding edges to/from the pi-block node instead.
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/D68827
2019-11-08 21:05:06 +01:00
|
|
|
bool shouldCreatePiBlocks() const final override;
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const DDGNode &N);
|
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const DDGNode::NodeKind K);
|
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const DDGEdge &E);
|
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const DDGEdge::EdgeKind K);
|
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const DataDependenceGraph &G);
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DDG Analysis Passes
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Analysis pass that builds the DDG for a loop.
|
|
|
|
class DDGAnalysis : public AnalysisInfoMixin<DDGAnalysis> {
|
|
|
|
public:
|
|
|
|
using Result = std::unique_ptr<DataDependenceGraph>;
|
|
|
|
Result run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR);
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend AnalysisInfoMixin<DDGAnalysis>;
|
|
|
|
static AnalysisKey Key;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Textual printer pass for the DDG of a loop.
|
|
|
|
class DDGAnalysisPrinterPass : public PassInfoMixin<DDGAnalysisPrinterPass> {
|
|
|
|
public:
|
|
|
|
explicit DDGAnalysisPrinterPass(raw_ostream &OS) : OS(OS) {}
|
|
|
|
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
|
|
|
|
LoopStandardAnalysisResults &AR, LPMUpdater &U);
|
|
|
|
|
|
|
|
private:
|
|
|
|
raw_ostream &OS;
|
|
|
|
};
|
|
|
|
|
2020-05-27 18:33:46 +02:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// DependenceGraphInfo Implementation
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
template <typename NodeType>
|
|
|
|
bool DependenceGraphInfo<NodeType>::getDependencies(
|
|
|
|
const NodeType &Src, const NodeType &Dst, DependenceList &Deps) const {
|
|
|
|
assert(Deps.empty() && "Expected empty output list at the start.");
|
|
|
|
|
|
|
|
// List of memory access instructions from src and dst nodes.
|
|
|
|
SmallVector<Instruction *, 8> SrcIList, DstIList;
|
|
|
|
auto isMemoryAccess = [](const Instruction *I) {
|
|
|
|
return I->mayReadOrWriteMemory();
|
|
|
|
};
|
|
|
|
Src.collectInstructions(isMemoryAccess, SrcIList);
|
|
|
|
Dst.collectInstructions(isMemoryAccess, DstIList);
|
|
|
|
|
|
|
|
for (auto *SrcI : SrcIList)
|
|
|
|
for (auto *DstI : DstIList)
|
|
|
|
if (auto Dep =
|
|
|
|
const_cast<DependenceInfo *>(&DI)->depends(SrcI, DstI, true))
|
|
|
|
Deps.push_back(std::move(Dep));
|
|
|
|
|
|
|
|
return !Deps.empty();
|
|
|
|
}
|
|
|
|
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// GraphTraits specializations for the DDG
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// non-const versions of the grapth trait specializations for DDG
|
|
|
|
template <> struct GraphTraits<DDGNode *> {
|
|
|
|
using NodeRef = DDGNode *;
|
|
|
|
|
|
|
|
static DDGNode *DDGGetTargetNode(DGEdge<DDGNode, DDGEdge> *P) {
|
|
|
|
return &P->getTargetNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provide a mapped iterator so that the GraphTrait-based implementations can
|
|
|
|
// find the target nodes without having to explicitly go through the edges.
|
|
|
|
using ChildIteratorType =
|
|
|
|
mapped_iterator<DDGNode::iterator, decltype(&DDGGetTargetNode)>;
|
|
|
|
using ChildEdgeIteratorType = DDGNode::iterator;
|
|
|
|
|
|
|
|
static NodeRef getEntryNode(NodeRef N) { return N; }
|
|
|
|
static ChildIteratorType child_begin(NodeRef N) {
|
|
|
|
return ChildIteratorType(N->begin(), &DDGGetTargetNode);
|
|
|
|
}
|
|
|
|
static ChildIteratorType child_end(NodeRef N) {
|
|
|
|
return ChildIteratorType(N->end(), &DDGGetTargetNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ChildEdgeIteratorType child_edge_begin(NodeRef N) {
|
|
|
|
return N->begin();
|
|
|
|
}
|
|
|
|
static ChildEdgeIteratorType child_edge_end(NodeRef N) { return N->end(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct GraphTraits<DataDependenceGraph *> : public GraphTraits<DDGNode *> {
|
|
|
|
using nodes_iterator = DataDependenceGraph::iterator;
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
static NodeRef getEntryNode(DataDependenceGraph *DG) {
|
|
|
|
return &DG->getRoot();
|
|
|
|
}
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
static nodes_iterator nodes_begin(DataDependenceGraph *DG) {
|
|
|
|
return DG->begin();
|
|
|
|
}
|
|
|
|
static nodes_iterator nodes_end(DataDependenceGraph *DG) { return DG->end(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// const versions of the grapth trait specializations for DDG
|
|
|
|
template <> struct GraphTraits<const DDGNode *> {
|
|
|
|
using NodeRef = const DDGNode *;
|
|
|
|
|
|
|
|
static const DDGNode *DDGGetTargetNode(const DGEdge<DDGNode, DDGEdge> *P) {
|
|
|
|
return &P->getTargetNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provide a mapped iterator so that the GraphTrait-based implementations can
|
|
|
|
// find the target nodes without having to explicitly go through the edges.
|
|
|
|
using ChildIteratorType =
|
|
|
|
mapped_iterator<DDGNode::const_iterator, decltype(&DDGGetTargetNode)>;
|
|
|
|
using ChildEdgeIteratorType = DDGNode::const_iterator;
|
|
|
|
|
|
|
|
static NodeRef getEntryNode(NodeRef N) { return N; }
|
|
|
|
static ChildIteratorType child_begin(NodeRef N) {
|
|
|
|
return ChildIteratorType(N->begin(), &DDGGetTargetNode);
|
|
|
|
}
|
|
|
|
static ChildIteratorType child_end(NodeRef N) {
|
|
|
|
return ChildIteratorType(N->end(), &DDGGetTargetNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ChildEdgeIteratorType child_edge_begin(NodeRef N) {
|
|
|
|
return N->begin();
|
|
|
|
}
|
|
|
|
static ChildEdgeIteratorType child_edge_end(NodeRef N) { return N->end(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct GraphTraits<const DataDependenceGraph *>
|
|
|
|
: public GraphTraits<const DDGNode *> {
|
|
|
|
using nodes_iterator = DataDependenceGraph::const_iterator;
|
|
|
|
static NodeRef getEntryNode(const DataDependenceGraph *DG) {
|
[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
2019-10-01 21:32:42 +02:00
|
|
|
return &DG->getRoot();
|
Data Dependence Graph Basics
Summary:
This is the first patch in a series of patches that will implement data dependence graph in LLVM. Many of the ideas used in this implementation are based on the following paper:
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe (1981). DEPENDENCE GRAPHS AND COMPILER OPTIMIZATIONS.
This patch contains support for a basic DDGs containing only atomic nodes (one node for each instruction). The edges are two fold: def-use edges and memory-dependence edges.
The implementation takes a list of basic-blocks and only considers dependencies among instructions in those basic blocks. Any dependencies coming into or going out of instructions that do not belong to those basic blocks are ignored.
The algorithm for building the graph involves the following steps in order:
1. For each instruction in the range of basic blocks to consider, create an atomic node in the resulting graph.
2. For each node in the graph establish def-use edges to/from other nodes in the graph.
3. For each pair of nodes containing memory instruction(s) create memory edges between them. This part of the algorithm goes through the instructions in lexicographical order and creates edges in reverse order if the sink of the dependence occurs before the source of it.
Authored By: bmahjour
Reviewer: Meinersbur, fhahn, myhsu, xtian, dmgreen, kbarton, jdoerfert
Reviewed By: Meinersbur, fhahn, myhsu
Subscribers: ychen, arphaman, simoll, a.elovikov, mgorny, hiraditya, jfb, wuzish, llvm-commits, jsji, Whitney, etiotto
Tag: #llvm
Differential Revision: https://reviews.llvm.org/D65350
llvm-svn: 372238
2019-09-18 19:43:45 +02:00
|
|
|
}
|
|
|
|
static nodes_iterator nodes_begin(const DataDependenceGraph *DG) {
|
|
|
|
return DG->begin();
|
|
|
|
}
|
|
|
|
static nodes_iterator nodes_end(const DataDependenceGraph *DG) {
|
|
|
|
return DG->end();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_ANALYSIS_DDG_H
|