gcc/gcc/genextract.c

588 lines
14 KiB
C
Raw Normal View History

1991-10-24 18:21:48 +01:00
/* Generate code from machine description to extract operands from insn as rtl.
2000-02-26 14:55:09 +01:00
Copyright (C) 1987, 1991, 1992, 1993, 1997, 1998,
1999, 2000 Free Software Foundation, Inc.
1991-10-24 18:21:48 +01:00
This file is part of GNU CC.
GNU CC 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 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 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 GNU CC; see the file COPYING. If not, write to
1995-06-15 13:52:21 +02:00
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
1991-10-24 18:21:48 +01:00
#include "hconfig.h"
#include "system.h"
1991-10-24 18:21:48 +01:00
#include "rtl.h"
#include "obstack.h"
#include "errors.h"
#include "insn-config.h"
1991-10-24 18:21:48 +01:00
static struct obstack obstack;
struct obstack *rtl_obstack = &obstack;
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
/* This structure contains all the information needed to describe one
set of extractions methods. Each method may be used by more than
one pattern if the operands are in the same place.
The string for each operand describes that path to the operand and
contains `0' through `9' when going into an expression and `a' through
`z' when going into a vector. We assume here that only the first operand
of an rtl expression is a vector. genrecog.c makes the same assumption
(and uses the same representation) and it is currently true. */
struct extraction
{
int op_count;
char *oplocs[MAX_RECOG_OPERANDS];
int dup_count;
char *duplocs[MAX_DUP_OPERANDS];
int dupnums[MAX_DUP_OPERANDS];
struct code_ptr *insns;
struct extraction *next;
};
/* Holds a single insn code that use an extraction method. */
struct code_ptr
{
int insn_code;
struct code_ptr *next;
};
static struct extraction *extractions;
/* Holds an array of names indexed by insn_code_number. */
static char **insn_name_ptr = 0;
static int insn_name_ptr_size = 0;
1991-10-24 18:21:48 +01:00
/* Number instruction patterns handled, starting at 0 for first one. */
static int insn_code_number;
/* Records the large operand number in this insn. */
static int op_count;
/* Records the location of any operands using the string format described
above. */
static char *oplocs[MAX_RECOG_OPERANDS];
1991-10-24 18:21:48 +01:00
/* Number the occurrences of MATCH_DUP in each instruction,
starting at 0 for the first occurrence. */
static int dup_count;
/* Records the location of any MATCH_DUP operands. */
1991-10-24 18:21:48 +01:00
static char *duplocs[MAX_DUP_OPERANDS];
1991-10-24 18:21:48 +01:00
/* Record the operand number of any MATCH_DUPs. */
1991-10-24 18:21:48 +01:00
static int dupnums[MAX_DUP_OPERANDS];
1991-10-24 18:21:48 +01:00
/* Record the list of insn_codes for peepholes. */
1991-10-24 18:21:48 +01:00
static struct code_ptr *peepholes;
1991-10-24 18:21:48 +01:00
static void gen_insn PARAMS ((rtx));
static void walk_rtx PARAMS ((rtx, const char *));
static void print_path PARAMS ((const char *));
static void record_insn_name PARAMS ((int, const char *));
1991-10-24 18:21:48 +01:00
static void
gen_insn (insn)
rtx insn;
{
register int i;
register struct extraction *p;
register struct code_ptr *link;
1991-10-24 18:21:48 +01:00
op_count = 0;
1991-10-24 18:21:48 +01:00
dup_count = 0;
/* No operands seen so far in this pattern. */
memset (oplocs, 0, sizeof oplocs);
1991-10-24 18:21:48 +01:00
/* Walk the insn's pattern, remembering at all times the path
down to the walking point. */
if (XVECLEN (insn, 1) == 1)
walk_rtx (XVECEXP (insn, 1, 0), "");
1991-10-24 18:21:48 +01:00
else
for (i = XVECLEN (insn, 1) - 1; i >= 0; i--)
{
char *path = (char *) alloca (2);
1991-10-24 18:21:48 +01:00
path[0] = 'a' + i;
path[1] = 0;
walk_rtx (XVECEXP (insn, 1, i), path);
1991-10-24 18:21:48 +01:00
}
link = (struct code_ptr *) xmalloc (sizeof (struct code_ptr));
link->insn_code = insn_code_number;
1996-07-04 00:07:53 +02:00
/* See if we find something that already had this extraction method. */
for (p = extractions; p; p = p->next)
1991-10-24 18:21:48 +01:00
{
if (p->op_count != op_count || p->dup_count != dup_count)
continue;
for (i = 0; i < op_count; i++)
if (p->oplocs[i] != oplocs[i]
&& ! (p->oplocs[i] != 0 && oplocs[i] != 0
&& ! strcmp (p->oplocs[i], oplocs[i])))
break;
if (i != op_count)
continue;
for (i = 0; i < dup_count; i++)
if (p->dupnums[i] != dupnums[i]
|| strcmp (p->duplocs[i], duplocs[i]))
break;
if (i != dup_count)
continue;
/* This extraction is the same as ours. Just link us in. */
link->next = p->insns;
p->insns = link;
return;
1991-10-24 18:21:48 +01:00
}
/* Otherwise, make a new extraction method. */
1991-10-24 18:21:48 +01:00
p = (struct extraction *) xmalloc (sizeof (struct extraction));
p->op_count = op_count;
p->dup_count = dup_count;
p->next = extractions;
extractions = p;
p->insns = link;
link->next = 0;
for (i = 0; i < op_count; i++)
p->oplocs[i] = oplocs[i];
for (i = 0; i < dup_count; i++)
p->dupnums[i] = dupnums[i], p->duplocs[i] = duplocs[i];
}
1991-10-24 18:21:48 +01:00
static void
walk_rtx (x, path)
rtx x;
const char *path;
1991-10-24 18:21:48 +01:00
{
register RTX_CODE code;
register int i;
register int len;
rtl.h (rtx_format): Constify a char*. * rtl.h (rtx_format): Constify a char*. * rtl.c (rtx_format): Likewise. (copy_rtx, copy_most_rtx, read_rtx): Likewise. (init_rtl): Use accessor macro, not `rtx_format'. * alias.c (rtx_equal_for_memref_p, find_symbolic_term): Constify a char*. * caller-save.c (mark_referenced_regs): Likewise. * combine.c (subst, make_compound_operation, known_cond, gen_rtx_combine, update_table_tick, get_last_value_validate, use_crosses_set_p, mark_used_regs_combine, move_deaths): Likewise. * cse.c (rtx_cost, mention_regs, canon_hash, exp_equiv_p, refers_to_p, canon_reg, fold_rtx, cse_process_notes, count_reg_usage): Likewise. * emit-rtl.c (gen_rtx, copy_rtx_if_shared, reset_used_flags): Likewise. * final.c (leaf_renumber_regs_insn): Likewise. * flow.c (mark_used_regs, find_use_as_address, dump_flow_info, dump_edge_info, count_reg_references): Likewise. * function.c (fixup_var_refs_1, walk_fixup_memory_subreg, fixup_stack_1, purge_addressof_1, instantiate_virtual_regs_1): Likewise. * gcse.c (oprs_unchanged_p, hash_expr_1, expr_equiv_p, oprs_not_set_p, expr_killed_p, compute_transp, find_used_regs, add_label_notes): Likewise. * genattrtab.c (attr_rtx, attr_copy_rtx, encode_units_mask, clear_struct_flag, count_sub_rtxs, count_alternatives, compares_alternatives_p, contained_in_p, walk_attr_value, write_expr_attr_cache): Likewise. * genconfig.c (walk_insn_part): Likewise. * genemit.c (max_operand_1, gen_exp): Likewise. * genextract.c (walk_rtx): Likewise. * genflags.c (num_operands): Likewise. * genoutput.c (scan_operands): Likewise. * genpeep.c (match_rtx): Likewise. * genrecog.c (add_to_sequence): Likewise. * haifa-sched.c (may_trap_exp, sched_analyze_2, attach_deaths): Likewise. * integrate.c (save_constants, copy_for_inline, copy_rtx_and_substitute, subst_constants, restore_constants): Likewise. * jump.c (mark_jump_label, invert_exp, redirect_exp, rtx_renumbered_equal_p, rtx_equal_for_thread_p): Likewise. * local-alloc.c (contains_replace_regs, memref_referenced_p): Likewise. * loop.c (record_excess_regs, rtx_equal_for_loop_p, add_label_notes, replace_call_address, count_nonfixed_reads, invariant_p, find_single_use_in_loop, find_mem_givs, find_life_end, maybe_eliminate_biv_1, update_reg_last_use): Likewise. * print-rtl.c (reg_names, print_rtx): Likewise. * recog.c (validate_replace_rtx_1, find_single_use_1): Likewise. * reg-stack.c (stack_regs_mentioned_p, record_label_references, record_reg_life_pat, swap_rtx_condition, goto_block_pat, print_blocks): Likewise. * regclass.c (fix_register, record_address_regs, reg_scan_mark_refs): Likewise. * regmove.c (stable_but_for_p): Likewise. * reload.c (loc_mentioned_in_p, operands_match_p, find_reloads_toplevsubst_reg_equivs, find_reloads_address_1, copy_replacements, refers_to_regno_for_reload_p, refers_to_mem_for_reload_p, find_inc_amount, regno_clobbered_p, reload_when_needed_name, reg_class_names, debug_reload_to_stream): Likewise. * reload1.c (eliminate_regs, scan_paradoxical_subregs, delete_address_reloads_1, count_occurrences, reload_cse_mem_conflict_p, reload_combine_note_use, add_auto_inc_notes): Likewise. * resource.c (mark_referenced_resources, mark_set_resources): Likewise. * rtlanal.c (rtx_unstable_p, rtx_varies_p, rtx_addr_varies_p, reg_mentioned_p, regs_set_between_p, modified_between_p, modified_in_p, refers_to_regno_p, reg_overlap_mentioned_p, rtx_equal_p, volatile_insn_p, volatile_refs_p, side_effects_p, may_trap_p, inequality_comparisons_p, replace_rtx, replace_regs, jmp_uses_reg_or_mem, for_each_rtx, regno_use_in): Likewise. * sched.c (sched_analyze_2, attach_deaths): Likewise. * stupid.c (stupid_mark_refs): Likewise. * unroll.c (remap_split_bivs): Likewise. * varasm.c (mark_constants): Likewise. * a29k/a29k.c (uses_local_reg_p): Likewise. * alpha/alpha.c (summarize_insn): Likewise. * arm/arm.c (symbol_mentioned_p, label_mentioned_p, eliminate_lr2ip): Likewise. * arm/thumb.c (symbol_mentioned_p, label_mentioned_p): Likewise. * i386/i386.c (symbolic_reference_mentioned_p, copy_all_rtx, reg_mentioned_in_mem): Likewise. * ns32k/ns32k.c (global_symbolic_reference_mentioned_p, symbolic_reference_mentioned_p): Likewise. * romp/romp.c (unsigned_comparisons_p, hash_rtx): Likewise. * sh/sh.c (regs_used, mark_use): Likewise. * vax/vax.c (vax_rtx_cost): Likewise. From-SVN: r28784
1999-08-21 01:05:25 +02:00
register const char *fmt;
int depth = strlen (path);
char *newpath;
1991-10-24 18:21:48 +01:00
if (x == 0)
return;
code = GET_CODE (x);
switch (code)
{
case PC:
case CC0:
case CONST_INT:
case SYMBOL_REF:
return;
case MATCH_OPERAND:
case MATCH_SCRATCH:
oplocs[XINT (x, 0)] = xstrdup (path);
op_count = MAX (op_count, XINT (x, 0) + 1);
1991-10-24 18:21:48 +01:00
break;
case MATCH_DUP:
case MATCH_PAR_DUP:
duplocs[dup_count] = xstrdup (path);
dupnums[dup_count] = XINT (x, 0);
1991-10-24 18:21:48 +01:00
dup_count++;
break;
case MATCH_OP_DUP:
duplocs[dup_count] = xstrdup (path);
dupnums[dup_count] = XINT (x, 0);
dup_count++;
newpath = (char *) alloca (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
for (i = XVECLEN (x, 1) - 1; i >= 0; i--)
{
newpath[depth] = '0' + i;
walk_rtx (XVECEXP (x, 1, i), newpath);
}
return;
1991-10-24 18:21:48 +01:00
case MATCH_OPERATOR:
oplocs[XINT (x, 0)] = xstrdup (path);
op_count = MAX (op_count, XINT (x, 0) + 1);
newpath = (char *) alloca (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
1991-10-24 18:21:48 +01:00
for (i = XVECLEN (x, 2) - 1; i >= 0; i--)
{
newpath[depth] = '0' + i;
walk_rtx (XVECEXP (x, 2, i), newpath);
1991-10-24 18:21:48 +01:00
}
return;
case MATCH_PARALLEL:
oplocs[XINT (x, 0)] = xstrdup (path);
op_count = MAX (op_count, XINT (x, 0) + 1);
newpath = (char *) alloca (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
1991-10-24 18:21:48 +01:00
for (i = XVECLEN (x, 2) - 1; i >= 0; i--)
{
newpath[depth] = 'a' + i;
walk_rtx (XVECEXP (x, 2, i), newpath);
1991-10-24 18:21:48 +01:00
}
return;
case ADDRESS:
walk_rtx (XEXP (x, 0), path);
return;
default:
break;
1991-10-24 18:21:48 +01:00
}
newpath = (char *) alloca (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
1991-10-24 18:21:48 +01:00
fmt = GET_RTX_FORMAT (code);
len = GET_RTX_LENGTH (code);
for (i = 0; i < len; i++)
{
if (fmt[i] == 'e' || fmt[i] == 'u')
{
newpath[depth] = '0' + i;
walk_rtx (XEXP (x, i), newpath);
1991-10-24 18:21:48 +01:00
}
else if (fmt[i] == 'E')
{
int j;
for (j = XVECLEN (x, i) - 1; j >= 0; j--)
{
newpath[depth] = 'a' + j;
walk_rtx (XVECEXP (x, i, j), newpath);
1991-10-24 18:21:48 +01:00
}
}
}
}
/* Given a PATH, representing a path down the instruction's
pattern from the root to a certain point, output code to
evaluate to the rtx at that point. */
static void
print_path (path)
const char *path;
1991-10-24 18:21:48 +01:00
{
register int len = strlen (path);
register int i;
if (len == 0)
{
/* Don't emit "pat", since we may try to take the address of it,
which isn't what is intended. */
printf("PATTERN (insn)");
return;
}
/* We first write out the operations (XEXP or XVECEXP) in reverse
order, then write "insn", then the indices in forward order. */
for (i = len - 1; i >=0 ; i--)
1991-10-24 18:21:48 +01:00
{
if (ISLOWER(path[i]))
printf ("XVECEXP (");
else if (ISDIGIT(path[i]))
printf ("XEXP (");
else
abort ();
1991-10-24 18:21:48 +01:00
}
1992-05-04 16:04:43 +02:00
printf ("pat");
for (i = 0; i < len; i++)
1991-10-24 18:21:48 +01:00
{
if (ISLOWER(path[i]))
printf (", 0, %d)", path[i] - 'a');
else if (ISDIGIT(path[i]))
printf (", %d)", path[i] - '0');
else
abort ();
1991-10-24 18:21:48 +01:00
}
}
system.h: Include libiberty.h. * system.h: Include libiberty.h. * c-aux-info.c: Remove prototypes for concat/concat3. Change function `concat' from fixed parameters to variable parameters, as is done in libiberty. All callers of concat/concat3 changed to use the new `concat' with variable args. * cccp.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * cexp.y: Likewise. * collect2.c: Likewise. * config/1750a/1750a.h: Likewise. * cppalloc.c: Likewise. * cppexp.c: Likewise. * cppfiles.c: Likewise. * cpphash.c: Likewise. * cpplib.c: Likewise. * dyn-string.c: Likewise. * fix-header.c: Likewise. * gcc.c: Likewise. * gcov.c: Likewise. * genattr.c: Likewise. * genattrtab.c: Likewise. * gencheck.c: Likewise. * gencodes.c: Likewise. * genconfig.c: Likewise. * genemit.c: Likewise. * genextract.c: Likewise. * genflags.c: Likewise. * gengenrtl.c: Likewise. * genopinit.c: Likewise. * genoutput.c: Likewise. * genpeep.c: Likewise. * genrecog.c: Likewise. * getpwd.c: Likewise. * halfpic.c: Likewise. * hash.c: Likewise. * mips-tdump.c: Likewise. Wrap malloc/realloc/calloc prototypes in NEED_DECLARATION_* macros. * mips-tfile.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. (fatal): Fix const-ification of variable `format' in !ANSI_PROTOTYPES case. * prefix.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * print-rtl.c: Rename variable `spaces' to `xspaces' to avoid conflicting with function `spaces' from libiberty. * profile.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * protoize.c: Likewise. * rtl.h: Likewise. * scan.h: Likewise. * tlink.c: Likewise. * toplev.c: Likewise. * toplev.h: Likewise. * tree.h: Likewise. From-SVN: r23931
1998-11-27 11:09:17 +01:00
PTR
1991-10-24 18:21:48 +01:00
xmalloc (size)
system.h: Include libiberty.h. * system.h: Include libiberty.h. * c-aux-info.c: Remove prototypes for concat/concat3. Change function `concat' from fixed parameters to variable parameters, as is done in libiberty. All callers of concat/concat3 changed to use the new `concat' with variable args. * cccp.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * cexp.y: Likewise. * collect2.c: Likewise. * config/1750a/1750a.h: Likewise. * cppalloc.c: Likewise. * cppexp.c: Likewise. * cppfiles.c: Likewise. * cpphash.c: Likewise. * cpplib.c: Likewise. * dyn-string.c: Likewise. * fix-header.c: Likewise. * gcc.c: Likewise. * gcov.c: Likewise. * genattr.c: Likewise. * genattrtab.c: Likewise. * gencheck.c: Likewise. * gencodes.c: Likewise. * genconfig.c: Likewise. * genemit.c: Likewise. * genextract.c: Likewise. * genflags.c: Likewise. * gengenrtl.c: Likewise. * genopinit.c: Likewise. * genoutput.c: Likewise. * genpeep.c: Likewise. * genrecog.c: Likewise. * getpwd.c: Likewise. * halfpic.c: Likewise. * hash.c: Likewise. * mips-tdump.c: Likewise. Wrap malloc/realloc/calloc prototypes in NEED_DECLARATION_* macros. * mips-tfile.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. (fatal): Fix const-ification of variable `format' in !ANSI_PROTOTYPES case. * prefix.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * print-rtl.c: Rename variable `spaces' to `xspaces' to avoid conflicting with function `spaces' from libiberty. * profile.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * protoize.c: Likewise. * rtl.h: Likewise. * scan.h: Likewise. * tlink.c: Likewise. * toplev.c: Likewise. * toplev.h: Likewise. * tree.h: Likewise. From-SVN: r23931
1998-11-27 11:09:17 +01:00
size_t size;
1991-10-24 18:21:48 +01:00
{
system.h: Include libiberty.h. * system.h: Include libiberty.h. * c-aux-info.c: Remove prototypes for concat/concat3. Change function `concat' from fixed parameters to variable parameters, as is done in libiberty. All callers of concat/concat3 changed to use the new `concat' with variable args. * cccp.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * cexp.y: Likewise. * collect2.c: Likewise. * config/1750a/1750a.h: Likewise. * cppalloc.c: Likewise. * cppexp.c: Likewise. * cppfiles.c: Likewise. * cpphash.c: Likewise. * cpplib.c: Likewise. * dyn-string.c: Likewise. * fix-header.c: Likewise. * gcc.c: Likewise. * gcov.c: Likewise. * genattr.c: Likewise. * genattrtab.c: Likewise. * gencheck.c: Likewise. * gencodes.c: Likewise. * genconfig.c: Likewise. * genemit.c: Likewise. * genextract.c: Likewise. * genflags.c: Likewise. * gengenrtl.c: Likewise. * genopinit.c: Likewise. * genoutput.c: Likewise. * genpeep.c: Likewise. * genrecog.c: Likewise. * getpwd.c: Likewise. * halfpic.c: Likewise. * hash.c: Likewise. * mips-tdump.c: Likewise. Wrap malloc/realloc/calloc prototypes in NEED_DECLARATION_* macros. * mips-tfile.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. (fatal): Fix const-ification of variable `format' in !ANSI_PROTOTYPES case. * prefix.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * print-rtl.c: Rename variable `spaces' to `xspaces' to avoid conflicting with function `spaces' from libiberty. * profile.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * protoize.c: Likewise. * rtl.h: Likewise. * scan.h: Likewise. * tlink.c: Likewise. * toplev.c: Likewise. * toplev.h: Likewise. * tree.h: Likewise. From-SVN: r23931
1998-11-27 11:09:17 +01:00
register PTR val = (PTR) malloc (size);
1991-10-24 18:21:48 +01:00
if (val == 0)
fatal ("virtual memory exhausted");
return val;
}
system.h: Include libiberty.h. * system.h: Include libiberty.h. * c-aux-info.c: Remove prototypes for concat/concat3. Change function `concat' from fixed parameters to variable parameters, as is done in libiberty. All callers of concat/concat3 changed to use the new `concat' with variable args. * cccp.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * cexp.y: Likewise. * collect2.c: Likewise. * config/1750a/1750a.h: Likewise. * cppalloc.c: Likewise. * cppexp.c: Likewise. * cppfiles.c: Likewise. * cpphash.c: Likewise. * cpplib.c: Likewise. * dyn-string.c: Likewise. * fix-header.c: Likewise. * gcc.c: Likewise. * gcov.c: Likewise. * genattr.c: Likewise. * genattrtab.c: Likewise. * gencheck.c: Likewise. * gencodes.c: Likewise. * genconfig.c: Likewise. * genemit.c: Likewise. * genextract.c: Likewise. * genflags.c: Likewise. * gengenrtl.c: Likewise. * genopinit.c: Likewise. * genoutput.c: Likewise. * genpeep.c: Likewise. * genrecog.c: Likewise. * getpwd.c: Likewise. * halfpic.c: Likewise. * hash.c: Likewise. * mips-tdump.c: Likewise. Wrap malloc/realloc/calloc prototypes in NEED_DECLARATION_* macros. * mips-tfile.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. (fatal): Fix const-ification of variable `format' in !ANSI_PROTOTYPES case. * prefix.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * print-rtl.c: Rename variable `spaces' to `xspaces' to avoid conflicting with function `spaces' from libiberty. * profile.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * protoize.c: Likewise. * rtl.h: Likewise. * scan.h: Likewise. * tlink.c: Likewise. * toplev.c: Likewise. * toplev.h: Likewise. * tree.h: Likewise. From-SVN: r23931
1998-11-27 11:09:17 +01:00
PTR
xrealloc (old, size)
PTR old;
system.h: Include libiberty.h. * system.h: Include libiberty.h. * c-aux-info.c: Remove prototypes for concat/concat3. Change function `concat' from fixed parameters to variable parameters, as is done in libiberty. All callers of concat/concat3 changed to use the new `concat' with variable args. * cccp.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * cexp.y: Likewise. * collect2.c: Likewise. * config/1750a/1750a.h: Likewise. * cppalloc.c: Likewise. * cppexp.c: Likewise. * cppfiles.c: Likewise. * cpphash.c: Likewise. * cpplib.c: Likewise. * dyn-string.c: Likewise. * fix-header.c: Likewise. * gcc.c: Likewise. * gcov.c: Likewise. * genattr.c: Likewise. * genattrtab.c: Likewise. * gencheck.c: Likewise. * gencodes.c: Likewise. * genconfig.c: Likewise. * genemit.c: Likewise. * genextract.c: Likewise. * genflags.c: Likewise. * gengenrtl.c: Likewise. * genopinit.c: Likewise. * genoutput.c: Likewise. * genpeep.c: Likewise. * genrecog.c: Likewise. * getpwd.c: Likewise. * halfpic.c: Likewise. * hash.c: Likewise. * mips-tdump.c: Likewise. Wrap malloc/realloc/calloc prototypes in NEED_DECLARATION_* macros. * mips-tfile.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. (fatal): Fix const-ification of variable `format' in !ANSI_PROTOTYPES case. * prefix.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * print-rtl.c: Rename variable `spaces' to `xspaces' to avoid conflicting with function `spaces' from libiberty. * profile.c: Remove things made redundant by libiberty.h and/or conform to libiberty standards. * protoize.c: Likewise. * rtl.h: Likewise. * scan.h: Likewise. * tlink.c: Likewise. * toplev.c: Likewise. * toplev.h: Likewise. * tree.h: Likewise. From-SVN: r23931
1998-11-27 11:09:17 +01:00
size_t size;
1991-10-24 18:21:48 +01:00
{
register PTR ptr;
if (old)
ptr = (PTR) realloc (old, size);
else
ptr = (PTR) malloc (size);
if (!ptr)
1991-10-24 18:21:48 +01:00
fatal ("virtual memory exhausted");
return ptr;
1991-10-24 18:21:48 +01:00
}
char *
1999-01-13 12:49:34 +01:00
xstrdup (input)
const char *input;
{
register size_t len = strlen (input) + 1;
register char *output = xmalloc (len);
memcpy (output, input, len);
return output;
}
1991-10-24 18:21:48 +01:00
extern int main PARAMS ((int, char **));
1991-10-24 18:21:48 +01:00
int
main (argc, argv)
int argc;
char **argv;
{
rtx desc;
FILE *infile;
int c, i;
struct extraction *p;
struct code_ptr *link;
const char *name;
1991-10-24 18:21:48 +01:00
progname = "genextract";
1991-10-24 18:21:48 +01:00
obstack_init (rtl_obstack);
if (argc <= 1)
fatal ("No input file name.");
infile = fopen (argv[1], "r");
if (infile == 0)
{
perror (argv[1]);
return (FATAL_EXIT_CODE);
1991-10-24 18:21:48 +01:00
}
read_rtx_filename = argv[1];
1991-10-24 18:21:48 +01:00
/* Assign sequential codes to all entries in the machine description
in parallel with the tables in insn-output.c. */
insn_code_number = 0;
printf ("/* Generated automatically by the program `genextract'\n\
from the machine description file `md'. */\n\n");
printf ("#include \"config.h\"\n");
printf ("#include \"system.h\"\n");
Makefile.in (toplev.o): Depend on $(EXPR_H). * Makefile.in (toplev.o): Depend on $(EXPR_H). (insn-extract.o, insn-attrtab.o): Depend on toplev.h. * gansidecl.h: Define ATTRIBUTE_NORETURN. * genattrtab.c: Have insn-attrtab.c include toplev.h. * genextract.c: Have insn-extract.c include toplev.h. * rtl.h: Don't prototype `fatal_insn_not_found' and `fatal_insn'. * toplev.c: Include expr.h. (really_sorry, fancy_abort): Remove prototypes. (set_target_switch): Add argument in prototype. (vfatal): Mark prototype with ATTRIBUTE_NORETURN. (v_really_sorry): Likewise. (print_version, print_single_switch, print_switch_values): Make static and add prototype arguments. (decl_printable_name): Add prototype arguments. (lang_expand_expr_t): New typedef. (lang_expand_expr): Declare as a lang_expand_expr_t. (incomplete_decl_finalize_hook): Add prototype argument. (decl_name): Mark variable `verbosity' with ATTRIBUTE_UNUSED. (botch): Likewise for variable `s'. (rest_of_type_compilation): Mark variables `type' and `toplev' with ATTRIBUTE_UNUSED if none of DBX_DEBUGGING_INFO, XCOFF_DEBUGGING_INFO or SDB_DEBUGGING_INFO are defined. (display_help): Make variable `i' an `unsigned long'. (main): Remove unused parameter `envp'. Cast assignment to `lang_expand_expr' to a `lang_expand_expr_t'. Cast -1 when comparing it with a `size_t'. * toplev.h (fatal, fatal_io_error, pfatal_with_name): Mark prototype with ATTRIBUTE_NORETURN. (fatal_insn_not_found, fatal_insn, really_sorry, push_float_handler, pop_float_handler): Add prototypes. (fancy_abort): Mark prototype with ATTRIBUTE_NORETURN. (do_abort, botch): Add prototypes. From-SVN: r22293
1998-09-06 07:56:20 +02:00
printf ("#include \"rtl.h\"\n");
printf ("#include \"insn-config.h\"\n");
printf ("#include \"recog.h\"\n");
Makefile.in (toplev.o): Depend on $(EXPR_H). * Makefile.in (toplev.o): Depend on $(EXPR_H). (insn-extract.o, insn-attrtab.o): Depend on toplev.h. * gansidecl.h: Define ATTRIBUTE_NORETURN. * genattrtab.c: Have insn-attrtab.c include toplev.h. * genextract.c: Have insn-extract.c include toplev.h. * rtl.h: Don't prototype `fatal_insn_not_found' and `fatal_insn'. * toplev.c: Include expr.h. (really_sorry, fancy_abort): Remove prototypes. (set_target_switch): Add argument in prototype. (vfatal): Mark prototype with ATTRIBUTE_NORETURN. (v_really_sorry): Likewise. (print_version, print_single_switch, print_switch_values): Make static and add prototype arguments. (decl_printable_name): Add prototype arguments. (lang_expand_expr_t): New typedef. (lang_expand_expr): Declare as a lang_expand_expr_t. (incomplete_decl_finalize_hook): Add prototype argument. (decl_name): Mark variable `verbosity' with ATTRIBUTE_UNUSED. (botch): Likewise for variable `s'. (rest_of_type_compilation): Mark variables `type' and `toplev' with ATTRIBUTE_UNUSED if none of DBX_DEBUGGING_INFO, XCOFF_DEBUGGING_INFO or SDB_DEBUGGING_INFO are defined. (display_help): Make variable `i' an `unsigned long'. (main): Remove unused parameter `envp'. Cast assignment to `lang_expand_expr' to a `lang_expand_expr_t'. Cast -1 when comparing it with a `size_t'. * toplev.h (fatal, fatal_io_error, pfatal_with_name): Mark prototype with ATTRIBUTE_NORETURN. (fatal_insn_not_found, fatal_insn, really_sorry, push_float_handler, pop_float_handler): Add prototypes. (fancy_abort): Mark prototype with ATTRIBUTE_NORETURN. (do_abort, botch): Add prototypes. From-SVN: r22293
1998-09-06 07:56:20 +02:00
printf ("#include \"toplev.h\"\n\n");
1991-10-24 18:21:48 +01:00
/* This variable exists only so it can be the "location"
of any missing operand whose numbers are skipped by a given pattern. */
Warning fixes: * Makefile.in (c-lang.o): Depend on c-tree.h, c-lex.h and toplev.h. (c-lex.o): Depend on output.h. (c-common.o): Likewise. (stmt.o): Likewise. (calls.o): Likewise. (integrate.o): Depend on toplev.h. (regclass.o): Depend on output.h. (final.o): Depend on reload.h. * c-common.c: Include output.h. (check_format_info): Remove unused variable `integral_format'. * c-decl.c (print_lang_decl): Mark parameters `file', `node' and `indent' with ATTRIBUTE_UNUSED. (print_lang_type): Likewise. (maybe_build_cleanup): Likewise for parameter `decl'. (copy_lang_decl): Likewise for parameter `node'. * c-lang.c: Include c-tree.h, c-lex.h and toplev.h. (lang_print_xnode): Mark parameters `file', `node' and `indent' with ATTRIBUTE_UNUSED. (lookup_interface): Likewise for parameter `arg'. (is_class_name): Likewise. (maybe_objc_check_decl): Likewise for parameter `decl'. (maybe_objc_comptypes): Likewise for parameters `lhs', `rhs' and `reflexive'. (maybe_objc_method_name): Likewise for parameter `decl'. (build_objc_string): Likewise for parameters `len' and `str'. * c-lex.c: Include output.h. * c-lex.h (position_after_white_space): Correct typo in prototype. * c-tree.h (finish_file, c_expand_start_cond, c_expand_start_else, c_expand_end_cond, init_iterators): Add prototypes. * caller-save.c (set_reg_live): Mark parameters `reg' and `setter' with ATTRIBUTE_UNUSED. * calls.c: Include output.h. * cccp.c (pipe_closed): Mark parameter `signo' with ATTRIBUTE_UNUSED. * combine.c: Move inclusion of expr.h to after insn-config.h. * iris6.h (ASM_IDENTIFY_GCC, ASM_IDENTIFY_LANGUAGE): Don't define as empty, rather define as ((void)0). * sparc.c (sparc_check_64): Add braces around ambiguous `else'. Add parentheses around assignment used as truth value. * cplus-dem.c (squangle_mop_up): Change return type to void. (internal_cplus_demangle): Remove unused parameter `options'. All callers changed. (cplus_demangle_opname): Remove function wide variable `int i' and replace with `size_t i' at each location where it is used. (cplus_demangle_opname): change type of `i' from int to size_t. * cppexp.c (right_shift): Mark parameter `pfile' with ATTRIBUTE_UNUSED. * cpphash.c (cpp_lookup): Likewise. (cpp_hash_cleanup): Likewise. * cpplib.c (parse_name): Add a prototype and make it static. (null_underflow): Mark parameter `pfile' with ATTRIBUTE_UNUSED. (null_cleanup): Likewise for parameters `pbuf' and `pfile'. (macro_cleanup): Likewise for parameter `pfile'. (file_cleanup): Likewise. * cpplib.h (cpp_reader_init, cpp_options_init, cpp_start_read, cpp_read_check_assertion, skip_rest_of_line): Add prototypes. * crtstuff.c (force_to_data, __CTOR_LIST__, force_to_data, __DTOR_END__, __FRAME_END__): Mark with ATTRIBUTE_UNUSED. * cse.c (cse_check_loop_start): Mark parameter `set' with ATTRIBUTE_UNUSED. * dbxout.c (flag_minimal_debug, have_used_extensions, source_label_number): Move inside macro wrapper check against defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO). * dwarf2out.c (gen_entry_point_die): Hide prototype and definition. * except.h (doing_eh): Provide prototype. * expr.c: Move inclusion of expr.h to after insn-config.h. * final.c: Include reload.h. (shorten_branches): Cast the first argument of bzero to char *. * fix-header.c (cpp_print_containing_files): Mark parameter `pfile' with ATTRIBUTE_UNUSED. (cpp_fatal): Likewise. * flow.c (find_basic_blocks_1): Cast the first argument of bzero to char *. * genattrtab.c (make_length_attrs): Change the type of variable `i' from int to size_t. (zero_fn): Mark parameter `exp' with ATTRIBUTE_UNUSED. (one_fn): Likewise. * genextract.c (main): When generating insn-extract.c, mark variable `junk' with ATTRIBUTE_UNUSED. * gengenrtl.c (gencode): When generating genrtl.c, cast the first argument of bzero to char*. * integrate.c: Include toplev.h. * libgcc2.c: Wrap `struct exception_table' and `find_exception_handler' in macro DWARF2_UNWIND_INFO. * objc/Make-lang.in (objc-act.o): Depend on toplev.h. * objc/objc-act.c: Include toplev.h. (lang_print_xnode): Mark parameters `file', `node' and `indent' with ATTRIBUTE_UNUSED. (finish_protocol): Likewise for parameter `protocol'. * output.h (declare_weak): Add prototype. (decode_reg_name): Don't wrap with TREE_CODE macro. (assemble_alias): Add prototype. * regclass.c: Include output.h. * reload.h (reloads_conflict): Add prototype. * rtl.h (print_rtl_single, mark_elimiation, reg_class_subset_p, output_func_start_profiler): Add prototypes. * rtlanal.c (reg_set_p_1): Mark parameters `x' and `pat' with ATTRIBUTE_UNUSED. * scan-decls.c: Include scan.h. * scan.h (recognized_function, recognized_extern): Add prototypes. * stmt.c: Include output.h. * toplev.c (error_for_asm, warning_for_asm): Remove prototypes. (output_lang_identify): Hide prototype and definition. (float_signal): Mark parameter `signo' with ATTRIBUTE_UNUSED. (pipe_closed): Likewise. * toplev.h (count_error, strip_off_ending, error_for_asm, warning_for_asm): Add prototypes. From-SVN: r19712
1998-05-13 14:40:39 +02:00
printf ("static rtx junk ATTRIBUTE_UNUSED;\n");
1991-10-24 18:21:48 +01:00
printf ("void\ninsn_extract (insn)\n");
printf (" rtx insn;\n");
printf ("{\n");
printf (" register rtx *ro = recog_data.operand;\n");
printf (" register rtx **ro_loc = recog_data.operand_loc;\n");
1992-05-04 16:04:43 +02:00
printf (" rtx pat = PATTERN (insn);\n");
printf (" int i ATTRIBUTE_UNUSED;\n\n");
printf (" memset (ro, 0, sizeof (*ro) * MAX_RECOG_OPERANDS);\n");
printf (" memset (ro_loc, 0, sizeof (*ro_loc) * MAX_RECOG_OPERANDS);\n");
1992-05-04 16:04:43 +02:00
printf (" switch (INSN_CODE (insn))\n");
1991-10-24 18:21:48 +01:00
printf (" {\n");
printf (" case -1:\n");
printf (" fatal_insn_not_found (insn);\n\n");
1991-10-24 18:21:48 +01:00
/* Read the machine description. */
while (1)
{
c = read_skip_spaces (infile);
if (c == EOF)
break;
ungetc (c, infile);
desc = read_rtx (infile);
if (GET_CODE (desc) == DEFINE_INSN)
{
record_insn_name (insn_code_number, XSTR (desc, 0));
1991-10-24 18:21:48 +01:00
gen_insn (desc);
++insn_code_number;
}
else if (GET_CODE (desc) == DEFINE_PEEPHOLE)
1991-10-24 18:21:48 +01:00
{
struct code_ptr *link
= (struct code_ptr *) xmalloc (sizeof (struct code_ptr));
link->insn_code = insn_code_number;
link->next = peepholes;
peepholes = link;
1991-10-24 18:21:48 +01:00
++insn_code_number;
}
else if (GET_CODE (desc) == DEFINE_EXPAND
backport: Makefile.in (STAGESTUFF): Add *.peephole2. Merge peephole2 from new_ia32_branch: * Makefile.in (STAGESTUFF): Add *.peephole2. (mostlyclean): Likewise. (recog.o): Depend on resource.h. * final.c (peephole): Conditionalize decl on HAVE_peephole. (final_scan_insn): Likewise for the invocation of peephole. * genconfig.c (main): Look for peephole and peephole2 patterns. Emit HAVE_peephole* accordingly. * genpeep.c (main): Conditionalize entire output on HAVE_peephole. * flags.h (flag_peephole2): Declare. * toplev.c: New pass peephole2. New flag -fpeephole2. * genattrtab.c (main): Count DEFINE_PEEPHOLE2. * gencodes.c (main): Likewise. * genextract.c (main): Likewise. * genoutput.c (main): Likewise. * genemit.c (max_operand_1): Look for the max scratch operand. (gen_rtx_scratch): New. (gen_exp): Use it, and pass on new arg subroutine_type. (gen_expand): Take max scratch into account. (gen_split): Emit peephole2 functions. (output_peephole2_scratch): New. (main): Include hard-reg-set.h and resource.h. Handle peephole2. * genrecog.c (routine_type): Add PEEPHOLE2. (IS_SPLIT): New. (make_insn_sequence): Match outer parallel for peep2. Discard top level scratches and dups. (add_to_sequence): New args insn_type and top. Update all callers. Handle toplevel peep2 matching insns. (write_subroutine): Handle peep2. (write_tree_1): Likewise. (write_tree): Likewise. (main): Likewise. (change_state): New arg afterward. Update all callers. Handle matching separate insns. * recog.c (recog_next_insn): New. (peephole2_optimize): New. * rtl.def (DEFINE_PEEPHOLE2): New. * resource.c (find_free_register): New argument last_insn. Use it to find a register available through the entire span. * resource.h (find_free_register): Update prototype. From-SVN: r29015
1999-08-31 22:37:09 +02:00
|| GET_CODE (desc) == DEFINE_PEEPHOLE2
|| GET_CODE (desc) == DEFINE_SPLIT)
++insn_code_number;
}
1991-10-24 18:21:48 +01:00
/* Write out code to handle peepholes and the insn_codes that it should
be called for. */
if (peepholes)
1991-10-24 18:21:48 +01:00
{
for (link = peepholes; link; link = link->next)
printf (" case %d:\n", link->insn_code);
1991-10-24 18:21:48 +01:00
/* The vector in the insn says how many operands it has.
And all it contains are operands. In fact, the vector was
created just for the sake of this function. */
printf (" for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)\n");
printf (" ro[i] = XVECEXP (pat, 0, i);\n");
printf (" break;\n\n");
}
/* Write out all the ways to extract insn operands. */
for (p = extractions; p; p = p->next)
{
for (link = p->insns; link; link = link->next)
{
i = link->insn_code;
name = get_insn_name (i);
if (name)
printf (" case %d: /* %s */\n", i, name);
else
printf (" case %d:\n", i);
}
for (i = 0; i < p->op_count; i++)
{
if (p->oplocs[i] == 0)
{
printf (" ro[%d] = const0_rtx;\n", i);
printf (" ro_loc[%d] = &junk;\n", i);
}
else
{
printf (" ro[%d] = *(ro_loc[%d] = &", i, i);
print_path (p->oplocs[i]);
printf (");\n");
}
}
for (i = 0; i < p->dup_count; i++)
{
printf (" recog_data.dup_loc[%d] = &", i);
print_path (p->duplocs[i]);
printf (";\n");
printf (" recog_data.dup_num[%d] = %d;\n", i, p->dupnums[i]);
}
printf (" break;\n\n");
1991-10-24 18:21:48 +01:00
}
/* This should never be reached. Note that we would also reach this abort
if we tried to extract something whose INSN_CODE was a DEFINE_EXPAND or
DEFINE_SPLIT, but that is correct. */
printf (" default:\n abort ();\n");
1991-10-24 18:21:48 +01:00
printf (" }\n}\n");
fflush (stdout);
return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
1991-10-24 18:21:48 +01:00
}
/* Define this so we can link with print-rtl.o to get debug_rtx function. */
const char *
get_insn_name (code)
int code ATTRIBUTE_UNUSED;
{
if (code < insn_name_ptr_size)
return insn_name_ptr[code];
else
return NULL;
}
static void
record_insn_name (code, name)
int code;
const char *name;
{
static const char *last_real_name = "insn";
static int last_real_code = 0;
char *new;
if (insn_name_ptr_size <= code)
{
int new_size;
new_size = (insn_name_ptr_size ? insn_name_ptr_size * 2 : 512);
insn_name_ptr =
(char **) xrealloc (insn_name_ptr, sizeof(char *) * new_size);
memset (insn_name_ptr + insn_name_ptr_size, 0,
sizeof(char *) * (new_size - insn_name_ptr_size));
insn_name_ptr_size = new_size;
}
if (!name || name[0] == '\0')
{
new = xmalloc (strlen (last_real_name) + 10);
sprintf (new, "%s+%d", last_real_name, code - last_real_code);
}
else
{
last_real_name = new = xstrdup (name);
last_real_code = code;
}
insn_name_ptr[code] = new;
}