[cfe-dev] TreeTransform: QualType for OpenCL float4

Christoph Viebig (lists) lists at christoph-viebig.de
Tue Jan 27 07:48:41 PST 2015


Hi Sameer, hi list,

you were right with your hint. OpenCL vector types (float2,float4,..)
are (at least in libclc) TypedefTypes. So pointing me to
Sema::addImplicitTypedef() was good. The types are declared for example
in libclc/generic/include/clc/clctypes.h:

  typedef __attribute__((ext_vector_type(4))) float float4;

Known identifiers are stored in ASTContext's IdentifierTable.
Having this it's possible to ask Sema for the QualType of a known
identifier using it's IdentifierInfo. The following snippet assumes
a reference to an instance of Sema in the variable SemaRef and shows
how you can retrieve the QualType of a previously declared type:

  IdentifierInfo& VectorII = SemaRef.getASTContext().Idents.get("float4");
  ParsedType PT = SemaRef.getTypeName(VectorII, SourceLocation(),
SemaRef.getCurScope());
  QualType Q = PT.get();

Best regards
Christoph

> "Christoph Viebig (lists)" <lists at christoph-viebig.de> hat am 23. Januar 2015
> um 12:27 geschrieben:
>
>
> Hi Sameer,
>
> thanks again for your answer :)
> Unfortunately it turns out that this doesn't work.
> So the print out is still: float data __attribute__((ext_vector_type(4)))
> But I could imagine from the use of the method that it can be used to register
> type aliases like in C++ typedef. But I might be wrong though.
>
> I will try to look on it later today again. Maybe I'll find something in the
> Parser or so.
>
> Best
> Christoph
>
> > "Sahasrabuddhe, Sameer" <Sameer.Sahasrabuddhe at amd.com> hat am 22. Januar
> > 2015
> > um 19:46 geschrieben:
> >
> >
> >
> > Sema::addImplicitTypedef() seems to be meant for registering a "name" for a
> > type, although I have never used it myself! Can't make out if this will help
> > your purpose, which is to print "float16" instead of the entire extended
> > vector syntax.
> >
> > Sameer.
> > ________________________________________
> > From: Christoph Viebig (lists) [lists at christoph-viebig.de]
> > Sent: Thursday, January 22, 2015 5:31 PM
> > To: cfe-dev at cs.uiuc.edu; Sahasrabuddhe, Sameer
> > Subject: Re: [cfe-dev] TreeTransform: QualType for OpenCL float4
> >
> > Hi Sameer,
> >
> > thank you very much for your answer. It indeed works fine, altough it seems
> > that
> > pointer types can not be converted by
> > SemaRef.getASTContext().getExtVectorType(Param->getType(), 4);
> > because assert(vecType->isBuiltinType() || vecType->isDependentType()); is
> > failing in ASTContext.cpp.
> >
> > The print method returns for such a transformed ParmVarDecl:
> >
> > float data __attribute__((ext_vector_type(4)))
> >
> > which is also reflected in the AST dump:
> >
> > ParmVarDecl 0x2aa64f0 <line:2:5, col:11> col:11 data 'float
> > __attribute__((ext_vector_type(4)))'
> >
> > If I declare a float16 variable in the program that's parsed the original
> > type
> > name is preserved (float16):
> > 'float16':'float __attribute__((ext_vector_type(16)))'
> >
> > as you can see here:
> >
> > DeclStmt 0x2aa63e0 <line:4:5, col:26>
> > `-VarDecl 0x2aa6350 <col:5,
> > ../libclc/generic/include/clc/float/definitions.h:1:25>
> > demoMinReductionKernel.cl:4:13 agg 'float16':'float
> > __attribute__((ext_vector_type(16)))' cinit
> > `-ImplicitCastExpr 0x2aa63c8
> > <../libclc/generic/include/clc/float/definitions.h:1:25> 'float16':'float
> > __attribute__((ext_vector_type(16)))' <VectorSplat>
> > `-FloatingLiteral 0x2aa63a8 <col:25> 'float' 3.402823e+38
> >
> > Do you now if there is some sort of alias that needs to be modified or set
> > as
> > well?
> >
> > Best regards
> > Christoph
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list