1 // Check if mlir marks the corresponding function with required coroutine attribute.
3 // RUN: mlir-opt %s -pass-pipeline="builtin.module(async-to-async-runtime,func.func(async-runtime-ref-counting,async-runtime-ref-counting-opt),convert-async-to-llvm,func.func(convert-linalg-to-loops,convert-scf-to-cf),finalize-memref-to-llvm,func.func(convert-arith-to-llvm),convert-func-to-llvm,reconcile-unrealized-casts)" \
6 // CHECK: llvm.func @async_execute_fn{{.*}}attributes{{.*}}presplitcoroutine
7 // CHECK: llvm.func @async_execute_fn_0{{.*}}attributes{{.*}}presplitcoroutine
8 // CHECK: llvm.func @async_execute_fn_1{{.*}}attributes{{.*}}presplitcoroutine
11 %i0 = arith.constant 0 : index
12 %i1 = arith.constant 1 : index
13 %i2 = arith.constant 2 : index
14 %i3 = arith.constant 3 : index
16 %c0 = arith.constant 0.0 : f32
17 %c1 = arith.constant 1.0 : f32
18 %c2 = arith.constant 2.0 : f32
19 %c3 = arith.constant 3.0 : f32
20 %c4 = arith.constant 4.0 : f32
22 %A = memref.alloc() : memref<4xf32>
23 linalg.fill ins(%c0 : f32) outs(%A : memref<4xf32>)
25 %U = memref.cast %A : memref<4xf32> to memref<*xf32>
26 call @printMemrefF32(%U): (memref<*xf32>) -> ()
28 memref.store %c1, %A[%i0]: memref<4xf32>
29 call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
30 call @printMemrefF32(%U): (memref<*xf32>) -> ()
32 %outer = async.execute {
33 memref.store %c2, %A[%i1]: memref<4xf32>
34 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
35 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
37 // No op async region to create a token for testing async dependency.
38 %noop = async.execute {
39 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
43 %inner = async.execute [%noop] {
44 memref.store %c3, %A[%i2]: memref<4xf32>
45 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
46 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
50 async.await %inner : !async.token
52 memref.store %c4, %A[%i3]: memref<4xf32>
53 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
54 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
58 async.await %outer : !async.token
60 call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
61 call @printMemrefF32(%U): (memref<*xf32>) -> ()
63 memref.dealloc %A : memref<4xf32>
68 func.func private @mlirAsyncRuntimePrintCurrentThreadId() -> ()
70 func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface }