OpenASIP 2.2
Loading...
Searching...
No Matches
BFShareOperandsLate.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 BFShareOperandsLate.cc
27 *
28 * Definition of BFShareOperandsLate class
29 *
30 * After scheduling a move,
31 * Searches for potential operations to share operand with, and
32 * then calls BFShareOperandLate to fo the actual operand sharing.
33 *
34 * @author Heikki Kultala 2014-2020(heikki.kultala-no.spam-tuni.fi)
35 * @note rating: red
36 */
37
38
40#include "Move.hh"
41#include "Terminal.hh"
42#include "MoveNode.hh"
44#include "Instruction.hh"
46#include "BFShareOperandLate.hh"
48
50 BFOptimization(sched), mn_(mn), operandShareDistance_(6) {
53 if (opts != NULL) {
54 if (opts->operandShareDistance() > -1) {
56 }
57 }
58
59}
60
61
63#ifdef DEBUG_BUBBLEFISH_SCHEDULER
64 std::cerr << "\t\tTrying share operands late for: " << mn_.toString()
65 << std::endl;
66#endif
67 TTAProgram::Move& currMove = mn_.move();
68 TTAProgram::Terminal& currDest = currMove.destination();
69 TTAProgram::Terminal& currSrc = currMove.source();
70 if (currSrc.isImmediateRegister() ||
71 currSrc.isFUPort()) {
72 // lets not analyze yet when data in these change
73 return false;
74 }
75
76 if (!currDest.isFUPort() ||
77 currDest.isTriggering() ||
78 currDest.isOpcodeSetting()) {
79#ifdef DEBUG_BUBBLEFISH_SCHEDULER
80 std::cerr << "\t\t\tdest not operand port" << std::endl;
81#endif
82 return false;
83 }
84
85// TTAMachine::RegisterFile* guardRF = NULL;
86// int guardIndex = -1;
87// bool guardInverted = false;
88 if (!currMove.isUnconditional()) {
89 return false;
90 /*
91 TTAMachine::Guard& guard = move.guard().guard();
92 RegisterGuard* rg = dynamic_cast<TTAMachine::RegisterGuard*>(&guard);
93 if (rg) {
94 guardRF = rg->registerFile();
95 guardIndex = rg->registerIndex();
96 guardInverted = rg->isInverted();
97 }
98 */
99 }
100
101
102 int cycle = mn_.cycle();
103 unsigned int idx = rm().instructionIndex(cycle);
104 unsigned int limit = ii() ? std::min(ii(), idx+operandShareDistance_) :
105 std::min((unsigned)rm().largestCycle()+1, idx+operandShareDistance_);
106#ifdef DEBUG_BUBBLEFISH_SCHEDULER
107 std::cerr << "\t\t\tidx: " << idx << " limit:" << limit << std::endl;
108#endif
109 for (unsigned int i = idx; i < limit; i++) {
110 const TTAProgram::Instruction& ins = *rm().instruction(i);
111 for (int j = 0; j < ins.moveCount(); j++) {
112 const TTAProgram::Move& laterMove = ins.move(j);
113 const TTAProgram::Terminal& laterDest = laterMove.destination();
114 if (&laterMove == &currMove) {
115 continue;
116 }
117 if (!laterDest.equals(currDest)) {
118 continue;
119 }
120
121 const TTAProgram::Terminal& laterSrc = laterMove.source();
122 if (laterSrc.equals(currSrc)) {
123 MoveNode& laterNode = ddg().nodeOfMove(laterMove);
124#ifdef DEBUG_BUBBLEFISH_SCHEDULER
125 std::cerr << "\t\t\t\tOriginal scheduled move: " << mn_.toString()
126 << std::endl;
127 std::cerr << "\t\t\t\tLate op sharing Could remove later move: "
128 << laterNode.toString() << std::endl;
129#endif
130 BFShareOperandLate* bfsol =
131 new BFShareOperandLate(sched_,laterNode, mn_);
132 return runPostChild(bfsol);
133 } else {
134#ifdef DEBUG_BUBBLEFISH_SCHEDULER
135 std::cerr << "\t\t\tAnother move overwrites my dest"
136 << ddg().nodeOfMove(laterMove).toString() << std::endl;
137#endif
138 return false;
139 }
140 }
141 for (int j = 0; j < ins.moveCount(); j++) {
142 TTAProgram::Move& laterMove = ins.move(j);
143 TTAProgram::Terminal& laterDest = laterMove.destination();
144 // src is overwritten here
145 if (laterDest.equals(currSrc)) {
146#ifdef DEBUG_BUBBLEFISH_SCHEDULER
147 std::cerr << "\t\t\tOverwrites src: " <<
148 ddg().nodeOfMove(laterMove).toString() << std::endl;
149#endif
150 return false;
151 }
152 }
153 }
154 return false;
155}
156
static CmdLineOptions * cmdLineOptions()
unsigned int ii() const
BF2Scheduler & sched_
DataDependenceGraph & ddg()
SimpleResourceManager & rm() const
BFShareOperandsLate(BF2Scheduler &sched, MoveNode &mn)
MoveNode & nodeOfMove(const TTAProgram::Move &move)
int cycle() const
Definition MoveNode.cc:421
std::string toString() const
Definition MoveNode.cc:576
TTAProgram::Move & move()
bool runPostChild(Reversible *preChild)
virtual int operandShareDistance() const
unsigned int instructionIndex(unsigned int) const
virtual TTAProgram::Instruction * instruction(int cycle) const override
Move & move(int i) const
bool isUnconditional() const
Definition Move.cc:154
Terminal & source() const
Definition Move.cc:302
Terminal & destination() const
Definition Move.cc:323
virtual bool isTriggering() const
Definition Terminal.cc:298
virtual bool isOpcodeSetting() const
Definition Terminal.cc:285
virtual bool equals(const Terminal &other) const =0
virtual bool isImmediateRegister() const
Definition Terminal.cc:97
virtual bool isFUPort() const
Definition Terminal.cc:118