Files
clang-p2996/mlir/test/mlir-cpu-runner/async-value.mlir
Matthias Springer eb6c4197d5 [mlir][CF] Split cf-to-llvm from func-to-llvm (#120580)
Do not run `cf-to-llvm` as part of `func-to-llvm`. This commit fixes
https://github.com/llvm/llvm-project/issues/70982.

This commit changes the way how `func.func` ops are lowered to LLVM.
Previously, the signature of the entire region (i.e., entry block and
all other blocks in the `func.func` op) was converted as part of the
`func.func` lowering pattern.

Now, only the entry block is converted. The remaining block signatures
are converted together with `cf.br` and `cf.cond_br` as part of
`cf-to-llvm`. All unstructured control flow is not converted as part of
a single pass (`cf-to-llvm`). `func-to-llvm` no longer deals with
unstructured control flow.

Also add more test cases for control flow dialect ops.

Note: This PR is in preparation of #120431, which adds an additional
GPU-specific lowering for `cf.assert`. This was a problem because
`cf.assert` used to be converted as part of `func-to-llvm`.

Note for LLVM integration: If you see failures, add
`-convert-cf-to-llvm` to your pass pipeline.
2024-12-20 13:46:45 +01:00

84 lines
3.3 KiB
MLIR

// 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)" \
// RUN: | mlir-cpu-runner \
// RUN: -e main -entry-point-result=void -O0 \
// RUN: -shared-libs=%mlir_c_runner_utils \
// RUN: -shared-libs=%mlir_runner_utils \
// RUN: -shared-libs=%mlir_async_runtime \
// RUN: | FileCheck %s --dump-input=always
// FIXME: https://github.com/llvm/llvm-project/issues/57231
// UNSUPPORTED: hwasan
// FIXME: Windows does not have aligned_alloc
// UNSUPPORTED: system-windows
func.func @main() {
// ------------------------------------------------------------------------ //
// Blocking async.await outside of the async.execute.
// ------------------------------------------------------------------------ //
%token, %result = async.execute -> !async.value<f32> {
%0 = arith.constant 123.456 : f32
async.yield %0 : f32
}
%1 = async.await %result : !async.value<f32>
// CHECK: 123.456
vector.print %1 : f32
// ------------------------------------------------------------------------ //
// Non-blocking async.await inside the async.execute
// ------------------------------------------------------------------------ //
%token0, %result0 = async.execute -> !async.value<f32> {
%token1, %result2 = async.execute -> !async.value<f32> {
%2 = arith.constant 456.789 : f32
async.yield %2 : f32
}
%3 = async.await %result2 : !async.value<f32>
async.yield %3 : f32
}
%4 = async.await %result0 : !async.value<f32>
// CHECK: 456.789
vector.print %4 : f32
// ------------------------------------------------------------------------ //
// Memref allocated inside async.execute region.
// ------------------------------------------------------------------------ //
%token2, %result2 = async.execute[%token0] -> !async.value<memref<f32>> {
%5 = memref.alloc() : memref<f32>
%c0 = arith.constant 0.25 : f32
memref.store %c0, %5[]: memref<f32>
async.yield %5 : memref<f32>
}
%6 = async.await %result2 : !async.value<memref<f32>>
%7 = memref.cast %6 : memref<f32> to memref<*xf32>
// CHECK: Unranked Memref
// CHECK-SAME: rank = 0 offset = 0 sizes = [] strides = []
// CHECK-NEXT: [0.25]
call @printMemrefF32(%7): (memref<*xf32>) -> ()
// ------------------------------------------------------------------------ //
// Memref passed as async.execute operand.
// ------------------------------------------------------------------------ //
%token3 = async.execute(%result2 as %unwrapped : !async.value<memref<f32>>) {
%8 = memref.load %unwrapped[]: memref<f32>
%9 = arith.addf %8, %8 : f32
memref.store %9, %unwrapped[]: memref<f32>
async.yield
}
async.await %token3 : !async.token
// CHECK: Unranked Memref
// CHECK-SAME: rank = 0 offset = 0 sizes = [] strides = []
// CHECK-NEXT: [0.5]
call @printMemrefF32(%7): (memref<*xf32>) -> ()
memref.dealloc %6 : memref<f32>
return
}
func.func private @printMemrefF32(memref<*xf32>)
attributes { llvm.emit_c_interface }