OpenASIP 2.2
Loading...
Searching...
No Matches
ConflictDetectionCodeGenerator.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 ConflictDetectionCodeGenerator.cc
26 *
27 * Definition of ConflictDetectionCodeGenerator class.
28 *
29 * @author Viljami Korhonen 2008 (viljami.korhonen-no.spam-tut.fi)
30 * @note rating: red
31 */
32
35#include "Application.hh"
36#include "Machine.hh"
37#include "FunctionUnit.hh"
38#include "Operation.hh"
39#include "Machine.hh"
40#include "HWOperation.hh"
41#include "Environment.hh"
42
43#include <string>
44#include <sstream>
45
46using std::string;
47using std::endl;
48using namespace TTAMachine;
49
50/**
51 * The constructor.
52 *
53 * Gets the conflict detection settings and initializes the generator
54 * @param machine The machine model
55 *
56 */
59 const CompiledSimSymbolGenerator& symbolGenerator,
60 bool conflictDetectionEnabled) :
61 machine_(machine), conflictDetectionEnabled_(conflictDetectionEnabled),
62 symbolGen_(symbolGenerator) {
63
65 return;
66 }
67
68 string conflictDetectionSetting;
69
70 std::string SETTING =
71 Environment::environmentVariable("TTASIM_CONFLICT_DETECTOR");
72 if (SETTING == "") {
73 conflictDetectionSetting = "AFSA"; // by default
74 } else {
75 conflictDetectionSetting = SETTING;
76 }
77
78 if (conflictDetectionSetting == "CRT") {
79 conflictDetectorType_ = "ReservationTableFUResourceConflictDetector";
80 conflictDetectorMethod_ = "issueOperationInline";
81 conflictDetectorAdvanceCycle_ = "advanceCycle";
83 } else if (conflictDetectionSetting == "AFSA") {
84 conflictDetectorType_ = "FSAFUResourceConflictDetector";
85 conflictDetectorMethod_ = "issueOperationInline";
86 conflictDetectorAdvanceCycle_ = "advanceCycle";
87 conflictDetectorExtraInitMethod_ = "initializeAllStates";
88 } else if (conflictDetectionSetting == "LFSA") {
89 conflictDetectorType_ = "FSAFUResourceConflictDetector";
90 conflictDetectorMethod_ = "issueOperationLazyInline";
91 conflictDetectorAdvanceCycle_ = "advanceCycle";
93 } else if (conflictDetectionSetting == "DCM") {
94 conflictDetectorType_ = "DCMFUResourceConflictDetector";
95 conflictDetectorMethod_ = "issueOperationInline";
96 conflictDetectorAdvanceCycle_ = "advanceCycle";
98 } else {
100 << "Unknown CONFLICT_DETECTION_SETTING: '"
101 << conflictDetectionSetting << "'" << endl;
103 return;
104 }
105
106 // initialize the detectors
108 << "Using conflict detector " << conflictDetectorType_ << std::endl;
109
112 for (int i = 0; i < fus.count(); ++i) {
113 const FunctionUnit& fu = *fus.item(i);
114 if (!fu.needsConflictDetection()) { // no need for conflict detection?
115 continue;
116 } else {
119 }
120 }
121
122 // No conflict detection is needed
123 if (conflictDetectors_.empty()) {
125 }
126}
127
128/**
129 * The destructor
130 */
133
134/**
135 * Generates code for including the conflict detectors
136 * @return The generated code for including the conflict detectors
137 */
138string
140
142 return "";
143
144 std::stringstream ss;
145 ss << "#include \"FSAFUResourceConflictDetector.hh\"" << endl << endl;
146 return ss.str();
147}
148
149/**
150 * Creates symbol declaration code for the given FU's conflict detectors
151 *
152 * @param fu FU to create the conflict detector for
153 * @return The generated symbol declaration code
154 */
155string
157
159 return "";
160
161 std::stringstream ss;
162 ss << "\t" << conflictDetectorType_ << " "
163 << symbolGen_.conflictDetectorSymbol(fu) << ";" << endl;
164
165 return ss.str();
166}
167
168/**
169 * Generates exra initialization call for conflict detectors that require a one
170 *
171 * @return The generated code for extra initialization call
172 */
173string
175 std::stringstream ss;
177 for (ConflictDetectorObjectNameMap::const_iterator i =
178 conflictDetectors_.begin(); i != conflictDetectors_.end(); ++i) {
179 ss << "\t" << i->second << "."
180 << conflictDetectorExtraInitMethod_ << "();" << std::endl;
181 }
182 }
183 return ss.str();
184}
185
186/**
187 * Generates code for notifying of detected conflicts
188 *
189 * @return Generated code for notifying of detected conflicts
190 */
191string
193
195 return "";
196
197 std::stringstream ss;
198 ss << endl
199 << "\tif (conflictDetected_) {" << endl
200 << "\thaltSimulation(__FILE__, __LINE__, __FUNCTION__,"
201 << "\"Conflict detected!\");" << endl
202 << "\t}" << endl;
203
204 return ss.str();
205}
206
207/**
208 * Generates code for notifying of detected conflicts
209 *
210 * @return Generated code for notifying of detected conflicts
211 */
212string
215 return "";
216
217 std::stringstream ss;
218
219 for (ConflictDetectorObjectNameMap::const_iterator i =
220 conflictDetectors_.begin(); i != conflictDetectors_.end(); ++i) {
221 ss << "\t," << i->second
222 << "(functionUnit(\"" << i->first << "\"))"
223 << endl;
224 }
225 return ss.str();
226}
227
228/**
229 * Generates code for a function that advances clocks of each conflict detector
230 *
231 * @return A std::string containing generated code for the clock advances
232 */
233string
235
237 return "";
238
239 std::stringstream ss;
240 // advance clock of all conflict detection models
241 for (ConflictDetectorObjectNameMap::const_iterator i =
242 conflictDetectors_.begin(); i != conflictDetectors_.end(); ++i) {
243 ss << "\t" << (*i).second << "."
244 << conflictDetectorAdvanceCycle_ << "();" << endl;
245 }
246
247 return ss.str();
248}
249
250/**
251 * Generates code for detecting an FU pipeline resource conflicts.
252 *
253 * @param op the triggered operation
254 * @return A std::string containing generated code for the operation call
255 */
256string
258 const TTAMachine::HWOperation& op) {
259
261 return "";
262
263 const TTAMachine::FunctionUnit& fu = *op.parentUnit();
264
265 if (conflictDetectors_.find(fu.name()) == conflictDetectors_.end())
266 return ""; // no conflict detection for the FU of the given operation
267
268 int operationID = -1;
269 for (int i = 0; i < fu.operationCount(); ++i) {
270 if (fu.operation(i)->name() == op.name()) {
271 operationID = i;
272 break;
273 }
274 }
275 std::stringstream ss;
276 std::string detector = conflictDetectors_[fu.name()];
277 ss << "engine.conflictDetected_ |= !engine." << detector << "."
278 << conflictDetectorMethod_ << "(" << operationID << ");" << endl;
279 return ss.str();
280}
281
282/**
283 * Returns a boolean describing if the conflict detection is enabled or not
284 *
285 * @return True if the conflict detection is enabled
286 */
287bool
291
TTAMachine::Machine * machine
the architecture definition of the estimated processor
static std::ostream & logStream()
std::string conflictDetectorSymbol(const TTAMachine::FunctionUnit &fu) const
std::string conflictDetectorType_
The FU resource conflict detector used, empty string if disabled.
const TTAMachine::Machine & machine_
The machine.
std::string symbolDeclaration(const TTAMachine::FunctionUnit &fu)
ConflictDetectionCodeGenerator(const TTAMachine::Machine &machine, const CompiledSimSymbolGenerator &, bool conflictDetectionEnabled=false)
std::string conflictDetectorMethod_
The method in the resource conflict detector used to detect conflicts, empty string if disabled.
std::string conflictDetectorAdvanceCycle_
The method to be called on the conflict detector on cycle advance.
ConflictDetectorObjectNameMap conflictDetectors_
The resource conflict detector object name for each FU if any.
std::string detectConflicts(const TTAMachine::HWOperation &op)
std::string conflictDetectorExtraInitMethod_
A method to be called on the conflict detector for initialization, empty if none.
const CompiledSimSymbolGenerator & symbolGen_
Symbol generator.
bool conflictDetectionEnabled_
True, if the conflict detection is enabled.
static std::string environmentVariable(const std::string &variable)
virtual TCEString name() const
virtual HWOperation * operation(const std::string &name) const
virtual int operationCount() const
bool needsConflictDetection() const
const std::string & name() const
FunctionUnit * parentUnit() const
ComponentType * item(int index) const
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380