OpenASIP  2.0
ComponentAdder.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2011 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 ComponentAdder.cc
26  *
27  * Explorer plugin that adds machine components to a given machine.
28  *
29  * @author Esa Määttä 2008 (esa.maatta-no.spam-tut.fi)
30  * @author Pekka Jääskeläinen 2011
31  * @note rating: red
32  */
33 
34 #include <vector>
35 #include <string>
37 #include "DSDBManager.hh"
38 #include "Machine.hh"
39 #include "HDBRegistry.hh"
40 #include "StringTools.hh"
41 #include "RFPort.hh"
43 #include "Exception.hh"
44 #include "Conversion.hh"
45 
46 //using namespace TTAProgram;
47 using namespace TTAMachine;
48 using namespace HDB;
49 using std::endl;
50 
51 /**
52  * Explorer plugin that adds machine components to a given machine.
53  *
54  * Supported parameters:
55  * - rf_size, number of registers in one register file, default is 4
56  * - max_rfs, maximum number of register files in the machine, default is 16
57  * - rf_reads, number of register read ports in register files, default is 1
58  * - rf_writes, number of register write ports in register file, default is 1
59  * - build_idf, if parameter is set the idf file is built, not set as default
60  * - adf, if idf is wanted to generated to some arhitecture, no default value.
61  * If adf parameter is given the idf is built.
62  */
64  PLUGIN_DESCRIPTION("Explorer plugin that adds machine components to a "
65  "given machine.");
66 
68  RFName_("rf"),
69  RFCount_(1),
70  RFSize_(4),
71  RFReadPorts_(1),
72  RFWritePorts_(1),
73  adf_(""),
74  buildIdf_(false) {
75 
76  // compulsory parameters
77  // no compulsory parameters
78 
79  // parameters that have a default value
80  addParameter(RFNamePN_, STRING, false, RFName_);
81  addParameter(RFCountPN_, UINT, false, Conversion::toString(RFCount_));
82  addParameter(RFSizePN_, UINT, false, Conversion::toString(RFSize_));
83  addParameter(RFReadPortsPN_, UINT, false, Conversion::toString(RFReadPorts_));
84  addParameter(RFWritePortsPN_, UINT, false, Conversion::toString(RFWritePorts_));
85  addParameter(adfPN_, STRING, false, adf_);
86  addParameter(buildIdfPN_, BOOL, false, Conversion::toString(buildIdf_));
87  }
88 
89  virtual bool requiresStartingPointArchitecture() const { return false; }
90  virtual bool producesArchitecture() const { return true; }
91  virtual bool requiresHDB() const { return false; }
92  virtual bool requiresSimulationData() const { return true; }
93  virtual bool requiresApplication() const { return false; }
94 
95  /**
96  * Explorer plugin that adds machine components to a given machine with
97  * adf parameter or with configuration id in dsdb.
98  */
99  virtual std::vector<RowID>
100  explore(const RowID& configurationID, const unsigned int&) {
101  readParameters();
102  std::vector<RowID> result;
103 
104  // check if adf given
105  if (configurationID == 0 && adf_ == "") {
106  std::ostringstream msg(std::ostringstream::out);
107  msg << "No configuration nor adf defined. Use -s <confID> to "
108  << "define the configuration to be optimized or give adf "
109  << "as plugin parameter." << endl;
110  verboseLog(msg.str());
111  return result;
112  }
113 
114  DSDBManager& dsdb = db();
116  conf.hasImplementation = false;
117  TTAMachine::Machine* mach = NULL;
118 
119  // load the adf from file or from dsdb
120  try {
121  if (adf_ != "") {
123  } else {
124  conf = dsdb.configuration(configurationID);
125  mach = dsdb.architecture(conf.architectureID);
126  }
127  } catch (const Exception& e) {
128  std::ostringstream msg(std::ostringstream::out);
129  msg << "Error loading the adf." << std::endl;
130  verboseLog(msg.str());
131  return result;
132  }
133  assert(mach != NULL);
134 
135  // add components
136  addComponents(mach);
137 
138  if (buildIdf_) {
139  try {
140  // add idf to configuration
141  selector_.selectComponentsToConf(conf, dsdb, mach);
142  } catch (const Exception& e) {
143  std::ostringstream msg(std::ostringstream::out);
144  msg << e.errorMessage()
145  << " " << e.fileName()
146  << " " << e.lineNum() << std::endl;
147  verboseLog(msg.str());
148  }
149  } else {
150  conf.hasImplementation = false;
151  }
152 
153  // add machine to configuration
154  conf.architectureID = dsdb.addArchitecture(*mach);
155 
156  // add new configuration to dsdb
157  RowID confID = dsdb.addConfiguration(conf);
158  result.push_back(confID);
159  return result;
160  }
161 
162 private:
163  /// Selector used by the plugin.
165 
166  static const std::string RFNamePN_;
167  static const std::string RFCountPN_;
168  static const std::string RFSizePN_;
169  static const std::string RFReadPortsPN_;
170  static const std::string RFWritePortsPN_;
171  static const std::string adfPN_;
172  static const std::string buildIdfPN_;
173 
174  // register file variables
175  std::string RFName_;
176  int RFCount_;
177  int RFSize_;
180  /// name of the adf file if wanted to use idf generation
181  std::string adf_;
182  /// do we build idf
183  bool buildIdf_;
184 
185  /**
186  * Reads the parameters given to the plugin.
187  */
188  void readParameters() {
189  readOptionalParameter(RFNamePN_, RFName_);
190  readOptionalParameter(RFCountPN_, RFCount_);
191  readOptionalParameter(RFSizePN_, RFSize_);
192  readOptionalParameter(RFReadPortsPN_, RFReadPorts_);
193  readOptionalParameter(RFWritePortsPN_, RFWritePorts_);
194  readOptionalParameter(adfPN_, adf_);
195  readOptionalParameter(buildIdfPN_, buildIdf_);
196  }
197 
198 
199  /**
200  * Builds the machine in basis of the analyzed data from the applications.
201  *
202  * @return The initial machine of NULL if an error occurred.
203  */
205  // add register files
206  addRegisterFiles(mach);
207  }
208 
209 
210  /**
211  * Adds register file(s) to the machine
212  *
213  * TODO: add type and guard latency setting
214  *
215  * @return void
216  */
218  for (int i = 0; i < RFCount_; i++) {
219  std::string RFName = RFName_ + Conversion::toString(i);
220 
222  mach->registerFileNavigator();
223  if (RFNav.hasItem(RFName)) {
224  RFName = RFName_ + Conversion::toString(i+RFNav.count());
225  }
226 
228  RFName, RFSize_, 32, RFReadPorts_, RFWritePorts_, 0,
230  for (int n = 0; n < RFReadPorts_; n++) {
231  new TTAMachine::RFPort("read" +
232  Conversion::toString( + 1), *rf);
233  }
234  for (int n = 0; n < RFWritePorts_; n++) {
235  new TTAMachine::RFPort("write" +
236  Conversion::toString(n + 1), *rf);
237  }
238  try {
239  mach->addRegisterFile(*rf);
240  } catch (const ComponentAlreadyExists& e) {
241  verboseLog("ComponentAdder: Tried to add RF with a already"
242  "existing name (" + RFName)
244  }
245  }
246  }
247 };
248 
249 // parameters
250 const std::string ComponentAdder::RFNamePN_("rf_name");
251 const std::string ComponentAdder::RFCountPN_("rf_count");
252 const std::string ComponentAdder::RFSizePN_("rf_size");
253 const std::string ComponentAdder::RFReadPortsPN_("rf_reads");
254 const std::string ComponentAdder::RFWritePortsPN_("rf_writes");
255 const std::string ComponentAdder::adfPN_("adf");
256 const std::string ComponentAdder::buildIdfPN_("build_idf");
257 
ComponentAdder::ComponentAdder
ComponentAdder()
Definition: ComponentAdder.cc:67
Exception::lineNum
int lineNum() const
HDB
Definition: CostDatabase.hh:49
ComponentAdder::producesArchitecture
virtual bool producesArchitecture() const
Definition: ComponentAdder.cc:90
Exception.hh
UINT
@ UINT
Definition: ExplorerPluginParameter.hh:40
DSDBManager::architecture
TTAMachine::Machine * architecture(RowID id) const
Definition: DSDBManager.cc:807
DSDBManager::MachineConfiguration::hasImplementation
bool hasImplementation
Definition: DSDBManager.hh:80
Application::exitProgram
static void exitProgram(const int status=EXIT_SUCCESS)
Definition: Application.cc:258
ComponentAdder
Definition: ComponentAdder.cc:63
ComponentAdder::RFWritePorts_
int RFWritePorts_
Definition: ComponentAdder.cc:179
DesignSpaceExplorerPlugin
Definition: DesignSpaceExplorerPlugin.hh:55
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
ComponentAdder::RFReadPorts_
int RFReadPorts_
Definition: ComponentAdder.cc:178
ComponentAdder::requiresHDB
virtual bool requiresHDB() const
Definition: ComponentAdder.cc:91
TTAMachine::Machine::Navigator::count
int count() const
Conversion::toString
static std::string toString(const T &source)
DesignSpaceExplorerPlugin.hh
verboseLog
#define verboseLog(text)
Definition: Application.hh:115
TTAMachine::RFPort
Definition: RFPort.hh:45
ComponentAdder::buildIdf_
bool buildIdf_
do we build idf
Definition: ComponentAdder.cc:183
ComponentAdder::adf_
std::string adf_
name of the adf file if wanted to use idf generation
Definition: ComponentAdder.cc:181
BOOL
@ BOOL
Definition: ExplorerPluginParameter.hh:40
Exception::fileName
std::string fileName() const
ComponentAdder::selector_
ComponentImplementationSelector selector_
Selector used by the plugin.
Definition: ComponentAdder.cc:164
StringTools.hh
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::Machine::addRegisterFile
virtual void addRegisterFile(RegisterFile &unit)
Definition: Machine.cc:236
ComponentAdder::RFNamePN_
static const std::string RFNamePN_
Definition: ComponentAdder.cc:166
ComponentAdder::requiresSimulationData
virtual bool requiresSimulationData() const
Definition: ComponentAdder.cc:92
ComponentAdder::requiresApplication
virtual bool requiresApplication() const
Definition: ComponentAdder.cc:93
DSDBManager::MachineConfiguration
Definition: DSDBManager.hh:78
PLUGIN_DESCRIPTION
const std::string PLUGIN_DESCRIPTION
Definition: DefaultICDecoderPlugin.cc:917
STRING
@ STRING
Definition: ExplorerPluginParameter.hh:40
EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN
#define EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN(PLUGIN_NAME__)
Definition: DesignSpaceExplorerPlugin.hh:125
ComponentAdder::buildIdfPN_
static const std::string buildIdfPN_
Definition: ComponentAdder.cc:172
Conversion.hh
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
ComponentAdder::RFSize_
int RFSize_
Definition: ComponentAdder.cc:177
ComponentAdder::RFWritePortsPN_
static const std::string RFWritePortsPN_
Definition: ComponentAdder.cc:170
ComponentAdder::explore
virtual std::vector< RowID > explore(const RowID &configurationID, const unsigned int &)
Definition: ComponentAdder.cc:100
Machine.hh
Exception
Definition: Exception.hh:54
DSDBManager
Definition: DSDBManager.hh:76
ComponentAdder::RFCountPN_
static const std::string RFCountPN_
Definition: ComponentAdder.cc:167
ComponentImplementationSelector.hh
ComponentAdder::adfPN_
static const std::string adfPN_
Definition: ComponentAdder.cc:171
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
DSDBManager.hh
DSDBManager::addConfiguration
RowID addConfiguration(const MachineConfiguration &conf)
Definition: DSDBManager.cc:299
ComponentImplementationSelector
Definition: ComponentImplementationSelector.hh:74
DSDBManager::addArchitecture
RowID addArchitecture(const TTAMachine::Machine &mom)
Definition: DSDBManager.cc:191
TTAMachine::Machine::registerFileNavigator
virtual RegisterFileNavigator registerFileNavigator() const
Definition: Machine.cc:450
DSDBManager::configuration
MachineConfiguration configuration(RowID id) const
Definition: DSDBManager.cc:361
ComponentAdder::addComponents
void addComponents(TTAMachine::Machine *mach)
Definition: ComponentAdder.cc:204
ComponentAdder::readParameters
void readParameters()
Definition: ComponentAdder.cc:188
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
ComponentAdder::addRegisterFiles
void addRegisterFiles(TTAMachine::Machine *mach)
Definition: ComponentAdder.cc:217
ComponentAdder::RFReadPortsPN_
static const std::string RFReadPortsPN_
Definition: ComponentAdder.cc:169
TTAMachine::RegisterFile::NORMAL
@ NORMAL
Used for general register allocation.
Definition: RegisterFile.hh:51
ComponentAlreadyExists
Definition: Exception.hh:510
ComponentAdder::RFName_
std::string RFName_
Definition: ComponentAdder.cc:175
ComponentAdder::RFSizePN_
static const std::string RFSizePN_
Definition: ComponentAdder.cc:168
RFPort.hh
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
TTAMachine
Definition: Assembler.hh:48
ComponentAdder::requiresStartingPointArchitecture
virtual bool requiresStartingPointArchitecture() const
Definition: ComponentAdder.cc:89
HDBRegistry.hh
DSDBManager::MachineConfiguration::architectureID
RowID architectureID
Definition: DSDBManager.hh:79
ComponentAdder::RFCount_
int RFCount_
Definition: ComponentAdder.cc:176
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
TTAMachine::Machine
Definition: Machine.hh:73
TTAMachine::Machine::loadFromADF
static Machine * loadFromADF(const std::string &adfFileName)
Definition: Machine.cc:905