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