[cfe-commits] r79637 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/CodeGen/CGCXX.cpp

Fariborz Jahanian fjahanian at apple.com
Fri Aug 21 09:31:06 PDT 2009


Author: fjahanian
Date: Fri Aug 21 11:31:06 2009
New Revision: 79637

URL: http://llvm.org/viewvc/llvm-project?rev=79637&view=rev
Log:
Introduce getConstantArrayElementCount API and use it in
construction/destruction of array members.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/CodeGen/CGCXX.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=79637&r1=79636&r2=79637&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Aug 21 11:31:06 2009
@@ -805,6 +805,9 @@
   /// (which needn't actually be an array type).
   QualType getBaseElementType(QualType QT);
   
+  /// getConstantArrayElementCount - Returns number of constant array elements.
+  uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
+  
   /// getArrayDecayedType - Return the properly qualified result of decaying the
   /// specified array type to a pointer.  This operation is non-trivial when
   /// handling typedefs etc.  The canonical type of "T" must be an array type,

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=79637&r1=79636&r2=79637&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Aug 21 11:31:06 2009
@@ -2382,6 +2382,17 @@
   return ElemTy;
 }
 
+/// getConstantArrayElementCount - Returns number of constant array elements.
+uint64_t 
+ASTContext::getConstantArrayElementCount(const ConstantArrayType *CA)  const {
+  uint64_t ElementCount = 1;
+  do {
+    ElementCount *= CA->getSize().getZExtValue();
+    CA = dyn_cast<ConstantArrayType>(CA->getElementType());
+  } while (CA);
+  return ElementCount;
+}
+
 /// getFloatingRank - Return a relative rank for floating point types.
 /// This routine will assert if passed a built-in type that isn't a float.
 static FloatingRank getFloatingRank(QualType T) {

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=79637&r1=79636&r2=79637&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Aug 21 11:31:06 2009
@@ -346,10 +346,10 @@
   assert(CA && "Do we support VLA for construction ?");
   
   // Create a temporary for the loop index and initialize it with 0.
-  llvm::Value *IndexPtr = CreateTempAlloca(llvm::Type::getInt32Ty(VMContext),
+  llvm::Value *IndexPtr = CreateTempAlloca(llvm::Type::getInt64Ty(VMContext),
                                            "loop.index");
   llvm::Value* zeroConstant = 
-    llvm::Constant::getNullValue(llvm::Type::getInt32Ty(VMContext));
+    llvm::Constant::getNullValue(llvm::Type::getInt64Ty(VMContext));
   Builder.CreateStore(zeroConstant, IndexPtr, false);
   
   // Start the loop with a block that tests the condition.
@@ -364,7 +364,7 @@
   // otherwise, go to the block after the for-loop.
   uint64_t NumElements = CA->getSize().getZExtValue();
   llvm::Value * NumElementsPtr = 
-  llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), NumElements);
+  llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), NumElements);
   llvm::Value *Counter = Builder.CreateLoad(IndexPtr);
   llvm::Value *IsLess = Builder.CreateICmpULT(Counter, NumElementsPtr, 
                                               "isless");
@@ -378,15 +378,10 @@
   Counter = Builder.CreateLoad(IndexPtr);
   if (const ConstantArrayType *CAT = 
       dyn_cast<ConstantArrayType>(Array->getElementType())) {
-    uint32_t delta = 1;
-    const ConstantArrayType *CAW = CAT;
-    do {
-      delta *= CAW->getSize().getZExtValue();
-      CAW = dyn_cast<ConstantArrayType>(CAW->getElementType());
-    } while (CAW);
+    uint64_t delta = getContext().getConstantArrayElementCount(CAT);
     // Address = This + delta*Counter for current loop iteration.
     llvm::Value *DeltaPtr = 
-      llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), delta);
+      llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), delta);
     DeltaPtr = Builder.CreateMul(Counter, DeltaPtr, "mul");
     llvm::Value *Address = 
       Builder.CreateInBoundsGEP(This, DeltaPtr, "arrayidx");
@@ -422,12 +417,7 @@
   assert(CA && "Do we support VLA for destruction ?");
   llvm::Value *One = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), 
                                             1);
-  uint64_t ElementCount = 1;
-  const ConstantArrayType *CAW = CA;
-  do {
-    ElementCount *= CAW->getSize().getZExtValue();
-    CAW = dyn_cast<ConstantArrayType>(CAW->getElementType());
-  } while (CAW);
+  uint64_t ElementCount = getContext().getConstantArrayElementCount(CA);
   // Create a temporary for the loop index and initialize it with count of
   // array elements.
   llvm::Value *IndexPtr = CreateTempAlloca(llvm::Type::getInt64Ty(VMContext),





More information about the cfe-commits mailing list