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 | 97405b2 | 2005-06-02 03:39:33 +0000 | [diff] [blame] | 34 | #include "pub_tool_libcbase.h" |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 35 | #include "pub_tool_libcassert.h" |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 36 | #include "pub_tool_libcfile.h" |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 37 | #include "pub_tool_libcprint.h" |
njn | f39e9a3 | 2005-06-12 02:43:17 +0000 | [diff] [blame] | 38 | #include "pub_tool_libcproc.h" |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 39 | #include "pub_tool_machine.h" |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 40 | #include "pub_tool_mallocfree.h" |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 41 | #include "pub_tool_options.h" |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 42 | #include "pub_tool_oset.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" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 45 | #include "pub_tool_clientstate.h" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 46 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 47 | #include "cg_arch.h" |
nethercote | 27fc1da | 2004-01-04 16:56:57 +0000 | [diff] [blame] | 48 | #include "cg_sim.c" |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 49 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 50 | /*------------------------------------------------------------*/ |
| 51 | /*--- Constants ---*/ |
| 52 | /*------------------------------------------------------------*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 53 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 54 | /* Set to 1 for very verbose debugging */ |
| 55 | #define DEBUG_CG 0 |
| 56 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 57 | #define MIN_LINE_SIZE 16 |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 58 | #define FILE_LEN VKI_PATH_MAX |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 59 | #define FN_LEN 256 |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 60 | |
| 61 | /*------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 62 | /*--- Profiling events ---*/ |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 63 | /*------------------------------------------------------------*/ |
| 64 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 65 | typedef |
| 66 | enum { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 67 | VgpGetLineCC = VgpFini+1, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 68 | VgpCacheSimulate, |
| 69 | VgpCacheResults |
| 70 | } |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 71 | VgpToolCC; |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 72 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 73 | /*------------------------------------------------------------*/ |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 74 | /*--- Types and Data Structures ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 75 | /*------------------------------------------------------------*/ |
| 76 | |
| 77 | typedef struct _CC CC; |
| 78 | struct _CC { |
| 79 | ULong a; |
| 80 | ULong m1; |
| 81 | ULong m2; |
| 82 | }; |
| 83 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 84 | //------------------------------------------------------------ |
| 85 | // Primary data structure #1: CC table |
| 86 | // - Holds the per-source-line hit/miss stats, grouped by file/function/line. |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 87 | // - an ordered set of CCs. CC indexing done by file/function/line (as |
| 88 | // determined from the instrAddr). |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 89 | // - Traversed for dumping stats at end in file/func/line hierarchy. |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 90 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 91 | typedef struct { |
| 92 | Char* file; |
| 93 | Char* fn; |
| 94 | Int line; |
| 95 | } |
| 96 | CodeLoc; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 97 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 98 | typedef struct _LineCC LineCC; |
| 99 | struct _LineCC { |
| 100 | CodeLoc loc; |
| 101 | CC Ir; |
| 102 | CC Dr; |
| 103 | CC Dw; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 106 | // First compare file, then fn, then line. |
| 107 | static Int cmp_CodeLoc_LineCC(void *vloc, void *vcc) |
| 108 | { |
| 109 | Int res; |
| 110 | CodeLoc* a = (CodeLoc*)vloc; |
| 111 | CodeLoc* b = &(((LineCC*)vcc)->loc); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 112 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 113 | res = VG_(strcmp)(a->file, b->file); |
| 114 | if (0 != res) |
| 115 | return res; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 116 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 117 | res = VG_(strcmp)(a->fn, b->fn); |
| 118 | if (0 != res) |
| 119 | return res; |
| 120 | |
| 121 | return a->line - b->line; |
| 122 | } |
| 123 | |
| 124 | static OSet* CC_table; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 125 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 126 | //------------------------------------------------------------ |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 127 | // Primary data structure #2: InstrInfo table |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 128 | // - Holds the cached info about each instr that is used for simulation. |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 129 | // - table(BB_start_addr, list(InstrInfo)) |
| 130 | // - For each BB, each InstrInfo in the list holds info about the |
| 131 | // instruction (instrLen, instrAddr, etc), plus a pointer to its line |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 132 | // CC. This node is what's passed to the simulation function. |
| 133 | // - When BBs are discarded the relevant list(instr_details) is freed. |
| 134 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 135 | typedef struct _InstrInfo InstrInfo; |
| 136 | struct _InstrInfo { |
nethercote | ca1f2dc | 2004-07-21 08:49:02 +0000 | [diff] [blame] | 137 | Addr instr_addr; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 138 | UChar instr_len; |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 139 | LineCC* parent; // parent line-CC |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | typedef struct _BB_info BB_info; |
| 143 | struct _BB_info { |
sewardj | 4ba057c | 2005-10-18 12:04:18 +0000 | [diff] [blame] | 144 | Addr BB_addr; // key; MUST BE FIRST |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 145 | Int n_instrs; |
| 146 | InstrInfo instrs[0]; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 149 | static OSet* instrInfoTable; |
| 150 | |
| 151 | //------------------------------------------------------------ |
| 152 | // Secondary data structure: string table |
| 153 | // - holds strings, avoiding dups |
| 154 | // - used for filenames and function names, each of which will be |
| 155 | // pointed to by one or more CCs. |
| 156 | // - it also allows equality checks just by pointer comparison, which |
| 157 | // is good when printing the output file at the end. |
| 158 | |
| 159 | static OSet* stringTable; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 160 | |
| 161 | //------------------------------------------------------------ |
| 162 | // Stats |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 163 | static Int distinct_files = 0; |
| 164 | static Int distinct_fns = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 165 | static Int distinct_lines = 0; |
sewardj | 4f29ddf | 2002-05-03 22:29:04 +0000 | [diff] [blame] | 166 | static Int distinct_instrs = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 167 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 168 | static Int full_debugs = 0; |
| 169 | static Int file_line_debugs = 0; |
| 170 | static Int fn_debugs = 0; |
| 171 | static Int no_debugs = 0; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 172 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 173 | /*------------------------------------------------------------*/ |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 174 | /*--- String table operations ---*/ |
| 175 | /*------------------------------------------------------------*/ |
| 176 | |
| 177 | static Int stringCmp( void* key, void* elem ) |
| 178 | { |
| 179 | return VG_(strcmp)(*(Char**)key, *(Char**)elem); |
| 180 | } |
| 181 | |
| 182 | // Get a permanent string; either pull it out of the string table if it's |
| 183 | // been encountered before, or dup it and put it into the string table. |
| 184 | static Char* get_perm_string(Char* s) |
| 185 | { |
| 186 | Char** s_ptr = VG_(OSet_Lookup)(stringTable, &s); |
| 187 | if (s_ptr) { |
| 188 | return *s_ptr; |
| 189 | } else { |
| 190 | Char** s_node = VG_(OSet_AllocNode)(stringTable, sizeof(Char*)); |
| 191 | *s_node = VG_(strdup)(s); |
| 192 | VG_(OSet_Insert)(stringTable, s_node); |
| 193 | return *s_node; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /*------------------------------------------------------------*/ |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 198 | /*--- CC table operations ---*/ |
| 199 | /*------------------------------------------------------------*/ |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 200 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 201 | static void get_debug_info(Addr instr_addr, Char file[FILE_LEN], |
| 202 | Char fn[FN_LEN], Int* line) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 203 | { |
sewardj | 7cee6f9 | 2005-06-13 17:39:06 +0000 | [diff] [blame] | 204 | Bool found_file_line = VG_(get_filename_linenum)( |
| 205 | instr_addr, |
| 206 | file, FILE_LEN, |
| 207 | NULL, 0, NULL, |
| 208 | line |
| 209 | ); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 210 | Bool found_fn = VG_(get_fnname)(instr_addr, fn, FN_LEN); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 211 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 212 | if (!found_file_line) { |
| 213 | VG_(strcpy)(file, "???"); |
| 214 | *line = 0; |
| 215 | } |
| 216 | if (!found_fn) { |
| 217 | VG_(strcpy)(fn, "???"); |
| 218 | } |
| 219 | if (found_file_line) { |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 220 | if (found_fn) full_debugs++; |
| 221 | else file_line_debugs++; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 222 | } else { |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 223 | if (found_fn) fn_debugs++; |
| 224 | else no_debugs++; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 228 | // Do a three step traversal: by file, then fn, then line. |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 229 | // Returns a pointer to the line CC, creates a new one if necessary. |
| 230 | static LineCC* get_lineCC(Addr origAddr) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 231 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 232 | Char file[FILE_LEN], fn[FN_LEN]; |
| 233 | Int line; |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 234 | CodeLoc loc; |
| 235 | LineCC* lineCC; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 236 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 237 | get_debug_info(origAddr, file, fn, &line); |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 238 | |
| 239 | VGP_PUSHCC(VgpGetLineCC); |
| 240 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 241 | loc.file = file; |
| 242 | loc.fn = fn; |
| 243 | loc.line = line; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 244 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 245 | lineCC = VG_(OSet_Lookup)(CC_table, &loc); |
| 246 | if (!lineCC) { |
| 247 | // Allocate and zero a new node. |
| 248 | lineCC = VG_(OSet_AllocNode)(CC_table, sizeof(LineCC)); |
| 249 | lineCC->loc.file = get_perm_string(loc.file); |
| 250 | lineCC->loc.fn = get_perm_string(loc.fn); |
| 251 | lineCC->loc.line = loc.line; |
| 252 | VG_(OSet_Insert)(CC_table, lineCC); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 253 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 254 | |
| 255 | VGP_POPCC(VgpGetLineCC); |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 256 | return lineCC; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /*------------------------------------------------------------*/ |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 260 | /*--- Cache simulation functions ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 261 | /*------------------------------------------------------------*/ |
| 262 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 263 | static VG_REGPARM(1) |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 264 | void log_1I_0D_cache_access(InstrInfo* n) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 265 | { |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 266 | //VG_(printf)("1I_0D : CCaddr=0x%010lx, iaddr=0x%010lx, isize=%lu\n", |
| 267 | // n, n->instr_addr, n->instr_len); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 268 | VGP_PUSHCC(VgpCacheSimulate); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 269 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 270 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 271 | n->parent->Ir.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 272 | VGP_POPCC(VgpCacheSimulate); |
| 273 | } |
| 274 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 275 | static VG_REGPARM(2) |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 276 | void log_2I_0D_cache_access(InstrInfo* n, InstrInfo* n2) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 277 | { |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 278 | //VG_(printf)("2I_0D : CC1addr=0x%010lx, i1addr=0x%010lx, i1size=%lu\n" |
| 279 | // " CC2addr=0x%010lx, i2addr=0x%010lx, i2size=%lu\n", |
| 280 | // n, n->instr_addr, n->instr_len, |
| 281 | // n2, n2->instr_addr, n2->instr_len); |
| 282 | VGP_PUSHCC(VgpCacheSimulate); |
| 283 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
| 284 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 285 | n->parent->Ir.a++; |
| 286 | cachesim_I1_doref(n2->instr_addr, n2->instr_len, |
| 287 | &n2->parent->Ir.m1, &n2->parent->Ir.m2); |
| 288 | n2->parent->Ir.a++; |
| 289 | VGP_POPCC(VgpCacheSimulate); |
| 290 | } |
| 291 | |
| 292 | static VG_REGPARM(3) |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 293 | void log_3I_0D_cache_access(InstrInfo* n, InstrInfo* n2, InstrInfo* n3) |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 294 | { |
| 295 | //VG_(printf)("3I_0D : CC1addr=0x%010lx, i1addr=0x%010lx, i1size=%lu\n" |
| 296 | // " CC2addr=0x%010lx, i2addr=0x%010lx, i2size=%lu\n" |
| 297 | // " CC3addr=0x%010lx, i3addr=0x%010lx, i3size=%lu\n", |
| 298 | // n, n->instr_addr, n->instr_len, |
| 299 | // n2, n2->instr_addr, n2->instr_len, |
| 300 | // n3, n3->instr_addr, n3->instr_len); |
| 301 | VGP_PUSHCC(VgpCacheSimulate); |
| 302 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
| 303 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 304 | n->parent->Ir.a++; |
| 305 | cachesim_I1_doref(n2->instr_addr, n2->instr_len, |
| 306 | &n2->parent->Ir.m1, &n2->parent->Ir.m2); |
| 307 | n2->parent->Ir.a++; |
| 308 | cachesim_I1_doref(n3->instr_addr, n3->instr_len, |
| 309 | &n3->parent->Ir.m1, &n3->parent->Ir.m2); |
| 310 | n3->parent->Ir.a++; |
| 311 | VGP_POPCC(VgpCacheSimulate); |
| 312 | } |
| 313 | |
| 314 | static VG_REGPARM(3) |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 315 | void log_1I_1Dr_cache_access(InstrInfo* n, Addr data_addr, Word data_size) |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 316 | { |
| 317 | //VG_(printf)("1I_1Dr: CCaddr=0x%010lx, iaddr=0x%010lx, isize=%lu\n" |
| 318 | // " daddr=0x%010lx, dsize=%lu\n", |
| 319 | // n, n->instr_addr, n->instr_len, data_addr, 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++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 324 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 325 | cachesim_D1_doref(data_addr, data_size, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 326 | &n->parent->Dr.m1, &n->parent->Dr.m2); |
| 327 | n->parent->Dr.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 328 | VGP_POPCC(VgpCacheSimulate); |
| 329 | } |
| 330 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 331 | static VG_REGPARM(3) |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 332 | void log_1I_1Dw_cache_access(InstrInfo* n, Addr data_addr, Word data_size) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 333 | { |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 334 | //VG_(printf)("1I_1Dw: CCaddr=0x%010lx, iaddr=0x%010lx, isize=%lu\n" |
| 335 | // " daddr=0x%010lx, dsize=%lu\n", |
| 336 | // n, n->instr_addr, n->instr_len, data_addr, data_size); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 337 | VGP_PUSHCC(VgpCacheSimulate); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 338 | cachesim_I1_doref(n->instr_addr, n->instr_len, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 339 | &n->parent->Ir.m1, &n->parent->Ir.m2); |
| 340 | n->parent->Ir.a++; |
| 341 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 342 | cachesim_D1_doref(data_addr, data_size, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 343 | &n->parent->Dw.m1, &n->parent->Dw.m2); |
| 344 | n->parent->Dw.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 345 | VGP_POPCC(VgpCacheSimulate); |
| 346 | } |
| 347 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 348 | static VG_REGPARM(3) |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 349 | void log_0I_1Dr_cache_access(InstrInfo* n, Addr data_addr, Word data_size) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 350 | { |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 351 | //VG_(printf)("0I_1Dr: CCaddr=0x%010lx, daddr=0x%010lx, dsize=%lu\n", |
| 352 | // n, data_addr, data_size); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 353 | VGP_PUSHCC(VgpCacheSimulate); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 354 | cachesim_D1_doref(data_addr, data_size, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 355 | &n->parent->Dr.m1, &n->parent->Dr.m2); |
| 356 | n->parent->Dr.a++; |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 357 | VGP_POPCC(VgpCacheSimulate); |
| 358 | } |
| 359 | |
| 360 | static VG_REGPARM(3) |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 361 | void log_0I_1Dw_cache_access(InstrInfo* n, Addr data_addr, Word data_size) |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 362 | { |
| 363 | //VG_(printf)("0I_1Dw: CCaddr=0x%010lx, daddr=0x%010lx, dsize=%lu\n", |
| 364 | // n, data_addr, data_size); |
| 365 | VGP_PUSHCC(VgpCacheSimulate); |
| 366 | cachesim_D1_doref(data_addr, data_size, |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 367 | &n->parent->Dw.m1, &n->parent->Dw.m2); |
| 368 | n->parent->Dw.a++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 369 | VGP_POPCC(VgpCacheSimulate); |
| 370 | } |
| 371 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 372 | /*------------------------------------------------------------*/ |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 373 | /*--- Instrumentation types and structures ---*/ |
| 374 | /*------------------------------------------------------------*/ |
| 375 | |
| 376 | /* Maintain an ordered list of memory events which are outstanding, in |
| 377 | the sense that no IR has yet been generated to do the relevant |
| 378 | helper calls. The BB is scanned top to bottom and memory events |
| 379 | are added to the end of the list, merging with the most recent |
| 380 | notified event where possible (Dw immediately following Dr and |
| 381 | having the same size and EA can be merged). |
| 382 | |
| 383 | This merging is done so that for architectures which have |
| 384 | load-op-store instructions (x86, amd64), the insn is treated as if |
| 385 | it makes just one memory reference (a modify), rather than two (a |
| 386 | read followed by a write at the same address). |
| 387 | |
| 388 | At various points the list will need to be flushed, that is, IR |
| 389 | generated from it. That must happen before any possible exit from |
| 390 | the block (the end, or an IRStmt_Exit). Flushing also takes place |
| 391 | when there is no space to add a new event. |
| 392 | |
| 393 | If we require the simulation statistics to be up to date with |
| 394 | respect to possible memory exceptions, then the list would have to |
| 395 | be flushed before each memory reference. That would however lose |
| 396 | performance by inhibiting event-merging during flushing. |
| 397 | |
| 398 | Flushing the list consists of walking it start to end and emitting |
| 399 | instrumentation IR for each event, in the order in which they |
| 400 | appear. It may be possible to emit a single call for two adjacent |
| 401 | events in order to reduce the number of helper function calls made. |
| 402 | For example, it could well be profitable to handle two adjacent Ir |
| 403 | events with a single helper call. */ |
| 404 | |
| 405 | typedef |
| 406 | IRExpr |
| 407 | IRAtom; |
| 408 | |
| 409 | typedef |
sewardj | 20edebf | 2005-10-12 10:29:40 +0000 | [diff] [blame] | 410 | enum { Event_Ir, Event_Dr, Event_Dw, Event_Dm } |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 411 | EventKind; |
| 412 | |
| 413 | typedef |
| 414 | struct { |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 415 | EventKind ekind; // All |
| 416 | InstrInfo* inode; // All; inode for this event's instruction |
| 417 | Int datasize; // Dr/Dw/Dm only |
| 418 | IRAtom* dataEA; // Dr/Dw/Dm only; IR ATOM ONLY |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 419 | } |
| 420 | Event; |
| 421 | |
| 422 | /* Up to this many unnotified events are allowed. Number is |
| 423 | arbitrary. Larger numbers allow more event merging to occur, but |
| 424 | potentially induce more spilling due to extending live ranges of |
| 425 | address temporaries. */ |
| 426 | #define N_EVENTS 16 |
| 427 | |
| 428 | |
| 429 | /* A struct which holds all the running state during instrumentation. |
| 430 | Mostly to avoid passing loads of parameters everywhere. */ |
| 431 | typedef |
| 432 | struct { |
| 433 | /* The current outstanding-memory-event list. */ |
| 434 | Event events[N_EVENTS]; |
| 435 | Int events_used; |
| 436 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 437 | /* The array of InstrInfo bins for the BB. */ |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 438 | BB_info* bbInfo; |
| 439 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 440 | /* Number InstrInfo bins 'used' so far. */ |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 441 | Int bbInfo_i; |
| 442 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 443 | /* The output BB being constructed. */ |
| 444 | IRBB* bbOut; |
| 445 | } |
| 446 | CgState; |
| 447 | |
| 448 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 449 | /*------------------------------------------------------------*/ |
| 450 | /*--- Instrumentation main ---*/ |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 451 | /*------------------------------------------------------------*/ |
| 452 | |
sewardj | 4ba057c | 2005-10-18 12:04:18 +0000 | [diff] [blame] | 453 | // Note that origAddr is the real origAddr, not the address of the first |
| 454 | // instruction in the block (they can be different due to redirection). |
nethercote | 564b2b0 | 2004-08-07 15:54:53 +0000 | [diff] [blame] | 455 | static |
sewardj | a3a29a5 | 2005-10-12 16:16:03 +0000 | [diff] [blame] | 456 | BB_info* get_BB_info(IRBB* bbIn, Addr origAddr) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 457 | { |
njn | 4bd67b5 | 2005-08-11 00:47:10 +0000 | [diff] [blame] | 458 | Int i, n_instrs; |
| 459 | IRStmt* st; |
| 460 | BB_info* bbInfo; |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 461 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 462 | // Count number of original instrs in BB |
| 463 | n_instrs = 0; |
| 464 | for (i = 0; i < bbIn->stmts_used; i++) { |
| 465 | st = bbIn->stmts[i]; |
| 466 | if (Ist_IMark == st->tag) n_instrs++; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 467 | } |
| 468 | |
njn | f7d2609 | 2005-10-12 16:45:17 +0000 | [diff] [blame] | 469 | // Check that we don't have an entry for this BB in the instr-info table. |
| 470 | // If this assertion fails, there has been some screwup: some |
| 471 | // translations must have been discarded but Cachegrind hasn't discarded |
| 472 | // the corresponding entries in the instr-info table. |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 473 | bbInfo = VG_(OSet_Lookup)(instrInfoTable, &origAddr); |
sewardj | a3a29a5 | 2005-10-12 16:16:03 +0000 | [diff] [blame] | 474 | tl_assert(NULL == bbInfo); |
| 475 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 476 | // BB never translated before (at this address, at least; could have |
| 477 | // been unloaded and then reloaded elsewhere in memory) |
| 478 | bbInfo = VG_(OSet_AllocNode)(instrInfoTable, |
| 479 | sizeof(BB_info) + n_instrs*sizeof(InstrInfo)); |
| 480 | bbInfo->BB_addr = origAddr; |
sewardj | a3a29a5 | 2005-10-12 16:16:03 +0000 | [diff] [blame] | 481 | bbInfo->n_instrs = n_instrs; |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 482 | VG_(OSet_Insert)( instrInfoTable, bbInfo ); |
sewardj | a3a29a5 | 2005-10-12 16:16:03 +0000 | [diff] [blame] | 483 | distinct_instrs++; |
| 484 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 485 | return bbInfo; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 486 | } |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 487 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 488 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 489 | static void showEvent ( Event* ev ) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 490 | { |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 491 | switch (ev->ekind) { |
| 492 | case Event_Ir: |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 493 | VG_(printf)("Ir %p\n", ev->inode); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 494 | break; |
| 495 | case Event_Dr: |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 496 | VG_(printf)("Dr %p %d EA=", ev->inode, ev->datasize); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 497 | ppIRExpr(ev->dataEA); |
| 498 | VG_(printf)("\n"); |
| 499 | break; |
| 500 | case Event_Dw: |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 501 | VG_(printf)("Dw %p %d EA=", ev->inode, ev->datasize); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 502 | ppIRExpr(ev->dataEA); |
| 503 | VG_(printf)("\n"); |
| 504 | break; |
| 505 | case Event_Dm: |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 506 | VG_(printf)("Dm %p %d EA=", ev->inode, ev->datasize); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 507 | ppIRExpr(ev->dataEA); |
| 508 | VG_(printf)("\n"); |
| 509 | break; |
| 510 | default: |
| 511 | tl_assert(0); |
| 512 | break; |
| 513 | } |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 514 | } |
| 515 | |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 516 | // Reserve and initialise an InstrInfo for the first mention of a new insn. |
| 517 | static |
| 518 | InstrInfo* setup_InstrInfo ( CgState* cgs, Addr instr_addr, UInt instr_len ) |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 519 | { |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 520 | InstrInfo* i_node; |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 521 | tl_assert(cgs->bbInfo_i >= 0); |
| 522 | tl_assert(cgs->bbInfo_i < cgs->bbInfo->n_instrs); |
| 523 | i_node = &cgs->bbInfo->instrs[ cgs->bbInfo_i ]; |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 524 | i_node->instr_addr = instr_addr; |
| 525 | i_node->instr_len = instr_len; |
| 526 | i_node->parent = get_lineCC(instr_addr); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 527 | cgs->bbInfo_i++; |
| 528 | return i_node; |
| 529 | } |
sewardj | 17a56bf | 2005-03-21 01:35:02 +0000 | [diff] [blame] | 530 | |
sewardj | 17a56bf | 2005-03-21 01:35:02 +0000 | [diff] [blame] | 531 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 532 | /* Generate code for all outstanding memory events, and mark the queue |
| 533 | empty. Code is generated into cgs->bbOut, and this activity |
| 534 | 'consumes' slots in cgs->bbInfo. */ |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 535 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 536 | static void flushEvents ( CgState* cgs ) |
| 537 | { |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 538 | Int i, regparms; |
| 539 | Char* helperName; |
| 540 | void* helperAddr; |
| 541 | IRExpr** argv; |
| 542 | IRExpr* i_node_expr; |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 543 | IRDirty* di; |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 544 | Event* ev; |
| 545 | Event* ev2; |
| 546 | Event* ev3; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 547 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 548 | i = 0; |
| 549 | while (i < cgs->events_used) { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 550 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 551 | helperName = NULL; |
| 552 | helperAddr = NULL; |
| 553 | argv = NULL; |
| 554 | regparms = 0; |
| 555 | |
| 556 | /* generate IR to notify event i and possibly the ones |
| 557 | immediately following it. */ |
| 558 | tl_assert(i >= 0 && i < cgs->events_used); |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 559 | |
| 560 | ev = &cgs->events[i]; |
| 561 | ev2 = ( i < cgs->events_used-1 ? &cgs->events[i+1] : NULL ); |
| 562 | ev3 = ( i < cgs->events_used-2 ? &cgs->events[i+2] : NULL ); |
| 563 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 564 | if (DEBUG_CG) { |
| 565 | VG_(printf)(" flush "); |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 566 | showEvent( ev ); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 567 | } |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 568 | |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 569 | i_node_expr = mkIRExpr_HWord( (HWord)ev->inode ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 570 | |
| 571 | /* Decide on helper fn to call and args to pass it, and advance |
| 572 | i appropriately. */ |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 573 | switch (ev->ekind) { |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 574 | case Event_Ir: |
| 575 | /* Merge with a following Dr/Dm if it is from this insn. */ |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 576 | if (ev2 && (ev2->ekind == Event_Dr || ev2->ekind == Event_Dm)) { |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 577 | tl_assert(ev2->inode == ev->inode); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 578 | helperName = "log_1I_1Dr_cache_access"; |
| 579 | helperAddr = &log_1I_1Dr_cache_access; |
| 580 | argv = mkIRExprVec_3( i_node_expr, |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 581 | ev2->dataEA, |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 582 | mkIRExpr_HWord( ev2->datasize ) ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 583 | regparms = 3; |
| 584 | i += 2; |
| 585 | } |
| 586 | /* Merge with a following Dw if it is from this insn. */ |
| 587 | else |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 588 | if (ev2 && ev2->ekind == Event_Dw) { |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 589 | tl_assert(ev2->inode == ev->inode); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 590 | helperName = "log_1I_1Dw_cache_access"; |
| 591 | helperAddr = &log_1I_1Dw_cache_access; |
| 592 | argv = mkIRExprVec_3( i_node_expr, |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 593 | ev2->dataEA, |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 594 | mkIRExpr_HWord( ev2->datasize ) ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 595 | regparms = 3; |
| 596 | i += 2; |
| 597 | } |
| 598 | /* Merge with two following Irs if possible. */ |
| 599 | else |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 600 | if (ev2 && ev3 && ev2->ekind == Event_Ir && ev3->ekind == Event_Ir) |
| 601 | { |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 602 | helperName = "log_3I_0D_cache_access"; |
| 603 | helperAddr = &log_3I_0D_cache_access; |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 604 | argv = mkIRExprVec_3( i_node_expr, |
| 605 | mkIRExpr_HWord( (HWord)ev2->inode ), |
| 606 | mkIRExpr_HWord( (HWord)ev3->inode ) ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 607 | regparms = 3; |
| 608 | i += 3; |
| 609 | } |
| 610 | /* Merge with a following Ir if possible. */ |
| 611 | else |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 612 | if (ev2 && ev2->ekind == Event_Ir) { |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 613 | helperName = "log_2I_0D_cache_access"; |
| 614 | helperAddr = &log_2I_0D_cache_access; |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 615 | argv = mkIRExprVec_2( i_node_expr, |
| 616 | mkIRExpr_HWord( (HWord)ev2->inode ) ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 617 | regparms = 2; |
| 618 | i += 2; |
| 619 | } |
| 620 | /* No merging possible; emit as-is. */ |
| 621 | else { |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 622 | // Assertion: this Event_Ir must be the last one in the |
| 623 | // events buffer, otherwise it would have been merged with a |
| 624 | // following event. |
| 625 | tl_assert(!ev2 && !ev3); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 626 | helperName = "log_1I_0D_cache_access"; |
| 627 | helperAddr = &log_1I_0D_cache_access; |
| 628 | argv = mkIRExprVec_1( i_node_expr ); |
| 629 | regparms = 1; |
| 630 | i++; |
| 631 | } |
| 632 | break; |
| 633 | case Event_Dr: |
| 634 | case Event_Dm: |
| 635 | helperName = "log_0I_1Dr_cache_access"; |
| 636 | helperAddr = &log_0I_1Dr_cache_access; |
| 637 | argv = mkIRExprVec_3( i_node_expr, |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 638 | ev->dataEA, |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 639 | mkIRExpr_HWord( ev->datasize ) ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 640 | regparms = 3; |
| 641 | i++; |
| 642 | break; |
| 643 | case Event_Dw: |
| 644 | helperName = "log_0I_1Dw_cache_access"; |
| 645 | helperAddr = &log_0I_1Dw_cache_access; |
| 646 | argv = mkIRExprVec_3( i_node_expr, |
njn | c285dca | 2005-10-15 22:07:28 +0000 | [diff] [blame] | 647 | ev->dataEA, |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 648 | mkIRExpr_HWord( ev->datasize ) ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 649 | regparms = 3; |
| 650 | i++; |
| 651 | break; |
| 652 | default: |
| 653 | tl_assert(0); |
| 654 | } |
| 655 | |
| 656 | /* Add the helper. */ |
| 657 | tl_assert(helperName); |
| 658 | tl_assert(helperAddr); |
| 659 | tl_assert(argv); |
| 660 | di = unsafeIRDirty_0_N( regparms, helperName, helperAddr, argv); |
| 661 | addStmtToIRBB( cgs->bbOut, IRStmt_Dirty(di) ); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 662 | } |
| 663 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 664 | cgs->events_used = 0; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 665 | } |
njn | 14d01ce | 2004-11-26 11:30:14 +0000 | [diff] [blame] | 666 | |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 667 | static void addEvent_Ir ( CgState* cgs, InstrInfo* inode ) |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 668 | { |
| 669 | Event* evt; |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 670 | if (cgs->events_used == N_EVENTS) |
| 671 | flushEvents(cgs); |
| 672 | tl_assert(cgs->events_used >= 0 && cgs->events_used < N_EVENTS); |
| 673 | evt = &cgs->events[cgs->events_used]; |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 674 | evt->ekind = Event_Ir; |
| 675 | evt->inode = inode; |
| 676 | evt->datasize = 0; |
| 677 | evt->dataEA = NULL; /*paranoia*/ |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 678 | cgs->events_used++; |
| 679 | } |
| 680 | |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 681 | static |
| 682 | void addEvent_Dr ( CgState* cgs, InstrInfo* inode, Int datasize, IRAtom* ea ) |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 683 | { |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 684 | Event* evt; |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 685 | tl_assert(isIRAtom(ea)); |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 686 | tl_assert(datasize >= 1 && datasize <= MIN_LINE_SIZE); |
| 687 | if (cgs->events_used == N_EVENTS) |
| 688 | flushEvents(cgs); |
| 689 | tl_assert(cgs->events_used >= 0 && cgs->events_used < N_EVENTS); |
| 690 | evt = &cgs->events[cgs->events_used]; |
| 691 | evt->ekind = Event_Dr; |
| 692 | evt->inode = inode; |
| 693 | evt->datasize = datasize; |
| 694 | evt->dataEA = ea; |
| 695 | cgs->events_used++; |
| 696 | } |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 697 | |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 698 | static |
| 699 | void addEvent_Dw ( CgState* cgs, InstrInfo* inode, Int datasize, IRAtom* ea ) |
| 700 | { |
| 701 | Event* lastEvt; |
| 702 | Event* evt; |
| 703 | |
| 704 | tl_assert(isIRAtom(ea)); |
| 705 | tl_assert(datasize >= 1 && datasize <= MIN_LINE_SIZE); |
| 706 | |
| 707 | /* Is it possible to merge this write with the preceding read? */ |
| 708 | lastEvt = &cgs->events[cgs->events_used-1]; |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 709 | if (cgs->events_used > 0 |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 710 | && lastEvt->ekind == Event_Dr |
| 711 | && lastEvt->datasize == datasize |
| 712 | && lastEvt->inode == inode |
| 713 | && eqIRAtom(lastEvt->dataEA, ea)) |
| 714 | { |
| 715 | lastEvt->ekind = Event_Dm; |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 716 | return; |
| 717 | } |
| 718 | |
| 719 | /* No. Add as normal. */ |
| 720 | if (cgs->events_used == N_EVENTS) |
| 721 | flushEvents(cgs); |
| 722 | tl_assert(cgs->events_used >= 0 && cgs->events_used < N_EVENTS); |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 723 | evt = &cgs->events[cgs->events_used]; |
| 724 | evt->ekind = Event_Dw; |
| 725 | evt->inode = inode; |
| 726 | evt->datasize = datasize; |
| 727 | evt->dataEA = ea; |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 728 | cgs->events_used++; |
| 729 | } |
| 730 | |
| 731 | //////////////////////////////////////////////////////////// |
| 732 | |
| 733 | |
sewardj | 4ba057c | 2005-10-18 12:04:18 +0000 | [diff] [blame] | 734 | static |
| 735 | IRBB* cg_instrument ( IRBB* bbIn, VexGuestLayout* layout, |
| 736 | Addr64 orig_addr_noredir, VexGuestExtents* vge, |
| 737 | IRType gWordTy, IRType hWordTy ) |
njn | 14d01ce | 2004-11-26 11:30:14 +0000 | [diff] [blame] | 738 | { |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 739 | Int i, isize; |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 740 | IRStmt* st; |
| 741 | Addr64 cia; /* address of current insn */ |
| 742 | CgState cgs; |
| 743 | IRTypeEnv* tyenv = bbIn->tyenv; |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 744 | InstrInfo* curr_inode = NULL; |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 745 | |
sewardj | d54babf | 2005-03-21 00:55:49 +0000 | [diff] [blame] | 746 | if (gWordTy != hWordTy) { |
| 747 | /* We don't currently support this case. */ |
| 748 | VG_(tool_panic)("host/guest word size mismatch"); |
| 749 | } |
| 750 | |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 751 | /* Set up BB, including copying of the where-next stuff. */ |
| 752 | cgs.bbOut = emptyIRBB(); |
| 753 | cgs.bbOut->tyenv = dopyIRTypeEnv(tyenv); |
| 754 | tl_assert( isIRAtom(bbIn->next) ); |
| 755 | cgs.bbOut->next = dopyIRExpr(bbIn->next); |
| 756 | cgs.bbOut->jumpkind = bbIn->jumpkind; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 757 | |
sewardj | a9f538c | 2005-10-23 12:06:55 +0000 | [diff] [blame] | 758 | // Copy verbatim any IR preamble preceding the first IMark |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 759 | i = 0; |
sewardj | a9f538c | 2005-10-23 12:06:55 +0000 | [diff] [blame] | 760 | while (i < bbIn->stmts_used && bbIn->stmts[i]->tag != Ist_IMark) { |
| 761 | addStmtToIRBB( cgs.bbOut, bbIn->stmts[i] ); |
| 762 | i++; |
| 763 | } |
| 764 | |
| 765 | // Get the first statement, and initial cia from it |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 766 | tl_assert(bbIn->stmts_used > 0); |
sewardj | a9f538c | 2005-10-23 12:06:55 +0000 | [diff] [blame] | 767 | tl_assert(i < bbIn->stmts_used); |
| 768 | st = bbIn->stmts[i]; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 769 | tl_assert(Ist_IMark == st->tag); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 770 | cia = st->Ist.IMark.addr; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 771 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 772 | // Set up running state and get block info |
| 773 | cgs.events_used = 0; |
sewardj | 4ba057c | 2005-10-18 12:04:18 +0000 | [diff] [blame] | 774 | cgs.bbInfo = get_BB_info(bbIn, (Addr)orig_addr_noredir); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 775 | cgs.bbInfo_i = 0; |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 776 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 777 | if (DEBUG_CG) |
| 778 | VG_(printf)("\n\n---------- cg_instrument ----------\n"); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 779 | |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 780 | // Traverse the block, initialising inodes, adding events and flushing as |
| 781 | // necessary. |
sewardj | a9f538c | 2005-10-23 12:06:55 +0000 | [diff] [blame] | 782 | for (/*use current i*/; i < bbIn->stmts_used; i++) { |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 783 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 784 | st = bbIn->stmts[i]; |
| 785 | tl_assert(isFlatIRStmt(st)); |
njn | b3507ea | 2005-08-02 23:07:02 +0000 | [diff] [blame] | 786 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 787 | switch (st->tag) { |
| 788 | case Ist_NoOp: |
| 789 | case Ist_AbiHint: |
| 790 | case Ist_Put: |
| 791 | case Ist_PutI: |
| 792 | case Ist_MFence: |
| 793 | break; |
njn | 20677cc | 2005-08-12 23:47:51 +0000 | [diff] [blame] | 794 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 795 | case Ist_IMark: |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 796 | cia = st->Ist.IMark.addr; |
| 797 | isize = st->Ist.IMark.len; |
| 798 | |
| 799 | // If Vex fails to decode an instruction, the size will be zero. |
| 800 | // Pretend otherwise. |
| 801 | if (isize == 0) isize = VG_MIN_INSTR_SZB; |
| 802 | |
njn | a5ad9ba | 2005-11-10 15:20:37 +0000 | [diff] [blame] | 803 | // Sanity-check size. |
| 804 | tl_assert( (VG_MIN_INSTR_SZB <= isize && isize <= VG_MAX_INSTR_SZB) |
| 805 | || VG_CLREQ_SZB == isize ); |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 806 | |
| 807 | // Get space for and init the inode, record it as the current one. |
| 808 | // Subsequent Dr/Dw/Dm events from the same instruction will |
| 809 | // also use it. |
| 810 | curr_inode = setup_InstrInfo(&cgs, cia, isize); |
| 811 | |
| 812 | addEvent_Ir( &cgs, curr_inode ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 813 | break; |
| 814 | |
| 815 | case Ist_Tmp: { |
| 816 | IRExpr* data = st->Ist.Tmp.data; |
| 817 | if (data->tag == Iex_Load) { |
| 818 | IRExpr* aexpr = data->Iex.Load.addr; |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 819 | // Note also, endianness info is ignored. I guess |
| 820 | // that's not interesting. |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 821 | addEvent_Dr( &cgs, curr_inode, sizeofIRType(data->Iex.Load.ty), |
| 822 | aexpr ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 823 | } |
| 824 | break; |
njn | b3507ea | 2005-08-02 23:07:02 +0000 | [diff] [blame] | 825 | } |
| 826 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 827 | case Ist_Store: { |
| 828 | IRExpr* data = st->Ist.Store.data; |
| 829 | IRExpr* aexpr = st->Ist.Store.addr; |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 830 | addEvent_Dw( &cgs, curr_inode, |
| 831 | sizeofIRType(typeOfIRExpr(tyenv, data)), aexpr ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 832 | break; |
| 833 | } |
njn | b3507ea | 2005-08-02 23:07:02 +0000 | [diff] [blame] | 834 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 835 | case Ist_Dirty: { |
| 836 | Int dataSize; |
| 837 | IRDirty* d = st->Ist.Dirty.details; |
| 838 | if (d->mFx != Ifx_None) { |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 839 | /* This dirty helper accesses memory. Collect the details. */ |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 840 | tl_assert(d->mAddr != NULL); |
| 841 | tl_assert(d->mSize != 0); |
| 842 | dataSize = d->mSize; |
| 843 | // Large (eg. 28B, 108B, 512B on x86) data-sized |
| 844 | // instructions will be done inaccurately, but they're |
| 845 | // very rare and this avoids errors from hitting more |
| 846 | // than two cache lines in the simulation. |
| 847 | if (dataSize > MIN_LINE_SIZE) |
| 848 | dataSize = MIN_LINE_SIZE; |
| 849 | if (d->mFx == Ifx_Read || d->mFx == Ifx_Modify) |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 850 | addEvent_Dr( &cgs, curr_inode, dataSize, d->mAddr ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 851 | if (d->mFx == Ifx_Write || d->mFx == Ifx_Modify) |
njn | fd9f622 | 2005-10-16 00:17:37 +0000 | [diff] [blame] | 852 | addEvent_Dw( &cgs, curr_inode, dataSize, d->mAddr ); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 853 | } else { |
| 854 | tl_assert(d->mAddr == NULL); |
| 855 | tl_assert(d->mSize == 0); |
| 856 | } |
| 857 | break; |
| 858 | } |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 859 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 860 | case Ist_Exit: |
| 861 | /* We may never reach the next statement, so need to flush |
| 862 | all outstanding transactions now. */ |
| 863 | flushEvents( &cgs ); |
| 864 | break; |
| 865 | |
| 866 | default: |
| 867 | tl_assert(0); |
| 868 | break; |
njn | b3507ea | 2005-08-02 23:07:02 +0000 | [diff] [blame] | 869 | } |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 870 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 871 | /* Copy the original statement */ |
| 872 | addStmtToIRBB( cgs.bbOut, st ); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 873 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 874 | if (DEBUG_CG) { |
| 875 | ppIRStmt(st); |
| 876 | VG_(printf)("\n"); |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | /* At the end of the bb. Flush outstandings. */ |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 881 | flushEvents( &cgs ); |
| 882 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 883 | /* done. stay sane ... */ |
| 884 | tl_assert(cgs.bbInfo_i == cgs.bbInfo->n_instrs); |
| 885 | |
| 886 | if (DEBUG_CG) { |
| 887 | VG_(printf)( "goto {"); |
| 888 | ppIRJumpKind(bbIn->jumpkind); |
| 889 | VG_(printf)( "} "); |
| 890 | ppIRExpr( bbIn->next ); |
| 891 | VG_(printf)( "}\n"); |
| 892 | } |
| 893 | |
| 894 | return cgs.bbOut; |
njn | 14d01ce | 2004-11-26 11:30:14 +0000 | [diff] [blame] | 895 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 896 | |
| 897 | /*------------------------------------------------------------*/ |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 898 | /*--- Cache configuration ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 899 | /*------------------------------------------------------------*/ |
| 900 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 901 | #define UNDEFINED_CACHE { -1, -1, -1 } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 902 | |
| 903 | static cache_t clo_I1_cache = UNDEFINED_CACHE; |
| 904 | static cache_t clo_D1_cache = UNDEFINED_CACHE; |
| 905 | static cache_t clo_L2_cache = UNDEFINED_CACHE; |
| 906 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 907 | /* Checks cache config is ok; makes it so if not. */ |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 908 | static |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 909 | void check_cache(cache_t* cache, Char *name) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 910 | { |
| 911 | /* First check they're all powers of two */ |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 912 | if (-1 == VG_(log2)(cache->size)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 913 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 914 | "error: %s size of %dB not a power of two; aborting.", |
| 915 | name, cache->size); |
| 916 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 917 | } |
| 918 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 919 | if (-1 == VG_(log2)(cache->assoc)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 920 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 921 | "error: %s associativity of %d not a power of two; aborting.", |
| 922 | name, cache->assoc); |
| 923 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 924 | } |
| 925 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 926 | if (-1 == VG_(log2)(cache->line_size)) { |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 927 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 928 | "error: %s line size of %dB not a power of two; aborting.", |
| 929 | name, cache->line_size); |
| 930 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 931 | } |
| 932 | |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 933 | // Then check line size >= 16 -- any smaller and a single instruction could |
| 934 | // straddle three cache lines, which breaks a simulation assertion and is |
| 935 | // stupid anyway. |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 936 | if (cache->line_size < MIN_LINE_SIZE) { |
| 937 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 938 | "error: %s line size of %dB too small; aborting.", |
| 939 | name, cache->line_size); |
| 940 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /* Then check cache size > line size (causes seg faults if not). */ |
| 944 | if (cache->size <= cache->line_size) { |
| 945 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 946 | "error: %s cache size of %dB <= line size of %dB; aborting.", |
| 947 | name, cache->size, cache->line_size); |
| 948 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | /* Then check assoc <= (size / line size) (seg faults otherwise). */ |
| 952 | if (cache->assoc > (cache->size / cache->line_size)) { |
| 953 | VG_(message)(Vg_UserMsg, |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 954 | "warning: %s associativity > (size / line size); aborting.", name); |
| 955 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 959 | static |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 960 | void configure_caches(cache_t* I1c, cache_t* D1c, cache_t* L2c) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 961 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 962 | #define DEFINED(L) (-1 != L.size || -1 != L.assoc || -1 != L.line_size) |
| 963 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 964 | Int n_clos = 0; |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 965 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 966 | // Count how many were defined on the command line. |
| 967 | if (DEFINED(clo_I1_cache)) { n_clos++; } |
| 968 | if (DEFINED(clo_D1_cache)) { n_clos++; } |
| 969 | if (DEFINED(clo_L2_cache)) { n_clos++; } |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 970 | |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 971 | // Set the cache config (using auto-detection, if supported by the |
| 972 | // architecture) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 973 | VG_(configure_caches)( I1c, D1c, L2c, (3 == n_clos) ); |
sewardj | b1a77a4 | 2002-07-13 13:31:20 +0000 | [diff] [blame] | 974 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 975 | // Then replace with any defined on the command line. |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 976 | if (DEFINED(clo_I1_cache)) { *I1c = clo_I1_cache; } |
| 977 | if (DEFINED(clo_D1_cache)) { *D1c = clo_D1_cache; } |
| 978 | if (DEFINED(clo_L2_cache)) { *L2c = clo_L2_cache; } |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 979 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 980 | // Then check values and fix if not acceptable. |
njn | a1d1a64 | 2004-11-26 18:36:02 +0000 | [diff] [blame] | 981 | check_cache(I1c, "I1"); |
| 982 | check_cache(D1c, "D1"); |
| 983 | check_cache(L2c, "L2"); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 984 | |
| 985 | if (VG_(clo_verbosity) > 1) { |
| 986 | VG_(message)(Vg_UserMsg, "Cache configuration used:"); |
| 987 | VG_(message)(Vg_UserMsg, " I1: %dB, %d-way, %dB lines", |
| 988 | I1c->size, I1c->assoc, I1c->line_size); |
| 989 | VG_(message)(Vg_UserMsg, " D1: %dB, %d-way, %dB lines", |
| 990 | D1c->size, D1c->assoc, D1c->line_size); |
| 991 | VG_(message)(Vg_UserMsg, " L2: %dB, %d-way, %dB lines", |
| 992 | L2c->size, L2c->assoc, L2c->line_size); |
| 993 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 994 | #undef CMD_LINE_DEFINED |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 995 | } |
| 996 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 997 | /*------------------------------------------------------------*/ |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 998 | /*--- cg_fini() and related function ---*/ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 999 | /*------------------------------------------------------------*/ |
| 1000 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1001 | // Total reads/writes/misses. Calculated during CC traversal at the end. |
| 1002 | // All auto-zeroed. |
| 1003 | static CC Ir_total; |
| 1004 | static CC Dr_total; |
| 1005 | static CC Dw_total; |
| 1006 | |
| 1007 | static Char* cachegrind_out_file; |
| 1008 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1009 | static void fprint_CC_table_and_calc_totals(void) |
| 1010 | { |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1011 | Int i, fd; |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 1012 | SysRes sres; |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1013 | Char buf[512], *currFile = NULL, *currFn = NULL; |
| 1014 | LineCC* lineCC; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1015 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1016 | VGP_PUSHCC(VgpCacheResults); |
njn | 13f0293 | 2003-04-30 20:23:58 +0000 | [diff] [blame] | 1017 | |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 1018 | sres = VG_(open)(cachegrind_out_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY, |
| 1019 | VKI_S_IRUSR|VKI_S_IWUSR); |
| 1020 | if (sres.isError) { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1021 | // If the file can't be opened for whatever reason (conflict |
| 1022 | // between multiple cachegrinded processes?), give up now. |
njn | ee0e6a3 | 2005-04-24 00:21:01 +0000 | [diff] [blame] | 1023 | VG_(message)(Vg_UserMsg, |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 1024 | "error: can't open cache simulation output file '%s'", |
njn | ee0e6a3 | 2005-04-24 00:21:01 +0000 | [diff] [blame] | 1025 | cachegrind_out_file ); |
| 1026 | VG_(message)(Vg_UserMsg, |
| 1027 | " ... so simulation results will be missing."); |
sewardj | 0744b6c | 2002-12-11 00:45:42 +0000 | [diff] [blame] | 1028 | return; |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 1029 | } else { |
| 1030 | fd = sres.val; |
sewardj | 0744b6c | 2002-12-11 00:45:42 +0000 | [diff] [blame] | 1031 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1032 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1033 | // "desc:" lines (giving I1/D1/L2 cache configuration). The spaces after |
| 1034 | // the 2nd colon makes cg_annotate's output look nicer. |
| 1035 | VG_(sprintf)(buf, "desc: I1 cache: %s\n" |
| 1036 | "desc: D1 cache: %s\n" |
| 1037 | "desc: L2 cache: %s\n", |
| 1038 | I1.desc_line, D1.desc_line, L2.desc_line); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 1039 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1040 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1041 | // "cmd:" line |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1042 | VG_(strcpy)(buf, "cmd:"); |
| 1043 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1044 | if (VG_(args_the_exename)) { |
| 1045 | VG_(write)(fd, " ", 1); |
| 1046 | VG_(write)(fd, VG_(args_the_exename), |
| 1047 | VG_(strlen)( VG_(args_the_exename) )); |
| 1048 | } |
| 1049 | for (i = 0; i < VG_(args_for_client).used; i++) { |
| 1050 | if (VG_(args_for_client).strs[i]) { |
| 1051 | VG_(write)(fd, " ", 1); |
| 1052 | VG_(write)(fd, VG_(args_for_client).strs[i], |
| 1053 | VG_(strlen)(VG_(args_for_client).strs[i])); |
| 1054 | } |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1055 | } |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1056 | // "events:" line |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1057 | VG_(sprintf)(buf, "\nevents: Ir I1mr I2mr Dr D1mr D2mr Dw D1mw D2mw\n"); |
| 1058 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 1059 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1060 | // Traverse every lineCC |
| 1061 | VG_(OSet_ResetIter)(CC_table); |
| 1062 | while ( (lineCC = VG_(OSet_Next)(CC_table)) ) { |
njn | 4311fe6 | 2005-12-08 23:18:50 +0000 | [diff] [blame^] | 1063 | Bool just_hit_a_new_file = False; |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1064 | // If we've hit a new file, print a "fl=" line. Note that because |
| 1065 | // each string is stored exactly once in the string table, we can use |
| 1066 | // pointer comparison rather than strcmp() to test for equality, which |
| 1067 | // is good because most of the time the comparisons are equal and so |
njn | 4311fe6 | 2005-12-08 23:18:50 +0000 | [diff] [blame^] | 1068 | // the whole strings would have to be checked. |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1069 | if ( lineCC->loc.file != currFile ) { |
| 1070 | currFile = lineCC->loc.file; |
| 1071 | VG_(sprintf)(buf, "fl=%s\n", currFile); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1072 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1073 | distinct_files++; |
njn | 4311fe6 | 2005-12-08 23:18:50 +0000 | [diff] [blame^] | 1074 | just_hit_a_new_file = True; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1075 | } |
njn | 4311fe6 | 2005-12-08 23:18:50 +0000 | [diff] [blame^] | 1076 | // If we've hit a new function, print a "fn=" line. We know to do |
| 1077 | // this when the function name changes, and also every time we hit a |
| 1078 | // new file (in which case the new function name might be the same as |
| 1079 | // in the old file, hence the just_hit_a_new_file test). |
| 1080 | if ( just_hit_a_new_file || lineCC->loc.fn != currFn ) { |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1081 | currFn = lineCC->loc.fn; |
| 1082 | VG_(sprintf)(buf, "fn=%s\n", currFn); |
| 1083 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 1084 | distinct_fns++; |
njn | 4311fe6 | 2005-12-08 23:18:50 +0000 | [diff] [blame^] | 1085 | just_hit_a_new_file = False; |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | // Print the LineCC |
| 1089 | VG_(sprintf)(buf, "%u %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
| 1090 | lineCC->loc.line, |
| 1091 | lineCC->Ir.a, lineCC->Ir.m1, lineCC->Ir.m2, |
| 1092 | lineCC->Dr.a, lineCC->Dr.m1, lineCC->Dr.m2, |
| 1093 | lineCC->Dw.a, lineCC->Dw.m1, lineCC->Dw.m2); |
| 1094 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 1095 | |
| 1096 | // Update summary stats |
| 1097 | Ir_total.a += lineCC->Ir.a; |
| 1098 | Ir_total.m1 += lineCC->Ir.m1; |
| 1099 | Ir_total.m2 += lineCC->Ir.m2; |
| 1100 | Dr_total.a += lineCC->Dr.a; |
| 1101 | Dr_total.m1 += lineCC->Dr.m1; |
| 1102 | Dr_total.m2 += lineCC->Dr.m2; |
| 1103 | Dw_total.a += lineCC->Dw.a; |
| 1104 | Dw_total.m1 += lineCC->Dw.m1; |
| 1105 | Dw_total.m2 += lineCC->Dw.m2; |
| 1106 | |
| 1107 | distinct_lines++; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1110 | // Summary stats must come after rest of table, since we calculate them |
| 1111 | // during traversal. */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1112 | VG_(sprintf)(buf, "summary: " |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1113 | "%llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1114 | Ir_total.a, Ir_total.m1, Ir_total.m2, |
| 1115 | Dr_total.a, Dr_total.m1, Dr_total.m2, |
| 1116 | Dw_total.a, Dw_total.m1, Dw_total.m2); |
| 1117 | VG_(write)(fd, (void*)buf, VG_(strlen)(buf)); |
| 1118 | VG_(close)(fd); |
| 1119 | } |
| 1120 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1121 | static UInt ULong_width(ULong n) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1122 | { |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1123 | UInt w = 0; |
| 1124 | while (n > 0) { |
| 1125 | n = n / 10; |
| 1126 | w++; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1127 | } |
sewardj | 46c59b1 | 2005-11-01 02:20:19 +0000 | [diff] [blame] | 1128 | if (w == 0) w = 1; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1129 | return w + (w-1)/3; // add space for commas |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1132 | static void cg_fini(Int exitcode) |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1133 | { |
njn | 0103de5 | 2005-10-10 16:49:01 +0000 | [diff] [blame] | 1134 | static Char buf1[128], buf2[128], buf3[128], fmt [128]; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1135 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1136 | CC D_total; |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 1137 | ULong L2_total_m, L2_total_mr, L2_total_mw, |
| 1138 | L2_total, L2_total_r, L2_total_w; |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1139 | Int l1, l2, l3; |
| 1140 | Int p; |
| 1141 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1142 | fprint_CC_table_and_calc_totals(); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1143 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 1144 | if (VG_(clo_verbosity) == 0) |
| 1145 | return; |
| 1146 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1147 | /* I cache results. Use the I_refs value to determine the first column |
| 1148 | * width. */ |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1149 | l1 = ULong_width(Ir_total.a); |
| 1150 | l2 = ULong_width(Dr_total.a); |
| 1151 | l3 = ULong_width(Dw_total.a); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1152 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1153 | /* Make format string, getting width right for numbers */ |
njn | 99cb9e3 | 2005-09-25 17:59:16 +0000 | [diff] [blame] | 1154 | VG_(sprintf)(fmt, "%%s %%,%dllu", l1); |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1155 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1156 | VG_(message)(Vg_UserMsg, fmt, "I refs: ", Ir_total.a); |
| 1157 | VG_(message)(Vg_UserMsg, fmt, "I1 misses: ", Ir_total.m1); |
| 1158 | VG_(message)(Vg_UserMsg, fmt, "L2i misses: ", Ir_total.m2); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1159 | |
| 1160 | p = 100; |
| 1161 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1162 | if (0 == Ir_total.a) Ir_total.a = 1; |
njn | 856c54e | 2005-06-26 18:43:40 +0000 | [diff] [blame] | 1163 | VG_(percentify)(Ir_total.m1, Ir_total.a, 2, l1+1, buf1); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1164 | VG_(message)(Vg_UserMsg, "I1 miss rate: %s", buf1); |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1165 | |
njn | 856c54e | 2005-06-26 18:43:40 +0000 | [diff] [blame] | 1166 | VG_(percentify)(Ir_total.m2, Ir_total.a, 2, l1+1, buf1); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1167 | VG_(message)(Vg_UserMsg, "L2i miss rate: %s", buf1); |
| 1168 | VG_(message)(Vg_UserMsg, ""); |
| 1169 | |
| 1170 | /* D cache results. Use the D_refs.rd and D_refs.wr values to determine the |
| 1171 | * width of columns 2 & 3. */ |
| 1172 | D_total.a = Dr_total.a + Dw_total.a; |
| 1173 | D_total.m1 = Dr_total.m1 + Dw_total.m1; |
| 1174 | D_total.m2 = Dr_total.m2 + Dw_total.m2; |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1175 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1176 | /* Make format string, getting width right for numbers */ |
njn | 99cb9e3 | 2005-09-25 17:59:16 +0000 | [diff] [blame] | 1177 | VG_(sprintf)(fmt, "%%s %%,%dllu (%%,%dllu rd + %%,%dllu wr)", l1, l2, l3); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1178 | |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1179 | VG_(message)(Vg_UserMsg, fmt, "D refs: ", |
| 1180 | D_total.a, Dr_total.a, Dw_total.a); |
| 1181 | VG_(message)(Vg_UserMsg, fmt, "D1 misses: ", |
| 1182 | D_total.m1, Dr_total.m1, Dw_total.m1); |
| 1183 | VG_(message)(Vg_UserMsg, fmt, "L2d misses: ", |
| 1184 | D_total.m2, Dr_total.m2, Dw_total.m2); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1185 | |
| 1186 | p = 10; |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1187 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1188 | if (0 == D_total.a) D_total.a = 1; |
| 1189 | if (0 == Dr_total.a) Dr_total.a = 1; |
| 1190 | if (0 == Dw_total.a) Dw_total.a = 1; |
njn | 856c54e | 2005-06-26 18:43:40 +0000 | [diff] [blame] | 1191 | VG_(percentify)( D_total.m1, D_total.a, 1, l1+1, buf1); |
| 1192 | VG_(percentify)(Dr_total.m1, Dr_total.a, 1, l2+1, buf2); |
| 1193 | VG_(percentify)(Dw_total.m1, Dw_total.a, 1, l3+1, buf3); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1194 | VG_(message)(Vg_UserMsg, "D1 miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 1195 | |
njn | 856c54e | 2005-06-26 18:43:40 +0000 | [diff] [blame] | 1196 | VG_(percentify)( D_total.m2, D_total.a, 1, l1+1, buf1); |
| 1197 | VG_(percentify)(Dr_total.m2, Dr_total.a, 1, l2+1, buf2); |
| 1198 | VG_(percentify)(Dw_total.m2, Dw_total.a, 1, l3+1, buf3); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1199 | VG_(message)(Vg_UserMsg, "L2d miss rate: %s (%s + %s )", buf1, buf2,buf3); |
| 1200 | VG_(message)(Vg_UserMsg, ""); |
| 1201 | |
| 1202 | /* L2 overall results */ |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 1203 | |
| 1204 | L2_total = Dr_total.m1 + Dw_total.m1 + Ir_total.m1; |
| 1205 | L2_total_r = Dr_total.m1 + Ir_total.m1; |
| 1206 | L2_total_w = Dw_total.m1; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1207 | VG_(message)(Vg_UserMsg, fmt, "L2 refs: ", |
| 1208 | L2_total, L2_total_r, L2_total_w); |
njn | 1d021fa | 2002-05-02 13:56:34 +0000 | [diff] [blame] | 1209 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1210 | L2_total_m = Dr_total.m2 + Dw_total.m2 + Ir_total.m2; |
| 1211 | L2_total_mr = Dr_total.m2 + Ir_total.m2; |
| 1212 | L2_total_mw = Dw_total.m2; |
njn | 607adfc | 2003-09-30 14:15:44 +0000 | [diff] [blame] | 1213 | VG_(message)(Vg_UserMsg, fmt, "L2 misses: ", |
| 1214 | L2_total_m, L2_total_mr, L2_total_mw); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1215 | |
njn | 856c54e | 2005-06-26 18:43:40 +0000 | [diff] [blame] | 1216 | VG_(percentify)(L2_total_m, (Ir_total.a + D_total.a), 1, l1+1, buf1); |
| 1217 | VG_(percentify)(L2_total_mr, (Ir_total.a + Dr_total.a), 1, l2+1, buf2); |
| 1218 | VG_(percentify)(L2_total_mw, Dw_total.a, 1, l3+1, buf3); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1219 | VG_(message)(Vg_UserMsg, "L2 miss rate: %s (%s + %s )", buf1, buf2,buf3); |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1220 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1221 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1222 | // Various stats |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1223 | if (VG_(clo_verbosity) > 1) { |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1224 | Int debug_lookups = full_debugs + fn_debugs + |
| 1225 | file_line_debugs + no_debugs; |
| 1226 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1227 | VG_(message)(Vg_DebugMsg, ""); |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1228 | VG_(message)(Vg_DebugMsg, "cachegrind: distinct files: %d", distinct_files); |
| 1229 | VG_(message)(Vg_DebugMsg, "cachegrind: distinct fns: %d", distinct_fns); |
| 1230 | VG_(message)(Vg_DebugMsg, "cachegrind: distinct lines: %d", distinct_lines); |
| 1231 | VG_(message)(Vg_DebugMsg, "cachegrind: distinct instrs:%d", distinct_instrs); |
| 1232 | VG_(message)(Vg_DebugMsg, "cachegrind: debug lookups : %d", debug_lookups); |
| 1233 | VG_(message)(Vg_DebugMsg, "cachegrind: with full info:%3d%% (%d)", |
| 1234 | full_debugs * 100 / debug_lookups, full_debugs); |
| 1235 | VG_(message)(Vg_DebugMsg, "cachegrind: with file/line info:%3d%% (%d)", |
| 1236 | file_line_debugs * 100 / debug_lookups, file_line_debugs); |
| 1237 | VG_(message)(Vg_DebugMsg, "cachegrind: with fn name info:%3d%% (%d)", |
| 1238 | fn_debugs * 100 / debug_lookups, fn_debugs); |
| 1239 | VG_(message)(Vg_DebugMsg, "cachegrind: with zero info:%3d%% (%d)", |
| 1240 | no_debugs * 100 / debug_lookups, no_debugs); |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1241 | VG_(message)(Vg_DebugMsg, "cachegrind: string table size: %u", |
| 1242 | VG_(OSet_Size)(stringTable)); |
| 1243 | VG_(message)(Vg_DebugMsg, "cachegrind: CC table size: %u", |
| 1244 | VG_(OSet_Size)(CC_table)); |
| 1245 | VG_(message)(Vg_DebugMsg, "cachegrind: InstrInfo table size: %u", |
| 1246 | VG_(OSet_Size)(instrInfoTable)); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1247 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1248 | VGP_POPCC(VgpCacheResults); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1251 | /*--------------------------------------------------------------------*/ |
| 1252 | /*--- Discarding BB info ---*/ |
| 1253 | /*--------------------------------------------------------------------*/ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1254 | |
sewardj | a3a29a5 | 2005-10-12 16:16:03 +0000 | [diff] [blame] | 1255 | // Called when a translation is removed from the translation cache for |
| 1256 | // any reason at all: to free up space, because the guest code was |
| 1257 | // unmapped or modified, or for any arbitrary reason. |
sewardj | 4ba057c | 2005-10-18 12:04:18 +0000 | [diff] [blame] | 1258 | static |
| 1259 | void cg_discard_basic_block_info ( Addr64 orig_addr64, VexGuestExtents vge ) |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1260 | { |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1261 | BB_info* bbInfo; |
sewardj | 4ba057c | 2005-10-18 12:04:18 +0000 | [diff] [blame] | 1262 | Addr orig_addr = (Addr)orig_addr64; |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 1263 | |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 1264 | tl_assert(vge.n_used > 0); |
| 1265 | |
| 1266 | if (DEBUG_CG) |
sewardj | 4ba057c | 2005-10-18 12:04:18 +0000 | [diff] [blame] | 1267 | VG_(printf)( "discard_basic_block_info: %p, %p, %llu\n", |
| 1268 | (void*)(Addr)orig_addr, |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 1269 | (void*)(Addr)vge.base[0], (ULong)vge.len[0]); |
njn | 4294fd4 | 2002-06-05 14:41:10 +0000 | [diff] [blame] | 1270 | |
sewardj | 4ba057c | 2005-10-18 12:04:18 +0000 | [diff] [blame] | 1271 | // Get BB info, remove from table, free BB info. Simple! Note that we |
| 1272 | // use orig_addr, not the first instruction address in vge. |
| 1273 | bbInfo = VG_(OSet_Remove)(instrInfoTable, &orig_addr); |
njn | 6a3009b | 2005-03-20 00:20:06 +0000 | [diff] [blame] | 1274 | tl_assert(NULL != bbInfo); |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1275 | VG_(OSet_FreeNode)(instrInfoTable, bbInfo); |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | /*--------------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1279 | /*--- Command line processing ---*/ |
| 1280 | /*--------------------------------------------------------------------*/ |
| 1281 | |
njn | 0103de5 | 2005-10-10 16:49:01 +0000 | [diff] [blame] | 1282 | static void parse_cache_opt ( cache_t* cache, Char* opt ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1283 | { |
njn | 0103de5 | 2005-10-10 16:49:01 +0000 | [diff] [blame] | 1284 | Int i = 0, i2, i3; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1285 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1286 | // Option argument looks like "65536,2,64". |
| 1287 | // Find commas, replace with NULs to make three independent |
| 1288 | // strings, then extract numbers, put NULs back. Yuck. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1289 | while (VG_(isdigit)(opt[i])) i++; |
| 1290 | if (',' == opt[i]) { |
| 1291 | opt[i++] = '\0'; |
| 1292 | i2 = i; |
| 1293 | } else goto bad; |
| 1294 | while (VG_(isdigit)(opt[i])) i++; |
| 1295 | if (',' == opt[i]) { |
| 1296 | opt[i++] = '\0'; |
| 1297 | i3 = i; |
| 1298 | } else goto bad; |
| 1299 | while (VG_(isdigit)(opt[i])) i++; |
| 1300 | if ('\0' != opt[i]) goto bad; |
| 1301 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1302 | cache->size = (Int)VG_(atoll)(opt); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1303 | cache->assoc = (Int)VG_(atoll)(opt + i2); |
| 1304 | cache->line_size = (Int)VG_(atoll)(opt + i3); |
| 1305 | |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1306 | opt[i2-1] = ','; |
| 1307 | opt[i3-1] = ','; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1308 | return; |
| 1309 | |
| 1310 | bad: |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1311 | VG_(bad_option)(opt); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1314 | static Bool cg_process_cmd_line_option(Char* arg) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1315 | { |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1316 | // 5 is length of "--I1=" |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1317 | if (VG_CLO_STREQN(5, arg, "--I1=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1318 | parse_cache_opt(&clo_I1_cache, &arg[5]); |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1319 | else if (VG_CLO_STREQN(5, arg, "--D1=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1320 | parse_cache_opt(&clo_D1_cache, &arg[5]); |
njn | 39c8665 | 2003-05-21 10:13:39 +0000 | [diff] [blame] | 1321 | else if (VG_CLO_STREQN(5, arg, "--L2=")) |
nethercote | 9313ac4 | 2004-07-06 21:54:20 +0000 | [diff] [blame] | 1322 | parse_cache_opt(&clo_L2_cache, &arg[5]); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1323 | else |
| 1324 | return False; |
| 1325 | |
| 1326 | return True; |
| 1327 | } |
| 1328 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1329 | static void cg_print_usage(void) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1330 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1331 | VG_(printf)( |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1332 | " --I1=<size>,<assoc>,<line_size> set I1 cache manually\n" |
| 1333 | " --D1=<size>,<assoc>,<line_size> set D1 cache manually\n" |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1334 | " --L2=<size>,<assoc>,<line_size> set L2 cache manually\n" |
| 1335 | ); |
| 1336 | } |
| 1337 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1338 | static void cg_print_debug_usage(void) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1339 | { |
| 1340 | VG_(printf)( |
| 1341 | " (none)\n" |
| 1342 | ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | /*--------------------------------------------------------------------*/ |
| 1346 | /*--- Setup ---*/ |
| 1347 | /*--------------------------------------------------------------------*/ |
| 1348 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1349 | static void cg_post_clo_init(void) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1350 | { |
| 1351 | cache_t I1c, D1c, L2c; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1352 | |
nethercote | b35a8b9 | 2004-09-11 16:45:27 +0000 | [diff] [blame] | 1353 | configure_caches(&I1c, &D1c, &L2c); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1354 | |
| 1355 | cachesim_I1_initcache(I1c); |
| 1356 | cachesim_D1_initcache(D1c); |
| 1357 | cachesim_L2_initcache(L2c); |
| 1358 | |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 1359 | VG_(register_profile_event)(VgpGetLineCC, "get-lineCC"); |
| 1360 | VG_(register_profile_event)(VgpCacheSimulate, "cache-simulate"); |
| 1361 | VG_(register_profile_event)(VgpCacheResults, "cache-results"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
njn | 57ca7ab | 2005-06-21 23:44:58 +0000 | [diff] [blame] | 1364 | static Char base_dir[VKI_PATH_MAX]; |
| 1365 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1366 | static void cg_pre_clo_init(void) |
| 1367 | { |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1368 | VG_(details_name) ("Cachegrind"); |
| 1369 | VG_(details_version) (NULL); |
| 1370 | VG_(details_description) ("an I1/D1/L2 cache profiler"); |
| 1371 | VG_(details_copyright_author)( |
| 1372 | "Copyright (C) 2002-2005, and GNU GPL'd, by Nicholas Nethercote et al."); |
| 1373 | VG_(details_bug_reports_to) (VG_BUGS_TO); |
sewardj | 5155dec | 2005-10-12 10:09:23 +0000 | [diff] [blame] | 1374 | VG_(details_avg_translation_sizeB) ( 245 ); |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1375 | |
| 1376 | VG_(basic_tool_funcs) (cg_post_clo_init, |
| 1377 | cg_instrument, |
| 1378 | cg_fini); |
| 1379 | |
| 1380 | VG_(needs_basic_block_discards)(cg_discard_basic_block_info); |
| 1381 | VG_(needs_command_line_options)(cg_process_cmd_line_option, |
| 1382 | cg_print_usage, |
| 1383 | cg_print_debug_usage); |
| 1384 | |
| 1385 | /* Get working directory */ |
njn | 57ca7ab | 2005-06-21 23:44:58 +0000 | [diff] [blame] | 1386 | tl_assert( VG_(getcwd)(base_dir, VKI_PATH_MAX) ); |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1387 | |
| 1388 | /* Block is big enough for dir name + cachegrind.out.<pid> */ |
| 1389 | cachegrind_out_file = VG_(malloc)((VG_(strlen)(base_dir) + 32)*sizeof(Char)); |
| 1390 | VG_(sprintf)(cachegrind_out_file, "%s/cachegrind.out.%d", |
| 1391 | base_dir, VG_(getpid)()); |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1392 | |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1393 | CC_table = VG_(OSet_Create)(offsetof(LineCC, loc), |
| 1394 | cmp_CodeLoc_LineCC, |
| 1395 | VG_(malloc), VG_(free)); |
sewardj | 4ba057c | 2005-10-18 12:04:18 +0000 | [diff] [blame] | 1396 | instrInfoTable = VG_(OSet_Create)(/*keyOff*/0, |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1397 | NULL, |
| 1398 | VG_(malloc), VG_(free)); |
| 1399 | stringTable = VG_(OSet_Create)(/*keyOff*/0, |
| 1400 | stringCmp, |
| 1401 | VG_(malloc), VG_(free)); |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1404 | VG_DETERMINE_INTERFACE_VERSION(cg_pre_clo_init) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1405 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1406 | /*--------------------------------------------------------------------*/ |
njn | f69f945 | 2005-07-03 17:53:11 +0000 | [diff] [blame] | 1407 | /*--- end ---*/ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1408 | /*--------------------------------------------------------------------*/ |
njn | d3bef4f | 2005-10-15 17:46:18 +0000 | [diff] [blame] | 1409 | |