From: Daniel Dunbar Date: Fri, 16 Jul 2010 00:00:15 +0000 (+0000) Subject: IRgen: Move blocks runtime interfaces to CodeGenModule. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=673431a2986f750b4d8fadb57abf3f00db27bbbd;p=clang IRgen: Move blocks runtime interfaces to CodeGenModule. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108481 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index cb9e636221..f38c04bcc4 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -111,20 +111,6 @@ BuildDescriptorBlockDecl(const BlockExpr *BE, bool BlockHasCopyDispose, CharUnit return C; } -llvm::Constant *BlockModule::getNSConcreteGlobalBlock() { - if (NSConcreteGlobalBlock == 0) - NSConcreteGlobalBlock = CGM.CreateRuntimeVariable(PtrToInt8Ty, - "_NSConcreteGlobalBlock"); - return NSConcreteGlobalBlock; -} - -llvm::Constant *BlockModule::getNSConcreteStackBlock() { - if (NSConcreteStackBlock == 0) - NSConcreteStackBlock = CGM.CreateRuntimeVariable(PtrToInt8Ty, - "_NSConcreteStackBlock"); - return NSConcreteStackBlock; -} - static void CollectBlockDeclRefInfo(const Stmt *S, CGBlockInfo &Info) { for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end(); I != E; ++I) @@ -700,7 +686,7 @@ BlockModule::GetAddrOfGlobalBlock(const BlockExpr *BE, const char * n) { && "no imports allowed for global block"); // isa - LiteralFields[0] = getNSConcreteGlobalBlock(); + LiteralFields[0] = CGM.getNSConcreteGlobalBlock(); // Flags LiteralFields[1] = @@ -1012,7 +998,7 @@ GenerateCopyHelperFunction(bool BlockHasCopyDispose, const llvm::StructType *T, Dstv = Builder.CreateBitCast(Dstv, PtrToInt8Ty); llvm::Value *N = llvm::ConstantInt::get(CGF.Int32Ty, flag); - llvm::Value *F = getBlockObjectAssign(); + llvm::Value *F = CGM.getBlockObjectAssign(); Builder.CreateCall3(F, Dstv, Srcv, N); } } @@ -1164,7 +1150,7 @@ GeneratebyrefCopyHelperFunction(const llvm::Type *T, int flag) { flag |= BLOCK_BYREF_CALLER; llvm::Value *N = llvm::ConstantInt::get(CGF.Int32Ty, flag); - llvm::Value *F = getBlockObjectAssign(); + llvm::Value *F = CGM.getBlockObjectAssign(); Builder.CreateCall3(F, DstObj, SrcObj, N); CGF.FinishFunction(); @@ -1259,37 +1245,8 @@ llvm::Constant *BlockFunction::BuildbyrefDestroyHelper(const llvm::Type *T, return Entry=CodeGenFunction(CGM).GeneratebyrefDestroyHelperFunction(T, Flag); } -llvm::Value *BlockFunction::getBlockObjectDispose() { - if (CGM.BlockObjectDispose == 0) { - const llvm::FunctionType *FTy; - std::vector ArgTys; - const llvm::Type *ResultType = llvm::Type::getVoidTy(VMContext); - ArgTys.push_back(PtrToInt8Ty); - ArgTys.push_back(CGF.Int32Ty); - FTy = llvm::FunctionType::get(ResultType, ArgTys, false); - CGM.BlockObjectDispose - = CGM.CreateRuntimeFunction(FTy, "_Block_object_dispose"); - } - return CGM.BlockObjectDispose; -} - -llvm::Value *BlockFunction::getBlockObjectAssign() { - if (CGM.BlockObjectAssign == 0) { - const llvm::FunctionType *FTy; - std::vector ArgTys; - const llvm::Type *ResultType = llvm::Type::getVoidTy(VMContext); - ArgTys.push_back(PtrToInt8Ty); - ArgTys.push_back(PtrToInt8Ty); - ArgTys.push_back(CGF.Int32Ty); - FTy = llvm::FunctionType::get(ResultType, ArgTys, false); - CGM.BlockObjectAssign - = CGM.CreateRuntimeFunction(FTy, "_Block_object_assign"); - } - return CGM.BlockObjectAssign; -} - void BlockFunction::BuildBlockRelease(llvm::Value *V, int flag) { - llvm::Value *F = getBlockObjectDispose(); + llvm::Value *F = CGM.getBlockObjectDispose(); llvm::Value *N; V = Builder.CreateBitCast(V, PtrToInt8Ty); N = llvm::ConstantInt::get(CGF.Int32Ty, flag); diff --git a/lib/CodeGen/CGBlocks.h b/lib/CodeGen/CGBlocks.h index 772a62c24f..743e3c83be 100644 --- a/lib/CodeGen/CGBlocks.h +++ b/lib/CodeGen/CGBlocks.h @@ -73,8 +73,6 @@ class BlockModule : public BlockBase { CodeGenTypes &getTypes() { return Types; } const llvm::TargetData &getTargetData() const { return TheTargetData; } public: - llvm::Constant *getNSConcreteGlobalBlock(); - llvm::Constant *getNSConcreteStackBlock(); int getGlobalUniqueCount() { return ++Block.GlobalUniqueCount; } const llvm::Type *getBlockDescriptorType(); @@ -82,14 +80,6 @@ public: llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *); - /// NSConcreteGlobalBlock - Cached reference to the class pointer for global - /// 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; @@ -97,8 +87,6 @@ public: int GlobalUniqueCount; } Block; - llvm::Value *BlockObjectAssign; - llvm::Value *BlockObjectDispose; const llvm::PointerType *PtrToInt8Ty; std::map AssignCache; @@ -108,9 +96,7 @@ public: CodeGenTypes &T, CodeGenModule &CodeGen) : Context(C), TheModule(M), TheTargetData(TD), Types(T), CGM(CodeGen), VMContext(M.getContext()), - NSConcreteGlobalBlock(0), NSConcreteStackBlock(0), BlockDescriptorType(0), - GenericBlockLiteralType(0), - BlockObjectAssign(0), BlockObjectDispose(0) { + BlockDescriptorType(0), GenericBlockLiteralType(0) { Block.GlobalUniqueCount = 0; PtrToInt8Ty = llvm::Type::getInt8PtrTy(M.getContext()); } @@ -207,8 +193,6 @@ public: llvm::Constant *BuildbyrefDestroyHelper(const llvm::Type *T, int flag, unsigned Align); - llvm::Value *getBlockObjectAssign(); - llvm::Value *getBlockObjectDispose(); void BuildBlockRelease(llvm::Value *DeclPtr, int flag = BLOCK_FIELD_IS_BYREF); bool BlockRequiresCopying(QualType Ty) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index ed95422300..f05a018e91 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -50,9 +50,10 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO, TheTargetData(TD), TheTargetCodeGenInfo(0), Diags(diags), Types(C, M, TD, getTargetCodeGenInfo().getABIInfo()), VTables(*this), Runtime(0), ABI(0), - CFConstantStringClassRef(0), - NSConstantStringClassRef(0), - VMContext(M.getContext()) { + CFConstantStringClassRef(0), NSConstantStringClassRef(0), + VMContext(M.getContext()), + NSConcreteGlobalBlock(0), NSConcreteStackBlock(0), + BlockObjectAssign(0), BlockObjectDispose(0){ if (!Features.ObjC1) Runtime = 0; @@ -2132,3 +2133,54 @@ void CodeGenFunction::EmitDeclMetadata() { } } } + +///@name Custom Runtime Function Interfaces +///@{ +// +// FIXME: These can be eliminated once we can have clients just get the required +// AST nodes from the builtin tables. + +llvm::Constant *CodeGenModule::getBlockObjectDispose() { + if (BlockObjectDispose) + return BlockObjectDispose; + + const llvm::FunctionType *FTy; + std::vector ArgTys; + const llvm::Type *ResultType = llvm::Type::getVoidTy(VMContext); + ArgTys.push_back(PtrToInt8Ty); + ArgTys.push_back(llvm::Type::getInt32Ty(VMContext)); + FTy = llvm::FunctionType::get(ResultType, ArgTys, false); + return BlockObjectDispose = + CreateRuntimeFunction(FTy, "_Block_object_dispose"); +} + +llvm::Constant *CodeGenModule::getBlockObjectAssign() { + if (BlockObjectAssign) + return BlockObjectAssign; + + const llvm::FunctionType *FTy; + std::vector ArgTys; + const llvm::Type *ResultType = llvm::Type::getVoidTy(VMContext); + ArgTys.push_back(PtrToInt8Ty); + ArgTys.push_back(PtrToInt8Ty); + ArgTys.push_back(llvm::Type::getInt32Ty(VMContext)); + FTy = llvm::FunctionType::get(ResultType, ArgTys, false); + return BlockObjectAssign = + CreateRuntimeFunction(FTy, "_Block_object_assign"); +} + +llvm::Constant *CodeGenModule::getNSConcreteGlobalBlock() { + if (NSConcreteGlobalBlock) + return NSConcreteGlobalBlock; + return NSConcreteGlobalBlock = CreateRuntimeVariable( + PtrToInt8Ty, "_NSConcreteGlobalBlock"); +} + +llvm::Constant *CodeGenModule::getNSConcreteStackBlock() { + if (NSConcreteStackBlock) + return NSConcreteStackBlock; + return NSConcreteStackBlock = CreateRuntimeVariable( + PtrToInt8Ty, "_NSConcreteStackBlock"); +} + +///@} diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 05d02ec0a0..f3bd307129 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -193,6 +193,16 @@ class CodeGenModule : public BlockModule { void createCXXABI(); llvm::LLVMContext &VMContext; + + /// @name Cache for Blocks Runtime Globals + /// @{ + + llvm::Constant *NSConcreteGlobalBlock; + llvm::Constant *NSConcreteStackBlock; + llvm::Constant *BlockObjectAssign; + llvm::Constant *BlockObjectDispose; + + /// @} public: CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts, llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags); @@ -398,6 +408,16 @@ public: llvm::Constant *CreateRuntimeVariable(const llvm::Type *Ty, llvm::StringRef Name); + ///@name Custom Blocks Runtime Interfaces + ///@{ + + llvm::Constant *getNSConcreteGlobalBlock(); + llvm::Constant *getNSConcreteStackBlock(); + llvm::Constant *getBlockObjectAssign(); + llvm::Constant *getBlockObjectDispose(); + + ///@} + void UpdateCompletedType(const TagDecl *TD) { // Make sure that this type is translated. Types.UpdateCompletedType(TD);