This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: SH: use register names instead of numbers
- To: rth at redhat dot com (Richard Henderson)
- Subject: Re: SH: use register names instead of numbers
- From: Joern Rennecke <amylaar at redhat dot com>
- Date: Tue, 21 Nov 2000 21:42:40 +0000 (GMT)
- Cc: amylaar at redhat dot com (Joern Rennecke), zackw at Stanford dot EDU (Zack Weinberg), aoliva at redhat dot com (Alexandre Oliva), gcc-patches at gcc dot gnu dot org
> On Mon, Nov 20, 2000 at 11:06:03PM +0000, Joern Rennecke wrote:
> > If I write a patch for this, is someone willing to review it?
>
> Yes.
Ok, here it is:
Tue Nov 21 21:31:43 2000 J"orn Rennecke <amylaar@redhat.com>
* rtl.h (traverse_md_constants): Declare.
(struct md_constant): Define.
* Makefile.in (HOST_RTL): Add hashtab.o .
(OBJS): Add hashtab.o .
(hashtab.o): New rule.
(rtl.o): Depends on HASHTAB_H.
* rtl.c (hashtab.h): #include.
(md_constants): New static variable.
(def_hash, def_name_eq_p, read_constants): New static functions.
(traverse_md_constants): New function.
(read_name): Do constant expansion.
(read_rtx): Recognize define_constants.
* gencodes.c (print_md_constant): New function.
(main): Emit #defines for all constant definitions encountered.
Index: rtl.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/rtl.h,v
retrieving revision 1.170
diff -p -r1.170 rtl.h
*** rtl.h 2000/10/16 22:11:02 1.170
--- rtl.h 2000/11/21 21:38:22
*************** extern void init_varasm_once PARAMS ((v
*** 1973,1978 ****
--- 1973,1981 ----
/* In rtl.c */
extern void init_rtl PARAMS ((void));
extern void rtx_free PARAMS ((rtx));
+ extern void traverse_md_constants PARAMS ((int (*) (void **, void *),
+ void *));
+ struct md_constant { char *name, *value; };
#ifdef BUFSIZ
extern int read_skip_spaces PARAMS ((FILE *));
Index: Makefile.in
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/Makefile.in,v
retrieving revision 1.860
diff -p -r1.860 Makefile.in
*** Makefile.in 2000/10/19 20:54:38 1.860
--- Makefile.in 2000/11/21 21:38:23
*************** HOST_LIBS = $(USE_HOST_OBSTACK) $(USE_HO
*** 643,649 ****
$(USE_HOST_VFPRINTF) $(USE_HOST_DOPRINT) $(HOST_CLIB)
HOST_RTL = $(HOST_PREFIX)rtl.o $(HOST_PREFIX)bitmap.o \
! $(HOST_PREFIX)ggc-none.o gensupport.o
HOST_PRINT = $(HOST_PREFIX)print-rtl.o
HOST_ERRORS = $(HOST_PREFIX)errors.o
--- 643,649 ----
$(USE_HOST_VFPRINTF) $(USE_HOST_DOPRINT) $(HOST_CLIB)
HOST_RTL = $(HOST_PREFIX)rtl.o $(HOST_PREFIX)bitmap.o \
! $(HOST_PREFIX)ggc-none.o gensupport.o hashtab.o
HOST_PRINT = $(HOST_PREFIX)print-rtl.o
HOST_ERRORS = $(HOST_PREFIX)errors.o
*************** OBJS = diagnostic.o version.o tree.o pri
*** 750,756 ****
profile.o insn-attrtab.o $(out_object_file) $(EXTRA_OBJS) convert.o \
mbchar.o splay-tree.o graph.o sbitmap.o resource.o hash.o predict.o \
lists.o ggc-common.o $(GGC) simplify-rtx.o ssa.o bb-reorder.o \
! sibcall.o conflict.o timevar.o ifcvt.o dependence.o dce.o
BACKEND = toplev.o libbackend.a
--- 750,756 ----
profile.o insn-attrtab.o $(out_object_file) $(EXTRA_OBJS) convert.o \
mbchar.o splay-tree.o graph.o sbitmap.o resource.o hash.o predict.o \
lists.o ggc-common.o $(GGC) simplify-rtx.o ssa.o bb-reorder.o \
! sibcall.o conflict.o timevar.o ifcvt.o dependence.o dce.o hashtab.o
BACKEND = toplev.o libbackend.a
*************** varasm.o : varasm.c $(CONFIG_H) system.h
*** 1352,1358 ****
xcoffout.h output.h c-pragma.h toplev.h dbxout.h sdbout.h $(GGC_H)
function.o : function.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h \
function.h insn-flags.h insn-codes.h $(EXPR_H) $(REGS_H) hard-reg-set.h \
! insn-config.h $(RECOG_H) output.h toplev.h except.h hash.h $(GGC_H)
stmt.o : stmt.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h function.h \
insn-flags.h insn-config.h insn-codes.h hard-reg-set.h $(EXPR_H) except.h \
$(LOOP_H) $(RECOG_H) toplev.h output.h varray.h $(GGC_H)
--- 1352,1359 ----
xcoffout.h output.h c-pragma.h toplev.h dbxout.h sdbout.h $(GGC_H)
function.o : function.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h \
function.h insn-flags.h insn-codes.h $(EXPR_H) $(REGS_H) hard-reg-set.h \
! insn-config.h $(RECOG_H) output.h toplev.h except.h hash.h $(GGC_H) \
! defaults.h
stmt.o : stmt.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h function.h \
insn-flags.h insn-config.h insn-codes.h hard-reg-set.h $(EXPR_H) except.h \
$(LOOP_H) $(RECOG_H) toplev.h output.h varray.h $(GGC_H)
*************** final.o : final.c $(CONFIG_H) system.h $
*** 1491,1497 ****
dbxout.h $(BASIC_BLOCK_H)
recog.o : recog.c $(CONFIG_H) system.h $(RTL_H) function.h $(BASIC_BLOCK_H) \
$(REGS_H) $(RECOG_H) hard-reg-set.h flags.h insn-config.h $(INSN_ATTR_H) \
! insn-flags.h insn-codes.h real.h toplev.h output.h
reg-stack.o : reg-stack.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) $(RECOG_H) \
$(REGS_H) hard-reg-set.h flags.h insn-config.h insn-flags.h toplev.h \
varray.h function.h
--- 1492,1498 ----
dbxout.h $(BASIC_BLOCK_H)
recog.o : recog.c $(CONFIG_H) system.h $(RTL_H) function.h $(BASIC_BLOCK_H) \
$(REGS_H) $(RECOG_H) hard-reg-set.h flags.h insn-config.h $(INSN_ATTR_H) \
! insn-flags.h insn-codes.h real.h toplev.h output.h defaults.h
reg-stack.o : reg-stack.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) $(RECOG_H) \
$(REGS_H) hard-reg-set.h flags.h insn-config.h insn-flags.h toplev.h \
varray.h function.h
*************** $(MD_FILE): $(MD_DEPS)
*** 1702,1707 ****
--- 1703,1713 ----
gensupport.o: gensupport.c $(RTL_H) $(OBSTACK_H) system.h errors.h gensupport.h
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/gensupport.c
+ hashtab.o: $(srcdir)/../libiberty/hashtab.c $(CONFIG_H)
+ rm -f hashtab.c
+ $(LN_S) $(srcdir)/../libiberty/hashtab.c hashtab.c
+ $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) hashtab.c
+
genconfig : genconfig.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBDEPS)
$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \
genconfig.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBS)
*************** gengenrtl.o : gengenrtl.c $(RTL_BASE_H)
*** 1800,1806 ****
# and HOST_PREFIX_1 is `foobar', just to ensure these rules don't conflict
# with the rules for rtl.o, alloca.o, etc.
$(HOST_PREFIX_1)rtl.o: $(srcdir)/rtl.c $(CONFIG_H) system.h $(RTL_H) \
! bitmap.h $(GGC_H) toplev.h
rm -f $(HOST_PREFIX)rtl.c
sed -e 's/config[.]h/hconfig.h/' $(srcdir)/rtl.c > $(HOST_PREFIX)rtl.c
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(HOST_PREFIX)rtl.c
--- 1806,1812 ----
# and HOST_PREFIX_1 is `foobar', just to ensure these rules don't conflict
# with the rules for rtl.o, alloca.o, etc.
$(HOST_PREFIX_1)rtl.o: $(srcdir)/rtl.c $(CONFIG_H) system.h $(RTL_H) \
! bitmap.h $(GGC_H) toplev.h $(HASHTAB_H)
rm -f $(HOST_PREFIX)rtl.c
sed -e 's/config[.]h/hconfig.h/' $(srcdir)/rtl.c > $(HOST_PREFIX)rtl.c
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(HOST_PREFIX)rtl.c
Index: rtl.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/rtl.c,v
retrieving revision 1.82
diff -p -r1.82 rtl.c
*** rtl.c 2000/10/16 22:11:02 1.82
--- rtl.c 2000/11/21 21:38:23
*************** Boston, MA 02111-1307, USA. */
*** 28,33 ****
--- 28,34 ----
#include "ggc.h"
#include "obstack.h"
#include "toplev.h"
+ #include "hashtab.h"
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
*************** const char * const reg_note_name[] =
*** 301,310 ****
--- 302,316 ----
"REG_EH_RETHROW", "REG_SAVE_NOTE", "REG_MAYBE_DEAD", "REG_NORETURN"
};
+ static htab_t md_constants;
+
static void fatal_with_file_and_line PARAMS ((FILE *, const char *, ...))
ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN;
static void fatal_expected_char PARAMS ((FILE *, int, int)) ATTRIBUTE_NORETURN;
static void read_name PARAMS ((char *, FILE *));
+ static unsigned def_hash PARAMS ((const void *));
+ static int def_name_eq_p PARAMS ((const void *, const void *));
+ static void read_constants PARAMS ((FILE *infile, char *tmp_char));
/* Allocate an rtx vector of N elements.
*************** read_name (str, infile)
*** 870,875 ****
--- 876,900 ----
read_rtx_lineno++;
*p = 0;
+
+ if (md_constants)
+ {
+ /* Do constant expansion. */
+ struct md_constant *def;
+
+ p = str;
+ do
+ {
+ struct md_constant tmp_def;
+
+ tmp_def.name = p;
+ def = htab_find (md_constants, &tmp_def);
+ if (def)
+ p = def->value;
+ } while (def);
+ if (p != str)
+ strcpy (str, p);
+ }
}
/* Provide a version of a function to read a long long if the system does
*************** atoll(p)
*** 909,914 ****
--- 934,1030 ----
}
#endif
+ /* Given a constant definition, return a hash code for its name. */
+ static unsigned
+ def_hash (def)
+ const void *def;
+ {
+ unsigned result, i;
+ const char *string = ((const struct md_constant *)def)->name;
+
+ for (result = i = 0;*string++ != '\0'; i++)
+ result += ((unsigned char) *string << (i % CHAR_BIT));
+ return result;
+ }
+
+ /* Given two constant definitions, return true if they have the same name. */
+ static int
+ def_name_eq_p (def1, def2)
+ const void *def1, *def2;
+ {
+ return ! strcmp (((const struct md_constant *)def1)->name,
+ ((const struct md_constant *)def2)->name);
+ }
+
+ /* INFILE is a FILE pointer to read text from. TMP_CHAR is a buffer suitable
+ to read a name or number into. Process a define_constants directive,
+ starting with the optional space after the "define_constants". */
+ static void
+ read_constants (infile, tmp_char)
+ FILE *infile;
+ char *tmp_char;
+ {
+ int c;
+ htab_t defs;
+
+ c = read_skip_spaces (infile);
+ if (c != '[')
+ fatal_expected_char (infile, '[', c);
+ defs = md_constants;
+ if (! defs)
+ defs = htab_create (32, def_hash, def_name_eq_p, (htab_del) 0);
+ /* Disable constant expansion during definition processing. */
+ md_constants = 0;
+ while ( (c = read_skip_spaces (infile)) != ']')
+ {
+ struct md_constant *def;
+ void **entry_ptr;
+
+ if (c != '(')
+ fatal_expected_char (infile, '(', c);
+ def = xmalloc (sizeof (struct md_constant));
+ def->name = tmp_char;
+ read_name (tmp_char, infile);
+ entry_ptr = htab_find_slot (defs, def, TRUE);
+ if (! *entry_ptr)
+ def->name = xstrdup (tmp_char);
+ c = read_skip_spaces (infile);
+ ungetc (c, infile);
+ read_name (tmp_char, infile);
+ if (! *entry_ptr)
+ {
+ def->value = xstrdup (tmp_char);
+ *entry_ptr = def;
+ }
+ else
+ {
+ def = *entry_ptr;
+ if (strcmp (def->value, tmp_char))
+ fatal_with_file_and_line (infile,
+ "redefinition of %s, was %s, now %s",
+ def->name, def->value, tmp_char);
+ }
+ c = read_skip_spaces (infile);
+ if (c != ')')
+ fatal_expected_char (infile, ')', c);
+ }
+ md_constants = defs;
+ c = read_skip_spaces (infile);
+ if (c != ')')
+ fatal_expected_char (infile, ')', c);
+ }
+
+ /* For every constant definition, call CALLBACK with two arguments:
+ a pointer a pointer to the constant definition and INFO.
+ Stops when CALLBACK returns zero. */
+ void
+ traverse_md_constants (callback, info)
+ htab_trav callback;
+ void *info;
+ {
+ htab_traverse (md_constants, callback, info);
+ }
+
/* Read an rtx in printed representation from INFILE
and return an actual rtx in core constructed accordingly.
read_rtx is not used in the compiler proper, but rather in
*************** read_rtx (infile)
*** 937,942 ****
--- 1053,1059 ----
rtx value; /* Value of this node. */
};
+ again:
c = read_skip_spaces (infile); /* Should be open paren. */
if (c != '(')
fatal_expected_char (infile, '(', c);
*************** read_rtx (infile)
*** 945,950 ****
--- 1062,1072 ----
tmp_code = UNKNOWN;
+ if (! strcmp (tmp_char, "define_constants"))
+ {
+ read_constants (infile, tmp_char);
+ goto again;
+ }
for (i = 0; i < NUM_RTX_CODE; i++)
if (! strcmp (tmp_char, GET_RTX_NAME (i)))
{
Index: gencodes.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/gencodes.c,v
retrieving revision 1.33
diff -p -r1.33 gencodes.c
*** gencodes.c 2000/08/27 16:09:41 1.33
--- gencodes.c 2000/11/21 21:38:23
*************** Boston, MA 02111-1307, USA. */
*** 32,37 ****
--- 32,38 ----
static int insn_code_number;
static void gen_insn PARAMS ((rtx));
+ static int print_md_constant PARAMS ((void **, void *));
static void
gen_insn (insn)
*************** from the machine description file `md'.
*** 86,95 ****
printf (" CODE_FOR_nothing = %d };\n", insn_code_number + 1);
! printf ("\n#define MAX_INSN_CODE ((int) CODE_FOR_nothing)\n");
! printf ("#endif /* MAX_INSN_CODE */\n");
fflush (stdout);
return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
}
--- 87,98 ----
printf (" CODE_FOR_nothing = %d };\n", insn_code_number + 1);
! printf ("\n#define MAX_INSN_CODE ((int) CODE_FOR_nothing)\n\n");
! traverse_md_constants (print_md_constant, stdout);
+ printf ("\n#endif /* MAX_INSN_CODE */\n");
+
fflush (stdout);
return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
}
*************** get_insn_name (code)
*** 100,103 ****
--- 103,120 ----
int code ATTRIBUTE_UNUSED;
{
return NULL;
+ }
+
+ /* Called via traverse_md_constants; emit a #define for
+ the current constant definition. */
+ static int
+ print_md_constant (slot, info)
+ void **slot;
+ void *info;
+ {
+ struct md_constant *def = *slot;
+ FILE *file = info;
+
+ fprintf (file, "#define %s %s\n", def->name, def->value);
+ return 1;
}