Skip to content

Commit f9dd202

Browse files
teresajohnsongithub-actions[bot]
authored andcommitted
Automerge: [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.
2 parents 5d62294 + eb74d8e commit f9dd202

File tree

6 files changed

+55
-22
lines changed

6 files changed

+55
-22
lines changed

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,9 @@ class ModuleSummaryIndex {
14491449
/// every summary of a GV is synchronized.
14501450
bool WithDSOLocalPropagation = false;
14511451

1452+
/// Indicates that summary-based internalization and promotion has run.
1453+
bool WithInternalizeAndPromote = false;
1454+
14521455
/// Indicates that we have whole program visibility.
14531456
bool WithWholeProgramVisibility = false;
14541457

@@ -1653,6 +1656,9 @@ class ModuleSummaryIndex {
16531656
bool withDSOLocalPropagation() const { return WithDSOLocalPropagation; }
16541657
void setWithDSOLocalPropagation() { WithDSOLocalPropagation = true; }
16551658

1659+
bool withInternalizeAndPromote() const { return WithInternalizeAndPromote; }
1660+
void setWithInternalizeAndPromote() { WithInternalizeAndPromote = true; }
1661+
16561662
bool withWholeProgramVisibility() const { return WithWholeProgramVisibility; }
16571663
void setWithWholeProgramVisibility() { WithWholeProgramVisibility = true; }
16581664

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8603,7 +8603,7 @@ getEnableSplitLTOUnitAndUnifiedFlag(BitstreamCursor &Stream,
86038603
case bitc::FS_FLAGS: { // [flags]
86048604
uint64_t Flags = Record[0];
86058605
// Scan flags.
8606-
assert(Flags <= 0x2ff && "Unexpected bits in flag");
8606+
assert(Flags <= 0x7ff && "Unexpected bits in flag");
86078607

86088608
bool EnableSplitLTOUnit = Flags & 0x8;
86098609
bool UnifiedLTO = Flags & 0x200;

llvm/lib/IR/ModuleSummaryIndex.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ uint64_t ModuleSummaryIndex::getFlags() const {
111111
Flags |= 0x100;
112112
if (hasUnifiedLTO())
113113
Flags |= 0x200;
114+
if (withInternalizeAndPromote())
115+
Flags |= 0x400;
114116
return Flags;
115117
}
116118

117119
void ModuleSummaryIndex::setFlags(uint64_t Flags) {
118-
assert(Flags <= 0x2ff && "Unexpected bits in flag");
120+
assert(Flags <= 0x7ff && "Unexpected bits in flag");
119121
// 1 bit: WithGlobalValueDeadStripping flag.
120122
// Set on combined index only.
121123
if (Flags & 0x1)
@@ -154,6 +156,10 @@ void ModuleSummaryIndex::setFlags(uint64_t Flags) {
154156
// Set on combined index only.
155157
if (Flags & 0x200)
156158
setUnifiedLTO();
159+
// 1 bit: WithInternalizeAndPromote flag.
160+
// Set on combined index only.
161+
if (Flags & 0x400)
162+
setWithInternalizeAndPromote();
157163
}
158164

159165
// Collect for the given module the list of function it defines

llvm/lib/LTO/LTO.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,11 @@ void llvm::thinLTOInternalizeAndPromoteInIndex(
551551
function_ref<bool(StringRef, ValueInfo)> isExported,
552552
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
553553
isPrevailing) {
554+
assert(!Index.withInternalizeAndPromote());
554555
for (auto &I : Index)
555556
thinLTOInternalizeAndPromoteGUID(Index.getValueInfo(I), isExported,
556557
isPrevailing);
558+
Index.setWithInternalizeAndPromote();
557559
}
558560

559561
// Requires a destructor for std::vector<InputModule>.

llvm/test/Bitcode/thinlto-deadstrip-flag.ll

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; REQUIRES: x86-registered-target
2+
; RUN: opt -module-summary %s -o %t.o
3+
4+
;; By default, the indexing step should perform and set the appropriate index
5+
;; flags for dead stripping, attribute propagation, DSO local propagation,
6+
;; and internalization/promotion.
7+
; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \
8+
; RUN: -r %t.o,glob,plx
9+
; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=ALL
10+
;; The flag value should be 0x461 aka 1121:
11+
;; 0x1: Dead stripping
12+
;; 0x20: Attribute propagation
13+
;; 0x40: DSO local propagation
14+
;; 0x400: Internalization/promotion
15+
; ALL: <FLAGS op0=1121/>
16+
17+
;; Ensure dead stripping performed flag is not set on distributed index
18+
;; when option used to disable dead stripping computation.
19+
; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \
20+
; RUN: -r %t.o,glob,plx -compute-dead=false
21+
; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=NODEAD
22+
;; Flag should be 0x460 aka 1120.
23+
; NODEAD: <FLAGS op0=1120/>
24+
25+
;; Disabling attribute propagation should disable that as well as DSO local
26+
;; propagation.
27+
; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \
28+
; RUN: -r %t.o,glob,plx -propagate-attrs=false
29+
; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=NOPROP
30+
;; Flag should be 0x401 aka 1025.
31+
; NOPROP: <FLAGS op0=1025/>
32+
33+
;; Note there isn't currently a way to disable internalization+promotion, which
34+
;; are performed together.
35+
36+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
37+
target triple = "x86_64-unknown-linux-gnu"
38+
39+
@glob = global i32 0

0 commit comments

Comments
 (0)