Home | History | Annotate | Download | only in CodeGen

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:
101 cl::desc("Improve global merge pass to ignore globals only used alone"),
115 STATISTIC(NumMerged, "Number of globals merged");
126 /// Currently, this applies a dead simple heuristic: only consider globals
134 bool doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
136 /// \brief Merge everything in \p Globals for which the corresponding bit
138 bool doMerge(const SmallVectorImpl<GlobalVariable *> &Globals,
176 return "Merge internal globals";
192 bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
196 std::stable_sort(Globals.begin(), Globals.end(),
202 // If we want to just blindly group all globals together, do so.
204 BitVector AllGlobals(Globals.size());
206 return doMerge(Globals, AllGlobals, M, isConst, AddrSpace);
210 // discover all sets of globals used together, and how many times each of
215 // code (currently, a Function) to the set of globals seen so far that are
221 // combination of the previous N-1 globals.
227 // We keep track of the sets of globals used together "close enough".
229 UsedGlobalSet(size_t Size) : Globals(Size), UsageCount(1) {}
230 BitVector Globals;
239 UsedGlobalSets.emplace_back(Globals.size());
267 for (size_t GI = 0, GE = Globals.size(); GI != GE; ++GI) {
268 GlobalVariable *GV = Globals[GI];
317 CreateGlobalSet().Globals.set(GI);
327 if (UsedGlobalSets[UGSIdx].Globals.test(GI)) {
349 NewUGS.Globals.set(GI);
350 NewUGS.Globals |= UsedGlobalSets[UGSIdx].Globals;
355 // Now we found a bunch of sets of globals used together. We accumulated
357 // that use that exact set of globals).
363 return UGS1.Globals.count() * UGS1.UsageCount <
364 UGS2.Globals.count() * UGS2.UsageCount;
367 // We can choose to merge all globals together, but ignore globals never used
371 BitVector AllGlobals(Globals.size());
376 if (UGS.Globals.count() > 1)
377 AllGlobals |= UGS.Globals;
379 return doMerge(Globals, AllGlobals, M, isConst, AddrSpace);
388 BitVector PickedGlobals(Globals.size());
395 if (PickedGlobals.anyCommon(UGS.Globals))
397 PickedGlobals |= UGS.Globals;
401 if (UGS.Globals.count() < 2)
403 Changed |= doMerge(Globals, UGS.Globals, M, isConst, AddrSpace);
409 bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals,
412 assert(Globals.size() > 1);
428 Type *Ty = Globals[j]->getValueType();
434 Inits.push_back(Globals[j]->getInitializer());
445 GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage();
446 std::string Name = Globals[k]->getName();
454 Globals[k]->replaceAllUsesWith(GEP);
455 Globals[k]->eraseFromParent();
501 // Look for globals in the clauses of the landing pad instruction
517 DenseMap<unsigned, SmallVector<GlobalVariable*, 16> > Globals, ConstGlobals,
522 // Grab all non-const globals.
523 for (auto &GV : M.globals()) {
524 // Merge is safe for "normal" internal or external globals only
537 // Ignore fancy-aligned globals for now.
543 // Ignore all 'special' globals.
548 // Ignore all "required" globals:
558 Globals[AddressSpace].push_back(&GV);
562 for (auto &P : Globals)