Lines Matching refs:GV

108 static bool isLeakCheckerRoot(GlobalVariable *GV) {  in isLeakCheckerRoot()  argument
117 if (GV->hasPrivateLinkage()) in isLeakCheckerRoot()
121 Types.push_back(GV->getValueType()); in isLeakCheckerRoot()
189 CleanupPointerRootUsers(GlobalVariable *GV, in CleanupPointerRootUsers() argument
206 SmallVector<User *> Worklist(GV->users()); in CleanupPointerRootUsers()
260 GV->removeDeadConstantUsers(); in CleanupPointerRootUsers()
267 static bool CleanupConstantGlobalUsers(GlobalVariable *GV, in CleanupConstantGlobalUsers() argument
269 Constant *Init = GV->getInitializer(); in CleanupConstantGlobalUsers()
270 SmallVector<User *, 8> WorkList(GV->users()); in CleanupConstantGlobalUsers()
307 if (PtrOp == GV) { in CleanupConstantGlobalUsers()
317 if (getUnderlyingObject(MI->getRawDest()) == GV) in CleanupConstantGlobalUsers()
324 GV->removeDeadConstantUsers(); in CleanupConstantGlobalUsers()
340 GlobalVariable *GV, const DataLayout &DL) { in collectSRATypes() argument
348 AppendUses(GV); in collectSRATypes()
369 if (Ptr != GV || Offset.getActiveBits() >= 64) in collectSRATypes()
382 ConstantFoldLoadFromConst(GV->getInitializer(), Ty, Offset, DL); in collectSRATypes()
385 << *GV << " with type " << *Ty << " at offset " in collectSRATypes()
428 static void transferSRADebugInfo(GlobalVariable *GV, GlobalVariable *NGV, in transferSRADebugInfo() argument
433 GV->getDebugInfo(GVs); in transferSRADebugInfo()
508 static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) { in SRAGlobal() argument
509 assert(GV->hasLocalLinkage()); in SRAGlobal()
513 if (!collectSRATypes(Parts, GV, DL) || Parts.empty()) in SRAGlobal()
517 if (Parts.size() == 1 && Parts.begin()->second.Ty == GV->getValueType()) in SRAGlobal()
548 if (Offset > DL.getTypeAllocSize(GV->getValueType())) in SRAGlobal()
551 LLVM_DEBUG(dbgs() << "PERFORMING GLOBAL SRA ON: " << *GV << "\n"); in SRAGlobal()
555 DL.getValueOrABITypeAlignment(GV->getAlign(), GV->getValueType()); in SRAGlobal()
556 uint64_t VarSize = DL.getTypeSizeInBits(GV->getValueType()); in SRAGlobal()
563 *GV->getParent(), Ty, false, GlobalVariable::InternalLinkage, in SRAGlobal()
564 Initializer, GV->getName() + "." + Twine(NameSuffix++), GV, in SRAGlobal()
565 GV->getThreadLocalMode(), GV->getAddressSpace()); in SRAGlobal()
566 NGV->copyAttributesFrom(GV); in SRAGlobal()
577 transferSRADebugInfo(GV, NGV, OffsetForTy * 8, in SRAGlobal()
590 AppendUsers(GV); in SRAGlobal()
605 assert(Ptr == GV && "Load/store must be from/to global"); in SRAGlobal()
631 GV->removeDeadConstantUsers(); in SRAGlobal()
632 GV->eraseFromParent(); in SRAGlobal()
696 static bool allUsesOfLoadedValueWillTrapIfNull(const GlobalVariable *GV) { in allUsesOfLoadedValueWillTrapIfNull() argument
698 Worklist.push_back(GV); in allUsesOfLoadedValueWillTrapIfNull()
711 if (CE->stripPointerCasts() != GV) in allUsesOfLoadedValueWillTrapIfNull()
726 static void allUsesOfLoadAndStores(GlobalVariable *GV, in allUsesOfLoadAndStores() argument
729 Worklist.push_back(GV); in allUsesOfLoadAndStores()
816 GlobalVariable *GV, Constant *LV, const DataLayout &DL, in OptimizeAwayTrappingUsesOfLoads() argument
825 for (User *GlobalUser : llvm::make_early_inc_range(GV->users())) { in OptimizeAwayTrappingUsesOfLoads()
837 assert(GlobalUser->getOperand(1) == GV && in OptimizeAwayTrappingUsesOfLoads()
854 LLVM_DEBUG(dbgs() << "OPTIMIZED LOADS FROM STORED ONCE POINTER: " << *GV in OptimizeAwayTrappingUsesOfLoads()
862 if (isLeakCheckerRoot(GV)) { in OptimizeAwayTrappingUsesOfLoads()
863 Changed |= CleanupPointerRootUsers(GV, GetTLI); in OptimizeAwayTrappingUsesOfLoads()
866 CleanupConstantGlobalUsers(GV, DL); in OptimizeAwayTrappingUsesOfLoads()
868 if (GV->use_empty()) { in OptimizeAwayTrappingUsesOfLoads()
871 GV->eraseFromParent(); in OptimizeAwayTrappingUsesOfLoads()
902 OptimizeGlobalAddressOfAllocation(GlobalVariable *GV, CallInst *CI, in OptimizeGlobalAddressOfAllocation() argument
906 LLVM_DEBUG(errs() << "PROMOTING GLOBAL: " << *GV << " CALL = " << *CI in OptimizeGlobalAddressOfAllocation()
910 Type *GlobalType = ArrayType::get(Type::getInt8Ty(GV->getContext()), in OptimizeGlobalAddressOfAllocation()
916 *GV->getParent(), GlobalType, false, GlobalValue::InternalLinkage, in OptimizeGlobalAddressOfAllocation()
917 UndefValue::get(GlobalType), GV->getName() + ".body", nullptr, in OptimizeGlobalAddressOfAllocation()
918 GV->getThreadLocalMode()); in OptimizeGlobalAddressOfAllocation()
937 new GlobalVariable(Type::getInt1Ty(GV->getContext()), false, in OptimizeGlobalAddressOfAllocation()
939 ConstantInt::getFalse(GV->getContext()), in OptimizeGlobalAddressOfAllocation()
940 GV->getName()+".init", GV->getThreadLocalMode()); in OptimizeGlobalAddressOfAllocation()
945 allUsesOfLoadAndStores(GV, Guses); in OptimizeGlobalAddressOfAllocation()
951 GV->getContext(), in OptimizeGlobalAddressOfAllocation()
976 LV = ConstantInt::getFalse(GV->getContext()); in OptimizeGlobalAddressOfAllocation()
979 LV = ConstantInt::getTrue(GV->getContext()); in OptimizeGlobalAddressOfAllocation()
1001 GV->getParent()->insertGlobalVariable(GV->getIterator(), InitBool); in OptimizeGlobalAddressOfAllocation()
1004 GV->eraseFromParent(); in OptimizeGlobalAddressOfAllocation()
1020 const GlobalVariable *GV) { in valueIsOnlyUsedLocallyOrStoredToOneGlobal() argument
1037 SI->getPointerOperand()->stripPointerCasts() != GV) in valueIsOnlyUsedLocallyOrStoredToOneGlobal()
1063 static bool tryToOptimizeStoreOfAllocationToGlobal(GlobalVariable *GV, in tryToOptimizeStoreOfAllocationToGlobal() argument
1093 if (!allUsesOfLoadedValueWillTrapIfNull(GV)) in tryToOptimizeStoreOfAllocationToGlobal()
1100 if (!valueIsOnlyUsedLocallyOrStoredToOneGlobal(CI, GV)) in tryToOptimizeStoreOfAllocationToGlobal()
1103 OptimizeGlobalAddressOfAllocation(GV, CI, AllocSize, InitVal, DL, TLI); in tryToOptimizeStoreOfAllocationToGlobal()
1110 optimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, in optimizeOnceStoredGlobal() argument
1120 if (GV->getInitializer()->getType()->isPointerTy() && in optimizeOnceStoredGlobal()
1121 GV->getInitializer()->isNullValue() && in optimizeOnceStoredGlobal()
1125 GV->getInitializer()->getType()->getPointerAddressSpace())) { in optimizeOnceStoredGlobal()
1128 if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC, DL, GetTLI)) in optimizeOnceStoredGlobal()
1133 if (tryToOptimizeStoreOfAllocationToGlobal(GV, CI, DL, TLI)) in optimizeOnceStoredGlobal()
1146 static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { in TryToShrinkGlobalToBoolean() argument
1147 Type *GVElType = GV->getValueType(); in TryToShrinkGlobalToBoolean()
1154 if (GVElType == Type::getInt1Ty(GV->getContext()) || in TryToShrinkGlobalToBoolean()
1161 for (User *U : GV->users()) { in TryToShrinkGlobalToBoolean()
1168 LLVM_DEBUG(dbgs() << " *** SHRINKING TO BOOL: " << *GV << "\n"); in TryToShrinkGlobalToBoolean()
1171 GlobalVariable *NewGV = new GlobalVariable(Type::getInt1Ty(GV->getContext()), in TryToShrinkGlobalToBoolean()
1174 ConstantInt::getFalse(GV->getContext()), in TryToShrinkGlobalToBoolean()
1175 GV->getName()+".b", in TryToShrinkGlobalToBoolean()
1176 GV->getThreadLocalMode(), in TryToShrinkGlobalToBoolean()
1177 GV->getType()->getAddressSpace()); in TryToShrinkGlobalToBoolean()
1178 NewGV->copyAttributesFrom(GV); in TryToShrinkGlobalToBoolean()
1179 GV->getParent()->insertGlobalVariable(GV->getIterator(), NewGV); in TryToShrinkGlobalToBoolean()
1181 Constant *InitVal = GV->getInitializer(); in TryToShrinkGlobalToBoolean()
1182 assert(InitVal->getType() != Type::getInt1Ty(GV->getContext()) && in TryToShrinkGlobalToBoolean()
1186 GV->getDebugInfo(GVs); in TryToShrinkGlobalToBoolean()
1196 auto *CIInit = dyn_cast<ConstantInt>(GV->getInitializer()); in TryToShrinkGlobalToBoolean()
1205 const DataLayout &DL = GV->getParent()->getDataLayout(); in TryToShrinkGlobalToBoolean()
1235 for(auto *GV : GVs) in TryToShrinkGlobalToBoolean() local
1236 NewGV->addDebugInfo(GV); in TryToShrinkGlobalToBoolean()
1239 while (!GV->use_empty()) { in TryToShrinkGlobalToBoolean()
1240 Instruction *UI = cast<Instruction>(GV->user_back()); in TryToShrinkGlobalToBoolean()
1247 StoreVal = ConstantInt::get(Type::getInt1Ty(GV->getContext()), in TryToShrinkGlobalToBoolean()
1259 assert(LI->getOperand(0) == GV && "Not a copy!"); in TryToShrinkGlobalToBoolean()
1298 NewGV->takeName(GV); in TryToShrinkGlobalToBoolean()
1299 GV->eraseFromParent(); in TryToShrinkGlobalToBoolean()
1304 deleteIfDead(GlobalValue &GV, in deleteIfDead() argument
1307 GV.removeDeadConstantUsers(); in deleteIfDead()
1309 if (!GV.isDiscardableIfUnused() && !GV.isDeclaration()) in deleteIfDead()
1312 if (const Comdat *C = GV.getComdat()) in deleteIfDead()
1313 if (!GV.hasLocalLinkage() && NotDiscardableComdats.count(C)) in deleteIfDead()
1317 if (auto *F = dyn_cast<Function>(&GV)) in deleteIfDead()
1320 Dead = GV.use_empty(); in deleteIfDead()
1324 LLVM_DEBUG(dbgs() << "GLOBAL DEAD: " << GV << "\n"); in deleteIfDead()
1325 if (auto *F = dyn_cast<Function>(&GV)) { in deleteIfDead()
1329 GV.eraseFromParent(); in deleteIfDead()
1335 const Function *F, GlobalValue *GV, in isPointerValueDeadOnEntryToFunction() argument
1347 const DataLayout &DL = GV->getParent()->getDataLayout(); in isPointerValueDeadOnEntryToFunction()
1350 for (auto *U : GV->users()) { in isPointerValueDeadOnEntryToFunction()
1404 GlobalVariable *GV, const StoreInst *StoredOnceStore, in forwardStoredOnceStore() argument
1414 for (User *U : GV->users()) { in forwardStoredOnceStore()
1439 processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS, in processInternalGlobal() argument
1443 auto &DL = GV->getParent()->getDataLayout(); in processInternalGlobal()
1454 GV->getValueType()->isSingleValueType() && in processInternalGlobal()
1455 GV->getType()->getAddressSpace() == DL.getAllocaAddrSpace() && in processInternalGlobal()
1456 !GV->isExternallyInitialized() && in processInternalGlobal()
1458 isPointerValueDeadOnEntryToFunction(GS.AccessingFunction, GV, in processInternalGlobal()
1460 const DataLayout &DL = GV->getParent()->getDataLayout(); in processInternalGlobal()
1462 LLVM_DEBUG(dbgs() << "LOCALIZING GLOBAL: " << *GV << "\n"); in processInternalGlobal()
1465 Type *ElemTy = GV->getValueType(); in processInternalGlobal()
1468 GV->getName(), &FirstI); in processInternalGlobal()
1469 if (!isa<UndefValue>(GV->getInitializer())) in processInternalGlobal()
1470 new StoreInst(GV->getInitializer(), Alloca, &FirstI); in processInternalGlobal()
1472 GV->replaceAllUsesWith(Alloca); in processInternalGlobal()
1473 GV->eraseFromParent(); in processInternalGlobal()
1483 LLVM_DEBUG(dbgs() << "GLOBAL NEVER LOADED: " << *GV << "\n"); in processInternalGlobal()
1485 if (isLeakCheckerRoot(GV)) { in processInternalGlobal()
1487 Changed = CleanupPointerRootUsers(GV, GetTLI); in processInternalGlobal()
1491 Changed = CleanupConstantGlobalUsers(GV, DL); in processInternalGlobal()
1495 if (GV->use_empty()) { in processInternalGlobal()
1496 GV->eraseFromParent(); in processInternalGlobal()
1504 LLVM_DEBUG(dbgs() << "MARKING CONSTANT: " << *GV << "\n"); in processInternalGlobal()
1510 assert(!GV->isConstant() && "Expected a non-constant global"); in processInternalGlobal()
1511 GV->setConstant(true); in processInternalGlobal()
1516 Changed |= CleanupConstantGlobalUsers(GV, DL); in processInternalGlobal()
1519 if (GV->use_empty()) { in processInternalGlobal()
1522 GV->eraseFromParent(); in processInternalGlobal()
1530 if (!GV->getInitializer()->getType()->isSingleValueType()) { in processInternalGlobal()
1531 const DataLayout &DL = GV->getParent()->getDataLayout(); in processInternalGlobal()
1532 if (SRAGlobal(GV, DL)) in processInternalGlobal()
1541 GV->getType()->getAddressSpace()); in processInternalGlobal()
1550 if (SOVConstant && isa<UndefValue>(GV->getInitializer()) && in processInternalGlobal()
1552 DL.getTypeAllocSize(GV->getValueType()) && in processInternalGlobal()
1554 if (SOVConstant->getType() == GV->getValueType()) { in processInternalGlobal()
1556 GV->setInitializer(SOVConstant); in processInternalGlobal()
1560 *GV->getParent(), SOVConstant->getType(), GV->isConstant(), in processInternalGlobal()
1561 GV->getLinkage(), SOVConstant, "", GV, GV->getThreadLocalMode(), in processInternalGlobal()
1562 GV->getAddressSpace()); in processInternalGlobal()
1563 NGV->takeName(GV); in processInternalGlobal()
1564 NGV->copyAttributesFrom(GV); in processInternalGlobal()
1565 GV->replaceAllUsesWith(NGV); in processInternalGlobal()
1566 GV->eraseFromParent(); in processInternalGlobal()
1567 GV = NGV; in processInternalGlobal()
1571 CleanupConstantGlobalUsers(GV, DL); in processInternalGlobal()
1573 if (GV->use_empty()) { in processInternalGlobal()
1576 GV->eraseFromParent(); in processInternalGlobal()
1585 if (optimizeOnceStoredGlobal(GV, StoredOnceValue, DL, GetTLI)) in processInternalGlobal()
1591 if (forwardStoredOnceStore(GV, GS.StoredOnceStore, LookupDomTree)) in processInternalGlobal()
1597 (!isa<UndefValue>(GV->getInitializer()) || in processInternalGlobal()
1599 if (TryToShrinkGlobalToBoolean(GV, SOVConstant)) { in processInternalGlobal()
1612 processGlobal(GlobalValue &GV, in processGlobal() argument
1616 if (GV.getName().starts_with("llvm.")) in processGlobal()
1621 if (GlobalStatus::analyzeGlobal(&GV, GS)) in processGlobal()
1625 if (!GS.IsCompared && !GV.hasGlobalUnnamedAddr()) { in processGlobal()
1626 auto NewUnnamedAddr = GV.hasLocalLinkage() ? GlobalValue::UnnamedAddr::Global in processGlobal()
1628 if (NewUnnamedAddr != GV.getUnnamedAddr()) { in processGlobal()
1629 GV.setUnnamedAddr(NewUnnamedAddr); in processGlobal()
1636 if (!GV.hasLocalLinkage()) in processGlobal()
1639 auto *GVar = dyn_cast<GlobalVariable>(&GV); in processGlobal()
2032 for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) { in OptimizeGlobalVars()
2034 if (!GV.hasName() && !GV.isDeclaration() && !GV.hasLocalLinkage()) in OptimizeGlobalVars()
2035 GV.setLinkage(GlobalValue::InternalLinkage); in OptimizeGlobalVars()
2037 if (GV.hasInitializer()) in OptimizeGlobalVars()
2038 if (auto *C = dyn_cast<Constant>(GV.getInitializer())) { in OptimizeGlobalVars()
2045 GV.setInitializer(New); in OptimizeGlobalVars()
2048 if (deleteIfDead(GV, NotDiscardableComdats)) { in OptimizeGlobalVars()
2053 Changed |= processGlobal(GV, GetTTI, GetTLI, LookupDomTree); in OptimizeGlobalVars()
2081 for (GlobalVariable *GV : Eval.getInvariants()) in EvaluateStaticConstructor()
2082 GV->setConstant(true); in EvaluateStaticConstructor()
2111 for (GlobalValue *GV : Init) { in setUsedInitializer()
2112 Constant *Cast = ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, PtrTy); in setUsedInitializer()
2166 bool usedCount(GlobalValue *GV) const { return Used.count(GV); } in usedCount()
2168 bool compilerUsedCount(GlobalValue *GV) const { in compilerUsedCount()
2169 return CompilerUsed.count(GV); in compilerUsedCount()
2172 bool usedErase(GlobalValue *GV) { return Used.erase(GV); } in usedErase() argument
2173 bool compilerUsedErase(GlobalValue *GV) { return CompilerUsed.erase(GV); } in compilerUsedErase() argument
2174 bool usedInsert(GlobalValue *GV) { return Used.insert(GV).second; } in usedInsert() argument
2176 bool compilerUsedInsert(GlobalValue *GV) { in compilerUsedInsert() argument
2177 return CompilerUsed.insert(GV).second; in compilerUsedInsert()
2206 static bool mayHaveOtherReferences(GlobalValue &GV, const LLVMUsed &U) { in mayHaveOtherReferences() argument
2207 if (!GV.hasLocalLinkage()) in mayHaveOtherReferences()
2210 return U.usedCount(&GV) || U.compilerUsedCount(&GV); in mayHaveOtherReferences()
2249 for (GlobalValue *GV : Used.used()) in OptimizeGlobalAliases()
2250 Used.compilerUsedErase(GV); in OptimizeGlobalAliases()
2254 auto IsModuleLocal = [](GlobalValue &GV) { in OptimizeGlobalAliases() argument
2255 return !GlobalValue::isInterposableLinkage(GV.getLinkage()) && in OptimizeGlobalAliases()
2256 (GV.isDSOLocal() || GV.isImplicitDSOLocal()); in OptimizeGlobalAliases()
2427 for (const GlobalVariable &GV : M.globals()) in optimizeGlobalsInModule() local
2428 if (const Comdat *C = GV.getComdat()) in optimizeGlobalsInModule()
2429 if (!GV.isDiscardableIfUnused() || !GV.use_empty()) in optimizeGlobalsInModule()