OSDN Git Service

PR testsuite/34168
[pf3gnuchains/gcc-fork.git] / gcc / tree-flow-inline.h
index cb2f655..d8593bd 100644 (file)
@@ -1,12 +1,12 @@
 /* Inline functions for tree-flow.h
-   Copyright (C) 2001, 2003, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
    Contributed by Diego Novillo <dnovillo@redhat.com>
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GCC is distributed in the hope that it will be useful,
@@ -15,9 +15,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to
-the Free Software Foundation, 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 #ifndef _TREE_FLOW_INLINE_H
 #define _TREE_FLOW_INLINE_H 1
@@ -30,14 +29,14 @@ Boston, MA 02110-1301, USA.  */
    infrastructure is initialized.  Check for presence of the datastructures
    at first place.  */
 static inline bool
-gimple_in_ssa_p (struct function *fun)
+gimple_in_ssa_p (const struct function *fun)
 {
   return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
 }
 
 /* 'true' after aliases have been computed (see compute_may_aliases).  */
 static inline bool
-gimple_aliases_computed_p (struct function *fun)
+gimple_aliases_computed_p (const struct function *fun)
 {
   gcc_assert (fun && fun->gimple_df);
   return fun->gimple_df->aliases_computed_p;
@@ -51,7 +50,7 @@ gimple_aliases_computed_p (struct function *fun)
    call-clobbered variables are addressable (e.g., a local static
    variable).  */
 static inline bitmap
-gimple_addressable_vars (struct function *fun)
+gimple_addressable_vars (const struct function *fun)
 {
   gcc_assert (fun && fun->gimple_df);
   return fun->gimple_df->addressable_vars;
@@ -60,7 +59,7 @@ gimple_addressable_vars (struct function *fun)
 /* Call clobbered variables in the function.  If bit I is set, then
    REFERENCED_VARS (I) is call-clobbered.  */
 static inline bitmap
-gimple_call_clobbered_vars (struct function *fun)
+gimple_call_clobbered_vars (const struct function *fun)
 {
   gcc_assert (fun && fun->gimple_df);
   return fun->gimple_df->call_clobbered_vars;
@@ -68,7 +67,7 @@ gimple_call_clobbered_vars (struct function *fun)
 
 /* Array of all variables referenced in the function.  */
 static inline htab_t
-gimple_referenced_vars (struct function *fun)
+gimple_referenced_vars (const struct function *fun)
 {
   if (!fun->gimple_df)
     return NULL;
@@ -77,7 +76,7 @@ gimple_referenced_vars (struct function *fun)
 
 /* Artificial variable used to model the effects of function calls.  */
 static inline tree
-gimple_global_var (struct function *fun)
+gimple_global_var (const struct function *fun)
 {
   gcc_assert (fun && fun->gimple_df);
   return fun->gimple_df->global_var;
@@ -86,7 +85,7 @@ gimple_global_var (struct function *fun)
 /* Artificial variable used to model the effects of nonlocal
    variables.  */
 static inline tree
-gimple_nonlocal_all (struct function *fun)
+gimple_nonlocal_all (const struct function *fun)
 {
   gcc_assert (fun && fun->gimple_df);
   return fun->gimple_df->nonlocal_all;
@@ -95,7 +94,7 @@ gimple_nonlocal_all (struct function *fun)
 /* Hashtable of variables annotations.  Used for static variables only;
    local variables have direct pointer in the tree node.  */
 static inline htab_t
-gimple_var_anns (struct function *fun)
+gimple_var_anns (const struct function *fun)
 {
   return fun->gimple_df->var_anns;
 }
@@ -124,7 +123,7 @@ first_htab_element (htab_iterator *hti, htab_t table)
    or NULL if we have  reached the end.  */
 
 static inline bool
-end_htab_p (htab_iterator *hti)
+end_htab_p (const htab_iterator *hti)
 {
   if (hti->slot >= hti->limit)
     return true;
@@ -152,20 +151,15 @@ next_htab_element (htab_iterator *hti)
 static inline tree
 first_referenced_var (referenced_var_iterator *iter)
 {
-  struct int_tree_map *itm;
-  itm = (struct int_tree_map *) first_htab_element (&iter->hti,
-                                                    gimple_referenced_vars
-                                                   (cfun));
-  if (!itm) 
-    return NULL;
-  return itm->to;
+  return (tree) first_htab_element (&iter->hti,
+                                   gimple_referenced_vars (cfun));
 }
 
 /* Return true if we have hit the end of the referenced variables ITER is
    iterating through.  */
 
 static inline bool
-end_referenced_vars_p (referenced_var_iterator *iter)
+end_referenced_vars_p (const referenced_var_iterator *iter)
 {
   return end_htab_p (&iter->hti);
 }
@@ -176,11 +170,7 @@ end_referenced_vars_p (referenced_var_iterator *iter)
 static inline tree
 next_referenced_var (referenced_var_iterator *iter)
 {
-  struct int_tree_map *itm;
-  itm = (struct int_tree_map *) next_htab_element (&iter->hti);
-  if (!itm) 
-    return NULL;
-  return itm->to;
+  return (tree) next_htab_element (&iter->hti);
 } 
 
 /* Fill up VEC with the variables in the referenced vars hashtable.  */
@@ -198,25 +188,30 @@ fill_referenced_var_vec (VEC (tree, heap) **vec)
 /* Return the variable annotation for T, which must be a _DECL node.
    Return NULL if the variable annotation doesn't already exist.  */
 static inline var_ann_t
-var_ann (tree t)
+var_ann (const_tree t)
 {
-  gcc_assert (t);
-  gcc_assert (DECL_P (t));
-  gcc_assert (TREE_CODE (t) != FUNCTION_DECL);
-  if (!MTAG_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
+  var_ann_t ann;
+
+  if (!MTAG_P (t)
+      && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
     {
       struct static_var_ann_d *sann
         = ((struct static_var_ann_d *)
           htab_find_with_hash (gimple_var_anns (cfun), t, DECL_UID (t)));
       if (!sann)
        return NULL;
-      gcc_assert (sann->ann.common.type == VAR_ANN);
-      return &sann->ann;
+      ann = &sann->ann;
     }
-  gcc_assert (!t->base.ann
-             || t->base.ann->common.type == VAR_ANN);
+  else
+    {
+      if (!t->base.ann)
+       return NULL;
+      ann = (var_ann_t) t->base.ann;
+    }
+
+  gcc_assert (ann->common.type == VAR_ANN);
 
-  return (var_ann_t) t->base.ann;
+  return ann;
 }
 
 /* Return the variable annotation for T, which must be a _DECL node.
@@ -231,7 +226,7 @@ get_var_ann (tree var)
 /* Return the function annotation for T, which must be a FUNCTION_DECL node.
    Return NULL if the function annotation doesn't already exist.  */
 static inline function_ann_t
-function_ann (tree t)
+function_ann (const_tree t)
 {
   gcc_assert (t);
   gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
@@ -306,7 +301,7 @@ bb_for_stmt (tree t)
 /* Return the may_aliases bitmap for variable VAR, or NULL if it has
    no may aliases.  */
 static inline bitmap
-may_aliases (tree var)
+may_aliases (const_tree var)
 {
   return MTAG_ALIASES (var);
 }
@@ -314,7 +309,7 @@ may_aliases (tree var)
 /* Return the line number for EXPR, or return -1 if we have no line
    number information for it.  */
 static inline int
-get_lineno (tree expr)
+get_lineno (const_tree expr)
 {
   if (expr == NULL_TREE)
     return -1;
@@ -328,24 +323,6 @@ get_lineno (tree expr)
   return EXPR_LINENO (expr);
 }
 
-/* Return the file name for EXPR, or return "???" if we have no
-   filename information.  */
-static inline const char *
-get_filename (tree expr)
-{
-  const char *filename;
-  if (expr == NULL_TREE)
-    return "???";
-
-  if (TREE_CODE (expr) == COMPOUND_EXPR)
-    expr = TREE_OPERAND (expr, 0);
-
-  if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
-    return filename;
-  else
-    return "???";
-}
-
 /* Return true if T is a noreturn call.  */
 static inline bool
 noreturn_call_p (tree t)
@@ -497,7 +474,7 @@ relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree s
 
 /* Return true is IMM has reached the end of the immediate use list.  */
 static inline bool
-end_readonly_imm_use_p (imm_use_iterator *imm)
+end_readonly_imm_use_p (const imm_use_iterator *imm)
 {
   return (imm->imm_use == imm->end_p);
 }
@@ -525,8 +502,8 @@ next_readonly_imm_use (imm_use_iterator *imm)
   use_operand_p old = imm->imm_use;
 
 #ifdef ENABLE_CHECKING
-  /* If this assertion fails, it indicates the 'next' pointer has changed 
-     since we the last bump.  This indicates that the list is being modified
+  /* If this assertion fails, it indicates the 'next' pointer has changed
+     since the last bump.  This indicates that the list is being modified
      via stmt changes, or SET_USE, or somesuch thing, and you need to be
      using the SAFE version of the iterator.  */
   gcc_assert (imm->iter_node.next == old->next);
@@ -535,26 +512,24 @@ next_readonly_imm_use (imm_use_iterator *imm)
 
   imm->imm_use = old->next;
   if (end_readonly_imm_use_p (imm))
-    return old;
+    return NULL_USE_OPERAND_P;
   return imm->imm_use;
 }
 
 /* Return true if VAR has no uses.  */
 static inline bool
-has_zero_uses (tree var)
+has_zero_uses (const_tree var)
 {
-  ssa_use_operand_t *ptr;
-  ptr = &(SSA_NAME_IMM_USE_NODE (var));
+  const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
   /* A single use means there is no items in the list.  */
   return (ptr == ptr->next);
 }
 
 /* Return true if VAR has a single use.  */
 static inline bool
-has_single_use (tree var)
+has_single_use (const_tree var)
 {
-  ssa_use_operand_t *ptr;
-  ptr = &(SSA_NAME_IMM_USE_NODE (var));
+  const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
   /* A single use means there is one item in the list.  */
   return (ptr != ptr->next && ptr == ptr->next->next);
 }
@@ -563,11 +538,9 @@ has_single_use (tree var)
 /* If VAR has only a single immediate use, return true, and set USE_P and STMT
    to the use pointer and stmt of occurrence.  */
 static inline bool
-single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
+single_imm_use (const_tree var, use_operand_p *use_p, tree *stmt)
 {
-  ssa_use_operand_t *ptr;
-
-  ptr = &(SSA_NAME_IMM_USE_NODE (var));
+  const ssa_use_operand_t *const ptr = &(SSA_NAME_IMM_USE_NODE (var));
   if (ptr != ptr->next && ptr == ptr->next->next)
     {
       *use_p = ptr->next;
@@ -581,13 +554,12 @@ single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
 
 /* Return the number of immediate uses of VAR.  */
 static inline unsigned int
-num_imm_uses (tree var)
+num_imm_uses (const_tree var)
 {
-  ssa_use_operand_t *ptr, *start;
-  unsigned int num;
+  const ssa_use_operand_t *const start = &(SSA_NAME_IMM_USE_NODE (var));
+  const ssa_use_operand_t *ptr;
+  unsigned int num = 0;
 
-  start = &(SSA_NAME_IMM_USE_NODE (var));
-  num = 0;
   for (ptr = start->next; ptr != start; ptr = ptr->next)
      num++;
 
@@ -635,7 +607,7 @@ addresses_taken (tree stmt)
 /* Return the PHI nodes for basic block BB, or NULL if there are no
    PHI nodes.  */
 static inline tree
-phi_nodes (basic_block bb)
+phi_nodes (const_basic_block bb)
 {
   gcc_assert (!(bb->flags & BB_RTL));
   if (!bb->il.tree)
@@ -705,36 +677,11 @@ set_is_used (tree var)
   ann->used = 1;
 }
 
-/* Return true if T is an executable statement.  */
-static inline bool
-is_exec_stmt (tree t)
-{
-  return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
-}
-
-
-/* Return true if this stmt can be the target of a control transfer stmt such
-   as a goto.  */
-static inline bool
-is_label_stmt (tree t)
-{
-  if (t)
-    switch (TREE_CODE (t))
-      {
-       case LABEL_DECL:
-       case LABEL_EXPR:
-       case CASE_LABEL_EXPR:
-         return true;
-       default:
-         return false;
-      }
-  return false;
-}
 
 /* Return true if T (assumed to be a DECL) is a global variable.  */
 
 static inline bool
-is_global_var (tree t)
+is_global_var (const_tree t)
 {
   if (MTAG_P (t))
     return (TREE_STATIC (t) || MTAG_GLOBAL (t));
@@ -747,7 +694,7 @@ is_global_var (tree t)
    slip in in the meantime.  */
 
 static inline bool
-phi_ssa_name_p (tree t)
+phi_ssa_name_p (const_tree t)
 {
   if (TREE_CODE (t) == SSA_NAME)
     return true;
@@ -762,7 +709,7 @@ phi_ssa_name_p (tree t)
 /* Returns the list of statements in BB.  */
 
 static inline tree
-bb_stmt_list (basic_block bb)
+bb_stmt_list (const_basic_block bb)
 {
   gcc_assert (!(bb->flags & BB_RTL));
   return bb->il.tree->stmt_list;
@@ -905,14 +852,14 @@ memory_partition (tree sym)
    name for a memory partition.  */
 
 static inline bool
-factoring_name_p (tree name)
+factoring_name_p (const_tree name)
 {
   return TREE_CODE (SSA_NAME_VAR (name)) == MEMORY_PARTITION_TAG;
 }
 
 /* Return true if VAR is a clobbered by function calls.  */
 static inline bool
-is_call_clobbered (tree var)
+is_call_clobbered (const_tree var)
 {
   if (!MTAG_P (var))
     return var_ann (var)->call_clobbered;
@@ -946,7 +893,7 @@ clear_call_clobbered (tree var)
 /* Return the common annotation for T.  Return NULL if the annotation
    doesn't already exist.  */
 static inline tree_ann_common_t
-tree_common_ann (tree t)
+tree_common_ann (const_tree t)
 {
   /* Watch out static variables with unshared annotations.  */
   if (DECL_P (t) && TREE_CODE (t) == VAR_DECL)
@@ -970,7 +917,7 @@ get_tree_common_ann (tree t)
 
 /* Return true if PTR is finished iterating.  */
 static inline bool
-op_iter_done (ssa_op_iter *ptr)
+op_iter_done (const ssa_op_iter *ptr)
 {
   return ptr->done;
 }
@@ -1436,7 +1383,7 @@ op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
 /* Return true is IMM has reached the end of the immediate use stmt list.  */
 
 static inline bool
-end_imm_use_stmt_p (imm_use_iterator *imm)
+end_imm_use_stmt_p (const imm_use_iterator *imm)
 {
   return (imm->imm_use == imm->end_p);
 }
@@ -1554,7 +1501,6 @@ next_imm_use_stmt (imm_use_iterator *imm)
 
   link_use_stmts_after (imm->imm_use, imm);
   return USE_STMT (imm->imm_use);
-
 }
 
 /* This routine will return the first use on the stmt IMM currently refers
@@ -1570,7 +1516,7 @@ first_imm_use_on_stmt (imm_use_iterator *imm)
 /*  Return TRUE if the last use on the stmt IMM refers to has been visited.  */
 
 static inline bool
-end_imm_use_on_stmt_p (imm_use_iterator *imm)
+end_imm_use_on_stmt_p (const imm_use_iterator *imm)
 {
   return (imm->imm_use == &(imm->iter_node));
 }
@@ -1593,7 +1539,7 @@ next_imm_use_on_stmt (imm_use_iterator *imm)
 /* Return true if VAR cannot be modified by the program.  */
 
 static inline bool
-unmodifiable_var_p (tree var)
+unmodifiable_var_p (const_tree var)
 {
   if (TREE_CODE (var) == SSA_NAME)
     var = SSA_NAME_VAR (var);
@@ -1607,7 +1553,7 @@ unmodifiable_var_p (tree var)
 /* Return true if REF, an ARRAY_REF, has an INDIRECT_REF somewhere in it.  */
 
 static inline bool
-array_ref_contains_indirect_ref (tree ref)
+array_ref_contains_indirect_ref (const_tree ref)
 {
   gcc_assert (TREE_CODE (ref) == ARRAY_REF);
 
@@ -1622,7 +1568,7 @@ array_ref_contains_indirect_ref (tree ref)
    somewhere in it.  */
 
 static inline bool
-ref_contains_array_ref (tree ref)
+ref_contains_array_ref (const_tree ref)
 {
   gcc_assert (handled_component_p (ref));
 
@@ -1639,7 +1585,7 @@ ref_contains_array_ref (tree ref)
    subvariables for it.  */
 
 static inline subvar_t *
-lookup_subvars_for_var (tree var)
+lookup_subvars_for_var (const_tree var)
 {
   var_ann_t ann = var_ann (var);
   gcc_assert (ann);
@@ -1668,21 +1614,95 @@ get_subvars_for_var (tree var)
 static inline tree
 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
 {
-  subvar_t sv;
+  subvar_t sv = get_subvars_for_var (var);
+  int low, high;
+
+  low = 0;
+  high = VEC_length (tree, sv) - 1;
+  while (low <= high)
+    {
+      int mid = (low + high) / 2;
+      tree subvar = VEC_index (tree, sv, mid);
+      if (SFT_OFFSET (subvar) == offset)
+       return subvar;
+      else if (SFT_OFFSET (subvar) < offset)
+       low = mid + 1;
+      else
+       high = mid - 1;
+    }
+
+  return NULL_TREE;
+}
+
+
+/* Return the first subvariable in SV that overlaps [offset, offset + size[.
+   NULL_TREE is returned, if there is no overlapping subvariable, else *I
+   is set to the index in the SV vector of the first overlap.  */
+
+static inline tree
+get_first_overlapping_subvar (subvar_t sv, unsigned HOST_WIDE_INT offset,
+                             unsigned HOST_WIDE_INT size, unsigned int *i)
+{
+  int low = 0;
+  int high = VEC_length (tree, sv) - 1;
+  int mid;
+  tree subvar;
+
+  if (low > high)
+    return NULL_TREE;
+
+  /* Binary search for offset.  */
+  do
+    {
+      mid = (low + high) / 2;
+      subvar = VEC_index (tree, sv, mid);
+      if (SFT_OFFSET (subvar) == offset)
+       {
+         *i = mid;
+         return subvar;
+       }
+      else if (SFT_OFFSET (subvar) < offset)
+       low = mid + 1;
+      else
+       high = mid - 1;
+    }
+  while (low <= high);
+
+  /* As we didn't find a subvar with offset, adjust to return the
+     first overlapping one.  */
+  if (SFT_OFFSET (subvar) < offset
+      && SFT_OFFSET (subvar) + SFT_SIZE (subvar) <= offset)
+    {
+      mid += 1;
+      if ((unsigned)mid >= VEC_length (tree, sv))
+       return NULL_TREE;
+      subvar = VEC_index (tree, sv, mid);
+    }
+  else if (SFT_OFFSET (subvar) > offset
+          && size <= SFT_OFFSET (subvar) - offset)
+    {
+      mid -= 1;
+      if (mid < 0)
+       return NULL_TREE;
+      subvar = VEC_index (tree, sv, mid);
+    }
 
-  for (sv = get_subvars_for_var (var); sv; sv = sv->next)
-    if (SFT_OFFSET (sv->var) == offset)
-      return sv->var;
+  if (overlap_subvar (offset, size, subvar, NULL))
+    {
+      *i = mid;
+      return subvar;
+    }
 
   return NULL_TREE;
 }
 
+
 /* Return true if V is a tree that we can have subvars for.
    Normally, this is any aggregate type.  Also complex
    types which are not gimple registers can have subvars.  */
 
 static inline bool
-var_can_have_subvars (tree v)
+var_can_have_subvars (const_tree v)
 {
   /* Volatile variables should never have subvars.  */
   if (TREE_THIS_VOLATILE (v))
@@ -1705,14 +1725,37 @@ var_can_have_subvars (tree v)
   return false;
 }
 
-  
+
+/* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
+   overlap.  SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
+   range is open-ended.  Otherwise return false.  */
+
+static inline bool
+ranges_overlap_p (unsigned HOST_WIDE_INT pos1,
+                 unsigned HOST_WIDE_INT size1,
+                 unsigned HOST_WIDE_INT pos2,
+                 unsigned HOST_WIDE_INT size2)
+{
+  if (pos1 >= pos2
+      && (size2 == (unsigned HOST_WIDE_INT)-1
+         || pos1 < (pos2 + size2)))
+    return true;
+  if (pos2 >= pos1
+      && (size1 == (unsigned HOST_WIDE_INT)-1
+         || pos2 < (pos1 + size1)))
+    return true;
+
+  return false;
+}
+
+
 /* Return true if OFFSET and SIZE define a range that overlaps with some
    portion of the range of SV, a subvar.  If there was an exact overlap,
    *EXACT will be set to true upon return. */
 
 static inline bool
 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
-               tree sv,  bool *exact)
+               const_tree sv,  bool *exact)
 {
   /* There are three possible cases of overlap.
      1. We can have an exact overlap, like so:   
@@ -1811,15 +1854,31 @@ get_value_handle (tree expr)
 
 /* Accessor to tree-ssa-operands.c caches.  */
 static inline struct ssa_operands *
-gimple_ssa_operands (struct function *fun)
+gimple_ssa_operands (const struct function *fun)
 {
   return &fun->gimple_df->ssa_operands;
 }
 
 /* Map describing reference statistics for function FN.  */
 static inline struct mem_ref_stats_d *
-gimple_mem_ref_stats (struct function *fn)
+gimple_mem_ref_stats (const struct function *fn)
 {
   return &fn->gimple_df->mem_ref_stats;
 }
+
+/* Given an edge_var_map V, return the PHI arg definition.  */
+
+static inline tree
+redirect_edge_var_map_def (edge_var_map *v)
+{
+  return v->def;
+}
+
+/* Given an edge_var_map V, return the PHI result.  */
+
+static inline tree
+redirect_edge_var_map_result (edge_var_map *v)
+{
+  return v->result;
+}
 #endif /* _TREE_FLOW_INLINE_H  */