My Project
BlockSupport.h
Go to the documentation of this file.
1 //===- BlockSupport.h -------------------------------------------*- C++ -*-===//
2 //
3 // Part of the MLIR 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 a number of support types for the Block class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_IR_BLOCK_SUPPORT_H
14 #define MLIR_IR_BLOCK_SUPPORT_H
15 
16 #include "mlir/IR/Value.h"
17 #include "llvm/ADT/PointerUnion.h"
18 #include "llvm/ADT/ilist.h"
19 #include "llvm/ADT/ilist_node.h"
20 
21 namespace mlir {
22 class Block;
23 
24 //===----------------------------------------------------------------------===//
25 // Predecessors
26 //===----------------------------------------------------------------------===//
27 
33  : public llvm::mapped_iterator<ValueUseIterator<BlockOperand>,
34  Block *(*)(BlockOperand &)> {
35  static Block *unwrap(BlockOperand &value);
36 
37 public:
38  using reference = Block *;
39 
42  : llvm::mapped_iterator<ValueUseIterator<BlockOperand>,
43  Block *(*)(BlockOperand &)>(it, &unwrap) {}
44  explicit PredecessorIterator(BlockOperand *operand)
46 
48  unsigned getSuccessorIndex() const;
49 };
50 
51 //===----------------------------------------------------------------------===//
52 // Successors
53 //===----------------------------------------------------------------------===//
54 
56 class SuccessorRange final
57  : public detail::indexed_accessor_range_base<SuccessorRange, BlockOperand *,
58  Block *, Block *, Block *> {
59 public:
61  SuccessorRange(Block *block);
63 
64 private:
66  static BlockOperand *offset_base(BlockOperand *object, ptrdiff_t index) {
67  return object + index;
68  }
70  static Block *dereference_iterator(BlockOperand *object, ptrdiff_t index) {
71  return object[index].get();
72  }
73 
75  friend RangeBaseT;
76 };
77 
78 } // end namespace mlir
79 
80 namespace llvm {
81 
82 //===----------------------------------------------------------------------===//
83 // ilist_traits for Operation
84 //===----------------------------------------------------------------------===//
85 
86 namespace ilist_detail {
87 // Explicitly define the node access for the operation list so that we can
88 // break the dependence on the Operation class in this header. This allows for
89 // operations to have trailing Regions without a circular include
90 // dependence.
91 template <>
92 struct SpecificNodeAccess<
93  typename compute_node_options<::mlir::Operation>::type> : NodeAccess {
94 protected:
95  using OptionsT = typename compute_node_options<mlir::Operation>::type;
96  using pointer = typename OptionsT::pointer;
97  using const_pointer = typename OptionsT::const_pointer;
98  using node_type = ilist_node_impl<OptionsT>;
99 
100  static node_type *getNodePtr(pointer N);
101  static const node_type *getNodePtr(const_pointer N);
102 
103  static pointer getValuePtr(node_type *N);
104  static const_pointer getValuePtr(const node_type *N);
105 };
106 } // end namespace ilist_detail
107 
108 template <> struct ilist_traits<::mlir::Operation> {
110  using op_iterator = simple_ilist<Operation>::iterator;
111 
112  static void deleteNode(Operation *op);
113  void addNodeToList(Operation *op);
114  void removeNodeFromList(Operation *op);
115  void transferNodesFromList(ilist_traits<Operation> &otherList,
116  op_iterator first, op_iterator last);
117 
118 private:
119  mlir::Block *getContainingBlock();
120 };
121 
122 //===----------------------------------------------------------------------===//
123 // ilist_traits for Block
124 //===----------------------------------------------------------------------===//
125 
126 template <>
127 struct ilist_traits<::mlir::Block> : public ilist_alloc_traits<::mlir::Block> {
129  using block_iterator = simple_ilist<::mlir::Block>::iterator;
130 
131  void addNodeToList(Block *block);
132  void removeNodeFromList(Block *block);
133  void transferNodesFromList(ilist_traits<Block> &otherList,
134  block_iterator first, block_iterator last);
135 
136 private:
137  mlir::Region *getParentRegion();
138 };
139 
140 } // end namespace llvm
141 
142 #endif // MLIR_IR_BLOCK_SUPPORT_H
Definition: InferTypeOpInterface.cpp:20
Definition: Region.h:23
typename OptionsT::const_pointer const_pointer
Definition: BlockSupport.h:97
Definition: PassRegistry.cpp:413
Definition: Operation.h:27
Block represents an ordered list of Operations.
Definition: Block.h:21
PredecessorIterator(BlockOperand *operand)
Definition: BlockSupport.h:44
An iterator over all of the uses of an IR object.
Definition: UseDefLists.h:25
Terminator operations can have Block operands to represent successors.
Definition: UseDefLists.h:288
simple_ilist< Operation >::iterator op_iterator
Definition: BlockSupport.h:110
typename compute_node_options< mlir::Operation >::type OptionsT
Definition: BlockSupport.h:95
This class implements the successor iterators for Block.
Definition: BlockSupport.h:56
simple_ilist<::mlir::Block >::iterator block_iterator
Definition: BlockSupport.h:129
unsigned getSuccessorIndex() const
Get the successor number in the predecessor terminator.
Definition: Block.cpp:271
Definition: BlockSupport.h:32
PredecessorIterator(ValueUseIterator< BlockOperand > it)
Initializes the operand type iterator to the specified operand iterator.
Definition: BlockSupport.h:41