| 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: 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 |
| 60 | |