Use arrays and SmallVectors instead of std::vectors when building function
types.  Also, cache a translation of 'void' in CGM and provide a ptrdiff_t
alias.  No functionality change.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131373 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
index c6bedd2..f11d528 100644
--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -245,7 +245,7 @@
 }
 
 static void initializeForBlockHeader(CodeGenModule &CGM, CGBlockInfo &info,
-                                std::vector<const llvm::Type*> &elementTypes) {
+                    llvm::SmallVectorImpl<const llvm::Type*> &elementTypes) {
   ASTContext &C = CGM.getContext();
 
   // The header is basically a 'struct { void *; int; int; void *; void *; }'.
@@ -282,7 +282,7 @@
   ASTContext &C = CGM.getContext();
   const BlockDecl *block = info.getBlockDecl();
 
-  std::vector<const llvm::Type*> elementTypes;
+  llvm::SmallVector<const llvm::Type*, 8> elementTypes;
   initializeForBlockHeader(CGM, info, elementTypes);
 
   if (!block->hasCaptures()) {
@@ -703,9 +703,8 @@
   BlockLiteral = Builder.CreateBitCast(BlockLiteral, VoidPtrTy, "tmp");
 
   // Add the block literal.
-  QualType VoidPtrTy = getContext().getPointerType(getContext().VoidTy);
   CallArgList Args;
-  Args.add(RValue::get(BlockLiteral), VoidPtrTy);
+  Args.add(RValue::get(BlockLiteral), getContext().VoidPtrTy);
 
   QualType FnType = BPT->getPointeeType();
 
@@ -1499,29 +1498,29 @@
   
   QualType Ty = D->getType();
 
-  std::vector<const llvm::Type *> Types;
+  llvm::SmallVector<const llvm::Type *, 8> types;
   
   llvm::PATypeHolder ByRefTypeHolder = llvm::OpaqueType::get(getLLVMContext());
   
   // void *__isa;
-  Types.push_back(Int8PtrTy);
+  types.push_back(Int8PtrTy);
   
   // void *__forwarding;
-  Types.push_back(llvm::PointerType::getUnqual(ByRefTypeHolder));
+  types.push_back(llvm::PointerType::getUnqual(ByRefTypeHolder));
   
   // int32_t __flags;
-  Types.push_back(Int32Ty);
+  types.push_back(Int32Ty);
     
   // int32_t __size;
-  Types.push_back(Int32Ty);
+  types.push_back(Int32Ty);
 
   bool HasCopyAndDispose = getContext().BlockRequiresCopying(Ty);
   if (HasCopyAndDispose) {
     /// void *__copy_helper;
-    Types.push_back(Int8PtrTy);
+    types.push_back(Int8PtrTy);
     
     /// void *__destroy_helper;
-    Types.push_back(Int8PtrTy);
+    types.push_back(Int8PtrTy);
   }
 
   bool Packed = false;
@@ -1544,11 +1543,11 @@
     if (NumPaddingBytes > 0) {
       const llvm::Type *Ty = llvm::Type::getInt8Ty(getLLVMContext());
       // FIXME: We need a sema error for alignment larger than the minimum of
-      // the maximal stack alignmint and the alignment of malloc on the system.
+      // the maximal stack alignment and the alignment of malloc on the system.
       if (NumPaddingBytes > 1)
         Ty = llvm::ArrayType::get(Ty, NumPaddingBytes);
     
-      Types.push_back(Ty);
+      types.push_back(Ty);
 
       // We want a packed struct.
       Packed = true;
@@ -1556,9 +1555,9 @@
   }
 
   // T x;
-  Types.push_back(ConvertTypeForMem(Ty));
+  types.push_back(ConvertTypeForMem(Ty));
   
-  const llvm::Type *T = llvm::StructType::get(getLLVMContext(), Types, Packed);
+  const llvm::Type *T = llvm::StructType::get(getLLVMContext(), types, Packed);
   
   cast<llvm::OpaqueType>(ByRefTypeHolder.get())->refineAbstractTypeTo(T);
   CGM.getModule().addTypeName("struct.__block_byref_" + D->getNameAsString(), 
@@ -1566,7 +1565,7 @@
   
   Info.first = ByRefTypeHolder.get();
   
-  Info.second = Types.size() - 1;
+  Info.second = types.size() - 1;
   
   return Info.first;
 }