Otawa  0.10
Processor.h
Go to the documentation of this file.
1 /*
2  * hard::Processor class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2005-12, 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_HARD_PROCESSOR_H
22 #define OTAWA_HARD_PROCESSOR_H
23 
24 #include <elm/string.h>
25 #include <elm/serial2/macros.h>
26 #include <elm/serial2/collections.h>
27 #include <elm/genstruct/Table.h>
28 #include <otawa/prog/Inst.h>
29 #include <elm/util/strong_type.h>
31 #include <elm/system/Path.h>
32 #include <otawa/prog/Manager.h>
33 
34 namespace otawa { namespace hard {
35 
36 using namespace elm;
37 using namespace elm::genstruct;
38 class ProcessorBuilder;
39 
40 // PipelineUnit class
41 class PipelineUnit {
42  SERIALIZABLE(otawa::hard::PipelineUnit, FIELD(name) & FIELD(latency) & FIELD(width) & FIELD(branch) & FIELD(mem));
43 public:
44  inline PipelineUnit(void): latency(1), width(1), branch(false), mem(false) { };
45  virtual ~PipelineUnit(void) { }
46  inline elm::String getName(void) const { return name; };
47  inline int getLatency(void) const { return latency; };
48  inline int getWidth(void) const { return width; };
49  inline bool isBranch(void) const { return branch; }
50  inline bool isMem(void) const { return mem; }
51 protected:
52  string name;
53  int latency;
54  int width;
55  bool branch;
56  bool mem;
57 };
58 
59 // FunctionalUnit class
61  friend class FunctionalUnitBuilder;
62  SERIALIZABLE(otawa::hard::FunctionalUnit, BASE(otawa::hard::PipelineUnit) & FIELD(pipelined));
63  bool pipelined;
64 public:
65  inline FunctionalUnit(void): pipelined(false) { };
66  virtual ~FunctionalUnit(void) { }
67  inline bool isPipelined(void) const { return pipelined; };
68 };
69 
70 // Dispatch class
71 class Dispatch {
72  friend class StageBuilder;
73  SERIALIZABLE(otawa::hard::Dispatch, FIELD(type) & FIELD(fu));
74 public:
76 private:
79 public:
80  inline Dispatch(void): type(0), fu(0) { };
81  virtual ~Dispatch(void) { }
82  inline type_t getType(void) const { return type; };
83  inline FunctionalUnit *getFU(void) const { return fu; };
84 };
85 
86 // Stage class
87 class Stage: public PipelineUnit {
88  friend class StageBuilder;
89  SERIALIZABLE(otawa::hard::Stage, BASE(otawa::hard::PipelineUnit) & FIELD(type) & FIELD(fus) & FIELD(dispatch) & FIELD(ordered));
90 public:
91  typedef enum type_t {
92  NONE = 0,
97  DECOMP
98  } type_t;
99 private:
103  bool ordered;
104 public:
105  inline Stage(type_t _type = NONE): type(_type), ordered(false) { };
106  virtual ~Stage(void) { }
107  inline type_t getType(void) const { return type; };
108  inline const Table<FunctionalUnit *>& getFUs(void) const { return fus; }
109  inline const Table<Dispatch *>& getDispatch(void) const { return dispatch; }
110  inline bool isOrdered(void) const { return ordered; }
111  template <class T> inline T select(Inst *inst, const T table[]) const;
112  template <class T> inline T select(Inst::kind_t kind, const T table[]) const;
113 };
114 
115 // Queue class
116 class Queue {
117  friend class QueueBuilder;
118  SERIALIZABLE(otawa::hard::Queue, FIELD(name) & FIELD(size) & FIELD(input)
119  & FIELD(output) & FIELD(intern));
121  int size;
122  Stage *input, *output;
124 public:
125  inline Queue(void): size(0), input(0), output(0) { }
126  virtual ~Queue(void) { }
127  inline elm::String getName(void) const { return name; }
128  inline int getSize(void) const { return size; }
129  inline Stage *getInput(void) const { return input; }
130  inline Stage *getOutput(void) const { return output; }
131  inline const AllocatedTable<Stage *>& getIntern(void) const
132  { return intern; }
133 };
134 
135 // Processor class
136 class Processor {
137  friend class ProcessorBuilder;
138  SERIALIZABLE(otawa::hard::Processor, FIELD(arch) & FIELD(model)
139  & FIELD(builder) & FIELD(stages) & FIELD(queues) & FIELD(frequency));
140 
141 public:
142  inline Processor(void): frequency(0) { }
143  virtual ~Processor(void) { }
144  inline elm::String getArch(void) const { return arch; };
145  inline elm::String getModel(void) const { return model; };
146  inline elm::String getBuilder(void) const { return builder; };
147  inline const Table<Stage *>& getStages(void) const { return stages; };
148  inline const Table<Queue *>& getQueues(void) const { return queues; };
149  inline t::uint64 getFrequency(void) const { return frequency; }
150 
151  static const Processor null;
152  static Processor *load(const elm::system::Path& path) throw(LoadException);
153  static Processor *load(xom::Element *element) throw(LoadException);
154 
155 private:
162 };
163 
164 
165 // Stage inlines
166 template <class T>
167 inline T Stage::select(Inst *inst, const T table[]) const {
168  return select<T>(inst->kind(), table);
169 }
170 
171 template <class T>
172 inline T Stage::select(Inst::kind_t kind, const T table[]) const {
173  for(int i = 0; i < dispatch.count(); i++) {
174  Inst::kind_t mask = dispatch[i]->getType();
175  if((mask & kind) == mask)
176  return table[i];
177  }
178 }
179 
180 // features
183 
184 } } // otawa::hard
185 
187 namespace elm { namespace serial2 {
188  void __unserialize(Unserializer& s, otawa::hard::Dispatch::type_t& v);
189  void __serialize(Serializer& s, otawa::hard::Dispatch::type_t v);
190 } }
191 
192 #endif // OTAWA_HARD_PROCESSOR_H
int latency
Definition: Processor.h:53
type_t getType(void) const
Definition: Processor.h:82
The usual Feature class has as drawback to exhibit completely the processing of the feature and there...
Definition: SilentFeature.h:32
virtual ~Dispatch(void)
Definition: Processor.h:81
elm::String getArch(void) const
Definition: Processor.h:144
elm::String getName(void) const
Definition: Processor.h:127
struct otawa::sem::inst inst
const Table< Dispatch * > & getDispatch(void) const
Definition: Processor.h:109
Identifier< const Processor * > PROCESSOR
Current memory.
Processor(void)
Definition: Processor.h:142
virtual ~Stage(void)
Definition: Processor.h:106
A dispatch object allows to map some kinds of instructions to a functional unit.
Definition: Processor.h:71
static const Processor null
Definition: Processor.h:151
Queue(void)
Definition: Processor.h:125
t::uint64 getFrequency(void) const
Definition: Processor.h:149
int getLatency(void) const
Definition: Processor.h:47
PipelineUnit(void)
Definition: Processor.h:44
type_t type
Definition: Processor.h:77
virtual ~Queue(void)
Definition: Processor.h:126
t::uint32 mask
Definition: base.h:45
const AllocatedTable< Stage * > & getIntern(void) const
Definition: Processor.h:131
Definition: Processor.h:96
Definition: ClpValue.h:54
virtual ~FunctionalUnit(void)
Definition: Processor.h:66
AllocatedTable< Queue * > queues
Definition: Processor.h:160
Definition: ProcessorBuilder.h:79
type_t type
Definition: Processor.h:100
bool ordered
Definition: Processor.h:103
AllocatedTable< FunctionalUnit * > fus
Definition: Processor.h:101
Definition: Processor.h:93
FunctionalUnit(void)
Definition: Processor.h:65
Stage * output
Definition: Processor.h:122
Definition: ProcessorBuilder.h:62
Description of a processor pipeline.
Definition: Processor.h:136
elm::String arch
Definition: Processor.h:156
Stage(type_t _type=NONE)
Definition: Processor.h:105
Definition: Processor.h:94
bool pipelined
Definition: Processor.h:63
bool isBranch(void) const
Definition: Processor.h:49
elm::String builder
Definition: Processor.h:158
uint32 size
bool branch
Definition: Processor.h:55
Inst::kind_t kind
Definition: odisasm.cpp:106
bool isMem(void) const
Definition: Processor.h:50
int width
Definition: Processor.h:54
type_t getType(void) const
Definition: Processor.h:107
virtual ~PipelineUnit(void)
Definition: Processor.h:45
Definition: ProcessorBuilder.h:30
virtual ~Processor(void)
Definition: Processor.h:143
This class represents a stage in a pipeline.
Definition: Processor.h:87
FunctionalUnit * fu
Definition: Processor.h:78
elm::String name
Definition: Processor.h:120
#define STRONG_TYPE(N, T)
bool isOrdered(void) const
Definition: Processor.h:110
Definition: Processor.h:41
virtual kind_t kind(void)=0
Get the kind of the current instruction.
Definition: Processor.h:95
inst load(int d, int a, int t)
Definition: inst.h:153
int getWidth(void) const
Definition: Processor.h:48
AllocatedTable< Stage * > intern
Definition: Processor.h:123
The instructions queues stores instruction that come from one stage to another one.
Definition: Processor.h:116
type_t
Definition: Processor.h:91
elm::t::uint32 kind_t
Definition: Inst.h:67
int getSize(void) const
Definition: Processor.h:128
AllocatedTable< Stage * > stages
Definition: Processor.h:159
const Table< Queue * > & getQueues(void) const
Definition: Processor.h:148
AllocatedTable< Dispatch * > dispatch
Definition: Processor.h:102
A functional unit is specialized in the computation of some kinds of instructions.
Definition: Processor.h:60
bool isPipelined(void) const
Definition: Processor.h:67
This class represents identifier with a typed associated value.
Definition: Identifier.h:51
cstring name
Definition: odisasm.cpp:107
const Table< FunctionalUnit * > & getFUs(void) const
Definition: Processor.h:108
elm::String getModel(void) const
Definition: Processor.h:145
Exception thrown when a loader encounters an error during load.
Definition: Manager.h:52
FunctionalUnit * getFU(void) const
Definition: Processor.h:83
This class represents assembly instruction of a piece of code.
Definition: Inst.h:62
Stage * getOutput(void) const
Definition: Processor.h:130
const Table< Stage * > & getStages(void) const
Definition: Processor.h:147
Definition: ProcessorBuilder.h:43
IntFormat width(int width, IntFormat fmt)
elm::String getName(void) const
Definition: Processor.h:46
elm::String getBuilder(void) const
Definition: Processor.h:146
string name
Definition: Processor.h:52
Stage * getInput(void) const
Definition: Processor.h:129
t::uint64 frequency
Definition: Processor.h:161
const Type & type(void)
Definition: type.h:163
elm::String model
Definition: Processor.h:157
inst branch(int to)
Definition: inst.h:149
T select(Inst *inst, const T table[]) const
Definition: Processor.h:167
int size
Definition: Processor.h:121
SilentFeature PROCESSOR_FEATURE
This feature ensures we have obtained the memory configuration of the system.
Dispatch(void)
Definition: Processor.h:80
uint64_t uint64
ENUM(otawa::hard::Stage::type_t)
type_t
Definition: features.h:57
bool mem
Definition: Processor.h:56