Skip to content

Commit dde98e0

Browse files
committed
An overview of grapht and dependence_grapht in corresponding README.md.
1 parent 4293897 commit dde98e0

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

src/analyses/README.md

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

97152
\subsection analyses-dirtyt Address-taken lvalue analysis (dirtyt)
98153

src/util/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,45 @@ _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`. A graph is always directional. However, an
392+
undirected graph can be emulated if one inserts for each edge (u, v) also
393+
(v, u). A multigraph is not supported, as parallel edges are not allowed between
394+
vertices.
395+
396+
#### Data representation
397+
398+
A graph is defined by a template class `grapht<N>`, where `N` should define
399+
a node of the graph. The class `grapht` stores the nodes in a vector. A user of
400+
the graph may access the nodes only via their indices in the vector. The node
401+
type `N` must meet these requirements:
402+
- 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+
- must define a type `edget`, representing type of data attached to any edge
406+
of the graph; if case edges should not have any data atached, then one can
407+
use a predefined class `empty_edget`. The type must be default-constructible.
408+
- must define a type `edgets` as an associative container compatible with the
409+
type `std::map<std::size_t, edget>`.
410+
- publicly accessible members of the type `edgest`, named `in` and `out`.
411+
The members represent edges in the graph. Namely, if `u` is the index of some
412+
node in the graph and `v` is a key in the map `in` (resp. `out`) of that node,
413+
then `(v, u)` (resp. `(u, v)`) represent an edge in the graph, labelled with
414+
`in[v]` (resp. `out[v]`).
415+
- methods `add_in`, `erase_in`, and `add_out`, `erase_out` for insertion and
416+
removal of values to and from the maps `in` and `out`.
417+
- a method `pretty` converting the node to a "pretty" string.
418+
419+
One can use a predefined template class `graph_nodet<E>` as the template
420+
parameter `N` of the graph.
421+
422+
#### Graph algorithms
423+
424+
The graph implementation comes with several graph algorithms. We describe each
425+
of them in following paragraphs.
426+
427+
TODO!

0 commit comments

Comments
 (0)