On 11/07/13 10:58, Martin Jambor wrote:

Sorry for the delay.  I'd just like to re-iterate one comment from my
previous email which is that I do not think tree-sra.c should export
any function to the outside world apart from the entry points of the
passes (yes, there is already build_ref_for_offset which I admit is
entirely my creation but that should be moved elswhere too).

So please put sra_ipa_get_adjustment_candidate to ipa-prop.c.  I see
that it requires get_ssa_base_param to be moved there as well but
since IPA-SRA uses it in different places, it would need exporting
too, which would be weird because it does not really do anything with
parameters.  Since the function is so trivial, I would even suggest
introducing another private copy to ipa-prop.c (and leaving the
original without the new parameter).  Alternatively, you can move the
function to tree.c but for that it looks too specialized.

Done.

Note that I didn't have to move
ipa_sra_modify_function_body, since it wasn't used outside of tree-sra.c, and omp-low.c has its own version. Instead I just removed it from ipa-prop.h where I had inadvertently placed it.

OK for branch?
commit c7602b7b88a9e85c7e3076e38d471be5bc728089
Author: Aldy Hernandez <al...@redhat.com>
Date:   Mon Nov 11 10:10:47 2013 -0700

        * ipa-prop.c (get_ssa_base_param): New.
        * ipa-prop.h (ipa_modify_expr): Rename from ipa_sra_modify_expr.
        Remove ipa_sra_modify_function_body.
        (ipa_get_adjustment_candidate): Rename from
        sra_ipa_get_adjustment_candidate.
        * omp-low.c (ipa_simd_modify_stmt_ops): Rename
        sra_ipa_get_adjustment_candidate to ipa_get_adjustment_candidate.
        * tree-sra.c (get_ssa_base_param): Remove default_def argument.
        (create_access): Remove lass argument to get_ssa_base_param.
        (disqualify_base_of_expr): Same.
        (sra_ipa_get_adjustment_candidate): Rename to
        ipa_get_adjustment_candidate and move to ipa-prop.c.
        (sra_ipa_modify_expr): Rename to ipa_modify_expr and move to
        ipa-prop.c.
        (sra_ipa_modify_assign): Rename sra_ipa_modify_expr to
        ipa_modify_expr.
        (ipa_sra_modify_function_body): Same.

diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
index 76e9b61..042d623 100644
--- a/gcc/ipa-prop.c
+++ b/gcc/ipa-prop.c
@@ -3756,6 +3756,124 @@ ipa_modify_call_arguments (struct cgraph_edge *cs, 
gimple stmt,
   free_dominance_info (CDI_DOMINATORS);
 }
 
+/* If the expression *EXPR should be replaced by a reduction of a parameter, do
+   so.  ADJUSTMENTS is a pointer to a vector of adjustments.  CONVERT
+   specifies whether the function should care about type incompatibility the
+   current and new expressions.  If it is false, the function will leave
+   incompatibility issues to the caller.  Return true iff the expression
+   was modified. */
+
+bool
+ipa_modify_expr (tree *expr, bool convert,
+                ipa_parm_adjustment_vec adjustments)
+{
+  struct ipa_parm_adjustment *cand
+    = ipa_get_adjustment_candidate (expr, &convert, adjustments, false);
+  if (!cand)
+    return false;
+
+  tree src;
+  if (cand->by_ref)
+    src = build_simple_mem_ref (cand->new_decl);
+  else
+    src = cand->new_decl;
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    {
+      fprintf (dump_file, "About to replace expr ");
+      print_generic_expr (dump_file, *expr, 0);
+      fprintf (dump_file, " with ");
+      print_generic_expr (dump_file, src, 0);
+      fprintf (dump_file, "\n");
+    }
+
+  if (convert && !useless_type_conversion_p (TREE_TYPE (*expr), cand->type))
+    {
+      tree vce = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (*expr), src);
+      *expr = vce;
+    }
+  else
+    *expr = src;
+  return true;
+}
+
+/* If T is an SSA_NAME, return NULL if it is not a default def or
+   return its base variable if it is.  If IGNORE_DEFAULT_DEF is true,
+   the base variable is always returned, regardless if it is a default
+   def.  Return T if it is not an SSA_NAME.  */
+
+static tree
+get_ssa_base_param (tree t, bool ignore_default_def)
+{
+  if (TREE_CODE (t) == SSA_NAME)
+    {
+      if (ignore_default_def || SSA_NAME_IS_DEFAULT_DEF (t))
+       return SSA_NAME_VAR (t);
+      else
+       return NULL_TREE;
+    }
+  return t;
+}
+
+/* Given an expression, return an adjustment entry specifying the
+   transformation to be done on EXPR.  If no suitable adjustment entry
+   was found, returns NULL.
+
+   If IGNORE_DEFAULT_DEF is set, consider SSA_NAMEs which are not a
+   default def, otherwise bail on them.
+
+   If CONVERT is non-NULL, this function will set *CONVERT if the
+   expression provided is a component reference that must be converted
+   upon return.  ADJUSTMENTS is the adjustments vector.  */
+
+ipa_parm_adjustment *
+ipa_get_adjustment_candidate (tree *&expr, bool *convert,
+                             ipa_parm_adjustment_vec adjustments,
+                             bool ignore_default_def)
+{
+  if (TREE_CODE (*expr) == BIT_FIELD_REF
+      || TREE_CODE (*expr) == IMAGPART_EXPR
+      || TREE_CODE (*expr) == REALPART_EXPR)
+    {
+      expr = &TREE_OPERAND (*expr, 0);
+      if (convert)
+       *convert = true;
+    }
+
+  HOST_WIDE_INT offset, size, max_size;
+  tree base = get_ref_base_and_extent (*expr, &offset, &size, &max_size);
+  if (!base || size == -1 || max_size == -1)
+    return NULL;
+
+  if (TREE_CODE (base) == MEM_REF)
+    {
+      offset += mem_ref_offset (base).low * BITS_PER_UNIT;
+      base = TREE_OPERAND (base, 0);
+    }
+
+  base = get_ssa_base_param (base, ignore_default_def);
+  if (!base || TREE_CODE (base) != PARM_DECL)
+    return NULL;
+
+  struct ipa_parm_adjustment *cand = NULL;
+  unsigned int len = adjustments.length ();
+  for (unsigned i = 0; i < len; i++)
+    {
+      struct ipa_parm_adjustment *adj = &adjustments[i];
+
+      if (adj->base == base
+         && (adj->offset == offset || adj->op == IPA_PARM_OP_REMOVE))
+       {
+         cand = adj;
+         break;
+       }
+    }
+
+  if (!cand || cand->op == IPA_PARM_OP_COPY || cand->op == IPA_PARM_OP_REMOVE)
+    return NULL;
+  return cand;
+}
+
 /* Return true iff BASE_INDEX is in ADJUSTMENTS more than once.  */
 
 static bool
diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h
index e1e8622..28ef013 100644
--- a/gcc/ipa-prop.h
+++ b/gcc/ipa-prop.h
@@ -716,15 +716,14 @@ tree ipa_value_from_jfunc (struct ipa_node_params *info,
                           struct ipa_jump_func *jfunc);
 unsigned int ipcp_transform_function (struct cgraph_node *node);
 void ipa_dump_param (FILE *, struct ipa_node_params *info, int i);
+bool ipa_modify_expr (tree *, bool, ipa_parm_adjustment_vec);
+ipa_parm_adjustment *ipa_get_adjustment_candidate (tree *&, bool *,
+                                                  ipa_parm_adjustment_vec,
+                                                  bool);
 
 
 /* From tree-sra.c:  */
 tree build_ref_for_offset (location_t, tree, HOST_WIDE_INT, tree,
                           gimple_stmt_iterator *, bool);
-bool ipa_sra_modify_function_body (ipa_parm_adjustment_vec);
-bool sra_ipa_modify_expr (tree *, bool, ipa_parm_adjustment_vec);
-ipa_parm_adjustment *sra_ipa_get_adjustment_candidate (tree *&, bool *,
-                                                      ipa_parm_adjustment_vec,
-                                                      bool);
 
 #endif /* IPA_PROP_H */
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 51cda58..980af84 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -11739,7 +11739,7 @@ ipa_simd_modify_stmt_ops (tree *tp, int *walk_subtrees, 
void *data)
     }
   struct modify_stmt_info *info = (struct modify_stmt_info *) wi->info;
   struct ipa_parm_adjustment *cand
-    = sra_ipa_get_adjustment_candidate (tp, NULL, info->adjustments, true);
+    = ipa_get_adjustment_candidate (tp, NULL, info->adjustments, true);
   if (!cand)
     return NULL_TREE;
 
diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c
index 2f19899..721751e 100644
--- a/gcc/tree-sra.c
+++ b/gcc/tree-sra.c
@@ -785,17 +785,15 @@ type_internals_preclude_sra_p (tree type, const char 
**msg)
     }
 }
 
-/* If T is an SSA_NAME, return NULL if it is not a default def or
-   return its base variable if it is.  If IGNORE_DEFAULT_DEF is true,
-   the base variable is always returned, regardless if it is a default
-   def.  Return T if it is not an SSA_NAME.  */
+/* If T is an SSA_NAME, return NULL if it is not a default def or return its
+   base variable if it is.  Return T if it is not an SSA_NAME.  */
 
 static tree
-get_ssa_base_param (tree t, bool ignore_default_def)
+get_ssa_base_param (tree t)
 {
   if (TREE_CODE (t) == SSA_NAME)
     {
-      if (ignore_default_def || SSA_NAME_IS_DEFAULT_DEF (t))
+      if (SSA_NAME_IS_DEFAULT_DEF (t))
        return SSA_NAME_VAR (t);
       else
        return NULL_TREE;
@@ -876,7 +874,7 @@ create_access (tree expr, gimple stmt, bool write)
   if (sra_mode == SRA_MODE_EARLY_IPA
       && TREE_CODE (base) == MEM_REF)
     {
-      base = get_ssa_base_param (TREE_OPERAND (base, 0), false);
+      base = get_ssa_base_param (TREE_OPERAND (base, 0));
       if (!base)
        return NULL;
       ptr = true;
@@ -1041,7 +1039,7 @@ disqualify_base_of_expr (tree t, const char *reason)
   t = get_base_address (t);
   if (sra_mode == SRA_MODE_EARLY_IPA
       && TREE_CODE (t) == MEM_REF)
-    t = get_ssa_base_param (TREE_OPERAND (t, 0), false);
+    t = get_ssa_base_param (TREE_OPERAND (t, 0));
 
   if (t && DECL_P (t))
     disqualify_candidate (t, reason);
@@ -4489,106 +4487,6 @@ replace_removed_params_ssa_names (gimple stmt,
   return true;
 }
 
-/* Given an expression, return an adjustment entry specifying the
-   transformation to be done on EXPR.  If no suitable adjustment entry
-   was found, returns NULL.
-
-   If IGNORE_DEFAULT_DEF is set, consider SSA_NAMEs which are not a
-   default def, otherwise bail on them.
-
-   If CONVERT is non-NULL, this function will set *CONVERT if the
-   expression provided is a component reference that must be converted
-   upon return.  ADJUSTMENTS is the adjustments vector.  */
-
-ipa_parm_adjustment *
-sra_ipa_get_adjustment_candidate (tree *&expr, bool *convert,
-                                 ipa_parm_adjustment_vec adjustments,
-                                 bool ignore_default_def)
-{
-  if (TREE_CODE (*expr) == BIT_FIELD_REF
-      || TREE_CODE (*expr) == IMAGPART_EXPR
-      || TREE_CODE (*expr) == REALPART_EXPR)
-    {
-      expr = &TREE_OPERAND (*expr, 0);
-      if (convert)
-       *convert = true;
-    }
-
-  HOST_WIDE_INT offset, size, max_size;
-  tree base = get_ref_base_and_extent (*expr, &offset, &size, &max_size);
-  if (!base || size == -1 || max_size == -1)
-    return NULL;
-
-  if (TREE_CODE (base) == MEM_REF)
-    {
-      offset += mem_ref_offset (base).low * BITS_PER_UNIT;
-      base = TREE_OPERAND (base, 0);
-    }
-
-  base = get_ssa_base_param (base, ignore_default_def);
-  if (!base || TREE_CODE (base) != PARM_DECL)
-    return NULL;
-
-  struct ipa_parm_adjustment *cand = NULL;
-  unsigned int len = adjustments.length ();
-  for (unsigned i = 0; i < len; i++)
-    {
-      struct ipa_parm_adjustment *adj = &adjustments[i];
-
-      if (adj->base == base
-         && (adj->offset == offset || adj->op == IPA_PARM_OP_REMOVE))
-       {
-         cand = adj;
-         break;
-       }
-    }
-
-  if (!cand || cand->op == IPA_PARM_OP_COPY || cand->op == IPA_PARM_OP_REMOVE)
-    return NULL;
-  return cand;
-}
-
-/* If the expression *EXPR should be replaced by a reduction of a parameter, do
-   so.  ADJUSTMENTS is a pointer to a vector of adjustments.  CONVERT
-   specifies whether the function should care about type incompatibility the
-   current and new expressions.  If it is false, the function will leave
-   incompatibility issues to the caller.  Return true iff the expression
-   was modified. */
-
-bool
-sra_ipa_modify_expr (tree *expr, bool convert,
-                    ipa_parm_adjustment_vec adjustments)
-{
-  struct ipa_parm_adjustment *cand
-    = sra_ipa_get_adjustment_candidate (expr, &convert, adjustments, false);
-  if (!cand)
-    return false;
-
-  tree src;
-  if (cand->by_ref)
-    src = build_simple_mem_ref (cand->new_decl);
-  else
-    src = cand->new_decl;
-
-  if (dump_file && (dump_flags & TDF_DETAILS))
-    {
-      fprintf (dump_file, "About to replace expr ");
-      print_generic_expr (dump_file, *expr, 0);
-      fprintf (dump_file, " with ");
-      print_generic_expr (dump_file, src, 0);
-      fprintf (dump_file, "\n");
-    }
-
-  if (convert && !useless_type_conversion_p (TREE_TYPE (*expr), cand->type))
-    {
-      tree vce = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (*expr), src);
-      *expr = vce;
-    }
-  else
-    *expr = src;
-  return true;
-}
-
 /* If the statement pointed to by STMT_PTR contains any expressions that need
    to replaced with a different one as noted by ADJUSTMENTS, do so.  Handle any
    potential type incompatibilities (GSI is used to accommodate conversion
@@ -4609,8 +4507,8 @@ sra_ipa_modify_assign (gimple *stmt_ptr, 
gimple_stmt_iterator *gsi,
   rhs_p = gimple_assign_rhs1_ptr (stmt);
   lhs_p = gimple_assign_lhs_ptr (stmt);
 
-  any = sra_ipa_modify_expr (rhs_p, false, adjustments);
-  any |= sra_ipa_modify_expr (lhs_p, false, adjustments);
+  any = ipa_modify_expr (rhs_p, false, adjustments);
+  any |= ipa_modify_expr (lhs_p, false, adjustments);
   if (any)
     {
       tree new_rhs = NULL_TREE;
@@ -4682,7 +4580,7 @@ ipa_sra_modify_function_body (ipa_parm_adjustment_vec 
adjustments)
            case GIMPLE_RETURN:
              t = gimple_return_retval_ptr (stmt);
              if (*t != NULL_TREE)
-               modified |= sra_ipa_modify_expr (t, true, adjustments);
+               modified |= ipa_modify_expr (t, true, adjustments);
              break;
 
            case GIMPLE_ASSIGN:
@@ -4695,13 +4593,13 @@ ipa_sra_modify_function_body (ipa_parm_adjustment_vec 
adjustments)
              for (i = 0; i < gimple_call_num_args (stmt); i++)
                {
                  t = gimple_call_arg_ptr (stmt, i);
-                 modified |= sra_ipa_modify_expr (t, true, adjustments);
+                 modified |= ipa_modify_expr (t, true, adjustments);
                }
 
              if (gimple_call_lhs (stmt))
                {
                  t = gimple_call_lhs_ptr (stmt);
-                 modified |= sra_ipa_modify_expr (t, false, adjustments);
+                 modified |= ipa_modify_expr (t, false, adjustments);
                  modified |= replace_removed_params_ssa_names (stmt,
                                                                adjustments);
                }
@@ -4711,12 +4609,12 @@ ipa_sra_modify_function_body (ipa_parm_adjustment_vec 
adjustments)
              for (i = 0; i < gimple_asm_ninputs (stmt); i++)
                {
                  t = &TREE_VALUE (gimple_asm_input_op (stmt, i));
-                 modified |= sra_ipa_modify_expr (t, true, adjustments);
+                 modified |= ipa_modify_expr (t, true, adjustments);
                }
              for (i = 0; i < gimple_asm_noutputs (stmt); i++)
                {
                  t = &TREE_VALUE (gimple_asm_output_op (stmt, i));
-                 modified |= sra_ipa_modify_expr (t, false, adjustments);
+                 modified |= ipa_modify_expr (t, false, adjustments);
                }
              break;
 

Reply via email to