OpenASIP 2.2
Loading...
Searching...
No Matches
TPEFProgramFactory.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 TPEFProgramFactory.hh
26 *
27 * Declaration of TPEFProgramFactory class.
28 *
29 * @author Mikael Lepistö 2005 (tmlepist-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen 2006 (pjaaskel-no.spam-cs.tut.fi)
31 * @note rating: yellow
32 */
33
34#ifndef TTA_TPEF_PROGRAM_FACTORY_HH
35#define TTA_TPEF_PROGRAM_FACTORY_HH
36
37#include <memory>
38#include <map>
39#include <list>
40#include <memory>
41
42#include "Binary.hh"
43#include "MoveElement.hh"
44#include "ResourceElement.hh"
45#include "ResourceSection.hh"
46#include "Socket.hh"
47#include "TPEFTools.hh"
48#include "ASpaceElement.hh"
49
50namespace TTAMachine {
51 class Machine;
52 class FunctionUnit;
53 class AddressSpace;
54 class Socket;
55 class RegisterFile;
56 class Guard;
57 class ImmediateUnit;
58 class InstructionTemplate;
59 class Port;
60 class Bus;
61 class Unit;
62}
63
64namespace TPEF {
65 class ImmediateElement;
66}
67
68class SimValue;
70
71namespace TTAProgram {
72
73class Move;
74class Immediate;
75class Terminal;
76class Program;
77class Instruction;
78
79/**
80 * Creates a new TTA program out of a description of a binary representation
81 * of the program and a model of the target architecture.
82 *
83 * This class builds only one program, even if the input binary contains many
84 * programs (the original TPEF file has multiple code sections with different
85 * address spaces).
86 */
88public:
90 const TPEF::Binary& aBinary,
91 const TTAMachine::Machine& aMachine);
92
94 const TPEF::Binary &aBinary,
95 const TTAMachine::Machine& aMachine,
96 UniversalMachine* aUniversalMachine);
97
99 const TPEF::Binary &aBinary, UniversalMachine* aMachine);
100
101 virtual ~TPEFProgramFactory();
102
103 Program* build();
104
105protected:
106 typedef std::map<HalfWord, SimValue*> InlineValues;
107 typedef std::pair<Word, Word> ImmediateKey;
108 typedef std::map<ImmediateKey, TPEF::ImmediateElement*> ImmediateMap;
109 typedef std::vector<TPEF::MoveElement*> MoveVector;
110 typedef std::vector<TPEF::ImmediateElement*> ImmediateVector;
111
113 const TPEF::ResourceSection &resources,
114 MoveVector& moveElements,
115 ImmediateVector& longImmediates,
116 ImmediateMap& immElements) const;
117
118
119 void addProcedures(
121 const TTAMachine::AddressSpace &programASpace) const;
122
124 const TPEF::ResourceSection &resources,
125 const TTAMachine::Bus *aBus,
128 HalfWord unitId,
129 HalfWord index,
130 const ImmediateMap *immediateMap = NULL) const;
131
133 const TPEF::ResourceSection &resources,
134 HalfWord busId) const;
135
137 const TPEF::ResourceSection &resources,
138 HalfWord rfId) const;
139
141 const TPEF::ResourceSection &resources,
142 Byte immUnitId) const;
143
145 const TPEF::ResourceSection &resources,
146 HalfWord unitId, std::string tpefOpName = "") const;
147
149 const TTAMachine::Bus &bus,
150 const TTAMachine::Unit &portParent,
151 std::string tpefOpName = "",
152 int tpefOpIndex = 0) const;
153
155 const TPEF::ASpaceElement *aSpace) const;
156
158 const TPEF::ResourceSection &resources,
159 TTAMachine::Bus &bus,
161 HalfWord unitId,
162 HalfWord index,
163 bool isInverted) const;
164
166 const TPEF::ResourceSection &resources,
167 ImmediateVector& longImmediates,
168 MoveVector& moves) const;
169
171
172 void createLabels(Program &prog);
173
175
176 void createDataMemories(Program &prog);
177
178 bool isFunctionStart(
179 const TPEF::InstructionElement &instructionElement) const;
180
181 std::string functionName(
182 const TPEF::InstructionElement &instructionElement) const;
183
184 std::string stringOfChunk(
185 const TPEF::Chunk *chunk, const TPEF::Section *chunkOwner) const;
186
187
188private:
189
190 /// Cache key for resources that are accessed from MOM(s)
191 class CacheKey {
192 public:
194 const TTAMachine::Bus &aBus,
197 HalfWord anUnitId, HalfWord anIndex) :
198 bus_(aBus), direction_(aDirection), type_(aType),
199 unitId_(anUnitId), index_(anIndex) { }
200
201 bool operator<(const CacheKey &keyToCompare) const {
202
203 if (direction_ < keyToCompare.direction_) return true;
204 else if (direction_ > keyToCompare.direction_) return false;
205
206 if (type_ < keyToCompare.type_) return true;
207 else if (type_ > keyToCompare.type_) return false;
208
209 if (unitId_ < keyToCompare.unitId_ ) return true;
210 else if (unitId_ > keyToCompare.unitId_ ) return false;
211
212 if (index_ < keyToCompare.index_ ) return true;
213 else if (index_ > keyToCompare.index_) return false;
214
215 if (&bus_ < &(keyToCompare.bus_)) return true;
216
217 return false;
218 }
219
220 private:
221 /// Bus that was used for transport.
223 /// Direction if the port was read or written.
225 /// Type of the accessed unit.
227 /// unit id of the corresponding TPEF resource element.
228 HalfWord unitId_;
229 /// Index of the corresponding TPEF resource element.
230 HalfWord index_;
231 };
232
233 /**
234 * Helper struct for resolving socket allocations
235 * for register file access.
236 *
237 * This could be removed, if register file port storing for register
238 * references is implemented in TPEF.
239 */
241 SocketAllocation(std::shared_ptr<Move> m, unsigned int anIndex) :
242 index(anIndex) ,move(m), src(0), dst(0) { };
243
244 unsigned int index;
245 std::shared_ptr<Move> move;
246 std::vector<TTAMachine::Socket*> srcSocks;
247 std::vector<TTAMachine::Socket*> dstSocks;
248 unsigned int src;
249 unsigned int dst;
250 };
251
253
255 SocketAllocation& alloc,
256 std::map<TTAMachine::Socket*,
257 std::vector<SocketAllocation*> >& fixedSockets) const;
258
260 SocketAllocation& alloc,
261 std::map<TTAMachine::Socket*,
262 std::vector<SocketAllocation*> >& fixedSockets) const;
263
265 std::vector<SocketAllocation>& allocs) const;
266
267 Terminal* getFromCache(const CacheKey &key) const;
268 void addToCache(const CacheKey &key, Terminal *cachedTerm) const;
269 void clearCache() const;
270
271 /// Binary that is used for creating program.
273 /// Target machine of program.
275 /// Universal machine of program.
277
278 /// TPEFTools object for helper functions.
280 /// Instruction address space of machine.
282 /// Instruction address space element of TPEF.
284
285 /// Stores information of start points of procedures that were found.
286 std::map<const TPEF::InstructionElement*,
288
289 /// Moves whose source terminals are addresses referring to instructions.
290 mutable std::list<std::shared_ptr<Move> > instructionImmediates_;
291
292 /// Long immediates whose value terminals refers to instructions.
293 mutable std::list<std::shared_ptr<Immediate> > longInstructionImmediates_;
294
295 /// Cache map of terminals that are returned by different search
296 /// parameters.
297 mutable std::map<const CacheKey, Terminal *> cache_;
298
299 /// Busses that are already allocated by moves of current instruction.
300 mutable std::set<HalfWord> allocatedBusses_;
301
302 /// Program instruction by TPEF instruction element.
303 mutable std::map<TPEF::InstructionElement*, Instruction*> instructionMap_;
304
305};
306
307}
308
309#endif
unsigned char Byte
Definition BaseType.hh:116
find Finds info of the inner loops in the program
Cache key for resources that are accessed from MOM(s)
TPEF::MoveElement::FieldType type_
Type of the accessed unit.
bool operator<(const CacheKey &keyToCompare) const
const TTAMachine::Bus & bus_
Bus that was used for transport.
TTAMachine::Socket::Direction direction_
Direction if the port was read or written.
HalfWord index_
Index of the corresponding TPEF resource element.
CacheKey(const TTAMachine::Bus &aBus, TTAMachine::Socket::Direction aDirection, TPEF::MoveElement::FieldType aType, HalfWord anUnitId, HalfWord anIndex)
HalfWord unitId_
unit id of the corresponding TPEF resource element.
std::vector< TPEF::ImmediateElement * > ImmediateVector
std::vector< TPEF::MoveElement * > MoveVector
const TTAMachine::Machine * machine_
Target machine of program.
TTAMachine::Bus & findBus(const TPEF::ResourceSection &resources, HalfWord busId) const
bool canDestinationBeAssigned(SocketAllocation &alloc, std::map< TTAMachine::Socket *, std::vector< SocketAllocation * > > &fixedSockets) const
std::string stringOfChunk(const TPEF::Chunk *chunk, const TPEF::Section *chunkOwner) const
std::map< HalfWord, SimValue * > InlineValues
bool canSourceBeAssigned(SocketAllocation &alloc, std::map< TTAMachine::Socket *, std::vector< SocketAllocation * > > &fixedSockets) const
TPEF::ASpaceElement * tpefInstrASpace_
Instruction address space element of TPEF.
TTAMachine::RegisterFile & findRegisterFile(const TPEF::ResourceSection &resources, HalfWord rfId) const
TTAMachine::AddressSpace & findAddressSpace(const TPEF::ASpaceElement *aSpace) const
std::set< HalfWord > allocatedBusses_
Busses that are already allocated by moves of current instruction.
void createDataRelocs(Program &prog)
std::string functionName(const TPEF::InstructionElement &instructionElement) const
std::map< ImmediateKey, TPEF::ImmediateElement * > ImmediateMap
const TPEF::Binary * binary_
Binary that is used for creating program.
TTAMachine::Guard & findGuard(const TPEF::ResourceSection &resources, TTAMachine::Bus &bus, TPEF::MoveElement::FieldType type, HalfWord unitId, HalfWord index, bool isInverted) const
bool isFunctionStart(const TPEF::InstructionElement &instructionElement) const
std::list< std::shared_ptr< Immediate > > longInstructionImmediates_
Long immediates whose value terminals refers to instructions.
TTAMachine::ImmediateUnit & findImmediateUnit(const TPEF::ResourceSection &resources, Byte immUnitId) const
TTAMachine::AddressSpace * adfInstrASpace_
Instruction address space of machine.
void resolveSocketAllocations(std::vector< SocketAllocation > &allocs) const
TPEF::TPEFTools tpefTools_
TPEFTools object for helper functions.
std::map< const CacheKey, Terminal * > cache_
Cache map of terminals that are returned by different search parameters.
void addToCache(const CacheKey &key, Terminal *cachedTerm) const
std::pair< Word, Word > ImmediateKey
Terminal * getFromCache(const CacheKey &key) const
void addProcedures(Program &program, const TTAMachine::AddressSpace &programASpace) const
TTAMachine::FunctionUnit & findFunctionUnit(const TPEF::ResourceSection &resources, HalfWord unitId, std::string tpefOpName="") const
Instruction * createInstruction(const TPEF::ResourceSection &resources, MoveVector &moveElements, ImmediateVector &longImmediates, ImmediateMap &immElements) const
Terminal * createTerminal(const TPEF::ResourceSection &resources, const TTAMachine::Bus *aBus, TTAMachine::Socket::Direction direction, TPEF::MoveElement::FieldType type, HalfWord unitId, HalfWord index, const ImmediateMap *immediateMap=NULL) const
TTAMachine::Port & findPort(const TTAMachine::Bus &bus, const TTAMachine::Unit &portParent, std::string tpefOpName="", int tpefOpIndex=0) const
UniversalMachine * universalMachine_
Universal machine of program.
std::map< TPEF::InstructionElement *, Instruction * > instructionMap_
Program instruction by TPEF instruction element.
TTAMachine::InstructionTemplate & findInstrTemplate(const TPEF::ResourceSection &resources, ImmediateVector &longImmediates, MoveVector &moves) const
std::list< std::shared_ptr< Move > > instructionImmediates_
Moves whose source terminals are addresses referring to instructions.
std::map< const TPEF::InstructionElement *, class FunctionStart * > functionStartPositions_
Stores information of start points of procedures that were found.
SocketAllocation(std::shared_ptr< Move > m, unsigned int anIndex)