OpenASIP  2.0
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"
39 #include "DataDependenceGraph.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"
48 #include "BFInsertLiveRangeUse.hh"
49 #include "BFClearLiveRangeUse.hh"
50 
51 bool
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 =
109  ddg().firstScheduledRegisterWrites(rf, index);
110 
111  MoveNode* lastScheduledKill0 =
112  ddg().lastScheduledRegisterKill(rf, index);
113 
114  for (auto i: firstScheduledDefs0) {
115  if (!ddg().exclusingGuards(*i, useMove)) {
116  DataDependenceEdge* war =
117  new DataDependenceEdge(
119  DataDependenceEdge::DEP_WAR, regName);
120  runPostChild(new BFConnectNodes(sched_, useMove, *i, war));
121  }
122  if (!ddg().exclusingGuards(*i, defMove)) {
123  DataDependenceEdge* waw =
124  new DataDependenceEdge(
126  DataDependenceEdge::DEP_WAW, regName);
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 =
138  new DataDependenceEdge(
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 =
151  new DataDependenceEdge(
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 
166  LiveRangeData::MoveNodeUseSet& lastReads0 =
167  bbn.basicBlock().liveRangeData_->regLastUses_[regName];
169  sched_, lastReads0, MoveNodeUse(useMove)));
170  }
171 
172  // last write, for WaW defs
173  LiveRangeData::MoveNodeUseSet& firstDefs =
175 
176  if (useMove.move().isUnconditional()) {
177  LiveRangeData::MoveNodeUseSet& firstReads =
178  bbn.basicBlock().liveRangeData_->regFirstUses_[regName];
179 
180  runPostChild(new BFClearLiveRangeUse(sched_, firstReads));
181  runPostChild(new BFClearLiveRangeUse(sched_, firstDefs));
182  // TODO: what about updating the kill bookkeeping?
183  }
184 
185  runPostChild(
187  sched_, firstDefs, MoveNodeUse(defMove)));
188  }
189 }
TTAProgram::Move::copy
std::shared_ptr< Move > copy() const
Definition: Move.cc:413
BF2Scheduler::deletingNode
void deletingNode(MoveNode *deletedNode)
Definition: BF2Scheduler.cc:1633
DataDependenceGraph::lastScheduledRegisterWrites
NodeSet lastScheduledRegisterWrites(const TTAMachine::BaseRegisterFile &rf, int registerIndex) const
Definition: DataDependenceGraph.cc:1206
BFRegCopy::createAntidepsForReg
void createAntidepsForReg(MoveNode &firstMove, MoveNode &lastMove, const TTAMachine::RegisterFile &rf, int index, TCEString regName, BasicBlockNode &bbn, bool loopScheduling)
Definition: BFRegCopy.cc:99
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
LiveRangeData::MoveNodeUseSet
std::set< MoveNodeUse > MoveNodeUseSet
Definition: LiveRangeData.hh:51
TTAProgram::Move::isReturn
bool isReturn() const
Definition: Move.cc:259
BoostGraph< MoveNode, DataDependenceEdge >::NodeSet
std::set< MoveNode *, typename MoveNode ::Comparator > NodeSet
Definition: BoostGraph.hh:86
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
MoveNodeUse
Definition: MoveNodeUse.hh:20
TTAProgram::AnnotatedInstructionElement::setAnnotation
void setAnnotation(const ProgramAnnotation &annotation)
Definition: AnnotatedInstructionElement.cc:79
BasicBlockNode.hh
LiveRangeData::regDefines_
MoveNodeUseMapSet regDefines_
Definition: LiveRangeData.hh:78
DataDependenceGraph.hh
MoveNode
Definition: MoveNode.hh:65
DataDependenceEdge::EDGE_REGISTER
@ EDGE_REGISTER
Definition: DataDependenceEdge.hh:53
MachinePart.hh
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
DataDependenceGraph::lastScheduledRegisterKill
MoveNode * lastScheduledRegisterKill(const TTAMachine::BaseRegisterFile &rf, int registerIndex) const
Definition: DataDependenceGraph.cc:1285
BFConnectNodes
Definition: BFConnectNodes.hh:38
BasicBlockNode::basicBlock
TTAProgram::BasicBlock & basicBlock()
Definition: BasicBlockNode.cc:126
assert
#define assert(condition)
Definition: Application.hh:86
BFRegCopy::undoOnlyMe
void undoOnlyMe()
Definition: BFRegCopy.cc:81
BF2Scheduler.hh
TTAProgram::BasicBlock::liveRangeData_
LiveRangeData * liveRangeData_
Definition: BasicBlock.hh:111
BFClearLiveRangeUse.hh
LiveRangeData::regFirstDefines_
MoveNodeUseMapSet regFirstDefines_
Definition: LiveRangeData.hh:87
DataDependenceGraph::removeNode
void removeNode(MoveNode &node)
Definition: DataDependenceGraph.cc:2843
BasicBlockNode
Definition: BasicBlockNode.hh:64
LiveRangeData::regLastUses_
MoveNodeUseMapSet regLastUses_
Definition: LiveRangeData.hh:79
BFRegCopy::undoDDG
void undoDDG()
Definition: BFRegCopy.cc:86
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
BFRegCopy::regCopy_
MoveNode * regCopy_
Definition: BFRegCopy.hh:70
BFRegCopy::undoSplit
virtual void undoSplit()=0
DataDependenceEdge::DEP_WAW
@ DEP_WAW
Definition: DataDependenceEdge.hh:49
BFInsertLiveRangeUse.hh
BFClearLiveRangeUse
Definition: BFClearLiveRangeUse.hh:39
DataDependenceGraph::addNode
void addNode(MoveNode &moveNode)
Definition: DataDependenceGraph.cc:144
MoveNode::move
TTAProgram::Move & move()
TTAProgram::ProgramAnnotation::ANN_STACKFRAME_PROCEDURE_RETURN
@ ANN_STACKFRAME_PROCEDURE_RETURN
precedure return jmp
Definition: ProgramAnnotation.hh:76
BFRegCopy::mn_
MoveNode & mn_
Definition: BFRegCopy.hh:69
RegisterFile.hh
TCEString
Definition: TCEString.hh:53
BasicBlock.hh
BFInsertLiveRangeUse
Definition: BFInsertLiveRangeUse.hh:39
DataDependenceGraph::firstScheduledRegisterWrites
NodeSet firstScheduledRegisterWrites(const TTAMachine::BaseRegisterFile &rf, int registerIndex) const
Definition: DataDependenceGraph.cc:1245
DataDependenceEdge
Definition: DataDependenceEdge.hh:43
MoveNode::isScheduled
bool isScheduled() const
Definition: MoveNode.cc:409
TTAProgram::ProgramAnnotation::ANN_CONNECTIVITY_MOVE
@ ANN_CONNECTIVITY_MOVE
A reg to reg move that was added because of missing connectivity between the original target and dest...
Definition: ProgramAnnotation.hh:123
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
BFRegCopy::splitMove
virtual bool splitMove(BasicBlockNode &bbn)=0
BFConnectNodes.hh
TTAProgram::ProgramAnnotation
Definition: ProgramAnnotation.hh:49
Move.hh
DataDependenceEdge::DEP_WAR
@ DEP_WAR
Definition: DataDependenceEdge.hh:48
MoveNode.hh
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
BFRegCopy::operator()
bool operator()()
Definition: BFRegCopy.cc:52
DataDependenceGraph::lastScheduledRegisterReads
NodeSet lastScheduledRegisterReads(const TTAMachine::BaseRegisterFile &rf, int registerIndex) const
Definition: DataDependenceGraph.cc:1080
ProgramAnnotation.hh
BFRegCopy.hh
DataDependenceGraph::getBasicBlockNode
const BasicBlockNode & getBasicBlockNode(const MoveNode &mn) const
Definition: DataDependenceGraph.cc:186
LiveRangeData::regFirstUses_
MoveNodeUseMapSet regFirstUses_
Definition: LiveRangeData.hh:86