OpenASIP 2.2
Loading...
Searching...
No Matches
SimulationStatistics.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 SimulationStatistics.hh
26 *
27 * Implementation of SimulationStatistics class.
28 *
29 * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30 * @author Henry Linjamäki 2017 (henry.linjamaki-no.spam-tut.fi)
31 * @note rating: red
32 */
33
36#include "Program.hh"
37#include "NullInstruction.hh"
38#include "InstructionMemory.hh"
40
41/**
42 * Constructs a new simulation statistics calculation loop.
43 *
44 * @param programData The program the statistics are calculated from.
45 * @param executionCounts Execution counts of instructions and moves in the
46 * program.
47 */
49 const TTAProgram::Program& programData,
50 const InstructionMemory& executionCounts) :
51 program_(programData), executionCounts_(executionCounts) {
52}
53
54
55/**
56 * Destructor.
57 */
60
61/**
62 * Adds a new statistics type to be included in simulation statistics
63 * calculation.
64 *
65 * @param statisticsType New statistics type.
66 */
67void
69 SimulationStatisticsCalculator& statisticsType) {
70 statisticsTypes_.push_back(&statisticsType);
71}
72
73/**
74 * Calculates simulation statistics by going through the program and
75 * invoking calculate() for all statistics types.
76 */
77void
79
80 if (statisticsTypes_.size() == 0)
81 return;
82
83 const TTAProgram::Instruction* currentInstruction =
85 while (currentInstruction != &TTAProgram::NullInstruction::instance()) {
86
87 // Skip implicit instructions they are processed already (see below).
88 if (currentInstruction->size() == 0) {
89 currentInstruction = &program_.nextInstruction(*currentInstruction);
90 continue;
91 }
92
93 auto instrAddr = currentInstruction->address().location();
94 const ExecutableInstruction& execInstr =
96 if (execInstr.executionCount() == 0) {
97 currentInstruction =
98 &program_.nextInstruction(*currentInstruction);
99 continue;
100 }
101
102 // First process explicit instruction ...
103 for (std::size_t i = 0; i < statisticsTypes_.size(); ++i) {
104 statisticsTypes_[i]->calculateForInstruction(
105 *currentInstruction, execInstr);
106 }
107
108 // ... and then the following implicit instructions.
109 // FIXME: Potential breakage. Can not know if the executable instruction
110 // corresponds to the program instruction. It is now assumed the
111 // execution instructions are created and added to executionCounts_ in
112 // same order as program instructions currently being traversed.
114 *currentInstruction);
115 for (auto& implExecInstr : executionCounts_.implicitInstructionsAt(
116 instrAddr)) {
117 if (implInstr->size() != 0)
118 break;
119 for (std::size_t i = 0; i < statisticsTypes_.size(); ++i) {
120 statisticsTypes_[i]->calculateForInstruction(
121 *implInstr, *implExecInstr);
122 }
123 implInstr = &program_.nextInstruction(*implInstr);
124 }
125 currentInstruction = &program_.nextInstruction(*currentInstruction);
126 }
127}
ClockCycleCount executionCount() const
const InstructionContainer & implicitInstructionsAt(InstructionAddress addr) const
const ExecutableInstruction & instructionAtConst(InstructionAddress address) const
SimulationStatistics(const TTAProgram::Program &programData, const InstructionMemory &executionCounts)
std::vector< SimulationStatisticsCalculator * > statisticsTypes_
All registered statistics types are stored in this container.
const TTAProgram::Program & program_
The program used in calculating the statistics.
const InstructionMemory & executionCounts_
The execution counts of instructions and moves in the program.
void addStatistics(SimulationStatisticsCalculator &statisticsType)
InstructionAddress location() const
Address address() const
static NullInstruction & instance()
Instruction & nextInstruction(const Instruction &) const
Definition Program.cc:403
Address startAddress() const
Definition Program.cc:286
Instruction & instructionAt(InstructionAddress address) const
Definition Program.cc:374