OpenASIP  2.0
BFRegCopyBefore.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 BFRegCopyBefore.cc
27  *
28  * Definition of BFRegCopyBefore class
29  *
30  * Creates a register-to-register copy before a move, modifying the source
31  * of the original move into the temporaty register and making the source
32  * of the temp move the original souce register.
33  *
34  * Used for temp-reg-copies of operand moves.
35  *
36  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
37  * @note rating: red
38  */
39 
40 #include "BFRegCopyBefore.hh"
41 #include "RegisterFile.hh"
42 #include "TerminalRegister.hh"
43 #include "BF2Scheduler.hh"
44 #include "MoveNode.hh"
45 #include "Move.hh"
46 #include "BFRemoveEdge.hh"
47 #include "BFConnectNodes.hh"
48 
49 
50 bool
52 
53  std::set<const TTAMachine::RegisterFile*,
56 
57  // cannot create reg copy if no temp regs available.
58  if (rfs.empty()) {
59  return false;
60  }
61 
62  const TTAMachine::RegisterFile& rf = **rfs.rbegin();
63 
64  int lastRegisterIndex = rf.size()-1;
65  TTAMachine::Port* dstRFPort = rf.firstWritePort();
66  TTAMachine::Port* srcRFPort = rf.firstReadPort();
67 
68  TTAProgram::TerminalRegister* tempWrite =
69  new TTAProgram::TerminalRegister(*dstRFPort, lastRegisterIndex);
70 
72  new TTAProgram::TerminalRegister(*srcRFPort, lastRegisterIndex);
73 
74  regCopy_->move().setDestination(tempWrite);
75  mn_.move().setSource(tempRead);
76 
77  auto iEdges = ddg().rootGraph()->inEdges(mn_);
78  for (auto iEdge : iEdges) {
79  if (!iEdge->isRegisterOrRA() || iEdge->headPseudo()) {
80  continue;
81  }
82 
83  //copy guard use edge to the regcopy.
84  if (iEdge->guardUse() &&
85  iEdge->dependenceType() == DataDependenceEdge::DEP_RAW) {
86  MoveNode& tail = ddg().rootGraph()->tailNode(*iEdge);
88  new BFConnectNodes(sched_, tail, *regCopy_, iEdge, true));
89  } else if (iEdge->isRAW()) {
90  MoveNode& tail = ddg().rootGraph()->tailNode(*iEdge);
91  runPostChild(new BFRemoveEdge(sched_, tail, mn_, *iEdge));
92  runPostChild(new BFConnectNodes(sched_, tail, *regCopy_, iEdge));
93  }
94  }
95 
96  auto oEdges = ddg().rootGraph()->outEdges(mn_);
97  for (auto oEdge : oEdges) {
98  if (!oEdge->isRegisterOrRA() || oEdge->tailPseudo()) {
99  continue;
100  }
101  if (oEdge->dependenceType() == DataDependenceEdge::DEP_WAR &&
102  !oEdge->guardUse()) {
103  MoveNode& head = ddg().rootGraph()->headNode(*oEdge);
104  runPostChild(new BFRemoveEdge(sched_, mn_, head, *oEdge));
105  runPostChild(new BFConnectNodes(sched_, *regCopy_, head, oEdge));
106  }
107  }
108 
109  TCEString tempRegName = rf.name() + '.' +
110  Conversion::toString(lastRegisterIndex);
111 
112  DataDependenceEdge* newEdge =
113  new DataDependenceEdge(
115  DataDependenceEdge::DEP_RAW, tempRegName);
116 
117  runPostChild(new BFConnectNodes(sched_, *regCopy_, mn_, newEdge));
118 
120  *regCopy_, mn_, rf, lastRegisterIndex,
121  tempRegName, bbn, ii()!= 0);
122 
123  return true;
124 }
125 
128 }
TTAMachine::RegisterFile::firstReadPort
Port * firstReadPort() const
Definition: RegisterFile.cc:607
BFRegCopy::createAntidepsForReg
void createAntidepsForReg(MoveNode &firstMove, MoveNode &lastMove, const TTAMachine::RegisterFile &rf, int index, TCEString regName, BasicBlockNode &bbn, bool loopScheduling)
Definition: BFRegCopy.cc:99
BoostGraph::tailNode
virtual Node & tailNode(const Edge &edge) const
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
BoostGraph::headNode
virtual Node & headNode(const Edge &edge) const
BF2Scheduler::possibleTempRegRFs
std::set< const TTAMachine::RegisterFile *, TTAMachine::MachinePart::Comparator > possibleTempRegRFs(const MoveNode &mn, bool tempRegAfter, const TTAMachine::RegisterFile *forbiddenRF=nullptr)
Definition: BF2Scheduler.cc:899
BFRegCopyBefore::forbiddenRF_
const TTAMachine::RegisterFile * forbiddenRF_
Definition: BFRegCopyBefore.hh:53
BFOptimization::ii
unsigned int ii() const
Definition: BFOptimization.cc:85
MoveNode
Definition: MoveNode.hh:65
DataDependenceEdge::EDGE_REGISTER
@ EDGE_REGISTER
Definition: DataDependenceEdge.hh:53
Conversion::toString
static std::string toString(const T &source)
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
BFConnectNodes
Definition: BFConnectNodes.hh:38
TerminalRegister.hh
BFRemoveEdge.hh
BFRegCopyBefore::splitMove
bool splitMove(BasicBlockNode &bbn)
Definition: BFRegCopyBefore.cc:51
TTAProgram::Move::setDestination
void setDestination(Terminal *dst)
Definition: Move.cc:333
BFRemoveEdge
Definition: BFRemoveEdge.hh:40
TTAMachine::RegisterFile::firstWritePort
Port * firstWritePort() const
Definition: RegisterFile.cc:618
BF2Scheduler.hh
BoostGraph::rootGraph
BoostGraph * rootGraph()
DataDependenceEdge::DEP_RAW
@ DEP_RAW
Definition: DataDependenceEdge.hh:47
BFRegCopyBefore.hh
TTAMachine::Port
Definition: Port.hh:54
BFRegCopyBefore::undoSplit
void undoSplit()
Definition: BFRegCopyBefore.cc:126
BasicBlockNode
Definition: BasicBlockNode.hh:64
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
BFRegCopy::regCopy_
MoveNode * regCopy_
Definition: BFRegCopy.hh:70
BoostGraph::inEdges
virtual EdgeSet inEdges(const Node &node) const
BoostGraph::outEdges
virtual EdgeSet outEdges(const Node &node) const
MoveNode::move
TTAProgram::Move & move()
BFRegCopy::mn_
MoveNode & mn_
Definition: BFRegCopy.hh:69
RegisterFile.hh
TCEString
Definition: TCEString.hh:53
TTAProgram::Terminal::copy
virtual Terminal * copy() const =0
DataDependenceEdge
Definition: DataDependenceEdge.hh:43
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
BFConnectNodes.hh
Move.hh
TTAMachine::BaseRegisterFile::size
virtual int size() const
DataDependenceEdge::DEP_WAR
@ DEP_WAR
Definition: DataDependenceEdge.hh:48
MoveNode.hh
TTAMachine::MachinePart::Comparator
Definition: MachinePart.hh:59
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
TTAProgram::TerminalRegister
Definition: TerminalRegister.hh:53
TTAProgram::Move::setSource
void setSource(Terminal *src)
Definition: Move.cc:312