[llvm] [FuncAttrs] Relax norecurse attribute inference (PR #139943)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 20 07:44:44 PDT 2025


================
@@ -2322,8 +2338,39 @@ PreservedAnalyses PostOrderFunctionAttrsPass::run(LazyCallGraph::SCC &C,
     Functions.push_back(&N.getFunction());
   }
 
-  auto ChangedFunctions =
-      deriveAttrsInPostOrder(Functions, AARGetter, ArgAttrsOnly);
+  bool NoFunctionsAddressIsTaken = false;
+  // Check if any function in the whole program has its address taken or has
+  // potentially external linkage.
+  // We use this information when inferring norecurse attribute: If there is
+  // no function whose address is taken and all functions have internal
+  // linkage, there is no path for a callback to any user function.
+  if (IsLTOPostLink) {
----------------
david-arm wrote:

Is it worth adding an option near the top of this file like this:

```
static cl::opt<bool> ForceLTOFuncAttrs(
    "force-lto-funcattrs", cl::init(false), cl::Hidden,
    cl::desc("Force LTO behaviour of function-attrs pass. Intended for testing"
             "purposes only"));
```

? If you do this you can then change the if check above to be:

```
  if (IsLTOPostLink || ForceLTOFuncAttrs) {
...
```

and change the RUN lines in the tests to use `opt -p function-attrs -force-lto-funcattrs -S` instead of `opt -p lto<O2>`? That will ensure the tests run faster and don't test the whole pipeline.

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


More information about the llvm-commits mailing list