[cfe-commits] r110239 - in /cfe/trunk/lib/CodeGen: CGBlocks.cpp CGObjCMac.cpp CodeGenFunction.h

Fariborz Jahanian fjahanian at apple.com
Wed Aug 4 11:44:59 PDT 2010


Author: fjahanian
Date: Wed Aug  4 13:44:59 2010
New Revision: 110239

URL: http://llvm.org/viewvc/llvm-project?rev=110239&view=rev
Log:
More objc block variable layout info. work.


Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=110239&r1=110238&r2=110239&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Aug  4 13:44:59 2010
@@ -36,6 +36,7 @@
 llvm::Constant *CodeGenFunction::
 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;
@@ -72,11 +73,8 @@
           CGM.GetAddrOfConstantCString(BlockTypeEncoding), PtrToInt8Ty));
   
   // Layout.
-  if (CGM.getContext().getLangOptions().ObjC1)
-    C = CGM.getObjCRuntime().GCBlockLayout(*this, Info.DeclRefs);
-  else
-    C = llvm::Constant::getNullValue(PtrToInt8Ty);
-  
+  C = BlockVarLayout;
+    
   Elts.push_back(C);
 
   C = llvm::ConstantStruct::get(VMContext, Elts, false);
@@ -198,6 +196,7 @@
   llvm::Value *V;
 
   {
+    llvm::Constant *BlockVarLayout;
     // C = BuildBlockStructInitlist();
     unsigned int flags = BLOCK_HAS_SIGNATURE;
 
@@ -206,6 +205,7 @@
     // __invoke
     llvm::Function *Fn
       = CodeGenFunction(CGM).GenerateBlockFunction(CurGD, BE, Info, CurFuncDecl,
+                                                   BlockVarLayout,
                                                    LocalDeclMap);
     BlockHasCopyDispose |= Info.BlockHasCopyDispose;
     Elts[3] = Fn;
@@ -233,7 +233,8 @@
 
     if (Info.BlockLayout.empty()) {
       // __descriptor
-      Elts[4] = BuildDescriptorBlockDecl(BE, Info, 0, 0);
+      C = llvm::Constant::getNullValue(PtrToInt8Ty);
+      Elts[4] = BuildDescriptorBlockDecl(BE, Info, 0, C, 0);
 
       // Optimize to being a global block.
       Elts[0] = CGM.getNSConcreteGlobalBlock();
@@ -388,6 +389,7 @@
 
     // __descriptor
     llvm::Value *Descriptor = BuildDescriptorBlockDecl(BE, Info, Ty,
+                                                       BlockVarLayout,
                                                        &NoteForHelper);
     Descriptor = Builder.CreateBitCast(Descriptor, PtrToInt8Ty);
     Builder.CreateStore(Descriptor, Builder.CreateStructGEP(V, 4, "block.tmp"));
@@ -656,10 +658,12 @@
   std::vector<llvm::Constant*> LiteralFields(FieldCount);
 
   CGBlockInfo Info(n);
+  llvm::Constant *BlockVarLayout;
   llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
   llvm::Function *Fn
     = CodeGenFunction(CGM).GenerateBlockFunction(GlobalDecl(), BE, 
-                                                 Info, 0, LocalDeclMap);
+                                                 Info, 0, BlockVarLayout,
+                                                 LocalDeclMap);
   assert(Info.BlockSize == BlockLiteralSize
          && "no imports allowed for global block");
 
@@ -703,6 +707,7 @@
 CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, const BlockExpr *BExpr,
                                        CGBlockInfo &Info,
                                        const Decl *OuterFuncDecl,
+                                       llvm::Constant *& BlockVarLayout,
                                   llvm::DenseMap<const Decl*, llvm::Value*> ldm) {
 
   // Check if we should generate debug info for this block.
@@ -750,6 +755,12 @@
   // Build the block struct now.
   AllocateAllBlockDeclRefs(*this, Info);
 
+  // Capture block layout info. here.
+  if (CGM.getContext().getLangOptions().ObjC1)
+    BlockVarLayout = CGM.getObjCRuntime().GCBlockLayout(*this, Info.DeclRefs);
+  else
+    BlockVarLayout = llvm::Constant::getNullValue(PtrToInt8Ty);
+  
   QualType ParmTy = getContext().getBlockParmType(BlockHasCopyDispose,
                                                   BlockLayout);
 

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=110239&r1=110238&r2=110239&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Aug  4 13:44:59 2010
@@ -1690,8 +1690,12 @@
 }
 
 llvm::Constant *CGObjCCommonMac::GCBlockLayout(CodeGen::CodeGenFunction &CGF,
-              const llvm::SmallVectorImpl<const BlockDeclRefExpr *> &BDRE) {
-  return llvm::Constant::getNullValue(llvm::Type::getInt8PtrTy(VMContext));
+              const llvm::SmallVectorImpl<const BlockDeclRefExpr *> &DeclRefs) {
+  llvm::Constant *NullPtr = 
+    llvm::Constant::getNullValue(llvm::Type::getInt8PtrTy(VMContext));
+  if (DeclRefs.empty())
+    return NullPtr;
+  return NullPtr;
 }
 
 llvm::Value *CGObjCMac::GenerateProtocolRef(CGBuilderTy &Builder,

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=110239&r1=110238&r2=110239&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Aug  4 13:44:59 2010
@@ -761,12 +761,14 @@
   llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *,
                                            const CGBlockInfo &Info,
                                            const llvm::StructType *,
+                                           llvm::Constant *BlockVarLayout,
                                            std::vector<HelperInfo> *);
 
   llvm::Function *GenerateBlockFunction(GlobalDecl GD,
                                         const BlockExpr *BExpr,
                                         CGBlockInfo &Info,
                                         const Decl *OuterFuncDecl,
+                                        llvm::Constant *& BlockVarLayout,
                                   llvm::DenseMap<const Decl*, llvm::Value*> ldm);
 
   llvm::Value *LoadBlockStruct();





More information about the cfe-commits mailing list