Convert character arrays to string csts

Submitted by Martin Liška on Aug. 9, 2017, 11:39 a.m.

Details

Message ID b373fc4d-8acb-a65d-7b0a-81c196ed0b00@suse.cz
State New
Headers show

Commit Message

Martin Liška Aug. 9, 2017, 11:39 a.m.
On 08/09/2017 11:43 AM, Richard Biener wrote:
> I only have the patch I sent you so I can't re-diff.
> 
> Richard.

Hi.

I'm sending rebased version of the patch. However the patch
eats all my memory when e.g. building ../../../libgcc/libgcov-merge.c.
If you have time, please try to make it working for &STRING_CST. I can continue
then.

Thanks,
Martin

Comments

Richard Guenther Aug. 14, 2017, 11:23 a.m.
On Wed, Aug 9, 2017 at 1:39 PM, Martin Liška <mliska@suse.cz> wrote:
> On 08/09/2017 11:43 AM, Richard Biener wrote:
>> I only have the patch I sent you so I can't re-diff.
>>
>> Richard.
>
> Hi.
>
> I'm sending rebased version of the patch. However the patch
> eats all my memory when e.g. building ../../../libgcc/libgcov-merge.c.
> If you have time, please try to make it working for &STRING_CST. I can continue
> then.

Note I didn't send the patch to make you use it -- it changes too much and I
never fixed all the fall out.  It was meant as an exercise on how to
use a CONST_DECL.

Richard.

> Thanks,
> Martin
Richard Guenther Aug. 14, 2017, 11:25 a.m.
On Mon, Aug 14, 2017 at 1:23 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Wed, Aug 9, 2017 at 1:39 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 08/09/2017 11:43 AM, Richard Biener wrote:
>>> I only have the patch I sent you so I can't re-diff.
>>>
>>> Richard.
>>
>> Hi.
>>
>> I'm sending rebased version of the patch. However the patch
>> eats all my memory when e.g. building ../../../libgcc/libgcov-merge.c.
>> If you have time, please try to make it working for &STRING_CST. I can continue
>> then.
>
> Note I didn't send the patch to make you use it -- it changes too much and I
> never fixed all the fall out.  It was meant as an exercise on how to
> use a CONST_DECL.

Btw. the

@@ -732,7 +730,7 @@ is_gimple_reg (tree t)
   if (virtual_operand_p (t))
     return false;

-  if (TREE_CODE (t) == SSA_NAME)
+  if (TREE_CODE (t) == SSA_NAME || TREE_CODE (t) == CONST_DECL)
     return true;

   if (!is_gimple_variable (t))

hunk looks wrong.

Richard.

> Richard.
>
>> Thanks,
>> Martin
Richard Guenther Aug. 14, 2017, 11:58 a.m.
On Mon, Aug 14, 2017 at 1:25 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Mon, Aug 14, 2017 at 1:23 PM, Richard Biener
> <richard.guenther@gmail.com> wrote:
>> On Wed, Aug 9, 2017 at 1:39 PM, Martin Liška <mliska@suse.cz> wrote:
>>> On 08/09/2017 11:43 AM, Richard Biener wrote:
>>>> I only have the patch I sent you so I can't re-diff.
>>>>
>>>> Richard.
>>>
>>> Hi.
>>>
>>> I'm sending rebased version of the patch. However the patch
>>> eats all my memory when e.g. building ../../../libgcc/libgcov-merge.c.
>>> If you have time, please try to make it working for &STRING_CST. I can continue
>>> then.
>>
>> Note I didn't send the patch to make you use it -- it changes too much and I
>> never fixed all the fall out.  It was meant as an exercise on how to
>> use a CONST_DECL.
>
> Btw. the
>
> @@ -732,7 +730,7 @@ is_gimple_reg (tree t)
>    if (virtual_operand_p (t))
>      return false;
>
> -  if (TREE_CODE (t) == SSA_NAME)
> +  if (TREE_CODE (t) == SSA_NAME || TREE_CODE (t) == CONST_DECL)
>      return true;
>
>    if (!is_gimple_variable (t))
>
> hunk looks wrong.

Oh, and the gimplifier.c hunk was misapplied - the gimplification to CONST_DECL
is supposed to only happen for STRING_CSTs, not arbitrary constants.

Updated patch attached.

Richard.

>
> Richard.
>
>> Richard.
>>
>>> Thanks,
>>> Martin

Patch hide | download patch | download mbox

diff --git a/gcc/gimple-expr.c b/gcc/gimple-expr.c
index c1771fcf1d0..eb22456c241 100644
--- a/gcc/gimple-expr.c
+++ b/gcc/gimple-expr.c
@@ -631,7 +631,7 @@  is_gimple_address (const_tree t)
       op = TREE_OPERAND (op, 0);
     }
 
-  if (CONSTANT_CLASS_P (op) || TREE_CODE (op) == MEM_REF)
+  if (TREE_CODE (op) == MEM_REF)
     return true;
 
   switch (TREE_CODE (op))
@@ -667,11 +667,10 @@  is_gimple_invariant_address (const_tree t)
     {
       const_tree op0 = TREE_OPERAND (op, 0);
       return (TREE_CODE (op0) == ADDR_EXPR
-	      && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
-		  || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
+	      && decl_address_invariant_p (TREE_OPERAND (op0, 0)));
     }
 
-  return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
+  return decl_address_invariant_p (op);
 }
 
 /* Return true if T is a gimple invariant address at IPA level
@@ -693,11 +692,10 @@  is_gimple_ip_invariant_address (const_tree t)
     {
       const_tree op0 = TREE_OPERAND (op, 0);
       return (TREE_CODE (op0) == ADDR_EXPR
-	      && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
-		  || decl_address_ip_invariant_p (TREE_OPERAND (op0, 0))));
+	      && decl_address_ip_invariant_p (TREE_OPERAND (op0, 0)));
     }
 
-  return CONSTANT_CLASS_P (op) || decl_address_ip_invariant_p (op);
+  return decl_address_ip_invariant_p (op);
 }
 
 /* Return true if T is a GIMPLE minimal invariant.  It's a restricted
@@ -732,7 +730,7 @@  is_gimple_reg (tree t)
   if (virtual_operand_p (t))
     return false;
 
-  if (TREE_CODE (t) == SSA_NAME)
+  if (TREE_CODE (t) == SSA_NAME || TREE_CODE (t) == CONST_DECL)
     return true;
 
   if (!is_gimple_variable (t))
@@ -825,8 +823,7 @@  is_gimple_mem_ref_addr (tree t)
   return (is_gimple_reg (t)
 	  || TREE_CODE (t) == INTEGER_CST
 	  || (TREE_CODE (t) == ADDR_EXPR
-	      && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
-		  || decl_address_invariant_p (TREE_OPERAND (t, 0)))));
+	      && decl_address_invariant_p (TREE_OPERAND (t, 0))));
 }
 
 /* Hold trees marked addressable during expand.  */
diff --git a/gcc/gimple-expr.h b/gcc/gimple-expr.h
index 6e969164a37..04de209c092 100644
--- a/gcc/gimple-expr.h
+++ b/gcc/gimple-expr.h
@@ -94,9 +94,7 @@  is_gimple_id (tree t)
   return (is_gimple_variable (t)
 	  || TREE_CODE (t) == FUNCTION_DECL
 	  || TREE_CODE (t) == LABEL_DECL
-	  || TREE_CODE (t) == CONST_DECL
-	  /* Allow string constants, since they are addressable.  */
-	  || TREE_CODE (t) == STRING_CST);
+	  || TREE_CODE (t) == CONST_DECL);
 }
 
 /* Return true if OP, an SSA name or a DECL is a virtual operand.  */
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 86623e09f5d..d56d1dfe8ab 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -2871,7 +2871,8 @@  gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
      so as to match the min_lval predicate.  Failure to do so may result
      in the creation of large aggregate temporaries.  */
   tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval,
-			fallback | fb_lvalue);
+			expr_stack.length () > 0
+			? fb_lvalue : fallback | fb_lvalue);
   ret = MIN (ret, tret);
 
   /* And finally, the indices and operands of ARRAY_REF.  During this
@@ -11503,7 +11504,17 @@  gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
 	     that in the GIMPLE IL.  */
 	  if (TREE_OVERFLOW_P (*expr_p))
 	    *expr_p = drop_tree_overflow (*expr_p);
-	  ret = GS_ALL_DONE;
+
+	  if (fallback & fb_rvalue)
+	    ret = GS_ALL_DONE;
+	  else
+	    {
+	      tree cdecl = build_decl (UNKNOWN_LOCATION, CONST_DECL,
+				       NULL_TREE, TREE_TYPE (*expr_p));
+	      DECL_INITIAL (cdecl) = *expr_p;
+	      *expr_p = cdecl;
+	      ret = GS_OK;
+	    }
 	  break;
 
 	case CONST_DECL: