Lines Matching refs:GV
110 static bool isLeakCheckerRoot(GlobalVariable *GV) { in isLeakCheckerRoot() argument
119 if (GV->hasPrivateLinkage()) in isLeakCheckerRoot()
123 Types.push_back(GV->getValueType()); in isLeakCheckerRoot()
193 CleanupPointerRootUsers(GlobalVariable *GV, in CleanupPointerRootUsers() argument
211 for (User *U : llvm::make_early_inc_range(GV->users())) { in CleanupPointerRootUsers()
248 CleanupPointerRootUsers(GV, GetTLI); in CleanupPointerRootUsers()
278 static bool CleanupConstantGlobalUsers(GlobalVariable *GV, in CleanupConstantGlobalUsers() argument
280 Constant *Init = GV->getInitializer(); in CleanupConstantGlobalUsers()
281 SmallVector<User *, 8> WorkList(GV->users()); in CleanupConstantGlobalUsers()
318 if (PtrOp == GV) { in CleanupConstantGlobalUsers()
328 if (getUnderlyingObject(MI->getRawDest()) == GV) in CleanupConstantGlobalUsers()
335 GV->removeDeadConstantUsers(); in CleanupConstantGlobalUsers()
341 static bool collectSRATypes(DenseMap<uint64_t, Type *> &Types, GlobalValue *GV, in collectSRATypes() argument
350 AppendUses(GV); in collectSRATypes()
371 if (Ptr != GV || Offset.getActiveBits() >= 64) in collectSRATypes()
398 static void transferSRADebugInfo(GlobalVariable *GV, GlobalVariable *NGV, in transferSRADebugInfo() argument
403 GV->getDebugInfo(GVs); in transferSRADebugInfo()
454 static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) { in SRAGlobal() argument
455 assert(GV->hasLocalLinkage()); in SRAGlobal()
459 if (!collectSRATypes(Types, GV, DL) || Types.empty()) in SRAGlobal()
463 if (Types.size() == 1 && Types.begin()->second == GV->getValueType()) in SRAGlobal()
486 if (Offset > DL.getTypeAllocSize(GV->getValueType())) in SRAGlobal()
490 Constant *OrigInit = GV->getInitializer(); in SRAGlobal()
497 << *GV << " with type " << *Pair.second << " at offset " in SRAGlobal()
504 LLVM_DEBUG(dbgs() << "PERFORMING GLOBAL SRA ON: " << *GV << "\n"); in SRAGlobal()
508 DL.getValueOrABITypeAlignment(GV->getAlign(), GV->getValueType()); in SRAGlobal()
509 uint64_t VarSize = DL.getTypeSizeInBits(GV->getValueType()); in SRAGlobal()
518 *GV->getParent(), Ty, false, GlobalVariable::InternalLinkage, in SRAGlobal()
519 Initializers[Offset], GV->getName() + "." + Twine(NameSuffix++), GV, in SRAGlobal()
520 GV->getThreadLocalMode(), GV->getAddressSpace()); in SRAGlobal()
521 NGV->copyAttributesFrom(GV); in SRAGlobal()
532 transferSRADebugInfo(GV, NGV, Offset * 8, DL.getTypeAllocSizeInBits(Ty), in SRAGlobal()
545 AppendUsers(GV); in SRAGlobal()
560 assert(Ptr == GV && "Load/store must be from/to global"); in SRAGlobal()
586 GV->removeDeadConstantUsers(); in SRAGlobal()
587 GV->eraseFromParent(); in SRAGlobal()
650 static bool allUsesOfLoadedValueWillTrapIfNull(const GlobalVariable *GV) { in allUsesOfLoadedValueWillTrapIfNull() argument
652 Worklist.push_back(GV); in allUsesOfLoadedValueWillTrapIfNull()
665 if (CE->stripPointerCasts() != GV) in allUsesOfLoadedValueWillTrapIfNull()
680 static void allUsesOfLoadAndStores(GlobalVariable *GV, in allUsesOfLoadAndStores() argument
683 Worklist.push_back(GV); in allUsesOfLoadAndStores()
771 GlobalVariable *GV, Constant *LV, const DataLayout &DL, in OptimizeAwayTrappingUsesOfLoads() argument
780 for (User *GlobalUser : llvm::make_early_inc_range(GV->users())) { in OptimizeAwayTrappingUsesOfLoads()
792 assert(GlobalUser->getOperand(1) == GV && in OptimizeAwayTrappingUsesOfLoads()
808 LLVM_DEBUG(dbgs() << "OPTIMIZED LOADS FROM STORED ONCE POINTER: " << *GV in OptimizeAwayTrappingUsesOfLoads()
816 if (isLeakCheckerRoot(GV)) { in OptimizeAwayTrappingUsesOfLoads()
817 Changed |= CleanupPointerRootUsers(GV, GetTLI); in OptimizeAwayTrappingUsesOfLoads()
820 CleanupConstantGlobalUsers(GV, DL); in OptimizeAwayTrappingUsesOfLoads()
822 if (GV->use_empty()) { in OptimizeAwayTrappingUsesOfLoads()
825 GV->eraseFromParent(); in OptimizeAwayTrappingUsesOfLoads()
856 OptimizeGlobalAddressOfAllocation(GlobalVariable *GV, CallInst *CI, in OptimizeGlobalAddressOfAllocation() argument
860 LLVM_DEBUG(errs() << "PROMOTING GLOBAL: " << *GV << " CALL = " << *CI in OptimizeGlobalAddressOfAllocation()
864 Type *GlobalType = ArrayType::get(Type::getInt8Ty(GV->getContext()), in OptimizeGlobalAddressOfAllocation()
870 *GV->getParent(), GlobalType, false, GlobalValue::InternalLinkage, in OptimizeGlobalAddressOfAllocation()
871 UndefValue::get(GlobalType), GV->getName() + ".body", nullptr, in OptimizeGlobalAddressOfAllocation()
872 GV->getThreadLocalMode()); in OptimizeGlobalAddressOfAllocation()
909 new GlobalVariable(Type::getInt1Ty(GV->getContext()), false, in OptimizeGlobalAddressOfAllocation()
911 ConstantInt::getFalse(GV->getContext()), in OptimizeGlobalAddressOfAllocation()
912 GV->getName()+".init", GV->getThreadLocalMode()); in OptimizeGlobalAddressOfAllocation()
917 allUsesOfLoadAndStores(GV, Guses); in OptimizeGlobalAddressOfAllocation()
923 GV->getContext(), in OptimizeGlobalAddressOfAllocation()
950 LV = ConstantInt::getFalse(GV->getContext()); in OptimizeGlobalAddressOfAllocation()
953 LV = ConstantInt::getTrue(GV->getContext()); in OptimizeGlobalAddressOfAllocation()
975 GV->getParent()->getGlobalList().insert(GV->getIterator(), InitBool); in OptimizeGlobalAddressOfAllocation()
978 GV->eraseFromParent(); in OptimizeGlobalAddressOfAllocation()
995 const GlobalVariable *GV) { in valueIsOnlyUsedLocallyOrStoredToOneGlobal() argument
1012 SI->getPointerOperand()->stripPointerCasts() != GV) in valueIsOnlyUsedLocallyOrStoredToOneGlobal()
1038 static bool tryToOptimizeStoreOfAllocationToGlobal(GlobalVariable *GV, in tryToOptimizeStoreOfAllocationToGlobal() argument
1068 if (!allUsesOfLoadedValueWillTrapIfNull(GV)) in tryToOptimizeStoreOfAllocationToGlobal()
1075 if (!valueIsOnlyUsedLocallyOrStoredToOneGlobal(CI, GV)) in tryToOptimizeStoreOfAllocationToGlobal()
1078 OptimizeGlobalAddressOfAllocation(GV, CI, AllocSize, InitVal, DL, TLI); in tryToOptimizeStoreOfAllocationToGlobal()
1085 optimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, in optimizeOnceStoredGlobal() argument
1095 if (GV->getInitializer()->getType()->isPointerTy() && in optimizeOnceStoredGlobal()
1096 GV->getInitializer()->isNullValue() && in optimizeOnceStoredGlobal()
1100 GV->getInitializer()->getType()->getPointerAddressSpace())) { in optimizeOnceStoredGlobal()
1102 if (GV->getInitializer()->getType() != SOVC->getType()) in optimizeOnceStoredGlobal()
1103 SOVC = ConstantExpr::getBitCast(SOVC, GV->getInitializer()->getType()); in optimizeOnceStoredGlobal()
1106 if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC, DL, GetTLI)) in optimizeOnceStoredGlobal()
1111 if (tryToOptimizeStoreOfAllocationToGlobal(GV, CI, DL, TLI)) in optimizeOnceStoredGlobal()
1124 static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { in TryToShrinkGlobalToBoolean() argument
1125 Type *GVElType = GV->getValueType(); in TryToShrinkGlobalToBoolean()
1132 if (GVElType == Type::getInt1Ty(GV->getContext()) || in TryToShrinkGlobalToBoolean()
1139 for (User *U : GV->users()) { in TryToShrinkGlobalToBoolean()
1146 LLVM_DEBUG(dbgs() << " *** SHRINKING TO BOOL: " << *GV << "\n"); in TryToShrinkGlobalToBoolean()
1149 GlobalVariable *NewGV = new GlobalVariable(Type::getInt1Ty(GV->getContext()), in TryToShrinkGlobalToBoolean()
1152 ConstantInt::getFalse(GV->getContext()), in TryToShrinkGlobalToBoolean()
1153 GV->getName()+".b", in TryToShrinkGlobalToBoolean()
1154 GV->getThreadLocalMode(), in TryToShrinkGlobalToBoolean()
1155 GV->getType()->getAddressSpace()); in TryToShrinkGlobalToBoolean()
1156 NewGV->copyAttributesFrom(GV); in TryToShrinkGlobalToBoolean()
1157 GV->getParent()->getGlobalList().insert(GV->getIterator(), NewGV); in TryToShrinkGlobalToBoolean()
1159 Constant *InitVal = GV->getInitializer(); in TryToShrinkGlobalToBoolean()
1160 assert(InitVal->getType() != Type::getInt1Ty(GV->getContext()) && in TryToShrinkGlobalToBoolean()
1164 GV->getDebugInfo(GVs); in TryToShrinkGlobalToBoolean()
1174 auto *CIInit = dyn_cast<ConstantInt>(GV->getInitializer()); in TryToShrinkGlobalToBoolean()
1183 const DataLayout &DL = GV->getParent()->getDataLayout(); in TryToShrinkGlobalToBoolean()
1213 for(auto *GV : GVs) in TryToShrinkGlobalToBoolean() local
1214 NewGV->addDebugInfo(GV); in TryToShrinkGlobalToBoolean()
1217 while (!GV->use_empty()) { in TryToShrinkGlobalToBoolean()
1218 Instruction *UI = cast<Instruction>(GV->user_back()); in TryToShrinkGlobalToBoolean()
1225 StoreVal = ConstantInt::get(Type::getInt1Ty(GV->getContext()), in TryToShrinkGlobalToBoolean()
1237 assert(LI->getOperand(0) == GV && "Not a copy!"); in TryToShrinkGlobalToBoolean()
1276 NewGV->takeName(GV); in TryToShrinkGlobalToBoolean()
1277 GV->eraseFromParent(); in TryToShrinkGlobalToBoolean()
1282 deleteIfDead(GlobalValue &GV, in deleteIfDead() argument
1285 GV.removeDeadConstantUsers(); in deleteIfDead()
1287 if (!GV.isDiscardableIfUnused() && !GV.isDeclaration()) in deleteIfDead()
1290 if (const Comdat *C = GV.getComdat()) in deleteIfDead()
1291 if (!GV.hasLocalLinkage() && NotDiscardableComdats.count(C)) in deleteIfDead()
1295 if (auto *F = dyn_cast<Function>(&GV)) in deleteIfDead()
1298 Dead = GV.use_empty(); in deleteIfDead()
1302 LLVM_DEBUG(dbgs() << "GLOBAL DEAD: " << GV << "\n"); in deleteIfDead()
1303 if (auto *F = dyn_cast<Function>(&GV)) { in deleteIfDead()
1307 GV.eraseFromParent(); in deleteIfDead()
1313 const Function *F, GlobalValue *GV, in isPointerValueDeadOnEntryToFunction() argument
1325 const DataLayout &DL = GV->getParent()->getDataLayout(); in isPointerValueDeadOnEntryToFunction()
1328 for (auto *U : GV->users()) { in isPointerValueDeadOnEntryToFunction()
1450 GlobalVariable *GV, const StoreInst *StoredOnceStore, in forwardStoredOnceStore() argument
1460 for (User *U : GV->users()) { in forwardStoredOnceStore()
1485 processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS, in processInternalGlobal() argument
1489 auto &DL = GV->getParent()->getDataLayout(); in processInternalGlobal()
1500 GV->getValueType()->isSingleValueType() && in processInternalGlobal()
1501 GV->getType()->getAddressSpace() == 0 && in processInternalGlobal()
1502 !GV->isExternallyInitialized() && in processInternalGlobal()
1503 allNonInstructionUsersCanBeMadeInstructions(GV) && in processInternalGlobal()
1505 isPointerValueDeadOnEntryToFunction(GS.AccessingFunction, GV, in processInternalGlobal()
1507 const DataLayout &DL = GV->getParent()->getDataLayout(); in processInternalGlobal()
1509 LLVM_DEBUG(dbgs() << "LOCALIZING GLOBAL: " << *GV << "\n"); in processInternalGlobal()
1512 Type *ElemTy = GV->getValueType(); in processInternalGlobal()
1515 GV->getName(), &FirstI); in processInternalGlobal()
1516 if (!isa<UndefValue>(GV->getInitializer())) in processInternalGlobal()
1517 new StoreInst(GV->getInitializer(), Alloca, &FirstI); in processInternalGlobal()
1519 makeAllConstantUsesInstructions(GV); in processInternalGlobal()
1521 GV->replaceAllUsesWith(Alloca); in processInternalGlobal()
1522 GV->eraseFromParent(); in processInternalGlobal()
1532 LLVM_DEBUG(dbgs() << "GLOBAL NEVER LOADED: " << *GV << "\n"); in processInternalGlobal()
1534 if (isLeakCheckerRoot(GV)) { in processInternalGlobal()
1536 Changed = CleanupPointerRootUsers(GV, GetTLI); in processInternalGlobal()
1540 Changed = CleanupConstantGlobalUsers(GV, DL); in processInternalGlobal()
1544 if (GV->use_empty()) { in processInternalGlobal()
1545 GV->eraseFromParent(); in processInternalGlobal()
1553 LLVM_DEBUG(dbgs() << "MARKING CONSTANT: " << *GV << "\n"); in processInternalGlobal()
1559 assert(!GV->isConstant() && "Expected a non-constant global"); in processInternalGlobal()
1560 GV->setConstant(true); in processInternalGlobal()
1565 Changed |= CleanupConstantGlobalUsers(GV, DL); in processInternalGlobal()
1568 if (GV->use_empty()) { in processInternalGlobal()
1571 GV->eraseFromParent(); in processInternalGlobal()
1579 if (!GV->getInitializer()->getType()->isSingleValueType()) { in processInternalGlobal()
1580 const DataLayout &DL = GV->getParent()->getDataLayout(); in processInternalGlobal()
1581 if (SRAGlobal(GV, DL)) in processInternalGlobal()
1590 GV->getType()->getAddressSpace()); in processInternalGlobal()
1599 if (SOVConstant && isa<UndefValue>(GV->getInitializer()) && in processInternalGlobal()
1601 DL.getTypeAllocSize(GV->getValueType()) && in processInternalGlobal()
1603 if (SOVConstant->getType() == GV->getValueType()) { in processInternalGlobal()
1605 GV->setInitializer(SOVConstant); in processInternalGlobal()
1609 *GV->getParent(), SOVConstant->getType(), GV->isConstant(), in processInternalGlobal()
1610 GV->getLinkage(), SOVConstant, "", GV, GV->getThreadLocalMode(), in processInternalGlobal()
1611 GV->getAddressSpace()); in processInternalGlobal()
1612 NGV->takeName(GV); in processInternalGlobal()
1613 NGV->copyAttributesFrom(GV); in processInternalGlobal()
1614 GV->replaceAllUsesWith(ConstantExpr::getBitCast(NGV, GV->getType())); in processInternalGlobal()
1615 GV->eraseFromParent(); in processInternalGlobal()
1616 GV = NGV; in processInternalGlobal()
1620 CleanupConstantGlobalUsers(GV, DL); in processInternalGlobal()
1622 if (GV->use_empty()) { in processInternalGlobal()
1625 GV->eraseFromParent(); in processInternalGlobal()
1634 if (optimizeOnceStoredGlobal(GV, StoredOnceValue, DL, GetTLI)) in processInternalGlobal()
1640 if (forwardStoredOnceStore(GV, GS.StoredOnceStore, LookupDomTree)) in processInternalGlobal()
1646 (!isa<UndefValue>(GV->getInitializer()) || in processInternalGlobal()
1648 if (TryToShrinkGlobalToBoolean(GV, SOVConstant)) { in processInternalGlobal()
1661 processGlobal(GlobalValue &GV, in processGlobal() argument
1665 if (GV.getName().startswith("llvm.")) in processGlobal()
1670 if (GlobalStatus::analyzeGlobal(&GV, GS)) in processGlobal()
1674 if (!GS.IsCompared && !GV.hasGlobalUnnamedAddr()) { in processGlobal()
1675 auto NewUnnamedAddr = GV.hasLocalLinkage() ? GlobalValue::UnnamedAddr::Global in processGlobal()
1677 if (NewUnnamedAddr != GV.getUnnamedAddr()) { in processGlobal()
1678 GV.setUnnamedAddr(NewUnnamedAddr); in processGlobal()
1685 if (!GV.hasLocalLinkage()) in processGlobal()
1688 auto *GVar = dyn_cast<GlobalVariable>(&GV); in processGlobal()
2069 for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) { in OptimizeGlobalVars()
2071 if (!GV.hasName() && !GV.isDeclaration() && !GV.hasLocalLinkage()) in OptimizeGlobalVars()
2072 GV.setLinkage(GlobalValue::InternalLinkage); in OptimizeGlobalVars()
2074 if (GV.hasInitializer()) in OptimizeGlobalVars()
2075 if (auto *C = dyn_cast<Constant>(GV.getInitializer())) { in OptimizeGlobalVars()
2082 GV.setInitializer(New); in OptimizeGlobalVars()
2085 if (deleteIfDead(GV, NotDiscardableComdats)) { in OptimizeGlobalVars()
2090 Changed |= processGlobal(GV, GetTTI, GetTLI, LookupDomTree); in OptimizeGlobalVars()
2118 for (GlobalVariable *GV : Eval.getInvariants()) in EvaluateStaticConstructor()
2119 GV->setConstant(true); in EvaluateStaticConstructor()
2142 for (GlobalValue *GV : Init) { in setUsedInitializer()
2144 = ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, Int8PtrTy); in setUsedInitializer()
2197 bool usedCount(GlobalValue *GV) const { return Used.count(GV); } in usedCount()
2199 bool compilerUsedCount(GlobalValue *GV) const { in compilerUsedCount()
2200 return CompilerUsed.count(GV); in compilerUsedCount()
2203 bool usedErase(GlobalValue *GV) { return Used.erase(GV); } in usedErase() argument
2204 bool compilerUsedErase(GlobalValue *GV) { return CompilerUsed.erase(GV); } in compilerUsedErase() argument
2205 bool usedInsert(GlobalValue *GV) { return Used.insert(GV).second; } in usedInsert() argument
2207 bool compilerUsedInsert(GlobalValue *GV) { in compilerUsedInsert() argument
2208 return CompilerUsed.insert(GV).second; in compilerUsedInsert()
2293 for (GlobalValue *GV : Used.used()) in OptimizeGlobalAliases()
2294 Used.compilerUsedErase(GV); in OptimizeGlobalAliases()
2298 auto IsModuleLocal = [](GlobalValue &GV) { in OptimizeGlobalAliases() argument
2299 return !GlobalValue::isInterposableLinkage(GV.getLinkage()) && in OptimizeGlobalAliases()
2300 (GV.isDSOLocal() || GV.isImplicitDSOLocal()); in OptimizeGlobalAliases()
2471 for (const GlobalVariable &GV : M.globals()) in optimizeGlobalsInModule() local
2472 if (const Comdat *C = GV.getComdat()) in optimizeGlobalsInModule()
2473 if (!GV.isDiscardableIfUnused() || !GV.use_empty()) in optimizeGlobalsInModule()