OpenASIP 2.2
Loading...
Searching...
No Matches
BFRegCopy.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 BFRegCopy.cc
27 *
28 * Definition of BFRegCopy class
29 *
30 * Base class for creating a register-to-register copy.
31 *
32 * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
33 * @note rating: red
34 */
35
36#include "BFRegCopy.hh"
37#include "ProgramAnnotation.hh"
38#include "MoveNode.hh"
40#include "Move.hh"
41#include "MachinePart.hh"
42#include "BF2Scheduler.hh"
43#include "BasicBlockNode.hh"
44#include "BasicBlock.hh"
45#include "RegisterFile.hh"
46
47#include "BFConnectNodes.hh"
50
51bool
53
54 if (mn_.move().isReturn()) {
57 mn_.move().setAnnotation(annotation);
58 }
59
60 TTAProgram::ProgramAnnotation connMoveAnnotation(
62
63 auto copyMove = mn_.move().copy();
64 regCopy_ = new MoveNode(copyMove);
66 ddg().addNode(*regCopy_,bbn);
67 copyMove->addAnnotation(connMoveAnnotation);
68
69 if (splitMove(bbn)) {
70 return true;
71 }
72 else {
73#ifdef DEBUG_BUBBLEFISH_SCHEDULER
74 std::cerr << "Regcopy creation failing.." << std::endl;
75#endif
76 undoDDG();
77 return false;
78 }
79}
80
82 undoSplit();
83 undoDDG();
84}
85
87
89
90#ifdef DEBUG_BUBBLEFISH_SCHEDULER
91 std::cerr << "\t\tUndid merge for copy for: " << mn_.toString()
92 << " reg copy: " << regCopy_->toString() << std::endl;
93#endif
96 delete regCopy_;
97}
98
100 MoveNode& defMove,
101 MoveNode& useMove,
102 const TTAMachine::RegisterFile& rf,
103 int index,
104 TCEString regName,
105 BasicBlockNode& bbn,
106 bool loopScheduling) {
107
108 DataDependenceGraph::NodeSet firstScheduledDefs0 =
110
111 MoveNode* lastScheduledKill0 =
112 ddg().lastScheduledRegisterKill(rf, index);
113
114 for (auto i: firstScheduledDefs0) {
115 if (!ddg().exclusingGuards(*i, useMove)) {
116 DataDependenceEdge* war =
120 runPostChild(new BFConnectNodes(sched_, useMove, *i, war));
121 }
122 if (!ddg().exclusingGuards(*i, defMove)) {
123 DataDependenceEdge* waw =
127 runPostChild(new BFConnectNodes(sched_, defMove, *i, waw));
128 }
129 }
130
131 if (loopScheduling) {
132 DataDependenceGraph::NodeSet lastScheduledReads0 =
133 ddg().lastScheduledRegisterReads(rf, index);
134
135 for (auto i: lastScheduledReads0) {
136 if (!ddg().exclusingGuards(*i, defMove)) {
137 DataDependenceEdge* war =
141 false, false, false, false, 1);
142 runPostChild(new BFConnectNodes(sched_, *i, defMove, war));
143 }
144 }
145
146 DataDependenceGraph::NodeSet lastScheduledDefs0 =
147 ddg().lastScheduledRegisterWrites(rf, index);
148 for (auto i: lastScheduledDefs0) {
149 if (!ddg().exclusingGuards(*i, defMove)) {
150 DataDependenceEdge* waw =
154 false, false, false, false, 1);
155 runPostChild(new BFConnectNodes(sched_, *i, defMove, waw));
156 }
157 }
158 }
159 if (bbn.basicBlock().liveRangeData_ != NULL) {
160 if (lastScheduledKill0 == NULL) {
161 LiveRangeData::MoveNodeUseSet& lastWrites0 =
162 bbn.basicBlock().liveRangeData_->regDefines_[regName];
164 sched_, lastWrites0, MoveNodeUse(defMove)));
165
167 bbn.basicBlock().liveRangeData_->regLastUses_[regName];
169 sched_, lastReads0, MoveNodeUse(useMove)));
170 }
171
172 // last write, for WaW defs
175
176 if (useMove.move().isUnconditional()) {
179
180 runPostChild(new BFClearLiveRangeUse(sched_, firstReads));
181 runPostChild(new BFClearLiveRangeUse(sched_, firstDefs));
182 // TODO: what about updating the kill bookkeeping?
183 }
184
187 sched_, firstDefs, MoveNodeUse(defMove)));
188 }
189}
#define assert(condition)
void deletingNode(MoveNode *deletedNode)
BF2Scheduler & sched_
DataDependenceGraph & ddg()
MoveNode * regCopy_
Definition BFRegCopy.hh:70
virtual void undoSplit()=0
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
void undoOnlyMe()
Definition BFRegCopy.cc:81
bool operator()()
Definition BFRegCopy.cc:52
virtual bool splitMove(BasicBlockNode &bbn)=0
void undoDDG()
Definition BFRegCopy.cc:86
TTAProgram::BasicBlock & basicBlock()
NodeSet lastScheduledRegisterWrites(const TTAMachine::BaseRegisterFile &rf, int registerIndex) const
void addNode(MoveNode &moveNode)
bool exclusingGuards(const MoveNode &mn1, const MoveNode &mn2) const
NodeSet firstScheduledRegisterWrites(const TTAMachine::BaseRegisterFile &rf, int registerIndex) const
const BasicBlockNode & getBasicBlockNode(const MoveNode &mn) const
NodeSet lastScheduledRegisterReads(const TTAMachine::BaseRegisterFile &rf, int registerIndex) const
void removeNode(MoveNode &node)
MoveNode * lastScheduledRegisterKill(const TTAMachine::BaseRegisterFile &rf, int registerIndex) const
std::set< GraphNode *, typename GraphNode::Comparator > NodeSet
Definition Graph.hh:53
std::string toString() const
Definition MoveNode.cc:576
TTAProgram::Move & move()
bool isScheduled() const
Definition MoveNode.cc:409
bool runPostChild(Reversible *preChild)
void setAnnotation(const ProgramAnnotation &annotation)
LiveRangeData * liveRangeData_
bool isReturn() const
Definition Move.cc:259
bool isUnconditional() const
Definition Move.cc:154
std::shared_ptr< Move > copy() const
Definition Move.cc:413
@ ANN_STACKFRAME_PROCEDURE_RETURN
precedure return jmp
@ ANN_CONNECTIVITY_MOVE
A reg to reg move that was added because of missing connectivity between the original target and dest...
MoveNodeUseMapSet regFirstUses_
MoveNodeUseMapSet regLastUses_
std::set< MoveNodeUse > MoveNodeUseSet
MoveNodeUseMapSet regFirstDefines_
MoveNodeUseMapSet regDefines_