File: coro-eh-aware-edge-split-01.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 (91 lines) | stat: -rw-r--r-- 3,094 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
; Check that we can handle edge splits leading into a landingpad
; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; CHECK-LABEL: define internal fastcc void @g.resume(
define void @g(i1 %cond, i32 %x, i32 %y) presplitcoroutine personality i32 0 {
entry:
  %id = call token @llvm.coro.id(i32 16, ptr null, ptr null, ptr null)
  %size = tail call i64 @llvm.coro.size.i64()
  %alloc = call ptr @malloc(i64 %size)
  %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)
  %sp = call i8 @llvm.coro.suspend(token none, i1 false)
  switch i8 %sp, label %coro.ret [
    i8 0, label %resume
    i8 1, label %cleanup
  ]

resume:
  br i1 %cond, label %invoke1, label %invoke2

invoke1:
  invoke void @may_throw1()
          to label %unreach unwind label %pad.with.phi
invoke2:
  invoke void @may_throw2()
          to label %unreach unwind label %pad.with.phi

; Verify that we created cleanuppads on every edge and inserted a reload of the spilled value

; CHECK: pad.with.phi.from.invoke2:
; CHECK:   %0 = cleanuppad within none []
; CHECK:   %y.reload.addr = getelementptr inbounds %g.Frame, ptr %hdl, i32 0, i32 3
; CHECK:   %y.reload = load i32, ptr %y.reload.addr
; CHECK:   cleanupret from %0 unwind label %pad.with.phi

; CHECK: pad.with.phi.from.invoke1:
; CHECK:   %1 = cleanuppad within none []
; CHECK:   %x.reload.addr = getelementptr inbounds %g.Frame, ptr %hdl, i32 0, i32 2
; CHECK:   %x.reload = load i32, ptr %x.reload.addr
; CHECK:   cleanupret from %1 unwind label %pad.with.phi

; CHECK: pad.with.phi:
; CHECK:   %val = phi i32 [ %x.reload, %pad.with.phi.from.invoke1 ], [ %y.reload, %pad.with.phi.from.invoke2 ]
; CHECK:   %tok = cleanuppad within none []
; CHECK:   call void @use_val(i32 %val)
; CHECK:   cleanupret from %tok unwind to caller

pad.with.phi:
  %val = phi i32 [ %x, %invoke1 ], [ %y, %invoke2 ]
  %tok = cleanuppad within none []
  call void @use_val(i32 %val)
  cleanupret from %tok unwind to caller

cleanup:                                        ; preds = %invoke.cont15, %if.else, %if.then, %ehcleanup21, %init.suspend
  %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
  call void @free(ptr %mem)
  br label %coro.ret

coro.ret:
  call i1 @llvm.coro.end(ptr null, i1 false, token none)
  ret void

unreach:
  unreachable
}

; Function Attrs: argmemonly nounwind readonly
declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
declare noalias ptr @malloc(i64)
declare i64 @llvm.coro.size.i64()
declare ptr @llvm.coro.begin(token, ptr writeonly)

; Function Attrs: nounwind
declare token @llvm.coro.save(ptr)
declare i8 @llvm.coro.suspend(token, i1)

; Function Attrs: argmemonly nounwind
declare void @may_throw1()
declare void @may_throw2()

declare ptr @__cxa_begin_catch(ptr)

declare void @use_val(i32)
declare void @__cxa_end_catch()

; Function Attrs: nounwind
declare i1 @llvm.coro.end(ptr, i1, token)
declare void @free(ptr)
declare ptr @llvm.coro.free(token, ptr nocapture readonly)