This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[cs]
- From: Per Bothner <per at bothner dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 30 Nov 2003 22:11:57 -0800
- Subject: [cs]
I checked the attached into the compile-server branch.
This is primarily to help gathering statics on fragments,
but there are some other cleanups.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2003-11-30 Per Bothner <pbothner@apple.com>
* cpplib.h (struct cpp_callbacks): Remove use of PARAMS macro.
Drop last two parameters of enter_fragment call-back.
* cppfiles.c (_cpp_enter_fragment): Likewise.
* c-common.h (cb_enter_fragment): Likewise.
* c-common.h (track_dependencies, track_declarations): New globals.
* c-common.c (track_dependencies, track_declarations): New globals.
(create_builtins_fragment): Set track_declarations.
(register_fragment_dependency): Do nothing unless track_dependencies.
(cb_enter_fragment): Calculate file name and line internally,
rather than being passed as parameters.
Set track_dependencies and track_declarations.
(cb_exit_fragment): Clear track_dependencies and track_declarations.
* c-common.c (cb_enter_fragment): Tweak inform messages.
* c-common.c (count_register_fragment_dependency_calls,
count_nonredundant_register_fragment_dependency_calls,
count_fragment_declarations, count_fragment_tags,
int count_new_fragments, count_new_empty_fragments,
lines_new_fragments, count_reread_fragments,
count_reread_empty_fragments, lines_reread_fragments,
count_reused_fragments, count_reused_empty_fragments,
lines_reused_fragments, current_fragment_is_new,
current_fragment_nested_at_start, current_fragment_nested_at_end):
New counters used for gathering statistics.
(note_fragment_binding_1, note_fragment_binding_3,
register_fragment_dependency, cb_enter_fragment, cb_exit_fragment):
Adjust counters.
(define gather_fragment_statistics): Enable/disable statistics.
(report_fragment_statistics): Print out statistics.
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.261.2.8
diff -u -p -r1.261.2.8 cpplib.h
--- cpplib.h 24 Nov 2003 21:56:12 -0000 1.261.2.8
+++ cpplib.h 1 Dec 2003 06:07:05 -0000
@@ -404,12 +404,11 @@ struct cpp_callbacks
const char *, int);
/* Notifies front-end end that the current fragment uses some other
fragment. Called if non-null when a macro is used. */
- void (*uses_fragment) PARAMS ((cpp_reader*, cpp_fragment*));
+ void (*uses_fragment) (cpp_reader*, cpp_fragment*);
/* True if this is a bad place to create a new fragment. */
- bool (*avoid_new_fragment) PARAMS ((cpp_reader*));
- bool (*enter_fragment) PARAMS ((cpp_reader *, cpp_fragment *,
- const char*, int));
- void (*exit_fragment) PARAMS ((cpp_reader *, cpp_fragment *));
+ bool (*avoid_new_fragment) (cpp_reader*);
+ bool (*enter_fragment) (cpp_reader *, cpp_fragment *);
+ void (*exit_fragment) (cpp_reader *, cpp_fragment *);
void (*define) (cpp_reader *, unsigned int, cpp_hashnode *);
void (*undef) (cpp_reader *, unsigned int, cpp_hashnode *);
void (*ident) (cpp_reader *, unsigned int, const cpp_string *);
Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.177.2.9
diff -u -p -r1.177.2.9 cppfiles.c
--- cppfiles.c 24 Nov 2003 21:54:13 -0000 1.177.2.9
+++ cppfiles.c 1 Dec 2003 06:07:05 -0000
@@ -603,9 +603,7 @@ _cpp_enter_fragment (pfile, fragment)
{
if (pfile->cb.enter_fragment != NULL)
{
- if (pfile->cb.enter_fragment (pfile, fragment,
- fragment->name,
- SOURCE_LINE (linemap_lookup (&pfile->line_maps, pfile->line), pfile->line)))
+ if (pfile->cb.enter_fragment (pfile, fragment))
{
pfile->buffer->cur = fragment->end;
pfile->buffer->line_base = fragment->end - 1;
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.194.2.8
diff -u -p -r1.194.2.8 c-common.h
--- c-common.h 24 Nov 2003 21:56:13 -0000 1.194.2.8
+++ c-common.h 1 Dec 2003 06:07:06 -0000
@@ -196,6 +196,8 @@ extern size_t c_tree_size (enum tree_cod
#define FRAGMENT_CHAIN(F) (TREE_TYPE (F))
#define FRAGMENT_GLOBAL_CHAIN(F) (TREE_CHAIN (F))
+extern int track_dependencies;
+extern int track_declarations;
extern int main_timestamp;
extern int c_timestamp;
extern GTY(()) struct c_include_fragment *current_c_fragment;
@@ -222,7 +224,7 @@ extern void process_undo_buffer (void);
extern tree save_fragment_bindings (void);
-extern bool cb_enter_fragment (cpp_reader*, cpp_fragment*, const char*, int);
+extern bool cb_enter_fragment (cpp_reader*, cpp_fragment*);
extern void cb_exit_fragment (cpp_reader*, cpp_fragment*);
extern void cb_uses_fragment (cpp_reader*, cpp_fragment*);
extern bool cb_avoid_new_fragment (cpp_reader*);
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.438.2.12
diff -u -p -r1.438.2.12 c-common.c
--- c-common.c 24 Nov 2003 21:56:12 -0000 1.438.2.12
+++ c-common.c 1 Dec 2003 06:07:08 -0000
@@ -4204,6 +4204,7 @@ create_builtins_fragment (void)
builtins_fragment = fragment;
builtins_c_fragment = st;
parse_in->do_note_macros = 1;
+ track_declarations = 1;
}
/* Note that the current fragment depends on USED. */
@@ -4332,12 +4333,18 @@ note_tag (tree tagtype)
}
}
+int count_register_fragment_dependency_calls;
+int count_nonredundant_register_fragment_dependency_calls;
+int count_fragment_declarations;
+int count_fragment_tags;
+
void
note_fragment_binding_1 (tree1)
tree tree1;
{
reserve_fragment_binding (1);
TREE_VEC_ELT (fragment_bindings_stack, fragment_bindings_end - 1) = tree1;
+ count_fragment_declarations++;
}
void
@@ -4357,6 +4364,7 @@ note_fragment_binding_3 (tree1, tree2, t
TREE_VEC_ELT (fragment_bindings_stack, fragment_bindings_end - 3) = tree1;
TREE_VEC_ELT (fragment_bindings_stack, fragment_bindings_end - 2) = tree2;
TREE_VEC_ELT (fragment_bindings_stack, fragment_bindings_end - 1) = tree3;
+ count_fragment_tags++;
}
/* Note that the current fragment depends on (some binding from) USED. */
@@ -4365,6 +4373,9 @@ void
register_fragment_dependency (used)
struct c_include_fragment* used;
{
+ if (! track_dependencies)
+ return;
+ count_register_fragment_dependency_calls++;
if (! used->used_in_current && used != current_c_fragment
&& used != builtins_c_fragment
&& current_c_fragment != NULL)
@@ -4386,9 +4397,12 @@ register_fragment_dependency (used)
= (tree) used;
current_fragment_deps_end++;
used->used_in_current = 1;
+ count_nonredundant_register_fragment_dependency_calls++;
}
}
+int track_dependencies;
+int track_declarations;
int main_timestamp;
int c_timestamp;
/* Inside an incomplete enum, for example. */
@@ -4450,6 +4464,47 @@ dont_defeat_good_checking ()
}
#define warn_fragment_invalidation (! quiet_flag)
+#define gather_fragment_statistics 0
+
+int count_new_fragments;
+int count_new_empty_fragments;
+int lines_new_fragments;
+int count_reread_fragments;
+int count_reread_empty_fragments;
+int lines_reread_fragments;
+int count_reused_fragments;
+int count_reused_empty_fragments;
+int lines_reused_fragments;
+int current_fragment_is_new;
+int current_fragment_nested_at_start;
+int current_fragment_nested_at_end;
+
+extern void report_fragment_statistics (void);
+void
+report_fragment_statistics (void)
+{
+ if (gather_fragment_statistics)
+ {
+ fprintf (stderr, "%d fragments with %d lines (%d empty)"
+ " read for the first time\n",
+ count_new_fragments, lines_new_fragments,
+ count_new_empty_fragments);
+
+ fprintf (stderr, "%d fragments with %d lines (%d empty)"
+ " invalidated and re-read\n",
+ count_reread_fragments, lines_reread_fragments,
+ count_reread_empty_fragments);
+
+ fprintf (stderr, "%d fragments with %d lines (%d empty) reused\n",
+ count_reused_fragments, lines_reused_fragments,
+ count_reused_empty_fragments);
+ fprintf (stderr, "registered %d non-redundant (%d total) fragment dependencies\n",
+ count_nonredundant_register_fragment_dependency_calls,
+ count_register_fragment_dependency_calls);
+ fprintf (stderr, "%d declarations and %d tags in fragments\n",
+ count_fragment_declarations, count_fragment_tags);
+ }
+}
/* Called from cpp at the start of a new fragment.
Check if the fragment has been seen before and we can re-use the
@@ -4458,16 +4513,16 @@ dont_defeat_good_checking ()
up so we can remember new bindings as we see them. */
bool
-cb_enter_fragment (reader, fragment, name, line)
- cpp_reader* reader ATTRIBUTE_UNUSED;
- cpp_fragment *fragment;
- const char* name;
- int line;
+cb_enter_fragment (cpp_reader* reader, cpp_fragment *fragment)
{
struct c_include_fragment* st = C_FRAGMENT (fragment);
bool valid = 0;
+ const char* name = fragment->name;
+#if 0
input_filename = fragment->name;
- input_line = line;
+ input_line = SOURCE_LINE (linemap_lookup (&reader->line_maps, reader->line), reader->line);
+#endif
+ current_fragment_is_new = 0;
if (st == NULL)
{
if (!lang_hooks.uses_conditional_symtab)
@@ -4475,6 +4530,9 @@ cb_enter_fragment (reader, fragment, nam
st = alloc_include_fragment ();
st->name = name;
st->valid = 0;
+ if (warn_fragment_invalidation)
+ inform ("fragment seen for the first time");
+ current_fragment_is_new = 1;
}
}
else
@@ -4486,11 +4544,12 @@ cb_enter_fragment (reader, fragment, nam
{
valid = 0;
if (warn_fragment_invalidation)
- inform ("invalidating cached fragment because it is inside a declaration");
+ inform ("invalidating cached fragment because it begins inside a declaration");
}
if (st->include_timestamp >= main_timestamp
&& valid
+ && ! fragment->empty
&& dont_defeat_good_checking ())
{
/* This fragment has already been included for this main file.
@@ -4542,8 +4601,11 @@ cb_enter_fragment (reader, fragment, nam
}
else
{
- if (warn_fragment_invalidation)
- inform ("reusing cached fragment");
+ if (warn_fragment_invalidation && ! fragment->empty)
+ {
+ inform ("reusing cached fragment");
+ fprintf(stderr, "reuse %d lines (start:%d, end:%d)\n", fragment->end_line - fragment->start_line, fragment->start_line, fragment->end_line);
+ }
restore_fragment (fragment);
}
}
@@ -4580,6 +4642,17 @@ cb_enter_fragment (reader, fragment, nam
/* Note fragment->was_resued is redundant - it's same as
st->include_timestamp > st->read_timestamp */
fragment->was_reused = valid;
+ track_dependencies = !valid;
+ track_declarations = !valid;
+ if (gather_fragment_statistics && valid)
+ {
+ int num_lines = fragment->end_line - fragment->start_line;
+ bool is_empty = fragment->empty;
+ count_reused_fragments++;
+ lines_reused_fragments += num_lines;
+ if (is_empty)
+ count_reused_empty_fragments++;
+ }
return valid;
}
@@ -4624,6 +4697,9 @@ cb_exit_fragment (reader, fragment)
{
struct c_include_fragment* st = C_FRAGMENT (fragment);
reader->do_note_macros = 0;
+ track_dependencies = 0;
+ track_declarations = 0;
+
if (st != NULL)
{
int i;
@@ -4662,10 +4738,30 @@ cb_exit_fragment (reader, fragment)
}
current_c_fragment = NULL;
+ if (gather_fragment_statistics)
+ {
+ int num_lines = reader->line - fragment->start_line;
+ bool is_empty = reader->mi_valid;
+ if (current_fragment_is_new)
+ {
+ count_new_fragments++;
+ lines_new_fragments += num_lines;
+ if (is_empty)
+ count_new_empty_fragments++;
+ }
+ else
+ {
+ count_reread_fragments++;
+ lines_reread_fragments += num_lines;
+ if (is_empty)
+ count_new_empty_fragments++;
+ }
+ }
+
if (currently_nested)
{
if (warn_fragment_invalidation)
- inform ("invalidating cached fragment because it is inside a declaration");
+ inform ("invalidating cached fragment because it ends inside a declaration");
st->valid = 0;
}
else