MLIR  21.0.0git
WalkResult.h
Go to the documentation of this file.
1 //===- WalkResult.h - Status of completed walk ------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Result kind for completed walk.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_SUPPORT_WALKRESULT_H
14 #define MLIR_SUPPORT_WALKRESULT_H
15 
16 #include "mlir/Support/LLVM.h"
17 
18 namespace mlir {
19 class Diagnostic;
20 class InFlightDiagnostic;
21 
22 /// A utility result that is used to signal how to proceed with an ongoing walk:
23 /// * Interrupt: the walk will be interrupted and no more operations, regions
24 /// or blocks will be visited.
25 /// * Advance: the walk will continue.
26 /// * Skip: the walk of the current operation, region or block and their
27 /// nested elements that haven't been visited already will be skipped and will
28 /// continue with the next operation, region or block.
29 class WalkResult {
30  enum ResultEnum { Interrupt, Advance, Skip } result;
31 
32 public:
33  WalkResult(ResultEnum result = Advance) : result(result) {}
34 
35  /// Allow LogicalResult to interrupt the walk on failure.
36  WalkResult(LogicalResult result)
37  : result(failed(result) ? Interrupt : Advance) {}
38 
39  /// Allow diagnostics to interrupt the walk.
40  WalkResult(Diagnostic &&) : result(Interrupt) {}
41  WalkResult(InFlightDiagnostic &&) : result(Interrupt) {}
42 
43  bool operator==(const WalkResult &rhs) const { return result == rhs.result; }
44  bool operator!=(const WalkResult &rhs) const { return result != rhs.result; }
45 
46  static WalkResult interrupt() { return {Interrupt}; }
47  static WalkResult advance() { return {Advance}; }
48  static WalkResult skip() { return {Skip}; }
49 
50  /// Returns true if the walk was interrupted.
51  bool wasInterrupted() const { return result == Interrupt; }
52 
53  /// Returns true if the walk was skipped.
54  bool wasSkipped() const { return result == Skip; }
55 };
56 
57 } // namespace mlir
58 
59 #endif
This class contains all of the information necessary to report a diagnostic to the DiagnosticEngine.
Definition: Diagnostics.h:155
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:314
A utility result that is used to signal how to proceed with an ongoing walk:
Definition: WalkResult.h:29
WalkResult(InFlightDiagnostic &&)
Definition: WalkResult.h:41
bool operator==(const WalkResult &rhs) const
Definition: WalkResult.h:43
WalkResult(LogicalResult result)
Allow LogicalResult to interrupt the walk on failure.
Definition: WalkResult.h:36
WalkResult(ResultEnum result=Advance)
Definition: WalkResult.h:33
static WalkResult skip()
Definition: WalkResult.h:48
bool wasSkipped() const
Returns true if the walk was skipped.
Definition: WalkResult.h:54
static WalkResult advance()
Definition: WalkResult.h:47
bool wasInterrupted() const
Returns true if the walk was interrupted.
Definition: WalkResult.h:51
WalkResult(Diagnostic &&)
Allow diagnostics to interrupt the walk.
Definition: WalkResult.h:40
static WalkResult interrupt()
Definition: WalkResult.h:46
bool operator!=(const WalkResult &rhs) const
Definition: WalkResult.h:44
Include the generated interface declarations.