[llvm-commits] [PATCH] Stack Coloring optimization

Jakob Stoklund Olesen stoklund at 2pi.dk
Thu Aug 30 11:57:57 PDT 2012


On Aug 30, 2012, at 2:51 AM, Nadav Rotem <nrotem at apple.com> wrote:

> 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.

About alias analysis. Andy was just showing me the scheduler's AA code. It is using the memory operands to find the underlying LLVM IR object. Loads and stores to different allocas are partitioned according to their underlying IR object.

Merging stack slots before the MI scheduler could invalidate this form of alias analysis since two IR allocas can share a stack slot.

/jakob




More information about the llvm-commits mailing list