This article includes alist of references,related reading, orexternal links,but its sources remain unclear because it lacksinline citations. Please helpimprove this article byintroducing more precise citations.(January 2016) (Learn how and when to remove this message) |
Incomputer science,rematerialization orremat is acompiler optimization which saves time by recomputing a value instead of loading it from memory. It is typically tightly integrated withregister allocation, where it is used as an alternative tospilling registers to memory. It was conceived byGregory Chaitin,Marc Auslander,Ashok Chandra,John Cocke,Martin Hopkins andPeter Markstein and implemented in the Pl.8 compiler for the 801 Minicomputer in the late 1970s. Later improvements were made byPreston Briggs,Keith D. Cooper, andLinda Torczon in 1992.
Traditional optimizations such ascommon subexpression elimination andloop invariant hoisting often focus on eliminating redundant computation. Since computation requiresCPU cycles, this is usually a good thing, but it has the potentially devastating side effect that it can increase the live ranges of variables and create many new variables, resulting in spills during register allocation. Rematerialization is nearly the opposite: it decreasesregister pressure by increasing the amount of CPU computation. To avoid adding more computation time than necessary, rematerialization is done only when the compiler can be confident that it will be of benefit — that is, when a register spill to memory would otherwise occur.
Rematerialization works by keeping track of the expression used to compute each variable, using the concept ofavailable expressions. Sometimes the variables used to compute a value are modified, and so can no longer be used to rematerialize that value. The expression is then said to no longer be available. Other criteria must also be fulfilled, for example a maximum complexity on the expression used to rematerialize the value; it would do no good to rematerialize a value using a complex computation that takes more time than a load. Usually the expression must also have noside effects.