From 370e4761bcd52f601a80a252845ebddbec87d904 Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Tue, 6 Dec 2022 14:15:50 -0800 Subject: [BOLT][NFC] Use std::optional for findAttributeInfo LLVM started switching from `llvm::Optional` to `std::optional`: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716/11 Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D139259 --- bolt/include/bolt/Core/DebugData.h | 5 +++-- bolt/lib/Core/DebugData.cpp | 10 ++++----- bolt/lib/Rewrite/DWARFRewriter.cpp | 45 +++++++++++++++++++------------------- 3 files changed, 31 insertions(+), 29 deletions(-) (limited to 'bolt') diff --git a/bolt/include/bolt/Core/DebugData.h b/bolt/include/bolt/Core/DebugData.h index 1ba31fe..d9a8834 100644 --- a/bolt/include/bolt/Core/DebugData.h +++ b/bolt/include/bolt/Core/DebugData.h @@ -46,7 +46,7 @@ struct AttrInfo { /// \param DIE die to look up in. /// \param AbbrevDecl abbrev declaration for the die. /// \param Index an index in Abbrev declaration entry. -Optional +std::optional findAttributeInfo(const DWARFDie DIE, const DWARFAbbreviationDeclaration *AbbrevDecl, uint32_t Index); @@ -56,7 +56,8 @@ findAttributeInfo(const DWARFDie DIE, /// \param DIE die to look up in. /// \param Attr the attribute to extract. /// \return an optional AttrInfo with DWARFFormValue and Offset. -Optional findAttributeInfo(const DWARFDie DIE, dwarf::Attribute Attr); +std::optional findAttributeInfo(const DWARFDie DIE, + dwarf::Attribute Attr); // DWARF5 Header in order of encoding. // Types represent encodnig sizes. diff --git a/bolt/lib/Core/DebugData.cpp b/bolt/lib/Core/DebugData.cpp index d0e8988..1d6f656 100644 --- a/bolt/lib/Core/DebugData.cpp +++ b/bolt/lib/Core/DebugData.cpp @@ -42,7 +42,7 @@ class MCSymbol; namespace bolt { -Optional +std::optional findAttributeInfo(const DWARFDie DIE, const DWARFAbbreviationDeclaration *AbbrevDecl, uint32_t Index) { @@ -73,8 +73,8 @@ findAttributeInfo(const DWARFDie DIE, return AttrInfo{*Value, DIE.getAbbreviationDeclarationPtr(), Offset, ValSize}; } -Optional findAttributeInfo(const DWARFDie DIE, - dwarf::Attribute Attr) { +std::optional findAttributeInfo(const DWARFDie DIE, + dwarf::Attribute Attr) { if (!DIE.isValid()) return std::nullopt; const DWARFAbbreviationDeclaration *AbbrevDecl = @@ -666,7 +666,7 @@ void DebugLoclistWriter::finalizeDWARF5( *LocStream << *LocBodyBuffer; if (!isSplitDwarf()) { - if (Optional AttrInfoVal = + if (std::optional AttrInfoVal = findAttributeInfo(CU.getUnitDIE(), dwarf::DW_AT_loclists_base)) DebugInfoPatcher.addLE32Patch(AttrInfoVal->Offset, LoclistBaseOffset + @@ -733,7 +733,7 @@ void DebugInfoBinaryPatcher::insertNewEntry(const DWARFDie &DIE, uint32_t Offset = DIE.getOffset() + 1; size_t NumOfAttributes = AbbrevDecl->getNumAttributes(); if (NumOfAttributes) { - Optional Val = + std::optional Val = findAttributeInfo(DIE, AbbrevDecl, NumOfAttributes - 1); assert(Val && "Invalid Value."); diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp index 72eac7b..c3a8e393 100644 --- a/bolt/lib/Rewrite/DWARFRewriter.cpp +++ b/bolt/lib/Rewrite/DWARFRewriter.cpp @@ -62,10 +62,10 @@ namespace bolt { /// \param DIE die to look up in. /// \param Attrs finds the first attribute that matches and extracts it. /// \return an optional AttrInfo with DWARFFormValue and Offset. -Optional findAttributeInfo(const DWARFDie DIE, - std::vector Attrs) { +std::optional findAttributeInfo(const DWARFDie DIE, + std::vector Attrs) { for (dwarf::Attribute &Attr : Attrs) - if (Optional Info = findAttributeInfo(DIE, Attr)) + if (std::optional Info = findAttributeInfo(DIE, Attr)) return Info; return std::nullopt; } @@ -230,7 +230,7 @@ void DWARFRewriter::updateDebugInfo() { auto updateDWONameCompDir = [&](DWARFUnit &Unit) -> void { const DWARFDie &DIE = Unit.getUnitDIE(); - Optional AttrInfoVal = findAttributeInfo( + std::optional AttrInfoVal = findAttributeInfo( DIE, {dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}); (void)AttrInfoVal; assert(AttrInfoVal && "Skeleton CU doesn't have dwo_name."); @@ -514,11 +514,11 @@ void DWARFRewriter::updateUnitDebugInfo( } }; - if (Optional AttrVal = + if (std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_call_pc)) patchPC(*AttrVal, "DW_AT_call_pc"); - if (Optional AttrVal = + if (std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_call_return_pc)) patchPC(*AttrVal, "DW_AT_call_return_pc"); @@ -528,7 +528,7 @@ void DWARFRewriter::updateUnitDebugInfo( // Handle any tag that can have DW_AT_location attribute. DWARFFormValue Value; uint64_t AttrOffset; - if (Optional AttrVal = + if (std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_location)) { AttrOffset = AttrVal->Offset; Value = AttrVal->V; @@ -690,7 +690,7 @@ void DWARFRewriter::updateUnitDebugInfo( SizeDiff + CurrEndOffset, 1); } } - } else if (Optional AttrVal = + } else if (std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_low_pc)) { AttrOffset = AttrVal->Offset; Value = AttrVal->V; @@ -736,7 +736,7 @@ void DWARFRewriter::updateUnitDebugInfo( } } else if (IsDWP && Unit.isDWOUnit()) { // Not a common path so don't want to search all DIEs all the time. - Optional SignatureAttrVal = + std::optional SignatureAttrVal = findAttributeInfo(DIE, dwarf::DW_AT_signature); if (!SignatureAttrVal) continue; @@ -771,7 +771,8 @@ void DWARFRewriter::updateUnitDebugInfo( case dwarf::DW_FORM_ref8: case dwarf::DW_FORM_ref_udata: case dwarf::DW_FORM_ref_addr: { - Optional AttrVal = findAttributeInfo(DIE, AbbrevDecl, Index); + std::optional AttrVal = + findAttributeInfo(DIE, AbbrevDecl, Index); uint32_t DestinationAddress = AttrVal->V.getRawUValue() + (Decl.Form == dwarf::DW_FORM_ref_addr ? 0 : Unit.getOffset()); @@ -813,7 +814,7 @@ void DWARFRewriter::updateDWARFObjectAddressRanges( if (RangesBase) { // If DW_AT_GNU_ranges_base is present, update it. No further modifications // are needed for ranges base. - Optional RangesBaseAttrInfo = + std::optional RangesBaseAttrInfo = findAttributeInfo(DIE, dwarf::DW_AT_GNU_ranges_base); if (!RangesBaseAttrInfo) RangesBaseAttrInfo = findAttributeInfo(DIE, dwarf::DW_AT_rnglists_base); @@ -826,9 +827,9 @@ void DWARFRewriter::updateDWARFObjectAddressRanges( } } - Optional LowPCAttrInfo = + std::optional LowPCAttrInfo = findAttributeInfo(DIE, dwarf::DW_AT_low_pc); - if (Optional AttrVal = + if (std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_ranges)) { // Case 1: The object was already non-contiguous and had DW_AT_ranges. // In this case we simply need to update the value of DW_AT_ranges @@ -881,7 +882,7 @@ void DWARFRewriter::updateDWARFObjectAddressRanges( // Case 2: The object has both DW_AT_low_pc and DW_AT_high_pc emitted back // to back. Replace with new attributes and patch the DIE. - Optional HighPCAttrInfo = + std::optional HighPCAttrInfo = findAttributeInfo(DIE, dwarf::DW_AT_high_pc); if (LowPCAttrInfo && HighPCAttrInfo) { convertToRangesPatchAbbrev(*DIE.getDwarfUnit(), AbbreviationDecl, @@ -937,7 +938,7 @@ void DWARFRewriter::updateLineTableOffsets(const MCAsmLayout &Layout) { if (!Label) continue; - Optional AttrVal = + std::optional AttrVal = findAttributeInfo(CU.get()->getUnitDIE(), dwarf::DW_AT_stmt_list); if (!AttrVal) continue; @@ -951,7 +952,7 @@ void DWARFRewriter::updateLineTableOffsets(const MCAsmLayout &Layout) { for (const std::unique_ptr &TU : BC.DwCtx->types_section_units()) { DWARFUnit *Unit = TU.get(); - Optional AttrVal = + std::optional AttrVal = findAttributeInfo(TU.get()->getUnitDIE(), dwarf::DW_AT_stmt_list); if (!AttrVal) continue; @@ -1039,9 +1040,9 @@ DWARFRewriter::finalizeDebugSections(DebugInfoBinaryPatcher &DebugInfoPatcher) { uint64_t Offset = 0; uint64_t AttrOffset = 0; uint32_t Size = 0; - Optional AttrValGnu = + std::optional AttrValGnu = findAttributeInfo(DIE, dwarf::DW_AT_GNU_addr_base); - Optional AttrVal = + std::optional AttrVal = findAttributeInfo(DIE, dwarf::DW_AT_addr_base); // For cases where Skeleton CU does not have DW_AT_GNU_addr_base @@ -1827,8 +1828,8 @@ std::unique_ptr DWARFRewriter::makeFinalLocListsSection( namespace { -void getRangeAttrData(DWARFDie DIE, Optional &LowPCVal, - Optional &HighPCVal) { +void getRangeAttrData(DWARFDie DIE, std::optional &LowPCVal, + std::optional &HighPCVal) { LowPCVal = findAttributeInfo(DIE, dwarf::DW_AT_low_pc); HighPCVal = findAttributeInfo(DIE, dwarf::DW_AT_high_pc); uint64_t LowPCOffset = LowPCVal->Offset; @@ -1894,8 +1895,8 @@ void DWARFRewriter::convertToRangesPatchDebugInfo( DWARFDie DIE, uint64_t RangesSectionOffset, SimpleBinaryPatcher &DebugInfoPatcher, uint64_t LowPCToUse, Optional RangesBase) { - Optional LowPCVal; - Optional HighPCVal; + std::optional LowPCVal; + std::optional HighPCVal; getRangeAttrData(DIE, LowPCVal, HighPCVal); uint64_t LowPCOffset = LowPCVal->Offset; uint64_t HighPCOffset = HighPCVal->Offset; -- cgit v1.1