HPCToolkit
PCProfileFilter.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // PCProfileFilter.h
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // See, in particular, the comments associated with 'PCProfile'.
57 //
58 //***************************************************************************
59 
60 #ifndef PCProfileFilter_H
61 #define PCProfileFilter_H
62 
63 //************************* System Include Files ****************************
64 
65 #include <vector>
66 #include <list>
67 #include <string>
68 
69 //*************************** User Include Files ****************************
70 
71 #include <include/uint.h>
72 
73 #include <lib/isa/ISA.hpp>
74 
75 #include <lib/binutils/LM.hpp>
76 
77 //*************************** Forward Declarations ***************************
78 
79 class PCProfileFilter;
80 class MetricFilter;
81 class PCFilter;
82 
83 // Some useful containers
84 class PCProfileFilterList : public std::list<PCProfileFilter*> {
85 public:
86  typedef std::list<PCProfileFilter*> Base;
87 
88 public:
90  virtual ~PCProfileFilterList() { clear(); }
91  virtual void clear() { Base::clear(); } // does not delte contents
92  void destroyContents(); // deletes contents
93 };
94 
95 
96 class PCProfileMetric;
97 
98 //****************************************************************************
99 // PCProfileFilter
100 //****************************************************************************
101 
102 // 'PCProfileFilter' is a filter that implicitly defines a derived
103 // metric (e.g. 'ProfileMetric') by specifing some combination of raw
104 // metrics and pcs from a 'PCProfile'.
105 // Currently, filters are strictly divided between metric and pc filters.
107 {
108 public:
109  // PCProfileFilter: assumes ownership of the MetricFilter and PCFilter.
111  : mfilt(x), pcfilt(y) { }
112  virtual ~PCProfileFilter();
113 
114  // Name, Description: The name and a description of what this filter
115  // computes.
116  const std::string& GetName() const { return name; }
117  const std::string& GetDescription() const { return description; }
118 
119  void SetName(const char* s) { name = (s) ? s : ""; }
120  void SetDescription(const char* s) { description = (s) ? s : ""; }
121 
122  // Access to the various sub-filters. (These intentionally return
123  // non-const pointers!)
124  MetricFilter* GetMetricFilter() const { return mfilt; }
125  PCFilter* GetPCFilter() const { return pcfilt; }
126 
127  void Dump(std::ostream& o = std::cerr);
128  void DDump();
129 
130 private:
131  // Should not be used
133  PCProfileFilter& operator=(const PCProfileFilter& p) { return *this; }
134 
135 protected:
136 private:
137  std::string name;
138  std::string description;
139 
142 };
143 
144 
145 //****************************************************************************
146 // MetricFilter
147 //****************************************************************************
148 
149 // MetricFilter: An abstract base class providing an interface for
150 // standard and user-defined metric filters. A MetricFilter divides
151 // metrics into two sets sets, 'in' and 'out'.
153 public:
155  virtual ~MetricFilter() { }
156 
157  // Returns true if 'm' is within the 'in' set; false otherwise.
158  virtual bool operator()(const PCProfileMetric* m) = 0;
159 
160 private:
161 };
162 
163 
164 //****************************************************************************
165 // PCFilter
166 //****************************************************************************
167 
168 // PCFilter: An abstract base class providing an interface for
169 // standard and user-defined PC filters. A PCFilter divides
170 // PC into two sets sets, 'in' and 'out'.
171 class PCFilter {
172 public:
173  PCFilter() { }
174  virtual ~PCFilter() { }
175 
176  // Returns true if the operation at 'pc' and 'opIndex' is within the
177  // 'in' set; false otherwise.
178  virtual bool operator()(VMA pc, ushort opIndex) = 0;
179 
180 private:
181 };
182 
183 
184 //****************************************************************************
185 // InsnClassExpr
186 //****************************************************************************
187 
188 
189 #define INSN_CLASS_ALL 0x00000001 /* cannot be part of disjunction! */
190 #define INSN_CLASS_FLOP 0x00000002
191 #define INSN_CLASS_INTOP 0x00000004
192 #define INSN_CLASS_MEMOP 0x00000008
193 #define INSN_CLASS_OTHER 0x00000010
194 
195 // InsnClassExpr: A common 'PCFilter' will be an instruction class
196 // filter (cf. 'InsnFilter'). This represent a disjunctive expression
197 // of instruction classes that can be used with an 'InsnFilter'.
198 
200 public:
201  typedef uint32_t bitvec_t;
202 
203 public:
204  // A 'InsnClassExpr' can be created using the bit definitions above.
205  InsnClassExpr(bitvec_t bv = 0) : bits(bv) { }
206  virtual ~InsnClassExpr() { }
207 
208  InsnClassExpr(const InsnClassExpr& x) { *this = x; }
210  bits = x.bits;
211  return *this;
212  }
213 
214  // IsSatisfied: Test to see if this query expression is satisfied by
215  // the given instruction class description within 'bv'. (Only on
216  // bit (= class) in 'bv' is set.)
217  bool IsSatisfied(const bitvec_t bv) {
218  if (IsSet(INSN_CLASS_ALL)) {
219  return true;
220  } else {
221  return IsSet(bv); // only one bit (= class) in 'bv' is set
222  }
223  }
224 
225  // IsValid: If no bits are set, this must be an invalid expression
226  bool IsValid() const { return bits != 0; }
227 
228  // IsSet: Tests to see if all the specified bits are set
229  bool IsSet(const bitvec_t bv) const {
230  return (bits & bv) == bv;
231  }
232  bool IsSet(const InsnClassExpr& m) const {
233  return (bits & m.bits) == m.bits;
234  }
235  // IsSetAny: Tests to see if *any* of the specified bits are set
236  bool IsSetAny(const bitvec_t bv) const {
237  return (bits & bv) != 0;
238  }
239  bool IsSetAny(const InsnClassExpr& m) const {
240  return (bits & m.bits) != 0;
241  }
242  // Set: Set all the specified bits
243  void Set(const bitvec_t bv) {
244  bits = bits | bv;
245  }
246  void Set(const InsnClassExpr& m) {
247  bits = bits | m.bits;
248  }
249  // Unset: Clears all the specified bits
250  void Unset(const bitvec_t bv) {
251  bits = bits & ~bv;
252  }
253  void Unset(const InsnClassExpr& m) {
254  bits = bits & ~(m.bits);
255  }
256 
257  void Dump(std::ostream& o = std::cerr);
258  void DDump();
259 
260 private:
261 
262 protected:
263 private:
264  bitvec_t bits;
265 };
266 
267 
268 // ConvertInsnDesc: Converts an InsnDesc to one of the above classes
271 
272 
273 //****************************************************************************
274 // InsnFilter
275 //****************************************************************************
276 
277 // InsnFilter: Divides PCs into two sets by Alpha instruction class.
278 class InsnFilter : public PCFilter {
279 public:
280  InsnFilter(InsnClassExpr expr_, binutils::LM* lm_);
281  virtual ~InsnFilter();
282 
283  // Returns true if the operation at 'pc' and 'opIndex' satisfies
284  // 'expr'; false otherwise.
285  virtual bool operator()(VMA pc, ushort opIndex);
286 
287 private:
289  binutils::LM* lm; // we do not own
290 };
291 
292 
293 //****************************************************************************
294 
295 #endif
PCFilter * GetPCFilter() const
virtual ~PCProfileFilterList()
bool IsSatisfied(const bitvec_t bv)
bfd_vma VMA
Definition: ISATypes.hpp:79
void SetDescription(const char *s)
InsnClassExpr(bitvec_t bv=0)
std::string description
MetricFilter * mfilt
MetricFilter * GetMetricFilter() const
void Set(const bitvec_t bv)
PCProfileFilter(const PCProfileFilter &p)
std::list< PCProfileFilter * > Base
virtual ~InsnClassExpr()
unsigned short int ushort
Definition: uint.h:120
InsnClassExpr expr
const std::string & GetDescription() const
InsnClassExpr & operator=(const InsnClassExpr &x)
InsnClassExpr::bitvec_t ConvertToInsnClass(ISA::InsnDesc d)
virtual ~PCFilter()
#define INSN_CLASS_ALL
void Unset(const bitvec_t bv)
bool IsValid() const
bool IsSet(const InsnClassExpr &m) const
const std::string & GetName() const
bool IsSet(const bitvec_t bv) const
virtual void clear()
void Unset(const InsnClassExpr &m)
InsnClassExpr(const InsnClassExpr &x)
#define NULL
Definition: ElfHelper.cpp:85
PCProfileFilter(MetricFilter *x=NULL, PCFilter *y=NULL)
void SetName(const char *s)
binutils::LM * lm
bool IsSetAny(const InsnClassExpr &m) const
PCProfileFilter & operator=(const PCProfileFilter &p)
void Set(const InsnClassExpr &m)
bool IsSetAny(const bitvec_t bv) const
virtual ~MetricFilter()