1 // RUN: mlir-opt %s -convert-async-to-llvm | FileCheck %s
3 // CHECK-LABEL: @coro_id
5 // CHECK: %0 = llvm.mlir.constant(0 : i32) : i32
6 // CHECK: %1 = llvm.mlir.null : !llvm.ptr<i8>
7 // CHECK: %2 = llvm.intr.coro.id %0, %1, %1, %1 : !llvm.token
12 // CHECK-LABEL: @coro_begin
14 // CHECK: %[[ID:.*]] = llvm.intr.coro.id
16 // CHECK: %[[SIZE:.*]] = llvm.intr.coro.size : i64
17 // CHECK: %[[ALLOC:.*]] = llvm.call @malloc(%[[SIZE]])
18 // CHECK: %[[HDL:.*]] = llvm.intr.coro.begin %[[ID]], %[[ALLOC]]
19 %1 = async.coro.begin %0
23 // CHECK-LABEL: @coro_free
25 // CHECK: %[[ID:.*]] = llvm.intr.coro.id
27 // CHECK: %[[HDL:.*]] = llvm.intr.coro.begin
28 %1 = async.coro.begin %0
29 // CHECK: %[[MEM:.*]] = llvm.intr.coro.free %[[ID]], %[[HDL]]
30 // CHECK: llvm.call @free(%[[MEM]])
31 async.coro.free %0, %1
35 // CHECK-LABEL: @coro_end
38 // CHECK: %[[HDL:.*]] = llvm.intr.coro.begin
39 %1 = async.coro.begin %0
40 // CHECK: %[[FALSE:.*]] = llvm.mlir.constant(false) : i1
41 // CHECK: llvm.intr.coro.end %[[HDL]], %[[FALSE]]
46 // CHECK-LABEL: @coro_save
49 // CHECK: %[[HDL:.*]] = llvm.intr.coro.begin
50 %1 = async.coro.begin %0
51 // CHECK: llvm.intr.coro.save %[[HDL]]
52 %2 = async.coro.save %1
56 // CHECK-LABEL: @coro_suspend
57 func @coro_suspend() {
59 // CHECK: %[[HDL:.*]] = llvm.intr.coro.begin
60 %1 = async.coro.begin %0
61 // CHECK: %[[STATE:.*]] = llvm.intr.coro.save %[[HDL]]
62 %2 = async.coro.save %1
64 // CHECK: %[[FINAL:.*]] = llvm.mlir.constant(false) : i1
65 // CHECK: %[[RET:.*]] = llvm.intr.coro.suspend %[[STATE]], %[[FINAL]]
66 // CHECK: %[[SEXT:.*]] = llvm.sext %[[RET]] : i8 to i32
67 // CHECK: llvm.switch %[[SEXT]] : i32, ^[[SUSPEND:[b0-9]+]]
68 // CHECK-NEXT: 0: ^[[RESUME:[b0-9]+]]
69 // CHECK-NEXT: 1: ^[[CLEANUP:[b0-9]+]]
70 async.coro.suspend %2, ^suspend, ^resume, ^cleanup
73 // CHECK: return {coro.resume}
74 return { coro.resume }
76 // CHECK: ^[[CLEANUP]]
77 // CHECK: return {coro.cleanup}
78 return { coro.cleanup }
80 // CHECK: ^[[SUSPEND]]
81 // CHECK: return {coro.suspend}
82 return { coro.suspend }