13 #ifndef MLIR_IR_VISITORS_H
14 #define MLIR_IR_VISITORS_H
18 #include "llvm/ADT/STLExtras.h"
22 class InFlightDiagnostic;
35 enum ResultEnum { Interrupt, Advance, Skip } result;
42 : result(
failed(result) ? Interrupt : Advance) {}
87 bool isAfterRegion(
int region)
const {
return nextRegion == region + 1; }
102 template <
typename Ret,
typename Arg,
typename... Rest>
104 template <
typename Ret,
typename F,
typename Arg,
typename... Rest>
106 template <
typename Ret,
typename F,
typename Arg,
typename... Rest>
108 template <
typename F>
112 template <typename T>
167 typename RetT = decltype(std::declval<FuncTy>()(std::declval<ArgT>()))>
188 typename RetT = decltype(std::declval<FuncTy>()(std::declval<ArgT>()))>
190 !llvm::is_one_of<ArgT, Operation *, Region *, Block *>::value &&
191 std::is_same<RetT, void>::value,
195 if (
auto derivedOp = dyn_cast<ArgT>(op))
223 typename RetT = decltype(std::declval<FuncTy>()(std::declval<ArgT>()))>
225 !llvm::is_one_of<ArgT, Operation *, Region *, Block *>::value &&
226 std::is_same<RetT, WalkResult>::value,
230 if (
auto derivedOp = dyn_cast<ArgT>(op))
231 return callback(derivedOp);
262 template <
typename FuncTy,
typename ArgT = detail::first_argument<FuncTy>,
263 typename RetT = decltype(std::declval<FuncTy>()(
264 std::declval<ArgT>(), std::declval<const WalkStage &>()))>
265 std::enable_if_t<std::is_same<ArgT, Operation *>::value, RetT>
277 template <
typename FuncTy,
typename ArgT = detail::first_argument<FuncTy>,
278 typename RetT = decltype(std::declval<FuncTy>()(
279 std::declval<ArgT>(), std::declval<const WalkStage &>()))>
280 std::enable_if_t<!std::is_same<ArgT, Operation *>::value &&
281 std::is_same<RetT, void>::value,
285 if (
auto derivedOp = dyn_cast<ArgT>(op))
286 callback(derivedOp, stage);
302 template <
typename FuncTy,
typename ArgT = detail::first_argument<FuncTy>,
303 typename RetT = decltype(std::declval<FuncTy>()(
304 std::declval<ArgT>(), std::declval<const WalkStage &>()))>
305 std::enable_if_t<!std::is_same<ArgT, Operation *>::value &&
306 std::is_same<RetT, WalkResult>::value,
310 if (
auto derivedOp = dyn_cast<ArgT>(op))
311 return callback(derivedOp, stage);
319 template <
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:
WalkResult(InFlightDiagnostic &&)
bool operator==(const WalkResult &rhs) const
WalkResult(LogicalResult result)
Allow LogicalResult to interrupt the walk on failure.
bool wasSkipped() const
Returns true if the walk was skipped.
WalkResult(ResultEnum result)
static WalkResult advance()
bool wasInterrupted() const
Returns true if the walk was interrupted.
WalkResult(Diagnostic &&)
Allow diagnostics to interrupt the walk.
static WalkResult interrupt()
bool operator!=(const WalkResult &rhs) const
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.
Include the generated interface declarations.
decltype(walk(nullptr, std::declval< FnT >())) walkResultType
Utility to provide the return type of a templated walk method.
decltype(first_argument_type(&F::operator())) first_argument_type(F)
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'.
Include the generated interface declarations.
WalkOrder
Traversal order for region, block and operation walk utilities.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.