OpenASIP 2.2
Loading...
Searching...
No Matches
CompiledSimCodeGenerator.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2010 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 CompiledSimCodeGenerator.hh
26 *
27 * Declaration of CompiledSimCodeGenerator class.
28 *
29 * @author Viljami Korhonen 2007 (viljami.korhonen-no.spam-tut.fi)
30 * @author Pekka Jääskeläinen 2010
31 * @note rating: red
32 */
33
34#ifndef COMPILED_SIM_CODE_GENERATOR_HH
35#define COMPILED_SIM_CODE_GENERATOR_HH
36
37#include <iostream>
38#include <fstream>
39#include <string>
40#include <set>
41#include <map>
42
43#include "OperationPool.hh"
44#include "SimulatorConstants.hh"
47#include "CIStringSet.hh"
48
49namespace TTAMachine {
50 class Machine;
51 class FunctionUnit;
52 class FUPort;
53 class Port;
54 class Unit;
55 class HWOperation;
56 class Guard;
57 class RegisterFile;
58 class ControlUnit;
59 class Bus;
60 class RegisterGuard;
61}
62
63namespace TTAProgram {
64 class Program;
65 class Instruction;
66 class Procedure;
67 class Terminal;
68 class CodeLabel;
69 class GlobalScope;
70 class Move;
71}
72
75
76
77/// A struct for tracking basic blocks and their relation to their procedures
79 /// Procedure start per basic block starts
80 std::map<InstructionAddress, InstructionAddress> procedureStart;
81
82 typedef std::multimap<InstructionAddress, InstructionAddress>
84
85 /// All basic block start addresses per procedure start
87
88 /// Basic block starts and their corresponding .cpp files
89 std::map<InstructionAddress, std::string> basicBlockFiles;
90};
91
92
93/**
94 * A class that generates C/C++ code from the given POM and MOM
95 *
96 * Used for the compiled simulation
97 *
98 */
100public:
101 /// A type for std::string sets
102 typedef std::set<std::string> StringSet;
103 /// A type for storing address-to-address combinations
104 typedef std::map<InstructionAddress, InstructionAddress> AddressMap;
105
109 const TTASimulationController& controller,
110 bool fuResourceConflictDetection,
111 bool handleCycleEnd,
112 bool dynamicCompilation,
113 bool basicBlockPerFile = false,
114 bool functionPerFile = true,
115 const TCEString& globalSymbolPrefix = "");
116
118
119 virtual void generateToDirectory(const std::string& dirName);
120 virtual StringSet createdFiles() const;
121 virtual AddressMap basicBlocks() const;
123
125
126private:
127 /// Copying not allowed.
129 /// Assignment not allowed.
131
132 /**
133 * A struct for handling delayed assignments for the FU results
134 */
136 /// The source symbol
137 std::string sourceSymbol;
138 /// The target symbol
139 std::string targetSymbol;
140 /// The FU result symbol
141 std::string fuResultSymbol;
142 };
143
144 /// A type for operation symbol declarations: 1=op.name 2=op.symbol
145 typedef std::multimap<std::string, std::string> OperationSymbolDeclarations;
146
147 /// FU Result writes
148 typedef std::multimap<int, DelayedAssignment> DelayedAssignments;
149 typedef std::map<std::string, int> FUResultWrites;
150
155 void findBasicBlocks() const;
156 void generateProcedureCode(const TTAProgram::Procedure& procedure);
160 std::string generateHaltCode(const std::string& message="");
163 void updateSymbolsMap();
166 void generateMakefile();
167
168 void addDeclaredSymbol(const std::string& name, int width);
170
171 std::string handleJump(const TTAMachine::HWOperation& op);
172 std::string handleOperation(const TTAMachine::HWOperation& op);
175 std::string generateGuardRead(const TTAProgram::Move& move);
176 std::string generateGuardCondition(const TTAProgram::Move& move);
177 void generateInstruction(const TTAProgram::Instruction& instruction);
178 std::string generateTriggerCode(const TTAMachine::HWOperation& op);
179 std::string generateStoreTrigger(const TTAMachine::HWOperation& op);
180 std::string generateLoadTrigger(const TTAMachine::HWOperation& op);
181
182// guard-pipeline related methods
184 const std::string& regSymbolName, std::ostream& stream);
185
186 std::string guardPipelineTopSymbol(const TTAMachine::RegisterGuard& guard);
187 void generateGuardPipelineVariables(std::ostream& stream);
188 void generateGuardPipelineAdvance(std::ostream& stream);
189
190 std::string generateAddFUResult(
191 const TTAMachine::FUPort& resultPort,
192 const std::string& value,
193 int latency);
194
195 std::string generateFUResultRead(
196 const std::string& destination,
197 const std::string& resultSymbol);
198
199 int maxLatency() const;
200
201 std::vector<TTAMachine::Port*> fuOutputPorts(
202 const TTAMachine::FunctionUnit& fu) const;
203
204 static bool isStoreOperation(const std::string& opName);
205 static bool isLoadOperation(const std::string& opName);
206
207 /// The machine used for simulation
209 /// The simulated program
211 /// The simulator frontend
213 /// GCU
215
216 /// Should we let frontend handle each cycle end
218 /// Is this a dynamic compiled simulation?
220 /// Should the generator generate only one basic block per code file
222 /// Should the generator start with a new file after function end
224
225 /// Type for SimValue symbol declarations: string=symbolname, int=width
226 typedef std::map<std::string, int> SimValueSymbolDeclarations;
227 /// A list of all symbols that are declared after the program code is ready
229
230 /// A set of all the declared functions
232 /// A list of the code files created during the process
234 /// A list of used operations
236
237 /// Absolute instruction # being processed
239 /// Istruction counter for checking how many instructions to put per file
241 /// How many moves have we been through with?
243 /// Are we at the beginning of a new procedure?
245 /// Pointer to the current Procedure being processed
247
248 /// last instruction of the current basic block
250 /// name of the last used guard variable
251 std::string lastGuardBool_;
252 /// Temporary list of the used guard bool symbols per instruction
253 std::map<std::string, std::string> usedGuardSymbols_;
254 /// Program exit point addresses
255 std::set<InstructionAddress> exitPoints_;
256
257 /// The basic block map referred by start of the block as a key
259 /// The basic block map referred by end of the block as a key
261 /// Basic blocks relations to procedures and vice versa.
263 /// Delayed FU Result assignments
265 /// Last known FU result writes
267
268 /// The operation pool
270
271 /// Directory where to write the source files of the engine.
272 std::string targetDirectory_;
273 /// Name of the class to be created
274 std::string className_;
275 /// Header filename
276 std::string headerFile_;
277 /// Main source filename. This includes the constructor and the simulateCycle().
278 std::string mainFile_;
279 /// Current file being processed
280 std::fstream currentFile_;
281 /// Name of the current file being processed
282 std::string currentFileName_;
283 /// Current output stream i.e. the above file
284 std::ostream* os_;
285
286 /// The symbol generator
288
289 /// Conflict detection code generator
291
292 /// Maximum number of instructions per engine source code file,
293 /// computed from the instruction width (bus count) to control
294 /// simulation engine code size explosion with wider simulated
295 /// machines.
297 /// Max for each simulation function.
299
300 typedef std::map<std::string, int> GuardPipeline;
302
304
306};
307
308#endif // include once
309
UInt32 InstructionAddress
Definition BaseType.hh:175
TTAMachine::Machine * machine
the architecture definition of the estimated processor
find Finds info of the inner loops in the program
std::string generateStoreTrigger(const TTAMachine::HWOperation &op)
std::string generateFUResultRead(const std::string &destination, const std::string &resultSymbol)
std::string currentFileName_
Name of the current file being processed.
bool basicBlockPerFile_
Should the generator generate only one basic block per code file.
std::string generateGuardRead(const TTAProgram::Move &move)
std::string generateHaltCode(const std::string &message="")
std::multimap< std::string, std::string > OperationSymbolDeclarations
A type for operation symbol declarations: 1=op.name 2=op.symbol.
std::string handleJump(const TTAMachine::HWOperation &op)
std::set< InstructionAddress > exitPoints_
Program exit point addresses.
void generateInstruction(const TTAProgram::Instruction &instruction)
std::string handleOperationWithoutDag(const TTAMachine::HWOperation &op)
std::map< InstructionAddress, InstructionAddress > AddressMap
A type for storing address-to-address combinations.
std::string generateTriggerCode(const TTAMachine::HWOperation &op)
std::string handleOperation(const TTAMachine::HWOperation &op)
bool functionPerFile_
Should the generator start with a new file after function end.
const TTAProgram::Program & program_
The simulated program.
CompiledSimCodeGenerator(const CompiledSimCodeGenerator &)
Copying not allowed.
DelayedAssignments delayedFUResultWrites_
Delayed FU Result assignments.
CompiledSimCodeGenerator & operator=(const CompiledSimCodeGenerator &)
Assignment not allowed.
const TTAProgram::Procedure * currentProcedure_
Pointer to the current Procedure being processed.
std::string lastGuardBool_
name of the last used guard variable
std::vector< TTAMachine::Port * > fuOutputPorts(const TTAMachine::FunctionUnit &fu) const
const TTAMachine::ControlUnit & gcu_
GCU.
std::set< std::string > StringSet
A type for std::string sets.
std::string generateGuardCondition(const TTAProgram::Move &move)
const TTASimulationController & simController_
The simulator frontend.
bool handleCycleEnd_
Should we let frontend handle each cycle end.
std::string generateAddFUResult(const TTAMachine::FUPort &resultPort, const std::string &value, int latency)
ConflictDetectionCodeGenerator conflictDetectionGenerator_
Conflict detection code generator.
static TCETools::CIStringSet supportedMemoryOperations()
std::multimap< int, DelayedAssignment > DelayedAssignments
FU Result writes.
std::map< std::string, std::string > usedGuardSymbols_
Temporary list of the used guard bool symbols per instruction.
void generateShutdownCode(InstructionAddress address)
const TTAMachine::Machine & machine_
The machine used for simulation.
bool dynamicCompilation_
Is this a dynamic compiled simulation?
virtual AddressMap basicBlocks() const
InstructionAddress lastInstructionOfBB_
last instruction of the current basic block
std::fstream currentFile_
Current file being processed.
static bool isLoadOperation(const std::string &opName)
unsigned maxInstructionsPerSimulationFunction_
Max for each simulation function.
std::string guardPipelineTopSymbol(const TTAMachine::RegisterGuard &guard)
std::map< std::string, int > SimValueSymbolDeclarations
Type for SimValue symbol declarations: string=symbolname, int=width.
std::map< std::string, int > GuardPipeline
std::string className_
Name of the class to be created.
void generateGuardPipelineAdvance(std::ostream &stream)
std::string mainFile_
Main source filename. This includes the constructor and the simulateCycle().
int instructionNumber_
Absolute instruction # being processed.
AddressMap bbEnds_
The basic block map referred by end of the block as a key.
bool handleRegisterWrite(const std::string &regSymbolName, std::ostream &stream)
std::string generateLoadTrigger(const TTAMachine::HWOperation &op)
std::string headerFile_
Header filename.
int instructionCounter_
Istruction counter for checking how many instructions to put per file.
static bool isStoreOperation(const std::string &opName)
std::string targetDirectory_
Directory where to write the source files of the engine.
void generateGuardPipelineVariables(std::ostream &stream)
OperationPool operationPool_
The operation pool.
std::map< std::string, int > FUResultWrites
virtual void generateToDirectory(const std::string &dirName)
virtual ProcedureBBRelations procedureBBRelations() const
void generateProcedureCode(const TTAProgram::Procedure &procedure)
OperationSymbolDeclarations usedOperations_
A list of used operations.
StringSet createdFiles_
A list of the code files created during the process.
SimValueSymbolDeclarations declaredSymbols_
A list of all symbols that are declared after the program code is ready.
unsigned maxInstructionsPerFile_
Maximum number of instructions per engine source code file, computed from the instruction width (bus ...
CompiledSimSymbolGenerator symbolGen_
The symbol generator.
int moveCounter_
How many moves have we been through with?
ProcedureBBRelations procedureBBRelations_
Basic blocks relations to procedures and vice versa.
FUResultWrites lastFUWrites_
Last known FU result writes.
StringSet declaredFunctions_
A set of all the declared functions.
void addDeclaredSymbol(const std::string &name, int width)
bool isProcedureBegin_
Are we at the beginning of a new procedure?
std::ostream * os_
Current output stream i.e. the above file.
virtual StringSet createdFiles() const
AddressMap bbStarts_
The basic block map referred by start of the block as a key.
std::string detectConflicts(const TTAMachine::HWOperation &op)
std::set< TCEString, CaseInsensitiveCmp > CIStringSet
A struct for tracking basic blocks and their relation to their procedures.
std::multimap< InstructionAddress, InstructionAddress > BasicBlockStarts
std::map< InstructionAddress, std::string > basicBlockFiles
Basic block starts and their corresponding .cpp files.
std::map< InstructionAddress, InstructionAddress > procedureStart
Procedure start per basic block starts.
BasicBlockStarts basicBlockStarts
All basic block start addresses per procedure start.