Home | History | Annotate | Download | only in X86
      1 ; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck %s --check-prefix=X86
      2 ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=X64
      3 
      4 declare void @llvm.frameescape(...)
      5 declare i8* @llvm.frameaddress(i32)
      6 declare i8* @llvm.framerecover(i8*, i8*, i32)
      7 declare i32 @printf(i8*, ...)
      8 
      9 @str = internal constant [10 x i8] c"asdf: %d\0A\00"
     10 
     11 define void @print_framealloc_from_fp(i8* %fp) {
     12   %a.i8 = call i8* @llvm.framerecover(i8* bitcast (void()* @alloc_func to i8*), i8* %fp, i32 0)
     13   %a = bitcast i8* %a.i8 to i32*
     14   %a.val = load i32, i32* %a
     15   call i32 (i8*, ...) @printf(i8* getelementptr ([10 x i8], [10 x i8]* @str, i32 0, i32 0), i32 %a.val)
     16   %b.i8 = call i8* @llvm.framerecover(i8* bitcast (void()* @alloc_func to i8*), i8* %fp, i32 1)
     17   %b = bitcast i8* %b.i8 to i32*
     18   %b.val = load i32, i32* %b
     19   call i32 (i8*, ...) @printf(i8* getelementptr ([10 x i8], [10 x i8]* @str, i32 0, i32 0), i32 %b.val)
     20   store i32 42, i32* %b
     21   ret void
     22 }
     23 
     24 ; X64-LABEL: print_framealloc_from_fp:
     25 ; X64: movq %rcx, %[[parent_fp:[a-z]+]]
     26 ; X64: movl .Lalloc_func$frame_escape_0(%[[parent_fp]]), %edx
     27 ; X64: leaq {{.*}}(%rip), %[[str:[a-z]+]]
     28 ; X64: movq %[[str]], %rcx
     29 ; X64: callq printf
     30 ; X64: movl .Lalloc_func$frame_escape_1(%[[parent_fp]]), %edx
     31 ; X64: movq %[[str]], %rcx
     32 ; X64: callq printf
     33 ; X64: movl    $42, .Lalloc_func$frame_escape_1(%[[parent_fp]])
     34 ; X64: retq
     35 
     36 ; X86-LABEL: print_framealloc_from_fp:
     37 ; X86: pushl   %esi
     38 ; X86: subl    $8, %esp
     39 ; X86: movl    16(%esp), %esi
     40 ; X86: movl    _Lalloc_func$frame_escape_0(%esi), %eax
     41 ; X86: movl    %eax, 4(%esp)
     42 ; X86: movl    $_str, (%esp)
     43 ; X86: calll   _printf
     44 ; X86: movl    _Lalloc_func$frame_escape_1(%esi), %eax
     45 ; X86: movl    %eax, 4(%esp)
     46 ; X86: movl    $_str, (%esp)
     47 ; X86: calll   _printf
     48 ; X86: movl    $42, _Lalloc_func$frame_escape_1(%esi)
     49 ; X86: addl    $8, %esp
     50 ; X86: popl    %esi
     51 ; X86: retl
     52 
     53 define void @alloc_func() {
     54   %a = alloca i32
     55   %b = alloca i32
     56   call void (...) @llvm.frameescape(i32* %a, i32* %b)
     57   store i32 42, i32* %a
     58   store i32 13, i32* %b
     59   %fp = call i8* @llvm.frameaddress(i32 0)
     60   call void @print_framealloc_from_fp(i8* %fp)
     61   ret void
     62 }
     63 
     64 ; X64-LABEL: alloc_func:
     65 ; X64: subq    $48, %rsp
     66 ; X64: .seh_stackalloc 48
     67 ; X64: leaq    48(%rsp), %rbp
     68 ; X64: .seh_setframe 5, 48
     69 ; X64: .Lalloc_func$frame_escape_0 = 44
     70 ; X64: .Lalloc_func$frame_escape_1 = 40
     71 ; X64: movl $42, -4(%rbp)
     72 ; X64: movl $13, -8(%rbp)
     73 ; X64: leaq    -48(%rbp), %rcx
     74 ; X64: callq print_framealloc_from_fp
     75 ; X64: retq
     76 
     77 ; X86-LABEL: alloc_func:
     78 ; X86: pushl   %ebp
     79 ; X86: movl    %esp, %ebp
     80 ; X86: subl    $12, %esp
     81 ; X86: Lalloc_func$frame_escape_0 = -4
     82 ; X86: Lalloc_func$frame_escape_1 = -8
     83 ; X86: movl    $42, -4(%ebp)
     84 ; X86: movl    $13, -8(%ebp)
     85 ; X86: movl    %ebp, (%esp)
     86 ; X86: calll   _print_framealloc_from_fp
     87 ; X86: addl    $12, %esp
     88 ; X86: popl    %ebp
     89 ; X86: retl
     90 
     91 ; Helper to make this a complete program so it can be compiled and tested.
     92 define i32 @main() {
     93   call void @alloc_func()
     94   ret i32 0
     95 }
     96 
     97 define void @alloc_func_no_frameaddr() {
     98   %a = alloca i32
     99   %b = alloca i32
    100   call void (...) @llvm.frameescape(i32* %a, i32* %b)
    101   store i32 42, i32* %a
    102   store i32 13, i32* %b
    103   call void @print_framealloc_from_fp(i8* null)
    104   ret void
    105 }
    106 
    107 ; X64-LABEL: alloc_func_no_frameaddr:
    108 ; X64: subq    $40, %rsp
    109 ; X64: .seh_stackalloc 40
    110 ; X64: .seh_endprologue
    111 ; X64: .Lalloc_func_no_frameaddr$frame_escape_0 = 36
    112 ; X64: .Lalloc_func_no_frameaddr$frame_escape_1 = 32
    113 ; X64: movl $42, 36(%rsp)
    114 ; X64: movl $13, 32(%rsp)
    115 ; X64: xorl %ecx, %ecx
    116 ; X64: callq print_framealloc_from_fp
    117 ; X64: addq $40, %rsp
    118 ; X64: retq
    119