[cfe-commits] r47336 - in /cfe/trunk: CodeGen/CGExprAgg.cpp test/CodeGen/init.c
Lauro Ramos Venancio
lauro.venancio at gmail.com
Tue Feb 19 11:27:32 PST 2008
Author: laurov
Date: Tue Feb 19 13:27:31 2008
New Revision: 47336
URL: http://llvm.org/viewvc/llvm-project?rev=47336&view=rev
Log:
Simplify aggregate initilizer implementation. Use the CodeGenModule::EmitConstantExpr method when
possible.
Fix mediabench/mpeg2/mpeg2dec test.
Modified:
cfe/trunk/CodeGen/CGExprAgg.cpp
cfe/trunk/test/CodeGen/init.c
Modified: cfe/trunk/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprAgg.cpp?rev=47336&r1=47335&r2=47336&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/CodeGen/CGExprAgg.cpp Tue Feb 19 13:27:31 2008
@@ -85,8 +85,6 @@
private:
- llvm::Constant *GetConstantInit(InitListExpr *E,
- const llvm::ArrayType *AType);
void EmitNonConstInit(Expr *E, llvm::Value *Dest, const llvm::Type *DestType);
};
} // end anonymous namespace.
@@ -236,35 +234,6 @@
CGF.EmitBlock(ContBlock);
}
-llvm::Constant *AggExprEmitter::GetConstantInit(InitListExpr *E,
- const llvm::ArrayType *AType) {
- std::vector<llvm::Constant*> ArrayElts;
- unsigned NumInitElements = E->getNumInits();
- const llvm::Type *ElementType = AType->getElementType();
- unsigned i;
-
- for (i = 0; i != NumInitElements; ++i) {
- if (InitListExpr *InitList = dyn_cast<InitListExpr>(E->getInit(i))) {
- assert(isa<llvm::ArrayType>(ElementType) && "Invalid initilizer");
- llvm::Constant *C =
- GetConstantInit(InitList, cast<llvm::ArrayType>(ElementType));
- if (!C) return NULL;
- ArrayElts.push_back(C);
- } else if (llvm::Constant *C =
- dyn_cast<llvm::Constant>(CGF.EmitScalarExpr(E->getInit(i))))
- ArrayElts.push_back(C);
- else
- return NULL;
- }
-
- // Remaining default initializers
- unsigned NumArrayElements = AType->getNumElements();
- for (/*Do not initialize i*/; i < NumArrayElements; ++i)
- ArrayElts.push_back(llvm::Constant::getNullValue(ElementType));
-
- return llvm::ConstantArray::get(AType, ArrayElts);
-}
-
void AggExprEmitter::EmitNonConstInit(Expr *E, llvm::Value *DestPtr,
const llvm::Type *DestType) {
@@ -309,17 +278,8 @@
void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
- if (!E->getType()->isArrayType()) {
- CGF.WarnUnsupported(E, "aggregate init-list expression");
- return;
- }
-
- const llvm::PointerType *APType = cast<llvm::PointerType>(DestPtr->getType());
- const llvm::ArrayType *AType =
- cast<llvm::ArrayType>(APType->getElementType());
-
- llvm::Constant *V = GetConstantInit(E, AType);
- if (V) {
+ if (E->isConstantExpr(CGF.CGM.getContext(), NULL)) {
+ llvm::Constant *V = CGF.CGM.EmitConstantExpr(E);
// Create global value to hold this array.
V = new llvm::GlobalVariable(V->getType(), true,
llvm::GlobalValue::InternalLinkage,
@@ -328,8 +288,19 @@
EmitAggregateCopy(DestPtr, V , E->getType());
return;
- } else
+ } else {
+ if (!E->getType()->isArrayType()) {
+ CGF.WarnUnsupported(E, "aggregate init-list expression");
+ return;
+ }
+
+ const llvm::PointerType *APType =
+ cast<llvm::PointerType>(DestPtr->getType());
+ const llvm::ArrayType *AType =
+ cast<llvm::ArrayType>(APType->getElementType());
+
EmitNonConstInit(E, DestPtr, AType);
+ }
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/test/CodeGen/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/init.c?rev=47336&r1=47335&r2=47336&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/init.c (original)
+++ cfe/trunk/test/CodeGen/init.c Tue Feb 19 13:27:31 2008
@@ -11,4 +11,5 @@
int *c[2] = { &a[1][1], &b[2][2] };
int *d[2][2] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} };
int *e[3][3] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} };
+ char ext[3][3] = {".Y",".U",".V"};
}
More information about the cfe-commits
mailing list