• Home
  • Raw
  • Download

Lines Matching full:globals

1 //===-- GlobalMerge.cpp - Internal globals merging  -----------------------===//
9 // This pass merges globals with internal linkage into one. This way all the
10 // globals which were merged into a biggest one can be addressed using offsets
13 // when many globals are involved.
53 // However, merging globals can have tradeoffs:
105 cl::desc("Improve global merge pass to ignore globals only used alone"),
119 STATISTIC(NumMerged, "Number of globals merged");
130 /// Currently, this applies a dead simple heuristic: only consider globals
140 bool doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
142 /// \brief Merge everything in \p Globals for which the corresponding bit
144 bool doMerge(const SmallVectorImpl<GlobalVariable *> &Globals,
186 return "Merge internal globals"; in getPassName()
202 bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals, in doMerge() argument
206 std::stable_sort(Globals.begin(), Globals.end(), in doMerge()
212 // If we want to just blindly group all globals together, do so. in doMerge()
214 BitVector AllGlobals(Globals.size()); in doMerge()
216 return doMerge(Globals, AllGlobals, M, isConst, AddrSpace); in doMerge()
220 // discover all sets of globals used together, and how many times each of in doMerge()
225 // code (currently, a Function) to the set of globals seen so far that are in doMerge()
231 // combination of the previous N-1 globals. in doMerge()
237 // We keep track of the sets of globals used together "close enough". in doMerge()
239 UsedGlobalSet(size_t Size) : Globals(Size), UsageCount(1) {} in doMerge()
240 BitVector Globals; in doMerge() member
249 UsedGlobalSets.emplace_back(Globals.size()); in doMerge()
277 for (size_t GI = 0, GE = Globals.size(); GI != GE; ++GI) { in doMerge()
278 GlobalVariable *GV = Globals[GI]; in doMerge()
327 CreateGlobalSet().Globals.set(GI); in doMerge()
337 if (UsedGlobalSets[UGSIdx].Globals.test(GI)) { in doMerge()
359 NewUGS.Globals.set(GI); in doMerge()
360 NewUGS.Globals |= UsedGlobalSets[UGSIdx].Globals; in doMerge()
365 // Now we found a bunch of sets of globals used together. We accumulated in doMerge()
367 // that use that exact set of globals). in doMerge()
373 return UGS1.Globals.count() * UGS1.UsageCount < in doMerge()
374 UGS2.Globals.count() * UGS2.UsageCount; in doMerge()
377 // We can choose to merge all globals together, but ignore globals never used in doMerge()
381 BitVector AllGlobals(Globals.size()); in doMerge()
386 if (UGS.Globals.count() > 1) in doMerge()
387 AllGlobals |= UGS.Globals; in doMerge()
389 return doMerge(Globals, AllGlobals, M, isConst, AddrSpace); in doMerge()
398 BitVector PickedGlobals(Globals.size()); in doMerge()
405 if (PickedGlobals.anyCommon(UGS.Globals)) in doMerge()
407 PickedGlobals |= UGS.Globals; in doMerge()
411 if (UGS.Globals.count() < 2) in doMerge()
413 Changed |= doMerge(Globals, UGS.Globals, M, isConst, AddrSpace); in doMerge()
419 bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, in doMerge() argument
422 assert(Globals.size() > 1); in doMerge()
438 Type *Ty = Globals[j]->getValueType(); in doMerge()
444 Inits.push_back(Globals[j]->getInitializer()); in doMerge()
455 GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage(); in doMerge()
456 std::string Name = Globals[k]->getName(); in doMerge()
464 Globals[k]->replaceAllUsesWith(GEP); in doMerge()
465 Globals[k]->eraseFromParent(); in doMerge()
510 // Look for globals in the clauses of the landing pad instruction in setMustKeepGlobalVariables()
528 DenseMap<unsigned, SmallVector<GlobalVariable*, 16> > Globals, ConstGlobals, in doInitialization() local
533 // Grab all non-const globals. in doInitialization()
534 for (auto &GV : M.globals()) { in doInitialization()
535 // Merge is safe for "normal" internal or external globals only in doInitialization()
548 // Ignore fancy-aligned globals for now. in doInitialization()
554 // Ignore all 'special' globals. in doInitialization()
559 // Ignore all "required" globals: in doInitialization()
570 Globals[AddressSpace].push_back(&GV); in doInitialization()
574 for (auto &P : Globals) in doInitialization()