Detect Escaping Variables
Tiger in Stratego -- Compilation by Program Transformation
The default escaping variables analysis is very conservative and makes all variables escaping by annotating their declaration with
Stack(x)
.
In order for your compiler to produce good code is necessary to put as many variables as possible into registers.
Extend module
Tiger-VarEscape.r
in directory
tas2ir/
in the
TigerTrans package to detect only really escaping variables.
Sketch of the algorithm
- In principle every variable is non-escaping, i.e., its name
x
in its declaration should be transformed into Reg(x)
.
- If a variable is used inside a function that is different than the function it is declared in, the variable is escaping and its name
x
in its declaration should be transformed into Stack(x)
.
The analysis can be very nicely expressed in a single traversal over the program tree using dynamic rules.
--
EelcoVisser - 16 Nov 2001