📄 genattrtab.c
字号:
/* Generate code from machine description to compute values of attributes. Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc. Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)This file is part of GNU CC.GNU CC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU CC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU CC; see the file COPYING. If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA. *//* This program handles insn attributes and the DEFINE_DELAY and DEFINE_FUNCTION_UNIT definitions. It produces a series of functions named `get_attr_...', one for each insn attribute. Each of these is given the rtx for an insn and returns a member of the enum for the attribute. These subroutines have the form of a `switch' on the INSN_CODE (via `recog_memoized'). Each case either returns a constant attribute value or a value that depends on tests on other attributes, the form of operands, or some random C expression (encoded with a SYMBOL_REF expression). If the attribute `alternative', or a random C expression is present, `constrain_operands' is called. If either of these cases of a reference to an operand is found, `insn_extract' is called. The special attribute `length' is also recognized. For this operand, expressions involving the address of an operand or the current insn, (address (pc)), are valid. In this case, an initial pass is made to set all lengths that do not depend on address. Those that do are set to the maximum length. Then each insn that depends on an address is checked and possibly has its length changed. The process repeats until no further changed are made. The resulting lengths are saved for use by `get_attr_length'. A special form of DEFINE_ATTR, where the expression for default value is a CONST expression, indicates an attribute that is constant for a given run of the compiler. The subroutine generated for these attributes has no parameters as it does not depend on any particular insn. Constant attributes are typically used to specify which variety of processor is used. Internal attributes are defined to handle DEFINE_DELAY and DEFINE_FUNCTION_UNIT. Special routines are output for these cases. This program works by keeping a list of possible values for each attribute. These include the basic attribute choices, default values for attribute, and all derived quantities. As the description file is read, the definition for each insn is saved in a `struct insn_def'. When the file reading is complete, a `struct insn_ent' is created for each insn and chained to the corresponding attribute value, either that specified, or the default. An optimization phase is then run. This simplifies expressions for each insn. EQ_ATTR tests are resolved, whenever possible, to a test that indicates when the attribute has the specified value for the insn. This avoids recursive calls during compilation. The strategy used when processing DEFINE_DELAY and DEFINE_FUNCTION_UNIT definitions is to create arbitrarily complex expressions and have the optimization simplify them. Once optimization is complete, any required routines and definitions will be written. An optimization that is not yet implemented is to hoist the constant expressions entirely out of the routines and definitions that are written. A way to do this is to iterate over all possible combinations of values for constant attributes and generate a set of functions for that given combination. An initialization function would be written that evaluates the attributes and installs the corresponding set of routines and definitions (each would be accessed through a pointer). We use the flags in an RTX as follows: `unchanging' (RTX_UNCHANGING_P): This rtx is fully simplified independent of the insn code. `in_struct' (MEM_IN_STRUCT_P): This rtx is fully simplified for the insn code currently being processed (see optimize_attrs). `integrated' (RTX_INTEGRATED_P): This rtx is permanent and unique (see attr_rtx). `volatil' (MEM_VOLATILE_P): During simplify_by_exploding the value of an EQ_ATTR rtx is true if !volatil and false if volatil. */#include "hconfig.h"/* varargs must always be included after *config.h. */#ifdef __STDC__#include <stdarg.h>#else#include <varargs.h>#endif#include "rtl.h"#include "insn-config.h" /* For REGISTER_CONSTRAINTS */#include <stdio.h>#ifndef VMS#ifndef USG#include <sys/time.h>#include <sys/resource.h>#endif#endif/* We must include obstack.h after <sys/time.h>, to avoid lossage with /usr/include/sys/stdtypes.h on Sun OS 4.x. */#include "obstack.h"static struct obstack obstack, obstack1, obstack2;struct obstack *rtl_obstack = &obstack;struct obstack *hash_obstack = &obstack1;struct obstack *temp_obstack = &obstack2;#define obstack_chunk_alloc xmalloc#define obstack_chunk_free free/* Define this so we can link with print-rtl.o to get debug_rtx function. */char **insn_name_ptr = 0;extern void free ();extern rtx read_rtx ();static void fatal ();void fancy_abort ();/* enough space to reserve for printing out ints */#define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)/* Define structures used to record attributes and values. *//* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is encountered, we store all the relevant information into a `struct insn_def'. This is done to allow attribute definitions to occur anywhere in the file. */struct insn_def{ int insn_code; /* Instruction number. */ int insn_index; /* Expression numer in file, for errors. */ struct insn_def *next; /* Next insn in chain. */ rtx def; /* The DEFINE_... */ int num_alternatives; /* Number of alternatives. */ int vec_idx; /* Index of attribute vector in `def'. */};/* Once everything has been read in, we store in each attribute value a list of insn codes that have that value. Here is the structure used for the list. */struct insn_ent{ int insn_code; /* Instruction number. */ int insn_index; /* Index of definition in file */ struct insn_ent *next; /* Next in chain. */};/* Each value of an attribute (either constant or computed) is assigned a structure which is used as the listhead of the insns that have that value. */struct attr_value{ rtx value; /* Value of attribute. */ struct attr_value *next; /* Next attribute value in chain. */ struct insn_ent *first_insn; /* First insn with this value. */ int num_insns; /* Number of insns with this value. */ int has_asm_insn; /* True if this value used for `asm' insns */};/* Structure for each attribute. */struct attr_desc{ char *name; /* Name of attribute. */ struct attr_desc *next; /* Next attribute. */ int is_numeric; /* Values of this attribute are numeric. */ int negative_ok; /* Allow negative numeric values. */ int unsigned_p; /* Make the output function unsigned int. */ int is_const; /* Attribute value constant for each run. */ int is_special; /* Don't call `write_attr_set'. */ struct attr_value *first_value; /* First value of this attribute. */ struct attr_value *default_val; /* Default value for this attribute. */};#define NULL_ATTR (struct attr_desc *) NULL/* A range of values. */struct range{ int min; int max;};/* Structure for each DEFINE_DELAY. */struct delay_desc{ rtx def; /* DEFINE_DELAY expression. */ struct delay_desc *next; /* Next DEFINE_DELAY. */ int num; /* Number of DEFINE_DELAY, starting at 1. */};/* Record information about each DEFINE_FUNCTION_UNIT. */struct function_unit_op{ rtx condexp; /* Expression TRUE for applicable insn. */ struct function_unit_op *next; /* Next operation for this function unit. */ int num; /* Ordinal for this operation type in unit. */ int ready; /* Cost until data is ready. */ int issue_delay; /* Cost until unit can accept another insn. */ rtx conflict_exp; /* Expression TRUE for insns incurring issue delay. */ rtx issue_exp; /* Expression computing issue delay. */};/* Record information about each function unit mentioned in a DEFINE_FUNCTION_UNIT. */struct function_unit{ char *name; /* Function unit name. */ struct function_unit *next; /* Next function unit. */ int num; /* Ordinal of this unit type. */ int multiplicity; /* Number of units of this type. */ int simultaneity; /* Maximum number of simultaneous insns on this function unit or 0 if unlimited. */ rtx condexp; /* Expression TRUE for insn needing unit. */ int num_opclasses; /* Number of different operation types. */ struct function_unit_op *ops; /* Pointer to first operation type. */ int needs_conflict_function; /* Nonzero if a conflict function required. */ int needs_blockage_function; /* Nonzero if a blockage function required. */ int needs_range_function; /* Nonzero if blockage range function needed.*/ rtx default_cost; /* Conflict cost, if constant. */ struct range issue_delay; /* Range of issue delay values. */ int max_blockage; /* Maximum time an insn blocks the unit. */};/* Listheads of above structures. *//* This one is indexed by the first character of the attribute name. */#define MAX_ATTRS_INDEX 256static struct attr_desc *attrs[MAX_ATTRS_INDEX];static struct insn_def *defs;static struct delay_desc *delays;static struct function_unit *units;/* An expression where all the unknown terms are EQ_ATTR tests can be rearranged into a COND provided we can enumerate all possible combinations of the unknown values. The set of combinations become the tests of the COND; the value of the expression given that combination is computed and becomes the corresponding value. To do this, we must be able to enumerate all values for each attribute used in the expression (currently, we give up if we find a numeric attribute). If the set of EQ_ATTR tests used in an expression tests the value of N different attributes, the list of all possible combinations can be made by walking the N-dimensional attribute space defined by those attributes. We record each of these as a struct dimension. The algorithm relies on sharing EQ_ATTR nodes: if two nodes in an expression are the same, the will also have the same address. We find all the EQ_ATTR nodes by marking them MEM_VOLATILE_P. This bit later represents the value of an EQ_ATTR node, so once all nodes are marked, they are also given an initial value of FALSE. We then separate the set of EQ_ATTR nodes into dimensions for each attribute and put them on the VALUES list. Terms are added as needed by `add_values_to_cover' so that all possible values of the attribute are tested. Each dimension also has a current value. This is the node that is currently considered to be TRUE. If this is one of the nodes added by `add_values_to_cover', all the EQ_ATTR tests in the original expression will be FALSE. Otherwise, only the CURRENT_VALUE will be true. NUM_VALUES is simply the length of the VALUES list and is there for convenience. Once the dimensions are created, the algorithm enumerates all possible values and computes the current value of the given expression. */struct dimension { struct attr_desc *attr; /* Attribute for this dimension. */ rtx values; /* List of attribute values used. */ rtx current_value; /* Position in the list for the TRUE value. */ int num_values; /* Length of the values list. */};/* Other variables. */static int insn_code_number;static int insn_index_number;static int got_define_asm_attributes;static int must_extract;static int must_constrain;static int address_used;static int length_used;static int num_delays;static int have_annul_true, have_annul_false;static int num_units;static int num_insn_ents;/* Used as operand to `operate_exp': */enum operator {PLUS_OP, MINUS_OP, POS_MINUS_OP, EQ_OP, OR_OP, MAX_OP, MIN_OP, RANGE_OP};/* Stores, for each insn code, the number of constraint alternatives. */static int *insn_n_alternatives;/* Stores, for each insn code, a bitmap that has bits on for each possible alternative. */static int *insn_alternatives;/* If nonzero, assume that the `alternative' attr has this value. This is the hashed, unique string for the numeral whose value is chosen alternative. */static char *current_alternative_string;/* Used to simplify expressions. */static rtx true_rtx, false_rtx;/* Used to reduce calls to `strcmp' */static char *alternative_name;/* Simplify an expression. Only call the routine if there is something to simplify. */#define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX) \ (RTX_UNCHANGING_P (EXP) || MEM_IN_STRUCT_P (EXP) ? (EXP) \ : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX)) /* Simplify (eq_attr ("alternative") ...) when we are working with a particular alternative. */#define SIMPLIFY_ALTERNATIVE(EXP) \ if (current_alternative_string \ && GET_CODE ((EXP)) == EQ_ATTR \ && XSTR ((EXP), 0) == alternative_name) \ (EXP) = (XSTR ((EXP), 1) == current_alternative_string \ ? true_rtx : false_rtx);/* These are referenced by rtlanal.c and hence need to be defined somewhere. They won't actually be used. */rtx frame_pointer_rtx, hard_frame_pointer_rtx, stack_pointer_rtx;rtx arg_pointer_rtx;static rtx attr_rtx PVPROTO((enum rtx_code, ...));#ifdef HAVE_VPRINTFstatic char *attr_printf PVPROTO((int, char *, ...));#elsestatic char *attr_printf ();#endifstatic char *attr_string PROTO((char *, int));static rtx check_attr_test PROTO((rtx, int));static rtx check_attr_value PROTO((rtx, struct attr_desc *));static rtx convert_set_attr_alternative PROTO((rtx, int, int, int));static rtx convert_set_attr PROTO((rtx, int, int, int));static void check_defs PROTO((void));static rtx convert_const_symbol_ref PROTO((rtx, struct attr_desc *));static rtx make_canonical PROTO((struct attr_desc *, rtx));static struct attr_value *get_attr_value PROTO((rtx, struct attr_desc *, int));static rtx copy_rtx_unchanging PROTO((rtx));static rtx copy_boolean PROTO((rtx));static void expand_delays PROTO((void));static rtx operate_exp PROTO((enum operator, rtx, rtx));static void expand_units PROTO((void));static rtx simplify_knowing PROTO((rtx, rtx));static rtx encode_units_mask PROTO((rtx));static void fill_attr PROTO((struct attr_desc *));/* dpx2 compiler chokes if we specify the arg types of the args. */static rtx substitute_address PROTO((rtx, rtx (*) (), rtx (*) ()));static void make_length_attrs PROTO((void));static rtx identity_fn PROTO((rtx));static rtx zero_fn PROTO((rtx));static rtx one_fn PROTO((rtx));static rtx max_fn PROTO((rtx));static rtx simplify_cond PROTO((rtx, int, int));static rtx simplify_by_alternatives PROTO((rtx, int, int));static rtx simplify_by_exploding PROTO((rtx));static int find_and_mark_used_attributes PROTO((rtx, rtx *, int *));static void unmark_used_attributes PROTO((rtx, struct dimension *, int));static int add_values_to_cover PROTO((struct dimension *));static int increment_current_value PROTO((struct dimension *, int));static rtx test_for_current_value PROTO((struct dimension *, int));static rtx simplify_with_current_value PROTO((rtx, struct dimension *, int));static rtx simplify_with_current_value_aux PROTO((rtx));static void clear_struct_flag PROTO((rtx));static int count_sub_rtxs PROTO((rtx, int));static void remove_insn_ent PROTO((struct attr_value *, struct insn_ent *));static void insert_insn_ent PROTO((struct attr_value *, struct insn_ent *));static rtx insert_right_side PROTO((enum rtx_code, rtx, rtx, int, int));static rtx make_alternative_compare PROTO((int));static int compute_alternative_mask PROTO((rtx, enum rtx_code));static rtx evaluate_eq_attr PROTO((rtx, rtx, int, int));static rtx simplify_and_tree PROTO((rtx, rtx *, int, int));static rtx simplify_or_tree PROTO((rtx, rtx *, int, int));static rtx simplify_test_exp PROTO((rtx, int, int));static void optimize_attrs PROTO((void));static void gen_attr PROTO((rtx));static int count_alternatives PROTO((rtx));static int compares_alternatives_p PROTO((rtx));static int contained_in_p PROTO((rtx, rtx));static void gen_insn PROTO((rtx));static void gen_delay PROTO((rtx));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -