OpenASIP  2.0
FSAFUResourceConflictDetector.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 FSAFUResourceConflictDetector.cc
26  *
27  * Definition of FSAFUResourceConflictDetector class.
28  *
29  * @author Pekka Jääskeläinen 2006 (pjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
34 #include "StringTools.hh"
35 #include "ResourceVectorSet.hh"
37 #include "Machine.hh"
38 #include "TCEString.hh"
39 #include <fstream>
40 #include <string>
41 
42 /**
43  * Constructor.
44  *
45  * Initializes the FSA to a lazy mode in which the states are built when
46  * they are needed the first time. In order to initialize all states,
47  * call initializeAllStates().
48  *
49  * @param fu The function unit to detect conflicts for.
50  * @exception InvalidData If the model could not be built from the given FU.
51  */
53  const TTAMachine::FunctionUnit& fu) :
55  pimpl_(new FSAFUResourceConflictDetectorPimpl(fu)) {
57 }
58 
59 /**
60  * Destructor.
61  */
63  delete pimpl_;
64  pimpl_ = NULL;
65 }
66 
67 /**
68  * Initializes all states in the state machine.
69  *
70  * By default, only the initial state is constructed and rest when
71  * visited the first time.
72  */
73 void
76 }
77 
78 /**
79  * Writes the state machine to a Graphviz dot file.
80  *
81  * @param fileName The file name.
82  */
83 void
85  const TCEString& fileName) const {
86 
87  std::ofstream dot(fileName.c_str());
88  dot << pimpl_->fsa_.toDotString() << std::endl;
89  dot.close();
90 }
91 
92 /**
93  * Issues an operation and reports a conflict if detected.
94  *
95  * @param id The id of the operation to issue.
96  * @return False in case a conflict is detected, otherwise true.
97  */
98 bool
100  return issueOperationLazyInline(id);
101 }
102 
103 /**
104  * Returns the name of the operation associated to the given transition id.
105  *
106  * @param id The transition id.
107  * @return The name of the operation.
108  */
109 const char*
111  return pimpl_->fsa_.transitionName(id).c_str();
112 }
113 
114 /**
115  * Simulates a cycle advance and reports a conflict if detected.
116  *
117  * @return False in case a conflict is detected, otherwise true.
118  */
119 bool
121  return advanceCycleLazyInline();
122 }
123 
124 /**
125  * Returns an operation id for the given operation.
126  *
127  * Operation IDs are used in the interface for optimizing the access. This
128  * method converts OSAL Operations to operation IDs.
129  *
130  * @param operation The OSAL Operation to find ID for.
131  * @return The operation ID.
132  */
135  const TCEString& operationName) const {
136 
137  return pimpl_->fsa_.transitionIndex(
139 }
140 
141 /**
142  * Sets the state of the detector to its initial state.
143  *
144  * This means that the FU state is assumed to be what it is in powerup.
145  */
146 void
150 }
151 
152 /**
153  * The FSA FU model is considered to be idle when the FSA is at start state and
154  * there are no new operations issued at that state.
155  */
156 bool
158  return pimpl_->currentState_ == pimpl_->fsa_.startState()
160 }
161 
162 /**
163  * @file FSAFUResourceConflictDetector.icc
164  *
165  * Inline implementations of FSAFUResourceConflictDetector class.
166  *
167  * @author Pekka Jääskeläinen 2007 (pjaaskel-no.spam-cs.tut.fi)
168  * @note rating: red
169  */
170 
171 /**
172  * Issues an operation and reports a conflict if detected.
173  *
174  * Inlineable optimized version for compiled simulation and benchmarking.
175  * All states are assumed initialized. For lazily initialized FSA, use
176  * issueOperationLazyInline(). This version has about balanced runtime for
177  * conflict and no-conflict cases for sensible benchmarking with random
178  * operation sequences.
179  *
180  * @param id The id of the operation to issue.
181  * @return False in case a conflict is detected, otherwise true.
182  */
183 bool
185 
188  pimpl_->nextState_ = 0;
189  return false;
190  }
191  return true;
192 }
193 
194 /**
195  * Issues an operation and reports a conflict if detected.
196  *
197  * Inlineable optimized version for compiled simulation and benchmarking.
198  * For lazily initialized FSA. Checks if a state is missing and constructs
199  * it if needed.
200  *
201  * @param id The id of the operation to issue.
202  * @return False in case a conflict is detected, otherwise true.
203  */
204 bool
206 
210  }
212  pimpl_->nextState_ = 0;
213  return false;
214  }
215  return true;
216 }
217 
218 /**
219  * Simulates a cycle advance and reports a conflict if detected.
220  *
221  * Inlineable optimized version for compiled simulation and benchmarking.
222  *
223  * @note Do not call this in case the last operation issue transfered
224  * the FSA to the illegal state! That is, returned false. No checking is
225  * done to get fastest possible simulation.
226  *
227  * @return False in case a conflict is detected, otherwise true.
228  */
229 inline bool
231 
232  // assert(nextState_ != FiniteStateAutomaton::ILLEGAL_STATE);
234  // issue NOP transition at the next cycle in case there are no other
235  // operation issues
237  fsa_.transitions_[pimpl_->currentState_][pimpl_->NOP];
238  return true;
239 }
240 
241 /**
242  * Simulates a cycle advance and reports a conflict if detected.
243  *
244  * Inlineable optimized version for compiled simulation and benchmarking.
245  *
246  * @note Do not call this in case the last operation issue transfered
247  * the FSA to the illegal state! That is, returned false. No checking is
248  * done to get fastest possible simulation.
249  *
250  * @return False in case a conflict is detected, otherwise true.
251  */
252 inline bool
254 
255  // assert(nextState_ != FiniteStateAutomaton::ILLEGAL_STATE);
257  // issue NOP transition at the next cycle in case there are no other
258  // operation issues
263  }
264  return true;
265 }
266 
FSAFUResourceConflictDetector::isIdle
virtual bool isIdle()
Definition: FSAFUResourceConflictDetector.cc:157
FSAFUResourceConflictDetector::advanceCycleLazyInline
bool advanceCycleLazyInline()
Definition: FSAFUResourceConflictDetector.cc:253
FiniteStateAutomaton::ILLEGAL_STATE
static const FSAStateIndex ILLEGAL_STATE
A state id which denotes an illegal state.
Definition: FiniteStateAutomaton.hh:61
FiniteStateAutomaton::transitions_
TransitionMap transitions_
The state transitions. In protected to allow fast access from derived classes.
Definition: FiniteStateAutomaton.hh:120
FiniteStateAutomaton::startState
virtual FSAStateIndex startState() const
Definition: FiniteStateAutomaton.cc:282
FiniteStateAutomaton::transitionName
virtual const std::string & transitionName(FSAStateTransitionIndex transition) const
Definition: FiniteStateAutomaton.cc:81
ResourceVectorSet.hh
FSAFUResourceConflictDetector::reset
virtual void reset()
Definition: FSAFUResourceConflictDetector.cc:147
FSAFUResourceConflictDetectorPimpl::currentState_
FiniteStateAutomaton::FSAStateIndex currentState_
Current state of the FSA.
Definition: FSAFUResourceConflictDetectorPimpl.hh:64
FUFiniteStateAutomaton::buildStateMachine
void buildStateMachine()
Definition: FUFiniteStateAutomaton.cc:176
FSAFUResourceConflictDetector::FSAFUResourceConflictDetector
FSAFUResourceConflictDetector(const TTAMachine::FunctionUnit &fu)
Definition: FSAFUResourceConflictDetector.cc:52
FUResourceConflictDetector::OperationID
int OperationID
Type for identifying operations in the conflict detector interface.
Definition: FUResourceConflictDetector.hh:49
FSAFUResourceConflictDetector::issueOperationInline
bool issueOperationInline(OperationID id)
Definition: FSAFUResourceConflictDetector.cc:184
FUFiniteStateAutomaton::resolveState
FiniteStateAutomaton::FSAStateIndex resolveState(FiniteStateAutomaton::FSAStateIndex source, FiniteStateAutomaton::FSAStateTransitionIndex transition)
Definition: FUFiniteStateAutomaton.cc:105
FiniteStateAutomaton::UNKNOWN_STATE
static const FSAStateIndex UNKNOWN_STATE
A state id which denotes an unknown (unresolved) state. Used for lazy construction of states.
Definition: FiniteStateAutomaton.hh:64
TCEString.hh
StringTools::stringToUpper
static std::string stringToUpper(const std::string &source)
Definition: StringTools.cc:143
StringTools.hh
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
FSAFUResourceConflictDetector::pimpl_
FSAFUResourceConflictDetectorPimpl * pimpl_
Private implementation in a separate source file.
Definition: FSAFUResourceConflictDetector.hh:77
FUResourceConflictDetector
Definition: FUResourceConflictDetector.hh:45
FSAFUResourceConflictDetectorPimpl
Definition: FSAFUResourceConflictDetectorPimpl.hh:48
FSAFUResourceConflictDetector::advanceCycleInline
bool advanceCycleInline()
Definition: FSAFUResourceConflictDetector.cc:230
FSAFUResourceConflictDetectorPimpl::NOP
const FiniteStateAutomaton::FSAStateTransitionIndex NOP
The transition index of a NOP operation.
Definition: FSAFUResourceConflictDetectorPimpl.hh:70
FSAFUResourceConflictDetector::writeToDotFile
virtual void writeToDotFile(const TCEString &fileName) const
Definition: FSAFUResourceConflictDetector.cc:84
FiniteStateAutomaton::toDotString
virtual std::string toDotString() const
Definition: FiniteStateAutomaton.cc:235
Machine.hh
FSAFUResourceConflictDetectorPimpl::fsa_
FUFiniteStateAutomaton fsa_
The FSA.
Definition: FSAFUResourceConflictDetectorPimpl.hh:62
FSAFUResourceConflictDetector::issueOperationLazyInline
bool issueOperationLazyInline(OperationID id)
Definition: FSAFUResourceConflictDetector.cc:205
FSAFUResourceConflictDetector::advanceCycle
virtual bool advanceCycle()
Definition: FSAFUResourceConflictDetector.cc:120
FSAFUResourceConflictDetectorPimpl.hh
FiniteStateAutomaton::transitionIndex
virtual FSAStateTransitionIndex transitionIndex(const std::string &transitionName) const
Definition: FiniteStateAutomaton.cc:120
FSAFUResourceConflictDetector::initializeAllStates
void initializeAllStates()
Definition: FSAFUResourceConflictDetector.cc:74
FSAFUResourceConflictDetector::operationName
const char * operationName(OperationID id) const
Definition: FSAFUResourceConflictDetector.cc:110
TCEString
Definition: TCEString.hh:53
FSAFUResourceConflictDetector::operationID
virtual OperationID operationID(const TCEString &operationName) const
Definition: FSAFUResourceConflictDetector.cc:134
FSAFUResourceConflictDetector::~FSAFUResourceConflictDetector
virtual ~FSAFUResourceConflictDetector()
Definition: FSAFUResourceConflictDetector.cc:62
FSAFUResourceConflictDetector.hh
FSAFUResourceConflictDetector::issueOperation
virtual bool issueOperation(OperationID id)
Definition: FSAFUResourceConflictDetector.cc:99
FSAFUResourceConflictDetectorPimpl::nextState_
FiniteStateAutomaton::FSAStateIndex nextState_
The next state of the FSA (move to currentState in cycle advance).
Definition: FSAFUResourceConflictDetectorPimpl.hh:66