[cfe-dev] Adding support for Cloning in the AST

moataz ragab mtzrgb at gmail.com
Sat May 23 15:50:30 PDT 2009


On Sat, May 23, 2009 at 3:46 PM, Sebastian Redl <
sebastian.redl at getdesigned.at> wrote:

> Douglas Gregor wrote:
> >
> > On May 19, 2009, at 7:18 PM, moataz ragab wrote:
> >
> >> Whether it might be useful or not to clone a declaration, it might be
> >> useful if you want to create a new variable declaration similar to
> >> another declaration and only change the name.
> >
> >
> > Hmmm, interesting. It seems to me like we really want to give the
> > expression's Clone method some information that tells it what to do
> > with declarations. For your loop-unrolling rewriter, we want to
> > replace some variable declarations with other, similar variables
> > (e.g., when the original variable was declared in the loop) or reuse
> > the same variable declaration (if the variable is declared outside the
> > loop).
>

   For the loop unrolling rewriter, I was thinking about skipping the
declarations in loop body and replace them with an assignmen if they were
initializing the variable. I planned to stop the cloning at this level and
make the expression point to the same declaration.
It doesn't come to my mind a case where I would need to declare another
variable. Please correct me if I am wrong?
But this is not a generic approach to cloning.

I had another application, where I want to do loop splitting on parallel
processors and that will need to split the arrays to keep them local to each
processor memory. I haven't really gone through the implementation but was
thinking of just cloning the declaration, change the name and size of the
array.

For my purposes, where I need to build a canonical expression,
> > we replace types with their canonical types and replace some
> > declarations (e.g., for non-type template parameters) with their
> > "canonical" declarations. This tells me that we need to think about
> > some kind of policy argument for Clone() that permits these changes.
> A callback to handle all sub-objects, instead of just cloning
> recursively? It would be very tricky to do as a "policy" that is
> anything less than a fully generic callback, given that cloning is deep.
> The callback has to handle everything in that part of the AST somehow.
> You can't stop at a single level.
>
   What do you think about passing a visitor to Clone()?

>
>
> Sebastian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090524/cf9ea606/attachment.html>


More information about the cfe-dev mailing list