21 #ifndef OTAWA_DFA_FASTSTATE_H_
22 #define OTAWA_DFA_FASTSTATE_H_
24 #include <elm/types.h>
25 #include <elm/util/array.h>
26 #include <elm/alloc/StackAllocator.h>
30 namespace otawa {
namespace dfa {
60 rblock_mask = (1 << rblock_shift) - 1,
61 rblock_size = 1 << rblock_shift;
74 nrblock((state->process().platform()->regCount() + rblock_mask) >> rblock_shift),
90 inline void setMultiMax(
int new_multi_max) { multi_max = new_multi_max; }
99 ASSERTP(r < nrblock * rblock_size,
"register index out of bound");
100 return s->regs[r >> rblock_shift][r & rblock_mask];
111 ASSERTP(r < nrblock * rblock_size,
"register index out of bound");
113 typename D::t *rblock = allocator.allocate<
typename D::t>(rblock_size);
115 rblock[r & rblock_mask] = v;
116 typename D::t **regs = allocator.allocate<
value_t *>(nrblock);
118 regs[r >> rblock_shift] = rblock;
136 for(cur = s->
mem; cur && cur->
a < a; cur = cur->
n) {
137 *pn =
new(allocator)
node_t(cur);
154 *pn =
new(allocator)
node_t(a, v, next);
191 node_t *mem = 0, *cur = 0;
195 if((b - a) / off > multi_max || v == D::top) {
196 for(cur = s->
mem; cur && cur->
a < b; cur = cur->n)
199 a += (cur->a - a + off - 1) / off * off;
200 *pn =
new(allocator)
node_t(cur);
207 for(cur = s->
mem; cur && cur->
a < b; cur = cur->n)
209 value_t v = dom->join(cur->v, v);
212 *pn =
new(allocator)
node_t(cur->a, v);
217 a += (cur->a - a + off - 1) / off * off;
219 *pn =
new(allocator)
node_t(cur);
252 if((b - a) / off > multi_max)
257 for(
node_t *cur = s->
mem; cur && cur->
a < b; cur = cur->n)
259 r = dom->join(r, cur->v);
263 a += (cur->a - a + off - 1) / off * off;
275 else if(s1 == top || s2 == top)
287 regs = allocator.allocate<
value_t *>(nrblock);
288 for(
int i = 0; i < nrblock; i++) {
290 regs[i] = s1->
regs[i];
292 regs[i] = allocator.allocate<
value_t>(rblock_size);
293 for(
int j = 0; j < rblock_size; j++)
294 regs[i][j] = dom->join(s1->
regs[i][j], s2->
regs[i][j]);
302 while(cur1 != cur2 && cur1 && cur2) {
303 if(cur1->a == cur2->a) {
304 *pn =
new(allocator)
node_t(cur1->a, dom->join(cur1->v, cur2->v));
310 else if(cur1->a < cur2->a)
321 return new(allocator)
state_t(regs, mem);
340 template <
class W>
t map(
t s, W& w) {
345 for(
int i = 0; i < nrblock; i++) {
348 bool changed =
false;
349 for(
int j = 0; j < rblock_size; j++) {
350 rblock[j] = w.process(s->
regs[i][j]);
351 changed |= !dom->equals(rblock[j], s->
regs[i][j]);
357 regs = allocator.allocate<
value_t *>(nrblock);
361 regs[i] = allocator.allocate<
value_t>(rblock_size);
365 regs[i] = s->
regs[i];
372 node_t *cur = s->
mem, **pn = &mem, *last;
373 for(cur = s->
mem, last = s->
mem; cur; cur = cur->
n) {
375 if(!dom->equals(cur->
v, v)) {
378 for(
node_t *p = last; p != cur; p = p ->
n) {
379 *pn =
new(allocator)
node_t(p);
384 *pn =
new(allocator)
node_t(cur->
a, v);
391 if(mem == s->
mem && regs == s->
regs)
394 return new(allocator)
state_t(regs, mem);
409 for(
int i = 0; i < nrblock; i++)
411 for(
int j = 0; j < rblock_size; j++)
412 if(!dom->equals(s1->
regs[i][j], s2->
regs[i][j]))
419 for(c1 = s1->
mem, c2 = s2->
mem; c1 && c2; c1 = c1->
n, c2 = c2->
n) {
422 if(c1->
a != c2->
a || !dom->equals(c1->
v, c2->
v))
438 for(
int i = 0; i < nrblock; i++)
439 for(
int j = 0; j < rblock_size; j++)
440 if(!dom->equals(s->
regs[i][j], dom->bot)) {
445 out <<
"r" << ((i * rblock_size) + j) <<
" = ";
446 dom->dump(out, s->
regs[i][j]);
449 out <<
"no register set";
461 dom->dump(out, n->v);
464 out <<
"no memory set";
492 else if(s1 == top || s2 == top)
504 regs = allocator.allocate<
value_t *>(nrblock);
505 for(
int i = 0; i < nrblock; i++) {
507 regs[i] = s1->
regs[i];
509 regs[i] = allocator.allocate<
value_t>(rblock_size);
510 for(
int j = 0; j < rblock_size; j++)
511 regs[i][j] = w.process(s1->
regs[i][j], s2->
regs[i][j]);
519 while(cur1 != cur2 && cur1 && cur2) {
522 if(cur1->a == cur2->a) {
523 *pn =
new(allocator)
node_t(cur1->a, w.process(cur1->v, cur2->v));
531 else if(cur1->a < cur2->a)
543 return new(allocator)
state_t(regs, mem);
555 for(
int i = 0; i < nrblock; i++) {
556 regs[i] = allocator.allocate<
value_t>(rblock_size);
557 for(
int j = 0; j < rblock_size; j++)
558 regs[i][j] = dom->bot;
560 return new(allocator)
state_t(regs, 0);
void copy(T *target, const T *source, int size)
t set(t s, register_t r, value_t v)
Set a register value.
Definition: FastState.h:110
elm::t::size nrblock
Definition: FastState.h:564
void print(io::Output &out, t s)
Display the state.
Definition: FastState.h:433
value_t v
Definition: FastState.h:46
t::uint32 address_t
Definition: FastState.h:37
FastState(D *d, dfa::State *state, StackAllocator &alloc)
Build a state.
Definition: FastState.h:72
Fast implementation of abstract domain on the functional state of a microprocessor including the regi...
Definition: FastState.h:35
Definition: FastState.h:42
bool equals(t s1, t s2)
Test if both states are equal.
Definition: FastState.h:403
t::uint32 register_t
Definition: FastState.h:38
state_t * t
Definition: FastState.h:64
value_t ** regs
Definition: FastState.h:53
t combine(t s1, t s2, W &w)
Apply a function to combine two states.
Definition: FastState.h:487
D * dom
Definition: FastState.h:563
node_t(address_t _a, value_t _v, node_t *_n=0)
Definition: FastState.h:43
t store(t s, address_t a, value_t v)
Perform a store to memory.
Definition: FastState.h:131
node_t * mem
Definition: FastState.h:54
int getMultiMax(void) const
Get the max number of multiple load/store before jumping to top.
Definition: FastState.h:84
node_t(node_t *node)
Definition: FastState.h:44
t make(bool bot)
Make a basic state.
Definition: FastState.h:553
t join(t s1, t s2)
Perform join of both states.
Definition: FastState.h:270
D::t value_t
Definition: FastState.h:39
t::uint32 size
Definition: base.h:46
node_t * n
Definition: FastState.h:47
value_t load(t s, address_t a, address_t b, ot::size off)
Load multiple values from a memory area.
Definition: FastState.h:247
The representation of an address in OTAWA.
Definition: base.h:54
address_t a
Definition: FastState.h:45
Represents a value of the data state.
Definition: State.h:86
Property * make(const Identifier< T > &id, const T &v)
Definition: info.h:31
sys::SystemOutStream & out
t storeAtTop(t s)
Store to T address (set all memory to T).
Definition: FastState.h:235
dfa::State * istate
Definition: FastState.h:567
void setMultiMax(int new_multi_max)
Set the maximum number of multiple load/store before approximating to top.
Definition: FastState.h:90
Definition: FastState.h:51
t store(t s, address_t a, address_t b, ot::size off, value_t v)
Perform a multiple-store (joining on all memories that are modified).
Definition: FastState.h:184
StackAllocator & allocator
Definition: FastState.h:565
int multi_max
Definition: FastState.h:566
state_t(value_t **r, node_t *m)
Definition: FastState.h:52
t top
Definition: FastState.h:569
value_t load(t s, address_t a)
Perform a load at the given address.
Definition: FastState.h:166
t map(t s, W &w)
Apply a function to transform a state.
Definition: FastState.h:340