A small tweak to avoid inserting the same decl more than once in the symbol ...
13 years, 8 months ago
(2011-07-18 16:39:06 UTC)
#1
A small tweak to avoid inserting the same decl more than once in the
symbol table for a pph image.
Tested on x86_64. Committed to branch.
Diego.
* pph-streamer-in.c (pph_in_struct_function): Revert previous
change. Do not allow shared struct functions.
* pph-streamer-out.c (decls_to_register_t): New type.
(decls_to_register): Change type to decls_to_register_t.
Update all users.
(pph_add_decl_to_register): Do not register the same DECL more
than once.
diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 0808cab..f1aa7c9 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -819,18 +819,14 @@ pph_in_struct_function (pph_stream *stream)
marker = pph_in_start_record (stream, &ix);
if (marker == PPH_RECORD_END)
return NULL;
- else if (marker == PPH_RECORD_SHARED)
- return (struct function *) pph_in_shared_data (stream, ix);
- decl = pph_in_tree (stream);
+ /* Since struct function is embedded in every decl, fn cannot be shared. */
+ gcc_assert (marker != PPH_RECORD_SHARED);
+ decl = pph_in_tree (stream);
allocate_struct_function (decl, false);
fn = DECL_STRUCT_FUNCTION (decl);
- /* Now register it. We would normally use ALLOC_AND_REGISTER,
- but retrofit_lang_decl does not return a pointer. */
- pph_register_shared_data (stream, fn, ix);
-
input_struct_function_base (fn, stream->data_in, stream->ib);
/* struct eh_status *eh; -- zero init */
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index ee294df..15a0c53 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -43,7 +43,16 @@ static FILE *current_pph_file = NULL;
we finish parsing the header file, this array is written out to the
PPH image. This way, the reader will be able to instantiate these
symbols in the same order that they were instantiated originally. */
-static VEC(tree,heap) *decls_to_register = NULL;
+typedef struct decls_to_register_t {
+ /* Table of all the declarations to register in declaration order. */
+ VEC(tree,heap) *v;
+
+ /* Set of declarations to register used to avoid adding duplicate
+ entries to the table. */
+ struct pointer_set_t *m;
+} decls_to_register_t;
+
+static decls_to_register_t decls_to_register = { NULL, NULL };
/* Callback for packing value fields in ASTs. BP is the bitpack
we are packing into. EXPR is the tree to pack. */
@@ -1236,8 +1245,8 @@ pph_out_symtab (pph_stream *stream, bool ref_p)
tree decl;
unsigned i;
- pph_out_uint (stream, VEC_length (tree, decls_to_register));
- FOR_EACH_VEC_ELT (tree, decls_to_register, i, decl)
+ pph_out_uint (stream, VEC_length (tree, decls_to_register.v));
+ FOR_EACH_VEC_ELT (tree, decls_to_register.v, i, decl)
if (TREE_CODE (decl) == FUNCTION_DECL && DECL_STRUCT_FUNCTION (decl))
{
if (DECL_SAVED_TREE (decl))
@@ -1252,7 +1261,12 @@ pph_out_symtab (pph_stream *stream, bool ref_p)
pph_out_tree (stream, decl, ref_p);
}
- VEC_free (tree, heap, decls_to_register);
+ if (decls_to_register.m)
+ {
+ VEC_free (tree, heap, decls_to_register.v);
+ pointer_set_destroy (decls_to_register.m);
+ decls_to_register.m = NULL;
+ }
}
@@ -1263,6 +1277,8 @@ pph_write_file_contents (pph_stream *stream,
cpp_idents_used *idents_used)
{
/* Emit all the identifiers and symbols in the global namespace. */
pph_out_identifiers (stream, idents_used);
+
+ /* Emit the bindings for the global namespace. */
pph_out_scope_chain (stream, scope_chain, false);
if (flag_pph_dump_tree)
pph_dump_namespace (pph_logfile, global_namespace);
@@ -1665,5 +1681,11 @@ void
pph_add_decl_to_register (tree decl)
{
if (decl)
- VEC_safe_push (tree, heap, decls_to_register, decl);
+ {
+ if (decls_to_register.m == NULL)
+ decls_to_register.m = pointer_set_create ();
+
+ if (!pointer_set_insert (decls_to_register.m, decl))
+ VEC_safe_push (tree, heap, decls_to_register.v, decl);
+ }
}
--
This patch is available for review at http://codereview.appspot.com/4758052
Issue 4758052: [pph] Do not emit the same decl more than once in the symbol table
(Closed)
Created 13 years, 8 months ago by Diego Novillo
Modified 13 years, 7 months ago
Reviewers:
Base URL:
Comments: 0