OpenASIP 2.2
Loading...
Searching...
No Matches
InputPSocketResource.cc
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 InputPSocketResource.cc
26 *
27 * Implementation of prototype of Resource Model:
28 * implementation of the InputPSocketResource.
29 *
30 * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31 * @note rating: red
32 */
33
35#include "MoveNode.hh"
36#include "MoveGuard.hh"
37#include "Guard.hh"
38#include "Move.hh"
39
40/**
41 * Constructor defining resource name
42 * @param name Name of resource
43 */
44InputPSocketResource::InputPSocketResource(const std::string& name, unsigned int initiationInterval) :
45 PSocketResource(name, initiationInterval) {}
46
47/**
48 * Empty destructor
49 */
51
52/**
53 * Allways return true
54 * @return true
55 */
56bool
60
61/**
62 * Tests if all referred resources in dependent groups are of
63 * proper types
64 * @return true Allways true, dep. groups are empty
65 */
66bool
68 for (int i = 0; i < dependentResourceGroupCount(); i++) {
69 if (dependentResourceCount(i) > 0) {
70 return false;
71 }
72 }
73 return true;
74}
75
76/**
77 * Tests if all referred resources in related groups are of
78 * proper types
79 * @return true If all resources in related groups are
80 * Segment or InputFU resources
81 */
82bool
84 for (int i = 0; i < relatedResourceGroupCount(); i++) {
85 for (int j = 0, count = relatedResourceCount(i); j < count; j++) {
86 if (!(relatedResource(i, j).isInputFUResource() ||
88 return false;
89 }
90 }
91 return true;
92}
93
94/**
95 * Return true if resource can be assigned for given resource in given cycle.
96 *
97 * @param cycle Cycle to test
98 * @param node MoveNode to test
99 * @return true if node can be assigned to cycle
100 */
101bool
102InputPSocketResource::canAssign(const int cycle, const MoveNode& node)
103 const {
104
105 ResourceRecordType::const_iterator iter = resourceRecord_.find(cycle);
106 if (iter != resourceRecord_.end()) {
107 std::set<MoveNode*> movesInCycle = iter->second;
108 for (std::set<MoveNode*>::iterator it = movesInCycle.begin();
109 it != movesInCycle.end(); it++) {
110#ifdef NO_OVERCOMMIT
111 return false;
112#else
113 MoveNode* mn = *it;
114 if (node.move().isUnconditional() ||
115 mn->move().isUnconditional()) {
116 return false;
117 }
118 if (!node.move().guard().guard().isOpposite(
119 mn->move().guard().guard())) {
120 return false;
121 }
122#endif
123 }
124 }
125 return true;
126}
127
128/**
129 * Comparison operator.
130 *
131 * Favours sockets which have less connections.
132 */
133bool
135 const InputPSocketResource *ipsr =
136 dynamic_cast<const InputPSocketResource*>(&other);
137 if (ipsr == NULL) {
138 return false;
139 }
140
141 // favour sockets which have connections to busses with fewest connections
142 // calculate the connections..
143 int connCount = 0;
144 int connCount2 = 0;
145
146 for (int i = 0; i < relatedResourceCount(1); i++) {
148 connCount += r.relatedResourceCount(0);
149 }
150
151 for (int i = 0; i < other.relatedResourceCount(1); i++) {
152 SchedulingResource& r = other.relatedResource(1,i);
153 connCount2 += r.relatedResourceCount(0);
154 }
155
156 // then the comparison.
157 if (connCount < connCount2) {
158 return true;
159 }
160
161 if (connCount > connCount2) {
162 return false;
163 }
164
165
166 // favour sockets with less buses.
167 if (relatedResourceCount(1) < ipsr->relatedResourceCount(1)) {
168 return true;
169 }
170 if (relatedResourceCount(1) > ipsr->relatedResourceCount(1)) {
171 return false;
172 }
173
174 // then use the default use count, name comparison,
175 // but in opposite direction, facouring already used
176 return other.SchedulingResource::operator<(*this);
177}
virtual bool operator<(const SchedulingResource &other) const override
virtual bool validateRelatedGroups() override
virtual bool canAssign(const int cycle, const MoveNode &node) const override
InputPSocketResource(const std::string &name, unsigned int initiationInterval=0)
virtual bool validateDependentGroups() override
virtual bool isInputPSocketResource() const override
TTAProgram::Move & move()
ResourceRecordType resourceRecord_
virtual bool isBusResource() const
virtual SchedulingResource & relatedResource(const int group, const int index) const
int relatedResourceCount(const int group) const
int dependentResourceCount(const int group) const
virtual int relatedResourceGroupCount() const
virtual bool isInputFUResource() const
virtual int dependentResourceGroupCount() const
virtual bool isOpposite(const Guard &guard) const =0
const TTAMachine::Guard & guard() const
Definition MoveGuard.cc:86
MoveGuard & guard() const
Definition Move.cc:345
bool isUnconditional() const
Definition Move.cc:154