From: Fangrui Song Date: Sun, 4 Dec 2022 21:36:08 +0000 (+0000) Subject: [MC] llvm::Optional => std::optional X-Git-Tag: upstream/17.0.6~25383 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f4c16c44737caac25bf09ec2d85809820579ae40;p=platform%2Fupstream%2Fllvm.git [MC] llvm::Optional => std::optional https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 --- diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h index d286ba4..f36c5e8 100644 --- a/bolt/include/bolt/Core/BinaryContext.h +++ b/bolt/include/bolt/Core/BinaryContext.h @@ -283,7 +283,7 @@ public: Expected getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, - Optional Checksum, + std::optional Checksum, std::optional Source, unsigned CUID, unsigned DWARFVersion); diff --git a/bolt/include/bolt/Core/DebugData.h b/bolt/include/bolt/Core/DebugData.h index 5485016..5be678c 100644 --- a/bolt/include/bolt/Core/DebugData.h +++ b/bolt/include/bolt/Core/DebugData.h @@ -1130,10 +1130,10 @@ public: /// Emit the Dwarf file and the line tables for a given CU. void emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params, - Optional &LineStr, BinaryContext &BC) const; + std::optional &LineStr, BinaryContext &BC) const; Expected tryGetFile(StringRef &Directory, StringRef &FileName, - Optional Checksum, + std::optional Checksum, std::optional Source, uint16_t DwarfVersion, unsigned FileNumber = 0) { @@ -1150,7 +1150,7 @@ public: /// Sets the root file \p Directory, \p FileName, optional \p CheckSum, and /// optional \p Source. void setRootFile(StringRef Directory, StringRef FileName, - Optional Checksum, + std::optional Checksum, std::optional Source) { Header.setRootFile(Directory, FileName, Checksum, Source); } diff --git a/bolt/include/bolt/Core/MCPlus.h b/bolt/include/bolt/Core/MCPlus.h index b4a72ac..e3ddb19 100644 --- a/bolt/include/bolt/Core/MCPlus.h +++ b/bolt/include/bolt/Core/MCPlus.h @@ -21,6 +21,17 @@ #include namespace llvm { + +template () + << std::declval())> +raw_ostream &operator<<(raw_ostream &OS, const std::optional &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 280e121..8f2bc4c 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 BinaryContext::getDwarfFile( StringRef Directory, StringRef FileName, unsigned FileNumber, - Optional Checksum, std::optional Source, + std::optional Checksum, std::optional 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 Checksum; + std::optional Checksum; if (LineTable->Prologue.ContentTypes.HasMD5) Checksum = LineTable->Prologue.FileNames[0].Checksum; Optional Name = @@ -1683,7 +1683,7 @@ void BinaryContext::preprocessDebugInfo() { if (Optional FName = dwarf::toString(FileNames[I].Name)) FileName = *FName; assert(FileName != ""); - Optional Checksum; + std::optional 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 80a96a0..6d39353 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 &LineStr, + std::optional &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 LineStr(std::nullopt); + std::optional LineStr; ErrorOr 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 a5e7b3f..9ce4dbf 100644 --- a/llvm/include/llvm/MC/MCAsmBackend.h +++ b/llvm/include/llvm/MC/MCAsmBackend.h @@ -89,7 +89,7 @@ public: virtual unsigned getNumFixupKinds() const = 0; /// Map a relocation name used in .reloc to a fixup kind. - virtual Optional getFixupKind(StringRef Name) const; + virtual std::optional 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 4fb273f..8e06854 100644 --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -616,9 +616,9 @@ public: /// Return the unique ID of the section with the given name, flags and entry /// size, if it exists. - Optional getELFUniqueIDForEntsize(StringRef SectionName, - unsigned Flags, - unsigned EntrySize); + std::optional getELFUniqueIDForEntsize(StringRef SectionName, + unsigned Flags, + unsigned EntrySize); MCSectionGOFF *getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, const MCExpr *SubsectionId); @@ -673,13 +673,12 @@ public: bool hasXCOFFSection(StringRef Section, XCOFF::CsectProperties CsectProp) const; - MCSectionXCOFF * - getXCOFFSection(StringRef Section, SectionKind K, - Optional CsectProp = std::nullopt, - bool MultiSymbolsAllowed = false, - const char *BeginSymName = nullptr, - Optional DwarfSubtypeFlags = - std::nullopt); + MCSectionXCOFF *getXCOFFSection( + StringRef Section, SectionKind K, + std::optional CsectProp = std::nullopt, + bool MultiSymbolsAllowed = false, const char *BeginSymName = nullptr, + std::optional 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 @@ public: void setMainFileName(StringRef S) { MainFileName = std::string(S); } /// Creates an entry in the dwarf file and directory tables. - Expected getDwarfFile( - StringRef Directory, StringRef FileName, unsigned FileNumber, - Optional Checksum, std::optional Source, - unsigned CUID); + Expected getDwarfFile(StringRef Directory, StringRef FileName, + unsigned FileNumber, + std::optional Checksum, + std::optional Source, + unsigned CUID); bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0); @@ -754,7 +754,7 @@ public: /// These are "file 0" and "directory 0" in DWARF v5. void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir, StringRef Filename, - Optional Checksum, + std::optional Checksum, std::optional 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 ebe81fd..82a1847 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 StorageMappingClass; - Optional Index; + std::optional StorageMappingClass; + std::optional Index; bool IsLabel; - XCOFFSymbolInfo(Optional Smc, - Optional Idx, bool Label) + XCOFFSymbolInfo(std::optional Smc, + std::optional Idx, bool Label) : StorageMappingClass(Smc), Index(Idx), IsLabel(Label) {} bool operator<(const XCOFFSymbolInfo &SymInfo) const; @@ -44,8 +44,8 @@ private: public: SymbolInfoTy(uint64_t Addr, StringRef Name, - Optional Smc, Optional Idx, - bool Label) + std::optional Smc, + std::optional 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 @@ public: /// 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 + virtual std::optional onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef 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 e576dab..d9c88c5 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 Checksum; + std::optional Checksum; /// The source code of the file. Non-owning reference to data allocated in /// MCContext. @@ -271,17 +271,16 @@ public: MCDwarfLineTableHeader() = default; Expected tryGetFile(StringRef &Directory, StringRef &FileName, - Optional Checksum, + std::optional Checksum, std::optional Source, - uint16_t DwarfVersion, - unsigned FileNumber = 0); + uint16_t DwarfVersion, unsigned FileNumber = 0); std::pair Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, - Optional &LineStr) const; + std::optional &LineStr) const; std::pair Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, ArrayRef SpecialOpcodeLengths, - Optional &LineStr) const; + std::optional &LineStr) const; void resetMD5Usage() { HasAllMD5 = true; HasAnyMD5 = false; @@ -295,7 +294,7 @@ public: } void setRootFile(StringRef Directory, StringRef FileName, - Optional Checksum, + std::optional Checksum, std::optional Source) { CompilationDir = std::string(Directory); RootFile.Name = std::string(FileName); @@ -316,7 +315,8 @@ public: private: void emitV2FileDirTables(MCStreamer *MCOS) const; - void emitV5FileDirTables(MCStreamer *MCOS, Optional &LineStr) const; + void emitV5FileDirTables(MCStreamer *MCOS, + std::optional &LineStr) const; }; class MCDwarfDwoLineTable { @@ -325,7 +325,7 @@ class MCDwarfDwoLineTable { public: void maybeSetRootFile(StringRef Directory, StringRef FileName, - Optional Checksum, + std::optional Checksum, std::optional Source) { if (!Header.RootFile.Name.empty()) return; @@ -333,8 +333,8 @@ public: } unsigned getFile(StringRef Directory, StringRef FileName, - Optional Checksum, uint16_t DwarfVersion, - std::optional Source) { + std::optional Checksum, + uint16_t DwarfVersion, std::optional Source) { HasSplitLineTable = true; return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion)); @@ -354,7 +354,7 @@ public: // This emits the Dwarf file and the line tables for a given Compile Unit. void emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params, - Optional &LineStr) const; + std::optional &LineStr) const; // This emits a single line table associated with a given Section. static void @@ -362,12 +362,11 @@ public: const MCLineSection::MCDwarfLineEntryCollection &LineEntries); Expected tryGetFile(StringRef &Directory, StringRef &FileName, - Optional Checksum, + std::optional Checksum, std::optional Source, - uint16_t DwarfVersion, - unsigned FileNumber = 0); + uint16_t DwarfVersion, unsigned FileNumber = 0); unsigned getFile(StringRef &Directory, StringRef &FileName, - Optional Checksum, + std::optional Checksum, std::optional Source, uint16_t DwarfVersion, unsigned FileNumber = 0) { return cantFail(tryGetFile(Directory, FileName, Checksum, Source, @@ -375,7 +374,7 @@ public: } void setRootFile(StringRef Directory, StringRef FileName, - Optional Checksum, + std::optional Checksum, std::optional 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 a937f82..61c443f 100644 --- a/llvm/include/llvm/MC/MCInstrAnalysis.h +++ b/llvm/include/llvm/MC/MCInstrAnalysis.h @@ -157,13 +157,13 @@ public: /// Given an instruction tries to get the address of a memory operand. Returns /// the address on success. - virtual Optional + virtual std::optional 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 + virtual std::optional 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 2ac18a2..ce200a4 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 +#include namespace llvm { class MCContext; @@ -451,7 +451,7 @@ private: bool PositionIndependent = false; MCContext *Ctx = nullptr; VersionTuple SDKVersion; - Optional DarwinTargetVariantTriple; + std::optional 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 fbc54c6..52ddaf3 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -191,7 +191,7 @@ public: void emitTPRel64Value(const MCExpr *Value) override; void emitGPRel32Value(const MCExpr *Value) override; void emitGPRel64Value(const MCExpr *Value) override; - Optional> + std::optional> 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 7165a29..40095c1 100644 --- a/llvm/include/llvm/MC/MCRegisterInfo.h +++ b/llvm/include/llvm/MC/MCRegisterInfo.h @@ -514,7 +514,7 @@ public: /// Map a dwarf register back to a target register. Returns None is there is /// no mapping. - Optional getLLVMRegNum(unsigned RegNum, bool isEH) const; + std::optional 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 b6b6dbf..68832f5 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 CsectProp; + std::optional CsectProp; MCSymbolXCOFF *const QualName; StringRef SymbolTableName; - Optional DwarfSubtypeFlags; + std::optional DwarfSubtypeFlags; bool MultiSymbolsAllowed; static constexpr unsigned DefaultAlignVal = 4; static constexpr unsigned DefaultTextAlignVal = 32; @@ -118,10 +118,12 @@ public: bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; } bool isCsect() const { return CsectProp.has_value(); } bool isDwarfSect() const { return DwarfSubtypeFlags.has_value(); } - Optional getDwarfSubtypeFlags() const { + std::optional getDwarfSubtypeFlags() const { return DwarfSubtypeFlags; } - Optional getCsectProp() const { return CsectProp; } + std::optional getCsectProp() const { + return CsectProp; + } }; } // end namespace llvm diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index 5edae19..bdab8e3 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -908,7 +908,7 @@ public: /// implements the DWARF2 '.file 4 "foo.c"' assembler directive. unsigned emitDwarfFileDirective( unsigned FileNo, StringRef Directory, StringRef Filename, - Optional Checksum = std::nullopt, + std::optional Checksum = std::nullopt, std::optional Source = std::nullopt, unsigned CUID = 0) { return cantFail( tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum, @@ -922,12 +922,12 @@ public: /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive. virtual Expected tryEmitDwarfFileDirective( unsigned FileNo, StringRef Directory, StringRef Filename, - Optional Checksum = std::nullopt, + std::optional Checksum = std::nullopt, std::optional 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 Checksum, + std::optional Checksum, std::optional Source, unsigned CUID = 0); @@ -1086,7 +1086,7 @@ public: /// Record a relocation described by the .reloc directive. Return None if /// succeeded. Otherwise, return a pair (Name is invalid, error message). - virtual Optional> + virtual std::optional> 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 6cf4dd5..815b0b7 100644 --- a/llvm/include/llvm/MC/MCSubtargetInfo.h +++ b/llvm/include/llvm/MC/MCSubtargetInfo.h @@ -247,7 +247,7 @@ public: /// Return the target cache line size in bytes at a given level. /// - virtual Optional getCacheLineSize(unsigned Level) const; + virtual std::optional 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 @@ public: /// cache model. /// virtual unsigned getCacheLineSize() const { - Optional Size = getCacheLineSize(0); + std::optional Size = getCacheLineSize(0); if (Size) return *Size; diff --git a/llvm/include/llvm/MC/MCSymbolWasm.h b/llvm/include/llvm/MC/MCSymbolWasm.h index 33ec0db..66f0e3a 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 Type; + std::optional Type; bool IsWeak = false; bool IsHidden = false; bool IsComdat = false; bool OmitFromLinkingSection = false; mutable bool IsUsedInInitArray = false; mutable bool IsUsedInGOT = false; - Optional ImportModule; - Optional ImportName; - Optional ExportName; + std::optional ImportModule; + std::optional ImportName; + std::optional ExportName; wasm::WasmSignature *Signature = nullptr; - Optional GlobalType; - Optional TableType; + std::optional GlobalType; + std::optional 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 @@ public: bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; } bool isTag() const { return Type == wasm::WASM_SYMBOL_TYPE_TAG; } - Optional getType() const { return Type; } + std::optional 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 cc19f88..bb68e6a 100644 --- a/llvm/include/llvm/MC/MCSymbolXCOFF.h +++ b/llvm/include/llvm/MC/MCSymbolXCOFF.h @@ -64,7 +64,7 @@ public: } private: - Optional StorageClass; + std::optional 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 0213b54..7333e8a 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 getExplicitRelaxAll(); +std::optional getExplicitRelaxAll(); bool getIncrementalLinkerCompatible(); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 9629a5b..a6580b7 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 DwarfDebug::getMD5AsBytes(const DIFile *File) const { +std::optional +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 31e4081..9245ac9 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -839,7 +839,7 @@ public: /// If the \p File has an MD5 checksum, return it as an MD5Result /// allocated in the MCContext. - Optional getMD5AsBytes(const DIFile *File) const; + std::optional getMD5AsBytes(const DIFile *File) const; }; } // end namespace llvm diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp index bc2a7a8..bb2d1da 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 Reg = TRI->getLLVMRegNum(DwarfReg, true)) + if (std::optional Reg = TRI->getLLVMRegNum(DwarfReg, true)) OS << printReg(*Reg, TRI); else OS << ""; diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp index 2d3b14a..e9b657ea 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 LLVMRegNum = MRI->getLLVMRegNum(RegNum, IsEH)) { + if (std::optional 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 17b180f..b9d5ddd 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 LLVMRegNum = MRI->getLLVMRegNum(DwarfRegNum, isEH)) { + if (std::optional 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 LLVMRegNum = MRI.getLLVMRegNum(DwarfRegNum, false); + std::optional LLVMRegNum = + MRI.getLLVMRegNum(DwarfRegNum, false); if (!LLVMRegNum) { OS << ""; 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 LLVMRegNum = MRI.getLLVMRegNum(DwarfRegNum, false); + std::optional LLVMRegNum = + MRI.getLLVMRegNum(DwarfRegNum, false); if (!LLVMRegNum) { OS << ""; return false; @@ -463,7 +466,8 @@ static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I, // DW_OP_reg: 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 LLVMRegNum = MRI.getLLVMRegNum(DwarfRegNum, false); + std::optional LLVMRegNum = + MRI.getLLVMRegNum(DwarfRegNum, false); if (!LLVMRegNum) { OS << ""; 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 LLVMRegNum = MRI.getLLVMRegNum(DwarfRegNum, false); + std::optional LLVMRegNum = + MRI.getLLVMRegNum(DwarfRegNum, false); if (!LLVMRegNum) { OS << ""; return false; diff --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp index d4d5662..8c638c0 100644 --- a/llvm/lib/MC/MCAsmBackend.cpp +++ b/llvm/lib/MC/MCAsmBackend.cpp @@ -74,7 +74,7 @@ MCAsmBackend::createDwoObjectWriter(raw_pwrite_stream &OS, } } -Optional MCAsmBackend::getFixupKind(StringRef Name) const { +std::optional MCAsmBackend::getFixupKind(StringRef Name) const { return std::nullopt; } diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index 469d897..eab51f0 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 Checksum, + std::optional Checksum, std::optional Source, bool UseDwarfDirectory, raw_svector_ostream &OS) const; @@ -250,8 +250,9 @@ public: void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr, SMLoc Loc = SMLoc()) override; - void emitAlignmentDirective(unsigned ByteAlignment, Optional Value, - unsigned ValueSize, unsigned MaxBytesToEmit); + void emitAlignmentDirective(unsigned ByteAlignment, + std::optional Value, unsigned ValueSize, + unsigned MaxBytesToEmit); void emitValueToAlignment(Align Alignment, int64_t Value = 0, unsigned ValueSize = 1, @@ -267,14 +268,13 @@ public: void emitFileDirective(StringRef Filename) override; void emitFileDirective(StringRef Filename, StringRef CompilerVerion, StringRef TimeStamp, StringRef Description) override; - Expected - tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory, - StringRef Filename, - Optional Checksum = std::nullopt, - std::optional Source = std::nullopt, - unsigned CUID = 0) override; + Expected tryEmitDwarfFileDirective( + unsigned FileNo, StringRef Directory, StringRef Filename, + std::optional Checksum = std::nullopt, + std::optional Source = std::nullopt, + unsigned CUID = 0) override; void emitDwarfFile0Directive(StringRef Directory, StringRef Filename, - Optional Checksum, + std::optional Checksum, std::optional Source, unsigned CUID = 0) override; void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, @@ -385,7 +385,7 @@ public: void emitBundleLock(bool AlignToEnd) override; void emitBundleUnlock() override; - Optional> + std::optional> 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 Value, + std::optional 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 Checksum, std::optional Source, + std::optional Checksum, std::optional Source, bool UseDwarfDirectory, raw_svector_ostream &OS) const { SmallString<128> FullPathName; @@ -1575,7 +1575,7 @@ void MCAsmStreamer::printDwarfFileDirective( Expected MCAsmStreamer::tryEmitDwarfFileDirective( unsigned FileNo, StringRef Directory, StringRef Filename, - Optional Checksum, std::optional Source, + std::optional Checksum, std::optional Source, unsigned CUID) { assert(CUID == 0 && "multiple CUs not supported by MCAsmStreamer"); @@ -1607,11 +1607,10 @@ Expected MCAsmStreamer::tryEmitDwarfFileDirective( return FileNo; } -void MCAsmStreamer::emitDwarfFile0Directive(StringRef Directory, - StringRef Filename, - Optional Checksum, - std::optional Source, - unsigned CUID) { +void MCAsmStreamer::emitDwarfFile0Directive( + StringRef Directory, StringRef Filename, + std::optional Checksum, std::optional 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 LLVMRegister = MRI->getLLVMRegNum(Register, true)) { + if (std::optional LLVMRegister = + MRI->getLLVMRegNum(Register, true)) { InstPrinter->printRegName(OS, *LLVMRegister); return; } @@ -2373,7 +2373,7 @@ void MCAsmStreamer::emitBundleUnlock() { EmitEOL(); } -Optional> +std::optional> 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 773738c..dc24bd9 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 MCContext::getELFUniqueIDForEntsize(StringRef SectionName, - unsigned Flags, - unsigned EntrySize) { +std::optional +MCContext::getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags, + unsigned EntrySize) { auto I = ELFEntrySizeMap.find( MCContext::ELFEntrySizeKey{SectionName, Flags, EntrySize}); - return (I != ELFEntrySizeMap.end()) ? Optional(I->second) + return (I != ELFEntrySizeMap.end()) ? std::optional(I->second) : std::nullopt; } @@ -771,9 +771,9 @@ bool MCContext::hasXCOFFSection(StringRef Section, MCSectionXCOFF *MCContext::getXCOFFSection( StringRef Section, SectionKind Kind, - Optional CsectProp, bool MultiSymbolsAllowed, + std::optional CsectProp, bool MultiSymbolsAllowed, const char *BeginSymName, - Optional DwarfSectionSubtypeFlags) { + std::optional 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 Cksum; + std::optional 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 MCContext::getDwarfFile(StringRef Directory, - StringRef FileName, - unsigned FileNumber, - Optional Checksum, - std::optional Source, - unsigned CUID) { +Expected +MCContext::getDwarfFile(StringRef Directory, StringRef FileName, + unsigned FileNumber, + std::optional Checksum, + std::optional 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 2db45a9..e3a0848 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 +std::optional MCDisassembler::onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef Bytes, uint64_t Address, raw_ostream &CStream) const { diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp index c129157..8737af6 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 LineStr; + std::optional 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 NoLineStr(std::nullopt); + std::optional NoLineStr(std::nullopt); MCOS.switchSection(Section); MCOS.emitLabel(Header.Emit(&MCOS, Params, std::nullopt, NoLineStr).second); } std::pair MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, - Optional &LineStr) const { + std::optional &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 &LineStr) { + std::optional &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 &LineStr) const { + MCStreamer *MCOS, std::optional &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 MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, ArrayRef StandardOpcodeLengths, - Optional &LineStr) const { + std::optional &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 &LineStr) const { + std::optional &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 MCDwarfLineTable::tryGetFile(StringRef &Directory, - StringRef &FileName, - Optional Checksum, - std::optional Source, - uint16_t DwarfVersion, - unsigned FileNumber) { +Expected +MCDwarfLineTable::tryGetFile(StringRef &Directory, StringRef &FileName, + std::optional Checksum, + std::optional 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 Checksum) { + StringRef &FileName, + std::optional Checksum) { if (RootFile.Name.empty() || StringRef(RootFile.Name) != FileName) return false; return RootFile.Checksum == Checksum; } Expected -MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, - StringRef &FileName, - Optional Checksum, +MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, StringRef &FileName, + std::optional Checksum, std::optional 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 962ed98..6e0e80f 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> Err = + if (std::optional> 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 36133f6..cea905d 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 MCInstrAnalysis::evaluateMemoryOperandAddress( +std::optional MCInstrAnalysis::evaluateMemoryOperandAddress( const MCInst &Inst, const MCSubtargetInfo *STI, uint64_t Addr, uint64_t Size) const { return std::nullopt; } -Optional +std::optional 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 d5e8f8a..d98dfb4 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 absoluteSymbolDiff(const MCSymbol *Hi, - const MCSymbol *Lo) { +static std::optional 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 Diff = absoluteSymbolDiff(Hi, Lo)) + if (std::optional 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 Diff = absoluteSymbolDiff(Hi, Lo)) + if (std::optional 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> +static std::optional> 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::optional> MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc, const MCSubtargetInfo &STI) { - Optional MaybeKind = Assembler->getBackend().getFixupKind(Name); + std::optional 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> Error; - Error = getOffsetAndDataFragment(Symbol, SymbolOffset, DF); + std::optional> 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 767c467..d3a6f51 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> Err = + if (std::optional> 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 CKMem; + std::optional 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 fa419c8..032d1f2 100644 --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -848,8 +848,8 @@ private: const MCExpr *evaluateBuiltinValue(BuiltinSymbol Symbol, SMLoc StartLoc); - llvm::Optional evaluateBuiltinTextMacro(BuiltinSymbol Symbol, - SMLoc StartLoc); + std::optional 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 ExpandedValue; + std::optional 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 BuiltinText = + std::optional 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 CKMem; + std::optional CKMem; if (HasMD5) { MD5::MD5Result Sum; for (unsigned i = 0; i != 8; ++i) { @@ -6892,7 +6892,7 @@ bool MasmParser::expandStatement(SMLoc Loc) { StringMap BuiltinValues; for (const auto &S : BuiltinSymbolMap) { const BuiltinSymbol &Sym = S.getValue(); - if (llvm::Optional Text = evaluateBuiltinTextMacro(Sym, Loc)) { + if (std::optional 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::optional MasmParser::evaluateBuiltinTextMacro(BuiltinSymbol Symbol, SMLoc StartLoc) { switch (Symbol) { default: diff --git a/llvm/lib/MC/MCRegisterInfo.cpp b/llvm/lib/MC/MCRegisterInfo.cpp index 91b568f..9c88e3b 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 MCRegisterInfo::getLLVMRegNum(unsigned RegNum, - bool isEH) const { +std::optional 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 LRegNum = getLLVMRegNum(RegNum, true)) + if (std::optional 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 5f999b3..385b18a 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 -MCStreamer::tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory, - StringRef Filename, - Optional Checksum, - std::optional Source, - unsigned CUID) { +Expected MCStreamer::tryEmitDwarfFileDirective( + unsigned FileNo, StringRef Directory, StringRef Filename, + std::optional Checksum, std::optional Source, + unsigned CUID) { return getContext().getDwarfFile(Directory, Filename, FileNo, Checksum, Source, CUID); } void MCStreamer::emitDwarfFile0Directive(StringRef Directory, StringRef Filename, - Optional Checksum, + std::optional Checksum, std::optional Source, unsigned CUID) { getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum, diff --git a/llvm/lib/MC/MCSubtargetInfo.cpp b/llvm/lib/MC/MCSubtargetInfo.cpp index 03539e3..fc9826c 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 MCSubtargetInfo::getCacheLineSize(unsigned Level) const { +std::optional +MCSubtargetInfo::getCacheLineSize(unsigned Level) const { return std::nullopt; } diff --git a/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp b/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp index ee4bf12..575a2b2 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 llvm::mc::getExplicit##NAME() { \ + std::optional 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 d37800a..dc932a4 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 GetOptionalAbsDifference(MCStreamer &Streamer, - const MCSymbol *LHS, - const MCSymbol *RHS) { +static std::optional 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 GetOptionalAbsDifference(MCStreamer &Streamer, static int64_t GetAbsDifference(MCStreamer &Streamer, const MCSymbol *LHS, const MCSymbol *RHS) { - Optional MaybeDiff = GetOptionalAbsDifference(Streamer, LHS, RHS); + std::optional 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 MaybeDistance = + std::optional 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 MaybeDistance = + std::optional 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 MaybeDistance = GetOptionalAbsDifference( + std::optional 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 &Epilog = EpilogInfo.Instructions; - Optional MaybeDistance = GetOptionalAbsDifference( + std::optional 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 RawFuncLength; + std::optional 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 MaybeEpilogOffset = + std::optional 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 e796aeb..8eaf528 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp @@ -46,7 +46,7 @@ public: return AArch64::NumTargetFixupKinds; } - Optional getFixupKind(StringRef Name) const override; + std::optional 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 AArch64AsmBackend::getFixupKind(StringRef Name) const { +std::optional +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 089a02f..89f3756 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 +std::optional AMDGPUDisassembler::onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef 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 b811d70..870f7b1 100644 --- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h +++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h @@ -129,10 +129,9 @@ public: return MCDisassembler::Fail; } - Optional onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, - ArrayRef Bytes, - uint64_t Address, - raw_ostream &CStream) const override; + std::optional + onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef Bytes, + uint64_t Address, raw_ostream &CStream) const override; DecodeStatus decodeKernelDescriptor(StringRef KdName, ArrayRef Bytes, uint64_t KdAddress) const; diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp index 79d025e..f0653ae 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp @@ -50,7 +50,7 @@ public: bool writeNopData(raw_ostream &OS, uint64_t Count, const MCSubtargetInfo *STI) const override; - Optional getFixupKind(StringRef Name) const override; + std::optional 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((Value >> (i * 8)) & 0xff); } -Optional AMDGPUAsmBackend::getFixupKind(StringRef Name) const { - return StringSwitch>(Name) +std::optional +AMDGPUAsmBackend::getFixupKind(StringRef Name) const { + return StringSwitch>(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 673a009..dfa305a 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp @@ -47,11 +47,12 @@ public: }; } // end anonymous namespace -Optional ARMAsmBackend::getFixupKind(StringRef Name) const { +std::optional ARMAsmBackend::getFixupKind(StringRef Name) const { return std::nullopt; } -Optional ARMAsmBackendELF::getFixupKind(StringRef Name) const { +std::optional +ARMAsmBackendELF::getFixupKind(StringRef Name) const { unsigned Type = llvm::StringSwitch(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 9b0c8c0..a952823 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h @@ -31,7 +31,7 @@ public: return STI->getFeatureBits()[ARM::HasV6T2Ops]; } - Optional getFixupKind(StringRef Name) const override; + std::optional 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 2431c48..37afdf4 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h @@ -28,7 +28,7 @@ public: return createARMELFObjectWriter(OSABI); } - Optional getFixupKind(StringRef Name) const override; + std::optional getFixupKind(StringRef Name) const override; }; } diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp index dbaf36e..d0bf019 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp @@ -431,15 +431,14 @@ public: return false; } - Optional evaluateMemoryOperandAddress(const MCInst &Inst, - const MCSubtargetInfo *STI, - uint64_t Addr, - uint64_t Size) const override; + std::optional + evaluateMemoryOperandAddress(const MCInst &Inst, const MCSubtargetInfo *STI, + uint64_t Addr, uint64_t Size) const override; }; } // namespace -static Optional +static std::optional // 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 evaluateMemOpAddrForAddrMode3(const MCInst &Inst, - const MCInstrDesc &Desc, - unsigned MemOpIndex, - uint64_t Addr) { +static std::optional +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 evaluateMemOpAddrForAddrMode3(const MCInst &Inst, return Addr + ImmOffs; } -static Optional evaluateMemOpAddrForAddrMode5(const MCInst &Inst, - const MCInstrDesc &Desc, - unsigned MemOpIndex, - uint64_t Addr) { +static std::optional +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 evaluateMemOpAddrForAddrMode5(const MCInst &Inst, return Addr + ImmOffs * 4; } -static Optional +static std::optional 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 +static std::optional // 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 +static std::optional // 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 +static std::optional // 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 ARMMCInstrAnalysis::evaluateMemoryOperandAddress( +std::optional 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 33e84fe..0d524b4 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 LoongArchAsmBackend::getFixupKind(StringRef Name) const { +std::optional +LoongArchAsmBackend::getFixupKind(StringRef Name) const { if (STI.getTargetTriple().isOSBinFormatELF()) { auto Type = llvm::StringSwitch(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 a69f8dc..0d04cec 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h @@ -51,7 +51,7 @@ public: return LoongArch::NumTargetFixupKinds; } - Optional getFixupKind(StringRef Name) const override; + std::optional 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 be577f6..71f333d 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 MipsAsmBackend::getFixupKind(StringRef Name) const { +std::optional MipsAsmBackend::getFixupKind(StringRef Name) const { unsigned Type = llvm::StringSwitch(Name) .Case("BFD_RELOC_NONE", ELF::R_MIPS_NONE) .Case("BFD_RELOC_16", ELF::R_MIPS_16) @@ -310,7 +310,7 @@ Optional MipsAsmBackend::getFixupKind(StringRef Name) const { if (Type != -1u) return static_cast(FirstLiteralRelocationKind + Type); - return StringSwitch>(Name) + return StringSwitch>(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 5a0da3b..1172a06 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h @@ -43,7 +43,7 @@ public: uint64_t Value, bool IsResolved, const MCSubtargetInfo *STI) const override; - Optional getFixupKind(StringRef Name) const override; + std::optional 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 ee64bf5..227bd59 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp @@ -226,7 +226,7 @@ public: return createPPCELFObjectWriter(Is64, OSABI); } - Optional getFixupKind(StringRef Name) const override; + std::optional getFixupKind(StringRef Name) const override; }; class XCOFFPPCAsmBackend : public PPCAsmBackend { @@ -242,7 +242,8 @@ public: } // end anonymous namespace -Optional ELFPPCAsmBackend::getFixupKind(StringRef Name) const { +std::optional +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 fe2303d..150b9e7 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 RISCVAsmBackend::getFixupKind(StringRef Name) const { +std::optional RISCVAsmBackend::getFixupKind(StringRef Name) const { if (STI.getTargetTriple().isOSBinFormatELF()) { unsigned Type; Type = llvm::StringSwitch(Name) diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h index 5d62c3a..7e380ab 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h @@ -80,7 +80,7 @@ public: return RISCV::NumTargetFixupKinds; } - Optional getFixupKind(StringRef Name) const override; + std::optional 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 721e659..aa89488 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 getFixupKind(StringRef Name) const override { + std::optional getFixupKind(StringRef Name) const override { unsigned Type; Type = llvm::StringSwitch(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 3401c4c..d9f770a 100644 --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp @@ -89,7 +89,7 @@ public: unsigned getNumFixupKinds() const override { return SystemZ::NumTargetFixupKinds; } - Optional getFixupKind(StringRef Name) const override; + std::optional 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 @@ public: }; } // end anonymous namespace -Optional SystemZMCAsmBackend::getFixupKind(StringRef Name) const { +std::optional +SystemZMCAsmBackend::getFixupKind(StringRef Name) const { unsigned Type = llvm::StringSwitch(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 87dfeba..1f07b16 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 Bytes, uint64_t Address, raw_ostream &CStream) const override; - Optional onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, - ArrayRef Bytes, - uint64_t Address, - raw_ostream &CStream) const override; + std::optional + onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef 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 Bytes) { return true; } -Optional WebAssemblyDisassembler::onSymbolStart( - SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef Bytes, - uint64_t Address, raw_ostream &CStream) const { +std::optional +WebAssemblyDisassembler::onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, + ArrayRef 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 bcb6cf1..cf7d9ff 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 WasmTy = Sym->getType(); + std::optional 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 f8b0471..67f93ae 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp @@ -168,7 +168,7 @@ public: return X86::NumTargetFixupKinds; } - Optional getFixupKind(StringRef Name) const override; + std::optional 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 X86AsmBackend::getFixupKind(StringRef Name) const { +std::optional X86AsmBackend::getFixupKind(StringRef Name) const { if (STI.getTargetTriple().isOSBinFormatELF()) { unsigned Type; if (STI.getTargetTriple().getArch() == Triple::x86_64) { @@ -1145,8 +1145,8 @@ public: , Is64Bit(is64Bit) { } - Optional getFixupKind(StringRef Name) const override { - return StringSwitch>(Name) + std::optional getFixupKind(StringRef Name) const override { + return StringSwitch>(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 12d9acc..63c6f9c 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp @@ -506,11 +506,10 @@ public: bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size, uint64_t &Target) const override; - Optional evaluateMemoryOperandAddress(const MCInst &Inst, - const MCSubtargetInfo *STI, - uint64_t Addr, - uint64_t Size) const override; - Optional + std::optional + evaluateMemoryOperandAddress(const MCInst &Inst, const MCSubtargetInfo *STI, + uint64_t Addr, uint64_t Size) const override; + std::optional 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 X86MCInstrAnalysis::evaluateMemoryOperandAddress( +std::optional 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 X86MCInstrAnalysis::evaluateMemoryOperandAddress( return std::nullopt; } -Optional +std::optional 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 1169532..3b1d3e0 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 +std::optional 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 +std::optional 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 4616059..35d1c0f 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 +std::optional getXCOFFSymbolCsectSMC(const object::XCOFFObjectFile &Obj, const object::SymbolRef &Sym); -Optional +std::optional 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 e15054d..565e232 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 getWasmCodeSection(const WasmObjectFile &Obj) { +static std::optional 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 getWasmCodeSection(const WasmObjectFile &Obj) { static void addMissingWasmCodeSymbols(const WasmObjectFile &Obj, std::map &AllSymbols) { - Optional Section = getWasmCodeSection(Obj); + std::optional 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 Smc = + std::optional 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 MaybeTarget = + if (std::optional 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 SymRef = + std::optional SymRef = getXCOFFSymbolContainingSymbolRef(cast(O), Symbol); if (SymRef) { diff --git a/llvm/unittests/MC/DwarfLineTableHeaders.cpp b/llvm/unittests/MC/DwarfLineTableHeaders.cpp index 7dab9df..f45ad72 100644 --- a/llvm/unittests/MC/DwarfLineTableHeaders.cpp +++ b/llvm/unittests/MC/DwarfLineTableHeaders.cpp @@ -118,7 +118,7 @@ public: TheStreamer->switchSection(C.MOFI->getDwarfLineSection()); MCDwarfLineTableHeader Header; MCDwarfLineTableParams Params = Assembler.getDWARFLinetableParams(); - Optional LineStr(std::nullopt); + std::optional LineStr(std::nullopt); if (Ctx.getDwarfVersion() >= 5) { LineStr.emplace(Ctx); Header.setRootFile("dir", "file", std::nullopt, std::nullopt);