13#ifndef MLIR_IR_VISITORS_H
14#define MLIR_IR_VISITORS_H
18#include "llvm/ADT/STLExtras.h"
64 bool isAfterRegion(
int region)
const {
return nextRegion == region + 1; }
79template <
typename Ret,
typename Arg,
typename... Rest>
81template <
typename Ret,
typename F,
typename Arg,
typename... Rest>
83template <
typename Ret,
typename F,
typename Arg,
typename... Rest>
101template <
typename Iterator>
106 for (
auto ®ion : Iterator::makeIterable(*op)) {
109 for (
auto &block : Iterator::makeIterable(region)) {
110 for (
auto &nestedOp : Iterator::makeIterable(block))
118template <
typename Iterator>
121 for (
auto ®ion : Iterator::makeIterable(*op)) {
124 auto &&It = Iterator::makeIterable(region);
125 for (
auto &block : llvm::make_early_inc_range(It)) {
128 for (
auto &nestedOp : Iterator::makeIterable(block))
136template <
typename Iterator>
143 for (
auto ®ion : Iterator::makeIterable(*op)) {
144 for (
auto &block : Iterator::makeIterable(region)) {
146 for (
auto &nestedOp :
147 llvm::make_early_inc_range(Iterator::makeIterable(block)))
166template <
typename Iterator>
171 for (
auto ®ion : Iterator::makeIterable(*op)) {
176 if (
result.wasInterrupted())
179 for (
auto &block : Iterator::makeIterable(region)) {
180 for (
auto &nestedOp : Iterator::makeIterable(block))
185 if (callback(®ion).wasInterrupted())
194template <
typename Iterator>
197 for (
auto ®ion : Iterator::makeIterable(*op)) {
200 auto &&It = Iterator::makeIterable(region);
201 for (
auto &block : llvm::make_early_inc_range(It)) {
206 if (
result.wasInterrupted())
209 for (
auto &nestedOp : Iterator::makeIterable(block))
213 if (callback(&block).wasInterrupted())
223template <
typename Iterator>
231 if (
result.wasInterrupted())
236 for (
auto ®ion : Iterator::makeIterable(*op)) {
237 for (
auto &block : Iterator::makeIterable(region)) {
239 for (
auto &nestedOp :
240 llvm::make_early_inc_range(Iterator::makeIterable(block))) {
276 typename RetT =
decltype(std::declval<FuncTy>()(std::declval<ArgT>()))>
277std::enable_if_t<llvm::is_one_of<ArgT, Operation *, Region *, Block *>::value,
298 typename RetT =
decltype(std::declval<FuncTy>()(std::declval<ArgT>()))>
300 !llvm::is_one_of<ArgT, Operation *, Region *, Block *>::value &&
301 std::is_same<RetT, void>::value,
305 if (
auto derivedOp = dyn_cast<ArgT>(op))
335 typename RetT =
decltype(std::declval<FuncTy>()(std::declval<ArgT>()))>
337 !llvm::is_one_of<ArgT, Operation *, Region *, Block *>::value &&
338 std::is_same<RetT, WalkResult>::value,
342 if (
auto derivedOp = dyn_cast<ArgT>(op))
343 return callback(derivedOp);
375template <
typename FuncTy,
typename ArgT = detail::first_argument<FuncTy>,
376 typename RetT = decltype(std::declval<FuncTy>()(
377 std::declval<ArgT>(), std::declval<const WalkStage &>()))>
378std::enable_if_t<std::is_same<ArgT, Operation *>::value, RetT>
390template <
typename FuncTy,
typename ArgT = detail::first_argument<FuncTy>,
391 typename RetT = decltype(std::declval<FuncTy>()(
392 std::declval<ArgT>(), std::declval<const WalkStage &>()))>
393std::enable_if_t<!std::is_same<ArgT, Operation *>::value &&
394 std::is_same<RetT, void>::value,
398 if (
auto derivedOp = dyn_cast<ArgT>(op))
399 callback(derivedOp, stage);
415template <
typename FuncTy,
typename ArgT = detail::first_argument<FuncTy>,
416 typename RetT = decltype(std::declval<FuncTy>()(
417 std::declval<ArgT>(), std::declval<const WalkStage &>()))>
418std::enable_if_t<!std::is_same<ArgT, Operation *>::value &&
419 std::is_same<RetT, WalkResult>::value,
423 if (
auto derivedOp = dyn_cast<ArgT>(op))
424 return callback(derivedOp, stage);
432template <
typename FnT>
Block represents an ordered list of Operations.
This class contains all of the information necessary to report a diagnostic to the DiagnosticEngine.
This class represents a diagnostic that is inflight and set to be reported.
Operation is the basic unit of execution within MLIR.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
A utility result that is used to signal how to proceed with an ongoing walk:
static WalkResult advance()
static WalkResult interrupt()
A utility class to encode the current walk stage for "generic" walkers.
void advance()
Advance the walk stage.
int getNextRegion() const
Returns the next region that will be visited.
bool isBeforeRegion(int region) const
Returns true if parent operation is being visited just before visiting region number region.
bool isAfterAllRegions() const
Return true if parent operation is being visited after all regions.
bool isAfterRegion(int region) const
Returns true if parent operation is being visited just after visiting region number region.
bool isBeforeAllRegions() const
Return true if parent operation is being visited before all regions.
void walk(Operation *op, function_ref< void(Region *)> callback, WalkOrder order)
Walk all of the regions, blocks, or operations nested under (and including) the given operation.
decltype(first_argument_type(std::declval< T >())) first_argument
Type definition of the first argument to the given callable 'T'.
Arg first_argument_type(Ret(*)(Arg, Rest...))
Helper templates to deduce the first argument of a callback parameter.
decltype(walk(nullptr, std::declval< FnT >())) walkResultType
Utility to provide the return type of a templated walk method.
Include the generated interface declarations.
WalkOrder
Traversal order for region, block and operation walk utilities.
llvm::function_ref< Fn > function_ref
This iterator enumerates the elements in "forward" order.
static MutableArrayRef< Region > makeIterable(Operation &range)
Make operations iterable: return the list of regions.
static constexpr T & makeIterable(T &range)
Regions and block are already iterable.