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