gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
looppoint_analysis.cc
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
30
31namespace gem5
32{
33
34LooppointAnalysis::LooppointAnalysis(const LooppointAnalysisParams &params)
35 : ProbeListenerObject(params),
36 lpaManager(params.looppoint_analysis_manager),
37 bbValidAddrRange(params.bb_valid_addr_range),
38 markerValidAddrRange(params.marker_valid_addr_range),
39 ifListening(params.if_listening),
40 bbInstCounter(0)
41{
42 DPRINTF(LooppointAnalysis, "Start listening from the beginning of the "
43 "simulation? %s\n", ifListening ? "Yes" : "No");
44
45 for (int i = 0; i < params.bb_excluded_addr_ranges.size(); i++) {
46 bbExcludedAddrRanges.push_back(
48 params.bb_excluded_addr_ranges[i].start(),
49 params.bb_excluded_addr_ranges[i].end()
50 )
51 );
52 DPRINTF(LooppointAnalysis, "Excluding address range: (%li, %li)\n",
53 params.bb_excluded_addr_ranges[i].start(),
54 params.bb_excluded_addr_ranges[i].end()
55 );
56 }
57
58 DPRINTF(LooppointAnalysis, "Valid address range: (%li, %li)\n",
60 DPRINTF(LooppointAnalysis, "Valid marker address range: (%li, %li)\n",
62}
63
64void
66{
67 if (localBBV.find(pc) == localBBV.end()) {
68 localBBV.insert(std::make_pair(pc, 1));
69 } else {
70 localBBV.find(pc)->second++;
71 }
72}
73
74void
77)
78{
79 const StaticInstPtr &inst = inst_pair.second;
80
81 if (inst->isMicroop() && !inst->isLastMicroop()) {
82 // ignore this if it is a microop
83 return;
84 }
85
86 SimpleThread* thread = inst_pair.first;
87
88 auto &pcstate =
90 Addr pc = pcstate.pc();
91
93 // if we have already encountered this pc, we should already
94 // categorized it
96 // if it is categorized as a valid not control instruction
99 } else if (lpaManager->ifValidControl(pc)) {
100 // if it is categorized as a valid control instruction
101 bbInstCounter ++;
106 bbInstCounter = 0;
108 // if it is categorized as a backward branch
110 }
111 }
112 return;
113 }
114
116 // if we have not encountered this pc before, we should now update it to
117 // the corresponding category
118
119 if (!thread->getIsaPtr()->inUserMode()) {
120 // ignore this if it is not in user mode
121 return;
122 }
123
125 // ignore this if it is not in the valid address range
126 return;
127 }
128
129 if (bbExcludedAddrRanges.size() > 0) {
130 for (int i = 0; i < bbExcludedAddrRanges.size(); i++) {
131 if (bbExcludedAddrRanges[i].contains(pc)) {
132 // ignore this if it is in the excluded address range
133 return;
134 }
135 }
136 }
137
140
141 if (inst->isControl()) {
142 // if it is a control instruction, we see it as the end of a basic
143 // block
148 bbInstCounter = 0;
149
150 if (markerValidAddrRange.end() > 0
152 // if it is not in the marker valid address range, we do not
153 // consider it as a possible marker used loop branch instruction
154 return;
155 }
156
157 if (inst->isDirectCtrl()) {
158 // We only consider direct control instructions as possible
159 // loop branch instructions because it is PC-relative and it
160 // excludes return instructions.
161 if (pcstate.npc() < pc) {
163 }
164
165 }
166 } else {
168 }
169}
170
171void
173{
174 if (ifListening) {
175 if (listeners.empty()) {
176 listeners.push_back(new looppointAnalysisListener(this,
177 "Commit", &LooppointAnalysis::checkPc));
179 "Start listening to the RetiredInstsPC\n");
180 }
181 }
182
183}
184
185void
191
192void
194{
195 ifListening = false;
196 bool _ifRemoved;
197 for (auto &_listener : listeners) {
198 _ifRemoved = getProbeManager()->removeListener("Commit", *_listener);
199 panic_if(!_ifRemoved, "Failed to remove listener");
200 if (_listener != nullptr) {
201 delete(_listener);
203 "Deleted Listener pointer\n");
204 }
205 }
206 listeners.clear();
207 DPRINTF(LooppointAnalysis, "Stop listening to Commit\n");
208}
209
211 LooppointAnalysisManagerParams &params)
212 : SimObject(params),
213 regionLength(params.region_length),
214 globalInstCounter(0),
215 mostRecentBackwardBranchPC(0)
216{
217 DPRINTF(LooppointAnalysis, "regionLength = %i\n", regionLength);
218}
219
220void
222{
224 backwardBranchCounter.insert(std::make_pair(pc, 1));
225 } else {
226 backwardBranchCounter.find(pc)->second++;
227 }
228
230
232 // note that we do not reset any counter here but only raise an
233 // exit event.
234 // we can reset the counters through the simulation script using
235 // the helper functions in the LooppointAnalysisManager class
236 DPRINTF(LooppointAnalysis, "simpoint starting point found\n");
237 DPRINTF(LooppointAnalysis, "globalInstCounter = %lu\n",
239 DPRINTF(LooppointAnalysis, "regionLength = %lu\n",
241 exitSimLoopNow("simpoint starting point found");
242 }
243}
244
245void
247{
248 if (globalBBV.find(pc) == globalBBV.end()) {
249 globalBBV.insert(std::make_pair(pc, 1));
250 } else {
251 globalBBV.find(pc)->second++;
252 }
253}
254
255}// namespace gem5
#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
virtual bool inUserMode() const =0
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...
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 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.
bool ifValidControl(const Addr pc) const
bool ifValidNotControl(const Addr pc) const
void updateBBInstMap(Addr pc, uint64_t inst_ount)
LooppointAnalysisManager(const LooppointAnalysisManagerParams &params)
uint64_t regionLength
This variable stores the number of instructions that we used to define a region.
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...
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.
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.
void startListening()
When this function is called, it sets the class variable ifListening to true, then calls the regProbe...
Target & as()
Definition pcstate.hh:73
This class is a minimal wrapper around SimObject.
Definition probe.hh:108
ProbeManager * getProbeManager()
Definition probe.hh:116
std::vector< ProbeListener * > listeners
Definition probe.hh:111
bool removeListener(std::string point_name, ProbeListener &listener)
Remove a ProbeListener from the ProbePoint named by pointName.
Definition probe.cc:103
Abstract superclass for simulation objects.
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
ThreadContext * getTC()
Returns the pointer to this SimpleThread's ThreadContext.
BaseISA * getIsaPtr() const override
bool isDirectCtrl() const
bool isLastMicroop() const
bool isMicroop() const
bool isControl() const
virtual const PCStateBase & pcState() const =0
STL pair class.
Definition stl.hh:58
bool contains(const Addr &a) const
Determine if the range contains an address.
Addr end() const
Get the end address of the range.
Addr start() const
Get the start address of the range.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
const Params & params() const
Bitfield< 7 > i
Definition misc_types.hh:67
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
void exitSimLoopNow(const std::string &message, int exit_code, Tick repeat, bool serialize)
Schedule an event as above, but make it high priority so it runs before any normal events which are s...
Definition sim_events.cc:99

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