Robert L. Bocchino Jr.
2007-Feb-17 05:50 UTC
[LLVMdev] Unused malloc/free don't get optimized
Hi,>> That's surprising to me. I thought there was a pass that converts >> malloc's that trivially dominate all free's and whose pointer doesn't >> escape would be lowered to alloca's -- but I looked and couldn't >> find one.I implemented a pass like this a while back. It's fairly sophisticated and relies on DSA to generate a call graph and do some other things. At one point I gave the pass to the PyPy folks; they reported that it worked except for a case that DSA couldn't handle -- I think it was variable length arrays. DSA may be able to handle that case now. I'm happy to give you my code if you want to use it and/or work it up for submission into LLVM. If you don't want the dependence on DSA, you could probably easily modify it to make it simpler and more conservative. Rob Robert L. Bocchino Jr. Ph.D. Student University of Illinois, Urbana-Champaign -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070216/1c8aecdc/attachment.html>
Robert L. Bocchino Jr. wrote:> Hi, > >>> That's surprising to me. I thought there was a pass that converts >>> malloc's that trivially dominate all free's and whose pointer doesn't >>> escape would be lowered to alloca's -- but I looked and couldn't find >>> one. > > I implemented a pass like this a while back. It's fairly sophisticated > and relies on DSA to generate a call graph and do some other things. At > one point I gave the pass to the PyPy folks; they reported that it > worked except for a case that DSA couldn't handle -- I think it was > variable length arrays. DSA may be able to handle that case now. I'm > happy to give you my code if you want to use it and/or work it up for > submission into LLVM. If you don't want the dependence on DSA, you > could probably easily modify it to make it simpler and more conservative.Sounds good! I'd like to see the code, even though I can't promise that I'll do anything with it in the near term. I'd rather not depend on DSA in particular. If it could depend on AliasAnalysis then it would grow stronger or weaker depending on what aliasing analysis was loaded at the time. Are there any special features of DSA that you're using? Nick Lewycky
Robert L. Bocchino Jr.
2007-Feb-22 16:21 UTC
[LLVMdev] Unused malloc/free don't get optimized
> Sounds good! I'd like to see the code, even though I can't promise > that > I'll do anything with it in the near term.OK. I've sent you the code in a separate email.> I'd rather not depend on DSA in particular. If it could depend on > AliasAnalysis then it would grow stronger or weaker depending on what > aliasing analysis was loaded at the time. Are there any special > features > of DSA that you're using?I glanced at the code again, and it looks like I use DSA to (1) construct the call graph and (2) identify things that would be unsafe to put on the stack, such as arrays, cyclic data structures, and allocations with escaping references. Right now these parts are pretty heavily dependent on DSA -- e.g., they make explicit use of the various DSA graphs. I'm sure you could modify the code to use AliasAnalysis instead of DSA, but I'm not sure what would be involved in that. Rob Robert L. Bocchino Jr. Ph.D. Student University of Illinois, Urbana-Champaign -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070222/9cf515e8/attachment.html>