OpenASIP  2.0
ExecutionPipeline.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file ExecutionPipeline.hh
26  *
27  * Declaration of class ExecutionPipeline.
28  *
29  * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_EXECUTION_PIPELINE_HH
34 #define TTA_EXECUTION_PIPELINE_HH
35 
36 #include <vector>
37 #include <map>
38 #include <set>
39 
40 #include "MachinePart.hh"
41 #include "Exception.hh"
42 #include "PipelineElement.hh"
43 
44 class Operand;
45 class ObjectState;
46 
47 namespace TTAMachine {
48 
49 class HWOperation;
50 class FUPort;
51 
52 /**
53  * Represents an execution pipeline in function unit.
54  */
56 public:
57  /// Set for operand indexes.
58  typedef std::set<int> OperandSet;
59  /// Set for pipeline elements.
60  typedef std::set<PipelineElement*,PipelineElement::Comparator> ResourceSet;
61 
63  virtual ~ExecutionPipeline();
64 
65  const HWOperation* parentOperation() const;
66 
67  void addResourceUse(const std::string& name, int start, int duration);
68  void addPortRead(int operand, int start, int duration);
69  void addPortWrite(int operand, int start, int duration);
70  void removeResourceUse(const std::string& name);
71  void removeResourceUse(const std::string& name, int cycle);
72  void removeAllResourceUses();
73  void removeOperandUse(int operand, int cycle);
74  bool isResourceUsed(const std::string& name, int cycle) const;
75 
76  ResourceSet resourceUsages(int cycle) const;
77 
78  bool isPortUsed(const FUPort& port, int cycle) const;
79  bool isPortRead(const FUPort& port, int cycle) const;
80  bool isPortWritten(const FUPort& port, int cycle) const;
81 
82  OperandSet readOperands(int cycle) const;
83  OperandSet writtenOperands(int cycle) const;
84  OperandSet readOperands() const;
86 
87  int latency() const;
88  int latency(int output) const;
89  int slack(int input) const;
90 
91  ObjectState* saveState() const;
92  void loadState(const ObjectState* state);
93 
94  bool isArchitectureEqual(const ExecutionPipeline* pipeline) const;
95 
96  /// ObjectState name for ExecutionPipeline.
97  static const std::string OSNAME_PIPELINE;
98  /// ObjectState name for pipeline resource usage.
99  static const std::string OSNAME_RESOURCE_USAGE;
100  /// ObjectState name for operand read.
101  static const std::string OSNAME_OPERAND_READ;
102  /// ObjectState name for operand write.
103  static const std::string OSNAME_OPERAND_WRITE;
104  /// ObjectState attribute key for name of resource.
105  static const std::string OSKEY_RESOURCE_NAME;
106  /// ObjectState attribute key for operand number.
107  static const std::string OSKEY_OPERAND;
108  /// ObjectState attribute key for start cycle of a resource usage.
109  static const std::string OSKEY_START_CYCLE;
110  /// ObjectState attribute key for duration of a resource usage.
111  static const std::string OSKEY_CYCLES;
112 
113 private:
114  /// Vector for ObjectState pointers.
115  typedef std::vector<const ObjectState*> ObjectStateTable;
116 
117  /// Vector for resource sets.
118  typedef std::vector<ResourceSet> ResourceUsage;
119  /// Vector for operand sets.
120  typedef std::vector<OperandSet> IOUsage;
121 
122  void checkStartCycle(int startCycle) const;
123  static void checkDuration(int duration);
124  static void checkResourceName(const std::string& name);
125  void checkInputOperand(int operand) const;
126  void checkOutputOperand(int operand) const;
128  const std::string& resource, int start, int duration) const;
129  void checkOperandAvailability(int operand, int start, int duration) const;
130 
132  const std::string& name,
133  int start,
134  int duration);
135  void internalAddPortUse(
136  int operand,
137  int start,
138  int duration,
139  IOUsage& toModify);
141  const std::string& name,
142  int start,
143  int duration);
144  void internalRemoveOperandUse(int operand, int start, int duration);
145  void adjustLatency(int newLatency);
146  bool isOperandBound(
147  const FUPort& port,
148  const OperandSet& operands) const;
149  bool isOperandWritten(int operand) const;
150  bool isOperandRead(int operand) const;
151  int firstCycle() const;
152  int firstCycleWithoutResource(const std::string& resource) const;
154  const std::string& resource,
155  int cycle) const;
156  int firstCycleWithoutOperandUse(int operand, int cycle) const;
157  ResourceSet usedResources() const;
158  PipelineElement* pipelineElement(const std::string& name) const;
159  PipelineElement* addPipelineElement(const std::string& name) const;
160  static void saveResourceUse(
161  const PipelineElement* element,
162  int cycleToSave,
163  ObjectState* pipelineState);
164  static void saveOperandUse(
165  int operand,
166  int cycleToSave,
167  ObjectState* pipelineState,
168  const std::string& osName);
169  ObjectStateTable sortResourceUsages(const ObjectState* pipelineState) const;
170  void addResourceUsage(
171  ObjectStateTable& usages, const ObjectState* usageState) const;
172 
173  /// Resource usage.
175  /// Operand reads.
177  /// Operand writes.
179  /// The parent operation.
181 
182 };
183 }
184 
185 #endif
Operand
Definition: Operand.hh:52
TTAMachine::ExecutionPipeline::saveState
ObjectState * saveState() const
Definition: ExecutionPipeline.cc:551
TTAMachine::SubComponent
Definition: MachinePart.hh:168
TTAMachine::ExecutionPipeline::isOperandWritten
bool isOperandWritten(int operand) const
Definition: ExecutionPipeline.cc:1057
TTAMachine::HWOperation
Definition: HWOperation.hh:52
Exception.hh
TTAMachine::ExecutionPipeline::isPortUsed
bool isPortUsed(const FUPort &port, int cycle) const
Definition: ExecutionPipeline.cc:349
TTAMachine::ExecutionPipeline::resourceUsage_
ResourceUsage resourceUsage_
Resource usage.
Definition: ExecutionPipeline.hh:174
TTAMachine::ExecutionPipeline::OSNAME_PIPELINE
static const std::string OSNAME_PIPELINE
ObjectState name for ExecutionPipeline.
Definition: ExecutionPipeline.hh:97
TTAMachine::ExecutionPipeline::isArchitectureEqual
bool isArchitectureEqual(const ExecutionPipeline *pipeline) const
Definition: ExecutionPipeline.cc:693
TTAMachine::ExecutionPipeline::readOperands
OperandSet readOperands() const
Definition: ExecutionPipeline.cc:448
TTAMachine::ExecutionPipeline::ObjectStateTable
std::vector< const ObjectState * > ObjectStateTable
Vector for ObjectState pointers.
Definition: ExecutionPipeline.hh:115
ObjectState
Definition: ObjectState.hh:59
TTAMachine::ExecutionPipeline::removeResourceUse
void removeResourceUse(const std::string &name)
Definition: ExecutionPipeline.cc:189
TTAMachine::ExecutionPipeline::adjustLatency
void adjustLatency(int newLatency)
Definition: ExecutionPipeline.cc:1003
TTAMachine::ExecutionPipeline::checkOperandAvailability
void checkOperandAvailability(int operand, int start, int duration) const
Definition: ExecutionPipeline.cc:858
TTAMachine::ExecutionPipeline::internalAddPortUse
void internalAddPortUse(int operand, int start, int duration, IOUsage &toModify)
Definition: ExecutionPipeline.cc:911
TTAMachine::ExecutionPipeline::ExecutionPipeline
ExecutionPipeline(HWOperation &parentOperation)
Definition: ExecutionPipeline.cc:68
TTAMachine::ExecutionPipeline::OSKEY_OPERAND
static const std::string OSKEY_OPERAND
ObjectState attribute key for operand number.
Definition: ExecutionPipeline.hh:107
TTAMachine::ExecutionPipeline::internalRemoveOperandUse
void internalRemoveOperandUse(int operand, int start, int duration)
Definition: ExecutionPipeline.cc:971
MachinePart.hh
TTAMachine::ExecutionPipeline::addPipelineElement
PipelineElement * addPipelineElement(const std::string &name) const
Definition: ExecutionPipeline.cc:1272
TTAMachine::ExecutionPipeline::OSNAME_OPERAND_WRITE
static const std::string OSNAME_OPERAND_WRITE
ObjectState name for operand write.
Definition: ExecutionPipeline.hh:103
TTAMachine::ExecutionPipeline::firstCycleWithoutResource
int firstCycleWithoutResource(const std::string &resource) const
Definition: ExecutionPipeline.cc:1121
TTAMachine::ExecutionPipeline::~ExecutionPipeline
virtual ~ExecutionPipeline()
Definition: ExecutionPipeline.cc:79
TTAMachine::ExecutionPipeline::ResourceUsage
std::vector< ResourceSet > ResourceUsage
Vector for resource sets.
Definition: ExecutionPipeline.hh:118
TTAMachine::ExecutionPipeline::OSKEY_CYCLES
static const std::string OSKEY_CYCLES
ObjectState attribute key for duration of a resource usage.
Definition: ExecutionPipeline.hh:111
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAMachine::ExecutionPipeline::usedResources
ResourceSet usedResources() const
Definition: ExecutionPipeline.cc:1238
TTAMachine::ExecutionPipeline::addResourceUse
void addResourceUse(const std::string &name, int start, int duration)
Definition: ExecutionPipeline.cc:112
TTAMachine::ExecutionPipeline::slack
int slack(int input) const
Definition: ExecutionPipeline.cc:528
TTAMachine::ExecutionPipeline::pipelineElement
PipelineElement * pipelineElement(const std::string &name) const
Definition: ExecutionPipeline.cc:1259
TTAMachine::ExecutionPipeline::opWrites_
IOUsage opWrites_
Operand writes.
Definition: ExecutionPipeline.hh:178
TTAMachine::ExecutionPipeline::isPortWritten
bool isPortWritten(const FUPort &port, int cycle) const
Definition: ExecutionPipeline.cc:386
TTAMachine::ExecutionPipeline::isOperandRead
bool isOperandRead(int operand) const
Definition: ExecutionPipeline.cc:1076
TTAMachine::ExecutionPipeline::firstCycleWithoutOperandUse
int firstCycleWithoutOperandUse(int operand, int cycle) const
Definition: ExecutionPipeline.cc:1201
TTAMachine::ExecutionPipeline::addPortRead
void addPortRead(int operand, int start, int duration)
Definition: ExecutionPipeline.cc:141
TTAMachine::ExecutionPipeline::checkResourceName
static void checkResourceName(const std::string &name)
Definition: ExecutionPipeline.cc:765
TTAMachine::ExecutionPipeline::checkDuration
static void checkDuration(int duration)
Definition: ExecutionPipeline.cc:751
TTAMachine::ExecutionPipeline::addResourceUsage
void addResourceUsage(ObjectStateTable &usages, const ObjectState *usageState) const
Definition: ExecutionPipeline.cc:1401
TTAMachine::ExecutionPipeline::OSKEY_RESOURCE_NAME
static const std::string OSKEY_RESOURCE_NAME
ObjectState attribute key for name of resource.
Definition: ExecutionPipeline.hh:105
TTAMachine::ExecutionPipeline::OperandSet
std::set< int > OperandSet
Set for operand indexes.
Definition: ExecutionPipeline.hh:58
TTAMachine::ExecutionPipeline::saveResourceUse
static void saveResourceUse(const PipelineElement *element, int cycleToSave, ObjectState *pipelineState)
Definition: ExecutionPipeline.cc:1290
TTAMachine::ExecutionPipeline::parent_
HWOperation * parent_
The parent operation.
Definition: ExecutionPipeline.hh:180
TTAMachine::ExecutionPipeline::sortResourceUsages
ObjectStateTable sortResourceUsages(const ObjectState *pipelineState) const
Definition: ExecutionPipeline.cc:1378
TTAMachine::ExecutionPipeline::OSNAME_RESOURCE_USAGE
static const std::string OSNAME_RESOURCE_USAGE
ObjectState name for pipeline resource usage.
Definition: ExecutionPipeline.hh:99
TTAMachine::ExecutionPipeline::isPortRead
bool isPortRead(const FUPort &port, int cycle) const
Definition: ExecutionPipeline.cc:362
TTAMachine::ExecutionPipeline::saveOperandUse
static void saveOperandUse(int operand, int cycleToSave, ObjectState *pipelineState, const std::string &osName)
Definition: ExecutionPipeline.cc:1334
TTAMachine::PipelineElement
Definition: PipelineElement.hh:46
TTAMachine::ExecutionPipeline::firstCycle
int firstCycle() const
Definition: ExecutionPipeline.cc:1097
TTAMachine::ExecutionPipeline::ResourceSet
std::set< PipelineElement *, PipelineElement::Comparator > ResourceSet
Set for pipeline elements.
Definition: ExecutionPipeline.hh:60
TTAMachine::ExecutionPipeline::parentOperation
const HWOperation * parentOperation() const
Definition: ExecutionPipeline.cc:89
TTAMachine::ExecutionPipeline::removeOperandUse
void removeOperandUse(int operand, int cycle)
Definition: ExecutionPipeline.cc:272
PipelineElement.hh
TTAMachine::ExecutionPipeline::checkInputOperand
void checkInputOperand(int operand) const
Definition: ExecutionPipeline.cc:782
TTAMachine::ExecutionPipeline::IOUsage
std::vector< OperandSet > IOUsage
Vector for operand sets.
Definition: ExecutionPipeline.hh:120
TTAMachine::ExecutionPipeline::checkOutputOperand
void checkOutputOperand(int operand) const
Definition: ExecutionPipeline.cc:804
TTAMachine::ExecutionPipeline::isOperandBound
bool isOperandBound(const FUPort &port, const OperandSet &operands) const
Definition: ExecutionPipeline.cc:1035
TTAMachine::ExecutionPipeline::opReads_
IOUsage opReads_
Operand reads.
Definition: ExecutionPipeline.hh:176
TTAMachine::ExecutionPipeline
Definition: ExecutionPipeline.hh:55
TTAMachine::ExecutionPipeline::resourceUsages
ResourceSet resourceUsages(int cycle) const
Definition: ExecutionPipeline.cc:327
TTAMachine::ExecutionPipeline::addPortWrite
void addPortWrite(int operand, int start, int duration)
Definition: ExecutionPipeline.cc:167
TTAMachine::ExecutionPipeline::OSKEY_START_CYCLE
static const std::string OSKEY_START_CYCLE
ObjectState attribute key for start cycle of a resource usage.
Definition: ExecutionPipeline.hh:109
TTAMachine::ExecutionPipeline::internalRemoveResourceUse
void internalRemoveResourceUse(const std::string &name, int start, int duration)
Definition: ExecutionPipeline.cc:936
TTAMachine
Definition: Assembler.hh:48
TTAMachine::ExecutionPipeline::latency
int latency() const
Definition: ExecutionPipeline.cc:482
TTAMachine::ExecutionPipeline::loadState
void loadState(const ObjectState *state)
Definition: ExecutionPipeline.cc:611
TTAMachine::ExecutionPipeline::writtenOperands
OperandSet writtenOperands() const
Definition: ExecutionPipeline.cc:464
TTAMachine::ExecutionPipeline::checkStartCycle
void checkStartCycle(int startCycle) const
Definition: ExecutionPipeline.cc:723
TTAMachine::ExecutionPipeline::isResourceUsed
bool isResourceUsed(const std::string &name, int cycle) const
Definition: ExecutionPipeline.cc:300
TTAMachine::ExecutionPipeline::removeAllResourceUses
void removeAllResourceUses()
Definition: ExecutionPipeline.cc:243
TTAMachine::ExecutionPipeline::internalAddResourceUse
void internalAddResourceUse(const std::string &name, int start, int duration)
Definition: ExecutionPipeline.cc:884
TTAMachine::ExecutionPipeline::OSNAME_OPERAND_READ
static const std::string OSNAME_OPERAND_READ
ObjectState name for operand read.
Definition: ExecutionPipeline.hh:101
TTAMachine::ExecutionPipeline::checkResourceAvailability
void checkResourceAvailability(const std::string &resource, int start, int duration) const
Definition: ExecutionPipeline.cc:826