]> granicus.if.org Git - clang/commitdiff
Some cleanup of block API code.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 15 Nov 2010 19:19:38 +0000 (19:19 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 15 Nov 2010 19:19:38 +0000 (19:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119174 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CGBlocks.h
lib/CodeGen/CGDecl.cpp

index a6929649efa1a1ae6541fca871d840be0bf02bb9..2206e8a1cd7bc7164be370ca5a0e28e46b88eb22 100644 (file)
@@ -39,7 +39,6 @@ BuildDescriptorBlockDecl(const BlockExpr *BE, const CGBlockInfo &Info,
                          const llvm::StructType* Ty,
                          llvm::Constant *BlockVarLayout,
                          std::vector<HelperInfo> *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<ValueDecl>(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<HelperInfo> *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<HelperInfo> *NoteForHelperp) {
   QualType R = getContext().VoidTy;
 
@@ -1112,14 +1110,12 @@ GenerateDestroyHelperFunction(bool BlockHasCopyDispose,
 
 llvm::Constant *BlockFunction::BuildCopyHelper(const llvm::StructType *T,
                                        std::vector<HelperInfo> *NoteForHelper) {
-  return CodeGenFunction(CGM).GenerateCopyHelperFunction(BlockHasCopyDispose,
-                                                         T, NoteForHelper);
+  return CodeGenFunction(CGM).GenerateCopyHelperFunction(T, NoteForHelper);
 }
 
 llvm::Constant *BlockFunction::BuildDestroyHelper(const llvm::StructType *T,
                                       std::vector<HelperInfo> *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;
 }
index a5f2aa9e69c303ce78e1f5338d107dbdf9af9005..f82ce117b349e83fc795f56195c19c2a8c851d68 100644 (file)
@@ -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<HelperInfo> *);
-  llvm::Constant *GenerateDestroyHelperFunction(bool, const llvm::StructType *,
+  llvm::Constant *GenerateDestroyHelperFunction(const llvm::StructType *,
                                                 std::vector<HelperInfo> *);
 
   llvm::Constant *BuildCopyHelper(const llvm::StructType *,
index 02da0a533b8e897fa2fd808e084007c5b4630e29..cb0b09da5c672ffb2912d681731dcba1aaa5707b 100644 (file)
@@ -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()),