This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Decrease size of cp_token (PR bootstrap/68271)


Hi!

As discussed in bugzilla some time ago, this patch decreases size of
cp_token on 64-bit hosts from 24 bytes to 16 bytes and on 32-bit
hosts from 16 bytes to 12.  As for C++ all tokens are preparsed, it is quite
important.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-01-15  Jakub Jelinek  <jakub@redhat.com>

	PR bootstrap/68271
	* parser.h (cp_token): Remove pragma_kind field.  Add comment
	with number of unused bits.
	* parser.c (eof_token): Remove pragma_kind field initializer.
	(cp_lexer_get_preprocessor_token): Don't set pragma_kind
	field, don't clear CPP_PRAGMA u.value.
	(cp_parser_pragma_kind): New function.
	(cp_parser_omp_sections_scope, cp_parser_oacc_kernels_parallel,
	cp_parser_omp_construct, cp_parser_initial_pragma,
	cp_parser_pragma): Use cp_parser_pragma_kind instead of accessing
	pragma_kind field.

	* c-pragma.c (c_register_pragma_1): Adjust comment to note that
	C++ FE no longer has limit on number of pragmas.

--- gcc/cp/parser.h.jj	2016-01-04 14:55:57.000000000 +0100
+++ gcc/cp/parser.h	2016-01-15 15:46:53.479338001 +0100
@@ -47,8 +47,6 @@ struct GTY (()) cp_token {
   ENUM_BITFIELD (rid) keyword : 8;
   /* Token flags.  */
   unsigned char flags;
-  /* Identifier for the pragma.  */
-  ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
   /* True if this token is from a context where it is implicitly extern "C" */
   BOOL_BITFIELD implicit_extern_c : 1;
   /* True if an error has already been reported for this token, such as a
@@ -59,6 +57,7 @@ struct GTY (()) cp_token {
      it is no longer a valid token and it should be considered
      deleted.  */
   BOOL_BITFIELD purged_p : 1;
+  /* 5 unused bits.  */
   /* The location at which this token was found.  */
   location_t location;
   /* The value associated with this token, if any.  */
--- gcc/cp/parser.c.jj	2016-01-14 22:31:22.000000000 +0100
+++ gcc/cp/parser.c	2016-01-15 16:24:42.520089347 +0100
@@ -48,7 +48,7 @@ along with GCC; see the file COPYING3.
 
 static cp_token eof_token =
 {
-  CPP_EOF, RID_MAX, 0, PRAGMA_NONE, false, false, false, 0, { NULL }
+  CPP_EOF, RID_MAX, 0, false, false, false, 0, { NULL }
 };
 
 /* The various kinds of non integral constant we encounter. */
@@ -782,7 +782,6 @@ cp_lexer_get_preprocessor_token (cp_lexe
     = c_lex_with_flags (&token->u.value, &token->location, &token->flags,
 			lexer == NULL ? 0 : C_LEX_STRING_NO_JOIN);
   token->keyword = RID_MAX;
-  token->pragma_kind = PRAGMA_NONE;
   token->purged_p = false;
   token->error_reported = false;
 
@@ -848,13 +847,6 @@ cp_lexer_get_preprocessor_token (cp_lexe
 	default:            token->keyword = C_RID_CODE (token->u.value);
 	}
     }
-  else if (token->type == CPP_PRAGMA)
-    {
-      /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
-      token->pragma_kind = ((enum pragma_kind)
-			    TREE_INT_CST_LOW (token->u.value));
-      token->u.value = NULL_TREE;
-    }
 }
 
 /* Update the globals input_location and the input file stack from TOKEN.  */
@@ -2689,6 +2681,18 @@ cp_parser_is_keyword (cp_token* token, e
   return token->keyword == keyword;
 }
 
+/* Return TOKEN's pragma_kind if it is CPP_PRAGMA, otherwise
+   PRAGMA_NONE.  */
+
+static enum pragma_kind
+cp_parser_pragma_kind (cp_token *token)
+{
+  if (token->type != CPP_PRAGMA)
+    return PRAGMA_NONE;
+  /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
+  return (enum pragma_kind) TREE_INT_CST_LOW (token->u.value);
+}
+
 /* Helper function for cp_parser_error.
    Having peeked a token of kind TOK1_KIND that might signify
    a conflict marker, peek successor tokens to determine
@@ -33937,7 +33941,8 @@ cp_parser_omp_sections_scope (cp_parser
 
   stmt = push_stmt_list ();
 
-  if (cp_lexer_peek_token (parser->lexer)->pragma_kind != PRAGMA_OMP_SECTION)
+  if (cp_parser_pragma_kind (cp_lexer_peek_token (parser->lexer))
+      != PRAGMA_OMP_SECTION)
     {
       substmt = cp_parser_omp_structured_block (parser);
       substmt = build1 (OMP_SECTION, void_type_node, substmt);
@@ -33952,7 +33957,7 @@ cp_parser_omp_sections_scope (cp_parser
       if (tok->type == CPP_EOF)
 	break;
 
-      if (tok->pragma_kind == PRAGMA_OMP_SECTION)
+      if (cp_parser_pragma_kind (tok) == PRAGMA_OMP_SECTION)
 	{
 	  cp_lexer_consume_token (parser->lexer);
 	  cp_parser_require_pragma_eol (parser, tok);
@@ -35356,7 +35361,7 @@ cp_parser_oacc_kernels_parallel (cp_pars
 {
   omp_clause_mask mask;
   enum tree_code code;
-  switch (pragma_tok->pragma_kind)
+  switch (cp_parser_pragma_kind (pragma_tok))
     {
     case PRAGMA_OACC_KERNELS:
       strcat (p_name, " kernels");
@@ -36572,7 +36577,7 @@ cp_parser_omp_construct (cp_parser *pars
   char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
   omp_clause_mask mask (0);
 
-  switch (pragma_tok->pragma_kind)
+  switch (cp_parser_pragma_kind (pragma_tok))
     {
     case PRAGMA_OACC_ATOMIC:
       cp_parser_omp_atomic (parser, pragma_tok);
@@ -36971,7 +36976,7 @@ cp_parser_initial_pragma (cp_token *firs
   tree name = NULL;
 
   cp_lexer_get_preprocessor_token (NULL, first_token);
-  if (first_token->pragma_kind != PRAGMA_GCC_PCH_PREPROCESS)
+  if (cp_parser_pragma_kind (first_token) != PRAGMA_GCC_PCH_PREPROCESS)
     return;
 
   cp_lexer_get_preprocessor_token (NULL, first_token);
@@ -37046,7 +37051,7 @@ cp_parser_pragma (cp_parser *parser, enu
   gcc_assert (pragma_tok->type == CPP_PRAGMA);
   parser->lexer->in_pragma = true;
 
-  id = pragma_tok->pragma_kind;
+  id = cp_parser_pragma_kind (pragma_tok);
   if (id != PRAGMA_OMP_DECLARE_REDUCTION && id != PRAGMA_OACC_ROUTINE)
     cp_ensure_no_omp_declare_simd (parser);
   switch (id)
--- gcc/c-family/c-pragma.c.jj	2016-01-04 14:55:58.000000000 +0100
+++ gcc/c-family/c-pragma.c	2016-01-15 16:20:57.850183494 +0100
@@ -1372,8 +1372,9 @@ c_register_pragma_1 (const char *space,
       id = registered_pragmas.length ();
       id += PRAGMA_FIRST_EXTERNAL - 1;
 
-      /* The C++ front end allocates 8 bits in cp_token; the C front end
-	 allocates 8 bits in c_token.  At present this is sufficient.  */
+      /* The C front end allocates 8 bits in c_token.  The C++ front end
+	 keeps the pragma kind in the form of INTEGER_CST, so no small
+	 limit applies.  At present this is sufficient.  */
       gcc_assert (id < 256);
     }
 

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]