Title: Interval Partitioning of a Flow Graph
1Interval Partitioning of a Flow Graph
- Input a flow graph G (N, E, n0).
- Output a partition of G into a set of disjoint
intervals. - Method for each n, compute I(n).
- I(n) n
- while there exists a node m ? n0
- all of whose predecessors are in I(n)
- do I(n) I(n) ? m
- The headers of the intervals are chosen as
follows - construct I(n0) and select all nodes in that
interval, - while there is a node m not yet selected
- but with a selected predecessor
- do construct I(m) and select all nodes in that
interval. - Note the order of selection does not affect
final partitioning
2Interval Partitioning Example
- Initially I(1) 1
- -1 is selected
- Pick node 2
- I(2) 2 then execute while loop
- I(2) 2 U 3 U 4 U 5
- 2, 3, 4, 5 are selected
- Note After 1, the only node we can pick is 2,
because it is the only one with selected
predecessor!
1
Natural loop
2
3
4
5
- Note node 2 dominates nodes 3, 4, 5.
- node 2 is the only entry of the interval
(header).
3Interval Graphs
- From the intervals of one flow graph G one may
construct a new flow graph I(G) by the following
rules - Nodes The nodes of I(G) correspond to the
intervals in the interval partition of G. - Initial node The initial node of I(G) is the
interval that contains the initial node of G. - Edges There is an edge from interval I to
interval J if and only if there is an edge from
some node in I to the header of J. - Note There could not be an edge entering some
node n of J other than the header, because there
would be no way n could have added to J in
interval partitioning algorithm.
4Interval Graphs (Cont)
- Limit flow graph of G Applying interval
partitioning and interval graph construction in
alternation, leads to a sequence of graphs G,
I(G), I(I(G)) In(G) where the nodes of In(G)
are in one interval. In(G) is the limit.
Property A flow graph is reducible if and only
if its limit flow graph is a single node
(historic definition).
5T1-T2 Analysis
- Motivation A convenient way to achieve same
effect as interval analysis. - Definition Repeatedly apply two simple trans
formations to flow graphs - - T1 If n is a node with a loop, i.e., an edge
n?n, delete that edge. - - T2 If there is a node n ? n0 that has a
unique predecessor, m, then m may consume n by
deleting n and making all successors of n
(including m, possibly) be successors of m. - Facts
- - By applying (T1 T2 )k (G) until no further
application is possible then a unique flow-graph
results. - - The flow graph (T1 T2 )k (G) is the limit
flow-graph of G.
6Example of T1 - T2 Analysis
T2
T1
T2
T2
a
a
a
ab
abcd
b
c
b
cd
b
cd
cb
d
7Example of T1 - T2 Analysis
Regions a set of nodes N with a header
dominating all other nodes. Property While
reducing a flow graph with T1-T2 following holds
all the time
T2
T1
T2
T2
a
a
a
ab
abcd
b
c
b
cd
b
cd
cb
d
T2
T1
T2
T2
- A node represents a region of G.
- An edge from a to b represents a set of edges of
G. Each is from some node in a to header of b. - -Each node and edge of G is represented by
exactly one node or edge of the current graph.
8Optimizations of Basic Blocks
- Equivalent transformations Two basic block are
equivalent if they compute the same set of
expressions. - -Expressions are the values of the live
variables at the exit of the block. - Two important classes of local transformations
- -structure preserving transformations
- common sub expression elimination
- dead code elimination
- renaming of temporary variables
- interchange of two independent adjacent
statements. - -algebraic transformations (countlessly many)
- simplify expressions
- replace expensive operations with cheaper ones.
9The DAG Representation of Basic Blocks
- Directed acyclic graphs (DAGs) give a picture of
how the value computed by each statement in the
basic block is used in the subsequent statements
of the block. - Definition a dag for a basic block is a directed
acyclic graph with the following labels on nodes - leaves are labeled with either variable names or
constants. - they are unique identifiers
- from operators we determine whether l- or
r-value. - represent initial values of names. Subscript with
0. - interior nodes are labeled by an operator symbol.
- Nodes are also (optionally) given a sequence of
identifiers for labels. - - interior node ? computed values
- - identifiers in the sequence have that value.
10Example of DAG Representation
- t1 4i
- t2 at1
- t3 4i
- t4 bt3
- t5 t2 t4
- t6 prod t5
- prod t6
- t7 i 1
- i t7
- if i lt 20 goto 1
t6, prod
t5
prod
t4
(1)
t2
lt
t1, t3
t7, i
a
b
20
4
i0
1
- Three address code Corresponding DAG
- Utility Constructing a dag from 3AS is a good
way of determining - common sub expressions (expressions computed more
than once), - which names are used inside the block but
evaluated outside, - which statements of the block could have their
computed value used outside the block.
11Constructing a DAG
- Input a basic block. Statements (i) x y op z
(ii) x op y (iii) x y - Output a dag for the basic block containing
- - a label for each node. For leaves an
identifier - constants are permitted. For
interior nodes an operator symbol. - - for each node a (possibly empty) list of
attached identifiers - constants not permitted. - Method Initially assume there are no nodes, and
node is undefined. - If node(y) is undefined created a leaf labeled
y, let node(y) be this node. In case(i) if
node(z) is undefined create a leaf labeled z and
that leaf be node(z). - In case(i) determine if there is a node labeled
op whose left child is node(y) and right child is
node(z). If not create such a node, let be n.
case(ii), (iii) similar. - Delete x from the list attached to node(x).
Append x to the list of identify for node n and
set node(x) to n.