OpenASIP  2.0
BFPostpassLoopDRE.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 BFPostpassLoopDRE.cc
27  *
28  * Definition of BFPostpassLoopDRE class
29  *
30  * Performs a dead-result elimination of a loop-bypassed move.
31  * The move which is eliminated from the loop body is still left
32  * in the epilog, to have correct value for the register after
33  * the loop.
34  *
35  * This class is called in the postpass-bypass phase.
36  *
37  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
38  * @note rating: red
39  */
40 
41 #include "BFPostpassLoopDRE.hh"
42 
43 #include "BF2Scheduler.hh"
44 #include "DataDependenceGraph.hh"
45 
46 #include "BFPostpassDRE.hh"
47 #include "BFUnscheduleMove.hh"
48 
49 #include "MoveNodeDuplicator.hh"
50 #include "SimpleResourceManager.hh"
51 
52 
53 bool
55  if (!sched_.killDeadResults()) {
56  return false;
57  }
58 
59  if (!dreAllowed()) {
60  return false;
61  }
62 
63  // Create a copy to prolog.
65  if (prologMN_ == NULL) {
66  return false;
67  }
68 
69  int prologCycle = BF2Scheduler::PROLOG_CYCLE_BIAS + srcCycle_;
70  if (prologRM()->canAssign(prologCycle, *prologMN_)) {
71  prologRM()->assign(prologCycle, *prologMN_);
72 
73  // then remove
74  ddg().copyDepsOver(mn_, true, false);
75  ddg().dropNode(mn_);
77  return true;
78 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
79  } else {
80  std::cerr << "\t\t\t\tProlog cycle assign fail for loop-dre: "
81  << prologMN_->toString()
82  << " prolog cycle: " << prologCycle << std::endl;
83 #endif
84  }
85  return false;
86 }
87 
90  for (auto edge: edges) {
91  if (edge->edgeReason() == DataDependenceEdge::EDGE_OPERATION) {
92 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
93  std::cerr << "DRE not allowed due op edge: "
94  << edge->toString() << std::endl;
95 #endif
96  return false;
97  }
98  if ((edge->edgeReason() == DataDependenceEdge::EDGE_REGISTER ||
99  edge->edgeReason() ==DataDependenceEdge::EDGE_RA) &&
100  edge->dependenceType() == DataDependenceEdge::DEP_RAW) {
101 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
102  std::cerr << "DRE not allowed due edge: "
103  << edge->toString() << std::endl;
104 #endif
105  return false;
106  }
107  }
108  return true;
109 }
110 
115 }
BFUnscheduleMove.hh
BFOptimization::duplicator
MoveNodeDuplicator & duplicator() const
Definition: BFOptimization.cc:87
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
BFPostpassLoopDRE::srcCycle_
int srcCycle_
Definition: BFPostpassLoopDRE.hh:57
BF2Scheduler::killDeadResults
bool killDeadResults() const
Definition: BF2Scheduler.hh:110
BFPostpassLoopDRE.hh
DataDependenceGraph.hh
BFPostpassLoopDRE::undoOnlyMe
void undoOnlyMe() override
Definition: BFPostpassLoopDRE.cc:111
SimpleResourceManager::assign
virtual void assign(int cycle, 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) override
Definition: SimpleResourceManager.cc:221
DataDependenceEdge::EDGE_REGISTER
@ EDGE_REGISTER
Definition: DataDependenceEdge.hh:53
SimpleResourceManager::unassign
virtual void unassign(MoveNode &node) override
Definition: SimpleResourceManager.cc:252
BoostGraph::dropNode
virtual void dropNode(Node &node)
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
BFPostpassDRE.hh
BFOptimization::prologRM
SimpleResourceManager * prologRM() const
Definition: BFOptimization.cc:77
BF2Scheduler.hh
BoostGraph< MoveNode, DataDependenceEdge >::EdgeSet
std::set< DataDependenceEdge *, typename DataDependenceEdge ::Comparator > EdgeSet
Definition: BoostGraph.hh:87
DataDependenceEdge::DEP_RAW
@ DEP_RAW
Definition: DataDependenceEdge.hh:47
BFPostpassLoopDRE::operator()
bool operator()() override
Definition: BFPostpassLoopDRE.cc:54
DataDependenceEdge::EDGE_OPERATION
@ EDGE_OPERATION
Definition: DataDependenceEdge.hh:56
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
MoveNodeDuplicator.hh
BF2Scheduler::PROLOG_CYCLE_BIAS
static const int PROLOG_CYCLE_BIAS
Definition: BF2Scheduler.hh:209
MoveNodeDuplicator::getMoveNode
MoveNode * getMoveNode(MoveNode &mn)
Definition: MoveNodeDuplicator.cc:85
BoostGraph::outEdges
virtual EdgeSet outEdges(const Node &node) const
BF2Scheduler::nodeResurrected
void nodeResurrected(MoveNode &mn)
Definition: BF2Scheduler.cc:811
BFPostpassLoopDRE::prologMN_
MoveNode * prologMN_
Definition: BFPostpassLoopDRE.hh:56
SimpleResourceManager.hh
BF2Scheduler::nodeKilled
void nodeKilled(MoveNode &mn)
Definition: BF2Scheduler.cc:807
DataDependenceGraph::copyDepsOver
EdgeSet copyDepsOver(MoveNode &node, bool anti, bool raw)
Definition: DataDependenceGraph.cc:2422
BFPostpassLoopDRE::mn_
MoveNode & mn_
Definition: BFPostpassLoopDRE.hh:55
DataDependenceEdge::EDGE_RA
@ EDGE_RA
Definition: DataDependenceEdge.hh:57
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
BFPostpassLoopDRE::dreAllowed
bool dreAllowed()
Definition: BFPostpassLoopDRE.cc:88
BoostGraph::restoreNodeFromParent
void restoreNodeFromParent(GraphNode &node)