Complete __Block_byref_id_object_copy cogegen for block literals.

llvm-svn: 66257
This commit is contained in:
Mike Stump 2009-03-06 06:12:24 +00:00
parent c8e5085cd3
commit f89230d93b
3 changed files with 55 additions and 10 deletions

View File

@ -755,15 +755,21 @@ llvm::Constant *BlockFunction::BuildDestroyHelper() {
return CodeGenFunction(CGM).GenerateDestroyHelperFunction();
}
llvm::Constant *BlockFunction::GeneratebyrefCopyHelperFunction() {
llvm::Constant *BlockFunction::
GeneratebyrefCopyHelperFunction(const llvm::Type *T, int flag) {
QualType R = getContext().VoidTy;
FunctionArgList Args;
// FIXME: This leaks
ImplicitParamDecl *Dst =
ImplicitParamDecl::Create(getContext(), 0, SourceLocation(), 0,
getContext().getPointerType(getContext().VoidTy));
Args.push_back(std::make_pair(Dst, Dst->getType()));
// FIXME: This leaks
ImplicitParamDecl *Src =
ImplicitParamDecl::Create(getContext(), 0, SourceLocation(), 0,
getContext().getPointerType(getContext().VoidTy));
Args.push_back(std::make_pair(Src, Src->getType()));
const CGFunctionInfo &FI =
@ -787,7 +793,27 @@ llvm::Constant *BlockFunction::GeneratebyrefCopyHelperFunction() {
FunctionDecl::Static, false,
true);
CGF.StartFunction(FD, R, Fn, Args, SourceLocation());
// EmitStmt(BExpr->getBody());
// dst->x
llvm::Value *V = CGF.GetAddrOfLocalVar(Dst);
V = Builder.CreateBitCast(V, T);
V = Builder.CreateStructGEP(V, 6, "x");
llvm::Value *DstObj = Builder.CreateBitCast(V, PtrToInt8Ty);
// src->x
V = CGF.GetAddrOfLocalVar(Src);
V = Builder.CreateLoad(V);
V = Builder.CreateBitCast(V, T);
V = Builder.CreateStructGEP(V, 6, "x");
V = Builder.CreateBitCast(V, llvm::PointerType::get(PtrToInt8Ty, 0));
llvm::Value *SrcObj = Builder.CreateLoad(V);
flag |= BLOCK_BYREF_CALLER;
llvm::Value *N = llvm::ConstantInt::get(llvm::Type::Int32Ty, flag);
llvm::Value *F = getBlockObjectAssign();
Builder.CreateCall3(F, DstObj, SrcObj, N);
CGF.FinishFunction();
return llvm::ConstantExpr::getBitCast(Fn, PtrToInt8Ty);
@ -845,8 +871,9 @@ BlockFunction::GeneratebyrefDestroyHelperFunction(const llvm::Type *T,
return llvm::ConstantExpr::getBitCast(Fn, PtrToInt8Ty);
}
llvm::Constant *BlockFunction::BuildbyrefCopyHelper(int flag) {
return CodeGenFunction(CGM).GeneratebyrefCopyHelperFunction();
llvm::Constant *BlockFunction::BuildbyrefCopyHelper(const llvm::Type *T,
int flag) {
return CodeGenFunction(CGM).GeneratebyrefCopyHelperFunction(T, flag);
}
llvm::Constant *BlockFunction::BuildbyrefDestroyHelper(const llvm::Type *T,
@ -868,6 +895,21 @@ llvm::Value *BlockFunction::getBlockObjectDispose() {
return CGM.BlockObjectDispose;
}
llvm::Value *BlockFunction::getBlockObjectAssign() {
if (CGM.BlockObjectAssign == 0) {
const llvm::FunctionType *FTy;
std::vector<const llvm::Type*> ArgTys;
const llvm::Type *ResultType = llvm::Type::VoidTy;
ArgTys.push_back(PtrToInt8Ty);
ArgTys.push_back(PtrToInt8Ty);
ArgTys.push_back(llvm::Type::Int32Ty);
FTy = llvm::FunctionType::get(ResultType, ArgTys, false);
CGM.BlockObjectAssign
= CGM.CreateRuntimeFunction(FTy, "_Block_object_assign");
}
return CGM.BlockObjectAssign;
}
void BlockFunction::BuildBlockRelease(llvm::Value *V, int flag) {
llvm::Value *F = getBlockObjectDispose();
llvm::Value *N;

View File

@ -94,6 +94,7 @@ public:
int GlobalUniqueCount;
} Block;
llvm::Value *BlockObjectAssign;
llvm::Value *BlockObjectDispose;
const llvm::Type *PtrToInt8Ty;
@ -102,7 +103,7 @@ public:
: Context(C), TheModule(M), TheTargetData(TD), Types(T),
CGM(CodeGen),
NSConcreteGlobalBlock(0), NSConcreteStackBlock(0), BlockDescriptorType(0),
GenericBlockLiteralType(0), BlockObjectDispose(0) {
GenericBlockLiteralType(0), BlockObjectAssign(0), BlockObjectDispose(0) {
Block.GlobalUniqueCount = 0;
PtrToInt8Ty = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
}
@ -163,12 +164,13 @@ public:
llvm::Constant *BuildCopyHelper();
llvm::Constant *BuildDestroyHelper();
llvm::Constant *GeneratebyrefCopyHelperFunction();
llvm::Constant *GeneratebyrefCopyHelperFunction(const llvm::Type *, int flag);
llvm::Constant *GeneratebyrefDestroyHelperFunction(const llvm::Type *T, int);
llvm::Constant *BuildbyrefCopyHelper(int flag);
llvm::Constant *BuildbyrefDestroyHelper(const llvm::Type*, int flag);
llvm::Constant *BuildbyrefCopyHelper(const llvm::Type *T, int flag);
llvm::Constant *BuildbyrefDestroyHelper(const llvm::Type *T, int flag);
llvm::Value *getBlockObjectAssign();
llvm::Value *getBlockObjectDispose();
void BuildBlockRelease(llvm::Value *DeclPtr, int flag = BLOCK_FIELD_IS_BYREF);

View File

@ -373,7 +373,8 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
if (flags & BLOCK_HAS_COPY_DISPOSE) {
BlockHasCopyDispose = true;
llvm::Value *copy_helper = Builder.CreateStructGEP(DeclPtr, 4);
Builder.CreateStore(BuildbyrefCopyHelper(flag), copy_helper);
Builder.CreateStore(BuildbyrefCopyHelper(DeclPtr->getType(), flag),
copy_helper);
llvm::Value *destroy_helper = Builder.CreateStructGEP(DeclPtr, 5);
Builder.CreateStore(BuildbyrefDestroyHelper(DeclPtr->getType(), flag),