OpenASIP  2.0
BFScheduleExact.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 BFScheduleExact.cc
27  *
28  * Declaration of BFScheduleExact class
29  *
30  * Tries to schedule a move to an exact cycle (no order).
31  *
32  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
33  * @note rating: red
34  */
35 
36 #include "BFScheduleExact.hh"
37 #include "BFRegCopyBefore.hh"
38 #include "BFRegCopyAfter.hh"
39 #include "SimpleResourceManager.hh"
40 #include "MoveNode.hh"
41 #include "DataDependenceGraph.hh"
42 #include "Move.hh"
43 #include "Machine.hh"
44 #include "ControlUnit.hh"
45 #include "TerminalImmediate.hh"
46 #include "BF2Scheduler.hh"
47 #include "BFScheduleBU.hh"
48 #include "BFEarlyGuardBypass.hh"
49 #include "MoveGuard.hh"
50 #include "Guard.hh"
51 
52 bool
54 
55 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
56  std::cerr << "\t\tScheduling to exact cycle: " << mn_.toString()
57  << " to cycle: " << c_ << std::endl;
58 #endif
59  BFRegCopy* regCopyBefore = NULL;
60  //BFRegCopy* regCopyAfter = NULL;
61  BFRegCopy* regCopy = NULL;
62 
63  if (!mn_.move().isUnconditional() &&
64  mn_.move().guard().guard().parentBus() == nullptr) {
66  std::cerr << "Early guard bypass failed!" << std::endl;
67  return false;
68  }
69  }
70  if (allowRegCopy_ && !canBeScheduled(mn_)) {
71  if (mn_.isSourceOperation()) {
72  // assumes the result read is wanted to the exact cycle.
73  // reg cpy after both splits the move and schedules the copy.
74  // TODO: should it be scheudled TD instead of BU then?
75  regCopy = new BFRegCopyAfter(sched_,mn_, INT_MAX);
76  } else {
77  // this only splits the move. scheduled later.
78  regCopyBefore = regCopy = new BFRegCopyBefore(sched_,mn_, INT_MAX);
79  }
80 
81  if (!runPreChild(regCopy)) {
82  return false;
83  }
84  }
85  int ddglc = ddg().latestCycle(mn_, ii(), false, false);
86  int ddgec = ddg().earliestCycle(mn_, ii(), false, false);
87 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
88  std::cerr << "\t\t\tddg lc: " << ddglc << std::endl;
89  std::cerr << "\t\t\tddg ec: " << ddgec << std::endl;
90 #endif
91  if (ddglc >= c_ && ddgec <= c_ && canAssign(c_, mn_, nullptr, srcFU_)) {
92  createdCopy_ = assign(c_, mn_, nullptr, srcFU_);
93  if (regCopyBefore != NULL) {
94  MoveNode* regCopy = regCopyBefore->getRegCopy();
95  BFScheduleBU* regCopySched =
96  new BFScheduleBU(sched_, *regCopy, c_-1, false, false, false);
97  if (!runPostChild(regCopySched)) {
98  undo();
99  return false;
100  }
101  }
102  return true;
103  } else {
105  return false;
106  }
107 }
108 
109 void
112  if (jumpLimitMove_) {
116  jumpLimitMove_ = NULL;
117  }
118 }
BFOptimization::unassign
virtual void unassign(MoveNode &mn, bool disposePrologCopy=true)
Definition: BFOptimization.cc:196
Reversible::undoAndRemovePreChildren
void undoAndRemovePreChildren()
Definition: Reversible.cc:80
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
BFScheduleExact::undoOnlyMe
virtual void undoOnlyMe()
Definition: BFScheduleExact.cc:110
BFEarlyGuardBypass.hh
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
BFScheduleExact::oldJumpLimitWidth_
int oldJumpLimitWidth_
Definition: BFScheduleExact.hh:65
BFOptimization::ii
unsigned int ii() const
Definition: BFOptimization.cc:85
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
DataDependenceGraph.hh
MoveNode
Definition: MoveNode.hh:65
BFScheduleExact::allowRegCopy_
bool allowRegCopy_
Definition: BFScheduleExact.hh:61
BFRegCopy::getRegCopy
MoveNode * getRegCopy()
Definition: BFRegCopy.hh:52
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
SimValue
Definition: SimValue.hh:96
BFRegCopy
Definition: BFRegCopy.hh:47
BFEarlyGuardBypass
Definition: BFEarlyGuardBypass.hh:7
BFRegCopyAfter
Definition: BFRegCopyAfter.hh:44
BFScheduleBU
Definition: BFScheduleBU.hh:45
BF2Scheduler.hh
BFRegCopyBefore.hh
BFScheduleBU.hh
TTAProgram::Move::guard
MoveGuard & guard() const
Definition: Move.cc:345
Reversible::undo
virtual void undo()
Definition: Reversible.cc:69
Guard.hh
MoveNode::isSourceOperation
bool isSourceOperation() const
Definition: MoveNode.cc:168
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
BFScheduleExact::oldJumpLimit_
int oldJumpLimit_
Definition: BFScheduleExact.hh:64
Machine.hh
BFOptimization::canBeScheduled
bool canBeScheduled(const MoveNode &mn)
Definition: BFOptimization.cc:1067
DataDependenceGraph::earliestCycle
int earliestCycle(const MoveNode &moveNode, unsigned int ii=UINT_MAX, bool ignoreRegWaRs=false, bool ignoreRegWaWs=false, bool ignoreGuards=false, bool ignoreFUDeps=false, bool ignoreSameOperationEdges=false, bool assumeBypassing=false) const
Definition: DataDependenceGraph.cc:388
TTAProgram::TerminalImmediate
Definition: TerminalImmediate.hh:44
TTAMachine::Guard::parentBus
virtual Bus * parentBus() const
MoveNode::move
TTAProgram::Move & move()
BFScheduleExact::srcFU_
const TTAMachine::FunctionUnit * srcFU_
Definition: BFScheduleExact.hh:67
BFRegCopyBefore
Definition: BFRegCopyBefore.hh:44
TerminalImmediate.hh
Reversible::runPreChild
bool runPreChild(Reversible *preChild)
Definition: Reversible.cc:127
ControlUnit.hh
BFScheduleExact.hh
SimpleResourceManager.hh
BFRegCopyAfter.hh
TTAProgram::MoveGuard::guard
const TTAMachine::Guard & guard() const
Definition: MoveGuard.cc:86
Move.hh
BFScheduleExact::c_
int c_
Definition: BFScheduleExact.hh:62
MoveNode.hh
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
BFScheduleMove::mn_
MoveNode & mn_
Definition: BFScheduleMove.hh:50
BFScheduleExact::operator()
virtual bool operator()()
Definition: BFScheduleExact.cc:53
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
TTAProgram::Move::setSource
void setSource(Terminal *src)
Definition: Move.cc:312
BFScheduleExact::createdCopy_
bool createdCopy_
Definition: BFScheduleExact.hh:66
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
BFScheduleExact::jumpLimitMove_
TTAProgram::Move * jumpLimitMove_
Definition: BFScheduleExact.hh:63
MoveGuard.hh