<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64945>64945</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Coroutines] Support `@llvm.coro.await_suspend` actually 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:optimizations,
            missed-optimization,
            coroutines
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ChuanqiXu9
      </td>
    </tr>
</table>

<pre>
    After https://github.com/llvm/llvm-project/commit/c4672454743e942f148a1aff1e809dae73e464f6, we will add a `noinline` attribute to the await_suspend member function of an awaiter if the awaiter has any non static member functions.

Obviously, this decision will bring some performance regressions. e.g., https://github.com/llvm/llvm-project/issues/64933

The suggested long term solution is to introduce the new intrinisic:

```
call @llvm.coro.await_suspend(ptr %awaiter, ptr %handle,
 ptr @awaitSuspendFn)
```

Then in the middle end, we can perform analysis the awaitSuspendFn to see if the coroutine handle escapes or not. If it won't escape, we can replace above intrinsic to the direct call. Otherwise, we will only convert them in the CoroSplit phase.

The key point of the solution is that it is much easier and better to do analysis in the middle end instead of the frontend.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVMGO4zYM_Rr5QqzhyLITH3yYziBAT3uYHnorZIm22cqSK9ETpF9fyJnMZLdFgWKBILYlUXzv8ZE6JZo8Yi-an0TzUuiN5xD753nT_k_6deuKIdhr_zQyRpiZ1yTqJyHPQp4n4nkbShMWIc_Ovd0fX9YYfkfDQp5NWBbaX1R7lKpRR1Vjp-R4UCd90ON4wFPVWY3HGlWrxlbIZ7ggXMg50NaCBtFWPpB35FG0FWjmSMPGCByAZwR90cS_pS2t6C0suAwYYdy8YQoewgja385gBBo_QzIdnUD7K_jgIbFmMt_Hp1JUL6J6uv1_Hd4obMldM0qeKYFFQynn2QEPkfwEKSwIK8YxxEV7gxBxipjSfh1gOZU5_H9LSSltmIQ8t6qr60dYv8wIaZsmTIwWXPATMMYFUnDbLgKlLBZ5jsFuBncNPF72FfKUyGQgDzeKtnr_7Z9GOwdCVRlRaUIM5TeiC3laOYKQzbuwmd_7yqy9dSjk8-2m27Kq9oOvt_CzF7L717wf9DyQ31EvZK1D2JPuRjHa37UG7bW7pkz2XuOPDJl_QrwbIHPYmDzCDR9gMnrFBCGCD1zCzyMQwyV4IY_8vvuQMeLqtEHQQ3jDdxkTmbslLUU0DFm2Er7yjPFCCR-tHby7ggn-DSPnkOVO8DnE8Lo6YlhnnbD8vs5_4BXWQJ6zs3PAN0WeNWfclGDZzAyoE2EE7S0MyNnxHMCGT6H-oSqQT4za3m8fY_CM3paF7Wvb1Z0usD-0nTyp-lh3xdyP1Xhsmg7rZrD16VDJoT6ZscWx1bI61rqgXlayrk5SVVLKQ1c2x0qqqj7Vqm7tUR2EqnDR5MrdXiFOxW71vlWdagqnB3Rpn05S7p1RP4WVaaG_9N6hQspsLykXSgntl8fNj72Pgu_Hm5ci9nt7DduUsrEpcfrMz8RuH4jPn2HNC7xu6xoi54n0H82QZ5ThTTt3hWKLrv-hTlfN3wEAAP__yRTfYg">