From 77af8bff97a0b20dac9ff9a95385d036da7d8ba5 Mon Sep 17 00:00:00 2001 From: Lance Wang Date: Tue, 24 Jun 2025 21:00:13 -0700 Subject: [PATCH] [mlir]Moves the StateStack to IR folder from Support folder. (#145598) [MLIR] Fix circular dependency introduced in In https://github.com/llvm/llvm-project/pull/144897. This PR is to break the dependency. by moving StateStack to IR folder This commit resolves a circular dependency issue between mlir/Support and mlir/IR: - Move StateStack.h and StateStack.cpp from Support to IR folder - Update CMakeLists.txt files to reflect the new locations - Update Bazel BUILD file to maintain correct dependencies - Update includes in affected files (flang, Target/LLVMIR) The circular dependency was caused by StateStack.h depending on IR/Visitors.h while other IR files depended on Support. Moving StateStack to IR eliminates this cycle while maintaining proper separation of concerns. --- flang/lib/Lower/Bridge.cpp | 2 +- flang/lib/Lower/OpenMP/OpenMP.cpp | 2 +- mlir/include/mlir/{Support => IR}/StateStack.h | 6 +++--- mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h | 2 +- mlir/lib/IR/CMakeLists.txt | 1 + mlir/lib/{Support => IR}/StateStack.cpp | 2 +- mlir/lib/Support/CMakeLists.txt | 1 - utils/bazel/llvm-project-overlay/mlir/BUILD.bazel | 6 +----- 8 files changed, 9 insertions(+), 13 deletions(-) rename mlir/include/mlir/{Support => IR}/StateStack.h (97%) rename mlir/lib/{Support => IR}/StateStack.cpp (92%) diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index 8506b9a984e5..336a6f82319e 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 60b6366c184d..8575d8cf352f 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/Support/StateStack.h" +#include "mlir/IR/StateStack.h" #include "mlir/Transforms/RegionUtils.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Frontend/OpenMP/OMPConstants.h" diff --git a/mlir/include/mlir/Support/StateStack.h b/mlir/include/mlir/IR/StateStack.h similarity index 97% rename from mlir/include/mlir/Support/StateStack.h rename to mlir/include/mlir/IR/StateStack.h index 44972fafe7fe..6a22e3b0d00a 100644 --- a/mlir/include/mlir/Support/StateStack.h +++ b/mlir/include/mlir/IR/StateStack.h @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#ifndef MLIR_SUPPORT_STACKFRAME_H -#define MLIR_SUPPORT_STACKFRAME_H +#ifndef MLIR_IR_STACKFRAME_H +#define MLIR_IR_STACKFRAME_H #include "mlir/IR/Visitors.h" #include "mlir/Support/TypeID.h" @@ -125,4 +125,4 @@ struct isa_impl { }; } // namespace llvm -#endif // MLIR_SUPPORT_STACKFRAME_H +#endif // MLIR_IR_STACKFRAME_H diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h index 79e8bb6add0d..197be5f30b5b 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 4cabac185171..997782df8c5f 100644 --- a/mlir/lib/IR/CMakeLists.txt +++ b/mlir/lib/IR/CMakeLists.txt @@ -32,6 +32,7 @@ add_mlir_library(MLIRIR PatternMatch.cpp Region.cpp RegionKindInterface.cpp + StateStack.cpp SymbolTable.cpp TensorEncoding.cpp Types.cpp diff --git a/mlir/lib/Support/StateStack.cpp b/mlir/lib/IR/StateStack.cpp similarity index 92% rename from mlir/lib/Support/StateStack.cpp rename to mlir/lib/IR/StateStack.cpp index a9bb3ffb2e1b..22fdcd73c625 100644 --- a/mlir/lib/Support/StateStack.cpp +++ b/mlir/lib/IR/StateStack.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "mlir/Support/StateStack.h" +#include "mlir/IR/StateStack.h" namespace mlir { diff --git a/mlir/lib/Support/CMakeLists.txt b/mlir/lib/Support/CMakeLists.txt index 02b6c694a28f..488decd52ae6 100644 --- a/mlir/lib/Support/CMakeLists.txt +++ b/mlir/lib/Support/CMakeLists.txt @@ -11,7 +11,6 @@ add_mlir_library(MLIRSupport FileUtilities.cpp InterfaceSupport.cpp RawOstreamExtras.cpp - StateStack.cpp StorageUniquer.cpp Timing.cpp ToolUtilities.cpp diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel index e7b289efc6e6..a0b72b970969 100644 --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -4845,11 +4845,7 @@ cc_library( ]), hdrs = glob(["include/mlir/Support/*.h"]), includes = ["include"], - deps = [ - "//llvm:Support", - "//mlir:IR", - ], -) + deps = ["//llvm:Support"],) cc_library( name = "Debug",