OpenASIP 2.2
Loading...
Searching...
No Matches
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"
40#include "BF2Scheduler.hh"
41#include "Move.hh"
42
43#include "POMDisassembler.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();
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
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}
#define assert(condition)
void nodeResurrected(MoveNode &mn)
void nodeAndCopyKilled(MoveNode &mn)
unsigned int ii() const
BF2Scheduler & sched_
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)
SimpleResourceManager * prologRM() const
DataDependenceGraph & ddg()
virtual void unassign(MoveNode &mn, bool disposePrologCopy=true)
MoveNodeDuplicator & duplicator() const
SimpleResourceManager & rm() const
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)
const TTAMachine::ImmediateUnit * removedImmu_
const TTAMachine::ImmediateUnit * sharedImmu_
const TTAMachine::Bus * originalSharedBus_
const TTAMachine::Bus * originalRemovedBus_
const TTAMachine::Bus * originalSharedPrologBus_
const TTAMachine::Bus * originalRemovedPrologBus_
virtual bool operator()()
MoveNode & removed_
MoveNode & shared_
virtual void undoOnlyMe()
void restoreNodeFromParent(GraphNode &node)
virtual void dropNode(Node &node)
MoveNode * getMoveNode(MoveNode &mn)
int cycle() const
Definition MoveNode.cc:421
std::string toString() const
Definition MoveNode.cc:576
TTAProgram::Move & move()
ProgramOperation & destinationOperation(unsigned int index=0) const
static std::string disassemble(const TTAProgram::Move &move)
MoveNode * triggeringMove() const
std::string toString() const
bool runPostChild(Reversible *preChild)
virtual TTAProgram::Instruction * instruction(int cycle) const override
virtual int immediateWriteCycle(const MoveNode &) const
virtual TCEString name() const
Move & move(int i) const
Terminal & source() const
Definition Move.cc:302
const TTAMachine::Bus & bus() const
Definition Move.cc:373
virtual int index() const
Definition Terminal.cc:274
virtual bool isImmediateRegister() const
Definition Terminal.cc:97
virtual const TTAMachine::ImmediateUnit & immediateUnit() const
Definition Terminal.cc:240