14 #ifndef LLVM_ADT_DIRECTEDGRAPH_H 15 #define LLVM_ADT_DIRECTEDGRAPH_H 27 template <
class NodeType,
class EdgeType>
class DGEdge {
56 bool isEqualTo(
const EdgeType &
E)
const {
return this == &
E; }
59 EdgeType &
getDerived() {
return *
static_cast<EdgeType *
>(
this); }
61 return *
static_cast<const EdgeType *
>(
this);
70 template <
class NodeType,
class EdgeType>
class DGNode {
77 explicit DGNode(EdgeType &
E) : Edges() { Edges.insert(&E); }
88 Edges = std::move(
N.Edges);
101 const EdgeType &
front()
const {
return *Edges.front(); }
102 EdgeType &
front() {
return *Edges.front(); }
103 const EdgeType &
back()
const {
return *Edges.back(); }
104 EdgeType &
back() {
return *Edges.back(); }
111 assert(EL.
empty() &&
"Expected the list of edges to be empty.");
112 for (
auto *
E : Edges)
113 if (
E->getTargetNode() ==
N)
120 bool addEdge(EdgeType &
E) {
return Edges.insert(&E); }
127 return (findEdgeTo(N) != Edges.end());
147 return *
static_cast<const NodeType *
>(
this);
154 Edges, [&N](
const EdgeType *
E) {
return E->getTargetNode() ==
N; });
184 Nodes = std::move(
G.Nodes);
197 size_t size()
const {
return Nodes.size(); }
211 if (findNode(N) != Nodes.end())
220 assert(EL.
empty() &&
"Expected the list of edges to be empty.");
222 for (
auto *
Node : Nodes) {
225 Node->findEdgesTo(N, TempList);
226 EL.
insert(EL.
end(), TempList.begin(), TempList.end());
238 if (IT == Nodes.end())
242 for (
auto *
Node : Nodes) {
245 Node->findEdgesTo(N, EL);
247 Node->removeEdge(*
E);
259 assert(findNode(Src) != Nodes.end() &&
"Src node should be present.");
260 assert(findNode(Dst) != Nodes.end() &&
"Dst node should be present.");
261 assert((E.getTargetNode() == Dst) &&
262 "Target of the given edge does not match Dst.");
263 return Src.addEdge(E);
273 #endif // LLVM_ADT_DIRECTEDGRAPH_H DGraphType & operator=(const DGraphType &G)
const NodeType & getDerived() const
DGEdge< NodeType, EdgeType > & operator=(const DGEdge< NodeType, EdgeType > &E)
bool operator==(const NodeType &N) const
Static polymorphism: delegate implementation (via isEqualTo) to the derived class.
void clear()
Clear the outgoing edges.
typename SuperClass::const_iterator const_iterator
This class represents lattice values for constants.
const EdgeType & front() const
void push_back(const T &Elt)
const NodeType & getTargetNode() const
Retrieve the target node this edge connects to.
DGNode< NodeType, EdgeType > & operator=(const DGNode< NodeType, EdgeType > &&N)
DGNode(EdgeType &E)
Create a node with a single outgoing edge E.
bool hasEdgeTo(const NodeType &N) const
Test whether there is an edge that goes from this node to N.
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
bool addEdge(EdgeType &E)
Add the given edge E to this node, if it doesn't exist already.
const_iterator begin() const
const_iterator findNode(const NodeType &N) const
Find the given node N in the table.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
DGNode< NodeType, EdgeType > & operator=(const DGNode< NodeType, EdgeType > &N)
bool isEqualTo(const EdgeType &E) const
DirectedGraph(NodeType &N)
typename EdgeListTy::const_iterator const_iterator
bool operator!=(const EdgeType &E) const
bool connect(NodeType &Src, NodeType &Dst, EdgeType &E)
Assuming nodes Src and Dst are already in the graph, connect node Src to node Dst using the provided ...
bool findIncomingEdgesToNode(const NodeType &N, SmallVectorImpl< EdgeType *> &EL) const
Collect in EL all edges that are coming into node N.
const EdgeListTy & getEdges() const
Retrieve the outgoing edges for the node.
bool removeNode(NodeType &N)
Remove the given node N from the graph.
bool operator!=(const NodeType &N) const
DGNode(const DGNode< NodeType, EdgeType > &N)
bool operator==(const EdgeType &E) const
Static polymorphism: delegate implementation (via isEqualTo) to the derived class.
const_iterator end() const
Represent an edge in the directed graph.
const EdgeType & back() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void setTargetNode(const NodeType &N)
Set the target node this edge connects to.
const NodeType & front() const
DGEdge(NodeType &N)
Create an edge pointing to the given node N.
DGNode(DGNode< NodeType, EdgeType > &&N)
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
DGEdge(const DGEdge< NodeType, EdgeType > &E)
typename vector_type::const_iterator const_iterator
iterator findNode(const NodeType &N)
typename vector_type::const_iterator iterator
DGraphType & operator=(const DGraphType &&G)
Represent a node in the directed graph.
NodeType & getTargetNode()
const_iterator end() const
typename SuperClass::iterator iterator
iterator insert(iterator I, T &&Elt)
void removeEdge(EdgeType &E)
Remove the given edge E from this node, if it exists.
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate IT block based on arch"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT, "arm-no-restrict-it", "Allow IT blocks based on ARMv7")))
LLVM_NODISCARD bool empty() const
typename EdgeListTy::iterator iterator
typename NodeListTy::const_iterator const_iterator
const_iterator findEdgeTo(const NodeType &N) const
Find an edge to N.
const NodeType & back() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool findEdgesTo(const NodeType &N, SmallVectorImpl< EdgeType *> &EL) const
Collect in EL, all the edges from this node to N.
DirectedGraph(DGraphType &&RHS)
bool addNode(NodeType &N)
Add the given node N to the graph if it is not already present.
bool isEqualTo(const NodeType &N) const
A vector that has set insertion semantics.
typename NodeListTy::iterator iterator
const EdgeType & getDerived() const
DirectedGraph(const DGraphType &G)
const_iterator begin() const