[ThinLTO] Add index flag for internalization/promotion status (#164530)

Add an index-wide flag indicating whether index-based internalization
and promotion have completed. This will be used in a follow on change.
This commit is contained in:
Teresa Johnson 2025-10-22 07:30:43 -07:00 committed by GitHub
parent 7ae7a5ad51
commit eb74d8e03c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 55 additions and 22 deletions

View File

@ -1449,6 +1449,9 @@ private:
/// every summary of a GV is synchronized.
bool WithDSOLocalPropagation = false;
/// Indicates that summary-based internalization and promotion has run.
bool WithInternalizeAndPromote = false;
/// Indicates that we have whole program visibility.
bool WithWholeProgramVisibility = false;
@ -1653,6 +1656,9 @@ public:
bool withDSOLocalPropagation() const { return WithDSOLocalPropagation; }
void setWithDSOLocalPropagation() { WithDSOLocalPropagation = true; }
bool withInternalizeAndPromote() const { return WithInternalizeAndPromote; }
void setWithInternalizeAndPromote() { WithInternalizeAndPromote = true; }
bool withWholeProgramVisibility() const { return WithWholeProgramVisibility; }
void setWithWholeProgramVisibility() { WithWholeProgramVisibility = true; }

View File

@ -8603,7 +8603,7 @@ getEnableSplitLTOUnitAndUnifiedFlag(BitstreamCursor &Stream,
case bitc::FS_FLAGS: { // [flags]
uint64_t Flags = Record[0];
// Scan flags.
assert(Flags <= 0x2ff && "Unexpected bits in flag");
assert(Flags <= 0x7ff && "Unexpected bits in flag");
bool EnableSplitLTOUnit = Flags & 0x8;
bool UnifiedLTO = Flags & 0x200;

View File

@ -111,11 +111,13 @@ uint64_t ModuleSummaryIndex::getFlags() const {
Flags |= 0x100;
if (hasUnifiedLTO())
Flags |= 0x200;
if (withInternalizeAndPromote())
Flags |= 0x400;
return Flags;
}
void ModuleSummaryIndex::setFlags(uint64_t Flags) {
assert(Flags <= 0x2ff && "Unexpected bits in flag");
assert(Flags <= 0x7ff && "Unexpected bits in flag");
// 1 bit: WithGlobalValueDeadStripping flag.
// Set on combined index only.
if (Flags & 0x1)
@ -154,6 +156,10 @@ void ModuleSummaryIndex::setFlags(uint64_t Flags) {
// Set on combined index only.
if (Flags & 0x200)
setUnifiedLTO();
// 1 bit: WithInternalizeAndPromote flag.
// Set on combined index only.
if (Flags & 0x400)
setWithInternalizeAndPromote();
}
// Collect for the given module the list of function it defines

View File

@ -551,9 +551,11 @@ void llvm::thinLTOInternalizeAndPromoteInIndex(
function_ref<bool(StringRef, ValueInfo)> isExported,
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
isPrevailing) {
assert(!Index.withInternalizeAndPromote());
for (auto &I : Index)
thinLTOInternalizeAndPromoteGUID(Index.getValueInfo(I), isExported,
isPrevailing);
Index.setWithInternalizeAndPromote();
}
// Requires a destructor for std::vector<InputModule>.

View File

@ -1,20 +0,0 @@
; REQUIRES: x86-registered-target
; RUN: opt -module-summary %s -o %t.o
; Ensure dead stripping performed flag is set on distributed index
; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \
; RUN: -r %t.o,glob,plx
; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=WITHDEAD
; WITHDEAD: <FLAGS op0=97/>
; 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: <FLAGS op0=96/>
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

View File

@ -0,0 +1,39 @@
; REQUIRES: x86-registered-target
; RUN: opt -module-summary %s -o %t.o
;; By default, the indexing step should perform and set the appropriate index
;; flags for dead stripping, attribute propagation, DSO local propagation,
;; and internalization/promotion.
; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \
; RUN: -r %t.o,glob,plx
; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=ALL
;; The flag value should be 0x461 aka 1121:
;; 0x1: Dead stripping
;; 0x20: Attribute propagation
;; 0x40: DSO local propagation
;; 0x400: Internalization/promotion
; ALL: <FLAGS op0=1121/>
;; 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
;; Flag should be 0x460 aka 1120.
; NODEAD: <FLAGS op0=1120/>
;; Disabling attribute propagation should disable that as well as DSO local
;; propagation.
; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \
; RUN: -r %t.o,glob,plx -propagate-attrs=false
; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=NOPROP
;; Flag should be 0x401 aka 1025.
; NOPROP: <FLAGS op0=1025/>
;; Note there isn't currently a way to disable internalization+promotion, which
;; are performed together.
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