Otawa  0.10
MUSTProblem.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * This file describes the "MUST" cache problem.
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2007, 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 CACHE_MUSTPROBLEM_H_
25 #define CACHE_MUSTPROBLEM_H_
26 
27 #include <otawa/util/HalfAbsInt.h>
28 #include <elm/assert.h>
29 #include <elm/io.h>
30 #include <otawa/prog/WorkSpace.h>
31 #include <otawa/cache/LBlockSet.h>
32 #include <otawa/hard/Cache.h>
33 #include <otawa/cfg/BasicBlock.h>
34 
35 
36 namespace otawa {
37 
38 
39 class MUSTProblem {
40 
41  // Types
42  public:
43 
44  class Domain {
45  int A, size;
46 
47  public:
55  inline Domain(const int _size, const int _A)
56  : A (_A), size(_size)
57  {
58  age = new int [size];
59  for (int i = 0; i < size; i++)
60  age[i] = 0;
61  }
62 
63  inline ~Domain() {
64  delete [] age;
65  }
66 
67  inline Domain(const Domain &source) : A(source.A), size(source.size) {
68  age = new int [size];
69  for (int i = 0; i < size; i++)
70  age[i] = source.age[i];
71 
72  }
73 
74  inline Domain& operator=(const Domain &src) {
75  ASSERT((A == src.A) && (size == src.size));
76  for (int i = 0; i < size ; i++)
77  age[i] = src.age[i];
78  return(*this);
79 
80  }
81 
82  inline void glb(const Domain &dom) {
83  ASSERT((A == dom.A) && (size == dom.size));
84 
85  for (int i = 0; i < size; i++) {
86  if (((age[i] > dom.age[i]) && (dom.age[i] != -1)) || (age[i] == -1))
87  age[i] = dom.age[i];
88  }
89  }
90 
91  inline void lub(const Domain &dom) {
92  ASSERT((A == dom.A) && (size == dom.size));
93 
94  for (int i = 0; i < size; i++) {
95  if (((age[i] < dom.age[i]) && (age[i] != -1))|| (dom.age[i] == -1))
96  age[i] = dom.age[i];
97  }
98  }
99 
100  inline int getSize(void) {
101  return size;
102  }
103 
104  inline void addDamage(const int id, const int damage) {
105  ASSERT((id >= 0) && (id < size));
106  if (age[id] == -1)
107  return;
108  age[id] += damage;
109  if (age[id] >= A)
110  age[id] = -1;
111  }
112 
113  inline bool equals(const Domain &dom) const {
114  ASSERT((A == dom.A) && (size == dom.size));
115  for (int i = 0; i < size; i++)
116  if (age[i] != dom.age[i])
117  return false;
118  return true;
119  }
120 
121  inline void empty() {
122  for (int i = 0; i < size; i++)
123  age[i] = -1;
124 
125  }
126 
127  inline bool contains(const int id) {
128  ASSERT((id < size) && (id >= 0));
129  return(age[id] != -1);
130  }
131 
132 
133  inline void inject(const int id) {
134  if (contains(id)) {
135  for (int i = 0; i < size; i++) {
136  if ((age[i] < age[id]) && (age[i] != -1))
137  age[i]++;
138  }
139  age[id] = 0;
140  } else {
141  for (int i = 0; i < size; i++) {
142  if (age[i] != -1)
143  age[i]++;
144  if (age[i] == A)
145  age[i] = -1;
146  }
147  }
148  age[id] = 0;
149  }
150 
151  inline void print(elm::io::Output &output) const {
152  bool first = true;
153  output << "[";
154  for (int i = 0; i < size; i++) {
155  if (age[i] != -1) {
156  if (!first) {
157  output << ", ";
158  }
159  // output << i << ":" << age[i];
160  output << i;
161  output << ":";
162  output << age[i];
163 
164  first = false;
165  }
166  }
167  output << "]";
168 
169  }
170 
171  inline int getAge(int id) const {
172  ASSERT(id < size);
173  return(age[id]);
174  }
175 
176  inline void setAge(const int id, const int _age) {
177  ASSERT(id < size);
178  ASSERT((_age < A) || (_age == -1));
179  age[id] = _age;
180  }
181 
182 
183  /*
184  * For each cache block belonging to the set:
185  * age[block] represents its age, from 0 (newest) to A-1 (oldest).
186  * The value -1 means that the block is not in the set.
187  */
188  int *age;
189  };
190 
191  private:
192 
193  // Fields
196  const int line;
200 
201  public:
203 
204  // Public fields
205 
206  // Constructors
207  MUSTProblem(const int _size, LBlockSet *_lbset, WorkSpace *_fw, const hard::Cache *_cache, const int _A);
208 
209  // Destructors
210  ~MUSTProblem();
211 
212  // Problem methods
213  const Domain& bottom(void) const;
214  const Domain& entry(void) const;
215 
216 
217 
218  inline void lub(Domain &a, const Domain &b) const {
219  a.lub(b);
220  }
221  inline void assign(Domain &a, const Domain &b) const {
222  a = b;
223  }
224  inline bool equals(const Domain &a, const Domain &b) const {
225  return (a.equals(b));
226  }
227 
228 
229  void update(Domain& out, const Domain& in, BasicBlock* bb);
230  inline void enterContext(Domain &dom, BasicBlock *header, hai_context_t ctx) {
231 
232  }
233 
234  inline void leaveContext(Domain &dom, BasicBlock *header, hai_context_t ctx) {
235 
236  }
237 
238 };
239 
240 elm::io::Output& operator<<(elm::io::Output& output, const MUSTProblem::Domain& dom);
241 
242 }
243 
244 #endif /*CACHE_MUSTPROBLEM_H_*/
Domain ent
Definition: MUSTProblem.h:199
int * age
Definition: MUSTProblem.h:188
dtd::RefAttr< BasicBlock * > source("source", dtd::STRICT|dtd::REQUIRED)
const Domain & entry(void) const
Definition: cache_MUSTProblem.cpp:55
Domain(const Domain &source)
Definition: MUSTProblem.h:67
WorkSpace * fw
Definition: MUSTProblem.h:195
void lub(Domain &a, const Domain &b) const
Definition: MUSTProblem.h:218
void leaveContext(Domain &dom, BasicBlock *header, hai_context_t ctx)
Definition: MUSTProblem.h:234
int getAge(int id) const
Definition: MUSTProblem.h:171
sys::SystemInStream & in
dtd::Element bb(dtd::make("bb", _BB).attr(id).attr(address).attr(size))
elm::io::Output & operator<<(elm::io::Output &out, Address addr)
Definition: base.cpp:188
void update(Domain &out, const Domain &in, BasicBlock *bb)
Definition: cache_MUSTProblem.cpp:59
uint32 size
Domain & operator=(const Domain &src)
Definition: MUSTProblem.h:74
void inject(const int id)
Definition: MUSTProblem.h:133
void assign(Domain &a, const Domain &b) const
Definition: MUSTProblem.h:221
LBlockSet * lbset
Definition: MUSTProblem.h:194
const int line
Definition: MUSTProblem.h:196
void lub(const Domain &dom)
Definition: MUSTProblem.h:91
const hard::Cache * cache
Definition: MUSTProblem.h:197
MUSTProblem(const int _size, LBlockSet *_lbset, WorkSpace *_fw, const hard::Cache *_cache, const int _A)
Definition: cache_MUSTProblem.cpp:37
void setAge(const int id, const int _age)
Definition: MUSTProblem.h:176
Domain(const int _size, const int _A)
Definition: MUSTProblem.h:55
int A
Definition: MUSTProblem.h:45
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
void empty()
Definition: MUSTProblem.h:121
This class contains the configuration of a level of cache of processor.
Definition: Cache.h:34
~MUSTProblem()
Definition: cache_MUSTProblem.cpp:49
bool contains(const int id)
Definition: MUSTProblem.h:127
void print(elm::io::Output &output) const
Definition: MUSTProblem.h:151
int getSize(void)
Definition: MUSTProblem.h:100
Definition: MUSTProblem.h:39
sys::SystemOutStream & out
This class represents the list of l-blocks of a task for a chosen cache row.
Definition: LBlockSet.h:38
bool equals(const Domain &a, const Domain &b) const
Definition: MUSTProblem.h:224
const Domain & bottom(void) const
Definition: cache_MUSTProblem.cpp:52
~Domain()
Definition: MUSTProblem.h:63
hai_context_t
Definition: HalfAbsInt.h:50
bool equals(const Domain &dom) const
Definition: MUSTProblem.h:113
void enterContext(Domain &dom, BasicBlock *header, hai_context_t ctx)
Definition: MUSTProblem.h:230
This is the minimal definition of a basic block.
Definition: BasicBlock.h:43
Domain bot
Definition: MUSTProblem.h:198
Domain callstate
Definition: MUSTProblem.h:202
int size
Definition: MUSTProblem.h:45
void addDamage(const int id, const int damage)
Definition: MUSTProblem.h:104
void glb(const Domain &dom)
Definition: MUSTProblem.h:82
Definition: MUSTProblem.h:44