]> granicus.if.org Git - clang/commitdiff
Support checking and codegen of constant vector globals
authorNate Begeman <natebegeman@mac.com>
Fri, 25 Jan 2008 05:34:48 +0000 (05:34 +0000)
committerNate Begeman <natebegeman@mac.com>
Fri, 25 Jan 2008 05:34:48 +0000 (05:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46343 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
CodeGen/CodeGenModule.cpp
test/CodeGen/ocu-vector.c
test/Sema/vector-init.c [new file with mode: 0644]

index 8aa5eed80b4e2b1f4f12b95424607bc9becc891a..becce2a6222ace4f95e87a29d1d1fdfd58e223ad 100644 (file)
@@ -487,7 +487,8 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
   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);
     
index bb61dc7cd8253e9c8b7cf46b3bf4fd85c6430211..e841ee54926774406c191ea634bf91a5a91332a9 100644 (file)
@@ -300,7 +300,8 @@ static llvm::Constant *GenerateAggregateInit(const InitListExpr *ILE,
     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 @@ static llvm::Constant *GenerateAggregateInit(const InitListExpr *ILE,
   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 @@ static llvm::Constant *GenerateConstantExpr(const Expr *Expression,
     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);
index ee6e737a5853eca52a0b4ed840331c848bfab0d6..cffef339ee3347eb78e6e4f2791fe2405c2750f7 100644 (file)
@@ -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;
diff --git a/test/Sema/vector-init.c b/test/Sema/vector-init.c
new file mode 100644 (file)
index 0000000..5436cba
--- /dev/null
@@ -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 };