OpenASIP  2.0
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 
40 #include "DataDependenceGraph.hh"
41 #include "FunctionUnit.hh"
42 
43 class ProgramOperation;
44 class MoveNode;
46 class InterPassData;
47 class MoveNodeSelector;
49 
50 namespace TTAProgram {
51  class Move;
52  class BasicBlock;
53 }
54 
55 namespace 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  */
92 public:
94  InterPassData& data,
96  MoveNodeSelector& selector,
97  bool buScheduler = false);
98 
99  virtual ~RegisterCopyAdder();
100 
101  typedef std::map<const MoveNode*, DataDependenceGraph::NodeSet>
103 
105  AddedRegisterCopies(int count);
107  int count_;
110  };
111 
113  ProgramOperation& programOperation,
114  const TTAMachine::Machine& targetMachine,
115  DataDependenceGraph* ddg);
116 
117  void operandsScheduled(
118  AddedRegisterCopies& copies,
119  DataDependenceGraph& ddg);
120 
121  void resultsScheduled(
122  AddedRegisterCopies& copies,
123  DataDependenceGraph& ddg);
124 
126  MoveNode& moveNode,
127  DataDependenceGraph* ddg);
128 
129  static void findTempRegisters(
131 
132  static void fixDDGEdgesInTempReg(
133  DataDependenceGraph& ddg,
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 
143 private:
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 
189  DataDependenceGraph& ddg,
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,
209  DataDependenceGraph& ddg,
210  BasicBlockNode& bbn,
211  bool backwards,
212  bool loopScheduling);
213 
215  DataDependenceGraph& ddg,
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
RegisterCopyAdder::AddedRegisterCopies
Definition: RegisterCopyAdder.hh:104
TTAProgram
Definition: Estimator.hh:65
RegisterCopyAdder::addConnectionRegisterCopiesImmediate
int addConnectionRegisterCopiesImmediate(MoveNode &originalMove, const TTAMachine::Port &destinationPort, bool countOnly=true, DataDependenceGraph *ddg=NULL, DataDependenceGraph::NodeSet *addedNodes=NULL)
Definition: RegisterCopyAdder.cc:767
RegisterCopyAdder::AddedRegisterCopyMap
std::map< const MoveNode *, DataDependenceGraph::NodeSet > AddedRegisterCopyMap
Definition: RegisterCopyAdder.hh:102
RegisterCopyAdder::addCandidateSetAnnotations
void addCandidateSetAnnotations(ProgramOperation &programOperation, const TTAMachine::Machine &machine)
Definition: RegisterCopyAdder.cc:2002
RegisterCopyAdder
Definition: RegisterCopyAdder.hh:91
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
RegisterCopyAdder::fixDDGEdgesInTempRegChainImmediate
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)
Definition: RegisterCopyAdder.cc:1501
RegisterCopyAdder::interPassData_
InterPassData & interPassData_
the inter pass data from which to fetch the scratch register list
Definition: RegisterCopyAdder.hh:238
BoostGraph< MoveNode, DataDependenceEdge >::NodeSet
std::set< MoveNode *, typename MoveNode ::Comparator > NodeSet
Definition: BoostGraph.hh:86
RegisterCopyAdder::AddedRegisterCopies::AddedRegisterCopies
AddedRegisterCopies()
Definition: RegisterCopyAdder.cc:2241
RegisterCopyAdder::AddedRegisterCopies::operandCopies_
AddedRegisterCopyMap operandCopies_
Definition: RegisterCopyAdder.hh:108
RegisterCopyAdder::RegisterCopyCountIndex
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
Definition: RegisterCopyAdder.hh:231
RegisterCopyAdder::addRegisterCopies
AddedRegisterCopies addRegisterCopies(ProgramOperation &programOperation, const TTAMachine::FunctionUnit &fu, bool countOnly=true, DataDependenceGraph *ddg=NULL, int neededCopies=0)
Definition: RegisterCopyAdder.cc:257
DataDependenceGraph.hh
ProgramOperation
Definition: ProgramOperation.hh:70
MoveNode
Definition: MoveNode.hh:65
RegisterCopyAdder::fixDDGEdgesInTempReg
static void fixDDGEdgesInTempReg(DataDependenceGraph &ddg, MoveNode &originalMove, MoveNode *firstMove, MoveNode *lastMove, const TTAMachine::RegisterFile *lastRF, int lastRegisterIndex, BasicBlockNode &currentBBNode, bool bottomUpScheduling, bool loopScheduling)
Definition: RegisterCopyAdder.cc:1048
RegisterCopyAdder::RegisterCopyAdder
RegisterCopyAdder(InterPassData &data, SimpleResourceManager &rm, MoveNodeSelector &selector, bool buScheduler=false)
Definition: RegisterCopyAdder.cc:74
RegisterCopyAdder::requiredRegisterCopiesForEachFU
RegisterCopyCountIndex requiredRegisterCopiesForEachFU(const TTAMachine::Machine &targetMachine, ProgramOperation &programOperation)
Definition: RegisterCopyAdder.cc:95
RegisterCopyAdder::isAllowedUnit
bool isAllowedUnit(const TTAMachine::FunctionUnit &fu, const ProgramOperation &po)
Definition: RegisterCopyAdder.cc:2196
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
RegisterCopyAdder::addRegisterCopiesToRRMove
AddedRegisterCopies addRegisterCopiesToRRMove(MoveNode &moveNode, DataDependenceGraph *ddg)
Definition: RegisterCopyAdder.cc:212
RegisterCopyAdder::findTempRegisters
static void findTempRegisters(const TTAMachine::Machine &machine, InterPassData &ipd)
Definition: RegisterCopyAdder.cc:2136
TTAMachine::Port
Definition: Port.hh:54
BasicBlockNode
Definition: BasicBlockNode.hh:64
RegisterCopyAdder::operandsScheduled
void operandsScheduled(AddedRegisterCopies &copies, DataDependenceGraph &ddg)
Definition: RegisterCopyAdder.cc:2079
RegisterCopyAdder::AddedRegisterCopies::count_
int count_
Definition: RegisterCopyAdder.hh:107
InterPassData
Definition: InterPassData.hh:48
MoveNodeSelector
Definition: MoveNodeSelector.hh:45
RegisterCopyAdder::rm_
SimpleResourceManager & rm_
the resource manager to check for machine resources in heuristics
Definition: RegisterCopyAdder.hh:242
RegisterCopyAdder::~RegisterCopyAdder
virtual ~RegisterCopyAdder()
Definition: RegisterCopyAdder.cc:84
RegisterCopyAdder::AddedRegisterCopies::resultCopies_
AddedRegisterCopyMap resultCopies_
Definition: RegisterCopyAdder.hh:109
RegisterCopyAdder::resultsScheduled
void resultsScheduled(AddedRegisterCopies &copies, DataDependenceGraph &ddg)
Definition: RegisterCopyAdder.cc:2108
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
RegisterCopyAdder::createAntidepsForReg
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)
Definition: RegisterCopyAdder.cc:1312
SimpleResourceManager
Definition: SimpleResourceManager.hh:58
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
RegisterCopyAdder::fixDDGEdgesInTempRegChain
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)
Definition: RegisterCopyAdder.cc:1170
RegisterCopyAdder::countAndAddConnectionRegisterCopiesToRR
int countAndAddConnectionRegisterCopiesToRR(MoveNode &moveNode, DataDependenceGraph *ddg=NULL, DataDependenceGraph::NodeSet *addedNodes=NULL)
Definition: RegisterCopyAdder.cc:1638
TTAMachine
Definition: Assembler.hh:48
TTAMachine::MachinePart::Comparator
Definition: MachinePart.hh:59
RegisterCopyAdder::addConnectionRegisterCopies
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)
Definition: RegisterCopyAdder.cc:328
RegisterCopyAdder::buScheduler_
bool buScheduler_
Indicate that register copy adder is called from bottom up scheduler, this causes search for first sc...
Definition: RegisterCopyAdder.hh:246
TTAMachine::Machine
Definition: Machine.hh:73
FunctionUnit.hh
RegisterCopyAdder::addMinimumRegisterCopies
AddedRegisterCopies addMinimumRegisterCopies(ProgramOperation &programOperation, const TTAMachine::Machine &targetMachine, DataDependenceGraph *ddg)
Definition: RegisterCopyAdder.cc:139