diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -894,7 +894,8 @@ BinaryBasicBlock *getLandingPadBBFor(const BinaryBasicBlock &BB, const MCInst &InvokeInst) const { assert(BC.MIB->isInvoke(InvokeInst) && "must be invoke instruction"); - const Optional LP = BC.MIB->getEHInfo(InvokeInst); + const std::optional LP = + BC.MIB->getEHInfo(InvokeInst); if (LP && LP->first) { BinaryBasicBlock *LBB = BB.getLandingPad(LP->first); assert(LBB && "Landing pad should be defined"); diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h --- a/bolt/include/bolt/Core/MCPlusBuilder.h +++ b/bolt/include/bolt/Core/MCPlusBuilder.h @@ -18,7 +18,6 @@ #include "bolt/Core/Relocation.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitVector.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringMap.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCDisassembler/MCSymbolizer.h" @@ -33,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -132,8 +132,8 @@ AnnotationInst->addOperand(MCOperand::createImm(AnnotationValue)); } - Optional getAnnotationOpValue(const MCInst &Inst, - unsigned Index) const { + std::optional getAnnotationOpValue(const MCInst &Inst, + unsigned Index) const { const MCInst *AnnotationInst = getAnnotationInst(Inst); if (!AnnotationInst) return std::nullopt; @@ -1049,7 +1049,7 @@ } /// Return handler and action info for invoke instruction if present. - Optional getEHInfo(const MCInst &Inst) const; + std::optional getEHInfo(const MCInst &Inst) const; /// Add handler and action info for call instruction. void addEHInfo(MCInst &Inst, const MCPlus::MCLandingPad &LP); @@ -1081,7 +1081,7 @@ bool unsetJumpTable(MCInst &Inst); /// Return destination of conditional tail call instruction if \p Inst is one. - Optional getConditionalTailCall(const MCInst &Inst) const; + std::optional getConditionalTailCall(const MCInst &Inst) const; /// Mark the \p Instruction as a conditional tail call, and set its /// destination address if it is known. If \p Instruction was already marked, @@ -1093,7 +1093,7 @@ bool unsetConditionalTailCall(MCInst &Inst); /// Return offset of \p Inst in the original function, if available. - Optional getOffset(const MCInst &Inst) const; + std::optional getOffset(const MCInst &Inst) const; /// Return the offset if the annotation is present, or \p Default otherwise. uint32_t getOffsetWithDefault(const MCInst &Inst, uint32_t Default) const; @@ -1591,8 +1591,8 @@ /// Create a target-specific relocation out of the \p Fixup. /// Note that not every fixup could be converted into a relocation. - virtual Optional createRelocation(const MCFixup &Fixup, - const MCAsmBackend &MAB) const { + virtual std::optional + createRelocation(const MCFixup &Fixup, const MCAsmBackend &MAB) const { llvm_unreachable("not implemented"); return Relocation(); } @@ -1666,7 +1666,7 @@ } /// Return annotation index matching the \p Name. - Optional getAnnotationIndex(StringRef Name) const { + std::optional getAnnotationIndex(StringRef Name) const { auto AI = AnnotationNameIndexMap.find(Name); if (AI != AnnotationNameIndexMap.end()) return AI->second; @@ -1744,7 +1744,7 @@ /// Use hasAnnotation() if the annotation may not exist. template ValueType &getAnnotationAs(const MCInst &Inst, unsigned Index) const { - Optional Value = getAnnotationOpValue(Inst, Index); + std::optional Value = getAnnotationOpValue(Inst, Index); assert(Value && "annotation should exist"); return reinterpret_cast *>(*Value) ->getValue(); diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -1846,7 +1846,8 @@ if (MIB->isTailCall(Instruction)) OS << " # TAILCALL "; if (MIB->isInvoke(Instruction)) { - const Optional EHInfo = MIB->getEHInfo(Instruction); + const std::optional EHInfo = + MIB->getEHInfo(Instruction); OS << " # handler: "; if (EHInfo->first) OS << *EHInfo->first; @@ -1864,7 +1865,7 @@ OS << " # UNKNOWN CONTROL FLOW"; } } - if (Optional Offset = MIB->getOffset(Instruction)) + if (std::optional Offset = MIB->getOffset(Instruction)) OS << " # Offset: " << *Offset; MIB->printAnnotations(Instruction, OS); diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -1548,7 +1548,7 @@ // Create relocation for every fixup. for (const MCFixup &Fixup : Fixups) { - Optional Rel = BC.MIB->createRelocation(Fixup, *BC.MAB); + std::optional Rel = BC.MIB->createRelocation(Fixup, *BC.MAB); if (!Rel) { Success = false; continue; @@ -1923,7 +1923,8 @@ if (!BC.MIB->isInvoke(Instr)) continue; - const Optional EHInfo = BC.MIB->getEHInfo(Instr); + const std::optional EHInfo = + BC.MIB->getEHInfo(Instr); if (!EHInfo || !EHInfo->first) continue; @@ -2280,7 +2281,7 @@ if (!CTCInstr) continue; - Optional TargetAddressOrNone = + std::optional TargetAddressOrNone = BC.MIB->getConditionalTailCall(*CTCInstr); if (!TargetAddressOrNone) continue; diff --git a/bolt/lib/Core/Exceptions.cpp b/bolt/lib/Core/Exceptions.cpp --- a/bolt/lib/Core/Exceptions.cpp +++ b/bolt/lib/Core/Exceptions.cpp @@ -393,7 +393,7 @@ // Extract exception handling information from the instruction. const MCSymbol *LP = nullptr; uint64_t Action = 0; - if (const Optional EHInfo = + if (const std::optional EHInfo = BC.MIB->getEHInfo(*II)) std::tie(LP, Action) = *EHInfo; diff --git a/bolt/lib/Core/MCPlusBuilder.cpp b/bolt/lib/Core/MCPlusBuilder.cpp --- a/bolt/lib/Core/MCPlusBuilder.cpp +++ b/bolt/lib/Core/MCPlusBuilder.cpp @@ -133,14 +133,14 @@ return false; } -Optional MCPlusBuilder::getEHInfo(const MCInst &Inst) const { +std::optional MCPlusBuilder::getEHInfo(const MCInst &Inst) const { if (!isCall(Inst)) return std::nullopt; - Optional LPSym = + std::optional LPSym = getAnnotationOpValue(Inst, MCAnnotation::kEHLandingPad); if (!LPSym) return std::nullopt; - Optional Action = + std::optional Action = getAnnotationOpValue(Inst, MCAnnotation::kEHAction); if (!Action) return std::nullopt; @@ -171,7 +171,7 @@ } int64_t MCPlusBuilder::getGnuArgsSize(const MCInst &Inst) const { - Optional Value = + std::optional Value = getAnnotationOpValue(Inst, MCAnnotation::kGnuArgsSize); if (!Value) return -1LL; @@ -188,7 +188,7 @@ } uint64_t MCPlusBuilder::getJumpTable(const MCInst &Inst) const { - Optional Value = + std::optional Value = getAnnotationOpValue(Inst, MCAnnotation::kJumpTable); if (!Value) return 0; @@ -216,9 +216,9 @@ return true; } -Optional +std::optional MCPlusBuilder::getConditionalTailCall(const MCInst &Inst) const { - Optional Value = + std::optional Value = getAnnotationOpValue(Inst, MCAnnotation::kConditionalTailCall); if (!Value) return std::nullopt; @@ -240,8 +240,9 @@ return true; } -Optional MCPlusBuilder::getOffset(const MCInst &Inst) const { - Optional Value = getAnnotationOpValue(Inst, MCAnnotation::kOffset); +std::optional MCPlusBuilder::getOffset(const MCInst &Inst) const { + std::optional Value = + getAnnotationOpValue(Inst, MCAnnotation::kOffset); if (!Value) return std::nullopt; return static_cast(*Value); @@ -249,7 +250,7 @@ uint32_t MCPlusBuilder::getOffsetWithDefault(const MCInst &Inst, uint32_t Default) const { - if (Optional Offset = getOffset(Inst)) + if (std::optional Offset = getOffset(Inst)) return *Offset; return Default; } diff --git a/bolt/lib/Passes/DataflowAnalysis.cpp b/bolt/lib/Passes/DataflowAnalysis.cpp --- a/bolt/lib/Passes/DataflowAnalysis.cpp +++ b/bolt/lib/Passes/DataflowAnalysis.cpp @@ -58,7 +58,7 @@ for (MCInst &Inst : *Thrower) { if (!MIB->isInvoke(Inst)) continue; - const Optional EHInfo = MIB->getEHInfo(Inst); + const std::optional EHInfo = MIB->getEHInfo(Inst); if (!EHInfo || EHInfo->first != BB.getLabel()) continue; Task(ProgramPoint(&Inst)); diff --git a/bolt/lib/Passes/IdenticalCodeFolding.cpp b/bolt/lib/Passes/IdenticalCodeFolding.cpp --- a/bolt/lib/Passes/IdenticalCodeFolding.cpp +++ b/bolt/lib/Passes/IdenticalCodeFolding.cpp @@ -110,8 +110,8 @@ // NB: there's no need to compare jump table indirect jump instructions // separately as jump tables are handled by comparing corresponding // symbols. - const Optional EHInfoA = BC.MIB->getEHInfo(InstA); - const Optional EHInfoB = BC.MIB->getEHInfo(InstB); + const std::optional EHInfoA = BC.MIB->getEHInfo(InstA); + const std::optional EHInfoB = BC.MIB->getEHInfo(InstB); if (EHInfoA || EHInfoB) { if (!EHInfoA && (EHInfoB->first || EHInfoB->second)) diff --git a/bolt/lib/Passes/Inliner.cpp b/bolt/lib/Passes/Inliner.cpp --- a/bolt/lib/Passes/Inliner.cpp +++ b/bolt/lib/Passes/Inliner.cpp @@ -250,7 +250,8 @@ const bool CSIsInvoke = BC.MIB->isInvoke(*CallInst); const bool CSIsTailCall = BC.MIB->isTailCall(*CallInst); const int64_t CSGNUArgsSize = BC.MIB->getGnuArgsSize(*CallInst); - const Optional CSEHInfo = BC.MIB->getEHInfo(*CallInst); + const std::optional CSEHInfo = + BC.MIB->getEHInfo(*CallInst); // Split basic block at the call site if there will be more incoming edges // coming from the callee. diff --git a/bolt/lib/Passes/SplitFunctions.cpp b/bolt/lib/Passes/SplitFunctions.cpp --- a/bolt/lib/Passes/SplitFunctions.cpp +++ b/bolt/lib/Passes/SplitFunctions.cpp @@ -443,7 +443,7 @@ std::vector Blocks(BF.pbegin(), BF.pend()); for (BinaryBasicBlock *BB : Blocks) { for (MCInst &Instr : *BB) { - const Optional EHInfo = MIB->getEHInfo(Instr); + const std::optional EHInfo = MIB->getEHInfo(Instr); if (!EHInfo || !EHInfo->first) continue; diff --git a/bolt/lib/Profile/YAMLProfileWriter.cpp b/bolt/lib/Profile/YAMLProfileWriter.cpp --- a/bolt/lib/Profile/YAMLProfileWriter.cpp +++ b/bolt/lib/Profile/YAMLProfileWriter.cpp @@ -53,7 +53,7 @@ continue; yaml::bolt::CallSiteInfo CSI; - Optional Offset = BC.MIB->getOffset(Instr); + std::optional Offset = BC.MIB->getOffset(Instr); if (!Offset || *Offset < BB->getInputOffset()) continue; CSI.Offset = *Offset - BB->getInputOffset(); diff --git a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp --- a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp +++ b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp @@ -2588,7 +2588,7 @@ return Code; } - Optional + std::optional createRelocation(const MCFixup &Fixup, const MCAsmBackend &MAB) const override { const MCFixupKindInfo &FKI = MAB.getFixupKindInfo(Fixup.getKind()); @@ -3594,7 +3594,7 @@ if (CallOrJmp.getOpcode() == X86::CALL64r || CallOrJmp.getOpcode() == X86::CALL64pcrel32) { - if (Optional Offset = getOffset(CallInst)) + if (std::optional Offset = getOffset(CallInst)) // Annotated as duplicated call setOffset(CallOrJmp, *Offset); } @@ -3602,7 +3602,7 @@ if (isInvoke(CallInst) && !isInvoke(CallOrJmp)) { // Copy over any EH or GNU args size information from the original // call. - Optional EHInfo = getEHInfo(CallInst); + std::optional EHInfo = getEHInfo(CallInst); if (EHInfo) addEHInfo(CallOrJmp, *EHInfo); int64_t GnuArgsSize = getGnuArgsSize(CallInst); diff --git a/bolt/unittests/Core/MCPlusBuilder.cpp b/bolt/unittests/Core/MCPlusBuilder.cpp --- a/bolt/unittests/Core/MCPlusBuilder.cpp +++ b/bolt/unittests/Core/MCPlusBuilder.cpp @@ -140,7 +140,7 @@ // Test encodeAnnotationImm using this indirect way BC->MIB->addEHInfo(Inst, MCPlus::MCLandingPad(LPSymbol, Value)); // Round-trip encoding-decoding check for negative values - Optional EHInfo = BC->MIB->getEHInfo(Inst); + std::optional EHInfo = BC->MIB->getEHInfo(Inst); ASSERT_TRUE(EHInfo.has_value()); MCPlus::MCLandingPad LP = EHInfo.value(); uint64_t DecodedValue = LP.second;