File: coro-async-dyn-align.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 1,998,492 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (96 lines) | stat: -rw-r--r-- 3,756 bytes parent folder | download | duplicates (8)
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
91
92
93
94
95
96
; RUN: opt < %s  -O0 -S | FileCheck  %s

target datalayout = "p:64:64:64"

%async.task = type { i64 }
%async.actor = type { i64 }
%async.fp = type <{ i32, i32 }>

%async.ctxt = type { ptr, ptr }

@my_other_async_function_fp = external global <{ i32, i32 }>
declare void @my_other_async_function(ptr %async.ctxt)

@my_async_function_fp = constant <{ i32, i32 }>
  <{ i32 trunc (
       i64 sub (
         i64 ptrtoint (ptr @my_async_function to i64),
         i64 ptrtoint (ptr getelementptr inbounds (<{ i32, i32 }>, ptr @my_async_function_fp, i32 0, i32 1) to i64)
       )
     to i32),
     i32 32
}>

declare void @opaque(ptr)
declare ptr @llvm.coro.async.context.alloc(ptr, ptr)
declare void @llvm.coro.async.context.dealloc(ptr)
declare ptr @llvm.coro.async.resume()
declare token @llvm.coro.id.async(i32, i32, i32, ptr)
declare ptr @llvm.coro.begin(token, ptr)
declare i1 @llvm.coro.end.async(ptr, i1, ...)
declare i1 @llvm.coro.end(ptr, i1, token)
declare swiftcc void @asyncReturn(ptr)
declare swiftcc void @asyncSuspend(ptr)
declare {ptr} @llvm.coro.suspend.async(i32, ptr, ptr, ...)

define swiftcc void @my_async_function.my_other_async_function_fp.apply(ptr %fnPtr, ptr %async.ctxt) {
  tail call swiftcc void %fnPtr(ptr %async.ctxt)
  ret void
}

define ptr @__swift_async_resume_project_context(ptr %ctxt) {
entry:
  %resume_ctxt = load ptr, ptr %ctxt, align 8
  ret ptr %resume_ctxt
}


; CHECK: %my_async_function.Frame = type { i64, [48 x i8], i64, i64, [16 x i8], ptr, i64, ptr }
; CHECK: define swiftcc void @my_async_function
; CHECK:  [[T0:%.*]] = getelementptr inbounds %my_async_function.Frame, ptr %async.ctx.frameptr, i32 0, i32 3
; CHECK:  [[T1:%.*]] = ptrtoint ptr [[T0]] to i64
; CHECK:  [[T2:%.*]] = add i64 [[T1]], 31
; CHECK:  [[T3:%.*]] = and i64 [[T2]], -32
; CHECK:  [[T4:%.*]] = inttoptr i64 [[T3]] to ptr
; CHECK:  [[FP:%.*]] = getelementptr inbounds %my_async_function.Frame, ptr %async.ctx.frameptr, i32 0, i32 0
; CHECK:  [[T6:%.*]] = ptrtoint ptr [[FP]] to i64
; CHECK:  [[T7:%.*]] = add i64 [[T6]], 63
; CHECK:  [[T8:%.*]] = and i64 [[T7]], -64
; CHECK:  [[T9:%.*]] = inttoptr i64 [[T8]] to ptr
; CHECK:  store i64 2, ptr [[T4]]
; CHECK:  store i64 3, ptr [[T9]]

define swiftcc void @my_async_function(ptr swiftasync %async.ctxt) presplitcoroutine {
entry:
  %tmp = alloca i64, align 8
  %tmp2 = alloca i64, align 16
  %tmp3 = alloca i64, align 32
  %tmp4 = alloca i64, align 64

  %id = call token @llvm.coro.id.async(i32 32, i32 16, i32 0,
          ptr @my_async_function_fp)
  %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
  store i64 0, ptr %tmp
  store i64 1, ptr %tmp2
  store i64 2, ptr %tmp3
  store i64 3, ptr %tmp4

  %callee_context = call ptr @llvm.coro.async.context.alloc(ptr null, ptr null)
  %callee_context.return_to_caller.addr = getelementptr inbounds %async.ctxt, ptr %callee_context, i32 0, i32 1
  %resume.func_ptr = call ptr @llvm.coro.async.resume()
  store ptr %resume.func_ptr, ptr %callee_context.return_to_caller.addr

  %res = call {ptr} (i32, ptr, ptr, ...) @llvm.coro.suspend.async(i32 0,
                                                  ptr %resume.func_ptr,
                                                  ptr @__swift_async_resume_project_context,
                                                  ptr @my_async_function.my_other_async_function_fp.apply,
                                                  ptr @asyncSuspend, ptr %callee_context)
  call void @opaque(ptr %tmp)
  call void @opaque(ptr %tmp2)
  call void @opaque(ptr %tmp3)
  call void @opaque(ptr %tmp4)
  call void @llvm.coro.async.context.dealloc(ptr %callee_context)
  tail call swiftcc void @asyncReturn(ptr %async.ctxt)
  call i1 (ptr, i1, ...) @llvm.coro.end.async(ptr %hdl, i1 0)
  unreachable
}