introduce a new abstraction for handling the memory object being

analyzed, and use it as common currency between the element use
collector and its clients.  Element collection is about to become
more nuanced.  NFC.


Swift SVN r10781
This commit is contained in:
Chris Lattner
2013-12-04 17:07:29 +00:00
parent c4f9cd1576
commit 6fdb5f9ce1
4 changed files with 150 additions and 146 deletions

View File

@@ -939,27 +939,29 @@ static void optimizeMemoryAllocations(SILFunction &Fn) {
auto I = BB.begin(), E = BB.end();
while (I != E) {
SILInstruction *Inst = I;
if (isa<AllocBoxInst>(Inst) || isa<AllocStackInst>(Inst)) {
DEBUG(llvm::errs() << "*** DI Optimize looking at: " << *Inst << "\n");
// Set up the datastructure used to collect the uses of the allocation.
SmallVector<DIMemoryUse, 16> Uses;
SmallVector<SILInstruction*, 4> Releases;
// Walk the use list of the pointer, collecting them.
collectDIElementUsesFromAllocation(Inst, Uses, Releases, true);
AllocOptimize(Inst, Uses, Releases).doIt();
// Carefully move iterator to avoid invalidation problems.
if (!isa<AllocBoxInst>(Inst) && !isa<AllocStackInst>(Inst)) {
++I;
if (Inst->use_empty()) {
Inst->eraseFromParent();
++NumAllocRemoved;
}
continue;
}
DEBUG(llvm::errs() << "*** DI Optimize looking at: " << *Inst << "\n");
DIMemoryObjectInfo MemInfo(Inst);
// Set up the datastructure used to collect the uses of the allocation.
SmallVector<DIMemoryUse, 16> Uses;
SmallVector<SILInstruction*, 4> Releases;
// Walk the use list of the pointer, collecting them.
collectDIElementUsesFrom(MemInfo, Uses, Releases, true);
AllocOptimize(Inst, Uses, Releases).doIt();
// Carefully move iterator to avoid invalidation problems.
++I;
if (Inst->use_empty()) {
Inst->eraseFromParent();
++NumAllocRemoved;
}
}
}
}