OpenASIP  2.0
BFSchedulePreLoopShared.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 BFSchedulePreLoopShared.cc
27  *
28  * Definition of BFSchedulePreLoopShared class.
29  *
30  * Schedules an loop-operand-shared move in the prolog of the loop.
31  *
32  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
33  * @note rating: red
34  */
35 
37 #include "SimpleResourceManager.hh"
38 #include "MoveNodeDuplicator.hh"
39 #include "DataDependenceGraph.hh"
40 #include "BF2Scheduler.hh"
41 #include "Move.hh"
42 
44 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
45  std::cerr << "\tScheduling pre-loop-shared operand: "
47  << std::endl;
48 #endif
49  auto a = duplicator().duplicateMoveNode(originalMN_, true, true);
50  prologMN_ = a.first;
51 
52  // These should always be unconditional. Operand moves have
53  // no side effects, and nobody else uses the FU,
54  // and the value of the guard might change between the iterations
55  if (!prologMN_->move().isUnconditional()) {
56  prologMN_->move().setGuard(NULL);
57  }
58  if (prologMN_ == NULL) {
59 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
60  std::cerr << "\t\tMissing prolog MN for the move. " << std::endl;
61 #endif
62  return false;
63  }
64  int ddgLC = prologDDG()->latestCycle(*prologMN_);
65 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
66  std::cerr << "\tddg lc: " << ddgLC << std::endl;
67 #endif
68  if (ddgLC < 0) {
70  return false;
71  }
72  int lastCycleOfProlog = rm().initiationInterval()-1+
74  int rmlc = prologRM()->latestCycle(
75  std::min(ddgLC, lastCycleOfProlog), *prologMN_);
76 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
77  std::cerr << "\trmlc: " << rmlc << std::endl;
78 #endif
79  if (rmlc < 0) {
81  return false;
82  }
83  prologRM()->assign(rmlc, *prologMN_);
84 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
85  std::cerr << "scheduling of pre-loop opshare ok!"
86  << prologMN_->toString() << std::endl;
87 #endif
88  return true;
89 }
90 
92 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
93  std::cerr << "undoing scheudle of pre-loop opschare: "
94  << prologMN_->toString() << std::endl;
95 #endif
97 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
98  std::cerr << "unassigned scheudle of pre-loop opschare: "
99  << prologMN_->toString() << std::endl;
100 #endif
101 
103 }
BFOptimization::duplicator
MoveNodeDuplicator & duplicator() const
Definition: BFOptimization.cc:87
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
BFSchedulePreLoopShared::operator()
bool operator()()
Definition: BFSchedulePreLoopShared.cc:43
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
DataDependenceGraph.hh
TTAProgram::Move::setGuard
void setGuard(MoveGuard *guard)
Definition: Move.cc:360
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
SimpleResourceManager::initiationInterval
virtual unsigned initiationInterval() const
Definition: SimpleResourceManager.hh:135
SimpleResourceManager::unassign
virtual void unassign(MoveNode &node) override
Definition: SimpleResourceManager.cc:252
MoveNodeDuplicator::duplicateMoveNode
std::pair< MoveNode *, bool > duplicateMoveNode(MoveNode &mn, bool addToDDG, bool ignoreSameBBBackEdges)
Definition: MoveNodeDuplicator.cc:106
BFOptimization::prologRM
SimpleResourceManager * prologRM() const
Definition: BFOptimization.cc:77
BF2Scheduler.hh
BFOptimization::prologDDG
DataDependenceGraph * prologDDG()
Definition: BFOptimization.cc:75
MoveNodeDuplicator::disposeMoveNode
void disposeMoveNode(MoveNode *newMN)
Definition: MoveNodeDuplicator.cc:53
BFSchedulePreLoopShared.hh
BFSchedulePreLoopShared::originalMN_
MoveNode & originalMN_
Definition: BFSchedulePreLoopShared.hh:45
BFSchedulePreLoopShared::undoOnlyMe
void undoOnlyMe()
Definition: BFSchedulePreLoopShared.cc:91
BFOptimization::rm
SimpleResourceManager & rm() const
Definition: BFOptimization.cc:76
MoveNodeDuplicator.hh
BF2Scheduler::PROLOG_CYCLE_BIAS
static const int PROLOG_CYCLE_BIAS
Definition: BF2Scheduler.hh:209
MoveNode::move
TTAProgram::Move & move()
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
BFSchedulePreLoopShared::prologMN_
MoveNode * prologMN_
Definition: BFSchedulePreLoopShared.hh:46
Move.hh
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