sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | This file is part of drd, a data race detector. |
| 3 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2008 Bart Van Assche |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | bart.vanassche@gmail.com |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU General Public License as |
| 9 | published by the Free Software Foundation; either version 2 of the |
| 10 | License, or (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, but |
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307, USA. |
| 21 | |
| 22 | The GNU General Public License is contained in the file COPYING. |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #include "pub_tool_basics.h" // Addr, SizeT |
| 27 | #include "pub_tool_debuginfo.h" // VG_(get_objname)() |
| 28 | #include "pub_tool_libcassert.h" // tl_assert() |
| 29 | #include "pub_tool_libcbase.h" // VG_(memset) |
| 30 | #include "pub_tool_libcprint.h" // VG_(printf) |
| 31 | #include "pub_tool_machine.h" // VG_(get_IP)() |
| 32 | #include "pub_tool_mallocfree.h" // VG_(malloc), VG_(free) |
| 33 | #include "pub_drd_bitmap.h" |
| 34 | #include "drd_bitmap.h" |
| 35 | #include "drd_error.h" |
| 36 | #include "drd_suppression.h" |
| 37 | |
| 38 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 39 | /* Forward declarations. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 40 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 41 | struct bitmap2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 42 | |
| 43 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 44 | /* Local function declarations. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 45 | |
| 46 | static void bm2_merge(struct bitmap2* const bm2l, |
| 47 | const struct bitmap2* const bm2r); |
| 48 | |
| 49 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 50 | /* Local constants. */ |
| 51 | |
| 52 | static ULong s_bitmap_creation_count; |
| 53 | |
| 54 | |
| 55 | /* Function definitions. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 56 | |
| 57 | struct bitmap* bm_new() |
| 58 | { |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 59 | unsigned i; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 60 | struct bitmap* bm; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 61 | |
bart | f29205e | 2008-03-25 18:51:06 +0000 | [diff] [blame] | 62 | /* If this assert fails, fix the definition of BITS_PER_BITS_PER_UWORD */ |
| 63 | /* in drd_bitmap.h. */ |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 64 | tl_assert((1 << BITS_PER_BITS_PER_UWORD) == BITS_PER_UWORD); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 65 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 66 | bm = VG_(malloc)(sizeof(*bm)); |
| 67 | tl_assert(bm); |
bart | f29205e | 2008-03-25 18:51:06 +0000 | [diff] [blame] | 68 | /* Cache initialization. a1 is initialized with a value that never can */ |
| 69 | /* match any valid address: the upper ADDR0_BITS bits of a1 are always */ |
| 70 | /* zero for a valid cache entry. */ |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 71 | for (i = 0; i < N_CACHE_ELEM; i++) |
| 72 | { |
bart | f29205e | 2008-03-25 18:51:06 +0000 | [diff] [blame] | 73 | bm->cache[i].a1 = ~(UWord)1; |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 74 | bm->cache[i].bm2 = 0; |
| 75 | } |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 76 | bm->oset = VG_(OSetGen_Create)(0, 0, VG_(malloc), VG_(free)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 77 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 78 | s_bitmap_creation_count++; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 79 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 80 | return bm; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void bm_delete(struct bitmap* const bm) |
| 84 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 85 | struct bitmap2* bm2; |
| 86 | struct bitmap2ref* bm2ref; |
| 87 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 88 | tl_assert(bm); |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 89 | |
| 90 | VG_(OSetGen_ResetIter)(bm->oset); |
| 91 | for ( ; (bm2ref = VG_(OSetGen_Next)(bm->oset)) != 0; ) |
| 92 | { |
| 93 | bm2 = bm2ref->bm2; |
| 94 | tl_assert(bm2->refcnt >= 1); |
| 95 | if (--bm2->refcnt == 0) |
| 96 | { |
| 97 | VG_(free)(bm2); |
| 98 | } |
| 99 | } |
| 100 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 101 | VG_(OSetGen_Destroy)(bm->oset); |
| 102 | VG_(free)(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 106 | * Record an access of type access_type at addresses a .. a + size - 1 in |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 107 | * bitmap bm. |
| 108 | */ |
| 109 | void bm_access_range(struct bitmap* const bm, |
bart | 9036dea | 2008-03-13 19:10:06 +0000 | [diff] [blame] | 110 | const Addr a1, const Addr a2, |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 111 | const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 112 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 113 | Addr b, b_next; |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 114 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 115 | tl_assert(bm); |
| 116 | tl_assert(a1 < a2); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 117 | /* The current implementation of bm_access_range does not work for the */ |
| 118 | /* ADDR0_COUNT highest addresses in the address range. At least on Linux */ |
| 119 | /* this is not a problem since the upper part of the address space is */ |
| 120 | /* reserved for the kernel. */ |
| 121 | tl_assert(a2 + ADDR0_COUNT > a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 122 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 123 | for (b = a1; b < a2; b = b_next) |
| 124 | { |
| 125 | Addr b_start; |
| 126 | Addr b_end; |
| 127 | struct bitmap2* bm2; |
| 128 | SPLIT_ADDRESS(b); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 129 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 130 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 131 | if (b_next > a2) |
| 132 | { |
| 133 | b_next = a2; |
| 134 | } |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 135 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 136 | bm2 = bm2_lookup_or_insert_exclusive(bm, b1); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 137 | tl_assert(bm2); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 138 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 139 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 140 | b_start = a1; |
| 141 | else |
| 142 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 143 | b_start = (bm2->addr << ADDR0_BITS); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 144 | else |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 145 | break; |
| 146 | tl_assert(a1 <= b_start && b_start <= a2); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 147 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 148 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 149 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 150 | else |
| 151 | b_end = a2; |
| 152 | tl_assert(a1 <= b_end && b_end <= a2); |
| 153 | tl_assert(b_start < b_end); |
| 154 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 155 | |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 156 | if (access_type == eLoad) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 157 | { |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 158 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end - 1) & ADDR0_MASK); b0++) |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 159 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 160 | bm0_set(bm2->bm1.bm0_r, b0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 161 | } |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 162 | } |
| 163 | else |
| 164 | { |
| 165 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end - 1) & ADDR0_MASK); b0++) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 166 | { |
| 167 | bm0_set(bm2->bm1.bm0_w, b0); |
| 168 | } |
| 169 | } |
| 170 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 171 | } |
| 172 | |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 173 | void bm_access_range_load(struct bitmap* const bm, |
| 174 | const Addr a1, const Addr a2) |
| 175 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 176 | bm_access_range(bm, a1, a2, eLoad); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 177 | } |
| 178 | |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 179 | void bm_access_load_1(struct bitmap* const bm, const Addr a1) |
| 180 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 181 | bm_access_aligned_load(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | void bm_access_load_2(struct bitmap* const bm, const Addr a1) |
| 185 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 186 | if ((a1 & 1) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 187 | bm_access_aligned_load(bm, a1, 2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 188 | else |
| 189 | bm_access_range(bm, a1, a1 + 2, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void bm_access_load_4(struct bitmap* const bm, const Addr a1) |
| 193 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 194 | if ((a1 & 3) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 195 | bm_access_aligned_load(bm, a1, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 196 | else |
| 197 | bm_access_range(bm, a1, a1 + 4, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void bm_access_load_8(struct bitmap* const bm, const Addr a1) |
| 201 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 202 | if ((a1 & 7) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 203 | bm_access_aligned_load(bm, a1, 8); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 204 | else if ((a1 & 3) == 0) |
| 205 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 206 | bm_access_aligned_load(bm, a1 + 0, 4); |
| 207 | bm_access_aligned_load(bm, a1 + 4, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 208 | } |
| 209 | else |
| 210 | bm_access_range(bm, a1, a1 + 8, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 211 | } |
| 212 | |
bart | f5acbbc | 2008-05-10 08:22:20 +0000 | [diff] [blame] | 213 | void bm_access_range_store(struct bitmap* const bm, |
| 214 | const Addr a1, const Addr a2) |
| 215 | { |
| 216 | bm_access_range(bm, a1, a2, eStore); |
| 217 | } |
| 218 | |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 219 | void bm_access_store_1(struct bitmap* const bm, const Addr a1) |
| 220 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 221 | bm_access_aligned_store(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void bm_access_store_2(struct bitmap* const bm, const Addr a1) |
| 225 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 226 | if ((a1 & 1) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 227 | bm_access_aligned_store(bm, a1, 2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 228 | else |
| 229 | bm_access_range(bm, a1, a1 + 2, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | void bm_access_store_4(struct bitmap* const bm, const Addr a1) |
| 233 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 234 | if ((a1 & 3) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 235 | bm_access_aligned_store(bm, a1, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 236 | else |
| 237 | bm_access_range(bm, a1, a1 + 4, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | void bm_access_store_8(struct bitmap* const bm, const Addr a1) |
| 241 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 242 | if ((a1 & 7) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 243 | bm_access_aligned_store(bm, a1, 8); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 244 | else if ((a1 & 3) == 0) |
| 245 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 246 | bm_access_aligned_store(bm, a1 + 0, 4); |
| 247 | bm_access_aligned_store(bm, a1 + 4, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 248 | } |
| 249 | else |
| 250 | bm_access_range(bm, a1, a1 + 8, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 251 | } |
| 252 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 253 | Bool bm_has(struct bitmap* const bm, const Addr a1, const Addr a2, |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 254 | const BmAccessTypeT access_type) |
| 255 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 256 | Addr b; |
| 257 | for (b = a1; b < a2; b++) |
| 258 | { |
| 259 | if (! bm_has_1(bm, b, access_type)) |
| 260 | { |
| 261 | return False; |
| 262 | } |
| 263 | } |
| 264 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 265 | } |
| 266 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 267 | Bool bm_has_any_load(struct bitmap* const bm, const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 268 | { |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 269 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 270 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 271 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 272 | |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 273 | for (b = a1; b < a2; b = b_next) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 274 | { |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 275 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
| 276 | |
| 277 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 278 | if (b_next > a2) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 279 | { |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 280 | b_next = a2; |
| 281 | } |
| 282 | |
| 283 | if (bm2) |
| 284 | { |
| 285 | Addr b_start; |
| 286 | Addr b_end; |
| 287 | UWord b0; |
| 288 | const struct bitmap1* const p1 = &bm2->bm1; |
| 289 | |
| 290 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 291 | b_start = a1; |
| 292 | else |
| 293 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 294 | b_start = (bm2->addr << ADDR0_BITS); |
| 295 | else |
| 296 | break; |
| 297 | tl_assert(a1 <= b_start && b_start <= a2); |
| 298 | |
| 299 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 300 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 301 | else |
| 302 | b_end = a2; |
| 303 | tl_assert(a1 <= b_end && b_end <= a2); |
| 304 | tl_assert(b_start < b_end); |
| 305 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
| 306 | |
| 307 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 308 | { |
| 309 | if (bm0_is_set(p1->bm0_r, b0)) |
| 310 | { |
| 311 | return True; |
| 312 | } |
| 313 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 314 | } |
| 315 | } |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 319 | Bool bm_has_any_store(struct bitmap* const bm, |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 320 | const Addr a1, const Addr a2) |
| 321 | { |
| 322 | Addr b, b_next; |
| 323 | |
| 324 | tl_assert(bm); |
| 325 | |
| 326 | for (b = a1; b < a2; b = b_next) |
| 327 | { |
| 328 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
| 329 | |
| 330 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 331 | if (b_next > a2) |
| 332 | { |
| 333 | b_next = a2; |
| 334 | } |
| 335 | |
| 336 | if (bm2) |
| 337 | { |
| 338 | Addr b_start; |
| 339 | Addr b_end; |
| 340 | UWord b0; |
| 341 | const struct bitmap1* const p1 = &bm2->bm1; |
| 342 | |
| 343 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 344 | b_start = a1; |
| 345 | else |
| 346 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 347 | b_start = (bm2->addr << ADDR0_BITS); |
| 348 | else |
| 349 | break; |
| 350 | tl_assert(a1 <= b_start && b_start <= a2); |
| 351 | |
| 352 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 353 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 354 | else |
| 355 | b_end = a2; |
| 356 | tl_assert(a1 <= b_end && b_end <= a2); |
| 357 | tl_assert(b_start < b_end); |
| 358 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
| 359 | |
| 360 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 361 | { |
| 362 | if (bm0_is_set(p1->bm0_w, b0)) |
| 363 | { |
| 364 | return True; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 370 | } |
| 371 | |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 372 | /* Return True if there is a read access, write access or both */ |
| 373 | /* to any of the addresses in the range [ a1, a2 [ in bitmap bm. */ |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 374 | Bool bm_has_any_access(struct bitmap* const bm, |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 375 | const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 376 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 377 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 378 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 379 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 380 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 381 | for (b = a1; b < a2; b = b_next) |
| 382 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 383 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 384 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 385 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 386 | if (b_next > a2) |
| 387 | { |
| 388 | b_next = a2; |
| 389 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 390 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 391 | if (bm2) |
| 392 | { |
| 393 | Addr b_start; |
| 394 | Addr b_end; |
| 395 | UWord b0; |
| 396 | const struct bitmap1* const p1 = &bm2->bm1; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 397 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 398 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 399 | b_start = a1; |
| 400 | else |
| 401 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 402 | b_start = (bm2->addr << ADDR0_BITS); |
| 403 | else |
| 404 | break; |
| 405 | tl_assert(a1 <= b_start && b_start <= a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 406 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 407 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 408 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 409 | else |
| 410 | b_end = a2; |
| 411 | tl_assert(a1 <= b_end && b_end <= a2); |
| 412 | tl_assert(b_start < b_end); |
| 413 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 414 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 415 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 416 | { |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 417 | if (bm0_is_set(p1->bm0_r, b0) | bm0_is_set(p1->bm0_w, b0)) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 418 | { |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 419 | return True; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 420 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 421 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 422 | } |
| 423 | } |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 424 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 425 | } |
| 426 | |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 427 | /** Report whether an access of type access_type at address a is recorded in |
| 428 | * bitmap bm. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 429 | */ |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 430 | Bool bm_has_1(struct bitmap* const bm, |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 431 | const Addr a, const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 432 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 433 | const struct bitmap2* p2; |
| 434 | const struct bitmap1* p1; |
| 435 | const UWord* p0; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 436 | const UWord a0 = a & ADDR0_MASK; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 437 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 438 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 439 | |
bart | 11d0b50 | 2008-03-22 16:44:03 +0000 | [diff] [blame] | 440 | p2 = bm2_lookup(bm, a >> ADDR0_BITS); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 441 | if (p2) |
| 442 | { |
| 443 | p1 = &p2->bm1; |
| 444 | p0 = (access_type == eLoad) ? p1->bm0_r : p1->bm0_w; |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 445 | return bm0_is_set(p0, a0) ? True : False; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 446 | } |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 447 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 448 | } |
| 449 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 450 | void bm_clear(struct bitmap* const bm, |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 451 | const Addr a1, |
| 452 | const Addr a2) |
| 453 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 454 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 455 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 456 | tl_assert(bm); |
| 457 | tl_assert(a1); |
| 458 | tl_assert(a1 <= a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 459 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 460 | for (b = a1; b < a2; b = b_next) |
| 461 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 462 | struct bitmap2* const p2 = bm2_lookup_exclusive(bm, b >> ADDR0_BITS); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 463 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 464 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 465 | if (b_next > a2) |
| 466 | { |
| 467 | b_next = a2; |
| 468 | } |
| 469 | |
| 470 | if (p2) |
| 471 | { |
| 472 | Addr c = b; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 473 | /* If the first address in the bitmap that must be cleared does not */ |
bart | 5955f33 | 2008-03-25 17:19:20 +0000 | [diff] [blame] | 474 | /* start on an UWord boundary, start clearing the first addresses. */ |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 475 | if (UWORD_LSB(c)) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 476 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 477 | Addr c_next = UWORD_MSB(c) + BITS_PER_UWORD; |
| 478 | if (c_next > b_next) |
| 479 | c_next = b_next; |
bart | 5955f33 | 2008-03-25 17:19:20 +0000 | [diff] [blame] | 480 | bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, c_next - c); |
| 481 | bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, c_next - c); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 482 | c = c_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 483 | } |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 484 | /* If some UWords have to be cleared entirely, do this now. */ |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 485 | if (UWORD_LSB(c) == 0) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 486 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 487 | const Addr c_next = UWORD_MSB(b_next); |
| 488 | tl_assert(UWORD_LSB(c) == 0); |
| 489 | tl_assert(UWORD_LSB(c_next) == 0); |
| 490 | tl_assert(c_next <= b_next); |
| 491 | tl_assert(c <= c_next); |
| 492 | if (c_next > c) |
| 493 | { |
| 494 | UWord idx = (c & ADDR0_MASK) >> BITS_PER_BITS_PER_UWORD; |
| 495 | VG_(memset)(&p2->bm1.bm0_r[idx], 0, (c_next - c) / 8); |
| 496 | VG_(memset)(&p2->bm1.bm0_w[idx], 0, (c_next - c) / 8); |
| 497 | c = c_next; |
| 498 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 499 | } |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 500 | /* If the last address in the bitmap that must be cleared does not */ |
bart | 5955f33 | 2008-03-25 17:19:20 +0000 | [diff] [blame] | 501 | /* fall on an UWord boundary, clear the last addresses. */ |
| 502 | /* tl_assert(c <= b_next); */ |
| 503 | bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, b_next - c); |
| 504 | bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, b_next - c); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 505 | } |
| 506 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 507 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 508 | |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 509 | /** Clear all references to loads in bitmap bm starting at address a1 and |
| 510 | * up to but not including address a2. |
| 511 | */ |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 512 | void bm_clear_load(struct bitmap* const bm, |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 513 | const Addr a1, const Addr a2) |
| 514 | { |
| 515 | Addr a; |
| 516 | |
| 517 | for (a = a1; a < a2; a++) |
| 518 | { |
| 519 | struct bitmap2* const p2 = bm2_lookup_exclusive(bm, a >> ADDR0_BITS); |
| 520 | if (p2) |
| 521 | { |
| 522 | bm0_clear(p2->bm1.bm0_r, a & ADDR0_MASK); |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | /** Clear all references to stores in bitmap bm starting at address a1 and |
| 528 | * up to but not including address a2. |
| 529 | */ |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 530 | void bm_clear_store(struct bitmap* const bm, |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 531 | const Addr a1, const Addr a2) |
| 532 | { |
| 533 | Addr a; |
| 534 | |
| 535 | for (a = a1; a < a2; a++) |
| 536 | { |
| 537 | struct bitmap2* const p2 = bm2_lookup_exclusive(bm, a >> ADDR0_BITS); |
| 538 | if (p2) |
| 539 | { |
| 540 | bm0_clear(p2->bm1.bm0_w, a & ADDR0_MASK); |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 545 | /** Clear bitmap bm starting at address a1 and up to but not including address |
| 546 | * a2. Return True if and only if any of the addresses was set before |
| 547 | * clearing. |
| 548 | */ |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 549 | Bool bm_test_and_clear(struct bitmap* const bm, |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 550 | const Addr a1, const Addr a2) |
| 551 | { |
| 552 | Bool result; |
| 553 | |
| 554 | result = bm_has_any_access(bm, a1, a2) != 0; |
| 555 | bm_clear(bm, a1, a2); |
| 556 | return result; |
| 557 | } |
| 558 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 559 | Bool bm_has_conflict_with(struct bitmap* const bm, |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 560 | const Addr a1, const Addr a2, |
| 561 | const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 562 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 563 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 564 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 565 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 566 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 567 | for (b = a1; b < a2; b = b_next) |
| 568 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 569 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 570 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 571 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 572 | if (b_next > a2) |
| 573 | { |
| 574 | b_next = a2; |
| 575 | } |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 576 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 577 | if (bm2) |
| 578 | { |
| 579 | Addr b_start; |
| 580 | Addr b_end; |
| 581 | UWord b0; |
| 582 | const struct bitmap1* const p1 = &bm2->bm1; |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 583 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 584 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 585 | b_start = a1; |
| 586 | else |
| 587 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 588 | b_start = (bm2->addr << ADDR0_BITS); |
| 589 | else |
| 590 | break; |
| 591 | tl_assert(a1 <= b_start && b_start <= a2); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 592 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 593 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 594 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 595 | else |
| 596 | b_end = a2; |
| 597 | tl_assert(a1 <= b_end && b_end <= a2); |
| 598 | tl_assert(b_start < b_end); |
| 599 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 600 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 601 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 602 | { |
| 603 | if (access_type == eLoad) |
| 604 | { |
| 605 | if (bm0_is_set(p1->bm0_w, b0)) |
| 606 | { |
| 607 | return True; |
| 608 | } |
| 609 | } |
| 610 | else |
| 611 | { |
| 612 | tl_assert(access_type == eStore); |
| 613 | if (bm0_is_set(p1->bm0_r, b0) |
| 614 | | bm0_is_set(p1->bm0_w, b0)) |
| 615 | { |
| 616 | return True; |
| 617 | } |
| 618 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 619 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 623 | } |
| 624 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 625 | Bool bm_load_has_conflict_with(struct bitmap* const bm, |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 626 | const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 627 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 628 | return bm_has_conflict_with(bm, a1, a2, eLoad); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 629 | } |
| 630 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 631 | Bool bm_load_1_has_conflict_with(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 632 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 633 | return bm_aligned_load_has_conflict_with(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 634 | } |
| 635 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 636 | Bool bm_load_2_has_conflict_with(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 637 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 638 | if ((a1 & 1) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 639 | return bm_aligned_load_has_conflict_with(bm, a1, 2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 640 | else |
| 641 | return bm_has_conflict_with(bm, a1, a1 + 2, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 642 | } |
| 643 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 644 | Bool bm_load_4_has_conflict_with(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 645 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 646 | if ((a1 & 3) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 647 | return bm_aligned_load_has_conflict_with(bm, a1, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 648 | else |
| 649 | return bm_has_conflict_with(bm, a1, a1 + 4, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 650 | } |
| 651 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 652 | Bool bm_load_8_has_conflict_with(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 653 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 654 | if ((a1 & 7) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 655 | return bm_aligned_load_has_conflict_with(bm, a1, 8); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 656 | else |
| 657 | return bm_has_conflict_with(bm, a1, a1 + 8, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 658 | } |
| 659 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 660 | Bool bm_store_1_has_conflict_with(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 661 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 662 | return bm_aligned_store_has_conflict_with(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 663 | } |
| 664 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 665 | Bool bm_store_2_has_conflict_with(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 666 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 667 | if ((a1 & 1) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 668 | return bm_aligned_store_has_conflict_with(bm, a1, 2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 669 | else |
| 670 | return bm_has_conflict_with(bm, a1, a1 + 2, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 671 | } |
| 672 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 673 | Bool bm_store_4_has_conflict_with(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 674 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 675 | if ((a1 & 3) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 676 | return bm_aligned_store_has_conflict_with(bm, a1, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 677 | else |
| 678 | return bm_has_conflict_with(bm, a1, a1 + 4, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 679 | } |
| 680 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 681 | Bool bm_store_8_has_conflict_with(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 682 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 683 | if ((a1 & 7) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 684 | return bm_aligned_store_has_conflict_with(bm, a1, 8); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 685 | else |
| 686 | return bm_has_conflict_with(bm, a1, a1 + 8, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 687 | } |
| 688 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 689 | Bool bm_store_has_conflict_with(struct bitmap* const bm, |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 690 | const Addr a1, const Addr a2) |
| 691 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 692 | return bm_has_conflict_with(bm, a1, a2, eStore); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 693 | } |
| 694 | |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 695 | /** Return True if the two bitmaps *lhs and *rhs are identical, and false |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 696 | * if not. |
| 697 | */ |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 698 | Bool bm_equal(struct bitmap* const lhs, struct bitmap* const rhs) |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 699 | { |
| 700 | struct bitmap2* bm2l; |
| 701 | struct bitmap2ref* bm2l_ref; |
| 702 | struct bitmap2* bm2r; |
| 703 | const struct bitmap2ref* bm2r_ref; |
| 704 | |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 705 | /* It's not possible to have two independent iterators over the same OSet, */ |
| 706 | /* so complain if lhs == rhs. */ |
| 707 | tl_assert(lhs != rhs); |
| 708 | |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 709 | VG_(OSetGen_ResetIter)(lhs->oset); |
| 710 | VG_(OSetGen_ResetIter)(rhs->oset); |
| 711 | |
| 712 | for ( ; (bm2l_ref = VG_(OSetGen_Next)(lhs->oset)) != 0; ) |
| 713 | { |
bart | f5acbbc | 2008-05-10 08:22:20 +0000 | [diff] [blame] | 714 | while (bm2l_ref |
| 715 | && (bm2l = bm2l_ref->bm2) |
| 716 | && bm2l |
| 717 | && ! bm_has_any_access(lhs, |
| 718 | bm2l->addr << ADDR0_BITS, |
| 719 | (bm2l->addr + 1) << ADDR0_BITS)) |
| 720 | { |
| 721 | bm2l_ref = VG_(OSetGen_Next)(lhs->oset); |
| 722 | } |
| 723 | if (bm2l_ref == 0) |
| 724 | break; |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 725 | tl_assert(bm2l); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 726 | #if 0 |
| 727 | VG_(message)(Vg_DebugMsg, "bm_equal: at 0x%lx", bm2l->addr << ADDR0_BITS); |
| 728 | #endif |
| 729 | |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 730 | bm2r_ref = VG_(OSetGen_Next)(rhs->oset); |
| 731 | if (bm2r_ref == 0) |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 732 | { |
| 733 | #if 0 |
| 734 | VG_(message)(Vg_DebugMsg, "bm_equal: no match found"); |
| 735 | #endif |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 736 | return False; |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 737 | } |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 738 | bm2r = bm2r_ref->bm2; |
| 739 | tl_assert(bm2r); |
| 740 | tl_assert(bm_has_any_access(rhs, |
| 741 | bm2r->addr << ADDR0_BITS, |
| 742 | (bm2r->addr + 1) << ADDR0_BITS)); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 743 | |
| 744 | if (bm2l != bm2r |
| 745 | && (bm2l->addr != bm2r->addr |
| 746 | || VG_(memcmp)(&bm2l->bm1, &bm2r->bm1, sizeof(bm2l->bm1)) != 0)) |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 747 | { |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 748 | #if 0 |
| 749 | VG_(message)(Vg_DebugMsg, "bm_equal: rhs 0x%lx -- returning false", |
| 750 | bm2r->addr << ADDR0_BITS); |
| 751 | #endif |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 752 | return False; |
| 753 | } |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 754 | } |
| 755 | bm2r = VG_(OSetGen_Next)(rhs->oset); |
| 756 | if (bm2r) |
| 757 | { |
| 758 | tl_assert(bm_has_any_access(rhs, |
| 759 | bm2r->addr << ADDR0_BITS, |
| 760 | (bm2r->addr + 1) << ADDR0_BITS)); |
| 761 | #if 0 |
| 762 | VG_(message)(Vg_DebugMsg, |
| 763 | "bm_equal: remaining rhs 0x%lx -- returning false", |
| 764 | bm2r->addr << ADDR0_BITS); |
| 765 | #endif |
| 766 | return False; |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 767 | } |
| 768 | return True; |
| 769 | } |
| 770 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 771 | void bm_swap(struct bitmap* const bm1, struct bitmap* const bm2) |
| 772 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 773 | OSet* const tmp = bm1->oset; |
| 774 | bm1->oset = bm2->oset; |
| 775 | bm2->oset = tmp; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 776 | } |
| 777 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 778 | /** Merge bitmaps *lhs and *rhs into *lhs. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 779 | void bm_merge2(struct bitmap* const lhs, |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 780 | struct bitmap* const rhs) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 781 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 782 | struct bitmap2* bm2l; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 783 | struct bitmap2ref* bm2l_ref; |
| 784 | struct bitmap2* bm2r; |
| 785 | const struct bitmap2ref* bm2r_ref; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 786 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 787 | VG_(OSetGen_ResetIter)(rhs->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 788 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 789 | for ( ; (bm2r_ref = VG_(OSetGen_Next)(rhs->oset)) != 0; ) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 790 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 791 | bm2r = bm2r_ref->bm2; |
| 792 | bm2l_ref = VG_(OSetGen_Lookup)(lhs->oset, &bm2r->addr); |
| 793 | if (bm2l_ref) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 794 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 795 | bm2l = bm2l_ref->bm2; |
| 796 | if (bm2l != bm2r) |
| 797 | { |
| 798 | if (bm2l->refcnt > 1) |
| 799 | bm2l = bm2_make_exclusive(lhs, bm2l_ref); |
| 800 | bm2_merge(bm2l, bm2r); |
| 801 | } |
| 802 | } |
| 803 | else |
| 804 | { |
| 805 | bm2_insert_addref(lhs, bm2r); |
| 806 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 807 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /** |
| 811 | * Report whether there are any RW / WR / WW patterns in lhs and rhs. |
| 812 | * @param lhs First bitmap. |
| 813 | * @param rhs Bitmap to be compared with lhs. |
| 814 | * @return !=0 if there are data races, == 0 if there are none. |
| 815 | */ |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 816 | int bm_has_races(struct bitmap* const lhs, |
| 817 | struct bitmap* const rhs) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 818 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 819 | VG_(OSetGen_ResetIter)(lhs->oset); |
| 820 | VG_(OSetGen_ResetIter)(rhs->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 821 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 822 | for (;;) |
| 823 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 824 | const struct bitmap2ref* bm2l_ref; |
| 825 | const struct bitmap2ref* bm2r_ref; |
| 826 | const struct bitmap2* bm2l; |
| 827 | const struct bitmap2* bm2r; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 828 | const struct bitmap1* bm1l; |
| 829 | const struct bitmap1* bm1r; |
| 830 | unsigned k; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 831 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 832 | bm2l_ref = VG_(OSetGen_Next)(lhs->oset); |
| 833 | bm2l = bm2l_ref->bm2; |
| 834 | bm2r_ref = VG_(OSetGen_Next)(rhs->oset); |
| 835 | bm2r = bm2r_ref->bm2; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 836 | while (bm2l && bm2r && bm2l->addr != bm2r->addr) |
| 837 | { |
| 838 | if (bm2l->addr < bm2r->addr) |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 839 | bm2l = (bm2l_ref = VG_(OSetGen_Next)(lhs->oset))->bm2; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 840 | else |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 841 | bm2r = (bm2r_ref = VG_(OSetGen_Next)(rhs->oset))->bm2; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 842 | } |
| 843 | if (bm2l == 0 || bm2r == 0) |
| 844 | break; |
| 845 | |
| 846 | bm1l = &bm2l->bm1; |
| 847 | bm1r = &bm2r->bm1; |
| 848 | |
| 849 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 850 | { |
| 851 | unsigned b; |
| 852 | for (b = 0; b < BITS_PER_UWORD; b++) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 853 | { |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 854 | UWord const access_mask |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 855 | = ((bm1l->bm0_r[k] & bm0_mask(b)) ? LHS_R : 0) |
| 856 | | ((bm1l->bm0_w[k] & bm0_mask(b)) ? LHS_W : 0) |
| 857 | | ((bm1r->bm0_r[k] & bm0_mask(b)) ? RHS_R : 0) |
| 858 | | ((bm1r->bm0_w[k] & bm0_mask(b)) ? RHS_W : 0); |
| 859 | Addr const a = MAKE_ADDRESS(bm2l->addr, k * BITS_PER_UWORD | b); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 860 | if (HAS_RACE(access_mask) && ! drd_is_suppressed(a, a + 1)) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 861 | { |
| 862 | return 1; |
| 863 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 864 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 868 | } |
| 869 | |
bart | 7e81a17 | 2008-06-09 19:50:51 +0000 | [diff] [blame^] | 870 | void bm_print(struct bitmap* const bm) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 871 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 872 | struct bitmap2* bm2; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 873 | struct bitmap2ref* bm2ref; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 874 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 875 | VG_(OSetGen_ResetIter)(bm->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 876 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 877 | for ( ; (bm2ref = VG_(OSetGen_Next)(bm->oset)) != 0; ) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 878 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 879 | const struct bitmap1* bm1; |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 880 | unsigned b; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 881 | |
| 882 | bm2 = bm2ref->bm2; |
| 883 | bm1 = &bm2->bm1; |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 884 | for (b = 0; b < ADDR0_COUNT; b++) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 885 | { |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 886 | const Addr a = (bm2->addr << ADDR0_BITS) | b; |
| 887 | const Bool r = bm0_is_set(bm1->bm0_r, b) != 0; |
| 888 | const Bool w = bm0_is_set(bm1->bm0_w, b) != 0; |
| 889 | if (r || w) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 890 | { |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 891 | VG_(printf)("0x%08lx %c %c\n", |
| 892 | a, |
| 893 | w ? 'W' : ' ', |
| 894 | r ? 'R' : ' '); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 895 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 896 | } |
| 897 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | ULong bm_get_bitmap_creation_count(void) |
| 901 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 902 | return s_bitmap_creation_count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 903 | } |
| 904 | |
bart | 588d90f | 2008-04-06 13:05:58 +0000 | [diff] [blame] | 905 | ULong bm_get_bitmap2_node_creation_count(void) |
| 906 | { |
| 907 | return s_bitmap2_creation_count; |
| 908 | } |
| 909 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 910 | ULong bm_get_bitmap2_creation_count(void) |
| 911 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 912 | return s_bitmap2_creation_count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 913 | } |
| 914 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 915 | /** Allocate and initialize a second level bitmap. */ |
| 916 | static struct bitmap2* bm2_new(const UWord a1) |
| 917 | { |
| 918 | struct bitmap2* bm2; |
| 919 | |
| 920 | bm2 = VG_(malloc)(sizeof(*bm2)); |
| 921 | bm2->addr = a1; |
| 922 | bm2->refcnt = 1; |
| 923 | |
| 924 | s_bitmap2_creation_count++; |
| 925 | |
| 926 | return bm2; |
| 927 | } |
| 928 | |
| 929 | /** Make a copy of a shared second level bitmap such that the copy can be |
| 930 | * modified. |
| 931 | * |
| 932 | * @param a1 client address shifted right by ADDR0_BITS. |
| 933 | * @param bm bitmap pointer. |
| 934 | */ |
| 935 | static |
| 936 | struct bitmap2* bm2_make_exclusive(struct bitmap* const bm, |
| 937 | struct bitmap2ref* const bm2ref) |
| 938 | { |
| 939 | UWord a1; |
| 940 | struct bitmap2* bm2; |
| 941 | struct bitmap2* bm2_copy; |
| 942 | |
| 943 | tl_assert(bm); |
| 944 | tl_assert(bm2ref); |
| 945 | bm2 = bm2ref->bm2; |
| 946 | tl_assert(bm2); |
| 947 | tl_assert(bm2->refcnt > 1); |
| 948 | bm2->refcnt--; |
| 949 | tl_assert(bm2->refcnt >= 1); |
| 950 | a1 = bm2->addr; |
| 951 | bm2_copy = bm2_new(a1); |
| 952 | tl_assert(bm2_copy); |
| 953 | tl_assert(bm2_copy->addr == a1); |
| 954 | tl_assert(bm2_copy->refcnt == 1); |
| 955 | VG_(memcpy)(&bm2_copy->bm1, &bm2->bm1, sizeof(bm2->bm1)); |
| 956 | bm2ref->bm2 = bm2_copy; |
| 957 | |
| 958 | bm_update_cache(bm, a1, bm2_copy); |
| 959 | |
| 960 | return bm2_copy; |
| 961 | } |
| 962 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 963 | static void bm2_merge(struct bitmap2* const bm2l, |
| 964 | const struct bitmap2* const bm2r) |
| 965 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 966 | unsigned k; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 967 | |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 968 | tl_assert(bm2l); |
| 969 | tl_assert(bm2r); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 970 | tl_assert(bm2l->addr == bm2r->addr); |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 971 | tl_assert(bm2l->refcnt == 1); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 972 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 973 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 974 | { |
| 975 | bm2l->bm1.bm0_r[k] |= bm2r->bm1.bm0_r[k]; |
| 976 | } |
| 977 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 978 | { |
| 979 | bm2l->bm1.bm0_w[k] |= bm2r->bm1.bm0_w[k]; |
| 980 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 981 | } |