[llvm] [BOLT] Use restored names in funcs-{, file-}no-regex (PR #127738)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 18 19:18:21 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)

<details>
<summary>Changes</summary>

Since function names given via funcs-no-regex are supposed to be verbatim
and don't contain BOLT-added suffixes, the check should use "restored"
BinaryFunction names stripped of suffixes.

Test Plan: added funcs-no-regex.s


---
Full diff: https://github.com/llvm/llvm-project/pull/127738.diff


2 Files Affected:

- (modified) bolt/lib/Rewrite/RewriteInstance.cpp (+5-5) 
- (added) bolt/test/X86/funcs-no-regex.s (+16) 


``````````diff
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 4329235d47049..13e7e52dc5691 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -2976,8 +2976,7 @@ void RewriteInstance::selectFunctionsToProcess() {
   populateFunctionNames(opts::FunctionNamesFileNR, opts::ForceFunctionNamesNR);
 
   // Make a set of functions to process to speed up lookups.
-  std::unordered_set<std::string> ForceFunctionsNR(
-      opts::ForceFunctionNamesNR.begin(), opts::ForceFunctionNamesNR.end());
+  StringSet<> ForceFunctionsNR(opts::ForceFunctionNamesNR);
 
   if ((!opts::ForceFunctionNames.empty() ||
        !opts::ForceFunctionNamesNR.empty()) &&
@@ -3051,9 +3050,10 @@ void RewriteInstance::selectFunctionsToProcess() {
           return true;
 
       // Non-regex check (-funcs-no-regex and -funcs-file-no-regex).
-      for (const StringRef Name : Function.getNames())
-        if (ForceFunctionsNR.count(Name.str()))
-          return true;
+      if (Function.forEachName([&](StringRef Name) {
+            return ForceFunctionsNR.contains(NameResolver::restore(Name));
+          }))
+        return true;
 
       return false;
     }
diff --git a/bolt/test/X86/funcs-no-regex.s b/bolt/test/X86/funcs-no-regex.s
new file mode 100644
index 0000000000000..a2cf8c1e91ce7
--- /dev/null
+++ b/bolt/test/X86/funcs-no-regex.s
@@ -0,0 +1,16 @@
+## Checks handling of function names passed via -funcs-no-regex
+
+# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
+# RUN: ld.lld %t.o -o %t.exe -nostdlib
+# RUN: llvm-bolt %t.exe -o %t.out -funcs-no-regex=func -print-cfg | FileCheck %s
+# CHECK: Binary Function "func/1"
+
+.globl _start
+.type _start, @function
+_start:
+  ret
+  .size _start, .-_start
+
+.type func, @function
+func:
+  ud2

``````````

</details>


https://github.com/llvm/llvm-project/pull/127738


More information about the llvm-commits mailing list