[Mlir-commits] [mlir] [mlir] Remove mlir-src-sharder dependency on MLIRSupport (PR #236978)

Fabrice de Gans llvmlistbot at llvm.org
Thu Oct 29 14:53:35 PDT 2026


https://github.com/Steelskin created https://github.com/llvm/llvm-project/pull/236978

When LLVM is built as a dylib, MLIRSupport depends on the LLVM dylib. This breaks mlir-src-sharder, which links LLVM statically due to being a native tablegen tool. This PR removes the dependency on MLIRSupport from mlir-src-sharder, following established precedent [1] in MLIR.

The effort to build LLVM as a dylib is tracked in #109483.

[1] mlir/lib/TableGen/CMakeLists.txt (b9a907d1336f)

>From 226d90c831c57a054af834299ddef537f3fa36b6 Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <fabrice at thebrowser.company>
Date: Thu, 29 Oct 2026 14:44:49 -0700
Subject: [PATCH] [mlir] Remove mlir-src-sharder dependency on MLIRSupport

When LLVM is built as a dylib, MLIRSupport depends on the LLVM dylib.
This breaks mlir-src-sharder, which links LLVM statically due to being
a native tablegen tool. This PR removes the dependency on MLIRSupport
from mlir-src-sharder, following established precedent [1] in MLIR.

The effort to build LLVM as a dylib is tracked in #109483.

[1] mlir/lib/TableGen/CMakeLists.txt (b9a907d1336f)
---
 mlir/tools/mlir-src-sharder/CMakeLists.txt    |  2 -
 .../mlir-src-sharder/mlir-src-sharder.cpp     | 41 ++++++++++---------
 2 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/mlir/tools/mlir-src-sharder/CMakeLists.txt b/mlir/tools/mlir-src-sharder/CMakeLists.txt
index b5d90cfe238ed3..116acf7e937ff9 100644
--- a/mlir/tools/mlir-src-sharder/CMakeLists.txt
+++ b/mlir/tools/mlir-src-sharder/CMakeLists.txt
@@ -1,5 +1,4 @@
 set(LLVM_LINK_COMPONENTS Support)
-set(LIBS MLIRSupport)
 
 add_tablegen(mlir-src-sharder MLIR_SRC_SHARDER
   DESTINATION "${MLIR_TOOLS_INSTALL_DIR}"
@@ -7,6 +6,5 @@ add_tablegen(mlir-src-sharder MLIR_SRC_SHARDER
   mlir-src-sharder.cpp)
 
 set_target_properties(mlir-src-sharder PROPERTIES FOLDER "MLIR/Tablegenning")
-target_link_libraries(mlir-src-sharder PRIVATE ${LIBS})
 
 mlir_check_all_link_libraries(mlir-src-sharder)
diff --git a/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp b/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp
index 9ec9b721502076..91da693790c8a3 100644
--- a/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp
+++ b/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "mlir/Support/FileUtilities.h"
 #include "mlir/Support/LLVM.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/ToolOutputFile.h"
@@ -26,16 +26,16 @@ static LogicalResult createDependencyFile(StringRef outputFilename,
     return failure();
   }
 
-  std::string errorMessage;
-  std::unique_ptr<llvm::ToolOutputFile> outputFile =
-      openOutputFile(dependencyFile, &errorMessage);
-  if (!outputFile) {
-    llvm::errs() << errorMessage << "\n";
+  std::error_code ec;
+  llvm::ToolOutputFile outputFile(dependencyFile, ec, llvm::sys::fs::OF_None);
+  if (ec) {
+    llvm::errs() << "cannot open output file '" << dependencyFile
+                 << "': " << ec.message() << "\n";
     return failure();
   }
 
-  outputFile->os() << outputFilename << ":\n";
-  outputFile->keep();
+  outputFile.os() << outputFilename << ":\n";
+  outputFile.keep();
   return success();
 }
 
@@ -76,11 +76,11 @@ int main(int argc, char **argv) {
   llvm::cl::ParseCommandLineOptions(argc, argv);
 
   // Open the input file.
-  std::string errorMessage;
-  std::unique_ptr<llvm::MemoryBuffer> inputFile =
-      openInputFile(inputFilename, &errorMessage);
-  if (!inputFile) {
-    llvm::errs() << errorMessage << "\n";
+  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> inputFile =
+      llvm::MemoryBuffer::getFileOrSTDIN(inputFilename);
+  if (std::error_code ec = inputFile.getError()) {
+    llvm::errs() << "cannot open input file '" << inputFilename
+                 << "': " << ec.message() << "\n";
     return 1;
   }
 
@@ -88,7 +88,7 @@ int main(int argc, char **argv) {
   std::string outputStr;
   llvm::raw_string_ostream os(outputStr);
   os << "#define GET_OP_DEFS_" << opShardIndex << "\n"
-     << inputFile->getBuffer();
+     << (*inputFile)->getBuffer();
 
   // Determine whether we need to write the output file.
   bool shouldWriteOutput = true;
@@ -104,14 +104,15 @@ int main(int argc, char **argv) {
 
   // Populate the output file if necessary.
   if (shouldWriteOutput) {
-    std::unique_ptr<llvm::ToolOutputFile> outputFile =
-        openOutputFile(outputFilename, &errorMessage);
-    if (!outputFile) {
-      llvm::errs() << errorMessage << "\n";
+    std::error_code ec;
+    llvm::ToolOutputFile outputFile(outputFilename, ec, llvm::sys::fs::OF_None);
+    if (ec) {
+      llvm::errs() << "cannot open output file '" << outputFilename
+                   << "': " << ec.message() << "\n";
       return 1;
     }
-    outputFile->os() << os.str();
-    outputFile->keep();
+    outputFile.os() << os.str();
+    outputFile.keep();
   }
 
   // Always write the depfile, even if the main output hasn't changed. If it's



More information about the Mlir-commits mailing list