gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
looppoint_analysis.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __CPU_SIMPLE_PROBES_LOOPPOINT_ANALYSIS_HH__
30#define __CPU_SIMPLE_PROBES_LOOPPOINT_ANALYSIS_HH__
31
32// C++ includes
33#include <list>
34#include <unordered_map>
35#include <unordered_set>
36
37// m5 includes
40#include "cpu/simple_thread.hh"
41#include "sim/sim_exit.hh"
42
43// class includes
44#include "debug/LooppointAnalysis.hh"
45#include "params/LooppointAnalysis.hh"
46#include "params/LooppointAnalysisManager.hh"
47
48namespace gem5
49{
50
52{
53 public:
54 LooppointAnalysis(const LooppointAnalysisParams &params);
55
56 virtual void regProbeListeners();
57
66
72 void startListening();
73
78 void stopListening();
79
82
83 private:
84
90
97
103
108
114
120
125 std::unordered_map<Addr, uint64_t> localBBV;
126
132 void updateLocalBBV(const Addr pc);
133
134 public:
135 std::unordered_map<Addr, uint64_t>
137 {
138 return localBBV;
139 };
140
141 void
143 {
144 localBBV.clear();
145 };
146};
147
149{
150 public:
151 LooppointAnalysisManager(const LooppointAnalysisManagerParams &params);
152
158 void countBackwardBranch(const Addr pc);
159
165 void updateGlobalBBV(const Addr pc);
166
167 private:
174 std::unordered_map<Addr, uint64_t> backwardBranchCounter;
175
183 std::unordered_map<Addr, uint64_t> globalBBV;
184
191 std::unordered_map<Addr, uint64_t> bbInstMap;
192
199 uint64_t regionLength;
200
207
213
218 std::unordered_set<Addr> validNotControlPC;
223 std::unordered_set<Addr> validControlPC;
228 std::unordered_set<Addr> encounteredPC;
229
230 public:
231 bool
233 {
234 return backwardBranchCounter.find(pc) != backwardBranchCounter.end();
235 };
236
237 bool
239 {
240 return validNotControlPC.find(pc) != validNotControlPC.end();
241 };
242
243 bool
244 ifValidControl(const Addr pc) const
245 {
246 return validControlPC.find(pc) != validControlPC.end();
247 };
248
249 bool
250 ifEncountered(const Addr pc) const
251 {
252 return encounteredPC.find(pc) != encounteredPC.end();
253 };
254
255 void
257 {
258 validNotControlPC.insert(pc);
259 };
260
261 void
263 {
264 validControlPC.insert(pc);
265 };
266
267 void
269 {
270 encounteredPC.insert(pc);
271 };
272
273 void
274 updateBBInstMap(Addr pc, uint64_t inst_ount)
275 {
276 if (bbInstMap.find(pc) == bbInstMap.end())
277 {
278 bbInstMap.insert(std::make_pair(pc, inst_ount));
279 }
280 };
281
282 std::unordered_map<Addr, uint64_t> getBBInstMap() const
283 {
284 return bbInstMap;
285 };
286
287 std::unordered_map<Addr, uint64_t>
289 {
290 return globalBBV;
291 };
292
293 void
295 {
296 globalBBV.clear();
297 DPRINTF(LooppointAnalysis,"globalBBV is cleared\n");
298 };
299
300 uint64_t
302 {
303 return globalInstCounter;
304 };
305
306 void
308 {
310 DPRINTF(LooppointAnalysis,"globalInstCounter is cleared\n current "
311 "globalInstCounter = %lu\n", globalInstCounter);
312 };
313
314 void
319
320 Addr
325
326 std::unordered_map<Addr, uint64_t>
328 {
330 };
331
332 uint64_t
337};
338
339} // namespace gem5
340
341
342
343
344#endif // __CPU_SIMPLE_PROBES_LOOPPOINT_ANALYSIS_HH__
#define DPRINTF(x,...)
Definition trace.hh:209
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition addr_range.hh:82
void updateGlobalBBV(const Addr pc)
This function is called by the LooppointAnalysis probe listener when it reaches the branch instructio...
void updateValidNotControl(const Addr pc)
Addr mostRecentBackwardBranchPC
This variable stores the Program Counter address of the most recent valid backward branch that we con...
std::unordered_map< Addr, uint64_t > backwardBranchCounter
This counter is for the valid backward branches that we consider as candidates for marking the execut...
std::unordered_map< Addr, uint64_t > getGlobalBBV() const
bool ifEncountered(const Addr pc) const
void countBackwardBranch(const Addr pc)
This function is called by the LooppointAnalysis probe listener when it finds a valid backward branch...
uint64_t getMostRecentBackwardBranchCount() const
uint64_t globalInstCounter
This is a counter for the globally executed instructions.
bool ifBackwardBranch(const Addr pc) const
std::unordered_map< Addr, uint64_t > globalBBV
This is the global basic block vector that contains the count of each basic block that is executed.
std::unordered_set< Addr > encounteredPC
This set stores the Program Counter addresses of the encountered instructions.
bool ifValidControl(const Addr pc) const
bool ifValidNotControl(const Addr pc) const
void updateBBInstMap(Addr pc, uint64_t inst_ount)
std::unordered_map< Addr, uint64_t > getBBInstMap() const
uint64_t regionLength
This variable stores the number of instructions that we used to define a region.
std::unordered_map< Addr, uint64_t > getBackwardBranchCounter() const
std::unordered_map< Addr, uint64_t > bbInstMap
This map stores the number of instructions in each basic block.
std::unordered_set< Addr > validControlPC
This set stores the Program Counter addresses of the valid control instructions.
std::unordered_set< Addr > validNotControlPC
This set stores the Program Counter addresses of the valid not control instructions.
std::vector< AddrRange > bbExcludedAddrRanges
Any basic block that is in this range will not be analyzed.
virtual void regProbeListeners()
Register probe listeners for this object.
void stopListening()
When this function is called, it sets the class variable ifListening to false, then removes the probe...
AddrRange markerValidAddrRange
We only consider the loops within this address range as candidates for marking the execution points.
void updateLocalBBV(const Addr pc)
This function updates the localBBV for the input PC's basic block.
uint64_t bbInstCounter
The counter for the number of instructions within the current basic block.
LooppointAnalysisManager * lpaManager
This is the pointer to the LooppointAnalysisManager SimObject that is managing all the LooppointAnaly...
std::unordered_map< Addr, uint64_t > localBBV
The basic block vector for the current core that the LooppointAnalysis is attached to.
ProbeListenerArg< LooppointAnalysis, std::pair< SimpleThread *, StaticInstPtr > > looppointAnalysisListener
bool ifListening
Only when this is set to true, the LooppointAnalysis will listen to the probe points.
AddrRange bbValidAddrRange
This is the valid address range for the basic block that the LooppointAnalysis considers analyzing.
void checkPc(const std::pair< SimpleThread *, StaticInstPtr > &inst_pair)
This function is called when a the probe point notifies the LoopPointAnalysis probe listener.
std::unordered_map< Addr, uint64_t > getLocalBBV() const
void startListening()
When this function is called, it sets the class variable ifListening to true, then calls the regProbe...
ProbeListenerArg generates a listener for the class of Arg and the class type T which is the class co...
Definition probe.hh:229
This class is a minimal wrapper around SimObject.
Definition probe.hh:108
Abstract superclass for simulation objects.
STL pair class.
Definition stl.hh:58
STL vector class.
Definition stl.hh:37
const Params & params() const
Bitfield< 4 > pc
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147

Generated on Mon Jan 13 2025 04:28:32 for gem5 by doxygen 1.9.8