@@ -174,61 +174,6 @@ This may be acceptable if LLVM's coroutine support is primarily being
174
174
used for low-level lowering and inlining is expected to be applied
175
175
earlier in the pipeline.
176
176
177
- Async Lowering
178
- --------------
179
-
180
- In async-continuation lowering, signaled by the use of `llvm.coro.id.async `,
181
- handling of control-flow must be handled explicitly by the frontend.
182
-
183
- In this lowering, a coroutine is assumed to take the current `async context ` as
184
- its first argument. It is used to marshal arguments and return values of the
185
- coroutine. Therefore a async coroutine returns `void `.
186
-
187
- .. code-block :: llvm
188
- define swiftcc void @async_coroutine(i8* %async.ctxt, i8*, i8*) {
189
- }
190
-
191
-
192
- Every suspend point takes an `async context ` argument which provides the context
193
- and the coroutine frame of the callee function. Every
194
- suspend point has an associated `resume function ` denoted by the
195
- `llvm.coro.async.resume ` intrinsic. The coroutine is resumed by
196
- calling this `resume function ` passing the `async context ` as the first
197
- argument. It is assumed that the `resume function ` can restore its (the
198
- caller's) `async context ` by loading the first field in the `async context `.
199
-
200
- .. code-block :: c
201
-
202
- struct async_context {
203
- struct async_context *caller_context;
204
- ...
205
- }
206
-
207
- The frontend should provide a `async function pointer ` struct associated with
208
- each async coroutine by `llvm.coro.id.async `'s argument. The initial size and
209
- alignment of the `async context ` must be provided as arguments to the
210
- `llvm.coro.id.async ` intrinsic. Lowering will update the size entry with the
211
- coroutine frame requirements. The frontend is responsible for allocating the
212
- memory for the `async context ` but can use the `async function pointer ` struct
213
- to obtain the required size.
214
-
215
- .. code-block :: c
216
- struct async_function_pointer {
217
- uint32_t context_size;
218
- uint32_t relative_function_pointer_to_async_impl;
219
- }
220
-
221
- Lowering will split an async coroutine into a ramp function and one resume
222
- function per suspend point.
223
-
224
- How control-flow is passed between caller, suspension point, and back to
225
- resume function is left up to the frontend.
226
-
227
- The suspend point takes a function and its arguments. The function is intended
228
- to model the transfer to the callee function. It will be tail called by
229
- lowering and therefore must have the same signature and calling convention as
230
- the async coroutine.
231
-
232
177
Coroutines by Example
233
178
=====================
234
179
@@ -1148,45 +1093,6 @@ duplicated.
1148
1093
1149
1094
A frontend should emit exactly one `coro.id ` intrinsic per coroutine.
1150
1095
1151
- .. _coro.id.async :
1152
-
1153
- 'llvm.coro.id.async' Intrinsic
1154
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1155
- ::
1156
-
1157
- declare token @llvm.coro.id.async(i32 <context size>, i32 <align>,
1158
- i8* <context arg>,
1159
- i8* <async function pointer>)
1160
-
1161
- Overview:
1162
- """""""""
1163
-
1164
- The '``llvm.coro.id.async ``' intrinsic returns a token identifying an async coroutine.
1165
-
1166
- Arguments:
1167
- """"""""""
1168
-
1169
- The first argument provides the initial size of the `async context ` as required
1170
- from the frontend. Lowering will add to this size the size required by the frame
1171
- storage and store that value to the `async function pointer `.
1172
-
1173
- The second argument, is the alignment guarantee of the memory of the
1174
- `async context `. The frontend guarantees that the memory will be aligned by this
1175
- value.
1176
-
1177
- The third argument is the `async context ` argument in the current coroutine.
1178
-
1179
- The fourth argument is the address of the `async function pointer ` struct.
1180
- Lowering will update the context size requirement in this struct by adding the
1181
- coroutine frame size requirement to the initial size requirement as specified by
1182
- the first argument of this intrinisc.
1183
-
1184
-
1185
- Semantics:
1186
- """"""""""
1187
-
1188
- A frontend should emit exactly one `coro.id.async ` intrinsic per coroutine.
1189
-
1190
1096
.. _coro.id.retcon :
1191
1097
1192
1098
'llvm.coro.id.retcon' Intrinsic
@@ -1474,46 +1380,6 @@ to the coroutine:
1474
1380
switch i8 %suspend1, label %suspend [i8 0, label %resume1
1475
1381
i8 1, label %cleanup]
1476
1382
1477
- .. _coro.suspend.async :
1478
-
1479
- 'llvm.coro.suspend.async' Intrinsic
1480
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1481
- ::
1482
-
1483
- declare {i8*, i8*, i8*} @llvm.coro.suspend.async(i8* <resume function>,
1484
- i8* <callee context>,
1485
- ... <function to call>
1486
- ... <arguments to function>)
1487
-
1488
- Overview:
1489
- """""""""
1490
-
1491
- The '``llvm.coro.suspend.async ``' intrinsic marks the point where
1492
- execution of a async coroutine is suspended and control is passed to a callee.
1493
-
1494
- Arguments:
1495
- """"""""""
1496
-
1497
- The first argument should be the result of the `llvm.coro.async.resume ` intrinsic.
1498
- Lowering will replace this intrinsic with the resume function for this suspend
1499
- point.
1500
-
1501
- The second argument is the `async context ` allocation for the callee. It should
1502
- provide storage the `async context ` header and the coroutine frame.
1503
-
1504
- The third argument is the function that models tranfer to the callee at the
1505
- suspend point. It should take 3 arguments. Lowering will `musttail ` call this
1506
- function.
1507
-
1508
- The fourth to six argument are the arguments for the third argument.
1509
-
1510
- Semantics:
1511
- """"""""""
1512
-
1513
- The result of the intrinsic are mapped to the arguments of the resume function.
1514
- Execution is suspended at this intrinsic and resumed when the resume function is
1515
- called.
1516
-
1517
1383
.. _coro.suspend.retcon :
1518
1384
1519
1385
'llvm.coro.suspend.retcon' Intrinsic
0 commit comments