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: eliminate checks for debug output in compiler built with --disable-checking


This patch gives a small but measurable C++ compile speed improvement by eliminating a conditional in some time-critical functions in the parser. OK to commit to mainline?

--Matt


Index: gcc/cp/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/ChangeLog,v
retrieving revision 1.4330
diff -p -r1.4330 ChangeLog
*** gcc/cp/ChangeLog 3 Sep 2004 18:09:26 -0000 1.4330
--- gcc/cp/ChangeLog 3 Sep 2004 19:18:20 -0000
***************
*** 1,3 ****
--- 1,18 ----
+ 2004-0903 Matt Austern <austern@apple.com>
+ Compile speed improvement.
+ * parser.c (cp_lexer_print_token): Only define if ENABLE_CHECKING set.
+ (cp_lexer_debugging_p): Likewise.
+ (cp_lexer_start_debugging): Likewise.
+ (cp_lexer_stop_debugging): Likewise.
+ (cp_lexer_debug_stream): Likewise.
+ (cp_lexer_new_main): Only set debugging_p if ENABLE_CHECKING set.
+ (cp_lexer_new_from_tokens): Likewise.
+ (cp_lexer_peek_token): Only emit debug output if ENABLE_CHECKING set.
+ (cp_lexer_consume_token): Likewise.
+ (cp_lexer_save_tokens): Likewise.
+ (cp_lexer_commit_tokens): Likewise.
+ (cp_lexer_rollback_tokens): Likewise.
+
2004-09-03 Jan Beulich <jbeulich@novell.com>


  	* g++spec.c (MATH_LIBRARY_PROFILE): Default to MATH_LIBRARY rather
Index: gcc/cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.241
diff -p -r1.241 parser.c
*** gcc/cp/parser.c	30 Aug 2004 16:03:45 -0000	1.241
--- gcc/cp/parser.c	3 Sep 2004 19:18:24 -0000
*************** static void cp_lexer_rollback_tokens
*** 256,261 ****
--- 256,262 ----
    (cp_lexer *);
  static inline void cp_lexer_set_source_position_from_token
    (cp_lexer *, const cp_token *);
+ #ifdef ENABLE_CHECKING
  static void cp_lexer_print_token
    (FILE *, cp_token *);
  static inline bool cp_lexer_debugging_p
*************** static void cp_lexer_start_debugging
*** 264,269 ****
--- 265,271 ----
    (cp_lexer *) ATTRIBUTE_UNUSED;
  static void cp_lexer_stop_debugging
    (cp_lexer *) ATTRIBUTE_UNUSED;
+ #endif /* ENABLE_CHECKING */

/* Manifest constants. */

*************** static void cp_lexer_stop_debugging
*** 292,299 ****
--- 294,303 ----

/* Variables. */

+ #ifdef ENABLE_CHECKING
  /* The stream to which debugging output should be written.  */
  static FILE *cp_lexer_debug_stream;
+ #endif /* ENABLE_CHECKING */

  /* Create a new main C++ lexer, the lexer that gets tokens from the
     preprocessor.  */
*************** cp_lexer_new_main (void)
*** 332,339 ****
--- 336,345 ----
    /* Create the STRINGS array.  */
    VARRAY_TREE_INIT (lexer->string_tokens, 32, "strings");

+ #ifdef ENABLE_CHECKING
    /* Assume we are not debugging.  */
    lexer->debugging_p = false;
+ #endif /* ENABLE_CHECKING */

    return lexer;
  }
*************** cp_lexer_new_from_tokens (cp_token_cache
*** 383,402 ****
--- 389,414 ----
    /* Create the STRINGS array.  */
    VARRAY_TREE_INIT (lexer->string_tokens, 32, "strings");

+ #ifdef ENABLE_CHECKING
    /* Assume we are not debugging.  */
    lexer->debugging_p = false;
+ #endif /* ENABLE_CHECKING */

    return lexer;
  }

/* Returns nonzero if debugging information should be output. */

+ #ifdef ENABLE_CHECKING
+
  static inline bool
  cp_lexer_debugging_p (cp_lexer *lexer)
  {
    return lexer->debugging_p;
  }

+ #endif /* ENABLE_CHECKING */
+
  /* Set the current source position from the information stored in
     TOKEN.  */

*************** cp_lexer_peek_token (cp_lexer* lexer)
*** 659,670 ****
--- 671,684 ----
      cp_lexer_read_token (lexer);

    /* Provide debugging output.  */
+ #ifdef ENABLE_CHECKING
    if (cp_lexer_debugging_p (lexer))
      {
        fprintf (cp_lexer_debug_stream, "cp_lexer: peeking at token: ");
        cp_lexer_print_token (cp_lexer_debug_stream, lexer->next_token);
        fprintf (cp_lexer_debug_stream, "\n");
      }
+ #endif /* ENABLE_CHECKING */

    token = lexer->next_token;
    cp_lexer_set_source_position_from_token (lexer, token);
*************** cp_lexer_consume_token (cp_lexer* lexer)
*** 773,784 ****
--- 787,800 ----
      }

    /* Provide debugging output.  */
+ #ifdef ENABLE_CHECKING
    if (cp_lexer_debugging_p (lexer))
      {
        fprintf (cp_lexer_debug_stream, "cp_lexer: consuming token: ");
        cp_lexer_print_token (cp_lexer_debug_stream, token);
        fprintf (cp_lexer_debug_stream, "\n");
      }
+ #endif /* ENABLE_CHECKING */

    return token;
  }
*************** static void
*** 854,861 ****
--- 870,879 ----
  cp_lexer_save_tokens (cp_lexer* lexer)
  {
    /* Provide debugging output.  */
+ #ifdef ENABLE_CHECKING
    if (cp_lexer_debugging_p (lexer))
      fprintf (cp_lexer_debug_stream, "cp_lexer: saving tokens\n");
+ #endif /* ENABLE_CHECKING */

    /* Make sure that LEXER->NEXT_TOKEN is non-NULL so that we can
       restore the tokens if required.  */
*************** static void
*** 874,881 ****
--- 892,901 ----
  cp_lexer_commit_tokens (cp_lexer* lexer)
  {
    /* Provide debugging output.  */
+ #ifdef ENABLE_CHECKING
    if (cp_lexer_debugging_p (lexer))
      fprintf (cp_lexer_debug_stream, "cp_lexer: committing tokens\n");
+ #endif /* ENABLE_CHECKING */

    VARRAY_POP (lexer->saved_tokens);
  }
*************** cp_lexer_rollback_tokens (cp_lexer* lexe
*** 889,896 ****
--- 909,918 ----
    size_t delta;

    /* Provide debugging output.  */
+ #ifdef ENABLE_CHECKING
    if (cp_lexer_debugging_p (lexer))
      fprintf (cp_lexer_debug_stream, "cp_lexer: restoring tokens\n");
+ #endif /* ENABLE_CHECKING */

    /* Find the token that was the NEXT_TOKEN when we started saving
       tokens.  */
*************** cp_lexer_rollback_tokens (cp_lexer* lexe
*** 910,915 ****
--- 932,939 ----

/* Print a representation of the TOKEN on the STREAM. */

+ #ifdef ENABLE_CHECKING
+
  static void
  cp_lexer_print_token (FILE * stream, cp_token* token)
  {
*************** cp_lexer_stop_debugging (cp_lexer* lexer
*** 994,999 ****
--- 1018,1025 ----
    --lexer->debugging_p;
  }

+ #endif /* ENABLE_CHECKING */
+
  
  /* Decl-specifiers.  */


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