Commit 504279ae by Richard Sandiford Committed by Richard Sandiford

Simplify the implementation of HARD_REG_SET

We have two styles of HARD_REG_SET: a single integer based on
HOST_WIDEST_FAST_INT (used when FIRST_PSEUDO_REGISTER is small enough)
or an array of integers.  One of the nice properties of this arrangement
is that:

  void foo (const HARD_REG_SET);

is passed by value as an integer when the set is small enough and
by reference otherwise.

(This is in constrast to "const HARD_REG_SET &", which would always
be passed by reference, and in contrast to passing a structure wrapper
like "struct s { T elts[1]; }" by value, where the structure might be
passed like a T or by reference, depending on the ABI.)

However, one of the disadvantages of using an array is that simple
assignment doesn't work.  We need to use COPY_HARD_REG_SET instead.

This patch uses a structure wrapper around the array, and preserves
the above "nice property" using a new const_hard_reg_set typedef.
The patch also removes the manual unrolling for small array sizes;
I think these days we can rely on the compiler to do that for us.

This meant fixing two port-specific quirks:

- epiphany passed NULL as a HARD_REG_SET whose value doesn't matter.
  The patch passes the NO_REGS set instead.

- ia64 reused TEST_HARD_REG_BIT and SET_HARD_REG_BIT for arrays that
  are bigger than HARD_REG_SET.  The patch just open-codes them.

The patch is probably being too conservative.  Very few places actually
take advantage of the "nice property" above, and we could have a
cleaner interface if we used a structure wrapper for all cases.

2019-09-09  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* hard-reg-set.h (HARD_REG_SET): Define using a typedef rather
	than a #define.  Use a structure rather than an array as the
	fallback definition.  Remove special cases for low array sizes.
	(const_hard_reg_set): New typedef.
	(hard_reg_set_subset_p): Use it instead of "const HARD_REG_SET".
	(hard_reg_set_equal_p, hard_reg_set_intersect_p): Likewise.
	(hard_reg_set_empty_p): Likewise.
	(SET_HARD_REG_BIT): Use a function rather than a macro to
	handle the case in which HARD_REG_SET is a structure.
	(CLEAR_HARD_REG_BIT, TEST_HARD_REG_BIT, CLEAR_HARD_REG_SET)
	(SET_HARD_REG_SET, COPY_HARD_REG_SET, COMPL_HARD_REG_SET)
	(AND_HARD_REG_SET, AND_COMPL_HARD_REG_SET, IOR_HARD_REG_SET)
	(IOR_COMPL_HARD_REG_SET): Likewise.
	(hard_reg_set_iterator::pset): Constify the pointer target.
	(hard_reg_set_iter_init): Take a const_hard_reg_set instead
	of a "const HARD_REG_SET".  Update the handling of non-integer
	HARD_REG_SETs.
	* recog.h: Test HARD_CONST instead of CLEAR_HARD_REG_SET.
	* reload.h: Likewise.
	* rtl.h (choose_hard_reg_mode): Remove unnecessary line break.
	* regs.h (in_hard_reg_set_p): Take a const_hard_reg_set instead
	of a "const HARD_REG_SET".
	(overlaps_hard_reg_set_p, range_overlaps_hard_reg_set_p): Likewise.
	(range_in_hard_reg_set_p): Likewise.
	* ira-costs.c (restrict_cost_classes): Likewise.
	* shrink-wrap.c (move_insn_for_shrink_wrap): Likewise.
	* config/epiphany/resolve-sw-modes.c (pass_resolve_sw_modes::execute):
	Pass a NO_REGS HARD_REG_SET rather than NULL to emit_set_fp_mode.
	* config/ia64/ia64.c (rws_insn): In the CHECKING_P version,
	use unsigned HOST_WIDEST_FAST_INT rather than HARD_REG_ELT_TYPE.
	(rws_insn_set, rws_insn_test): In the CHECKING_P version,
	take an unsigned int and open-code the HARD_REG_SET operations.

From-SVN: r275526
parent 812b3c62
2019-09-09 Richard Sandiford <richard.sandiford@arm.com> 2019-09-09 Richard Sandiford <richard.sandiford@arm.com>
* hard-reg-set.h (HARD_REG_SET): Define using a typedef rather
than a #define. Use a structure rather than an array as the
fallback definition. Remove special cases for low array sizes.
(const_hard_reg_set): New typedef.
(hard_reg_set_subset_p): Use it instead of "const HARD_REG_SET".
(hard_reg_set_equal_p, hard_reg_set_intersect_p): Likewise.
(hard_reg_set_empty_p): Likewise.
(SET_HARD_REG_BIT): Use a function rather than a macro to
handle the case in which HARD_REG_SET is a structure.
(CLEAR_HARD_REG_BIT, TEST_HARD_REG_BIT, CLEAR_HARD_REG_SET)
(SET_HARD_REG_SET, COPY_HARD_REG_SET, COMPL_HARD_REG_SET)
(AND_HARD_REG_SET, AND_COMPL_HARD_REG_SET, IOR_HARD_REG_SET)
(IOR_COMPL_HARD_REG_SET): Likewise.
(hard_reg_set_iterator::pset): Constify the pointer target.
(hard_reg_set_iter_init): Take a const_hard_reg_set instead
of a "const HARD_REG_SET". Update the handling of non-integer
HARD_REG_SETs.
* recog.h: Test HARD_CONST instead of CLEAR_HARD_REG_SET.
* reload.h: Likewise.
* rtl.h (choose_hard_reg_mode): Remove unnecessary line break.
* regs.h (in_hard_reg_set_p): Take a const_hard_reg_set instead
of a "const HARD_REG_SET".
(overlaps_hard_reg_set_p, range_overlaps_hard_reg_set_p): Likewise.
(range_in_hard_reg_set_p): Likewise.
* ira-costs.c (restrict_cost_classes): Likewise.
* shrink-wrap.c (move_insn_for_shrink_wrap): Likewise.
* config/epiphany/resolve-sw-modes.c (pass_resolve_sw_modes::execute):
Pass a NO_REGS HARD_REG_SET rather than NULL to emit_set_fp_mode.
* config/ia64/ia64.c (rws_insn): In the CHECKING_P version,
use unsigned HOST_WIDEST_FAST_INT rather than HARD_REG_ELT_TYPE.
(rws_insn_set, rws_insn_test): In the CHECKING_P version,
take an unsigned int and open-code the HARD_REG_SET operations.
2019-09-09 Richard Sandiford <richard.sandiford@arm.com>
* Makefile.in (OBJS): Remove bt-load.o. * Makefile.in (OBJS): Remove bt-load.o.
* doc/invoke.texi (fbranch-target-load-optimize): Delete. * doc/invoke.texi (fbranch-target-load-optimize): Delete.
(fbranch-target-load-optimize2, fbtr-bb-exclusive): Likewise. (fbranch-target-load-optimize2, fbtr-bb-exclusive): Likewise.
......
...@@ -167,7 +167,8 @@ pass_resolve_sw_modes::execute (function *fun) ...@@ -167,7 +167,8 @@ pass_resolve_sw_modes::execute (function *fun)
} }
start_sequence (); start_sequence ();
emit_set_fp_mode (EPIPHANY_MSW_ENTITY_ROUND_UNKNOWN, emit_set_fp_mode (EPIPHANY_MSW_ENTITY_ROUND_UNKNOWN,
jilted_mode, FP_MODE_NONE, NULL); jilted_mode, FP_MODE_NONE,
reg_class_contents[NO_REGS]);
seq = get_insns (); seq = get_insns ();
end_sequence (); end_sequence ();
need_commit = true; need_commit = true;
......
...@@ -6230,20 +6230,25 @@ struct reg_write_state ...@@ -6230,20 +6230,25 @@ struct reg_write_state
struct reg_write_state rws_sum[NUM_REGS]; struct reg_write_state rws_sum[NUM_REGS];
#if CHECKING_P #if CHECKING_P
/* Bitmap whether a register has been written in the current insn. */ /* Bitmap whether a register has been written in the current insn. */
HARD_REG_ELT_TYPE rws_insn[(NUM_REGS + HOST_BITS_PER_WIDEST_FAST_INT - 1) unsigned HOST_WIDEST_FAST_INT rws_insn
/ HOST_BITS_PER_WIDEST_FAST_INT]; [(NUM_REGS + HOST_BITS_PER_WIDEST_FAST_INT - 1)
/ HOST_BITS_PER_WIDEST_FAST_INT];
static inline void static inline void
rws_insn_set (int regno) rws_insn_set (unsigned int regno)
{ {
gcc_assert (!TEST_HARD_REG_BIT (rws_insn, regno)); unsigned int elt = regno / HOST_BITS_PER_WIDEST_FAST_INT;
SET_HARD_REG_BIT (rws_insn, regno); unsigned int bit = regno % HOST_BITS_PER_WIDEST_FAST_INT;
gcc_assert (!((rws_insn[elt] >> bit) & 1));
rws_insn[elt] |= (unsigned HOST_WIDEST_FAST_INT) 1 << bit;
} }
static inline int static inline int
rws_insn_test (int regno) rws_insn_test (unsigned int regno)
{ {
return TEST_HARD_REG_BIT (rws_insn, regno); unsigned int elt = regno / HOST_BITS_PER_WIDEST_FAST_INT;
unsigned int bit = regno % HOST_BITS_PER_WIDEST_FAST_INT;
return (rws_insn[elt] >> bit) & 1;
} }
#else #else
/* When not checking, track just REG_AR_CFM and REG_VOLATILE. */ /* When not checking, track just REG_AR_CFM and REG_VOLATILE. */
......
...@@ -237,7 +237,7 @@ setup_cost_classes (cost_classes_t from) ...@@ -237,7 +237,7 @@ setup_cost_classes (cost_classes_t from)
allocated. */ allocated. */
static cost_classes_t static cost_classes_t
restrict_cost_classes (cost_classes_t full, machine_mode mode, restrict_cost_classes (cost_classes_t full, machine_mode mode,
const HARD_REG_SET &regs) const_hard_reg_set regs)
{ {
static struct cost_classes narrow; static struct cost_classes narrow;
int map[N_REG_CLASSES]; int map[N_REG_CLASSES];
......
...@@ -142,7 +142,7 @@ extern void preprocess_constraints (rtx_insn *); ...@@ -142,7 +142,7 @@ extern void preprocess_constraints (rtx_insn *);
extern rtx_insn *peep2_next_insn (int); extern rtx_insn *peep2_next_insn (int);
extern int peep2_regno_dead_p (int, int); extern int peep2_regno_dead_p (int, int);
extern int peep2_reg_dead_p (int, rtx); extern int peep2_reg_dead_p (int, rtx);
#ifdef CLEAR_HARD_REG_SET #ifdef HARD_CONST
extern rtx peep2_find_free_register (int, int, const char *, extern rtx peep2_find_free_register (int, int, const char *,
machine_mode, HARD_REG_SET *); machine_mode, HARD_REG_SET *);
#endif #endif
......
...@@ -298,7 +298,7 @@ remove_from_hard_reg_set (HARD_REG_SET *regs, machine_mode mode, ...@@ -298,7 +298,7 @@ remove_from_hard_reg_set (HARD_REG_SET *regs, machine_mode mode,
/* Return true if REGS contains the whole of (reg:MODE REGNO). */ /* Return true if REGS contains the whole of (reg:MODE REGNO). */
static inline bool static inline bool
in_hard_reg_set_p (const HARD_REG_SET regs, machine_mode mode, in_hard_reg_set_p (const_hard_reg_set regs, machine_mode mode,
unsigned int regno) unsigned int regno)
{ {
unsigned int end_regno; unsigned int end_regno;
...@@ -323,7 +323,7 @@ in_hard_reg_set_p (const HARD_REG_SET regs, machine_mode mode, ...@@ -323,7 +323,7 @@ in_hard_reg_set_p (const HARD_REG_SET regs, machine_mode mode,
/* Return true if (reg:MODE REGNO) includes an element of REGS. */ /* Return true if (reg:MODE REGNO) includes an element of REGS. */
static inline bool static inline bool
overlaps_hard_reg_set_p (const HARD_REG_SET regs, machine_mode mode, overlaps_hard_reg_set_p (const_hard_reg_set regs, machine_mode mode,
unsigned int regno) unsigned int regno)
{ {
unsigned int end_regno; unsigned int end_regno;
...@@ -363,7 +363,7 @@ remove_range_from_hard_reg_set (HARD_REG_SET *regs, unsigned int regno, ...@@ -363,7 +363,7 @@ remove_range_from_hard_reg_set (HARD_REG_SET *regs, unsigned int regno,
/* Like overlaps_hard_reg_set_p, but use a REGNO/NREGS range instead of /* Like overlaps_hard_reg_set_p, but use a REGNO/NREGS range instead of
REGNO and MODE. */ REGNO and MODE. */
static inline bool static inline bool
range_overlaps_hard_reg_set_p (const HARD_REG_SET set, unsigned regno, range_overlaps_hard_reg_set_p (const_hard_reg_set set, unsigned regno,
int nregs) int nregs)
{ {
while (nregs-- > 0) while (nregs-- > 0)
...@@ -375,7 +375,7 @@ range_overlaps_hard_reg_set_p (const HARD_REG_SET set, unsigned regno, ...@@ -375,7 +375,7 @@ range_overlaps_hard_reg_set_p (const HARD_REG_SET set, unsigned regno,
/* Like in_hard_reg_set_p, but use a REGNO/NREGS range instead of /* Like in_hard_reg_set_p, but use a REGNO/NREGS range instead of
REGNO and MODE. */ REGNO and MODE. */
static inline bool static inline bool
range_in_hard_reg_set_p (const HARD_REG_SET set, unsigned regno, int nregs) range_in_hard_reg_set_p (const_hard_reg_set set, unsigned regno, int nregs)
{ {
while (nregs-- > 0) while (nregs-- > 0)
if (!TEST_HARD_REG_BIT (set, regno + nregs)) if (!TEST_HARD_REG_BIT (set, regno + nregs))
......
...@@ -274,7 +274,7 @@ extern int reload_first_uid; ...@@ -274,7 +274,7 @@ extern int reload_first_uid;
extern int num_not_at_initial_offset; extern int num_not_at_initial_offset;
#if defined SET_HARD_REG_BIT && defined CLEAR_REG_SET #if defined HARD_CONST && defined CLEAR_REG_SET
/* This structure describes instructions which are relevant for reload. /* This structure describes instructions which are relevant for reload.
Apart from all regular insns, this also includes CODE_LABELs, since they Apart from all regular insns, this also includes CODE_LABELs, since they
must be examined for register elimination. */ must be examined for register elimination. */
...@@ -326,7 +326,7 @@ extern class insn_chain *reload_insn_chain; ...@@ -326,7 +326,7 @@ extern class insn_chain *reload_insn_chain;
extern class insn_chain *new_insn_chain (void); extern class insn_chain *new_insn_chain (void);
#endif #endif
#if defined SET_HARD_REG_BIT #if defined HARD_CONST
extern void compute_use_by_pseudos (HARD_REG_SET *, bitmap); extern void compute_use_by_pseudos (HARD_REG_SET *, bitmap);
#endif #endif
......
...@@ -3377,8 +3377,7 @@ extern bool val_signbit_known_clear_p (machine_mode, ...@@ -3377,8 +3377,7 @@ extern bool val_signbit_known_clear_p (machine_mode,
unsigned HOST_WIDE_INT); unsigned HOST_WIDE_INT);
/* In reginfo.c */ /* In reginfo.c */
extern machine_mode choose_hard_reg_mode (unsigned int, unsigned int, extern machine_mode choose_hard_reg_mode (unsigned int, unsigned int, bool);
bool);
extern const HARD_REG_SET &simplifiable_subregs (const subreg_shape &); extern const HARD_REG_SET &simplifiable_subregs (const subreg_shape &);
/* In emit-rtl.c */ /* In emit-rtl.c */
......
...@@ -151,8 +151,8 @@ live_edge_for_reg (basic_block bb, int regno, int end_regno) ...@@ -151,8 +151,8 @@ live_edge_for_reg (basic_block bb, int regno, int end_regno)
static bool static bool
move_insn_for_shrink_wrap (basic_block bb, rtx_insn *insn, move_insn_for_shrink_wrap (basic_block bb, rtx_insn *insn,
const HARD_REG_SET uses, const_hard_reg_set uses,
const HARD_REG_SET defs, const_hard_reg_set defs,
bool *split_p, bool *split_p,
struct dead_debug_local *debug) struct dead_debug_local *debug)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment