|
1 | 1 | # Offline partial evaluation
|
| 2 | + |
| 3 | +## Motivation |
| 4 | + |
| 5 | +The offline partial evaluation is motivated by improving the experience |
| 6 | +for users seeking to integrate ASLp within other tools. |
| 7 | +With the original online method, |
| 8 | +only one opcode could be processed at a time, and |
| 9 | +each new opcode would require a complete traversal and simplification |
| 10 | +of the ASL specification. |
| 11 | +This is obviously inefficient |
| 12 | +and necessitates a tight coupling between ASLp |
| 13 | +and programs looking to use it. |
| 14 | + |
| 15 | +## Introduction |
| 16 | + |
| 17 | +Offline partial evaluation aims to improve this |
| 18 | +by performing much of the partial evaluation _ahead-of-time_ |
| 19 | +instead of once per-instruction. |
| 20 | +In the offline method, |
| 21 | +partial evaluation operates with only the knowledge |
| 22 | +that the opcode is constant, |
| 23 | +but without knowledge of the _value_ of the opcode. |
| 24 | + |
| 25 | +Further, |
| 26 | +we desire a separation of the "decoding" phase |
| 27 | +(where opcode bits are examined to determine _which_ instruction is represented), |
| 28 | +and the "execution" phase (where opcodes are executed and their actions performed). |
| 29 | +This delineation is implemented by hand-written lifters, |
| 30 | +where the language of the semantics IR is separate from the language used to implement the lifter itself. |
| 31 | + |
| 32 | +ASL itself has no such separation, but we can compute it with a _binding-time analysis_. |
| 33 | +In this analysis, |
| 34 | +constants and the instruction opcode are marked as *lift-time*, then the analysis |
| 35 | +traverses the AST in this way: |
| 36 | +- if an expression uses only lift-time values, it is also marked as *lift-time*, otherwise |
| 37 | +- the expression is marked as *run-time*. |
| 38 | +Lift-time values are simply emitted into the lifter's language, and |
| 39 | +will not be visible within the final semantics. |
| 40 | +Run-time-marked values are translated to a `gen_` prefixed function, |
| 41 | +indicating that this should be emitted into the semantics and deferred until run-time. |
| 42 | +This gives us an AST for a program which takes an opcode and then constructs a residual program |
| 43 | +representing the semantics of the instruction. |
| 44 | + |
| 45 | +In particular, this representation |
| 46 | +within an AST |
| 47 | +enables efficient translation of the lifter to arbitrary lifter languages and semantics languages. |
| 48 | +This is desirable, entirely eliminating the need to (de)serialise |
| 49 | +the semantics and communicate across language boundaries. |
| 50 | + |
| 51 | +## Overview |
| 52 | + |
| 53 | +The entry-point for the offline transformation process is the `run` function, |
| 54 | +near the end of [symbolic_lifter.ml](/libASL/symbolic_lifter.ml). |
| 55 | +Here, the process is divided into stages: |
| 56 | +- **Stage 1** - mock decoder & instruction encoding definitions: |
| 57 | + Converts the ASL decoder tree into separate functions making up a proper ASL program. |
| 58 | + Makes use of [decoder_program.ml](/libASL/decoder_program.ml). |
| 59 | +- **Stage 2** - call graph construction: |
| 60 | + Identifies reachable functions, using [call_graph.ml](/libASL/call_graph.ml). |
| 61 | +- **Stage 3** - simplification: |
| 62 | + Minor cleanup of temporary dynamic-length bit-vectors and unsupported structures. |
| 63 | +- **Stage 4** - specialisation: |
| 64 | + Performs requirement analysis to ensure bit-vector lengths |
| 65 | + and loop iterations are statically known. |
| 66 | + Inserts splits to branch on conditions determining these quantities. [req_analysis.ml](/libASL/req_analysis.ml). |
| 67 | +- **Stage 5** - disassembly: |
| 68 | + Invokes the online partial evaluation to reduce and inline structures, then |
| 69 | + simplifies with BDDs (an opcode-sensitive value analysis to, e.g., eliminate always-true assertions), |
| 70 | +- **Stage 6** - cleanup: |
| 71 | + Remove unused variables within each instruction function. |
| 72 | +- **Stage 7** - offline transform: |
| 73 | + Performs binding-time analysis and transformations, |
| 74 | + then BDD-based copy-propagation transform and one final cleanup. [offline_opt.ml](/libASL/offline_opt.ml). |
| 75 | + |
| 76 | +After the lifter is generated, it is passed to a "backend" |
| 77 | +which performs the (mostly syntactic) translation |
| 78 | +to a targeted lifter language. |
| 79 | + |
| 80 | +## Backends |
| 81 | + |
| 82 | +TODO: mechanism of a backend and how to implement one. |
| 83 | + |
| 84 | +- given a set of instruction functions |
| 85 | +- instruction-building interface |
| 86 | +- required: mutable variables, bitvector, bool, and int representations |
0 commit comments