OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
BusBroker Class Reference

#include <BusBroker.hh>

Inheritance diagram for BusBroker:
Inheritance graph
Collaboration diagram for BusBroker:
Collaboration graph

Public Member Functions

 BusBroker (std::string name, ResourceBroker &ipBroker, ResourceBroker &opBroker, const TTAMachine::Machine &mach, unsigned int initiationInterval=0)
 
virtual ~BusBroker ()
 
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 override
 
virtual SchedulingResourceavailableResource (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 override
 
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 override
 
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 override
 
virtual void assign (int cycle, MoveNode &node, SchedulingResource &res, int immWriteCycle, int immRegIndex) override
 
virtual void unassign (MoveNode &node)
 
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 override
 
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 override
 
virtual bool isAlreadyAssigned (int cycle, const MoveNode &node, const TTAMachine::Bus *preassignedBus) const override
 
virtual bool isApplicable (const MoveNode &node, const TTAMachine::Bus *) const override
 
virtual void buildResources (const TTAMachine::Machine &target)
 
virtual void setupResourceLinks (const ResourceMapper &mapper)
 
virtual bool isBusBroker () const
 
virtual bool canTransportImmediate (const MoveNode &node, const TTAMachine::Bus *preAssigndBus) const
 
virtual bool isInUse (int cycle, const MoveNode &node) const
 
virtual bool hasGuard (const MoveNode &node) const
 
void clear () override
 
void setCFG (const ControlFlowGraph *cfg)
 
void setBBN (const BasicBlockNode *bbn)
 
- Public Member Functions inherited from ResourceBroker
 ResourceBroker (std::string, unsigned int initiationInterval=0)
 
virtual ~ResourceBroker ()
 
SchedulingResourceresourceOf (const TTAMachine::MachinePart &mp) const
 
virtual const TTAMachine::MachinePartmachinePartOf (const SchedulingResource &r) const
 
bool hasResourceOf (const TTAMachine::MachinePart &mp) const
 
bool hasResource (const SchedulingResource &r) const
 
int resourceCount () const
 
virtual bool isITemplateBroker () const
 
virtual bool isIUBroker () const
 
virtual bool isExecutionPipelineBroker () const
 
void validateResources () const
 
virtual std::string brokerName () const
 
void resources (ResourceSet &contents)
 
virtual void setInitiationInterval (unsigned int cycles)
 
virtual void setMaxCycle (unsigned int)
 

Private Member Functions

bool jumpToBBN (const MoveNode &mn, BasicBlockNode &bbn) const
 
bool canPerformSIMMJump (const MoveNode &mn, ShortImmPSocketResource &immRes) const
 
virtual bool canTransportImmediate (const MoveNode &node, ShortImmPSocketResource &immRes) const
 
virtual ShortImmPSocketResourcefindImmResource (BusResource &busRes) const
 

Private Attributes

std::list< SchedulingResource * > shortImmPSocketResources_
 
std::map< const MoveNode *, bool > busPreassigned_
 
ResourceBrokerinputPSocketBroker_
 
ResourceBrokeroutputPSocketBroker_
 
bool hasLimm_
 
const TTAMachine::Machinemach_
 
const ControlFlowGraphcfg_
 
const BasicBlockNodebbn_
 

Additional Inherited Members

- Public Types inherited from ResourceBroker
typedef std::set< SchedulingResource * > ResourceSet
 
- Protected Types inherited from ResourceBroker
typedef std::map< const TTAMachine::MachinePart *, SchedulingResource *, TTAMachine::MachinePart::ComparatorResourceMap
 
typedef std::map< const MoveNode *, SchedulingResource *, MoveNode::ComparatorMoveResMap
 
- Protected Member Functions inherited from ResourceBroker
void setResourceMapper (const ResourceMapper &mapper)
 
const ResourceMapperresourceMapper () const
 
unsigned int instructionIndex (unsigned int) const
 
void addResource (const TTAMachine::MachinePart &mp, SchedulingResource *res)
 
- Protected Attributes inherited from ResourceBroker
unsigned int initiationInterval_
 
ResourceMap resMap_
 
const ResourceMapperresourceMapper_
 
MoveResMap assignedResources_
 
std::string brokerName_
 

Detailed Description

Bus broker.

Definition at line 60 of file BusBroker.hh.

Constructor & Destructor Documentation

◆ BusBroker()

BusBroker::BusBroker ( std::string  name,
ResourceBroker ipBroker,
ResourceBroker opBroker,
const TTAMachine::Machine mach,
unsigned int  initiationInterval = 0 
)

Constructor.

Parameters
namename for this broker.
ipsbreference to InputPSocketBroker of this RM.
opsbreference to OutputPSocketBroker of this RM.
initiationIntervalinitiationinterval when doing loop scheduling.

Definition at line 73 of file BusBroker.cc.

78 :
79 ResourceBroker(name, initiationInterval), inputPSocketBroker_(ipBroker),
80 outputPSocketBroker_(opBroker), hasLimm_(false), mach_(&mach) {
81}
const TTAMachine::Machine * mach_
Definition BusBroker.hh:151
bool hasLimm_
Definition BusBroker.hh:150
ResourceBroker & outputPSocketBroker_
Definition BusBroker.hh:149
ResourceBroker & inputPSocketBroker_
Definition BusBroker.hh:148

◆ ~BusBroker()

BusBroker::~BusBroker ( )
virtual

Destructor.

Definition at line 86 of file BusBroker.cc.

86 {
88}
std::list< SchedulingResource * > shortImmPSocketResources_
Definition BusBroker.hh:146
static void deleteAllItems(SequenceType &aSequence)

References SequenceTools::deleteAllItems(), and shortImmPSocketResources_.

Here is the call graph for this function:

Member Function Documentation

◆ allAvailableResources()

SchedulingResourceSet BusBroker::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
overridevirtual

Return all resources managed by this broker that can be assigned to the given node in the given cycle.

Parameters
cycleCycle.
nodeNode.
busif not null, bus that has to be used.
srcFUif not null, srcFu that has to be used.
dstFUif not null, dstFU that has to be used.
immWriteCycleif not -1 and src is imm, write cycle of limm.
Returns
All resources managed by this broker that can be assigned to the given node in the given cycle.

Reimplemented from ResourceBroker.

Definition at line 178 of file BusBroker.cc.

184 {
185
186 cycle = instructionIndex(cycle);
187 SchedulingResourceSet candidates;
188
189 Move& move = const_cast<MoveNode&>(node).move();
190 const Port* dstPort = &move.destination().port();
191 Socket* inputSocket = dstPort->inputSocket();
192
193 // In case bus was already assigned previously, pick only relevant resource.
195 BusResource* preassignedBus = NULL;
196 if (&move.bus() != &um.universalBus()) {
197 preassignedBus = dynamic_cast<BusResource*>(resourceOf(move.bus()));
198 }
199 if (bus != NULL) {
200 preassignedBus = dynamic_cast<BusResource*>(resourceOf(*bus));
201 }
202
203 if (inputSocket == NULL) {
204 string unit = dstPort->parentUnit()->name();
205 string port = dstPort->name();
206 string msg =
207 "Tried to find bus for a move to '" + unit + "." + port +
208 "' which has no connections to an input socket. "
209 "Check operation bindings!";
210 throw ModuleRunTimeError(__FILE__, __LINE__, __func__, msg);
211 }
212
213 InputPSocketResource* iPSocket = NULL;
214 try {
215 iPSocket =
216 static_cast<InputPSocketResource*>(
217 inputPSocketBroker_.resourceOf(*inputSocket));
218 } catch (const KeyNotFound& e) {
219 std::string msg = "BusBroker: finding ";
220 msg += " resource for Socket ";
221 msg += " failed with error: ";
222 msg += e.errorMessageStack();
223 throw KeyNotFound(
224 __FILE__, __LINE__, __func__, msg);
225 }
226
227 OutputPSocketResource* oPSocket = NULL;
228
229 if (move.source().isImmediate()) {
230
231 // find a bus with appropriate immediate width that is connected to
232 // destination
233 ResourceMap::const_iterator resIter = resMap_.begin();
234 while (resIter != resMap_.end()) {
235 // look for bus resources with appropriate related shortimmsocket
236 // resources
237 BusResource* busRes =
238 static_cast<BusResource*>((*resIter).second);
239 if (busRes == NULL) {
240 throw InvalidData(
241 __FILE__, __LINE__, __func__,
242 "Bus broker has other then Bus Resource registered!");
243 }
244
245 ShortImmPSocketResource& immRes = findImmResource(*busRes);
246 if (preassignedBus == NULL || busRes == preassignedBus) {
247 if (canTransportImmediate(node, immRes) &&
248 busRes->canAssign(cycle, node, immRes, *iPSocket)) {
249 candidates.insert(*busRes);
250 }
251 }
252 resIter++;
253 }
254
255 } else {
256
257 const Port* srcPort = &move.source().port();
258 Socket* outputSocket = srcPort->outputSocket();
259 if (outputSocket == NULL) {
260 string unit = srcPort->parentUnit()->name();
261 string port = srcPort->name();
262 string msg =
263 "Tried to find bus for a move from '" + unit + "." + port +
264 "' which has no connections to an output socket! Check "
265 "operation bindings!";
266 throw ModuleRunTimeError(__FILE__, __LINE__, __func__, msg);
267 }
268
269 oPSocket = NULL;
270 try {
271 oPSocket =
272 static_cast<OutputPSocketResource*>(
273 outputPSocketBroker_.resourceOf(*outputSocket));
274 } catch (const KeyNotFound& e) {
275 std::string msg = "BusBroker: finding ";
276 msg += " resource for Socket ";
277 msg += " failed with error: ";
278 msg += e.errorMessageStack();
279 throw KeyNotFound(
280 __FILE__, __LINE__, __func__, msg);
281 }
282
283 ResourceMap::const_iterator resIter = resMap_.begin();
284 while (resIter != resMap_.end()) {
285 BusResource* busRes =
286 static_cast<BusResource*>((*resIter).second);
287 if (preassignedBus == NULL ||
288 busRes == preassignedBus) {
289 if (busRes->canAssign(cycle, node, *oPSocket, *iPSocket)) {
290 candidates.insert(*busRes);
291 }
292 }
293 resIter++;
294 }
295 }
296 if (!move.isUnconditional()) {
297
298 const Guard& guard = move.guard().guard();
299 for (int i = 0; i < candidates.count(); i++) {
300 SchedulingResource& busResource = candidates.resource(i);
301 const Bus* aBus =
302 static_cast<const Bus*>(&machinePartOf(busResource));
303 if (aBus == NULL) {
304 throw InvalidData(
305 __FILE__, __LINE__, __func__,
306 "Bus Resource is missing bus in MOM!");
307 }
308
309 bool guardFound = false;
310 for (int j = 0; j < aBus->guardCount(); j++) {
311 Guard* busGuard = aBus->guard(j);
312 if (busGuard->isEqual(guard)) {
313 guardFound = true;
314 break;
315 }
316 }
317
318 if (!guardFound) {
319 candidates.remove(busResource);
320 i--;
321 }
322 }
323 }
324 return candidates;
325}
#define __func__
virtual ShortImmPSocketResource & findImmResource(BusResource &busRes) const
Definition BusBroker.cc:846
virtual bool canTransportImmediate(const MoveNode &node, const TTAMachine::Bus *preAssigndBus) const
Definition BusBroker.cc:756
virtual bool canAssign(const int cycle, const MoveNode &node) const override
std::string errorMessageStack(bool messagesOnly=false) const
Definition Exception.cc:138
SchedulingResource * resourceOf(const TTAMachine::MachinePart &mp) const
unsigned int instructionIndex(unsigned int) const
virtual const TTAMachine::MachinePart & machinePartOf(const SchedulingResource &r) const
ResourceMap resMap_
void remove(SchedulingResource &resource)
SchedulingResource & resource(int index) const
void insert(SchedulingResource &resource)
Guard * guard(int index) const
Definition Bus.cc:456
int guardCount() const
Definition Bus.cc:441
virtual TCEString name() const
virtual bool isEqual(const Guard &guard) const =0
virtual Socket * outputSocket() const
Definition Port.cc:281
Unit * parentUnit() const
virtual Socket * inputSocket() const
Definition Port.cc:261
virtual std::string name() const
Definition Port.cc:141
const TTAMachine::Guard & guard() const
Definition MoveGuard.cc:86
MoveGuard & guard() const
Definition Move.cc:345
bool isUnconditional() const
Definition Move.cc:154
Terminal & source() const
Definition Move.cc:302
Terminal & destination() const
Definition Move.cc:323
const TTAMachine::Bus & bus() const
Definition Move.cc:373
virtual const TTAMachine::Port & port() const
Definition Terminal.cc:378
virtual bool isImmediate() const
Definition Terminal.cc:63
static UniversalMachine & instance()
TTAMachine::Bus & universalBus() const

References __func__, TTAProgram::Move::bus(), BusResource::canAssign(), canTransportImmediate(), SchedulingResourceSet::count(), TTAProgram::Move::destination(), Exception::errorMessageStack(), findImmResource(), TTAProgram::Move::guard(), TTAProgram::MoveGuard::guard(), TTAMachine::Bus::guard(), TTAMachine::Bus::guardCount(), inputPSocketBroker_, TTAMachine::Port::inputSocket(), SchedulingResourceSet::insert(), UniversalMachine::instance(), ResourceBroker::instructionIndex(), TTAMachine::Guard::isEqual(), TTAProgram::Terminal::isImmediate(), TTAProgram::Move::isUnconditional(), ResourceBroker::machinePartOf(), TTAMachine::Component::name(), TTAMachine::Port::name(), outputPSocketBroker_, TTAMachine::Port::outputSocket(), TTAMachine::Port::parentUnit(), TTAProgram::Terminal::port(), SchedulingResourceSet::remove(), ResourceBroker::resMap_, SchedulingResourceSet::resource(), ResourceBroker::resourceOf(), TTAProgram::Move::source(), and UniversalMachine::universalBus().

Referenced by availableResource(), and isAnyResourceAvailable().

Here is the call graph for this function:

◆ assign()

void BusBroker::assign ( int  cycle,
MoveNode node,
SchedulingResource res,
int  immWriteCycle,
int  immRegIndex 
)
overridevirtual

Mark given resource as in use for the given node, and assign the corresponding machine part (if applicable) to the node's move.

If the node is already assigned to given resource, this method does nothing.

Parameters
cycleCycle for which to assign bus
nodeNode which will be transfered using a bus
resResourceObject referring to particular bus to assign
Exceptions
WrongSubclassIf this broker does not recognise the given type of resource.
InvalidParametersIf he given resource cannot be assigned to given node or no corresponding machine part is found.

Implements ResourceBroker.

Definition at line 474 of file BusBroker.cc.

475 {
476
477 cycle = instructionIndex(cycle);
478 BusResource& busRes = static_cast<BusResource&>(res);
479 Move& move = const_cast<MoveNode&>(node).move();
480 if (hasResource(res)) {
481 Bus& bus =
482 const_cast<Bus&>(static_cast<const Bus&>(machinePartOf(res)));
483
485 if (&move.bus() != &um.universalBus()) {
486 busPreassigned_[&node] = true;
487 assert(&bus == &move.bus() &&
488 "preassigned bus which is different than selected bus?");
489 } else {
490 move.setBus(bus);
491 busPreassigned_[&node] = false;
492 }
493 if (!move.isUnconditional()) {
494 for (int j = 0; j < bus.guardCount(); j++) {
495 Guard* busGuard = bus.guard(j);
496 if (busGuard->isEqual(move.guard().guard())) {
497 move.setGuard(new MoveGuard(*busGuard));
498 break;
499 }
500 }
501 }
502 busRes.assign(cycle,node);
503 } else {
504 string msg = "Broker does not contain given resource.";
505 throw InvalidData(__FILE__, __LINE__, __func__, msg);
506 }
507 assignedResources_.insert(
508 std::pair<const MoveNode*, SchedulingResource*>(&node, &busRes));
509}
#define assert(condition)
std::map< const MoveNode *, bool > busPreassigned_
Definition BusBroker.hh:147
virtual void assign(const int cycle, MoveNode &node) override
MoveResMap assignedResources_
bool hasResource(const SchedulingResource &r) const
void setGuard(MoveGuard *guard)
Definition Move.cc:360
void setBus(const TTAMachine::Bus &bus)
Definition Move.cc:383

References __func__, assert, BusResource::assign(), ResourceBroker::assignedResources_, TTAProgram::Move::bus(), busPreassigned_, TTAProgram::Move::guard(), TTAProgram::MoveGuard::guard(), TTAMachine::Bus::guard(), TTAMachine::Bus::guardCount(), ResourceBroker::hasResource(), UniversalMachine::instance(), ResourceBroker::instructionIndex(), TTAMachine::Guard::isEqual(), TTAProgram::Move::isUnconditional(), ResourceBroker::machinePartOf(), TTAProgram::Move::setBus(), TTAProgram::Move::setGuard(), and UniversalMachine::universalBus().

Here is the call graph for this function:

◆ availableResource()

SchedulingResource & BusBroker::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
overridevirtual

Return one (any) resource managed by this broker that can be assigned to the given node in the given cycle.

If no change occurs to the state of the resources, the broker should always return the same object. If a resource of the type managed by this broker is already assigned to the node, it is returned.

Parameters
cycleCycle.
nodeNode.
busif not null, bus that has to be used.
srcFUif not null, srcFu that has to be used.
dstFUif not null, dstFU that has to be used.
immWriteCycleif not -1 and src is imm, write cycle of limm.
Returns
One (any) resource managed by this broker that can be assigned to the given node in the given cycle.
Exceptions
InstanceNotFoundIf no available resource is found.

Reimplemented from ResourceBroker.

Definition at line 141 of file BusBroker.cc.

147 {
148
149 cycle = instructionIndex(cycle);
150 SchedulingResourceSet allAvailableBuses =
151 allAvailableResources(cycle, node, bus, srcFU, dstFU, immWriteCycle,
152 immu, immRegIndex);
153 if (allAvailableBuses.count() == 0) {
154 string msg = "No available resource found.";
155 throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
156 } else {
157 if (bus != NULL) {
158 assert(allAvailableBuses.count() == 1);
159 }
160 return allAvailableBuses.resource(0);
161 }
162}
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 override
Definition BusBroker.cc:178

References __func__, allAvailableResources(), assert, SchedulingResourceSet::count(), ResourceBroker::instructionIndex(), and SchedulingResourceSet::resource().

Here is the call graph for this function:

◆ buildResources()

void BusBroker::buildResources ( const TTAMachine::Machine target)
virtual

Build all resource objects of the controlled type required to model scheduling resources of the given target processor.

This method cannot set up the resource links (dependent and related resources) of the constructed resource objects.

Parameters
targetTarget machine.

Implements ResourceBroker.

Definition at line 646 of file BusBroker.cc.

646 {
647 hasLimm_ = target.immediateUnitNavigator().count() > 0;
648 Machine::BusNavigator navi = target.busNavigator();
651
652 std::map<const Bus*,int> limmSlotCounts;
653 std::map<const Bus*,int> nopSlotCounts;
654
655 // calculate count of limm slots and nop slots associated with each bus.
656 // used to priorize busses which do not get into way of limm writes.
657 for (int i = 0; i < itn.count(); i++) {
658 InstructionTemplate* it = itn.item(i);
659 for (int j = 0; j < it->slotCount(); j++) {
660 TemplateSlot* itSlot = it->slot(j);
661 if (itSlot->destination() != NULL) {
662 limmSlotCounts[itSlot->bus()]++;
663 }
664 }
665 }
666
667 for (int i = 0; i < navi.count(); i++) {
668 Bus* bus = navi.item(i);
669 assert(bus->segmentCount() == 1);
670 int socketCount = bus->segment(0)->connectionCount();
671 BusResource* busResource = new BusResource(
672 bus->name(), bus->width(),limmSlotCounts[bus],
673 nopSlotCounts[bus], bus->guardCount(),
674 bus->immediateWidth(), socketCount, initiationInterval_);
675 ResourceBroker::addResource(*bus, busResource);
676 }
677}
void addResource(const TTAMachine::MachinePart &mp, SchedulingResource *res)
unsigned int initiationInterval_
virtual Segment * segment(int index) const
Definition Bus.cc:329
int width() const
Definition Bus.cc:149
virtual int segmentCount() const
Definition Bus.cc:385
virtual TemplateSlot * slot(int index) const
ComponentType * item(int index) const
virtual InstructionTemplateNavigator instructionTemplateNavigator() const
Definition Machine.cc:428
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
int connectionCount() const
const Bus * bus() const
ImmediateUnit * destination() const

References ResourceBroker::addResource(), assert, TTAMachine::TemplateSlot::bus(), TTAMachine::Machine::busNavigator(), TTAMachine::Segment::connectionCount(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::TemplateSlot::destination(), TTAMachine::Bus::guardCount(), hasLimm_, TTAMachine::Machine::immediateUnitNavigator(), TTAMachine::Bus::immediateWidth(), ResourceBroker::initiationInterval_, TTAMachine::Machine::instructionTemplateNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::name(), TTAMachine::Bus::segment(), TTAMachine::Bus::segmentCount(), TTAMachine::InstructionTemplate::slot(), TTAMachine::InstructionTemplate::slotCount(), and TTAMachine::Bus::width().

Here is the call graph for this function:

◆ canPerformSIMMJump()

bool BusBroker::canPerformSIMMJump ( const MoveNode mn,
ShortImmPSocketResource immRes 
) const
private

Definition at line 801 of file BusBroker.cc.

802 {
803 return false; // WiP.
804}

Referenced by canTransportImmediate().

◆ canTransportImmediate() [1/2]

bool BusBroker::canTransportImmediate ( const MoveNode node,
const TTAMachine::Bus preassignedBus 
) const
virtual

Return true if immediate in given node can be transported by any bus in broker, with the guard which the move contains.

Parameters
nodeNode that contains immediate read.
Returns
True if immediate in given node can be transported by any bus in broker.

Definition at line 756 of file BusBroker.cc.

757 {
758 ResourceMap::const_iterator resIter = resMap_.begin();
759 while (resIter != resMap_.end()) {
760 BusResource* busRes = static_cast<BusResource*>((*resIter).second);
761 ShortImmPSocketResource* immRes = &findImmResource(*busRes);
762 const Bus* aBus = static_cast<const Bus*>(resIter->first);
763 if (preassignedBus != NULL && aBus != preassignedBus) {
764 resIter++;
765 continue;
766 }
767 if (canTransportImmediate(node, *immRes)) {
768 bool guardOK = false;
769 if (node.move().isUnconditional()) {
770 guardOK = true;
771 } else {
772 // We need to check that the bus contains the guard
773 // which the move has. Only return true if the
774 // guard is found from the bus.
775 const Guard& guard = node.move().guard().guard();
776 for (int j = 0; j < aBus->guardCount(); j++) {
777 Guard* busGuard = aBus->guard(j);
778 if (busGuard->isEqual(guard)) {
779 guardOK = true;
780 break;
781 }
782 }
783 }
784 if (guardOK) {
785 if (!hasLimm_) {
786 return true;
787 } else {
789 *aBus, node)) {
790 return true;
791 }
792 }
793 }
794 }
795 resIter++;
796 }
797 return false;
798}
static bool busConnectedToDestination(const TTAMachine::Bus &bus, const MoveNode &moveNode)
TTAProgram::Move & move()

References MachineConnectivityCheck::busConnectedToDestination(), canTransportImmediate(), findImmResource(), TTAProgram::Move::guard(), TTAProgram::MoveGuard::guard(), TTAMachine::Bus::guard(), TTAMachine::Bus::guardCount(), hasLimm_, TTAMachine::Guard::isEqual(), TTAProgram::Move::isUnconditional(), MoveNode::move(), and ResourceBroker::resMap_.

Referenced by allAvailableResources(), canTransportImmediate(), SimpleBrokerDirector::canTransportImmediate(), and isAvailable().

Here is the call graph for this function:

◆ canTransportImmediate() [2/2]

bool BusBroker::canTransportImmediate ( const MoveNode node,
ShortImmPSocketResource immRes 
) const
privatevirtual

Return true if immediate in given node can be transported by bus that is represented by given p-socket resource.

Parameters
nodeNode that contains immediate read.
immResP-socket resource representing write if immediate to related bus.
Returns
True if immediate in given node can be transported by bus that is represented by given p-socket resource.

Definition at line 817 of file BusBroker.cc.

819 {
820
821 Move& move = const_cast<MoveNode&>(node).move();
822
823 if (move.isJump() && canPerformSIMMJump(node, immRes)) {
824 return true;
825 }
826
828 immRes.signExtends(),
829 static_cast<const TTAProgram::TerminalImmediate&>(move.source()),
830 *mach_);
831
832 if (bits <= immRes.immediateWidth()) {
833 return true;
834 } else {
835 return false;
836 }
837}
bool canPerformSIMMJump(const MoveNode &mn, ShortImmPSocketResource &immRes) const
Definition BusBroker.cc:801
static int requiredImmediateWidth(bool signExtension, const TTAProgram::TerminalImmediate &source, const TTAMachine::Machine &mach)
bool isJump() const
Definition Move.cc:164

References canPerformSIMMJump(), ShortImmPSocketResource::immediateWidth(), TTAProgram::Move::isJump(), mach_, MachineConnectivityCheck::requiredImmediateWidth(), ShortImmPSocketResource::signExtends(), and TTAProgram::Move::source().

Here is the call graph for this function:

◆ clear()

void BusBroker::clear ( )
overridevirtual

Clears all resources managed by the broker so that the broker can be reused.

Reimplemented from ResourceBroker.

Definition at line 889 of file BusBroker.cc.

889 {
891 for (std::list<SchedulingResource*>::iterator i =
893 i != shortImmPSocketResources_.end(); i++) {
894 (*i)->clear();
895 }
896 busPreassigned_.clear();
897}
virtual void clear()

References busPreassigned_, ResourceBroker::clear(), and shortImmPSocketResources_.

Here is the call graph for this function:

◆ earliestCycle()

int BusBroker::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
overridevirtual

Return the earliest cycle, starting from given cycle, where a resource of the type managed by this broker can be assigned to the given node.

Parameters
cycleCycle.
nodeNode.
Returns
The earliest cycle, starting from given cycle, where a resource of the type managed by this broker can be assigned to the given node.

Implements ResourceBroker.

Definition at line 550 of file BusBroker.cc.

554 {
555 abortWithError("Not implemented.");
556 return -1;
557}
#define abortWithError(message)

References abortWithError.

◆ findImmResource()

ShortImmPSocketResource & BusBroker::findImmResource ( BusResource busRes) const
privatevirtual

Return the short immediate p-socket resource related to given bus.

Parameters
busResBus resource.
Returns
The short immediate p-socket resource related to given bus.

Definition at line 846 of file BusBroker.cc.

846 {
847 int i = 0;
848 SchedulingResource* socketRes = NULL;
849 ShortImmPSocketResource* immRes = NULL;
850 while (i < busRes.relatedResourceCount(0)) {
851 socketRes = &busRes.relatedResource(0, i);
852 if (socketRes->isShortImmPSocketResource()) {
853 return *(static_cast<ShortImmPSocketResource*>(socketRes));
854 }
855 i++;
856 }
857 return *immRes;
858}
virtual SchedulingResource & relatedResource(const int group, const int index) const
int relatedResourceCount(const int group) const
virtual bool isShortImmPSocketResource() const

References SchedulingResource::isShortImmPSocketResource(), SchedulingResource::relatedResource(), and SchedulingResource::relatedResourceCount().

Referenced by allAvailableResources(), canTransportImmediate(), and isAvailable().

Here is the call graph for this function:

◆ hasGuard()

bool BusBroker::hasGuard ( const MoveNode node) const
virtual

Tests if any of a buses known to BusBroker supports a guard required by MoveNode.

Parameters
nodeMoveNode to test.
Returns
true if some of the buses supports guard of node.

Definition at line 868 of file BusBroker.cc.

868 {
869 Move& move = const_cast<MoveNode&>(node).move();
870 const Guard& guard = move.guard().guard();
871 ResourceMap::const_iterator resIter = resMap_.begin();
872 while (resIter != resMap_.end()) {
873 SchedulingResource& busResource = *(*resIter).second;
874 const Bus* aBus =
875 static_cast<const Bus*>(&machinePartOf(busResource));
876
877 for (int j = 0; j < aBus->guardCount(); j++) {
878 Guard* busGuard = aBus->guard(j);
879 if (busGuard->isEqual(guard)) {
880 return true;
881 }
882 }
883 resIter++;
884 }
885 return false;
886}

References TTAProgram::Move::guard(), TTAProgram::MoveGuard::guard(), TTAMachine::Bus::guard(), TTAMachine::Bus::guardCount(), TTAMachine::Guard::isEqual(), ResourceBroker::machinePartOf(), and ResourceBroker::resMap_.

Referenced by SimpleBrokerDirector::hasGuard().

Here is the call graph for this function:

◆ isAlreadyAssigned()

bool BusBroker::isAlreadyAssigned ( int  cycle,
const MoveNode node,
const TTAMachine::Bus preassignedBus 
) const
overridevirtual

Return true if the given node is already assigned a resource of the type managed by this broker, and the assignment appears valid (that is, the broker has marked that resource as in use in the given cycle).

Parameters
cycleCycle.
nodeNode.
Returns
True if the given node is already assigned a resource of the type managed by this broker, and the assignment appears valid (that is, the broker has marked that resource as in use in the given cycle).

Implements ResourceBroker.

Definition at line 594 of file BusBroker.cc.

595 {
597 return false;
598 }
599 return isInUse(instructionIndex(cycle),node);
600}
virtual bool isInUse(int cycle, const MoveNode &node) const
Definition BusBroker.cc:612
static bool containsKey(const MapType &aMap, const KeyType &aKey)

References ResourceBroker::assignedResources_, MapTools::containsKey(), ResourceBroker::instructionIndex(), and isInUse().

Here is the call graph for this function:

◆ isAnyResourceAvailable()

bool BusBroker::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
overridevirtual

Return true if one of the resources managed by this broker is suitable for the request contained in the node and can be assigned to it in given cycle.

Parameters
cycleCycle.
nodeNode.
busif not null, bus that has to be used.
srcFUif not null, srcFu that has to be used.
dstFUif not null, dstFU that has to be used.
immWriteCycleif not -1 and src is imm, write cycle of limm.
Returns
True if one of the resources managed by this broker is suitable for the request contained in the node and can be assigned to it in given cycle.

Reimplemented from ResourceBroker.

Definition at line 106 of file BusBroker.cc.

112 {
113
114 cycle = instructionIndex(cycle);
115 SchedulingResourceSet allAvailableBuses =
117 cycle, node, bus, srcFU, dstFU, immWriteCycle, immu, immRegIndex);
118 return allAvailableBuses.count() > 0;
119}

References allAvailableResources(), SchedulingResourceSet::count(), and ResourceBroker::instructionIndex().

Here is the call graph for this function:

◆ isApplicable()

bool BusBroker::isApplicable ( const MoveNode mn,
const TTAMachine::Bus  
) const
overridevirtual

Return true if the given node needs a resource of the type managed by this broker, false otherwise.

Parameters
nodeNode.
Returns
True if the given node needs a resource of the type managed by this broker, false otherwise.

Implements ResourceBroker.

Definition at line 632 of file BusBroker.cc.

632 {
633 return mn.isMove();
634}
bool isMove() const

References MoveNode::isMove().

Here is the call graph for this function:

◆ isAvailable()

bool BusBroker::isAvailable ( SchedulingResource res,
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
overridevirtual

Tells whether the given resource is available for given node at given cycle.

Reimplemented from ResourceBroker.

Definition at line 332 of file BusBroker.cc.

338 {
339
340 if (bus != NULL && resourceOf(*bus) != &res) {
341 return false;
342 }
343 cycle = instructionIndex(cycle);
344
345 Move& move = const_cast<MoveNode&>(node).move();
346 const Port* dstPort = &move.destination().port();
347 Socket* inputSocket = dstPort->inputSocket();
348
349 if (inputSocket == NULL) {
350 string unit = dstPort->parentUnit()->name();
351 string port = dstPort->name();
352 string msg =
353 "Tried to find bus for a move to '" + unit + "." + port +
354 "' which has no connections to an input socket. "
355 "Check operation bindings!";
356 throw ModuleRunTimeError(__FILE__, __LINE__, __func__, msg);
357 }
358
359 InputPSocketResource* iPSocket = NULL;
360 try {
361 iPSocket =
362 static_cast<InputPSocketResource*>(
363 inputPSocketBroker_.resourceOf(*inputSocket));
364 } catch (const KeyNotFound& e) {
365 std::string msg = "BusBroker: finding ";
366 msg += " resource for Socket ";
367 msg += " failed with error: ";
368 msg += e.errorMessageStack();
369 throw KeyNotFound(
370 __FILE__, __LINE__, __func__, msg);
371 }
372
373 OutputPSocketResource* oPSocket = NULL;
374
375 if (move.source().isImmediate()) {
376
377 // look for bus resources with appropriate related shortimmsocket
378 // resources
379 BusResource* busRes =
380 dynamic_cast<BusResource*>(&res);
381 if (busRes == NULL) {
382 throw InvalidData(
383 __FILE__, __LINE__, __func__,
384 "Wrong type of resource for the broker given!");
385 }
386
387 ShortImmPSocketResource& immRes = findImmResource(*busRes);
388 if (!canTransportImmediate(node, immRes) &&
389 busRes->canAssign(cycle, node, immRes, *iPSocket)) {
390 return false;
391 }
392 } else {
393 const Port* srcPort = &move.source().port();
394 Socket* outputSocket = srcPort->outputSocket();
395 if (outputSocket == NULL) {
396 string unit = srcPort->parentUnit()->name();
397 string port = srcPort->name();
398 string msg =
399 "Tried to find bus for a move from '" + unit + "." + port +
400 "' which has no connections to an output socket! Check "
401 "operation bindings!";
402 throw ModuleRunTimeError(__FILE__, __LINE__, __func__, msg);
403 }
404
405 oPSocket = NULL;
406 try {
407 oPSocket =
408 static_cast<OutputPSocketResource*>(
409 outputPSocketBroker_.resourceOf(*outputSocket));
410 } catch (const KeyNotFound& e) {
411 std::string msg = "BusBroker: finding ";
412 msg += " resource for Socket ";
413 msg += " failed with error: ";
414 msg += e.errorMessageStack();
415 throw KeyNotFound(
416 __FILE__, __LINE__, __func__, msg);
417 }
418
419 BusResource* busRes =
420 dynamic_cast<BusResource*>(&res);
421 if (busRes == NULL) {
422 throw InvalidData(
423 __FILE__, __LINE__, __func__,
424 "Wrong type of resource for the broker given!");
425 }
426
427 if (!busRes->canAssign(cycle, node, *oPSocket, *iPSocket)) {
428 return false;
429 }
430 }
431 if (!move.isUnconditional()) {
432
433 const Guard& guard = move.guard().guard();
434 const Bus* aBus =
435 dynamic_cast<const Bus*>(&machinePartOf(res));
436 if (aBus == NULL) {
437 throw InvalidData(
438 __FILE__, __LINE__, __func__,
439 "Bus Resource is missing bus in MOM!");
440 }
441
442 bool guardFound = false;
443 for (int j = 0; j < aBus->guardCount(); j++) {
444 Guard* busGuard = aBus->guard(j);
445 if (busGuard->isEqual(guard)) {
446 guardFound = true;
447 break;
448 }
449 }
450
451 if (!guardFound) {
452 return false;
453 }
454 }
455 return true;
456}

References __func__, BusResource::canAssign(), canTransportImmediate(), TTAProgram::Move::destination(), Exception::errorMessageStack(), findImmResource(), TTAProgram::Move::guard(), TTAProgram::MoveGuard::guard(), TTAMachine::Bus::guard(), TTAMachine::Bus::guardCount(), inputPSocketBroker_, TTAMachine::Port::inputSocket(), ResourceBroker::instructionIndex(), TTAMachine::Guard::isEqual(), TTAProgram::Terminal::isImmediate(), TTAProgram::Move::isUnconditional(), ResourceBroker::machinePartOf(), TTAMachine::Component::name(), TTAMachine::Port::name(), outputPSocketBroker_, TTAMachine::Port::outputSocket(), TTAMachine::Port::parentUnit(), TTAProgram::Terminal::port(), ResourceBroker::resourceOf(), and TTAProgram::Move::source().

Here is the call graph for this function:

◆ isBusBroker()

bool BusBroker::isBusBroker ( ) const
virtual

Return true always.

Returns
True always.

Reimplemented from ResourceBroker.

Definition at line 743 of file BusBroker.cc.

743 {
744 return true;
745}

◆ isInUse()

bool BusBroker::isInUse ( int  cycle,
const MoveNode node 
) const
virtual

Return true if given node already uses a resource of the type managed by this broker and assignment appears to be valid.

Parameters
cycleCycle to test
nodeNode to test
Returns
True if given node already uses a resource of the type managed by the broker.

Definition at line 612 of file BusBroker.cc.

612 {
613 cycle = instructionIndex(cycle);
614 const Bus& bus = const_cast<MoveNode&>(node).move().bus();
615 if (!hasResourceOf(bus)) {
616 return false;
617 }
618
619 SchedulingResource* res = resourceOf(bus);
620 BusResource& busRes = static_cast<BusResource&>(*res);
621 return busRes.isInUse(cycle);
622}
virtual bool isInUse(const int cycle) const override
bool hasResourceOf(const TTAMachine::MachinePart &mp) const

References ResourceBroker::hasResourceOf(), ResourceBroker::instructionIndex(), BusResource::isInUse(), and ResourceBroker::resourceOf().

Referenced by isAlreadyAssigned().

Here is the call graph for this function:

◆ jumpToBBN()

bool BusBroker::jumpToBBN ( const MoveNode mn,
BasicBlockNode bbn 
) const
private

◆ latestCycle()

int BusBroker::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
overridevirtual

Return the latest cycle, starting from given cycle, where a resource of the type managed by this broker can be assigned to the given node.

Parameters
cycleCycle.
nodeNode.
Returns
The latest cycle, starting from given cycle, where a resource of the type managed by this broker can be assigned to the given node.

Implements ResourceBroker.

Definition at line 571 of file BusBroker.cc.

575 {
576 abortWithError("Not implemented.");
577 return -1;
578}

References abortWithError.

◆ setBBN()

void BusBroker::setBBN ( const BasicBlockNode bbn)
inline

Definition at line 136 of file BusBroker.hh.

136{ bbn_ = bbn; }
const BasicBlockNode * bbn_
Definition BusBroker.hh:153

References bbn_.

Referenced by SimpleBrokerDirector::setBBN().

◆ setCFG()

void BusBroker::setCFG ( const ControlFlowGraph cfg)
inline

Definition at line 135 of file BusBroker.hh.

135{ cfg_ = cfg; }
const ControlFlowGraph * cfg_
Definition BusBroker.hh:152

References cfg_.

Referenced by SimpleBrokerDirector::setCFG().

◆ setupResourceLinks()

void BusBroker::setupResourceLinks ( const ResourceMapper mapper)
virtual

Complete resource initialisation by creating the references to other resources due to a dependency or a relation. Use the given resource mapper to lookup dependent and related resources using machine parts as keys.

Parameters
mapperResource mapper.

Implements ResourceBroker.

Definition at line 688 of file BusBroker.cc.

688 {
689
690 setResourceMapper(mapper);
691
692 for (ResourceMap::iterator resIter = resMap_.begin();
693 resIter != resMap_.end(); resIter++) {
694
695 const Bus* bus = dynamic_cast<const Bus*>((*resIter).first);
696 if (bus == NULL) {
697 throw InvalidData(
698 __FILE__, __LINE__, __func__,
699 "Bus broker has other then Bus Resource registered!");
700 }
701
702 SchedulingResource* busResource = (*resIter).second;
703
704 int immWidth = bus->immediateWidth();
705
706 ShortImmPSocketResource* immSocketResource =
708 bus->name() + "Imm", immWidth, bus->signExtends(),
710
711 shortImmPSocketResources_.push_back(immSocketResource);
712 busResource->addToRelatedGroup(0, *immSocketResource);
713
714 for (int i = 0; i < bus->segmentCount(); i++) {
715 Segment* seg = bus->segment(i);
716 for (int j = 0; j < seg->connectionCount(); j++) {
717 Socket* socket = seg->connection(j);
718 SchedulingResource* relRes =
720 if (relRes == NULL) {
721 relRes = outputPSocketBroker_.resourceOf(*socket);
722 }
723 if (relRes != NULL) {
724 busResource->addToRelatedGroup(0, *relRes);
725 } else {
726 std::string msg = "BusBroker: finding ";
727 msg += " resource for Socket ";
728 msg += " failed. ";
729 throw KeyNotFound(
730 __FILE__, __LINE__, __func__, msg);
731 }
732 }
733 }
734 }
735}
void setResourceMapper(const ResourceMapper &mapper)
virtual void addToRelatedGroup(const int group, SchedulingResource &resource)
int immediateWidth() const
Definition Bus.cc:160
bool signExtends() const
Definition Bus.cc:171
const Connection & connection(const Socket &socket) const
Definition Segment.cc:250

References __func__, SchedulingResource::addToRelatedGroup(), TTAMachine::Segment::connection(), TTAMachine::Segment::connectionCount(), TTAMachine::Bus::immediateWidth(), ResourceBroker::initiationInterval_, inputPSocketBroker_, TTAMachine::Component::name(), outputPSocketBroker_, ResourceBroker::resMap_, ResourceBroker::resourceOf(), TTAMachine::Bus::segment(), TTAMachine::Bus::segmentCount(), ResourceBroker::setResourceMapper(), shortImmPSocketResources_, and TTAMachine::Bus::signExtends().

Here is the call graph for this function:

◆ unassign()

void BusBroker::unassign ( MoveNode node)
virtual

Free the resource type managed by this broker and unassign it from given node.

If this broker is not applicable to the given node, or the node is not assigned a resource of the managed type, this method does nothing.

Parameters
nodeNode to unassign.

Implements ResourceBroker.

Definition at line 522 of file BusBroker.cc.

522 {
523
525 Move& move = const_cast<MoveNode&>(node).move();
526 const Bus& bus = move.bus();
527 SchedulingResource* res = resourceOf(bus);
528 BusResource& busRes = static_cast<BusResource&>(*res);
529 busRes.unassign(node.cycle(),node);
530 assignedResources_.erase(&node);
531 if (!busPreassigned_[&node]) {
533 move.setBus(um.universalBus());
534 }
535 }
536}
virtual void unassign(const int cycle, MoveNode &node) override
int cycle() const
Definition MoveNode.cc:421

References ResourceBroker::assignedResources_, TTAProgram::Move::bus(), busPreassigned_, MapTools::containsKey(), MoveNode::cycle(), UniversalMachine::instance(), ResourceBroker::resourceOf(), TTAProgram::Move::setBus(), BusResource::unassign(), and UniversalMachine::universalBus().

Here is the call graph for this function:

Member Data Documentation

◆ bbn_

const BasicBlockNode* BusBroker::bbn_
private

Definition at line 153 of file BusBroker.hh.

Referenced by setBBN().

◆ busPreassigned_

std::map<const MoveNode*, bool> BusBroker::busPreassigned_
private

Definition at line 147 of file BusBroker.hh.

Referenced by assign(), clear(), and unassign().

◆ cfg_

const ControlFlowGraph* BusBroker::cfg_
private

Definition at line 152 of file BusBroker.hh.

Referenced by setCFG().

◆ hasLimm_

bool BusBroker::hasLimm_
private

Definition at line 150 of file BusBroker.hh.

Referenced by buildResources(), and canTransportImmediate().

◆ inputPSocketBroker_

ResourceBroker& BusBroker::inputPSocketBroker_
private

Definition at line 148 of file BusBroker.hh.

Referenced by allAvailableResources(), isAvailable(), and setupResourceLinks().

◆ mach_

const TTAMachine::Machine* BusBroker::mach_
private

Definition at line 151 of file BusBroker.hh.

Referenced by canTransportImmediate().

◆ outputPSocketBroker_

ResourceBroker& BusBroker::outputPSocketBroker_
private

Definition at line 149 of file BusBroker.hh.

Referenced by allAvailableResources(), isAvailable(), and setupResourceLinks().

◆ shortImmPSocketResources_

std::list<SchedulingResource*> BusBroker::shortImmPSocketResources_
private

Definition at line 146 of file BusBroker.hh.

Referenced by clear(), setupResourceLinks(), and ~BusBroker().


The documentation for this class was generated from the following files: