llvm.org GIT mirror llvm / eeb1971
[IR] Add Instruction::isLifetimeStartOrEnd, NFC Instruction::isLifetimeStartOrEnd() checks whether an Instruction is an llvm.lifetime.start or an llvm.lifetime.end intrinsic. This was suggested as a cleanup in D55967. Differential Revision: https://reviews.llvm.org/D56019 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349964 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 10 months ago
18 changed file(s) with 41 addition(s) and 69 deletion(s). Raw diff Collapse all Expand all
581581 }
582582 }
583583
584 /// Return true if the instruction is a llvm.lifetime.start or
585 /// llvm.lifetime.end marker.
586 bool isLifetimeStartOrEnd() const;
587
584588 /// Return a pointer to the next non-debug instruction in the same basic
585589 /// block as 'this', or nullptr if no such instruction exists.
586590 const Instruction *getNextNonDebugInstruction() const;
322322 case Instruction::Invoke: {
323323 ImmutableCallSite CS(I);
324324
325 if (const IntrinsicInst *II = dyn_cast(I)) {
326 if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
327 II->getIntrinsicID() == Intrinsic::lifetime_end)
328 break;
329 }
325 if (I->isLifetimeStartOrEnd())
326 break;
330327
331328 if (const MemIntrinsic *MI = dyn_cast(I)) {
332329 US.updateRange(getMemIntrinsicAccessRange(MI, UI, Ptr));
38213821 const IntrinsicInst *II = dyn_cast(U);
38223822 if (!II) return false;
38233823
3824 if (II->getIntrinsicID() != Intrinsic::lifetime_start &&
3825 II->getIntrinsicID() != Intrinsic::lifetime_end)
3824 if (!II->isLifetimeStartOrEnd())
38263825 return false;
38273826 }
38283827 return true;
323323 case Instruction::Invoke: {
324324 ImmutableCallSite CS(I);
325325
326 if (const IntrinsicInst *II = dyn_cast(I)) {
327 if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
328 II->getIntrinsicID() == Intrinsic::lifetime_end)
329 continue;
330 }
326 if (I->isLifetimeStartOrEnd())
327 continue;
331328
332329 if (const MemIntrinsic *MI = dyn_cast(I)) {
333330 if (!IsMemIntrinsicSafe(MI, UI, AllocaPtr, AllocaSize)) {
4545 }
4646
4747 bool StackColoring::readMarker(Instruction *I, bool *IsStart) {
48 auto *II = dyn_cast(I);
49 if (!II || (II->getIntrinsicID() != Intrinsic::lifetime_start &&
50 II->getIntrinsicID() != Intrinsic::lifetime_end))
48 if (!I->isLifetimeStartOrEnd())
5149 return false;
5250
51 auto *II = cast(I);
5352 *IsStart = II->getIntrinsicID() == Intrinsic::lifetime_start;
5453 return true;
5554 }
156156 return NeedsProtector;
157157 }
158158
159 static bool isLifetimeInst(const Instruction *I) {
160 if (const auto Intrinsic = dyn_cast(I)) {
161 const auto Id = Intrinsic->getIntrinsicID();
162 return Id == Intrinsic::lifetime_start || Id == Intrinsic::lifetime_end;
163 }
164 return false;
165 }
166
167159 bool StackProtector::HasAddressTaken(const Instruction *AI) {
168160 for (const User *U : AI->users()) {
169161 if (const StoreInst *SI = dyn_cast(U)) {
174166 return true;
175167 } else if (const CallInst *CI = dyn_cast(U)) {
176168 // Ignore intrinsics that are not calls. TODO: Use isLoweredToCall().
177 if (!isa(CI) && !isLifetimeInst(CI))
169 if (!isa(CI) && !CI->isLifetimeStartOrEnd())
178170 return true;
179171 } else if (isa(U)) {
180172 return true;
205205 if (isa(I) || isa(I))
206206 continue;
207207
208 if (auto *II = dyn_cast(&I))
209 if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
210 II->getIntrinsicID() == Intrinsic::lifetime_end)
211 continue;
208 if (I.isLifetimeStartOrEnd())
209 continue;
212210
213211 return &I;
214212 }
597597 !this->isTerminator();
598598 }
599599
600 bool Instruction::isLifetimeStartOrEnd() const {
601 auto II = dyn_cast(this);
602 if (!II)
603 return false;
604 Intrinsic::ID ID = II->getIntrinsicID();
605 return ID == Intrinsic::lifetime_start || ID == Intrinsic::lifetime_end;
606 }
607
600608 const Instruction *Instruction::getNextNonDebugInstruction() const {
601609 for (const Instruction *I = getNextNode(); I; I = I->getNextNode())
602610 if (!isa(I))
850850 break;
851851 }
852852
853 IntrinsicInst *IntrInst = dyn_cast(&I);
854 if (IntrInst) {
855 if (IntrInst->getIntrinsicID() == Intrinsic::lifetime_start ||
856 IntrInst->getIntrinsicID() == Intrinsic::lifetime_end)
857 continue;
858 }
853 if (I.isLifetimeStartOrEnd())
854 continue;
859855
860856 if (CallInst *CI = dyn_cast(&I)) {
861857 InlineCost += getCallsiteCost(CallSite(CI), DL);
115115 }
116116
117117 // Lifetime intrinsics can be handled by the caller.
118 if (IntrinsicInst *II = dyn_cast(I)) {
119 if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
120 II->getIntrinsicID() == Intrinsic::lifetime_end) {
121 assert(II->use_empty() && "Lifetime markers have no result to use!");
122 ToDelete.push_back(II);
123 continue;
124 }
118 if (I->isLifetimeStartOrEnd()) {
119 assert(I->use_empty() && "Lifetime markers have no result to use!");
120 ToDelete.push_back(I);
121 continue;
125122 }
126123
127124 // If this is isn't our memcpy/memmove, reject it as something we can't
10041004 if (ID == Intrinsic::localescape) LocalEscapeCall = ⅈ
10051005 if (!ASan.UseAfterScope)
10061006 return;
1007 if (ID != Intrinsic::lifetime_start && ID != Intrinsic::lifetime_end)
1007 if (!II.isLifetimeStartOrEnd())
10081008 return;
10091009 // Found lifetime intrinsic, add ASan instrumentation if necessary.
10101010 ConstantInt *Size = dyn_cast(II.getArgOperand(0));
918918 continue;
919919 }
920920 if (const IntrinsicInst *IT = dyn_cast(U))
921 if (IT->getIntrinsicID() == Intrinsic::lifetime_start ||
922 IT->getIntrinsicID() == Intrinsic::lifetime_end)
921 if (IT->isLifetimeStartOrEnd())
923922 continue;
924923
925924 if (U != C && U != cpy)
912912 if (!IsOffsetKnown)
913913 return PI.setAborted(&II);
914914
915 if (II.getIntrinsicID() == Intrinsic::lifetime_start ||
916 II.getIntrinsicID() == Intrinsic::lifetime_end) {
915 if (II.isLifetimeStartOrEnd()) {
917916 ConstantInt *Length = cast(II.getArgOperand(0));
918917 uint64_t Size = std::min(AllocSize - Offset.getLimitedValue(),
919918 Length->getLimitedValue());
18061805 if (!S.isSplittable())
18071806 return false; // Skip any unsplittable intrinsics.
18081807 } else if (IntrinsicInst *II = dyn_cast(U->getUser())) {
1809 if (II->getIntrinsicID() != Intrinsic::lifetime_start &&
1810 II->getIntrinsicID() != Intrinsic::lifetime_end)
1808 if (!II->isLifetimeStartOrEnd())
18111809 return false;
18121810 } else if (U->get()->getType()->getPointerElementType()->isStructTy()) {
18131811 // Disable vector promotion when there are loads or stores of an FCA.
20282026 if (!S.isSplittable())
20292027 return false; // Skip any unsplittable intrinsics.
20302028 } else if (IntrinsicInst *II = dyn_cast(U->getUser())) {
2031 if (II->getIntrinsicID() != Intrinsic::lifetime_start &&
2032 II->getIntrinsicID() != Intrinsic::lifetime_end)
2029 if (!II->isLifetimeStartOrEnd())
20332030 return false;
20342031 } else {
20352032 return false;
30123009 }
30133010
30143011 bool visitIntrinsicInst(IntrinsicInst &II) {
3015 assert(II.getIntrinsicID() == Intrinsic::lifetime_start ||
3016 II.getIntrinsicID() == Intrinsic::lifetime_end);
3012 assert(II.isLifetimeStartOrEnd());
30173013 LLVM_DEBUG(dbgs() << " original: " << II << "\n");
30183014 assert(II.getArgOperand(1) == OldPtr);
30193015
331331 default: {
332332 IntrinsicInst *IntrInst = dyn_cast(&II);
333333 if (IntrInst) {
334 if (IntrInst->getIntrinsicID() == Intrinsic::lifetime_start ||
335 IntrInst->getIntrinsicID() == Intrinsic::lifetime_end)
334 if (IntrInst->isLifetimeStartOrEnd())
336335 break;
337336 return false;
338337 }
482482 }
483483 }
484484
485 if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
486 II->getIntrinsicID() == Intrinsic::lifetime_end) {
485 if (II->isLifetimeStartOrEnd()) {
487486 LLVM_DEBUG(dbgs() << "Ignoring lifetime intrinsic.\n");
488487 ++CurInst;
489488 continue;
13191319
13201320 // Check whether this Value is used by a lifetime intrinsic.
13211321 static bool isUsedByLifetimeMarker(Value *V) {
1322 for (User *U : V->users()) {
1323 if (IntrinsicInst *II = dyn_cast(U)) {
1324 switch (II->getIntrinsicID()) {
1325 default: break;
1326 case Intrinsic::lifetime_start:
1327 case Intrinsic::lifetime_end:
1322 for (User *U : V->users())
1323 if (IntrinsicInst *II = dyn_cast(U))
1324 if (II->isLifetimeStartOrEnd())
13281325 return true;
1329 }
1330 }
1331 }
13321326 return false;
13331327 }
13341328
392392 return true;
393393
394394 // Lifetime intrinsics are dead when their right-hand is undef.
395 if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
396 II->getIntrinsicID() == Intrinsic::lifetime_end)
395 if (II->isLifetimeStartOrEnd())
397396 return isa(II->getArgOperand(1));
398397
399398 // Assumptions are dead if their condition is trivially true. Guards on
8181 if (SI->isVolatile())
8282 return false;
8383 } else if (const IntrinsicInst *II = dyn_cast(U)) {
84 if (II->getIntrinsicID() != Intrinsic::lifetime_start &&
85 II->getIntrinsicID() != Intrinsic::lifetime_end)
84 if (!II->isLifetimeStartOrEnd())
8685 return false;
8786 } else if (const BitCastInst *BCI = dyn_cast(U)) {
8887 if (BCI->getType() != Type::getInt8PtrTy(U->getContext(), AS))