OpenASIP  2.0
BFLateBypassGuard.cc
Go to the documentation of this file.
1 #include "BFLateBypassGuard.hh"
2 #include "BFScheduleBU.hh"
3 #include "BFScheduleExact.hh"
4 
6 #include "DataDependenceGraph.hh"
7 #include "MoveNode.hh"
8 #include "Move.hh"
9 
10 #include "Bus.hh"
11 #include "BUMoveNodeSelector.hh"
12 #include "Terminal.hh"
13 #include "FUPort.hh"
14 #include "Guard.hh"
15 #include "Operation.hh"
16 #include "MoveGuard.hh"
17 
18 bool
20 
21 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
22  std::cerr << "\t\tPerforming late bypass guard: " << dst_.toString() << std::endl;
23 #endif
24 
25  // Only allow guard bypass if it can save clock cycles on guard path.
26  if (dst_.cycle() > lc_ + dst_.guardLatency()-1) {
27 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
28  std::cerr << "\t\t\tAborting guard bypass due too long guard distance" << std::endl;
29 #endif
30 
31  return false;
32  }
33 
34  if (!src_.isSourceOperation()) {
35 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
36  std::cerr << "\t\t\tsrc src not op: "<< src_.toString() << std::endl;
37 #endif
38  return false;
39  }
40 
41 
42  if (dst_.isSourceOperation()) {
43 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
44  std::cerr << "\t\t\tsrc not constant: " << dst_.toString() << std::endl;
45 #endif
46  return false;
47  }
48 
49 
51  const Operation& op = po.operation();
52 
53  // TODO: might need set of these for annotations.
54  const TTAMachine::FunctionUnit* fu = NULL;
55  for (int i = 0; i < po.inputMoveCount(); i++) {
56  MoveNode& mn = po.inputMove(i);
57  if (mn.isScheduled()) {
58  fu = &mn.move().destination().functionUnit();
59  }
60  // TODO: fu annotations can forbid this?
61  }
62  for (int i = 0; i < po.outputMoveCount(); i++) {
63  MoveNode& mn = po.outputMove(i);
64  if (mn.isScheduled()) {
65  fu = &mn.move().source().functionUnit();
66  }
67  // TODO: fu annotations can forbid this?
68  }
69 
70  if (dst_.move().isUnconditional()) {
71  ddg().writeToDotFile("guard_edge_dest_uncond.dot");
72  }
74  const TTAMachine::Bus& bus = dst_.move().bus();
75  for (int i = 0; i < bus.guardCount(); i++) {
76 
77  TTAMachine::Guard* guard = bus.guard(i);
79  dynamic_cast<TTAMachine::PortGuard*>(guard);
80  if (pg == NULL) {
81  continue;
82  }
83  if (pg->isInverted() != dst_.move().guard().isInverted()) {
84  continue;
85  }
86  const TTAMachine::FUPort* port = pg->port();
87  TTAMachine::FunctionUnit* gfu = port->parentUnit();
88  if (gfu->hasOperation(op.name()) &&
89  po.outputIndexFromGuard(*pg) ==
91  (fu == NULL || fu == gfu)) {
92 
93  if (!po.isLegalFU(*gfu)) {
94 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
95  std::cerr << "\t\t\tFU: " << gfu->name() << " not allowed for operation: " << po.toString() << std::endl;
96 #endif
97  continue;
98  }
99 
100 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
101  std::cerr << "\t\t\tFound suitable guard & FU" << std::endl;
102 #endif
104  originalBus_ = &dst_.move().bus();
106 
107  unassign(dst_, false);
108 
109  // TODO: backup old guard.
110  dst_.move().setGuard(new TTAProgram::MoveGuard(*guard));
111 
113 
115  if ((*sched)()) {
116  postChildren_.push(sched);
117 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
118  std::cerr << "\t\tGuard conversion ok: " << dst_.toString() << std::endl;
119 #endif
120  return true;
121  } else {
122 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
123  std::cerr << "\t\tGuard conversion sched fail.: " << dst_.toString() << std::endl;
124 #endif
125  delete sched;
126 
128 
131 
134  }
135  }
136  }
137 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
138  std::cerr << "\t\t\tDid not find a bus with suitable guard?" << std::endl;
139 #endif
140  return false;
141 }
142 
143 
144 
145 
146 void
148 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
149  std::cerr << "\t\t\tUndoing guard conversion: " << dst_.toString() << std::endl;
150 #endif
151 
153 
155 
157 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
158  std::cerr << "\t\t\tReassigning move: " << dst_.toString() << " to cycle: "
159  << originalCycle_ << " bus: " << originalBus_->name() << std::endl;
160 #endif
163 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
164  std::cerr << "\t\tReassigned move:" << dst_.toString() << std::endl;
165 #endif
166 }
TTAMachine::Guard
Definition: Guard.hh:55
ProgramOperation::operation
const Operation & operation() const
Definition: ProgramOperation.cc:590
Reversible::postChildren_
std::stack< Reversible * > postChildren_
Definition: Reversible.hh:58
BFOptimization::unassign
virtual void unassign(MoveNode &mn, bool disposePrologCopy=true)
Definition: BFOptimization.cc:196
BFLateBypass::lc_
int lc_
Definition: BFLateBypass.hh:59
BFLateBypassGuard.hh
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
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
TTAMachine::PortGuard::port
FUPort * port() const
TTAMachine::BaseFUPort::parentUnit
FunctionUnit * parentUnit() const
Definition: BaseFUPort.cc:96
TTAProgram::MoveGuard::isInverted
bool isInverted() const
Definition: MoveGuard.cc:76
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
TTAMachine::Bus
Definition: Bus.hh:53
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
BFLateBypassGuard::operator()
virtual bool operator()()
Definition: BFLateBypassGuard.cc:19
TTAProgram::Move::bus
const TTAMachine::Bus & bus() const
Definition: Move.cc:373
DataDependenceGraph.hh
ProgramOperation
Definition: ProgramOperation.hh:70
TTAProgram::Move::setGuard
void setGuard(MoveGuard *guard)
Definition: Move.cc:360
MoveNode
Definition: MoveNode.hh:65
BUMoveNodeSelector.hh
BFLateBypassGuard::undoOnlyMe
virtual void undoOnlyMe()
Definition: BFLateBypassGuard.cc:147
BFOptimization
Definition: BFOptimization.hh:73
BFLateBypass::dst_
MoveNode & dst_
Definition: BFLateBypass.hh:58
Terminal.hh
ProgramOperation::outputIndexFromGuard
int outputIndexFromGuard(const TTAMachine::PortGuard &pg) const
Definition: ProgramOperation.cc:266
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
ProgramOperation::isLegalFU
bool isLegalFU(const TTAMachine::FunctionUnit &fu) const
Definition: ProgramOperation.cc:915
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
MoveNode::sourceOperation
ProgramOperation & sourceOperation() const
Definition: MoveNode.cc:453
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAProgram::Terminal::operationIndex
virtual int operationIndex() const
Definition: Terminal.cc:364
MoveNode::cycle
int cycle() const
Definition: MoveNode.cc:421
MoveNode::guardLatency
int guardLatency() const
Definition: MoveNode.cc:779
BFScheduleBU.hh
TTAProgram::Move::guard
MoveGuard & guard() const
Definition: Move.cc:345
Guard.hh
Operation.hh
MoveNode::isSourceOperation
bool isSourceOperation() const
Definition: MoveNode.cc:168
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
TTAMachine::FunctionUnit::hasOperation
virtual bool hasOperation(const std::string &name) const
Definition: FunctionUnit.cc:330
Bus.hh
ProgramOperation::inputMoveCount
int inputMoveCount() const
Definition: ProgramOperation.cc:600
TTAMachine::Bus::guardCount
int guardCount() const
Definition: Bus.cc:441
TTAMachine::Bus::guard
Guard * guard(int index) const
Definition: Bus.cc:456
Operation
Definition: Operation.hh:59
GraphBase::writeToDotFile
virtual void writeToDotFile(const TCEString &fileName) const
DataDependenceGraph::guardRestored
void guardRestored(MoveNode &guardSrc, MoveNode &dst)
Definition: DataDependenceGraph.cc:5849
ProgramOperation::outputMoveCount
int outputMoveCount() const
Definition: ProgramOperation.cc:610
TTAProgram::Terminal::functionUnit
virtual const TTAMachine::FunctionUnit & functionUnit() const
Definition: Terminal.cc:251
MoveNode::move
TTAProgram::Move & move()
BFLateBypassGuard::originalGuard_
const TTAMachine::Guard * originalGuard_
Definition: BFLateBypassGuard.hh:16
ProgramOperation::toString
std::string toString() const
Definition: ProgramOperation.cc:746
BFLateBypass::originalCycle_
int originalCycle_
Definition: BFLateBypass.hh:56
TTAMachine::Guard::isInverted
virtual bool isInverted() const
DataDependenceGraph::guardConverted
void guardConverted(MoveNode &guardSrc, MoveNode &dst)
Definition: DataDependenceGraph.cc:5795
BFScheduleExact
Definition: BFScheduleExact.hh:47
FUPort.hh
BFScheduleExact.hh
SimpleResourceManager.hh
MoveNode::isScheduled
bool isScheduled() const
Definition: MoveNode.cc:409
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
BFLateBypass::src_
MoveNode & src_
Definition: BFLateBypass.hh:57
TTAMachine::PortGuard
Definition: Guard.hh:99
TTAProgram::MoveGuard::guard
const TTAMachine::Guard & guard() const
Definition: MoveGuard.cc:86
Move.hh
MoveNode.hh
TTAProgram::MoveGuard
Definition: MoveGuard.hh:47
ProgramOperation::outputMove
MoveNode & outputMove(int index) const
Definition: ProgramOperation.cc:632
TTAProgram::Move::setBus
void setBus(const TTAMachine::Bus &bus)
Definition: Move.cc:383
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
ProgramOperation::inputMove
MoveNode & inputMove(int index) const
Definition: ProgramOperation.cc:621
BFLateBypass::originalBus_
const TTAMachine::Bus * originalBus_
Definition: BFLateBypass.hh:60
MoveGuard.hh