summaryrefslogtreecommitdiff
path: root/src/jib
AgeCommit message (Collapse)Author
2019-05-17SMT: Finish adding all memory builtins from lib/regfp.sailAlasdair Armstrong
2019-05-16SMT: Tweak SMT generation interfaceAlasdair Armstrong
Expose AST -> Jib compilation function for SMT, and smt_header function Functorise the optimiser so it can output the SMT definitions to any data structure
2019-05-16SMT: Improve simplification for generated SMTAlasdair Armstrong
Generate addresses, kinds, and values separately for read and write events. Add an mli interface for jib_smt.ml
2019-05-14SMT: Allow printing SMT with an optional variable prefixAlasdair Armstrong
Allows us to mix generated SMT for two separate threads without name clashes, however we do want to be able to share datatypes so they are not prefixed. Currently the pretty-printer adds the prefix but we may want a smt_def -> smt_def renaming function instead.
2019-05-14Various bugfixesAlasdair Armstrong
Since we have __deref to desugar *x in this file (as it's the one file everything includes) we might as well add a __bitfield_deref here too, for the bitfield setters. Make sure undefined_nat can be used in C Both -memo_z3 and -no_memo_z3 were listed as default options, now only -no_memo_z3 is listed as the default.
2019-05-14SMT: Add comment explaining path conditionalsAlasdair Armstrong
2019-05-10SMT: Implement memory events for read_mem and write_memAlasdair
Generate SMT where the memory reads and writes are totally unconstrained, allowing additional constraints to be added that restrict the possible reads and writes based on some memory model.
2019-05-10SMT: Experiment with symbolic memory reads and writesAlasdair Armstrong
2019-05-10SMT: Fix error in get_pathcondAlasdair Armstrong
2019-05-10SMT: Lazily compute efficient path conditionalsAlasdair
Effectively reverts 7280e7b with a different method that isn't slow, although it's not totally clear that this is correct - it could just be more subtly wrong than before commit 7280e7b. Following is mostly so I can remember what I did to document & write up properly at some point: What we do is compute 'pi' conditions as before by traversing the dominator tree, we each node having a pi condition defined as the conjunction of all guards between it and the start node in the dominator tree. This is imprecise because we have situations like 1 / \ 2 3 | | | 4 | |\ 5 6 9 \ / | 7 10 | 8 where 8 = match_failure, 1 = start and 10 = return. 2, 3, 6 and 9 are guards as they come directly after a control flow split, which always follows a conditional jump. Here the path through the dominator tree for the match_failure is 1->7->8 which contains no guards so the pi condition would be empty. What we do now is walk backwards (CFG must be acyclic at this point) until we hit the join point prior to where we require a path condition. We then take the disjunction of the pi conditions for the join point's predecessors, so 5 and 6 in this case. Which gives us a path condition of 2 | (3 & 6) as the dominator chains are 1->2->5 and 1->3->4->6. I think this works as any split in the control flow must have been caused by a conditional jump followed by distinct guards, so each of the nodes immediately prior to a join point must be dominated by at least one unique guard. It also explains why the pi conditions seem sufficient to choose outcomes of phi functions. If we hit a guard before a join (such as 9 for return's path conditional) we just return the pi condition for that guard, i.e. (3 & 9) for 10. If we reach start then the path condition is simply true.
2019-05-09SMT: Add explicit terminators to SSA graphAlasdair Armstrong
Makes the graph slightly cleaner, and means we can represent conditionals in a way that shoud allow computing path conditions much easier. Essentially rather than a basic block being a list of instructions where the last instruction is a jump (or other terminator) it is now a list of instructions combined with an explict terminator, i.e. CF_block (instrs @ I_jump (cval, label) ==> CF_block (instrs, T_jump (n, label)) Rather than storing the cval in the T_jump it just has a number that links to a mapping from numbers to cvals, and we represent the negation of any cval in that table by negating its number. Therefore at any join point in the CFG, we can efficiently check when the joining path conditionals contain both n and minus n and remove both.
2019-05-09SMT: Make path conditionals more preciseAlasdair Armstrong
Previously path conditionals for a node were defined as the path conditional of the immediate dominator (+ a guard for explicit guard nodes after conditional branches), whereas now they are the path conditional of the immediate dominator plus an expression encapsulating all the guards between the immediate dominator and the node. This is needed as the previous method was incorrect for certain control flow graphs. This slows down the generated SMT massively, because it causes the path conditionals to become huge when the immediate dominator is far away from the node in question. It also changes computing path conditionals from O(n) to O(n^2) which is not ideal as our inlined graphs can become massive. Need to figure out a better way to generate minimal path conditionals between the immediate dominator and the node. I upped the timeout for the SMT tests from 20s to 300s each but this may still cause a failure in Jenkins because that machine is slow.
2019-05-08SMT: Add test for various real number propertiesAlasdair Armstrong
2019-05-08SMT: Add reals and strings to SMT backendAlasdair Armstrong
Jib_compile now has an option that lets it generate real value literals (VL_real), which we don't want for backends (i.e. C), which don't support them. Reals are encoded as actual reals in SMT, as there isn't really any nice way to encode them as bitvectors. Currently we just have the pure real functions, functions between integers and reals (i.e. floor, to_real, etc) are not supported for now. Strings are likewise encoded as SMTLIB strings, for similar reasons. Jib_smt has ctx.use_real and ctx.use_string which are set when we generate anything real or string related, so we can keep the logic as Arrays+Bitvectors for most Sail that doesn't require either.
2019-05-07Move parser combinators shared by property and model parsing to separate fileAlasdair Armstrong
2019-05-07SMT: Use builtin_type_error consistently across builtin definitionsAlasdair Armstrong
2019-05-05C: Add option to compile using __int128 rather than GMPAlasdair
Only requires a very small change to c_backend.ml. Most of this commit is duplication of the builtins and runtime in lib/int128. But the actual differences in those files is also fairly minor could be handled by some simple ifdefs for the integer builtins.
2019-05-03Jib: Optimize set_slice for ARM v8.5Alasdair Armstrong
2019-05-03Jib: Fix optimizations for SMT IR changesAlasdair Armstrong
Fixes C backend optimizations that were disabled due to changes in the IR while working on the SMT generation. Also add a -Oaarch64_fast option that optimizes any integer within a struct to be an int64_t, which is safe for the ARM v8.5 spec and improves performance significantly (reduces Linux boot times by 4-5 minutes). Eventually this should probably be a directive that can be attached to any arbitrary struct/type. Fixes the -c_specialize option for ARM v8.5. However this only gives a very small performance improvment for a very large increase in compilation time however.
2019-05-01SMT: Fix some C optimisations that were disabledAlasdair Armstrong
Need to get these working again before we can thing about merging back into sail2
2019-05-01Jib: Refactor V_callAlasdair Armstrong
Get rid of separate V_op and V_unary constructors. jib.ott now defines the valid operations for V_call including zero/sign extension, in such a way that the operation ctyp can be inferred. Overall this makes the IR less ad-hoc, and means we can share more code between SMT and C. string_of_cval no longer used by c_backend, which now uses sgen_cval following other sgen_ functions in the code generator, meaning string_of_cval doesn't have to produce valid C code anymore and so can be used for backend-agnostic debug and error messages.
2019-04-30SMT: Allow custom queriesAlasdair Armstrong
As an example: $counterexample :query exist match_failure function prop(xs: bits(4)) -> unit = { match xs { _ : bits(3) @ 0b0 => () } } Will return Solver found counterexample: ok xs -> 0x1 as we are asking for an input such that a match failure occurs, meanwhile $counterexample :query ~(exist match_failure) function prop(xs: bits(4)) -> unit = { match xs { _ : bits(3) @ 0b0 => () } } will return 0x0 as we are asking for an input such that no match failure occurs. Note that we can now support properties for non-boolean functions by not including the return event in the query.
2019-04-30SMT: Fix dead-code FIXME in jib_compileAlasdair Armstrong
Add an Assumption event that is true whenever a property's type quantifier is true, rather than wrapping body in a if-statement that ends up creating a dead branch.
2019-04-30SMT: Simplify and generalise checking eventsAlasdair Armstrong
SMT query now expressed as a logical expression over events, so e.g. let default_query = Q_or [Q_and [Q_all Assertion; Q_all Return; Q_not (Q_exist Match)]; Q_exist Overflow] Checks either an overflow occurred, or the function returned true, while all assertions held, and no match failures occurred. Currently there is only the default query but the plan is to make this user-specifiable in the $property/$counterexample directives.
2019-04-29SMT: Refactor overflow checks into generic event checking systemAlasdair Armstrong
Have assert events for assertions and overflow events for potential integer overflow. Unclear how these should interact... The order in which such events are applied to the final assertion is potentially quite important. Overflow checks and assertions are now path sensitive, as they should be.
2019-04-29SMT: Support arbitrary tuple sizesAlasdair Armstrong
2019-04-27Merge branch 'sail2' into smt_experimentsAlasdair
2019-04-25SMT: Provide a more useful error message when topsort failsAlasdair
2019-04-24SMT: Make sure we clear overflow checks between generating propertiesAlasdair Armstrong
2019-04-24SMT: Can now recheck some simple models via the interpreterAlasdair
Probably need to clean-up the implementation and merge new_interpreter into this branch before supporting re-checking counterexamples with more things.
2019-04-23SMT: Add some commentsAlasdair
2019-04-23SMT: Only check counterexamples automatically with -smt_auto flagAlasdair Armstrong
2019-04-23SMT: Add parser for generated modelsAlasdair Armstrong
Simple parser-combinator style parser for generated models. It's actually quite tricky to reconstruct the models because we can have: let x = something $counterexample function prop(x: bits(32)) -> bool = ... where the function argument becomes zx/1 rather than zx/0, which is what we'd expect for the argument of a property. Might need to do something smarter with encoding locations into smt names to figure out what SMT variables correspond to which souce variables exactly. The above also previously generated incorrect SMT, which has now been fixed.
2019-04-23SMT: Add signed builtinThomas Bauereiss
2019-04-20SMT: Support writing to register referencesAlasdair Armstrong
Add a new AE_write_ref constructor in the ANF representation to make writes to register references explicit in Jib_compile
2019-04-17SMT: Automatically get model when $counterexample is used rather than $propertyAlasdair Armstrong
2019-04-17SMT: Support register referencesAlasdair Armstrong
2019-04-17SMT: Support generic vectors and handle lets between specs and functionsAlasdair Armstrong
If we have e.g. $property val prop : ... let X = 0 function prop(...) = X == ... then we need to ensure that let X is included when we generate the property.
2019-04-17SMT: Unroll simple foreach loopsAlasdair Armstrong
2019-04-16Fix: Don't repeat ctyp_of_typ callAlasdair Armstrong
2019-04-16Remove unnecessary assertThomas Bauereiss
2019-04-16SMT: Support toplevel letbindingsAlasdair Armstrong
2019-04-16SMT: Fix inlining issuesAlasdair Armstrong
2019-04-16BugfixingThomas Bauereiss
2019-04-16SMT: Take care to not generate duplicate labelsThomas Bauereiss
2019-04-16SMT: Add struct value literalsAlasdair
Generates much better SMT that assigning each field one-by-one starting with an undefined struct.
2019-04-15Add more SMT builtinsThomas Bauereiss
2019-04-15SMT: Allow partial specializationsAlasdair Armstrong
Change specialisation so we only specialize integer parameters when they are constant. This makes ensures that the integer-specialised code is always type-correct.
2019-04-15Fix: Allow zero-length vector literalsAlasdair Armstrong
2019-04-15Basic loop termination measures for CoqBrian Campbell
Currently only supports pure termination measures for loops with effects. The user syntax uses separate termination measure declarations, as in the previous recursive termination measures, which are rewritten into the loop AST nodes before type checking (because it would be rather difficult to calculate the correct environment to type check the separate declaration in).