[llvm-branch-commits] [llvm] [BOLT] Name similarity function matching (PR #95884)
Maksim Panchenko via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jun 27 14:45:42 PDT 2024
================
@@ -415,11 +423,116 @@ 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.
+ uint64_t MatchedWithNameSimilarity = 0;
+
+ if (opts::NameSimilarityFunctionMatchingThreshold > 0) {
+ ItaniumPartialDemangler ItaniumPartialDemangler;
+
+ auto DemangleName = [&](std::string &FunctionName) {
+ StringRef RestoredName = NameResolver::restore(FunctionName);
+ return demangle(RestoredName);
+ };
+
+ auto DeriveNameSpace = [&](std::string &DemangledName) {
+ if (ItaniumPartialDemangler.partialDemangle(DemangledName.c_str()))
+ return std::string("");
+ std::vector<char> Buffer(DemangledName.begin(), DemangledName.end());
+ size_t BufferSize = Buffer.size();
+ char *NameSpace = ItaniumPartialDemangler.getFunctionDeclContextName(
+ &Buffer[0], &BufferSize);
+ return NameSpace ? std::string(NameSpace) : std::string("");
+ };
+
+ // Preprocessing YamlBFs to minimize the number of BFs to process.
+ std::unordered_map<std::string, std::set<uint32_t>>
+ NamespaceToProfiledBFSizes;
+ NamespaceToProfiledBFSizes.reserve(YamlBP.Functions.size());
+ std::vector<std::string> ProfileBFDemangledNames;
+ ProfileBFDemangledNames.reserve(YamlBP.Functions.size());
+ std::vector<std::string> ProfiledBFNamespaces;
+ ProfiledBFNamespaces.reserve(YamlBP.Functions.size());
+
+ for (auto &YamlBF : YamlBP.Functions) {
+ std::string YamlBFDemangledName = DemangleName(YamlBF.Name);
+ ProfileBFDemangledNames.push_back(YamlBFDemangledName);
+ std::string YamlBFNamespace = DeriveNameSpace(YamlBFDemangledName);
+ ProfiledBFNamespaces.push_back(YamlBFNamespace);
+ NamespaceToProfiledBFSizes[YamlBFNamespace].insert(YamlBF.NumBasicBlocks);
+ }
+
+ std::unordered_map<std::string, std::vector<BinaryFunction *>>
----------------
maksfb wrote:
Same for `StringMap`.
https://github.com/llvm/llvm-project/pull/95884
More information about the llvm-branch-commits
mailing list