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