Lines Matching refs:GV
111 static bool isLeakCheckerRoot(GlobalVariable *GV) { in isLeakCheckerRoot() argument
120 if (GV->hasPrivateLinkage()) in isLeakCheckerRoot()
124 Types.push_back(GV->getValueType()); in isLeakCheckerRoot()
192 CleanupPointerRootUsers(GlobalVariable *GV, in CleanupPointerRootUsers() argument
209 SmallVector<User *> Worklist(GV->users()); in CleanupPointerRootUsers()
263 GV->removeDeadConstantUsers(); in CleanupPointerRootUsers()
270 static bool CleanupConstantGlobalUsers(GlobalVariable *GV, in CleanupConstantGlobalUsers() argument
272 Constant *Init = GV->getInitializer(); in CleanupConstantGlobalUsers()
273 SmallVector<User *, 8> WorkList(GV->users()); in CleanupConstantGlobalUsers()
314 if (PtrOp == GV) { in CleanupConstantGlobalUsers()
324 if (getUnderlyingObject(MI->getRawDest()) == GV) in CleanupConstantGlobalUsers()
334 GV->removeDeadConstantUsers(); in CleanupConstantGlobalUsers()
350 GlobalVariable *GV, const DataLayout &DL) { in collectSRATypes() argument
358 AppendUses(GV); in collectSRATypes()
379 if (Ptr != GV || Offset.getActiveBits() >= 64) in collectSRATypes()
392 ConstantFoldLoadFromConst(GV->getInitializer(), Ty, Offset, DL); in collectSRATypes()
395 << *GV << " with type " << *Ty << " at offset " in collectSRATypes()
438 static void transferSRADebugInfo(GlobalVariable *GV, GlobalVariable *NGV, in transferSRADebugInfo() argument
443 GV->getDebugInfo(GVs); in transferSRADebugInfo()
518 static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) { in SRAGlobal() argument
519 assert(GV->hasLocalLinkage()); in SRAGlobal()
523 if (!collectSRATypes(Parts, GV, DL) || Parts.empty()) in SRAGlobal()
527 if (Parts.size() == 1 && Parts.begin()->second.Ty == GV->getValueType()) in SRAGlobal()
558 if (Offset > DL.getTypeAllocSize(GV->getValueType())) in SRAGlobal()
561 LLVM_DEBUG(dbgs() << "PERFORMING GLOBAL SRA ON: " << *GV << "\n"); in SRAGlobal()
565 DL.getValueOrABITypeAlignment(GV->getAlign(), GV->getValueType()); in SRAGlobal()
566 uint64_t VarSize = DL.getTypeSizeInBits(GV->getValueType()); in SRAGlobal()
573 *GV->getParent(), Ty, false, GlobalVariable::InternalLinkage, in SRAGlobal()
574 Initializer, GV->getName() + "." + Twine(NameSuffix++), GV, in SRAGlobal()
575 GV->getThreadLocalMode(), GV->getAddressSpace()); in SRAGlobal()
576 NGV->copyAttributesFrom(GV); in SRAGlobal()
587 transferSRADebugInfo(GV, NGV, OffsetForTy * 8, in SRAGlobal()
600 AppendUsers(GV); in SRAGlobal()
615 assert(Ptr == GV && "Load/store must be from/to global"); in SRAGlobal()
641 GV->removeDeadConstantUsers(); in SRAGlobal()
642 GV->eraseFromParent(); in SRAGlobal()
706 static bool allUsesOfLoadedValueWillTrapIfNull(const GlobalVariable *GV) { in allUsesOfLoadedValueWillTrapIfNull() argument
708 Worklist.push_back(GV); in allUsesOfLoadedValueWillTrapIfNull()
721 if (CE->stripPointerCasts() != GV) in allUsesOfLoadedValueWillTrapIfNull()
736 static void allUsesOfLoadAndStores(GlobalVariable *GV, in allUsesOfLoadAndStores() argument
739 Worklist.push_back(GV); in allUsesOfLoadAndStores()
826 GlobalVariable *GV, Constant *LV, const DataLayout &DL, in OptimizeAwayTrappingUsesOfLoads() argument
835 for (User *GlobalUser : llvm::make_early_inc_range(GV->users())) { in OptimizeAwayTrappingUsesOfLoads()
847 assert(GlobalUser->getOperand(1) == GV && in OptimizeAwayTrappingUsesOfLoads()
864 LLVM_DEBUG(dbgs() << "OPTIMIZED LOADS FROM STORED ONCE POINTER: " << *GV in OptimizeAwayTrappingUsesOfLoads()
872 if (isLeakCheckerRoot(GV)) { in OptimizeAwayTrappingUsesOfLoads()
873 Changed |= CleanupPointerRootUsers(GV, GetTLI); in OptimizeAwayTrappingUsesOfLoads()
876 CleanupConstantGlobalUsers(GV, DL); in OptimizeAwayTrappingUsesOfLoads()
878 if (GV->use_empty()) { in OptimizeAwayTrappingUsesOfLoads()
881 GV->eraseFromParent(); in OptimizeAwayTrappingUsesOfLoads()
912 OptimizeGlobalAddressOfAllocation(GlobalVariable *GV, CallInst *CI, in OptimizeGlobalAddressOfAllocation() argument
916 LLVM_DEBUG(errs() << "PROMOTING GLOBAL: " << *GV << " CALL = " << *CI in OptimizeGlobalAddressOfAllocation()
920 Type *GlobalType = ArrayType::get(Type::getInt8Ty(GV->getContext()), in OptimizeGlobalAddressOfAllocation()
926 *GV->getParent(), GlobalType, false, GlobalValue::InternalLinkage, in OptimizeGlobalAddressOfAllocation()
927 UndefValue::get(GlobalType), GV->getName() + ".body", nullptr, in OptimizeGlobalAddressOfAllocation()
928 GV->getThreadLocalMode()); in OptimizeGlobalAddressOfAllocation()
947 new GlobalVariable(Type::getInt1Ty(GV->getContext()), false, in OptimizeGlobalAddressOfAllocation()
949 ConstantInt::getFalse(GV->getContext()), in OptimizeGlobalAddressOfAllocation()
950 GV->getName()+".init", GV->getThreadLocalMode()); in OptimizeGlobalAddressOfAllocation()
955 allUsesOfLoadAndStores(GV, Guses); in OptimizeGlobalAddressOfAllocation()
961 GV->getContext(), in OptimizeGlobalAddressOfAllocation()
987 LV = ConstantInt::getFalse(GV->getContext()); in OptimizeGlobalAddressOfAllocation()
990 LV = ConstantInt::getTrue(GV->getContext()); in OptimizeGlobalAddressOfAllocation()
1012 GV->getParent()->insertGlobalVariable(GV->getIterator(), InitBool); in OptimizeGlobalAddressOfAllocation()
1015 GV->eraseFromParent(); in OptimizeGlobalAddressOfAllocation()
1031 const GlobalVariable *GV) { in valueIsOnlyUsedLocallyOrStoredToOneGlobal() argument
1048 SI->getPointerOperand()->stripPointerCasts() != GV) in valueIsOnlyUsedLocallyOrStoredToOneGlobal()
1074 static bool tryToOptimizeStoreOfAllocationToGlobal(GlobalVariable *GV, in tryToOptimizeStoreOfAllocationToGlobal() argument
1104 if (!allUsesOfLoadedValueWillTrapIfNull(GV)) in tryToOptimizeStoreOfAllocationToGlobal()
1111 if (!valueIsOnlyUsedLocallyOrStoredToOneGlobal(CI, GV)) in tryToOptimizeStoreOfAllocationToGlobal()
1114 OptimizeGlobalAddressOfAllocation(GV, CI, AllocSize, InitVal, DL, TLI); in tryToOptimizeStoreOfAllocationToGlobal()
1121 optimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, in optimizeOnceStoredGlobal() argument
1131 if (GV->getInitializer()->getType()->isPointerTy() && in optimizeOnceStoredGlobal()
1132 GV->getInitializer()->isNullValue() && in optimizeOnceStoredGlobal()
1136 GV->getInitializer()->getType()->getPointerAddressSpace())) { in optimizeOnceStoredGlobal()
1139 if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC, DL, GetTLI)) in optimizeOnceStoredGlobal()
1144 if (tryToOptimizeStoreOfAllocationToGlobal(GV, CI, DL, TLI)) in optimizeOnceStoredGlobal()
1157 static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { in TryToShrinkGlobalToBoolean() argument
1158 Type *GVElType = GV->getValueType(); in TryToShrinkGlobalToBoolean()
1165 if (GVElType == Type::getInt1Ty(GV->getContext()) || in TryToShrinkGlobalToBoolean()
1172 for (User *U : GV->users()) { in TryToShrinkGlobalToBoolean()
1179 LLVM_DEBUG(dbgs() << " *** SHRINKING TO BOOL: " << *GV << "\n"); in TryToShrinkGlobalToBoolean()
1182 GlobalVariable *NewGV = new GlobalVariable(Type::getInt1Ty(GV->getContext()), in TryToShrinkGlobalToBoolean()
1185 ConstantInt::getFalse(GV->getContext()), in TryToShrinkGlobalToBoolean()
1186 GV->getName()+".b", in TryToShrinkGlobalToBoolean()
1187 GV->getThreadLocalMode(), in TryToShrinkGlobalToBoolean()
1188 GV->getType()->getAddressSpace()); in TryToShrinkGlobalToBoolean()
1189 NewGV->copyAttributesFrom(GV); in TryToShrinkGlobalToBoolean()
1190 GV->getParent()->insertGlobalVariable(GV->getIterator(), NewGV); in TryToShrinkGlobalToBoolean()
1192 Constant *InitVal = GV->getInitializer(); in TryToShrinkGlobalToBoolean()
1193 assert(InitVal->getType() != Type::getInt1Ty(GV->getContext()) && in TryToShrinkGlobalToBoolean()
1197 GV->getDebugInfo(GVs); in TryToShrinkGlobalToBoolean()
1207 auto *CIInit = dyn_cast<ConstantInt>(GV->getInitializer()); in TryToShrinkGlobalToBoolean()
1216 const DataLayout &DL = GV->getDataLayout(); in TryToShrinkGlobalToBoolean()
1246 for(auto *GV : GVs) in TryToShrinkGlobalToBoolean() local
1247 NewGV->addDebugInfo(GV); in TryToShrinkGlobalToBoolean()
1250 while (!GV->use_empty()) { in TryToShrinkGlobalToBoolean()
1251 Instruction *UI = cast<Instruction>(GV->user_back()); in TryToShrinkGlobalToBoolean()
1258 StoreVal = ConstantInt::get(Type::getInt1Ty(GV->getContext()), in TryToShrinkGlobalToBoolean()
1270 assert(LI->getOperand(0) == GV && "Not a copy!"); in TryToShrinkGlobalToBoolean()
1310 NewGV->takeName(GV); in TryToShrinkGlobalToBoolean()
1311 GV->eraseFromParent(); in TryToShrinkGlobalToBoolean()
1316 deleteIfDead(GlobalValue &GV, in deleteIfDead() argument
1319 GV.removeDeadConstantUsers(); in deleteIfDead()
1321 if (!GV.isDiscardableIfUnused() && !GV.isDeclaration()) in deleteIfDead()
1324 if (const Comdat *C = GV.getComdat()) in deleteIfDead()
1325 if (!GV.hasLocalLinkage() && NotDiscardableComdats.count(C)) in deleteIfDead()
1329 if (auto *F = dyn_cast<Function>(&GV)) in deleteIfDead()
1332 Dead = GV.use_empty(); in deleteIfDead()
1336 LLVM_DEBUG(dbgs() << "GLOBAL DEAD: " << GV << "\n"); in deleteIfDead()
1337 if (auto *F = dyn_cast<Function>(&GV)) { in deleteIfDead()
1341 GV.eraseFromParent(); in deleteIfDead()
1347 const Function *F, GlobalValue *GV, in isPointerValueDeadOnEntryToFunction() argument
1359 const DataLayout &DL = GV->getDataLayout(); in isPointerValueDeadOnEntryToFunction()
1362 for (auto *U : GV->users()) { in isPointerValueDeadOnEntryToFunction()
1416 GlobalVariable *GV, const StoreInst *StoredOnceStore, in forwardStoredOnceStore() argument
1426 for (User *U : GV->users()) { in forwardStoredOnceStore()
1451 processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS, in processInternalGlobal() argument
1455 auto &DL = GV->getDataLayout(); in processInternalGlobal()
1466 GV->getValueType()->isSingleValueType() && in processInternalGlobal()
1467 GV->getType()->getAddressSpace() == DL.getAllocaAddrSpace() && in processInternalGlobal()
1468 !GV->isExternallyInitialized() && in processInternalGlobal()
1470 isPointerValueDeadOnEntryToFunction(GS.AccessingFunction, GV, in processInternalGlobal()
1472 const DataLayout &DL = GV->getDataLayout(); in processInternalGlobal()
1474 LLVM_DEBUG(dbgs() << "LOCALIZING GLOBAL: " << *GV << "\n"); in processInternalGlobal()
1477 Type *ElemTy = GV->getValueType(); in processInternalGlobal()
1480 nullptr, GV->getName(), FirstI); in processInternalGlobal()
1481 if (!isa<UndefValue>(GV->getInitializer())) in processInternalGlobal()
1482 new StoreInst(GV->getInitializer(), Alloca, FirstI); in processInternalGlobal()
1484 GV->replaceAllUsesWith(Alloca); in processInternalGlobal()
1485 GV->eraseFromParent(); in processInternalGlobal()
1495 LLVM_DEBUG(dbgs() << "GLOBAL NEVER LOADED: " << *GV << "\n"); in processInternalGlobal()
1497 if (isLeakCheckerRoot(GV)) { in processInternalGlobal()
1499 Changed = CleanupPointerRootUsers(GV, GetTLI); in processInternalGlobal()
1503 Changed = CleanupConstantGlobalUsers(GV, DL); in processInternalGlobal()
1507 if (GV->use_empty()) { in processInternalGlobal()
1508 GV->eraseFromParent(); in processInternalGlobal()
1516 LLVM_DEBUG(dbgs() << "MARKING CONSTANT: " << *GV << "\n"); in processInternalGlobal()
1522 assert(!GV->isConstant() && "Expected a non-constant global"); in processInternalGlobal()
1523 GV->setConstant(true); in processInternalGlobal()
1528 Changed |= CleanupConstantGlobalUsers(GV, DL); in processInternalGlobal()
1531 if (GV->use_empty()) { in processInternalGlobal()
1534 GV->eraseFromParent(); in processInternalGlobal()
1542 if (!GV->getInitializer()->getType()->isSingleValueType()) { in processInternalGlobal()
1543 const DataLayout &DL = GV->getDataLayout(); in processInternalGlobal()
1544 if (SRAGlobal(GV, DL)) in processInternalGlobal()
1553 GV->getType()->getAddressSpace()); in processInternalGlobal()
1562 if (SOVConstant && isa<UndefValue>(GV->getInitializer()) && in processInternalGlobal()
1564 DL.getTypeAllocSize(GV->getValueType()) && in processInternalGlobal()
1566 if (SOVConstant->getType() == GV->getValueType()) { in processInternalGlobal()
1568 GV->setInitializer(SOVConstant); in processInternalGlobal()
1572 *GV->getParent(), SOVConstant->getType(), GV->isConstant(), in processInternalGlobal()
1573 GV->getLinkage(), SOVConstant, "", GV, GV->getThreadLocalMode(), in processInternalGlobal()
1574 GV->getAddressSpace()); in processInternalGlobal()
1575 NGV->takeName(GV); in processInternalGlobal()
1576 NGV->copyAttributesFrom(GV); in processInternalGlobal()
1577 GV->replaceAllUsesWith(NGV); in processInternalGlobal()
1578 GV->eraseFromParent(); in processInternalGlobal()
1579 GV = NGV; in processInternalGlobal()
1583 CleanupConstantGlobalUsers(GV, DL); in processInternalGlobal()
1585 if (GV->use_empty()) { in processInternalGlobal()
1588 GV->eraseFromParent(); in processInternalGlobal()
1597 if (optimizeOnceStoredGlobal(GV, StoredOnceValue, DL, GetTLI)) in processInternalGlobal()
1603 if (forwardStoredOnceStore(GV, GS.StoredOnceStore, LookupDomTree)) in processInternalGlobal()
1609 (!isa<UndefValue>(GV->getInitializer()) || in processInternalGlobal()
1611 if (TryToShrinkGlobalToBoolean(GV, SOVConstant)) { in processInternalGlobal()
1624 processGlobal(GlobalValue &GV, in processGlobal() argument
1628 if (GV.getName().starts_with("llvm.")) in processGlobal()
1633 if (GlobalStatus::analyzeGlobal(&GV, GS)) in processGlobal()
1637 if (!GS.IsCompared && !GV.hasGlobalUnnamedAddr()) { in processGlobal()
1638 auto NewUnnamedAddr = GV.hasLocalLinkage() ? GlobalValue::UnnamedAddr::Global in processGlobal()
1640 if (NewUnnamedAddr != GV.getUnnamedAddr()) { in processGlobal()
1641 GV.setUnnamedAddr(NewUnnamedAddr); in processGlobal()
1648 if (!GV.hasLocalLinkage()) in processGlobal()
1651 auto *GVar = dyn_cast<GlobalVariable>(&GV); in processGlobal()
2044 for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) { in OptimizeGlobalVars()
2046 if (!GV.hasName() && !GV.isDeclaration() && !GV.hasLocalLinkage()) in OptimizeGlobalVars()
2047 GV.setLinkage(GlobalValue::InternalLinkage); in OptimizeGlobalVars()
2049 if (GV.hasInitializer()) in OptimizeGlobalVars()
2050 if (auto *C = dyn_cast<Constant>(GV.getInitializer())) { in OptimizeGlobalVars()
2057 GV.setInitializer(New); in OptimizeGlobalVars()
2060 if (deleteIfDead(GV, NotDiscardableComdats)) { in OptimizeGlobalVars()
2065 Changed |= processGlobal(GV, GetTTI, GetTLI, LookupDomTree); in OptimizeGlobalVars()
2093 for (GlobalVariable *GV : Eval.getInvariants()) in EvaluateStaticConstructor()
2094 GV->setConstant(true); in EvaluateStaticConstructor()
2123 for (GlobalValue *GV : Init) { in setUsedInitializer()
2124 Constant *Cast = ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, PtrTy); in setUsedInitializer()
2178 bool usedCount(GlobalValue *GV) const { return Used.count(GV); } in usedCount()
2180 bool compilerUsedCount(GlobalValue *GV) const { in compilerUsedCount()
2181 return CompilerUsed.count(GV); in compilerUsedCount()
2184 bool usedErase(GlobalValue *GV) { return Used.erase(GV); } in usedErase() argument
2185 bool compilerUsedErase(GlobalValue *GV) { return CompilerUsed.erase(GV); } in compilerUsedErase() argument
2186 bool usedInsert(GlobalValue *GV) { return Used.insert(GV).second; } in usedInsert() argument
2188 bool compilerUsedInsert(GlobalValue *GV) { in compilerUsedInsert() argument
2189 return CompilerUsed.insert(GV).second; in compilerUsedInsert()
2218 static bool mayHaveOtherReferences(GlobalValue &GV, const LLVMUsed &U) { in mayHaveOtherReferences() argument
2219 if (!GV.hasLocalLinkage()) in mayHaveOtherReferences()
2222 return U.usedCount(&GV) || U.compilerUsedCount(&GV); in mayHaveOtherReferences()
2261 for (GlobalValue *GV : Used.used()) in OptimizeGlobalAliases()
2262 Used.compilerUsedErase(GV); in OptimizeGlobalAliases()
2266 auto IsModuleLocal = [](GlobalValue &GV) { in OptimizeGlobalAliases() argument
2267 return !GlobalValue::isInterposableLinkage(GV.getLinkage()) && in OptimizeGlobalAliases()
2268 (GV.isDSOLocal() || GV.isImplicitDSOLocal()); in OptimizeGlobalAliases()
2500 for (const GlobalVariable &GV : M.globals()) in optimizeGlobalsInModule() local
2501 if (const Comdat *C = GV.getComdat()) in optimizeGlobalsInModule()
2502 if (!GV.isDiscardableIfUnused() || !GV.use_empty()) in optimizeGlobalsInModule()