xref: /llvm-project/llvm/lib/CodeGen/GlobalMerge.cpp (revision 8207641251706ea808df6d2a1ea8f87b8ee04c6d)
1 //===-- GlobalMerge.cpp - Internal globals merging  -----------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
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
11 // from the same base pointer (no need for separate base pointer for each of the
12 // global). Such a transformation can significantly reduce the register pressure
13 // when many globals are involved.
14 //
15 // For example, consider the code which touches several global variables at
16 // once:
17 //
18 // static int foo[N], bar[N], baz[N];
19 //
20 // for (i = 0; i < N; ++i) {
21 //    foo[i] = bar[i] * baz[i];
22 // }
23 //
24 //  On ARM the addresses of 3 arrays should be kept in the registers, thus
25 //  this code has quite large register pressure (loop body):
26 //
27 //  ldr     r1, [r5], #4
28 //  ldr     r2, [r6], #4
29 //  mul     r1, r2, r1
30 //  str     r1, [r0], #4
31 //
32 //  Pass converts the code to something like:
33 //
34 //  static struct {
35 //    int foo[N];
36 //    int bar[N];
37 //    int baz[N];
38 //  } merged;
39 //
40 //  for (i = 0; i < N; ++i) {
41 //    merged.foo[i] = merged.bar[i] * merged.baz[i];
42 //  }
43 //
44 //  and in ARM code this becomes:
45 //
46 //  ldr     r0, [r5, #40]
47 //  ldr     r1, [r5, #80]
48 //  mul     r0, r1, r0
49 //  str     r0, [r5], #4
50 //
51 //  note that we saved 2 registers here almostly "for free".
52 //
53 // However, merging globals can have tradeoffs:
54 // - it confuses debuggers, tools, and users
55 // - it makes linker optimizations less useful (order files, LOHs, ...)
56 // - it forces usage of indexed addressing (which isn't necessarily "free")
57 // - it can increase register pressure when the uses are disparate enough.
58 //
59 // We use heuristics to discover the best global grouping we can (cf cl::opts).
60 // ===---------------------------------------------------------------------===//
61 
62 #include "llvm/Transforms/Scalar.h"
63 #include "llvm/ADT/DenseMap.h"
64 #include "llvm/ADT/SmallBitVector.h"
65 #include "llvm/ADT/SmallPtrSet.h"
66 #include "llvm/ADT/Statistic.h"
67 #include "llvm/CodeGen/Passes.h"
68 #include "llvm/IR/Attributes.h"
69 #include "llvm/IR/Constants.h"
70 #include "llvm/IR/DataLayout.h"
71 #include "llvm/IR/DerivedTypes.h"
72 #include "llvm/IR/Function.h"
73 #include "llvm/IR/GlobalVariable.h"
74 #include "llvm/IR/Instructions.h"
75 #include "llvm/IR/Intrinsics.h"
76 #include "llvm/IR/Module.h"
77 #include "llvm/Pass.h"
78 #include "llvm/Support/CommandLine.h"
79 #include "llvm/Support/Debug.h"
80 #include "llvm/Support/raw_ostream.h"
81 #include "llvm/Target/TargetLowering.h"
82 #include "llvm/Target/TargetLoweringObjectFile.h"
83 #include "llvm/Target/TargetSubtargetInfo.h"
84 #include <algorithm>
85 using namespace llvm;
86 
87 #define DEBUG_TYPE "global-merge"
88 
89 // FIXME: This is only useful as a last-resort way to disable the pass.
90 static cl::opt<bool>
91 EnableGlobalMerge("enable-global-merge", cl::Hidden,
92                   cl::desc("Enable the global merge pass"),
93                   cl::init(true));
94 
95 static cl::opt<bool> GlobalMergeGroupByUse(
96     "global-merge-group-by-use", cl::Hidden,
97     cl::desc("Improve global merge pass to look at uses"), cl::init(true));
98 
99 static cl::opt<bool> GlobalMergeIgnoreSingleUse(
100     "global-merge-ignore-single-use", cl::Hidden,
101     cl::desc("Improve global merge pass to ignore globals only used alone"),
102     cl::init(true));
103 
104 static cl::opt<bool>
105 EnableGlobalMergeOnConst("global-merge-on-const", cl::Hidden,
106                          cl::desc("Enable global merge pass on constants"),
107                          cl::init(false));
108 
109 // FIXME: this could be a transitional option, and we probably need to remove
110 // it if only we are sure this optimization could always benefit all targets.
111 static cl::opt<bool>
112 EnableGlobalMergeOnExternal("global-merge-on-external", cl::Hidden,
113      cl::desc("Enable global merge pass on external linkage"),
114      cl::init(false));
115 
116 STATISTIC(NumMerged, "Number of globals merged");
117 namespace {
118   class GlobalMerge : public FunctionPass {
119     const TargetMachine *TM;
120     const DataLayout *DL;
121     // FIXME: Infer the maximum possible offset depending on the actual users
122     // (these max offsets are different for the users inside Thumb or ARM
123     // functions), see the code that passes in the offset in the ARM backend
124     // for more information.
125     unsigned MaxOffset;
126 
127     /// Whether we should try to optimize for size only.
128     /// Currently, this applies a dead simple heuristic: only consider globals
129     /// used in minsize functions for merging.
130     /// FIXME: This could learn about optsize, and be used in the cost model.
131     bool OnlyOptimizeForSize;
132 
133     bool doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
134                  Module &M, bool isConst, unsigned AddrSpace) const;
135     /// \brief Merge everything in \p Globals for which the corresponding bit
136     /// in \p GlobalSet is set.
137     bool doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
138                  const BitVector &GlobalSet, Module &M, bool isConst,
139                  unsigned AddrSpace) const;
140 
141     /// \brief Check if the given variable has been identified as must keep
142     /// \pre setMustKeepGlobalVariables must have been called on the Module that
143     ///      contains GV
144     bool isMustKeepGlobalVariable(const GlobalVariable *GV) const {
145       return MustKeepGlobalVariables.count(GV);
146     }
147 
148     /// Collect every variables marked as "used" or used in a landing pad
149     /// instruction for this Module.
150     void setMustKeepGlobalVariables(Module &M);
151 
152     /// Collect every variables marked as "used"
153     void collectUsedGlobalVariables(Module &M);
154 
155     /// Keep track of the GlobalVariable that must not be merged away
156     SmallPtrSet<const GlobalVariable *, 16> MustKeepGlobalVariables;
157 
158   public:
159     static char ID;             // Pass identification, replacement for typeid.
160     explicit GlobalMerge(const TargetMachine *TM = nullptr,
161                          unsigned MaximalOffset = 0,
162                          bool OnlyOptimizeForSize = false)
163         : FunctionPass(ID), TM(TM), DL(TM->getDataLayout()),
164           MaxOffset(MaximalOffset), OnlyOptimizeForSize(OnlyOptimizeForSize) {
165       initializeGlobalMergePass(*PassRegistry::getPassRegistry());
166     }
167 
168     bool doInitialization(Module &M) override;
169     bool runOnFunction(Function &F) override;
170     bool doFinalization(Module &M) override;
171 
172     const char *getPassName() const override {
173       return "Merge internal globals";
174     }
175 
176     void getAnalysisUsage(AnalysisUsage &AU) const override {
177       AU.setPreservesCFG();
178       FunctionPass::getAnalysisUsage(AU);
179     }
180   };
181 } // end anonymous namespace
182 
183 char GlobalMerge::ID = 0;
184 INITIALIZE_PASS_BEGIN(GlobalMerge, "global-merge", "Merge global variables",
185                       false, false)
186 INITIALIZE_PASS_END(GlobalMerge, "global-merge", "Merge global variables",
187                     false, false)
188 
189 bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
190                           Module &M, bool isConst, unsigned AddrSpace) const {
191   // FIXME: Find better heuristics
192   std::stable_sort(Globals.begin(), Globals.end(),
193                    [this](const GlobalVariable *GV1, const GlobalVariable *GV2) {
194     Type *Ty1 = cast<PointerType>(GV1->getType())->getElementType();
195     Type *Ty2 = cast<PointerType>(GV2->getType())->getElementType();
196 
197     return (DL->getTypeAllocSize(Ty1) < DL->getTypeAllocSize(Ty2));
198   });
199 
200   // If we want to just blindly group all globals together, do so.
201   if (!GlobalMergeGroupByUse) {
202     BitVector AllGlobals(Globals.size());
203     AllGlobals.set();
204     return doMerge(Globals, AllGlobals, M, isConst, AddrSpace);
205   }
206 
207   // If we want to be smarter, look at all uses of each global, to try to
208   // discover all sets of globals used together, and how many times each of
209   // these sets occured.
210   //
211   // Keep this reasonably efficient, by having an append-only list of all sets
212   // discovered so far (UsedGlobalSet), and mapping each "together-ness" unit of
213   // code (currently, a Function) to the set of globals seen so far that are
214   // used together in that unit (GlobalUsesByFunction).
215   //
216   // When we look at the Nth global, we now that any new set is either:
217   // - the singleton set {N}, containing this global only, or
218   // - the union of {N} and a previously-discovered set, containing some
219   //   combination of the previous N-1 globals.
220   // Using that knowledge, when looking at the Nth global, we can keep:
221   // - a reference to the singleton set {N} (CurGVOnlySetIdx)
222   // - a list mapping each previous set to its union with {N} (EncounteredUGS),
223   //   if it actually occurs.
224 
225   // We keep track of the sets of globals used together "close enough".
226   struct UsedGlobalSet {
227     UsedGlobalSet(size_t Size) : Globals(Size), UsageCount(1) {}
228     BitVector Globals;
229     unsigned UsageCount;
230   };
231 
232   // Each set is unique in UsedGlobalSets.
233   std::vector<UsedGlobalSet> UsedGlobalSets;
234 
235   // Avoid repeating the create-global-set pattern.
236   auto CreateGlobalSet = [&]() -> UsedGlobalSet & {
237     UsedGlobalSets.emplace_back(Globals.size());
238     return UsedGlobalSets.back();
239   };
240 
241   // The first set is the empty set.
242   CreateGlobalSet().UsageCount = 0;
243 
244   // We define "close enough" to be "in the same function".
245   // FIXME: Grouping uses by function is way too aggressive, so we should have
246   // a better metric for distance between uses.
247   // The obvious alternative would be to group by BasicBlock, but that's in
248   // turn too conservative..
249   // Anything in between wouldn't be trivial to compute, so just stick with
250   // per-function grouping.
251 
252   // The value type is an index into UsedGlobalSets.
253   // The default (0) conveniently points to the empty set.
254   DenseMap<Function *, size_t /*UsedGlobalSetIdx*/> GlobalUsesByFunction;
255 
256   // Now, look at each merge-eligible global in turn.
257 
258   // Keep track of the sets we already encountered to which we added the
259   // current global.
260   // Each element matches the same-index element in UsedGlobalSets.
261   // This lets us efficiently tell whether a set has already been expanded to
262   // include the current global.
263   std::vector<size_t> EncounteredUGS;
264 
265   for (size_t GI = 0, GE = Globals.size(); GI != GE; ++GI) {
266     GlobalVariable *GV = Globals[GI];
267 
268     // Reset the encountered sets for this global...
269     std::fill(EncounteredUGS.begin(), EncounteredUGS.end(), 0);
270     // ...and grow it in case we created new sets for the previous global.
271     EncounteredUGS.resize(UsedGlobalSets.size());
272 
273     // We might need to create a set that only consists of the current global.
274     // Keep track of its index into UsedGlobalSets.
275     size_t CurGVOnlySetIdx = 0;
276 
277     // For each global, look at all its Uses.
278     for (auto &U : GV->uses()) {
279       // This Use might be a ConstantExpr.  We're interested in Instruction
280       // users, so look through ConstantExpr...
281       Use *UI, *UE;
282       if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U.getUser())) {
283         UI = &*CE->use_begin();
284         UE = nullptr;
285       } else if (isa<Instruction>(U.getUser())) {
286         UI = &U;
287         UE = UI->getNext();
288       } else {
289         continue;
290       }
291 
292       // ...to iterate on all the instruction users of the global.
293       // Note that we iterate on Uses and not on Users to be able to getNext().
294       for (; UI != UE; UI = UI->getNext()) {
295         Instruction *I = dyn_cast<Instruction>(UI->getUser());
296         if (!I)
297           continue;
298 
299         Function *ParentFn = I->getParent()->getParent();
300 
301         // If we're only optimizing for size, ignore non-minsize functions.
302         if (OnlyOptimizeForSize &&
303             !ParentFn->hasFnAttribute(Attribute::MinSize))
304           continue;
305 
306         size_t UGSIdx = GlobalUsesByFunction[ParentFn];
307 
308         // If this is the first global the basic block uses, map it to the set
309         // consisting of this global only.
310         if (!UGSIdx) {
311           // If that set doesn't exist yet, create it.
312           if (!CurGVOnlySetIdx) {
313             CurGVOnlySetIdx = UsedGlobalSets.size();
314             CreateGlobalSet().Globals.set(GI);
315           } else {
316             ++UsedGlobalSets[CurGVOnlySetIdx].UsageCount;
317           }
318 
319           GlobalUsesByFunction[ParentFn] = CurGVOnlySetIdx;
320           continue;
321         }
322 
323         // If we already encountered this BB, just increment the counter.
324         if (UsedGlobalSets[UGSIdx].Globals.test(GI)) {
325           ++UsedGlobalSets[UGSIdx].UsageCount;
326           continue;
327         }
328 
329         // If not, the previous set wasn't actually used in this function.
330         --UsedGlobalSets[UGSIdx].UsageCount;
331 
332         // If we already expanded the previous set to include this global, just
333         // reuse that expanded set.
334         if (size_t ExpandedIdx = EncounteredUGS[UGSIdx]) {
335           ++UsedGlobalSets[ExpandedIdx].UsageCount;
336           GlobalUsesByFunction[ParentFn] = ExpandedIdx;
337           continue;
338         }
339 
340         // If not, create a new set consisting of the union of the previous set
341         // and this global.  Mark it as encountered, so we can reuse it later.
342         GlobalUsesByFunction[ParentFn] = EncounteredUGS[UGSIdx] =
343             UsedGlobalSets.size();
344 
345         UsedGlobalSet &NewUGS = CreateGlobalSet();
346         NewUGS.Globals.set(GI);
347         NewUGS.Globals |= UsedGlobalSets[UGSIdx].Globals;
348       }
349     }
350   }
351 
352   // Now we found a bunch of sets of globals used together.  We accumulated
353   // the number of times we encountered the sets (i.e., the number of blocks
354   // that use that exact set of globals).
355   //
356   // Multiply that by the size of the set to give us a crude profitability
357   // metric.
358   std::sort(UsedGlobalSets.begin(), UsedGlobalSets.end(),
359             [](const UsedGlobalSet &UGS1, const UsedGlobalSet &UGS2) {
360               return UGS1.Globals.count() * UGS1.UsageCount <
361                      UGS2.Globals.count() * UGS2.UsageCount;
362             });
363 
364   // We can choose to merge all globals together, but ignore globals never used
365   // with another global.  This catches the obviously non-profitable cases of
366   // having a single global, but is aggressive enough for any other case.
367   if (GlobalMergeIgnoreSingleUse) {
368     BitVector AllGlobals(Globals.size());
369     for (size_t i = 0, e = UsedGlobalSets.size(); i != e; ++i) {
370       const UsedGlobalSet &UGS = UsedGlobalSets[e - i - 1];
371       if (UGS.UsageCount == 0)
372         continue;
373       if (UGS.Globals.count() > 1)
374         AllGlobals |= UGS.Globals;
375     }
376     return doMerge(Globals, AllGlobals, M, isConst, AddrSpace);
377   }
378 
379   // Starting from the sets with the best (=biggest) profitability, find a
380   // good combination.
381   // The ideal (and expensive) solution can only be found by trying all
382   // combinations, looking for the one with the best profitability.
383   // Don't be smart about it, and just pick the first compatible combination,
384   // starting with the sets with the best profitability.
385   BitVector PickedGlobals(Globals.size());
386   bool Changed = false;
387 
388   for (size_t i = 0, e = UsedGlobalSets.size(); i != e; ++i) {
389     const UsedGlobalSet &UGS = UsedGlobalSets[e - i - 1];
390     if (UGS.UsageCount == 0)
391       continue;
392     if (PickedGlobals.anyCommon(UGS.Globals))
393       continue;
394     PickedGlobals |= UGS.Globals;
395     // If the set only contains one global, there's no point in merging.
396     // Ignore the global for inclusion in other sets though, so keep it in
397     // PickedGlobals.
398     if (UGS.Globals.count() < 2)
399       continue;
400     Changed |= doMerge(Globals, UGS.Globals, M, isConst, AddrSpace);
401   }
402 
403   return Changed;
404 }
405 
406 bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
407                           const BitVector &GlobalSet, Module &M, bool isConst,
408                           unsigned AddrSpace) const {
409 
410   Type *Int32Ty = Type::getInt32Ty(M.getContext());
411 
412   assert(Globals.size() > 1);
413 
414   DEBUG(dbgs() << " Trying to merge set, starts with #"
415                << GlobalSet.find_first() << "\n");
416 
417   ssize_t i = GlobalSet.find_first();
418   while (i != -1) {
419     ssize_t j = 0;
420     uint64_t MergedSize = 0;
421     std::vector<Type*> Tys;
422     std::vector<Constant*> Inits;
423 
424     bool HasExternal = false;
425     GlobalVariable *TheFirstExternal = 0;
426     for (j = i; j != -1; j = GlobalSet.find_next(j)) {
427       Type *Ty = Globals[j]->getType()->getElementType();
428       MergedSize += DL->getTypeAllocSize(Ty);
429       if (MergedSize > MaxOffset) {
430         break;
431       }
432       Tys.push_back(Ty);
433       Inits.push_back(Globals[j]->getInitializer());
434 
435       if (Globals[j]->hasExternalLinkage() && !HasExternal) {
436         HasExternal = true;
437         TheFirstExternal = Globals[j];
438       }
439     }
440 
441     // If merged variables doesn't have external linkage, we needn't to expose
442     // the symbol after merging.
443     GlobalValue::LinkageTypes Linkage = HasExternal
444                                             ? GlobalValue::ExternalLinkage
445                                             : GlobalValue::InternalLinkage;
446 
447     StructType *MergedTy = StructType::get(M.getContext(), Tys);
448     Constant *MergedInit = ConstantStruct::get(MergedTy, Inits);
449 
450     // If merged variables have external linkage, we use symbol name of the
451     // first variable merged as the suffix of global symbol name. This would
452     // be able to avoid the link-time naming conflict for globalm symbols.
453     GlobalVariable *MergedGV = new GlobalVariable(
454         M, MergedTy, isConst, Linkage, MergedInit,
455         HasExternal ? "_MergedGlobals_" + TheFirstExternal->getName()
456                     : "_MergedGlobals",
457         nullptr, GlobalVariable::NotThreadLocal, AddrSpace);
458 
459     for (ssize_t k = i, idx = 0; k != j; k = GlobalSet.find_next(k)) {
460       GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage();
461       std::string Name = Globals[k]->getName();
462 
463       Constant *Idx[2] = {
464         ConstantInt::get(Int32Ty, 0),
465         ConstantInt::get(Int32Ty, idx++)
466       };
467       Constant *GEP =
468           ConstantExpr::getInBoundsGetElementPtr(MergedTy, MergedGV, Idx);
469       Globals[k]->replaceAllUsesWith(GEP);
470       Globals[k]->eraseFromParent();
471 
472       if (Linkage != GlobalValue::InternalLinkage) {
473         // Generate a new alias...
474         auto *PTy = cast<PointerType>(GEP->getType());
475         GlobalAlias::create(PTy, Linkage, Name, GEP, &M);
476       }
477 
478       NumMerged++;
479     }
480     i = j;
481   }
482 
483   return true;
484 }
485 
486 void GlobalMerge::collectUsedGlobalVariables(Module &M) {
487   // Extract global variables from llvm.used array
488   const GlobalVariable *GV = M.getGlobalVariable("llvm.used");
489   if (!GV || !GV->hasInitializer()) return;
490 
491   // Should be an array of 'i8*'.
492   const ConstantArray *InitList = cast<ConstantArray>(GV->getInitializer());
493 
494   for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
495     if (const GlobalVariable *G =
496         dyn_cast<GlobalVariable>(InitList->getOperand(i)->stripPointerCasts()))
497       MustKeepGlobalVariables.insert(G);
498 }
499 
500 void GlobalMerge::setMustKeepGlobalVariables(Module &M) {
501   collectUsedGlobalVariables(M);
502 
503   for (Module::iterator IFn = M.begin(), IEndFn = M.end(); IFn != IEndFn;
504        ++IFn) {
505     for (Function::iterator IBB = IFn->begin(), IEndBB = IFn->end();
506          IBB != IEndBB; ++IBB) {
507       // Follow the invoke link to find the landing pad instruction
508       const InvokeInst *II = dyn_cast<InvokeInst>(IBB->getTerminator());
509       if (!II) continue;
510 
511       const LandingPadInst *LPInst = II->getUnwindDest()->getLandingPadInst();
512       // Look for globals in the clauses of the landing pad instruction
513       for (unsigned Idx = 0, NumClauses = LPInst->getNumClauses();
514            Idx != NumClauses; ++Idx)
515         if (const GlobalVariable *GV =
516             dyn_cast<GlobalVariable>(LPInst->getClause(Idx)
517                                      ->stripPointerCasts()))
518           MustKeepGlobalVariables.insert(GV);
519     }
520   }
521 }
522 
523 bool GlobalMerge::doInitialization(Module &M) {
524   if (!EnableGlobalMerge)
525     return false;
526 
527   DenseMap<unsigned, SmallVector<GlobalVariable*, 16> > Globals, ConstGlobals,
528                                                         BSSGlobals;
529   bool Changed = false;
530   setMustKeepGlobalVariables(M);
531 
532   // Grab all non-const globals.
533   for (Module::global_iterator I = M.global_begin(),
534          E = M.global_end(); I != E; ++I) {
535     // Merge is safe for "normal" internal or external globals only
536     if (I->isDeclaration() || I->isThreadLocal() || I->hasSection())
537       continue;
538 
539     if (!(EnableGlobalMergeOnExternal && I->hasExternalLinkage()) &&
540         !I->hasInternalLinkage())
541       continue;
542 
543     PointerType *PT = dyn_cast<PointerType>(I->getType());
544     assert(PT && "Global variable is not a pointer!");
545 
546     unsigned AddressSpace = PT->getAddressSpace();
547 
548     // Ignore fancy-aligned globals for now.
549     unsigned Alignment = DL->getPreferredAlignment(I);
550     Type *Ty = I->getType()->getElementType();
551     if (Alignment > DL->getABITypeAlignment(Ty))
552       continue;
553 
554     // Ignore all 'special' globals.
555     if (I->getName().startswith("llvm.") ||
556         I->getName().startswith(".llvm."))
557       continue;
558 
559     // Ignore all "required" globals:
560     if (isMustKeepGlobalVariable(I))
561       continue;
562 
563     if (DL->getTypeAllocSize(Ty) < MaxOffset) {
564       if (TargetLoweringObjectFile::getKindForGlobal(I, *TM).isBSSLocal())
565         BSSGlobals[AddressSpace].push_back(I);
566       else if (I->isConstant())
567         ConstGlobals[AddressSpace].push_back(I);
568       else
569         Globals[AddressSpace].push_back(I);
570     }
571   }
572 
573   for (DenseMap<unsigned, SmallVector<GlobalVariable*, 16> >::iterator
574        I = Globals.begin(), E = Globals.end(); I != E; ++I)
575     if (I->second.size() > 1)
576       Changed |= doMerge(I->second, M, false, I->first);
577 
578   for (DenseMap<unsigned, SmallVector<GlobalVariable*, 16> >::iterator
579        I = BSSGlobals.begin(), E = BSSGlobals.end(); I != E; ++I)
580     if (I->second.size() > 1)
581       Changed |= doMerge(I->second, M, false, I->first);
582 
583   if (EnableGlobalMergeOnConst)
584     for (DenseMap<unsigned, SmallVector<GlobalVariable*, 16> >::iterator
585          I = ConstGlobals.begin(), E = ConstGlobals.end(); I != E; ++I)
586       if (I->second.size() > 1)
587         Changed |= doMerge(I->second, M, true, I->first);
588 
589   return Changed;
590 }
591 
592 bool GlobalMerge::runOnFunction(Function &F) {
593   return false;
594 }
595 
596 bool GlobalMerge::doFinalization(Module &M) {
597   MustKeepGlobalVariables.clear();
598   return false;
599 }
600 
601 Pass *llvm::createGlobalMergePass(const TargetMachine *TM, unsigned Offset,
602                                   bool OnlyOptimizeForSize) {
603   return new GlobalMerge(TM, Offset, OnlyOptimizeForSize);
604 }
605