Liveness Analysis
:material-circle-edit-outline: 约 291 个字 :material-clock-time-two-outline: 预计阅读时间 1 分钟
Flow Graph Terminology
Uses and Defs
Liveness
Liveness: A variable is live on an edge if there is a directed path from that edge to a use of the variable that does not go through any def.
- this variable will be used later
- this variable will not be re-defined before being used
Live-in: A variable is live-in at a node if it is live on any of the in-edges of that node;
Live-out: A variable is live-out at a node if it is live on any of the out-edges of the node
Calculation of Liveness
Solving the Equations
我们试试前向分析
还是得后向分析更块收敛,因为 in 需要 out
MoreDiscussions
略
Interference Graphs
冲突图,用于寄存器分配
- Two types of interferences
- overlapping live ranges
- when a must be generated by an instruction that cannot address register r1, then a and r1 interfere
- 即该指令没法访问 r1
左边的情况就不需要给 s 和 t 添加冲突边,即两者可使用同一个寄存器
右边则冲突了
- 第一条即我定义时不应使用还会活跃的变量会使用的寄存器
- 第二条即针对 MOVE 指令,我们不给 a 和 c 之间添加冲突边
此外,每条 MOVE 指令的两个变量用虚线连接,即合并边,如果已有干涉边就不用了