Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 1 | //===--- CGBlocks.cpp - Emit LLVM Code for declarations -------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This contains code to emit blocks. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CodeGenFunction.h" |
| 15 | #include "CodeGenModule.h" |
Mike Stump | fc5e6de | 2009-03-20 21:53:12 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclObjC.h" |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 17 | #include "llvm/Module.h" |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetData.h" |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 19 | #include <algorithm> |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | using namespace CodeGen; |
| 22 | |
Mike Stump | 9d8c126 | 2009-03-06 18:42:23 +0000 | [diff] [blame] | 23 | llvm::Constant *CodeGenFunction:: |
Mike Stump | 68bb7a2 | 2009-03-25 17:58:24 +0000 | [diff] [blame] | 24 | BuildDescriptorBlockDecl(bool BlockHasCopyDispose, uint64_t Size, |
| 25 | const llvm::StructType* Ty, |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 26 | std::vector<HelperInfo> *NoteForHelper) { |
Mike Stump | ff8f087 | 2009-02-13 16:55:51 +0000 | [diff] [blame] | 27 | const llvm::Type *UnsignedLongTy |
| 28 | = CGM.getTypes().ConvertType(getContext().UnsignedLongTy); |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 29 | llvm::Constant *C; |
| 30 | std::vector<llvm::Constant*> Elts; |
| 31 | |
| 32 | // reserved |
Mike Stump | ff8f087 | 2009-02-13 16:55:51 +0000 | [diff] [blame] | 33 | C = llvm::ConstantInt::get(UnsignedLongTy, 0); |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 34 | Elts.push_back(C); |
| 35 | |
| 36 | // Size |
Mike Stump | 139c396 | 2009-02-21 20:07:44 +0000 | [diff] [blame] | 37 | // FIXME: What is the right way to say this doesn't fit? We should give |
| 38 | // a user diagnostic in that case. Better fix would be to change the |
| 39 | // API to size_t. |
Mike Stump | fca5da0 | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 40 | C = llvm::ConstantInt::get(UnsignedLongTy, Size); |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 41 | Elts.push_back(C); |
| 42 | |
| 43 | if (BlockHasCopyDispose) { |
| 44 | // copy_func_helper_decl |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 45 | Elts.push_back(BuildCopyHelper(Ty, NoteForHelper)); |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 46 | |
| 47 | // destroy_func_decl |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 48 | Elts.push_back(BuildDestroyHelper(Ty, NoteForHelper)); |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | C = llvm::ConstantStruct::get(Elts); |
| 52 | |
Owen Anderson | 96bcdd4 | 2009-07-08 01:29:18 +0000 | [diff] [blame] | 53 | C = new llvm::GlobalVariable(CGM.getModule().getContext(), C->getType(), true, |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 54 | llvm::GlobalValue::InternalLinkage, |
Mike Stump | 92ea888 | 2009-02-13 20:17:16 +0000 | [diff] [blame] | 55 | C, "__block_descriptor_tmp", &CGM.getModule()); |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 56 | return C; |
| 57 | } |
| 58 | |
Mike Stump | 1f010b5 | 2009-03-04 18:17:45 +0000 | [diff] [blame] | 59 | llvm::Constant *BlockModule::getNSConcreteGlobalBlock() { |
Chris Lattner | 98a8799 | 2009-05-13 02:50:56 +0000 | [diff] [blame] | 60 | if (NSConcreteGlobalBlock == 0) |
| 61 | NSConcreteGlobalBlock = CGM.CreateRuntimeVariable(PtrToInt8Ty, |
| 62 | "_NSConcreteGlobalBlock"); |
Mike Stump | 5f87e9d | 2009-02-13 17:23:42 +0000 | [diff] [blame] | 63 | return NSConcreteGlobalBlock; |
| 64 | } |
| 65 | |
Mike Stump | 1f010b5 | 2009-03-04 18:17:45 +0000 | [diff] [blame] | 66 | llvm::Constant *BlockModule::getNSConcreteStackBlock() { |
Chris Lattner | 98a8799 | 2009-05-13 02:50:56 +0000 | [diff] [blame] | 67 | if (NSConcreteStackBlock == 0) |
| 68 | NSConcreteStackBlock = CGM.CreateRuntimeVariable(PtrToInt8Ty, |
| 69 | "_NSConcreteStackBlock"); |
Mike Stump | eb3a5ca | 2009-02-13 19:29:27 +0000 | [diff] [blame] | 70 | return NSConcreteStackBlock; |
| 71 | } |
| 72 | |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 73 | static void CollectBlockDeclRefInfo(const Stmt *S, |
Anders Carlsson | 6cf64be | 2009-03-01 01:09:12 +0000 | [diff] [blame] | 74 | CodeGenFunction::BlockInfo &Info) { |
| 75 | for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end(); |
| 76 | I != E; ++I) |
Daniel Dunbar | 56941d3 | 2009-03-02 07:00:57 +0000 | [diff] [blame] | 77 | if (*I) |
| 78 | CollectBlockDeclRefInfo(*I, Info); |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 79 | |
Anders Carlsson | 6cf64be | 2009-03-01 01:09:12 +0000 | [diff] [blame] | 80 | if (const BlockDeclRefExpr *DE = dyn_cast<BlockDeclRefExpr>(S)) { |
| 81 | // FIXME: Handle enums. |
| 82 | if (isa<FunctionDecl>(DE->getDecl())) |
| 83 | return; |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 84 | |
Anders Carlsson | 6cf64be | 2009-03-01 01:09:12 +0000 | [diff] [blame] | 85 | if (DE->isByRef()) |
| 86 | Info.ByRefDeclRefs.push_back(DE); |
| 87 | else |
| 88 | Info.ByCopyDeclRefs.push_back(DE); |
| 89 | } |
| 90 | } |
| 91 | |
Mike Stump | f13eac1 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 92 | /// CanBlockBeGlobal - Given a BlockInfo struct, determines if a block can be |
| 93 | /// declared as a global variable instead of on the stack. |
Chris Lattner | 98a8799 | 2009-05-13 02:50:56 +0000 | [diff] [blame] | 94 | static bool CanBlockBeGlobal(const CodeGenFunction::BlockInfo &Info) { |
Anders Carlsson | 6cf64be | 2009-03-01 01:09:12 +0000 | [diff] [blame] | 95 | return Info.ByRefDeclRefs.empty() && Info.ByCopyDeclRefs.empty(); |
| 96 | } |
| 97 | |
Mike Stump | f13eac1 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 98 | // FIXME: Push most into CGM, passing down a few bits, like current function |
| 99 | // name. |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 100 | llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) { |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 101 | |
Anders Carlsson | 6cf64be | 2009-03-01 01:09:12 +0000 | [diff] [blame] | 102 | std::string Name = CurFn->getName(); |
| 103 | CodeGenFunction::BlockInfo Info(0, Name.c_str()); |
| 104 | CollectBlockDeclRefInfo(BE->getBody(), Info); |
| 105 | |
| 106 | // Check if the block can be global. |
Mike Stump | f13eac1 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 107 | // FIXME: This test doesn't work for nested blocks yet. Longer term, I'd like |
| 108 | // to just have one code path. We should move this function into CGM and pass |
| 109 | // CGF, then we can just check to see if CGF is 0. |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 110 | if (0 && CanBlockBeGlobal(Info)) |
Anders Carlsson | 6cf64be | 2009-03-01 01:09:12 +0000 | [diff] [blame] | 111 | return CGM.GetAddrOfGlobalBlock(BE, Name.c_str()); |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 112 | |
| 113 | std::vector<llvm::Constant*> Elts(5); |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 114 | llvm::Constant *C; |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 115 | llvm::Value *V; |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 116 | |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 117 | { |
| 118 | // C = BuildBlockStructInitlist(); |
| 119 | unsigned int flags = BLOCK_HAS_DESCRIPTOR; |
| 120 | |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 121 | // We run this first so that we set BlockHasCopyDispose from the entire |
| 122 | // block literal. |
| 123 | // __invoke |
| 124 | uint64_t subBlockSize, subBlockAlign; |
| 125 | llvm::SmallVector<const Expr *, 8> subBlockDeclRefDecls; |
Mike Stump | 68bb7a2 | 2009-03-25 17:58:24 +0000 | [diff] [blame] | 126 | bool subBlockHasCopyDispose = false; |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 127 | llvm::Function *Fn |
Mike Stump | fc5e6de | 2009-03-20 21:53:12 +0000 | [diff] [blame] | 128 | = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, CurFuncDecl, LocalDeclMap, |
Mike Stump | a20c59e | 2009-03-13 23:34:28 +0000 | [diff] [blame] | 129 | subBlockSize, |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 130 | subBlockAlign, |
| 131 | subBlockDeclRefDecls, |
Mike Stump | 68bb7a2 | 2009-03-25 17:58:24 +0000 | [diff] [blame] | 132 | subBlockHasCopyDispose); |
| 133 | BlockHasCopyDispose |= subBlockHasCopyDispose; |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 134 | Elts[3] = Fn; |
| 135 | |
Mike Stump | ba2cb0e | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 136 | // FIXME: Don't use BlockHasCopyDispose, it is set more often then |
| 137 | // necessary, for example: { ^{ __block int i; ^{ i = 1; }(); }(); } |
Mike Stump | 68bb7a2 | 2009-03-25 17:58:24 +0000 | [diff] [blame] | 138 | if (subBlockHasCopyDispose) |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 139 | flags |= BLOCK_HAS_COPY_DISPOSE; |
| 140 | |
Mike Stump | 92ea888 | 2009-02-13 20:17:16 +0000 | [diff] [blame] | 141 | // __isa |
Mike Stump | eb3a5ca | 2009-02-13 19:29:27 +0000 | [diff] [blame] | 142 | C = CGM.getNSConcreteStackBlock(); |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 143 | C = llvm::ConstantExpr::getBitCast(C, PtrToInt8Ty); |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 144 | Elts[0] = C; |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 145 | |
| 146 | // __flags |
| 147 | const llvm::IntegerType *IntTy = cast<llvm::IntegerType>( |
| 148 | CGM.getTypes().ConvertType(CGM.getContext().IntTy)); |
| 149 | C = llvm::ConstantInt::get(IntTy, flags); |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 150 | Elts[1] = C; |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 151 | |
| 152 | // __reserved |
| 153 | C = llvm::ConstantInt::get(IntTy, 0); |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 154 | Elts[2] = C; |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 155 | |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 156 | if (subBlockDeclRefDecls.size() == 0) { |
Mike Stump | 9d8c126 | 2009-03-06 18:42:23 +0000 | [diff] [blame] | 157 | // __descriptor |
Mike Stump | 68bb7a2 | 2009-03-25 17:58:24 +0000 | [diff] [blame] | 158 | Elts[4] = BuildDescriptorBlockDecl(subBlockHasCopyDispose, subBlockSize, 0, 0); |
Mike Stump | 9d8c126 | 2009-03-06 18:42:23 +0000 | [diff] [blame] | 159 | |
Mike Stump | a7db9be | 2009-03-01 20:07:53 +0000 | [diff] [blame] | 160 | // Optimize to being a global block. |
| 161 | Elts[0] = CGM.getNSConcreteGlobalBlock(); |
| 162 | Elts[1] = llvm::ConstantInt::get(IntTy, flags|BLOCK_IS_GLOBAL); |
| 163 | |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 164 | C = llvm::ConstantStruct::get(Elts); |
| 165 | |
| 166 | char Name[32]; |
| 167 | sprintf(Name, "__block_holder_tmp_%d", CGM.getGlobalUniqueCount()); |
Owen Anderson | 96bcdd4 | 2009-07-08 01:29:18 +0000 | [diff] [blame] | 168 | C = new llvm::GlobalVariable(CGM.getModule().getContext(), |
| 169 | C->getType(), true, |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 170 | llvm::GlobalValue::InternalLinkage, |
| 171 | C, Name, &CGM.getModule()); |
| 172 | QualType BPT = BE->getType(); |
| 173 | C = llvm::ConstantExpr::getBitCast(C, ConvertType(BPT)); |
| 174 | return C; |
| 175 | } |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 176 | |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 177 | std::vector<const llvm::Type *> Types(5+subBlockDeclRefDecls.size()); |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 178 | for (int i=0; i<4; ++i) |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 179 | Types[i] = Elts[i]->getType(); |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 180 | Types[4] = PtrToInt8Ty; |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 181 | |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 182 | for (unsigned i=0; i < subBlockDeclRefDecls.size(); ++i) { |
| 183 | const Expr *E = subBlockDeclRefDecls[i]; |
| 184 | const BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(E); |
| 185 | QualType Ty = E->getType(); |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 186 | if (BDRE && BDRE->isByRef()) { |
| 187 | uint64_t Align = getContext().getDeclAlignInBytes(BDRE->getDecl()); |
| 188 | Types[i+5] = llvm::PointerType::get(BuildByRefType(Ty, Align), 0); |
| 189 | } else |
| 190 | Types[i+5] = ConvertType(Ty); |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 191 | } |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 192 | |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 193 | llvm::StructType *Ty = llvm::StructType::get(Types, true); |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 194 | |
| 195 | llvm::AllocaInst *A = CreateTempAlloca(Ty); |
| 196 | A->setAlignment(subBlockAlign); |
| 197 | V = A; |
| 198 | |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 199 | std::vector<HelperInfo> NoteForHelper(subBlockDeclRefDecls.size()); |
| 200 | int helpersize = 0; |
| 201 | |
| 202 | for (unsigned i=0; i<4; ++i) |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 203 | Builder.CreateStore(Elts[i], Builder.CreateStructGEP(V, i, "block.tmp")); |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 204 | |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 205 | for (unsigned i=0; i < subBlockDeclRefDecls.size(); ++i) |
| 206 | { |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 207 | // FIXME: Push const down. |
| 208 | Expr *E = const_cast<Expr*>(subBlockDeclRefDecls[i]); |
| 209 | DeclRefExpr *DR; |
| 210 | ValueDecl *VD; |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 211 | |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 212 | DR = dyn_cast<DeclRefExpr>(E); |
| 213 | // Skip padding. |
| 214 | if (DR) continue; |
| 215 | |
| 216 | BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(E); |
| 217 | VD = BDRE->getDecl(); |
| 218 | |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 219 | llvm::Value* Addr = Builder.CreateStructGEP(V, i+5, "tmp"); |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 220 | NoteForHelper[helpersize].index = i+5; |
| 221 | NoteForHelper[helpersize].RequiresCopying = BlockRequiresCopying(VD->getType()); |
| 222 | NoteForHelper[helpersize].flag |
| 223 | = VD->getType()->isBlockPointerType() ? BLOCK_FIELD_IS_BLOCK : BLOCK_FIELD_IS_OBJECT; |
| 224 | |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 225 | if (LocalDeclMap[VD]) { |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 226 | if (BDRE->isByRef()) { |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 227 | NoteForHelper[helpersize].flag = BLOCK_FIELD_IS_BYREF | |
Mike Stump | 0a33ed3 | 2009-03-07 06:04:31 +0000 | [diff] [blame] | 228 | // FIXME: Someone double check this. |
| 229 | (VD->getType().isObjCGCWeak() ? BLOCK_FIELD_IS_WEAK : 0); |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 230 | const llvm::Type *Ty = Types[i+5]; |
| 231 | llvm::Value *Loc = LocalDeclMap[VD]; |
| 232 | Loc = Builder.CreateStructGEP(Loc, 1, "forwarding"); |
| 233 | Loc = Builder.CreateLoad(Loc, false); |
| 234 | Loc = Builder.CreateBitCast(Loc, Ty); |
| 235 | Builder.CreateStore(Loc, Addr); |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 236 | ++helpersize; |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 237 | continue; |
| 238 | } else |
| 239 | E = new (getContext()) DeclRefExpr (cast<NamedDecl>(VD), |
| 240 | VD->getType(), SourceLocation(), |
| 241 | false, false); |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 242 | } |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 243 | if (BDRE->isByRef()) { |
Mike Stump | 29782de | 2009-03-21 21:00:35 +0000 | [diff] [blame] | 244 | NoteForHelper[helpersize].flag = BLOCK_FIELD_IS_BYREF | |
| 245 | // FIXME: Someone double check this. |
| 246 | (VD->getType().isObjCGCWeak() ? BLOCK_FIELD_IS_WEAK : 0); |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 247 | E = new (getContext()) |
| 248 | UnaryOperator(E, UnaryOperator::AddrOf, |
| 249 | getContext().getPointerType(E->getType()), |
| 250 | SourceLocation()); |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 251 | } |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 252 | ++helpersize; |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 253 | |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 254 | RValue r = EmitAnyExpr(E, Addr, false); |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 255 | if (r.isScalar()) { |
| 256 | llvm::Value *Loc = r.getScalarVal(); |
| 257 | const llvm::Type *Ty = Types[i+5]; |
| 258 | if (BDRE->isByRef()) { |
Mike Stump | f13eac1 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 259 | // E is now the address of the value field, instead, we want the |
| 260 | // address of the actual ByRef struct. We optimize this slightly |
| 261 | // compared to gcc by not grabbing the forwarding slot as this must |
| 262 | // be done during Block_copy for us, and we can postpone the work |
| 263 | // until then. |
| 264 | uint64_t offset = BlockDecls[BDRE->getDecl()]; |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 265 | |
Mike Stump | f13eac1 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 266 | llvm::Value *BlockLiteral = LoadBlockStruct(); |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 267 | |
Mike Stump | f13eac1 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 268 | Loc = Builder.CreateGEP(BlockLiteral, |
| 269 | llvm::ConstantInt::get(llvm::Type::Int64Ty, |
| 270 | offset), |
| 271 | "block.literal"); |
| 272 | Ty = llvm::PointerType::get(Ty, 0); |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 273 | Loc = Builder.CreateBitCast(Loc, Ty); |
Mike Stump | f13eac1 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 274 | Loc = Builder.CreateLoad(Loc, false); |
| 275 | // Loc = Builder.CreateBitCast(Loc, Ty); |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 276 | } |
| 277 | Builder.CreateStore(Loc, Addr); |
| 278 | } else if (r.isComplex()) |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 279 | // FIXME: implement |
| 280 | ErrorUnsupported(BE, "complex in block literal"); |
| 281 | else if (r.isAggregate()) |
| 282 | ; // Already created into the destination |
| 283 | else |
| 284 | assert (0 && "bad block variable"); |
| 285 | // FIXME: Ensure that the offset created by the backend for |
| 286 | // the struct matches the previously computed offset in BlockDecls. |
| 287 | } |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 288 | NoteForHelper.resize(helpersize); |
Mike Stump | 9d8c126 | 2009-03-06 18:42:23 +0000 | [diff] [blame] | 289 | |
| 290 | // __descriptor |
Mike Stump | 68bb7a2 | 2009-03-25 17:58:24 +0000 | [diff] [blame] | 291 | llvm::Value *Descriptor = BuildDescriptorBlockDecl(subBlockHasCopyDispose, |
| 292 | subBlockSize, Ty, |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 293 | &NoteForHelper); |
| 294 | Descriptor = Builder.CreateBitCast(Descriptor, PtrToInt8Ty); |
| 295 | Builder.CreateStore(Descriptor, Builder.CreateStructGEP(V, 4, "block.tmp")); |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 296 | } |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 297 | |
Mike Stump | d55240e | 2009-02-19 01:01:04 +0000 | [diff] [blame] | 298 | QualType BPT = BE->getType(); |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 299 | return Builder.CreateBitCast(V, ConvertType(BPT)); |
Mike Stump | b95bc00 | 2009-02-13 16:19:19 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | |
Mike Stump | 1f010b5 | 2009-03-04 18:17:45 +0000 | [diff] [blame] | 303 | const llvm::Type *BlockModule::getBlockDescriptorType() { |
Mike Stump | 95e5480 | 2009-02-13 15:16:56 +0000 | [diff] [blame] | 304 | if (BlockDescriptorType) |
| 305 | return BlockDescriptorType; |
| 306 | |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 307 | const llvm::Type *UnsignedLongTy = |
Mike Stump | 95e5480 | 2009-02-13 15:16:56 +0000 | [diff] [blame] | 308 | getTypes().ConvertType(getContext().UnsignedLongTy); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 309 | |
Mike Stump | 95e5480 | 2009-02-13 15:16:56 +0000 | [diff] [blame] | 310 | // struct __block_descriptor { |
| 311 | // unsigned long reserved; |
| 312 | // unsigned long block_size; |
| 313 | // }; |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 314 | BlockDescriptorType = llvm::StructType::get(UnsignedLongTy, |
| 315 | UnsignedLongTy, |
Mike Stump | 95e5480 | 2009-02-13 15:16:56 +0000 | [diff] [blame] | 316 | NULL); |
| 317 | |
| 318 | getModule().addTypeName("struct.__block_descriptor", |
| 319 | BlockDescriptorType); |
| 320 | |
| 321 | return BlockDescriptorType; |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Mike Stump | 1f010b5 | 2009-03-04 18:17:45 +0000 | [diff] [blame] | 324 | const llvm::Type *BlockModule::getGenericBlockLiteralType() { |
Mike Stump | 0dffa46 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 325 | if (GenericBlockLiteralType) |
| 326 | return GenericBlockLiteralType; |
| 327 | |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 328 | const llvm::Type *BlockDescPtrTy = |
Mike Stump | 0dffa46 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 329 | llvm::PointerType::getUnqual(getBlockDescriptorType()); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 330 | |
Mike Stump | 7b7cd8b | 2009-02-13 16:01:35 +0000 | [diff] [blame] | 331 | const llvm::IntegerType *IntTy = cast<llvm::IntegerType>( |
| 332 | getTypes().ConvertType(getContext().IntTy)); |
| 333 | |
Mike Stump | 0dffa46 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 334 | // struct __block_literal_generic { |
Mike Stump | d55240e | 2009-02-19 01:01:04 +0000 | [diff] [blame] | 335 | // void *__isa; |
| 336 | // int __flags; |
| 337 | // int __reserved; |
| 338 | // void (*__invoke)(void *); |
| 339 | // struct __block_descriptor *__descriptor; |
Mike Stump | 0dffa46 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 340 | // }; |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 341 | GenericBlockLiteralType = llvm::StructType::get(PtrToInt8Ty, |
Mike Stump | 7b7cd8b | 2009-02-13 16:01:35 +0000 | [diff] [blame] | 342 | IntTy, |
| 343 | IntTy, |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 344 | PtrToInt8Ty, |
Mike Stump | 0dffa46 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 345 | BlockDescPtrTy, |
| 346 | NULL); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 347 | |
Mike Stump | 0dffa46 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 348 | getModule().addTypeName("struct.__block_literal_generic", |
| 349 | GenericBlockLiteralType); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 350 | |
Mike Stump | 0dffa46 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 351 | return GenericBlockLiteralType; |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Mike Stump | 1f010b5 | 2009-03-04 18:17:45 +0000 | [diff] [blame] | 354 | const llvm::Type *BlockModule::getGenericExtendedBlockLiteralType() { |
Mike Stump | d55240e | 2009-02-19 01:01:04 +0000 | [diff] [blame] | 355 | if (GenericExtendedBlockLiteralType) |
| 356 | return GenericExtendedBlockLiteralType; |
| 357 | |
Mike Stump | d55240e | 2009-02-19 01:01:04 +0000 | [diff] [blame] | 358 | const llvm::Type *BlockDescPtrTy = |
| 359 | llvm::PointerType::getUnqual(getBlockDescriptorType()); |
| 360 | |
| 361 | const llvm::IntegerType *IntTy = cast<llvm::IntegerType>( |
| 362 | getTypes().ConvertType(getContext().IntTy)); |
| 363 | |
| 364 | // struct __block_literal_generic { |
| 365 | // void *__isa; |
| 366 | // int __flags; |
| 367 | // int __reserved; |
| 368 | // void (*__invoke)(void *); |
| 369 | // struct __block_descriptor *__descriptor; |
| 370 | // void *__copy_func_helper_decl; |
| 371 | // void *__destroy_func_decl; |
| 372 | // }; |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 373 | GenericExtendedBlockLiteralType = llvm::StructType::get(PtrToInt8Ty, |
Mike Stump | d55240e | 2009-02-19 01:01:04 +0000 | [diff] [blame] | 374 | IntTy, |
| 375 | IntTy, |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 376 | PtrToInt8Ty, |
Mike Stump | d55240e | 2009-02-19 01:01:04 +0000 | [diff] [blame] | 377 | BlockDescPtrTy, |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 378 | PtrToInt8Ty, |
| 379 | PtrToInt8Ty, |
Mike Stump | d55240e | 2009-02-19 01:01:04 +0000 | [diff] [blame] | 380 | NULL); |
| 381 | |
| 382 | getModule().addTypeName("struct.__block_literal_extended_generic", |
| 383 | GenericExtendedBlockLiteralType); |
| 384 | |
| 385 | return GenericExtendedBlockLiteralType; |
| 386 | } |
| 387 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 388 | RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) { |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 389 | const BlockPointerType *BPT = |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 390 | E->getCallee()->getType()->getAsBlockPointerType(); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 391 | |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 392 | llvm::Value *Callee = EmitScalarExpr(E->getCallee()); |
| 393 | |
| 394 | // Get a pointer to the generic block literal. |
| 395 | const llvm::Type *BlockLiteralTy = |
Mike Stump | 0dffa46 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 396 | llvm::PointerType::getUnqual(CGM.getGenericBlockLiteralType()); |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 397 | |
| 398 | // Bitcast the callee to a block literal. |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 399 | llvm::Value *BlockLiteral = |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 400 | Builder.CreateBitCast(Callee, BlockLiteralTy, "block.literal"); |
| 401 | |
| 402 | // Get the function pointer from the literal. |
| 403 | llvm::Value *FuncPtr = Builder.CreateStructGEP(BlockLiteral, 3, "tmp"); |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 404 | |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 405 | BlockLiteral = |
| 406 | Builder.CreateBitCast(BlockLiteral, |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 407 | llvm::PointerType::getUnqual(llvm::Type::Int8Ty), |
| 408 | "tmp"); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 409 | |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 410 | // Add the block literal. |
| 411 | QualType VoidPtrTy = getContext().getPointerType(getContext().VoidTy); |
| 412 | CallArgList Args; |
| 413 | Args.push_back(std::make_pair(RValue::get(BlockLiteral), VoidPtrTy)); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 414 | |
Anders Carlsson | 6759c4d | 2009-04-08 23:13:16 +0000 | [diff] [blame] | 415 | QualType FnType = BPT->getPointeeType(); |
| 416 | |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 417 | // And the rest of the arguments. |
Anders Carlsson | 6759c4d | 2009-04-08 23:13:16 +0000 | [diff] [blame] | 418 | EmitCallArgs(Args, FnType->getAsFunctionProtoType(), |
| 419 | E->arg_begin(), E->arg_end()); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 420 | |
Anders Carlsson | 417d983 | 2009-04-07 22:10:22 +0000 | [diff] [blame] | 421 | // Load the function. |
| 422 | llvm::Value *Func = Builder.CreateLoad(FuncPtr, false, "tmp"); |
| 423 | |
Anders Carlsson | ea92a92 | 2009-04-08 02:55:55 +0000 | [diff] [blame] | 424 | QualType ResultType = FnType->getAsFunctionType()->getResultType(); |
| 425 | |
| 426 | const CGFunctionInfo &FnInfo = |
| 427 | CGM.getTypes().getFunctionInfo(ResultType, Args); |
Anders Carlsson | 417d983 | 2009-04-07 22:10:22 +0000 | [diff] [blame] | 428 | |
| 429 | // Cast the function pointer to the right type. |
| 430 | const llvm::Type *BlockFTy = |
Anders Carlsson | ea92a92 | 2009-04-08 02:55:55 +0000 | [diff] [blame] | 431 | CGM.getTypes().GetFunctionType(FnInfo, false); |
Anders Carlsson | 417d983 | 2009-04-07 22:10:22 +0000 | [diff] [blame] | 432 | |
| 433 | const llvm::Type *BlockFTyPtr = llvm::PointerType::getUnqual(BlockFTy); |
| 434 | Func = Builder.CreateBitCast(Func, BlockFTyPtr); |
| 435 | |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 436 | // And call the block. |
Anders Carlsson | 3f03b81 | 2009-04-07 00:20:24 +0000 | [diff] [blame] | 437 | return EmitCall(FnInfo, Func, Args); |
Anders Carlsson | d2a889b | 2009-02-12 00:39:25 +0000 | [diff] [blame] | 438 | } |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 439 | |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 440 | llvm::Value *CodeGenFunction::GetAddrOfBlockDecl(const BlockDeclRefExpr *E) { |
| 441 | uint64_t &offset = BlockDecls[E->getDecl()]; |
| 442 | |
| 443 | const llvm::Type *Ty; |
| 444 | Ty = CGM.getTypes().ConvertType(E->getDecl()->getType()); |
| 445 | |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 446 | // See if we have already allocated an offset for this variable. |
| 447 | if (offset == 0) { |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 448 | // Don't run the expensive check, unless we have to. |
| 449 | if (!BlockHasCopyDispose && BlockRequiresCopying(E->getType())) |
| 450 | BlockHasCopyDispose = true; |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 451 | // if not, allocate one now. |
| 452 | offset = getBlockOffset(E); |
| 453 | } |
| 454 | |
| 455 | llvm::Value *BlockLiteral = LoadBlockStruct(); |
| 456 | llvm::Value *V = Builder.CreateGEP(BlockLiteral, |
| 457 | llvm::ConstantInt::get(llvm::Type::Int64Ty, |
| 458 | offset), |
Mike Stump | f13eac1 | 2009-03-04 22:48:06 +0000 | [diff] [blame] | 459 | "block.literal"); |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 460 | if (E->isByRef()) { |
| 461 | bool needsCopyDispose = BlockRequiresCopying(E->getType()); |
| 462 | uint64_t Align = getContext().getDeclAlignInBytes(E->getDecl()); |
| 463 | const llvm::Type *PtrStructTy |
| 464 | = llvm::PointerType::get(BuildByRefType(E->getType(), Align), 0); |
Mike Stump | 29782de | 2009-03-21 21:00:35 +0000 | [diff] [blame] | 465 | // The block literal will need a copy/destroy helper. |
| 466 | BlockHasCopyDispose = true; |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 467 | Ty = PtrStructTy; |
| 468 | Ty = llvm::PointerType::get(Ty, 0); |
| 469 | V = Builder.CreateBitCast(V, Ty); |
| 470 | V = Builder.CreateLoad(V, false); |
| 471 | V = Builder.CreateStructGEP(V, 1, "forwarding"); |
| 472 | V = Builder.CreateLoad(V, false); |
| 473 | V = Builder.CreateBitCast(V, PtrStructTy); |
| 474 | V = Builder.CreateStructGEP(V, needsCopyDispose*2 + 4, "x"); |
| 475 | } else { |
| 476 | Ty = llvm::PointerType::get(Ty, 0); |
| 477 | V = Builder.CreateBitCast(V, Ty); |
| 478 | } |
| 479 | return V; |
| 480 | } |
| 481 | |
Mike Stump | fc5e6de | 2009-03-20 21:53:12 +0000 | [diff] [blame] | 482 | void CodeGenFunction::BlockForwardSelf() { |
| 483 | const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl); |
| 484 | ImplicitParamDecl *SelfDecl = OMD->getSelfDecl(); |
| 485 | llvm::Value *&DMEntry = LocalDeclMap[SelfDecl]; |
| 486 | if (DMEntry) |
| 487 | return; |
| 488 | // FIXME - Eliminate BlockDeclRefExprs, clients don't need/want to care |
| 489 | BlockDeclRefExpr *BDRE = new (getContext()) |
| 490 | BlockDeclRefExpr(SelfDecl, |
| 491 | SelfDecl->getType(), SourceLocation(), false); |
| 492 | DMEntry = GetAddrOfBlockDecl(BDRE); |
| 493 | } |
| 494 | |
Mike Stump | 084ba46 | 2009-02-14 22:16:35 +0000 | [diff] [blame] | 495 | llvm::Constant * |
Mike Stump | d6d0ebe | 2009-03-04 18:47:42 +0000 | [diff] [blame] | 496 | BlockModule::GetAddrOfGlobalBlock(const BlockExpr *BE, const char * n) { |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 497 | // Generate the block descriptor. |
| 498 | const llvm::Type *UnsignedLongTy = Types.ConvertType(Context.UnsignedLongTy); |
Mike Stump | 7b7cd8b | 2009-02-13 16:01:35 +0000 | [diff] [blame] | 499 | const llvm::IntegerType *IntTy = cast<llvm::IntegerType>( |
| 500 | getTypes().ConvertType(getContext().IntTy)); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 501 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 502 | llvm::Constant *DescriptorFields[2]; |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 503 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 504 | // Reserved |
| 505 | DescriptorFields[0] = llvm::Constant::getNullValue(UnsignedLongTy); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 506 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 507 | // Block literal size. For global blocks we just use the size of the generic |
| 508 | // block literal struct. |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 509 | uint64_t BlockLiteralSize = |
Mike Stump | 0dffa46 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 510 | TheTargetData.getTypeStoreSizeInBits(getGenericBlockLiteralType()) / 8; |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 511 | DescriptorFields[1] = llvm::ConstantInt::get(UnsignedLongTy,BlockLiteralSize); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 512 | |
| 513 | llvm::Constant *DescriptorStruct = |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 514 | llvm::ConstantStruct::get(&DescriptorFields[0], 2); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 515 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 516 | llvm::GlobalVariable *Descriptor = |
Owen Anderson | 96bcdd4 | 2009-07-08 01:29:18 +0000 | [diff] [blame] | 517 | new llvm::GlobalVariable(getModule().getContext(), |
| 518 | DescriptorStruct->getType(), true, |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 519 | llvm::GlobalVariable::InternalLinkage, |
| 520 | DescriptorStruct, "__block_descriptor_global", |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 521 | &getModule()); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 522 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 523 | // Generate the constants for the block literal. |
| 524 | llvm::Constant *LiteralFields[5]; |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 525 | |
Mike Stump | 084ba46 | 2009-02-14 22:16:35 +0000 | [diff] [blame] | 526 | CodeGenFunction::BlockInfo Info(0, n); |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 527 | uint64_t subBlockSize, subBlockAlign; |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 528 | llvm::SmallVector<const Expr *, 8> subBlockDeclRefDecls; |
Daniel Dunbar | adaf35f | 2009-03-12 03:07:24 +0000 | [diff] [blame] | 529 | bool subBlockHasCopyDispose = false; |
Mike Stump | a20c59e | 2009-03-13 23:34:28 +0000 | [diff] [blame] | 530 | llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; |
Mike Stump | fca5da0 | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 531 | llvm::Function *Fn |
Mike Stump | fc5e6de | 2009-03-20 21:53:12 +0000 | [diff] [blame] | 532 | = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, 0, LocalDeclMap, |
Mike Stump | a20c59e | 2009-03-13 23:34:28 +0000 | [diff] [blame] | 533 | subBlockSize, |
Mike Stump | d6d0ebe | 2009-03-04 18:47:42 +0000 | [diff] [blame] | 534 | subBlockAlign, |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 535 | subBlockDeclRefDecls, |
| 536 | subBlockHasCopyDispose); |
Mike Stump | fca5da0 | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 537 | assert(subBlockSize == BlockLiteralSize |
| 538 | && "no imports allowed for global block"); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 539 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 540 | // isa |
Mike Stump | 5f87e9d | 2009-02-13 17:23:42 +0000 | [diff] [blame] | 541 | LiteralFields[0] = getNSConcreteGlobalBlock(); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 542 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 543 | // Flags |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 544 | LiteralFields[1] = |
Anders Carlsson | 63810c6 | 2009-03-01 21:09:29 +0000 | [diff] [blame] | 545 | llvm::ConstantInt::get(IntTy, BLOCK_IS_GLOBAL | BLOCK_HAS_DESCRIPTOR); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 546 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 547 | // Reserved |
Mike Stump | 7b7cd8b | 2009-02-13 16:01:35 +0000 | [diff] [blame] | 548 | LiteralFields[2] = llvm::Constant::getNullValue(IntTy); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 549 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 550 | // Function |
| 551 | LiteralFields[3] = Fn; |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 552 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 553 | // Descriptor |
| 554 | LiteralFields[4] = Descriptor; |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 555 | |
| 556 | llvm::Constant *BlockLiteralStruct = |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 557 | llvm::ConstantStruct::get(&LiteralFields[0], 5); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 558 | |
| 559 | llvm::GlobalVariable *BlockLiteral = |
Owen Anderson | 96bcdd4 | 2009-07-08 01:29:18 +0000 | [diff] [blame] | 560 | new llvm::GlobalVariable(getModule().getContext(), |
| 561 | BlockLiteralStruct->getType(), true, |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 562 | llvm::GlobalVariable::InternalLinkage, |
| 563 | BlockLiteralStruct, "__block_literal_global", |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 564 | &getModule()); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 565 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 566 | return BlockLiteral; |
| 567 | } |
| 568 | |
Mike Stump | fca5da0 | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 569 | llvm::Value *CodeGenFunction::LoadBlockStruct() { |
| 570 | return Builder.CreateLoad(LocalDeclMap[getBlockStructDecl()], "self"); |
| 571 | } |
| 572 | |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 573 | llvm::Function * |
| 574 | CodeGenFunction::GenerateBlockFunction(const BlockExpr *BExpr, |
| 575 | const BlockInfo& Info, |
Mike Stump | fc5e6de | 2009-03-20 21:53:12 +0000 | [diff] [blame] | 576 | const Decl *OuterFuncDecl, |
Mike Stump | a20c59e | 2009-03-13 23:34:28 +0000 | [diff] [blame] | 577 | llvm::DenseMap<const Decl*, llvm::Value*> ldm, |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 578 | uint64_t &Size, |
| 579 | uint64_t &Align, |
| 580 | llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls, |
| 581 | bool &subBlockHasCopyDispose) { |
Devang Patel | 6ae64bb | 2009-04-15 21:51:44 +0000 | [diff] [blame] | 582 | |
| 583 | // Check if we should generate debug info for this block. |
| 584 | if (CGM.getDebugInfo()) |
| 585 | DebugInfo = CGM.getDebugInfo(); |
| 586 | |
Mike Stump | a20c59e | 2009-03-13 23:34:28 +0000 | [diff] [blame] | 587 | // Arrange for local static and local extern declarations to appear |
| 588 | // to be local to this function as well, as they are directly referenced |
| 589 | // in a block. |
| 590 | for (llvm::DenseMap<const Decl *, llvm::Value*>::iterator i = ldm.begin(); |
| 591 | i != ldm.end(); |
| 592 | ++i) { |
| 593 | const VarDecl *VD = dyn_cast<VarDecl>(i->first); |
| 594 | |
Daniel Dunbar | 644c15e | 2009-04-14 02:25:56 +0000 | [diff] [blame] | 595 | if (VD->getStorageClass() == VarDecl::Static || VD->hasExternalStorage()) |
Mike Stump | a20c59e | 2009-03-13 23:34:28 +0000 | [diff] [blame] | 596 | LocalDeclMap[VD] = i->second; |
| 597 | } |
| 598 | |
Eli Friedman | 584abaf | 2009-03-28 03:24:54 +0000 | [diff] [blame] | 599 | // FIXME: We need to rearrange the code for copy/dispose so we have this |
| 600 | // sooner, so we can calculate offsets correctly. |
| 601 | if (!BlockHasCopyDispose) |
| 602 | BlockOffset = CGM.getTargetData() |
| 603 | .getTypeStoreSizeInBits(CGM.getGenericBlockLiteralType()) / 8; |
| 604 | else |
| 605 | BlockOffset = CGM.getTargetData() |
| 606 | .getTypeStoreSizeInBits(CGM.getGenericExtendedBlockLiteralType()) / 8; |
| 607 | BlockAlign = getContext().getTypeAlign(getContext().VoidPtrTy) / 8; |
| 608 | |
Fariborz Jahanian | 3413b1a | 2009-04-11 17:55:15 +0000 | [diff] [blame] | 609 | const FunctionType *BlockFunctionType = BExpr->getFunctionType(); |
| 610 | QualType ResultType; |
| 611 | bool IsVariadic; |
Fariborz Jahanian | de6a649 | 2009-04-11 18:54:57 +0000 | [diff] [blame] | 612 | if (const FunctionProtoType *FTy = |
| 613 | dyn_cast<FunctionProtoType>(BlockFunctionType)) { |
Fariborz Jahanian | 3413b1a | 2009-04-11 17:55:15 +0000 | [diff] [blame] | 614 | ResultType = FTy->getResultType(); |
| 615 | IsVariadic = FTy->isVariadic(); |
| 616 | } |
| 617 | else { |
| 618 | // K&R style block. |
| 619 | ResultType = BlockFunctionType->getResultType(); |
| 620 | IsVariadic = false; |
| 621 | } |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 622 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 623 | FunctionArgList Args; |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 624 | |
Chris Lattner | 8130e7f | 2009-02-28 19:01:03 +0000 | [diff] [blame] | 625 | const BlockDecl *BD = BExpr->getBlockDecl(); |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 626 | |
| 627 | // FIXME: This leaks |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 628 | ImplicitParamDecl *SelfDecl = |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 629 | ImplicitParamDecl::Create(getContext(), 0, |
| 630 | SourceLocation(), 0, |
| 631 | getContext().getPointerType(getContext().VoidTy)); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 632 | |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 633 | Args.push_back(std::make_pair(SelfDecl, SelfDecl->getType())); |
Mike Stump | fca5da0 | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 634 | BlockStructDecl = SelfDecl; |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 635 | |
Steve Naroff | 494cb0f | 2009-03-13 16:56:44 +0000 | [diff] [blame] | 636 | for (BlockDecl::param_const_iterator i = BD->param_begin(), |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 637 | e = BD->param_end(); i != e; ++i) |
Mike Stump | 459207f | 2009-02-17 23:25:52 +0000 | [diff] [blame] | 638 | Args.push_back(std::make_pair(*i, (*i)->getType())); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 639 | |
| 640 | const CGFunctionInfo &FI = |
Fariborz Jahanian | 3413b1a | 2009-04-11 17:55:15 +0000 | [diff] [blame] | 641 | CGM.getTypes().getFunctionInfo(ResultType, Args); |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 642 | |
Mike Stump | 084ba46 | 2009-02-14 22:16:35 +0000 | [diff] [blame] | 643 | std::string Name = std::string("__") + Info.Name + "_block_invoke_"; |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 644 | CodeGenTypes &Types = CGM.getTypes(); |
Fariborz Jahanian | 3413b1a | 2009-04-11 17:55:15 +0000 | [diff] [blame] | 645 | const llvm::FunctionType *LTy = Types.GetFunctionType(FI, IsVariadic); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 646 | |
| 647 | llvm::Function *Fn = |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 648 | llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage, |
| 649 | Name, |
| 650 | &CGM.getModule()); |
Mike Stump | c4ae963 | 2009-02-13 15:32:32 +0000 | [diff] [blame] | 651 | |
Daniel Dunbar | 5b90ae1 | 2009-04-17 00:48:04 +0000 | [diff] [blame] | 652 | CGM.SetInternalFunctionAttributes(BD, Fn, FI); |
| 653 | |
Chris Lattner | ab3d373 | 2009-04-23 07:18:56 +0000 | [diff] [blame] | 654 | StartFunction(BD, ResultType, Fn, Args, |
Chris Lattner | 8130e7f | 2009-02-28 19:01:03 +0000 | [diff] [blame] | 655 | BExpr->getBody()->getLocEnd()); |
Chris Lattner | ab3d373 | 2009-04-23 07:18:56 +0000 | [diff] [blame] | 656 | CurFuncDecl = OuterFuncDecl; |
Chris Lattner | f6279ae | 2009-04-23 05:30:27 +0000 | [diff] [blame] | 657 | CurCodeDecl = BD; |
Chris Lattner | 8130e7f | 2009-02-28 19:01:03 +0000 | [diff] [blame] | 658 | EmitStmt(BExpr->getBody()); |
| 659 | FinishFunction(cast<CompoundStmt>(BExpr->getBody())->getRBracLoc()); |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 660 | |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 661 | // The runtime needs a minimum alignment of a void *. |
| 662 | uint64_t MinAlign = getContext().getTypeAlign(getContext().VoidPtrTy) / 8; |
| 663 | BlockOffset = llvm::RoundUpToAlignment(BlockOffset, MinAlign); |
| 664 | |
Mike Stump | fca5da0 | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 665 | Size = BlockOffset; |
Mike Stump | f171182 | 2009-02-25 23:33:13 +0000 | [diff] [blame] | 666 | Align = BlockAlign; |
| 667 | subBlockDeclRefDecls = BlockDeclRefDecls; |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 668 | subBlockHasCopyDispose |= BlockHasCopyDispose; |
Anders Carlsson | 1f1cd39 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 669 | return Fn; |
| 670 | } |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 671 | |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 672 | uint64_t BlockFunction::getBlockOffset(const BlockDeclRefExpr *BDRE) { |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 673 | const ValueDecl *D = dyn_cast<ValueDecl>(BDRE->getDecl()); |
| 674 | |
| 675 | uint64_t Size = getContext().getTypeSize(D->getType()) / 8; |
| 676 | uint64_t Align = getContext().getDeclAlignInBytes(D); |
| 677 | |
| 678 | if (BDRE->isByRef()) { |
| 679 | Size = getContext().getTypeSize(getContext().VoidPtrTy) / 8; |
| 680 | Align = getContext().getTypeAlign(getContext().VoidPtrTy) / 8; |
| 681 | } |
| 682 | |
| 683 | assert ((Align > 0) && "alignment must be 1 byte or more"); |
| 684 | |
| 685 | uint64_t OldOffset = BlockOffset; |
| 686 | |
| 687 | // Ensure proper alignment, even if it means we have to have a gap |
| 688 | BlockOffset = llvm::RoundUpToAlignment(BlockOffset, Align); |
| 689 | BlockAlign = std::max(Align, BlockAlign); |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 690 | |
Mike Stump | 2b6933f | 2009-02-28 09:07:16 +0000 | [diff] [blame] | 691 | uint64_t Pad = BlockOffset - OldOffset; |
| 692 | if (Pad) { |
| 693 | llvm::ArrayType::get(llvm::Type::Int8Ty, Pad); |
| 694 | QualType PadTy = getContext().getConstantArrayType(getContext().CharTy, |
| 695 | llvm::APInt(32, Pad), |
| 696 | ArrayType::Normal, 0); |
| 697 | ValueDecl *PadDecl = VarDecl::Create(getContext(), 0, SourceLocation(), |
| 698 | 0, QualType(PadTy), VarDecl::None, |
| 699 | SourceLocation()); |
| 700 | Expr *E; |
| 701 | E = new (getContext()) DeclRefExpr(PadDecl, PadDecl->getType(), |
| 702 | SourceLocation(), false, false); |
| 703 | BlockDeclRefDecls.push_back(E); |
| 704 | } |
| 705 | BlockDeclRefDecls.push_back(BDRE); |
| 706 | |
| 707 | BlockOffset += Size; |
| 708 | return BlockOffset-Size; |
| 709 | } |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 710 | |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 711 | llvm::Constant *BlockFunction:: |
| 712 | GenerateCopyHelperFunction(bool BlockHasCopyDispose, const llvm::StructType *T, |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 713 | std::vector<HelperInfo> *NoteForHelperp) { |
Mike Stump | ecd7942 | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 714 | QualType R = getContext().VoidTy; |
| 715 | |
| 716 | FunctionArgList Args; |
| 717 | // FIXME: This leaks |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 718 | ImplicitParamDecl *Dst = |
| 719 | ImplicitParamDecl::Create(getContext(), 0, SourceLocation(), 0, |
| 720 | getContext().getPointerType(getContext().VoidTy)); |
| 721 | Args.push_back(std::make_pair(Dst, Dst->getType())); |
Mike Stump | ecd7942 | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 722 | ImplicitParamDecl *Src = |
| 723 | ImplicitParamDecl::Create(getContext(), 0, SourceLocation(), 0, |
| 724 | getContext().getPointerType(getContext().VoidTy)); |
Mike Stump | ecd7942 | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 725 | Args.push_back(std::make_pair(Src, Src->getType())); |
| 726 | |
| 727 | const CGFunctionInfo &FI = |
| 728 | CGM.getTypes().getFunctionInfo(R, Args); |
| 729 | |
Mike Stump | c32f9c1 | 2009-06-05 23:26:36 +0000 | [diff] [blame] | 730 | // FIXME: We'd like to put these into a mergable by content, with |
| 731 | // internal linkage. |
Mike Stump | ecd7942 | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 732 | std::string Name = std::string("__copy_helper_block_"); |
| 733 | CodeGenTypes &Types = CGM.getTypes(); |
| 734 | const llvm::FunctionType *LTy = Types.GetFunctionType(FI, false); |
| 735 | |
| 736 | llvm::Function *Fn = |
| 737 | llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage, |
| 738 | Name, |
| 739 | &CGM.getModule()); |
| 740 | |
| 741 | IdentifierInfo *II |
| 742 | = &CGM.getContext().Idents.get("__copy_helper_block_"); |
| 743 | |
| 744 | FunctionDecl *FD = FunctionDecl::Create(getContext(), |
| 745 | getContext().getTranslationUnitDecl(), |
| 746 | SourceLocation(), II, R, |
| 747 | FunctionDecl::Static, false, |
| 748 | true); |
| 749 | CGF.StartFunction(FD, R, Fn, Args, SourceLocation()); |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 750 | |
| 751 | llvm::Value *SrcObj = CGF.GetAddrOfLocalVar(Src); |
| 752 | llvm::Type *PtrPtrT; |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 753 | |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 754 | if (NoteForHelperp) { |
| 755 | std::vector<HelperInfo> &NoteForHelper = *NoteForHelperp; |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 756 | |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 757 | PtrPtrT = llvm::PointerType::get(llvm::PointerType::get(T, 0), 0); |
| 758 | SrcObj = Builder.CreateBitCast(SrcObj, PtrPtrT); |
| 759 | SrcObj = Builder.CreateLoad(SrcObj); |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 760 | |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 761 | llvm::Value *DstObj = CGF.GetAddrOfLocalVar(Dst); |
Mike Stump | b71fa97 | 2009-04-15 22:11:36 +0000 | [diff] [blame] | 762 | llvm::Type *PtrPtrT; |
| 763 | PtrPtrT = llvm::PointerType::get(llvm::PointerType::get(T, 0), 0); |
| 764 | DstObj = Builder.CreateBitCast(DstObj, PtrPtrT); |
| 765 | DstObj = Builder.CreateLoad(DstObj); |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 766 | |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 767 | for (unsigned i=0; i < NoteForHelper.size(); ++i) { |
| 768 | int flag = NoteForHelper[i].flag; |
| 769 | int index = NoteForHelper[i].index; |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 770 | |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 771 | if ((NoteForHelper[i].flag & BLOCK_FIELD_IS_BYREF) |
| 772 | || NoteForHelper[i].RequiresCopying) { |
| 773 | llvm::Value *Srcv = SrcObj; |
| 774 | Srcv = Builder.CreateStructGEP(Srcv, index); |
| 775 | Srcv = Builder.CreateBitCast(Srcv, |
| 776 | llvm::PointerType::get(PtrToInt8Ty, 0)); |
| 777 | Srcv = Builder.CreateLoad(Srcv); |
| 778 | |
| 779 | llvm::Value *Dstv = Builder.CreateStructGEP(DstObj, index); |
| 780 | Dstv = Builder.CreateBitCast(Dstv, PtrToInt8Ty); |
| 781 | |
| 782 | llvm::Value *N = llvm::ConstantInt::get(llvm::Type::Int32Ty, flag); |
| 783 | llvm::Value *F = getBlockObjectAssign(); |
| 784 | Builder.CreateCall3(F, Dstv, Srcv, N); |
| 785 | } |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | |
Mike Stump | ecd7942 | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 789 | CGF.FinishFunction(); |
| 790 | |
| 791 | return llvm::ConstantExpr::getBitCast(Fn, PtrToInt8Ty); |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Mike Stump | 9d8c126 | 2009-03-06 18:42:23 +0000 | [diff] [blame] | 794 | llvm::Constant *BlockFunction:: |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 795 | GenerateDestroyHelperFunction(bool BlockHasCopyDispose, |
| 796 | const llvm::StructType* T, |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 797 | std::vector<HelperInfo> *NoteForHelperp) { |
Mike Stump | ecd7942 | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 798 | QualType R = getContext().VoidTy; |
| 799 | |
| 800 | FunctionArgList Args; |
| 801 | // FIXME: This leaks |
| 802 | ImplicitParamDecl *Src = |
| 803 | ImplicitParamDecl::Create(getContext(), 0, SourceLocation(), 0, |
| 804 | getContext().getPointerType(getContext().VoidTy)); |
| 805 | |
| 806 | Args.push_back(std::make_pair(Src, Src->getType())); |
| 807 | |
| 808 | const CGFunctionInfo &FI = |
| 809 | CGM.getTypes().getFunctionInfo(R, Args); |
| 810 | |
Mike Stump | c32f9c1 | 2009-06-05 23:26:36 +0000 | [diff] [blame] | 811 | // FIXME: We'd like to put these into a mergable by content, with |
| 812 | // internal linkage. |
Mike Stump | ecd7942 | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 813 | std::string Name = std::string("__destroy_helper_block_"); |
| 814 | CodeGenTypes &Types = CGM.getTypes(); |
| 815 | const llvm::FunctionType *LTy = Types.GetFunctionType(FI, false); |
| 816 | |
| 817 | llvm::Function *Fn = |
| 818 | llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage, |
| 819 | Name, |
| 820 | &CGM.getModule()); |
| 821 | |
| 822 | IdentifierInfo *II |
| 823 | = &CGM.getContext().Idents.get("__destroy_helper_block_"); |
| 824 | |
| 825 | FunctionDecl *FD = FunctionDecl::Create(getContext(), |
| 826 | getContext().getTranslationUnitDecl(), |
| 827 | SourceLocation(), II, R, |
| 828 | FunctionDecl::Static, false, |
| 829 | true); |
| 830 | CGF.StartFunction(FD, R, Fn, Args, SourceLocation()); |
Mike Stump | 05a6d4e | 2009-03-07 02:53:18 +0000 | [diff] [blame] | 831 | |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 832 | if (NoteForHelperp) { |
| 833 | std::vector<HelperInfo> &NoteForHelper = *NoteForHelperp; |
Mike Stump | 05a6d4e | 2009-03-07 02:53:18 +0000 | [diff] [blame] | 834 | |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 835 | llvm::Value *SrcObj = CGF.GetAddrOfLocalVar(Src); |
| 836 | llvm::Type *PtrPtrT; |
| 837 | PtrPtrT = llvm::PointerType::get(llvm::PointerType::get(T, 0), 0); |
| 838 | SrcObj = Builder.CreateBitCast(SrcObj, PtrPtrT); |
| 839 | SrcObj = Builder.CreateLoad(SrcObj); |
Mike Stump | 05a6d4e | 2009-03-07 02:53:18 +0000 | [diff] [blame] | 840 | |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 841 | for (unsigned i=0; i < NoteForHelper.size(); ++i) { |
| 842 | int flag = NoteForHelper[i].flag; |
| 843 | int index = NoteForHelper[i].index; |
Mike Stump | 05a6d4e | 2009-03-07 02:53:18 +0000 | [diff] [blame] | 844 | |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 845 | if ((NoteForHelper[i].flag & BLOCK_FIELD_IS_BYREF) |
| 846 | || NoteForHelper[i].RequiresCopying) { |
| 847 | llvm::Value *Srcv = SrcObj; |
| 848 | Srcv = Builder.CreateStructGEP(Srcv, index); |
| 849 | Srcv = Builder.CreateBitCast(Srcv, |
| 850 | llvm::PointerType::get(PtrToInt8Ty, 0)); |
| 851 | Srcv = Builder.CreateLoad(Srcv); |
| 852 | |
| 853 | BuildBlockRelease(Srcv, flag); |
| 854 | } |
Mike Stump | 05a6d4e | 2009-03-07 02:53:18 +0000 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | |
Mike Stump | ecd7942 | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 858 | CGF.FinishFunction(); |
| 859 | |
| 860 | return llvm::ConstantExpr::getBitCast(Fn, PtrToInt8Ty); |
| 861 | } |
| 862 | |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 863 | llvm::Constant *BlockFunction::BuildCopyHelper(const llvm::StructType *T, |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 864 | std::vector<HelperInfo> *NoteForHelper) { |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 865 | return CodeGenFunction(CGM).GenerateCopyHelperFunction(BlockHasCopyDispose, |
| 866 | T, NoteForHelper); |
Mike Stump | ecd7942 | 2009-03-06 01:33:24 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 869 | llvm::Constant *BlockFunction::BuildDestroyHelper(const llvm::StructType *T, |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 870 | std::vector<HelperInfo> *NoteForHelperp) { |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 871 | return CodeGenFunction(CGM).GenerateDestroyHelperFunction(BlockHasCopyDispose, |
Mike Stump | 2f9a426 | 2009-04-10 18:52:28 +0000 | [diff] [blame] | 872 | T, NoteForHelperp); |
Mike Stump | ad9605d | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 873 | } |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 874 | |
Mike Stump | 11973b6 | 2009-03-06 06:12:24 +0000 | [diff] [blame] | 875 | llvm::Constant *BlockFunction:: |
| 876 | GeneratebyrefCopyHelperFunction(const llvm::Type *T, int flag) { |
Mike Stump | f4b6234 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 877 | QualType R = getContext().VoidTy; |
| 878 | |
| 879 | FunctionArgList Args; |
| 880 | // FIXME: This leaks |
Mike Stump | 11973b6 | 2009-03-06 06:12:24 +0000 | [diff] [blame] | 881 | ImplicitParamDecl *Dst = |
| 882 | ImplicitParamDecl::Create(getContext(), 0, SourceLocation(), 0, |
| 883 | getContext().getPointerType(getContext().VoidTy)); |
| 884 | Args.push_back(std::make_pair(Dst, Dst->getType())); |
| 885 | |
| 886 | // FIXME: This leaks |
Mike Stump | f4b6234 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 887 | ImplicitParamDecl *Src = |
| 888 | ImplicitParamDecl::Create(getContext(), 0, SourceLocation(), 0, |
| 889 | getContext().getPointerType(getContext().VoidTy)); |
Mike Stump | f4b6234 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 890 | Args.push_back(std::make_pair(Src, Src->getType())); |
| 891 | |
| 892 | const CGFunctionInfo &FI = |
| 893 | CGM.getTypes().getFunctionInfo(R, Args); |
| 894 | |
| 895 | std::string Name = std::string("__Block_byref_id_object_copy_"); |
| 896 | CodeGenTypes &Types = CGM.getTypes(); |
| 897 | const llvm::FunctionType *LTy = Types.GetFunctionType(FI, false); |
| 898 | |
Mike Stump | c32f9c1 | 2009-06-05 23:26:36 +0000 | [diff] [blame] | 899 | // FIXME: We'd like to put these into a mergable by content, with |
| 900 | // internal linkage. |
Mike Stump | f4b6234 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 901 | llvm::Function *Fn = |
| 902 | llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage, |
| 903 | Name, |
| 904 | &CGM.getModule()); |
| 905 | |
| 906 | IdentifierInfo *II |
| 907 | = &CGM.getContext().Idents.get("__Block_byref_id_object_copy_"); |
| 908 | |
| 909 | FunctionDecl *FD = FunctionDecl::Create(getContext(), |
| 910 | getContext().getTranslationUnitDecl(), |
| 911 | SourceLocation(), II, R, |
| 912 | FunctionDecl::Static, false, |
| 913 | true); |
| 914 | CGF.StartFunction(FD, R, Fn, Args, SourceLocation()); |
Mike Stump | 11973b6 | 2009-03-06 06:12:24 +0000 | [diff] [blame] | 915 | |
| 916 | // dst->x |
| 917 | llvm::Value *V = CGF.GetAddrOfLocalVar(Dst); |
Mike Stump | b71fa97 | 2009-04-15 22:11:36 +0000 | [diff] [blame] | 918 | V = Builder.CreateBitCast(V, llvm::PointerType::get(T, 0)); |
| 919 | V = Builder.CreateLoad(V); |
Mike Stump | 11973b6 | 2009-03-06 06:12:24 +0000 | [diff] [blame] | 920 | V = Builder.CreateStructGEP(V, 6, "x"); |
| 921 | llvm::Value *DstObj = Builder.CreateBitCast(V, PtrToInt8Ty); |
| 922 | |
| 923 | // src->x |
| 924 | V = CGF.GetAddrOfLocalVar(Src); |
| 925 | V = Builder.CreateLoad(V); |
| 926 | V = Builder.CreateBitCast(V, T); |
| 927 | V = Builder.CreateStructGEP(V, 6, "x"); |
| 928 | V = Builder.CreateBitCast(V, llvm::PointerType::get(PtrToInt8Ty, 0)); |
| 929 | llvm::Value *SrcObj = Builder.CreateLoad(V); |
| 930 | |
| 931 | flag |= BLOCK_BYREF_CALLER; |
| 932 | |
| 933 | llvm::Value *N = llvm::ConstantInt::get(llvm::Type::Int32Ty, flag); |
| 934 | llvm::Value *F = getBlockObjectAssign(); |
| 935 | Builder.CreateCall3(F, DstObj, SrcObj, N); |
| 936 | |
Mike Stump | f4b6234 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 937 | CGF.FinishFunction(); |
| 938 | |
| 939 | return llvm::ConstantExpr::getBitCast(Fn, PtrToInt8Ty); |
| 940 | } |
| 941 | |
Mike Stump | 4a0e513 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 942 | llvm::Constant * |
| 943 | BlockFunction::GeneratebyrefDestroyHelperFunction(const llvm::Type *T, |
| 944 | int flag) { |
Mike Stump | f4b6234 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 945 | QualType R = getContext().VoidTy; |
| 946 | |
| 947 | FunctionArgList Args; |
| 948 | // FIXME: This leaks |
| 949 | ImplicitParamDecl *Src = |
| 950 | ImplicitParamDecl::Create(getContext(), 0, SourceLocation(), 0, |
| 951 | getContext().getPointerType(getContext().VoidTy)); |
| 952 | |
| 953 | Args.push_back(std::make_pair(Src, Src->getType())); |
| 954 | |
| 955 | const CGFunctionInfo &FI = |
| 956 | CGM.getTypes().getFunctionInfo(R, Args); |
| 957 | |
| 958 | std::string Name = std::string("__Block_byref_id_object_dispose_"); |
| 959 | CodeGenTypes &Types = CGM.getTypes(); |
| 960 | const llvm::FunctionType *LTy = Types.GetFunctionType(FI, false); |
| 961 | |
Mike Stump | c32f9c1 | 2009-06-05 23:26:36 +0000 | [diff] [blame] | 962 | // FIXME: We'd like to put these into a mergable by content, with |
| 963 | // internal linkage. |
Mike Stump | f4b6234 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 964 | llvm::Function *Fn = |
| 965 | llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage, |
| 966 | Name, |
| 967 | &CGM.getModule()); |
| 968 | |
| 969 | IdentifierInfo *II |
| 970 | = &CGM.getContext().Idents.get("__Block_byref_id_object_dispose_"); |
| 971 | |
| 972 | FunctionDecl *FD = FunctionDecl::Create(getContext(), |
| 973 | getContext().getTranslationUnitDecl(), |
| 974 | SourceLocation(), II, R, |
| 975 | FunctionDecl::Static, false, |
| 976 | true); |
| 977 | CGF.StartFunction(FD, R, Fn, Args, SourceLocation()); |
Mike Stump | 4a0e513 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 978 | |
| 979 | llvm::Value *V = CGF.GetAddrOfLocalVar(Src); |
Mike Stump | b71fa97 | 2009-04-15 22:11:36 +0000 | [diff] [blame] | 980 | V = Builder.CreateBitCast(V, llvm::PointerType::get(T, 0)); |
| 981 | V = Builder.CreateLoad(V); |
Mike Stump | 4a0e513 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 982 | V = Builder.CreateStructGEP(V, 6, "x"); |
Mike Stump | b71fa97 | 2009-04-15 22:11:36 +0000 | [diff] [blame] | 983 | V = Builder.CreateBitCast(V, llvm::PointerType::get(PtrToInt8Ty, 0)); |
| 984 | V = Builder.CreateLoad(V); |
Mike Stump | 4a0e513 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 985 | |
Mike Stump | 4a0e513 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 986 | flag |= BLOCK_BYREF_CALLER; |
| 987 | BuildBlockRelease(V, flag); |
Mike Stump | f4b6234 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 988 | CGF.FinishFunction(); |
| 989 | |
| 990 | return llvm::ConstantExpr::getBitCast(Fn, PtrToInt8Ty); |
| 991 | } |
| 992 | |
Mike Stump | 11973b6 | 2009-03-06 06:12:24 +0000 | [diff] [blame] | 993 | llvm::Constant *BlockFunction::BuildbyrefCopyHelper(const llvm::Type *T, |
Mike Stump | c32f9c1 | 2009-06-05 23:26:36 +0000 | [diff] [blame] | 994 | int flag, unsigned Align) { |
| 995 | // All alignments below that of pointer alignment collpase down to just |
| 996 | // pointer alignment, as we always have at least that much alignment to begin |
| 997 | // with. |
| 998 | Align /= unsigned(CGF.Target.getPointerAlign(0)/8); |
| 999 | // As an optimization, we only generate a single function of each kind we |
| 1000 | // might need. We need a different one for each alignment and for each |
| 1001 | // setting of flags. We mix Align and flag to get the kind. |
| 1002 | uint64_t kind = (uint64_t)Align*BLOCK_BYREF_CURRENT_MAX + flag; |
| 1003 | llvm::Constant *& Entry = CGM.AssignCache[kind]; |
| 1004 | if (Entry) |
| 1005 | return Entry; |
| 1006 | return Entry=CodeGenFunction(CGM).GeneratebyrefCopyHelperFunction(T, flag); |
Mike Stump | f4b6234 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Mike Stump | 4a0e513 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 1009 | llvm::Constant *BlockFunction::BuildbyrefDestroyHelper(const llvm::Type *T, |
Mike Stump | c32f9c1 | 2009-06-05 23:26:36 +0000 | [diff] [blame] | 1010 | int flag, |
| 1011 | unsigned Align) { |
| 1012 | // All alignments below that of pointer alignment collpase down to just |
| 1013 | // pointer alignment, as we always have at least that much alignment to begin |
| 1014 | // with. |
| 1015 | Align /= unsigned(CGF.Target.getPointerAlign(0)/8); |
| 1016 | // As an optimization, we only generate a single function of each kind we |
| 1017 | // might need. We need a different one for each alignment and for each |
| 1018 | // setting of flags. We mix Align and flag to get the kind. |
| 1019 | uint64_t kind = (uint64_t)Align*BLOCK_BYREF_CURRENT_MAX + flag; |
| 1020 | llvm::Constant *& Entry = CGM.DestroyCache[kind]; |
| 1021 | if (Entry) |
| 1022 | return Entry; |
| 1023 | return Entry=CodeGenFunction(CGM).GeneratebyrefDestroyHelperFunction(T, flag); |
Mike Stump | f4b6234 | 2009-03-06 02:29:21 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 1026 | llvm::Value *BlockFunction::getBlockObjectDispose() { |
| 1027 | if (CGM.BlockObjectDispose == 0) { |
| 1028 | const llvm::FunctionType *FTy; |
| 1029 | std::vector<const llvm::Type*> ArgTys; |
| 1030 | const llvm::Type *ResultType = llvm::Type::VoidTy; |
| 1031 | ArgTys.push_back(PtrToInt8Ty); |
| 1032 | ArgTys.push_back(llvm::Type::Int32Ty); |
| 1033 | FTy = llvm::FunctionType::get(ResultType, ArgTys, false); |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 1034 | CGM.BlockObjectDispose |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 1035 | = CGM.CreateRuntimeFunction(FTy, "_Block_object_dispose"); |
| 1036 | } |
| 1037 | return CGM.BlockObjectDispose; |
| 1038 | } |
| 1039 | |
Mike Stump | 11973b6 | 2009-03-06 06:12:24 +0000 | [diff] [blame] | 1040 | llvm::Value *BlockFunction::getBlockObjectAssign() { |
| 1041 | if (CGM.BlockObjectAssign == 0) { |
| 1042 | const llvm::FunctionType *FTy; |
| 1043 | std::vector<const llvm::Type*> ArgTys; |
| 1044 | const llvm::Type *ResultType = llvm::Type::VoidTy; |
| 1045 | ArgTys.push_back(PtrToInt8Ty); |
| 1046 | ArgTys.push_back(PtrToInt8Ty); |
| 1047 | ArgTys.push_back(llvm::Type::Int32Ty); |
| 1048 | FTy = llvm::FunctionType::get(ResultType, ArgTys, false); |
| 1049 | CGM.BlockObjectAssign |
| 1050 | = CGM.CreateRuntimeFunction(FTy, "_Block_object_assign"); |
| 1051 | } |
| 1052 | return CGM.BlockObjectAssign; |
| 1053 | } |
| 1054 | |
Mike Stump | 4a0e513 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 1055 | void BlockFunction::BuildBlockRelease(llvm::Value *V, int flag) { |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 1056 | llvm::Value *F = getBlockObjectDispose(); |
Mike Stump | 4a0e513 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 1057 | llvm::Value *N; |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 1058 | V = Builder.CreateBitCast(V, PtrToInt8Ty); |
Mike Stump | 4a0e513 | 2009-03-06 04:53:30 +0000 | [diff] [blame] | 1059 | N = llvm::ConstantInt::get(llvm::Type::Int32Ty, flag); |
Mike Stump | 6029466 | 2009-03-05 01:23:13 +0000 | [diff] [blame] | 1060 | Builder.CreateCall2(F, V, N); |
| 1061 | } |
Mike Stump | 1bdbf63 | 2009-03-05 08:32:30 +0000 | [diff] [blame] | 1062 | |
| 1063 | ASTContext &BlockFunction::getContext() const { return CGM.getContext(); } |
Mike Stump | 1fa52fe | 2009-03-07 02:35:30 +0000 | [diff] [blame] | 1064 | |
| 1065 | BlockFunction::BlockFunction(CodeGenModule &cgm, CodeGenFunction &cgf, |
| 1066 | CGBuilderTy &B) |
| 1067 | : CGM(cgm), CGF(cgf), Builder(B) { |
| 1068 | PtrToInt8Ty = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); |
| 1069 | |
| 1070 | BlockHasCopyDispose = false; |
| 1071 | } |