llvm-project
70 строк · 2.5 Кб
1// Check if mlir marks the corresponding function with required coroutine attribute.
2//
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)" \
4// RUN: | FileCheck %s
5
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
9
10func.func @main() {
11%i0 = arith.constant 0 : index
12%i1 = arith.constant 1 : index
13%i2 = arith.constant 2 : index
14%i3 = arith.constant 3 : index
15
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
21
22%A = memref.alloc() : memref<4xf32>
23linalg.fill ins(%c0 : f32) outs(%A : memref<4xf32>)
24
25%U = memref.cast %A : memref<4xf32> to memref<*xf32>
26call @printMemrefF32(%U): (memref<*xf32>) -> ()
27
28memref.store %c1, %A[%i0]: memref<4xf32>
29call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
30call @printMemrefF32(%U): (memref<*xf32>) -> ()
31
32%outer = async.execute {
33memref.store %c2, %A[%i1]: memref<4xf32>
34func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
35func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
36
37// No op async region to create a token for testing async dependency.
38%noop = async.execute {
39func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
40async.yield
41}
42
43%inner = async.execute [%noop] {
44memref.store %c3, %A[%i2]: memref<4xf32>
45func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
46func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
47
48async.yield
49}
50async.await %inner : !async.token
51
52memref.store %c4, %A[%i3]: memref<4xf32>
53func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
54func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
55
56async.yield
57}
58async.await %outer : !async.token
59
60call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
61call @printMemrefF32(%U): (memref<*xf32>) -> ()
62
63memref.dealloc %A : memref<4xf32>
64
65return
66}
67
68func.func private @mlirAsyncRuntimePrintCurrentThreadId() -> ()
69
70func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface }
71