gem5 v25.0.0.1
Loading...
Searching...
No Matches
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
39#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
65 void checkPc(const std::pair<SimpleThread*,
66 const StaticInstPtr>& inst_pair);
67
73 void startListening();
74
79 void stopListening();
80
83
84 private:
85
91
98
104
109
115
121
126 std::unordered_map<Addr, uint64_t> localBBV;
127
133 void updateLocalBBV(const Addr pc);
134
135 public:
136 std::unordered_map<Addr, uint64_t>
138 {
139 return localBBV;
140 };
141
142 void
144 {
145 localBBV.clear();
146 };
147};
148
150{
151 public:
152 LooppointAnalysisManager(const LooppointAnalysisManagerParams &params);
153
159 void countBackwardBranch(const Addr pc);
160
166 void updateGlobalBBV(const Addr pc);
167
168 private:
175 std::unordered_map<Addr, uint64_t> backwardBranchCounter;
176
184 std::unordered_map<Addr, uint64_t> globalBBV;
185
192 std::unordered_map<Addr, uint64_t> bbInstMap;
193
200 uint64_t regionLength;
201
208
214
219 std::unordered_set<Addr> validNotControlPC;
224 std::unordered_set<Addr> validControlPC;
229 std::unordered_set<Addr> encounteredPC;
230
231 public:
232 bool
234 {
235 return backwardBranchCounter.find(pc) != backwardBranchCounter.end();
236 };
237
238 bool
240 {
241 return validNotControlPC.find(pc) != validNotControlPC.end();
242 };
243
244 bool
245 ifValidControl(const Addr pc) const
246 {
247 return validControlPC.find(pc) != validControlPC.end();
248 };
249
250 bool
251 ifEncountered(const Addr pc) const
252 {
253 return encounteredPC.find(pc) != encounteredPC.end();
254 };
255
256 void
258 {
259 validNotControlPC.insert(pc);
260 };
261
262 void
264 {
265 validControlPC.insert(pc);
266 };
267
268 void
270 {
271 encounteredPC.insert(pc);
272 };
273
274 void
275 updateBBInstMap(Addr pc, uint64_t inst_ount)
276 {
277 if (bbInstMap.find(pc) == bbInstMap.end())
278 {
279 bbInstMap.insert(std::make_pair(pc, inst_ount));
280 }
281 };
282
283 std::unordered_map<Addr, uint64_t> getBBInstMap() const
284 {
285 return bbInstMap;
286 };
287
288 std::unordered_map<Addr, uint64_t>
290 {
291 return globalBBV;
292 };
293
294 void
296 {
297 globalBBV.clear();
298 DPRINTF(LooppointAnalysis,"globalBBV is cleared\n");
299 };
300
301 uint64_t
303 {
304 return globalInstCounter;
305 };
306
307 void
309 {
311 DPRINTF(LooppointAnalysis,"globalInstCounter is cleared\n current "
312 "globalInstCounter = %lu\n", globalInstCounter);
313 };
314
315 void
320
321 Addr
326
327 std::unordered_map<Addr, uint64_t>
329 {
331 };
332
333 uint64_t
338};
339
340} // namespace gem5
341
342
343
344
345#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
LooppointAnalysisManager(const LooppointAnalysisManagerParams &params)
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 checkPc(const std::pair< SimpleThread *, const StaticInstPtr > &inst_pair)
This function is called when a the probe point notifies the LoopPointAnalysis probe listener.
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...
LooppointAnalysis(const LooppointAnalysisParams &params)
std::unordered_map< Addr, uint64_t > localBBV
The basic block vector for the current core that the LooppointAnalysis is attached to.
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.
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< LooppointAnalysis, std::pair< SimpleThread *, const StaticInstPtr > > looppointAnalysisListener
ProbeListenerArg generates a listener for the class of Arg and the class type T which is the class co...
Definition probe.hh:239
ProbeListenerObject(const ProbeListenerObjectParams &params)
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
STL pair class.
Definition stl.hh:58
STL vector class.
Definition stl.hh:37
const Params & params() const
SimObject(const Params &p)
Definition sim_object.cc:58
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
RefCountingPtr< StaticInst > StaticInstPtr

Generated on Sat Oct 18 2025 08:06:42 for gem5 by doxygen 1.14.0