Skip to content

Commit f368101

Browse files
committedFeb 7, 2018
[ThinLTO] Serialize WithGlobalValueDeadStripping index flag for distributed backends
Summary: A recent fix to drop dead symbols (r323633) did not work for ThinLTO distributed backends because we lose the WithGlobalValueDeadStripping set on the index during the thin link. This patch adds a new flags record to the bitcode format for the index, and serializes this flag for the combined index (it would always be 0 for the per-module index generated by the compile step, so no need to serialize the new flags record there until/unless we add another flag that applies to the per-module indexes). Generally this flag should always be set for the distributed backends, which are necessarily performed after the thin link. However, if we were to simply set this flag on the index applied to the distributed backends (invoked via clang), we would lose the ability to disable dead stripping via -compute-dead=false for debugging purposes. Reviewers: grimar, pcc Subscribers: mehdi_amini, inglorion, eraman, llvm-commits Differential Revision: https://reviews.llvm.org/D42799 llvm-svn: 324444
1 parent 37a4a8a commit f368101

13 files changed

+48
-0
lines changed
 

‎llvm/include/llvm/Bitcode/LLVMBitCodes.h

+2
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ enum GlobalValueSummarySymtabCodes {
261261
// numrefs x valueid,
262262
// n x (valueid, relblockfreq)]
263263
FS_PERMODULE_RELBF = 19,
264+
// Index-wide flags
265+
FS_FLAGS = 20,
264266
};
265267

266268
enum MetadataCodes {

‎llvm/lib/Bitcode/Reader/BitcodeReader.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -5133,6 +5133,16 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
51335133
switch (BitCode) {
51345134
default: // Default behavior: ignore.
51355135
break;
5136+
case bitc::FS_FLAGS: { // [flags]
5137+
uint64_t Flags = Record[0];
5138+
// Scan flags (set only on the combined index).
5139+
assert(Flags <= 1 && "Unexpected bits in flag");
5140+
5141+
// 1 bit: WithGlobalValueDeadStripping flag.
5142+
if (Flags & 0x1)
5143+
TheIndex.setWithGlobalValueDeadStripping();
5144+
break;
5145+
}
51365146
case bitc::FS_VALUE_GUID: { // [valueid, refguid]
51375147
uint64_t ValueID = Record[0];
51385148
GlobalValue::GUID RefGUID = Record[1];

‎llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3552,6 +3552,11 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
35523552
Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 3);
35533553
Stream.EmitRecord(bitc::FS_VERSION, ArrayRef<uint64_t>{INDEX_VERSION});
35543554

3555+
// Write the index flags. Currently we only write a single flag, the value of
3556+
// withGlobalValueDeadStripping, which only applies to the combined index.
3557+
Stream.EmitRecord(bitc::FS_FLAGS,
3558+
ArrayRef<uint64_t>{Index.withGlobalValueDeadStripping()});
3559+
35553560
for (const auto &GVI : valueIds()) {
35563561
Stream.EmitRecord(bitc::FS_VALUE_GUID,
35573562
ArrayRef<uint64_t>{GVI.second, GVI.first});

‎llvm/test/Bitcode/thinlto-alias.ll

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
; COMBINED: <GLOBALVAL_SUMMARY_BLOCK
2424
; COMBINED-NEXT: <VERSION
25+
; COMBINED-NEXT: <FLAGS
2526
; See if the call to analias is registered, using the expected value id.
2627
; COMBINED-NEXT: <VALUE_GUID op0=[[ALIASID:[0-9]+]] op1=-5751648690987223394/>
2728
; COMBINED-NEXT: <VALUE_GUID
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; REQUIRES: x86-registered-target
2+
; RUN: opt -module-summary %s -o %t.o
3+
4+
; Ensure dead stripping performed flag is set on distributed index
5+
; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \
6+
; RUN: -r %t.o,glob,plx
7+
; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=WITHDEAD
8+
; WITHDEAD: <FLAGS op0=1/>
9+
10+
; Ensure dead stripping performed flag is not set on distributed index
11+
; when option used to disable dead stripping computation.
12+
; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \
13+
; RUN: -r %t.o,glob,plx -compute-dead=false
14+
; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=NODEAD
15+
; NODEAD: <FLAGS op0=0/>
16+
17+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
18+
target triple = "x86_64-unknown-linux-gnu"
19+
20+
@glob = global i32 0

‎llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
; COMBINED: <GLOBALVAL_SUMMARY_BLOCK
2626
; COMBINED-NEXT: <VERSION
27+
; COMBINED-NEXT: <FLAGS
2728
; COMBINED-NEXT: <VALUE_GUID op0=[[FUNCID:[0-9]+]] op1=7289175272376759421/>
2829
; COMBINED-NEXT: <VALUE_GUID
2930
; COMBINED-NEXT: <COMBINED

‎llvm/test/Bitcode/thinlto-function-summary-callgraph-profile-summary.ll

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
; COMBINED: <GLOBALVAL_SUMMARY_BLOCK
3939
; COMBINED-NEXT: <VERSION
40+
; COMBINED-NEXT: <FLAGS
4041
; COMBINED-NEXT: <VALUE_GUID
4142
; COMBINED-NEXT: <VALUE_GUID
4243
; COMBINED-NEXT: <VALUE_GUID

‎llvm/test/Bitcode/thinlto-function-summary-callgraph-sample-profile-summary.ll

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
; COMBINED: <GLOBALVAL_SUMMARY_BLOCK
4141
; COMBINED-NEXT: <VERSION
42+
; COMBINED-NEXT: <FLAGS
4243
; COMBINED-NEXT: <VALUE_GUID
4344
; COMBINED-NEXT: <VALUE_GUID
4445
; COMBINED-NEXT: <VALUE_GUID

‎llvm/test/Bitcode/thinlto-function-summary-callgraph.ll

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
; COMBINED: <GLOBALVAL_SUMMARY_BLOCK
2828
; COMBINED-NEXT: <VERSION
29+
; COMBINED-NEXT: <FLAGS
2930
; Only 2 VALUE_GUID since reference to undefinedglob should not be included in
3031
; combined index.
3132
; COMBINED-NEXT: <VALUE_GUID op0=[[FUNCID:[0-9]+]] op1=7289175272376759421/>

‎llvm/test/Bitcode/thinlto-function-summary-originalnames.ll

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
; COMBINED: <GLOBALVAL_SUMMARY_BLOCK
77
; COMBINED-NEXT: <VERSION
8+
; COMBINED-NEXT: <FLAGS
89
; COMBINED-NEXT: <VALUE_GUID {{.*}} op1=4947176790635855146/>
910
; COMBINED-NEXT: <VALUE_GUID {{.*}} op1=-6591587165810580810/>
1011
; COMBINED-NEXT: <VALUE_GUID {{.*}} op1=-4377693495213223786/>

‎llvm/test/tools/gold/X86/thinlto.ll

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
9696
; BACKEND1-NEXT: <GLOBALVAL_SUMMARY_BLOCK
9797
; BACKEND1-NEXT: <VERSION
98+
; BACKEND1-NEXT: <FLAGS
9899
; BACKEND1-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
99100
; BACKEND1-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
100101
; BACKEND1-NEXT: <COMBINED
@@ -108,6 +109,7 @@
108109
; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
109110
; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
110111
; BACKEND2-NEXT: <VERSION
112+
; BACKEND2-NEXT: <FLAGS
111113
; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
112114
; BACKEND2-NEXT: <COMBINED
113115
; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
@@ -118,6 +120,7 @@
118120
; COMBINED-NEXT: </MODULE_STRTAB_BLOCK
119121
; COMBINED-NEXT: <GLOBALVAL_SUMMARY_BLOCK
120122
; COMBINED-NEXT: <VERSION
123+
; COMBINED-NEXT: <FLAGS
121124
; COMBINED-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
122125
; COMBINED-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
123126
; COMBINED-NEXT: <COMBINED

‎llvm/test/tools/llvm-lto/thinlto.ll

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
; COMBINED-NEXT: </MODULE_STRTAB_BLOCK
1212
; COMBINED-NEXT: <GLOBALVAL_SUMMARY_BLOCK
1313
; COMBINED-NEXT: <VERSION
14+
; COMBINED-NEXT: <FLAGS
1415
; COMBINED-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
1516
; COMBINED-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
1617
; COMBINED-NEXT: <COMBINED

‎llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
315315
STRINGIFY_CODE(FS, COMBINED_ALIAS)
316316
STRINGIFY_CODE(FS, COMBINED_ORIGINAL_NAME)
317317
STRINGIFY_CODE(FS, VERSION)
318+
STRINGIFY_CODE(FS, FLAGS)
318319
STRINGIFY_CODE(FS, TYPE_TESTS)
319320
STRINGIFY_CODE(FS, TYPE_TEST_ASSUME_VCALLS)
320321
STRINGIFY_CODE(FS, TYPE_CHECKED_LOAD_VCALLS)

0 commit comments

Comments
 (0)
Please sign in to comment.