Skip to content

Commit 54a3c2a

Browse files
committed
[ThinLTO] Add option to disable readonly/writeonly attribute propagation
Summary: Add an option to allow the attribute propagation on the index to be disabled, to allow a workaround for issues (such as that fixed by D70977). Also move the setting of the WithAttributePropagation flag on the index into propagateAttributes(), and remove some old stale code that predated this flag and cleared the maybe read/write only bits when we need to disable the propagation (previously only when importing disabled, now also when the new option disables it). Reviewers: evgeny777, steven_wu Subscribers: mehdi_amini, inglorion, hiraditya, dexonsmith, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70984
1 parent 2ec71ea commit 54a3c2a

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

llvm/lib/IR/ModuleSummaryIndex.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/ADT/SCCIterator.h"
1616
#include "llvm/ADT/Statistic.h"
1717
#include "llvm/ADT/StringMap.h"
18+
#include "llvm/Support/CommandLine.h"
1819
#include "llvm/Support/Path.h"
1920
#include "llvm/Support/raw_ostream.h"
2021
using namespace llvm;
@@ -26,6 +27,10 @@ STATISTIC(ReadOnlyLiveGVars,
2627
STATISTIC(WriteOnlyLiveGVars,
2728
"Number of live global variables marked write only");
2829

30+
static cl::opt<bool> PropagateAttrs("propagate-attrs", cl::init(true),
31+
cl::Hidden,
32+
cl::desc("Propagate attributes in index"));
33+
2934
FunctionSummary FunctionSummary::ExternalNode =
3035
FunctionSummary::makeDummyFunctionSummary({});
3136

@@ -157,6 +162,8 @@ static void propagateAttributesToRefs(GlobalValueSummary *S) {
157162
// See internalizeGVsAfterImport.
158163
void ModuleSummaryIndex::propagateAttributes(
159164
const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
165+
if (!PropagateAttrs)
166+
return;
160167
for (auto &P : *this)
161168
for (auto &S : P.second.SummaryList) {
162169
if (!isGlobalValueLive(S.get()))
@@ -183,6 +190,7 @@ void ModuleSummaryIndex::propagateAttributes(
183190
}
184191
propagateAttributesToRefs(S.get());
185192
}
193+
setWithAttributePropagation();
186194
if (llvm::AreStatisticsEnabled())
187195
for (auto &P : *this)
188196
if (P.second.SummaryList.size())

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -901,19 +901,8 @@ void llvm::computeDeadSymbolsWithConstProp(
901901
function_ref<PrevailingType(GlobalValue::GUID)> isPrevailing,
902902
bool ImportEnabled) {
903903
computeDeadSymbols(Index, GUIDPreservedSymbols, isPrevailing);
904-
if (ImportEnabled) {
904+
if (ImportEnabled)
905905
Index.propagateAttributes(GUIDPreservedSymbols);
906-
} else {
907-
// If import is disabled we should drop read/write-only attribute
908-
// from all summaries to prevent internalization.
909-
for (auto &P : Index)
910-
for (auto &S : P.second.SummaryList)
911-
if (auto *GVS = dyn_cast<GlobalVarSummary>(S.get())) {
912-
GVS->setReadOnly(false);
913-
GVS->setWriteOnly(false);
914-
}
915-
}
916-
Index.setWithAttributePropagation();
917906
}
918907

919908
/// Compute the set of summaries needed for a ThinLTO backend compilation of

llvm/test/ThinLTO/X86/writeonly.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
; OPTIMIZE-NEXT: %2 = tail call i32 @rand()
2626
; OPTIMIZE-NEXT: ret i32 0
2727

28+
; Confirm that with -propagate-attrs=false we no longer do write-only importing
29+
; RUN: llvm-lto -propagate-attrs=false -thinlto-action=import -exported-symbol=main %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported.bc -stats 2>&1 | FileCheck %s --check-prefix=STATS-NOPROP
30+
; RUN: llvm-dis %t1.imported.bc -o - | FileCheck %s --check-prefix=IMPORT-NOPROP
31+
; STATS-NOPROP-NOT: Number of live global variables marked write only
32+
; IMPORT-NOPROP: @gFoo.llvm.0 = available_externally
33+
; IMPORT-NOPROP-NEXT: @gBar = available_externally
34+
2835
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
2936
target triple = "x86_64-pc-linux-gnu"
3037

0 commit comments

Comments
 (0)