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 3 4declare i8* @llvm.frameaddress(i32) 5declare void @llvm.localescape(...) 6declare i8* @llvm.localaddress() 7declare i8* @llvm.localrecover(i8*, i8*, i32) 8declare i32 @printf(i8*, ...) 9 10@str = internal constant [10 x i8] c"asdf: %d\0A\00" 11 12define 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) 21 store i32 42, i32* %b 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) 25 ret void 26} 27 28; X64-LABEL: print_framealloc_from_fp: 29; X64: movq %rcx, %[[parent_fp:[a-z]+]] 30; X64: movl .Lalloc_func$frame_escape_0(%[[parent_fp]]), %edx 31; X64: leaq {{.*}}(%rip), %[[str:[a-z]+]] 32; X64: movq %[[str]], %rcx 33; X64: callq printf 34; X64: movl .Lalloc_func$frame_escape_1(%[[parent_fp]]), %edx 35; X64: movq %[[str]], %rcx 36; X64: callq printf 37; X64: movl $42, .Lalloc_func$frame_escape_1(%[[parent_fp]]) 38; X64: retq 39 40; X86-LABEL: print_framealloc_from_fp: 41; X86: pushl %esi 42; X86: movl 8(%esp), %esi 43; X86: pushl Lalloc_func$frame_escape_0(%esi) 44; X86: pushl $_str 45; X86: calll _printf 46; X86: addl $8, %esp 47; X86: pushl Lalloc_func$frame_escape_1(%esi) 48; X86: pushl $_str 49; X86: calll _printf 50; X86: addl $8, %esp 51; X86: movl $42, Lalloc_func$frame_escape_1(%esi) 52; X86: movl $4, %eax 53; X86: pushl Lalloc_func$frame_escape_1(%esi,%eax) 54; X86: pushl $_str 55; X86: calll _printf 56; X86: addl $8, %esp 57; X86: popl %esi 58; X86: retl 59 60define void @alloc_func(i32 %n) { 61 %a = alloca i32 62 %b = alloca i32, i32 2 63 call void (...) @llvm.localescape(i32* %a, i32* %b) 64 store i32 42, i32* %a 65 store i32 13, i32* %b 66 67 ; Force usage of EBP with a dynamic alloca. 68 alloca i8, i32 %n 69 70 %lp = call i8* @llvm.localaddress() 71 call void @print_framealloc_from_fp(i8* %lp) 72 ret void 73} 74 75; X64-LABEL: alloc_func: 76; X64: pushq %rbp 77; X64: subq $16, %rsp 78; X64: .seh_stackalloc 16 79; X64: leaq 16(%rsp), %rbp 80; X64: .seh_setframe 5, 16 81; X64: .Lalloc_func$frame_escape_0 = -4 82; X64: .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 87; X64: retq 88 89; X86-LABEL: alloc_func: 90; X86: pushl %ebp 91; X86: movl %esp, %ebp 92; X86: subl $12, %esp 93; X86: Lalloc_func$frame_escape_0 = -4 94; X86: Lalloc_func$frame_escape_1 = -12 95; X86: movl $42, -4(%ebp) 96; X86: movl $13, -12(%ebp) 97; X86: pushl %ebp 98; X86: calll _print_framealloc_from_fp 99; X86: movl %ebp, %esp 100; X86: popl %ebp 101; X86: retl 102 103; Helper to make this a complete program so it can be compiled and tested. 104define i32 @main() { 105 call void @alloc_func(i32 3) 106 ret i32 0 107} 108 109define void @alloc_func_no_frameaddr() { 110 %a = alloca i32 111 %b = alloca i32 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) 116 ret void 117} 118 119; X64-LABEL: alloc_func_no_frameaddr: 120; X64: subq $40, %rsp 121; X64: .seh_stackalloc 40 122; X64: .seh_endprologue 123; X64: .Lalloc_func_no_frameaddr$frame_escape_0 = 36 124; X64: .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 130; X64: retq 131 132; X86-LABEL: alloc_func_no_frameaddr: 133; X86: subl $8, %esp 134; X86: Lalloc_func_no_frameaddr$frame_escape_0 = 4 135; X86: Lalloc_func_no_frameaddr$frame_escape_1 = 0 136; X86: movl $42, 4(%esp) 137; X86: movl $13, (%esp) 138; X86: pushl $0 139; X86: calll _print_framealloc_from_fp 140; X86: addl $12, %esp 141; X86: retl 142