260 likes | 433 Views
Program Schemas In Dependence Analysis. Sebastian Danicic (Goldsmiths) Mark Harman (King’s) Rob Hierons (Brunel) John Howroyd (Scotland) Mike Laurence (Liverpool). Program Schemas. A program schema is a program where all expressions are replaced by symbolic expressions. if p(x)
E N D
Program Schemas In Dependence Analysis Sebastian Danicic (Goldsmiths) Mark Harman (King’s) Rob Hierons (Brunel) John Howroyd (Scotland) Mike Laurence (Liverpool)
Program Schemas A program schema is a program where all expressions are replaced by symbolic expressions. if p(x) then x:=f(x); else y:=g(k); if (x<1) then x:=x+2; else y:=x+2; if (x<1) then x:=x+2; else y:=x+2; Different programs in the same equivalence class.
Two Classes of Schema • Free Schemas For every path, , through S, there is a program in the equivalence class of S that takes . • Liberal Schemas The same symbolic expression does not occur more than once along any path.
History of Schemas • Schemas were first introduced in the late 1950s for compiler optimisation and verification. • Two schemas are equivalent if and only if for all interpretations the resulting programs are semantically identical. • The most important problems concerned decidability of equivalence. • By the 1970s interest in schemas waned due to the scarcity of positive results.
Positive Results in Schematology • Equivalence of Ianov Schemas is decidable. (Ianov 1958) • Equivalence of Progressive Schemas is decidable. (Paterson 1967 - PhD) • Equivalence of Through Schemas is decidable. (Sabelfeld 1990)
Linear Schemas A linear schema is one where each function and predicate symbol occurs at most once. • Importantly for us, linear schemas are at exactly the same level of abstraction as program dependence analysis. • If equivalence of linear schemas is decidable the so is dataflow minimal slicing.
Linearity Makes Things Easier! • Considering only schemas to be linear, which is exactly what we want for dataflow analysis has also enabled us to prove some more positive results about schemas. • Linearity captures the “normal” abstraction: we never need worry about things like two variables having the same value in all interpretations.
Our Positive Results on Schemas • Equivalence of Conservative Free Linear Schemas is decidable. (TCS - 2003) • Equivalence of Liberal Free Linear Schemas is decidable. (M.Laurence PhD thesis) • For Liberal Free Linear Schemas, traditional program dependence produces dataflow minimal slices.(submitted to TCS)
What is Dependence Analysis? P . . . . . . . . . Which bits of P affect this? Which bits of P affect variable x? Which bits can we delete without affecting x? Slicing
Slicing • Slicing program P on a variable x deletes statements from P to produce a program P’ which behaves the same with respect to variable x. • P is a slice of itself - useless! • We want slices to be small - useful!
Applications of Dependence Analysis • Testing and Debugging Cuts down search space when looking for bugs • Program Restructuring Helps us convert monolithic programs into many procedures • Program Comprehension and Maintenance Prism
The Traditional Approach to PDA Program CFG Start while(i>0) { x=x+1; i=i-1; } i > 0 exit x=x+1 i=i-1
Data & Control Dependence 1 x=x+1 2 y=5 3 x > 0 4 5 a=y b=x+1 Node 5 is data dependent on Node 1 Node 5 is control dependent on Node 3
Data Dependence & Control Dependence x:=x+1; y:=5; A B C D E is Data Dependent on A E is Control Dependent on C x>0 E z:=x; z:=x+1;
Dataflow Abstraction Program Dependence Analysis is reduced to a graph theoretic problem where the only informationused is the set of defined variables and the set of referenced variables of each node. x=y+a+b x=2*y-a-b
Transitivity Assumption In Program Dependence Analysis, Node A is considered to be dependent on Node B if and only if there is a chain of nodes A=A1…An=B where Ai is either data or control dependent on Ai+1
Limitations of Traditional Program Dependence Analysis The final value of x is not dependent on the loop, so the loop is removed. But the loop does have an effect on the final value of x! Program dependence does not consider as a value. while(true) { y:=y+1; } x:=5; x=5; Slice w.r.t. x
So using traditional program dependence analysis a program P and its slice agree in all states where P terminates. Now what about ? while p(x) { if q(k) then k:=f(k); else{ k:=g(k); x:=h(x); } } Slice on x. PDA removes nothing. But can we?
So using traditional program dependence analysis a program P and its slice agree in all states where P terminates. Now what about ? This line can be removed as its only contribution is to non-termination. So why isn’t it? while p(x) { if q(k) then k:=f(k); else{ k:=g(k); x:=h(x); } } Slice on x. PDA removes nothing. But can we?
while p(x) { if q(k) then k:=f(k); else{ k:=g(k); x:=h(x); } } while x>0 { if k>0 then k:=k-1; else{ k:=k+17; x:=x-1; } } while x<0 { if k>0 then k:=k+1; else{ k:=k+1; x:=x+5; } }
Traditional Dependence analysis is producing “spurious dependences”. Let S be the schema on the previous slide and S’ be the schema with the statement k:=g(k) removed. For all programs P in the equivalence class of the schema S, the corresponding program P’ in the equivalence class of S’ will be a slice of P with respect to x. S’ is a smaller slice than that produced by traditional dependence analysis although it is constructed at the same level of abstraction. Smaller slices are good!
The Dataflow Minimality problem S’ is a minimal slice of S. That is, should we delete more statement to produce a schema S’’ then there will exist an interpretation, I, such that program P’’ is not a slice of P. Where P and P’’ are the result of respectively interpreting S and S’’ in I.
Open Question Are dataflow minimal slices computable? I.e Given a schema S are the minimal slices of S computable. This result is obviously not true about programs. But at the schema level it may be.
Future Work • Is equivalence of linear schemas decidable? • Is freeness of linear schemas decidable? • Non standard semantics for schemas to match non standard semantics for program dependence.
The End Any Questions?