1 // 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-arith-to-llvm),convert-vector-to-llvm,finalize-memref-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts)" \
2 // RUN: | mlir-cpu-runner \
3 // RUN: -e main -entry-point-result=void -O0 \
4 // RUN: -shared-libs=%mlir_c_runner_utils \
5 // RUN: -shared-libs=%mlir_runner_utils \
6 // RUN: -shared-libs=%mlir_async_runtime \
7 // RUN: | FileCheck %s --dump-input=always
9 // FIXME: https://github.com/llvm/llvm-project/issues/57231
10 // UNSUPPORTED: hwasan
11 // FIXME: Windows does not have aligned_alloc
12 // UNSUPPORTED: system-windows
16 // ------------------------------------------------------------------------ //
17 // Blocking async.await outside of the async.execute.
18 // ------------------------------------------------------------------------ //
19 %token, %result = async.execute -> !async.value<f32> {
20 %0 = arith.constant 123.456 : f32
23 %1 = async.await %result : !async.value<f32>
28 // ------------------------------------------------------------------------ //
29 // Non-blocking async.await inside the async.execute
30 // ------------------------------------------------------------------------ //
31 %token0, %result0 = async.execute -> !async.value<f32> {
32 %token1, %result2 = async.execute -> !async.value<f32> {
33 %2 = arith.constant 456.789 : f32
36 %3 = async.await %result2 : !async.value<f32>
39 %4 = async.await %result0 : !async.value<f32>
44 // ------------------------------------------------------------------------ //
45 // Memref allocated inside async.execute region.
46 // ------------------------------------------------------------------------ //
47 %token2, %result2 = async.execute[%token0] -> !async.value<memref<f32>> {
48 %5 = memref.alloc() : memref<f32>
49 %c0 = arith.constant 0.25 : f32
50 memref.store %c0, %5[]: memref<f32>
51 async.yield %5 : memref<f32>
53 %6 = async.await %result2 : !async.value<memref<f32>>
54 %7 = memref.cast %6 : memref<f32> to memref<*xf32>
56 // CHECK: Unranked Memref
57 // CHECK-SAME: rank = 0 offset = 0 sizes = [] strides = []
59 call @printMemrefF32(%7): (memref<*xf32>) -> ()
61 // ------------------------------------------------------------------------ //
62 // Memref passed as async.execute operand.
63 // ------------------------------------------------------------------------ //
64 %token3 = async.execute(%result2 as %unwrapped : !async.value<memref<f32>>) {
65 %8 = memref.load %unwrapped[]: memref<f32>
66 %9 = arith.addf %8, %8 : f32
67 memref.store %9, %unwrapped[]: memref<f32>
70 async.await %token3 : !async.token
72 // CHECK: Unranked Memref
73 // CHECK-SAME: rank = 0 offset = 0 sizes = [] strides = []
75 call @printMemrefF32(%7): (memref<*xf32>) -> ()
77 memref.dealloc %6 : memref<f32>
82 func.func private @printMemrefF32(memref<*xf32>)
83 attributes { llvm.emit_c_interface }