Skip to content

[mlir] Move WalkResult to Support #145649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged

[mlir] Move WalkResult to Support #145649

merged 1 commit into from
Jun 25, 2025

Conversation

jpienaar
Copy link
Member

This also enables moving StateStack, both are relatively generic helper structs not tied to IR.

This also enables moving StateStack, both are relatively generic helper
structs not tied to IR.
@jpienaar jpienaar requested a review from ftynse June 25, 2025 07:56
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir:llvm mlir flang Flang issues not falling into any other category flang:fir-hlfir labels Jun 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 25, 2025

@llvm/pr-subscribers-mlir-core
@llvm/pr-subscribers-flang-fir-hlfir
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-llvm

Author: Jacques Pienaar (jpienaar)

Changes

This also enables moving StateStack, both are relatively generic helper structs not tied to IR.


Full diff: https://github.com/llvm/llvm-project/pull/145649.diff

9 Files Affected:

  • (modified) flang/lib/Lower/Bridge.cpp (+1-1)
  • (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+1-1)
  • (modified) mlir/include/mlir/IR/Visitors.h (+1-35)
  • (renamed) mlir/include/mlir/Support/StateStack.h (+4-4)
  • (added) mlir/include/mlir/Support/WalkResult.h (+59)
  • (modified) mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h (+1-1)
  • (modified) mlir/lib/IR/CMakeLists.txt (-1)
  • (modified) mlir/lib/Support/CMakeLists.txt (+1)
  • (renamed) mlir/lib/Support/StateStack.cpp (+1-1)
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 {
 

@jpienaar jpienaar merged commit d0469d1 into llvm:main Jun 25, 2025
13 checks passed
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
This also enables moving StateStack, both are relatively generic helper
structs not tied to IR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category mlir:core MLIR Core Infrastructure mlir:llvm mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants