OpenASIP  2.0
PendingAssignment.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 PendingAssignment.cc
26  *
27  * Implementation of PendingAssignment class.
28  *
29  * @author Ari Mets�halme 2006 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 
35 #include "ResourceBroker.hh"
36 #include "PendingAssignment.hh"
37 #include "MoveNode.hh"
38 
39 using std::string;
40 
41 /**
42  * Constructor.
43  */
45  broker_(broker), cycle_(-1), node_(NULL), assignmentTried_(false),
46  lastTriedAssignment_(-1) {
47 }
48 
49 /**
50  * Destructor.
51  */
53 }
54 
55 /**
56  * Return the broker of this pending assignment.
57  *
58  * @return The broker of this pending assignment.
59  */
62  return broker_;
63 }
64 
65 /**
66  * Record the input node to which resources have to be assigned or
67  * allocated, and the cycle in which the node should be placed.
68  *
69  * @param cycle Cycle.
70  * @param node Node.
71  */
72 void
74  const TTAMachine::Bus* bus,
75  const TTAMachine::FunctionUnit* srcFU,
76  const TTAMachine::FunctionUnit* dstFU,
77  int immWriteCycle,
78  const TTAMachine::ImmediateUnit* immu,
79  int immRegIndex) {
80  cycle_ = cycle;
81  node_ = &node;
82  bus_ = bus;
83  srcFU_ = srcFU;
84  dstFU_ = dstFU;
85  immWriteCycle_ = immWriteCycle;
86  immu_ = immu;
87  immRegIndex_ = immRegIndex;
89 }
90 
91 /**
92  * Return true if, for the currently applied assignments, there exists
93  * at least one tentative assignment which has not been tried yet.
94  *
95  * @return True if, for the currently applied assignments, there exists
96  * at least one tentative assignment which has not been tried yet.
97  */
98 bool
100  if (lastTriedAssignment_ == -1) {
103  immRegIndex_);
104  // Sorts candidate set of resources by their use count or name if
105  // the use counts are identical
107  }
109 }
110 
111 /**
112  * Try to assign the next possible assignment found by current
113  * broker.
114  *
115  * @exception ModuleRunTimeError If this PendingAssignment has run out of
116  * possible assignments.
117  */
118 void
120 
122 
123  if (availableResources_.count() == 0 ||
125  string msg = "Ran out of possible assignments!";
126  throw ModuleRunTimeError(__FILE__, __LINE__, __func__, msg);
127  }
128 
129  broker_.assign(
132  assignmentTried_ = true;
133 }
134 
135 /**
136  * Unassign the resource of this pending assignment currently assigned
137  * to the node.
138  *
139  * Last tried assignment is remembered.
140  *
141  * @exception ModuleRunTimeError If no resource in the set of
142  * resources of this pending assignment is currently assigned to the
143  * node.
144  */
145 void
149  } else {
150  string msg = "No resource in the set of resources of this pending"
151  "assignment was assigned to the given node!";
152  throw ModuleRunTimeError(__FILE__, __LINE__, __func__, msg);
153  }
154 }
155 
156 /**
157  * Clear out the record of the possible resource assignments of the
158  * current broker that have been already tried.
159  *
160  * If one of the possible resources is still assigned to the node,
161  * unassign it.
162  */
163 void
167  }
169 }
170 
171 /**
172  * Clears the pending assignment.
173  *
174  * Does not unassign anything.
175  */
176 void
178  cycle_ = -1;
179  node_ = NULL;
180  immu_ = NULL;
181  immWriteCycle_ = -1;
182  immRegIndex_ = -1;
183 
184  assignmentTried_ = false;
187  bus_ = NULL;
188 }
ResourceBroker::allAvailableResources
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
Definition: ResourceBroker.cc:143
ResourceBroker::isAlreadyAssigned
virtual bool isAlreadyAssigned(int cycle, const MoveNode &node, const TTAMachine::Bus *preassignedBus) const =0
PendingAssignment::assignmentTried_
bool assignmentTried_
Definition: PendingAssignment.hh:78
ResourceBroker::assign
virtual void assign(int cycle, MoveNode &node, SchedulingResource &res, int immWriteCycle, int immRegIndex)=0
PendingAssignment::forget
void forget()
Definition: PendingAssignment.cc:164
PendingAssignment::node_
MoveNode * node_
Definition: PendingAssignment.hh:73
PendingAssignment::availableResources_
SchedulingResourceSet availableResources_
Definition: PendingAssignment.hh:79
TTAMachine::Bus
Definition: Bus.hh:53
ResourceBroker
Definition: ResourceBroker.hh:61
MoveNode
Definition: MoveNode.hh:65
PendingAssignment::broker
ResourceBroker & broker()
Definition: PendingAssignment.cc:61
PendingAssignment::~PendingAssignment
virtual ~PendingAssignment()
Definition: PendingAssignment.cc:52
SchedulingResourceSet::clear
void clear()
Definition: SchedulingResource.cc:336
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
PendingAssignment::lastTriedAssignment_
int lastTriedAssignment_
Definition: PendingAssignment.hh:80
__func__
#define __func__
Definition: Application.hh:67
ModuleRunTimeError
Definition: Exception.hh:1043
PendingAssignment::srcFU_
const TTAMachine::FunctionUnit * srcFU_
Definition: PendingAssignment.hh:75
PendingAssignment::isAssignmentPossible
bool isAssignmentPossible()
Definition: PendingAssignment.cc:99
PendingAssignment::immu_
const TTAMachine::ImmediateUnit * immu_
Definition: PendingAssignment.hh:81
PendingAssignment::immRegIndex_
int immRegIndex_
Definition: PendingAssignment.hh:82
ResourceBroker.hh
PendingAssignment::tryNext
void tryNext()
Definition: PendingAssignment.cc:119
SchedulingResourceSet::count
int count() const
Definition: SchedulingResource.cc:251
PendingAssignment::setRequest
void setRequest(int cycle, MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex)
Definition: PendingAssignment.cc:73
ResourceBroker::unassign
virtual void unassign(MoveNode &node)=0
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
PendingAssignment::PendingAssignment
PendingAssignment(ResourceBroker &broker)
Definition: PendingAssignment.cc:44
PendingAssignment::bus_
const TTAMachine::Bus * bus_
Definition: PendingAssignment.hh:74
PendingAssignment::cycle_
int cycle_
Definition: PendingAssignment.hh:72
PendingAssignment::clear
void clear()
Definition: PendingAssignment.cc:177
PendingAssignment.hh
SchedulingResourceSet::resource
SchedulingResource & resource(int index) const
Definition: SchedulingResource.cc:263
MoveNode.hh
PendingAssignment::dstFU_
const TTAMachine::FunctionUnit * dstFU_
Definition: PendingAssignment.hh:76
PendingAssignment::broker_
ResourceBroker & broker_
Corresponding resource broker.
Definition: PendingAssignment.hh:71
PendingAssignment::immWriteCycle_
int immWriteCycle_
Definition: PendingAssignment.hh:77
PendingAssignment::undoAssignment
void undoAssignment()
Definition: PendingAssignment.cc:146
SchedulingResourceSet::sort
void sort()
Definition: SchedulingResource.cc:328
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50