OpenASIP  2.0
BFShareOperands.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 BFShareOperands.cc
27  *
28  * Definition of BFShareOperands class
29  *
30  * Searches for potential operations to share operand with, and
31  * then calls BFShareOperandWithScheduled to fo the actual operand sharing.
32  *
33  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
34  * @note rating: red
35  */
36 
37 #include "BFShareOperands.hh"
38 #include "DataDependenceGraph.hh"
39 #include "FunctionUnit.hh"
40 #include "Terminal.hh"
41 #include "Move.hh"
42 #include "Operation.hh"
43 #include "BF2Scheduler.hh"
44 #include "BF2ScheduleFront.hh"
46 #include "HWOperation.hh"
47 #include "FUPort.hh"
48 
50  // TODO: alctually check the guards
51  if (!mn_.move().isUnconditional()) {
52  return false;
53  }
54 
55 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
56  std::cerr << "\t\tShareOperands operator() called for:"
57  << mn_.toString() << std::endl;
58 #endif
59 
62 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
63  std::cerr << "\t\t\tIllegal operand share: " << mn_.toString()
64  << std::endl;
65 #endif
66  return false;
67  }
68 
69  bool didSomething = false;
71  const Operation& op = po.operation();
72  const TTAMachine::FunctionUnit* forcedFU = po.scheduledFU();
73 
75  for (auto i : siblings) {
76  if (!i->isDestinationOperation()) {
77  continue;
78  }
79 
80  if (i->isScheduled()) {
81  if (i->cycle() > maxCycle_) {
82  continue;
83  }
84  // limit operand sharing for reasonable distances
85  // TODO: use the cmd line parameter
86  int ddglc = ddg().latestCycle(mn_, ii(), false, false);
87  if (i->cycle() < ddglc - 5) {
88  continue;
89  }
90 
91  // try share with already scheduled
92  const TTAProgram::Terminal& dt = i->move().destination();
93  if (dt.isFUPort()) {
94  const TTAMachine::FunctionUnit& fu = dt.functionUnit();
95  if (!fu.hasOperation(op.name())) {
96  continue;
97  }
98  const TTAMachine::HWOperation* hwop = fu.operation(op.name());
99  const TTAMachine::FUPort *sharedPort =
100  hwop->port(mn_.move().destination().operationIndex());
101  if (sharedPort != &dt.port()) {
102  continue;
103  }
104  if (dt.isTriggering()) {
105  // TODO: is sibling commutative?
106  continue;
107  }
108  if (forcedFU != NULL) {
109  if (&fu == forcedFU) {
110  MoveNode* trigger =
112  mn_, targetMachine());
113  if (trigger == &mn_) {
114  continue;
115  }
116 
119  if (runPreChild(sows)) {
120  didSomething = true;
121  }
122  }
123  } else {
124  if (fu.hasOperation(op.name())) {
125  if (sched_.isTrigger(fu, mn_)) {
126  // TODO: change commutative
127  continue;
128  }
129 
132  if (runPreChild(sows)) {
133  didSomething = true;
134  }
135  }
136  }
137  }
138  }
139  }
140  return didSomething;
141 }
142 
144 
145 bool BFShareOperands::removedNode() { return false; }
ProgramOperation::operation
const Operation & operation() const
Definition: ProgramOperation.cc:590
TTAProgram::Terminal::isFUPort
virtual bool isFUPort() const
Definition: Terminal.cc:118
TTAProgram::Terminal::isTriggering
virtual bool isTriggering() const
Definition: Terminal.cc:298
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
TTAMachine::HWOperation
Definition: HWOperation.hh:52
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::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
BFOptimization::getSisterTrigger
static MoveNode * getSisterTrigger(const MoveNode &mn, const TTAMachine::Machine &mach)
Definition: BFOptimization.cc:848
DataDependenceGraph.hh
ProgramOperation
Definition: ProgramOperation.hh:70
MoveNode
Definition: MoveNode.hh:65
Terminal.hh
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
BFOptimization::targetMachine
const TTAMachine::Machine & targetMachine() const
Definition: BFOptimization.cc:81
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
BF2Scheduler::isTrigger
bool isTrigger(const TTAMachine::Unit &unit, MoveNode &mn)
Definition: BF2Scheduler.cc:819
DataDependenceGraph::regDepSiblings
NodeSet regDepSiblings(const MoveNode &mn) const
Definition: DataDependenceGraph.cc:5620
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::HWOperation::port
virtual FUPort * port(int operand) const
Definition: HWOperation.cc:320
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAProgram::Terminal::operationIndex
virtual int operationIndex() const
Definition: Terminal.cc:364
HWOperation.hh
BF2Scheduler.hh
BFShareOperands::operator()
virtual bool operator()()
Definition: BFShareOperands.cc:49
BFShareOperands::undoOnlyMe
virtual void undoOnlyMe()
Definition: BFShareOperands.cc:143
BF2ScheduleFront.hh
Operation.hh
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
TTAMachine::FunctionUnit::hasOperation
virtual bool hasOperation(const std::string &name) const
Definition: FunctionUnit.cc:330
Operation
Definition: Operation.hh:59
ProgramOperation::scheduledFU
const TTAMachine::FunctionUnit * scheduledFU() const
Definition: ProgramOperation.cc:866
BFShareOperands::mn_
MoveNode & mn_
Definition: BFShareOperands.hh:58
TTAProgram::Terminal::functionUnit
virtual const TTAMachine::FunctionUnit & functionUnit() const
Definition: Terminal.cc:251
MoveNode::destinationOperation
ProgramOperation & destinationOperation(unsigned int index=0) const
MoveNode::move
TTAProgram::Move & move()
BFShareOperands::maxCycle_
int maxCycle_
Definition: BFShareOperands.hh:59
BF2Scheduler::currentFront
BF2ScheduleFront * currentFront()
Definition: BF2Scheduler.hh:188
Reversible::runPreChild
bool runPreChild(Reversible *preChild)
Definition: Reversible.cc:127
BF2ScheduleFront::illegalOperandShares_
DataDependenceGraph::NodeSet illegalOperandShares_
Definition: BF2ScheduleFront.hh:72
FUPort.hh
BFShareOperandWithScheduled.hh
TTAProgram::Terminal
Definition: Terminal.hh:60
TTAProgram::Terminal::port
virtual const TTAMachine::Port & port() const
Definition: Terminal.cc:378
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
BFShareOperands.hh
Move.hh
BFShareOperands::removedNode
virtual bool removedNode()
Definition: BFShareOperands.cc:145
BFShareOperandWithScheduled
Definition: BFShareOperandWithScheduled.hh:44
FunctionUnit.hh
DataDependenceGraph::latestCycle
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
Definition: DataDependenceGraph.cc:543