Optimizing Compilers
Inter-Procedural Dataflow Analysis Markus Schordan
Institut f¨ ur Computersprachen Technische Universit ¨ at Wien
Markus Schordan October 2, 2007 1
Syntax
P⋆ ::= begin D⋆ S⋆ end D ::= D; D | proc p(val x; res y) isℓn S endℓx S ::= ... | [call p(a, z)]ℓc
ℓr
Labeling scheme
- procedure declarations
ℓn: for entering the body ℓx: for exiting the body
- procedure calls
ℓc: for the call ℓr: for the return
Markus Schordan October 2, 2007 2
Analysing Procedures
We consider procedures with call-by-value and call-by-result parameters. Example:
begin proc fib(val z,u; res v) is if z<3 then (v:=u+1; r:=r+1) else ( call fib (z-1,u,v); call fib (z-2,v,v) ) end; r:=0; call fib(x,0,y) end
Markus Schordan October 2, 2007
Example Flow Graph
main proc fib(val z, u; res v)
[is]1
❄
[z < 3]2
❄ ❄
[v := u+1]3
❄
[r := r+1]4
❄ ❄
[end]9 [call fib(z-1, u, v)]5
6
❄
[call fib(z-2, v, v)]7
8
✛ ✛ ✛ ✛ ❄
[r := 0]10
❄
[call fib(x, 0, y)]11
12
❄ ✲ ✻
Markus Schordan October 2, 2007 4
Flow Graph for Procedures
[call p(a, z)]ℓc
ℓr
proc p(val x; res y) isℓn S endℓx init ℓc ℓn final {ℓr} {ℓx} blocks {[call p(a, z)]ℓc
ℓr}
{isℓn} ∪ blocks(S) ∪ {endℓx} labels {ℓc, ℓr} {ℓc, ℓr} ∪ labels(S) flow {(ℓc; ℓn), (ℓx; ℓr)} {(ℓn, init(S))} ∪ flow(S) ∪ {ℓ, ℓx) | ℓ ∈ final(S))}
- (ℓc; ℓn) is the flow corresponding to calling a procedure at ℓc and
entering the procedure body at ℓn and
- (ℓx; ℓr) is the flow corresponding to exiting a procedure body at ℓx
and returning to the call at ℓr.
Markus Schordan October 2, 2007 5
Naive Formulation
Treat the three kinds of flow, (ℓ1, ℓ2), (ℓc; ℓn), (ℓx; ℓr) in the same w Equation system: A◦(ℓ) = {A•(ℓ′) | (ℓ′, ℓ) ∈ F ∨ (ℓ′; ℓ) ∈ F} ⊔ ιℓ
E
A•(ℓ) = f A
ℓ (A◦(ℓ))
- both procedure calls (ℓc; ℓn) and procedure returns (ℓx; ℓr) a
treated like “goto’s”.
- there is no mechanism for ensuring that information flowing
(ℓc; ℓn) flows back along (ℓx; ℓr) to the same call
- intuitively, the equation system considers a much too large s
“paths” through the program and hence will be grossly impr (although formally on the safe side)
Markus Schordan October 2, 2007