weld-project / weld

High-performance runtime for data analytics applications
https://www.weld.rs
BSD 3-Clause "New" or "Revised" License
2.99k stars 260 forks source link

Remove unnecessary SIR assignments in loop bodies #492

Closed sppalkia closed 4 years ago

sppalkia commented 4 years ago

This adds a new SIR optimization pass that removes unnecessary assignment statements in the SIR in loop body functions.

@harumichi can you try this for your use case and make sure its sufficient?

Note: Because of various complexities in the way that loop bodies are called and how they reference symbols in the calling process (see comment in the patch), this patch is only applied to innermost loop body functions at the moment. Rather than trying to make this pass interprocedural to support other functions, it will be better to simplify the SIR/code generation by making the loop body function a closure over the values it accesses, and have the code generation access those values as parameters of this closure without requiring specific naming conventions (currently, the variable names in the loop body function must match variable names in the calling function, which makes deleting those variables more complex).