aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGBlocks.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/CGBlocks.cpp')
-rw-r--r--lib/CodeGen/CGBlocks.cpp48
1 files changed, 22 insertions, 26 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
index 76a68b1526..fb90e025eb 100644
--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -481,8 +481,8 @@ static void computeBlockInfo(CodeGenModule &CGM, CGBlockInfo &info) {
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::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) {
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 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) {
// 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 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) {
// 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 *CodeGenModule::getGenericBlockLiteralType() {
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 @@ const llvm::Type *CodeGenModule::getGenericBlockLiteralType() {
// 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 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E,
// 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::Value *CodeGenFunction::GetAddrOfBlockDecl(const VarDecl *variable,
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 @@ CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *blockExpr,
blockInfo,
0, LocalDeclMap);
}
- blockFn = llvm::ConstantExpr::getBitCast(blockFn, Int8PtrTy);
+ blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy);
return buildGlobalBlock(*this, blockInfo, blockFn);
}
@@ -860,11 +857,10 @@ static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM,
// __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 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) {
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 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) {
FinishFunction();
- return llvm::ConstantExpr::getBitCast(Fn, Int8PtrTy);
+ return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
}
llvm::Constant *
@@ -1246,7 +1242,7 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) {
// 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 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) {
FinishFunction();
- return llvm::ConstantExpr::getBitCast(Fn, Int8PtrTy);
+ return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
}
llvm::Constant *CodeGenFunction::
@@ -1318,8 +1314,8 @@ GeneratebyrefCopyHelperFunction(const llvm::Type *T, BlockFieldFlags flags,
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());