llvm.org GIT mirror llvm / 6c146ee
DbgInfoIntrinsics no longer appear in an instruction's use list; so clean up looking for them in use iterations and remove OnlyUsedByDbgInfoIntrinsics() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94111 91177308-0d34-0410-b5e6-96231b3b80d8 Victor Hernandez 9 years ago
3 changed file(s) with 8 addition(s) and 91 deletion(s). Raw diff Collapse all Expand all
2626 class AllocaInst;
2727 class ConstantExpr;
2828 class TargetData;
29 class DbgInfoIntrinsic;
3029
3130 template class SmallVectorImpl;
3231
153152 /// The phi node is deleted and it returns the pointer to the alloca inserted.
154153 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0);
155154
156 /// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
157 /// by DbgIntrinsics. If DbgInUses is specified then the vector is filled
158 /// with DbgInfoIntrinsic that use the instruction I.
159 bool OnlyUsedByDbgInfoIntrinsics(Instruction *I,
160 SmallVectorImpl *DbgInUses = 0);
161
162155 } // End llvm namespace
163156
164157 #endif
8484 /// isUnsafe - This is set to true if the alloca cannot be SROA'd.
8585 bool isUnsafe : 1;
8686
87 /// needsCleanup - This is set to true if there is some use of the alloca
88 /// that requires cleanup.
89 bool needsCleanup : 1;
90
9187 /// isMemCpySrc - This is true if this aggregate is memcpy'd from.
9288 bool isMemCpySrc : 1;
9389
9591 bool isMemCpyDst : 1;
9692
9793 AllocaInfo()
98 : isUnsafe(false), needsCleanup(false),
99 isMemCpySrc(false), isMemCpyDst(false) {}
94 : isUnsafe(false), isMemCpySrc(false), isMemCpyDst(false) {}
10095 };
10196
10297 unsigned SRThreshold;
10398
10499 void MarkUnsafe(AllocaInfo &I) { I.isUnsafe = true; }
105100
106 int isSafeAllocaToScalarRepl(AllocaInst *AI);
101 bool isSafeAllocaToScalarRepl(AllocaInst *AI);
107102
108103 void isSafeForScalarRepl(Instruction *I, AllocaInst *AI, uint64_t Offset,
109104 AllocaInfo &Info);
118113 void DoScalarReplacement(AllocaInst *AI,
119114 std::vector &WorkList);
120115 void DeleteDeadInstructions();
121 void CleanupAllocaUsers(Value *V);
122116 AllocaInst *AddNewAlloca(Function &F, const Type *Ty, AllocaInst *Base);
123117
124118 void RewriteForScalarRepl(Instruction *I, AllocaInst *AI, uint64_t Offset,
280274 getNumSAElements(AI->getAllocatedType()) <= SRThreshold/4) {
281275 // Check that all of the users of the allocation are capable of being
282276 // transformed.
283 switch (isSafeAllocaToScalarRepl(AI)) {
284 default: llvm_unreachable("Unexpected value!");
285 case 0: // Not safe to scalar replace.
286 break;
287 case 1: // Safe, but requires cleanup/canonicalizations first
288 CleanupAllocaUsers(AI);
289 // FALL THROUGH.
290 case 3: // Safe to scalar replace.
277 if (isSafeAllocaToScalarRepl(AI)) {
291278 DoScalarReplacement(AI, WorkList);
292279 Changed = true;
293280 continue;
436423 SIType, true, Info);
437424 } else
438425 MarkUnsafe(Info);
439 } else if (isa(UI)) {
440 // If one user is DbgInfoIntrinsic then check if all users are
441 // DbgInfoIntrinsics.
442 if (OnlyUsedByDbgInfoIntrinsics(I)) {
443 Info.needsCleanup = true;
444 return;
445 }
446 MarkUnsafe(Info);
447426 } else {
448427 DEBUG(errs() << " Transformation preventing inst: " << *User << '\n');
449428 MarkUnsafe(Info);
11491128 /// isSafeStructAllocaToScalarRepl - Check to see if the specified allocation of
11501129 /// an aggregate can be broken down into elements. Return 0 if not, 3 if safe,
11511130 /// or 1 if safe after canonicalization has been performed.
1152 int SROA::isSafeAllocaToScalarRepl(AllocaInst *AI) {
1131 bool SROA::isSafeAllocaToScalarRepl(AllocaInst *AI) {
11531132 // Loop over the use list of the alloca. We can only transform it if all of
11541133 // the users are safe to transform.
11551134 AllocaInfo Info;
11571136 isSafeForScalarRepl(AI, AI, 0, Info);
11581137 if (Info.isUnsafe) {
11591138 DEBUG(dbgs() << "Cannot transform: " << *AI << '\n');
1160 return 0;
1139 return false;
11611140 }
11621141
11631142 // Okay, we know all the users are promotable. If the aggregate is a memcpy
11671146 // struct.
11681147 if (Info.isMemCpySrc && Info.isMemCpyDst &&
11691148 HasPadding(AI->getAllocatedType(), *TD))
1170 return 0;
1171
1172 // If we require cleanup, return 1, otherwise return 3.
1173 return Info.needsCleanup ? 1 : 3;
1174 }
1175
1176 /// CleanupAllocaUsers - If SROA reported that it can promote the specified
1177 /// allocation, but only if cleaned up, perform the cleanups required.
1178 void SROA::CleanupAllocaUsers(Value *V) {
1179 for (Value::use_iterator UI = V->use_begin(), E = V->use_end();
1180 UI != E; ) {
1181 User *U = *UI++;
1182 Instruction *I = cast(U);
1183 SmallVector DbgInUses;
1184 if (!isa(I) && OnlyUsedByDbgInfoIntrinsics(I, &DbgInUses)) {
1185 // Safe to remove debug info uses.
1186 while (!DbgInUses.empty()) {
1187 DbgInfoIntrinsic *DI = DbgInUses.pop_back_val();
1188 DI->eraseFromParent();
1189 }
1190 I->eraseFromParent();
1191 }
1192 }
1149 return false;
1150
1151 return true;
11931152 }
11941153
11951154 /// MergeInType - Add the 'In' type to the accumulated type (Accum) so far at
13241283 }
13251284 }
13261285
1327 // Ignore dbg intrinsic.
1328 if (isa(User))
1329 continue;
1330
13311286 // Otherwise, we cannot handle this!
13321287 return false;
13331288 }
14521407 } else {
14531408 // Noop transfer. Src == Dst
14541409 }
1455
14561410
14571411 MTI->eraseFromParent();
14581412 continue;
14591413 }
14601414
1461 // If user is a dbg info intrinsic then it is safe to remove it.
1462 if (isa(User)) {
1463 User->eraseFromParent();
1464 continue;
1465 }
1466
14671415 llvm_unreachable("Unsupported operation!");
14681416 }
14691417 }
608608 return true;
609609 }
610610
611
612
613 /// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
614 /// by DbgIntrinsics. If DbgInUses is specified then the vector is filled
615 /// with the DbgInfoIntrinsic that use the instruction I.
616 bool llvm::OnlyUsedByDbgInfoIntrinsics(Instruction *I,
617 SmallVectorImpl *DbgInUses) {
618 if (DbgInUses)
619 DbgInUses->clear();
620
621 for (Value::use_iterator UI = I->use_begin(), UE = I->use_end(); UI != UE;
622 ++UI) {
623 if (DbgInfoIntrinsic *DI = dyn_cast(*UI)) {
624 if (DbgInUses)
625 DbgInUses->push_back(DI);
626 } else {
627 if (DbgInUses)
628 DbgInUses->clear();
629 return false;
630 }
631 }
632 return true;
633 }
634
635611 /// EliminateDuplicatePHINodes - Check for and eliminate duplicate PHI
636612 /// nodes in this block. This doesn't try to be clever about PHI nodes
637613 /// which differ only in the order of the incoming values, but instcombine