Mercurial > projects > ldc
changeset 1488:ca31a8e9c42b
Oops, I accidentally pushed r1486 before the last touches were committed.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Mon, 08 Jun 2009 13:52:45 +0200 |
parents | f62347c22d81 |
children | a048f31bf9f6 |
files | gen/passes/GarbageCollect2Stack.cpp |
diffstat | 1 files changed, 9 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/gen/passes/GarbageCollect2Stack.cpp Mon Jun 08 13:45:26 2009 +0200 +++ b/gen/passes/GarbageCollect2Stack.cpp Mon Jun 08 13:52:45 2009 +0200 @@ -50,12 +50,10 @@ struct Analysis { TargetData& TD; const Module& M; - DominatorTree& DT; CallGraph* CG; CallGraphNode* CGNode; const Type* getTypeFor(Value* typeinfo) const; - bool isSafeToStackAllocate(Instruction* Alloc); }; } @@ -319,6 +317,8 @@ CS.getInstruction()->eraseFromParent(); } +static bool isSafeToStackAllocate(Instruction* Alloc, DominatorTree& DT); + /// runOnFunction - Top level algorithm. /// bool GarbageCollect2Stack::runOnFunction(Function &F) { @@ -329,7 +329,7 @@ CallGraph* CG = getAnalysisIfAvailable<CallGraph>(); CallGraphNode* CGNode = CG ? (*CG)[&F] : NULL; - Analysis A = { TD, *M, DT, CG, CGNode }; + Analysis A = { TD, *M, CG, CGNode }; BasicBlock& Entry = F.getEntryBlock(); @@ -370,7 +370,7 @@ DEBUG(DOUT << "GarbageCollect2Stack inspecting: " << *Inst); - if (!info->analyze(CS, A) || !A.isSafeToStackAllocate(Inst)) + if (!info->analyze(CS, A) || !isSafeToStackAllocate(Inst, DT)) continue; // Let's alloca this! @@ -432,8 +432,8 @@ /// /// Based on LLVM's PointerMayBeCaptured(), which only does escape analysis but /// doesn't care about loops. -bool Analysis::isSafeToStackAllocate(Instruction* Alloc) { - assert(isa<PointerType>(Alloc->getType()) && "Capture is for pointers only!"); +bool isSafeToStackAllocate(Instruction* Alloc, DominatorTree& DT) { + assert(isa<PointerType>(Alloc->getType()) && "Allocation is not a pointer?"); Value* V = Alloc; SmallVector<Use*, 16> Worklist; @@ -498,8 +498,9 @@ // the original allocation. // That can only be true if it dominates the allocation. // FIXME: To be more precise, it's also only true if it's then used after - // the original allocation instruction gets performed again, but - // how to check that? + // the original allocation instruction gets performed again (and + // the instruction generating the derived pointer doesn't), but how + // to check that? if (!I->use_empty() && DT.dominates(I, Alloc)) return false;