96 lines · plain
1; RUN: opt < %s -passes=pgo-instr-gen -enable-vtable-value-profiling -S 2>&1 | FileCheck %s --check-prefix=GEN --implicit-check-not="VTable value profiling is presently not supported"2; RUN: opt < %s -passes=pgo-instr-gen,instrprof -enable-vtable-value-profiling -S 2>&1 | FileCheck %s --check-prefix=LOWER --implicit-check-not="VTable value profiling is presently not supported"3 4source_filename = "vtable_local.ll"5target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"6target triple = "x86_64-unknown-linux-gnu"7 8; The test IR is generated based on the following C++ program.9; Base1 has external linkage and Base2 has local linkage.10; class Derived uses multiple inheritance so its virtual table11; global variable contains two vtables. func1 is loaded from12; the vtable compatible with class Base1, and func2 is loaded13; from the vtable compatible with class Base2.14 15; class Base1 {16; public:17; virtual int func1(int a) ;18; };19;20; namespace {21; class Base2 {22; public:23; __attribute__((noinline)) virtual int func2(int a) {24; return a;25; }26; };27; }28 29; class Derived : public Base1, public Base2 {30; public:31; Derived(int c) : v(c) {}32; private:33; int v;34; };35;36; Derived* createType();37 38; int func(int a) {39; Derived* d = createType();40; return d->func2(a) + d->func1(a);41; }42 43target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"44target triple = "x86_64-unknown-linux-gnu"45 46@_ZTV7Derived = constant { [3 x ptr], [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN5Base15func1Ei], [3 x ptr] [ptr inttoptr (i64 -8 to ptr), ptr null, ptr @_ZN12_GLOBAL__N_15Base25func2Ei] }, !type !0, !type !3, !type !6, !type !8, !type !1047@_ZTV5Base1 = available_externally constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN5Base15func1Ei] }, !type !048@_ZTVN12_GLOBAL__N_15Base2E = internal constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN12_GLOBAL__N_15Base25func2Ei] }, !type !11, !type !8; !vcall_visibility !1249@llvm.compiler.used = appending global [1 x ptr] [ptr @_ZTV5Base1], section "llvm.metadata"50 51; GEN: __llvm_profile_raw_version = comdat any52; GEN: __llvm_profile_raw_version = hidden constant i64 72057594037927946, comdat53; GEN: __profn__Z4funci = private constant [8 x i8] c"_Z4funci"54 55; LOWER: $__profvt__ZTV7Derived = comdat nodeduplicate56; LOWER: $"__profvt_vtable_local.ll;_ZTVN12_GLOBAL__N_15Base2E" = comdat nodeduplicate57; LOWER: @__profvt__ZTV7Derived = global { i64, ptr, i32 } { i64 -4576307468236080025, ptr @_ZTV7Derived, i32 48 }, section "__llvm_prf_vtab", comdat, align 858; LOWER: @"__profvt_vtable_local.ll;_ZTVN12_GLOBAL__N_15Base2E" = internal global { i64, ptr, i32 } { i64 1419990121885302679, ptr @_ZTVN12_GLOBAL__N_15Base2E, i32 24 }, section "__llvm_prf_vtab", comdat, align 859; LOWER: @__llvm_prf_vnm = private constant {{.*}}, section "__llvm_prf_vns", align 160; LOWER: @llvm.used = appending global [5 x ptr] [ptr @__profvt__ZTV7Derived, ptr @"__profvt_vtable_local.ll;_ZTVN12_GLOBAL__N_15Base2E", ptr @__llvm_prf_vnodes, ptr @__llvm_prf_nm, ptr @__llvm_prf_vnm], section "llvm.metadata"61 62define i32 @_Z4funci(i32 %a) {63entry:64 %call = call ptr @_Z10createTypev()65 %add.ptr = getelementptr inbounds i8, ptr %call, i64 866 %vtable = load ptr, ptr %add.ptr67; GEN: [[P1:%[0-9]+]] = ptrtoint ptr %vtable to i6468; GEN: call void @llvm.instrprof.value.profile(ptr @__profn__Z4funci, i64 [[CFGHash:[0-9]+]], i64 [[P1]], i32 2, i32 0)69; LOWER: [[P1:%[0-9]+]] = ptrtoint ptr %vtable to i6470; LOWER: call void @__llvm_profile_instrument_target(i64 [[P1]], ptr @__profd__Z4funci, i32 2)71 %vfunc1 = load ptr, ptr %vtable72 %call1 = call i32 %vfunc1(ptr %add.ptr, i32 %a)73 %vtable2 = load ptr, ptr %call74; GEN: [[P2:%[0-9]+]] = ptrtoint ptr %vtable2 to i6475; GEN: call void @llvm.instrprof.value.profile(ptr @__profn__Z4funci, i64 [[CFGHash]], i64 [[P2]], i32 2, i32 1)76; LOWER: [[P2:%[0-9]+]] = ptrtoint ptr %vtable2 to i6477; LOWER: call void @__llvm_profile_instrument_target(i64 [[P2]], ptr @__profd__Z4funci, i32 3)78 %vfunc2 = load ptr, ptr %vtable279 %call4 = call i32 %vfunc2(ptr %call, i32 %a)80 %add = add nsw i32 %call1, %call481 ret i32 %add82}83 84declare ptr @_Z10createTypev()85declare i32 @_ZN12_GLOBAL__N_15Base25func2Ei(ptr %this, i32 %a)86declare i32 @_ZN5Base15func1Ei(ptr, i32)87 88!0 = !{i64 16, !"_ZTS5Base1"}89!3 = !{i64 16, !"_ZTS7Derived"}90!6 = !{i64 40, !7}91!7 = distinct !{}92!8 = !{i64 16, !9}93!9 = distinct !{}94!10 = !{i64 40, !9}95!11 = !{i64 16, !7}96