MV(REG(t),
ADDT(MULT(REG(b), REG(b)),
MULT(MULT(REG(a), LI(4)), REG(c))))
computes t := b*b + 4*a*c. The nodes ADDT and
MULT are the trapping form of addition and multiplication,
and LI is used for integer constants. An infinite number
of registers are assumed by the model, however depending on the
target machine the first 0..K registers map onto the first
K registers on the target machine. Everything else is
assumed to be a pseudo-register. The REG node is used to
indicate a general purpose register.
The core MLRisc language makes no assumptions about instructions or calling convections of the target architecture. Trees can be created and combined in almost any form, with certain meaningless trees such as LOAD32(REAL 3.14127) being forbidden by the MLRisc type structure.
Such pure trees are nice but inadequate in real compilers. One needs to be able to propagate front end specific information, such as frame sizes and frame offsets where the actual values are only available after register allocation and spilling. One could add support for frames in MLRISC, however this becomes a slippery slope because some compilers (e.g. SML/NJ) do not have a conventional notion of frames --- indeed there is no runtime stack in the execution of SML/NJ. A frame organization for one person may not meet the needs for another, and so on. In MLRISC, the special requirements of different compilers is communicated into the MLRisc language, and subsequently into the optimizations phases, by specializing the MLRisc data structure with client specific information. There are currently three dimensions over which one could specialize the MLRisc language.
In the SML/NJ compiler, an encoding of a list of registers is passed to the garbage collector as the roots of live variables. This encoding cannot be computed until register allocation has been performed, therefore the integer literal encoding is represented as an abstract Constant.
Again, in the SML/NJ compiler, most stores are for initializing records in the allocation space, therefore representing every slot in the allocation space as a unique region allows one to commute most store instructions. Similarly, most loads are from immutable records, and a simple analysis marks these are being accesses to read-only memory. Read-only memory is characterized as having multiple uses but no definitions.
In the TIL compiler, a trace table is generated for every call site that records the set of live variables, their location (register or stack offset), and the type associated with the variable. This table is integrated into the program using the abstract pseudo-op mechanism. An interesting aspect of these tables is that they may need adjustment based on the results of register spilling.
The more convention use of the psuedo-op abstraction is to propagate function prologue and epilogue information.
The constants abstraction are created by a tree node called CONST. In the SML/NJ compiler, the tree that communicates garbage collection information looks like:
MV(maskReg, CONST{r110,r200,r300,r400 ...})
where maskReg is a dedicated register. On the DEC Alpha,
this would get translated to:
LDA maskReg, {encode(r110,r200,r300,r400, ...)}
which indicates that the alpha instruction set (and optimization
suite) know about these types of values. Further, after
register allocation, the LDA instruction may not be
sufficient as the encoding may result in a value that is too large
as an operand to LDA. Two instructions may ultimately be
required to load the encoding into the maskReg
register. This expansion is done during span-dependency resolution.
All these examples are intended to indicate that one intermediate representation and optimization suite does not fit all, but that the intermediate representation and optimization suite needs to be specialized to the needs of the client.