OpenASIP 2.2
Loading...
Searching...
No Matches
RFAccessTracker.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 RFAccessTracker.cc
26 *
27 * Definition of RFAccessTracker class.
28 *
29 * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include "RFAccessTracker.hh"
34#include "Application.hh"
35#include "SimulatorToolbox.hh"
37#include "SimulatorFrontend.hh"
38#include "InstructionMemory.hh"
40#include "Machine.hh"
41#include "Instruction.hh"
42#include "Move.hh"
43#include "MapTools.hh"
44#include "Terminal.hh"
45#include "hash_map.hh"
46#include "NullInstruction.hh"
47#include "Program.hh"
48#include "boost/tuple/tuple_comparison.hpp"
49
50#include <algorithm>
51#include <vector>
52#include <string>
53#include <iostream>
54#include <iomanip>
55
56/**
57 * Constructor.
58 *
59 * @param frontend The SimulationFrontend which is used to access simulation
60 * data.
61 * @param instructions Used to fetch instruction execution counts.
62 */
64 SimulatorFrontend& frontend,
65 const InstructionMemory& instructions) :
66 frontend_(frontend), instructionExecutions_(instructions) {
71}
72
73/**
74 * Destructor.
75 */
82
83/**
84 * Counts the concurrent register file accesses of current clock cycle.
85 */
86void
88
90
91 // create a final sum stats which includes the conditional and unconditional
92 // executions
93
94 totalAccesses_.clear();
95
97 const TTAProgram::Instruction* currentInstruction =
98 &program.instructionAt(program.startAddress().location());
99 while (currentInstruction !=
101
102 const ExecutableInstruction& execInstruction =
104 currentInstruction->address().location());
105
106 if (!currentInstruction->hasRegisterAccesses() ||
107 currentInstruction->hasConditionalRegisterAccesses() ||
108 execInstruction.executionCount() == 0) {
109 currentInstruction = &program.nextInstruction(*currentInstruction);
110 continue;
111 }
112
113 accessesInInstruction_.clear();
114
115 for (int i = 0; i < currentInstruction->moveCount(); ++i) {
116 const TTAProgram::Move& move = currentInstruction->move(i);
117 if (move.source().isGPR()) {
119 move.source().registerFile().name().c_str()].get<1>();
120 }
121
122 if (move.destination().isGPR()) {
124 move.destination().registerFile().name().c_str()].
125 get<0>();
126 }
127 }
128
129 for (RFAccessIndex::iterator i = accessesInInstruction_.begin();
130 i != accessesInInstruction_.end(); ++i) {
131
133 (*i).first, (*i).second.get<0>(), (*i).second.get<1>());
134 totalAccesses_[key] += execInstruction.executionCount();
135 }
136
137 currentInstruction = &program.nextInstruction(*currentInstruction);
138 }
139
140 // add the access data of the instruction with the conditional accesses
141 ConcurrentRFAccessIndex::iterator i = conditionalAccesses_.begin();
142 for (; i != conditionalAccesses_.end(); ++i) {
143 ConcurrentRFAccess key = (*i).first;
145 }
146
147 } else if (event == SimulationEventHandler::SE_CYCLE_END) {
148
149 const InstructionAddress& address =
151 const TTAProgram::Instruction& instruction =
153 if (!instruction.hasConditionalRegisterAccesses())
154 return;
155
157
158 const ExecutableInstruction& execInstruction =
160
161 for (int i = 0; i < instruction.moveCount(); ++i) {
162 if (execInstruction.moveSquashed(i))
163 continue;
164 const TTAProgram::Move& move = instruction.move(i);
165 if (move.source().isGPR()) {
167 move.source().registerFile().name().c_str()].get<1>();
168 }
169
170 if (move.destination().isGPR()) {
172 move.destination().registerFile().name().c_str()].get<0>();
173 }
174 }
175
176 for (RFAccessIndex::iterator i = accessesInInstruction_.begin();
177 i != accessesInInstruction_.end(); ++i) {
178 ++conditionalAccesses_[boost::make_tuple(
179 (*i).first, (*i).second.get<0>(),
180 (*i).second.get<1>())];
181 }
182 } else {
183 abortWithError("RFAccessTracker received an unknown event.");
184 }
185}
186
187/**
188 * Returns the count of clock cycles in which the given register file was
189 * written and read concurrently the given times.
190 *
191 * @param rfName Name of the register file.
192 * @param concurrentWrites Count of concurrent writes.
193 * @param concurrentReads Count of concurrent reads.
194 * @return The count of cycles in which the given count of concurrent accesses
195 * was made to the given register file.
196 */
199 const std::string& rfName,
200 std::size_t concurrentWrites,
201 std::size_t concurrentReads) const {
202 try {
204 totalAccesses_, boost::make_tuple(
205 rfName, concurrentWrites, concurrentReads));
206 } catch (const Exception& e) {
207 return 0;
208 }
209}
210
211/**
212 * Returns the access data base.
213 *
214 * In case statistics are not up-to-date, finalizes the calculation before
215 * returning the index.
216 *
217 * @return The access data base.
218 */
223
#define abortWithError(message)
UInt32 InstructionAddress
Definition BaseType.hh:175
find Finds info of the inner loops in the program
CycleCount ClockCycleCount
Alias for ClockCycleCount.
ClockCycleCount executionCount() const
bool moveSquashed(std::size_t moveIndex) const
virtual bool unregisterListener(int event, Listener *listener)
Definition Informer.cc:104
virtual bool registerListener(int event, Listener *listener)
Definition Informer.cc:87
const ExecutableInstruction & instructionAtConst(InstructionAddress address) const
virtual void handleEvent()
Definition Listener.cc:70
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)
boost::tuple< std::string, std::size_t, std::size_t > ConcurrentRFAccess
type to be used as a key for storing concurrent access info
RFAccessIndex accessesInInstruction_
container used in collecting register accesses in an instruction
SimulatorFrontend & frontend_
the simulator frontend used to access simulation data
ClockCycleCount concurrentRegisterFileAccessCount(const std::string &rfName, std::size_t concurrentWrites, std::size_t concurrentReads) const
const ConcurrentRFAccessIndex & accessDataBase() const
ConcurrentRFAccessIndex totalAccesses_
total (conditional + unconditional) register file accesses are counted in this container
RFAccessTracker(SimulatorFrontend &frontend, const InstructionMemory &instructions)
ConcurrentRFAccessIndex conditionalAccesses_
conditional register file accesses are counted in this container
std::map< ConcurrentRFAccess, ClockCycleCount > ConcurrentRFAccessIndex
concurrent accesses and their counts
const InstructionMemory & instructionExecutions_
used to access instruction execution data
virtual ~RFAccessTracker()
@ SE_CYCLE_END
Generated before advancing the simulator clock at the end of a simulation cycle.
@ SE_SIMULATION_STOPPED
Generated after simulation has stopped, temporarily or permantently, and control is being returned to...
SimulationEventHandler & eventHandler()
virtual InstructionAddress lastExecutedInstruction(int coreId=-1) const
const TTAProgram::Program & program() const
virtual TCEString name() const
InstructionAddress location() const
Move & move(int i) const
Address address() const
bool hasConditionalRegisterAccesses() const
bool hasRegisterAccesses() const
Terminal & source() const
Definition Move.cc:302
Terminal & destination() const
Definition Move.cc:323
static NullInstruction & instance()
Instruction & instructionAt(InstructionAddress address) const
Definition Program.cc:374
virtual bool isGPR() const
Definition Terminal.cc:107
virtual const TTAMachine::RegisterFile & registerFile() const
Definition Terminal.cc:225