OpenASIP  2.0
BFRemoveGuardsFromSuccs.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 BFRemoveGuardsFromSuccs.cc
27  *
28  * Definition of BFRemoveGuardsFromSuccs class
29  *
30  * When scheduling a move wihch writes a guard, check for the uses of the
31  * guard and try to remove those guad uses to allows scheduling this guard write
32  * later. Calls BFRemoveGuardFromSucc.
33  *
34  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
35  * @note rating: red
36  */
37 
39 #include "BFRemoveGuardFromSucc.hh"
40 #include "DataDependenceGraph.hh"
41 #include "Move.hh"
42 #include <list>
43 #include "SimpleResourceManager.hh"
44 
46 
48 
49 // std::list<BFRemoveGuardFromSucc*> guardRemoves;
50  std::list<MoveNode*> guardRemoveNodes;
51 
52  for (auto e: outEdges) {
53  if (e->guardUse() &&
54  e->dependenceType() == DataDependenceEdge::DEP_RAW) {
55  MoveNode& head = ddg().headNode(*e);
56  if (head.move().isUnconditional()) {
57  std::cerr << "guard edge to uncond move?" << head.toString()
58  << std::endl;
59  continue;
60  }
61  if (head.isScheduled()) {
62  // this is not in critical path.
63  int cycle = head.cycle();
64  if (cycle > maxLC_ + head.guardLatency()) {
65  continue;
66  } else {
67  if (canBeSpeculated(head)) {
68  guardRemoveNodes.push_back(&head);
69  } else {
70  maxLC_ = std::min(
71  maxLC_, head.cycle() - head.guardLatency());
72  continue;
73  }
74  }
75  }
76  }
77  }
78 
79  for (auto i: guardRemoveNodes) {
80  MoveNode& mn = *i;
81  if (mn.cycle() - mn.guardLatency() < maxLC_) {
83  }
84  }
85  if (postChildren_.empty()) {
86  return false;
87  }
88 
89  // if could not improve schedule, return everything back the way it was
90  int ddglc = ddg().latestCycle(guardWrite_, ii(), false, false);
91  int rmlc = rm().latestCycle(ddglc, guardWrite_);
92  if (rmlc <= oldLC_) {
93  undo();
94  return false;
95  }
96 
97  return true;
98 }
Reversible::postChildren_
std::stack< Reversible * > postChildren_
Definition: Reversible.hh:58
BFRemoveGuardsFromSuccs::maxLC_
int maxLC_
Definition: BFRemoveGuardsFromSuccs.hh:55
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
BoostGraph::headNode
virtual Node & headNode(const Edge &edge) const
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
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
BFOptimization::canBeSpeculated
bool canBeSpeculated(const Operation &op)
Definition: BFOptimization.cc:857
MoveNode::cycle
int cycle() const
Definition: MoveNode.cc:421
MoveNode::guardLatency
int guardLatency() const
Definition: MoveNode.cc:779
BoostGraph< MoveNode, DataDependenceEdge >::EdgeSet
std::set< DataDependenceEdge *, typename DataDependenceEdge ::Comparator > EdgeSet
Definition: BoostGraph.hh:87
BFRemoveGuardsFromSuccs.hh
DataDependenceEdge::DEP_RAW
@ DEP_RAW
Definition: DataDependenceEdge.hh:47
Reversible::undo
virtual void undo()
Definition: Reversible.cc:69
BFRemoveGuardFromSucc
Definition: BFRemoveGuardFromSucc.hh:54
BFRemoveGuardsFromSuccs::oldLC_
int oldLC_
Definition: BFRemoveGuardsFromSuccs.hh:54
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
BFOptimization::rm
SimpleResourceManager & rm() const
Definition: BFOptimization.cc:76
BoostGraph::outEdges
virtual EdgeSet outEdges(const Node &node) const
MoveNode::move
TTAProgram::Move & move()
BFRemoveGuardsFromSuccs::guardWrite_
MoveNode & guardWrite_
Definition: BFRemoveGuardsFromSuccs.hh:53
SimpleResourceManager::latestCycle
virtual int latestCycle(MoveNode &node, const TTAMachine::Bus *bus=NULL, const TTAMachine::FunctionUnit *srcFU=NULL, const TTAMachine::FunctionUnit *dstFU=NULL, int immWriteCycle=-1, const TTAMachine::ImmediateUnit *immu=nullptr, int immRegIndex=-1) const override
Definition: SimpleResourceManager.cc:349
SimpleResourceManager.hh
MoveNode::isScheduled
bool isScheduled() const
Definition: MoveNode.cc:409
Move.hh
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
BFRemoveGuardFromSucc.hh
BFRemoveGuardsFromSuccs::operator()
bool operator()() override
Definition: BFRemoveGuardsFromSuccs.cc:45
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