We're out of tree codes; now what?

Doug Gregor doug.gregor@gmail.com
Mon Mar 19 13:41:00 GMT 2007


On 3/12/07, Richard Kenner <kenner@vlsi1.ultra.nyu.edu> wrote:
> > It's going to have a big performance impact. To extract a 9-bit value,
> > the compiler will need to do a lot of masking every time it accesses
> > the TREE_CODE.
>
> "a lot masking" means at most two additional instructions, one if we
> put it in the right place.  I'd be shocked if we could even measure
> this, let alone be a "big" performance impact.

I went ahead and implemented this, to see what the real impact would
be. The following patch frees up TREE_LANG_FLAG_5, and uses that extra
bit for the tree code.

On tramp3d, memory usage remains the same (obviously), and the
performance results are not as bad as I had imagined:

8-bit tree code, --enable-checking:

real    1m56.776s
user    1m54.995s
sys     0m0.541s

9-bit tree code, --enable-checking:

real    2m16.095s
user    2m12.132s
sys     0m0.562s

8-bit tree code, --disable-checking:

real    0m55.693s
user    0m43.734s
sys     0m0.414s

9-bit tree code, --disable-checking:

real    0m58.821s
user    0m46.122s
sys     0m0.443s

So, about 16% slower with --enable-checking, 5% slower with --disable-checking.

Subcodes might still be the way to go, but I'm feeling less bad about
the 9-bit tree code option.

  Cheers,
  Doug

2007-03-19  Douglas Gregor  <doug.gregor@gmail.com>

	* java-tree.h (HAS_BEEN_ALREADY_PARSED_P): Move to TREE_PROTECTED.

2007-03-19  Douglas Gregor  <doug.gregor@gmail.com>

	* tree.c (tree_contains_struct): Support 512 tree codes.
	* tree.h (tree_contains_struct): Ditto.
	(MAX_TREE_CODES): We now support 512 tree codes.
	(struct tree_base): Make "code" 9 bits, remove lang_flag_5.
	(TREE_LANG_FLAG_5): Remove.
	(BINFO_FLAG_5): Remove.
	* print-tree.c (print_node): Don't print TREE_LANG_FLAG_5.
	
2007-03-19  Douglas Gregor  <doug.gregor@gmail.com>

	* cp-tree.h (C_IS_RESERVED_WORD): Move to TREE_PROTECTED.
	(BINFO_PRIMARY_P): Move to BINFO_FLAG_6.
	(DECL_VTABLE_OR_VTT_P): Move to nothrow_flag.

Index: java/java-tree.h
===================================================================
--- java/java-tree.h	(revision 122993)
+++ java/java-tree.h	(working copy)
@@ -48,7 +48,6 @@ struct JCF;
    3: HAS_FINALIZER (in RECORD_TYPE)
    4: IS_A_COMMAND_LINE_FILENAME_P (in IDENTIFIER_NODE)
       IS_ARRAY_LENGTH_ACCESS (in INDIRECT_REF)
-   5: HAS_BEEN_ALREADY_PARSED_P (in IDENTIFIER_NODE)
    6: CAN_COMPLETE_NORMALLY (in statement nodes)

    Usage of TYPE_LANG_FLAG_?:
@@ -1521,7 +1520,7 @@ extern tree *type_map;
 #define IS_A_COMMAND_LINE_FILENAME_P(ID) TREE_LANG_FLAG_4 (ID)

 /* True if filename ID has already been parsed */
-#define HAS_BEEN_ALREADY_PARSED_P(ID) TREE_LANG_FLAG_5 (ID)
+#define HAS_BEEN_ALREADY_PARSED_P(ID) TREE_PROTECTED (ID)

 /* True if TYPE (a TREE_TYPE denoting a class type) was found to
    feature a finalizer method. */
Index: tree.c
===================================================================
--- tree.c	(revision 122993)
+++ tree.c	(working copy)
@@ -168,7 +168,7 @@ static unsigned int attribute_hash_list
 tree global_trees[TI_MAX];
 tree integer_types[itk_none];

-unsigned char tree_contains_struct[256][64];
+unsigned char tree_contains_struct[512][64];

 /* Number of operands for each OpenMP clause.  */
 unsigned const char omp_clause_num_ops[] =
Index: tree.h
===================================================================
--- tree.h	(revision 122993)
+++ tree.h	(working copy)
@@ -41,7 +41,7 @@ enum tree_code {

 #undef DEFTREECODE

-extern unsigned char tree_contains_struct[256][64];
+extern unsigned char tree_contains_struct[512][64];
 #define CODE_CONTAINS_STRUCT(CODE, STRUCT)
(tree_contains_struct[(CODE)][(STRUCT)])

 /* Number of language-independent tree codes.  */
@@ -80,7 +80,7 @@ extern const char *const tree_code_class
 #define TREE_CODE_CLASS_STRING(CLASS)\
         tree_code_class_strings[(int) (CLASS)]

-#define MAX_TREE_CODES 256
+#define MAX_TREE_CODES 512
 extern const enum tree_code_class tree_code_type[];
 #define TREE_CODE_CLASS(CODE)	tree_code_type[(int) (CODE)]

@@ -363,7 +363,7 @@ union tree_ann_d;

 struct tree_base GTY(())
 {
-  ENUM_BITFIELD(tree_code) code : 8;
+  ENUM_BITFIELD(tree_code) code : 9;

   unsigned side_effects_flag : 1;
   unsigned constant_flag : 1;
@@ -388,7 +388,8 @@ struct tree_base GTY(())
   unsigned lang_flag_2 : 1;
   unsigned lang_flag_3 : 1;
   unsigned lang_flag_4 : 1;
-  unsigned lang_flag_5 : 1;
+  /* NOTE: lang_flag_5 is intentionally absent; it was been used for the 9th
+     bit of code.  */
   unsigned lang_flag_6 : 1;
   unsigned visited : 1;

@@ -485,6 +486,12 @@ struct gimple_stmt GTY(())
        CALL_FROM_THUNK_P in
            CALL_EXPR

+       C_IS_RESERVED_WORD in
+         IDENTIFIER_NODE (C++ only)
+
+       HAS_BEEN_ALREADY_PARSED_P in
+         IDENTIFIER_NODE (Java only)
+
    side_effects_flag:

        TREE_SIDE_EFFECTS in
@@ -549,6 +556,9 @@ struct gimple_stmt GTY(())
        TREE_THIS_NOTRAP in
           (ALIGN/MISALIGNED_)INDIRECT_REF, ARRAY_REF, ARRAY_RANGE_REF

+       DECL_VTABLE_OR_VTT_P in
+          VAR_DECL (C++ only)
+
    deprecated_flag:

 	TREE_DEPRECATED in
@@ -1296,7 +1306,8 @@ extern void omp_clause_range_check_faile
 /* Used in classes in C++.  */
 #define TREE_PRIVATE(NODE) ((NODE)->base.private_flag)
 /* Used in classes in C++.
-   In a BLOCK node, this is BLOCK_HANDLER_BLOCK.  */
+   In a BLOCK node, this is BLOCK_HANDLER_BLOCK.
+   In a C++ IDENTIFIER_NODE, this is C_IS_RESERVED_WORD.  */
 #define TREE_PROTECTED(NODE) ((NODE)->base.protected_flag)

 /* Nonzero in a _DECL if the use of the name is defined as a
@@ -1321,7 +1332,6 @@ extern void omp_clause_range_check_faile
 #define TREE_LANG_FLAG_2(NODE) ((NODE)->base.lang_flag_2)
 #define TREE_LANG_FLAG_3(NODE) ((NODE)->base.lang_flag_3)
 #define TREE_LANG_FLAG_4(NODE) ((NODE)->base.lang_flag_4)
-#define TREE_LANG_FLAG_5(NODE) ((NODE)->base.lang_flag_5)
 #define TREE_LANG_FLAG_6(NODE) ((NODE)->base.lang_flag_6)
 

 /* Define additional fields and accessors for nodes representing constants.  */
@@ -2286,7 +2296,6 @@ struct tree_type GTY(())
 #define BINFO_FLAG_2(NODE) TREE_LANG_FLAG_2(TREE_BINFO_CHECK(NODE))
 #define BINFO_FLAG_3(NODE) TREE_LANG_FLAG_3(TREE_BINFO_CHECK(NODE))
 #define BINFO_FLAG_4(NODE) TREE_LANG_FLAG_4(TREE_BINFO_CHECK(NODE))
-#define BINFO_FLAG_5(NODE) TREE_LANG_FLAG_5(TREE_BINFO_CHECK(NODE))
 #define BINFO_FLAG_6(NODE) TREE_LANG_FLAG_6(TREE_BINFO_CHECK(NODE))

 /* The actual data type node being inherited in this basetype.  */
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 122993)
+++ cp/cp-tree.h	(working copy)
@@ -80,8 +80,6 @@ struct diagnostic_context;
 	  or FIELD_DECL).
       IDENTIFIER_TYPENAME_P (in IDENTIFIER_NODE)
       DECL_TINFO_P (in VAR_DECL)
-   5: C_IS_RESERVED_WORD (in IDENTIFIER_NODE)
-      DECL_VTABLE_OR_VTT_P (in VAR_DECL)
    6: IDENTIFIER_REPO_CHOSEN (in IDENTIFIER_NODE)
       DECL_CONSTRUCTION_VTABLE_P (in VAR_DECL)
       TYPE_MARKED_P (in _TYPE)
@@ -212,7 +210,7 @@ struct lang_identifier GTY(())
    keyword.  C_RID_CODE (node) is then the RID_* value of the keyword,
    and C_RID_YYCODE is the token number wanted by Yacc.  */

-#define C_IS_RESERVED_WORD(ID) TREE_LANG_FLAG_5 (ID)
+#define C_IS_RESERVED_WORD(ID) TREE_PROTECTED (ID)

 #define LANG_IDENTIFIER_CAST(NODE) \
 	((struct lang_identifier*)IDENTIFIER_NODE_CHECK (NODE))
@@ -1465,7 +1463,7 @@ struct lang_type GTY(())
 #define BINFO_LOST_PRIMARY_P(NODE) BINFO_FLAG_4 (NODE)

 /* Nonzero if this BINFO is a primary base class.  */
-#define BINFO_PRIMARY_P(NODE) BINFO_FLAG_5(NODE)
+#define BINFO_PRIMARY_P(NODE) BINFO_FLAG_6(NODE)

 /* Used by various search routines.  */
 #define IDENTIFIER_MARKED(NODE) TREE_LANG_FLAG_0 (NODE)
@@ -2031,7 +2029,8 @@ struct lang_decl GTY(())
 #define DECL_TINFO_P(NODE) TREE_LANG_FLAG_4 (VAR_DECL_CHECK (NODE))

 /* 1 iff VAR_DECL node NODE is virtual table or VTT.  */
-#define DECL_VTABLE_OR_VTT_P(NODE) TREE_LANG_FLAG_5 (VAR_DECL_CHECK (NODE))
+#define DECL_VTABLE_OR_VTT_P(NODE)                      \
+  (VAR_DECL_CHECK (NODE)->base.nothrow_flag)

 /* Returns 1 iff VAR_DECL is a construction virtual table.
    DECL_VTABLE_OR_VTT_P will be true in this case and must be checked
Index: print-tree.c
===================================================================
--- print-tree.c	(revision 122993)
+++ print-tree.c	(working copy)
@@ -314,8 +314,6 @@ print_node (FILE *file, const char *pref
     fputs (" tree_3", file);
   if (TREE_LANG_FLAG_4 (node))
     fputs (" tree_4", file);
-  if (TREE_LANG_FLAG_5 (node))
-    fputs (" tree_5", file);
   if (TREE_LANG_FLAG_6 (node))
     fputs (" tree_6", file);



More information about the Gcc mailing list