[SROA] Switch the common variable name for the 'AllocaSlices' class to

'AS'.

Using 'S' as this was a terrible idea. Arguably, 'AS' is not much
better, but it at least follows the idea of using initialisms and
removes active confusion about the AllocaSlices variable and a Slice
variable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219963 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth
2014-10-16 21:11:55 +00:00
parent c62c42b1e4
commit 68ca48cd90

View File

@ -334,7 +334,7 @@ class AllocaSlices::SliceBuilder : public PtrUseVisitor<SliceBuilder> {
typedef PtrUseVisitor<SliceBuilder> Base; typedef PtrUseVisitor<SliceBuilder> Base;
const uint64_t AllocSize; const uint64_t AllocSize;
AllocaSlices &S; AllocaSlices &AS;
SmallDenseMap<Instruction *, unsigned> MemTransferSliceMap; SmallDenseMap<Instruction *, unsigned> MemTransferSliceMap;
SmallDenseMap<Instruction *, uint64_t> PHIOrSelectSizes; SmallDenseMap<Instruction *, uint64_t> PHIOrSelectSizes;
@ -343,14 +343,14 @@ class AllocaSlices::SliceBuilder : public PtrUseVisitor<SliceBuilder> {
SmallPtrSet<Instruction *, 4> VisitedDeadInsts; SmallPtrSet<Instruction *, 4> VisitedDeadInsts;
public: public:
SliceBuilder(const DataLayout &DL, AllocaInst &AI, AllocaSlices &S) SliceBuilder(const DataLayout &DL, AllocaInst &AI, AllocaSlices &AS)
: PtrUseVisitor<SliceBuilder>(DL), : PtrUseVisitor<SliceBuilder>(DL),
AllocSize(DL.getTypeAllocSize(AI.getAllocatedType())), S(S) {} AllocSize(DL.getTypeAllocSize(AI.getAllocatedType())), AS(AS) {}
private: private:
void markAsDead(Instruction &I) { void markAsDead(Instruction &I) {
if (VisitedDeadInsts.insert(&I)) if (VisitedDeadInsts.insert(&I))
S.DeadUsers.push_back(&I); AS.DeadUsers.push_back(&I);
} }
void insertUse(Instruction &I, const APInt &Offset, uint64_t Size, void insertUse(Instruction &I, const APInt &Offset, uint64_t Size,
@ -361,7 +361,7 @@ private:
DEBUG(dbgs() << "WARNING: Ignoring " << Size << " byte use @" << Offset DEBUG(dbgs() << "WARNING: Ignoring " << Size << " byte use @" << Offset
<< " which has zero size or starts outside of the " << " which has zero size or starts outside of the "
<< AllocSize << " byte alloca:\n" << AllocSize << " byte alloca:\n"
<< " alloca: " << S.AI << "\n" << " alloca: " << AS.AI << "\n"
<< " use: " << I << "\n"); << " use: " << I << "\n");
return markAsDead(I); return markAsDead(I);
} }
@ -379,12 +379,12 @@ private:
if (Size > AllocSize - BeginOffset) { if (Size > AllocSize - BeginOffset) {
DEBUG(dbgs() << "WARNING: Clamping a " << Size << " byte use @" << Offset DEBUG(dbgs() << "WARNING: Clamping a " << Size << " byte use @" << Offset
<< " to remain within the " << AllocSize << " byte alloca:\n" << " to remain within the " << AllocSize << " byte alloca:\n"
<< " alloca: " << S.AI << "\n" << " alloca: " << AS.AI << "\n"
<< " use: " << I << "\n"); << " use: " << I << "\n");
EndOffset = AllocSize; EndOffset = AllocSize;
} }
S.Slices.push_back(Slice(BeginOffset, EndOffset, U, IsSplittable)); AS.Slices.push_back(Slice(BeginOffset, EndOffset, U, IsSplittable));
} }
void visitBitCastInst(BitCastInst &BC) { void visitBitCastInst(BitCastInst &BC) {
@ -485,7 +485,7 @@ private:
DEBUG(dbgs() << "WARNING: Ignoring " << Size << " byte store @" << Offset DEBUG(dbgs() << "WARNING: Ignoring " << Size << " byte store @" << Offset
<< " which extends past the end of the " << AllocSize << " which extends past the end of the " << AllocSize
<< " byte alloca:\n" << " byte alloca:\n"
<< " alloca: " << S.AI << "\n" << " alloca: " << AS.AI << "\n"
<< " use: " << SI << "\n"); << " use: " << SI << "\n");
return markAsDead(SI); return markAsDead(SI);
} }
@ -535,7 +535,7 @@ private:
if (Offset.uge(AllocSize)) { if (Offset.uge(AllocSize)) {
SmallDenseMap<Instruction *, unsigned>::iterator MTPI = MemTransferSliceMap.find(&II); SmallDenseMap<Instruction *, unsigned>::iterator MTPI = MemTransferSliceMap.find(&II);
if (MTPI != MemTransferSliceMap.end()) if (MTPI != MemTransferSliceMap.end())
S.Slices[MTPI->second].kill(); AS.Slices[MTPI->second].kill();
return markAsDead(II); return markAsDead(II);
} }
@ -558,10 +558,10 @@ private:
bool Inserted; bool Inserted;
SmallDenseMap<Instruction *, unsigned>::iterator MTPI; SmallDenseMap<Instruction *, unsigned>::iterator MTPI;
std::tie(MTPI, Inserted) = std::tie(MTPI, Inserted) =
MemTransferSliceMap.insert(std::make_pair(&II, S.Slices.size())); MemTransferSliceMap.insert(std::make_pair(&II, AS.Slices.size()));
unsigned PrevIdx = MTPI->second; unsigned PrevIdx = MTPI->second;
if (!Inserted) { if (!Inserted) {
Slice &PrevP = S.Slices[PrevIdx]; Slice &PrevP = AS.Slices[PrevIdx];
// Check if the begin offsets match and this is a non-volatile transfer. // Check if the begin offsets match and this is a non-volatile transfer.
// In that case, we can completely elide the transfer. // In that case, we can completely elide the transfer.
@ -579,7 +579,7 @@ private:
insertUse(II, Offset, Size, /*IsSplittable=*/Inserted && Length); insertUse(II, Offset, Size, /*IsSplittable=*/Inserted && Length);
// Check that we ended up with a valid index in the map. // Check that we ended up with a valid index in the map.
assert(S.Slices[PrevIdx].getUse()->getUser() == &II && assert(AS.Slices[PrevIdx].getUse()->getUser() == &II &&
"Map index doesn't point back to a slice with this user."); "Map index doesn't point back to a slice with this user.");
} }
@ -667,7 +667,7 @@ private:
else else
// Otherwise the operand to the PHI/select is dead, and we can replace // Otherwise the operand to the PHI/select is dead, and we can replace
// it with undef. // it with undef.
S.DeadOperands.push_back(U); AS.DeadOperands.push_back(U);
return; return;
} }
@ -690,7 +690,7 @@ private:
// FIXME: This should instead be escaped in the event we're instrumenting // FIXME: This should instead be escaped in the event we're instrumenting
// for address sanitization. // for address sanitization.
if (Offset.uge(AllocSize)) { if (Offset.uge(AllocSize)) {
S.DeadOperands.push_back(U); AS.DeadOperands.push_back(U);
return; return;
} }
@ -970,11 +970,11 @@ private:
friend class PHIOrSelectSpeculator; friend class PHIOrSelectSpeculator;
friend class AllocaSliceRewriter; friend class AllocaSliceRewriter;
bool rewritePartition(AllocaInst &AI, AllocaSlices &S, bool rewritePartition(AllocaInst &AI, AllocaSlices &AS,
AllocaSlices::iterator B, AllocaSlices::iterator E, AllocaSlices::iterator B, AllocaSlices::iterator E,
int64_t BeginOffset, int64_t EndOffset, int64_t BeginOffset, int64_t EndOffset,
ArrayRef<AllocaSlices::iterator> SplitUses); ArrayRef<AllocaSlices::iterator> SplitUses);
bool splitAlloca(AllocaInst &AI, AllocaSlices &S); bool splitAlloca(AllocaInst &AI, AllocaSlices &AS);
bool runOnAlloca(AllocaInst &AI); bool runOnAlloca(AllocaInst &AI);
void clobberUse(Use &U); void clobberUse(Use &U);
void deleteDeadInstructions(SmallPtrSetImpl<AllocaInst *> &DeletedAllocas); void deleteDeadInstructions(SmallPtrSetImpl<AllocaInst *> &DeletedAllocas);
@ -1981,7 +1981,7 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
typedef llvm::InstVisitor<AllocaSliceRewriter, bool> Base; typedef llvm::InstVisitor<AllocaSliceRewriter, bool> Base;
const DataLayout &DL; const DataLayout &DL;
AllocaSlices &S; AllocaSlices &AS;
SROA &Pass; SROA &Pass;
AllocaInst &OldAI, &NewAI; AllocaInst &OldAI, &NewAI;
const uint64_t NewAllocaBeginOffset, NewAllocaEndOffset; const uint64_t NewAllocaBeginOffset, NewAllocaEndOffset;
@ -2028,14 +2028,14 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
IRBuilderTy IRB; IRBuilderTy IRB;
public: public:
AllocaSliceRewriter(const DataLayout &DL, AllocaSlices &S, SROA &Pass, AllocaSliceRewriter(const DataLayout &DL, AllocaSlices &AS, SROA &Pass,
AllocaInst &OldAI, AllocaInst &NewAI, AllocaInst &OldAI, AllocaInst &NewAI,
uint64_t NewAllocaBeginOffset, uint64_t NewAllocaBeginOffset,
uint64_t NewAllocaEndOffset, bool IsVectorPromotable, uint64_t NewAllocaEndOffset, bool IsVectorPromotable,
bool IsIntegerPromotable, bool IsIntegerPromotable,
SmallPtrSetImpl<PHINode *> &PHIUsers, SmallPtrSetImpl<PHINode *> &PHIUsers,
SmallPtrSetImpl<SelectInst *> &SelectUsers) SmallPtrSetImpl<SelectInst *> &SelectUsers)
: DL(DL), S(S), Pass(Pass), OldAI(OldAI), NewAI(NewAI), : DL(DL), AS(AS), Pass(Pass), OldAI(OldAI), NewAI(NewAI),
NewAllocaBeginOffset(NewAllocaBeginOffset), NewAllocaBeginOffset(NewAllocaBeginOffset),
NewAllocaEndOffset(NewAllocaEndOffset), NewAllocaEndOffset(NewAllocaEndOffset),
NewAllocaTy(NewAI.getAllocatedType()), NewAllocaTy(NewAI.getAllocatedType()),
@ -3099,7 +3099,7 @@ static Type *getTypePartition(const DataLayout &DL, Type *Ty,
/// appropriate new offsets. It also evaluates how successful the rewrite was /// appropriate new offsets. It also evaluates how successful the rewrite was
/// at enabling promotion and if it was successful queues the alloca to be /// at enabling promotion and if it was successful queues the alloca to be
/// promoted. /// promoted.
bool SROA::rewritePartition(AllocaInst &AI, AllocaSlices &S, bool SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
AllocaSlices::iterator B, AllocaSlices::iterator E, AllocaSlices::iterator B, AllocaSlices::iterator E,
int64_t BeginOffset, int64_t EndOffset, int64_t BeginOffset, int64_t EndOffset,
ArrayRef<AllocaSlices::iterator> SplitUses) { ArrayRef<AllocaSlices::iterator> SplitUses) {
@ -3158,8 +3158,9 @@ bool SROA::rewritePartition(AllocaInst &AI, AllocaSlices &S,
// the alloca's alignment unconstrained. // the alloca's alignment unconstrained.
if (Alignment <= DL->getABITypeAlignment(SliceTy)) if (Alignment <= DL->getABITypeAlignment(SliceTy))
Alignment = 0; Alignment = 0;
NewAI = new AllocaInst(SliceTy, nullptr, Alignment, NewAI =
AI.getName() + ".sroa." + Twine(B - S.begin()), &AI); new AllocaInst(SliceTy, nullptr, Alignment,
AI.getName() + ".sroa." + Twine(B - AS.begin()), &AI);
++NumNewAllocas; ++NumNewAllocas;
} }
@ -3175,19 +3176,19 @@ bool SROA::rewritePartition(AllocaInst &AI, AllocaSlices &S,
SmallPtrSet<PHINode *, 8> PHIUsers; SmallPtrSet<PHINode *, 8> PHIUsers;
SmallPtrSet<SelectInst *, 8> SelectUsers; SmallPtrSet<SelectInst *, 8> SelectUsers;
AllocaSliceRewriter Rewriter(*DL, S, *this, AI, *NewAI, BeginOffset, AllocaSliceRewriter Rewriter(*DL, AS, *this, AI, *NewAI, BeginOffset,
EndOffset, IsVectorPromotable, EndOffset, IsVectorPromotable,
IsIntegerPromotable, PHIUsers, SelectUsers); IsIntegerPromotable, PHIUsers, SelectUsers);
bool Promotable = true; bool Promotable = true;
for (auto & SplitUse : SplitUses) { for (auto & SplitUse : SplitUses) {
DEBUG(dbgs() << " rewriting split "); DEBUG(dbgs() << " rewriting split ");
DEBUG(S.printSlice(dbgs(), SplitUse, "")); DEBUG(AS.printSlice(dbgs(), SplitUse, ""));
Promotable &= Rewriter.visit(SplitUse); Promotable &= Rewriter.visit(SplitUse);
++NumUses; ++NumUses;
} }
for (AllocaSlices::iterator I = B; I != E; ++I) { for (AllocaSlices::iterator I = B; I != E; ++I) {
DEBUG(dbgs() << " rewriting "); DEBUG(dbgs() << " rewriting ");
DEBUG(S.printSlice(dbgs(), I, "")); DEBUG(AS.printSlice(dbgs(), I, ""));
Promotable &= Rewriter.visit(I); Promotable &= Rewriter.visit(I);
++NumUses; ++NumUses;
} }
@ -3273,8 +3274,8 @@ removeFinishedSplitUses(SmallVectorImpl<AllocaSlices::iterator> &SplitUses,
/// \brief Walks the slices of an alloca and form partitions based on them, /// \brief Walks the slices of an alloca and form partitions based on them,
/// rewriting each of their uses. /// rewriting each of their uses.
bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &S) { bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
if (S.begin() == S.end()) if (AS.begin() == AS.end())
return false; return false;
unsigned NumPartitions = 0; unsigned NumPartitions = 0;
@ -3282,9 +3283,10 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &S) {
SmallVector<AllocaSlices::iterator, 4> SplitUses; SmallVector<AllocaSlices::iterator, 4> SplitUses;
uint64_t MaxSplitUseEndOffset = 0; uint64_t MaxSplitUseEndOffset = 0;
uint64_t BeginOffset = S.begin()->beginOffset(); uint64_t BeginOffset = AS.begin()->beginOffset();
for (AllocaSlices::iterator SI = S.begin(), SJ = std::next(SI), SE = S.end(); for (AllocaSlices::iterator SI = AS.begin(), SJ = std::next(SI),
SE = AS.end();
SI != SE; SI = SJ) { SI != SE; SI = SJ) {
uint64_t MaxEndOffset = SI->endOffset(); uint64_t MaxEndOffset = SI->endOffset();
@ -3322,8 +3324,8 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &S) {
// we'll have to rewrite uses and erase old split uses. // we'll have to rewrite uses and erase old split uses.
if (BeginOffset < MaxEndOffset) { if (BeginOffset < MaxEndOffset) {
// Rewrite a sequence of overlapping slices. // Rewrite a sequence of overlapping slices.
Changed |= Changed |= rewritePartition(AI, AS, SI, SJ, BeginOffset, MaxEndOffset,
rewritePartition(AI, S, SI, SJ, BeginOffset, MaxEndOffset, SplitUses); SplitUses);
++NumPartitions; ++NumPartitions;
removeFinishedSplitUses(SplitUses, MaxSplitUseEndOffset, MaxEndOffset); removeFinishedSplitUses(SplitUses, MaxSplitUseEndOffset, MaxEndOffset);
@ -3362,8 +3364,8 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &S) {
uint64_t PostSplitEndOffset = uint64_t PostSplitEndOffset =
SJ == SE ? MaxSplitUseEndOffset : SJ->beginOffset(); SJ == SE ? MaxSplitUseEndOffset : SJ->beginOffset();
Changed |= rewritePartition(AI, S, SJ, SJ, MaxEndOffset, PostSplitEndOffset, Changed |= rewritePartition(AI, AS, SJ, SJ, MaxEndOffset,
SplitUses); PostSplitEndOffset, SplitUses);
++NumPartitions; ++NumPartitions;
if (SJ == SE) if (SJ == SE)
@ -3426,13 +3428,13 @@ bool SROA::runOnAlloca(AllocaInst &AI) {
Changed |= AggRewriter.rewrite(AI); Changed |= AggRewriter.rewrite(AI);
// Build the slices using a recursive instruction-visiting builder. // Build the slices using a recursive instruction-visiting builder.
AllocaSlices S(*DL, AI); AllocaSlices AS(*DL, AI);
DEBUG(S.print(dbgs())); DEBUG(AS.print(dbgs()));
if (S.isEscaped()) if (AS.isEscaped())
return Changed; return Changed;
// Delete all the dead users of this alloca before splitting and rewriting it. // Delete all the dead users of this alloca before splitting and rewriting it.
for (Instruction *DeadUser : S.getDeadUsers()) { for (Instruction *DeadUser : AS.getDeadUsers()) {
// Free up everything used by this instruction. // Free up everything used by this instruction.
for (Use &DeadOp : DeadUser->operands()) for (Use &DeadOp : DeadUser->operands())
clobberUse(DeadOp); clobberUse(DeadOp);
@ -3444,16 +3446,16 @@ bool SROA::runOnAlloca(AllocaInst &AI) {
DeadInsts.insert(DeadUser); DeadInsts.insert(DeadUser);
Changed = true; Changed = true;
} }
for (Use *DeadOp : S.getDeadOperands()) { for (Use *DeadOp : AS.getDeadOperands()) {
clobberUse(*DeadOp); clobberUse(*DeadOp);
Changed = true; Changed = true;
} }
// No slices to split. Leave the dead alloca for a later pass to clean up. // No slices to split. Leave the dead alloca for a later pass to clean up.
if (S.begin() == S.end()) if (AS.begin() == AS.end())
return Changed; return Changed;
Changed |= splitAlloca(AI, S); Changed |= splitAlloca(AI, AS);
DEBUG(dbgs() << " Speculating PHIs\n"); DEBUG(dbgs() << " Speculating PHIs\n");
while (!SpeculatablePHIs.empty()) while (!SpeculatablePHIs.empty())