Otawa  0.10
features.h
Go to the documentation of this file.
1 /*
2  * otawa::dcache module features
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2013, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef OTAWA_DCACHE_FEATURES_H_
22 #define OTAWA_DCACHE_FEATURES_H_
23 
25 #include <otawa/cache/categories.h>
26 #include <otawa/prop/PropList.h>
27 #include <otawa/dfa/BitSet.h>
28 #include <otawa/hard/Cache.h>
29 
30 namespace otawa {
31 
32 namespace ilp { class Var; }
33 class Inst;
34 
35 namespace dcache {
36 
37 // type of unrolling
38 typedef enum data_fmlevel_t {
44 
45 
46 // ACS class
47 class ACS {
48 public:
49  inline ACS(const int _size, const int _A, int init = -1) : A (_A), size(_size), age(new int [size])
50  { for (int i = 0; i < size; i++) age[i] = init; }
51  inline ~ACS() { delete [] age; }
52 
53  inline int getSize(void) const { return size; }
54  inline int getA(void) const { return A; }
55 
56  inline ACS(const ACS &source) : A(source.A), size(source.size), age(new int [size])
57  { for (int i = 0; i < size; i++) age[i] = source.age[i]; }
58 
59  inline ACS& operator=(const ACS& src) { set(src); return *this; }
60 
61  inline bool equals(const ACS& dom) const {
62  ASSERT((A == dom.A) && (size == dom.size));
63  for (int i = 0; i < size; i++) if (age[i] != dom.age[i]) return false;
64  return true;
65  }
66 
67  inline void empty(void) { for (int i = 0; i < size; i++) age[i] = -1; }
68  inline bool contains(const int id) const { ASSERT((id < size) && (id >= 0)); return(age[id] != -1); }
69 
70  void print(elm::io::Output &output) const;
71 
72  inline int getAge(int id) const { ASSERT(id < size); return(age[id]); }
73  inline void setAge(const int id, const int _age)
74  { ASSERT(id < size); ASSERT((_age < A) || (_age == -1)); age[id] = _age; }
75  inline void set(const ACS& dom)
76  { ASSERT(A == dom.A); ASSERT(size == dom.size); for(int i = 0; i < size; i++) age[i] = dom.age[i]; }
77 
78  inline const int& operator[](int i) const { return age[i]; }
79  inline int& operator[](int i) { return age[i]; }
80 
81 protected:
82  int A, size;
83  int *age;
84 };
85 inline io::Output& operator<<(io::Output& out, const ACS& acs) { acs.print(out); return out; }
86 
87 
88 // Block class
89 class Block {
90 public:
91  inline Block(void): _set(-1), idx(-1) { }
92  inline Block(int set, int index, const Address& address): _set(set), idx(index), addr(address) { ASSERT(!address.isNull()); }
93  inline Block(const Block& block): _set(block._set), idx(block.idx), addr(block.addr) { }
94  inline int set(void) const { return _set; }
95  inline int index(void) const { return idx; }
96  inline const Address& address(void) const { return addr; }
97  void print(io::Output& out) const;
98 
99 private:
100  int _set;
101  int idx;
103 };
104 inline io::Output& operator<<(io::Output& out, const Block& block) { block.print(out); return out; }
105 
106 
107 // BlockCollection class
109 public:
110  ~BlockCollection(void);
111  inline const Block& operator[](int i) const { return *blocks[i]; }
112  const Block& obtain(const Address& addr);
113  inline void setSet(int set) { _set = set; }
114 
115  inline int count(void) const { return blocks.count(); }
116  inline int cacheSet(void) const { return _set; }
117 
118 private:
119  int _set;
121 };
122 
123 
124 // Data
125 class BlockAccess: public PropList {
126 public:
127  typedef enum action_t {
128  NONE = 0,
129  LOAD = 1,
130  STORE = 2,
131  PURGE = 3
132  } action_t;
133  typedef enum kind_t {
134  ANY = 0,
135  BLOCK = 1,
136  RANGE = 2
137  } kind_t;
138 
139  inline BlockAccess(void): inst(0), _kind(ANY), _action(NONE) { }
140  inline BlockAccess(Inst *instruction, action_t action): inst(instruction), _kind(ANY), _action(action) { ASSERT(instruction); }
141  inline BlockAccess(Inst *instruction, action_t action, const Block& block): inst(instruction), _kind(BLOCK), _action(action)
142  { ASSERT(instruction); data.blk = &block; }
144  { ASSERT(instruction); data.range.first = first; data.range.last = last; }
145  inline BlockAccess(const BlockAccess& acc): inst(acc.inst), _kind(acc._kind), _action(acc._action)
146  { data = acc.data; }
147  inline BlockAccess& operator=(const BlockAccess& acc)
148  { inst = acc.inst; _kind = acc._kind; _action = acc._action; data = acc.data; return *this; }
149 
150  inline Inst *instruction(void) const { return inst; }
151  inline kind_t kind(void) const { return kind_t(_kind); }
152  inline bool isAny(void) const { return _kind == ANY; }
153  inline action_t action(void) const { return action_t(_action); }
154  inline const Block& block(void) const { ASSERT(_kind == BLOCK); return *data.blk; }
155  inline int first(void) const { ASSERT(_kind == RANGE); return data.range.first; }
156  inline int last(void) const { ASSERT(_kind == RANGE); return data.range.last; }
157  inline bool inRange(int block) const { if(first() < last()) return first() <= block && block <= last(); else return block <= first() || last() <= block; }
158  bool inSet(int set, const hard::Cache *cache) const;
159  bool in(const Block& block) const;
160 
161  void print(io::Output& out) const;
162 
163 private:
166  union {
167  const Block *blk;
169  } data;
170 };
171 inline io::Output& operator<<(io::Output& out, const BlockAccess& acc) { acc.print(out); return out; }
172 inline io::Output& operator<<(io::Output& out, const Pair<int, BlockAccess *>& v) { return out; }
174 
175 // DirtyManager class
177 public:
178 
179  typedef struct t {
180  friend class DirtyManager;
181  public:
182  inline t(void) { }
183  inline t(int s): _may(s), _must(s) { }
184  inline t(const t& i): _may(i._may), _must(i._must) { }
185  inline const dfa::BitSet& may(void) const { return _may; }
186  inline const dfa::BitSet& must(void) const { return _must; }
187  void print(io::Output& out) const;
188  inline bool mayBeDirty(int b) const { return _may.contains(b); }
189  inline bool mustBeDirty(int b) const { return _must.contains(b); }
190  private:
191  inline dfa::BitSet& may(void) { return _may; }
192  inline dfa::BitSet& must(void) { return _must; }
194  } t;
195 
196  DirtyManager(const BlockCollection& coll);
197  bool mayBeDirty(const t& value, int block) const;
198  bool mustBeDirty(const t& value, int block) const;
199  const t& bottom(void) const;
200  const t& top(void) const;
201  void set(t& d, const t& s) const;
202  void update(t& d, const BlockAccess& acc);
203  void join(t& d, const t& s) const;
204  bool equals(const t& s1, const t& s2) const;
205 
206 private:
209 };
210 inline io::Output& operator<<(io::Output& out, const DirtyManager::t& v) { v.print(out); return out; }
211 
212 // useful typedefs
216 
217 
218 // block analysis
224 
225 // MUST analysis
235 
236 // categories build
240 
241 // ILP constraint build
244 
245 // MAY analysis
249 
250 // Dirty analysis
253 
254 // Purge analysis
255 typedef enum {
257  NO_PURGE = 1,
261 } purge_t;
265 
266 // WCET builder
268 
269 } } // otawa::dcache
270 
271 #endif /* OTAWA_DCACHE_FEATURES_H_ */
int A
Definition: features.h:82
Identifier< ilp::Var * > MISS_VAR
This property gives the variable counting the number of misses of a BlockAccess.
dtd::RefAttr< BasicBlock * > source("source", dtd::STRICT|dtd::REQUIRED)
p::feature CONSTRAINTS_FEATURE
This feature ensures that the constraints associated with each data cache block categories has been t...
A block access represents a data memory access of an instruction.
Definition: features.h:125
hard::Cache::block_t last
Only for the RANGE kind, get the last accessed block.
Definition: features.h:168
int _set
Definition: features.h:100
bool equals(const ACS &dom) const
Test if two ACS are equals.
Definition: features.h:61
struct otawa::dcache::DirtyManager::t t
State for the dirty analysis.
BlockAccess(Inst *instruction, action_t action)
Build a block access of type ANY.
Definition: features.h:140
Definition: features.h:39
struct otawa::dcache::BlockAccess::@0::@1 range
dfa::BitSet _must
Definition: features.h:193
Identifier< Vector< ACS * > * > ENTRY_MAY_ACS
Configuration property giving the ACS at the startup of the task.
Definition: features.h:131
Block(int set, int index, const Address &address)
Build a simple block.
Definition: features.h:92
Identifier< cache::category_t > CATEGORY
Gives the category for a data cache block access.
union otawa::dcache::BlockAccess::@0 data
Identifier< Pair< int, BlockAccess * > > DATA_BLOCKS
Give the list of accesses to the data cache.
genstruct::Vector< ACS * > acs_table_t
Definition: features.h:214
Identifier< Address > INITIAL_SP
Provide the address of the stack pointer at the start of the task.
p::feature DATA_BLOCK_FEATURE
This feature ensures that information about the data cache accesses has been provided on each basic b...
int last(void) const
Definition: features.h:156
Identifier< data_fmlevel_t > DATA_FIRSTMISS_LEVEL
According to its value, select the way the first-miss analysis is performed: – analysis of inner lo...
void empty(void)
Set all block to age -1.
Definition: features.h:67
kind_t kind(void) const
Get the kind of the access.
Definition: features.h:151
const dfa::BitSet & may(void) const
Definition: features.h:185
elm::io::Output & operator<<(elm::io::Output &output, const MUSTProblem::Domain &dom)
Definition: dcache_ACSBuilder.cpp:155
action_t action(void) const
Get the performed action.
Definition: features.h:153
Definition: features.h:134
bool contains(const int id) const
Test if a block is in the ACS , that is, its each age is in the interval [0, A[ where A is the associ...
Definition: features.h:68
This class implements a set as a bit vector.
Definition: BitSet.h:82
Identifier< bool > DATA_PSEUDO_UNROLLING
This configuration property activates, if set to true (default), the pseudo-unrolling for the cache a...
void print(elm::io::Output &output) const
Print the ACS.
Definition: dcache_ACSBuilder.cpp:498
dfa::BitSet & must(void)
Definition: features.h:192
BlockAccess(const BlockAccess &acc)
Construction by cloning.
Definition: features.h:145
ACS(const ACS &source)
Constructor by cloning.
Definition: features.h:56
const BlockCollection & _coll
Definition: features.h:208
bool contains(int index) const
Test if the bit set contains an item.
Definition: BitSet.h:111
Inst * inst
Definition: features.h:164
Definition: features.h:258
void setAge(const int id, const int _age)
Change the age of a block.
Definition: features.h:73
int getA(void) const
Definition: features.h:54
bool mustBeDirty(int b) const
Definition: features.h:189
bool in(const Block &block) const
Test if the given block may be concerned by the current access.
Definition: dcache.cpp:60
const Block & obtain(const Address &addr)
Obtain a block matching the given address.
Definition: dcache_BlockBuilder.cpp:316
Identifier< const BlockCollection * > DATA_BLOCK_COLLECTION
Gives the list of used blocks in the data cache.
BlockAccess(void)
Build a null block access.
Definition: features.h:139
int index(void) const
Get the number of a block.
Definition: features.h:95
p::feature MAY_ACS_FEATURE
This feature that the MAY analysis has been performed for the L1 data cache and that the ACS are prov...
Identifier< BasicBlock * > CATEGORY_HEADER
When a cache access has a category of cache::FIRST_MISS, the "first" part is relative to a particular...
Definition: features.h:256
Definition: features.h:41
genstruct::Vector< acs_stack_t > acs_stack_table_t
Definition: features.h:215
uint32 size
Definition: features.h:129
t bot
Definition: features.h:207
A dirty manager allows to exploit the results of the dirty analysis (DIRTY_FEATURE).
Definition: features.h:176
Definition: features.h:259
bool inRange(int block) const
Test if the given block is the range of the given access.
Definition: features.h:157
Address addr
Definition: features.h:102
bool isNull(void) const
Test if the address is null.
Definition: base.h:72
Definition: features.h:179
const Block & operator[](int i) const
Definition: features.h:111
t(int s)
Definition: features.h:183
int & operator[](int i)
Definition: features.h:79
const t & bottom(void) const
Build a bottom dirty state.
Definition: Dirty.cpp:135
Block(const Block &block)
Cloning of a block.
Definition: features.h:93
t::uint32 offset_t
Definition: base.h:57
Definition: features.h:42
p::feature MUST_ACS_FEATURE
This feature ensures that the ACS (Abstract Cache State) for the MUST data cache analysis has been bu...
const Block * blk
Definition: features.h:167
Identifier< purge_t > PURGE
p::feature PURGE_FEATURE
void setSet(int set)
Set the set number of the block collection.
Definition: features.h:113
Identifier< acs_table_t * > ENTRY_PERS_ACS
This configuration property allows to provide an non-empty ACS for the persistence analysis...
const int & operator[](int i) const
Definition: features.h:78
p::feature CATEGORY_FEATURE
This features ensures that a category each data block access have received a category describing its ...
int getAge(int id) const
Get the age of a block.
Definition: features.h:72
int set(void) const
Get the set number of a block.
Definition: features.h:94
This class contains the configuration of a level of cache of processor.
Definition: Cache.h:34
DirtyManager(const BlockCollection &coll)
Definition: Dirty.cpp:102
const t & top(void) const
Build a top dirty state.
Definition: Dirty.cpp:143
int size
Definition: features.h:82
The representation of an address in OTAWA.
Definition: base.h:54
Definition: features.h:130
void print(io::Output &out) const
Definition: dcache_BlockBuilder.cpp:452
StringOption cache(command, 'c',"cache","used cache","path","")
const dfa::BitSet & must(void) const
Definition: features.h:186
p::feature CLP_BLOCK_FEATURE
int cacheSet(void) const
Definition: features.h:116
uint8_t uint8
bool inSet(int set, const hard::Cache *cache) const
Test if the given set concerns the range access.
Definition: dcache.cpp:37
dfa::BitSet _may
Definition: features.h:193
sys::SystemOutStream & out
BlockAccess & operator=(const BlockAccess &acc)
Definition: features.h:147
p::feature DIRTY_FEATURE
This feature is only useful for data cache with write-back mechanism.
int _set
Definition: features.h:119
bool mustBeDirty(const t &value, int block) const
Test if the given block must be dirty.
Definition: Dirty.cpp:127
ACS & operator=(const ACS &src)
Definition: features.h:59
Identifier< acs_table_t * > MUST_ACS
Provide for each basic block the ACS (Abstract Cache State) of the data cache for each set of the cac...
int idx
Definition: features.h:101
void set(t &d, const t &s) const
Copy a state in an existing one.
Definition: Dirty.cpp:153
~ACS()
Definition: features.h:51
This class represents identifier with a typed associated value.
Definition: Identifier.h:51
Definition: features.h:136
Identifier< acs_table_t * > ENTRY_MUST_ACS
This configuration property is shared by all processor implementing the MUST_ACS_FEATURE.
bool isAny(void) const
Definition: features.h:152
int * age
Definition: features.h:83
t::uint32 block_t
Definition: Cache.h:64
Definition: features.h:135
kind_t
Definition: features.h:133
int getSize(void) const
Get the number of blocks of the ACS.
Definition: features.h:53
This class represents assembly instruction of a piece of code.
Definition: Inst.h:62
Identifier< Vector< ACS * > * > MAY_ACS
Provide the ACS for the MAY analysis.
void update(t &d, const BlockAccess &acc)
Update the dirty state with the given block access.
Definition: Dirty.cpp:175
void print(io::Output &out) const
Definition: Dirty.cpp:268
t::uint8 _kind
Definition: features.h:165
This a list of properties.
Definition: PropList.h:63
Inst * instruction(void) const
Get the instruction performing the access.
Definition: features.h:150
t _top
Definition: features.h:207
void join(t &d, const t &s) const
Join two dirty states.
Definition: Dirty.cpp:260
bool equals(const t &s1, const t &s2) const
Test if both dirty states are equals.
Definition: Dirty.cpp:165
p::feature WCET_FUNCTION_FEATURE
This feature provides an easy and naive way to add data cache time to the WCET computation by adding ...
Identifier< acs_table_t * > PERS_ACS
This identifier gives an array of ACS for the persistence analysis.
Identifier< AllocatedTable< DirtyManager::t > > DIRTY
This property contains information about the dirty state of a block.
p::feature PERS_ACS_FEATURE
Feature ensuring that the persistence analysis has been performed.
Represents a single block used by the data cache.
Definition: features.h:89
bool mayBeDirty(const t &value, int block) const
Test if the given block may be dirty.
Definition: Dirty.cpp:117
Identifier< acs_stack_table_t * > LEVEL_PERS_ACS
This identifier allows to get an array on a stack of ACS, one entry for each set of the analyzed cach...
int count(void) const
Get the count of blocks in this collection.
Definition: features.h:115
Definition: features.h:40
const Address & address(void) const
Definition: features.h:96
void set(const ACS &dom)
Set the ages of the given ACS to the current one.
Definition: features.h:75
Representation of an Abstract Cache State where each data cache block is represented by its age...
Definition: features.h:47
dfa::BitSet & may(void)
Definition: features.h:191
ACS(const int _size, const int _A, int init=-1)
Definition: features.h:49
data_fmlevel_t
Definition: features.h:38
t::uint8 _action
Definition: features.h:165
t(const t &i)
Definition: features.h:184
~BlockCollection(void)
Definition: dcache_BlockBuilder.cpp:306
Block(void)
Build a "any" number (with a null address).
Definition: features.h:91
BlockAccess(Inst *instruction, action_t action, Address::offset_t first, Address::offset_t last)
Build a block access of type range.
Definition: features.h:143
bool mayBeDirty(int b) const
Definition: features.h:188
genstruct::Vector< Block * > blocks
Definition: features.h:120
A block collections stores the list of data blocks used in a task for a specific line.
Definition: features.h:108
const Block & block(void) const
Only for kind BLOCK, get the accessed block.
Definition: features.h:154
Shortcut to create a feature with a maker (without the mess of SilentFeature).
Definition: AbstractFeature.h:51
void print(io::Output &out) const
Print a block.
Definition: dcache_BlockBuilder.cpp:288
int first(void) const
Definition: features.h:155
genstruct::AllocatedTable< ACS * > acs_stack_t
Definition: features.h:213
Definition: features.h:128
action_t
Definition: features.h:127
BlockAccess(Inst *instruction, action_t action, const Block &block)
Definition: features.h:141
Definition: features.h:257
Definition: features.h:260
t(void)
Definition: features.h:182
purge_t
Definition: features.h:255