June 19, 2017 Compositional Recurrence Analysis Revisited Zachary Kincaid 1 Jason Breck 2 Ashkan Forouhi Boroujeni 2 Thomas Reps 2 , 3 1 Princeton University 2 University of Wisconsin-Madison 3 GrammaTech, Inc.
How can we apply loop analyses to recursive procedures?
• Algebraic program analysis [Tarjan JACM 1981] Over-approximating the behavior of loops convergence upon a property that over-approximates all reachable states. 1 Compute a path expression to a point of interest (e.g., an assertion) 2 Evaluate the path expression in the semantic algebra defining the analysis to yield a property that over-approximates all paths. • Iterative program analysis [Cousot & Cousot POPL 1977] • Repeatedly evaluate the program under an abstract semantics until
Over-approximating the behavior of loops convergence upon a property that over-approximates all reachable states. 1 Compute a path expression to a point of interest (e.g., an assertion) 2 Evaluate the path expression in the semantic algebra defining the analysis to yield a property that over-approximates all paths. • Iterative program analysis [Cousot & Cousot POPL 1977] • Repeatedly evaluate the program under an abstract semantics until • Algebraic program analysis [Tarjan JACM 1981]
outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges
outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges
outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges
outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges
outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges
outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges
outer: h+g [i >= n] [x > 100] a b c d e f g h (h+g)i inner: ((h+g)ij) (h+g)ik i j k l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [j >= n] [j < n] j := j + 1 skip end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 j := j + 1 if (j < n): goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 control flow edges def((h+g)ij) ∗ (h+g)ik
outer: h+g [i >= n] [x > 100] a b c d e f g h (h+g)i inner: ((h+g)ij) (h+g)ik i j k def((h+g)ij) (h+g)ik l m Path expression : Regular expression over alphabet of [j >= n] [j < n] j := j + 1 skip end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 j := j + 1 if (j < n): goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 control flow edges abc(def((h+g)ij) ∗ (h+g)ik) ∗ lm
Evaluation of a path expression: • Control flow edges D is a semantic function Space of program properties Composition operators • D = ⟨ D , ⊗ , ⊕ , ∗ , 0 , 1 ⟩ is a semantic algebra
Evaluation of a path expression: • Control flow edges D is a semantic function Space of program properties Composition operators • D = ⟨ D , ⊗ , ⊕ , ∗ , 0 , 1 ⟩ is a semantic algebra
Evaluation of a path expression: • Control flow edges D is a semantic function Space of program properties Composition operators • D = ⟨ D , ⊗ , ⊕ , ∗ , 0 , 1 ⟩ is a semantic algebra
Evaluation of a path expression: Space of program properties Composition operators • D = ⟨ D , ⊗ , ⊕ , ∗ , 0 , 1 ⟩ is a semantic algebra • � · � : Control flow edges → D is a semantic function
Evaluation of a path expression: Space of program properties Composition operators • D = ⟨ D , ⊗ , ⊕ , ∗ , 0 , 1 ⟩ is a semantic algebra • � · � : Control flow edges → D is a semantic function � abc(def((h+g)ij) ∗ (h+g)ik) ∗ lm � = � a � ⊗ � b � ⊗ � c � ( ⊗ � d � ⊗ � e � ⊗ � f � ) ∗ ( ⊗ ( � h � ⊕ � g � ) ⊗ � i � ⊗ � j � ) ∗ ⊗ ( � h � ⊕ � g � ) ⊗ � i � ⊗ � k � ⊗ � l � ⊗ � m �
Compositional recurrence analysis [Farzan & Kincaid FMCAD 2015] • x x x x x • • • D is the set of transition formulas in non-linear integer arithmetic � x := x + 1 � ≜ x ′ = x + 1 ∧ y ′ = y
Compositional recurrence analysis [Farzan & Kincaid FMCAD 2015] • • • D is the set of transition formulas in non-linear integer arithmetic � x := x + 1 � ≜ x ′ = x + 1 ∧ y ′ = y • ϕ ⊗ ψ ≜ ∃ x ′′ .ϕ [ x ′ �→ x ′′ ] ∧ ψ [ x �→ x ′′ ]
Compositional recurrence analysis [Farzan & Kincaid FMCAD 2015] • • D is the set of transition formulas in non-linear integer arithmetic � x := x + 1 � ≜ x ′ = x + 1 ∧ y ′ = y • ϕ ⊗ ψ ≜ ∃ x ′′ .ϕ [ x ′ �→ x ′′ ] ∧ ψ [ x �→ x ′′ ] • ϕ ⊕ ψ ≜ ϕ ∨ ψ
Compositional recurrence analysis [Farzan & Kincaid FMCAD 2015] • D is the set of transition formulas in non-linear integer arithmetic � x := x + 1 � ≜ x ′ = x + 1 ∧ y ′ = y • ϕ ⊗ ψ ≜ ∃ x ′′ .ϕ [ x ′ �→ x ′′ ] ∧ ψ [ x �→ x ′′ ] • ϕ ⊕ ψ ≜ ϕ ∨ ψ • ϕ ∗ ≜ ...
i k i k i k x k y k x k y k x k y k x k x k x k y k y k y k k i x y k k k i x y Polyhedron closed forms cl CRA’s iteration operator i recurrences while (i < n): if (*): x := x + i else y := y + i i := i + 1 loop abstraction loop body i < n ( x ′ = x + i ∧ y ′ = y ) ( ) ∧ ( y ′ = y + i ∧ x ′ = x ) ∨ ∧ i ′ = i + 1 ∧ n ′ = n ∃ k . k ≥ 0 ∧ i ′ = i + k ∧ x ′ + y ′ = x + y + k ( k + 1)/2 + k i 0 ∧ x ′ ≥ x ∧ y ′ ≥ y
i k x k y k x k y k CRA’s iteration operator x Polyhedron i k k k y while (i < n): k i x y closed forms cl recurrences loop abstraction x := x + i if (*): else loop body y := y + i i := i + 1 i < n ( x ′ = x + i ∧ y ′ = y ) ( ) ∧ ( y ′ = y + i ∧ x ′ = x ) ∨ ∧ i ′ = i + 1 ∧ n ′ = n i ( k ) = i ( k − 1) + 1 x ( k ) + y ( k ) = x ( k − 1) + y ( k − 1) + i x ( k ) ≥ x ( k − 1) y ( k ) ≥ y ( k − 1) ∃ k . k ≥ 0 ∧ i ′ = i + k ∧ x ′ + y ′ = x + y + k ( k + 1)/2 + k i 0 ∧ x ′ ≥ x ∧ y ′ ≥ y
CRA’s iteration operator while (i < n): cl closed forms Polyhedron recurrences loop body loop abstraction i := i + 1 if (*): x := x + i else y := y + i i < n ( x ′ = x + i ∧ y ′ = y ) ( ) ∧ ( y ′ = y + i ∧ x ′ = x ) ∨ ∧ i ′ = i + 1 ∧ n ′ = n i ( k ) = i (0) + k i ( k ) = i ( k − 1) + 1 x ( k ) + y ( k ) = x (0) + y (0) + k ( k + 1) x ( k ) + y ( k ) = x ( k − 1) + y ( k − 1) + i + k i 0 2 x ( k ) ≥ x ( k − 1) x ( k ) ≥ x (0) y ( k ) ≥ y ( k − 1) y ( k ) ≥ y (0) ∃ k . k ≥ 0 ∧ i ′ = i + k ∧ x ′ + y ′ = x + y + k ( k + 1)/2 + k i 0 ∧ x ′ ≥ x ∧ y ′ ≥ y
Recommend
More recommend