OpenASIP  2.0
ResourceBroker.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 ResourceBroker.hh
26  *
27  * Declaration of ResourceBroker class.
28  *
29  * @author Ari Mets�halme 2006 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_RESOURCE_BROKER_HH
34 #define TTA_RESOURCE_BROKER_HH
35 
36 #include <map>
37 #include <set>
38 #include <string>
39 
40 #include "Exception.hh"
41 #include "SchedulingResource.hh"
42 #include "MachinePart.hh"
43 #include "MoveNode.hh"
44 
45 #define TEST_BROKERS 0
46 
47 namespace TTAMachine {
48  class Machine;
49  class MachinePart;
50  class Bus;
51  class FunctionUnit;
52  class ImmediateUnit;
53 }
54 
55 
56 class ResourceMapper;
57 
58 /**
59  * Base interface for resource brokers.
60  */
62 public:
63  ResourceBroker(std::string, unsigned int initiationInterval = 0);
64  virtual ~ResourceBroker();
65 
66  typedef std::set<SchedulingResource*> ResourceSet;
67  virtual bool isAnyResourceAvailable(
68  int cycle, const MoveNode& node,
69  const TTAMachine::Bus* bus,
70  const TTAMachine::FunctionUnit* srcFU,
71  const TTAMachine::FunctionUnit* dstFU,
72  int immWriteCycle,
73  const TTAMachine::ImmediateUnit* immu,
74  int immRegIndex)
75  const;
77  int cycle,
78  const MoveNode& node,
79  const TTAMachine::Bus* bus,
80  const TTAMachine::FunctionUnit* srcFU,
81  const TTAMachine::FunctionUnit* dstFU,
82  int immWriteCycle,
83  const TTAMachine::ImmediateUnit* immu,
84  int immRegIndex) const;
86  int cycle, const MoveNode& node,
87  const TTAMachine::Bus* bus,
88  const TTAMachine::FunctionUnit* srcFU,
89  const TTAMachine::FunctionUnit* dstFU,
90  int immWriteCycle,
91  const TTAMachine::ImmediateUnit* immu,
92  int immRegIndex) const;
93  virtual bool isAvailable(
94  SchedulingResource& des, const MoveNode& node, int cycle,
95  const TTAMachine::Bus* bus,
96  const TTAMachine::FunctionUnit* srcFU,
97  const TTAMachine::FunctionUnit* dstFU,
98  int immWriteCycle,
99  const TTAMachine::ImmediateUnit* immu,
100  int immRegIndex) const;
101  virtual int earliestCycle(
102  int cycle, const MoveNode& node,
103  const TTAMachine::Bus* bus,
104  const TTAMachine::FunctionUnit* srcFU,
105  const TTAMachine::FunctionUnit* dstFU,
106  int immWriteCycle,
107  const TTAMachine::ImmediateUnit* immu,
108  int immRegIndex) const = 0;
109  virtual int latestCycle(
110  int cycle, const MoveNode& node,
111  const TTAMachine::Bus* bus,
112  const TTAMachine::FunctionUnit* srcFU,
113  const TTAMachine::FunctionUnit* dstFU,
114  int immWriteCycle,
115  const TTAMachine::ImmediateUnit* immu,
116  int immRegIndex) const = 0;
117  virtual bool isAlreadyAssigned(
118  int cycle, const MoveNode& node,const TTAMachine::Bus* preassignedBus)
119  const = 0;
120  virtual bool isApplicable(
121  const MoveNode& node, const TTAMachine::Bus* preassignedBus) const = 0;
122  virtual void assign(
123  int cycle, MoveNode& node, SchedulingResource& res, int immWriteCycle,
124  int immRegIndex) = 0;
125 
126  virtual void unassign(MoveNode& node) = 0;
127 
128  virtual void buildResources(const TTAMachine::Machine& target) = 0;
129  virtual void setupResourceLinks(const ResourceMapper& mapper) = 0;
131  const TTAMachine::MachinePart& mp) const;
132  virtual const TTAMachine::MachinePart& machinePartOf(
133  const SchedulingResource& r) const;
134  bool hasResourceOf(const TTAMachine::MachinePart& mp) const;
135  bool hasResource(const SchedulingResource& r) const;
136  int resourceCount() const;
137 
138  virtual bool isBusBroker() const;
139  virtual bool isITemplateBroker() const;
140  virtual bool isIUBroker() const;
141  virtual bool isExecutionPipelineBroker() const;
142  void validateResources() const;
143  virtual std::string brokerName() const;
144  void resources(ResourceSet& contents);
145  virtual void setInitiationInterval(unsigned int cycles);
146  virtual void clear();
147  virtual void setMaxCycle(unsigned int) {};
148 protected:
149  typedef std::map<
152  // A container to store MoveNode - Scheduling Resource pairs
153  typedef std::map<const MoveNode*, SchedulingResource*,
155  void setResourceMapper(const ResourceMapper& mapper);
156  const ResourceMapper& resourceMapper() const;
157 
158  unsigned int initiationInterval_;
159  unsigned int instructionIndex(unsigned int) const;
160 
161  void addResource(
162  const TTAMachine::MachinePart& mp,
163  SchedulingResource* res);
164 
168  std::string brokerName_;
169 };
170 
171 #include "ResourceBroker.icc"
172 
173 #endif
ResourceBroker::~ResourceBroker
virtual ~ResourceBroker()
Definition: ResourceBroker.cc:59
ResourceBroker::allAvailableResources
virtual SchedulingResourceSet allAvailableResources(int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const
Definition: ResourceBroker.cc:143
ResourceBroker::isAlreadyAssigned
virtual bool isAlreadyAssigned(int cycle, const MoveNode &node, const TTAMachine::Bus *preassignedBus) const =0
ResourceBroker::assign
virtual void assign(int cycle, MoveNode &node, SchedulingResource &res, int immWriteCycle, int immRegIndex)=0
ResourceBroker::initiationInterval_
unsigned int initiationInterval_
Definition: ResourceBroker.hh:158
Exception.hh
ResourceBroker.icc
ResourceBroker::resMap_
ResourceMap resMap_
Definition: ResourceBroker.hh:165
TTAMachine::Bus
Definition: Bus.hh:53
ResourceBroker::ResourceMap
std::map< const TTAMachine::MachinePart *, SchedulingResource *, TTAMachine::MachinePart::Comparator > ResourceMap
Definition: ResourceBroker.hh:147
ResourceBroker
Definition: ResourceBroker.hh:61
ResourceBroker::hasResource
bool hasResource(const SchedulingResource &r) const
Definition: ResourceBroker.cc:214
MoveNode
Definition: MoveNode.hh:65
ResourceBroker::isApplicable
virtual bool isApplicable(const MoveNode &node, const TTAMachine::Bus *preassignedBus) const =0
ResourceBroker::assignedResources_
MoveResMap assignedResources_
Definition: ResourceBroker.hh:167
ResourceBroker::brokerName
virtual std::string brokerName() const
Definition: ResourceBroker.cc:356
ResourceBroker::addResource
void addResource(const TTAMachine::MachinePart &mp, SchedulingResource *res)
Definition: ResourceBroker.cc:265
ResourceBroker::hasResourceOf
bool hasResourceOf(const TTAMachine::MachinePart &mp) const
Definition: ResourceBroker.cc:203
MachinePart.hh
ResourceBroker::ResourceSet
std::set< SchedulingResource * > ResourceSet
Definition: ResourceBroker.hh:66
SchedulingResourceSet
Definition: SchedulingResource.hh:161
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
ResourceBroker::resources
void resources(ResourceSet &contents)
Definition: ResourceBroker.cc:279
ResourceBroker::MoveResMap
std::map< const MoveNode *, SchedulingResource *, MoveNode::Comparator > MoveResMap
Definition: ResourceBroker.hh:154
ResourceBroker::setResourceMapper
void setResourceMapper(const ResourceMapper &mapper)
Definition: ResourceBroker.cc:224
ResourceBroker::setMaxCycle
virtual void setMaxCycle(unsigned int)
Definition: ResourceBroker.hh:147
SchedulingResource
Definition: SchedulingResource.hh:52
SchedulingResource.hh
ResourceBroker::isAvailable
virtual bool isAvailable(SchedulingResource &des, const MoveNode &node, int cycle, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const
Definition: ResourceBroker.cc:158
ResourceBroker::clear
virtual void clear()
Definition: ResourceBroker.cc:365
TTAMachine::MachinePart
Definition: MachinePart.hh:57
GraphNode::Comparator
Definition: GraphNode.hh:56
ResourceBroker::setInitiationInterval
virtual void setInitiationInterval(unsigned int cycles)
Definition: ResourceBroker.cc:292
ResourceBroker::resourceOf
SchedulingResource * resourceOf(const TTAMachine::MachinePart &mp) const
ResourceBroker::validateResources
void validateResources() const
Definition: ResourceBroker.cc:329
ResourceBroker::isAnyResourceAvailable
virtual bool isAnyResourceAvailable(int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const
Definition: ResourceBroker.cc:75
ResourceBroker::isITemplateBroker
virtual bool isITemplateBroker() const
Definition: ResourceBroker.cc:308
ResourceBroker::availableResource
virtual SchedulingResource & availableResource(int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const
Definition: ResourceBroker.cc:111
ResourceBroker::setupResourceLinks
virtual void setupResourceLinks(const ResourceMapper &mapper)=0
ResourceBroker::isExecutionPipelineBroker
virtual bool isExecutionPipelineBroker() const
Definition: ResourceBroker.cc:318
ResourceBroker::resourceCount
int resourceCount() const
Definition: ResourceBroker.cc:298
ResourceBroker::isIUBroker
virtual bool isIUBroker() const
Definition: ResourceBroker.cc:313
ResourceBroker::unassign
virtual void unassign(MoveNode &node)=0
ResourceBroker::earliestCycle
virtual int earliestCycle(int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const =0
ResourceBroker::buildResources
virtual void buildResources(const TTAMachine::Machine &target)=0
ResourceBroker::latestCycle
virtual int latestCycle(int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const =0
ResourceBroker::instructionIndex
unsigned int instructionIndex(unsigned int) const
Definition: ResourceBroker.cc:249
ResourceMapper
Definition: ResourceMapper.hh:51
ResourceBroker::ResourceBroker
ResourceBroker(std::string, unsigned int initiationInterval=0)
Definition: ResourceBroker.cc:49
ResourceBroker::resourceMapper
const ResourceMapper & resourceMapper() const
Definition: ResourceBroker.cc:234
ResourceBroker::machinePartOf
virtual const TTAMachine::MachinePart & machinePartOf(const SchedulingResource &r) const
Definition: ResourceBroker.cc:181
ResourceBroker::resourceMapper_
const ResourceMapper * resourceMapper_
Definition: ResourceBroker.hh:166
TTAMachine
Definition: Assembler.hh:48
MoveNode.hh
TTAMachine::MachinePart::Comparator
Definition: MachinePart.hh:59
ResourceBroker::isBusBroker
virtual bool isBusBroker() const
Definition: ResourceBroker.cc:303
TTAMachine::Machine
Definition: Machine.hh:73
ResourceBroker::brokerName_
std::string brokerName_
Definition: ResourceBroker.hh:168
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50