[cfe-dev] [PATCH] Add __builtin_convertvector

Hal Finkel hfinkel at anl.gov
Fri Sep 13 11:19:05 PDT 2013


----- Original Message -----
> Hal
> 
> __builtin_astype is not a builtin that is recognized by the front-end
> -- at least Builtins.def does not define it. Is this because one
> expects to be able to use type cases for this?

There are two separate issues here.

 1. Like __builtin_astype, __builtin_convertvector needs to be defined as its own token because it needs special parser support (it takes a type name as a parameter).

 2. In the patch I actually do add __builtin_convertvector to Builtins.def; the only reason being that it allows __has_builtin to work as expected. If this approach flies, then I was planning to propose a patch to do the same with the other token builtins.

> Note that this does
> not work in OpenCL, where type casts between vector types are
> illegal. To implement OpenCL's astype functions, an explicit
> __builtin_astype (similar to __builtin_convervector) would be handy.

OpenCL has a bunch of convert_<type> functions for doing conversions. Some of them could be implemented in terms of __builtin_convertvector ;) -- nevertheless, __builtin_astype *is* an OpenCL feature, and I don't understand what you're trying to say.

Thanks again,
Hal

> 
> -erik
> 
> On 2013-09-13, at 9:16 , hfinkel at anl.gov wrote:
> 
> > Hi eli.friedman,
> > 
> > LLVM supports applying conversion instructions to vectors of the
> > same number of elements (fptrunc, fptosi, etc.) but currently
> > there is no way for a Clang user to cause such instructions to be
> > generated when using builtin vector types.
> > 
> > C-style casting on vectors is already defined in terms of bitcasts,
> > and so cannot be used for these conversions as well (without
> > leading to a very confusing set of semantics). As a result, I'd
> > like to add this new intrinsic (patterned after the OpenCL
> > __builtin_astype intrinsic). This will aid the creation of vector
> > intrinsic headers that create generic IR instead of
> > target-dependent intrinsics (in other words, this is a generic
> > _mm_cvtepi32_ps).
> > 
> > Please review.
> > 
> > http://llvm-reviews.chandlerc.com/D1677
> > 
> > Files:
> >  docs/LanguageExtensions.rst
> >  include/clang/AST/Expr.h
> >  include/clang/AST/RecursiveASTVisitor.h
> >  include/clang/Basic/Builtins.def
> >  include/clang/Basic/DiagnosticSemaKinds.td
> >  include/clang/Basic/StmtNodes.td
> >  include/clang/Basic/TokenKinds.def
> >  include/clang/Sema/Sema.h
> >  include/clang/Serialization/ASTBitCodes.h
> >  lib/AST/Expr.cpp
> >  lib/AST/ExprClassification.cpp
> >  lib/AST/ExprConstant.cpp
> >  lib/AST/ItaniumMangle.cpp
> >  lib/AST/StmtPrinter.cpp
> >  lib/AST/StmtProfile.cpp
> >  lib/CodeGen/CGExprScalar.cpp
> >  lib/Parse/ParseExpr.cpp
> >  lib/Sema/SemaExceptionSpec.cpp
> >  lib/Sema/SemaExpr.cpp
> >  lib/Sema/TreeTransform.h
> >  lib/Serialization/ASTReaderStmt.cpp
> >  lib/Serialization/ASTWriterStmt.cpp
> >  lib/StaticAnalyzer/Core/ExprEngine.cpp
> >  test/CodeGen/convertvector.c
> >  test/PCH/exprs.h
> >  test/Preprocessor/feature_tests.c
> >  test/Sema/convertvector.c
> >  tools/libclang/CXCursor.cpp
> >  tools/libclang/RecursiveASTVisitor.h
> > <D1677.1.patch>_______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 
> --
> Erik Schnetter <schnetter at gmail.com>
> http://www.perimeterinstitute.ca/personal/eschnetter/
> 
> My email is as private as my paper mail. I therefore support
> encrypting
> and signing email messages. Get my PGP key from http://pgp.mit.edu/.
> 
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory



More information about the cfe-dev mailing list