Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiver Riddle <riddleriver@gmail.com>2022-11-13 01:38:27 +0300
committerRiver Riddle <riddleriver@gmail.com>2022-11-13 02:05:13 +0300
commit858a6ec3af29a6483f013cc382de7860c0f33351 (patch)
tree1cefe0b8db95f6a8e0f2047974459b29c4eed199
parent46fab767882d48d2dd46a497baa3197bf9a98ab2 (diff)
[mlir] Add openInputFile overload that accepts the expected alignment
This just forwards to the alignment parameter on `MemoryBuffer::getFileOrSTDIN`.
-rw-r--r--mlir/include/mlir/Support/FileUtilities.h7
-rw-r--r--mlir/lib/Support/FileUtilities.cpp19
2 files changed, 23 insertions, 3 deletions
diff --git a/mlir/include/mlir/Support/FileUtilities.h b/mlir/include/mlir/Support/FileUtilities.h
index 1a1b036bca51..fca17d82a2bf 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 a20ad485064c..060ac08b4bb7 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) {