[Mlir-commits] [mlir] [mlir] Remove mlir-src-sharder dependency on MLIRSupport (PR #236978)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 29 14:54:15 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Fabrice de Gans (Steelskin)
<details>
<summary>Changes</summary>
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)
---
Full diff: https://github.com/llvm/llvm-project/pull/236978.diff
2 Files Affected:
- (modified) mlir/tools/mlir-src-sharder/CMakeLists.txt (-2)
- (modified) mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp (+21-20)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/236978
More information about the Mlir-commits
mailing list