Support checking and codegen of constant vector globals

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46343 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nate Begeman 2008-01-25 05:34:48 +00:00
Родитель a99603333f
Коммит d47d4f518e
4 изменённых файлов: 19 добавлений и 2 удалений

Просмотреть файл

@ -487,7 +487,8 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
case CompoundLiteralExprClass: case CompoundLiteralExprClass:
if (Loc) *Loc = getLocStart(); if (Loc) *Loc = getLocStart();
// Allow "(int []){2,4}", since the array will be converted to a pointer. // 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: { case UnaryOperatorClass: {
const UnaryOperator *Exp = cast<UnaryOperator>(this); const UnaryOperator *Exp = cast<UnaryOperator>(this);

Просмотреть файл

@ -300,7 +300,8 @@ static llvm::Constant *GenerateAggregateInit(const InitListExpr *ILE,
return 0; return 0;
} }
assert((ILE->getType()->isArrayType() || ILE->getType()->isStructureType()) && assert((ILE->getType()->isArrayType() || ILE->getType()->isStructureType() ||
ILE->getType()->isVectorType()) &&
"Bad type for init list!"); "Bad type for init list!");
CodeGenTypes& Types = CGM.getTypes(); CodeGenTypes& Types = CGM.getTypes();
@ -342,6 +343,9 @@ static llvm::Constant *GenerateAggregateInit(const InitListExpr *ILE,
if (ILE->getType()->isStructureType()) if (ILE->getType()->isStructureType())
return llvm::ConstantStruct::get(cast<llvm::StructType>(CType), Elts); 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 // Make sure we have an array at this point
assert(AType); assert(AType);
@ -417,6 +421,12 @@ static llvm::Constant *GenerateConstantExpr(const Expr *Expression,
return llvm::ConstantArray::get(Str, false); 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. // Elide parenthesis.
case Stmt::ParenExprClass: case Stmt::ParenExprClass:
return GenerateConstantExpr(cast<ParenExpr>(Expression)->getSubExpr(), CGM); return GenerateConstantExpr(cast<ParenExpr>(Expression)->getSubExpr(), CGM);

Просмотреть файл

@ -3,6 +3,7 @@
typedef __attribute__(( ocu_vector_type(4) )) float float4; typedef __attribute__(( ocu_vector_type(4) )) float float4;
typedef __attribute__(( ocu_vector_type(2) )) float float2; typedef __attribute__(( ocu_vector_type(2) )) float float2;
float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
float4 test1(float4 V) { float4 test1(float4 V) {
return V.wzyx+V; return V.wzyx+V;

5
test/Sema/vector-init.c Normal file
Просмотреть файл

@ -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 };