OpenASIP  2.0
BasicBlock.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 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  * @file BasicBlock.cc
26  *
27  * Implementation of graph node (basic block).
28  *
29  * @author Andrea Cilio 2005 (cilio-no.spam-cs.tut.fi)
30  * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include <algorithm>
35 
36 #include "BasicBlock.hh"
37 #include "Exception.hh"
38 #include "Instruction.hh"
39 #include "POMDisassembler.hh"
40 #include "NullAddressSpace.hh"
41 #include "Move.hh"
42 #include "Terminal.hh"
43 
44 using namespace TTAProgram;
45 
46 /**
47  * Constructor.
48  */
49 BasicBlock::BasicBlock(int startAddress) :
50  CodeSnippet(Address(startAddress,
51  TTAMachine::NullAddressSpace::instance())),
52  liveRangeData_(NULL),
53  skippedFirstInstructions_(0),
54  statisticsValid_(false), innerLoop_(false), tripCount_(0) {
55 }
56 
57 /**
58  * To prevent compiler warning of virtual destructor.
59  */
61 }
62 
63 /**
64  * Creates a deep copy of the basic block.
65  */
68 
69  BasicBlock* newBB = new BasicBlock(startAddr_.location());
70  if (instructionCount() > 0) {
71  for (int i = skippedFirstInstructions(); i < instructionCount(); i++) {
72  newBB->add(instructionAtIndex(i).copy());
73  }
74  }
75  return newBB;
76 }
77 
78 
79 /**
80  * Returns the count of instructions in the beginning of this BB that
81  * should not be copied out from this BB, ie. logically don't belong here
82  * but are here because they cannot have been removed without messing
83  * some data structures (like RM bookkeeping)
84  *
85  * @return count of first instructions to skip
86  */
87 int
90 }
91 /**
92  * Sets n first instructions of this BB to be skipped instructions, ie.
93  * instructions that do not logically belong here but are here because cannot
94  * have been removed without messing soem data structures (liek RM bookkeeping)
95  *
96  * @param count number of instructions to mark as skipped instructions
97  */
100 }
101 
102 
103 
104 /**
105  * Updates and returns the statistics about Basic Block
106  *
107  * @return refrence to structure with information about basic block
108  */
109 
110 const BasicBlockStatistics&
112  // hack, statistics should be cached when all the operations that
113  // could change the moves in instructions are taken care of.
114  statisticsValid_ = false;
115  if (statisticsValid_) {
116  return statistics_;
117  } else {
122  for (int i = 0; i < instructionCount(); i++) {
123  int newMoveCount =
125  statistics_.setMoveCount(newMoveCount);
126  int newImmCount =
129  statistics_.setImmediateCount(newImmCount);
130  for (int j = 0;
131  j < instructionAtIndex(i).moveCount();
132  j++) {
133  TTAProgram::Move& tempMove =
134  instructionAtIndex(i).move(j);
135  if (tempMove.source().isFUPort() &&
136  tempMove.destination().isFUPort()) {
137  int newBypassCount = statistics_.bypassedCount() + 1;
138  statistics_.setBypassedCount(newBypassCount);
139  }
140  }
141  }
142  statisticsValid_ = true;
143  return statistics_;
144  }
145 }
146 
147 /**
148  * Trigger recorded statistics about BB invalid and calls clear of
149  * code snippet.
150  */
151 void
153  statisticsValid_ = false;
155 }
156 /**
157  * Constructor, creates statistics structure with zero content.
158  */
160  moveCount_(0),
161  immediateCount_(0),
162  instructionCount_(0),
163  bypassedCount_(0) {
164 }
165 
166 /**
167  * To prevent compiler warning of virtual destructor.
168  */
170 }
171 
172 /**
173  * Returns move count from statistics object.
174  * @return count of moves stored in object
175  */
176 int
178  return moveCount_;
179 }
180 /**
181  * Returns immediate count from statistics object.
182  * @return count of immediates stored in object
183  */
184 int
186  return immediateCount_;
187 }
188 /**
189  * Returns instruction count from statistics object.
190  * @return count of instructions stored in object
191  */
192 int
194  return instructionCount_;
195 }
196 /**
197  * Returns bypassed move count from statistics object.
198  * @return count of bypassed moves stored in object
199  */
200 int
202  return bypassedCount_;
203 }
204 /**
205  * Sets the move count in statistic object.
206  *
207  * @param count number of moves to store in object
208  */
209 void
211  moveCount_ = count;
212 }
213 /**
214  * Sets the immediate count in statistic object.
215  *
216  * @param count number of immediates to store in object
217  */
218 
219 void
221  immediateCount_ = count;
222 }
223 /**
224  * Sets the instruction count in statistic object.
225  *
226  * @param count number of instructions to store in object
227  */
228 
229 void
231  instructionCount_ = count;
232 }
233 /**
234  * Sets the bypassed move count in statistic object.
235  *
236  * @param count number of bypassed moves to store in object
237  */
238 void
240  bypassedCount_ = count;
241 }
242 
TTAProgram::BasicBlockStatistics::bypassedCount_
int bypassedCount_
Definition: BasicBlock.hh:71
TTAProgram::BasicBlockStatistics::setInstructionCount
virtual void setInstructionCount(int)
Definition: BasicBlock.cc:230
TTAProgram::Terminal::isFUPort
virtual bool isFUPort() const
Definition: Terminal.cc:118
TTAProgram
Definition: Estimator.hh:65
TTAProgram::BasicBlock::statistics
const BasicBlockStatistics & statistics()
Definition: BasicBlock.cc:111
TTAProgram::BasicBlockStatistics::moveCount
virtual int moveCount() const
Definition: BasicBlock.cc:177
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
TTAProgram::Address
Definition: Address.hh:51
Exception.hh
TTAProgram::CodeSnippet::clear
virtual void clear()
Definition: CodeSnippet.cc:89
TTAProgram::BasicBlockStatistics::moveCount_
int moveCount_
Definition: BasicBlock.hh:68
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
TTAProgram::BasicBlockStatistics::setImmediateCount
virtual void setImmediateCount(int)
Definition: BasicBlock.cc:220
TTAProgram::BasicBlockStatistics::instructionCount_
int instructionCount_
Definition: BasicBlock.hh:70
Terminal.hh
TTAProgram::BasicBlock::copy
BasicBlock * copy() const
Definition: BasicBlock.cc:67
TTAProgram::BasicBlock::statistics_
BasicBlockStatistics statistics_
Definition: BasicBlock.hh:117
TTAProgram::BasicBlockStatistics::setBypassedCount
virtual void setBypassedCount(int)
Definition: BasicBlock.cc:239
POMDisassembler.hh
TTAProgram::BasicBlockStatistics
Definition: BasicBlock.hh:55
TTAProgram::BasicBlock::skippedFirstInstructions
int skippedFirstInstructions() const
Definition: BasicBlock.cc:88
TTAProgram::BasicBlock::skipFirstInstructions
void skipFirstInstructions(int count)
Definition: BasicBlock.cc:98
Instruction.hh
TTAProgram::CodeSnippet::instructionCount
virtual int instructionCount() const
Definition: CodeSnippet.cc:205
TTAProgram::BasicBlockStatistics::immediateCount
virtual int immediateCount() const
Definition: BasicBlock.cc:185
TTAProgram::CodeSnippet::add
virtual void add(Instruction *ins)
Definition: CodeSnippet.cc:432
TTAProgram::Instruction::copy
Instruction * copy() const
Definition: Instruction.cc:379
TTAProgram::BasicBlockStatistics::immediateCount_
int immediateCount_
Definition: BasicBlock.hh:69
NullAddressSpace.hh
TTAProgram::BasicBlockStatistics::BasicBlockStatistics
BasicBlockStatistics()
Definition: BasicBlock.cc:159
TTAProgram::BasicBlock::BasicBlock
BasicBlock(int startAddress=0)
Definition: BasicBlock.cc:49
TTAProgram::Address::location
InstructionAddress location() const
TTAProgram::Move
Definition: Move.hh:55
TTAProgram::BasicBlock::statisticsValid_
bool statisticsValid_
Definition: BasicBlock.hh:116
TTAProgram::CodeSnippet
Definition: CodeSnippet.hh:59
TTAProgram::BasicBlockStatistics::setMoveCount
virtual void setMoveCount(int)
Definition: BasicBlock.cc:210
TTAProgram::BasicBlock
Definition: BasicBlock.hh:85
TTAProgram::BasicBlock::skippedFirstInstructions_
int skippedFirstInstructions_
Definition: BasicBlock.hh:115
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
TTAProgram::BasicBlockStatistics::~BasicBlockStatistics
virtual ~BasicBlockStatistics()
Definition: BasicBlock.cc:169
BasicBlock.hh
TTAProgram::Instruction::immediateCount
int immediateCount() const
Definition: Instruction.cc:267
TTAProgram::CodeSnippet::instructionAtIndex
virtual Instruction & instructionAtIndex(int index) const
Definition: CodeSnippet.cc:285
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
TTAProgram::BasicBlockStatistics::bypassedCount
virtual int bypassedCount() const
Definition: BasicBlock.cc:201
TTAProgram::BasicBlockStatistics::instructionCount
virtual int instructionCount() const
Definition: BasicBlock.cc:193
TTAProgram::BasicBlock::~BasicBlock
virtual ~BasicBlock()
Definition: BasicBlock.cc:60
TTAProgram::BasicBlock::clear
virtual void clear()
Definition: BasicBlock.cc:152
Move.hh
TTAMachine
Definition: Assembler.hh:48
TTAProgram::CodeSnippet::startAddr_
Address startAddr_
The start (lowest) address of the procedure.
Definition: CodeSnippet.hh:130
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176