This patch is needed to make c++ exceptions work for mips16.
[oota-llvm.git] / test / CodeGen / Mips / mips16ex.ll
1 ; RUN: llc  -march=mipsel -mcpu=mips16 -relocation-model=pic -O3 < %s | FileCheck %s -check-prefix=16
2
3 ;16: $eh_func_begin0=.
4 @.str = private unnamed_addr constant [7 x i8] c"hello\0A\00", align 1
5 @_ZTIi = external constant i8*
6 @.str1 = private unnamed_addr constant [15 x i8] c"exception %i \0A\00", align 1
7
8 define i32 @main() {
9 entry:
10   %retval = alloca i32, align 4
11   %exn.slot = alloca i8*
12   %ehselector.slot = alloca i32
13   %e = alloca i32, align 4
14   store i32 0, i32* %retval
15   %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([7 x i8]* @.str, i32 0, i32 0))
16   %exception = call i8* @__cxa_allocate_exception(i32 4) nounwind
17   %0 = bitcast i8* %exception to i32*
18   store i32 20, i32* %0
19   invoke void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) noreturn
20           to label %unreachable unwind label %lpad
21
22 lpad:                                             ; preds = %entry
23   %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
24           catch i8* bitcast (i8** @_ZTIi to i8*)
25   %2 = extractvalue { i8*, i32 } %1, 0
26   store i8* %2, i8** %exn.slot
27   %3 = extractvalue { i8*, i32 } %1, 1
28   store i32 %3, i32* %ehselector.slot
29   br label %catch.dispatch
30
31 catch.dispatch:                                   ; preds = %lpad
32   %sel = load i32* %ehselector.slot
33   %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
34   %matches = icmp eq i32 %sel, %4
35   br i1 %matches, label %catch, label %eh.resume
36
37 catch:                                            ; preds = %catch.dispatch
38   %exn = load i8** %exn.slot
39   %5 = call i8* @__cxa_begin_catch(i8* %exn) nounwind
40   %6 = bitcast i8* %5 to i32*
41   %exn.scalar = load i32* %6
42   store i32 %exn.scalar, i32* %e, align 4
43   %7 = load i32* %e, align 4
44   %call2 = invoke i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str1, i32 0, i32 0), i32 %7)
45           to label %invoke.cont unwind label %lpad1
46
47 invoke.cont:                                      ; preds = %catch
48   call void @__cxa_end_catch() nounwind
49   br label %try.cont
50
51 try.cont:                                         ; preds = %invoke.cont
52   ret i32 0
53
54 lpad1:                                            ; preds = %catch
55   %8 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
56           cleanup
57   %9 = extractvalue { i8*, i32 } %8, 0
58   store i8* %9, i8** %exn.slot
59   %10 = extractvalue { i8*, i32 } %8, 1
60   store i32 %10, i32* %ehselector.slot
61   call void @__cxa_end_catch() nounwind
62   br label %eh.resume
63
64 eh.resume:                                        ; preds = %lpad1, %catch.dispatch
65   %exn3 = load i8** %exn.slot
66   %sel4 = load i32* %ehselector.slot
67   %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
68   %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
69   resume { i8*, i32 } %lpad.val5
70
71 unreachable:                                      ; preds = %entry
72   unreachable
73 }
74
75 declare i32 @printf(i8*, ...)
76
77 declare i8* @__cxa_allocate_exception(i32)
78
79 declare i32 @__gxx_personality_v0(...)
80
81 declare void @__cxa_throw(i8*, i8*, i8*)
82
83 declare i32 @llvm.eh.typeid.for(i8*) nounwind readnone
84
85 declare i8* @__cxa_begin_catch(i8*)
86
87 declare void @__cxa_end_catch()