File: convert-coro-to-llvm.mlir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (90 lines) | stat: -rw-r--r-- 2,994 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// RUN: mlir-opt %s -convert-async-to-llvm='use-opaque-pointers=1' | FileCheck %s

// CHECK-LABEL: @coro_id
func.func @coro_id() {
  // CHECK: %0 = llvm.mlir.constant(0 : i32) : i32
  // CHECK: %1 = llvm.mlir.null : !llvm.ptr
  // CHECK: %2 = llvm.intr.coro.id %0, %1, %1, %1 : (i32, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> !llvm.token
  %0 = async.coro.id
  return
}

// CHECK-LABEL: @coro_begin
func.func @coro_begin() {
  // CHECK: %[[ID:.*]] = llvm.intr.coro.id
  %0 = async.coro.id
  // CHECK: %[[SIZE:.*]] = llvm.intr.coro.size : i64
  // CHECK: %[[ALIGN:.*]] = llvm.intr.coro.align : i64
  // CHECK: %[[SIZE_PLUS_ALIGN:.*]] = llvm.add %[[SIZE]], %[[ALIGN]] : i64
  // CHECK: %[[C1:.*]] = llvm.mlir.constant(1 : i64) : i64
  // CHECK: %[[SIZE_PLUS_ALIGN_MINUS_ONE:.*]] = llvm.sub %[[SIZE_PLUS_ALIGN]], %[[C1]] : i64
  // CHECK: %[[C0:.*]] = llvm.mlir.constant(0 : i64) : i64
  // CHECK: %[[NEGATED_ALIGN:.*]] = llvm.sub %[[C0]], %[[ALIGN]]  : i64
  // CHECK: %[[ROUNDED_SIZE:.*]] = llvm.and %[[SIZE_PLUS_ALIGN_MINUS_ONE]], %[[NEGATED_ALIGN]] : i64
  // CHECK: %[[ALLOC:.*]] = llvm.call @aligned_alloc(%[[ALIGN]], %[[ROUNDED_SIZE]])
  // CHECK: %[[HDL:.*]] = llvm.intr.coro.begin %[[ID]], %[[ALLOC]]
  %1 = async.coro.begin %0
  return
}

// CHECK-LABEL: @coro_free
func.func @coro_free() {
  // CHECK: %[[ID:.*]] = llvm.intr.coro.id
  %0 = async.coro.id
  // CHECK: %[[HDL:.*]] = llvm.intr.coro.begin
  %1 = async.coro.begin %0
  // CHECK: %[[MEM:.*]] = llvm.intr.coro.free %[[ID]], %[[HDL]]
  // CHECK: llvm.call @free(%[[MEM]])
  async.coro.free %0, %1
  return
}

// CHECK-LABEL: @coro_end
func.func @coro_end() {
  %0 = async.coro.id
  // CHECK: %[[HDL:.*]] = llvm.intr.coro.begin
  %1 = async.coro.begin %0
  // CHECK: %[[FALSE:.*]] = llvm.mlir.constant(false) : i1
  // CHECK: llvm.intr.coro.end %[[HDL]], %[[FALSE]]
  async.coro.end %1
  return
}

// CHECK-LABEL: @coro_save
func.func @coro_save() {
  %0 = async.coro.id
  // CHECK: %[[HDL:.*]] = llvm.intr.coro.begin
  %1 = async.coro.begin %0
  // CHECK: llvm.intr.coro.save %[[HDL]]
  %2 = async.coro.save %1
  return
}

// CHECK-LABEL: @coro_suspend
func.func @coro_suspend() {
  %0 = async.coro.id
  // CHECK: %[[HDL:.*]] = llvm.intr.coro.begin
  %1 = async.coro.begin %0
  // CHECK: %[[STATE:.*]] = llvm.intr.coro.save %[[HDL]]
  %2 = async.coro.save %1

  // CHECK: %[[FINAL:.*]] = llvm.mlir.constant(false) : i1
  // CHECK: %[[RET:.*]] = llvm.intr.coro.suspend %[[STATE]], %[[FINAL]]
  // CHECK: %[[SEXT:.*]] = llvm.sext %[[RET]] : i8 to i32
  // CHECK: llvm.switch %[[SEXT]] : i32, ^[[SUSPEND:[b0-9]+]]
  // CHECK-NEXT: 0: ^[[RESUME:[b0-9]+]]
  // CHECK-NEXT: 1: ^[[CLEANUP:[b0-9]+]]
  async.coro.suspend %2, ^suspend, ^resume, ^cleanup
^resume:
  // CHECK: ^[[RESUME]]
  // CHECK:   return {coro.resume}
  return { coro.resume }
^cleanup:
  // CHECK: ^[[CLEANUP]]
  // CHECK:   return {coro.cleanup}
  return { coro.cleanup }
^suspend:
  // CHECK: ^[[SUSPEND]]
  // CHECK:   return {coro.suspend}
  return { coro.suspend }
}