OpenASIP  2.0
BFShareOperand.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 BFShareOperand.cc
27  *
28  * Definition of BFShareOperand class.
29  *
30  * Performs an operands sharing between two (or more) operations
31  *
32  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
33  * @note rating: red
34  */
35 
36 #include "BFShareOperand.hh"
37 #include "MoveNode.hh"
38 #include "DataDependenceGraph.hh"
39 #include "Move.hh"
40 #include "Terminal.hh"
41 #include "MoveNodeDuplicator.hh"
42 
46  return false;
47  }
51  op->removeInputNode(removed_);
52 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
53  std::cerr << "\t\t\t\t\tRemoved: " << removed_.toString()
54  << " from: " << op->toString() << std::endl;
55 #endif
56 
58  op->addInputNode(shared_);
59 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
60  std::cerr << "\t\t\t\t\tAdded: " << shared_.toString()
61  << " to: " << op->toString() << std::endl;
62 #endif
63 
64  // update also prolog movenodes.
65  if (ii()) {
66  MoveNode* prologMNOfRemoved = duplicator().getMoveNode(removed_);
67  ProgramOperationPtr prologPO;
68  if (prologMNOfRemoved) {
69  prologPO = prologMNOfRemoved->destinationOperationPtr(0);
70  prologMNOfRemoved->removeDestinationOperation(&*prologPO);
71  prologPO->removeInputNode(*prologMNOfRemoved);
72  } else {
73  prologPO = duplicator().getProgramOperation(op);
74  }
75 
76  MoveNode* prologMNOfShared = duplicator().getMoveNode(shared_);
77  if (prologMNOfShared) {
78  if (prologPO == nullptr) {
80  createdPrologPOs_.insert(prologPO);
81  }
82  prologMNOfShared->addDestinationOperationPtr(prologPO);
83  prologPO->addInputNode(*prologMNOfShared);
84  }
85  }
86  ops_.push_back(op);
87  }
88  return true;
89 }
90 
91 void
93 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
94  std::cerr << "\t\t\t\tBFShareOperand undoing itseld, shared: "
95  << shared_.toString() << std::endl;
96 #endif
97  while(ops_.size()) {
98  ProgramOperationPtr op = *ops_.rbegin();
99 
100  if (ii()) {
101  ProgramOperationPtr prologPO =
103 
104  MoveNode* prologMNOfShared = duplicator().getMoveNode(shared_);
105  MoveNode* prologMNOfRemoved = duplicator().getMoveNode(removed_);
106 
107  if (prologMNOfShared) {
108  // if the mn is duplicated, also the PO should be duplicated
109  assert(prologPO != nullptr);
110  prologPO->removeInputNode(*prologMNOfShared);
111  prologMNOfShared->removeDestinationOperation(&*prologPO);
112  }
113 
114  if (prologMNOfRemoved) {
115  // if the mn is duplicated, also the PO should be duplicated
116  assert(prologPO != nullptr);
117  prologPO->addInputNode(*prologMNOfRemoved);
118  prologMNOfRemoved->addDestinationOperationPtr(prologPO);
119  }
120  }
121 
122 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
123  std::cerr << "\t\t\t\t\t\tRestoring, op: "
124  << op->toString() << std::endl;
125 #endif
126  op->removeInputNode(shared_);
128  op->addInputNode(removed_);
130 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
131  std::cerr << "\t\t\t\t\t\tRestored: " << removed_.toString()
132  << " to: " << op->toString() << std::endl;
133 #endif
134  ops_.pop_back();
135  }
136 }
BFShareOperand::removed_
MoveNode & removed_
Definition: BFShareOperand.hh:52
BFOptimization::duplicator
MoveNodeDuplicator & duplicator() const
Definition: BFOptimization.cc:87
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
BFOptimization::ii
unsigned int ii() const
Definition: BFOptimization.cc:85
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
DataDependenceGraph.hh
MoveNode
Definition: MoveNode.hh:65
Terminal.hh
MoveNodeDuplicator::duplicateProgramOperationPtr
ProgramOperationPtr duplicateProgramOperationPtr(ProgramOperationPtr old)
Definition: MoveNodeDuplicator.cc:173
ProgramOperationPtr
std::shared_ptr< ProgramOperation > ProgramOperationPtr
Definition: MoveNode.hh:52
assert
#define assert(condition)
Definition: Application.hh:86
TTAProgram::Terminal::operationIndex
virtual int operationIndex() const
Definition: Terminal.cc:364
MoveNode::addDestinationOperationPtr
void addDestinationOperationPtr(ProgramOperationPtr po)
Definition: MoveNode.cc:533
BFShareOperand::operator()
virtual bool operator()()
Definition: BFShareOperand.cc:43
BFShareOperand::createdPrologPOs_
std::set< ProgramOperationPtr > createdPrologPOs_
Definition: BFShareOperand.hh:55
BFShareOperand.hh
MoveNode::destinationOperationCount
unsigned int destinationOperationCount() const
BFShareOperand::undoOnlyMe
virtual void undoOnlyMe()
Definition: BFShareOperand.cc:92
MoveNodeDuplicator::getProgramOperation
ProgramOperationPtr getProgramOperation(ProgramOperationPtr old)
Definition: MoveNodeDuplicator.cc:188
MoveNodeDuplicator.hh
BFShareOperand::shared_
MoveNode & shared_
Definition: BFShareOperand.hh:53
MoveNodeDuplicator::getMoveNode
MoveNode * getMoveNode(MoveNode &mn)
Definition: MoveNodeDuplicator.cc:85
MoveNode::destinationOperationPtr
ProgramOperationPtr destinationOperationPtr(unsigned int index=0) const
MoveNode::move
TTAProgram::Move & move()
MoveNode::removeDestinationOperation
void removeDestinationOperation(const ProgramOperation *po)
Definition: MoveNode.cc:741
Move.hh
BFShareOperand::ops_
std::vector< ProgramOperationPtr > ops_
Definition: BFShareOperand.hh:54
MoveNode.hh