[patch] Introduce deep unsharing

Eric Botcazou ebotcazou@adacore.com
Mon May 17 20:49:00 GMT 2010


> "unshare" == make local copies of global types in each function
> that uses them?  (and thus never actually use the global type?)

No, we unshare only the size expressions, not the types themselves.

> If you don't end up copying the types themselves I still don't see
> how copying anything else will avoid gimplification of one function
> affecting that of another.

If you copy the original expressions in a function and gimplify the result, 
the original expressions are obviously not affected.

> If we don't copy the types then its sizes get gimplified in the first
> function and TYPE_SIZES_GIMPLIFIED gets set on the type.

As I said previously, TYPE_SIZES_GIMPLIFIED is set on the types and the size 
expressions are marked with TREE_VISITED when they are created.  So, for each 
function the size expressions are referenced in, they are first unshared 
(copied) then gimplified.  The original expressions aren't affected at all.

> When we arrive at the 2nd function no matter if we copy anything
> in the type itself TYPE_SIZES_GIMPLIFIED is still set and the
> type sizes are replaced.  If you otoh avoid gimplifying the type sizes
> then you won't get them gimplified.

Of course, you cannot gimplify global types since they are global.

> So maybe you don't want to gimplify type sizes but only gimplify
> references to them inside COMPONENT_REFs and ARRAY_REFs?
> And those are all via SAVE_EXPRs that are shared between
> expressions across functions?   So you'd need to copy the SAVE_EXPR
> itself before gimplifying it?  At least I don't see how only copying
> its argument is going to help you - the SAVE_EXPR itself will still
> be shared and you modify all shared uses.

No, SAVE_EXPRs must never be shared between functions since you cannot unshare 
them.  So we never generate SAVE_EXPRs at the global level, including in size 
expressions for global types.  The problem is regular SAVE_EXPRs generated in 
functions and which happen to reference size expressions in their subtree.

This unsharing mechanism for global types has been there since GCC 4.0.0, 
unmodified.  It works in 99% of the cases.  We ran into the remaining 1% at 
AdaCore so we extended it with deep unsharing 4 years ago, going through 
several iterations over the years to refine and simplify it.  The outcome is 
the patch I posted and I don't think we can do much simpler/better.

See http://gcc.gnu.org/ml/gcc-patches/2008-05/msg00939.html for an earlier 
submission of a more intrusive version.

-- 
Eric Botcazou



More information about the Gcc-patches mailing list