[llvm] Reapply "[coro][CoroSplit] Use `llvm.lifetime.end` to compute putting objects on the frame vs the stack (#90265) (PR #91372)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun May 12 23:58:40 PDT 2024


================
@@ -130,14 +130,35 @@ static const Loop *getOutermostLoop(const LoopInfo *LI, const BasicBlock *BB) {
   return L ? L->getOutermostLoop() : nullptr;
 }
 
-bool llvm::isPotentiallyReachableFromMany(
-    SmallVectorImpl<BasicBlock *> &Worklist, const BasicBlock *StopBB,
-    const SmallPtrSetImpl<BasicBlock *> *ExclusionSet, const DominatorTree *DT,
-    const LoopInfo *LI) {
-  // When the stop block is unreachable, it's dominated from everywhere,
+template <class T, bool IsMany>
+static bool isReachableImpl(SmallVectorImpl<BasicBlock *> &Worklist,
+                            const T *StopBBOrSet,
+                            const SmallPtrSetImpl<BasicBlock *> *ExclusionSet,
+                            const DominatorTree *DT, const LoopInfo *LI) {
+  const BasicBlock *StopBB;
+  const SmallPtrSetImpl<const BasicBlock *> *StopSet;
+
+  // SmallPtrSetImpl is incompatible with LLVM's casting functions.
+  if constexpr (IsMany)
+    StopSet =
+        static_cast<const SmallPtrSetImpl<const BasicBlock *> *>(StopBBOrSet);
+  else
+    StopBB = static_cast<const BasicBlock *>(StopBBOrSet);
----------------
nikic wrote:

Something like https://github.com/nikic/llvm-project/commit/932822472eeba688e5bfcb6a3ffc6c0f79f69dd4, though it would be nice to also avoid the StopLoops conditional...

I don't think we need StopBBReachable -- setting DT to nullptr if any one is unreachable is fine here (DT is only an optimization, and unreachable block is an unlikely edge case).

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


More information about the llvm-commits mailing list