Otawa  0.10
ClpValue.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * CLP Value definition
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2011, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  */
23 
24 #ifndef OTAWA_DATA_CLP_VALUE_H_
25 #define OTAWA_DATA_CLP_VALUE_H_
26 
27 #include <elm/types.h>
28 #include <elm/type_info.h>
29 #include <elm/io.h>
30 #include <elm/assert.h>
31 
32 namespace otawa { namespace clp {
33 
34 using namespace elm;
35 
36 // Here we define the number of bits the CLP will be (here modulo 2^32)
37 const int NBITS = 32;
44 
45 
53 typedef enum {
55  REG, // only used for addresses
56  VAL,
58 } kind_t;
59 
66  class Value {
67  public:
68  static int and_threshold;
69 
70  inline bool isConst(void) const { return delta() == 0 || mtimes() == 0; }
71 
78  inline Value(kind_t kind=VAL, intn_t lower=0, intn_t delta=0,
79  uintn_t mtimes=0): _kind(kind), _lower(lower), _delta(delta),
80  _mtimes(mtimes) { check(); }
82  inline Value(const Value& val):
83  _kind(val._kind), _lower(val._lower), _delta(val._delta),
84  _mtimes(val._mtimes) { }
89  inline Value(const int val):
90  _kind(VAL), _lower(val), _delta(0), _mtimes(0) {}
91 
92  inline Value& operator=(const Value& val){
93  set(val._kind, val._lower, val._delta, val._mtimes);
94  return *this;
95  }
96 
97  inline bool isTop(void) const { return _kind == ALL; }
98 
99  inline bool operator==(const Value& val) const {
100  return (
101  (_kind == val._kind &&
102  _lower == val._lower &&
103  _delta == val._delta &&
104  _mtimes == val._mtimes)
105  /* WARNING: keep in order to verify it does not break something else
106  ||
107  ( (_delta == 1 || _delta == -1) &&
108  (val._delta == 1 || val._delta == -1) &&
109  _mtimes == UMAXn && val._mtimes == UMAXn)*/
110  );
111  }
112  inline bool operator!=(const Value& val) const {
113  return ! operator==(val);
114  }
115 
116  Value operator+(const Value& val) const;
117  Value operator-(const Value& val) const;
118  inline bool operator>=(const int val) const {
119  return _lower >= val;
120  }
121 
122  inline kind_t kind(void) const { return _kind; }
123  inline intn_t lower(void) const { return _lower; }
124  inline intn_t upper(void) const { return _lower + _delta * _mtimes; }
125  inline intn_t delta(void) const { return _delta; }
126  inline uintn_t mtimes(void) const { return _mtimes; }
127 
131  inline intn_t start(void) const {
132  if (_delta < 0)
133  return _lower + _delta * _mtimes;
134  else
135  return _lower;
136  }
137 
141  inline intn_t stop(void) const {
142  if (_delta < 0)
143  return _lower;
144  else
145  return _lower + _delta * _mtimes;
146  }
147 
152  void add(const Value& val);
157  void sub(const Value& val);
162  void print(io::Output& out) const;
168  void shl(const Value& val);
174  void shr(const Value& val);
175 
176  void _or(const Value& val);
177 
182  void join(const Value& val);
187  void widening(const Value& val);
193  void ffwidening(const Value& val, int loopBound);
198  void inter(const Value& val);
203  void reverse(void);
204 
205  inline bool swrap(void) const
206  { return _delta != 0 && _mtimes > (MAXn - _lower) / elm::abs(_delta); }
207  inline bool uwrap(void) const
208  { return _delta != 0 && _mtimes > (UMAXn - _lower) / elm::abs(_delta); }
209 
210  void ge(intn_t k);
211  void geu(uintn_t k);
212  void le(intn_t k);
213  void leu(uintn_t k);
214  void eq(uintn_t k);
215  void ne(uintn_t k);
216  void _and(const Value& val);
217 
219  static const Value none;
221  static const Value all;
222 
231  inline void set(kind_t kind, intn_t lower, intn_t delta,
232  uintn_t mtimes){
233  _kind = kind;
234  _lower = lower;
235  _delta = delta;
236  _mtimes = mtimes;
237  check();
238  }
239  private:
240  inline void check(void) { /*ASSERT((_delta == 0 && _mtimes == 0) || (_delta != 0 && _mtimes != 0));*/ }
241 
246  };
247 
249  { val.print(out); return out; }
250 
251 } // clp
252 
253 } // otawa
254 
255 #endif /* OTAWA_DATA_CLP_VALUE_H_ */
Value & operator=(const Value &val)
Definition: ClpValue.h:92
bool operator==(const CString &s1, const CString &s2)
uintn_t mtimes(void) const
Definition: ClpValue.h:126
intn_t start(void) const
Definition: ClpValue.h:131
void print(io::Output &out) const
Print a human representation of the CLP.
Definition: clp_analysis.cpp:272
const uintn_t UMAXn
Definition: ClpValue.h:41
inst shr(int d, int a, int b)
Definition: inst.h:166
op_t reverse(op_t logop)
Definition: clp_symbolic_expr.cpp:301
static const Value none
Represents the bottom element.
Definition: ClpValue.h:219
Definition: ClpValue.h:55
intn_t _delta
Definition: ClpValue.h:244
elm::t::int32 intn_t
Definition: ClpValue.h:38
static int and_threshold
Find a file of 1 in a word.
Definition: ClpValue.h:68
Definition: ClpValue.h:54
Expression operator-(const Term &t1, const Term &t2)
Definition: expr.h:96
t::uint32 abs(t::int32 v)
int32_t int32
Value(kind_t kind=VAL, intn_t lower=0, intn_t delta=0, uintn_t mtimes=0)
Constructor for a new CLP.
Definition: ClpValue.h:78
inst _and(int d, int a, int b)
Definition: inst.h:170
bool isConst(void) const
Definition: ClpValue.h:70
bool swrap(void) const
Definition: ClpValue.h:205
intn_t lower(void) const
Definition: ClpValue.h:123
const intn_t MINn
Definition: ClpValue.h:43
IntOption delta(command, 'D',"delta","use delta method with given sequence length","length", 4)
Inst::kind_t kind
Definition: odisasm.cpp:106
Value(const Value &val)
Copy constructor.
Definition: ClpValue.h:82
A set of values represented by a Circular Linear Progression.
Definition: ClpValue.h:66
kind_t
Allowed types for values: NONE represents nothing; REG is only used for addresses, and represents a register; VAL represents some values (either a constant or an interval); ALL is the Top element.
Definition: ClpValue.h:53
intn_t stop(void) const
Definition: ClpValue.h:141
static const Value all
Represents the top element.
Definition: ClpValue.h:221
Value(const int val)
Singleton constructor.
Definition: ClpValue.h:89
Definition: ClpValue.h:57
intn_t delta(void) const
Definition: ClpValue.h:125
void check(void)
Definition: ClpValue.h:240
bool operator!=(const Value &val) const
Definition: ClpValue.h:112
intn_t upper(void) const
Definition: ClpValue.h:124
sys::SystemOutStream & out
intn_t _lower
Definition: ClpValue.h:243
bool operator==(const Value &val) const
Definition: ClpValue.h:99
kind_t kind(void) const
Definition: ClpValue.h:122
void set(kind_t kind, intn_t lower, intn_t delta, uintn_t mtimes)
Set the values for the current object.
Definition: ClpValue.h:231
bool uwrap(void) const
Definition: ClpValue.h:207
Definition: ClpValue.h:56
const intn_t MAXn
Definition: ClpValue.h:42
elm::t::uint32 uintn_t
Definition: ClpValue.h:39
inst add(int d, int a, int b)
Definition: inst.h:163
inst sub(int d, int a, int b)
Definition: inst.h:164
bool isTop(void) const
Definition: ClpValue.h:97
bool operator>=(const int val) const
Definition: ClpValue.h:118
const int NBITS
Definition: ClpValue.h:37
kind_t _kind
Definition: ClpValue.h:242
elm::io::Output & operator<<(elm::io::Output &out, const otawa::clp::Value &val)
Definition: ClpValue.h:248
Expression operator+(const Term &t1, const Term &t2)
Definition: expr.h:95
inst shl(int d, int a, int b)
Definition: inst.h:165
t::uint64 STAT_UINT
Definition: ClpValue.h:40
uintn_t _mtimes
Definition: ClpValue.h:245
inst _or(int d, int a, int b)
Definition: inst.h:171
uint32_t uint32
uint64_t uint64