OpenASIP  2.0
BFEarlyBypasser.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 BFEarlyBypasser.cc
27  *
28  * Definition of BFEarlyBypassed class.
29  *
30  * Before scheduling an operand move, searches for a move which might be a
31  * bypass source and then tries class BFEarlyBypass or BFLoopBypass class
32  * to perform the actual bypass.
33  *
34  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
35  * @note rating: red
36  */
37 
38 #include "BFEarlyBypasser.hh"
39 #include "BFDREEarly.hh"
41 #include "DataDependenceGraph.hh"
42 #include "BF2Scheduler.hh"
43 #include "BF2ScheduleFront.hh"
44 #include "BFEarlyBypass.hh"
46 
47 bool
49 
50  if (bypassDistance_ == 0) return false;
51 
53  if (bypassEdge == NULL) {
54  return false;
55  }
56  MoveNode& src = ddg().tailNode(*bypassEdge);
57 
58  if (sched_.currentFront()->illegalBypassSources_.count(&src)) {
59 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
60  std::cerr << "Bypass source illegal: " << src.toString() << std::endl;
61 #endif
62  return 0;
63  }
64 
65  if (!ddg().guardsAllowBypass(src, dst_, bypassEdge->isBackEdge())) {
66  return false;
67  }
68 
70  src, dst_, sched_.targetMachine())) {
71  return false;
72  }
73 
74  int bypassSourceLC = bypassSourceLatestCycle(src, dst_);
75  if (bypassSourceLC == -1) {
76  return false;
77  }
78 
79  if (bypassEdge->isBackEdge()) {
80  if (!src.isScheduled() || src.cycle() < (int)ii()) {
81  return false;
82  }
83  } else {
84  return runPreChild(new BFEarlyBypass(sched_, src, dst_));
85  }
86  return false;
87 }
88 
89 /**
90  * Checks that bypass source does not WHAT??? */
92  MoveNode& bypassSrc, MoveNode& bypassDst) {
94 
95  int lc = INT_MAX;
96 
97  if (bypassSrc.isSourceOperation()) {
98  ProgramOperation& po = bypassSrc.sourceOperation();
99  for (int j = 0; j < po.inputMoveCount(); j++) {
100  MoveNode& inputMove = po.inputMove(j);
101  // may also be a shared operand
102  if (!sched_.isPreLoopSharedOperand(inputMove)) {
103  nodes.insert(&inputMove);
104  }
105  }
106 
107  for (int j = 0; j < po.outputMoveCount(); j++) {
108  MoveNode& outputMove = po.outputMove(j);
109  if (!sched_.isDeadResult(outputMove)) {
110  nodes.insert(&outputMove);
111  }
112  }
113  } else {
114  nodes.insert(&bypassSrc);
115  }
116 
117  for (auto mn : nodes) {
119  for (auto e : edges) {
120  MoveNode& head = ddg().headNode(*e);
121  if (head.isScheduled()) {
122  lc = std::min(lc, head.cycle());
123  continue;
124  }
125  if (&head == &bypassDst || head.isInFrontier() ||
126  e->isBackEdge() || nodes.count(&head)) {
127  continue;
128  }
129 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
130  std::cerr << "\t\t\t\tEdge almost preventing bypass from: "
131  << bypassSrc.toString() << "to: " <<bypassDst.toString()
132  << ": " << e->toString() << " dst: "
133  << head.toString() << std::endl;
134 #endif
135  return -1;
136  }
137  }
138  return lc;
139 }
140 
142  BFOptimization(sched), dst_(mn) {
145  if (opts != NULL && opts->bypassDistance() > -1) {
147  }
148 }
BF2ScheduleFront::illegalBypassSources_
DataDependenceGraph::NodeSet illegalBypassSources_
Definition: BF2ScheduleFront.hh:71
BoostGraph::tailNode
virtual Node & tailNode(const Edge &edge) const
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
MachineConnectivityCheck.hh
BoostGraph::headNode
virtual Node & headNode(const Edge &edge) const
DataDependenceEdge::isBackEdge
bool isBackEdge() const
Definition: DataDependenceEdge.hh:118
BFEarlyBypasser::dst_
MoveNode & dst_
Definition: BFEarlyBypasser.hh:49
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
BF2Scheduler::targetMachine
const TTAMachine::Machine & targetMachine() const
Definition: BF2Scheduler.hh:127
BF2Scheduler::isDeadResult
bool isDeadResult(MoveNode &mn) const
Definition: BF2Scheduler.cc:798
DataDependenceGraph.hh
ProgramOperation
Definition: ProgramOperation.hh:70
MoveNode
Definition: MoveNode.hh:65
BFOptimization
Definition: BFOptimization.hh:73
SchedulerCmdLineOptions
Definition: SchedulerCmdLineOptions.hh:45
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
SchedulerCmdLineOptions.hh
BFEarlyBypass
Definition: BFEarlyBypass.hh:39
MoveNode::sourceOperation
ProgramOperation & sourceOperation() const
Definition: MoveNode.cc:453
BF2Scheduler::findBypassEdge
DataDependenceEdge * findBypassEdge(const MoveNode &mn)
Definition: BF2Scheduler.cc:838
MachineConnectivityCheck::canBypass
static bool canBypass(const MoveNode &src, const MoveNode &user, const TTAMachine::Machine &targetMachine)
Definition: MachineConnectivityCheck.cc:1789
BFEarlyBypasser::bypassSourceLatestCycle
int bypassSourceLatestCycle(MoveNode &bypassSrc, MoveNode &bypassDst)
Definition: BFEarlyBypasser.cc:91
BF2Scheduler::isPreLoopSharedOperand
TTAMachine::FUPort * isPreLoopSharedOperand(MoveNode &mn) const
Definition: BF2Scheduler.cc:1625
BFEarlyBypass.hh
MoveNode::cycle
int cycle() const
Definition: MoveNode.cc:421
BF2Scheduler.hh
BFEarlyBypasser::bypassDistance_
int bypassDistance_
Definition: BFEarlyBypasser.hh:50
BoostGraph< MoveNode, DataDependenceEdge >::EdgeSet
std::set< DataDependenceEdge *, typename DataDependenceEdge ::Comparator > EdgeSet
Definition: BoostGraph.hh:87
Application::cmdLineOptions
static CmdLineOptions * cmdLineOptions()
Definition: Application.cc:397
BF2Scheduler
Definition: BF2Scheduler.hh:74
BF2ScheduleFront.hh
MoveNode::isSourceOperation
bool isSourceOperation() const
Definition: MoveNode.cc:168
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
ProgramOperation::inputMoveCount
int inputMoveCount() const
Definition: ProgramOperation.cc:600
BFEarlyBypasser::operator()
bool operator()()
Definition: BFEarlyBypasser.cc:48
ProgramOperation::outputMoveCount
int outputMoveCount() const
Definition: ProgramOperation.cc:610
BFDREEarly.hh
BoostGraph::outEdges
virtual EdgeSet outEdges(const Node &node) const
BF2Scheduler::currentFront
BF2ScheduleFront * currentFront()
Definition: BF2Scheduler.hh:188
MoveNode::isInFrontier
bool isInFrontier() const
Reversible::runPreChild
bool runPreChild(Reversible *preChild)
Definition: Reversible.cc:127
BFEarlyBypasser.hh
DataDependenceEdge
Definition: DataDependenceEdge.hh:43
MoveNode::isScheduled
bool isScheduled() const
Definition: MoveNode.cc:409
SchedulerCmdLineOptions::bypassDistance
virtual int bypassDistance() const
Definition: SchedulerCmdLineOptions.cc:327
ProgramOperation::outputMove
MoveNode & outputMove(int index) const
Definition: ProgramOperation.cc:632
BFEarlyBypasser::BFEarlyBypasser
BFEarlyBypasser(BF2Scheduler &sched, MoveNode &mn)
Definition: BFEarlyBypasser.cc:141
ProgramOperation::inputMove
MoveNode & inputMove(int index) const
Definition: ProgramOperation.cc:621