[cfe-dev] Tree transformation in clang
eyasu getahun
eya.get at gmail.com
Thu Dec 1 07:22:40 PST 2011
Hi Vassil,
Sorry I was out for dinner. Its so great explanation and it is much
helpful. Thanks a lot.
For optimization, I know it is easier to do it at LLVM bitcode level. But
my intention is to do it at AST level. Most optimization passes are already
implemented at LLVM level. Later, I will implement optimizations at llvm
level. Thanks again.
On Thu, Dec 1, 2011 at 10:03 PM, Vassil Vassilev <
vasil.georgiev.vasilev at cern.ch> wrote:
> **
> Hi,
> TreeTransform is part of the "curiously recurring template pattern" used
> all around in clang.
> You could define your own transformation that uses that pattern. It is
> very efficient because it
> allows to have sort-of inheritance without having vtables.
> Example code you can find in:
> /lib/Sema/SemaTemplateInstantiate.cpp
> /lib/Sema/SemaTemplateDeduction.cpp
> /lib/Sema/SemaTemplate.cpp
> However, TreeTransform is not public interface...
>
> There were a lot of changes in it recently and maybe my experience is
> old-dated but
> I tried to use it once and I had hard time when I wanted to replace one
> node with 2 or more
> nodes or when I tried to remove nodes. For 1:1 transformation I think is
> very good interface, though.
>
> Talking about optimizations: Have you consider the LLVM bitcode - it is
> SSA based and IMHO
> is much more suitable for optimizations?
>
> Vassil
>
>
> On 12/01/2011 02:36 PM, eyasu getahun wrote:
>
>
> Hello Vasil,
>
> Thanks for your detail explanation. The main thing what I want to do is
> AST level optimization. But before implementing optimizations, I need to
> transform the resulting AST which is build by clang after parsing the given
> source code. That mean i want to transform this AST to another AST. Later
> it will be easy to implement optimizations on the new AST. When i read
> clang source files, I got TreeTransformation.h file. I thought that there
> is tree to tree transformation that is already implemented inside clang.
> But I couldn't get the implementation. Now am getting information from you
> guys that this file is just a facility or base for implementation other
> transformations. So, this is good information that I got from you guys. Now
> am going to do the transformation by my self and implementing optimizations
> later on. If there was implemented tree to tree transformation, i don't
> need to go implement tree transformation.
>
> Hope you got my idea. It is just my ideal design and didn't go further. I
> will start the tasks soon. Do you have any idea or suggestion how to go?
> Thanks again.
>
> On Thu, Dec 1, 2011 at 9:01 PM, Vassil Vassilev <
> vasil.georgiev.vasilev at cern.ch> wrote:
>
>> Hi,
>> TreeTransform is the facility used to rebuild the templated nodes of
>> the AST once
>> clang has the full type/value information (for example at instantiation
>> time). It replaces
>> the nodes that are marked as of dependent type with their actual
>> instantiation type and
>> performs the semantic checks with the new types.
>>
>> Maybe if you clarify a little bit more (and perhaps give examples) I
>> can be more helpful.
>> In general TreeTransform is not meant to implement every possible
>> tree-to-tree transformation.
>>
>> Nevertheless, it can be used as model how to build your own one. Right
>> now I am not aware of
>> an interface that implements arbitrary tree-to-tree transformation.
>> However, there are couple of interfaces that you might find useful for
>> that. You might want to
>> have a look at clang::ASTConsumer, clang::SemaConsumer and
>> clang::RecursiveASTVisitor
>>
>> Depending on what is the exact idea of the transformation you could also
>> use clang's
>> rewrite subsystem, which is pretty powerful, but it AFAIK it doesn't work
>> on AST level. It is more
>> source-to-source transformation.
>>
>> Vassil
>>
>>
>> On 11/30/2011 04:20 AM, eyasu getahun wrote:
>>
>> Hello all,
>>
>> I have seen tree transformation in clang(TreeTransform.h). This is to
>> transform one AST to another AST. But it is not clear for me how they used
>> this header file for the transformation. I didn't see the function for the
>> transformation. Just they used this header file for semantic template
>> instantiation and template deduction. Even there is no explicit command
>> line option for the transformation. Do you guys think that the
>> transformation is well implemented and documented? please let me know if
>> you have any idea about the transformation that they used in clang. Thanks
>> in advance!
>>
>>
>> --
>> *With Best Regards,
>>
>> ===========================================
>> Eyasu Getahun*
>>
>>
>>
>> _______________________________________________
>> cfe-dev mailing listcfe-dev at cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>>
>
>
> --
> *With Best Regards,
>
> ===========================================
> Eyasu Getahun*
>
> 1 Fusionopolis way, #08-10 Connexis North Tower
> Singapore 138632, Singapore
> Mobile: +393279239907
> *===========================================
> *
>
>
>
--
*With Best Regards,
===========================================
Eyasu Getahun*
1 Fusionopolis way, #08-10 Connexis North Tower
Singapore 138632, Singapore
Mobile: +393279239907
*===========================================
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111201/4c72a18a/attachment.html>
More information about the cfe-dev
mailing list