[cfe-commits] r46343 - in /cfe/trunk: AST/Expr.cpp CodeGen/CodeGenModule.cpp test/CodeGen/ocu-vector.c test/Sema/vector-init.c
Nate Begeman
natebegeman at mac.com
Thu Jan 24 21:34:48 PST 2008
Author: sampo
Date: Thu Jan 24 23:34:48 2008
New Revision: 46343
URL: http://llvm.org/viewvc/llvm-project?rev=46343&view=rev
Log:
Support checking and codegen of constant vector globals
Added:
cfe/trunk/test/Sema/vector-init.c
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/ocu-vector.c
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=46343&r1=46342&r2=46343&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Thu Jan 24 23:34:48 2008
@@ -487,7 +487,8 @@
case CompoundLiteralExprClass:
if (Loc) *Loc = getLocStart();
// Allow "(int []){2,4}", since the array will be converted to a pointer.
- return TR->isArrayType();
+ // Allow "(vector type){2,4}" since the elements are all constant.
+ return TR->isArrayType() || TR->isVectorType();
case UnaryOperatorClass: {
const UnaryOperator *Exp = cast<UnaryOperator>(this);
Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=46343&r1=46342&r2=46343&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Thu Jan 24 23:34:48 2008
@@ -300,7 +300,8 @@
return 0;
}
- assert((ILE->getType()->isArrayType() || ILE->getType()->isStructureType()) &&
+ assert((ILE->getType()->isArrayType() || ILE->getType()->isStructureType() ||
+ ILE->getType()->isVectorType()) &&
"Bad type for init list!");
CodeGenTypes& Types = CGM.getTypes();
@@ -342,6 +343,9 @@
if (ILE->getType()->isStructureType())
return llvm::ConstantStruct::get(cast<llvm::StructType>(CType), Elts);
+ if (ILE->getType()->isVectorType())
+ return llvm::ConstantVector::get(cast<llvm::VectorType>(CType), Elts);
+
// Make sure we have an array at this point
assert(AType);
@@ -417,6 +421,12 @@
return llvm::ConstantArray::get(Str, false);
}
+ // Generate initializer for the CompoundLiteral
+ case Stmt::CompoundLiteralExprClass: {
+ const CompoundLiteralExpr *CLE = cast<CompoundLiteralExpr>(Expression);
+ return GenerateConstantExpr(CLE->getInitializer(), CGM);
+ }
+
// Elide parenthesis.
case Stmt::ParenExprClass:
return GenerateConstantExpr(cast<ParenExpr>(Expression)->getSubExpr(), CGM);
Modified: cfe/trunk/test/CodeGen/ocu-vector.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ocu-vector.c?rev=46343&r1=46342&r2=46343&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/ocu-vector.c (original)
+++ cfe/trunk/test/CodeGen/ocu-vector.c Thu Jan 24 23:34:48 2008
@@ -3,6 +3,7 @@
typedef __attribute__(( ocu_vector_type(4) )) float float4;
typedef __attribute__(( ocu_vector_type(2) )) float float2;
+float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
float4 test1(float4 V) {
return V.wzyx+V;
Added: cfe/trunk/test/Sema/vector-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vector-init.c?rev=46343&view=auto
==============================================================================
--- cfe/trunk/test/Sema/vector-init.c (added)
+++ cfe/trunk/test/Sema/vector-init.c Thu Jan 24 23:34:48 2008
@@ -0,0 +1,5 @@
+// RUN: clang %s -verify -fsyntax-only
+
+typedef __attribute__(( ocu_vector_type(4) )) float float4;
+
+float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
More information about the cfe-commits
mailing list