OpenASIP  2.0
CodeGenerator.hh
Go to the documentation of this file.
1 /**
2  * @file CodeGenerator.hh
3  *
4  * Declaration of CodeGenerator class.
5  *
6  * @author Mikael Lepisto 2008 (mikael.lepisto@tut.fi)
7  * @author Heikki Kultala 2015 (heikki.kultala-NO.SPAM-tut.fi)
8  * @note rating: red
9  */
10 
11 #ifndef TTA_CODE_GENERATOR_HH
12 #define TTA_CODE_GENERATOR_HH
13 
14 #include <set>
15 
16 #include "MachineInfo.hh"
17 #include "ProgramOperation.hh"
18 #include "TCEString.hh"
19 
20 namespace TTAMachine {
21  class Machine;
22  class Bus;
23  class RegisterFile;
24 }
25 
26 namespace TTAProgram {
27  class Address;
28  class Instruction;
29  class InstructionReference;
30  class InstructionReferenceManager;
31  class Procedure;
32  class TerminalRegister;
33  class Terminal;
34  class TerminalFUPort;
35  class Move;
36  class ProgramAnnotation;
37  class MoveGuard;
38  class CodeSnippet;
39 }
40 
41 class UniversalMachine;
42 
43 namespace TTAProgram {
44 
45 /**
46  * CodeGenerator generates code pieces for given Program.
47  *
48  * Contains various helper functions for making hand writing of POM
49  * easier.
50  *
51  * @todo Rename to POMGenerator.
52  */
54 public:
55  typedef std::set<TCEString> RegisterSet;
56 
57  /// @todo This should probably take only Program
59  const TTAMachine::Machine& mach);
60 
61  virtual ~CodeGenerator();
62 
64  TTAProgram::CodeSnippet& dstProcedure,
65  TTAProgram::Terminal* srcTerminal,
66  TTAProgram::Terminal* dstTerminal);
67 
69  TTAProgram::Terminal* srcTerminal,
70  TTAProgram::Terminal* dstTerminal,
72  annotation);
73 
74 
77  const TTAMachine::RegisterFile& rf, int regNum, bool readPort) const;
78 
80  const TCEString& name, bool readPort);
81 
83  const TCEString& opName, int operand);
84 
85  void loadTerminal(TTAProgram::CodeSnippet& dstProcedure,
86  TTAProgram::Terminal* srcTerminal,
87  TTAProgram::Terminal* dstTerminal);
88 
89  void storeTerminal(TTAProgram::CodeSnippet& dstProcedure,
90  TTAProgram::Terminal* dstTerminal,
91  TTAProgram::Terminal* srcTerminal);
92 
93  void loadFromAddress(TTAProgram::CodeSnippet& dstProcedure,
94  TTAProgram::Terminal* srcTerminal,
95  const TCEString& dstReg);
96 
97  void storeToAddress(TTAProgram::CodeSnippet& dstProcedure,
98  TTAProgram::Terminal* dstTerminal,
99  const TCEString& srcReg);
100 
102  const TCEString& srcReg,
103  const TCEString& dstReg);
104 
106  const TCEString& dstReg,
107  const TCEString& srcReg);
108 
110  TTAProgram::CodeSnippet& dstProcedure, const TCEString& dstReg,
111  int increment);
112 
114  TTAProgram::CodeSnippet& dstProcedure, const TCEString& dstReg,
115  int decrement);
116 
118  TTAProgram::CodeSnippet& dstProcedure, const TCEString& spReg);
119 
121  TTAProgram::CodeSnippet& dstProcedure, const TCEString& spReg);
122 
123  void popFromStack(TTAProgram::CodeSnippet& dstProcedure,
124  const TCEString& stackRegister,
125  TTAProgram::Terminal* dstTerminal);
126 
128  const TCEString& stackRegister,
129  const TCEString& dstReg);
130 
131  void pushToStack(TTAProgram::CodeSnippet& dstProcedure,
132  const TCEString& stackRegister,
133  TTAProgram::Terminal* srcTerminal);
134 
135  void pushRegisterToStack(TTAProgram::CodeSnippet& dstProcedure,
136  const TCEString& stackRegister,
137  const TCEString& srcReg);
138 
139 
140  void popFromBuffer(TTAProgram::CodeSnippet& dstProcedure,
141  const TCEString& indexRegister,
142  TTAProgram::Terminal* dstTerminal);
143 
145  const TCEString& indexRegister,
146  const TCEString& dstReg);
147 
148  void pushToBuffer(TTAProgram::CodeSnippet& dstProcedure,
149  const TCEString& indexRegister,
150  TTAProgram::Terminal* srcTerminal);
151 
153  const TCEString& stackRegister,
154  const TCEString& srcReg);
155 
157  TTAProgram::CodeSnippet& dstProcedure,
158  const TCEString& stackRegister,
160 
162  TTAProgram::CodeSnippet& dstProcedure,
163  const TCEString& indexRegister,
165 
166  void registerJump(
167  TTAProgram::CodeSnippet& dstProcedure,
168  const TCEString& jumpAddrReg);
169 
170  void registerJump(
171  TTAProgram::CodeSnippet& dstProcedure,
172  const TCEString& jumpAddrReg,
173  const TTAProgram::ProgramAnnotation& annotation);
174 
175  std::shared_ptr<TTAProgram::Move>
177 
178  std::shared_ptr<TTAProgram::Move> createCall(
180 
181  void createExternalCall(
182  TTAProgram::CodeSnippet& dstProcedure,
183  const TCEString& procedureName);
184 
185  void createCall(
186  TTAProgram::CodeSnippet& dstProcedure,
188 
189  void registerMove(
190  TTAProgram::CodeSnippet& dstProcedure,
191  const TCEString& srcReg, const TCEString& dstReg);
192 
193  void immediateMove(
194  TTAProgram::CodeSnippet& dstProcedure,
195  int imm, const TCEString& dstReg);
196 
199  const TCEString& name,
200  const TCEString& schedProcedureName,
201  const TCEString& stackReg,
202  const TCEString& rvReg,
203  const RegisterSet& saveRegs);
204 
206  const TTAProgram::MoveGuard &mg, const TTAMachine::Bus* bus = NULL);
207 
208  std::vector<ProgramOperationPtr> createForLoopBufferInit(
209  const MoveNode* dynamicLimitMove, int iterationCount, int divider, int loopSize);
210 
212 
214 
215  std::shared_ptr<TTAProgram::Move> createMove(
217 
218 private:
219  /// Target machine.
221  /// Universal machine
223 
226 };
227 }
228 
229 #endif
TTAProgram
Definition: Estimator.hh:65
TTAProgram::CodeGenerator::CodeGenerator
CodeGenerator(const TTAMachine::Machine &mach)
Definition: CodeGenerator.cc:45
TTAProgram::CodeGenerator::uMach_
const UniversalMachine * uMach_
Universal machine.
Definition: CodeGenerator.hh:222
TTAProgram::CodeGenerator::immediateMove
void immediateMove(TTAProgram::CodeSnippet &dstProcedure, int imm, const TCEString &dstReg)
Definition: CodeGenerator.cc:717
TTAProgram::CodeGenerator::popFromStack
void popFromStack(TTAProgram::CodeSnippet &dstProcedure, const TCEString &stackRegister, TTAProgram::Terminal *dstTerminal)
Definition: CodeGenerator.cc:436
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::CodeGenerator::createTerminalFUPort
TTAProgram::TerminalFUPort * createTerminalFUPort(const TCEString &opName, int operand)
Definition: CodeGenerator.cc:94
TTAProgram::CodeGenerator::mach_
const TTAMachine::Machine * mach_
Target machine.
Definition: CodeGenerator.hh:220
TTAMachine::Bus
Definition: Bus.hh:53
TTAProgram::CodeGenerator::registerMove
void registerMove(TTAProgram::CodeSnippet &dstProcedure, const TCEString &srcReg, const TCEString &dstReg)
Definition: CodeGenerator.cc:703
TTAProgram::CodeGenerator::createWhileLoopBufferInit
ProgramOperationPtr createWhileLoopBufferInit(int loopSize)
Definition: CodeGenerator.cc:1116
MachineInfo.hh
TTAProgram::CodeGenerator::addMoveToProcedure
TTAProgram::Instruction * addMoveToProcedure(TTAProgram::CodeSnippet &dstProcedure, TTAProgram::Terminal *srcTerminal, TTAProgram::Terminal *dstTerminal)
Definition: CodeGenerator.cc:54
MoveNode
Definition: MoveNode.hh:65
TTAProgram::CodeGenerator::~CodeGenerator
virtual ~CodeGenerator()
Definition: CodeGenerator.cc:51
TTAProgram::CodeGenerator::addAnnotatedMoveToProcedure
void addAnnotatedMoveToProcedure(TTAProgram::CodeSnippet &dstProcedure, TTAProgram::Terminal *srcTerminal, TTAProgram::Terminal *dstTerminal, const TTAProgram::ProgramAnnotation &annotation)
Definition: CodeGenerator.cc:71
TTAProgram::CodeGenerator::storeTerminal
void storeTerminal(TTAProgram::CodeSnippet &dstProcedure, TTAProgram::Terminal *dstTerminal, TTAProgram::Terminal *srcTerminal)
Definition: CodeGenerator.cc:213
ProgramOperationPtr
std::shared_ptr< ProgramOperation > ProgramOperationPtr
Definition: MoveNode.hh:52
TTAProgram::CodeGenerator::pushRegisterToStack
void pushRegisterToStack(TTAProgram::CodeSnippet &dstProcedure, const TCEString &stackRegister, const TCEString &srcReg)
Definition: CodeGenerator.cc:493
TTAProgram::CodeGenerator::createTerminalRegister
TTAProgram::Terminal * createTerminalRegister(const TTAMachine::RegisterFile &rf, int regNum, bool readPort) const
Definition: CodeGenerator.cc:115
TCEString.hh
TTAProgram::CodeGenerator::incrementStackPointer
void incrementStackPointer(TTAProgram::CodeSnippet &dstProcedure, const TCEString &spReg)
Definition: CodeGenerator.cc:417
TTAProgram::CodeGenerator::storeToAddress
void storeToAddress(TTAProgram::CodeSnippet &dstProcedure, TTAProgram::Terminal *dstTerminal, const TCEString &srcReg)
Definition: CodeGenerator.cc:276
TTAProgram::CodeGenerator::pushRegisterToBuffer
void pushRegisterToBuffer(TTAProgram::CodeSnippet &dstProcedure, const TCEString &stackRegister, const TCEString &srcReg)
Definition: CodeGenerator.cc:585
UniversalMachine
Definition: UniversalMachine.hh:56
TTAProgram::CodeGenerator::createMove
std::shared_ptr< TTAProgram::Move > createMove(TTAProgram::Terminal *src, TTAProgram::Terminal *dst)
Definition: CodeGenerator.cc:1065
TTAProgram::CodeGenerator::RegisterSet
std::set< TCEString > RegisterSet
Definition: CodeGenerator.hh:55
TTAProgram::CodeGenerator::storeToRegisterAddress
void storeToRegisterAddress(TTAProgram::CodeSnippet &dstProcedure, const TCEString &dstReg, const TCEString &srcReg)
Definition: CodeGenerator.cc:315
TTAProgram::CodeGenerator::decrementRegisterAddress
void decrementRegisterAddress(TTAProgram::CodeSnippet &dstProcedure, const TCEString &dstReg, int decrement)
Definition: CodeGenerator.cc:380
TTAProgram::CodeGenerator::createSchedYieldProcedure
TTAProgram::Procedure * createSchedYieldProcedure(TTAProgram::InstructionReferenceManager &refManager, const TCEString &name, const TCEString &schedProcedureName, const TCEString &stackReg, const TCEString &rvReg, const RegisterSet &saveRegs)
Definition: CodeGenerator.cc:743
TTAProgram::CodeGenerator::popRegisterFromStack
void popRegisterFromStack(TTAProgram::CodeSnippet &dstProcedure, const TCEString &stackRegister, const TCEString &dstReg)
Definition: CodeGenerator.cc:456
TTAProgram::CodeGenerator::loadTerminal
void loadTerminal(TTAProgram::CodeSnippet &dstProcedure, TTAProgram::Terminal *srcTerminal, TTAProgram::Terminal *dstTerminal)
Definition: CodeGenerator.cc:169
TTAProgram::CodeGenerator::stackAlignment_
int stackAlignment_
Definition: CodeGenerator.hh:224
TTAProgram::CodeGenerator::createCall
std::shared_ptr< TTAProgram::Move > createCall(TTAProgram::InstructionReference &callDst)
Definition: CodeGenerator.cc:657
TTAProgram::CodeGenerator::decrementStackPointer
void decrementStackPointer(TTAProgram::CodeSnippet &dstProcedure, const TCEString &spReg)
Definition: CodeGenerator.cc:423
TTAProgram::CodeSnippet
Definition: CodeSnippet.hh:59
TTAProgram::CodeGenerator::incrementRegisterAddress
void incrementRegisterAddress(TTAProgram::CodeSnippet &dstProcedure, const TCEString &dstReg, int increment)
Definition: CodeGenerator.cc:335
TTAProgram::CodeGenerator::popRegisterFromBuffer
void popRegisterFromBuffer(TTAProgram::CodeSnippet &dstProcedure, const TCEString &indexRegister, const TCEString &dstReg)
Definition: CodeGenerator.cc:548
TTAProgram::CodeGenerator::registerJump
void registerJump(TTAProgram::CodeSnippet &dstProcedure, const TCEString &jumpAddrReg)
Definition: CodeGenerator.cc:609
TTAProgram::TerminalFUPort
Definition: TerminalFUPort.hh:56
ProgramOperation.hh
TTAProgram::CodeGenerator::pushInstructionReferenceToStack
void pushInstructionReferenceToStack(TTAProgram::CodeSnippet &dstProcedure, const TCEString &stackRegister, TTAProgram::InstructionReference &srcAddr)
Definition: CodeGenerator.cc:503
TTAProgram::CodeGenerator::popFromBuffer
void popFromBuffer(TTAProgram::CodeSnippet &dstProcedure, const TCEString &indexRegister, TTAProgram::Terminal *dstTerminal)
Definition: CodeGenerator.cc:529
TTAProgram::CodeGenerator::loadFromRegisterAddress
void loadFromRegisterAddress(TTAProgram::CodeSnippet &dstProcedure, const TCEString &srcReg, const TCEString &dstReg)
Definition: CodeGenerator.cc:295
TTAProgram::InstructionReferenceManager
Definition: InstructionReferenceManager.hh:82
TTAProgram::CodeGenerator::opset_
MachineInfo::OperationSet opset_
Definition: CodeGenerator.hh:225
MachineInfo::OperationSet
TCETools::CIStringSet OperationSet
Definition: MachineInfo.hh:60
TCEString
Definition: TCEString.hh:53
TTAProgram::CodeGenerator::pushInstructionReferenceToBuffer
void pushInstructionReferenceToBuffer(TTAProgram::CodeSnippet &dstProcedure, const TCEString &indexRegister, TTAProgram::InstructionReference &srcAddr)
Definition: CodeGenerator.cc:596
TTAProgram::CodeGenerator
Definition: CodeGenerator.hh:53
TTAProgram::CodeGenerator::createBreakOperation
ProgramOperationPtr createBreakOperation(const MoveNode *jump)
Definition: CodeGenerator.cc:1070
TTAProgram::Terminal
Definition: Terminal.hh:60
TTAProgram::CodeGenerator::createForLoopBufferInit
std::vector< ProgramOperationPtr > createForLoopBufferInit(const MoveNode *dynamicLimitMove, int iterationCount, int divider, int loopSize)
Definition: CodeGenerator.cc:898
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
TTAProgram::ProgramAnnotation
Definition: ProgramAnnotation.hh:49
TTAProgram::CodeGenerator::loadFromAddress
void loadFromAddress(TTAProgram::CodeSnippet &dstProcedure, TTAProgram::Terminal *srcTerminal, const TCEString &dstReg)
Definition: CodeGenerator.cc:256
TTAProgram::CodeGenerator::createInverseGuard
static TTAProgram::MoveGuard * createInverseGuard(const TTAProgram::MoveGuard &mg, const TTAMachine::Bus *bus=NULL)
Definition: CodeGenerator.cc:837
TTAMachine
Definition: Assembler.hh:48
TTAProgram::MoveGuard
Definition: MoveGuard.hh:47
TTAProgram::InstructionReference
Definition: InstructionReference.hh:49
TTAProgram::Procedure
Definition: Procedure.hh:55
TTAProgram::CodeGenerator::pushToStack
void pushToStack(TTAProgram::CodeSnippet &dstProcedure, const TCEString &stackRegister, TTAProgram::Terminal *srcTerminal)
Definition: CodeGenerator.cc:474
TTAProgram::CodeGenerator::createExternalCall
void createExternalCall(TTAProgram::CodeSnippet &dstProcedure, const TCEString &procedureName)
Definition: CodeGenerator.cc:671
TTAProgram::CodeGenerator::createJump
std::shared_ptr< TTAProgram::Move > createJump(TTAProgram::InstructionReference &dst)
Definition: CodeGenerator.cc:640
TTAMachine::Machine
Definition: Machine.hh:73
TTAProgram::CodeGenerator::pushToBuffer
void pushToBuffer(TTAProgram::CodeSnippet &dstProcedure, const TCEString &indexRegister, TTAProgram::Terminal *srcTerminal)
Definition: CodeGenerator.cc:565