1991-10-24 13:21:48 -04:00
|
|
|
|
/* Generate attribute information (insn-attr.h) from machine description.
|
1992-01-17 18:03:50 -05:00
|
|
|
|
Copyright (C) 1991 Free Software Foundation, Inc.
|
1991-10-24 13:21:48 -04:00
|
|
|
|
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 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
|
|
|
|
|
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "rtl.h"
|
|
|
|
|
#include "obstack.h"
|
|
|
|
|
|
|
|
|
|
static struct obstack obstack;
|
|
|
|
|
struct obstack *rtl_obstack = &obstack;
|
|
|
|
|
|
|
|
|
|
#define obstack_chunk_alloc xmalloc
|
|
|
|
|
#define obstack_chunk_free free
|
|
|
|
|
|
|
|
|
|
extern void free ();
|
|
|
|
|
extern int atoi ();
|
1992-04-27 15:09:11 -04:00
|
|
|
|
extern rtx read_rtx ();
|
1991-10-24 13:21:48 -04:00
|
|
|
|
|
|
|
|
|
char *xmalloc ();
|
|
|
|
|
static void fatal ();
|
|
|
|
|
void fancy_abort ();
|
|
|
|
|
|
1992-08-14 18:49:34 -04:00
|
|
|
|
struct namelist
|
|
|
|
|
{
|
|
|
|
|
struct namelist *next;
|
|
|
|
|
char *name;
|
|
|
|
|
};
|
|
|
|
|
|
1991-10-24 13:21:48 -04:00
|
|
|
|
static void
|
|
|
|
|
write_upcase (str)
|
|
|
|
|
char *str;
|
|
|
|
|
{
|
|
|
|
|
for (; *str; str++)
|
|
|
|
|
if (*str >= 'a' && *str <= 'z')
|
|
|
|
|
printf ("%c", *str - 'a' + 'A');
|
|
|
|
|
else
|
|
|
|
|
printf ("%c", *str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gen_attr (attr)
|
|
|
|
|
rtx attr;
|
|
|
|
|
{
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0));
|
|
|
|
|
|
|
|
|
|
/* If numeric attribute, don't need to write an enum. */
|
|
|
|
|
if (*XSTR (attr, 1) == '\0')
|
|
|
|
|
printf ("extern int get_attr_%s ();\n", XSTR (attr, 0));
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf ("enum attr_%s {", XSTR (attr, 0));
|
|
|
|
|
write_upcase (XSTR (attr, 0));
|
|
|
|
|
printf ("_");
|
|
|
|
|
|
|
|
|
|
for (p = XSTR (attr, 1); *p != '\0'; p++)
|
|
|
|
|
{
|
|
|
|
|
if (*p == ',')
|
|
|
|
|
{
|
|
|
|
|
printf (", ");
|
|
|
|
|
write_upcase (XSTR (attr, 0));
|
|
|
|
|
printf ("_");
|
|
|
|
|
}
|
|
|
|
|
else if (*p >= 'a' && *p <= 'z')
|
|
|
|
|
printf ("%c", *p - 'a' + 'A');
|
|
|
|
|
else
|
|
|
|
|
printf ("%c", *p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf ("};\n");
|
|
|
|
|
printf ("extern enum attr_%s get_attr_%s ();\n\n",
|
|
|
|
|
XSTR (attr, 0), XSTR (attr, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If `length' attribute, write additional function definitions and define
|
|
|
|
|
variables used by `insn_current_length'. */
|
|
|
|
|
if (! strcmp (XSTR (attr, 0), "length"))
|
|
|
|
|
{
|
|
|
|
|
printf ("extern void init_lengths ();\n");
|
|
|
|
|
printf ("extern void shorten_branches ();\n");
|
|
|
|
|
printf ("extern int insn_default_length ();\n");
|
|
|
|
|
printf ("extern int insn_variable_length_p ();\n");
|
|
|
|
|
printf ("extern int insn_current_length ();\n\n");
|
|
|
|
|
printf ("extern int *insn_addresses;\n");
|
|
|
|
|
printf ("extern int insn_current_address;\n\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1992-08-14 18:49:34 -04:00
|
|
|
|
write_units (num_units, min_ready_cost, max_ready_cost,
|
|
|
|
|
min_busy_delay, max_busy_delay)
|
1991-10-24 13:21:48 -04:00
|
|
|
|
{
|
|
|
|
|
printf ("#define INSN_SCHEDULING\n\n");
|
|
|
|
|
printf ("extern int result_ready_cost ();\n");
|
|
|
|
|
printf ("extern int function_units_used ();\n\n");
|
|
|
|
|
printf ("extern struct function_unit_desc\n");
|
|
|
|
|
printf ("{\n");
|
|
|
|
|
printf (" char *name;\n");
|
|
|
|
|
printf (" int bitmask;\n");
|
|
|
|
|
printf (" int multiplicity;\n");
|
|
|
|
|
printf (" int simultaneity;\n");
|
|
|
|
|
printf (" int default_cost;\n");
|
1992-08-14 18:49:34 -04:00
|
|
|
|
printf (" int max_busy_cost;\n");
|
1991-10-24 13:21:48 -04:00
|
|
|
|
printf (" int (*ready_cost_function) ();\n");
|
|
|
|
|
printf (" int (*conflict_cost_function) ();\n");
|
|
|
|
|
printf ("} function_units[];\n\n");
|
1992-08-14 18:49:34 -04:00
|
|
|
|
printf ("#define FUNCTION_UNITS_SIZE %d\n", num_units);
|
|
|
|
|
printf ("#define MIN_READY_COST %d\n", min_ready_cost);
|
|
|
|
|
printf ("#define MAX_READY_COST %d\n", max_ready_cost);
|
|
|
|
|
printf ("#define MIN_BUSY_DELAY %d\n", min_busy_delay);
|
|
|
|
|
printf ("#define MAX_BUSY_DELAY %d\n\n", max_busy_delay);
|
1991-10-24 13:21:48 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
xmalloc (size)
|
|
|
|
|
unsigned size;
|
|
|
|
|
{
|
|
|
|
|
register char *val = (char *) malloc (size);
|
|
|
|
|
|
|
|
|
|
if (val == 0)
|
|
|
|
|
fatal ("virtual memory exhausted");
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
xrealloc (ptr, size)
|
|
|
|
|
char *ptr;
|
|
|
|
|
unsigned size;
|
|
|
|
|
{
|
|
|
|
|
char * result = (char *) realloc (ptr, size);
|
|
|
|
|
if (!result)
|
|
|
|
|
fatal ("virtual memory exhausted");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fatal (s, a1, a2)
|
|
|
|
|
char *s;
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "genattr: ");
|
|
|
|
|
fprintf (stderr, s, a1, a2);
|
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
|
exit (FATAL_EXIT_CODE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* More 'friendly' abort that prints the line and file.
|
|
|
|
|
config.h can #define abort fancy_abort if you like that sort of thing. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fancy_abort ()
|
|
|
|
|
{
|
|
|
|
|
fatal ("Internal gcc abort.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (argc, argv)
|
|
|
|
|
int argc;
|
|
|
|
|
char **argv;
|
|
|
|
|
{
|
|
|
|
|
rtx desc;
|
|
|
|
|
FILE *infile;
|
|
|
|
|
register int c;
|
|
|
|
|
int have_delay = 0;
|
|
|
|
|
int have_annul_true = 0;
|
|
|
|
|
int have_annul_false = 0;
|
|
|
|
|
int have_units = 0;
|
1992-08-14 18:49:34 -04:00
|
|
|
|
int num_units = 0;
|
|
|
|
|
int min_ready_cost = 100000, max_ready_cost = -1;
|
|
|
|
|
int min_busy_delay = 100000, max_busy_delay = -1;
|
|
|
|
|
struct namelist *units = 0;
|
1991-10-24 13:21:48 -04:00
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
obstack_init (rtl_obstack);
|
|
|
|
|
|
|
|
|
|
if (argc <= 1)
|
|
|
|
|
fatal ("No input file name.");
|
|
|
|
|
|
|
|
|
|
infile = fopen (argv[1], "r");
|
|
|
|
|
if (infile == 0)
|
|
|
|
|
{
|
|
|
|
|
perror (argv[1]);
|
|
|
|
|
exit (FATAL_EXIT_CODE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_rtl ();
|
|
|
|
|
|
|
|
|
|
printf ("/* Generated automatically by the program `genattr'\n\
|
|
|
|
|
from the machine description file `md'. */\n\n");
|
|
|
|
|
|
|
|
|
|
/* For compatibility, define the attribute `alternative', which is just
|
|
|
|
|
a reference to the variable `which_alternative'. */
|
|
|
|
|
|
|
|
|
|
printf ("#define HAVE_ATTR_alternative\n");
|
|
|
|
|
printf ("#define get_attr_alternative(insn) which_alternative\n");
|
|
|
|
|
|
|
|
|
|
/* 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_ATTR)
|
|
|
|
|
gen_attr (desc);
|
|
|
|
|
|
|
|
|
|
else if (GET_CODE (desc) == DEFINE_DELAY)
|
|
|
|
|
{
|
|
|
|
|
if (! have_delay)
|
|
|
|
|
{
|
|
|
|
|
printf ("#define DELAY_SLOTS\n");
|
|
|
|
|
printf ("extern int num_delay_slots ();\n");
|
|
|
|
|
printf ("extern int eligible_for_delay ();\n\n");
|
|
|
|
|
have_delay = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < XVECLEN (desc, 1); i += 3)
|
|
|
|
|
{
|
|
|
|
|
if (XVECEXP (desc, 1, i + 1) && ! have_annul_true)
|
|
|
|
|
{
|
|
|
|
|
printf ("#define ANNUL_IFTRUE_SLOTS\n");
|
|
|
|
|
printf ("extern int eligible_for_annul_true ();\n");
|
|
|
|
|
have_annul_true = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (XVECEXP (desc, 1, i + 2) && ! have_annul_false)
|
|
|
|
|
{
|
|
|
|
|
printf ("#define ANNUL_IFFALSE_SLOTS\n");
|
|
|
|
|
printf ("extern int eligible_for_annul_false ();\n");
|
|
|
|
|
have_annul_false = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1992-08-14 18:49:34 -04:00
|
|
|
|
else if (GET_CODE (desc) == DEFINE_FUNCTION_UNIT)
|
1991-10-24 13:21:48 -04:00
|
|
|
|
{
|
1992-08-14 18:49:34 -04:00
|
|
|
|
struct namelist *unit;
|
|
|
|
|
char *name = XSTR (desc, 0);
|
|
|
|
|
int ready_cost = XINT (desc, 4);
|
|
|
|
|
int busy_delay = XINT (desc, 5);
|
|
|
|
|
|
1991-10-24 13:21:48 -04:00
|
|
|
|
have_units = 1;
|
1992-08-14 18:49:34 -04:00
|
|
|
|
if (min_ready_cost > ready_cost) min_ready_cost = ready_cost;
|
|
|
|
|
if (max_ready_cost < ready_cost) max_ready_cost = ready_cost;
|
|
|
|
|
if (min_busy_delay > busy_delay) min_busy_delay = busy_delay;
|
|
|
|
|
if (max_busy_delay < busy_delay) max_busy_delay = busy_delay;
|
|
|
|
|
|
|
|
|
|
/* If the optional conflict vector was specified, the busy delay
|
|
|
|
|
may be zero. */
|
|
|
|
|
if (XVEC (desc, 6) != 0) min_busy_delay = 0;
|
|
|
|
|
|
|
|
|
|
for (unit = units; unit; unit = unit->next)
|
|
|
|
|
if (strcmp (unit->name, name) == 0)
|
|
|
|
|
break;
|
|
|
|
|
if (unit == 0)
|
|
|
|
|
{
|
|
|
|
|
int len = strlen (name) + 1;
|
|
|
|
|
unit = (struct namelist *) alloca (sizeof (struct namelist));
|
|
|
|
|
unit->name = (char *) alloca (len);
|
|
|
|
|
bcopy (name, unit->name, len);
|
|
|
|
|
unit->next = units;
|
|
|
|
|
units = unit;
|
|
|
|
|
num_units++;
|
|
|
|
|
}
|
1991-10-24 13:21:48 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1992-08-14 18:49:34 -04:00
|
|
|
|
if (have_units)
|
|
|
|
|
write_units (num_units, min_ready_cost, max_ready_cost,
|
|
|
|
|
min_busy_delay, max_busy_delay);
|
|
|
|
|
|
1991-10-24 13:21:48 -04:00
|
|
|
|
fflush (stdout);
|
|
|
|
|
exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|