Skip to content

Commit d47ce4e

Browse files
fix test to make it pass at HEAD
1 parent 78fe701 commit d47ce4e

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

compiler-rt/test/profile/Linux/instrprof-vtable-value-prof.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// ld.lld: error: /lib/../lib64/Scrt1.o: ABI version 1 is not supported
77
// UNSUPPORTED: ppc && host-byteorder-big-endian
88

9-
// RUN: rm -rf %t && split-file %s %t && cd %t
9+
// RUN: rm -rf %t && mkdir %t && split-file %s %t && cd %t
1010

11-
// RUN: %clangxx_pgogen -fuse-ld=lld -O2 -fprofile-generate=. -mllvm -enable-vtable-value-profiling %s -o test
11+
// RUN: %clangxx_pgogen -fuse-ld=lld -O2 -fprofile-generate=. -mllvm -enable-vtable-value-profiling lib.cpp main.cpp -o test
1212
// RUN: env LLVM_PROFILE_FILE=test.profraw ./test
1313

1414
// Show vtable profiles from raw profile.
@@ -38,23 +38,23 @@
3838
// COMMON-NEXT: Number of instrumented vtables: 2
3939
// RAW: Indirect Target Results:
4040
// RAW-NEXT: [ 0, _ZN8Derived14funcEii, 50 ] (25.00%)
41-
// RAW-NEXT: [ 0, {{.*}}instrprof-vtable-value-prof.cpp;_ZN12_GLOBAL__N_18Derived24funcEii, 150 ] (75.00%)
41+
// RAW-NEXT: [ 0, {{.*}}lib.cpp;_ZN12_GLOBAL__N_18Derived24funcEii, 150 ] (75.00%)
4242
// RAW-NEXT: [ 1, _ZN8Derived1D0Ev, 250 ] (25.00%)
43-
// RAW-NEXT: [ 1, {{.*}}instrprof-vtable-value-prof.cpp;_ZN12_GLOBAL__N_18Derived2D0Ev, 750 ] (75.00%)
43+
// RAW-NEXT: [ 1, {{.*}}lib.cpp;_ZN12_GLOBAL__N_18Derived2D0Ev, 750 ] (75.00%)
4444
// RAW-NEXT: VTable Results:
4545
// RAW-NEXT: [ 0, _ZTV8Derived1, 50 ] (25.00%)
46-
// RAW-NEXT: [ 0, {{.*}}instrprof-vtable-value-prof.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 150 ] (75.00%)
46+
// RAW-NEXT: [ 0, {{.*}}lib.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 150 ] (75.00%)
4747
// RAW-NEXT: [ 1, _ZTV8Derived1, 250 ] (25.00%)
48-
// RAW-NEXT: [ 1, {{.*}}instrprof-vtable-value-prof.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%)
48+
// RAW-NEXT: [ 1, {{.*}}lib.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%)
4949
// INDEXED: Indirect Target Results:
50-
// INDEXED-NEXT: [ 0, {{.*}}instrprof-vtable-value-prof.cpp;_ZN12_GLOBAL__N_18Derived24funcEii, 150 ] (75.00%)
50+
// INDEXED-NEXT: [ 0, {{.*}}lib.cpp;_ZN12_GLOBAL__N_18Derived24funcEii, 150 ] (75.00%)
5151
// INDEXED-NEXT: [ 0, _ZN8Derived14funcEii, 50 ] (25.00%)
52-
// INDEXED-NEXT: [ 1, {{.*}}instrprof-vtable-value-prof.cpp;_ZN12_GLOBAL__N_18Derived2D0Ev, 750 ] (75.00%)
52+
// INDEXED-NEXT: [ 1, {{.*}}lib.cpp;_ZN12_GLOBAL__N_18Derived2D0Ev, 750 ] (75.00%)
5353
// INDEXED-NEXT: [ 1, _ZN8Derived1D0Ev, 250 ] (25.00%)
5454
// INDEXED-NEXT: VTable Results:
55-
// INDEXED-NEXT: [ 0, {{.*}}instrprof-vtable-value-prof.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 150 ] (75.00%)
55+
// INDEXED-NEXT: [ 0, {{.*}}lib.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 150 ] (75.00%)
5656
// INDEXED-NEXT: [ 0, _ZTV8Derived1, 50 ] (25.00%)
57-
// INDEXED-NEXT: [ 1, {{.*}}instrprof-vtable-value-prof.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%)
57+
// INDEXED-NEXT: [ 1, {{.*}}lib.cpp;_ZTVN12_GLOBAL__N_18Derived2E, 750 ] (75.00%)
5858
// INDEXED-NEXT: [ 1, _ZTV8Derived1, 250 ] (25.00%)
5959
// COMMON: Instrumentation level: IR entry_first = 0
6060
// COMMON-NEXT: Functions shown: 1
@@ -94,27 +94,27 @@
9494
// ICTEXT: # NumValueSites:
9595
// ICTEXT: 2
9696
// ICTEXT: 2
97-
// ICTEXT: {{.*}}instrprof-vtable-value-prof.cpp;_ZN12_GLOBAL__N_18Derived24funcEii:150
97+
// ICTEXT: {{.*}}lib.cpp;_ZN12_GLOBAL__N_18Derived24funcEii:150
9898
// ICTEXT: _ZN8Derived14funcEii:50
9999
// ICTEXT: 2
100-
// ICTEXT: {{.*}}instrprof-vtable-value-prof.cpp;_ZN12_GLOBAL__N_18Derived2D0Ev:750
100+
// ICTEXT: {{.*}}lib.cpp;_ZN12_GLOBAL__N_18Derived2D0Ev:750
101101
// ICTEXT: _ZN8Derived1D0Ev:250
102102
// ICTEXT: # ValueKind = IPVK_VTableTarget:
103103
// ICTEXT: 2
104104
// ICTEXT: # NumValueSites:
105105
// ICTEXT: 2
106106
// ICTEXT: 2
107-
// ICTEXT: {{.*}}instrprof-vtable-value-prof.cpp;_ZTVN12_GLOBAL__N_18Derived2E:150
107+
// ICTEXT: {{.*}}lib.cpp;_ZTVN12_GLOBAL__N_18Derived2E:150
108108
// ICTEXT: _ZTV8Derived1:50
109109
// ICTEXT: 2
110-
// ICTEXT: {{.*}}instrprof-vtable-value-prof.cpp;_ZTVN12_GLOBAL__N_18Derived2E:750
110+
// ICTEXT: {{.*}}lib.cpp;_ZTVN12_GLOBAL__N_18Derived2E:750
111111
// ICTEXT: _ZTV8Derived1:250
112112

113113
// When vtable value profiles exist, pgo-instr-use pass should annotate them
114114
// even if `-enable-vtable-value-profiling` is not explicitly on.
115115
// RUN: %clangxx -m64 -fprofile-use=test.profdata -fuse-ld=lld -O2 \
116116
// RUN: -mllvm -print-after=pgo-instr-use -mllvm -filter-print-funcs=main \
117-
// RUN: -mllvm -print-module-scope %s 2>&1 | FileCheck %s --check-prefix=ANNOTATE
117+
// RUN: -mllvm -print-module-scope lib.cpp main.cpp 2>&1 | FileCheck %s --check-prefix=ANNOTATE
118118

119119
// ANNOTATE-NOT: Inconsistent number of value sites
120120
// ANNOTATE: !{!"VP", i32 2
@@ -123,7 +123,7 @@
123123
// if `-icp-max-num-vtables` is set to zero.
124124
// RUN: %clangxx -m64 -fprofile-use=test.profdata -fuse-ld=lld -O2 \
125125
// RUN: -mllvm -icp-max-num-vtables=0 -mllvm -print-after=pgo-instr-use \
126-
// RUN: -mllvm -filter-print-funcs=main -mllvm -print-module-scope %s 2>&1 | \
126+
// RUN: -mllvm -filter-print-funcs=main -mllvm -print-module-scope lib.cpp main.cpp 2>&1 | \
127127
// RUN: FileCheck %s --check-prefix=OMIT
128128

129129
// OMIT: Inconsistent number of value sites
@@ -145,26 +145,26 @@
145145
// RUN: -Wl,-plugin-opt,-import-assume-unique-local \
146146
// RUN: -Wl,-mllvm,-enable-vtable-profile-use -Rpass=pgo-icall-prom \
147147
// RUN: -Wl,-mllvm,-print-after=pgo-icall-prom \
148-
// RUN: -Wl,-mllvm,-filter-print-funcs=main %s 2>&1 \
148+
// RUN: -Wl,-mllvm,-filter-print-funcs=main lib.cpp main.cpp 2>&1 \
149149
// RUN: | FileCheck %s --check-prefixes=REMARK,IR --implicit-check-not="!VP"
150150

151151
// For the indirect call site `ptr->func`
152-
// REMARK: instrprof-vtable-value-prof.cpp:240:19: Promote indirect call to _ZN12_GLOBAL__N_18Derived24funcEii with count 150 out of 200, sink 1 instruction(s) and compare 1 vtable(s): {_ZTVN12_GLOBAL__N_18Derived2E}
153-
// REMARK: instrprof-vtable-value-prof.cpp:240:19: Promote indirect call to _ZN8Derived14funcEii with count 50 out of 50, sink 1 instruction(s) and compare 1 vtable(s): {_ZTV8Derived1}
152+
// REMARK: main.cpp:10:19: Promote indirect call to _ZN12_GLOBAL__N_18Derived24funcEii.llvm.{{.*}} with count 150 out of 200, sink 1 instruction(s) and compare 1 vtable(s): {_ZTVN12_GLOBAL__N_18Derived2E.llvm.{{.*}}}
153+
// REMARK: main.cpp:10:19: Promote indirect call to _ZN8Derived14funcEii with count 50 out of 50, sink 1 instruction(s) and compare 1 vtable(s): {_ZTV8Derived1}
154154
//
155155
// For the indirect call site `delete ptr`
156-
// REMARK: instrprof-vtable-value-prof.cpp:242:5: Promote indirect call to _ZN12_GLOBAL__N_18Derived2D0Ev with count 750 out of 1000, sink 2 instruction(s) and compare 1 vtable(s): {_ZTVN12_GLOBAL__N_18Derived2E}
157-
// REMARK: instrprof-vtable-value-prof.cpp:242:5: Promote indirect call to _ZN8Derived1D0Ev with count 250 out of 250, sink 2 instruction(s) and compare 1 vtable(s): {_ZTV8Derived1}
156+
// REMARK: main.cpp:12:5: Promote indirect call to _ZN12_GLOBAL__N_18Derived2D0Ev.llvm.{{.*}} with count 750 out of 1000, sink 2 instruction(s) and compare 1 vtable(s): {_ZTVN12_GLOBAL__N_18Derived2E.llvm.{{.*}}}
157+
// REMARK: main.cpp:12:5: Promote indirect call to _ZN8Derived1D0Ev with count 250 out of 250, sink 2 instruction(s) and compare 1 vtable(s): {_ZTV8Derived1}
158158

159159
// The IR matchers for indirect callsite `ptr->func`.
160160
// IR-LABEL: @main
161161
// IR: [[OBJ:%.*]] = {{.*}}call {{.*}} @_Z10createTypei
162162
// IR: [[VTABLE:%.*]] = load ptr, ptr [[OBJ]]
163-
// IR: [[CMP1:%.*]] = icmp eq ptr [[VTABLE]], getelementptr inbounds (i8, ptr @_ZTVN12_GLOBAL__N_18Derived2E, i32 16)
163+
// IR: [[CMP1:%.*]] = icmp eq ptr [[VTABLE]], getelementptr inbounds (i8, ptr @_ZTVN12_GLOBAL__N_18Derived2E.llvm.{{.*}}, i32 16)
164164
// IR: br i1 [[CMP1]], label %[[BB1:.*]], label %[[BB2:[a-zA-Z0-9_.]+]],
165165
//
166166
// IR: [[BB1]]:
167-
// IR: [[RESBB1:%.*]] = {{.*}}call {{.*}} @_ZN12_GLOBAL__N_18Derived24funcEii
167+
// IR: [[RESBB1:%.*]] = {{.*}}call {{.*}} @_ZN12_GLOBAL__N_18Derived24funcEii.llvm.{{.*}}
168168
// IR: br label %[[MERGE0:[a-zA-Z0-9_.]+]]
169169
//
170170
// IR: [[BB2]]:
@@ -203,23 +203,23 @@ class Derived1 : public Base {
203203

204204
~Derived1() {}
205205
};
206+
207+
__attribute__((noinline)) Base *createType(int a);
208+
209+
//--- lib.cpp
210+
#include "lib.h"
211+
206212
namespace {
207213
class Derived2 : public Base {
208214
public:
209-
int func(int a, int b) override;
215+
int func(int a, int b) override { return a * (a - b); }
210216

211217
~Derived2() {}
212218
};
213219
} // namespace
214220

215-
__attribute__((noinline)) Base *createType(int a);
216-
217-
//-- lib.cpp
218-
219221
int Derived1::func(int a, int b) { return a * b; }
220222

221-
int Derived2::func(int a, int b) { return a * (a - b); }
222-
223223
Base *createType(int a) {
224224
Base *base = nullptr;
225225
if (a % 4 == 0)
@@ -230,6 +230,8 @@ Base *createType(int a) {
230230
}
231231

232232
//--- main.cpp
233+
#include "lib.h"
234+
233235
int main(int argc, char **argv) {
234236
int sum = 0;
235237
for (int i = 0; i < 1000; i++) {

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ class GlobalsImporter final {
381381
[&](const GlobalValueSummary *RefSummary) -> bool {
382382
if (ImportAssumeUniqueLocal)
383383
return false;
384+
385+
errs() << "Ref VI is " << VI << "\n";
386+
errs() << RefSummary->modulePath() << "\n";
387+
errs() << Summary.modulePath() << "\n";
384388
return GlobalValue::isLocalLinkage(RefSummary->linkage()) &&
385389
RefSummary->modulePath() != Summary.modulePath();
386390
};

0 commit comments

Comments
 (0)