OpenASIP 2.2
Loading...
Searching...
No Matches
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
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
45using namespace TTAProgram;
46
47/**
48 * The constructor.
49 */
51 biggestAddress_(0) {
52}
53
54/**
55 * The destructor.
56 */
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 */
66void
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 */
117std::set<std::string>
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 */
127std::set<SIntWord>
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 */
137std::map<int, int>
141
142/**
143 * Returns the biggest instruction address used in the analyzed programs.
144 *
145 * @return The biggest instruction address.
146 */
151
152
153/**
154 * Resets the all counters used be the analyzer.
155 */
156void
UInt32 InstructionAddress
Definition BaseType.hh:175
find Finds info of the inner loops in the program
static int requiredBits(unsigned long int number)
virtual TCEString name() const
Definition Operation.cc:93
unsigned int unsignedValue() const
Definition SimValue.cc:919
std::map< int, int > immediates_
Set of immediate widths used in the applications.
std::map< int, int > immediateBitWidths() const
InstructionAddress biggestAddress() const
std::set< std::string > operationsUsed() const
void addProgram(const TTAProgram::Program &program)
unsigned int biggestAddress_
Memory used by programs.
std::set< SIntWord > integerRegisterIndexes() const
std::set< SIntWord > integerVariables_
Set of integer variables used in the applications.
std::set< std::string > operations_
Set of operations used in the applications.
static std::string stringToLower(const std::string &source)
InstructionAddress location() const
virtual Address startAddress() const
DataDefinition & dataDefinition(Address address) const
Definition DataMemory.cc:79
int dataDefinitionCount() const
Move & move(int i) const
Terminal & source() const
Definition Move.cc:302
Terminal & destination() const
Definition Move.cc:323
virtual SimValue value() const
Definition Terminal.cc:178
virtual int index() const
Definition Terminal.cc:274
virtual bool isOpcodeSetting() const
Definition Terminal.cc:285
virtual Operation & operation() const
Definition Terminal.cc:319
virtual bool isGPR() const
Definition Terminal.cc:107
virtual bool isImmediate() const
Definition Terminal.cc:63
virtual bool isFUPort() const
Definition Terminal.cc:118