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,convert-cf-to-llvm,reconcile-unrealized-casts)" \ 2// RUN: | mlir-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 8 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 13 14func.func @main() { 15 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 21 async.yield %0 : f32 22 } 23 %1 = async.await %result : !async.value<f32> 24 25 // CHECK: 123.456 26 vector.print %1 : f32 27 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 34 async.yield %2 : f32 35 } 36 %3 = async.await %result2 : !async.value<f32> 37 async.yield %3 : f32 38 } 39 %4 = async.await %result0 : !async.value<f32> 40 41 // CHECK: 456.789 42 vector.print %4 : f32 43 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> 52 } 53 %6 = async.await %result2 : !async.value<memref<f32>> 54 %7 = memref.cast %6 : memref<f32> to memref<*xf32> 55 56 // CHECK: Unranked Memref 57 // CHECK-SAME: rank = 0 offset = 0 sizes = [] strides = [] 58 // CHECK-NEXT: [0.25] 59 call @printMemrefF32(%7): (memref<*xf32>) -> () 60 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> 68 async.yield 69 } 70 async.await %token3 : !async.token 71 72 // CHECK: Unranked Memref 73 // CHECK-SAME: rank = 0 offset = 0 sizes = [] strides = [] 74 // CHECK-NEXT: [0.5] 75 call @printMemrefF32(%7): (memref<*xf32>) -> () 76 77 memref.dealloc %6 : memref<f32> 78 79 return 80} 81 82func.func private @printMemrefF32(memref<*xf32>) 83 attributes { llvm.emit_c_interface } 84