From: Amir Ayupov Date: Sun, 11 Dec 2022 20:02:21 +0000 (-0800) Subject: [BOLT][NFC] Use std::optional in BC X-Git-Tag: upstream/17.0.6~24291 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e8f5743e86c7386b2f91c614b16a2588b390024e;p=platform%2Fupstream%2Fllvm.git [BOLT][NFC] Use std::optional in BC --- diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h index 277d266..2d60ac5 100644 --- a/bolt/include/bolt/Core/BinaryContext.h +++ b/bolt/include/bolt/Core/BinaryContext.h @@ -152,7 +152,7 @@ class BinaryContext { std::string Filename; /// Unique build ID if available for the binary. - Optional FileBuildID; + std::optional FileBuildID; /// Set of all sections. struct CompareSections { @@ -259,7 +259,7 @@ public: void clearFragmentsToSkip() { FragmentsToSkip.clear(); } /// Given DWOId returns CU if it exists in DWOCUs. - Optional getDWOCU(uint64_t DWOId); + std::optional getDWOCU(uint64_t DWOId); /// Returns DWOContext if it exists. DWARFContext *getDWOContext() const; @@ -319,7 +319,7 @@ public: StringRef getFilename() const { return Filename; } void setFilename(StringRef Name) { Filename = std::string(Name); } - Optional getFileBuildID() const { + std::optional getFileBuildID() const { if (FileBuildID) return StringRef(*FileBuildID); @@ -1064,8 +1064,8 @@ public: /// mapping. Note that \p FileOffset should be page-aligned and could be /// different from the file offset of the segment which could be unaligned. /// If no segment is found that matches \p FileOffset, return std::nullopt. - Optional getBaseAddressForMapping(uint64_t MMapAddress, - uint64_t FileOffset) const; + std::optional getBaseAddressForMapping(uint64_t MMapAddress, + uint64_t FileOffset) const; /// Check if the address belongs to this binary's static allocation space. bool containsAddress(uint64_t Address) const { diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp index 58c1f43..02d9fc9 100644 --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -1527,7 +1527,7 @@ std::vector BinaryContext::getAllBinaryFunctions() { return AllFunctions; } -Optional BinaryContext::getDWOCU(uint64_t DWOId) { +std::optional BinaryContext::getDWOCU(uint64_t DWOId) { auto Iter = DWOCUs.find(DWOId); if (Iter == DWOCUs.end()) return std::nullopt; @@ -1886,7 +1886,7 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction, } } -Optional +std::optional BinaryContext::getBaseAddressForMapping(uint64_t MMapAddress, uint64_t FileOffset) const { // Find a segment with a matching file offset. diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp index 39c07a3..4245ce8 100644 --- a/bolt/lib/Profile/DataAggregator.cpp +++ b/bolt/lib/Profile/DataAggregator.cpp @@ -475,7 +475,7 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) { return Error::success(); } - if (Optional FileBuildID = BC.getFileBuildID()) { + if (std::optional FileBuildID = BC.getFileBuildID()) { outs() << "BOLT-INFO: binary build-id is: " << *FileBuildID << "\n"; processFileBuildID(*FileBuildID); } else { @@ -2057,7 +2057,7 @@ std::error_code DataAggregator::parseMMapEvents() { // Set base address for shared objects. if (!BC->HasFixedLoadAddress) { - Optional BaseAddress = + std::optional BaseAddress = BC->getBaseAddressForMapping(MMapInfo.MMapAddress, MMapInfo.Offset); if (!BaseAddress) { errs() << "PERF2BOLT-WARNING: unable to find base address of the " diff --git a/bolt/lib/Profile/YAMLProfileWriter.cpp b/bolt/lib/Profile/YAMLProfileWriter.cpp index dd8dc24..bee18a6 100644 --- a/bolt/lib/Profile/YAMLProfileWriter.cpp +++ b/bolt/lib/Profile/YAMLProfileWriter.cpp @@ -154,7 +154,7 @@ std::error_code YAMLProfileWriter::writeProfile(const RewriteInstance &RI) { // Fill out the header info. BP.Header.Version = 1; BP.Header.FileName = std::string(BC.getFilename()); - Optional BuildID = BC.getFileBuildID(); + std::optional BuildID = BC.getFileBuildID(); BP.Header.Id = BuildID ? std::string(*BuildID) : ""; BP.Header.Origin = std::string(RI.getProfileReader()->getReaderName()); diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp index 1701e89..a2ce969 100644 --- a/bolt/lib/Rewrite/DWARFRewriter.cpp +++ b/bolt/lib/Rewrite/DWARFRewriter.cpp @@ -256,7 +256,7 @@ void DWARFRewriter::updateDebugInfo() { auto processUnitDIE = [&](size_t CUIndex, DWARFUnit *Unit) { // Check if the unit is a skeleton and we need special updates for it and // its matching split/DWO CU. - Optional SplitCU; + std::optional SplitCU; Optional RangesBase; std::optional DWOId = Unit->getDWOId(); StrOffstsWriter->initialize(Unit->getStringOffsetSection(), @@ -1419,7 +1419,7 @@ void DWARFRewriter::writeDWP( continue; // Skipping CUs that we failed to load. - Optional DWOCU = BC.getDWOCU(*DWOId); + std::optional DWOCU = BC.getDWOCU(*DWOId); if (!DWOCU) continue; @@ -1588,7 +1588,7 @@ void DWARFRewriter::writeDWOFiles( continue; // Skipping CUs that we failed to load. - Optional DWOCU = BC.getDWOCU(*DWOId); + std::optional DWOCU = BC.getDWOCU(*DWOId); if (!DWOCU) continue;