/* See if wv is contained within wsu. If so, deallocate wv and return the index of the already-present copy. If not, add wv to both the vec2ix and ix2vec mappings and return its index. */ static WordSet add_or_dealloc_WordVec( WordSetU* wsu, WordVec* wv_new ) { Bool have; WordVec* wv_old; Word/*Set*/ ix_old = -1; /* Really WordSet, but need something that can safely be casted to a Word* in the lookupFM. Making it WordSet (which is 32 bits) causes failures on a 64-bit platform. */ tl_assert(wv_new->owner == wsu); have = HG_(lookupFM)( wsu->vec2ix, (Word*)&wv_old, (Word*)&ix_old, (Word)wv_new ); if (have) { tl_assert(wv_old != wv_new); tl_assert(wv_old); tl_assert(wv_old->owner == wsu); tl_assert(ix_old < wsu->ix2vec_used); tl_assert(wsu->ix2vec[ix_old] == wv_old); delete_WV( wv_new ); return (WordSet)ix_old; } else { ensure_ix2vec_space( wsu ); tl_assert(wsu->ix2vec); tl_assert(wsu->ix2vec_used < wsu->ix2vec_size); wsu->ix2vec[wsu->ix2vec_used] = wv_new; HG_(addToFM)( wsu->vec2ix, (Word)wv_new, (Word)wsu->ix2vec_used ); if (0) VG_(printf)("aodW %d\n", (Int)wsu->ix2vec_used ); wsu->ix2vec_used++; tl_assert(wsu->ix2vec_used <= wsu->ix2vec_size); return (WordSet)(wsu->ix2vec_used - 1); } }
void HG_(dieWS) ( WordSetU* wsu, WordSet ws ) { WordVec* wv = do_ix2vec_with_dead( wsu, ws ); WordVec* wv_in_vec2ix; UWord wv_ix = -1; if (HG_DEBUG) VG_(printf)("dieWS %s %d %p\n", wsu->cc, (Int)ws, wv); if (ws == 0) return; if (!wv) return; wsu->n_die++; wsu->ix2vec[ws] = (WordVec*) wsu->ix2vec_free; wsu->ix2vec_free = &wsu->ix2vec[ws]; VG_(delFromFM) ( wsu->vec2ix, (Word*)&wv_in_vec2ix, (Word*)&wv_ix, (Word)wv ); if (HG_DEBUG) VG_(printf)("dieWS wv_ix %d\n", (Int)wv_ix); tl_assert (wv_ix); tl_assert (wv_ix == ws); delete_WV( wv ); wsu->cache_addTo.inUse = 0; wsu->cache_delFrom.inUse = 0; wsu->cache_intersect.inUse = 0; wsu->cache_minus.inUse = 0; }
static WordSet add_or_dealloc_WordVec( WordSetU* wsu, WordVec* wv_new ) { Bool have; WordVec* wv_old; UWord ix_old = -1; tl_assert(wv_new->owner == wsu); have = VG_(lookupFM)( wsu->vec2ix, (Word*)&wv_old, (Word*)&ix_old, (Word)wv_new ); if (have) { tl_assert(wv_old != wv_new); tl_assert(wv_old); tl_assert(wv_old->owner == wsu); tl_assert(ix_old < wsu->ix2vec_used); tl_assert(wsu->ix2vec[ix_old] == wv_old); delete_WV( wv_new ); return (WordSet)ix_old; } else if (wsu->ix2vec_free) { WordSet ws; tl_assert(is_dead(wsu,(WordVec*)wsu->ix2vec_free)); ws = wsu->ix2vec_free - &(wsu->ix2vec[0]); tl_assert(wsu->ix2vec[ws] == NULL || is_dead(wsu,wsu->ix2vec[ws])); wsu->ix2vec_free = (WordVec **) wsu->ix2vec[ws]; wsu->ix2vec[ws] = wv_new; VG_(addToFM)( wsu->vec2ix, (Word)wv_new, ws ); if (HG_DEBUG) VG_(printf)("aodW %s re-use free %d %p\n", wsu->cc, (Int)ws, wv_new ); return ws; } else { ensure_ix2vec_space( wsu ); tl_assert(wsu->ix2vec); tl_assert(wsu->ix2vec_used < wsu->ix2vec_size); wsu->ix2vec[wsu->ix2vec_used] = wv_new; VG_(addToFM)( wsu->vec2ix, (Word)wv_new, (Word)wsu->ix2vec_used ); if (HG_DEBUG) VG_(printf)("aodW %s %d %p\n", wsu->cc, (Int)wsu->ix2vec_used, wv_new ); wsu->ix2vec_used++; tl_assert(wsu->ix2vec_used <= wsu->ix2vec_size); return (WordSet)(wsu->ix2vec_used - 1); } }
static void delete_WV_for_FM ( Word wv ) { delete_WV( (WordVec*)wv ); }