Re: [PING][AARCH64, Question] Does AARCH64 GCC support long calls?

2014-10-25 Thread Yangfei (Felix)
> > Thanks for the reply.  It seems that -mcmodel=large is different from
> -mlong-calls.
> > GCC still emit the BL instruction with -mcmodel=large.  I thinks GCC should
> emit BLR instruction with -mlong-calls, right?
> 
> 
> Oh right.  Also it looks like it is not hooked up but the support is partly 
> there:
> /* Return true if calls to DECL should be treated as
>long-calls (ie called via a register).  */ static bool 
> aarch64_decl_is_long_call_p
> (const_tree decl ATTRIBUTE_UNUSED) {
>   return false;
> }
> 
> I had added the attribute in a version for this and the users of the 
> toolchain has
> not reported a bug about it so it seems like it is working.
> I don't have time right now to add support for the option or port the 
> attribute to
> the latest version but it should be easy as returning true from that function 
> when
> the option is turned on.
> 
> Thanks,
> Andrew Pinski
> 

Thanks Andrew. 
I'm interested in this part and already have an initial patch for it. 
I can handle this if you don't mind :-) 



Re: update address taken: don't drop clobbers

2014-10-25 Thread Marc Glisse

(replying to both messages)

On Fri, 24 Oct 2014, Jeff Law wrote:

[ https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01830.html ]
So I'm still trying to get comfortable with this patch.  I guess my concerns 
about having one of the undefined value SSA_NAMEs appearing in two 
conflicting coalesce lists are alleviated by the twiddle to 
coalesce_partitions where we essentially ignore them.


So in the end, they don't end up a part of any partition?


Without the liveness patch, their lifetime should mean that they don't 
coalesce with anything. But I would expect they get their own partition 
then (I am forgetting these details way too fast...). With the liveness 
patch which gives them an empty lifetime, they should all coalesce with at 
least one other ssa_name.


What happens when we expand them?  I guess they get a new pseudo since 
they're a distinct partition?  If we had a sensible story for expansion, 
then I could probably get on board with this patch.


As I mentioned in my message, I don't know. Last time I looked I couldn't 
find how coalescing was actually performed. tree-outof-ssa.c has a 
function rewrite_trees with a promising comment but an empty body :-/
I agree that we need to understand what happens at expansion time when the 
variables are not coalesced before pushing a patch that prevents 
coalescing. I was kind of hoping someone would have a pointer...



On Fri, 24 Oct 2014, Jeff Law wrote:

[ https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01787.html ]

On 10/17/14 14:41, Marc Glisse wrote:


Thinking about it some more, I don't think we should need any kind of
DCE here. The rewriting in update_ssa already does a form of forward
propagation that avoids generating dead assignments, the problem only
occurs if we explicitly introduce this new assignment. So I believe we
should go back to an earlier version, like the attached, which is less
work for the compiler.

And now I can go re-read the old discussion (apparently I should avoid
gsi_replace, and there may be other ways to handle the coalescing).

I'm starting to agree -- a later message indicated you wanted to drop the 
unlink_stmt_vdef call and you wanted to avoid gsi_replace, that seems fine. 
I'll approve once those things are taken care of.


I don't really want to avoid gsi_replace, but I am willing to do it if it 
makes reviewers nervous to call such a high-level function in the cleanup 
code between passes (Richard in particular was unhappy about it).


To clarify things so I know what to test and re-post, we are talking 
about the patch in 
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01787.html and we can forget 
about the coalescing thing in 
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01830.html ?

(I'd be happy with that :-)

Thanks,

--
Marc Glisse


Re: genmatch infinite loop during bootstrap on AIX

2014-10-25 Thread Richard Biener
On October 25, 2014 1:33:39 AM CEST, David Edelsohn  wrote:
>genmatch is hanging when bootstrapping on AIX (gcc111).  When I attach
>to the process:
>
>#0  0x1007efac in std::basic_string,
>std::allocator >::basic_string ()
>#1  0x1000e6b0 in _ZN6parser13parse_captureEP7operand (this=0x300594b8,
>op=0x0)
>at /home/dje/src/src/gcc/genmatch.c:2607

Does it really hang in libstdc++ or does it loop somewhere in genmatch? Is this 
stage1 or later?

Does this happen only after the 2nd part of the merge went in? That is, what 
revision?

Thanks,
Richard.

>#2  0x1000e9f0 in _ZN6parser10parse_exprEv (this=0x2ff20208)
>at /home/dje/src/src/gcc/genmatch.c:2669
>#3  0x1000ee38 in _ZN6parser8parse_opEv (this=0x2ff20208)
>at /home/dje/src/src/gcc/genmatch.c:2728
>#4  0x1000efc4 in
>_ZN6parser14parse_simplifyEjR3vecIP8simplify7va_heap6vl_ptrEP12predicate_idP4expr
>(this=0x2ff20208, match_location=4614, simplifiers=...,
>matcher=0x0, result=0x0) at /home/dje/src/src/gcc/genmatch.c:2792
>#5  0x100102fc in _ZN6parser13parse_patternEv (this=0x2ff20208)
>at /home/dje/src/src/gcc/genmatch.c:3052
>#6  0x10010c0c in _ZN6parser9parse_forEj (this=0x2ff20208)
>at /home/dje/src/src/gcc/genmatch.c:2991
>#7  0x10010350 in _ZN6parser13parse_patternEv (this=0x2ff20208)
>at /home/dje/src/src/gcc/genmatch.c:3090
>#8  0x1001122c in _ZN6parserC2EP10cpp_reader (this=0x2ff20208,
>r_=0x3003bbec)
>at /home/dje/src/src/gcc/genmatch.c:3122
>#9  0x10004acc in main (argc=,
>argv=) at  _start_ :3204




Re: PATCH: fix breakage from "[PATCH] Fix genmatch linking"

2014-10-25 Thread Richard Biener
On October 24, 2014 6:47:10 PM CEST, Hans-Peter Nilsson 
 wrote:
>> From: Richard Biener 
>> Date: Fri, 24 Oct 2014 09:56:51 +0200
>> On Fri, 24 Oct 2014, Hans-Peter Nilsson wrote:
>> > Still, I don't understand exactly how your patch
>> > introduces build-subdirectories where there were none before.
>> > Maybe that "+all-gcc: maybe-all-build-libcpp" was wrong and
>> > should be different?
>> 
>> No, we do need a build-libcpp to build gcc/build/genmatch.
>> Not sure how you got around without a build-libiberty as other
>> gen* programs surely require that.
>
>Regular cross-configurations got around fine as they used the
>"host"-build libiberty, which for crosses seemed to differ from
>"build"-builds(!) only in that they're built at the objdir top
>instead of objdir/build-.  Crosses *could* still use
>the host libraries, but whatever; we're avoiding a
>cross-or-native-conditional now.  I haven't given
>canadian-crosses any thought, maybe they were broken before.

Most definitely. I wonder why we don't use the same trick with regular 
bootstrap. There I see build- variants of libiberty used for stage1.

Richard.

>brgds, H-P




[spu] RFA: Use new rtl iterators in ea_symbol_ref_p

2014-10-25 Thread Richard Sandiford
Make spu.c use FOR_EACH_SUBRTX instead of for_each_rtx, as part of a series
to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for spu-elf.  OK to install?

Thanks,
Richard


gcc/
* config/spu/spu.c: Include rtl-iter.h
(ea_symbol_ref): Replace with...
(ea_symbol_ref_p): ...this new function.
(spu_legitimate_address_p): Update call accordingly.
(spu_legitimate_constant_p): Likewise.  Use FOR_EACH_SUBRTX.

Index: gcc/config/spu/spu.c
===
--- gcc/config/spu/spu.c2014-10-25 09:48:53.108538042 +0100
+++ gcc/config/spu/spu.c2014-10-25 09:51:14.796788623 +0100
@@ -69,6 +69,7 @@
 #include "dumpfile.h"
 #include "cfgloop.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 /* Builtin types, data and prototypes. */
 
@@ -3466,10 +3467,9 @@ exp2_immediate_p (rtx op, enum machine_m
 
 /* Return true if X is a SYMBOL_REF to an __ea qualified variable.  */
 
-static int
-ea_symbol_ref (rtx *px, void *data ATTRIBUTE_UNUSED)
+static bool
+ea_symbol_ref_p (const_rtx x)
 {
-  rtx x = *px;
   tree decl;
 
   if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS)
@@ -3496,13 +3496,15 @@ ea_symbol_ref (rtx *px, void *data ATTRI
 bool
 spu_legitimate_constant_p (enum machine_mode mode, rtx x)
 {
+  subrtx_iterator::array_type array;
   if (GET_CODE (x) == HIGH)
 x = XEXP (x, 0);
 
   /* Reject any __ea qualified reference.  These can't appear in
  instructions but must be forced to the constant pool.  */
-  if (for_each_rtx (&x, ea_symbol_ref, 0))
-return 0;
+  FOR_EACH_SUBRTX (iter, array, x, ALL)
+if (ea_symbol_ref_p (*iter))
+  return 0;
 
   /* V4SI with all identical symbols is valid. */
   if (!flag_pic
@@ -3548,7 +3550,7 @@ spu_legitimate_address_p (enum machine_m
 case CONST:
   /* Keep __ea references until reload so that spu_expand_mov can see them
 in MEMs.  */
-  if (ea_symbol_ref (&x, 0))
+  if (ea_symbol_ref_p (x))
return !reload_in_progress && !reload_completed;
   return !TARGET_LARGE_MEM;
 


[x86] RFA: Use new rtl iterators in ix86_check_avx256_register

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for x86_64-linux-gnu, and also by a boostrap.  OK to install?

Thanks,
Richard


gcc/
* config/i386/i386.c: Include rtl-iter.h
(ix86_check_avx256_register): Take a const_rtx and return a bool.
(ix86_check_avx256_stores): Update call accordingly.
(ix86_avx_u128_mode_entry, ix86_avx_u128_mode_exit): Likewise.
(ix86_avx_u128_mode_needed): Likewise.  Use FOR_EACH_SUBRTX.

Index: gcc/config/i386/i386.c
===
--- gcc/config/i386/i386.c  2014-10-25 09:48:53.074537743 +0100
+++ gcc/config/i386/i386.c  2014-10-25 09:51:15.189792126 +0100
@@ -88,6 +88,7 @@ the Free Software Foundation; either ver
 #include "tree-vectorizer.h"
 #include "shrink-wrap.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 static rtx legitimize_dllimport_symbol (rtx, bool);
 static rtx legitimize_pe_coff_extern_decl (rtx, bool);
@@ -16114,19 +16115,14 @@ output_387_binary_op (rtx insn, rtx *ope
 
 /* Check if a 256bit AVX register is referenced inside of EXP.   */
 
-static int
-ix86_check_avx256_register (rtx *pexp, void *)
+static bool
+ix86_check_avx256_register (const_rtx exp)
 {
-  rtx exp = *pexp;
-
   if (GET_CODE (exp) == SUBREG)
 exp = SUBREG_REG (exp);
 
-  if (REG_P (exp)
-  && VALID_AVX256_REG_OR_OI_MODE (GET_MODE (exp)))
-return 1;
-
-  return 0;
+  return (REG_P (exp)
+ && VALID_AVX256_REG_OR_OI_MODE (GET_MODE (exp)));
 }
 
 /* Return needed mode for entity in optimize_mode_switching pass.  */
@@ -16148,7 +16144,7 @@ ix86_avx_u128_mode_needed (rtx_insn *ins
{
  rtx arg = XEXP (XEXP (link, 0), 0);
 
- if (ix86_check_avx256_register (&arg, NULL))
+ if (ix86_check_avx256_register (arg))
return AVX_U128_DIRTY;
}
}
@@ -16160,8 +16156,10 @@ ix86_avx_u128_mode_needed (rtx_insn *ins
  changes state only when a 256bit register is written to, but we need
  to prevent the compiler from moving optimal insertion point above
  eventual read from 256bit register.  */
-  if (for_each_rtx (&PATTERN (insn), ix86_check_avx256_register, NULL))
-return AVX_U128_DIRTY;
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
+if (ix86_check_avx256_register (*iter))
+  return AVX_U128_DIRTY;
 
   return AVX_U128_ANY;
 }
@@ -16245,7 +16243,7 @@ ix86_mode_needed (int entity, rtx_insn *
 static void
 ix86_check_avx256_stores (rtx dest, const_rtx, void *data)
  {
-   if (ix86_check_avx256_register (&dest, NULL))
+   if (ix86_check_avx256_register (dest))
 {
   bool *used = (bool *) data;
   *used = true;
@@ -16310,7 +16308,7 @@ ix86_avx_u128_mode_entry (void)
 {
   rtx incoming = DECL_INCOMING_RTL (arg);
 
-  if (incoming && ix86_check_avx256_register (&incoming, NULL))
+  if (incoming && ix86_check_avx256_register (incoming))
return AVX_U128_DIRTY;
 }
 
@@ -16344,7 +16342,7 @@ ix86_avx_u128_mode_exit (void)
 
   /* Exit mode is set to AVX_U128_DIRTY if there are
  256bit modes used in the function return register.  */
-  if (reg && ix86_check_avx256_register (®, NULL))
+  if (reg && ix86_check_avx256_register (reg))
 return AVX_U128_DIRTY;
 
   return AVX_U128_CLEAN;


[x86] RFA: Use new rtl iterators in x86_extended_reg_mentioned_p

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for x86_64-linux-gnu, and also by a boostrap.  OK to install?

Thanks,
Richard


gcc/
* config/i386/i386.c (extended_reg_mentioned_1): Delete.
(x86_extended_reg_mentioned_p): Use FOR_EACH_SUBRTX.

Index: gcc/config/i386/i386.c
===
--- gcc/config/i386/i386.c  2014-10-25 09:51:15.189792126 +0100
+++ gcc/config/i386/i386.c  2014-10-25 09:51:15.606795843 +0100
@@ -39688,25 +39688,20 @@ x86_extended_QIreg_mentioned_p (rtx_insn
   return false;
 }
 
-/* Return nonzero when P points to register encoded via REX prefix.
-   Called via for_each_rtx.  */
-static int
-extended_reg_mentioned_1 (rtx *p, void *)
-{
-   unsigned int regno;
-   if (!REG_P (*p))
- return 0;
-   regno = REGNO (*p);
-   return REX_INT_REGNO_P (regno) || REX_SSE_REGNO_P (regno);
-}
-
 /* Return true when INSN mentions register that must be encoded using REX
prefix.  */
 bool
 x86_extended_reg_mentioned_p (rtx insn)
 {
-  return for_each_rtx (INSN_P (insn) ? &PATTERN (insn) : &insn,
-  extended_reg_mentioned_1, NULL);
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, 
NONCONST)
+{
+  const_rtx x = *iter;
+  if (REG_P (x)
+ && (REX_INT_REGNO_P (REGNO (x)) || REX_SSE_REGNO_P (REGNO (x
+   return true;
+}
+  return false;
 }
 
 /* If profitable, negate (without causing overflow) integer constant


[x86] RFA: Use new rtl iterators in find_constant

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.
It's a bit hard to read, so I've attached a -b version too.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for x86_64-linux-gnu, and also by a boostrap.  OK to install?

Thanks,
Richard


gcc/
* config/i386/i386.c (find_constant_1): Delete.
(find_constant): Use FOR_EACH_SUBRTX.

Index: gcc/config/i386/i386.c
===
--- gcc/config/i386/i386.c  2014-10-25 09:51:15.606795843 +0100
+++ gcc/config/i386/i386.c  2014-10-25 09:51:15.992799283 +0100
@@ -46526,53 +46526,44 @@ allocate_next_window (int window_num)
   return dispatch_window_list1;
 }
 
-/* Increment the number of immediate operands of an instruction.  */
+/* Compute number of immediate operands of an instruction.  */
 
-static int
-find_constant_1 (rtx *in_rtx, imm_info *imm_values)
+static void
+find_constant (rtx in_rtx, imm_info *imm_values)
 {
-  if (*in_rtx == 0)
-return 0;
-
-switch ( GET_CODE (*in_rtx))
-{
-case CONST:
-case SYMBOL_REF:
-case CONST_INT:
-  (imm_values->imm)++;
-  if (x86_64_immediate_operand (*in_rtx, SImode))
-   (imm_values->imm32)++;
-  else
-   (imm_values->imm64)++;
-  break;
-
-case CONST_DOUBLE:
-  (imm_values->imm)++;
-  (imm_values->imm64)++;
-  break;
-
-case CODE_LABEL:
-  if (LABEL_KIND (*in_rtx) == LABEL_NORMAL)
+  if (INSN_P (in_rtx))
+in_rtx = PATTERN (in_rtx);
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, in_rtx, ALL)
+if (const_rtx x = *iter)
+  switch (GET_CODE (x))
{
+   case CONST:
+   case SYMBOL_REF:
+   case CONST_INT:
  (imm_values->imm)++;
- (imm_values->imm32)++;
-   }
-  break;
-
-default:
-  break;
-}
+ if (x86_64_immediate_operand (CONST_CAST_RTX (x), SImode))
+   (imm_values->imm32)++;
+ else
+   (imm_values->imm64)++;
+ break;
 
-  return 0;
-}
+   case CONST_DOUBLE:
+ (imm_values->imm)++;
+ (imm_values->imm64)++;
+ break;
 
-/* Compute number of immediate operands of an instruction.  */
+   case CODE_LABEL:
+ if (LABEL_KIND (x) == LABEL_NORMAL)
+   {
+ (imm_values->imm)++;
+ (imm_values->imm32)++;
+   }
+ break;
 
-static void
-find_constant (rtx in_rtx, imm_info *imm_values)
-{
-  for_each_rtx (INSN_P (in_rtx) ? &PATTERN (in_rtx) : &in_rtx,
-   (rtx_function) find_constant_1, (void *) imm_values);
+   default:
+ break;
+   }
 }
 
 /* Return total size of immediate operands of an instruction along with number


Index: gcc/config/i386/i386.c
===
--- gcc/config/i386/i386.c	2014-10-25 10:05:55.546618859 +0100
+++ gcc/config/i386/i386.c	2014-10-25 10:05:58.575647258 +0100
@@ -46526,21 +46526,23 @@ allocate_next_window (int window_num)
   return dispatch_window_list1;
 }
 
-/* Increment the number of immediate operands of an instruction.  */
+/* Compute number of immediate operands of an instruction.  */
 
-static int
-find_constant_1 (rtx *in_rtx, imm_info *imm_values)
+static void
+find_constant (rtx in_rtx, imm_info *imm_values)
 {
-  if (*in_rtx == 0)
-return 0;
-
-switch ( GET_CODE (*in_rtx))
+  if (INSN_P (in_rtx))
+in_rtx = PATTERN (in_rtx);
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, in_rtx, ALL)
+if (const_rtx x = *iter)
+  switch (GET_CODE (x))
 {
 case CONST:
 case SYMBOL_REF:
 case CONST_INT:
   (imm_values->imm)++;
-  if (x86_64_immediate_operand (*in_rtx, SImode))
+	  if (x86_64_immediate_operand (CONST_CAST_RTX (x), SImode))
 	(imm_values->imm32)++;
   else
 	(imm_values->imm64)++;
@@ -46552,7 +46554,7 @@ find_constant_1 (rtx *in_rtx, imm_info *
   break;
 
 case CODE_LABEL:
-  if (LABEL_KIND (*in_rtx) == LABEL_NORMAL)
+	  if (LABEL_KIND (x) == LABEL_NORMAL)
 	{
 	  (imm_values->imm)++;
 	  (imm_values->imm32)++;
@@ -46562,17 +46564,6 @@ find_constant_1 (rtx *in_rtx, imm_info *
 default:
   break;
 }
-
-  return 0;
-}
-
-/* Compute number of immediate operands of an instruction.  */
-
-static void
-find_constant (rtx in_rtx, imm_info *imm_values)
-{
-  for_each_rtx (INSN_P (in_rtx) ? &PATTERN (in_rtx) : &in_rtx,
-		(rtx_function) find_constant_1, (void *) imm_values);
 }
 
 /* Return total size of immediate operands of an instruction along with number


[x86] RFA: Use new rtl iterators in ix86_loop_unroll_adjust

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

It looks like this code should be iterating over the pattern rather than
the full insn, or do MEMs in notes really count?  If we iterate over the
pattern then there should be no need for the test for null.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for x86_64-linux-gnu, and also by a boostrap.  OK to install?

Thanks,
Richard


gcc/
* config/i386/i386.c (ix86_loop_memcount): Delete.
(ix86_loop_unroll_adjust): Use FOR_EACH_SUBRTX.

Index: gcc/config/i386/i386.c
===
--- gcc/config/i386/i386.c  2014-10-25 09:51:15.992799283 +0100
+++ gcc/config/i386/i386.c  2014-10-25 09:51:16.373802679 +0100
@@ -47405,29 +47405,6 @@ ix86_simd_clone_usable (struct cgraph_no
 }
 }
 
-/* This function gives out the number of memory references.
-   This value determines the unrolling factor for
-   bdver3 and bdver4 architectures. */
-
-static int
-ix86_loop_memcount (rtx *x, unsigned *mem_count)
-{
-  if (*x != NULL_RTX && MEM_P (*x))
-   {
- enum machine_mode mode;
- unsigned int n_words;
-
- mode = GET_MODE (*x);
- n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
-
-if (n_words > 4)
-   (*mem_count)+=2;
-else
-   (*mem_count)+=1;
-   }
-  return 0;
-}
-
 /* This function adjusts the unroll factor based on
the hardware capabilities. For ex, bdver3 has
a loop buffer which makes unrolling of smaller
@@ -47447,14 +47424,22 @@ ix86_loop_unroll_adjust (unsigned nunrol
  return nunroll;
 
   /* Count the number of memory references within the loop body.  */
+  subrtx_iterator::array_type array;
   bbs = get_loop_body (loop);
   for (i = 0; i < loop->num_nodes; i++)
-{
-  for (insn = BB_HEAD (bbs[i]); insn != BB_END (bbs[i]); insn = NEXT_INSN 
(insn))
-if (NONDEBUG_INSN_P (insn))
-for_each_rtx_in_insn (&insn, (rtx_function) ix86_loop_memcount,
- &mem_count);
-}
+FOR_BB_INSNS (bbs[i], insn)
+  if (NONDEBUG_INSN_P (insn))
+   FOR_EACH_SUBRTX (iter, array, insn, NONCONST)
+ if (const_rtx x = *iter)
+   if (MEM_P (x))
+ {
+   enum machine_mode mode = GET_MODE (x);
+   unsigned int n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
+   if (n_words > 4)
+ mem_count += 2;
+   else
+ mem_count += 1;
+ }
   free (bbs);
 
   if (mem_count && mem_count <=32)


[m68k] RFA: Use new rtl iterators in m68k_final_prescan_insn

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for m68k-elf.  OK to install?

Thanks,
Richard


gcc/
* config/m68k/m68k.c: Include rtl-iter.h.
(m68k_final_prescan_insn_1): Delete.
(m68k_final_prescan_insn): Use FOR_EACH_SUBRTX_VAR.

Index: gcc/config/m68k/m68k.c
===
--- gcc/config/m68k/m68k.c  2014-10-25 09:48:52.914536337 +0100
+++ gcc/config/m68k/m68k.c  2014-10-25 09:51:16.781806316 +0100
@@ -55,6 +55,7 @@ the Free Software Foundation; either ver
 #include "opts.h"
 #include "optabs.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 enum reg_class regno_reg_class[] =
 {
@@ -2279,49 +2280,6 @@ m68k_unwrap_symbol (rtx orig, bool unwra
   return m68k_unwrap_symbol_1 (orig, unwrap_reloc32_p, NULL);
 }
 
-/* Helper for m68k_final_prescan_insn.  */
-
-static int
-m68k_final_prescan_insn_1 (rtx *x_ptr, void *data ATTRIBUTE_UNUSED)
-{
-  rtx x = *x_ptr;
-
-  if (m68k_unwrap_symbol (x, true) != x)
-/* For rationale of the below, see comment in m68k_final_prescan_insn.  */
-{
-  rtx plus;
-
-  gcc_assert (GET_CODE (x) == CONST);
-  plus = XEXP (x, 0);
-
-  if (GET_CODE (plus) == PLUS || GET_CODE (plus) == MINUS)
-   {
- rtx unspec;
- rtx addend;
-
- unspec = XEXP (plus, 0);
- gcc_assert (GET_CODE (unspec) == UNSPEC);
- addend = XEXP (plus, 1);
- gcc_assert (CONST_INT_P (addend));
-
- /* We now have all the pieces, rearrange them.  */
-
- /* Move symbol to plus.  */
- XEXP (plus, 0) = XVECEXP (unspec, 0, 0);
-
- /* Move plus inside unspec.  */
- XVECEXP (unspec, 0, 0) = plus;
-
- /* Move unspec to top level of const.  */
- XEXP (x, 0) = unspec;
-   }
-
-  return -1;
-}
-
-  return 0;
-}
-
 /* Prescan insn before outputing assembler for it.  */
 
 void
@@ -2347,13 +2305,47 @@ m68k_final_prescan_insn (rtx_insn *insn
  Note, that the top level of operand remains intact, so we don't have
  to patch up anything outside of the operand.  */
 
+  subrtx_var_iterator::array_type array;
   for (i = 0; i < n_operands; ++i)
 {
   rtx op;
 
   op = operands[i];
 
-  for_each_rtx (&op, m68k_final_prescan_insn_1, NULL);
+  FOR_EACH_SUBRTX_VAR (iter, array, op, ALL)
+   {
+ rtx x = *iter;
+ if (m68k_unwrap_symbol (x, true) != x)
+   {
+ rtx plus;
+
+ gcc_assert (GET_CODE (x) == CONST);
+ plus = XEXP (x, 0);
+
+ if (GET_CODE (plus) == PLUS || GET_CODE (plus) == MINUS)
+   {
+ rtx unspec;
+ rtx addend;
+
+ unspec = XEXP (plus, 0);
+ gcc_assert (GET_CODE (unspec) == UNSPEC);
+ addend = XEXP (plus, 1);
+ gcc_assert (CONST_INT_P (addend));
+
+ /* We now have all the pieces, rearrange them.  */
+
+ /* Move symbol to plus.  */
+ XEXP (plus, 0) = XVECEXP (unspec, 0, 0);
+
+ /* Move plus inside unspec.  */
+ XVECEXP (unspec, 0, 0) = plus;
+
+ /* Move unspec to top level of const.  */
+ XEXP (x, 0) = unspec;
+   }
+ iter.skip_subrtxes ();
+   }
+   }
 }
 }
 


[m68k] RFA: Use new rtl iterators in m68k_tls_reference_p

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for m68k-elf.  OK to install?

Thanks,
Richard


gcc/
* config/m68k/m68k.c (m68k_tls_reference_p_1): Delete.
(m68k_tls_reference_p): Use FOR_EACH_SUBRTX_VAR.

Index: gcc/config/m68k/m68k.c
===
--- gcc/config/m68k/m68k.c  2014-10-25 09:51:16.781806316 +0100
+++ gcc/config/m68k/m68k.c  2014-10-25 09:51:17.194809998 +0100
@@ -2671,22 +2671,6 @@ m68k_tls_symbol_p (rtx x)
   return SYMBOL_REF_TLS_MODEL (x) != 0;
 }
 
-/* Helper for m68k_tls_referenced_p.  */
-
-static int
-m68k_tls_reference_p_1 (rtx *x_ptr, void *data ATTRIBUTE_UNUSED)
-{
-  /* Note: this is not the same as m68k_tls_symbol_p.  */
-  if (GET_CODE (*x_ptr) == SYMBOL_REF)
-return SYMBOL_REF_TLS_MODEL (*x_ptr) != 0 ? 1 : 0;
-
-  /* Don't recurse into legitimate TLS references.  */
-  if (m68k_tls_reference_p (*x_ptr, true))
-return -1;
-
-  return 0;
-}
-
 /* If !LEGITIMATE_P, return true if X is a TLS symbol reference,
though illegitimate one.
If LEGITIMATE_P, return true if X is a legitimate TLS symbol reference.  */
@@ -2698,7 +2682,22 @@ m68k_tls_reference_p (rtx x, bool legiti
 return false;
 
   if (!legitimate_p)
-return for_each_rtx (&x, m68k_tls_reference_p_1, NULL) == 1 ? true : false;
+{
+  subrtx_var_iterator::array_type array;
+  FOR_EACH_SUBRTX_VAR (iter, array, x, ALL)
+   {
+ rtx x = *iter;
+
+ /* Note: this is not the same as m68k_tls_symbol_p.  */
+ if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0)
+   return true;
+
+ /* Don't recurse into legitimate TLS references.  */
+ if (m68k_tls_reference_p (x, true))
+   iter.skip_subrtxes ();
+   }
+  return false;
+}
   else
 {
   enum m68k_reloc reloc = RELOC_GOT;


[xtensa] RFA: Use new rtl iterators in xtensa_tls_referenced_p

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for xtensa-elf.  OK to install?

Thanks,
Richard


gcc/
* config/xtensa/xtensa.c: Include rtl-iter.h.
(xtensa_tls_referenced_p_1): Delete.
(xtensa_tls_referenced_p): Use FOR_EACH_SUBRTX.

Index: gcc/config/xtensa/xtensa.c
===
--- gcc/config/xtensa/xtensa.c  2014-10-25 09:48:52.858535844 +0100
+++ gcc/config/xtensa/xtensa.c  2014-10-25 09:51:17.602813634 +0100
@@ -66,6 +66,7 @@ Software Foundation; either version 3, o
 #include "gimplify.h"
 #include "df.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 
 /* Enumeration for all of the relational tests, so that we can build
@@ -1986,34 +1987,6 @@ xtensa_mode_dependent_address_p (const_r
   return constantpool_address_p (addr);
 }
 
-/* Helper for xtensa_tls_referenced_p.  */
-
-static int
-xtensa_tls_referenced_p_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
-{
-  if (GET_CODE (*x) == SYMBOL_REF)
-return SYMBOL_REF_TLS_MODEL (*x) != 0;
-
-  /* Ignore TLS references that have already been legitimized.  */
-  if (GET_CODE (*x) == UNSPEC)
-{
-  switch (XINT (*x, 1))
-   {
-   case UNSPEC_TPOFF:
-   case UNSPEC_DTPOFF:
-   case UNSPEC_TLS_FUNC:
-   case UNSPEC_TLS_ARG:
-   case UNSPEC_TLS_CALL:
- return -1;
-   default:
- break;
-   }
-}
-
-  return 0;
-}
-
-
 /* Return TRUE if X contains any TLS symbol references.  */
 
 bool
@@ -2022,7 +1995,29 @@ xtensa_tls_referenced_p (rtx x)
   if (! TARGET_HAVE_TLS)
 return false;
 
-  return for_each_rtx (&x, xtensa_tls_referenced_p_1, NULL);
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, x, ALL)
+{
+  const_rtx x = *iter;
+  if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0)
+   return true;
+
+  /* Ignore TLS references that have already been legitimized.  */
+  if (GET_CODE (x) == UNSPEC)
+   switch (XINT (x, 1))
+ {
+ case UNSPEC_TPOFF:
+ case UNSPEC_DTPOFF:
+ case UNSPEC_TLS_FUNC:
+ case UNSPEC_TLS_ARG:
+ case UNSPEC_TLS_CALL:
+   iter.skip_subrtxes ();
+   break;
+ default:
+   break;
+ }
+}
+  return false;
 }
 
 


[mep] RFA: Use new rtl iterators in global_reg_mentioned_p

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.
The cases:

case SCRATCH:
case PC:
case CC0:
case CONST_INT:
case CONST_DOUBLE:
case CONST:
case LABEL_REF:

were just short-cuts to avoid looking through unnecessary subrtxes.
SCRATCH, PC and CC0 don't have subrtxes, so keeping the cases would
add rather than remove work when using the new iterator.  The other
cases are handled by the NONCONST argument to FOR_EACH_SUBRTX.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mep-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mep/mep.c: Include rtl-iter.h.
(global_reg_mentioned_p_1): Take a const_rtx and return a bool.
(xtensa_tls_referenced_p): Return a bool.  Use FOR_EACH_SUBRTX.

Index: gcc/config/mep/mep.c
===
--- gcc/config/mep/mep.c2014-10-25 09:48:52.837535660 +0100
+++ gcc/config/mep/mep.c2014-10-25 09:51:18.001817191 +0100
@@ -69,6 +69,7 @@ Software Foundation; either version 3, o
 #include "opts.h"
 #include "dumpfile.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 /* Structure of this file:
 
@@ -6367,14 +6368,10 @@ mep_vector_mode_supported_p (enum machin
 /* A subroutine of global_reg_mentioned_p, returns 1 if *LOC mentions
a global register.  */
 
-static int
-global_reg_mentioned_p_1 (rtx *loc, void *data ATTRIBUTE_UNUSED)
+static bool
+global_reg_mentioned_p_1 (const_rtx x)
 {
   int regno;
-  rtx x = *loc;
-
-  if (! x)
-return 0;
 
   switch (GET_CODE (x))
 {
@@ -6383,40 +6380,31 @@ global_reg_mentioned_p_1 (rtx *loc, void
{
  if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER
  && global_regs[subreg_regno (x)])
-   return 1;
- return 0;
+   return true;
+ return false;
}
   break;
 
 case REG:
   regno = REGNO (x);
   if (regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
-   return 1;
-  return 0;
-
-case SCRATCH:
-case PC:
-case CC0:
-case CONST_INT:
-case CONST_DOUBLE:
-case CONST:
-case LABEL_REF:
-  return 0;
+   return true;
+  return false;
 
 case CALL:
   /* A non-constant call might use a global register.  */
-  return 1;
+  return true;
 
 default:
   break;
 }
 
-  return 0;
+  return false;
 }
 
 /* Returns nonzero if X mentions a global register.  */
 
-static int
+static bool
 global_reg_mentioned_p (rtx x)
 {
   if (INSN_P (x))
@@ -6424,16 +6412,20 @@ global_reg_mentioned_p (rtx x)
   if (CALL_P (x))
{
  if (! RTL_CONST_OR_PURE_CALL_P (x))
-   return 1;
+   return true;
  x = CALL_INSN_FUNCTION_USAGE (x);
  if (x == 0)
-   return 0;
+   return false;
}
   else
x = PATTERN (x);
 }
 
-  return for_each_rtx (&x, global_reg_mentioned_p_1, NULL);
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, x, NONCONST)
+if (global_reg_mentioned_p_1 (*iter))
+  return true;
+  return false;
 }
 /* Scheduling hooks for VLIW mode.
 


[mep] RFA: Use new rtl iterators in mep_store_find_set

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mep-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mep/mep.c (mep_store_find_set): Take a const_rtx and
return a bool.  Replace "void *" with specific type.  Iterate
over all subrtxes.
(mep_store_data_bypass_1): Update calls accordingly.

Index: gcc/config/mep/mep.c
===
--- gcc/config/mep/mep.c2014-10-25 09:51:18.001817191 +0100
+++ gcc/config/mep/mep.c2014-10-25 09:51:18.384820605 +0100
@@ -6644,13 +6644,16 @@ mep_sched_reorder (FILE *dump ATTRIBUTE_
   return 2;
 }
 
-/* A for_each_rtx callback.  Return true if *X is a register that is
-   set by insn PREV.  */
+/* Return true if X contains a register that is set by insn PREV.  */
 
-static int
-mep_store_find_set (rtx *x, void *prev)
+static bool
+mep_store_find_set (const_rtx x, const rtx_insn *prev)
 {
-  return REG_P (*x) && reg_set_p (*x, (const_rtx) prev);
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, x, NONCONST)
+if (REG_P (x) && reg_set_p (x, prev))
+  return true;
+  return false;
 }
 
 /* Like mep_store_bypass_p, but takes a pattern as the second argument,
@@ -6687,7 +6690,7 @@ mep_store_data_bypass_1 (rtx_insn *prev,
 
   src = SET_SRC (pat);
   for (i = 1; i < XVECLEN (src, 0); i++)
-   if (for_each_rtx (&XVECEXP (src, 0, i), mep_store_find_set, prev))
+   if (mep_store_find_set (XVECEXP (src, 0, i), prev))
  return false;
 
   return true;
@@ -6695,7 +6698,7 @@ mep_store_data_bypass_1 (rtx_insn *prev,
 
   /* Otherwise just check that PREV doesn't modify any register mentioned
  in the memory destination.  */
-  return !for_each_rtx (&SET_DEST (pat), mep_store_find_set, prev);
+  return !mep_store_find_set (SET_DEST (pat), prev);
 }
 
 /* Return true if INSN is a store instruction and if the store address


[mep] RFA: Use new rtl iterators in mep_mul_hilo_bypass_p

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mep-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mep/mep.c (mep_mul_hilo_bypass_1): Delete.
(mep_mul_hilo_bypass_p): Use FOR_EACH_SUBRTX.

Index: gcc/config/mep/mep.c
===
--- gcc/config/mep/mep.c2014-10-25 09:51:18.384820605 +0100
+++ gcc/config/mep/mep.c2014-10-25 09:51:18.765824001 +0100
@@ -6710,18 +6710,6 @@ mep_store_data_bypass_p (rtx_insn *prev,
   return INSN_P (insn) ? mep_store_data_bypass_1 (prev, PATTERN (insn)) : 
false;
 }
 
-/* A for_each_rtx subroutine of mep_mul_hilo_bypass_p.  Return 1 if *X
-   is a register other than LO or HI and if PREV sets *X.  */
-
-static int
-mep_mul_hilo_bypass_1 (rtx *x, void *prev)
-{
-  return (REG_P (*x)
- && REGNO (*x) != LO_REGNO
- && REGNO (*x) != HI_REGNO
- && reg_set_p (*x, (const_rtx) prev));
-}
-
 /* Return true if, apart from HI/LO, there are no true dependencies
between multiplication instructions PREV and INSN.  */
 
@@ -6733,8 +6721,19 @@ mep_mul_hilo_bypass_p (rtx_insn *prev, r
   pat = PATTERN (insn);
   if (GET_CODE (pat) == PARALLEL)
 pat = XVECEXP (pat, 0, 0);
-  return (GET_CODE (pat) == SET
- && !for_each_rtx (&SET_SRC (pat), mep_mul_hilo_bypass_1, prev));
+  if (GET_CODE (pat) != SET)
+return false;
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, SET_SRC (pat), NONCONST)
+{
+  const_rtx x = *iter;
+  if (REG_P (x)
+ && REGNO (x) != LO_REGNO
+ && REGNO (x) != HI_REGNO
+ && reg_set_p (x, prev))
+   return false;
+}
+  return true;
 }
 
 /* Return true if INSN is an ldc instruction that issues to the


[MIPS] RFA: Use new rtl iterators in mips_small_data_pattern_p

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mips64-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mips/mips.c: Include rtl-iter.h.
(mips_small_data_pattern_1): Take an rtx rather than an rtx pointer.
Take the context as a parameter instead of the containing MEM.
Iterate over all subrtxes.
(mips_small_data_pattern_p): Update call accordingly.

Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c  2014-10-25 09:48:52.737534781 +0100
+++ gcc/config/mips/mips.c  2014-10-25 09:51:19.145827388 +0100
@@ -76,6 +76,7 @@ the Free Software Foundation; either ver
 #include "context.h"
 #include "cgraph.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 /* True if X is an UNSPEC wrapper around a SYMBOL_REF or LABEL_REF.  */
 #define UNSPEC_ADDRESS_P(X)\
@@ -3449,29 +3450,32 @@ mips_rewrite_small_data_p (rtx x, enum m
  && symbol_type == SYMBOL_GP_RELATIVE);
 }
 
-/* A for_each_rtx callback for mips_small_data_pattern_p.  DATA is the
-   containing MEM, or null if none.  */
+/* Return true if OP refers to small data symbols directly, not through
+   a LO_SUM.  CONTEXT is the context in which X appears.  */
 
 static int
-mips_small_data_pattern_1 (rtx *loc, void *data)
+mips_small_data_pattern_1 (rtx x, enum mips_symbol_context context)
 {
-  enum mips_symbol_context context;
-
-  /* Ignore things like "g" constraints in asms.  We make no particular
- guarantee about which symbolic constants are acceptable as asm operands
- versus which must be forced into a GPR.  */
-  if (GET_CODE (*loc) == LO_SUM || GET_CODE (*loc) == ASM_OPERANDS)
-return -1;
-
-  if (MEM_P (*loc))
+  subrtx_var_iterator::array_type array;
+  FOR_EACH_SUBRTX_VAR (iter, array, x, ALL)
 {
-  if (for_each_rtx (&XEXP (*loc, 0), mips_small_data_pattern_1, *loc))
-   return 1;
-  return -1;
-}
+  rtx x = *iter;
 
-  context = data ? SYMBOL_CONTEXT_MEM : SYMBOL_CONTEXT_LEA;
-  return mips_rewrite_small_data_p (*loc, context);
+  /* Ignore things like "g" constraints in asms.  We make no particular
+guarantee about which symbolic constants are acceptable as asm operands
+versus which must be forced into a GPR.  */
+  if (GET_CODE (x) == LO_SUM || GET_CODE (x) == ASM_OPERANDS)
+   iter.skip_subrtxes ();
+  else if (MEM_P (x))
+   {
+ if (mips_small_data_pattern_1 (XEXP (x, 0), SYMBOL_CONTEXT_MEM))
+   return true;
+ iter.skip_subrtxes ();
+   }
+  else if (mips_rewrite_small_data_p (x, context))
+   return true;
+}
+  return false;
 }
 
 /* Return true if OP refers to small data symbols directly, not through
@@ -3480,7 +3484,7 @@ mips_small_data_pattern_1 (rtx *loc, voi
 bool
 mips_small_data_pattern_p (rtx op)
 {
-  return for_each_rtx (&op, mips_small_data_pattern_1, NULL);
+  return mips_small_data_pattern_1 (op, SYMBOL_CONTEXT_LEA);
 }
 
 /* A for_each_rtx callback, used by mips_rewrite_small_data.


[MIPS] RFA: Use new rtl iterators in mips_rewrite_small_data

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mips64-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mips/mips.c (mips_rewrite_small_data_1): Take the context
as a parameter instead of the containing MEM.  Iterate over all
subrtxes.  Don't return a value.
(mips_rewrite_small_data): Update call accordingly.

Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c  2014-10-25 09:51:19.145827388 +0100
+++ gcc/config/mips/mips.c  2014-10-25 09:51:19.543830935 +0100
@@ -3487,28 +3487,29 @@ mips_small_data_pattern_p (rtx op)
   return mips_small_data_pattern_1 (op, SYMBOL_CONTEXT_LEA);
 }
 
-/* A for_each_rtx callback, used by mips_rewrite_small_data.
-   DATA is the containing MEM, or null if none.  */
+/* Rewrite *LOC so that it refers to small data using explicit
+   relocations.  CONTEXT is the context in which *LOC appears.  */
 
-static int
-mips_rewrite_small_data_1 (rtx *loc, void *data)
+static void
+mips_rewrite_small_data_1 (rtx *loc, enum mips_symbol_context context)
 {
-  enum mips_symbol_context context;
-
-  if (MEM_P (*loc))
+  subrtx_ptr_iterator::array_type array;
+  FOR_EACH_SUBRTX_PTR (iter, array, loc, ALL)
 {
-  for_each_rtx (&XEXP (*loc, 0), mips_rewrite_small_data_1, *loc);
-  return -1;
+  rtx *loc = *iter;
+  if (MEM_P (*loc))
+   {
+ mips_rewrite_small_data_1 (&XEXP (*loc, 0), SYMBOL_CONTEXT_MEM);
+ iter.skip_subrtxes ();
+   }
+  else if (mips_rewrite_small_data_p (*loc, context))
+   {
+ *loc = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, *loc);
+ iter.skip_subrtxes ();
+   }
+  else if (GET_CODE (*loc) == LO_SUM)
+   iter.skip_subrtxes ();
 }
-
-  context = data ? SYMBOL_CONTEXT_MEM : SYMBOL_CONTEXT_LEA;
-  if (mips_rewrite_small_data_p (*loc, context))
-*loc = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, *loc);
-
-  if (GET_CODE (*loc) == LO_SUM)
-return -1;
-
-  return 0;
 }
 
 /* Rewrite instruction pattern PATTERN so that it refers to small data
@@ -3518,7 +3519,7 @@ mips_rewrite_small_data_1 (rtx *loc, voi
 mips_rewrite_small_data (rtx pattern)
 {
   pattern = copy_insn (pattern);
-  for_each_rtx (&pattern, mips_rewrite_small_data_1, NULL);
+  mips_rewrite_small_data_1 (&pattern, SYMBOL_CONTEXT_LEA);
   return pattern;
 }
 


[MIPS] RFA: Use new rtl iterators in mips_kernel_reg_p

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mips64-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mips/mips.c (mips_kernel_reg_p): Replace with...
(mips_refers_to_kernel_reg_p): ...this new function.
(mips_expand_prologue): Update accordingly.

Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c  2014-10-25 09:51:19.543830935 +0100
+++ gcc/config/mips/mips.c  2014-10-25 09:51:19.947834536 +0100
@@ -11045,12 +11045,16 @@ mips_output_probe_stack_range (rtx reg1,
   return "";
 }
 
-/* A for_each_rtx callback.  Stop the search if *X is a kernel register.  */
+/* Return true if X contains a kernel register.  */
 
-static int
-mips_kernel_reg_p (rtx *x, void *data ATTRIBUTE_UNUSED)
+static bool
+mips_refers_to_kernel_reg_p (const_rtx x)
 {
-  return REG_P (*x) && KERNEL_REG_P (REGNO (*x));
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, x, NONCONST)
+if (REG_P (*iter) && KERNEL_REG_P (REGNO (*iter)))
+  return true;
+  return false;
 }
 
 /* Expand the "prologue" pattern.  */
@@ -11322,7 +11326,7 @@ mips_expand_prologue (void)
   rtx_insn *insn;
   for (insn = get_last_insn (); insn != NULL_RTX; insn = PREV_INSN (insn))
if (INSN_P (insn)
-   && for_each_rtx (&PATTERN (insn), mips_kernel_reg_p, NULL))
+   && mips_refers_to_kernel_reg_p (PATTERN (insn)))
  break;
   /* Emit a move from K1 to COP0 Status after insn.  */
   gcc_assert (insn != NULL_RTX);
@@ -11669,7 +11673,7 @@ mips_expand_epilogue (bool sibcall_p)
 {
   for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
if (INSN_P (insn)
-   && for_each_rtx (&PATTERN(insn), mips_kernel_reg_p, NULL))
+   && mips_refers_to_kernel_reg_p (PATTERN (insn)))
  break;
   gcc_assert (insn != NULL_RTX);
   /* Insert disable interrupts before the first use of K0 or K1.  */


[MIPS] RFA: Use new rtl iterators in mips16_rewrite_pool_refs

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.
Note that the order of the UNSPEC and TARGET_MIPS16_TEXT_LOADS handling
didn't matter because we never rewrite the unspec itself; the check is
there to protect the contents of the unspec.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mips64-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mips/mips.c (mips16_rewrite_pool_refs_info): Delete.
(mips16_rewrite_pool_refs): Take the insn and constant pool as
parameters.  Iterate over the instruction's pattern and return void.
(mips16_lay_out_constants): Update accordingly.

Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c  2014-10-25 09:51:19.947834536 +0100
+++ gcc/config/mips/mips.c  2014-10-25 09:51:20.330837950 +0100
@@ -14778,44 +14778,39 @@ mips16_rewrite_pool_constant (struct mip
 }
 }
 
-/* This structure is used to communicate with mips16_rewrite_pool_refs.
-   INSN is the instruction we're rewriting and POOL points to the current
-   constant pool.  */
-struct mips16_rewrite_pool_refs_info {
-  rtx_insn *insn;
-  struct mips16_constant_pool *pool;
-};
-
-/* Rewrite *X so that constant pool references refer to the constant's
-   label instead.  DATA points to a mips16_rewrite_pool_refs_info
-   structure.  */
+/* Rewrite INSN so that constant pool references refer to the constant's
+   label instead.  */
 
-static int
-mips16_rewrite_pool_refs (rtx *x, void *data)
+static void
+mips16_rewrite_pool_refs (rtx_insn *insn, struct mips16_constant_pool *pool)
 {
-  struct mips16_rewrite_pool_refs_info *info =
-(struct mips16_rewrite_pool_refs_info *) data;
-
-  if (force_to_mem_operand (*x, Pmode))
+  subrtx_ptr_iterator::array_type array;
+  FOR_EACH_SUBRTX_PTR (iter, array, &PATTERN (insn), ALL)
 {
-  rtx mem = force_const_mem (GET_MODE (*x), *x);
-  validate_change (info->insn, x, mem, false);
-}
+  rtx *loc = *iter;
 
-  if (MEM_P (*x))
-{
-  mips16_rewrite_pool_constant (info->pool, &XEXP (*x, 0));
-  return -1;
-}
-
-  /* Don't rewrite the __mips16_rdwr symbol.  */
-  if (GET_CODE (*x) == UNSPEC && XINT (*x, 1) == UNSPEC_TLS_GET_TP)
-return -1;
-
-  if (TARGET_MIPS16_TEXT_LOADS)
-mips16_rewrite_pool_constant (info->pool, x);
+  if (force_to_mem_operand (*loc, Pmode))
+   {
+ rtx mem = force_const_mem (GET_MODE (*loc), *loc);
+ validate_change (insn, loc, mem, false);
+   }
 
-  return GET_CODE (*x) == CONST ? -1 : 0;
+  if (MEM_P (*loc))
+   {
+ mips16_rewrite_pool_constant (pool, &XEXP (*loc, 0));
+ iter.skip_subrtxes ();
+   }
+  else
+   {
+ if (TARGET_MIPS16_TEXT_LOADS)
+   mips16_rewrite_pool_constant (pool, loc);
+ if (GET_CODE (*loc) == CONST
+ /* Don't rewrite the __mips16_rdwr symbol.  */
+ || (GET_CODE (*loc) == UNSPEC
+ && XINT (*loc, 1) == UNSPEC_TLS_GET_TP))
+   iter.skip_subrtxes ();
+   }
+}
 }
 
 /* Return whether CFG is used in mips_reorg.  */
@@ -14834,7 +14829,6 @@ mips_cfg_in_reorg (void)
 mips16_lay_out_constants (bool split_p)
 {
   struct mips16_constant_pool pool;
-  struct mips16_rewrite_pool_refs_info info;
   rtx_insn *insn, *barrier;
 
   if (!TARGET_MIPS16_PCREL_LOADS)
@@ -14853,11 +14847,7 @@ mips16_lay_out_constants (bool split_p)
 {
   /* Rewrite constant pool references in INSN.  */
   if (USEFUL_INSN_P (insn))
-   {
- info.insn = insn;
- info.pool = &pool;
- for_each_rtx (&PATTERN (insn), mips16_rewrite_pool_refs, &info);
-   }
+   mips16_rewrite_pool_refs (insn, &pool);
 
   pool.insn_address += mips16_insn_length (insn);
 


[MIPS] RFA: Use new rtl iterators in r10k_needs_protection_p_1

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mips64-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mips/mips.c (r10k_needs_protection_p_1): Take an rtx
rather than an rtx pointer.  Change type of insn from "void *"
to its real type.  Return bool rather than int.  Iterate over
all subrtxes here.
(r10k_needs_protection_p_store): Update accordingly.
(r10k_needs_protection_p): Likewise.

Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c  2014-10-25 09:51:20.330837950 +0100
+++ gcc/config/mips/mips.c  2014-10-25 09:51:20.718841409 +0100
@@ -15063,28 +15063,28 @@ r10k_safe_mem_expr_p (tree expr, unsigne
   return offset < tree_to_uhwi (DECL_SIZE_UNIT (inner));
 }
 
-/* A for_each_rtx callback for which DATA points to the instruction
-   containing *X.  Stop the search if we find a MEM that is not safe
-   from R10K speculation.  */
+/* Return true if X contains a MEM that is not safe from R10K speculation.
+   INSN is the instruction that contains X.  */
 
-static int
-r10k_needs_protection_p_1 (rtx *loc, void *data)
+static bool
+r10k_needs_protection_p_1 (rtx x, rtx_insn *insn)
 {
-  rtx mem;
-
-  mem = *loc;
-  if (!MEM_P (mem))
-return 0;
-
-  if (MEM_EXPR (mem)
-  && MEM_OFFSET_KNOWN_P (mem)
-  && r10k_safe_mem_expr_p (MEM_EXPR (mem), MEM_OFFSET (mem)))
-return -1;
-
-  if (r10k_safe_address_p (XEXP (mem, 0), (rtx_insn *) data))
-return -1;
-
-  return 1;
+  subrtx_var_iterator::array_type array;
+  FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST)
+{
+  rtx mem = *iter;
+  if (MEM_P (mem))
+   {
+ if ((MEM_EXPR (mem)
+  && MEM_OFFSET_KNOWN_P (mem)
+  && r10k_safe_mem_expr_p (MEM_EXPR (mem), MEM_OFFSET (mem)))
+ || r10k_safe_address_p (XEXP (mem, 0), insn))
+   iter.skip_subrtxes ();
+ else
+   return true;
+   }
+}
+  return false;
 }
 
 /* A note_stores callback for which DATA points to an instruction pointer.
@@ -15098,7 +15098,7 @@ r10k_needs_protection_p_store (rtx x, co
   rtx_insn **insn_ptr;
 
   insn_ptr = (rtx_insn **) data;
-  if (*insn_ptr && for_each_rtx (&x, r10k_needs_protection_p_1, *insn_ptr))
+  if (*insn_ptr && r10k_needs_protection_p_1 (x, *insn_ptr))
 *insn_ptr = NULL;
 }
 
@@ -15136,7 +15136,7 @@ r10k_needs_protection_p (rtx_insn *insn)
   return insn == NULL_RTX;
 }
 
-  return for_each_rtx (&PATTERN (insn), r10k_needs_protection_p_1, insn);
+  return r10k_needs_protection_p_1 (PATTERN (insn), insn);
 }
 
 /* Return true if BB is only reached by blocks in PROTECTED_BBS and if every


[MIPS] RFA: Use new rtl iterators in r10k_needs_protection_p_call

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mips64-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mips/mips.c (r10k_needs_protection_p_call): Take a const_rtx
and return a bool.  Iterate over all subrtxes here.
(r10k_needs_protection_p): Update accordingly.

Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c  2014-10-25 09:51:20.718841409 +0100
+++ gcc/config/mips/mips.c  2014-10-25 09:51:21.129845072 +0100
@@ -15102,23 +15102,26 @@ r10k_needs_protection_p_store (rtx x, co
 *insn_ptr = NULL;
 }
 
-/* A for_each_rtx callback that iterates over the pattern of a CALL_INSN.
-   Return nonzero if the call is not to a declared function.  */
+/* X is the pattern of a call instruction.  Return true if the call is
+   not to a declared function.  */
 
-static int
-r10k_needs_protection_p_call (rtx *loc, void *data ATTRIBUTE_UNUSED)
+static bool
+r10k_needs_protection_p_call (const_rtx x)
 {
-  rtx x;
-
-  x = *loc;
-  if (!MEM_P (x))
-return 0;
-
-  x = XEXP (x, 0);
-  if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_DECL (x))
-return -1;
-
-  return 1;
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, x, NONCONST)
+{
+  const_rtx mem = *iter;
+  if (MEM_P (mem))
+   {
+ const_rtx addr = XEXP (mem, 0);
+ if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DECL (addr))
+   iter.skip_subrtxes ();
+ else
+   return true;
+   }
+}
+  return false;
 }
 
 /* Return true if instruction INSN needs to be protected by an R10K
@@ -15128,7 +15131,7 @@ r10k_needs_protection_p_call (rtx *loc,
 r10k_needs_protection_p (rtx_insn *insn)
 {
   if (CALL_P (insn))
-return for_each_rtx (&PATTERN (insn), r10k_needs_protection_p_call, NULL);
+return r10k_needs_protection_p_call (PATTERN (insn));
 
   if (mips_r10k_cache_barrier == R10K_CACHE_BARRIER_STORE)
 {


[MIPS] RFA: Use new rtl iterators in mips_sim_wait_regs_1

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mips64-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mips/mips.c (mips_sim_insn): Update comment.
(mips_sim_wait_regs_2): Delete.
(mips_sim_wait_regs_1): Use FOR_EACH_SUBRTX_VAR.

Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c  2014-10-25 09:51:21.129845072 +0100
+++ gcc/config/mips/mips.c  2014-10-25 09:51:21.522848575 +0100
@@ -15468,7 +15468,7 @@ mips_annotate_pic_calls (void)
 }
 }
 
-/* A temporary variable used by for_each_rtx callbacks, etc.  */
+/* A temporary variable used by note_uses callbacks, etc.  */
 static rtx_insn *mips_sim_insn;
 
 /* A structure representing the state of the processor pipeline.
@@ -15562,23 +15562,16 @@ mips_sim_wait_reg (struct mips_sim *stat
 }
 }
 
-/* A for_each_rtx callback.  If *X is a register, advance simulation state
-   DATA until mips_sim_insn can read the register's value.  */
-
-static int
-mips_sim_wait_regs_2 (rtx *x, void *data)
-{
-  if (REG_P (*x))
-mips_sim_wait_reg ((struct mips_sim *) data, mips_sim_insn, *x);
-  return 0;
-}
-
-/* Call mips_sim_wait_regs_2 (R, DATA) for each register R mentioned in *X.  */
+/* A note_uses callback.  For each register in *X, advance simulation
+   state DATA until mips_sim_insn can read the register's value.  */
 
 static void
 mips_sim_wait_regs_1 (rtx *x, void *data)
 {
-  for_each_rtx (x, mips_sim_wait_regs_2, data);
+  subrtx_var_iterator::array_type array;
+  FOR_EACH_SUBRTX_VAR (iter, array, *x, NONCONST)
+if (REG_P (*iter))
+  mips_sim_wait_reg ((struct mips_sim *) data, mips_sim_insn, *iter);
 }
 
 /* Advance simulation state STATE until all of INSN's register


[MIPS] RFA: Use new rtl iterators in mips_record_lo_sums

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mips64-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mips/mips.c (mips_record_lo_sum): Replace with...
(mips_record_lo_sums): ...this new function.
(mips_reorg_process_insns): Update accordingly.

Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c  2014-10-25 09:51:21.522848575 +0100
+++ gcc/config/mips/mips.c  2014-10-25 09:51:21.912852052 +0100
@@ -16040,16 +16040,15 @@ mips_lo_sum_offset_lookup (mips_offset_t
   return INTVAL (offset) <= entry->offset;
 }
 
-/* A for_each_rtx callback for which DATA is a mips_lo_sum_offset hash table.
-   Record every LO_SUM in *LOC.  */
+/* Search X for LO_SUMs and record them in HTAB.  */
 
-static int
-mips_record_lo_sum (rtx *loc, void *data)
+static void
+mips_record_lo_sums (const_rtx x, mips_offset_table *htab)
 {
-  if (GET_CODE (*loc) == LO_SUM)
-mips_lo_sum_offset_lookup ((mips_offset_table*) data,
-  XEXP (*loc, 1), INSERT);
-  return 0;
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, x, NONCONST)
+if (GET_CODE (*iter) == LO_SUM)
+  mips_lo_sum_offset_lookup (htab, XEXP (*iter, 1), INSERT);
 }
 
 /* Return true if INSN is a SET of an orphaned high-part relocation.
@@ -16224,10 +16223,10 @@ mips_reorg_process_insns (void)
  get_referenced_operands (string, used, noperands);
  for (int i = 0; i < noperands; ++i)
if (used[i])
- for_each_rtx (&ops[i], mips_record_lo_sum, &htab);
+ mips_record_lo_sums (ops[i], &htab);
}
  else
-   for_each_rtx (&PATTERN (subinsn), mips_record_lo_sum, &htab);
+   mips_record_lo_sums (PATTERN (subinsn), &htab);
}
 
   last_insn = 0;


[MIPS] RFA: Use new rtl iterators in mips_need_noat_wrapper_p

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for mips64-elf.  OK to install?

Thanks,
Richard


gcc/
* config/mips/mips.c (mips_at_reg_p): Delete.
(mips_need_noat_wrapper_p): Use FOR_EACH_SUBRTX.

Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c  2014-10-25 09:51:21.912852052 +0100
+++ gcc/config/mips/mips.c  2014-10-25 09:51:22.291855430 +0100
@@ -17528,26 +17528,20 @@ mips_epilogue_uses (unsigned int regno)
   return false;
 }
 
-/* A for_each_rtx callback.  Stop the search if *X is an AT register.  */
-
-static int
-mips_at_reg_p (rtx *x, void *data ATTRIBUTE_UNUSED)
-{
-  return REG_P (*x) && REGNO (*x) == AT_REGNUM;
-}
-
 /* Return true if INSN needs to be wrapped in ".set noat".
INSN has NOPERANDS operands, stored in OPVEC.  */
 
 static bool
 mips_need_noat_wrapper_p (rtx_insn *insn, rtx *opvec, int noperands)
 {
-  int i;
-
   if (recog_memoized (insn) >= 0)
-for (i = 0; i < noperands; i++)
-  if (for_each_rtx (&opvec[i], mips_at_reg_p, NULL))
-   return true;
+{
+  subrtx_iterator::array_type array;
+  for (int i = 0; i < noperands; i++)
+   FOR_EACH_SUBRTX (iter, array, opvec[i], NONCONST)
+ if (REG_P (*iter) && REGNO (*iter) == AT_REGNUM)
+   return true;
+}
   return false;
 }
 


[FRV] RFA: Use new rtl iterators in frv_ifcvt_modify_tests

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.
In this particular cases there's a find_all_hard_regs function that can
be used instead, although rtl.h needs to be included after hard-reg-set.h
in order to get the declaration:

#ifdef HARD_CONST
extern void find_all_hard_regs (const_rtx, HARD_REG_SET *);
extern void find_all_hard_reg_sets (const_rtx, HARD_REG_SET *, bool);
#endif

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for frv-elf.  OK to install?

Thanks,
Richard


gcc/
* config/frv/frv.c: Move include of rtl.h after hard-reg-set.h.
(frv_clear_registers_used): Delete.
(frv_ifcvt_modify_tests): Use find_all_hard_regs.

Index: gcc/config/frv/frv.c
===
--- gcc/config/frv/frv.c2014-10-25 09:48:52.218530218 +0100
+++ gcc/config/frv/frv.c2014-10-25 09:51:22.658858701 +0100
@@ -21,13 +21,13 @@ the Free Software Foundation; either ver
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
-#include "rtl.h"
 #include "tree.h"
 #include "varasm.h"
 #include "stor-layout.h"
 #include "stringpool.h"
 #include "regs.h"
 #include "hard-reg-set.h"
+#include "rtl.h"
 #include "insn-config.h"
 #include "conditions.h"
 #include "insn-flags.h"
@@ -326,7 +326,6 @@ static rtx frv_expand_mwtacc_builtin(e
 static rtx frv_expand_noargs_builtin   (enum insn_code);
 static void frv_split_iacc_move(rtx, rtx);
 static rtx frv_emit_comparison (enum rtx_code, rtx, rtx);
-static int frv_clear_registers_used(rtx *, void *);
 static void frv_ifcvt_add_insn (rtx, rtx, int);
 static rtx frv_ifcvt_rewrite_mem   (rtx, enum machine_mode, rtx);
 static rtx frv_ifcvt_load_value(rtx, rtx);
@@ -5185,33 +5184,6 @@ frv_split_abs (rtx operands[])
 }
 
 
-/* An internal function called by for_each_rtx to clear in a hard_reg set each
-   register used in an insn.  */
-
-static int
-frv_clear_registers_used (rtx *ptr, void *data)
-{
-  if (GET_CODE (*ptr) == REG)
-{
-  int regno = REGNO (*ptr);
-  HARD_REG_SET *p_regs = (HARD_REG_SET *)data;
-
-  if (regno < FIRST_PSEUDO_REGISTER)
-   {
- int reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (*ptr));
-
- while (regno < reg_max)
-   {
- CLEAR_HARD_REG_BIT (*p_regs, regno);
- regno++;
-   }
-   }
-}
-
-  return 0;
-}
-
-
 /* Initialize machine-specific if-conversion data.
On the FR-V, we don't have any extra fields per se, but it is useful hook to
initialize the static storage.  */
@@ -5404,9 +5376,11 @@ frv_ifcvt_modify_tests (ce_if_block *ce_
  rtx pattern;
  rtx set;
  int skip_nested_if = FALSE;
+ HARD_REG_SET mentioned_regs;
 
- for_each_rtx (&PATTERN (insn), frv_clear_registers_used,
-   (void *)&tmp_reg->regs);
+ CLEAR_HARD_REG_SET (mentioned_regs);
+ find_all_hard_regs (PATTERN (insn), &mentioned_regs);
+ AND_COMPL_HARD_REG_SET (tmp_reg->regs, mentioned_regs);
 
  pattern = PATTERN (insn);
  if (GET_CODE (pattern) == COND_EXEC)
@@ -5442,8 +5416,8 @@ frv_ifcvt_modify_tests (ce_if_block *ce_
}
 
  if (! skip_nested_if)
-   for_each_rtx (&PATTERN (insn), frv_clear_registers_used,
- (void *)&frv_ifcvt.nested_cc_ok_rewrite);
+   AND_COMPL_HARD_REG_SET (frv_ifcvt.nested_cc_ok_rewrite,
+   mentioned_regs);
}
 
  if (insn == last_insn)


[FRV] RFA: Use new rtl iterators in frv_acc_group

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for frv-elf.  OK to install?

Thanks,
Richard


gcc/
* config/frv/frv.c: Include rtl-iter.h.
(frv_acc_group_1): Delete.
(frv_acc_group): Use FOR_EACH_SUBRTX.

Index: gcc/config/frv/frv.c
===
--- gcc/config/frv/frv.c2014-10-25 09:51:22.658858701 +0100
+++ gcc/config/frv/frv.c2014-10-25 09:51:23.05386 +0100
@@ -58,6 +58,7 @@ the Free Software Foundation; either ver
 #include "dumpfile.h"
 #include "builtins.h"
 #include "ifcvt.h"
+#include "rtl-iter.h"
 
 #ifndef FRV_INLINE
 #define FRV_INLINE inline
@@ -329,7 +330,6 @@ static rtx frv_emit_comparison  (enum r
 static void frv_ifcvt_add_insn (rtx, rtx, int);
 static rtx frv_ifcvt_rewrite_mem   (rtx, enum machine_mode, rtx);
 static rtx frv_ifcvt_load_value(rtx, rtx);
-static int frv_acc_group_1 (rtx *, void *);
 static unsigned int frv_insn_unit  (rtx_insn *);
 static bool frv_issues_to_branch_unit_p(rtx_insn *);
 static int frv_cond_flags  (rtx);
@@ -7004,33 +7004,29 @@ frv_issue_rate (void)
 }
 }
 
-/* A for_each_rtx callback.  If X refers to an accumulator, return
-   ACC_GROUP_ODD if the bit 2 of the register number is set and
-   ACC_GROUP_EVEN if it is clear.  Return 0 (ACC_GROUP_NONE)
-   otherwise.  */
-
-static int
-frv_acc_group_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
-{
-  if (REG_P (*x))
-{
-  if (ACC_P (REGNO (*x)))
-   return (REGNO (*x) - ACC_FIRST) & 4 ? ACC_GROUP_ODD : ACC_GROUP_EVEN;
-  if (ACCG_P (REGNO (*x)))
-   return (REGNO (*x) - ACCG_FIRST) & 4 ? ACC_GROUP_ODD : ACC_GROUP_EVEN;
-}
-  return 0;
-}
-
 /* Return the value of INSN's acc_group attribute.  */
 
 int
 frv_acc_group (rtx insn)
 {
   /* This distinction only applies to the FR550 packing constraints.  */
-  if (frv_cpu_type != FRV_CPU_FR550)
-return ACC_GROUP_NONE;
-  return for_each_rtx (&PATTERN (insn), frv_acc_group_1, 0);
+  if (frv_cpu_type == FRV_CPU_FR550)
+{
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
+   if (REG_P (*iter))
+ {
+   unsigned int regno = REGNO (*iter);
+   /* If REGNO refers to an accumulator, return ACC_GROUP_ODD if
+  the bit 2 of the register number is set and ACC_GROUP_EVEN if
+  it is clear.  */
+   if (ACC_P (regno))
+ return (regno - ACC_FIRST) & 4 ? ACC_GROUP_ODD : ACC_GROUP_EVEN;
+   if (ACCG_P (regno))
+ return (regno - ACCG_FIRST) & 4 ? ACC_GROUP_ODD : ACC_GROUP_EVEN;
+ }
+}
+  return ACC_GROUP_NONE;
 }
 
 /* Return the index of the DFA unit in FRV_UNIT_NAMES[] that instruction


[FRV] RFA: Use new rtl iterators in frv_registers_conflict_p_1

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for frv-elf.  OK to install?

Thanks,
Richard


gcc/
* config/frv/frv.c (frv_registers_conflict_p_1): Take an rtx rather
than an rtx *.  Take the regstate_t directly rather than via a void *.
Return a bool rather than an int.  Iterate over all subrtxes here.
(frv_registers_conflict_p): Update accordingly.

Index: gcc/config/frv/frv.c
===
--- gcc/config/frv/frv.c2014-10-25 09:51:23.05386 +0100
+++ gcc/config/frv/frv.c2014-10-25 09:51:23.450865761 +0100
@@ -334,7 +334,6 @@ static unsigned int frv_insn_unit   (rtx_
 static bool frv_issues_to_branch_unit_p(rtx_insn *);
 static int frv_cond_flags  (rtx);
 static bool frv_regstate_conflict_p(regstate_t, regstate_t);
-static int frv_registers_conflict_p_1  (rtx *, void *);
 static bool frv_registers_conflict_p   (rtx);
 static void frv_registers_update_1 (rtx, const_rtx, void *);
 static void frv_registers_update   (rtx);
@@ -7162,53 +7161,49 @@ frv_regstate_conflict_p (regstate_t cond
 }
 
 
-/* A for_each_rtx callback.  Return 1 if *X depends on an instruction in
-   the current packet.  DATA points to a regstate_t that describes the
-   condition under which *X might be set or used.  */
+/* Return true if an instruction with pattern PAT depends on an
+   instruction in the current packet.  COND describes the condition
+   under which PAT might be set or used.  */
 
-static int
-frv_registers_conflict_p_1 (rtx *x, void *data)
+static bool
+frv_registers_conflict_p_1 (rtx pat, regstate_t cond)
 {
-  unsigned int regno, i;
-  regstate_t cond;
-
-  cond = *(regstate_t *) data;
-
-  if (GET_CODE (*x) == REG)
-FOR_EACH_REGNO (regno, *x)
-  if ((frv_packet.regstate[regno] & REGSTATE_MODIFIED) != 0)
-   if (frv_regstate_conflict_p (frv_packet.regstate[regno], cond))
- return 1;
-
-  if (GET_CODE (*x) == MEM)
+  subrtx_var_iterator::array_type array;
+  FOR_EACH_SUBRTX_VAR (iter, array, pat, NONCONST)
 {
-  /* If we ran out of memory slots, assume a conflict.  */
-  if (frv_packet.num_mems > ARRAY_SIZE (frv_packet.mems))
-   return 1;
+  rtx x = *iter;
+  if (GET_CODE (x) == REG)
+   {
+ unsigned int regno;
+ FOR_EACH_REGNO (regno, x)
+   if ((frv_packet.regstate[regno] & REGSTATE_MODIFIED) != 0)
+ if (frv_regstate_conflict_p (frv_packet.regstate[regno], cond))
+   return true;
+   }
+  else if (GET_CODE (x) == MEM)
+   {
+ /* If we ran out of memory slots, assume a conflict.  */
+ if (frv_packet.num_mems > ARRAY_SIZE (frv_packet.mems))
+   return 1;
 
-  /* Check for output or true dependencies with earlier MEMs.  */
-  for (i = 0; i < frv_packet.num_mems; i++)
-   if (frv_regstate_conflict_p (frv_packet.mems[i].cond, cond))
- {
-   if (true_dependence (frv_packet.mems[i].mem, VOIDmode, *x))
- return 1;
+ /* Check for output or true dependencies with earlier MEMs.  */
+ for (unsigned int i = 0; i < frv_packet.num_mems; i++)
+   if (frv_regstate_conflict_p (frv_packet.mems[i].cond, cond))
+ {
+   if (true_dependence (frv_packet.mems[i].mem, VOIDmode, x))
+ return true;
 
-   if (output_dependence (frv_packet.mems[i].mem, *x))
- return 1;
- }
-}
+   if (output_dependence (frv_packet.mems[i].mem, x))
+ return true;
+ }
+   }
 
-  /* The return values of calls aren't significant: they describe
- the effect of the call as a whole, not of the insn itself.  */
-  if (GET_CODE (*x) == SET && GET_CODE (SET_SRC (*x)) == CALL)
-{
-  if (for_each_rtx (&SET_SRC (*x), frv_registers_conflict_p_1, data))
-   return 1;
-  return -1;
+  /* The return values of calls aren't significant: they describe
+the effect of the call as a whole, not of the insn itself.  */
+  else if (GET_CODE (x) == SET && GET_CODE (SET_SRC (x)) == CALL)
+   iter.substitute (SET_SRC (x));
 }
-
-  /* Check subexpressions.  */
-  return 0;
+  return false;
 }
 
 
@@ -7223,13 +7218,13 @@ frv_registers_conflict_p (rtx x)
   flags = 0;
   if (GET_CODE (x) == COND_EXEC)
 {
-  if (for_each_rtx (&XEXP (x, 0), frv_registers_conflict_p_1, &flags))
+  if (frv_registers_conflict_p_1 (XEXP (x, 0), flags))
return true;
 
   flags |= frv_cond_flags (XEXP (x, 0));
   x = XEXP (x, 1);
 }
-  return for_each_rtx (&x, frv_registers_conflict_p_1, &flags);
+  return frv_registers_conflict_p_1 (x, flags);
 }
 
 


[FRV] RFA: Use new rtl iterators in frv_io_handle_use

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.
As with the first FR-V patch, we can find_all_hard_regs instead.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for frv-elf.  OK to install?

Thanks,
Richard


gcc/
* config/frv/frv.c (frv_io_handle_use_1): Delete.
(frv_io_handle_use): Use find_all_hard_regs.

Index: gcc/config/frv/frv.c
===
--- gcc/config/frv/frv.c2014-10-25 09:51:23.450865761 +0100
+++ gcc/config/frv/frv.c2014-10-25 09:51:23.839869228 +0100
@@ -7793,29 +7793,13 @@ frv_io_handle_set (rtx x, const_rtx pat
   CLEAR_HARD_REG_BIT (*set, regno);
 }
 
-/* A for_each_rtx callback for which DATA points to a HARD_REG_SET.
-   Add every register in *X to the set.  */
-
-static int
-frv_io_handle_use_1 (rtx *x, void *data)
-{
-  HARD_REG_SET *set = (HARD_REG_SET *) data;
-  unsigned int regno;
-
-  if (REG_P (*x))
-FOR_EACH_REGNO (regno, *x)
-  SET_HARD_REG_BIT (*set, regno);
-
-  return 0;
-}
-
-/* A note_stores callback that applies frv_io_handle_use_1 to an
-   entire rhs value.  */
+/* A note_uses callback that adds all registers in *X to hard register
+   set *DATA.  */
 
 static void
 frv_io_handle_use (rtx *x, void *data)
 {
-  for_each_rtx (x, frv_io_handle_use_1, data);
+  find_all_hard_regs (*x, (HARD_REG_SET *) data);
 }
 
 /* Go through block BB looking for membars to remove.  There are two


[ARC] RFA: Use new rtl iterators in arc_rewrite_small_data

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.
As with the first FR-V patch, we can find_all_hard_regs instead.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for arc-elf.  OK to install?

Thanks,
Richard


gcc/
* config/arc/arc.c: Include rtl-iter.h.
(arc_rewrite_small_data_1): Delete.
(arc_rewrite_small_data): Use FOR_EACH_SUBRTX_PTR.

Index: gcc/config/arc/arc.c
===
--- gcc/config/arc/arc.c2014-10-25 09:40:38.176518180 +0100
+++ gcc/config/arc/arc.c2014-10-25 09:51:25.501884042 +0100
@@ -72,6 +72,7 @@ the Free Software Foundation; either ver
 #include "pass_manager.h"
 #include "wide-int.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 /* Which cpu we're compiling for (A5, ARC600, ARC601, ARC700).  */
 static const char *arc_cpu_string = "";
@@ -6351,38 +6352,6 @@ arc_rewrite_small_data_p (rtx x)
  && SYMBOL_REF_SMALL_P(x));
 }
 
-/* A for_each_rtx callback, used by arc_rewrite_small_data.  */
-
-static int
-arc_rewrite_small_data_1 (rtx *loc, void *data)
-{
-  if (arc_rewrite_small_data_p (*loc))
-{
-  rtx top;
-
-  gcc_assert (SDATA_BASE_REGNUM == PIC_OFFSET_TABLE_REGNUM);
-  *loc = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, *loc);
-  if (loc == data)
-   return -1;
-  top = *(rtx*) data;
-  if (GET_CODE (top) == MEM && &XEXP (top, 0) == loc)
-   ; /* OK.  */
-  else if (GET_CODE (top) == MEM
- && GET_CODE (XEXP (top, 0)) == PLUS
- && GET_CODE (XEXP (XEXP (top, 0), 0)) == MULT)
-   *loc = force_reg (Pmode, *loc);
-  else
-   gcc_unreachable ();
-  return -1;
-}
-
-  if (GET_CODE (*loc) == PLUS
-  && rtx_equal_p (XEXP (*loc, 0), pic_offset_table_rtx))
-return -1;
-
-  return 0;
-}
-
 /* If possible, rewrite OP so that it refers to small data using
explicit relocations.  */
 
@@ -6390,7 +6359,31 @@ arc_rewrite_small_data_1 (rtx *loc, void
 arc_rewrite_small_data (rtx op)
 {
   op = copy_insn (op);
-  for_each_rtx (&op, arc_rewrite_small_data_1, &op);
+  subrtx_ptr_iterator::array_type array;
+  FOR_EACH_SUBRTX_PTR (iter, array, &op, ALL)
+{
+  rtx *loc = *iter;
+  if (arc_rewrite_small_data_p (*loc))
+   {
+ gcc_assert (SDATA_BASE_REGNUM == PIC_OFFSET_TABLE_REGNUM);
+ *loc = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, *loc);
+ if (loc != &op)
+   {
+ if (GET_CODE (op) == MEM && &XEXP (op, 0) == loc)
+   ; /* OK.  */
+ else if (GET_CODE (op) == MEM
+  && GET_CODE (XEXP (op, 0)) == PLUS
+  && GET_CODE (XEXP (XEXP (op, 0), 0)) == MULT)
+   *loc = force_reg (Pmode, *loc);
+ else
+   gcc_unreachable ();
+   }
+ iter.skip_subrtxes ();
+   }
+  else if (GET_CODE (*loc) == PLUS
+  && rtx_equal_p (XEXP (*loc, 0), pic_offset_table_rtx))
+   iter.skip_subrtxes ();
+}
   return op;
 }
 


[ARC] RFA: Use new rtl iterators in small_data_pattern

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for arc-elf.  OK to install?

Thanks,
Richard


gcc/
* config/arc/arc.c (arc_rewrite_small_data_p): Constify argument.
(small_data_pattern_1): Delete.
(small_data_pattern): Use FOR_EACH_SUBRTX.

Index: gcc/config/arc/arc.c
===
--- gcc/config/arc/arc.c2014-10-25 09:51:25.501884042 +0100
+++ gcc/config/arc/arc.c2014-10-25 09:51:25.901887608 +0100
@@ -6337,7 +6337,7 @@ arc_in_small_data_p (const_tree decl)
as a gp+symref.  */
 
 static bool
-arc_rewrite_small_data_p (rtx x)
+arc_rewrite_small_data_p (const_rtx x)
 {
   if (GET_CODE (x) == CONST)
 x = XEXP (x, 0);
@@ -6387,26 +6387,25 @@ arc_rewrite_small_data (rtx op)
   return op;
 }
 
-/* A for_each_rtx callback for small_data_pattern.  */
-
-static int
-small_data_pattern_1 (rtx *loc, void *data ATTRIBUTE_UNUSED)
-{
-  if (GET_CODE (*loc) == PLUS
-  && rtx_equal_p (XEXP (*loc, 0), pic_offset_table_rtx))
-return  -1;
-
-  return arc_rewrite_small_data_p (*loc);
-}
-
 /* Return true if OP refers to small data symbols directly, not through
a PLUS.  */
 
 bool
 small_data_pattern (rtx op, enum machine_mode)
 {
-  return (GET_CODE (op) != SEQUENCE
- && for_each_rtx (&op, small_data_pattern_1, 0));
+  if (GET_CODE (op) == SEQUENCE)
+return false;
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, op, ALL)
+{
+  const_rtx x = *iter;
+  if (GET_CODE (x) == PLUS
+ && rtx_equal_p (XEXP (x, 0), pic_offset_table_rtx))
+   iter.skip_subrtxes ();
+  else if (arc_rewrite_small_data_p (x))
+   return true;
+}
+  return false;
 }
 
 /* Return true if OP is an acceptable memory operand for ARCompact


Re: [ARC] RFA: Use new rtl iterators in arc_rewrite_small_data

2014-10-25 Thread Richard Sandiford
Richard Sandiford  writes:
> This is part of a series to remove uses of for_each_rtx from the ports.
> As with the first FR-V patch, we can find_all_hard_regs instead.

Oops, forgot that line :-)


[ARC] RFA: Use new rtl iterators in arc600_corereg_hazard

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for arc-elf.  OK to install?

Thanks,
Richard


gcc/
* config/arc/arc.c (arc600_corereg_hazard_1): Delete.
(arc600_corereg_hazard): Use FOR_EACH_SUBRTX.

Index: gcc/config/arc/arc.c
===
--- gcc/config/arc/arc.c2014-10-25 09:51:25.901887608 +0100
+++ gcc/config/arc/arc.c2014-10-25 09:51:26.279890977 +0100
@@ -7698,38 +7698,6 @@ disi_highpart (rtx in)
   return simplify_gen_subreg (SImode, in, DImode, TARGET_BIG_ENDIAN ? 0 : 4);
 }
 
-/* Called by arc600_corereg_hazard via for_each_rtx.
-   If a hazard is found, return a conservative estimate of the required
-   length adjustment to accomodate a nop.  */
-
-static int
-arc600_corereg_hazard_1 (rtx *xp, void *data)
-{
-  rtx x = *xp;
-  rtx dest;
-  rtx pat = (rtx) data;
-
-  switch (GET_CODE (x))
-{
-case SET: case POST_INC: case POST_DEC: case PRE_INC: case PRE_DEC:
-  break;
-default:
-/* This is also fine for PRE/POST_MODIFY, because they contain a SET.  */
-  return 0;
-}
-  dest = XEXP (x, 0);
-  /* Check if this sets a an extension register.  N.B. we use 61 for the
- condition codes, which is definitely not an extension register.  */
-  if (REG_P (dest) && REGNO (dest) >= 32 && REGNO (dest) < 61
-  /* Check if the same register is used by the PAT.  */
-  && (refers_to_regno_p
-  (REGNO (dest),
-  REGNO (dest) + (GET_MODE_SIZE (GET_MODE (dest)) + 3) / 4U, pat, 0)))
-return 4;
-
-  return 0;
-}
-
 /* Return length adjustment for INSN.
For ARC600:
A write to a core reg greater or equal to 32 must not be immediately
@@ -7761,8 +7729,31 @@ arc600_corereg_hazard (rtx_insn *pred, r
   || recog_memoized (pred) == CODE_FOR_umul64_600
   || recog_memoized (pred) == CODE_FOR_umac64_600)
 return 0;
-  return for_each_rtx (&PATTERN (pred), arc600_corereg_hazard_1,
-  PATTERN (succ));
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, PATTERN (pred), NONCONST)
+{
+  const_rtx x = *iter;
+  switch (GET_CODE (x))
+   {
+   case SET: case POST_INC: case POST_DEC: case PRE_INC: case PRE_DEC:
+ break;
+   default:
+ /* This is also fine for PRE/POST_MODIFY, because they
+contain a SET.  */
+ continue;
+   }
+  rtx dest = XEXP (x, 0);
+  /* Check if this sets a an extension register.  N.B. we use 61 for the
+condition codes, which is definitely not an extension register.  */
+  if (REG_P (dest) && REGNO (dest) >= 32 && REGNO (dest) < 61
+ /* Check if the same register is used by the PAT.  */
+ && (refers_to_regno_p
+ (REGNO (dest),
+  REGNO (dest) + (GET_MODE_SIZE (GET_MODE (dest)) + 3) / 4U,
+  PATTERN (succ), 0)))
+   return 4;
+}
+  return 0;
 }
 
 /* For ARC600:


[ARC] RFA: Use new rtl iterators in arc_write_ext_corereg

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for arc-elf.  OK to install?

Thanks,
Richard


gcc/
* config/arc/arc.c (write_ext_corereg_1): Delete.
(arc_write_ext_corereg): Use FOR_EACH_SUBRTX.

Index: gcc/config/arc/arc.c
===
--- gcc/config/arc/arc.c2014-10-25 09:51:26.279890977 +0100
+++ gcc/config/arc/arc.c2014-10-25 09:51:26.656894338 +0100
@@ -8423,34 +8423,30 @@ arc_predicate_delay_insns (void)
   be hoisted out into a delay slot, a basic block can also be emptied this
   way, and branch and/or fall through targets be redirected.  Hence we don't
   want such writes in a delay slot.  */
-/* Called by arc_write_ext_corereg via for_each_rtx.  */
-
-static int
-write_ext_corereg_1 (rtx *xp, void *data ATTRIBUTE_UNUSED)
-{
-  rtx x = *xp;
-  rtx dest;
-
-  switch (GET_CODE (x))
-{
-case SET: case POST_INC: case POST_DEC: case PRE_INC: case PRE_DEC:
-  break;
-default:
-/* This is also fine for PRE/POST_MODIFY, because they contain a SET.  */
-  return 0;
-}
-  dest = XEXP (x, 0);
-  if (REG_P (dest) && REGNO (dest) >= 32 && REGNO (dest) < 61)
-return 1;
-  return 0;
-}
 
 /* Return nonzreo iff INSN writes to an extension core register.  */
 
 int
 arc_write_ext_corereg (rtx insn)
 {
-  return for_each_rtx (&PATTERN (insn), write_ext_corereg_1, 0);
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
+{
+  const_rtx x = *iter;
+  switch (GET_CODE (x))
+   {
+   case SET: case POST_INC: case POST_DEC: case PRE_INC: case PRE_DEC:
+ break;
+   default:
+ /* This is also fine for PRE/POST_MODIFY, because they
+contain a SET.  */
+ continue;
+   }
+  const_rtx dest = XEXP (x, 0);
+  if (REG_P (dest) && REGNO (dest) >= 32 && REGNO (dest) < 61)
+   return 1;
+}
+  return 0;
 }
 
 /* This is like the hook, but returns NULL when it can't / won't generate


[SH] RFA: Use new rtl iterators in shmedia_cleanup_truncate

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.
There are some some small rearrangements to cope with the 80-character limit.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for sh-elf.  OK to install?

Thanks,
Richard


gcc/
* config/sh/sh-protos.h (shmedia_cleanup_truncate): Take an
rtx as argument and return the number of changes.
* config/sh/sh.c: Include rtl-iter.h.
(shmedia_cleanup_truncate): Take an rtx as argument and iterate
over all subrtxes.  Return the number of changes made.
* config/sh/sh.md: Update caller accordingly.

Index: gcc/config/sh/sh-protos.h
===
--- gcc/config/sh/sh-protos.h   2014-10-25 09:40:38.030517007 +0100
+++ gcc/config/sh/sh-protos.h   2014-10-25 09:51:27.047897823 +0100
@@ -215,7 +215,7 @@ extern void sh_init_cumulative_args (CUM
 extern rtx sh_dwarf_register_span (rtx);
 
 extern rtx replace_n_hard_rtx (rtx, rtx *, int , int);
-extern int shmedia_cleanup_truncate (rtx *, void *);
+extern int shmedia_cleanup_truncate (rtx);
 
 extern bool sh_contains_memref_p (rtx);
 extern bool sh_loads_bankedreg_p (rtx);
Index: gcc/config/sh/sh.c
===
--- gcc/config/sh/sh.c  2014-10-25 09:40:38.030517007 +0100
+++ gcc/config/sh/sh.c  2014-10-25 09:51:27.049897841 +0100
@@ -78,6 +78,7 @@ the Free Software Foundation; either ver
 #include "pass_manager.h"
 #include "context.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 int code_for_indirect_jump_scratch = CODE_FOR_indirect_jump_scratch;
 
@@ -12940,25 +12941,30 @@ sh_gen_truncate (enum machine_mode mode,
   return gen_rtx_fmt_e (code, mode, x);
 }
 
-/* Called via for_each_rtx after reload, to clean up truncates of
-   registers that span multiple actual hard registers.  */
+/* Look through X cleaning up truncates of registers that span multiple
+   actual hard registers.  Return the number of changes made.  */
 int
-shmedia_cleanup_truncate (rtx *p, void *n_changes)
+shmedia_cleanup_truncate (rtx x)
 {
-  rtx x = *p, reg;
-
-  if (GET_CODE (x) != TRUNCATE)
-return 0;
-  reg = XEXP (x, 0);
-  if (GET_MODE_SIZE (GET_MODE (reg)) > 8 && REG_P (reg))
+  int n_changes = 0;
+  subrtx_var_iterator::array_type array;
+  FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST)
 {
-  enum machine_mode reg_mode = GET_MODE (reg);
-  XEXP (x, 0) = simplify_subreg (DImode, reg, reg_mode,
-subreg_lowpart_offset (DImode, reg_mode));
-  *(int*) n_changes += 1;
-  return -1;
+  rtx x = *iter;
+  if (GET_CODE (x) == TRUNCATE)
+   {
+ rtx reg = XEXP (x, 0);
+ enum machine_mode reg_mode = GET_MODE (reg);
+ if (REG_P (reg) && GET_MODE_SIZE (reg_mode) > 8)
+   {
+ int offset = subreg_lowpart_offset (DImode, reg_mode);
+ XEXP (x, 0) = simplify_subreg (DImode, reg, reg_mode, offset);
+ n_changes += 1;
+ iter.skip_subrtxes ();
+   }
+   }
 }
-  return 0;
+  return n_changes;
 }
 
 /* Load and store depend on the highpart of the address.  However,
Index: gcc/config/sh/sh.md
===
--- gcc/config/sh/sh.md 2014-10-25 09:40:38.030517007 +0100
+++ gcc/config/sh/sh.md 2014-10-25 09:51:27.051897858 +0100
@@ -15803,10 +15803,7 @@ (define_split
   "TARGET_SHMEDIA && reload_completed"
   [(set (match_dup 0) (match_dup 1))]
 {
-  int n_changes = 0;
-
-  for_each_rtx (&operands[1], shmedia_cleanup_truncate, &n_changes);
-  if (!n_changes)
+  if (!shmedia_cleanup_truncate (operands[1]))
 FAIL;
 })
 


[SH] RFA: Use new rtl iterators in sh_contains_memref_p

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for sh-elf.  OK to install?

Thanks,
Richard


gcc/
* config/sh/sh.c (sh_contains_memref_p_1): Delete.
(sh_contains_memref_p): Use FOR_EACH_SUBRTX.

Index: gcc/config/sh/sh.c
===
--- gcc/config/sh/sh.c  2014-10-25 09:51:27.049897841 +0100
+++ gcc/config/sh/sh.c  2014-10-25 09:51:27.492901789 +0100
@@ -12972,18 +12972,15 @@ shmedia_cleanup_truncate (rtx x)
so we must look at the rtl ourselves to see if any of the feeding
registers is used in a memref.
 
-   Called by sh_contains_memref_p via for_each_rtx.  */
-static int
-sh_contains_memref_p_1 (rtx *loc, void *data ATTRIBUTE_UNUSED)
-{
-  return (MEM_P (*loc));
-}
-
-/* Return true iff INSN contains a MEM.  */
+   Return true iff INSN contains a MEM.  */
 bool
 sh_contains_memref_p (rtx insn)
 {
-  return for_each_rtx (&PATTERN (insn), &sh_contains_memref_p_1, NULL);
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
+if (MEM_P (*iter))
+  return true;
+  return false;
 }
 
 /* Return true iff INSN loads a banked register.  */


[microblaze] RFA: Use new rtl iterators in microblaze_tls_referenced_p

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for microblaze-elf.  OK to install?

Thanks,
Richard


gcc/
* config/microblaze/microblaze.c: Include rtl-iter.h.
(microblaze_tls_referenced_p_1): Delete.
(microblaze_tls_referenced_p): Use FOR_EACH_SUBRTX.

Index: gcc/config/microblaze/microblaze.c
===
--- gcc/config/microblaze/microblaze.c  2014-10-25 09:40:37.967516501 +0100
+++ gcc/config/microblaze/microblaze.c  2014-10-25 09:51:27.863905096 +0100
@@ -56,6 +56,7 @@
 #include "diagnostic-core.h"
 #include "cgraph.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 #define MICROBLAZE_VERSION_COMPARE(VA,VB) strcasecmp (VA, VB)
 
@@ -444,20 +445,6 @@ microblaze_tls_symbol_p (rtx x)
   return SYMBOL_REF_TLS_MODEL (x) != 0;
 }
 
-static int
-microblaze_tls_operand_p_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
-{
-  if (GET_CODE (*x) == SYMBOL_REF)
-return SYMBOL_REF_TLS_MODEL (*x) != 0;
-
-  /* Don't recurse into UNSPEC_TLS looking for TLS symbols; these are
- TLS offsets, not real symbol references.  */
-  if (GET_CODE (*x) == UNSPEC && XINT (*x, 1) == UNSPEC_TLS)
-return -1;
-
-  return 0;
-}
-
 /* Return TRUE if X contains any TLS symbol references.  */
 
 bool
@@ -465,8 +452,18 @@ microblaze_tls_referenced_p (rtx x)
 {
   if (!TARGET_HAVE_TLS)
 return false;
-
-  return for_each_rtx (&x, microblaze_tls_operand_p_1, NULL);
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, x, ALL)
+{
+  const_rtx x = *iter;
+  if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0)
+   return true;
+  /* Don't recurse into UNSPEC_TLS looking for TLS symbols; these are
+TLS offsets, not real symbol references.  */
+  if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS)
+   iter.skip_subrtxes ();
+}
+  return false;
 }
 
 bool


[s390] RFA: Use new rtl iterators in s390_loop_unroll_adjust

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.
I think we only want to consider MEMs in patterns here, not MEMs in notes etc.
(Not sure why I "fixed" it for s390 but not for x86...)

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for s390x-linux-gnu.  OK to install?

Thanks,
Richard


gcc/
* config/s390/s390.c: Include rtl-iter.h.
(check_dpu): Delete.
(s390_loop_unroll_adjust): Only iterate over patterns.
Use FOR_EACH_SUBRTX.

Index: gcc/config/s390/s390.c
===
--- gcc/config/s390/s390.c  2014-10-25 09:40:37.948516349 +0100
+++ gcc/config/s390/s390.c  2014-10-25 09:51:28.229908359 +0100
@@ -74,6 +74,7 @@ Software Foundation; either version 3, o
 #include "tree-pass.h"
 #include "context.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 /* Define the specific costs for a given cpu.  */
 
@@ -11749,19 +11750,6 @@ s390_sched_init (FILE *file ATTRIBUTE_UN
   s390_sched_state = 0;
 }
 
-/* This function checks the whole of insn X for memory references. The
-   function always returns zero because the framework it is called
-   from would stop recursively analyzing the insn upon a return value
-   other than zero. The real result of this function is updating
-   counter variable MEM_COUNT.  */
-static int
-check_dpu (rtx *x, unsigned *mem_count)
-{
-  if (*x != NULL_RTX && MEM_P (*x))
-(*mem_count)++;
-  return 0;
-}
-
 /* This target hook implementation for TARGET_LOOP_UNROLL_ADJUST calculates
a new number struct loop *loop should be unrolled if tuned for cpus with
a built-in stride prefetcher.
@@ -11784,12 +11772,13 @@ s390_loop_unroll_adjust (unsigned nunrol
 
   /* Count the number of memory references within the loop body.  */
   bbs = get_loop_body (loop);
+  subrtx_iterator::array_type array;
   for (i = 0; i < loop->num_nodes; i++)
-{
-  for (insn = BB_HEAD (bbs[i]); insn != BB_END (bbs[i]); insn = NEXT_INSN 
(insn))
-   if (INSN_P (insn) && INSN_CODE (insn) != -1)
-for_each_rtx_in_insn (&insn, (rtx_function) check_dpu, &mem_count);
-}
+FOR_BB_INSNS (bbs[i], insn)
+  if (INSN_P (insn) && INSN_CODE (insn) != -1)
+   FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
+ if (MEM_P (*iter))
+   mem_count += 1;
   free (bbs);
 
   /* Prevent division by zero, and we do not need to adjust nunroll in this 
case.  */


[alpha] RFA: Use new rtl iterators in split_small_symbolic_operand

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for alpha-linux-gnu.  OK to install?

Thanks,
Richard


gcc/
* config/alpha/alpha.c: Include rtl-iter.h.
(split_small_symbolic_operand_1): Delete.
(split_small_symbolic_operand): Use FOR_EACH_SUBRTX_PTR.

Index: gcc/config/alpha/alpha.c
===
--- gcc/config/alpha/alpha.c2014-10-25 09:40:37.907516019 +0100
+++ gcc/config/alpha/alpha.c2014-10-25 09:51:29.006915284 +0100
@@ -80,6 +80,7 @@ the Free Software Foundation; either ver
 #include "opts.h"
 #include "params.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 /* Specify which cpu to schedule for.  */
 enum processor_type alpha_tune;
@@ -1236,30 +1237,24 @@ some_small_symbolic_operand_int (rtx *px
   return small_symbolic_operand (x, Pmode) != 0;
 }
 
-static int
-split_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
-{
-  rtx x = *px;
-
-  /* Don't re-split.  */
-  if (GET_CODE (x) == LO_SUM)
-return -1;
-
-  if (small_symbolic_operand (x, Pmode))
-{
-  x = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, x);
-  *px = x;
-  return -1;
-}
-
-  return 0;
-}
-
 rtx
 split_small_symbolic_operand (rtx x)
 {
   x = copy_insn (x);
-  for_each_rtx (&x, split_small_symbolic_operand_1, NULL);
+  subrtx_ptr_iterator::array_type array;
+  FOR_EACH_SUBRTX_PTR (iter, array, &x, ALL)
+{
+  rtx *ptr = *iter;
+  rtx x = *ptr;
+  /* Don't re-split.  */
+  if (GET_CODE (x) == LO_SUM)
+   iter.skip_subrtxes ();
+  else if (small_symbolic_operand (x, Pmode))
+   {
+ *ptr = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, x);
+ iter.skip_subrtxes ();
+   }
+}
   return x;
 }
 


[alpha] RFA: Use new rtl iterators in alpha_set_memflags

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for alpha-linux-gnu.  OK to install?

Thanks,
Richard


gcc/
* config/alpha/alpha.c (alpha_set_memflags_1): Delete.
(alpha_set_memflags): Use FOR_EACH_SUBRTX_VAR.

Index: gcc/config/alpha/alpha.c
===
--- gcc/config/alpha/alpha.c2014-10-25 09:51:29.006915284 +0100
+++ gcc/config/alpha/alpha.c2014-10-25 09:51:29.394918743 +0100
@@ -1668,30 +1668,6 @@ alpha_secondary_reload (bool in_p, rtx x
   return NO_REGS;
 }
 
-/* Subfunction of the following function.  Update the flags of any MEM
-   found in part of X.  */
-
-static int
-alpha_set_memflags_1 (rtx *xp, void *data)
-{
-  rtx x = *xp, orig = (rtx) data;
-
-  if (!MEM_P (x))
-return 0;
-
-  MEM_VOLATILE_P (x) = MEM_VOLATILE_P (orig);
-  MEM_NOTRAP_P (x) = MEM_NOTRAP_P (orig);
-  MEM_READONLY_P (x) = MEM_READONLY_P (orig);
-
-  /* Sadly, we cannot use alias sets because the extra aliasing
- produced by the AND interferes.  Given that two-byte quantities
- are the only thing we would be able to differentiate anyway,
- there does not seem to be any point in convoluting the early
- out of the alias check.  */
-
-  return -1;
-}
-
 /* Given SEQ, which is an INSN list, look for any MEMs in either
a SET_DEST or a SET_SRC and copy the in-struct, unchanging, and
volatile flags from REF into each of the MEMs found.  If REF is not
@@ -1713,9 +1689,26 @@ alpha_set_memflags (rtx seq, rtx ref)
   && !MEM_READONLY_P (ref))
 return;
 
+  subrtx_var_iterator::array_type array;
   for (insn = as_a  (seq); insn; insn = NEXT_INSN (insn))
 if (INSN_P (insn))
-  for_each_rtx (&PATTERN (insn), alpha_set_memflags_1, (void *) ref);
+  FOR_EACH_SUBRTX_VAR (iter, array, PATTERN (insn), NONCONST)
+   {
+ rtx x = *iter;
+ if (MEM_P (x))
+   {
+ MEM_VOLATILE_P (x) = MEM_VOLATILE_P (ref);
+ MEM_NOTRAP_P (x) = MEM_NOTRAP_P (ref);
+ MEM_READONLY_P (x) = MEM_READONLY_P (ref);
+ /* Sadly, we cannot use alias sets because the extra
+aliasing produced by the AND interferes.  Given that
+two-byte quantities are the only thing we would be
+able to differentiate anyway, there does not seem to
+be any point in convoluting the early out of the
+alias check.  */
+ iter.skip_subrtxes ();
+   }
+   }
 else
   gcc_unreachable ();
 }


[alpha] RFA: Use new rtl iterators in alpha_find_lo_sum_using_gp

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for alpha-linux-gnu.  OK to install?

Thanks,
Richard


gcc/
* config/alpha/alpha-protos.h (alpha_find_lo_sum_using_gp): Return
a bool.
* config/alpha/alpha.c (find_lo_sum_using_gp): Delete.
(alpha_find_lo_sum_using_gp): Use FOR_EACH_SUBRTX.  Return a bool.

Index: gcc/config/alpha/alpha-protos.h
===
--- gcc/config/alpha/alpha-protos.h 2014-10-25 09:40:37.813515264 +0100
+++ gcc/config/alpha/alpha-protos.h 2014-10-25 09:51:29.781922193 +0100
@@ -75,7 +75,7 @@ extern rtx function_value (const_tree, c
 extern void alpha_start_function (FILE *, const char *, tree);
 extern void alpha_end_function (FILE *, const char *, tree);
 
-extern int alpha_find_lo_sum_using_gp (rtx);
+extern bool alpha_find_lo_sum_using_gp (rtx);
 
 #ifdef REAL_VALUE_TYPE
 extern int check_float_value (enum machine_mode, REAL_VALUE_TYPE *, int);
Index: gcc/config/alpha/alpha.c
===
--- gcc/config/alpha/alpha.c2014-10-25 09:51:29.394918743 +0100
+++ gcc/config/alpha/alpha.c2014-10-25 09:51:29.783922210 +0100
@@ -7554,16 +7554,17 @@ vms_output_aligned_decl_common(FILE *fil
 
 #endif
 
-static int
-find_lo_sum_using_gp (rtx *px, void *data ATTRIBUTE_UNUSED)
-{
-  return GET_CODE (*px) == LO_SUM && XEXP (*px, 0) == pic_offset_table_rtx;
-}
-
-int
+bool
 alpha_find_lo_sum_using_gp (rtx insn)
 {
-  return for_each_rtx (&PATTERN (insn), find_lo_sum_using_gp, NULL) > 0;
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
+{
+  const_rtx x = *iter;
+  if (GET_CODE (x) == LO_SUM && XEXP (x, 0) == pic_offset_table_rtx)
+   return true;
+}
+  return false;
 }
 
 static int


[alpha] RFA: Use new rtl iterators in some_small_symbolic_operand_int

2014-10-25 Thread Richard Sandiford
This is part of a series to remove uses of for_each_rtx from the ports.

Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
and g++.dg for alpha-linux-gnu.  OK to install?

Thanks,
Richard


gcc/
* config/alpha/alpha-protos.h (some_small_symbolic_operand_int):
Take an rtx and return a bool.
* config/alpha/alpha.c (some_small_symbolic_operand_int): Likewise.
Use FOR_EACH_SUBRTX_VAR.
* config/alpha/predicates.md (some_small_symbolic_operand): Update
accordingly.

Index: gcc/config/alpha/alpha-protos.h
===
--- gcc/config/alpha/alpha-protos.h 2014-10-25 09:51:29.781922193 +0100
+++ gcc/config/alpha/alpha-protos.h 2014-10-25 09:51:30.191925847 +0100
@@ -112,6 +112,6 @@ extern HOST_WIDE_INT alpha_vms_initial_e
 
 extern rtx unicosmk_add_call_info_word (rtx);
 
-extern int some_small_symbolic_operand_int (rtx *, void *);
+extern bool some_small_symbolic_operand_int (rtx);
 extern int tls_symbolic_operand_1 (rtx, int, int);
 extern rtx resolve_reload_operand (rtx);
Index: gcc/config/alpha/alpha.c
===
--- gcc/config/alpha/alpha.c2014-10-25 09:51:29.783922210 +0100
+++ gcc/config/alpha/alpha.c2014-10-25 09:51:30.192925856 +0100
@@ -1225,16 +1225,20 @@ alpha_function_ok_for_sibcall (tree decl
   return decl_has_samegp (decl);
 }
 
-int
-some_small_symbolic_operand_int (rtx *px, void *data ATTRIBUTE_UNUSED)
+bool
+some_small_symbolic_operand_int (rtx x)
 {
-  rtx x = *px;
-
-  /* Don't re-split.  */
-  if (GET_CODE (x) == LO_SUM)
-return -1;
-
-  return small_symbolic_operand (x, Pmode) != 0;
+  subrtx_var_iterator::array_type array;
+  FOR_EACH_SUBRTX_VAR (iter, array, x, ALL)
+{
+  rtx x = *iter;
+  /* Don't re-split.  */
+  if (GET_CODE (x) == LO_SUM)
+   iter.skip_subrtxes ();
+  else if (small_symbolic_operand (x, Pmode))
+   return true;
+}
+  return false;
 }
 
 rtx
Index: gcc/config/alpha/predicates.md
===
--- gcc/config/alpha/predicates.md  2014-10-25 09:40:37.750514758 +0100
+++ gcc/config/alpha/predicates.md  2014-10-25 09:51:30.193925865 +0100
@@ -638,7 +638,7 @@ (define_predicate "some_small_symbolic_o
   /* Avoid search unless necessary.  */
   if (!TARGET_EXPLICIT_RELOCS || !reload_completed)
 return false;
-  return for_each_rtx (&op, some_small_symbolic_operand_int, NULL);
+  return some_small_symbolic_operand_int (op);
 })
 
 ;; Accept a register, or a memory if BWX is enabled.


Re: [PATCH] PR36312

2014-10-25 Thread Anthony Brandon
Hi,

Sorry for the delay. Here are the updated diff and changelog.

gcc/testsuite/ChangeLog:

2014-10-25  Anthony Brandon  

PR driver/36312
* gcc.misc-tests/output.exp: New test case for identical input and
output files.

include/ChangeLog:

2014-10-25  Anthony Brandon  

PR driver/36312
* filenames.h: Add prototype for canonical_filename_eq.

gcc/ChangeLog:

2014-10-25  Anthony Brandon  

PR driver/36312
* diagnostic-core.h: Add prototype for fatal_error.
* diagnostic.c (fatal_error): New function fatal_error.
* gcc.c (store_arg): Remove have_o_argbuf_index.
(process_command): Check if input and output files are the same.
* toplev.c (init_asm_output): Check if input and output files are the same.

libiberty/ChangeLog:

2014-10-25  Anthony Brandon  

PR driver/36312
* filename_cmp.c (canonical_filename_eq): New function to check if
file names are the same.
* functions.texi: Updated with documentation for new function.

On Sun, Oct 19, 2014 at 11:17 AM, Manuel López-Ibáñez
 wrote:
> On 18 October 2014 14:43, Anthony Brandon  wrote:
>> Never mind about functions.texi. I figured out how to do it.
>> Here is the new diff and changelog.
>>
>> libiberty/ChangeLog:
>>
>> 2014-10-18  Anthony Brandon  
>>
>> * filename_cmp.c (filename_eq): No change.
>
> Unfortunately mklog is not 100% perfect (actually, it is 'diff -p'
> which is far from perfect). You need to revise that the ChageLog makes
> sense (or make mklog smarter). Thus, drop (filename_eq)...
>
> Also, the changelogs should say PR driver/36312
> (https://gcc.gnu.org/codingconventions.html#ChangeLogs).
>
> I think you need to explain the difference between using fatal_error()
> and fatal_error(UNKNOWN_LOCATION). Yes, I should know because I wrote
> this part of the patch. But to be honest, I don't remember why I did
> this change.
>
> +This function first normalizes the file names so that different file names
> +pointing to the same underlying file are treated as being identical.
>
> I would suggest: "This function compares the canonical versions of the
> filenames as returned by @code{lrealpath()}, so that ..."
>
> I cannot approve the patch, but it looks fine to me. If you don't get
> a reply in a few days, you should ping the relevant maintainers:
> https://gcc.gnu.org/wiki/Community#ping
>
> Great first contribution! What are your plans next?
>
> Cheers,
>
> Manuel.



-- 
Anthony
diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
index a8245de..2fba279 100644
--- a/gcc/diagnostic-core.h
+++ b/gcc/diagnostic-core.h
@@ -68,6 +68,8 @@ extern void error_n (location_t, int, const char *, const 
char *, ...)
 extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
 extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
  ATTRIBUTE_NORETURN;
+extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3)
+ ATTRIBUTE_NORETURN;
 /* Pass one of the OPT_W* from options.h as the second parameter.  */
 extern bool pedwarn (location_t, int, const char *, ...)
  ATTRIBUTE_GCC_DIAG(3,4);
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 642cbe3..f7f8aaa 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -1163,6 +1163,23 @@ fatal_error (const char *gmsgid, ...)
   gcc_unreachable ();
 }
 
+/* An error which is severe enough that we make no attempt to
+   continue.  Do not use this for internal consistency checks; that's
+   internal_error.  Use of this function should be rare.  */
+void
+fatal_error (location_t loc, const char *gmsgid, ...)
+{
+  diagnostic_info diagnostic;
+  va_list ap;
+
+  va_start (ap, gmsgid);
+  diagnostic_set_info (&diagnostic, gmsgid, &ap, loc, DK_FATAL);
+  report_diagnostic (&diagnostic);
+  va_end (ap);
+
+  gcc_unreachable ();
+}
+
 /* An internal consistency check has failed.  We make no attempt to
continue.  Note that unless there is debugging value to be had from
a more specific message, or some other good reason, you should use
diff --git a/gcc/gcc.c b/gcc/gcc.c
index e013d52..6f144de 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1702,17 +1702,15 @@ typedef const char *const_char_p; /* For DEF_VEC_P.  */
 
 static vec argbuf;
 
-/* Position in the argbuf vector containing the name of the output file
-   (the value associated with the "-o" flag).  */
-
-static int have_o_argbuf_index = 0;
-
 /* Were the options -c, -S or -E passed.  */
 static int have_c = 0;
 
 /* Was the option -o passed.  */
 static int have_o = 0;
 
+/* Pointer to output file name passed in with -o. */
+static const char *output_file = 0;
+
 /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
temp file.  If the HOST_BIT_BUCKET is used for %j, no entry is made for
it here.  */
@@ -1762,8 +1760,6 @@ store_arg (const char *arg, int delete_always, int 
delete_failure)
 {
   argbuf.safe_push (arg);
 
-  if (strcmp (arg, "-o") == 0)
-have_o_argbuf_index = argbuf.length ();
   if (delete_alway

Re: [m68k] RFA: Use new rtl iterators in m68k_final_prescan_insn

2014-10-25 Thread Andreas Schwab
Richard Sandiford  writes:

> gcc/
>   * config/m68k/m68k.c: Include rtl-iter.h.
>   (m68k_final_prescan_insn_1): Delete.
>   (m68k_final_prescan_insn): Use FOR_EACH_SUBRTX_VAR.

Ok.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: [m68k] RFA: Use new rtl iterators in m68k_tls_reference_p

2014-10-25 Thread Andreas Schwab
Richard Sandiford  writes:

> gcc/
>   * config/m68k/m68k.c (m68k_tls_reference_p_1): Delete.
>   (m68k_tls_reference_p): Use FOR_EACH_SUBRTX_VAR.

Ok.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: genmatch infinite loop during bootstrap on AIX

2014-10-25 Thread David Edelsohn
This occurs in genmatch builti in stage2.  Revision 216674.

Because of the previous build breakage during the merge, it is
difficult to know exactly what was working.  GCC seemed to be able to
build with the earlier genmatch patch.

Running genmatch --gimple match.pd produces no output and spins in libstdc++.

Thanks, David

On Sat, Oct 25, 2014 at 4:06 AM, Richard Biener  wrote:
> On October 25, 2014 1:33:39 AM CEST, David Edelsohn  wrote:
>>genmatch is hanging when bootstrapping on AIX (gcc111).  When I attach
>>to the process:
>>
>>#0  0x1007efac in std::basic_string,
>>std::allocator >::basic_string ()
>>#1  0x1000e6b0 in _ZN6parser13parse_captureEP7operand (this=0x300594b8,
>>op=0x0)
>>at /home/dje/src/src/gcc/genmatch.c:2607
>
> Does it really hang in libstdc++ or does it loop somewhere in genmatch? Is 
> this stage1 or later?
>
> Does this happen only after the 2nd part of the merge went in? That is, what 
> revision?
>
> Thanks,
> Richard.
>
>>#2  0x1000e9f0 in _ZN6parser10parse_exprEv (this=0x2ff20208)
>>at /home/dje/src/src/gcc/genmatch.c:2669
>>#3  0x1000ee38 in _ZN6parser8parse_opEv (this=0x2ff20208)
>>at /home/dje/src/src/gcc/genmatch.c:2728
>>#4  0x1000efc4 in
>>_ZN6parser14parse_simplifyEjR3vecIP8simplify7va_heap6vl_ptrEP12predicate_idP4expr
>>(this=0x2ff20208, match_location=4614, simplifiers=...,
>>matcher=0x0, result=0x0) at /home/dje/src/src/gcc/genmatch.c:2792
>>#5  0x100102fc in _ZN6parser13parse_patternEv (this=0x2ff20208)
>>at /home/dje/src/src/gcc/genmatch.c:3052
>>#6  0x10010c0c in _ZN6parser9parse_forEj (this=0x2ff20208)
>>at /home/dje/src/src/gcc/genmatch.c:2991
>>#7  0x10010350 in _ZN6parser13parse_patternEv (this=0x2ff20208)
>>at /home/dje/src/src/gcc/genmatch.c:3090
>>#8  0x1001122c in _ZN6parserC2EP10cpp_reader (this=0x2ff20208,
>>r_=0x3003bbec)
>>at /home/dje/src/src/gcc/genmatch.c:3122
>>#9  0x10004acc in main (argc=,
>>argv=) at  _start_ :3204
>
>


Re: genmatch infinite loop during bootstrap on AIX

2014-10-25 Thread David Edelsohn
It may be fallout from Maxim's scheduler patch.  I'm testing that.
Backing up before Maxim's patch and your genmatch patch does not enter
an endless loop.

- David

On Sat, Oct 25, 2014 at 4:06 AM, Richard Biener  wrote:
> On October 25, 2014 1:33:39 AM CEST, David Edelsohn  wrote:
>>genmatch is hanging when bootstrapping on AIX (gcc111).  When I attach
>>to the process:
>>
>>#0  0x1007efac in std::basic_string,
>>std::allocator >::basic_string ()
>>#1  0x1000e6b0 in _ZN6parser13parse_captureEP7operand (this=0x300594b8,
>>op=0x0)
>>at /home/dje/src/src/gcc/genmatch.c:2607
>
> Does it really hang in libstdc++ or does it loop somewhere in genmatch? Is 
> this stage1 or later?
>
> Does this happen only after the 2nd part of the merge went in? That is, what 
> revision?
>
> Thanks,
> Richard.
>
>>#2  0x1000e9f0 in _ZN6parser10parse_exprEv (this=0x2ff20208)
>>at /home/dje/src/src/gcc/genmatch.c:2669
>>#3  0x1000ee38 in _ZN6parser8parse_opEv (this=0x2ff20208)
>>at /home/dje/src/src/gcc/genmatch.c:2728
>>#4  0x1000efc4 in
>>_ZN6parser14parse_simplifyEjR3vecIP8simplify7va_heap6vl_ptrEP12predicate_idP4expr
>>(this=0x2ff20208, match_location=4614, simplifiers=...,
>>matcher=0x0, result=0x0) at /home/dje/src/src/gcc/genmatch.c:2792
>>#5  0x100102fc in _ZN6parser13parse_patternEv (this=0x2ff20208)
>>at /home/dje/src/src/gcc/genmatch.c:3052
>>#6  0x10010c0c in _ZN6parser9parse_forEj (this=0x2ff20208)
>>at /home/dje/src/src/gcc/genmatch.c:2991
>>#7  0x10010350 in _ZN6parser13parse_patternEv (this=0x2ff20208)
>>at /home/dje/src/src/gcc/genmatch.c:3090
>>#8  0x1001122c in _ZN6parserC2EP10cpp_reader (this=0x2ff20208,
>>r_=0x3003bbec)
>>at /home/dje/src/src/gcc/genmatch.c:3122
>>#9  0x10004acc in main (argc=,
>>argv=) at  _start_ :3204
>
>


[C PATCH] Add 'aka's on type printing in diagnostics

2014-10-25 Thread Marek Polacek
This patch teaches the compiler to also print the typedef-stripped
version of a type when appropriate.  C++ FE does this for a few
years now.  With this patch we're able to say
note: expected 'B * {aka struct A *}' but argument is of type 'struct B *'
Compare that with
note: expected 'struct B *' but argument is of type 'struct B *'
that we output until recently.

We must be careful not to print the typedef-stripped part if it's
identical to the non-stripped part.  I worked it out by using
a temporary c_pretty_printer and an obstack (C++'s type_to_string
uses an obstack too).

Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk?

2014-10-25  Marek Polacek  

* c-objc-common.c (c_tree_printer) : For a typedef name,
print the stripped version as well, if they're not the same.

* gcc.dg/diag-aka-1.c: New test.
* gcc.dg/pr13804-1.c: Adjust dg-error.
* gcc.dg/redecl-14.c: Likewise.
* gcc.dg/pr56980.c: Adjust dg-message.

diff --git gcc/c/c-objc-common.c gcc/c/c-objc-common.c
index 73bb297..f923458 100644
--- gcc/c/c-objc-common.c
+++ gcc/c/c-objc-common.c
@@ -135,23 +135,48 @@ c_tree_printer (pretty_printer *pp, text_info *text, 
const char *spec,
   break;
 
 case 'T':
-  gcc_assert (TYPE_P (t));
-  name = TYPE_NAME (t);
-
-  if (name && TREE_CODE (name) == TYPE_DECL)
-   {
- if (DECL_NAME (name))
-   pp_identifier (cpp, lang_hooks.decl_printable_name (name, 2));
- else
-   cpp->type_id (t);
- return true;
-   }
-  else
-   {
+  {
+   gcc_assert (TYPE_P (t));
+   struct obstack *ob = pp_buffer (cpp)->obstack;
+   char *p = (char *) obstack_base (ob);
+   /* Remember the end of the initial dump.  */
+   int len = obstack_object_size (ob);
+
+   name = TYPE_NAME (t);
+   if (name && TREE_CODE (name) == TYPE_DECL && DECL_NAME (name))
+ pp_identifier (cpp, lang_hooks.decl_printable_name (name, 2));
+   else
  cpp->type_id (t);
- return true;
-   }
-  break;
+
+   /* If we're printing a type that involves typedefs, also print the
+  stripped version.  But sometimes the stripped version looks
+  exactly the same, so we don't want it after all.  To avoid
+  printing it in that case, we play ugly obstack games.  */
+   if (TYPE_CANONICAL (t) && t != TYPE_CANONICAL (t))
+ {
+   c_pretty_printer cpp2;
+   /* Print the stripped version into a temporary printer.  */
+   cpp2.type_id (TYPE_CANONICAL (t));
+   struct obstack *ob2 = cpp2.buffer->obstack;
+   /* Get the stripped version from the temporary printer.  */
+   const char *aka = (char *) obstack_base (ob2);
+   int aka_len = obstack_object_size (ob2);
+   int type1_len = obstack_object_size (ob) - len;
+
+   /* If they are identical, bail out.  */
+   if (aka_len == type1_len && memcmp (p + len, aka, aka_len) == 0)
+ return true;
+
+   /* They're not, print the stripped version now.  */
+   pp_c_whitespace (cpp);
+   pp_left_brace (cpp);
+   pp_c_ws_string (cpp, "aka");
+   pp_c_whitespace (cpp);
+   cpp->type_id (TYPE_CANONICAL (t));
+   pp_right_brace (cpp);
+ }
+   return true;
+  }
 
 case 'E':
   if (TREE_CODE (t) == IDENTIFIER_NODE)
diff --git gcc/testsuite/gcc.dg/diag-aka-1.c gcc/testsuite/gcc.dg/diag-aka-1.c
index e69de29..87bc757 100644
--- gcc/testsuite/gcc.dg/diag-aka-1.c
+++ gcc/testsuite/gcc.dg/diag-aka-1.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-Wc++-compat" } */
+
+typedef struct A { int i; } B;
+typedef struct T { int i; } T;
+typedef const float TFA;
+typedef TFA TFB;
+typedef TFB TFC;
+typedef int IA[];
+typedef IA *IAP;
+extern IAP arr[];
+
+void fn1 (B *); /* { dg-message "expected .B \\* {aka struct A \\*}. but 
argument is of type .struct B \\*." } */
+void fn2 (TFC *);
+
+void 
+bar (B *b, int *i)
+{
+  fn1 ((struct B *) b); /* { dg-warning "passing argument" } */
+  fn2 (i); /* { dg-warning "passing argument" } */
+  sizeof (arr); /* { dg-error "invalid application of .sizeof. to incomplete 
type .int \\(\\*\\\[\\\]\\)\\\[\\\]." } */
+}
+
+int
+foo (void *a)
+{
+  T *t = a; /* { dg-warning "request for implicit conversion from .void \\*. 
to .T \\* {aka struct T \\*}. not" } */
+  return t->i;
+}
diff --git gcc/testsuite/gcc.dg/pr13804-1.c gcc/testsuite/gcc.dg/pr13804-1.c
index 4363678..65b238a 100644
--- gcc/testsuite/gcc.dg/pr13804-1.c
+++ gcc/testsuite/gcc.dg/pr13804-1.c
@@ -20,9 +20,9 @@ void
 f (void)
 {
   x0.c; /* { dg-error "'struct s0' has no member named 'c'" } */
-  x1.c; /* { dg-error "'S0' has no member named 'c'" } */
+  x1.c; /* { dg-error "'S0 {aka struct s0}' has no member named 'c'" } */
   x2.c; /* { dg-error "'union u0' has no member named 'c'" } */
-  x3.c; /* { dg-error "'U0' has no mem

Re: update address taken: don't drop clobbers

2014-10-25 Thread Marc Glisse

On Fri, 24 Oct 2014, Jeff Law wrote:

I'm starting to agree -- a later message indicated you wanted to drop the 
unlink_stmt_vdef call and you wanted to avoid gsi_replace, that seems fine. 
I'll approve once those things are taken care of.


The following passed bootstrap+testsuite. I wasn't sure what exactly a 
clobber is guaranteed not to have (no histograms for instance? At least I 
assumed it doesn't throw) so I may have kept some unnecessary calls when I 
inlined gsi_replace. I'd be happy to remove any you feel is useless.


2014-10-26  Marc Glisse  

PR tree-optimization/60770
gcc/
* tree-into-ssa.c: Include value-prof.h.
(maybe_register_def): Replace clobbers with default definitions.
* tree-ssa-live.c: Include tree-ssa.h.
(set_var_live_on_entry): Do not mark undefined variables as live.
(verify_live_on_entry): Do not check undefined variables.
* tree-ssa.h (ssa_undefined_value_p): New parameter for the case
of partially undefined variables.
* tree-ssa.c (ssa_undefined_value_p): Likewise.
(execute_update_addresses_taken): Do not drop clobbers.
gcc/testsuite/
* gcc.dg/tree-ssa/pr60770-1.c: New file.

--
Marc GlisseIndex: gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c
===
--- gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c   (revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c   (working copy)
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -Wall" } */
+
+int f(int n){
+  int*p;
+  {
+int yyy=n;
+p=&yyy;
+  }
+  return *p; /* { dg-warning "yyy" } */
+}
Index: gcc/tree-into-ssa.c
===
--- gcc/tree-into-ssa.c (revision 216689)
+++ gcc/tree-into-ssa.c (working copy)
@@ -52,20 +52,21 @@ along with GCC; see the file COPYING3.
 #include "expr.h"
 #include "tree-dfa.h"
 #include "tree-ssa.h"
 #include "tree-inline.h"
 #include "tree-pass.h"
 #include "cfgloop.h"
 #include "domwalk.h"
 #include "params.h"
 #include "diagnostic-core.h"
 #include "tree-into-ssa.h"
+#include "value-prof.h"
 
 #define PERCENT(x,y) ((float)(x) * 100.0 / (float)(y))
 
 /* This file builds the SSA form for a function as described in:
R. Cytron, J. Ferrante, B. Rosen, M. Wegman, and K. Zadeck. Efficiently
Computing Static Single Assignment Form and the Control Dependence
Graph. ACM Transactions on Programming Languages and Systems,
13(4):451-490, October 1991.  */
 
 /* Structure to map a variable VAR to the set of blocks that contain
@@ -1837,26 +1838,42 @@ maybe_register_def (def_operand_p def_p,
 {
   tree def = DEF_FROM_PTR (def_p);
   tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def);
 
   /* If DEF is a naked symbol that needs renaming, create a new
  name for it.  */
   if (marked_for_renaming (sym))
 {
   if (DECL_P (def))
{
- tree tracked_var;
+ if (gimple_clobber_p (stmt) && is_gimple_reg (sym))
+   {
+ /* Replace clobber stmts with a default def. This new use of a
+default definition may make it look like SSA_NAMEs have
+conflicting lifetimes, so we need special code to let them
+coalesce properly.  */
+ /* Hand-inlined version of the following, for safety
+gsi_replace (&gsi, gimple_build_nop (), true);  */
+ gimple nop = gimple_build_nop ();
+ gimple_set_bb (nop, gsi_bb (gsi));
+ gimple_set_bb (stmt, NULL);
+ gimple_remove_stmt_histograms (cfun, stmt);
+ delink_stmt_imm_use (stmt);
+ gsi_set_stmt (&gsi, nop);
 
- def = make_ssa_name (def, stmt);
+ def = get_or_create_ssa_default_def (cfun, sym);
+   }
+ else
+   def = make_ssa_name (def, stmt);
  SET_DEF (def_p, def);
 
- tracked_var = target_for_debug_bind (sym);
+ tree tracked_var = target_for_debug_bind (sym);
  if (tracked_var)
{
  gimple note = gimple_build_debug_bind (tracked_var, def, stmt);
  /* If stmt ends the bb, insert the debug stmt on the single
 non-EH edge from the stmt.  */
  if (gsi_one_before_end_p (gsi) && stmt_ends_bb_p (stmt))
{
  basic_block bb = gsi_bb (gsi);
  edge_iterator ei;
  edge e, ef = NULL;
Index: gcc/tree-ssa-live.c
===
--- gcc/tree-ssa-live.c (revision 216689)
+++ gcc/tree-ssa-live.c (working copy)
@@ -40,20 +40,21 @@ along with GCC; see the file COPYING3.
 #include "stringpool.h"
 #include "tree-ssanames.h"
 #include "expr.h"
 #include "tree-dfa.h"
 #include "timevar.h"
 #include "dumpfile.h"
 #include "tree-ssa-live.h"
 #include "diagnostic-core.h"
 #include "debug.h"
 #include "flags.h"
+#include "tree-ssa.h"
 
 #ifdef ENABLE

support operator list

2014-10-25 Thread Prathamesh Kulkarni
Hi,
This patch adds support for operator-lists, and uses
them in match-bitwise.pd and match-comparison.pd

* genmatch.c
(parser::parse_operator_list): New member function in parser.
(add_substitute): New function.
(flatten_substitutes): Likewise.
(parser::parse_for): Call add_substitute.
(parser::parse_pattern): Call parser::parse_operator_list.

* match-bitwise.pd
(bitwise_ors): New operator-list.
(bitwise_ops): Likewise.
Use bitwise_ors and bitwise_ops in patterns.

* match-comparison.pd
 (eq_ops): New operator-list.
 (cmp_ops): Likewise.
 Use cmp_ops and eq_ops in patterns.

Thanks,
Prathamesh
Index: gcc/genmatch.c
===
--- gcc/genmatch.c	(revision 216673)
+++ gcc/genmatch.c	(working copy)
@@ -2419,6 +2419,7 @@
   void parse_simplify (source_location, vec&, predicate_id *,
 		   expr *);
   void parse_for (source_location);
+  void parse_operator_list ();
   void parse_if (source_location);
   void parse_predicates (source_location);
 
@@ -2582,8 +2583,10 @@
 	   || strcmp  (id, "convert2") == 0)
 fatal_at (id_tok, "expected '?' after conditional operator");
   id_base *op = get_operator (id);
+
   if (!op)
 fatal_at (id_tok, "unknown operator %s", id);
+  
   return op;
 }
 
@@ -2900,6 +2903,20 @@
 
 /* Parsing of the outer control structures.  */
 
+bool
+add_substitute (user_id *op, id_base *idb, int& arity) 
+{
+  if (arity == -1)
+arity = idb->nargs;
+  else if (idb->nargs == -1)
+;
+  else if (idb->nargs != arity)
+return false;
+
+  op->substitutes.safe_push (idb);
+  return true;
+}
+  
 /* Parse a for expression
  for = '(' 'for' ...  ')'
  subst =  '(' ... ')'  */
@@ -2938,15 +2955,16 @@
 	  if (*idb == CONVERT0 || *idb == CONVERT1 || *idb == CONVERT2)
 	fatal_at (token, "conditional operators cannot be used inside for");
 
-	  if (arity == -1)
-	arity = idb->nargs;
-	  else if (idb->nargs == -1)
-	;
-	  else if (idb->nargs != arity)
-	fatal_at (token, "operator '%s' with arity %d does not match "
-		  "others with arity %d", oper, idb->nargs, arity);
+	  vec substitutes = vNULL;
+	  if (idb->kind == id_base::USER)
+	substitutes = (as_a (idb))->substitutes;
+	  else
+	substitutes.safe_push (idb);
 
-	  op->substitutes.safe_push (idb);
+	  for (unsigned si = 0; si < substitutes.length (); ++si)
+	if (!add_substitute (op, substitutes[si], arity))
+	  fatal_at (token, "operator '%s' with arity %d does not match "
+			   "others with arity %d", oper, idb->nargs, arity);
 	}
   op->nargs = arity;
   token = expect (CPP_CLOSE_PAREN);
@@ -2997,6 +3015,55 @@
 operators->remove_elt (user_ids[i]);
 }
 
+void
+flatten_substitutes (vec& ids, vec& substitutes)
+{
+  user_id *op;
+ 
+  for (unsigned i = 0; i < ids.length (); ++i)
+if ((op = dyn_cast (ids[i])) != 0)
+  flatten_substitutes (op->substitutes, substitutes);
+else
+  substitutes.safe_push (ids[i]);
+}
+
+void
+parser::parse_operator_list ()
+{
+  const char *id = get_ident ();
+  user_id *op = new user_id (id);
+  vec user_id_tokens = vNULL;
+
+  id_base **slot = operators->find_slot_with_hash (op, op->hashval, INSERT);
+  if (*slot)
+fatal ("operator %s already defined", id);
+  *slot = op;
+
+  const cpp_token *token;
+  vec ids = vNULL;
+
+  while ((token = peek_ident ()) != 0)
+{
+  const char *oper = get_ident ();
+  id_base *p = get_operator (oper);
+  if (p == 0)
+	fatal_at (token, "%s is not defined", oper);
+  ids.safe_push (p);
+  user_id_tokens.safe_push (token);
+}
+
+  if (ids.length () == 0)
+fatal_at (token, "operator list cannot be empty");
+
+  flatten_substitutes (ids, op->substitutes);
+  int arity = op->substitutes[0]->nargs;
+  for (unsigned i = 1; i < op->substitutes.length (); ++i)
+if (op->substitutes[i]->nargs != -1 && arity != op->substitutes[i]->nargs)
+  fatal_at (user_id_tokens[i], "operator '%s' with arity %d does not match "
+		   "others with arity %d", op->substitutes[i]->id, op->substitutes[i]->nargs, arity);
+}
+
+
 /* Parse an outer if expression.
  if = '(' 'if' '('  ')'  ')'  */
 
@@ -3097,6 +3164,8 @@
 	fatal_at (token, "define_predicates inside if or for is not supported");
   parse_predicates (token->src_loc);
 }
+  else if (strcmp (id, "define_operator_list") == 0)
+parse_operator_list ();
   else
 fatal_at (token, "expected %s'simplify', 'match', 'for' or 'if'",
 	  active_ifs.length () == 0 && active_fors.length () == 0
Index: gcc/match-bitwise.pd
===
--- gcc/match-bitwise.pd	(revision 216673)
+++ gcc/match-bitwise.pd	(working copy)
@@ -17,6 +17,9 @@
 along with GCC; see the file COPYING3.  If not see
 .  */
 
+(define_operator_list bitwise_ors bit_ior bit_xor)
+(define_operator_list bitwise_ops bit_and bitwise_ors) 
+
 /* Try to fol

Re: genmatch infinite loop during bootstrap on AIX

2014-10-25 Thread David Edelsohn
Bootstrap succeeds with Maxim's patch (r216624).

The other, significant changes I see on trunk between r216624 and r216674 are:

match-and-simplify through r216632
ipc-icf in r216662
libstdc++ in r216667

No other patches to trunk *seem* like they should affect PPC bootstrap.

- David


On Sat, Oct 25, 2014 at 10:04 AM, David Edelsohn  wrote:
> It may be fallout from Maxim's scheduler patch.  I'm testing that.
> Backing up before Maxim's patch and your genmatch patch does not enter
> an endless loop.
>
> - David
>
> On Sat, Oct 25, 2014 at 4:06 AM, Richard Biener  wrote:
>> On October 25, 2014 1:33:39 AM CEST, David Edelsohn  
>> wrote:
>>>genmatch is hanging when bootstrapping on AIX (gcc111).  When I attach
>>>to the process:
>>>
>>>#0  0x1007efac in std::basic_string,
>>>std::allocator >::basic_string ()
>>>#1  0x1000e6b0 in _ZN6parser13parse_captureEP7operand (this=0x300594b8,
>>>op=0x0)
>>>at /home/dje/src/src/gcc/genmatch.c:2607
>>
>> Does it really hang in libstdc++ or does it loop somewhere in genmatch? Is 
>> this stage1 or later?
>>
>> Does this happen only after the 2nd part of the merge went in? That is, what 
>> revision?
>>
>> Thanks,
>> Richard.
>>
>>>#2  0x1000e9f0 in _ZN6parser10parse_exprEv (this=0x2ff20208)
>>>at /home/dje/src/src/gcc/genmatch.c:2669
>>>#3  0x1000ee38 in _ZN6parser8parse_opEv (this=0x2ff20208)
>>>at /home/dje/src/src/gcc/genmatch.c:2728
>>>#4  0x1000efc4 in
>>>_ZN6parser14parse_simplifyEjR3vecIP8simplify7va_heap6vl_ptrEP12predicate_idP4expr
>>>(this=0x2ff20208, match_location=4614, simplifiers=...,
>>>matcher=0x0, result=0x0) at /home/dje/src/src/gcc/genmatch.c:2792
>>>#5  0x100102fc in _ZN6parser13parse_patternEv (this=0x2ff20208)
>>>at /home/dje/src/src/gcc/genmatch.c:3052
>>>#6  0x10010c0c in _ZN6parser9parse_forEj (this=0x2ff20208)
>>>at /home/dje/src/src/gcc/genmatch.c:2991
>>>#7  0x10010350 in _ZN6parser13parse_patternEv (this=0x2ff20208)
>>>at /home/dje/src/src/gcc/genmatch.c:3090
>>>#8  0x1001122c in _ZN6parserC2EP10cpp_reader (this=0x2ff20208,
>>>r_=0x3003bbec)
>>>at /home/dje/src/src/gcc/genmatch.c:3122
>>>#9  0x10004acc in main (argc=,
>>>argv=) at  _start_ :3204
>>
>>


Re: [PATCH, fixincludes]: Add pthread.h to glibc_c99_inline_4 fix

2014-10-25 Thread Bruce Korb

On 10/21/14 02:30, Uros Bizjak wrote:

2014-10-21  Uros Bizjak  

 * inclhack.def (glibc_c99_inline_4): Add pthread.h to files.
 * fixincl.x: Regenerate.

Bootstrapped and regression tested on CentOS 5.11 x86_64-linux-gnu {,-m32}.

OK for mainline?





Re: [PATCH, fixincludes]: Add pthread.h to glibc_c99_inline_4 fix

2014-10-25 Thread Bruce Korb

On 10/25/14 10:40, Bruce Korb wrote:

On 10/21/14 02:30, Uros Bizjak wrote:

2014-10-21  Uros Bizjak  

 * inclhack.def (glibc_c99_inline_4): Add pthread.h to files.
 * fixincl.x: Regenerate.

Bootstrapped and regression tested on CentOS 5.11 x86_64-linux-gnu {,-m32}.

OK for mainline?


Interesting.  I clicked "send" and my typing disappeared.

"Looks fine to me."


Re: [Patch, Fortran] Add CO_REDUCE

2014-10-25 Thread Andreas Schwab
Tobias Burnus  writes:

> diff --git a/gcc/testsuite/gfortran.dg/coarray_collectives_14.f90 
> b/gcc/testsuite/gfortran.dg/coarray_collectives_14.f90
> new file mode 100644
> index 000..f0ab932
> --- /dev/null
> +++ b/gcc/testsuite/gfortran.dg/coarray_collectives_14.f90

FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 55)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 57)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 59)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 61)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 63)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 65)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 67)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 69)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 71)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 73)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 75)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 77)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 79)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 81)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 83)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 87)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O   (test for errors, line 89)
FAIL: gfortran.dg/coarray_collectives_14.f90   -O  (test for excess errors)

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: [SH] RFA: Use new rtl iterators in shmedia_cleanup_truncate

2014-10-25 Thread Oleg Endo


On Oct 25, 2014, at 12:02 PM, Richard Sandiford  
wrote:

> This is part of a series to remove uses of for_each_rtx from the ports.
> There are some some small rearrangements to cope with the 80-character limit.
> 
> Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
> and g++.dg for sh-elf.  OK to install?

OK with me.

Cheers,
Oleg




> gcc/
>* config/sh/sh-protos.h (shmedia_cleanup_truncate): Take an
>rtx as argument and return the number of changes.
>* config/sh/sh.c: Include rtl-iter.h.
>(shmedia_cleanup_truncate): Take an rtx as argument and iterate
>over all subrtxes.  Return the number of changes made.
>* config/sh/sh.md: Update caller accordingly.
> 
> Index: gcc/config/sh/sh-protos.h
> ===
> --- gcc/config/sh/sh-protos.h2014-10-25 09:40:38.030517007 +0100
> +++ gcc/config/sh/sh-protos.h2014-10-25 09:51:27.047897823 +0100
> @@ -215,7 +215,7 @@ extern void sh_init_cumulative_args (CUM
> extern rtx sh_dwarf_register_span (rtx);
> 
> extern rtx replace_n_hard_rtx (rtx, rtx *, int , int);
> -extern int shmedia_cleanup_truncate (rtx *, void *);
> +extern int shmedia_cleanup_truncate (rtx);
> 
> extern bool sh_contains_memref_p (rtx);
> extern bool sh_loads_bankedreg_p (rtx);
> Index: gcc/config/sh/sh.c
> ===
> --- gcc/config/sh/sh.c2014-10-25 09:40:38.030517007 +0100
> +++ gcc/config/sh/sh.c2014-10-25 09:51:27.049897841 +0100
> @@ -78,6 +78,7 @@ the Free Software Foundation; either ver
> #include "pass_manager.h"
> #include "context.h"
> #include "builtins.h"
> +#include "rtl-iter.h"
> 
> int code_for_indirect_jump_scratch = CODE_FOR_indirect_jump_scratch;
> 
> @@ -12940,25 +12941,30 @@ sh_gen_truncate (enum machine_mode mode,
>   return gen_rtx_fmt_e (code, mode, x);
> }
> 
> -/* Called via for_each_rtx after reload, to clean up truncates of
> -   registers that span multiple actual hard registers.  */
> +/* Look through X cleaning up truncates of registers that span multiple
> +   actual hard registers.  Return the number of changes made.  */
> int
> -shmedia_cleanup_truncate (rtx *p, void *n_changes)
> +shmedia_cleanup_truncate (rtx x)
> {
> -  rtx x = *p, reg;
> -
> -  if (GET_CODE (x) != TRUNCATE)
> -return 0;
> -  reg = XEXP (x, 0);
> -  if (GET_MODE_SIZE (GET_MODE (reg)) > 8 && REG_P (reg))
> +  int n_changes = 0;
> +  subrtx_var_iterator::array_type array;
> +  FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST)
> {
> -  enum machine_mode reg_mode = GET_MODE (reg);
> -  XEXP (x, 0) = simplify_subreg (DImode, reg, reg_mode,
> - subreg_lowpart_offset (DImode, reg_mode));
> -  *(int*) n_changes += 1;
> -  return -1;
> +  rtx x = *iter;
> +  if (GET_CODE (x) == TRUNCATE)
> +{
> +  rtx reg = XEXP (x, 0);
> +  enum machine_mode reg_mode = GET_MODE (reg);
> +  if (REG_P (reg) && GET_MODE_SIZE (reg_mode) > 8)
> +{
> +  int offset = subreg_lowpart_offset (DImode, reg_mode);
> +  XEXP (x, 0) = simplify_subreg (DImode, reg, reg_mode, offset);
> +  n_changes += 1;
> +  iter.skip_subrtxes ();
> +}
> +}
> }
> -  return 0;
> +  return n_changes;
> }
> 
> /* Load and store depend on the highpart of the address.  However,
> Index: gcc/config/sh/sh.md
> ===
> --- gcc/config/sh/sh.md2014-10-25 09:40:38.030517007 +0100
> +++ gcc/config/sh/sh.md2014-10-25 09:51:27.051897858 +0100
> @@ -15803,10 +15803,7 @@ (define_split
>   "TARGET_SHMEDIA && reload_completed"
>   [(set (match_dup 0) (match_dup 1))]
> {
> -  int n_changes = 0;
> -
> -  for_each_rtx (&operands[1], shmedia_cleanup_truncate, &n_changes);
> -  if (!n_changes)
> +  if (!shmedia_cleanup_truncate (operands[1]))
> FAIL;
> })
> 


Re: [SH] RFA: Use new rtl iterators in sh_contains_memref_p

2014-10-25 Thread Oleg Endo


On Oct 25, 2014, at 12:03 PM, Richard Sandiford  
wrote:

> This is part of a series to remove uses of for_each_rtx from the ports.
> 
> Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
> and g++.dg for sh-elf.  OK to install?

OK with me.

Cheers,
Oleg



> gcc/
>* config/sh/sh.c (sh_contains_memref_p_1): Delete.
>(sh_contains_memref_p): Use FOR_EACH_SUBRTX.
> 
> Index: gcc/config/sh/sh.c
> ===
> --- gcc/config/sh/sh.c2014-10-25 09:51:27.049897841 +0100
> +++ gcc/config/sh/sh.c2014-10-25 09:51:27.492901789 +0100
> @@ -12972,18 +12972,15 @@ shmedia_cleanup_truncate (rtx x)
>so we must look at the rtl ourselves to see if any of the feeding
>registers is used in a memref.
> 
> -   Called by sh_contains_memref_p via for_each_rtx.  */
> -static int
> -sh_contains_memref_p_1 (rtx *loc, void *data ATTRIBUTE_UNUSED)
> -{
> -  return (MEM_P (*loc));
> -}
> -
> -/* Return true iff INSN contains a MEM.  */
> +   Return true iff INSN contains a MEM.  */
> bool
> sh_contains_memref_p (rtx insn)
> {
> -  return for_each_rtx (&PATTERN (insn), &sh_contains_memref_p_1, NULL);
> +  subrtx_iterator::array_type array;
> +  FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
> +if (MEM_P (*iter))
> +  return true;
> +  return false;
> }
> 
> /* Return true iff INSN loads a banked register.  */


[match-and-simplify] error checking on user defined oper in for

2014-10-25 Thread Prathamesh Kulkarni
Currently this is accepted:
(for plus (mult div)
  ...)
which is incorrect. This patch puts more error-checks on the user-defined
operator in for-pattern.

* genmatch.c
  (insert_operator): New function.
  (parse_for): Call insert_operator.

Thanks,
Prathamesh
Index: gcc/genmatch.c
===
--- gcc/genmatch.c	(revision 216673)
+++ gcc/genmatch.c	(working copy)
@@ -349,8 +349,41 @@
   return 0;
 }
 
+id_base *
+insert_operator (id_base *op)
+{
+  id_base **orig_slot;
+  id_base **slot = orig_slot = operators->find_slot_with_hash (op, op->hashval, INSERT);
+  if (*slot)
+return 0;
 
+  char *id2 = xstrdup (op->id);
+  for (unsigned i = 0; i < strlen (id2); ++i)
+id2[i] = TOUPPER (id2[i]);
 
+  id_base tem (id_base::CODE, id2); 
+  slot = operators->find_slot_with_hash (&tem, tem.hashval, INSERT);
+  if (*slot)
+{
+  free (id2);
+  return 0;
+}
+
+  /* Try _EXPR appended */
+  id2 = (char *)xrealloc (id2, strlen (id2) + sizeof ("_EXPR") + 1);
+  strcat (id2, "_EXPR");
+  id_base tem2 (id_base::CODE, id2); 
+  slot = operators->find_slot_with_hash (&tem2, tem2.hashval, INSERT);
+
+  if (*slot)
+{
+  free (id2);
+  return 0;
+}
+
+  *orig_slot = op;
+  return *orig_slot;
+}
 /* The AST produced by parsing of the pattern definitions.  */
 
 struct dt_operand;
@@ -2920,10 +2953,8 @@
   /* Insert the user defined operators into the operator hash.  */
   const char *id = get_ident ();
   user_id *op = new user_id (id);
-  id_base **slot = operators->find_slot_with_hash (op, op->hashval, INSERT);
-  if (*slot)
-	fatal_at (token, "operator already defined");
-  *slot = op;
+  if (insert_operator (op) == 0)
+	fatal_at (token, "operator '%s' already defined", id);
   user_ids.safe_push (op);
 
   eat_token (CPP_OPEN_PAREN);


Re: [mep] RFA: Use new rtl iterators in global_reg_mentioned_p

2014-10-25 Thread DJ Delorie

>   * config/mep/mep.c: Include rtl-iter.h.
>   (global_reg_mentioned_p_1): Take a const_rtx and return a bool.
>   (xtensa_tls_referenced_p): Return a bool.  Use FOR_EACH_SUBRTX.

OK.


Re: [mep] RFA: Use new rtl iterators in mep_store_find_set

2014-10-25 Thread DJ Delorie

>   * config/mep/mep.c (mep_store_find_set): Take a const_rtx and
>   return a bool.  Replace "void *" with specific type.  Iterate
>   over all subrtxes.
>   (mep_store_data_bypass_1): Update calls accordingly.

OK.


Re: [xtensa] RFA: Use new rtl iterators in xtensa_tls_referenced_p

2014-10-25 Thread augustine.sterl...@gmail.com
On Sat, Oct 25, 2014 at 2:17 AM, Richard Sandiford
 wrote:
> This is part of a series to remove uses of for_each_rtx from the ports.
>
> Tested by making sure there were no code changes for gcc.dg, gcc.c-torture
> and g++.dg for xtensa-elf.  OK to install?

OK for Xtensa


Re: [mep] RFA: Use new rtl iterators in mep_mul_hilo_bypass_p

2014-10-25 Thread DJ Delorie

> gcc/
>   * config/mep/mep.c (mep_mul_hilo_bypass_1): Delete.
>   (mep_mul_hilo_bypass_p): Use FOR_EACH_SUBRTX.

OK.


[committed] Fix reassoc bit test optimization (PR tree-optimization/63641)

2014-10-25 Thread Jakub Jelinek
Hi!

Ian reported a bug in optimize_range_tests_to_bit_test, high used to be
off-by-one.  E.g. if the topmost bit in mask is set (wi::clz (mask) is
0), then the highest number covered by the mask is lowi (which corresponds
to bit 0) + prec - 1, rather than lowi + prec.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk as obvious.

2014-10-25  Jakub Jelinek  

PR tree-optimization/63641
* tree-ssa-reassoc.c (optimize_range_tests_to_bit_test): Set high
to low + prec - 1 - clz (mask) instead of low + prec - clz (mask).

* gcc.c-torture/execute/pr63641.c: New test.

--- gcc/tree-ssa-reassoc.c.jj   2014-10-17 12:53:59.0 +0200
+++ gcc/tree-ssa-reassoc.c  2014-10-24 22:38:55.762859480 +0200
@@ -2513,7 +2513,7 @@ optimize_range_tests_to_bit_test (enum t
{
  tree high = wide_int_to_tree (TREE_TYPE (lowi),
wi::to_widest (lowi)
-   + prec - wi::clz (mask));
+   + prec - 1 - wi::clz (mask));
  operand_entry_t oe = (*ops)[ranges[i].idx];
  tree op = oe->op;
  gimple stmt = op ? SSA_NAME_DEF_STMT (op)
--- gcc/testsuite/gcc.c-torture/execute/pr63641.c.jj2014-10-25 
18:54:15.338191911 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr63641.c   2014-10-25 
18:53:21.0 +0200
@@ -0,0 +1,54 @@
+/* PR tree-optimization/63641 */
+
+__attribute__ ((noinline, noclone)) int
+foo (unsigned char b)
+{
+  if (0x0 <= b && b <= 0x8)
+goto lab;
+  if (b == 0x0b)
+goto lab;
+  if (0x0e <= b && b <= 0x1a)
+goto lab;
+  if (0x1c <= b && b <= 0x1f)
+goto lab;
+  return 0;
+lab:
+  return 1;
+}
+
+__attribute__ ((noinline, noclone)) int
+bar (unsigned char b)
+{
+  if (0x0 <= b && b <= 0x8)
+goto lab;
+  if (b == 0x0b)
+goto lab;
+  if (0x0e <= b && b <= 0x1a)
+goto lab;
+  if (0x3c <= b && b <= 0x3f)
+goto lab;
+  return 0;
+lab:
+  return 1;
+}
+
+char tab1[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1,
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 };
+char tab2[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1,
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
+   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 };
+
+int
+main ()
+{
+  int i;
+  asm volatile ("" : : : "memory");
+  for (i = 0; i < 256; i++)
+if (foo (i) != (i < 32 ? tab1[i] : 0))
+  __builtin_abort ();
+  for (i = 0; i < 256; i++)
+if (bar (i) != (i < 64 ? tab2[i] : 0))
+  __builtin_abort ();
+  return 0;
+}

Jakub


RE: [MIPS] RFA: Use new rtl iterators in mips_rewrite_small_data

2014-10-25 Thread Matthew Fortune
> gcc/
>   * config/mips/mips.c (mips_rewrite_small_data_1): Take the context
>   as a parameter instead of the containing MEM.  Iterate over all
>   subrtxes.  Don't return a value.
>   (mips_rewrite_small_data): Update call accordingly.

OK


RE: [MIPS] RFA: Use new rtl iterators in mips_small_data_pattern_p

2014-10-25 Thread Matthew Fortune
> gcc/
>   * config/mips/mips.c: Include rtl-iter.h.
>   (mips_small_data_pattern_1): Take an rtx rather than an rtx pointer.
>   Take the context as a parameter instead of the containing MEM.
>   Iterate over all subrtxes.
>   (mips_small_data_pattern_p): Update call accordingly.

OK


RE: [MIPS] RFA: Use new rtl iterators in mips16_rewrite_pool_refs

2014-10-25 Thread Matthew Fortune
> gcc/
>   * config/mips/mips.c (mips16_rewrite_pool_refs_info): Delete.
>   (mips16_rewrite_pool_refs): Take the insn and constant pool as
>   parameters.  Iterate over the instruction's pattern and return void.
>   (mips16_lay_out_constants): Update accordingly.

OK
 


RE: [MIPS] RFA: Use new rtl iterators in r10k_needs_protection_p_1

2014-10-25 Thread Matthew Fortune
> gcc/
>   * config/mips/mips.c (r10k_needs_protection_p_1): Take an rtx
>   rather than an rtx pointer.  Change type of insn from "void *"
>   to its real type.  Return bool rather than int.  Iterate over
>   all subrtxes here.
>   (r10k_needs_protection_p_store): Update accordingly.
>   (r10k_needs_protection_p): Likewise.

OK


RE: [MIPS] RFA: Use new rtl iterators in mips_kernel_reg_p

2014-10-25 Thread Matthew Fortune
> gcc/
>   * config/mips/mips.c (mips_kernel_reg_p): Replace with...
>   (mips_refers_to_kernel_reg_p): ...this new function.
>   (mips_expand_prologue): Update accordingly.

OK


RE: [MIPS] RFA: Use new rtl iterators in mips_sim_wait_regs_1

2014-10-25 Thread Matthew Fortune
> gcc/
>   * config/mips/mips.c (mips_sim_insn): Update comment.
>   (mips_sim_wait_regs_2): Delete.
>   (mips_sim_wait_regs_1): Use FOR_EACH_SUBRTX_VAR.

OK


RE: [MIPS] RFA: Use new rtl iterators in mips_record_lo_sums

2014-10-25 Thread Matthew Fortune
> gcc/
>   * config/mips/mips.c (mips_record_lo_sum): Replace with...
>   (mips_record_lo_sums): ...this new function.
>   (mips_reorg_process_insns): Update accordingly.

OK


RE: [MIPS] RFA: Use new rtl iterators in r10k_needs_protection_p_call

2014-10-25 Thread Matthew Fortune
> gcc/
>   * config/mips/mips.c (r10k_needs_protection_p_call): Take a const_rtx
>   and return a bool.  Iterate over all subrtxes here.
>   (r10k_needs_protection_p): Update accordingly.

OK


RE: [MIPS] RFA: Use new rtl iterators in mips_need_noat_wrapper_p

2014-10-25 Thread Matthew Fortune
> gcc/
>   * config/mips/mips.c (mips_at_reg_p): Delete.
>   (mips_need_noat_wrapper_p): Use FOR_EACH_SUBRTX.

OK. That should be the last one to cover all changes to use
new rtl iterators for MIPS.

Thanks for splitting this up per change it made it easy to read
through.

Matthew


Re: genmatch infinite loop during bootstrap on AIX

2014-10-25 Thread David Edelsohn
Richard,

I confirmed again with gcc111, which fails with r216632 and succeeds
with r216624.

On my internal AIX system bootstrapping with GCC 4.7.3, it enters an
infinite loop in stage 1.  With gcc111 and bootstrapping with GCC
4.8.1, it enters an infinite loop in stage 2.

Thanks, David

On Sat, Oct 25, 2014 at 2:36 PM, David Edelsohn  wrote:
> Richard,
>
> There definitely seems to be something wrong with genmatch and the
> recent match-and-simplify patch (r216632).  Using a different,
> internal AIX system to speed up testing the potential causes of the
> problem, a tree at r216661 (just before Marxin's patch) hangs in
> genmatch during stage 1 bootstrap using G++ 4.7.3:
>
> (gdb) where
> #0  0x10068158 in std::allocator::allocator() ()
> #1  0x1000b0b0 in _ZN6parser13parse_captureEP7operand (this=0x2ff20974, 
> op=0x0)
> at /nasfarm/edelsohn/src/src/gcc/genmatch.c:2607
> #2  0x1000b994 in _ZN6parser8parse_opEv (this=0x2ff20974)
> at /nasfarm/edelsohn/src/src/gcc/genmatch.c:2767
> #3  0x1000b4f4 in _ZN6parser10parse_exprEv (this=0x2ff20974)
> at /nasfarm/edelsohn/src/src/gcc/genmatch.c:2669
> #4  0x1000b7c0 in _ZN6parser8parse_opEv (this=0x2ff20974)
> at /nasfarm/edelsohn/src/src/gcc/genmatch.c:2728
> #5  0x1000ba4c in
> _ZN6parser14parse_simplifyEjR3vecIP8simplify7va_heap6vl_ptrEP12predicate_idP4expr
> (this=0x2ff20974, match_location=4614, simplifiers=...,
> matcher=0x0, result=0x0) at /nasfarm/edelsohn/src/src/gcc/genmatch.c:2792
> #6  0x1000c868 in _ZN6parser13parse_patternEv (this=0x2ff20974)
> at /nasfarm/edelsohn/src/src/gcc/genmatch.c:3052
> #7  0x1000c544 in _ZN6parser9parse_forEj (this=0x2ff20974)
> at /nasfarm/edelsohn/src/src/gcc/genmatch.c:2991
> #8  0x1000cb1c in _ZN6parser13parse_patternEv (this=0x2ff20974)
> at /nasfarm/edelsohn/src/src/gcc/genmatch.c:3090
> #9  0x1000cd78 in _ZN6parserC2EP10cpp_reader (this=0x2ff20974, r_=0x3000c8e8)
> at /nasfarm/edelsohn/src/src/gcc/genmatch.c:3122
> #10 0x10011614 in main (argc=3, argv=0x2ff20a3c)
> at /nasfarm/edelsohn/src/src/gcc/genmatch.c:3204
>
> r216624 (after Maxim's sched patches and before your
> match-and-simplify patch) does not have a problem on gcc111.
>
> - David
>
>
> On Sat, Oct 25, 2014 at 1:18 PM, David Edelsohn  wrote:
>> Bootstrap succeeds with Maxim's patch (r216624).
>>
>> The other, significant changes I see on trunk between r216624 and r216674 
>> are:
>>
>> match-and-simplify through r216632
>> ipc-icf in r216662
>> libstdc++ in r216667
>>
>> No other patches to trunk *seem* like they should affect PPC bootstrap.
>>
>> - David
>>
>>
>> On Sat, Oct 25, 2014 at 10:04 AM, David Edelsohn  wrote:
>>> It may be fallout from Maxim's scheduler patch.  I'm testing that.
>>> Backing up before Maxim's patch and your genmatch patch does not enter
>>> an endless loop.
>>>
>>> - David
>>>
>>> On Sat, Oct 25, 2014 at 4:06 AM, Richard Biener  wrote:
 On October 25, 2014 1:33:39 AM CEST, David Edelsohn  
 wrote:
>genmatch is hanging when bootstrapping on AIX (gcc111).  When I attach
>to the process:
>
>#0  0x1007efac in std::basic_string,
>std::allocator >::basic_string ()
>#1  0x1000e6b0 in _ZN6parser13parse_captureEP7operand (this=0x300594b8,
>op=0x0)
>at /home/dje/src/src/gcc/genmatch.c:2607

 Does it really hang in libstdc++ or does it loop somewhere in genmatch? Is 
 this stage1 or later?

 Does this happen only after the 2nd part of the merge went in? That is, 
 what revision?

 Thanks,
 Richard.

>#2  0x1000e9f0 in _ZN6parser10parse_exprEv (this=0x2ff20208)
>at /home/dje/src/src/gcc/genmatch.c:2669
>#3  0x1000ee38 in _ZN6parser8parse_opEv (this=0x2ff20208)
>at /home/dje/src/src/gcc/genmatch.c:2728
>#4  0x1000efc4 in
>_ZN6parser14parse_simplifyEjR3vecIP8simplify7va_heap6vl_ptrEP12predicate_idP4expr
>(this=0x2ff20208, match_location=4614, simplifiers=...,
>matcher=0x0, result=0x0) at /home/dje/src/src/gcc/genmatch.c:2792
>#5  0x100102fc in _ZN6parser13parse_patternEv (this=0x2ff20208)
>at /home/dje/src/src/gcc/genmatch.c:3052
>#6  0x10010c0c in _ZN6parser9parse_forEj (this=0x2ff20208)
>at /home/dje/src/src/gcc/genmatch.c:2991
>#7  0x10010350 in _ZN6parser13parse_patternEv (this=0x2ff20208)
>at /home/dje/src/src/gcc/genmatch.c:3090
>#8  0x1001122c in _ZN6parserC2EP10cpp_reader (this=0x2ff20208,
>r_=0x3003bbec)
>at /home/dje/src/src/gcc/genmatch.c:3122
>#9  0x10004acc in main (argc=,
>argv=) at  _start_ :3204




Re: support operator list

2014-10-25 Thread Prathamesh Kulkarni
Fixed a silly mistake in match-bitwise.pd (I had put ')' at wrong place).
This patch also checks if operator-list is used outside for-pattern
(in parser::parse_operation).

* genmatch.c
(user_id): Add new member is_oper_list.
(user_id::user_id): Add new default argument.
(parser::parse_operator_list): New member function in parser.
(add_substitute): New function.
(flatten_substitutes): Likewise.
(parser::parse_for): Call add_substitute.
(parser::parse_pattern): Call parser::parse_operator_list.
(parser::parse_operation): Put check for operator-list.

* match-bitwise.pd
(bitwise_ors): New operator-list.
(bitwise_ops): Likewise.
Use bitwise_ors and bitwise_ops in patterns.

* match-comparison.pd
 (eq_ops): New operator-list.
 (cmp_ops): Likewise.
 Use cmp_ops and eq_ops in patterns.

Thanks,
Prathamesh



On Sat, Oct 25, 2014 at 10:44 PM, Prathamesh Kulkarni
 wrote:
> Hi,
> This patch adds support for operator-lists, and uses
> them in match-bitwise.pd and match-comparison.pd
>
> * genmatch.c
> (parser::parse_operator_list): New member function in parser.
> (add_substitute): New function.
> (flatten_substitutes): Likewise.
> (parser::parse_for): Call add_substitute.
> (parser::parse_pattern): Call parser::parse_operator_list.
>
> * match-bitwise.pd
> (bitwise_ors): New operator-list.
> (bitwise_ops): Likewise.
> Use bitwise_ors and bitwise_ops in patterns.
>
> * match-comparison.pd
>  (eq_ops): New operator-list.
>  (cmp_ops): Likewise.
>  Use cmp_ops and eq_ops in patterns.
>
> Thanks,
> Prathamesh
Index: gcc/genmatch.c
===
--- gcc/genmatch.c	(revision 216673)
+++ gcc/genmatch.c	(working copy)
@@ -218,9 +218,10 @@
 
 struct user_id : public id_base
 {
-  user_id (const char *id_)
-: id_base (id_base::USER, id_), substitutes (vNULL) {}
+  user_id (const char *id_, bool is_oper_list_ = false)
+: id_base (id_base::USER, id_), substitutes (vNULL), is_oper_list (is_oper_list_) {}
   vec substitutes;
+  bool is_oper_list;
 };
 
 template<>
@@ -2419,6 +2420,7 @@
   void parse_simplify (source_location, vec&, predicate_id *,
 		   expr *);
   void parse_for (source_location);
+  void parse_operator_list ();
   void parse_if (source_location);
   void parse_predicates (source_location);
 
@@ -2582,8 +2584,14 @@
 	   || strcmp  (id, "convert2") == 0)
 fatal_at (id_tok, "expected '?' after conditional operator");
   id_base *op = get_operator (id);
+
   if (!op)
 fatal_at (id_tok, "unknown operator %s", id);
+  
+  user_id *uid;
+  if ((uid = dyn_cast (op)) != 0 && uid->is_oper_list)
+fatal_at (id_tok, "operator-list '%s' can be used only in for", uid->id);
+
   return op;
 }
 
@@ -2900,6 +2908,20 @@
 
 /* Parsing of the outer control structures.  */
 
+bool
+add_substitute (user_id *op, id_base *idb, int& arity) 
+{
+  if (arity == -1)
+arity = idb->nargs;
+  else if (idb->nargs == -1)
+;
+  else if (idb->nargs != arity)
+return false;
+
+  op->substitutes.safe_push (idb);
+  return true;
+}
+  
 /* Parse a for expression
  for = '(' 'for' ...  ')'
  subst =  '(' ... ')'  */
@@ -2938,15 +2960,16 @@
 	  if (*idb == CONVERT0 || *idb == CONVERT1 || *idb == CONVERT2)
 	fatal_at (token, "conditional operators cannot be used inside for");
 
-	  if (arity == -1)
-	arity = idb->nargs;
-	  else if (idb->nargs == -1)
-	;
-	  else if (idb->nargs != arity)
-	fatal_at (token, "operator '%s' with arity %d does not match "
-		  "others with arity %d", oper, idb->nargs, arity);
+	  vec substitutes = vNULL;
+	  if (idb->kind == id_base::USER)
+	substitutes = (as_a (idb))->substitutes;
+	  else
+	substitutes.safe_push (idb);
 
-	  op->substitutes.safe_push (idb);
+	  for (unsigned si = 0; si < substitutes.length (); ++si)
+	if (!add_substitute (op, substitutes[si], arity))
+	  fatal_at (token, "operator '%s' with arity %d does not match "
+			   "others with arity %d", oper, idb->nargs, arity);
 	}
   op->nargs = arity;
   token = expect (CPP_CLOSE_PAREN);
@@ -2997,6 +3020,55 @@
 operators->remove_elt (user_ids[i]);
 }
 
+void
+flatten_substitutes (vec& ids, vec& substitutes)
+{
+  user_id *op;
+ 
+  for (unsigned i = 0; i < ids.length (); ++i)
+if ((op = dyn_cast (ids[i])) != 0)
+  flatten_substitutes (op->substitutes, substitutes);
+else
+  substitutes.safe_push (ids[i]);
+}
+
+void
+parser::parse_operator_list ()
+{
+  const char *id = get_ident ();
+  user_id *op = new user_id (id, true);
+  vec user_id_tokens = vNULL;
+
+  id_base **slot = operators->find_slot_with_hash (op, op->hashval, INSERT);
+  if (*slot)
+fatal ("operator %s already defined", id);
+  *slot = op;
+
+  const cpp_token *token;
+  vec ids = vNULL;
+
+  while ((token = peek_ident ()) != 0)
+{
+  const char *oper = get_ident ();
+  id_base *p = get_operator (oper);
+