[clang-tools-extra] c589730 - [YAML] Convert Optional to std::optional

Krzysztof Parzyszek via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 6 12:50:04 PST 2022


Author: Krzysztof Parzyszek
Date: 2022-12-06T12:49:32-08:00
New Revision: c589730ad5286fc784b8aacf2f0214149603f312

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

LOG: [YAML] Convert Optional to std::optional

Added: 
    

Modified: 
    clang-tools-extra/clang-doc/BitcodeReader.cpp
    clang-tools-extra/clang-doc/Representation.h
    clang-tools-extra/clang-doc/YAMLGenerator.cpp
    clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
    clang-tools-extra/clang-tidy/ClangTidyOptions.h
    clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
    clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
    clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
    clang-tools-extra/clangd/TidyProvider.cpp
    clang/lib/APINotes/APINotesYAMLCompiler.cpp
    llvm/include/llvm/Analysis/BlockFrequencyInfo.h
    llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
    llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
    llvm/include/llvm/Analysis/ProfileSummaryInfo.h
    llvm/include/llvm/CodeGen/MBFIWrapper.h
    llvm/include/llvm/CodeGen/MIRYamlMapping.h
    llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
    llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
    llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h
    llvm/include/llvm/IR/DiagnosticInfo.h
    llvm/include/llvm/InterfaceStub/IFSHandler.h
    llvm/include/llvm/InterfaceStub/IFSStub.h
    llvm/include/llvm/ObjectYAML/ArchiveYAML.h
    llvm/include/llvm/ObjectYAML/COFFYAML.h
    llvm/include/llvm/ObjectYAML/DWARFYAML.h
    llvm/include/llvm/ObjectYAML/DXContainerYAML.h
    llvm/include/llvm/ObjectYAML/ELFYAML.h
    llvm/include/llvm/ObjectYAML/MachOYAML.h
    llvm/include/llvm/ObjectYAML/OffloadYAML.h
    llvm/include/llvm/ObjectYAML/XCOFFYAML.h
    llvm/include/llvm/ProfileData/InstrProfCorrelator.h
    llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h
    llvm/include/llvm/Remarks/Remark.h
    llvm/include/llvm/Remarks/RemarkSerializer.h
    llvm/include/llvm/Remarks/YAMLRemarkSerializer.h
    llvm/include/llvm/Support/YAMLTraits.h
    llvm/lib/Analysis/BlockFrequencyInfo.cpp
    llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
    llvm/lib/Analysis/OptimizationRemarkEmitter.cpp
    llvm/lib/Analysis/ProfileSummaryInfo.cpp
    llvm/lib/CodeGen/MBFIWrapper.cpp
    llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
    llvm/lib/CodeGen/MachineFunctionSplitter.cpp
    llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp
    llvm/lib/IR/LLVMRemarkStreamer.cpp
    llvm/lib/InterfaceStub/IFSHandler.cpp
    llvm/lib/ObjectYAML/COFFEmitter.cpp
    llvm/lib/ObjectYAML/DWARFEmitter.cpp
    llvm/lib/ObjectYAML/ELFEmitter.cpp
    llvm/lib/ObjectYAML/ELFYAML.cpp
    llvm/lib/ProfileData/InstrProfCorrelator.cpp
    llvm/lib/Remarks/BitstreamRemarkSerializer.cpp
    llvm/lib/Remarks/Remark.cpp
    llvm/lib/Remarks/YAMLRemarkParser.cpp
    llvm/lib/Remarks/YAMLRemarkSerializer.cpp
    llvm/lib/Support/AMDGPUMetadata.cpp
    llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
    llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
    llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
    llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
    llvm/lib/Transforms/Instrumentation/CGProfile.cpp
    llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
    llvm/tools/dsymutil/DebugMap.cpp
    llvm/tools/dsymutil/DebugMap.h
    llvm/tools/dsymutil/MachODebugMapParser.cpp
    llvm/tools/llvm-ifs/llvm-ifs.cpp
    llvm/tools/llvm-opt-report/OptReport.cpp
    llvm/tools/llvm-pdbutil/PdbYaml.h
    llvm/tools/obj2yaml/dwarf2yaml.cpp
    llvm/tools/obj2yaml/elf2yaml.cpp
    llvm/tools/yaml2obj/yaml2obj.cpp
    mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 524b82d9fcc53..072011448330e 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 
 namespace clang {
 namespace doc {
@@ -81,7 +82,7 @@ llvm::Error decodeRecord(const Record &R, TagTypeKind &Field,
   }
 }
 
-llvm::Error decodeRecord(const Record &R, llvm::Optional<Location> &Field,
+llvm::Error decodeRecord(const Record &R, std::optional<Location> &Field,
                          llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
     return llvm::createStringError(llvm::inconvertibleErrorCode(),

diff  --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index 7d76844462885..2a690883b33e7 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -22,6 +22,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include <array>
+#include <optional>
 #include <string>
 
 namespace clang {
@@ -295,7 +296,7 @@ struct SymbolInfo : public Info {
 
   void merge(SymbolInfo &&I);
 
-  llvm::Optional<Location> DefLoc;    // Location where this decl is defined.
+  std::optional<Location> DefLoc;     // Location where this decl is defined.
   llvm::SmallVector<Location, 2> Loc; // Locations where this decl is declared.
 };
 
@@ -421,7 +422,7 @@ struct EnumInfo : public SymbolInfo {
   // Set to nonempty to the type when this is an explicitly typed enum. For
   //   enum Foo : short { ... };
   // this will be "short".
-  llvm::Optional<TypeInfo> BaseType;
+  std::optional<TypeInfo> BaseType;
 
   llvm::SmallVector<EnumValueInfo, 4> Members; // List of enum members.
 };

diff  --git a/clang-tools-extra/clang-doc/YAMLGenerator.cpp b/clang-tools-extra/clang-doc/YAMLGenerator.cpp
index b54486102ccc3..0e662c0d9006c 100644
--- a/clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -11,6 +11,7 @@
 #include "Generators.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 
 using namespace clang::doc;
 
@@ -125,7 +126,7 @@ static void InfoMapping(IO &IO, Info &I) {
 
 static void SymbolInfoMapping(IO &IO, SymbolInfo &I) {
   InfoMapping(IO, I);
-  IO.mapOptional("DefLocation", I.DefLoc, Optional<Location>());
+  IO.mapOptional("DefLocation", I.DefLoc, std::optional<Location>());
   IO.mapOptional("Location", I.Loc, llvm::SmallVector<Location, 2>());
 }
 

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index c98ecb8bb29ad..cf790f9f579a1 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -16,6 +16,7 @@
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/YAMLTraits.h"
+#include <optional>
 #include <utility>
 
 #define DEBUG_TYPE "clang-tidy-options"
@@ -155,7 +156,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
 }
 
 template <typename T>
-static void mergeVectors(Optional<T> &Dest, const Optional<T> &Src) {
+static void mergeVectors(std::optional<T> &Dest, const std::optional<T> &Src) {
   if (Src) {
     if (Dest)
       Dest->insert(Dest->end(), Src->begin(), Src->end());
@@ -164,14 +165,14 @@ static void mergeVectors(Optional<T> &Dest, const Optional<T> &Src) {
   }
 }
 
-static void mergeCommaSeparatedLists(Optional<std::string> &Dest,
-                                     const Optional<std::string> &Src) {
+static void mergeCommaSeparatedLists(std::optional<std::string> &Dest,
+                                     const std::optional<std::string> &Src) {
   if (Src)
     Dest = (Dest && !Dest->empty() ? *Dest + "," : "") + *Src;
 }
 
 template <typename T>
-static void overrideValue(Optional<T> &Dest, const Optional<T> &Src) {
+static void overrideValue(std::optional<T> &Dest, const std::optional<T> &Src) {
   if (Src)
     Dest = Src;
 }

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 20e54215ac8a4..6102399d9d387 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -17,6 +17,7 @@
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include <functional>
+#include <optional>
 #include <string>
 #include <system_error>
 #include <utility>
@@ -67,17 +68,17 @@ struct ClangTidyOptions {
                                        unsigned Order) const;
 
   /// Checks filter.
-  llvm::Optional<std::string> Checks;
+  std::optional<std::string> Checks;
 
   /// WarningsAsErrors filter.
-  llvm::Optional<std::string> WarningsAsErrors;
+  std::optional<std::string> WarningsAsErrors;
 
   /// Output warnings from headers matching this filter. Warnings from
   /// main files will always be displayed.
-  llvm::Optional<std::string> HeaderFilterRegex;
+  std::optional<std::string> HeaderFilterRegex;
 
   /// Output warnings from system headers matching \c HeaderFilterRegex.
-  llvm::Optional<bool> SystemHeaders;
+  std::optional<bool> SystemHeaders;
 
   /// Format code around applied fixes with clang-format using this
   /// style.
@@ -91,13 +92,13 @@ struct ClangTidyOptions {
   ///   * '{inline-formatting-style-in-yaml-format}'.
   ///
   /// See clang-format documentation for more about configuring format style.
-  llvm::Optional<std::string> FormatStyle;
+  std::optional<std::string> FormatStyle;
 
   /// Specifies the name or e-mail of the user running clang-tidy.
   ///
   /// This option is used, for example, to place the correct user name in TODO()
   /// comments in the relevant check.
-  llvm::Optional<std::string> User;
+  std::optional<std::string> User;
 
   /// Helper structure for storing option value with priority of the value.
   struct ClangTidyValue {
@@ -120,10 +121,10 @@ struct ClangTidyOptions {
   typedef std::vector<std::string> ArgList;
 
   /// Add extra compilation arguments to the end of the list.
-  llvm::Optional<ArgList> ExtraArgs;
+  std::optional<ArgList> ExtraArgs;
 
   /// Add extra compilation arguments to the start of the list.
-  llvm::Optional<ArgList> ExtraArgsBefore;
+  std::optional<ArgList> ExtraArgsBefore;
 
   /// Only used in the FileOptionsProvider and ConfigOptionsProvider. If true
   /// and using a FileOptionsProvider, it will take a configuration file in the
@@ -132,10 +133,10 @@ struct ClangTidyOptions {
   /// config on top of any configuration file it finds in the directory using
   /// the same logic as FileOptionsProvider. If false or missing, only this
   /// configuration file will be used.
-  llvm::Optional<bool> InheritParentConfig;
+  std::optional<bool> InheritParentConfig;
 
   /// Use colors in diagnostics. If missing, it will be auto detected.
-  llvm::Optional<bool> UseColor;
+  std::optional<bool> UseColor;
 };
 
 /// Abstract interface for retrieving various ClangTidy options.

diff  --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
index ec099f0e400c9..afc7fa40db0ae 100644
--- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
@@ -9,6 +9,7 @@
 #include "TodoCommentCheck.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/Preprocessor.h"
+#include <optional>
 
 namespace clang {
 namespace tidy {
@@ -17,7 +18,7 @@ namespace readability {
 
 class TodoCommentCheck::TodoCommentHandler : public CommentHandler {
 public:
-  TodoCommentHandler(TodoCommentCheck &Check, llvm::Optional<std::string> User)
+  TodoCommentHandler(TodoCommentCheck &Check, std::optional<std::string> User)
       : Check(Check), User(User ? *User : "unknown"),
         TodoMatch("^// *TODO *(\\(.*\\))?:?( )?(.*)$") {}
 

diff  --git a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
index c2948451ac5f0..3706f43d255b3 100644
--- a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
@@ -11,6 +11,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/Support/ConvertUTF.h"
+#include <optional>
 
 using namespace clang;
 using namespace clang::tidy::misc;
@@ -90,7 +91,7 @@ class MisleadingBidirectionalCheck::MisleadingBidirectionalHandler
     : public CommentHandler {
 public:
   MisleadingBidirectionalHandler(MisleadingBidirectionalCheck &Check,
-                                 llvm::Optional<std::string> User)
+                                 std::optional<std::string> User)
       : Check(Check) {}
 
   bool HandleComment(Preprocessor &PP, SourceRange Range) override {

diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 422ae6c772d74..3ff4cbdad4dac 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -26,6 +26,7 @@
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/WithColor.h"
+#include <optional>
 
 using namespace clang::tooling;
 using namespace llvm;
@@ -308,19 +309,10 @@ static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider(
   DefaultOptions.HeaderFilterRegex = HeaderFilter;
   DefaultOptions.SystemHeaders = SystemHeaders;
   DefaultOptions.FormatStyle = FormatStyle;
-  if (auto User = llvm::sys::Process::GetEnv("USER")) // FIXME(kparzysz-quic)
-    DefaultOptions.User = *User;
-  else
-    DefaultOptions.User = std::nullopt;
+  DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
   // USERNAME is used on Windows.
-  // if (!DefaultOptions.User)
-  //  DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
-  if (!DefaultOptions.User) { // FIXME(kparzysz-quic)
-    if (auto Username = llvm::sys::Process::GetEnv("USERNAME"))
-      DefaultOptions.User = *Username;
-    else
-      DefaultOptions.User = std::nullopt;
-  }
+  if (!DefaultOptions.User)
+    DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
 
   ClangTidyOptions OverrideOptions;
   if (Checks.getNumOccurrences() > 0)

diff  --git a/clang-tools-extra/clangd/TidyProvider.cpp b/clang-tools-extra/clangd/TidyProvider.cpp
index 7f134d9232665..936b1ce3edaba 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/Process.h"
 #include "llvm/Support/SourceMgr.h"
 #include <memory>
+#include <optional>
 
 namespace clang {
 namespace clangd {
@@ -136,7 +137,7 @@ class DotClangTidyTree {
 
 } // namespace
 
-static void mergeCheckList(llvm::Optional<std::string> &Checks,
+static void mergeCheckList(std::optional<std::string> &Checks,
                            llvm::StringRef List) {
   if (List.empty())
     return;
@@ -148,14 +149,13 @@ static void mergeCheckList(llvm::Optional<std::string> &Checks,
 }
 
 TidyProviderRef provideEnvironment() {
-  static const llvm::Optional<std::string> User = [] {
+  static const std::optional<std::string> User = [] {
     std::optional<std::string> Ret = llvm::sys::Process::GetEnv("USER");
 #ifdef _WIN32
     if (!Ret)
-      Ret = llvm::sys::Process::GetEnv("USERNAME");
+      return llvm::sys::Process::GetEnv("USERNAME");
 #endif
-    return Ret ? llvm::Optional<std::string>(*Ret)
-               : llvm::Optional<std::string>();
+    return Ret;
   }();
 
   if (User)

diff  --git a/clang/lib/APINotes/APINotesYAMLCompiler.cpp b/clang/lib/APINotes/APINotesYAMLCompiler.cpp
index 1e6ccb59e0683..42279b8668c64 100644
--- a/clang/lib/APINotes/APINotesYAMLCompiler.cpp
+++ b/clang/lib/APINotes/APINotesYAMLCompiler.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/Support/YAMLTraits.h"
+#include <optional>
 #include <vector>
 using namespace clang;
 using namespace api_notes;
@@ -70,9 +71,9 @@ template <> struct ScalarEnumerationTraits<MethodKind> {
 namespace {
 struct Param {
   unsigned Position;
-  Optional<bool> NoEscape = false;
-  Optional<NullabilityKind> Nullability;
-  Optional<RetainCountConventionKind> RetainCountConvention;
+  std::optional<bool> NoEscape = false;
+  std::optional<NullabilityKind> Nullability;
+  std::optional<RetainCountConventionKind> RetainCountConvention;
   StringRef Type;
 };
 
@@ -151,10 +152,10 @@ struct Method {
   MethodKind Kind;
   ParamsSeq Params;
   NullabilitySeq Nullability;
-  Optional<NullabilityKind> NullabilityOfRet;
-  Optional<RetainCountConventionKind> RetainCountConvention;
+  std::optional<NullabilityKind> NullabilityOfRet;
+  std::optional<RetainCountConventionKind> RetainCountConvention;
   AvailabilityItem Availability;
-  Optional<bool> SwiftPrivate;
+  std::optional<bool> SwiftPrivate;
   StringRef SwiftName;
   FactoryAsInitKind FactoryAsInit = FactoryAsInitKind::Infer;
   bool DesignatedInit = false;
@@ -202,12 +203,12 @@ template <> struct MappingTraits<Method> {
 namespace {
 struct Property {
   StringRef Name;
-  llvm::Optional<MethodKind> Kind;
-  llvm::Optional<NullabilityKind> Nullability;
+  std::optional<MethodKind> Kind;
+  std::optional<NullabilityKind> Nullability;
   AvailabilityItem Availability;
-  Optional<bool> SwiftPrivate;
+  std::optional<bool> SwiftPrivate;
   StringRef SwiftName;
-  Optional<bool> SwiftImportAsAccessors;
+  std::optional<bool> SwiftImportAsAccessors;
   StringRef Type;
 };
 
@@ -240,12 +241,12 @@ struct Class {
   StringRef Name;
   bool AuditedForNullability = false;
   AvailabilityItem Availability;
-  Optional<bool> SwiftPrivate;
+  std::optional<bool> SwiftPrivate;
   StringRef SwiftName;
-  Optional<StringRef> SwiftBridge;
-  Optional<StringRef> NSErrorDomain;
-  Optional<bool> SwiftImportAsNonGeneric;
-  Optional<bool> SwiftObjCMembers;
+  std::optional<StringRef> SwiftBridge;
+  std::optional<StringRef> NSErrorDomain;
+  std::optional<bool> SwiftImportAsNonGeneric;
+  std::optional<bool> SwiftObjCMembers;
   MethodsSeq Methods;
   PropertiesSeq Properties;
 };
@@ -282,10 +283,10 @@ struct Function {
   StringRef Name;
   ParamsSeq Params;
   NullabilitySeq Nullability;
-  Optional<NullabilityKind> NullabilityOfRet;
-  Optional<api_notes::RetainCountConventionKind> RetainCountConvention;
+  std::optional<NullabilityKind> NullabilityOfRet;
+  std::optional<api_notes::RetainCountConventionKind> RetainCountConvention;
   AvailabilityItem Availability;
-  Optional<bool> SwiftPrivate;
+  std::optional<bool> SwiftPrivate;
   StringRef SwiftName;
   StringRef Type;
   StringRef ResultType;
@@ -319,9 +320,9 @@ template <> struct MappingTraits<Function> {
 namespace {
 struct GlobalVariable {
   StringRef Name;
-  llvm::Optional<NullabilityKind> Nullability;
+  std::optional<NullabilityKind> Nullability;
   AvailabilityItem Availability;
-  Optional<bool> SwiftPrivate;
+  std::optional<bool> SwiftPrivate;
   StringRef SwiftName;
   StringRef Type;
 };
@@ -352,7 +353,7 @@ namespace {
 struct EnumConstant {
   StringRef Name;
   AvailabilityItem Availability;
-  Optional<bool> SwiftPrivate;
+  std::optional<bool> SwiftPrivate;
   StringRef SwiftName;
 };
 
@@ -411,12 +412,12 @@ struct Tag {
   StringRef Name;
   AvailabilityItem Availability;
   StringRef SwiftName;
-  Optional<bool> SwiftPrivate;
-  Optional<StringRef> SwiftBridge;
-  Optional<StringRef> NSErrorDomain;
-  Optional<EnumExtensibilityKind> EnumExtensibility;
-  Optional<bool> FlagEnum;
-  Optional<EnumConvenienceAliasKind> EnumConvenienceKind;
+  std::optional<bool> SwiftPrivate;
+  std::optional<StringRef> SwiftBridge;
+  std::optional<StringRef> NSErrorDomain;
+  std::optional<EnumExtensibilityKind> EnumExtensibility;
+  std::optional<bool> FlagEnum;
+  std::optional<EnumConvenienceAliasKind> EnumConvenienceKind;
 };
 
 typedef std::vector<Tag> TagsSeq;
@@ -457,10 +458,10 @@ struct Typedef {
   StringRef Name;
   AvailabilityItem Availability;
   StringRef SwiftName;
-  Optional<bool> SwiftPrivate;
-  Optional<StringRef> SwiftBridge;
-  Optional<StringRef> NSErrorDomain;
-  Optional<SwiftNewTypeKind> SwiftType;
+  std::optional<bool> SwiftPrivate;
+  std::optional<StringRef> SwiftBridge;
+  std::optional<StringRef> NSErrorDomain;
+  std::optional<SwiftNewTypeKind> SwiftType;
 };
 
 typedef std::vector<Typedef> TypedefsSeq;
@@ -549,7 +550,7 @@ struct Module {
   TopLevelItems TopLevel;
   VersionedSeq SwiftVersions;
 
-  llvm::Optional<bool> SwiftInferImportAsMember = {std::nullopt};
+  std::optional<bool> SwiftInferImportAsMember = std::nullopt;
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   LLVM_DUMP_METHOD void dump() /*const*/;

diff  --git a/llvm/include/llvm/Analysis/BlockFrequencyInfo.h b/llvm/include/llvm/Analysis/BlockFrequencyInfo.h
index 4c38cdd4a62be..39507570a1b2c 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfo.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfo.h
@@ -13,12 +13,12 @@
 #ifndef LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H
 #define LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/BlockFrequency.h"
 #include <cstdint>
 #include <memory>
+#include <optional>
 
 namespace llvm {
 
@@ -67,13 +67,13 @@ class BlockFrequencyInfo {
   /// Returns the estimated profile count of \p BB.
   /// This computes the relative block frequency of \p BB and multiplies it by
   /// the enclosing function's count (if available) and returns the value.
-  Optional<uint64_t> getBlockProfileCount(const BasicBlock *BB,
-                                          bool AllowSynthetic = false) const;
+  std::optional<uint64_t>
+  getBlockProfileCount(const BasicBlock *BB, bool AllowSynthetic = false) const;
 
   /// Returns the estimated profile count of \p Freq.
   /// This uses the frequency \p Freq and multiplies it by
   /// the enclosing function's count (if available) and returns the value.
-  Optional<uint64_t> getProfileCountFromFreq(uint64_t Freq) const;
+  std::optional<uint64_t> getProfileCountFromFreq(uint64_t Freq) const;
 
   /// Returns true if \p BB is an irreducible loop header
   /// block. Otherwise false.

diff  --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index 0e9cac076902c..68d9d1bcf18cb 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -18,7 +18,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/GraphTraits.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
@@ -523,12 +522,12 @@ class BlockFrequencyInfoImplBase {
   Scaled64 getFloatingBlockFreq(const BlockNode &Node) const;
 
   BlockFrequency getBlockFreq(const BlockNode &Node) const;
-  Optional<uint64_t> getBlockProfileCount(const Function &F,
-                                          const BlockNode &Node,
-                                          bool AllowSynthetic = false) const;
-  Optional<uint64_t> getProfileCountFromFreq(const Function &F,
-                                             uint64_t Freq,
-                                             bool AllowSynthetic = false) const;
+  std::optional<uint64_t>
+  getBlockProfileCount(const Function &F, const BlockNode &Node,
+                       bool AllowSynthetic = false) const;
+  std::optional<uint64_t>
+  getProfileCountFromFreq(const Function &F, uint64_t Freq,
+                          bool AllowSynthetic = false) const;
   bool isIrrLoopHeader(const BlockNode &Node);
 
   void setBlockFreq(const BlockNode &Node, uint64_t Freq);
@@ -1021,16 +1020,16 @@ template <class BT> class BlockFrequencyInfoImpl : BlockFrequencyInfoImplBase {
     return BlockFrequencyInfoImplBase::getBlockFreq(getNode(BB));
   }
 
-  Optional<uint64_t> getBlockProfileCount(const Function &F,
-                                          const BlockT *BB,
-                                          bool AllowSynthetic = false) const {
+  std::optional<uint64_t>
+  getBlockProfileCount(const Function &F, const BlockT *BB,
+                       bool AllowSynthetic = false) const {
     return BlockFrequencyInfoImplBase::getBlockProfileCount(F, getNode(BB),
                                                             AllowSynthetic);
   }
 
-  Optional<uint64_t> getProfileCountFromFreq(const Function &F,
-                                             uint64_t Freq,
-                                             bool AllowSynthetic = false) const {
+  std::optional<uint64_t>
+  getProfileCountFromFreq(const Function &F, uint64_t Freq,
+                          bool AllowSynthetic = false) const {
     return BlockFrequencyInfoImplBase::getProfileCountFromFreq(F, Freq,
                                                                AllowSynthetic);
   }
@@ -1730,7 +1729,7 @@ raw_ostream &BlockFrequencyInfoImpl<BT>::print(raw_ostream &OS) const {
     OS << " - " << bfi_detail::getBlockName(&BB) << ": float = ";
     getFloatingBlockFreq(&BB).print(OS, 5)
         << ", int = " << getBlockFreq(&BB).getFrequency();
-    if (Optional<uint64_t> ProfileCount =
+    if (std::optional<uint64_t> ProfileCount =
         BlockFrequencyInfoImplBase::getBlockProfileCount(
             F->getFunction(), getNode(&BB)))
       OS << ", count = " << ProfileCount.value();

diff  --git a/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h b/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
index ff706e91f3c45..8aaeaf2991029 100644
--- a/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
+++ b/llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
@@ -14,11 +14,11 @@
 #ifndef LLVM_ANALYSIS_OPTIMIZATIONREMARKEMITTER_H
 #define LLVM_ANALYSIS_OPTIMIZATIONREMARKEMITTER_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/Analysis/BlockFrequencyInfo.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
+#include <optional>
 
 namespace llvm {
 class Function;
@@ -116,7 +116,7 @@ class OptimizationRemarkEmitter {
 
   /// Compute hotness from IR value (currently assumed to be a block) if PGO is
   /// available.
-  Optional<uint64_t> computeHotness(const Value *V);
+  std::optional<uint64_t> computeHotness(const Value *V);
 
   /// Similar but use value from \p OptDiag and update hotness there.
   void computeHotness(DiagnosticInfoIROptimization &OptDiag);

diff  --git a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
index f67dfa1bc24f1..9cf8fe3254a5c 100644
--- a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
+++ b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
@@ -98,9 +98,9 @@ class ProfileSummaryInfo {
   }
 
   /// Returns the profile count for \p CallInst.
-  Optional<uint64_t> getProfileCount(const CallBase &CallInst,
-                                     BlockFrequencyInfo *BFI,
-                                     bool AllowSynthetic = false) const;
+  std::optional<uint64_t> getProfileCount(const CallBase &CallInst,
+                                          BlockFrequencyInfo *BFI,
+                                          bool AllowSynthetic = false) const;
   /// Returns true if module \c M has partial-profile sample profile.
   bool hasPartialSampleProfile() const;
   /// Returns true if the working set size of the code is considered huge.

diff  --git a/llvm/include/llvm/CodeGen/MBFIWrapper.h b/llvm/include/llvm/CodeGen/MBFIWrapper.h
index 59506bb13ec6a..714ecc5d4334e 100644
--- a/llvm/include/llvm/CodeGen/MBFIWrapper.h
+++ b/llvm/include/llvm/CodeGen/MBFIWrapper.h
@@ -15,9 +15,9 @@
 #define LLVM_CODEGEN_MBFIWRAPPER_H
 
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/Support/BlockFrequency.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 
 namespace llvm {
 
@@ -30,7 +30,8 @@ class MBFIWrapper {
 
   BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
   void setBlockFreq(const MachineBasicBlock *MBB, BlockFrequency F);
-  Optional<uint64_t> getBlockProfileCount(const MachineBasicBlock *MBB) const;
+  std::optional<uint64_t>
+  getBlockProfileCount(const MachineBasicBlock *MBB) const;
 
   raw_ostream &printBlockFreq(raw_ostream &OS,
                               const MachineBasicBlock *MBB) const;

diff  --git a/llvm/include/llvm/CodeGen/MIRYamlMapping.h b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
index cb18030f72236..ba6b64d0a8482 100644
--- a/llvm/include/llvm/CodeGen/MIRYamlMapping.h
+++ b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
@@ -14,7 +14,6 @@
 #ifndef LLVM_CODEGEN_MIRYAMLMAPPING_H
 #define LLVM_CODEGEN_MIRYAMLMAPPING_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/CodeGen/MachineJumpTableInfo.h"
 #include "llvm/CodeGen/TargetFrameLowering.h"
@@ -23,6 +22,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <cstdint>
+#include <optional>
 #include <string>
 #include <vector>
 
@@ -249,7 +249,7 @@ struct MachineStackObject {
   TargetStackID::Value StackID;
   StringValue CalleeSavedRegister;
   bool CalleeSavedRestored = true;
-  Optional<int64_t> LocalOffset;
+  std::optional<int64_t> LocalOffset;
   StringValue DebugVar;
   StringValue DebugExpr;
   StringValue DebugLoc;
@@ -291,7 +291,8 @@ template <> struct MappingTraits<MachineStackObject> {
                        StringValue()); // Don't print it out when it's empty.
     YamlIO.mapOptional("callee-saved-restored", Object.CalleeSavedRestored,
                        true);
-    YamlIO.mapOptional("local-offset", Object.LocalOffset, Optional<int64_t>());
+    YamlIO.mapOptional("local-offset", Object.LocalOffset,
+                       std::optional<int64_t>());
     YamlIO.mapOptional("debug-info-variable", Object.DebugVar,
                        StringValue()); // Don't print it out when it's empty.
     YamlIO.mapOptional("debug-info-expression", Object.DebugExpr,
@@ -708,7 +709,7 @@ struct MachineFunction {
   bool TracksDebugUserValues = false;
   std::vector<VirtualRegisterDefinition> VirtualRegisters;
   std::vector<MachineFunctionLiveIn> LiveIns;
-  Optional<std::vector<FlowStringValue>> CalleeSavedRegisters;
+  std::optional<std::vector<FlowStringValue>> CalleeSavedRegisters;
   // TODO: Serialize the various register masks.
   // Frame information
   MachineFrameInfo FrameInfo;
@@ -749,7 +750,7 @@ template <> struct MappingTraits<MachineFunction> {
     YamlIO.mapOptional("liveins", MF.LiveIns,
                        std::vector<MachineFunctionLiveIn>());
     YamlIO.mapOptional("calleeSavedRegisters", MF.CalleeSavedRegisters,
-                       Optional<std::vector<FlowStringValue>>());
+                       std::optional<std::vector<FlowStringValue>>());
     YamlIO.mapOptional("frameInfo", MF.FrameInfo, MachineFrameInfo());
     YamlIO.mapOptional("fixedStack", MF.FixedStackObjects,
                        std::vector<FixedMachineStackObject>());

diff  --git a/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h b/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
index 6c442d3d07bdb..2290d26c0827b 100644
--- a/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
@@ -13,11 +13,11 @@
 #ifndef LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
 #define LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/Support/BlockFrequency.h"
 #include <cstdint>
 #include <memory>
+#include <optional>
 
 namespace llvm {
 
@@ -69,8 +69,9 @@ class MachineBlockFrequencyInfo : public MachineFunctionPass {
     return getBlockFreq(MBB).getFrequency() * (1.0f / getEntryFreq());
   }
 
-  Optional<uint64_t> getBlockProfileCount(const MachineBasicBlock *MBB) const;
-  Optional<uint64_t> getProfileCountFromFreq(uint64_t Freq) const;
+  std::optional<uint64_t>
+  getBlockProfileCount(const MachineBasicBlock *MBB) const;
+  std::optional<uint64_t> getProfileCountFromFreq(uint64_t Freq) const;
 
   bool isIrrLoopHeader(const MachineBasicBlock *MBB) const;
 

diff  --git a/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h b/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
index cb0998984dfbb..2b177e6763d39 100644
--- a/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
+++ b/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
@@ -18,6 +18,7 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/Function.h"
+#include <optional>
 
 namespace llvm {
 class MachineBasicBlock;
@@ -201,7 +202,7 @@ class MachineOptimizationRemarkEmitter {
 
   /// Compute hotness from IR value (currently assumed to be a block) if PGO is
   /// available.
-  Optional<uint64_t> computeHotness(const MachineBasicBlock &MBB);
+  std::optional<uint64_t> computeHotness(const MachineBasicBlock &MBB);
 
   /// Similar but use value from \p OptDiag and update hotness there.
   void computeHotness(DiagnosticInfoMIROptimization &Remark);

diff  --git a/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h b/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h
index 1ebc4d47e0964..6e2d7870a3cfb 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h
@@ -347,7 +347,7 @@ class PointerRecord : public TypeRecord {
 
   TypeIndex ReferentType;
   uint32_t Attrs = 0;
-  Optional<MemberPointerInfo> MemberInfo;
+  std::optional<MemberPointerInfo> MemberInfo;
 
   void setAttrs(PointerKind PK, PointerMode PM, PointerOptions PO,
                 uint8_t Size) {

diff  --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index f3abce37b1678..628445fe9fb2c 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -479,8 +479,8 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
   StringRef getPassName() const { return PassName; }
   StringRef getRemarkName() const { return RemarkName; }
   std::string getMsg() const;
-  Optional<uint64_t> getHotness() const { return Hotness; }
-  void setHotness(Optional<uint64_t> H) { Hotness = H; }
+  std::optional<uint64_t> getHotness() const { return Hotness; }
+  void setHotness(std::optional<uint64_t> H) { Hotness = H; }
 
   bool isVerbose() const { return IsVerbose; }
 
@@ -521,7 +521,7 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
 
   /// If profile information is available, this is the number of times the
   /// corresponding code was executed in a profile instrumentation run.
-  Optional<uint64_t> Hotness;
+  std::optional<uint64_t> Hotness;
 
   /// Arguments collected via the streaming interface.
   SmallVector<Argument, 4> Args;

diff  --git a/llvm/include/llvm/InterfaceStub/IFSHandler.h b/llvm/include/llvm/InterfaceStub/IFSHandler.h
index bfa5692811d76..09687bfb9e44f 100644
--- a/llvm/include/llvm/InterfaceStub/IFSHandler.h
+++ b/llvm/include/llvm/InterfaceStub/IFSHandler.h
@@ -19,6 +19,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/VersionTuple.h"
 #include <memory>
+#include <optional>
 #include <string>
 #include <vector>
 
@@ -41,10 +42,10 @@ Expected<std::unique_ptr<IFSStub>> readIFSFromBuffer(StringRef Buf);
 Error writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub);
 
 /// Override the target platform inforation in the text stub.
-Error overrideIFSTarget(IFSStub &Stub, Optional<IFSArch> OverrideArch,
-                        Optional<IFSEndiannessType> OverrideEndianness,
-                        Optional<IFSBitWidthType> OverrideBitWidth,
-                        Optional<std::string> OverrideTriple);
+Error overrideIFSTarget(IFSStub &Stub, std::optional<IFSArch> OverrideArch,
+                        std::optional<IFSEndiannessType> OverrideEndianness,
+                        std::optional<IFSBitWidthType> OverrideBitWidth,
+                        std::optional<std::string> OverrideTriple);
 
 /// Validate the target platform inforation in the text stub.
 Error validateIFSTarget(IFSStub &Stub, bool ParseTriple);

diff  --git a/llvm/include/llvm/InterfaceStub/IFSStub.h b/llvm/include/llvm/InterfaceStub/IFSStub.h
index 0f935cd478d50..1196691067333 100644
--- a/llvm/include/llvm/InterfaceStub/IFSStub.h
+++ b/llvm/include/llvm/InterfaceStub/IFSStub.h
@@ -14,8 +14,8 @@
 #ifndef LLVM_INTERFACESTUB_IFSSTUB_H
 #define LLVM_INTERFACESTUB_IFSSTUB_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/Support/VersionTuple.h"
+#include <optional>
 #include <vector>
 
 namespace llvm {
@@ -53,21 +53,21 @@ struct IFSSymbol {
   IFSSymbol() = default;
   explicit IFSSymbol(std::string SymbolName) : Name(std::move(SymbolName)) {}
   std::string Name;
-  Optional<uint64_t> Size;
+  std::optional<uint64_t> Size;
   IFSSymbolType Type;
   bool Undefined;
   bool Weak;
-  Optional<std::string> Warning;
+  std::optional<std::string> Warning;
   bool operator<(const IFSSymbol &RHS) const { return Name < RHS.Name; }
 };
 
 struct IFSTarget {
-  Optional<std::string> Triple;
-  Optional<std::string> ObjectFormat;
-  Optional<IFSArch> Arch;
-  Optional<std::string> ArchString;
-  Optional<IFSEndiannessType> Endianness;
-  Optional<IFSBitWidthType> BitWidth;
+  std::optional<std::string> Triple;
+  std::optional<std::string> ObjectFormat;
+  std::optional<IFSArch> Arch;
+  std::optional<std::string> ArchString;
+  std::optional<IFSEndiannessType> Endianness;
+  std::optional<IFSBitWidthType> BitWidth;
 
   bool empty();
 };
@@ -89,7 +89,7 @@ inline bool operator!=(const IFSTarget &Lhs, const IFSTarget &Rhs) {
 struct IFSStub {
   // TODO: Add support for symbol versioning.
   VersionTuple IfsVersion;
-  Optional<std::string> SoName;
+  std::optional<std::string> SoName;
   IFSTarget Target;
   std::vector<std::string> NeededLibs;
   std::vector<IFSSymbol> Symbols;

diff  --git a/llvm/include/llvm/ObjectYAML/ArchiveYAML.h b/llvm/include/llvm/ObjectYAML/ArchiveYAML.h
index 8d05feedcc62b..c83c7ee56f1f9 100644
--- a/llvm/include/llvm/ObjectYAML/ArchiveYAML.h
+++ b/llvm/include/llvm/ObjectYAML/ArchiveYAML.h
@@ -17,6 +17,7 @@
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/ObjectYAML/YAML.h"
 #include "llvm/ADT/MapVector.h"
+#include <optional>
 
 namespace llvm {
 namespace ArchYAML {
@@ -44,13 +45,13 @@ struct Archive {
 
     MapVector<StringRef, Field> Fields;
 
-    Optional<yaml::BinaryRef> Content;
-    Optional<llvm::yaml::Hex8> PaddingByte;
+    std::optional<yaml::BinaryRef> Content;
+    std::optional<llvm::yaml::Hex8> PaddingByte;
   };
 
   StringRef Magic;
-  Optional<std::vector<Child>> Members;
-  Optional<yaml::BinaryRef> Content;
+  std::optional<std::vector<Child>> Members;
+  std::optional<yaml::BinaryRef> Content;
 };
 
 } // end namespace ArchYAML

diff  --git a/llvm/include/llvm/ObjectYAML/COFFYAML.h b/llvm/include/llvm/ObjectYAML/COFFYAML.h
index eec5af928f6d1..b8b17e9e32d43 100644
--- a/llvm/include/llvm/ObjectYAML/COFFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/COFFYAML.h
@@ -21,6 +21,7 @@
 #include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
 #include "llvm/ObjectYAML/YAML.h"
 #include <cstdint>
+#include <optional>
 #include <vector>
 
 namespace llvm {
@@ -63,7 +64,7 @@ struct Relocation {
   // specified), allowing disambiguating between multiple symbols with the
   // same name or crafting intentionally broken files for testing.
   StringRef SymbolName;
-  Optional<uint32_t> SymbolTableIndex;
+  std::optional<uint32_t> SymbolTableIndex;
 };
 
 struct Section {
@@ -73,7 +74,7 @@ struct Section {
   std::vector<CodeViewYAML::YAMLDebugSubsection> DebugS;
   std::vector<CodeViewYAML::LeafRecord> DebugT;
   std::vector<CodeViewYAML::LeafRecord> DebugP;
-  Optional<CodeViewYAML::DebugHSection> DebugH;
+  std::optional<CodeViewYAML::DebugHSection> DebugH;
   std::vector<Relocation> Relocations;
   StringRef Name;
 
@@ -84,12 +85,12 @@ struct Symbol {
   COFF::symbol Header;
   COFF::SymbolBaseType SimpleType = COFF::IMAGE_SYM_TYPE_NULL;
   COFF::SymbolComplexType ComplexType = COFF::IMAGE_SYM_DTYPE_NULL;
-  Optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition;
-  Optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol;
-  Optional<COFF::AuxiliaryWeakExternal> WeakExternal;
+  std::optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition;
+  std::optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol;
+  std::optional<COFF::AuxiliaryWeakExternal> WeakExternal;
   StringRef File;
-  Optional<COFF::AuxiliarySectionDefinition> SectionDefinition;
-  Optional<COFF::AuxiliaryCLRToken> CLRToken;
+  std::optional<COFF::AuxiliarySectionDefinition> SectionDefinition;
+  std::optional<COFF::AuxiliaryCLRToken> CLRToken;
   StringRef Name;
 
   Symbol();
@@ -97,11 +98,12 @@ struct Symbol {
 
 struct PEHeader {
   COFF::PE32Header Header;
-  Optional<COFF::DataDirectory> DataDirectories[COFF::NUM_DATA_DIRECTORIES];
+  std::optional<COFF::DataDirectory>
+      DataDirectories[COFF::NUM_DATA_DIRECTORIES];
 };
 
 struct Object {
-  Optional<PEHeader> OptionalHeader;
+  std::optional<PEHeader> OptionalHeader;
   COFF::header Header;
   std::vector<Section> Sections;
   std::vector<Symbol> Symbols;

diff  --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
index 856cea9a15357..a70ddf3a180a2 100644
--- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -21,6 +21,7 @@
 #include "llvm/ObjectYAML/YAML.h"
 #include "llvm/Support/YAMLTraits.h"
 #include <cstdint>
+#include <optional>
 #include <unordered_map>
 #include <vector>
 
@@ -34,14 +35,14 @@ struct AttributeAbbrev {
 };
 
 struct Abbrev {
-  Optional<yaml::Hex64> Code;
+  std::optional<yaml::Hex64> Code;
   llvm::dwarf::Tag Tag;
   llvm::dwarf::Constants Children;
   std::vector<AttributeAbbrev> Attributes;
 };
 
 struct AbbrevTable {
-  Optional<uint64_t> ID;
+  std::optional<uint64_t> ID;
   std::vector<Abbrev> Table;
 };
 
@@ -52,10 +53,10 @@ struct ARangeDescriptor {
 
 struct ARange {
   dwarf::DwarfFormat Format;
-  Optional<yaml::Hex64> Length;
+  std::optional<yaml::Hex64> Length;
   uint16_t Version;
   yaml::Hex64 CuOffset;
-  Optional<yaml::Hex8> AddrSize;
+  std::optional<yaml::Hex8> AddrSize;
   yaml::Hex8 SegSize;
   std::vector<ARangeDescriptor> Descriptors;
 };
@@ -69,8 +70,8 @@ struct RangeEntry {
 
 /// Class that describes a single range list inside the .debug_ranges section.
 struct Ranges {
-  Optional<llvm::yaml::Hex64> Offset;
-  Optional<llvm::yaml::Hex8> AddrSize;
+  std::optional<llvm::yaml::Hex64> Offset;
+  std::optional<llvm::yaml::Hex8> AddrSize;
   std::vector<RangeEntry> Entries;
 };
 
@@ -108,12 +109,12 @@ struct DWARFContext {
 
 struct Unit {
   dwarf::DwarfFormat Format;
-  Optional<yaml::Hex64> Length;
+  std::optional<yaml::Hex64> Length;
   uint16_t Version;
-  Optional<uint8_t> AddrSize;
+  std::optional<uint8_t> AddrSize;
   llvm::dwarf::UnitType Type; // Added in DWARF 5
-  Optional<uint64_t> AbbrevTableID;
-  Optional<yaml::Hex64> AbbrOffset;
+  std::optional<uint64_t> AbbrevTableID;
+  std::optional<yaml::Hex64> AbbrOffset;
   std::vector<Entry> Entries;
 };
 
@@ -126,7 +127,7 @@ struct File {
 
 struct LineTableOpcode {
   dwarf::LineNumberOps Opcode;
-  Optional<uint64_t> ExtLen;
+  std::optional<uint64_t> ExtLen;
   dwarf::LineNumberExtendedOps SubOpcode;
   uint64_t Data;
   int64_t SData;
@@ -137,16 +138,16 @@ struct LineTableOpcode {
 
 struct LineTable {
   dwarf::DwarfFormat Format;
-  Optional<uint64_t> Length;
+  std::optional<uint64_t> Length;
   uint16_t Version;
-  Optional<uint64_t> PrologueLength;
+  std::optional<uint64_t> PrologueLength;
   uint8_t MinInstLength;
   uint8_t MaxOpsPerInst;
   uint8_t DefaultIsStmt;
   uint8_t LineBase;
   uint8_t LineRange;
-  Optional<uint8_t> OpcodeBase;
-  Optional<std::vector<uint8_t>> StandardOpcodeLengths;
+  std::optional<uint8_t> OpcodeBase;
+  std::optional<std::vector<uint8_t>> StandardOpcodeLengths;
   std::vector<StringRef> IncludeDirs;
   std::vector<File> Files;
   std::vector<LineTableOpcode> Opcodes;
@@ -159,16 +160,16 @@ struct SegAddrPair {
 
 struct AddrTableEntry {
   dwarf::DwarfFormat Format;
-  Optional<yaml::Hex64> Length;
+  std::optional<yaml::Hex64> Length;
   yaml::Hex16 Version;
-  Optional<yaml::Hex8> AddrSize;
+  std::optional<yaml::Hex8> AddrSize;
   yaml::Hex8 SegSelectorSize;
   std::vector<SegAddrPair> SegAddrPairs;
 };
 
 struct StringOffsetsTable {
   dwarf::DwarfFormat Format;
-  Optional<yaml::Hex64> Length;
+  std::optional<yaml::Hex64> Length;
   yaml::Hex16 Version;
   yaml::Hex16 Padding;
   std::vector<yaml::Hex64> Offsets;
@@ -187,23 +188,23 @@ struct RnglistEntry {
 struct LoclistEntry {
   dwarf::LoclistEntries Operator;
   std::vector<yaml::Hex64> Values;
-  Optional<yaml::Hex64> DescriptionsLength;
+  std::optional<yaml::Hex64> DescriptionsLength;
   std::vector<DWARFOperation> Descriptions;
 };
 
 template <typename EntryType> struct ListEntries {
-  Optional<std::vector<EntryType>> Entries;
-  Optional<yaml::BinaryRef> Content;
+  std::optional<std::vector<EntryType>> Entries;
+  std::optional<yaml::BinaryRef> Content;
 };
 
 template <typename EntryType> struct ListTable {
   dwarf::DwarfFormat Format;
-  Optional<yaml::Hex64> Length;
+  std::optional<yaml::Hex64> Length;
   yaml::Hex16 Version;
-  Optional<yaml::Hex8> AddrSize;
+  std::optional<yaml::Hex8> AddrSize;
   yaml::Hex8 SegSelectorSize;
-  Optional<uint32_t> OffsetEntryCount;
-  Optional<std::vector<yaml::Hex64>> Offsets;
+  std::optional<uint32_t> OffsetEntryCount;
+  std::optional<std::vector<yaml::Hex64>> Offsets;
   std::vector<ListEntries<EntryType>> Lists;
 };
 
@@ -211,22 +212,22 @@ struct Data {
   bool IsLittleEndian;
   bool Is64BitAddrSize;
   std::vector<AbbrevTable> DebugAbbrev;
-  Optional<std::vector<StringRef>> DebugStrings;
-  Optional<std::vector<StringOffsetsTable>> DebugStrOffsets;
-  Optional<std::vector<ARange>> DebugAranges;
-  Optional<std::vector<Ranges>> DebugRanges;
-  Optional<std::vector<AddrTableEntry>> DebugAddr;
-  Optional<PubSection> PubNames;
-  Optional<PubSection> PubTypes;
+  std::optional<std::vector<StringRef>> DebugStrings;
+  std::optional<std::vector<StringOffsetsTable>> DebugStrOffsets;
+  std::optional<std::vector<ARange>> DebugAranges;
+  std::optional<std::vector<Ranges>> DebugRanges;
+  std::optional<std::vector<AddrTableEntry>> DebugAddr;
+  std::optional<PubSection> PubNames;
+  std::optional<PubSection> PubTypes;
 
-  Optional<PubSection> GNUPubNames;
-  Optional<PubSection> GNUPubTypes;
+  std::optional<PubSection> GNUPubNames;
+  std::optional<PubSection> GNUPubTypes;
 
   std::vector<Unit> CompileUnits;
 
   std::vector<LineTable> DebugLines;
-  Optional<std::vector<ListTable<RnglistEntry>>> DebugRnglists;
-  Optional<std::vector<ListTable<LoclistEntry>>> DebugLoclists;
+  std::optional<std::vector<ListTable<RnglistEntry>>> DebugRnglists;
+  std::optional<std::vector<ListTable<LoclistEntry>>> DebugLoclists;
 
   bool isEmpty() const;
 

diff  --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 49602aa5eda16..55c61ff96b7c4 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -20,6 +20,7 @@
 #include "llvm/ObjectYAML/YAML.h"
 #include "llvm/Support/YAMLTraits.h"
 #include <cstdint>
+#include <optional>
 #include <string>
 #include <vector>
 
@@ -37,21 +38,21 @@ struct VersionTuple {
 struct FileHeader {
   std::vector<llvm::yaml::Hex8> Hash;
   VersionTuple Version;
-  Optional<uint32_t> FileSize;
+  std::optional<uint32_t> FileSize;
   uint32_t PartCount;
-  Optional<std::vector<uint32_t>> PartOffsets;
+  std::optional<std::vector<uint32_t>> PartOffsets;
 };
 
 struct DXILProgram {
   uint8_t MajorVersion;
   uint8_t MinorVersion;
   uint16_t ShaderKind;
-  Optional<uint32_t> Size;
+  std::optional<uint32_t> Size;
   uint16_t DXILMajorVersion;
   uint16_t DXILMinorVersion;
-  Optional<uint32_t> DXILOffset;
-  Optional<uint32_t> DXILSize;
-  Optional<std::vector<llvm::yaml::Hex8>> DXIL;
+  std::optional<uint32_t> DXILOffset;
+  std::optional<uint32_t> DXILSize;
+  std::optional<std::vector<llvm::yaml::Hex8>> DXIL;
 };
 
 #define SHADER_FLAG(Num, Val, Str) bool Val = false;
@@ -75,9 +76,9 @@ struct Part {
   Part(std::string N, uint32_t S) : Name(N), Size(S) {}
   std::string Name;
   uint32_t Size;
-  Optional<DXILProgram> Program;
-  Optional<ShaderFlags> Flags;
-  Optional<ShaderHash> Hash;
+  std::optional<DXILProgram> Program;
+  std::optional<ShaderFlags> Flags;
+  std::optional<ShaderHash> Hash;
 };
 
 struct Object {

diff  --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h
index ddd5dd9cf3c96..cc77971c61cb0 100644
--- a/llvm/include/llvm/ObjectYAML/ELFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h
@@ -23,6 +23,7 @@
 #include "llvm/Support/YAMLTraits.h"
 #include <cstdint>
 #include <memory>
+#include <optional>
 #include <vector>
 
 namespace llvm {
@@ -115,18 +116,18 @@ struct FileHeader {
   ELF_ELFOSABI OSABI;
   llvm::yaml::Hex8 ABIVersion;
   ELF_ET Type;
-  Optional<ELF_EM> Machine;
+  std::optional<ELF_EM> Machine;
   ELF_EF Flags;
   llvm::yaml::Hex64 Entry;
-  Optional<StringRef> SectionHeaderStringTable;
+  std::optional<StringRef> SectionHeaderStringTable;
 
-  Optional<llvm::yaml::Hex64> EPhOff;
-  Optional<llvm::yaml::Hex16> EPhEntSize;
-  Optional<llvm::yaml::Hex16> EPhNum;
-  Optional<llvm::yaml::Hex16> EShEntSize;
-  Optional<llvm::yaml::Hex64> EShOff;
-  Optional<llvm::yaml::Hex16> EShNum;
-  Optional<llvm::yaml::Hex16> EShStrNdx;
+  std::optional<llvm::yaml::Hex64> EPhOff;
+  std::optional<llvm::yaml::Hex16> EPhEntSize;
+  std::optional<llvm::yaml::Hex16> EPhNum;
+  std::optional<llvm::yaml::Hex16> EShEntSize;
+  std::optional<llvm::yaml::Hex64> EShOff;
+  std::optional<llvm::yaml::Hex16> EShNum;
+  std::optional<llvm::yaml::Hex16> EShStrNdx;
 };
 
 struct SectionHeader {
@@ -136,14 +137,14 @@ struct SectionHeader {
 struct Symbol {
   StringRef Name;
   ELF_STT Type;
-  Optional<StringRef> Section;
-  Optional<ELF_SHN> Index;
+  std::optional<StringRef> Section;
+  std::optional<ELF_SHN> Index;
   ELF_STB Binding;
-  Optional<llvm::yaml::Hex64> Value;
-  Optional<llvm::yaml::Hex64> Size;
-  Optional<uint8_t> Other;
+  std::optional<llvm::yaml::Hex64> Value;
+  std::optional<llvm::yaml::Hex64> Size;
+  std::optional<uint8_t> Other;
 
-  Optional<uint32_t> StName;
+  std::optional<uint32_t> StName;
 };
 
 struct SectionOrType {
@@ -164,8 +165,8 @@ struct BBAddrMapEntry {
   uint8_t Version;
   llvm::yaml::Hex8 Feature;
   llvm::yaml::Hex64 Address;
-  Optional<uint64_t> NumBlocks;
-  Optional<std::vector<BBEntry>> BBEntries;
+  std::optional<uint64_t> NumBlocks;
+  std::optional<std::vector<BBEntry>> BBEntries;
 };
 
 struct StackSizeEntry {
@@ -211,7 +212,7 @@ struct Chunk {
 
   ChunkKind Kind;
   StringRef Name;
-  Optional<llvm::yaml::Hex64> Offset;
+  std::optional<llvm::yaml::Hex64> Offset;
 
   // Usually chunks are not created implicitly, but rather loaded from YAML.
   // This flag is used to signal whether this is the case or not.
@@ -223,14 +224,14 @@ struct Chunk {
 
 struct Section : public Chunk {
   ELF_SHT Type;
-  Optional<ELF_SHF> Flags;
-  Optional<llvm::yaml::Hex64> Address;
-  Optional<StringRef> Link;
+  std::optional<ELF_SHF> Flags;
+  std::optional<llvm::yaml::Hex64> Address;
+  std::optional<StringRef> Link;
   llvm::yaml::Hex64 AddressAlign;
-  Optional<llvm::yaml::Hex64> EntSize;
+  std::optional<llvm::yaml::Hex64> EntSize;
 
-  Optional<yaml::BinaryRef> Content;
-  Optional<llvm::yaml::Hex64> Size;
+  std::optional<yaml::BinaryRef> Content;
+  std::optional<llvm::yaml::Hex64> Size;
 
   // Holds the original section index.
   unsigned OriginalSecNdx;
@@ -252,35 +253,35 @@ struct Section : public Chunk {
   // useful for creating invalid objects.
 
   // This can be used to override the sh_addralign field.
-  Optional<llvm::yaml::Hex64> ShAddrAlign;
+  std::optional<llvm::yaml::Hex64> ShAddrAlign;
 
   // This can be used to override the offset stored in the sh_name field.
   // It does not affect the name stored in the string table.
-  Optional<llvm::yaml::Hex64> ShName;
+  std::optional<llvm::yaml::Hex64> ShName;
 
   // This can be used to override the sh_offset field. It does not place the
   // section data at the offset specified.
-  Optional<llvm::yaml::Hex64> ShOffset;
+  std::optional<llvm::yaml::Hex64> ShOffset;
 
   // This can be used to override the sh_size field. It does not affect the
   // content written.
-  Optional<llvm::yaml::Hex64> ShSize;
+  std::optional<llvm::yaml::Hex64> ShSize;
 
   // This can be used to override the sh_flags field.
-  Optional<llvm::yaml::Hex64> ShFlags;
+  std::optional<llvm::yaml::Hex64> ShFlags;
 
   // This can be used to override the sh_type field. It is useful when we
   // want to use specific YAML keys for a section of a particular type to
   // describe the content, but still want to have a 
diff erent final type
   // for the section.
-  Optional<ELF_SHT> ShType;
+  std::optional<ELF_SHT> ShType;
 };
 
 // Fill is a block of data which is placed outside of sections. It is
 // not present in the sections header table, but it might affect the output file
 // size and program headers produced.
 struct Fill : Chunk {
-  Optional<yaml::BinaryRef> Pattern;
+  std::optional<yaml::BinaryRef> Pattern;
   llvm::yaml::Hex64 Size;
 
   Fill() : Chunk(ChunkKind::Fill, /*Implicit=*/false) {}
@@ -296,9 +297,9 @@ struct SectionHeaderTable : Chunk {
     return S->Kind == ChunkKind::SectionHeaderTable;
   }
 
-  Optional<std::vector<SectionHeader>> Sections;
-  Optional<std::vector<SectionHeader>> Excluded;
-  Optional<bool> NoHeaders;
+  std::optional<std::vector<SectionHeader>> Sections;
+  std::optional<std::vector<SectionHeader>> Excluded;
+  std::optional<bool> NoHeaders;
 
   size_t getNumHeaders(size_t SectionsNum) const {
     if (IsImplicit || isDefault())
@@ -314,7 +315,7 @@ struct SectionHeaderTable : Chunk {
 };
 
 struct BBAddrMapSection : Section {
-  Optional<std::vector<BBAddrMapEntry>> Entries;
+  std::optional<std::vector<BBAddrMapEntry>> Entries;
 
   BBAddrMapSection() : Section(ChunkKind::BBAddrMap) {}
 
@@ -328,7 +329,7 @@ struct BBAddrMapSection : Section {
 };
 
 struct StackSizesSection : Section {
-  Optional<std::vector<StackSizeEntry>> Entries;
+  std::optional<std::vector<StackSizeEntry>> Entries;
 
   StackSizesSection() : Section(ChunkKind::StackSizes) {}
 
@@ -346,7 +347,7 @@ struct StackSizesSection : Section {
 };
 
 struct DynamicSection : Section {
-  Optional<std::vector<DynamicEntry>> Entries;
+  std::optional<std::vector<DynamicEntry>> Entries;
 
   DynamicSection() : Section(ChunkKind::Dynamic) {}
 
@@ -358,7 +359,7 @@ struct DynamicSection : Section {
 };
 
 struct RawContentSection : Section {
-  Optional<llvm::yaml::Hex64> Info;
+  std::optional<llvm::yaml::Hex64> Info;
 
   RawContentSection() : Section(ChunkKind::RawContent) {}
 
@@ -367,7 +368,7 @@ struct RawContentSection : Section {
   }
 
   // Is used when a content is read as an array of bytes.
-  Optional<std::vector<uint8_t>> ContentBuf;
+  std::optional<std::vector<uint8_t>> ContentBuf;
 };
 
 struct NoBitsSection : Section {
@@ -377,7 +378,7 @@ struct NoBitsSection : Section {
 };
 
 struct NoteSection : Section {
-  Optional<std::vector<ELFYAML::NoteEntry>> Notes;
+  std::optional<std::vector<ELFYAML::NoteEntry>> Notes;
 
   NoteSection() : Section(ChunkKind::Note) {}
 
@@ -389,8 +390,8 @@ struct NoteSection : Section {
 };
 
 struct HashSection : Section {
-  Optional<std::vector<uint32_t>> Bucket;
-  Optional<std::vector<uint32_t>> Chain;
+  std::optional<std::vector<uint32_t>> Bucket;
+  std::optional<std::vector<uint32_t>> Chain;
 
   std::vector<std::pair<StringRef, bool>> getEntries() const override {
     return {{"Bucket", Bucket.has_value()}, {"Chain", Chain.has_value()}};
@@ -398,8 +399,8 @@ struct HashSection : Section {
 
   // The following members are used to override section fields.
   // This is useful for creating invalid objects.
-  Optional<llvm::yaml::Hex64> NBucket;
-  Optional<llvm::yaml::Hex64> NChain;
+  std::optional<llvm::yaml::Hex64> NBucket;
+  std::optional<llvm::yaml::Hex64> NChain;
 
   HashSection() : Section(ChunkKind::Hash) {}
 
@@ -410,7 +411,7 @@ struct GnuHashHeader {
   // The number of hash buckets.
   // Not used when dumping the object, but can be used to override
   // the real number of buckets when emiting an object from a YAML document.
-  Optional<llvm::yaml::Hex32> NBuckets;
+  std::optional<llvm::yaml::Hex32> NBuckets;
 
   // Index of the first symbol in the dynamic symbol table
   // included in the hash table.
@@ -420,17 +421,17 @@ struct GnuHashHeader {
   // Not used when dumping the object, but can be used to override the real
   // number of words in the Bloom filter when emiting an object from a YAML
   // document.
-  Optional<llvm::yaml::Hex32> MaskWords;
+  std::optional<llvm::yaml::Hex32> MaskWords;
 
   // A shift constant used by the Bloom filter.
   llvm::yaml::Hex32 Shift2;
 };
 
 struct GnuHashSection : Section {
-  Optional<GnuHashHeader> Header;
-  Optional<std::vector<llvm::yaml::Hex64>> BloomFilter;
-  Optional<std::vector<llvm::yaml::Hex32>> HashBuckets;
-  Optional<std::vector<llvm::yaml::Hex32>> HashValues;
+  std::optional<GnuHashHeader> Header;
+  std::optional<std::vector<llvm::yaml::Hex64>> BloomFilter;
+  std::optional<std::vector<llvm::yaml::Hex32>> HashBuckets;
+  std::optional<std::vector<llvm::yaml::Hex32>> HashValues;
 
   GnuHashSection() : Section(ChunkKind::GnuHash) {}
 
@@ -458,8 +459,8 @@ struct VerneedEntry {
 };
 
 struct VerneedSection : Section {
-  Optional<std::vector<VerneedEntry>> VerneedV;
-  Optional<llvm::yaml::Hex64> Info;
+  std::optional<std::vector<VerneedEntry>> VerneedV;
+  std::optional<llvm::yaml::Hex64> Info;
 
   VerneedSection() : Section(ChunkKind::Verneed) {}
 
@@ -473,7 +474,7 @@ struct VerneedSection : Section {
 };
 
 struct AddrsigSection : Section {
-  Optional<std::vector<YAMLFlowString>> Symbols;
+  std::optional<std::vector<YAMLFlowString>> Symbols;
 
   AddrsigSection() : Section(ChunkKind::Addrsig) {}
 
@@ -490,7 +491,7 @@ struct LinkerOption {
 };
 
 struct LinkerOptionsSection : Section {
-  Optional<std::vector<LinkerOption>> Options;
+  std::optional<std::vector<LinkerOption>> Options;
 
   LinkerOptionsSection() : Section(ChunkKind::LinkerOptions) {}
 
@@ -504,7 +505,7 @@ struct LinkerOptionsSection : Section {
 };
 
 struct DependentLibrariesSection : Section {
-  Optional<std::vector<YAMLFlowString>> Libs;
+  std::optional<std::vector<YAMLFlowString>> Libs;
 
   DependentLibrariesSection() : Section(ChunkKind::DependentLibraries) {}
 
@@ -524,7 +525,7 @@ struct CallGraphEntryWeight {
 };
 
 struct CallGraphProfileSection : Section {
-  Optional<std::vector<CallGraphEntryWeight>> Entries;
+  std::optional<std::vector<CallGraphEntryWeight>> Entries;
 
   CallGraphProfileSection() : Section(ChunkKind::CallGraphProfile) {}
 
@@ -538,7 +539,7 @@ struct CallGraphProfileSection : Section {
 };
 
 struct SymverSection : Section {
-  Optional<std::vector<uint16_t>> Entries;
+  std::optional<std::vector<uint16_t>> Entries;
 
   SymverSection() : Section(ChunkKind::Symver) {}
 
@@ -550,16 +551,16 @@ struct SymverSection : Section {
 };
 
 struct VerdefEntry {
-  Optional<uint16_t> Version;
-  Optional<uint16_t> Flags;
-  Optional<uint16_t> VersionNdx;
-  Optional<uint32_t> Hash;
+  std::optional<uint16_t> Version;
+  std::optional<uint16_t> Flags;
+  std::optional<uint16_t> VersionNdx;
+  std::optional<uint32_t> Hash;
   std::vector<StringRef> VerNames;
 };
 
 struct VerdefSection : Section {
-  Optional<std::vector<VerdefEntry>> Entries;
-  Optional<llvm::yaml::Hex64> Info;
+  std::optional<std::vector<VerdefEntry>> Entries;
+  std::optional<llvm::yaml::Hex64> Info;
 
   VerdefSection() : Section(ChunkKind::Verdef) {}
 
@@ -573,8 +574,8 @@ struct VerdefSection : Section {
 struct GroupSection : Section {
   // Members of a group contain a flag and a list of section indices
   // that are part of the group.
-  Optional<std::vector<SectionOrType>> Members;
-  Optional<StringRef> Signature; /* Info */
+  std::optional<std::vector<SectionOrType>> Members;
+  std::optional<StringRef> Signature; /* Info */
 
   GroupSection() : Section(ChunkKind::Group) {}
 
@@ -589,11 +590,11 @@ struct Relocation {
   llvm::yaml::Hex64 Offset;
   YAMLIntUInt Addend;
   ELF_REL Type;
-  Optional<StringRef> Symbol;
+  std::optional<StringRef> Symbol;
 };
 
 struct RelocationSection : Section {
-  Optional<std::vector<Relocation>> Relocations;
+  std::optional<std::vector<Relocation>> Relocations;
   StringRef RelocatableSec; /* Info */
 
   RelocationSection() : Section(ChunkKind::Relocation) {}
@@ -608,7 +609,7 @@ struct RelocationSection : Section {
 };
 
 struct RelrSection : Section {
-  Optional<std::vector<llvm::yaml::Hex64>> Entries;
+  std::optional<std::vector<llvm::yaml::Hex64>> Entries;
 
   RelrSection() : Section(ChunkKind::Relr) {}
 
@@ -622,7 +623,7 @@ struct RelrSection : Section {
 };
 
 struct SymtabShndxSection : Section {
-  Optional<std::vector<uint32_t>> Entries;
+  std::optional<std::vector<uint32_t>> Entries;
 
   SymtabShndxSection() : Section(ChunkKind::SymtabShndxSection) {}
 
@@ -641,7 +642,7 @@ struct ARMIndexTableEntry {
 };
 
 struct ARMIndexTableSection : Section {
-  Optional<std::vector<ARMIndexTableEntry>> Entries;
+  std::optional<std::vector<ARMIndexTableEntry>> Entries;
 
   ARMIndexTableSection() : Section(ChunkKind::ARMIndexTable) {}
 
@@ -680,12 +681,12 @@ struct ProgramHeader {
   ELF_PF Flags;
   llvm::yaml::Hex64 VAddr;
   llvm::yaml::Hex64 PAddr;
-  Optional<llvm::yaml::Hex64> Align;
-  Optional<llvm::yaml::Hex64> FileSize;
-  Optional<llvm::yaml::Hex64> MemSize;
-  Optional<llvm::yaml::Hex64> Offset;
-  Optional<StringRef> FirstSec;
-  Optional<StringRef> LastSec;
+  std::optional<llvm::yaml::Hex64> Align;
+  std::optional<llvm::yaml::Hex64> FileSize;
+  std::optional<llvm::yaml::Hex64> MemSize;
+  std::optional<llvm::yaml::Hex64> Offset;
+  std::optional<StringRef> FirstSec;
+  std::optional<StringRef> LastSec;
 
   // This vector contains all chunks from [FirstSec, LastSec].
   std::vector<Chunk *> Chunks;
@@ -703,9 +704,9 @@ struct Object {
   // cleaner and nicer if we read them from the YAML as a separate
   // top-level key, which automatically ensures that invariants like there
   // being a single SHT_SYMTAB section are upheld.
-  Optional<std::vector<Symbol>> Symbols;
-  Optional<std::vector<Symbol>> DynamicSymbols;
-  Optional<DWARFYAML::Data> DWARF;
+  std::optional<std::vector<Symbol>> Symbols;
+  std::optional<std::vector<Symbol>> DynamicSymbols;
+  std::optional<DWARFYAML::Data> DWARF;
 
   std::vector<Section *> getSections() {
     std::vector<Section *> Ret;

diff  --git a/llvm/include/llvm/ObjectYAML/MachOYAML.h b/llvm/include/llvm/ObjectYAML/MachOYAML.h
index 7d35766cc2420..ccb81f5702d0e 100644
--- a/llvm/include/llvm/ObjectYAML/MachOYAML.h
+++ b/llvm/include/llvm/ObjectYAML/MachOYAML.h
@@ -21,6 +21,7 @@
 #include "llvm/ObjectYAML/YAML.h"
 #include "llvm/Support/YAMLTraits.h"
 #include <cstdint>
+#include <optional>
 #include <string>
 #include <vector>
 
@@ -54,7 +55,7 @@ struct Section {
   llvm::yaml::Hex32 reserved1;
   llvm::yaml::Hex32 reserved2;
   llvm::yaml::Hex32 reserved3;
-  Optional<llvm::yaml::BinaryRef> content;
+  std::optional<llvm::yaml::BinaryRef> content;
   std::vector<Relocation> relocations;
 };
 
@@ -141,7 +142,7 @@ struct Object {
   std::vector<LoadCommand> LoadCommands;
   std::vector<Section> Sections;
   LinkEditData LinkEdit;
-  Optional<llvm::yaml::BinaryRef> RawLinkEditSegment;
+  std::optional<llvm::yaml::BinaryRef> RawLinkEditSegment;
   DWARFYAML::Data DWARF;
 };
 

diff  --git a/llvm/include/llvm/ObjectYAML/OffloadYAML.h b/llvm/include/llvm/ObjectYAML/OffloadYAML.h
index fc7a8cc7e78e6..95d64c6eca184 100644
--- a/llvm/include/llvm/ObjectYAML/OffloadYAML.h
+++ b/llvm/include/llvm/ObjectYAML/OffloadYAML.h
@@ -19,6 +19,7 @@
 #include "llvm/Object/OffloadBinary.h"
 #include "llvm/ObjectYAML/YAML.h"
 #include "llvm/Support/YAMLTraits.h"
+#include <optional>
 
 namespace llvm {
 namespace OffloadYAML {
@@ -30,17 +31,17 @@ struct Binary {
   };
 
   struct Member {
-    Optional<object::ImageKind> ImageKind;
-    Optional<object::OffloadKind> OffloadKind;
-    Optional<uint32_t> Flags;
-    Optional<std::vector<StringEntry>> StringEntries;
-    Optional<yaml::BinaryRef> Content;
+    std::optional<object::ImageKind> ImageKind;
+    std::optional<object::OffloadKind> OffloadKind;
+    std::optional<uint32_t> Flags;
+    std::optional<std::vector<StringEntry>> StringEntries;
+    std::optional<yaml::BinaryRef> Content;
   };
 
-  Optional<uint32_t> Version;
-  Optional<uint64_t> Size;
-  Optional<uint64_t> EntryOffset;
-  Optional<uint64_t> EntrySize;
+  std::optional<uint32_t> Version;
+  std::optional<uint64_t> Size;
+  std::optional<uint64_t> EntryOffset;
+  std::optional<uint64_t> EntrySize;
   std::vector<Member> Members;
 };
 

diff  --git a/llvm/include/llvm/ObjectYAML/XCOFFYAML.h b/llvm/include/llvm/ObjectYAML/XCOFFYAML.h
index 39bc334e1a89b..f1e821fe5fa36 100644
--- a/llvm/include/llvm/ObjectYAML/XCOFFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/XCOFFYAML.h
@@ -14,6 +14,7 @@
 
 #include "llvm/BinaryFormat/XCOFF.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include <optional>
 #include <vector>
 
 namespace llvm {
@@ -30,35 +31,35 @@ struct FileHeader {
 };
 
 struct AuxiliaryHeader {
-  Optional<llvm::yaml::Hex16> Magic;
-  Optional<llvm::yaml::Hex16> Version;
-  Optional<llvm::yaml::Hex64> TextStartAddr;
-  Optional<llvm::yaml::Hex64> DataStartAddr;
-  Optional<llvm::yaml::Hex64> TOCAnchorAddr;
-  Optional<uint16_t> SecNumOfEntryPoint;
-  Optional<uint16_t> SecNumOfText;
-  Optional<uint16_t> SecNumOfData;
-  Optional<uint16_t> SecNumOfTOC;
-  Optional<uint16_t> SecNumOfLoader;
-  Optional<uint16_t> SecNumOfBSS;
-  Optional<llvm::yaml::Hex16> MaxAlignOfText;
-  Optional<llvm::yaml::Hex16> MaxAlignOfData;
-  Optional<llvm::yaml::Hex16> ModuleType;
-  Optional<llvm::yaml::Hex8> CpuFlag;
-  Optional<llvm::yaml::Hex8> CpuType;
-  Optional<llvm::yaml::Hex8> TextPageSize;
-  Optional<llvm::yaml::Hex8> DataPageSize;
-  Optional<llvm::yaml::Hex8> StackPageSize;
-  Optional<llvm::yaml::Hex8> FlagAndTDataAlignment;
-  Optional<llvm::yaml::Hex64> TextSize;
-  Optional<llvm::yaml::Hex64> InitDataSize;
-  Optional<llvm::yaml::Hex64> BssDataSize;
-  Optional<llvm::yaml::Hex64> EntryPointAddr;
-  Optional<llvm::yaml::Hex64> MaxStackSize;
-  Optional<llvm::yaml::Hex64> MaxDataSize;
-  Optional<uint16_t> SecNumOfTData;
-  Optional<uint16_t> SecNumOfTBSS;
-  Optional<llvm::yaml::Hex16> Flag;
+  std::optional<llvm::yaml::Hex16> Magic;
+  std::optional<llvm::yaml::Hex16> Version;
+  std::optional<llvm::yaml::Hex64> TextStartAddr;
+  std::optional<llvm::yaml::Hex64> DataStartAddr;
+  std::optional<llvm::yaml::Hex64> TOCAnchorAddr;
+  std::optional<uint16_t> SecNumOfEntryPoint;
+  std::optional<uint16_t> SecNumOfText;
+  std::optional<uint16_t> SecNumOfData;
+  std::optional<uint16_t> SecNumOfTOC;
+  std::optional<uint16_t> SecNumOfLoader;
+  std::optional<uint16_t> SecNumOfBSS;
+  std::optional<llvm::yaml::Hex16> MaxAlignOfText;
+  std::optional<llvm::yaml::Hex16> MaxAlignOfData;
+  std::optional<llvm::yaml::Hex16> ModuleType;
+  std::optional<llvm::yaml::Hex8> CpuFlag;
+  std::optional<llvm::yaml::Hex8> CpuType;
+  std::optional<llvm::yaml::Hex8> TextPageSize;
+  std::optional<llvm::yaml::Hex8> DataPageSize;
+  std::optional<llvm::yaml::Hex8> StackPageSize;
+  std::optional<llvm::yaml::Hex8> FlagAndTDataAlignment;
+  std::optional<llvm::yaml::Hex64> TextSize;
+  std::optional<llvm::yaml::Hex64> InitDataSize;
+  std::optional<llvm::yaml::Hex64> BssDataSize;
+  std::optional<llvm::yaml::Hex64> EntryPointAddr;
+  std::optional<llvm::yaml::Hex64> MaxStackSize;
+  std::optional<llvm::yaml::Hex64> MaxDataSize;
+  std::optional<uint16_t> SecNumOfTData;
+  std::optional<uint16_t> SecNumOfTBSS;
+  std::optional<llvm::yaml::Hex16> Flag;
 };
 
 struct Relocation {
@@ -100,8 +101,8 @@ struct AuxSymbolEnt {
 };
 
 struct FileAuxEnt : AuxSymbolEnt {
-  Optional<StringRef> FileNameOrString;
-  Optional<XCOFF::CFileStringType> FileStringType;
+  std::optional<StringRef> FileNameOrString;
+  std::optional<XCOFF::CFileStringType> FileStringType;
 
   FileAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_FILE) {}
   static bool classof(const AuxSymbolEnt *S) {
@@ -111,17 +112,17 @@ struct FileAuxEnt : AuxSymbolEnt {
 
 struct CsectAuxEnt : AuxSymbolEnt {
   // Only for XCOFF32.
-  Optional<uint32_t> SectionOrLength;
-  Optional<uint32_t> StabInfoIndex;
-  Optional<uint16_t> StabSectNum;
+  std::optional<uint32_t> SectionOrLength;
+  std::optional<uint32_t> StabInfoIndex;
+  std::optional<uint16_t> StabSectNum;
   // Only for XCOFF64.
-  Optional<uint32_t> SectionOrLengthLo;
-  Optional<uint32_t> SectionOrLengthHi;
+  std::optional<uint32_t> SectionOrLengthLo;
+  std::optional<uint32_t> SectionOrLengthHi;
   // Common fields for both XCOFF32 and XCOFF64.
-  Optional<uint32_t> ParameterHashIndex;
-  Optional<uint16_t> TypeChkSectNum;
-  Optional<uint8_t> SymbolAlignmentAndType;
-  Optional<XCOFF::StorageMappingClass> StorageMappingClass;
+  std::optional<uint32_t> ParameterHashIndex;
+  std::optional<uint16_t> TypeChkSectNum;
+  std::optional<uint8_t> SymbolAlignmentAndType;
+  std::optional<XCOFF::StorageMappingClass> StorageMappingClass;
 
   CsectAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_CSECT) {}
   static bool classof(const AuxSymbolEnt *S) {
@@ -130,10 +131,10 @@ struct CsectAuxEnt : AuxSymbolEnt {
 };
 
 struct FunctionAuxEnt : AuxSymbolEnt {
-  Optional<uint32_t> OffsetToExceptionTbl; // Only for XCOFF32.
-  Optional<uint64_t> PtrToLineNum;
-  Optional<uint32_t> SizeOfFunction;
-  Optional<int32_t> SymIdxOfNextBeyond;
+  std::optional<uint32_t> OffsetToExceptionTbl; // Only for XCOFF32.
+  std::optional<uint64_t> PtrToLineNum;
+  std::optional<uint32_t> SizeOfFunction;
+  std::optional<int32_t> SymIdxOfNextBeyond;
 
   FunctionAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_FCN) {}
   static bool classof(const AuxSymbolEnt *S) {
@@ -142,9 +143,9 @@ struct FunctionAuxEnt : AuxSymbolEnt {
 };
 
 struct ExcpetionAuxEnt : AuxSymbolEnt {
-  Optional<uint64_t> OffsetToExceptionTbl;
-  Optional<uint32_t> SizeOfFunction;
-  Optional<int32_t> SymIdxOfNextBeyond;
+  std::optional<uint64_t> OffsetToExceptionTbl;
+  std::optional<uint32_t> SizeOfFunction;
+  std::optional<int32_t> SymIdxOfNextBeyond;
 
   ExcpetionAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_EXCEPT) {}
   static bool classof(const AuxSymbolEnt *S) {
@@ -154,10 +155,10 @@ struct ExcpetionAuxEnt : AuxSymbolEnt {
 
 struct BlockAuxEnt : AuxSymbolEnt {
   // Only for XCOFF32.
-  Optional<uint16_t> LineNumHi;
-  Optional<uint16_t> LineNumLo;
+  std::optional<uint16_t> LineNumHi;
+  std::optional<uint16_t> LineNumLo;
   // Only for XCOFF64.
-  Optional<uint32_t> LineNum;
+  std::optional<uint32_t> LineNum;
 
   BlockAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_SYM) {}
   static bool classof(const AuxSymbolEnt *S) {
@@ -166,8 +167,8 @@ struct BlockAuxEnt : AuxSymbolEnt {
 };
 
 struct SectAuxEntForDWARF : AuxSymbolEnt {
-  Optional<uint32_t> LengthOfSectionPortion;
-  Optional<uint32_t> NumberOfRelocEnt;
+  std::optional<uint32_t> LengthOfSectionPortion;
+  std::optional<uint32_t> NumberOfRelocEnt;
 
   SectAuxEntForDWARF() : AuxSymbolEnt(AuxSymbolType::AUX_SECT) {}
   static bool classof(const AuxSymbolEnt *S) {
@@ -176,9 +177,9 @@ struct SectAuxEntForDWARF : AuxSymbolEnt {
 };
 
 struct SectAuxEntForStat : AuxSymbolEnt {
-  Optional<uint32_t> SectionLength;
-  Optional<uint16_t> NumberOfRelocEnt;
-  Optional<uint16_t> NumberOfLineNum;
+  std::optional<uint32_t> SectionLength;
+  std::optional<uint16_t> NumberOfRelocEnt;
+  std::optional<uint16_t> NumberOfLineNum;
 
   SectAuxEntForStat() : AuxSymbolEnt(AuxSymbolType::AUX_STAT) {}
   static bool classof(const AuxSymbolEnt *S) {
@@ -189,25 +190,25 @@ struct SectAuxEntForStat : AuxSymbolEnt {
 struct Symbol {
   StringRef SymbolName;
   llvm::yaml::Hex64 Value; // Symbol value; storage class-dependent.
-  Optional<StringRef> SectionName;
-  Optional<uint16_t> SectionIndex;
+  std::optional<StringRef> SectionName;
+  std::optional<uint16_t> SectionIndex;
   llvm::yaml::Hex16 Type;
   XCOFF::StorageClass StorageClass;
-  Optional<uint8_t> NumberOfAuxEntries;
+  std::optional<uint8_t> NumberOfAuxEntries;
   std::vector<std::unique_ptr<AuxSymbolEnt>> AuxEntries;
 };
 
 struct StringTable {
-  Optional<uint32_t> ContentSize; // The total size of the string table.
-  Optional<uint32_t> Length;      // The value of the length field for the first
+  std::optional<uint32_t> ContentSize; // The total size of the string table.
+  std::optional<uint32_t> Length; // The value of the length field for the first
                                   // 4 bytes of the table.
-  Optional<std::vector<StringRef>> Strings;
-  Optional<yaml::BinaryRef> RawContent;
+  std::optional<std::vector<StringRef>> Strings;
+  std::optional<yaml::BinaryRef> RawContent;
 };
 
 struct Object {
   FileHeader Header;
-  Optional<AuxiliaryHeader> AuxHeader;
+  std::optional<AuxiliaryHeader> AuxHeader;
   std::vector<Section> Sections;
   std::vector<Symbol> Symbols;
   StringTable StrTbl;

diff  --git a/llvm/include/llvm/ProfileData/InstrProfCorrelator.h b/llvm/include/llvm/ProfileData/InstrProfCorrelator.h
index 0efd4ea65bfdc..3238a90c1747c 100644
--- a/llvm/include/llvm/ProfileData/InstrProfCorrelator.h
+++ b/llvm/include/llvm/ProfileData/InstrProfCorrelator.h
@@ -17,6 +17,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/YAMLTraits.h"
+#include <optional>
 #include <vector>
 
 namespace llvm {
@@ -83,12 +84,12 @@ class InstrProfCorrelator {
 
   struct Probe {
     std::string FunctionName;
-    Optional<std::string> LinkageName;
+    std::optional<std::string> LinkageName;
     yaml::Hex64 CFGHash;
     yaml::Hex64 CounterOffset;
     uint32_t NumCounters;
-    Optional<std::string> FilePath;
-    Optional<int> LineNumber;
+    std::optional<std::string> FilePath;
+    std::optional<int> LineNumber;
   };
 
   struct CorrelationData {

diff  --git a/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h b/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h
index a997fba481fd0..f3c2c0dbb9d3a 100644
--- a/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h
+++ b/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h
@@ -17,6 +17,7 @@
 #include "llvm/Bitstream/BitstreamWriter.h"
 #include "llvm/Remarks/BitstreamRemarkContainer.h"
 #include "llvm/Remarks/RemarkSerializer.h"
+#include <optional>
 
 namespace llvm {
 namespace remarks {
@@ -107,7 +108,7 @@ struct BitstreamRemarkSerializerHelper {
   void emitMetaBlock(uint64_t ContainerVersion,
                      Optional<uint64_t> RemarkVersion,
                      Optional<const StringTable *> StrTab = std::nullopt,
-                     Optional<StringRef> Filename = std::nullopt);
+                     std::optional<StringRef> Filename = std::nullopt);
 
   /// Emit a remark block. The string table is required.
   void emitRemarkBlock(const Remark &Remark, StringTable &StrTab);
@@ -146,9 +147,9 @@ struct BitstreamRemarkSerializer : public RemarkSerializer {
   /// The metadata serializer associated to this remark serializer. Based on the
   /// container type of the current serializer, the container type of the
   /// metadata serializer will change.
-  std::unique_ptr<MetaSerializer>
-  metaSerializer(raw_ostream &OS,
-                 Optional<StringRef> ExternalFilename = std::nullopt) override;
+  std::unique_ptr<MetaSerializer> metaSerializer(
+      raw_ostream &OS,
+      std::optional<StringRef> ExternalFilename = std::nullopt) override;
 
   static bool classof(const RemarkSerializer *S) {
     return S->SerializerFormat == Format::Bitstream;
@@ -167,13 +168,13 @@ struct BitstreamMetaSerializer : public MetaSerializer {
   BitstreamRemarkSerializerHelper *Helper = nullptr;
 
   Optional<const StringTable *> StrTab;
-  Optional<StringRef> ExternalFilename;
+  std::optional<StringRef> ExternalFilename;
 
   /// Create a new meta serializer based on \p ContainerType.
   BitstreamMetaSerializer(raw_ostream &OS,
                           BitstreamRemarkContainerType ContainerType,
                           Optional<const StringTable *> StrTab = std::nullopt,
-                          Optional<StringRef> ExternalFilename = std::nullopt)
+                          std::optional<StringRef> ExternalFilename = std::nullopt)
       : MetaSerializer(OS), TmpHelper(std::nullopt), Helper(nullptr),
         StrTab(StrTab), ExternalFilename(ExternalFilename) {
     TmpHelper.emplace(ContainerType);
@@ -184,7 +185,7 @@ struct BitstreamMetaSerializer : public MetaSerializer {
   BitstreamMetaSerializer(raw_ostream &OS,
                           BitstreamRemarkSerializerHelper &Helper,
                           Optional<const StringTable *> StrTab = std::nullopt,
-                          Optional<StringRef> ExternalFilename = std::nullopt)
+                          std::optional<StringRef> ExternalFilename = std::nullopt)
       : MetaSerializer(OS), TmpHelper(std::nullopt), Helper(&Helper),
         StrTab(StrTab), ExternalFilename(ExternalFilename) {}
 

diff  --git a/llvm/include/llvm/Remarks/Remark.h b/llvm/include/llvm/Remarks/Remark.h
index 160e8dc8db706..e1f9d33f0b570 100644
--- a/llvm/include/llvm/Remarks/Remark.h
+++ b/llvm/include/llvm/Remarks/Remark.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CBindingWrapping.h"
+#include <optional>
 #include <string>
 
 namespace llvm {
@@ -44,7 +45,7 @@ struct Argument {
   // FIXME: We might want to be able to store other types than strings here.
   StringRef Val;
   // If set, the debug location corresponding to the value.
-  Optional<RemarkLocation> Loc;
+  std::optional<RemarkLocation> Loc;
 };
 
 // Create wrappers for C Binding types (see CBindingWrapping.h).
@@ -80,11 +81,11 @@ struct Remark {
   StringRef FunctionName;
 
   /// The location in the source file of the remark.
-  Optional<RemarkLocation> Loc;
+  std::optional<RemarkLocation> Loc;
 
   /// If profile information is available, this is the number of times the
   /// corresponding code was executed in a profile instrumentation run.
-  Optional<uint64_t> Hotness;
+  std::optional<uint64_t> Hotness;
 
   /// Arguments collected via the streaming interface.
   SmallVector<Argument, 5> Args;
@@ -112,7 +113,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Remark, LLVMRemarkEntryRef)
 /// Comparison operators for Remark objects and dependent objects.
 
 template <typename T>
-bool operator<(const Optional<T> &LHS, const Optional<T> &RHS) {
+bool operator<(const std::optional<T> &LHS, const std::optional<T> &RHS) {
   // Sorting based on optionals should result in all `None` entries to appear
   // before the valid entries. For example, remarks with no debug location will
   // appear first.

diff  --git a/llvm/include/llvm/Remarks/RemarkSerializer.h b/llvm/include/llvm/Remarks/RemarkSerializer.h
index 1ca45300b4eed..f73135f4fbd38 100644
--- a/llvm/include/llvm/Remarks/RemarkSerializer.h
+++ b/llvm/include/llvm/Remarks/RemarkSerializer.h
@@ -15,6 +15,7 @@
 
 #include "llvm/Remarks/RemarkFormat.h"
 #include "llvm/Remarks/RemarkStringTable.h"
+#include <optional>
 
 namespace llvm {
 
@@ -47,7 +48,7 @@ struct RemarkSerializer {
   SerializerMode Mode;
   /// The string table containing all the unique strings used in the output.
   /// The table can be serialized to be consumed after the compilation.
-  Optional<StringTable> StrTab;
+  std::optional<StringTable> StrTab;
 
   RemarkSerializer(Format SerializerFormat, raw_ostream &OS,
                    SerializerMode Mode)
@@ -60,7 +61,7 @@ struct RemarkSerializer {
   /// Return the corresponding metadata serializer.
   virtual std::unique_ptr<MetaSerializer>
   metaSerializer(raw_ostream &OS,
-                 Optional<StringRef> ExternalFilename = std::nullopt) = 0;
+                 std::optional<StringRef> ExternalFilename = std::nullopt) = 0;
 };
 
 /// This is the base class for a remark metadata serializer.

diff  --git a/llvm/include/llvm/Remarks/YAMLRemarkSerializer.h b/llvm/include/llvm/Remarks/YAMLRemarkSerializer.h
index 14e14a7ec6328..d2a1db5791ae0 100644
--- a/llvm/include/llvm/Remarks/YAMLRemarkSerializer.h
+++ b/llvm/include/llvm/Remarks/YAMLRemarkSerializer.h
@@ -15,6 +15,7 @@
 
 #include "llvm/Remarks/RemarkSerializer.h"
 #include "llvm/Support/YAMLTraits.h"
+#include <optional>
 
 namespace llvm {
 namespace remarks {
@@ -35,12 +36,12 @@ struct YAMLRemarkSerializer : public RemarkSerializer {
   yaml::Output YAMLOutput;
 
   YAMLRemarkSerializer(raw_ostream &OS, SerializerMode Mode,
-                       Optional<StringTable> StrTab = std::nullopt);
+                       std::optional<StringTable> StrTab = std::nullopt);
 
   void emit(const Remark &Remark) override;
-  std::unique_ptr<MetaSerializer>
-  metaSerializer(raw_ostream &OS,
-                 Optional<StringRef> ExternalFilename = std::nullopt) override;
+  std::unique_ptr<MetaSerializer> metaSerializer(
+      raw_ostream &OS,
+      std::optional<StringRef> ExternalFilename = std::nullopt) override;
 
   static bool classof(const RemarkSerializer *S) {
     return S->SerializerFormat == Format::YAML;
@@ -49,13 +50,13 @@ struct YAMLRemarkSerializer : public RemarkSerializer {
 protected:
   YAMLRemarkSerializer(Format SerializerFormat, raw_ostream &OS,
                        SerializerMode Mode,
-                       Optional<StringTable> StrTab = std::nullopt);
+                       std::optional<StringTable> StrTab = std::nullopt);
 };
 
 struct YAMLMetaSerializer : public MetaSerializer {
-  Optional<StringRef> ExternalFilename;
+  std::optional<StringRef> ExternalFilename;
 
-  YAMLMetaSerializer(raw_ostream &OS, Optional<StringRef> ExternalFilename)
+  YAMLMetaSerializer(raw_ostream &OS, std::optional<StringRef> ExternalFilename)
       : MetaSerializer(OS), ExternalFilename(ExternalFilename) {}
 
   void emit() override;
@@ -81,9 +82,9 @@ struct YAMLStrTabRemarkSerializer : public YAMLRemarkSerializer {
   /// Override to emit the metadata if necessary.
   void emit(const Remark &Remark) override;
 
-  std::unique_ptr<MetaSerializer>
-  metaSerializer(raw_ostream &OS,
-                 Optional<StringRef> ExternalFilename = std::nullopt) override;
+  std::unique_ptr<MetaSerializer> metaSerializer(
+      raw_ostream &OS,
+      std::optional<StringRef> ExternalFilename = std::nullopt) override;
 
   static bool classof(const RemarkSerializer *S) {
     return S->SerializerFormat == Format::YAMLStrTab;
@@ -95,7 +96,7 @@ struct YAMLStrTabMetaSerializer : public YAMLMetaSerializer {
   const StringTable &StrTab;
 
   YAMLStrTabMetaSerializer(raw_ostream &OS,
-                           Optional<StringRef> ExternalFilename,
+                           std::optional<StringRef> ExternalFilename,
                            const StringTable &StrTab)
       : YAMLMetaSerializer(OS, ExternalFilename), StrTab(StrTab) {}
 

diff  --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index cb0588a7203bd..4eff55f07ed7b 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -10,7 +10,6 @@
 #define LLVM_SUPPORT_YAMLTRAITS_H
 
 #include "llvm/ADT/BitVector.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -27,6 +26,7 @@
 #include <map>
 #include <memory>
 #include <new>
+#include <optional>
 #include <string>
 #include <system_error>
 #include <type_traits>
@@ -904,9 +904,10 @@ class IO {
   }
 
   template <typename T, typename Context>
-  void mapOptionalWithContext(const char *Key, Optional<T> &Val, Context &Ctx) {
-    this->processKeyWithDefault(Key, Val, Optional<T>(), /*Required=*/false,
-                                Ctx);
+  void mapOptionalWithContext(const char *Key, std::optional<T> &Val,
+                              Context &Ctx) {
+    this->processKeyWithDefault(Key, Val, std::optional<T>(),
+                                /*Required=*/false, Ctx);
   }
 
   template <typename T, typename Context>
@@ -926,9 +927,9 @@ class IO {
 
 private:
   template <typename T, typename Context>
-  void processKeyWithDefault(const char *Key, Optional<T> &Val,
-                             const Optional<T> &DefaultValue, bool Required,
-                             Context &Ctx);
+  void processKeyWithDefault(const char *Key, std::optional<T> &Val,
+                             const std::optional<T> &DefaultValue,
+                             bool Required, Context &Ctx);
 
   template <typename T, typename Context>
   void processKeyWithDefault(const char *Key, T &Val, const T &DefaultValue,
@@ -1665,10 +1666,10 @@ class Output : public IO {
 };
 
 template <typename T, typename Context>
-void IO::processKeyWithDefault(const char *Key, Optional<T> &Val,
-                               const Optional<T> &DefaultValue, bool Required,
-                               Context &Ctx) {
-  assert(!DefaultValue && "Optional<T> shouldn't have a value!");
+void IO::processKeyWithDefault(const char *Key, std::optional<T> &Val,
+                               const std::optional<T> &DefaultValue,
+                               bool Required, Context &Ctx) {
+  assert(!DefaultValue && "std::optional<T> shouldn't have a value!");
   void *SaveInfo;
   bool UseDefault = true;
   const bool sameAsDefault = outputting() && !Val;
@@ -1677,13 +1678,14 @@ void IO::processKeyWithDefault(const char *Key, Optional<T> &Val,
   if (Val &&
       this->preflightKey(Key, Required, sameAsDefault, UseDefault, SaveInfo)) {
 
-    // When reading an Optional<X> key from a YAML description, we allow the
-    // special "<none>" value, which can be used to specify that no value was
-    // requested, i.e. the DefaultValue will be assigned. The DefaultValue is
-    // usually None.
+    // When reading an std::optional<X> key from a YAML description, we allow
+    // the special "<none>" value, which can be used to specify that no value
+    // was requested, i.e. the DefaultValue will be assigned. The DefaultValue
+    // is usually None.
     bool IsNone = false;
     if (!outputting())
-      if (const auto *Node = dyn_cast<ScalarNode>(((Input *)this)->getCurrentNode()))
+      if (const auto *Node =
+              dyn_cast<ScalarNode>(((Input *)this)->getCurrentNode()))
         // We use rtrim to ignore possible white spaces that might exist when a
         // comment is present on the same line.
         IsNone = Node->getRawValue().rtrim(' ') == "<none>";

diff  --git a/llvm/lib/Analysis/BlockFrequencyInfo.cpp b/llvm/lib/Analysis/BlockFrequencyInfo.cpp
index c21c46b2f40c7..923b24e4d25b1 100644
--- a/llvm/lib/Analysis/BlockFrequencyInfo.cpp
+++ b/llvm/lib/Analysis/BlockFrequencyInfo.cpp
@@ -26,6 +26,7 @@
 #include "llvm/Support/GraphWriter.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cassert>
+#include <optional>
 #include <string>
 
 using namespace llvm;
@@ -204,7 +205,7 @@ BlockFrequency BlockFrequencyInfo::getBlockFreq(const BasicBlock *BB) const {
   return BFI ? BFI->getBlockFreq(BB) : 0;
 }
 
-Optional<uint64_t>
+std::optional<uint64_t>
 BlockFrequencyInfo::getBlockProfileCount(const BasicBlock *BB,
                                          bool AllowSynthetic) const {
   if (!BFI)
@@ -213,7 +214,7 @@ BlockFrequencyInfo::getBlockProfileCount(const BasicBlock *BB,
   return BFI->getBlockProfileCount(*getFunction(), BB, AllowSynthetic);
 }
 
-Optional<uint64_t>
+std::optional<uint64_t>
 BlockFrequencyInfo::getProfileCountFromFreq(uint64_t Freq) const {
   if (!BFI)
     return std::nullopt;

diff  --git a/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp b/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
index be4a602076b25..ab0930ff7636f 100644
--- a/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
+++ b/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
@@ -31,6 +31,7 @@
 #include <iterator>
 #include <list>
 #include <numeric>
+#include <optional>
 #include <utility>
 #include <vector>
 
@@ -585,7 +586,7 @@ BlockFrequencyInfoImplBase::getBlockFreq(const BlockNode &Node) const {
   return Freqs[Node.Index].Integer;
 }
 
-Optional<uint64_t>
+std::optional<uint64_t>
 BlockFrequencyInfoImplBase::getBlockProfileCount(const Function &F,
                                                  const BlockNode &Node,
                                                  bool AllowSynthetic) const {
@@ -593,7 +594,7 @@ BlockFrequencyInfoImplBase::getBlockProfileCount(const Function &F,
                                  AllowSynthetic);
 }
 
-Optional<uint64_t>
+std::optional<uint64_t>
 BlockFrequencyInfoImplBase::getProfileCountFromFreq(const Function &F,
                                                     uint64_t Freq,
                                                     bool AllowSynthetic) const {

diff  --git a/llvm/lib/Analysis/OptimizationRemarkEmitter.cpp b/llvm/lib/Analysis/OptimizationRemarkEmitter.cpp
index d4d13b0b22ff0..95d55ea44dbfd 100644
--- a/llvm/lib/Analysis/OptimizationRemarkEmitter.cpp
+++ b/llvm/lib/Analysis/OptimizationRemarkEmitter.cpp
@@ -20,6 +20,7 @@
 #include "llvm/IR/Dominators.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/InitializePasses.h"
+#include <optional>
 
 using namespace llvm;
 
@@ -60,7 +61,8 @@ bool OptimizationRemarkEmitter::invalidate(
   return false;
 }
 
-Optional<uint64_t> OptimizationRemarkEmitter::computeHotness(const Value *V) {
+std::optional<uint64_t>
+OptimizationRemarkEmitter::computeHotness(const Value *V) {
   if (!BFI)
     return std::nullopt;
 

diff  --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
index f48698a0e54f4..ea77b40b9a7c5 100644
--- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp
+++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
@@ -20,6 +20,7 @@
 #include "llvm/InitializePasses.h"
 #include "llvm/ProfileData/ProfileCommon.h"
 #include "llvm/Support/CommandLine.h"
+#include <optional>
 using namespace llvm;
 
 // Knobs for profile summary based thresholds.
@@ -75,7 +76,7 @@ void ProfileSummaryInfo::refresh() {
   computeThresholds();
 }
 
-Optional<uint64_t> ProfileSummaryInfo::getProfileCount(
+std::optional<uint64_t> ProfileSummaryInfo::getProfileCount(
     const CallBase &Call, BlockFrequencyInfo *BFI, bool AllowSynthetic) const {
   assert((isa<CallInst>(Call) || isa<InvokeInst>(Call)) &&
          "We can only get profile count for call/invoke instruction.");

diff  --git a/llvm/lib/CodeGen/MBFIWrapper.cpp b/llvm/lib/CodeGen/MBFIWrapper.cpp
index efebb18c99080..5b388be278394 100644
--- a/llvm/lib/CodeGen/MBFIWrapper.cpp
+++ b/llvm/lib/CodeGen/MBFIWrapper.cpp
@@ -11,9 +11,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
 #include "llvm/CodeGen/MBFIWrapper.h"
+#include <optional>
 
 using namespace llvm;
 
@@ -31,7 +31,7 @@ void MBFIWrapper::setBlockFreq(const MachineBasicBlock *MBB,
   MergedBBFreq[MBB] = F;
 }
 
-Optional<uint64_t>
+std::optional<uint64_t>
 MBFIWrapper::getBlockProfileCount(const MachineBasicBlock *MBB) const {
   auto I = MergedBBFreq.find(MBB);
 

diff  --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
index afe0786bc1ec4..86dd3e92e2304 100644
--- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
+++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
@@ -23,6 +23,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/GraphWriter.h"
+#include <optional>
 #include <string>
 
 using namespace llvm;
@@ -231,7 +232,7 @@ MachineBlockFrequencyInfo::getBlockFreq(const MachineBasicBlock *MBB) const {
   return MBFI ? MBFI->getBlockFreq(MBB) : 0;
 }
 
-Optional<uint64_t> MachineBlockFrequencyInfo::getBlockProfileCount(
+std::optional<uint64_t> MachineBlockFrequencyInfo::getBlockProfileCount(
     const MachineBasicBlock *MBB) const {
   if (!MBFI)
     return std::nullopt;
@@ -240,7 +241,7 @@ Optional<uint64_t> MachineBlockFrequencyInfo::getBlockProfileCount(
   return MBFI->getBlockProfileCount(F, MBB);
 }
 
-Optional<uint64_t>
+std::optional<uint64_t>
 MachineBlockFrequencyInfo::getProfileCountFromFreq(uint64_t Freq) const {
   if (!MBFI)
     return std::nullopt;

diff  --git a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp
index 29caf7204c426..5d8139b3ee641 100644
--- a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp
+++ b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp
@@ -35,6 +35,7 @@
 #include "llvm/IR/Function.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Support/CommandLine.h"
+#include <optional>
 
 using namespace llvm;
 
@@ -157,7 +158,7 @@ setDescendantEHBlocksCold(SmallVectorImpl<MachineBasicBlock *> &EHBlocks,
 static bool isColdBlock(const MachineBasicBlock &MBB,
                         const MachineBlockFrequencyInfo *MBFI,
                         ProfileSummaryInfo *PSI) {
-  Optional<uint64_t> Count = MBFI->getBlockProfileCount(&MBB);
+  std::optional<uint64_t> Count = MBFI->getBlockProfileCount(&MBB);
   if (!Count)
     return true;
 

diff  --git a/llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp b/llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp
index 4dda1c4fbf529..1c31eba909e78 100644
--- a/llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp
+++ b/llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp
@@ -18,6 +18,7 @@
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/InitializePasses.h"
+#include <optional>
 
 using namespace llvm;
 
@@ -30,7 +31,7 @@ DiagnosticInfoMIROptimization::MachineArgument::MachineArgument(
            /*SkipDebugLoc=*/true);
 }
 
-Optional<uint64_t>
+std::optional<uint64_t>
 MachineOptimizationRemarkEmitter::computeHotness(const MachineBasicBlock &MBB) {
   if (!MBFI)
     return std::nullopt;

diff  --git a/llvm/lib/IR/LLVMRemarkStreamer.cpp b/llvm/lib/IR/LLVMRemarkStreamer.cpp
index 023894d09495b..8fbc33328de82 100644
--- a/llvm/lib/IR/LLVMRemarkStreamer.cpp
+++ b/llvm/lib/IR/LLVMRemarkStreamer.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Remarks/RemarkStreamer.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include <optional>
 
 using namespace llvm;
 
@@ -45,7 +46,7 @@ static remarks::Type toRemarkType(enum DiagnosticKind Kind) {
 }
 
 /// DiagnosticLocation -> remarks::RemarkLocation.
-static Optional<remarks::RemarkLocation>
+static std::optional<remarks::RemarkLocation>
 toRemarkLocation(const DiagnosticLocation &DL) {
   if (!DL.isValid())
     return std::nullopt;

diff  --git a/llvm/lib/InterfaceStub/IFSHandler.cpp b/llvm/lib/InterfaceStub/IFSHandler.cpp
index 4edaeb74d6a7a..c8e9c11bc3a66 100644
--- a/llvm/lib/InterfaceStub/IFSHandler.cpp
+++ b/llvm/lib/InterfaceStub/IFSHandler.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Support/LineIterator.h"
 #include "llvm/Support/YAMLTraits.h"
 #include <functional>
+#include <optional>
 
 using namespace llvm;
 using namespace llvm::ifs;
@@ -216,10 +217,11 @@ Error ifs::writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub) {
   return Error::success();
 }
 
-Error ifs::overrideIFSTarget(IFSStub &Stub, Optional<IFSArch> OverrideArch,
-                             Optional<IFSEndiannessType> OverrideEndianness,
-                             Optional<IFSBitWidthType> OverrideBitWidth,
-                             Optional<std::string> OverrideTriple) {
+Error ifs::overrideIFSTarget(
+    IFSStub &Stub, std::optional<IFSArch> OverrideArch,
+    std::optional<IFSEndiannessType> OverrideEndianness,
+    std::optional<IFSBitWidthType> OverrideBitWidth,
+    std::optional<std::string> OverrideTriple) {
   std::error_code OverrideEC(1, std::generic_category());
   if (OverrideArch) {
     if (Stub.Target.Arch && Stub.Target.Arch.value() != OverrideArch.value()) {

diff  --git a/llvm/lib/ObjectYAML/COFFEmitter.cpp b/llvm/lib/ObjectYAML/COFFEmitter.cpp
index f6e716b5a8751..a57da9b3287d4 100644
--- a/llvm/lib/ObjectYAML/COFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/COFFEmitter.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 #include <vector>
 
 using namespace llvm;
@@ -454,7 +455,7 @@ static bool writeCOFF(COFFParser &CP, raw_ostream &OS) {
     }
     for (uint32_t I = 0; I < CP.Obj.OptionalHeader->Header.NumberOfRvaAndSize;
          ++I) {
-      const Optional<COFF::DataDirectory> *DataDirectories =
+      const std::optional<COFF::DataDirectory> *DataDirectories =
           CP.Obj.OptionalHeader->DataDirectories;
       uint32_t NumDataDir = std::size(CP.Obj.OptionalHeader->DataDirectories);
       if (I >= NumDataDir || !DataDirectories[I]) {

diff  --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index c0e2cdd54f07a..f25c016e9aa35 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -33,6 +33,7 @@
 #include <cstddef>
 #include <cstdint>
 #include <memory>
+#include <optional>
 #include <string>
 #include <vector>
 
@@ -552,7 +553,7 @@ static void writeLineTableOpcode(const DWARFYAML::LineTableOpcode &Op,
 }
 
 static std::vector<uint8_t>
-getStandardOpcodeLengths(uint16_t Version, Optional<uint8_t> OpcodeBase) {
+getStandardOpcodeLengths(uint16_t Version, std::optional<uint8_t> OpcodeBase) {
   // If the opcode_base field isn't specified, we returns the
   // standard_opcode_lengths array according to the version by default.
   std::vector<uint8_t> StandardOpcodeLengths{0, 1, 1, 1, 1, 0,

diff  --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 88d430f893125..53fee6af0c14d 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -31,6 +31,7 @@
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 
 using namespace llvm;
 
@@ -314,7 +315,7 @@ template <class ELFT> class ELFState {
 
   BumpPtrAllocator StringAlloc;
   uint64_t alignToOffset(ContiguousBlobAccumulator &CBA, uint64_t Align,
-                         llvm::Optional<llvm::yaml::Hex64> Offset);
+                         std::optional<llvm::yaml::Hex64> Offset);
 
   uint64_t getSectionNameOffset(StringRef Name);
 
@@ -715,8 +716,8 @@ uint64_t ELFState<ELFT>::getSectionNameOffset(StringRef Name) {
 }
 
 static uint64_t writeContent(ContiguousBlobAccumulator &CBA,
-                             const Optional<yaml::BinaryRef> &Content,
-                             const Optional<llvm::yaml::Hex64> &Size) {
+                             const std::optional<yaml::BinaryRef> &Content,
+                             const std::optional<llvm::yaml::Hex64> &Size) {
   size_t ContentSize = 0;
   if (Content) {
     CBA.writeAsBinary(*Content);
@@ -1453,7 +1454,7 @@ void ELFState<ELFT>::writeSectionContent(
 template <class ELFT>
 uint64_t
 ELFState<ELFT>::alignToOffset(ContiguousBlobAccumulator &CBA, uint64_t Align,
-                              llvm::Optional<llvm::yaml::Hex64> Offset) {
+                              std::optional<llvm::yaml::Hex64> Offset) {
   uint64_t CurrentOffset = CBA.getOffset();
   uint64_t AlignedOffset;
 

diff  --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 504a6837a1a17..5513ce460dbc3 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -23,6 +23,7 @@
 #include "llvm/Support/WithColor.h"
 #include <cassert>
 #include <cstdint>
+#include <optional>
 
 namespace llvm {
 
@@ -1160,7 +1161,7 @@ namespace {
 
 struct NormalizedOther {
   NormalizedOther(IO &IO) : YamlIO(IO) {}
-  NormalizedOther(IO &IO, Optional<uint8_t> Original) : YamlIO(IO) {
+  NormalizedOther(IO &IO, std::optional<uint8_t> Original) : YamlIO(IO) {
     assert(Original && "This constructor is only used for outputting YAML and "
                        "assumes a non-empty Original");
     std::vector<StOtherPiece> Ret;
@@ -1200,7 +1201,7 @@ struct NormalizedOther {
     return 0;
   }
 
-  Optional<uint8_t> denormalize(IO &) {
+  std::optional<uint8_t> denormalize(IO &) {
     if (!Other)
       return std::nullopt;
     uint8_t Ret = 0;
@@ -1248,7 +1249,7 @@ struct NormalizedOther {
   }
 
   IO &YamlIO;
-  Optional<std::vector<StOtherPiece>> Other;
+  std::optional<std::vector<StOtherPiece>> Other;
   std::string UnknownFlagsHolder;
 };
 
@@ -1298,11 +1299,11 @@ void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
 
   // Symbol's Other field is a bit special. It is usually a field that
   // represents st_other and holds the symbol visibility. However, on some
-  // platforms, it can contain bit fields and regular values, or even sometimes a
-  // crazy mix of them (see comments for NormalizedOther). Because of this, we
+  // platforms, it can contain bit fields and regular values, or even sometimes
+  // a crazy mix of them (see comments for NormalizedOther). Because of this, we
   // need special handling.
-  MappingNormalization<NormalizedOther, Optional<uint8_t>> Keys(IO,
-                                                                Symbol.Other);
+  MappingNormalization<NormalizedOther, std::optional<uint8_t>> Keys(
+      IO, Symbol.Other);
   IO.mapOptional("Other", Keys->Other);
 }
 

diff  --git a/llvm/lib/ProfileData/InstrProfCorrelator.cpp b/llvm/lib/ProfileData/InstrProfCorrelator.cpp
index 38ae5d8f821c0..a727ff7cf6ef3 100644
--- a/llvm/lib/ProfileData/InstrProfCorrelator.cpp
+++ b/llvm/lib/ProfileData/InstrProfCorrelator.cpp
@@ -16,6 +16,7 @@
 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
 #include "llvm/Object/MachO.h"
 #include "llvm/Support/Debug.h"
+#include <optional>
 
 #define DEBUG_TYPE "correlator"
 

diff  --git a/llvm/lib/Remarks/BitstreamRemarkSerializer.cpp b/llvm/lib/Remarks/BitstreamRemarkSerializer.cpp
index 91aaef11dffe3..542896765d824 100644
--- a/llvm/lib/Remarks/BitstreamRemarkSerializer.cpp
+++ b/llvm/lib/Remarks/BitstreamRemarkSerializer.cpp
@@ -13,6 +13,7 @@
 
 #include "llvm/Remarks/BitstreamRemarkSerializer.h"
 #include "llvm/Remarks/Remark.h"
+#include <optional>
 
 using namespace llvm;
 using namespace llvm::remarks;
@@ -232,7 +233,7 @@ void BitstreamRemarkSerializerHelper::setupBlockInfo() {
 
 void BitstreamRemarkSerializerHelper::emitMetaBlock(
     uint64_t ContainerVersion, Optional<uint64_t> RemarkVersion,
-    Optional<const StringTable *> StrTab, Optional<StringRef> Filename) {
+    Optional<const StringTable *> StrTab, std::optional<StringRef> Filename) {
   // Emit the meta block
   Bitstream.EnterSubblock(META_BLOCK_ID, 3);
 
@@ -277,7 +278,7 @@ void BitstreamRemarkSerializerHelper::emitRemarkBlock(const Remark &Remark,
   R.push_back(StrTab.add(Remark.FunctionName).first);
   Bitstream.EmitRecordWithAbbrev(RecordRemarkHeaderAbbrevID, R);
 
-  if (const Optional<RemarkLocation> &Loc = Remark.Loc) {
+  if (const std::optional<RemarkLocation> &Loc = Remark.Loc) {
     R.clear();
     R.push_back(RECORD_REMARK_DEBUG_LOC);
     R.push_back(StrTab.add(Loc->SourceFilePath).first);
@@ -286,7 +287,7 @@ void BitstreamRemarkSerializerHelper::emitRemarkBlock(const Remark &Remark,
     Bitstream.EmitRecordWithAbbrev(RecordRemarkDebugLocAbbrevID, R);
   }
 
-  if (Optional<uint64_t> Hotness = Remark.Hotness) {
+  if (std::optional<uint64_t> Hotness = Remark.Hotness) {
     R.clear();
     R.push_back(RECORD_REMARK_HOTNESS);
     R.push_back(*Hotness);
@@ -366,7 +367,7 @@ void BitstreamRemarkSerializer::emit(const Remark &Remark) {
 }
 
 std::unique_ptr<MetaSerializer> BitstreamRemarkSerializer::metaSerializer(
-    raw_ostream &OS, Optional<StringRef> ExternalFilename) {
+    raw_ostream &OS, std::optional<StringRef> ExternalFilename) {
   assert(Helper.ContainerType !=
          BitstreamRemarkContainerType::SeparateRemarksMeta);
   bool IsStandalone =

diff  --git a/llvm/lib/Remarks/Remark.cpp b/llvm/lib/Remarks/Remark.cpp
index e6b7de1a2cf52..a038f81874d1f 100644
--- a/llvm/lib/Remarks/Remark.cpp
+++ b/llvm/lib/Remarks/Remark.cpp
@@ -13,6 +13,7 @@
 #include "llvm/Remarks/Remark.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 
 using namespace llvm;
 using namespace llvm::remarks;
@@ -60,7 +61,7 @@ extern "C" LLVMRemarkStringRef LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg) {
 
 extern "C" LLVMRemarkDebugLocRef
 LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg) {
-  if (const Optional<RemarkLocation> &Loc = unwrap(Arg)->Loc)
+  if (const std::optional<RemarkLocation> &Loc = unwrap(Arg)->Loc)
     return wrap(&*Loc);
   return nullptr;
 }
@@ -91,13 +92,13 @@ LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark) {
 
 extern "C" LLVMRemarkDebugLocRef
 LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark) {
-  if (const Optional<RemarkLocation> &Loc = unwrap(Remark)->Loc)
+  if (const std::optional<RemarkLocation> &Loc = unwrap(Remark)->Loc)
     return wrap(&*Loc);
   return nullptr;
 }
 
 extern "C" uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark) {
-  if (const Optional<uint64_t> &Hotness = unwrap(Remark)->Hotness)
+  if (const std::optional<uint64_t> &Hotness = unwrap(Remark)->Hotness)
     return *Hotness;
   return 0;
 }

diff  --git a/llvm/lib/Remarks/YAMLRemarkParser.cpp b/llvm/lib/Remarks/YAMLRemarkParser.cpp
index 6372e541104c5..265371c0839aa 100644
--- a/llvm/lib/Remarks/YAMLRemarkParser.cpp
+++ b/llvm/lib/Remarks/YAMLRemarkParser.cpp
@@ -367,7 +367,7 @@ Expected<Argument> YAMLRemarkParser::parseArg(yaml::Node &Node) {
 
   std::optional<StringRef> KeyStr;
   std::optional<StringRef> ValueStr;
-  Optional<RemarkLocation> Loc;
+  std::optional<RemarkLocation> Loc;
 
   for (yaml::KeyValueNode &ArgEntry : *ArgMap) {
     Expected<StringRef> MaybeKey = parseKey(ArgEntry);

diff  --git a/llvm/lib/Remarks/YAMLRemarkSerializer.cpp b/llvm/lib/Remarks/YAMLRemarkSerializer.cpp
index 513c7efeb4421..68285c3dde1bf 100644
--- a/llvm/lib/Remarks/YAMLRemarkSerializer.cpp
+++ b/llvm/lib/Remarks/YAMLRemarkSerializer.cpp
@@ -23,8 +23,8 @@ using namespace llvm::remarks;
 // unsigned or a StringRef).
 template <typename T>
 static void mapRemarkHeader(yaml::IO &io, T PassName, T RemarkName,
-                            Optional<RemarkLocation> RL, T FunctionName,
-                            Optional<uint64_t> Hotness,
+                            std::optional<RemarkLocation> RL, T FunctionName,
+                            std::optional<uint64_t> Hotness,
                             ArrayRef<Argument> Args) {
   io.mapRequired("Pass", PassName);
   io.mapRequired("Name", RemarkName);
@@ -158,12 +158,12 @@ template <> struct MappingTraits<Argument> {
 LLVM_YAML_IS_SEQUENCE_VECTOR(Argument)
 
 YAMLRemarkSerializer::YAMLRemarkSerializer(raw_ostream &OS, SerializerMode Mode,
-                                           Optional<StringTable> StrTabIn)
+                                           std::optional<StringTable> StrTabIn)
     : YAMLRemarkSerializer(Format::YAML, OS, Mode, std::move(StrTabIn)) {}
 
 YAMLRemarkSerializer::YAMLRemarkSerializer(Format SerializerFormat,
                                            raw_ostream &OS, SerializerMode Mode,
-                                           Optional<StringTable> StrTabIn)
+                                           std::optional<StringTable> StrTabIn)
     : RemarkSerializer(SerializerFormat, OS, Mode),
       YAMLOutput(OS, reinterpret_cast<void *>(this)) {
   StrTab = std::move(StrTabIn);
@@ -176,9 +176,8 @@ void YAMLRemarkSerializer::emit(const Remark &Remark) {
   YAMLOutput << R;
 }
 
-std::unique_ptr<MetaSerializer>
-YAMLRemarkSerializer::metaSerializer(raw_ostream &OS,
-                                     Optional<StringRef> ExternalFilename) {
+std::unique_ptr<MetaSerializer> YAMLRemarkSerializer::metaSerializer(
+    raw_ostream &OS, std::optional<StringRef> ExternalFilename) {
   return std::make_unique<YAMLMetaSerializer>(OS, ExternalFilename);
 }
 
@@ -197,7 +196,7 @@ void YAMLStrTabRemarkSerializer::emit(const Remark &Remark) {
 }
 
 std::unique_ptr<MetaSerializer> YAMLStrTabRemarkSerializer::metaSerializer(
-    raw_ostream &OS, Optional<StringRef> ExternalFilename) {
+    raw_ostream &OS, std::optional<StringRef> ExternalFilename) {
   assert(StrTab);
   return std::make_unique<YAMLStrTabMetaSerializer>(OS, ExternalFilename,
                                                     *StrTab);

diff  --git a/llvm/lib/Support/AMDGPUMetadata.cpp b/llvm/lib/Support/AMDGPUMetadata.cpp
index 3d6325134d75f..e24cbde38795b 100644
--- a/llvm/lib/Support/AMDGPUMetadata.cpp
+++ b/llvm/lib/Support/AMDGPUMetadata.cpp
@@ -14,6 +14,7 @@
 
 #include "llvm/Support/AMDGPUMetadata.h"
 #include "llvm/Support/YAMLTraits.h"
+#include <optional>
 
 using namespace llvm::AMDGPU;
 using namespace llvm::AMDGPU::HSAMD;
@@ -112,7 +113,7 @@ struct MappingTraits<Kernel::Arg::Metadata> {
     YIO.mapRequired(Kernel::Arg::Key::ValueKind, MD.mValueKind);
 
     // Removed. Accepted for parsing compatibility, but not emitted.
-    Optional<ValueType> Unused;
+    std::optional<ValueType> Unused;
     YIO.mapOptional(Kernel::Arg::Key::ValueType, Unused);
 
     YIO.mapOptional(Kernel::Arg::Key::PointeeAlign, MD.mPointeeAlign,

diff  --git a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
index fad00e13d31c6..164c9576b9440 100644
--- a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
+++ b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
@@ -23,6 +23,7 @@
 #include "llvm/IR/Function.h"
 #include "llvm/MC/MCLinkerOptimizationHint.h"
 #include <cassert>
+#include <optional>
 
 namespace llvm {
 
@@ -132,7 +133,7 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
   /// redzone, and no value otherwise.
   /// Initialized during frame lowering, unless the function has the noredzone
   /// attribute, in which case it is set to false at construction.
-  Optional<bool> HasRedZone;
+  std::optional<bool> HasRedZone;
 
   /// ForwardedMustTailRegParms - A list of virtual and physical registers
   /// that must be forwarded to every musttail call.
@@ -334,7 +335,7 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
     return NumLocalDynamicTLSAccesses;
   }
 
-  Optional<bool> hasRedZone() const { return HasRedZone; }
+  std::optional<bool> hasRedZone() const { return HasRedZone; }
   void setHasRedZone(bool s) { HasRedZone = s; }
 
   int getVarArgsStackIndex() const { return VarArgsStackIndex; }
@@ -458,7 +459,7 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
 
 namespace yaml {
 struct AArch64FunctionInfo final : public yaml::MachineFunctionInfo {
-  Optional<bool> HasRedZone;
+  std::optional<bool> HasRedZone;
 
   AArch64FunctionInfo() = default;
   AArch64FunctionInfo(const llvm::AArch64FunctionInfo &MFI);

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 7a9d37c1bbb8e..6a57078a055b8 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -1485,7 +1485,7 @@ bool GCNTargetMachine::parseMachineFunctionInfo(
     MFI->reserveWWMRegister(ParsedReg);
   }
 
-  auto parseAndCheckArgument = [&](const Optional<yaml::SIArgument> &A,
+  auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
                                    const TargetRegisterClass &RC,
                                    ArgDescriptor &Arg, unsigned UserSGPRs,
                                    unsigned SystemSGPRs) {

diff  --git a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
index 7f76da65aacf3..26a62317a5e5e 100644
--- a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
@@ -22,6 +22,7 @@
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/Function.h"
 #include <cassert>
+#include <optional>
 #include <vector>
 
 #define MAX_LANES 64
@@ -537,12 +538,12 @@ static yaml::StringValue regToString(Register Reg,
   return Dest;
 }
 
-static Optional<yaml::SIArgumentInfo>
+static std::optional<yaml::SIArgumentInfo>
 convertArgumentInfo(const AMDGPUFunctionArgInfo &ArgInfo,
                     const TargetRegisterInfo &TRI) {
   yaml::SIArgumentInfo AI;
 
-  auto convertArg = [&](Optional<yaml::SIArgument> &A,
+  auto convertArg = [&](std::optional<yaml::SIArgument> &A,
                         const ArgDescriptor &Arg) {
     if (!Arg)
       return false;

diff  --git a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
index 9ad440b0aad43..70a6009e4f5d8 100644
--- a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
@@ -22,6 +22,7 @@
 #include "llvm/CodeGen/MIRYamlMapping.h"
 #include "llvm/CodeGen/PseudoSourceValue.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 
 namespace llvm {
 
@@ -90,7 +91,7 @@ struct SIArgument {
     StringValue RegisterName;
     unsigned StackOffset;
   };
-  Optional<unsigned> Mask;
+  std::optional<unsigned> Mask;
 
   // Default constructor, which creates a stack argument.
   SIArgument() : IsRegister(false), StackOffset(0) {}
@@ -153,27 +154,27 @@ template <> struct MappingTraits<SIArgument> {
 };
 
 struct SIArgumentInfo {
-  Optional<SIArgument> PrivateSegmentBuffer;
-  Optional<SIArgument> DispatchPtr;
-  Optional<SIArgument> QueuePtr;
-  Optional<SIArgument> KernargSegmentPtr;
-  Optional<SIArgument> DispatchID;
-  Optional<SIArgument> FlatScratchInit;
-  Optional<SIArgument> PrivateSegmentSize;
-
-  Optional<SIArgument> WorkGroupIDX;
-  Optional<SIArgument> WorkGroupIDY;
-  Optional<SIArgument> WorkGroupIDZ;
-  Optional<SIArgument> WorkGroupInfo;
-  Optional<SIArgument> LDSKernelId;
-  Optional<SIArgument> PrivateSegmentWaveByteOffset;
-
-  Optional<SIArgument> ImplicitArgPtr;
-  Optional<SIArgument> ImplicitBufferPtr;
-
-  Optional<SIArgument> WorkItemIDX;
-  Optional<SIArgument> WorkItemIDY;
-  Optional<SIArgument> WorkItemIDZ;
+  std::optional<SIArgument> PrivateSegmentBuffer;
+  std::optional<SIArgument> DispatchPtr;
+  std::optional<SIArgument> QueuePtr;
+  std::optional<SIArgument> KernargSegmentPtr;
+  std::optional<SIArgument> DispatchID;
+  std::optional<SIArgument> FlatScratchInit;
+  std::optional<SIArgument> PrivateSegmentSize;
+
+  std::optional<SIArgument> WorkGroupIDX;
+  std::optional<SIArgument> WorkGroupIDY;
+  std::optional<SIArgument> WorkGroupIDZ;
+  std::optional<SIArgument> WorkGroupInfo;
+  std::optional<SIArgument> LDSKernelId;
+  std::optional<SIArgument> PrivateSegmentWaveByteOffset;
+
+  std::optional<SIArgument> ImplicitArgPtr;
+  std::optional<SIArgument> ImplicitBufferPtr;
+
+  std::optional<SIArgument> WorkItemIDX;
+  std::optional<SIArgument> WorkItemIDY;
+  std::optional<SIArgument> WorkItemIDZ;
 };
 
 template <> struct MappingTraits<SIArgumentInfo> {
@@ -270,9 +271,9 @@ struct SIMachineFunctionInfo final : public yaml::MachineFunctionInfo {
   unsigned BytesInStackArgArea = 0;
   bool ReturnsVoid = true;
 
-  Optional<SIArgumentInfo> ArgInfo;
+  std::optional<SIArgumentInfo> ArgInfo;
   SIMode Mode;
-  Optional<FrameIndex> ScavengeFI;
+  std::optional<FrameIndex> ScavengeFI;
   StringValue VGPRForAGPRCopy;
 
   SIMachineFunctionInfo() = default;

diff  --git a/llvm/lib/Transforms/Instrumentation/CGProfile.cpp b/llvm/lib/Transforms/Instrumentation/CGProfile.cpp
index 27107f46ed921..1c630e9ee424d 100644
--- a/llvm/lib/Transforms/Instrumentation/CGProfile.cpp
+++ b/llvm/lib/Transforms/Instrumentation/CGProfile.cpp
@@ -18,6 +18,7 @@
 #include "llvm/InitializePasses.h"
 #include "llvm/ProfileData/InstrProf.h"
 #include "llvm/Transforms/Instrumentation.h"
+#include <optional>
 
 using namespace llvm;
 
@@ -73,7 +74,7 @@ static bool runCGProfilePass(
       continue;
     TargetTransformInfo &TTI = GetTTI(F);
     for (auto &BB : F) {
-      Optional<uint64_t> BBCount = BFI.getBlockProfileCount(&BB);
+      std::optional<uint64_t> BBCount = BFI.getBlockProfileCount(&BB);
       if (!BBCount)
         continue;
       for (auto &I : BB) {

diff  --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
index 4d4674b859fef..451a0f3de7be1 100644
--- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
@@ -38,6 +38,7 @@
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/ValueMapper.h"
 
+#include <optional>
 #include <set>
 #include <sstream>
 
@@ -1707,7 +1708,7 @@ void CHR::transformScopes(CHRScope *Scope, DenseSet<PHINode *> &TrivialPHIs) {
   BasicBlock *EntryBlock = FirstRegion->getEntry();
   Region *LastRegion = Scope->RegInfos[Scope->RegInfos.size() - 1].R;
   BasicBlock *ExitBlock = LastRegion->getExit();
-  Optional<uint64_t> ProfileCount = BFI.getBlockProfileCount(EntryBlock);
+  std::optional<uint64_t> ProfileCount = BFI.getBlockProfileCount(EntryBlock);
 
   if (ExitBlock) {
     // Insert a trivial phi at the exit block (where the CHR hot path and the

diff  --git a/llvm/tools/dsymutil/DebugMap.cpp b/llvm/tools/dsymutil/DebugMap.cpp
index 79b6cb2c80a21..2464cd879bddb 100644
--- a/llvm/tools/dsymutil/DebugMap.cpp
+++ b/llvm/tools/dsymutil/DebugMap.cpp
@@ -28,6 +28,7 @@
 #include <cinttypes>
 #include <cstdint>
 #include <memory>
+#include <optional>
 #include <string>
 #include <utility>
 #include <vector>
@@ -43,7 +44,8 @@ DebugMapObject::DebugMapObject(StringRef ObjectFilename,
                                uint8_t Type)
     : Filename(std::string(ObjectFilename)), Timestamp(Timestamp), Type(Type) {}
 
-bool DebugMapObject::addSymbol(StringRef Name, Optional<uint64_t> ObjectAddress,
+bool DebugMapObject::addSymbol(StringRef Name,
+                               std::optional<uint64_t> ObjectAddress,
                                uint64_t LinkedAddress, uint32_t Size) {
   auto InsertResult = Symbols.insert(
       std::make_pair(Name, SymbolMapping(ObjectAddress, LinkedAddress, Size)));
@@ -277,7 +279,7 @@ MappingTraits<dsymutil::DebugMapObject>::YamlDMO::denormalize(IO &IO) {
   dsymutil::DebugMapObject Res(Path, sys::toTimePoint(Timestamp), MachO::N_OSO);
   for (auto &Entry : Entries) {
     auto &Mapping = Entry.second;
-    Optional<uint64_t> ObjAddress;
+    std::optional<uint64_t> ObjAddress;
     if (Mapping.ObjectAddress)
       ObjAddress = *Mapping.ObjectAddress;
     auto AddressIt = SymbolAddresses.find(Entry.first);

diff  --git a/llvm/tools/dsymutil/DebugMap.h b/llvm/tools/dsymutil/DebugMap.h
index e4fbaa81174bf..4854f41beb545 100644
--- a/llvm/tools/dsymutil/DebugMap.h
+++ b/llvm/tools/dsymutil/DebugMap.h
@@ -22,7 +22,6 @@
 #define LLVM_TOOLS_DSYMUTIL_DEBUGMAP_H
 
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
@@ -35,6 +34,7 @@
 #include <cstddef>
 #include <cstdint>
 #include <memory>
+#include <optional>
 #include <string>
 #include <utility>
 #include <vector>
@@ -135,11 +135,11 @@ class DebugMap {
 class DebugMapObject {
 public:
   struct SymbolMapping {
-    Optional<yaml::Hex64> ObjectAddress;
+    std::optional<yaml::Hex64> ObjectAddress;
     yaml::Hex64 BinaryAddress;
     yaml::Hex32 Size;
 
-    SymbolMapping(Optional<uint64_t> ObjectAddr, uint64_t BinaryAddress,
+    SymbolMapping(std::optional<uint64_t> ObjectAddr, uint64_t BinaryAddress,
                   uint32_t Size)
         : BinaryAddress(BinaryAddress), Size(Size) {
       if (ObjectAddr)
@@ -156,7 +156,7 @@ class DebugMapObject {
   /// Adds a symbol mapping to this DebugMapObject.
   /// \returns false if the symbol was already registered. The request
   /// is discarded in this case.
-  bool addSymbol(StringRef SymName, Optional<uint64_t> ObjectAddress,
+  bool addSymbol(StringRef SymName, std::optional<uint64_t> ObjectAddress,
                  uint64_t LinkedAddress, uint32_t Size);
 
   /// Lookup a symbol mapping.

diff  --git a/llvm/tools/dsymutil/MachODebugMapParser.cpp b/llvm/tools/dsymutil/MachODebugMapParser.cpp
index 26aeb39023487..2f391c54e8ca8 100644
--- a/llvm/tools/dsymutil/MachODebugMapParser.cpp
+++ b/llvm/tools/dsymutil/MachODebugMapParser.cpp
@@ -9,12 +9,12 @@
 #include "BinaryHolder.h"
 #include "DebugMap.h"
 #include "MachOUtils.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Object/MachO.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 #include <vector>
 
 namespace {
@@ -59,10 +59,10 @@ class MachODebugMapParser {
   std::vector<std::string> CommonSymbols;
 
   /// Map of the currently processed object file symbol addresses.
-  StringMap<Optional<uint64_t>> CurrentObjectAddresses;
+  StringMap<std::optional<uint64_t>> CurrentObjectAddresses;
 
   /// Lazily computed map of symbols aliased to the processed object file.
-  StringMap<Optional<uint64_t>> CurrentObjectAliasMap;
+  StringMap<std::optional<uint64_t>> CurrentObjectAliasMap;
 
   /// If CurrentObjectAliasMap has been computed for a given address.
   SmallSet<uint64_t, 4> SeenAliasValues;

diff  --git a/llvm/tools/llvm-ifs/llvm-ifs.cpp b/llvm/tools/llvm-ifs/llvm-ifs.cpp
index d704422163241..89b495b102274 100644
--- a/llvm/tools/llvm-ifs/llvm-ifs.cpp
+++ b/llvm/tools/llvm-ifs/llvm-ifs.cpp
@@ -84,14 +84,14 @@ class IFSOptTable : public opt::OptTable {
 struct DriverConfig {
   std::vector<std::string> InputFilePaths;
 
-  Optional<FileFormat> InputFormat;
-  Optional<FileFormat> OutputFormat;
+  std::optional<FileFormat> InputFormat;
+  std::optional<FileFormat> OutputFormat;
 
   std::optional<std::string> HintIfsTarget;
-  Optional<std::string> OptTargetTriple;
-  Optional<IFSArch> OverrideArch;
-  Optional<IFSBitWidthType> OverrideBitWidth;
-  Optional<IFSEndiannessType> OverrideEndianness;
+  std::optional<std::string> OptTargetTriple;
+  std::optional<IFSArch> OverrideArch;
+  std::optional<IFSBitWidthType> OverrideBitWidth;
+  std::optional<IFSEndiannessType> OverrideEndianness;
 
   bool StripIfsArch = false;
   bool StripIfsBitwidth = false;
@@ -130,7 +130,7 @@ static std::string getTypeName(IFSSymbolType Type) {
 }
 
 static Expected<std::unique_ptr<IFSStub>>
-readInputFile(Optional<FileFormat> &InputFormat, StringRef FilePath) {
+readInputFile(std::optional<FileFormat> &InputFormat, StringRef FilePath) {
   // Read in file.
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrError =
       MemoryBuffer::getFileOrSTDIN(FilePath, /*IsText=*/true);
@@ -306,7 +306,7 @@ static DriverConfig parseArgs(int argc, char *const *argv) {
   for (const opt::Arg *A : Args.filtered(OPT_INPUT))
     Config.InputFilePaths.push_back(A->getValue());
   if (const opt::Arg *A = Args.getLastArg(OPT_input_format_EQ)) {
-    Config.InputFormat = StringSwitch<Optional<FileFormat>>(A->getValue())
+    Config.InputFormat = StringSwitch<std::optional<FileFormat>>(A->getValue())
                              .Case("IFS", FileFormat::IFS)
                              .Case("ELF", FileFormat::ELF)
                              .Default(std::nullopt);
@@ -319,7 +319,7 @@ static DriverConfig parseArgs(int argc, char *const *argv) {
                " option: Cannot find option named '" + OptionName + "'!");
   };
   if (const opt::Arg *A = Args.getLastArg(OPT_output_format_EQ)) {
-    Config.OutputFormat = StringSwitch<Optional<FileFormat>>(A->getValue())
+    Config.OutputFormat = StringSwitch<std::optional<FileFormat>>(A->getValue())
                               .Case("IFS", FileFormat::IFS)
                               .Case("ELF", FileFormat::ELF)
                               .Case("TBD", FileFormat::TBD)
@@ -341,7 +341,7 @@ static DriverConfig parseArgs(int argc, char *const *argv) {
   }
   if (const opt::Arg *A = Args.getLastArg(OPT_endianness_EQ)) {
     Config.OverrideEndianness =
-        StringSwitch<Optional<IFSEndiannessType>>(A->getValue())
+        StringSwitch<std::optional<IFSEndiannessType>>(A->getValue())
             .Case("little", IFSEndiannessType::Little)
             .Case("big", IFSEndiannessType::Big)
             .Default(std::nullopt);

diff  --git a/llvm/tools/llvm-opt-report/OptReport.cpp b/llvm/tools/llvm-opt-report/OptReport.cpp
index e0388632ba554..cc7e60ba13783 100644
--- a/llvm/tools/llvm-opt-report/OptReport.cpp
+++ b/llvm/tools/llvm-opt-report/OptReport.cpp
@@ -32,6 +32,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include <cstdlib>
 #include <map>
+#include <optional>
 #include <set>
 
 using namespace llvm;
@@ -208,7 +209,7 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) {
         Arg.Val.getAsInteger(10, UnrollCount);
     }
 
-    const Optional<remarks::RemarkLocation> &Loc = Remark.Loc;
+    const std::optional<remarks::RemarkLocation> &Loc = Remark.Loc;
     if (!Loc)
       continue;
 

diff  --git a/llvm/tools/llvm-pdbutil/PdbYaml.h b/llvm/tools/llvm-pdbutil/PdbYaml.h
index c335eef2f1c5e..4382e91e20973 100644
--- a/llvm/tools/llvm-pdbutil/PdbYaml.h
+++ b/llvm/tools/llvm-pdbutil/PdbYaml.h
@@ -11,7 +11,6 @@
 
 #include "OutputStyle.h"
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
 #include "llvm/DebugInfo/MSF/MSFCommon.h"
@@ -24,6 +23,7 @@
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/YAMLTraits.h"
 
+#include <optional>
 #include <vector>
 
 namespace llvm {
@@ -67,7 +67,7 @@ struct PdbDbiModuleInfo {
   StringRef Mod;
   std::vector<StringRef> SourceFiles;
   std::vector<CodeViewYAML::YAMLDebugSubsection> Subsections;
-  Optional<PdbModiStream> Modi;
+  std::optional<PdbModiStream> Modi;
 };
 
 struct PdbDbiStream {
@@ -94,16 +94,16 @@ struct PdbPublicsStream {
 struct PdbObject {
   explicit PdbObject(BumpPtrAllocator &Allocator) : Allocator(Allocator) {}
 
-  Optional<MSFHeaders> Headers;
-  Optional<std::vector<uint32_t>> StreamSizes;
-  Optional<std::vector<StreamBlockList>> StreamMap;
-  Optional<PdbInfoStream> PdbStream;
-  Optional<PdbDbiStream> DbiStream;
-  Optional<PdbTpiStream> TpiStream;
-  Optional<PdbTpiStream> IpiStream;
-  Optional<PdbPublicsStream> PublicsStream;
+  std::optional<MSFHeaders> Headers;
+  std::optional<std::vector<uint32_t>> StreamSizes;
+  std::optional<std::vector<StreamBlockList>> StreamMap;
+  std::optional<PdbInfoStream> PdbStream;
+  std::optional<PdbDbiStream> DbiStream;
+  std::optional<PdbTpiStream> TpiStream;
+  std::optional<PdbTpiStream> IpiStream;
+  std::optional<PdbPublicsStream> PublicsStream;
 
-  Optional<std::vector<StringRef>> StringTable;
+  std::optional<std::vector<StringRef>> StringTable;
 
   BumpPtrAllocator &Allocator;
 };

diff  --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp
index 347fb3dbf0239..1147e97cc0625 100644
--- a/llvm/tools/obj2yaml/dwarf2yaml.cpp
+++ b/llvm/tools/obj2yaml/dwarf2yaml.cpp
@@ -18,6 +18,7 @@
 #include "llvm/ObjectYAML/DWARFYAML.h"
 
 #include <algorithm>
+#include <optional>
 
 using namespace llvm;
 
@@ -165,7 +166,7 @@ Error dumpDebugRanges(DWARFContext &DCtx, DWARFYAML::Data &Y) {
   return ErrorSuccess();
 }
 
-static Optional<DWARFYAML::PubSection>
+static std::optional<DWARFYAML::PubSection>
 dumpPubSection(const DWARFContext &DCtx, const DWARFSection &Section,
                bool IsGNUStyle) {
   DWARFYAML::PubSection Y;

diff  --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index f64e479d51a7e..0c4e841c47467 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -54,11 +54,11 @@ class ELFDumper {
   Expected<std::vector<ELFYAML::ProgramHeader>>
   dumpProgramHeaders(ArrayRef<std::unique_ptr<ELFYAML::Chunk>> Sections);
 
-  Optional<DWARFYAML::Data>
+  std::optional<DWARFYAML::Data>
   dumpDWARFSections(std::vector<std::unique_ptr<ELFYAML::Chunk>> &Sections);
 
   Error dumpSymbols(const Elf_Shdr *Symtab,
-                    Optional<std::vector<ELFYAML::Symbol>> &Symbols);
+                    std::optional<std::vector<ELFYAML::Symbol>> &Symbols);
   Error dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
                    StringRef StrTable, ELFYAML::Symbol &S);
   Expected<std::vector<std::unique_ptr<ELFYAML::Chunk>>> dumpSections();
@@ -102,7 +102,7 @@ class ELFDumper {
   dumpPlaceholderSection(const Elf_Shdr *Shdr);
 
   bool shouldPrintSection(const ELFYAML::Section &S, const Elf_Shdr &SHdr,
-                          Optional<DWARFYAML::Data> DWARF);
+                          std::optional<DWARFYAML::Data> DWARF);
 
 public:
   ELFDumper(const object::ELFFile<ELFT> &O, std::unique_ptr<DWARFContext> DCtx);
@@ -183,7 +183,7 @@ ELFDumper<ELFT>::getUniquedSymbolName(const Elf_Sym *Sym, StringRef StrTable,
 template <class ELFT>
 bool ELFDumper<ELFT>::shouldPrintSection(const ELFYAML::Section &S,
                                          const Elf_Shdr &SHdr,
-                                         Optional<DWARFYAML::Data> DWARF) {
+                                         std::optional<DWARFYAML::Data> DWARF) {
   // We only print the SHT_NULL section at index 0 when it
   // has at least one non-null field, because yaml2obj
   // normally creates the zero section at index 0 implicitly.
@@ -511,7 +511,7 @@ ELFDumper<ELFT>::dumpProgramHeaders(
 }
 
 template <class ELFT>
-Optional<DWARFYAML::Data> ELFDumper<ELFT>::dumpDWARFSections(
+std::optional<DWARFYAML::Data> ELFDumper<ELFT>::dumpDWARFSections(
     std::vector<std::unique_ptr<ELFYAML::Chunk>> &Sections) {
   DWARFYAML::Data DWARF;
   for (std::unique_ptr<ELFYAML::Chunk> &C : Sections) {
@@ -674,7 +674,8 @@ ELFDumper<ELFT>::dumpSections() {
 
 template <class ELFT>
 Error ELFDumper<ELFT>::dumpSymbols(
-    const Elf_Shdr *Symtab, Optional<std::vector<ELFYAML::Symbol>> &Symbols) {
+    const Elf_Shdr *Symtab,
+    std::optional<std::vector<ELFYAML::Symbol>> &Symbols) {
   if (!Symtab)
     return Error::success();
 

diff  --git a/llvm/tools/yaml2obj/yaml2obj.cpp b/llvm/tools/yaml2obj/yaml2obj.cpp
index 37aa3a96601d1..ba1f54d2ecf7c 100644
--- a/llvm/tools/yaml2obj/yaml2obj.cpp
+++ b/llvm/tools/yaml2obj/yaml2obj.cpp
@@ -60,8 +60,8 @@ cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
                                     cl::Prefix, cl::cat(Cat));
 } // namespace
 
-static Optional<std::string> preprocess(StringRef Buf,
-                                        yaml::ErrorHandler ErrHandler) {
+static std::optional<std::string> preprocess(StringRef Buf,
+                                             yaml::ErrorHandler ErrHandler) {
   DenseMap<StringRef, StringRef> Defines;
   for (StringRef Define : D) {
     StringRef Macro, Definition;
@@ -134,7 +134,8 @@ int main(int argc, char **argv) {
   if (!Buf)
     return 1;
 
-  Optional<std::string> Buffer = preprocess(Buf.get()->getBuffer(), ErrHandler);
+  std::optional<std::string> Buffer =
+      preprocess(Buf.get()->getBuffer(), ErrHandler);
   if (!Buffer)
     return 1;
 

diff  --git a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
index bede0513a5517..f9b83895c3715 100644
--- a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
+++ b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
@@ -27,6 +27,7 @@
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/YAMLTraits.h"
+#include <optional>
 
 using namespace mlir;
 
@@ -52,7 +53,7 @@ struct LinalgYAMLContext {
 struct LinalgOpMetadata {
   std::string name;
   std::string cppClassName;
-  Optional<std::string> doc;
+  std::optional<std::string> doc;
   SmallVector<std::string> implements;
   SmallVector<std::string> defines;
 };
@@ -76,11 +77,11 @@ enum class LinalgOperandDefKind {
 struct LinalgOperandDef {
   std::string name;
   LinalgOperandDefKind kind;
-  Optional<std::string> typeVar;
-  Optional<SerializedAffineMap> shapeMap;
-  Optional<SerializedAffineMap> indexAttrMap;
-  Optional<SmallVector<int64_t>> defaultIndices;
-  Optional<std::string> defaultFn;
+  std::optional<std::string> typeVar;
+  std::optional<SerializedAffineMap> shapeMap;
+  std::optional<SerializedAffineMap> indexAttrMap;
+  std::optional<SmallVector<int64_t>> defaultIndices;
+  std::optional<std::string> defaultFn;
 };
 
 enum class LinalgIteratorTypeDef {
@@ -89,7 +90,7 @@ enum class LinalgIteratorTypeDef {
 };
 
 struct LinalgIndexingMapsConfig {
-  Optional<SmallVector<SerializedAffineMap>> staticIndexingMaps;
+  std::optional<SmallVector<SerializedAffineMap>> staticIndexingMaps;
 };
 
 struct ScalarExpression;
@@ -98,19 +99,19 @@ enum class ScalarFnKind { Unary, Binary, Type };
 
 struct ScalarFn {
   ScalarFnKind kind;
-  Optional<std::string> fnName;
-  Optional<std::string> attrName;
-  Optional<std::string> typeVar;
+  std::optional<std::string> fnName;
+  std::optional<std::string> attrName;
+  std::optional<std::string> typeVar;
   // NOTE: This must be of arity 1, but to break the self-referential cycle,
   // we use a heap allocated vector.
   std::vector<ScalarExpression> operands;
 };
 
 struct ScalarExpression {
-  Optional<std::string> arg;
-  Optional<std::string> constant;
-  Optional<int64_t> index;
-  Optional<ScalarFn> scalarFn;
+  std::optional<std::string> arg;
+  std::optional<std::string> constant;
+  std::optional<int64_t> index;
+  std::optional<ScalarFn> scalarFn;
 };
 
 struct ScalarAssign {
@@ -126,8 +127,8 @@ struct LinalgStructuredOpConfig {
 };
 
 struct LinalgOpConfig {
-  Optional<LinalgOpMetadata> metadata;
-  Optional<LinalgStructuredOpConfig> structuredOp;
+  std::optional<LinalgOpMetadata> metadata;
+  std::optional<LinalgStructuredOpConfig> structuredOp;
 };
 
 } // namespace


        


More information about the cfe-commits mailing list