[llvm] f4c16c4 - [MC] llvm::Optional => std::optional

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 4 13:36:16 PST 2022


Author: Fangrui Song
Date: 2022-12-04T21:36:08Z
New Revision: f4c16c44737caac25bf09ec2d85809820579ae40

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

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

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

Added: 
    

Modified: 
    bolt/include/bolt/Core/BinaryContext.h
    bolt/include/bolt/Core/DebugData.h
    bolt/include/bolt/Core/MCPlus.h
    bolt/lib/Core/BinaryContext.cpp
    bolt/lib/Core/DebugData.cpp
    llvm/include/llvm/MC/MCAsmBackend.h
    llvm/include/llvm/MC/MCContext.h
    llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
    llvm/include/llvm/MC/MCDwarf.h
    llvm/include/llvm/MC/MCInstrAnalysis.h
    llvm/include/llvm/MC/MCObjectFileInfo.h
    llvm/include/llvm/MC/MCObjectStreamer.h
    llvm/include/llvm/MC/MCRegisterInfo.h
    llvm/include/llvm/MC/MCSectionXCOFF.h
    llvm/include/llvm/MC/MCStreamer.h
    llvm/include/llvm/MC/MCSubtargetInfo.h
    llvm/include/llvm/MC/MCSymbolWasm.h
    llvm/include/llvm/MC/MCSymbolXCOFF.h
    llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/lib/CodeGen/MachineOperand.cpp
    llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
    llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
    llvm/lib/MC/MCAsmBackend.cpp
    llvm/lib/MC/MCAsmStreamer.cpp
    llvm/lib/MC/MCContext.cpp
    llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
    llvm/lib/MC/MCDwarf.cpp
    llvm/lib/MC/MCELFStreamer.cpp
    llvm/lib/MC/MCInstrAnalysis.cpp
    llvm/lib/MC/MCObjectStreamer.cpp
    llvm/lib/MC/MCParser/AsmParser.cpp
    llvm/lib/MC/MCParser/MasmParser.cpp
    llvm/lib/MC/MCRegisterInfo.cpp
    llvm/lib/MC/MCStreamer.cpp
    llvm/lib/MC/MCSubtargetInfo.cpp
    llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
    llvm/lib/MC/MCWin64EH.cpp
    llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
    llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
    llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
    llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
    llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
    llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h
    llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h
    llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
    llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
    llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
    llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
    llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h
    llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
    llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
    llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
    llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
    llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp
    llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
    llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
    llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
    llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
    llvm/tools/llvm-objdump/XCOFFDump.cpp
    llvm/tools/llvm-objdump/XCOFFDump.h
    llvm/tools/llvm-objdump/llvm-objdump.cpp
    llvm/unittests/MC/DwarfLineTableHeaders.cpp

Removed: 
    


################################################################################
diff  --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h
index d286ba4a68c36..f36c5e8a6611f 100644
--- a/bolt/include/bolt/Core/BinaryContext.h
+++ b/bolt/include/bolt/Core/BinaryContext.h
@@ -283,7 +283,7 @@ class BinaryContext {
 
   Expected<unsigned> getDwarfFile(StringRef Directory, StringRef FileName,
                                   unsigned FileNumber,
-                                  Optional<MD5::MD5Result> Checksum,
+                                  std::optional<MD5::MD5Result> Checksum,
                                   std::optional<StringRef> Source,
                                   unsigned CUID, unsigned DWARFVersion);
 

diff  --git a/bolt/include/bolt/Core/DebugData.h b/bolt/include/bolt/Core/DebugData.h
index 5485016ed2d88..5be678cc12e27 100644
--- a/bolt/include/bolt/Core/DebugData.h
+++ b/bolt/include/bolt/Core/DebugData.h
@@ -1130,10 +1130,10 @@ class DwarfLineTable {
 
   /// Emit the Dwarf file and the line tables for a given CU.
   void emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params,
-              Optional<MCDwarfLineStr> &LineStr, BinaryContext &BC) const;
+              std::optional<MCDwarfLineStr> &LineStr, BinaryContext &BC) const;
 
   Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName,
-                                Optional<MD5::MD5Result> Checksum,
+                                std::optional<MD5::MD5Result> Checksum,
                                 std::optional<StringRef> Source,
                                 uint16_t DwarfVersion,
                                 unsigned FileNumber = 0) {
@@ -1150,7 +1150,7 @@ class DwarfLineTable {
   /// Sets the root file \p Directory, \p FileName, optional \p CheckSum, and
   /// optional \p Source.
   void setRootFile(StringRef Directory, StringRef FileName,
-                   Optional<MD5::MD5Result> Checksum,
+                   std::optional<MD5::MD5Result> Checksum,
                    std::optional<StringRef> Source) {
     Header.setRootFile(Directory, FileName, Checksum, Source);
   }

diff  --git a/bolt/include/bolt/Core/MCPlus.h b/bolt/include/bolt/Core/MCPlus.h
index b4a72ac274fad..e3ddb192821e9 100644
--- a/bolt/include/bolt/Core/MCPlus.h
+++ b/bolt/include/bolt/Core/MCPlus.h
@@ -21,6 +21,17 @@
 #include <vector>
 
 namespace llvm {
+
+template <typename T, typename = decltype(std::declval<raw_ostream &>()
+                                          << std::declval<const T &>())>
+raw_ostream &operator<<(raw_ostream &OS, const std::optional<T> &O) {
+  if (O)
+    OS << *O;
+  else
+    OS << std::nullopt;
+  return OS;
+}
+
 namespace bolt {
 
 // NOTE: using SmallVector for instruction list results in a memory regression.

diff  --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index 280e121fb4a1b..8f2bc4ceecc41 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -1461,7 +1461,7 @@ void BinaryContext::printGlobalSymbols(raw_ostream &OS) const {
 
 Expected<unsigned> BinaryContext::getDwarfFile(
     StringRef Directory, StringRef FileName, unsigned FileNumber,
-    Optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
+    std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
     unsigned CUID, unsigned DWARFVersion) {
   DwarfLineTable &Table = DwarfLineTablesCUMap[CUID];
   return Table.tryGetFile(Directory, FileName, Checksum, Source, DWARFVersion,
@@ -1645,7 +1645,7 @@ void BinaryContext::preprocessDebugInfo() {
 
     uint16_t DwarfVersion = LineTable->Prologue.getVersion();
     if (DwarfVersion >= 5) {
-      Optional<MD5::MD5Result> Checksum;
+      std::optional<MD5::MD5Result> Checksum;
       if (LineTable->Prologue.ContentTypes.HasMD5)
         Checksum = LineTable->Prologue.FileNames[0].Checksum;
       Optional<const char *> Name =
@@ -1683,7 +1683,7 @@ void BinaryContext::preprocessDebugInfo() {
       if (Optional<const char *> FName = dwarf::toString(FileNames[I].Name))
         FileName = *FName;
       assert(FileName != "");
-      Optional<MD5::MD5Result> Checksum;
+      std::optional<MD5::MD5Result> Checksum;
       if (DwarfVersion >= 5 && LineTable->Prologue.ContentTypes.HasMD5)
         Checksum = LineTable->Prologue.FileNames[I].Checksum;
       cantFail(getDwarfFile(Dir, FileName, 0, Checksum, std::nullopt, CUID,

diff  --git a/bolt/lib/Core/DebugData.cpp b/bolt/lib/Core/DebugData.cpp
index 80a96a033cdd4..6d39353dcf72d 100644
--- a/bolt/lib/Core/DebugData.cpp
+++ b/bolt/lib/Core/DebugData.cpp
@@ -1513,7 +1513,7 @@ static inline void emitDwarfLineTable(
 }
 
 void DwarfLineTable::emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params,
-                            Optional<MCDwarfLineStr> &LineStr,
+                            std::optional<MCDwarfLineStr> &LineStr,
                             BinaryContext &BC) const {
   if (!RawData.empty()) {
     assert(MCLineSections.getMCLineEntries().empty() &&
@@ -1585,7 +1585,7 @@ void DwarfLineTable::emit(BinaryContext &BC, MCStreamer &Streamer) {
   if (LineTables.empty())
     return;
   // In a v5 non-split line table, put the strings in a separate section.
-  Optional<MCDwarfLineStr> LineStr(std::nullopt);
+  std::optional<MCDwarfLineStr> LineStr;
   ErrorOr<BinarySection &> LineStrSection =
       BC.getUniqueSectionByName(".debug_line_str");
   // Some versions of GCC output DWARF5 .debug_info, but DWARF4 or lower

diff  --git a/llvm/include/llvm/MC/MCAsmBackend.h b/llvm/include/llvm/MC/MCAsmBackend.h
index a5e7b3f504f56..9ce4dbf6e9908 100644
--- a/llvm/include/llvm/MC/MCAsmBackend.h
+++ b/llvm/include/llvm/MC/MCAsmBackend.h
@@ -89,7 +89,7 @@ class MCAsmBackend {
   virtual unsigned getNumFixupKinds() const = 0;
 
   /// Map a relocation name used in .reloc to a fixup kind.
-  virtual Optional<MCFixupKind> getFixupKind(StringRef Name) const;
+  virtual std::optional<MCFixupKind> getFixupKind(StringRef Name) const;
 
   /// Get information on a fixup kind.
   virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;

diff  --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 4fb273fb1ccd6..8e06854fe135f 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -616,9 +616,9 @@ class MCContext {
 
   /// Return the unique ID of the section with the given name, flags and entry
   /// size, if it exists.
-  Optional<unsigned> getELFUniqueIDForEntsize(StringRef SectionName,
-                                              unsigned Flags,
-                                              unsigned EntrySize);
+  std::optional<unsigned> getELFUniqueIDForEntsize(StringRef SectionName,
+                                                   unsigned Flags,
+                                                   unsigned EntrySize);
 
   MCSectionGOFF *getGOFFSection(StringRef Section, SectionKind Kind,
                                 MCSection *Parent, const MCExpr *SubsectionId);
@@ -673,13 +673,12 @@ class MCContext {
   bool hasXCOFFSection(StringRef Section,
                        XCOFF::CsectProperties CsectProp) const;
 
-  MCSectionXCOFF *
-  getXCOFFSection(StringRef Section, SectionKind K,
-                  Optional<XCOFF::CsectProperties> CsectProp = std::nullopt,
-                  bool MultiSymbolsAllowed = false,
-                  const char *BeginSymName = nullptr,
-                  Optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags =
-                      std::nullopt);
+  MCSectionXCOFF *getXCOFFSection(
+      StringRef Section, SectionKind K,
+      std::optional<XCOFF::CsectProperties> CsectProp = std::nullopt,
+      bool MultiSymbolsAllowed = false, const char *BeginSymName = nullptr,
+      std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags =
+          std::nullopt);
 
   // Create and save a copy of STI and return a reference to the copy.
   MCSubtargetInfo &getSubtargetCopy(const MCSubtargetInfo &STI);
@@ -717,10 +716,11 @@ class MCContext {
   void setMainFileName(StringRef S) { MainFileName = std::string(S); }
 
   /// Creates an entry in the dwarf file and directory tables.
-  Expected<unsigned> getDwarfFile(
-      StringRef Directory, StringRef FileName, unsigned FileNumber,
-      Optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
-      unsigned CUID);
+  Expected<unsigned> getDwarfFile(StringRef Directory, StringRef FileName,
+                                  unsigned FileNumber,
+                                  std::optional<MD5::MD5Result> Checksum,
+                                  std::optional<StringRef> Source,
+                                  unsigned CUID);
 
   bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0);
 
@@ -754,7 +754,7 @@ class MCContext {
   /// These are "file 0" and "directory 0" in DWARF v5.
   void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir,
                               StringRef Filename,
-                              Optional<MD5::MD5Result> Checksum,
+                              std::optional<MD5::MD5Result> Checksum,
                               std::optional<StringRef> Source) {
     getMCDwarfLineTable(CUID).setRootFile(CompilationDir, Filename, Checksum,
                                           Source);

diff  --git a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
index ebe81fd8d1215..82a1847ac9be2 100644
--- a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
+++ b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
@@ -20,11 +20,11 @@
 namespace llvm {
 
 struct XCOFFSymbolInfo {
-  Optional<XCOFF::StorageMappingClass> StorageMappingClass;
-  Optional<uint32_t> Index;
+  std::optional<XCOFF::StorageMappingClass> StorageMappingClass;
+  std::optional<uint32_t> Index;
   bool IsLabel;
-  XCOFFSymbolInfo(Optional<XCOFF::StorageMappingClass> Smc,
-                  Optional<uint32_t> Idx, bool Label)
+  XCOFFSymbolInfo(std::optional<XCOFF::StorageMappingClass> Smc,
+                  std::optional<uint32_t> Idx, bool Label)
       : StorageMappingClass(Smc), Index(Idx), IsLabel(Label) {}
 
   bool operator<(const XCOFFSymbolInfo &SymInfo) const;
@@ -44,8 +44,8 @@ struct SymbolInfoTy {
 
 public:
   SymbolInfoTy(uint64_t Addr, StringRef Name,
-               Optional<XCOFF::StorageMappingClass> Smc, Optional<uint32_t> Idx,
-               bool Label)
+               std::optional<XCOFF::StorageMappingClass> Smc,
+               std::optional<uint32_t> Idx, bool Label)
       : Addr(Addr), Name(Name), XCOFFSymInfo(Smc, Idx, Label), IsXCOFF(true),
         HasType(false) {}
   SymbolInfoTy(uint64_t Addr, StringRef Name, uint8_t Type,
@@ -159,7 +159,7 @@ class MCDisassembler {
   ///                   done by buffering the output if needed.
   ///                 - None if the target doesn't want to handle the symbol
   ///                   separately. Value of Size is ignored in this case.
-  virtual Optional<DecodeStatus>
+  virtual std::optional<DecodeStatus>
   onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef<uint8_t> Bytes,
                 uint64_t Address, raw_ostream &CStream) const;
   // TODO:

diff  --git a/llvm/include/llvm/MC/MCDwarf.h b/llvm/include/llvm/MC/MCDwarf.h
index e576dab2f9eb8..d9c88c54d4101 100644
--- a/llvm/include/llvm/MC/MCDwarf.h
+++ b/llvm/include/llvm/MC/MCDwarf.h
@@ -90,7 +90,7 @@ struct MCDwarfFile {
 
   /// The MD5 checksum, if there is one. Non-owning pointer to data allocated
   /// in MCContext.
-  Optional<MD5::MD5Result> Checksum;
+  std::optional<MD5::MD5Result> Checksum;
 
   /// The source code of the file. Non-owning reference to data allocated in
   /// MCContext.
@@ -271,17 +271,16 @@ struct MCDwarfLineTableHeader {
   MCDwarfLineTableHeader() = default;
 
   Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName,
-                                Optional<MD5::MD5Result> Checksum,
+                                std::optional<MD5::MD5Result> Checksum,
                                 std::optional<StringRef> Source,
-                                uint16_t DwarfVersion,
-                                unsigned FileNumber = 0);
+                                uint16_t DwarfVersion, unsigned FileNumber = 0);
   std::pair<MCSymbol *, MCSymbol *>
   Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
-       Optional<MCDwarfLineStr> &LineStr) const;
+       std::optional<MCDwarfLineStr> &LineStr) const;
   std::pair<MCSymbol *, MCSymbol *>
   Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
        ArrayRef<char> SpecialOpcodeLengths,
-       Optional<MCDwarfLineStr> &LineStr) const;
+       std::optional<MCDwarfLineStr> &LineStr) const;
   void resetMD5Usage() {
     HasAllMD5 = true;
     HasAnyMD5 = false;
@@ -295,7 +294,7 @@ struct MCDwarfLineTableHeader {
   }
 
   void setRootFile(StringRef Directory, StringRef FileName,
-                   Optional<MD5::MD5Result> Checksum,
+                   std::optional<MD5::MD5Result> Checksum,
                    std::optional<StringRef> Source) {
     CompilationDir = std::string(Directory);
     RootFile.Name = std::string(FileName);
@@ -316,7 +315,8 @@ struct MCDwarfLineTableHeader {
 
 private:
   void emitV2FileDirTables(MCStreamer *MCOS) const;
-  void emitV5FileDirTables(MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr) const;
+  void emitV5FileDirTables(MCStreamer *MCOS,
+                           std::optional<MCDwarfLineStr> &LineStr) const;
 };
 
 class MCDwarfDwoLineTable {
@@ -325,7 +325,7 @@ class MCDwarfDwoLineTable {
 
 public:
   void maybeSetRootFile(StringRef Directory, StringRef FileName,
-                        Optional<MD5::MD5Result> Checksum,
+                        std::optional<MD5::MD5Result> Checksum,
                         std::optional<StringRef> Source) {
     if (!Header.RootFile.Name.empty())
       return;
@@ -333,8 +333,8 @@ class MCDwarfDwoLineTable {
   }
 
   unsigned getFile(StringRef Directory, StringRef FileName,
-                   Optional<MD5::MD5Result> Checksum, uint16_t DwarfVersion,
-                   std::optional<StringRef> Source) {
+                   std::optional<MD5::MD5Result> Checksum,
+                   uint16_t DwarfVersion, std::optional<StringRef> Source) {
     HasSplitLineTable = true;
     return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source,
                                       DwarfVersion));
@@ -354,7 +354,7 @@ class MCDwarfLineTable {
 
   // This emits the Dwarf file and the line tables for a given Compile Unit.
   void emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params,
-              Optional<MCDwarfLineStr> &LineStr) const;
+              std::optional<MCDwarfLineStr> &LineStr) const;
 
   // This emits a single line table associated with a given Section.
   static void
@@ -362,12 +362,11 @@ class MCDwarfLineTable {
           const MCLineSection::MCDwarfLineEntryCollection &LineEntries);
 
   Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName,
-                                Optional<MD5::MD5Result> Checksum,
+                                std::optional<MD5::MD5Result> Checksum,
                                 std::optional<StringRef> Source,
-                                uint16_t DwarfVersion,
-                                unsigned FileNumber = 0);
+                                uint16_t DwarfVersion, unsigned FileNumber = 0);
   unsigned getFile(StringRef &Directory, StringRef &FileName,
-                   Optional<MD5::MD5Result> Checksum,
+                   std::optional<MD5::MD5Result> Checksum,
                    std::optional<StringRef> Source, uint16_t DwarfVersion,
                    unsigned FileNumber = 0) {
     return cantFail(tryGetFile(Directory, FileName, Checksum, Source,
@@ -375,7 +374,7 @@ class MCDwarfLineTable {
   }
 
   void setRootFile(StringRef Directory, StringRef FileName,
-                   Optional<MD5::MD5Result> Checksum,
+                   std::optional<MD5::MD5Result> Checksum,
                    std::optional<StringRef> Source) {
     Header.CompilationDir = std::string(Directory);
     Header.RootFile.Name = std::string(FileName);

diff  --git a/llvm/include/llvm/MC/MCInstrAnalysis.h b/llvm/include/llvm/MC/MCInstrAnalysis.h
index a937f8203a0d7..61c443f97254c 100644
--- a/llvm/include/llvm/MC/MCInstrAnalysis.h
+++ b/llvm/include/llvm/MC/MCInstrAnalysis.h
@@ -157,13 +157,13 @@ class MCInstrAnalysis {
 
   /// Given an instruction tries to get the address of a memory operand. Returns
   /// the address on success.
-  virtual Optional<uint64_t>
+  virtual std::optional<uint64_t>
   evaluateMemoryOperandAddress(const MCInst &Inst, const MCSubtargetInfo *STI,
                                uint64_t Addr, uint64_t Size) const;
 
   /// Given an instruction with a memory operand that could require relocation,
   /// returns the offset within the instruction of that relocation.
-  virtual Optional<uint64_t>
+  virtual std::optional<uint64_t>
   getMemoryOperandRelocationOffset(const MCInst &Inst, uint64_t Size) const;
 
   /// Returns (PLT virtual address, GOT virtual address) pairs for PLT entries.

diff  --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h
index 2ac18a28805db..ce200a41cfa8d 100644
--- a/llvm/include/llvm/MC/MCObjectFileInfo.h
+++ b/llvm/include/llvm/MC/MCObjectFileInfo.h
@@ -13,13 +13,13 @@
 #ifndef LLVM_MC_MCOBJECTFILEINFO_H
 #define LLVM_MC_MCOBJECTFILEINFO_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/BinaryFormat/Swift.h"
 #include "llvm/MC/MCSection.h"
 #include "llvm/Support/VersionTuple.h"
 
 #include <array>
+#include <optional>
 
 namespace llvm {
 class MCContext;
@@ -451,7 +451,7 @@ class MCObjectFileInfo {
   bool PositionIndependent = false;
   MCContext *Ctx = nullptr;
   VersionTuple SDKVersion;
-  Optional<Triple> DarwinTargetVariantTriple;
+  std::optional<Triple> DarwinTargetVariantTriple;
   VersionTuple DarwinTargetVariantSDKVersion;
 
   void initMachOMCObjectFileInfo(const Triple &T);

diff  --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h
index fbc54c67d7c40..52ddaf3488299 100644
--- a/llvm/include/llvm/MC/MCObjectStreamer.h
+++ b/llvm/include/llvm/MC/MCObjectStreamer.h
@@ -191,7 +191,7 @@ class MCObjectStreamer : public MCStreamer {
   void emitTPRel64Value(const MCExpr *Value) override;
   void emitGPRel32Value(const MCExpr *Value) override;
   void emitGPRel64Value(const MCExpr *Value) override;
-  Optional<std::pair<bool, std::string>>
+  std::optional<std::pair<bool, std::string>>
   emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
                      SMLoc Loc, const MCSubtargetInfo &STI) override;
   using MCStreamer::emitFill;

diff  --git a/llvm/include/llvm/MC/MCRegisterInfo.h b/llvm/include/llvm/MC/MCRegisterInfo.h
index 7165a2982d1b0..40095c193fad6 100644
--- a/llvm/include/llvm/MC/MCRegisterInfo.h
+++ b/llvm/include/llvm/MC/MCRegisterInfo.h
@@ -514,7 +514,7 @@ class MCRegisterInfo {
 
   /// Map a dwarf register back to a target register. Returns None is there is
   /// no mapping.
-  Optional<unsigned> getLLVMRegNum(unsigned RegNum, bool isEH) const;
+  std::optional<unsigned> getLLVMRegNum(unsigned RegNum, bool isEH) const;
 
   /// Map a target EH register number to an equivalent DWARF register
   /// number.

diff  --git a/llvm/include/llvm/MC/MCSectionXCOFF.h b/llvm/include/llvm/MC/MCSectionXCOFF.h
index b6b6dbfaadf46..68832f5daad58 100644
--- a/llvm/include/llvm/MC/MCSectionXCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionXCOFF.h
@@ -32,10 +32,10 @@ namespace llvm {
 class MCSectionXCOFF final : public MCSection {
   friend class MCContext;
 
-  Optional<XCOFF::CsectProperties> CsectProp;
+  std::optional<XCOFF::CsectProperties> CsectProp;
   MCSymbolXCOFF *const QualName;
   StringRef SymbolTableName;
-  Optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags;
+  std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags;
   bool MultiSymbolsAllowed;
   static constexpr unsigned DefaultAlignVal = 4;
   static constexpr unsigned DefaultTextAlignVal = 32;
@@ -118,10 +118,12 @@ class MCSectionXCOFF final : public MCSection {
   bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
   bool isCsect() const { return CsectProp.has_value(); }
   bool isDwarfSect() const { return DwarfSubtypeFlags.has_value(); }
-  Optional<XCOFF::DwarfSectionSubtypeFlags> getDwarfSubtypeFlags() const {
+  std::optional<XCOFF::DwarfSectionSubtypeFlags> getDwarfSubtypeFlags() const {
     return DwarfSubtypeFlags;
   }
-  Optional<XCOFF::CsectProperties> getCsectProp() const { return CsectProp; }
+  std::optional<XCOFF::CsectProperties> getCsectProp() const {
+    return CsectProp;
+  }
 };
 
 } // end namespace llvm

diff  --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h
index 5edae19eccfbe..bdab8e3a3f3ae 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -908,7 +908,7 @@ class MCStreamer {
   /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
   unsigned emitDwarfFileDirective(
       unsigned FileNo, StringRef Directory, StringRef Filename,
-      Optional<MD5::MD5Result> Checksum = std::nullopt,
+      std::optional<MD5::MD5Result> Checksum = std::nullopt,
       std::optional<StringRef> Source = std::nullopt, unsigned CUID = 0) {
     return cantFail(
         tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum,
@@ -922,12 +922,12 @@ class MCStreamer {
   /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive.
   virtual Expected<unsigned> tryEmitDwarfFileDirective(
       unsigned FileNo, StringRef Directory, StringRef Filename,
-      Optional<MD5::MD5Result> Checksum = std::nullopt,
+      std::optional<MD5::MD5Result> Checksum = std::nullopt,
       std::optional<StringRef> Source = std::nullopt, unsigned CUID = 0);
 
   /// Specify the "root" file of the compilation, using the ".file 0" extension.
   virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
-                                       Optional<MD5::MD5Result> Checksum,
+                                       std::optional<MD5::MD5Result> Checksum,
                                        std::optional<StringRef> Source,
                                        unsigned CUID = 0);
 
@@ -1086,7 +1086,7 @@ class MCStreamer {
 
   /// Record a relocation described by the .reloc directive. Return None if
   /// succeeded. Otherwise, return a pair (Name is invalid, error message).
-  virtual Optional<std::pair<bool, std::string>>
+  virtual std::optional<std::pair<bool, std::string>>
   emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
                      SMLoc Loc, const MCSubtargetInfo &STI) {
     return std::nullopt;

diff  --git a/llvm/include/llvm/MC/MCSubtargetInfo.h b/llvm/include/llvm/MC/MCSubtargetInfo.h
index 6cf4dd5b299a4..815b0b71ded2f 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -247,7 +247,7 @@ class MCSubtargetInfo {
 
   /// Return the target cache line size in bytes at a given level.
   ///
-  virtual Optional<unsigned> getCacheLineSize(unsigned Level) const;
+  virtual std::optional<unsigned> getCacheLineSize(unsigned Level) const;
 
   /// Return the target cache line size in bytes.  By default, return
   /// the line size for the bottom-most level of cache.  This provides
@@ -256,7 +256,7 @@ class MCSubtargetInfo {
   /// cache model.
   ///
   virtual unsigned getCacheLineSize() const {
-    Optional<unsigned> Size = getCacheLineSize(0);
+    std::optional<unsigned> Size = getCacheLineSize(0);
     if (Size)
       return *Size;
 

diff  --git a/llvm/include/llvm/MC/MCSymbolWasm.h b/llvm/include/llvm/MC/MCSymbolWasm.h
index 33ec0db8fcab4..66f0e3a90e8a6 100644
--- a/llvm/include/llvm/MC/MCSymbolWasm.h
+++ b/llvm/include/llvm/MC/MCSymbolWasm.h
@@ -14,19 +14,19 @@
 namespace llvm {
 
 class MCSymbolWasm : public MCSymbol {
-  Optional<wasm::WasmSymbolType> Type;
+  std::optional<wasm::WasmSymbolType> Type;
   bool IsWeak = false;
   bool IsHidden = false;
   bool IsComdat = false;
   bool OmitFromLinkingSection = false;
   mutable bool IsUsedInInitArray = false;
   mutable bool IsUsedInGOT = false;
-  Optional<StringRef> ImportModule;
-  Optional<StringRef> ImportName;
-  Optional<StringRef> ExportName;
+  std::optional<StringRef> ImportModule;
+  std::optional<StringRef> ImportName;
+  std::optional<StringRef> ExportName;
   wasm::WasmSignature *Signature = nullptr;
-  Optional<wasm::WasmGlobalType> GlobalType;
-  Optional<wasm::WasmTableType> TableType;
+  std::optional<wasm::WasmGlobalType> GlobalType;
+  std::optional<wasm::WasmTableType> TableType;
 
   /// An expression describing how to calculate the size of a symbol. If a
   /// symbol has no size this field will be NULL.
@@ -48,7 +48,7 @@ class MCSymbolWasm : public MCSymbol {
   bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
   bool isTag() const { return Type == wasm::WASM_SYMBOL_TYPE_TAG; }
 
-  Optional<wasm::WasmSymbolType> getType() const { return Type; }
+  std::optional<wasm::WasmSymbolType> getType() const { return Type; }
 
   void setType(wasm::WasmSymbolType type) { Type = type; }
 

diff  --git a/llvm/include/llvm/MC/MCSymbolXCOFF.h b/llvm/include/llvm/MC/MCSymbolXCOFF.h
index cc19f882e6ad4..bb68e6a928787 100644
--- a/llvm/include/llvm/MC/MCSymbolXCOFF.h
+++ b/llvm/include/llvm/MC/MCSymbolXCOFF.h
@@ -64,7 +64,7 @@ class MCSymbolXCOFF : public MCSymbol {
   }
 
 private:
-  Optional<XCOFF::StorageClass> StorageClass;
+  std::optional<XCOFF::StorageClass> StorageClass;
   MCSectionXCOFF *RepresentedCsect = nullptr;
   XCOFF::VisibilityType VisibilityType = XCOFF::SYM_V_UNSPECIFIED;
   StringRef SymbolTableName;

diff  --git a/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h b/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
index 0213b5440e011..7333e8a8d0457 100644
--- a/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
+++ b/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
@@ -25,7 +25,7 @@ enum class EmitDwarfUnwindType;
 namespace mc {
 
 bool getRelaxAll();
-Optional<bool> getExplicitRelaxAll();
+std::optional<bool> getExplicitRelaxAll();
 
 bool getIncrementalLinkerCompatible();
 

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 9629a5b1d1f9b..a6580b7f6339f 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -3530,7 +3530,8 @@ void DwarfDebug::insertSectionLabel(const MCSymbol *S) {
       AddrPool.getIndex(S);
 }
 
-Optional<MD5::MD5Result> DwarfDebug::getMD5AsBytes(const DIFile *File) const {
+std::optional<MD5::MD5Result>
+DwarfDebug::getMD5AsBytes(const DIFile *File) const {
   assert(File);
   if (getDwarfVersion() < 5)
     return std::nullopt;

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 31e4081b71413..9245ac9242ff2 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -839,7 +839,7 @@ class DwarfDebug : public DebugHandlerBase {
 
   /// If the \p File has an MD5 checksum, return it as an MD5Result
   /// allocated in the MCContext.
-  Optional<MD5::MD5Result> getMD5AsBytes(const DIFile *File) const;
+  std::optional<MD5::MD5Result> getMD5AsBytes(const DIFile *File) const;
 };
 
 } // end namespace llvm

diff  --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp
index bc2a7a8ea0177..bb2d1dac5c668 100644
--- a/llvm/lib/CodeGen/MachineOperand.cpp
+++ b/llvm/lib/CodeGen/MachineOperand.cpp
@@ -458,7 +458,7 @@ static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS,
     return;
   }
 
-  if (Optional<unsigned> Reg = TRI->getLLVMRegNum(DwarfReg, true))
+  if (std::optional<unsigned> Reg = TRI->getLLVMRegNum(DwarfReg, true))
     OS << printReg(*Reg, TRI);
   else
     OS << "<badreg>";

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
index 2d3b14a5570c9..e9b657ea8271b 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
@@ -33,7 +33,7 @@ using namespace dwarf;
 static void printRegister(raw_ostream &OS, const MCRegisterInfo *MRI, bool IsEH,
                           unsigned RegNum) {
   if (MRI) {
-    if (Optional<unsigned> LLVMRegNum = MRI->getLLVMRegNum(RegNum, IsEH)) {
+    if (std::optional<unsigned> LLVMRegNum = MRI->getLLVMRegNum(RegNum, IsEH)) {
       if (const char *RegName = MRI->getName(*LLVMRegNum)) {
         OS << RegName;
         return;

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
index 17b180f55001c..b9d5ddd8ab9d9 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -242,7 +242,8 @@ bool DWARFExpression::prettyPrintRegisterOp(
   else
     DwarfRegNum = Opcode - DW_OP_reg0;
 
-  if (Optional<unsigned> LLVMRegNum = MRI->getLLVMRegNum(DwarfRegNum, isEH)) {
+  if (std::optional<unsigned> LLVMRegNum =
+          MRI->getLLVMRegNum(DwarfRegNum, isEH)) {
     if (const char *RegName = MRI->getName(*LLVMRegNum)) {
       if ((Opcode >= DW_OP_breg0 && Opcode <= DW_OP_breg31) ||
           Opcode == DW_OP_bregx)
@@ -414,7 +415,8 @@ static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I,
       // DW_OP_regx: A register, with the register num given as an operand.
       // Printed as the plain register name.
       uint64_t DwarfRegNum = Op.getRawOperand(0);
-      Optional<unsigned> LLVMRegNum = MRI.getLLVMRegNum(DwarfRegNum, false);
+      std::optional<unsigned> LLVMRegNum =
+          MRI.getLLVMRegNum(DwarfRegNum, false);
       if (!LLVMRegNum) {
         OS << "<unknown register " << DwarfRegNum << ">";
         return false;
@@ -426,7 +428,8 @@ static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I,
     case dwarf::DW_OP_bregx: {
       int DwarfRegNum = Op.getRawOperand(0);
       int64_t Offset = Op.getRawOperand(1);
-      Optional<unsigned> LLVMRegNum = MRI.getLLVMRegNum(DwarfRegNum, false);
+      std::optional<unsigned> LLVMRegNum =
+          MRI.getLLVMRegNum(DwarfRegNum, false);
       if (!LLVMRegNum) {
         OS << "<unknown register " << DwarfRegNum << ">";
         return false;
@@ -463,7 +466,8 @@ static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I,
         // DW_OP_reg<N>: A register, with the register num implied by the
         // opcode. Printed as the plain register name.
         uint64_t DwarfRegNum = Opcode - dwarf::DW_OP_reg0;
-        Optional<unsigned> LLVMRegNum = MRI.getLLVMRegNum(DwarfRegNum, false);
+        std::optional<unsigned> LLVMRegNum =
+            MRI.getLLVMRegNum(DwarfRegNum, false);
         if (!LLVMRegNum) {
           OS << "<unknown register " << DwarfRegNum << ">";
           return false;
@@ -474,7 +478,8 @@ static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I,
                  Opcode <= dwarf::DW_OP_breg31) {
         int DwarfRegNum = Opcode - dwarf::DW_OP_breg0;
         int64_t Offset = Op.getRawOperand(0);
-        Optional<unsigned> LLVMRegNum = MRI.getLLVMRegNum(DwarfRegNum, false);
+        std::optional<unsigned> LLVMRegNum =
+            MRI.getLLVMRegNum(DwarfRegNum, false);
         if (!LLVMRegNum) {
           OS << "<unknown register " << DwarfRegNum << ">";
           return false;

diff  --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp
index d4d5662980ee5..8c638c0db258f 100644
--- a/llvm/lib/MC/MCAsmBackend.cpp
+++ b/llvm/lib/MC/MCAsmBackend.cpp
@@ -74,7 +74,7 @@ MCAsmBackend::createDwoObjectWriter(raw_pwrite_stream &OS,
   }
 }
 
-Optional<MCFixupKind> MCAsmBackend::getFixupKind(StringRef Name) const {
+std::optional<MCFixupKind> MCAsmBackend::getFixupKind(StringRef Name) const {
   return std::nullopt;
 }
 

diff  --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 469d89708cede..eab51f0ca7923 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -63,7 +63,7 @@ class MCAsmStreamer final : public MCStreamer {
   void PrintQuotedString(StringRef Data, raw_ostream &OS) const;
   void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
                                StringRef Filename,
-                               Optional<MD5::MD5Result> Checksum,
+                               std::optional<MD5::MD5Result> Checksum,
                                std::optional<StringRef> Source,
                                bool UseDwarfDirectory,
                                raw_svector_ostream &OS) const;
@@ -250,8 +250,9 @@ class MCAsmStreamer final : public MCStreamer {
   void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
                 SMLoc Loc = SMLoc()) override;
 
-  void emitAlignmentDirective(unsigned ByteAlignment, Optional<int64_t> Value,
-                              unsigned ValueSize, unsigned MaxBytesToEmit);
+  void emitAlignmentDirective(unsigned ByteAlignment,
+                              std::optional<int64_t> Value, unsigned ValueSize,
+                              unsigned MaxBytesToEmit);
 
   void emitValueToAlignment(Align Alignment, int64_t Value = 0,
                             unsigned ValueSize = 1,
@@ -267,14 +268,13 @@ class MCAsmStreamer final : public MCStreamer {
   void emitFileDirective(StringRef Filename) override;
   void emitFileDirective(StringRef Filename, StringRef CompilerVerion,
                          StringRef TimeStamp, StringRef Description) override;
-  Expected<unsigned>
-  tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
-                            StringRef Filename,
-                            Optional<MD5::MD5Result> Checksum = std::nullopt,
-                            std::optional<StringRef> Source = std::nullopt,
-                            unsigned CUID = 0) override;
+  Expected<unsigned> tryEmitDwarfFileDirective(
+      unsigned FileNo, StringRef Directory, StringRef Filename,
+      std::optional<MD5::MD5Result> Checksum = std::nullopt,
+      std::optional<StringRef> Source = std::nullopt,
+      unsigned CUID = 0) override;
   void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
-                               Optional<MD5::MD5Result> Checksum,
+                               std::optional<MD5::MD5Result> Checksum,
                                std::optional<StringRef> Source,
                                unsigned CUID = 0) override;
   void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column,
@@ -385,7 +385,7 @@ class MCAsmStreamer final : public MCStreamer {
   void emitBundleLock(bool AlignToEnd) override;
   void emitBundleUnlock() override;
 
-  Optional<std::pair<bool, std::string>>
+  std::optional<std::pair<bool, std::string>>
   emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
                      SMLoc Loc, const MCSubtargetInfo &STI) override;
 
@@ -1417,7 +1417,7 @@ void MCAsmStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
 }
 
 void MCAsmStreamer::emitAlignmentDirective(unsigned ByteAlignment,
-                                           Optional<int64_t> Value,
+                                           std::optional<int64_t> Value,
                                            unsigned ValueSize,
                                            unsigned MaxBytesToEmit) {
   if (MAI->useDotAlignForAlignment()) {
@@ -1544,7 +1544,7 @@ void MCAsmStreamer::emitFileDirective(StringRef Filename,
 
 void MCAsmStreamer::printDwarfFileDirective(
     unsigned FileNo, StringRef Directory, StringRef Filename,
-    Optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
+    std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
     bool UseDwarfDirectory, raw_svector_ostream &OS) const {
   SmallString<128> FullPathName;
 
@@ -1575,7 +1575,7 @@ void MCAsmStreamer::printDwarfFileDirective(
 
 Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
     unsigned FileNo, StringRef Directory, StringRef Filename,
-    Optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
+    std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
     unsigned CUID) {
   assert(CUID == 0 && "multiple CUs not supported by MCAsmStreamer");
 
@@ -1607,11 +1607,10 @@ Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
   return FileNo;
 }
 
-void MCAsmStreamer::emitDwarfFile0Directive(StringRef Directory,
-                                            StringRef Filename,
-                                            Optional<MD5::MD5Result> Checksum,
-                                            std::optional<StringRef> Source,
-                                            unsigned CUID) {
+void MCAsmStreamer::emitDwarfFile0Directive(
+    StringRef Directory, StringRef Filename,
+    std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
+    unsigned CUID) {
   assert(CUID == 0);
   // .file 0 is new for DWARF v5.
   if (getContext().getDwarfVersion() < 5)
@@ -1889,7 +1888,8 @@ void MCAsmStreamer::EmitRegisterName(int64_t Register) {
     // just ones that map to LLVM register numbers and have known names.
     // Fall back to using the original number directly if no name is known.
     const MCRegisterInfo *MRI = getContext().getRegisterInfo();
-    if (Optional<unsigned> LLVMRegister = MRI->getLLVMRegNum(Register, true)) {
+    if (std::optional<unsigned> LLVMRegister =
+            MRI->getLLVMRegNum(Register, true)) {
       InstPrinter->printRegName(OS, *LLVMRegister);
       return;
     }
@@ -2373,7 +2373,7 @@ void MCAsmStreamer::emitBundleUnlock() {
   EmitEOL();
 }
 
-Optional<std::pair<bool, std::string>>
+std::optional<std::pair<bool, std::string>>
 MCAsmStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
                                   const MCExpr *Expr, SMLoc,
                                   const MCSubtargetInfo &STI) {

diff  --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 773738c8f2827..dc24bd9ca8d01 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -635,12 +635,12 @@ bool MCContext::isELFGenericMergeableSection(StringRef SectionName) {
          ELFSeenGenericMergeableSections.count(SectionName);
 }
 
-Optional<unsigned> MCContext::getELFUniqueIDForEntsize(StringRef SectionName,
-                                                       unsigned Flags,
-                                                       unsigned EntrySize) {
+std::optional<unsigned>
+MCContext::getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags,
+                                    unsigned EntrySize) {
   auto I = ELFEntrySizeMap.find(
       MCContext::ELFEntrySizeKey{SectionName, Flags, EntrySize});
-  return (I != ELFEntrySizeMap.end()) ? Optional<unsigned>(I->second)
+  return (I != ELFEntrySizeMap.end()) ? std::optional<unsigned>(I->second)
                                       : std::nullopt;
 }
 
@@ -771,9 +771,9 @@ bool MCContext::hasXCOFFSection(StringRef Section,
 
 MCSectionXCOFF *MCContext::getXCOFFSection(
     StringRef Section, SectionKind Kind,
-    Optional<XCOFF::CsectProperties> CsectProp, bool MultiSymbolsAllowed,
+    std::optional<XCOFF::CsectProperties> CsectProp, bool MultiSymbolsAllowed,
     const char *BeginSymName,
-    Optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSectionSubtypeFlags) {
+    std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSectionSubtypeFlags) {
   bool IsDwarfSec = DwarfSectionSubtypeFlags.has_value();
   assert((IsDwarfSec != CsectProp.has_value()) && "Invalid XCOFF section!");
 
@@ -932,7 +932,7 @@ EmitDwarfUnwindType MCContext::emitDwarfUnwindInfo() const {
 void MCContext::setGenDwarfRootFile(StringRef InputFileName, StringRef Buffer) {
   // MCDwarf needs the root file as well as the compilation directory.
   // If we find a '.file 0' directive that will supersede these values.
-  Optional<MD5::MD5Result> Cksum;
+  std::optional<MD5::MD5Result> Cksum;
   if (getDwarfVersion() >= 5) {
     MD5 Hash;
     MD5::MD5Result Sum;
@@ -969,12 +969,11 @@ void MCContext::setGenDwarfRootFile(StringRef InputFileName, StringRef Buffer) {
 /// directory tables.  If the file number has already been allocated it is an
 /// error and zero is returned and the client reports the error, else the
 /// allocated file number is returned.  The file numbers may be in any order.
-Expected<unsigned> MCContext::getDwarfFile(StringRef Directory,
-                                           StringRef FileName,
-                                           unsigned FileNumber,
-                                           Optional<MD5::MD5Result> Checksum,
-                                           std::optional<StringRef> Source,
-                                           unsigned CUID) {
+Expected<unsigned>
+MCContext::getDwarfFile(StringRef Directory, StringRef FileName,
+                        unsigned FileNumber,
+                        std::optional<MD5::MD5Result> Checksum,
+                        std::optional<StringRef> Source, unsigned CUID) {
   MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
   return Table.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
                           FileNumber);

diff  --git a/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp b/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
index 2db45a91e0878..e3a0848009770 100644
--- a/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
+++ b/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
@@ -13,7 +13,7 @@ using namespace llvm;
 
 MCDisassembler::~MCDisassembler() = default;
 
-Optional<MCDisassembler::DecodeStatus>
+std::optional<MCDisassembler::DecodeStatus>
 MCDisassembler::onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
                               ArrayRef<uint8_t> Bytes, uint64_t Address,
                               raw_ostream &CStream) const {

diff  --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index c129157657c32..8737af647cda4 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -265,7 +265,7 @@ void MCDwarfLineTable::emit(MCStreamer *MCOS, MCDwarfLineTableParams Params) {
     return;
 
   // In a v5 non-split line table, put the strings in a separate section.
-  Optional<MCDwarfLineStr> LineStr;
+  std::optional<MCDwarfLineStr> LineStr;
   if (context.getDwarfVersion() >= 5)
     LineStr.emplace(context);
 
@@ -285,14 +285,14 @@ void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params,
                                MCSection *Section) const {
   if (!HasSplitLineTable)
     return;
-  Optional<MCDwarfLineStr> NoLineStr(std::nullopt);
+  std::optional<MCDwarfLineStr> NoLineStr(std::nullopt);
   MCOS.switchSection(Section);
   MCOS.emitLabel(Header.Emit(&MCOS, Params, std::nullopt, NoLineStr).second);
 }
 
 std::pair<MCSymbol *, MCSymbol *>
 MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
-                             Optional<MCDwarfLineStr> &LineStr) const {
+                             std::optional<MCDwarfLineStr> &LineStr) const {
   static const char StandardOpcodeLengths[] = {
       0, // length of DW_LNS_copy
       1, // length of DW_LNS_advance_pc
@@ -382,7 +382,7 @@ void MCDwarfLineTableHeader::emitV2FileDirTables(MCStreamer *MCOS) const {
 
 static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,
                                bool EmitMD5, bool HasSource,
-                               Optional<MCDwarfLineStr> &LineStr) {
+                               std::optional<MCDwarfLineStr> &LineStr) {
   assert(!DwarfFile.Name.empty());
   if (LineStr)
     LineStr->emitRef(MCOS, DwarfFile.Name);
@@ -407,7 +407,7 @@ static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,
 }
 
 void MCDwarfLineTableHeader::emitV5FileDirTables(
-    MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr) const {
+    MCStreamer *MCOS, std::optional<MCDwarfLineStr> &LineStr) const {
   // The directory format, which is just a list of the directory paths.  In a
   // non-split object, these are references to .debug_line_str; in a split
   // object, they are inline strings.
@@ -482,7 +482,7 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
 std::pair<MCSymbol *, MCSymbol *>
 MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
                              ArrayRef<char> StandardOpcodeLengths,
-                             Optional<MCDwarfLineStr> &LineStr) const {
+                             std::optional<MCDwarfLineStr> &LineStr) const {
   MCContext &context = MCOS->getContext();
 
   // Create a symbol at the beginning of the line table.
@@ -548,7 +548,7 @@ MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
 }
 
 void MCDwarfLineTable::emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params,
-                              Optional<MCDwarfLineStr> &LineStr) const {
+                              std::optional<MCDwarfLineStr> &LineStr) const {
   MCSymbol *LineEndSym = Header.Emit(MCOS, Params, LineStr).second;
 
   // Put out the line tables.
@@ -560,30 +560,28 @@ void MCDwarfLineTable::emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params,
   MCOS->emitLabel(LineEndSym);
 }
 
-Expected<unsigned> MCDwarfLineTable::tryGetFile(StringRef &Directory,
-                                                StringRef &FileName,
-                                                Optional<MD5::MD5Result> Checksum,
-                                                std::optional<StringRef> Source,
-                                                uint16_t DwarfVersion,
-                                                unsigned FileNumber) {
+Expected<unsigned>
+MCDwarfLineTable::tryGetFile(StringRef &Directory, StringRef &FileName,
+                             std::optional<MD5::MD5Result> Checksum,
+                             std::optional<StringRef> Source,
+                             uint16_t DwarfVersion, unsigned FileNumber) {
   return Header.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
                            FileNumber);
 }
 
 static bool isRootFile(const MCDwarfFile &RootFile, StringRef &Directory,
-                       StringRef &FileName, Optional<MD5::MD5Result> Checksum) {
+                       StringRef &FileName,
+                       std::optional<MD5::MD5Result> Checksum) {
   if (RootFile.Name.empty() || StringRef(RootFile.Name) != FileName)
     return false;
   return RootFile.Checksum == Checksum;
 }
 
 Expected<unsigned>
-MCDwarfLineTableHeader::tryGetFile(StringRef &Directory,
-                                   StringRef &FileName,
-                                   Optional<MD5::MD5Result> Checksum,
+MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, StringRef &FileName,
+                                   std::optional<MD5::MD5Result> Checksum,
                                    std::optional<StringRef> Source,
-                                   uint16_t DwarfVersion,
-                                   unsigned FileNumber) {
+                                   uint16_t DwarfVersion, unsigned FileNumber) {
   if (Directory == CompilationDir)
     Directory = "";
   if (FileName.empty()) {

diff  --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index 962ed989537e9..6e0e80f4f97ae 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -501,7 +501,7 @@ void MCELFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE,
   }
   const MCConstantExpr *MCOffset = MCConstantExpr::create(Offset, getContext());
   MCObjectStreamer::visitUsedExpr(*SRE);
-  if (Optional<std::pair<bool, std::string>> Err =
+  if (std::optional<std::pair<bool, std::string>> Err =
           MCObjectStreamer::emitRelocDirective(
               *MCOffset, "BFD_RELOC_NONE", SRE, SRE->getLoc(),
               *getContext().getSubtargetInfo()))

diff  --git a/llvm/lib/MC/MCInstrAnalysis.cpp b/llvm/lib/MC/MCInstrAnalysis.cpp
index 36133f687b837..cea905d092e0b 100644
--- a/llvm/lib/MC/MCInstrAnalysis.cpp
+++ b/llvm/lib/MC/MCInstrAnalysis.cpp
@@ -30,13 +30,13 @@ bool MCInstrAnalysis::evaluateBranch(const MCInst & /*Inst*/, uint64_t /*Addr*/,
   return false;
 }
 
-Optional<uint64_t> MCInstrAnalysis::evaluateMemoryOperandAddress(
+std::optional<uint64_t> MCInstrAnalysis::evaluateMemoryOperandAddress(
     const MCInst &Inst, const MCSubtargetInfo *STI, uint64_t Addr,
     uint64_t Size) const {
   return std::nullopt;
 }
 
-Optional<uint64_t>
+std::optional<uint64_t>
 MCInstrAnalysis::getMemoryOperandRelocationOffset(const MCInst &Inst,
                                                   uint64_t Size) const {
   return std::nullopt;

diff  --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index d5e8f8a5b6800..d98dfb418be0f 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -149,8 +149,8 @@ void MCObjectStreamer::resolvePendingFixups() {
 
 // As a compile-time optimization, avoid allocating and evaluating an MCExpr
 // tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
-static Optional<uint64_t> absoluteSymbolDiff(const MCSymbol *Hi,
-                                             const MCSymbol *Lo) {
+static std::optional<uint64_t> absoluteSymbolDiff(const MCSymbol *Hi,
+                                                  const MCSymbol *Lo) {
   assert(Hi && Lo);
   if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
       Hi->isVariable() || Lo->isVariable())
@@ -163,7 +163,7 @@ void MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi,
                                               const MCSymbol *Lo,
                                               unsigned Size) {
   if (!getAssembler().getContext().getTargetTriple().isRISCV())
-    if (Optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
+    if (std::optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
       return emitIntValue(*Diff, Size);
   MCStreamer::emitAbsoluteSymbolDiff(Hi, Lo, Size);
 }
@@ -171,7 +171,7 @@ void MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi,
 void MCObjectStreamer::emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
                                                        const MCSymbol *Lo) {
   if (!getAssembler().getContext().getTargetTriple().isRISCV())
-    if (Optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
+    if (std::optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
       return emitULEB128IntValue(*Diff);
   MCStreamer::emitAbsoluteSymbolDiffAsULEB128(Hi, Lo);
 }
@@ -726,7 +726,7 @@ void MCObjectStreamer::emitGPRel64Value(const MCExpr *Value) {
   DF->getContents().resize(DF->getContents().size() + 8, 0);
 }
 
-static Optional<std::pair<bool, std::string>>
+static std::optional<std::pair<bool, std::string>>
 getOffsetAndDataFragment(const MCSymbol &Symbol, uint32_t &RelocOffset,
                          MCDataFragment *&DF) {
   if (Symbol.isVariable()) {
@@ -788,11 +788,12 @@ getOffsetAndDataFragment(const MCSymbol &Symbol, uint32_t &RelocOffset,
   return std::nullopt;
 }
 
-Optional<std::pair<bool, std::string>>
+std::optional<std::pair<bool, std::string>>
 MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
                                      const MCExpr *Expr, SMLoc Loc,
                                      const MCSubtargetInfo &STI) {
-  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
+  std::optional<MCFixupKind> MaybeKind =
+      Assembler->getBackend().getFixupKind(Name);
   if (!MaybeKind)
     return std::make_pair(true, std::string("unknown relocation name"));
 
@@ -824,8 +825,8 @@ MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
   const MCSymbol &Symbol = SRE.getSymbol();
   if (Symbol.isDefined()) {
     uint32_t SymbolOffset = 0;
-    Optional<std::pair<bool, std::string>> Error;
-    Error = getOffsetAndDataFragment(Symbol, SymbolOffset, DF);
+    std::optional<std::pair<bool, std::string>> Error =
+        getOffsetAndDataFragment(Symbol, SymbolOffset, DF);
 
     if (Error != std::nullopt)
       return Error;

diff  --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 767c467f21ad2..d3a6f51e0aa6c 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3183,7 +3183,7 @@ bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
 
   const MCTargetAsmParser &MCT = getTargetParser();
   const MCSubtargetInfo &STI = MCT.getSTI();
-  if (Optional<std::pair<bool, std::string>> Err =
+  if (std::optional<std::pair<bool, std::string>> Err =
           getStreamer().emitRelocDirective(*Offset, Name, Expr, DirectiveLoc,
                                            STI))
     return Error(Err->first ? NameLoc : OffsetLoc, Err->second);
@@ -3583,7 +3583,7 @@ bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
       Ctx.setGenDwarfForAssembly(false);
     }
 
-    Optional<MD5::MD5Result> CKMem;
+    std::optional<MD5::MD5Result> CKMem;
     if (HasMD5) {
       MD5::MD5Result Sum;
       for (unsigned i = 0; i != 8; ++i) {

diff  --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp
index fa419c882534c..032d1f2df4a58 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -848,8 +848,8 @@ class MasmParser : public MCAsmParser {
 
   const MCExpr *evaluateBuiltinValue(BuiltinSymbol Symbol, SMLoc StartLoc);
 
-  llvm::Optional<std::string> evaluateBuiltinTextMacro(BuiltinSymbol Symbol,
-                                                       SMLoc StartLoc);
+  std::optional<std::string> evaluateBuiltinTextMacro(BuiltinSymbol Symbol,
+                                                      SMLoc StartLoc);
 
   // ".ascii", ".asciz", ".string"
   bool parseDirectiveAscii(StringRef IDVal, bool ZeroTerminated);
@@ -1201,7 +1201,7 @@ bool MasmParser::expandMacros() {
     return false;
   }
 
-  llvm::Optional<std::string> ExpandedValue;
+  std::optional<std::string> ExpandedValue;
   auto BuiltinIt = BuiltinSymbolMap.find(IDLower);
   if (BuiltinIt != BuiltinSymbolMap.end()) {
     ExpandedValue =
@@ -3617,7 +3617,7 @@ bool MasmParser::parseTextItem(std::string &Data) {
       // Try to resolve as a built-in text macro
       auto BuiltinIt = BuiltinSymbolMap.find(ID.lower());
       if (BuiltinIt != BuiltinSymbolMap.end()) {
-        llvm::Optional<std::string> BuiltinText =
+        std::optional<std::string> BuiltinText =
             evaluateBuiltinTextMacro(BuiltinIt->getValue(), StartLoc);
         if (!BuiltinText) {
           // Not a text macro; break without substituting
@@ -4888,7 +4888,7 @@ bool MasmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
       Ctx.setGenDwarfForAssembly(false);
     }
 
-    Optional<MD5::MD5Result> CKMem;
+    std::optional<MD5::MD5Result> CKMem;
     if (HasMD5) {
       MD5::MD5Result Sum;
       for (unsigned i = 0; i != 8; ++i) {
@@ -6892,7 +6892,7 @@ bool MasmParser::expandStatement(SMLoc Loc) {
   StringMap<std::string> BuiltinValues;
   for (const auto &S : BuiltinSymbolMap) {
     const BuiltinSymbol &Sym = S.getValue();
-    if (llvm::Optional<std::string> Text = evaluateBuiltinTextMacro(Sym, Loc)) {
+    if (std::optional<std::string> Text = evaluateBuiltinTextMacro(Sym, Loc)) {
       BuiltinValues[S.getKey().lower()] = std::move(*Text);
     }
   }
@@ -7692,7 +7692,7 @@ const MCExpr *MasmParser::evaluateBuiltinValue(BuiltinSymbol Symbol,
   llvm_unreachable("unhandled built-in symbol");
 }
 
-llvm::Optional<std::string>
+std::optional<std::string>
 MasmParser::evaluateBuiltinTextMacro(BuiltinSymbol Symbol, SMLoc StartLoc) {
   switch (Symbol) {
   default:

diff  --git a/llvm/lib/MC/MCRegisterInfo.cpp b/llvm/lib/MC/MCRegisterInfo.cpp
index 91b568f0142ce..9c88e3be97df0 100644
--- a/llvm/lib/MC/MCRegisterInfo.cpp
+++ b/llvm/lib/MC/MCRegisterInfo.cpp
@@ -78,8 +78,8 @@ int MCRegisterInfo::getDwarfRegNum(MCRegister RegNum, bool isEH) const {
   return I->ToReg;
 }
 
-Optional<unsigned> MCRegisterInfo::getLLVMRegNum(unsigned RegNum,
-                                                 bool isEH) const {
+std::optional<unsigned> MCRegisterInfo::getLLVMRegNum(unsigned RegNum,
+                                                      bool isEH) const {
   const DwarfLLVMRegPair *M = isEH ? EHDwarf2LRegs : Dwarf2LRegs;
   unsigned Size = isEH ? EHDwarf2LRegsSize : Dwarf2LRegsSize;
 
@@ -101,7 +101,7 @@ int MCRegisterInfo::getDwarfRegNumFromDwarfEHRegNum(unsigned RegNum) const {
   // a corresponding LLVM register number at all.  So if we can't map the
   // EH register number to an LLVM register number, assume it's just a
   // valid DWARF register number as is.
-  if (Optional<unsigned> LRegNum = getLLVMRegNum(RegNum, true))
+  if (std::optional<unsigned> LRegNum = getLLVMRegNum(RegNum, true))
     return getDwarfRegNum(*LRegNum, false);
   return RegNum;
 }

diff  --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 5f999b3d652c7..385b18ac228c2 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -227,19 +227,17 @@ void llvm::MCStreamer::emitNops(int64_t NumBytes, int64_t ControlledNopLen,
 /// The implementation in this class just redirects to emitFill.
 void MCStreamer::emitZeros(uint64_t NumBytes) { emitFill(NumBytes, 0); }
 
-Expected<unsigned>
-MCStreamer::tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
-                                      StringRef Filename,
-                                      Optional<MD5::MD5Result> Checksum,
-                                      std::optional<StringRef> Source,
-                                      unsigned CUID) {
+Expected<unsigned> MCStreamer::tryEmitDwarfFileDirective(
+    unsigned FileNo, StringRef Directory, StringRef Filename,
+    std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
+    unsigned CUID) {
   return getContext().getDwarfFile(Directory, Filename, FileNo, Checksum,
                                    Source, CUID);
 }
 
 void MCStreamer::emitDwarfFile0Directive(StringRef Directory,
                                          StringRef Filename,
-                                         Optional<MD5::MD5Result> Checksum,
+                                         std::optional<MD5::MD5Result> Checksum,
                                          std::optional<StringRef> Source,
                                          unsigned CUID) {
   getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,

diff  --git a/llvm/lib/MC/MCSubtargetInfo.cpp b/llvm/lib/MC/MCSubtargetInfo.cpp
index 03539e38ab138..fc9826cf2b2ea 100644
--- a/llvm/lib/MC/MCSubtargetInfo.cpp
+++ b/llvm/lib/MC/MCSubtargetInfo.cpp
@@ -345,7 +345,8 @@ MCSubtargetInfo::getCacheAssociativity(unsigned Level) const {
   return std::nullopt;
 }
 
-Optional<unsigned> MCSubtargetInfo::getCacheLineSize(unsigned Level) const {
+std::optional<unsigned>
+MCSubtargetInfo::getCacheLineSize(unsigned Level) const {
   return std::nullopt;
 }
 

diff  --git a/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp b/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
index ee4bf12d8395f..575a2b2f82f28 100644
--- a/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
+++ b/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
@@ -26,7 +26,7 @@ using namespace llvm;
 
 #define MCOPT_EXP(TY, NAME)                                                    \
   MCOPT(TY, NAME)                                                              \
-  Optional<TY> llvm::mc::getExplicit##NAME() {                                 \
+  std::optional<TY> llvm::mc::getExplicit##NAME() {                            \
     if (NAME##View->getNumOccurrences()) {                                     \
       TY res = *NAME##View;                                                    \
       return res;                                                              \

diff  --git a/llvm/lib/MC/MCWin64EH.cpp b/llvm/lib/MC/MCWin64EH.cpp
index d37800a9d704f..dc932a4339a8a 100644
--- a/llvm/lib/MC/MCWin64EH.cpp
+++ b/llvm/lib/MC/MCWin64EH.cpp
@@ -274,9 +274,9 @@ static const MCExpr *GetSubDivExpr(MCStreamer &Streamer, const MCSymbol *LHS,
   return Expr;
 }
 
-static Optional<int64_t> GetOptionalAbsDifference(MCStreamer &Streamer,
-                                                  const MCSymbol *LHS,
-                                                  const MCSymbol *RHS) {
+static std::optional<int64_t> GetOptionalAbsDifference(MCStreamer &Streamer,
+                                                       const MCSymbol *LHS,
+                                                       const MCSymbol *RHS) {
   MCContext &Context = Streamer.getContext();
   const MCExpr *Diff =
       MCBinaryExpr::createSub(MCSymbolRefExpr::create(LHS, Context),
@@ -293,7 +293,8 @@ static Optional<int64_t> GetOptionalAbsDifference(MCStreamer &Streamer,
 
 static int64_t GetAbsDifference(MCStreamer &Streamer, const MCSymbol *LHS,
                                 const MCSymbol *RHS) {
-  Optional<int64_t> MaybeDiff = GetOptionalAbsDifference(Streamer, LHS, RHS);
+  std::optional<int64_t> MaybeDiff =
+      GetOptionalAbsDifference(Streamer, LHS, RHS);
   if (!MaybeDiff)
     report_fatal_error("Failed to evaluate function length in SEH unwind info");
   return *MaybeDiff;
@@ -305,7 +306,7 @@ static void checkARM64Instructions(MCStreamer &Streamer,
                                    StringRef Name, StringRef Type) {
   if (!End)
     return;
-  Optional<int64_t> MaybeDistance =
+  std::optional<int64_t> MaybeDistance =
       GetOptionalAbsDifference(Streamer, End, Begin);
   if (!MaybeDistance)
     return;
@@ -1552,7 +1553,7 @@ static void checkARMInstructions(MCStreamer &Streamer,
                                  StringRef Name, StringRef Type) {
   if (!End)
     return;
-  Optional<int64_t> MaybeDistance =
+  std::optional<int64_t> MaybeDistance =
       GetOptionalAbsDifference(Streamer, End, Begin);
   if (!MaybeDistance)
     return;
@@ -1774,7 +1775,7 @@ static int checkARMPackedEpilog(MCStreamer &streamer, WinEH::FrameInfo *info,
 
   // Check that the epilog actually is at the very end of the function,
   // otherwise it can't be packed.
-  Optional<int64_t> MaybeDistance = GetOptionalAbsDifference(
+  std::optional<int64_t> MaybeDistance = GetOptionalAbsDifference(
       streamer, info->FuncletOrFuncEnd, info->EpilogMap.begin()->first);
   if (!MaybeDistance)
     return -1;
@@ -2000,7 +2001,7 @@ static bool tryARMPackedUnwind(MCStreamer &streamer, WinEH::FrameInfo *info,
     if (EpilogInfo.Condition != 0xe) // ARMCC::AL
       return false;
     const std::vector<WinEH::Instruction> &Epilog = EpilogInfo.Instructions;
-    Optional<int64_t> MaybeDistance = GetOptionalAbsDifference(
+    std::optional<int64_t> MaybeDistance = GetOptionalAbsDifference(
         streamer, info->FuncletOrFuncEnd, info->EpilogMap.begin()->first);
     if (!MaybeDistance)
       return false;
@@ -2310,7 +2311,7 @@ static void ARMEmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info,
                        " not correctly terminated");
   }
 
-  Optional<int64_t> RawFuncLength;
+  std::optional<int64_t> RawFuncLength;
   const MCExpr *FuncLengthExpr = nullptr;
   if (!info->FuncletOrFuncEnd) {
     report_fatal_error("FuncletOrFuncEnd not set");
@@ -2440,7 +2441,7 @@ static void ARMEmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info,
       MCSymbol *EpilogStart = I.first;
       uint32_t EpilogIndex = I.second;
 
-      Optional<int64_t> MaybeEpilogOffset =
+      std::optional<int64_t> MaybeEpilogOffset =
           GetOptionalAbsDifference(streamer, EpilogStart, info->Begin);
       const MCExpr *OffsetExpr = nullptr;
       uint32_t EpilogOffset = 0;

diff  --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
index e796aeb6bfc0c..8eaf528d9ea5c 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
@@ -46,7 +46,7 @@ class AArch64AsmBackend : public MCAsmBackend {
     return AArch64::NumTargetFixupKinds;
   }
 
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
 
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override {
     const static MCFixupKindInfo Infos[AArch64::NumTargetFixupKinds] = {
@@ -330,7 +330,8 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target,
   }
 }
 
-Optional<MCFixupKind> AArch64AsmBackend::getFixupKind(StringRef Name) const {
+std::optional<MCFixupKind>
+AArch64AsmBackend::getFixupKind(StringRef Name) const {
   if (!TheTriple.isOSBinFormatELF())
     return std::nullopt;
 

diff  --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index 089a02ff268b4..89f37568e80c6 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -2210,7 +2210,7 @@ MCDisassembler::DecodeStatus AMDGPUDisassembler::decodeKernelDescriptor(
   return MCDisassembler::Success;
 }
 
-Optional<MCDisassembler::DecodeStatus>
+std::optional<MCDisassembler::DecodeStatus>
 AMDGPUDisassembler::onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
                                   ArrayRef<uint8_t> Bytes, uint64_t Address,
                                   raw_ostream &CStream) const {

diff  --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
index b811d70bc108b..870f7b17df20c 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
@@ -129,10 +129,9 @@ class AMDGPUDisassembler : public MCDisassembler {
     return MCDisassembler::Fail;
   }
 
-  Optional<DecodeStatus> onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
-                                       ArrayRef<uint8_t> Bytes,
-                                       uint64_t Address,
-                                       raw_ostream &CStream) const override;
+  std::optional<DecodeStatus>
+  onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef<uint8_t> Bytes,
+                uint64_t Address, raw_ostream &CStream) const override;
 
   DecodeStatus decodeKernelDescriptor(StringRef KdName, ArrayRef<uint8_t> Bytes,
                                       uint64_t KdAddress) const;

diff  --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
index 79d025e8010f7..f0653aec925d0 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
@@ -50,7 +50,7 @@ class AMDGPUAsmBackend : public MCAsmBackend {
   bool writeNopData(raw_ostream &OS, uint64_t Count,
                     const MCSubtargetInfo *STI) const override;
 
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
                              const MCValue &Target) override;
@@ -162,8 +162,9 @@ void AMDGPUAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
     Data[Offset + i] |= static_cast<uint8_t>((Value >> (i * 8)) & 0xff);
 }
 
-Optional<MCFixupKind> AMDGPUAsmBackend::getFixupKind(StringRef Name) const {
-  return StringSwitch<Optional<MCFixupKind>>(Name)
+std::optional<MCFixupKind>
+AMDGPUAsmBackend::getFixupKind(StringRef Name) const {
+  return StringSwitch<std::optional<MCFixupKind>>(Name)
 #define ELF_RELOC(Name, Value)                                                 \
   .Case(#Name, MCFixupKind(FirstLiteralRelocationKind + Value))
 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"

diff  --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
index 673a00920e813..dfa305a3b968d 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
@@ -47,11 +47,12 @@ class ARMELFObjectWriter : public MCELFObjectTargetWriter {
 };
 } // end anonymous namespace
 
-Optional<MCFixupKind> ARMAsmBackend::getFixupKind(StringRef Name) const {
+std::optional<MCFixupKind> ARMAsmBackend::getFixupKind(StringRef Name) const {
   return std::nullopt;
 }
 
-Optional<MCFixupKind> ARMAsmBackendELF::getFixupKind(StringRef Name) const {
+std::optional<MCFixupKind>
+ARMAsmBackendELF::getFixupKind(StringRef Name) const {
   unsigned Type = llvm::StringSwitch<unsigned>(Name)
 #define ELF_RELOC(X, Y) .Case(#X, Y)
 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"

diff  --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h
index 9b0c8c0841618..a952823d1aad9 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h
@@ -31,7 +31,7 @@ class ARMAsmBackend : public MCAsmBackend {
     return STI->getFeatureBits()[ARM::HasV6T2Ops];
   }
 
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
 
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
 

diff  --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h
index 2431c4865b645..37afdf439e9a0 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h
@@ -28,7 +28,7 @@ class ARMAsmBackendELF : public ARMAsmBackend {
     return createARMELFObjectWriter(OSABI);
   }
 
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
 };
 }
 

diff  --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
index dbaf36e712c6b..d0bf0198d4010 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
@@ -431,15 +431,14 @@ class ARMMCInstrAnalysis : public MCInstrAnalysis {
     return false;
   }
 
-  Optional<uint64_t> evaluateMemoryOperandAddress(const MCInst &Inst,
-                                                  const MCSubtargetInfo *STI,
-                                                  uint64_t Addr,
-                                                  uint64_t Size) const override;
+  std::optional<uint64_t>
+  evaluateMemoryOperandAddress(const MCInst &Inst, const MCSubtargetInfo *STI,
+                               uint64_t Addr, uint64_t Size) const override;
 };
 
 } // namespace
 
-static Optional<uint64_t>
+static std::optional<uint64_t>
 // NOLINTNEXTLINE(readability-identifier-naming)
 evaluateMemOpAddrForAddrMode_i12(const MCInst &Inst, const MCInstrDesc &Desc,
                                  unsigned MemOpIndex, uint64_t Addr) {
@@ -458,10 +457,9 @@ evaluateMemOpAddrForAddrMode_i12(const MCInst &Inst, const MCInstrDesc &Desc,
   return Addr + OffImm;
 }
 
-static Optional<uint64_t> evaluateMemOpAddrForAddrMode3(const MCInst &Inst,
-                                                        const MCInstrDesc &Desc,
-                                                        unsigned MemOpIndex,
-                                                        uint64_t Addr) {
+static std::optional<uint64_t>
+evaluateMemOpAddrForAddrMode3(const MCInst &Inst, const MCInstrDesc &Desc,
+                              unsigned MemOpIndex, uint64_t Addr) {
   if (MemOpIndex + 2 >= Desc.getNumOperands())
     return std::nullopt;
 
@@ -479,10 +477,9 @@ static Optional<uint64_t> evaluateMemOpAddrForAddrMode3(const MCInst &Inst,
   return Addr + ImmOffs;
 }
 
-static Optional<uint64_t> evaluateMemOpAddrForAddrMode5(const MCInst &Inst,
-                                                        const MCInstrDesc &Desc,
-                                                        unsigned MemOpIndex,
-                                                        uint64_t Addr) {
+static std::optional<uint64_t>
+evaluateMemOpAddrForAddrMode5(const MCInst &Inst, const MCInstrDesc &Desc,
+                              unsigned MemOpIndex, uint64_t Addr) {
   if (MemOpIndex + 1 >= Desc.getNumOperands())
     return std::nullopt;
 
@@ -499,7 +496,7 @@ static Optional<uint64_t> evaluateMemOpAddrForAddrMode5(const MCInst &Inst,
   return Addr + ImmOffs * 4;
 }
 
-static Optional<uint64_t>
+static std::optional<uint64_t>
 evaluateMemOpAddrForAddrMode5FP16(const MCInst &Inst, const MCInstrDesc &Desc,
                                   unsigned MemOpIndex, uint64_t Addr) {
   if (MemOpIndex + 1 >= Desc.getNumOperands())
@@ -518,7 +515,7 @@ evaluateMemOpAddrForAddrMode5FP16(const MCInst &Inst, const MCInstrDesc &Desc,
   return Addr + ImmOffs * 2;
 }
 
-static Optional<uint64_t>
+static std::optional<uint64_t>
 // NOLINTNEXTLINE(readability-identifier-naming)
 evaluateMemOpAddrForAddrModeT2_i8s4(const MCInst &Inst, const MCInstrDesc &Desc,
                                     unsigned MemOpIndex, uint64_t Addr) {
@@ -539,7 +536,7 @@ evaluateMemOpAddrForAddrModeT2_i8s4(const MCInst &Inst, const MCInstrDesc &Desc,
   return Addr + OffImm;
 }
 
-static Optional<uint64_t>
+static std::optional<uint64_t>
 // NOLINTNEXTLINE(readability-identifier-naming)
 evaluateMemOpAddrForAddrModeT2_pc(const MCInst &Inst, const MCInstrDesc &Desc,
                                   unsigned MemOpIndex, uint64_t Addr) {
@@ -555,14 +552,14 @@ evaluateMemOpAddrForAddrModeT2_pc(const MCInst &Inst, const MCInstrDesc &Desc,
   return Addr + OffImm;
 }
 
-static Optional<uint64_t>
+static std::optional<uint64_t>
 // NOLINTNEXTLINE(readability-identifier-naming)
 evaluateMemOpAddrForAddrModeT1_s(const MCInst &Inst, const MCInstrDesc &Desc,
                                  unsigned MemOpIndex, uint64_t Addr) {
   return evaluateMemOpAddrForAddrModeT2_pc(Inst, Desc, MemOpIndex, Addr);
 }
 
-Optional<uint64_t> ARMMCInstrAnalysis::evaluateMemoryOperandAddress(
+std::optional<uint64_t> ARMMCInstrAnalysis::evaluateMemoryOperandAddress(
     const MCInst &Inst, const MCSubtargetInfo *STI, uint64_t Addr,
     uint64_t Size) const {
   const MCInstrDesc &Desc = Info->get(Inst.getOpcode());

diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index 33e84fe98497f..0d524b4ecf6d9 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -24,7 +24,8 @@
 
 using namespace llvm;
 
-Optional<MCFixupKind> LoongArchAsmBackend::getFixupKind(StringRef Name) const {
+std::optional<MCFixupKind>
+LoongArchAsmBackend::getFixupKind(StringRef Name) const {
   if (STI.getTargetTriple().isOSBinFormatELF()) {
     auto Type = llvm::StringSwitch<unsigned>(Name)
 #define ELF_RELOC(X, Y) .Case(#X, Y)

diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
index a69f8dcfec38a..0d04cecc45547 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
@@ -51,7 +51,7 @@ class LoongArchAsmBackend : public MCAsmBackend {
     return LoongArch::NumTargetFixupKinds;
   }
 
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
 
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
 

diff  --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
index be577f6cdcd28..71f333d0d0c38 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
@@ -300,7 +300,7 @@ void MipsAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
   }
 }
 
-Optional<MCFixupKind> MipsAsmBackend::getFixupKind(StringRef Name) const {
+std::optional<MCFixupKind> MipsAsmBackend::getFixupKind(StringRef Name) const {
   unsigned Type = llvm::StringSwitch<unsigned>(Name)
                       .Case("BFD_RELOC_NONE", ELF::R_MIPS_NONE)
                       .Case("BFD_RELOC_16", ELF::R_MIPS_16)
@@ -310,7 +310,7 @@ Optional<MCFixupKind> MipsAsmBackend::getFixupKind(StringRef Name) const {
   if (Type != -1u)
     return static_cast<MCFixupKind>(FirstLiteralRelocationKind + Type);
 
-  return StringSwitch<Optional<MCFixupKind>>(Name)
+  return StringSwitch<std::optional<MCFixupKind>>(Name)
       .Case("R_MIPS_NONE", FK_NONE)
       .Case("R_MIPS_32", FK_Data_4)
       .Case("R_MIPS_CALL_HI16", (MCFixupKind)Mips::fixup_Mips_CALL_HI16)

diff  --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h
index 5a0da3bc49bfe..1172a06a3e084 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h
@@ -43,7 +43,7 @@ class MipsAsmBackend : public MCAsmBackend {
                   uint64_t Value, bool IsResolved,
                   const MCSubtargetInfo *STI) const override;
 
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
 
   unsigned getNumFixupKinds() const override {

diff  --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
index ee64bf5addf40..227bd59ba3a64 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
@@ -226,7 +226,7 @@ class ELFPPCAsmBackend : public PPCAsmBackend {
     return createPPCELFObjectWriter(Is64, OSABI);
   }
 
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
 };
 
 class XCOFFPPCAsmBackend : public PPCAsmBackend {
@@ -242,7 +242,8 @@ class XCOFFPPCAsmBackend : public PPCAsmBackend {
 
 } // end anonymous namespace
 
-Optional<MCFixupKind> ELFPPCAsmBackend::getFixupKind(StringRef Name) const {
+std::optional<MCFixupKind>
+ELFPPCAsmBackend::getFixupKind(StringRef Name) const {
   if (TT.isOSBinFormatELF()) {
     unsigned Type;
     if (TT.isPPC64()) {

diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index fe2303d06dee3..150b9e71f1613 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -27,7 +27,7 @@
 
 using namespace llvm;
 
-Optional<MCFixupKind> RISCVAsmBackend::getFixupKind(StringRef Name) const {
+std::optional<MCFixupKind> RISCVAsmBackend::getFixupKind(StringRef Name) const {
   if (STI.getTargetTriple().isOSBinFormatELF()) {
     unsigned Type;
     Type = llvm::StringSwitch<unsigned>(Name)

diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
index 5d62c3a8b0dfc..7e380ab44da41 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
@@ -80,7 +80,7 @@ class RISCVAsmBackend : public MCAsmBackend {
     return RISCV::NumTargetFixupKinds;
   }
 
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
 
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
 

diff  --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
index 721e659d0a8a4..aa89488bbb62a 100644
--- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
+++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
@@ -141,7 +141,7 @@ namespace {
       return Sparc::NumTargetFixupKinds;
     }
 
-    Optional<MCFixupKind> getFixupKind(StringRef Name) const override {
+    std::optional<MCFixupKind> getFixupKind(StringRef Name) const override {
       unsigned Type;
       Type = llvm::StringSwitch<unsigned>(Name)
 #define ELF_RELOC(X, Y) .Case(#X, Y)

diff  --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp
index 3401c4c708a8a..d9f770a399f62 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp
@@ -89,7 +89,7 @@ class SystemZMCAsmBackend : public MCAsmBackend {
   unsigned getNumFixupKinds() const override {
     return SystemZ::NumTargetFixupKinds;
   }
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
                              const MCValue &Target) override;
@@ -111,7 +111,8 @@ class SystemZMCAsmBackend : public MCAsmBackend {
 };
 } // end anonymous namespace
 
-Optional<MCFixupKind> SystemZMCAsmBackend::getFixupKind(StringRef Name) const {
+std::optional<MCFixupKind>
+SystemZMCAsmBackend::getFixupKind(StringRef Name) const {
   unsigned Type = llvm::StringSwitch<unsigned>(Name)
 #define ELF_RELOC(X, Y) .Case(#X, Y)
 #include "llvm/BinaryFormat/ELFRelocs/SystemZ.def"

diff  --git a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
index 87dfeba0648a5..1f07b1619b493 100644
--- a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
+++ b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
@@ -45,10 +45,9 @@ class WebAssemblyDisassembler final : public MCDisassembler {
   DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
                               ArrayRef<uint8_t> Bytes, uint64_t Address,
                               raw_ostream &CStream) const override;
-  Optional<DecodeStatus> onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
-                                       ArrayRef<uint8_t> Bytes,
-                                       uint64_t Address,
-                                       raw_ostream &CStream) const override;
+  std::optional<DecodeStatus>
+  onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef<uint8_t> Bytes,
+                uint64_t Address, raw_ostream &CStream) const override;
 
 public:
   WebAssemblyDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx,
@@ -121,9 +120,11 @@ bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef<uint8_t> Bytes) {
   return true;
 }
 
-Optional<MCDisassembler::DecodeStatus> WebAssemblyDisassembler::onSymbolStart(
-    SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef<uint8_t> Bytes,
-    uint64_t Address, raw_ostream &CStream) const {
+std::optional<MCDisassembler::DecodeStatus>
+WebAssemblyDisassembler::onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
+                                       ArrayRef<uint8_t> Bytes,
+                                       uint64_t Address,
+                                       raw_ostream &CStream) const {
   Size = 0;
   if (Address == 0) {
     // Start of a code section: we're parsing only the function count.

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index bcb6cf1b4e1db..cf7d9ff2024bf 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -272,7 +272,7 @@ MCSymbol *WebAssemblyAsmPrinter::getOrCreateWasmSymbol(StringRef Name) {
 }
 
 void WebAssemblyAsmPrinter::emitSymbolType(const MCSymbolWasm *Sym) {
-  Optional<wasm::WasmSymbolType> WasmTy = Sym->getType();
+  std::optional<wasm::WasmSymbolType> WasmTy = Sym->getType();
   if (!WasmTy)
     return;
 

diff  --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index f8b0471300fb5..67f93ae7bfbee 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -168,7 +168,7 @@ class X86AsmBackend : public MCAsmBackend {
     return X86::NumTargetFixupKinds;
   }
 
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
 
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
 
@@ -587,7 +587,7 @@ void X86AsmBackend::emitInstructionEnd(MCObjectStreamer &OS, const MCInst &Inst)
   Sec->ensureMinAlignment(AlignBoundary);
 }
 
-Optional<MCFixupKind> X86AsmBackend::getFixupKind(StringRef Name) const {
+std::optional<MCFixupKind> X86AsmBackend::getFixupKind(StringRef Name) const {
   if (STI.getTargetTriple().isOSBinFormatELF()) {
     unsigned Type;
     if (STI.getTargetTriple().getArch() == Triple::x86_64) {
@@ -1145,8 +1145,8 @@ class WindowsX86AsmBackend : public X86AsmBackend {
     , Is64Bit(is64Bit) {
   }
 
-  Optional<MCFixupKind> getFixupKind(StringRef Name) const override {
-    return StringSwitch<Optional<MCFixupKind>>(Name)
+  std::optional<MCFixupKind> getFixupKind(StringRef Name) const override {
+    return StringSwitch<std::optional<MCFixupKind>>(Name)
         .Case("dir32", FK_Data_4)
         .Case("secrel32", FK_SecRel_4)
         .Case("secidx", FK_SecRel_2)

diff  --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
index 12d9acc1ebead..63c6f9c11d9b0 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
@@ -506,11 +506,10 @@ class X86MCInstrAnalysis : public MCInstrAnalysis {
 
   bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
                       uint64_t &Target) const override;
-  Optional<uint64_t> evaluateMemoryOperandAddress(const MCInst &Inst,
-                                                  const MCSubtargetInfo *STI,
-                                                  uint64_t Addr,
-                                                  uint64_t Size) const override;
-  Optional<uint64_t>
+  std::optional<uint64_t>
+  evaluateMemoryOperandAddress(const MCInst &Inst, const MCSubtargetInfo *STI,
+                               uint64_t Addr, uint64_t Size) const override;
+  std::optional<uint64_t>
   getMemoryOperandRelocationOffset(const MCInst &Inst,
                                    uint64_t Size) const override;
 };
@@ -637,7 +636,7 @@ bool X86MCInstrAnalysis::evaluateBranch(const MCInst &Inst, uint64_t Addr,
   return true;
 }
 
-Optional<uint64_t> X86MCInstrAnalysis::evaluateMemoryOperandAddress(
+std::optional<uint64_t> X86MCInstrAnalysis::evaluateMemoryOperandAddress(
     const MCInst &Inst, const MCSubtargetInfo *STI, uint64_t Addr,
     uint64_t Size) const {
   const MCInstrDesc &MCID = Info->get(Inst.getOpcode());
@@ -662,7 +661,7 @@ Optional<uint64_t> X86MCInstrAnalysis::evaluateMemoryOperandAddress(
   return std::nullopt;
 }
 
-Optional<uint64_t>
+std::optional<uint64_t>
 X86MCInstrAnalysis::getMemoryOperandRelocationOffset(const MCInst &Inst,
                                                      uint64_t Size) const {
   if (Inst.getOpcode() != X86::LEA64r)

diff  --git a/llvm/tools/llvm-objdump/XCOFFDump.cpp b/llvm/tools/llvm-objdump/XCOFFDump.cpp
index 116953269128d..3b1d3e0bb7532 100644
--- a/llvm/tools/llvm-objdump/XCOFFDump.cpp
+++ b/llvm/tools/llvm-objdump/XCOFFDump.cpp
@@ -43,7 +43,7 @@ Error objdump::getXCOFFRelocationValueString(const XCOFFObjectFile &Obj,
   return Error::success();
 }
 
-Optional<XCOFF::StorageMappingClass>
+std::optional<XCOFF::StorageMappingClass>
 objdump::getXCOFFSymbolCsectSMC(const XCOFFObjectFile &Obj,
                                 const SymbolRef &Sym) {
   const XCOFFSymbolRef SymRef = Obj.toSymbolRef(Sym.getRawDataRefImpl());
@@ -58,7 +58,7 @@ objdump::getXCOFFSymbolCsectSMC(const XCOFFObjectFile &Obj,
   return CsectAuxEntOrErr.get().getStorageMappingClass();
 }
 
-Optional<object::SymbolRef>
+std::optional<object::SymbolRef>
 objdump::getXCOFFSymbolContainingSymbolRef(const XCOFFObjectFile &Obj,
                                            const SymbolRef &Sym) {
   const XCOFFSymbolRef SymRef = Obj.toSymbolRef(Sym.getRawDataRefImpl());

diff  --git a/llvm/tools/llvm-objdump/XCOFFDump.h b/llvm/tools/llvm-objdump/XCOFFDump.h
index 4616059409463..35d1c0f1ebbe5 100644
--- a/llvm/tools/llvm-objdump/XCOFFDump.h
+++ b/llvm/tools/llvm-objdump/XCOFFDump.h
@@ -16,11 +16,11 @@ namespace llvm {
 struct SymbolInfoTy;
 
 namespace objdump {
-Optional<XCOFF::StorageMappingClass>
+std::optional<XCOFF::StorageMappingClass>
 getXCOFFSymbolCsectSMC(const object::XCOFFObjectFile &Obj,
                        const object::SymbolRef &Sym);
 
-Optional<object::SymbolRef>
+std::optional<object::SymbolRef>
 getXCOFFSymbolContainingSymbolRef(const object::XCOFFObjectFile &Obj,
                                   const object::SymbolRef &Sym);
 

diff  --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index e15054d88bcab..565e2325a8786 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -863,7 +863,7 @@ addDynamicElfSymbols(const ELFObjectFileBase &Obj,
     llvm_unreachable("Unsupported binary format");
 }
 
-static Optional<SectionRef> getWasmCodeSection(const WasmObjectFile &Obj) {
+static std::optional<SectionRef> getWasmCodeSection(const WasmObjectFile &Obj) {
   for (auto SecI : Obj.sections()) {
     const WasmSection &Section = Obj.getWasmSection(SecI);
     if (Section.Type == wasm::WASM_SEC_CODE)
@@ -875,7 +875,7 @@ static Optional<SectionRef> getWasmCodeSection(const WasmObjectFile &Obj) {
 static void
 addMissingWasmCodeSymbols(const WasmObjectFile &Obj,
                           std::map<SectionRef, SectionSymbolsTy> &AllSymbols) {
-  Optional<SectionRef> Section = getWasmCodeSection(Obj);
+  std::optional<SectionRef> Section = getWasmCodeSection(Obj);
   if (!Section)
     return;
   SectionSymbolsTy &Symbols = AllSymbols[*Section];
@@ -1084,7 +1084,7 @@ SymbolInfoTy objdump::createSymbolInfo(const ObjectFile &Obj,
     DataRefImpl SymbolDRI = Symbol.getRawDataRefImpl();
 
     const uint32_t SymbolIndex = XCOFFObj.getSymbolIndex(SymbolDRI.p);
-    Optional<XCOFF::StorageMappingClass> Smc =
+    std::optional<XCOFF::StorageMappingClass> Smc =
         getXCOFFSymbolCsectSMC(XCOFFObj, Symbol);
     return SymbolInfoTy(Addr, Name, Smc, SymbolIndex,
                         isLabel(XCOFFObj, Symbol));
@@ -1823,7 +1823,7 @@ static void disassembleObject(const Target *TheTarget, ObjectFile &Obj,
             bool PrintTarget =
                 MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target);
             if (!PrintTarget)
-              if (Optional<uint64_t> MaybeTarget =
+              if (std::optional<uint64_t> MaybeTarget =
                       MIA->evaluateMemoryOperandAddress(
                           Inst, STI, SectionAddr + Index, Size)) {
                 Target = *MaybeTarget;
@@ -2480,7 +2480,7 @@ void objdump::printSymbol(const ObjectFile &O, const SymbolRef &Symbol,
     StringRef SectionName = unwrapOrError(Section->getName(), FileName);
     outs() << SectionName;
     if (O.isXCOFF()) {
-      Optional<SymbolRef> SymRef =
+      std::optional<SymbolRef> SymRef =
           getXCOFFSymbolContainingSymbolRef(cast<XCOFFObjectFile>(O), Symbol);
       if (SymRef) {
 

diff  --git a/llvm/unittests/MC/DwarfLineTableHeaders.cpp b/llvm/unittests/MC/DwarfLineTableHeaders.cpp
index 7dab9df0ef08b..f45ad7229c176 100644
--- a/llvm/unittests/MC/DwarfLineTableHeaders.cpp
+++ b/llvm/unittests/MC/DwarfLineTableHeaders.cpp
@@ -118,7 +118,7 @@ class DwarfLineTableHeaders : public ::testing::Test {
     TheStreamer->switchSection(C.MOFI->getDwarfLineSection());
     MCDwarfLineTableHeader Header;
     MCDwarfLineTableParams Params = Assembler.getDWARFLinetableParams();
-    Optional<MCDwarfLineStr> LineStr(std::nullopt);
+    std::optional<MCDwarfLineStr> LineStr(std::nullopt);
     if (Ctx.getDwarfVersion() >= 5) {
       LineStr.emplace(Ctx);
       Header.setRootFile("dir", "file", std::nullopt, std::nullopt);


        


More information about the llvm-commits mailing list