OpenASIP 2.2
Loading...
Searching...
No Matches
BFRegCopyAfter.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2014 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 * @file BFRegCopyAfter.cc
27 *
28 * Definition of BFRegCopyAfter class
29 *
30 * Creates a register-to-register copy after a move, modifying the destination
31 * of the original move into the temporaty register and makint the destination
32 * of the temp move the original destination register.
33 *
34 * Used for tempreg copies of result moves.
35 *
36 * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
37 * @note rating: red
38 */
39
40#include "BFRegCopyAfter.hh"
41#include "MoveNode.hh"
43#include "RegisterFile.hh"
44#include "TerminalRegister.hh"
45#include "Move.hh"
46#include "BF2Scheduler.hh"
47#include "BFConnectNodes.hh"
48#include "BFRemoveEdge.hh"
49#include "BFScheduleBU.hh"
50bool
52
53#ifdef DEBUG_BUBBLEFISH_SCHEDULER
54 std::cerr << "\t\tBFRegCopyAfter splitting move: "
55 << mn_.toString() << std::endl;
56#endif
57
58 std::set<const TTAMachine::RegisterFile*,
60 rfs = sched_.possibleTempRegRFs(mn_, true);
61
62 // cannot create reg copy if no temp regs available.
63 if (rfs.empty()) {
64 return false;
65 }
66
67 const TTAMachine::RegisterFile& rf = **rfs.rbegin();
68
69 int lastRegisterIndex = rf.size()-1;
70 TTAMachine::Port* dstRFPort = rf.firstWritePort();
71 TTAMachine::Port* srcRFPort = rf.firstReadPort();
72
74 new TTAProgram::TerminalRegister(*dstRFPort, lastRegisterIndex);
75
77 new TTAProgram::TerminalRegister(*srcRFPort, lastRegisterIndex);
78
79 regCopy_->move().setSource(tempRead);
80 mn_.move().setDestination(tempWrite);
81
82 auto iEdges = ddg().rootGraph()->inEdges(mn_);
83 for (auto iEdge : iEdges) {
84 if (!iEdge->isRegisterOrRA() || iEdge->headPseudo()) {
85 continue;
86 }
87
88 //copy guard use edge to the regcopy.
89 if (iEdge->guardUse() &&
90 iEdge->dependenceType() == DataDependenceEdge::DEP_RAW) {
91 MoveNode& tail = ddg().rootGraph()->tailNode(*iEdge);
93 new BFConnectNodes(sched_, tail, *regCopy_, iEdge, true));
94 } else if (iEdge->isFalseDep()) {
95 MoveNode& tail = ddg().rootGraph()->tailNode(*iEdge);
96 runPostChild(new BFRemoveEdge(sched_, tail, mn_, *iEdge));
97 runPostChild(new BFConnectNodes(sched_, tail, *regCopy_, iEdge));
98 }
99 }
100
101 auto oEdges = ddg().rootGraph()->outEdges(mn_);
102 for (auto oEdge : oEdges) {
103 if (!oEdge->isRegisterOrRA() || oEdge->tailPseudo()) {
104 continue;
105 }
106
107 if (oEdge->dependenceType() == DataDependenceEdge::DEP_WAW ||
108 oEdge->dependenceType() == DataDependenceEdge::DEP_RAW) {
109
110 MoveNode& head = ddg().rootGraph()->headNode(*oEdge);
111 runPostChild(new BFRemoveEdge(sched_, mn_, head, *oEdge));
112 runPostChild(new BFConnectNodes(sched_, *regCopy_, head, oEdge));
113 }
114
115 if (oEdge->dependenceType() == DataDependenceEdge::DEP_WAR &&
116 oEdge->guardUse()) {
117 MoveNode& head = ddg().rootGraph()->headNode(*oEdge);
119 new BFConnectNodes(sched_, *regCopy_, head, oEdge, true));
120 }
121 }
122
123 TCEString tempRegName = rf.name() + '.' +
124 Conversion::toString(lastRegisterIndex);
125
126 DataDependenceEdge* newEdge =
129 DataDependenceEdge::DEP_RAW, tempRegName);
130
132
134 mn_, *regCopy_, rf, lastRegisterIndex,
135 tempRegName, bbn, ii()!= 0);
136
137#ifdef DEBUG_BUBBLEFISH_SCHEDULER
138 std::cerr << " \t\t\tMoves after split: " << mn_.toString() << " and " <<
139 regCopy_->toString() << std::endl;
140#endif
141#ifdef DEBUG_BUBBLEFISH_SCHEDULER
142// writeDotWithNameAndNodeID(ddg(), "regcopy_created_after", mn_);
143
144// assert(ddg_->maxSourceDistance(mn) != -1);
145// assert(ddg_->maxSourceDistance(*copyNode) != -1);
146// std::cerr << "\t\tmn source distance: " << ddg_->maxSourceDistance(mn) << std::endl;
147// std::cerr << "\t\tmn regcopy source distance: " << ddg_->maxSourceDistance(*copyNode) << std::endl;
148#endif
149
150 // TODO: bypass regcopies??
151 BFScheduleBU* regCopySched =
152 new BFScheduleBU(sched_,*regCopy_, lc_, true, true, false);
153 bool ok = runPostChild(regCopySched);
154 if (!ok) {
156 undoSplit();
157 return false;
158 }
159 return true;
160}
161
162void
164#ifdef DEBUG_BUBBLEFISH_SCHEDULER
165 std::cerr << "\t\tBFRegCopyAfter undoing split move: " << mn_.toString()
166 << " and " << regCopy_->toString() << std::endl;
167#endif
169}
std::set< const TTAMachine::RegisterFile *, TTAMachine::MachinePart::Comparator > possibleTempRegRFs(const MoveNode &mn, bool tempRegAfter, const TTAMachine::RegisterFile *forbiddenRF=nullptr)
unsigned int ii() const
BF2Scheduler & sched_
DataDependenceGraph & ddg()
bool splitMove(BasicBlockNode &bbn)
MoveNode * regCopy_
Definition BFRegCopy.hh:70
void createAntidepsForReg(MoveNode &firstMove, MoveNode &lastMove, const TTAMachine::RegisterFile &rf, int index, TCEString regName, BasicBlockNode &bbn, bool loopScheduling)
Definition BFRegCopy.cc:99
MoveNode & mn_
Definition BFRegCopy.hh:69
BoostGraph * rootGraph()
virtual Node & headNode(const Edge &edge) const
virtual EdgeSet outEdges(const Node &node) const
virtual Node & tailNode(const Edge &edge) const
virtual EdgeSet inEdges(const Node &node) const
static std::string toString(const T &source)
std::string toString() const
Definition MoveNode.cc:576
TTAProgram::Move & move()
bool runPostChild(Reversible *preChild)
void undoAndRemovePostChildren()
Definition Reversible.cc:89
virtual int size() const
virtual TCEString name() const
Port * firstReadPort() const
Port * firstWritePort() const
void setSource(Terminal *src)
Definition Move.cc:312
Terminal & destination() const
Definition Move.cc:323
void setDestination(Terminal *dst)
Definition Move.cc:333
virtual Terminal * copy() const =0