GCC Middle and Back End API Reference
|
#include "bconfig.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "rtl.h"
#include "obstack.h"
#include "errors.h"
#include "hashtab.h"
#include "read-md.h"
#include "gensupport.h"
Data Structures | |
struct | queue_elem |
struct | std_pred_table |
Macros | |
#define | MAX_OPERANDS 40 |
#define | MNEMONIC_ATTR_NAME "mnemonic" |
#define | MNEMONIC_HTAB_SIZE 1024 |
#define | N 0 |
#define | Y 1 |
#define | I 2 |
#define | TRISTATE_AND(a, b) |
#define | TRISTATE_OR(a, b) |
#define | TRISTATE_NOT(a) ((a) == I ? I : !(a)) |
#define | NUM_KNOWN_STD_PREDS ARRAY_SIZE (std_preds) |
Typedefs | |
typedef const char *(* | constraints_handler_t )(const char *, int) |
#define I 2 |
#define MAX_OPERANDS 40 |
Support routines for the various generation passes. Copyright (C) 2000-2013 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/.
Referenced by subst_pattern_match().
#define MNEMONIC_ATTR_NAME "mnemonic" |
Referenced by gen_mnemonic_setattr().
#define MNEMONIC_HTAB_SIZE 1024 |
Referenced by gen_mnemonic_setattr().
#define N 0 |
Predicate handling.
We construct from the machine description a table mapping each predicate to a list of the rtl codes it can possibly match. The function 'maybe_both_true' uses it to deduce that there are no expressions that can be matches by certain pairs of tree nodes. Also, if a predicate can match only one code, we can hardwire that code into the node testing the predicate.
Some predicates are flagged as special. validate_pattern will not warn about modeless match_operand expressions if they have a special predicate. Predicates that allow only constants are also treated as special, for this purpose.
validate_pattern will warn about predicates that allow non-lvalues when they appear in destination operands.
Calculating the set of rtx codes that can possibly be accepted by a predicate expression EXP requires a three-state logic: any given subexpression may definitively accept a code C (Y), definitively reject a code C (N), or may have an indeterminate effect (I). N and I is N; Y or I is Y; Y and I, N or I are both I. Here are full truth tables.
a b a&b a|b Y Y Y Y N Y N Y N N N N I Y I Y I N N I I I I I
We represent Y with 1, N with 0, I with 2. If any code is left in an I state by the complete expression, we must assume that that code can be accepted.
#define NUM_KNOWN_STD_PREDS ARRAY_SIZE (std_preds) |
Referenced by add_c_test().
#define TRISTATE_AND | ( | a, | |
b | |||
) |
#define TRISTATE_OR | ( | a, | |
b | |||
) |
#define Y 1 |
typedef const char*(* constraints_handler_t)(const char *, int) |
void add_c_test | ( | ) |
Record the C test expression EXPR in the condition_table, with value VAL. Duplicates clobber previous entries.
References eq_struct_pred_data(), hash_struct_pred_data(), pred_data::name, std_pred_table::name, NUM_KNOWN_STD_PREDS, pred_data::special, and std_pred_table::special.
|
static |
Build a define_attr for an binary attribute with name NAME and possible values "yes" and "no", and queue it.
References GET_CODE, GET_RTX_FORMAT, GET_RTX_LENGTH, and XSTR.
|
static |
Add mnemonic STR with length LEN to the mnemonic hash table MNEMONIC_HTAB. A trailing zero end character is appendend to STR and a permanent heap copy of STR is created.
Not found; create a permanent copy and add it to the hash table.
Referenced by gen_mnemonic_setattr().
void add_predicate | ( | ) |
void add_predicate_code | ( | ) |
Record that predicate PRED can accept CODE.
|
static |
If output pattern of define_subst contains MATCH_DUP, then this expression would be replaced with the pattern, matched with MATCH_OPERAND from input pattern. This pattern could contain any number of MATCH_OPERANDs, MATCH_OPERATORs etc., so it's possible that a MATCH_OPERAND from output_pattern (if any) would have the same number, as MATCH_OPERAND from copied pattern. To avoid such indexes overlapping, we assign new indexes to MATCH_OPERANDs, laying in the output pattern outside of MATCH_DUPs.
|
static |
Alter the attribute vector of INSN, which is a COND_EXEC variant created from a define_insn pattern. We must modify the "predicable" attribute to be named "ce_enabled", and also change any "enabled" attribute that's present so that it takes ce_enabled into account. We rely on the fact that INSN was created with copy_rtx, and modify data in-place.
We already give an error elsewhere.
We already give an error elsewhere.
|
static |
|
static |
As number of constraints is changed after define_subst, we need to process attributes as well - we need to duplicate them the same way that we duplicated constraints in original pattern ELEM is a queue element, containing our rtl-template, N_DUP - multiplication factor.
|
static |
|
static |
Duplicate constraints in PATTERN. If pattern is from original rtl-template, we need to duplicate each alternative - for that we need to use duplicate_each_alternative () as a functor ALTER. If pattern is from output-pattern of define_subst, we need to duplicate constraints in another way - with duplicate_alternatives (). N_DUP is multiplication factor.
References queue_elem::data, join_c_conditions(), and XSTR.
|
static |
??? Could coordinate with genoutput to not duplicate code here.
You must take care of the predicate yourself.
|
static |
|
static |
Alter the output of INSN whose pattern was modified by DEFINE_SUBST. We must replicate output strings according to the new number of alternatives ALT in substituted pattern. If ALT equals 1, output has one alternative or defined by C code, then output is returned without any changes.
Referenced by alter_predicate_for_insn().
|
static |
Replicate C as needed to fill out ALT alternatives.
Fall through.
References alter_predicate_for_insn(), gcc_unreachable, NULL, XEXP, XVECEXP, and XVECLEN.
|
static |
References XSTR.
|
static |
Find attribute SUBST in ELEM and assign NEW_VALUE to it.
References queue_elem::data, GET_CODE, GET_NUM_ELEM, RTVEC_ELT, SET, SET_DEST, SET_SRC, XSTR, and XVEC.
|
static |
int cmp_c_test | ( | ) |
Compare two c_test expression structures.
References std_pred_table::allows_const_p, std_pred_table::name, NUM_RTX_CODE, RTX_CODE, and std_pred_table::special.
Referenced by gen_mnemonic_attr().
|
static |
|
static |
Determine how many alternatives there are in INSN, and how many operands.
Fall through.
Fall through.
|
static |
Recursively calculate the set of rtx codes accepted by the predicate expression EXP, writing the result to CODES. LINENO is the line number on which the directive containing EXP appeared.
a ? b : c accepts the same codes as (a & b) | (!a & c).
MATCH_CODE allows a specified list of codes. However, if it does not apply to the top level of the expression, it does not constrain the set of codes for the top level.
MATCH_OPERAND disallows the set of codes that the named predicate disallows, and is indeterminate for the codes that it does allow.
(match_test WHATEVER) is completely indeterminate.
|
static |
|
static |
From string STR "a,b,c" produce "a,b,c,a,b,c,a,b,c", i.e. original string, duplicated N_DUP times.
Global modifier characters mustn't be duplicated: skip if found.
Copy original constraints N_DUP times.
References NULL.
|
static |
|
static |
From string STR "a,b,c" produce "a,a,a,b,b,b,c,c,c", i.e. string where each alternative from the original string is duplicated N_DUP times.
Global modifier characters mustn't be duplicated: skip if found.
Copy a constraint N_DUP times.
|
static |
References NULL.
Referenced by add_c_test().
|
static |
This is subroutine of renumerate_operands_in_pattern. It finds first not-occupied operand-index.
References gcc_assert, NULL, XINT, and XSTR.
Referenced by mark_operands_from_match_dup().
|
static |
Generate (set_attr "mnemonic" "..") RTXs and append them to every insn definition in case the back end requests it by defining the mnemonic attribute. The values for the attribute will be extracted from the output patterns of the insn definitions as far as possible.
Look for the DEFINE_ATTR for `mnemonic'.
A (define_attr "mnemonic" "...") indicates that the back-end wants a mnemonic attribute to be generated.
Check if the insn definition already has (set_attr "mnemonic" ...) or (set (attr "mnemonic") ...).
Add the user defined values to the hash table.
Replace the last ',' with the zero end character.
References check_define_attr_duplicates(), cmp_c_test(), condition_table, hash_c_test(), have_error, init_predicate_table(), NULL, process_define_cond_exec(), process_define_subst(), read_md_files(), rtl_obstack, rtx_handle_directive(), and sequence_num.
|
static |
Scan INSN for mnemonic strings and add them to the mnemonic hash table in MNEMONIC_HTAB.
The mnemonics cannot be found if they are emitted using C code.
If a mnemonic string contains ';' or a newline the string assumed to consist of more than a single instruction. The attribute value will then be set to the user defined default value.
Skip patterns which use C code to emit the template.
Don't set a value if there are more than one instruction in the string.
An insn definition might emit an empty string.
References add_mnemonic_string(), queue_elem::data, define_attr_tail, GET_CODE, have_error, htab_eq_string(), MNEMONIC_ATTR_NAME, mnemonic_htab_callback(), MNEMONIC_HTAB_SIZE, queue_elem::next, NULL, scan_comma_elt(), SET, SET_DEST, string_obstack, XSTR, XVEC, XVECEXP, and XVECLEN.
rtx gen_rtx_CONST_INT | ( | enum machine_mode | ARG_UNUSEDmode, |
HOST_WIDE_INT | arg | ||
) |
Make a version of gen_rtx_CONST_INT so that GEN_INT can be used in the gensupport programs.
|
static |
Generate RTL expression (match_dup OPNO)
|
static |
|
static |
The routine scans rtl PATTERN, find match_operand in it and counts number of alternatives. If PATTERN contains several match_operands with different number of alternatives, error is emitted, and the routine returns 0. If all match_operands in PATTERN have the same number of alternatives, it's stored in N_ALT, and the routine returns 1. Argument LINENO is used in when the error is emitted.
n_alternatives returns 1 if constraint string is empty - here we fix it up.
const char* get_insn_name | ( | ) |
Referenced by nodes_identical_1().
void get_pattern_stats | ( | ) |
Make STATS describe the operands that appear in instruction pattern PATTERN.
|
static |
Make STATS describe the operands that appear in rtx X.
|
static |
|
static |
Return true if ELEM has the attribute with the name of DEFINE_SUBST represented by SUBST_ELEM and this attribute has value SUBST_TRUE. DEFINE_SUBST isn't applied to patterns without such attribute. In other words, we suppose the default value of the attribute to be 'no' since it is always generated automaticaly in read-rtl.c.
Only (set_attr "subst" "yes/no") and (set (attr "subst" (const_string "yes/no"))) are currently allowed.
hashval_t hash_c_test | ( | ) |
Helper functions for insn elision. Compute a hash function of a c_test structure, which is keyed by its ->expr field.
Referenced by gen_mnemonic_attr().
|
static |
Referenced by add_c_test().
|
static |
Comparison function for the mnemonic hash table.
Referenced by gen_mnemonic_setattr().
|
static |
Examine the attribute "predicable"; discover its boolean values and its default.
Look for the DEFINE_ATTR for `predicable', which must exist.
|
static |
Initialize the table of predicate definitions, starting with the information we have on generic predicates.
Referenced by gen_mnemonic_attr().
bool init_rtx_reader_args | ( | ) |
Programs that don't have their own options can use this entry point instead.
Referenced by main().
The entry point for initializing the reader.
Prepare to read input.
Start at 1, to make 0 available for CODE_FOR_nothing.
Process define_cond_exec patterns.
Process define_subst patterns.
|
static |
|
static |
Return true if attribute PREDICABLE is true for ELEM, which holds a DEFINE_INSN.
??? It would be possible to handle this if we really tried. It's not easy though, and I'm not going to bother until it really proves necessary.
Find out which value we're looking at. Multiple alternatives means at least one is predicable.
|
read |
Referenced by subst_pattern_match().
|
static |
This is a subroutine of mark_operands_used_in_match_dup. This routine is marks all MATCH_OPERANDs inside PATTERN as occupied.
References find_first_unused_number_of_operand(), gcc_assert, used_operands_numbers, and XINT.
|
static |
This is a subroutine of adjust_operands_numbers. It goes through all expressions in PATTERN and when MATCH_DUP is met, all MATCH_OPERANDs inside it is marked as occupied. The process of marking is done by routin mark_operands_from_match_dup.
References renumerate_operands_in_pattern().
int maybe_eval_c_test | ( | ) |
Given a string representing a C test expression, look it up in the condition_table and report whether or not its value is known at compile time. Returns a tristate: 1 for known true, 0 for known false, -1 for unknown.
Referenced by gen_insn().
|
static |
This function is called for the elements in the mnemonic hashtable and generates a comma separated list of the mnemonics.
Referenced by gen_mnemonic_setattr().
|
static |
Modify VAL, which is an attribute expression for the "enabled" attribute, to take "ce_enabled" into account. Return the new expression.
|
static |
|
static |
Return the number of alternatives in constraint S.
|
static |
If we have any DEFINE_COND_EXEC patterns, expand the DEFINE_INSN patterns appropriately.
References XTMPL.
Referenced by gen_mnemonic_attr().
|
static |
Process define_predicate directive DESC, which appears on line number LINENO. Compute the set of codes that can be matched, and record this as a known predicate.
|
static |
If we have any DEFINE_SUBST patterns, expand DEFINE_INSN and DEFINE_EXPAND patterns appropriately.
Check if each define_subst has corresponding define_subst_attr.
References string_obstack.
Referenced by gen_mnemonic_attr().
|
static |
|
static |
Replicate insns as appropriate for the given DEFINE_COND_EXEC.
Construct a new pattern for the new insn.
Put the new pattern on the `other' list so that it (a) is not reprocessed by other define_cond_exec patterns (b) appears after all normal define_insn patterns. ??? B is debatable. If one has normal insns that match cond_exec patterns, they will be preferred over these generated patterns. Whether this matters in practice, or if it's a good thing, or whether we should thread these new patterns into the define_insn chain just after their generator is something we'll have to experiment with.
If the original insn came from a define_insn_and_split, generate a new split to handle the predicated insn.
Predicate the pattern matched by the split.
Predicate all of the insns generated by the split.
Add the new split to the queue.
|
static |
|
static |
Process a top level rtx in some way, queuing as appropriate.
Fall through.
Create a split with values from the insn_and_split.
If the split condition starts with "&&", append it to the insn condition to create the new split condition.
Fix up the DEFINE_INSN.
Queue them.
|
static |
Try to apply define_substs to the given ELEM. Only define_substs, specified via attributes would be applied. If attribute, requiring define_subst, is set, but no define_subst was applied, ELEM would be deleted.
Compare original rtl-pattern from define_insn with input pattern from define_subst. Also, check if numbers of alternatives are the same in all match_operands.
Check if numbers of alternatives are the same in all match_operands in output template of define_subst.
Clear array in which we save occupied indexes of operands.
Create a pattern, based on the output one from define_subst.
Duplicate constraints in substitute-pattern.
Substitute match_dup and match_op_dup in the new pattern and duplicate constraints.
We don't need any constraints in DEFINE_EXPAND.
Recalculate condition, joining conditions from original and DEFINE_SUBST input patterns.
Mark that subst was applied by changing attribute from "yes" to "no".
If ELEM contains a subst attribute with value "yes", then we expected that a subst would be applied, but it wasn't - so, we need to remove that elementto avoid duplicating.
|
staticread |
Queue PATTERN on LIST_TAIL. Return the address of the new queue element.
References queue_elem::next, and NULL.
rtx read_md_rtx | ( | ) |
The entry point for reading a single rtx from an md file. Return the rtx, or NULL if the md file has been fully processed. Return the line where the rtx was found in LINENO. Return the number of code generating rtx'en read since the start of the md file in SEQNR.
Read all patterns from a given queue before moving on to the next.
Discard insn patterns which we know can never match (because their C test is provably always false). If insn_elision is false, our caller needs to see all the patterns. Note that the elided patterns are never counted by the sequence numbering; it is the caller's responsibility, when insn_elision is false, not to use elided pattern numbers for anything.
*seqnr is used here so the name table will match caller's idea of insn numbering, whether or not elision is active.
References condition_table, c_test::expr, and c_test::value.
Referenced by main().
|
static |
|
static |
|
static |
|
static |
Recursively remove constraints from an rtx.
|
static |
Remove element ELEM from QUEUE.
|
static |
This is subroutine of adjust_operands_numbers. It visits all expressions in PATTERN and assigns not-occupied operand indexes to MATCH_OPERANDs and MATCH_OPERATORs of this PATTERN.
Referenced by mark_operands_used_in_match_dup().
|
static |
This routine checks all match_operands in PATTERN and if some of have the same index, it replaces all of them except the first one to match_dup. Usually, match_operands with the same indexes are forbidden, but after define_subst copy an RTL-expression from original template, indexes of existed and just-copied match_operands could coincide. To fix it, we replace one of them with match_dup.
Compare predicates before replacing with match_dup.
|
static |
A read_md_files callback for reading an rtx.
Referenced by gen_mnemonic_attr().
|
static |
|
static |
Adjust all of the operand numbers in SRC to match the shift they'll get from an operand displacement of DISP. Return a pointer after the adjusted string.
|
static |
The routine modifies given input PATTERN of define_subst, replacing MATCH_DUP and MATCH_OP_DUP with operands from define_insn original pattern, whose operands are stored in OPERAND_DATA array. It also duplicates constraints in operands - constraints from define_insn operands are duplicated N_SUBST_ALT times, constraints from define_subst operands are duplicated N_ALT times. After the duplication, returned output rtl-pattern contains every combination of input constraints Vs constraints from define_subst output.
Duplicate constraints.
Referenced by subst_pattern_match().
|
static |
Compare RTL-template of original define_insn X to input RTL-template of define_subst PT. Return 1 if the templates match, 0 otherwise. During the comparison, the routine also fills global_array OPERAND_DATA.
MATCH_DUP, and MATCH_OP_DUP don't have a specified mode, so we always accept them.
Compare modes.
In case X is also match_operator, compare predicates.
Compare operands. MATCH_OPERATOR in input template could match in original template either 1) MATCH_OPERAND, 2) UNSPEC, 3) ordinary operation (like PLUS). In the first case operands are at (XVECEXP (x, 2, j)), in the second - at (XVECEXP (x, 0, j)), in the last one - (XEXP (x, j)). X_VECEXP_POS variable shows, where to look for these operands.
MATCH_OPERATOR or UNSPEC case.
Compare operands number in X and PT.
Ordinary operator.
Compare operands number in X and PT. We count operands differently for X and PT since we compare an operator (with operands directly in RTX) and MATCH_OPERATOR (that has a vector with operands).
Store the operand to OPERAND_DATA array.
Currently interface for these constructions isn't defined - probably they aren't needed in input template of define_subst at all. So, for now their usage in define_subst is forbidden.
If PT is none of the handled above, then we match only expressions with the same code in X.
References gcc_assert, GET_MODE, lookup_predicate(), MAX_OPERANDS, subst_pattern_match(), XEXP, XINT, XSTR, XVECEXP, and XVECLEN.
void traverse_c_tests | ( | ) |
For every C test, call CALLBACK with two arguments: a pointer to the condition structure and INFO. Stops when CALLBACK returns zero.
|
static |
Return true if NAME is a valid predicate name.
References pred_data::codes, error_with_line(), NUM_RTX_CODE, and XSTR.
|
static |
Referenced by gen_mnemonic_attr(), and read_md_rtx().
|
static |
|
static |
Referenced by gen_mnemonic_setattr().
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
0 means no warning about that code yet, 1 means warned.
struct pred_data* first_predicate |
int insn_elision = 1 |
Set this to 0 to disable automatic elision of insn patterns which can never be used in this configuration. See genconditions.c. Must be set before calling init_md_reader.
|
static |
These functions allow linkage with print-rtl.c. Also, some generators like to annotate their output with insn names. Holds an array of names indexed by insn_code_number.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Helper functions for define_predicate and define_special_predicate processing. Shared between genrecog.c and genpreds.c.
Referenced by attr_rtx_1(), gen_mnemonic_attr(), get_attr_order(), and process_define_predicate().
|
static |
Counter for patterns that generate code: define_insn, define_expand, define_split, define_peephole, and define_peephole2. See read_md_rtx(). Any define_insn_and_splits are already in separate queues so that the insn and the splitter get a unique number also.
Referenced by gen_mnemonic_attr().
|
static |
|
static |
|
static |
int target_flags |
In case some macros used by files we include need it, define this here.
Referenced by default_class_max_nregs().
|
static |
Referenced by mark_operands_from_match_dup().