OpenASIP  2.0
BFShareOperandLate.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 BFShareOperandLate.cc
27  *
28  * Definition of BFShareOperandLate class.
29  *
30  * Performs an operands sharing between two (or more) operations,
31  * after already scheduling these operations.
32  *
33  * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
34  * @note rating: red
35  */
36 
37 #include "BFShareOperandLate.hh"
38 #include "MoveNode.hh"
39 #include "DataDependenceGraph.hh"
40 #include "BF2Scheduler.hh"
41 #include "Move.hh"
42 
43 #include "POMDisassembler.hh"
44 #include "SimpleResourceManager.hh"
45 #include "Instruction.hh"
46 #include "Move.hh"
47 #include "Bus.hh"
48 #include "MoveNodeDuplicator.hh"
49 #include "Terminal.hh"
51 
53 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
54  std::cerr << "Sharing oeprand late: removing: " << removed_.toString()
55  << " shared: " << shared_.toString() << std::endl;
56 #endif
60 
65  }
66 
71  }
72 
73  MoveNode* removedPrologMN = ii() ? duplicator().getMoveNode(removed_) : NULL;
74  if (removedPrologMN != NULL) {
75  originalRemovedPrologBus_ = &removedPrologMN->move().bus();
76  if (removedPrologMN->move().source().isImmediateRegister()) {
78  prologRM()->immediateWriteCycle(*removedPrologMN);
79  }
80  }
81  MoveNode* sharedPrologMN = ii() ? duplicator().getMoveNode(shared_) : NULL;
82  if (sharedPrologMN != NULL) {
83  originalSharedPrologBus_ = &sharedPrologMN->move().bus();
84  if (sharedPrologMN->move().source().isImmediateRegister()) {
86  prologRM()->immediateWriteCycle(*sharedPrologMN);
87  }
88  }
89 
90  int cycle = shared_.cycle();
91  MoveNode* removedOpTrigger = removed_.destinationOperation().triggeringMove();
92 
93  unassign(shared_, false);
94  unassign(removed_, false);
97  if (BFShareOperand::operator()()) {
98  if (canAssign(cycle, shared_)) {
99  assign(cycle, shared_);
100 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
101  std::cerr << "\t\t\t\tShare operand late OK for: "
102  << shared_.toString() << std::endl;
103  std::cerr << "\t\t\t\tRescheduling trigger closer:"
104  << removedOpTrigger->toString() << std::endl;
105 #endif
106 
107  auto resched =
108  new BFRescheduleResultClose(sched_, *removedOpTrigger, 0);
109 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
110  if (runPostChild(resched)) {
111  std::cerr << "\t\t\tRescheduled trigger closer." << std::endl;
112  }
113 #else
114  runPostChild(resched);
115 #endif
116  return true;
117  } else {
118 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
119  std::cerr << "\t\t\t\tShare operand late FAIL on assign for: "
120  << shared_.toString() << std::endl;
121 #endif
123  revert(cycle);
124  return false;
125  }
126  } else {
127  revert(cycle);
128  return false;
129  }
130 }
131 
133  int cycle = shared_.cycle();
134  unassign(shared_, false);
136  revert(cycle);
137 }
138 
139 void BFShareOperandLate::revert(int cycle) {
140 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
141  assert(
142  canAssign(
143  cycle, shared_, originalSharedBus_, NULL, NULL,
147 
148 #endif
149  assign(cycle, shared_, originalSharedBus_, NULL, NULL,
153 
156 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
158  NULL, NULL, originalRemovedPrologBus_,
161  std::cerr << "Cannot return to original: " << removed_.toString()
162  << std::endl
163  << "dest PO: " << removed_.destinationOperation().toString()
164  << std::endl
165  << "original cycle: " << originalCycle_ << std::endl;
167  for (int i = 0; i < ins->moveCount(); i++) {
168  TTAProgram::Move& m = ins->move(i);
169  std::cerr << "\t" << POMDisassembler::disassemble(m)
170  << " bus: " << m.bus().name() << std::endl;
171  }
172  assert(false);
173  }
174 #endif
176  NULL, NULL, originalRemovedPrologBus_,
179 }
BFShareOperandLate::originalCycle_
int originalCycle_
Definition: BFShareOperandLate.hh:69
BFShareOperand::removed_
MoveNode & removed_
Definition: BFShareOperand.hh:52
SimpleResourceManager::immediateWriteCycle
virtual int immediateWriteCycle(const MoveNode &) const
Definition: SimpleResourceManager.cc:520
BFOptimization::unassign
virtual void unassign(MoveNode &mn, bool disposePrologCopy=true)
Definition: BFOptimization.cc:196
BFOptimization::assign
virtual bool assign(int cycle, MoveNode &, 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 ignoreGuardWriteCycle=false)
Definition: BFOptimization.cc:103
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
BFOptimization::duplicator
MoveNodeDuplicator & duplicator() const
Definition: BFOptimization.cc:87
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
TTAProgram::Terminal::index
virtual int index() const
Definition: Terminal.cc:274
BFShareOperandLate::undoOnlyMe
virtual void undoOnlyMe()
Definition: BFShareOperandLate.cc:132
BFOptimization::ii
unsigned int ii() const
Definition: BFOptimization.cc:85
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::Move::bus
const TTAMachine::Bus & bus() const
Definition: Move.cc:373
DataDependenceGraph.hh
MoveNode
Definition: MoveNode.hh:65
Terminal.hh
BoostGraph::dropNode
virtual void dropNode(Node &node)
ProgramOperation::triggeringMove
MoveNode * triggeringMove() const
Definition: ProgramOperation.cc:643
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
POMDisassembler.hh
BFShareOperandLate::sharedImmWriteCycle_
int sharedImmWriteCycle_
Definition: BFShareOperandLate.hh:80
assert
#define assert(condition)
Definition: Application.hh:86
BFShareOperandLate::originalRemovedPrologBus_
const TTAMachine::Bus * originalRemovedPrologBus_
Definition: BFShareOperandLate.hh:72
TTAProgram::Terminal::isImmediateRegister
virtual bool isImmediateRegister() const
Definition: Terminal.cc:97
BFShareOperandLate::removedImmu_
const TTAMachine::ImmediateUnit * removedImmu_
Definition: BFShareOperandLate.hh:77
MoveNode::cycle
int cycle() const
Definition: MoveNode.cc:421
BFOptimization::prologRM
SimpleResourceManager * prologRM() const
Definition: BFOptimization.cc:77
BF2Scheduler.hh
Instruction.hh
BFRescheduleResultClose
Definition: BFRescheduleResultClose.hh:44
BF2Scheduler::nodeAndCopyKilled
void nodeAndCopyKilled(MoveNode &mn)
Definition: BF2Scheduler.cc:803
BFShareOperandLate::removedImmWriteCycle_
int removedImmWriteCycle_
Definition: BFShareOperandLate.hh:75
BFShareOperandLate::sharedPrologImmWriteCycle_
int sharedPrologImmWriteCycle_
Definition: BFShareOperandLate.hh:81
BFShareOperandLate::removedPrologImmWriteCycle_
int removedPrologImmWriteCycle_
Definition: BFShareOperandLate.hh:76
TTAProgram::Terminal::immediateUnit
virtual const TTAMachine::ImmediateUnit & immediateUnit() const
Definition: Terminal.cc:240
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
TTAProgram::Move
Definition: Move.hh:55
BFRescheduleResultClose.hh
Bus.hh
BFShareOperandLate::originalSharedBus_
const TTAMachine::Bus * originalSharedBus_
Definition: BFShareOperandLate.hh:71
BFShareOperand::undoOnlyMe
virtual void undoOnlyMe()
Definition: BFShareOperand.cc:92
BFOptimization::rm
SimpleResourceManager & rm() const
Definition: BFOptimization.cc:76
MoveNodeDuplicator.hh
BFShareOperandLate::originalSharedPrologBus_
const TTAMachine::Bus * originalSharedPrologBus_
Definition: BFShareOperandLate.hh:73
BFShareOperand::shared_
MoveNode & shared_
Definition: BFShareOperand.hh:53
MoveNodeDuplicator::getMoveNode
MoveNode * getMoveNode(MoveNode &mn)
Definition: MoveNodeDuplicator.cc:85
MoveNode::destinationOperation
ProgramOperation & destinationOperation(unsigned int index=0) const
MoveNode::move
TTAProgram::Move & move()
ProgramOperation::toString
std::string toString() const
Definition: ProgramOperation.cc:746
POMDisassembler::disassemble
static std::string disassemble(const TTAProgram::Move &move)
Definition: POMDisassembler.cc:629
BFShareOperandLate::operator()
virtual bool operator()()
Definition: BFShareOperandLate.cc:52
BF2Scheduler::nodeResurrected
void nodeResurrected(MoveNode &mn)
Definition: BF2Scheduler.cc:811
BFShareOperandLate::sharedImmu_
const TTAMachine::ImmediateUnit * sharedImmu_
Definition: BFShareOperandLate.hh:82
BFShareOperandLate::originalRemovedBus_
const TTAMachine::Bus * originalRemovedBus_
Definition: BFShareOperandLate.hh:70
BFShareOperandLate::revert
void revert(int cycle)
Definition: BFShareOperandLate.cc:139
BFShareOperandLate::removedImmRegIndex_
int removedImmRegIndex_
Definition: BFShareOperandLate.hh:78
SimpleResourceManager.hh
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
Move.hh
MoveNode.hh
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
BFShareOperandLate::sharedImmRegIndex_
int sharedImmRegIndex_
Definition: BFShareOperandLate.hh:83
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
BFShareOperandLate.hh
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
SimpleResourceManager::instruction
virtual TTAProgram::Instruction * instruction(int cycle) const override
Definition: SimpleResourceManager.cc:442
BoostGraph::restoreNodeFromParent
void restoreNodeFromParent(GraphNode &node)