OpenASIP  2.0
StaticProgramAnalyzer.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 StaticProgramAnalyzer.cc
26  *
27  * Implementation of the StaticProgramAnalyzer class.
28  *
29  * @author Jari Mäntyneva 2007 (jari.mantyneva-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include "StaticProgramAnalyzer.hh"
34 #include "Instruction.hh"
35 #include "Move.hh"
36 #include "Terminal.hh"
37 #include "StringTools.hh"
38 #include "DataMemory.hh"
39 #include "DataDefinition.hh"
40 #include "TCEString.hh"
41 #include "MathTools.hh"
42 #include "Program.hh"
43 #include "Operation.hh"
44 
45 using namespace TTAProgram;
46 
47 /**
48  * The constructor.
49  */
51  biggestAddress_(0) {
52 }
53 
54 /**
55  * The destructor.
56  */
58 }
59 
60 /**
61  * Adds a new program to the analyzer and analyzes it. Results are added to
62  * the previously analyzed results.
63  *
64  * @param program Sequential program to be analyzed.
65  */
66 void
68 
69  Instruction* instruction = &program.firstInstruction();
70  Instruction* lastInstruction = &program.lastInstruction();
71  while (instruction != lastInstruction) {
72  for (int i = 0; i < instruction->moveCount(); i++) {
73  Move& move = instruction->move(i);
74  Terminal* source = &move.source();
75  Terminal* destination = &move.destination();
76  if (source->isGPR()) {
77  integerVariables_.insert(source->index());
78  } else if (source->isImmediate()) {
80  source->value().unsignedValue())] += 1;
81  }
82  if (destination->isFUPort()) {
83  if (destination->isOpcodeSetting()) {
84  operations_.insert(
86  destination->operation().name()));
87  }
88  } else if (destination->isGPR()) {
89  integerVariables_.insert(destination->index());
90  }
91 
92  }
93  instruction = &program.nextInstruction(*instruction);
94  }
95  // analyze the needed memory
96  for (int i = 0; i < program.dataMemoryCount(); i++) {
97  DataMemory& dataMemory = program.dataMemory(i);
98  int definitionCount = dataMemory.dataDefinitionCount();
99  DataDefinition& definition =
100  dataMemory.dataDefinition(definitionCount - 1);
101  Address address = definition.startAddress();
102  InstructionAddress instructionAddress = address.location();
103  instructionAddress += definition.size();
104  if (biggestAddress_ < instructionAddress) {
105  biggestAddress_ = instructionAddress;
106  }
107  }
108 }
109 
110 /**
111  * Returns set of operations used in the analyzed programs.
112  *
113  * Operation names in the se are in lower case.
114  *
115  * @return Set of operations used in the analyzed programs.
116  */
117 std::set<std::string>
119  return operations_;
120 }
121 
122 /**
123  * Returns set of register indexes used in the analyzed programs.
124  *
125  * @return Set of register indexes used in the analyzed programs.
126  */
127 std::set<SIntWord>
129  return integerVariables_;
130 }
131 
132 /**
133  * Returns set of immediate bit widths used in the analyzed programs.
134  *
135  * @return Set of immediate bit widths used in the analyzed programs.
136  */
137 std::map<int, int>
139  return immediates_;
140 }
141 
142 /**
143  * Returns the biggest instruction address used in the analyzed programs.
144  *
145  * @return The biggest instruction address.
146  */
149  return biggestAddress_;
150 }
151 
152 
153 /**
154  * Resets the all counters used be the analyzer.
155  */
156 void
158  operations_.clear();
159  integerVariables_.clear();
160 }
TTAProgram::Terminal::isFUPort
virtual bool isFUPort() const
Definition: Terminal.cc:118
TTAProgram
Definition: Estimator.hh:65
TTAProgram::Program
Definition: Program.hh:63
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
StaticProgramAnalyzer::biggestAddress
InstructionAddress biggestAddress() const
Definition: StaticProgramAnalyzer.cc:148
TTAProgram::DataDefinition
Definition: DataDefinition.hh:52
StaticProgramAnalyzer::immediates_
std::map< int, int > immediates_
Set of immediate widths used in the applications.
Definition: StaticProgramAnalyzer.hh:67
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
TTAProgram::Terminal::index
virtual int index() const
Definition: Terminal.cc:274
TTAProgram::Address
Definition: Address.hh:51
TTAProgram::DataDefinition::startAddress
virtual Address startAddress() const
Definition: DataDefinition.cc:129
TTAProgram::DataDefinition::size
virtual int size() const
Definition: DataDefinition.cc:211
TTAProgram::Instruction
Definition: Instruction.hh:57
StaticProgramAnalyzer::resetCounters
void resetCounters()
Definition: StaticProgramAnalyzer.cc:157
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
TTAProgram::DataMemory::dataDefinitionCount
int dataDefinitionCount() const
Definition: DataMemory.cc:129
StaticProgramAnalyzer.hh
Terminal.hh
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
TTAProgram::Terminal::operation
virtual Operation & operation() const
Definition: Terminal.cc:319
TCEString.hh
StringTools.hh
StaticProgramAnalyzer::operations_
std::set< std::string > operations_
Set of operations used in the applications.
Definition: StaticProgramAnalyzer.hh:65
StaticProgramAnalyzer::integerRegisterIndexes
std::set< SIntWord > integerRegisterIndexes() const
Definition: StaticProgramAnalyzer.cc:128
StaticProgramAnalyzer::~StaticProgramAnalyzer
virtual ~StaticProgramAnalyzer()
Definition: StaticProgramAnalyzer.cc:57
Instruction.hh
DataMemory.hh
StaticProgramAnalyzer::StaticProgramAnalyzer
StaticProgramAnalyzer()
Definition: StaticProgramAnalyzer.cc:50
StaticProgramAnalyzer::integerVariables_
std::set< SIntWord > integerVariables_
Set of integer variables used in the applications.
Definition: StaticProgramAnalyzer.hh:63
TTAProgram::Terminal::isGPR
virtual bool isGPR() const
Definition: Terminal.cc:107
Operation.hh
TTAProgram::Terminal::value
virtual SimValue value() const
Definition: Terminal.cc:178
MathTools::requiredBits
static int requiredBits(unsigned long int number)
TTAProgram::Address::location
InstructionAddress location() const
TTAProgram::Move
Definition: Move.hh:55
StaticProgramAnalyzer::addProgram
void addProgram(const TTAProgram::Program &program)
Definition: StaticProgramAnalyzer.cc:67
TTAProgram::Terminal::isOpcodeSetting
virtual bool isOpcodeSetting() const
Definition: Terminal.cc:285
SimValue::unsignedValue
unsigned int unsignedValue() const
Definition: SimValue.cc:919
StaticProgramAnalyzer::immediateBitWidths
std::map< int, int > immediateBitWidths() const
Definition: StaticProgramAnalyzer.cc:138
Program.hh
StaticProgramAnalyzer::operationsUsed
std::set< std::string > operationsUsed() const
Definition: StaticProgramAnalyzer.cc:118
TTAProgram::DataMemory::dataDefinition
DataDefinition & dataDefinition(Address address) const
Definition: DataMemory.cc:79
TTAProgram::Terminal
Definition: Terminal.hh:60
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
MathTools.hh
TTAProgram::DataMemory
Definition: DataMemory.hh:56
Move.hh
TTAProgram::Terminal::isImmediate
virtual bool isImmediate() const
Definition: Terminal.cc:63
DataDefinition.hh
StringTools::stringToLower
static std::string stringToLower(const std::string &source)
Definition: StringTools.cc:160
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
StaticProgramAnalyzer::biggestAddress_
unsigned int biggestAddress_
Memory used by programs.
Definition: StaticProgramAnalyzer.hh:69