OpenASIP 2.2
Loading...
Searching...
No Matches
InputFUResource.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 InputFUResource.cc
26 *
27 * Implementation of prototype of Resource Model:
28 * implementation of the InputFUResource.
29 *
30 * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#include "InputFUResource.hh"
35#include "FUPort.hh"
36#include "Application.hh"
37#include "Exception.hh"
38#include "MoveNode.hh"
40#include "ResourceManager.hh"
42
46
47/**
48 * Constructor defining name of resource.
49 *
50 * @param name Name of resource
51 */
53 const std::string& name, int opCount, int nopSlotWeight,
54 unsigned int initiationInterval) :
55 FUResource(name, opCount, nopSlotWeight, initiationInterval) {
56}
57
58/**
59 * Empty destructor
60 */
63
64/**
65 * Not to be used, aborts!
66 *
67 * Use version with third InputPSocket operand!
68 */
69bool
70InputFUResource::canAssign(const int, const MoveNode&) const {
71 abortWithError("Wrong method. Use canAssign with PSocket!");
72 return false;
73}
74
75/**
76 * Assign resource to given node for given cycle
77 * as a side effect, assign also execution pipeline for triggering moves.
78 *
79 * @param cycle Cycle to assign
80 * @param node MoveNode assigned
81 * @param pSocket InputPSocket used for writting operand
82 * @throw In case the assignment is impossible, should have been tested
83 * with canAssing first.
84 */
85void
87 const int cycle,
88 MoveNode& node) {
89
90 for (int i = 0; i < dependentResourceGroupCount(); i++) {
91 for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
95 dynamic_cast<ExecutionPipelineResource*>(res);
96 epRes->assignDestination(cycle, node);
98 return;
99 }
100 }
101 }
102 abortWithError("InputFUResource has no execution pipeline registered!");
103}
104
105/**
106 * Unassign resource from given node for given cycle,
107 * for triggering moves also unassign execution pipeline.
108 *
109 * @param cycle Cycle to remove assignment from
110 * @param node MoveNode to remove assignment from
111 * @param pSocket InputPSocket used for writting operand
112 * @throw In case PSocket is not connected to FU
113 */
114void
116 const int cycle,
117 MoveNode& node) {
118
119 for (int i = 0; i < dependentResourceGroupCount(); i++) {
120 for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
124 dynamic_cast<ExecutionPipelineResource*>(res);
125 epRes->unassignDestination(cycle, node);
127 return;
128 }
129 }
130 }
131 abortWithError("InputFUResource has no execution pipeline registered!");
132}
133
134/**
135 * Return true if resource can be assigned for given node in given cycle.
136 *
137 * @param cycle Cycle to test
138 * @param node MoveNode to test
139 * @param pSocket InputPSocket used for writting operand
140 * @return true if node can be assigned to cycle
141 * @throw Internal error, PSocket is not conencted to FU or ExecutionPipeline
142 */
143bool
145 const int cycle,
146 const MoveNode& node,
147 const InputPSocketResource& pSocket,
148 const bool triggers) const {
149
150 if (!hasDependentResource(pSocket)) {
151 std::string msg = "InputPSocket ";
152 msg += pSocket.name();
153 msg += " is not connected to ";
154 msg += name();
155 msg += "!";
156 throw ModuleRunTimeError(__FILE__, __LINE__, __func__, msg);
157 return false;
158 }
159
160 if (!pSocket.canAssign(cycle, node)) {
161 debugLogRM("cannot assign pSocket");
162 return false;
163 }
164
165 for (int i = 0; i < dependentResourceGroupCount(); i++) {
166 for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
168 if (depRes.isExecutionPipelineResource()) {
170 static_cast<ExecutionPipelineResource*>(&depRes);
171 if (!(epRes->canAssignDestination(cycle, node, triggers))) {
172 debugLogRM("cannot assign execution pipeline resource");
173 return false;
174 } else {
175 return true;
176 }
177 }
178 }
179 }
180 debugLogRM("could not find a depedent resource I could assign");
181 return false;
182}
183
184/**
185 * Test if resource InputFUResource is available.
186 *
187 * Not all the PSocket are inUse and there is some operation possible for
188 * triggering moves.
189 *
190 * @param cycle Cycle which to test
191 * @return True if FUResource is available in cycle
192 */
193bool
194InputFUResource::isAvailable(const int cycle) const {
195 // Test availability of PSockets using parent class
196 if (!FUResource::isAvailable(cycle)) {
197 return false;
198 }
199 for (int i = 0; i < dependentResourceGroupCount(); i++) {
200 for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
202 dependentResource(i, j).isAvailable(cycle)) {
203 return true;
204 }
205 }
206 }
207 return false;
208}
209
210/**
211 * Test if resource InputFUResource is used in given cycle.
212 *
213 * True if some of InputPSockets are already used or there is
214 * operation already in execution pipeline.
215 *
216 * @param cycle Cycle which to test
217 * @return True if InputFUResource is already used in cycle
218 */
219bool
220InputFUResource::isInUse(const int cycle) const {
221 // Test isInUse of PSockets using parent class
222 if (FUResource::isInUse(cycle)) {
223 return true;
224 }
225 for (int i = 0; i < dependentResourceGroupCount(); i++) {
226 for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
228 dependentResource(i, j).isInUse(cycle)) {
229 return true;
230 }
231 }
232 }
233 return false;
234}
235
236/**
237 * Allways return true
238 *
239 * @return true
240 */
241bool
243 return true;
244}
245
246/**
247 * Tests if all referred resource in dependent groups are of
248 * proper types.
249 *
250 * @return true If all resources in dependent groups are
251 * input or output PSockets or executionPipeline
252 */
253bool
255 for (int i = 0; i < dependentResourceGroupCount(); i++) {
256 for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
260 return false;
261 }
262 }
263 }
264 return true;
265}
266
267/**
268 * Tests if related resource groups are empty.
269 *
270 * @return true If all related resource groups are
271 * empty
272 */
273bool
275 for (int i = 0; i < relatedResourceGroupCount(); i++) {
276 if (relatedResourceCount(i) > 0) {
277 return false;
278 }
279 }
280 return true;
281}
#define __func__
#define abortWithError(message)
#define debugLogRM(__X)
virtual void assignDestination(const int cycle, MoveNode &node)
virtual bool canAssignDestination(const int cycle, const MoveNode &node, const bool triggering=false) const
virtual void unassignDestination(const int cycle, MoveNode &node)
virtual bool isAvailable(const int cycle) const override
Definition FUResource.cc:80
virtual bool isInUse(const int cycle) const override
Definition FUResource.cc:62
virtual bool isInUse(const int cycle) const override
InputFUResource(const std::string &name, int opCount, int nopSlotWeight, unsigned int initiationInterval=0)
virtual void assign(const int cycle, MoveNode &node) override
virtual bool validateRelatedGroups() override
virtual void unassign(const int cycle, MoveNode &node) override
virtual bool isInputFUResource() const override
virtual bool validateDependentGroups() override
virtual ~InputFUResource()
virtual bool canAssign(const int cycle, const MoveNode &node) const override
virtual bool isAvailable(const int cycle) const override
virtual bool canAssign(const int cycle, const MoveNode &node) const override
virtual void increaseUseCount()
int relatedResourceCount(const int group) const
virtual SchedulingResource & dependentResource(const int group, const int index) const
virtual bool isInputPSocketResource() const
virtual const std::string & name() const
virtual bool hasDependentResource(const SchedulingResource &sResource) const
virtual void decreaseUseCount()
virtual bool isOutputPSocketResource() const
int dependentResourceCount(const int group) const
virtual int relatedResourceGroupCount() const
virtual bool isAvailable(const int cycle) const =0
virtual bool isExecutionPipelineResource() const
virtual int dependentResourceGroupCount() const
virtual bool isInUse(const int cycle) const =0