* Add a shallow_copy_rtvec function
@ 2009-10-22 21:11 Richard Sandiford
2009-10-22 22:19 ` Richard Henderson
0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2009-10-22 21:11 UTC (permalink / raw)
To: gcc-patches
The patch I'm about to post needs to copy an rtvec without copy_rtxing
the elements themselves. This kind of copy is really the rtvec equivalent
of a shallow_copy_rtx, so here's a patch to add it under the name
shallow_copy_rtvec.
I searched gcc/ for existing cases where this might be useful, but the
only obvious one I could see was cselib_subst_to_values. I think the
new structure is clearer, and since we're doing the "old != new"
comparisons anyway, we might as well avoid dirtying the cache in
cases where we know "old == new".
Tested on x86_64-linux-gnu. OK to install?
Richard
gcc/
* rtl.h (shallow_copy_rtvec): Declare.
* rtl.c (shallow_copy_rtvec): New function.
* cselib.c (cselib_subst_to_values): Use it. Only modify an
rtx field if the subrtx has changed.
Index: gcc/rtl.h
===================================================================
--- gcc/rtl.h 2009-10-22 21:00:52.000000000 +0100
+++ gcc/rtl.h 2009-10-22 21:03:37.000000000 +0100
@@ -1568,6 +1568,7 @@ extern rtx rtx_alloc_stat (RTX_CODE MEM_
#define rtx_alloc(c) rtx_alloc_stat (c MEM_STAT_INFO)
extern rtvec rtvec_alloc (int);
+extern rtvec shallow_copy_rtvec (rtvec);
extern bool shared_const_p (const_rtx);
extern rtx copy_rtx (rtx);
extern void dump_rtx_statistics (void);
Index: gcc/rtl.c
===================================================================
--- gcc/rtl.c 2009-10-22 21:00:52.000000000 +0100
+++ gcc/rtl.c 2009-10-22 21:03:37.000000000 +0100
@@ -164,6 +164,20 @@ rtvec_alloc (int n)
return rt;
}
+/* Create a bitwise copy of VEC. */
+
+rtvec
+shallow_copy_rtvec (rtvec vec)
+{
+ rtvec newvec;
+ int n;
+
+ n = GET_NUM_ELEM (vec);
+ newvec = rtvec_alloc (n);
+ memcpy (&newvec->elem[0], &vec->elem[0], sizeof (rtx) * n);
+ return newvec;
+}
+
/* Return the number of bytes occupied by rtx value X. */
unsigned int
Index: gcc/cselib.c
===================================================================
--- gcc/cselib.c 2009-10-22 21:00:52.000000000 +0100
+++ gcc/cselib.c 2009-10-22 21:03:37.000000000 +0100
@@ -1422,30 +1422,31 @@ cselib_subst_to_values (rtx x)
{
rtx t = cselib_subst_to_values (XEXP (x, i));
- if (t != XEXP (x, i) && x == copy)
- copy = shallow_copy_rtx (x);
-
- XEXP (copy, i) = t;
+ if (t != XEXP (x, i))
+ {
+ if (x == copy)
+ copy = shallow_copy_rtx (x);
+ XEXP (copy, i) = t;
+ }
}
else if (fmt[i] == 'E')
{
- int j, k;
+ int j;
for (j = 0; j < XVECLEN (x, i); j++)
{
rtx t = cselib_subst_to_values (XVECEXP (x, i, j));
- if (t != XVECEXP (x, i, j) && XVEC (x, i) == XVEC (copy, i))
+ if (t != XVECEXP (x, i, j))
{
- if (x == copy)
- copy = shallow_copy_rtx (x);
-
- XVEC (copy, i) = rtvec_alloc (XVECLEN (x, i));
- for (k = 0; k < j; k++)
- XVECEXP (copy, i, k) = XVECEXP (x, i, k);
+ if (XVEC (x, i) == XVEC (copy, i))
+ {
+ if (x == copy)
+ copy = shallow_copy_rtx (x);
+ XVEC (copy, i) = shallow_copy_rtvec (XVEC (x, i));
+ }
+ XVECEXP (copy, i, j) = t;
}
-
- XVECEXP (copy, i, j) = t;
}
}
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Add a shallow_copy_rtvec function
2009-10-22 21:11 Add a shallow_copy_rtvec function Richard Sandiford
@ 2009-10-22 22:19 ` Richard Henderson
0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2009-10-22 22:19 UTC (permalink / raw)
To: gcc-patches, rdsandiford
On 10/22/2009 02:07 PM, Richard Sandiford wrote:
> * rtl.h (shallow_copy_rtvec): Declare.
> * rtl.c (shallow_copy_rtvec): New function.
> * cselib.c (cselib_subst_to_values): Use it. Only modify an
> rtx field if the subrtx has changed.
Ok.
r~
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-10-22 22:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-22 21:11 Add a shallow_copy_rtvec function Richard Sandiford
2009-10-22 22:19 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).