sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 1 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
njn | 101e572 | 2005-04-21 02:37:54 +0000 | [diff] [blame] | 3 | /*--- Cachegrind: everything but the simulation itself. ---*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 4 | /*--- cg_main.c ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 8 | This file is part of Cachegrind, a Valgrind tool for cache |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 9 | profiling programs. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 10 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 11 | Copyright (C) 2002-2005 Nicholas Nethercote |
njn | 2bc1012 | 2005-05-08 02:10:27 +0000 | [diff] [blame] | 12 | njn@valgrind.org |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 29 | The GNU General Public License is contained in the file COPYING. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 30 | */ |
| 31 | |
nethercote | 4606320 | 2004-09-02 08:51:43 +0000 | [diff] [blame] | 32 | #include "tool.h" |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 33 | #include "pub_tool_mallocfree.h" |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 34 | #include "pub_tool_tooliface.h" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 35 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 36 | #include "cg_arch.h" |
nethercote | 27fc1da | 2004-01-04 16:56:57 +0000 | [diff] [blame] | 37 | #include "cg_sim.c" |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 38 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 39 | /*------------------------------------------------------------*/ |
| 40 | /*--- Constants ---*/ |
| 41 | /*------------------------------------------------------------*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 42 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 43 | #define MIN_LINE_SIZE 16 |
| 44 | #define FILE_LEN 256 |
| 45 | #define FN_LEN 256 |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 46 | |
| 47 | /*------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 48 | /*--- Profiling events ---*/ |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 49 | /*------------------------------------------------------------*/ |
| 50 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 51 | typedef |
| 52 | enum { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 53 | VgpGetLineCC = VgpFini+1, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 54 | VgpCacheSimulate, |
| 55 | VgpCacheResults |
| 56 | } |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 57 | VgpToolCC; |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 58 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 59 | /*------------------------------------------------------------*/ |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 60 | /*--- Types and Data Structures ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 61 | /*------------------------------------------------------------*/ |
| 62 | |
| 63 | typedef struct _CC CC; |
| 64 | struct _CC { |
| 65 | ULong a; |
| 66 | ULong m1; |
| 67 | ULong m2; |
| 68 | }; |
| 69 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 70 | //------------------------------------------------------------ |
| 71 | // Primary data structure #1: CC table |
| 72 | // - Holds the per-source-line hit/miss stats, grouped by file/function/line. |
| 73 | // - hash(file, hash(fn, hash(line+CC))) |
| 74 | // - Each hash table is separately chained. |
| 75 | // - The array sizes below work fairly well for Konqueror. |
| 76 | // - Lookups done by instr_addr, which is converted immediately to a source |
| 77 | // location. |
| 78 | // - Traversed for dumping stats at end in file/func/line hierarchy. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 79 | |
| 80 | #define N_FILE_ENTRIES 251 |
| 81 | #define N_FN_ENTRIES 53 |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 82 | #define N_LINE_ENTRIES 37 |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 83 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 84 | typedef struct _lineCC lineCC; |
| 85 | struct _lineCC { |
| 86 | Int line; |
| 87 | CC Ir; |
| 88 | CC Dr; |
| 89 | CC Dw; |
| 90 | lineCC* next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 93 | typedef struct _fnCC fnCC; |
| 94 | struct _fnCC { |
| 95 | Char* fn; |
| 96 | fnCC* next; |
| 97 | lineCC* lines[N_LINE_ENTRIES]; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 100 | typedef struct _fileCC fileCC; |
| 101 | struct _fileCC { |
| 102 | Char* file; |
| 103 | fileCC* next; |
| 104 | fnCC* fns[N_FN_ENTRIES]; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 107 | // Top level of CC table. Auto-zeroed. |
| 108 | static fileCC *CC_table[N_FILE_ENTRIES]; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 109 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 110 | //------------------------------------------------------------ |
| 111 | // Primary data structre #2: Instr-info table |
| 112 | // - Holds the cached info about each instr that is used for simulation. |
| 113 | // - table(BB_start_addr, list(instr_info)) |
| 114 | // - For each BB, each instr_info in the list holds info about the |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 115 | // instruction (instr_len, instr_addr, etc), plus a pointer to its line |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 116 | // CC. This node is what's passed to the simulation function. |
| 117 | // - When BBs are discarded the relevant list(instr_details) is freed. |
| 118 | |
| 119 | typedef struct _instr_info instr_info; |
| 120 | struct _instr_info { |
nethercote | ca1f2dc | 2004-07-21 08:49:02 +0000 | [diff] [blame] | 121 | Addr instr_addr; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 122 | UChar instr_len; |
nethercote | ca1f2dc | 2004-07-21 08:49:02 +0000 | [diff] [blame] | 123 | UChar data_size; |
| 124 | lineCC* parent; // parent line-CC |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | typedef struct _BB_info BB_info; |
| 128 | struct _BB_info { |
| 129 | BB_info* next; // next field |
| 130 | Addr BB_addr; // key |
| 131 | Int n_instrs; |
| 132 | instr_info instrs[0]; |
| 133 | }; |
| 134 | |
| 135 | VgHashTable instr_info_table; // hash(Addr, BB_info) |
| 136 | |
| 137 | //------------------------------------------------------------ |
| 138 | // Stats |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 139 | static Int distinct_files = 0; |
| 140 | static Int distinct_fns = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 141 | static Int distinct_lines = 0; |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 142 | static Int distinct_instrs = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 143 | |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 144 | static Int full_debug_BBs = 0; |
| 145 | static Int file_line_debug_BBs = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 146 | static Int fn_debug_BBs = 0; |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 147 | static Int no_debug_BBs = 0; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 148 | |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 149 | static Int BB_retranslations = 0; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 150 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 151 | /*------------------------------------------------------------*/ |
| 152 | /*--- CC table operations ---*/ |
| 153 | /*------------------------------------------------------------*/ |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 154 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 155 | static void get_debug_info(Addr instr_addr, Char file[FILE_LEN], |
| 156 | Char fn[FN_LEN], Int* line) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 157 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 158 | Bool found_file_line = VG_(get_filename_linenum)(instr_addr, file, |
| 159 | FILE_LEN, line); |
| 160 | Bool found_fn = VG_(get_fnname)(instr_addr, fn, FN_LEN); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 161 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 162 | if (!found_file_line) { |
| 163 | VG_(strcpy)(file, "???"); |
| 164 | *line = 0; |
| 165 | } |
| 166 | if (!found_fn) { |
| 167 | VG_(strcpy)(fn, "???"); |
| 168 | } |
| 169 | if (found_file_line) { |
| 170 | if (found_fn) full_debug_BBs++; |
| 171 | else file_line_debug_BBs++; |
| 172 | } else { |
| 173 | if (found_fn) fn_debug_BBs++; |
| 174 | else no_debug_BBs++; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 178 | static UInt hash(Char *s, UInt table_size) |
| 179 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 180 | const int hash_constant = 256; |
| 181 | int hash_value = 0; |
| 182 | for ( ; *s; s++) |
| 183 | hash_value = (hash_constant * hash_value + *s) % table_size; |
| 184 | return hash_value; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 185 | } |
| 186 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 187 | static __inline__ |
| 188 | fileCC* new_fileCC(Char filename[], fileCC* next) |
nethercote | 09d853e | 2004-01-21 16:12:55 +0000 | [diff] [blame] | 189 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 190 | // Using calloc() zeroes the fns[] array |
| 191 | fileCC* cc = VG_(calloc)(1, sizeof(fileCC)); |
| 192 | cc->file = VG_(strdup)(filename); |
| 193 | cc->next = next; |
| 194 | return cc; |
nethercote | 09d853e | 2004-01-21 16:12:55 +0000 | [diff] [blame] | 195 | } |
| 196 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 197 | static __inline__ |
| 198 | fnCC* new_fnCC(Char fn[], fnCC* next) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 199 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 200 | // Using calloc() zeroes the lines[] array |
| 201 | fnCC* cc = VG_(calloc)(1, sizeof(fnCC)); |
| 202 | cc->fn = VG_(strdup)(fn); |
| 203 | cc->next = next; |
| 204 | return cc; |
| 205 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 206 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 207 | static __inline__ |
| 208 | lineCC* new_lineCC(Int line, lineCC* next) |
| 209 | { |
| 210 | // Using calloc() zeroes the Ir/Dr/Dw CCs and the instrs[] array |
| 211 | lineCC* cc = VG_(calloc)(1, sizeof(lineCC)); |
| 212 | cc->line = line; |
| 213 | cc->next = next; |
| 214 | return cc; |
| 215 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 216 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 217 | static __inline__ |
| 218 | instr_info* new_instr_info(Addr instr_addr, lineCC* parent, instr_info* next) |
| 219 | { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 220 | // Using calloc() zeroes instr_len and data_size |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 221 | instr_info* ii = VG_(calloc)(1, sizeof(instr_info)); |
| 222 | ii->instr_addr = instr_addr; |
| 223 | ii->parent = parent; |
| 224 | return ii; |
| 225 | } |
| 226 | |
| 227 | // Do a three step traversal: by file, then fn, then line. |
| 228 | // In all cases prepends new nodes to their chain. Returns a pointer to the |
| 229 | // line node, creates a new one if necessary. |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 230 | static lineCC* get_lineCC(Addr origAddr) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 231 | { |
| 232 | fileCC *curr_fileCC; |
| 233 | fnCC *curr_fnCC; |
| 234 | lineCC *curr_lineCC; |
| 235 | Char file[FILE_LEN], fn[FN_LEN]; |
| 236 | Int line; |
| 237 | UInt file_hash, fn_hash, line_hash; |
| 238 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 239 | get_debug_info(origAddr, file, fn, &line); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 240 | |
| 241 | VGP_PUSHCC(VgpGetLineCC); |
| 242 | |
| 243 | // level 1 |
| 244 | file_hash = hash(file, N_FILE_ENTRIES); |
| 245 | curr_fileCC = CC_table[file_hash]; |
| 246 | while (NULL != curr_fileCC && !VG_STREQ(file, curr_fileCC->file)) { |
| 247 | curr_fileCC = curr_fileCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 248 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 249 | if (NULL == curr_fileCC) { |
| 250 | CC_table[file_hash] = curr_fileCC = |
| 251 | new_fileCC(file, CC_table[file_hash]); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 252 | distinct_files++; |
| 253 | } |
| 254 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 255 | // level 2 |
| 256 | fn_hash = hash(fn, N_FN_ENTRIES); |
| 257 | curr_fnCC = curr_fileCC->fns[fn_hash]; |
| 258 | while (NULL != curr_fnCC && !VG_STREQ(fn, curr_fnCC->fn)) { |
| 259 | curr_fnCC = curr_fnCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 260 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 261 | if (NULL == curr_fnCC) { |
| 262 | curr_fileCC->fns[fn_hash] = curr_fnCC = |
| 263 | new_fnCC(fn, curr_fileCC->fns[fn_hash]); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 264 | distinct_fns++; |
| 265 | } |
| 266 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 267 | // level 3 |
| 268 | line_hash = line % N_LINE_ENTRIES; |
| 269 | curr_lineCC = curr_fnCC->lines[line_hash]; |
| 270 | while (NULL != curr_lineCC && line != curr_lineCC->line) { |
| 271 | curr_lineCC = curr_lineCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 272 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 273 | if (NULL == curr_lineCC) { |
| 274 | curr_fnCC->lines[line_hash] = curr_lineCC = |
| 275 | new_lineCC(line, curr_fnCC->lines[line_hash]); |
| 276 | distinct_lines++; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 277 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 278 | |
| 279 | VGP_POPCC(VgpGetLineCC); |
| 280 | return curr_lineCC; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /*------------------------------------------------------------*/ |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 284 | /*--- Cache simulation functions ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 285 | /*------------------------------------------------------------*/ |
| 286 | |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 287 | static VGA_REGPARM(1) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 288 | void log_1I_0D_cache_access(instr_info* n) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 289 | { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 290 | //VG_(printf)("1I_0D : CCaddr=0x%x, iaddr=0x%x, isize=%u\n", |
| 291 | // n, n->instr_addr, n->instr_len); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 292 | VGP_PUSHCC(VgpCacheSimulate); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 293 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 294 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 295 | n->parent->Ir.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 296 | VGP_POPCC(VgpCacheSimulate); |
| 297 | } |
| 298 | |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 299 | static VGA_REGPARM(2) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 300 | void log_1I_1Dr_cache_access(instr_info* n, Addr data_addr) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 301 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 302 | //VG_(printf)("1I_1Dr: CCaddr=%p, iaddr=%p, isize=%u, daddr=%p, dsize=%u\n", |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 303 | // n, n->instr_addr, n->instr_len, data_addr, n->data_size); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 304 | VGP_PUSHCC(VgpCacheSimulate); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 305 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 306 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 307 | n->parent->Ir.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 308 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 309 | cachesim_D1_doref(data_addr, n->data_size, |
| 310 | &n->parent->Dr.m1, &n->parent->Dr.m2); |
| 311 | n->parent->Dr.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 312 | VGP_POPCC(VgpCacheSimulate); |
| 313 | } |
| 314 | |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 315 | static VGA_REGPARM(2) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 316 | void log_1I_1Dw_cache_access(instr_info* n, Addr data_addr) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 317 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 318 | //VG_(printf)("1I_1Dw: CCaddr=%p, iaddr=%p, isize=%u, daddr=%p, dsize=%u\n", |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 319 | // n, n->instr_addr, n->instr_len, data_addr, n->data_size); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 320 | VGP_PUSHCC(VgpCacheSimulate); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 321 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 322 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 323 | n->parent->Ir.a++; |
| 324 | |
| 325 | cachesim_D1_doref(data_addr, n->data_size, |
| 326 | &n->parent->Dw.m1, &n->parent->Dw.m2); |
| 327 | n->parent->Dw.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 328 | VGP_POPCC(VgpCacheSimulate); |
| 329 | } |
| 330 | |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 331 | static VGA_REGPARM(3) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 332 | void log_1I_2D_cache_access(instr_info* n, Addr data_addr1, Addr data_addr2) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 333 | { |
| 334 | //VG_(printf)("1I_2D: CCaddr=%p, iaddr=%p, isize=%u, daddr1=%p, daddr2=%p, dsize=%u\n", |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 335 | // n, n->instr_addr, n->instr_len, data_addr1, data_addr2, n->data_size); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 336 | VGP_PUSHCC(VgpCacheSimulate); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 337 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 338 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 339 | n->parent->Ir.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 340 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 341 | cachesim_D1_doref(data_addr1, n->data_size, |
| 342 | &n->parent->Dr.m1, &n->parent->Dr.m2); |
| 343 | n->parent->Dr.a++; |
| 344 | cachesim_D1_doref(data_addr2, n->data_size, |
| 345 | &n->parent->Dw.m1, &n->parent->Dw.m2); |
| 346 | n->parent->Dw.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 347 | VGP_POPCC(VgpCacheSimulate); |
| 348 | } |
| 349 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 350 | /*------------------------------------------------------------*/ |
| 351 | /*--- Instrumentation ---*/ |
| 352 | /*------------------------------------------------------------*/ |
| 353 | |
nethercote | 564b2b0 | 2004-08-07 15:54:53 +0000 | [diff] [blame] | 354 | static |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 355 | BB_info* get_BB_info(IRBB* bbIn, Addr origAddr, Bool* bbSeenBefore) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 356 | { |
| 357 | Int i, n_instrs; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 358 | IRStmt* st; |
| 359 | BB_info* bbInfo; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 360 | VgHashNode** dummy; |
| 361 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 362 | // Count number of original instrs in BB |
| 363 | n_instrs = 0; |
| 364 | for (i = 0; i < bbIn->stmts_used; i++) { |
| 365 | st = bbIn->stmts[i]; |
| 366 | if (Ist_IMark == st->tag) n_instrs++; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | // Get the BB_info |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 370 | bbInfo = (BB_info*)VG_(HT_get_node)(instr_info_table, origAddr, &dummy); |
| 371 | *bbSeenBefore = ( NULL == bbInfo ? False : True ); |
| 372 | if (*bbSeenBefore) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 373 | // BB must have been translated before, but flushed from the TT |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 374 | tl_assert(bbInfo->n_instrs == n_instrs ); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 375 | BB_retranslations++; |
| 376 | } else { |
| 377 | // BB never translated before (at this address, at least; could have |
| 378 | // been unloaded and then reloaded elsewhere in memory) |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 379 | bbInfo = VG_(calloc)(1, sizeof(BB_info) + n_instrs*sizeof(instr_info)); |
| 380 | bbInfo->BB_addr = origAddr; |
| 381 | bbInfo->n_instrs = n_instrs; |
| 382 | VG_(HT_add_node)( instr_info_table, (VgHashNode*)bbInfo ); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 383 | distinct_instrs++; |
| 384 | } |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 385 | return bbInfo; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 386 | } |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 387 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 388 | static |
| 389 | void handleOneStatement(IRTypeEnv* tyenv, IRBB* bbOut, IRStmt* st, |
| 390 | Addr* instrAddr, UInt* instrLen, |
| 391 | IRExpr** loadAddrExpr, IRExpr** storeAddrExpr, |
| 392 | UInt* dataSize) |
| 393 | { |
sewardj | 7f4a862 | 2005-03-26 21:55:21 +0000 | [diff] [blame] | 394 | tl_assert(isFlatIRStmt(st)); |
| 395 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 396 | switch (st->tag) { |
sewardj | 21dc345 | 2005-03-21 00:27:41 +0000 | [diff] [blame] | 397 | case Ist_NoOp: |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 398 | break; |
| 399 | |
sewardj | e6da2fa | 2005-05-12 17:57:14 +0000 | [diff] [blame] | 400 | case Ist_AbiHint: |
| 401 | /* ABI hints aren't interesting to cachegrind. Ignore. */ |
| 402 | break; |
| 403 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 404 | case Ist_IMark: |
sewardj | 2b641fe | 2005-03-21 11:53:38 +0000 | [diff] [blame] | 405 | /* st->Ist.IMark.addr is a 64-bit int. ULong_to_Ptr casts this |
| 406 | to the host's native pointer type; if that is 32 bits then it |
| 407 | discards the upper 32 bits. If we are cachegrinding on a |
| 408 | 32-bit host then we are also ensured that the guest word size |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 409 | is 32 bits, due to the assertion in cg_instrument that the |
sewardj | 2b641fe | 2005-03-21 11:53:38 +0000 | [diff] [blame] | 410 | host and guest word sizes must be the same. Hence |
| 411 | st->Ist.IMark.addr will have been derived from a 32-bit guest |
| 412 | code address and truncation of it is safe. I believe this |
| 413 | assignment should be correct for both 32- and 64-bit |
| 414 | machines. */ |
| 415 | *instrAddr = (Addr)ULong_to_Ptr(st->Ist.IMark.addr); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 416 | *instrLen = st->Ist.IMark.len; |
| 417 | addStmtToIRBB( bbOut, st ); |
| 418 | break; |
| 419 | |
| 420 | case Ist_Tmp: { |
| 421 | IRExpr* data = st->Ist.Tmp.data; |
| 422 | if (data->tag == Iex_LDle) { |
| 423 | IRExpr* aexpr = data->Iex.LDle.addr; |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 424 | tl_assert( isIRAtom(aexpr) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 425 | |
| 426 | // XXX: repe cmpsb does two loads... the first one is ignored here! |
| 427 | //tl_assert( NULL == *loadAddrExpr ); // XXX: ??? |
| 428 | *loadAddrExpr = aexpr; |
| 429 | *dataSize = sizeofIRType(data->Iex.LDle.ty); |
| 430 | } |
| 431 | addStmtToIRBB( bbOut, st ); |
| 432 | break; |
| 433 | } |
| 434 | |
| 435 | case Ist_STle: { |
| 436 | IRExpr* data = st->Ist.STle.data; |
| 437 | IRExpr* aexpr = st->Ist.STle.addr; |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 438 | tl_assert( isIRAtom(aexpr) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 439 | tl_assert( NULL == *storeAddrExpr ); // XXX: ??? |
| 440 | *storeAddrExpr = aexpr; |
| 441 | *dataSize = sizeofIRType(typeOfIRExpr(tyenv, data)); |
| 442 | addStmtToIRBB( bbOut, st ); |
| 443 | break; |
| 444 | } |
| 445 | |
sewardj | 7f4a862 | 2005-03-26 21:55:21 +0000 | [diff] [blame] | 446 | case Ist_Dirty: { |
| 447 | IRDirty* d = st->Ist.Dirty.details; |
| 448 | if (d->mFx != Ifx_None) { |
| 449 | /* This dirty helper accesses memory. Collect the |
| 450 | details. */ |
| 451 | tl_assert(d->mAddr != NULL); |
| 452 | tl_assert(d->mSize != 0); |
| 453 | *dataSize = d->mSize; |
| 454 | if (d->mFx == Ifx_Read || d->mFx == Ifx_Modify) |
| 455 | *loadAddrExpr = d->mAddr; |
| 456 | if (d->mFx == Ifx_Write || d->mFx == Ifx_Modify) |
| 457 | *storeAddrExpr = d->mAddr; |
| 458 | } else { |
| 459 | tl_assert(d->mAddr == NULL); |
| 460 | tl_assert(d->mSize == 0); |
| 461 | } |
| 462 | addStmtToIRBB( bbOut, st ); |
| 463 | break; |
| 464 | } |
| 465 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 466 | case Ist_Put: |
| 467 | case Ist_PutI: |
| 468 | case Ist_Exit: |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 469 | case Ist_MFence: |
| 470 | addStmtToIRBB( bbOut, st ); |
| 471 | break; |
| 472 | |
| 473 | default: |
| 474 | VG_(printf)("\n"); |
| 475 | ppIRStmt(st); |
| 476 | VG_(printf)("\n"); |
| 477 | VG_(tool_panic)("Cachegrind: unhandled IRStmt"); |
| 478 | } |
| 479 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 480 | |
nethercote | 564b2b0 | 2004-08-07 15:54:53 +0000 | [diff] [blame] | 481 | static |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 482 | void do_details( instr_info* n, Bool bbSeenBefore, |
| 483 | Addr instr_addr, Int instr_len, Int data_size ) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 484 | { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 485 | if (bbSeenBefore) { |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 486 | tl_assert( n->instr_addr == instr_addr ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 487 | tl_assert( n->instr_len == instr_len ); |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 488 | tl_assert( n->data_size == data_size ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 489 | // Don't check that (n->parent == parent)... it's conceivable that |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 490 | // the debug info might change; the other asserts should be enough to |
| 491 | // detect anything strange. |
| 492 | } else { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 493 | lineCC* parent = get_lineCC(instr_addr); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 494 | n->instr_addr = instr_addr; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 495 | n->instr_len = instr_len; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 496 | n->data_size = data_size; |
| 497 | n->parent = parent; |
| 498 | } |
| 499 | } |
| 500 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 501 | static Bool loadStoreAddrsMatch(IRExpr* loadAddrExpr, IRExpr* storeAddrExpr) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 502 | { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 503 | // I'm assuming that for 'modify' instructions, that Vex always makes |
| 504 | // the loadAddrExpr and storeAddrExpr be of the same type, ie. both Tmp |
| 505 | // expressions, or both Const expressions. |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 506 | tl_assert(isIRAtom(loadAddrExpr)); |
| 507 | tl_assert(isIRAtom(storeAddrExpr)); |
| 508 | return eqIRAtom(loadAddrExpr, storeAddrExpr); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | // Instrumentation for the end of each original instruction. |
| 512 | static |
| 513 | void endOfInstr(IRBB* bbOut, instr_info* i_node, Bool bbSeenBefore, |
| 514 | UInt instrAddr, UInt instrLen, UInt dataSize, |
| 515 | IRExpr* loadAddrExpr, IRExpr* storeAddrExpr) |
| 516 | { |
| 517 | IRDirty* di; |
| 518 | IRExpr *arg1, *arg2, *arg3, **argv; |
| 519 | Int argc; |
| 520 | Char* helperName; |
| 521 | void* helperAddr; |
sewardj | 17a56bf | 2005-03-21 01:35:02 +0000 | [diff] [blame] | 522 | IRType wordTy; |
| 523 | |
| 524 | // Stay sane ... |
| 525 | tl_assert(sizeof(HWord) == sizeof(void*)); |
| 526 | if (sizeof(HWord) == 4) { |
| 527 | wordTy = Ity_I32; |
| 528 | } else |
| 529 | if (sizeof(HWord) == 8) { |
| 530 | wordTy = Ity_I64; |
| 531 | } else { |
| 532 | VG_(tool_panic)("endOfInstr: strange word size"); |
| 533 | } |
| 534 | |
| 535 | if (loadAddrExpr) |
| 536 | tl_assert(wordTy == typeOfIRExpr(bbOut->tyenv, loadAddrExpr)); |
| 537 | if (storeAddrExpr) |
| 538 | tl_assert(wordTy == typeOfIRExpr(bbOut->tyenv, storeAddrExpr)); |
| 539 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 540 | |
| 541 | // Nb: instrLen will be zero if Vex failed to decode it. |
| 542 | tl_assert( 0 == instrLen || |
njn | a60a7c1 | 2005-05-08 17:49:37 +0000 | [diff] [blame] | 543 | (instrLen >= VGA_MIN_INSTR_SZB && |
| 544 | instrLen <= VGA_MAX_INSTR_SZB) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 545 | |
njn | 016712a | 2005-04-04 02:52:16 +0000 | [diff] [blame] | 546 | // Large (eg. 28B, 108B, 512B on x86) data-sized instructions will be |
| 547 | // done inaccurately, but they're very rare and this avoids errors from |
| 548 | // hitting more than two cache lines in the simulation. |
| 549 | if (dataSize > MIN_LINE_SIZE) dataSize = MIN_LINE_SIZE; |
| 550 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 551 | // Setup 1st arg: instr_info node's address |
sewardj | 17a56bf | 2005-03-21 01:35:02 +0000 | [diff] [blame] | 552 | // Believed to be 64-bit clean |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 553 | do_details(i_node, bbSeenBefore, instrAddr, instrLen, dataSize ); |
sewardj | 17a56bf | 2005-03-21 01:35:02 +0000 | [diff] [blame] | 554 | arg1 = mkIRExpr_HWord( (HWord)i_node ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 555 | |
| 556 | if (!loadAddrExpr && !storeAddrExpr) { |
| 557 | // no load/store |
| 558 | tl_assert(0 == dataSize); |
| 559 | helperName = "log_1I_0D_cache_access"; |
| 560 | helperAddr = &log_1I_0D_cache_access; |
| 561 | argc = 1; |
| 562 | argv = mkIRExprVec_1(arg1); |
| 563 | |
| 564 | } else if (loadAddrExpr && !storeAddrExpr) { |
| 565 | // load |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 566 | tl_assert( isIRAtom(loadAddrExpr) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 567 | helperName = "log_1I_1Dr_cache_access"; |
| 568 | helperAddr = &log_1I_1Dr_cache_access; |
| 569 | argc = 2; |
| 570 | arg2 = loadAddrExpr; |
| 571 | argv = mkIRExprVec_2(arg1, arg2); |
| 572 | |
| 573 | } else if (!loadAddrExpr && storeAddrExpr) { |
| 574 | // store |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 575 | tl_assert( isIRAtom(storeAddrExpr) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 576 | helperName = "log_1I_1Dw_cache_access"; |
| 577 | helperAddr = &log_1I_1Dw_cache_access; |
| 578 | argc = 2; |
| 579 | arg2 = storeAddrExpr; |
| 580 | argv = mkIRExprVec_2(arg1, arg2); |
| 581 | |
| 582 | } else { |
| 583 | tl_assert( loadAddrExpr && storeAddrExpr ); |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 584 | tl_assert( isIRAtom(loadAddrExpr) ); |
| 585 | tl_assert( isIRAtom(storeAddrExpr) ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 586 | |
| 587 | if ( loadStoreAddrsMatch(loadAddrExpr, storeAddrExpr) ) { |
| 588 | // modify |
| 589 | helperName = "log_1I_1Dr_cache_access"; |
| 590 | helperAddr = &log_1I_1Dr_cache_access; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 591 | argc = 2; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 592 | arg2 = loadAddrExpr; |
| 593 | argv = mkIRExprVec_2(arg1, arg2); |
| 594 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 595 | } else { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 596 | // load/store |
| 597 | helperName = "log_1I_2D_cache_access"; |
| 598 | helperAddr = &log_1I_2D_cache_access; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 599 | argc = 3; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 600 | arg2 = loadAddrExpr; |
| 601 | arg3 = storeAddrExpr; |
| 602 | argv = mkIRExprVec_3(arg1, arg2, arg3); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 606 | // Add call to the instrumentation function |
| 607 | di = unsafeIRDirty_0_N( argc, helperName, helperAddr, argv); |
| 608 | addStmtToIRBB( bbOut, IRStmt_Dirty(di) ); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 609 | } |
njn | 14d01ce | 2004-11-26 11:30:14 +0000 | [diff] [blame] | 610 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 611 | static IRBB* cg_instrument ( IRBB* bbIn, VexGuestLayout* layout, |
| 612 | IRType gWordTy, IRType hWordTy ) |
njn | 14d01ce | 2004-11-26 11:30:14 +0000 | [diff] [blame] | 613 | { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 614 | Int i, dataSize = 0, bbInfo_i; |
| 615 | IRBB* bbOut; |
| 616 | IRStmt* st; |
| 617 | BB_info* bbInfo; |
| 618 | Bool bbSeenBefore = False; |
| 619 | Addr instrAddr, origAddr; |
| 620 | UInt instrLen; |
| 621 | IRExpr *loadAddrExpr, *storeAddrExpr; |
| 622 | |
sewardj | d54babf | 2005-03-21 00:55:49 +0000 | [diff] [blame] | 623 | if (gWordTy != hWordTy) { |
| 624 | /* We don't currently support this case. */ |
| 625 | VG_(tool_panic)("host/guest word size mismatch"); |
| 626 | } |
| 627 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 628 | /* Set up BB */ |
| 629 | bbOut = emptyIRBB(); |
| 630 | bbOut->tyenv = dopyIRTypeEnv(bbIn->tyenv); |
| 631 | bbOut->next = dopyIRExpr(bbIn->next); |
| 632 | bbOut->jumpkind = bbIn->jumpkind; |
| 633 | |
| 634 | // Get the first statement, and origAddr from it |
| 635 | i = 0; |
| 636 | tl_assert(bbIn->stmts_used > 0); |
| 637 | st = bbIn->stmts[0]; |
| 638 | tl_assert(Ist_IMark == st->tag); |
| 639 | origAddr = (Addr)st->Ist.IMark.addr; |
| 640 | tl_assert(origAddr == st->Ist.IMark.addr); // XXX: check no overflow |
| 641 | |
| 642 | // Get block info |
| 643 | bbInfo = get_BB_info(bbIn, origAddr, &bbSeenBefore); |
| 644 | bbInfo_i = 0; |
| 645 | |
| 646 | do { |
| 647 | // We should be at an IMark statement |
| 648 | tl_assert(Ist_IMark == st->tag); |
| 649 | |
| 650 | // Reset stuff for this original instruction |
| 651 | loadAddrExpr = storeAddrExpr = NULL; |
| 652 | dataSize = 0; |
| 653 | |
| 654 | // Process all the statements for this original instruction (ie. until |
| 655 | // the next IMark statement, or the end of the block) |
| 656 | do { |
| 657 | handleOneStatement(bbIn->tyenv, bbOut, st, &instrAddr, &instrLen, |
| 658 | &loadAddrExpr, &storeAddrExpr, &dataSize); |
| 659 | i++; |
| 660 | st = ( i < bbIn->stmts_used ? bbIn->stmts[i] : NULL ); |
| 661 | } |
| 662 | while (st && Ist_IMark != st->tag); |
| 663 | |
| 664 | // Add instrumentation for this original instruction. |
| 665 | endOfInstr(bbOut, &bbInfo->instrs[ bbInfo_i ], bbSeenBefore, |
| 666 | instrAddr, instrLen, dataSize, loadAddrExpr, storeAddrExpr); |
| 667 | |
| 668 | bbInfo_i++; |
| 669 | } |
| 670 | while (st); |
| 671 | |
| 672 | return bbOut; |
njn | 14d01ce | 2004-11-26 11:30:14 +0000 | [diff] [blame] | 673 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 674 | |
| 675 | /*------------------------------------------------------------*/ |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 676 | /*--- Cache configuration ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 677 | /*------------------------------------------------------------*/ |
| 678 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 679 | #define UNDEFINED_CACHE { -1, -1, -1 } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 680 | |
| 681 | static cache_t clo_I1_cache = UNDEFINED_CACHE; |
| 682 | static cache_t clo_D1_cache = UNDEFINED_CACHE; |
| 683 | static cache_t clo_L2_cache = UNDEFINED_CACHE; |
| 684 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 685 | /* Checks cache config is ok; makes it so if not. */ |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 686 | static |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 687 | void check_cache(cache_t* cache, Char *name) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 688 | { |
| 689 | /* First check they're all powers of two */ |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 690 | if (-1 == VG_(log2)(cache->size)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 691 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 692 | "error: %s size of %dB not a power of two; aborting.", |
| 693 | name, cache->size); |
| 694 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 695 | } |
| 696 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 697 | if (-1 == VG_(log2)(cache->assoc)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 698 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 699 | "error: %s associativity of %d not a power of two; aborting.", |
| 700 | name, cache->assoc); |
| 701 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 702 | } |
| 703 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 704 | if (-1 == VG_(log2)(cache->line_size)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 705 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 706 | "error: %s line size of %dB not a power of two; aborting.", |
| 707 | name, cache->line_size); |
| 708 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 709 | } |
| 710 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 711 | // Then check line size >= 16 -- any smaller and a single instruction could |
| 712 | // straddle three cache lines, which breaks a simulation assertion and is |
| 713 | // stupid anyway. |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 714 | if (cache->line_size < MIN_LINE_SIZE) { |
| 715 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 716 | "error: %s line size of %dB too small; aborting.", |
| 717 | name, cache->line_size); |
| 718 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | /* Then check cache size > line size (causes seg faults if not). */ |
| 722 | if (cache->size <= cache->line_size) { |
| 723 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 724 | "error: %s cache size of %dB <= line size of %dB; aborting.", |
| 725 | name, cache->size, cache->line_size); |
| 726 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | /* Then check assoc <= (size / line size) (seg faults otherwise). */ |
| 730 | if (cache->assoc > (cache->size / cache->line_size)) { |
| 731 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 732 | "warning: %s associativity > (size / line size); aborting.", name); |
| 733 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 737 | static |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 738 | void configure_caches(cache_t* I1c, cache_t* D1c, cache_t* L2c) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 739 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 740 | #define DEFINED(L) (-1 != L.size || -1 != L.assoc || -1 != L.line_size) |
| 741 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 742 | Int n_clos = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 743 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 744 | // Count how many were defined on the command line. |
| 745 | if (DEFINED(clo_I1_cache)) { n_clos++; } |
| 746 | if (DEFINED(clo_D1_cache)) { n_clos++; } |
| 747 | if (DEFINED(clo_L2_cache)) { n_clos++; } |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 748 | |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 749 | // Set the cache config (using auto-detection, if supported by the |
| 750 | // architecture) |
| 751 | VGA_(configure_caches)( I1c, D1c, L2c, (3 == n_clos) ); |
sewardj | b1a77a4 | 2002-07-13 13:31:20 +0000 | [diff] [blame] | 752 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 753 | // Then replace with any defined on the command line. |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 754 | if (DEFINED(clo_I1_cache)) { *I1c = clo_I1_cache; } |
| 755 | if (DEFINED(clo_D1_cache)) { *D1c = clo_D1_cache; } |
| 756 | if (DEFINED(clo_L2_cache)) { *L2c = clo_L2_cache; } |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 757 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 758 | // Then check values and fix if not acceptable. |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 759 | check_cache(I1c, "I1"); |
| 760 | check_cache(D1c, "D1"); |
| 761 | check_cache(L2c, "L2"); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 762 | |
| 763 | if (VG_(clo_verbosity) > 1) { |
| 764 | VG_(message)(Vg_UserMsg, "Cache configuration used:"); |
| 765 | VG_(message)(Vg_UserMsg, " I1: %dB, %d-way, %dB lines", |
| 766 | I1c->size, I1c->assoc, I1c->line_size); |
| 767 | VG_(message)(Vg_UserMsg, " D1: %dB, %d-way, %dB lines", |
| 768 | D1c->size, D1c->assoc, D1c->line_size); |
| 769 | VG_(message)(Vg_UserMsg, " L2: %dB, %d-way, %dB lines", |
| 770 | L2c->size, L2c->assoc, L2c->line_size); |
| 771 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 772 | #undef CMD_LINE_DEFINED |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 773 | } |
| 774 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 775 | /*------------------------------------------------------------*/ |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 776 | /*--- cg_fini() and related function ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 777 | /*------------------------------------------------------------*/ |
| 778 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 779 | // Total reads/writes/misses. Calculated during CC traversal at the end. |
| 780 | // All auto-zeroed. |
| 781 | static CC Ir_total; |
| 782 | static CC Dr_total; |
| 783 | static CC Dw_total; |
| 784 | |
| 785 | static Char* cachegrind_out_file; |
| 786 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 787 | static void fprint_lineCC(Int fd, lineCC* n) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 788 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 789 | Char buf[512]; |
| 790 | VG_(sprintf)(buf, "%u %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
| 791 | n->line, |
| 792 | n->Ir.a, n->Ir.m1, n->Ir.m2, |
| 793 | n->Dr.a, n->Dr.m1, n->Dr.m2, |
| 794 | n->Dw.a, n->Dw.m1, n->Dw.m2); |
| 795 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 796 | |
| 797 | Ir_total.a += n->Ir.a; Ir_total.m1 += n->Ir.m1; Ir_total.m2 += n->Ir.m2; |
| 798 | Dr_total.a += n->Dr.a; Dr_total.m1 += n->Dr.m1; Dr_total.m2 += n->Dr.m2; |
| 799 | Dw_total.a += n->Dw.a; Dw_total.m1 += n->Dw.m1; Dw_total.m2 += n->Dw.m2; |
| 800 | } |
| 801 | |
| 802 | static void fprint_CC_table_and_calc_totals(void) |
| 803 | { |
| 804 | Int fd; |
| 805 | Char buf[512]; |
| 806 | fileCC *curr_fileCC; |
| 807 | fnCC *curr_fnCC; |
| 808 | lineCC *curr_lineCC; |
| 809 | Int i, j, k; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 810 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 811 | VGP_PUSHCC(VgpCacheResults); |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 812 | |
njn | db918dd | 2003-07-22 20:45:11 +0000 | [diff] [blame] | 813 | fd = VG_(open)(cachegrind_out_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY, |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 814 | VKI_S_IRUSR|VKI_S_IWUSR); |
nethercote | 50da0f3 | 2003-10-30 10:33:30 +0000 | [diff] [blame] | 815 | if (fd < 0) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 816 | // If the file can't be opened for whatever reason (conflict |
| 817 | // between multiple cachegrinded processes?), give up now. |
njn | ee0e6a3 | 2005-04-24 00:21:01 +0000 | [diff] [blame] | 818 | VG_(message)(Vg_UserMsg, |
| 819 | "error: can't open cache simulation output file `%s'", |
| 820 | cachegrind_out_file ); |
| 821 | VG_(message)(Vg_UserMsg, |
| 822 | " ... so simulation results will be missing."); |
sewardj | 0744b6c | 2002-12-11 00:45:42 +0000 | [diff] [blame] | 823 | return; |
| 824 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 825 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 826 | // "desc:" lines (giving I1/D1/L2 cache configuration). The spaces after |
| 827 | // the 2nd colon makes cg_annotate's output look nicer. |
| 828 | VG_(sprintf)(buf, "desc: I1 cache: %s\n" |
| 829 | "desc: D1 cache: %s\n" |
| 830 | "desc: L2 cache: %s\n", |
| 831 | I1.desc_line, D1.desc_line, L2.desc_line); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 832 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 833 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 834 | // "cmd:" line |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 835 | VG_(strcpy)(buf, "cmd:"); |
| 836 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 837 | for (i = 0; i < VG_(client_argc); i++) { |
sewardj | 4bf3aba | 2005-05-13 23:32:43 +0000 | [diff] [blame^] | 838 | if (VG_(client_argv)[i] == NULL) |
| 839 | continue; |
thughes | 6f7eb9c | 2004-10-06 13:50:12 +0000 | [diff] [blame] | 840 | VG_(write)(fd, " ", 1); |
thughes | 30c43d8 | 2004-10-06 13:49:36 +0000 | [diff] [blame] | 841 | VG_(write)(fd, VG_(client_argv)[i], VG_(strlen)(VG_(client_argv)[i])); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 842 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 843 | // "events:" line |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 844 | VG_(sprintf)(buf, "\nevents: Ir I1mr I2mr Dr D1mr D2mr Dw D1mw D2mw\n"); |
| 845 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 846 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 847 | // Six loops here: three for the hash table arrays, and three for the |
| 848 | // chains hanging off the hash table arrays. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 849 | for (i = 0; i < N_FILE_ENTRIES; i++) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 850 | curr_fileCC = CC_table[i]; |
| 851 | while (curr_fileCC != NULL) { |
| 852 | VG_(sprintf)(buf, "fl=%s\n", curr_fileCC->file); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 853 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 854 | |
| 855 | for (j = 0; j < N_FN_ENTRIES; j++) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 856 | curr_fnCC = curr_fileCC->fns[j]; |
| 857 | while (curr_fnCC != NULL) { |
| 858 | VG_(sprintf)(buf, "fn=%s\n", curr_fnCC->fn); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 859 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 860 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 861 | for (k = 0; k < N_LINE_ENTRIES; k++) { |
| 862 | curr_lineCC = curr_fnCC->lines[k]; |
| 863 | while (curr_lineCC != NULL) { |
| 864 | fprint_lineCC(fd, curr_lineCC); |
| 865 | curr_lineCC = curr_lineCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 866 | } |
| 867 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 868 | curr_fnCC = curr_fnCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 869 | } |
| 870 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 871 | curr_fileCC = curr_fileCC->next; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 875 | // Summary stats must come after rest of table, since we calculate them |
| 876 | // during traversal. */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 877 | VG_(sprintf)(buf, "summary: " |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 878 | "%llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 879 | Ir_total.a, Ir_total.m1, Ir_total.m2, |
| 880 | Dr_total.a, Dr_total.m1, Dr_total.m2, |
| 881 | Dw_total.a, Dw_total.m1, Dw_total.m2); |
| 882 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 883 | VG_(close)(fd); |
| 884 | } |
| 885 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 886 | static UInt ULong_width(ULong n) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 887 | { |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 888 | UInt w = 0; |
| 889 | while (n > 0) { |
| 890 | n = n / 10; |
| 891 | w++; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 892 | } |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 893 | return w + (w-1)/3; // add space for commas |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 894 | } |
| 895 | |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 896 | static |
daywalker | 8ad1a40 | 2003-09-18 01:15:32 +0000 | [diff] [blame] | 897 | void percentify(Int n, Int ex, Int field_width, char buf[]) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 898 | { |
| 899 | int i, len, space; |
| 900 | |
daywalker | 8ad1a40 | 2003-09-18 01:15:32 +0000 | [diff] [blame] | 901 | VG_(sprintf)(buf, "%d.%d%%", n / ex, n % ex); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 902 | len = VG_(strlen)(buf); |
| 903 | space = field_width - len; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 904 | if (space < 0) space = 0; /* Allow for v. small field_width */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 905 | i = len; |
| 906 | |
| 907 | /* Right justify in field */ |
| 908 | for ( ; i >= 0; i--) buf[i + space] = buf[i]; |
| 909 | for (i = 0; i < space; i++) buf[i] = ' '; |
| 910 | } |
| 911 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 912 | static void cg_fini(Int exitcode) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 913 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 914 | static char buf1[128], buf2[128], buf3[128], fmt [128]; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 915 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 916 | CC D_total; |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 917 | ULong L2_total_m, L2_total_mr, L2_total_mw, |
| 918 | L2_total, L2_total_r, L2_total_w; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 919 | Int l1, l2, l3; |
| 920 | Int p; |
| 921 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 922 | fprint_CC_table_and_calc_totals(); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 923 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 924 | if (VG_(clo_verbosity) == 0) |
| 925 | return; |
| 926 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 927 | /* I cache results. Use the I_refs value to determine the first column |
| 928 | * width. */ |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 929 | l1 = ULong_width(Ir_total.a); |
| 930 | l2 = ULong_width(Dr_total.a); |
| 931 | l3 = ULong_width(Dw_total.a); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 932 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 933 | /* Make format string, getting width right for numbers */ |
| 934 | VG_(sprintf)(fmt, "%%s %%,%dld", l1); |
| 935 | |
| 936 | VG_(message)(Vg_UserMsg, fmt, "I refs: ", Ir_total.a); |
| 937 | VG_(message)(Vg_UserMsg, fmt, "I1 misses: ", Ir_total.m1); |
| 938 | VG_(message)(Vg_UserMsg, fmt, "L2i misses: ", Ir_total.m2); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 939 | |
| 940 | p = 100; |
| 941 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 942 | if (0 == Ir_total.a) Ir_total.a = 1; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 943 | percentify(Ir_total.m1 * 100 * p / Ir_total.a, p, l1+1, buf1); |
| 944 | VG_(message)(Vg_UserMsg, "I1 miss rate: %s", buf1); |
| 945 | |
| 946 | percentify(Ir_total.m2 * 100 * p / Ir_total.a, p, l1+1, buf1); |
| 947 | VG_(message)(Vg_UserMsg, "L2i miss rate: %s", buf1); |
| 948 | VG_(message)(Vg_UserMsg, ""); |
| 949 | |
| 950 | /* D cache results. Use the D_refs.rd and D_refs.wr values to determine the |
| 951 | * width of columns 2 & 3. */ |
| 952 | D_total.a = Dr_total.a + Dw_total.a; |
| 953 | D_total.m1 = Dr_total.m1 + Dw_total.m1; |
| 954 | D_total.m2 = Dr_total.m2 + Dw_total.m2; |
| 955 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 956 | /* Make format string, getting width right for numbers */ |
| 957 | VG_(sprintf)(fmt, "%%s %%,%dld (%%,%dld rd + %%,%dld wr)", l1, l2, l3); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 958 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 959 | VG_(message)(Vg_UserMsg, fmt, "D refs: ", |
| 960 | D_total.a, Dr_total.a, Dw_total.a); |
| 961 | VG_(message)(Vg_UserMsg, fmt, "D1 misses: ", |
| 962 | D_total.m1, Dr_total.m1, Dw_total.m1); |
| 963 | VG_(message)(Vg_UserMsg, fmt, "L2d misses: ", |
| 964 | D_total.m2, Dr_total.m2, Dw_total.m2); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 965 | |
| 966 | p = 10; |
| 967 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 968 | if (0 == D_total.a) D_total.a = 1; |
| 969 | if (0 == Dr_total.a) Dr_total.a = 1; |
| 970 | if (0 == Dw_total.a) Dw_total.a = 1; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 971 | percentify( D_total.m1 * 100 * p / D_total.a, p, l1+1, buf1); |
| 972 | percentify(Dr_total.m1 * 100 * p / Dr_total.a, p, l2+1, buf2); |
| 973 | percentify(Dw_total.m1 * 100 * p / Dw_total.a, p, l3+1, buf3); |
| 974 | VG_(message)(Vg_UserMsg, "D1 miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 975 | |
| 976 | percentify( D_total.m2 * 100 * p / D_total.a, p, l1+1, buf1); |
| 977 | percentify(Dr_total.m2 * 100 * p / Dr_total.a, p, l2+1, buf2); |
| 978 | percentify(Dw_total.m2 * 100 * p / Dw_total.a, p, l3+1, buf3); |
| 979 | VG_(message)(Vg_UserMsg, "L2d miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 980 | VG_(message)(Vg_UserMsg, ""); |
| 981 | |
| 982 | /* L2 overall results */ |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 983 | |
| 984 | L2_total = Dr_total.m1 + Dw_total.m1 + Ir_total.m1; |
| 985 | L2_total_r = Dr_total.m1 + Ir_total.m1; |
| 986 | L2_total_w = Dw_total.m1; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 987 | VG_(message)(Vg_UserMsg, fmt, "L2 refs: ", |
| 988 | L2_total, L2_total_r, L2_total_w); |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 989 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 990 | L2_total_m = Dr_total.m2 + Dw_total.m2 + Ir_total.m2; |
| 991 | L2_total_mr = Dr_total.m2 + Ir_total.m2; |
| 992 | L2_total_mw = Dw_total.m2; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 993 | VG_(message)(Vg_UserMsg, fmt, "L2 misses: ", |
| 994 | L2_total_m, L2_total_mr, L2_total_mw); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 995 | |
| 996 | percentify(L2_total_m * 100 * p / (Ir_total.a + D_total.a), p, l1+1, buf1); |
| 997 | percentify(L2_total_mr * 100 * p / (Ir_total.a + Dr_total.a), p, l2+1, buf2); |
| 998 | percentify(L2_total_mw * 100 * p / Dw_total.a, p, l3+1, buf3); |
| 999 | VG_(message)(Vg_UserMsg, "L2 miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 1000 | |
| 1001 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1002 | // Various stats |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1003 | if (VG_(clo_verbosity) > 1) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1004 | int BB_lookups = full_debug_BBs + fn_debug_BBs + |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1005 | file_line_debug_BBs + no_debug_BBs; |
| 1006 | |
| 1007 | VG_(message)(Vg_DebugMsg, ""); |
| 1008 | VG_(message)(Vg_DebugMsg, "Distinct files: %d", distinct_files); |
| 1009 | VG_(message)(Vg_DebugMsg, "Distinct fns: %d", distinct_fns); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1010 | VG_(message)(Vg_DebugMsg, "Distinct lines: %d", distinct_lines); |
| 1011 | VG_(message)(Vg_DebugMsg, "Distinct instrs: %d", distinct_instrs); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1012 | VG_(message)(Vg_DebugMsg, "BB lookups: %d", BB_lookups); |
| 1013 | VG_(message)(Vg_DebugMsg, "With full debug info:%3d%% (%d)", |
| 1014 | full_debug_BBs * 100 / BB_lookups, |
| 1015 | full_debug_BBs); |
| 1016 | VG_(message)(Vg_DebugMsg, "With file/line debug info:%3d%% (%d)", |
| 1017 | file_line_debug_BBs * 100 / BB_lookups, |
| 1018 | file_line_debug_BBs); |
| 1019 | VG_(message)(Vg_DebugMsg, "With fn name debug info:%3d%% (%d)", |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1020 | fn_debug_BBs * 100 / BB_lookups, |
| 1021 | fn_debug_BBs); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1022 | VG_(message)(Vg_DebugMsg, "With no debug info:%3d%% (%d)", |
| 1023 | no_debug_BBs * 100 / BB_lookups, |
| 1024 | no_debug_BBs); |
| 1025 | VG_(message)(Vg_DebugMsg, "BBs Retranslated: %d", BB_retranslations); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1026 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1027 | VGP_POPCC(VgpCacheResults); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1030 | /*--------------------------------------------------------------------*/ |
| 1031 | /*--- Discarding BB info ---*/ |
| 1032 | /*--------------------------------------------------------------------*/ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1033 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1034 | // Called when a translation is invalidated due to code unloading. |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1035 | static void cg_discard_basic_block_info ( Addr a, SizeT size ) |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1036 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1037 | VgHashNode** prev_next_ptr; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 1038 | VgHashNode* bbInfo; |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 1039 | |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 1040 | if (0) VG_(printf)( "discard_basic_block_info: %p, %llu\n", a, (ULong)size); |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 1041 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1042 | // Get BB info, remove from table, free BB info. Simple! |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 1043 | bbInfo = VG_(HT_get_node)(instr_info_table, a, &prev_next_ptr); |
| 1044 | tl_assert(NULL != bbInfo); |
| 1045 | *prev_next_ptr = bbInfo->next; |
| 1046 | VG_(free)(bbInfo); |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | /*--------------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1050 | /*--- Command line processing ---*/ |
| 1051 | /*--------------------------------------------------------------------*/ |
| 1052 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1053 | static void parse_cache_opt ( cache_t* cache, char* opt ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1054 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1055 | int i = 0, i2, i3; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1056 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1057 | // Option argument looks like "65536,2,64". |
| 1058 | // Find commas, replace with NULs to make three independent |
| 1059 | // strings, then extract numbers, put NULs back. Yuck. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1060 | while (VG_(isdigit)(opt[i])) i++; |
| 1061 | if (',' == opt[i]) { |
| 1062 | opt[i++] = '\0'; |
| 1063 | i2 = i; |
| 1064 | } else goto bad; |
| 1065 | while (VG_(isdigit)(opt[i])) i++; |
| 1066 | if (',' == opt[i]) { |
| 1067 | opt[i++] = '\0'; |
| 1068 | i3 = i; |
| 1069 | } else goto bad; |
| 1070 | while (VG_(isdigit)(opt[i])) i++; |
| 1071 | if ('\0' != opt[i]) goto bad; |
| 1072 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1073 | cache->size = (Int)VG_(atoll)(opt); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1074 | cache->assoc = (Int)VG_(atoll)(opt + i2); |
| 1075 | cache->line_size = (Int)VG_(atoll)(opt + i3); |
| 1076 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1077 | opt[i2-1] = ','; |
| 1078 | opt[i3-1] = ','; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1079 | return; |
| 1080 | |
| 1081 | bad: |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1082 | VG_(bad_option)(opt); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1085 | static Bool cg_process_cmd_line_option(Char* arg) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1086 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1087 | // 5 is length of "--I1=" |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1088 | if (VG_CLO_STREQN(5, arg, "--I1=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1089 | parse_cache_opt(&clo_I1_cache, &arg[5]); |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1090 | else if (VG_CLO_STREQN(5, arg, "--D1=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1091 | parse_cache_opt(&clo_D1_cache, &arg[5]); |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1092 | else if (VG_CLO_STREQN(5, arg, "--L2=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1093 | parse_cache_opt(&clo_L2_cache, &arg[5]); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1094 | else |
| 1095 | return False; |
| 1096 | |
| 1097 | return True; |
| 1098 | } |
| 1099 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1100 | static void cg_print_usage(void) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1101 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1102 | VG_(printf)( |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1103 | " --I1=<size>,<assoc>,<line_size> set I1 cache manually\n" |
| 1104 | " --D1=<size>,<assoc>,<line_size> set D1 cache manually\n" |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1105 | " --L2=<size>,<assoc>,<line_size> set L2 cache manually\n" |
| 1106 | ); |
| 1107 | } |
| 1108 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1109 | static void cg_print_debug_usage(void) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1110 | { |
| 1111 | VG_(printf)( |
| 1112 | " (none)\n" |
| 1113 | ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | /*--------------------------------------------------------------------*/ |
| 1117 | /*--- Setup ---*/ |
| 1118 | /*--------------------------------------------------------------------*/ |
| 1119 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1120 | static void cg_post_clo_init(void) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1121 | { |
| 1122 | cache_t I1c, D1c, L2c; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1123 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 1124 | configure_caches(&I1c, &D1c, &L2c); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1125 | |
| 1126 | cachesim_I1_initcache(I1c); |
| 1127 | cachesim_D1_initcache(D1c); |
| 1128 | cachesim_L2_initcache(L2c); |
| 1129 | |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 1130 | VG_(register_profile_event)(VgpGetLineCC, "get-lineCC"); |
| 1131 | VG_(register_profile_event)(VgpCacheSimulate, "cache-simulate"); |
| 1132 | VG_(register_profile_event)(VgpCacheResults, "cache-results"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1135 | static void cg_pre_clo_init(void) |
| 1136 | { |
| 1137 | Char* base_dir = NULL; |
| 1138 | |
| 1139 | VG_(details_name) ("Cachegrind"); |
| 1140 | VG_(details_version) (NULL); |
| 1141 | VG_(details_description) ("an I1/D1/L2 cache profiler"); |
| 1142 | VG_(details_copyright_author)( |
| 1143 | "Copyright (C) 2002-2005, and GNU GPL'd, by Nicholas Nethercote et al."); |
| 1144 | VG_(details_bug_reports_to) (VG_BUGS_TO); |
| 1145 | VG_(details_avg_translation_sizeB) ( 155 ); |
| 1146 | |
| 1147 | VG_(basic_tool_funcs) (cg_post_clo_init, |
| 1148 | cg_instrument, |
| 1149 | cg_fini); |
| 1150 | |
| 1151 | VG_(needs_basic_block_discards)(cg_discard_basic_block_info); |
| 1152 | VG_(needs_command_line_options)(cg_process_cmd_line_option, |
| 1153 | cg_print_usage, |
| 1154 | cg_print_debug_usage); |
| 1155 | |
| 1156 | /* Get working directory */ |
| 1157 | tl_assert( VG_(getcwd_alloc)(&base_dir) ); |
| 1158 | |
| 1159 | /* Block is big enough for dir name + cachegrind.out.<pid> */ |
| 1160 | cachegrind_out_file = VG_(malloc)((VG_(strlen)(base_dir) + 32)*sizeof(Char)); |
| 1161 | VG_(sprintf)(cachegrind_out_file, "%s/cachegrind.out.%d", |
| 1162 | base_dir, VG_(getpid)()); |
| 1163 | VG_(free)(base_dir); |
| 1164 | |
| 1165 | instr_info_table = VG_(HT_construct)(); |
| 1166 | } |
| 1167 | |
| 1168 | VG_DETERMINE_INTERFACE_VERSION(cg_pre_clo_init, 0) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1169 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1170 | /*--------------------------------------------------------------------*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 1171 | /*--- end cg_main.c ---*/ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1172 | /*--------------------------------------------------------------------*/ |