OSDN Git Service

PR objc/43061
[pf3gnuchains/gcc-fork.git] / gcc / ipa-type-escape.c
index 2aedb95..8d773f1 100644 (file)
@@ -1,5 +1,6 @@
 /* Type based alias analysis.
-   Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation,
+   Inc.
    Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
 
 This file is part of GCC.
@@ -42,11 +43,11 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "langhooks.h"
 #include "pointer-set.h"
+#include "splay-tree.h"
 #include "ggc.h"
 #include "ipa-utils.h"
 #include "ipa-type-escape.h"
-#include "c-common.h"
-#include "tree-gimple.h"
+#include "gimple.h"
 #include "cgraph.h"
 #include "output.h"
 #include "flags.h"
@@ -89,7 +90,7 @@ enum escape_t
    previous cases above.  During the analysis phase, a bit is set in
    one of these vectors if an operation of the offending class is
    discovered to happen on the associated type.  */
+
 static bitmap global_types_exposed_parameter;
 static bitmap global_types_full_escape;
 
@@ -133,21 +134,21 @@ static struct pointer_set_t *visited_stmts;
 
 static bitmap_obstack ipa_obstack;
 
-/* Static functions from this file that are used 
+/* Static functions from this file that are used
    before being defined.  */
-static unsigned int look_for_casts (tree lhs ATTRIBUTE_UNUSED, tree);
-static bool is_cast_from_non_pointer (tree, tree, void *);
+static unsigned int look_for_casts (tree);
+static bool is_cast_from_non_pointer (tree, gimple, void *);
 
 /* Get the name of TYPE or return the string "<UNNAMED>".  */
 static const char*
 get_name_of_type (tree type)
 {
   tree name = TYPE_NAME (type);
-  
+
   if (!name)
     /* Unnamed type, do what you like here.  */
     return "<UNNAMED>";
-  
+
   /* It will be a TYPE_DECL in the case of a typedef, otherwise, an
      identifier_node */
   if (TREE_CODE (name) == TYPE_DECL)
@@ -163,11 +164,11 @@ get_name_of_type (tree type)
     }
   else if (TREE_CODE (name) == IDENTIFIER_NODE)
     return IDENTIFIER_POINTER (name);
-  else 
+  else
     return "<UNNAMED>";
 }
 
-struct type_brand_s 
+struct type_brand_s
 {
   const char* name;
   int seq;
@@ -175,7 +176,7 @@ struct type_brand_s
 
 /* Splay tree comparison function on type_brand_s structures.  */
 
-static int 
+static int
 compare_type_brand (splay_tree_key sk1, splay_tree_key sk2)
 {
   struct type_brand_s * k1 = (struct type_brand_s *) sk1;
@@ -184,7 +185,7 @@ compare_type_brand (splay_tree_key sk1, splay_tree_key sk2)
   int value = strcmp(k1->name, k2->name);
   if (value == 0)
     return k2->seq - k1->seq;
-  else 
+  else
     return value;
 }
 
@@ -280,7 +281,7 @@ type_to_consider (tree type)
     case VECTOR_TYPE:
     case VOID_TYPE:
       return true;
-  
+
     default:
       return false;
     }
@@ -290,7 +291,7 @@ type_to_consider (tree type)
    the POINTER_TOs and if SEE_THRU_ARRAYS is true, remove all of the
    ARRAY_OFs and POINTER_TOs.  */
 
-static tree 
+static tree
 get_canon_type (tree type, bool see_thru_ptrs, bool see_thru_arrays)
 {
   splay_tree_node result;
@@ -299,16 +300,16 @@ get_canon_type (tree type, bool see_thru_ptrs, bool see_thru_arrays)
     return NULL;
 
   type = TYPE_MAIN_VARIANT (type);
-  if (see_thru_arrays) 
+  if (see_thru_arrays)
     while (POINTER_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)
       type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
 
-  else if (see_thru_ptrs) 
+  else if (see_thru_ptrs)
     while (POINTER_TYPE_P (type))
        type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
 
-  result = splay_tree_lookup(type_to_canon_type, (splay_tree_key) type);
-  
+  result = splay_tree_lookup (type_to_canon_type, (splay_tree_key) type);
+
   if (result == NULL)
     return discover_unique_type (type);
   else return (tree) result->value;
@@ -330,9 +331,9 @@ get_canon_type_uid (tree type, bool see_thru_ptrs, bool see_thru_arrays)
    number if TYPE is a pointer to a record or union.  The number is
    the number of pointer types stripped to get to the record or union
    type.  Return -1 if TYPE is none of the above.  */
+
 int
-ipa_type_escape_star_count_of_interesting_type (tree type) 
+ipa_type_escape_star_count_of_interesting_type (tree type)
 {
   int count = 0;
   /* Strip the *'s off.  */
@@ -346,22 +347,22 @@ ipa_type_escape_star_count_of_interesting_type (tree type)
     }
 
   /* We are interested in records, and unions only.  */
-  if (TREE_CODE (type) == RECORD_TYPE 
-      || TREE_CODE (type) == QUAL_UNION_TYPE 
+  if (TREE_CODE (type) == RECORD_TYPE
+      || TREE_CODE (type) == QUAL_UNION_TYPE
       || TREE_CODE (type) == UNION_TYPE)
     return count;
-  else 
+  else
     return -1;
-} 
+}
 
 
 /* Return 0 if TYPE is a record or union type.  Return a positive
    number if TYPE is a pointer to a record or union.  The number is
    the number of pointer types stripped to get to the record or union
    type.  Return -1 if TYPE is none of the above.  */
+
 int
-ipa_type_escape_star_count_of_interesting_or_array_type (tree type) 
+ipa_type_escape_star_count_of_interesting_or_array_type (tree type)
 {
   int count = 0;
   /* Strip the *'s off.  */
@@ -375,15 +376,15 @@ ipa_type_escape_star_count_of_interesting_or_array_type (tree type)
     }
 
   /* We are interested in records, and unions only.  */
-  if (TREE_CODE (type) == RECORD_TYPE 
-      || TREE_CODE (type) == QUAL_UNION_TYPE 
+  if (TREE_CODE (type) == RECORD_TYPE
+      || TREE_CODE (type) == QUAL_UNION_TYPE
       || TREE_CODE (type) == UNION_TYPE)
     return count;
-  else 
+  else
     return -1;
-} 
+}
+
+
 /* Return true if the record, or union TYPE passed in escapes this
    compilation unit. Note that all of the pointer-to's are removed
    before testing since these may not be correct.  */
@@ -393,19 +394,19 @@ ipa_type_escape_type_contained_p (tree type)
 {
   if (!initialized)
     return false;
-  return !bitmap_bit_p (global_types_full_escape, 
+  return !bitmap_bit_p (global_types_full_escape,
                        get_canon_type_uid (type, true, false));
 }
 
 /* Return true if a modification to a field of type FIELD_TYPE cannot
    clobber a record of RECORD_TYPE.  */
 
-bool 
+bool
 ipa_type_escape_field_does_not_clobber_p (tree record_type, tree field_type)
-{ 
+{
   splay_tree_node result;
   int uid;
-  
+
   if (!initialized)
     return false;
 
@@ -417,25 +418,25 @@ ipa_type_escape_field_does_not_clobber_p (tree record_type, tree field_type)
   while (POINTER_TYPE_P (record_type))
     {
       record_type = TYPE_MAIN_VARIANT (TREE_TYPE (record_type));
-      if (POINTER_TYPE_P (field_type)) 
+      if (POINTER_TYPE_P (field_type))
        field_type = TYPE_MAIN_VARIANT (TREE_TYPE (field_type));
-      else 
+      else
        /* However, if field_type is a union, this quick test is not
           correct since one of the variants of the union may be a
           pointer to type and we cannot see across that here.  So we
           just strip the remaining pointer tos off the record type
           and fall thru to the more precise code.  */
-       if (TREE_CODE (field_type) == QUAL_UNION_TYPE 
+       if (TREE_CODE (field_type) == QUAL_UNION_TYPE
            || TREE_CODE (field_type) == UNION_TYPE)
          {
            while (POINTER_TYPE_P (record_type))
              record_type = TYPE_MAIN_VARIANT (TREE_TYPE (record_type));
            break;
-         } 
-       else 
+         }
+       else
          return true;
     }
-  
+
   record_type = get_canon_type (record_type, true, true);
   /* The record type must be contained.  The field type may
      escape.  */
@@ -444,8 +445,8 @@ ipa_type_escape_field_does_not_clobber_p (tree record_type, tree field_type)
 
   uid = TYPE_UID (record_type);
   result = splay_tree_lookup (uid_to_addressof_down_map, (splay_tree_key) uid);
-  
-  if (result) 
+
+  if (result)
     {
       bitmap field_type_map = (bitmap) result->value;
       uid = get_canon_type_uid (field_type, true, true);
@@ -469,10 +470,10 @@ mark_type (tree type, enum escape_t escape_status)
   int uid;
 
   type = get_canon_type (type, true, true);
-  if (!type) 
+  if (!type)
     return NULL;
 
-  switch (escape_status) 
+  switch (escape_status)
     {
     case EXPOSED_PARAMETER:
       map = global_types_exposed_parameter;
@@ -493,7 +494,7 @@ mark_type (tree type, enum escape_t escape_status)
          /* Efficiency hack. When things are bad, do not mess around
             with this type anymore.  */
          bitmap_set_bit (global_types_exposed_parameter, uid);
-       }      
+       }
     }
   return type;
 }
@@ -502,7 +503,7 @@ mark_type (tree type, enum escape_t escape_status)
    EXPOSED_PARAMETER and the TYPE is a pointer type, the set is
    changed to FULL_ESCAPE.  */
 
-static void 
+static void
 mark_interesting_type (tree type, enum escape_t escape_status)
 {
   if (!type) return;
@@ -521,24 +522,24 @@ mark_interesting_type (tree type, enum escape_t escape_status)
 
 /* Return true if PARENT is supertype of CHILD.  Both types must be
    known to be structures or unions. */
+
 static bool
 parent_type_p (tree parent, tree child)
 {
   int i;
   tree binfo, base_binfo;
-  if (TYPE_BINFO (parent)) 
+  if (TYPE_BINFO (parent))
     for (binfo = TYPE_BINFO (parent), i = 0;
         BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
       {
        tree binfotype = BINFO_TYPE (base_binfo);
-       if (binfotype == child) 
+       if (binfotype == child)
          return true;
        else if (parent_type_p (binfotype, child))
          return true;
       }
   if (TREE_CODE (parent) == UNION_TYPE
-      || TREE_CODE (parent) == QUAL_UNION_TYPE) 
+      || TREE_CODE (parent) == QUAL_UNION_TYPE)
     {
       tree field;
       /* Search all of the variants in the union to see if one of them
@@ -550,9 +551,9 @@ parent_type_p (tree parent, tree child)
          tree field_type;
          if (TREE_CODE (field) != FIELD_DECL)
            continue;
-         
+
          field_type = TREE_TYPE (field);
-         if (field_type == child) 
+         if (field_type == child)
            return true;
        }
 
@@ -565,16 +566,16 @@ parent_type_p (tree parent, tree child)
          tree field_type;
          if (TREE_CODE (field) != FIELD_DECL)
            continue;
-         
+
          field_type = TREE_TYPE (field);
-         if (TREE_CODE (field_type) == RECORD_TYPE 
-             || TREE_CODE (field_type) == QUAL_UNION_TYPE 
+         if (TREE_CODE (field_type) == RECORD_TYPE
+             || TREE_CODE (field_type) == QUAL_UNION_TYPE
              || TREE_CODE (field_type) == UNION_TYPE)
-           if (parent_type_p (field_type, child)) 
+           if (parent_type_p (field_type, child))
              return true;
        }
     }
-  
+
   if (TREE_CODE (parent) == RECORD_TYPE)
     {
       tree field;
@@ -585,19 +586,19 @@ parent_type_p (tree parent, tree child)
          tree field_type;
          if (TREE_CODE (field) != FIELD_DECL)
            continue;
-         
+
          field_type = TREE_TYPE (field);
-         if (field_type == child) 
+         if (field_type == child)
            return true;
          /* You can only cast to the first field so if it does not
             match, quit.  */
-         if (TREE_CODE (field_type) == RECORD_TYPE 
-             || TREE_CODE (field_type) == QUAL_UNION_TYPE 
+         if (TREE_CODE (field_type) == RECORD_TYPE
+             || TREE_CODE (field_type) == QUAL_UNION_TYPE
              || TREE_CODE (field_type) == UNION_TYPE)
            {
-             if (parent_type_p (field_type, child)) 
+             if (parent_type_p (field_type, child))
                return true;
-             else 
+             else
                break;
            }
        }
@@ -608,7 +609,7 @@ parent_type_p (tree parent, tree child)
 /* Return the number of pointer tos for TYPE and return TYPE with all
    of these stripped off.  */
 
-static int 
+static int
 count_stars (tree* type_ptr)
 {
   tree type = *type_ptr;
@@ -645,7 +646,7 @@ check_cast_type (tree to_type, tree from_type)
 {
   int to_stars = count_stars (&to_type);
   int from_stars = count_stars (&from_type);
-  if (to_stars != from_stars) 
+  if (to_stars != from_stars)
     return CT_SIDEWAYS;
 
   if (to_type == from_type)
@@ -654,48 +655,39 @@ check_cast_type (tree to_type, tree from_type)
   if (parent_type_p (to_type, from_type)) return CT_UP;
   if (parent_type_p (from_type, to_type)) return CT_DOWN;
   return CT_SIDEWAYS;
-}     
+}
 
-/* This function returns nonzero if VAR is result of call 
+/* This function returns nonzero if VAR is result of call
    to malloc function.  */
 
 static bool
 is_malloc_result (tree var)
 {
-  tree def_stmt;
-  tree rhs;
-  int flags;
+  gimple def_stmt;
 
   if (!var)
     return false;
-  
+
   if (SSA_NAME_IS_DEFAULT_DEF (var))
     return false;
 
   def_stmt = SSA_NAME_DEF_STMT (var);
-  
-  if (TREE_CODE (def_stmt) != GIMPLE_MODIFY_STMT)
-    return false;
 
-  if (var != GIMPLE_STMT_OPERAND (def_stmt, 0))
+  if (!is_gimple_call (def_stmt))
     return false;
 
-  rhs = get_call_expr_in (def_stmt);
-
-  if (!rhs)
+  if (var != gimple_call_lhs (def_stmt))
     return false;
 
-  flags = call_expr_flags (rhs);
-    
-  return ((flags & ECF_MALLOC) != 0);
+  return ((gimple_call_flags (def_stmt) & ECF_MALLOC) != 0);
 
 }
 
 /* Check a cast FROM this variable, TO_TYPE.  Mark the escaping types
    if appropriate. Returns cast_type as detected.  */
+
 static enum cast_type
-check_cast (tree to_type, tree from) 
+check_cast (tree to_type, tree from)
 {
   tree from_type = get_canon_type (TREE_TYPE (from), false, false);
   bool to_interesting_type, from_interesting_type;
@@ -705,12 +697,12 @@ check_cast (tree to_type, tree from)
   if (!from_type || !to_type || from_type == to_type)
     return cast;
 
-  to_interesting_type = 
+  to_interesting_type =
     ipa_type_escape_star_count_of_interesting_type (to_type) >= 0;
-  from_interesting_type = 
+  from_interesting_type =
     ipa_type_escape_star_count_of_interesting_type (from_type) >= 0;
 
-  if (to_interesting_type) 
+  if (to_interesting_type)
     if (from_interesting_type)
       {
        /* Both types are interesting. This can be one of four types
@@ -720,7 +712,7 @@ check_cast (tree to_type, tree from)
           interesting here because if type is marked as escaping, all
           of its subtypes escape.  */
        cast = check_cast_type (to_type, from_type);
-       switch (cast) 
+       switch (cast)
          {
          case CT_UP:
          case CT_USELESS:
@@ -739,18 +731,18 @@ check_cast (tree to_type, tree from)
     else
       {
        /* This code excludes two cases from marking as escaped:
-          
+
        1. if this is a cast of index of array of structures/unions
-       that happens before accessing array element, we should not 
+       that happens before accessing array element, we should not
        mark it as escaped.
        2. if this is a cast from the local that is a result from a
-       call to malloc, do not mark the cast as bad.  
+       call to malloc, do not mark the cast as bad.
 
        */
-       
+
        if (POINTER_TYPE_P (to_type) && !POINTER_TYPE_P (from_type))
          cast = CT_FROM_NON_P;
-       else if (TREE_CODE (from) == SSA_NAME 
+       else if (TREE_CODE (from) == SSA_NAME
                 && is_malloc_result (from))
          cast = CT_FROM_MALLOC;
        else
@@ -768,122 +760,105 @@ check_cast (tree to_type, tree from)
   return cast;
 }
 
-typedef struct cast 
-{
-  int type;
-  tree stmt;
-}cast_t;
-
-/* This function is a callback for walk_tree called from 
-   is_cast_from_non_pointer. The data->type is set to be:
 
-   0      - if there is no cast
-   number - the number of casts from non-pointer type
-   -1     - if there is a cast that makes the type to escape
+/* Scan assignment statement S to see if there are any casts within it.  */
 
-   If data->type = number, then data->stmt will contain the 
-   last casting stmt met in traversing.  */
-
-static tree
-is_cast_from_non_pointer_1 (tree *tp, int *walk_subtrees, void *data)
+static unsigned int
+look_for_casts_stmt (gimple s)
 {
-  tree def_stmt = *tp;
+  unsigned int cast = 0;
 
+  gcc_assert (is_gimple_assign (s));
 
-  if (pointer_set_insert (visited_stmts, def_stmt))
+  if (gimple_assign_cast_p (s))
     {
-      *walk_subtrees = 0;
-      return NULL;
+      tree castfromvar = gimple_assign_rhs1 (s);
+      cast |= check_cast (TREE_TYPE (gimple_assign_lhs (s)), castfromvar);
     }
-  
-  switch (TREE_CODE (def_stmt))
+  else
     {
-    case GIMPLE_MODIFY_STMT:
-      {
-       use_operand_p use_p; 
-       ssa_op_iter iter;
-       tree lhs = GIMPLE_STMT_OPERAND (def_stmt, 0);
-       tree rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
-
-        unsigned int cast = look_for_casts (lhs, rhs);
-       /* Check that only one cast happened, and it's of 
-          non-pointer type.  */
-       if ((cast & CT_FROM_NON_P) == (CT_FROM_NON_P) 
-           && (cast & ~(CT_FROM_NON_P)) == 0)
-         {
-           ((cast_t *)data)->stmt = def_stmt;
-           ((cast_t *)data)->type++;
-
-           FOR_EACH_SSA_USE_OPERAND (use_p, def_stmt, iter, SSA_OP_ALL_USES)
-             {
-               walk_use_def_chains (USE_FROM_PTR (use_p), is_cast_from_non_pointer, 
-                                    data, false);
-               if (((cast_t*)data)->type == -1)
-                 return def_stmt;
-             }
-         }
-
-       /* Check that there is no cast, or cast is not harmful. */
-       else if ((cast & CT_NO_CAST) == (CT_NO_CAST)
-                || (cast & CT_DOWN) == (CT_DOWN)
-                || (cast & CT_UP) == (CT_UP)
-                || (cast & CT_USELESS) == (CT_USELESS)
-                || (cast & CT_FROM_MALLOC) == (CT_FROM_MALLOC))
-         {
-           FOR_EACH_SSA_USE_OPERAND (use_p, def_stmt, iter, SSA_OP_ALL_USES)
-             {
-               walk_use_def_chains (USE_FROM_PTR (use_p), is_cast_from_non_pointer, 
-                                    data, false);
-               if (((cast_t*)data)->type == -1)
-                 return def_stmt;
-             }     
-         }
+      size_t i;
+      for (i = 0; i < gimple_num_ops (s); i++)
+       cast |= look_for_casts (gimple_op (s, i));
+    }
 
-       /* The cast is harmful.  */
-       else
-         {
-           ((cast_t *)data)->type = -1;
-           return def_stmt;
-         }
+  if (!cast)
+    cast = CT_NO_CAST;
 
-       *walk_subtrees = 0;
-      }     
-      break;
+  return cast;
+}
 
-    default:
-      {
-       *walk_subtrees = 0;
-       break;
-      }
-    }
 
-  return NULL;
-}
+typedef struct cast
+{
+  int type;
+  gimple stmt;
+} cast_t;
 
-/* This function is a callback for walk_use_def_chains function called 
+/* This function is a callback for walk_use_def_chains function called
    from is_array_access_through_pointer_and_index.  */
 
 static bool
-is_cast_from_non_pointer (tree var, tree def_stmt, void *data)
+is_cast_from_non_pointer (tree var, gimple def_stmt, void *data)
 {
-
   if (!def_stmt || !var)
     return false;
-  
-  if (TREE_CODE (def_stmt) == PHI_NODE)
+
+  if (gimple_code (def_stmt) == GIMPLE_PHI)
     return false;
 
   if (SSA_NAME_IS_DEFAULT_DEF (var))
       return false;
 
-  walk_tree (&def_stmt, is_cast_from_non_pointer_1, data, NULL);
+  if (is_gimple_assign (def_stmt))
+    {
+      use_operand_p use_p;
+      ssa_op_iter iter;
+      unsigned int cast = look_for_casts_stmt (def_stmt);
+
+      /* Check that only one cast happened, and it's of non-pointer
+        type.  */
+      if ((cast & CT_FROM_NON_P) == (CT_FROM_NON_P)
+         && (cast & ~(CT_FROM_NON_P)) == 0)
+       {
+         ((cast_t *)data)->stmt = def_stmt;
+         ((cast_t *)data)->type++;
+
+         FOR_EACH_SSA_USE_OPERAND (use_p, def_stmt, iter, SSA_OP_ALL_USES)
+           {
+             walk_use_def_chains (USE_FROM_PTR (use_p),
+                                  is_cast_from_non_pointer, data, false);
+             if (((cast_t*)data)->type == -1)
+               break;
+           }
+       }
+      /* Check that there is no cast, or cast is not harmful. */
+      else if ((cast & CT_NO_CAST) == (CT_NO_CAST)
+         || (cast & CT_DOWN) == (CT_DOWN)
+         || (cast & CT_UP) == (CT_UP)
+         || (cast & CT_USELESS) == (CT_USELESS)
+         || (cast & CT_FROM_MALLOC) == (CT_FROM_MALLOC))
+       {
+         FOR_EACH_SSA_USE_OPERAND (use_p, def_stmt, iter, SSA_OP_ALL_USES)
+           {
+             walk_use_def_chains (USE_FROM_PTR (use_p),
+                                  is_cast_from_non_pointer, data, false);
+             if (((cast_t*)data)->type == -1)
+               break;
+           }
+       }
+       /* The cast is harmful.  */
+       else
+         ((cast_t *)data)->type = -1;
+    }
+
   if (((cast_t*)data)->type == -1)
     return true;
-  
+
   return false;
 }
 
-/* When array element a_p[i] is accessed through the pointer a_p 
+/* When array element a_p[i] is accessed through the pointer a_p
    and index i, it's translated into the following sequence
    in gimple:
 
@@ -893,45 +868,46 @@ is_cast_from_non_pointer (tree var, tree def_stmt, void *data)
   a_p.2_8 = a_p;
   D.1608_9 = D.1606_7 + a_p.2_8;
 
-  OP0 and OP1 are of the same pointer types and stand for 
+  OP0 and OP1 are of the same pointer types and stand for
   D.1606_7 and a_p.2_8 or vise versa.
 
   This function checks that:
 
-  1. one of OP0 and OP1 (D.1606_7) has passed only one cast from 
+  1. one of OP0 and OP1 (D.1606_7) has passed only one cast from
   non-pointer type (D.1606_7 = (struct str_t *) D.1605_6;).
 
-  2. one of OP0 and OP1 which has passed the cast from 
-  non-pointer type (D.1606_7), is actually generated by multiplication of 
+  2. one of OP0 and OP1 which has passed the cast from
+  non-pointer type (D.1606_7), is actually generated by multiplication of
   index by size of type to which both OP0 and OP1 point to
   (in this case D.1605_6 = i.1_5 * 16; ).
 
-  3. an address of def of the var to which was made cast (D.1605_6) 
+  3. an address of def of the var to which was made cast (D.1605_6)
   was not taken.(How can it happen?)
 
   The following items are checked implicitly by the end of algorithm:
 
-  4. one of OP0 and OP1 (a_p.2_8) have never been cast 
-  (because if it was cast to pointer type, its type, that is also 
-  the type of OP0 and OP1, will be marked as escaped during 
-  analysis of casting stmt (when check_cast() is called 
-  from scan_for_refs for this stmt)).   
+  4. one of OP0 and OP1 (a_p.2_8) have never been cast
+  (because if it was cast to pointer type, its type, that is also
+  the type of OP0 and OP1, will be marked as escaped during
+  analysis of casting stmt (when check_cast() is called
+  from scan_for_refs for this stmt)).
 
   5. defs of OP0 and OP1 are not passed into externally visible function
   (because if they are passed then their type, that is also the type of OP0
-  and OP1, will be marked and escaped during check_call function called from 
+  and OP1, will be marked and escaped during check_call function called from
   scan_for_refs with call stmt).
 
-  In total, 1-5 guaranty that it's an access to array by pointer and index. 
+  In total, 1-5 guaranty that it's an access to array by pointer and index.
 
 */
 
 bool
-is_array_access_through_pointer_and_index (enum tree_code code, tree op0, 
+is_array_access_through_pointer_and_index (enum tree_code code, tree op0,
                                           tree op1, tree *base, tree *offset,
-                                          tree *offset_cast_stmt)
+                                          gimple *offset_cast_stmt)
 {
-  tree before_cast, before_cast_def_stmt;
+  tree before_cast;
+  gimple before_cast_def_stmt;
   cast_t op0_cast, op1_cast;
 
   *base = NULL;
@@ -969,7 +945,7 @@ is_array_access_through_pointer_and_index (enum tree_code code, tree op0,
                           false);
       pointer_set_destroy (visited_stmts);
 
-      visited_stmts = pointer_set_create ();  
+      visited_stmts = pointer_set_create ();
       walk_use_def_chains (op1, is_cast_from_non_pointer,(void *)(&op1_cast),
                           false);
       pointer_set_destroy (visited_stmts);
@@ -983,15 +959,15 @@ is_array_access_through_pointer_and_index (enum tree_code code, tree op0,
       else if (op0_cast.type == 0 && op1_cast.type == 1)
        {
          *base = op0;
-         *offset = op1;      
+         *offset = op1;
          *offset_cast_stmt = op1_cast.stmt;
        }
       else
        return false;
     }
-  
-  /* Check 2.  
-     offset_cast_stmt is of the form: 
+
+  /* Check 2.
+     offset_cast_stmt is of the form:
      D.1606_7 = (struct str_t *) D.1605_6;  */
 
   if (*offset_cast_stmt)
@@ -999,10 +975,10 @@ is_array_access_through_pointer_and_index (enum tree_code code, tree op0,
       before_cast = SINGLE_SSA_TREE_OPERAND (*offset_cast_stmt, SSA_OP_USE);
       if (!before_cast)
        return false;
-  
+
       if (SSA_NAME_IS_DEFAULT_DEF (before_cast))
        return false;
-  
+
       before_cast_def_stmt = SSA_NAME_DEF_STMT (before_cast);
       if (!before_cast_def_stmt)
        return false;
@@ -1012,28 +988,25 @@ is_array_access_through_pointer_and_index (enum tree_code code, tree op0,
 
   /* before_cast_def_stmt should be of the form:
      D.1605_6 = i.1_5 * 16; */
-  
-  if (TREE_CODE (before_cast_def_stmt) == GIMPLE_MODIFY_STMT)
-    {
-      tree lhs = GIMPLE_STMT_OPERAND (before_cast_def_stmt,0);
-      tree rhs = GIMPLE_STMT_OPERAND (before_cast_def_stmt,1);
 
+  if (is_gimple_assign (before_cast_def_stmt))
+    {
       /* We expect temporary here.  */
-      if (!is_gimple_reg (lhs))        
+      if (!is_gimple_reg (gimple_assign_lhs (before_cast_def_stmt)))
        return false;
 
-      if (TREE_CODE (rhs) == MULT_EXPR)
+      if (gimple_assign_rhs_code (before_cast_def_stmt) == MULT_EXPR)
        {
-         tree arg0 = TREE_OPERAND (rhs, 0);
-         tree arg1 = TREE_OPERAND (rhs, 1);
-         tree unit_size = 
+         tree arg0 = gimple_assign_rhs1 (before_cast_def_stmt);
+         tree arg1 = gimple_assign_rhs2 (before_cast_def_stmt);
+         tree unit_size =
            TYPE_SIZE_UNIT (TREE_TYPE (TYPE_MAIN_VARIANT (TREE_TYPE (op0))));
 
-         if (!(CONSTANT_CLASS_P (arg0) 
-             && simple_cst_equal (arg0,unit_size))
-             && !(CONSTANT_CLASS_P (arg1) 
-             && simple_cst_equal (arg1,unit_size)))
-           return false;                          
+         if (!(CONSTANT_CLASS_P (arg0)
+             && simple_cst_equal (arg0, unit_size))
+             && !(CONSTANT_CLASS_P (arg1)
+             && simple_cst_equal (arg1, unit_size)))
+           return false;
        }
       else
        return false;
@@ -1051,11 +1024,11 @@ is_array_access_through_pointer_and_index (enum tree_code code, tree op0,
 /* Register the parameter and return types of function FN.  The type
    ESCAPES if the function is visible outside of the compilation
    unit.  */
-static void 
-check_function_parameter_and_return_types (tree fn, bool escapes) 
+static void
+check_function_parameter_and_return_types (tree fn, bool escapes)
 {
   tree arg;
-  
+
   if (TYPE_ARG_TYPES (TREE_TYPE (fn)))
     {
       for (arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
@@ -1084,7 +1057,7 @@ check_function_parameter_and_return_types (tree fn, bool escapes)
   if (escapes)
     {
       tree type = get_canon_type (TREE_TYPE (TREE_TYPE (fn)), false, false);
-      mark_interesting_type (type, EXPOSED_PARAMETER); 
+      mark_interesting_type (type, EXPOSED_PARAMETER);
     }
 }
 
@@ -1099,7 +1072,7 @@ has_proper_scope_for_analysis (tree t)
   tree type = get_canon_type (TREE_TYPE (t), false, false);
   if (!type) return;
 
-  if (lookup_attribute ("used", DECL_ATTRIBUTES (t)))
+  if (DECL_PRESERVE_P (t))
     {
       mark_interesting_type (type, FULL_ESCAPE);
       return;
@@ -1107,7 +1080,7 @@ has_proper_scope_for_analysis (tree t)
 
   /* Do not want to do anything with volatile except mark any
      function that uses one to be not const or pure.  */
-  if (TREE_THIS_VOLATILE (t)) 
+  if (TREE_THIS_VOLATILE (t))
     return;
 
   /* Do not care about a local automatic that is not static.  */
@@ -1120,12 +1093,12 @@ has_proper_scope_for_analysis (tree t)
         constant, we can allow this variable in pure or const
         functions but the scope is too large for our analysis to set
         these bits ourselves.  */
-      
+
       if (TREE_READONLY (t)
          && DECL_INITIAL (t)
          && is_gimple_min_invariant (DECL_INITIAL (t)))
        ; /* Read of a constant, do not change the function state.  */
-      else 
+      else
        {
          /* The type escapes for all public and externs. */
          mark_interesting_type (type, FULL_ESCAPE);
@@ -1147,7 +1120,7 @@ check_operand (tree t)
     check_function_parameter_and_return_types (t, true);
 
   else if (TREE_CODE (t) == VAR_DECL)
-    has_proper_scope_for_analysis (t); 
+    has_proper_scope_for_analysis (t);
 }
 
 /* Examine tree T for references.   */
@@ -1155,9 +1128,6 @@ check_operand (tree t)
 static void
 check_tree (tree t)
 {
-  if ((TREE_CODE (t) == EXC_PTR_EXPR) || (TREE_CODE (t) == FILTER_EXPR))
-    return;
-
   /* We want to catch here also REALPART_EXPR and IMAGEPART_EXPR,
      but they already included in handled_component_p.  */
   while (handled_component_p (t))
@@ -1172,7 +1142,11 @@ check_tree (tree t)
     check_tree (TREE_OPERAND (t, 0));
 
   if (SSA_VAR_P (t) || (TREE_CODE (t) == FUNCTION_DECL))
-    check_operand (t);
+    {
+      check_operand (t);
+      if (DECL_P (t) && DECL_INITIAL (t))
+       check_tree (DECL_INITIAL (t));
+    }
 }
 
 /* Create an address_of edge FROM_TYPE.TO_TYPE.  */
@@ -1182,11 +1156,11 @@ mark_interesting_addressof (tree to_type, tree from_type)
   int from_uid;
   int to_uid;
   bitmap type_map;
-  splay_tree_node result; 
+  splay_tree_node result;
 
   from_type = get_canon_type (from_type, false, false);
   to_type = get_canon_type (to_type, false, false);
-  
+
   if (!from_type || !to_type)
     return;
 
@@ -1194,41 +1168,41 @@ mark_interesting_addressof (tree to_type, tree from_type)
   to_uid = TYPE_UID (to_type);
 
   gcc_assert (ipa_type_escape_star_count_of_interesting_type (from_type) == 0);
-  
+
   /* Process the Y into X map pointer.  */
-  result = splay_tree_lookup (uid_to_addressof_down_map, 
+  result = splay_tree_lookup (uid_to_addressof_down_map,
                              (splay_tree_key) from_uid);
-  
-  if (result) 
-    type_map = (bitmap) result->value;  
-  else 
+
+  if (result)
+    type_map = (bitmap) result->value;
+  else
     {
       type_map = BITMAP_ALLOC (&ipa_obstack);
       splay_tree_insert (uid_to_addressof_down_map,
-                        from_uid, 
+                        from_uid,
                         (splay_tree_value)type_map);
     }
   bitmap_set_bit (type_map, TYPE_UID (to_type));
-  
+
   /* Process the X into Y reverse map pointer.  */
-  result = 
+  result =
     splay_tree_lookup (uid_to_addressof_up_map, (splay_tree_key) to_uid);
-  
-  if (result) 
-    type_map = (bitmap) result->value;  
-  else 
+
+  if (result)
+    type_map = (bitmap) result->value;
+  else
     {
       type_map = BITMAP_ALLOC (&ipa_obstack);
       splay_tree_insert (uid_to_addressof_up_map,
-                        to_uid, 
+                        to_uid,
                         (splay_tree_value)type_map);
     }
-  bitmap_set_bit (type_map, TYPE_UID (from_type)); 
+  bitmap_set_bit (type_map, TYPE_UID (from_type));
 }
 
 /* Scan tree T to see if there are any addresses taken in within T.  */
 
-static void 
+static void
 look_for_address_of (tree t)
 {
   if (TREE_CODE (t) == ADDR_EXPR)
@@ -1237,14 +1211,14 @@ look_for_address_of (tree t)
       tree cref = TREE_OPERAND (t, 0);
 
       /* If we have an expression of the form "&a.b.c.d", mark a.b,
-        b.c and c.d. as having its address taken.  */ 
+        b.c and c.d. as having its address taken.  */
       tree fielddecl = NULL_TREE;
       while (cref!= x)
        {
          if (TREE_CODE (cref) == COMPONENT_REF)
            {
              fielddecl =  TREE_OPERAND (cref, 1);
-             mark_interesting_addressof (TREE_TYPE (fielddecl), 
+             mark_interesting_addressof (TREE_TYPE (fielddecl),
                                          DECL_FIELD_CONTEXT (fielddecl));
            }
          else if (TREE_CODE (cref) == ARRAY_REF)
@@ -1253,27 +1227,25 @@ look_for_address_of (tree t)
          cref = TREE_OPERAND (cref, 0);
        }
 
-      if (TREE_CODE (x) == VAR_DECL) 
+      if (TREE_CODE (x) == VAR_DECL)
        has_proper_scope_for_analysis (x);
     }
 }
 
 
-/* Scan tree T to see if there are any casts within it.
-   LHS Is the LHS of the expression involving the cast.  */
+/* Scan tree T to see if there are any casts within it.  */
 
-static unsigned int 
-look_for_casts (tree lhs ATTRIBUTE_UNUSED, tree t)
+static unsigned int
+look_for_casts (tree t)
 {
   unsigned int cast = 0;
 
-
   if (is_gimple_cast (t) || TREE_CODE (t) == VIEW_CONVERT_EXPR)
     {
       tree castfromvar = TREE_OPERAND (t, 0);
       cast = cast | check_cast (TREE_TYPE (t), castfromvar);
     }
-  else 
+  else
     while (handled_component_p (t))
       {
        t = TREE_OPERAND (t, 0);
@@ -1292,7 +1264,7 @@ look_for_casts (tree lhs ATTRIBUTE_UNUSED, tree t)
   if (!cast)
     cast = CT_NO_CAST;
   return cast;
-} 
+}
 
 /* Check to see if T is a read or address of operation on a static var
    we are interested in analyzing.  */
@@ -1301,7 +1273,7 @@ static void
 check_rhs_var (tree t)
 {
   look_for_address_of (t);
-  check_tree(t);
+  check_tree (t);
 }
 
 /* Check to see if T is an assignment to a static var we are
@@ -1310,7 +1282,7 @@ check_rhs_var (tree t)
 static void
 check_lhs_var (tree t)
 {
-  check_tree(t);
+  check_tree (t);
 }
 
 /* This is a scaled down version of get_asm_expr_operands from
@@ -1321,36 +1293,16 @@ check_lhs_var (tree t)
    analyzed and STMT is the actual asm statement.  */
 
 static void
-get_asm_expr_operands (tree stmt)
+check_asm (gimple stmt)
 {
-  int noutputs = list_length (ASM_OUTPUTS (stmt));
-  const char **oconstraints
-    = (const char **) alloca ((noutputs) * sizeof (const char *));
-  int i;
-  tree link;
-  const char *constraint;
-  bool allows_mem, allows_reg, is_inout;
-  
-  for (i=0, link = ASM_OUTPUTS (stmt); link; ++i, link = TREE_CHAIN (link))
-    {
-      oconstraints[i] = constraint
-       = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
-      parse_output_constraint (&constraint, i, 0, 0,
-                              &allows_mem, &allows_reg, &is_inout);
-      
-      check_lhs_var (TREE_VALUE (link));
-    }
+  size_t i;
+
+  for (i = 0; i < gimple_asm_noutputs (stmt); i++)
+    check_lhs_var (gimple_asm_output_op (stmt, i));
+
+  for (i = 0; i < gimple_asm_ninputs (stmt); i++)
+    check_rhs_var (gimple_asm_input_op (stmt, i));
 
-  for (link = ASM_INPUTS (stmt); link; link = TREE_CHAIN (link))
-    {
-      constraint
-       = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
-      parse_input_constraint (&constraint, 0, 0, noutputs, 0,
-                             oconstraints, &allows_mem, &allows_reg);
-      
-      check_rhs_var (TREE_VALUE (link));
-    }
-  
   /* There is no code here to check for asm memory clobbers.  The
      casual maintainer might think that such code would be necessary,
      but that appears to be wrong.  In other parts of the compiler,
@@ -1359,86 +1311,83 @@ get_asm_expr_operands (tree stmt)
      assumed to already escape.  So, we are protected here.  */
 }
 
-/* Check the parameters of a function call to CALL_EXPR to mark the
+
+/* Check the parameters of function call to CALL to mark the
    types that pass across the function boundary.  Also check to see if
    this is either an indirect call, a call outside the compilation
    unit.  */
 
 static void
-check_call (tree call_expr) 
+check_call (gimple call)
 {
-  tree operand;
-  tree callee_t = get_callee_fndecl (call_expr);
+  tree callee_t = gimple_call_fndecl (call);
   struct cgraph_node* callee;
   enum availability avail = AVAIL_NOT_AVAILABLE;
-  call_expr_arg_iterator iter;
+  size_t i;
+
+  for (i = 0; i < gimple_call_num_args (call); i++)
+    check_rhs_var (gimple_call_arg (call, i));
 
-  FOR_EACH_CALL_EXPR_ARG (operand, iter, call_expr)
-    check_rhs_var (operand);
-  
   if (callee_t)
     {
       tree arg_type;
       tree last_arg_type = NULL;
       callee = cgraph_node(callee_t);
       avail = cgraph_function_body_availability (callee);
-      
+
       /* Check that there are no implicit casts in the passing of
         parameters.  */
       if (TYPE_ARG_TYPES (TREE_TYPE (callee_t)))
        {
-         for (arg_type = TYPE_ARG_TYPES (TREE_TYPE (callee_t)),
-                operand = first_call_expr_arg (call_expr, &iter);
+         for (arg_type = TYPE_ARG_TYPES (TREE_TYPE (callee_t)), i = 0;
               arg_type && TREE_VALUE (arg_type) != void_type_node;
-              arg_type = TREE_CHAIN (arg_type),
-                operand = next_call_expr_arg (&iter))
+              arg_type = TREE_CHAIN (arg_type), i++)
            {
+             tree operand = gimple_call_arg (call, i);
              if (operand)
                {
                  last_arg_type = TREE_VALUE(arg_type);
                  check_cast (last_arg_type, operand);
                }
-             else 
+             else
                /* The code reaches here for some unfortunate
                   builtin functions that do not have a list of
                   argument types.  */
-               break; 
+               break;
            }
-       } 
-      else  
-       { 
+       }
+      else
+       {
          /* FIXME - According to Geoff Keating, we should never
             have to do this; the front ends should always process
             the arg list from the TYPE_ARG_LIST. */
-         for (arg_type = DECL_ARGUMENTS (callee_t),
-                operand = first_call_expr_arg (call_expr, &iter);
+         for (arg_type = DECL_ARGUMENTS (callee_t), i = 0;
               arg_type;
-              arg_type = TREE_CHAIN (arg_type),
-                operand = next_call_expr_arg (&iter))
+              arg_type = TREE_CHAIN (arg_type), i++)
            {
+             tree operand = gimple_call_arg (call, i);
              if (operand)
                {
-                 last_arg_type = TREE_TYPE(arg_type);
+                 last_arg_type = TREE_TYPE (arg_type);
                  check_cast (last_arg_type, operand);
-               } 
-             else 
+               }
+             else
                /* The code reaches here for some unfortunate
                   builtin functions that do not have a list of
                   argument types.  */
-               break; 
+               break;
            }
        }
-      
+
       /* In the case where we have a var_args function, we need to
         check the remaining parameters against the last argument.  */
       arg_type = last_arg_type;
-      for (;
-          operand != NULL_TREE;
-          operand = next_call_expr_arg (&iter))
+      for ( ; i < gimple_call_num_args (call); i++)
        {
+         tree operand = gimple_call_arg (call, i);
          if (arg_type)
            check_cast (arg_type, operand);
-         else 
+         else
            {
              /* The code reaches here for some unfortunate
                 builtin functions that do not have a list of
@@ -1456,20 +1405,20 @@ check_call (tree call_expr)
      are any bits available for the callee (such as by declaration or
      because it is builtin) and process solely on the basis of those
      bits. */
-
   if (avail == AVAIL_NOT_AVAILABLE || avail == AVAIL_OVERWRITABLE)
     {
       /* If this is a direct call to an external function, mark all of
         the parameter and return types.  */
-      FOR_EACH_CALL_EXPR_ARG (operand, iter, call_expr)
+      for (i = 0; i < gimple_call_num_args (call); i++)
        {
+         tree operand = gimple_call_arg (call, i);
          tree type = get_canon_type (TREE_TYPE (operand), false, false);
          mark_interesting_type (type, EXPOSED_PARAMETER);
-    }
-         
-      if (callee_t) 
+       }
+
+      if (callee_t)
        {
-         tree type = 
+         tree type =
            get_canon_type (TREE_TYPE (TREE_TYPE (callee_t)), false, false);
          mark_interesting_type (type, EXPOSED_PARAMETER);
        }
@@ -1478,7 +1427,7 @@ check_call (tree call_expr)
 
 /* CODE is the operation on OP0 and OP1.  OP0 is the operand that we
    *know* is a pointer type.  OP1 may be a pointer type.  */
-static bool 
+static bool
 okay_pointer_operation (enum tree_code code, tree op0, tree op1)
 {
   tree op0type = TYPE_MAIN_VARIANT (TREE_TYPE (op0));
@@ -1493,31 +1442,32 @@ okay_pointer_operation (enum tree_code code, tree op0, tree op1)
     case PLUS_EXPR:
     case POINTER_PLUS_EXPR:
       {
-       tree base, offset, offset_cast_stmt;
+       tree base, offset;
+       gimple offset_cast_stmt;
 
        if (POINTER_TYPE_P (op0type)
-           && TREE_CODE (op0) == SSA_NAME 
-           && TREE_CODE (op1) == SSA_NAME 
-           && is_array_access_through_pointer_and_index (code, op0, op1, 
-                                                         &base, 
-                                                         &offset, 
+           && TREE_CODE (op0) == SSA_NAME
+           && TREE_CODE (op1) == SSA_NAME
+           && is_array_access_through_pointer_and_index (code, op0, op1,
+                                                         &base,
+                                                         &offset,
                                                          &offset_cast_stmt))
          return true;
        else
          {
            tree size_of_op0_points_to = TYPE_SIZE_UNIT (TREE_TYPE (op0type));
-           
+
            if (CONSTANT_CLASS_P (op1)
                && size_of_op0_points_to
-               && multiple_of_p (TREE_TYPE (size_of_op0_points_to), 
+               && multiple_of_p (TREE_TYPE (size_of_op0_points_to),
                                  op1, size_of_op0_points_to))
              return true;
 
-           if (CONSTANT_CLASS_P (op0) 
+           if (CONSTANT_CLASS_P (op0)
                && size_of_op0_points_to
-               && multiple_of_p (TREE_TYPE (size_of_op0_points_to), 
+               && multiple_of_p (TREE_TYPE (size_of_op0_points_to),
                                  op0, size_of_op0_points_to))
-             return true;          
+             return true;
          }
       }
       break;
@@ -1527,157 +1477,131 @@ okay_pointer_operation (enum tree_code code, tree op0, tree op1)
   return false;
 }
 
-/* TP is the part of the tree currently under the microscope.
-   WALK_SUBTREES is part of the walk_tree api but is unused here.
-   DATA is cgraph_node of the function being walked.  */
 
-/* FIXME: When this is converted to run over SSA form, this code
-   should be converted to use the operand scanner.  */
 
-static tree
-scan_for_refs (tree *tp, int *walk_subtrees, void *data)
+/* Helper for scan_for_refs.  Check the operands of an assignment to
+   mark types that may escape.  */
+
+static void
+check_assign (gimple t)
 {
-  struct cgraph_node *fn = (struct cgraph_node *) data;
-  tree t = *tp;
+  /* First look on the lhs and see what variable is stored to */
+  check_lhs_var (gimple_assign_lhs (t));
+
+  /* For the purposes of figuring out what the cast affects */
 
-  switch (TREE_CODE (t))  
+  /* Next check the operands on the rhs to see if they are ok. */
+  switch (TREE_CODE_CLASS (gimple_assign_rhs_code (t)))
     {
-    case VAR_DECL:
-      if (DECL_INITIAL (t))
-       walk_tree (&DECL_INITIAL (t), scan_for_refs, fn, visited_nodes);
-      *walk_subtrees = 0;
+    case tcc_binary:
+      {
+       tree op0 = gimple_assign_rhs1 (t);
+       tree type0 = get_canon_type (TREE_TYPE (op0), false, false);
+       tree op1 = gimple_assign_rhs2 (t);
+       tree type1 = get_canon_type (TREE_TYPE (op1), false, false);
+
+       /* If this is pointer arithmetic of any bad sort, then
+           we need to mark the types as bad.  For binary
+           operations, no binary operator we currently support
+           is always "safe" in regard to what it would do to
+           pointers for purposes of determining which types
+           escape, except operations of the size of the type.
+           It is possible that min and max under the right set
+           of circumstances and if the moon is in the correct
+           place could be safe, but it is hard to see how this
+           is worth the effort.  */
+       if (type0 && POINTER_TYPE_P (type0)
+           && !okay_pointer_operation (gimple_assign_rhs_code (t), op0, op1))
+         mark_interesting_type (type0, FULL_ESCAPE);
+
+       if (type1 && POINTER_TYPE_P (type1)
+           && !okay_pointer_operation (gimple_assign_rhs_code (t), op1, op0))
+         mark_interesting_type (type1, FULL_ESCAPE);
+
+       look_for_casts (op0);
+       look_for_casts (op1);
+       check_rhs_var (op0);
+       check_rhs_var (op1);
+      }
       break;
 
-    case GIMPLE_MODIFY_STMT:
+    case tcc_unary:
       {
-       /* First look on the lhs and see what variable is stored to */
-       tree lhs = GIMPLE_STMT_OPERAND (t, 0);
-       tree rhs = GIMPLE_STMT_OPERAND (t, 1);
+       tree op0 = gimple_assign_rhs1 (t);
+       tree type0 = get_canon_type (TREE_TYPE (op0), false, false);
+
+       /* For unary operations, if the operation is NEGATE or ABS on
+          a pointer, this is also considered pointer arithmetic and
+          thus, bad for business.  */
+       if (type0
+           && POINTER_TYPE_P (type0)
+           && (TREE_CODE (op0) == NEGATE_EXPR
+             || TREE_CODE (op0) == ABS_EXPR))
+         mark_interesting_type (type0, FULL_ESCAPE);
+
+       check_rhs_var (op0);
+       look_for_casts (op0);
+      }
+      break;
 
-       check_lhs_var (lhs);
-       check_cast (TREE_TYPE (lhs), rhs);
+    case tcc_reference:
+      look_for_casts (gimple_assign_rhs1 (t));
+      check_rhs_var (gimple_assign_rhs1 (t));
+      break;
 
-       /* For the purposes of figuring out what the cast affects */
+    case tcc_declaration:
+      check_rhs_var (gimple_assign_rhs1 (t));
+      break;
 
-       /* Next check the operands on the rhs to see if they are ok. */
-       switch (TREE_CODE_CLASS (TREE_CODE (rhs))) 
-         {
-         case tcc_binary:          
-           {
-             tree op0 = TREE_OPERAND (rhs, 0);
-             tree type0 = get_canon_type (TREE_TYPE (op0), false, false);
-             tree op1 = TREE_OPERAND (rhs, 1);
-             tree type1 = get_canon_type (TREE_TYPE (op1), false, false);
-             /* If this is pointer arithmetic of any bad sort, then
-                we need to mark the types as bad.  For binary
-                operations, no binary operator we currently support
-                is always "safe" in regard to what it would do to
-                pointers for purposes of determining which types
-                escape, except operations of the size of the type.
-                It is possible that min and max under the right set
-                of circumstances and if the moon is in the correct
-                place could be safe, but it is hard to see how this
-                is worth the effort.  */
-             if (type0 && POINTER_TYPE_P (type0)
-                 && !okay_pointer_operation (TREE_CODE (rhs), op0, op1))
-               mark_interesting_type (type0, FULL_ESCAPE);
-             if (type1 && POINTER_TYPE_P (type1)
-                 && !okay_pointer_operation (TREE_CODE (rhs), op1, op0))
-               mark_interesting_type (type1, FULL_ESCAPE);
-             
-             look_for_casts (lhs, op0);
-             look_for_casts (lhs, op1);
-             check_rhs_var (op0);
-             check_rhs_var (op1);
-           }
-           break;
-         case tcc_unary:
-           {
-             tree op0 = TREE_OPERAND (rhs, 0);
-             tree type0 = get_canon_type (TREE_TYPE (op0), false, false);
-             /* For unary operations, if the operation is NEGATE or
-                ABS on a pointer, this is also considered pointer
-                arithmetic and thus, bad for business.  */
-             if (type0 && (TREE_CODE (op0) == NEGATE_EXPR
-                  || TREE_CODE (op0) == ABS_EXPR)
-                 && POINTER_TYPE_P (type0))
-               {
-                 mark_interesting_type (type0, FULL_ESCAPE);
-               }
-             check_rhs_var (op0);
-             look_for_casts (lhs, op0);
-             look_for_casts (lhs, rhs);
-           }
+    case tcc_expression:
+      if (gimple_assign_rhs_code (t) == ADDR_EXPR)
+       {
+         tree rhs = gimple_assign_rhs1 (t);
+         look_for_casts (TREE_OPERAND (rhs, 0));
+         check_rhs_var (rhs);
+       }
+      break;
 
-           break;
-         case tcc_reference:
-           look_for_casts (lhs, rhs);
-           check_rhs_var (rhs);
-           break;
-         case tcc_declaration:
-           check_rhs_var (rhs);
-           break;
-         case tcc_expression:
-           switch (TREE_CODE (rhs)) 
-             {
-             case ADDR_EXPR:
-               look_for_casts (lhs, TREE_OPERAND (rhs, 0));
-               check_rhs_var (rhs);
-               break;
-             default:
-               break;
-             }
-           break;
-         case tcc_vl_exp:
-           switch (TREE_CODE (rhs))
-             {
-             case CALL_EXPR:
-               /* If this is a call to malloc, squirrel away the
-                  result so we do mark the resulting cast as being
-                  bad.  */
-               check_call (rhs);
-               break;
-             default:
-               break;
-             }
-           break;
-         default:
-           break;
-         }
-       *walk_subtrees = 0;
-      }
+    default:
       break;
+    }
+}
+
+
+/* Scan statement T for references to types and mark anything
+   interesting.  */
 
-    case ADDR_EXPR:
-      /* This case is here to find addresses on rhs of constructors in
-        decl_initial of static variables. */
-      check_rhs_var (t);
-      *walk_subtrees = 0;
+static void
+scan_for_refs (gimple t)
+{
+  switch (gimple_code (t))
+    {
+    case GIMPLE_ASSIGN:
+      check_assign (t);
       break;
 
-    case CALL_EXPR: 
+    case GIMPLE_CALL:
+      /* If this is a call to malloc, squirrel away the result so we
+        do mark the resulting cast as being bad.  */
       check_call (t);
-      *walk_subtrees = 0;
       break;
-      
-    case ASM_EXPR:
-      get_asm_expr_operands (t);
-      *walk_subtrees = 0;
+
+    case GIMPLE_ASM:
+      check_asm (t);
       break;
-      
+
     default:
       break;
     }
-  return NULL;
+
+  return;
 }
 
 
 /* The init routine for analyzing global static variable usage.  See
    comments at top for description.  */
-static void 
-ipa_init (void) 
+static void
+ipa_init (void)
 {
   bitmap_obstack_initialize (&ipa_obstack);
   global_types_exposed_parameter = BITMAP_ALLOC (&ipa_obstack);
@@ -1705,7 +1629,7 @@ ipa_init (void)
    compilation unit but their right hand sides may contain references
    to variables defined within this unit.  */
 
-static void 
+static void
 analyze_variable (struct varpool_node *vnode)
 {
   tree global = vnode->decl;
@@ -1720,7 +1644,7 @@ analyze_variable (struct varpool_node *vnode)
   gcc_assert (TREE_CODE (global) == VAR_DECL);
 
   if (DECL_INITIAL (global))
-    walk_tree (&DECL_INITIAL (global), scan_for_refs, NULL, visited_nodes);
+    check_tree (DECL_INITIAL (global));
 }
 
 /* This is the main routine for finding the reference patterns for
@@ -1730,21 +1654,20 @@ static void
 analyze_function (struct cgraph_node *fn)
 {
   tree decl = fn->decl;
-  check_function_parameter_and_return_types (decl, 
+  check_function_parameter_and_return_types (decl,
                                             fn->local.externally_visible);
   if (dump_file)
     fprintf (dump_file, "\n local analysis of %s", cgraph_node_name (fn));
-  
+
   {
     struct function *this_cfun = DECL_STRUCT_FUNCTION (decl);
     basic_block this_block;
 
     FOR_EACH_BB_FN (this_block, this_cfun)
       {
-       block_stmt_iterator bsi;
-       for (bsi = bsi_start (this_block); !bsi_end_p (bsi); bsi_next (&bsi))
-         walk_tree (bsi_stmt_ptr (bsi), scan_for_refs, 
-                    fn, visited_nodes);
+       gimple_stmt_iterator gsi;
+       for (gsi = gsi_start_bb (this_block); !gsi_end_p (gsi); gsi_next (&gsi))
+         scan_for_refs (gsi_stmt (gsi));
       }
   }
 
@@ -1752,16 +1675,15 @@ analyze_function (struct cgraph_node *fn)
   if (DECL_STRUCT_FUNCTION (decl))
     {
       tree step;
-      for (step = DECL_STRUCT_FUNCTION (decl)->unexpanded_var_list;
+      for (step = DECL_STRUCT_FUNCTION (decl)->local_decls;
           step;
           step = TREE_CHAIN (step))
        {
          tree var = TREE_VALUE (step);
-         if (TREE_CODE (var) == VAR_DECL 
+         if (TREE_CODE (var) == VAR_DECL
              && DECL_INITIAL (var)
              && !TREE_STATIC (var))
-           walk_tree (&DECL_INITIAL (var), scan_for_refs, 
-                      fn, visited_nodes);
+           check_tree (DECL_INITIAL (var));
          get_canon_type (TREE_TYPE (var), false, false);
        }
     }
@@ -1773,31 +1695,31 @@ analyze_function (struct cgraph_node *fn)
 static tree
 type_for_uid (int uid)
 {
-  splay_tree_node result = 
+  splay_tree_node result =
     splay_tree_lookup (uid_to_canon_type, (splay_tree_key) uid);
-  
+
   if (result)
-    return (tree) result->value;  
+    return (tree) result->value;
   else return NULL;
 }
 
-/* Return the a bitmap with the subtypes of the type for UID.  If it
+/* Return a bitmap with the subtypes of the type for UID.  If it
    does not exist, return either NULL or a new bitmap depending on the
-   value of CREATE.  */ 
+   value of CREATE.  */
 
 static bitmap
 subtype_map_for_uid (int uid, bool create)
 {
-  splay_tree_node result = splay_tree_lookup (uid_to_subtype_map, 
+  splay_tree_node result = splay_tree_lookup (uid_to_subtype_map,
                              (splay_tree_key) uid);
-  
-  if (result) 
-    return (bitmap) result->value;  
+
+  if (result)
+    return (bitmap) result->value;
   else if (create)
     {
       bitmap subtype_map = BITMAP_ALLOC (&ipa_obstack);
       splay_tree_insert (uid_to_subtype_map,
-                        uid, 
+                        uid,
                         (splay_tree_value)subtype_map);
       return subtype_map;
     }
@@ -1829,17 +1751,17 @@ close_type_seen (tree type)
 
   /* If we are doing a language with a type hierarchy, mark all of
      the superclasses.  */
-  if (TYPE_BINFO (type)) 
+  if (TYPE_BINFO (type))
     for (binfo = TYPE_BINFO (type), i = 0;
         BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
       {
        tree binfo_type = BINFO_TYPE (base_binfo);
-       bitmap subtype_map = subtype_map_for_uid 
+       bitmap subtype_map = subtype_map_for_uid
          (TYPE_UID (TYPE_MAIN_VARIANT (binfo_type)), true);
        bitmap_set_bit (subtype_map, uid);
        close_type_seen (get_canon_type (binfo_type, true, true));
       }
-      
+
   /* If the field is a struct or union type, mark all of the
      subfields.  */
   for (field = TYPE_FIELDS (type);
@@ -1859,7 +1781,7 @@ close_type_seen (tree type)
 /* Take a TYPE that has been passed by value to an external function
    and mark all of the fields that have pointer types as escaping. For
    any of the non pointer types that are structures or unions,
-   recurse.  TYPE is never a pointer type.  */ 
+   recurse.  TYPE is never a pointer type.  */
 
 static void
 close_type_exposed_parameter (tree type)
@@ -1892,13 +1814,13 @@ close_type_exposed_parameter (tree type)
       mark_interesting_type (field_type, EXPOSED_PARAMETER);
 
       /* Only recurse for non pointer types of structures and unions.  */
-      if (ipa_type_escape_star_count_of_interesting_type (field_type) == 0) 
+      if (ipa_type_escape_star_count_of_interesting_type (field_type) == 0)
        close_type_exposed_parameter (field_type);
     }
 }
 
 /* The next function handles the case where a type fully escapes.
-   This means that not only does the type itself escape, 
+   This means that not only does the type itself escape,
 
    a) the type of every field recursively escapes
    b) the type of every subtype escapes as well as the super as well
@@ -1909,7 +1831,7 @@ close_type_exposed_parameter (tree type)
 
    Take a TYPE that has had the address taken for an instance of it
    and mark all of the types for its fields as having their addresses
-   taken. */ 
+   taken. */
 
 static void
 close_type_full_escape (tree type)
@@ -1920,7 +1842,7 @@ close_type_full_escape (tree type)
   tree binfo, base_binfo;
   bitmap_iterator bi;
   bitmap subtype_map;
-  splay_tree_node address_result; 
+  splay_tree_node address_result;
 
   /* Strip off any pointer or array types.  */
   type = get_canon_type (type, true, true);
@@ -1936,7 +1858,7 @@ close_type_full_escape (tree type)
 
   /* If we are doing a language with a type hierarchy, mark all of
      the superclasses.  */
-  if (TYPE_BINFO (type)) 
+  if (TYPE_BINFO (type))
     for (binfo = TYPE_BINFO (type), i = 0;
         BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
       {
@@ -1944,13 +1866,13 @@ close_type_full_escape (tree type)
        binfotype = mark_type (binfotype, FULL_ESCAPE);
        close_type_full_escape (binfotype);
       }
-      
+
   /* Mark as escaped any types that have been down casted to
      this type. */
   if (subtype_map)
     EXECUTE_IF_SET_IN_BITMAP (subtype_map, 0, i, bi)
       {
-       tree subtype = type_for_uid (i); 
+       tree subtype = type_for_uid (i);
        subtype = mark_type (subtype, FULL_ESCAPE);
        close_type_full_escape (subtype);
       }
@@ -1975,7 +1897,7 @@ close_type_full_escape (tree type)
 
   /* For all of the types A that contain this type B and were part of
      an expression like "&...A.B...", mark the A's as escaping.  */
-  address_result = splay_tree_lookup (uid_to_addressof_up_map, 
+  address_result = splay_tree_lookup (uid_to_addressof_up_map,
                                      (splay_tree_key) uid);
   if (address_result)
     {
@@ -1989,21 +1911,21 @@ close_type_full_escape (tree type)
 
 /* Transitively close the addressof bitmap for the type with UID.
    This means that if we had a.b and b.c, a would have both b and c in
-   its maps.  */ 
+   its maps.  */
 
 static bitmap
-close_addressof_down (int uid) 
+close_addressof_down (int uid)
 {
   bitmap_iterator bi;
-  splay_tree_node result = 
+  splay_tree_node result =
     splay_tree_lookup (uid_to_addressof_down_map, (splay_tree_key) uid);
   bitmap map = NULL;
   bitmap new_map;
   unsigned int i;
-  
-  if (result) 
+
+  if (result)
     map = (bitmap) result->value;
-  else 
+  else
     return NULL;
 
   if (bitmap_bit_p (been_there_done_that, uid))
@@ -2027,9 +1949,9 @@ close_addressof_down (int uid)
     {
       bitmap submap = close_addressof_down (i);
       bitmap_set_bit (new_map, i);
-      if (submap) 
+      if (submap)
        bitmap_ior_into (new_map, submap);
-    }      
+    }
   result->value = (splay_tree_value) new_map;
 
   BITMAP_FREE (map);
@@ -2054,17 +1976,15 @@ type_escape_execute (void)
   FOR_EACH_STATIC_VARIABLE (vnode)
     analyze_variable (vnode);
 
-  /* Process all of the functions. next
+  /* Process all of the functions next.
 
      We do not want to process any of the clones so we check that this
      is a master clone.  However, we do need to process any
      AVAIL_OVERWRITABLE functions (these are never clones) because
-     they may cause a type variable to escape.  
+     they may cause a type variable to escape.
   */
   for (node = cgraph_nodes; node; node = node->next)
-    if (node->analyzed 
-       && (cgraph_is_master_clone (node)
-           || (cgraph_function_body_availability (node) == AVAIL_OVERWRITABLE)))
+    if (node->analyzed && !node->clone_of)
       analyze_function (node);
 
 
@@ -2112,7 +2032,7 @@ type_escape_execute (void)
      contained an entry for Y if there had been an operation of the
      form &X.Y.  This step adds all of the fields contained within Y
      (recursively) to X's map.  */
-  
+
   result = splay_tree_min (uid_to_addressof_down_map);
   while (result)
     {
@@ -2130,7 +2050,7 @@ type_escape_execute (void)
     {
       tree type = (tree) result->value;
       tree key = (tree) result->key;
-      if (POINTER_TYPE_P (type) 
+      if (POINTER_TYPE_P (type)
          || TREE_CODE (type) == ARRAY_TYPE)
        {
          splay_tree_remove (all_canon_types, (splay_tree_key) result->key);
@@ -2142,7 +2062,7 @@ type_escape_execute (void)
     }
 
   if (dump_file)
-    { 
+    {
       EXECUTE_IF_SET_IN_BITMAP (global_types_seen, 0, i, bi)
        {
          /* The pointer types are in the global_types_full_escape
@@ -2153,7 +2073,7 @@ type_escape_execute (void)
          print_generic_expr (dump_file, type, 0);
          if (bitmap_bit_p (global_types_full_escape, i))
            fprintf(dump_file, " escaped\n");
-         else 
+         else
            fprintf(dump_file, " contained\n");
        }
     }
@@ -2191,13 +2111,15 @@ type_escape_execute (void)
 static bool
 gate_type_escape_vars (void)
 {
-  return (flag_unit_at_a_time != 0 && flag_ipa_type_escape
+  return (flag_ipa_type_escape
          /* Don't bother doing anything if the program has errors.  */
          && !(errorcount || sorrycount));
 }
 
-struct tree_opt_pass pass_ipa_type_escape =
+struct simple_ipa_opt_pass pass_ipa_type_escape =
 {
+ {
+  SIMPLE_IPA_PASS,
   "type-escape-var",                   /* name */
   gate_type_escape_vars,               /* gate */
   type_escape_execute,                 /* execute */
@@ -2209,7 +2131,6 @@ struct tree_opt_pass pass_ipa_type_escape =
   0,                                   /* properties_provided */
   0,                                   /* properties_destroyed */
   0,                                   /* todo_flags_start */
-  0,                                    /* todo_flags_finish */
-  0                                    /* letter */
+  0                                     /* todo_flags_finish */
+ }
 };
-