[PGO] MST based PGO instrumentation infrastructure
[oota-llvm.git] / test / Transforms / PGOProfile / landingpad_gen.ll
1 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
4
5 @val = global i32 0, align 4
6 @_ZTIi = external constant i8*
7 ; CHECK: @__llvm_profile_name__Z3bari = private constant [7 x i8] c"_Z3bari"
8 ; CHECK: @__llvm_profile_name__Z3fooi = private constant [7 x i8] c"_Z3fooi"
9
10 define i32 @_Z3bari(i32 %i) {
11 entry:
12   %rem = srem i32 %i, 3
13   %tobool = icmp ne i32 %rem, 0
14   br i1 %tobool, label %if.then, label %if.end
15
16 if.then:
17 ; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3bari, i32 0, i32 0), i64 23319865734, i32 2, i32 1)
18   %exception = call i8* @__cxa_allocate_exception(i64 4)
19   %tmp = bitcast i8* %exception to i32*
20   store i32 %i, i32* %tmp, align 16
21   call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
22   unreachable
23
24 if.end:
25 ; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3bari, i32 0, i32 0), i64 23319865734, i32 2, i32 0)
26   ret i32 0
27 }
28
29 declare i8* @__cxa_allocate_exception(i64)
30
31 declare void @__cxa_throw(i8*, i8*, i8*)
32
33 define i32 @_Z3fooi(i32 %i) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
34 entry:
35   %rem = srem i32 %i, 2
36   %tobool = icmp ne i32 %rem, 0
37   br i1 %tobool, label %if.then, label %if.end
38
39 if.then:
40   %mul = mul nsw i32 %i, 7
41   %call = invoke i32 @_Z3bari(i32 %mul)
42           to label %invoke.cont unwind label %lpad
43
44 invoke.cont:
45 ; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3fooi, i32 0, i32 0), i64 57451243578, i32 4, i32 1)
46   br label %if.end
47
48 lpad:
49   %tmp = landingpad { i8*, i32 }
50           catch i8* bitcast (i8** @_ZTIi to i8*)
51   %tmp1 = extractvalue { i8*, i32 } %tmp, 0
52   %tmp2 = extractvalue { i8*, i32 } %tmp, 1
53   br label %catch.dispatch
54
55 catch.dispatch:
56   %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
57   %matches = icmp eq i32 %tmp2, %tmp3
58   br i1 %matches, label %catch, label %eh.resume
59
60 catch:
61 ; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3fooi, i32 0, i32 0), i64 57451243578, i32 4, i32 2)
62   %tmp4 = call i8* @__cxa_begin_catch(i8* %tmp1)
63   %tmp5 = bitcast i8* %tmp4 to i32*
64   %tmp6 = load i32, i32* %tmp5, align 4
65   %tmp7 = load i32, i32* @val, align 4
66   %sub = sub nsw i32 %tmp7, %tmp6
67   store i32 %sub, i32* @val, align 4
68   call void @__cxa_end_catch()
69   br label %try.cont
70
71 try.cont:
72   ret i32 -1
73
74 if.end:
75 ; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3fooi, i32 0, i32 0), i64 57451243578, i32 4, i32 0)
76   %tmp8 = load i32, i32* @val, align 4
77   %add = add nsw i32 %tmp8, %i
78   store i32 %add, i32* @val, align 4
79   br label %try.cont
80
81 eh.resume:
82 ; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3fooi, i32 0, i32 0), i64 57451243578, i32 4, i32 3)
83   %lpad.val = insertvalue { i8*, i32 } undef, i8* %tmp1, 0
84   %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %tmp2, 1
85   resume { i8*, i32 } %lpad.val3
86 }
87
88 declare i32 @__gxx_personality_v0(...)
89
90 declare i32 @llvm.eh.typeid.for(i8*)
91
92 declare i8* @__cxa_begin_catch(i8*)
93
94 declare void @__cxa_end_catch()
95