From: Amir Ayupov Date: Sun, 11 Dec 2022 20:14:15 +0000 (-0800) Subject: [BOLT][NFC] Use std::optional for getLTOCommonName X-Git-Tag: upstream/17.0.6~24290 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=15d1e51750654e004f64becbc36af4f93751e8b1;p=platform%2Fupstream%2Fllvm.git [BOLT][NFC] Use std::optional for getLTOCommonName --- diff --git a/bolt/include/bolt/Profile/ProfileReaderBase.h b/bolt/include/bolt/Profile/ProfileReaderBase.h index dd23844..7061d8e 100644 --- a/bolt/include/bolt/Profile/ProfileReaderBase.h +++ b/bolt/include/bolt/Profile/ProfileReaderBase.h @@ -47,7 +47,7 @@ class BoltAddressTranslation; /// best match. /// /// Return a common part of LTO name for a given \p Name. -Optional getLTOCommonName(const StringRef Name); +std::optional getLTOCommonName(const StringRef Name); class ProfileReaderBase { protected: diff --git a/bolt/lib/Profile/DataReader.cpp b/bolt/lib/Profile/DataReader.cpp index c5b5521..d6e031a 100644 --- a/bolt/lib/Profile/DataReader.cpp +++ b/bolt/lib/Profile/DataReader.cpp @@ -41,7 +41,7 @@ DumpData("dump-data", namespace llvm { namespace bolt { -Optional getLTOCommonName(const StringRef Name) { +std::optional getLTOCommonName(const StringRef Name) { size_t LTOSuffixPos = Name.find(".lto_priv."); if (LTOSuffixPos != StringRef::npos) return Name.substr(0, LTOSuffixPos + 10); @@ -1257,14 +1257,14 @@ std::error_code DataReader::parse() { void DataReader::buildLTONameMaps() { for (StringMapEntry &FuncData : NamesToBranches) { const StringRef FuncName = FuncData.getKey(); - const Optional CommonName = getLTOCommonName(FuncName); + const std::optional CommonName = getLTOCommonName(FuncName); if (CommonName) LTOCommonNameMap[*CommonName].push_back(&FuncData.getValue()); } for (StringMapEntry &FuncData : NamesToMemEvents) { const StringRef FuncName = FuncData.getKey(); - const Optional CommonName = getLTOCommonName(FuncName); + const std::optional CommonName = getLTOCommonName(FuncName); if (CommonName) LTOCommonNameMemMap[*CommonName].push_back(&FuncData.getValue()); } @@ -1308,7 +1308,7 @@ std::vector fetchMapEntriesRegex( // of matching a name at the end of the list. for (auto FI = FuncNames.rbegin(), FE = FuncNames.rend(); FI != FE; ++FI) { std::string Name = normalizeName(*FI); - const Optional LTOCommonName = getLTOCommonName(Name); + const std::optional LTOCommonName = getLTOCommonName(Name); if (LTOCommonName) { auto I = LTOCommonNameMap.find(*LTOCommonName); if (I != LTOCommonNameMap.end()) { diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index 59819b4..d2ccadd 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -49,13 +49,13 @@ void YAMLProfileReader::buildNameMaps( if (Pos != StringRef::npos) Name = Name.substr(0, Pos); ProfileNameToProfile[Name] = &YamlBF; - if (const Optional CommonName = getLTOCommonName(Name)) + if (const std::optional CommonName = getLTOCommonName(Name)) LTOCommonNameMap[*CommonName].push_back(&YamlBF); } for (auto &BFI : Functions) { const BinaryFunction &Function = BFI.second; for (StringRef Name : Function.getNames()) - if (const Optional CommonName = getLTOCommonName(Name)) + if (const std::optional CommonName = getLTOCommonName(Name)) LTOCommonNameFunctionMap[*CommonName].insert(&Function); } } @@ -287,7 +287,7 @@ bool YAMLProfileReader::mayHaveProfileData(const BinaryFunction &BF) { for (StringRef Name : BF.getNames()) { if (ProfileNameToProfile.find(Name) != ProfileNameToProfile.end()) return true; - if (const Optional CommonName = getLTOCommonName(Name)) { + if (const std::optional CommonName = getLTOCommonName(Name)) { if (LTOCommonNameMap.find(*CommonName) != LTOCommonNameMap.end()) return true; } @@ -341,7 +341,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) { continue; for (StringRef FunctionName : Function.getNames()) { - const Optional CommonName = getLTOCommonName(FunctionName); + const std::optional CommonName = + getLTOCommonName(FunctionName); if (CommonName) { auto I = LTOCommonNameMap.find(*CommonName); if (I == LTOCommonNameMap.end()) diff --git a/bolt/lib/Rewrite/BoltDiff.cpp b/bolt/lib/Rewrite/BoltDiff.cpp index c52d4d9..837fd87 100644 --- a/bolt/lib/Rewrite/BoltDiff.cpp +++ b/bolt/lib/Rewrite/BoltDiff.cpp @@ -202,7 +202,7 @@ class RewriteInstanceDiff { const double Score = getNormalizedScore(Function, RI1); LargestBin1.insert(std::make_pair<>(Score, &Function)); for (const StringRef &Name : Function.getNames()) { - if (Optional OptionalLTOName = getLTOCommonName(Name)) + if (std::optional OptionalLTOName = getLTOCommonName(Name)) LTOName = *OptionalLTOName; NameLookup[Name] = &Function; } @@ -222,7 +222,7 @@ class RewriteInstanceDiff { const double Score = getNormalizedScore(Function, RI2); LargestBin2.insert(std::make_pair<>(Score, &Function)); for (const StringRef &Name : Function.getNames()) { - if (Optional OptionalLTOName = getLTOCommonName(Name)) + if (std::optional OptionalLTOName = getLTOCommonName(Name)) LTOName = *OptionalLTOName; } if (opts::IgnoreLTOSuffix && !LTOName.empty()) { @@ -245,7 +245,7 @@ class RewriteInstanceDiff { bool Match = false; for (const StringRef &Name : Function2.getNames()) { auto Iter = NameLookup.find(Name); - if (Optional OptionalLTOName = getLTOCommonName(Name)) + if (std::optional OptionalLTOName = getLTOCommonName(Name)) LTOName = *OptionalLTOName; if (Iter == NameLookup.end()) continue;