• Home
  • Raw
  • Download

Lines Matching refs:GV

80     bool ProcessGlobal(GlobalVariable *GV,Module::global_iterator &GVI);
81 bool ProcessInternalGlobal(GlobalVariable *GV,Module::global_iterator &GVI,
234 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>( in AnalyzeGlobal() local
237 if (StoredVal == GV->getInitializer()) { in AnalyzeGlobal()
241 cast<LoadInst>(StoredVal)->getOperand(0) == GV) { in AnalyzeGlobal()
301 static bool isLeakCheckerRoot(GlobalVariable *GV) { in isLeakCheckerRoot() argument
310 if (GV->hasPrivateLinkage()) in isLeakCheckerRoot()
314 Types.push_back(cast<PointerType>(GV->getType())->getElementType()); in isLeakCheckerRoot()
379 static bool CleanupPointerRootUsers(GlobalVariable *GV, in CleanupPointerRootUsers() argument
397 for (Value::use_iterator UI = GV->use_begin(), E = GV->use_end(); in CleanupPointerRootUsers()
436 CleanupPointerRootUsers(GV, TLI); in CleanupPointerRootUsers()
578 static bool IsUserOfGlobalSafeForSRA(User *U, GlobalValue *GV) { in IsUserOfGlobalSafeForSRA() argument
644 static bool GlobalUsersSafeToSRA(GlobalValue *GV) { in GlobalUsersSafeToSRA() argument
645 for (Value::use_iterator UI = GV->use_begin(), E = GV->use_end(); in GlobalUsersSafeToSRA()
647 if (!IsUserOfGlobalSafeForSRA(*UI, GV)) in GlobalUsersSafeToSRA()
659 static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD) { in SRAGlobal() argument
661 if (!GlobalUsersSafeToSRA(GV)) in SRAGlobal()
664 assert(GV->hasLocalLinkage() && !GV->isConstant()); in SRAGlobal()
665 Constant *Init = GV->getInitializer(); in SRAGlobal()
669 Module::GlobalListType &Globals = GV->getParent()->getGlobalList(); in SRAGlobal()
672 unsigned StartAlignment = GV->getAlignment(); in SRAGlobal()
674 StartAlignment = TD.getABITypeAlignment(GV->getType()); in SRAGlobal()
684 In, GV->getName()+"."+Twine(i), in SRAGlobal()
685 GV->getThreadLocalMode(), in SRAGlobal()
686 GV->getType()->getAddressSpace()); in SRAGlobal()
687 Globals.insert(GV, NGV); in SRAGlobal()
705 if (NumElements > 16 && GV->hasNUsesOrMore(16)) in SRAGlobal()
717 In, GV->getName()+"."+Twine(i), in SRAGlobal()
718 GV->getThreadLocalMode(), in SRAGlobal()
719 GV->getType()->getAddressSpace()); in SRAGlobal()
720 Globals.insert(GV, NGV); in SRAGlobal()
735 DEBUG(dbgs() << "PERFORMING GLOBAL SRA ON: " << *GV); in SRAGlobal()
737 Constant *NullInt =Constant::getNullValue(Type::getInt32Ty(GV->getContext())); in SRAGlobal()
741 while (!GV->use_empty()) { in SRAGlobal()
742 User *GEP = GV->use_back(); in SRAGlobal()
782 Globals.erase(GV); in SRAGlobal()
847 static bool AllUsesOfLoadedValueWillTrapIfNull(const GlobalVariable *GV) { in AllUsesOfLoadedValueWillTrapIfNull() argument
848 for (Value::const_use_iterator UI = GV->use_begin(), E = GV->use_end(); in AllUsesOfLoadedValueWillTrapIfNull()
934 static bool OptimizeAwayTrappingUsesOfLoads(GlobalVariable *GV, Constant *LV, in OptimizeAwayTrappingUsesOfLoads() argument
944 for (Value::use_iterator GUI = GV->use_begin(), E = GV->use_end(); GUI != E;){ in OptimizeAwayTrappingUsesOfLoads()
957 assert(GlobalUser->getOperand(1) == GV && in OptimizeAwayTrappingUsesOfLoads()
971 DEBUG(dbgs() << "OPTIMIZED LOADS FROM STORED ONCE POINTER: " << *GV); in OptimizeAwayTrappingUsesOfLoads()
978 if (isLeakCheckerRoot(GV)) { in OptimizeAwayTrappingUsesOfLoads()
979 Changed |= CleanupPointerRootUsers(GV, TLI); in OptimizeAwayTrappingUsesOfLoads()
982 CleanupConstantGlobalUsers(GV, 0, TD, TLI); in OptimizeAwayTrappingUsesOfLoads()
984 if (GV->use_empty()) { in OptimizeAwayTrappingUsesOfLoads()
987 GV->eraseFromParent(); in OptimizeAwayTrappingUsesOfLoads()
1016 static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, in OptimizeGlobalAddressOfMalloc() argument
1022 DEBUG(errs() << "PROMOTING GLOBAL: " << *GV << " CALL = " << *CI << '\n'); in OptimizeGlobalAddressOfMalloc()
1033 GlobalVariable *NewGV = new GlobalVariable(*GV->getParent(), in OptimizeGlobalAddressOfMalloc()
1037 GV->getName()+".body", in OptimizeGlobalAddressOfMalloc()
1038 GV, in OptimizeGlobalAddressOfMalloc()
1039 GV->getThreadLocalMode()); in OptimizeGlobalAddressOfMalloc()
1062 if (NewGV->getType() != GV->getType()->getElementType()) in OptimizeGlobalAddressOfMalloc()
1064 GV->getType()->getElementType()); in OptimizeGlobalAddressOfMalloc()
1069 new GlobalVariable(Type::getInt1Ty(GV->getContext()), false, in OptimizeGlobalAddressOfMalloc()
1071 ConstantInt::getFalse(GV->getContext()), in OptimizeGlobalAddressOfMalloc()
1072 GV->getName()+".init", GV->getThreadLocalMode()); in OptimizeGlobalAddressOfMalloc()
1076 while (!GV->use_empty()) { in OptimizeGlobalAddressOfMalloc()
1077 if (StoreInst *SI = dyn_cast<StoreInst>(GV->use_back())) { in OptimizeGlobalAddressOfMalloc()
1079 new StoreInst(ConstantInt::getTrue(GV->getContext()), InitBool, false, 0, in OptimizeGlobalAddressOfMalloc()
1085 LoadInst *LI = cast<LoadInst>(GV->use_back()); in OptimizeGlobalAddressOfMalloc()
1104 LV = ConstantInt::getFalse(GV->getContext()); in OptimizeGlobalAddressOfMalloc()
1130 GV->getParent()->getGlobalList().insert(GV, InitBool); in OptimizeGlobalAddressOfMalloc()
1133 GV->eraseFromParent(); in OptimizeGlobalAddressOfMalloc()
1151 const GlobalVariable *GV, in ValueIsOnlyUsedLocallyOrStoredToOneGlobal() argument
1162 if (SI->getOperand(0) == V && SI->getOperand(1) != GV) in ValueIsOnlyUsedLocallyOrStoredToOneGlobal()
1169 if (!ValueIsOnlyUsedLocallyOrStoredToOneGlobal(Inst, GV, PHIs)) in ValueIsOnlyUsedLocallyOrStoredToOneGlobal()
1178 if (!ValueIsOnlyUsedLocallyOrStoredToOneGlobal(PN, GV, PHIs)) in ValueIsOnlyUsedLocallyOrStoredToOneGlobal()
1184 if (!ValueIsOnlyUsedLocallyOrStoredToOneGlobal(BCI, GV, PHIs)) in ValueIsOnlyUsedLocallyOrStoredToOneGlobal()
1200 GlobalVariable *GV) { in ReplaceUsesOfMallocWithGlobal() argument
1206 if (SI->getOperand(1) == GV) { in ReplaceUsesOfMallocWithGlobal()
1216 ReplaceUsesOfMallocWithGlobal(U, GV); in ReplaceUsesOfMallocWithGlobal()
1224 if (SI->getOperand(1) == GV) { in ReplaceUsesOfMallocWithGlobal()
1227 ReplaceUsesOfMallocWithGlobal(GEPI, GV); in ReplaceUsesOfMallocWithGlobal()
1234 Value *NL = new LoadInst(GV, GV->getName()+".val", InsertPt); in ReplaceUsesOfMallocWithGlobal()
1295 static bool AllGlobalLoadUsesSimpleEnoughForHeapSRA(const GlobalVariable *GV, in AllGlobalLoadUsesSimpleEnoughForHeapSRA() argument
1299 for (Value::const_use_iterator UI = GV->use_begin(), E = GV->use_end(); in AllGlobalLoadUsesSimpleEnoughForHeapSRA()
1331 if (LI->getOperand(0) == GV) in AllGlobalLoadUsesSimpleEnoughForHeapSRA()
1468 static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, CallInst *CI, in PerformHeapAllocSRoA() argument
1471 DEBUG(dbgs() << "SROA HEAP ALLOC: " << *GV << " MALLOC = " << *CI << '\n'); in PerformHeapAllocSRoA()
1479 ReplaceUsesOfMallocWithGlobal(CI, GV); in PerformHeapAllocSRoA()
1491 new GlobalVariable(*GV->getParent(), in PerformHeapAllocSRoA()
1494 GV->getName() + ".f" + Twine(FieldNo), GV, in PerformHeapAllocSRoA()
1495 GV->getThreadLocalMode()); in PerformHeapAllocSRoA()
1579 InsertedScalarizedValues[GV] = FieldGlobals; in PerformHeapAllocSRoA()
1586 for (Value::use_iterator UI = GV->use_begin(), E = GV->use_end(); UI != E;) { in PerformHeapAllocSRoA()
1647 GV->eraseFromParent(); in PerformHeapAllocSRoA()
1656 static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, in TryToOptimizeStoreOfMallocToGlobal() argument
1676 if (!AllUsesOfLoadedValueWillTrapIfNull(GV)) in TryToOptimizeStoreOfMallocToGlobal()
1685 if (!ValueIsOnlyUsedLocallyOrStoredToOneGlobal(CI, GV, PHIs)) in TryToOptimizeStoreOfMallocToGlobal()
1702 GVI = OptimizeGlobalAddressOfMalloc(GV, CI, AllocTy, NElements, TD, TLI); in TryToOptimizeStoreOfMallocToGlobal()
1726 AllGlobalLoadUsesSimpleEnoughForHeapSRA(GV, CI)) { in TryToOptimizeStoreOfMallocToGlobal()
1747 GVI = PerformHeapAllocSRoA(GV, CI, getMallocArraySize(CI, TD, TLI, true), in TryToOptimizeStoreOfMallocToGlobal()
1757 static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, in OptimizeOnceStoredGlobal() argument
1768 if (GV->getInitializer()->getType()->isPointerTy() && in OptimizeOnceStoredGlobal()
1769 GV->getInitializer()->isNullValue()) { in OptimizeOnceStoredGlobal()
1771 if (GV->getInitializer()->getType() != SOVC->getType()) in OptimizeOnceStoredGlobal()
1772 SOVC = ConstantExpr::getBitCast(SOVC, GV->getInitializer()->getType()); in OptimizeOnceStoredGlobal()
1775 if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC, TD, TLI)) in OptimizeOnceStoredGlobal()
1780 TryToOptimizeStoreOfMallocToGlobal(GV, CI, MallocType, Ordering, GVI, in OptimizeOnceStoredGlobal()
1793 static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { in TryToShrinkGlobalToBoolean() argument
1794 Type *GVElType = GV->getType()->getElementType(); in TryToShrinkGlobalToBoolean()
1801 if (GVElType == Type::getInt1Ty(GV->getContext()) || in TryToShrinkGlobalToBoolean()
1808 for (Value::use_iterator I = GV->use_begin(), E = GV->use_end(); I != E; ++I){ in TryToShrinkGlobalToBoolean()
1814 DEBUG(dbgs() << " *** SHRINKING TO BOOL: " << *GV); in TryToShrinkGlobalToBoolean()
1817 GlobalVariable *NewGV = new GlobalVariable(Type::getInt1Ty(GV->getContext()), in TryToShrinkGlobalToBoolean()
1820 ConstantInt::getFalse(GV->getContext()), in TryToShrinkGlobalToBoolean()
1821 GV->getName()+".b", in TryToShrinkGlobalToBoolean()
1822 GV->getThreadLocalMode()); in TryToShrinkGlobalToBoolean()
1823 GV->getParent()->getGlobalList().insert(GV, NewGV); in TryToShrinkGlobalToBoolean()
1825 Constant *InitVal = GV->getInitializer(); in TryToShrinkGlobalToBoolean()
1826 assert(InitVal->getType() != Type::getInt1Ty(GV->getContext()) && in TryToShrinkGlobalToBoolean()
1835 while (!GV->use_empty()) { in TryToShrinkGlobalToBoolean()
1836 Instruction *UI = cast<Instruction>(GV->use_back()); in TryToShrinkGlobalToBoolean()
1843 StoreVal = ConstantInt::get(Type::getInt1Ty(GV->getContext()), in TryToShrinkGlobalToBoolean()
1855 assert(LI->getOperand(0) == GV && "Not a copy!"); in TryToShrinkGlobalToBoolean()
1884 GV->eraseFromParent(); in TryToShrinkGlobalToBoolean()
1891 bool GlobalOpt::ProcessGlobal(GlobalVariable *GV, in ProcessGlobal() argument
1893 if (!GV->isDiscardableIfUnused()) in ProcessGlobal()
1897 GV->removeDeadConstantUsers(); in ProcessGlobal()
1899 if (GV->use_empty()) { in ProcessGlobal()
1900 DEBUG(dbgs() << "GLOBAL DEAD: " << *GV); in ProcessGlobal()
1901 GV->eraseFromParent(); in ProcessGlobal()
1906 if (!GV->hasLocalLinkage()) in ProcessGlobal()
1912 if (AnalyzeGlobal(GV, GS, PHIUsers)) in ProcessGlobal()
1915 if (!GS.isCompared && !GV->hasUnnamedAddr()) { in ProcessGlobal()
1916 GV->setUnnamedAddr(true); in ProcessGlobal()
1920 if (GV->isConstant() || !GV->hasInitializer()) in ProcessGlobal()
1923 return ProcessInternalGlobal(GV, GVI, PHIUsers, GS); in ProcessGlobal()
1928 bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV, in ProcessInternalGlobal() argument
1943 GV->getType()->getElementType()->isSingleValueType() && in ProcessInternalGlobal()
1946 GV->getType()->getAddressSpace() == 0) { in ProcessInternalGlobal()
1947 DEBUG(dbgs() << "LOCALIZING GLOBAL: " << *GV); in ProcessInternalGlobal()
1950 Type *ElemTy = GV->getType()->getElementType(); in ProcessInternalGlobal()
1952 AllocaInst *Alloca = new AllocaInst(ElemTy, NULL, GV->getName(), &FirstI); in ProcessInternalGlobal()
1953 if (!isa<UndefValue>(GV->getInitializer())) in ProcessInternalGlobal()
1954 new StoreInst(GV->getInitializer(), Alloca, &FirstI); in ProcessInternalGlobal()
1956 GV->replaceAllUsesWith(Alloca); in ProcessInternalGlobal()
1957 GV->eraseFromParent(); in ProcessInternalGlobal()
1965 DEBUG(dbgs() << "GLOBAL NEVER LOADED: " << *GV); in ProcessInternalGlobal()
1968 if (isLeakCheckerRoot(GV)) { in ProcessInternalGlobal()
1970 Changed = CleanupPointerRootUsers(GV, TLI); in ProcessInternalGlobal()
1974 Changed = CleanupConstantGlobalUsers(GV, GV->getInitializer(), TD, TLI); in ProcessInternalGlobal()
1978 if (GV->use_empty()) { in ProcessInternalGlobal()
1979 GV->eraseFromParent(); in ProcessInternalGlobal()
1986 DEBUG(dbgs() << "MARKING CONSTANT: " << *GV); in ProcessInternalGlobal()
1987 GV->setConstant(true); in ProcessInternalGlobal()
1990 CleanupConstantGlobalUsers(GV, GV->getInitializer(), TD, TLI); in ProcessInternalGlobal()
1993 if (GV->use_empty()) { in ProcessInternalGlobal()
1996 GV->eraseFromParent(); in ProcessInternalGlobal()
2002 } else if (!GV->getInitializer()->getType()->isSingleValueType()) { in ProcessInternalGlobal()
2004 if (GlobalVariable *FirstNewGV = SRAGlobal(GV, *TD)) { in ProcessInternalGlobal()
2014 if (isa<UndefValue>(GV->getInitializer())) { in ProcessInternalGlobal()
2016 GV->setInitializer(SOVConstant); in ProcessInternalGlobal()
2019 CleanupConstantGlobalUsers(GV, GV->getInitializer(), TD, TLI); in ProcessInternalGlobal()
2021 if (GV->use_empty()) { in ProcessInternalGlobal()
2024 GV->eraseFromParent(); in ProcessInternalGlobal()
2027 GVI = GV; in ProcessInternalGlobal()
2035 if (OptimizeOnceStoredGlobal(GV, GS.StoredOnceValue, GS.Ordering, GVI, in ProcessInternalGlobal()
2042 if (TryToShrinkGlobalToBoolean(GV, SOVConstant)) { in ProcessInternalGlobal()
2126 GlobalVariable *GV = GVI++; in OptimizeGlobalVars() local
2128 if (!GV->hasName() && !GV->isDeclaration()) in OptimizeGlobalVars()
2129 GV->setLinkage(GlobalValue::InternalLinkage); in OptimizeGlobalVars()
2131 if (GV->hasInitializer()) in OptimizeGlobalVars()
2132 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(GV->getInitializer())) { in OptimizeGlobalVars()
2135 GV->setInitializer(New); in OptimizeGlobalVars()
2138 Changed |= ProcessGlobal(GV, GVI); in OptimizeGlobalVars()
2146 GlobalVariable *GV = M.getGlobalVariable("llvm.global_ctors"); in FindGlobalCtors() local
2147 if (GV == 0) return 0; in FindGlobalCtors()
2151 if (!GV->hasUniqueInitializer()) return 0; in FindGlobalCtors()
2153 if (isa<ConstantAggregateZero>(GV->getInitializer())) in FindGlobalCtors()
2154 return GV; in FindGlobalCtors()
2155 ConstantArray *CA = cast<ConstantArray>(GV->getInitializer()); in FindGlobalCtors()
2174 return GV; in FindGlobalCtors()
2179 static std::vector<Function*> ParseGlobalCtors(GlobalVariable *GV) { in ParseGlobalCtors() argument
2180 if (GV->getInitializer()->isNullValue()) in ParseGlobalCtors()
2182 ConstantArray *CA = cast<ConstantArray>(GV->getInitializer()); in ParseGlobalCtors()
2344 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) in isSimpleEnoughPointerToCommit() local
2347 return GV->hasUniqueInitializer(); in isSimpleEnoughPointerToCommit()
2354 GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0)); in isSimpleEnoughPointerToCommit() local
2357 if (!GV->hasUniqueInitializer()) in isSimpleEnoughPointerToCommit()
2369 return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE); in isSimpleEnoughPointerToCommit()
2437 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Addr)) { in CommitValueTo() local
2438 assert(GV->hasInitializer()); in CommitValueTo()
2439 GV->setInitializer(Val); in CommitValueTo()
2444 GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0)); in CommitValueTo() local
2445 GV->setInitializer(EvaluateStoreInto(GV->getInitializer(), Val, CE, 2)); in CommitValueTo()
2553 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(P)) { in ComputeLoadResult() local
2554 if (GV->hasDefinitiveInitializer()) in ComputeLoadResult()
2555 return GV->getInitializer(); in ComputeLoadResult()
2563 GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0)); in ComputeLoadResult() local
2564 if (GV->hasDefinitiveInitializer()) in ComputeLoadResult()
2565 return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE); in ComputeLoadResult()
2715 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Ptr)) { in EvaluateBlock() local
2716 Type *ElemTy = cast<PointerType>(GV->getType())->getElementType(); in EvaluateBlock()
2720 Invariants.insert(GV); in EvaluateBlock()