DDG.h 20 KB

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