Reformat some bits of AllocaPromoter and simplify the name and type of

our visiting datastructures in the AllocaPromoter/SSAUpdater path of
SROA. Also shift the order if clears around to be more consistent.

No functionality changed here, this is just a cleanup.

llvm-svn: 188144
This commit is contained in:
Chandler Carruth 2013-08-11 01:03:18 +00:00
parent 705c5951ca
commit 45b136f4cf
1 changed files with 20 additions and 21 deletions

View File

@ -733,9 +733,9 @@ class AllocaPromoter : public LoadAndStorePromoter {
SmallVector<DbgValueInst *, 4> DVIs; SmallVector<DbgValueInst *, 4> DVIs;
public: public:
AllocaPromoter(const SmallVectorImpl<Instruction*> &Insts, SSAUpdater &S, AllocaPromoter(const SmallVectorImpl<Instruction *> &Insts, SSAUpdater &S,
AllocaInst &AI, DIBuilder &DIB) AllocaInst &AI, DIBuilder &DIB)
: LoadAndStorePromoter(Insts, S), AI(AI), DIB(DIB) {} : LoadAndStorePromoter(Insts, S), AI(AI), DIB(DIB) {}
void run(const SmallVectorImpl<Instruction*> &Insts) { void run(const SmallVectorImpl<Instruction*> &Insts) {
// Retain the debug information attached to the alloca for use when // Retain the debug information attached to the alloca for use when
@ -3364,12 +3364,12 @@ void SROA::deleteDeadInstructions(SmallPtrSet<AllocaInst*, 4> &DeletedAllocas) {
} }
static void enqueueUsersInWorklist(Instruction &I, static void enqueueUsersInWorklist(Instruction &I,
SmallVectorImpl<Use *> &UseWorklist, SmallVectorImpl<Instruction *> &Worklist,
SmallPtrSet<Use *, 8> &VisitedUses) { SmallPtrSet<Instruction *, 8> &Visited) {
for (Value::use_iterator UI = I.use_begin(), UE = I.use_end(); UI != UE; for (Value::use_iterator UI = I.use_begin(), UE = I.use_end(); UI != UE;
++UI) ++UI)
if (VisitedUses.insert(&UI.getUse())) if (Visited.insert(cast<Instruction>(*UI)))
UseWorklist.push_back(&UI.getUse()); Worklist.push_back(cast<Instruction>(*UI));
} }
/// \brief Promote the allocas, using the best available technique. /// \brief Promote the allocas, using the best available technique.
@ -3396,29 +3396,29 @@ bool SROA::promoteAllocas(Function &F) {
DEBUG(dbgs() << "Promoting allocas with SSAUpdater...\n"); DEBUG(dbgs() << "Promoting allocas with SSAUpdater...\n");
SSAUpdater SSA; SSAUpdater SSA;
DIBuilder DIB(*F.getParent()); DIBuilder DIB(*F.getParent());
SmallVector<Instruction*, 64> Insts; SmallVector<Instruction *, 64> Insts;
// We need a worklist to walk the uses of each alloca. // We need a worklist to walk the uses of each alloca.
SmallVector<Use *, 8> UseWorklist; SmallVector<Instruction *, 8> Worklist;
SmallPtrSet<Use *, 8> VisitedUses; SmallPtrSet<Instruction *, 8> Visited;
SmallVector<Instruction *, 32> DeadInsts; SmallVector<Instruction *, 32> DeadInsts;
for (unsigned Idx = 0, Size = PromotableAllocas.size(); Idx != Size; ++Idx) { for (unsigned Idx = 0, Size = PromotableAllocas.size(); Idx != Size; ++Idx) {
AllocaInst *AI = PromotableAllocas[Idx]; AllocaInst *AI = PromotableAllocas[Idx];
UseWorklist.clear(); Insts.clear();
VisitedUses.clear(); Worklist.clear();
Visited.clear();
enqueueUsersInWorklist(*AI, UseWorklist, VisitedUses); enqueueUsersInWorklist(*AI, Worklist, Visited);
while (!UseWorklist.empty()) { while (!Worklist.empty()) {
Use *U = UseWorklist.pop_back_val(); Instruction *I = Worklist.pop_back_val();
Instruction &I = *cast<Instruction>(U->getUser());
// FIXME: Currently the SSAUpdater infrastructure doesn't reason about // FIXME: Currently the SSAUpdater infrastructure doesn't reason about
// lifetime intrinsics and so we strip them (and the bitcasts+GEPs // lifetime intrinsics and so we strip them (and the bitcasts+GEPs
// leading to them) here. Eventually it should use them to optimize the // leading to them) here. Eventually it should use them to optimize the
// scalar values produced. // scalar values produced.
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I)) { if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
assert(II->getIntrinsicID() == Intrinsic::lifetime_start || assert(II->getIntrinsicID() == Intrinsic::lifetime_start ||
II->getIntrinsicID() == Intrinsic::lifetime_end); II->getIntrinsicID() == Intrinsic::lifetime_end);
II->eraseFromParent(); II->eraseFromParent();
@ -3428,12 +3428,12 @@ bool SROA::promoteAllocas(Function &F) {
// Push the loads and stores we find onto the list. SROA will already // Push the loads and stores we find onto the list. SROA will already
// have validated that all loads and stores are viable candidates for // have validated that all loads and stores are viable candidates for
// promotion. // promotion.
if (LoadInst *LI = dyn_cast<LoadInst>(&I)) { if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
assert(LI->getType() == AI->getAllocatedType()); assert(LI->getType() == AI->getAllocatedType());
Insts.push_back(LI); Insts.push_back(LI);
continue; continue;
} }
if (StoreInst *SI = dyn_cast<StoreInst>(&I)) { if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
assert(SI->getValueOperand()->getType() == AI->getAllocatedType()); assert(SI->getValueOperand()->getType() == AI->getAllocatedType());
Insts.push_back(SI); Insts.push_back(SI);
continue; continue;
@ -3442,11 +3442,10 @@ bool SROA::promoteAllocas(Function &F) {
// For everything else, we know that only no-op bitcasts and GEPs will // For everything else, we know that only no-op bitcasts and GEPs will
// make it this far, just recurse through them and recall them for later // make it this far, just recurse through them and recall them for later
// removal. // removal.
DeadInsts.push_back(&I); DeadInsts.push_back(I);
enqueueUsersInWorklist(I, UseWorklist, VisitedUses); enqueueUsersInWorklist(*I, Worklist, Visited);
} }
AllocaPromoter(Insts, SSA, *AI, DIB).run(Insts); AllocaPromoter(Insts, SSA, *AI, DIB).run(Insts);
Insts.clear();
while (!DeadInsts.empty()) while (!DeadInsts.empty())
DeadInsts.pop_back_val()->eraseFromParent(); DeadInsts.pop_back_val()->eraseFromParent();
AI->eraseFromParent(); AI->eraseFromParent();