Commit 9f33a5d9 by Richard Sandiford Committed by Richard Sandiford

Pass rtx and index to read-md.c iterator routines

The read-md.c iterator callbacks previously used a void * to record the
position at which the iterator value should be installed.  This doesn't
scale easily to the SUBREG_BYTE representation used by a later patch,
so this patch replaces the void * with both an rtx and an operand
number.  The operand number is ignored for modes and codes.

2017-08-21  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	* read-md.h (md_reader::record_potential_iterator_use): Replace
	pointer argument with an rtx and an index.
	* read-rtl.c (iterator_group::apply_iterator): Likewise.
	(apply_mode_iterator): Likewise.
	(apply_code_iterator): Likewise.
	(apply_int_iterator): Likewise.
	(apply_subst_iterator): Likewise.
	(record_iterator_use): Likewise.
	(record_attribute_use): Likewise.
	(md_reader::record_potential_iterator_use): Likewise.  Update calls
	to record_iterator_use and apply_iterator.
	(iterator_use): Replace ptr with x and index.
	(attribute_use): Likewise.
	(apply_attribute_uses): Update calls to apply_iterator.
	(apply_iterators): Likewise.  Update initialization of iterator_use.
	(rtx_reader::read_rtx_code): Update calls to record_iterator_use
	and record_potential_iterator_use.
	(rtx_reader::read_rtx_operand): Likewise.

Co-Authored-By: Alan Hayward <alan.hayward@arm.com>
Co-Authored-By: David Sherwood <david.sherwood@arm.com>

From-SVN: r251219
parent 38fbc003
...@@ -2,6 +2,29 @@ ...@@ -2,6 +2,29 @@
Alan Hayward <alan.hayward@arm.com> Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com> David Sherwood <david.sherwood@arm.com>
* read-md.h (md_reader::record_potential_iterator_use): Replace
pointer argument with an rtx and an index.
* read-rtl.c (iterator_group::apply_iterator): Likewise.
(apply_mode_iterator): Likewise.
(apply_code_iterator): Likewise.
(apply_int_iterator): Likewise.
(apply_subst_iterator): Likewise.
(record_iterator_use): Likewise.
(record_attribute_use): Likewise.
(md_reader::record_potential_iterator_use): Likewise. Update calls
to record_iterator_use and apply_iterator.
(iterator_use): Replace ptr with x and index.
(attribute_use): Likewise.
(apply_attribute_uses): Update calls to apply_iterator.
(apply_iterators): Likewise. Update initialization of iterator_use.
(rtx_reader::read_rtx_code): Update calls to record_iterator_use
and record_potential_iterator_use.
(rtx_reader::read_rtx_operand): Likewise.
2017-08-21 Richard Sandiford <richard.sandiford@linaro.org>
Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com>
* varasm.c (const_rtx_hash_1): Don't hash in the mode of a * varasm.c (const_rtx_hash_1): Don't hash in the mode of a
CONST_WIDE_INT. CONST_WIDE_INT.
......
...@@ -162,7 +162,8 @@ class md_reader ...@@ -162,7 +162,8 @@ class md_reader
rtx copy_rtx_for_iterators (rtx original); rtx copy_rtx_for_iterators (rtx original);
void read_conditions (); void read_conditions ();
void record_potential_iterator_use (struct iterator_group *group, void record_potential_iterator_use (struct iterator_group *group,
void *ptr, const char *name); rtx x, unsigned int index,
const char *name);
struct mapping *read_mapping (struct iterator_group *group, htab_t table); struct mapping *read_mapping (struct iterator_group *group, htab_t table);
const char *get_top_level_filename () const { return m_toplevel_fname; } const char *get_top_level_filename () const { return m_toplevel_fname; }
......
...@@ -76,8 +76,10 @@ struct iterator_group { ...@@ -76,8 +76,10 @@ struct iterator_group {
return its integer value. */ return its integer value. */
int (*find_builtin) (const char *); int (*find_builtin) (const char *);
/* Make the given pointer use the given iterator value. */ /* Make the given rtx use the iterator value given by the third argument.
void (*apply_iterator) (void *, int); If the iterator applies to operands, the second argument gives the
operand index, otherwise it is ignored. */
void (*apply_iterator) (rtx, unsigned int, int);
}; };
/* Records one use of an iterator. */ /* Records one use of an iterator. */
...@@ -85,8 +87,11 @@ struct iterator_use { ...@@ -85,8 +87,11 @@ struct iterator_use {
/* The iterator itself. */ /* The iterator itself. */
struct mapping *iterator; struct mapping *iterator;
/* The location of the use, as passed to the apply_iterator callback. */ /* The location of the use, as passed to the apply_iterator callback.
void *ptr; The index is the number of the operand that used the iterator
if applicable, otherwise it is ignored. */
rtx x;
unsigned int index;
}; };
/* Records one use of an attribute (the "<[iterator:]attribute>" syntax) /* Records one use of an attribute (the "<[iterator:]attribute>" syntax)
...@@ -98,8 +103,11 @@ struct attribute_use { ...@@ -98,8 +103,11 @@ struct attribute_use {
/* The name of the attribute, possibly with an "iterator:" prefix. */ /* The name of the attribute, possibly with an "iterator:" prefix. */
const char *value; const char *value;
/* The location of the use, as passed to GROUP's apply_iterator callback. */ /* The location of the use, as passed to GROUP's apply_iterator callback.
void *ptr; The index is the number of the operand that used the iterator
if applicable, otherwise it is ignored. */
rtx x;
unsigned int index;
}; };
/* This struct is used to link subst_attr named ATTR_NAME with /* This struct is used to link subst_attr named ATTR_NAME with
...@@ -150,9 +158,9 @@ find_mode (const char *name) ...@@ -150,9 +158,9 @@ find_mode (const char *name)
} }
static void static void
apply_mode_iterator (void *loc, int mode) apply_mode_iterator (rtx x, unsigned int, int mode)
{ {
PUT_MODE ((rtx) loc, (machine_mode) mode); PUT_MODE (x, (machine_mode) mode);
} }
/* In compact dumps, the code of insns is prefixed with "c", giving "cinsn", /* In compact dumps, the code of insns is prefixed with "c", giving "cinsn",
...@@ -193,9 +201,9 @@ find_code (const char *name) ...@@ -193,9 +201,9 @@ find_code (const char *name)
} }
static void static void
apply_code_iterator (void *loc, int code) apply_code_iterator (rtx x, unsigned int, int code)
{ {
PUT_CODE ((rtx) loc, (enum rtx_code) code); PUT_CODE (x, (enum rtx_code) code);
} }
/* Implementations of the iterator_group callbacks for ints. */ /* Implementations of the iterator_group callbacks for ints. */
...@@ -212,9 +220,9 @@ find_int (const char *name) ...@@ -212,9 +220,9 @@ find_int (const char *name)
} }
static void static void
apply_int_iterator (void *loc, int value) apply_int_iterator (rtx x, unsigned int index, int value)
{ {
*(int *)loc = value; XINT (x, index) = value;
} }
#ifdef GENERATOR_FILE #ifdef GENERATOR_FILE
...@@ -222,14 +230,13 @@ apply_int_iterator (void *loc, int value) ...@@ -222,14 +230,13 @@ apply_int_iterator (void *loc, int value)
/* This routine adds attribute or does nothing depending on VALUE. When /* This routine adds attribute or does nothing depending on VALUE. When
VALUE is 1, it does nothing - the first duplicate of original VALUE is 1, it does nothing - the first duplicate of original
template is kept untouched when it's subjected to a define_subst. template is kept untouched when it's subjected to a define_subst.
When VALUE isn't 1, the routine modifies RTL-template LOC, adding When VALUE isn't 1, the routine modifies RTL-template RT, adding
attribute, named exactly as define_subst, which later will be attribute, named exactly as define_subst, which later will be
applied. If such attribute has already been added, then no the applied. If such attribute has already been added, then no the
routine has no effect. */ routine has no effect. */
static void static void
apply_subst_iterator (void *loc, int value) apply_subst_iterator (rtx rt, unsigned int, int value)
{ {
rtx rt = (rtx)loc;
rtx new_attr; rtx new_attr;
rtvec attrs_vec, new_attrs_vec; rtvec attrs_vec, new_attrs_vec;
int i; int i;
...@@ -516,7 +523,7 @@ apply_attribute_uses (void) ...@@ -516,7 +523,7 @@ apply_attribute_uses (void)
v = map_attr_string (ause->value); v = map_attr_string (ause->value);
if (!v) if (!v)
fatal_with_file_and_line ("unknown iterator value `%s'", ause->value); fatal_with_file_and_line ("unknown iterator value `%s'", ause->value);
ause->group->apply_iterator (ause->ptr, ause->group->apply_iterator (ause->x, ause->index,
ause->group->find_builtin (v->string)); ause->group->find_builtin (v->string));
} }
} }
...@@ -583,7 +590,8 @@ apply_iterators (rtx original, vec<rtx> *queue) ...@@ -583,7 +590,8 @@ apply_iterators (rtx original, vec<rtx> *queue)
if (iuse->iterator->group == &substs) if (iuse->iterator->group == &substs)
continue; continue;
v = iuse->iterator->current_value; v = iuse->iterator->current_value;
iuse->iterator->group->apply_iterator (iuse->ptr, v->number); iuse->iterator->group->apply_iterator (iuse->x, iuse->index,
v->number);
condition = rtx_reader_ptr->join_c_conditions (condition, v->string); condition = rtx_reader_ptr->join_c_conditions (condition, v->string);
} }
apply_attribute_uses (); apply_attribute_uses ();
...@@ -598,9 +606,11 @@ apply_iterators (rtx original, vec<rtx> *queue) ...@@ -598,9 +606,11 @@ apply_iterators (rtx original, vec<rtx> *queue)
v = iuse->iterator->current_value; v = iuse->iterator->current_value;
if (iuse->iterator->group == &substs) if (iuse->iterator->group == &substs)
{ {
iuse->ptr = x; iuse->x = x;
iuse->index = 0;
current_iterator_name = iuse->iterator->name; current_iterator_name = iuse->iterator->name;
iuse->iterator->group->apply_iterator (iuse->ptr, v->number); iuse->iterator->group->apply_iterator (iuse->x, iuse->index,
v->number);
} }
} }
/* Add the new rtx to the end of the queue. */ /* Add the new rtx to the end of the queue. */
...@@ -860,33 +870,36 @@ validate_const_wide_int (const char *string) ...@@ -860,33 +870,36 @@ validate_const_wide_int (const char *string)
fatal_with_file_and_line ("invalid hex constant \"%s\"\n", string); fatal_with_file_and_line ("invalid hex constant \"%s\"\n", string);
} }
/* Record that PTR uses iterator ITERATOR. */ /* Record that X uses iterator ITERATOR. If the use is in an operand
of X, INDEX is the index of that operand, otherwise it is ignored. */
static void static void
record_iterator_use (struct mapping *iterator, void *ptr) record_iterator_use (struct mapping *iterator, rtx x, unsigned int index)
{ {
struct iterator_use iuse = {iterator, ptr}; struct iterator_use iuse = {iterator, x, index};
iterator_uses.safe_push (iuse); iterator_uses.safe_push (iuse);
} }
/* Record that PTR uses attribute VALUE, which must match a built-in /* Record that X uses attribute VALUE, which must match a built-in
value from group GROUP. */ value from group GROUP. If the use is in an operand of X, INDEX
is the index of that operand, otherwise it is ignored. */
static void static void
record_attribute_use (struct iterator_group *group, void *ptr, record_attribute_use (struct iterator_group *group, rtx x,
const char *value) unsigned int index, const char *value)
{ {
struct attribute_use ause = {group, value, ptr}; struct attribute_use ause = {group, value, x, index};
attribute_uses.safe_push (ause); attribute_uses.safe_push (ause);
} }
/* Interpret NAME as either a built-in value, iterator or attribute /* Interpret NAME as either a built-in value, iterator or attribute
for group GROUP. PTR is the value to pass to GROUP's apply_iterator for group GROUP. X and INDEX are the values to pass to GROUP's
callback. */ apply_iterator callback. */
void void
md_reader::record_potential_iterator_use (struct iterator_group *group, md_reader::record_potential_iterator_use (struct iterator_group *group,
void *ptr, const char *name) rtx x, unsigned int index,
const char *name)
{ {
struct mapping *m; struct mapping *m;
size_t len; size_t len;
...@@ -897,15 +910,16 @@ md_reader::record_potential_iterator_use (struct iterator_group *group, ...@@ -897,15 +910,16 @@ md_reader::record_potential_iterator_use (struct iterator_group *group,
/* Copy the attribute string into permanent storage, without the /* Copy the attribute string into permanent storage, without the
angle brackets around it. */ angle brackets around it. */
obstack_grow0 (&m_string_obstack, name + 1, len - 2); obstack_grow0 (&m_string_obstack, name + 1, len - 2);
record_attribute_use (group, ptr, XOBFINISH (&m_string_obstack, char *)); record_attribute_use (group, x, index,
XOBFINISH (&m_string_obstack, char *));
} }
else else
{ {
m = (struct mapping *) htab_find (group->iterators, &name); m = (struct mapping *) htab_find (group->iterators, &name);
if (m != 0) if (m != 0)
record_iterator_use (m, ptr); record_iterator_use (m, x, index);
else else
group->apply_iterator (ptr, group->find_builtin (name)); group->apply_iterator (x, index, group->find_builtin (name));
} }
} }
...@@ -1288,7 +1302,7 @@ rtx_reader::read_rtx_code (const char *code_name) ...@@ -1288,7 +1302,7 @@ rtx_reader::read_rtx_code (const char *code_name)
} }
if (iterator) if (iterator)
record_iterator_use (iterator, return_rtx); record_iterator_use (iterator, return_rtx, 0);
/* Check for flags. */ /* Check for flags. */
read_flags (return_rtx); read_flags (return_rtx);
...@@ -1317,7 +1331,7 @@ rtx_reader::read_rtx_code (const char *code_name) ...@@ -1317,7 +1331,7 @@ rtx_reader::read_rtx_code (const char *code_name)
if (c == ':') if (c == ':')
{ {
read_name (&name); read_name (&name);
record_potential_iterator_use (&modes, return_rtx, name.string); record_potential_iterator_use (&modes, return_rtx, 0, name.string);
} }
else else
unread_char (c); unread_char (c);
...@@ -1555,7 +1569,7 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx) ...@@ -1555,7 +1569,7 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
m = 0; m = 0;
} }
if (m != 0) if (m != 0)
record_iterator_use (m, return_rtx); record_iterator_use (m, return_rtx, 0);
} }
#endif /* #ifdef GENERATOR_FILE */ #endif /* #ifdef GENERATOR_FILE */
...@@ -1596,8 +1610,7 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx) ...@@ -1596,8 +1610,7 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
case 'n': case 'n':
/* Can be an iterator or an integer constant. */ /* Can be an iterator or an integer constant. */
read_name (&name); read_name (&name);
record_potential_iterator_use (&ints, &XINT (return_rtx, idx), record_potential_iterator_use (&ints, return_rtx, idx, name.string);
name.string);
break; break;
case 'r': case 'r':
......
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