[llvm] [coro][pgp] Do not insert counters in the `suspend` block (PR #71262)

Wei Wang via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 15:36:16 PST 2023


================
@@ -92,6 +94,39 @@ template <class Edge, class BBInfo> class CFGMST {
     return It->second.get();
   }
 
+  void handleCoroSuspendEdge(Edge *E) {
+    // We must not add instrumentation to the BB representing the
+    // "suspend" path, else CoroSplit won't be able to lower
+    // llvm.coro.suspend to a tail call. We do want profiling info for
+    // the other branches (resume/destroy). So we do 2 things:
+    // 1. we prefer instrumenting those other edges by setting the weight
+    //    of the "suspend" edge to max, and
+    // 2. we mark the edge as "Removed" to guarantee it is not considered
+    //    for instrumentation. That could technically happen:
+    //    (from test/Transforms/Coroutines/coro-split-musttail.ll)
+    //
+    // %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
----------------
apolloww wrote:

`llvm.coro.suspend` is lowered to either 0 in `.resume` function or 1 in .destroy/.cleanup function. 

When `await_suspend` returns a handle, we always want the following call to its `.resume` function to be a tail call in order to have symmetric transfer to work.

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


More information about the llvm-commits mailing list