OpenASIP 2.2
Loading...
Searching...
No Matches
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
44using namespace TTAProgram;
45
46/**
47 * Constructor.
48 */
49BasicBlock::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 */
62
63/**
64 * Creates a deep copy of the basic block.
65 */
68
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 */
87int
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 */
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
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;
132 j++) {
133 TTAProgram::Move& tempMove =
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 */
151void
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 */
171
172/**
173 * Returns move count from statistics object.
174 * @return count of moves stored in object
175 */
176int
180/**
181 * Returns immediate count from statistics object.
182 * @return count of immediates stored in object
183 */
184int
188/**
189 * Returns instruction count from statistics object.
190 * @return count of instructions stored in object
191 */
192int
196/**
197 * Returns bypassed move count from statistics object.
198 * @return count of bypassed moves stored in object
199 */
200int
204/**
205 * Sets the move count in statistic object.
206 *
207 * @param count number of moves to store in object
208 */
209void
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
219void
223/**
224 * Sets the instruction count in statistic object.
225 *
226 * @param count number of instructions to store in object
227 */
228
229void
233/**
234 * Sets the bypassed move count in statistic object.
235 *
236 * @param count number of bypassed moves to store in object
237 */
238void
242
find Finds info of the inner loops in the false
InstructionAddress location() const
virtual int instructionCount() const
virtual void setInstructionCount(int)
virtual void setBypassedCount(int)
virtual int bypassedCount() const
virtual void setImmediateCount(int)
virtual int moveCount() const
virtual int immediateCount() const
BasicBlockStatistics statistics_
virtual void clear()
int skippedFirstInstructions() const
Definition BasicBlock.cc:88
BasicBlock * copy() const
Definition BasicBlock.cc:67
const BasicBlockStatistics & statistics()
void skipFirstInstructions(int count)
Definition BasicBlock.cc:98
BasicBlock(int startAddress=0)
Definition BasicBlock.cc:49
Address startAddr_
The start (lowest) address of the procedure.
virtual void add(Instruction *ins)
virtual int instructionCount() const
virtual Instruction & instructionAtIndex(int index) const
Instruction * copy() const
Move & move(int i) const
Terminal & source() const
Definition Move.cc:302
Terminal & destination() const
Definition Move.cc:323
virtual bool isFUPort() const
Definition Terminal.cc:118