Class 31: Canonicalizing trees, continued
Held Friday, November 20, 1998
- Don't forget to get me topics and times for your presentations.
- One group has chosen a topic: garbage collection.
- I'd also be happy to hear debates on the old topics, now that
you have more information.
- Next Monday, we'll look at basic blocks and conditional branches.
- Next Wednesday, we'll discuss the interpreter I've written for
- Canonical IRTs do not contain
These are handled by putting the canonical IRTs in a sequence.
- Canonical trees restrict the use of
CALL, so that each
CALL is only used in a
MOVE (which stores
the result somewhere) or
EXP (which throws away the
- Note that we do not need the ``spine'' I suggested. Rather, we need
to make sure that we ``bubble up'' all the sequencing nodes to the
- If we know that
s can be executed before
is evaluated, as in
BINOP(plus, ESEQ(s,e1), e2), we
can move the
ESEQ to the top.
- If we know that
e1 must be evaluated before
is executed, as in
BINOP(plus, e1, ESEQ(s,e2)), then
we must create a new temporary,
MOVE e1 to that temporary,
and then put stuff in the right sequence.
- The second technique leads to some unnecesarily big trees. If the
s) does not affect the value of the expression
e1), then we can safely do
without augmenting the tree.
- When is it safe? For example,
if the expression is a constant or the statement does nothing.
- Appel says that a statement and expression commute if
the statement has no side-effects that can alter the result
produced by e (and, conversely, the expression has no side effects
that can alter the effects of the statement).
- It may be impossible to determine at compile time whether a statement
and expression commute. For example, do
MEM(TEMP(2)) commute? Not if
TEMP(2) contain the same value (which is often only possible
to determine at run time).
- If we can determine that a statement and expression do commute, then we
can do simpler translations.
- For example,
BINOP(op, e1, ESEQ(s, e2)) can be rewritten as
ESEQ(s, BINOP(op, e1, e2)) if s and e1 commute.
- What are some of the other intersting things that sequence nodes can
- We'll consider each in turn (sorry, I'm not giving away the answers).
- We've handled the sequencing part of canonicalization, but not the
calls (except in relation to sequencing).
- Basically, any
CALL that is not used in a legal format
must be translated.
- Start with:
ESEQ(MOVE(TEMP(t), CALL(fun,args)), TEMP(t))
- You need to be careful on the recursion.
- Consider the C/Java fragment
A[++i] = i.
- This might be written in Tiger as the fragment
A[(i = i + 1; i)] = i
(ugly, isn't it).
- What IRT should we generate?
- How do we canonicalize it?
- Created Friday, November 20, 1998. Some parts filled in from the
previous day's class, but mostly new.
- On Monday, November 23, 1998, moved a short example to the next
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Mon Nov 23 10:59:04 1998.
This page generated on Mon Nov 23 11:35:20 1998 by SiteWeaver.
Contact our webmaster at email@example.com