⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genattrtab.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Generate code from machine description to compute values of attributes.   Copyright (C) 1991 Free Software Foundation, Inc.   Contributed by Richard Kenner (kenner@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, 675 Mass Ave, Cambridge, MA 02139, 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 "gvarargs.h"#include "hconfig.h"#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 a blockage range function required.  */  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;/* 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;/* 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, stack_pointer_rtx, arg_pointer_rtx;static rtx attr_rtx ();static char *attr_printf ();static char *attr_string ();static rtx check_attr_test ();static rtx check_attr_value ();static rtx convert_set_attr_alternative ();static rtx convert_set_attr ();static void check_defs ();static rtx convert_const_symbol_ref ();static rtx make_canonical ();static struct attr_value *get_attr_value ();static rtx copy_rtx_unchanging ();static rtx copy_boolean ();static void expand_delays ();static rtx operate_exp ();static void expand_units ();static rtx simplify_knowing ();static rtx encode_units_mask ();static void fill_attr ();static rtx substitute_address ();static void make_length_attrs ();static rtx identity_fn ();static rtx zero_fn ();static rtx one_fn ();static rtx max_fn ();static rtx simplify_cond ();static rtx simplify_by_alternatives ();static rtx simplify_by_exploding ();static int find_and_mark_used_attributes ();static void unmark_used_attributes ();static int add_values_to_cover ();static int increment_current_value ();static rtx test_for_current_value ();static rtx simplify_with_current_value ();static rtx simplify_with_current_value_aux ();static void remove_insn_ent ();static void insert_insn_ent ();static rtx insert_right_side ();static rtx make_alternative_compare ();static int compute_alternative_mask ();static rtx evaluate_eq_attr ();static rtx simplify_and_tree ();static rtx simplify_or_tree ();static rtx simplify_test_exp ();static void optimize_attrs ();static void gen_attr ();static int count_alternatives ();static int compares_alternatives_p ();static int contained_in_p ();static void gen_insn ();static void gen_delay ();static void gen_unit ();static void write_test_expr ();static int max_attr_value ();static void walk_attr_value ();static void write_attr_get ();static rtx eliminate_known_true ();static void write_attr_set ();static void write_attr_case ();static void write_attr_value ();static void write_attr_valueq ();static void write_upcase ();static void write_indent ();static void write_eligible_delay ();static void write_function_unit_info ();static void write_complex_function ();static int n_comma_elts ();static char *next_comma_elt ();static struct attr_desc *find_attr ();static void make_internal_attr ();static struct attr_value *find_most_used ();static rtx find_single_value ();static rtx make_numeric_value ();static void extend_range ();char *xrealloc ();char *xmalloc ();static void fatal ();#define oballoc(size) obstack_alloc (hash_obstack, size)/* Hash table for sharing RTL and strings.  *//* Each hash table slot is a bucket containing a chain of these structures.   Strings are given negative hash codes; RTL expressions are given positive   hash codes.  */struct attr_hash{  struct attr_hash *next;	/* Next structure in the bucket.  */  int hashcode;			/* Hash code of this rtx or string.  */  union    {      char *str;		/* The string (negative hash codes) */      rtx rtl;			/* or the RTL recorded here.  */    } u;};/* Now here is the hash table.  When recording an RTL, it is added to   the slot whose index is the hash code mod the table size.  Note   that the hash table is used for several kinds of RTL (see attr_rtx)   and for strings.  While all these live in the same table, they are   completely independent, and the hash code is computed differently   for each.  */#define RTL_HASH_SIZE 4093struct attr_hash *attr_hash_table[RTL_HASH_SIZE];/* Here is how primitive or already-shared RTL's hash   codes are made.  */#define RTL_HASH(RTL) ((HOST_WIDE_INT) (RTL) & 0777777)/* Add an entry to the hash table for RTL with hash code HASHCODE.  */static voidattr_hash_add_rtx (hashcode, rtl)     int hashcode;     rtx rtl;{  register struct attr_hash *h;  h = (struct attr_hash *) obstack_alloc (hash_obstack,					  sizeof (struct attr_hash));  h->hashcode = hashcode;  h->u.rtl = rtl;  h->next = attr_hash_table[hashcode % RTL_HASH_SIZE];  attr_hash_table[hashcode % RTL_HASH_SIZE] = h;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -