DDG.h 20 KB

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