OpenASIP  2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ConflictDetectionCodeGenerator Class Reference

#include <ConflictDetectionCodeGenerator.hh>

Collaboration diagram for ConflictDetectionCodeGenerator:
Collaboration graph

Public Member Functions

 ConflictDetectionCodeGenerator (const TTAMachine::Machine &machine, const CompiledSimSymbolGenerator &, bool conflictDetectionEnabled=false)
 
virtual ~ConflictDetectionCodeGenerator ()
 
std::string includes ()
 
std::string symbolDeclaration (const TTAMachine::FunctionUnit &fu)
 
std::string extraInitialization ()
 
std::string notifyOfConflicts ()
 
std::string updateSymbolDeclarations ()
 
std::string advanceClockCode ()
 
std::string detectConflicts (const TTAMachine::HWOperation &op)
 
bool conflictDetectionEnabled () const
 

Private Types

typedef std::map< std::string, std::string > ConflictDetectorObjectNameMap
 1=fu.name(), 2=conflict detector object name More...
 

Private Member Functions

 ConflictDetectionCodeGenerator (const ConflictDetectionCodeGenerator &)
 Copying not allowed. More...
 
ConflictDetectionCodeGeneratoroperator= (const ConflictDetectionCodeGenerator &)
 Assignment not allowed. More...
 

Private Attributes

const TTAMachine::Machinemachine_
 The machine. More...
 
bool conflictDetectionEnabled_
 True, if the conflict detection is enabled. More...
 
std::string conflictDetectorType_
 The FU resource conflict detector used, empty string if disabled. More...
 
std::string conflictDetectorMethod_
 The method in the resource conflict detector used to detect conflicts, empty string if disabled. More...
 
std::string conflictDetectorAdvanceCycle_
 The method to be called on the conflict detector on cycle advance. More...
 
std::string conflictDetectorExtraInitMethod_
 A method to be called on the conflict detector for initialization, empty if none. More...
 
ConflictDetectorObjectNameMap conflictDetectors_
 The resource conflict detector object name for each FU if any. More...
 
const CompiledSimSymbolGeneratorsymbolGen_
 Symbol generator. More...
 

Detailed Description

A class that generates C/C++ code for FU conflict detection cases

Used for the compiled simulation

Definition at line 67 of file ConflictDetectionCodeGenerator.hh.

Member Typedef Documentation

◆ ConflictDetectorObjectNameMap

typedef std::map<std::string, std::string> ConflictDetectionCodeGenerator::ConflictDetectorObjectNameMap
private

1=fu.name(), 2=conflict detector object name

Definition at line 109 of file ConflictDetectionCodeGenerator.hh.

Constructor & Destructor Documentation

◆ ConflictDetectionCodeGenerator() [1/2]

ConflictDetectionCodeGenerator::ConflictDetectionCodeGenerator ( const TTAMachine::Machine machine,
const CompiledSimSymbolGenerator symbolGenerator,
bool  conflictDetectionEnabled = false 
)

The constructor.

Gets the conflict detection settings and initializes the generator

Parameters
machineThe machine model

Definition at line 57 of file ConflictDetectionCodeGenerator.cc.

60  :
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 
110  const Machine::FunctionUnitNavigator& fus =
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 {
117  conflictDetectors_[fu.name()] =
119  }
120  }
121 
122  // No conflict detection is needed
123  if (conflictDetectors_.empty()) {
125  }
126 }

References conflictDetectionEnabled(), conflictDetectionEnabled_, conflictDetectorAdvanceCycle_, conflictDetectorExtraInitMethod_, conflictDetectorMethod_, conflictDetectors_, CompiledSimSymbolGenerator::conflictDetectorSymbol(), conflictDetectorType_, TTAMachine::Machine::Navigator< ComponentType >::count(), Environment::environmentVariable(), TTAMachine::Machine::functionUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), Application::logStream(), machine_, TTAMachine::Component::name(), TTAMachine::FunctionUnit::needsConflictDetection(), and symbolGen_.

Here is the call graph for this function:

◆ ~ConflictDetectionCodeGenerator()

ConflictDetectionCodeGenerator::~ConflictDetectionCodeGenerator ( )
virtual

The destructor

Definition at line 131 of file ConflictDetectionCodeGenerator.cc.

131  {
132 }

◆ ConflictDetectionCodeGenerator() [2/2]

ConflictDetectionCodeGenerator::ConflictDetectionCodeGenerator ( const ConflictDetectionCodeGenerator )
private

Copying not allowed.

Member Function Documentation

◆ advanceClockCode()

string ConflictDetectionCodeGenerator::advanceClockCode ( )

Generates code for a function that advances clocks of each conflict detector

Returns
A std::string containing generated code for the clock advances

Definition at line 234 of file ConflictDetectionCodeGenerator.cc.

234  {
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 }

References conflictDetectionEnabled_, conflictDetectorAdvanceCycle_, and conflictDetectors_.

Referenced by CompiledSimCodeGenerator::generateAdvanceClockCode().

◆ conflictDetectionEnabled()

bool ConflictDetectionCodeGenerator::conflictDetectionEnabled ( ) const

Returns a boolean describing if the conflict detection is enabled or not

Returns
True if the conflict detection is enabled

Definition at line 288 of file ConflictDetectionCodeGenerator.cc.

288  {
290 }

References conflictDetectionEnabled_.

Referenced by ConflictDetectionCodeGenerator(), CompiledSimCodeGenerator::generateHeaderAndMainCode(), and CompiledSimCodeGenerator::generateInstruction().

◆ detectConflicts()

string ConflictDetectionCodeGenerator::detectConflicts ( const TTAMachine::HWOperation op)

Generates code for detecting an FU pipeline resource conflicts.

Parameters
opthe triggered operation
Returns
A std::string containing generated code for the operation call

Definition at line 257 of file ConflictDetectionCodeGenerator.cc.

258  {
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 }

References conflictDetectionEnabled_, conflictDetectorMethod_, conflictDetectors_, TTAMachine::HWOperation::name(), TTAMachine::Component::name(), TTAMachine::FunctionUnit::operation(), TTAMachine::FunctionUnit::operationCount(), and TTAMachine::HWOperation::parentUnit().

Referenced by CompiledSimCodeGenerator::generateInstruction().

Here is the call graph for this function:

◆ extraInitialization()

string ConflictDetectionCodeGenerator::extraInitialization ( )

Generates exra initialization call for conflict detectors that require a one

Returns
The generated code for extra initialization call

Definition at line 174 of file ConflictDetectionCodeGenerator.cc.

174  {
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 }

References conflictDetectionEnabled_, conflictDetectorExtraInitMethod_, and conflictDetectors_.

Referenced by CompiledSimCodeGenerator::generateConstructorCode().

◆ includes()

string ConflictDetectionCodeGenerator::includes ( )

Generates code for including the conflict detectors

Returns
The generated code for including the conflict detectors

Definition at line 139 of file ConflictDetectionCodeGenerator.cc.

139  {
140 
142  return "";
143 
144  std::stringstream ss;
145  ss << "#include \"FSAFUResourceConflictDetector.hh\"" << endl << endl;
146  return ss.str();
147 }

References conflictDetectionEnabled_.

Referenced by CompiledSimCodeGenerator::generateHeaderAndMainCode().

◆ notifyOfConflicts()

string ConflictDetectionCodeGenerator::notifyOfConflicts ( )

Generates code for notifying of detected conflicts

Returns
Generated code for notifying of detected conflicts

Definition at line 192 of file ConflictDetectionCodeGenerator.cc.

192  {
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 }

References conflictDetectionEnabled_.

Referenced by CompiledSimCodeGenerator::generateConstructorCode().

◆ operator=()

ConflictDetectionCodeGenerator& ConflictDetectionCodeGenerator::operator= ( const ConflictDetectionCodeGenerator )
private

Assignment not allowed.

◆ symbolDeclaration()

string ConflictDetectionCodeGenerator::symbolDeclaration ( const TTAMachine::FunctionUnit fu)

Creates symbol declaration code for the given FU's conflict detectors

Parameters
fuFU to create the conflict detector for
Returns
The generated symbol declaration code

Definition at line 156 of file ConflictDetectionCodeGenerator.cc.

156  {
157 
159  return "";
160 
161  std::stringstream ss;
162  ss << "\t" << conflictDetectorType_ << " "
163  << symbolGen_.conflictDetectorSymbol(fu) << ";" << endl;
164 
165  return ss.str();
166 }

References conflictDetectionEnabled_, CompiledSimSymbolGenerator::conflictDetectorSymbol(), conflictDetectorType_, TTAMachine::FunctionUnit::needsConflictDetection(), and symbolGen_.

Referenced by CompiledSimCodeGenerator::generateHeaderAndMainCode().

Here is the call graph for this function:

◆ updateSymbolDeclarations()

string ConflictDetectionCodeGenerator::updateSymbolDeclarations ( )

Generates code for notifying of detected conflicts

Returns
Generated code for notifying of detected conflicts

Definition at line 213 of file ConflictDetectionCodeGenerator.cc.

213  {
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 }

References conflictDetectionEnabled_, and conflictDetectors_.

Referenced by CompiledSimCodeGenerator::updateDeclaredSymbolsList().

Member Data Documentation

◆ conflictDetectionEnabled_

bool ConflictDetectionCodeGenerator::conflictDetectionEnabled_
private

◆ conflictDetectorAdvanceCycle_

std::string ConflictDetectionCodeGenerator::conflictDetectorAdvanceCycle_
private

The method to be called on the conflict detector on cycle advance.

Definition at line 103 of file ConflictDetectionCodeGenerator.hh.

Referenced by advanceClockCode(), and ConflictDetectionCodeGenerator().

◆ conflictDetectorExtraInitMethod_

std::string ConflictDetectionCodeGenerator::conflictDetectorExtraInitMethod_
private

A method to be called on the conflict detector for initialization, empty if none.

Definition at line 106 of file ConflictDetectionCodeGenerator.hh.

Referenced by ConflictDetectionCodeGenerator(), and extraInitialization().

◆ conflictDetectorMethod_

std::string ConflictDetectionCodeGenerator::conflictDetectorMethod_
private

The method in the resource conflict detector used to detect conflicts, empty string if disabled.

Definition at line 101 of file ConflictDetectionCodeGenerator.hh.

Referenced by ConflictDetectionCodeGenerator(), and detectConflicts().

◆ conflictDetectors_

ConflictDetectorObjectNameMap ConflictDetectionCodeGenerator::conflictDetectors_
private

The resource conflict detector object name for each FU if any.

Definition at line 111 of file ConflictDetectionCodeGenerator.hh.

Referenced by advanceClockCode(), ConflictDetectionCodeGenerator(), detectConflicts(), extraInitialization(), and updateSymbolDeclarations().

◆ conflictDetectorType_

std::string ConflictDetectionCodeGenerator::conflictDetectorType_
private

The FU resource conflict detector used, empty string if disabled.

Definition at line 98 of file ConflictDetectionCodeGenerator.hh.

Referenced by ConflictDetectionCodeGenerator(), and symbolDeclaration().

◆ machine_

const TTAMachine::Machine& ConflictDetectionCodeGenerator::machine_
private

The machine.

Definition at line 92 of file ConflictDetectionCodeGenerator.hh.

Referenced by ConflictDetectionCodeGenerator().

◆ symbolGen_

const CompiledSimSymbolGenerator& ConflictDetectionCodeGenerator::symbolGen_
private

Symbol generator.

Definition at line 114 of file ConflictDetectionCodeGenerator.hh.

Referenced by ConflictDetectionCodeGenerator(), and symbolDeclaration().


The documentation for this class was generated from the following files:
ConflictDetectionCodeGenerator::conflictDetectorExtraInitMethod_
std::string conflictDetectorExtraInitMethod_
A method to be called on the conflict detector for initialization, empty if none.
Definition: ConflictDetectionCodeGenerator.hh:106
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
ConflictDetectionCodeGenerator::conflictDetectors_
ConflictDetectorObjectNameMap conflictDetectors_
The resource conflict detector object name for each FU if any.
Definition: ConflictDetectionCodeGenerator.hh:111
ConflictDetectionCodeGenerator::symbolGen_
const CompiledSimSymbolGenerator & symbolGen_
Symbol generator.
Definition: ConflictDetectionCodeGenerator.hh:114
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
ConflictDetectionCodeGenerator::conflictDetectionEnabled
bool conflictDetectionEnabled() const
Definition: ConflictDetectionCodeGenerator.cc:288
TTAMachine::Machine::Navigator::count
int count() const
ConflictDetectionCodeGenerator::conflictDetectorAdvanceCycle_
std::string conflictDetectorAdvanceCycle_
The method to be called on the conflict detector on cycle advance.
Definition: ConflictDetectionCodeGenerator.hh:103
ConflictDetectionCodeGenerator::machine_
const TTAMachine::Machine & machine_
The machine.
Definition: ConflictDetectionCodeGenerator.hh:92
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::HWOperation::name
const std::string & name() const
Definition: HWOperation.cc:141
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
ConflictDetectionCodeGenerator::conflictDetectorType_
std::string conflictDetectorType_
The FU resource conflict detector used, empty string if disabled.
Definition: ConflictDetectionCodeGenerator.hh:98
TTAMachine::HWOperation::parentUnit
FunctionUnit * parentUnit() const
Definition: HWOperation.cc:190
TTAMachine::FunctionUnit::needsConflictDetection
bool needsConflictDetection() const
Definition: FunctionUnit.cc:804
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
Environment::environmentVariable
static std::string environmentVariable(const std::string &variable)
Definition: Environment.cc:406
ConflictDetectionCodeGenerator::conflictDetectorMethod_
std::string conflictDetectorMethod_
The method in the resource conflict detector used to detect conflicts, empty string if disabled.
Definition: ConflictDetectionCodeGenerator.hh:101
CompiledSimSymbolGenerator::conflictDetectorSymbol
std::string conflictDetectorSymbol(const TTAMachine::FunctionUnit &fu) const
Definition: CompiledSimSymbolGenerator.cc:270
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
ConflictDetectionCodeGenerator::conflictDetectionEnabled_
bool conflictDetectionEnabled_
True, if the conflict detection is enabled.
Definition: ConflictDetectionCodeGenerator.hh:95