@@ -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
110121static 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
0 commit comments