OpenASIP 2.2
Loading...
Searching...
No Matches
ImmediateGenerator.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 ImmediateGenerator.cc
26 *
27 * Explorer plugin that creates or modifies machine instruction templates.
28 *
29 * @author Esa Määttä 2007 (esa.maatta-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <vector>
34#include <string>
35#include <set>
36
38#include "DSDBManager.hh"
39#include "Machine.hh"
40#include "TemplateSlot.hh"
41#include "Exception.hh"
42
43#include "TestApplication.hh"
44#include "Program.hh"
45#include "Instruction.hh"
46#include "Move.hh"
47#include "Terminal.hh"
48#include "HDBRegistry.hh"
50#include "ControlUnit.hh"
51#include "HWOperation.hh"
52#include "StringTools.hh"
53#include "Segment.hh"
54#include "CostEstimates.hh"
55#include "Application.hh"
56#include "Procedure.hh"
58#include "Conversion.hh"
59
60using namespace TTAProgram;
61using namespace TTAMachine;
62using namespace HDB;
63using std::endl;
64
65/**
66 * Explorer plugin that creates or modifies machine instruction template by
67 * adding/removing immediates.
68 */
70 PLUGIN_DESCRIPTION("Creates immediates for configuration.");
71
96
97 virtual bool requiresStartingPointArchitecture() const { return true; }
98 virtual bool producesArchitecture() const { return true; }
99 virtual bool requiresHDB() const { return false; }
100 virtual bool requiresSimulationData() const { return false; }
101 virtual bool requiresApplication() const { return false; }
102
103 /**
104 * Explorer plugin that creates or modifies machine instruction templates.
105 * TODO: add some modifying functionality.
106 *
107 * Supported parameters:
108 * - print, boolean, print information about machines instruction templates.
109 * - remove_it_name, string, remove instruction template with a given name.
110 * - add_it_name, string, add empty instruction template with a given name.
111 * - modify_it_name, string, modify instruction template with a given name.
112 * - width, int, instruction template supported width.
113 * - width_part, int, minimum size of width per slot. Default 8.
114 * - split, boolean, split immediate among slots.
115 * - dst_imm_unit, string, destination immediate unit.
116 *
117 * @param startPointConfigurationID Configuration to optimize.
118 */
119 virtual std::vector<RowID>
120 explore(const RowID& startPointConfigurationID, const unsigned int&) {
121
122 // XXX: does this plugin have to touch short immediates.
123
124 std::vector<RowID> result;
125
127
128 try {
129 DSDBManager& dsdb = db();
130 // loads starting configuration
132 dsdb.configuration(startPointConfigurationID);
133
134 // load machine from configuration
135 //Machine* origMach = NULL;
136 Machine* mach = NULL;
137 try {
138 //origMach = dsdb.architecture(conf.architectureID);
139 mach = dsdb.architecture(conf.architectureID);
140 } catch (const Exception& e) {
141 std::ostringstream msg(std::ostringstream::out);
142 msg << e.errorMessage() << endl;
143 verboseLog(msg.str());
144 return result;
145 }
146
147 if (!removeInsTemplateName_.empty()) {
149 }
150
151 if (!addInsTemplateName_.empty()) {
152 if (split_) {
154 } else {
156 }
157 }
158
159 // print immediate info if print parameter given
160 if (print_) {
162 }
163
164 if (createNewConfig_) {
165 // create the new configuration to be saved to dsdb
166 // do long immediates affect these
168 if (conf.hasImplementation) {
169 newConf.hasImplementation = true;
172 CostEstimator::Estimator estimator;
174 estimator.totalArea(*mach, *idf);
175 CostEstimator::DelayInNanoSeconds longestPathDelay =
176 estimator.longestPath(*mach, *idf);
177 newConf.implementationID =
178 dsdb.addImplementation(*idf, longestPathDelay, area);
179 } else {
180 newConf.hasImplementation = false;
181 }
182 newConf.architectureID = dsdb.addArchitecture(*mach);
183 CostEstimates estimates;
184
185 RowID confID = dsdb.addConfiguration(newConf);
186 result.push_back(confID);
187 }
188
189 } catch (const Exception& e) {
190 std::ostringstream msg(std::ostringstream::out);
191 msg << "Error while using ImmediateGenerator:" << endl
192 << e.errorMessage() << endl;
193 verboseLog(msg.str());
194 return result;
195 }
196 return result;
197 }
198
199private:
200 /// Boolean value used to decide if new config is created.
202
203 // parameter names
204 static const std::string printPN_;
205 static const std::string removeInsTemplateNamePN_;
206 static const std::string addInsTemplateNamePN_;
207 static const std::string modInsTemplateNamePN_;
208 static const std::string widthPN_;
209 static const std::string widthPartPN_;
210 static const std::string splitPN_;
211 static const std::string dstImmUnitNamePN_;
212
213 // parameters
214 /// print values
215 bool print_;
216 /// instruction template name to be removed.
218 /// instruction template name to be added.
220 /// instruction template name to be modified.
222 /// width of the target template
223 unsigned int width_;
224 /// minimum width on long instruction slot when splitting the template.
225 unsigned int widthPart_;
226 /// make evenly bus/slot wise splitted template.
227 bool split_;
228 /// destination immediate unit name
229 std::string dstImmUnitName_;
230
231
232 /**
233 * Reads the parameters given to the plugin.
234 */
245
246
247 /**
248 * Print info about instruction templates of a given machine.
249 *
250 * @param mach Machine which instruction templates are to be printed.
251 */
255
256 std::ostringstream msg(std::ostringstream::out);
257 msg << "====== Instruction templates: =======" << endl;
258
259 TTAMachine::InstructionTemplate* insTemplate = NULL;
260 TTAMachine::TemplateSlot* tempSlot = NULL;
261 for (int it = 0; it < ITNav.count(); it++) {
262 insTemplate = ITNav.item(it);
263
264 msg << "Instruction template: " << insTemplate->name() << endl;
265 if (insTemplate->isEmpty()) {
266 msg << "\tEmpty instruction template." << endl;
267 continue;
268 }
269
270 msg << "\tSlot count: " << insTemplate->slotCount() << endl;
271 for (int sc = 0; sc < insTemplate->slotCount(); sc++) {
272 tempSlot = insTemplate->slot(sc);
273 msg << "\t\tSlot name: " << tempSlot->slot() << endl;
274 msg << "\t\tSlot width: " << tempSlot->width() << endl;
275 msg << "\t\tSlot destination: "
276 << tempSlot->destination()->name() << endl;
277 }
278
279 msg << "\tSupported Width: " << insTemplate->supportedWidth() << endl;
280 msg << "\tNumber of Destinations: "
281 << insTemplate->numberOfDestinations() << endl;
282 }
283 verboseLog(msg.str());
284 }
285
286 /**
287 * Removes instruction template with a name given as parameter.
288 *
289 * @param mach Target machine.
290 * @param name Instruction template name to be removed.
291 */
292 void removeInsTemplate(TTAMachine::Machine& mach, std::string name) {
295
296 TTAMachine::InstructionTemplate* insTemplate = NULL;
297 for (int it = 0; it < ITNav.count(); it++) {
298 insTemplate = ITNav.item(it);
299 if (insTemplate->name() == name) {
300 mach.deleteInstructionTemplate(*insTemplate);
301 createNewConfig_ = true;
302 }
303 }
304
305 if (!createNewConfig_) {
306 std::ostringstream msg(std::ostringstream::out);
307 msg << "Error while using ImmediateGenerator:" << endl
308 << "Instruction template with name \"" << name
309 << "\" was not found." << endl;
310 verboseLog(msg.str());
311 }
312 }
313
314 /**
315 * Adds instruction template with a name given as parameter.
316 *
317 * @param mach Target machine.
318 * @param name Instruction template name to be added.
319 */
320 void addInsTemplate(TTAMachine::Machine& mach, std::string name) {
321 TTAMachine::InstructionTemplate* insTemplate = NULL;
322
323 try {
324 insTemplate = new InstructionTemplate(name, mach);
325 } catch (ComponentAlreadyExists& e) {
326 std::ostringstream msg(std::ostringstream::out);
327 msg << "Error while using ImmediateGenerator:" << endl
328 << e.errorMessage() << endl;
329 verboseLog(msg.str());
330 delete insTemplate;
331 return;
332 } catch (InvalidName& e) {
333 std::ostringstream msg(std::ostringstream::out);
334 msg << "Error while using ImmediateGenerator:" << endl
335 << e.errorMessage() << endl;
336 verboseLog(msg.str());
337 delete insTemplate;
338 return;
339 }
340 createNewConfig_ = true;
341 }
342
343 /**
344 * Adds instruction template with a name given as parameter and add
345 * bus wise splitted slots to the template.
346 *
347 * @param mach Target machine.
348 * @param name Instruction template name to be added.
349 */
351 TTAMachine::InstructionTemplate* insTemplate = NULL;
352
353 // find target immediate unit for the instruction template slots
356
357 TTAMachine::ImmediateUnit* immUnit = NULL;
358 TTAMachine::ImmediateUnit* dstImmUnit = NULL;
359 if (dstImmUnitName_.empty()) {
360 // if no destination immediate unit specified take one if exists
361 if (IUNav.count() > 0) {
362 dstImmUnit = IUNav.item(0);
363 } else {
364 std::ostringstream msg(std::ostringstream::out);
365 msg << "Error while using ImmediateGenerator:" << endl
366 << "No immediate units." << endl;
367 verboseLog(msg.str());
368 return;
369 }
370 } else {
371 for (int iu = 0; iu < IUNav.count(); iu++) {
372 immUnit = IUNav.item(iu);
373 if (immUnit->name() == dstImmUnitName_) {
374 dstImmUnit = immUnit;
375 }
376 }
377 if (dstImmUnit == NULL) {
378 std::ostringstream msg(std::ostringstream::out);
379 msg << "Error while using ImmediateGenerator:" << endl
380 << "Given destination immediate unit \""
381 << dstImmUnitName_ << "\" was not found." << endl;
382 verboseLog(msg.str());
383 return;
384 }
385 }
386
387 // add instruction template
388 try {
389 insTemplate = new InstructionTemplate(name, mach);
390 } catch (ComponentAlreadyExists& e) {
391 std::ostringstream msg(std::ostringstream::out);
392 msg << "Error while using ImmediateGenerator:" << endl
393 << e.errorMessage() << endl;
394 verboseLog(msg.str());
395 delete insTemplate;
396 insTemplate = NULL;
397 return;
398 } catch (InvalidName& e) {
399 std::ostringstream msg(std::ostringstream::out);
400 msg << "Error while using ImmediateGenerator:" << endl
401 << e.errorMessage() << endl;
402 verboseLog(msg.str());
403 delete insTemplate;
404 insTemplate = NULL;
405 return;
406 }
407
408 // TODO: split among immediate slots also?
409 Machine::BusNavigator busNav = mach.busNavigator();
410
411 int slotCount = (width_/widthPart_);
412
413 // if too few busses to make even one widthPart_ length template slot
414 if (busNav.count() < slotCount) {
415 slotCount = busNav.count();
416 }
417
418 int overSpill = width_ - (slotCount * widthPart_);
419 int widthAdd = 0;
420 TTAMachine::Bus* busP = NULL;
421 for (int bus = 0; bus < slotCount; bus++) {
422 busP = busNav.item(bus);
423
424 if (overSpill > 0) {
425 if (overSpill < static_cast<int>(
426 busP->width() - widthPart_)) {
427 widthAdd = overSpill;
428 overSpill = -1; // all spilled
429 } else {
430 widthAdd = busP->width() - widthPart_;
431 overSpill = overSpill - widthAdd;
432 }
433 } else {
434 widthAdd = 0;
435 }
436
437 try {
438 insTemplate->addSlot(busP->name(), widthPart_ + widthAdd,
439 *dstImmUnit);
440 } catch (const Exception& e) {
441 std::ostringstream msg(std::ostringstream::out);
442 msg << "Error while using ImmediateGenerator:" << endl
443 << e.errorMessage() << endl;
444 verboseLog(msg.str());
445 delete insTemplate;
446 insTemplate = NULL;
447 return;
448 }
449 }
450
451 // check if all spilled
452 if (overSpill > 0) {
453 std::ostringstream msg(std::ostringstream::out);
454 msg << "Error while using ImmediateGenerator:" << endl
455 << "Immediate template generation failed, width=\"" << width_
456 << "\" too great by: \"" << overSpill << "\"" << endl;
457 verboseLog(msg.str());
458 delete insTemplate;
459 insTemplate = NULL;
460 return;
461 }
462
463 createNewConfig_ = true;
464 }
465};
466
467// parameter names
468const std::string ImmediateGenerator::printPN_("print");
469const std::string ImmediateGenerator::removeInsTemplateNamePN_("remove_it_name");
470const std::string ImmediateGenerator::addInsTemplateNamePN_("add_it_name");
471const std::string ImmediateGenerator::modInsTemplateNamePN_("modify_it_name");
472const std::string ImmediateGenerator::widthPN_("width");
473const std::string ImmediateGenerator::widthPartPN_("width_part");
474const std::string ImmediateGenerator::splitPN_("split");
475const std::string ImmediateGenerator::dstImmUnitNamePN_("dst_imm_unit");
476
#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__)
find Finds info of the inner loops in the false
#define UINT(OPERAND)
Definition OSAL.hh:313
#define BOOL()
static std::string toString(const T &source)
AreaInGates totalArea(const TTAMachine::Machine &machine, const IDF::MachineImplementation &machineImplementation)
area estimation functions
Definition Estimator.cc:84
DelayInNanoSeconds longestPath(const TTAMachine::Machine &machine, const IDF::MachineImplementation &machineImplementation)
delay estimation functions
Definition Estimator.cc:915
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 readCompulsoryParameter(const std::string paramName, T &param) const
virtual std::string name() 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
virtual bool requiresStartingPointArchitecture() const
void addInsTemplate(TTAMachine::Machine &mach, std::string name)
std::string modInsTemplateName_
instruction template name to be modified.
bool createNewConfig_
Boolean value used to decide if new config is created.
virtual std::vector< RowID > explore(const RowID &startPointConfigurationID, const unsigned int &)
static const std::string addInsTemplateNamePN_
virtual bool requiresHDB() const
void removeInsTemplate(TTAMachine::Machine &mach, std::string name)
PLUGIN_DESCRIPTION("Creates immediates for configuration.")
void addSplitInsTemplate(TTAMachine::Machine &mach, std::string name)
std::string dstImmUnitName_
destination immediate unit name
static const std::string splitPN_
virtual bool requiresSimulationData() const
unsigned int widthPart_
minimum width on long instruction slot when splitting the template.
virtual bool requiresApplication() const
static const std::string removeInsTemplateNamePN_
std::string addInsTemplateName_
instruction template name to be added.
std::string removeInsTemplateName_
instruction template name to be removed.
bool print_
print values
unsigned int width_
width of the target template
static const std::string widthPartPN_
static const std::string printPN_
bool split_
make evenly bus/slot wise splitted template.
virtual bool producesArchitecture() const
void printImmediateTemplates(TTAMachine::Machine &mach)
static const std::string widthPN_
static const std::string modInsTemplateNamePN_
static const std::string dstImmUnitNamePN_
int width() const
Definition Bus.cc:149
virtual TCEString name() const
virtual void addSlot(const std::string &slotName, int width, ImmediateUnit &dstUnit)
virtual TemplateSlot * slot(int index) const
ComponentType * item(int index) const
virtual InstructionTemplateNavigator instructionTemplateNavigator() const
Definition Machine.cc:428
virtual void deleteInstructionTemplate(InstructionTemplate &instrTempl)
Definition Machine.cc:599
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
std::string slot() const
ImmediateUnit * destination() const
double AreaInGates
type for area values in equivalent gates
double DelayInNanoSeconds
type for propagation delays in nano seconds