]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Move the WordFM (AVL trees of UWord-pairs) implementation from
authorJulian Seward <jseward@acm.org>
Tue, 19 Aug 2008 08:38:52 +0000 (08:38 +0000)
committerJulian Seward <jseward@acm.org>
Tue, 19 Aug 2008 08:38:52 +0000 (08:38 +0000)
helgrind/ into the core.  It's just too darn useful to not be in the
core.  There is some overlap in functionality between OSet and WordFM,
but OSet is more space efficient in some circumstances, whereas WordFM
is easier to use and a bit more flexible in some cases.

Also in this new module (m_wordfm) is a type WordBag, build on top of
WordFM.  This provides Multiset of UWords functionality.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8524

coregrind/Makefile.am
coregrind/m_wordfm.c [moved from helgrind/hg_wordfm.c with 80% similarity]
coregrind/pub_core_wordfm.h [new file with mode: 0644]
helgrind/Makefile.am
helgrind/hg_main.c
helgrind/hg_wordset.c
include/Makefile.am
include/pub_tool_wordfm.h [moved from helgrind/hg_wordfm.h with 80% similarity]

index 90d92e1391ccbe5df378a5ffd6529c53fd9d5ea0..eca4af471e9c5d2fc478af29be798985f1fa6dd1 100644 (file)
@@ -136,6 +136,7 @@ noinst_HEADERS = \
        pub_core_ume.h          \
        pub_core_vki.h          \
        pub_core_vkiscnums.h    \
+       pub_core_wordfm.h       \
        pub_core_xarray.h       \
        m_coredump/priv_elf.h   \
        m_debuginfo/priv_misc.h \
@@ -199,6 +200,7 @@ COREGRIND_SOURCES_COMMON = \
        m_ume.c \
        m_vki.c \
        m_vkiscnums.c \
+       m_wordfm.c \
        m_xarray.c \
        m_aspacemgr/aspacemgr-common.c \
        m_debuginfo/misc.c \
similarity index 80%
rename from helgrind/hg_wordfm.c
rename to coregrind/m_wordfm.c
index 6126ff0fbbca93148a6eeb82aece275e5ce07eaf..d00fac76c280c360237b85d5f4f01c50be52fd58 100644 (file)
@@ -2,12 +2,12 @@
 /*--------------------------------------------------------------------*/
 /*--- An AVL tree based finite map for word keys and word values.  ---*/
 /*--- Inspired by Haskell's "FiniteMap" library.                   ---*/
-/*---                                                  hg_wordfm.c ---*/
+/*---                                                   m_wordfm.c ---*/
 /*--------------------------------------------------------------------*/
 
 /*
-   This file is part of Helgrind, a Valgrind tool for detecting errors
-   in threaded programs.
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
 
    Copyright (C) 2007-2008 Julian Seward
       jseward@acm.org
    The GNU General Public License is contained in the file COPYING.
 */
 
-#include "pub_tool_basics.h"
-#include "pub_tool_libcassert.h"
-#include "pub_tool_libcbase.h"
+#include "pub_core_basics.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_libcbase.h"
+#include "pub_core_wordfm.h"   /* self */
 
 
-#ifdef HG_WORDFM_STANDALONE  // standalone compilation
-// Standalone mode (for testing). 
-// On x86_64 compile like this: 
-//   gcc -m64 hg_wordfm.c -I../include -I../VEX/pub
-//       -DVGA_amd64=1 -DHG_WORDFM_STANDALONE -g -O -Wall
-# include <assert.h>
-# include <string.h>
-# include <stdio.h>
-# include <stdlib.h>
-
-# undef  tl_assert
-# define tl_assert assert
-# define vgPlain_memset memset
-
-#endif /* def HG_WORDFM_STANDALONE */
-
-
-#define HG_(str) VGAPPEND(vgHelgrind_,str)
-#include "hg_wordfm.h"
-
 //------------------------------------------------------------------//
 //---                           WordFM                           ---//
 //---                       Implementation                       ---//
@@ -547,7 +528,7 @@ static void initFM ( WordFM* fm,
    sections of the map, or the whole thing.  If kCmp is NULL then the
    ordering used is unsigned word ordering (UWord) on the key
    values. */
-WordFM* HG_(newFM) ( void* (*alloc_nofail)( SizeT ),
+WordFM* VG_(newFM) ( void* (*alloc_nofail)( SizeT ),
                      void  (*dealloc)(void*),
                      Word  (*kCmp)(UWord,UWord) )
 {
@@ -578,7 +559,7 @@ static void avl_free ( AvlNode* nd,
 
 /* Free up the FM.  If kFin is non-NULL, it is applied to keys
    before the FM is deleted; ditto with vFin for vals. */
-void HG_(deleteFM) ( WordFM* fm, void(*kFin)(UWord), void(*vFin)(UWord) )
+void VG_(deleteFM) ( WordFM* fm, void(*kFin)(UWord), void(*vFin)(UWord) )
 {
    void(*dealloc)(void*) = fm->dealloc;
    avl_free( fm->root, kFin, vFin, dealloc );
@@ -587,7 +568,7 @@ void HG_(deleteFM) ( WordFM* fm, void(*kFin)(UWord), void(*vFin)(UWord) )
 }
 
 /* Add (k,v) to fm. */
-void HG_(addToFM) ( WordFM* fm, UWord k, UWord v )
+void VG_(addToFM) ( WordFM* fm, UWord k, UWord v )
 {
    MaybeWord oldV;
    AvlNode* node;
@@ -604,7 +585,7 @@ void HG_(addToFM) ( WordFM* fm, UWord k, UWord v )
 }
 
 // Delete key from fm, returning associated key and val if found
-Bool HG_(delFromFM) ( WordFM* fm,
+Bool VG_(delFromFM) ( WordFM* fm,
                       /*OUT*/UWord* oldK, /*OUT*/UWord* oldV, UWord key )
 {
    AvlNode* node = avl_find_node( fm->root, key, fm->kCmp );
@@ -622,7 +603,7 @@ Bool HG_(delFromFM) ( WordFM* fm,
 }
 
 // Look up in fm, assigning found key & val at spec'd addresses
-Bool HG_(lookupFM) ( WordFM* fm, 
+Bool VG_(lookupFM) ( WordFM* fm, 
                      /*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key )
 {
    AvlNode* node = avl_find_node( fm->root, key, fm->kCmp );
@@ -637,14 +618,14 @@ Bool HG_(lookupFM) ( WordFM* fm,
    }
 }
 
-UWord HG_(sizeFM) ( WordFM* fm )
+UWord VG_(sizeFM) ( WordFM* fm )
 {
    // Hmm, this is a bad way to do this
    return fm->root ? size_avl_nonNull( fm->root ) : 0;
 }
 
 // set up FM for iteration
-void HG_(initIterFM) ( WordFM* fm )
+void VG_(initIterFM) ( WordFM* fm )
 {
    tl_assert(fm);
    stackClear(fm);
@@ -653,10 +634,10 @@ void HG_(initIterFM) ( WordFM* fm )
 }
 
 // set up FM for iteration so that the first key subsequently produced
-// by HG_(nextIterFM) is the smallest key in the map >= start_at.
+// by VG_(nextIterFM) is the smallest key in the map >= start_at.
 // Naturally ">=" is defined by the comparison function supplied to
-// HG_(newFM), as documented above.
-void HG_(initIterAtFM) ( WordFM* fm, UWord start_at )
+// VG_(newFM), as documented above.
+void VG_(initIterAtFM) ( WordFM* fm, UWord start_at )
 {
    Int     i;
    AvlNode *n, *t;
@@ -706,7 +687,7 @@ void HG_(initIterAtFM) ( WordFM* fm, UWord start_at )
 
 // get next key/val pair.  Will tl_assert if fm has been modified
 // or looked up in since initIter{,At}FM was called.
-Bool HG_(nextIterFM) ( WordFM* fm, /*OUT*/UWord* pKey, /*OUT*/UWord* pVal )
+Bool VG_(nextIterFM) ( WordFM* fm, /*OUT*/UWord* pKey, /*OUT*/UWord* pVal )
 {
    Int i = 0;
    AvlNode* n = NULL;
@@ -743,11 +724,11 @@ Bool HG_(nextIterFM) ( WordFM* fm, /*OUT*/UWord* pKey, /*OUT*/UWord* pVal )
 }
 
 // clear the I'm iterating flag
-void HG_(doneIterFM) ( WordFM* fm )
+void VG_(doneIterFM) ( WordFM* fm )
 {
 }
 
-WordFM* HG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) )
+WordFM* VG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) )
 {
    WordFM* nyu; 
 
@@ -787,38 +768,38 @@ struct _WordBag {
    WordFM* fm; 
 };
 
-WordBag* HG_(newBag) ( void* (*alloc_nofail)( SizeT ),
+WordBag* VG_(newBag) ( void* (*alloc_nofail)( SizeT ),
                        void  (*dealloc)(void*) )
 {
    WordBag* bag = alloc_nofail(sizeof(WordBag));
-   bag->fm = HG_(newFM)( alloc_nofail, dealloc, NULL );
+   bag->fm = VG_(newFM)( alloc_nofail, dealloc, NULL );
    return bag;
 }
 
-void HG_(deleteBag) ( WordBag* bag )
+void VG_(deleteBag) ( WordBag* bag )
 {
    void (*dealloc)(void*) = bag->fm->dealloc;
-   HG_(deleteFM)( bag->fm, NULL, NULL );
+   VG_(deleteFM)( bag->fm, NULL, NULL );
    VG_(memset)(bag, 0, sizeof(WordBag));
    dealloc(bag);
 }
 
-void HG_(addToBag)( WordBag* bag, UWord w )
+void VG_(addToBag)( WordBag* bag, UWord w )
 {
    UWord key, count;
-   if (HG_(lookupFM)(bag->fm, &key, &count, w)) {
+   if (VG_(lookupFM)(bag->fm, &key, &count, w)) {
       tl_assert(key == w);
       tl_assert(count >= 1);
-      HG_(addToFM)(bag->fm, w, count+1);
+      VG_(addToFM)(bag->fm, w, count+1);
    } else {
-      HG_(addToFM)(bag->fm, w, 1);
+      VG_(addToFM)(bag->fm, w, 1);
    }
 }
 
-UWord HG_(elemBag) ( WordBag* bag, UWord w )
+UWord VG_(elemBag) ( WordBag* bag, UWord w )
 {
    UWord key, count;
-   if (HG_(lookupFM)( bag->fm, &key, &count, w)) {
+   if (VG_(lookupFM)( bag->fm, &key, &count, w)) {
       tl_assert(key == w);
       tl_assert(count >= 1);
       return count;
@@ -827,9 +808,9 @@ UWord HG_(elemBag) ( WordBag* bag, UWord w )
    }
 }
 
-UWord HG_(sizeUniqueBag) ( WordBag* bag )
+UWord VG_(sizeUniqueBag) ( WordBag* bag )
 {
-   return HG_(sizeFM)( bag->fm );
+   return VG_(sizeFM)( bag->fm );
 }
 
 static UWord sizeTotalBag_wrk ( AvlNode* nd )
@@ -843,7 +824,7 @@ static UWord sizeTotalBag_wrk ( AvlNode* nd )
       w += sizeTotalBag_wrk(nd->child[1]);
    return w;
 }
-UWord HG_(sizeTotalBag)( WordBag* bag )
+UWord VG_(sizeTotalBag)( WordBag* bag )
 {
    if (bag->fm->root)
       return sizeTotalBag_wrk(bag->fm->root);
@@ -851,17 +832,17 @@ UWord HG_(sizeTotalBag)( WordBag* bag )
       return 0;
 }
 
-Bool HG_(delFromBag)( WordBag* bag, UWord w )
+Bool VG_(delFromBag)( WordBag* bag, UWord w )
 {
    UWord key, count;
-   if (HG_(lookupFM)(bag->fm, &key, &count, w)) {
+   if (VG_(lookupFM)(bag->fm, &key, &count, w)) {
       tl_assert(key == w);
       tl_assert(count >= 1);
       if (count > 1) {
-         HG_(addToFM)(bag->fm, w, count-1);
+         VG_(addToFM)(bag->fm, w, count-1);
       } else {
          tl_assert(count == 1);
-         HG_(delFromFM)( bag->fm, NULL, NULL, w );
+         VG_(delFromFM)( bag->fm, NULL, NULL, w );
       }
       return True;
    } else {
@@ -869,15 +850,15 @@ Bool HG_(delFromBag)( WordBag* bag, UWord w )
    }
 }
 
-Bool HG_(isEmptyBag)( WordBag* bag )
+Bool VG_(isEmptyBag)( WordBag* bag )
 {
-   return HG_(sizeFM)(bag->fm) == 0;
+   return VG_(sizeFM)(bag->fm) == 0;
 }
 
-Bool HG_(isSingletonTotalBag)( WordBag* bag )
+Bool VG_(isSingletonTotalBag)( WordBag* bag )
 {
    AvlNode* nd;
-   if (HG_(sizeFM)(bag->fm) != 1)
+   if (VG_(sizeFM)(bag->fm) != 1)
       return False;
    nd = bag->fm->root;
    tl_assert(nd);
@@ -886,7 +867,7 @@ Bool HG_(isSingletonTotalBag)( WordBag* bag )
    return nd->val == 1;
 }
 
-UWord HG_(anyElementOfBag)( WordBag* bag )
+UWord VG_(anyElementOfBag)( WordBag* bag )
 {
    /* Return an arbitrarily chosen element in the bag.  We might as
       well return the one at the root of the underlying AVL tree. */
@@ -896,19 +877,19 @@ UWord HG_(anyElementOfBag)( WordBag* bag )
    return nd->key;
 }
 
-void HG_(initIterBag)( WordBag* bag )
+void VG_(initIterBag)( WordBag* bag )
 {
-   HG_(initIterFM)(bag->fm);
+   VG_(initIterFM)(bag->fm);
 }
 
-Bool HG_(nextIterBag)( WordBag* bag, /*OUT*/UWord* pVal, /*OUT*/UWord* pCount )
+Bool VG_(nextIterBag)( WordBag* bag, /*OUT*/UWord* pVal, /*OUT*/UWord* pCount )
 {
-   return HG_(nextIterFM)( bag->fm, pVal, pCount );
+   return VG_(nextIterFM)( bag->fm, pVal, pCount );
 }
 
-void HG_(doneIterBag)( WordBag* bag )
+void VG_(doneIterBag)( WordBag* bag )
 {
-   HG_(doneIterFM)( bag->fm );
+   VG_(doneIterFM)( bag->fm );
 }
 
 //------------------------------------------------------------------//
@@ -916,119 +897,6 @@ void HG_(doneIterBag)( WordBag* bag )
 //---                       Implementation                       ---//
 //------------------------------------------------------------------//
 
-
-#ifdef HG_WORDFM_STANDALONE
-
-//------------------------------------------------------------------//
-//---                      Simple test driver.                   ---//
-//------------------------------------------------------------------//
-
-// We create a map with N values {1, 3, 5, ..., (N*2-1)}
-// and do some trivial stuff with it. 
-
-
-// Return the number of elements in range [beg, end). 
-// Just lookup for each element in range and count. 
-int search_all_elements_in_range_1(WordFM *map, long beg, long end)
-{
-   long n_found = 0;
-   long i;
-   for (i = beg; i < end; i++) {
-      UWord key, val;
-      if (HG_(lookupFM)(map, &key, &val, (Word)i)) {
-         n_found++;
-         assert(key == -val);
-         assert(key == (UWord)i);
-      }
-   }
-   return n_found;
-}
-
-// Return the number of elements in range [beg, end). 
-// Start with the largest element 'e' such that 'e <= beg' 
-// and iterate until 'e < end'. 
-int search_all_elements_in_range_2(WordFM *map, long beg, long end)
-{
-   int n_found = 0;
-   UWord key, val;
-   HG_(initIterAtFM)(map, beg);
-   while (HG_(nextIterFM)(map, &key, &val) && (long)key < end) {
-      assert(key == -val);
-      n_found++;
-   }
-   HG_(doneIterFM)(map);
-   return n_found;
-}
-
-int main(void)
-{
-   long i, n = 10;
-   UWord key, val;
-   long beg, end;
-
-   printf("Create the map, n=%ld\n", n);
-   WordFM *map = HG_(newFM)(malloc, free, NULL/*unboxed Word cmp*/);
-
-   printf("Add keys: ");
-   for(i = 0; i < n; i++) {
-      long val = i * 2 + 1; // 1, 3, 5, ... (n*2-1)
-      printf("%ld ", val);
-      HG_(addToFM)(map, val, -val);
-   }
-   assert(HG_(sizeFM)(map) == (UWord)n);
-   printf("\n");
-   printf("Iterate elements, size=%d\n", (int)HG_(sizeFM)(map));
-   HG_(initIterFM)(map);
-
-   while (HG_(nextIterFM(map, &key, &val))) {
-   //   int j;
-   //   printf("Stack k=%d\n", (int)key);
-   //   for(j = map->stackTop-1; j >= 0; j--) {
-   //      printf("\t[%d]: k=%d s=%d\n", j,
-   //             (int)map->nodeStack[j]->key, (int)map->numStack[j]);
-   //   }
-      assert(key == -val);
-   }
-   HG_(doneIterFM)(map);
-
-   printf("Test initIterAtFM\n");
-   for(beg = 0; beg <= n*2; beg++) {
-      HG_(initIterAtFM)(map, (Word)beg);
-      int prev = -1; 
-      printf("StartWith: %ld: ", beg);
-      int n_iter = 0;
-
-      while(HG_(nextIterFM(map, &key, &val))) {
-         printf("%d ", (int)key);
-         assert(key == -val);
-         if(prev > 0) assert(prev + 2 == (int)key);
-         prev = (int)key;
-         n_iter++;
-      }
-      HG_(doneIterFM)(map);
-
-      printf("\ntotal: %d\n", n_iter);
-      if      (beg < 1   ) assert(n_iter == n);
-      else if (beg >= n*2) assert(n_iter == 0);
-      else                 assert(n_iter == (n - beg/2));
-   }
-
-   printf("Compare search_all_elements_in_range_[12]\n");
-   for (beg = 0; beg <= n*2; beg++) {
-      for (end = 0; end <= n*2; end++) {
-         assert(   search_all_elements_in_range_1(map, beg, end) 
-                == search_all_elements_in_range_2(map, beg, end));
-      }
-   }
-
-   printf("Delete the map\n");
-   HG_(deleteFM)(map, NULL, NULL);
-   printf("Ok!\n");
-   return 0;
-}
-
-#endif
-
 /*--------------------------------------------------------------------*/
-/*--- end                                              hg_wordfm.c ---*/
+/*--- end                                               m_wordfm.c ---*/
 /*--------------------------------------------------------------------*/
diff --git a/coregrind/pub_core_wordfm.h b/coregrind/pub_core_wordfm.h
new file mode 100644 (file)
index 0000000..925f0ca
--- /dev/null
@@ -0,0 +1,64 @@
+
+/*--------------------------------------------------------------------*/
+/*--- An AVL tree based finite map for word keys and word values.  ---*/
+/*--- Inspired by Haskell's "FiniteMap" library.                   ---*/
+/*---                                            pub_core_wordfm.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2007-2008 Julian Seward
+      jseward@acm.org
+
+   This code is based on previous work by Nicholas Nethercote
+   (coregrind/m_oset.c) which is
+
+   Copyright (C) 2005-2008 Nicholas Nethercote
+       njn@valgrind.org
+
+   which in turn was derived partially from:
+
+      AVL C library
+      Copyright (C) 2000,2002  Daniel Nagy
+
+      This program is free software; you can redistribute it and/or
+      modify it under the terms of the GNU General Public License as
+      published by the Free Software Foundation; either version 2 of
+      the License, or (at your option) any later version.
+      [...]
+
+      (taken from libavl-0.4/debian/copyright)
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_WORDFM_H
+#define __PUB_CORE_WORDFM_H
+
+/* No core-only exports; everything in this module is visible to both
+   the core and tools. */
+
+#include "pub_tool_wordfm.h"
+
+#endif   /* ! __PUB_CORE_WORDFM_H */
+
+/*--------------------------------------------------------------------*/
+/*--- end                                        pub_core_wordfm.h ---*/
+/*--------------------------------------------------------------------*/
index 0da581f5e6a95d8a7e0847cad53418b4bbb35114..1776adc3d49cdeab2a28de879e2c2a27f11438fa 100644 (file)
@@ -70,7 +70,7 @@ vgpreload_helgrind_ppc64_aix5_so_LDFLAGS      = \
        $(PRELOAD_LDFLAGS_PPC64_AIX5) \
        $(LIBREPLACEMALLOC_LDFLAGS_PPC64_AIX5)
 
-HELGRIND_SOURCES_COMMON = hg_wordfm.c hg_wordset.c hg_main.c
+HELGRIND_SOURCES_COMMON = hg_wordset.c hg_main.c
 
 helgrind_x86_linux_SOURCES      = $(HELGRIND_SOURCES_COMMON)
 helgrind_x86_linux_CPPFLAGS     = $(AM_CPPFLAGS_X86_LINUX)
@@ -118,4 +118,4 @@ hgincludedir = $(includedir)/valgrind
 
 hginclude_HEADERS = helgrind.h
 
-noinst_HEADERS = hg_wordfm.h hg_wordset.h
+noinst_HEADERS = hg_wordset.h
index 4b9be47a35ed6364676da0b0d82dbe34aeb92535..54d76cdbbeca8b4f47bd10efa52a641ca2620bf5 100644 (file)
 #include "pub_tool_xarray.h"
 #include "pub_tool_stacktrace.h"
 #include "pub_tool_debuginfo.h"  /* VG_(get_data_description) */
+#include "pub_tool_wordfm.h"
 
 #include "helgrind.h"
 
 #define HG_(str) VGAPPEND(vgHelgrind_,str)
-#include "hg_wordfm.h"
 #include "hg_wordset.h"
 
 /*----------------------------------------------------------------*/
@@ -630,12 +630,12 @@ static Bool is_sane_Bag_of_Threads ( WordBag* bag )
 {
    Thread* thr;
    Word    count;
-   HG_(initIterBag)( bag );
-   while (HG_(nextIterBag)( bag, (Word*)&thr, &count )) {
+   VG_(initIterBag)( bag );
+   while (VG_(nextIterBag)( bag, (Word*)&thr, &count )) {
       if (count < 1) return False;
       if (!is_sane_Thread(thr)) return False;
    }
-   HG_(doneIterBag)( bag );
+   VG_(doneIterBag)( bag );
    return True;
 }
 static Bool is_sane_Lock_BASE ( Lock* lock )
@@ -657,7 +657,7 @@ static Bool is_sane_Lock_BASE ( Lock* lock )
 
    /* If heldBy is non-NULL, we require it to contain at least one
       thread. */
-   if (HG_(isEmptyBag)(lock->heldBy))
+   if (VG_(isEmptyBag)(lock->heldBy))
       return False;
 
    /* Lock is either r- or w-held. */
@@ -666,7 +666,7 @@ static Bool is_sane_Lock_BASE ( Lock* lock )
    if (lock->heldW) {
       /* Held in write-mode */
       if ((lock->kind == LK_nonRec || lock->kind == LK_rdwr)
-          && !HG_(isSingletonTotalBag)(lock->heldBy))
+          && !VG_(isSingletonTotalBag)(lock->heldBy))
          return False;
    } else {
       /* Held in read-mode */
@@ -694,7 +694,7 @@ static void del_LockN ( Lock* lk )
 {
    tl_assert(is_sane_LockN(lk));
    if (lk->heldBy)
-      HG_(deleteBag)( lk->heldBy );
+      VG_(deleteBag)( lk->heldBy );
    VG_(memset)(lk, 0xAA, sizeof(*lk));
    hg_free(lk);
 }
@@ -729,8 +729,8 @@ static void lockN_acquire_writer ( Lock* lk, Thread* thr )
          tl_assert(lk->heldBy == NULL); /* can't w-lock recursively */
          tl_assert(!lk->heldW);
          lk->heldW  = True;
-         lk->heldBy = HG_(newBag)( hg_zalloc, hg_free );
-         HG_(addToBag)( lk->heldBy, (Word)thr );
+         lk->heldBy = VG_(newBag)( hg_zalloc, hg_free );
+         VG_(addToBag)( lk->heldBy, (Word)thr );
          break;
       case LK_mbRec:
          if (lk->heldBy == NULL)
@@ -738,11 +738,11 @@ static void lockN_acquire_writer ( Lock* lk, Thread* thr )
          /* 2nd and subsequent locking of a lock by its owner */
          tl_assert(lk->heldW);
          /* assert: lk is only held by one thread .. */
-         tl_assert(HG_(sizeUniqueBag(lk->heldBy)) == 1);
+         tl_assert(VG_(sizeUniqueBag(lk->heldBy)) == 1);
          /* assert: .. and that thread is 'thr'. */
-         tl_assert(HG_(elemBag)(lk->heldBy, (Word)thr)
-                   == HG_(sizeTotalBag)(lk->heldBy));
-         HG_(addToBag)(lk->heldBy, (Word)thr);
+         tl_assert(VG_(elemBag)(lk->heldBy, (Word)thr)
+                   == VG_(sizeTotalBag)(lk->heldBy));
+         VG_(addToBag)(lk->heldBy, (Word)thr);
          break;
       case LK_rdwr:
          tl_assert(lk->heldBy == NULL && !lk->heldW); /* must be unheld */
@@ -780,11 +780,11 @@ static void lockN_acquire_reader ( Lock* lk, Thread* thr )
    /* end EXPOSITION only */
 
    if (lk->heldBy) {
-      HG_(addToBag)(lk->heldBy, (Word)thr);
+      VG_(addToBag)(lk->heldBy, (Word)thr);
    } else {
       lk->heldW  = False;
-      lk->heldBy = HG_(newBag)( hg_zalloc, hg_free );
-      HG_(addToBag)( lk->heldBy, (Word)thr );
+      lk->heldBy = VG_(newBag)( hg_zalloc, hg_free );
+      VG_(addToBag)( lk->heldBy, (Word)thr );
    }
    tl_assert(!lk->heldW);
    tl_assert(is_sane_LockN(lk));
@@ -803,13 +803,13 @@ static void lockN_release ( Lock* lk, Thread* thr )
    tl_assert(lk->heldBy);
    stats__lockN_releases++;
    /* Remove it from the holder set */
-   b = HG_(delFromBag)(lk->heldBy, (Word)thr);
+   b = VG_(delFromBag)(lk->heldBy, (Word)thr);
    /* thr must actually have been a holder of lk */
    tl_assert(b);
    /* normalise */
    tl_assert(lk->acquired_at);
-   if (HG_(isEmptyBag)(lk->heldBy)) {
-      HG_(deleteBag)(lk->heldBy);
+   if (VG_(isEmptyBag)(lk->heldBy)) {
+      VG_(deleteBag)(lk->heldBy);
       lk->heldBy      = NULL;
       lk->heldW       = False;
       lk->acquired_at = NULL;
@@ -825,8 +825,8 @@ static void remove_Lock_from_locksets_of_all_owning_Threads( Lock* lk )
       return;
    }
    /* for each thread that holds this lock do ... */
-   HG_(initIterBag)( lk->heldBy );
-   while (HG_(nextIterBag)( lk->heldBy, (Word*)&thr, NULL )) {
+   VG_(initIterBag)( lk->heldBy );
+   while (VG_(nextIterBag)( lk->heldBy, (Word*)&thr, NULL )) {
       tl_assert(is_sane_Thread(thr));
       tl_assert(HG_(elemWS)( univ_lsets,
                              thr->locksetA, (Word)lk ));
@@ -840,7 +840,7 @@ static void remove_Lock_from_locksets_of_all_owning_Threads( Lock* lk )
             = HG_(delFromWS)( univ_lsets, thr->locksetW, (Word)lk );
       }
    }
-   HG_(doneIterBag)( lk->heldBy );
+   VG_(doneIterBag)( lk->heldBy );
 }
 
 /* --------- xxxID functions --------- */
@@ -1107,10 +1107,10 @@ static void pp_Lock ( Int d, Lock* lk )
       Thread* thr;
       Word    count;
       VG_(printf)(" { ");
-      HG_(initIterBag)( lk->heldBy );
-      while (HG_(nextIterBag)( lk->heldBy, (Word*)&thr, &count ))
+      VG_(initIterBag)( lk->heldBy );
+      while (VG_(nextIterBag)( lk->heldBy, (Word*)&thr, &count ))
          VG_(printf)("%lu:%p ", count, thr);
-      HG_(doneIterBag)( lk->heldBy );
+      VG_(doneIterBag)( lk->heldBy );
       VG_(printf)("}");
    }
    VG_(printf)("\n");
@@ -1140,14 +1140,14 @@ static void pp_map_locks ( Int d )
    void* gla;
    Lock* lk;
    space(d); VG_(printf)("map_locks (%d entries) {\n",
-                         (Int)HG_(sizeFM)( map_locks ));
-   HG_(initIterFM)( map_locks );
-   while (HG_(nextIterFM)( map_locks, (Word*)&gla,
+                         (Int)VG_(sizeFM)( map_locks ));
+   VG_(initIterFM)( map_locks );
+   while (VG_(nextIterFM)( map_locks, (Word*)&gla,
                                       (Word*)&lk )) {
       space(d+3);
       VG_(printf)("guest %p -> Lock %p\n", gla, lk);
    }
-   HG_(doneIterFM)( map_locks );
+   VG_(doneIterFM)( map_locks );
    space(d); VG_(printf)("}\n");
 }
 
@@ -1188,14 +1188,14 @@ static void pp_map_segments ( Int d )
    SegmentID segid;
    Segment*  seg;
    space(d); VG_(printf)("map_segments (%d entries) {\n", 
-                         (Int)HG_(sizeFM)( map_segments ));
-   HG_(initIterFM)( map_segments );
-   while (HG_(nextIterFM)( map_segments, (Word*)&segid,
+                         (Int)VG_(sizeFM)( map_segments ));
+   VG_(initIterFM)( map_segments );
+   while (VG_(nextIterFM)( map_segments, (Word*)&segid,
                                          (Word*)&seg )) {
       space(d+3);
       VG_(printf)("segid 0x%x -> Segment %p\n", (UInt)segid, seg);
    }
-   HG_(doneIterFM)( map_segments );
+   VG_(doneIterFM)( map_segments );
    space(d); VG_(printf)("}\n");
 }
 
@@ -1309,12 +1309,12 @@ static void pp_map_shmem_shared ( Int d )
    Addr    ga;
    SecMap* sm;
    space(d); VG_(printf)("map_shmem_ShR_and_ShM_only {\n");
-   HG_(initIterFM)( map_shmem );
-   while (HG_(nextIterFM)( map_shmem, (Word*)&ga,
+   VG_(initIterFM)( map_shmem );
+   while (VG_(nextIterFM)( map_shmem, (Word*)&ga,
                                       (Word*)&sm )) {
       pp_SecMap_shared( d+3, sm, ga );
    }
-   HG_(doneIterFM) ( map_shmem );
+   VG_(doneIterFM) ( map_shmem );
    space(d); VG_(printf)("}\n");
 }
 
@@ -1380,7 +1380,7 @@ static void initialise_data_structures ( void )
 
    tl_assert(sizeof(Addr) == sizeof(Word));
    tl_assert(map_shmem == NULL);
-   map_shmem = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
+   map_shmem = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
    tl_assert(map_shmem != NULL);
    shmem__invalidate_scache();
 
@@ -1392,18 +1392,18 @@ static void initialise_data_structures ( void )
    tl_assert(sizeof(SegmentID) <= sizeof(Word));
    tl_assert(sizeof(Segment*) == sizeof(Word));
    tl_assert(map_segments == NULL);
-   map_segments = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
+   map_segments = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
    tl_assert(map_segments != NULL);
    hbefore__invalidate_cache();
 
    tl_assert(sizeof(Addr) == sizeof(Word));
    tl_assert(map_locks == NULL);
-   map_locks = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
+   map_locks = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
    tl_assert(map_locks != NULL);
 
    __bus_lock_Lock = mk_LockN( LK_nonRec, (Addr)&__bus_lock );
    tl_assert(is_sane_LockN(__bus_lock_Lock));
-   HG_(addToFM)( map_locks, (Word)&__bus_lock, (Word)__bus_lock_Lock );
+   VG_(addToFM)( map_locks, (Word)&__bus_lock, (Word)__bus_lock_Lock );
 
    tl_assert(univ_tsets == NULL);
    univ_tsets = HG_(newWordSetU)( hg_zalloc, hg_free, 8/*cacheSize*/ );
@@ -1522,13 +1522,13 @@ Lock* map_locks_lookup_or_create ( LockKind lkk, Addr ga, ThreadId tid )
    Bool  found;
    Lock* oldlock = NULL;
    tl_assert(is_sane_ThreadId(tid));
-   found = HG_(lookupFM)( map_locks, 
+   found = VG_(lookupFM)( map_locks, 
                           NULL, (Word*)&oldlock, (Word)ga );
    if (!found) {
       Lock* lock = mk_LockN(lkk, ga);
       lock->appeared_at = VG_(record_ExeContext)( tid, 0 );
       tl_assert(is_sane_LockN(lock));
-      HG_(addToFM)( map_locks, (Word)ga, (Word)lock );
+      VG_(addToFM)( map_locks, (Word)ga, (Word)lock );
       tl_assert(oldlock == NULL);
       // mark the relevant secondary map has .mbHasLocks
       shmem__set_mbHasLocks( ga, True );
@@ -1547,7 +1547,7 @@ static Lock* map_locks_maybe_lookup ( Addr ga )
 {
    Bool  found;
    Lock* lk = NULL;
-   found = HG_(lookupFM)( map_locks, NULL, (Word*)&lk, (Word)ga );
+   found = VG_(lookupFM)( map_locks, NULL, (Word*)&lk, (Word)ga );
    tl_assert(found  ?  lk != NULL  :  lk == NULL);
    if (found) {
       // check the relevant secondary map has .mbHasLocks?
@@ -1560,7 +1560,7 @@ static void map_locks_delete ( Addr ga )
 {
    Addr  ga2 = 0;
    Lock* lk  = NULL;
-   HG_(delFromFM)( map_locks,
+   VG_(delFromFM)( map_locks,
                    (Word*)&ga2, (Word*)&lk, (Word)ga );
    /* delFromFM produces the val which is being deleted, if it is
       found.  So assert it is non-null; that in effect asserts that we
@@ -1584,7 +1584,7 @@ static Segment* map_segments_lookup ( SegmentID segid )
    Bool     found;
    Segment* seg = NULL;
    tl_assert( is_sane_SegmentID(segid) );
-   found = HG_(lookupFM)( map_segments,
+   found = VG_(lookupFM)( map_segments,
                           NULL, (Word*)&seg, (Word)segid );
    tl_assert(found);
    tl_assert(seg != NULL);
@@ -1596,7 +1596,7 @@ static Segment* map_segments_maybe_lookup ( SegmentID segid )
    Bool     found;
    Segment* seg = NULL;
    tl_assert( is_sane_SegmentID(segid) );
-   found = HG_(lookupFM)( map_segments,
+   found = VG_(lookupFM)( map_segments,
                           NULL, (Word*)&seg, (Word)segid );
    if (!found) tl_assert(seg == NULL);
    return seg;
@@ -1605,8 +1605,8 @@ static Segment* map_segments_maybe_lookup ( SegmentID segid )
 static void map_segments_add ( SegmentID segid, Segment* seg )
 {
    /* This is a bit inefficient.  Oh well. */
-   tl_assert( !HG_(lookupFM)( map_segments, NULL, NULL, segid ));
-   HG_(addToFM)( map_segments, (Word)segid, (Word)seg );
+   tl_assert( !VG_(lookupFM)( map_segments, NULL, NULL, segid ));
+   VG_(addToFM)( map_segments, (Word)segid, (Word)seg );
 }
 
 /*--------------- to do with Vector Timestamps ---------------*/
@@ -2346,7 +2346,7 @@ static SecMap* shmem__find_or_alloc_SecMap ( Addr ga )
 {
    SecMap* sm    = NULL;
    Addr    gaKey = shmem__round_to_SecMap_base(ga);
-   if (HG_(lookupFM)( map_shmem,
+   if (VG_(lookupFM)( map_shmem,
                       NULL/*keyP*/, (Word*)&sm, (Word)gaKey )) {
       /* Found; address of SecMap is in sm */
       tl_assert(sm);
@@ -2354,7 +2354,7 @@ static SecMap* shmem__find_or_alloc_SecMap ( Addr ga )
       /* create a new one */
       sm = shmem__alloc_SecMap();
       tl_assert(sm);
-      HG_(addToFM)( map_shmem, (Word)gaKey, (Word)sm );
+      VG_(addToFM)( map_shmem, (Word)gaKey, (Word)sm );
    }
    return sm;
 }
@@ -2368,7 +2368,7 @@ static Bool shmem__get_mbHasLocks ( Addr a )
 {
    SecMap* sm;
    Addr aKey = shmem__round_to_SecMap_base(a);
-   if (HG_(lookupFM)( map_shmem,
+   if (VG_(lookupFM)( map_shmem,
                       NULL/*keyP*/, (Word*)&sm, (Word)aKey )) {
       /* Found */
       return sm->mbHasLocks;
@@ -2382,14 +2382,14 @@ static void shmem__set_mbHasLocks ( Addr a, Bool b )
    SecMap* sm;
    Addr aKey = shmem__round_to_SecMap_base(a);
    tl_assert(b == False || b == True);
-   if (HG_(lookupFM)( map_shmem,
+   if (VG_(lookupFM)( map_shmem,
                       NULL/*keyP*/, (Word*)&sm, (Word)aKey )) {
       /* Found; address of SecMap is in sm */
    } else {
       /* create a new one */
       sm = shmem__alloc_SecMap();
       tl_assert(sm);
-      HG_(addToFM)( map_shmem, (Word)aKey, (Word)sm );
+      VG_(addToFM)( map_shmem, (Word)aKey, (Word)sm );
    }
    sm->mbHasLocks = b;
 }
@@ -2399,14 +2399,14 @@ static void shmem__set_mbHasShared ( Addr a, Bool b )
    SecMap* sm;
    Addr aKey = shmem__round_to_SecMap_base(a);
    tl_assert(b == False || b == True);
-   if (HG_(lookupFM)( map_shmem,
+   if (VG_(lookupFM)( map_shmem,
                       NULL/*keyP*/, (Word*)&sm, (Word)aKey )) {
       /* Found; address of SecMap is in sm */
    } else {
       /* create a new one */
       sm = shmem__alloc_SecMap();
       tl_assert(sm);
-      HG_(addToFM)( map_shmem, (Word)aKey, (Word)sm );
+      VG_(addToFM)( map_shmem, (Word)aKey, (Word)sm );
    }
    sm->mbHasShared = b;
 }
@@ -2496,7 +2496,7 @@ static void laog__sanity_check ( Char* who ); /* fwds */
 static Bool thread_is_a_holder_of_Lock ( Thread* thr, Lock* lk )
 {
    if (lk->heldBy)
-      return HG_(elemBag)( lk->heldBy, (Word)thr ) > 0;
+      return VG_(elemBag)( lk->heldBy, (Word)thr ) > 0;
    else
       return False;
 }
@@ -2555,15 +2555,15 @@ static void locks__sanity_check ( Char* who )
    // # entries in admin_locks == # entries in map_locks
    for (i = 0, lk = admin_locks;  lk;  i++, lk = lk->admin)
       ;
-   if (i != HG_(sizeFM)(map_locks)) BAD("1");
+   if (i != VG_(sizeFM)(map_locks)) BAD("1");
    // for each entry (gla, lk) in map_locks
    //      gla == lk->guest_addr
-   HG_(initIterFM)( map_locks );
-   while (HG_(nextIterFM)( map_locks,
+   VG_(initIterFM)( map_locks );
+   while (VG_(nextIterFM)( map_locks,
                            (Word*)&gla, (Word*)&lk )) {
       if (lk->guestaddr != gla) BAD("2");
    }
-   HG_(doneIterFM)( map_locks );
+   VG_(doneIterFM)( map_locks );
    // scan through admin_locks ...
    for (lk = admin_locks; lk; lk = lk->admin) {
       // lock is sane.  Quite comprehensive, also checks that
@@ -2581,8 +2581,8 @@ static void locks__sanity_check ( Char* who )
       if (lk->heldBy) {
          Thread* thr;
          Word    count;
-         HG_(initIterBag)( lk->heldBy );
-         while (HG_(nextIterBag)( lk->heldBy, 
+         VG_(initIterBag)( lk->heldBy );
+         while (VG_(nextIterBag)( lk->heldBy, 
                                   (Word*)&thr, &count )) {
             // is_sane_LockN above ensures these
             tl_assert(count >= 1);
@@ -2597,7 +2597,7 @@ static void locks__sanity_check ( Char* who )
                 && HG_(elemWS)(univ_lsets, thr->locksetW, (Word)lk)) 
                BAD("8");
          }
-         HG_(doneIterBag)( lk->heldBy );
+         VG_(doneIterBag)( lk->heldBy );
       } else {
          /* lock not held by anybody */
          if (lk->heldW) BAD("9"); /* should be False if !heldBy */
@@ -2631,7 +2631,7 @@ static void segments__sanity_check ( Char* who )
    // # entries in admin_segments == # entries in map_segments
    for (i = 0, seg = admin_segments;  seg;  i++, seg = seg->admin)
       ;
-   if (i != HG_(sizeFM)(map_segments)) BAD("1");
+   if (i != VG_(sizeFM)(map_segments)) BAD("1");
    // for seg in Segments {
    for (seg = admin_segments; seg; seg = seg->admin) {
       if (!is_sane_Segment(seg)) BAD("2");
@@ -2671,9 +2671,9 @@ static void shmem__sanity_check ( Char* who )
    Word    i, j, ws_size, n_valid_tags;
    UWord*  ws_words;
    Addr*   valid_tags;
-   HG_(initIterFM)( map_shmem );
+   VG_(initIterFM)( map_shmem );
    // for sm in SecMaps {
-   while (HG_(nextIterFM)( map_shmem,
+   while (VG_(nextIterFM)( map_shmem,
                            (Word*)&smga, (Word*)&sm )) {
       SecMapIter itr;
       SVal*      w32p = NULL;
@@ -2737,7 +2737,7 @@ static void shmem__sanity_check ( Char* who )
       // GCing of SecMaps is implemented
       //if (allNoAccess && sm->mbHasLocks) BAD("13a");
    }
-   HG_(doneIterFM)( map_shmem );
+   VG_(doneIterFM)( map_shmem );
 
    // check the cache
    valid_tags   = hg_zalloc(N_WAY_NENT * sizeof(Addr));
@@ -2929,8 +2929,8 @@ void record_last_lock_lossage ( Addr ga_of_access,
                       HG_(cardinalityWS)( univ_lsets, lset_old), lk );
    if (lk->appeared_at) {
       if (ga_to_lastlock == NULL)
-         ga_to_lastlock = HG_(newFM)( hg_zalloc, hg_free, NULL );
-      HG_(addToFM)( ga_to_lastlock, ga_of_access, (Word)lk->appeared_at );
+         ga_to_lastlock = VG_(newFM)( hg_zalloc, hg_free, NULL );
+      VG_(addToFM)( ga_to_lastlock, ga_of_access, (Word)lk->appeared_at );
       stats__ga_LL_adds++;
    }
 }
@@ -2944,7 +2944,7 @@ static ExeContext* maybe_get_lastlock_initpoint ( Addr ga )
 {
    ExeContext* ec_hint = NULL;
    if (ga_to_lastlock != NULL 
-       && HG_(lookupFM)(ga_to_lastlock, 
+       && VG_(lookupFM)(ga_to_lastlock, 
                         NULL, (Word*)&ec_hint, ga)) {
       tl_assert(ec_hint != NULL);
       return ec_hint;
@@ -4941,8 +4941,8 @@ static void shadow_mem_make_NoAccess ( Thread* thr, Addr aIN, SizeT len )
    locksToDelete = HG_(emptyWS)( univ_lsets );
    
    /* Iterate over all locks in the range firstA .. lastA inclusive. */
-   HG_(initIterAtFM)( map_locks, firstA );
-   while (HG_(nextIterFM)( map_locks, (Word*)&gla, (Word*)&lk )
+   VG_(initIterAtFM)( map_locks, firstA );
+   while (VG_(nextIterFM)( map_locks, (Word*)&gla, (Word*)&lk )
           && gla <= lastA) {
       tl_assert(is_sane_LockN(lk));
       tl_assert(gla >= firstA);
@@ -4956,15 +4956,15 @@ static void shadow_mem_make_NoAccess ( Thread* thr, Addr aIN, SizeT len )
          them all, but that's too much hassle.  So choose one
          arbitrarily. */
       if (lk->heldBy) {
-         tl_assert(!HG_(isEmptyBag)(lk->heldBy));
-         record_error_FreeMemLock( (Thread*)HG_(anyElementOfBag)(lk->heldBy),
+         tl_assert(!VG_(isEmptyBag)(lk->heldBy));
+         record_error_FreeMemLock( (Thread*)VG_(anyElementOfBag)(lk->heldBy),
                                    lk );
          /* remove lock from locksets of all owning threads */
          remove_Lock_from_locksets_of_all_owning_Threads( lk );
          /* Leave lk->heldBy in place; del_Lock below will free it up. */
       }
    }
-   HG_(doneIterFM)( map_locks );
+   VG_(doneIterFM)( map_locks );
 
    /* --- Step 5 --- */
 
@@ -4991,8 +4991,8 @@ static void shadow_mem_make_NoAccess ( Thread* thr, Addr aIN, SizeT len )
      SecMapIter itr;
      SVal*      w32p = NULL;
 
-     HG_(initIterFM)( map_shmem );
-     while (HG_(nextIterFM)( map_shmem,
+     VG_(initIterFM)( map_shmem );
+     while (VG_(nextIterFM)( map_shmem,
                              (Word*)&ga, (Word*)&sm )) {
         tl_assert(sm);
         stats_SMs++;
@@ -5019,7 +5019,7 @@ static void shadow_mem_make_NoAccess ( Thread* thr, Addr aIN, SizeT len )
               *w32p = wnew;
         }
      }
-     HG_(doneIterFM)( map_shmem );
+     VG_(doneIterFM)( map_shmem );
      if (SHOW_EXPENSIVE_STUFF)
         VG_(printf)("shadow_mem_make_NoAccess: %d SMs, %d scanned\n", 
                     stats_SMs, stats_SMs_scanned);
@@ -5144,9 +5144,9 @@ void evhH__post_thread_w_acquires_lock ( Thread* thr,
 
    /* So the lock is held in w-mode.  If it's held by some other
       thread, then libpthread must be buggy. */
-   tl_assert(HG_(sizeUniqueBag)(lk->heldBy) == 1); /* from precondition */
+   tl_assert(VG_(sizeUniqueBag)(lk->heldBy) == 1); /* from precondition */
 
-   if (thr != (Thread*)HG_(anyElementOfBag)(lk->heldBy)) {
+   if (thr != (Thread*)VG_(anyElementOfBag)(lk->heldBy)) {
       record_error_Misc( thr, "Bug in libpthread: write lock "
                               "granted on mutex/rwlock which is currently "
                               "wr-held by a different thread");
@@ -5309,14 +5309,14 @@ void evhH__pre_thread_releases_lock ( Thread* thr,
 
    /* The lock is held.  Is this thread one of the holders?  If not,
       report a bug in the client. */
-   n = HG_(elemBag)( lock->heldBy, (Word)thr );
+   n = VG_(elemBag)( lock->heldBy, (Word)thr );
    tl_assert(n >= 0);
    if (n == 0) {
       /* We are not a current holder of the lock.  This is a bug in
          the guest, and (per POSIX pthread rules) the unlock
          attempt will fail.  So just complain and do nothing
          else. */
-      Thread* realOwner = (Thread*)HG_(anyElementOfBag)( lock->heldBy );
+      Thread* realOwner = (Thread*)VG_(anyElementOfBag)( lock->heldBy );
       tl_assert(is_sane_Thread(realOwner));
       tl_assert(realOwner != thr);
       tl_assert(!HG_(elemWS)( univ_lsets, thr->locksetA, (Word)lock ));
@@ -5335,7 +5335,7 @@ void evhH__pre_thread_releases_lock ( Thread* thr,
 
    if (n > 0) {
       tl_assert(lock->heldBy);
-      tl_assert(n == HG_(elemBag)( lock->heldBy, (Word)thr )); 
+      tl_assert(n == VG_(elemBag)( lock->heldBy, (Word)thr )); 
       /* We still hold the lock.  So either it's a recursive lock 
          or a rwlock which is currently r-held. */
       tl_assert(lock->kind == LK_mbRec
@@ -5348,7 +5348,7 @@ void evhH__pre_thread_releases_lock ( Thread* thr,
    } else {
       /* We no longer hold the lock. */
       if (lock->heldBy) {
-         tl_assert(0 == HG_(elemBag)( lock->heldBy, (Word)thr ));
+         tl_assert(0 == VG_(elemBag)( lock->heldBy, (Word)thr ));
       }
       /* update this thread's lockset accordingly. */
       thr->locksetA
@@ -5665,8 +5665,8 @@ void evh__HG_PTHREAD_JOIN_POST ( ThreadId stay_tid, Thread* quit_thr )
    shmem__flush_and_invalidate_scache();
 
    stats_SMs = stats_SMs_scanned = stats_reExcls = 0;
-   HG_(initIterFM)( map_shmem );
-   while (HG_(nextIterFM)( map_shmem,
+   VG_(initIterFM)( map_shmem );
+   while (VG_(nextIterFM)( map_shmem,
                            (Word*)&ga, (Word*)&sm )) {
       SecMapIter itr;
       SVal*      w32p = NULL;
@@ -5723,7 +5723,7 @@ void evh__HG_PTHREAD_JOIN_POST ( ThreadId stay_tid, Thread* quit_thr )
          *w32p = wnew;
       }
    }
-   HG_(doneIterFM)( map_shmem );
+   VG_(doneIterFM)( map_shmem );
 
    if (SHOW_EXPENSIVE_STUFF)
       VG_(printf)("evh__post_thread_join: %d SMs, "
@@ -5912,7 +5912,7 @@ void evh__HG_PTHREAD_MUTEX_DESTROY_PRE( ThreadId tid, void* mutex )
          record_error_Misc( thr, "pthread_mutex_destroy of a locked mutex" );
          /* remove lock from locksets of all owning threads */
          remove_Lock_from_locksets_of_all_owning_Threads( lk );
-         HG_(deleteBag)( lk->heldBy );
+         VG_(deleteBag)( lk->heldBy );
          lk->heldBy = NULL;
          lk->heldW = False;
          lk->acquired_at = NULL;
@@ -5952,7 +5952,7 @@ static void evh__HG_PTHREAD_MUTEX_LOCK_PRE ( ThreadId tid,
         && (lk->kind == LK_nonRec || lk->kind == LK_rdwr)
         && lk->heldBy
         && lk->heldW
-        && HG_(elemBag)( lk->heldBy, (Word)thr ) > 0 ) {
+        && VG_(elemBag)( lk->heldBy, (Word)thr ) > 0 ) {
       /* uh, it's a non-recursive lock and we already w-hold it, and
          this is a real lock operation (not a speculative "tryLock"
          kind of thing).  Duh.  Deadlock coming up; but at least
@@ -6021,7 +6021,7 @@ static WordFM* map_cond_to_Segment = NULL;
 
 static void map_cond_to_Segment_INIT ( void ) {
    if (UNLIKELY(map_cond_to_Segment == NULL)) {
-      map_cond_to_Segment = HG_(newFM)( hg_zalloc, hg_free, NULL );
+      map_cond_to_Segment = VG_(newFM)( hg_zalloc, hg_free, NULL );
       tl_assert(map_cond_to_Segment != NULL);
    }
 }
@@ -6063,7 +6063,7 @@ static void evh__HG_PTHREAD_COND_SIGNAL_PRE ( ThreadId tid, void* cond )
       new_seg->vts = tick_VTS( new_seg->thr, new_seg->prev->vts );
 
       /* ... and add the binding. */
-      HG_(addToFM)( map_cond_to_Segment, (Word)cond,
+      VG_(addToFM)( map_cond_to_Segment, (Word)cond,
                                          (Word)(new_seg->prev) );
    }
 }
@@ -6110,7 +6110,7 @@ static Bool evh__HG_PTHREAD_COND_WAIT_PRE ( ThreadId tid,
             thr, "pthread_cond_{timed}wait called with un-held mutex");
       } else
       if (lk->heldBy != NULL
-          && HG_(elemBag)( lk->heldBy, (Word)thr ) == 0) {
+          && VG_(elemBag)( lk->heldBy, (Word)thr ) == 0) {
          lk_valid = False;
          record_error_Misc( 
             thr, "pthread_cond_{timed}wait called with mutex "
@@ -6162,7 +6162,7 @@ static void evh__HG_PTHREAD_COND_WAIT_POST ( ThreadId tid,
       /* and find out which thread signalled us; then add a dependency
          edge back to it. */
       signalling_seg = NULL;
-      found = HG_(lookupFM)( map_cond_to_Segment, 
+      found = VG_(lookupFM)( map_cond_to_Segment, 
                              NULL, (Word*)&signalling_seg,
                                    (Word)cond );
       if (found) {
@@ -6233,7 +6233,7 @@ void evh__HG_PTHREAD_RWLOCK_DESTROY_PRE( ThreadId tid, void* rwl )
          record_error_Misc( thr, "pthread_rwlock_destroy of a locked mutex" );
          /* remove lock from locksets of all owning threads */
          remove_Lock_from_locksets_of_all_owning_Threads( lk );
-         HG_(deleteBag)( lk->heldBy );
+         VG_(deleteBag)( lk->heldBy );
          lk->heldBy = NULL;
          lk->heldW = False;
          lk->acquired_at = NULL;
@@ -6362,7 +6362,7 @@ static WordFM* map_sem_to_Segment_stack = NULL;
 
 static void map_sem_to_Segment_stack_INIT ( void ) {
    if (map_sem_to_Segment_stack == NULL) {
-      map_sem_to_Segment_stack = HG_(newFM)( hg_zalloc, hg_free, NULL );
+      map_sem_to_Segment_stack = VG_(newFM)( hg_zalloc, hg_free, NULL );
       tl_assert(map_sem_to_Segment_stack != NULL);
    }
 }
@@ -6371,14 +6371,14 @@ static void push_Segment_for_sem ( void* sem, Segment* seg ) {
    XArray* xa;
    tl_assert(seg);
    map_sem_to_Segment_stack_INIT();
-   if (HG_(lookupFM)( map_sem_to_Segment_stack, 
+   if (VG_(lookupFM)( map_sem_to_Segment_stack, 
                       NULL, (Word*)&xa, (Word)sem )) {
       tl_assert(xa);
       VG_(addToXA)( xa, &seg );
    } else {
       xa = VG_(newXA)( hg_zalloc, hg_free, sizeof(Segment*) );
       VG_(addToXA)( xa, &seg );
-      HG_(addToFM)( map_sem_to_Segment_stack, (Word)sem, (Word)xa );
+      VG_(addToFM)( map_sem_to_Segment_stack, (Word)sem, (Word)xa );
    }
 }
 
@@ -6386,7 +6386,7 @@ static Segment* mb_pop_Segment_for_sem ( void* sem ) {
    XArray*  xa;
    Segment* seg;
    map_sem_to_Segment_stack_INIT();
-   if (HG_(lookupFM)( map_sem_to_Segment_stack, 
+   if (VG_(lookupFM)( map_sem_to_Segment_stack, 
                       NULL, (Word*)&xa, (Word)sem )) {
       /* xa is the stack for this semaphore. */
       Word sz = VG_(sizeXA)( xa );
@@ -6640,10 +6640,10 @@ static void laog__show ( Char* who ) {
    Lock* me;
    LAOGLinks* links;
    VG_(printf)("laog (requested by %s) {\n", who);
-   HG_(initIterFM)( laog );
+   VG_(initIterFM)( laog );
    me = NULL;
    links = NULL;
-   while (HG_(nextIterFM)( laog, (Word*)&me,
+   while (VG_(nextIterFM)( laog, (Word*)&me,
                                  (Word*)&links )) {
       tl_assert(me);
       tl_assert(links);
@@ -6657,7 +6657,7 @@ static void laog__show ( Char* who ) {
       me = NULL;
       links = NULL;
    }
-   HG_(doneIterFM)( laog );
+   VG_(doneIterFM)( laog );
    VG_(printf)("}\n");
 }
 
@@ -6681,7 +6681,7 @@ static void laog__add_edge ( Lock* src, Lock* dst ) {
    /* Update the out edges for src */
    keyW  = 0;
    links = NULL;
-   if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)src )) {
+   if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)src )) {
       WordSetID outs_new;
       tl_assert(links);
       tl_assert(keyW == (Word)src);
@@ -6692,12 +6692,12 @@ static void laog__add_edge ( Lock* src, Lock* dst ) {
       links = hg_zalloc(sizeof(LAOGLinks));
       links->inns = HG_(emptyWS)( univ_laog );
       links->outs = HG_(singletonWS)( univ_laog, (Word)dst );
-      HG_(addToFM)( laog, (Word)src, (Word)links );
+      VG_(addToFM)( laog, (Word)src, (Word)links );
    }
    /* Update the in edges for dst */
    keyW  = 0;
    links = NULL;
-   if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)dst )) {
+   if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)dst )) {
       WordSetID inns_new;
       tl_assert(links);
       tl_assert(keyW == (Word)dst);
@@ -6708,7 +6708,7 @@ static void laog__add_edge ( Lock* src, Lock* dst ) {
       links = hg_zalloc(sizeof(LAOGLinks));
       links->inns = HG_(singletonWS)( univ_laog, (Word)src );
       links->outs = HG_(emptyWS)( univ_laog );
-      HG_(addToFM)( laog, (Word)dst, (Word)links );
+      VG_(addToFM)( laog, (Word)dst, (Word)links );
    }
 
    tl_assert( (presentF && presentR) || (!presentF && !presentR) );
@@ -6727,7 +6727,7 @@ static void laog__add_edge ( Lock* src, Lock* dst ) {
       expo.src_ec = NULL;
       expo.dst_ec = NULL;
       tl_assert(laog_exposition);
-      if (HG_(lookupFM)( laog_exposition, NULL, NULL, (Word)&expo )) {
+      if (VG_(lookupFM)( laog_exposition, NULL, NULL, (Word)&expo )) {
          /* we already have it; do nothing */
       } else {
          LAOGLinkExposition* expo2 = hg_zalloc(sizeof(LAOGLinkExposition));
@@ -6735,7 +6735,7 @@ static void laog__add_edge ( Lock* src, Lock* dst ) {
          expo2->dst_ga = dst->guestaddr;
          expo2->src_ec = src->acquired_at;
          expo2->dst_ec = dst->acquired_at;
-         HG_(addToFM)( laog_exposition, (Word)expo2, (Word)NULL );
+         VG_(addToFM)( laog_exposition, (Word)expo2, (Word)NULL );
       }
    }
 }
@@ -6748,7 +6748,7 @@ static void laog__del_edge ( Lock* src, Lock* dst ) {
    /* Update the out edges for src */
    keyW  = 0;
    links = NULL;
-   if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)src )) {
+   if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)src )) {
       tl_assert(links);
       tl_assert(keyW == (Word)src);
       links->outs = HG_(delFromWS)( univ_laog, links->outs, (Word)dst );
@@ -6756,7 +6756,7 @@ static void laog__del_edge ( Lock* src, Lock* dst ) {
    /* Update the in edges for dst */
    keyW  = 0;
    links = NULL;
-   if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)dst )) {
+   if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)dst )) {
       tl_assert(links);
       tl_assert(keyW == (Word)dst);
       links->inns = HG_(delFromWS)( univ_laog, links->inns, (Word)src );
@@ -6769,7 +6769,7 @@ static WordSetID /* in univ_laog */ laog__succs ( Lock* lk ) {
    LAOGLinks* links;
    keyW  = 0;
    links = NULL;
-   if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)lk )) {
+   if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)lk )) {
       tl_assert(links);
       tl_assert(keyW == (Word)lk);
       return links->outs;
@@ -6784,7 +6784,7 @@ static WordSetID /* in univ_laog */ laog__preds ( Lock* lk ) {
    LAOGLinks* links;
    keyW  = 0;
    links = NULL;
-   if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)lk )) {
+   if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)lk )) {
       tl_assert(links);
       tl_assert(keyW == (Word)lk);
       return links->inns;
@@ -6801,11 +6801,11 @@ static void laog__sanity_check ( Char* who ) {
    LAOGLinks* links;
    if ( !laog )
       return; /* nothing much we can do */
-   HG_(initIterFM)( laog );
+   VG_(initIterFM)( laog );
    me = NULL;
    links = NULL;
    if (0) VG_(printf)("laog sanity check\n");
-   while (HG_(nextIterFM)( laog, (Word*)&me,
+   while (VG_(nextIterFM)( laog, (Word*)&me,
                                  (Word*)&links )) {
       tl_assert(me);
       tl_assert(links);
@@ -6826,7 +6826,7 @@ static void laog__sanity_check ( Char* who ) {
       me = NULL;
       links = NULL;
    }
-   HG_(doneIterFM)( laog );
+   VG_(doneIterFM)( laog );
    return;
 
   bad:
@@ -6860,7 +6860,7 @@ Lock* laog__do_dfs_from_to ( Lock* src, WordSetID dsts /* univ_lsets */ )
 
    ret     = NULL;
    stack   = VG_(newXA)( hg_zalloc, hg_free, sizeof(Lock*) );
-   visited = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
+   visited = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
 
    (void) VG_(addToXA)( stack, &src );
 
@@ -6875,10 +6875,10 @@ Lock* laog__do_dfs_from_to ( Lock* src, WordSetID dsts /* univ_lsets */ )
 
       if (HG_(elemWS)( univ_lsets, dsts, (Word)here )) { ret = here; break; }
 
-      if (HG_(lookupFM)( visited, NULL, NULL, (Word)here ))
+      if (VG_(lookupFM)( visited, NULL, NULL, (Word)here ))
          continue;
 
-      HG_(addToFM)( visited, (Word)here, 0 );
+      VG_(addToFM)( visited, (Word)here, 0 );
 
       succs = laog__succs( here );
       HG_(getPayloadWS)( &succs_words, &succs_size, univ_laog, succs );
@@ -6886,7 +6886,7 @@ Lock* laog__do_dfs_from_to ( Lock* src, WordSetID dsts /* univ_lsets */ )
          (void) VG_(addToXA)( stack, &succs_words[i] );
    }
 
-   HG_(deleteFM)( visited, NULL, NULL );
+   VG_(deleteFM)( visited, NULL, NULL );
    VG_(deleteXA)( stack );
    return ret;
 }
@@ -6913,9 +6913,9 @@ static void laog__pre_thread_acquires_lock (
       return;
 
    if (!laog)
-      laog = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
+      laog = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
    if (!laog_exposition)
-      laog_exposition = HG_(newFM)( hg_zalloc, hg_free, 
+      laog_exposition = VG_(newFM)( hg_zalloc, hg_free, 
                                     cmp_LAOGLinkExposition );
 
    /* First, the check.  Complain if there is any path in laog from lk
@@ -6939,7 +6939,7 @@ static void laog__pre_thread_acquires_lock (
       key.src_ec = NULL;
       key.dst_ec = NULL;
       found = NULL;
-      if (HG_(lookupFM)( laog_exposition,
+      if (VG_(lookupFM)( laog_exposition,
                          (Word*)&found, NULL, (Word)&key )) {
          tl_assert(found != &key);
          tl_assert(found->src_ga == key.src_ga);
@@ -7021,9 +7021,9 @@ static void laog__handle_lock_deletions (
    UWord* ws_words;
 
    if (!laog)
-      laog = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
+      laog = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
    if (!laog_exposition)
-      laog_exposition = HG_(newFM)( hg_zalloc, hg_free, 
+      laog_exposition = VG_(newFM)( hg_zalloc, hg_free, 
                                     cmp_LAOGLinkExposition );
 
    HG_(getPayloadWS)( &ws_words, &ws_size, univ_lsets, locksToDelete );
@@ -7499,7 +7499,7 @@ static WordFM* map_pthread_t_to_Thread = NULL; /* pthread_t -> Thread* */
 
 static void map_pthread_t_to_Thread_INIT ( void ) {
    if (UNLIKELY(map_pthread_t_to_Thread == NULL)) {
-      map_pthread_t_to_Thread = HG_(newFM)( hg_zalloc, hg_free, NULL );
+      map_pthread_t_to_Thread = VG_(newFM)( hg_zalloc, hg_free, NULL );
       tl_assert(map_pthread_t_to_Thread != NULL);
    }
 }
@@ -7559,7 +7559,7 @@ Bool hg_handle_client_request ( ThreadId tid, UWord* args, UWord* ret)
          if (0)
          VG_(printf)("XXXX: bind pthread_t %p to Thread* %p\n",
                      (void*)args[1], (void*)my_thr );
-         HG_(addToFM)( map_pthread_t_to_Thread, (Word)args[1], (Word)my_thr );
+         VG_(addToFM)( map_pthread_t_to_Thread, (Word)args[1], (Word)my_thr );
          break;
       }
 
@@ -7582,7 +7582,7 @@ Bool hg_handle_client_request ( ThreadId tid, UWord* args, UWord* ret)
          VG_(printf)("NOTIFY_JOIN_COMPLETE (tid %d): quitter = %p\n", (Int)tid,
                      (void*)args[1]);
          map_pthread_t_to_Thread_INIT();
-         found = HG_(lookupFM)( map_pthread_t_to_Thread, 
+         found = VG_(lookupFM)( map_pthread_t_to_Thread, 
                                 NULL, (Word*)&thr_q, (Word)args[1] );
           /* Can this fail?  It would mean that our pthread_join
              wrapper observed a successful join on args[1] yet that
@@ -7736,10 +7736,10 @@ static HChar* string_table_strdup ( HChar* str ) {
    if (!str)
       str = "(null)";
    if (!string_table) {
-      string_table = HG_(newFM)( hg_zalloc, hg_free, string_table_cmp );
+      string_table = VG_(newFM)( hg_zalloc, hg_free, string_table_cmp );
       tl_assert(string_table);
    }
-   if (HG_(lookupFM)( string_table,
+   if (VG_(lookupFM)( string_table,
                       NULL, (Word*)&copy, (Word)str )) {
       tl_assert(copy);
       if (0) VG_(printf)("string_table_strdup: %p -> %p\n", str, copy );
@@ -7747,7 +7747,7 @@ static HChar* string_table_strdup ( HChar* str ) {
    } else {
       copy = VG_(strdup)(str);
       tl_assert(copy);
-      HG_(addToFM)( string_table, (Word)copy, (Word)copy );
+      VG_(addToFM)( string_table, (Word)copy, (Word)copy );
       return copy;
    }
 }
@@ -7771,10 +7771,10 @@ static Lock* mk_LockP_from_LockN ( Lock* lkn )
    stats__ga_LockN_to_P_queries++;
    tl_assert( is_sane_LockN(lkn) );
    if (!yaWFM) {
-      yaWFM = HG_(newFM)( hg_zalloc, hg_free, lock_unique_cmp );
+      yaWFM = VG_(newFM)( hg_zalloc, hg_free, lock_unique_cmp );
       tl_assert(yaWFM);
    }
-   if (!HG_(lookupFM)( yaWFM, NULL, (Word*)&lkp, (Word)lkn)) {
+   if (!VG_(lookupFM)( yaWFM, NULL, (Word*)&lkp, (Word)lkn)) {
       lkp = hg_zalloc( sizeof(Lock) );
       *lkp = *lkn;
       lkp->admin = NULL;
@@ -7785,7 +7785,7 @@ static Lock* mk_LockP_from_LockN ( Lock* lkn )
       lkp->heldW  = False;
       lkp->heldBy = NULL;
       lkp->acquired_at = NULL;
-      HG_(addToFM)( yaWFM, (Word)lkp, (Word)lkp );
+      VG_(addToFM)( yaWFM, (Word)lkp, (Word)lkp );
    }
    tl_assert( is_sane_LockP(lkp) );
    return lkp;
@@ -8693,19 +8693,19 @@ static void hg_fini ( Int exitcode )
 
       VG_(printf)("L(ast)L(ock) map: %'8lu inserts (%d map size)\n",
                   stats__ga_LL_adds,
-                  (Int)(ga_to_lastlock ? HG_(sizeFM)( ga_to_lastlock ) : 0) );
+                  (Int)(ga_to_lastlock ? VG_(sizeFM)( ga_to_lastlock ) : 0) );
 
       VG_(printf)("  LockN-to-P map: %'8lu queries (%d map size)\n",
                   stats__ga_LockN_to_P_queries,
-                  (Int)(yaWFM ? HG_(sizeFM)( yaWFM ) : 0) );
+                  (Int)(yaWFM ? VG_(sizeFM)( yaWFM ) : 0) );
 
       VG_(printf)("string table map: %'8lu queries (%d map size)\n",
                   stats__string_table_queries,
-                  (Int)(string_table ? HG_(sizeFM)( string_table ) : 0) );
+                  (Int)(string_table ? VG_(sizeFM)( string_table ) : 0) );
       VG_(printf)("            LAOG: %'8d map size\n",
-                  (Int)(laog ? HG_(sizeFM)( laog ) : 0));
+                  (Int)(laog ? VG_(sizeFM)( laog ) : 0));
       VG_(printf)(" LAOG exposition: %'8d map size\n",
-                  (Int)(laog_exposition ? HG_(sizeFM)( laog_exposition ) : 0));
+                  (Int)(laog_exposition ? VG_(sizeFM)( laog_exposition ) : 0));
       VG_(printf)("           locks: %'8lu acquires, "
                   "%'lu releases\n",
                   stats__lockN_acquires,
index 77e09b03a90a680cabaaf7d09aac3304e99a019e..ad6f66d5246e929c2c18466e5e76e9b4043535dc 100644 (file)
@@ -38,9 +38,9 @@
 #include "pub_tool_libcassert.h"
 #include "pub_tool_libcbase.h"
 #include "pub_tool_libcprint.h"
+#include "pub_tool_wordfm.h"
 
 #define HG_(str) VGAPPEND(vgHelgrind_,str)
-#include "hg_wordfm.h"
 #include "hg_wordset.h"
 
 //------------------------------------------------------------------//
@@ -280,7 +280,7 @@ static WordSet add_or_dealloc_WordVec( WordSetU* wsu, WordVec* wv_new )
       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, 
+   have = VG_(lookupFM)( wsu->vec2ix, 
                          (Word*)&wv_old, (Word*)&ix_old,
                          (Word)wv_new );
    if (have) {
@@ -296,7 +296,7 @@ static WordSet add_or_dealloc_WordVec( WordSetU* wsu, WordVec* wv_new )
       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 );
+      VG_(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);
@@ -316,7 +316,7 @@ WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( SizeT ),
    VG_(memset)( wsu, 0, sizeof(WordSetU) );
    wsu->alloc   = alloc_nofail;
    wsu->dealloc = dealloc;
-   wsu->vec2ix  = HG_(newFM)( alloc_nofail, dealloc, cmp_WordVecs_for_FM );
+   wsu->vec2ix  = VG_(newFM)( alloc_nofail, dealloc, cmp_WordVecs_for_FM );
    wsu->ix2vec_used = 0;
    wsu->ix2vec_size = 0;
    wsu->ix2vec      = NULL;
@@ -334,7 +334,7 @@ void HG_(deleteWordSetU) ( WordSetU* wsu )
 {
    void (*dealloc)(void*) = wsu->dealloc;
    tl_assert(wsu->vec2ix);
-   HG_(deleteFM)( wsu->vec2ix, delete_WV_for_FM, NULL/*val-finalizer*/ );
+   VG_(deleteFM)( wsu->vec2ix, delete_WV_for_FM, NULL/*val-finalizer*/ );
    if (wsu->ix2vec)
       dealloc(wsu->ix2vec);
    dealloc(wsu);
@@ -496,10 +496,11 @@ void HG_(ppWSUstats) ( WordSetU* wsu, HChar* name )
    VG_(printf)("   WordSet \"%s\":\n", name);
    VG_(printf)("      addTo        %10lu (%lu uncached)\n",
                wsu->n_add, wsu->n_add_uncached);
-   VG_(printf)("      delFrom      %10lu (%lu uncached)\n",
+   VG_(printf)("      delFrom      %10lu (%lu uncached)\n", 
                wsu->n_del, wsu->n_del_uncached);
    VG_(printf)("      union        %10lu\n", wsu->n_union);
-   VG_(printf)("      intersect    %10lu (%lu uncached) [nb. incl isSubsetOf]\n",
+   VG_(printf)("      intersect    %10lu (%lu uncached) "
+               "[nb. incl isSubsetOf]\n", 
                wsu->n_intersect, wsu->n_intersect_uncached);
    VG_(printf)("      minus        %10lu (%lu uncached)\n",
                wsu->n_minus, wsu->n_minus_uncached);
index f3f3ce7238afae459590d1459492fe1b03550255..70d32a698506a602bb32cfe74d6b96e60d929d63 100644 (file)
@@ -32,5 +32,6 @@ incinc_HEADERS = \
        pub_tool_tooliface.h            \
        pub_tool_vki.h                  \
        pub_tool_vkiscnums.h            \
+       pub_tool_wordfm.h               \
        pub_tool_xarray.h               \
        valgrind.h
similarity index 80%
rename from helgrind/hg_wordfm.h
rename to include/pub_tool_wordfm.h
index db89712618c20140d957a45e821e085af2e42c39..8bbee73d7475445f293c206a3752c6b3947a9aa1 100644 (file)
@@ -2,12 +2,12 @@
 /*--------------------------------------------------------------------*/
 /*--- An AVL tree based finite map for word keys and word values.  ---*/
 /*--- Inspired by Haskell's "FiniteMap" library.                   ---*/
-/*---                                                  hg_wordfm.h ---*/
+/*---                                            pub_tool_wordfm.h ---*/
 /*--------------------------------------------------------------------*/
 
 /*
-   This file is part of Helgrind, a Valgrind tool for detecting errors
-   in threaded programs.
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
 
    Copyright (C) 2007-2008 Julian Seward
       jseward@acm.org
@@ -49,8 +49,8 @@
    The GNU General Public License is contained in the file COPYING.
 */
 
-#ifndef __HG_WORDFM_H
-#define __HG_WORDFM_H
+#ifndef __PUB_TOOL_WORDFM_H
+#define __PUB_TOOL_WORDFM_H
 
 //------------------------------------------------------------------//
 //---                           WordFM                           ---//
@@ -61,7 +61,7 @@
    WordSet, WordBag) now operate on unsigned words (UWord), whereas
    they previously operated on signed words (Word).  This became a
    problem, when using unboxed comparisons (when kCmp == NULL), with
-   the introduction of HG_(initIterAtFM), which allows iteration over
+   the introduction of VG_(initIterAtFM), which allows iteration over
    parts of mappings.  Iterating over a mapping in increasing order of
    signed Word keys is not what callers expect when iterating through
    maps whose keys represent addresses (Addr) since Addr is unsigned,
@@ -76,46 +76,46 @@ typedef  struct _WordFM  WordFM; /* opaque */
    sections of the map, or the whole thing.  If kCmp is NULL then the
    ordering used is unsigned word ordering (UWord) on the key
    values. */
-WordFM* HG_(newFM) ( void* (*alloc_nofail)( SizeT ),
+WordFM* VG_(newFM) ( void* (*alloc_nofail)( SizeT ),
                      void  (*dealloc)(void*),
                      Word  (*kCmp)(UWord,UWord) );
 
 /* Free up the FM.  If kFin is non-NULL, it is applied to keys
    before the FM is deleted; ditto with vFin for vals. */
-void HG_(deleteFM) ( WordFM*, void(*kFin)(UWord), void(*vFin)(UWord) );
+void VG_(deleteFM) ( WordFM*, void(*kFin)(UWord), void(*vFin)(UWord) );
 
 /* Add (k,v) to fm.  If a binding for k already exists, it is updated
    to map to this new v.  In that case we should really return the
    previous v so that caller can finalise it.  Oh well. */
-void HG_(addToFM) ( WordFM* fm, UWord k, UWord v );
+void VG_(addToFM) ( WordFM* fm, UWord k, UWord v );
 
 // Delete key from fm, returning associated key and val if found
-Bool HG_(delFromFM) ( WordFM* fm,
+Bool VG_(delFromFM) ( WordFM* fm,
                       /*OUT*/UWord* oldK, /*OUT*/UWord* oldV, UWord key );
 
 // Look up in fm, assigning found key & val at spec'd addresses
-Bool HG_(lookupFM) ( WordFM* fm, 
+Bool VG_(lookupFM) ( WordFM* fm, 
                      /*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key );
 
 // How many elements are there in fm?
-UWord HG_(sizeFM) ( WordFM* fm );
+UWord VG_(sizeFM) ( WordFM* fm );
 
 // set up FM for iteration
-void HG_(initIterFM) ( WordFM* fm );
+void VG_(initIterFM) ( WordFM* fm );
 
 // set up FM for iteration so that the first key subsequently produced
-// by HG_(nextIterFM) is the smallest key in the map >= start_at.
+// by VG_(nextIterFM) is the smallest key in the map >= start_at.
 // Naturally ">=" is defined by the comparison function supplied to
-// HG_(newFM), as documented above.
-void HG_(initIterAtFM) ( WordFM* fm, UWord start_at );
+// VG_(newFM), as documented above.
+void VG_(initIterAtFM) ( WordFM* fm, UWord start_at );
 
 // get next key/val pair.  Will assert if fm has been modified
 // or looked up in since initIterFM/initIterWithStartFM was called.
-Bool HG_(nextIterFM) ( WordFM* fm,
+Bool VG_(nextIterFM) ( WordFM* fm,
                        /*OUT*/UWord* pKey, /*OUT*/UWord* pVal );
 
 // clear the I'm iterating flag
-void HG_(doneIterFM) ( WordFM* fm );
+void VG_(doneIterFM) ( WordFM* fm );
 
 // Deep copy a FM.  If dopyK is NULL, keys are copied verbatim.
 // If non-null, dopyK is applied to each key to generate the
@@ -123,7 +123,7 @@ void HG_(doneIterFM) ( WordFM* fm );
 // is non-NULL but the result is NULL, it is assumed that dopyK
 // could not allocate memory, in which case the copy is abandoned
 // and NULL is returned.  Ditto with dopyV for values.
-WordFM* HG_(dopyFM) ( WordFM* fm,
+WordFM* VG_(dopyFM) ( WordFM* fm,
                       UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) );
 
 //------------------------------------------------------------------//
@@ -139,46 +139,46 @@ WordFM* HG_(dopyFM) ( WordFM* fm,
 typedef  struct _WordBag  WordBag; /* opaque */
 
 /* Allocate and initialise a WordBag */
-WordBag* HG_(newBag) ( void* (*alloc_nofail)( SizeT ),
+WordBag* VG_(newBag) ( void* (*alloc_nofail)( SizeT ),
                        void  (*dealloc)(void*) );
 
 /* Free up the Bag. */
-void HG_(deleteBag) ( WordBag* );
+void VG_(deleteBag) ( WordBag* );
 
 /* Add a word. */
-void HG_(addToBag)( WordBag*, UWord );
+void VG_(addToBag)( WordBag*, UWord );
 
 /* Find out how many times the given word exists in the bag. */
-UWord HG_(elemBag) ( WordBag*, UWord );
+UWord VG_(elemBag) ( WordBag*, UWord );
 
 /* Delete a word from the bag. */
-Bool HG_(delFromBag)( WordBag*, UWord );
+Bool VG_(delFromBag)( WordBag*, UWord );
 
 /* Is the bag empty? */
-Bool HG_(isEmptyBag)( WordBag* );
+Bool VG_(isEmptyBag)( WordBag* );
 
 /* Does the bag have exactly one element? */
-Bool HG_(isSingletonTotalBag)( WordBag* );
+Bool VG_(isSingletonTotalBag)( WordBag* );
 
 /* Return an arbitrary element from the bag. */
-UWord HG_(anyElementOfBag)( WordBag* );
+UWord VG_(anyElementOfBag)( WordBag* );
 
 /* How many different / total elements are in the bag? */
-UWord HG_(sizeUniqueBag)( WordBag* ); /* fast */
-UWord HG_(sizeTotalBag)( WordBag* );  /* warning: slow */
+UWord VG_(sizeUniqueBag)( WordBag* ); /* fast */
+UWord VG_(sizeTotalBag)( WordBag* );  /* warning: slow */
 
 /* Iterating over the elements of a bag. */
-void HG_(initIterBag)( WordBag* );
-Bool HG_(nextIterBag)( WordBag*, /*OUT*/UWord* pVal, /*OUT*/UWord* pCount );
-void HG_(doneIterBag)( WordBag* );
+void VG_(initIterBag)( WordBag* );
+Bool VG_(nextIterBag)( WordBag*, /*OUT*/UWord* pVal, /*OUT*/UWord* pCount );
+void VG_(doneIterBag)( WordBag* );
 
 //------------------------------------------------------------------//
 //---             end WordBag (unboxed words only)               ---//
 //---                      Public interface                      ---//
 //------------------------------------------------------------------//
 
-#endif /* ! __HG_WORDFM_H */
+#endif /* ! __PUB_TOOL_WORDFM_H */
 
 /*--------------------------------------------------------------------*/
-/*--- end                                              hg_wordfm.h ---*/
+/*--- end                                        pub_tool_wordfm.h ---*/
 /*--------------------------------------------------------------------*/