90 likes | 198 Views
Argument Size Analysis Using Polyhedrons. Lunjin Lu (Advisor) Jie Ouyang (Student). Motivations. Purpose: To discover the relationship between arguments regarding their sizes Applications: Discovery of symbolic constant Loop invariant computations Termination analysis.
E N D
Argument Size Analysis Using Polyhedrons Lunjin Lu (Advisor) Jie Ouyang (Student)
Motivations • Purpose: • To discover the relationship between arguments regarding their sizes • Applications: • Discovery of symbolic constant • Loop invariant computations • Termination analysis
Structure of the Analyzor Original Program SCCs computation Abstract compilation Normalized Program Call Dependency Graph Fixed Point Evaluation Analysis Results
Bottom up Logic Program Analysis • Bottom up analysis is the reverse procedure of top down analysis. • Bottom up analysis starts from the stated facts in the program and derive the set of all correct answers. • The invariant derived by bottom up analysis is independent to any particular goals. • Bottom up analysis corresponds to the procedure of fixed point semantics evaluation.
Abstract Interpretation • Abstract intrepretation maps concrete domain to abstract domain • Variables are abstracted to their size norm(integer) • Example: list_length([X|Xs])=1+list_length(Xs) • A constraint system describing argument size relationships is generated for each clause • Example: append([],A,A) append(A,B,C):- A=0,B=C
Fixed Point Evaluation • Fixed Point Semantics captures the set of all correct answers of logic programs. • Analysis result is the fixed point semantics on the abstract domain. • Semi naive strategy is an efficient approach for evaluating fixed point. • Widening technique is applied to enforce the convergence of the evaluation.
Polyhedra and Program Analysis • Many program analysis problems on numerical domain can be modeled as constraint systems. • A polyhedron is a geometric representation of answers of algebraic constraint systems. • Abstraction of set operations on concrete semantics domain corresponds to polyhedron operations on abstract semantics domain. • Parma Polyhedra Library(PPL) is the new generation library implementing polyhedron operations.
Original Program Normalized Program quicksort(A,B):- A=0, B=0, A>=0, B>=0 quicksort(A,B):- A=1+C, partition(C,D,E,F), quicksort(E,G), quicksort(F,H), append(G,I,B), I=1+H, D>=0, C>=0, B>=0, E>=0, F>=0, G>=0, H>=0, A>=0, I>=0 partition(A,B,C,D):- A=1+E, C=1+F, G=0, B=0, partition(E,B,F,D), G>=0, E>=0, B>=0, F>=0, D>=0, A>=0, C>=0 partition(A,B,C,D):- A=1+E, D=1+F, G=0, B=0, partition(E,B,C,F), G>=0, E>=0, B>=0, C>=0, F>=0, A>=0, D>=0 partition(A,B,C,D):- A=0, C=0, D=0, B>=0, A>=0, C>=0, D>=0 append(A,B,C):- A=0,C=B,B>=0,A>=0,C>=0 append(A,B,C):-A=1+D,C=1+E,append(D,B,E),D>=0, B>=0,E>=0,A>=0,C>=0 quicksort([],[]). quicksort([X|Xs],Ys) :- partition(Xs,X,Left,Right), quicksort(Left,Ls), quicksort(Right,Rs), append(Ls,[X|Rs],Ys). partition([X|Xs],Y,[X|Ls],Rs) :- X =< Y, partition(Xs,Y,Ls,Rs). partition([X|Xs],Y,Ls,[X|Rs]) :- X > Y, partition(Xs,Y,Ls,Rs). partition([],Y,[],[]). append([],Ys,Ys). append([X|Xs],Ys,[X|Zs]) :- append(Xs,Ys,Zs). Sample Abstract Interpretation
Analysis Result Normalized Program quicksort(A,B):- A=0, B=0, A>=0, B>=0 quicksort(A,B):- A=1+C, partition(C,D,E,F), quicksort(E,G), quicksort(F,H), append(G,I,B), I=1+H, D>=0, C>=0, B>=0, E>=0, F>=0, G>=0, H>=0, A>=0, I=0 partition(A,B,C,D):- A=1+E, C=1+F, G=0, B=0, partition(E,B,F,D), G>=0, E>=0, B>=0, F>=0, D>=0, A>=0, C>=0 partition(A,B,C,D):- A=1+E, D=1+F, G=0, B=0, partition(E,B,C,F), G>=0, E>=0, B>=0, C>=0, F>=0, A>=0, D>=0 partition(A,B,C,D):- A=0, C=0, D=0, B>=0, A>=0, C>=0, D>=0 append(A,B,C):- A=0, C=B, B>=0, A>=0, C>=0 append(A,B,C):- A=1+D, C=1+E, append(D,B,E), D>=0, B>=0, E>=0, A>=0, C>=0 quicksort(A,B):- A>=0, A=B partition(A,B,C,D):- A>= C, B>=0, C>=0, A=C+D append(A,B,C):- A>=0, B>=0, A+B=C Sample Analysis Result