[clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] [NFC][SystemZ][z/OS] Replace isText with OpenFlags in MemoryBuffer::getFile()/getFileOrSTDIN() (PR #228189)

Abhina Sree via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 06:28:14 PDT 2026


https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/228189

>From 2fa0aa0bdba14c06c3c264e541f533c52128bab9 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Thu, 1 Oct 2026 14:26:25 -0400
Subject: [PATCH] Replace IsText with OpenFlags in MemoryBuffer getFile
 functions

---
 .../clang-include-fixer/FuzzySymbolIndex.cpp  |  4 ++-
 .../clang-include-fixer/YamlSymbolIndex.cpp   |  2 +-
 .../tool/FindAllSymbolsMain.cpp               |  3 +-
 .../tool/ClangIncludeFixer.cpp                |  4 ++-
 .../ConfusableTable/BuildConfusableTable.cpp  |  3 +-
 clang/lib/Driver/OffloadBundler.cpp           | 11 ++++----
 .../JSONFormat/JSONFormatImpl.cpp             |  3 +-
 clang/lib/Tooling/JSONCompilationDatabase.cpp |  3 +-
 clang/tools/clang-format/ClangFormat.cpp      |  4 +--
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 12 ++++----
 clang/tools/driver/cc1as_main.cpp             |  3 +-
 .../JSONFormatTest/JSONFormatTest.cpp         |  6 ++--
 .../PreambleInNamedModulesTest.cpp            |  2 +-
 lld/COFF/Driver.cpp                           | 12 ++++----
 lld/COFF/DriverUtils.cpp                      |  2 +-
 lld/COFF/SymbolTable.cpp                      |  2 +-
 lld/ELF/InputFiles.cpp                        |  2 +-
 .../Plugins/ObjectFile/PDB/ObjectFilePDB.cpp  |  2 +-
 .../DWARF/DWARFASTParserClangTests.cpp        |  9 ++++--
 .../TestingSupport/TestUtilities.cpp          |  6 ++--
 llvm/benchmarks/RuntimeLibcalls.cpp           |  4 ++-
 llvm/include/llvm/Support/MemoryBuffer.h      |  9 +++---
 llvm/lib/Analysis/IR2Vec.cpp                  |  3 +-
 llvm/lib/AsmParser/Parser.cpp                 |  5 ++--
 llvm/lib/BinaryFormat/Magic.cpp               |  2 +-
 llvm/lib/CAS/OnDiskGraphDB.cpp                |  4 +--
 llvm/lib/CodeGen/MIR2Vec.cpp                  |  4 ++-
 llvm/lib/CodeGen/MIRParser/MIRParser.cpp      |  4 ++-
 llvm/lib/DTLTO/DTLTO.cpp                      |  2 +-
 llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp      |  4 ++-
 llvm/lib/DebugInfo/PDB/Native/InputFile.cpp   |  2 +-
 .../DebugInfo/PDB/Native/NativeSession.cpp    |  2 +-
 llvm/lib/Debuginfod/Debuginfod.cpp            |  3 +-
 llvm/lib/FuzzMutate/FuzzerCLI.cpp             |  2 +-
 llvm/lib/IRReader/IRReader.cpp                |  3 +-
 llvm/lib/LTO/LTOCodeGenerator.cpp             |  2 +-
 llvm/lib/Object/Archive.cpp                   |  3 +-
 llvm/lib/Object/Binary.cpp                    |  2 +-
 .../ProfileData/Coverage/CoverageMapping.cpp  |  2 +-
 llvm/lib/ProfileData/GCOV.cpp                 |  2 +-
 llvm/lib/ProfileData/MemProfReader.cpp        |  5 ++--
 llvm/lib/Support/MemoryBuffer.cpp             | 28 +++++++++----------
 llvm/lib/Support/SourceMgr.cpp                |  2 +-
 llvm/lib/TableGen/Main.cpp                    |  5 ++--
 llvm/lib/Target/DirectX/DXContainerPDB.cpp    |  2 +-
 llvm/lib/Testing/Support/SupportHelpers.cpp   |  2 +-
 .../llvm-dlltool/DlltoolDriver.cpp            |  2 +-
 llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp   |  7 +++--
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp    |  2 +-
 llvm/tools/dsymutil/DebugMap.cpp              |  4 ++-
 llvm/tools/dsymutil/dsymutil.cpp              |  2 +-
 llvm/tools/lli/lli.cpp                        |  2 +-
 llvm/tools/llvm-ar/llvm-ar.cpp                |  4 +--
 llvm/tools/llvm-cas-fuzzer/cas-fuzzer.cpp     |  2 +-
 llvm/tools/llvm-cov/gcov.cpp                  |  4 +--
 .../llvm-ctxprof-util/llvm-ctxprof-util.cpp   |  3 +-
 llvm/tools/llvm-cvtres/llvm-cvtres.cpp        |  4 +--
 llvm/tools/llvm-cxxmap/llvm-cxxmap.cpp        |  6 ++--
 .../llvm-debuginfod-find.cpp                  |  2 +-
 llvm/tools/llvm-exegesis/llvm-exegesis.cpp    |  4 +--
 llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp    |  4 +--
 llvm/tools/llvm-ifs/llvm-ifs.cpp              |  3 +-
 .../llvm-libtool-darwin.cpp                   |  2 +-
 llvm/tools/llvm-link/llvm-link.cpp            |  5 ++--
 llvm/tools/llvm-mc/llvm-mc.cpp                |  3 +-
 llvm/tools/llvm-objdump/SourcePrinter.cpp     |  3 +-
 llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp      |  2 +-
 llvm/tools/llvm-rc/ResourceFileWriter.cpp     |  2 +-
 llvm/tools/llvm-rc/llvm-rc.cpp                |  4 +--
 llvm/tools/llvm-readobj/llvm-readobj.cpp      |  2 +-
 llvm/tools/llvm-readtapi/llvm-readtapi.cpp    |  2 +-
 llvm/tools/llvm-reduce/ReducerWorkItem.cpp    |  4 ++-
 llvm/tools/llvm-strings/llvm-strings.cpp      |  3 +-
 llvm/tools/obj2yaml/obj2yaml.cpp              |  2 +-
 llvm/tools/sanstats/sanstats.cpp              |  2 +-
 llvm/tools/yaml2obj/yaml2obj.cpp              |  2 +-
 .../unittests/DebugInfo/PDB/TpiStreamTest.cpp |  2 +-
 llvm/unittests/Support/raw_ostream_test.cpp   |  2 +-
 llvm/utils/FileCheck/FileCheck.cpp            |  5 ++--
 llvm/utils/split-file/split-file.cpp          |  2 +-
 mlir/lib/Support/FileUtilities.cpp            |  2 +-
 mlir/lib/Target/LLVM/ROCDL/Target.cpp         |  2 +-
 mlir/tools/mlir-pdll/mlir-pdll.cpp            |  5 ++--
 .../mlir-src-sharder/mlir-src-sharder.cpp     |  5 ++--
 84 files changed, 183 insertions(+), 138 deletions(-)

diff --git a/clang-tools-extra/clang-include-fixer/FuzzySymbolIndex.cpp b/clang-tools-extra/clang-include-fixer/FuzzySymbolIndex.cpp
index 98987ad380196f..60842d95d0d024 100644
--- a/clang-tools-extra/clang-include-fixer/FuzzySymbolIndex.cpp
+++ b/clang-tools-extra/clang-include-fixer/FuzzySymbolIndex.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 #include "FuzzySymbolIndex.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Regex.h"
 
 using clang::find_all_symbols::SymbolAndSignals;
@@ -131,7 +132,8 @@ FuzzySymbolIndex::queryRegexp(const std::vector<std::string> &Tokens) {
 
 llvm::Expected<std::unique_ptr<FuzzySymbolIndex>>
 FuzzySymbolIndex::createFromYAML(StringRef FilePath) {
-  auto Buffer = llvm::MemoryBuffer::getFile(FilePath, /*IsText=*/true);
+  auto Buffer =
+      llvm::MemoryBuffer::getFile(FilePath, llvm::sys::fs::OF_TextWithCRLF);
   if (!Buffer)
     return llvm::errorCodeToError(Buffer.getError());
   return std::make_unique<MemSymbolIndex>(
diff --git a/clang-tools-extra/clang-include-fixer/YamlSymbolIndex.cpp b/clang-tools-extra/clang-include-fixer/YamlSymbolIndex.cpp
index 7f570ee917197b..3ab3daaf8dc32d 100644
--- a/clang-tools-extra/clang-include-fixer/YamlSymbolIndex.cpp
+++ b/clang-tools-extra/clang-include-fixer/YamlSymbolIndex.cpp
@@ -22,7 +22,7 @@ namespace include_fixer {
 
 llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
 YamlSymbolIndex::createFromFile(llvm::StringRef FilePath) {
-  auto Buffer = llvm::MemoryBuffer::getFile(FilePath, /*IsText=*/true);
+  auto Buffer = llvm::MemoryBuffer::getFile(FilePath, sys::fs::OF_TextWithCRLF);
   if (!Buffer)
     return Buffer.getError();
 
diff --git a/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp b/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
index 995006e183569e..3a66c2d895ed9a 100644
--- a/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
+++ b/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
@@ -95,7 +95,8 @@ bool Merge(llvm::StringRef MergeDir, llvm::StringRef OutputFile) {
       // Parse YAML files in parallel.
       Pool.async(
           [&AddSymbols](std::string Path) {
-            auto Buffer = llvm::MemoryBuffer::getFile(Path, /*IsText=*/true);
+            auto Buffer =
+                llvm::MemoryBuffer::getFile(Path, sys::fs::OF_TextWithCRLF);
             if (!Buffer) {
               llvm::errs() << "Can't open " << Path << "\n";
               return;
diff --git a/clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp b/clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp
index f983b9d590542e..386132c685c8ab 100644
--- a/clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp
+++ b/clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp
@@ -19,6 +19,7 @@
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/YAMLTraits.h"
 
@@ -413,7 +414,8 @@ int includeFixerMain(int argc, const char **argv) {
       llvm::errs() << llvm::toString(InsertStyle.takeError()) << "\n";
       return 1;
     }
-    auto Buffer = llvm::MemoryBuffer::getFile(FilePath, /*IsText=*/true);
+    auto Buffer =
+        llvm::MemoryBuffer::getFile(FilePath, sys::fs::OF_TextWithCRLF);
     if (!Buffer) {
       errs() << "Couldn't open file: " + FilePath.str() + ": "
              << Buffer.getError().message() + "\n";
diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp b/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
index ccabe31ea6b807..27f3e14bd30d08 100644
--- a/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
@@ -10,6 +10,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -23,7 +24,7 @@ struct ConfusableEntry {
 } // namespace
 
 int main(int argc, char *argv[]) {
-  auto ErrorOrBuffer = MemoryBuffer::getFile(argv[1], true);
+  auto ErrorOrBuffer = MemoryBuffer::getFile(argv[1], sys::fs::OF_TextWithCRLF);
   if (!ErrorOrBuffer)
     return 1;
   std::unique_ptr<MemoryBuffer> Buffer = std::move(ErrorOrBuffer.get());
diff --git a/clang/lib/Driver/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp
index 2d0c326ab6f406..3935884e22f098 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -1025,7 +1025,7 @@ Error OffloadBundler::ListBundleIDsInFile(
 
   // Open Input file.
   ErrorOr<std::unique_ptr<MemoryBuffer>> Contents =
-      MemoryBuffer::getFileOrSTDIN(InputFileName, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(InputFileName, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = Contents.getError())
     return createFileError(InputFileName, EC);
 
@@ -1195,7 +1195,7 @@ Error OffloadBundler::BundleFiles() {
   InputBuffers.reserve(BundlerConfig.InputFileNames.size());
   for (auto &I : BundlerConfig.InputFileNames) {
     ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
-        MemoryBuffer::getFileOrSTDIN(I, /*IsText=*/true);
+        MemoryBuffer::getFileOrSTDIN(I, sys::fs::OF_TextWithCRLF);
     if (std::error_code EC = CodeOrErr.getError())
       return createFileError(I, EC);
     InputBuffers.emplace_back(std::move(*CodeOrErr));
@@ -1265,7 +1265,7 @@ Error OffloadBundler::UnbundleFiles() {
   // Open Input file.
   ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
       MemoryBuffer::getFileOrSTDIN(BundlerConfig.InputFileNames.front(),
-                                   /*IsText=*/true);
+                                   sys::fs::OF_Text);
   if (std::error_code EC = CodeOrErr.getError())
     return createFileError(BundlerConfig.InputFileNames.front(), EC);
 
@@ -1493,7 +1493,8 @@ CheckHeterogeneousArchive(StringRef ArchiveName,
                           const OffloadBundlerConfig &BundlerConfig) {
   std::vector<std::unique_ptr<MemoryBuffer>> ArchiveBuffers;
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
-      MemoryBuffer::getFileOrSTDIN(ArchiveName, true, false);
+      MemoryBuffer::getFileOrSTDIN(ArchiveName, sys::fs::OF_TextWithCRLF,
+                                   false);
   if (std::error_code EC = BufOrErr.getError())
     return createFileError(ArchiveName, EC);
 
@@ -1588,7 +1589,7 @@ Error OffloadBundler::UnbundleArchive() {
   }
 
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
-      MemoryBuffer::getFileOrSTDIN(IFName, true, false);
+      MemoryBuffer::getFileOrSTDIN(IFName, sys::fs::OF_TextWithCRLF, false);
   if (std::error_code EC = BufOrErr.getError())
     return createFileError(BundlerConfig.InputFileNames.front(), EC);
 
diff --git a/clang/lib/ScalableStaticAnalysis/Core/Serialization/JSONFormat/JSONFormatImpl.cpp b/clang/lib/ScalableStaticAnalysis/Core/Serialization/JSONFormat/JSONFormatImpl.cpp
index b19849233f0f8f..9b89b057850f91 100644
--- a/clang/lib/ScalableStaticAnalysis/Core/Serialization/JSONFormat/JSONFormatImpl.cpp
+++ b/clang/lib/ScalableStaticAnalysis/Core/Serialization/JSONFormat/JSONFormatImpl.cpp
@@ -55,7 +55,8 @@ llvm::Expected<Value> readJSON(llvm::StringRef Path) {
         .build();
   }
 
-  auto BufferOrError = llvm::MemoryBuffer::getFile(Path, /*IsText=*/true);
+  auto BufferOrError =
+      llvm::MemoryBuffer::getFile(Path, llvm::sys::fs::OF_TextWithCRLF);
   if (!BufferOrError) {
     const std::error_code EC = BufferOrError.getError();
     return ErrorBuilder::create(EC, ErrorMessages::FailedToReadFile, Path,
diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index 0efa75970d9864..c42233a2fa9e8a 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
@@ -190,7 +191,7 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath,
                                       JSONCommandLineSyntax Syntax) {
   // Don't mmap: if we're a long-lived process, the build system may overwrite.
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> DatabaseBuffer =
-      llvm::MemoryBuffer::getFile(FilePath, /*IsText=*/false,
+      llvm::MemoryBuffer::getFile(FilePath, llvm::sys::fs::OF_None,
                                   /*RequiresNullTerminator=*/true,
                                   /*IsVolatile=*/true);
   if (std::error_code Result = DatabaseBuffer.getError()) {
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index d465ed57f0033e..a89544a8ce7a7c 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -410,7 +410,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
       !OutputXML && Inplace
           ? MemoryBuffer::getFileAsStream(FileName)
-          : MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/true);
+          : MemoryBuffer::getFileOrSTDIN(FileName, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = CodeOrErr.getError()) {
     errs() << FileName << ": " << EC.message() << "\n";
     return true;
@@ -555,7 +555,7 @@ static int dumpConfig() {
     // Read in the code in case the filename alone isn't enough to detect the
     // language.
     ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
-        MemoryBuffer::getFileOrSTDIN(FileNames[0], /*IsText=*/true);
+        MemoryBuffer::getFileOrSTDIN(FileNames[0], sys::fs::OF_TextWithCRLF);
     if (std::error_code EC = CodeOrErr.getError()) {
       llvm::errs() << EC.message() << "\n";
       return 1;
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 778f73909665dc..453cc9018a5cee 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -318,14 +318,14 @@ class ResourceDirectoryCache {
     };
     if (llvm::sys::ExecuteAndWait(ClangBinaryPath, PrintResourceDirArgs, {},
                                   Redirects)) {
-      auto ErrorBuf =
-          llvm::MemoryBuffer::getFile(ErrorFile.c_str(), /*IsText=*/true);
+      auto ErrorBuf = llvm::MemoryBuffer::getFile(
+          ErrorFile.c_str(), llvm::sys::fs::OF_TextWithCRLF);
       llvm::errs() << ErrorBuf.get()->getBuffer();
       return "";
     }
 
-    auto OutputBuf =
-        llvm::MemoryBuffer::getFile(OutputFile.c_str(), /*IsText=*/true);
+    auto OutputBuf = llvm::MemoryBuffer::getFile(
+        OutputFile.c_str(), llvm::sys::fs::OF_TextWithCRLF);
     if (!OutputBuf)
       return "";
     StringRef Output = OutputBuf.get()->getBuffer().rtrim('\n');
@@ -1114,8 +1114,8 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
         std::unique_ptr<llvm::MemoryBuffer> TU;
         std::optional<llvm::MemoryBufferRef> TUBuffer;
         if (!TranslationUnitFile.empty()) {
-          auto MaybeTU =
-              llvm::MemoryBuffer::getFile(TranslationUnitFile, /*IsText=*/true);
+          auto MaybeTU = llvm::MemoryBuffer::getFile(
+              TranslationUnitFile, llvm::sys::fs::OF_TextWithCRLF);
           if (!MaybeTU) {
             llvm::errs() << "cannot open input translation unit: "
                          << MaybeTU.getError().message() << "\n";
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index 077cd69ce4e2ca..a24a205f9b04d6 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -442,7 +442,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
   ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer = [&] {
     // FIXME(sandboxing): Make this a proper input file.
     auto BypassSandbox = sys::sandbox::scopedDisable();
-    return MemoryBuffer::getFileOrSTDIN(Opts.InputFile, /*IsText=*/true);
+    return MemoryBuffer::getFileOrSTDIN(Opts.InputFile,
+                                        sys::fs::OF_TextWithCRLF);
   }();
 
   if (std::error_code EC = Buffer.getError()) {
diff --git a/clang/unittests/ScalableStaticAnalysis/Serialization/JSONFormatTest/JSONFormatTest.cpp b/clang/unittests/ScalableStaticAnalysis/Serialization/JSONFormatTest/JSONFormatTest.cpp
index 777625dc9fed7e..9454171bdbf4be 100644
--- a/clang/unittests/ScalableStaticAnalysis/Serialization/JSONFormatTest/JSONFormatTest.cpp
+++ b/clang/unittests/ScalableStaticAnalysis/Serialization/JSONFormatTest/JSONFormatTest.cpp
@@ -123,7 +123,8 @@ bool JSONFormatTest::permissionsAreEnforced() const {
                  // silently suppressing the test.
   }
 
-  auto Buffer = llvm::MemoryBuffer::getFile(ProbePath, /*IsText=*/true);
+  auto Buffer =
+      llvm::MemoryBuffer::getFile(ProbePath, llvm::sys::fs::OF_TextWithCRLF);
   bool Enforced = !Buffer; // If open failed, permissions are enforced.
 
   // Restore permissions so TearDown can clean up the temp directory.
@@ -137,7 +138,8 @@ llvm::Expected<llvm::json::Value>
 JSONFormatTest::readJSONFromFile(llvm::StringRef FileName) const {
   PathString FilePath = makePath(FileName);
 
-  auto BufferOrError = llvm::MemoryBuffer::getFile(FilePath, /*IsText=*/true);
+  auto BufferOrError =
+      llvm::MemoryBuffer::getFile(FilePath, llvm::sys::fs::OF_TextWithCRLF);
   if (!BufferOrError) {
     return llvm::createStringError(BufferOrError.getError(),
                                    "Failed to read file: %s", FilePath.c_str());
diff --git a/clang/unittests/Serialization/PreambleInNamedModulesTest.cpp b/clang/unittests/Serialization/PreambleInNamedModulesTest.cpp
index b826f20ce4d70e..3ed48fa2668e92 100644
--- a/clang/unittests/Serialization/PreambleInNamedModulesTest.cpp
+++ b/clang/unittests/Serialization/PreambleInNamedModulesTest.cpp
@@ -93,7 +93,7 @@ export using ::E;
   ASSERT_TRUE(Invocation);
 
   llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> ContentsBuffer =
-      llvm::MemoryBuffer::getFile(MainFilePath, /*IsText=*/true);
+      llvm::MemoryBuffer::getFile(MainFilePath, sys::fs::OF_TextWithCRLF);
   EXPECT_TRUE(ContentsBuffer);
   std::unique_ptr<MemoryBuffer> Buffer = std::move(*ContentsBuffer);
 
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index ecbb5e9fff4e19..b468672dfaa4ee 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -164,7 +164,7 @@ static std::future<MBErrPair> createFutureForFile(std::string path,
   auto strategy = std::launch::deferred;
 #endif
   return std::async(strategy, [=]() {
-    auto mbOrErr = MemoryBuffer::getFile(path, /*IsText=*/false,
+    auto mbOrErr = MemoryBuffer::getFile(path, sys::fs::OF_None,
                                          /*RequiresNullTerminator=*/false);
     if (!mbOrErr)
       return MBErrPair{nullptr, mbOrErr.getError()};
@@ -422,7 +422,7 @@ void LinkerDriver::enqueuePath(StringRef path, bool lazy, InputOpt inputOpt) {
       // before something we can find with an architecture, we won't find the
       // winsysroot file.
       if (std::optional<StringRef> retryPath = findFileIfNew(pathStr)) {
-        auto retryMb = MemoryBuffer::getFile(*retryPath, /*IsText=*/false,
+        auto retryMb = MemoryBuffer::getFile(*retryPath, sys::fs::OF_None,
                                              /*RequiresNullTerminator=*/false);
         ec = retryMb.getError();
         if (!ec) {
@@ -1114,7 +1114,7 @@ void LinkerDriver::createImportLibrary(bool asLib) {
   // If the import library already exists, replace it only if the contents
   // have changed.
   ErrorOr<std::unique_ptr<MemoryBuffer>> oldBuf = MemoryBuffer::getFile(
-      path, /*IsText=*/false, /*RequiresNullTerminator=*/false);
+      path, sys::fs::OF_None, /*RequiresNullTerminator=*/false);
   if (!oldBuf) {
     checkError(writeImportLibrary(libName, path, exports, ctx.config.machine,
                                   ctx.config.mingw, nativeExports));
@@ -1135,7 +1135,7 @@ void LinkerDriver::createImportLibrary(bool asLib) {
   }
 
   std::unique_ptr<MemoryBuffer> newBuf = check(MemoryBuffer::getFile(
-      tmpName, /*IsText=*/false, /*RequiresNullTerminator=*/false));
+      tmpName, sys::fs::OF_None, /*RequiresNullTerminator=*/false));
   if ((*oldBuf)->getBuffer() != newBuf->getBuffer()) {
     oldBuf->reset();
     checkError(errorCodeToError(sys::fs::rename(tmpName, path)));
@@ -1181,7 +1181,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
   // Open a file.
   StringRef path = arg.substr(1);
   std::unique_ptr<MemoryBuffer> mb =
-      CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
+      CHECK(MemoryBuffer::getFile(path, sys::fs::OF_None,
                                   /*RequiresNullTerminator=*/false,
                                   /*IsVolatile=*/true),
             "could not open " + path);
@@ -1209,7 +1209,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
 
 void LinkerDriver::parseCallGraphFile(StringRef path) {
   std::unique_ptr<MemoryBuffer> mb =
-      CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
+      CHECK(MemoryBuffer::getFile(path, sys::fs::OF_None,
                                   /*RequiresNullTerminator=*/false,
                                   /*IsVolatile=*/true),
             "could not open " + path);
diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp
index 265ddee6d85572..220183ec9d7a92 100644
--- a/lld/COFF/DriverUtils.cpp
+++ b/lld/COFF/DriverUtils.cpp
@@ -421,7 +421,7 @@ class TemporaryFile {
   // is called (you cannot remove an opened file on Windows.)
   std::unique_ptr<MemoryBuffer> getMemoryBuffer() {
     // IsVolatile=true forces MemoryBuffer to not use mmap().
-    return CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
+    return CHECK(MemoryBuffer::getFile(path, sys::fs::OF_None,
                                        /*RequiresNullTerminator=*/false,
                                        /*IsVolatile=*/true),
                  "could not open " + path);
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index ea5bdbc0be4890..400d02899f1fc5 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -1336,7 +1336,7 @@ void SymbolTable::assignExportOrdinals() {
 void SymbolTable::parseModuleDefs(StringRef path) {
   llvm::TimeTraceScope timeScope("Parse def file");
   std::unique_ptr<MemoryBuffer> mb =
-      CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
+      CHECK(MemoryBuffer::getFile(path, sys::fs::OF_None,
                                   /*RequiresNullTerminator=*/false,
                                   /*IsVolatile=*/true),
             "could not open " + path);
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 4af0898cef6078..7759458e93944b 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -245,7 +245,7 @@ std::optional<MemoryBufferRef> elf::readFile(Ctx &ctx, StringRef path) {
   Log(ctx) << path;
   ctx.arg.dependencyFiles.insert(llvm::CachedHashString(path));
 
-  auto mbOrErr = MemoryBuffer::getFile(path, /*IsText=*/false,
+  auto mbOrErr = MemoryBuffer::getFile(path, sys::fs::OF_None,
                                        /*RequiresNullTerminator=*/false);
   if (auto ec = mbOrErr.getError()) {
     ErrAlways(ctx) << "cannot open " << path << ": " << ec.message();
diff --git a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
index 840169c563a9c8..93abafcfc96478 100644
--- a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
+++ b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
@@ -175,7 +175,7 @@ ObjectFilePDB::loadPDBFile(std::string PdbPath,
   if (ec || magic != llvm::file_magic::pdb)
     return nullptr;
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ErrorOrBuffer =
-      llvm::MemoryBuffer::getFile(PdbPath, /*IsText=*/false,
+      llvm::MemoryBuffer::getFile(PdbPath, llvm::sys::fs::OF_None,
                                   /*RequiresNullTerminator=*/false);
   if (!ErrorOrBuffer)
     return nullptr;
diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
index 4d4dc578166946..9beffcc516f3de 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
@@ -581,7 +581,8 @@ TEST_F(ExtractIntFromFormValueTest, TestUnsignedInt) {
 TEST_F(DWARFASTParserClangTests, TestDefaultTemplateParamParsing) {
   // Tests parsing DW_AT_default_value for template parameters.
   auto BufferOrError = llvm::MemoryBuffer::getFile(
-      GetInputFilePath("DW_AT_default_value-test.yaml"), /*IsText=*/true);
+      GetInputFilePath("DW_AT_default_value-test.yaml"),
+      llvm::sys::fs::OF_TextWithCRLF);
   ASSERT_TRUE(BufferOrError);
 
   DWARFASTParserClangYAMLTester tester(BufferOrError.get()->getBuffer());
@@ -625,7 +626,8 @@ TEST_F(DWARFASTParserClangTests, TestSpecDeclExistsError) {
   // Tests that parsing a ClassTemplateSpecializationDecl that already exists
   // is handled gracefully.
   auto BufferOrError = llvm::MemoryBuffer::getFile(
-      GetInputFilePath("DW_AT_spec_decl_exists-test.yaml"), /*IsText=*/true);
+      GetInputFilePath("DW_AT_spec_decl_exists-test.yaml"),
+      llvm::sys::fs::OF_TextWithCRLF);
   ASSERT_TRUE(BufferOrError);
   DWARFASTParserClangYAMLTester tester(BufferOrError.get()->getBuffer());
   DWARFDIE cu_die = tester.GetCUDIE();
@@ -2122,7 +2124,8 @@ TEST_F(DWARFASTParserClangTests,
 TEST_F(DWARFASTParserClangTests, TestRustVariantMember) {
   // Tests that 128-bit discriminants are output to variant names correctly.
   auto yamldata = llvm::MemoryBuffer::getFile(
-      GetInputFilePath("DW_TAG_variant_rust-test.yaml"), /*IsText=*/true);
+      GetInputFilePath("DW_TAG_variant_rust-test.yaml"),
+      llvm::sys::fs::OF_TextWithCRLF);
   ASSERT_TRUE(yamldata);
 
   DWARFASTParserClangYAMLTester tester(yamldata->get()->getBuffer());
diff --git a/lldb/unittests/TestingSupport/TestUtilities.cpp b/lldb/unittests/TestingSupport/TestUtilities.cpp
index d164c227afb9eb..825a9eecbb495d 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -45,9 +45,9 @@ llvm::Expected<TestFile> TestFile::fromYaml(llvm::StringRef Yaml) {
 }
 
 llvm::Expected<TestFile> TestFile::fromYamlFile(const llvm::Twine &Name) {
-  auto BufferOrError =
-      llvm::MemoryBuffer::getFile(GetInputFilePath(Name), /*IsText=*/false,
-                                  /*RequiresNullTerminator=*/false);
+  auto BufferOrError = llvm::MemoryBuffer::getFile(
+      GetInputFilePath(Name), llvm::sys::fs::OF_None,
+      /*RequiresNullTerminator=*/false);
   if (!BufferOrError)
     return llvm::errorCodeToError(BufferOrError.getError());
   return fromYaml(BufferOrError.get()->getBuffer());
diff --git a/llvm/benchmarks/RuntimeLibcalls.cpp b/llvm/benchmarks/RuntimeLibcalls.cpp
index 707bdca7ceab76..2a3e219df0501d 100644
--- a/llvm/benchmarks/RuntimeLibcalls.cpp
+++ b/llvm/benchmarks/RuntimeLibcalls.cpp
@@ -10,6 +10,7 @@
 #include "benchmark/benchmark.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/LineIterator.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/TargetParser/Triple.h"
@@ -45,7 +46,8 @@ static std::vector<std::string> getRandomFuncNames() {
 
 #ifdef SYMBOL_TEST_DATA_FILE
 static std::vector<std::string> readSymbolsFromFile(StringRef InputFile) {
-  auto BufOrError = MemoryBuffer::getFileOrSTDIN(InputFile, /*IsText=*/true);
+  auto BufOrError =
+      MemoryBuffer::getFileOrSTDIN(InputFile, sys::fs::OF_TextWithCRLF);
   if (!BufOrError) {
     reportFatalUsageError("failed to open \'" + Twine(InputFile) +
                           "\': " + BufOrError.getError().message());
diff --git a/llvm/include/llvm/Support/MemoryBuffer.h b/llvm/include/llvm/Support/MemoryBuffer.h
index ea911681bd7760..586221578f2715 100644
--- a/llvm/include/llvm/Support/MemoryBuffer.h
+++ b/llvm/include/llvm/Support/MemoryBuffer.h
@@ -22,6 +22,7 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/File.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include <cstddef>
 #include <cstdint>
@@ -86,8 +87,7 @@ class LLVM_ABI MemoryBuffer {
   /// Open the specified file as a MemoryBuffer, returning a new MemoryBuffer
   /// if successful, otherwise returning null.
   ///
-  /// \param IsText Set to true to indicate that the file should be read in
-  /// text mode.
+  /// \param Flags, e.g. \c sys::fs::OF_Text to open in text mode.
   ///
   /// \param IsVolatile Set to true to indicate that the contents of the file
   /// can change outside the user's control, e.g. when libclang tries to parse
@@ -96,7 +96,7 @@ class LLVM_ABI MemoryBuffer {
   /// \param Alignment Set to indicate that the buffer should be aligned to at
   /// least the specified alignment.
   static ErrorOr<std::unique_ptr<MemoryBuffer>>
-  getFile(const Twine &Filename, bool IsText = false,
+  getFile(const Twine &Filename, sys::fs::OpenFlags Flags = sys::fs::OF_None,
           bool RequiresNullTerminator = true, bool IsVolatile = false,
           std::optional<Align> Alignment = std::nullopt);
 
@@ -148,7 +148,8 @@ class LLVM_ABI MemoryBuffer {
   /// Open the specified file as a MemoryBuffer, or open stdin if the Filename
   /// is "-".
   static ErrorOr<std::unique_ptr<MemoryBuffer>>
-  getFileOrSTDIN(const Twine &Filename, bool IsText = false,
+  getFileOrSTDIN(const Twine &Filename,
+                 sys::fs::OpenFlags Flags = sys::fs::OF_None,
                  bool RequiresNullTerminator = true,
                  std::optional<Align> Alignment = std::nullopt);
 
diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp
index 1c11fbe0f849f8..87031b7205475d 100644
--- a/llvm/lib/Analysis/IR2Vec.cpp
+++ b/llvm/lib/Analysis/IR2Vec.cpp
@@ -23,6 +23,7 @@
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/MemoryBuffer.h"
 
@@ -483,7 +484,7 @@ using VocabMap = std::map<std::string, Embedding>;
 Error readVocabularyFromFile(StringRef VocabFilePath, VocabMap &OpcVocab,
                              VocabMap &TypeVocab, VocabMap &ArgVocab) {
   auto BufOrError =
-      MemoryBuffer::getFileOrSTDIN(VocabFilePath, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(VocabFilePath, sys::fs::OF_TextWithCRLF);
   if (!BufOrError)
     return createFileError(VocabFilePath, BufOrError.getError());
 
diff --git a/llvm/lib/AsmParser/Parser.cpp b/llvm/lib/AsmParser/Parser.cpp
index d52141d158122f..6336835c28d02a 100644
--- a/llvm/lib/AsmParser/Parser.cpp
+++ b/llvm/lib/AsmParser/Parser.cpp
@@ -16,6 +16,7 @@
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ModuleSummaryIndex.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 #include <algorithm>
@@ -68,7 +69,7 @@ std::unique_ptr<Module> llvm::parseAssemblyFile(StringRef Filename,
                                                 LLVMContext &Context,
                                                 SlotMapping *Slots) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
-      MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(Filename, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = FileOrErr.getError()) {
     Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
                        "Could not open input file: " + EC.message());
@@ -111,7 +112,7 @@ parseAssemblyFileWithIndex(StringRef Filename, SMDiagnostic &Err,
                            bool UpgradeDebugInfo,
                            DataLayoutCallbackTy DataLayoutCallback) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
-      MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(Filename, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = FileOrErr.getError()) {
     Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
                        "Could not open input file: " + EC.message());
diff --git a/llvm/lib/BinaryFormat/Magic.cpp b/llvm/lib/BinaryFormat/Magic.cpp
index 0786c4b9889fbf..bc39e0423d8bf1 100644
--- a/llvm/lib/BinaryFormat/Magic.cpp
+++ b/llvm/lib/BinaryFormat/Magic.cpp
@@ -284,7 +284,7 @@ file_magic llvm::identify_magic(StringRef Magic) {
 }
 
 std::error_code llvm::identify_magic(const Twine &Path, file_magic &Result) {
-  auto FileOrError = MemoryBuffer::getFile(Path, /*IsText=*/false,
+  auto FileOrError = MemoryBuffer::getFile(Path, /*Flags=*/sys::fs::OF_None,
                                            /*RequiresNullTerminator=*/false);
   if (!FileOrError)
     return FileOrError.getError();
diff --git a/llvm/lib/CAS/OnDiskGraphDB.cpp b/llvm/lib/CAS/OnDiskGraphDB.cpp
index ffec3c3dbe8ae2..843d56e39b2190 100644
--- a/llvm/lib/CAS/OnDiskGraphDB.cpp
+++ b/llvm/lib/CAS/OnDiskGraphDB.cpp
@@ -993,7 +993,7 @@ Error OnDiskGraphDB::validate(bool Deep, HashingFuncT Hasher) const {
       // If need to validate the content of the file later, just load the
       // buffer here. Otherwise, just check the existance of the file.
       if (Deep) {
-        auto File = MemoryBuffer::getFile(Path, /*IsText=*/false,
+        auto File = MemoryBuffer::getFile(Path, sys::fs::OF_None,
                                           /*RequiresNullTerminator=*/false);
         if (!File || !*File)
           return formatError("record file \'" + Path + "\' does not exist");
@@ -1529,7 +1529,7 @@ std::unique_ptr<MemoryBuffer> StandaloneDataInMemory::getStandaloneMemoryBuffer(
                       IndexOffset, Path);
   auto BypassSandbox = sys::sandbox::scopedDisable();
   ErrorOr<std::unique_ptr<MemoryBuffer>> Mapped =
-      MemoryBuffer::getFile(Path, /*IsText=*/false,
+      MemoryBuffer::getFile(Path, sys::fs::OF_None,
                             /*RequiresNullTerminator=*/false,
                             /*IsVolatile=*/false);
   if (!Mapped)
diff --git a/llvm/lib/CodeGen/MIR2Vec.cpp b/llvm/lib/CodeGen/MIR2Vec.cpp
index 30f30ec57020d7..39020d5fe5621e 100644
--- a/llvm/lib/CodeGen/MIR2Vec.cpp
+++ b/llvm/lib/CodeGen/MIR2Vec.cpp
@@ -19,6 +19,7 @@
 #include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Errc.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Regex.h"
 
@@ -482,7 +483,8 @@ Error MIR2VecVocabProvider::readVocabulary(VocabMap &OpcodeVocab,
         "MIR2Vec vocabulary file path not specified; set it "
         "using --mir2vec-vocab-path");
 
-  auto BufOrError = MemoryBuffer::getFileOrSTDIN(VocabFile, /*IsText=*/true);
+  auto BufOrError =
+      MemoryBuffer::getFileOrSTDIN(VocabFile, sys::fs::OF_TextWithCRLF);
   if (!BufOrError)
     return createFileError(VocabFile, BufOrError.getError());
 
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index 26af6ef073082d..94ea55a7d464eb 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -32,6 +32,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ValueSymbolTable.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/LineIterator.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SMLoc.h"
@@ -1370,7 +1371,8 @@ bool MIRParser::parseMachineFunctions(Module &M, ModuleAnalysisManager &MAM) {
 std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(
     StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
     std::function<void(Function &)> ProcessIRFunction) {
-  auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
+  auto FileOrErr =
+      MemoryBuffer::getFileOrSTDIN(Filename, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = FileOrErr.getError()) {
     Error = SMDiagnostic(Filename, SourceMgr::DK_Error,
                          "could not open input file: " + EC.message());
diff --git a/llvm/lib/DTLTO/DTLTO.cpp b/llvm/lib/DTLTO/DTLTO.cpp
index 669ba75c80d4b6..b38f7cc798745c 100644
--- a/llvm/lib/DTLTO/DTLTO.cpp
+++ b/llvm/lib/DTLTO/DTLTO.cpp
@@ -304,7 +304,7 @@ Error lto::DTLTO::addObjectFilesToLink() {
     // Load the native object from a file into a memory buffer
     // and store its contents in the output buffer.
     auto ObjFileMbOrErr =
-        MemoryBuffer::getFile(Job.NativeObjectPath, /*IsText=*/false,
+        MemoryBuffer::getFile(Job.NativeObjectPath, sys::fs::OF_None,
                               /*RequiresNullTerminator=*/false);
     if (std::error_code EC = ObjFileMbOrErr.getError())
       return make_error<StringError>(
diff --git a/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp b/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp
index 561ef48bf757bc..e3340883c95aef 100644
--- a/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp
+++ b/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp
@@ -12,6 +12,7 @@
 #include "llvm/DebugInfo/GSYM/GsymCreator.h"
 #include "llvm/DebugInfo/GSYM/GsymDataExtractor.h"
 #include "llvm/MC/StringTableBuilder.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/InterleavedRange.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/Support/YAMLTraits.h"
@@ -149,7 +150,8 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionYAML)
 
 Error CallSiteInfoLoader::loadYAML(StringRef YAMLFile) {
   // Step 1: Read YAML file
-  auto BufferOrError = MemoryBuffer::getFile(YAMLFile, /*IsText=*/true);
+  auto BufferOrError =
+      MemoryBuffer::getFile(YAMLFile, sys::fs::OF_TextWithCRLF);
   if (!BufferOrError)
     return errorCodeToError(BufferOrError.getError());
 
diff --git a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
index 49be0edc33a108..2d390fe746be3b 100644
--- a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
@@ -335,7 +335,7 @@ Expected<InputFile> InputFile::open(StringRef Path, bool AllowUnknownFile) {
         formatv("File {0} is not a supported file type", Path),
         inconvertibleErrorCode());
 
-  auto Result = MemoryBuffer::getFile(Path, /*IsText=*/false,
+  auto Result = MemoryBuffer::getFile(Path, /*Flags=*/sys::fs::OF_None,
                                       /*RequiresNullTerminator=*/false);
   if (!Result)
     return make_error<StringError>(
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
index aedbbe7f2e5167..0488dc6a3d8934 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
@@ -103,7 +103,7 @@ static Error validatePdbMagic(StringRef PdbPath) {
 static Expected<std::unique_ptr<PDBFile>>
 loadPdbFile(StringRef PdbPath, std::unique_ptr<BumpPtrAllocator> &Allocator) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
-      MemoryBuffer::getFile(PdbPath, /*IsText=*/false,
+      MemoryBuffer::getFile(PdbPath, /*Flags=*/sys::fs::OF_None,
                             /*RequiresNullTerminator=*/false);
   if (!ErrorOrBuffer)
     return make_error<RawError>(ErrorOrBuffer.getError());
diff --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp
index f6b278f1bbda23..c9a5a60a826501 100644
--- a/llvm/lib/Debuginfod/Debuginfod.cpp
+++ b/llvm/lib/Debuginfod/Debuginfod.cpp
@@ -35,6 +35,7 @@
 #include "llvm/Support/Caching.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
@@ -189,7 +190,7 @@ static SmallVector<std::string, 0> getHeaders() {
   if (!Filename)
     return {};
   ErrorOr<std::unique_ptr<MemoryBuffer>> HeadersFile =
-      MemoryBuffer::getFile(Filename, /*IsText=*/true);
+      MemoryBuffer::getFile(Filename, sys::fs::OF_TextWithCRLF);
   if (!HeadersFile)
     return {};
 
diff --git a/llvm/lib/FuzzMutate/FuzzerCLI.cpp b/llvm/lib/FuzzMutate/FuzzerCLI.cpp
index 504532865440fe..71ead5cad59df8 100644
--- a/llvm/lib/FuzzMutate/FuzzerCLI.cpp
+++ b/llvm/lib/FuzzMutate/FuzzerCLI.cpp
@@ -156,7 +156,7 @@ int llvm::runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne,
       continue;
     }
 
-    auto BufOrErr = MemoryBuffer::getFile(Arg, /*IsText=*/false,
+    auto BufOrErr = MemoryBuffer::getFile(Arg, /*Flags=*/sys::fs::OF_None,
                                           /*RequiresNullTerminator=*/false);
     if (std::error_code EC = BufOrErr.getError()) {
       errs() << "Error reading file: " << Arg << ": " << EC.message() << "\n";
diff --git a/llvm/lib/IRReader/IRReader.cpp b/llvm/lib/IRReader/IRReader.cpp
index 8b9c41acd42359..f554ecc2229268 100644
--- a/llvm/lib/IRReader/IRReader.cpp
+++ b/llvm/lib/IRReader/IRReader.cpp
@@ -14,6 +14,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/PassTimingInfo.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/Timer.h"
@@ -96,7 +97,7 @@ std::unique_ptr<Module> llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err,
                                           ParserCallbacks Callbacks,
                                           AsmParserContext *ParserContext) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
-      MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(Filename, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = FileOrErr.getError()) {
     Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
                        "Could not open input file: " + EC.message());
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 6cb30123c9572d..98d80cef2baf92 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -346,7 +346,7 @@ LTOCodeGenerator::compileOptimized() {
 
   // read .o file into memory buffer
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = MemoryBuffer::getFile(
-      name, /*IsText=*/false, /*RequiresNullTerminator=*/false);
+      name, sys::fs::OF_None, /*RequiresNullTerminator=*/false);
   if (std::error_code EC = BufferOrErr.getError()) {
     emitError(EC.message());
     sys::fs::remove(NativeObjectPath);
diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp
index be0dcaab9ba5ec..803ab7d95dbd46 100644
--- a/llvm/lib/Object/Archive.cpp
+++ b/llvm/lib/Object/Archive.cpp
@@ -701,7 +701,8 @@ Expected<StringRef> Archive::Child::getBuffer() const {
     return FullNameOrErr.takeError();
   const std::string &FullName = *FullNameOrErr;
   ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =
-      MemoryBuffer::getFile(FullName, false, /*RequiresNullTerminator=*/false);
+      MemoryBuffer::getFile(FullName, /*Flags=*/sys::fs::OF_None,
+                            /*RequiresNullTerminator=*/false);
   if (std::error_code EC = Buf.getError())
     return errorCodeToError(EC);
   Parent->ThinBuffers.push_back(std::move(*Buf));
diff --git a/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp
index 30414257fa90be..d94c662954f0fb 100644
--- a/llvm/lib/Object/Binary.cpp
+++ b/llvm/lib/Object/Binary.cpp
@@ -110,7 +110,7 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
 Expected<OwningBinary<Binary>>
 object::createBinary(StringRef Path, LLVMContext *Context, bool InitContent) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
-      MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/false,
+      MemoryBuffer::getFileOrSTDIN(Path, /*Flags=*/sys::fs::OF_None,
                                    /*RequiresNullTerminator=*/false);
   if (std::error_code EC = FileOrErr.getError())
     return errorCodeToError(EC);
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index cbb048d15bca24..6f4d95ace604f5 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -1015,7 +1015,7 @@ Error CoverageMapping::loadFromFile(
     CoverageMapping &Coverage, bool &DataFound,
     SmallVectorImpl<object::BuildID> *FoundBinaryIDs) {
   auto CovMappingBufOrErr = MemoryBuffer::getFileOrSTDIN(
-      Filename, /*IsText=*/false, /*RequiresNullTerminator=*/false);
+      Filename, sys::fs::OF_None, /*RequiresNullTerminator=*/false);
   if (std::error_code EC = CovMappingBufOrErr.getError())
     return createFileError(Filename, errorCodeToError(EC));
   MemoryBufferRef CovMappingBufRef =
diff --git a/llvm/lib/ProfileData/GCOV.cpp b/llvm/lib/ProfileData/GCOV.cpp
index 7d0a243d023885..e3b43f12d13e43 100644
--- a/llvm/lib/ProfileData/GCOV.cpp
+++ b/llvm/lib/ProfileData/GCOV.cpp
@@ -614,7 +614,7 @@ class LineConsumer {
     // Open source files without requiring a NUL terminator. The concurrent
     // modification may nullify the NUL terminator condition.
     ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
-        MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/false,
+        MemoryBuffer::getFileOrSTDIN(Filename, /*Flags=*/sys::fs::OF_None,
                                      /*RequiresNullTerminator=*/false);
     if (std::error_code EC = BufferOrErr.getError()) {
       errs() << Filename << ": " << EC.message() << "\n";
diff --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp
index c476e1a08cd59d..e0eaabdd1ee827 100644
--- a/llvm/lib/ProfileData/MemProfReader.cpp
+++ b/llvm/lib/ProfileData/MemProfReader.cpp
@@ -39,6 +39,7 @@
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 
@@ -817,7 +818,7 @@ Error RawMemProfReader::readNextRecord(
 
 Expected<std::unique_ptr<YAMLMemProfReader>>
 YAMLMemProfReader::create(const Twine &Path) {
-  auto BufferOr = MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/true);
+  auto BufferOr = MemoryBuffer::getFileOrSTDIN(Path, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = BufferOr.getError())
     return report(errorCodeToError(EC), Path.getSingleStringRef());
 
@@ -833,7 +834,7 @@ YAMLMemProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
 }
 
 bool YAMLMemProfReader::hasFormat(const StringRef Path) {
-  auto BufferOr = MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/true);
+  auto BufferOr = MemoryBuffer::getFileOrSTDIN(Path, sys::fs::OF_TextWithCRLF);
   if (!BufferOr)
     return false;
 
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp
index 9c49c143cf01c2..ae28f2cd6e53b0 100644
--- a/llvm/lib/Support/MemoryBuffer.cpp
+++ b/llvm/lib/Support/MemoryBuffer.cpp
@@ -121,8 +121,8 @@ class MemoryBufferMem : public MB {
 template <typename MB>
 static ErrorOr<std::unique_ptr<MB>>
 getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
-           bool IsText, bool RequiresNullTerminator, bool IsVolatile,
-           std::optional<Align> Alignment);
+           sys::fs::OpenFlags Flags, bool RequiresNullTerminator,
+           bool IsVolatile, std::optional<Align> Alignment);
 
 std::unique_ptr<MemoryBuffer>
 MemoryBuffer::getMemBuffer(StringRef InputData, StringRef BufferName,
@@ -159,7 +159,7 @@ MemoryBuffer::getMemBufferCopy(StringRef InputData, const Twine &BufferName) {
 }
 
 ErrorOr<std::unique_ptr<MemoryBuffer>>
-MemoryBuffer::getFileOrSTDIN(const Twine &Filename, bool IsText,
+MemoryBuffer::getFileOrSTDIN(const Twine &Filename, sys::fs::OpenFlags Flags,
                              bool RequiresNullTerminator,
                              std::optional<Align> Alignment) {
   sys::sandbox::violationIfEnabled();
@@ -169,7 +169,7 @@ MemoryBuffer::getFileOrSTDIN(const Twine &Filename, bool IsText,
 
   if (NameRef == "-")
     return getSTDIN();
-  return getFile(Filename, IsText, RequiresNullTerminator,
+  return getFile(Filename, Flags, RequiresNullTerminator,
                  /*IsVolatile=*/false, Alignment);
 }
 
@@ -179,7 +179,7 @@ MemoryBuffer::getFileSlice(const Twine &FilePath, uint64_t MapSize,
                            std::optional<Align> Alignment) {
   sys::sandbox::violationIfEnabled();
 
-  return getFileAux<MemoryBuffer>(FilePath, MapSize, Offset, /*IsText=*/false,
+  return getFileAux<MemoryBuffer>(FilePath, MapSize, Offset, sys::fs::OF_None,
                                   /*RequiresNullTerminator=*/false, IsVolatile,
                                   Alignment);
 }
@@ -262,13 +262,13 @@ getMemoryBufferForStream(sys::fs::file_t FD, const Twine &BufferName) {
 }
 
 ErrorOr<std::unique_ptr<MemoryBuffer>>
-MemoryBuffer::getFile(const Twine &Filename, bool IsText,
+MemoryBuffer::getFile(const Twine &Filename, sys::fs::OpenFlags Flags,
                       bool RequiresNullTerminator, bool IsVolatile,
                       std::optional<Align> Alignment) {
   sys::sandbox::violationIfEnabled();
 
-  return getFileAux<MemoryBuffer>(Filename, /*MapSize=*/-1, /*Offset=*/0,
-                                  IsText, RequiresNullTerminator, IsVolatile,
+  return getFileAux<MemoryBuffer>(Filename, /*MapSize=*/-1, /*Offset=*/0, Flags,
+                                  RequiresNullTerminator, IsVolatile,
                                   Alignment);
 }
 
@@ -281,10 +281,10 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
 template <typename MB>
 static ErrorOr<std::unique_ptr<MB>>
 getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
-           bool IsText, bool RequiresNullTerminator, bool IsVolatile,
-           std::optional<Align> Alignment) {
-  Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead(
-      Filename, IsText ? sys::fs::OF_TextWithCRLF : sys::fs::OF_None);
+           sys::fs::OpenFlags Flags, bool RequiresNullTerminator,
+           bool IsVolatile, std::optional<Align> Alignment) {
+  Expected<sys::fs::file_t> FDOrErr =
+      sys::fs::openNativeFileForRead(Filename, Flags);
   if (!FDOrErr)
     return errorToErrorCode(FDOrErr.takeError());
   sys::fs::file_t FD = *FDOrErr;
@@ -300,7 +300,7 @@ WritableMemoryBuffer::getFile(const Twine &Filename, bool IsVolatile,
   sys::sandbox::violationIfEnabled();
 
   return getFileAux<WritableMemoryBuffer>(
-      Filename, /*MapSize=*/-1, /*Offset=*/0, /*IsText=*/false,
+      Filename, /*MapSize=*/-1, /*Offset=*/0, sys::fs::OF_None,
       /*RequiresNullTerminator=*/false, IsVolatile, Alignment);
 }
 
@@ -311,7 +311,7 @@ WritableMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize,
   sys::sandbox::violationIfEnabled();
 
   return getFileAux<WritableMemoryBuffer>(
-      Filename, MapSize, Offset, /*IsText=*/false,
+      Filename, MapSize, Offset, sys::fs::OF_None,
       /*RequiresNullTerminator=*/false, IsVolatile, Alignment);
 }
 
diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp
index 2c40d313bb2674..8f66b0b281b4bb 100644
--- a/llvm/lib/Support/SourceMgr.cpp
+++ b/llvm/lib/Support/SourceMgr.cpp
@@ -73,7 +73,7 @@ SourceMgr::OpenIncludeFile(const std::string &Filename,
   auto GetFile = [this, RequiresNullTerminator](StringRef Path) {
     return FS ? FS->getBufferForFile(Path, /*FileSize=*/-1,
                                      RequiresNullTerminator)
-              : MemoryBuffer::getFile(Path, /*IsText=*/false,
+              : MemoryBuffer::getFile(Path, sys::fs::OF_None,
                                       RequiresNullTerminator);
   };
 
diff --git a/llvm/lib/TableGen/Main.cpp b/llvm/lib/TableGen/Main.cpp
index b86f5f48707b05..5c17454124b7b1 100644
--- a/llvm/lib/TableGen/Main.cpp
+++ b/llvm/lib/TableGen/Main.cpp
@@ -121,7 +121,8 @@ static int WriteOutput(const char *argv0, StringRef Filename,
     // Only updates the real output file if there are any differences.
     // This prevents recompilation of all the files depending on it if there
     // aren't any.
-    if (auto ExistingOrErr = MemoryBuffer::getFile(Filename, /*IsText=*/true))
+    if (auto ExistingOrErr =
+            MemoryBuffer::getFile(Filename, sys::fs::OF_TextWithCRLF))
       if (std::move(ExistingOrErr.get())->getBuffer() == Content)
         return 0;
   }
@@ -148,7 +149,7 @@ int llvm::TableGenMain(const char *argv0, MultiFileTableGenMainFn MainFn) {
 
   Timer.startTimer("Parse, build records");
   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
-      MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(InputFilename, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = FileOrErr.getError())
     return reportError(argv0, "Could not open input file '" + InputFilename +
                                   "': " + EC.message() + "\n");
diff --git a/llvm/lib/Target/DirectX/DXContainerPDB.cpp b/llvm/lib/Target/DirectX/DXContainerPDB.cpp
index 13f57baaaa032a..19dd3884e250e2 100644
--- a/llvm/lib/Target/DirectX/DXContainerPDB.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerPDB.cpp
@@ -185,7 +185,7 @@ bool DXContainerPDB::runOnModule(Module &M) {
     return false;
 
   ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getFile(
-      DebugFileName, /*IsText=*/false, /*RequiresNullTerminator=*/false);
+      DebugFileName, sys::fs::OF_None, /*RequiresNullTerminator=*/false);
   if (!Buf)
     reportFatalInternalError("Failed to read PDB for PRIV embedding");
 
diff --git a/llvm/lib/Testing/Support/SupportHelpers.cpp b/llvm/lib/Testing/Support/SupportHelpers.cpp
index e9e44fd115100e..70b74a92f78c89 100644
--- a/llvm/lib/Testing/Support/SupportHelpers.cpp
+++ b/llvm/lib/Testing/Support/SupportHelpers.cpp
@@ -39,7 +39,7 @@ SmallString<128> llvm::unittest::getInputFileDirectory(const char *Argv0) {
 
   EXPECT_TRUE(Found) << "Unit test source directory file does not exist.";
 
-  auto File = MemoryBuffer::getFile(InputFilePath, /*IsText=*/true);
+  auto File = MemoryBuffer::getFile(InputFilePath, sys::fs::OF_TextWithCRLF);
 
   EXPECT_TRUE(static_cast<bool>(File))
       << "Could not open unit test source directory file.";
diff --git a/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp b/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
index d914b49747c328..841fb062a6176b 100644
--- a/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
+++ b/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
@@ -239,7 +239,7 @@ bool identifyImportName(const COFFObjectFile &Obj, StringRef ObjName,
 
 int doIdentify(StringRef File, bool IdentifyStrict) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> MaybeBuf = MemoryBuffer::getFile(
-      File, /*IsText=*/false, /*RequiredNullTerminator=*/false);
+      File, sys::fs::OF_None, /*RequiredNullTerminator=*/false);
   if (!MaybeBuf)
     return printError(errorCodeToError(MaybeBuf.getError()), File);
   if (identify_magic(MaybeBuf.get()->getBuffer()) != file_magic::archive) {
diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
index 55e59aa6ac12dd..982d7299c4ae87 100644
--- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -26,6 +26,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/StringSaver.h"
@@ -86,7 +87,7 @@ static std::vector<StringRef> getSearchPaths(opt::InputArgList *Args,
 // Opens a file. Path has to be resolved already. (used for def file)
 std::unique_ptr<MemoryBuffer> openFile(const Twine &Path) {
   ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB =
-      MemoryBuffer::getFile(Path, /*IsText=*/true);
+      MemoryBuffer::getFile(Path, sys::fs::OF_TextWithCRLF);
 
   if (std::error_code EC = MB.getError()) {
     llvm::errs() << "cannot open file " << Path << ": " << EC.message() << "\n";
@@ -121,7 +122,7 @@ static void doList(opt::InputArgList &Args) {
   for (auto *Arg : Args.filtered(OPT_INPUT)) {
     // Create or open the archive object.
     ErrorOr<std::unique_ptr<MemoryBuffer>> MaybeBuf = MemoryBuffer::getFile(
-        Arg->getValue(), /*IsText=*/false, /*RequiresNullTerminator=*/false);
+        Arg->getValue(), sys::fs::OF_None, /*RequiresNullTerminator=*/false);
     fatalOpenError(errorCodeToError(MaybeBuf.getError()), Arg->getValue());
 
     if (identify_magic(MaybeBuf.get()->getBuffer()) == file_magic::archive) {
@@ -470,7 +471,7 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
 
     // Open a file.
     ErrorOr<std::unique_ptr<MemoryBuffer>> MOrErr = MemoryBuffer::getFile(
-        Path, /*IsText=*/false, /*RequiresNullTerminator=*/false);
+        Path, sys::fs::OF_None, /*RequiresNullTerminator=*/false);
     fatalOpenError(errorCodeToError(MOrErr.getError()), Path);
     MemoryBufferRef MBRef = (*MOrErr)->getMemBufferRef();
 
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index ab3b2e51c885bc..5921471abdc53b 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -2327,7 +2327,7 @@ bool LowerTypeTestsModule::runForTesting(Module &M, ModuleAnalysisManager &AM) {
     ExitOnError ExitOnErr("-lowertypetests-read-summary: " + ClReadSummary +
                           ": ");
     auto ReadSummaryFile = ExitOnErr(errorOrToExpected(
-        MemoryBuffer::getFile(ClReadSummary, /*IsText=*/true)));
+        MemoryBuffer::getFile(ClReadSummary, sys::fs::OF_TextWithCRLF)));
     // TODO: Convert the rest of tests (some YAML features are missing from
     // textual summary assembly) and remove YAML from this file.
     if (ReadSummaryFile->getBuffer().starts_with("---")) {
diff --git a/llvm/tools/dsymutil/DebugMap.cpp b/llvm/tools/dsymutil/DebugMap.cpp
index a88959ae405c12..da3d54870937a6 100644
--- a/llvm/tools/dsymutil/DebugMap.cpp
+++ b/llvm/tools/dsymutil/DebugMap.cpp
@@ -15,6 +15,7 @@
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Chrono.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
@@ -147,7 +148,8 @@ DebugMap::DebugMap(const Triple &BinaryTriple, StringRef BinaryPath,
 ErrorOr<std::vector<std::unique_ptr<DebugMap>>>
 DebugMap::parseYAMLDebugMap(BinaryHolder &BinHolder, StringRef InputFile,
                             StringRef PrependPath, bool Verbose) {
-  auto ErrOrFile = MemoryBuffer::getFileOrSTDIN(InputFile, /*IsText=*/true);
+  auto ErrOrFile =
+      MemoryBuffer::getFileOrSTDIN(InputFile, sys::fs::OF_TextWithCRLF);
   if (auto Err = ErrOrFile.getError())
     return Err;
 
diff --git a/llvm/tools/dsymutil/dsymutil.cpp b/llvm/tools/dsymutil/dsymutil.cpp
index 0b30d3512d8d2c..78be32ed2c6f8d 100644
--- a/llvm/tools/dsymutil/dsymutil.cpp
+++ b/llvm/tools/dsymutil/dsymutil.cpp
@@ -772,7 +772,7 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
 
     auto ParseAllowDisallowFile =
         [&](const std::string &FilePath) -> Expected<StringSet<>> {
-      auto BufOrErr = MemoryBuffer::getFile(FilePath, /*IsText=*/true);
+      auto BufOrErr = MemoryBuffer::getFile(FilePath, sys::fs::OF_TextWithCRLF);
       if (!BufOrErr)
         return make_error<StringError>(
             Twine("cannot open allow/disallow file '") + FilePath +
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index 6bee74935a1157..713dec154b4017 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -333,7 +333,7 @@ class LLIObjectCache : public ObjectCache {
       return nullptr;
     // Load the object from the cache filename
     ErrorOr<std::unique_ptr<MemoryBuffer>> IRObjectBuffer =
-        MemoryBuffer::getFile(CacheName, /*IsText=*/false,
+        MemoryBuffer::getFile(CacheName, sys::fs::OF_None,
                               /*RequiresNullTerminator=*/false);
     // If the file isn't there, that's OK.
     if (!IRObjectBuffer)
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index 6ab53375509c8c..11acc6cb8a17ff 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -303,7 +303,7 @@ static void getArchive() {
 }
 
 static object::Archive &readLibrary(const Twine &Library) {
-  auto BufOrErr = MemoryBuffer::getFile(Library, /*IsText=*/false,
+  auto BufOrErr = MemoryBuffer::getFile(Library, sys::fs::OF_None,
                                         /*RequiresNullTerminator=*/false);
   failIfError(BufOrErr.getError(), "could not open library " + Library);
   ArchiveBuffers.push_back(std::move(*BufOrErr));
@@ -1169,7 +1169,7 @@ static void performOperation(ArchiveOperation Operation,
 static int performOperation(ArchiveOperation Operation) {
   // Create or open the archive object.
   ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getFile(
-      ArchiveName, /*IsText=*/false, /*RequiresNullTerminator=*/false);
+      ArchiveName, sys::fs::OF_None, /*RequiresNullTerminator=*/false);
   std::error_code EC = Buf.getError();
   if (EC && EC != errc::no_such_file_or_directory)
     fail("unable to open '" + ArchiveName + "': " + EC.message());
diff --git a/llvm/tools/llvm-cas-fuzzer/cas-fuzzer.cpp b/llvm/tools/llvm-cas-fuzzer/cas-fuzzer.cpp
index 1508a1d57559a0..80af864b9632bf 100644
--- a/llvm/tools/llvm-cas-fuzzer/cas-fuzzer.cpp
+++ b/llvm/tools/llvm-cas-fuzzer/cas-fuzzer.cpp
@@ -82,7 +82,7 @@ static void collectFilesWithPrefix(StringRef Dir, StringRef Prefix,
 
 /// Read an entire file into a buffer.
 static bool readFileBytes(StringRef Path, SmallVectorImpl<char> &Buf) {
-  auto MBOrErr = MemoryBuffer::getFile(Path, /*IsText=*/false,
+  auto MBOrErr = MemoryBuffer::getFile(Path, /*Flags=*/sys::fs::OF_None,
                                        /*RequiresNullTerminator=*/false);
   if (!MBOrErr)
     return false;
diff --git a/llvm/tools/llvm-cov/gcov.cpp b/llvm/tools/llvm-cov/gcov.cpp
index 875b1e088de54c..9b10dd7f3213c2 100644
--- a/llvm/tools/llvm-cov/gcov.cpp
+++ b/llvm/tools/llvm-cov/gcov.cpp
@@ -69,7 +69,7 @@ static void reportCoverage(StringRef SourceFile, StringRef ObjectDir,
   // Open .gcda and .gcda without requiring a NUL terminator. The concurrent
   // modification may nullify the NUL terminator condition.
   ErrorOr<std::unique_ptr<MemoryBuffer>> GCNO_Buff =
-      MemoryBuffer::getFileOrSTDIN(GCNO, /*IsText=*/false,
+      MemoryBuffer::getFileOrSTDIN(GCNO, sys::fs::OF_None,
                                    /*RequiresNullTerminator=*/false);
   if (std::error_code EC = GCNO_Buff.getError()) {
     errs() << GCNO << ": " << EC.message() << "\n";
@@ -82,7 +82,7 @@ static void reportCoverage(StringRef SourceFile, StringRef ObjectDir,
   }
 
   ErrorOr<std::unique_ptr<MemoryBuffer>> GCDA_Buff =
-      MemoryBuffer::getFileOrSTDIN(GCDA, /*IsText=*/false,
+      MemoryBuffer::getFileOrSTDIN(GCDA, sys::fs::OF_None,
                                    /*RequiresNullTerminator=*/false);
   if (std::error_code EC = GCDA_Buff.getError()) {
     if (EC != errc::no_such_file_or_directory) {
diff --git a/llvm/tools/llvm-ctxprof-util/llvm-ctxprof-util.cpp b/llvm/tools/llvm-ctxprof-util/llvm-ctxprof-util.cpp
index 5903919f96db59..39f75ee393c3c1 100644
--- a/llvm/tools/llvm-ctxprof-util/llvm-ctxprof-util.cpp
+++ b/llvm/tools/llvm-ctxprof-util/llvm-ctxprof-util.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -48,7 +49,7 @@ namespace {
 // Save the bitstream profile from the JSON representation.
 Error convertFromYaml() {
   auto BufOrError =
-      MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(InputFilename, sys::fs::OF_TextWithCRLF);
   if (!BufOrError)
     return createFileError(InputFilename, BufOrError.getError());
 
diff --git a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp
index e13c66c9ab1a76..f4a1b771ed2822 100644
--- a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp
+++ b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp
@@ -160,7 +160,7 @@ int main(int Argc, const char **Argv) {
 
   for (const auto &File : InputFiles) {
     std::unique_ptr<MemoryBuffer> Buffer = error(
-        File, MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false,
+        File, MemoryBuffer::getFileOrSTDIN(File, sys::fs::OF_None,
                                            /*RequiresNullTerminator=*/false));
     file_magic Type = identify_magic(Buffer->getMemBufferRef().getBuffer());
     if (Type != file_magic::windows_resource)
@@ -207,7 +207,7 @@ int main(int Argc, const char **Argv) {
   if (Verbose) {
     std::unique_ptr<MemoryBuffer> Buffer =
         error(OutputFile,
-              MemoryBuffer::getFileOrSTDIN(OutputFile, /*IsText=*/false,
+              MemoryBuffer::getFileOrSTDIN(OutputFile, sys::fs::OF_None,
                                            /*RequiresNullTerminator=*/false));
 
     ScopedPrinter W(errs());
diff --git a/llvm/tools/llvm-cxxmap/llvm-cxxmap.cpp b/llvm/tools/llvm-cxxmap/llvm-cxxmap.cpp
index 6eb193ad5f45c9..8f818164deed14 100644
--- a/llvm/tools/llvm-cxxmap/llvm-cxxmap.cpp
+++ b/llvm/tools/llvm-cxxmap/llvm-cxxmap.cpp
@@ -146,17 +146,17 @@ int main(int argc, const char *argv[]) {
   cl::ParseCommandLineOptions(argc, argv, "LLVM C++ mangled name remapper\n");
 
   auto OldSymbolBufOrError =
-      MemoryBuffer::getFileOrSTDIN(OldSymbolFile, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(OldSymbolFile, sys::fs::OF_TextWithCRLF);
   if (!OldSymbolBufOrError)
     exitWithErrorCode(OldSymbolBufOrError.getError(), OldSymbolFile);
 
   auto NewSymbolBufOrError =
-      MemoryBuffer::getFileOrSTDIN(NewSymbolFile, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(NewSymbolFile, sys::fs::OF_TextWithCRLF);
   if (!NewSymbolBufOrError)
     exitWithErrorCode(NewSymbolBufOrError.getError(), NewSymbolFile);
 
   auto RemappingBufOrError =
-      MemoryBuffer::getFileOrSTDIN(RemappingFile, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(RemappingFile, sys::fs::OF_TextWithCRLF);
   if (!RemappingBufOrError)
     exitWithErrorCode(RemappingBufOrError.getError(), RemappingFile);
 
diff --git a/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp b/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
index 483b14a841083c..c55b0626d3248f 100644
--- a/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
+++ b/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
@@ -128,7 +128,7 @@ int llvm_debuginfod_find_main(int argc, char **argv,
   if (DumpToStdout) {
     // Print the contents of the artifact.
     ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getFile(
-        Path, /*IsText=*/false, /*RequiresNullTerminator=*/false);
+        Path, sys::fs::OF_None, /*RequiresNullTerminator=*/false);
     ExitOnDebuginfodFindError(errorCodeToError(Buf.getError()));
     outs() << Buf.get()->getBuffer();
   } else
diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
index b5820f8669f1d5..27fab7d2394c0f 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -640,8 +640,8 @@ static void analysisMain() {
 #include "llvm/Config/TargetExegesis.def"
 
   auto MemoryBuffer = ExitOnFileError(
-      BenchmarkFile,
-      errorOrToExpected(MemoryBuffer::getFile(BenchmarkFile, /*IsText=*/true)));
+      BenchmarkFile, errorOrToExpected(MemoryBuffer::getFile(
+                         BenchmarkFile, sys::fs::OF_TextWithCRLF)));
 
   const auto TriplesAndCpus = ExitOnFileError(
       BenchmarkFile,
diff --git a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
index cb93054a89273d..a21e772bcdd66c 100644
--- a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
+++ b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
@@ -652,7 +652,7 @@ static llvm::Error handleFileConversionToGSYM(StringRef Filename,
                                               const std::string &OutFile,
                                               OutputAggregator &Out) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> BuffOrErr =
-      MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(Filename, sys::fs::OF_TextWithCRLF);
   error(Filename, BuffOrErr.getError());
   std::unique_ptr<MemoryBuffer> Buffer = std::move(BuffOrErr.get());
 
@@ -660,7 +660,7 @@ static llvm::Error handleFileConversionToGSYM(StringRef Filename,
   std::unique_ptr<Binary> SymtabBinary;
   if (!SymtabFilename.empty()) {
     auto SymtabBufOrErr =
-        MemoryBuffer::getFile(SymtabFilename, /*IsText=*/true);
+        MemoryBuffer::getFile(SymtabFilename, sys::fs::OF_TextWithCRLF);
     if (!SymtabBufOrErr)
       return createStringError(SymtabBufOrErr.getError(),
                                "failed to open symbol table file '%s'",
diff --git a/llvm/tools/llvm-ifs/llvm-ifs.cpp b/llvm/tools/llvm-ifs/llvm-ifs.cpp
index 575a1117363fe5..7fbfb6d6a18939 100644
--- a/llvm/tools/llvm-ifs/llvm-ifs.cpp
+++ b/llvm/tools/llvm-ifs/llvm-ifs.cpp
@@ -23,6 +23,7 @@
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileOutputBuffer.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VersionTuple.h"
@@ -120,7 +121,7 @@ static Expected<std::unique_ptr<IFSStub>>
 readInputFile(std::optional<FileFormat> &InputFormat, StringRef FilePath) {
   // Read in file.
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrError =
-      MemoryBuffer::getFileOrSTDIN(FilePath, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(FilePath, sys::fs::OF_TextWithCRLF);
   if (!BufOrError)
     return createStringError(BufOrError.getError(), "Could not open `%s`",
                              FilePath.data());
diff --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
index b2e02173ee3b4e..e59599208890ea 100644
--- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -134,7 +134,7 @@ static Error processFileList() {
   std::tie(FileName, DirName) = StringRef(FileList).rsplit(",");
 
   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
-      MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/false,
+      MemoryBuffer::getFileOrSTDIN(FileName, sys::fs::OF_None,
                                    /*RequiresNullTerminator=*/true);
   if (std::error_code EC = FileOrErr.getError())
     return createFileError(FileName, errorCodeToError(EC));
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index 9390301f1b75ab..728950f918bd8e 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -312,7 +312,7 @@ static bool importFunctions(const char *argv0, Module &DestModule) {
   auto ModuleLoader = [&DestModule](const char *argv0,
                                     const std::string &Identifier) {
     std::unique_ptr<MemoryBuffer> Buffer = ExitOnErr(errorOrToExpected(
-        MemoryBuffer::getFileOrSTDIN(Identifier, /*IsText=*/true)));
+        MemoryBuffer::getFileOrSTDIN(Identifier, sys::fs::OF_TextWithCRLF)));
     return loadFile(argv0, std::move(Buffer), DestModule.getContext(), false);
   };
 
@@ -384,7 +384,8 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
   // Similar to some flags, internalization doesn't apply to the first file.
   bool InternalizeLinkedSymbols = false;
   for (const auto &File : Files) {
-    auto BufferOrErr = MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/true);
+    auto BufferOrErr =
+        MemoryBuffer::getFileOrSTDIN(File, sys::fs::OF_TextWithCRLF);
 
     // When we encounter a missing file, make sure we expose its name.
     if (auto EC = BufferOrErr.getError())
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index 01d42f07e337da..9713833455e24f 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -33,6 +33,7 @@
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compression.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/InitLLVM.h"
@@ -428,7 +429,7 @@ int main(int argc, char **argv) {
   Triple TheTriple(TripleName);
 
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
-      MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(InputFilename, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = BufferPtr.getError()) {
     WithColor::error(errs(), ProgName)
         << InputFilename << ": " << EC.message() << '\n';
diff --git a/llvm/tools/llvm-objdump/SourcePrinter.cpp b/llvm/tools/llvm-objdump/SourcePrinter.cpp
index 66ffa36cdd7eb6..2626f589733aac 100644
--- a/llvm/tools/llvm-objdump/SourcePrinter.cpp
+++ b/llvm/tools/llvm-objdump/SourcePrinter.cpp
@@ -708,7 +708,8 @@ bool SourcePrinter::cacheSource(const DILineInfo &LineInfo) {
         PathToOpen = std::move(*Resolved);
     }
 
-    auto BufferOrError = MemoryBuffer::getFile(PathToOpen, /*IsText=*/true);
+    auto BufferOrError =
+        MemoryBuffer::getFile(PathToOpen, sys::fs::OF_TextWithCRLF);
     if (!BufferOrError) {
       if (MissingSources.insert(LineInfo.FileName).second)
         reportWarning("failed to find source " + LineInfo.FileName,
diff --git a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
index 4ca77cc9e9af12..f71a066c5bf10c 100644
--- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
+++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
@@ -804,7 +804,7 @@ static ExitOnError ExitOnErr;
 static void yamlToPdb(StringRef Path, unsigned DocNum) {
   BumpPtrAllocator Allocator;
   ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
-      MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/false,
+      MemoryBuffer::getFileOrSTDIN(Path, sys::fs::OF_None,
                                    /*RequiresNullTerminator=*/false);
 
   if (ErrorOrBuffer.getError()) {
diff --git a/llvm/tools/llvm-rc/ResourceFileWriter.cpp b/llvm/tools/llvm-rc/ResourceFileWriter.cpp
index fe88ce45bc878f..2786f94abc5b2b 100644
--- a/llvm/tools/llvm-rc/ResourceFileWriter.cpp
+++ b/llvm/tools/llvm-rc/ResourceFileWriter.cpp
@@ -1567,7 +1567,7 @@ ResourceFileWriter::loadFile(StringRef File) const {
   SmallString<128> Cwd;
 
   auto Open = [&](StringRef Resolved) {
-    auto Buffer = MemoryBuffer::getFile(Resolved, /*IsText=*/false,
+    auto Buffer = MemoryBuffer::getFile(Resolved, sys::fs::OF_None,
                                         /*RequiresNullTerminator=*/false);
     if (Buffer && Params.ShowIncludes)
       errs() << "Note: including file: " << Resolved << "\n";
diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp
index 7be5b16dce3bae..bc5f383affc8ba 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -587,7 +587,7 @@ void doRc(std::string Src, std::string Dest, RcOptions &Opts,
 
   // Read and tokenize the input file.
   ErrorOr<std::unique_ptr<MemoryBuffer>> File =
-      MemoryBuffer::getFile(PreprocessedFile, /*IsText=*/true);
+      MemoryBuffer::getFile(PreprocessedFile, sys::fs::OF_TextWithCRLF);
   if (!File) {
     fatalError("Error opening file '" + Twine(PreprocessedFile) +
                "': " + File.getError().message());
@@ -667,7 +667,7 @@ void doCvtres(std::string Src, std::string Dest, std::string TargetTriple) {
   object::WindowsResourceParser Parser;
 
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
-      MemoryBuffer::getFile(Src, /*IsText=*/true);
+      MemoryBuffer::getFile(Src, sys::fs::OF_TextWithCRLF);
   if (!BufferOrErr)
     fatalError("Error opening file '" + Twine(Src) +
                "': " + BufferOrErr.getError().message());
diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp
index 6ec0563d6d3272..ac00b191ce19e7 100644
--- a/llvm/tools/llvm-readobj/llvm-readobj.cpp
+++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp
@@ -625,7 +625,7 @@ static void dumpWindowsResourceFile(WindowsResource *WinRes,
 /// Opens \a File and dumps it.
 static void dumpInput(StringRef File, ScopedPrinter &Writer) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
-      MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false,
+      MemoryBuffer::getFileOrSTDIN(File, sys::fs::OF_None,
                                    /*RequiresNullTerminator=*/false);
   if (std::error_code EC = FileOrErr.getError())
     return reportError(errorCodeToError(EC), File);
diff --git a/llvm/tools/llvm-readtapi/llvm-readtapi.cpp b/llvm/tools/llvm-readtapi/llvm-readtapi.cpp
index f032e90401d103..f8d53efb8e3dac 100644
--- a/llvm/tools/llvm-readtapi/llvm-readtapi.cpp
+++ b/llvm/tools/llvm-readtapi/llvm-readtapi.cpp
@@ -120,7 +120,7 @@ static std::unique_ptr<InterfaceFile>
 getInterfaceFile(const StringRef Filename, bool ResetBanner = true) {
   ExitOnErr.setBanner(TOOLNAME + ": error: '" + Filename.str() + "' ");
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
-      MemoryBuffer::getFile(Filename, /*IsText=*/true);
+      MemoryBuffer::getFile(Filename, sys::fs::OF_TextWithCRLF);
   if (BufferOrErr.getError())
     ExitOnErr(errorCodeToError(BufferOrErr.getError()));
   auto Buffer = std::move(*BufferOrErr);
diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index 6b202aec3e8f85..0f63fb51973433 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -32,6 +32,7 @@
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Passes/PassBuilder.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/ToolOutputFile.h"
@@ -835,7 +836,8 @@ llvm::parseReducerWorkItem(StringRef ToolName, StringRef Filename,
   auto MMM = std::make_unique<ReducerWorkItem>();
 
   if (IsMIR) {
-    auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
+    auto FileOrErr =
+        MemoryBuffer::getFileOrSTDIN(Filename, sys::fs::OF_TextWithCRLF);
     if (std::error_code EC = FileOrErr.getError()) {
       WithColor::error(errs(), ToolName) << EC.message() << '\n';
       return {nullptr, false};
diff --git a/llvm/tools/llvm-strings/llvm-strings.cpp b/llvm/tools/llvm-strings/llvm-strings.cpp
index f2abd1c3271a88..19e4cc942f5898 100644
--- a/llvm/tools/llvm-strings/llvm-strings.cpp
+++ b/llvm/tools/llvm-strings/llvm-strings.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Option/Option.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -165,7 +166,7 @@ int main(int argc, char **argv) {
 
   for (const auto &File : InputFileNames) {
     ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
-        MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/true);
+        MemoryBuffer::getFileOrSTDIN(File, sys::fs::OF_TextWithCRLF);
     if (std::error_code EC = Buffer.getError())
       errs() << File << ": " << EC.message() << '\n';
     else
diff --git a/llvm/tools/obj2yaml/obj2yaml.cpp b/llvm/tools/obj2yaml/obj2yaml.cpp
index eb0a816904be52..8f87795a5cf75c 100644
--- a/llvm/tools/obj2yaml/obj2yaml.cpp
+++ b/llvm/tools/obj2yaml/obj2yaml.cpp
@@ -63,7 +63,7 @@ static Error dumpObject(const ObjectFile &Obj, raw_ostream &OS) {
 
 static Error dumpInput(StringRef File, unsigned RawSegment, raw_ostream &OS) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
-      MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false,
+      MemoryBuffer::getFileOrSTDIN(File, sys::fs::OF_None,
                                    /*RequiresNullTerminator=*/false);
   if (std::error_code EC = FileOrErr.getError())
     return errorCodeToError(EC);
diff --git a/llvm/tools/sanstats/sanstats.cpp b/llvm/tools/sanstats/sanstats.cpp
index a2dee8d59dcb0e..201eb2bf48c252 100644
--- a/llvm/tools/sanstats/sanstats.cpp
+++ b/llvm/tools/sanstats/sanstats.cpp
@@ -131,7 +131,7 @@ int main(int argc, char **argv) {
                               "Sanitizer Statistics Processing Tool");
 
   ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getFile(
-      ClInputFile, /*IsText=*/false, /*RequiresNullTerminator=*/false);
+      ClInputFile, sys::fs::OF_None, /*RequiresNullTerminator=*/false);
   if (!MBOrErr) {
     errs() << argv[0] << ": " << ClInputFile << ": "
            << MBOrErr.getError().message() << '\n';
diff --git a/llvm/tools/yaml2obj/yaml2obj.cpp b/llvm/tools/yaml2obj/yaml2obj.cpp
index 8fb5b0af0d3ab4..8638093e60f3b8 100644
--- a/llvm/tools/yaml2obj/yaml2obj.cpp
+++ b/llvm/tools/yaml2obj/yaml2obj.cpp
@@ -160,7 +160,7 @@ int main(int argc, char **argv) {
   }
 
   ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =
-      MemoryBuffer::getFileOrSTDIN(Input, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(Input, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = Buf.getError()) {
     WithColor::error(errs(), ProgName) << Input << ": " << EC.message() << '\n';
     return 1;
diff --git a/llvm/unittests/DebugInfo/PDB/TpiStreamTest.cpp b/llvm/unittests/DebugInfo/PDB/TpiStreamTest.cpp
index e7339751915bb1..49016204c87fab 100644
--- a/llvm/unittests/DebugInfo/PDB/TpiStreamTest.cpp
+++ b/llvm/unittests/DebugInfo/PDB/TpiStreamTest.cpp
@@ -36,7 +36,7 @@ static Expected<std::unique_ptr<PDBFile>>
 openSimplePdb(BumpPtrAllocator &Allocator) {
   std::string PdbPath = getPdbPath();
   ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
-      MemoryBuffer::getFile(PdbPath, /*IsText=*/false,
+      MemoryBuffer::getFile(PdbPath, /*Flags=*/sys::fs::OF_None,
                             /*RequiresNullTerminator=*/false);
   EXPECT_TRUE(ErrorOrBuffer);
   std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
diff --git a/llvm/unittests/Support/raw_ostream_test.cpp b/llvm/unittests/Support/raw_ostream_test.cpp
index aded02c7b34027..6bdbd89b5e2c44 100644
--- a/llvm/unittests/Support/raw_ostream_test.cpp
+++ b/llvm/unittests/Support/raw_ostream_test.cpp
@@ -497,7 +497,7 @@ TEST(raw_ostreamTest, flush_tied_to_stream_on_write) {
 
 static void checkFileData(StringRef FileName, StringRef GoldenData) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
-      MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(FileName, sys::fs::OF_TextWithCRLF);
   EXPECT_FALSE(BufOrErr.getError());
 
   EXPECT_EQ((*BufOrErr)->getBufferSize(), GoldenData.size());
diff --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp
index 0ec3b88d356f37..60470665f7d30b 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -17,6 +17,7 @@
 
 #include "llvm/FileCheck/FileCheck.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Process.h"
@@ -1166,7 +1167,7 @@ int main(int argc, char **argv) {
 
   // Read the expected strings from the check file.
   ErrorOr<std::unique_ptr<MemoryBuffer>> CheckFileOrErr =
-      MemoryBuffer::getFileOrSTDIN(CheckFilename, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(CheckFilename, sys::fs::OF_TextWithCRLF);
   if (std::error_code EC = CheckFileOrErr.getError()) {
     errs() << "Could not open check file '" << CheckFilename
            << "': " << EC.message() << '\n';
@@ -1188,7 +1189,7 @@ int main(int argc, char **argv) {
 
   // Open the file to check and add it to SourceMgr.
   ErrorOr<std::unique_ptr<MemoryBuffer>> InputFileOrErr =
-      MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(InputFilename, sys::fs::OF_TextWithCRLF);
   if (InputFilename == "-")
     InputFilename = "<stdin>"; // Overwrite for improved diagnostic messages
   if (std::error_code EC = InputFileOrErr.getError()) {
diff --git a/llvm/utils/split-file/split-file.cpp b/llvm/utils/split-file/split-file.cpp
index c65b0428f3b140..9ed6420a1e1cff 100644
--- a/llvm/utils/split-file/split-file.cpp
+++ b/llvm/utils/split-file/split-file.cpp
@@ -176,7 +176,7 @@ int main(int argc, char **argv) {
     fatal("", "too many positional arguments");
   StringRef input = positional[0], output = positional[1];
   ErrorOr<std::unique_ptr<MemoryBuffer>> bufferOrErr =
-      MemoryBuffer::getFileOrSTDIN(input, /*IsText=*/true);
+      MemoryBuffer::getFileOrSTDIN(input, sys::fs::OF_TextWithCRLF);
   if (std::error_code ec = bufferOrErr.getError())
     fatal(input, ec.message());
 
diff --git a/mlir/lib/Support/FileUtilities.cpp b/mlir/lib/Support/FileUtilities.cpp
index a5c44d3a9c8eb0..74b27a7621d61f 100644
--- a/mlir/lib/Support/FileUtilities.cpp
+++ b/mlir/lib/Support/FileUtilities.cpp
@@ -23,7 +23,7 @@ static std::unique_ptr<llvm::MemoryBuffer>
 openInputFileImpl(StringRef inputFilename, std::string *errorMessage,
                   std::optional<llvm::Align> alignment) {
   auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(
-      inputFilename, /*IsText=*/false, /*RequiresNullTerminator=*/true,
+      inputFilename, llvm::sys::fs::OF_None, /*RequiresNullTerminator=*/true,
       alignment);
   if (std::error_code error = fileOrErr.getError()) {
     if (errorMessage)
diff --git a/mlir/lib/Target/LLVM/ROCDL/Target.cpp b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
index 56bf2a030760e7..42e2c9283fb070 100644
--- a/mlir/lib/Target/LLVM/ROCDL/Target.cpp
+++ b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
@@ -369,7 +369,7 @@ mlir::ROCDL::linkObjectCode(ArrayRef<char> objectCode, StringRef lldPath,
 
   // Load the HSA code object.
   auto hsacoFile =
-      llvm::MemoryBuffer::getFile(tempHsacoFilename, /*IsText=*/false);
+      llvm::MemoryBuffer::getFile(tempHsacoFilename, llvm::sys::fs::OF_None);
   if (!hsacoFile)
     return emitError()
            << "failed to read the HSA code object from the temp file";
diff --git a/mlir/tools/mlir-pdll/mlir-pdll.cpp b/mlir/tools/mlir-pdll/mlir-pdll.cpp
index 76122a04115139..7825ed712933ec 100644
--- a/mlir/tools/mlir-pdll/mlir-pdll.cpp
+++ b/mlir/tools/mlir-pdll/mlir-pdll.cpp
@@ -16,6 +16,7 @@
 #include "mlir/Tools/PDLL/ODS/Context.h"
 #include "mlir/Tools/PDLL/Parser/Parser.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/ToolOutputFile.h"
@@ -222,8 +223,8 @@ int main(int argc, char **argv) {
     // Only update the real output file if there are any differences. This
     // prevents recompilation of all the files depending on it if there aren't
     // any.
-    if (auto existingOrErr =
-            llvm::MemoryBuffer::getFile(outputFilename, /*IsText=*/true))
+    if (auto existingOrErr = llvm::MemoryBuffer::getFile(
+            outputFilename, llvm::sys::fs::OF_TextWithCRLF))
       if (std::move(existingOrErr.get())->getBuffer() == outputStr)
         shouldWriteOutput = false;
   }
diff --git a/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp b/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp
index 9ec9b721502076..c4d67b5a724407 100644
--- a/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp
+++ b/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp
@@ -9,6 +9,7 @@
 #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"
@@ -96,8 +97,8 @@ int main(int argc, char **argv) {
     // Only update the real output file if there are any differences. This
     // prevents recompilation of all the files depending on it if there aren't
     // any.
-    if (auto existingOrErr =
-            llvm::MemoryBuffer::getFile(outputFilename, /*IsText=*/true))
+    if (auto existingOrErr = llvm::MemoryBuffer::getFile(
+            outputFilename, llvm::sys::fs::OF_TextWithCRLF))
       if (std::move(existingOrErr.get())->getBuffer() == outputStr)
         shouldWriteOutput = false;
   }



More information about the llvm-commits mailing list