[Mlir-commits] [mlir] d0469d1 - [mlir] Move WalkResult to Support (#145649)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jun 25 01:58:49 PDT 2025
Author: Jacques Pienaar
Date: 2025-06-25T01:58:44-07:00
New Revision: d0469d1d3c31e919dba97637ac7ab063c44118e5
URL: https://github.com/llvm/llvm-project/commit/d0469d1d3c31e919dba97637ac7ab063c44118e5
DIFF: https://github.com/llvm/llvm-project/commit/d0469d1d3c31e919dba97637ac7ab063c44118e5.diff
LOG: [mlir] Move WalkResult to Support (#145649)
This also enables moving StateStack, both are relatively generic helper
structs not tied to IR.
Added:
mlir/include/mlir/Support/StateStack.h
mlir/include/mlir/Support/WalkResult.h
mlir/lib/Support/StateStack.cpp
Modified:
flang/lib/Lower/Bridge.cpp
flang/lib/Lower/OpenMP/OpenMP.cpp
mlir/include/mlir/IR/Visitors.h
mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
mlir/lib/IR/CMakeLists.txt
mlir/lib/Support/CMakeLists.txt
Removed:
mlir/include/mlir/IR/StateStack.h
mlir/lib/IR/StateStack.cpp
################################################################################
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 336a6f82319e6..8506b9a984e58 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -68,8 +68,8 @@
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/PatternMatch.h"
-#include "mlir/IR/StateStack.h"
#include "mlir/Parser/Parser.h"
+#include "mlir/Support/StateStack.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSet.h"
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 8575d8cf352fd..60b6366c184d4 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -39,7 +39,7 @@
#include "flang/Support/OpenMP-utils.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
-#include "mlir/IR/StateStack.h"
+#include "mlir/Support/StateStack.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Frontend/OpenMP/OMPConstants.h"
diff --git a/mlir/include/mlir/IR/Visitors.h b/mlir/include/mlir/IR/Visitors.h
index 15abf2559e5c4..893f66ae33deb 100644
--- a/mlir/include/mlir/IR/Visitors.h
+++ b/mlir/include/mlir/IR/Visitors.h
@@ -14,6 +14,7 @@
#define MLIR_IR_VISITORS_H
#include "mlir/Support/LLVM.h"
+#include "mlir/Support/WalkResult.h"
#include "llvm/ADT/STLExtras.h"
namespace mlir {
@@ -23,41 +24,6 @@ class Operation;
class Block;
class Region;
-/// A utility result that is used to signal how to proceed with an ongoing walk:
-/// * Interrupt: the walk will be interrupted and no more operations, regions
-/// or blocks will be visited.
-/// * Advance: the walk will continue.
-/// * Skip: the walk of the current operation, region or block and their
-/// nested elements that haven't been visited already will be skipped and will
-/// continue with the next operation, region or block.
-class WalkResult {
- enum ResultEnum { Interrupt, Advance, Skip } result;
-
-public:
- WalkResult(ResultEnum result = Advance) : result(result) {}
-
- /// Allow LogicalResult to interrupt the walk on failure.
- WalkResult(LogicalResult result)
- : result(failed(result) ? Interrupt : Advance) {}
-
- /// Allow diagnostics to interrupt the walk.
- WalkResult(Diagnostic &&) : result(Interrupt) {}
- WalkResult(InFlightDiagnostic &&) : result(Interrupt) {}
-
- bool operator==(const WalkResult &rhs) const { return result == rhs.result; }
- bool operator!=(const WalkResult &rhs) const { return result != rhs.result; }
-
- static WalkResult interrupt() { return {Interrupt}; }
- static WalkResult advance() { return {Advance}; }
- static WalkResult skip() { return {Skip}; }
-
- /// Returns true if the walk was interrupted.
- bool wasInterrupted() const { return result == Interrupt; }
-
- /// Returns true if the walk was skipped.
- bool wasSkipped() const { return result == Skip; }
-};
-
/// Traversal order for region, block and operation walk utilities.
enum class WalkOrder { PreOrder, PostOrder };
diff --git a/mlir/include/mlir/IR/StateStack.h b/mlir/include/mlir/Support/StateStack.h
similarity index 96%
rename from mlir/include/mlir/IR/StateStack.h
rename to mlir/include/mlir/Support/StateStack.h
index 6a22e3b0d00a4..ef0f5d198b456 100644
--- a/mlir/include/mlir/IR/StateStack.h
+++ b/mlir/include/mlir/Support/StateStack.h
@@ -12,11 +12,11 @@
//
//===----------------------------------------------------------------------===//
-#ifndef MLIR_IR_STACKFRAME_H
-#define MLIR_IR_STACKFRAME_H
+#ifndef MLIR_SUPPORT_STACKFRAME_H
+#define MLIR_SUPPORT_STACKFRAME_H
-#include "mlir/IR/Visitors.h"
#include "mlir/Support/TypeID.h"
+#include "mlir/Support/WalkResult.h"
#include <memory>
namespace mlir {
@@ -125,4 +125,4 @@ struct isa_impl<T, ::mlir::StateStackFrame> {
};
} // namespace llvm
-#endif // MLIR_IR_STACKFRAME_H
+#endif // MLIR_SUPPORT_STACKFRAME_H
diff --git a/mlir/include/mlir/Support/WalkResult.h b/mlir/include/mlir/Support/WalkResult.h
new file mode 100644
index 0000000000000..cd3b1e1562796
--- /dev/null
+++ b/mlir/include/mlir/Support/WalkResult.h
@@ -0,0 +1,59 @@
+//===- WalkResult.h - Status of completed walk ------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Result kind for completed walk.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_SUPPORT_WALKRESULT_H
+#define MLIR_SUPPORT_WALKRESULT_H
+
+#include "mlir/Support/LLVM.h"
+
+namespace mlir {
+class Diagnostic;
+class InFlightDiagnostic;
+
+/// A utility result that is used to signal how to proceed with an ongoing walk:
+/// * Interrupt: the walk will be interrupted and no more operations, regions
+/// or blocks will be visited.
+/// * Advance: the walk will continue.
+/// * Skip: the walk of the current operation, region or block and their
+/// nested elements that haven't been visited already will be skipped and will
+/// continue with the next operation, region or block.
+class WalkResult {
+ enum ResultEnum { Interrupt, Advance, Skip } result;
+
+public:
+ WalkResult(ResultEnum result = Advance) : result(result) {}
+
+ /// Allow LogicalResult to interrupt the walk on failure.
+ WalkResult(LogicalResult result)
+ : result(failed(result) ? Interrupt : Advance) {}
+
+ /// Allow diagnostics to interrupt the walk.
+ WalkResult(Diagnostic &&) : result(Interrupt) {}
+ WalkResult(InFlightDiagnostic &&) : result(Interrupt) {}
+
+ bool operator==(const WalkResult &rhs) const { return result == rhs.result; }
+ bool operator!=(const WalkResult &rhs) const { return result != rhs.result; }
+
+ static WalkResult interrupt() { return {Interrupt}; }
+ static WalkResult advance() { return {Advance}; }
+ static WalkResult skip() { return {Skip}; }
+
+ /// Returns true if the walk was interrupted.
+ bool wasInterrupted() const { return result == Interrupt; }
+
+ /// Returns true if the walk was skipped.
+ bool wasSkipped() const { return result == Skip; }
+};
+
+} // namespace mlir
+
+#endif
diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
index 197be5f30b5b0..79e8bb6add0da 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -16,9 +16,9 @@
#include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
#include "mlir/IR/Operation.h"
-#include "mlir/IR/StateStack.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/IR/Value.h"
+#include "mlir/Support/StateStack.h"
#include "mlir/Target/LLVMIR/Export.h"
#include "mlir/Target/LLVMIR/LLVMTranslationInterface.h"
#include "mlir/Target/LLVMIR/TypeToLLVM.h"
diff --git a/mlir/lib/IR/CMakeLists.txt b/mlir/lib/IR/CMakeLists.txt
index 997782df8c5f3..4cabac185171c 100644
--- a/mlir/lib/IR/CMakeLists.txt
+++ b/mlir/lib/IR/CMakeLists.txt
@@ -32,7 +32,6 @@ add_mlir_library(MLIRIR
PatternMatch.cpp
Region.cpp
RegionKindInterface.cpp
- StateStack.cpp
SymbolTable.cpp
TensorEncoding.cpp
Types.cpp
diff --git a/mlir/lib/Support/CMakeLists.txt b/mlir/lib/Support/CMakeLists.txt
index 488decd52ae64..02b6c694a28fd 100644
--- a/mlir/lib/Support/CMakeLists.txt
+++ b/mlir/lib/Support/CMakeLists.txt
@@ -11,6 +11,7 @@ add_mlir_library(MLIRSupport
FileUtilities.cpp
InterfaceSupport.cpp
RawOstreamExtras.cpp
+ StateStack.cpp
StorageUniquer.cpp
Timing.cpp
ToolUtilities.cpp
diff --git a/mlir/lib/IR/StateStack.cpp b/mlir/lib/Support/StateStack.cpp
similarity index 92%
rename from mlir/lib/IR/StateStack.cpp
rename to mlir/lib/Support/StateStack.cpp
index 22fdcd73c625b..a9bb3ffb2e1b0 100644
--- a/mlir/lib/IR/StateStack.cpp
+++ b/mlir/lib/Support/StateStack.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/IR/StateStack.h"
+#include "mlir/Support/StateStack.h"
namespace mlir {
More information about the Mlir-commits
mailing list