Module 5 Chapter 6 ICG
Module 5 Chapter 6 ICG
Chapter 6
Intermediate Code Generation
Prof. Maya B S
Assistant Professor
Department of CS&E
BIT, Bangalore
• The difference is that a node ‘N’ in a DAG has more than one parent.
• DAG not only represent expression , it gives the compiler important clues
regarding the generation of efficient code to evaluate the expression.
• The leaf for ‘a’ has 2 parents, because ‘a’ appears in the expressions.
• Two occurrence of the common subexpression b-c are represented by one
node , he node labeled by –
• That node has 2 parents , representing its two uses in the subexpression
a*(b-c) and (b-c)*d.
• Even though ‘b’ and ‘c’ appears twice in the complete expression, their
nodes each have one parent, since both uses are in the common
subexpression b-c.
• Similarly, the nodes returned at step8 and 9 are the same as those returned
at step 3 and 4(i.e p8=p3, p9=p4).
• Hence the nodes returned at step 10 must be the same at that returned at
step5. ie p10=p5.
• This integer historically has been called the value number for the node or for the
expression represented by the node.
• Above figure ,the node labeled + have value number 3 and its left and right children
have number 1 and 2 respectively.
1. ((x+y)-((x+y)*(x-y)))+((x+y)*(x-y))
2. Construct the DAG and identify the value number for the sub expression
of the following expressions, assuming + associates from left.
a) a+b+(a+b)
b) a+b+a+b
c) a+a+(a+a+a+(a+a+a+a))
• Instructions with unary operator like x=minus y or x=y do not use arg2.
note that for a copy statement like x=y, op is = while for most other
operations, the assignment operator is implied.
• Home work
All assignment in SSA are to variables with distinct names; Hence the term
static single assignment .
Below figure shows the same intermediate program in 3 address code and
in static single assignment form .subscripts distinguish each definition of
variables p and q in the SSA representation.
• Y=x*a;
• Has two control flow paths in which the variable ‘X’ gets defined.
• If we use different names for X in the true part and the false part of the
conditional statement , then which name should we use in assignment
y=x*a?