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

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

index 9aa5207a443849a41632f2c4de7fe0c38da24022..cb096fcacc0c35cc4b3a732d5bd147575e729b1c 100644 (file)
@@ -26,25 +26,25 @@ enum {
   IsGlobal = 1 << 28
 };
 
-static const llvm::Type *getBlockDescriptorType(CodeGenModule &CGM) {
-  static const llvm::Type *Ty = 0;
-    
-  if (!Ty) {
-    const llvm::Type *UnsignedLongTy = 
-      CGM.getTypes().ConvertType(CGM.getContext().UnsignedLongTy);
-        
-    // struct __block_descriptor {
-    //   unsigned long reserved;
-    //   unsigned long block_size;
-    // };
-    Ty = llvm::StructType::get(UnsignedLongTy, 
-                               UnsignedLongTy, 
-                               NULL);
+const llvm::Type *CodeGenModule::getBlockDescriptorType() {
+  if (BlockDescriptorType)
+    return BlockDescriptorType;
+
+  const llvm::Type *UnsignedLongTy = 
+    getTypes().ConvertType(getContext().UnsignedLongTy);
         
-    CGM.getModule().addTypeName("struct.__block_descriptor", Ty);
-  }
-    
-  return Ty;
+  // struct __block_descriptor {
+  //   unsigned long reserved;
+  //   unsigned long block_size;
+  // };
+  BlockDescriptorType = llvm::StructType::get(UnsignedLongTy, 
+                                              UnsignedLongTy, 
+                                              NULL);
+
+  getModule().addTypeName("struct.__block_descriptor",
+                          BlockDescriptorType);
+
+  return BlockDescriptorType;
 }
 
 static const llvm::Type *getGenericBlockLiteralType(CodeGenModule &CGM) {
@@ -55,7 +55,7 @@ static const llvm::Type *getGenericBlockLiteralType(CodeGenModule &CGM) {
       llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
         
     const llvm::Type *BlockDescPtrTy = 
-      llvm::PointerType::getUnqual(getBlockDescriptorType(CGM));
+      llvm::PointerType::getUnqual(CGM.getBlockDescriptorType());
         
     // struct __block_literal_generic {
     //   void *isa;
index df4a3d07636d193098ff6232a6b03c62f616e8b5..422eb3bb7b88e4704292d215645437c616b40b90 100644 (file)
@@ -36,7 +36,8 @@ CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO,
                              Diagnostic &diags, bool GenerateDebugInfo)
   : Context(C), Features(LO), TheModule(M), TheTargetData(TD), Diags(diags),
     Types(C, M, TD), Runtime(0), MemCpyFn(0), MemMoveFn(0), MemSetFn(0),
-    CFConstantStringClassRef(0), NSConcreteGlobalBlock(0) {
+    CFConstantStringClassRef(0), NSConcreteGlobalBlock(0),
+    BlockDescriptorType(0) {
 
   if (Features.ObjC1) {
     if (Features.NeXTRuntime) {
index d8719efabfd265f85405e46733903fd42fd8f920..c484264e3d57bf0c243361285524e93cb73ff844 100644 (file)
@@ -123,10 +123,12 @@ class CodeGenModule {
   /// Obj-C class pointer.
   llvm::Constant *CFConstantStringClassRef;
   
-  /// NSConcreteGlobalBlock - Cached reference to the clas pointer for 
+  /// NSConcreteGlobalBlock - Cached reference to the class pointer for 
   /// global blocks.
   llvm::Constant *NSConcreteGlobalBlock;
   
+  const llvm::Type *BlockDescriptorType;
+
   std::vector<llvm::Function *> BuiltinFunctions;
 public:
   CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M, 
@@ -138,6 +140,8 @@ public:
   /// Release - Finalize LLVM code generation.
   void Release();
 
+  const llvm::Type *getBlockDescriptorType();
+
   /// getObjCRuntime() - Return a reference to the configured
   /// Objective-C runtime.
   CGObjCRuntime &getObjCRuntime() {