[llvm-branch-commits] [BOLT] Name similarity function matching (PR #95884)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jun 17 23:14:49 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: shaw young (shawbyoung)
<details>
<summary>Changes</summary>
Matching functions based on edit
distance.
Test Plan: tbd
---
Full diff: https://github.com/llvm/llvm-project/pull/95884.diff
1 Files Affected:
- (modified) bolt/lib/Profile/YAMLProfileReader.cpp (+29)
``````````diff
diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp
index f25f59201f1cd..a4f8ba9a440b6 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -13,6 +13,7 @@
#include "bolt/Profile/ProfileYAMLMapping.h"
#include "bolt/Utils/Utils.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/edit_distance.h"
#include "llvm/Support/CommandLine.h"
using namespace llvm;
@@ -23,6 +24,10 @@ extern cl::opt<unsigned> Verbosity;
extern cl::OptionCategory BoltOptCategory;
extern cl::opt<bool> InferStaleProfile;
+cl::opt<unsigned> NameSimilarityFunctionMatchingThreshold(
+ "name-similarity-function-matching-threshold", cl::desc("edit distance."),
+ cl::init(0), cl::Hidden, cl::cat(BoltOptCategory));
+
static llvm::cl::opt<bool>
IgnoreHash("profile-ignore-hash",
cl::desc("ignore hash while reading function profile"),
@@ -415,6 +420,30 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
if (!YamlBF.Used && BF && !ProfiledFunctions.count(BF))
matchProfileToFunction(YamlBF, *BF);
+ // Uses name similarity to match functions that were not matched by name.
+ for (auto YamlBF : YamlBP.Functions) {
+ if (YamlBF.Used)
+ continue;
+
+ unsigned MinEditDistance = UINT_MAX;
+ BinaryFunction *ClosestNameBF = nullptr;
+
+ for (auto &[_, BF] : BC.getBinaryFunctions()) {
+ if (ProfiledFunctions.count(&BF))
+ continue;
+
+ unsigned BFEditDistance = BF.getOneName().edit_distance(YamlBF.Name);
+ if (BFEditDistance < MinEditDistance) {
+ MinEditDistance = BFEditDistance;
+ ClosestNameBF = &BF;
+ }
+ }
+
+ if (ClosestNameBF &&
+ MinEditDistance < opts::NameSimilarityFunctionMatchingThreshold)
+ matchProfileToFunction(YamlBF, *ClosestNameBF);
+ }
+
for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions)
if (!YamlBF.Used && opts::Verbosity >= 1)
errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name
``````````
</details>
https://github.com/llvm/llvm-project/pull/95884
More information about the llvm-branch-commits
mailing list