Add test case for C++ exception handling and fix the following mistakes in MipsFrameL...
[oota-llvm.git] / test / CodeGen / Mips / eh.ll
1 ; RUN: llc  < %s -march=mipsel -mcpu=4ke | FileCheck %s -check-prefix=CHECK-EL
2 ; RUN: llc  < %s -march=mips   -mcpu=4ke | FileCheck %s -check-prefix=CHECK-EB
3
4 @g1 = global double 0.000000e+00, align 8
5 @_ZTId = external constant i8*
6
7 define void @_Z1fd(double %i2) {
8 entry:
9 ; CHECK-EL:  addiu $sp, $sp
10 ; CHECK-EL:  .cfi_def_cfa_offset
11 ; CHECK-EL:  sdc1 $f20
12 ; CHECK-EL:  sw  $ra
13 ; CHECK-EL:  sw  $17
14 ; CHECK-EL:  sw  $16
15 ; CHECK-EL:  .cfi_offset 52, -8
16 ; CHECK-EL:  .cfi_offset 53, -4
17 ; CHECK-EB:  .cfi_offset 53, -8
18 ; CHECK-EB:  .cfi_offset 52, -4
19 ; CHECK-EL:  .cfi_offset 31, -12
20 ; CHECK-EL:  .cfi_offset 17, -16
21 ; CHECK-EL:  .cfi_offset 16, -20
22 ; CHECK-EL:  .cprestore 
23
24   %exception = tail call i8* @__cxa_allocate_exception(i32 8) nounwind
25   %0 = bitcast i8* %exception to double*
26   store double 3.200000e+00, double* %0, align 8, !tbaa !0
27   invoke void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTId to i8*), i8* null) noreturn
28           to label %unreachable unwind label %lpad
29
30 lpad:                                             ; preds = %entry
31 ; CHECK-EL:  # %lpad
32 ; CHECK-EL:  lw  $gp
33 ; CHECK-EL:  beq $5
34
35   %exn = tail call i8* @llvm.eh.exception() nounwind
36   %eh.selector = tail call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTId to i8*)) nounwind
37   %1 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTId to i8*)) nounwind
38   %2 = icmp eq i32 %eh.selector, %1
39   br i1 %2, label %catch, label %eh.resume
40
41 catch:                                            ; preds = %lpad
42   %3 = tail call i8* @__cxa_begin_catch(i8* %exn) nounwind
43   %4 = bitcast i8* %3 to double*
44   %exn.scalar = load double* %4, align 8
45   %add = fadd double %exn.scalar, %i2
46   store double %add, double* @g1, align 8, !tbaa !0
47   tail call void @__cxa_end_catch() nounwind
48   ret void
49
50 eh.resume:                                        ; preds = %lpad
51   tail call void @llvm.eh.resume(i8* %exn, i32 %eh.selector) noreturn
52   unreachable
53
54 unreachable:                                      ; preds = %entry
55   unreachable
56 }
57
58 declare i8* @__cxa_allocate_exception(i32)
59
60 declare i8* @llvm.eh.exception() nounwind readonly
61
62 declare i32 @__gxx_personality_v0(...)
63
64 declare i32 @llvm.eh.selector(i8*, i8*, ...) nounwind
65
66 declare i32 @llvm.eh.typeid.for(i8*) nounwind
67
68 declare void @llvm.eh.resume(i8*, i32)
69
70 declare void @__cxa_throw(i8*, i8*, i8*)
71
72 declare i8* @__cxa_begin_catch(i8*)
73
74 declare void @__cxa_end_catch()
75
76 !0 = metadata !{metadata !"double", metadata !1}
77 !1 = metadata !{metadata !"omnipotent char", metadata !2}
78 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}