OpenASIP 2.2
Loading...
Searching...
No Matches
RemoveUnconnectedComponents.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 RemoveUnconnectedComponents.cc
26 *
27 * Explorer plugin that removes unconnected ports from units or creates
28 * connections to these ports in case of a FUs. Also removes unconnected
29 * buses. If all ports from a unit are removed, removes also the unit.
30 *
31 *
32 * @author Esa Määttä 2007 (esa.maatta-no.spam-tut.fi)
33 * @note rating: red
34 */
35
36#include <string>
37#include <vector>
38
40#include "DSDBManager.hh"
41#include "Machine.hh"
42#include "MachineTester.hh"
43#include "Exception.hh"
44#include "StringTools.hh"
45#include "Conversion.hh"
46
48
49using std::endl;
50using namespace TTAMachine;
51
52/**
53 * Explorer plugin that removes unconnected ports from units or creates
54 * connections to these ports in case of a FUs. Also removes unconnected
55 * buses. If all ports from a unit are removed, removes also the unit.
56 */
58 PLUGIN_DESCRIPTION("Removes unconnected components from a configuration.");
59
62
63 // compulsory parameters
64 // no compulsory parameters
65
66 // parameters that have a default value
69 }
70
71
72 virtual bool requiresStartingPointArchitecture() const { return true; }
73 virtual bool producesArchitecture() const { return true; }
74 virtual bool requiresHDB() const { return false; }
75 virtual bool requiresSimulationData() const { return false; }
76 virtual bool requiresApplication() const { return false; }
77
78 /**
79 * Removes unconnected components from a configuration.
80 *
81 * Explorer plugin that removes unconnected ports from units or creates
82 * connections to these ports in case of a FUs. Also removes unconnected
83 * buses. If all ports from a unit are removed, removes also the unit.
84 * Removes also unconnected FUs. First unconnected sockets are removed.
85 *
86 * Supported parameters:
87 * - allow_remove, Allows the RFs port removal and portless RFs removal.
88 *
89 * @param configurationID Configuration to optimize.
90 */
91 virtual std::vector<RowID>
92 explore(const RowID& configurationID, const unsigned int&) {
93
94 std::vector<RowID> result;
95
97
98 try {
99 DSDBManager& dsdb = db();
101 dsdb.configuration(configurationID);
102
103 // get the machine belonging to the configuration
104 Machine* mach = NULL;
105 try {
106 mach = dsdb.architecture(conf.architectureID);
107 } catch (const Exception& e) {
108 return result;
109 }
110
111 // removes sockets not connected to any bus
112 removeSockets(*mach);
113
114 // removes FUs not connected to any socket by any port
115 std::vector<std::string> removedFUNames;
116 removeUnconnectedFUs(*mach, removedFUNames);
117
118 // checks that every FU port is connected to a socket
119 checkFUPorts(*mach);
120
121 // register files are removed only if allow_remove parameter is
122 // given, else connections to sockets are made for RFs
123 std::vector<std::string> removedRFNames;
124 checkRFPorts(*mach, removedRFNames);
125
126 // removes buses that have no connections to any socket
127 checkBuses(*mach);
128
130 if (conf.hasImplementation) {
131 newConf.hasImplementation = true;
134 // removes removed RFs from idf
135 while (!removedRFNames.empty()) {
136 idf->removeRFImplementation(removedRFNames.at(
137 removedRFNames.size()-1));
138 removedRFNames.pop_back();
139 }
140 // removes removed FUs from idf
141 while (!removedFUNames.empty()) {
142 idf->removeFUImplementation(removedFUNames.at(
143 removedFUNames.size()-1));
144 removedFUNames.pop_back();
145 }
146 newConf.implementationID =
147 dsdb.addImplementation(*idf, 0, 0);
148 } else {
149 newConf.hasImplementation = false;
150 }
151 newConf.architectureID = dsdb.addArchitecture(*mach);
152
153 RowID confID = dsdb.addConfiguration(newConf);
154 result.push_back(confID);
155
156 } catch (const Exception& e) {
157 std::ostringstream msg(std::ostringstream::out);
158 msg << "Error while using RemoveUnconnectedComponents:"
159 << endl << e.errorMessage() << endl;
160 verboseLog(msg.str());
161 return result;
162 }
163 return result;
164 }
165
166private:
167 static const std::string allowRemovalPN_;
168 /// parameter allow removal of unused ports and RFs without ports.
170
171
172 /**
173 * Reads the parameters given to the plugin.
174 */
178
179
180 /**
181 * Removes totally unconnected FUs.
182 *
183 * @param mach Machine which unconnected FUs are removed.
184 * @param removedFUNames Names of FU units that were removed from machine
185 */
187 std::vector<std::string>& removedFUNames) {
188
189 //MachineTester& tester = mach.machineTester();
190 Machine::SocketNavigator socketNav = mach.socketNavigator();
191
193 for (int i = 0; i < FUNav.count(); ++i) {
194 FunctionUnit* FU = FUNav.item(i);
195 bool noConnections = true;
196 for (int j = 0; j < FU->portCount(); ++j) {
197 Port* port = FU->port(j);
198 // if no connections
199 if (port->socketCount() > 0) {
200 noConnections = false;
201 break;
202 }
203 }
204 // remove FU if it did not have any connections
205 if (noConnections) {
206 mach.removeFunctionUnit(*FU);
207 removedFUNames.push_back(FU->name());
208 --i;
209 }
210 }
211 }
212
213 /**
214 * Checks that every FU port has at least one connection.
215 *
216 * Adds an new connection to some available socket if port has no
217 * connections
218 *
219 * @param mach Machine which FU ports are checked.
220 */
222 MachineTester& tester = mach.machineTester();
223 Machine::SocketNavigator socketNav = mach.socketNavigator();
224
226 for (int i = 0; i < FUNav.count(); ++i) {
227 FunctionUnit* FU = FUNav.item(i);
228 for (int j = 0; j < FU->portCount(); ++j) {
229 Port* port = FU->port(j);
230 // if no connections, make a connection to some socket
231 if (port->socketCount() < 1) {
232 Socket* socket = NULL;
233 // find a socket where FU port can be connected
234 for (int soc = 0; i < socketNav.count(); ++soc) {
235 socket = socketNav.item(soc);
236 if (tester.canConnect(*socket, *port)) {
237 port->attachSocket(*socket);
238 break;
239 }
240 }
241 }
242 }
243 }
244 }
245
246 /**
247 * Checks that every RF port has connections.
248 *
249 * Removes every port of a RF that has no connections to sockets if
250 * allowRemoval_ is true else makes connection to available socket.
251 * If RF ends up having no ports, removes the RF from machine.
252 *
253 * @param mach Machine which RF ports are checked.
254 * @param removedRFNames Names of RF units that were removed from machine
255 * content only added not read in this function.
256 */
258 std::vector<std::string>& removedRFNames) {
259
260 MachineTester& tester = mach.machineTester();
261 Machine::SocketNavigator socketNav = mach.socketNavigator();
262
264 for (int i = 0; i < RFNav.count(); ++i) {
265 RegisterFile* RF = RFNav.item(i);
266 for (int j = 0; j < RF->portCount(); ++j) {
267 Port* port = RF->port(j);
268 // if no connections
269 if (port->socketCount() < 1) {
270 if (allowRemoval_) {
271 delete port;
272 port = NULL;
273 --j;
274 if (RF->portCount() < 1) {
275 mach.removeRegisterFile(*RF);
276 removedRFNames.push_back(RF->name());
277 --i;
278 }
279 } else {
280 Socket* socket = NULL;
281 // find a socket where RF port can be connected
282 for (int soc = 0; i < socketNav.count(); ++soc) {
283 socket = socketNav.item(soc);
284 if (tester.canConnect(*socket, *port)) {
285 port->attachSocket(*socket);
286 break;
287 }
288 }
289 }
290 }
291 }
292 }
293 }
294
295 /**
296 * Checks buses and removes the ones that have no connections to sockets.
297 *
298 * @param mach Machine which buses are checked.
299 */
301 Machine::SocketNavigator socketNav = mach.socketNavigator();
302 Machine::BusNavigator busNav = mach.busNavigator();
303 for (int i = 0; i < busNav.count(); ++i) {
304 bool isConnected = false;
305 for (int j = 0; j < socketNav.count(); ++j) {
306 if ((busNav.item(i))->isConnectedTo(
307 *socketNav.item(j))) {
308 isConnected = true;
309 }
310 }
311 // if not connected to any socket remove bus
312 if (!isConnected) {
313 mach.removeBus(*busNav.item(i));
314 }
315 }
316 }
317
318 /**
319 * Removes sockets that are not needed in the machine.
320 *
321 * @param mach Machine which extra sockets are removed.
322 */
324
325 // remove not connected sockets
327 std::list<std::string> removedSocketNames;
328 modifier.removeNotConnectedSockets(mach, removedSocketNames);
329 }
330};
331
332const std::string
334
#define verboseLog(text)
int RowID
Type definition of row ID in relational databases.
Definition DBTypes.hh:37
#define EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN(PLUGIN_NAME__)
const string FU
const string RF
find Finds info of the inner loops in the false
#define BOOL()
static std::string toString(const T &source)
RowID addArchitecture(const TTAMachine::Machine &mom)
TTAMachine::Machine * architecture(RowID id) const
IDF::MachineImplementation * implementation(RowID id) const
MachineConfiguration configuration(RowID id) const
RowID addImplementation(const IDF::MachineImplementation &impl, double longestPathDelay, CostEstimator::AreaInGates area)
RowID addConfiguration(const MachineConfiguration &conf)
void readOptionalParameter(const std::string paramName, T &param) const
void addParameter(TCEString name, ExplorerPluginParameterType type, bool compulsory=true, TCEString defaultValue="", TCEString description="")
virtual DSDBManager & db()
std::string errorMessage() const
Definition Exception.cc:123
void removeFUImplementation(const std::string &unitName)
void removeRFImplementation(const std::string &unitName)
void removeNotConnectedSockets(TTAMachine::Machine &mach, std::list< std::string > &removedSocketNames)
virtual bool canConnect(const TTAMachine::Socket &socket, const TTAMachine::Segment &segment)
PLUGIN_DESCRIPTION("Removes unconnected components from a configuration.")
void checkFUPorts(TTAMachine::Machine &mach)
virtual bool requiresStartingPointArchitecture() const
void removeSockets(TTAMachine::Machine &mach)
void removeUnconnectedFUs(TTAMachine::Machine &mach, std::vector< std::string > &removedFUNames)
void checkRFPorts(TTAMachine::Machine &mach, std::vector< std::string > &removedRFNames)
virtual std::vector< RowID > explore(const RowID &configurationID, const unsigned int &)
bool allowRemoval_
parameter allow removal of unused ports and RFs without ports.
void checkBuses(TTAMachine::Machine &mach)
ComponentType * item(int index) const
virtual RegisterFileNavigator registerFileNavigator() const
Definition Machine.cc:450
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
virtual SocketNavigator socketNavigator() const
Definition Machine.cc:368
MachineTester & machineTester() const
Definition Machine.cc:671
virtual void removeBus(Bus &bus)
Definition Machine.cc:477
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
virtual void removeFunctionUnit(FunctionUnit &unit)
Definition Machine.cc:530
virtual void removeRegisterFile(RegisterFile &unit)
Definition Machine.cc:554
virtual void attachSocket(Socket &socket)
Definition Port.cc:191
virtual int socketCount() const
Definition Port.cc:375