[PATCH] D156043: [BOLT][NFC] Simplify YAMLProfileReader

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 08:26:26 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe8a75c3f6eca: [BOLT][NFC] Simplify YAMLProfileReader (authored by Amir).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156043/new/

https://reviews.llvm.org/D156043

Files:
  bolt/include/bolt/Profile/YAMLProfileReader.h
  bolt/lib/Profile/YAMLProfileReader.cpp


Index: bolt/lib/Profile/YAMLProfileReader.cpp
===================================================================
--- bolt/lib/Profile/YAMLProfileReader.cpp
+++ bolt/lib/Profile/YAMLProfileReader.cpp
@@ -36,13 +36,12 @@
 namespace bolt {
 
 bool YAMLProfileReader::isYAML(const StringRef Filename) {
-  ErrorOr<std::unique_ptr<MemoryBuffer>> MB =
-      MemoryBuffer::getFileOrSTDIN(Filename);
-  if (std::error_code EC = MB.getError())
-    report_error(Filename, EC);
-  StringRef Buffer = MB.get()->getBuffer();
-  if (Buffer.startswith("---\n"))
-    return true;
+  if (auto MB = MemoryBuffer::getFileOrSTDIN(Filename)) {
+    StringRef Buffer = (*MB)->getBuffer();
+    return Buffer.startswith("---\n");
+  } else {
+    report_error(Filename, MB.getError());
+  }
   return false;
 }
 
@@ -66,13 +65,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(
@@ -327,12 +322,9 @@
 
   auto profileMatches = [](const yaml::bolt::BinaryFunctionProfile &Profile,
                            BinaryFunction &BF) {
-    if (opts::IgnoreHash && Profile.NumBasicBlocks == BF.size())
-      return true;
-    if (!opts::IgnoreHash &&
-        Profile.Hash == static_cast<uint64_t>(BF.getHash()))
-      return true;
-    return false;
+    if (opts::IgnoreHash)
+      return Profile.NumBasicBlocks == BF.size();
+    return Profile.Hash == static_cast<uint64_t>(BF.getHash());
   };
 
   // We have to do 2 passes since LTO introduces an ambiguity in function
Index: bolt/include/bolt/Profile/YAMLProfileReader.h
===================================================================
--- bolt/include/bolt/Profile/YAMLProfileReader.h
+++ bolt/include/bolt/Profile/YAMLProfileReader.h
@@ -51,17 +51,17 @@
   /// Map a function ID from a YAML profile to a BinaryFunction object.
   std::vector<BinaryFunction *> YamlProfileToFunction;
 
+  using FunctionSet = std::unordered_set<const BinaryFunction *>;
   /// To keep track of functions that have a matched profile before the profile
   /// is attributed.
-  std::unordered_set<const BinaryFunction *> ProfiledFunctions;
+  FunctionSet ProfiledFunctions;
 
   /// For LTO symbol resolution.
   /// Map a common LTO prefix to a list of YAML profiles matching the prefix.
   StringMap<std::vector<yaml::bolt::BinaryFunctionProfile *>> LTOCommonNameMap;
 
   /// Map a common LTO prefix to a set of binary functions.
-  StringMap<std::unordered_set<const BinaryFunction *>>
-      LTOCommonNameFunctionMap;
+  StringMap<FunctionSet> LTOCommonNameFunctionMap;
 
   /// Strict matching of a name in a profile to its contents.
   StringMap<yaml::bolt::BinaryFunctionProfile *> ProfileNameToProfile;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156043.544382.patch
Type: text/x-patch
Size: 3093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230726/8456fea1/attachment.bin>


More information about the llvm-commits mailing list