OpenASIP 2.2
Loading...
Searching...
No Matches
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"
42#include "BFPushDepsUp.hh"
43#include "Move.hh"
44#include "BF2Scheduler.hh"
45#include "BFScheduleBU.hh"
46
47bool
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}
#define assert(condition)
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
MoveNode * guardWriteNode()
unsigned int ii() const
BF2Scheduler & sched_
DataDependenceGraph & ddg()
bool isLoopBypass(MoveNode &mn)
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
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
EdgeSet operationInEdges(const MoveNode &node) const
std::set< GraphNode *, typename GraphNode::Comparator > NodeSet
Definition Graph.hh:53
int cycle() const
Definition MoveNode.cc:421
ProgramOperation & sourceOperation() const
Definition MoveNode.cc:453
std::string toString() const
Definition MoveNode.cc:576
TTAProgram::Move & move()
bool isSourceOperation() const
Definition MoveNode.cc:168
bool isScheduled() const
Definition MoveNode.cc:409
int outputMoveCount() const
int inputMoveCount() const
MoveNode * triggeringMove() const
MoveNode & inputMove(int index) const
MoveNode & outputMove(int index) const
bool runPostChild(Reversible *preChild)
virtual void undo()
Definition Reversible.cc:69
bool isControlFlowMove() const
Definition Move.cc:233