Syntax-Directed Translation (SDT), Three-Address Code & Register Liveness
Synthesized vs Inherited attributes, S-attributed vs L-attributed SDTs, Basic Block leader identification, SSA static single assignment, and Chaitin register interference graph coloring.
1. Synthesized vs Inherited Attributes & SDT Classes
- Synthesized Attribute: Computed at parent node strictly from attributes of 's children (and tokens at ). Evaluated naturally during bottom-up LR parsing.
- Inherited Attribute: Computed at child node from 's parent and/or siblings.
| SDT Class | Allowed Attributes | Compatible Parser Evaluation |
|---|---|---|
| S-Attributed SDT | Synthesized ONLY (semantic actions at right end of production) | Bottom-up LR stack evaluation |
| L-Attributed SDT | Synthesized + Inherited ONLY from parent or LEFT siblings () | Top-down LL(1) / Depth-First Left-to-Right traversal |
Every S-attributed SDT is automatically L-attributed ().
2. Basic Blocks, Leaders & SSA Form
In Three-Address Code (TAC), Leader instructions partition code into Basic Blocks:
- The very first instruction of the intermediate code is a leader.
- Any instruction that is the target of a conditional or unconditional jump is a leader.
- Any instruction that immediately follows a conditional or unconditional jump is a leader.
- Static Single Assignment (SSA): Every variable is assigned at most once statically (), inserting -functions at control-flow merge points.
- Minimum Registers via Graph Coloring: Construct the Register Interference Graph where vertices = variables and an edge exists iff and are simultaneously live. Minimum registers without spilling = Chromatic Number !
Practice Questions on This Chapter (4)
In an L-Attributed Syntax-Directed Definition for production , an inherited attribute of symbol may depend on:
In global register allocation via Chaitin’s algorithm, finding the minimum number of CPU registers needed for live variables without spilling reduces directly to:
How many lexical tokens are produced by a standard C lexical analyzer (using Maximal Munch) on the statement: printf("i = %d, &i = %x", i, &i);?
Consider the Syntax-Directed Definition: , and , with . Notice + (&) has higher precedence than * (#) and both are left-associative! Evaluate 2 # 3 & 5 # 4 & 1.