# HG changeset patch # User Frits van Bommel # Date 1244461965 -7200 # Node ID ca31a8e9c42bb5434ada7a47960c73819a26dddb # Parent f62347c22d8156a0652f177fff81ff4f2a1c407b Oops, I accidentally pushed r1486 before the last touches were committed. diff -r f62347c22d81 -r ca31a8e9c42b gen/passes/GarbageCollect2Stack.cpp --- 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(); 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(Alloc->getType()) && "Capture is for pointers only!"); +bool isSafeToStackAllocate(Instruction* Alloc, DominatorTree& DT) { + assert(isa(Alloc->getType()) && "Allocation is not a pointer?"); Value* V = Alloc; SmallVector 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;