12 #ifndef LLVM_ANALYSIS_REGIONITERATOR_H 13 #define LLVM_ANALYSIS_REGIONITERATOR_H 22 #include <type_traits> 39 template <
class NodeRef,
class BlockT,
class RegionT>
41 :
public std::iterator<std::forward_iterator_tag, NodeRef> {
42 using super = std::iterator<std::forward_iterator_tag, NodeRef>;
44 using SuccIterTy =
typename BlockTraits::ChildIteratorType;
57 static_assert(std::is_pointer<NodeRef>::value,
58 "FIXME: Currently RNSuccIterator only supports NodeRef as " 59 "pointers due to the use of pointer-specific data structures " 60 "(e.g. PointerIntPair and SmallPtrSet) internally. Generalize " 61 "it to support non-pointer types");
71 void advanceRegionSucc() {
72 assert(Node.
getInt() == ItRgBegin &&
"Cannot advance region successor!");
76 NodeRef getNode()
const {
return Node.
getPointer(); }
79 bool isRegionMode()
const {
return Node.
getInt() != ItBB; }
83 NodeRef getISucc(BlockT *BB)
const {
85 succ = getNode()->getParent()->getNode(BB);
86 assert(succ &&
"BB not in Region or entered subregion!");
91 inline BlockT* getRegionSucc()
const {
92 assert(Node.
getInt() == ItRgBegin &&
"Cannot get the region successor!");
93 return getNode()->template getNodeAs<RegionT>()->getExit();
97 inline bool isExit(BlockT* BB)
const {
98 return getNode()->getParent()->getExit() == BB;
107 : Node(node, node->isSubRegion() ? ItRgBegin : ItBB),
108 BItor(
BlockTraits::child_begin(node->getEntry())) {
111 while (BlockTraits::child_end(node->getEntry()) != BItor && isExit(*BItor))
114 if (isRegionMode() && isExit(getRegionSucc()))
120 : Node(node, node->isSubRegion() ? ItRgEnd : ItBB),
124 assert(isRegionMode() == x.isRegionMode() &&
"Broken iterator!");
128 return BItor == x.BItor;
134 BlockT *BB = isRegionMode() ? getRegionSucc() : *BItor;
135 assert(!isExit(BB) &&
"Iterator out of range!");
147 while (BItor != BlockTraits::child_end(getNode()->getEntry())
166 template <
class NodeRef,
class BlockT,
class RegionT>
168 :
public std::iterator<std::forward_iterator_tag, NodeRef> {
169 using super = std::iterator<std::forward_iterator_tag, NodeRef>;
171 using SuccIterTy =
typename BlockTraits::ChildIteratorType;
185 : Node(node), Itor(
BlockTraits::child_begin(node->getEntry())) {
186 assert(!Node->isSubRegion() &&
187 "Subregion node not allowed in flat iterating mode!");
188 assert(Node->getParent() &&
"A BB node must have a parent!");
191 while (BlockTraits::child_end(Node->getEntry()) != Itor &&
192 Node->getParent()->getExit() == *Itor)
198 : Node(node), Itor(
BlockTraits::child_end(node->getEntry())) {
199 assert(!Node->isSubRegion() &&
200 "Subregion node not allowed in flat iterating mode!");
204 assert(Node->getParent() == x.Node->getParent()
205 &&
"Cannot compare iterators of different regions!");
207 return Itor == x.Itor && Node == x.Node;
216 RegionT *Parent = Node->getParent();
220 assert(Parent->getExit() != BB &&
"iterator out of range!");
222 return Parent->getBBNode(BB);
229 while (Itor !=
succ_end(Node->getEntry())
230 && Node->getParent()->getExit() == *Itor);
242 template <
class NodeRef,
class BlockT,
class RegionT>
247 template <
class NodeRef,
class BlockT,
class RegionT>
259 #define RegionNodeGraphTraits(NodeT, BlockT, RegionT) \ 260 template <> struct GraphTraits<NodeT *> { \ 261 using NodeRef = NodeT *; \ 262 using ChildIteratorType = RNSuccIterator<NodeRef, BlockT, RegionT>; \ 263 static NodeRef getEntryNode(NodeRef N) { return N; } \ 264 static inline ChildIteratorType child_begin(NodeRef N) { \ 265 return RNSuccIterator<NodeRef, BlockT, RegionT>(N); \ 267 static inline ChildIteratorType child_end(NodeRef N) { \ 268 return RNSuccIterator<NodeRef, BlockT, RegionT>(N, true); \ 271 template <> struct GraphTraits<FlatIt<NodeT *>> { \ 272 using NodeRef = NodeT *; \ 273 using ChildIteratorType = \ 274 RNSuccIterator<FlatIt<NodeRef>, BlockT, RegionT>; \ 275 static NodeRef getEntryNode(NodeRef N) { return N; } \ 276 static inline ChildIteratorType child_begin(NodeRef N) { \ 277 return RNSuccIterator<FlatIt<NodeRef>, BlockT, RegionT>(N); \ 279 static inline ChildIteratorType child_end(NodeRef N) { \ 280 return RNSuccIterator<FlatIt<NodeRef>, BlockT, RegionT>(N, true); \ 284 #define RegionGraphTraits(RegionT, NodeT) \ 285 template <> struct GraphTraits<RegionT *> : public GraphTraits<NodeT *> { \ 286 using nodes_iterator = df_iterator<NodeRef>; \ 287 static NodeRef getEntryNode(RegionT *R) { \ 288 return R->getNode(R->getEntry()); \ 290 static nodes_iterator nodes_begin(RegionT *R) { \ 291 return nodes_iterator::begin(getEntryNode(R)); \ 293 static nodes_iterator nodes_end(RegionT *R) { \ 294 return nodes_iterator::end(getEntryNode(R)); \ 298 struct GraphTraits<FlatIt<RegionT *>> \ 299 : public GraphTraits<FlatIt<NodeT *>> { \ 300 using nodes_iterator = \ 301 df_iterator<NodeRef, df_iterator_default_set<NodeRef>, false, \ 302 GraphTraits<FlatIt<NodeRef>>>; \ 303 static NodeRef getEntryNode(RegionT *R) { \ 304 return R->getBBNode(R->getEntry()); \ 306 static nodes_iterator nodes_begin(RegionT *R) { \ 307 return nodes_iterator::begin(getEntryNode(R)); \ 309 static nodes_iterator nodes_end(RegionT *R) { \ 310 return nodes_iterator::end(getEntryNode(R)); \ 360 #endif // LLVM_ANALYSIS_REGIONITERATOR_H
const_iterator end(StringRef path)
Get end iterator over path.
void setInt(IntType IntVal)
bool operator==(const Self &x) const
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
This class represents lattice values for constants.
PointerTy getPointer() const
static nodes_iterator nodes_begin(RegionInfo *RI)
value_type operator*() const
Hierarchical RegionNode successor iterator.
Flat RegionNode iterator.
RNSuccIterator(NodeRef node)
Create the iterator from a RegionNode.
static nodes_iterator nodes_end(RegionInfo *RI)
RNSuccIterator(NodeRef node, bool)
Create an end iterator.
RegionInfo & getRegionInfo()
static nodes_iterator nodes_begin(RegionInfoPass *RI)
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
typename super::value_type value_type
RegionT * getTopLevelRegion() const
RNSuccIterator(NodeRef node, bool)
Create an end iterator.
RegionNodeGraphTraits(RegionNode, BasicBlock, Region)
Interval::succ_iterator succ_end(Interval *I)
typename FlatIt< RegionNode * > ::UnknownGraphTypeError NodeRef
bool operator!=(const Self &x) const
static NodeRef getEntryNode(RegionInfoPass *RI)
bool operator==(const Self &x) const
static NodeRef getEntryNode(RegionInfo *RI)
RNSuccIterator(NodeRef node)
Create begin iterator of a RegionNode.
RegionGraphTraits(Region, RegionNode)
typename super::value_type value_type
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
value_type operator*() const
Marker class to iterate over the elements of a Region in flat mode.
static nodes_iterator nodes_end(RegionInfoPass *RI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator!=(const Self &x) const