[llvm-commits] [PATCH] Stack Coloring optimization

Nadav Rotem nrotem at apple.com
Thu Aug 30 02:51:41 PDT 2012


Hi All, 

I've been working on a new optimization for reducing the stack size.  Currently, when we declare allocas in LLVM IR, these allocas are directly translated to stack slots. And when we inline small functions into larger function, these allocas add up and take up lots of space.  In some cases we know that the use of the allocas is bounded by disjoint regions.  In this optimization we merge multiple disjoint slots into a single slot.  LLVM uses the lifetime markers for specifying the regions in which the allcoa is used.  This patch propagates the lifetime markers through SelectionDAG and makes them pseudo ops.  Later, a pre-register-allocator pass constructs live intervals which represent the lifeless of different stack slots. Next, the pass merges disjoint intervals.  Notice that lifetime markers and not perfect single-entry-single exit regions. They may be removed by optimizations, they may start with two markers, and end with one, or even not end at all! 

So, why is this done in codegen?  There are a number of reasons. First, joining allocas may hinder alias analysis. Second, in the future we would like to share the alloca space with spill slots.     

The inliner has a 'hack' for merging allocas when inlining functions. We plan to remove this hack once this pass is tuned and we see that there are no regressions.  Also, we plan to look at joining multiple non-disjoint slot into a bigger disjoint slot.

This work is based on code by Owen, and on feedback and ideas from a number of other engineers at Apple.

Any comments or review are much appreciated.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: stack_coloring_cr.diff
Type: application/octet-stream
Size: 35519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120830/ca4e4d47/attachment.obj>
-------------- next part --------------


Thanks,
Nadav


More information about the llvm-commits mailing list