From: Mike Stump Date: Fri, 13 Feb 2009 15:25:34 +0000 (+0000) Subject: Move GenericBlockLiteralType into CGM. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9b8a7977109604d573b49d517e98badbbb9d5ac7;p=clang Move GenericBlockLiteralType into CGM. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64452 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index cb096fcacc..2168351738 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -47,34 +47,35 @@ const llvm::Type *CodeGenModule::getBlockDescriptorType() { return BlockDescriptorType; } -static const llvm::Type *getGenericBlockLiteralType(CodeGenModule &CGM) { - static const llvm::Type *Ty = 0; - - if (!Ty) { - const llvm::Type *Int8PtrTy = - llvm::PointerType::getUnqual(llvm::Type::Int8Ty); +const llvm::Type * +CodeGenModule::getGenericBlockLiteralType() { + if (GenericBlockLiteralType) + return GenericBlockLiteralType; + + const llvm::Type *Int8PtrTy = + llvm::PointerType::getUnqual(llvm::Type::Int8Ty); - const llvm::Type *BlockDescPtrTy = - llvm::PointerType::getUnqual(CGM.getBlockDescriptorType()); + const llvm::Type *BlockDescPtrTy = + llvm::PointerType::getUnqual(getBlockDescriptorType()); - // struct __block_literal_generic { - // void *isa; - // int flags; - // int reserved; - // void (*invoke)(void *); - // struct __block_descriptor *descriptor; - // }; - Ty = llvm::StructType::get(Int8PtrTy, - llvm::Type::Int32Ty, - llvm::Type::Int32Ty, - Int8PtrTy, - BlockDescPtrTy, - NULL); + // struct __block_literal_generic { + // void *isa; + // int flags; + // int reserved; + // void (*invoke)(void *); + // struct __block_descriptor *descriptor; + // }; + GenericBlockLiteralType = llvm::StructType::get(Int8PtrTy, + llvm::Type::Int32Ty, + llvm::Type::Int32Ty, + Int8PtrTy, + BlockDescPtrTy, + NULL); - CGM.getModule().addTypeName("struct.__block_literal_generic", Ty); - } + getModule().addTypeName("struct.__block_literal_generic", + GenericBlockLiteralType); - return Ty; + return GenericBlockLiteralType; } /// getBlockFunctionType - Given a BlockPointerType, will return the @@ -103,7 +104,7 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) { // Get a pointer to the generic block literal. const llvm::Type *BlockLiteralTy = - llvm::PointerType::getUnqual(getGenericBlockLiteralType(CGM)); + llvm::PointerType::getUnqual(CGM.getGenericBlockLiteralType()); // Bitcast the callee to a block literal. llvm::Value *BlockLiteral = @@ -164,7 +165,7 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE) { // Block literal size. For global blocks we just use the size of the generic // block literal struct. uint64_t BlockLiteralSize = - TheTargetData.getTypeStoreSizeInBits(getGenericBlockLiteralType(*this)) / 8; + TheTargetData.getTypeStoreSizeInBits(getGenericBlockLiteralType()) / 8; DescriptorFields[1] = llvm::ConstantInt::get(UnsignedLongTy,BlockLiteralSize); llvm::Constant *DescriptorStruct = diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 422eb3bb7b..53d99f07eb 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -37,7 +37,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO, : 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), - BlockDescriptorType(0) { + BlockDescriptorType(0), GenericBlockLiteralType(0) { if (Features.ObjC1) { if (Features.NeXTRuntime) { diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index c484264e3d..eb9ce7dfed 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -128,6 +128,7 @@ class CodeGenModule { llvm::Constant *NSConcreteGlobalBlock; const llvm::Type *BlockDescriptorType; + const llvm::Type * GenericBlockLiteralType; std::vector BuiltinFunctions; public: @@ -142,6 +143,8 @@ public: const llvm::Type *getBlockDescriptorType(); + const llvm::Type *getGenericBlockLiteralType(); + /// getObjCRuntime() - Return a reference to the configured /// Objective-C runtime. CGObjCRuntime &getObjCRuntime() {