preallocated.ll
3.46 KB
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
; RUN: opt < %s -globalopt -S | FileCheck %s
declare token @llvm.call.preallocated.setup(i32)
declare i8* @llvm.call.preallocated.arg(token, i32)
declare i32 @__CxxFrameHandler3(...)
; Don't touch functions with any musttail calls
define internal i32 @preallocated_musttail(i32* preallocated(i32) %p) {
; CHECK-LABEL: define internal i32 @preallocated_musttail(i32* preallocated(i32) %p)
%rv = load i32, i32* %p
ret i32 %rv
}
define i32 @call_preallocated_musttail(i32* preallocated(i32) %a) {
%r = musttail call i32 @preallocated_musttail(i32* preallocated(i32) %a)
ret i32 %r
}
; CHECK-LABEL: define i32 @call_preallocated_musttail(i32* preallocated(i32) %a)
; CHECK: musttail call i32 @preallocated_musttail(i32* preallocated(i32) %a)
define i32 @call_preallocated_musttail_without_musttail() {
%c = call token @llvm.call.preallocated.setup(i32 1)
%N = call i8* @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
%n = bitcast i8* %N to i32*
%r = call i32 @preallocated_musttail(i32* preallocated(i32) %n) ["preallocated"(token %c)]
ret i32 %r
}
; CHECK-LABEL: define i32 @call_preallocated_musttail_without_musttail()
; CHECK: call i32 @preallocated_musttail(i32* preallocated(i32) %n)
; Check that only one alloca per preallocated arg
define internal i32 @preallocated(i32* preallocated(i32) %a) {
; CHECK-LABEL: define internal fastcc i32 @preallocated(i32* %a)
%rv = load i32, i32* %a
ret i32 %rv
}
declare void @foo(i8*)
define i32 @call_preallocated_multiple_args() {
; CHECK-LABEL: define i32 @call_preallocated_multiple_args()
; CHECK-NEXT: [[SS:%[0-9a-zA-Z_]+]] = call i8* @llvm.stacksave()
; CHECK-NEXT: [[ARG0:%[0-9a-zA-Z_]+]] = alloca i32
; CHECK-NEXT: [[ARG1:%[0-9a-zA-Z_]+]] = bitcast i32* [[ARG0]] to i8*
; CHECK-NEXT: call void @foo(i8* [[ARG1]])
; CHECK-NEXT: call void @foo(i8* [[ARG1]])
; CHECK-NEXT: call void @foo(i8* [[ARG1]])
; CHECK-NEXT: [[ARG2:%[0-9a-zA-Z_]+]] = bitcast i8* [[ARG1]] to i32*
; CHECK-NEXT: call fastcc i32 @preallocated(i32* [[ARG2]])
; CHECK-NEXT: call void @llvm.stackrestore(i8* [[SS]])
; CHECK-NEXT: ret
%c = call token @llvm.call.preallocated.setup(i32 1)
%a1 = call i8* @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
call void @foo(i8* %a1)
%a2 = call i8* @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
call void @foo(i8* %a2)
%a3 = call i8* @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
call void @foo(i8* %a3)
%b = bitcast i8* %a3 to i32*
%r = call i32 @preallocated(i32* preallocated(i32) %b) ["preallocated"(token %c)]
ret i32 %r
}
; Don't touch functions with any invokes
define internal i32 @preallocated_invoke(i32* preallocated(i32) %p) {
; CHECK-LABEL: define internal i32 @preallocated_invoke(i32* preallocated(i32) %p)
%rv = load i32, i32* %p
ret i32 %rv
}
define i32 @call_preallocated_invoke() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
%c = call token @llvm.call.preallocated.setup(i32 1)
%a = call i8* @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
%b = bitcast i8* %a to i32*
%r = invoke i32 @preallocated_invoke(i32* preallocated(i32) %b) ["preallocated"(token %c)]
to label %conta unwind label %contb
conta:
ret i32 %r
contb:
%s = catchswitch within none [label %catch] unwind to caller
catch:
%p = catchpad within %s []
catchret from %p to label %cont
cont:
ret i32 42
}
; CHECK-LABEL: define i32 @call_preallocated_invoke()
; CHECK: invoke i32 @preallocated_invoke(i32* preallocated(i32) %b)