Skip to content

Commit 07c635b

Browse files
committed
Merge branch 'release_70' of github.com:llvm-mirror/llvm into release_70
2 parents 796ae24 + 4c946b7 commit 07c635b

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

lib/Analysis/ModuleSummaryAnalysis.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,17 @@ cl::opt<FunctionSummary::ForceSummaryHotnessType, true> FSEC(
7474
// Walk through the operands of a given User via worklist iteration and populate
7575
// the set of GlobalValue references encountered. Invoked either on an
7676
// Instruction or a GlobalVariable (which walks its initializer).
77-
static void findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
77+
// Return true if any of the operands contains blockaddress. This is important
78+
// to know when computing summary for global var, because if global variable
79+
// references basic block address we can't import it separately from function
80+
// containing that basic block. For simplicity we currently don't import such
81+
// global vars at all. When importing function we aren't interested if any
82+
// instruction in it takes an address of any basic block, because instruction
83+
// can only take an address of basic block located in the same function.
84+
static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
7885
SetVector<ValueInfo> &RefEdges,
7986
SmallPtrSet<const User *, 8> &Visited) {
87+
bool HasBlockAddress = false;
8088
SmallVector<const User *, 32> Worklist;
8189
Worklist.push_back(CurUser);
8290

@@ -92,8 +100,10 @@ static void findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
92100
const User *Operand = dyn_cast<User>(OI);
93101
if (!Operand)
94102
continue;
95-
if (isa<BlockAddress>(Operand))
103+
if (isa<BlockAddress>(Operand)) {
104+
HasBlockAddress = true;
96105
continue;
106+
}
97107
if (auto *GV = dyn_cast<GlobalValue>(Operand)) {
98108
// We have a reference to a global value. This should be added to
99109
// the reference set unless it is a callee. Callees are handled
@@ -105,6 +115,7 @@ static void findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
105115
Worklist.push_back(Operand);
106116
}
107117
}
118+
return HasBlockAddress;
108119
}
109120

110121
static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount,
@@ -369,14 +380,16 @@ computeVariableSummary(ModuleSummaryIndex &Index, const GlobalVariable &V,
369380
DenseSet<GlobalValue::GUID> &CantBePromoted) {
370381
SetVector<ValueInfo> RefEdges;
371382
SmallPtrSet<const User *, 8> Visited;
372-
findRefEdges(Index, &V, RefEdges, Visited);
383+
bool HasBlockAddress = findRefEdges(Index, &V, RefEdges, Visited);
373384
bool NonRenamableLocal = isNonRenamableLocal(V);
374385
GlobalValueSummary::GVFlags Flags(V.getLinkage(), NonRenamableLocal,
375386
/* Live = */ false, V.isDSOLocal());
376387
auto GVarSummary =
377388
llvm::make_unique<GlobalVarSummary>(Flags, RefEdges.takeVector());
378389
if (NonRenamableLocal)
379390
CantBePromoted.insert(V.getGUID());
391+
if (HasBlockAddress)
392+
GVarSummary->setNotEligibleToImport();
380393
Index.addGlobalValueSummary(V, std::move(GVarSummary));
381394
}
382395

lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ static void computeImportForReferencedGlobals(
258258

259259
for (auto &RefSummary : VI.getSummaryList())
260260
if (RefSummary->getSummaryKind() == GlobalValueSummary::GlobalVarKind &&
261-
// Don't try to import regular LTO summaries added to dummy module.
262-
!RefSummary->modulePath().empty() &&
261+
!RefSummary->notEligibleToImport() &&
263262
!GlobalValue::isInterposableLinkage(RefSummary->linkage()) &&
264263
RefSummary->refs().empty()) {
265264
ImportList[RefSummary->modulePath()].insert(VI.getGUID());
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
2+
target triple = "x86_64-unknown-linux-gnu"
3+
4+
@label_addr = internal constant [1 x i8*] [i8* blockaddress(@foo, %lb)], align 8
5+
6+
; Function Attrs: noinline norecurse nounwind optnone uwtable
7+
define dso_local [1 x i8*]* @foo() {
8+
br label %lb
9+
10+
lb:
11+
ret [1 x i8*]* @label_addr
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: opt -module-summary %s -o %t1.bc
2+
; RUN: opt -module-summary %p/Inputs/globals-import-blockaddr.ll -o %t2.bc
3+
; RUN: llvm-lto2 run -save-temps %t1.bc -r=%t1.bc,foo,l -r=%t1.bc,main,pl %t2.bc -r=%t2.bc,foo,pl -o %t3
4+
; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s
5+
6+
; Verify that we haven't imported GV containing blockaddress
7+
; CHECK: @label_addr.llvm.0 = external hidden constant
8+
9+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
10+
target triple = "x86_64-unknown-linux-gnu"
11+
12+
declare dso_local [1 x i8*]* @foo();
13+
14+
define dso_local i32 @main() {
15+
%p = call [1 x i8*]* @foo()
16+
%v = ptrtoint [1 x i8*]* %p to i32
17+
ret i32 %v
18+
}

0 commit comments

Comments
 (0)