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