This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[tuples] Fix GS_CALL gimplification


When gimplifying CALL_EXPRs that need to return a value, we were not
setting the LHS of the call properly.  To create the temporary, we
cannot use the existing formal temporary table support because it is
purely tree-based, so for now I added a new temporary variable creation
that should eventually get its own support for formal temporaries.

Tested with gimple.exp.  Committed.
2007-07-15  Diego Novillo  <dnovillo@google.com>

	* gimple-ir.c (gimple_statement_structure): Remove code
	after gcc_unreachable call.
	* gimplify.c (get_tmp_var_for): New.
	(gimplify_call_expr): Call it.


testsuite/ChangeLog.tuples:

	* gcc.dg/gimple/call.c: Add strings to expect in the .gimple file.

Index: testsuite/gcc.dg/gimple/call.c
===================================================================
--- testsuite/gcc.dg/gimple/call.c	(revision 126643)
+++ testsuite/gcc.dg/gimple/call.c	(working copy)
@@ -8,3 +8,7 @@ baz (int i)
   int a = foo (bar (i));
   return a;
 }
+
+/* { dg-final { scan-tree-dump-times "gimpleir: bar.0 = bar \\(i\\)" 1 "gimple"} } */
+/* { dg-final { scan-tree-dump-times "gimpleir: foo.1 = foo \\(bar.0\\)" 1 "gimple"} } */
+/* { dg-final { cleanup-tree-dump "gimple" } } */
Index: gimple-ir.c
===================================================================
--- gimple-ir.c	(revision 126643)
+++ gimple-ir.c	(working copy)
@@ -727,7 +727,6 @@ gimple_statement_structure (gimple gs)
     case GS_OMP_SINGLE:		return GSS_OMP_SINGLE;
     default:
       gcc_unreachable ();
-      return GSS_BASE;
     }
 }
 
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 126643)
+++ gimplify.c	(working copy)
@@ -618,6 +618,30 @@ get_initialized_tmp_var (tree val, gs_se
   return internal_get_tmp_var (val, pre_p, post_p, false);
 }
 
+/* Create a temporary variable to be used as the LHS of the given GIMPLE
+   statement STMT. STMT must be GS_ASSIGN or GS_CALL.  If IS_FORMAL is
+   true, try to return a temporary from the formal temporaries table
+   (which will attempt to return the same temporary created for a
+   previous statement identical to STMT.  */
+
+static tree
+get_tmp_var_for (gimple stmt)
+{
+  tree lhs;
+  enum gs_code code = GS_CODE (stmt);
+
+  /* FIXME tuples, add support for formal temporaries (worth it?)  */
+  if (GS_CODE (stmt) == GS_ASSIGN)
+    return create_tmp_from_val (gs_assign_operand (stmt, 1));
+  else if (GS_CODE (stmt) == GS_CALL)
+    return create_tmp_from_val (gs_call_fn (stmt));
+  else
+    gcc_unreachable ();
+
+  return lhs;
+}
+
+
 /* Declares all the variables in VARS in SCOPE.  If DEBUG_INFO is
    true, generate debug info for them; otherwise don't.  */
 
@@ -2063,6 +2087,7 @@ gimplify_call_expr (tree *expr_p, gs_seq
   enum gimplify_status ret;
   int i, nargs;
   VEC(tree, gc) *args = NULL;
+  gimple call;
 
   gcc_assert (TREE_CODE (*expr_p) == CALL_EXPR);
 
@@ -2163,8 +2188,17 @@ gimplify_call_expr (tree *expr_p, gs_seq
       && (call_expr_flags (*expr_p) & (ECF_CONST | ECF_PURE)))
     TREE_SIDE_EFFECTS (*expr_p) = 0;
 
-  gs_add (pre_p, gs_build_call_vec (fndecl, args));
-  if (!want_value)
+  /* Now add the GIMPLE call to PRE_P.  If WANT_VALUE is set, we need
+     to create the appropriate temporary for the call's LHS.  */
+  call = gs_build_call_vec (fndecl, args);
+  gs_add (pre_p, call);
+  if (want_value)
+    {
+      tree lhs = get_tmp_var_for (call);
+      gs_call_set_lhs (call, lhs);
+      *expr_p = lhs;
+    }
+  else
     *expr_p = NULL_TREE;
 
   return ret;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]