xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Analysis/DDG.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- llvm/Analysis/DDG.h --------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the Data-Dependence Graph (DDG).
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_ANALYSIS_DDG_H
14 #define LLVM_ANALYSIS_DDG_H
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/DirectedGraph.h"
18 #include "llvm/Analysis/DependenceAnalysis.h"
19 #include "llvm/Analysis/DependenceGraphBuilder.h"
20 #include "llvm/Analysis/LoopAnalysisManager.h"
21 #include "llvm/Support/Compiler.h"
22 
23 namespace llvm {
24 class Function;
25 class Loop;
26 class LoopInfo;
27 class DDGNode;
28 class DDGEdge;
29 using DDGNodeBase = DGNode<DDGNode, DDGEdge>;
30 using DDGEdgeBase = DGEdge<DDGNode, DDGEdge>;
31 using DDGBase = DirectedGraph<DDGNode, DDGEdge>;
32 class LPMUpdater;
33 
34 /// Data Dependence Graph Node
35 /// The graph can represent the following types of nodes:
36 /// 1. Single instruction node containing just one instruction.
37 /// 2. Multiple instruction node where two or more instructions from
38 ///    the same basic block are merged into one node.
39 /// 3. Pi-block node which is a group of other DDG nodes that are part of a
40 ///    strongly-connected component of the graph.
41 ///    A pi-block node contains more than one single or multiple instruction
42 ///    nodes. The root node cannot be part of a pi-block.
43 /// 4. Root node is a special node that connects to all components such that
44 ///    there is always a path from it to any node in the graph.
45 class LLVM_ABI DDGNode : public DDGNodeBase {
46 public:
47   using InstructionListType = SmallVectorImpl<Instruction *>;
48 
49   enum class NodeKind {
50     Unknown,
51     SingleInstruction,
52     MultiInstruction,
53     PiBlock,
54     Root,
55   };
56 
57   DDGNode() = delete;
DDGNode(const NodeKind K)58   DDGNode(const NodeKind K) : Kind(K) {}
59   DDGNode(const DDGNode &N) = default;
DDGNode(DDGNode && N)60   DDGNode(DDGNode &&N) : DDGNodeBase(std::move(N)), Kind(N.Kind) {}
61   virtual ~DDGNode() = 0;
62 
63   DDGNode &operator=(const DDGNode &N) {
64     DGNode::operator=(N);
65     Kind = N.Kind;
66     return *this;
67   }
68 
69   DDGNode &operator=(DDGNode &&N) {
70     DGNode::operator=(std::move(N));
71     Kind = N.Kind;
72     return *this;
73   }
74 
75   /// Getter for the kind of this node.
getKind()76   NodeKind getKind() const { return Kind; }
77 
78   /// Collect a list of instructions, in \p IList, for which predicate \p Pred
79   /// evaluates to true when iterating over instructions of this node. Return
80   /// true if at least one instruction was collected, and false otherwise.
81   bool collectInstructions(llvm::function_ref<bool(Instruction *)> const &Pred,
82                            InstructionListType &IList) const;
83 
84 protected:
85   /// Setter for the kind of this node.
setKind(NodeKind K)86   void setKind(NodeKind K) { Kind = K; }
87 
88 private:
89   NodeKind Kind;
90 };
91 
92 /// Subclass of DDGNode representing the root node of the graph.
93 /// There should only be one such node in a given graph.
94 class RootDDGNode : public DDGNode {
95 public:
RootDDGNode()96   RootDDGNode() : DDGNode(NodeKind::Root) {}
97   RootDDGNode(const RootDDGNode &N) = delete;
RootDDGNode(RootDDGNode && N)98   RootDDGNode(RootDDGNode &&N) : DDGNode(std::move(N)) {}
99   ~RootDDGNode() = default;
100 
101   /// Define classof to be able to use isa<>, cast<>, dyn_cast<>, etc.
classof(const DDGNode * N)102   static bool classof(const DDGNode *N) {
103     return N->getKind() == NodeKind::Root;
104   }
classof(const RootDDGNode * N)105   static bool classof(const RootDDGNode *N) { return true; }
106 };
107 
108 /// Subclass of DDGNode representing single or multi-instruction nodes.
109 class LLVM_ABI SimpleDDGNode : public DDGNode {
110   friend class DDGBuilder;
111 
112 public:
113   SimpleDDGNode() = delete;
114   SimpleDDGNode(Instruction &I);
115   SimpleDDGNode(const SimpleDDGNode &N);
116   SimpleDDGNode(SimpleDDGNode &&N);
117   ~SimpleDDGNode();
118 
119   SimpleDDGNode &operator=(const SimpleDDGNode &N) = default;
120 
121   SimpleDDGNode &operator=(SimpleDDGNode &&N) {
122     DDGNode::operator=(std::move(N));
123     InstList = std::move(N.InstList);
124     return *this;
125   }
126 
127   /// Get the list of instructions in this node.
getInstructions()128   const InstructionListType &getInstructions() const {
129     assert(!InstList.empty() && "Instruction List is empty.");
130     return InstList;
131   }
getInstructions()132   InstructionListType &getInstructions() {
133     return const_cast<InstructionListType &>(
134         static_cast<const SimpleDDGNode *>(this)->getInstructions());
135   }
136 
137   /// Get the first/last instruction in the node.
getFirstInstruction()138   Instruction *getFirstInstruction() const { return getInstructions().front(); }
getLastInstruction()139   Instruction *getLastInstruction() const { return getInstructions().back(); }
140 
141   /// Define classof to be able to use isa<>, cast<>, dyn_cast<>, etc.
classof(const DDGNode * N)142   static bool classof(const DDGNode *N) {
143     return N->getKind() == NodeKind::SingleInstruction ||
144            N->getKind() == NodeKind::MultiInstruction;
145   }
classof(const SimpleDDGNode * N)146   static bool classof(const SimpleDDGNode *N) { return true; }
147 
148 private:
149   /// Append the list of instructions in \p Input to this node.
appendInstructions(const InstructionListType & Input)150   void appendInstructions(const InstructionListType &Input) {
151     setKind((InstList.size() == 0 && Input.size() == 1)
152                 ? NodeKind::SingleInstruction
153                 : NodeKind::MultiInstruction);
154     llvm::append_range(InstList, Input);
155   }
appendInstructions(const SimpleDDGNode & Input)156   void appendInstructions(const SimpleDDGNode &Input) {
157     appendInstructions(Input.getInstructions());
158   }
159 
160   /// List of instructions associated with a single or multi-instruction node.
161   SmallVector<Instruction *, 2> InstList;
162 };
163 
164 /// Subclass of DDGNode representing a pi-block. A pi-block represents a group
165 /// of DDG nodes that are part of a strongly-connected component of the graph.
166 /// Replacing all the SCCs with pi-blocks results in an acyclic representation
167 /// of the DDG. For example if we have:
168 /// {a -> b}, {b -> c, d}, {c -> a}
169 /// the cycle a -> b -> c -> a is abstracted into a pi-block "p" as follows:
170 /// {p -> d} with "p" containing: {a -> b}, {b -> c}, {c -> a}
171 class LLVM_ABI PiBlockDDGNode : public DDGNode {
172 public:
173   using PiNodeList = SmallVector<DDGNode *, 4>;
174 
175   PiBlockDDGNode() = delete;
176   PiBlockDDGNode(const PiNodeList &List);
177   PiBlockDDGNode(const PiBlockDDGNode &N);
178   PiBlockDDGNode(PiBlockDDGNode &&N);
179   ~PiBlockDDGNode();
180 
181   PiBlockDDGNode &operator=(const PiBlockDDGNode &N) = default;
182 
183   PiBlockDDGNode &operator=(PiBlockDDGNode &&N) {
184     DDGNode::operator=(std::move(N));
185     NodeList = std::move(N.NodeList);
186     return *this;
187   }
188 
189   /// Get the list of nodes in this pi-block.
getNodes()190   const PiNodeList &getNodes() const {
191     assert(!NodeList.empty() && "Node list is empty.");
192     return NodeList;
193   }
getNodes()194   PiNodeList &getNodes() {
195     return const_cast<PiNodeList &>(
196         static_cast<const PiBlockDDGNode *>(this)->getNodes());
197   }
198 
199   /// Define classof to be able to use isa<>, cast<>, dyn_cast<>, etc.
classof(const DDGNode * N)200   static bool classof(const DDGNode *N) {
201     return N->getKind() == NodeKind::PiBlock;
202   }
203 
204 private:
205   /// List of nodes in this pi-block.
206   PiNodeList NodeList;
207 };
208 
209 /// Data Dependency Graph Edge.
210 /// An edge in the DDG can represent a def-use relationship or
211 /// a memory dependence based on the result of DependenceAnalysis.
212 /// A rooted edge connects the root node to one of the components
213 /// of the graph.
214 class DDGEdge : public DDGEdgeBase {
215 public:
216   /// The kind of edge in the DDG
217   enum class EdgeKind {
218     Unknown,
219     RegisterDefUse,
220     MemoryDependence,
221     Rooted,
222     Last = Rooted // Must be equal to the largest enum value.
223   };
224 
225   explicit DDGEdge(DDGNode &N) = delete;
DDGEdge(DDGNode & N,EdgeKind K)226   DDGEdge(DDGNode &N, EdgeKind K) : DDGEdgeBase(N), Kind(K) {}
DDGEdge(const DDGEdge & E)227   DDGEdge(const DDGEdge &E) : DDGEdgeBase(E), Kind(E.getKind()) {}
DDGEdge(DDGEdge && E)228   DDGEdge(DDGEdge &&E) : DDGEdgeBase(std::move(E)), Kind(E.Kind) {}
229   DDGEdge &operator=(const DDGEdge &E) = default;
230 
231   DDGEdge &operator=(DDGEdge &&E) {
232     DDGEdgeBase::operator=(std::move(E));
233     Kind = E.Kind;
234     return *this;
235   }
236 
237   /// Get the edge kind
getKind()238   EdgeKind getKind() const { return Kind; };
239 
240   /// Return true if this is a def-use edge, and false otherwise.
isDefUse()241   bool isDefUse() const { return Kind == EdgeKind::RegisterDefUse; }
242 
243   /// Return true if this is a memory dependence edge, and false otherwise.
isMemoryDependence()244   bool isMemoryDependence() const { return Kind == EdgeKind::MemoryDependence; }
245 
246   /// Return true if this is an edge stemming from the root node, and false
247   /// otherwise.
isRooted()248   bool isRooted() const { return Kind == EdgeKind::Rooted; }
249 
250 private:
251   EdgeKind Kind;
252 };
253 
254 /// Encapsulate some common data and functionality needed for different
255 /// variations of data dependence graphs.
256 template <typename NodeType> class DependenceGraphInfo {
257 public:
258   using DependenceList = SmallVector<std::unique_ptr<Dependence>, 1>;
259 
260   DependenceGraphInfo() = delete;
261   DependenceGraphInfo(const DependenceGraphInfo &G) = delete;
DependenceGraphInfo(const std::string & N,const DependenceInfo & DepInfo)262   DependenceGraphInfo(const std::string &N, const DependenceInfo &DepInfo)
263       : Name(N), DI(DepInfo), Root(nullptr) {}
DependenceGraphInfo(DependenceGraphInfo && G)264   DependenceGraphInfo(DependenceGraphInfo &&G)
265       : Name(std::move(G.Name)), DI(std::move(G.DI)), Root(G.Root) {}
266   virtual ~DependenceGraphInfo() = default;
267 
268   /// Return the label that is used to name this graph.
getName()269   StringRef getName() const { return Name; }
270 
271   /// Return the root node of the graph.
getRoot()272   NodeType &getRoot() const {
273     assert(Root && "Root node is not available yet. Graph construction may "
274                    "still be in progress\n");
275     return *Root;
276   }
277 
278   /// Collect all the data dependency infos coming from any pair of memory
279   /// accesses from \p Src to \p Dst, and store them into \p Deps. Return true
280   /// if a dependence exists, and false otherwise.
281   bool getDependencies(const NodeType &Src, const NodeType &Dst,
282                        DependenceList &Deps) const;
283 
284   /// Return a string representing the type of dependence that the dependence
285   /// analysis identified between the two given nodes. This function assumes
286   /// that there is a memory dependence between the given two nodes.
287   std::string getDependenceString(const NodeType &Src,
288                                   const NodeType &Dst) const;
289 
290 protected:
291   // Name of the graph.
292   std::string Name;
293 
294   // Store a copy of DependenceInfo in the graph, so that individual memory
295   // dependencies don't need to be stored. Instead when the dependence is
296   // queried it is recomputed using @DI.
297   const DependenceInfo DI;
298 
299   // A special node in the graph that has an edge to every connected component of
300   // the graph, to ensure all nodes are reachable in a graph walk.
301   NodeType *Root = nullptr;
302 };
303 
304 using DDGInfo = DependenceGraphInfo<DDGNode>;
305 
306 /// Data Dependency Graph
307 class LLVM_ABI DataDependenceGraph : public DDGBase, public DDGInfo {
308   friend AbstractDependenceGraphBuilder<DataDependenceGraph>;
309   friend class DDGBuilder;
310 
311 public:
312   using NodeType = DDGNode;
313   using EdgeType = DDGEdge;
314 
315   DataDependenceGraph() = delete;
316   DataDependenceGraph(const DataDependenceGraph &G) = delete;
DataDependenceGraph(DataDependenceGraph && G)317   DataDependenceGraph(DataDependenceGraph &&G)
318       : DDGBase(std::move(G)), DDGInfo(std::move(G)) {}
319   DataDependenceGraph(Function &F, DependenceInfo &DI);
320   DataDependenceGraph(Loop &L, LoopInfo &LI, DependenceInfo &DI);
321   ~DataDependenceGraph();
322 
323   /// If node \p N belongs to a pi-block return a pointer to the pi-block,
324   /// otherwise return null.
325   const PiBlockDDGNode *getPiBlock(const NodeType &N) const;
326 
327 protected:
328   /// Add node \p N to the graph, if it's not added yet, and keep track of the
329   /// root node as well as pi-blocks and their members. Return true if node is
330   /// successfully added.
331   bool addNode(NodeType &N);
332 
333 private:
334   using PiBlockMapType = DenseMap<const NodeType *, const PiBlockDDGNode *>;
335 
336   /// Mapping from graph nodes to their containing pi-blocks. If a node is not
337   /// part of a pi-block, it will not appear in this map.
338   PiBlockMapType PiBlockMap;
339 };
340 
341 /// Concrete implementation of a pure data dependence graph builder. This class
342 /// provides custom implementation for the pure-virtual functions used in the
343 /// generic dependence graph build algorithm.
344 ///
345 /// For information about time complexity of the build algorithm see the
346 /// comments near the declaration of AbstractDependenceGraphBuilder.
347 class LLVM_ABI DDGBuilder
348     : public AbstractDependenceGraphBuilder<DataDependenceGraph> {
349 public:
DDGBuilder(DataDependenceGraph & G,DependenceInfo & D,const BasicBlockListType & BBs)350   DDGBuilder(DataDependenceGraph &G, DependenceInfo &D,
351              const BasicBlockListType &BBs)
352       : AbstractDependenceGraphBuilder(G, D, BBs) {}
createRootNode()353   DDGNode &createRootNode() final {
354     auto *RN = new RootDDGNode();
355     assert(RN && "Failed to allocate memory for DDG root node.");
356     Graph.addNode(*RN);
357     return *RN;
358   }
createFineGrainedNode(Instruction & I)359   DDGNode &createFineGrainedNode(Instruction &I) final {
360     auto *SN = new SimpleDDGNode(I);
361     assert(SN && "Failed to allocate memory for simple DDG node.");
362     Graph.addNode(*SN);
363     return *SN;
364   }
createPiBlock(const NodeListType & L)365   DDGNode &createPiBlock(const NodeListType &L) final {
366     auto *Pi = new PiBlockDDGNode(L);
367     assert(Pi && "Failed to allocate memory for pi-block node.");
368     Graph.addNode(*Pi);
369     return *Pi;
370   }
createDefUseEdge(DDGNode & Src,DDGNode & Tgt)371   DDGEdge &createDefUseEdge(DDGNode &Src, DDGNode &Tgt) final {
372     auto *E = new DDGEdge(Tgt, DDGEdge::EdgeKind::RegisterDefUse);
373     assert(E && "Failed to allocate memory for edge");
374     Graph.connect(Src, Tgt, *E);
375     return *E;
376   }
createMemoryEdge(DDGNode & Src,DDGNode & Tgt)377   DDGEdge &createMemoryEdge(DDGNode &Src, DDGNode &Tgt) final {
378     auto *E = new DDGEdge(Tgt, DDGEdge::EdgeKind::MemoryDependence);
379     assert(E && "Failed to allocate memory for edge");
380     Graph.connect(Src, Tgt, *E);
381     return *E;
382   }
createRootedEdge(DDGNode & Src,DDGNode & Tgt)383   DDGEdge &createRootedEdge(DDGNode &Src, DDGNode &Tgt) final {
384     auto *E = new DDGEdge(Tgt, DDGEdge::EdgeKind::Rooted);
385     assert(E && "Failed to allocate memory for edge");
386     assert(isa<RootDDGNode>(Src) && "Expected root node");
387     Graph.connect(Src, Tgt, *E);
388     return *E;
389   }
390 
getNodesInPiBlock(const DDGNode & N)391   const NodeListType &getNodesInPiBlock(const DDGNode &N) final {
392     auto *PiNode = dyn_cast<const PiBlockDDGNode>(&N);
393     assert(PiNode && "Expected a pi-block node.");
394     return PiNode->getNodes();
395   }
396 
397   /// Return true if the two nodes \pSrc and \pTgt are both simple nodes and
398   /// the consecutive instructions after merging belong to the same basic block.
399   bool areNodesMergeable(const DDGNode &Src, const DDGNode &Tgt) const final;
400   void mergeNodes(DDGNode &Src, DDGNode &Tgt) final;
401   bool shouldSimplify() const final;
402   bool shouldCreatePiBlocks() const final;
403 };
404 
405 LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DDGNode &N);
406 LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DDGNode::NodeKind K);
407 LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DDGEdge &E);
408 LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DDGEdge::EdgeKind K);
409 LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DataDependenceGraph &G);
410 
411 //===--------------------------------------------------------------------===//
412 // DDG Analysis Passes
413 //===--------------------------------------------------------------------===//
414 
415 /// Analysis pass that builds the DDG for a loop.
416 class DDGAnalysis : public AnalysisInfoMixin<DDGAnalysis> {
417 public:
418   using Result = std::unique_ptr<DataDependenceGraph>;
419   LLVM_ABI Result run(Loop &L, LoopAnalysisManager &AM,
420                       LoopStandardAnalysisResults &AR);
421 
422 private:
423   friend AnalysisInfoMixin<DDGAnalysis>;
424   LLVM_ABI static AnalysisKey Key;
425 };
426 
427 /// Textual printer pass for the DDG of a loop.
428 class DDGAnalysisPrinterPass : public PassInfoMixin<DDGAnalysisPrinterPass> {
429 public:
DDGAnalysisPrinterPass(raw_ostream & OS)430   explicit DDGAnalysisPrinterPass(raw_ostream &OS) : OS(OS) {}
431   LLVM_ABI PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
432                                  LoopStandardAnalysisResults &AR,
433                                  LPMUpdater &U);
isRequired()434   static bool isRequired() { return true; }
435 
436 private:
437   raw_ostream &OS;
438 };
439 
440 //===--------------------------------------------------------------------===//
441 // DependenceGraphInfo Implementation
442 //===--------------------------------------------------------------------===//
443 
444 template <typename NodeType>
getDependencies(const NodeType & Src,const NodeType & Dst,DependenceList & Deps)445 bool DependenceGraphInfo<NodeType>::getDependencies(
446     const NodeType &Src, const NodeType &Dst, DependenceList &Deps) const {
447   assert(Deps.empty() && "Expected empty output list at the start.");
448 
449   // List of memory access instructions from src and dst nodes.
450   SmallVector<Instruction *, 8> SrcIList, DstIList;
451   auto isMemoryAccess = [](const Instruction *I) {
452     return I->mayReadOrWriteMemory();
453   };
454   Src.collectInstructions(isMemoryAccess, SrcIList);
455   Dst.collectInstructions(isMemoryAccess, DstIList);
456 
457   for (auto *SrcI : SrcIList)
458     for (auto *DstI : DstIList)
459       if (auto Dep =
460               const_cast<DependenceInfo *>(&DI)->depends(SrcI, DstI))
461         Deps.push_back(std::move(Dep));
462 
463   return !Deps.empty();
464 }
465 
466 template <typename NodeType>
467 std::string
getDependenceString(const NodeType & Src,const NodeType & Dst)468 DependenceGraphInfo<NodeType>::getDependenceString(const NodeType &Src,
469                                                    const NodeType &Dst) const {
470   std::string Str;
471   raw_string_ostream OS(Str);
472   DependenceList Deps;
473   if (!getDependencies(Src, Dst, Deps))
474     return Str;
475   interleaveComma(Deps, OS, [&](const std::unique_ptr<Dependence> &D) {
476     D->dump(OS);
477     // Remove the extra new-line character printed by the dump
478     // method
479     if (Str.back() == '\n')
480       Str.pop_back();
481   });
482 
483   return Str;
484 }
485 
486 //===--------------------------------------------------------------------===//
487 // GraphTraits specializations for the DDG
488 //===--------------------------------------------------------------------===//
489 
490 /// non-const versions of the grapth trait specializations for DDG
491 template <> struct GraphTraits<DDGNode *> {
492   using NodeRef = DDGNode *;
493 
494   static DDGNode *DDGGetTargetNode(DGEdge<DDGNode, DDGEdge> *P) {
495     return &P->getTargetNode();
496   }
497 
498   // Provide a mapped iterator so that the GraphTrait-based implementations can
499   // find the target nodes without having to explicitly go through the edges.
500   using ChildIteratorType =
501       mapped_iterator<DDGNode::iterator, decltype(&DDGGetTargetNode)>;
502   using ChildEdgeIteratorType = DDGNode::iterator;
503 
504   static NodeRef getEntryNode(NodeRef N) { return N; }
505   static ChildIteratorType child_begin(NodeRef N) {
506     return ChildIteratorType(N->begin(), &DDGGetTargetNode);
507   }
508   static ChildIteratorType child_end(NodeRef N) {
509     return ChildIteratorType(N->end(), &DDGGetTargetNode);
510   }
511 
512   static ChildEdgeIteratorType child_edge_begin(NodeRef N) {
513     return N->begin();
514   }
515   static ChildEdgeIteratorType child_edge_end(NodeRef N) { return N->end(); }
516 };
517 
518 template <>
519 struct GraphTraits<DataDependenceGraph *> : public GraphTraits<DDGNode *> {
520   using nodes_iterator = DataDependenceGraph::iterator;
521   static NodeRef getEntryNode(DataDependenceGraph *DG) {
522     return &DG->getRoot();
523   }
524   static nodes_iterator nodes_begin(DataDependenceGraph *DG) {
525     return DG->begin();
526   }
527   static nodes_iterator nodes_end(DataDependenceGraph *DG) { return DG->end(); }
528 };
529 
530 /// const versions of the grapth trait specializations for DDG
531 template <> struct GraphTraits<const DDGNode *> {
532   using NodeRef = const DDGNode *;
533 
534   static const DDGNode *DDGGetTargetNode(const DGEdge<DDGNode, DDGEdge> *P) {
535     return &P->getTargetNode();
536   }
537 
538   // Provide a mapped iterator so that the GraphTrait-based implementations can
539   // find the target nodes without having to explicitly go through the edges.
540   using ChildIteratorType =
541       mapped_iterator<DDGNode::const_iterator, decltype(&DDGGetTargetNode)>;
542   using ChildEdgeIteratorType = DDGNode::const_iterator;
543 
544   static NodeRef getEntryNode(NodeRef N) { return N; }
545   static ChildIteratorType child_begin(NodeRef N) {
546     return ChildIteratorType(N->begin(), &DDGGetTargetNode);
547   }
548   static ChildIteratorType child_end(NodeRef N) {
549     return ChildIteratorType(N->end(), &DDGGetTargetNode);
550   }
551 
552   static ChildEdgeIteratorType child_edge_begin(NodeRef N) {
553     return N->begin();
554   }
555   static ChildEdgeIteratorType child_edge_end(NodeRef N) { return N->end(); }
556 };
557 
558 template <>
559 struct GraphTraits<const DataDependenceGraph *>
560     : public GraphTraits<const DDGNode *> {
561   using nodes_iterator = DataDependenceGraph::const_iterator;
562   static NodeRef getEntryNode(const DataDependenceGraph *DG) {
563     return &DG->getRoot();
564   }
565   static nodes_iterator nodes_begin(const DataDependenceGraph *DG) {
566     return DG->begin();
567   }
568   static nodes_iterator nodes_end(const DataDependenceGraph *DG) {
569     return DG->end();
570   }
571 };
572 
573 } // namespace llvm
574 
575 #endif // LLVM_ANALYSIS_DDG_H
576