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:
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: **
Analysis Comparison
Reaching Definitions | Live Variables | Available Expressions | |
---|---|---|---|
Domain | Set of definitions | Set of variables | Set of expressions |
Direction | Forwards | Backwards | Forwards |
May/Must | May | May | Must |
Boundary | OUT[entry] = ∅ \emptyset ∅ | IN[exit] = ∅ \emptyset ∅ | OUT[entry] = ∅ \emptyset ∅ |
Initialization | OUT[B] = ∅ \emptyset ∅ | IN[B] = ∅ \emptyset ∅ | OUT[B] = ∪ \cup ∪ |
Transfer function | OUT = | **gen ∪ \cup ∪ ** | (IN - kill) |
Meet | ∪ \cup ∪ | ∪ \cup ∪ | ∩ \cap ∩ |