Skip to content

Commit 9fbd5fb

Browse files
authored
[IR][NFC] Switch to use LifetimeIntrinsic (llvm#125528)
1 parent fe694b1 commit 9fbd5fb

File tree

11 files changed

+16
-57
lines changed

11 files changed

+16
-57
lines changed

llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class StackInfoBuilder {
9191

9292
uint64_t getAllocaSizeInBytes(const AllocaInst &AI);
9393
void alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Align);
94-
bool isLifetimeIntrinsic(Value *V);
9594

9695
Value *readRegister(IRBuilder<> &IRB, StringRef Name);
9796
Value *getFP(IRBuilder<> &IRB);

llvm/lib/Target/AArch64/AArch64StackTagging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ bool AArch64StackTagging::runOnFunction(Function &Fn) {
575575
TagPCall->setName(Info.AI->getName() + ".tag");
576576
// Does not replace metadata, so we don't have to handle DbgVariableRecords.
577577
Info.AI->replaceUsesWithIf(TagPCall, [&](const Use &U) {
578-
return !memtag::isLifetimeIntrinsic(U.getUser());
578+
return !isa<LifetimeIntrinsic>(U.getUser());
579579
});
580580
TagPCall->setOperand(0, Info.AI);
581581

llvm/lib/Transforms/Coroutines/SpillUtils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,8 @@ struct AllocaUseVisitor : PtrUseVisitor<AllocaUseVisitor> {
226226
if (auto *S = dyn_cast<StoreInst>(U))
227227
if (S->getPointerOperand() == I)
228228
continue;
229-
if (auto *II = dyn_cast<IntrinsicInst>(U))
230-
if (II->isLifetimeStartOrEnd())
231-
continue;
229+
if (isa<LifetimeIntrinsic>(U))
230+
continue;
232231
// BitCastInst creats aliases of the memory location being stored
233232
// into.
234233
if (auto *BI = dyn_cast<BitCastInst>(U)) {

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,7 @@ bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
15181518

15191519
AI->replaceUsesWithIf(Replacement, [AICast, AILong](const Use &U) {
15201520
auto *User = U.getUser();
1521-
return User != AILong && User != AICast &&
1522-
!memtag::isLifetimeIntrinsic(User);
1521+
return User != AILong && User != AICast && !isa<LifetimeIntrinsic>(User);
15231522
});
15241523

15251524
memtag::annotateDebugRecords(Info, retagMask(N));

llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,8 @@ void collectMemAccessInfo(
497497
if (CallInst *CI = dyn_cast<CallInst>(&Inst))
498498
maybeMarkSanitizerLibraryCallNoBuiltin(CI, &TLI);
499499

500-
if (isa<MemIntrinsic>(Inst)) {
500+
if (isa<MemIntrinsic, LifetimeIntrinsic>(Inst))
501501
MemTypeResetInsts.push_back(&Inst);
502-
} else if (auto *II = dyn_cast<IntrinsicInst>(&Inst)) {
503-
if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
504-
II->getIntrinsicID() == Intrinsic::lifetime_end)
505-
MemTypeResetInsts.push_back(&Inst);
506-
}
507502
} else if (isa<AllocaInst>(Inst)) {
508503
MemTypeResetInsts.push_back(&Inst);
509504
}
@@ -819,11 +814,7 @@ bool TypeSanitizer::instrumentMemInst(Value *V, Instruction *ShadowBase,
819814
NeedsMemMove = isa<MemMoveInst>(MTI);
820815
}
821816
}
822-
} else if (auto *II = dyn_cast<IntrinsicInst>(I)) {
823-
if (II->getIntrinsicID() != Intrinsic::lifetime_start &&
824-
II->getIntrinsicID() != Intrinsic::lifetime_end)
825-
return false;
826-
817+
} else if (auto *II = dyn_cast<LifetimeIntrinsic>(I)) {
827818
Size = II->getArgOperand(0);
828819
Dest = II->getArgOperand(1);
829820
} else if (auto *AI = dyn_cast<AllocaInst>(I)) {

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,8 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpyLoad,
968968
append_range(srcUseList, U->users());
969969
continue;
970970
}
971-
if (const auto *IT = dyn_cast<IntrinsicInst>(U))
972-
if (IT->isLifetimeStartOrEnd())
973-
continue;
971+
if (isa<LifetimeIntrinsic>(U))
972+
continue;
974973

975974
if (U != C && U != cpyLoad) {
976975
LLVM_DEBUG(dbgs() << "Call slot: Source accessed by " << *U << "\n");

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,10 @@ void CodeExtractor::findAllocas(const CodeExtractorAnalysisCache &CEAC,
535535

536536
Instruction *Bitcast = cast<Instruction>(U);
537537
for (User *BU : Bitcast->users()) {
538-
IntrinsicInst *IntrInst = dyn_cast<IntrinsicInst>(BU);
538+
auto *IntrInst = dyn_cast<LifetimeIntrinsic>(BU);
539539
if (!IntrInst)
540540
continue;
541541

542-
if (!IntrInst->isLifetimeStartOrEnd())
543-
continue;
544-
545542
if (definedInRegion(Blocks, IntrInst))
546543
continue;
547544

@@ -1083,8 +1080,8 @@ static void eraseLifetimeMarkersOnInputs(const SetVector<BasicBlock *> &Blocks,
10831080
SetVector<Value *> &LifetimesStart) {
10841081
for (BasicBlock *BB : Blocks) {
10851082
for (Instruction &I : llvm::make_early_inc_range(*BB)) {
1086-
auto *II = dyn_cast<IntrinsicInst>(&I);
1087-
if (!II || !II->isLifetimeStartOrEnd())
1083+
auto *II = dyn_cast<LifetimeIntrinsic>(&I);
1084+
if (!II)
10881085
continue;
10891086

10901087
// Get the memory operand of the lifetime marker. If the underlying

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,9 +1777,8 @@ static Value *HandleByValArgument(Type *ByValType, Value *Arg,
17771777
// Check whether this Value is used by a lifetime intrinsic.
17781778
static bool isUsedByLifetimeMarker(Value *V) {
17791779
for (User *U : V->users())
1780-
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(U))
1781-
if (II->isLifetimeStartOrEnd())
1782-
return true;
1780+
if (isa<LifetimeIntrinsic>(U))
1781+
return true;
17831782
return false;
17841783
}
17851784

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,7 @@ bool llvm::wouldInstructionBeTriviallyDead(const Instruction *I,
497497
// are lifetime intrinsics then the intrinsics are dead.
498498
if (isa<AllocaInst>(Arg) || isa<GlobalValue>(Arg) || isa<Argument>(Arg))
499499
return llvm::all_of(Arg->uses(), [](Use &Use) {
500-
if (IntrinsicInst *IntrinsicUse =
501-
dyn_cast<IntrinsicInst>(Use.getUser()))
502-
return IntrinsicUse->isLifetimeStartOrEnd();
503-
return false;
500+
return isa<LifetimeIntrinsic>(Use.getUser());
504501
});
505502
return false;
506503
}

llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ void StackInfoBuilder::visit(OptimizationRemarkEmitter &ORE,
154154
}
155155
return;
156156
}
157-
auto *II = dyn_cast<IntrinsicInst>(&Inst);
158-
if (II && (II->getIntrinsicID() == Intrinsic::lifetime_start ||
159-
II->getIntrinsicID() == Intrinsic::lifetime_end)) {
157+
if (auto *II = dyn_cast<LifetimeIntrinsic>(&Inst)) {
160158
AllocaInst *AI = findAllocaForValue(II->getArgOperand(1));
161159
if (!AI) {
162160
Info.UnrecognizedLifetimes.push_back(&Inst);
@@ -261,11 +259,6 @@ void alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Alignment) {
261259
Info.AI = NewAI;
262260
}
263261

264-
bool isLifetimeIntrinsic(Value *V) {
265-
auto *II = dyn_cast<IntrinsicInst>(V);
266-
return II && II->isLifetimeStartOrEnd();
267-
}
268-
269262
Value *readRegister(IRBuilder<> &IRB, StringRef Name) {
270263
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
271264
MDNode *MD =

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,20 +2187,6 @@ bool SimplifyCFGOpt::hoistSuccIdenticalTerminatorToSwitchOrIf(
21872187
return Changed;
21882188
}
21892189

2190-
// Check lifetime markers.
2191-
static bool isLifeTimeMarker(const Instruction *I) {
2192-
if (auto II = dyn_cast<IntrinsicInst>(I)) {
2193-
switch (II->getIntrinsicID()) {
2194-
default:
2195-
break;
2196-
case Intrinsic::lifetime_start:
2197-
case Intrinsic::lifetime_end:
2198-
return true;
2199-
}
2200-
}
2201-
return false;
2202-
}
2203-
22042190
// TODO: Refine this. This should avoid cases like turning constant memcpy sizes
22052191
// into variables.
22062192
static bool replacingOperandWithVariableIsCheap(const Instruction *I,
@@ -2321,7 +2307,7 @@ static bool canSinkInstructions(
23212307
// backend may handle such lifetimes incorrectly as well (#104776).
23222308
// Don't sink lifetimes if it would introduce a phi on the pointer
23232309
// argument.
2324-
if (isLifeTimeMarker(I0) && OI == 1 &&
2310+
if (isa<LifetimeIntrinsic>(I0) && OI == 1 &&
23252311
any_of(Insts, [](const Instruction *I) {
23262312
return isa<AllocaInst>(I->getOperand(1)->stripPointerCasts());
23272313
}))

0 commit comments

Comments
 (0)