1cee313d2SEric Christopher; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN 23307240fSFangrui Song; RUN: opt < %s -passes=pgo-instr-gen,instrprof -vp-static-alloc=true -S | FileCheck %s --check-prefix=LOWER 33307240fSFangrui Song; RUN: opt < %s -passes=pgo-instr-gen,instrprof -vp-static-alloc=false -S | FileCheck %s --check-prefix=LOWER 4cee313d2SEric Christopher 57b1d7937SAmy Huangtarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 6cee313d2SEric Christophertarget triple = "x86_64-unknown-linux-gnu" 7cee313d2SEric Christopher 83307240fSFangrui Song$novp_inline = comdat any 93307240fSFangrui Song$vp_inline = comdat any 10cee313d2SEric Christopher 11*9ff36df5SFangrui Song@bar = external global ptr, align 8 123307240fSFangrui Song 133307240fSFangrui Song; GEN: @__profn_novp_inline = linkonce_odr hidden constant [11 x i8] c"novp_inline" 14cee313d2SEric Christopher; GEN: @__profn_foo = private constant [3 x i8] c"foo" 153307240fSFangrui Song; GEN: @__profn_vp_inline = linkonce_odr hidden constant [9 x i8] c"vp_inline" 163307240fSFangrui Song 173307240fSFangrui Song;; Test that a linkonce function's address is recorded. 183307240fSFangrui Song;; We allow a linkonce profd to be private if the function does not use value profiling. 193307240fSFangrui Song; LOWER: @__profd_novp_inline.[[HASH:[0-9]+]] = private global {{.*}} @__profc_novp_inline.[[HASH]] 20*9ff36df5SFangrui Song; LOWER-SAME: ptr @novp_inline 213307240fSFangrui Song; LOWER: @__profd_foo = private {{.*}} @__profc_foo 223307240fSFangrui Song 233307240fSFangrui Song;; __profd_vp_inline.[[#]] is referenced by code and may be referenced by other 243307240fSFangrui Song;; text sections due to inlining. It can't be local because a linker error would 253307240fSFangrui Song;; occur if a prevailing text section references the non-prevailing local symbol. 263307240fSFangrui Song; LOWER: @__profd_vp_inline.[[FOO_HASH:[0-9]+]] = linkonce_odr hidden {{.*}} @__profc_vp_inline.[[FOO_HASH]] 27*9ff36df5SFangrui Song; LOWER-SAME: ptr @vp_inline 283307240fSFangrui Song 293307240fSFangrui Songdefine linkonce_odr void @novp_inline() comdat { 303307240fSFangrui Song ret void 313307240fSFangrui Song} 32cee313d2SEric Christopher 33cee313d2SEric Christopherdefine void @foo() { 34cee313d2SEric Christopherentry: 353307240fSFangrui Song; GEN: @foo() 36cee313d2SEric Christopher; GEN: entry: 37*9ff36df5SFangrui Song; GEN-NEXT: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 [[#FOO_HASH:]], i32 1, i32 0) 38*9ff36df5SFangrui Song %tmp = load ptr, ptr @bar, align 8 39*9ff36df5SFangrui Song; GEN: [[ICALL_TARGET:%[0-9]+]] = ptrtoint ptr %tmp to i64 40*9ff36df5SFangrui Song; GEN-NEXT: call void @llvm.instrprof.value.profile(ptr @__profn_foo, i64 [[#FOO_HASH]], i64 [[ICALL_TARGET]], i32 0, i32 0) 41*9ff36df5SFangrui Song; LOWER: call void @__llvm_profile_instrument_target(i64 %1, ptr @__profd_foo, i32 0) 423307240fSFangrui Song call void %tmp() 433307240fSFangrui Song ret void 443307240fSFangrui Song} 453307240fSFangrui Song 463307240fSFangrui Songdefine linkonce_odr void @vp_inline() comdat { 473307240fSFangrui Songentry: 483307240fSFangrui Song; GEN: @vp_inline() 493307240fSFangrui Song; GEN: entry: 50*9ff36df5SFangrui Song; GEN-NEXT: call void @llvm.instrprof.increment(ptr @__profn_vp_inline, i64 [[#FOO_HASH:]], i32 1, i32 0) 51*9ff36df5SFangrui Song %tmp = load ptr, ptr @bar, align 8 52*9ff36df5SFangrui Song; GEN: [[ICALL_TARGET:%[0-9]+]] = ptrtoint ptr %tmp to i64 53*9ff36df5SFangrui Song; GEN-NEXT: call void @llvm.instrprof.value.profile(ptr @__profn_vp_inline, i64 [[#FOO_HASH]], i64 [[ICALL_TARGET]], i32 0, i32 0) 54*9ff36df5SFangrui Song; LOWER: call void @__llvm_profile_instrument_target(i64 %1, ptr @__profd_vp_inline.[[#]], i32 0) 55cee313d2SEric Christopher call void %tmp() 56cee313d2SEric Christopher ret void 57cee313d2SEric Christopher} 58cee313d2SEric Christopher 59*9ff36df5SFangrui Song@bar2 = global ptr null, align 8 60*9ff36df5SFangrui Song@_ZTIi = external constant ptr 61cee313d2SEric Christopher 62*9ff36df5SFangrui Songdefine i32 @foo2(i32 %arg, ptr nocapture readnone %arg1) personality ptr @__gxx_personality_v0 { 63cee313d2SEric Christopherbb: 64*9ff36df5SFangrui Song %tmp2 = load ptr, ptr @bar2, align 8 65cee313d2SEric Christopher invoke void %tmp2() 66cee313d2SEric Christopher to label %bb10 unwind label %bb2 67*9ff36df5SFangrui Song; GEN: [[ICALL_TARGET2:%[0-9]+]] = ptrtoint ptr %tmp2 to i64 68*9ff36df5SFangrui Song; GEN-NEXT: call void @llvm.instrprof.value.profile(ptr @__profn_foo2, i64 [[FOO2_HASH:[0-9]+]], i64 [[ICALL_TARGET2]], i32 0, i32 0) 69cee313d2SEric Christopher 70cee313d2SEric Christopherbb2: ; preds = %bb 71*9ff36df5SFangrui Song %tmp3 = landingpad { ptr, i32 } 72*9ff36df5SFangrui Song catch ptr @_ZTIi 73*9ff36df5SFangrui Song %tmp4 = extractvalue { ptr, i32 } %tmp3, 1 74*9ff36df5SFangrui Song %tmp5 = tail call i32 @llvm.eh.typeid.for(ptr @_ZTIi) 75cee313d2SEric Christopher %tmp6 = icmp eq i32 %tmp4, %tmp5 76cee313d2SEric Christopher br i1 %tmp6, label %bb7, label %bb11 77cee313d2SEric Christopher 78cee313d2SEric Christopherbb7: ; preds = %bb2 79*9ff36df5SFangrui Song %tmp8 = extractvalue { ptr, i32 } %tmp3, 0 80*9ff36df5SFangrui Song %tmp9 = tail call ptr @__cxa_begin_catch(ptr %tmp8) 81cee313d2SEric Christopher tail call void @__cxa_end_catch() 82cee313d2SEric Christopher br label %bb10 83cee313d2SEric Christopher 84cee313d2SEric Christopherbb10: ; preds = %bb7, %bb 85cee313d2SEric Christopher ret i32 0 86cee313d2SEric Christopher 87cee313d2SEric Christopherbb11: ; preds = %bb2 88*9ff36df5SFangrui Song resume { ptr, i32 } %tmp3 89cee313d2SEric Christopher} 90cee313d2SEric Christopher 91cee313d2SEric Christopherdeclare i32 @__gxx_personality_v0(...) 92cee313d2SEric Christopher 93cee313d2SEric Christopher; Function Attrs: nounwind readnone 94*9ff36df5SFangrui Songdeclare i32 @llvm.eh.typeid.for(ptr) #0 95cee313d2SEric Christopher 96*9ff36df5SFangrui Songdeclare ptr @__cxa_begin_catch(ptr) 97cee313d2SEric Christopher 98cee313d2SEric Christopherdeclare void @__cxa_end_catch() 99cee313d2SEric Christopher 100