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