Static Analysis By Elimination Pavle Subotic, Andrew Santosa, - - PowerPoint PPT Presentation

static analysis by elimination
SMART_READER_LITE
LIVE PREVIEW

Static Analysis By Elimination Pavle Subotic, Andrew Santosa, - - PowerPoint PPT Presentation

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments Static Analysis By Elimination Pavle Subotic, Andrew Santosa, Bernhard Scholz pavle.subotic@it.uu.se , andrew.santosa@usyd.edu.au ,


slide-1
SLIDE 1

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Static Analysis By Elimination

Pavle Subotic, Andrew Santosa, Bernhard Scholz

pavle.subotic@it.uu.se, andrew.santosa@usyd.edu.au, bernhard.scholz@usyd.edu.au Uppsala University, Sweden University of Sydney, Australia Bytecode workshop 2013

Subotic, Santosa, Scholz Static Analysis By Elimination 1 / 32

slide-2
SLIDE 2

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Introduction

◮ Range Analysis

◮ Finds lower and upper bounds of variables values

◮ Challenges

◮ Conceptionally infinitely ascending chains ◮ Identify Loops

◮ Existing techniques

◮ Relies on code structure (e.g. Astr´

ee [Cousot et al., 2006])

◮ Require a pre-processing stage to discover loop headers

([Bourdoncle, 1993])

Subotic, Santosa, Scholz Static Analysis By Elimination 2 / 32

slide-3
SLIDE 3

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Introduction

◮ Our technique:

  • 1. Extends elimination-based data flow analysis to a lattice with

infinite ascending chains

  • 2. Fast termination
  • 3. Loops are detected intrinsically with in the data flow analysis.

◮ Implemented as an analysis pass in the LLVM compiler

framework.

Subotic, Santosa, Scholz Static Analysis By Elimination 3 / 32

slide-4
SLIDE 4

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Motivating Example

int i,k = 0; int arr[5]; . . .

B0

if (i < 5) goto B2 else goto B7;

B1

int j = 0; if (i < 5) goto B3 else goto B5;

B2

I1:i ≥ 0 ∧ j ≤ 3 if (arr[j] > arr[j+1]) goto B5 else goto B6;

B3

swap(arr, j, j+1); k++;

B4

I2:i == 5 ∧ k ≤ 25

B7

j++;

B6

i++;

B5

Subotic, Santosa, Scholz Static Analysis By Elimination 4 / 32

slide-5
SLIDE 5

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Background Existing Techniques Our Approach Implementation Experiments

Subotic, Santosa, Scholz Static Analysis By Elimination 5 / 32

slide-6
SLIDE 6

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Foundations

◮ Range Analysis is a complete lattice ◮ x ⊒ y, x is as or less precise than y ◮ ⊤ least element (least precise), ◮ ⊥ greatest element, so ⊤ ⊒ ⊥ ◮ ⊔ merges information ◮ ⊓ constrains information

Subotic, Santosa, Scholz Static Analysis By Elimination 6 / 32

slide-7
SLIDE 7

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Representing Information with Intervals

[-inf, inf] [-100, 100] [-200, -110] [-170,-150] [-155,-111] [-150, -150] ⊥ [-90, 10] [5, 100] [9,9] More info Join Meet

Subotic, Santosa, Scholz Static Analysis By Elimination 7 / 32

slide-8
SLIDE 8

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Some Existing Techniques

◮ Iterative Data-Flow Analysis [Kildall, 1973] :

◮ A technique for iteratively gathering variable information at

various points in a computer program.

◮ Operates on finite and short lattice structures

◮ Abstract Interpretation [Cousot & Cousot, 1977] :

◮ A theory of sound approximation of the semantics of computer

programs

◮ Approximating the execution behaviour of a computer program ◮ Additional theory of widening/narrowing to accelerate

convergence, required with high and unbounded domains

Subotic, Santosa, Scholz Static Analysis By Elimination 8 / 32

slide-9
SLIDE 9

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Iterative Data-Flow Analysis

◮ Input in the form of a Control Flow Graph (CFG) ◮ Initialise to ⊥ ◮ Every block transforms the values ◮ Iterate through CFG until a fixpoint is reached

Subotic, Santosa, Scholz Static Analysis By Elimination 9 / 32

slide-10
SLIDE 10

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Attempt 1: Iterative Data-Flow Analysis

if (a < 3) a = [5,5] condition: a < 3 condition: a >= 3 a = [1, 4]

[1,4] ⊓ [-∞, 2] = [1,2] [1,4] ⊓ [3, ∞] = [3,4] [5,5] ⊔ [3,4] = [3,5]

….

Subotic, Santosa, Scholz Static Analysis By Elimination 10 / 32

slide-11
SLIDE 11

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Attempt 1: Iterative Data-Flow Analysis

int I, k = 0 int arr[5] = ...

if i < 5 int j = 0 if j < 5 i++

invariant (2)

j++;

invariant (1)

if arr[j] > arr[j+1] swap(j, j+1) k++

*P1 *P2 *P4 *P3 b1 b2 b3 b4 b5 b6 b7 b8

Subotic, Santosa, Scholz Static Analysis By Elimination 11 / 32

slide-12
SLIDE 12

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

With Kleene Iteration

if (j <= 3) j++; k++; ... int j = 0; int i = 0; Subotic, Santosa, Scholz Static Analysis By Elimination 12 / 32

slide-13
SLIDE 13

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

With Kleene Iteration

∀li ∈ L.l1 ⊑ l2 ⊑ l3 ⊑ l4...⊑ ln

where: In the example, when the inner loop is first visited, we have that j → [0, 0] and k → [0, 0]. In subsequent visits, j → [0, 1] and k → [0, 1], j → [0, 2] and k → [0, 2], j → [0, 3] and k → [0, 3],

. . .

j → [0, 4] and k → [0, ∞].

Subotic, Santosa, Scholz Static Analysis By Elimination 13 / 32

slide-14
SLIDE 14

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

The Problem: Slow Termination

◮ Impractically slow termination

◮ Conditions not incorporating increasing variables ◮ Large loop bounds Subotic, Santosa, Scholz Static Analysis By Elimination 14 / 32

slide-15
SLIDE 15

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Attempt 2: Abstract Interpretation

◮ General method to compute a sound approximation of

program semantics

◮ Define an abstract semantics, soundly connect to the concrete

semantics

◮ Soundness ensures that if a property does not hold in the

abstract world, it will not hold in the concrete world

◮ Define widening and narrowing operator Subotic, Santosa, Scholz Static Analysis By Elimination 15 / 32

slide-16
SLIDE 16

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Abstract Interpretation

Widening and narrowing enforce termination

◮ Widening safely approximates the fixpoint solution ◮ Narrowing recovers some precision

Subotic, Santosa, Scholz Static Analysis By Elimination 16 / 32

slide-17
SLIDE 17

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Attempt 2: Abstract Interpretation

Red / FP Ext / FP Fixed-Point (FP) ⊤ ⊥ Less precision More precision widening narrowing

Subotic, Santosa, Scholz Static Analysis By Elimination 17 / 32

slide-18
SLIDE 18

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Abstract Interpretation

◮ Requires to know where to perform widening ◮ Previously approaches

◮ Use the syntax to determine the loop ◮ Perform complicated pre-processing to find loop headers Subotic, Santosa, Scholz Static Analysis By Elimination 18 / 32

slide-19
SLIDE 19

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Our Approach

◮ Discovers loops implicitly using elimination-based data flow

analysis

◮ Various acceleration techniques can be embedded such as

widening and narrowing

Subotic, Santosa, Scholz Static Analysis By Elimination 19 / 32

slide-20
SLIDE 20

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Our Approach

◮ Elimination-based approach: Based on Gaussian elimination ◮ Instead of iterating, we eliminate variables from the flow

equations

◮ substitution

e.g. x = true, y = x ∨ false y = true ∨ false

◮ loop-breaking

e.g. x = x ∧ true x = true

◮ When all variables are eliminated, we compute a solution

Subotic, Santosa, Scholz Static Analysis By Elimination 20 / 32

slide-21
SLIDE 21

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Elimination-based Approach Example - Diverging

i = 1; if(i < 1) goto B1; else goto B2;

B0

i =i + 1; goto B2;

B1

i =i + 1; goto B1;

B2

Figure: An Irreducible CFG of a Diverging Program

Subotic, Santosa, Scholz Static Analysis By Elimination 21 / 32

slide-22
SLIDE 22

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Elimination

EQS =              X0 = f0(⊤) X1 = f1(X0, X2) X2 = f2(X0, X1) Substitution EQS0 =              X0 = f0(⊤) X1 = f1(f0(⊤), X2) X2 = f2(f0(⊤), X1) Substitution EQS1 =              X0 = f0(⊤) X1 = f1(f0(⊤), X2) X2 = f2(f0(⊤), f1(f0(⊤), X2)) Break Loop, Substitute Back EQS2 =              X0 = f0(⊤) X1 = f1(f0(⊤), F∗(f2(f0(⊤), f1(f0(⊤), X2), X′

2)))

X2 = F∗(f2(f0(⊤), f1(f0(⊤), X2), X′

2)) Subotic, Santosa, Scholz Static Analysis By Elimination 22 / 32

slide-23
SLIDE 23

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Solve

◮ X1 = f1(f0(⊤), F∗(f2(f0(⊤), f1(f0(⊤), X2), X′ 2))) ◮ F∗ performs widening and narrowing

Subotic, Santosa, Scholz Static Analysis By Elimination 23 / 32

slide-24
SLIDE 24

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

LLVM Prototype

◮ Implemented in LLVM for core instructions ◮ Implementation supports both Intervals and Symbolic

Intervals

Subotic, Santosa, Scholz Static Analysis By Elimination 24 / 32

slide-25
SLIDE 25

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Block i j k B0 [0, 0]

[0,0] B1 [0, 5] [0, 5] [0, ∞] B2 [0, 4] [0, 0] [0, ∞] B3 [0, 4] [0, 5] [0, ∞] B4 [0, 4] [1, 4] [1, ∞] B5 [1, 5] [5, 5] [1, ∞] B6 [5, 5] [5, 5] [0, ∞]

Table: Motivating Example

Subotic, Santosa, Scholz Static Analysis By Elimination 25 / 32

slide-26
SLIDE 26

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Test Exact Bounded Part Widen Full Widen T1 1 5 T2 2 1 T3 2 1 T4 1 3 2 T5 10 T6 3 1 T7 1 2 T8 4 4 5 T9 1 5 T10 1 4 T11 2 2 T12 2 3 3 1 T13 1 2 2 T14 3 6 6 T15 3 5 4 All 27 45 26 6 (%) 26 43 25 6

Table: Variable Bounds Per Test Case

Subotic, Santosa, Scholz Static Analysis By Elimination 26 / 32

slide-27
SLIDE 27

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Summary

◮ Implemented in the LLVM Compiler Framework ◮ Feasibility shown using several test programs

Subotic, Santosa, Scholz Static Analysis By Elimination 27 / 32

slide-28
SLIDE 28

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

Some Future Work

◮ Conduct comparison with existing techniques ◮ Add non-numerical domains ◮ Improve precision through additional abstract domains

(Template Polyhedra [Sankaranarayanan et al., 2005])

◮ Integrate with acceleration methods such as policy

iteration [Gawlitza & Seidl, 2007]

Subotic, Santosa, Scholz Static Analysis By Elimination 28 / 32

slide-29
SLIDE 29

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

References I

Bourdoncle, F. (1993). Efficient chaotic iteration strategies with widenings. In In Proceedings of the International Conference on Formal Methods in Programming and their Applications (pp. 128–141).: Springer-Verlag. Cousot, P . & Cousot, R. (1977). Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In 4th POPL (pp. 238–252).

Subotic, Santosa, Scholz Static Analysis By Elimination 29 / 32

slide-30
SLIDE 30

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

References II

Cousot, P ., Cousot, R., Feret, J., Mauborgne, L., Min´ e, A., Monniaux, D., & Rival, X. (2006). Combination of abstractions in the ASTRE ´ E static analyzer. In 11th ASIAN (pp. 272–300). Gawlitza, T. & Seidl, H. (2007). Precise fixpoint computation through strategy iteration. In Proceedings of the 16th European conference on Programming, ESOP’07 (pp. 300–315). Berlin, Heidelberg: Springer-Verlag. Kildall, G. A. (1973). A unified approach to global program optimization. 1st POPL (pp. 194–206).

Subotic, Santosa, Scholz Static Analysis By Elimination 30 / 32

slide-31
SLIDE 31

Outline of Presentation Background Existing Techniques Our Approach Implementation Experiments

References III

Sankaranarayanan, S., Sipma, H. B., & Manna, Z. (2005). Scalable analysis of linear systems using mathematical programming. In In Proc. VMCAI, LNCS 3385 (pp. 25–41).: Springer.

Subotic, Santosa, Scholz Static Analysis By Elimination 31 / 32