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; })