1; Test that instrumentaiton works fine for the case of catchswitch stmts.
2; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
3; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
4; RUN: llvm-profdata merge %S/Inputs/PR41279_2.proftext -o %t.profdata
5; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
6; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
7
8
9define dso_local void @f() personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
10; USE-LABEL: @f
11; USE-SAME: !prof ![[FUNC_ENTRY_COUNT:[0-9]+]]
12; USE-DAG: {{![0-9]+}} = !{i32 1, !"ProfileSummary", {{![0-9]+}}}
13; USE-DAG: {{![0-9]+}} = !{!"DetailedSummary", {{![0-9]+}}}
14; USE-DAG: ![[FUNC_ENTRY_COUNT]] = !{!"function_entry_count", i64 5}
15entry:
16  %__exception_code = alloca i32, align 4
17  %__exception_code2 = alloca i32, align 4
18  invoke void @f() #2
19          to label %invoke.cont unwind label %catch.dispatch
20
21catch.dispatch:
22  %0 = catchswitch within none [label %__except] unwind to caller
23
24__except:
25  %1 = catchpad within %0 [i8* null]
26  catchret from %1 to label %__except1
27
28__except1:
29  %2 = call i32 @llvm.eh.exceptioncode(token %1)
30  store i32 %2, i32* %__exception_code, align 4
31  br label %__try.cont7
32;GEN:  _except1:
33;GEN:    call void @llvm.instrprof.increment(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @__profn_f, i32 0, i32 0), i64 62077759478, i32 2, i32 1)
34
35invoke.cont:
36  br label %__try.cont
37
38__try.cont:
39  invoke void @f()
40          to label %invoke.cont3 unwind label %catch.dispatch4
41
42catch.dispatch4:
43  %3 = catchswitch within none [label %__except5] unwind to caller
44; GEN: catch.dispatch4:
45; GEN-NOT: call void @llvm.instrprof.increment
46
47__except5:
48  %4 = catchpad within %3 [i8* null]
49  catchret from %4 to label %__except6
50
51__except6:
52  %5 = call i32 @llvm.eh.exceptioncode(token %4)
53  store i32 %5, i32* %__exception_code2, align 4
54  br label %__try.cont7
55
56__try.cont7:
57  ret void
58
59invoke.cont3:
60  br label %__try.cont7
61;GEN: invoke.cont3:
62;GEN:  call void @llvm.instrprof.increment(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @__profn_f, i32 0, i32 0), i64 62077759478, i32 2, i32 0)
63
64}
65
66declare dso_local i32 @__C_specific_handler(...)
67
68declare i32 @llvm.eh.exceptioncode(token)
69