Skip to content

Commit a855f50

Browse files
Merge pull request #7554 from thomasspriggs/tas/goto-transform-docs
Add documentation for an overview of the goto program transformation passes
2 parents fd457d2 + 06a68ec commit a855f50

File tree

2 files changed

+319
-0
lines changed

2 files changed

+319
-0
lines changed

doc/architectural/cbmc-architecture.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ To be documented.
6969

7070
## Instrumentation: goto functions → goto functions
7171

72+
For an overview of the transformations applied to goto programs after the
73+
generation of the initial goto program and before BMC, see
74+
\subpage goto-program-transformations .
75+
7276
To be documented.
7377

7478
## Goto functions → BMC → Counterexample (trace)
Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
\ingroup module_hidden
2+
3+
\page goto-program-transformations Goto Program Transformations
4+
5+
\section required-transforms Core Transformation Passes
6+
7+
This section lists the transformation passes that must have been applied for the
8+
goto model to be in core goto format.
9+
10+
Note that the passes are listed below in the order they are currently called in
11+
CBMC. While all dependencies on the ordering are not fully documented, the
12+
following order should be used.
13+
14+
\subsection assembly-transform Removal/Lowering of Assembly
15+
16+
This pass goes through the goto model and removes or lowers instances of
17+
assembly intructions. Assembly instructions are stored in instances of the
18+
`other` instruction.
19+
20+
The implementation of this pass is called via the \ref remove_asm(goto_modelt &)
21+
function. For full documentation of this pass see \ref remove_asm.h
22+
23+
<em>This pass has no predecessor.</em>
24+
25+
\subsection linking-transform Linking of Standard Libraries
26+
27+
This pass links the function definitions from the Cprover standard library
28+
models to the current goto model.
29+
30+
The implementation of this pass is called via the \ref
31+
link_to_library(goto_modelt &, message_handlert &, const std::function<void(const std::set<irep_idt> &, const symbol_tablet &, symbol_tablet &, message_handlert &)> &) "link_to_library function."
32+
33+
<em>Predecessor pass is \ref assembly-transform .</em>
34+
35+
\subsection function-pointer-transform Removal/Lowering of Function Pointers
36+
37+
This pass finds all the instructions which are function calls to the value of a
38+
function pointer. Each instruction is then replaced with a switch block. The
39+
switch block contains a case for each of the potential targets of the function
40+
pointer. The targets are found by looking for all functions in the goto program
41+
that approximately match the type of the function pointer.
42+
43+
Note that for this pass to work as intended, all potential targets of calls to
44+
function pointers must be in the model. Otherwise they will not be added to the
45+
relevant switch blocks. This may cause the assertion that the switch blocks'
46+
fallthrough is unreachable to be shown to be violated via an invalid counter
47+
example.
48+
49+
The implementation of this pass is called via the \ref
50+
remove_function_pointers(message_handlert &, goto_modelt &, bool)
51+
"remove_function_pointers" function. Detailed documentation of this pass belongs
52+
in \ref remove_function_pointers.h
53+
54+
<em>Predecessor pass is the \ref linking-transform or the optional
55+
\ref string-instrument-transform if it is being used.</em>
56+
57+
\subsection mmio-transform Memory Mapped IO Instrumentation
58+
59+
This pass finds pointer dereferences and adds corresponding calls to the
60+
`__CPROVER_mm_io_r` and `__CPROVER_mm_io_w` modelling functions if they exist.
61+
See the device behaviour section of `modeling-mmio.md` for details of
62+
modeling memory-mapped I/O regions of device interfaces. This pass is always
63+
carried out but will only make changes if one of the modelling functions exist.
64+
65+
The implementation of this pass is called via the \ref mm_io(goto_modelt &)
66+
"mm_io" function. Further documentation of this pass can be found in \ref
67+
mm_io.h
68+
69+
<em>Predecessor pass is \ref function-pointer-transform .</em>
70+
71+
72+
\subsection precondition-transform Instrument/Remove Preconditions
73+
74+
This pass moves preconditions associated with functions to call sites rather
75+
than at the head of the function. Note that functions may have multiple call
76+
sites and in this case the instrumentation is copied to these multiple call
77+
sites.
78+
79+
The implementation of this is called via \ref
80+
instrument_preconditions(goto_modelt &goto_model) . Documentation of this pass
81+
belongs in \ref instrument_preconditions.h
82+
83+
<em>Predecessor pass is \ref mmio-transform.</em>
84+
85+
86+
\subsection returns-transform Removal/Lowering of Return Statements
87+
88+
This pass replaces returns of values with writes and reads to global variables.
89+
90+
The implementation of this is called via \ref remove_returns(goto_modelt &) .
91+
Detailed documentation of this pass can be found in \ref remove_returns.h
92+
93+
<em>The predecessor passes is the \ref precondition-transform or the optional
94+
\ref inlining-transform if is being used.</em>
95+
96+
97+
\subsection vector-transform Remove/Lower Vector Typed Expressions
98+
99+
This pass removes/lowers expressions corresponding to CPU instruction sets such
100+
as MMX, SSE and AVX. For more details on how this is done see vector_typet and
101+
remove_vector.cpp. The implementation of this is called via \ref
102+
remove_vector(goto_modelt &goto_model)
103+
104+
<em>Predecessor pass is \ref returns-transform.</em>
105+
106+
107+
\subsection complex-transform Remove/Lower Complex Typed Expressions
108+
109+
This pass is for the handling of complex numbers in the mathematical sense of a
110+
number consisting of paired real and imaginary parts. These are removed/lowered
111+
in this pass. The implementation of this is called via \ref
112+
remove_complex(goto_modelt &) . Documentation for this pass belongs in \ref
113+
remove_complex.h
114+
115+
<em>Predecessor pass is \ref vector-transform.</em>
116+
117+
118+
\subsection unions-transform Rewrite Unions
119+
120+
This pass converts union member access into byte extract and byte update
121+
operations.
122+
123+
The implementation of this pass is called via \ref rewrite_union(goto_modelt &)
124+
125+
<em>Predecessor pass is \ref complex-transform.</em>
126+
127+
128+
\subsection check-c-transform goto_check_c
129+
130+
This is a pass that can add many checks and instrumentation largely related to
131+
the definition of the C language. Note that this transformation pass is
132+
mandatory in the current implementation, however it may have no effect depending
133+
on the command line options specified.
134+
135+
The implementation of this pass is called via \ref
136+
goto_check_c(const optionst &, goto_modelt &, message_handlert &)
137+
138+
<em>Predecessor pass is \ref unions-transform.</em>
139+
140+
141+
\subsection floats-transform Adjust Float Expressions
142+
143+
This is a transform from general mathematical operations over floating point
144+
types into floating point specific operator variations which include a rounding
145+
mode.
146+
147+
The implementation of this pass is called via \ref
148+
adjust_float_expressions(goto_modelt &) . Documentation of this pass can be
149+
found in \ref adjust_float_expressions.h
150+
151+
<em>Predecessor pass is \ref check-c-transform or the optional \ref
152+
assertions-transform if it is being used.</em>
153+
154+
155+
\subsection update-transform Goto Functions Update
156+
157+
This transformation updates in memory data goto program fields which may
158+
have been invalidated by previous passes. Note that the following are performed
159+
by this pass:
160+
- Incoming edges
161+
- Target numbers
162+
- location numbers
163+
- loop numbers
164+
165+
The implementation of this pass is called via \ref goto_functionst::update()
166+
167+
<em>Predecessor pass is \ref floats-transform or the optional \ref
168+
string-abstraction-transform if it is being used.</em>
169+
170+
171+
\subsection failed-symbols-transform Add Failed Symbols
172+
173+
This pass adds failed symbols to the symbol table. See
174+
`src/pointer-analysis/add_failed_symbols.h` for details. The implementation of
175+
this pass is called via \ref add_failed_symbols(symbol_table_baset &) . The
176+
purpose of failed symbols is explained in the documentation of the function \ref
177+
goto_symext::dereference(exprt &, statet &, bool)
178+
179+
<em>Predecessor pass is \ref update-transform or the optional \ref
180+
nondet-transform if it is being used.</em>
181+
182+
183+
\subsection remove-skip-transform Remove Skip Instructions
184+
185+
This transformation removes skip instructions. Note that this transformation is
186+
called in many places and may be called as part of other transformations. This
187+
instance here is part of the mandatory transformation to reach core goto format.
188+
If there is a use case where it is desirable to preserve a "no operation"
189+
instruction, a `LOCATION` type instruction may be used in place of a `SKIP`
190+
instruction. The `LOCATION` instruction has the same semantics as the `SKIP`
191+
instruction, but is not removed by the remove skip instructions pass.
192+
193+
The implementation of this pass is called via \ref remove_skip(goto_modelt &)
194+
195+
<em>Predecessor pass is \ref failed-symbols-transform or the optional \ref
196+
unused-functions-transform if it is being used.</em>
197+
198+
199+
200+
\subsection properties-transform Label Properties
201+
202+
This transformation adds newly generated unique property identifiers to assert
203+
instructions. The property identifiers are stored in the location data structure
204+
associated with each instruction.
205+
206+
The implementation of this pass is called via \ref
207+
label_properties(goto_modelt &)
208+
209+
<em>Predecessor pass is \ref remove-skip-transform or the optional \ref
210+
coverage-transform if it is being used.</em>
211+
212+
213+
214+
\section optional-transforms Optional Transformation Passes
215+
216+
The sections lists the optional transformation passes that are optional and will
217+
modify a goto model. Note that these are documented here for consistency, but
218+
not required for core goto format.
219+
220+
Note for each optional pass there is a listed predeceesor pass. This is the pass
221+
currently called before the listed pass in CBMC. While the ordering may not be
222+
fully documented, this should be followed.
223+
224+
\subsection string-instrument-transform String Instrumentation
225+
226+
This (optional) pass adds checks on calls to some of the C standard library
227+
string functions. It uses the tracking information added by the
228+
\ref string-abstraction-transform pass. It is switched on by the
229+
`--string-abstraction` command line option.
230+
231+
The implementation of this pass is called via the
232+
\ref string_instrumentation(goto_modelt &goto_model) function. Detailed
233+
documentation of this pass belongs in \ref string_instrumentation.h
234+
235+
<em>The predecessor pass is \ref linking-transform .</em>
236+
237+
\subsection inlining-transform Partial Inlining
238+
239+
This pass does partial inlining when this option is switched on. Partal inlining
240+
is inlining of functions either: marked as inline, or smaller than a specified
241+
limit. For further detail see the implementation function \ref
242+
goto_partial_inline(goto_modelt &, message_handlert &, unsigned, bool)
243+
244+
<em>Predecessor pass is \ref precondition-transform.</em>
245+
246+
247+
\subsection assertions-transform Transform Assertions Assumptions
248+
249+
This pass removes user provided assertions and assumptions when user has opted
250+
to do so. Note that this pass removes skip instructions if any other changes
251+
are made. The implementation of this pass is called via the \ref
252+
transform_assertions_assumptions(const optionst &, goto_modelt &) function.
253+
254+
<em>Predecessor pass is \ref check-c-transform.</em>
255+
256+
257+
\subsection string-abstraction-transform String Abstraction
258+
259+
This (optional) transformation pass adds tracking of length of C strings. It is
260+
switched on by the `--string-abstraction` command line option. This changes made
261+
by this pass are documented as part of the documentation for the \ref
262+
string_abstractiont class. The implementation of this pass is called via the
263+
\ref string_abstraction(goto_modelt &, message_handlert &) function.
264+
265+
<em>Predecessor pass is \ref floats-transform.</em>
266+
267+
268+
\subsection nondet-transform Add Non-Deterministic Initialisation of Global Scoped Variables
269+
270+
This transformation adds non-deterministic initialisation of global scoped
271+
variables including static variables. For details see
272+
`src/goto-instrument/nondet_static.h`. The initialisation code is added to the
273+
`CPROVER_initialize` function in the goto model. The implementation of this pass
274+
is called via the \ref nondet_static(goto_modelt &) function.
275+
276+
<em>Predecessor pass is \ref update-transform.</em>
277+
278+
279+
\subsection unused-functions-transform Remove Unused Functions
280+
281+
This pass removes unused functions from the goto model. In practice this builds
282+
a collection of all the functions that are potentially called, and then removes
283+
any function not in this collection.
284+
285+
This pass cannot handle function calls via function pointers. Attempting to run
286+
this pass against a goto model which contains such a function call will result
287+
in an invariant violation. Therefore the function pointer removal pass must
288+
always be applied to the goto model before the remove unused functions pass.
289+
290+
The implementation of this pass is called via the \ref
291+
remove_unused_functions(goto_modelt &, message_handlert &) function.
292+
293+
<em>Predecessor pass is \ref failed-symbols-transform.</em>
294+
295+
296+
\subsection coverage-transform Add Coverage Goals
297+
298+
This transformation adds coverage goals instrumentation and is only applied if
299+
the `--cover` option has been specified. The implementation of this pass is
300+
called via the \ref instrument_cover_goals(const cover_configt &, goto_modelt &, message_handlert &)
301+
function.
302+
303+
<em>Predecessor pass is \ref remove-skip-transform .</em>
304+
305+
306+
\subsection slicing-transforms Slicing
307+
308+
This includes several slicing passes as specified by various slicing command
309+
line options. The reachability slicer is enabled by the `--reachability-slice`
310+
command line option. The implementation of this pass is called via the \ref
311+
reachability_slicer(goto_modelt &, message_handlert &) function. The full slicer
312+
is enabled by the `--full-slice` command line option. The implementation of this
313+
pass is called via the \ref full_slicer(goto_modelt &) function.
314+
315+
<em>Predecessor pass is \ref properties-transform .</em>

0 commit comments

Comments
 (0)