Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit dca651f

Browse files
committed
Re-apply "[profiling] Remove dead profile name vars after emitting name data"
This reverts 295092 (re-applies 295084), with a fix for dangling references from the array of coverage names passed down from frontends. I missed this in my initial testing because I only checked test/Profile, and not test/CoverageMapping as well. Original commit message: The profile name variables passed to counter increment intrinsics are dead after we emit the finalized name data in __llvm_prf_nm. However, we neglect to erase these name variables. This causes huge size increases in the __TEXT,__const section as well as slowdowns when linker dead stripping is disabled. Some affected projects are so massive that they fail to link on Darwin, because only the small code model is supported. Fix the issue by throwing away the name constants as soon as we're done with them. Differential Revision: https://reviews.llvm.org/D29921 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295099 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 71648d0 commit dca651f

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ void InstrProfiling::lowerCoverageData(GlobalVariable *CoverageNamesVar) {
295295

296296
Name->setLinkage(GlobalValue::PrivateLinkage);
297297
ReferencedNames.push_back(Name);
298+
NC->dropAllReferences();
298299
}
300+
CoverageNamesVar->eraseFromParent();
299301
}
300302

301303
/// Get the name of a profiling variable for a particular function.
@@ -532,6 +534,9 @@ void InstrProfiling::emitNameData() {
532534
NamesSize = CompressedNameStr.size();
533535
NamesVar->setSection(getNameSection());
534536
UsedVars.push_back(NamesVar);
537+
538+
for (auto *NamePtr : ReferencedNames)
539+
NamePtr->eraseFromParent();
535540
}
536541

537542
void InstrProfiling::emitRegistration() {

test/Instrumentation/InstrProfiling/PR23499.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ $_Z3barIvEvv = comdat any
1313

1414
@__profn__Z3barIvEvv = linkonce_odr hidden constant [11 x i8] c"_Z3barIvEvv", align 1
1515

16-
; CHECK: @__profn__Z3barIvEvv = private constant [11 x i8] c"_Z3barIvEvv", align 1
16+
; CHECK-NOT: __profn__Z3barIvEvv
1717
; CHECK: @__profc__Z3barIvEvv = linkonce_odr hidden global [1 x i64] zeroinitializer, section "{{.*}}__llvm_prf_cnts", comdat($__profv__Z3barIvEvv), align 8
1818
; 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
1919
; CHECK: @__llvm_prf_nm = private constant [{{.*}} x i8] c"{{.*}}", section "{{.*}}__llvm_prf_names"
2020

2121

22-
; COFF: @__profn__Z3barIvEvv = private constant [11 x i8] c"_Z3barIvEvv", align 1
22+
; COFF-NOT: __profn__Z3barIvEvv
2323
; COFF: @__profc__Z3barIvEvv = linkonce_odr hidden global [1 x i64] zeroinitializer, section "{{.*}}__llvm_prf_cnts", comdat, align 8
2424
; 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
2525

test/Instrumentation/InstrProfiling/platform.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
; RUN: opt < %s -mtriple=x86_64-pc-solaris -passes=instrprof -S | FileCheck %s -check-prefix=SOLARIS
1313

1414
@__profn_foo = hidden constant [3 x i8] c"foo"
15-
; MACHO: @__profn_foo = private constant [3 x i8] c"foo"
16-
; ELF: @__profn_foo = private constant [3 x i8] c"foo"
15+
; MACHO-NOT: __profn_foo
16+
; ELF-NOT: __profn_foo
1717

1818
; MACHO: @__profc_foo = hidden global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8
1919
; ELF: @__profc_foo = hidden global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8

test/Instrumentation/InstrProfiling/profiling.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
target triple = "x86_64-apple-macosx10.10.0"
55

66
@__profn_foo = hidden constant [3 x i8] c"foo"
7-
; CHECK: @__profn_foo = private constant [3 x i8] c"foo"
7+
; CHECK-NOT: __profn_foo
88
@__profn_bar = hidden constant [4 x i8] c"bar\00"
9-
; CHECK: @__profn_bar = private constant [4 x i8] c"bar\00"
9+
; CHECK-NOT: __profn_bar
1010
@__profn_baz = hidden constant [3 x i8] c"baz"
11-
; CHECK: @__profn_baz = private constant [3 x i8] c"baz"
11+
; CHECK-NOT: __profn_baz
1212

1313
; CHECK: @__profc_foo = hidden global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8
1414
; CHECK: @__profd_foo = hidden {{.*}}, section "__DATA,__llvm_prf_data,regular,live_support", align 8

test/Transforms/PGOProfile/comdat_internal.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $foo = comdat any
1212
@bar = global i32 ()* @foo, align 8
1313

1414
; CHECK: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
15-
; CHECK: @__profn__stdin__foo = private constant [11 x i8] c"<stdin>:foo"
15+
; CHECK-NOT: __profn__stdin__foo
1616
; CHECK: @__profc__stdin__foo.[[FOO_HASH]] = private global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", comdat($__profv__stdin__foo.[[FOO_HASH]]), align 8
1717
; CHECK: @__profd__stdin__foo.[[FOO_HASH]] = private global { i64, i64, i64*, i8*, i8*, i32, [1 x i16] } { i64 -5640069336071256030, i64 [[FOO_HASH]], i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc__stdin__foo.[[FOO_HASH]], i32 0, i32 0), i8* null
1818
; CHECK-NOT: bitcast (i32 ()* @foo to i8*)

0 commit comments

Comments
 (0)