OpenASIP  2.0
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 
41 #include "SimpleResourceManager.hh"
42 #include "DataDependenceGraph.hh"
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 
58 bool
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
76  originalBus_ = &dst_.move().bus();
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  }
120  sched = new BFScheduleExact(sched_, dst_, originalCycle_);
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 
160 void
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 }
BFMergeAndKeepUser.hh
Reversible::postChildren_
std::stack< Reversible * > postChildren_
Definition: Reversible.hh:58
BoostGraph::predecessors
virtual NodeSet predecessors(const Node &node, bool ignoreBackEdges=false, bool ignoreForwardEdges=false) const
BFLateBypass.hh
BFOptimization::unassign
virtual void unassign(MoveNode &mn, bool disposePrologCopy=true)
Definition: BFOptimization.cc:196
BFLateBypass::lc_
int lc_
Definition: BFLateBypass.hh:59
TTAProgram::Move::isTriggering
bool isTriggering() const
Definition: Move.cc:284
BFOptimization::assign
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)
Definition: BFOptimization.cc:103
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
BFOptimization::duplicator
MoveNodeDuplicator & duplicator() const
Definition: BFOptimization.cc:87
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
BFOptimization::ii
unsigned int ii() const
Definition: BFOptimization.cc:85
BoostGraph< MoveNode, DataDependenceEdge >::NodeSet
std::set< MoveNode *, typename MoveNode ::Comparator > NodeSet
Definition: BoostGraph.hh:86
TTAProgram::Move::bus
const TTAMachine::Bus & bus() const
Definition: Move.cc:373
DataDependenceGraph.hh
MoveNode
Definition: MoveNode.hh:65
BFOptimization
Definition: BFOptimization.hh:73
BFLateBypass::dst_
MoveNode & dst_
Definition: BFLateBypass.hh:58
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
assert
#define assert(condition)
Definition: Application.hh:86
BFLateBypass::prologBus_
const TTAMachine::Bus * prologBus_
Definition: BFLateBypass.hh:61
MoveNode::isGuardOperation
bool isGuardOperation() const
Definition: MoveNode.cc:181
MoveNode::cycle
int cycle() const
Definition: MoveNode.cc:421
BFScheduleBU
Definition: BFScheduleBU.hh:45
TTAProgram::Move::isControlFlowMove
bool isControlFlowMove() const
Definition: Move.cc:233
BFScheduleBU.hh
Reversible::undo
virtual void undo()
Definition: Reversible.cc:69
BFLateBypass::operator()
virtual bool operator()()
Definition: BFLateBypass.cc:59
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
Bus.hh
MoveNode::destinationOperationCount
unsigned int destinationOperationCount() const
MoveNodeDuplicator.hh
GraphBase::writeToDotFile
virtual void writeToDotFile(const TCEString &fileName) const
MoveNodeDuplicator::getMoveNode
MoveNode * getMoveNode(MoveNode &mn)
Definition: MoveNodeDuplicator.cc:85
MoveNode::destinationOperation
ProgramOperation & destinationOperation(unsigned int index=0) const
MoveNode::move
TTAProgram::Move & move()
ProgramOperation::toString
std::string toString() const
Definition: ProgramOperation.cc:746
BFLateBypass::originalCycle_
int originalCycle_
Definition: BFLateBypass.hh:56
BFScheduleExact
Definition: BFScheduleExact.hh:47
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
BFScheduleExact.hh
SimpleResourceManager.hh
BFLateBypass::src_
MoveNode & src_
Definition: BFLateBypass.hh:57
BFLateBypass::undoOnlyMe
virtual void undoOnlyMe()
Definition: BFLateBypass.cc:161
Move.hh
MoveNode.hh
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
BFOptimization::canAssign
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)
Definition: BFOptimization.cc:495
BFOptimization::mightBeReady
virtual void mightBeReady(MoveNode &mn)
Definition: BFOptimization.cc:953
BFLateBypass::originalBus_
const TTAMachine::Bus * originalBus_
Definition: BFLateBypass.hh:60
BFMergeAndKeepUser
Definition: BFMergeAndKeepUser.hh:41