Skip to content

Commit 64f5d7e

Browse files
committed
Revert "[InstrProfiling] Place __llvm_prf_vnodes and __llvm_prf_names in llvm.used on ELF"
This reverts commit 04c3040. Breaks instrprof-value-merge.c in bootstrap builds.
1 parent c714b44 commit 64f5d7e

File tree

6 files changed

+75
-123
lines changed

6 files changed

+75
-123
lines changed

compiler-rt/test/profile/Linux/Inputs/instrprof-value-merge.c

Lines changed: 0 additions & 70 deletions
This file was deleted.

compiler-rt/test/profile/Linux/instrprof-value-merge-lld.c

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,79 @@
1-
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c
1+
// RUN: %clang_pgogen -o %t -O3 %s
22
// RUN: rm -rf %t.profdir
33
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
44
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
55
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
66
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
77
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
8-
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c
8+
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %s
99

10-
/// -z start-stop-gc requires binutils 2.37.
11-
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c -fuse-ld=bfd -ffunction-sections -fdata-sections -Wl,--gc-sections
12-
// RUN: rm -rf %t.profdir
13-
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
14-
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
15-
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
16-
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
17-
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
18-
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c
10+
#include <string.h>
1911

20-
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c -fuse-ld=gold -ffunction-sections -fdata-sections -Wl,--gc-sections
21-
// RUN: rm -rf %t.profdir
22-
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
23-
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
24-
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
25-
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
26-
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
27-
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c
12+
void (*f0)();
13+
void (*f1)();
14+
void (*f2)();
15+
16+
char dst[200];
17+
char src[200];
18+
volatile int n;
19+
20+
__attribute__((noinline)) void foo() {}
21+
22+
__attribute__((noinline)) void bar() {
23+
f0 = foo;
24+
f1 = foo;
25+
f2 = foo;
26+
n = 4;
27+
}
28+
int main(int argc, char *argv[]) {
29+
int i;
30+
bar();
31+
if (argc == 1) {
32+
f0();
33+
for (i = 0; i < 9; i++)
34+
f1();
35+
for (i = 0; i < 99; i++)
36+
f2();
37+
} else {
38+
memcpy((void *)dst, (void *)src, n);
39+
for (i = 0; i < 6; i++)
40+
memcpy((void *)(dst + 2), (void *)src, n + 1);
41+
for (i = 0; i < 66; i++)
42+
memcpy((void *)(dst + 9), (void *)src, n + 2);
43+
}
44+
}
45+
46+
// CHECK: Counters:
47+
// CHECK: main:
48+
// CHECK: Hash: 0x0a9bd81e87ab6e87
49+
// CHECK: Counters: 6
50+
// CHECK: Indirect Call Site Count: 3
51+
// CHECK: Number of Memory Intrinsics Calls: 3
52+
// CHECK: Block counts: [27, 297, 12, 132, 3, 2]
53+
// CHECK: Indirect Target Results:
54+
// CHECK: [ 0, foo, 3 ]
55+
// CHECK: [ 1, foo, 27 ]
56+
// CHECK: [ 2, foo, 297 ]
57+
// CHECK: Memory Intrinsic Size Results:
58+
// CHECK: [ 0, 4, 2 ]
59+
// CHECK: [ 1, 5, 12 ]
60+
// CHECK: [ 2, 6, 132 ]
61+
// CHECK: Instrumentation level: IR
62+
// CHECK: Functions shown: 1
63+
// CHECK: Total functions: 3
64+
// CHECK: Maximum function count: 327
65+
// CHECK: Maximum internal block count: 297
66+
// CHECK: Statistics for indirect call sites profile:
67+
// CHECK: Total number of sites: 3
68+
// CHECK: Total number of sites with values: 3
69+
// CHECK: Total number of profiled values: 3
70+
// CHECK: Value sites histogram:
71+
// CHECK: NumTargets, SiteCount
72+
// CHECK: 1, 3
73+
// CHECK: Statistics for memory intrinsic calls sizes profile:
74+
// CHECK: Total number of sites: 3
75+
// CHECK: Total number of sites with values: 3
76+
// CHECK: Total number of profiled values: 3
77+
// CHECK: Value sites histogram:
78+
// CHECK: NumTargets, SiteCount
79+
// CHECK: 1, 3

llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class InstrProfiling : public PassInfoMixin<InstrProfiling> {
5757
}
5858
};
5959
DenseMap<GlobalVariable *, PerFunctionProfileData> ProfileDataMap;
60-
std::vector<GlobalValue *> CompilerUsedVars;
6160
std::vector<GlobalValue *> UsedVars;
6261
std::vector<GlobalVariable *> ReferencedNames;
6362
GlobalVariable *NamesVar;

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ bool InstrProfiling::run(
539539
NamesVar = nullptr;
540540
NamesSize = 0;
541541
ProfileDataMap.clear();
542-
CompilerUsedVars.clear();
543542
UsedVars.clear();
544543
TT = Triple(M.getTargetTriple());
545544

@@ -922,7 +921,7 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
922921
ProfileDataMap[NamePtr] = PD;
923922

924923
// Mark the data variable as used so that it isn't stripped out.
925-
CompilerUsedVars.push_back(Data);
924+
UsedVars.push_back(Data);
926925
// Now that the linkage set by the FE has been passed to the data and counter
927926
// variables, reset Name variable's linkage and visibility to private so that
928927
// it can be removed later by the compiler.
@@ -977,8 +976,6 @@ void InstrProfiling::emitVNodes() {
977976
Constant::getNullValue(VNodesTy), getInstrProfVNodesVarName());
978977
VNodesVar->setSection(
979978
getInstrProfSectionName(IPSK_vnodes, TT.getObjectFormat()));
980-
// VNodesVar is used by runtime but not referenced via relocation by other
981-
// sections. Conservatively make it linker retained.
982979
UsedVars.push_back(VNodesVar);
983980
}
984981

@@ -1007,8 +1004,6 @@ void InstrProfiling::emitNameData() {
10071004
// linker from inserting padding before the start of the names section or
10081005
// between names entries.
10091006
NamesVar->setAlignment(Align(1));
1010-
// NamesVar is used by runtime but not referenced via relocation by other
1011-
// sections. Conservatively make it linker retained.
10121007
UsedVars.push_back(NamesVar);
10131008

10141009
for (auto *NamePtr : ReferencedNames)
@@ -1036,9 +1031,6 @@ void InstrProfiling::emitRegistration() {
10361031
getInstrProfRegFuncName(), M);
10371032

10381033
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", RegisterF));
1039-
for (Value *Data : CompilerUsedVars)
1040-
if (Data != NamesVar && !isa<Function>(Data))
1041-
IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(Data, VoidPtrTy));
10421034
for (Value *Data : UsedVars)
10431035
if (Data != NamesVar && !isa<Function>(Data))
10441036
IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(Data, VoidPtrTy));
@@ -1089,7 +1081,7 @@ bool InstrProfiling::emitRuntimeHook() {
10891081
IRB.CreateRet(Load);
10901082

10911083
// Mark the user variable as used so that it isn't stripped out.
1092-
CompilerUsedVars.push_back(User);
1084+
UsedVars.push_back(User);
10931085
return true;
10941086
}
10951087

@@ -1102,14 +1094,9 @@ void InstrProfiling::emitUses() {
11021094
// or discarded as a unit, so llvm.compiler.used is sufficient. Otherwise,
11031095
// conservatively make all of them retained by the linker.
11041096
if (TT.isOSBinFormatELF())
1105-
appendToCompilerUsed(*M, CompilerUsedVars);
1097+
appendToCompilerUsed(*M, UsedVars);
11061098
else
1107-
appendToUsed(*M, CompilerUsedVars);
1108-
1109-
// We do not add proper references from used metadata sections to NamesVar and
1110-
// VNodesVar, so we have to be conservative and place them in llvm.used
1111-
// regardless of the target,
1112-
appendToUsed(*M, UsedVars);
1099+
appendToUsed(*M, UsedVars);
11131100
}
11141101

11151102
void InstrProfiling::emitInitialization() {

llvm/test/Instrumentation/InstrProfiling/icall.ll

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ attributes #0 = { nounwind }
5050
; DYN-NOT: @__profvp_foo
5151
; DYN-NOT: @__llvm_prf_vnodes
5252

53-
;; __llvm_prf_vnodes and __llvm_prf_nm are not referenced by other metadata sections.
54-
;; We have to conservatively place them in llvm.used.
55-
; STATIC: @llvm.used = appending global
56-
; STATIC-SAME: @__llvm_prf_vnodes
57-
; STATIC-SAME: @__llvm_prf_nm
58-
5953
; STATIC: call void @__llvm_profile_instrument_target(i64 %3, i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_foo to i8*), i32 0)
6054
; STATIC-EXT: call void @__llvm_profile_instrument_target(i64 %3, i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_foo to i8*), i32 zeroext 0)
6155
; STATIC-SEXT: call void @__llvm_profile_instrument_target(i64 %3, i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_foo to i8*), i32 signext 0)

0 commit comments

Comments
 (0)