[PATCH] Fix tree node sharing problem (2/2)

Eric Botcazou ebotcazou@adacore.com
Thu May 15 22:31:00 GMT 2008


Hi,

Ada is very sensitive to tree node sharing because it deals with a lot of 
global parameterized types.  When the variable components of these types are 
gimplified via gimplify_type_sizes, they cause temporaries to be created and 
these are tied to a given subprogram; hence the gimplification cannot occur 
on the original expression attached to the type but only on a copy that has 
previously been created by the mark/copy-if-shared/unmark mechanism of the 
gimplifier.

This mechanism has an annoying limitation for SAVE_EXPRs (and TARGET_EXPRs): 
it simply balks at them.  More precisely, the unsharing stops at SAVE_EXPRs, 
on the grounds that SAVE_EXPRs must not be copied by definition.  But nodes 
under the SAVE_EXPRs can be shared too if they come from a global type and 
thus may need to be unshared too.

We have used a kludge in Gigi to overcome this limitation up to now, but it 
doesn't work in all cases and is somewhat gross.  Therefore we are proposing
to teach the gimplifier to unshare nodes under SAVE_EXPRs too, without of 
course unsharing the SAVE_EXPRs themselves.  We have been doing this in our 
compiler for quite some time now.

The attached patch has been bootstrapped/regtested on x86_64-suse-linux with 
no effect on total user time.  Of course this new feature is only required 
for Ada so it could as well be keyed on a langhook.  OK for mainline?


2008-05-15  Eric Botcazou  <ebotcazou@adacore.com>

	* gimplify.c: Include pointer-set.h.
	(mostly_copy_tree_r): Copy trees under SAVE_EXPR and TARGET_EXPR
	nodes, but only once.  Stop at BIND_EXPR nodes.  Do not propagate
	the 'data' argument to copy_tree_r.
	(copy_if_shared_r): Unshare trees under SAVE_EXPR and TARGET_EXPR
	nodes, but only once.  Remove redundant code dealing with types,
	decls and constants.  Remove bogus ATTRIBUTE_UNUSED marker.
	Propagate 'data' argument to walk_tree.
	(copy_if_shared): New function.
	(unmark_visited_r): Unmark trees under SAVE_EXPR and TARGET_EXPR
	nodes, but only once.  Remove bogus ATTRIBUTE_UNUSED marker.
	(unmark_visited): New function.
	(unshare_body): Call copy_if_shared instead of doing it manually.
	(unvisit_body): Call unmark_visited instead of doing it manually.
	(unshare_all_trees): Likewise.
	* Makefile.in (gimplify.o): Add pointer-set.h dependency.
ada/
	* trans.c (unshare_save_expr): Delete.
	(gigi): Do not unshare trees under SAVE_EXPRs here.


-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-diff
Size: 10169 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080515/aa828f0e/attachment.bin>


More information about the Gcc-patches mailing list