Assorted cleanup:
  - Have CGM precompute a number of commonly-used types
  - Have CGF copy that during initialization instead of recomputing them
  - Use TBAA info when initializing a parameter variable
  - Refactor the scalar ++/-- code



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125562 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
index 76a68b1..fb90e02 100644
--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -481,8 +481,8 @@
   if (endAlign < maxFieldAlign) {
     CharUnits padding = maxFieldAlign - endAlign;
 
-    const llvm::Type *i8 = llvm::IntegerType::get(CGM.getLLVMContext(), 8);
-    elementTypes.push_back(llvm::ArrayType::get(i8, padding.getQuantity()));
+    elementTypes.push_back(llvm::ArrayType::get(CGM.Int8Ty,
+                                                padding.getQuantity()));
     blockSize += padding;
 
     endAlign = getLowBit(blockSize);
@@ -517,7 +517,7 @@
   llvm::Constant *blockFn
     = CodeGenFunction(CGM).GenerateBlockFunction(CurGD, blockInfo,
                                                  CurFuncDecl, LocalDeclMap);
-  blockFn = llvm::ConstantExpr::getBitCast(blockFn, Int8PtrTy);
+  blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy);
 
   // If there is nothing to capture, we can emit this as a global block.
   if (blockInfo.CanBeGlobal)
@@ -526,7 +526,7 @@
   // Otherwise, we have to emit this as a local block.
 
   llvm::Constant *isa = CGM.getNSConcreteStackBlock();
-  isa = llvm::ConstantExpr::getBitCast(isa, Int8PtrTy);
+  isa = llvm::ConstantExpr::getBitCast(isa, VoidPtrTy);
 
   // Build the block descriptor.
   llvm::Constant *descriptor = buildBlockDescriptor(CGM, blockInfo);
@@ -604,13 +604,13 @@
     // pointer at this point, since we're building something that will
     // live a shorter life than the stack byref anyway.
     if (ci->isByRef()) {
-      // Get an i8* that points to the byref struct.
+      // Get a void* that points to the byref struct.
       if (ci->isNested())
         src = Builder.CreateLoad(src, "byref.capture");
       else
-        src = Builder.CreateBitCast(src, Int8PtrTy);
+        src = Builder.CreateBitCast(src, VoidPtrTy);
 
-      // Write that i8* into the capture field.
+      // Write that void* into the capture field.
       Builder.CreateStore(src, blockField);
 
     // If we have a copy constructor, evaluate that into the block field.
@@ -710,9 +710,6 @@
 
   const llvm::Type *BlockDescPtrTy = getBlockDescriptorType();
 
-  const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(
-    getTypes().ConvertType(getContext().IntTy));
-
   // struct __block_literal_generic {
   //   void *__isa;
   //   int __flags;
@@ -720,11 +717,11 @@
   //   void (*__invoke)(void *);
   //   struct __block_descriptor *__descriptor;
   // };
-  GenericBlockLiteralType = llvm::StructType::get(IntTy->getContext(),
-                                                  Int8PtrTy,
+  GenericBlockLiteralType = llvm::StructType::get(getLLVMContext(),
+                                                  VoidPtrTy,
                                                   IntTy,
                                                   IntTy,
-                                                  Int8PtrTy,
+                                                  VoidPtrTy,
                                                   BlockDescPtrTy,
                                                   NULL);
 
@@ -753,7 +750,7 @@
   // Get the function pointer from the literal.
   llvm::Value *FuncPtr = Builder.CreateStructGEP(BlockLiteral, 3, "tmp");
 
-  BlockLiteral = Builder.CreateBitCast(BlockLiteral, Int8PtrTy, "tmp");
+  BlockLiteral = Builder.CreateBitCast(BlockLiteral, VoidPtrTy, "tmp");
 
   // Add the block literal.
   QualType VoidPtrTy = getContext().getPointerType(getContext().VoidTy);
@@ -827,7 +824,7 @@
 
 llvm::Constant *
 CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *blockExpr,
-                                  const char *name) {
+                                    const char *name) {
   CGBlockInfo blockInfo(blockExpr, name);
 
   // Compute information about the layout, etc., of this block.
@@ -841,7 +838,7 @@
                                                            blockInfo,
                                                            0, LocalDeclMap);
   }
-  blockFn = llvm::ConstantExpr::getBitCast(blockFn, Int8PtrTy);
+  blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy);
 
   return buildGlobalBlock(*this, blockInfo, blockFn);
 }
@@ -860,11 +857,10 @@
   // __flags
   BlockFlags flags = computeBlockFlag(CGM, blockInfo.getBlockExpr(),
                                       BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE);
-  const llvm::Type *intTy = CGM.getTypes().ConvertType(CGM.getContext().IntTy);
-  fields[1] = llvm::ConstantInt::get(intTy, flags.getBitMask());
+  fields[1] = llvm::ConstantInt::get(CGM.IntTy, flags.getBitMask());
 
   // Reserved
-  fields[2] = llvm::Constant::getNullValue(intTy);
+  fields[2] = llvm::Constant::getNullValue(CGM.IntTy);
 
   // Function
   fields[3] = blockFn;
@@ -1155,8 +1151,8 @@
       EmitSynthesizedCXXCopyCtor(dstField, srcField, copyExpr);
     } else {
       llvm::Value *srcValue = Builder.CreateLoad(srcField, "blockcopy.src");
-      srcValue = Builder.CreateBitCast(srcValue, Int8PtrTy);
-      llvm::Value *dstAddr = Builder.CreateBitCast(dstField, Int8PtrTy);
+      srcValue = Builder.CreateBitCast(srcValue, VoidPtrTy);
+      llvm::Value *dstAddr = Builder.CreateBitCast(dstField, VoidPtrTy);
       Builder.CreateCall3(CGM.getBlockObjectAssign(), dstAddr, srcValue,
                           llvm::ConstantInt::get(Int32Ty, flags));
     }
@@ -1164,7 +1160,7 @@
 
   FinishFunction();
 
-  return llvm::ConstantExpr::getBitCast(Fn, Int8PtrTy);
+  return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
 }
 
 llvm::Constant *
@@ -1246,7 +1242,7 @@
     // that things were done in reverse.
     } else {
       llvm::Value *value = Builder.CreateLoad(srcField);
-      value = Builder.CreateBitCast(value, Int8PtrTy);
+      value = Builder.CreateBitCast(value, VoidPtrTy);
       BuildBlockRelease(value, flags);
     }
   }
@@ -1255,7 +1251,7 @@
 
   FinishFunction();
 
-  return llvm::ConstantExpr::getBitCast(Fn, Int8PtrTy);
+  return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
 }
 
 llvm::Constant *CodeGenFunction::
@@ -1318,8 +1314,8 @@
     llvm::Value *SrcObj = V;
     EmitSynthesizedCXXCopyCtor(DstObj, SrcObj, copyExpr);
   } else {
-    DstObj = Builder.CreateBitCast(DstObj, Int8PtrTy);
-    V = Builder.CreateBitCast(V, llvm::PointerType::get(Int8PtrTy, 0));
+    DstObj = Builder.CreateBitCast(DstObj, VoidPtrTy);
+    V = Builder.CreateBitCast(V, VoidPtrPtrTy);
     llvm::Value *SrcObj = Builder.CreateLoad(V);
     flags |= BLOCK_BYREF_CALLER;
     llvm::Value *N = llvm::ConstantInt::get(Int32Ty, flags.getBitMask());