Skip to content

Commit 107d5a8

Browse files
authored
Merge pull request #4095 from marek-trtik/doc_dep_graph
DOC-56: An overview of grapht and dependence_grapht in corresponding README.md.
2 parents 4f19015 + a17a64a commit 107d5a8

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

src/analyses/README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,65 @@ To be documented.
9292

9393
\subsection analyses-dependence-graph Data- and control-dependence analysis (dependence_grapht)
9494

95-
To be documented.
95+
### Dependence graph
96+
97+
Implemented in `src/analyses/dependence_graph.h(cpp)`. It is a graph and an
98+
abstract interpreter at the same time. The abstract interpretation nature
99+
allows a dependence graph to [build itself](#Construction)
100+
(the graph) from a given GOTO program.
101+
102+
A dependence graph extends the class `grapht` with `dep_nodet` as the type of
103+
nodes (see `src/util/graph.h` for more details about
104+
[graph representation]("../util/README.md")).
105+
The `dep_nodet` extends `graph_nodet<dep_edget>` with an iterator to a GOTO
106+
program instruction. It means that each graph node corresponds to a particular
107+
program instruction. A labelled edge `(u, v)` of a dependence graph expresses
108+
a dependency of the program instruction corresponding to node `u` on the program
109+
instruction corresponding to node `v`. The label of the edge (data of the
110+
type `dep_edget` attached to the edge) denotes the kind of dependency. It can be
111+
`control-dependency`, `data-dependency`, or both.
112+
113+
#### Control dependency
114+
115+
An instruction `j` corresponding to node `v` is control-dependent on instruction
116+
`i` corresponding to node `u` if and only if `j` post-dominates at least one
117+
but not all successors instructions of `i`.
118+
119+
An instruction `j` post-dominates an instruction `i` if and only if each
120+
execution path going through `i` eventually reaches `j`.
121+
122+
Post-dominators analysis is implemented in `src/analyses/cfg_dominators.h(cpp)`.
123+
124+
#### Data dependency
125+
126+
The instruction `j` corresponding to node `v` is data-dependent on the
127+
instruction `i` corresponding to node `u` if and only if `j` may read data from
128+
the memory location defined (i.e. written) by `i`.
129+
130+
The reaching definitions analysis is used together with the read-write ranges
131+
analysis to check whether one instruction may read data writen by another
132+
instruction. For more details see `src/analyses/reaching_definitions.h(cpp)` and
133+
`src/analyses/goto_rw.h(cpp)`.
134+
135+
#### Construction
136+
137+
The dependence graph extends the standard abstract interpreter class `ait`
138+
with post-dominators analysis and reaching definitions analysis. The domain of
139+
the abstract interpreter is defined in the class `dep_graph_domaint`.
140+
141+
For each instruction `i` an instance of `dep_graph_domaint` associated with `i`
142+
is created. The instance stores a set `control_deps` of program
143+
instructions the instruction `i` depends on via control-dependency, and a set
144+
`data_deps` of program instructions the instruction `i` depends on via
145+
data-dependency. These sets are updated (increased) during the computation,
146+
until a fix-point is reached.
147+
148+
The construction of a dependence graph is started by calling its `initialize`
149+
method and then, once a fix-point is reached by the abstract interpreter, the
150+
method `finalize` converts data in the interpreter's domain (i.e. from
151+
`dep_graph_domaint` instances) into edges of the graph. Nodes of the graph are
152+
created during the run of the abstract interpreter; they are linked to the
153+
corresponding program instructions.
96154

97155
\subsection analyses-dirtyt Address-taken lvalue analysis (dirtyt)
98156

src/util/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,48 @@ _not_ be extended - but it may be helpful to be aware of where this happens.
383383
These are in the process of being removed - no new output should go
384384
via `std::cout` or `std::cerr`, but should instead use the
385385
\ref messaget and \ref message_handlert infrastructure.
386+
387+
388+
\subsection Graph
389+
### Graph
390+
391+
Implemented in `src/util/graph.h` as `grapht` class. The `grapht` class
392+
represents a directed graph. However, an undirected graph can be emulated by
393+
inserting for each edge (u, v) also (v, u). A multi-graph is not supported
394+
though, because parallel edges are not allowed between vertices.
395+
396+
#### Data representation
397+
398+
A graph is defined by a template class `grapht<N>`, where `N` is the type of the
399+
nodes of the graph. The class `grapht` stores the nodes in a vector. A user of
400+
the graph is supposed to access the nodes via their indices in the vector. The
401+
node type `N` must meet these requirements:
402+
- It must be default constructible; the common way how to insert a node to the
403+
graph is to call method `add_node` which pushes a new default-constructed
404+
instance of `N` to the end of the vector and returns its index.
405+
Then `operator[]` can be used to obtain a reference to the pushed instance and
406+
set its content as desired.
407+
- It must define a type `edget`, representing type of data attached to any edge
408+
of the graph; in case edges should not have any data attached, then one can
409+
use a predefined class `empty_edget`. The type must be default-constructible.
410+
- It must define a type `edgets` as an associative container compatible with the
411+
type `std::map<std::size_t, edget>`.
412+
- It must define publicly accessible members of the type `edgest`, named `in`
413+
and `out`. The members represent edges in the graph. Namely, if `u` is an
414+
index of some node in the graph and `v` is a key in the map `in` (resp. `out`)
415+
of that node, then `(v, u)` (resp. `(u, v)`) represent an edge in the graph,
416+
with attached data `in[v]` (resp. `out[v]`).
417+
- It must define methods `add_in`, `erase_in`, and `add_out`, `erase_out` for
418+
insertion and removal of values to and from the maps `in` and `out`.
419+
- It must define a method `pretty` converting the node to a "pretty" string.
420+
421+
One can use a predefined template class `graph_nodet<E>` as the template
422+
parameter `N` of the graph. The template parameter `E` allows to define the type
423+
`edget`.
424+
425+
#### Graph algorithms
426+
427+
The graph implementation comes with several graph algorithms. We describe each
428+
of them in following paragraphs.
429+
430+
TODO!

0 commit comments

Comments
 (0)