File: coro-spill-suspend.ll

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (59 lines) | stat: -rw-r--r-- 1,862 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
; Check that the return value of @llvm.coro.suspend gets spilled to the frame
; if it may be used across suspend points.
; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s


; %sp1 should be part of the frame (the i8 value).
; CHECK: %f.Frame = type { ptr, ptr, i1, i8 }

; If the coro resumes, %sp1 is set to 0.
; CHECK-LABEL: define{{.*}} void @f.resume
; CHECK: AfterCoroSuspend:
; CHECK: %sp1.spill.addr = getelementptr inbounds %f.Frame
; CHECK: store i8 0, ptr %sp1.spill.addr

; In the coro destroy function, %sp1 is reloaded from the frame. Its value
; depends on whether the coroutine was resumed or not.
; CHECK-LABEL: define{{.*}} void @f.destroy
; CHECK: cleanup:
; CHECK: %sp1.reload.addr = getelementptr inbounds %f.Frame
; CHECK: %sp1.reload = load i8, ptr %sp1.reload.addr
; CHECK: call void @print(i8 %sp1.reload)


define ptr @f(i32 %n) presplitcoroutine {
entry:
  %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
  %size = call i32 @llvm.coro.size.i32()
  %alloc = call ptr @malloc(i32 %size)
  %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)

  %sp1 = call i8 @llvm.coro.suspend(token none, i1 false)
  switch i8 %sp1, label %suspend [i8 0, label %resume1
                                  i8 1, label %cleanup]

resume1:
  %sp2 = call i8 @llvm.coro.suspend(token none, i1 false)
  switch i8 %sp2, label %suspend [i8 0, label %resume2
                                  i8 1, label %cleanup]

resume2:
  br label %cleanup

cleanup:
  ; This use of %sp1 may cross a suspend point (%sp2).
  call void @print(i8 %sp1)

  %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
  call void @free(ptr %mem)
  br label %suspend

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


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