From: Richard Sandiford <rdsandiford@googlemail.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 38/50] rtlanal.c:replace_label
Date: Sun, 03 Aug 2014 14:25:00 -0000 [thread overview]
Message-ID: <87egwx7iqk.fsf@googlemail.com> (raw)
In-Reply-To: <87y4v5d77q.fsf@googlemail.com> (Richard Sandiford's message of "Sun, 03 Aug 2014 14:38:01 +0100")
The main change here is to handle ADDR_VEC and ADDR_DIFF_VECs specially,
since they can have many elements and are a relatively important case
for this function. This is for speed rather than correctness.
gcc/
* rtl.h (replace_label_data): Delete.
(replace_label): Take the old label, new label and update-nuses flag
as direct arguments. Return void.
* cfgcleanup.c (outgoing_edges_match): Update accordingly.
* rtlanal.c (replace_label): Update interface as above. Handle
JUMP_TABLE_DATA as a special case. Handle JUMPs outside the
iterator. Use FOR_EACH_SUBRTX_PTR.
Index: gcc/rtl.h
===================================================================
--- gcc/rtl.h 2014-08-03 11:25:30.447157195 +0100
+++ gcc/rtl.h 2014-08-03 11:25:30.745160142 +0100
@@ -2211,14 +2211,6 @@ #define single_set(I) (INSN_P (I) \
: NULL_RTX)
#define single_set_1(I) single_set_2 (I, PATTERN (I))
-/* Structure used for passing data to REPLACE_LABEL. */
-struct replace_label_data
-{
- rtx r1;
- rtx r2;
- bool update_label_nuses;
-};
-
extern enum machine_mode get_address_mode (rtx mem);
extern int rtx_addr_can_trap_p (const_rtx);
extern bool nonzero_address_p (const_rtx);
@@ -2287,7 +2279,7 @@ extern void copy_reg_eh_region_note_forw
extern void copy_reg_eh_region_note_backward (rtx, rtx, rtx);
extern int inequality_comparisons_p (const_rtx);
extern rtx replace_rtx (rtx, rtx, rtx);
-extern int replace_label (rtx *, void *);
+extern void replace_label (rtx *, rtx, rtx, bool);
extern bool rtx_referenced_p (const_rtx, const_rtx);
extern bool tablejump_p (const_rtx, rtx *, rtx *);
extern int computed_jump_p (const_rtx);
Index: gcc/cfgcleanup.c
===================================================================
--- gcc/cfgcleanup.c 2014-08-03 11:25:22.602079634 +0100
+++ gcc/cfgcleanup.c 2014-08-03 11:25:30.745160142 +0100
@@ -1716,15 +1716,11 @@ outgoing_edges_match (int mode, basic_bl
if (identical)
{
- replace_label_data rr;
bool match;
/* Temporarily replace references to LABEL1 with LABEL2
in BB1->END so that we could compare the instructions. */
- rr.r1 = label1;
- rr.r2 = label2;
- rr.update_label_nuses = false;
- for_each_rtx (&BB_END (bb1), replace_label, &rr);
+ replace_label (&BB_END (bb1), label1, label2, false);
match = (old_insns_match_p (mode, BB_END (bb1), BB_END (bb2))
== dir_both);
@@ -1736,9 +1732,7 @@ outgoing_edges_match (int mode, basic_bl
/* Set the original label in BB1->END because when deleting
a block whose end is a tablejump, the tablejump referenced
from the instruction is deleted too. */
- rr.r1 = label2;
- rr.r2 = label1;
- for_each_rtx (&BB_END (bb1), replace_label, &rr);
+ replace_label (&BB_END (bb1), label2, label1, false);
return match;
}
@@ -1985,20 +1979,16 @@ #define SWAP(T, X, Y) do { T tmp = (X);
&& tablejump_p (BB_END (osrc2), &label2, &table2)
&& label1 != label2)
{
- replace_label_data rr;
rtx insn;
/* Replace references to LABEL1 with LABEL2. */
- rr.r1 = label1;
- rr.r2 = label2;
- rr.update_label_nuses = true;
for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
{
/* Do not replace the label in SRC1->END because when deleting
a block whose end is a tablejump, the tablejump referenced
from the instruction is deleted too. */
if (insn != BB_END (osrc1))
- for_each_rtx (&insn, replace_label, &rr);
+ replace_label (&insn, label1, label2, true);
}
}
}
Index: gcc/rtlanal.c
===================================================================
--- gcc/rtlanal.c 2014-08-03 11:25:30.448157205 +0100
+++ gcc/rtlanal.c 2014-08-03 11:25:30.746160151 +0100
@@ -2770,65 +2770,79 @@ replace_rtx (rtx x, rtx from, rtx to)
return x;
}
\f
-/* Replace occurrences of the old label in *X with the new one.
- DATA is a REPLACE_LABEL_DATA containing the old and new labels. */
+/* Replace occurrences of the OLD_LABEL in *LOC with NEW_LABEL. Also track
+ the change in LABEL_NUSES if UPDATE_LABEL_NUSES. */
-int
-replace_label (rtx *x, void *data)
+void
+replace_label (rtx *loc, rtx old_label, rtx new_label, bool update_label_nuses)
{
- rtx l = *x;
- rtx old_label = ((replace_label_data *) data)->r1;
- rtx new_label = ((replace_label_data *) data)->r2;
- bool update_label_nuses = ((replace_label_data *) data)->update_label_nuses;
-
- if (l == NULL_RTX)
- return 0;
-
- if (GET_CODE (l) == SYMBOL_REF
- && CONSTANT_POOL_ADDRESS_P (l))
+ /* Handle jump tables specially, since ADDR_{DIFF_,}VECs can be long. */
+ rtx x = *loc;
+ if (JUMP_TABLE_DATA_P (x))
{
- rtx c = get_pool_constant (l);
- if (rtx_referenced_p (old_label, c))
+ x = PATTERN (x);
+ rtvec vec = XVEC (x, GET_CODE (x) == ADDR_DIFF_VEC);
+ int len = GET_NUM_ELEM (vec);
+ for (int i = 0; i < len; ++i)
{
- rtx new_c, new_l;
- replace_label_data *d = (replace_label_data *) data;
-
- /* Create a copy of constant C; replace the label inside
- but do not update LABEL_NUSES because uses in constant pool
- are not counted. */
- new_c = copy_rtx (c);
- d->update_label_nuses = false;
- for_each_rtx (&new_c, replace_label, data);
- d->update_label_nuses = update_label_nuses;
-
- /* Add the new constant NEW_C to constant pool and replace
- the old reference to constant by new reference. */
- new_l = XEXP (force_const_mem (get_pool_mode (l), new_c), 0);
- *x = replace_rtx (l, l, new_l);
+ rtx ref = RTVEC_ELT (vec, i);
+ if (XEXP (ref, 0) == old_label)
+ {
+ XEXP (ref, 0) = new_label;
+ if (update_label_nuses)
+ {
+ ++LABEL_NUSES (new_label);
+ --LABEL_NUSES (old_label);
+ }
+ }
}
- return 0;
+ return;
}
/* If this is a JUMP_INSN, then we also need to fix the JUMP_LABEL
- field. This is not handled by for_each_rtx because it doesn't
+ field. This is not handled by the iterator because it doesn't
handle unprinted ('0') fields. */
- if (JUMP_P (l) && JUMP_LABEL (l) == old_label)
- JUMP_LABEL (l) = new_label;
+ if (JUMP_P (x) && JUMP_LABEL (x) == old_label)
+ JUMP_LABEL (x) = new_label;
- if ((GET_CODE (l) == LABEL_REF
- || GET_CODE (l) == INSN_LIST)
- && XEXP (l, 0) == old_label)
+ subrtx_ptr_iterator::array_type array;
+ FOR_EACH_SUBRTX_PTR (iter, array, loc, ALL)
{
- XEXP (l, 0) = new_label;
- if (update_label_nuses)
+ rtx *loc = *iter;
+ if (rtx x = *loc)
{
- ++LABEL_NUSES (new_label);
- --LABEL_NUSES (old_label);
+ if (GET_CODE (x) == SYMBOL_REF
+ && CONSTANT_POOL_ADDRESS_P (x))
+ {
+ rtx c = get_pool_constant (x);
+ if (rtx_referenced_p (old_label, c))
+ {
+ /* Create a copy of constant C; replace the label inside
+ but do not update LABEL_NUSES because uses in constant pool
+ are not counted. */
+ rtx new_c = copy_rtx (c);
+ replace_label (&new_c, old_label, new_label, false);
+
+ /* Add the new constant NEW_C to constant pool and replace
+ the old reference to constant by new reference. */
+ rtx new_mem = force_const_mem (get_pool_mode (x), new_c);
+ *loc = replace_rtx (x, x, XEXP (new_mem, 0));
+ }
+ }
+
+ if ((GET_CODE (x) == LABEL_REF
+ || GET_CODE (x) == INSN_LIST)
+ && XEXP (x, 0) == old_label)
+ {
+ XEXP (x, 0) = new_label;
+ if (update_label_nuses)
+ {
+ ++LABEL_NUSES (new_label);
+ --LABEL_NUSES (old_label);
+ }
+ }
}
- return 0;
}
-
- return 0;
}
/* Return true if X is referenced in BODY. */
next prev parent reply other threads:[~2014-08-03 14:25 UTC|newest]
Thread overview: 108+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-03 13:38 [PATCH 0/50] Faster for_each_rtx-like iterators Richard Sandiford
2014-08-03 13:39 ` [PATCH 01/50] Add rtl-iter.h Richard Sandiford
2014-08-05 20:48 ` Jeff Law
2014-08-05 22:19 ` Richard Henderson
2014-08-09 10:16 ` Richard Sandiford
2014-08-03 13:40 ` [PATCH 02/50] alias.c:refs_newer_value_p Richard Sandiford
2014-08-05 20:52 ` Jeff Law
2014-08-03 13:44 ` [PATCH 03/50] bt-load.c:find_btr_use Richard Sandiford
2014-08-06 18:39 ` Jeff Law
2014-08-03 13:48 ` [PATCH 04/50] caller-save.c:add_used_regs Richard Sandiford
2014-08-05 20:54 ` Jeff Law
2014-08-03 13:48 ` [PATCH 05/50] calls.c:internal_arg_pointer_based_exp Richard Sandiford
2014-08-05 20:56 ` Jeff Law
2014-08-03 13:50 ` [PATCH 06/50] combine.c:unmentioned_reg_p Richard Sandiford
2014-08-05 20:56 ` Jeff Law
2014-08-03 13:51 ` [PATCH 07/50] combine.c:record_truncated_values Richard Sandiford
2014-08-05 20:57 ` Jeff Law
2014-08-03 13:52 ` [PATCH 08/50] Faster for_each_rtx-like iterators Richard Sandiford
2014-08-06 18:17 ` Jeff Law
2014-08-03 13:53 ` [PATCH 09/50] cfgcleanup.c:mentions_nonequal_regs Richard Sandiford
2014-08-05 21:00 ` Jeff Law
2014-08-03 13:54 ` [PATCH 10/50] cse.c:approx_reg_cost Richard Sandiford
2014-08-05 21:01 ` Jeff Law
2014-08-03 13:55 ` [PATCH 11/50] Faster for_each_rtx-like iterators Richard Sandiford
2014-08-06 18:20 ` Jeff Law
2014-08-03 13:56 ` [PATCH 12/50] cse.c:check_for_label_ref Richard Sandiford
2014-08-06 18:15 ` Jeff Law
2014-08-03 13:57 ` [PATCH 13/50] cse.c:is_dead_debug_insn Richard Sandiford
2014-08-05 21:03 ` Jeff Law
2014-08-03 13:58 ` [PATCH 15/50] ddg.c:mark_mem_use Richard Sandiford
2014-08-05 21:04 ` Jeff Law
2014-08-03 13:58 ` [PATCH 14/50] cse.c:cse_change_cc_mode Richard Sandiford
2014-08-05 21:04 ` Jeff Law
2014-08-03 13:59 ` [PATCH 16/50] ddg.c:insns_may_alias_p Richard Sandiford
2014-08-05 21:05 ` Jeff Law
2014-08-03 14:02 ` [PATCH 18/50] dse.c:check_mem_read_use Richard Sandiford
2014-08-05 21:06 ` Jeff Law
2014-08-03 14:02 ` [PATCH 17/50] df-problems.c:find_memory Richard Sandiford
2014-08-05 21:29 ` Jeff Law
2014-08-06 8:35 ` Richard Earnshaw
2014-08-03 14:03 ` [PATCH 19/50] dwarf2out.c:const_ok_for_output Richard Sandiford
2014-08-05 21:30 ` Jeff Law
2014-08-03 14:04 ` [PATCH 20/50] dwarf2out.c:resolve_one_addr Richard Sandiford
2014-08-05 21:31 ` Jeff Law
2014-08-03 14:07 ` [PATCH 21/50] Faster for_each_rtx-like iterators Richard Sandiford
2014-08-05 21:09 ` Jeff Law
2014-08-03 14:08 ` [PATCH 22/50] final.c:mark_symbol_refs_as_used Richard Sandiford
2014-08-05 21:10 ` Jeff Law
2014-08-03 14:09 ` [PATCH 23/50] function.c:instantiate_virtual_regs_in_rtx Richard Sandiford
2014-08-06 18:14 ` Jeff Law
2014-08-03 14:10 ` [PATCH 25/50] ira.c:set_paradoxical_subreg Richard Sandiford
2014-08-05 21:11 ` Jeff Law
2014-08-03 14:10 ` [PATCH 24/50] fwprop.c:varying_mem_p Richard Sandiford
2014-08-05 21:10 ` Jeff Law
2014-08-03 14:11 ` [PATCH 26/50] jump.c:returnjump_p Richard Sandiford
2014-08-05 21:11 ` Jeff Law
2014-08-03 14:12 ` [PATCH 27/50] jump.c:eh_returnjump_p Richard Sandiford
2014-08-05 21:11 ` Jeff Law
2014-08-03 14:13 ` [PATCH 28/50] loop-iv.c:replace_single_def_regs Richard Sandiford
2014-08-05 22:08 ` Jeff Law
2014-08-03 14:14 ` [PATCH 29/50] loop-iv.c:altered_reg_used Richard Sandiford
2014-08-05 21:12 ` Jeff Law
2014-08-03 14:15 ` [PATCH 31/50] lower-subreg.c:resolve_debug Richard Sandiford
2014-08-05 21:13 ` Jeff Law
2014-08-03 14:15 ` [PATCH 30/50] lower-subreg.c:resolve_subreg_use Richard Sandiford
2014-08-06 18:12 ` Jeff Law
2014-08-03 14:17 ` [PATCH 32/50] lower-subreg.c:find_decomposable_subregs Richard Sandiford
2014-08-06 18:11 ` Jeff Law
2014-08-03 14:18 ` [PATCH 33/50] reg-stack.c:subst_all_stack_regs_in_debug_insn Richard Sandiford
2014-08-05 21:13 ` Jeff Law
2014-08-03 14:19 ` [PATCH 34/50] regcprop.c:kill_autoinc_value Richard Sandiford
2014-08-05 21:16 ` Jeff Law
2014-08-03 14:20 ` [PATCH 36/50] reload1.c:note_reg_elim_costly Richard Sandiford
2014-08-05 22:09 ` Jeff Law
2014-08-03 14:20 ` [PATCH 35/50] regcprop.c:cprop_find_used_regs Richard Sandiford
2014-08-05 21:17 ` Jeff Law
2014-08-03 14:22 ` [PATCH 37/50] rtlanal.c:rtx_referenced_p Richard Sandiford
2014-08-05 22:10 ` Jeff Law
2014-08-03 14:25 ` Richard Sandiford [this message]
2014-08-05 22:11 ` [PATCH 38/50] rtlanal.c:replace_label Jeff Law
2014-08-03 14:27 ` [PATCH 39/50] rtlanal.c:record_hard_reg_uses Richard Sandiford
2014-08-05 21:19 ` Jeff Law
2014-08-03 14:32 ` [PATCH 40/50] rtlanal.c:for_each_inc_dec Richard Sandiford
2014-08-06 18:33 ` Jeff Law
2014-08-09 10:13 ` Richard Sandiford
2014-08-12 20:11 ` Jeff Law
2014-08-26 19:28 ` Richard Sandiford
2014-08-27 20:36 ` Jeff Law
2014-08-03 14:33 ` [PATCH 41/50] rtlanal.c:tls_referenced_p Richard Sandiford
2014-08-05 21:19 ` Jeff Law
2014-08-03 14:34 ` [PATCH 42/50] sel-sched.c:count_occurrences_equiv Richard Sandiford
2014-08-05 22:12 ` Jeff Law
2014-08-03 14:34 ` [PATCH 43/50] store-motion.c:extract_mentioned_regs Richard Sandiford
2014-08-05 21:20 ` Jeff Law
2014-08-03 14:35 ` [PATCH 44/50] var-tracking.c:rtx_debug_expr_p Richard Sandiford
2014-08-05 21:20 ` Jeff Law
2014-08-03 14:36 ` [PATCH 45/50] var-tracking.c:non_suitable_const Richard Sandiford
2014-08-05 21:21 ` Jeff Law
2014-08-03 14:38 ` [PATCH 47/50] var-tracking.c:add_uses Richard Sandiford
2014-08-05 21:22 ` Jeff Law
2014-08-03 14:38 ` [PATCH 46/50] var-tracking.c:use_narrower_mode_test Richard Sandiford
2014-08-05 22:19 ` Jeff Law
2014-08-03 14:42 ` [PATCH 48/50] varasm.c:const_rtx_hash Richard Sandiford
2014-08-05 22:18 ` Jeff Law
2014-08-03 14:43 ` [PATCH 49/50] varasm.c:mark_constants Richard Sandiford
2014-08-05 22:16 ` Jeff Law
2014-08-03 14:45 ` [PATCH 50/50] varasm.c:compute_reloc_for_rtx Richard Sandiford
2014-08-05 22:15 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87egwx7iqk.fsf@googlemail.com \
--to=rdsandiford@googlemail.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).