diff mbox

Add a helper function: create_tmp

Message ID fa3985b4-5880-c149-97f7-cc74383e102b@suse.cz
State New
Headers show

Commit Message

Martin Liška Oct. 11, 2016, 9:28 a.m. UTC
Following patch is a small infrastructure enhancement
in gimple-fold.c.

Tests of the whole series have been running.

Thanks,
Martin

Comments

Richard Biener Oct. 11, 2016, 10:29 a.m. UTC | #1
On Tue, Oct 11, 2016 at 11:28 AM, Martin Liška <mliska@suse.cz> wrote:
> Following patch is a small infrastructure enhancement
> in gimple-fold.c.
>
> Tests of the whole series have been running.

Sorry to be picky, but can you rename it to create_reg_tmp?

Ok with that change.

RIchard.

> Thanks,
> Martin
Richard Biener Oct. 11, 2016, 10:31 a.m. UTC | #2
On Tue, Oct 11, 2016 at 12:29 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Tue, Oct 11, 2016 at 11:28 AM, Martin Liška <mliska@suse.cz> wrote:
>> Following patch is a small infrastructure enhancement
>> in gimple-fold.c.
>>
>> Tests of the whole series have been running.
>
> Sorry to be picky, but can you rename it to create_reg_tmp?

Hrm.  Too easy to confuse with create_tmp_reg ... so maybe
create_tmp_reg_or_ssa_name?

> Ok with that change.
>
> RIchard.
>
>> Thanks,
>> Martin
Martin Liška Oct. 12, 2016, 10:50 a.m. UTC | #3
On 10/11/2016 12:31 PM, Richard Biener wrote:
> Hrm.  Too easy to confuse with create_tmp_reg ... so maybe
> create_tmp_reg_or_ssa_name?

Yep, renamed function patch installed as r241030.

Thanks,
Martin
diff mbox

Patch

From cf5983472b8482734393680493293811e5400d6e Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 11 Oct 2016 11:20:33 +0200
Subject: [PATCH 2/5] Add a helper function: create_tmp

gcc/ChangeLog:

2016-10-11  Martin Liska  <mliska@suse.cz>

	* gimple-fold.c (create_tmp): New function.
	(gimple_fold_builtin_memory_op): Use the function.
	(gimple_fold_builtin_strchr): Likewise.
	(gimple_fold_builtin_strcat): Likewise.
	(gimple_build): Likewise.
---
 gcc/gimple-fold.c | 64 ++++++++++++++++++++-----------------------------------
 1 file changed, 23 insertions(+), 41 deletions(-)

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 3aaa09c..348f331 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -171,6 +171,19 @@  can_refer_decl_in_current_unit_p (tree decl, tree from_decl)
   return !node || !node->global.inlined_to;
 }
 
+/* Create a temporary for TYPE for a statement STMT.  If the current function
+   is in SSA form, a SSA name is created.  Otherwise a temporary register
+   is made.  */
+
+static tree
+create_tmp (tree type, gimple *stmt = NULL)
+{
+  if (gimple_in_ssa_p (cfun))
+    return make_ssa_name (type, stmt);
+  else
+    return create_tmp_reg (type);
+}
+
 /* CVAL is value taken from DECL_INITIAL of variable.  Try to transform it into
    acceptable form for is_gimple_min_invariant.
    FROM_DECL (if non-NULL) specify variable whose constructor contains CVAL.  */
@@ -747,11 +760,7 @@  gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
 		      if (is_gimple_reg_type (TREE_TYPE (srcmem)))
 			{
 			  new_stmt = gimple_build_assign (NULL_TREE, srcmem);
-			  if (gimple_in_ssa_p (cfun))
-			    srcmem = make_ssa_name (TREE_TYPE (srcmem),
-						    new_stmt);
-			  else
-			    srcmem = create_tmp_reg (TREE_TYPE (srcmem));
+			  srcmem = create_tmp (TREE_TYPE (srcmem), new_stmt);
 			  gimple_assign_set_lhs (new_stmt, srcmem);
 			  gimple_set_vuse (new_stmt, gimple_vuse (stmt));
 			  gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
@@ -1038,10 +1047,7 @@  gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
 	  if (! is_gimple_min_invariant (srcvar))
 	    {
 	      new_stmt = gimple_build_assign (NULL_TREE, srcvar);
-	      if (gimple_in_ssa_p (cfun))
-		srcvar = make_ssa_name (TREE_TYPE (srcvar), new_stmt);
-	      else
-		srcvar = create_tmp_reg (TREE_TYPE (srcvar));
+	      srcvar = create_tmp (TREE_TYPE (srcvar), new_stmt);
 	      gimple_assign_set_lhs (new_stmt, srcvar);
 	      gimple_set_vuse (new_stmt, gimple_vuse (stmt));
 	      gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
@@ -1535,10 +1541,7 @@  gimple_fold_builtin_strchr (gimple_stmt_iterator *gsi, bool is_strrchr)
   gimple_seq stmts = NULL;
   gimple *new_stmt = gimple_build_call (strlen_fn, 1, str);
   gimple_set_location (new_stmt, loc);
-  if (gimple_in_ssa_p (cfun))
-    len = make_ssa_name (size_type_node);
-  else
-    len = create_tmp_reg (size_type_node);
+  len = create_tmp (size_type_node);
   gimple_call_set_lhs (new_stmt, len);
   gimple_seq_add_stmt_without_update (&stmts, new_stmt);
 
@@ -1611,10 +1614,7 @@  gimple_fold_builtin_strcat (gimple_stmt_iterator *gsi, tree dst, tree src)
   gimple_seq stmts = NULL, stmts2;
   gimple *repl = gimple_build_call (strlen_fn, 1, dst);
   gimple_set_location (repl, loc);
-  if (gimple_in_ssa_p (cfun))
-    newdst = make_ssa_name (size_type_node);
-  else
-    newdst = create_tmp_reg (size_type_node);
+  newdst = create_tmp (size_type_node);
   gimple_call_set_lhs (repl, newdst);
   gimple_seq_add_stmt_without_update (&stmts, repl);
 
@@ -6376,10 +6376,7 @@  gimple_build (gimple_seq *seq, location_t loc,
   tree res = gimple_simplify (code, type, op0, seq, gimple_build_valueize);
   if (!res)
     {
-      if (gimple_in_ssa_p (cfun))
-	res = make_ssa_name (type);
-      else
-	res = create_tmp_reg (type);
+      res = create_tmp (type);
       gimple *stmt;
       if (code == REALPART_EXPR
 	  || code == IMAGPART_EXPR
@@ -6405,10 +6402,7 @@  gimple_build (gimple_seq *seq, location_t loc,
   tree res = gimple_simplify (code, type, op0, op1, seq, gimple_build_valueize);
   if (!res)
     {
-      if (gimple_in_ssa_p (cfun))
-	res = make_ssa_name (type);
-      else
-	res = create_tmp_reg (type);
+      res = create_tmp (type);
       gimple *stmt = gimple_build_assign (res, code, op0, op1);
       gimple_set_location (stmt, loc);
       gimple_seq_add_stmt_without_update (seq, stmt);
@@ -6429,10 +6423,7 @@  gimple_build (gimple_seq *seq, location_t loc,
 			      seq, gimple_build_valueize);
   if (!res)
     {
-      if (gimple_in_ssa_p (cfun))
-	res = make_ssa_name (type);
-      else
-	res = create_tmp_reg (type);
+      res = create_tmp (type);
       gimple *stmt;
       if (code == BIT_FIELD_REF)
 	stmt = gimple_build_assign (res, code,
@@ -6462,10 +6453,7 @@  gimple_build (gimple_seq *seq, location_t loc,
       gimple *stmt = gimple_build_call (decl, 1, arg0);
       if (!VOID_TYPE_P (type))
 	{
-	  if (gimple_in_ssa_p (cfun))
-	    res = make_ssa_name (type);
-	  else
-	    res = create_tmp_reg (type);
+	  res = create_tmp (type);
 	  gimple_call_set_lhs (stmt, res);
 	}
       gimple_set_location (stmt, loc);
@@ -6491,10 +6479,7 @@  gimple_build (gimple_seq *seq, location_t loc,
       gimple *stmt = gimple_build_call (decl, 2, arg0, arg1);
       if (!VOID_TYPE_P (type))
 	{
-	  if (gimple_in_ssa_p (cfun))
-	    res = make_ssa_name (type);
-	  else
-	    res = create_tmp_reg (type);
+	  res = create_tmp (type);
 	  gimple_call_set_lhs (stmt, res);
 	}
       gimple_set_location (stmt, loc);
@@ -6522,10 +6507,7 @@  gimple_build (gimple_seq *seq, location_t loc,
       gimple *stmt = gimple_build_call (decl, 3, arg0, arg1, arg2);
       if (!VOID_TYPE_P (type))
 	{
-	  if (gimple_in_ssa_p (cfun))
-	    res = make_ssa_name (type);
-	  else
-	    res = create_tmp_reg (type);
+	  res = create_tmp (type);
 	  gimple_call_set_lhs (stmt, res);
 	}
       gimple_set_location (stmt, loc);
-- 
2.9.2