[Mlir-commits] [mlir] 858a6ec - [mlir] Add openInputFile overload that accepts the expected alignment
River Riddle
llvmlistbot at llvm.org
Sat Nov 12 15:06:03 PST 2022
Author: River Riddle
Date: 2022-11-12T15:05:13-08:00
New Revision: 858a6ec3af29a6483f013cc382de7860c0f33351
URL: https://github.com/llvm/llvm-project/commit/858a6ec3af29a6483f013cc382de7860c0f33351
DIFF: https://github.com/llvm/llvm-project/commit/858a6ec3af29a6483f013cc382de7860c0f33351.diff
LOG: [mlir] Add openInputFile overload that accepts the expected alignment
This just forwards to the alignment parameter on `MemoryBuffer::getFileOrSTDIN`.
Added:
Modified:
mlir/include/mlir/Support/FileUtilities.h
mlir/lib/Support/FileUtilities.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Support/FileUtilities.h b/mlir/include/mlir/Support/FileUtilities.h
index 1a1b036bca51f..fca17d82a2bf2 100644
--- a/mlir/include/mlir/Support/FileUtilities.h
+++ b/mlir/include/mlir/Support/FileUtilities.h
@@ -17,6 +17,7 @@
#include <string>
namespace llvm {
+struct Align;
class MemoryBuffer;
class ToolOutputFile;
class StringRef;
@@ -29,6 +30,12 @@ namespace mlir {
std::unique_ptr<llvm::MemoryBuffer>
openInputFile(llvm::StringRef inputFilename,
std::string *errorMessage = nullptr);
+/// Open the file specified by its name for reading, with the given buffer
+/// alignment constraint. Write the error message to `errorMessage` if errors
+/// occur and `errorMessage` is not nullptr.
+std::unique_ptr<llvm::MemoryBuffer>
+openInputFile(llvm::StringRef inputFilename, llvm::Align alignment,
+ std::string *errorMessage = nullptr);
/// Open the file specified by its name for writing. Write the error message to
/// `errorMessage` if errors occur and `errorMessage` is not nullptr.
diff --git a/mlir/lib/Support/FileUtilities.cpp b/mlir/lib/Support/FileUtilities.cpp
index a20ad485064c8..060ac08b4bb7a 100644
--- a/mlir/lib/Support/FileUtilities.cpp
+++ b/mlir/lib/Support/FileUtilities.cpp
@@ -18,9 +18,12 @@
using namespace mlir;
-std::unique_ptr<llvm::MemoryBuffer>
-mlir::openInputFile(StringRef inputFilename, std::string *errorMessage) {
- auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(inputFilename);
+static std::unique_ptr<llvm::MemoryBuffer>
+openInputFileImpl(StringRef inputFilename, std::string *errorMessage,
+ Optional<llvm::Align> alignment) {
+ auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(
+ inputFilename, /*IsText=*/false, /*RequiresNullTerminator=*/true,
+ alignment);
if (std::error_code error = fileOrErr.getError()) {
if (errorMessage)
*errorMessage = "cannot open input file '" + inputFilename.str() +
@@ -30,6 +33,16 @@ mlir::openInputFile(StringRef inputFilename, std::string *errorMessage) {
return std::move(*fileOrErr);
}
+std::unique_ptr<llvm::MemoryBuffer>
+mlir::openInputFile(StringRef inputFilename, std::string *errorMessage) {
+ return openInputFileImpl(inputFilename, errorMessage,
+ /*alignment=*/llvm::None);
+}
+std::unique_ptr<llvm::MemoryBuffer>
+mlir::openInputFile(llvm::StringRef inputFilename, llvm::Align alignment,
+ std::string *errorMessage) {
+ return openInputFileImpl(inputFilename, errorMessage, alignment);
+}
std::unique_ptr<llvm::ToolOutputFile>
mlir::openOutputFile(StringRef outputFilename, std::string *errorMessage) {
More information about the Mlir-commits
mailing list