Lines Matching refs:AI
101 AllocaInst *AI;
126 explicit AllocaInfo(AllocaInst *ai)
127 : AI(ai), isUnsafe(false), isMemCpySrc(false), isMemCpyDst(false),
151 bool isSafeAllocaToScalarRepl(AllocaInst *AI);
164 void DoScalarReplacement(AllocaInst *AI,
168 void RewriteForScalarRepl(Instruction *I, AllocaInst *AI, uint64_t Offset,
170 void RewriteBitCast(BitCastInst *BC, AllocaInst *AI, uint64_t Offset,
172 void RewriteGEP(GetElementPtrInst *GEPI, AllocaInst *AI, uint64_t Offset,
174 void RewriteLifetimeIntrinsic(IntrinsicInst *II, AllocaInst *AI,
178 AllocaInst *AI,
180 void RewriteStoreUserOfWholeAlloca(StoreInst *SI, AllocaInst *AI,
182 void RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocaInst *AI,
184 bool ShouldAttemptScalarRepl(AllocaInst *AI);
310 AllocaInst *TryConvert(AllocaInst *AI);
332 AllocaInst *ConvertToScalarInfo::TryConvert(AllocaInst *AI) {
335 if (!CanConvertToScalar(AI, 0, 0) || !IsNotTrivial)
355 DEBUG(dbgs() << "CONVERT TO VECTOR: " << *AI << "\n TYPE = "
375 DEBUG(dbgs() << "CONVERT TO SCALAR INTEGER: " << *AI << "\n");
377 NewTy = IntegerType::get(AI->getContext(), BitWidth);
379 AllocaInst *NewAI = new AllocaInst(NewTy, 0, "", AI->getParent()->begin());
380 ConvertUsesToScalar(AI, NewAI, 0, 0);
1046 AllocaInst *AI;
1053 : LoadAndStorePromoter(Insts, S), AI(0), DIB(DB) {}
1055 void run(AllocaInst *AI, const SmallVectorImpl<Instruction*> &Insts) {
1057 this->AI = AI;
1058 if (MDNode *DebugNode = MDNode::getIfExists(AI->getContext(), AI)) {
1068 AI->eraseFromParent();
1084 return LI->getOperand(0) == AI;
1085 return cast<StoreInst>(I)->getPointerOperand() == AI;
1239 static bool tryToMakeAllocaBePromotable(AllocaInst *AI, const DataLayout *TD) {
1243 for (Value::use_iterator UI = AI->use_begin(), UE = AI->use_end();
1253 if (SI->getOperand(0) == AI || !SI->isSimple())
1254 return false; // Don't allow a store OF the AI, only INTO the AI.
1266 // This is very rare and we just scrambled the use list of AI, start
1268 return tryToMakeAllocaBePromotable(AI, TD);
1271 // If it is safe to turn "load (select c, AI, ptr)" into a select of two
1286 // If it is safe to turn "load (phi [AI, ptr, ...])" into a PHI of loads
1422 if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) // Is it an alloca?
1423 if (tryToMakeAllocaBePromotable(AI, TD))
1424 Allocas.push_back(AI);
1433 AllocaInst *AI = Allocas[i];
1436 for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end();
1439 AllocaPromoter(Insts, SSA, &DIB).run(AI, Insts);
1453 bool SROA::ShouldAttemptScalarRepl(AllocaInst *AI) {
1454 Type *T = AI->getAllocatedType();
1480 AllocaInst *AI = WorkList.back();
1485 if (AI->use_empty()) {
1486 AI->eraseFromParent();
1492 if (AI->isArrayAllocation() || !AI->getAllocatedType()->isSized())
1499 uint64_t AllocaSize = TD->getTypeAllocSize(AI->getAllocatedType());
1510 if (ShouldAttemptScalarRepl(AI) && isSafeAllocaToScalarRepl(AI)) {
1511 DoScalarReplacement(AI, WorkList);
1523 (unsigned)AllocaSize, *TD, ScalarLoadThreshold).TryConvert(AI)) {
1524 NewAI->takeName(AI);
1525 AI->eraseFromParent();
1539 void SROA::DoScalarReplacement(AllocaInst *AI,
1541 DEBUG(dbgs() << "Found inst to SROA: " << *AI << '\n');
1543 if (StructType *ST = dyn_cast<StructType>(AI->getAllocatedType())) {
1547 AI->getAlignment(),
1548 AI->getName() + "." + Twine(i), AI);
1553 ArrayType *AT = cast<ArrayType>(AI->getAllocatedType());
1557 AllocaInst *NA = new AllocaInst(ElTy, 0, AI->getAlignment(),
1558 AI->getName() + "." + Twine(i), AI);
1566 RewriteForScalarRepl(AI, AI, 0, ElementAllocas);
1570 AI->eraseFromParent();
1596 /// performing scalar replacement of alloca AI. The results are flagged in
1597 /// the Info parameter. Offset indicates the position within AI that is
1740 if (!TypeHasComponent(Info.AI->getAllocatedType(), Offset,
1785 /// isSafeMemAccess - Check if a load/store/memcpy operates on the entire AI
1798 MemSize == TD->getTypeAllocSize(Info.AI->getAllocatedType())) {
1814 if (isCompatibleAggregate(MemOpType, Info.AI->getAllocatedType())) {
1820 Type *T = Info.AI->getAllocatedType();
1863 /// RewriteForScalarRepl - Alloca AI is being split into NewElts, so rewrite
1865 /// Offset indicates the position within AI that is referenced by this
1867 void SROA::RewriteForScalarRepl(Instruction *I, AllocaInst *AI, uint64_t Offset,
1874 RewriteBitCast(BC, AI, Offset, NewElts);
1879 RewriteGEP(GEPI, AI, Offset, NewElts);
1887 MemSize == TD->getTypeAllocSize(AI->getAllocatedType()))
1888 RewriteMemIntrinUserOfAlloca(MI, I, AI, NewElts);
1897 RewriteLifetimeIntrinsic(II, AI, Offset, NewElts);
1905 if (isCompatibleAggregate(LIType, AI->getAllocatedType())) {
1924 TD->getTypeAllocSize(AI->getAllocatedType())) {
1926 RewriteLoadUserOfWholeAlloca(LI, AI, NewElts);
1934 if (isCompatibleAggregate(SIType, AI->getAllocatedType())) {
1951 TD->getTypeAllocSize(AI->getAllocatedType())) {
1953 RewriteStoreUserOfWholeAlloca(SI, AI, NewElts);
1971 BitCastInst *BCI = new BitCastInst(NewAI, AI->getType(), "", NewAI);
1981 void SROA::RewriteBitCast(BitCastInst *BC, AllocaInst *AI, uint64_t Offset,
1983 RewriteForScalarRepl(BC, AI, Offset, NewElts);
1984 if (BC->getOperand(0) != AI)
1991 Type *T = AI->getAllocatedType();
2039 void SROA::RewriteGEP(GetElementPtrInst *GEPI, AllocaInst *AI, uint64_t Offset,
2052 RewriteForScalarRepl(GEPI, AI, Offset, NewElts);
2054 Type *T = AI->getAllocatedType();
2057 if (GEPI->getOperand(0) == AI)
2060 T = AI->getAllocatedType();
2069 Type *i32Ty = Type::getInt32Ty(AI->getContext());
2100 void SROA::RewriteLifetimeIntrinsic(IntrinsicInst *II, AllocaInst *AI,
2106 Type *AIType = AI->getAllocatedType();
2154 /// RewriteMemIntrinUserOfAlloca - MI is a memcpy/memset/memmove from or to AI.
2158 AllocaInst *AI,
2176 // type as AI has, so we can GEP through it safely.
2190 if (OtherPtr == AI || OtherPtr == NewElts[0]) {
2203 PointerType::get(AI->getType()->getElementType(), AddrSpace);
2331 SROA::RewriteStoreUserOfWholeAlloca(StoreInst *SI, AllocaInst *AI,
2336 Type *AllocaEltTy = AI->getAllocatedType();
2346 DEBUG(dbgs() << "PROMOTING STORE TO WHOLE ALLOCA: " << *AI << '\n' << *SI
2349 // There are two forms here: AI could be an array or struct. Both cases
2446 SROA::RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocaInst *AI,
2450 Type *AllocaEltTy = AI->getAllocatedType();
2453 DEBUG(dbgs() << "PROMOTING LOAD OF WHOLE ALLOCA: " << *AI << '\n' << *LI
2456 // There are two forms here: AI could be an array or struct. Both cases
2570 bool SROA::isSafeAllocaToScalarRepl(AllocaInst *AI) {
2573 AllocaInfo Info(AI);
2575 isSafeForScalarRepl(AI, 0, Info);
2577 DEBUG(dbgs() << "Cannot transform: " << *AI << '\n');
2587 HasPadding(AI->getAllocatedType(), *TD))
2596 if (StructType *ST = dyn_cast<StructType>(AI->getAllocatedType())) {
2599 if (cast<ArrayType>(AI->getAllocatedType())->getNumElements() > 1)