File: lower-wasm-ehsjlj-phi.ll

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (126 lines) | stat: -rw-r--r-- 5,631 bytes parent folder | download | duplicates (6)
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
; RUN: opt < %s -wasm-lower-em-ehsjlj -wasm-enable-eh -wasm-enable-sjlj -S | FileCheck %s

target triple = "wasm32-unknown-emscripten"

%struct.__jmp_buf_tag = type { [6 x i32], i32, [32 x i32] }
@buf = internal global [1 x %struct.__jmp_buf_tag] zeroinitializer, align 16

; When longjmpable calls are coverted into invokes in Wasm SjLj transformation
; and their unwind destination is an existing catchpad or cleanuppad due to
; maintain the scope structure, the new pred BBs created by invokes and the
; correct incoming values should be added the existing phis in those unwind
; destinations.

; When longjmpable calls are within a cleanuppad.
define void @longjmpable_invoke_phi0() personality ptr @__gxx_wasm_personality_v0 {
; CHECK-LABEL: @longjmpable_invoke_phi0
entry:
  %val.entry = call i32 @llvm.wasm.memory.size.i32(i32 0)
  %0 = call i32 @setjmp(ptr @buf) #2
  invoke void @foo()
          to label %bb1 unwind label %ehcleanup1

bb1:                                              ; preds = %entry
  ; We use llvm.wasm.memory.size intrinsic just to get/use an i32 value. The
  ; reason we use an intrinsic here is to make it not longjmpable. If this can
  ; longjmp, the result will be more complicated and hard to check.
  %val.bb1 = call i32 @llvm.wasm.memory.size.i32(i32 0)
  invoke void @foo()
          to label %bb2 unwind label %ehcleanup0

bb2:                                              ; preds = %bb1
  unreachable

ehcleanup0:                                       ; preds = %bb1
  %1 = cleanuppad within none []
  call void @longjmpable() [ "funclet"(token %1) ]
; CHECK:      ehcleanup0
; CHECK:        invoke void @longjmpable
; CHECK-NEXT:           to label %.noexc unwind label %ehcleanup1
  invoke void @foo() [ "funclet"(token %1) ]
          to label %bb3 unwind label %ehcleanup1

bb3:                                              ; preds = %ehcleanup0
  %val.bb3 = call i32 @llvm.wasm.memory.size.i32(i32 0)
  call void @longjmpable() [ "funclet"(token %1) ]
; CHECK:      bb3:
; CHECK:        invoke void @longjmpable
; CHECK-NEXT:           to label %.noexc1 unwind label %ehcleanup1
  cleanupret from %1 unwind label %ehcleanup1

ehcleanup1:                                       ; preds = %bb3, %ehcleanup0, %entry
  %phi = phi i32 [ %val.entry, %entry ], [ %val.bb1, %ehcleanup0 ], [ %val.bb3, %bb3 ]
; CHECK:      ehcleanup1:
; CHECK-NEXT:   %phi = phi i32 [ %val.entry2, %entry.split.split ], [ %val.bb1, %.noexc ], [ %val.bb3, %.noexc1 ], [ %val.bb1, %ehcleanup0 ], [ %val.bb3, %bb3 ]
  %2 = cleanuppad within none []
  %3 = call i32 @llvm.wasm.memory.size.i32(i32 %phi)
  cleanupret from %2 unwind to caller
}

; When longjmpable calls are within a catchpad.
define void @longjmpable_invoke_phi1() personality ptr @__gxx_wasm_personality_v0 {
; CHECK-LABEL: @longjmpable_invoke_phi1
entry:
  %val.entry = call i32 @llvm.wasm.memory.size.i32(i32 0)
  %0 = call i32 @setjmp(ptr @buf) #2
  invoke void @foo()
          to label %bb1 unwind label %ehcleanup

bb1:                                              ; preds = %entry
  %val.bb1 = call i32 @llvm.wasm.memory.size.i32(i32 0)
  invoke void @foo()
          to label %bb2 unwind label %catch.dispatch

bb2:                                              ; preds = %bb1
  unreachable

catch.dispatch:                                   ; preds = %bb1
  %1 = catchswitch within none [label %catch.start] unwind label %ehcleanup

catch.start:                                      ; preds = %catch.dispatch
  %2 = catchpad within %1 [ptr null]
  %3 = call ptr @llvm.wasm.get.exception(token %2)
  %4 = call i32 @llvm.wasm.get.ehselector(token %2)
  call void @longjmpable() [ "funclet"(token %2) ]
; CHECK:      catch.start:
; CHECK:        invoke void @longjmpable
; CHECK-NEXT:           to label %.noexc unwind label %ehcleanup
  invoke void @foo() [ "funclet"(token %2) ]
          to label %bb3 unwind label %ehcleanup

bb3:                                              ; preds = %catch.start
  %val.bb3 = call i32 @llvm.wasm.memory.size.i32(i32 0)
  call void @longjmpable() [ "funclet"(token %2) ]
; CHECK:      bb3:
; CHECK:        invoke void @longjmpable
; CHECK-NEXT:           to label %.noexc1 unwind label %ehcleanup
  invoke void @foo() [ "funclet"(token %2) ]
          to label %bb4 unwind label %ehcleanup

bb4:                                              ; preds = %bb3
  unreachable

ehcleanup:                                        ; preds = %bb3, %catch.start, %catch.dispatch, %entry
  %phi = phi i32 [ %val.entry, %entry ], [ %val.bb1, %catch.dispatch ], [ %val.bb1, %catch.start ], [ %val.bb3, %bb3 ]
; CHECK:      ehcleanup:
; CHECK-NEXT:   %phi = phi i32 [ %val.entry2, %entry.split.split ], [ %val.bb1, %catch.dispatch ], [ %val.bb1, %.noexc ], [ %val.bb3, %.noexc1 ], [ %val.bb1, %catch.start ], [ %val.bb3, %bb3 ]
  %5 = cleanuppad within none []
  %6 = call i32 @llvm.wasm.memory.size.i32(i32 %phi)
  cleanupret from %5 unwind to caller
}

declare i32 @setjmp(ptr)
declare i32 @__gxx_wasm_personality_v0(...)
declare void @foo()
declare void @longjmpable()
declare void @use_i32(i32)
; Function Attrs: nocallback nofree nosync nounwind willreturn
declare i32 @llvm.wasm.get.ehselector(token) #0
; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.wasm.get.exception(token) #0
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)
declare i32 @llvm.wasm.memory.size.i32(i32) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(read) }
attributes #2 = { returns_twice }