[cfe-commits] r74299 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/ext_vector_components.c
Nate Begeman
natebegeman at mac.com
Fri Jun 26 11:22:18 PDT 2009
Author: sampo
Date: Fri Jun 26 13:22:18 2009
New Revision: 74299
URL: http://llvm.org/viewvc/llvm-project?rev=74299&view=rev
Log:
OpenCL 1.0 Support:
Add support for scalar to vector and partially initialized vector constant initializers.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/ext_vector_components.c
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=74299&r1=74298&r2=74299&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Jun 26 13:22:18 2009
@@ -486,12 +486,28 @@
APValue VectorExprEvaluator::VisitCastExpr(const CastExpr* E) {
const Expr* SE = E->getSubExpr();
+ QualType SETy = SE->getType();
+ APValue Result = APValue();
- // Check for vector->vector bitcast.
- if (SE->getType()->isVectorType())
+ // Check for vector->vector bitcast and scalar->vector splat.
+ if (SETy->isVectorType()) {
return this->Visit(const_cast<Expr*>(SE));
+ } else if (SETy->isIntegerType()) {
+ APSInt IntResult;
+ if (EvaluateInteger(SE, IntResult, Info))
+ Result = APValue(IntResult);
+ } else if (SETy->isRealFloatingType()) {
+ APFloat F(0.0);
+ if (EvaluateFloat(SE, F, Info))
+ Result = APValue(F);
+ }
- return APValue();
+ if (Result.isInt() || Result.isFloat()) {
+ unsigned NumElts = E->getType()->getAsVectorType()->getNumElements();
+ llvm::SmallVector<APValue, 4> Elts(NumElts, Result);
+ Result = APValue(&Elts[0], Elts.size());
+ }
+ return Result;
}
APValue
Modified: cfe/trunk/test/Sema/ext_vector_components.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ext_vector_components.c?rev=74299&r1=74298&r2=74299&view=diff
==============================================================================
--- cfe/trunk/test/Sema/ext_vector_components.c (original)
+++ cfe/trunk/test/Sema/ext_vector_components.c Fri Jun 26 13:22:18 2009
@@ -5,6 +5,8 @@
typedef __attribute__(( ext_vector_type(4) )) float float4;
typedef __attribute__(( ext_vector_type(16) )) float float16;
+static float4 vec4_0 = (float4)0.5f;
+
static void test() {
float2 vec2, vec2_2;
float3 vec3;
More information about the cfe-commits
mailing list