[cfe-commits] r64570 - in /cfe/trunk/lib/CodeGen: CGBlocks.cpp CGExprConstant.cpp CGExprScalar.cpp CodeGenFunction.h CodeGenModule.h

Mike Stump mrs at apple.com
Sat Feb 14 14:16:36 PST 2009


Author: mrs
Date: Sat Feb 14 16:16:35 2009
New Revision: 64570

URL: http://llvm.org/viewvc/llvm-project?rev=64570&view=rev
Log:
Generate the helper function for blocks.  Now basic codegen is
starting to work for blocks.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/lib/CodeGen/CodeGenModule.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Sat Feb 14 16:16:35 2009
@@ -107,7 +107,7 @@
   return NSConcreteStackBlock;
 }
 
-llvm::Constant *CodeGenFunction::BuildBlockLiteralTmp() {
+llvm::Constant *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) {
   // FIXME: Push up
   bool BlockHasCopyDispose = false;
   bool insideFunction = false;
@@ -147,8 +147,12 @@
     Elts.push_back(C);
 
     // __FuncPtr
-    // FIXME: Build this up.
-    Elts.push_back(C);
+    std::string Name;
+    if (const NamedDecl *ND = dyn_cast<NamedDecl>(CurFuncDecl))
+      Name = ND->getNameAsString();
+    BlockInfo Info(0, Name);
+    llvm::Function *Fn = CodeGenFunction(*this).GenerateBlockFunction(BE, Info);
+    Elts.push_back(Fn);
 
     // __descriptor
     Elts.push_back(BuildDescriptorBlockDecl());
@@ -287,7 +291,8 @@
                   Func, Args);
 }
 
-llvm::Constant *CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE) {
+llvm::Constant *
+CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE, std::string n) {
   // Generate the block descriptor.
   const llvm::Type *UnsignedLongTy = Types.ConvertType(Context.UnsignedLongTy);
   const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(
@@ -316,7 +321,7 @@
   // Generate the constants for the block literal.
   llvm::Constant *LiteralFields[5];
 
-  CodeGenFunction::BlockInfo Info(0, "global");
+  CodeGenFunction::BlockInfo Info(0, n);
   llvm::Function *Fn = CodeGenFunction(*this).GenerateBlockFunction(BE, Info);
 
   // isa
@@ -371,8 +376,7 @@
   const CGFunctionInfo &FI =
     CGM.getTypes().getFunctionInfo(FTy->getResultType(), Args);
 
-  std::string Name = std::string("__block_function_") + Info.NameSuffix;
-
+  std::string Name = std::string("__") + Info.Name + "_block_invoke_";
   CodeGenTypes &Types = CGM.getTypes();
   const llvm::FunctionType *LTy = Types.GetFunctionType(FI, FTy->isVariadic());
 

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sat Feb 14 16:16:35 2009
@@ -372,7 +372,10 @@
   }
     
   llvm::Constant *VisitBlockExpr(const BlockExpr *E) {
-    return CGM.GetAddrOfGlobalBlock(E);
+    const char *Name = "";
+    if (const NamedDecl *ND = dyn_cast<NamedDecl>(CGF->CurFuncDecl))
+      Name = ND->getNameAsString().c_str();
+    return CGM.GetAddrOfGlobalBlock(E, Name);
   }
   
   // Utility methods

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Feb 14 16:16:35 2009
@@ -1369,7 +1369,7 @@
 
 
 Value *ScalarExprEmitter::VisitBlockExpr(const BlockExpr *BE) {
-  llvm::Constant *C = CGF.BuildBlockLiteralTmp();
+  llvm::Constant *C = CGF.BuildBlockLiteralTmp(BE);
 
   const llvm::PointerType *PtrToInt8Ty
     = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Feb 14 16:16:35 2009
@@ -88,7 +88,7 @@
   const llvm::Type *LLVMIntTy;
   uint32_t LLVMPointerWidth;
 
-  llvm::Constant *BuildBlockLiteralTmp();
+  llvm::Constant *BuildBlockLiteralTmp(const BlockExpr *);
   llvm::Constant *BuildDescriptorBlockDecl();
 
 public:
@@ -250,13 +250,16 @@
   void GenerateObjCSetter(ObjCImplementationDecl *IMP,
                           const ObjCPropertyImplDecl *PID);
 
+  /// BlockInfo - Information to generate a block literal.
   struct BlockInfo {
+    /// BlockLiteralTy - The type of the block literal.
     const llvm::Type *BlockLiteralTy;
-    
-    const char *NameSuffix;
 
-    BlockInfo(const llvm::Type *blt, const char *ns) 
-      :  BlockLiteralTy(blt), NameSuffix(ns) {}
+    /// Name - the name of the function this block was created for, if any
+    std::string Name;
+
+    BlockInfo(const llvm::Type *blt, std::string n)
+      : BlockLiteralTy(blt), Name(n) {}
   };
   
   llvm::Function *GenerateBlockFunction(const BlockExpr *Expr,

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Sat Feb 14 16:16:35 2009
@@ -219,7 +219,7 @@
   llvm::Constant *GetAddrOfConstantCString(const std::string &str,
                                            const char *GlobalName=0);
 
-  llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE);
+  llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, std::string);
 
   /// getBuiltinLibFunction - Given a builtin id for a function like
   /// "__builtin_fabsf", return a Function* for "fabsf".





More information about the cfe-commits mailing list