HPCToolkit
ISA.cpp
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 // ISA.C
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 //************************* System Include Files ****************************
61 
62 #include <iostream>
63 using std::ostream;
64 
65 #include <cstdarg>
66 
67 #include <cstring>
68 
69 //*************************** User Include Files ****************************
70 
71 #include <include/gcc-attr.h>
72 
73 #include "ISA.hpp"
74 
76 
77 //*************************** Forward Declarations ***************************
78 
79 //****************************************************************************
80 
81 //****************************************************************************
82 // ISA
83 //****************************************************************************
84 
86  : refcount(1)
87 {
88  _cache = new DecodingCache();
89 }
90 
91 
93 {
94  delete _cache;
95 }
96 
97 
98 //****************************************************************************
99 // ISA::InstDesc
100 //****************************************************************************
101 
102 const char*
104 {
105  switch(ty) {
106  case MEM_LOAD: return "MEM_LOAD";
107  case MEM_STORE: return "MEM_STORE";
108  case MEM_OTHER: return "MEM_OTHER";
109 
110  case INT_BR_COND_REL: return "INT_BR_COND_REL";
111  case INT_BR_COND_IND: return "INT_BR_COND_IND";
112  case FP_BR_COND_REL: return "FP_BR_COND_REL";
113  case FP_BR_COND_IND: return "FP_BR_COND_IND";
114 
115  case BR_UN_COND_REL: return "BR_UN_COND_REL";
116  case BR_UN_COND_IND: return "BR_UN_COND_IND";
117 
118  case SUBR_REL: return "SUBR_REL";
119  case SUBR_IND: return "SUBR_IND";
120  case SUBR_RET: return "SUBR_RET";
121 
122  case INT_ADD: return "INT_ADD";
123  case INT_SUB: return "INT_SUB";
124  case INT_MUL: return "INT_MUL";
125  case INT_CMP: return "INT_CMP";
126  case INT_LOGIC: return "INT_LOGIC";
127  case INT_SHIFT: return "INT_SHIFT";
128  case INT_MOV: return "INT_MOV";
129  case INT_OTHER: return "INT_OTHER";
130 
131  case FP_ADD: return "FP_ADD";
132  case FP_SUB: return "FP_SUB";
133  case FP_MUL: return "FP_MUL";
134  case FP_DIV: return "FP_DIV";
135  case FP_CMP: return "FP_CMP";
136  case FP_CVT: return "FP_CVT";
137  case FP_SQRT: return "FP_SQRT";
138  case FP_MOV: return "FP_MOV";
139  case FP_OTHER: return "FP_OTHER";
140 
141  case SYS_CALL: return "SYS_CALL";
142  case OTHER: return "OTHER";
143  case INVALID: return "INVALID";
144 
145  default: DIAG_Die("Programming Error");
146  }
147  return NULL;
148 }
149 
150 
151 void
152 ISA::InsnDesc::dump(std::ostream& o)
153 {
154  o << toString();
155 }
156 
157 
158 void
160 {
161  dump(std::cerr);
162 }
163 
164 
165 //***************************************************************************
166 // binutils helpers
167 //***************************************************************************
168 
169 
170 extern "C" {
171 
172 int
173 GNUbu_fprintf(void* stream, const char* format, ...)
174 {
175 #define BUF_SZ 512
176  static char BUF[BUF_SZ];
177 
178  va_list args;
179  va_start(args, format);
180  int n = vsnprintf(BUF, BUF_SZ, format, args);
181  va_end(args);
182 
183  ostream* os = (ostream*)stream;
184  *os << BUF;
185 
186  return n;
187 }
188 
189 
190 int
192  const char* GCC_ATTR_UNUSED format, ...)
193 {
194  return 0;
195 }
196 
197 
198 void
200  struct disassemble_info* GCC_ATTR_UNUSED di)
201 {
202 }
203 
204 
205 int
206 GNUbu_read_memory(bfd_vma vma, bfd_byte* myaddr, unsigned int len,
207  struct disassemble_info* GCC_ATTR_UNUSED di)
208 {
209  memcpy(myaddr, BFDVMA_TO_PTR(vma, const char*), len);
210  return 0; /* success */
211 }
212 
213 } // extern "C"
214 
215 //***************************************************************************
virtual ~ISA()
Definition: ISA.cpp:92
DecodingCache * _cache
Definition: ISA.hpp:505
void dump(std::ostream &o=std::cerr)
Definition: ISA.cpp:152
int GNUbu_fprintf(void *stream, const char *format,...)
Definition: ISA.cpp:173
int GNUbu_fprintf_stub(void *GCC_ATTR_UNUSED stream, const char *GCC_ATTR_UNUSED format,...)
Definition: ISA.cpp:191
#define BFDVMA_TO_PTR(x, totype)
Definition: ISATypes.hpp:95
int GNUbu_read_memory(bfd_vma vma, bfd_byte *myaddr, unsigned int len, struct disassemble_info *GCC_ATTR_UNUSED di)
Definition: ISA.cpp:206
void GNUbu_print_addr_stub(bfd_vma GCC_ATTR_UNUSED di_vma, struct disassemble_info *GCC_ATTR_UNUSED di)
Definition: ISA.cpp:199
#define BUF_SZ
const char * toString() const
Definition: ISA.cpp:103
#define NULL
Definition: ElfHelper.cpp:85
ISA()
Definition: ISA.cpp:85
#define DIAG_Die(...)
Definition: diagnostics.h:267
#define GCC_ATTR_UNUSED
Definition: gcc-attr.h:80
<!-- ********************************************************************--> n<!-- HPCToolkit Experiment DTD --> n<!-- Version 2.1 --> n<!-- ********************************************************************--> n<!ELEMENT HPCToolkitExperiment(Header,(SecCallPathProfile|SecFlatProfile) *)> n<!ATTLIST HPCToolkitExperiment\n version CDATA #REQUIRED > n n<!-- ******************************************************************--> n n<!-- Info/NV:flexible name-value pairs:(n) ame;(t) ype;(v) alue --> n<!ELEMENT Info(NV *)> n<!ATTLIST Info\n n CDATA #IMPLIED > n<!ELEMENT NV EMPTY > n<!ATTLIST NV\n n CDATA #REQUIRED\n t CDATA #IMPLIED\n v CDATA #REQUIRED > n n<!-- ******************************************************************--> n<!-- Header --> n<!-- ******************************************************************--> n<!ELEMENT Header(Info *)> n<!ATTLIST Header\n n CDATA #REQUIRED > n n<!-- ******************************************************************--> n<!-- Section Header --> n<!-- ******************************************************************--> n<!ELEMENT SecHeader(MetricTable?, MetricDBTable?, TraceDBTable?, LoadModuleTable?, FileTable?, ProcedureTable?, Info *)> n n<!-- MetricTable:--> n<!ELEMENT MetricTable(Metric) * > n n<!-- Metric:(i) d;(n) ame --> n<!--(v) alue-type:transient type of values --> n<!--(t) ype:persistent type of metric --> n<!-- fmt:format;show;--> n<!ELEMENT Metric(MetricFormula *, Info?)> n<!ATTLIST Metric\n i CDATA #REQUIRED\n n CDATA #REQUIRED\n es CDATA #IMPLIED\n em CDATA #IMPLIED\n ep CDATA #IMPLIED\n v(raw|final|derived-incr|derived) \"raw\\ t (inclusive|exclusive|nil) \nil\\ partner CDATA #IMPLIED\ fmt CDATA #IMPLIED\ show (1|0) \1\\ show-percent (1|0) \1> n n<!-- MetricFormula represents derived metrics: (t)ype; (frm): formula --> n<!ELEMENT MetricFormula (Info?)> n<!ATTLIST MetricFormula\ t (combine|finalize) \finalize\\ i CDATA #IMPLIED\ frm CDATA #REQUIRED> n n<!-- Metric data, used in sections: (n)ame [from Metric]; (v)alue --> n<!ELEMENT M EMPTY> n<!ATTLIST M\ n CDATA #REQUIRED\ v CDATA #REQUIRED> n n<!-- MetricDBTable: --> n<!ELEMENT MetricDBTable (MetricDB)*> n n<!-- MetricDB: (i)d; (n)ame --> n<!-- (t)ype: persistent type of metric --> n<!-- db-glob: file glob describing files in metric db --> n<!-- db-id: id within metric db --> n<!-- db-num-metrics: number of metrics in db --> n<!-- db-header-sz: size (in bytes) of a db file header --> n<!ELEMENT MetricDB EMPTY> n<!ATTLIST MetricDB\ i CDATA #REQUIRED\ n CDATA #REQUIRED\ t (inclusive|exclusive|nil) \nil\\ partner CDATA #IMPLIED\ db-glob CDATA #IMPLIED\ db-id CDATA #IMPLIED\ db-num-metrics CDATA #IMPLIED\ db-header-sz CDATA #IMPLIED> n n<!-- TraceDBTable: --> n<!ELEMENT TraceDBTable (TraceDB)> n n<!-- TraceDB: (i)d --> n<!-- db-min-time: min beginning time stamp (global) --> n<!-- db-max-time: max ending time stamp (global) --> n<!ELEMENT TraceDB EMPTY> n<!ATTLIST TraceDB\ i CDATA #REQUIRED\ db-glob CDATA #IMPLIED\ db-min-time CDATA #IMPLIED\ db-max-time CDATA #IMPLIED\ db-header-sz CDATA #IMPLIED> n n<!-- LoadModuleTable assigns a short name to a load module --> n<!ELEMENT LoadModuleTable (LoadModule)*> n n<!ELEMENT LoadModule (Info?)> n<!ATTLIST LoadModule\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!-- FileTable assigns a short name to a file --> n<!ELEMENT FileTable (File)*> n n<!ELEMENT File (Info?)> n<!ATTLIST File\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!-- ProcedureTable assigns a short name to a procedure --> n<!ELEMENT ProcedureTable (Procedure)*> n n<!-- Info/NV: flexible name-value pairs: (n)ame; (t)ype; (v)alue --> n<!-- f: family of the procedure (fake, root, ...)--> n<!ELEMENT Procedure (Info?)> n<!ATTLIST Procedure\ i CDATA #REQUIRED\ n CDATA #REQUIRED\ f CDATA #IMPLIED> n n<!-- ****************************************************************** --> n<!-- Section: Call path profile --> n<!-- ****************************************************************** --> n<!ELEMENT SecCallPathProfile (SecHeader, SecCallPathProfileData)> n<!ATTLIST SecCallPathProfile\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!ELEMENT SecCallPathProfileData (PF|M)*> n<!-- Procedure frame --> n<!-- (i)d: unique identifier for cross referencing --> n<!-- (s)tatic scope id --> n<!-- (n)ame: a string or an id in ProcedureTable --> n<!-- (lm) load module: a string or an id in LoadModuleTable --> n<!-- (f)ile name: a string or an id in LoadModuleTable --> n<!-- (l)ine range: \beg-end\ (inclusive range) --> n<!-- (a)lien: whether frame is alien to enclosing P --> n<!-- (str)uct: hpcstruct node id --> n<!-- (t)ype: hpcrun node type: memory access, variable declaration, ... --> n<!-- (v)ma-range-set: \{[beg-end), [beg-end)...}\ --> n<!ELEMENT PF (PF|Pr|L|C|S|M)*> n<!ATTLIST PF\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ n CDATA #REQUIRED\ lm CDATA #IMPLIED\ f CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Procedure (static): GOAL: replace with 'P' --> n<!ELEMENT Pr (Pr|L|C|S|M)*> n<!ATTLIST Pr\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ n CDATA #REQUIRED\ lm CDATA #IMPLIED\ f CDATA #IMPLIED\ l CDATA #IMPLIED\ a (1|0) \0\\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Callsite (a special StatementRange) --> n<!ELEMENT C (PF|M)*> n<!ATTLIST C\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n n<!-- ****************************************************************** --> n<!-- Section: Flat profile --> n<!-- ****************************************************************** --> n<!ELEMENT SecFlatProfile (SecHeader, SecFlatProfileData)> n<!ATTLIST SecFlatProfile\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!ELEMENT SecFlatProfileData (LM|M)*> n<!-- Load module: (i)d; (n)ame; (v)ma-range-set --> n<!ELEMENT LM (F|P|M)*> n<!ATTLIST LM\ i CDATA #IMPLIED\ n CDATA #REQUIRED\ v CDATA #IMPLIED> n<!-- File --> n<!ELEMENT F (P|L|S|M)*> n<!ATTLIST F\ i CDATA #IMPLIED\ n CDATA #REQUIRED> n<!-- Procedure (Note 1) --> n<!ELEMENT P (P|A|L|S|C|M)*> n<!ATTLIST P\ i CDATA #IMPLIED\ n CDATA #REQUIRED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Alien (Note 1) --> n<!ELEMENT A (A|L|S|C|M)*> n<!ATTLIST A\ i CDATA #IMPLIED\ f CDATA #IMPLIED\ n CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Loop (Note 1,2) --> n<!ELEMENT L (A|Pr|L|S|C|M)*> n<!ATTLIST L\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ f CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Statement (Note 2) --> n<!-- (it): trace record identifier --> n<!ELEMENT S (S|M)*> n<!ATTLIST S\ i CDATA #IMPLIED\ it CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Note 1: Contained Cs may not contain PFs --> n<!-- Note 2: The 's' attribute is not used for flat profiles --> n
void ddump()
Definition: ISA.cpp:159