]> granicus.if.org Git - clang/commitdiff
Move NSConcreteStackBlock into CGM.
authorMike Stump <mrs@apple.com>
Fri, 13 Feb 2009 19:29:27 +0000 (19:29 +0000)
committerMike Stump <mrs@apple.com>
Fri, 13 Feb 2009 19:29:27 +0000 (19:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64479 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CodeGenModule.h

index be79a1a1ac1d362557d0c0985145a7bfc76082cb..d6c248dcef76e391b07076199250151309961f64 100644 (file)
@@ -93,6 +93,24 @@ llvm::Constant *CodeGenModule::getNSConcreteGlobalBlock() {
   return NSConcreteGlobalBlock;
 }
 
+llvm::Constant *CodeGenModule::getNSConcreteStackBlock() {
+  if (NSConcreteStackBlock)
+    return NSConcreteStackBlock;
+
+  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.
+  NSConcreteStackBlock
+    = new llvm::GlobalVariable(PtrToInt8Ty, false, 
+                               llvm::GlobalValue::ExternalLinkage,
+                               0, "_NSConcreteStackBlock",
+                               &getModule());
+
+  return NSConcreteStackBlock;
+}
+
 llvm::Constant *CodeGenFunction::BuildBlockLiteralTmp() {
   // FIXME: Push up
   bool BlockHasCopyDispose = false;
@@ -110,21 +128,14 @@ llvm::Constant *CodeGenFunction::BuildBlockLiteralTmp() {
     if (BlockHasCopyDispose)
       flags |= BLOCK_HAS_COPY_DISPOSE;
 
-    const llvm::PointerType *PtrToInt8Ty
-      = 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 *NSConcreteStackBlock_decl
-      = new llvm::GlobalVariable(PtrToInt8Ty, false, 
-                                 llvm::GlobalValue::ExternalLinkage,
-                                 0, "_NSConcreteStackBlock",
-                                 &CGM.getModule());
-    C = NSConcreteStackBlock_decl;
+    C = CGM.getNSConcreteStackBlock();
     if (!insideFunction ||
         (!BlockRefDeclList && !BlockByrefDeclList)) {
       C = CGM.getNSConcreteGlobalBlock();
       flags |= BLOCK_IS_GLOBAL;
     }
+    const llvm::PointerType *PtrToInt8Ty
+      = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
     C = llvm::ConstantExpr::getBitCast(C, PtrToInt8Ty);
     Elts.push_back(C);
 
index fb13dfde5caad1c2f9a7be02e60dd1cd6ab4e9b2..e79d18990d61e1caacd087df14dae9b2f52fd565 100644 (file)
@@ -123,6 +123,10 @@ class CodeGenModule {
   /// blocks.
   llvm::Constant *NSConcreteGlobalBlock;
 
+  /// NSConcreteStackBlock - Cached reference to the class poinnter for stack
+  /// blocks.
+  llvm::Constant *NSConcreteStackBlock;
+  
   const llvm::Type *BlockDescriptorType;
   const llvm::Type * GenericBlockLiteralType;
   struct {
@@ -141,6 +145,7 @@ public:
   void Release();
 
   llvm::Constant *getNSConcreteGlobalBlock();
+  llvm::Constant *getNSConcreteStackBlock();
   int getGlobalUniqueCount() { return ++Block.GlobalUniqueCount; }
   const llvm::Type *getBlockDescriptorType();