gcc tree changes

John Carr jfc@mit.edu
Fri Sep 19 19:42:00 GMT 1997


This is primarily to make the compiler faster (I haven't measured
recently; an earlier version of this change together with a similar
change for rtl which I will send soon made a combined difference of a
few percent in compile speed).  It may also reduce the size of the TOC
on AIX.

Basically, this removes one or two levels of indirection;
TREE_CODE_CLASS now makes one memory reference instead of three.

This requires a slight change to the language front ends (included for
Objective C and C++; Fortran doesn't seem to need it).


Fri Sep 19 21:51:21 1997  John F. Carr  <jfc@mit.edu>

	* tree.c, tree.h: Change tree_code_type, tree_code_length, and
	tree_code_name from pointers to arrays.
	* tree.c: Remove standard_tree_code_* variables, no longer used.
	* print-tree.c: Remove declaration of tree_code_name.

	* cp/lex.c (init_lex): Update for tree_code_* changes.
	* objc/objc-act.c (init_objc): Likewise.

In addition to the patches, replace-regexp "\([^,]\)" with '\1' in
gcc/tree.def, cp/cp-tree.def, objc/objc-tree.def.
	

*** tree.h.orig	Mon Sep 15 22:07:29 1997
--- tree.h	Fri Sep 19 21:16:51 1997
***************
*** 47,62 ****
     constant, `d' for a decl, `t' for a type, `s' for a statement,
     and `x' for anything else (TREE_LIST, IDENTIFIER, etc).  */
  
! extern char **tree_code_type;
! #define TREE_CODE_CLASS(CODE)	(*tree_code_type[(int) (CODE)])
  
  /* Number of argument-words in each kind of tree-node.  */
  
! extern int *tree_code_length;
  
  /* Names of tree components.  */
  
! extern char **tree_code_name;
  
  /* Codes that identify the various built in functions
     so that expand_call can identify them quickly.  */
--- 47,63 ----
     constant, `d' for a decl, `t' for a type, `s' for a statement,
     and `x' for anything else (TREE_LIST, IDENTIFIER, etc).  */
  
! #define MAX_TREE_CODES 256
! extern char tree_code_type[MAX_TREE_CODES];
! #define TREE_CODE_CLASS(CODE)	tree_code_type[(int) (CODE)]
  
  /* Number of argument-words in each kind of tree-node.  */
  
! extern int tree_code_length[MAX_TREE_CODES];
  
  /* Names of tree components.  */
  
! extern char *tree_code_name[MAX_TREE_CODES];
  
  /* Codes that identify the various built in functions
     so that expand_call can identify them quickly.  */
*** print-tree.c.orig	Mon Aug 11 11:57:12 1997
--- print-tree.c	Fri Sep 19 21:11:31 1997
***************
*** 23,30 ****
  #include "tree.h"
  #include <stdio.h>
  
- extern char **tree_code_name;
- 
  extern char *mode_name[];
  
  void print_node ();
--- 23,28 ----
*** tree.c.orig	Thu Aug 28 09:08:52 1997
--- tree.c	Fri Sep 19 21:06:57 1997
***************
*** 181,187 ****
  
  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  
! char *standard_tree_code_type[] = {
  #include "tree.def"
  };
  #undef DEFTREECODE
--- 181,187 ----
  
  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  
! char tree_code_type[MAX_TREE_CODES] = {
  #include "tree.def"
  };
  #undef DEFTREECODE
***************
*** 192,198 ****
  
  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
  
! int standard_tree_code_length[] = {
  #include "tree.def"
  };
  #undef DEFTREECODE
--- 192,198 ----
  
  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
  
! int tree_code_length[MAX_TREE_CODES] = {
  #include "tree.def"
  };
  #undef DEFTREECODE
***************
*** 201,227 ****
     Used for printing out the tree and error messages.  */
  #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
  
! char *standard_tree_code_name[] = {
  #include "tree.def"
  };
  #undef DEFTREECODE
  
- /* Table indexed by tree code giving a string containing a character
-    classifying the tree code.  Possibilities are
-    t, d, s, c, r, e, <, 1 and 2.  See tree.def for details.  */
- 
- char **tree_code_type;
- 
- /* Table indexed by tree code giving number of expression
-    operands beyond the fixed part of the node structure.
-    Not used for types or decls.  */
- 
- int *tree_code_length;
- 
- /* Table indexed by tree code giving name of tree code, as a string.  */
- 
- char **tree_code_name;
- 
  /* Statistics-gathering stuff.  */
  typedef enum
  {
--- 201,211 ----
     Used for printing out the tree and error messages.  */
  #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
  
! char *tree_code_name[MAX_TREE_CODES] = {
  #include "tree.def"
  };
  #undef DEFTREECODE
  
  /* Statistics-gathering stuff.  */
  typedef enum
  {
***************
*** 890,904 ****
  void
  init_tree_codes ()
  {
!   tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));
!   tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));
!   tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));
!   bcopy ((char *) standard_tree_code_type, (char *) tree_code_type,
! 	 sizeof (standard_tree_code_type));
!   bcopy ((char *) standard_tree_code_length, (char *) tree_code_length,
! 	 sizeof (standard_tree_code_length));
!   bcopy ((char *) standard_tree_code_name, (char *) tree_code_name,
! 	 sizeof (standard_tree_code_name));
  }
  
  /* Return a newly allocated node of code CODE.
--- 874,880 ----
  void
  init_tree_codes ()
  {
!   
  }
  
  /* Return a newly allocated node of code CODE.
***************
*** 3761,3768 ****
       handled above.  If this is a language-specific tree code, we can't
       trust what might be in the operand, so say we don't know
       the situation.  */
!   if ((int) code1
!       >= sizeof standard_tree_code_type / sizeof standard_tree_code_type[0])
      return -1;
  
    switch (TREE_CODE_CLASS (code1))
--- 3737,3743 ----
       handled above.  If this is a language-specific tree code, we can't
       trust what might be in the operand, so say we don't know
       the situation.  */
!   if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
      return -1;
  
    switch (TREE_CODE_CLASS (code1))
*** cp/lex.c.orig	Mon Sep  8 05:28:46 1997
--- cp/lex.c	Fri Sep 19 21:08:50 1997
***************
*** 348,355 ****
  
  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  
! char *cplus_tree_code_type[] = {
!   "x",
  #include "cp-tree.def"
  };
  #undef DEFTREECODE
--- 348,355 ----
  
  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  
! char cplus_tree_code_type[] = {
!   'x',
  #include "cp-tree.def"
  };
  #undef DEFTREECODE
***************
*** 444,461 ****
  
    init_cplus_expand ();
  
!   tree_code_type
!     = (char **) realloc (tree_code_type,
! 			 sizeof (char *) * LAST_CPLUS_TREE_CODE);
!   tree_code_length
!     = (int *) realloc (tree_code_length,
! 		       sizeof (int) * LAST_CPLUS_TREE_CODE);
!   tree_code_name
!     = (char **) realloc (tree_code_name,
! 			 sizeof (char *) * LAST_CPLUS_TREE_CODE);
!   bcopy ((char *)cplus_tree_code_type,
! 	 (char *)(tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE),
! 	 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
    bcopy ((char *)cplus_tree_code_length,
  	 (char *)(tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE),
  	 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
--- 444,452 ----
  
    init_cplus_expand ();
  
!   bcopy (cplus_tree_code_type,
! 	 tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
! 	 (int)LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE);
    bcopy ((char *)cplus_tree_code_length,
  	 (char *)(tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE),
  	 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
*** objc/objc-act.c.orig	Mon Aug 11 11:58:13 1997
--- objc/objc-act.c	Fri Sep 19 21:47:25 1997
***************
*** 85,92 ****
  
  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  
! char *objc_tree_code_type[] = {
!   "x",
  #include "objc-tree.def"
  };
  #undef DEFTREECODE
--- 85,92 ----
  
  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  
! char objc_tree_code_type[] = {
!   'x',
  #include "objc-tree.def"
  };
  #undef DEFTREECODE
***************
*** 7873,7891 ****
    gcc_obstack_init (&util_obstack);
    util_firstobj = (char *) obstack_finish (&util_obstack);
  
!   tree_code_type
!     = (char **) xrealloc (tree_code_type,
! 			  sizeof (char *) * LAST_OBJC_TREE_CODE);
!   tree_code_length
!     = (int *) xrealloc (tree_code_length,
! 			sizeof (int) * LAST_OBJC_TREE_CODE);
!   tree_code_name
!     = (char **) xrealloc (tree_code_name,
! 			  sizeof (char *) * LAST_OBJC_TREE_CODE);
!   bcopy ((char *) objc_tree_code_type,
! 	 (char *) (tree_code_type + (int) LAST_CODE),
! 	 (((int) LAST_OBJC_TREE_CODE - (int) LAST_CODE)
! 	  * sizeof (char *)));
    bcopy ((char *) objc_tree_code_length,
  	 (char *) (tree_code_length + (int) LAST_CODE),
  	 (((int) LAST_OBJC_TREE_CODE - (int) LAST_CODE)
--- 7873,7881 ----
    gcc_obstack_init (&util_obstack);
    util_firstobj = (char *) obstack_finish (&util_obstack);
  
!   bcopy (objc_tree_code_type,
! 	 tree_code_type + (int) LAST_CODE,
! 	 (int) LAST_OBJC_TREE_CODE - (int) LAST_CODE);
    bcopy ((char *) objc_tree_code_length,
  	 (char *) (tree_code_length + (int) LAST_CODE),
  	 (((int) LAST_OBJC_TREE_CODE - (int) LAST_CODE)



More information about the Gcc mailing list