[Mlir-commits] [mlir] [MLIR] Enable multi-buffer support in loadSourceFileBuffer (PR #187803)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Mar 20 14:50:45 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Vinicius Silva (viniciusfdasilva)
<details>
<summary>Changes</summary>
This PR implements multi-buffer support in the `loadSourceFileBuffer` utility, transitioning the infrastructure from a single-input constraint to a system capable of managing multiple source files within a single `llvm::SourceMgr`.
* Removed the single-buffer constraint: Deleted the check that limited `loadSourceFileBuffer` to a single active buffer.
* Implemented `SMLoc` support: Added an optional `includeLoc` parameter, enabling the `SourceMgr` to track and display *"included from"* stack traces for nested files.
* Enhanced error reporting: Refactored the error handling to include system-level error messages (`std::error_code`), providing clearer diagnostics for file I/O failures.
---
Full diff: https://github.com/llvm/llvm-project/pull/187803.diff
1 Files Affected:
- (modified) mlir/lib/Parser/Parser.cpp (+8-10)
``````````diff
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 310680bcfb34f..37dcc9b261a3c 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -73,19 +73,17 @@ LogicalResult mlir::parseSourceFile(llvm::StringRef filename, Block *block,
static LogicalResult loadSourceFileBuffer(llvm::StringRef filename,
llvm::SourceMgr &sourceMgr,
- MLIRContext *ctx) {
- if (sourceMgr.getNumBuffers() != 0) {
- // TODO: Extend to support multiple buffers.
- return emitError(mlir::UnknownLoc::get(ctx),
- "only main buffer parsed at the moment");
- }
+ MLIRContext *ctx,
+ SMLoc includeLoc = SMLoc()) {
+
auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename);
- if (fileOrErr.getError())
+ if (std::error_code ec = fileOrErr.getError()) {
return emitError(mlir::UnknownLoc::get(ctx),
- "could not open input file " + filename);
+ "could not open input file '" + filename + "': " + ec.message());
+ }
- // Load the MLIR source file.
- sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), SMLoc());
+ sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), includeLoc);
+
return success();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/187803
More information about the Mlir-commits
mailing list