llvm.org GIT mirror llvm / 4c946b7
Merging r344325: ------------------------------------------------------------------------ r344325 | evgeny777 | 2018-10-12 00:24:02 -0700 (Fri, 12 Oct 2018) | 4 lines [ThinLTO] Don't import GV which contains blockaddress Differential revision: https://reviews.llvm.org/D53139 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_70@345401 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 2 years ago
4 changed file(s) with 47 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
7373 // Walk through the operands of a given User via worklist iteration and populate
7474 // the set of GlobalValue references encountered. Invoked either on an
7575 // Instruction or a GlobalVariable (which walks its initializer).
76 static void findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
76 // Return true if any of the operands contains blockaddress. This is important
77 // to know when computing summary for global var, because if global variable
78 // references basic block address we can't import it separately from function
79 // containing that basic block. For simplicity we currently don't import such
80 // global vars at all. When importing function we aren't interested if any
81 // instruction in it takes an address of any basic block, because instruction
82 // can only take an address of basic block located in the same function.
83 static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
7784 SetVector &RefEdges,
7885 SmallPtrSet &Visited) {
86 bool HasBlockAddress = false;
7987 SmallVector Worklist;
8088 Worklist.push_back(CurUser);
8189
9199 const User *Operand = dyn_cast(OI);
92100 if (!Operand)
93101 continue;
94 if (isa(Operand))
102 if (isa(Operand)) {
103 HasBlockAddress = true;
95104 continue;
105 }
96106 if (auto *GV = dyn_cast(Operand)) {
97107 // We have a reference to a global value. This should be added to
98108 // the reference set unless it is a callee. Callees are handled
104114 Worklist.push_back(Operand);
105115 }
106116 }
117 return HasBlockAddress;
107118 }
108119
109120 static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount,
368379 DenseSet &CantBePromoted) {
369380 SetVector RefEdges;
370381 SmallPtrSet Visited;
371 findRefEdges(Index, &V, RefEdges, Visited);
382 bool HasBlockAddress = findRefEdges(Index, &V, RefEdges, Visited);
372383 bool NonRenamableLocal = isNonRenamableLocal(V);
373384 GlobalValueSummary::GVFlags Flags(V.getLinkage(), NonRenamableLocal,
374385 /* Live = */ false, V.isDSOLocal());
376387 llvm::make_unique(Flags, RefEdges.takeVector());
377388 if (NonRenamableLocal)
378389 CantBePromoted.insert(V.getGUID());
390 if (HasBlockAddress)
391 GVarSummary->setNotEligibleToImport();
379392 Index.addGlobalValueSummary(V, std::move(GVarSummary));
380393 }
381394
257257
258258 for (auto &RefSummary : VI.getSummaryList())
259259 if (RefSummary->getSummaryKind() == GlobalValueSummary::GlobalVarKind &&
260 // Don't try to import regular LTO summaries added to dummy module.
261 !RefSummary->modulePath().empty() &&
260 !RefSummary->notEligibleToImport() &&
262261 !GlobalValue::isInterposableLinkage(RefSummary->linkage()) &&
263262 RefSummary->refs().empty()) {
264263 ImportList[RefSummary->modulePath()].insert(VI.getGUID());
0 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
1 target triple = "x86_64-unknown-linux-gnu"
2
3 @label_addr = internal constant [1 x i8*] [i8* blockaddress(@foo, %lb)], align 8
4
5 ; Function Attrs: noinline norecurse nounwind optnone uwtable
6 define dso_local [1 x i8*]* @foo() {
7 br label %lb
8
9 lb:
10 ret [1 x i8*]* @label_addr
11 }
0 ; RUN: opt -module-summary %s -o %t1.bc
1 ; RUN: opt -module-summary %p/Inputs/globals-import-blockaddr.ll -o %t2.bc
2 ; 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
3 ; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s
4
5 ; Verify that we haven't imported GV containing blockaddress
6 ; CHECK: @label_addr.llvm.0 = external hidden constant
7
8 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
9 target triple = "x86_64-unknown-linux-gnu"
10
11 declare dso_local [1 x i8*]* @foo();
12
13 define dso_local i32 @main() {
14 %p = call [1 x i8*]* @foo()
15 %v = ptrtoint [1 x i8*]* %p to i32
16 ret i32 %v
17 }