OpenASIP  2.0
ITemplateBroker.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 ITemplateBroker.hh
26  *
27  * Declaration of ITemplateBroker class.
28  *
29  * @author Ari Mets�halme 2006 (ari.metsahalme-no.spam-tut.fi)
30  * @author Vladimir Guzma 2007 (vladimir.guzma-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #ifndef TTA_ITEMPLATE_BROKER_HH
35 #define TTA_ITEMPLATE_BROKER_HH
36 
37 #include <vector>
38 
39 #include "ResourceBroker.hh"
40 #include "ImmediateUnit.hh"
41 
42 namespace TTAMachine {
43  class Bus;
44  class Machine;
45  class MachinePart;
46  class ImmediateUnit;
47  class FunctionUnit;
48 }
49 
50 namespace TTAProgram {
51  class Instruction;
52  class Immediate;
53  class Move;
54 }
55 
56 class MoveNode;
57 class ResourceMapper;
58 class SchedulingResource;
60 class BusBroker;
61 
62 /**
63  * ITemplate broker.
64  */
66 public:
67  ITemplateBroker(std::string, BusBroker& busBroker, unsigned int initiationInterval = 0);
68  ITemplateBroker(std::string, BusBroker& busBroker, SimpleResourceManager*, unsigned int initiationInterval = 0);
69  virtual ~ITemplateBroker();
70 
71  virtual bool isAnyResourceAvailable(int, const MoveNode&,
72  const TTAMachine::Bus* bus,
73  const TTAMachine::FunctionUnit* srcFU,
74  const TTAMachine::FunctionUnit* dstFU,
75  int immWriteCycle,
76  const TTAMachine::ImmediateUnit* immu,
77  int immRegIndex) const override;
79  int,
80  const MoveNode&,
81  const TTAMachine::Bus* bus,
82  const TTAMachine::FunctionUnit* srcUnit,
83  const TTAMachine::FunctionUnit* dstUnit,
84  int immWriteCycle,
85  const TTAMachine::ImmediateUnit* immu,
86  int immRegIndex) const override;
87  virtual void assign(int cycle, MoveNode& node, SchedulingResource& res,
88  int immWriteCycle,
89  int immRegIndex) override;
90 
91  virtual void unassign(MoveNode& node) override;
92 
93  virtual int earliestCycle(int cycle, const MoveNode& node,
94  const TTAMachine::Bus* bus,
95  const TTAMachine::FunctionUnit* srcUnit,
96  const TTAMachine::FunctionUnit* dstUnit,
97  int immWriteCycle,
98  const TTAMachine::ImmediateUnit* immu,
99  int immRegIndex) const override;
100  virtual int latestCycle(int cycle, const MoveNode& node,
101  const TTAMachine::Bus* bus,
102  const TTAMachine::FunctionUnit* srcUnit,
103  const TTAMachine::FunctionUnit* dstUnit,
104  int immWriteCycle,
105  const TTAMachine::ImmediateUnit* immu,
106  int immRegIndex) const override;
107  virtual bool isAlreadyAssigned(
108  int cycle, const MoveNode& node,
109  const TTAMachine::Bus* preassignedBus) const override;
110  virtual bool isApplicable(
111  const MoveNode& node, const TTAMachine::Bus*) const override;
112  virtual void buildResources(const TTAMachine::Machine& target) override;
113  virtual void setupResourceLinks(const ResourceMapper& mapper) override;
114 
115  virtual bool isITemplateBroker() const override;
116  virtual TTAProgram::Instruction* instruction(int cycle);
117  virtual void loseInstructionOwnership(int cycle);
118  virtual bool isTemplateAvailable(
119  int, std::shared_ptr<TTAProgram::Immediate>) const;
120  void clearOldResources();
121  void clear() override;
122 private:
123  typedef std::vector<std::shared_ptr<const TTAProgram::Move> > Moves;
124  typedef std::vector<std::shared_ptr<const TTAProgram::Immediate> > Immediates;
125 
127  void assignImmediate(int, std::shared_ptr<TTAProgram::Immediate>);
129  bool isImmediateInTemplate(int, std::shared_ptr<TTAProgram::Immediate>) const;
130 
131  void reselectTemplate(TTAProgram::Instruction& ins, int cycle);
132  /// Move/immediate slots.
133  std::vector<TTAMachine::Bus*> slots_;
134  /// cycle/instruction
135  std::map<int, TTAProgram::Instruction*> instructions_;
136  /// MoveNode/ original parent instruction
137  std::map<const MoveNode*, TTAProgram::Instruction*, MoveNode::Comparator>
139 
140  /// Record cycle for MoveNodes that needed immediate writes,
141  /// IU broker restores immediates before the template broker is called
142  /// so we need to explicitely find the Immediate to remove it from
143  /// template
144  std::map<const MoveNode*, int, GraphNode::Comparator> immediateCycles_;
145  std::map<const MoveNode*, std::shared_ptr<TTAProgram::Immediate>,
147 
148  std::map<int, bool> instructionsNotOwned_;
149 
150  // Pointer to resource manager, needed to get information about
151  // immediate from IUBroker
154 };
155 
156 #endif
ITemplateBroker::instructions_
std::map< int, TTAProgram::Instruction * > instructions_
cycle/instruction
Definition: ITemplateBroker.hh:135
ITemplateBroker::assignImmediate
void assignImmediate(int, std::shared_ptr< TTAProgram::Immediate >)
Definition: ITemplateBroker.cc:300
ITemplateBroker::isTemplateAvailable
virtual bool isTemplateAvailable(int, std::shared_ptr< TTAProgram::Immediate >) const
Definition: ITemplateBroker.cc:948
ITemplateBroker::setupResourceLinks
virtual void setupResourceLinks(const ResourceMapper &mapper) override
Definition: ITemplateBroker.cc:625
TTAProgram
Definition: Estimator.hh:65
ITemplateBroker::busBroker_
BusBroker & busBroker_
Definition: ITemplateBroker.hh:153
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAMachine::Bus
Definition: Bus.hh:53
ITemplateBroker::isITemplateBroker
virtual bool isITemplateBroker() const override
Definition: ITemplateBroker.cc:681
ITemplateBroker::oldParentInstruction_
std::map< const MoveNode *, TTAProgram::Instruction *, MoveNode::Comparator > oldParentInstruction_
MoveNode/ original parent instruction.
Definition: ITemplateBroker.hh:138
ResourceBroker
Definition: ResourceBroker.hh:61
ITemplateBroker::allAvailableResources
virtual SchedulingResourceSet allAvailableResources(int, const MoveNode &, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcUnit, const TTAMachine::FunctionUnit *dstUnit, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const override
Definition: ITemplateBroker.cc:144
MoveNode
Definition: MoveNode.hh:65
ITemplateBroker::ITemplateBroker
ITemplateBroker(std::string, BusBroker &busBroker, unsigned int initiationInterval=0)
Definition: ITemplateBroker.cc:68
ImmediateUnit.hh
ITemplateBroker
Definition: ITemplateBroker.hh:65
ITemplateBroker::assign
virtual void assign(int cycle, MoveNode &node, SchedulingResource &res, int immWriteCycle, int immRegIndex) override
Definition: ITemplateBroker.cc:180
SchedulingResourceSet
Definition: SchedulingResource.hh:161
ITemplateBroker::latestCycle
virtual int latestCycle(int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcUnit, const TTAMachine::FunctionUnit *dstUnit, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const override
Definition: ITemplateBroker.cc:521
ITemplateBroker::findITemplates
SchedulingResourceSet findITemplates(int, Moves &, Immediates &) const
Definition: ITemplateBroker.cc:738
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
BusBroker
Definition: BusBroker.hh:60
ITemplateBroker::loseInstructionOwnership
virtual void loseInstructionOwnership(int cycle)
Definition: ITemplateBroker.cc:908
ITemplateBroker::isApplicable
virtual bool isApplicable(const MoveNode &node, const TTAMachine::Bus *) const override
Definition: ITemplateBroker.cc:582
SchedulingResource
Definition: SchedulingResource.hh:52
GraphNode::Comparator
Definition: GraphNode.hh:56
ITemplateBroker::Moves
std::vector< std::shared_ptr< const TTAProgram::Move > > Moves
Definition: ITemplateBroker.hh:123
ITemplateBroker::buildResources
virtual void buildResources(const TTAMachine::Machine &target) override
Definition: ITemplateBroker.cc:596
ITemplateBroker::reselectTemplate
void reselectTemplate(TTAProgram::Instruction &ins, int cycle)
Definition: ITemplateBroker.cc:470
ITemplateBroker::isAlreadyAssigned
virtual bool isAlreadyAssigned(int cycle, const MoveNode &node, const TTAMachine::Bus *preassignedBus) const override
Definition: ITemplateBroker.cc:544
ITemplateBroker::isAnyResourceAvailable
virtual bool isAnyResourceAvailable(int, const MoveNode &, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const override
Definition: ITemplateBroker.cc:115
ResourceBroker.hh
ITemplateBroker::rm_
SimpleResourceManager * rm_
Definition: ITemplateBroker.hh:152
ITemplateBroker::instructionsNotOwned_
std::map< int, bool > instructionsNotOwned_
Definition: ITemplateBroker.hh:148
ITemplateBroker::instruction
virtual TTAProgram::Instruction * instruction(int cycle)
Definition: ITemplateBroker.cc:693
ResourceMapper
Definition: ResourceMapper.hh:51
ITemplateBroker::clear
void clear() override
Definition: ITemplateBroker.cc:976
SimpleResourceManager
Definition: SimpleResourceManager.hh:58
ITemplateBroker::~ITemplateBroker
virtual ~ITemplateBroker()
Definition: ITemplateBroker.cc:89
ITemplateBroker::clearOldResources
void clearOldResources()
Definition: ITemplateBroker.cc:966
ITemplateBroker::unassignImmediate
void unassignImmediate(int, const TTAMachine::ImmediateUnit &)
Definition: ITemplateBroker.cc:440
TTAMachine
Definition: Assembler.hh:48
ITemplateBroker::unassign
virtual void unassign(MoveNode &node) override
Definition: ITemplateBroker.cc:381
ITemplateBroker::immediateCycles_
std::map< const MoveNode *, int, GraphNode::Comparator > immediateCycles_
Record cycle for MoveNodes that needed immediate writes, IU broker restores immediates before the tem...
Definition: ITemplateBroker.hh:144
ITemplateBroker::Immediates
std::vector< std::shared_ptr< const TTAProgram::Immediate > > Immediates
Definition: ITemplateBroker.hh:124
ITemplateBroker::earliestCycle
virtual int earliestCycle(int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcUnit, const TTAMachine::FunctionUnit *dstUnit, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const override
Definition: ITemplateBroker.cc:500
ITemplateBroker::immediateValues_
std::map< const MoveNode *, std::shared_ptr< TTAProgram::Immediate >, GraphNode::Comparator > immediateValues_
Definition: ITemplateBroker.hh:146
ITemplateBroker::slots_
std::vector< TTAMachine::Bus * > slots_
Move/immediate slots.
Definition: ITemplateBroker.hh:133
TTAMachine::Machine
Definition: Machine.hh:73
ITemplateBroker::isImmediateInTemplate
bool isImmediateInTemplate(int, std::shared_ptr< TTAProgram::Immediate >) const
Definition: ITemplateBroker.cc:920
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50