[llvm] [FuncAttrs][LTO] Relax norecurse attribute inference during postlink LTO (PR #158608)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 17 09:19:39 PDT 2025
================
@@ -2067,6 +2067,36 @@ static void inferAttrsFromFunctionBodies(const SCCNodeSet &SCCNodes,
AI.run(SCCNodes, Changed);
}
+// Determines if the function 'F' can be marked 'norecurse'.
+// It returns true if any call within 'F' could lead to a recursive
+// call back to 'F', and false otherwise.
+// The 'AnyFunctionsAddressIsTaken' parameter is a module-wide flag
+// that is true if any function's address is taken, or if any function
+// has external linkage. This is used to determine the safety of
+// external/library calls.
+static bool hasRecursiveCallee(Function &F,
+ bool AnyFunctionsAddressIsTaken = true) {
+ for (const auto &BB : F) {
+ for (const auto &I : BB.instructionsWithoutDebug()) {
+ if (const auto *CB = dyn_cast<CallBase>(&I)) {
+ const Function *Callee = CB->getCalledFunction();
+ if (!Callee || Callee == &F)
----------------
david-arm wrote:
We return true from `hasRecursiveCallee` when Callee is null, which suggests we know the callee is recursive. However, I think what we're really saying is that "it may be recursive, but we don't know for sure". Maybe it's worth renaming the function to `mayHaveRecursiveCallee`?
https://github.com/llvm/llvm-project/pull/158608
More information about the llvm-commits
mailing list