OpenASIP 2.2
Loading...
Searching...
No Matches
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 */
58
59/**
60 * Destructor.
61 */
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 */
73void
77
78/**
79 * Writes the state machine to a Graphviz dot file.
80 *
81 * @param fileName The file name.
82 */
83void
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 */
98bool
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 */
109const char*
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 */
119bool
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 */
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 */
146void
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 */
156bool
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 */
183bool
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 */
204bool
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 */
229inline 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 */
252inline 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
const FiniteStateAutomaton::FSAStateTransitionIndex NOP
The transition index of a NOP operation.
FiniteStateAutomaton::FSAStateIndex currentState_
Current state of the FSA.
FiniteStateAutomaton::FSAStateIndex nextState_
The next state of the FSA (move to currentState in cycle advance).
virtual bool issueOperation(OperationID id)
virtual OperationID operationID(const TCEString &operationName) const
FSAFUResourceConflictDetectorPimpl * pimpl_
Private implementation in a separate source file.
const char * operationName(OperationID id) const
FSAFUResourceConflictDetector(const TTAMachine::FunctionUnit &fu)
virtual void writeToDotFile(const TCEString &fileName) const
FiniteStateAutomaton::FSAStateIndex resolveState(FiniteStateAutomaton::FSAStateIndex source, FiniteStateAutomaton::FSAStateTransitionIndex transition)
int OperationID
Type for identifying operations in the conflict detector interface.
virtual FSAStateTransitionIndex transitionIndex(const std::string &transitionName) const
TransitionMap transitions_
The state transitions. In protected to allow fast access from derived classes.
virtual std::string toDotString() const
virtual const std::string & transitionName(FSAStateTransitionIndex transition) const
virtual FSAStateIndex startState() const
static const FSAStateIndex ILLEGAL_STATE
A state id which denotes an illegal state.
static const FSAStateIndex UNKNOWN_STATE
A state id which denotes an unknown (unresolved) state. Used for lazy construction of states.
static std::string stringToUpper(const std::string &source)