This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[sel-sched] Speed up the work with cfg successors
- From: Andrey Belevantsev <abel at ispras dot ru>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 11 Jan 2008 17:31:57 +0300
- Subject: [sel-sched] Speed up the work with cfg successors
Hello,
When traversing a scheduling region, we need to know the region
successors of the current insn, which may be different than its CFG
successors, say when these are not in the current region. We have a
number of functions to work with these successors, which allocate memory
too eagerly. I've rewritten these functions such as they compute all
needed information about successors (probability, flags, etc) during the
single iteration over them. This function uses the pool to allocate
memory for its return value. This helps speeding up some test cases.
Tested on ia64, committed to sel-sched branch.
Also, before committing this series of patches I forgot to mention that
I've screwed up the previous merge from trunk to the branch, as I
wrongly used the patch from our internal tree instead of doing svn
merge. It took some time to get the branch into the correct state.
Starting from rev. 131463, it should be fine.
Andrey
2008-01-11 Andrey Belevantsev <abel@ispras.ru>
* haifa-sched.c (rtx_vec_t): Move to ...
* sched-int.h: ... here.
* sel-sched-dump.c (dump_insn_array): Rename to
dump_insn_vector. Rewrite for using vector of insns.
(debug_insn_array): Likewise.
* sel-sched-dump.h: Export the above functions.
* sel-sched-ir.c (current_succs): New global variable.
(init_fences): Use FOR_EACH_SUCC* instead of cfg_succs*.
(get_seqno_of_a_pred): Likewise.
(insert_in_history_vect): Properly handle the situation of
merging different speculative statuses.
(av_set_split_usefulness): Use FOR_EACH_RHS.
(succs_info_pool): New variable.
(cfg_succs_n, cfg_succs_1, cfg_succs_2, cfg_succs,
cfg_succs_other, cfg_succ_1, cfg_succ, overall_prob_of_succs): Kill.
(alloc_succs_info, free_succs_info, compute_succs_info): New.
(alloc_sched_pools, free_sched_pools): Move and rename from ...
* sel-sched-ir.h (init_sched_pools, free_sched_pools) ... here.
Update all callers.
(MAX_WS): Move from sel-sched.c.
(struct succs_info): New.
(succ_iterator): New fields flags, current_flags.
(_succ_iter_start, _succ_iter_cond,
_eligible_successor_edge_p): Use them.
* sel-sched.c (compute_av_set): Use *_succs_info functions instead of
cfg_succs*. Stop when maximal lookahead is reached even
on a bb header.
(fill_insns): Use FOR_EACH_SUCC* instead of cfg_succs*.
(sel_region_finish): Likewise.
Index: gcc/sel-sched.c
===================================================================
--- gcc/sel-sched.c (revision 131184)
+++ gcc/sel-sched.c (working copy)
@@ -94,7 +94,8 @@ int max_insns_to_rename;
/* Definitions of local types and macros. */
/* Represents possible outcomes of moving an expression through an insn. */
-enum MOVEUP_RHS_CODE { MOVEUP_RHS_SAME, MOVEUP_RHS_NULL, MOVEUP_RHS_CHANGED };
+enum MOVEUP_RHS_CODE { MOVEUP_RHS_SAME, MOVEUP_RHS_AS_RHS,
+ MOVEUP_RHS_NULL, MOVEUP_RHS_CHANGED };
/* The container to be passed into rtx search & replace functions. */
struct rtx_search_arg
@@ -1826,6 +1827,8 @@ moveup_rhs (rhs_t insn_to_move_up, insn_
{
vinsn_t vi = RHS_VINSN (insn_to_move_up);
insn_t insn = VINSN_INSN (vi);
+ bool was_changed = false;
+ bool as_rhs = false;
ds_t *has_dep_p;
ds_t full_ds;
@@ -1899,6 +1902,7 @@ moveup_rhs (rhs_t insn_to_move_up, insn_
/* Speculation was successful. */
{
full_ds = 0;
+ was_changed = true;
sel_clear_has_dependence ();
}
}
@@ -1916,11 +1920,12 @@ moveup_rhs (rhs_t insn_to_move_up, insn_
return MOVEUP_RHS_NULL;
EXPR_TARGET_AVAILABLE (insn_to_move_up) = false;
+ as_rhs = true;
}
/* At this point we have either separable insns, that will be lifted
up only as RHSes, or non-separable insns with no dependency in lhs.
- If dependency is in RHS, then try perform substitution and move up
+ If dependency is in RHS, then try to perform substitution and move up
substituted RHS:
Ex. 1: Ex.2
@@ -1943,8 +1948,11 @@ moveup_rhs (rhs_t insn_to_move_up, insn_
if (can_overcome_dep_p (*rhs_dsp))
{
if (speculate_expr (insn_to_move_up, *rhs_dsp))
- /* Speculation was successful. */
- *rhs_dsp = 0;
+ {
+ /* Speculation was successful. */
+ *rhs_dsp = 0;
+ was_changed = true;
+ }
else
return MOVEUP_RHS_NULL;
}
@@ -1970,7 +1978,8 @@ moveup_rhs (rhs_t insn_to_move_up, insn_
line_finish ();
return MOVEUP_RHS_NULL;
}
-
+
+ was_changed = true;
line_finish ();
}
else
@@ -1983,7 +1992,11 @@ moveup_rhs (rhs_t insn_to_move_up, insn_
if (CANT_MOVE_TRAPPING (insn_to_move_up, through_insn))
return MOVEUP_RHS_NULL;
- return MOVEUP_RHS_CHANGED;
+ return (was_changed
+ ? MOVEUP_RHS_CHANGED
+ : (as_rhs
+ ? MOVEUP_RHS_AS_RHS
+ : MOVEUP_RHS_SAME));
}
/* Moves an av set AVP up through INSN, performing necessary
@@ -2015,6 +2028,14 @@ moveup_set_rhs (av_set_t *avp, insn_t in
}
else
print (" - unchanged (cached)");
+
+ line_finish ();
+ continue;
+ }
+ else if (bitmap_bit_p (INSN_FOUND_DEPS (insn), rhs_uid))
+ {
+ EXPR_TARGET_AVAILABLE (rhs) = false;
+ print (" - unchanged (as RHS, cached)");
line_finish ();
continue;
@@ -2024,18 +2045,17 @@ moveup_set_rhs (av_set_t *avp, insn_t in
{
case MOVEUP_RHS_NULL:
/* Cache that there is a hard dependence. */
- if (!unique_p)
- {
- bitmap_set_bit (INSN_ANALYZED_DEPS (insn), rhs_uid);
- bitmap_set_bit (INSN_FOUND_DEPS (insn), rhs_uid);
- }
+ bitmap_set_bit (INSN_ANALYZED_DEPS (insn), rhs_uid);
+ bitmap_set_bit (INSN_FOUND_DEPS (insn), rhs_uid);
av_set_iter_remove (&i);
+
print (" - removed");
break;
case MOVEUP_RHS_CHANGED:
print (" - changed");
-
+ gcc_assert (INSN_UID (EXPR_INSN_RTX (rhs)) != rhs_uid);
+
/* Mark that this insn changed this expr. */
insert_in_hash_vect (&EXPR_CHANGED_ON_INSNS (rhs),
VINSN_HASH (INSN_VINSN (insn)));
@@ -2046,14 +2066,20 @@ moveup_set_rhs (av_set_t *avp, insn_t in
break;
case MOVEUP_RHS_SAME:
/* Cache that there is a no dependence. */
- if (!unique_p)
- {
- bitmap_set_bit (INSN_ANALYZED_DEPS (insn), rhs_uid);
- bitmap_clear_bit (INSN_FOUND_DEPS (insn), rhs_uid);
- }
+ bitmap_set_bit (INSN_ANALYZED_DEPS (insn), rhs_uid);
+ bitmap_clear_bit (INSN_FOUND_DEPS (insn), rhs_uid);
print (" - unchanged");
break;
+ case MOVEUP_RHS_AS_RHS:
+ /* Only an LHS dependence was found. Cache that there is
+ no dependence, but the target register is not available. */
+ gcc_assert (!unique_p);
+ bitmap_clear_bit (INSN_ANALYZED_DEPS (insn), rhs_uid);
+ bitmap_set_bit (INSN_FOUND_DEPS (insn), rhs_uid);
+
+ print (" - unchanged (as RHS)");
+ break;
default:
gcc_unreachable ();
}
@@ -3309,8 +3335,7 @@ fill_vec_av_set (av_set_t av, blist_t bn
(target_available == false
&& !EXPR_SEPARABLE_P (rhs))
/* Don't try to find a register for low-priority expression. */
- || (max_insns_to_rename >= 0
- && n > max_insns_to_rename))
+ || n >= max_insns_to_rename)
{
succ++;
VEC_ordered_remove (rhs_t, vec_av_set, n);
@@ -6159,7 +6184,7 @@ sel_global_init (void)
init_sched_pools ();
- setup_sched_dump_to_stderr ();
+ setup_sched_dumps ();
/* Setup the infos for sched_init. */
sel_setup_sched_infos ();
Index: gcc/sel-sched-dump.c
===================================================================
--- gcc/sel-sched-dump.c (revision 131184)
+++ gcc/sel-sched-dump.c (working copy)
@@ -32,6 +32,7 @@
#include "insn-config.h"
#include "insn-attr.h"
#include "params.h"
+#include "output.h"
#include "basic-block.h"
#include "cselib.h"
#include "sel-sched-ir.h"
@@ -185,8 +186,13 @@ print_marker_to_log (void)
}
void
-setup_sched_dump_to_stderr (void)
+setup_sched_dumps (void)
{
+ sched_verbose = sched_verbose_param;
+ if (sched_verbose_param == 0 && dump_file)
+ sched_verbose = 1;
+ sched_dump = ((sched_verbose_param >= 10 || !dump_file)
+ ? stderr : dump_file);
sched_dump1 = stderr;
}
Index: gcc/sel-sched-dump.h
===================================================================
--- gcc/sel-sched-dump.h (revision 131182)
+++ gcc/sel-sched-dump.h (working copy)
@@ -183,7 +183,7 @@ extern bool new_line;
/* Functions from sel-sched-dump.c. */
extern const char * sel_print_insn (rtx, int);
extern void free_sel_dump_data (void);
-extern void setup_sched_dump_to_stderr (void);
+extern void setup_sched_dumps (void);
extern void block_start (void);
extern void block_finish (void);