File: coro-split-final-suspend.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 (129 lines) | stat: -rw-r--r-- 3,887 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
; Tests that we'll generate the store to the final suspend index if we see the unwind coro end.
; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s

define ptr @unwind_coro_end() presplitcoroutine personality i32 3 {
entry:
  %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
  %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
  call void @print(i32 0)
  br label %init

init:
  %initial_suspend = call i8 @llvm.coro.suspend(token none, i1 false)
  switch i8 %initial_suspend, label %init_suspend [i8 0, label %init_resume
                                                   i8 1, label %init_suspend]

init_suspend:
  ret ptr %hdl

init_resume:
  invoke void @print(i32 1)
          to label %final_suspend unwind label %lpad

final_suspend:
  %0 = call i8 @llvm.coro.suspend(token none, i1 true)
  switch i8 %0, label %suspend [i8 0, label %resume
                                i8 1, label %suspend]
resume:
  invoke void @print(i32 1) to label %suspend unwind label %lpad

suspend:
  call i1 @llvm.coro.end(ptr %hdl, i1 false, token none)
  call void @print(i32 0)
  ret ptr %hdl

lpad:
  %lpval = landingpad { ptr, i32 }
     cleanup

  call void @print(i32 2)
  %need.resume = call i1 @llvm.coro.end(ptr null, i1 true, token none)
  br i1 %need.resume, label %eh.resume, label %cleanup.cont

cleanup.cont:
  call void @print(i32 3)
  br label %eh.resume

eh.resume:
  resume { ptr, i32 } %lpval
}

; Tests that we need to store the final index if we see unwind coro end.
; CHECK: define{{.*}}@unwind_coro_end.resume
; CHECK: invoke{{.*}}print
; CHECK-NEXT: to label %[[RESUME:.*]] unwind label %[[LPAD:.*]]

; CHECK: [[RESUME]]:
; CHECK-NOT: {{.*:}}
; CHECK: store ptr null, ptr %hdl
; CHECK-NOT: {{.*:}}
; CHECK: store i1 true, ptr %index.addr

; CHECK: [[LPAD]]:
; CHECK-NOT: {{.*:}}
; CHECK: store ptr null, ptr %hdl
; CHECK-NOT: {{.*:}}
; CHECK: store i1 true, ptr %index.addr

; Tests the use of final index in the destroy function.
; CHECK: define{{.*}}@unwind_coro_end.destroy
; CHECK: %[[INDEX:.+]] = load i1, ptr %index.addr
; CHECK-NEXT: switch i1 %[[INDEX]],

define ptr @nounwind_coro_end(i1 %val) presplitcoroutine personality i32 3 {
entry:
  %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
  %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
  call void @print(i32 0)
  br label %init

init:
  %initial_suspend = call i8 @llvm.coro.suspend(token none, i1 false)
  switch i8 %initial_suspend, label %init_suspend [i8 0, label %init_resume
                                                   i8 1, label %init_suspend]

init_suspend:
  ret ptr %hdl

init_resume:
  br label %susp

susp:
  %0 = call i8 @llvm.coro.suspend(token none, i1 true)
  switch i8 %0, label %suspend [i8 0, label %resume
                                i8 1, label %suspend]
resume:
  call void @print(i32 1)
  br label %suspend

suspend:
  call i1 @llvm.coro.end(ptr %hdl, i1 false, token none)
  call void @print(i32 0)
  ret ptr %hdl
}

; Tests that we can omit to store the final suspend index if we don't
; see unwind coro end.
; CHECK: define{{.*}}@nounwind_coro_end.resume
; CHECK-NOT: store i1 true, ptr %index.addr
; CHECK: }

; Tests that we judge the final suspend case by the nullness of resume function.
; CHECK: define{{.*}}@nounwind_coro_end.destroy
; CHECK:  %[[RESUME_FN:.+]] = load ptr, ptr %hdl, align 8
; CHECK:  %{{.*}} = icmp eq ptr %[[RESUME_FN]], null

declare ptr @llvm.coro.free(token, ptr)
declare i32 @llvm.coro.size.i32()
declare i8  @llvm.coro.suspend(token, i1)
declare void @llvm.coro.resume(ptr)
declare void @llvm.coro.destroy(ptr)

declare token @llvm.coro.id(i32, ptr, ptr, ptr)
declare ptr @llvm.coro.alloc(token)
declare ptr @llvm.coro.begin(token, ptr)
declare i1 @llvm.coro.end(ptr, i1, token)

declare noalias ptr @malloc(i32)
declare void @print(i32)
declare void @free(ptr)