OpenASIP  2.0
BFPushAntidepDown.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 BFPushAntidepDown.cc
27  *
28  * Definition of BFPushAntidepDown class.
29  *
30  * Tries to reschedule a move into later cycle to allow move which has an
31  * antidep to it to be scheduler later.
32  *
33  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
34  * @note rating: red
35  */
36 
37 #include "BFPushAntidepDown.hh"
38 
39 #include "DataDependenceGraph.hh"
40 #include "SimpleResourceManager.hh"
41 #include "MoveNode.hh"
42 #include "Move.hh"
43 #include "Bus.hh"
44 
45 #include "BF2Scheduler.hh"
46 #include "MoveNodeDuplicator.hh"
47 #include "UniversalMachine.hh"
48 
49 //#define DEBUG_BUBBLEFISH_SCHEDULER
50 
51 bool
53  if (mn_.move().isControlFlowMove()) {
54 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
55  std::cerr << "\t\t\tCannot reschedule control flow move!" << std::endl;
56 #endif
57  return false;
58  }
59 
60  if (&mn_ == sched_.guardWriteNode()) {
61 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
62  std::cerr << "\t\t|TCannot reschedule guard write move!" << std::endl;
63 #endif
64  return false;
65  }
66 
68 
69  int ddgLC = ddg().latestCycle(mn_);
70  int ddgEC = ddg().earliestCycle(mn_);
71 
72  // first try to schedule top-down close to the optimal as possible
73  int prefEc = newLC_ - lat_ +1;
74  if (ddgEC > prefEc) {
75  prefEc = ddgEC;
76  }
77 
78  int ec = rmEC(prefEc, mn_);
79  if (ec <= std::min(ddgLC,sched_.maximumAllowedCycle()) && ec != -1) {
80 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
81  std::cerr << "\t\t\t\t\ttopdown resched: " << ec << std::endl;
82 #endif
83  assign(ec, mn_);
84  return true;
85  } else {
86  // topdown failed, bottom-up then be it
87  int lc = rmLC(
88  (std::min(ddgLC, sched_.maximumAllowedCycle())),mn_);
89 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
90  std::cerr << "\t\t\t\tbottomup resched ddglc: " << ddgLC << " latest_: "
91  << sched_.maximumAllowedCycle() << " lc: " << lc << std::endl;
92 #endif
93  if (lc < ddgEC || lc == oldCycle_) {
94 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
95  std::cerr << "\t\tPushing down antidep dest: " << mn_.toString()
96  << " failed lc: "<< lc << " ddgEC: " << ddgEC << std::endl;
97  std::cerr << "\t\tPushAntidepsDown seting to old bus: "
98  << mn_.toString() << " to bus "
99  << oldBus_->name() << std::endl;
100 #endif
101 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
102  assert(canAssign(oldCycle_, mn_, oldBus_, NULL, NULL, prologBus_));
103 #endif
104  assign(oldCycle_, mn_, oldBus_, NULL, NULL, prologBus_,
106  return false;
107  }
108  assert(lc != -1);
109  assign(lc, mn_);
110 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
111  std::cerr << "\t\tPushed antidep down: " << mn_.toString() << " bus: "
112  << mn_.move().bus().name() << std::endl;
113 #endif
114  return true;
115  }
116  return false;
117 }
BFPushAntidepDown::newLC_
int newLC_
Definition: BFPushAntidepDown.hh:57
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
BFUnscheduleMove::oldBus_
const TTAMachine::Bus * oldBus_
Definition: BFUnscheduleMove.hh:63
TTAProgram::Move::bus
const TTAMachine::Bus & bus() const
Definition: Move.cc:373
DataDependenceGraph.hh
BFOptimization::rmEC
virtual int rmEC(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)
Definition: BFOptimization.cc:213
BFUnscheduleMove::oldCycle_
int oldCycle_
Definition: BFUnscheduleMove.hh:62
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
BFUnscheduleMove::mn_
MoveNode & mn_
Definition: BFUnscheduleMove.hh:61
BFUnscheduleMove::oldImmWriteCycle_
int oldImmWriteCycle_
Definition: BFUnscheduleMove.hh:65
assert
#define assert(condition)
Definition: Application.hh:86
UniversalMachine.hh
BF2Scheduler.hh
TTAProgram::Move::isControlFlowMove
bool isControlFlowMove() const
Definition: Move.cc:233
BFPushAntidepDown::lat_
int lat_
Definition: BFPushAntidepDown.hh:56
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
Bus.hh
MoveNodeDuplicator.hh
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
BFPushAntidepDown.hh
BFPushAntidepDown::operator()
bool operator()()
Definition: BFPushAntidepDown.cc:52
BFUnscheduleMove::unscheduleOriginal
void unscheduleOriginal()
Definition: BFUnscheduleMove.cc:47
MoveNode::move
TTAProgram::Move & move()
BFUnscheduleMove::prologBus_
const TTAMachine::Bus * prologBus_
Definition: BFUnscheduleMove.hh:64
BFOptimization::rmLC
virtual int rmLC(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)
Definition: BFOptimization.cc:363
SimpleResourceManager.hh
BF2Scheduler::guardWriteNode
MoveNode * guardWriteNode()
Definition: BF2Scheduler.hh:191
Move.hh
MoveNode.hh
BF2Scheduler::maximumAllowedCycle
int maximumAllowedCycle() const
Definition: BF2Scheduler.hh:186
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
BFUnscheduleMove::prologImmWriteCycle_
int prologImmWriteCycle_
Definition: BFUnscheduleMove.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