OpenASIP  2.0
ITemplateResource.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 ITemplateResource.cc
26  *
27  * Implementation of ITemplateResource class.
28  *
29  * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include "ITemplateResource.hh"
34 #include "MapTools.hh"
35 #include "Application.hh"
36 #include "InstructionTemplate.hh"
37 
38 /**
39  * Constructor.
40  *
41  * @param name Name of template.
42  */
45  unsigned int initiationInterval):
46  SchedulingResource(templ.name(), initiationInterval),
47  template_(&templ){
48 }
49 
50 /**
51  * Destructor.
52  */
54 }
55 
56 /**
57  * Test if instruction template resource is used in given cycle.
58  *
59  * @param cycle Cycle to test.
60  * @return True if resource is used in given cycle.
61  */
62 bool
63 ITemplateResource::isInUse(const int cycle) const {
65  if (MapTools::valueForKey<int>(resourceRecord_, instructionIndex(cycle)) != 0) {
66  return true;
67  }
68  }
69  return false;
70 }
71 
72 /**
73  * Test if instruction tempalte resource is available in given cycle.
74  *
75  * @param cycle Cycle to test.
76  * @return True if resource available in given cycle.
77  */
78 bool
79 ITemplateResource::isAvailable(const int cycle) const {
80  return !isInUse(cycle);
81 }
82 
83 /**
84  * The overridden method should be used instead.
85  */
86 void
88  abortWithError("Not implemented!");
89 }
90 
91 /**
92  * Assign instruction template resource to given cycle.
93  *
94  * @param cycle Cycle to assign.
95  */
96 void
97 ITemplateResource::assign(const int cycle) {
98 
99  if (canAssign(cycle)) {
102  } else {
103  resourceRecord_[instructionIndex(cycle)] = 1;
104  }
105  }
106 }
107 
108 /**
109  * The overridden method should be used instead.
110  */
111 void
113 
114  abortWithError("Not implemented!");
115 }
116 
117 /**
118  * Unassign instruction template from given cycle.
119  *
120  * @param cycle Cycle to remove assignment from.
121  */
122 void
123 ITemplateResource::unassign(const int cycle) {
124 
125  if (isInUse(cycle)) {
127  }
128 }
129 
130 /**
131  * The overridden method should be used instead.
132  */
133 bool
134 ITemplateResource::canAssign(const int, const MoveNode&) const {
135  abortWithError("Not implemented!");
136  return false;
137 }
138 
139 /**
140  * Return true if instruction template resource can be assigned on given cycle.
141  *
142  * @param cycle Cycle to test.
143  * @return True if template can be assigned to given cycle.
144  */
145 bool
146 ITemplateResource::canAssign(const int cycle) const {
147  return !isInUse(cycle);
148 }
149 
150 /**
151  * Return true always.
152  *
153  * @return True always.
154  */
155 bool
157  return true;
158 }
159 
160 /**
161  * Tests if all referred resources in dependent groups are of
162  * proper types.
163  *
164  * @return True If all resources in dependent groups are
165  * immediate units or buses (move slots).
166  */
167 bool
169  for (int i = 0; i < dependentResourceGroupCount(); i++) {
170  for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
171  if (!(dependentResource(i, j).isIUResource() ||
172  dependentResource(i, j).isBusResource())) {
173  return false;
174  }
175  }
176  }
177  return true;
178 }
179 
180 /**
181  * Tests if related resource groups are empty.
182  *
183  * @return True if related resource groups are empty.
184  * @note This resource type has no related resources.
185  */
186 bool
188  for (int i = 0; i < relatedResourceGroupCount(); i++) {
189  if (relatedResourceCount(i) > 0) {
190  return false;
191  }
192  }
193  return true;
194 }
195 
196 
197 /**
198  * Clears bookkeeping of the scheduling resource.
199  *
200  * After this call the state of the resource should be identical to a
201  * newly-created and initialized resource.
202  */
203 void
206  resourceRecord_.clear();
207 }
208 
209 /**
210  * Comparison operator.
211  *
212  * Favours itemplates with more nop slots.
213  */
214 bool
216  const ITemplateResource *itr = static_cast<const ITemplateResource*>(&other);
217  if (itr == NULL) {
218  return false;
219  }
220 
221  return SchedulingResource::operator<(other);
222 }
SchedulingResource::dependentResourceGroupCount
virtual int dependentResourceGroupCount() const
Definition: SchedulingResource.cc:71
SchedulingResource::clear
virtual void clear()
Definition: SchedulingResource.cc:397
ITemplateResource::resourceRecord_
ResourceRecordType resourceRecord_
Definition: ITemplateResource.hh:82
ITemplateResource::canAssign
virtual bool canAssign(const int cycle, const MoveNode &node) const override
Definition: ITemplateResource.cc:134
MapTools.hh
ITemplateResource::unassign
virtual void unassign(const int cycle, MoveNode &node) override
Definition: ITemplateResource.cc:112
ITemplateResource::operator<
virtual bool operator<(const SchedulingResource &other) const override
Definition: ITemplateResource.cc:215
MoveNode
Definition: MoveNode.hh:65
ITemplateResource.hh
TTAMachine::InstructionTemplate
Definition: InstructionTemplate.hh:49
SchedulingResource::dependentResource
virtual SchedulingResource & dependentResource(const int group, const int index) const
Definition: SchedulingResource.cc:158
SchedulingResource::dependentResourceCount
int dependentResourceCount(const int group) const
SchedulingResource::isBusResource
virtual bool isBusResource() const
ITemplateResource::clear
void clear() override
Definition: ITemplateResource.cc:204
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
ITemplateResource::assign
virtual void assign(const int cycle, MoveNode &node) override
Definition: ITemplateResource.cc:87
InstructionTemplate.hh
SchedulingResource
Definition: SchedulingResource.hh:52
ITemplateResource::validateDependentGroups
virtual bool validateDependentGroups() override
Definition: ITemplateResource.cc:168
Application.hh
ITemplateResource::isAvailable
virtual bool isAvailable(const int cycle) const override
Definition: ITemplateResource.cc:79
SchedulingResource::operator<
virtual bool operator<(const SchedulingResource &other) const
SchedulingResource::instructionIndex
int instructionIndex(int cycle) const
SchedulingResource::relatedResourceCount
int relatedResourceCount(const int group) const
SchedulingResource::isIUResource
virtual bool isIUResource() const
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
ITemplateResource::validateRelatedGroups
virtual bool validateRelatedGroups() override
Definition: ITemplateResource.cc:187
ITemplateResource::isITemplateResource
virtual bool isITemplateResource() const override
Definition: ITemplateResource.cc:156
ITemplateResource
Definition: ITemplateResource.hh:51
SchedulingResource::relatedResourceGroupCount
virtual int relatedResourceGroupCount() const
Definition: SchedulingResource.cc:61
ITemplateResource::~ITemplateResource
virtual ~ITemplateResource()
Definition: ITemplateResource.cc:53
ITemplateResource::isInUse
virtual bool isInUse(const int cycle) const override
Definition: ITemplateResource.cc:63
ITemplateResource::ITemplateResource
ITemplateResource(TTAMachine::InstructionTemplate &templ, unsigned int initiationInterval=0)
Definition: ITemplateResource.cc:43