OpenASIP 2.2
Loading...
Searching...
No Matches
CompiledSimulation.hh
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 CompiledSimulation.hh
26 *
27 * Declaration of CompiledSimulation abstract class.
28 *
29 * @author Viljami Korhonen 2007 (viljami.korhonen-no.spam-tut.fi)
30 * @note This file is used in compiled simulation. Keep dependencies *clean*
31 * @note rating: red
32 */
33
34#ifndef COMPILED_SIMULATION_HH
35#define COMPILED_SIMULATION_HH
36
37#include "SimulatorConstants.hh"
38#include "SimValue.hh"
39#include "OperationPool.hh"
40
41namespace TTAMachine {
42 class Machine;
43 class FunctionUnit;
44}
45
46namespace TTAProgram {
47 class Program;
48}
49
53class MemorySystem;
55class CompiledSimulationEngine;
59
60
61/// Type for the simulateXXXXX basic block functions
62typedef void (*SimulateFunction)(void* engine);
63
64// Used to set export symbols visible
65#define EXPORT __attribute__((visibility("default")))
66
67
68/**
69 * A struct that describes a single FU result type
70 */
72 /// time when this result is ready
74
75 /// FU Result value
77
78 /// Is this result element used in the array or not
79 bool used;
80
82};
83
84/**
85 * A struct for dynamic array containing the FU results
86 */
88 /// size of the array
89 const int size;
90 /// array of result elements
92 /// Number of active elements in the buffer
94
95 /// A constructor that resets the variables
96 FUResultType(int maxLatency)
97 : size(maxLatency),
100 /// The destructor. Frees all memory
101 ~FUResultType() { delete[] data; data = 0; }
102};
103
104
105/**
106 * An abstract class that is used as a base for all the compiled simulations
107 *
108 * The derived classes are generated by CompiledSimCodeGenerator and then
109 * get loaded as plugins by the CompiledSimController.
110 *
111 */
113public:
116 InstructionAddress entryAddress,
117 InstructionAddress lastInstruction,
119 CompiledSimController& controller,
121 bool dynamicCompilation,
122 ProcedureBBRelations& procedureBBRelations);
123 virtual ~CompiledSimulation();
124
125 virtual void simulateCycle() = 0;
126 virtual void cycleEnd();
127
128 virtual void step(double count);
129 virtual void next(int count);
130 virtual void run();
131 virtual void runUntil(UIntWord address);
132
133 virtual InstructionAddress programCounter() const;
135
136 virtual ClockCycleCount cycleCount() const;
137
139 const char* rfName,
140 int registerIndex);
141
143 const char* iuName, int index);
144
145 virtual SimValue FUPortValue(
146 const char* fuName,
147 const char* portName);
148
149 virtual void requestToStop();
150 virtual bool stopRequested() const;
151 virtual bool isFinished() const;
152
154 int moveNumber,
155 InstructionAddress address) const;
157 const;
158
159
160 // Variables are defined public because of external C functions...
161 /// Number of cycles simulated so far
163 /// Number of basic blocks gone through
165 /// The jump target. Allows jumping to different addresses in the code
167 /// The program counter. i.e. which address the simulation is currently at
169 /// Last executed instruction
171 /// Number of cycles left to simulate until the execution returns
173 /// Should the simulation stop or not?
175 /// Is the simulation finished?
177
178 /// The operation pool
180 /// Next jump target as a function pointer" << endl
182
183 /// A flag for FU conflict detection
185
186 /// Move execution counts in a C style table
187 // Moves must be ordered in the same way as in POM!
188 // Also, only guarded move executions are stored here.
190 /// Basic block execution counts in a C style table
191 // Basic blocks are referred by their start addresses.
193
194 static void inline clearFUResults(
195 FUResultType& results);
196
197 static void inline addFUResult(
198 FUResultType& results,
200 const SimValue& value,
201 int latency);
202
203 static void inline addFUResult(
204 FUResultType& results,
206 const UIntWord& value,
207 int latency);
208
209 static void inline FUResult(
210 SimValue& target,
211 FUResultType& results,
212 ClockCycleCount cycles);
213
214protected:
215 TTAMachine::FunctionUnit& functionUnit(const char* name) const;
216
217 DirectAccessMemory& FUMemory(const char* FUName) const;
218 MemorySystem* memorySystem() const;
220 void msg(const char* message) const;
221 void haltSimulation(
222 const char* file,
223 int line,
224 const char* procedure,
225 const char* message) const;
226
227 void resizeJumpTable(int newSize);
231
232 SimValue* getSymbolValue(const char* symbolName);
233 void addSymbol(const char* symbolName, SimValue& value);
234
235 /// Is this a dynamic compiled simulation?
237
238 /// A struct for finding out procedure begins from procedure's basic blocks
240
241 /// The simulated machine
243
244 /// Entry address of the program
246 /// Last instruction of the program
248
249private:
250 /// Copying not allowed.
252 /// Assignment not allowed.
254
255 /// Private implementation in a separate source file
257};
258
259
260#include "CompiledSimulation.icc"
261
262#endif
Word UIntWord
Definition BaseType.hh:144
UInt32 InstructionAddress
Definition BaseType.hh:175
void(* SimulateFunction)(void *engine)
Type for the simulateXXXXX basic block functions.
TTAMachine::Machine * machine
the architecture definition of the estimated processor
find Finds info of the inner loops in the false
CycleCount ClockCycleCount
Alias for ClockCycleCount.
const InstructionAddress entryAddress_
Entry address of the program.
static void addFUResult(FUResultType &results, ClockCycleCount cycleCount, const SimValue &value, int latency)
MemorySystem * memorySystem() const
CompiledSimulation & operator=(const CompiledSimulation &)
Assignment not allowed.
virtual ClockCycleCount moveExecutionCount(int moveNumber, InstructionAddress address) const
void setJumpTargetFunction(InstructionAddress address, SimulateFunction fp)
virtual InstructionAddress lastExecutedInstruction() const
ProcedureBBRelations & procedureBBRelations_
A struct for finding out procedure begins from procedure's basic blocks.
virtual void simulateCycle()=0
SimulateFunction getSimulateFunction(InstructionAddress address)
static void addFUResult(FUResultType &results, ClockCycleCount cycleCount, const UIntWord &value, int latency)
SimulateFunction jumpTargetFunc_
Next jump target as a function pointer" << endl.
virtual void requestToStop()
const TTAMachine::Machine & machine_
The simulated machine.
virtual void step(double count)
virtual SimValue registerFileValue(const char *rfName, int registerIndex)
ClockCycleCount * moveExecCounts_
Move execution counts in a C style table.
bool stopRequested_
Should the simulation stop or not?
virtual void runUntil(UIntWord address)
SimulatorFrontend & frontend() const
virtual ClockCycleCount cycleCount() const
virtual bool isFinished() const
const InstructionAddress lastInstruction_
Last instruction of the program.
ClockCycleCount cycleCount_
Number of cycles simulated so far.
CompiledSimulation(const CompiledSimulation &)
Copying not allowed.
CompiledSimulationPimpl * pimpl_
Private implementation in a separate source file.
bool isFinished_
Is the simulation finished?
InstructionAddress programCounter_
The program counter. i.e. which address the simulation is currently at.
InstructionAddress lastExecutedInstruction_
Last executed instruction.
DirectAccessMemory & FUMemory(const char *FUName) const
virtual bool stopRequested() const
void resizeJumpTable(int newSize)
void addSymbol(const char *symbolName, SimValue &value)
virtual InstructionAddress programCounter() const
virtual void next(int count)
void msg(const char *message) const
void compileAndLoadFunction(InstructionAddress address)
bool conflictDetected_
A flag for FU conflict detection.
void haltSimulation(const char *file, int line, const char *procedure, const char *message) const
ClockCycleCount * bbExecCounts_
Basic block execution counts in a C style table.
static void FUResult(SimValue &target, FUResultType &results, ClockCycleCount cycles)
virtual SimValue immediateUnitRegisterValue(const char *iuName, int index)
OperationPool operationPool_
The operation pool.
SimValue * getSymbolValue(const char *symbolName)
virtual SimValue FUPortValue(const char *fuName, const char *portName)
ClockCycleCount cyclesToSimulate_
Number of cycles left to simulate until the execution returns.
InstructionAddress jumpTarget_
The jump target. Allows jumping to different addresses in the code.
bool dynamicCompilation_
Is this a dynamic compiled simulation?
static void clearFUResults(FUResultType &results)
TTAMachine::FunctionUnit & functionUnit(const char *name) const
int basicBlockCount_
Number of basic blocks gone through.
virtual InstructionAddress basicBlockStart(InstructionAddress address) const
ClockCycleCount cycles
time when this result is ready
bool used
Is this result element used in the array or not.
SimValue value
FU Result value.
~FUResultType()
The destructor. Frees all memory.
int numberOfElements
Number of active elements in the buffer.
const int size
size of the array
FUResultElementType * data
array of result elements
FUResultType(int maxLatency)
A constructor that resets the variables.
A struct for tracking basic blocks and their relation to their procedures.