OpenASIP  2.0
BFPushMoveUp2.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 BFPushMoveUp2.cc
27  *
28  * Definition of BFPushMoveUp2 class
29  *
30  * Tries to (recursively) reschedule move (and it's predecessors)
31  * into earlier cycle.
32  *
33  * This version may unschedule whole operations and put them above some other
34  * operations int he same FU.
35  *
36  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
37  * @note rating: red
38  */
39 
40 #include "BFPushMoveUp2.hh"
41 #include "DataDependenceGraph.hh"
42 #include "BFPushDepsUp.hh"
43 #include "Move.hh"
44 #include "BF2Scheduler.hh"
45 #include "BFScheduleBU.hh"
46 
47 bool
49 
50  if (lc_ == -1) {
51  std::cerr << "incoming lc -1 on pushmoveup!" << std::endl;
52  assert(false);
53  }
54  if (mn_.move().isControlFlowMove()) {
55 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
56  std::cerr << "\t\t|TCannot reschedule control flow move!" << std::endl;
57 #endif
58  return false;
59  }
60 
61  if (&mn_ == sched_.guardWriteNode()) {
62 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
63  std::cerr << "\t\t|TCannot reschedule guard write move!" << std::endl;
64 #endif
65  return false;
66  }
67 
68  if (!mn_.isSourceOperation()) {
69  return false;
70  }
71 
72  // unschedule this (result) move
74  MoveNode* trigger = po.triggeringMove();
76 
77  int ddgLC = ddg().latestCycle(mn_,ii());
78  int ddgEC = ddg().earliestCycle(mn_,ii());
79 
80  if (ddgLC == -1) {
81 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
82  std::cerr << "ddg latest cycle -1 in pushmoveup2 of:"
83  << mn_.toString() << std::endl;
84 #endif
86  return false;
87  }
88 
89  int lc = std::min(lc_, ddgLC);
90 
91  if (ddgEC > lc) {
92  DataDependenceGraph::NodeSet unschedOperands;
93  DataDependenceGraph::NodeSet unschedResults;
94  // undo the inputs
95  for (int i = 0; i < po.inputMoveCount(); i++) {
96  MoveNode& operand = po.inputMove(i);
97  if (operand.isScheduled()) {
98  if (!runPostChild(new BFUnscheduleMove(sched_, operand))) {
99  undo();
100  return false;
101  } else {
102  unschedOperands.insert(&operand);
103  }
104  }
105  }
106 
107  for (int i = 0; i < po.outputMoveCount(); i++) {
108  MoveNode& res = po.outputMove(i);
109  if (res.isScheduled() &&
110  (res.cycle() > lc ||
111  (isLoopBypass(res) && res.cycle()+((signed)ii()) > lc))) {
112  if (!runPostChild(new BFUnscheduleMove(sched_, res))) {
113  undo();
114  return false;
115  } else {
116  unschedResults.insert(&res);
117  }
118 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
119  } else {
120  std::cerr << "res which is not scheduled:" << res.toString()
121  << std::endl;
122 #endif
123  }
124  }
125 
126  // now whole op is not scheduled?
127 
128  // reschedule other results
129  for (int i = po.outputMoveCount()-1; i >= 0; i--) {
130  MoveNode& res = po.outputMove(i);
131  if (AssocTools::containsKey(unschedResults, &res)) {
132  int myLC = lc - isLoopBypass(res) * ii();
133  if (!runPostChild(
134  new BFScheduleBU(
135  sched_, res, myLC, false, false, false))) {
136  undo();
137  return false;
138  }
139  }
140  }
141 
142  // reschedule me.
143  if (!runPostChild(
144  new BFScheduleBU(sched_, mn_, lc, false, false, false))) {
145  undo();
146  return false;
147  }
148 
149  // reschdule trigger
150  if (AssocTools::containsKey(unschedOperands, trigger)) {
151  if (!runPostChild(
152  new BFScheduleBU(
153  sched_, *trigger, lc, false, false, false))) {
154  undo();
155  return false;
156  }
157  }
158 
159  // reschedule other operands
160  for (int i = 0; i < po.inputMoveCount(); i++) {
161  MoveNode& operand = po.inputMove(i);
162  if (&operand != trigger) {
163  if (AssocTools::containsKey(unschedOperands, &operand)) {
164  if (!runPostChild(
165  new BFScheduleBU(
166  sched_, operand, lc, false, false, false))) {
167  undo();
168  return false;
169  }
170  }
171  }
172  }
173  } else {
174  undo();
175  return false;
176  }
178  return true;
179 }
180 
182  auto inEdges = ddg().operationInEdges(mn);
183  for (auto e: inEdges) {
184  if (e->isBackEdge()) {
185  return true;
186  }
187  }
188 
189  return false;
190 }
BFPushMoveUp2::lc_
int lc_
Definition: BFPushMoveUp2.hh:62
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
BFOptimization::ii
unsigned int ii() const
Definition: BFOptimization.cc:85
AssocTools::containsKey
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
BoostGraph< MoveNode, DataDependenceEdge >::NodeSet
std::set< MoveNode *, typename MoveNode ::Comparator > NodeSet
Definition: BoostGraph.hh:86
BFUnscheduleMove::returnOriginal
void returnOriginal()
Definition: BFUnscheduleMove.cc:107
BFPushMoveUp2::operator()
bool operator()()
Definition: BFPushMoveUp2.cc:48
BFPushMoveUp2.hh
DataDependenceGraph.hh
ProgramOperation
Definition: ProgramOperation.hh:70
MoveNode
Definition: MoveNode.hh:65
ProgramOperation::triggeringMove
MoveNode * triggeringMove() const
Definition: ProgramOperation.cc:643
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
BFUnscheduleMove::mn_
MoveNode & mn_
Definition: BFUnscheduleMove.hh:61
MoveNode::sourceOperation
ProgramOperation & sourceOperation() const
Definition: MoveNode.cc:453
assert
#define assert(condition)
Definition: Application.hh:86
DataDependenceGraph::operationInEdges
EdgeSet operationInEdges(const MoveNode &node) const
Definition: DataDependenceGraph.cc:5913
MoveNode::cycle
int cycle() const
Definition: MoveNode.cc:421
BFScheduleBU
Definition: BFScheduleBU.hh:45
BF2Scheduler.hh
TTAProgram::Move::isControlFlowMove
bool isControlFlowMove() const
Definition: Move.cc:233
BFScheduleBU.hh
Reversible::undo
virtual void undo()
Definition: Reversible.cc:69
MoveNode::isSourceOperation
bool isSourceOperation() const
Definition: MoveNode.cc:168
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
ProgramOperation::inputMoveCount
int inputMoveCount() const
Definition: ProgramOperation.cc:600
BFUnscheduleMove::BFUnscheduleMove
BFUnscheduleMove(BF2Scheduler &sched, MoveNode &mn)
Definition: BFUnscheduleMove.hh:51
ProgramOperation::outputMoveCount
int outputMoveCount() const
Definition: ProgramOperation.cc:610
BFPushMoveUp2::isLoopBypass
bool isLoopBypass(MoveNode &mn)
Definition: BFPushMoveUp2.cc:181
DataDependenceGraph::earliestCycle
int earliestCycle(const MoveNode &moveNode, unsigned int ii=UINT_MAX, bool ignoreRegWaRs=false, bool ignoreRegWaWs=false, bool ignoreGuards=false, bool ignoreFUDeps=false, bool ignoreSameOperationEdges=false, bool assumeBypassing=false) const
Definition: DataDependenceGraph.cc:388
BFUnscheduleMove::unscheduleOriginal
void unscheduleOriginal()
Definition: BFUnscheduleMove.cc:47
MoveNode::move
TTAProgram::Move & move()
BFPushDepsUp.hh
MoveNode::isScheduled
bool isScheduled() const
Definition: MoveNode.cc:409
BF2Scheduler::guardWriteNode
MoveNode * guardWriteNode()
Definition: BF2Scheduler.hh:191
Move.hh
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
ProgramOperation::outputMove
MoveNode & outputMove(int index) const
Definition: ProgramOperation.cc:632
ProgramOperation::inputMove
MoveNode & inputMove(int index) const
Definition: ProgramOperation.cc:621
DataDependenceGraph::latestCycle
int latestCycle(const MoveNode &moveNode, unsigned int ii=UINT_MAX, bool ignoreRegAntideps=false, bool ignoreUnscheduledSuccessors=true, bool ignoreGuards=false, bool ignoreFUDeps=false, bool ignoreSameOperationEdges=false) const
Definition: DataDependenceGraph.cc:543