OpenASIP  2.0
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 
39 #include "BFShareOperandsLate.hh"
40 #include "Move.hh"
41 #include "Terminal.hh"
42 #include "MoveNode.hh"
43 #include "SimpleResourceManager.hh"
44 #include "Instruction.hh"
45 #include "DataDependenceGraph.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 
158 
159 }
TTAProgram::Terminal::isFUPort
virtual bool isFUPort() const
Definition: Terminal.cc:118
TTAProgram::Terminal::isTriggering
virtual bool isTriggering() const
Definition: Terminal.cc:298
BFShareOperandLate
Definition: BFShareOperandLate.hh:46
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
BFOptimization::ii
unsigned int ii() const
Definition: BFOptimization.cc:85
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
DataDependenceGraph.hh
MoveNode
Definition: MoveNode.hh:65
BFShareOperandsLate::undoOnlyMe
virtual void undoOnlyMe()
Definition: BFShareOperandsLate.cc:157
BFOptimization
Definition: BFOptimization.hh:73
Terminal.hh
SchedulerCmdLineOptions
Definition: SchedulerCmdLineOptions.hh:45
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
SchedulerCmdLineOptions.hh
BFShareOperandsLate::BFShareOperandsLate
BFShareOperandsLate(BF2Scheduler &sched, MoveNode &mn)
Definition: BFShareOperandsLate.cc:49
BFShareOperandsLate::operator()
virtual bool operator()()
Definition: BFShareOperandsLate.cc:62
TTAProgram::Terminal::isImmediateRegister
virtual bool isImmediateRegister() const
Definition: Terminal.cc:97
MoveNode::cycle
int cycle() const
Definition: MoveNode.cc:421
Instruction.hh
BFShareOperandsLate::operandShareDistance_
int operandShareDistance_
Definition: BFShareOperandsLate.hh:50
Application::cmdLineOptions
static CmdLineOptions * cmdLineOptions()
Definition: Application.cc:397
DataDependenceGraph::nodeOfMove
MoveNode & nodeOfMove(const TTAProgram::Move &move)
Definition: DataDependenceGraph.cc:3600
BF2Scheduler
Definition: BF2Scheduler.hh:74
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
TTAProgram::Move
Definition: Move.hh:55
BFShareOperandsLate::mn_
MoveNode & mn_
Definition: BFShareOperandsLate.hh:49
BFOptimization::rm
SimpleResourceManager & rm() const
Definition: BFOptimization.cc:76
TTAProgram::Terminal::isOpcodeSetting
virtual bool isOpcodeSetting() const
Definition: Terminal.cc:285
SimpleResourceManager::instructionIndex
unsigned int instructionIndex(unsigned int) const
Definition: SimpleResourceManager.cc:534
MoveNode::move
TTAProgram::Move & move()
TTAProgram::Terminal
Definition: Terminal.hh:60
SimpleResourceManager.hh
TTAProgram::Terminal::equals
virtual bool equals(const Terminal &other) const =0
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
Move.hh
MoveNode.hh
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
SchedulerCmdLineOptions::operandShareDistance
virtual int operandShareDistance() const
Definition: SchedulerCmdLineOptions.cc:336
BFShareOperandLate.hh
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
BFShareOperandsLate.hh
SimpleResourceManager::instruction
virtual TTAProgram::Instruction * instruction(int cycle) const override
Definition: SimpleResourceManager.cc:442