OpenASIP 2.2
Loading...
Searching...
No Matches
BFPostpassBypass.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 BFPostpassBypass.cc
27 *
28 * Definition of BFPostpassBypass class
29 *
30 * Performs a bypass after scheduling everything.
31 * May also bypass over a loop edge.
32 *
33 * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
34 * @note rating: red
35 */
36
38#include "BFPostpassBypass.hh"
39#include "BFUnscheduleMove.hh"
40#include "BFScheduleExact.hh"
41#include "Move.hh"
42#include "BFScheduleBU.hh"
43#include "Terminal.hh"
44#include "BFPostpassDRE.hh"
46#include "BFAssignToBody.hh"
47#include "BFPostpassLoopDRE.hh"
48#include "MoveNodeDuplicator.hh"
49#include "BFMergeAndKeepUser.hh"
50
52
53
56#ifdef DEBUG_BUBBLEFISH_SCHEDULER
57 static int counter = 0;
58 static int counter2 = 0;
59#endif
60
61 int originalCycle = dst_.cycle();
62 int srcCycle = src_.cycle();
63
64 if (loopBypass_ && originalCycle >= (int)ii()) {
65#ifdef DEBUG_BUBBLEFISH_SCHEDULER
66 std::cerr << "too late cycle for loop bypass" << std::endl;
67#endif
68 return false;
69 }
70
72 &src_.move().source().functionUnit() : nullptr;
73
75 &dst_.move().destination().functionUnit() : nullptr;
76
77 if (!loopBypass_) {
79 } else {
81 }
83
84 if (!runPreChild(
86#ifdef DEBUG_BUBBLEFISH_SCHEDULER
87 std::cerr << "merge and keep fail." << src_.toString()
88 << " and " << dst_.toString() << std::endl;
89#endif
91 return false;
92 }
93
95
96#ifdef DEBUG_BUBBLEFISH_SCHEDULER
97 std::cerr << "\t\t\tTried ordinary dre: " << dred_ << std::endl;
98#endif
99 if (loopBypass_ && !dred_) {
100#ifdef DEBUG_BUBBLEFISH_SCHEDULER
101 std::cerr << "\t\t\tsrccycle: " << srcCycle << std::endl;
102#endif
103 if (srcCycle >= (int)ii()) {
105 new BFPostpassLoopDRE(sched_, src_, srcCycle));
106 } else {
107 if (ddg().latestCycle(src_) >= (signed)ii()) {
110 }
111 }
112 }
113
114 // TODO: try to DRE here
115
116 if (!dred_) {
117 // if returning the old fails, abort everything
118#ifdef DEBUG_BUBBLEFISH_SCHEDULER
119 std::cerr << "\t\t\tundoing unscheduling of src" << std::endl;
120#endif
121 // if not dre, return the result
122 if (!runPostChild(
123 new BFScheduleExact(sched_, src_, srcCycle, false, ssfu))) {
124#ifdef DEBUG_BUBBLEFISH_SCHEDULER
125 std::cerr << "Scheduling back src:" << src_.toString()
126 << " to cycle: " << srcCycle
127 << " after post-pass bypass move failed" << std::endl;
128 ddg().writeToDotFile("postpass_fail1.dot");
129#endif
130 undo();
131 return false;
132 }
133
134#ifdef DEBUG_BUBBLEFISH_SCHEDULER
135 std::cerr << "\t\t\tundid unscheduling of src" << std::endl;
136#endif
137 }
138
139 BFOptimization* schedDst = NULL;
140 if (dst_.move().isControlFlowMove() ||
141 (ii() != 0 &&
142 static_cast<DataDependenceGraph*>(ddg().rootGraph())->
143 writesJumpGuard(dst_))) {
144 if (!loopBypass_) {
145 schedDst = new BFScheduleExact(
146 sched_, dst_, originalCycle, false);
147 } else {
148 schedDst = new BFAssignToBody(
149 sched_, dst_, originalCycle, ssfu, ddfu);
150 }
151 } else {
152 if (!loopBypass_) {
153 schedDst = new BFScheduleExact(
154 sched_, dst_, originalCycle, false);
155 } else {
156 schedDst = new BFAssignToBody(
157 sched_, dst_, originalCycle, ssfu, ddfu);
158 }
159 }
160
161 if (!runPostChild(schedDst)) {
162#ifdef DEBUG_BUBBLEFISH_SCHEDULER
163 std::cerr << "\t\tScheduling post-pass bypassed move failed:"
164 << dst_.toString() << "cycle: " << originalCycle
165 << std::endl;
166 ddg().writeToDotFile("postpass_fail2.dot");
167#endif
168 undo();
169 return false;
170 }
171 return true;
172}
173
175
176#ifdef DEBUG_BUBBLEFISH_SCHEDULER
177 std::cerr << "isloopbypass?" << loopBypass_ << std::endl;
178 std::cerr << "\t\t\tPerforming unmerge user of: "
179 << src_.toString() << " and: " << dst_.toString()
180 << std::endl;
181#endif
182#ifdef DEBUG_BUBBLEFISH_SCHEDULER
183 std::cerr << "\t\t\tPerformed unmerge user of: "
184 << src_.toString() << " and: " << dst_.toString()
185 << std::endl;
186#endif
187}
#define assert(condition)
unsigned int ii() const
BF2Scheduler & sched_
DataDependenceGraph & ddg()
bool operator()() override
void undoOnlyMe() override
virtual void writeToDotFile(const TCEString &fileName) const
int cycle() const
Definition MoveNode.cc:421
bool isDestinationOperation() const
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
bool runPostChild(Reversible *preChild)
virtual void undo()
Definition Reversible.cc:69
void undoAndRemovePreChildren()
Definition Reversible.cc:80
bool runPreChild(Reversible *preChild)
bool isControlFlowMove() const
Definition Move.cc:233
Terminal & source() const
Definition Move.cc:302
Terminal & destination() const
Definition Move.cc:323
virtual const TTAMachine::FunctionUnit & functionUnit() const
Definition Terminal.cc:251