OSDN Git Service

* gcc_release: Further update for SVN. Don't set EXPORTTAG or
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-operands.c
index d2a48bb..c902ff9 100644 (file)
@@ -15,8 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #include "config.h"
 #include "system.h"
@@ -26,14 +26,14 @@ Boston, MA 02111-1307, USA.  */
 #include "flags.h"
 #include "function.h"
 #include "diagnostic.h"
-#include "errors.h"
 #include "tree-flow.h"
 #include "tree-inline.h"
 #include "tree-pass.h"
 #include "ggc.h"
 #include "timevar.h"
-
+#include "toplev.h"
 #include "langhooks.h"
+#include "ipa-reference.h"
 
 /* This file contains the code required to manage the operands cache of the 
    SSA optimizer.  For every stmt, we maintain an operand cache in the stmt 
@@ -99,43 +99,34 @@ Boston, MA 02111-1307, USA.  */
    VUSE for 'b'.  */
 #define opf_no_vops    (1 << 2)
 
-/* This structure maintain a sorted list of operands which is created by
-   parse_ssa_operand.  */
-struct opbuild_list_d GTY (())
-{
-  varray_type vars;     /* The VAR_DECLS tree.  */
-  varray_type uid;      /* The sort value for virtual symbols.  */
-  varray_type next;     /* The next index in the sorted list.  */
-  int first;            /* First element in list.  */
-  unsigned num;                /* Number of elements.  */
-};
-                                                                                
-#define OPBUILD_LAST     -1
-                                                                                
+/* Operand is a "non-specific" kill for call-clobbers and such.  This is used
+   to distinguish "reset the world" events from explicit MODIFY_EXPRs.  */
+#define opf_non_specific  (1 << 3)
+
 
 /* Array for building all the def operands.  */
-static GTY (()) struct opbuild_list_d build_defs;
+static VEC(tree,heap) *build_defs;
 
 /* Array for building all the use operands.  */
-static GTY (()) struct opbuild_list_d build_uses;
+static VEC(tree,heap) *build_uses;
 
 /* Array for building all the v_may_def operands.  */
-static GTY (()) struct opbuild_list_d build_v_may_defs;
+static VEC(tree,heap) *build_v_may_defs;
 
 /* Array for building all the vuse operands.  */
-static GTY (()) struct opbuild_list_d build_vuses;
+static VEC(tree,heap) *build_vuses;
 
 /* Array for building all the v_must_def operands.  */
-static GTY (()) struct opbuild_list_d build_v_must_defs;
+static VEC(tree,heap) *build_v_must_defs;
 
 /* True if the operands for call clobbered vars are cached and valid.  */
 bool ssa_call_clobbered_cache_valid;
 bool ssa_ro_call_cache_valid;
 
 /* These arrays are the cached operand vectors for call clobbered calls.  */
-static GTY (()) varray_type clobbered_v_may_defs;
-static GTY (()) varray_type clobbered_vuses;
-static GTY (()) varray_type ro_call_vuses;
+static VEC(tree,heap) *clobbered_v_may_defs;
+static VEC(tree,heap) *clobbered_vuses;
+static VEC(tree,heap) *ro_call_vuses;
 static bool clobbered_aliased_loads;
 static bool clobbered_aliased_stores;
 static bool ro_call_aliased_loads;
@@ -144,16 +135,16 @@ static bool ops_active = false;
 static GTY (()) struct ssa_operand_memory_d *operand_memory = NULL;
 static unsigned operand_memory_index;
 
-static void note_addressable (tree, stmt_ann_t);
 static void get_expr_operands (tree, tree *, int);
 static void get_asm_expr_operands (tree);
 static void get_indirect_ref_operands (tree, tree, int);
+static void get_tmr_operands (tree, tree, int);
 static void get_call_expr_operands (tree, tree);
 static inline void append_def (tree *);
 static inline void append_use (tree *);
 static void append_v_may_def (tree);
 static void append_v_must_def (tree);
-static void add_call_clobber_ops (tree);
+static void add_call_clobber_ops (tree, tree);
 static void add_call_read_ops (tree);
 static void add_stmt_operand (tree *, stmt_ann_t, int);
 static void build_ssa_operands (tree stmt);
@@ -164,222 +155,65 @@ static vuse_optype_p free_vuses = NULL;
 static maydef_optype_p free_maydefs = NULL;
 static mustdef_optype_p free_mustdefs = NULL;
 
-/* Initialize a virtual operand build LIST called NAME with NUM elements.  */
-
-static inline void
-opbuild_initialize_virtual (struct  opbuild_list_d *list, int num, 
-                          const char *name)
-{
-  list->first = OPBUILD_LAST;
-  list->num = 0;
-  VARRAY_TREE_INIT (list->vars, num, name);
-  VARRAY_UINT_INIT (list->uid, num, "List UID");
-  VARRAY_INT_INIT (list->next, num, "List NEXT");
-}
-
-
-/* Initialize a real operand build LIST called NAME with NUM elements.  */
-
-static inline void
-opbuild_initialize_real (struct opbuild_list_d *list, int num, const char *name)
-{
-  list->first = OPBUILD_LAST;
-  list->num = 0;
-  VARRAY_TREE_PTR_INIT (list->vars, num, name);
-  VARRAY_INT_INIT (list->next, num, "List NEXT");
-  /* The UID field is not needed since we sort based on the pointer value.  */
-  list->uid = NULL;
-}
-
-
-/* Free memory used in virtual operand build object LIST.  */
-
-static inline void
-opbuild_free (struct opbuild_list_d *list)
-{
-  list->vars = NULL;
-  list->uid = NULL;
-  list->next = NULL;
-}
 
-
-/* Number of elements in an opbuild list.  */
+/* Return the DECL_UID of the base variable of T.  */
 
 static inline unsigned
-opbuild_num_elems (struct opbuild_list_d *list)
+get_name_decl (tree t)
 {
-  return list->num;
+  if (TREE_CODE (t) != SSA_NAME)
+    return DECL_UID (t);
+  else
+    return DECL_UID (SSA_NAME_VAR (t));
 }
 
+/* Comparison function for qsort used in operand_build_sort_virtual.  */
 
-/* Add VAR to the real operand list LIST, keeping it sorted and avoiding
-   duplicates.  The actual sort value is the tree pointer value.  */
-
-static inline void
-opbuild_append_real (struct opbuild_list_d *list, tree *var)
+static int
+operand_build_cmp (const void *p, const void *q)
 {
-  int index;
+  tree e1 = *((const tree *)p);
+  tree e2 = *((const tree *)q);
+  unsigned int u1,u2;
+
+  u1 = get_name_decl (e1);
+  u2 = get_name_decl (e2);
 
+  /* We want to sort in ascending order.  They can never be equal.  */
 #ifdef ENABLE_CHECKING
-  /* Ensure the real operand doesn't exist already.  */
-  for (index = list->first; 
-       index != OPBUILD_LAST; 
-       index = VARRAY_INT (list->next, index))
-    gcc_assert (VARRAY_TREE_PTR (list->vars, index) != var);
+  gcc_assert (u1 != u2);
 #endif
-
-  /* First item in the list.  */
-  index = VARRAY_ACTIVE_SIZE (list->vars);
-  if (index == 0)
-    list->first = index;
-  else
-    VARRAY_INT (list->next, index - 1) = index;
-  VARRAY_PUSH_INT (list->next, OPBUILD_LAST);
-  VARRAY_PUSH_TREE_PTR (list->vars, var);
-  list->num++;
+  return (u1 > u2 ? 1 : -1);
 }
 
-
-/* Add VAR to the virtual operand list LIST, keeping it sorted and avoiding
-   duplicates.  The actual sort value is the DECL UID of the base variable.  */
+/* Sort the virtual operands in LIST from lowest DECL_UID to highest.  */
 
 static inline void
-opbuild_append_virtual (struct opbuild_list_d *list, tree var)
+operand_build_sort_virtual (VEC(tree,heap) *list)
 {
-  int index, curr, last;
-  unsigned int var_uid;
-
-  if (TREE_CODE (var) != SSA_NAME)
-    var_uid = DECL_UID (var);
-  else
-    var_uid = DECL_UID (SSA_NAME_VAR (var));
-
-  index = VARRAY_ACTIVE_SIZE (list->vars);
-
-  if (index == 0)
+  int num = VEC_length (tree, list);
+  if (num < 2)
+    return;
+  if (num == 2)
     {
-      VARRAY_PUSH_TREE (list->vars, var);
-      VARRAY_PUSH_UINT (list->uid, var_uid);
-      VARRAY_PUSH_INT (list->next, OPBUILD_LAST);
-      list->first = 0;
-      list->num = 1;
+      if (get_name_decl (VEC_index (tree, list, 0)) 
+         > get_name_decl (VEC_index (tree, list, 1)))
+       {  
+         /* Swap elements if in the wrong order.  */
+         tree tmp = VEC_index (tree, list, 0);
+         VEC_replace (tree, list, 0, VEC_index (tree, list, 1));
+         VEC_replace (tree, list, 1, tmp);
+       }
       return;
     }
-
-  last = OPBUILD_LAST;
-  /* Find the correct spot in the sorted list.  */
-  for (curr = list->first; 
-       curr != OPBUILD_LAST; 
-       last = curr, curr = VARRAY_INT (list->next, curr))
-    {
-      if (VARRAY_UINT (list->uid, curr) > var_uid)
-        break;
-    }
-
-  if (last == OPBUILD_LAST)
-    {
-      /* First item in the list.  */
-      VARRAY_PUSH_INT (list->next, list->first);
-      list->first = index;
-    }
-  else
-    {
-      /* Don't enter duplicates at all.  */
-      if (VARRAY_UINT (list->uid, last) == var_uid)
-        return;
-      
-      VARRAY_PUSH_INT (list->next, VARRAY_INT (list->next, last));
-      VARRAY_INT (list->next, last) = index;
-    }
-  VARRAY_PUSH_TREE (list->vars, var);
-  VARRAY_PUSH_UINT (list->uid, var_uid);
-  list->num++;
+  /* There are 3 or more elements, call qsort.  */
+  qsort (VEC_address (tree, list), 
+        VEC_length (tree, list), 
+        sizeof (tree),
+        operand_build_cmp);
 }
 
 
-/*  Return the first element index in LIST.  OPBUILD_LAST means there are no 
-    more elements.  */
-
-static inline int
-opbuild_first (struct opbuild_list_d *list)
-{
-  if (list->num > 0)
-    return list->first;
-  else
-    return OPBUILD_LAST;
-}
-
-
-/* Return the next element after PREV in LIST.  */
-
-static inline int
-opbuild_next (struct opbuild_list_d *list, int prev)
-{
-  return VARRAY_INT (list->next, prev);
-}
-
-
-/* Return the real element at index ELEM in LIST.  */
-
-static inline tree *
-opbuild_elem_real (struct opbuild_list_d *list, int elem)
-{
-  return VARRAY_TREE_PTR (list->vars, elem);
-}
-
-
-/* Return the virtual element at index ELEM in LIST.  */
-
-static inline tree
-opbuild_elem_virtual (struct opbuild_list_d *list, int elem)
-{
-  return VARRAY_TREE (list->vars, elem);
-}
-
-
-/* Return the virtual element uid at index ELEM in LIST.  */
-static inline unsigned int
-opbuild_elem_uid (struct opbuild_list_d *list, int elem)
-{
-  return VARRAY_UINT (list->uid, elem);
-}
-
-
-/* Reset an operand build list.  */
-
-static inline void
-opbuild_clear (struct opbuild_list_d *list)
-{
-  list->first = OPBUILD_LAST;
-  VARRAY_POP_ALL (list->vars);
-  VARRAY_POP_ALL (list->next);
-  if (list->uid)
-    VARRAY_POP_ALL (list->uid);
-  list->num = 0;
-}
-
-
-/* Remove ELEM from LIST where PREV is the previous element.  Return the next 
-   element.  */
-
-static inline int 
-opbuild_remove_elem (struct opbuild_list_d *list, int elem, int prev)
-{
-  int ret;
-  if (prev != OPBUILD_LAST)
-    {
-      gcc_assert (VARRAY_INT (list->next, prev) == elem);
-      ret = VARRAY_INT (list->next, prev) = VARRAY_INT (list->next, elem);
-    }
-  else
-    {
-      gcc_assert (list->first == elem);
-      ret = list->first = VARRAY_INT (list->next, elem);
-    }
-  list->num--;
-  return ret;
-}
-
 
 /*  Return true if the ssa operands cache is active.  */
 
@@ -395,11 +229,12 @@ ssa_operands_active (void)
 void
 init_ssa_operands (void)
 {
-  opbuild_initialize_real (&build_defs, 5, "build defs");
-  opbuild_initialize_real (&build_uses, 10, "build uses");
-  opbuild_initialize_virtual (&build_vuses, 25, "build_vuses");
-  opbuild_initialize_virtual (&build_v_may_defs, 25, "build_v_may_defs");
-  opbuild_initialize_virtual (&build_v_must_defs, 25, "build_v_must_defs");
+  build_defs = VEC_alloc (tree, heap, 5);
+  build_uses = VEC_alloc (tree, heap, 10);
+  build_vuses = VEC_alloc (tree, heap, 25);
+  build_v_may_defs = VEC_alloc (tree, heap, 25);
+  build_v_must_defs = VEC_alloc (tree, heap, 25);
+
   gcc_assert (operand_memory == NULL);
   operand_memory_index = SSA_OPERAND_MEMORY_SIZE;
   ops_active = true;
@@ -412,11 +247,11 @@ void
 fini_ssa_operands (void)
 {
   struct ssa_operand_memory_d *ptr;
-  opbuild_free (&build_defs);
-  opbuild_free (&build_uses);
-  opbuild_free (&build_v_must_defs);
-  opbuild_free (&build_v_may_defs);
-  opbuild_free (&build_vuses);
+  VEC_free (tree, heap, build_defs);
+  VEC_free (tree, heap, build_uses);
+  VEC_free (tree, heap, build_v_must_defs);
+  VEC_free (tree, heap, build_v_may_defs);
+  VEC_free (tree, heap, build_vuses);
   free_defs = NULL;
   free_uses = NULL;
   free_vuses = NULL;
@@ -428,18 +263,9 @@ fini_ssa_operands (void)
       ggc_free (ptr);
     }
 
-  if (clobbered_v_may_defs)
-    {
-      ggc_free (clobbered_v_may_defs);
-      ggc_free (clobbered_vuses);
-      clobbered_v_may_defs = NULL;
-      clobbered_vuses = NULL;
-    }
-  if (ro_call_vuses)
-    {
-      ggc_free (ro_call_vuses);
-      ro_call_vuses = NULL;
-    }
+  VEC_free (tree, heap, clobbered_v_may_defs);
+  VEC_free (tree, heap, clobbered_vuses);
+  VEC_free (tree, heap, ro_call_vuses);
   ops_active = false;
 }
 
@@ -464,10 +290,10 @@ ssa_operand_alloc (unsigned size)
 }
 
 
-/* Make sure PTR is inn the correct immediate use list.  Since uses are simply
+/* Make sure PTR is in the correct immediate use list.  Since uses are simply
    pointers into the stmt TREE, there is no way of telling if anyone has
    changed what this pointer points to via TREE_OPERANDS (exp, 0) = <...>.
-   THe contents are different, but the the pointer is still the same.  This
+   The contents are different, but the pointer is still the same.  This
    routine will check to make sure PTR is in the correct list, and if it isn't
    put it in the correct list.  We cannot simply check the previous node 
    because all nodes in the same stmt might have be changed.  */
@@ -485,27 +311,12 @@ correct_use_link (use_operand_p ptr, tree stmt)
   prev = ptr->prev;
   if (prev)
     {
-      bool stmt_mod = true;
-      /* Find the first element which isn't a SAFE iterator, is in a different
-        stmt, and is not a a modified stmt,  That node is in the correct list,
-        see if we are too.  */
-
-      while (stmt_mod)
-       {
-         while (prev->stmt == stmt || prev->stmt == NULL)
-           prev = prev->prev;
-         if (prev->use == NULL)
-           stmt_mod = false;
-         else
-           if ((stmt_mod = stmt_modified_p (prev->stmt)))
-             prev = prev->prev;
-       }
+      /* Find the root element, making sure we skip any safe iterators.  */
+      while (prev->use != NULL || prev->stmt == NULL)
+       prev = prev->prev;
 
       /* Get the ssa_name of the list the node is in.  */
-      if (prev->use == NULL)
-       root = prev->stmt;
-      else
-       root = *(prev->use);
+      root = prev->stmt;
       /* If it's the right list, simply return.  */
       if (root == *(ptr->use))
        return;
@@ -516,9 +327,29 @@ correct_use_link (use_operand_p ptr, tree stmt)
 }
 
 
+/* This routine makes sure that PTR is in an immediate use list, and makes
+   sure the stmt pointer is set to the current stmt.  Virtual uses do not need
+   the overhead of correct_use_link since they cannot be directly manipulated
+   like a real use can be.  (They don't exist in the TREE_OPERAND nodes.)  */
+static inline void
+set_virtual_use_link (use_operand_p ptr, tree stmt)
+{
+  /*  Fold_stmt () may have changed the stmt pointers.  */
+  if (ptr->stmt != stmt)
+    ptr->stmt = stmt;
+
+  /* If this use isn't in a list, add it to the correct list.  */
+  if (!ptr->prev)
+    link_imm_use (ptr, *(ptr->use));
+}
+
+
+
 #define FINALIZE_OPBUILD               build_defs
-#define FINALIZE_OPBUILD_BASE(I)       opbuild_elem_real (&build_defs, (I))
-#define FINALIZE_OPBUILD_ELEM(I)       opbuild_elem_real (&build_defs, (I))
+#define FINALIZE_OPBUILD_BASE(I)       (tree *)VEC_index (tree,        \
+                                                          build_defs, (I))
+#define FINALIZE_OPBUILD_ELEM(I)       (tree *)VEC_index (tree,        \
+                                                          build_defs, (I))
 #define FINALIZE_FUNC                  finalize_ssa_def_ops
 #define FINALIZE_ALLOC                 alloc_def
 #define FINALIZE_FREE                  free_defs
@@ -537,7 +368,7 @@ correct_use_link (use_operand_p ptr, tree stmt)
 static void
 finalize_ssa_defs (tree stmt)
 {
-  unsigned int num = opbuild_num_elems (&build_defs);
+  unsigned int num = VEC_length (tree, build_defs);
   /* There should only be a single real definition per assignment.  */
   gcc_assert ((stmt && TREE_CODE (stmt) != MODIFY_EXPR) || num <= 1);
 
@@ -545,12 +376,14 @@ finalize_ssa_defs (tree stmt)
      find the elements at the beginning that are the same as the vector.  */
 
   finalize_ssa_def_ops (stmt);
-  opbuild_clear (&build_defs);
+  VEC_truncate (tree, build_defs, 0);
 }
 
 #define FINALIZE_OPBUILD       build_uses
-#define FINALIZE_OPBUILD_BASE(I)       opbuild_elem_real (&build_uses, (I))
-#define FINALIZE_OPBUILD_ELEM(I)       opbuild_elem_real (&build_uses, (I))
+#define FINALIZE_OPBUILD_BASE(I)       (tree *)VEC_index (tree,        \
+                                                          build_uses, (I))
+#define FINALIZE_OPBUILD_ELEM(I)       (tree *)VEC_index (tree,        \
+                                                          build_uses, (I))
 #define FINALIZE_FUNC          finalize_ssa_use_ops
 #define FINALIZE_ALLOC         alloc_use
 #define FINALIZE_FREE          free_uses
@@ -558,6 +391,7 @@ finalize_ssa_defs (tree stmt)
 #define FINALIZE_ELEM(PTR)     ((PTR)->use_ptr.use)
 #define FINALIZE_OPS           USE_OPS
 #define FINALIZE_USE_PTR(PTR)  USE_OP_PTR (PTR)
+#define FINALIZE_CORRECT_USE   correct_use_link
 #define FINALIZE_BASE(VAR)     VAR
 #define FINALIZE_BASE_TYPE     tree *
 #define FINALIZE_BASE_ZERO     NULL
@@ -575,25 +409,26 @@ finalize_ssa_uses (tree stmt)
 #ifdef ENABLE_CHECKING
   {
     unsigned x;
-    unsigned num = opbuild_num_elems (&build_uses);
+    unsigned num = VEC_length (tree, build_uses);
 
     /* If the pointer to the operand is the statement itself, something is
        wrong.  It means that we are pointing to a local variable (the 
        initial call to get_stmt_operands does not pass a pointer to a 
        statement).  */
     for (x = 0; x < num; x++)
-      gcc_assert (*(opbuild_elem_real (&build_uses, x)) != stmt);
+      gcc_assert (*((tree *)VEC_index (tree, build_uses, x)) != stmt);
   }
 #endif
   finalize_ssa_use_ops (stmt);
-  opbuild_clear (&build_uses);
+  VEC_truncate (tree, build_uses, 0);
 }
                                                                               
                                                                               
 /* Return a new v_may_def operand vector for STMT, comparing to OLD_OPS_P.  */                                                                                
 #define FINALIZE_OPBUILD       build_v_may_defs
-#define FINALIZE_OPBUILD_ELEM(I)       opbuild_elem_virtual (&build_v_may_defs, (I))
-#define FINALIZE_OPBUILD_BASE(I)       opbuild_elem_uid (&build_v_may_defs, (I))
+#define FINALIZE_OPBUILD_ELEM(I)       VEC_index (tree, build_v_may_defs, (I))
+#define FINALIZE_OPBUILD_BASE(I)       get_name_decl (VEC_index (tree, \
+                                                       build_v_may_defs, (I)))
 #define FINALIZE_FUNC          finalize_ssa_v_may_def_ops
 #define FINALIZE_ALLOC         alloc_maydef
 #define FINALIZE_FREE          free_maydefs
@@ -601,9 +436,9 @@ finalize_ssa_uses (tree stmt)
 #define FINALIZE_ELEM(PTR)     MAYDEF_RESULT (PTR)
 #define FINALIZE_OPS           MAYDEF_OPS
 #define FINALIZE_USE_PTR(PTR)  MAYDEF_OP_PTR (PTR)
+#define FINALIZE_CORRECT_USE   set_virtual_use_link
 #define FINALIZE_BASE_ZERO     0
-#define FINALIZE_BASE(VAR)     ((TREE_CODE (VAR) == SSA_NAME)          \
-                               ? DECL_UID (SSA_NAME_VAR (VAR)) : DECL_UID ((VAR)))
+#define FINALIZE_BASE(VAR)     get_name_decl (VAR)
 #define FINALIZE_BASE_TYPE     unsigned
 #define FINALIZE_INITIALIZE(PTR, VAL, STMT)                            \
                                (PTR)->def_var = (VAL);                 \
@@ -627,24 +462,25 @@ static inline void
 cleanup_v_may_defs (void)
 {
   unsigned x, num;
-  num = opbuild_num_elems (&build_v_may_defs);
+  num = VEC_length (tree, build_v_may_defs);
 
   for (x = 0; x < num; x++)
     {
-      tree t = opbuild_elem_virtual (&build_v_may_defs, x);
+      tree t = VEC_index (tree, build_v_may_defs, x);
       if (TREE_CODE (t) != SSA_NAME)
        {
          var_ann_t ann = var_ann (t);
          ann->in_v_may_def_list = 0;
        }
     }
-  opbuild_clear (&build_v_may_defs);
+  VEC_truncate (tree, build_v_may_defs, 0);
 }                                                                             
 
                                                                               
 #define FINALIZE_OPBUILD       build_vuses
-#define FINALIZE_OPBUILD_ELEM(I)       opbuild_elem_virtual (&build_vuses, (I))
-#define FINALIZE_OPBUILD_BASE(I)       opbuild_elem_uid (&build_vuses, (I))
+#define FINALIZE_OPBUILD_ELEM(I)       VEC_index (tree, build_vuses, (I))
+#define FINALIZE_OPBUILD_BASE(I)       get_name_decl (VEC_index (tree, \
+                                                       build_vuses, (I)))
 #define FINALIZE_FUNC          finalize_ssa_vuse_ops
 #define FINALIZE_ALLOC         alloc_vuse
 #define FINALIZE_FREE          free_vuses
@@ -652,9 +488,9 @@ cleanup_v_may_defs (void)
 #define FINALIZE_ELEM(PTR)     VUSE_OP (PTR)
 #define FINALIZE_OPS           VUSE_OPS
 #define FINALIZE_USE_PTR(PTR)  VUSE_OP_PTR (PTR)
+#define FINALIZE_CORRECT_USE   set_virtual_use_link
 #define FINALIZE_BASE_ZERO     0
-#define FINALIZE_BASE(VAR)     ((TREE_CODE (VAR) == SSA_NAME)          \
-                               ? DECL_UID (SSA_NAME_VAR (VAR)) : DECL_UID ((VAR)))
+#define FINALIZE_BASE(VAR)     get_name_decl (VAR)
 #define FINALIZE_BASE_TYPE     unsigned
 #define FINALIZE_INITIALIZE(PTR, VAL, STMT)                            \
                                (PTR)->use_var = (VAL);                 \
@@ -670,7 +506,7 @@ static void
 finalize_ssa_vuses (tree stmt)
 {
   unsigned num, num_v_may_defs;
-  int vuse_index;
+  unsigned vuse_index;
 
   /* Remove superfluous VUSE operands.  If the statement already has a
    V_MAY_DEF operation for a variable 'a', then a VUSE for 'a' is not
@@ -684,39 +520,35 @@ finalize_ssa_vuses (tree stmt)
   The VUSE <a_2> is superfluous because it is implied by the V_MAY_DEF
   operation.  */
 
-  num = opbuild_num_elems (&build_vuses);
-  num_v_may_defs = opbuild_num_elems (&build_v_may_defs);
+  num = VEC_length (tree, build_vuses);
+  num_v_may_defs = VEC_length (tree, build_v_may_defs);
 
   if (num > 0 && num_v_may_defs > 0)
     {
-      int last = OPBUILD_LAST;
-      vuse_index = opbuild_first (&build_vuses);
-      for ( ; vuse_index != OPBUILD_LAST; )
+      for (vuse_index = 0; vuse_index < VEC_length (tree, build_vuses); )
         {
          tree vuse;
-         vuse = opbuild_elem_virtual (&build_vuses, vuse_index);
+         vuse = VEC_index (tree, build_vuses, vuse_index);
          if (TREE_CODE (vuse) != SSA_NAME)
            {
              var_ann_t ann = var_ann (vuse);
              ann->in_vuse_list = 0;
              if (ann->in_v_may_def_list)
                {
-                 vuse_index = opbuild_remove_elem (&build_vuses, vuse_index, 
-                                                   last);
+                 VEC_ordered_remove (tree, build_vuses, vuse_index);
                  continue;
                }
            }
-         last = vuse_index;
-         vuse_index = opbuild_next (&build_vuses, vuse_index);
+         vuse_index++;
        }
     }
   else
     /* Clear out the in_list bits.  */
-    for (vuse_index = opbuild_first (&build_vuses);
-        vuse_index != OPBUILD_LAST;
-        vuse_index = opbuild_next (&build_vuses, vuse_index))
+    for (vuse_index = 0;
+        vuse_index < VEC_length (tree, build_vuses);
+        vuse_index++)
       {
-       tree t = opbuild_elem_virtual (&build_vuses, vuse_index);
+       tree t = VEC_index (tree, build_vuses, vuse_index);
        if (TREE_CODE (t) != SSA_NAME)
          {
            var_ann_t ann = var_ann (t);
@@ -729,15 +561,16 @@ finalize_ssa_vuses (tree stmt)
   cleanup_v_may_defs ();
                                                                               
   /* Free the vuses build vector.  */
-  opbuild_clear (&build_vuses);
+  VEC_truncate (tree, build_vuses, 0);
 
 }
                                                                               
 /* Return a new v_must_def operand vector for STMT, comparing to OLD_OPS_P.  */
                                                                               
 #define FINALIZE_OPBUILD       build_v_must_defs
-#define FINALIZE_OPBUILD_ELEM(I)       opbuild_elem_virtual (&build_v_must_defs, (I))
-#define FINALIZE_OPBUILD_BASE(I)       opbuild_elem_uid (&build_v_must_defs, (I))
+#define FINALIZE_OPBUILD_ELEM(I)       VEC_index (tree, build_v_must_defs, (I))
+#define FINALIZE_OPBUILD_BASE(I)       get_name_decl (VEC_index (tree, \
+                                                       build_v_must_defs, (I)))
 #define FINALIZE_FUNC          finalize_ssa_v_must_def_ops
 #define FINALIZE_ALLOC         alloc_mustdef
 #define FINALIZE_FREE          free_mustdefs
@@ -745,9 +578,9 @@ finalize_ssa_vuses (tree stmt)
 #define FINALIZE_ELEM(PTR)     MUSTDEF_RESULT (PTR)
 #define FINALIZE_OPS           MUSTDEF_OPS
 #define FINALIZE_USE_PTR(PTR)  MUSTDEF_KILL_PTR (PTR)
+#define FINALIZE_CORRECT_USE   set_virtual_use_link
 #define FINALIZE_BASE_ZERO     0
-#define FINALIZE_BASE(VAR)     ((TREE_CODE (VAR) == SSA_NAME)          \
-                               ? DECL_UID (SSA_NAME_VAR (VAR)) : DECL_UID ((VAR)))
+#define FINALIZE_BASE(VAR)     get_name_decl (VAR)
 #define FINALIZE_BASE_TYPE     unsigned
 #define FINALIZE_INITIALIZE(PTR, VAL, STMT)                            \
                                (PTR)->def_var = (VAL);                 \
@@ -768,7 +601,7 @@ finalize_ssa_v_must_defs (tree stmt)
      having subvars, and have num >1, you have hit a bug. */
 
   finalize_ssa_v_must_def_ops (stmt);
-  opbuild_clear (&build_v_must_defs);
+  VEC_truncate (tree, build_v_must_defs, 0);
 }
 
 
@@ -790,11 +623,11 @@ finalize_ssa_stmt_operands (tree stmt)
 static inline void
 start_ssa_stmt_operands (void)
 {
-  gcc_assert (opbuild_num_elems (&build_defs) == 0);
-  gcc_assert (opbuild_num_elems (&build_uses) == 0);
-  gcc_assert (opbuild_num_elems (&build_vuses) == 0);
-  gcc_assert (opbuild_num_elems (&build_v_may_defs) == 0);
-  gcc_assert (opbuild_num_elems (&build_v_must_defs) == 0);
+  gcc_assert (VEC_length (tree, build_defs) == 0);
+  gcc_assert (VEC_length (tree, build_uses) == 0);
+  gcc_assert (VEC_length (tree, build_vuses) == 0);
+  gcc_assert (VEC_length (tree, build_v_may_defs) == 0);
+  gcc_assert (VEC_length (tree, build_v_must_defs) == 0);
 }
 
 
@@ -803,7 +636,7 @@ start_ssa_stmt_operands (void)
 static inline void
 append_def (tree *def_p)
 {
-  opbuild_append_real (&build_defs, def_p);
+  VEC_safe_push (tree, heap, build_defs, (tree)def_p);
 }
 
 
@@ -812,7 +645,7 @@ append_def (tree *def_p)
 static inline void
 append_use (tree *use_p)
 {
-  opbuild_append_real (&build_uses, use_p);
+  VEC_safe_push (tree, heap, build_uses, (tree)use_p);
 }
 
 
@@ -831,7 +664,7 @@ append_v_may_def (tree var)
       ann->in_v_may_def_list = 1;
     }
 
-  opbuild_append_virtual (&build_v_may_defs, var);
+  VEC_safe_push (tree, heap, build_v_may_defs, (tree)var);
 }
 
 
@@ -851,7 +684,7 @@ append_vuse (tree var)
       ann->in_vuse_list = 1;
     }
 
-  opbuild_append_virtual (&build_vuses, var);
+  VEC_safe_push (tree, heap, build_vuses, (tree)var);
 }
 
 
@@ -863,11 +696,11 @@ append_v_must_def (tree var)
   unsigned i;
 
   /* Don't allow duplicate entries.  */
-  for (i = 0; i < opbuild_num_elems (&build_v_must_defs); i++)
-    if (var == opbuild_elem_virtual (&build_v_must_defs, i))
+  for (i = 0; i < VEC_length (tree, build_v_must_defs); i++)
+    if (var == VEC_index (tree, build_v_must_defs, i))
       return;
 
-  opbuild_append_virtual (&build_v_must_defs, var);
+  VEC_safe_push (tree, heap, build_v_must_defs, (tree)var);
 }
 
 
@@ -902,7 +735,8 @@ parse_ssa_operands (tree stmt)
        if (TREE_CODE (lhs) == VIEW_CONVERT_EXPR)
          lhs = TREE_OPERAND (lhs, 0);
 
-       if (TREE_CODE (lhs) != ARRAY_REF && TREE_CODE (lhs) != ARRAY_RANGE_REF
+       if (TREE_CODE (lhs) != ARRAY_REF
+           && TREE_CODE (lhs) != ARRAY_RANGE_REF
            && TREE_CODE (lhs) != BIT_FIELD_REF
            && TREE_CODE (lhs) != REALPART_EXPR
            && TREE_CODE (lhs) != IMAGPART_EXPR)
@@ -996,14 +830,16 @@ build_ssa_operands (tree stmt)
   start_ssa_stmt_operands ();
 
   parse_ssa_operands (stmt);
+  operand_build_sort_virtual (build_vuses);
+  operand_build_sort_virtual (build_v_may_defs);
+  operand_build_sort_virtual (build_v_must_defs);
 
   finalize_ssa_stmt_operands (stmt);
 }
 
 
 /* Free any operands vectors in OPS.  */
-#if 0
-static void 
+void 
 free_ssa_operands (stmt_operands_p ops)
 {
   ops->def_ops = NULL;
@@ -1011,14 +847,7 @@ free_ssa_operands (stmt_operands_p ops)
   ops->maydef_ops = NULL;
   ops->mustdef_ops = NULL;
   ops->vuse_ops = NULL;
-  while (ops->memory.next != NULL)
-    {
-      operand_memory_p tmp = ops->memory.next;
-      ops->memory.next = tmp->next;
-      ggc_free (tmp);
-    }
 }
-#endif
 
 
 /* Get the operands of statement STMT.  Note that repeated calls to
@@ -1072,9 +901,9 @@ copy_virtual_operands (tree dest, tree src)
   FOR_EACH_SSA_TREE_OPERAND (t, src, iter, SSA_OP_VMUSTDEF)
     append_v_must_def (t);
 
-  if (opbuild_num_elems (&build_vuses) == 0
-      && opbuild_num_elems (&build_v_may_defs) == 0
-      && opbuild_num_elems (&build_v_must_defs) == 0)
+  if (VEC_length (tree, build_vuses) == 0
+      && VEC_length (tree, build_v_may_defs) == 0
+      && VEC_length (tree, build_v_must_defs) == 0)
     return;
 
   /* Now commit the virtual operands to this stmt.  */
@@ -1138,9 +967,9 @@ create_ssa_artficial_load_stmt (tree new_stmt, tree old_stmt)
   start_ssa_stmt_operands ();
   parse_ssa_operands (new_stmt);
 
-  for (x = 0; x < opbuild_num_elems (&build_vuses); x++)
+  for (x = 0; x < VEC_length (tree, build_vuses); x++)
     {
-      tree t = opbuild_elem_virtual (&build_vuses, x);
+      tree t = VEC_index (tree, build_vuses, x);
       if (TREE_CODE (t) != SSA_NAME)
        {
          var_ann_t ann = var_ann (t);
@@ -1148,9 +977,9 @@ create_ssa_artficial_load_stmt (tree new_stmt, tree old_stmt)
        }
     }
    
-  for (x = 0; x < opbuild_num_elems (&build_v_may_defs); x++)
+  for (x = 0; x < VEC_length (tree, build_v_may_defs); x++)
     {
-      tree t = opbuild_elem_virtual (&build_v_may_defs, x);
+      tree t = VEC_index (tree, build_v_may_defs, x);
       if (TREE_CODE (t) != SSA_NAME)
        {
          var_ann_t ann = var_ann (t);
@@ -1158,9 +987,9 @@ create_ssa_artficial_load_stmt (tree new_stmt, tree old_stmt)
        }
     }
   /* Remove any virtual operands that were found.  */
-  opbuild_clear (&build_v_may_defs);
-  opbuild_clear (&build_v_must_defs);
-  opbuild_clear (&build_vuses);
+  VEC_truncate (tree, build_v_may_defs, 0);
+  VEC_truncate (tree, build_v_must_defs, 0);
+  VEC_truncate (tree, build_vuses, 0);
 
   /* For each VDEF on the original statement, we want to create a
      VUSE of the V_MAY_DEF result or V_MUST_DEF op on the new 
@@ -1177,7 +1006,7 @@ create_ssa_artficial_load_stmt (tree new_stmt, tree old_stmt)
     delink_imm_use (use_p);
 }
 
-static void
+void
 swap_tree_operands (tree stmt, tree *exp0, tree *exp1)
 {
   tree op0, op1;
@@ -1219,9 +1048,9 @@ swap_tree_operands (tree stmt, tree *exp0, tree *exp1)
 }
 
 
-/* Recursively scan the expression pointed by EXPR_P in statement referred to
-   by INFO.  FLAGS is one of the OPF_* constants modifying how to interpret the
-   operands found.  */
+/* Recursively scan the expression pointed to by EXPR_P in statement referred
+   to by INFO.  FLAGS is one of the OPF_* constants modifying how to interpret
+   the operands found.  */
 
 static void
 get_expr_operands (tree stmt, tree *expr_p, int flags)
@@ -1294,6 +1123,10 @@ get_expr_operands (tree stmt, tree *expr_p, int flags)
       get_indirect_ref_operands (stmt, expr, flags);
       return;
 
+    case TARGET_MEM_REF:
+      get_tmr_operands (stmt, expr, flags);
+      return;
+
     case ARRAY_REF:
     case ARRAY_RANGE_REF:
       /* Treat array references as references to the virtual variable
@@ -1318,7 +1151,7 @@ get_expr_operands (tree stmt, tree *expr_p, int flags)
     case IMAGPART_EXPR:
       {
        tree ref;
-       HOST_WIDE_INT offset, size;
+       unsigned HOST_WIDE_INT offset, size;
        /* This component ref becomes an access to all of the subvariables
           it can touch,  if we can determine that, but *NOT* the real one.
           If we can't determine which fields we could touch, the recursion
@@ -1335,9 +1168,10 @@ get_expr_operands (tree stmt, tree *expr_p, int flags)
                bool exact;             
                if (overlap_subvar (offset, size, sv, &exact))
                  {
-                   if (exact)
-                     flags &= ~opf_kill_def;
-                   add_stmt_operand (&sv->var, s_ann, flags);
+                   int subvar_flags = flags;
+                   if (!exact)
+                     subvar_flags &= ~opf_kill_def;
+                   add_stmt_operand (&sv->var, s_ann, subvar_flags);
                  }
              }
          }
@@ -1346,7 +1180,11 @@ get_expr_operands (tree stmt, tree *expr_p, int flags)
                             flags & ~opf_kill_def);
        
        if (code == COMPONENT_REF)
-         get_expr_operands (stmt, &TREE_OPERAND (expr, 2), opf_none);
+         {
+           if (s_ann && TREE_THIS_VOLATILE (TREE_OPERAND (expr, 1)))
+             s_ann->has_volatile_ops = true; 
+           get_expr_operands (stmt, &TREE_OPERAND (expr, 2), opf_none);
+         }
        return;
       }
     case WITH_SIZE_EXPR:
@@ -1393,10 +1231,13 @@ get_expr_operands (tree stmt, tree *expr_p, int flags)
       {
        /* General aggregate CONSTRUCTORs have been decomposed, but they
           are still in use as the COMPLEX_EXPR equivalent for vectors.  */
+       constructor_elt *ce;
+       unsigned HOST_WIDE_INT idx;
 
-       tree t;
-       for (t = TREE_OPERAND (expr, 0); t ; t = TREE_CHAIN (t))
-         get_expr_operands (stmt, &TREE_VALUE (t), opf_none);
+       for (idx = 0;
+            VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (expr), idx, ce);
+            idx++)
+         get_expr_operands (stmt, &ce->value, opf_none);
 
        return;
       }
@@ -1519,8 +1360,8 @@ get_asm_expr_operands (tree stmt)
       if (!allows_reg && allows_mem)
        {
          tree t = get_base_address (TREE_VALUE (link));
-         if (t && DECL_P (t))
-           note_addressable (t, s_ann);
+         if (t && DECL_P (t) && s_ann)
+           add_to_addressable_set (t, &s_ann->addresses_taken);
        }
 
       get_expr_operands (stmt, &TREE_VALUE (link), opf_is_def);
@@ -1538,8 +1379,8 @@ get_asm_expr_operands (tree stmt)
       if (!allows_reg && allows_mem)
        {
          tree t = get_base_address (TREE_VALUE (link));
-         if (t && DECL_P (t))
-           note_addressable (t, s_ann);
+         if (t && DECL_P (t) && s_ann)
+           add_to_addressable_set (t, &s_ann->addresses_taken);
        }
 
       get_expr_operands (stmt, &TREE_VALUE (link), 0);
@@ -1559,10 +1400,10 @@ get_asm_expr_operands (tree stmt)
          add_stmt_operand (&global_var, s_ann, opf_is_def);
        else
          EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, i, bi)
-             {
-               tree var = referenced_var (i);
-               add_stmt_operand (&var, s_ann, opf_is_def);
-             }
+           {
+             tree var = referenced_var (i);
+             add_stmt_operand (&var, s_ann, opf_is_def | opf_non_specific);
+           }
 
        /* Now clobber all addressables.  */
        EXECUTE_IF_SET_IN_BITMAP (addressable_vars, 0, i, bi)
@@ -1579,7 +1420,7 @@ get_asm_expr_operands (tree stmt)
                  && get_subvars_for_var (var) != NULL)
                continue;               
 
-             add_stmt_operand (&var, s_ann, opf_is_def);
+             add_stmt_operand (&var, s_ann, opf_is_def | opf_non_specific);
            }
 
        break;
@@ -1677,6 +1518,33 @@ get_indirect_ref_operands (tree stmt, tree expr, int flags)
   get_expr_operands (stmt, pptr, opf_none);
 }
 
+/* A subroutine of get_expr_operands to handle TARGET_MEM_REF.  */
+
+static void
+get_tmr_operands (tree stmt, tree expr, int flags)
+{
+  tree tag = TMR_TAG (expr);
+
+  /* First record the real operands.  */
+  get_expr_operands (stmt, &TMR_BASE (expr), opf_none);
+  get_expr_operands (stmt, &TMR_INDEX (expr), opf_none);
+
+  /* MEM_REFs should never be killing.  */
+  flags &= ~opf_kill_def;
+
+  if (TMR_SYMBOL (expr))
+    {
+      stmt_ann_t ann = stmt_ann (stmt);
+      add_to_addressable_set (TMR_SYMBOL (expr), &ann->addresses_taken);
+    }
+
+  if (tag)
+    get_expr_operands (stmt, &tag, flags);
+  else
+    /* Something weird, so ensure that we will be careful.  */
+    stmt_ann (stmt)->has_volatile_ops = true;
+}
+
 /* A subroutine of get_expr_operands to handle CALL_EXPR.  */
 
 static void
@@ -1704,7 +1572,7 @@ get_call_expr_operands (tree stmt, tree expr)
         there is no point in recording that.  */ 
       if (TREE_SIDE_EFFECTS (expr)
          && !(call_flags & (ECF_PURE | ECF_CONST | ECF_NORETURN)))
-       add_call_clobber_ops (stmt);
+       add_call_clobber_ops (stmt, get_callee_fndecl (expr));
       else if (!(call_flags & ECF_CONST))
        add_call_read_ops (stmt);
     }
@@ -1737,9 +1605,9 @@ add_stmt_operand (tree *var_p, stmt_ann_t s_ann, int flags)
 
   /* If the operand is an ADDR_EXPR, add its operand to the list of
      variables that have had their address taken in this statement.  */
-  if (TREE_CODE (var) == ADDR_EXPR)
+  if (TREE_CODE (var) == ADDR_EXPR && s_ann)
     {
-      note_addressable (TREE_OPERAND (var, 0), s_ann);
+      add_to_addressable_set (TREE_OPERAND (var, 0), &s_ann->addresses_taken);
       return;
     }
 
@@ -1764,20 +1632,21 @@ add_stmt_operand (tree *var_p, stmt_ann_t s_ann, int flags)
 
   /* If the variable cannot be modified and this is a V_MAY_DEF change
      it into a VUSE.  This happens when read-only variables are marked
-     call-clobbered and/or aliased to writeable variables.  So we only
-     check that this only happens on stores, and not writes to GIMPLE
-     registers.
-     
-     FIXME: The C++ FE is emitting assignments in the IL stream for
-     read-only globals.  This is wrong, but for the time being disable
-     this transformation on V_MUST_DEF operands (otherwise, we
-     mis-optimize SPEC2000's eon).  */
-  if ((flags & opf_is_def)
-      && !(flags & opf_kill_def)
-      && unmodifiable_var_p (var))
+     call-clobbered and/or aliased to writable variables.  So we only
+     check that this only happens on non-specific stores.
+
+     Note that if this is a specific store, i.e. associated with a
+     modify_expr, then we can't suppress the V_DEF, lest we run into
+     validation problems.
+
+     This can happen when programs cast away const, leaving us with a
+     store to read-only memory.  If the statement is actually executed
+     at runtime, then the program is ill formed.  If the statement is
+     not executed then all is well.  At the very least, we cannot ICE.  */
+  if ((flags & opf_non_specific) && unmodifiable_var_p (var))
     {
       gcc_assert (!is_real_op);
-      flags &= ~opf_is_def;
+      flags &= ~(opf_is_def | opf_kill_def);
     }
 
   if (is_real_op)
@@ -1840,35 +1709,17 @@ add_stmt_operand (tree *var_p, stmt_ann_t s_ann, int flags)
 
          if (flags & opf_is_def)
            {
-             bool added_may_defs_p = false;
-
              /* If the variable is also an alias tag, add a virtual
                 operand for it, otherwise we will miss representing
                 references to the members of the variable's alias set.
                 This fixes the bug in gcc.c-torture/execute/20020503-1.c.  */
              if (v_ann->is_alias_tag)
-               {
-                 added_may_defs_p = true;
-                 append_v_may_def (var);
-               }
+               append_v_may_def (var);
 
              for (i = 0; i < VARRAY_ACTIVE_SIZE (aliases); i++)
-               {
-                 /* While VAR may be modifiable, some of its aliases
-                    may not be.  If that's the case, we don't really
-                    need to add them a V_MAY_DEF for them.  */
-                 tree alias = VARRAY_TREE (aliases, i);
-
-                 if (unmodifiable_var_p (alias))
-                   append_vuse (alias);
-                 else
-                   {
-                     append_v_may_def (alias);
-                     added_may_defs_p = true;
-                   }
-               }
+               append_v_may_def (VARRAY_TREE (aliases, i));
 
-             if (s_ann && added_may_defs_p)
+             if (s_ann)
                s_ann->makes_aliased_stores = 1;
            }
          else
@@ -1889,73 +1740,63 @@ add_stmt_operand (tree *var_p, stmt_ann_t s_ann, int flags)
 }
 
   
-/* Record that VAR had its address taken in the statement with annotations
-   S_ANN.  */
+/* Add the base address of REF to the set *ADDRESSES_TAKEN.  If
+   *ADDRESSES_TAKEN is NULL, a new set is created.  REF may be
+   a single variable whose address has been taken or any other valid
+   GIMPLE memory reference (structure reference, array, etc).  If the
+   base address of REF is a decl that has sub-variables, also add all
+   of its sub-variables.  */
 
-static void
-note_addressable (tree var, stmt_ann_t s_ann)
+void
+add_to_addressable_set (tree ref, bitmap *addresses_taken)
 {
-  tree ref;
+  tree var;
   subvar_t svars;
-  HOST_WIDE_INT offset;
-  HOST_WIDE_INT size;
 
-  if (!s_ann)
-    return;
-  
-  /* If this is a COMPONENT_REF, and we know exactly what it touches, we only
-     take the address of the subvariables it will touch.
-     Otherwise, we take the address of all the subvariables, plus the real
-     ones.  */
+  gcc_assert (addresses_taken);
 
-  if (var && TREE_CODE (var) == COMPONENT_REF 
-      && (ref = okay_component_ref_for_subvars (var, &offset, &size)))
-    {
-      subvar_t sv;
-      svars = get_subvars_for_var (ref);
-      
-      if (s_ann->addresses_taken == NULL)
-       s_ann->addresses_taken = BITMAP_GGC_ALLOC ();      
-      
-      for (sv = svars; sv; sv = sv->next)
-       {
-         if (overlap_subvar (offset, size, sv, NULL))
-           bitmap_set_bit (s_ann->addresses_taken, var_ann (sv->var)->uid);
-       }
-      return;
-    }
-  
-  var = get_base_address (var);
+  /* Note that it is *NOT OKAY* to use the target of a COMPONENT_REF
+     as the only thing we take the address of.  If VAR is a structure,
+     taking the address of a field means that the whole structure may
+     be referenced using pointer arithmetic.  See PR 21407 and the
+     ensuing mailing list discussion.  */
+  var = get_base_address (ref);
   if (var && SSA_VAR_P (var))
     {
-      if (s_ann->addresses_taken == NULL)
-       s_ann->addresses_taken = BITMAP_GGC_ALLOC ();      
+      if (*addresses_taken == NULL)
+       *addresses_taken = BITMAP_GGC_ALLOC ();      
       
-
       if (var_can_have_subvars (var)
          && (svars = get_subvars_for_var (var)))
        {
          subvar_t sv;
          for (sv = svars; sv; sv = sv->next)
-           bitmap_set_bit (s_ann->addresses_taken, var_ann (sv->var)->uid);
+           {
+             bitmap_set_bit (*addresses_taken, DECL_UID (sv->var));
+             TREE_ADDRESSABLE (sv->var) = 1;
+           }
        }
       else
-       bitmap_set_bit (s_ann->addresses_taken, var_ann (var)->uid);
+       {
+         bitmap_set_bit (*addresses_taken, DECL_UID (var));
+         TREE_ADDRESSABLE (var) = 1;
+       }
     }
 }
 
+
 /* Add clobbering definitions for .GLOBAL_VAR or for each of the call
    clobbered variables in the function.  */
 
 static void
-add_call_clobber_ops (tree stmt)
+add_call_clobber_ops (tree stmt, tree callee)
 {
-  int i;
   unsigned u;
   tree t;
   bitmap_iterator bi;
   stmt_ann_t s_ann = stmt_ann (stmt);
   struct stmt_ann_d empty_ann;
+  bitmap not_read_b, not_written_b;
 
   /* Functions that are not const, pure or never return may clobber
      call-clobbered variables.  */
@@ -1970,24 +1811,36 @@ add_call_clobber_ops (tree stmt)
       return;
     }
 
+  /* FIXME - if we have better information from the static vars
+     analysis, we need to make the cache call site specific.  This way
+     we can have the performance benefits even if we are doing good
+     optimization.  */
+
+  /* Get info for local and module level statics.  There is a bit
+     set for each static if the call being processed does not read
+     or write that variable.  */
+
+  not_read_b = callee ? ipa_reference_get_not_read_global (callee) : NULL; 
+  not_written_b = callee ? ipa_reference_get_not_written_global (callee) : NULL; 
+
   /* If cache is valid, copy the elements into the build vectors.  */
-  if (ssa_call_clobbered_cache_valid)
+  if (ssa_call_clobbered_cache_valid
+      && (!not_read_b || bitmap_empty_p (not_read_b))
+      && (!not_written_b || bitmap_empty_p (not_written_b)))
     {
-      /* Process the caches in reverse order so we are always inserting at
-         the head of the list.  */
-      for (i = VARRAY_ACTIVE_SIZE (clobbered_vuses) - 1; i >=0; i--)
+      for (u = 0 ; u < VEC_length (tree, clobbered_vuses); u++)
        {
-         t = VARRAY_TREE (clobbered_vuses, i);
+         t = VEC_index (tree, clobbered_vuses, u);
          gcc_assert (TREE_CODE (t) != SSA_NAME);
          var_ann (t)->in_vuse_list = 1;
-         opbuild_append_virtual (&build_vuses, t);
+         VEC_safe_push (tree, heap, build_vuses, (tree)t);
        }
-      for (i = VARRAY_ACTIVE_SIZE (clobbered_v_may_defs) - 1; i >= 0; i--)
+      for (u = 0; u < VEC_length (tree, clobbered_v_may_defs); u++)
        {
-         t = VARRAY_TREE (clobbered_v_may_defs, i);
+         t = VEC_index (tree, clobbered_v_may_defs, u);
          gcc_assert (TREE_CODE (t) != SSA_NAME);
          var_ann (t)->in_v_may_def_list = 1;
-         opbuild_append_virtual (&build_v_may_defs, t);
+         VEC_safe_push (tree, heap, build_v_may_defs, (tree)t);
        }
       if (s_ann)
        {
@@ -2006,50 +1859,58 @@ add_call_clobber_ops (tree stmt)
       if (unmodifiable_var_p (var))
        add_stmt_operand (&var, &empty_ann, opf_none);
       else
-       add_stmt_operand (&var, &empty_ann, opf_is_def);
+       {
+         bool not_read
+           = not_read_b ? bitmap_bit_p (not_read_b, u) : false;
+         bool not_written
+           = not_written_b ? bitmap_bit_p (not_written_b, u) : false;
+
+         if ((TREE_READONLY (var)
+              && (TREE_STATIC (var) || DECL_EXTERNAL (var)))
+             || not_written)
+           {
+             if (!not_read)
+               add_stmt_operand (&var, &empty_ann, opf_none);
+           }
+         else
+           add_stmt_operand (&var, &empty_ann, opf_is_def);
+       }
     }
 
-  clobbered_aliased_loads = empty_ann.makes_aliased_loads;
-  clobbered_aliased_stores = empty_ann.makes_aliased_stores;
-
-  /* Set the flags for a stmt's annotation.  */
-  if (s_ann)
+  if ((!not_read_b || bitmap_empty_p (not_read_b))
+      && (!not_written_b || bitmap_empty_p (not_written_b)))
     {
-      s_ann->makes_aliased_loads = empty_ann.makes_aliased_loads;
-      s_ann->makes_aliased_stores = empty_ann.makes_aliased_stores;
-    }
+      clobbered_aliased_loads = empty_ann.makes_aliased_loads;
+      clobbered_aliased_stores = empty_ann.makes_aliased_stores;
 
-  /* Prepare empty cache vectors.  */
-  if (clobbered_v_may_defs)
-    {
-      VARRAY_POP_ALL (clobbered_vuses);
-      VARRAY_POP_ALL (clobbered_v_may_defs);
-    }
-  else
-    {
-      VARRAY_TREE_INIT (clobbered_v_may_defs, 10, "clobbered_v_may_defs");
-      VARRAY_TREE_INIT (clobbered_vuses, 10, "clobbered_vuses");
-    }
+      /* Set the flags for a stmt's annotation.  */
+      if (s_ann)
+       {
+         s_ann->makes_aliased_loads = empty_ann.makes_aliased_loads;
+         s_ann->makes_aliased_stores = empty_ann.makes_aliased_stores;
+       }
 
-  /* Now fill the clobbered cache with the values that have been found.  */
-  for (i = opbuild_first (&build_vuses);
-       i != OPBUILD_LAST;
-       i = opbuild_next (&build_vuses, i))
-    VARRAY_PUSH_TREE (clobbered_vuses, opbuild_elem_virtual (&build_vuses, i));
+      /* Prepare empty cache vectors.  */
+      VEC_truncate (tree, clobbered_vuses, 0);
+      VEC_truncate (tree, clobbered_v_may_defs, 0);
 
-  gcc_assert (opbuild_num_elems (&build_vuses) 
-             == VARRAY_ACTIVE_SIZE (clobbered_vuses));
+      /* Now fill the clobbered cache with the values that have been found.  */
+      for (u = 0; u < VEC_length (tree, build_vuses); u++)
+       VEC_safe_push (tree, heap, clobbered_vuses,
+                      VEC_index (tree, build_vuses, u));
 
-  for (i = opbuild_first (&build_v_may_defs);
-       i != OPBUILD_LAST;
-       i = opbuild_next (&build_v_may_defs, i))
-    VARRAY_PUSH_TREE (clobbered_v_may_defs, 
-                     opbuild_elem_virtual (&build_v_may_defs, i));
+      gcc_assert (VEC_length (tree, build_vuses) 
+                 == VEC_length (tree, clobbered_vuses));
 
-  gcc_assert (opbuild_num_elems (&build_v_may_defs) 
-             == VARRAY_ACTIVE_SIZE (clobbered_v_may_defs));
+      for (u = 0; u < VEC_length (tree, build_v_may_defs); u++)
+       VEC_safe_push (tree, heap, clobbered_v_may_defs, 
+                      VEC_index (tree, build_v_may_defs, u));
 
-  ssa_call_clobbered_cache_valid = true;
+      gcc_assert (VEC_length (tree, build_v_may_defs) 
+                 == VEC_length (tree, clobbered_v_may_defs));
+
+      ssa_call_clobbered_cache_valid = true;
+    }
 }
 
 
@@ -2059,7 +1920,6 @@ add_call_clobber_ops (tree stmt)
 static void
 add_call_read_ops (tree stmt)
 {
-  int i;
   unsigned u;
   tree t;
   bitmap_iterator bi;
@@ -2078,14 +1938,12 @@ add_call_read_ops (tree stmt)
   /* If cache is valid, copy the elements into the build vector.  */
   if (ssa_ro_call_cache_valid)
     {
-      for (i = VARRAY_ACTIVE_SIZE (ro_call_vuses) - 1; i >=0 ; i--)
+      for (u = 0; u < VEC_length (tree, ro_call_vuses); u++)
        {
-         /* Process the caches in reverse order so we are always inserting at
-            the head of the list.  */
-         t = VARRAY_TREE (ro_call_vuses, i);
+         t = VEC_index (tree, ro_call_vuses, u);
          gcc_assert (TREE_CODE (t) != SSA_NAME);
          var_ann (t)->in_vuse_list = 1;
-         opbuild_append_virtual (&build_vuses, t);
+         VEC_safe_push (tree, heap, build_vuses, (tree)t);
        }
       if (s_ann)
        s_ann->makes_aliased_loads = ro_call_aliased_loads;
@@ -2098,7 +1956,7 @@ add_call_read_ops (tree stmt)
   EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, u, bi)
     {
       tree var = referenced_var (u);
-      add_stmt_operand (&var, &empty_ann, opf_none);
+      add_stmt_operand (&var, &empty_ann, opf_none | opf_non_specific);
     }
 
   ro_call_aliased_loads = empty_ann.makes_aliased_loads;
@@ -2106,20 +1964,15 @@ add_call_read_ops (tree stmt)
     s_ann->makes_aliased_loads = empty_ann.makes_aliased_loads;
 
   /* Prepare empty cache vectors.  */
-  if (ro_call_vuses)
-    VARRAY_POP_ALL (ro_call_vuses);
-  else
-    VARRAY_TREE_INIT (ro_call_vuses, 10, "ro_call_vuses");
-
+  VEC_truncate (tree, ro_call_vuses, 0);
 
   /* Now fill the clobbered cache with the values that have been found.  */
-  for (i = opbuild_first (&build_vuses);
-       i != OPBUILD_LAST;
-       i = opbuild_next (&build_vuses, i))
-    VARRAY_PUSH_TREE (ro_call_vuses, opbuild_elem_virtual (&build_vuses, i));
+  for (u = 0; u <  VEC_length (tree, build_vuses); u++)
+    VEC_safe_push (tree, heap, ro_call_vuses,
+                  VEC_index (tree, build_vuses, u));
 
-  gcc_assert (opbuild_num_elems (&build_vuses) 
-             == VARRAY_ACTIVE_SIZE (ro_call_vuses));
+  gcc_assert (VEC_length (tree, build_vuses) 
+             == VEC_length (tree, ro_call_vuses));
 
   ssa_ro_call_cache_valid = true;
 }