[cfe-dev] TreeTransform: QualType for OpenCL float4

Christoph Viebig (lists) lists at christoph-viebig.de
Wed Jan 21 10:05:20 PST 2015


Hello list,

I am currently prototyping source-to-source transformation using
TreeTransform and would like to replace an OpenCL float variable type
by a vector variant like float4 (i.e. vectorize code) [0].

Background
----------

I know that AST transformations are somehow complicated as the
corresponding API (TreeTransform.h) is internal and for some purposes
not complete enaugh as discussed earlier in the threads [1, 2-3, 4-5,
6-7] but I have the strong feeling that an AST based transformation
is better than String concatenation/replacement in the long run,
especially when you need to recursively transform whole sub trees.

That's why I have the hope that it's still possible to reach my goals
using TreeTransform and some custom extensions that fit my needs (i.e.
rebuild instances of FunctionDecl and ParmVarDecl which is not
supported right now). For the use case of loop unrolling this worked
out fine so far.

My question focuses on changing variable types in VarDecl and
ParmVarDecl. Variable types (like int, float, ..) are stored as far as
I understand in QualType objects [8], holding information about the
actual type as well as their qualifiers (const, volatile). The type is
represented by an instance of Type [9].

Question
--------

My question is now: How can I construct or retrieve an instance of
Type that represents OpenCL float4 (e.g. from Sema or Context)?

As far as I found out it's possible to rebuild ParamVarDecl objects
by calling

ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
                             SourceLocation StartLoc,
                             SourceLocation IdLoc, IdentifierInfo *Id,
                             QualType T, TypeSourceInfo *TInfo,
                             StorageClass S, Expr *DefArg)

as shown in Sema::BuildParmVarDeclForTypedef(..) in SemaDecl.cpp but
it's required to hand over an instance of QualType which I do not have
at the moment.

--------

By the time writing this email I have also stumbled over
Sema::CheckParameter(..) in the same file. I know that I have to take
care of the AST invariants, that's why I would like to build as much
as possible on methods that validate them of course but for a first
prototype it would be sufficient to generate valid code using the
pretty printing functionality.

Please excuse this rather long email but I hope it gives enaugh
background to judge my question. I would be very happy if you can find
a short minute to give me hints on how to solve it.

Thank you very much in advance

Best regards
Christoph


[0]
https://www.khronos.org/registry/cl/sdk/2.0/docs/man/xhtml/vectorDataTypes.html

[1] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-July/023072.html

[2] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-March/020423.html
[3] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-April/020515.html

[4] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-May/037176.html
[5] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-June/037272.html

[6] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-March/028322.html
[7] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-April/028828.html

[8] http://clang.llvm.org/doxygen/classclang_1_1QualType.html
[9] http://clang.llvm.org/doxygen/classclang_1_1Type.html



More information about the cfe-dev mailing list