OpenASIP 2.2
Loading...
Searching...
No Matches
BFLateBypass.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 BFLateBypass.cc
27 *
28 * Definition of BFLateBypass class
29 *
30 * Performs a bypass of noy-yet-scheduled result into already scheduled
31 * use of the value.
32 *
33 * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
34 * @note rating: red
35 */
36
37#include "BFLateBypass.hh"
38#include "BFScheduleBU.hh"
39#include "BFScheduleExact.hh"
40
43#include "MoveNode.hh"
44#include "Move.hh"
45
46#include "Bus.hh"
47#include "MoveNodeDuplicator.hh"
48#include "BFMergeAndKeepUser.hh"
49
50//#define DEBUG_BUBBLEFISH_SCHEDULER
51//#define DEBUG_LOOP_SCHEDULER
52
53#ifdef DEBUG_BUBBLEFISH_SCHEDULER
54#define DEBUG_LOOP_SCHEDULER
55#endif
56
57
58bool
60 // if already has guard operation, cannot have source operation.
61 if (dst_.isGuardOperation()) {
62 return false;
63 }
64
65#ifdef DEBUG_BUBBLEFISH_SCHEDULER
66 std::cerr << "\t\tPerforming late bypass: " << dst_.toString() <<std::endl;
67#else
68#ifdef DEBUG_LOOP_SCHEDULER
69 if (ii() != 0) {
70 std::cerr << "\t\tPerforming late bypass, dst: "
71 << dst_.toString() << std::endl;
72 }
73#endif
74#endif
77 MoveNode* prologMN = ii() ? duplicator().getMoveNode(dst_) : NULL;
78 if (prologMN != NULL) {
79 prologBus_ = &prologMN->move().bus();
80#ifdef DEBUG_BUBBLEFISH_SCHEDULER
81 std::cerr << "\t\t\t\tProlog move: " << prologMN->toString()
82 << std::endl;
83 std::cerr << "\t\t\t\tLate bypass saving prolog bus: "
84 << prologBus_->name() << std::endl;
85#endif
86 }
87
88 bool dstTriggering = dst_.move().isTriggering();
89 // this one did not create the prolog copy so do not remove it here.
90 unassign(dst_, false);
91
92 // Take the predecssors so that they can be notified because their
93 // antideps may change
94 // makes compiling too slow, disabled for now
96
99#ifdef DEBUG_BUBBLEFISH_SCHEDULER
100 std::cerr << "\t\t\tMerge and keep fail!" << std::endl;
101#endif
102 return false;
103 }
104
105 // TODO: this does too much optimizations?
106
107 BFOptimization* sched = NULL;
108 if ((dst_.move().isControlFlowMove() && dstTriggering) ||
109 (ii() != 0 &&
110 static_cast<DataDependenceGraph*>(ddg().rootGraph())->
111 writesJumpGuard(dst_))) {
112 if (lc_ < originalCycle_) {
113#ifdef DEBUG_BUBBLEFISH_SCHEDULER
114 std::cerr << "Late bypass fail: must use originalcycle "
115 "which is too late!!!" << std::endl;
116#endif
117 undo();
118 return false;
119 }
121 } else {
122 sched = new BFScheduleBU(sched_, dst_, lc_, false, false, false);
123 }
124 if ((*sched)()) {
125 // TODO: get this from bypass distance setting?
126 if (dst_.cycle() + 3 < originalCycle_) {
127#ifdef DEBUG_BUBBLEFISH_SCHEDULER
128 std::cerr << "\t\t\tToo long bypass dist, fail late bypass!"
129 << std::endl;
130#endif
131 sched->undo();
132 delete sched;
133 undo();
134 return false;
135 }
136
137 postChildren_.push(sched);
138#ifdef DEBUG_BUBBLEFISH_SCHEDULER
139 std::cerr << "\t\tLate bypass ok: " << dst_.toString() << std::endl;
140#endif
141
142 // now notify antideps sources
143 for (auto i : pred) {
144 mightBeReady(*i);
145 }
146
147 return true;
148 } else {
149#ifdef DEBUG_BUBBLEFISH_SCHEDULER
150 std::cerr << "\t\tLate bypass sched fail.: " << dst_.toString()
151 << std::endl;
152#endif
153 delete sched;
154 undo();
155 return false;
156 }
157}
158
159
160void
162#ifdef DEBUG_BUBBLEFISH_SCHEDULER
163 std::cerr << "\t\t\tUndoing late bypass: " << dst_.toString() << std::endl;
164#endif
165
166#ifdef DEBUG_BUBBLEFISH_SCHEDULER
167 std::cerr << "\t\t\tReassigning move: " << dst_.toString() <<" to cycle: "
168 << originalCycle_ << " bus: " << originalBus_->name() << std::endl;
169 if (!canAssign(
170 originalCycle_, dst_, originalBus_, NULL, NULL, prologBus_)) {
171 std::cerr << "assign to original cycle fail, cycle: "
172 << originalCycle_ << " movenode: "
173 << dst_.toString() << std::endl;
174 for (int unsigned i = 0; i < dst_.destinationOperationCount(); i++) {
175 std::cerr << "\tDestination op: "
176 << dst_.destinationOperation(i).toString() << std::endl;
177 }
178 ddg().writeToDotFile("late_bypass_undo_fail.dot");
179 assert(false);
180 }
181#endif
183#ifdef DEBUG_BUBBLEFISH_SCHEDULER
184 std::cerr << "\t\tReassigned move:" << dst_.toString() << std::endl;
185#endif
186}
#define assert(condition)
virtual void undoOnlyMe()
MoveNode & dst_
MoveNode & src_
const TTAMachine::Bus * originalBus_
virtual bool operator()()
const TTAMachine::Bus * prologBus_
virtual void mightBeReady(MoveNode &mn)
unsigned int ii() const
BF2Scheduler & sched_
virtual bool canAssign(int cycle, MoveNode &mn, const TTAMachine::Bus *bus=nullptr, const TTAMachine::FunctionUnit *srcFU=nullptr, const TTAMachine::FunctionUnit *dstFU=nullptr, const TTAMachine::Bus *prologBus=nullptr, int immWriteCycle=-1, int prologImmWriteCycle=-1, const TTAMachine::ImmediateUnit *immu=nullptr, int immRegIndex=-1, bool ignoreGWN=false)
DataDependenceGraph & ddg()
virtual void unassign(MoveNode &mn, bool disposePrologCopy=true)
MoveNodeDuplicator & duplicator() const
virtual bool assign(int cycle, MoveNode &, const TTAMachine::Bus *bus=nullptr, const TTAMachine::FunctionUnit *srcFU_=nullptr, const TTAMachine::FunctionUnit *dstFU=nullptr, const TTAMachine::Bus *prologBus=nullptr, int immWriteCycle=-1, int prologImmWriteCycle=-1, const TTAMachine::ImmediateUnit *immu=nullptr, int immRegIndex=-1, bool ignoreGuardWriteCycle=false)
virtual NodeSet predecessors(const Node &node, bool ignoreBackEdges=false, bool ignoreForwardEdges=false) const
virtual void writeToDotFile(const TCEString &fileName) const
std::set< GraphNode *, typename GraphNode::Comparator > NodeSet
Definition Graph.hh:53
MoveNode * getMoveNode(MoveNode &mn)
unsigned int destinationOperationCount() const
bool isGuardOperation() const
Definition MoveNode.cc:181
int cycle() const
Definition MoveNode.cc:421
std::string toString() const
Definition MoveNode.cc:576
TTAProgram::Move & move()
ProgramOperation & destinationOperation(unsigned int index=0) const
std::string toString() const
bool runPostChild(Reversible *preChild)
std::stack< Reversible * > postChildren_
Definition Reversible.hh:58
virtual void undo()
Definition Reversible.cc:69
virtual TCEString name() const
bool isControlFlowMove() const
Definition Move.cc:233
bool isTriggering() const
Definition Move.cc:284
const TTAMachine::Bus & bus() const
Definition Move.cc:373