OpenASIP 2.2
Loading...
Searching...
No Matches
MoveNodeDuplicator.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2015 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/**
26 * This class is used for copying moves from a basic block to another
27 * corresponding basic block, copying also the programoperation structure.
28 */
29
30#include "MoveNodeDuplicator.hh"
31
32#include "BasicBlockNode.hh"
33#include "AssocTools.hh"
35#include "ProgramAnnotation.hh"
36#include "HWOperation.hh"
37#include "Operation.hh"
38#include "UniversalMachine.hh"
39#include "Terminal.hh"
40#include "MoveGuard.hh"
42#include "Move.hh"
43#include "TerminalFUPort.hh"
44#include "ControlUnit.hh"
46
47
50 oldDDG_(&oldDDG), newDDG_(&newDDG),
51 bigDDG_(static_cast<DataDependenceGraph*>(oldDDG.rootGraph())) { }
52
54 if (newMN == NULL) {
55 return;
56 }
57 if (newMN->isScheduled()) {
58 std::cerr << "\t\t\t\t\tCannot dispose scheduled mn: "
59 << newMN->toString() << std::endl;
60 assert(false);
61 }
62 assert(!newMN->isScheduled());
63 std::map<MoveNode*,MoveNode*,MoveNode::Comparator>::iterator i =
64 oldMoveNodes_.find(newMN);
65 // already disposed?
66 if (i == oldMoveNodes_.end()) {
67 return;
68 }
69 MoveNode* old = i->second;
70 moveNodes_.erase(old);
71 oldMoveNodes_.erase(newMN);
72 TTAProgram::Move* oldMove = &old->move();
73 moves_.erase(oldMove);
74 if (newDDG_->hasNode(*newMN)) {
75 newDDG_->removeNode(*newMN);
76 }
77 delete newMN;
78}
79
80/*
81 * Gets already duplicated move, but does not create a new one.
82 * If none found, returns null
83 */
86 std::map<MoveNode*,MoveNode*,MoveNode::Comparator>::iterator iter =
87 moveNodes_.find(&old);
88if (iter != moveNodes_.end()) {
89 return iter->second;
90 }
91 return NULL;
92}
93
94
95/**
96 *
97 * Duplicates a corresponding MoveNode a given move in the next BB.
98 *
99 * If no corresponding MoveNode created, creates one
100 *
101 * @param old ProgramOperation in jump target BB.
102 * @return new MoveNode for this BB.
103 */
104
105std::pair<MoveNode*, bool>
107 MoveNode& old, bool addToDDG, bool ignoreSameBBBackEdges) {
108 std::map<MoveNode*,MoveNode*,MoveNode::Comparator>::iterator iter =
109 moveNodes_.find(&old);
110
111 if (iter != moveNodes_.end()) {
112 MoveNode* node = iter->second;
113 if (addToDDG) {
114 if (!newDDG_->hasNode(*node)) {
115 newDDG_->addNode(*node, *bbn_);
116 bigDDG_->copyDependencies(old,*node, ignoreSameBBBackEdges, false);
117 }
118 }
119 }
121#ifdef DEBUG_BUBBLEFISH_SCHEDULER
122 std::cerr << "\t\t\t\t\told mn found: "
123 << moveNodes_[&old]->toString() << std::endl;
124#endif
125 return std::make_pair(moveNodes_[&old], false);
126 } else {
127 auto movePtr = duplicateMove(old.move());
128 MoveNode *newMN = new MoveNode(movePtr);
129
130 // TODO: only add to ddg if really scheduling, not for testing?
131 if (addToDDG) {
132 newDDG_->addNode(*newMN, *bbn_);
133 bigDDG_->copyDependencies(old,*newMN, ignoreSameBBBackEdges, false);
134 }
135
136 moveNodes_[&old] = newMN;
137 oldMoveNodes_[newMN] = &old;
138 if (old.isSourceOperation()) {
141 newMN->sourceOperation().addOutputNode(*newMN);
142 assert(newMN->isSourceOperation());
143 }
144 if (old.isDestinationOperation()) {
145 for (unsigned int i = 0;
146 i < old.destinationOperationCount(); i++) {
150 newMN->destinationOperation(i).addInputNode(*newMN);
151 }
153 }
154 if (old.isGuardOperation()) {
157 newMN->guardOperation().addGuardOutputNode(*newMN);
158 assert(newMN->isGuardOperation());
159 }
160 return std::make_pair(newMN, true);
161 }
162}
163
164/**
165 * Gets a corresponding ProgramOperation to a given move in the next BB.
166 *
167 * If no corresponding ProgramOperation created, creates one
168 *
169 * @param old ProgramOperation in jump target BB.
170 * @return new ProgramOperation for this BB.
171 */
174 ProgramOperationPtr old) { // , BasicBlockNode& bbn) {
176 return programOperations_[old.get()];
177 } else {
180 new ProgramOperation(old->operation()));
181 programOperations_[old.get()] = po;
182 oldProgramOperations_[po.get()] = old;
183 return po;
184 }
185}
186
189 auto i = programOperations_.find(old.get());
190 if (i != programOperations_.end()) {
191 return i->second;
192 } else {
193 return ProgramOperationPtr(nullptr);
194 }
195}
196
197
198std::shared_ptr<TTAProgram::Move>
201 return moves_[&old];
202 } else {
203 MoveNode& oldMN = oldDDG_->nodeOfMove(old);
204 std::shared_ptr<TTAProgram::Move> newMove(old.copy());
205 newMove->setBus(UniversalMachine::instance().universalBus());
206
207 TTAProgram::Terminal& source = newMove->source();
208 if (oldMN.isSourceOperation()) {
209 if (oldMN.isScheduled()) {
210 assert(source.isFUPort());
211 std::string fuName = source.functionUnit().name();
212 //TODO: which is the correct annotation here?
215 fuName);
216 newMove->setAnnotation(srcUnit);
217 const Operation &srcOp = oldMN.sourceOperation().operation();
218 const TTAMachine::HWOperation& hwop =
220 operation(srcOp.name());
221 newMove->setSource(new TTAProgram::TerminalFUPort(
222 hwop, old.source().operationIndex()));
223 }
224 } else {
225 if (source.isRA()) {
226 newMove->setSource(
228 *UniversalMachine::instance().controlUnit()->
229 returnAddressPort()));
230 }
231 }
232
233 TTAProgram::Terminal& dest = newMove->destination();
234 if (oldMN.isDestinationOperation()) {
235 assert(dest.isFUPort());
236
237 if (oldMN.isScheduled()) {
238 std::string fuName = dest.functionUnit().name();
239 //TODO: which is the correct annotation here?
242 fuName);
243 newMove->setAnnotation(dstUnit);
244 const Operation &dstOp =
248 operation(dstOp.name());
249 newMove->setDestination(new TTAProgram::TerminalFUPort(
250 hwop, old.destination().
251 operationIndex()));
252 } else {
253 if (dest.isRA()) {
254 newMove->setDestination(
256 *UniversalMachine::instance().controlUnit()->
257 returnAddressPort()));
258 }
259 }
260 }
261
262 moves_[&old] = newMove;
263
264 // set guard of new move to be same as old move.
265 if (!old.isUnconditional()) {
266 TTAProgram::MoveGuard* g = old.guard().copy();
267 newMove->setGuard(g);
268 }
269 return newMove;
270 }
271}
272
274 newDDG_->writeToDotFile("prolog_ddg.dot");
275}
#define assert(condition)
std::shared_ptr< ProgramOperation > ProgramOperationPtr
Definition MoveNode.hh:53
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
bool hasNode(const Node &) const
void copyDependencies(const MoveNode &src, MoveNode &dst, bool ignoreSameBBBackedges, bool moveOverLoopEdge=true)
void addNode(MoveNode &moveNode)
MoveNode & nodeOfMove(const TTAProgram::Move &move)
void removeNode(MoveNode &node)
virtual void writeToDotFile(const TCEString &fileName) const
DataDependenceGraph * bigDDG_
BasicBlockNode * bbn_
MoveNodeDuplicator(DataDependenceGraph &oldDDG, DataDependenceGraph &newDDG)
DataDependenceGraph * newDDG_
std::map< ProgramOperation *, ProgramOperationPtr, ProgramOperation::Comparator > programOperations_
std::shared_ptr< TTAProgram::Move > duplicateMove(TTAProgram::Move &old)
ProgramOperationPtr getProgramOperation(ProgramOperationPtr old)
std::map< TTAProgram::Move *, std::shared_ptr< TTAProgram::Move > > moves_
DataDependenceGraph * oldDDG_
std::map< ProgramOperation *, ProgramOperationPtr, ProgramOperation::Comparator > oldProgramOperations_
std::map< MoveNode *, MoveNode *, MoveNode::Comparator > oldMoveNodes_
MoveNode * getMoveNode(MoveNode &mn)
void disposeMoveNode(MoveNode *newMN)
ProgramOperationPtr duplicateProgramOperationPtr(ProgramOperationPtr old)
std::map< MoveNode *, MoveNode *, MoveNode::Comparator > moveNodes_
std::pair< MoveNode *, bool > duplicateMoveNode(MoveNode &mn, bool addToDDG, bool ignoreSameBBBackEdges)
void setGuardOperationPtr(ProgramOperationPtr po)
Definition MoveNode.cc:550
void setSourceOperationPtr(ProgramOperationPtr po)
Definition MoveNode.cc:541
ProgramOperationPtr sourceOperationPtr() const
Definition MoveNode.cc:458
unsigned int destinationOperationCount() const
bool isGuardOperation() const
Definition MoveNode.cc:181
ProgramOperationPtr guardOperationPtr() const
Definition MoveNode.cc:484
ProgramOperation & sourceOperation() const
Definition MoveNode.cc:453
bool isDestinationOperation() const
std::string toString() const
Definition MoveNode.cc:576
ProgramOperation & guardOperation() const
Definition MoveNode.cc:479
TTAProgram::Move & move()
bool isSourceOperation() const
Definition MoveNode.cc:168
bool isScheduled() const
Definition MoveNode.cc:409
ProgramOperationPtr destinationOperationPtr(unsigned int index=0) const
void addDestinationOperationPtr(ProgramOperationPtr po)
Definition MoveNode.cc:533
ProgramOperation & destinationOperation(unsigned int index=0) const
virtual TCEString name() const
Definition Operation.cc:93
void addGuardOutputNode(MoveNode &node)
const Operation & operation() const
void addOutputNode(MoveNode &node, int outputIndex)
void addInputNode(MoveNode &node)
virtual TCEString name() const
MoveGuard * copy() const
Definition MoveGuard.cc:96
MoveGuard & guard() const
Definition Move.cc:345
bool isUnconditional() const
Definition Move.cc:154
Terminal & source() const
Definition Move.cc:302
std::shared_ptr< Move > copy() const
Definition Move.cc:413
Terminal & destination() const
Definition Move.cc:323
@ ANN_CONN_CANDIDATE_UNIT_DST
Dst. unit candidate.
@ ANN_CONN_CANDIDATE_UNIT_SRC
Src. unit candidate.
virtual bool isRA() const
Definition Terminal.cc:129
virtual const TTAMachine::FunctionUnit & functionUnit() const
Definition Terminal.cc:251
virtual int operationIndex() const
Definition Terminal.cc:364
virtual bool isFUPort() const
Definition Terminal.cc:118
static UniversalMachine & instance()
UniversalFunctionUnit & universalFunctionUnit() const