From 2715b207a6a22970441da162313e1729d54dc24e Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 15 Nov 2010 19:19:38 +0000 Subject: [PATCH] Some cleanup of block API code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119174 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGBlocks.cpp | 34 +++++++++++++++------------------- lib/CodeGen/CGBlocks.h | 8 ++++---- lib/CodeGen/CGDecl.cpp | 2 +- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index a6929649ef..2206e8a1cd 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -39,7 +39,6 @@ BuildDescriptorBlockDecl(const BlockExpr *BE, const CGBlockInfo &Info, const llvm::StructType* Ty, llvm::Constant *BlockVarLayout, std::vector *NoteForHelper) { - bool BlockHasCopyDispose = Info.BlockHasCopyDispose; CharUnits Size = Info.BlockSize; const llvm::Type *UnsignedLongTy = CGM.getTypes().ConvertType(getContext().UnsignedLongTy); @@ -58,7 +57,7 @@ BuildDescriptorBlockDecl(const BlockExpr *BE, const CGBlockInfo &Info, Elts.push_back(C); // optional copy/dispose helpers - if (BlockHasCopyDispose) { + if (Info.BlockHasCopyDispose) { // copy_func_helper_decl Elts.push_back(BuildCopyHelper(Ty, NoteForHelper)); @@ -218,7 +217,7 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) { = CodeGenFunction(CGM).GenerateBlockFunction(CurGD, BE, Info, CurFuncDecl, BlockVarLayout, LocalDeclMap); - BlockHasCopyDispose |= Info.BlockHasCopyDispose; + SynthesizeCopyDisposeHelpers |= Info.BlockHasCopyDispose; Elts[3] = Fn; // FIXME: Don't use BlockHasCopyDispose, it is set more often then @@ -569,10 +568,9 @@ void CodeGenFunction::AllocateBlockDecl(const BlockDeclRefExpr *E) { return; // Don't run the expensive check, unless we have to. - if (!BlockHasCopyDispose) - if (E->isByRef() - || BlockRequiresCopying(E)) - BlockHasCopyDispose = true; + if (!SynthesizeCopyDisposeHelpers) + if (E->isByRef() || BlockRequiresCopying(E)) + SynthesizeCopyDisposeHelpers = true; const ValueDecl *D = cast(E->getDecl()); @@ -605,7 +603,7 @@ llvm::Value *CodeGenFunction::GetAddrOfBlockDecl(const ValueDecl *VD, const llvm::Type *PtrStructTy = llvm::PointerType::get(BuildByRefType(VD), 0); // The block literal will need a copy/destroy helper. - BlockHasCopyDispose = true; + SynthesizeCopyDisposeHelpers = true; const llvm::Type *Ty = PtrStructTy; Ty = llvm::PointerType::get(Ty, 0); @@ -776,8 +774,9 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, const BlockExpr *BExpr, else BlockVarLayout = llvm::Constant::getNullValue(PtrToInt8Ty); - QualType ParmTy = getContext().getBlockParmType(BlockHasCopyDispose, - BlockLayout); + QualType ParmTy = getContext().getBlockParmType( + SynthesizeCopyDisposeHelpers, + BlockLayout); // FIXME: This leaks ImplicitParamDecl *SelfDecl = @@ -907,7 +906,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, const BlockExpr *BExpr, Info.BlockSize = BlockOffset; Info.BlockAlign = BlockAlign; Info.BlockLayout = BlockLayout; - Info.BlockHasCopyDispose = BlockHasCopyDispose; + Info.BlockHasCopyDispose = SynthesizeCopyDisposeHelpers; return Fn; } @@ -942,7 +941,7 @@ CharUnits BlockFunction::getBlockOffset(CharUnits Size, CharUnits Align) { } llvm::Constant *BlockFunction:: -GenerateCopyHelperFunction(bool BlockHasCopyDispose, const llvm::StructType *T, +GenerateCopyHelperFunction(const llvm::StructType *T, std::vector *NoteForHelperp) { QualType R = getContext().VoidTy; @@ -1031,8 +1030,7 @@ GenerateCopyHelperFunction(bool BlockHasCopyDispose, const llvm::StructType *T, } llvm::Constant *BlockFunction:: -GenerateDestroyHelperFunction(bool BlockHasCopyDispose, - const llvm::StructType* T, +GenerateDestroyHelperFunction(const llvm::StructType* T, std::vector *NoteForHelperp) { QualType R = getContext().VoidTy; @@ -1112,14 +1110,12 @@ GenerateDestroyHelperFunction(bool BlockHasCopyDispose, llvm::Constant *BlockFunction::BuildCopyHelper(const llvm::StructType *T, std::vector *NoteForHelper) { - return CodeGenFunction(CGM).GenerateCopyHelperFunction(BlockHasCopyDispose, - T, NoteForHelper); + return CodeGenFunction(CGM).GenerateCopyHelperFunction(T, NoteForHelper); } llvm::Constant *BlockFunction::BuildDestroyHelper(const llvm::StructType *T, std::vector *NoteForHelperp) { - return CodeGenFunction(CGM).GenerateDestroyHelperFunction(BlockHasCopyDispose, - T, NoteForHelperp); + return CodeGenFunction(CGM).GenerateDestroyHelperFunction(T, NoteForHelperp); } llvm::Constant *BlockFunction:: @@ -1293,5 +1289,5 @@ BlockFunction::BlockFunction(CodeGenModule &cgm, CodeGenFunction &cgf, PtrToInt8Ty = llvm::PointerType::getUnqual( llvm::Type::getInt8Ty(VMContext)); - BlockHasCopyDispose = false; + SynthesizeCopyDisposeHelpers = false; } diff --git a/lib/CodeGen/CGBlocks.h b/lib/CodeGen/CGBlocks.h index a5f2aa9e69..f82ce117b3 100644 --- a/lib/CodeGen/CGBlocks.h +++ b/lib/CodeGen/CGBlocks.h @@ -154,8 +154,8 @@ public: /// for a value with the given size and alignment requirements. CharUnits getBlockOffset(CharUnits Size, CharUnits Align); - /// BlockHasCopyDispose - True iff the block uses copy/dispose. - bool BlockHasCopyDispose; + /// SynthesizeCopyDisposeHelpers - True iff the block uses copy/dispose. + bool SynthesizeCopyDisposeHelpers; /// BlockLayout - The layout of the block's storage, represented as /// a sequence of expressions which require such storage. The @@ -179,9 +179,9 @@ public: ImplicitParamDecl *BlockStructDecl; ImplicitParamDecl *getBlockStructDecl() { return BlockStructDecl; } - llvm::Constant *GenerateCopyHelperFunction(bool, const llvm::StructType *, + llvm::Constant *GenerateCopyHelperFunction(const llvm::StructType *, std::vector *); - llvm::Constant *GenerateDestroyHelperFunction(bool, const llvm::StructType *, + llvm::Constant *GenerateDestroyHelperFunction(const llvm::StructType *, std::vector *); llvm::Constant *BuildCopyHelper(const llvm::StructType *, diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 02da0a533b..cb0b09da5c 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -687,7 +687,7 @@ void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D, Builder.CreateStore(V, size_field); if (flags & BLOCK_HAS_COPY_DISPOSE) { - BlockHasCopyDispose = true; + SynthesizeCopyDisposeHelpers = true; llvm::Value *copy_helper = Builder.CreateStructGEP(DeclPtr, 4); Builder.CreateStore(BuildbyrefCopyHelper(DeclPtr->getType(), flag, Align.getQuantity()), -- 2.40.0