Loop Analysis in KeY
Tobias Gedell
gedell@cs.chalmers.se
4th KeY Workshop - L¨
- keberg June 9th, 2005 – p. 1/29
Loop Analysis in KeY Tobias Gedell gedell@cs.chalmers.se 4th KeY - - PowerPoint PPT Presentation
Loop Analysis in KeY Tobias Gedell gedell@cs.chalmers.se 4th KeY Workshop - L okeberg June 9th, 2005 p. 1/29 Introduction There are currently two ways of handling loops in KeY: Symbolic execution - repeated unwinding of loops Can be
Tobias Gedell
gedell@cs.chalmers.se
4th KeY Workshop - L¨
⊲ Symbolic execution - repeated unwinding of loops
⊲ Induction
4th KeY Workshop - L¨
⊲ Time consuming: If a.length is large than we need to execute
⊲ Not possible: If a.length is unknown we do not know when to
4th KeY Workshop - L¨
for(int i = 0; i < a.length; i++) a[i] = i; ...
4th KeY Workshop - L¨
for(int i = 0; i < a.length; i++) a[i] = i; ... {a[0] := 0} for(int i = 1; i < a.length; i++) a[i] = i; ...
4th KeY Workshop - L¨
for(int i = 0; i < a.length; i++) a[i] = i; ... {a[0] := 0} for(int i = 1; i < a.length; i++) a[i] = i; ... {a[0] := 0, a[1] := 1} for(int i = 2; i < a.length; i++) a[i] = i; ...
4th KeY Workshop - L¨
for(int i = 0; i < a.length; i++) a[i] = i; ... {a[0] := 0} for(int i = 1; i < a.length; i++) a[i] = i; ... {a[0] := 0, a[1] := 1} for(int i = 2; i < a.length; i++) a[i] = i; ... {a[0] := 0, a[1] := 1, a[2] := 2, . . .} ...
4th KeY Workshop - L¨
for(int i = 0; i < a.length; i++) a[i] = i; ... {a[0] := 0} for(int i = 1; i < a.length; i++) a[i] = i; ... {a[0] := 0, a[1] := 1} for(int i = 2; i < a.length; i++) a[i] = i; ... {a[0] := 0, a[1] := 1, a[2] := 2, . . .} ... We iteratively construct the update describing all side-effects of the loop.
4th KeY Workshop - L¨
{∀I ∈ [0, a.length − 1]. a[I] := I, i := a.length}
4th KeY Workshop - L¨
{a[I] := I}
4th KeY Workshop - L¨
{a[I] := I}
[0, a.length - 1]
4th KeY Workshop - L¨
{a[I] := I}
[0, a.length - 1]
4th KeY Workshop - L¨
{a[I] := I}
[0, a.length - 1]
{∀I ∈ [0, a.length − 1]. a[I] := I, i := a.length}
4th KeY Workshop - L¨
⊲ We can create a program analysis that calculates all assignments
4th KeY Workshop - L¨
⊲ We can create a program analysis that calculates all assignments
⊲ We can also let KeY compute the update.
4th KeY Workshop - L¨
⊲ The loop variable is monotonically increasing/decreasing.
4th KeY Workshop - L¨
⊲ The loop variable is monotonically increasing/decreasing.
⊲ The loop condition is of the form, i op e, where the value of e is not
4th KeY Workshop - L¨
⊲ The loop variable is monotonically increasing/decreasing.
⊲ The loop condition is of the form, i op e, where the value of e is not
⊲ The loop body does not terminate the loop by executing a break,
4th KeY Workshop - L¨
⊲ The loop variable is monotonically increasing/decreasing.
⊲ The loop condition is of the form, i op e, where the value of e is not
⊲ The loop body does not terminate the loop by executing a break,
⊲ There is no dependence between the loop iterations.
4th KeY Workshop - L¨
sv - the statement s where the loop variable has the value v. ⊲ Data dependence
4th KeY Workshop - L¨
⊲ Output dependence
4th KeY Workshop - L¨
4th KeY Workshop - L¨
4th KeY Workshop - L¨
4th KeY Workshop - L¨
4th KeY Workshop - L¨
4th KeY Workshop - L¨
LOOP Γ ⊢ <{.. old-rule(loop) ...}>φ, ∆, c Γ ⊢ <{.. replace-by-update(loop) ...}>φ, ∆, !c Γ ⊢ <{.. loop ...}>φ, ∆
where
loop ≡ for(..; ..; ..).. c = non-dependence-constraint(loop)
4th KeY Workshop - L¨
⊲ Transform offset += LEN_KEY
= offset0 + LEN_KEY * i. (2)
⊲ Create objects in updates. (1)
4th KeY Workshop - L¨
⊲ The dependence analysis is tailor made for solving constraints of a
⊲ We need quantified updates with a deterministic semantics for
⊲ Only works for a special class of loops.
4th KeY Workshop - L¨