OpenASIP  2.0
BFPushDepsUp.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 BFPushDepsUp.cc
27  *
28  * Definition of BFPushDepsUp class
29  *
30  * Tries to reschedule the predecessors of a move into earlier cycle.
31  *
32  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
33  * @note rating: red
34  */
35 
36 #include "BFPushDepsUp.hh"
37 #include "DataDependenceGraph.hh"
38 #include "BFPushMoveUp.hh"
39 #include "BFPushMoveUp2.hh"
40 
42 
43  if (prefCycle_ < 0) {
44  std::cerr << "push deps up prefcycle negative! "
45  << prefCycle_ << " move: " << mn_.toString() << std::endl;
46  assert(false);
47  }
48 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
50  for (int i = 0; i < recurseCounter_*2; i++)
51  std::cerr << "\t";
52  std::cerr << "\tPushing loop deps up: " << mn_.toString() << std::endl;
53 #endif
54 
55  bool pushed = false;
57  for (auto e : inEdges) {
58  MoveNode& loopDepTail = ddg().tailNode(*e);
59  if (loopDepTail.isScheduled()) {
60  int eLat = ddg().edgeLatency(*e, ii(), &loopDepTail, &mn_);
61  int prefTailCycle = prefCycle_ - eLat;
62 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
63  std::cerr << "\t\t\tmy prefcycle is: " << prefCycle_
64  << " latency is: " << eLat
65  << " so preftailcycle is: " << prefTailCycle
66  << std::endl;
67  std::cerr << "\t\t\t\tedge: " <<e->toString() << std::endl;
68 #endif
69  if (loopDepTail.cycle() > prefTailCycle) {
70  if (prefTailCycle < 0) {
71 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
73 #endif
75  return false;
76  }
77  BFOptimization* pushMoveUp;
78  if (loopDepTail.isSourceOperation()) {
79  pushMoveUp =
80  new BFPushMoveUp2(sched_, loopDepTail, prefTailCycle);
81  } else {
82  pushMoveUp =
83  new BFPushMoveUp(sched_, loopDepTail, prefTailCycle);
84  }
85  if (runPreChild(pushMoveUp)) {
86 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
87  for (int i = 0; i < recurseCounter_*2; i++)
88  std::cerr << "\t";
89  std::cerr << "\tpushed up succesfully: "
90  << loopDepTail.toString()
91  << " preChildren size: "
92  << preChildren_.size() << std::endl;
93 #endif
94  pushed = true;
95  } else {
96 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
97  for (int i = 0; i < recurseCounter_*2; i++)
98  std::cerr << "\t";
99  std::cerr << "\t\tpushing up fail: "
100  << loopDepTail.toString()
101  << " preChildren size: "
102  << preChildren_.size() << std::endl;
103 #endif
105 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
106  recurseCounter_--;
107 #endif
108  return false;
109  }
110  }
111  }
112  }
113 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
114  recurseCounter_--;
115 #endif
116 
117  return pushed;
118 }
119 
Reversible::undoAndRemovePreChildren
void undoAndRemovePreChildren()
Definition: Reversible.cc:80
BoostGraph::tailNode
virtual Node & tailNode(const Edge &edge) const
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
DataDependenceGraph::edgeLatency
int edgeLatency(const DataDependenceEdge &edge, int ii, const MoveNode *tail, const MoveNode *head) const
Definition: DataDependenceGraph.cc:311
BFOptimization::ii
unsigned int ii() const
Definition: BFOptimization.cc:85
BFPushMoveUp2.hh
BFPushMoveUp.hh
DataDependenceGraph.hh
MoveNode
Definition: MoveNode.hh:65
BFOptimization
Definition: BFOptimization.hh:73
Reversible::preChildren_
std::stack< Reversible * > preChildren_
Definition: Reversible.hh:57
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
BFPushMoveUp
Definition: BFPushMoveUp.hh:48
assert
#define assert(condition)
Definition: Application.hh:86
BFPushDepsUp::operator()
bool operator()()
Definition: BFPushDepsUp.cc:41
MoveNode::cycle
int cycle() const
Definition: MoveNode.cc:421
BoostGraph< MoveNode, DataDependenceEdge >::EdgeSet
std::set< DataDependenceEdge *, typename DataDependenceEdge ::Comparator > EdgeSet
Definition: BoostGraph.hh:87
MoveNode::isSourceOperation
bool isSourceOperation() const
Definition: MoveNode.cc:168
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
BFPushDepsUp::prefCycle_
int prefCycle_
Definition: BFPushDepsUp.hh:53
BoostGraph::inEdges
virtual EdgeSet inEdges(const Node &node) const
BFPushDepsUp::mn_
MoveNode & mn_
Definition: BFPushDepsUp.hh:52
Reversible::runPreChild
bool runPreChild(Reversible *preChild)
Definition: Reversible.cc:127
BFPushMoveUp2
Definition: BFPushMoveUp2.hh:51
BFPushDepsUp.hh
MoveNode::isScheduled
bool isScheduled() const
Definition: MoveNode.cc:409
BFPushDepsUp::recurseCounter_
static int recurseCounter_
Definition: BFPushDepsUp.hh:45