return false;
}
- void insertUse(Instruction &I, uint64_t Size, bool IsSplittable = false) {
+ void insertUse(Instruction &I, uint64_t Offset, uint64_t Size,
+ bool IsSplittable = false) {
uint64_t BeginOffset = Offset, EndOffset = Offset + Size;
// Completely skip uses which start outside of the allocation.
P.Partitions.push_back(New);
}
- bool handleLoadOrStore(Type *Ty, Instruction &I) {
+ bool handleLoadOrStore(Type *Ty, Instruction &I, uint64_t Offset) {
uint64_t Size = TD.getTypeStoreSize(Ty);
// If this memory access can be shown to *statically* extend outside the
return true;
}
- insertUse(I, Size);
+ insertUse(I, Offset, Size);
return true;
}
}
bool visitLoadInst(LoadInst &LI) {
- return handleLoadOrStore(LI.getType(), LI);
+ return handleLoadOrStore(LI.getType(), LI, Offset);
}
bool visitStoreInst(StoreInst &SI) {
if (SI.getOperand(0) == *U)
return markAsEscaping(SI);
- return handleLoadOrStore(SI.getOperand(0)->getType(), SI);
+ return handleLoadOrStore(SI.getOperand(0)->getType(), SI, Offset);
}
bool visitMemSetInst(MemSetInst &II) {
assert(II.getRawDest() == *U && "Pointer use is not the destination?");
ConstantInt *Length = dyn_cast<ConstantInt>(II.getLength());
- insertUse(II, Length ? Length->getZExtValue() : AllocSize - Offset, Length);
+ uint64_t Size = Length ? Length->getZExtValue() : AllocSize - Offset;
+ insertUse(II, Offset, Size, Length);
return true;
}
Offsets.DestEnd = Offset + Size;
}
- insertUse(II, Size, Offsets.IsSplittable);
+ insertUse(II, Offset, Size, Offsets.IsSplittable);
unsigned NewIdx = P.Partitions.size() - 1;
SmallDenseMap<Instruction *, unsigned>::const_iterator PMI;
II.getIntrinsicID() == Intrinsic::lifetime_end) {
ConstantInt *Length = cast<ConstantInt>(II.getArgOperand(0));
uint64_t Size = std::min(AllocSize - Offset, Length->getLimitedValue());
- insertUse(II, Size, true);
+ insertUse(II, Offset, Size, true);
return true;
}
std::pair<uint64_t, bool> &PHIInfo = P.PHIOrSelectSizes[&PN];
if (PHIInfo.first) {
PHIInfo.second = true;
- insertUse(PN, PHIInfo.first);
+ insertUse(PN, Offset, PHIInfo.first);
return true;
}
if (Instruction *EscapingI = hasUnsafePHIOrSelectUse(&PN, PHIInfo.first))
return markAsEscaping(*EscapingI);
- insertUse(PN, PHIInfo.first);
+ insertUse(PN, Offset, PHIInfo.first);
return true;
}
std::pair<uint64_t, bool> &SelectInfo = P.PHIOrSelectSizes[&SI];
if (SelectInfo.first) {
SelectInfo.second = true;
- insertUse(SI, SelectInfo.first);
+ insertUse(SI, Offset, SelectInfo.first);
return true;
}
if (Instruction *EscapingI = hasUnsafePHIOrSelectUse(&SI, SelectInfo.first))
return markAsEscaping(*EscapingI);
- insertUse(SI, SelectInfo.first);
+ insertUse(SI, Offset, SelectInfo.first);
return true;
}
P.DeadUsers.push_back(&I);
}
- void insertUse(uint64_t Size, Instruction &User) {
+ void insertUse(Instruction &User, uint64_t Offset, uint64_t Size) {
uint64_t BeginOffset = Offset, EndOffset = Offset + Size;
// If the use extends outside of the allocation, record it as a dead use
}
}
- void handleLoadOrStore(Type *Ty, Instruction &I) {
+ void handleLoadOrStore(Type *Ty, Instruction &I, uint64_t Offset) {
uint64_t Size = TD.getTypeStoreSize(Ty);
// If this memory access can be shown to *statically* extend outside the
if (Offset >= AllocSize || Size > AllocSize || Offset + Size > AllocSize)
return markAsDead(I);
- insertUse(Size, I);
+ insertUse(I, Offset, Size);
}
void visitBitCastInst(BitCastInst &BC) {
}
void visitLoadInst(LoadInst &LI) {
- handleLoadOrStore(LI.getType(), LI);
+ handleLoadOrStore(LI.getType(), LI, Offset);
}
void visitStoreInst(StoreInst &SI) {
- handleLoadOrStore(SI.getOperand(0)->getType(), SI);
+ handleLoadOrStore(SI.getOperand(0)->getType(), SI, Offset);
}
void visitMemSetInst(MemSetInst &II) {
ConstantInt *Length = dyn_cast<ConstantInt>(II.getLength());
- insertUse(Length ? Length->getZExtValue() : AllocSize - Offset, II);
+ uint64_t Size = Length ? Length->getZExtValue() : AllocSize - Offset;
+ insertUse(II, Offset, Size);
}
void visitMemTransferInst(MemTransferInst &II) {
ConstantInt *Length = dyn_cast<ConstantInt>(II.getLength());
- insertUse(Length ? Length->getZExtValue() : AllocSize - Offset, II);
+ uint64_t Size = Length ? Length->getZExtValue() : AllocSize - Offset;
+ insertUse(II, Offset, Size);
}
void visitIntrinsicInst(IntrinsicInst &II) {
II.getIntrinsicID() == Intrinsic::lifetime_end);
ConstantInt *Length = cast<ConstantInt>(II.getArgOperand(0));
- insertUse(std::min(AllocSize - Offset, Length->getLimitedValue()), II);
+ insertUse(II, Offset,
+ std::min(AllocSize - Offset, Length->getLimitedValue()));
}
- void insertPHIOrSelect(Instruction &User) {
+ void insertPHIOrSelect(Instruction &User, uint64_t Offset) {
uint64_t Size = P.PHIOrSelectSizes.lookup(&User).first;
// For PHI and select operands outside the alloca, we can't nuke the entire
return;
}
- insertUse(Size, User);
+ insertUse(User, Offset, Size);
}
void visitPHINode(PHINode &PN) {
if (PN.use_empty())
return markAsDead(PN);
- insertPHIOrSelect(PN);
+ insertPHIOrSelect(PN, Offset);
}
void visitSelectInst(SelectInst &SI) {
if (SI.use_empty())
return;
}
- insertPHIOrSelect(SI);
+ insertPHIOrSelect(SI, Offset);
}
/// \brief Unreachable, we've already visited the alloca once.