[PATCH] D154749: [BOLT][NFC] Simplify DataAggregator/YAMLProfileReader

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 7 14:18:04 PDT 2023


Amir created this revision.
Amir added a reviewer: bolt.
Herald added a reviewer: rafauler.
Herald added subscribers: treapster, ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, yota9.
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154749

Files:
  bolt/lib/Profile/DataAggregator.cpp
  bolt/lib/Profile/YAMLProfileReader.cpp


Index: bolt/lib/Profile/YAMLProfileReader.cpp
===================================================================
--- bolt/lib/Profile/YAMLProfileReader.cpp
+++ bolt/lib/Profile/YAMLProfileReader.cpp
@@ -62,13 +62,9 @@
 }
 
 bool YAMLProfileReader::hasLocalsWithFileName() const {
-  for (const StringMapEntry<yaml::bolt::BinaryFunctionProfile *> &KV :
-       ProfileNameToProfile) {
-    const StringRef &FuncName = KV.getKey();
-    if (FuncName.count('/') == 2 && FuncName[0] != '/')
-      return true;
-  }
-  return false;
+  return llvm::any_of(ProfileNameToProfile.keys(), [](StringRef FuncName) {
+    return FuncName.count('/') == 2 && FuncName[0] != '/';
+  });
 }
 
 bool YAMLProfileReader::parseFunctionProfile(
Index: bolt/lib/Profile/DataAggregator.cpp
===================================================================
--- bolt/lib/Profile/DataAggregator.cpp
+++ bolt/lib/Profile/DataAggregator.cpp
@@ -1468,13 +1468,10 @@
     NumTraces += parseLBRSample(Sample, NeedsSkylakeFix);
   }
 
-  for (const auto &LBR : BranchLBRs) {
-    const Trace &Trace = LBR.first;
-    if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Trace.From))
-      BF->setHasProfileAvailable();
-    if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Trace.To))
-      BF->setHasProfileAvailable();
-  }
+  for (const Trace &Trace : llvm::make_first_range(BranchLBRs))
+    for (const uint64_t Addr : {Trace.From, Trace.To})
+      if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Addr))
+        BF->setHasProfileAvailable();
 
   auto printColored = [](raw_ostream &OS, float Percent, float T1, float T2) {
     OS << " (";
@@ -1710,12 +1707,9 @@
     if (std::error_code EC = AggrEntry.getError())
       return EC;
 
-    if (BinaryFunction *BF =
-            getBinaryFunctionContainingAddress(AggrEntry->From.Offset))
-      BF->setHasProfileAvailable();
-    if (BinaryFunction *BF =
-            getBinaryFunctionContainingAddress(AggrEntry->To.Offset))
-      BF->setHasProfileAvailable();
+    for (const uint64_t Addr : {AggrEntry->From.Offset, AggrEntry->To.Offset})
+      if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Addr))
+        BF->setHasProfileAvailable();
 
     AggregatedLBRs.emplace_back(std::move(AggrEntry.get()));
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154749.538269.patch
Type: text/x-patch
Size: 2285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230707/c1f8cbc7/attachment.bin>


More information about the llvm-commits mailing list