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