[cfe-commits] r66247 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp lib/CodeGen/CGBlocks.h lib/CodeGen/CGDecl.cpp test/CodeGen/blocks-1.c

Mike Stump mrs at apple.com
Thu Mar 5 20:53:30 PST 2009


Author: mrs
Date: Thu Mar  5 22:53:30 2009
New Revision: 66247

URL: http://llvm.org/viewvc/llvm-project?rev=66247&view=rev
Log:
Finish off __Block_byref_id_object_dispose codegen for block literals.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGBlocks.h
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/test/CodeGen/blocks-1.c

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=66247&r1=66246&r2=66247&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Mar  5 22:53:30 2009
@@ -793,7 +793,9 @@
   return llvm::ConstantExpr::getBitCast(Fn, PtrToInt8Ty);
 }
 
-llvm::Constant *BlockFunction::GeneratebyrefDestroyHelperFunction() {
+llvm::Constant *
+BlockFunction::GeneratebyrefDestroyHelperFunction(const llvm::Type *T,
+                                                  int flag) {
   QualType R = getContext().VoidTy;
 
   FunctionArgList Args;
@@ -825,7 +827,19 @@
                                           FunctionDecl::Static, false,
                                           true);
   CGF.StartFunction(FD, R, Fn, Args, SourceLocation());
-  // BuildBlockRelease(Src, flag);
+
+  llvm::Value *V = CGF.GetAddrOfLocalVar(Src);
+  V = Builder.CreateBitCast(V, T);
+  V = Builder.CreateStructGEP(V, 6, "x");
+  V = Builder.CreateBitCast(V, PtrToInt8Ty);
+
+  // FIXME: Move to other one.
+  // int flag = BLOCK_FIELD_IS_BYREF;
+  // FIXME: Add weak support
+  if (0)
+    flag |= BLOCK_FIELD_IS_WEAK;
+  flag |= BLOCK_BYREF_CALLER;
+  BuildBlockRelease(V, flag);
   CGF.FinishFunction();
 
   return llvm::ConstantExpr::getBitCast(Fn, PtrToInt8Ty);
@@ -835,8 +849,9 @@
   return CodeGenFunction(CGM).GeneratebyrefCopyHelperFunction();
 }
 
-llvm::Constant *BlockFunction::BuildbyrefDestroyHelper(int flag) {
-  return CodeGenFunction(CGM).GeneratebyrefDestroyHelperFunction();
+llvm::Constant *BlockFunction::BuildbyrefDestroyHelper(const llvm::Type *T,
+                                                       int flag) {
+  return CodeGenFunction(CGM).GeneratebyrefDestroyHelperFunction(T, flag);
 }
 
 llvm::Value *BlockFunction::getBlockObjectDispose() {
@@ -853,13 +868,11 @@
   return CGM.BlockObjectDispose;
 }
 
-void BlockFunction::BuildBlockRelease(llvm::Value *DeclPtr) {
+void BlockFunction::BuildBlockRelease(llvm::Value *V, int flag) {
   llvm::Value *F = getBlockObjectDispose();
-  llvm::Value *N, *V;
-  V = Builder.CreateStructGEP(DeclPtr, 1, "forwarding");
-  V = Builder.CreateLoad(V, false);
+  llvm::Value *N;
   V = Builder.CreateBitCast(V, PtrToInt8Ty);
-  N = llvm::ConstantInt::get(llvm::Type::Int32Ty, BLOCK_FIELD_IS_BYREF);
+  N = llvm::ConstantInt::get(llvm::Type::Int32Ty, flag);
   Builder.CreateCall2(F, V, N);
 }
 

Modified: cfe/trunk/lib/CodeGen/CGBlocks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.h?rev=66247&r1=66246&r2=66247&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.h (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.h Thu Mar  5 22:53:30 2009
@@ -164,13 +164,13 @@
   llvm::Constant *BuildDestroyHelper();
 
   llvm::Constant *GeneratebyrefCopyHelperFunction();
-  llvm::Constant *GeneratebyrefDestroyHelperFunction();
+  llvm::Constant *GeneratebyrefDestroyHelperFunction(const llvm::Type *T, int);
 
   llvm::Constant *BuildbyrefCopyHelper(int flag);
-  llvm::Constant *BuildbyrefDestroyHelper(int flag);
+  llvm::Constant *BuildbyrefDestroyHelper(const llvm::Type*, int flag);
 
   llvm::Value *getBlockObjectDispose();
-  void BuildBlockRelease(llvm::Value *DeclPtr);
+  void BuildBlockRelease(llvm::Value *DeclPtr, int flag = BLOCK_FIELD_IS_BYREF);
 
   bool BlockRequiresCopying(QualType Ty) {
     if (Ty->isBlockPointerType())

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=66247&r1=66246&r2=66247&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Thu Mar  5 22:53:30 2009
@@ -345,8 +345,8 @@
       flag |= BLOCK_FIELD_IS_BLOCK;
       flags |= BLOCK_HAS_COPY_DISPOSE;
     } else if (BlockRequiresCopying(Ty)) {
-      flags |= BLOCK_HAS_COPY_DISPOSE;
       flag |= BLOCK_FIELD_IS_OBJECT;
+      flags |= BLOCK_HAS_COPY_DISPOSE;
     }
     // FIXME: Need to set BLOCK_FIELD_IS_WEAK as appropriate.
 
@@ -373,11 +373,11 @@
     if (flags & BLOCK_HAS_COPY_DISPOSE) {
       BlockHasCopyDispose = true;
       llvm::Value *copy_helper = Builder.CreateStructGEP(DeclPtr, 4);
-      llvm::Value *destroy_helper = Builder.CreateStructGEP(DeclPtr, 5);
-
       Builder.CreateStore(BuildbyrefCopyHelper(flag), copy_helper);
 
-      Builder.CreateStore(BuildbyrefDestroyHelper(flag), destroy_helper);
+      llvm::Value *destroy_helper = Builder.CreateStructGEP(DeclPtr, 5);
+      Builder.CreateStore(BuildbyrefDestroyHelper(DeclPtr->getType(), flag),
+                          destroy_helper);
     }
     needsDispose = true;
   }
@@ -400,7 +400,9 @@
 
   if (needsDispose && CGM.getLangOptions().getGCMode() != LangOptions::GCOnly) {
     CleanupScope scope(*this);
-    BuildBlockRelease(DeclPtr);
+    llvm::Value *V = Builder.CreateStructGEP(DeclPtr, 1, "forwarding");
+    V = Builder.CreateLoad(V, false);
+    BuildBlockRelease(V);
   }
 }
 

Modified: cfe/trunk/test/CodeGen/blocks-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/blocks-1.c?rev=66247&r1=66246&r2=66247&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/blocks-1.c (original)
+++ cfe/trunk/test/CodeGen/blocks-1.c Thu Mar  5 22:53:30 2009
@@ -1,9 +1,10 @@
 // RUN: clang %s -emit-llvm -o %t -fblocks -f__block &&
-// RUN: grep "_Block_object_dispose" %t | count 5
-// RUN: grep "__copy_helper_block_" %t | count 6
-// RUN: grep "__destroy_helper_block_" %t | count 6
-// RUN: grep "__Block_byref_id_object_copy_" %t | count 2
-// RUN: grep "__Block_byref_id_object_dispose_" %t | count 2
+// RUN: grep "_Block_object_dispose" %t | count 5 &&
+// RUN: grep "__copy_helper_block_" %t | count 6 &&
+// RUN: grep "__destroy_helper_block_" %t | count 6 &&
+// RUN: grep "__Block_byref_id_object_copy_" %t | count 2 &&
+// RUN: grep "__Block_byref_id_object_dispose_" %t | count 2 &&
+// RUN: grep "i32 135)" %t | count 1
 #include <stdio.h>
 
 void test1() {





More information about the cfe-commits mailing list