Skip to content

Liveness Analysis

:material-circle-edit-outline: 约 291 个字 :material-clock-time-two-outline: 预计阅读时间 1 分钟

Chapter10.pdf

Flow Graph Terminology

image-20250428212828792

Uses and Defs

image-20250428213121810

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

image-20250428213411988

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

image-20250428213545707

Calculation of Liveness

image-20250428214616623

image-20250428215331545

Solving the Equations

我们试试前向分析

image-20250428215533092

image-20250428220015515

还是得后向分析更块收敛,因为 in 需要 out

image-20250428220229486

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

image-20250515124216137

image-20250515124505709

左边的情况就不需要给 s 和 t 添加冲突边,即两者可使用同一个寄存器

右边则冲突了

image-20250428224415053

  • 第一条即我定义时不应使用还会活跃的变量会使用的寄存器
  • 第二条即针对 MOVE 指令,我们不给 a 和 c 之间添加冲突边

此外,每条 MOVE 指令的两个变量用虚线连接,即合并边,如果已有干涉边就不用了