Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
Analysis and Verification “of and with”Horn Clauses (using the system)
Manuel Hermenegildo 1,2 M. Carro1,2 P. Lopez-Garcıa3,1 U. Liqat1
J. Morales1 P. Chico4 R. Haemmerle2 A. Serrano1
1IMDEA Software Institute
2Technical University of Madrid (UPM)
3Spanish Research Council (CSIC)
4Elasticbox
COST Rich Model Toolkit Workshop, Malta, June 16-17, 2013
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 1 / 80
Outline
Part I The Ciao approach to Analysis and verificationof Constraint Logic Programs
The programming languageThe analysis, verification, and testing model
Part II The Ciao approach to Analysis and verificationof other paradigmsusing Constraint Logic Programs as IR
CLP (Horn Clauses) as intermediate representationUser-defined resource analysis/verif. of Java bytecodeEnergy analysis/verification of (Xmos) C programs
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 2 / 80
Outline
Part I The Ciao approach to Analysis and verificationof Constraint Logic Programs
The programming languageThe analysis, verification, and testing model
Part II The Ciao approach to Analysis and verificationof other paradigmsusing Constraint Logic Programs as IR
CLP (Horn Clauses) as intermediate representationUser-defined resource analysis/verif. of Java bytecodeEnergy analysis/verification of (Xmos) C programs
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 3 / 80
Logic and constraint programming: Mid-90’s:
Prolog/CLPs (dynamic), Mercury (static), Ciao (combination).Static analysis (abstract interpretation) maturing (aliasing, modes,data sizes, execution cost, .... scalability, incrementality, ...)
The Ciao approach [CP′94,AADEBUG′97,ICLP′99,...]
Start from a small, but very extensible (LP-based) kernel– a language-building language.Build gradually extensions in layers on top of it.Incorporating the most useful features from different prog. paradigms.
Offer the best of the dynamic and static language approaches.I Provide the flexibility of dynamic languages,
F Dynamic typing, dynamic load, dynamic program modification,meta-programming, top level, call (eval), scripts, ...
I But with guaranteed safety and efficiency.F Assertion checking, modules, itf files, separate/incr. compilation, small
executables, embeddability, high-performance, ...
Support the programmer with a great environment.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 4 / 80
Ciao EnablersModule system design:
I Allows separating dynamic and static code.I Allows global analysis, separate/incremental compilation.
Syntactic and semantic extension mechanism (packages):I All language features are in libraries (loaded, combined per module):
F Predicates, functions, higher order, constraints, objects, ...F Tabling, other search rules, ASP, ... concurrency, parallelism.F Full ISO-Prolog support –also via a library.
The Ciao assertions modelI Optional assertions, expressing rich (possibly undecidable) properties.I Integrated verification/certification, testing, diagnosis (in comp. loop).I Use throughout of safe approx. (abstract interpretation), “best effort.”
Compile-time and run-time technology:I Analysis, partial evaluation, profiling, ...I Several back ends (including Javascript)I Also bytecode (abstract machine written in Ciao dialect, specializable)
High performance through optimization, not language restriction.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 5 / 80
Extension: Constraint Logic Programming
Natural extension of LP: very general relations between variablesallowed (beyond Herbrand term equality).
Execution inserts new constraints in the constraint store (CS).
Constraint solver checks consistency of CS.
Examplep(X,Y) :-
X #> 5,
X #< 2.
p(X,Y) :-
X #>= 2,
Y #=< 2,
X #= Y.
?- p(X,Y).
X = 2, Y = 2
1. p(X,Y) CS=�
3. X #<2.
2. X #>5, X #<2. CS=�
CS={X>5}
CS={X>5, X<2}4. fail.
5. X #≥2, Y #≤2, X#=Y.
6. Y #≤2, X#=Y.
7. X#=Y.
8. true.
CS=�
CS={X≥2}
CS={X≥2, Y≤2}
CS={X=2, Y=2}
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 6 / 80
Extension: Tabling (OLDT resolution)
Properties:I Conservative extension of Prolog/SLD.I Avoids recomputations.I Better termination properties; easier to reason about termination.
F Ensures termination for “bounded term size” programs.F In other cases, less dependent on clause / subgoal order.
Applications:I Deductive databases.I Natural language (left recursive grammars).I Fixpoint: program analysis, reachability analysis. . .I Well Founded Semantics:
F A predicate can be defined based on its negation.F Semantic web reasoning.
I . . .
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 7 / 80
CLP+Tabling
Early work:I Theoretical; deductive databases, bottom-up deduction.
Goal-directed, top-down poses interesting questions.I Existing approaches in LP: XSB, TCHR, Ciao TCLP.I Still evolving.
Some issues:I Checking applicability of calls and previous solutions: entailment
(vs., e.g., call variant or call abstraction)Goal Answers
X > 3 ∧ Y = 1{X > 3} p(X, Y) X > 3 ∧ Y = 2
X > 5 ∧ Y = 3
What can we say about{X > 4} p(X, Y)?
I Answers to new (subsumed) calls: conj. of input + answer constraints.Goal Answers
X > 4 ∧ X > 3 ∧ Y = 1 ≡ X > 4 ∧ Y = 1{X > 4} p(X, Y) X > 4 ∧ X > 3 ∧ Y = 2 ≡ X > 4 ∧ Y = 2
X > 4 ∧ X > 5 ∧ Y = 3 ≡ X > 5 ∧ Y = 3
I Non subsumed calls: cannot use stored answer constraint safely.I Useful to project constraint store on call variables.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 8 / 80
Tabled CLP applicationsSome Experiments with Timed Automata
UPPAAL is a fast tool built specifically for TA verification:I Developed since 1999.
Ciao is a general-purpose, multi-paradigm language.
Ciao TCLP UPPAAL
Fisher 2 0 0
Fisher 3 12 1
Fisher 4 270 44
Fisher 5 10 576 4 514
Tried to select comparable UPPAAL and Ciao options.
Additionally: in Ciao, full programming power.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 9 / 80
Demo: properties, types, predicates, functions, higher order,
constraints, breadth-first search, tabling, ...
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 10 / 80
The Assertion Language
[BDD+97, PBH97, HPB99, PBH00b, MLGH09]
+
Comparator
(Incl. VCgen)Normalizer
& Lib Itf.
Assertion
Analysis
Info
[[P]]
Program
P
:− trust
I
Builtins/
Libs
RT Check
verificationwarning
compile−timeerror
verified
(ACC) code
certificate
Unit Test
AnalysisStatic
possiblerun−time error
:− check
:− false
:− checked
:− texec
:− check
:− test
(optimized)
PREPROCESSOR
Assertions optional, can be added at any time. Provide partial spec.Sets of pre/post/global triples (+ “status” field, documentation, ...).Used everywhere, for many purposes (incl. doc gen., foreign itf).System makes it worthwhile for the programmer to include them.Part of the programming language and “runnable.”
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 11 / 80
The Analyses (will return to them)
+(optimized)
Comparator(Incl. VCgen)
Normalizer& Lib Itf.
Assertion
AnalysisInfo[[P]]
ProgramP
:− trust
I
Builtins/Libs
RT Check
verificationwarning
compile−timeerror
verified
(ACC) codecertificate
Unit Test
AnalysisStatic
possiblerun−time error
:− check
:− false
:− checked
:− texec
:− check
:− test
PREPROCESSOR
Modular, parametric, polyvariant abstract interpretation.Accelerated, incremental fixpoint.Properties:
I Shapes, data sizes, sharing/aliasing, CHA, determinacy, exceptions,termination, ...
I Resources (time, memory, energy, ...), (user-defined) resources.
[MLNH07] [MH92, BGH99, PH96, HPMS00, NMLH07][MGH94, BCHP96, PH00, BdlBH+01, PCPH06, PCPH08]
[MH89, MH91, DLGH97, VB02, BLGH04, LGBH05, NBH06, MSHK07] [MLH08, MKSH08, MMLH+08, MHKS08, MKH09, LGBH10, MLLH08]
[DLH90, LGHD94, LGHD96, DLGHL94, DLGHL97, NMLGH07, MLGCH08, NMLH08, NMLH09, LGDB10, SLBH13, LKSGL13, SLH13]Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 12 / 80
Integrated Static/Dynamic Debugging and Verification
[BDD+97, HPB99, PBH00c, PBH00a, HPBLG03, HALGP05, PCPH06, PCPH08, MLGH09]
+
Comparator
(Incl. VCgen)Normalizer
& Lib Itf.
Assertion
Analysis
Info
[[P]]
Program
P
:− trust
I
Builtins/
Libs
RT Check
verificationwarning
compile−timeerror
verified
(ACC) code
certificate
Unit Test
AnalysisStatic
possiblerun−time error
:− check
:− false
:− checked
:− texec
:− check
:− test
(optimized)
PREPROCESSOR
Definition Sufficient conditionP is prt. correct w.r.t. Iα if α([[P]]) ≤ Iα [[P]]α+ ≤ IαP is complete w.r.t. Iα if Iα ≤ α([[P]]) Iα ≤ [[P]]α=
P is incorrect w.r.t. Iα if α([[P]]) 6≤ Iα [[P]]α= 6≤ Iα, or[[P]]α+ ∩ Iα = ∅ ∧ [[P]]α 6= ∅
P is incomplete w.r.t. Iα if Iα 6≤ α([[P]]) Iα 6≤ [[P]]α+
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 13 / 80
Integrated Static/Dynamic Debugging and Verification
[BDD+97, HPB99, PBH00c, PBH00a, HPBLG03, HALGP05, PCPH06, PCPH08, MLGH09]
+
Comparator
(Incl. VCgen)Normalizer
& Lib Itf.
Assertion
Analysis
Info
[[P]]
Program
P
:− trust
I
Builtins/
Libs
RT Check
verificationwarning
compile−timeerror
verified
(ACC) code
certificate
Unit Test
AnalysisStatic
possiblerun−time error
:− check
:− false
:− checked
:− texec
:− check
:− test
(optimized)
PREPROCESSOR
Based throughout on the notion of safe approximation (abstraction).
Run-time checks generated for parts of asserts. not verified statically.Diagnosis (for both static and dynamic errors).Comparison not always trivial: e.g., resource debugging/certification
I Need to compare functions.I “Segmented” answers.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 13 / 80
Demo: assertions, static errors (types, data sizes, procedure cost,
non-determinacy, ...), run-time check generation, certification, unit tests...
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 14 / 80
Abstraction-based Certification, Abstraction-Carrying Code
Comparator
(Incl. VCgen)Normalizer
& Lib Itf.
Assertion
Analysis
Info
[[P]]
Program
P
:− trust
I
Builtins/
Libs
RT Check
verificationwarning
compile−timeerror
verified
+(ACC) code
certificate
Unit Test
AnalysisStatic
possiblerun−time error
:− check
:− false
:− checked
:− texec
:− check
:− test
PREPROCESSOR
(optimized)
PRODUCER CONSUMER
[[P]]α = Analysis = lfp(analysis step)Certificate ⊂ [[P]]αCertificate →Safety Policy
Checker = analysis step
Interesting extensions: reduced certificates, incrementality, ...
[APH05, HALGP05, AAPH06]
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 15 / 80
Integration of Testing
+
Comparator
(Incl. VCgen)Normalizer
& Lib Itf.
Assertion
Analysis
Info
[[P]]
Program
P
:− trust
I
Builtins/
Libs
RT Check
verificationwarning
compile−timeerror
verified
(ACC) code
certificate
Unit Test
AnalysisStatic
possiblerun−time error
:− check
:− false
:− checkedPREPROCESSOR
:− texec
(optimized)
:− check
:− test
Many interactions within the integrated framework:
(Unit) tests are part of the assertion language::- test Pred [:Precond] [=>Postcond] [+CompExecProps].
Parts of unit tests that can be verified at compile-time are deleted.Unit testing uses the run-time assertion-checking machinery.Unit tests also provide test cases for the run-time checks.
I Assertions checked by unit testing, even if not conceived as tests.
[MLGH09]
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 16 / 80
Optimization
+
Comparator
(Incl. VCgen)Normalizer
& Lib Itf.
Assertion
Analysis
Info
[[P]]
Program
P
:− trust
I
Builtins/
Libs
RT Check
verificationwarning
compile−timeerror
verified
(ACC) code
certificate
Unit Test
AnalysisStatic
possiblerun−time error
:− check
:− false
:− checked
:− texec
:− check
:− test
PREPROCESSOR
(optimized)
Source-level optimizations:I Partial evaluation, (multiple) (abstract) specialization, ...
Low-level optimizations (e.g., dynamic check elimination, unboxing):I Use of specialized instructions.I Optimized native code generation.
→ obtaining close-to-C performance for declarative languages (Ciao).Parallelization. Granularity control.
[GH91, PH97, PH03, PHG99, PAH06] [PH99, MBdlBH99, BGH99, CCH08, MKSH08] [MCH04, CMM+06]
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 17 / 80
Discussion: The Ciao Approach [AADEBUG’97, etc.]
Approaches prior to Ciao had what we perceived as limitations:I limited the properties which may appear in specifications, orI checked specifications only at run-time or only at compile-time, orI were not automatic, or required assertions for all predicates, or . . .
The Ciao approach – solution to static/dynamic conundrum, which:I Integrates automatic compile-time and run-time checking of assertions.I Allows using assertions in only some parts of the program.I Deals safely with complex properties (beyond, e.g., traditional types).
Allows “modern” (agile/extreme/...) programming, “Scripts to Ps:”
I Develop program and specifications gradually, not necessarily in sync.I Both can be incomplete (including types).
F Temporarily use spec (including tests) as implementation.
I Go from types, to more complex assertions, to full specifications.
Assertion language design is important: many roles, used throughout.Assertions, properties in source language; “seamless integration.”Performance through optimization, not language restriction.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 18 / 80
Discussion: Comparison with Classical Types
“Traditional” Types Ciao Assertion-based Model“Properties” limited by decidability Much more general property languageMay need to limit prog. lang. No need to limit prog. lang.“Untypable” programs rejected Run-time checks introduced(Almost) Decidable Decidable + Undecidable(approximated)Expressed in a different language Expressed in the source languageTypes must be defined Types can be defined or inferredAssertions are only of type “check” “check”, “trust”, ...Type signatures & assertions different Type signatures are assertions
Some key issues:Safe / Sound approximation Suitable assertion languageAbstract Interpretation Powerful abstract domains
Works best when properties and assertions can be expressed in thesource language (i.e., source lang. supports predicates, constraints).
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 19 / 80
Outline
Part I The Ciao approach to Analysis and verificationof Constraint Logic Programs
The programming languageThe analysis, verification, and testing model
Part II The Ciao approach to Analysis and verificationof other paradigmsusing Constraint Logic Programs as IR
CLP (Horn Clauses) as intermediate representationUser-defined resource analysis/verif. of Java bytecodeEnergy analysis/verification of (Xmos) C programs
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 20 / 80
Intermediate Representation: (Constraint) Horn Clauses[MLNH07]
Transformation Analysis
Java parser
javac
soot + Ciaotransform.
xobjdumpSizes and
Prog. Point InfoPre/Post pairs
Sets of
(Horn clauses)
IR − CFGCiao Source
...
Resource Model
Resource Usage
Java Source
Java Bytecode
Xcore assembly
Shape
...
Sharing
CHA
Fixpointalgorithm
(AI−based)
XC Source
Resource Info.
Allows supporting multiple languages / paradigms.
Used for all analyses: aliasing, CHA/shape/types, data sizes / resources, etc.
Based on “blocks:” each block represented as a Horn clause.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 21 / 80
IR Issues: IR Level Trade-offs
XC source code
LLVM
XC Assembly
LLVM Code Generator
XC Compiler
Precision Loss
Op;miza;ons
Informa;on loss
Op;mized LLVM
Hardware
Layer 1
Layer 2
Layer 3 Energy Model
Analysis
Analysis Transform to Ciao IR
Analysis
Transform to Ciao IR
Transform to Ciao IR
Energy Model ?
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 22 / 80
IR Issues: Approaches to Performing the Transformation
The transformation (akin to Abstract Compilation):
I Source: Program P in LP + (possibly abstract) Semantics of LP
I Target: A (C) Horn Clause program capturing the semantics of P
Some approaches to performing the transformation:
I Direct transformation into block-based intermediate representation.F More control but correctness proof more indirect.F Used in the following (translation to a Ciao program).F Can add assertions to help analysis (sizes, metrics, resource models, ..).
I Partial evaluation of instrumented interpreters + slicing.F Systematic construction from small- and big-step semantics.F Correctness proof more direct.F Less automatic?
Some evidence that the two approaches can produce similar results.
Cf. John Gallagher’s talk!
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 23 / 80
Generating the Intermediate Representation
Specifics for Java:I Control flow graph construction from bytecode representation.I Elimination of stack variables.I Conversion to three-address statements.
I Explicit representation of this and ret as extra block parameters.
Specifics for XC:I Control flow graph construction from ISA (or LLVM IR) representation.I Resolving branching to predicates with multiple clauses.
I Inferring block parameters.
Some common tasks:I Generation of block-based CFG.I SSA transformation (e.g., splitting of input/output param).I Conversion of loops into recursions among blocks.I Branching, cases, dynamic dispatch → blocks w/same signature.
I Conversion to horn clauses.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 24 / 80
Java Example 1: sending SMSs
p u b l i c c l a s s C e l l P h o n e {
v o i d sendSms ( SmsPacket smsPk ,Encoder enc ,
Stream stm ) {i f ( smsPk != n u l l ) {stm . send (
enc . fo rmat ( smsPk . sms ) ) ;sendSms ( smsPk . next , enc , stm ) ;}}}
c l a s s SmsPacket{S t r i n g sms ;SmsPacket n e x t ;}
a b s t r a c t c l a s s Stream{@Cost ({ ” c e n t s ” , ”2∗ s i z e ( data ) ” })n a t i v e v o i d send ( S t r i n g data ) ;
}
i n t e r f a c e Encoder {S t r i n g format ( S t r i n g data ) ;}
c l a s s TrimEncoder implements Encoder {@Cost ({ ” c e n t s ” , ”0” })@Size ( ” s i z e ( r e t )<= s i z e ( s ) ” )p u b l i c S t r i n g format ( S t r i n g s ){
r e t u r n s . t r i m ( ) ;}}
c l a s s UnicodeEncoder implements Encoder {@Cost ({ ” c e n t s ” , ”0” })@Size ( ” s i z e ( r e t )<=6∗ s i z e ( s ) ” )p u b l i c S t r i n g format ( S t r i n g s ){
r e t u r n j a v a . n e t . URLEncoder . encode ( s ) ;}}
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 25 / 80
Java Example 1: sending SMSs – IR
Builtin.gtf(r1,next,r8)
CellPhone.sendSms(r0,r8,r2,r3,r9,r10)
Builtin.stf(r1,next,r10,r1_1)
Builtin.stf(r1_1,sms,r7,r4)
Encoder.format(r2, r6, r7)
Stream.send(r3,r7,void)
Stream.send(r0,r1,r2)
Encoder.format(r0,r1,r2)
Builtin.asg(r3,r2)
java.net.URLEncoder.encode(r1,r3)
Encoder.format(r0,r1,r2)
java.lang.String.trim(r1,r3)
Builtin.asg(r3,r2)
TrimEncoder.format(r0,r1,r2) UnicodeEncoder.format(r0,r1,r2)
TrimEncoder.format(r0,r1,r2) UnicodeEncoder.format(r0,r1,r2)
@Cost({"cents","0"}) @Cost({"cents","0"})
@Cost({"cents","2*size(r1)"})
@Size("size(r2)<=size(r1)") @Size("size(r2)<=6*size(r1)")
CellPhone.sendSms(r0,r1,r2,r3,r4,r5)
CellPhone.sendSms(r0,r1,r2,r3,r4,r5)
Builtin.ne(r1,null,void)
Builtin.gtf(r1,sms,r6)
Builtin.asg(r4,r5)
Builtin.eq(r1,null,void)
Builtin.asg(null,r5)
Internal representation: basic block → Horn clause.
Annotations (since Java 1.5) are preserved in the bytecode so theycan be carried over to our IR.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 26 / 80
Java Example 2: Factorial
@Resources ({ R e s o u r c e . STEPS})p u b l i c c l a s s Fact{
p u b l i c i n t f a c t o r i a l ( i n t n ) {i f ( n == 0)
r e t u r n 1 ;e l s e
r e t u r n n ∗ f a c t o r i a l ( n − 1 ) ;}
}
@Resource("STEPS")
Builtin.eq(void, N,0)
Builtin.asg_int(Ret,I3)
Fact.factorial(Ret,This,N)
Builtin.ne_int(void,N,0)
Builtin.sub(I1,N,1)
Fact.factorial(I2, This, I1)
Builtin.mul(I3,N,I2)
Fact.factorial(Ret,This,N)
Builtin.asg(Ret,1)
Source code → Basic blocks.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 27 / 80
Java Example 2: Factorial
@Resource("STEPS")
Builtin.eq(void, N,0)
Builtin.asg_int(Ret,I3)
Fact.factorial(Ret,This,N)
Builtin.ne_int(void,N,0)
Builtin.sub(I1,N,1)
Fact.factorial(I2, This, I1)
Builtin.mul(I3,N,I2)
Fact.factorial(Ret,This,N)
Builtin.asg(Ret,1)
:- entry ’Fact.factorial’/3:var*atm*num.
:- resource ’STEPS’.
’Fact.factorial’(Ret, This, N):-
eq_int(void,N,int,0,int),
asg_int(Ret,int,1,int).
’Fact.factorial’(Ret, This, N):-
ne_int(void,N,int,0,int),
sub(I1,int,N,int,1,int),
Fact.factorial(I2,This,I1),
mul(I3, int,N,int,I2,int),
asg_int(Ret,int,I3,int).
Intermediate representation: basic block → Horn clause.
Annotations (since Java 1.5) are preserved in the bytecode so theycan be carried over to our IR.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 28 / 80
Xcore Example: Control Flow Graph (CFG)
<fact>:
0x01: entsp (u6) 0x2
0x02: stw (ru6) r0, sp[0x1]
0x03: ldw (ru6) r1, sp[0x1]
0x04: ldc (ru6) r0, 0x0
0x05: lss (3r) r0, r0, r1
0x06: bf (ru6) r0, 0x1 <0x08>
0x07: bu (u6) 0x2 <0x10>
0x08: mkmsk (rus) r0, 0x1
0x09: retsp (u6) 0x2
0x10: ldw (ru6) r0, sp[0x1]
0x11: sub (2rus) r0, r0, 0x1
0x12: bl (u10) -0xc <fact>
0x13: ldw (ru6) r1, sp[0x1]
0x14: mul (l3r) r0, r1, r0
0x15: retsp (u6) 0x2
→Interpreter→
0x01start 0x02 0x03 0x04
0x050x06
0x08
0x09
0x07
0x10
0x11
0x12
0x13
0x14
0x15
return edge
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 29 / 80
Block Representation
Basic block
A basic block is a maximal sequence S of consecutive nodes G in CFG,starting from node n and ending in node m such that:
(∀k ∈ S/{n,m}. outEdges(k) = 1 ∧ inEdges(k) = 1) ∧outEdges(n) = 1 ∧ inEdges(m) = 1
Initial block starts from the entry node.
Dead code elimination.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 30 / 80
Xcore Example: Block Representation
<fact>
0x01: entsp (u6) 0x2
0x02: stw (ru6) r0, sp[0x1]
0x03: ldw (ru6) r1, sp[0x1]
0x04: ldc (ru6) r0, 0x0
0x05: lss (3r) r0, r0, r1
0x06: bf (ru6) r0, 0x1 <0x08>
0x07: bu (u6) 0x2 <0x10>
0x10: ldw (ru6) r0, sp[0x1]
0x11: sub (2rus) r0, r0, 0x1
0x12: bl (u10) -0xc <fact>
0x13: ldw (ru6) r1, sp[0x1]
0x14: mul (l3r) r0, r1, r0
0x15: retsp (u6) 0x2
0x08: mkmsk (rus) r0, 0x1
0x09: retsp (u6) 0x2
0x01start 0x02 0x03 0x04
0x050x06
0x08
0x09
0x07
0x10
0x11
0x12
0x13
0x14
0x15
return edge
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 31 / 80
Xcore Example: Block Representation
fact :-
0x01: entsp(0x2)
0x02: stw(r0, sp[0x1])
0x03: ldw(r1, sp[0x1])
0x04: ldc(r0, 0x0)
0x05: lss(r0, r0, r1)
0x06: bf(r0 , 0x1 <0x08 >)
branch(bf0 , bf1)
bf1 :-
0x07: bu(0x2 <0x10 >)
0x10: ldw(r0, sp[0x1])
0x11: sub(r0, r0, 0x1)
0x12: bl(-0xc <fact >)
call(fact)
0x13: ldw(r1, sp[0x1])
0x14: mul(r0, r1, r0)
0x15: retsp(0x2)
bf0 :-
0x08: mkmsk(r0, 0x1)
0x09: retsp(0x2)
factstart
bf0bf1
Figure: Block Control Flow Graph
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 32 / 80
Xcore Example: Horn Clause IR
0x01start 0x02 0x03 0x04
0x050x06
0x08
0x09
0x07
0x10
0x11
0x12
0x13
0x14
0x15
return edge
:- entry fact/2 : int * var.
fact(R0,R0_3):-
entsp(0x2),
stw(R0,Sp0x1),
ldw(R1,Sp0x1),
ldc(R0_1,0x0),
lss(R0_2,R0_1,R1),
bf(R0_2,_),
bf01(R0_2,Sp0x1,R0_3,R1_1).
bf01(1,Sp0x1,R0_4,R1):-
bu(_),
ldw(R0_1,Sp0x1),
sub(R0_2,R0_1,0x1),
bl(_),
fact(R0_2,R0_3),
ldw(R1,Sp0x1),
mul(R0_4,R1,R0_3),
retsp(0x2).
bf01(0,Sp0x1,R0,R1):-
mkmsk(R0,0x1),
retsp(0x2).
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 33 / 80
Fixpoint-based Analyzers
AnalysisTransformation
soot + Ciao
transform.
javac
Java parser
Java Source
Ciao Source
Java Bytecode
Fixpointalgorithm
(AI−based) ...
Resource Info.
Sizes and
Prog. Point InfoPre/Post pairs
Sets of
(Horn clauses)
Resource Usage
IR − CFG
Shape
...
Sharing
CHA
[MH92, BGH99, PH96, HPMS00, NMLH07] [MGH94, BCHP96, PH00, BdlBH+01, PCPH06, PCPH08]
[MH89, MH91, DLGH97, VB02, BLGH04, LGBH05, NBH06, MSHK07]
[MLH08, MKSH08, MMLH+08, MHKS08, MKH09, LGBH10, MLLH08] [SLBH13, LKSGL13, SLH13]
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 34 / 80
Efficient, Parametric Fixpoint Algorithm
Generic framework for implementing analyses: given abstract domain,computes lfp(SαP ) = [[P]]α, s.t. [[P]]α safely approximates [[P]].
It maintains and computes as a result (simplified):I A call-answer table: with (multiple) entries {block : λin 7→ λout}.
F Exit states for calls to block satisfying precond λin meet postcond λout .
I A dependency arc table: {A : λinA ⇒ B : λinB}.F Answers for call A : λinA depend on the answers for B : λinB :
(if exit for B : λinB changes, exit for A : λinA possibly also changes).F Dep(B : λinB ) = the set of entries depending on B : λinB .
Characteristics:I Precision: context-sensitivity / multivariance, prog. point info, ...I Efficiency: memoization, dependency tracking, SCCs, base cases, ...I Genericity: abstract domains are plugins, configurable, widening, ...I Handles mutually recursive methods.I Modular and incremental.I Handles library calls, externals, ...
Essentially efficient, incremental, (abstract) OLDT resolution.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 35 / 80
CFG traversal
Blocks are nodes; edges are invocations.
Top-down traversal of this CFG, starting from entry point.
Within each block: sequence of builtins, handled in the domain.
Inter-block calls/edges: project, extend, etc. (next slide).
As graph is traversed, triples (block, λin, λout)are stored for each block in a memo table.
Memo table entries have status ∈ {fixpoint, approx ., complete}.Iterate until all complete.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 36 / 80
Interprocedural analysis / recursion support
Project the caller state over the actual parameters,
find all the compatible implementations (blocks),
rename to their formal parameters,
... abstractly execute each compatible block, ...
calculate the least upper bound of the partial results of each block(if “monovariant on success” flag),
rename back to the actual parameters and, finally
extend (reconcile) return state into calling state.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 37 / 80
Speeding up convergence
Analyze non-recursive blocks first,use as starting λout in recursions.
Blocks derived from conditionals treated specially(no project or extend operations required).
The (block, λin, λout) tuplesact as a cache that avoids recomputation.
Use strongly-connected components (on the fly).
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 38 / 80
Resource Analysis
Java parser
AnalysisTransformation
soot + Ciao
transform.
javac
IR − CFG
Shape
...
Sharing
CHA
Java Source
Ciao Source
Java Bytecode
Fixpointalgorithm
(AI−based) ...
Resource Info.
Sizes and
Prog. Point InfoPre/Post pairs
Sets of
(Horn clauses)
Resource Usage
[DLH90, LGHD94, LGHD96, DLGHL94, DLGHL97, NMLGH07, MLNH07, MLGCH08, NMLH08]
[NMLH09, LGDB10, SLBH13, LKSGL13, SLH13]
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 39 / 80
Analysis/Debugging/Verification of Resources
Automatically infer upper/lower bounds on the usage that a programmakes of a general notion of various (user-definable) resources.
Examples:I Memory, execution time, execution steps, data sizes.I Bits sent or received over a socket, SMSs sent or received, accesses to
a database, calls to a procedure, files left open, money spent, ..I Energy consumed, . . .
Approach:1 Programmer defines via assertions resource-related properties for basic
procedures (e.g., instructions, bytecodes, libraries).2 System infers the resource usage bounds for rest of program as
functions of input data sizes.
Involved properties normally undecidable → approximation required(bounds that are safe and also as accurate as possible).
Applications: performance debugging and verification,resource-oriented optimization, granularity control in parallelism, . . .
[NMLGH07, NMLH09]
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 40 / 80
User-definable aspects of the analysis
A cost model defines an upper/lower bound cost for primitiveoperations (e.g., methods, bytecode instructions).
I Provided by the user, via the assertion language.
@Cost("cents","2*size(data)")
public native void Stream.send(java.lang.String data);
I Some predefined in system libraries.
For platform-dependent resources such as execution time or energyconsumption model needs to consider low level factors.
Assertions:I Also used to provide other inputs to the resource analysis such as
argument sizes, size metrics, etc. if needed.I Also allow improving the accuracy and scalability of the system.I Output of resource analysis also expressed via assertions.I Used additionally to state resource-related specifications which allows
finding bugs, verifying, certifying, etc.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 41 / 80
The Assertion Language (simplified grammar, Java)
〈primitive assrt〉 ::= primitive name(var∗)〈assrt〉∗〈assrt〉 ::= @requires ( 〈prop〉∗ )
| @ensures ( 〈prop〉∗ )| @cost ( 〈resource usage〉∗ )| @if ( 〈prop〉∗ ) { 〈prop〉∗ } [ cost ( 〈resource usage〉∗ ) ]
〈resource usage〉 ::= res usage(res name,〈expr〉)
〈prop〉 ::= type| size(var ,〈sz metric〉,〈expr〉)| size metric(var ,〈sz metric〉)
〈expr〉 ::= 〈expr〉〈bin op〉〈expr〉 | (∑|∏
)〈expr〉| 〈expr〉〈expr〉 | lognum〈expr〉 | −〈expr〉| 〈expr〉! | ∞ | num| size([〈sz metric〉,]arg(r num))
〈bin op〉 ::= + | − | × | / | %
〈sz metric〉 ::= int | ref | . . .
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 42 / 80
Overview of the Analysis1 Pre-analysis phase using the fixpoint analyzers:
I Class hierarchy analysis simplifies CFG and improves overall precision.I Sharing analysis for correctness (conservative: only when there is no
sharing among data structures –currently limited to acyclic).I Determinacy information inferred and used to obtain tighter bounds.I Non-failure (no exceptions) inferred for non-trivial lower bounds.
2 Set up recurrence equations representing the size of each outputargument as a function of the input data sizes.
I Data dependency graphs determine relative sizes of variable contents.(Size measures are derived from inferred shape information.)
3 Compute upper bounds to the solutions of these recurrence equationsto obtain bounds on output argument sizes.
I We have a simple recurrence solver, although the system can easilyinterface with tools like Parma, PUBS, Mathematica, Matlab, etc.
4 Use the size information to set up recurrence equations representingthe computational cost of each block and compute upper bounds totheir solutions to obtain resource usage.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 43 / 80
Overview of the Analysis1 Pre-analysis phase using the fixpoint analyzers:
I Class hierarchy analysis simplifies CFG and improves overall precision.I Sharing analysis for correctness (conservative: only when there is no
sharing among data structures –currently limited to acyclic).I Determinacy information inferred and used to obtain tighter bounds.I Non-failure (no exceptions) inferred for non-trivial lower bounds.
2 Set up recurrence equations representing the size of each outputargument as a function of the input data sizes.
I Data dependency graphs determine relative sizes of variable contents.(Size measures are derived from inferred shape information.)
3 Compute upper bounds to the solutions of these recurrence equationsto obtain bounds on output argument sizes.
I We have a simple recurrence solver, although the system can easilyinterface with tools like Parma, PUBS, Mathematica, Matlab, etc.
4 Use the size information to set up recurrence equations representingthe computational cost of each block and compute upper bounds totheir solutions to obtain resource usage.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 43 / 80
Overview of the Analysis1 Pre-analysis phase using the fixpoint analyzers:
I Class hierarchy analysis simplifies CFG and improves overall precision.I Sharing analysis for correctness (conservative: only when there is no
sharing among data structures –currently limited to acyclic).I Determinacy information inferred and used to obtain tighter bounds.I Non-failure (no exceptions) inferred for non-trivial lower bounds.
2 Set up recurrence equations representing the size of each outputargument as a function of the input data sizes.
I Data dependency graphs determine relative sizes of variable contents.(Size measures are derived from inferred shape information.)
3 Compute upper bounds to the solutions of these recurrence equationsto obtain bounds on output argument sizes.
I We have a simple recurrence solver, although the system can easilyinterface with tools like Parma, PUBS, Mathematica, Matlab, etc.
4 Use the size information to set up recurrence equations representingthe computational cost of each block and compute upper bounds totheir solutions to obtain resource usage.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 43 / 80
Overview of the Analysis1 Pre-analysis phase using the fixpoint analyzers:
I Class hierarchy analysis simplifies CFG and improves overall precision.I Sharing analysis for correctness (conservative: only when there is no
sharing among data structures –currently limited to acyclic).I Determinacy information inferred and used to obtain tighter bounds.I Non-failure (no exceptions) inferred for non-trivial lower bounds.
2 Set up recurrence equations representing the size of each outputargument as a function of the input data sizes.
I Data dependency graphs determine relative sizes of variable contents.(Size measures are derived from inferred shape information.)
3 Compute upper bounds to the solutions of these recurrence equationsto obtain bounds on output argument sizes.
I We have a simple recurrence solver, although the system can easilyinterface with tools like Parma, PUBS, Mathematica, Matlab, etc.
4 Use the size information to set up recurrence equations representingthe computational cost of each block and compute upper bounds totheir solutions to obtain resource usage.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 43 / 80
Example: sending SMSs
p u b l i c c l a s s C e l l P h o n e {
v o i d sendSms ( SmsPacket smsPk ,Encoder enc ,Stream stm ) {
i f ( smsPk != n u l l ) {stm . send (
enc . fo rmat ( smsPk . sms ) ) ;sendSms ( smsPk . next , enc , stm ) ;}}}
c l a s s SmsPacket{S t r i n g sms ;SmsPacket n e x t ;
}
a b s t r a c t c l a s s Stream{@Cost ({ ” c e n t s ” , ”2∗ s i z e ( data ) ” })n a t i v e v o i d send ( S t r i n g data ) ;
}
i n t e r f a c e Encoder {S t r i n g format ( S t r i n g data ) ;}
c l a s s TrimEncoder implements Encoder {@Cost ({ ” c e n t s ” , ”0” })@Size ( ” s i z e ( r e t )<= s i z e ( s ) ” )p u b l i c S t r i n g format ( S t r i n g s ){
r e t u r n s . t r i m ( ) ;}}
c l a s s UnicodeEncoder implements Encoder {@Cost ({ ” c e n t s ” , ”0” })@Size ( ” s i z e ( r e t )<=6∗ s i z e ( s ) ” )p u b l i c S t r i n g format ( S t r i n g s ){
r e t u r n j a v a . n e t . URLEncoder . encode ( s ) ;}}
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 44 / 80
Example (I)
1 System takes by default size of input data: size(smsPk) = n.I Result will be parametric on this.
2 The number of characters sent depends on the formatting done bythe different encoders:
I The user indicates that the encoding in TrimEncoder results in asmaller or equal (output) string.
c l a s s TrimEncoder implements Encoder {@Size ( ” s i z e ( r e t )<= s i z e ( s ) ” )p u b l i c S t r i n g format ( S t r i n g s ){
I And that the result of UnicodeEncoder can be up to 6 times larger(\uxxxx) than the one received.
c l a s s UnicodeEncoder implements Encoder {@Size ( ” s i z e ( r e t )<=6∗ s i z e ( s ) ” )p u b l i c S t r i n g format ( S t r i n g s ){
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 45 / 80
Example (II)
3 After setting up and solving the size equations the system obtainsthat the upper bound on the number of characters sent is:
max(6, 1) ∗ n = 6 ∗ n = 6 ∗ size(smsPk)
4 The analysis establishes then (cost) recurrences for every method:CostsendSms (r0, 0, r2, r3) = 0CostsendSms (r0, r1, r2, r3) = cost of sending a char ×CostsendSms (r0, r1− 1, r2, r3)
where r0,r1,r2, and r3 represent the size of This, SmsPk, enc, and stm, respectively.
5 Given that we are charged 2 cents per character sent:
@Cost ({ ” c e n t s ” , ”2∗ s i z e ( data ) ” })n a t i v e v o i d send ( S t r i n g data ) ;
CostsendSms (r0, 0, r2, r3) = 0CostsendSms (r0, r1, r2, r3) = 2× 6× (r1− 1)︸ ︷︷ ︸
character size
×CostsendSms (r0, r1− 1, r2, r3)
and the total cost of the sendSMS method is 6× r12 − 6× r1 cents.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 46 / 80
Some results (Java)
Program Resource(s) t Resource Usage Func. / Metric
BST Heap usage 367 O(2n) n ≡ tree depth
CellPhone SMS monetary cost 386 O(n2) n ≡ packets length
Client Bytes received and 527 O(n) n ≡ stream length
bandwidth required O(1) —
Dhrystone Energy consumption 759 O(n) n ≡ int value
Divbytwo Stack usage 219 O(log2(n)) n ≡ int value
Files Files left open and 649 O(n) n ≡ number of files
Data stored O(n ×m) m ≡ stream length
Join DB accesses 460 O(n ×m) n,m ≡ table records
Screen Screen width 536 O(n) n ≡ stream length
Different complexity functions, resources, types of loops/recursion,etc.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 47 / 80
Some results (Ciao)
Program Resource Usage Function Metrics Timeclient “bits received” λx .8 · x length 186color map “unifications” 39066 size 176copy files “files left open” λx .x length 180eight queen “queens movements” 19173961 length 304eval polynom “FPU usage” λx .2.5x length 44
fib “arith. operations”λx .2.17 · 1.61x +0.82 · (−0.61)x − 3
value 116
grammar “phrases” 24 length/size 227hanoi “disk movements” λx .2x − 1 value 100insert stores “accesses Stores” λn,m.n + k length 292
“insertions Stores” λn,m.n
perm “WAM instructions”λx .(
∑xi=1 18 · x!)+
(∑x
i=1 14 · x!i
) + 4 · x!length 98
power set “output elements” λx . 12· 2x+1 length 119
qsort “lists parallelized” λx .4 · 2x − 2x − 4 length 144send files “bytes read” λx , y .x · y length/size 179subst exp “replacements” λx , y .2xy + 2y size/length 153zebra “resolution steps” 30232844295713061 size 292
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 48 / 80
Interesting Resource: Execution Time
Important: e.g., verification of real-time constraints.
Very hard in current architectures, (e.g., worst-case cache behavior).
I Certainly feasible in simple processors and with caches turned off.I Our approach is complementary to accurate WCET models, which
consider cache behavior, pipeline state, etc. (inputs to us).
Approach:
I Obtain timing model of abstract machine instructions through aone-time profiling phase (results provided as assertions).
F Includes fitting constants in a function if the execution time dependson the argument’s properties.
I Static cost analysis phase which infers a function which returns(bounds on) the execution time of program for given input data sizes.
[MLGCH08]
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 49 / 80
First Phase Output
Cost assertions automatically generated in first phase and stored to makethe instruction execution costs available to the static analyzer.
Examples
:- true pred unify variable(A, B): int(A), int(B)
+ (cost(ub, exectime, 667.07),
cost(lb, exectime, 667.07)).
:- true pred unify variable(A, B): var(A), gnd(B)
+ (cost(ub, exectime, 233.3),
cost(lb, exectime, 233.3)).
:- true pred unify variable(A, B): list(A),list(B)
+ cost(ub, exectime, 271.58+284.34*length(A)). ...
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 50 / 80
Observed and Estimated Execution Time (Intel)
Pr. Cost. Intel (µs)No. App. Est. Prf. Obs. D. % Pr.D. %
1 E 110 110 113 -2.4 -2.42 E 69 69 71 -2.3 -2.33 E 1525 1525 1576 -3.3 -3.34 E 1501 1501 1589 -5.7 -5.75 E 2569 2569 2638 -2.7 -2.76 E 1875 1875 2027 -7.8 -7.87 E 1868 1868 1931 -3.3 -3.3
8 L 43 68 81 -67.2 -17.8U 3414 3569 3640 -6.4 -2.0
9 L 54 79 91 -54.6 -14.8U 3414 3694 4011 -16.2 -8.2
10 L 135 142 124 8.6 13.7U 7922 2937 2858 120.6 2.7
11 L 216 138 111 72.3 22.5U 226 216 162 34.0 29.5
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 51 / 80
Resource Analysis as an Abstract Interpretation[SLH13, SLBH13]
In the classical CiaoPP resource analysis the last steps (setting up andsolving recurrences) were not implemented as an abstract domain.
We have now defined, implemented and integrated the resourceanalysis as an abstract domain (a plugin of the generic fixpoint).
We get all the good features of the AI framework for free:
I Multivariance: e.g., separate different call patterns for same block:sort(lst(int),var) ... sort(lst(flt),var) ... sort(var,lst(int))
I Easier combination with other domains.I Easier integration w/static debugging/verification and rt-checking.I Many other engineering advantages.
New domain for size analysis (sized types) that infers bounds on thesize of data structures and substructures.
I Size: number of rule applications in type/shape definition.
Used in the XC energy analysis.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 52 / 80
The Sized Types Abstract Domain[SLBH13]
Sized types are representations of data shape information including bothlower and upper bounds on the size of the corresponding terms and theirsubterms at any position and depth.
Derived from the regular types inferred for program variables.
If τ is a regular type, sized(τ) is its corresponding sized type:listnum sized(listnum)
listnum -> []
listnum -> [num | listnum]listnum(α,β)
(num
(γ,δ)〈.,1〉
)The superscripts (size bound variables) express bounds on the numberof rule (functor) applications.{ [1,2,3,4], [2,4] } listnum(3,5)
(num
(1,4)〈.,1〉
)Size analysis infers relations (inequations) among the size boundvariables of the sized types occurring at different argument positions.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 53 / 80
Experimental Results
Prog. Resource An. (LB) Resource An. (UB) An. Time (s)New Prev. New Prev. RAML New Prev.
append α α = β β = β = 1.00 0.53appAll a1a2a3 a1 + b1b2b3 ∞ + b1b2b3 = 2.41 0.67coupled µ 0 + ν ∞ + ν = 1.37 0.64dyade α1α2 α1α2 = β1β2 β1β2 = β1β2 = 1.66 0.62erathos α α = β2 β2 = β2 = 2.25 0.77fib φµ φµ = φν φν = infeas. + 1.06 0.67hanoi 1 0 + 2ν ∞ + infeas. + 0.82 0.60isort α2 α2 = β2 β2 = β2 = 1.68 0.62isortl a2
1 a21 = b2
1b2 ∞ + b21b2 = 2.55 0.67
lisfact αγ α + βδ ∞ + unkn. ? 1.39 0.64listnum µ µ = ν ν = unkn. ? 1.19 0.58minsort α2 α + β2 β2 = β2 = 1.94 0.67nub a1 a1 = b2
1b2 ∞ + b21b2 = 3.61 0.91
part α α = β β = β = 1.70 0.65zip3 min(αi ) 0 + min(βi ) ∞ + β3 + 2.48 0.57
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 54 / 80
Energy Consumption Analysis
Specialize the generic resource analysis by encoding energy models:provide cost and size assertions for each individual instruction.
Some energy models:I Java bytecode energy consumption models available for simple
processors –upper bound consumption per bytecode in joules:
Opcode Inst. Cost in µJ Mem. Cost in µJ Total Cost in in µJiadd .957860 2.273580 3.23144isub .957360 2.273580 3.230.94. . . . . . . . . . . .
I More sophisticated ISA-level energy models developed w/Bristol &XMOS (based on “Tiwari” model).
The CiaoPP resource analysis then generates at compile time safeupper- and lower-bound energy consumption functions for givenprograms.
[NMLH08]
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 55 / 80
Demo: java resource analysis (including CHA, nullity, etc.);
XC energy analysis.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 56 / 80
Low-level ISA characterization
Obtaining the cost model: energy consumption per instruction
Coll. w/Xmos and Bristol U (based on Tiwari model).
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 57 / 80
Energy ModelExpressed in the Ciao assertion language
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 58 / 80
XC Source
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 59 / 80
Assembly Code
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 60 / 80
CiaoPP Menu
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 61 / 80
Select Resource Analysis
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 62 / 80
Analysis Results
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 63 / 80
Checking against actual HW energy consumptionTest programs run on two different HW rigs:
ISS (Instruction Set Simulation) and
SRA (Static Resource Analysis).
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 64 / 80
Some Results
BenchmarksFunction name Description Energy function
fact(N) Calculates N! 26.0 N + 19.4fibonacci(N) Nth Fibonacci no. 30.1 + 35.6 φN + 11.0 (1− φ)N
sqr(N) Computes N2 103.0 N2 + 205.8 N + 188.32poweroftwo(N) Calculates 2N 62.4 · 2N − 312.3sumofdigits(N) Adds all digits in N 84.4dlog10 Ne − 78.7
isprime(N) Checks if N is prime 58.6 N − 35.5power(base,exp) Calculates baseexp 6.3 (log2 exp + 1) + 6.5
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 65 / 80
Some Results
10 20 30 40 50 60N
0
200
400
600
800
1000
1200
1400
1600
1800En
ergy
(nJ)
Fact(N)
0.0
0.2
0.4
0.6
0.8
1.0
Rela
tive
Erro
r
1 2 3 4 5 6 7 8N
0
200
400
600
800
1000
1200
1400
1600
1800
Ener
gy (n
J)
Fibonacci(N)
0.0
0.2
0.4
0.6
0.8
1.0
1.2
Rela
tive
Erro
r
1|1 1|129 15|15 15|4000 129|4000base,exp
0
20
40
60
80
100
Ener
gy (n
J)
Power(base,exp)
0.0
0.2
0.4
0.6
0.8
1.0
Rela
tive
Erro
r
4 6 8 10 12 14 16 18 20N
0
1
2
3
4
5
6
Ener
gy (n
J)
1e7 PowerOfTwo(N)
0.5
0.0
0.5
1.0
1.5
2.0
2.5
Rela
tive
Erro
r
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 66 / 80
Feedback from the hardware experts (Xmos, Bristol)
SRA provides results beyond what is possible with simulation(as test run-time increases, ISS becomes impractically long).
SRA shows promising accuracy in comparison with ISS and the HW(at least for the simple cases studied so far).
Simulation time limits the usefulness of ISS method, whereasequation solving limits SRA.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 67 / 80
IR Level Trade-offs
XC source code
LLVM
XC Assembly
LLVM Code Generator
XC Compiler
Precision Loss
Op;miza;ons
Informa;on loss
Op;mized LLVM
Hardware
Layer 1
Layer 2
Layer 3 Energy Model
Analysis
Analysis Transform to Ciao IR
Analysis
Transform to Ciao IR
Transform to Ciao IR
Energy Model ?
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 68 / 80
LLVM IR vs. ISA tradeoffbu
u6
buf
u6
zext
rus
sext
rus
ldc
ru6
mkmsk
2r
andnot
2r
sext
2r
zext
2r
ldapf
u10
clz
l2r
mkmsk
rus
ldapb
u10
ldc
lru6
ldapf
lu20
ldapb
lu20
neg
2r
not
2r
bitrev
l2r
byterev
l2r
ldw
3r
stw
3r
ld16s
3r
ld8u
3r
st8
3r
st16
3r
ldaw
u6
eq
2rus
shr
3r
shl
3r
eq
3r
ldaw
lru6
lss
3r
lsu
3r
shl
2rus
shr
2rus
sub
2rus
add
2rus
or
3r
and
3r
sub
3r
ldawbl2rus
ldawfl2rus
add
3r
ashrl2rus
ashr
l3r
lda16b
l3r
xor
l3r
ldawb
l3r
crc32
l3r
lda16f
l3r
ldawf
l3r
mul
l3r
crc8
l4r
maccu
l4r
maccs
l4r
lsub
l5r
ladd
l5r
lmul
l6r
Odd threads instruction (name & encoding)
bu u6buf u6zext russext rusldc ru6
mkmsk 2randnot 2rsext 2rzext 2rldapf u10clz l2r
mkmsk rusldapb u10ldc lru6
ldapf lu20ldapb lu20neg 2rnot 2r
bitrev l2rbyterev l2r
ldw 3rstw 3r
ld16s 3rld8u 3rst8 3rst16 3rldaw u6eq 2russhr 3rshl 3req 3r
ldaw lru6lss 3rlsu 3rshl 2russhr 2russub 2rusadd 2rusor 3rand 3rsub 3r
ldawb l2rusldawf l2rusadd 3rashr l2rusashr l3r
lda16b l3rxor l3r
ldawb l3rcrc32 l3rlda16f l3rldawf l3rmul l3rcrc8 l4rmaccu l4rmaccs l4rlsub l5rladd l5rlmul l6r
Eve
nth
read
sin
stru
ctio
n(n
ame
&en
codi
ng)
120
128
136
144
152
160
168
176
184
192
200
Pow
er(m
W)
xC Program Error vs. HW ISA /llvm isa LLVM IR
fact 4.5% 2.86% 0.94fibonacci 11.94% 5.41% 0.92sqr 9.31% 1.49% 0.91power of two 11.15% 4.26% 0.93reverse 2.18% N/A N/Aconcat 8.71% N/A N/Amat mult 1.47% N/A N/Asum facts 2.42% N/A N/A
Average 6.46% 3.50% 0.92
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 69 / 80
Energy consumption verification / debugging:- check pred fact(A, B) : (int(A), var(B))
+ resource(energy, 0, 100).
1 Resource analysis infers upper and lower bounds for resource “energy.”The analysis results produced are::- true pred fact(A,B)
: (int(A), var(B))
=> (int(A), int(B), rsize(A, num(LA,UA)),
rsize(B, num(’Factorial’(LA),’Factorial’(UA))))
+ resource(energy, 21 * LA + 16, 21 * UA + 16).
2 Then, the analysis results are compared with the “check” assertion(the specification) and the following assertions are produced::- checked pred fact(A, B)
: (int(A), intervals(int(A), [i(0,4)]), var(B))
+ resource(energy, 0, 100).
:- false pred fact(A, B)
: (int(A), intervals(int(A), [i(5,inf)]), var(B))
+ resource(energy, 0, 100).
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 70 / 80
Resource Usage Verification – Function Comparisons
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 71 / 80
Resource Usage Verification – Function Comparisons
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 72 / 80
Resource Usage Verification – Function Comparisons
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 73 / 80
Tools / timeline’83 Parallel abstract machines → motivation: auto-parallelization.’88 MA3 analyzer: memo tables (cf. OLDT resolution), practicality established.’89 PLAI framework: accelerated fixpoint, abstract domains as plugins.
Sharing analysis, side-effect analysis.90’s Incremental analysis, concurrency (dynamic scheduling), automatic domain
combinations, scalability, auto-parallelization, extension to constraints.’90 GraCos analyzer: fully automatic cost analysis (upper bounds).
early 90’s Automatic parallelization with task granularity control.mid 90’s Ciao model: Integrated verification/debugging/optimization w/assertions.
’97-present CiaoPP tool:’91-’06 Combined abstract interpretation and partial evaluation.
late 90’s Lower bound cost analysis. Non-failure (no exceptions), determinacy.’01 Verification of cost, additional resources, ...
’01-05 Modularity/scalability. Diagnosis (locating origin of assrt. violations).New shape/type domains, widenings. Polyhedra, convex hulls.
’03 Abstraction carrying code, reduced certificates.’04 Verification/debugging/optimization of user-defined resources.’05 Multi-language support using CLP as IR: Java, C# (shapes, resources, ...).’08 Verification of exec. time. First results in energy (Java), heap models, ...’12 (X)C program energy analysis/verification, ISA-level energy models.’13 Cost analysis as abstract interpretation. Sized shapes inference. LLVM.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 74 / 80
http://www.ciao-lang.org
Provides access to:
Ciao, CiaoPP, LPdoc, etc.
Documentation.
Mailing lists.
etc.
Please contact us for GIT access.
Around 1,000,000 lines of (mostly Ciao/Prolog) code.
Mostly LGPL (some packages have some variations).
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
References – Overall Model
[BDD+97] F. Bueno, P. Deransart, W. Drabent, G. Ferrand, M. Hermenegildo, J. Maluszynski, and G. Puebla.On the Role of Semantic Approximations in Validation and Diagnosis of Constraint Logic Programs.In Proc. of the 3rd. Int’l Workshop on Automated Debugging–AADEBUG’97, pages 155–170, Linkoping, Sweden,May 1997. U. of Linkoping Press.
[HPB99] M. Hermenegildo, G. Puebla, and F. Bueno.Using Global Analysis, Partial Specifications, and an Extensible Assertion Language for Program Validation andDebugging.In K. R. Apt, V. Marek, M. Truszczynski, and D. S. Warren, editors, The Logic Programming Paradigm: a25–Year Perspective, pages 161–192. Springer-Verlag, July 1999.
[PBH00c] G. Puebla, F. Bueno, and M. Hermenegildo.Combined Static and Dynamic Assertion-Based Debugging of Constraint Logic Programs.In Logic-based Program Synthesis and Transformation (LOPSTR’99), number 1817 in LNCS, pages 273–292.Springer-Verlag, March 2000.
[PBH00a] G. Puebla, F. Bueno, and M. Hermenegildo.A Generic Preprocessor for Program Validation and Debugging.In P. Deransart, M. Hermenegildo, and J. Maluszynski, editors, Analysis and Visualization Tools for ConstraintProgramming, number 1870 in LNCS, pages 63–107. Springer-Verlag, September 2000.
[HPBLG03] M. Hermenegildo, G. Puebla, F. Bueno, and P. Lopez-Garcıa.Program Development Using Abstract Interpretation (and The Ciao System Preprocessor).In 10th International Static Analysis Symposium (SAS’03), number 2694 in LNCS, pages 127–152.Springer-Verlag, June 2003.
[MLGH09] E. Mera, P. Lopez-Garcıa, and M. Hermenegildo.Integrating Software Testing and Run-Time Checking in an Assertion Verification Framework.In 25th International Conference on Logic Programming (ICLP’09), number 5649 in LNCS, pages 281–295.Springer-Verlag, July 2009.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
References – Assertion Language
[PBH97] G. Puebla, F. Bueno, and M. Hermenegildo.An Assertion Language for Debugging of Constraint Logic Programs.In Proceedings of the ILPS’97 Workshop on Tools and Environments for (Constraint) Logic Programming,October 1997.Available from ftp://clip.dia.fi.upm.es/pub/papers/assert lang tr discipldeliv.ps.gz as technicalreport CLIP2/97.1.
[PBH00b] G. Puebla, F. Bueno, and M. Hermenegildo.An Assertion Language for Constraint Logic Programs.In P. Deransart, M. Hermenegildo, and J. Maluszynski, editors, Analysis and Visualization Tools for ConstraintProgramming, number 1870 in LNCS, pages 23–61. Springer-Verlag, September 2000.
[MLGH09] E. Mera, P. Lopez-Garcıa, and M. Hermenegildo.Integrating Software Testing and Run-Time Checking in an Assertion Verification Framework.In 25th International Conference on Logic Programming (ICLP’09), number 5649 in LNCS, pages 281–295.Springer-Verlag, July 2009.
References – Horn Clauses as Intermediate Representation
[MLNH07] M. Mendez-Lojo, J. Navas, and M. Hermenegildo.A Flexible (C)LP-Based Approach to the Analysis of Object-Oriented Programs.In 17th International Symposium on Logic-based Program Synthesis and Transformation (LOPSTR 2007),number 4915 in LNCS, pages 154–168. Springer-Verlag, August 2007.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
References – Abstraction Carrying Code
[APH05] E. Albert, G. Puebla, and M. Hermenegildo.Abstraction-Carrying Code.In Proc. of LPAR’04, volume 3452 of LNAI. Springer, 2005.
[HALGP05] M. Hermenegildo, E. Albert, P. Lopez-Garcıa, and G. Puebla.Abstraction Carrying Code and Resource-Awareness.In PPDP. ACM Press, 2005.
[AAPH06] E. Albert, P. Arenas, G. Puebla, and M. Hermenegildo.Reduced Certificates for Abstraction-Carrying Code.In 22nd International Conference on Logic Programming (ICLP 2006), number 4079 in LNCS, pages 163–178.Springer-Verlag, August 2006.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
References – Fixpoint-based Framework (Abstract Interpreters)
[MH92] K. Muthukumar and M. Hermenegildo.Compile-time Derivation of Variable Dependency Using Abstract Interpretation.Journal of Logic Programming, 13(2/3):315–347, July 1992.
[BGH99] F. Bueno, M. Garcıa de la Banda, and M. Hermenegildo.Effectiveness of Abstract Interpretation in Automatic Parallelization: A Case Study in Logic Programming.ACM Transactions on Programming Languages and Systems, 21(2):189–238, March 1999.
[PH96] G. Puebla and M. Hermenegildo.Optimized Algorithms for the Incremental Analysis of Logic Programs.In International Static Analysis Symposium (SAS 1996), number 1145 in LNCS, pages 270–284. Springer-Verlag,September 1996.
[HPMS00] M. Hermenegildo, G. Puebla, K. Marriott, and P. Stuckey.Incremental Analysis of Constraint Logic Programs.ACM Transactions on Programming Languages and Systems, 22(2):187–223, March 2000.
[NMLH07] J. Navas, M. Mendez-Lojo, and M. Hermenegildo.An Efficient, Context and Path Sensitive Analysis Framework for Java Programs.In 9th Workshop on Formal Techniques for Java-like Programs FTfJP 2007, July 2007.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
References – Modular Analysis, Analysis of Concurrency
[MGH94] K. Marriott, M. Garcıa de la Banda, and M. Hermenegildo.Analyzing Logic Programs with Dynamic Scheduling.In 20th. Annual ACM Conf. on Principles of Programming Languages, pages 240–254. ACM, January 1994.
[BCHP96] F. Bueno, D. Cabeza, M. Hermenegildo, and G. Puebla.Global Analysis of Standard Prolog Programs.In European Symposium on Programming, number 1058 in LNCS, pages 108–124, Sweden, April 1996.Springer-Verlag.
[PH00] G. Puebla and M. Hermenegildo.Some Issues in Analysis and Specialization of Modular Ciao-Prolog Programs.In Special Issue on Optimization and Implementation of Declarative Programming Languages, volume 30 ofElectronic Notes in Theoretical Computer Science. Elsevier - North Holland, March 2000.
[BdlBH+01] F. Bueno, M. Garcıa de la Banda, M. Hermenegildo, K. Marriott, G. Puebla, and P. Stuckey.A Model for Inter-module Analysis and Optimizing Compilation.In Logic-based Program Synthesis and Transformation, number 2042 in LNCS, pages 86–102. Springer-Verlag,March 2001.
[PCPH06] P. Pietrzak, J. Correas, G. Puebla, and M. Hermenegildo.Context-Sensitive Multivariant Assertion Checking in Modular Programs.In LPAR’06, number 4246 in LNCS, pages 392–406. Springer-Verlag, November 2006.
[PCPH08] P. Pietrzak, J. Correas, G. Puebla, and M. Hermenegildo.A Practical Type Analysis for Verification of Modular Prolog Programs.In PEPM’08, pages 61–70. ACM Press, January 2008.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
References – Domains: Sharing/Aliasing
[MH89] K. Muthukumar and M. Hermenegildo.Determination of Variable Dependence Information at Compile-Time Through Abstract Interpretation.In 1989 North American Conf. on Logic Programming, pages 166–189. MIT Press, October 1989.
[MH91] K. Muthukumar and M. Hermenegildo.Combined Determination of Sharing and Freeness of Program Variables Through Abstract Interpretation.In International Conference on Logic Programming (ICLP 1991), pages 49–63. MIT Press, June 1991.
[NBH06] J. Navas, F. Bueno, and M. Hermenegildo.Efficient top-down set-sharing analysis using cliques.In Eight International Symposium on Practical Aspects of Declarative Languages, number 2819 in LNCS, pages183–198. Springer-Verlag, January 2006.
[MLH08] M. Mendez-Lojo and M. Hermenegildo.Precise Set Sharing Analysis for Java-style Programs.In 9th International Conference on Verification, Model Checking and Abstract Interpretation (VMCAI’08),number 4905 in LNCS, pages 172–187. Springer-Verlag, January 2008.
[MMLH+08] M. Marron, M. Mendez-Lojo, M. Hermenegildo, D. Stefanovic, and D. Kapur.Sharing Analysis of Arrays, Collections, and Recursive Structures.In ACM WS on Program Analysis for SW Tools and Engineering (PASTE’08). ACM, November 2008.
[MKSH08] M. Marron, D. Kapur, D. Stefanovic, and M. Hermenegildo.Identification of Heap-Carried Data Dependence Via Explicit Store Heap Models.In 21st Int’l. WS on Languages and Compilers for Parallel Computing (LCPC’08), LNCS. Springer-Verlag, August2008.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
[MLLH08] M. Mendez-Lojo, O. Lhotak, and M. Hermenegildo.Efficient Set Sharing using ZBDDs.In 21st Int’l. WS on Languages and Compilers for Parallel Computing (LCPC’08), LNCS. Springer-Verlag, August2008.
[MKH09] M. Marron, D. Kapur, and M. Hermenegildo.Identification of Logically Related Heap Regions.In ISMM’09: Proceedings of the 8th international symposium on Memory management, New York, NY, USA,June 2009. ACM Press.
References – Domains: Shape/Type Analysis
[VB02] C. Vaucheret and F. Bueno.More Precise yet Efficient Type Inference for Logic Programs.In International Static Analysis Symposium, volume 2477 of Lecture Notes in Computer Science, pages 102–116.Springer-Verlag, September 2002.
[MSHK07] M. Marron, D. Stefanovic, M. Hermenegildo, and D. Kapur.Heap Analysis in the Presence of Collection Libraries.In ACM WS on Program Analysis for Software Tools and Engineering (PASTE’07). ACM, June 2007.
[MHKS08] M. Marron, M. Hermenegildo, D. Kapur, and D. Stefanovic.Efficient context-sensitive shape analysis with graph-based heap models.In Laurie Hendren, editor, International Conference on Compiler Construction (CC 2008), Lecture Notes inComputer Science. Springer, April 2008.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
References – Domains: Non-failure, Determinacy
[DLGH97] S.K. Debray, P. Lopez-Garcıa, and M. Hermenegildo.Non-Failure Analysis for Logic Programs.In 1997 International Conference on Logic Programming, pages 48–62, Cambridge, MA, June 1997. MIT Press,Cambridge, MA.
[BLGH04] F. Bueno, P. Lopez-Garcıa, and M. Hermenegildo.Multivariant Non-Failure Analysis via Standard Abstract Interpretation.In 7th International Symposium on Functional and Logic Programming (FLOPS 2004), number 2998 in LNCS,pages 100–116, Heidelberg, Germany, April 2004. Springer-Verlag.
[LGBH05] P. Lopez-Garcıa, F. Bueno, and M. Hermenegildo.Determinacy Analysis for Logic Programs Using Mode and Type Information.In Proceedings of the 14th International Symposium on Logic-based Program Synthesis and Transformation(LOPSTR’04), number 3573 in LNCS, pages 19–35. Springer-Verlag, August 2005.
[LGBH10] P. Lopez-Garcıa, F. Bueno, and M. Hermenegildo.Automatic Inference of Determinacy and Mutual Exclusion for Logic Programs Using Mode and TypeInformation.New Generation Computing, 28(2):117–206, 2010.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
References – Analysis and Verification of Resources
[DLH90] S. K. Debray, N.-W. Lin, and M. Hermenegildo.Task Granularity Analysis in Logic Programs.In Proc. of the 1990 ACM Conf. on Programming Language Design and Implementation, pages 174–188. ACMPress, June 1990.
[LGHD94] P. Lopez-Garcıa, M. Hermenegildo, and S.K. Debray.Towards Granularity Based Control of Parallelism in Logic Programs.In Hoon Hong, editor, Proc. of First International Symposium on Parallel Symbolic Computation, PASCO’94,pages 133–144. World Scientific, September 1994.
[LGHD96] P. Lopez-Garcıa, M. Hermenegildo, and S. K. Debray.A Methodology for Granularity Based Control of Parallelism in Logic Programs.Journal of Symbolic Computation, Special Issue on Parallel Symbolic Computation, 21(4–6):715–734, 1996.
[DLGHL94] S.K. Debray, P. Lopez-Garcıa, M. Hermenegildo, and N.-W. Lin.Estimating the Computational Cost of Logic Programs.In Static Analysis Symposium, SAS’94, number 864 in LNCS, pages 255–265, Namur, Belgium, September 1994.Springer-Verlag.
[DLGHL97] S. K. Debray, P. Lopez-Garcıa, M. Hermenegildo, and N.-W. Lin.Lower Bound Cost Estimation for Logic Programs.In 1997 International Logic Programming Symposium, pages 291–305. MIT Press, Cambridge, MA, October 1997.
[NMLGH07] J. Navas, E. Mera, P. Lopez-Garcıa, and M. Hermenegildo.User-Definable Resource Bounds Analysis for Logic Programs.In 23rd International Conference on Logic Programming (ICLP’07), volume 4670 of Lecture Notes in ComputerScience. Springer, 2007.
[MLGCH08] E. Mera, P. Lopez-Garcıa, M. Carro, and M. Hermenegildo.Towards Execution Time Estimation in Abstract Machine-Based Languages.In 10th Int’l. ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming (PPDP’08),pages 174–184. ACM Press, July 2008.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
[NMLH08] J. Navas, M. Mendez-Lojo, and M. Hermenegildo.Safe Upper-bounds Inference of Energy Consumption for Java Bytecode Applications.In The Sixth NASA Langley Formal Methods Workshop (LFM 08), April 2008.Extended Abstract.
[NMLH09] J. Navas, M. Mendez-Lojo, and M. Hermenegildo.User-Definable Resource Usage Bounds Analysis for Java Bytecode.In Proceedings of the Workshop on Bytecode Semantics, Verification, Analysis and Transformation(BYTECODE’09), volume 253 of Electronic Notes in Theoretical Computer Science, pages 6–86. Elsevier - NorthHolland, March 2009.
[LGDB10] P. Lopez-Garcıa, L. Darmawan, and F. Bueno.A Framework for Verification and Debugging of Resource Usage Properties.In M. Hermenegildo and T. Schaub, editors, Technical Communications of the 26th Int’l. Conference on LogicProgramming (ICLP’10), volume 7 of Leibniz International Proceedings in Informatics (LIPIcs), pages 104–113,Dagstuhl, Germany, July 2010. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik.
[SLBH13] A. Serrano, P. Lopez-Garcia, F. Bueno, M. Hermenegildo.Sized Type Analysis Logic Programs (Technical Communication).In Theory and Practice of Logic Programming, 29th Int’l. Conference on Logic Programming (ICLP’13) SpecialIssue, On-line Supplement, pages 1–14, Cambridge U. Press, August 2013.
[LKSGL13] U. Liqat, S. Kerrison, A. Serrano, K. Georgiou, P. Lopez-Garcia, N. Grech, M.V. Hermenegildo, K. Eder.Energy Consumption Analysis of Programs based on XMOS ISA-Level Models.In Pre-proceedings of the 23rd International Symposium on Logic-Based Program Synthesis and Transformation(LOPSTR’13), September 2013.
[SLH13] A. Serrano, P. Lopez-Garcia, M. Hermenegildo.Towards an Abstract Domain for Resource Analysis of Logic Programs Using Sized Types.In 23rd Workshop on Logic-based Methods in Programming Environments (WLPE 2013), 15 pages, August 2013.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
References – Automatic Parallelization, (Abstract) Partial Evaluation,Other Optimizations
[GH91] F. Giannotti and M. Hermenegildo.A Technique for Recursive Invariance Detection and Selective Program Specialization.In Proc. 3rd. Int’l Symposium on Programming Language Implementation and Logic Programming, number 528in LNCS, pages 323–335. Springer-Verlag, August 1991.
[PH97] G. Puebla and M. Hermenegildo.Abstract Specialization and its Application to Program Parallelization.In J. Gallagher, editor, Logic Program Synthesis and Transformation, number 1207 in LNCS, pages 169–186.Springer-Verlag, 1997.
[MBdlBH99] K. Muthukumar, F. Bueno, M. Garcıa de la Banda, and M. Hermenegildo.Automatic Compile-time Parallelization of Logic Programs for Restricted, Goal-level, IndependentAnd-parallelism.Journal of Logic Programming, 38(2):165–218, February 1999.
[PH99] G. Puebla and M. Hermenegildo.Abstract Multiple Specialization and its Application to Program Parallelization.J. of Logic Programming. Special Issue on Synthesis, Transformation and Analysis of Logic Programs,41(2&3):279–316, November 1999.
[PHG99] G. Puebla, M. Hermenegildo, and J. Gallagher.An Integration of Partial Evaluation in a Generic Abstract Interpretation Framework.In O Danvy, editor, ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation(PEPM’99), number NS-99-1 in BRISC Series, pages 75–85. University of Aarhus, Denmark, January 1999.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 75 / 80
[PH03] G. Puebla and M. Hermenegildo.Abstract Specialization and its Applications.In ACM Partial Evaluation and Semantics based Program Manipulation (PEPM’03), pages 29–43. ACM Press,June 2003.Invited talk.
[PAH06] G. Puebla, E. Albert, and M. Hermenegildo.Abstract Interpretation with Specialized Definitions.In SAS’06, number 4134 in LNCS, pages 107–126. Springer-Verlag, 2006.
[CCH08] A. Casas, M. Carro, and M. Hermenegildo.A High-Level Implementation of Non-Deterministic, Unrestricted, Independent And-Parallelism.In M. Garcıa de la Banda and E. Pontelli, editors, 24th International Conference on Logic Programming(ICLP’08), volume 5366 of LNCS, pages 651–666. Springer-Verlag, December 2008.
[MKSH08] M. Marron, D. Kapur, D. Stefanovic, and M. Hermenegildo.Identification of Heap-Carried Data Dependence Via Explicit Store Heap Models.In 21st Int’l. WS on Languages and Compilers for Parallel Computing (LCPC’08), LNCS. Springer-Verlag, August2008.
[MCH04] J. Morales, M. Carro, and M. Hermenegildo.Improving the Compilation of Prolog to C Using Moded Types and Determinism Information.In PADL’04, number 3057 in LNCS, pages 86–103. Springer-Verlag, June 2004.
[CMM+06] M. Carro, J. Morales, H.L. Muller, G. Puebla, and M. Hermenegildo.High-Level Languages for Small Devices: A Case Study.In Krisztian Flautner and Taewhan Kim, editors, Compilers, Architecture, and Synthesis for Embedded Systems,pages 271–281. ACM Press / Sheridan, October 2006.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 76 / 80
Ciao Architecture Overview
Compiler
Development EnvironmentEmacs based, command line,
top-levels (compilation, analysis)
Source (user and library)Packages
(multi-paradigm)
fsyntax
hiord
clpr
...
Modules(w./wo. assertions)
mod1
mod2
...modn
user interaction
Front-end Compiler(implements module system)
Expanded Code(Kernel Language)
Annotated/Transformed Code
Preprocessor
Analysis (types,modes, resources, . . . )
Verification (staticchecking of assertions)
Optimization (parallelism,specialization, . . . )
Back-end Compiler(optimized from annotations)
Executable Code(bytecode, native code)
Documenter(automatic
documentationfrom programswith assertions)
Run-time Engine and Libs.Multi-platform
Parallel, sequential, tabled, . . .
Compile-time MessagesErrors/warningsStatic Violations
Run-time MessagesDebugging
Dynamic Violations
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 76 / 80
The tabling algorithm via an example (OLDT resolution)
Example
:- table reach /2.
reach(X,Y) :-
edge(X,Z),
reach(Z,Y).
reach(X,Y) :-
edge(X,Y).
edge (1 ,2).
edge (2 ,1).
?- reach(1,Y).
Y = 1;
Y = 2;
no
Subgoal Answers
10. Y = 1
2. reach(1,Y) 15. Y = 2
18. Complete
9. Y = 1
5. reach(2,Y) 17. Y = 2
18. Complete
Y=2
1. reach(1,Y).
4. reach(2,Y).
7. reach(1,Y).
3. edge(1,Z), reach(Z,Y). 13. edge(1,Y).
6. edge(2,Z), reach(Z,Y). 8. edge(2,1).
14. edge(1,2).
12. fail
11. reach(1,1). 16. reach(1,2).
Z=2
Z=1
Y=1 Y=2
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 77 / 80
Entailment vs. Call Abstraction
TCHR: implementation of CHR on top of XSB Prolog with tabling.I It uses call abstraction.
Reach: is some graph in a node reachable within some distance?
Ciao TCLP TCHR
Reach 30 7 140 129 978
Reach 25 6 680 129 876
Reach 20 5 964 128 955
Reach 15 4 316 129 313
Reach 10 2 296 128 994
Reach 5 427 129 616
Reach 0 1 129 472
Constraints reduce the search space.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 78 / 80
The Assertion Language (subset)
:- pred Pred [:Precond] [=> Postcond] [+ Comp-formula ] .
Each typically a “mode” of use; the set covers the valid calls.:- pred quicksort(X,Y) : list(int) * var => sorted(Y) + (is det,not fails).
:- pred quicksort(X,Y) : var * list(int) => ground(X) + non det.
Properties; from libraries or user defined (in the source language)::- regtype color := green | blue | red.:- regtype list(X) :=[] | [ X|list]. ≡ list( ,[]). list(X,[H|T]) :- X(H), list(X,T).
:- prop sorted := [] | [ ] | [X,Y|Z] :- X > Y, sorted([Y|Z]).
Types/shapes, cost, data sizes, aliasing, termination, determinacy, non-failure, ...
Program-point Assertions:Inlined with code: ..., check( int(X), X>0, mshare([[X]]) ), ....
Assertion Status (so far “to be checked” – check status – default)Also: trust (guide analyzer), true/false (analysis output), test, etc.
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 79 / 80
Verification and Error Detection using Safe Approximations
[BDD+97, HPB99, PBH00c, PBH00a, HPBLG03]
Need to compare actual semantics [[P]] with intended semantics I:
P is partially correct w.r.t. I iff [[P]] ≤ IP is complete w.r.t. I iff I ≤ [[P]]P is incorrect w.r.t. I iff [[P]] 6≤ IP is incomplete w.r.t. I iff I 6≤ [[P]]
Usually, partial descriptions of I available, typically as assertions.
Problem: difficulty computing [[P]] w.r.t. interesting observables.
Approach: use a safe approximation of [[P]] → i.e., [[P]]α+ or [[P]]α−
Specially attractive if compiler computes (most of) [[P]]α+ anyway.
Definition Sufficient conditionP is prt. correct w.r.t. Iα if α([[P]]) ≤ Iα [[P]]α+ ≤ IαP is complete w.r.t. Iα if Iα ≤ α([[P]]) Iα ≤ [[P]]α=
P is incorrect w.r.t. Iα if α([[P]]) 6≤ Iα [[P]]α= 6≤ Iα, or[[P]]α+ ∩ Iα = ∅ ∧ [[P]]α 6= ∅
P is incomplete w.r.t. Iα if Iα 6≤ α([[P]]) Iα 6≤ [[P]]α+
Hermenegildo et al. (IMDEA, UPM, ...) Analysis and Verification “of and with” CLP Rich Model–Jun 16-17, 2013 80 / 80