[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 17 19:53:13 PST 2024


================
@@ -173,19 +173,36 @@ static bool ResumeStmtCanThrow(const Stmt *S) {
   return false;
 }
 
+static bool AwaitSuspendStmtCanThrow(const Stmt *S) {
+  return ResumeStmtCanThrow(S);
+}
+
 // Emit suspend expression which roughly looks like:
 //
 //   auto && x = CommonExpr();
 //   if (!x.await_ready()) {
 //      llvm_coro_save();
-//      x.await_suspend(...);     (*)
+//      llvm_coro_await_suspend(&x, frame, wrapper) (*)
 //      llvm_coro_suspend(); (**)
 //   }
 //   x.await_resume();
 //
 // where the result of the entire expression is the result of x.await_resume()
 //
-//   (*) If x.await_suspend return type is bool, it allows to veto a suspend:
+//   (*) llvm_coro_await_suspend_{void, bool, handle} is lowered to
+//      wrapper(&x, frame) when it's certain not to interfere with
+//      coroutine transform. await_suspend expression is
+//      asynchronous to the coroutine body and not all analyses
+//      and transformations can handle it correctly at the moment.
+//
+//      Wrapper function encapsulates x.await_suspend(...) call and looks like:
+//
+//      auto __await_suspend_wrapper(auto& awaiter, void* frame) {
+//        std::coroutine_handle<> handle(frame);
+//        return awaiter.await_suspend(handle);
+//      }
+//
+//      If x.await_suspend return type is bool, it allows to veto a suspend:
----------------
ChuanqiXu9 wrote:

```suggestion
//    (**) If x.await_suspend return type is bool, it allows to veto a suspend:
```

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


More information about the cfe-commits mailing list