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

Alan Zhao via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 20:05:09 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);
----------------
alanzhao1 wrote:

If I understand your comment correctly, you're suggesting that I pass a `SingleEntrySet<const BasicBlock *>` to `isReachableImpl(...)` when implementing `isPotentiallyReachableFromMany(...)` in order to remove all the `if` statements. This would require `SingleEntrySet` to be iterable (since we iterate through the elements of `StopSet`), which drives up the complexity of the class further.

(We could do something like

```cpp
template <class T>
class SingleEntrySet {
  using iterator = T*;
  T Elem;  
  iterator begin() { return &Elem; }
  iterator end() { return &Elem + 1; }
};
```

but this is UB)

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


More information about the llvm-commits mailing list