md.texi: Document define_subst.
* doc/md.texi: Document define_subst. * gensupport.c (MAX_OPERANDS): New define. (operand_data): New. (match_operand_entries_in_pattern): New. (used_operands_numbers): New. (subst_true): New. (subst_false): New. (define_subst_queue): New. (define_subst_tail): New. (define_subst_attr_queue): New. (define_subst_attr_tail): New. (has_subst_attribute): New. (subst_pattern_match): New. (get_alternatives_number): New. (alter_output_for_subst_insn): New. (alter_attrs_for_subst_insn): New. (process_substs_on_one_elem): New. (subst_dup): New. (process_define_subst): New. (duplicate_alternatives): New. (duplicate_each_alternative): New. (constraints_handler_t): New typedef. (alter_constraints): New. (adjust_operands_numbers): New. (replace_duplicating_operands_in_pattern): New. (remove_from_queue): New. (process_rtx): Handle define_subst and define_subst_attr. (change_subst_attribute): New. (alter_predicate_for_insn): Fix formatting. (alter_attrs_for_insn): Likewise. (alter_output_for_insn): Likewise. (mark_operands_from_match_dup): New. (mark_operands_used_in_match_dup): New. (find_first_unused_number_of_operand): New. (renumerate_operands_in_pattern): New. (generate_match_dup): New. (check_define_attr_duplicates): New. (init_rtx_reader_args_cb): Add checking for duplicated attrs and processing of define_subst. (read_md_rtx): Handle define_subst. * read-rtl.c (struct subst_attr_to_iter_mapping): New. (substs): New global. (apply_subst_iterator): New. (bind_subst_iter_and_attr): New. (find_subst_iter_by_attr): New. (map_attr_string): Handle subst-iterators. (add_condition_to_rtx): Handle define_subst. (apply_iterators): Likewise. (initialize_iterators): Likewise. (add_define_attr_for_define_subst): New. (add_define_subst_attr): New. (read_subst_mapping): New. (read_rtx): Handle define_subst_attr. (read_rtx_code): Add subst-attributes recognition during reading of strings. * rtl.def (DEFINE_EXPAND): Add vector of attributes. (DEFINE_SUBST): New. (DEFINE_SUBST_ATTR): New. Co-Authored-By: Kirill Yukhin <kirill.yukhin@intel.com> Co-Authored-By: Michael Zolotukhin <michael.v.zolotukhin@intel.com> From-SVN: r193618
This commit is contained in:
parent
d826d5c209
commit
477c104eaf
5 changed files with 1710 additions and 15 deletions
|
@ -1,3 +1,66 @@
|
|||
2012-11-19 Maxim Kuznetsov <maxim.kuznetsov@intel.com>
|
||||
Kirill Yukhin <kirill.yukhin@intel.com>
|
||||
Michael Zolotukhin <michael.v.zolotukhin@intel.com>
|
||||
|
||||
* doc/md.texi: Document define_subst.
|
||||
* gensupport.c (MAX_OPERANDS): New define.
|
||||
(operand_data): New.
|
||||
(match_operand_entries_in_pattern): New.
|
||||
(used_operands_numbers): New.
|
||||
(subst_true): New.
|
||||
(subst_false): New.
|
||||
(define_subst_queue): New.
|
||||
(define_subst_tail): New.
|
||||
(define_subst_attr_queue): New.
|
||||
(define_subst_attr_tail): New.
|
||||
(has_subst_attribute): New.
|
||||
(subst_pattern_match): New.
|
||||
(get_alternatives_number): New.
|
||||
(alter_output_for_subst_insn): New.
|
||||
(alter_attrs_for_subst_insn): New.
|
||||
(process_substs_on_one_elem): New.
|
||||
(subst_dup): New.
|
||||
(process_define_subst): New.
|
||||
(duplicate_alternatives): New.
|
||||
(duplicate_each_alternative): New.
|
||||
(constraints_handler_t): New typedef.
|
||||
(alter_constraints): New.
|
||||
(adjust_operands_numbers): New.
|
||||
(replace_duplicating_operands_in_pattern): New.
|
||||
(remove_from_queue): New.
|
||||
(process_rtx): Handle define_subst and define_subst_attr.
|
||||
(change_subst_attribute): New.
|
||||
(alter_predicate_for_insn): Fix formatting.
|
||||
(alter_attrs_for_insn): Likewise.
|
||||
(alter_output_for_insn): Likewise.
|
||||
(mark_operands_from_match_dup): New.
|
||||
(mark_operands_used_in_match_dup): New.
|
||||
(find_first_unused_number_of_operand): New.
|
||||
(renumerate_operands_in_pattern): New.
|
||||
(generate_match_dup): New.
|
||||
(check_define_attr_duplicates): New.
|
||||
(init_rtx_reader_args_cb): Add checking for duplicated attrs and
|
||||
processing of define_subst.
|
||||
(read_md_rtx): Handle define_subst.
|
||||
* read-rtl.c (struct subst_attr_to_iter_mapping): New.
|
||||
(substs): New global.
|
||||
(apply_subst_iterator): New.
|
||||
(bind_subst_iter_and_attr): New.
|
||||
(find_subst_iter_by_attr): New.
|
||||
(map_attr_string): Handle subst-iterators.
|
||||
(add_condition_to_rtx): Handle define_subst.
|
||||
(apply_iterators): Likewise.
|
||||
(initialize_iterators): Likewise.
|
||||
(add_define_attr_for_define_subst): New.
|
||||
(add_define_subst_attr): New.
|
||||
(read_subst_mapping): New.
|
||||
(read_rtx): Handle define_subst_attr.
|
||||
(read_rtx_code): Add subst-attributes recognition during reading of
|
||||
strings.
|
||||
* rtl.def (DEFINE_EXPAND): Add vector of attributes.
|
||||
(DEFINE_SUBST): New.
|
||||
(DEFINE_SUBST_ATTR): New.
|
||||
|
||||
2012-11-19 Tom de Vries <tom@codesourcery.com>
|
||||
|
||||
PR rtl-optimization/55315
|
||||
|
|
261
gcc/doc/md.texi
261
gcc/doc/md.texi
|
@ -46,6 +46,8 @@ See the next chapter for information on the C header file.
|
|||
* Insn Attributes:: Specifying the value of attributes for generated insns.
|
||||
* Conditional Execution::Generating @code{define_insn} patterns for
|
||||
predication.
|
||||
* Define Subst:: Generating @code{define_insn} and @code{define_expand}
|
||||
patterns from other patterns.
|
||||
* Constant Definitions::Defining symbolic constants that can be used in the
|
||||
md file.
|
||||
* Iterators:: Using iterators to generate patterns from a template.
|
||||
|
@ -6756,6 +6758,10 @@ Usually these statements prepare temporary registers for use as
|
|||
internal operands in the RTL template, but they can also generate RTL
|
||||
insns directly by calling routines such as @code{emit_insn}, etc.
|
||||
Any such insns precede the ones that come from the RTL template.
|
||||
|
||||
@item
|
||||
Optionally, a vector containing the values of attributes. @xref{Insn
|
||||
Attributes}.
|
||||
@end itemize
|
||||
|
||||
Every RTL insn emitted by a @code{define_expand} must match some
|
||||
|
@ -8893,6 +8899,213 @@ generates a new pattern
|
|||
@end smallexample
|
||||
|
||||
@end ifset
|
||||
@ifset INTERNALS
|
||||
@node Define Subst
|
||||
@section RTL Templates Transformations
|
||||
@cindex define_subst
|
||||
|
||||
For some hardware architectures there are common cases when the RTL
|
||||
templates for the instructions can be derived from the other RTL
|
||||
templates using simple transformations. E.g., @file{i386.md} contains
|
||||
an RTL template for the ordinary @code{sub} instruction---
|
||||
@code{*subsi_1}, and for the @code{sub} instruction with subsequent
|
||||
zero-extension---@code{*subsi_1_zext}. Such cases can be easily
|
||||
implemented by a single meta-template capable of generating a modified
|
||||
case based on the initial one:
|
||||
|
||||
@findex define_subst
|
||||
@smallexample
|
||||
(define_subst "@var{name}"
|
||||
[@var{input-template}]
|
||||
"@var{condition}"
|
||||
[@var{output-template}])
|
||||
@end smallexample
|
||||
@var{input-template} is a pattern describing the source RTL template,
|
||||
which will be transformed.
|
||||
|
||||
@var{condition} is a C expression that is conjunct with the condition
|
||||
from the input-template to generate a condition to be used in the
|
||||
output-template.
|
||||
|
||||
@var{output-template} is a pattern that will be used in the resulting
|
||||
template.
|
||||
|
||||
@code{define_subst} mechanism is tightly coupled with the notion of the
|
||||
subst attribute (@xref{Subst Iterators}). The use of
|
||||
@code{define_subst} is triggered by a reference to a subst attribute in
|
||||
the transforming RTL template. This reference initiates duplication of
|
||||
the source RTL template and substitution of the attributes with their
|
||||
values. The source RTL template is left unchanged, while the copy is
|
||||
transformed by @code{define_subst}. This transformation can fail in the
|
||||
case when the source RTL template is not matched against the
|
||||
input-template of the @code{define_subst}. In such case the copy is
|
||||
deleted.
|
||||
|
||||
@code{define_subst} can be used only in @code{define_insn} and
|
||||
@code{define_expand}, it cannot be used in other expressions (e.g. in
|
||||
@code{define_insn_and_split}).
|
||||
|
||||
@menu
|
||||
* Define Subst Example:: Example of @code{define_subst} work.
|
||||
* Define Subst Pattern Matching:: Process of template comparison.
|
||||
* Define Subst Output Template:: Generation of output template.
|
||||
@end menu
|
||||
|
||||
@node Define Subst Example
|
||||
@subsection @code{define_subst} Example
|
||||
@cindex define_subst
|
||||
|
||||
To illustrate how @code{define_subst} works, let us examine a simple
|
||||
template transformation.
|
||||
|
||||
Suppose there are two kinds of instructions: one that touches flags and
|
||||
the other that does not. The instructions of the second type could be
|
||||
generated with the following @code{define_subst}:
|
||||
|
||||
@smallexample
|
||||
(define_subst "add_clobber_subst"
|
||||
[(set (match_operand:SI 0 "" "")
|
||||
(match_operand:SI 1 "" ""))]
|
||||
""
|
||||
[(set (match_dup 0)
|
||||
(match_dup 1))
|
||||
(clobber (reg:CC FLAGS_REG))]
|
||||
@end smallexample
|
||||
|
||||
This @code{define_subst} can be applied to any RTL pattern containing
|
||||
@code{set} of mode SI and generates a copy with clobber when it is
|
||||
applied.
|
||||
|
||||
Assume there is an RTL template for a @code{max} instruction to be used
|
||||
in @code{define_subst} mentioned above:
|
||||
|
||||
@smallexample
|
||||
(define_insn "maxsi"
|
||||
[(set (match_operand:SI 0 "register_operand" "=r")
|
||||
(max:SI
|
||||
(match_operand:SI 1 "register_operand" "r")
|
||||
(match_operand:SI 2 "register_operand" "r")))]
|
||||
""
|
||||
"max\t@{%2, %1, %0|%0, %1, %2@}"
|
||||
[@dots{}])
|
||||
@end smallexample
|
||||
|
||||
To mark the RTL template for @code{define_subst} application,
|
||||
subst-attributes are used. They should be declared in advance:
|
||||
|
||||
@smallexample
|
||||
(define_subst_attr "add_clobber_name" "add_clobber_subst" "_noclobber" "_clobber")
|
||||
@end smallexample
|
||||
|
||||
Here @samp{add_clobber_name} is the attribute name,
|
||||
@samp{add_clobber_subst} is the name of the corresponding
|
||||
@code{define_subst}, the third argument (@samp{_noclobber}) is the
|
||||
attribute value that would be substituted into the unchanged version of
|
||||
the source RTL template, and the last argument (@samp{_clobber}) is the
|
||||
value that would be substituted into the second, transformed,
|
||||
version of the RTL template.
|
||||
|
||||
Once the subst-attribute has been defined, it should be used in RTL
|
||||
templates which need to be processed by the @code{define_subst}. So,
|
||||
the original RTL template should be changed:
|
||||
|
||||
@smallexample
|
||||
(define_insn "maxsi<add_clobber_name>"
|
||||
[(set (match_operand:SI 0 "register_operand" "=r")
|
||||
(max:SI
|
||||
(match_operand:SI 1 "register_operand" "r")
|
||||
(match_operand:SI 2 "register_operand" "r")))]
|
||||
""
|
||||
"max\t@{%2, %1, %0|%0, %1, %2@}"
|
||||
[@dots{}])
|
||||
@end smallexample
|
||||
|
||||
The result of the @code{define_subst} usage would look like the following:
|
||||
|
||||
@smallexample
|
||||
(define_insn "maxsi_noclobber"
|
||||
[(set (match_operand:SI 0 "register_operand" "=r")
|
||||
(max:SI
|
||||
(match_operand:SI 1 "register_operand" "r")
|
||||
(match_operand:SI 2 "register_operand" "r")))]
|
||||
""
|
||||
"max\t@{%2, %1, %0|%0, %1, %2@}"
|
||||
[@dots{}])
|
||||
(define_insn "maxsi_clobber"
|
||||
[(set (match_operand:SI 0 "register_operand" "=r")
|
||||
(max:SI
|
||||
(match_operand:SI 1 "register_operand" "r")
|
||||
(match_operand:SI 2 "register_operand" "r")))
|
||||
(clobber (reg:CC FLAGS_REG))]
|
||||
""
|
||||
"max\t@{%2, %1, %0|%0, %1, %2@}"
|
||||
[@dots{}])
|
||||
@end smallexample
|
||||
|
||||
@node Define Subst Pattern Matching
|
||||
@subsection Pattern Matching in @code{define_subst}
|
||||
@cindex define_subst
|
||||
|
||||
All expressions, allowed in @code{define_insn} or @code{define_expand},
|
||||
are allowed in the input-template of @code{define_subst}, except
|
||||
@code{match_par_dup}, @code{match_scratch}, @code{match_parallel}. The
|
||||
meanings of expressions in the input-template were changed:
|
||||
|
||||
@code{match_operand} matches any expression (possibly, a subtree in
|
||||
RTL-template), if modes of the @code{match_operand} and this expression
|
||||
are the same, or mode of the @code{match_operand} is @code{VOIDmode}, or
|
||||
this expression is @code{match_dup}, @code{match_op_dup}. If the
|
||||
expression is @code{match_operand} too, and predicate of
|
||||
@code{match_operand} from the input pattern is not empty, then the
|
||||
predicates are compared. That can be used for more accurate filtering
|
||||
of accepted RTL-templates.
|
||||
|
||||
@code{match_operator} matches common operators (like @code{plus},
|
||||
@code{minus}), @code{unspec}, @code{unspec_volatile} operators and
|
||||
@code{match_operator}s from the original pattern if the modes match and
|
||||
@code{match_operator} from the input pattern has the same number of
|
||||
operands as the operator from the original pattern.
|
||||
|
||||
@node Define Subst Output Template
|
||||
@subsection Generation of output template in @code{define_subst}
|
||||
@cindex define_subst
|
||||
|
||||
If all necessary checks for @code{define_subst} application pass, a new
|
||||
RTL-pattern, based on the output-template, is created to replace the old
|
||||
template. Like in input-patterns, meanings of some RTL expressions are
|
||||
changed when they are used in output-patterns of a @code{define_subst}.
|
||||
Thus, @code{match_dup} is used for copying the whole expression from the
|
||||
original pattern, which matched corresponding @code{match_operand} from
|
||||
the input pattern.
|
||||
|
||||
@code{match_dup N} is used in the output template to be replaced with
|
||||
the expression from the original pattern, which matched
|
||||
@code{match_operand N} from the input pattern. As a consequence,
|
||||
@code{match_dup} cannot be used to point to @code{match_operand}s from
|
||||
the output pattern, it should always refer to a @code{match_operand}
|
||||
from the input pattern.
|
||||
|
||||
In the output template one can refer to the expressions from the
|
||||
original pattern and create new ones. For instance, some operands could
|
||||
be added by means of standard @code{match_operand}.
|
||||
|
||||
After replacing @code{match_dup} with some RTL-subtree from the original
|
||||
pattern, it could happen that several @code{match_operand}s in the
|
||||
output pattern have the same indexes. It is unknown, how many and what
|
||||
indexes would be used in the expression which would replace
|
||||
@code{match_dup}, so such conflicts in indexes are inevitable. To
|
||||
overcome this issue, @code{match_operands} and @code{match_operators},
|
||||
which were introduced into the output pattern, are renumerated when all
|
||||
@code{match_dup}s are replaced.
|
||||
|
||||
Number of alternatives in @code{match_operand}s introduced into the
|
||||
output template @code{M} could differ from the number of alternatives in
|
||||
the original pattern @code{N}, so in the resultant pattern there would
|
||||
be @code{N*M} alternatives. Thus, constraints from the original pattern
|
||||
would be duplicated @code{N} times, constraints from the output pattern
|
||||
would be duplicated @code{M} times, producing all possible combinations.
|
||||
@end ifset
|
||||
|
||||
@ifset INTERNALS
|
||||
@node Constant Definitions
|
||||
@section Constant Definitions
|
||||
|
@ -9077,6 +9290,7 @@ facilities to make this process easier.
|
|||
* Mode Iterators:: Generating variations of patterns for different modes.
|
||||
* Code Iterators:: Doing the same for codes.
|
||||
* Int Iterators:: Doing the same for integers.
|
||||
* Subst Iterators:: Generating variations of patterns for define_subst.
|
||||
@end menu
|
||||
|
||||
@node Mode Iterators
|
||||
|
@ -9425,4 +9639,51 @@ This is equivalent to:
|
|||
|
||||
@end smallexample
|
||||
|
||||
@node Subst Iterators
|
||||
@subsection Subst Iterators
|
||||
@cindex subst iterators in @file{.md} files
|
||||
@findex define_subst
|
||||
@findex define_subst_attr
|
||||
|
||||
Subst iterators are special type of iterators with the following
|
||||
restrictions: they could not be declared explicitly, they always have
|
||||
only two values, and they do not have explicit dedicated name.
|
||||
Subst-iterators are triggered only when corresponding subst-attribute is
|
||||
used in RTL-pattern.
|
||||
|
||||
Subst iterators transform templates in the following way: the templates
|
||||
are duplicated, the subst-attributes in these templates are replaced
|
||||
with the corresponding values, and a new attribute is implicitly added
|
||||
to the given @code{define_insn}/@code{define_expand}. The name of the
|
||||
added attribute matches the name of @code{define_subst}. Such
|
||||
attributes are declared implicitly, and it is not allowed to have a
|
||||
@code{define_attr} named as a @code{define_subst}.
|
||||
|
||||
Each subst iterator is linked to a @code{define_subst}. It is declared
|
||||
implicitly by the first appearance of the corresponding
|
||||
@code{define_subst_attr}, and it is not allowed to define it explicitly.
|
||||
|
||||
Declarations of subst-attributes have the following syntax:
|
||||
|
||||
@findex define_subst_attr
|
||||
@smallexample
|
||||
(define_subst_attr "@var{name}"
|
||||
"@var{subst-name}"
|
||||
"@var{no-subst-value}"
|
||||
"@var{subst-applied-value}")
|
||||
@end smallexample
|
||||
|
||||
@var{name} is a string with which the given subst-attribute could be
|
||||
referred to.
|
||||
|
||||
@var{subst-name} shows which @code{define_subst} should be applied to an
|
||||
RTL-template if the given subst-attribute is present in the
|
||||
RTL-template.
|
||||
|
||||
@var{no-subst-value} is a value with which subst-attribute would be
|
||||
replaced in the first copy of the original RTL-template.
|
||||
|
||||
@var{subst-applied-value} is a value with which subst-attribute would be
|
||||
replaced in the second copy of the original RTL-template.
|
||||
|
||||
@end ifset
|
||||
|
|
1117
gcc/gensupport.c
1117
gcc/gensupport.c
File diff suppressed because it is too large
Load diff
277
gcc/read-rtl.c
277
gcc/read-rtl.c
|
@ -102,13 +102,28 @@ struct attribute_use {
|
|||
/* Vector definitions for the above. */
|
||||
typedef struct attribute_use attribute_use;
|
||||
|
||||
/* This struct is used to link subst_attr named ATTR_NAME with
|
||||
corresponding define_subst named ITER_NAME. */
|
||||
struct subst_attr_to_iter_mapping
|
||||
{
|
||||
char *attr_name;
|
||||
char *iter_name;
|
||||
};
|
||||
|
||||
/* Hash-table to store links between subst-attributes and
|
||||
define_substs. */
|
||||
htab_t subst_attr_to_iter_map = NULL;
|
||||
/* This global stores name of subst-iterator which is currently being
|
||||
processed. */
|
||||
const char *current_iterator_name;
|
||||
|
||||
static void validate_const_int (const char *);
|
||||
static rtx read_rtx_code (const char *);
|
||||
static rtx read_nested_rtx (void);
|
||||
static rtx read_rtx_variadic (rtx);
|
||||
|
||||
/* The mode and code iterator structures. */
|
||||
static struct iterator_group modes, codes, ints;
|
||||
static struct iterator_group modes, codes, ints, substs;
|
||||
|
||||
/* All iterators used in the current rtx. */
|
||||
static vec<mapping_ptr> current_iterators;
|
||||
|
@ -178,6 +193,91 @@ apply_int_iterator (void *loc, int value)
|
|||
*(int *)loc = value;
|
||||
}
|
||||
|
||||
/* This routine adds attribute or does nothing depending on VALUE. When
|
||||
VALUE is 1, it does nothing - the first duplicate of original
|
||||
template is kept untouched when it's subjected to a define_subst.
|
||||
When VALUE isn't 1, the routine modifies RTL-template LOC, adding
|
||||
attribute, named exactly as define_subst, which later will be
|
||||
applied. If such attribute has already been added, then no the
|
||||
routine has no effect. */
|
||||
static void
|
||||
apply_subst_iterator (void *loc, int value)
|
||||
{
|
||||
rtx rt = (rtx)loc;
|
||||
rtx new_attr;
|
||||
rtvec attrs_vec, new_attrs_vec;
|
||||
int i;
|
||||
if (value == 1)
|
||||
return;
|
||||
gcc_assert (GET_CODE (rt) == DEFINE_INSN
|
||||
|| GET_CODE (rt) == DEFINE_EXPAND);
|
||||
|
||||
attrs_vec = XVEC (rt, 4);
|
||||
|
||||
/* If we've already added attribute 'current_iterator_name', then we
|
||||
have nothing to do now. */
|
||||
if (attrs_vec)
|
||||
{
|
||||
for (i = 0; i < GET_NUM_ELEM (attrs_vec); i++)
|
||||
{
|
||||
if (strcmp (XSTR (attrs_vec->elem[i], 0), current_iterator_name) == 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add attribute with subst name - it serves as a mark for
|
||||
define_subst which later would be applied to this pattern. */
|
||||
new_attr = rtx_alloc (SET_ATTR);
|
||||
PUT_CODE (new_attr, SET_ATTR);
|
||||
XSTR (new_attr, 0) = xstrdup (current_iterator_name);
|
||||
XSTR (new_attr, 1) = xstrdup ("yes");
|
||||
|
||||
if (!attrs_vec)
|
||||
{
|
||||
new_attrs_vec = rtvec_alloc (1);
|
||||
new_attrs_vec->elem[0] = new_attr;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_attrs_vec = rtvec_alloc (GET_NUM_ELEM (attrs_vec) + 1);
|
||||
memcpy (&new_attrs_vec->elem[0], &attrs_vec->elem[0],
|
||||
GET_NUM_ELEM (attrs_vec) * sizeof (rtx));
|
||||
new_attrs_vec->elem[GET_NUM_ELEM (attrs_vec)] = new_attr;
|
||||
}
|
||||
XVEC (rt, 4) = new_attrs_vec;
|
||||
}
|
||||
|
||||
/* Map subst-attribute ATTR to subst iterator ITER. */
|
||||
|
||||
static void
|
||||
bind_subst_iter_and_attr (const char *iter, const char *attr)
|
||||
{
|
||||
struct subst_attr_to_iter_mapping *value;
|
||||
void **slot;
|
||||
if (!subst_attr_to_iter_map)
|
||||
subst_attr_to_iter_map =
|
||||
htab_create (1, leading_string_hash, leading_string_eq_p, 0);
|
||||
value = XNEW (struct subst_attr_to_iter_mapping);
|
||||
value->attr_name = xstrdup (attr);
|
||||
value->iter_name = xstrdup (iter);
|
||||
slot = htab_find_slot (subst_attr_to_iter_map, value, INSERT);
|
||||
*slot = value;
|
||||
}
|
||||
|
||||
/* Return name of a subst-iterator, corresponding to subst-attribute ATTR. */
|
||||
|
||||
static char*
|
||||
find_subst_iter_by_attr (const char *attr)
|
||||
{
|
||||
char *iter_name = NULL;
|
||||
struct subst_attr_to_iter_mapping *value;
|
||||
value = (struct subst_attr_to_iter_mapping*)
|
||||
htab_find (subst_attr_to_iter_map, &attr);
|
||||
if (value)
|
||||
iter_name = value->iter_name;
|
||||
return iter_name;
|
||||
}
|
||||
|
||||
/* Map attribute string P to its current value. Return null if the attribute
|
||||
isn't known. */
|
||||
|
||||
|
@ -216,11 +316,23 @@ map_attr_string (const char *p)
|
|||
/* Find the attribute specification. */
|
||||
m = (struct mapping *) htab_find (iterator->group->attrs, &attr);
|
||||
if (m)
|
||||
/* Find the attribute value associated with the current
|
||||
iterator value. */
|
||||
for (v = m->values; v; v = v->next)
|
||||
if (v->number == iterator->current_value->number)
|
||||
return v;
|
||||
{
|
||||
/* In contrast to code/mode/int iterators, attributes of subst
|
||||
iterators are linked to one specific subst-iterator. So, if
|
||||
we are dealing with subst-iterator, we should check if it's
|
||||
the one which linked with the given attribute. */
|
||||
if (iterator->group == &substs)
|
||||
{
|
||||
char *iter_name = find_subst_iter_by_attr (attr);
|
||||
if (strcmp (iter_name, iterator->name) != 0)
|
||||
continue;
|
||||
}
|
||||
/* Find the attribute value associated with the current
|
||||
iterator value. */
|
||||
for (v = m->values; v; v = v->next)
|
||||
if (v->number == iterator->current_value->number)
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -337,6 +449,7 @@ add_condition_to_rtx (rtx x, const char *extra)
|
|||
{
|
||||
case DEFINE_INSN:
|
||||
case DEFINE_EXPAND:
|
||||
case DEFINE_SUBST:
|
||||
XSTR (x, 2) = add_condition_to_string (XSTR (x, 2), extra);
|
||||
break;
|
||||
|
||||
|
@ -426,6 +539,7 @@ apply_iterators (rtx original, rtx *queue)
|
|||
htab_traverse (modes.iterators, add_current_iterators, NULL);
|
||||
htab_traverse (codes.iterators, add_current_iterators, NULL);
|
||||
htab_traverse (ints.iterators, add_current_iterators, NULL);
|
||||
htab_traverse (substs.iterators, add_current_iterators, NULL);
|
||||
gcc_assert (!current_iterators.is_empty ());
|
||||
|
||||
for (;;)
|
||||
|
@ -435,6 +549,8 @@ apply_iterators (rtx original, rtx *queue)
|
|||
condition = NULL;
|
||||
FOR_EACH_VEC_ELT (iterator_uses, i, iuse)
|
||||
{
|
||||
if (iuse->iterator->group == &substs)
|
||||
continue;
|
||||
v = iuse->iterator->current_value;
|
||||
iuse->iterator->group->apply_iterator (iuse->ptr, v->number);
|
||||
condition = join_c_conditions (condition, v->string);
|
||||
|
@ -443,6 +559,19 @@ apply_iterators (rtx original, rtx *queue)
|
|||
x = copy_rtx_for_iterators (original);
|
||||
add_condition_to_rtx (x, condition);
|
||||
|
||||
/* We apply subst iterator after RTL-template is copied, as during
|
||||
subst-iterator processing, we could add an attribute to the
|
||||
RTL-template, and we don't want to do it in the original one. */
|
||||
FOR_EACH_VEC_ELT (iterator_uses, i, iuse)
|
||||
{
|
||||
v = iuse->iterator->current_value;
|
||||
if (iuse->iterator->group == &substs)
|
||||
{
|
||||
iuse->ptr = x;
|
||||
current_iterator_name = iuse->iterator->name;
|
||||
iuse->iterator->group->apply_iterator (iuse->ptr, v->number);
|
||||
}
|
||||
}
|
||||
/* Add the new rtx to the end of the queue. */
|
||||
XEXP (*queue, 0) = x;
|
||||
XEXP (*queue, 1) = NULL_RTX;
|
||||
|
@ -538,6 +667,12 @@ initialize_iterators (void)
|
|||
ints.find_builtin = find_int;
|
||||
ints.apply_iterator = apply_int_iterator;
|
||||
|
||||
substs.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
|
||||
substs.iterators = htab_create (13, leading_string_hash,
|
||||
leading_string_eq_p, 0);
|
||||
substs.find_builtin = find_int; /* We don't use it, anyway. */
|
||||
substs.apply_iterator = apply_subst_iterator;
|
||||
|
||||
lower = add_mapping (&modes, modes.attrs, "mode");
|
||||
upper = add_mapping (&modes, modes.attrs, "MODE");
|
||||
lower_ptr = &lower->values;
|
||||
|
@ -780,6 +915,94 @@ read_mapping (struct iterator_group *group, htab_t table)
|
|||
return m;
|
||||
}
|
||||
|
||||
/* For iterator with name ATTR_NAME generate define_attr with values
|
||||
'yes' and 'no'. This attribute is used to mark templates to which
|
||||
define_subst ATTR_NAME should be applied. This attribute is set and
|
||||
defined implicitly and automatically. */
|
||||
static void
|
||||
add_define_attr_for_define_subst (const char *attr_name, rtx *queue)
|
||||
{
|
||||
rtx const_str, return_rtx;
|
||||
|
||||
return_rtx = rtx_alloc (DEFINE_ATTR);
|
||||
PUT_CODE (return_rtx, DEFINE_ATTR);
|
||||
|
||||
const_str = rtx_alloc (CONST_STRING);
|
||||
PUT_CODE (const_str, CONST_STRING);
|
||||
XSTR (const_str, 0) = xstrdup ("no");
|
||||
|
||||
XSTR (return_rtx, 0) = xstrdup (attr_name);
|
||||
XSTR (return_rtx, 1) = xstrdup ("no,yes");
|
||||
XEXP (return_rtx, 2) = const_str;
|
||||
|
||||
XEXP (*queue, 0) = return_rtx;
|
||||
XEXP (*queue, 1) = NULL_RTX;
|
||||
}
|
||||
|
||||
/* This routine generates DEFINE_SUBST_ATTR expression with operands
|
||||
ATTR_OPERANDS and places it to QUEUE. */
|
||||
static void
|
||||
add_define_subst_attr (const char **attr_operands, rtx *queue)
|
||||
{
|
||||
rtx return_rtx;
|
||||
int i;
|
||||
|
||||
return_rtx = rtx_alloc (DEFINE_SUBST_ATTR);
|
||||
PUT_CODE (return_rtx, DEFINE_SUBST_ATTR);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
XSTR (return_rtx, i) = xstrdup (attr_operands[i]);
|
||||
|
||||
XEXP (*queue, 0) = return_rtx;
|
||||
XEXP (*queue, 1) = NULL_RTX;
|
||||
}
|
||||
|
||||
/* Read define_subst_attribute construction. It has next form:
|
||||
(define_subst_attribute <attribute_name> <iterator_name> <value1> <value2>)
|
||||
Attribute is substituted with value1 when no subst is applied and with
|
||||
value2 in the opposite case.
|
||||
Attributes are added to SUBST_ATTRS_TABLE.
|
||||
In case the iterator is encountered for the first time, it's added to
|
||||
SUBST_ITERS_TABLE. Also, implicit define_attr is generated. */
|
||||
|
||||
static void
|
||||
read_subst_mapping (htab_t subst_iters_table, htab_t subst_attrs_table,
|
||||
rtx *queue)
|
||||
{
|
||||
struct mapping *m;
|
||||
struct map_value **end_ptr;
|
||||
const char *attr_operands[4];
|
||||
rtx * queue_elem = queue;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
attr_operands[i] = read_string (false);
|
||||
|
||||
add_define_subst_attr (attr_operands, queue_elem);
|
||||
|
||||
bind_subst_iter_and_attr (attr_operands[1], attr_operands[0]);
|
||||
|
||||
m = (struct mapping *) htab_find (substs.iterators, &attr_operands[1]);
|
||||
if (!m)
|
||||
{
|
||||
m = add_mapping (&substs, subst_iters_table, attr_operands[1]);
|
||||
end_ptr = &m->values;
|
||||
end_ptr = add_map_value (end_ptr, 1, "");
|
||||
end_ptr = add_map_value (end_ptr, 2, "");
|
||||
|
||||
/* Add element to the queue. */
|
||||
XEXP (*queue, 1) = rtx_alloc (EXPR_LIST);
|
||||
queue_elem = &XEXP (*queue, 1);
|
||||
|
||||
add_define_attr_for_define_subst (attr_operands[1], queue_elem);
|
||||
}
|
||||
|
||||
m = add_mapping (&substs, subst_attrs_table, attr_operands[0]);
|
||||
end_ptr = &m->values;
|
||||
end_ptr = add_map_value (end_ptr, 1, attr_operands[2]);
|
||||
end_ptr = add_map_value (end_ptr, 2, attr_operands[3]);
|
||||
}
|
||||
|
||||
/* Check newly-created code iterator ITERATOR to see whether every code has the
|
||||
same format. */
|
||||
|
||||
|
@ -850,6 +1073,15 @@ read_rtx (const char *rtx_name, rtx *x)
|
|||
read_mapping (&ints, ints.iterators);
|
||||
return false;
|
||||
}
|
||||
if (strcmp (rtx_name, "define_subst_attr") == 0)
|
||||
{
|
||||
read_subst_mapping (substs.iterators, substs.attrs, &queue_head);
|
||||
*x = queue_head;
|
||||
|
||||
/* READ_SUBST_MAPPING could generate a new DEFINE_ATTR. Return
|
||||
TRUE to process it. */
|
||||
return true;
|
||||
}
|
||||
|
||||
apply_iterators (read_rtx_code (rtx_name), &queue_head);
|
||||
iterator_uses.truncate (0);
|
||||
|
@ -868,12 +1100,15 @@ read_rtx_code (const char *code_name)
|
|||
{
|
||||
int i;
|
||||
RTX_CODE code;
|
||||
struct mapping *iterator;
|
||||
struct mapping *iterator, *m;
|
||||
const char *format_ptr;
|
||||
struct md_name name;
|
||||
rtx return_rtx;
|
||||
int c;
|
||||
HOST_WIDE_INT tmp_wide;
|
||||
char *str;
|
||||
char *start, *end, *ptr;
|
||||
char tmpstr[256];
|
||||
|
||||
/* Linked list structure for making RTXs: */
|
||||
struct rtx_list
|
||||
|
@ -1018,6 +1253,34 @@ read_rtx_code (const char *code_name)
|
|||
stringbuf = XOBFINISH (&string_obstack, char *);
|
||||
}
|
||||
|
||||
/* Find attr-names in the string. */
|
||||
ptr = &tmpstr[0];
|
||||
end = stringbuf;
|
||||
while ((start = strchr (end, '<')) && (end = strchr (start, '>')))
|
||||
{
|
||||
if ((end - start - 1 > 0)
|
||||
&& (end - start - 1 < (int)sizeof (tmpstr)))
|
||||
{
|
||||
strncpy (tmpstr, start+1, end-start-1);
|
||||
tmpstr[end-start-1] = 0;
|
||||
end++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
m = (struct mapping *) htab_find (substs.attrs, &ptr);
|
||||
if (m != 0)
|
||||
{
|
||||
/* Here we should find linked subst-iter. */
|
||||
str = find_subst_iter_by_attr (ptr);
|
||||
if (str)
|
||||
m = (struct mapping *) htab_find (substs.iterators, &str);
|
||||
else
|
||||
m = 0;
|
||||
}
|
||||
if (m != 0)
|
||||
record_iterator_use (m, return_rtx);
|
||||
}
|
||||
|
||||
if (star_if_braced)
|
||||
XTMPL (return_rtx, i) = stringbuf;
|
||||
else
|
||||
|
|
|
@ -906,8 +906,9 @@ DEF_RTL_EXPR(DEFINE_PEEPHOLE2, "define_peephole2", "EsES", RTX_EXTRA)
|
|||
This might, for example, create some RTX's and store them in
|
||||
elements of `recog_data.operand' for use by the vector of
|
||||
insn-patterns.
|
||||
(`operands' is an alias here for `recog_data.operand'). */
|
||||
DEF_RTL_EXPR(DEFINE_EXPAND, "define_expand", "sEss", RTX_EXTRA)
|
||||
(`operands' is an alias here for `recog_data.operand').
|
||||
5th: optionally, a vector of attributes for this expand. */
|
||||
DEF_RTL_EXPR(DEFINE_EXPAND, "define_expand", "sEssV", RTX_EXTRA)
|
||||
|
||||
/* Define a requirement for delay slots.
|
||||
1st operand: Condition involving insn attributes that, if true,
|
||||
|
@ -1280,6 +1281,8 @@ DEF_RTL_EXPR (ATTR_FLAG, "attr_flag", "s", RTX_EXTRA)
|
|||
true, the second operand will be used as the value of the conditional. */
|
||||
DEF_RTL_EXPR(COND, "cond", "Ee", RTX_EXTRA)
|
||||
|
||||
DEF_RTL_EXPR(DEFINE_SUBST, "define_subst", "sEsE", RTX_EXTRA)
|
||||
DEF_RTL_EXPR(DEFINE_SUBST_ATTR, "define_subst_attr", "ssss", RTX_EXTRA)
|
||||
#endif /* GENERATOR_FILE */
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue