22 #ifndef OTAWA_DFA_AI_H_
23 #define OTAWA_DFA_AI_H_
25 #include <elm/genstruct/Vector.h>
26 #include <elm/util/Pair.h>
27 #include <elm/util/BitVector.h>
28 #include <elm/PreIterator.h>
31 namespace otawa {
namespace ai {
34 using namespace elm::genstruct;
42 template <
class D,
class G,
class S>
54 : _dom(dom), _graph(graph), _store(store), wl_set(graph.count()),
end(false) {
55 store.set(_graph.entry(), dom.init());
56 for(
typename G::Successor succ(graph, _graph.entry()); succ; succ++)
57 push(graph.sinkOf(*succ));
73 while(!wl_vertices.isEmpty()) {
75 if(cur != _graph.exit())
85 inline typename G::vertex_t
item(
void) {
94 for(
typename G::Successor succ(_graph, cur); succ; succ++)
111 push(_graph.sinkOf(edge));
117 inline void change(
typename G::edge_t
edge,
typename D::t s) {
130 todo.
push(_graph.entry());
133 for(
typename G::Successor s(_graph, v); s; s++)
134 if(!contains(_graph.sinkOf(s))) {
135 push(_graph.sinkOf(s));
136 todo.
push(_graph.sinkOf(s));
141 for(
int i = 0, j = wl_vertices.length() - 1; i < j; i++, j--) {
143 wl_vertices[i] = wl_vertices[j];
144 wl_vertices[j] = tmp;
154 inline void check(
typename G::edge_t
edge,
typename D::t s) {
155 typename D::t ps = _store.get(edge);
156 if(!_dom.equals(s, ps))
173 typename D::t s = _dom.bot();
174 for(
typename G::Predecessor pred(_graph, vertex); pred; pred++) {
175 s = _dom.join(s, _store.get(*pred));
182 inline void push(
typename G::vertex_t v) {
183 if(!wl_set.bit(_graph.index(v))) {
185 wl_set.set(_graph.index(v));
189 inline typename G::vertex_t
pop(
void) {
190 typename G::vertex_t v = wl_vertices.pop();
191 wl_set.clear(_graph.index(v));
196 return wl_set.bit(_graph.index(v));
245 inline int count(
void)
const {
return _cfg->countBB(); }
257 template <
class D,
class G>
260 typedef typename D::t
t;
264 ArrayStore(D& dom, G& graph): _dom(dom), _graph(graph), map(new typename D::
t[_graph.count()]) {
265 for(
int i = 0; i < graph.count(); i++)
272 int i = _graph.index(_graph.sourceOf(e));
273 map[i] = _dom.join(map[i], s);
276 inline t get(
vertex_t v)
const {
return map[_graph.index(v)]; }
278 inline t get(
edge_t e)
const {
return map[_graph.index(_graph.sourceOf(e))]; }
290 template <
class D,
class G>
293 typedef typename D::t
t;
298 for(
typename G::Successor e(_graph, _graph.entry()); e; e++)
299 map.put(*e, _dom.init());
303 for(
typename G::Successor e(_graph, v); e; e++)
311 for(
typename G::Successor e(_graph, v); e; e++)
312 s = _dom.join(s, map.get(e, _dom.bot()));
316 inline t get(
edge_t e) {
return map.get(e, _dom.bot()); }
HashTable< edge_t, t > map
Definition: ai.h:321
D & _dom
Definition: ai.h:319
dtd::Element edge(dtd::make("edge", _EDGE).attr(source).attr(target).attr(called))
void change(typename G::edge_t edge, typename D::t s)
Change the output value of the current vertex for the given edge.
Definition: ai.h:117
BasicBlock * source(void) const
Definition: Edge.h:52
D::t input(void)
Compute the input state.
Definition: ai.h:163
G & _graph
Definition: ai.h:282
ArrayStore(D &dom, G &graph)
Definition: ai.h:264
Iterator(const CFGGraph &g)
Definition: ai.h:239
G::vertex_t vertex_t
Definition: ai.h:45
const int end
Definition: Registration.h:42
Edge * edge_t
Definition: ai.h:218
S & _store
Definition: ai.h:201
Predecessor(const Predecessor &p)
Definition: ai.h:228
G::vertex_t cur
Definition: ai.h:204
D::t t
Definition: ai.h:260
G::vertex_t vertex_t
Definition: ai.h:294
G::edge_t edge_t
Definition: ai.h:295
G::vertex_t item(void)
Get the current vertex.
Definition: ai.h:85
BiDiGraph implementation for CFG.
Definition: ai.h:212
D::t input(vertex_t vertex)
Compute the input state for the given vertex.
Definition: ai.h:172
Successor(const CFGGraph &graph, vertex_t v)
Definition: ai.h:233
D::t t
Definition: ai.h:293
Vector< typename G::vertex_t > wl_vertices
Definition: ai.h:202
Control Flow Graph representation.
Definition: CFG.h:42
bool end
Definition: ai.h:205
Predecessor(const CFGGraph &graph, vertex_t v)
Definition: ai.h:227
CFGGraph(CFG *cfg)
Definition: ai.h:214
vertex_t sourceOf(edge_t e) const
Definition: ai.h:223
Driver of abstract interpretation with a simple to-do list.
Definition: ai.h:43
void set(vertex_t v, t s)
Definition: ai.h:302
Successor(const Successor &p)
Definition: ai.h:234
CFG * _cfg
Definition: ai.h:248
void set(edge_t e, t s)
Definition: ai.h:271
BasicBlock * vertex_t
Definition: ai.h:217
G & _graph
Definition: ai.h:320
G::vertex_t vertex_t
Definition: ai.h:261
void changeAll(void)
Consider that all has been changed causing a re-computation of all.
Definition: ai.h:125
Definition: BasicBlock.h:165
int number(void) const
Get the number hooked on this basic block, that is, value of ID_Index property.
Definition: BasicBlock.h:146
vertex_t exit(void) const
Definition: ai.h:221
int index(vertex_t v) const
Definition: ai.h:244
Definition: BasicBlock.h:160
void set(edge_t e, t s)
Definition: ai.h:307
vertex_t sinkOf(edge_t e) const
Definition: ai.h:222
This class represents edges in the CFG representation.
Definition: Edge.h:33
dtd::Element cfg(dtd::make("cfg", _CFG).attr(id).content((entry,*bb, exit,*edge)))
void push(typename G::vertex_t v)
Definition: ai.h:182
void push(const T &value)
BasicBlock * target(void) const
Definition: Edge.h:53
BitVector wl_set
Definition: ai.h:203
State storage on the edges.
Definition: ai.h:291
void set(vertex_t v, t s)
Definition: ai.h:269
int count(void) const
Definition: ai.h:245
This is the minimal definition of a basic block.
Definition: BasicBlock.h:43
bool contains(vertex_t v)
Definition: ai.h:195
bool ended(void)
Test if the traversal is ended.
Definition: ai.h:65
void change(void)
Called when the output state of the current vertex is changed (and successors must be updated)...
Definition: ai.h:93
WorkListDriver(D &dom, const G &graph, S &store)
Initialize the driver.
Definition: ai.h:53
G::vertex_t pop(void)
Definition: ai.h:189
G::edge_t edge_t
Definition: ai.h:262
Iterator(const Iterator &i)
Definition: ai.h:240
void change(typename D::t s)
Set the new output state of the current vertex.
Definition: ai.h:101
void check(typename G::edge_t edge, typename D::t s)
If there is a state change for the given edge.
Definition: ai.h:154
D::t * map
Definition: ai.h:283
D & _dom
Definition: ai.h:281
void change(typename G::edge_t edge)
Called when the output state of the current vertex for the given edge is changed (and successors must...
Definition: ai.h:110
D & _dom
Definition: ai.h:199
Stockage of output values as an array.
Definition: ai.h:258
vertex_t entry(void) const
Definition: ai.h:220
EdgeStore(D &dom, G &graph)
Definition: ai.h:297
void next(void)
Go to the next vertex to process.
Definition: ai.h:72
const G & _graph
Definition: ai.h:200
inst store(int d, int a, int t)
Definition: inst.h:155