File: coro-split-final-suspend.ll

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (115 lines) | stat: -rw-r--r-- 3,446 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
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
; 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:
  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:
  invoke void @print(i32 1) to label %suspend unwind label %lpad

suspend:
  call i1 @llvm.coro.end(ptr %hdl, i1 false)
  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)
  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: 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)
  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)

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