//===- RegionIterator.h - Iterators to iteratate over Regions ---*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // This file defines the iterators to iterate over the elements of a Region. //===----------------------------------------------------------------------===// #ifndef LLVM_ANALYSIS_REGIONITERATOR_H #define LLVM_ANALYSIS_REGIONITERATOR_H #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/Analysis/RegionInfo.h" #include <cassert> #include <iterator> #include <type_traits> namespace llvm { class BasicBlock; class RegionInfo; //===----------------------------------------------------------------------===// /// Hierarchical RegionNode successor iterator. /// /// This iterator iterates over all successors of a RegionNode. /// /// For a BasicBlock RegionNode it skips all BasicBlocks that are not part of /// the parent Region. Furthermore for BasicBlocks that start a subregion, a /// RegionNode representing the subregion is returned. /// /// For a subregion RegionNode there is just one successor. The RegionNode /// representing the exit of the subregion. template <class NodeRef, class BlockT, class RegionT> class RNSuccIterator { … }; //===----------------------------------------------------------------------===// /// Flat RegionNode iterator. /// /// The Flat Region iterator will iterate over all BasicBlock RegionNodes that /// are contained in the Region and its subregions. This is close to a virtual /// control flow graph of the Region. RNSuccIterator<FlatIt<NodeRef>, BlockT, RegionT>; template <class NodeRef, class BlockT, class RegionT> inline RNSuccIterator<NodeRef, BlockT, RegionT> succ_begin(NodeRef Node) { … } template <class NodeRef, class BlockT, class RegionT> inline RNSuccIterator<NodeRef, BlockT, RegionT> succ_end(NodeRef Node) { … } //===--------------------------------------------------------------------===// // RegionNode GraphTraits specialization so the bbs in the region can be // iterate by generic graph iterators. // // NodeT can either be region node or const region node, otherwise child_begin // and child_end fail. #define RegionNodeGraphTraits(NodeT, BlockT, RegionT) … #define RegionGraphTraits(RegionT, NodeT) … RegionNodeGraphTraits(…); RegionNodeGraphTraits(const RegionNode, BasicBlock, Region); RegionGraphTraits(…); RegionGraphTraits(…); template <> struct GraphTraits<RegionInfo*> : public GraphTraits<FlatIt<RegionNode*>> { … }; template <> struct GraphTraits<RegionInfoPass*> : public GraphTraits<RegionInfo *> { … }; } // end namespace llvm #endif // LLVM_ANALYSIS_REGIONITERATOR_H