OpenASIP  2.0
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 
34 #include "SimulationStatistics.hh"
36 #include "Program.hh"
37 #include "NullInstruction.hh"
38 #include "InstructionMemory.hh"
39 #include "ExecutableInstruction.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  */
59 }
60 
61 /**
62  * Adds a new statistics type to be included in simulation statistics
63  * calculation.
64  *
65  * @param statisticsType New statistics type.
66  */
67 void
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  */
77 void
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 }
SimulationStatistics::addStatistics
void addStatistics(SimulationStatisticsCalculator &statisticsType)
Definition: SimulationStatistics.cc:68
InstructionMemory::instructionAtConst
const ExecutableInstruction & instructionAtConst(InstructionAddress address) const
TTAProgram::Program
Definition: Program.hh:63
ExecutableInstruction
Definition: ExecutableInstruction.hh:49
SimulationStatistics.hh
SimulationStatistics::~SimulationStatistics
virtual ~SimulationStatistics()
Definition: SimulationStatistics.cc:58
TTAProgram::Program::startAddress
Address startAddress() const
Definition: Program.cc:286
ExecutableInstruction::executionCount
ClockCycleCount executionCount() const
Definition: ExecutableInstruction.cc:85
TTAProgram::Program::nextInstruction
Instruction & nextInstruction(const Instruction &) const
Definition: Program.cc:403
InstructionMemory::implicitInstructionsAt
const InstructionContainer & implicitInstructionsAt(InstructionAddress addr) const
Definition: InstructionMemory.cc:128
TTAProgram::Instruction
Definition: Instruction.hh:57
InstructionMemory.hh
SimulationStatistics::calculate
void calculate()
Definition: SimulationStatistics.cc:78
InstructionMemory
Definition: InstructionMemory.hh:54
SimulationStatisticsCalculator
Definition: SimulationStatisticsCalculator.hh:49
TTAProgram::Program::instructionAt
Instruction & instructionAt(InstructionAddress address) const
Definition: Program.cc:374
SimulationStatisticsCalculator.hh
SimulationStatistics::executionCounts_
const InstructionMemory & executionCounts_
The execution counts of instructions and moves in the program.
Definition: SimulationStatistics.hh:64
NullInstruction.hh
TTAProgram::Address::location
InstructionAddress location() const
TTAProgram::NullInstruction::instance
static NullInstruction & instance()
Definition: NullInstruction.cc:66
Program.hh
TTAProgram::Instruction::size
short size() const
Definition: Instruction.cc:365
ExecutableInstruction.hh
SimulationStatistics::program_
const TTAProgram::Program & program_
The program used in calculating the statistics.
Definition: SimulationStatistics.hh:62
SimulationStatistics::SimulationStatistics
SimulationStatistics(const TTAProgram::Program &programData, const InstructionMemory &executionCounts)
Definition: SimulationStatistics.cc:48
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327
SimulationStatistics::statisticsTypes_
std::vector< SimulationStatisticsCalculator * > statisticsTypes_
All registered statistics types are stored in this container.
Definition: SimulationStatistics.hh:60