OpenASIP  2.0
BFRemoveGuardFromSucc.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 BFRemoveGuardFromSucc.cc
27  *
28  * Definition of BFRemoveGuardFromSucc class
29  *
30  * Tries to remove a guard from a move which is a successor of a move
31  * being schedule, to allow the guard write move to be scheduled later.
32  *
33  * The guard can be removed, if the move has no side effects.
34  *
35  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
36  * @note rating: red
37  */
38 
39 #include "BFRemoveGuardFromSucc.hh"
40 #include "MoveGuard.hh"
41 #include "Move.hh"
42 #include "BFScheduleMove.hh"
43 #include "DataDependenceGraph.hh"
44 #include "BFRemoveEdge.hh"
45 #include "MoveNodeDuplicator.hh"
46 
48 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
49  std::cerr << "\t\t\tRemoving guard from succ: " << mn_.toString()
50  << std::endl;
51 #endif
52  int cycle = mn_.cycle();
53  BFOptimization* unsched = new BFUnscheduleMove(sched_, mn_);
54  if (!runPreChild(unsched)) {
55 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
56  std::cerr << "\t\t\t\tUnsched failed: " << mn_.toString()
57  << std::endl;
58 #endif
59  return false;
60  }
61 
62  // Remove the guard edges from the ddg
63  auto inEdges = ddg().inEdges(mn_);
64  for (auto e: inEdges) {
65  if (e->guardUse() && !e->isFalseDep()) {
66  runPreChild(new BFRemoveEdge(sched_, ddg().tailNode(*e), mn_,*e));
67  }
68  }
69  auto outEdges = ddg().outEdges(mn_);
70  for (auto e: outEdges) {
71  if (e->guardUse() &&
72  e->dependenceType() == DataDependenceEdge::DEP_WAR) {
73  runPreChild(new BFRemoveEdge(sched_, mn_,ddg().headNode(*e), *e));
74  }
75  }
76 
77  // If the prolog move has already been created, update also it
78  MoveNode* prologMN = ii() ? duplicator().getMoveNode(mn_) : nullptr;
79  if (prologMN != nullptr) {
80  prologMN->move().setGuard(NULL);
81  }
82 
83  guard_ = mn_.move().guard().copy();
84  mn_.move().setGuard(NULL);
85  BFOptimization* sched = new BFSchedule(sched_, mn_, cycle);
86  if (runPostChild(sched)) {
87 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
88  std::cerr << "\t\t\t\tRe-scheduling ok: " << mn_.toString()
89  << std::endl;
90 #endif
91  return true;
92  } else {
93 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
94  std::cerr << "\t\t\t\tRe-scheduling failed, undoing..: "
95  << mn_.toString() << std::endl;
96 #endif
97  undo();
98  return false;
99  }
100 }
101 
103 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
104  std::cerr << "\t\t\tRestoring guard to succ: " << mn_.toString()
105  << std::endl;
106 #endif
107 
108  // If the prolog move has already been created, update also it
109  MoveNode* prologMN = ii() ? duplicator().getMoveNode(mn_) : nullptr;
110  if (prologMN != nullptr) {
111  prologMN->move().setGuard(guard_->copy());
112  }
113 
114  mn_.move().setGuard(guard_);
115 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
116  std::cerr << "\t\t\tRestored guard to succ: " << mn_.toString()
117  << std::endl;
118 #endif
119 
120 }
BFOptimization::duplicator
MoveNodeDuplicator & duplicator() const
Definition: BFOptimization.cc:87
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
BFRemoveGuardFromSucc::operator()
bool operator()() override
Definition: BFRemoveGuardFromSucc.cc:47
BFOptimization::ii
unsigned int ii() const
Definition: BFOptimization.cc:85
DataDependenceGraph.hh
TTAProgram::Move::setGuard
void setGuard(MoveGuard *guard)
Definition: Move.cc:360
MoveNode
Definition: MoveNode.hh:65
BFOptimization
Definition: BFOptimization.hh:73
BFRemoveGuardFromSucc::guard_
TTAProgram::MoveGuard * guard_
Definition: BFRemoveGuardFromSucc.hh:63
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
BFScheduleMove.hh
BFRemoveEdge.hh
BFRemoveEdge
Definition: BFRemoveEdge.hh:40
MoveNode::cycle
int cycle() const
Definition: MoveNode.cc:421
BFRemoveGuardFromSucc::undoOnlyMe
void undoOnlyMe() override
Definition: BFRemoveGuardFromSucc.cc:102
TTAProgram::Move::guard
MoveGuard & guard() const
Definition: Move.cc:345
BFRemoveGuardFromSucc::mn_
MoveNode & mn_
Definition: BFRemoveGuardFromSucc.hh:62
Reversible::undo
virtual void undo()
Definition: Reversible.cc:69
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
MoveNodeDuplicator.hh
BoostGraph::inEdges
virtual EdgeSet inEdges(const Node &node) const
MoveNodeDuplicator::getMoveNode
MoveNode * getMoveNode(MoveNode &mn)
Definition: MoveNodeDuplicator.cc:85
BoostGraph::outEdges
virtual EdgeSet outEdges(const Node &node) const
MoveNode::move
TTAProgram::Move & move()
Reversible::runPreChild
bool runPreChild(Reversible *preChild)
Definition: Reversible.cc:127
TTAProgram::MoveGuard::copy
MoveGuard * copy() const
Definition: MoveGuard.cc:96
BFUnscheduleMove
Definition: BFUnscheduleMove.hh:48
Move.hh
DataDependenceEdge::DEP_WAR
@ DEP_WAR
Definition: DataDependenceEdge.hh:48
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
BFRemoveGuardFromSucc.hh
BFSchedule
Definition: BFScheduleMove.hh:54
MoveGuard.hh