1 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
2 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
3 ; RUN: opt < %s -passes=pgo-instr-gen,instrprof -vp-static-alloc=true -S | FileCheck %s --check-prefix=LOWER
4 ; RUN: opt < %s -passes=pgo-instr-gen,instrprof -vp-static-alloc=false -S | FileCheck %s --check-prefix=LOWER
6 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-unknown-linux-gnu"
9 $novp_inline = comdat any
10 $vp_inline = comdat any
12 @bar = external global void ()*, align 8
14 ; GEN: @__profn_novp_inline = linkonce_odr hidden constant [11 x i8] c"novp_inline"
15 ; GEN: @__profn_foo = private constant [3 x i8] c"foo"
16 ; GEN: @__profn_vp_inline = linkonce_odr hidden constant [9 x i8] c"vp_inline"
18 ;; Test that a linkonce function's address is recorded.
19 ;; We allow a linkonce profd to be private if the function does not use value profiling.
20 ; LOWER: @__profd_novp_inline.[[HASH:[0-9]+]] = private global {{.*}} @__profc_novp_inline.[[HASH]]
21 ; LOWER-SAME: i8* bitcast (void ()* @novp_inline to i8*)
22 ; LOWER: @__profd_foo = private {{.*}} @__profc_foo
24 ;; __profd_vp_inline.[[#]] is referenced by code and may be referenced by other
25 ;; text sections due to inlining. It can't be local because a linker error would
26 ;; occur if a prevailing text section references the non-prevailing local symbol.
27 ; LOWER: @__profd_vp_inline.[[FOO_HASH:[0-9]+]] = linkonce_odr hidden {{.*}} @__profc_vp_inline.[[FOO_HASH]]
28 ; LOWER-SAME: i8* bitcast (void ()* @vp_inline to i8*)
30 define linkonce_odr void @novp_inline() comdat {
38 ; GEN-NEXT: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 [[#FOO_HASH:]], i32 1, i32 0)
39 %tmp = load void ()*, void ()** @bar, align 8
40 ; GEN: [[ICALL_TARGET:%[0-9]+]] = ptrtoint void ()* %tmp to i64
41 ; GEN-NEXT: call void @llvm.instrprof.value.profile(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 [[#FOO_HASH]], i64 [[ICALL_TARGET]], i32 0, i32 0)
42 ; LOWER: call void @__llvm_profile_instrument_target(i64 %1, i8* bitcast ({ i64, i64, i64, i8*, i8*, i32, [2 x i16] }* @__profd_foo to i8*), i32 0)
47 define linkonce_odr void @vp_inline() comdat {
51 ; GEN-NEXT: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_vp_inline, i32 0, i32 0), i64 [[#FOO_HASH:]], i32 1, i32 0)
52 %tmp = load void ()*, void ()** @bar, align 8
53 ; GEN: [[ICALL_TARGET:%[0-9]+]] = ptrtoint void ()* %tmp to i64
54 ; GEN-NEXT: call void @llvm.instrprof.value.profile(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_vp_inline, i32 0, i32 0), i64 [[#FOO_HASH]], i64 [[ICALL_TARGET]], i32 0, i32 0)
55 ; LOWER: call void @__llvm_profile_instrument_target(i64 %1, i8* bitcast ({ i64, i64, i64, i8*, i8*, i32, [2 x i16] }* @__profd_vp_inline.[[#]] to i8*), i32 0)
60 @bar2 = global void ()* null, align 8
61 @_ZTIi = external constant i8*
63 define i32 @foo2(i32 %arg, i8** nocapture readnone %arg1) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
65 %tmp2 = load void ()*, void ()** @bar2, align 8
67 to label %bb10 unwind label %bb2
68 ; GEN: [[ICALL_TARGET2:%[0-9]+]] = ptrtoint void ()* %tmp2 to i64
69 ; GEN-NEXT: call void @llvm.instrprof.value.profile(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__profn_foo2, i32 0, i32 0), i64 [[FOO2_HASH:[0-9]+]], i64 [[ICALL_TARGET2]], i32 0, i32 0)
72 %tmp3 = landingpad { i8*, i32 }
73 catch i8* bitcast (i8** @_ZTIi to i8*)
74 %tmp4 = extractvalue { i8*, i32 } %tmp3, 1
75 %tmp5 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
76 %tmp6 = icmp eq i32 %tmp4, %tmp5
77 br i1 %tmp6, label %bb7, label %bb11
80 %tmp8 = extractvalue { i8*, i32 } %tmp3, 0
81 %tmp9 = tail call i8* @__cxa_begin_catch(i8* %tmp8)
82 tail call void @__cxa_end_catch()
85 bb10: ; preds = %bb7, %bb
89 resume { i8*, i32 } %tmp3
92 declare i32 @__gxx_personality_v0(...)
94 ; Function Attrs: nounwind readnone
95 declare i32 @llvm.eh.typeid.for(i8*) #0
97 declare i8* @__cxa_begin_catch(i8*)
99 declare void @__cxa_end_catch()