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) {}
86 bool isAfterRegion(
int region)
const {
return nextRegion == region + 1; }
101 template <
typename Ret,
typename Arg,
typename... Rest>
103 template <
typename Ret,
typename F,
typename Arg,
typename... Rest>
105 template <
typename Ret,
typename F,
typename Arg,
typename... Rest>
107 template <
typename F>
111 template <typename T>
166 typename RetT = decltype(std::declval<FuncTy>()(std::declval<ArgT>()))>
167 typename std::enable_if<
169 walk(Operation *op, FuncTy &&callback) {
187 typename RetT = decltype(std::declval<FuncTy>()(std::declval<ArgT>()))>
188 typename std::enable_if<
194 if (
auto derivedOp = dyn_cast<ArgT>(op))
222 typename RetT = decltype(std::declval<FuncTy>()(std::declval<ArgT>()))>
223 typename std::enable_if<
229 if (
auto derivedOp = dyn_cast<ArgT>(op))
230 return callback(derivedOp);
261 template <
typename FuncTy,
typename ArgT = detail::first_argument<FuncTy>,
262 typename RetT = decltype(std::declval<FuncTy>()(
263 std::declval<ArgT>(), std::declval<const WalkStage &>()))>
276 template <
typename FuncTy,
typename ArgT = detail::first_argument<FuncTy>,
277 typename RetT = decltype(std::declval<FuncTy>()(
278 std::declval<ArgT>(), std::declval<const WalkStage &>()))>
280 std::is_same<RetT, void>::value,
284 if (
auto derivedOp = dyn_cast<ArgT>(op))
285 callback(derivedOp, stage);
301 template <
typename FuncTy,
typename ArgT = detail::first_argument<FuncTy>,
302 typename RetT = decltype(std::declval<FuncTy>()(
303 std::declval<ArgT>(), std::declval<const WalkStage &>()))>
305 std::is_same<RetT, WalkResult>::value,
309 if (
auto derivedOp = dyn_cast<ArgT>(op))
310 return callback(derivedOp, stage);
318 template <
typename FnT>
Include the generated interface declarations.
This class contains a list of basic blocks and a link to the parent operation it is attached to...
WalkResult(InFlightDiagnostic &&)
Explicitly register a set of "builtin" types.
Operation is a basic unit of execution within MLIR.
This class represents a diagnostic that is inflight and set to be reported.
Block represents an ordered list of Operations.
bool wasInterrupted() const
Returns true if the walk was interrupted.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
bool isAfterAllRegions() const
Return true if parent operation is being visited after all regions.
Arg first_argument_type(Ret(F::*)(Arg, Rest...))
static constexpr const bool value
bool isBeforeRegion(int region) const
Returns true if parent operation is being visited just before visiting region number region...
decltype(walk(nullptr, std::declval< FnT >())) walkResultType
Utility to provide the return type of a templated walk method.
This class contains all of the information necessary to report a diagnostic to the DiagnosticEngine...
This class represents an efficient way to signal success or failure.
void advance()
Advance the walk stage.
WalkResult(LogicalResult result)
Allow LogicalResult to interrupt the walk on failure.
static WalkResult advance()
int getNextRegion() const
Returns the next region that will be visited.
A utility class to encode the current walk stage for "generic" walkers.
static WalkResult interrupt()
A utility result that is used to signal how to proceed with an ongoing walk:
decltype(first_argument_type(std::declval< T >())) first_argument
Type definition of the first argument to the given callable 'T'.
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...
bool wasSkipped() const
Returns true if the walk was skipped.
bool operator==(const WalkResult &rhs) const
WalkResult(ResultEnum result)
std::enable_if<!std::is_same< ArgT, Operation * >::value &&std::is_same< RetT, WalkResult >::value, RetT >::type walk(Operation *op, FuncTy &&callback)
Walk all of the operations of type 'ArgT' nested under and including the given operation.
WalkOrder
Traversal order for region, block and operation walk utilities.
WalkResult(Diagnostic &&)
Allow diagnostics to interrupt the walk.