llvm.org GIT mirror llvm / 6e7129c
[profile] value profiling bug fix -- missing icall targets in profile-use Inline virtual functions has linkeonceodr linkage (emitted in comdat on supporting targets). If the vtable for the class is not emitted in the defining module, function won't be address taken thus its address is not recorded. At the mercy of the linker, if the per-func prf_data from this module (in comdat) is picked at link time, we will lose mapping from function address to its hash val. This leads to missing icall promotion. The second test case (currently disabled) in compiler_rt (r271528): instrprof-icall-prom.test demostrates the bug. The first profile-use subtest is fine due to linker order difference. With this change, no missing icall targets is found in instrumented clang's raw profile. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271532 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 4 years ago
3 changed file(s) with 20 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
257257 if (F->hasLocalLinkage() && F->hasComdat())
258258 return false;
259259 // Check uses of this function for other than direct calls or invokes to it.
260 return F->hasAddressTaken();
260 // Inline virtual functions have linkeOnceODR linkage. When a key method
261 // exists, the vtable will only be emitted in the TU where the key method
262 // is defined. In a TU where vtable is not available, the function won't
263 // be 'addresstaken'. If its address is not recorded here, the profile counter
264 // comdat group with missing address may be picked by the linker leading
265 // to missing indirect call target info.
266 return F->hasAddressTaken() || (F->hasLinkOnceLinkage() && F->hasComdat());
261267 }
262268
263269 static inline bool needsComdatForCounter(Function &F, Module &M) {
1414
1515 ; CHECK: @__profn__Z3barIvEvv = private constant [11 x i8] c"_Z3barIvEvv", align 1
1616 ; CHECK: @__profc__Z3barIvEvv = linkonce_odr hidden global [1 x i64] zeroinitializer, section "{{.*}}__llvm_prf_cnts", comdat($__profv__Z3barIvEvv), align 8
17 ; CHECK: @__profd__Z3barIvEvv = linkonce_odr hidden global { i64, i64, i64*, i8*, i8*, i32, [1 x i16] } { i64 4947693190065689389, i64 0, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc__Z3barIvEvv, i32 0, i32 0), i8* null, i8* null, i32 1, [1 x i16] zeroinitializer }, section "{{.*}}__llvm_prf_data", comdat($__profv__Z3barIvEvv), align 8
17 ; CHECK: @__profd__Z3barIvEvv = linkonce_odr hidden global { i64, i64, i64*, i8*, i8*, i32, [1 x i16] } { i64 4947693190065689389, i64 0, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc__Z3barIvEvv, i32 0, i32 0), i8*{{.*}}, i8* null, i32 1, [1 x i16] zeroinitializer }, section "{{.*}}__llvm_prf_data", comdat($__profv__Z3barIvEvv), align 8
1818 ; CHECK: @__llvm_prf_nm = private constant [{{.*}} x i8] c"{{.*}}", section "{{.*}}__llvm_prf_names"
1919
2020
2121 ; COFF: @__profn__Z3barIvEvv = private constant [11 x i8] c"_Z3barIvEvv", align 1
2222 ; COFF: @__profc__Z3barIvEvv = linkonce_odr hidden global [1 x i64] zeroinitializer, section "{{.*}}__llvm_prf_cnts", comdat, align 8
23 ; COFF: @__profd__Z3barIvEvv = linkonce_odr hidden global { i64, i64, i64*, i8*, i8*, i32, [1 x i16] } { i64 4947693190065689389, i64 0, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc__Z3barIvEvv, i32 0, i32 0), i8* null, i8* null, i32 1, [1 x i16] zeroinitializer }, section "{{.*}}__llvm_prf_data", comdat($__profc__Z3barIvEvv), align 8
23 ; COFF: @__profd__Z3barIvEvv = linkonce_odr hidden global { i64, i64, i64*, i8*, i8*, i32, [1 x i16] } { i64 4947693190065689389, i64 0, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc__Z3barIvEvv, i32 0, i32 0), i8*{{.*}}, i8* null, i32 1, [1 x i16] zeroinitializer }, section "{{.*}}__llvm_prf_data", comdat($__profc__Z3barIvEvv), align 8
2424
2525
2626 declare void @llvm.instrprof.increment(i8*, i64, i32, i32) #1
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
11 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
2 ; RUN: opt < %s -passes=pgo-instr-gen,instrprof -S | FileCheck %s --check-prefix=LOWER
3
24 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
35 target triple = "x86_64-unknown-linux-gnu"
6
7 $foo3 = comdat any
48
59 @bar = external global void ()*, align 8
610 ; GEN: @__profn_foo = private constant [3 x i8] c"foo"
4852 resume { i8*, i32 } %tmp3
4953 }
5054
55 ; Test that comdat function's address is recorded.
56 ; LOWER: @__profd_foo3 = linkonce_odr{{.*}}@foo3
57 ; Function Attrs: nounwind uwtable
58 define linkonce_odr i32 @foo3() comdat {
59 ret i32 1
60 }
61
5162 declare i32 @__gxx_personality_v0(...)
5263
5364 ; Function Attrs: nounwind readnone