Chapter 9: Code generation

DAG representation of basic blocks

. useful data structures for implementing transformations on basic blocks

. gives a picture of how value computed by a statement is used in subsequent statements

. good way of determining common sub-expressions

. A dag for a basic block has following labels on the nodes

- leaves are labeled by unique identifiers, either variable names or constants

- interior nodes are labeled by an operator symbol

- nodes are also optionally given a sequence of identifiers for labels

DAG (Directed Acyclic Graphs) are useful data structures for implementing transformations on basic blocks. A DAG gives a picture of how the value computed by a statement in a basic block is used in subsequent statements of the block. Constructing a DAG from three-address statements is a good way of determining common sub-expressions (expressions computed more than once) within a block, determining which names are used inside the block but evaluated outside the block, and determining which statements of the block could have their computed value used outside the block. A DAG for a basic block is a directed cyclic graph with the following labels on nodes: 1. Leaves are labeled by unique identifiers, either variable names or constants. From the operator applied to a name we determine whether the l-value or r-value of a name is needed; most leaves represent r- values. The leaves represent initial values of names, and we subscript them with 0 to avoid confusion with labels denoting "current" values of names as in (3) below. 2. Interior nodes are labeled by an operator symbol. 3. Nodes are also optionally given a sequence of identifiers for labels. The intention is that interior nodes represent computed values, and the identifiers labeling a node are deemed to have that value.