OpenASIP 2.2
Loading...
Searching...
No Matches
RegisterCopyAdder.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 RegisterCopyAdder.hh
26 *
27 * Declaration of RegisterCopyAdder class.
28 *
29 * @author Pekka Jääskeläinen 2007 (pjaaskel-no.spam-cs.tut.fi)
30 * @author Fabio Garzia 2010 (fabio.garzia-no.spam-tut.fi)
31 * @note rating: yellow
32 * @note reviewed 16-17 January 2008 by pj, pk, ml, hk
33 */
34
35#ifndef TTA_REGISTER_COPY_ADDER_HH
36#define TTA_REGISTER_COPY_ADDER_HH
37
38#include <map>
39
41#include "FunctionUnit.hh"
42
44class MoveNode;
46class InterPassData;
49
50namespace TTAProgram {
51 class Move;
52 class BasicBlock;
53}
54
55namespace TTAMachine {
56 class Port;
57 class RegisterFile;
58}
59
60/**
61 * Adds register copies through connected register files in case of missing
62 * connectivity in the operand moves of operations.
63 *
64 * In addition, annotates the moves in the operation with missing connectivity
65 * with the function unit candidates that are connected to all operand
66 * moves of the operation. The annotations should be checked and followed
67 * by the resource assignment stage to avoid scheduling failure due to
68 * missing connectivity. That is, after executing this pass, the scheduler
69 * (and resource assigner) can assume there is enough connectivity in the
70 * machine to schedule all moves of the operation (given the candidate FU
71 * annotations are adhered to).
72 *
73 * Immediates that must be converted to long immediates are annotated with
74 * the required IU which is guaranteed to have connectivity to the target FU.
75 * The RM/scheduler, when converting a short immediate to a long immediate
76 * must take this annotation in account, otherwise scheduling error might
77 * occur. It tries to minimize the added temp register copies for
78 * the operation by considering all possible FU bindings to each operation.
79 *
80 * The pass inputs a DDG with registers allocated but other resources
81 * unassigned in the considered operation and outputs a DDG with register
82 * copy moves inserted due to missing connectivity. Operation moves are
83 * annotated with candidate function units and immediate units for operation and
84 * immediate assignments. In case all function units / immediate units are
85 * equal candidates according to connectivity, no annotations are inserted as
86 * the FU/IU can be assigned freely to the operation/immediate.
87 *
88 * The candidate annotatons *must be* adhered to in resource assignment,
89 * otherwise the scheduling might fail due to missing connectivity.
90 */
92public:
94 InterPassData& data,
96 MoveNodeSelector& selector,
97 bool buScheduler = false);
98
99 virtual ~RegisterCopyAdder();
100
101 typedef std::map<const MoveNode*, DataDependenceGraph::NodeSet>
103
111
113 ProgramOperation& programOperation,
114 const TTAMachine::Machine& targetMachine,
116
118 AddedRegisterCopies& copies,
120
121 void resultsScheduled(
122 AddedRegisterCopies& copies,
124
126 MoveNode& moveNode,
128
129 static void findTempRegisters(
131
132 static void fixDDGEdgesInTempReg(
134 MoveNode& originalMove,
135 MoveNode* firstMove,
136 MoveNode* lastMove,
137 const TTAMachine::RegisterFile* lastRF,
138 int lastRegisterIndex,
139 BasicBlockNode& currentBBNode,
140 bool bottomUpScheduling,
141 bool loopScheduling);
142
143private:
144 bool isAllowedUnit(
145 const TTAMachine::FunctionUnit& fu,
146 const ProgramOperation& po);
147
149 ProgramOperation& programOperation,
150 const TTAMachine::FunctionUnit& fu,
151 bool countOnly = true,
152 DataDependenceGraph* ddg = NULL,
153 int neededCopies = 0);
154
156 MoveNode& originalMove,
157 const TTAMachine::Port& sourcePort,
158 const TTAMachine::Port& destinationPort,
159 bool countOnly = true,
160 DataDependenceGraph* ddg = NULL,
161 DataDependenceGraph::NodeSet* addedNodes = NULL,
162 int neededCopies = 0);
163
165 MoveNode& originalMove,
166 const TTAMachine::Port& destinationPort,
167 bool countOnly = true,
168 DataDependenceGraph* ddg = NULL,
169 DataDependenceGraph::NodeSet* addedNodes = NULL);
170
172 MoveNode& moveNode,
173 const TTAMachine::FunctionUnit& fu,
174 bool countOnly = true,
175 DataDependenceGraph* ddg = NULL,
176 DataDependenceGraph::NodeSet* addedNodes = NULL,
177 int neededCopies = 0);
178
180 MoveNode& moveNode,
181 DataDependenceGraph* ddg = NULL,
182 DataDependenceGraph::NodeSet* addedNodes = NULL);
183
185 ProgramOperation& programOperation,
187
190 MoveNode& originalMove,
191 MoveNode* firstMove,
192 std::vector<MoveNode*> intMoves,
193 MoveNode* lastMove,
194 const TTAMachine::RegisterFile* firstRF,
195 std::vector<const TTAMachine::RegisterFile*> intRF,
196 const TTAMachine::RegisterFile* lastRF,
197 int firstRegisterIndex,
198 std::vector<int> intRegisterIndex,
199 int lastRegisterIndex,
200 int regsRequired,
201 BasicBlockNode& currentBBNode);
202
203 static void createAntidepsForReg(
204 const MoveNode& defMove,
205 const MoveNode& useMove,
206 const MoveNode& originalMove,
207 const TTAMachine::RegisterFile& rf,
208 int index,
210 BasicBlockNode& bbn,
211 bool backwards,
212 bool loopScheduling);
213
216 MoveNode& originalMove,
217 MoveNode* firstMove,
218 MoveNode* regToRegCopy,
219 MoveNode* lastMove,
220 const TTAMachine::RegisterFile* tempRF1,
221 const TTAMachine::RegisterFile* tempRF2,
222 int tempRegisterIndex1,
223 int tempRegisterIndex2,
224 BasicBlockNode& currentBBNode);
225
226 /// container for storing the required register copies if the operation
227 /// was bound to the given FU
228 typedef std::map<
229 const TTAMachine::FunctionUnit*, int,
232
234 const TTAMachine::Machine& targetMachine,
235 ProgramOperation& programOperation);
236
237 /// the inter pass data from which to fetch the scratch register list
239 /// the resource manager to check for machine resources in heuristics
240 // SimpleResourceManager provides many methods not in the base interface
241 // ResourceManager, so we cannot use it.
243 /// Indicate that register copy adder is called from bottom up scheduler,
244 /// this causes search for first scheduled register write instead of last
245 /// read.
247};
248#endif
TTAMachine::Machine * machine
the architecture definition of the estimated processor
std::set< GraphNode *, typename GraphNode::Comparator > NodeSet
Definition Graph.hh:53
bool buScheduler_
Indicate that register copy adder is called from bottom up scheduler, this causes search for first sc...
static void fixDDGEdgesInTempReg(DataDependenceGraph &ddg, MoveNode &originalMove, MoveNode *firstMove, MoveNode *lastMove, const TTAMachine::RegisterFile *lastRF, int lastRegisterIndex, BasicBlockNode &currentBBNode, bool bottomUpScheduling, bool loopScheduling)
static void findTempRegisters(const TTAMachine::Machine &machine, InterPassData &ipd)
void operandsScheduled(AddedRegisterCopies &copies, DataDependenceGraph &ddg)
void fixDDGEdgesInTempRegChainImmediate(DataDependenceGraph &ddg, MoveNode &originalMove, MoveNode *firstMove, MoveNode *regToRegCopy, MoveNode *lastMove, const TTAMachine::RegisterFile *tempRF1, const TTAMachine::RegisterFile *tempRF2, int tempRegisterIndex1, int tempRegisterIndex2, BasicBlockNode &currentBBNode)
std::map< const TTAMachine::FunctionUnit *, int, TTAMachine::FunctionUnit::Comparator > RegisterCopyCountIndex
container for storing the required register copies if the operation was bound to the given FU
AddedRegisterCopies addRegisterCopiesToRRMove(MoveNode &moveNode, DataDependenceGraph *ddg)
bool isAllowedUnit(const TTAMachine::FunctionUnit &fu, const ProgramOperation &po)
int addConnectionRegisterCopies(MoveNode &originalMove, const TTAMachine::Port &sourcePort, const TTAMachine::Port &destinationPort, bool countOnly=true, DataDependenceGraph *ddg=NULL, DataDependenceGraph::NodeSet *addedNodes=NULL, int neededCopies=0)
InterPassData & interPassData_
the inter pass data from which to fetch the scratch register list
void fixDDGEdgesInTempRegChain(DataDependenceGraph &ddg, MoveNode &originalMove, MoveNode *firstMove, std::vector< MoveNode * > intMoves, MoveNode *lastMove, const TTAMachine::RegisterFile *firstRF, std::vector< const TTAMachine::RegisterFile * > intRF, const TTAMachine::RegisterFile *lastRF, int firstRegisterIndex, std::vector< int > intRegisterIndex, int lastRegisterIndex, int regsRequired, BasicBlockNode &currentBBNode)
SimpleResourceManager & rm_
the resource manager to check for machine resources in heuristics
std::map< const MoveNode *, DataDependenceGraph::NodeSet > AddedRegisterCopyMap
static void createAntidepsForReg(const MoveNode &defMove, const MoveNode &useMove, const MoveNode &originalMove, const TTAMachine::RegisterFile &rf, int index, DataDependenceGraph &ddg, BasicBlockNode &bbn, bool backwards, bool loopScheduling)
int addConnectionRegisterCopiesImmediate(MoveNode &originalMove, const TTAMachine::Port &destinationPort, bool countOnly=true, DataDependenceGraph *ddg=NULL, DataDependenceGraph::NodeSet *addedNodes=NULL)
AddedRegisterCopies addRegisterCopies(ProgramOperation &programOperation, const TTAMachine::FunctionUnit &fu, bool countOnly=true, DataDependenceGraph *ddg=NULL, int neededCopies=0)
RegisterCopyCountIndex requiredRegisterCopiesForEachFU(const TTAMachine::Machine &targetMachine, ProgramOperation &programOperation)
int countAndAddConnectionRegisterCopiesToRR(MoveNode &moveNode, DataDependenceGraph *ddg=NULL, DataDependenceGraph::NodeSet *addedNodes=NULL)
void addCandidateSetAnnotations(ProgramOperation &programOperation, const TTAMachine::Machine &machine)
void resultsScheduled(AddedRegisterCopies &copies, DataDependenceGraph &ddg)
AddedRegisterCopies addMinimumRegisterCopies(ProgramOperation &programOperation, const TTAMachine::Machine &targetMachine, DataDependenceGraph *ddg)