[llvm] [ObjCARC] Delete empty autoreleasepools with no autoreleases in them (PR #144788)
Jon Roelofs via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 18 18:12:08 PDT 2025
================
@@ -2485,6 +2490,197 @@ bool ObjCARCOpt::run(Function &F, AAResults &AA) {
return Changed;
}
+/// Helper function to recursively check if a value eventually leads to the
+/// target instruction through pointer casts and uses, up to a specified depth.
+static bool checkLeadsToTarget(Value *Val, User *Target, unsigned MaxDepth,
+ SmallPtrSet<Value *, 8> &Visited) {
+ if (MaxDepth == 0)
+ return false;
+
+ // Avoid infinite recursion by tracking visited values
+ if (!Visited.insert(Val).second)
+ return false;
+
+ for (User *U : Val->users()) {
+ if (U == Target)
+ return true;
+
+ // For pointer casts, recursively check their users
+ if (isa<CastInst>(U)) {
+ if (checkLeadsToTarget(cast<Value>(U), Target, MaxDepth - 1, Visited)) {
+ return true;
+ }
----------------
jroelofs wrote:
no need for `{}`s on one-liner `if`s. (which you should do that pretty much everywhere)
also, `User` inherits from `Value`, so the cast is just noise.
that said, as a higher-level comment, if I'm reading this correctly, I think it would be much more efficient to look from the target, strip pointer casts from it, and see if that points at the `PendingPush`.
https://github.com/llvm/llvm-project/pull/144788
More information about the llvm-commits
mailing list