Index: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h =================================================================== --- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h +++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h @@ -261,6 +261,8 @@ // numrefs x valueid, // n x (valueid, relblockfreq)] FS_PERMODULE_RELBF = 19, + // Index-wide flags + FS_FLAGS = 20, }; enum MetadataCodes { Index: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp @@ -5133,6 +5133,16 @@ switch (BitCode) { default: // Default behavior: ignore. break; + case bitc::FS_FLAGS: { // [flags] + uint64_t Flags = Record[0]; + // Scan flags (set only on the combined index). + assert(Flags <= 1 && "Unexpected bits in flag"); + + // 1 bit: WithGlobalValueDeadStripping flag. + if (Flags & 0x1) + TheIndex.setWithGlobalValueDeadStripping(); + break; + } case bitc::FS_VALUE_GUID: { // [valueid, refguid] uint64_t ValueID = Record[0]; GlobalValue::GUID RefGUID = Record[1]; Index: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3552,6 +3552,11 @@ Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 3); Stream.EmitRecord(bitc::FS_VERSION, ArrayRef{INDEX_VERSION}); + // Write the index flags. Currently we only write a single flag, the value of + // withGlobalValueDeadStripping, which only applies to the combined index. + Stream.EmitRecord(bitc::FS_FLAGS, + ArrayRef{Index.withGlobalValueDeadStripping()}); + for (const auto &GVI : valueIds()) { Stream.EmitRecord(bitc::FS_VALUE_GUID, ArrayRef{GVI.second, GVI.first}); Index: llvm/trunk/test/Bitcode/thinlto-alias.ll =================================================================== --- llvm/trunk/test/Bitcode/thinlto-alias.ll +++ llvm/trunk/test/Bitcode/thinlto-alias.ll @@ -22,6 +22,7 @@ ; COMBINED: ; COMBINED-NEXT: + +; Ensure dead stripping performed flag is not set on distributed index +; when option used to disable dead stripping computation. +; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \ +; RUN: -r %t.o,glob,plx -compute-dead=false +; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=NODEAD +; NODEAD: + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@glob = global i32 0 Index: llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll =================================================================== --- llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll +++ llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll @@ -24,6 +24,7 @@ ; COMBINED: ; COMBINED-NEXT: Index: llvm/trunk/test/Bitcode/thinlto-function-summary-originalnames.ll =================================================================== --- llvm/trunk/test/Bitcode/thinlto-function-summary-originalnames.ll +++ llvm/trunk/test/Bitcode/thinlto-function-summary-originalnames.ll @@ -5,6 +5,7 @@ ; COMBINED: ; COMBINED-NEXT: ; COMBINED-NEXT: Index: llvm/trunk/test/tools/gold/X86/thinlto.ll =================================================================== --- llvm/trunk/test/tools/gold/X86/thinlto.ll +++ llvm/trunk/test/tools/gold/X86/thinlto.ll @@ -95,6 +95,7 @@ ; BACKEND1-NEXT: