Skip to content

Commit b77c233

Browse files
committed
offline.md
1 parent 5dbf47a commit b77c233

File tree

2 files changed

+97
-11
lines changed

2 files changed

+97
-11
lines changed

docs/offline.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,86 @@
11
# 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

docs/online.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@ It does this "online" by recording,
99
for each variable,
1010
whether that variable is a concrete, symbolic, or unknown value
1111
(in order of simplification potential).
12-
Concrete values are simple literals which can almost always be immediately evaluated
13-
in expressions.
14-
Pure symbolic expressions are pure transformations of a combination
15-
of concrete and symbolic/unknown values.
16-
For example, this includes "(x + 1) - 1" and this can be used to simplify
17-
using algebraic properties of integers and bitvectors.
18-
The last type, unknown, is any computation which is opaque at partial-evaluation time.
19-
Most often, this is register and memory accesses.
20-
When used in an expression, this will emit code to perform the computation and store
21-
it into a read-only variable, transforming it into a pure symbolic expression.
12+
13+
- Concrete values are simple literals which can almost always be immediately evaluated
14+
in expressions.
15+
- Pure symbolic expressions are pure transformations of a combination
16+
of concrete and symbolic/unknown values.
17+
For example, this includes "(x + 1) - 1" and this can be used to simplify
18+
using algebraic properties of integers and bitvectors.
19+
- The last type, unknown, is any computation which is opaque at partial-evaluation time.
20+
Most often, this is register and memory accesses.
21+
When encountered in an expression, this will emit code to perform the computation and store
22+
it into a read-only variable, transforming it into a pure symbolic expression.
2223

2324
## Implementation
2425

2526
Within ASLp, the partial evaluation features are implemented by three files
2627
with different responsibilities.
2728
These are: symbolic.ml, dis.ml, and transforms.ml.
28-
This is also the order from lower-level concepts (expressions)
29+
This corresponds to the order from lower-level concepts (expressions)
2930
to higher-level ones (statements and programs).
3031

3132
### symbolic.ml

0 commit comments

Comments
 (0)