summaryrefslogtreecommitdiff
path: root/src/constant_fold.ml
AgeCommit message (Collapse)Author
2020-09-28Refactor: Rename 'a defs to 'a astAlasdair
Change internal terminology so we more clearly distinguish between a list of definitions 'defs' and functions that take an entire abstract syntax trees 'ast'.
2020-04-15Add more intuitive defaults to interactive toplevelAlasdair
sail -i now starts an interactive toplevel with a few additional options set by default: - It applies the "interpreter" rewrites to any files passed on the command line. - It also applies those rewrites after the :l/:load command - Registers previously started in a disabled state, as the interactive shell made no default decision as to how to handle undefined (which is the initial value for all registers). Now -i implies -undefined_gen - Better help text for :fix_registers - Nullary interactive actions generate Sail functions that round-trip through pretty printing and parsing (bugfix) The -interact_custom flag has the same behavior as the previous -i flag This commit also improves the c/ocaml/interpreter test harness so it cleans up temporary files which could cause issues with stale files when switching ocaml versions
2019-11-14Fix typo in constant folding for and_bool/or_boolAlasdair Armstrong
2019-11-06Allow specifying specific fields of a register as constant with ↵Alasdair Armstrong
:fixed_registers command
2019-11-06Add toplevel commands to fix specific register values and simply spec ↵Alasdair Armstrong
accordingly
2019-10-31Allow sail to be scripted using sailAlasdair
Currently the -is option allows a list of interactive commands to be passed to the interactive toplevel, however this is only capable of executing a sequential list of instructions which is quite limiting. This commit allows sail interactive commands to be invoked from sail functions running in the interpreter which can be freely interleaved with ordinary sail code, for example one could test an assertion at each QEMU/GDB breakpoint like so: $include <aarch64.sail> function main() -> unit = { sail_gdb_start("target-select remote localhost:1234"); while true do { sail_gdb_continue(); // Run until breakpoint sail_gdb_sync(); // Sync register state with QEMU if not(my_assertion()) { print_endline("Assertion failed") } } }
2019-07-11Make sure we do constant-fold primitives howeverAlasdair Armstrong
Previous change would stop all things defined externally from being folded, which was overly strict. We do want to allow folding for shared primitives, and can use the set of safe_primops in the interpreter for this.
2019-07-11Make sure constant folding won't fold external definitions that also have ↵Alasdair Armstrong
sail definitions Definitions can be made external on a per-backend basis, so we need to make sure constant folding doesn't inline external functions that have sail definitions for backends other than the ones we are currently targetting
2019-05-22Move Util.warn to Reporting, and make it take the location as a parameterAlasdair Armstrong
Also add a $suppress_warnings directive that ensures that no warnings are generated for a specific file.
2019-05-06Don't initialise registers in interpreter when register accesses not allowedBrian Campbell
Avoids having to handle unexpected undefined values during constant propagation.
2019-04-20Fix: Reduce constant-fold time for ARM from 20min+ to 10sAlasdair Armstrong
With the new interpreter changes computing the initial state for the interpreter does some significant work. The existing code was re-computing the initial state for every subexpression in the specification (not even just the ones due to be constant-folded away). Now we just compute the initial state once and use it for all constant folds. Also reduce the time taken for the simple_assignments rewrite from 20s to under 1s for ARMv8.5, by skipping l-expressions that are already in the simplest form.
2019-04-15Merge branch 'sail2' into rmem_interpreterJon French
2019-03-15Add a rewriting pass for constant propagation in mutrecsThomas Bauereiss
Propagating constants into mutually recursive calls and removing dead branches might break mutually recursive cycles. Also make constant propagation use the existing interpreter-based constant folding to evaluate function calls with only constant arguments (as opposed to a mixture of inlining and hard-coded rewrite rules).
2019-03-14Merge branch 'sail2' into rmem_interpreterJon French
2019-03-13Refactor interpreter monad to include pp in effect requests/failuresJon French
2019-03-06Add option to slice out printing and tracing functions when generating CAlasdair Armstrong
Make instruction dependency graph use graph.ml Expose incremental graph building functions for performance in graph.mli
2019-03-05More optimizations and improvments for C generationAlasdair Armstrong
Add some comments in constant_fold.ml
2019-02-25Merge branch 'sail2' into rmem_interpreterJon French
2019-02-14Fix a bug that caused constant propagation option to fail for v8.5Alasdair Armstrong
Make type-at-cursor work for scattered function clauses in emacs
2019-02-13Merge branch 'sail2' into rmem_interpreterJon French
2019-01-02...without debug printingJon French
2019-01-02restore V_attempted_read behaviour after mergeJon French
2018-12-28Merge branch 'sail2' into rmem_interpreterJon French
2018-12-27pass typechecking environment around interpreter and rewritersJon French
2018-12-22Improve error messages and debuggingAlasdair Armstrong
Work on improving the formatting and quality of error messages When sail is invoked with sail -i, any type errors now drop the user down to the interactive prompt, with the interactive environment being the environment at the point the type error occurred, this means the typechecker state can be interactively queried in the interpreter to help diagnose type errors.
2018-12-13Fixing rationals in Sail interpreter and OCamlAlasdair Armstrong
2018-12-04Remove FES_Fexps constructorAlasdair Armstrong
This makes dealing with records and field expressions in Sail much nicer because the constructors are no longer stacked together like matryoshka dolls with unnecessary layers. Previously to get the fields of a record it would be either E_aux (E_record (FES_aux (FES_Fexps (fexps, _), _)), _) but now it is simply: E_aux (E_record fexps, _)
2018-11-28Allow folding constant expressions into single register readsAlasdair
Essentially all we have to do to make this work is introduce a member of the Value type, V_attempted_read <reg>, which is returned whenever we try to read a register value with allow_registers disabled. This defers the failure from reading the register to the point where the register value is used (simply because nothing knows how to deal with V_attempted_read). However, if V_attempted_read is returned directly as the result of evaluating an expression, then we can replace the expression with a single direct register read. This optimises some indirection in the ARM specification.
2018-11-23C backend improvementsAlasdair Armstrong
- Propagate types more accurately to improve optimization on ANF representation. - Add a generic optimization pass to remove redundant variables that simply alias other variables. - Modify Sail interactive mode, so it can compile a specification with the :compile command, view generated intermediate representation via the :ir <function> command, and step-through the IR with :exec <exp> (although this is very incomplete) - Introduce a third bitvector representation, between fast fixed-precision bitvectors, and variable length large bitvectors. The bitvector types are now from most efficient to least * CT_fbits for fixed precision, 64-bit or less bitvectors * CT_sbits for 64-bit or less, variable length bitvectors * CT_lbits for arbitrary variable length bitvectors - Support for generating C code using CT_sbits is currently incomplete, it just exists in the intermediate representation right now. - Include ctyp in AV_C_fragment, so we don't have to recompute it
2018-09-10Various fixesAlasdair Armstrong
C: Don't print usage message and quit when called with no arguments, as this is used for testing C output OCaml: Fix generation of datatypes with multiple type arguments OCaml: Generate P_cons pattern correctly C: Fix constant propagation to not propagate letbindings with type annotations. This behaviour could cause type errors due to how type variables are introduced. Now we only propagate letbindings when the type of the propagated variable is guaranteed to be the same as the inferred type of the binding. Tests: Add OCaml tests to the C end-to-end tests (which really shouldn't be in test/c/ any more, something like test/compile might be better). Currently some issues with reals there like interpreter. Tests: Rename list.sail -> list_test.sail because ocaml doesn't want to compile files called list.ml.
2018-08-23Fix interpreter after re-writer changeAlasdair Armstrong
Interpreter used a re-write (vector concat removal) that is dependent on the vector_string_to_bit_list rewriting pass. This fixes the interpreter to work without either vector concat removal, or turning bitstrings into vector literals like [bitzero, bitzero, bitone]. This has the upside of reducing the number of steps the interpreter needs for working with bitvectors so should improve interpreter performance. We also now test all the C compilation tests behave the same using the interpreter. Currently the real number tests fail due to limitations of Lem's rational library (this must be fixed in Lem). This required supporting configuration registers in the interpreter. As such the interpreter was refactored to more cleanly process registers when building an initial global state. The functions are also collected into the global state, which removes the need to search for them in the AST every time a function call happens. This should not only improve performance, but also removes the need to pass an AST into the interpretation functions.
2018-08-17Improve builtins testsAlasdair Armstrong
Test the builtin functions by compiling them to C, OCaml, and OCaml via Lem. Split up some of the longer builtin test programs to avoid stack overflows when compiling to OCaml, as 3000+ line long blocks can cause issues with some re-writing steps. Also test constant-folding with builtins (this should reduce the asserts in these files to assert true), and also test constant folding with the C compilation. Fix a bug whereby vectors with heap-allocated elements were not initialized correctly. Fix a bug caused by compiling and optimising empty vector literals. Fix an OCaml test case that broke due to the ref type being used. Now uses references to registers. Fix a bug where Sail would output big integers that lem can't parse. Checks if integer is between Int32.min_int and Int32.max_int and if not, use integerOfString to represent the integer. Really this should be fixed in Lem. Make the python test runner script the default for testing builtins and running the C compilation tests in test/run_tests.sh Add a ocaml_build_dir option that sets a custom build directory for OCaml. This is needed for running OCaml tests in parallel so the builds don't clobber one another.
2018-06-29Constant folding improvementsAlasdair
2018-06-06Fix a typo.Yao Li
2018-06-07Add a constant folding optimization passAlasdair