Professional Documents
Culture Documents
• Exception:
– The store instruction had a label.
• Reduction
Reduction-in-strength
in strength transformations can be applied to replace
expensive operations
– x2 ; power(x, 2); x*x
– Fixed-point multiplication or division; shift
– Floating-point division by a constant can be approximated as multiplication by a constant
• Example:
E l
• Parsing-action
g conflicts can be resolved byy disambiguating
g g ppredicates
that can allow different selection strategies to be used in different
contexts.
(a - b) + e * (c + d)
1 . To generate machine code for an interior node with label k and two children with equal
labels do the following:
(a) Recursively generate code for the right child, using base=b + 1 . The result of the right child
appears in register Rb+k .
(b) Recursively generate code for the left child, using base b; the result appears in Rb+k-l
(c) Generate the instruction OP Rb+k , Rb+k
b+k-ll , Rb+k , where OP is the appropriate operation for
the interior node in question.
((a - b)) + e * (c
( + d))
C d for
Code f t2:
t2
For t3
F t3, using
i the
th original
i i l algorithm,
l ith
and the output is
Final output:
We then
W th need d bboth
th registers
i t ffor th
the lleft
ft child
hild
of the root, we need to generate the instruction
• Contiguous
g evaluation:
– Complete the evaluations of T1, T2, then evaluate root
• Noncontiguous evaluation:
– First evaluate part of T1 leaving the value in a register, next evaluate T2, then return to
evaluate the rest of T1
• Dynamic programming algorithm uses contiguous evaluation.
CS308 Compiler Theory 47
Contiguous Evaluation
• For the register machine in this section, we can prove that given any
machine-language
hi l program P to evaluate
l an expression
i tree T, we can
find an equivalent program p’ such that