From 81c5c822c32ec08096931ac652e7b4fd90083c5f Mon Sep 17 00:00:00 2001 From: wang2yn84 Date: Tue, 24 Jun 2025 17:22:55 -0700 Subject: [PATCH] [MLIR] Fix circular 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. This change improves build performance and reduces compilation issues. --- 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 8506b9a984e58..336a6f82319e6 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 60b6366c184d4..8575d8cf352fd 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 44972fafe7fed..6a22e3b0d00a4 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 79e8bb6add0da..197be5f30b5b0 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 4cabac185171c..997782df8c5f3 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 a9bb3ffb2e1b0..22fdcd73c625b 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 02b6c694a28fd..488decd52ae64 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 e7b289efc6e69..a0b72b9709695 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",