[cfe-commits] r64461 - in /cfe/trunk/lib/CodeGen: CGBlocks.cpp CodeGenModule.h

Mike Stump mrs at apple.com
Fri Feb 13 09:23:42 PST 2009


Author: mrs
Date: Fri Feb 13 11:23:42 2009
New Revision: 64461

URL: http://llvm.org/viewvc/llvm-project?rev=64461&view=rev
Log:
Condense NSConcreteGlobalBlock handling.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    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=64461&r1=64460&r2=64461&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Feb 13 11:23:42 2009
@@ -75,6 +75,24 @@
   return C;
 }
 
+llvm::Constant *CodeGenModule::getNSConcreteGlobalBlock() {
+  if (NSConcreteGlobalBlock)
+    return NSConcreteGlobalBlock;
+
+  const llvm::PointerType *PtrToInt8Ty
+    = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
+  // FIXME: Wee should have a CodeGenModule::AddRuntimeVariable that does the
+  // same thing as CreateRuntimeFunction if there's already a variable with
+  // the same name.
+  NSConcreteGlobalBlock
+    = new llvm::GlobalVariable(PtrToInt8Ty, false, 
+                               llvm::GlobalValue::ExternalLinkage,
+                               0, "_NSConcreteGlobalBlock",
+                               &getModule());
+
+  return NSConcreteGlobalBlock;
+}
+
 llvm::Constant *CodeGenFunction::BuildBlockLiteralTmp() {
   // FIXME: Push up
   bool BlockHasCopyDispose = false;
@@ -99,11 +117,6 @@
       = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
     // FIXME: static?  What if we start up a new, unrelated module?
     // logically we want 1 per module.
-    static llvm::Constant *NSConcreteGlobalBlock_decl
-      = new llvm::GlobalVariable(PtrToInt8Ty, false, 
-                                 llvm::GlobalValue::ExternalLinkage,
-                                 0, "_NSConcreteGlobalBlock",
-                                 &CGM.getModule());
     static llvm::Constant *NSConcreteStackBlock_decl
       = new llvm::GlobalVariable(PtrToInt8Ty, false, 
                                  llvm::GlobalValue::ExternalLinkage,
@@ -112,7 +125,7 @@
     C = NSConcreteStackBlock_decl;
     if (!insideFunction ||
         (!BlockRefDeclList && !BlockByrefDeclList)) {
-      C = NSConcreteGlobalBlock_decl;
+      C = CGM.getNSConcreteGlobalBlock();
       flags |= BLOCK_IS_GLOBAL;
     }
     C = llvm::ConstantExpr::getBitCast(C, PtrToInt8Ty);
@@ -272,18 +285,6 @@
 }
 
 llvm::Constant *CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE) {
-  if (!NSConcreteGlobalBlock) {
-    const llvm::Type *Ty = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
-
-    // FIXME: Wee should have a CodeGenModule::AddRuntimeVariable that does the
-    // same thing as CreateRuntimeFunction if there's already a variable with
-    // the same name.
-    NSConcreteGlobalBlock =
-      new llvm::GlobalVariable(Ty, false,
-                              llvm::GlobalVariable::ExternalLinkage, 0,
-                              "_NSConcreteGlobalBlock", &getModule());
-  }
-
   // Generate the block descriptor.
   const llvm::Type *UnsignedLongTy = Types.ConvertType(Context.UnsignedLongTy);
   const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(
@@ -316,7 +317,7 @@
   llvm::Function *Fn = CodeGenFunction(*this).GenerateBlockFunction(BE, Info);
 
   // isa
-  LiteralFields[0] = NSConcreteGlobalBlock;
+  LiteralFields[0] = getNSConcreteGlobalBlock();
 
   // Flags
   LiteralFields[1] = llvm::ConstantInt::get(IntTy, BLOCK_IS_GLOBAL);

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Fri Feb 13 11:23:42 2009
@@ -141,6 +141,8 @@
   /// Release - Finalize LLVM code generation.
   void Release();
 
+  llvm::Constant *getNSConcreteGlobalBlock();
+
   const llvm::Type *getBlockDescriptorType();
 
   const llvm::Type *getGenericBlockLiteralType();





More information about the cfe-commits mailing list