1 ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=X64
2 ; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck %s --check-prefix=X86
4 declare i8* @llvm.frameaddress(i32)
5 declare void @llvm.localescape(...)
6 declare i8* @llvm.localaddress()
7 declare i8* @llvm.localrecover(i8*, i8*, i32)
8 declare i32 @printf(i8*, ...)
10 @str = internal constant [10 x i8] c"asdf: %d\0A\00"
12 define void @print_framealloc_from_fp(i8* %fp) {
13 %a.i8 = call i8* @llvm.localrecover(i8* bitcast (void(i32)* @alloc_func to i8*), i8* %fp, i32 0)
14 %a = bitcast i8* %a.i8 to i32*
15 %a.val = load i32, i32* %a
16 call i32 (i8*, ...) @printf(i8* getelementptr ([10 x i8], [10 x i8]* @str, i32 0, i32 0), i32 %a.val)
17 %b.i8 = call i8* @llvm.localrecover(i8* bitcast (void(i32)* @alloc_func to i8*), i8* %fp, i32 1)
18 %b = bitcast i8* %b.i8 to i32*
19 %b.val = load i32, i32* %b
20 call i32 (i8*, ...) @printf(i8* getelementptr ([10 x i8], [10 x i8]* @str, i32 0, i32 0), i32 %b.val)
22 %b2 = getelementptr i32, i32* %b, i32 1
23 %b2.val = load i32, i32* %b2
24 call i32 (i8*, ...) @printf(i8* getelementptr ([10 x i8], [10 x i8]* @str, i32 0, i32 0), i32 %b2.val)
28 ; X64-LABEL: print_framealloc_from_fp:
29 ; X64: movq %rcx, %[[parent_fp:[a-z]+]]
30 ; X64: movl .Lalloc_func$frame_escape_0(%rcx), %edx
31 ; X64: leaq {{.*}}(%rip), %[[str:[a-z]+]]
32 ; X64: movq %[[str]], %rcx
34 ; X64: movl .Lalloc_func$frame_escape_1(%[[parent_fp]]), %edx
35 ; X64: movq %[[str]], %rcx
37 ; X64: movl $42, .Lalloc_func$frame_escape_1(%[[parent_fp]])
40 ; X86-LABEL: print_framealloc_from_fp:
42 ; X86: movl 8(%esp), %esi
43 ; X86: pushl Lalloc_func$frame_escape_0(%esi)
47 ; X86: pushl Lalloc_func$frame_escape_1(%esi)
51 ; X86: movl $42, Lalloc_func$frame_escape_1(%esi)
53 ; X86: pushl Lalloc_func$frame_escape_1(%esi,%eax)
60 define void @alloc_func(i32 %n) {
62 %b = alloca i32, i32 2
63 call void (...) @llvm.localescape(i32* %a, i32* %b)
67 ; Force usage of EBP with a dynamic alloca.
70 %lp = call i8* @llvm.localaddress()
71 call void @print_framealloc_from_fp(i8* %lp)
75 ; X64-LABEL: alloc_func:
78 ; X64: .seh_stackalloc 16
79 ; X64: leaq 16(%rsp), %rbp
80 ; X64: .seh_setframe %rbp, 16
81 ; X64: .set .Lalloc_func$frame_escape_0, -4
82 ; X64: .set .Lalloc_func$frame_escape_1, -12
83 ; X64: movl $42, -4(%rbp)
84 ; X64: movl $13, -12(%rbp)
85 ; X64: movq %rbp, %rcx
86 ; X64: callq print_framealloc_from_fp
89 ; X86-LABEL: alloc_func:
91 ; X86: movl %esp, %ebp
93 ; X86: .set Lalloc_func$frame_escape_0, -4
94 ; X86: .set Lalloc_func$frame_escape_1, -12
95 ; X86: movl $42, -4(%ebp)
96 ; X86: movl $13, -12(%ebp)
98 ; X86: calll _print_framealloc_from_fp
99 ; X86: movl %ebp, %esp
103 ; Helper to make this a complete program so it can be compiled and tested.
105 call void @alloc_func(i32 3)
109 define void @alloc_func_no_frameaddr() {
112 call void (...) @llvm.localescape(i32* %a, i32* %b)
113 store i32 42, i32* %a
114 store i32 13, i32* %b
115 call void @print_framealloc_from_fp(i8* null)
119 ; X64-LABEL: alloc_func_no_frameaddr:
120 ; X64: subq $40, %rsp
121 ; X64: .seh_stackalloc 40
122 ; X64: .seh_endprologue
123 ; X64: .set .Lalloc_func_no_frameaddr$frame_escape_0, 36
124 ; X64: .set .Lalloc_func_no_frameaddr$frame_escape_1, 32
125 ; X64: movl $42, 36(%rsp)
126 ; X64: movl $13, 32(%rsp)
127 ; X64: xorl %ecx, %ecx
128 ; X64: callq print_framealloc_from_fp
129 ; X64: addq $40, %rsp
132 ; X86-LABEL: alloc_func_no_frameaddr:
134 ; X86: .set Lalloc_func_no_frameaddr$frame_escape_0, 4
135 ; X86: .set Lalloc_func_no_frameaddr$frame_escape_1, 0
136 ; X86: movl $42, 4(%esp)
137 ; X86: movl $13, (%esp)
139 ; X86: calll _print_framealloc_from_fp
140 ; X86: addl $12, %esp