[BOLT][NFC] Use std::optional for getLTOCommonName

This commit is contained in:
Amir Ayupov 2022-12-11 12:14:15 -08:00
parent e8f5743e86
commit 15d1e51750
4 changed files with 13 additions and 12 deletions

View File

@ -47,7 +47,7 @@ class BoltAddressTranslation;
/// best match.
///
/// Return a common part of LTO name for a given \p Name.
Optional<StringRef> getLTOCommonName(const StringRef Name);
std::optional<StringRef> getLTOCommonName(const StringRef Name);
class ProfileReaderBase {
protected:

View File

@ -41,7 +41,7 @@ DumpData("dump-data",
namespace llvm {
namespace bolt {
Optional<StringRef> getLTOCommonName(const StringRef Name) {
std::optional<StringRef> 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<FuncBranchData> &FuncData : NamesToBranches) {
const StringRef FuncName = FuncData.getKey();
const Optional<StringRef> CommonName = getLTOCommonName(FuncName);
const std::optional<StringRef> CommonName = getLTOCommonName(FuncName);
if (CommonName)
LTOCommonNameMap[*CommonName].push_back(&FuncData.getValue());
}
for (StringMapEntry<FuncMemData> &FuncData : NamesToMemEvents) {
const StringRef FuncName = FuncData.getKey();
const Optional<StringRef> CommonName = getLTOCommonName(FuncName);
const std::optional<StringRef> CommonName = getLTOCommonName(FuncName);
if (CommonName)
LTOCommonNameMemMap[*CommonName].push_back(&FuncData.getValue());
}
@ -1308,7 +1308,7 @@ std::vector<decltype(MapTy::MapEntryTy::second) *> 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<StringRef> LTOCommonName = getLTOCommonName(Name);
const std::optional<StringRef> LTOCommonName = getLTOCommonName(Name);
if (LTOCommonName) {
auto I = LTOCommonNameMap.find(*LTOCommonName);
if (I != LTOCommonNameMap.end()) {

View File

@ -49,13 +49,13 @@ void YAMLProfileReader::buildNameMaps(
if (Pos != StringRef::npos)
Name = Name.substr(0, Pos);
ProfileNameToProfile[Name] = &YamlBF;
if (const Optional<StringRef> CommonName = getLTOCommonName(Name))
if (const std::optional<StringRef> 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<StringRef> CommonName = getLTOCommonName(Name))
if (const std::optional<StringRef> 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<StringRef> CommonName = getLTOCommonName(Name)) {
if (const std::optional<StringRef> 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<StringRef> CommonName = getLTOCommonName(FunctionName);
const std::optional<StringRef> CommonName =
getLTOCommonName(FunctionName);
if (CommonName) {
auto I = LTOCommonNameMap.find(*CommonName);
if (I == LTOCommonNameMap.end())

View File

@ -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<StringRef> OptionalLTOName = getLTOCommonName(Name))
if (std::optional<StringRef> 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<StringRef> OptionalLTOName = getLTOCommonName(Name))
if (std::optional<StringRef> 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<StringRef> OptionalLTOName = getLTOCommonName(Name))
if (std::optional<StringRef> OptionalLTOName = getLTOCommonName(Name))
LTOName = *OptionalLTOName;
if (Iter == NameLookup.end())
continue;