Otawa  0.10
ParExeProc.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * exegraph module interface
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 02110-1301 USA
21  */
22 
23 #ifndef OTAWA_PAREXEPROC_H
24 #define OTAWA_PAREXEPROC_H
25 
26 #include <elm/io.h>
27 #include <elm/genstruct/Vector.h>
28 #include <elm/string/String.h>
29 #include <elm/genstruct/DLList.h>
30 #include <stdio.h>
31 #include <otawa/otawa.h>
32 #include <otawa/hard/Processor.h>
33 
34 namespace otawa {
35 
36  using namespace elm;
37  using namespace elm::genstruct;
38 
39  class ParExeStage;
40  class ParExePipeline;
41  class ParExeProc;
42  class ParExeNode;
43 
44  namespace hard {
45  class Microprocessor;
46  } // hard
47 
48 
49 
50  // instruction_category_t instCategory(Inst *inst);
51 
52  /*
53  * class ParExeQueue
54  *
55  */
56 
57  class ParExeQueue {
58  private:
60  int _size;
63  public:
65  : _name(name), _size(size) {}
66  inline elm::String name(void)
67  {return _name;}
68  inline int size(void)
69  {return _size;}
70  inline ParExeStage * fillingStage(void)
71  {return _filling_stage;}
72  inline ParExeStage * emptyingStage(void)
73  {return _emptying_stage;}
74  inline void setFillingStage(ParExeStage * stage)
75  {_filling_stage = stage;}
76  inline void setEmptyingStage(ParExeStage * stage)
77  {_emptying_stage = stage;}
78  };
79 
80 
81  /*
82  * class ParExeStage
83  *
84  */
85 
86  class ParExeStage {
87  public:
88  typedef enum order_t {IN_ORDER, OUT_OF_ORDER} order_policy_t;
89  typedef enum pipeline_stage_category_t {FETCH, DECODE, EXECUTE, COMMIT, DELAY, FU} pipeline_stage_category_t;
90 
91  private:
94  int _latency;
95  int _width;
100  int _index;
104  public:
105  inline ParExeStage(pipeline_stage_category_t category, int latency, int width, order_t policy, ParExeQueue *sq, ParExeQueue *dq, elm::String name, int index=0, const hard::PipelineUnit *unit = 0);
106 
107  inline void addNode(ParExeNode * node)
108  { _nodes.add(node); }
109  inline void removeNode(ParExeNode *node)
110  { _nodes.remove(node); }
111 
112  inline const hard::PipelineUnit *unit(void) const { return _unit; }
113  inline order_t orderPolicy(void) {return _order_policy;}
114  inline int width(void) const {return _width;}
115  inline elm::String name(void) {return _name;}
116  inline int index(void) {return _index;}
117  inline pipeline_stage_category_t category(void) {return _category;}
118  inline ParExeQueue * sourceQueue(void) {return _source_queue;}
119  inline ParExeQueue * destinationQueue(void) {return _destination_queue;}
120  inline int latency(void) {return _latency;}
121  inline bool isFuStage(void) {return (_category == FU);}
122  inline void addFunctionalUnit(bool pipelined, int latency, int width, elm::String name, const hard::PipelineUnit *unit);
123  inline int numFus(void) {return _fus.length();}
124  inline ParExePipeline *fu(int index) {return _fus[index];}
125  inline ParExeNode* firstNode(void) {return _nodes[0];}
126  inline ParExeNode* lastNode(void) {return _nodes[_nodes.length()-1];}
127  inline bool hasNodes(void) {return (_nodes.length() != 0);}
128  inline void deleteNodes(void) {if (_nodes.length() != 0) _nodes.clear();}
129  inline int numNodes(void) {return _nodes.length();}
130  inline ParExeNode * node(int index)
131  { if (index >= _nodes.length()) return NULL; else return _nodes[index]; }
132  inline void addBinding(Inst::kind_t kind, ParExePipeline *fu) {_bindings.add(pair(kind, fu));}
133 
135  for(int i = 0; i < _bindings.length(); i++) {
136  Inst::kind_t mask = _bindings[i].fst;
137  if((kind & mask) == mask)
138  return _bindings[i].snd;
139  }
140  return 0;
141  }
142 
143  class NodeIterator: public elm::genstruct::Vector<ParExeNode *>::Iterator {
144  public:
145  inline NodeIterator(const ParExeStage *stage)
146  : elm::genstruct::Vector<ParExeNode *>::Iterator(stage->_nodes) {}
147  };
148 
149  };
150 
151 
152  /*
153  * class ParExePipeline
154  *
155  */
156 
157  class ParExePipeline {
158  protected:
160  private:
163  public:
164  ParExePipeline() : _first_stage(NULL){}
166  inline ParExeStage *lastStage() {return _last_stage;}
167  inline ParExeStage *firstStage() {return _first_stage; }
168  inline void addStage(ParExeStage *stage);
169  inline int numStages() {return _stages.length();}
170 
171  class StageIterator: public elm::genstruct::Vector<ParExeStage *>::Iterator {
172  public:
173  inline StageIterator(const ParExePipeline *pipeline)
174  : elm::genstruct::Vector<ParExeStage *>::Iterator(pipeline->_stages) {}
175  };
176  };
177 
178 
180  _stages.add(stage);
181  if (_first_stage == NULL)
182  _first_stage = stage;
183  _last_stage = stage;
184  if ( stage->sourceQueue() != NULL)
185  stage->sourceQueue()->setEmptyingStage(stage);
186  if ( stage->destinationQueue() != NULL)
187  stage->destinationQueue()->setFillingStage(stage);
188  }
189 
190  /*
191  * class ParExeProc
192  *
193  */
194 
195  class ParExeProc {
196  private:
202 
203  public:
204  typedef enum instruction_category_t {
205  IALU = 0,
206  FALU = 1,
207  MEMORY = 2,
208  CONTROL = 3,
209  MUL = 4,
210  DIV = 5,
211  INST_CATEGORY_NUMBER // must be the last value
213 
214 
216  inline void addQueue(elm::String name, int size){_queues.add(new ParExeQueue(name, size));}
217  inline ParExeQueue * queue(int index) {return _queues[index];}
218  inline void setFetchStage(ParExeStage * stage) {_fetch_stage = stage;}
219  inline ParExeStage * fetchStage(void) {return _fetch_stage;}
220  inline void setExecStage(ParExeStage * stage) {_exec_stage = stage;}
221  inline ParExeStage * execStage(void) {return _exec_stage;}
222  inline ParExeStage * lastStage(void) {return _pipeline.lastStage() ;}
223  inline bool isLastStage(ParExeStage *stage) {return (_pipeline.lastStage() == stage);}
224  inline ParExePipeline *pipeline() {return &_pipeline;}
225  inline elm::genstruct::SLList<ParExeStage *> *listOfInorderStages() {return &_inorder_stages;}
226 
227  class QueueIterator: public elm::genstruct::Vector<ParExeQueue *>::Iterator {
228  public:
229  inline QueueIterator(const ParExeProc *processor)
230  : elm::genstruct::Vector<ParExeQueue *>::Iterator(processor->_queues) {}
231  };
232 
233  };
234 
235  inline ParExeStage::ParExeStage(pipeline_stage_category_t category, int latency, int width, order_t policy, ParExeQueue *sq, ParExeQueue *dq, elm::String name, int index, const hard::PipelineUnit *unit)
236  : _unit(unit), _category(category), _latency(latency), _width(width), _order_policy(policy),
237  _source_queue(sq), _destination_queue(dq), _name(name), _index(index) {}
238 
239  inline void ParExeStage::addFunctionalUnit(bool pipelined, int latency, int width, elm::String name, const hard::PipelineUnit *unit) {
241  if ( !pipelined) {
242  ParExeStage * stage = new ParExeStage(FU, latency, width, _order_policy, _source_queue, _destination_queue, name, 0, unit);
243  fu->addStage(stage);
244  }
245  else {
246  ParExeStage * stage;
247 
248  // first_stage
249  stage = new ParExeStage(FU, 1, width, _order_policy, _source_queue, NULL, name + "1", 0, unit);
250  fu->addStage(stage);
251 
252  // intermediate stages
253  for (int i=2 ; i<latency ; i++) {
254  stage = new ParExeStage(FU, 1, width, IN_ORDER, NULL, NULL, _ << name << i, 0, unit);
255  fu->addStage(stage);
256  }
257 
258  // last stage
259  stage = new ParExeStage(FU, 1, width, IN_ORDER, NULL, _destination_queue, _ << name << latency, 0, unit);
260  fu->addStage(stage);
261  }
262  _fus.add(fu);
263  }
264 
265 
266 
267 
268 } // otawa
269 
270 #endif // OTAWA_MICROPROCESSOR_H
int _width
Definition: ParExeProc.h:95
QueueIterator(const ParExeProc *processor)
Definition: ParExeProc.h:229
ParExeQueue * destinationQueue(void)
Definition: ParExeProc.h:119
ParExePipeline()
Definition: ParExeProc.h:164
bool hasNodes(void)
Deletes all the nodes in the list.
Definition: ParExeProc.h:127
ParExeStage * fetchStage(void)
Definition: ParExeProc.h:219
instruction_category_t
Definition: Microprocessor.h:46
Iterator for the instruction queues.
Definition: ParExeProc.h:227
Representation of a pipeline stage to be used to build a ParExeGraph.
Definition: ParExeProc.h:86
Definition: ParExeProc.h:88
void addNode(ParExeNode *node)
This function adds an execution graph (ParExeGraph) node to the list of nodes related to the pipeline...
Definition: ParExeProc.h:107
ParExeStage * _filling_stage
Definition: ParExeProc.h:61
elm::String _name
Definition: ParExeProc.h:59
pipeline_stage_category_t _category
Definition: ParExeProc.h:93
t::uint32 mask
Definition: base.h:45
instruction_category_t
Definition: ParExeProc.h:204
elm::genstruct::SLList< ParExeStage * > _inorder_stages
Definition: ParExeProc.h:199
void setFillingStage(ParExeStage *stage)
Definition: ParExeProc.h:74
Pair< T1, T2 > pair(const T1 &v1, const T2 &v2)
void setEmptyingStage(ParExeStage *stage)
Definition: ParExeProc.h:76
Représentation of a processor (to be used to build a ParExeGraph).
Definition: ParExeProc.h:195
ParExePipeline * findFU(Inst::kind_t kind)
Definition: ParExeProc.h:134
void addQueue(elm::String name, int size)
Add an instruction queue to the processor.
Definition: ParExeProc.h:216
elm::String name(void)
Definition: ParExeProc.h:115
ParExeQueue * queue(int index)
Returns a pointer to the queue specified by index.
Definition: ParExeProc.h:217
bool isFuStage(void)
Definition: ParExeProc.h:121
elm::genstruct::Vector< ParExeQueue * > _queues
Definition: ParExeProc.h:197
Definition: Microprocessor.h:48
elm::genstruct::Vector< ParExeNode * > _nodes
Definition: ParExeProc.h:103
Description of a processor pipeline.
Definition: Processor.h:136
int _latency
Definition: ParExeProc.h:94
ParExeStage * _last_stage
Definition: ParExeProc.h:161
Definition: ParExeProc.h:89
Vector< Pair< Inst::kind_t, ParExePipeline * > > _bindings
Definition: ParExeProc.h:101
ParExeQueue(elm::String name, int size)
Constructor.
Definition: ParExeProc.h:64
AutoStringStartup & _
elm::String _name
Definition: ParExeProc.h:99
void addBinding(Inst::kind_t kind, ParExePipeline *fu)
Binds a functional unit to an instruction kind.
Definition: ParExeProc.h:132
StringOption proc(command, 'p',"processor","used processor","path","")
ParExeQueue * _source_queue
Definition: ParExeProc.h:97
uint32 size
elm::genstruct::SLList< ParExeStage * > * listOfInorderStages()
Definition: ParExeProc.h:225
Definition: features.h:44
Definition: ParExeProc.h:171
const hard::PipelineUnit * unit(void) const
Definition: ParExeProc.h:112
ParExeStage * lastStage()
Definition: ParExeProc.h:166
int index(void)
Definition: ParExeProc.h:116
Inst::kind_t kind
Definition: odisasm.cpp:106
ParExeNode * lastNode(void)
Definition: ParExeProc.h:126
Definition: Microprocessor.h:50
int numFus(void)
Definition: ParExeProc.h:123
A node of the ParExeGraph, that represents the crossing of an instruction inside a microprocessor sta...
Definition: ParExeGraph.h:339
int latency(void)
Definition: ParExeProc.h:120
ParExePipeline _pipeline
Definition: ParExeProc.h:198
Definition: Processor.h:41
void addFunctionalUnit(bool pipelined, int latency, int width, elm::String name, const hard::PipelineUnit *unit)
Adds a functional unit (should be used with EXECUTE stages only).
Definition: ParExeProc.h:239
Definition: Microprocessor.h:49
const hard::PipelineUnit * _unit
Definition: ParExeProc.h:92
Definition: Microprocessor.h:47
Definition: features.h:48
void addStage(ParExeStage *stage)
Adds a stage to the pipeline.
Definition: ParExeProc.h:179
ParExeStage * _exec_stage
Definition: ParExeProc.h:201
int _index
Definition: ParExeProc.h:100
int _size
Definition: ParExeProc.h:60
elm::t::uint32 kind_t
Definition: Inst.h:67
ParExeNode * firstNode(void)
Definition: ParExeProc.h:125
ParExeStage * _fetch_stage
Definition: ParExeProc.h:200
ParExeNode * node(int index)
Returns a pointer to a graph node related to the stage.
Definition: ParExeProc.h:130
int numStages()
Definition: ParExeProc.h:169
ParExeStage * emptyingStage(void)
Definition: ParExeProc.h:72
ParExeStage * firstStage()
Definition: ParExeProc.h:167
ParExeQueue * sourceQueue(void)
Definition: ParExeProc.h:118
Representation of a pipeline (list of stages).
Definition: ParExeProc.h:157
NodeIterator(const ParExeStage *stage)
Definition: ParExeProc.h:145
ParExeStage * execStage(void)
Definition: ParExeProc.h:221
elm::String name(void)
Definition: ParExeProc.h:66
elm::genstruct::Vector< ParExeStage * > _stages
Definition: ParExeProc.h:159
Iterator for the graph nodes related to the pipeline stage.
Definition: ParExeProc.h:143
bool isLastStage(ParExeStage *stage)
Definition: ParExeProc.h:223
ParExeStage(pipeline_stage_category_t category, int latency, int width, order_t policy, ParExeQueue *sq, ParExeQueue *dq, elm::String name, int index=0, const hard::PipelineUnit *unit=0)
Constructor.
Definition: ParExeProc.h:235
cstring name
Definition: odisasm.cpp:107
ParExeQueue * _destination_queue
Definition: ParExeProc.h:98
elm::genstruct::Vector< ParExePipeline * > _fus
Definition: ParExeProc.h:102
ParExeStage * lastStage(void)
Definition: ParExeProc.h:222
ParExeStage * fillingStage(void)
Definition: ParExeProc.h:70
ParExeStage * _emptying_stage
Definition: ParExeProc.h:62
ParExePipeline * pipeline()
Definition: ParExeProc.h:224
~ParExePipeline()
Definition: ParExeProc.h:165
int width(void) const
Definition: ParExeProc.h:114
IntFormat width(int width, IntFormat fmt)
Definition: Microprocessor.h:53
pipeline_stage_category_t category(void)
Definition: ParExeProc.h:117
Definition: Microprocessor.h:52
order_t _order_policy
Definition: ParExeProc.h:96
Representation of a hardware instruction queue to be used to build a ParExeGraph. ...
Definition: ParExeProc.h:57
order_t orderPolicy(void)
Definition: ParExeProc.h:113
pipeline_stage_category_t
Definition: ParExeProc.h:89
ParExePipeline * fu(int index)
This function returns a pointer to a functional unit pipeline.
Definition: ParExeProc.h:124
order_t
Definition: ParExeProc.h:88
int size(void)
Definition: ParExeProc.h:68
Definition: Microprocessor.h:51
int numNodes(void)
Definition: ParExeProc.h:129
void deleteNodes(void)
Definition: ParExeProc.h:128
void removeNode(ParExeNode *node)
Definition: ParExeProc.h:109
StageIterator(const ParExePipeline *pipeline)
Definition: ParExeProc.h:173
void setFetchStage(ParExeStage *stage)
Declares a stage as the fetch stage (it will undergo a special processing when building a ParExeGraph...
Definition: ParExeProc.h:218
void setExecStage(ParExeStage *stage)
Declares a stage as the execution stage (it will undergo a special processing when building a ParExeG...
Definition: ParExeProc.h:220
ParExeStage * _first_stage
Definition: ParExeProc.h:162