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]

[pph] Change representation of mutated trees (issue5540070)


This patch changes the representation of mutated trees to avoid
creating unnecessary (and ultimately confusing) cache entries.

Mutated trees are those that we read initially from an external PPH
image and get changed during parsing.  The most common case is when
the external PPH image has a declaration which is converted into a
full definition in the current file.

When we initially read these trees, we compute a checksum of its body.
So, when we write it out in the second file, we decide whether the
tree has mutated by re-computing its checksum.  If it did, we write a
special record (PPH_RECORD_START_MUTATED) which indicates to the
reader that this is a tree that exists in an external file, but its
body should be re-read.

Before this patch, we would also insert the tree into the cache of the
current file.  This converted further references to the tree into
internal references.

This is unnecessary, since the tree is already present in the external
cache.  Additionally, the new merging code that Lawrence is working on
gets confused by it, as it expects to always find the tree in the
external cache.

This patch changes that.  We now write the mutated reference to the
external cache.  But instead of adding the tree to the internal cache
of the current file, we re-sign the tree.

This way, subsequent references to the tree will resolve as regular
external references (PPH_RECORD_XREF).



	* pph-in.c (pph_in_tree): Do not expect an internal reference
	when reading a mutated tree.
	Only add the tree to the cache for PPH_RECORD_START markers.
	* pph-out.c (pph_out_start_tree_record): Do not add mutated
	trees to the internal cache.
	Re-sign mutated trees.
	Do not write an internal reference.

diff --git a/gcc/cp/pph-in.c b/gcc/cp/pph-in.c
index 827c8fd..ae918a2 100644
--- a/gcc/cp/pph-in.c
+++ b/gcc/cp/pph-in.c
@@ -2426,9 +2426,6 @@ pph_in_tree (pph_stream *stream)
          PPH image.  */
       expr = (tree) pph_cache_find (stream, PPH_RECORD_XREF, image_ix, ix,
 				    PPH_any_tree);
-
-      /* Read the internal cache slot where EXPR should be stored at.  */
-      ix = pph_in_uint (stream);
     }
   else if (marker == PPH_RECORD_START_MERGE_BODY)
     {
@@ -2438,12 +2435,13 @@ pph_in_tree (pph_stream *stream)
       expr = (tree) pph_cache_get (&stream->cache, ix);
     }
 
-  /* Add the new tree to the cache and read its body.  The tree is
-     added to the cache before we read its body to handle circular
-     references and references from children nodes.  If we are reading
-     a merge body, then the tree is already in the cache (it was added
-     by pph_in_merge_key_tree).  */
-  if (marker != PPH_RECORD_START_MERGE_BODY)
+  /* If we are starting to read a full tree, add its pointer to the
+     cache and read its body.  The tree is added to the cache before
+     we read its body to handle circular references and references
+     from children nodes.  If we are reading a merge body, then the
+     tree is already in the cache (it was added by
+     pph_in_merge_key_tree).  */
+  if (marker == PPH_RECORD_START)
     pph_cache_insert_at (&stream->cache, expr, ix, pph_tree_code_to_tag (expr));
 
   if (flag_pph_tracer)
diff --git a/gcc/cp/pph-out.c b/gcc/cp/pph-out.c
index 08c9862..55b48cb 100644
--- a/gcc/cp/pph-out.c
+++ b/gcc/cp/pph-out.c
@@ -696,33 +696,32 @@ pph_out_start_tree_record (pph_stream *stream, tree t)
     }
   else if (marker == PPH_RECORD_START_MUTATED)
     {
-      unsigned int internal_ix;
+      unsigned new_crc;
+      size_t nbytes;
+      pph_cache *ext_cache;
 
       /* We found T in an external PPH file, but it has mutated since
          we originally read it.  We are going to write out T again,
-         but the reader should not re-allocate T, rather it should
+         but the reader should not re-allocate T.  Rather, it should
          read the contents of T on top of the existing address.
 
-         We also add T to STREAM's internal cache so further
-         references go to it rather than the external version.
-         Note that although we add an entry for T in STREAM's internal
-         cache, the reference we write to the stream is to the
-         external version of T.  This way the reader will get the
-         location of T from the external reference and overwrite it
-         with the contents that we are going to write here.  */
-      pph_cache_add (&stream->cache, t, &internal_ix, tag);
+	 We also re-compute T's CRC and update its cache entry.  This
+	 way, further references to T will become regular external
+	 references.  */
       pph_out_record_marker (stream, marker, tag);
 
+      /* Update the CRC for T in the external cache, so we don't
+	 continue to consider it mutated.  */
+      new_crc = pph_get_signature (t, &nbytes);
+      ext_cache = pph_cache_select (stream, PPH_RECORD_XREF, include_ix);
+      pph_cache_sign (ext_cache, ix, new_crc, nbytes);
+
       /* Write the location of T in the external cache.  */
       gcc_assert (include_ix != -1u);
       pph_out_uint (stream, include_ix);
 
       gcc_assert (ix != -1u);
       pph_out_uint (stream, ix);
-
-      /* Now write the location of the new version of T in the
-         internal cache.  */
-      pph_out_uint (stream, internal_ix);
     }
   else
     gcc_unreachable ();
@@ -2304,7 +2303,6 @@ pph_out_tree (pph_stream *stream, tree expr)
 
   if (marker == PPH_RECORD_START || marker == PPH_RECORD_START_MUTATED)
     {
-
       /* This is the first time we see EXPR, write it out.  */
       if (marker == PPH_RECORD_START)
         {

--
This patch is available for review at http://codereview.appspot.com/5540070


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