Lines Matching defs:GV
111 static bool isLeakCheckerRoot(GlobalVariable *GV) {
120 if (GV->hasPrivateLinkage())
124 Types.push_back(GV->getValueType());
188 /// This GV is a pointer root. Loop over all users of the global and clean up
192 CleanupPointerRootUsers(GlobalVariable *GV,
209 SmallVector<User *> Worklist(GV->users());
263 GV->removeDeadConstantUsers();
267 /// We just marked GV constant. Loop over all users of the global, cleaning up
270 static bool CleanupConstantGlobalUsers(GlobalVariable *GV,
272 Constant *Init = GV->getInitializer();
273 SmallVector<User *, 8> WorkList(GV->users());
314 if (PtrOp == GV) {
324 if (getUnderlyingObject(MI->getRawDest()) == GV)
334 GV->removeDeadConstantUsers();
350 GlobalVariable *GV, const DataLayout &DL) {
358 AppendUses(GV);
379 if (Ptr != GV || Offset.getActiveBits() >= 64)
392 ConstantFoldLoadFromConst(GV->getInitializer(), Ty, Offset, DL);
395 << *GV << " with type " << *Ty << " at offset "
438 static void transferSRADebugInfo(GlobalVariable *GV, GlobalVariable *NGV,
443 GV->getDebugInfo(GVs);
518 static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) {
519 assert(GV->hasLocalLinkage());
523 if (!collectSRATypes(Parts, GV, DL) || Parts.empty())
527 if (Parts.size() == 1 && Parts.begin()->second.Ty == GV->getValueType())
558 if (Offset > DL.getTypeAllocSize(GV->getValueType()))
561 LLVM_DEBUG(dbgs() << "PERFORMING GLOBAL SRA ON: " << *GV << "\n");
565 DL.getValueOrABITypeAlignment(GV->getAlign(), GV->getValueType());
566 uint64_t VarSize = DL.getTypeSizeInBits(GV->getValueType());
573 *GV->getParent(), Ty, false, GlobalVariable::InternalLinkage,
574 Initializer, GV->getName() + "." + Twine(NameSuffix++), GV,
575 GV->getThreadLocalMode(), GV->getAddressSpace());
576 NGV->copyAttributesFrom(GV);
587 transferSRADebugInfo(GV, NGV, OffsetForTy * 8,
600 AppendUsers(GV);
615 assert(Ptr == GV && "Load/store must be from/to global");
641 GV->removeDeadConstantUsers();
642 GV->eraseFromParent();
703 /// Return true if all uses of any loads from GV will trap if the loaded value
706 static bool allUsesOfLoadedValueWillTrapIfNull(const GlobalVariable *GV) {
708 Worklist.push_back(GV);
721 if (CE->stripPointerCasts() != GV)
735 /// Get all the loads/store uses for global variable \p GV.
736 static void allUsesOfLoadAndStores(GlobalVariable *GV,
739 Worklist.push_back(GV);
826 GlobalVariable *GV, Constant *LV, const DataLayout &DL,
835 for (User *GlobalUser : llvm::make_early_inc_range(GV->users())) {
847 assert(GlobalUser->getOperand(1) == GV &&
864 LLVM_DEBUG(dbgs() << "OPTIMIZED LOADS FROM STORED ONCE POINTER: " << *GV
872 if (isLeakCheckerRoot(GV)) {
873 Changed |= CleanupPointerRootUsers(GV, GetTLI);
876 CleanupConstantGlobalUsers(GV, DL);
878 if (GV->use_empty()) {
881 GV->eraseFromParent();
910 /// loads of GV as uses of the new global.
912 OptimizeGlobalAddressOfAllocation(GlobalVariable *GV, CallInst *CI,
916 LLVM_DEBUG(errs() << "PROMOTING GLOBAL: " << *GV << " CALL = " << *CI
920 Type *GlobalType = ArrayType::get(Type::getInt8Ty(GV->getContext()),
926 *GV->getParent(), GlobalType, false, GlobalValue::InternalLinkage,
927 UndefValue::get(GlobalType), GV->getName() + ".body", nullptr,
928 GV->getThreadLocalMode());
947 new GlobalVariable(Type::getInt1Ty(GV->getContext()), false,
949 ConstantInt::getFalse(GV->getContext()),
950 GV->getName()+".init", GV->getThreadLocalMode());
953 // Loop over all instruction uses of GV, processing them in turn.
955 allUsesOfLoadAndStores(GV, Guses);
961 GV->getContext(),
987 LV = ConstantInt::getFalse(GV->getContext());
990 LV = ConstantInt::getTrue(GV->getContext());
1012 GV->getParent()->insertGlobalVariable(GV->getIterator(), InitBool);
1014 // Now the GV is dead, nuke it and the allocation..
1015 GV->eraseFromParent();
1026 /// Scan the use-list of GV checking to make sure that there are no complex uses
1027 /// of GV. We permit simple things like dereferencing the pointer, but not
1031 const GlobalVariable *GV) {
1048 SI->getPointerOperand()->stripPointerCasts() != GV)
1049 return false; // Storing the pointer not into GV... bad.
1050 continue; // Otherwise, storing through it, or storing into GV... fine.
1074 static bool tryToOptimizeStoreOfAllocationToGlobal(GlobalVariable *GV,
1104 if (!allUsesOfLoadedValueWillTrapIfNull(GV))
1111 if (!valueIsOnlyUsedLocallyOrStoredToOneGlobal(CI, GV))
1114 OptimizeGlobalAddressOfAllocation(GV, CI, AllocSize, InitVal, DL, TLI);
1121 optimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
1131 if (GV->getInitializer()->getType()->isPointerTy() &&
1132 GV->getInitializer()->isNullValue() &&
1136 GV->getInitializer()->getType()->getPointerAddressSpace())) {
1139 if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC, DL, GetTLI))
1144 if (tryToOptimizeStoreOfAllocationToGlobal(GV, CI, DL, TLI))
1153 /// At this point, we have learned that the only two values ever stored into GV
1157 static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
1158 Type *GVElType = GV->getValueType();
1160 // If GVElType is already i1, it is already shrunk. If the type of the GV is
1165 if (GVElType == Type::getInt1Ty(GV->getContext()) ||
1172 for (User *U : GV->users()) {
1179 LLVM_DEBUG(dbgs() << " *** SHRINKING TO BOOL: " << *GV << "\n");
1182 GlobalVariable *NewGV = new GlobalVariable(Type::getInt1Ty(GV->getContext()),
1185 ConstantInt::getFalse(GV->getContext()),
1186 GV->getName()+".b",
1187 GV->getThreadLocalMode(),
1188 GV->getType()->getAddressSpace());
1189 NewGV->copyAttributesFrom(GV);
1190 GV->getParent()->insertGlobalVariable(GV->getIterator(), NewGV);
1192 Constant *InitVal = GV->getInitializer();
1193 assert(InitVal->getType() != Type::getInt1Ty(GV->getContext()) &&
1197 GV->getDebugInfo(GVs);
1207 auto *CIInit = dyn_cast<ConstantInt>(GV->getInitializer());
1216 const DataLayout &DL = GV->getDataLayout();
1246 for(auto *GV : GVs)
1247 NewGV->addDebugInfo(GV);
1250 while (!GV->use_empty()) {
1251 Instruction *UI = cast<Instruction>(GV->user_back());
1258 StoreVal = ConstantInt::get(Type::getInt1Ty(GV->getContext()),
1270 assert(LI->getOperand(0) == GV && "Not a copy!");
1310 NewGV->takeName(GV);
1311 GV->eraseFromParent();
1316 deleteIfDead(GlobalValue &GV,
1319 GV.removeDeadConstantUsers();
1321 if (!GV.isDiscardableIfUnused() && !GV.isDeclaration())
1324 if (const Comdat *C = GV.getComdat())
1325 if (!GV.hasLocalLinkage() && NotDiscardableComdats.count(C))
1329 if (auto *F = dyn_cast<Function>(&GV))
1332 Dead = GV.use_empty();
1336 LLVM_DEBUG(dbgs() << "GLOBAL DEAD: " << GV << "\n");
1337 if (auto *F = dyn_cast<Function>(&GV)) {
1341 GV.eraseFromParent();
1347 const Function *F, GlobalValue *GV,
1349 // Find all uses of GV. We expect them all to be in F, and if we can't
1352 // On each of these uses, identify if the memory that GV points to is
1354 // if the first thing the function does is store to the GV, the GV can
1359 const DataLayout &DL = GV->getDataLayout();
1362 for (auto *U : GV->users()) {
1376 // We have identified all uses of GV into loads and stores. Now check if all
1416 GlobalVariable *GV, const StoreInst *StoredOnceStore,
1426 for (User *U : GV->users()) {
1451 processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS,
1455 auto &DL = GV->getDataLayout();
1466 GV->getValueType()->isSingleValueType() &&
1467 GV->getType()->getAddressSpace() == DL.getAllocaAddrSpace() &&
1468 !GV->isExternallyInitialized() &&
1470 isPointerValueDeadOnEntryToFunction(GS.AccessingFunction, GV,
1472 const DataLayout &DL = GV->getDataLayout();
1474 LLVM_DEBUG(dbgs() << "LOCALIZING GLOBAL: " << *GV << "\n");
1477 Type *ElemTy = GV->getValueType();
1480 nullptr, GV->getName(), FirstI);
1481 if (!isa<UndefValue>(GV->getInitializer()))
1482 new StoreInst(GV->getInitializer(), Alloca, FirstI);
1484 GV->replaceAllUsesWith(Alloca);
1485 GV->eraseFromParent();
1495 LLVM_DEBUG(dbgs() << "GLOBAL NEVER LOADED: " << *GV << "\n");
1497 if (isLeakCheckerRoot(GV)) {
1499 Changed = CleanupPointerRootUsers(GV, GetTLI);
1503 Changed = CleanupConstantGlobalUsers(GV, DL);
1507 if (GV->use_empty()) {
1508 GV->eraseFromParent();
1516 LLVM_DEBUG(dbgs() << "MARKING CONSTANT: " << *GV << "\n");
1522 assert(!GV->isConstant() && "Expected a non-constant global");
1523 GV->setConstant(true);
1528 Changed |= CleanupConstantGlobalUsers(GV, DL);
1531 if (GV->use_empty()) {
1534 GV->eraseFromParent();
1542 if (!GV->getInitializer()->getType()->isSingleValueType()) {
1543 const DataLayout &DL = GV->getDataLayout();
1544 if (SRAGlobal(GV, DL))
1553 GV->getType()->getAddressSpace());
1562 if (SOVConstant && isa<UndefValue>(GV->getInitializer()) &&
1564 DL.getTypeAllocSize(GV->getValueType()) &&
1566 if (SOVConstant->getType() == GV->getValueType()) {
1568 GV->setInitializer(SOVConstant);
1572 *GV->getParent(), SOVConstant->getType(), GV->isConstant(),
1573 GV->getLinkage(), SOVConstant, "", GV, GV->getThreadLocalMode(),
1574 GV->getAddressSpace());
1575 NGV->takeName(GV);
1576 NGV->copyAttributesFrom(GV);
1577 GV->replaceAllUsesWith(NGV);
1578 GV->eraseFromParent();
1579 GV = NGV;
1583 CleanupConstantGlobalUsers(GV, DL);
1585 if (GV->use_empty()) {
1588 GV->eraseFromParent();
1597 if (optimizeOnceStoredGlobal(GV, StoredOnceValue, DL, GetTLI))
1603 if (forwardStoredOnceStore(GV, GS.StoredOnceStore, LookupDomTree))
1609 (!isa<UndefValue>(GV->getInitializer()) ||
1611 if (TryToShrinkGlobalToBoolean(GV, SOVConstant)) {
1624 processGlobal(GlobalValue &GV,
1628 if (GV.getName().starts_with("llvm."))
1633 if (GlobalStatus::analyzeGlobal(&GV, GS))
1637 if (!GS.IsCompared && !GV.hasGlobalUnnamedAddr()) {
1638 auto NewUnnamedAddr = GV.hasLocalLinkage() ? GlobalValue::UnnamedAddr::Global
1640 if (NewUnnamedAddr != GV.getUnnamedAddr()) {
1641 GV.setUnnamedAddr(NewUnnamedAddr);
1648 if (!GV.hasLocalLinkage())
1651 auto *GVar = dyn_cast<GlobalVariable>(&GV);
2044 for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) {
2046 if (!GV.hasName() && !GV.isDeclaration() && !GV.hasLocalLinkage())
2047 GV.setLinkage(GlobalValue::InternalLinkage);
2049 if (GV.hasInitializer())
2050 if (auto *C = dyn_cast<Constant>(GV.getInitializer())) {
2057 GV.setInitializer(New);
2060 if (deleteIfDead(GV, NotDiscardableComdats)) {
2065 Changed |= processGlobal(GV, GetTTI, GetTLI, LookupDomTree);
2093 for (GlobalVariable *GV : Eval.getInvariants())
2094 GV->setConstant(true);
2123 for (GlobalValue *GV : Init) {
2124 Constant *Cast = ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, PtrTy);
2178 bool usedCount(GlobalValue *GV) const { return Used.count(GV); }
2180 bool compilerUsedCount(GlobalValue *GV) const {
2181 return CompilerUsed.count(GV);
2184 bool usedErase(GlobalValue *GV) { return Used.erase(GV); }
2185 bool compilerUsedErase(GlobalValue *GV) { return CompilerUsed.erase(GV); }
2186 bool usedInsert(GlobalValue *GV) { return Used.insert(GV).second; }
2188 bool compilerUsedInsert(GlobalValue *GV) {
2189 return CompilerUsed.insert(GV).second;
2218 static bool mayHaveOtherReferences(GlobalValue &GV, const LLVMUsed &U) {
2219 if (!GV.hasLocalLinkage())
2222 return U.usedCount(&GV) || U.compilerUsedCount(&GV);
2261 for (GlobalValue *GV : Used.used())
2262 Used.compilerUsedErase(GV);
2264 // Return whether GV is explicitly or implicitly dso_local and not replaceable
2266 auto IsModuleLocal = [](GlobalValue &GV) {
2267 return !GlobalValue::isInterposableLinkage(GV.getLinkage()) &&
2268 (GV.isDSOLocal() || GV.isImplicitDSOLocal());
2500 for (const GlobalVariable &GV : M.globals())
2501 if (const Comdat *C = GV.getComdat())
2502 if (!GV.isDiscardableIfUnused() || !GV.use_empty())