diff --git a/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt b/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt --- a/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt +++ b/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt @@ -14,5 +14,5 @@ MLIRIR MLIRInferTypeOpInterface MLIRSupport - MLIRSparseTensorRuntime + MLIRSparseTensorEnums ) diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CMakeLists.txt b/mlir/lib/Dialect/SparseTensor/Transforms/CMakeLists.txt --- a/mlir/lib/Dialect/SparseTensor/Transforms/CMakeLists.txt +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CMakeLists.txt @@ -31,6 +31,7 @@ MLIRSCFTransforms MLIRSCFUtils MLIRSparseTensorDialect + MLIRSparseTensorEnums MLIRSparseTensorUtils MLIRTensorDialect MLIRTransforms diff --git a/mlir/lib/ExecutionEngine/CMakeLists.txt b/mlir/lib/ExecutionEngine/CMakeLists.txt --- a/mlir/lib/ExecutionEngine/CMakeLists.txt +++ b/mlir/lib/ExecutionEngine/CMakeLists.txt @@ -137,6 +137,7 @@ EXCLUDE_FROM_LIBMLIR LINK_LIBS PUBLIC + MLIRSparseTensorEnums MLIRSparseTensorRuntime ) set_property(TARGET mlir_c_runner_utils PROPERTY CXX_STANDARD 17) diff --git a/mlir/lib/ExecutionEngine/SparseTensor/CMakeLists.txt b/mlir/lib/ExecutionEngine/SparseTensor/CMakeLists.txt --- a/mlir/lib/ExecutionEngine/SparseTensor/CMakeLists.txt +++ b/mlir/lib/ExecutionEngine/SparseTensor/CMakeLists.txt @@ -1,3 +1,24 @@ +# This library is shared by both MLIRSparseTensorDialect and +# MLIRSparseTensorRuntime, so it must not depend on any of the MLIR/LLVM +# internals or else mlir_c_runner_utils will inherit that dependency. +# +# Because this is a header-only (`INTERFACE`) library, we cannot use +# the `add_mlir_library` function. So we do our best to replicate the +# relevant portions below. If doing so becomes too complicated, then +# we should adjust the `add_mlir_library` function to also work for +# `INTERFACE` libraries. +set(MLIRSparseTensorEnums_srcs + ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine/SparseTensor/Enums.h) +add_library(MLIRSparseTensorEnums INTERFACE ${MLIRSparseTensorEnums_srcs}) +if(MSVC_IDE OR XCODE) + set_source_files_properties(${MLIRSparseTensorEnums_srcs} + PROPERTIES HEADER_FILE_ONLY ON) +endif() +target_link_libraries(MLIRSparseTensorEnums INTERFACE mlir_float16_utils) +add_mlir_library_install(MLIRSparseTensorEnums) +set_property(TARGET MLIRSparseTensorEnums PROPERTY CXX_STANDARD 17) + + # Unlike mlir_float16_utils, mlir_c_runner_utils, etc, we do *not* make # this a shared library: because doing so causes issues when building # on Windows. In particular, various functions take/return `std::vector` @@ -13,7 +34,7 @@ EXCLUDE_FROM_LIBMLIR LINK_LIBS PUBLIC - mlir_float16_utils + MLIRSparseTensorEnums ) set_property(TARGET MLIRSparseTensorRuntime PROPERTY CXX_STANDARD 17) diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -2067,6 +2067,17 @@ deps = [":PassBaseTdFiles"], ) +# This library is shared by both SparseTensorDialect and +# SparseTensorRuntime, so it must not depend on any of the MLIR/LLVM +# internals or else mlir_c_runner_utils will inherit that dependency. +cc_library( + name = "SparseTensorEnums", + srcs = [], + hdrs = ["include/mlir/ExecutionEngine/SparseTensor/Enums.h"], + includes = ["include"], + deps = [":mlir_float16_utils"], +) + cc_library( name = "SparseTensorDialect", srcs = ["lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp"], @@ -2077,8 +2088,8 @@ ":IR", ":InferTypeOpInterface", ":SparseTensorAttrDefsIncGen", + ":SparseTensorEnums", ":SparseTensorOpsIncGen", - ":SparseTensorRuntime", "//llvm:Support", ], ) @@ -2129,8 +2140,8 @@ ":SCFDialect", ":SCFTransforms", ":SparseTensorDialect", + ":SparseTensorEnums", ":SparseTensorPassIncGen", - ":SparseTensorRuntime", ":SparseTensorUtils", ":Support", ":TensorDialect", @@ -6727,10 +6738,6 @@ # pragma, therefore it cannot be safely/correctly used across DLL boundaries. # Consequently, we avoid using the "mlir_xxx_utils" naming scheme, # since that is reserved/intended for shared libraries only. -# -# We relist Float16bits.h because Enums.h includes it; rather than -# forcing all direct-dependants state that they also directly-depend -# on :mlir_float16_utils (to satisfy the layering_check). cc_library( name = "SparseTensorRuntime", srcs = [ @@ -6739,20 +6746,16 @@ "lib/ExecutionEngine/SparseTensor/Storage.cpp", ], hdrs = [ - "include/mlir/ExecutionEngine/Float16bits.h", "include/mlir/ExecutionEngine/SparseTensor/COO.h", "include/mlir/ExecutionEngine/SparseTensor/CheckedMul.h", - "include/mlir/ExecutionEngine/SparseTensor/Enums.h", "include/mlir/ExecutionEngine/SparseTensor/ErrorHandling.h", "include/mlir/ExecutionEngine/SparseTensor/File.h", "include/mlir/ExecutionEngine/SparseTensor/Storage.h", ], includes = ["include"], - deps = [":mlir_float16_utils"], + deps = [":SparseTensorEnums"], ) -# We relist Enums.h because SparseTensorRuntime.h includes/reexports it -# as part of the public API. cc_library( name = "_mlir_c_runner_utils", srcs = [ @@ -6762,11 +6765,13 @@ hdrs = [ "include/mlir/ExecutionEngine/CRunnerUtils.h", "include/mlir/ExecutionEngine/Msan.h", - "include/mlir/ExecutionEngine/SparseTensor/Enums.h", "include/mlir/ExecutionEngine/SparseTensorRuntime.h", ], includes = ["include"], - deps = [":SparseTensorRuntime"], + deps = [ + ":SparseTensorEnums", + ":SparseTensorRuntime", + ], ) # Indirection to avoid 'libmlir_c_runner_utils.so' filename clash.