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