MLIR  16.0.0git
RegionGraphTraits.h
Go to the documentation of this file.
1 //===- RegionGraphTraits.h - llvm::GraphTraits for CFGs ---------*- 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 implements specializations of llvm::GraphTraits for various MLIR
10 // CFG data types. This allows the generic LLVM graph algorithms to be applied
11 // to CFGs.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef MLIR_IR_REGIONGRAPHTRAITS_H
16 #define MLIR_IR_REGIONGRAPHTRAITS_H
17 
18 #include "mlir/IR/Region.h"
19 #include "llvm/ADT/GraphTraits.h"
20 
21 namespace llvm {
22 template <>
23 struct GraphTraits<mlir::Block *> {
25  using Node = mlir::Block;
26  using NodeRef = Node *;
27 
28  static NodeRef getEntryNode(NodeRef bb) { return bb; }
29 
31  return node->succ_begin();
32  }
33  static ChildIteratorType child_end(NodeRef node) { return node->succ_end(); }
34 };
35 
36 template <>
37 struct GraphTraits<Inverse<mlir::Block *>> {
39  using Node = mlir::Block;
40  using NodeRef = Node *;
41  static NodeRef getEntryNode(Inverse<NodeRef> inverseGraph) {
42  return inverseGraph.Graph;
43  }
44  static inline ChildIteratorType child_begin(NodeRef node) {
45  return node->pred_begin();
46  }
47  static inline ChildIteratorType child_end(NodeRef node) {
48  return node->pred_end();
49  }
50 };
51 
52 template <>
53 struct GraphTraits<mlir::Region *> : public GraphTraits<mlir::Block *> {
55  using NodeRef = mlir::Block *;
56 
57  static NodeRef getEntryNode(GraphType fn) { return &fn->front(); }
58 
59  using nodes_iterator = pointer_iterator<mlir::Region::iterator>;
61  return nodes_iterator(fn->begin());
62  }
64  return nodes_iterator(fn->end());
65  }
66 };
67 
68 template <>
69 struct GraphTraits<Inverse<mlir::Region *>>
70  : public GraphTraits<Inverse<mlir::Block *>> {
71  using GraphType = Inverse<mlir::Region *>;
72  using NodeRef = NodeRef;
73 
74  static NodeRef getEntryNode(GraphType fn) { return &fn.Graph->front(); }
75 
76  using nodes_iterator = pointer_iterator<mlir::Region::iterator>;
78  return nodes_iterator(fn.Graph->begin());
79  }
81  return nodes_iterator(fn.Graph->end());
82  }
83 };
84 
85 } // namespace llvm
86 
87 #endif
Block represents an ordered list of Operations.
Definition: Block.h:30
SuccessorRange::iterator succ_iterator
Definition: Block.h:250
succ_iterator succ_end()
Definition: Block.h:252
pred_iterator pred_begin()
Definition: Block.h:219
succ_iterator succ_begin()
Definition: Block.h:251
PredecessorIterator pred_iterator
Definition: Block.h:218
Operation & front()
Definition: Block.h:142
pred_iterator pred_end()
Definition: Block.h:222
Implement a predecessor iterator for blocks.
Definition: BlockSupport.h:51
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
iterator end()
Definition: Region.h:56
iterator begin()
Definition: Region.h:55
Block & front()
Definition: Region.h:65
Include the generated interface declarations.
Definition: CallGraph.h:229
Include the generated interface declarations.
static ChildIteratorType child_end(NodeRef node)
static NodeRef getEntryNode(Inverse< NodeRef > inverseGraph)
static ChildIteratorType child_begin(NodeRef node)
static nodes_iterator nodes_begin(GraphType fn)
static nodes_iterator nodes_end(GraphType fn)
pointer_iterator< mlir::Region::iterator > nodes_iterator
static ChildIteratorType child_end(NodeRef node)
mlir::Block::succ_iterator ChildIteratorType
static ChildIteratorType child_begin(NodeRef node)
static NodeRef getEntryNode(NodeRef bb)
static NodeRef getEntryNode(GraphType fn)
static nodes_iterator nodes_begin(GraphType fn)
pointer_iterator< mlir::Region::iterator > nodes_iterator
static nodes_iterator nodes_end(GraphType fn)