Home | History | Annotate | Download | only in CodeGen

Lines Matching defs: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";
202 bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
206 std::stable_sort(Globals.begin(), Globals.end(),
212 // If we want to just blindly group all globals together, do so.
214 BitVector AllGlobals(Globals.size());
216 return doMerge(Globals, AllGlobals, M, isConst, AddrSpace);
220 // discover all sets of globals used together, and how many times each of
225 // code (currently, a Function) to the set of globals seen so far that are
231 // combination of the previous N-1 globals.
237 // We keep track of the sets of globals used together "close enough".
239 UsedGlobalSet(size_t Size) : Globals(Size), UsageCount(1) {}
240 BitVector Globals;
249 UsedGlobalSets.emplace_back(Globals.size());
277 for (size_t GI = 0, GE = Globals.size(); GI != GE; ++GI) {
278 GlobalVariable *GV = Globals[GI];
327 CreateGlobalSet().Globals.set(GI);
337 if (UsedGlobalSets[UGSIdx].Globals.test(GI)) {
359 NewUGS.Globals.set(GI);
360 NewUGS.Globals |= UsedGlobalSets[UGSIdx].Globals;
365 // Now we found a bunch of sets of globals used together. We accumulated
367 // that use that exact set of globals).
373 return UGS1.Globals.count() * UGS1.UsageCount <
374 UGS2.Globals.count() * UGS2.UsageCount;
377 // We can choose to merge all globals together, but ignore globals never used
381 BitVector AllGlobals(Globals.size());
386 if (UGS.Globals.count() > 1)
387 AllGlobals |= UGS.Globals;
389 return doMerge(Globals, AllGlobals, M, isConst, AddrSpace);
398 BitVector PickedGlobals(Globals.size());
405 if (PickedGlobals.anyCommon(UGS.Globals))
407 PickedGlobals |= UGS.Globals;
411 if (UGS.Globals.count() < 2)
413 Changed |= doMerge(Globals, UGS.Globals, M, isConst, AddrSpace);
419 bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals,
422 assert(Globals
438 Type *Ty = Globals[j]->getValueType();
444 Inits.push_back(Globals[j]->getInitializer());
455 GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage();
456 std::string Name = Globals[k]->getName();
464 Globals[k]->replaceAllUsesWith(GEP);
465 Globals[k]->eraseFromParent();
510 // Look for globals in the clauses of the landing pad instruction
528 DenseMap<unsigned, SmallVector<GlobalVariable*, 16> > Globals, ConstGlobals,
533 // Grab all non-const globals.
534 for (auto &GV : M.globals()) {
535 // Merge is safe for "normal" internal or external globals only
548 // Ignore fancy-aligned globals for now.
554 // Ignore all 'special' globals.
559 // Ignore all "required" globals:
570 Globals[AddressSpace].push_back(&GV);
574 for (auto &P : Globals)