Static Analysis 04 Data Flow Analysis —Applications (II)

Data Flow Analysis —Applications (II)

(II) Live Variables Analysis

Live variables analysis tells whether the value of variable v at program point p could be used along some path in CFG starting at p. If so, v is live at p; otherwise, v is dead at p

  • Information of live variables can be used for register allocations.e.g., at some point all registers are full and we need to use one, then we should favor using a register with a dead value.

Understanding Live Variables Analysis

Backword!

Algorithm of Live Variables Analysis

一般情况下 May analysisi 初始化为 empty, Must analysis 初始化为 All

INPUT: CFG ( d e f B def_B defB and u s e B use_B useB computed for each basic block B)

OUTPUT: IN[B] and OUT[B] for each basic block B

METHOD:

Method

Example

Example

(III) Available Expressions Analysis

An expression x op y is available at program point p if (1) all paths from the entry to p must pass through the evaluation of x op y, and (2) after the last evaluation of x op y, there is no redefinition of x or y

  • This definition means at program p, we can replace expression x op y by the result of its last evaluation
  • The information of available expressions can be used for detecting global common subexpressions

Abstraction

Safe-approximation

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9J8r6dp7-1666225455041)(https://hurry11.oss-cn-nanjing.aliyuncs.com/img/image-20221006183636366.png)]

**What is available ** 可替换

O U T [ B ] = g e n B ∪ ( I N [ B ] − k i l l B ) OUT[B] = gen_B \cup (IN[B] - kill_B) OUT[B]=genB(IN[B]killB)

I N [ B ] = ∩ P    a    p r o d e c e s s o r    o f    B    O U T [ P ] IN[B] = \cap _{P \; a \; prodecessor \; of \; B} \;OUT[P] IN[B]=PaprodecessorofBOUT[P] All paths from entry to point p must pass through the evaluation of x op y

For safety of the analysis, it may report an expression as unavailable even if it is truly available (must analysis -> under-approximation)

Algorithm of Available Expressions Analysis

**INPUT: ** CFG ( $ kill_B$ and g e n B gen_B genB computed for each basic block B)

**OUTPUT: ** IN[B] and OUT[B] for each basic block B

**METHOD: **

Method

Final Result

Analysis Comparison

Reaching DefinitionsLive VariablesAvailable Expressions
DomainSet of definitionsSet of variablesSet of expressions
DirectionForwardsBackwardsForwards
May/MustMayMayMust
BoundaryOUT[entry] = ∅ \emptyset IN[exit] = ∅ \emptyset OUT[entry] = ∅ \emptyset
InitializationOUT[B] = ∅ \emptyset IN[B] = ∅ \emptyset OUT[B] = ∪ \cup
Transfer functionOUT =**gen ∪ \cup **(IN - kill)
Meet ∪ \cup ∪ \cup ∩ \cap
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值