sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 2 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 3 | |
sewardj | 03f8d3f | 2012-08-05 15:46:46 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2012 Bart Van Assche <bvanassche@acm.org>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU General Public License as |
| 8 | published by the Free Software Foundation; either version 2 of the |
| 9 | License, or (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 19 | 02111-1307, USA. |
| 20 | |
| 21 | The GNU General Public License is contained in the file COPYING. |
| 22 | */ |
| 23 | |
| 24 | |
bart | 39934d6 | 2009-02-15 16:18:03 +0000 | [diff] [blame] | 25 | #include "drd_basics.h" /* DRD_() */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 26 | #include "drd_bitmap.h" |
| 27 | #include "drd_error.h" |
| 28 | #include "drd_suppression.h" |
bart | 39934d6 | 2009-02-15 16:18:03 +0000 | [diff] [blame] | 29 | #include "pub_drd_bitmap.h" |
| 30 | #include "pub_tool_basics.h" /* Addr, SizeT */ |
| 31 | #include "pub_tool_debuginfo.h" /* VG_(get_objname)() */ |
| 32 | #include "pub_tool_libcassert.h" /* tl_assert() */ |
| 33 | #include "pub_tool_libcbase.h" /* VG_(memset) */ |
| 34 | #include "pub_tool_libcprint.h" /* VG_(printf) */ |
| 35 | #include "pub_tool_machine.h" /* VG_(get_IP)() */ |
| 36 | #include "pub_tool_mallocfree.h" /* VG_(malloc), VG_(free) */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 37 | |
| 38 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 39 | /* Local function declarations. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 40 | |
| 41 | static void bm2_merge(struct bitmap2* const bm2l, |
| 42 | const struct bitmap2* const bm2r); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 43 | static void bm2_print(const struct bitmap2* const bm2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 44 | |
| 45 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 46 | /* Local variables. */ |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 47 | |
bart | e44bccc | 2012-01-18 09:46:57 +0000 | [diff] [blame] | 48 | static OSet* s_bm2_set_template; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 49 | static ULong s_bitmap_creation_count; |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 50 | static ULong s_bitmap_merge_count; |
| 51 | static ULong s_bitmap2_merge_count; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 52 | |
| 53 | |
| 54 | /* Function definitions. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 55 | |
bart | e44bccc | 2012-01-18 09:46:57 +0000 | [diff] [blame] | 56 | void DRD_(bm_module_init)(void) |
| 57 | { |
| 58 | tl_assert(!s_bm2_set_template); |
| 59 | s_bm2_set_template |
| 60 | = VG_(OSetGen_Create_With_Pool)(0, 0, VG_(malloc), "drd.bitmap.bn.2", |
| 61 | VG_(free), 512, sizeof(struct bitmap2)); |
| 62 | } |
| 63 | |
| 64 | void DRD_(bm_module_cleanup)(void) |
| 65 | { |
| 66 | tl_assert(s_bm2_set_template); |
| 67 | VG_(OSetGen_Destroy)(s_bm2_set_template); |
| 68 | s_bm2_set_template = NULL; |
| 69 | } |
| 70 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 71 | struct bitmap* DRD_(bm_new)() |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 72 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 73 | struct bitmap* bm; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 74 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 75 | /* If this assert fails, fix the definition of BITS_PER_BITS_PER_UWORD */ |
| 76 | /* in drd_bitmap.h. */ |
| 77 | tl_assert((1 << BITS_PER_BITS_PER_UWORD) == BITS_PER_UWORD); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 78 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 79 | bm = VG_(malloc)("drd.bitmap.bn.1", sizeof(*bm)); |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 80 | DRD_(bm_init)(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 81 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 82 | return bm; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 83 | } |
| 84 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 85 | void DRD_(bm_delete)(struct bitmap* const bm) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 86 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 87 | tl_assert(bm); |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 88 | |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 89 | DRD_(bm_cleanup)(bm); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 90 | VG_(free)(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 91 | } |
| 92 | |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 93 | /** Initialize *bm. */ |
| 94 | void DRD_(bm_init)(struct bitmap* const bm) |
| 95 | { |
| 96 | unsigned i; |
| 97 | |
| 98 | tl_assert(bm); |
bart | 9f617a8 | 2009-06-21 18:08:31 +0000 | [diff] [blame] | 99 | /* |
| 100 | * Cache initialization. a1 is initialized with a value that never can |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 101 | * match any valid address: the upper (ADDR_LSB_BITS + ADDR_IGNORED_BITS) |
| 102 | * bits of a1 are always zero for a valid cache entry. |
| 103 | */ |
| 104 | for (i = 0; i < DRD_BITMAP_N_CACHE_ELEM; i++) |
| 105 | { |
| 106 | bm->cache[i].a1 = ~(UWord)1; |
| 107 | bm->cache[i].bm2 = 0; |
| 108 | } |
bart | e44bccc | 2012-01-18 09:46:57 +0000 | [diff] [blame] | 109 | bm->oset = VG_(OSetGen_EmptyClone)(s_bm2_set_template); |
bart | 9f617a8 | 2009-06-21 18:08:31 +0000 | [diff] [blame] | 110 | |
| 111 | s_bitmap_creation_count++; |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** Free the memory allocated by DRD_(bm_init)(). */ |
| 115 | void DRD_(bm_cleanup)(struct bitmap* const bm) |
| 116 | { |
| 117 | VG_(OSetGen_Destroy)(bm->oset); |
| 118 | } |
| 119 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 120 | /** |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 121 | * 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] | 122 | * bitmap bm. |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 123 | * |
| 124 | * @note The current implementation of bm_access_range does not work for the |
| 125 | * highest addresses in the address range. At least on Linux this is |
| 126 | * not a problem since the upper part of the address space is reserved |
| 127 | * for the kernel. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 128 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 129 | void DRD_(bm_access_range)(struct bitmap* const bm, |
| 130 | const Addr a1, const Addr a2, |
| 131 | const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 132 | { |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 133 | tl_assert(access_type == eLoad || access_type == eStore); |
| 134 | |
| 135 | if (access_type == eLoad) |
| 136 | return DRD_(bm_access_range_load)(bm, a1, a2); |
| 137 | else |
| 138 | return DRD_(bm_access_range_store)(bm, a1, a2); |
| 139 | } |
| 140 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 141 | void DRD_(bm_access_range_load)(struct bitmap* const bm, Addr a1, Addr a2) |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 142 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 143 | Addr b, b_next; |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 144 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 145 | tl_assert(bm); |
bart | a300398 | 2010-09-08 16:29:17 +0000 | [diff] [blame] | 146 | tl_assert(a1 <= a2); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 147 | tl_assert(a2 < first_address_with_higher_msb(a2)); |
| 148 | tl_assert(a1 == first_address_with_same_lsb(a1)); |
| 149 | tl_assert(a2 == first_address_with_same_lsb(a2)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 150 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 151 | for (b = a1; b < a2; b = b_next) |
| 152 | { |
| 153 | Addr b_start; |
| 154 | Addr b_end; |
| 155 | struct bitmap2* bm2; |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 156 | UWord b0; |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 157 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 158 | b_next = first_address_with_higher_msb(b); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 159 | if (b_next > a2) |
| 160 | { |
| 161 | b_next = a2; |
| 162 | } |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 163 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 164 | bm2 = bm2_lookup_or_insert_exclusive(bm, address_msb(b)); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 165 | tl_assert(bm2); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 166 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 167 | if (make_address(bm2->addr, 0) < a1) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 168 | b_start = a1; |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 169 | else |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 170 | if (make_address(bm2->addr, 0) < a2) |
| 171 | b_start = make_address(bm2->addr, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 172 | else |
| 173 | break; |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 174 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 175 | if (make_address(bm2->addr + 1, 0) < a2) |
| 176 | b_end = make_address(bm2->addr + 1, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 177 | else |
| 178 | b_end = a2; |
bart | f43b177 | 2009-04-25 08:08:33 +0000 | [diff] [blame] | 179 | |
| 180 | tl_assert(a1 <= b_start && b_start < b_end && b_end && b_end <= a2); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 181 | tl_assert(address_msb(b_start) == address_msb(b_end - 1)); |
| 182 | tl_assert(address_lsb(b_start) <= address_lsb(b_end - 1)); |
bart | f43b177 | 2009-04-25 08:08:33 +0000 | [diff] [blame] | 183 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 184 | if (address_lsb(b_start) == 0 && address_lsb(b_end) == 0) |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 185 | { |
bart | f43b177 | 2009-04-25 08:08:33 +0000 | [diff] [blame] | 186 | unsigned k; |
| 187 | |
| 188 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 189 | { |
| 190 | bm2->bm1.bm0_r[k] = ~(UWord)0; |
| 191 | } |
| 192 | } |
| 193 | else |
| 194 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 195 | for (b0 = address_lsb(b_start); b0 <= address_lsb(b_end - 1); b0++) |
bart | f43b177 | 2009-04-25 08:08:33 +0000 | [diff] [blame] | 196 | { |
| 197 | bm0_set(bm2->bm1.bm0_r, b0); |
| 198 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 199 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 200 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 201 | } |
| 202 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 203 | void DRD_(bm_access_load_1)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 204 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 205 | bm_access_aligned_load(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 206 | } |
| 207 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 208 | void DRD_(bm_access_load_2)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 209 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 210 | if ((a1 & 1) == 0) |
| 211 | bm_access_aligned_load(bm, a1, 2); |
| 212 | else |
| 213 | DRD_(bm_access_range)(bm, a1, a1 + 2, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 214 | } |
| 215 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 216 | void DRD_(bm_access_load_4)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 217 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 218 | if ((a1 & 3) == 0) |
| 219 | bm_access_aligned_load(bm, a1, 4); |
| 220 | else |
| 221 | DRD_(bm_access_range)(bm, a1, a1 + 4, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 222 | } |
| 223 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 224 | void DRD_(bm_access_load_8)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 225 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 226 | if ((a1 & 7) == 0) |
| 227 | bm_access_aligned_load(bm, a1, 8); |
| 228 | else if ((a1 & 3) == 0) |
| 229 | { |
| 230 | bm_access_aligned_load(bm, a1 + 0, 4); |
| 231 | bm_access_aligned_load(bm, a1 + 4, 4); |
| 232 | } |
| 233 | else |
| 234 | DRD_(bm_access_range)(bm, a1, a1 + 8, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 235 | } |
| 236 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 237 | void DRD_(bm_access_range_store)(struct bitmap* const bm, |
| 238 | const Addr a1, const Addr a2) |
bart | f5acbbc | 2008-05-10 08:22:20 +0000 | [diff] [blame] | 239 | { |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 240 | Addr b, b_next; |
| 241 | |
| 242 | tl_assert(bm); |
bart | a300398 | 2010-09-08 16:29:17 +0000 | [diff] [blame] | 243 | tl_assert(a1 <= a2); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 244 | tl_assert(a2 < first_address_with_higher_msb(a2)); |
| 245 | tl_assert(a1 == first_address_with_same_lsb(a1)); |
| 246 | tl_assert(a2 == first_address_with_same_lsb(a2)); |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 247 | |
| 248 | for (b = a1; b < a2; b = b_next) |
| 249 | { |
| 250 | Addr b_start; |
| 251 | Addr b_end; |
| 252 | struct bitmap2* bm2; |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 253 | UWord b0; |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 254 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 255 | b_next = first_address_with_higher_msb(b); |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 256 | if (b_next > a2) |
| 257 | { |
| 258 | b_next = a2; |
| 259 | } |
| 260 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 261 | bm2 = bm2_lookup_or_insert_exclusive(bm, address_msb(b)); |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 262 | tl_assert(bm2); |
| 263 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 264 | if (make_address(bm2->addr, 0) < a1) |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 265 | b_start = a1; |
| 266 | else |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 267 | if (make_address(bm2->addr, 0) < a2) |
| 268 | b_start = make_address(bm2->addr, 0); |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 269 | else |
| 270 | break; |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 271 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 272 | if (make_address(bm2->addr + 1, 0) < a2) |
| 273 | b_end = make_address(bm2->addr + 1, 0); |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 274 | else |
| 275 | b_end = a2; |
bart | f43b177 | 2009-04-25 08:08:33 +0000 | [diff] [blame] | 276 | |
| 277 | tl_assert(a1 <= b_start && b_start < b_end && b_end && b_end <= a2); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 278 | tl_assert(address_msb(b_start) == address_msb(b_end - 1)); |
| 279 | tl_assert(address_lsb(b_start) <= address_lsb(b_end - 1)); |
bart | f43b177 | 2009-04-25 08:08:33 +0000 | [diff] [blame] | 280 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 281 | if (address_lsb(b_start) == 0 && address_lsb(b_end) == 0) |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 282 | { |
bart | f43b177 | 2009-04-25 08:08:33 +0000 | [diff] [blame] | 283 | unsigned k; |
| 284 | |
| 285 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 286 | { |
| 287 | bm2->bm1.bm0_w[k] = ~(UWord)0; |
| 288 | } |
| 289 | } |
| 290 | else |
| 291 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 292 | for (b0 = address_lsb(b_start); b0 <= address_lsb(b_end - 1); b0++) |
bart | f43b177 | 2009-04-25 08:08:33 +0000 | [diff] [blame] | 293 | { |
| 294 | bm0_set(bm2->bm1.bm0_w, b0); |
| 295 | } |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
bart | f5acbbc | 2008-05-10 08:22:20 +0000 | [diff] [blame] | 298 | } |
| 299 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 300 | void DRD_(bm_access_store_1)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 301 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 302 | bm_access_aligned_store(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 303 | } |
| 304 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 305 | void DRD_(bm_access_store_2)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 306 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 307 | if ((a1 & 1) == 0) |
| 308 | bm_access_aligned_store(bm, a1, 2); |
| 309 | else |
| 310 | DRD_(bm_access_range)(bm, a1, a1 + 2, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 311 | } |
| 312 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 313 | void DRD_(bm_access_store_4)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 314 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 315 | if ((a1 & 3) == 0) |
| 316 | bm_access_aligned_store(bm, a1, 4); |
| 317 | else |
| 318 | DRD_(bm_access_range)(bm, a1, a1 + 4, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 319 | } |
| 320 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 321 | void DRD_(bm_access_store_8)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 322 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 323 | if ((a1 & 7) == 0) |
| 324 | bm_access_aligned_store(bm, a1, 8); |
| 325 | else if ((a1 & 3) == 0) |
| 326 | { |
| 327 | bm_access_aligned_store(bm, a1 + 0, 4); |
| 328 | bm_access_aligned_store(bm, a1 + 4, 4); |
| 329 | } |
| 330 | else |
| 331 | DRD_(bm_access_range)(bm, a1, a1 + 8, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 332 | } |
| 333 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 334 | Bool DRD_(bm_has)(struct bitmap* const bm, const Addr a1, const Addr a2, |
| 335 | const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 336 | { |
bart | da3a77b | 2009-04-23 20:07:23 +0000 | [diff] [blame] | 337 | tl_assert(access_type == eLoad || access_type == eStore); |
bart | da3a77b | 2009-04-23 20:07:23 +0000 | [diff] [blame] | 338 | |
| 339 | if (access_type == eLoad) |
| 340 | return DRD_(bm_has_any_load)(bm, a1, a2); |
| 341 | else |
| 342 | return DRD_(bm_has_any_store)(bm, a1, a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 343 | } |
| 344 | |
bart | 59d93d7 | 2011-12-12 19:02:34 +0000 | [diff] [blame] | 345 | Bool DRD_(bm_has_any_load_g)(struct bitmap* const bm) |
| 346 | { |
| 347 | struct bitmap2* bm2; |
| 348 | |
| 349 | tl_assert(bm); |
| 350 | |
| 351 | VG_(OSetGen_ResetIter)(bm->oset); |
| 352 | for ( ; (bm2 = VG_(OSetGen_Next)(bm->oset)) != NULL; ) { |
| 353 | Addr b_start; |
| 354 | Addr b_end; |
| 355 | UWord b0; |
| 356 | const struct bitmap1* const p1 = &bm2->bm1; |
| 357 | |
| 358 | b_start = make_address(bm2->addr, 0); |
| 359 | b_end = make_address(bm2->addr + 1, 0); |
| 360 | |
| 361 | for (b0 = address_lsb(b_start); b0 <= address_lsb(b_end - 1); b0++) |
| 362 | if (bm0_is_set(p1->bm0_r, b0)) |
| 363 | return True; |
| 364 | } |
| 365 | return False; |
| 366 | } |
| 367 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 368 | Bool |
| 369 | DRD_(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] | 370 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 371 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 372 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 373 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 374 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 375 | for (b = a1; b < a2; b = b_next) |
| 376 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 377 | const struct bitmap2* bm2 = bm2_lookup(bm, address_msb(b)); |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 378 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 379 | b_next = first_address_with_higher_msb(b); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 380 | if (b_next > a2) |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 381 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 382 | b_next = a2; |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 383 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 384 | |
| 385 | if (bm2) |
| 386 | { |
| 387 | Addr b_start; |
| 388 | Addr b_end; |
| 389 | UWord b0; |
| 390 | const struct bitmap1* const p1 = &bm2->bm1; |
| 391 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 392 | if (make_address(bm2->addr, 0) < a1) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 393 | b_start = a1; |
| 394 | else |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 395 | if (make_address(bm2->addr, 0) < a2) |
| 396 | b_start = make_address(bm2->addr, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 397 | else |
| 398 | break; |
| 399 | tl_assert(a1 <= b_start && b_start <= a2); |
| 400 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 401 | if (make_address(bm2->addr + 1, 0) < a2) |
| 402 | b_end = make_address(bm2->addr + 1, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 403 | else |
| 404 | b_end = a2; |
| 405 | tl_assert(a1 <= b_end && b_end <= a2); |
| 406 | tl_assert(b_start < b_end); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 407 | tl_assert(address_lsb(b_start) <= address_lsb(b_end - 1)); |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 408 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 409 | for (b0 = address_lsb(b_start); b0 <= address_lsb(b_end - 1); b0++) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 410 | { |
| 411 | if (bm0_is_set(p1->bm0_r, b0)) |
| 412 | { |
| 413 | return True; |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | return 0; |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 419 | } |
| 420 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 421 | Bool DRD_(bm_has_any_store)(struct bitmap* const bm, |
| 422 | const Addr a1, const Addr a2) |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 423 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 424 | Addr b, b_next; |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 425 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 426 | tl_assert(bm); |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 427 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 428 | for (b = a1; b < a2; b = b_next) |
| 429 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 430 | const struct bitmap2* bm2 = bm2_lookup(bm, address_msb(b)); |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 431 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 432 | b_next = first_address_with_higher_msb(b); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 433 | if (b_next > a2) |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 434 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 435 | b_next = a2; |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 436 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 437 | |
| 438 | if (bm2) |
| 439 | { |
| 440 | Addr b_start; |
| 441 | Addr b_end; |
| 442 | UWord b0; |
| 443 | const struct bitmap1* const p1 = &bm2->bm1; |
| 444 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 445 | if (make_address(bm2->addr, 0) < a1) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 446 | b_start = a1; |
| 447 | else |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 448 | if (make_address(bm2->addr, 0) < a2) |
| 449 | b_start = make_address(bm2->addr, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 450 | else |
| 451 | break; |
| 452 | tl_assert(a1 <= b_start && b_start <= a2); |
| 453 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 454 | if (make_address(bm2->addr + 1, 0) < a2) |
| 455 | b_end = make_address(bm2->addr + 1, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 456 | else |
| 457 | b_end = a2; |
| 458 | tl_assert(a1 <= b_end && b_end <= a2); |
| 459 | tl_assert(b_start < b_end); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 460 | tl_assert(address_lsb(b_start) <= address_lsb(b_end - 1)); |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 461 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 462 | for (b0 = address_lsb(b_start); b0 <= address_lsb(b_end - 1); b0++) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 463 | { |
| 464 | if (bm0_is_set(p1->bm0_w, b0)) |
| 465 | { |
| 466 | return True; |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 472 | } |
| 473 | |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 474 | /* Return True if there is a read access, write access or both */ |
| 475 | /* to any of the addresses in the range [ a1, a2 [ in bitmap bm. */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 476 | Bool DRD_(bm_has_any_access)(struct bitmap* const bm, |
| 477 | const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 478 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 479 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 480 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 481 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 482 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 483 | for (b = a1; b < a2; b = b_next) |
| 484 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 485 | const struct bitmap2* bm2 = bm2_lookup(bm, address_msb(b)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 486 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 487 | b_next = first_address_with_higher_msb(b); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 488 | if (b_next > a2) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 489 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 490 | b_next = a2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 491 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 492 | |
| 493 | if (bm2) |
| 494 | { |
| 495 | Addr b_start; |
| 496 | Addr b_end; |
| 497 | UWord b0; |
| 498 | const struct bitmap1* const p1 = &bm2->bm1; |
| 499 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 500 | if (make_address(bm2->addr, 0) < a1) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 501 | b_start = a1; |
| 502 | else |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 503 | if (make_address(bm2->addr, 0) < a2) |
| 504 | b_start = make_address(bm2->addr, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 505 | else |
| 506 | break; |
| 507 | tl_assert(a1 <= b_start && b_start <= a2); |
| 508 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 509 | if (make_address(bm2->addr + 1, 0) < a2) |
| 510 | b_end = make_address(bm2->addr + 1, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 511 | else |
| 512 | b_end = a2; |
| 513 | tl_assert(a1 <= b_end && b_end <= a2); |
| 514 | tl_assert(b_start < b_end); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 515 | tl_assert(address_lsb(b_start) <= address_lsb(b_end - 1)); |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 516 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 517 | for (b0 = address_lsb(b_start); b0 <= address_lsb(b_end - 1); b0++) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 518 | { |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 519 | /* |
| 520 | * Note: the statement below uses a binary or instead of a logical |
| 521 | * or on purpose. |
| 522 | */ |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 523 | if (bm0_is_set(p1->bm0_r, b0) | bm0_is_set(p1->bm0_w, b0)) |
| 524 | { |
| 525 | return True; |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 531 | } |
| 532 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 533 | /** |
| 534 | * Report whether an access of type access_type at address a is recorded in |
| 535 | * bitmap bm. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 536 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 537 | Bool DRD_(bm_has_1)(struct bitmap* const bm, |
| 538 | const Addr a, const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 539 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 540 | const struct bitmap2* p2; |
| 541 | const struct bitmap1* p1; |
| 542 | const UWord* p0; |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 543 | const UWord a0 = address_lsb(a); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 544 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 545 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 546 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 547 | p2 = bm2_lookup(bm, address_msb(a)); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 548 | if (p2) |
| 549 | { |
| 550 | p1 = &p2->bm1; |
| 551 | p0 = (access_type == eLoad) ? p1->bm0_r : p1->bm0_w; |
| 552 | return bm0_is_set(p0, a0) ? True : False; |
| 553 | } |
| 554 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 555 | } |
| 556 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 557 | void DRD_(bm_clear)(struct bitmap* const bm, Addr a1, Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 558 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 559 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 560 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 561 | tl_assert(bm); |
| 562 | tl_assert(a1); |
| 563 | tl_assert(a1 <= a2); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 564 | tl_assert(a1 == first_address_with_same_lsb(a1)); |
| 565 | tl_assert(a2 == first_address_with_same_lsb(a2)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 566 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 567 | for (b = a1; b < a2; b = b_next) |
| 568 | { |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 569 | struct bitmap2* p2; |
| 570 | Addr c; |
| 571 | |
| 572 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 573 | tl_assert(a1 <= b && b < a2); |
| 574 | #endif |
| 575 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 576 | p2 = bm2_lookup_exclusive(bm, address_msb(b)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 577 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 578 | b_next = first_address_with_higher_msb(b); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 579 | if (b_next > a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 580 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 581 | b_next = a2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 582 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 583 | |
bart | e2c7e67 | 2009-04-23 19:23:09 +0000 | [diff] [blame] | 584 | if (p2 == 0) |
| 585 | continue; |
| 586 | |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 587 | c = b; |
| 588 | /* If the first address in the bitmap that must be cleared does not */ |
| 589 | /* start on an UWord boundary, start clearing the first addresses. */ |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 590 | if (uword_lsb(address_lsb(c))) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 591 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 592 | Addr c_next = first_address_with_higher_uword_msb(c); |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 593 | if (c_next > b_next) |
| 594 | c_next = b_next; |
| 595 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 596 | tl_assert(a1 <= b && b <= c && c <= c_next && c_next <= b_next |
| 597 | && b_next <= a2); |
| 598 | #endif |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 599 | bm0_clear_range(p2->bm1.bm0_r, address_lsb(c), SCALED_SIZE(c_next - c)); |
| 600 | bm0_clear_range(p2->bm1.bm0_w, address_lsb(c), SCALED_SIZE(c_next - c)); |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 601 | c = c_next; |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 602 | } |
| 603 | /* If some UWords have to be cleared entirely, do this now. */ |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 604 | if (uword_lsb(address_lsb(c)) == 0) |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 605 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 606 | Addr c_next = first_address_with_same_uword_lsb(b_next); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 607 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 608 | tl_assert(uword_lsb(address_lsb(c)) == 0); |
| 609 | tl_assert(uword_lsb(address_lsb(c_next)) == 0); |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 610 | tl_assert(c_next <= b_next); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 611 | #endif |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 612 | if (c_next > c) |
| 613 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 614 | UWord idx = uword_msb(address_lsb(c)); |
| 615 | VG_(memset)(&p2->bm1.bm0_r[idx], 0, SCALED_SIZE((c_next - c) / 8)); |
| 616 | VG_(memset)(&p2->bm1.bm0_w[idx], 0, SCALED_SIZE((c_next - c) / 8)); |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 617 | c = c_next; |
| 618 | } |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 619 | } |
| 620 | /* If the last address in the bitmap that must be cleared does not */ |
| 621 | /* fall on an UWord boundary, clear the last addresses. */ |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 622 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 623 | tl_assert(a1 <= b && b <= c && c <= b_next && b_next <= a2); |
| 624 | #endif |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 625 | bm0_clear_range(p2->bm1.bm0_r, address_lsb(c), SCALED_SIZE(b_next - c)); |
| 626 | bm0_clear_range(p2->bm1.bm0_w, address_lsb(c), SCALED_SIZE(b_next - c)); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 627 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 628 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 629 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 630 | /** |
| 631 | * Clear all references to loads in bitmap bm starting at address a1 and |
| 632 | * up to but not including address a2. |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 633 | */ |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 634 | void DRD_(bm_clear_load)(struct bitmap* const bm, Addr a1, Addr a2) |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 635 | { |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 636 | Addr b, b_next; |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 637 | |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 638 | tl_assert(bm); |
| 639 | tl_assert(a1); |
| 640 | tl_assert(a1 <= a2); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 641 | tl_assert(a1 == first_address_with_same_lsb(a1)); |
| 642 | tl_assert(a2 == first_address_with_same_lsb(a2)); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 643 | |
| 644 | for (b = a1; b < a2; b = b_next) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 645 | { |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 646 | struct bitmap2* p2; |
| 647 | Addr c; |
| 648 | |
| 649 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 650 | tl_assert(a1 <= b && b < a2); |
| 651 | #endif |
| 652 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 653 | p2 = bm2_lookup_exclusive(bm, address_msb(b)); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 654 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 655 | b_next = first_address_with_higher_msb(b); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 656 | if (b_next > a2) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 657 | { |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 658 | b_next = a2; |
| 659 | } |
| 660 | |
bart | e2c7e67 | 2009-04-23 19:23:09 +0000 | [diff] [blame] | 661 | if (p2 == 0) |
| 662 | continue; |
| 663 | |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 664 | c = b; |
| 665 | /* If the first address in the bitmap that must be cleared does not */ |
| 666 | /* start on an UWord boundary, start clearing the first addresses. */ |
| 667 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 668 | tl_assert(a1 <= b && b <= c && c < b_next && b_next <= a2); |
| 669 | #endif |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 670 | if (uword_lsb(address_lsb(c))) |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 671 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 672 | Addr c_next = first_address_with_higher_uword_msb(c); |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 673 | if (c_next > b_next) |
| 674 | c_next = b_next; |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 675 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 676 | tl_assert(a1 <= b && b <= c && c < c_next && c_next <= b_next |
| 677 | && b_next <= a2); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 678 | #endif |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 679 | bm0_clear_range(p2->bm1.bm0_r, address_lsb(c), SCALED_SIZE(c_next - c)); |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 680 | c = c_next; |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 681 | } |
| 682 | /* If some UWords have to be cleared entirely, do this now. */ |
| 683 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 684 | tl_assert(a1 <= b && b <= c && c <= b_next && b_next <= a2); |
| 685 | #endif |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 686 | if (uword_lsb(address_lsb(c)) == 0) |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 687 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 688 | Addr c_next = first_address_with_same_uword_lsb(b_next); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 689 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 690 | tl_assert(uword_lsb(address_lsb(c)) == 0); |
| 691 | tl_assert(uword_lsb(address_lsb(c_next)) == 0); |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 692 | tl_assert(a1 <= b && b <= c && c <= c_next && c_next <= b_next |
| 693 | && b_next <= a2); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 694 | #endif |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 695 | if (c_next > c) |
| 696 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 697 | UWord idx = uword_msb(address_lsb(c)); |
| 698 | VG_(memset)(&p2->bm1.bm0_r[idx], 0, SCALED_SIZE((c_next - c) / 8)); |
bart | 25a439a | 2009-04-24 14:49:50 +0000 | [diff] [blame] | 699 | c = c_next; |
| 700 | } |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 701 | } |
| 702 | /* If the last address in the bitmap that must be cleared does not */ |
| 703 | /* fall on an UWord boundary, clear the last addresses. */ |
| 704 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 705 | tl_assert(a1 <= b && b <= c && c <= b_next && b_next <= a2); |
| 706 | #endif |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 707 | bm0_clear_range(p2->bm1.bm0_r, address_lsb(c), SCALED_SIZE(b_next - c)); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 708 | } |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 709 | } |
| 710 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 711 | /** |
| 712 | * Clear all references to stores in bitmap bm starting at address a1 and |
| 713 | * up to but not including address a2. |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 714 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 715 | void DRD_(bm_clear_store)(struct bitmap* const bm, |
| 716 | const Addr a1, const Addr a2) |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 717 | { |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 718 | Addr b, b_next; |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 719 | |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 720 | tl_assert(bm); |
| 721 | tl_assert(a1); |
| 722 | tl_assert(a1 <= a2); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 723 | tl_assert(a1 == first_address_with_same_lsb(a1)); |
| 724 | tl_assert(a2 == first_address_with_same_lsb(a2)); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 725 | |
| 726 | for (b = a1; b < a2; b = b_next) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 727 | { |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 728 | struct bitmap2* p2; |
| 729 | Addr c; |
| 730 | |
| 731 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 732 | tl_assert(a1 <= b && b < a2); |
| 733 | #endif |
| 734 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 735 | p2 = bm2_lookup_exclusive(bm, address_msb(b)); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 736 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 737 | b_next = first_address_with_higher_msb(b); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 738 | if (b_next > a2) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 739 | { |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 740 | b_next = a2; |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 741 | } |
| 742 | |
bart | e2c7e67 | 2009-04-23 19:23:09 +0000 | [diff] [blame] | 743 | if (p2 == 0) |
| 744 | continue; |
| 745 | |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 746 | c = b; |
| 747 | /* If the first address in the bitmap that must be cleared does not */ |
| 748 | /* start on an UWord boundary, start clearing the first addresses. */ |
| 749 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 750 | tl_assert(a1 <= b && b <= c && c < b_next && b_next <= a2); |
| 751 | #endif |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 752 | if (uword_lsb(address_lsb(c))) |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 753 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 754 | Addr c_next = first_address_with_higher_uword_msb(c); |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 755 | if (c_next > b_next) |
| 756 | c_next = b_next; |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 757 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 758 | tl_assert(a1 <= b && b <= c && c < c_next && c_next <= b_next |
| 759 | && b_next <= a2); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 760 | #endif |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 761 | bm0_clear_range(p2->bm1.bm0_w, address_lsb(c), SCALED_SIZE(c_next - c)); |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 762 | c = c_next; |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 763 | } |
| 764 | /* If some UWords have to be cleared entirely, do this now. */ |
| 765 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 766 | tl_assert(a1 <= b && b <= c && c <= b_next && b_next <= a2); |
| 767 | #endif |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 768 | if (uword_lsb(address_lsb(c)) == 0) |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 769 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 770 | Addr c_next = first_address_with_same_uword_lsb(b_next); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 771 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 772 | tl_assert(uword_lsb(address_lsb(c)) == 0); |
| 773 | tl_assert(uword_lsb(address_lsb(c_next)) == 0); |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 774 | tl_assert(a1 <= b && b <= c && c <= c_next && c_next <= b_next |
| 775 | && b_next <= a2); |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 776 | #endif |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 777 | if (c_next > c) |
| 778 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 779 | UWord idx = uword_msb(address_lsb(c)); |
| 780 | VG_(memset)(&p2->bm1.bm0_w[idx], 0, SCALED_SIZE((c_next - c) / 8)); |
bart | e6e86c5 | 2009-04-25 06:53:00 +0000 | [diff] [blame] | 781 | c = c_next; |
| 782 | } |
bart | 578eeb4 | 2009-04-23 15:42:27 +0000 | [diff] [blame] | 783 | } |
| 784 | /* If the last address in the bitmap that must be cleared does not */ |
| 785 | /* fall on an UWord boundary, clear the last addresses. */ |
| 786 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 787 | tl_assert(a1 <= b && b <= c && c <= b_next && b_next <= a2); |
| 788 | #endif |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 789 | bm0_clear_range(p2->bm1.bm0_w, address_lsb(c), SCALED_SIZE(b_next - c)); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 790 | } |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 791 | } |
| 792 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 793 | /** |
| 794 | * Clear bitmap bm starting at address a1 and up to but not including address |
| 795 | * a2. Return True if and only if any of the addresses was set before |
| 796 | * clearing. |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 797 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 798 | Bool DRD_(bm_test_and_clear)(struct bitmap* const bm, |
| 799 | const Addr a1, const Addr a2) |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 800 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 801 | Bool result; |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 802 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 803 | result = DRD_(bm_has_any_access)(bm, a1, a2) != 0; |
| 804 | DRD_(bm_clear)(bm, a1, a2); |
| 805 | return result; |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 806 | } |
| 807 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 808 | Bool DRD_(bm_has_conflict_with)(struct bitmap* const bm, |
| 809 | const Addr a1, const Addr a2, |
| 810 | const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 811 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 812 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 813 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 814 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 815 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 816 | for (b = a1; b < a2; b = b_next) |
| 817 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 818 | const struct bitmap2* bm2 = bm2_lookup(bm, address_msb(b)); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 819 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 820 | b_next = first_address_with_higher_msb(b); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 821 | if (b_next > a2) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 822 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 823 | b_next = a2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 824 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 825 | |
| 826 | if (bm2) |
| 827 | { |
| 828 | Addr b_start; |
| 829 | Addr b_end; |
| 830 | UWord b0; |
| 831 | const struct bitmap1* const p1 = &bm2->bm1; |
| 832 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 833 | if (make_address(bm2->addr, 0) < a1) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 834 | b_start = a1; |
| 835 | else |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 836 | if (make_address(bm2->addr, 0) < a2) |
| 837 | b_start = make_address(bm2->addr, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 838 | else |
| 839 | break; |
| 840 | tl_assert(a1 <= b_start && b_start <= a2); |
| 841 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 842 | if (make_address(bm2->addr + 1, 0) < a2) |
| 843 | b_end = make_address(bm2->addr + 1, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 844 | else |
| 845 | b_end = a2; |
| 846 | tl_assert(a1 <= b_end && b_end <= a2); |
| 847 | tl_assert(b_start < b_end); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 848 | tl_assert(address_lsb(b_start) <= address_lsb(b_end - 1)); |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 849 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 850 | for (b0 = address_lsb(b_start); b0 <= address_lsb(b_end - 1); b0++) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 851 | { |
| 852 | if (access_type == eLoad) |
| 853 | { |
| 854 | if (bm0_is_set(p1->bm0_w, b0)) |
| 855 | { |
| 856 | return True; |
| 857 | } |
| 858 | } |
| 859 | else |
| 860 | { |
| 861 | tl_assert(access_type == eStore); |
| 862 | if (bm0_is_set(p1->bm0_r, b0) |
| 863 | | bm0_is_set(p1->bm0_w, b0)) |
| 864 | { |
| 865 | return True; |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 872 | } |
| 873 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 874 | Bool DRD_(bm_load_has_conflict_with)(struct bitmap* const bm, |
| 875 | const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 876 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 877 | return DRD_(bm_has_conflict_with)(bm, a1, a2, eLoad); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 878 | } |
| 879 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 880 | Bool DRD_(bm_load_1_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 881 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 882 | return bm_aligned_load_has_conflict_with(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 883 | } |
| 884 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 885 | Bool DRD_(bm_load_2_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 886 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 887 | if ((a1 & 1) == 0) |
| 888 | return bm_aligned_load_has_conflict_with(bm, a1, 2); |
| 889 | else |
| 890 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 2, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 891 | } |
| 892 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 893 | Bool DRD_(bm_load_4_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 894 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 895 | if ((a1 & 3) == 0) |
| 896 | return bm_aligned_load_has_conflict_with(bm, a1, 4); |
| 897 | else |
| 898 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 4, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 899 | } |
| 900 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 901 | Bool DRD_(bm_load_8_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 902 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 903 | if ((a1 & 7) == 0) |
| 904 | return bm_aligned_load_has_conflict_with(bm, a1, 8); |
| 905 | else |
| 906 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 8, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 907 | } |
| 908 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 909 | Bool DRD_(bm_store_1_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 910 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 911 | return bm_aligned_store_has_conflict_with(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 912 | } |
| 913 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 914 | Bool DRD_(bm_store_2_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 915 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 916 | if ((a1 & 1) == 0) |
| 917 | return bm_aligned_store_has_conflict_with(bm, a1, 2); |
| 918 | else |
| 919 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 2, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 920 | } |
| 921 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 922 | Bool DRD_(bm_store_4_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 923 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 924 | if ((a1 & 3) == 0) |
| 925 | return bm_aligned_store_has_conflict_with(bm, a1, 4); |
| 926 | else |
| 927 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 4, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 928 | } |
| 929 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 930 | Bool DRD_(bm_store_8_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 931 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 932 | if ((a1 & 7) == 0) |
| 933 | return bm_aligned_store_has_conflict_with(bm, a1, 8); |
| 934 | else |
| 935 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 8, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 936 | } |
| 937 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 938 | Bool DRD_(bm_store_has_conflict_with)(struct bitmap* const bm, |
| 939 | const Addr a1, const Addr a2) |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 940 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 941 | return DRD_(bm_has_conflict_with)(bm, a1, a2, eStore); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 942 | } |
| 943 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 944 | /** |
| 945 | * Return True if the two bitmaps *lhs and *rhs are identical, and false |
| 946 | * if not. |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 947 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 948 | Bool DRD_(bm_equal)(struct bitmap* const lhs, struct bitmap* const rhs) |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 949 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 950 | struct bitmap2* bm2l; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 951 | struct bitmap2* bm2r; |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 952 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 953 | /* It's not possible to have two independent iterators over the same OSet, */ |
| 954 | /* so complain if lhs == rhs. */ |
| 955 | tl_assert(lhs != rhs); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 956 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 957 | VG_(OSetGen_ResetIter)(lhs->oset); |
| 958 | VG_(OSetGen_ResetIter)(rhs->oset); |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 959 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 960 | for ( ; (bm2l = VG_(OSetGen_Next)(lhs->oset)) != 0; ) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 961 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 962 | while (bm2l |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 963 | && ! DRD_(bm_has_any_access)(lhs, |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 964 | make_address(bm2l->addr, 0), |
| 965 | make_address(bm2l->addr + 1, 0))) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 966 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 967 | bm2l = VG_(OSetGen_Next)(lhs->oset); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 968 | } |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 969 | if (bm2l == 0) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 970 | break; |
| 971 | tl_assert(bm2l); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 972 | |
bart | b634b5d | 2009-04-26 14:42:33 +0000 | [diff] [blame] | 973 | do |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 974 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 975 | bm2r = VG_(OSetGen_Next)(rhs->oset); |
| 976 | if (bm2r == 0) |
bart | b634b5d | 2009-04-26 14:42:33 +0000 | [diff] [blame] | 977 | return False; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 978 | } |
bart | b634b5d | 2009-04-26 14:42:33 +0000 | [diff] [blame] | 979 | while (! DRD_(bm_has_any_access)(rhs, |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 980 | make_address(bm2r->addr, 0), |
| 981 | make_address(bm2r->addr + 1, 0))); |
bart | b634b5d | 2009-04-26 14:42:33 +0000 | [diff] [blame] | 982 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 983 | tl_assert(bm2r); |
| 984 | tl_assert(DRD_(bm_has_any_access)(rhs, |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 985 | make_address(bm2r->addr, 0), |
| 986 | make_address(bm2r->addr + 1, 0))); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 987 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 988 | if (bm2l != bm2r |
| 989 | && (bm2l->addr != bm2r->addr |
| 990 | || VG_(memcmp)(&bm2l->bm1, &bm2r->bm1, sizeof(bm2l->bm1)) != 0)) |
| 991 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 992 | return False; |
| 993 | } |
| 994 | } |
bart | b634b5d | 2009-04-26 14:42:33 +0000 | [diff] [blame] | 995 | |
| 996 | do |
| 997 | { |
| 998 | bm2r = VG_(OSetGen_Next)(rhs->oset); |
| 999 | } while (bm2r && ! DRD_(bm_has_any_access)(rhs, |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1000 | make_address(bm2r->addr, 0), |
| 1001 | make_address(bm2r->addr + 1, 0))); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1002 | if (bm2r) |
| 1003 | { |
| 1004 | tl_assert(DRD_(bm_has_any_access)(rhs, |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1005 | make_address(bm2r->addr, 0), |
| 1006 | make_address(bm2r->addr + 1, 0))); |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 1007 | return False; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1008 | } |
| 1009 | return True; |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 1012 | void DRD_(bm_swap)(struct bitmap* const bm1, struct bitmap* const bm2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1013 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1014 | OSet* const tmp = bm1->oset; |
| 1015 | bm1->oset = bm2->oset; |
| 1016 | bm2->oset = tmp; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 1019 | /** Merge bitmaps *lhs and *rhs into *lhs. */ |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1020 | void DRD_(bm_merge2)(struct bitmap* const lhs, struct bitmap* const rhs) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1021 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1022 | struct bitmap2* bm2l; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1023 | struct bitmap2* bm2r; |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1024 | |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1025 | /* |
| 1026 | * It's not possible to have two independent iterators over the same OSet, |
| 1027 | * so complain if lhs == rhs. |
| 1028 | */ |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1029 | tl_assert(lhs != rhs); |
| 1030 | |
| 1031 | s_bitmap_merge_count++; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1032 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1033 | VG_(OSetGen_ResetIter)(rhs->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1034 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1035 | for ( ; (bm2r = VG_(OSetGen_Next)(rhs->oset)) != 0; ) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1036 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1037 | bm2l = VG_(OSetGen_Lookup)(lhs->oset, &bm2r->addr); |
| 1038 | if (bm2l) |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 1039 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1040 | tl_assert(bm2l != bm2r); |
| 1041 | bm2_merge(bm2l, bm2r); |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 1042 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1043 | else |
| 1044 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1045 | bm2_insert_copy(lhs, bm2r); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1046 | } |
| 1047 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1050 | /** Clear bitmap2::recalc. */ |
| 1051 | void DRD_(bm_unmark)(struct bitmap* bm) |
| 1052 | { |
| 1053 | struct bitmap2* bm2; |
| 1054 | |
| 1055 | for (VG_(OSetGen_ResetIter)(bm->oset); |
| 1056 | (bm2 = VG_(OSetGen_Next)(bm->oset)) != 0; |
| 1057 | ) |
| 1058 | { |
| 1059 | bm2->recalc = False; |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | /** |
| 1064 | * Report whether bitmap2::recalc has been set for the second level bitmap |
| 1065 | * corresponding to address a. |
| 1066 | */ |
| 1067 | Bool DRD_(bm_is_marked)(struct bitmap* bm, const Addr a) |
| 1068 | { |
| 1069 | const struct bitmap2* bm2; |
| 1070 | |
| 1071 | bm2 = bm2_lookup(bm, a); |
| 1072 | return bm2 && bm2->recalc; |
| 1073 | } |
| 1074 | |
| 1075 | /** |
| 1076 | * Set bitmap2::recalc in bml for each second level bitmap in bmr that contains |
| 1077 | * at least one access. |
| 1078 | * |
| 1079 | * @note Any new second-level bitmaps inserted in bml by this function are |
| 1080 | * uninitialized. |
| 1081 | */ |
| 1082 | void DRD_(bm_mark)(struct bitmap* bml, struct bitmap* bmr) |
| 1083 | { |
| 1084 | struct bitmap2* bm2l; |
| 1085 | struct bitmap2* bm2r; |
| 1086 | |
| 1087 | for (VG_(OSetGen_ResetIter)(bmr->oset); |
| 1088 | (bm2r = VG_(OSetGen_Next)(bmr->oset)) != 0; |
| 1089 | ) |
| 1090 | { |
bart | 43ab339 | 2011-07-03 11:42:03 +0000 | [diff] [blame] | 1091 | bm2l = bm2_lookup_or_insert(bml, bm2r->addr); |
| 1092 | bm2l->recalc = True; |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | /** Clear all second-level bitmaps for which bitmap2::recalc == True. */ |
| 1097 | void DRD_(bm_clear_marked)(struct bitmap* bm) |
| 1098 | { |
| 1099 | struct bitmap2* bm2; |
| 1100 | |
| 1101 | for (VG_(OSetGen_ResetIter)(bm->oset); |
| 1102 | (bm2 = VG_(OSetGen_Next)(bm->oset)) != 0; |
| 1103 | ) |
| 1104 | { |
| 1105 | if (bm2->recalc) |
| 1106 | bm2_clear(bm2); |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | /** Merge the second level bitmaps from *rhs into *lhs for which recalc == True. */ |
| 1111 | void DRD_(bm_merge2_marked)(struct bitmap* const lhs, struct bitmap* const rhs) |
| 1112 | { |
| 1113 | struct bitmap2* bm2l; |
| 1114 | struct bitmap2* bm2r; |
| 1115 | |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1116 | /* |
| 1117 | * It's not possible to have two independent iterators over the same OSet, |
| 1118 | * so complain if lhs == rhs. |
| 1119 | */ |
| 1120 | tl_assert(lhs != rhs); |
| 1121 | |
| 1122 | s_bitmap_merge_count++; |
| 1123 | |
| 1124 | VG_(OSetGen_ResetIter)(rhs->oset); |
| 1125 | |
| 1126 | for ( ; (bm2r = VG_(OSetGen_Next)(rhs->oset)) != 0; ) |
| 1127 | { |
| 1128 | bm2l = VG_(OSetGen_Lookup)(lhs->oset, &bm2r->addr); |
| 1129 | if (bm2l && bm2l->recalc) |
| 1130 | { |
| 1131 | tl_assert(bm2l != bm2r); |
| 1132 | bm2_merge(bm2l, bm2r); |
| 1133 | } |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | /** Remove all marked second-level bitmaps that do not contain any access. */ |
| 1138 | void DRD_(bm_remove_cleared_marked)(struct bitmap* bm) |
| 1139 | { |
| 1140 | struct bitmap2* bm2; |
| 1141 | |
| 1142 | VG_(OSetGen_ResetIter)(bm->oset); |
| 1143 | for ( ; (bm2 = VG_(OSetGen_Next)(bm->oset)) != 0; ) |
| 1144 | { |
| 1145 | const UWord a1 = bm2->addr; |
| 1146 | if (bm2->recalc |
| 1147 | && ! DRD_(bm_has_any_access(bm, make_address(a1, 0), |
| 1148 | make_address(a1 + 1, 0)))) |
| 1149 | { |
| 1150 | bm2_remove(bm, a1); |
| 1151 | VG_(OSetGen_ResetIterAt)(bm->oset, &a1); |
| 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1156 | /** |
| 1157 | * Report whether there are any RW / WR / WW patterns in lhs and rhs. |
| 1158 | * @param lhs First bitmap. |
| 1159 | * @param rhs Bitmap to be compared with lhs. |
| 1160 | * @return !=0 if there are data races, == 0 if there are none. |
| 1161 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 1162 | int DRD_(bm_has_races)(struct bitmap* const lhs, struct bitmap* const rhs) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1163 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1164 | VG_(OSetGen_ResetIter)(lhs->oset); |
| 1165 | VG_(OSetGen_ResetIter)(rhs->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1166 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1167 | for (;;) |
| 1168 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1169 | const struct bitmap2* bm2l; |
| 1170 | const struct bitmap2* bm2r; |
| 1171 | const struct bitmap1* bm1l; |
| 1172 | const struct bitmap1* bm1r; |
| 1173 | unsigned k; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1174 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1175 | bm2l = VG_(OSetGen_Next)(lhs->oset); |
| 1176 | bm2r = VG_(OSetGen_Next)(rhs->oset); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1177 | while (bm2l && bm2r && bm2l->addr != bm2r->addr) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1178 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1179 | if (bm2l->addr < bm2r->addr) |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1180 | bm2l = VG_(OSetGen_Next)(lhs->oset); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1181 | else |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1182 | bm2r = VG_(OSetGen_Next)(rhs->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1183 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1184 | if (bm2l == 0 || bm2r == 0) |
| 1185 | break; |
| 1186 | |
| 1187 | bm1l = &bm2l->bm1; |
| 1188 | bm1r = &bm2r->bm1; |
| 1189 | |
| 1190 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 1191 | { |
| 1192 | unsigned b; |
| 1193 | for (b = 0; b < BITS_PER_UWORD; b++) |
| 1194 | { |
| 1195 | UWord const access_mask |
| 1196 | = ((bm1l->bm0_r[k] & bm0_mask(b)) ? LHS_R : 0) |
| 1197 | | ((bm1l->bm0_w[k] & bm0_mask(b)) ? LHS_W : 0) |
| 1198 | | ((bm1r->bm0_r[k] & bm0_mask(b)) ? RHS_R : 0) |
| 1199 | | ((bm1r->bm0_w[k] & bm0_mask(b)) ? RHS_W : 0); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1200 | Addr const a = make_address(bm2l->addr, k * BITS_PER_UWORD | b); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1201 | if (HAS_RACE(access_mask) && ! DRD_(is_suppressed)(a, a + 1)) |
| 1202 | { |
| 1203 | return 1; |
| 1204 | } |
| 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 1211 | void DRD_(bm_print)(struct bitmap* const bm) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1212 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1213 | struct bitmap2* bm2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1214 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1215 | for (VG_(OSetGen_ResetIter)(bm->oset); |
| 1216 | (bm2 = VG_(OSetGen_Next)(bm->oset)) != 0; |
| 1217 | ) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1218 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1219 | bm2_print(bm2); |
| 1220 | } |
| 1221 | } |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 1222 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1223 | static void bm2_print(const struct bitmap2* const bm2) |
| 1224 | { |
| 1225 | const struct bitmap1* bm1; |
| 1226 | Addr a; |
| 1227 | |
| 1228 | tl_assert(bm2); |
| 1229 | |
| 1230 | bm1 = &bm2->bm1; |
| 1231 | for (a = make_address(bm2->addr, 0); |
| 1232 | a <= make_address(bm2->addr + 1, 0) - 1; |
| 1233 | a++) |
| 1234 | { |
| 1235 | const Bool r = bm0_is_set(bm1->bm0_r, address_lsb(a)) != 0; |
| 1236 | const Bool w = bm0_is_set(bm1->bm0_w, address_lsb(a)) != 0; |
| 1237 | if (r || w) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1238 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1239 | VG_(printf)("0x%08lx %c %c\n", |
| 1240 | a, |
| 1241 | w ? 'W' : ' ', |
| 1242 | r ? 'R' : ' '); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1243 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1244 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 1247 | ULong DRD_(bm_get_bitmap_creation_count)(void) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1248 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1249 | return s_bitmap_creation_count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 1252 | ULong DRD_(bm_get_bitmap2_creation_count)(void) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1253 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1254 | return s_bitmap2_creation_count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1257 | ULong DRD_(bm_get_bitmap2_merge_count)(void) |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 1258 | { |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1259 | return s_bitmap2_merge_count; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1262 | /** Compute *bm2l |= *bm2r. */ |
| 1263 | static |
| 1264 | void bm2_merge(struct bitmap2* const bm2l, const struct bitmap2* const bm2r) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1265 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1266 | unsigned k; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1267 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1268 | tl_assert(bm2l); |
| 1269 | tl_assert(bm2r); |
| 1270 | tl_assert(bm2l->addr == bm2r->addr); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 1271 | |
| 1272 | s_bitmap2_merge_count++; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1273 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1274 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 1275 | { |
| 1276 | bm2l->bm1.bm0_r[k] |= bm2r->bm1.bm0_r[k]; |
| 1277 | } |
| 1278 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 1279 | { |
| 1280 | bm2l->bm1.bm0_w[k] |= bm2r->bm1.bm0_w[k]; |
| 1281 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1282 | } |