[llvm] [ObjCARC] Move autorelease-to-release conversion to pool pop site instead of converting in place (PR #152353)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 18 09:07:54 PDT 2026
================
@@ -601,6 +606,57 @@ class ObjCARCOpt {
};
} // end anonymous namespace
+/// Find the autoreleasePoolPop that will drain the given autorelease
+/// instruction in the same basic block, skipping over nested pools.
+///
+/// Since objc_autorelease does not change the refcount (it only registers the
+/// object for a deferred release at pool drain), we can move the release to
+/// just before the pool pop instead of converting in place. This avoids the
+/// need to check for uses of the pointer between the autorelease and the pop.
+Instruction *
+ObjCARCOpt::FindFollowingAutoreleasePoolPop(Instruction *AutoreleaseInst) {
+ assert(GetBasicARCInstKind(AutoreleaseInst) == ARCInstKind::Autorelease);
+
+ auto It = FollowingPoolPopCache.find(AutoreleaseInst);
+ if (It != FollowingPoolPopCache.end())
+ return It->second;
+
+ BasicBlock *BB = AutoreleaseInst->getParent();
+ Instruction *Result = nullptr;
+
+ SmallVector<Instruction *, 4> ScopeSiblings;
+
+ int Depth = 0;
+ for (BasicBlock::iterator I = std::next(AutoreleaseInst->getIterator()),
+ E = BB->end();
+ I != E; ++I) {
+ ARCInstKind Class = GetBasicARCInstKind(&*I);
----------------
AZero13 wrote:
You are right. So I fixed that!
https://github.com/llvm/llvm-project/pull/152353
More information about the llvm-commits
mailing list