[clang-tools-extra] b1df3a2 - [Support] llvm::Optional => std::optional

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 16 00:49:19 PST 2022


Author: Fangrui Song
Date: 2022-12-16T08:49:10Z
New Revision: b1df3a2c0b6a42570042934cb79ca0e4359f863b

URL: https://github.com/llvm/llvm-project/commit/b1df3a2c0b6a42570042934cb79ca0e4359f863b
DIFF: https://github.com/llvm/llvm-project/commit/b1df3a2c0b6a42570042934cb79ca0e4359f863b.diff

LOG: [Support] llvm::Optional => std::optional

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 
    

Modified: 
    clang-tools-extra/clangd/support/Threading.cpp
    clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
    clang/lib/CodeGen/CGObjC.cpp
    clang/lib/Lex/Lexer.cpp
    clang/lib/Lex/LiteralSupport.cpp
    clang/lib/Sema/SemaDeclAttr.cpp
    clang/lib/Serialization/ASTWriter.cpp
    clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
    clang/tools/libclang/CIndex.cpp
    llvm/include/llvm/Support/Allocator.h
    llvm/include/llvm/Support/BinaryStreamRef.h
    llvm/include/llvm/Support/Casting.h
    llvm/include/llvm/Support/Error.h
    llvm/include/llvm/Support/FileUtilities.h
    llvm/include/llvm/Support/FormatProviders.h
    llvm/include/llvm/Support/FormatVariadic.h
    llvm/include/llvm/Support/KnownBits.h
    llvm/include/llvm/Support/LockFileManager.h
    llvm/include/llvm/Support/MemoryBuffer.h
    llvm/include/llvm/Support/NativeFormatting.h
    llvm/include/llvm/Support/SMTAPI.h
    llvm/include/llvm/Support/Unicode.h
    llvm/include/llvm/Support/VersionTuple.h
    llvm/include/llvm/Support/VirtualFileSystem.h
    llvm/include/llvm/Support/thread.h
    llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
    llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
    llvm/lib/Support/BinaryStreamRef.cpp
    llvm/lib/Support/CrashRecoveryContext.cpp
    llvm/lib/Support/DJB.cpp
    llvm/lib/Support/FileUtilities.cpp
    llvm/lib/Support/FormatVariadic.cpp
    llvm/lib/Support/KnownBits.cpp
    llvm/lib/Support/LockFileManager.cpp
    llvm/lib/Support/MemoryBuffer.cpp
    llvm/lib/Support/NativeFormatting.cpp
    llvm/lib/Support/OptimizedStructLayout.cpp
    llvm/lib/Support/SymbolRemappingReader.cpp
    llvm/lib/Support/Threading.cpp
    llvm/lib/Support/UnicodeNameToCodepoint.cpp
    llvm/lib/Support/Unix/Threading.inc
    llvm/lib/Support/VersionTuple.cpp
    llvm/lib/Support/VirtualFileSystem.cpp
    llvm/lib/Support/Windows/Threading.inc
    llvm/lib/Support/Z3Solver.cpp
    llvm/unittests/ADT/StatisticTest.cpp
    llvm/unittests/Support/Casting.cpp
    llvm/unittests/Support/ErrorTest.cpp
    llvm/unittests/Support/KnownBitsTest.cpp
    llvm/unittests/Support/NativeFormatTests.cpp
    llvm/unittests/Support/Path.cpp
    llvm/unittests/Support/TypeTraitsTest.cpp
    mlir/lib/Support/FileUtilities.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/support/Threading.cpp b/clang-tools-extra/clangd/support/Threading.cpp
index 06d00c32d57d..be0d84cae3de 100644
--- a/clang-tools-extra/clangd/support/Threading.cpp
+++ b/clang-tools-extra/clangd/support/Threading.cpp
@@ -104,7 +104,7 @@ void AsyncTaskRunner::runAsync(const llvm::Twine &Name,
 
   // Ensure our worker threads have big enough stacks to run clang.
   llvm::thread Thread(
-      /*clang::DesiredStackSize*/ llvm::Optional<unsigned>(8 << 20),
+      /*clang::DesiredStackSize*/ std::optional<unsigned>(8 << 20),
       std::move(Task));
   Thread.detach();
 }

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index cf515c5a809a..c4ed790f5a7b 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -128,7 +128,7 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
       addStateConstraints(State);
 
       // Constraints are unsatisfiable
-      Optional<bool> isSat = Solver->check();
+      std::optional<bool> isSat = Solver->check();
       if (!isSat || !*isSat)
         return nullptr;
 
@@ -145,7 +145,7 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
 
       Solver->addConstraint(NotExp);
 
-      Optional<bool> isNotSat = Solver->check();
+      std::optional<bool> isNotSat = Solver->check();
       if (!isNotSat || *isNotSat)
         return nullptr;
 
@@ -340,7 +340,7 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
     Solver->reset();
     addStateConstraints(NewState);
 
-    Optional<bool> res = Solver->check();
+    std::optional<bool> res = Solver->check();
     if (!res)
       Cached[hash] = ConditionTruthVal();
     else

diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 961410c5b53e..42c766a3ec0e 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -3984,7 +3984,8 @@ static llvm::Value *emitIsPlatformVersionAtLeast(CodeGenFunction &CGF,
   llvm::SmallVector<llvm::Value *, 8> Args;
 
   auto EmitArgs = [&](const VersionTuple &Version, const llvm::Triple &TT) {
-    Optional<unsigned> Min = Version.getMinor(), SMin = Version.getSubminor();
+    std::optional<unsigned> Min = Version.getMinor(),
+                            SMin = Version.getSubminor();
     Args.push_back(
         llvm::ConstantInt::get(CGM.Int32Ty, getBaseMachOPlatformID(TT)));
     Args.push_back(llvm::ConstantInt::get(CGM.Int32Ty, Version.getMajor()));
@@ -4022,7 +4023,8 @@ CodeGenFunction::EmitBuiltinAvailable(const VersionTuple &Version) {
         CGM.CreateRuntimeFunction(FTy, "__isOSVersionAtLeast");
   }
 
-  Optional<unsigned> Min = Version.getMinor(), SMin = Version.getSubminor();
+  std::optional<unsigned> Min = Version.getMinor(),
+                          SMin = Version.getSubminor();
   llvm::Value *Args[] = {
       llvm::ConstantInt::get(CGM.Int32Ty, Version.getMajor()),
       llvm::ConstantInt::get(CGM.Int32Ty, Min.value_or(0)),

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 4a9c5b5cd680..c93d3349c9ac 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -3355,9 +3355,9 @@ llvm::Optional<uint32_t> Lexer::tryReadNamedUCN(const char *&StartPtr,
   }
 
   StringRef Name(Buffer.data(), Buffer.size());
-  llvm::Optional<char32_t> Match =
+  std::optional<char32_t> Match =
       llvm::sys::unicode::nameToCodepointStrict(Name);
-  llvm::Optional<llvm::sys::unicode::LooseMatchingResult> LooseMatch;
+  std::optional<llvm::sys::unicode::LooseMatchingResult> LooseMatch;
   if (!Match) {
     LooseMatch = llvm::sys::unicode::nameToCodepointLooseMatching(Name);
     if (Diagnose) {

diff  --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 4ba4d94a600f..05575e8d6e2a 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -358,7 +358,7 @@ void clang::expandUCNs(SmallVectorImpl<char> &Buf, StringRef Input) {
       ++I;
       auto Delim = std::find(I, Input.end(), '}');
       assert(Delim != Input.end());
-      llvm::Optional<llvm::sys::unicode::LooseMatchingResult> Res =
+      std::optional<llvm::sys::unicode::LooseMatchingResult> Res =
           llvm::sys::unicode::nameToCodepointLooseMatching(
               StringRef(I, std::distance(I, Delim)));
       assert(Res);
@@ -487,7 +487,7 @@ static void DiagnoseInvalidUnicodeCharacterName(
 
   namespace u = llvm::sys::unicode;
 
-  llvm::Optional<u::LooseMatchingResult> Res =
+  std::optional<u::LooseMatchingResult> Res =
       u::nameToCodepointLooseMatching(Name);
   if (Res) {
     Diag(Diags, Features, Loc, TokBegin, TokRangeBegin, TokRangeEnd,
@@ -565,8 +565,7 @@ static bool ProcessNamedUCNEscape(const char *ThisTokBegin,
   }
   StringRef Name(ThisTokBuf, ClosingBrace - ThisTokBuf);
   ThisTokBuf = ClosingBrace + 1;
-  llvm::Optional<char32_t> Res =
-      llvm::sys::unicode::nameToCodepointStrict(Name);
+  std::optional<char32_t> Res = llvm::sys::unicode::nameToCodepointStrict(Name);
   if (!Res) {
     if (Diags)
       DiagnoseInvalidUnicodeCharacterName(Diags, Features, Loc, ThisTokBegin,

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 93cc897e393f..a9fe447ef6a6 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2634,7 +2634,7 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   }
 
   if (II->isStr("fuchsia")) {
-    Optional<unsigned> Min, Sub;
+    std::optional<unsigned> Min, Sub;
     if ((Min = Introduced.Version.getMinor()) ||
         (Sub = Introduced.Version.getSubminor())) {
       S.Diag(AL.getLoc(), diag::warn_availability_fuchsia_unavailable_minor);

diff  --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 7469bcac18ee..935f3e7535cc 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -4466,11 +4466,11 @@ void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record,
 void ASTWriter::AddVersionTuple(const VersionTuple &Version,
                                 RecordDataImpl &Record) {
   Record.push_back(Version.getMajor());
-  if (Optional<unsigned> Minor = Version.getMinor())
+  if (std::optional<unsigned> Minor = Version.getMinor())
     Record.push_back(*Minor + 1);
   else
     Record.push_back(0);
-  if (Optional<unsigned> Subminor = Version.getSubminor())
+  if (std::optional<unsigned> Subminor = Version.getSubminor())
     Record.push_back(*Subminor + 1);
   else
     Record.push_back(0);

diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index e36716fe2aac..f47a524cadd6 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -3449,7 +3449,7 @@ void FalsePositiveRefutationBRVisitor::finalizeVisitor(
   }
 
   // And check for satisfiability
-  Optional<bool> IsSAT = RefutationSolver->check();
+  std::optional<bool> IsSAT = RefutationSolver->check();
   if (!IsSAT)
     return;
 

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 2c75e956ac70..f99275e4f243 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -7032,7 +7032,7 @@ void clang_enableStackTraces(void) {
 void clang_executeOnThread(void (*fn)(void *), void *user_data,
                            unsigned stack_size) {
   llvm::thread Thread(stack_size == 0 ? clang::DesiredStackSize
-                                      : llvm::Optional<unsigned>(stack_size),
+                                      : std::optional<unsigned>(stack_size),
                       fn, user_data);
   Thread.join();
 }
@@ -8236,13 +8236,13 @@ static CXVersion convertVersion(VersionTuple In) {
 
   Out.Major = In.getMajor();
 
-  Optional<unsigned> Minor = In.getMinor();
+  std::optional<unsigned> Minor = In.getMinor();
   if (Minor)
     Out.Minor = *Minor;
   else
     return Out;
 
-  Optional<unsigned> Subminor = In.getSubminor();
+  std::optional<unsigned> Subminor = In.getSubminor();
   if (Subminor)
     Out.Subminor = *Subminor;
 

diff  --git a/llvm/include/llvm/Support/Allocator.h b/llvm/include/llvm/Support/Allocator.h
index 8a70709c6784..ab3e12216d98 100644
--- a/llvm/include/llvm/Support/Allocator.h
+++ b/llvm/include/llvm/Support/Allocator.h
@@ -229,7 +229,7 @@ class BumpPtrAllocatorImpl
   /// The returned value is negative iff the object is inside a custom-size
   /// slab.
   /// Returns an empty optional if the pointer is not found in the allocator.
-  llvm::Optional<int64_t> identifyObject(const void *Ptr) {
+  std::optional<int64_t> identifyObject(const void *Ptr) {
     const char *P = static_cast<const char *>(Ptr);
     int64_t InSlabIdx = 0;
     for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
@@ -256,7 +256,7 @@ class BumpPtrAllocatorImpl
   /// \return An index uniquely and reproducibly identifying
   /// an input pointer \p Ptr in the given allocator.
   int64_t identifyKnownObject(const void *Ptr) {
-    Optional<int64_t> Out = identifyObject(Ptr);
+    std::optional<int64_t> Out = identifyObject(Ptr);
     assert(Out && "Wrong allocator used");
     return *Out;
   }

diff  --git a/llvm/include/llvm/Support/BinaryStreamRef.h b/llvm/include/llvm/Support/BinaryStreamRef.h
index 46fc9fb293df..0cea224527ac 100644
--- a/llvm/include/llvm/Support/BinaryStreamRef.h
+++ b/llvm/include/llvm/Support/BinaryStreamRef.h
@@ -10,12 +10,12 @@
 #define LLVM_SUPPORT_BINARYSTREAMREF_H
 
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/Support/BinaryStream.h"
 #include "llvm/Support/BinaryStreamError.h"
 #include "llvm/Support/Error.h"
 #include <cstdint>
 #include <memory>
+#include <optional>
 
 namespace llvm {
 
@@ -30,11 +30,11 @@ template <class RefType, class StreamType> class BinaryStreamRefBase {
   }
 
   BinaryStreamRefBase(std::shared_ptr<StreamType> SharedImpl, uint64_t Offset,
-                      Optional<uint64_t> Length)
+                      std::optional<uint64_t> Length)
       : SharedImpl(SharedImpl), BorrowedImpl(SharedImpl.get()),
         ViewOffset(Offset), Length(Length) {}
   BinaryStreamRefBase(StreamType &BorrowedImpl, uint64_t Offset,
-                      Optional<uint64_t> Length)
+                      std::optional<uint64_t> Length)
       : BorrowedImpl(&BorrowedImpl), ViewOffset(Offset), Length(Length) {}
   BinaryStreamRefBase(const BinaryStreamRefBase &Other) = default;
   BinaryStreamRefBase &operator=(const BinaryStreamRefBase &Other) = default;
@@ -142,7 +142,7 @@ template <class RefType, class StreamType> class BinaryStreamRefBase {
   std::shared_ptr<StreamType> SharedImpl;
   StreamType *BorrowedImpl = nullptr;
   uint64_t ViewOffset = 0;
-  Optional<uint64_t> Length;
+  std::optional<uint64_t> Length;
 };
 
 /// BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.  It
@@ -157,14 +157,14 @@ class BinaryStreamRef
   friend BinaryStreamRefBase<BinaryStreamRef, BinaryStream>;
   friend class WritableBinaryStreamRef;
   BinaryStreamRef(std::shared_ptr<BinaryStream> Impl, uint64_t ViewOffset,
-                  Optional<uint64_t> Length)
+                  std::optional<uint64_t> Length)
       : BinaryStreamRefBase(Impl, ViewOffset, Length) {}
 
 public:
   BinaryStreamRef() = default;
   BinaryStreamRef(BinaryStream &Stream);
   BinaryStreamRef(BinaryStream &Stream, uint64_t Offset,
-                  Optional<uint64_t> Length);
+                  std::optional<uint64_t> Length);
   explicit BinaryStreamRef(ArrayRef<uint8_t> Data,
                            llvm::support::endianness Endian);
   explicit BinaryStreamRef(StringRef Data, llvm::support::endianness Endian);
@@ -222,7 +222,7 @@ class WritableBinaryStreamRef
                                  WritableBinaryStream> {
   friend BinaryStreamRefBase<WritableBinaryStreamRef, WritableBinaryStream>;
   WritableBinaryStreamRef(std::shared_ptr<WritableBinaryStream> Impl,
-                          uint64_t ViewOffset, Optional<uint64_t> Length)
+                          uint64_t ViewOffset, std::optional<uint64_t> Length)
       : BinaryStreamRefBase(Impl, ViewOffset, Length) {}
 
   Error checkOffsetForWrite(uint64_t Offset, uint64_t DataSize) const {
@@ -238,7 +238,7 @@ class WritableBinaryStreamRef
   WritableBinaryStreamRef() = default;
   WritableBinaryStreamRef(WritableBinaryStream &Stream);
   WritableBinaryStreamRef(WritableBinaryStream &Stream, uint64_t Offset,
-                          Optional<uint64_t> Length);
+                          std::optional<uint64_t> Length);
   explicit WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data,
                                    llvm::support::endianness Endian);
   WritableBinaryStreamRef(const WritableBinaryStreamRef &Other) = default;

diff  --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h
index 8a2fa94f9cca..9d1228b5a134 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -14,11 +14,11 @@
 #ifndef LLVM_SUPPORT_CASTING_H
 #define LLVM_SUPPORT_CASTING_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/type_traits.h"
 #include <cassert>
 #include <memory>
+#include <optional>
 #include <type_traits>
 
 namespace llvm {
@@ -263,8 +263,8 @@ struct CastIsPossible {
 // over. In fact, some of the isa_impl templates should be moved over to
 // CastIsPossible.
 template <typename To, typename From>
-struct CastIsPossible<To, Optional<From>> {
-  static inline bool isPossible(const Optional<From> &f) {
+struct CastIsPossible<To, std::optional<From>> {
+  static inline bool isPossible(const std::optional<From> &f) {
     assert(f && "CastIsPossible::isPossible called on a nullopt!");
     return isa_impl_wrap<
         To, const From,
@@ -359,18 +359,18 @@ struct UniquePtrCast : public CastIsPossible<To, From *> {
   }
 };
 
-/// This cast trait provides Optional<T> casting. This means that if you have a
-/// value type, you can cast it to another value type and have dyn_cast return
-/// an Optional<T>.
+/// This cast trait provides std::optional<T> casting. This means that if you
+/// have a value type, you can cast it to another value type and have dyn_cast
+/// return an std::optional<T>.
 template <typename To, typename From, typename Derived = void>
 struct OptionalValueCast
     : public CastIsPossible<To, From>,
       public DefaultDoCastIfPossible<
-          Optional<To>, From,
+          std::optional<To>, From,
           detail::SelfType<Derived, OptionalValueCast<To, From>>> {
-  static inline Optional<To> castFailed() { return Optional<To>{}; }
+  static inline std::optional<To> castFailed() { return std::optional<To>{}; }
 
-  static inline Optional<To> doCast(const From &f) { return To(f); }
+  static inline std::optional<To> doCast(const From &f) { return To(f); }
 };
 
 /// Provides a cast trait that strips `const` from types to make it easier to
@@ -533,11 +533,12 @@ struct CastInfo<To, From, std::enable_if_t<!is_simple_type<From>::value>> {
 template <typename To, typename From>
 struct CastInfo<To, std::unique_ptr<From>> : public UniquePtrCast<To, From> {};
 
-/// Provide a CastInfo specialized for Optional<From>. It's assumed that if the
-/// input is Optional<From> that the output can be Optional<To>. If that's not
-/// the case, specialize CastInfo for your use case.
+/// Provide a CastInfo specialized for std::optional<From>. It's assumed that if
+/// the input is std::optional<From> that the output can be std::optional<To>.
+/// If that's not the case, specialize CastInfo for your use case.
 template <typename To, typename From>
-struct CastInfo<To, Optional<From>> : public OptionalValueCast<To, From> {};
+struct CastInfo<To, std::optional<From>> : public OptionalValueCast<To, From> {
+};
 
 /// isa<X> - Return true if the parameter to the template is an instance of one
 /// of the template type arguments.  Used like this:
@@ -606,10 +607,14 @@ template <typename T, typename Enable = void> struct ValueIsPresent {
 };
 
 // Optional provides its own way to check if something is present.
-template <typename T> struct ValueIsPresent<Optional<T>> {
+template <typename T> struct ValueIsPresent<std::optional<T>> {
   using UnwrappedType = T;
-  static inline bool isPresent(const Optional<T> &t) { return t.has_value(); }
-  static inline decltype(auto) unwrapValue(Optional<T> &t) { return t.value(); }
+  static inline bool isPresent(const std::optional<T> &t) {
+    return t.has_value();
+  }
+  static inline decltype(auto) unwrapValue(std::optional<T> &t) {
+    return t.value();
+  }
 };
 
 // If something is "nullable" then we just compare it to nullptr to see if it

diff  --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index c5eb4b3bf4d7..d821ab5b88fe 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -1039,7 +1039,7 @@ inline std::string toString(Error E) {
 ///
 /// Uses of this method are potentially indicative of design problems: If it's
 /// legitimate to do nothing while processing an "error", the error-producer
-/// might be more clearly refactored to return an Optional<T>.
+/// might be more clearly refactored to return an std::optional<T>.
 inline void consumeError(Error Err) {
   handleAllErrors(std::move(Err), [](const ErrorInfoBase &) {});
 }
@@ -1298,7 +1298,7 @@ class FileError final : public ErrorInfo<FileError> {
   static char ID;
 
 private:
-  FileError(const Twine &F, Optional<size_t> LineNum,
+  FileError(const Twine &F, std::optional<size_t> LineNum,
             std::unique_ptr<ErrorInfoBase> E) {
     assert(E && "Cannot create FileError from Error success value.");
     FileName = F.str();
@@ -1306,7 +1306,7 @@ class FileError final : public ErrorInfo<FileError> {
     Line = std::move(LineNum);
   }
 
-  static Error build(const Twine &F, Optional<size_t> Line, Error E) {
+  static Error build(const Twine &F, std::optional<size_t> Line, Error E) {
     std::unique_ptr<ErrorInfoBase> Payload;
     handleAllErrors(std::move(E),
                     [&](std::unique_ptr<ErrorInfoBase> EIB) -> Error {
@@ -1318,20 +1318,20 @@ class FileError final : public ErrorInfo<FileError> {
   }
 
   std::string FileName;
-  Optional<size_t> Line;
+  std::optional<size_t> Line;
   std::unique_ptr<ErrorInfoBase> Err;
 };
 
 /// Concatenate a source file path and/or name with an Error. The resulting
 /// Error is unchecked.
 inline Error createFileError(const Twine &F, Error E) {
-  return FileError::build(F, Optional<size_t>(), std::move(E));
+  return FileError::build(F, std::optional<size_t>(), std::move(E));
 }
 
 /// Concatenate a source file path and/or name with line number and an Error.
 /// The resulting Error is unchecked.
 inline Error createFileError(const Twine &F, size_t Line, Error E) {
-  return FileError::build(F, Optional<size_t>(Line), std::move(E));
+  return FileError::build(F, std::optional<size_t>(Line), std::move(E));
 }
 
 /// Concatenate a source file path and/or name with a std::error_code 

diff  --git a/llvm/include/llvm/Support/FileUtilities.h b/llvm/include/llvm/Support/FileUtilities.h
index b641781da4ab..c9a72d5d14ec 100644
--- a/llvm/include/llvm/Support/FileUtilities.h
+++ b/llvm/include/llvm/Support/FileUtilities.h
@@ -121,8 +121,9 @@ namespace llvm {
     /// Apply stored permissions to the \p OutputFilename.
     /// Copy LastAccess and ModificationTime if \p CopyDates is true.
     /// Overwrite stored permissions if \p OverwritePermissions is specified.
-    Error apply(StringRef OutputFilename, bool CopyDates = false,
-                Optional<sys::fs::perms> OverwritePermissions = std::nullopt);
+    Error
+    apply(StringRef OutputFilename, bool CopyDates = false,
+          std::optional<sys::fs::perms> OverwritePermissions = std::nullopt);
 
   private:
     FilePermissionsApplier(StringRef InputFilename, sys::fs::file_status Status)

diff  --git a/llvm/include/llvm/Support/FormatProviders.h b/llvm/include/llvm/Support/FormatProviders.h
index ab1245cfd4c0..3fcd1b38a967 100644
--- a/llvm/include/llvm/Support/FormatProviders.h
+++ b/llvm/include/llvm/Support/FormatProviders.h
@@ -59,9 +59,9 @@ struct use_double_formatter
 
 class HelperFunctions {
 protected:
-  static Optional<size_t> parseNumericPrecision(StringRef Str) {
+  static std::optional<size_t> parseNumericPrecision(StringRef Str) {
     size_t Prec;
-    Optional<size_t> Result;
+    std::optional<size_t> Result;
     if (Str.empty())
       Result = std::nullopt;
     else if (Str.getAsInteger(10, Prec)) {
@@ -312,7 +312,7 @@ struct format_provider<T,
     else
       S = FloatStyle::Fixed;
 
-    Optional<size_t> Precision = parseNumericPrecision(Style);
+    std::optional<size_t> Precision = parseNumericPrecision(Style);
     if (!Precision)
       Precision = getDefaultPrecision(S);
 

diff  --git a/llvm/include/llvm/Support/FormatVariadic.h b/llvm/include/llvm/Support/FormatVariadic.h
index bc5cd3edf66f..ddd80d89f1cd 100644
--- a/llvm/include/llvm/Support/FormatVariadic.h
+++ b/llvm/include/llvm/Support/FormatVariadic.h
@@ -26,7 +26,6 @@
 #define LLVM_SUPPORT_FORMATVARIADIC_H
 
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -37,6 +36,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include <array>
 #include <cstddef>
+#include <optional>
 #include <string>
 #include <tuple>
 #include <utility>
@@ -103,7 +103,7 @@ class formatv_object_base {
   }
   static SmallVector<ReplacementItem, 2> parseFormatString(StringRef Fmt);
 
-  static Optional<ReplacementItem> parseReplacementItem(StringRef Spec);
+  static std::optional<ReplacementItem> parseReplacementItem(StringRef Spec);
 
   std::string str() const {
     std::string Result;

diff  --git a/llvm/include/llvm/Support/KnownBits.h b/llvm/include/llvm/Support/KnownBits.h
index dbb3237bc59e..f20d3e112b83 100644
--- a/llvm/include/llvm/Support/KnownBits.h
+++ b/llvm/include/llvm/Support/KnownBits.h
@@ -15,7 +15,7 @@
 #define LLVM_SUPPORT_KNOWNBITS_H
 
 #include "llvm/ADT/APInt.h"
-#include "llvm/ADT/Optional.h"
+#include <optional>
 
 namespace llvm {
 
@@ -373,34 +373,34 @@ struct KnownBits {
   static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Determine if these known bits always give the same ICMP_EQ result.
-  static Optional<bool> eq(const KnownBits &LHS, const KnownBits &RHS);
+  static std::optional<bool> eq(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Determine if these known bits always give the same ICMP_NE result.
-  static Optional<bool> ne(const KnownBits &LHS, const KnownBits &RHS);
+  static std::optional<bool> ne(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Determine if these known bits always give the same ICMP_UGT result.
-  static Optional<bool> ugt(const KnownBits &LHS, const KnownBits &RHS);
+  static std::optional<bool> ugt(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Determine if these known bits always give the same ICMP_UGE result.
-  static Optional<bool> uge(const KnownBits &LHS, const KnownBits &RHS);
+  static std::optional<bool> uge(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Determine if these known bits always give the same ICMP_ULT result.
-  static Optional<bool> ult(const KnownBits &LHS, const KnownBits &RHS);
+  static std::optional<bool> ult(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Determine if these known bits always give the same ICMP_ULE result.
-  static Optional<bool> ule(const KnownBits &LHS, const KnownBits &RHS);
+  static std::optional<bool> ule(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Determine if these known bits always give the same ICMP_SGT result.
-  static Optional<bool> sgt(const KnownBits &LHS, const KnownBits &RHS);
+  static std::optional<bool> sgt(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Determine if these known bits always give the same ICMP_SGE result.
-  static Optional<bool> sge(const KnownBits &LHS, const KnownBits &RHS);
+  static std::optional<bool> sge(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Determine if these known bits always give the same ICMP_SLT result.
-  static Optional<bool> slt(const KnownBits &LHS, const KnownBits &RHS);
+  static std::optional<bool> slt(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Determine if these known bits always give the same ICMP_SLE result.
-  static Optional<bool> sle(const KnownBits &LHS, const KnownBits &RHS);
+  static std::optional<bool> sle(const KnownBits &LHS, const KnownBits &RHS);
 
   /// Update known bits based on ANDing with RHS.
   KnownBits &operator&=(const KnownBits &RHS);

diff  --git a/llvm/include/llvm/Support/LockFileManager.h b/llvm/include/llvm/Support/LockFileManager.h
index ab66621e6756..92c7ceed6a92 100644
--- a/llvm/include/llvm/Support/LockFileManager.h
+++ b/llvm/include/llvm/Support/LockFileManager.h
@@ -8,8 +8,8 @@
 #ifndef LLVM_SUPPORT_LOCKFILEMANAGER_H
 #define LLVM_SUPPORT_LOCKFILEMANAGER_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallString.h"
+#include <optional>
 #include <system_error>
 #include <utility> // for std::pair
 
@@ -54,14 +54,14 @@ class LockFileManager {
   SmallString<128> LockFileName;
   SmallString<128> UniqueLockFileName;
 
-  Optional<std::pair<std::string, int> > Owner;
+  std::optional<std::pair<std::string, int>> Owner;
   std::error_code ErrorCode;
   std::string ErrorDiagMsg;
 
   LockFileManager(const LockFileManager &) = delete;
   LockFileManager &operator=(const LockFileManager &) = delete;
 
-  static Optional<std::pair<std::string, int> >
+  static std::optional<std::pair<std::string, int>>
   readLockFile(StringRef LockFileName);
 
   static bool processStillExecuting(StringRef Hostname, int PID);

diff  --git a/llvm/include/llvm/Support/MemoryBuffer.h b/llvm/include/llvm/Support/MemoryBuffer.h
index d6ae98e341f0..b3477f1db0e9 100644
--- a/llvm/include/llvm/Support/MemoryBuffer.h
+++ b/llvm/include/llvm/Support/MemoryBuffer.h
@@ -97,7 +97,7 @@ class MemoryBuffer {
   static ErrorOr<std::unique_ptr<MemoryBuffer>>
   getFile(const Twine &Filename, bool IsText = false,
           bool RequiresNullTerminator = true, bool IsVolatile = false,
-          Optional<Align> Alignment = std::nullopt);
+          std::optional<Align> Alignment = std::nullopt);
 
   /// Read all of the specified file into a MemoryBuffer as a stream
   /// (i.e. until EOF reached). This is useful for special files that
@@ -111,7 +111,7 @@ class MemoryBuffer {
   static ErrorOr<std::unique_ptr<MemoryBuffer>>
   getOpenFileSlice(sys::fs::file_t FD, const Twine &Filename, uint64_t MapSize,
                    int64_t Offset, bool IsVolatile = false,
-                   Optional<Align> Alignment = std::nullopt);
+                   std::optional<Align> Alignment = std::nullopt);
 
   /// Given an already-open file descriptor, read the file and return a
   /// MemoryBuffer.
@@ -125,7 +125,7 @@ class MemoryBuffer {
   static ErrorOr<std::unique_ptr<MemoryBuffer>>
   getOpenFile(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
               bool RequiresNullTerminator = true, bool IsVolatile = false,
-              Optional<Align> Alignment = std::nullopt);
+              std::optional<Align> Alignment = std::nullopt);
 
   /// Open the specified memory range as a MemoryBuffer. Note that InputData
   /// must be null terminated if RequiresNullTerminator is true.
@@ -149,13 +149,13 @@ class MemoryBuffer {
   static ErrorOr<std::unique_ptr<MemoryBuffer>>
   getFileOrSTDIN(const Twine &Filename, bool IsText = false,
                  bool RequiresNullTerminator = true,
-                 Optional<Align> Alignment = std::nullopt);
+                 std::optional<Align> Alignment = std::nullopt);
 
   /// Map a subrange of the specified file as a MemoryBuffer.
   static ErrorOr<std::unique_ptr<MemoryBuffer>>
   getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
                bool IsVolatile = false,
-               Optional<Align> Alignment = std::nullopt);
+               std::optional<Align> Alignment = std::nullopt);
 
   //===--------------------------------------------------------------------===//
   // Provided for performance analysis.
@@ -201,13 +201,13 @@ class WritableMemoryBuffer : public MemoryBuffer {
 
   static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
   getFile(const Twine &Filename, bool IsVolatile = false,
-          Optional<Align> Alignment = std::nullopt);
+          std::optional<Align> Alignment = std::nullopt);
 
   /// Map a subrange of the specified file as a WritableMemoryBuffer.
   static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
   getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
                bool IsVolatile = false,
-               Optional<Align> Alignment = std::nullopt);
+               std::optional<Align> Alignment = std::nullopt);
 
   /// Allocate a new MemoryBuffer of the specified size that is not initialized.
   /// Note that the caller should initialize the memory allocated by this
@@ -217,7 +217,7 @@ class WritableMemoryBuffer : public MemoryBuffer {
   /// least the specified alignment.
   static std::unique_ptr<WritableMemoryBuffer>
   getNewUninitMemBuffer(size_t Size, const Twine &BufferName = "",
-                        Optional<Align> Alignment = std::nullopt);
+                        std::optional<Align> Alignment = std::nullopt);
 
   /// Allocate a new zero-initialized MemoryBuffer of the specified size. Note
   /// that the caller need not initialize the memory allocated by this method.

diff  --git a/llvm/include/llvm/Support/NativeFormatting.h b/llvm/include/llvm/Support/NativeFormatting.h
index f94b0174edd4..6fc1ee8d190e 100644
--- a/llvm/include/llvm/Support/NativeFormatting.h
+++ b/llvm/include/llvm/Support/NativeFormatting.h
@@ -38,9 +38,9 @@ void write_integer(raw_ostream &S, long long N, size_t MinDigits,
                    IntegerStyle Style);
 
 void write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style,
-               Optional<size_t> Width = std::nullopt);
+               std::optional<size_t> Width = std::nullopt);
 void write_double(raw_ostream &S, double D, FloatStyle Style,
-                  Optional<size_t> Precision = std::nullopt);
+                  std::optional<size_t> Precision = std::nullopt);
 }
 
 #endif

diff  --git a/llvm/include/llvm/Support/SMTAPI.h b/llvm/include/llvm/Support/SMTAPI.h
index 24dcd124593e..9389c96956dd 100644
--- a/llvm/include/llvm/Support/SMTAPI.h
+++ b/llvm/include/llvm/Support/SMTAPI.h
@@ -419,7 +419,7 @@ class SMTSolver {
                                  llvm::APFloat &Float) = 0;
 
   /// Check if the constraints are satisfiable
-  virtual Optional<bool> check() const = 0;
+  virtual std::optional<bool> check() const = 0;
 
   /// Push the current solver state
   virtual void push() = 0;

diff  --git a/llvm/include/llvm/Support/Unicode.h b/llvm/include/llvm/Support/Unicode.h
index 729775431e16..861548728d4f 100644
--- a/llvm/include/llvm/Support/Unicode.h
+++ b/llvm/include/llvm/Support/Unicode.h
@@ -14,8 +14,8 @@
 #ifndef LLVM_SUPPORT_UNICODE_H
 #define LLVM_SUPPORT_UNICODE_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallString.h"
+#include <optional>
 #include <string>
 
 namespace llvm {
@@ -67,14 +67,14 @@ int foldCharSimple(int C);
 /// For compatibility with the semantics of named character escape sequences in
 /// C++, this mapping does an exact match sensitive to casing and spacing.
 /// \return The codepoint of the corresponding character, if any.
-Optional<char32_t> nameToCodepointStrict(StringRef Name);
+std::optional<char32_t> nameToCodepointStrict(StringRef Name);
 
 struct LooseMatchingResult {
   char32_t CodePoint;
   SmallString<64> Name;
 };
 
-Optional<LooseMatchingResult> nameToCodepointLooseMatching(StringRef Name);
+std::optional<LooseMatchingResult> nameToCodepointLooseMatching(StringRef Name);
 
 struct MatchForCodepointName {
   std::string Name;

diff  --git a/llvm/include/llvm/Support/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h
index a525fbe7009f..1483252f4f7d 100644
--- a/llvm/include/llvm/Support/VersionTuple.h
+++ b/llvm/include/llvm/Support/VersionTuple.h
@@ -72,21 +72,21 @@ class VersionTuple {
   unsigned getMajor() const { return Major; }
 
   /// Retrieve the minor version number, if provided.
-  Optional<unsigned> getMinor() const {
+  std::optional<unsigned> getMinor() const {
     if (!HasMinor)
       return std::nullopt;
     return Minor;
   }
 
   /// Retrieve the subminor version number, if provided.
-  Optional<unsigned> getSubminor() const {
+  std::optional<unsigned> getSubminor() const {
     if (!HasSubminor)
       return std::nullopt;
     return Subminor;
   }
 
   /// Retrieve the build version number, if provided.
-  Optional<unsigned> getBuild() const {
+  std::optional<unsigned> getBuild() const {
     if (!HasBuild)
       return std::nullopt;
     return Build;

diff  --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h
index a2ce22ebd5af..295ed63def9b 100644
--- a/llvm/include/llvm/Support/VirtualFileSystem.h
+++ b/llvm/include/llvm/Support/VirtualFileSystem.h
@@ -509,9 +509,9 @@ class InMemoryFileSystem : public FileSystem {
   /// Create node with \p MakeNode and add it into this filesystem at \p Path.
   bool addFile(const Twine &Path, time_t ModificationTime,
                std::unique_ptr<llvm::MemoryBuffer> Buffer,
-               Optional<uint32_t> User, Optional<uint32_t> Group,
-               Optional<llvm::sys::fs::file_type> Type,
-               Optional<llvm::sys::fs::perms> Perms, MakeNodeFn MakeNode);
+               std::optional<uint32_t> User, std::optional<uint32_t> Group,
+               std::optional<llvm::sys::fs::file_type> Type,
+               std::optional<llvm::sys::fs::perms> Perms, MakeNodeFn MakeNode);
 
   /// Looks up the in-memory node for the path \p P.
   /// If \p FollowFinalSymlink is true, the returned node is guaranteed to
@@ -533,10 +533,10 @@ class InMemoryFileSystem : public FileSystem {
   /// 
diff erent contents.
   bool addFile(const Twine &Path, time_t ModificationTime,
                std::unique_ptr<llvm::MemoryBuffer> Buffer,
-               Optional<uint32_t> User = std::nullopt,
-               Optional<uint32_t> Group = std::nullopt,
-               Optional<llvm::sys::fs::file_type> Type = std::nullopt,
-               Optional<llvm::sys::fs::perms> Perms = std::nullopt);
+               std::optional<uint32_t> User = std::nullopt,
+               std::optional<uint32_t> Group = std::nullopt,
+               std::optional<llvm::sys::fs::file_type> Type = std::nullopt,
+               std::optional<llvm::sys::fs::perms> Perms = std::nullopt);
 
   /// Add a hard link to a file.
   ///
@@ -561,11 +561,12 @@ class InMemoryFileSystem : public FileSystem {
   /// Add a symbolic link. Unlike a HardLink, because \p Target doesn't need
   /// to refer to a file (or refer to anything, as it happens). Also, an
   /// in-memory directory for \p Target isn't automatically created.
-  bool addSymbolicLink(const Twine &NewLink, const Twine &Target,
-                       time_t ModificationTime,
-                       Optional<uint32_t> User = std::nullopt,
-                       Optional<uint32_t> Group = std::nullopt,
-                       Optional<llvm::sys::fs::perms> Perms = std::nullopt);
+  bool
+  addSymbolicLink(const Twine &NewLink, const Twine &Target,
+                  time_t ModificationTime,
+                  std::optional<uint32_t> User = std::nullopt,
+                  std::optional<uint32_t> Group = std::nullopt,
+                  std::optional<llvm::sys::fs::perms> Perms = std::nullopt);
 
   /// Add a buffer to the VFS with a path. The VFS does not own the buffer.
   /// If present, User, Group, Type and Perms apply to the newly-created file
@@ -575,10 +576,10 @@ class InMemoryFileSystem : public FileSystem {
   /// 
diff erent contents.
   bool addFileNoOwn(const Twine &Path, time_t ModificationTime,
                     const llvm::MemoryBufferRef &Buffer,
-                    Optional<uint32_t> User = std::nullopt,
-                    Optional<uint32_t> Group = std::nullopt,
-                    Optional<llvm::sys::fs::file_type> Type = std::nullopt,
-                    Optional<llvm::sys::fs::perms> Perms = std::nullopt);
+                    std::optional<uint32_t> User = std::nullopt,
+                    std::optional<uint32_t> Group = std::nullopt,
+                    std::optional<llvm::sys::fs::file_type> Type = std::nullopt,
+                    std::optional<llvm::sys::fs::perms> Perms = std::nullopt);
 
   std::string toString() const;
 
@@ -858,7 +859,7 @@ class RedirectingFileSystem : public vfs::FileSystem {
     /// When the found Entry is a DirectoryRemapEntry, stores the path in the
     /// external file system that the looked-up path in the virtual file system
     //  corresponds to.
-    Optional<std::string> ExternalRedirect;
+    std::optional<std::string> ExternalRedirect;
 
   public:
     LookupResult(Entry *E, sys::path::const_iterator Start,
@@ -867,7 +868,7 @@ class RedirectingFileSystem : public vfs::FileSystem {
     /// If the found Entry maps the the input path to a path in the external
     /// file system (i.e. it is a FileEntry or DirectoryRemapEntry), returns
     /// that path.
-    Optional<StringRef> getExternalRedirect() const {
+    std::optional<StringRef> getExternalRedirect() const {
       if (isa<DirectoryRemapEntry>(E))
         return StringRef(*ExternalRedirect);
       if (auto *FE = dyn_cast<FileEntry>(E))
@@ -1016,9 +1017,9 @@ void collectVFSFromYAML(
 
 class YAMLVFSWriter {
   std::vector<YAMLVFSEntry> Mappings;
-  Optional<bool> IsCaseSensitive;
-  Optional<bool> IsOverlayRelative;
-  Optional<bool> UseExternalNames;
+  std::optional<bool> IsCaseSensitive;
+  std::optional<bool> IsOverlayRelative;
+  std::optional<bool> UseExternalNames;
   std::string OverlayDir;
 
   void addEntry(StringRef VirtualPath, StringRef RealPath, bool IsDirectory);

diff  --git a/llvm/include/llvm/Support/thread.h b/llvm/include/llvm/Support/thread.h
index 660d31573a86..32599b9f7121 100644
--- a/llvm/include/llvm/Support/thread.h
+++ b/llvm/include/llvm/Support/thread.h
@@ -16,8 +16,8 @@
 #ifndef LLVM_SUPPORT_THREAD_H
 #define LLVM_SUPPORT_THREAD_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/Config/llvm-config.h"
+#include <optional>
 
 #ifdef _WIN32
 typedef unsigned long DWORD;
@@ -72,7 +72,7 @@ class thread {
   }
 #endif
 
-  static const llvm::Optional<unsigned> DefaultStackSize;
+  static const std::optional<unsigned> DefaultStackSize;
 
   thread() : Thread(native_handle_type()) {}
   thread(thread &&Other) noexcept
@@ -83,7 +83,7 @@ class thread {
       : thread(DefaultStackSize, f, args...) {}
 
   template <class Function, class... Args>
-  explicit thread(llvm::Optional<unsigned> StackSizeInBytes, Function &&f,
+  explicit thread(std::optional<unsigned> StackSizeInBytes, Function &&f,
                   Args &&...args);
   thread(const thread &) = delete;
 
@@ -120,14 +120,14 @@ class thread {
 
 thread::native_handle_type
 llvm_execute_on_thread_impl(thread::start_routine_type ThreadFunc, void *Arg,
-                            llvm::Optional<unsigned> StackSizeInBytes);
+                            std::optional<unsigned> StackSizeInBytes);
 void llvm_thread_join_impl(thread::native_handle_type Thread);
 void llvm_thread_detach_impl(thread::native_handle_type Thread);
 thread::id llvm_thread_get_id_impl(thread::native_handle_type Thread);
 thread::id llvm_thread_get_current_id_impl();
 
 template <class Function, class... Args>
-thread::thread(llvm::Optional<unsigned> StackSizeInBytes, Function &&f,
+thread::thread(std::optional<unsigned> StackSizeInBytes, Function &&f,
                Args &&...args) {
   typedef std::tuple<std::decay_t<Function>, std::decay_t<Args>...> CalleeTuple;
   std::unique_ptr<CalleeTuple> Callee(
@@ -171,7 +171,7 @@ class thread {
       : Thread(std::exchange(Other.Thread, std::thread())) {}
 
   template <class Function, class... Args>
-  explicit thread(llvm::Optional<unsigned> StackSizeInBytes, Function &&f,
+  explicit thread(std::optional<unsigned> StackSizeInBytes, Function &&f,
                   Args &&...args)
       : Thread(std::forward<Function>(f), std::forward<Args>(args)...) {}
 
@@ -224,7 +224,7 @@ struct thread {
   thread() {}
   thread(thread &&other) {}
   template <class Function, class... Args>
-  explicit thread(llvm::Optional<unsigned> StackSizeInBytes, Function &&f,
+  explicit thread(std::optional<unsigned> StackSizeInBytes, Function &&f,
                   Args &&...args) {
     f(std::forward<Args>(args)...);
   }

diff  --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index c5d5d68d849c..5ff3dd26f5fc 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -4216,7 +4216,7 @@ bool CombinerHelper::matchICmpToTrueFalseKnownBits(MachineInstr &MI,
   auto Pred = static_cast<CmpInst::Predicate>(MI.getOperand(1).getPredicate());
   auto KnownLHS = KB->getKnownBits(MI.getOperand(2).getReg());
   auto KnownRHS = KB->getKnownBits(MI.getOperand(3).getReg());
-  Optional<bool> KnownVal;
+  std::optional<bool> KnownVal;
   switch (Pred) {
   default:
     llvm_unreachable("Unexpected G_ICMP predicate?");

diff  --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index a0e7705e5843..a7716e893aa1 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -2103,9 +2103,9 @@ bool TargetLowering::SimplifyDemandedBits(
     KnownBits Known0 = TLO.DAG.computeKnownBits(Op0, DemandedElts, Depth + 1);
     KnownBits Known1 = TLO.DAG.computeKnownBits(Op1, DemandedElts, Depth + 1);
     Known = KnownBits::umin(Known0, Known1);
-    if (Optional<bool> IsULE = KnownBits::ule(Known0, Known1))
+    if (std::optional<bool> IsULE = KnownBits::ule(Known0, Known1))
       return TLO.CombineTo(Op, IsULE.value() ? Op0 : Op1);
-    if (Optional<bool> IsULT = KnownBits::ult(Known0, Known1))
+    if (std::optional<bool> IsULT = KnownBits::ult(Known0, Known1))
       return TLO.CombineTo(Op, IsULT.value() ? Op0 : Op1);
     break;
   }
@@ -2116,9 +2116,9 @@ bool TargetLowering::SimplifyDemandedBits(
     KnownBits Known0 = TLO.DAG.computeKnownBits(Op0, DemandedElts, Depth + 1);
     KnownBits Known1 = TLO.DAG.computeKnownBits(Op1, DemandedElts, Depth + 1);
     Known = KnownBits::umax(Known0, Known1);
-    if (Optional<bool> IsUGE = KnownBits::uge(Known0, Known1))
+    if (std::optional<bool> IsUGE = KnownBits::uge(Known0, Known1))
       return TLO.CombineTo(Op, IsUGE.value() ? Op0 : Op1);
-    if (Optional<bool> IsUGT = KnownBits::ugt(Known0, Known1))
+    if (std::optional<bool> IsUGT = KnownBits::ugt(Known0, Known1))
       return TLO.CombineTo(Op, IsUGT.value() ? Op0 : Op1);
     break;
   }

diff  --git a/llvm/lib/Support/BinaryStreamRef.cpp b/llvm/lib/Support/BinaryStreamRef.cpp
index 6d79d95e1bf0..06b4999d949b 100644
--- a/llvm/lib/Support/BinaryStreamRef.cpp
+++ b/llvm/lib/Support/BinaryStreamRef.cpp
@@ -67,7 +67,7 @@ class MutableArrayRefImpl : public WritableBinaryStream {
 BinaryStreamRef::BinaryStreamRef(BinaryStream &Stream)
     : BinaryStreamRefBase(Stream) {}
 BinaryStreamRef::BinaryStreamRef(BinaryStream &Stream, uint64_t Offset,
-                                 Optional<uint64_t> Length)
+                                 std::optional<uint64_t> Length)
     : BinaryStreamRefBase(Stream, Offset, Length) {}
 BinaryStreamRef::BinaryStreamRef(ArrayRef<uint8_t> Data, endianness Endian)
     : BinaryStreamRefBase(std::make_shared<ArrayRefImpl>(Data, Endian), 0,
@@ -105,7 +105,7 @@ WritableBinaryStreamRef::WritableBinaryStreamRef(WritableBinaryStream &Stream)
 
 WritableBinaryStreamRef::WritableBinaryStreamRef(WritableBinaryStream &Stream,
                                                  uint64_t Offset,
-                                                 Optional<uint64_t> Length)
+                                                 std::optional<uint64_t> Length)
     : BinaryStreamRefBase(Stream, Offset, Length) {}
 
 WritableBinaryStreamRef::WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data,

diff  --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp
index 7fe09eb95892..c7c384c9edc2 100644
--- a/llvm/lib/Support/CrashRecoveryContext.cpp
+++ b/llvm/lib/Support/CrashRecoveryContext.cpp
@@ -519,7 +519,7 @@ bool CrashRecoveryContext::RunSafelyOnThread(function_ref<void()> Fn,
   RunSafelyOnThreadInfo Info = { Fn, this, UseBackgroundPriority, false };
   llvm::thread Thread(RequestedStackSize == 0
                           ? std::nullopt
-                          : llvm::Optional<unsigned>(RequestedStackSize),
+                          : std::optional<unsigned>(RequestedStackSize),
                       RunSafelyOnThread_Dispatch, &Info);
   Thread.join();
 

diff  --git a/llvm/lib/Support/DJB.cpp b/llvm/lib/Support/DJB.cpp
index 2701d5da2fb2..b9d159cdb3a6 100644
--- a/llvm/lib/Support/DJB.cpp
+++ b/llvm/lib/Support/DJB.cpp
@@ -57,7 +57,8 @@ static UTF32 foldCharDwarf(UTF32 C) {
   return sys::unicode::foldCharSimple(C);
 }
 
-static Optional<uint32_t> fastCaseFoldingDjbHash(StringRef Buffer, uint32_t H) {
+static std::optional<uint32_t> fastCaseFoldingDjbHash(StringRef Buffer,
+                                                      uint32_t H) {
   bool AllASCII = true;
   for (unsigned char C : Buffer) {
     H = H * 33 + ('A' <= C && C <= 'Z' ? C - 'A' + 'a' : C);
@@ -69,7 +70,7 @@ static Optional<uint32_t> fastCaseFoldingDjbHash(StringRef Buffer, uint32_t H) {
 }
 
 uint32_t llvm::caseFoldingDjbHash(StringRef Buffer, uint32_t H) {
-  if (Optional<uint32_t> Result = fastCaseFoldingDjbHash(Buffer, H))
+  if (std::optional<uint32_t> Result = fastCaseFoldingDjbHash(Buffer, H))
     return *Result;
 
   std::array<UTF8, UNI_MAX_UTF8_BYTES_PER_CODE_POINT> Storage;

diff  --git a/llvm/lib/Support/FileUtilities.cpp b/llvm/lib/Support/FileUtilities.cpp
index 24960cc96bde..d01a41a46489 100644
--- a/llvm/lib/Support/FileUtilities.cpp
+++ b/llvm/lib/Support/FileUtilities.cpp
@@ -341,7 +341,7 @@ FilePermissionsApplier::create(StringRef InputFilename) {
 
 Error FilePermissionsApplier::apply(
     StringRef OutputFilename, bool CopyDates,
-    Optional<sys::fs::perms> OverwritePermissions) {
+    std::optional<sys::fs::perms> OverwritePermissions) {
   sys::fs::file_status Status = InputStatus;
 
   if (OverwritePermissions)

diff  --git a/llvm/lib/Support/FormatVariadic.cpp b/llvm/lib/Support/FormatVariadic.cpp
index 169cea445e93..10de7f16dcf8 100644
--- a/llvm/lib/Support/FormatVariadic.cpp
+++ b/llvm/lib/Support/FormatVariadic.cpp
@@ -55,7 +55,7 @@ bool formatv_object_base::consumeFieldLayout(StringRef &Spec, AlignStyle &Where,
   return !Failed;
 }
 
-Optional<ReplacementItem>
+std::optional<ReplacementItem>
 formatv_object_base::parseReplacementItem(StringRef Spec) {
   StringRef RepString = Spec.trim("{}");
 

diff  --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp
index c62a1a35d188..745c46fb6ffb 100644
--- a/llvm/lib/Support/KnownBits.cpp
+++ b/llvm/lib/Support/KnownBits.cpp
@@ -330,65 +330,65 @@ KnownBits KnownBits::ashr(const KnownBits &LHS, const KnownBits &RHS) {
   return Known;
 }
 
-Optional<bool> KnownBits::eq(const KnownBits &LHS, const KnownBits &RHS) {
+std::optional<bool> KnownBits::eq(const KnownBits &LHS, const KnownBits &RHS) {
   if (LHS.isConstant() && RHS.isConstant())
-    return Optional<bool>(LHS.getConstant() == RHS.getConstant());
+    return std::optional<bool>(LHS.getConstant() == RHS.getConstant());
   if (LHS.One.intersects(RHS.Zero) || RHS.One.intersects(LHS.Zero))
-    return Optional<bool>(false);
+    return std::optional<bool>(false);
   return std::nullopt;
 }
 
-Optional<bool> KnownBits::ne(const KnownBits &LHS, const KnownBits &RHS) {
-  if (Optional<bool> KnownEQ = eq(LHS, RHS))
-    return Optional<bool>(!*KnownEQ);
+std::optional<bool> KnownBits::ne(const KnownBits &LHS, const KnownBits &RHS) {
+  if (std::optional<bool> KnownEQ = eq(LHS, RHS))
+    return std::optional<bool>(!*KnownEQ);
   return std::nullopt;
 }
 
-Optional<bool> KnownBits::ugt(const KnownBits &LHS, const KnownBits &RHS) {
+std::optional<bool> KnownBits::ugt(const KnownBits &LHS, const KnownBits &RHS) {
   // LHS >u RHS -> false if umax(LHS) <= umax(RHS)
   if (LHS.getMaxValue().ule(RHS.getMinValue()))
-    return Optional<bool>(false);
+    return std::optional<bool>(false);
   // LHS >u RHS -> true if umin(LHS) > umax(RHS)
   if (LHS.getMinValue().ugt(RHS.getMaxValue()))
-    return Optional<bool>(true);
+    return std::optional<bool>(true);
   return std::nullopt;
 }
 
-Optional<bool> KnownBits::uge(const KnownBits &LHS, const KnownBits &RHS) {
-  if (Optional<bool> IsUGT = ugt(RHS, LHS))
-    return Optional<bool>(!*IsUGT);
+std::optional<bool> KnownBits::uge(const KnownBits &LHS, const KnownBits &RHS) {
+  if (std::optional<bool> IsUGT = ugt(RHS, LHS))
+    return std::optional<bool>(!*IsUGT);
   return std::nullopt;
 }
 
-Optional<bool> KnownBits::ult(const KnownBits &LHS, const KnownBits &RHS) {
+std::optional<bool> KnownBits::ult(const KnownBits &LHS, const KnownBits &RHS) {
   return ugt(RHS, LHS);
 }
 
-Optional<bool> KnownBits::ule(const KnownBits &LHS, const KnownBits &RHS) {
+std::optional<bool> KnownBits::ule(const KnownBits &LHS, const KnownBits &RHS) {
   return uge(RHS, LHS);
 }
 
-Optional<bool> KnownBits::sgt(const KnownBits &LHS, const KnownBits &RHS) {
+std::optional<bool> KnownBits::sgt(const KnownBits &LHS, const KnownBits &RHS) {
   // LHS >s RHS -> false if smax(LHS) <= smax(RHS)
   if (LHS.getSignedMaxValue().sle(RHS.getSignedMinValue()))
-    return Optional<bool>(false);
+    return std::optional<bool>(false);
   // LHS >s RHS -> true if smin(LHS) > smax(RHS)
   if (LHS.getSignedMinValue().sgt(RHS.getSignedMaxValue()))
-    return Optional<bool>(true);
+    return std::optional<bool>(true);
   return std::nullopt;
 }
 
-Optional<bool> KnownBits::sge(const KnownBits &LHS, const KnownBits &RHS) {
-  if (Optional<bool> KnownSGT = sgt(RHS, LHS))
-    return Optional<bool>(!*KnownSGT);
+std::optional<bool> KnownBits::sge(const KnownBits &LHS, const KnownBits &RHS) {
+  if (std::optional<bool> KnownSGT = sgt(RHS, LHS))
+    return std::optional<bool>(!*KnownSGT);
   return std::nullopt;
 }
 
-Optional<bool> KnownBits::slt(const KnownBits &LHS, const KnownBits &RHS) {
+std::optional<bool> KnownBits::slt(const KnownBits &LHS, const KnownBits &RHS) {
   return sgt(RHS, LHS);
 }
 
-Optional<bool> KnownBits::sle(const KnownBits &LHS, const KnownBits &RHS) {
+std::optional<bool> KnownBits::sle(const KnownBits &LHS, const KnownBits &RHS) {
   return sge(RHS, LHS);
 }
 

diff  --git a/llvm/lib/Support/LockFileManager.cpp b/llvm/lib/Support/LockFileManager.cpp
index 9059473cee86..b64d48302775 100644
--- a/llvm/lib/Support/LockFileManager.cpp
+++ b/llvm/lib/Support/LockFileManager.cpp
@@ -51,7 +51,7 @@ using namespace llvm;
 /// \param LockFileName The name of the lock file to read.
 ///
 /// \returns The process ID of the process that owns this lock file
-Optional<std::pair<std::string, int> >
+std::optional<std::pair<std::string, int>>
 LockFileManager::readLockFile(StringRef LockFileName) {
   // Read the owning host and PID out of the lock file. If it appears that the
   // owning process is dead, the lock file is invalid.

diff  --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp
index 77c509cedcdb..0bb11725d2fc 100644
--- a/llvm/lib/Support/MemoryBuffer.cpp
+++ b/llvm/lib/Support/MemoryBuffer.cpp
@@ -114,7 +114,7 @@ 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,
-           Optional<Align> Alignment);
+           std::optional<Align> Alignment);
 
 std::unique_ptr<MemoryBuffer>
 MemoryBuffer::getMemBuffer(StringRef InputData, StringRef BufferName,
@@ -150,7 +150,7 @@ MemoryBuffer::getMemBufferCopy(StringRef InputData, const Twine &BufferName) {
 ErrorOr<std::unique_ptr<MemoryBuffer>>
 MemoryBuffer::getFileOrSTDIN(const Twine &Filename, bool IsText,
                              bool RequiresNullTerminator,
-                             Optional<Align> Alignment) {
+                             std::optional<Align> Alignment) {
   SmallString<256> NameBuf;
   StringRef NameRef = Filename.toStringRef(NameBuf);
 
@@ -163,7 +163,7 @@ MemoryBuffer::getFileOrSTDIN(const Twine &Filename, bool IsText,
 ErrorOr<std::unique_ptr<MemoryBuffer>>
 MemoryBuffer::getFileSlice(const Twine &FilePath, uint64_t MapSize,
                            uint64_t Offset, bool IsVolatile,
-                           Optional<Align> Alignment) {
+                           std::optional<Align> Alignment) {
   return getFileAux<MemoryBuffer>(FilePath, MapSize, Offset, /*IsText=*/false,
                                   /*RequiresNullTerminator=*/false, IsVolatile,
                                   Alignment);
@@ -247,7 +247,7 @@ getMemoryBufferForStream(sys::fs::file_t FD, const Twine &BufferName) {
 ErrorOr<std::unique_ptr<MemoryBuffer>>
 MemoryBuffer::getFile(const Twine &Filename, bool IsText,
                       bool RequiresNullTerminator, bool IsVolatile,
-                      Optional<Align> Alignment) {
+                      std::optional<Align> Alignment) {
   return getFileAux<MemoryBuffer>(Filename, /*MapSize=*/-1, /*Offset=*/0,
                                   IsText, RequiresNullTerminator, IsVolatile,
                                   Alignment);
@@ -257,13 +257,13 @@ template <typename MB>
 static ErrorOr<std::unique_ptr<MB>>
 getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
                 uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator,
-                bool IsVolatile, Optional<Align> Alignment);
+                bool IsVolatile, std::optional<Align> Alignment);
 
 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,
-           Optional<Align> Alignment) {
+           std::optional<Align> Alignment) {
   Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead(
       Filename, IsText ? sys::fs::OF_TextWithCRLF : sys::fs::OF_None);
   if (!FDOrErr)
@@ -277,7 +277,7 @@ getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
 
 ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
 WritableMemoryBuffer::getFile(const Twine &Filename, bool IsVolatile,
-                              Optional<Align> Alignment) {
+                              std::optional<Align> Alignment) {
   return getFileAux<WritableMemoryBuffer>(
       Filename, /*MapSize=*/-1, /*Offset=*/0, /*IsText=*/false,
       /*RequiresNullTerminator=*/false, IsVolatile, Alignment);
@@ -286,7 +286,7 @@ WritableMemoryBuffer::getFile(const Twine &Filename, bool IsVolatile,
 ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
 WritableMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize,
                                    uint64_t Offset, bool IsVolatile,
-                                   Optional<Align> Alignment) {
+                                   std::optional<Align> Alignment) {
   return getFileAux<WritableMemoryBuffer>(
       Filename, MapSize, Offset, /*IsText=*/false,
       /*RequiresNullTerminator=*/false, IsVolatile, Alignment);
@@ -295,7 +295,7 @@ WritableMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize,
 std::unique_ptr<WritableMemoryBuffer>
 WritableMemoryBuffer::getNewUninitMemBuffer(size_t Size,
                                             const Twine &BufferName,
-                                            Optional<Align> Alignment) {
+                                            std::optional<Align> Alignment) {
   using MemBuffer = MemoryBufferMem<WritableMemoryBuffer>;
 
   // Use 16-byte alignment if no alignment is specified.
@@ -447,7 +447,7 @@ template <typename MB>
 static ErrorOr<std::unique_ptr<MB>>
 getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
                 uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator,
-                bool IsVolatile, Optional<Align> Alignment) {
+                bool IsVolatile, std::optional<Align> Alignment) {
   static int PageSize = sys::Process::getPageSizeEstimate();
 
   // Default is to map the full file.
@@ -518,16 +518,15 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
 ErrorOr<std::unique_ptr<MemoryBuffer>>
 MemoryBuffer::getOpenFile(sys::fs::file_t FD, const Twine &Filename,
                           uint64_t FileSize, bool RequiresNullTerminator,
-                          bool IsVolatile, Optional<Align> Alignment) {
+                          bool IsVolatile, std::optional<Align> Alignment) {
   return getOpenFileImpl<MemoryBuffer>(FD, Filename, FileSize, FileSize, 0,
                                        RequiresNullTerminator, IsVolatile,
                                        Alignment);
 }
 
-ErrorOr<std::unique_ptr<MemoryBuffer>>
-MemoryBuffer::getOpenFileSlice(sys::fs::file_t FD, const Twine &Filename,
-                               uint64_t MapSize, int64_t Offset,
-                               bool IsVolatile, Optional<Align> Alignment) {
+ErrorOr<std::unique_ptr<MemoryBuffer>> MemoryBuffer::getOpenFileSlice(
+    sys::fs::file_t FD, const Twine &Filename, uint64_t MapSize, int64_t Offset,
+    bool IsVolatile, std::optional<Align> Alignment) {
   assert(MapSize != uint64_t(-1));
   return getOpenFileImpl<MemoryBuffer>(FD, Filename, -1, MapSize, Offset, false,
                                        IsVolatile, Alignment);

diff  --git a/llvm/lib/Support/NativeFormatting.cpp b/llvm/lib/Support/NativeFormatting.cpp
index ee2d8853dd62..fb02de792cb6 100644
--- a/llvm/lib/Support/NativeFormatting.cpp
+++ b/llvm/lib/Support/NativeFormatting.cpp
@@ -136,7 +136,7 @@ void llvm::write_integer(raw_ostream &S, long long N, size_t MinDigits,
 }
 
 void llvm::write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style,
-                     Optional<size_t> Width) {
+                     std::optional<size_t> Width) {
   const size_t kMaxWidth = 128u;
 
   size_t W = std::min(kMaxWidth, Width.value_or(0u));
@@ -166,7 +166,7 @@ void llvm::write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style,
 }
 
 void llvm::write_double(raw_ostream &S, double N, FloatStyle Style,
-                        Optional<size_t> Precision) {
+                        std::optional<size_t> Precision) {
   size_t Prec = Precision.value_or(getDefaultPrecision(Style));
 
   if (std::isnan(N)) {

diff  --git a/llvm/lib/Support/OptimizedStructLayout.cpp b/llvm/lib/Support/OptimizedStructLayout.cpp
index 8f0431106657..c64eff60c0b1 100644
--- a/llvm/lib/Support/OptimizedStructLayout.cpp
+++ b/llvm/lib/Support/OptimizedStructLayout.cpp
@@ -346,9 +346,8 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) {
   // Helper function to try to find a field in the given queue that'll
   // fit starting at StartOffset but before EndOffset (if present).
   // Note that this never fails if EndOffset is not provided.
-  auto tryAddFillerFromQueue = [&](AlignmentQueue *Queue,
-                                   uint64_t StartOffset,
-                                   Optional<uint64_t> EndOffset) -> bool {
+  auto tryAddFillerFromQueue = [&](AlignmentQueue *Queue, uint64_t StartOffset,
+                                   std::optional<uint64_t> EndOffset) -> bool {
     assert(Queue->Head);
     assert(StartOffset == alignTo(LastEnd, Queue->Alignment));
     assert(!EndOffset || StartOffset < *EndOffset);
@@ -357,7 +356,8 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) {
     // queue if there's nothing in it that small.
     auto MaxViableSize =
       (EndOffset ? *EndOffset - StartOffset : ~(uint64_t)0);
-    if (Queue->MinSize > MaxViableSize) return false;
+    if (Queue->MinSize > MaxViableSize)
+      return false;
 
     // Find the matching field.  Note that this should always find
     // something because of the MinSize check above.
@@ -373,7 +373,7 @@ llvm::performOptimizedStructLayout(MutableArrayRef<Field> Fields) {
 
   // Helper function to find the "best" flexible-offset field according
   // to the criteria described above.
-  auto tryAddBestField = [&](Optional<uint64_t> BeforeOffset) -> bool {
+  auto tryAddBestField = [&](std::optional<uint64_t> BeforeOffset) -> bool {
     assert(!BeforeOffset || LastEnd < *BeforeOffset);
     auto QueueB = FlexibleFieldsByAlignment.begin();
     auto QueueE = FlexibleFieldsByAlignment.end();

diff  --git a/llvm/lib/Support/SymbolRemappingReader.cpp b/llvm/lib/Support/SymbolRemappingReader.cpp
index 3cae57770c37..0082696038e3 100644
--- a/llvm/lib/Support/SymbolRemappingReader.cpp
+++ b/llvm/lib/Support/SymbolRemappingReader.cpp
@@ -48,11 +48,11 @@ Error SymbolRemappingReader::read(MemoryBuffer &B) {
                          "found '" + Line + "'");
 
     using FK = ItaniumManglingCanonicalizer::FragmentKind;
-    Optional<FK> FragmentKind = StringSwitch<Optional<FK>>(Parts[0])
-                                    .Case("name", FK::Name)
-                                    .Case("type", FK::Type)
-                                    .Case("encoding", FK::Encoding)
-                                    .Default(std::nullopt);
+    std::optional<FK> FragmentKind = StringSwitch<std::optional<FK>>(Parts[0])
+                                         .Case("name", FK::Name)
+                                         .Case("type", FK::Type)
+                                         .Case("encoding", FK::Encoding)
+                                         .Default(std::nullopt);
     if (!FragmentKind)
       return ReportError("Invalid kind, expected 'name', 'type', or 'encoding',"
                          " found '" + Parts[0] + "'");

diff  --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp
index 24962ae20919..f4e3331a4b9b 100644
--- a/llvm/lib/Support/Threading.cpp
+++ b/llvm/lib/Support/Threading.cpp
@@ -82,9 +82,9 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const {
   // which is not enough for some/many normal LLVM compilations. This implements
   // the same interface as std::thread but requests the same stack size as the
   // main thread (8MB) before creation.
-const llvm::Optional<unsigned> llvm::thread::DefaultStackSize = 8 * 1024 * 1024;
+const std::optional<unsigned> llvm::thread::DefaultStackSize = 8 * 1024 * 1024;
 #else
-const llvm::Optional<unsigned> llvm::thread::DefaultStackSize;
+const std::optional<unsigned> llvm::thread::DefaultStackSize;
 #endif
 
 

diff  --git a/llvm/lib/Support/UnicodeNameToCodepoint.cpp b/llvm/lib/Support/UnicodeNameToCodepoint.cpp
index 5fb61250705c..a10a7e8082ac 100644
--- a/llvm/lib/Support/UnicodeNameToCodepoint.cpp
+++ b/llvm/lib/Support/UnicodeNameToCodepoint.cpp
@@ -285,7 +285,7 @@ static std::size_t findSyllable(StringRef Name, bool Strict,
   return size_t(Len);
 }
 
-static llvm::Optional<char32_t>
+static std::optional<char32_t>
 nameToHangulCodePoint(StringRef Name, bool Strict, BufferType &Buffer) {
   Buffer.clear();
   // Hangul Syllable Decomposition
@@ -343,7 +343,7 @@ static const GeneratedNamesData GeneratedNamesDataTable[] = {
     {"CJK COMPATIBILITY IDEOGRAPH-", 0x2F800, 0x2FA1D},
 };
 
-static llvm::Optional<char32_t>
+static std::optional<char32_t>
 nameToGeneratedCodePoint(StringRef Name, bool Strict, BufferType &Buffer) {
   for (auto &&Item : GeneratedNamesDataTable) {
     Buffer.clear();
@@ -370,12 +370,12 @@ nameToGeneratedCodePoint(StringRef Name, bool Strict, BufferType &Buffer) {
   return std::nullopt;
 }
 
-static llvm::Optional<char32_t> nameToCodepoint(StringRef Name, bool Strict,
-                                                BufferType &Buffer) {
+static std::optional<char32_t> nameToCodepoint(StringRef Name, bool Strict,
+                                               BufferType &Buffer) {
   if (Name.empty())
     return std::nullopt;
 
-  llvm::Optional<char32_t> Res = nameToHangulCodePoint(Name, Strict, Buffer);
+  std::optional<char32_t> Res = nameToHangulCodePoint(Name, Strict, Buffer);
   if (!Res)
     Res = nameToGeneratedCodePoint(Name, Strict, Buffer);
   if (Res)
@@ -400,14 +400,14 @@ static llvm::Optional<char32_t> nameToCodepoint(StringRef Name, bool Strict,
   return std::nullopt;
 }
 
-llvm::Optional<char32_t> nameToCodepointStrict(StringRef Name) {
+std::optional<char32_t> nameToCodepointStrict(StringRef Name) {
 
   BufferType Buffer;
   auto Opt = nameToCodepoint(Name, true, Buffer);
   return Opt;
 }
 
-llvm::Optional<LooseMatchingResult>
+std::optional<LooseMatchingResult>
 nameToCodepointLooseMatching(StringRef Name) {
   BufferType Buffer;
   auto Opt = nameToCodepoint(Name, false, Buffer);

diff  --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index def6afad38c7..819748db4ec2 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -58,7 +58,7 @@
 namespace llvm {
 pthread_t
 llvm_execute_on_thread_impl(void *(*ThreadFunc)(void *), void *Arg,
-                            llvm::Optional<unsigned> StackSizeInBytes) {
+                            std::optional<unsigned> StackSizeInBytes) {
   int errnum;
 
   // Construct the attributes object.

diff  --git a/llvm/lib/Support/VersionTuple.cpp b/llvm/lib/Support/VersionTuple.cpp
index 6a516481ac25..c0e007215a5d 100644
--- a/llvm/lib/Support/VersionTuple.cpp
+++ b/llvm/lib/Support/VersionTuple.cpp
@@ -29,11 +29,11 @@ std::string VersionTuple::getAsString() const {
 
 raw_ostream &llvm::operator<<(raw_ostream &Out, const VersionTuple &V) {
   Out << V.getMajor();
-  if (Optional<unsigned> Minor = V.getMinor())
+  if (std::optional<unsigned> Minor = V.getMinor())
     Out << '.' << *Minor;
-  if (Optional<unsigned> Subminor = V.getSubminor())
+  if (std::optional<unsigned> Subminor = V.getSubminor())
     Out << '.' << *Subminor;
-  if (Optional<unsigned> Build = V.getBuild())
+  if (std::optional<unsigned> Build = V.getBuild())
     Out << '.' << *Build;
   return Out;
 }

diff  --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index f210143b1204..eac6fc9a9e35 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -814,10 +814,10 @@ std::string InMemoryFileSystem::toString() const {
 
 bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
                                  std::unique_ptr<llvm::MemoryBuffer> Buffer,
-                                 Optional<uint32_t> User,
-                                 Optional<uint32_t> Group,
-                                 Optional<llvm::sys::fs::file_type> Type,
-                                 Optional<llvm::sys::fs::perms> Perms,
+                                 std::optional<uint32_t> User,
+                                 std::optional<uint32_t> Group,
+                                 std::optional<llvm::sys::fs::file_type> Type,
+                                 std::optional<llvm::sys::fs::perms> Perms,
                                  MakeNodeFn MakeNode) {
   SmallString<128> Path;
   P.toVector(Path);
@@ -891,10 +891,10 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
 
 bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
                                  std::unique_ptr<llvm::MemoryBuffer> Buffer,
-                                 Optional<uint32_t> User,
-                                 Optional<uint32_t> Group,
-                                 Optional<llvm::sys::fs::file_type> Type,
-                                 Optional<llvm::sys::fs::perms> Perms) {
+                                 std::optional<uint32_t> User,
+                                 std::optional<uint32_t> Group,
+                                 std::optional<llvm::sys::fs::file_type> Type,
+                                 std::optional<llvm::sys::fs::perms> Perms) {
   return addFile(P, ModificationTime, std::move(Buffer), User, Group, Type,
                  Perms,
                  [](detail::NewInMemoryNodeInfo NNI)
@@ -907,12 +907,11 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
                  });
 }
 
-bool InMemoryFileSystem::addFileNoOwn(const Twine &P, time_t ModificationTime,
-                                      const llvm::MemoryBufferRef &Buffer,
-                                      Optional<uint32_t> User,
-                                      Optional<uint32_t> Group,
-                                      Optional<llvm::sys::fs::file_type> Type,
-                                      Optional<llvm::sys::fs::perms> Perms) {
+bool InMemoryFileSystem::addFileNoOwn(
+    const Twine &P, time_t ModificationTime,
+    const llvm::MemoryBufferRef &Buffer, std::optional<uint32_t> User,
+    std::optional<uint32_t> Group, std::optional<llvm::sys::fs::file_type> Type,
+    std::optional<llvm::sys::fs::perms> Perms) {
   return addFile(P, ModificationTime, llvm::MemoryBuffer::getMemBuffer(Buffer),
                  std::move(User), std::move(Group), std::move(Type),
                  std::move(Perms),
@@ -1020,12 +1019,10 @@ bool InMemoryFileSystem::addHardLink(const Twine &NewLink,
                  });
 }
 
-bool InMemoryFileSystem::addSymbolicLink(const Twine &NewLink,
-                                         const Twine &Target,
-                                         time_t ModificationTime,
-                                         Optional<uint32_t> User,
-                                         Optional<uint32_t> Group,
-                                         Optional<llvm::sys::fs::perms> Perms) {
+bool InMemoryFileSystem::addSymbolicLink(
+    const Twine &NewLink, const Twine &Target, time_t ModificationTime,
+    std::optional<uint32_t> User, std::optional<uint32_t> Group,
+    std::optional<llvm::sys::fs::perms> Perms) {
   auto NewLinkNode = lookupNode(NewLink, /*FollowFinalSymlink=*/false);
   if (NewLinkNode)
     return false;
@@ -2272,7 +2269,7 @@ static Status getRedirectedFileStatus(const Twine &OriginalPath,
 ErrorOr<Status> RedirectingFileSystem::status(
     const Twine &CanonicalPath, const Twine &OriginalPath,
     const RedirectingFileSystem::LookupResult &Result) {
-  if (Optional<StringRef> ExtRedirect = Result.getExternalRedirect()) {
+  if (std::optional<StringRef> ExtRedirect = Result.getExternalRedirect()) {
     SmallString<256> CanonicalRemappedPath((*ExtRedirect).str());
     if (std::error_code EC = makeCanonical(CanonicalRemappedPath))
       return EC;
@@ -2603,9 +2600,10 @@ class JSONWriter {
 public:
   JSONWriter(llvm::raw_ostream &OS) : OS(OS) {}
 
-  void write(ArrayRef<YAMLVFSEntry> Entries, Optional<bool> UseExternalNames,
-             Optional<bool> IsCaseSensitive, Optional<bool> IsOverlayRelative,
-             StringRef OverlayDir);
+  void write(ArrayRef<YAMLVFSEntry> Entries,
+             std::optional<bool> UseExternalNames,
+             std::optional<bool> IsCaseSensitive,
+             std::optional<bool> IsOverlayRelative, StringRef OverlayDir);
 };
 
 } // namespace
@@ -2660,9 +2658,9 @@ void JSONWriter::writeEntry(StringRef VPath, StringRef RPath) {
 }
 
 void JSONWriter::write(ArrayRef<YAMLVFSEntry> Entries,
-                       Optional<bool> UseExternalNames,
-                       Optional<bool> IsCaseSensitive,
-                       Optional<bool> IsOverlayRelative,
+                       std::optional<bool> UseExternalNames,
+                       std::optional<bool> IsCaseSensitive,
+                       std::optional<bool> IsOverlayRelative,
                        StringRef OverlayDir) {
   using namespace llvm::sys;
 

diff  --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index aaeda2ff85f8..2c16fe442b70 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -26,7 +26,7 @@
 namespace llvm {
 HANDLE
 llvm_execute_on_thread_impl(unsigned(__stdcall *ThreadFunc)(void *), void *Arg,
-                            llvm::Optional<unsigned> StackSizeInBytes) {
+                            std::optional<unsigned> StackSizeInBytes) {
   HANDLE hThread = (HANDLE)::_beginthreadex(NULL, StackSizeInBytes.value_or(0),
                                             ThreadFunc, Arg, 0, NULL);
 

diff  --git a/llvm/lib/Support/Z3Solver.cpp b/llvm/lib/Support/Z3Solver.cpp
index 499548e91286..a49bedcfd2b0 100644
--- a/llvm/lib/Support/Z3Solver.cpp
+++ b/llvm/lib/Support/Z3Solver.cpp
@@ -870,7 +870,7 @@ class Z3Solver : public SMTSolver {
     return toAPFloat(Sort, Assign, Float, true);
   }
 
-  Optional<bool> check() const override {
+  std::optional<bool> check() const override {
     Z3_lbool res = Z3_solver_check(Context.Context, Solver);
     if (res == Z3_L_TRUE)
       return true;

diff  --git a/llvm/unittests/ADT/StatisticTest.cpp b/llvm/unittests/ADT/StatisticTest.cpp
index e4c144289bb8..91bc7f24c7f2 100644
--- a/llvm/unittests/ADT/StatisticTest.cpp
+++ b/llvm/unittests/ADT/StatisticTest.cpp
@@ -11,7 +11,7 @@
 #include "gtest/gtest.h"
 using namespace llvm;
 
-using OptionalStatistic = Optional<std::pair<StringRef, uint64_t>>;
+using OptionalStatistic = std::optional<std::pair<StringRef, uint64_t>>;
 
 namespace {
 #define DEBUG_TYPE "unittest"

diff  --git a/llvm/unittests/Support/Casting.cpp b/llvm/unittests/Support/Casting.cpp
index 8ccabaeea5de..ed05963bc105 100644
--- a/llvm/unittests/Support/Casting.cpp
+++ b/llvm/unittests/Support/Casting.cpp
@@ -235,7 +235,7 @@ TEST(CastingTest, dyn_cast_or_null) {
 
 TEST(CastingTest, dyn_cast_value_types) {
   T1 t1;
-  Optional<T2> t2 = dyn_cast<T2>(t1);
+  std::optional<T2> t2 = dyn_cast<T2>(t1);
   EXPECT_TRUE(t2);
 
   T2 *t2ptr = dyn_cast<T2>(&t1);
@@ -246,12 +246,12 @@ TEST(CastingTest, dyn_cast_value_types) {
 }
 
 TEST(CastingTest, dyn_cast_if_present) {
-  Optional<T1> empty{};
-  Optional<T2> F1 = dyn_cast_if_present<T2>(empty);
+  std::optional<T1> empty{};
+  std::optional<T2> F1 = dyn_cast_if_present<T2>(empty);
   EXPECT_FALSE(F1.has_value());
 
   T1 t1;
-  Optional<T2> F2 = dyn_cast_if_present<T2>(t1);
+  std::optional<T2> F2 = dyn_cast_if_present<T2>(t1);
   EXPECT_TRUE(F2.has_value());
 
   T1 *t1Null = nullptr;

diff  --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 16118a966015..11f93203597b 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -1070,7 +1070,7 @@ static Error createAnyError() {
 }
 
 struct MoveOnlyBox {
-  Optional<int> Box;
+  std::optional<int> Box;
 
   explicit MoveOnlyBox(int I) : Box(I) {}
   MoveOnlyBox() = default;
@@ -1117,7 +1117,7 @@ TEST(Error, moveInto) {
   // Check that this works with optionals too.
   {
     // Same cases as above.
-    Optional<MoveOnlyBox> MaybeV;
+    std::optional<MoveOnlyBox> MaybeV;
     EXPECT_THAT_ERROR(makeFailure().moveInto(MaybeV), Failed());
     EXPECT_EQ(std::nullopt, MaybeV);
 

diff  --git a/llvm/unittests/Support/KnownBitsTest.cpp b/llvm/unittests/Support/KnownBitsTest.cpp
index 1d609e9d2c10..0c3d9dfa7630 100644
--- a/llvm/unittests/Support/KnownBitsTest.cpp
+++ b/llvm/unittests/Support/KnownBitsTest.cpp
@@ -347,16 +347,16 @@ TEST(KnownBitsTest, ICmpExhaustive) {
         });
       });
 
-      Optional<bool> KnownEQ = KnownBits::eq(Known1, Known2);
-      Optional<bool> KnownNE = KnownBits::ne(Known1, Known2);
-      Optional<bool> KnownUGT = KnownBits::ugt(Known1, Known2);
-      Optional<bool> KnownUGE = KnownBits::uge(Known1, Known2);
-      Optional<bool> KnownULT = KnownBits::ult(Known1, Known2);
-      Optional<bool> KnownULE = KnownBits::ule(Known1, Known2);
-      Optional<bool> KnownSGT = KnownBits::sgt(Known1, Known2);
-      Optional<bool> KnownSGE = KnownBits::sge(Known1, Known2);
-      Optional<bool> KnownSLT = KnownBits::slt(Known1, Known2);
-      Optional<bool> KnownSLE = KnownBits::sle(Known1, Known2);
+      std::optional<bool> KnownEQ = KnownBits::eq(Known1, Known2);
+      std::optional<bool> KnownNE = KnownBits::ne(Known1, Known2);
+      std::optional<bool> KnownUGT = KnownBits::ugt(Known1, Known2);
+      std::optional<bool> KnownUGE = KnownBits::uge(Known1, Known2);
+      std::optional<bool> KnownULT = KnownBits::ult(Known1, Known2);
+      std::optional<bool> KnownULE = KnownBits::ule(Known1, Known2);
+      std::optional<bool> KnownSGT = KnownBits::sgt(Known1, Known2);
+      std::optional<bool> KnownSGE = KnownBits::sge(Known1, Known2);
+      std::optional<bool> KnownSLT = KnownBits::slt(Known1, Known2);
+      std::optional<bool> KnownSLE = KnownBits::sle(Known1, Known2);
 
       EXPECT_EQ(AllEQ || NoneEQ, KnownEQ.has_value());
       EXPECT_EQ(AllNE || NoneNE, KnownNE.has_value());

diff  --git a/llvm/unittests/Support/NativeFormatTests.cpp b/llvm/unittests/Support/NativeFormatTests.cpp
index 591a68f1380c..197fad1f83cf 100644
--- a/llvm/unittests/Support/NativeFormatTests.cpp
+++ b/llvm/unittests/Support/NativeFormatTests.cpp
@@ -26,7 +26,7 @@ template <typename T> std::string format_number(T N, IntegerStyle Style) {
 }
 
 std::string format_number(uint64_t N, HexPrintStyle Style,
-                          Optional<size_t> Width = std::nullopt) {
+                          std::optional<size_t> Width = std::nullopt) {
   std::string S;
   llvm::raw_string_ostream Str(S);
   write_hex(Str, N, Style, Width);
@@ -35,7 +35,7 @@ std::string format_number(uint64_t N, HexPrintStyle Style,
 }
 
 std::string format_number(double D, FloatStyle Style,
-                          Optional<size_t> Precision = std::nullopt) {
+                          std::optional<size_t> Precision = std::nullopt) {
   std::string S;
   llvm::raw_string_ostream Str(S);
   write_double(Str, D, Style, Precision);

diff  --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
index d649debeed42..16e0f048ccb7 100644
--- a/llvm/unittests/Support/Path.cpp
+++ b/llvm/unittests/Support/Path.cpp
@@ -454,7 +454,7 @@ std::string getEnvWin(const wchar_t *Var) {
 // RAII helper to set and restore an environment variable.
 class WithEnv {
   const char *Var;
-  llvm::Optional<std::string> OriginalValue;
+  std::optional<std::string> OriginalValue;
 
 public:
   WithEnv(const char *Var, const char *Value) : Var(Var) {
@@ -1767,7 +1767,7 @@ static void verifyFileContents(const Twine &Path, StringRef Contents) {
 
 TEST_F(FileSystemTest, CreateNew) {
   int FD;
-  Optional<FileDescriptorCloser> Closer;
+  std::optional<FileDescriptorCloser> Closer;
 
   // Succeeds if the file does not exist.
   ASSERT_FALSE(fs::exists(NonExistantFile));
@@ -1791,7 +1791,7 @@ TEST_F(FileSystemTest, CreateNew) {
 
 TEST_F(FileSystemTest, CreateAlways) {
   int FD;
-  Optional<FileDescriptorCloser> Closer;
+  std::optional<FileDescriptorCloser> Closer;
 
   // Succeeds if the file does not exist.
   ASSERT_FALSE(fs::exists(NonExistantFile));
@@ -1869,7 +1869,7 @@ TEST_F(FileSystemTest, AppendSetsCorrectFileOffset) {
   // the specified disposition.
   for (fs::CreationDisposition Disp : Disps) {
     int FD;
-    Optional<FileDescriptorCloser> Closer;
+    std::optional<FileDescriptorCloser> Closer;
 
     createFileWithData(NonExistantFile, false, fs::CD_CreateNew, "Fizz");
 
@@ -1975,7 +1975,7 @@ TEST_F(FileSystemTest, readNativeFileToEOF) {
   createFileWithData(NonExistantFile, false, fs::CD_CreateNew, Content);
   FileRemover Cleanup(NonExistantFile);
   const auto &Read = [&](SmallVectorImpl<char> &V,
-                         Optional<ssize_t> ChunkSize) {
+                         std::optional<ssize_t> ChunkSize) {
     Expected<fs::file_t> FD = fs::openNativeFileForRead(NonExistantFile);
     if (!FD)
       return FD.takeError();

diff  --git a/llvm/unittests/Support/TypeTraitsTest.cpp b/llvm/unittests/Support/TypeTraitsTest.cpp
index 734e50afa2db..71383ac63359 100644
--- a/llvm/unittests/Support/TypeTraitsTest.cpp
+++ b/llvm/unittests/Support/TypeTraitsTest.cpp
@@ -118,7 +118,7 @@ TEST(Triviality, ADT) {
   TrivialityTester<llvm::StringRef, true, true>();
   TrivialityTester<llvm::ArrayRef<int>, true, true>();
   TrivialityTester<llvm::PointerIntPair<int *, 2>, true, true>();
-  TrivialityTester<llvm::Optional<int>, true, true>();
+  TrivialityTester<std::optional<int>, true, true>();
 }
 
 } // namespace triviality

diff  --git a/mlir/lib/Support/FileUtilities.cpp b/mlir/lib/Support/FileUtilities.cpp
index 9fc86fcd6202..a5c44d3a9c8e 100644
--- a/mlir/lib/Support/FileUtilities.cpp
+++ b/mlir/lib/Support/FileUtilities.cpp
@@ -21,7 +21,7 @@ using namespace mlir;
 
 static std::unique_ptr<llvm::MemoryBuffer>
 openInputFileImpl(StringRef inputFilename, std::string *errorMessage,
-                  Optional<llvm::Align> alignment) {
+                  std::optional<llvm::Align> alignment) {
   auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(
       inputFilename, /*IsText=*/false, /*RequiresNullTerminator=*/true,
       alignment);


        


More information about the cfe-commits mailing list