Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1 | //===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This contains code to emit Objective-C code as LLVM code. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Devang Patel | bcbd03a | 2011-01-19 01:36:36 +0000 | [diff] [blame] | 14 | #include "CGDebugInfo.h" |
Ted Kremenek | 2979ec7 | 2008-04-09 15:51:31 +0000 | [diff] [blame] | 15 | #include "CGObjCRuntime.h" |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 16 | #include "CodeGenFunction.h" |
| 17 | #include "CodeGenModule.h" |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
Chris Lattner | 16f0049 | 2009-04-26 01:32:48 +0000 | [diff] [blame] | 20 | #include "clang/AST/StmtObjC.h" |
Daniel Dunbar | e66f4e3 | 2008-09-03 00:27:26 +0000 | [diff] [blame] | 21 | #include "clang/Basic/Diagnostic.h" |
Anders Carlsson | 3d8400d | 2008-08-30 19:51:14 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/STLExtras.h" |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetData.h" |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | using namespace CodeGen; |
| 26 | |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 27 | /// Emits an instance of NSConstantString representing the object. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 28 | llvm::Value *CodeGenFunction::EmitObjCStringLiteral(const ObjCStringLiteral *E) |
Daniel Dunbar | 71fcec9 | 2008-11-25 21:53:21 +0000 | [diff] [blame] | 29 | { |
David Chisnall | 0d13f6f | 2010-01-23 02:40:42 +0000 | [diff] [blame] | 30 | llvm::Constant *C = |
| 31 | CGM.getObjCRuntime().GenerateConstantString(E->getString()); |
Daniel Dunbar | ed7c618 | 2008-08-20 00:28:19 +0000 | [diff] [blame] | 32 | // FIXME: This bitcast should just be made an invariant on the Runtime. |
Owen Anderson | 3c4972d | 2009-07-29 18:54:39 +0000 | [diff] [blame] | 33 | return llvm::ConstantExpr::getBitCast(C, ConvertType(E->getType())); |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /// Emit a selector. |
| 37 | llvm::Value *CodeGenFunction::EmitObjCSelectorExpr(const ObjCSelectorExpr *E) { |
| 38 | // Untyped selector. |
| 39 | // Note that this implementation allows for non-constant strings to be passed |
| 40 | // as arguments to @selector(). Currently, the only thing preventing this |
| 41 | // behaviour is the type checking in the front end. |
Daniel Dunbar | 6d5a1c2 | 2010-02-03 20:11:42 +0000 | [diff] [blame] | 42 | return CGM.getObjCRuntime().GetSelector(Builder, E->getSelector()); |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Daniel Dunbar | ed7c618 | 2008-08-20 00:28:19 +0000 | [diff] [blame] | 45 | llvm::Value *CodeGenFunction::EmitObjCProtocolExpr(const ObjCProtocolExpr *E) { |
| 46 | // FIXME: This should pass the Decl not the name. |
| 47 | return CGM.getObjCRuntime().GenerateProtocolRef(Builder, E->getProtocol()); |
| 48 | } |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 49 | |
| 50 | |
John McCall | ef072fd | 2010-05-22 01:48:05 +0000 | [diff] [blame] | 51 | RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E, |
| 52 | ReturnValueSlot Return) { |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 53 | // Only the lookup mechanism and first two arguments of the method |
| 54 | // implementation vary between runtimes. We can get the receiver and |
| 55 | // arguments in generic code. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 | |
Daniel Dunbar | 208ff5e | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 57 | CGObjCRuntime &Runtime = CGM.getObjCRuntime(); |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 58 | bool isSuperMessage = false; |
Daniel Dunbar | f56f191 | 2008-08-25 08:19:24 +0000 | [diff] [blame] | 59 | bool isClassMessage = false; |
David Chisnall | c6cd5fd | 2010-04-28 19:33:36 +0000 | [diff] [blame] | 60 | ObjCInterfaceDecl *OID = 0; |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 61 | // Find the receiver |
Daniel Dunbar | 0b647a6 | 2010-04-22 03:17:06 +0000 | [diff] [blame] | 62 | llvm::Value *Receiver = 0; |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 63 | switch (E->getReceiverKind()) { |
| 64 | case ObjCMessageExpr::Instance: |
| 65 | Receiver = EmitScalarExpr(E->getInstanceReceiver()); |
| 66 | break; |
Daniel Dunbar | ddb2a3d | 2008-08-16 00:25:02 +0000 | [diff] [blame] | 67 | |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 68 | case ObjCMessageExpr::Class: { |
John McCall | 3031c63 | 2010-05-17 20:12:43 +0000 | [diff] [blame] | 69 | const ObjCObjectType *ObjTy |
| 70 | = E->getClassReceiver()->getAs<ObjCObjectType>(); |
| 71 | assert(ObjTy && "Invalid Objective-C class message send"); |
| 72 | OID = ObjTy->getInterface(); |
| 73 | assert(OID && "Invalid Objective-C class message send"); |
David Chisnall | c6cd5fd | 2010-04-28 19:33:36 +0000 | [diff] [blame] | 74 | Receiver = Runtime.GetClass(Builder, OID); |
Daniel Dunbar | f56f191 | 2008-08-25 08:19:24 +0000 | [diff] [blame] | 75 | isClassMessage = true; |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 76 | break; |
| 77 | } |
| 78 | |
| 79 | case ObjCMessageExpr::SuperInstance: |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 80 | Receiver = LoadObjCSelf(); |
Douglas Gregor | 04badcf | 2010-04-21 00:45:42 +0000 | [diff] [blame] | 81 | isSuperMessage = true; |
| 82 | break; |
| 83 | |
| 84 | case ObjCMessageExpr::SuperClass: |
| 85 | Receiver = LoadObjCSelf(); |
| 86 | isSuperMessage = true; |
| 87 | isClassMessage = true; |
| 88 | break; |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Daniel Dunbar | 19cd87e | 2008-08-30 03:02:31 +0000 | [diff] [blame] | 91 | CallArgList Args; |
Anders Carlsson | 131038e | 2009-04-18 20:29:27 +0000 | [diff] [blame] | 92 | EmitCallArgs(Args, E->getMethodDecl(), E->arg_begin(), E->arg_end()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 93 | |
Anders Carlsson | 7e70fb2 | 2010-06-21 20:59:55 +0000 | [diff] [blame] | 94 | QualType ResultType = |
| 95 | E->getMethodDecl() ? E->getMethodDecl()->getResultType() : E->getType(); |
| 96 | |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 97 | if (isSuperMessage) { |
Chris Lattner | 9384c76 | 2008-06-26 04:42:20 +0000 | [diff] [blame] | 98 | // super is only valid in an Objective-C method |
| 99 | const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl); |
Fariborz Jahanian | 7ce7792 | 2009-02-28 20:07:56 +0000 | [diff] [blame] | 100 | bool isCategoryImpl = isa<ObjCCategoryImplDecl>(OMD->getDeclContext()); |
Anders Carlsson | 7e70fb2 | 2010-06-21 20:59:55 +0000 | [diff] [blame] | 101 | return Runtime.GenerateMessageSendSuper(*this, Return, ResultType, |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 102 | E->getSelector(), |
Daniel Dunbar | f56f191 | 2008-08-25 08:19:24 +0000 | [diff] [blame] | 103 | OMD->getClassInterface(), |
Fariborz Jahanian | 7ce7792 | 2009-02-28 20:07:56 +0000 | [diff] [blame] | 104 | isCategoryImpl, |
Daniel Dunbar | f56f191 | 2008-08-25 08:19:24 +0000 | [diff] [blame] | 105 | Receiver, |
Daniel Dunbar | 19cd87e | 2008-08-30 03:02:31 +0000 | [diff] [blame] | 106 | isClassMessage, |
Daniel Dunbar | d6c93d7 | 2009-09-17 04:01:22 +0000 | [diff] [blame] | 107 | Args, |
| 108 | E->getMethodDecl()); |
Chris Lattner | 8fdf328 | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 109 | } |
Daniel Dunbar | d6c93d7 | 2009-09-17 04:01:22 +0000 | [diff] [blame] | 110 | |
Anders Carlsson | 7e70fb2 | 2010-06-21 20:59:55 +0000 | [diff] [blame] | 111 | return Runtime.GenerateMessageSend(*this, Return, ResultType, |
John McCall | ef072fd | 2010-05-22 01:48:05 +0000 | [diff] [blame] | 112 | E->getSelector(), |
David Chisnall | c6cd5fd | 2010-04-28 19:33:36 +0000 | [diff] [blame] | 113 | Receiver, Args, OID, |
Fariborz Jahanian | df9ccc6 | 2009-05-05 21:36:57 +0000 | [diff] [blame] | 114 | E->getMethodDecl()); |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 117 | /// StartObjCMethod - Begin emission of an ObjCMethod. This generates |
| 118 | /// the LLVM function and sets the other context used by |
| 119 | /// CodeGenFunction. |
Fariborz Jahanian | 679a502 | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 120 | void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD, |
| 121 | const ObjCContainerDecl *CD) { |
John McCall | d26bc76 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 122 | FunctionArgList args; |
Devang Patel | 4800ea6 | 2010-04-05 21:09:15 +0000 | [diff] [blame] | 123 | // Check if we should generate debug info for this method. |
Devang Patel | aa11289 | 2011-03-07 18:45:56 +0000 | [diff] [blame] | 124 | if (CGM.getModuleDebugInfo() && !OMD->hasAttr<NoDebugAttr>()) |
| 125 | DebugInfo = CGM.getModuleDebugInfo(); |
Devang Patel | 4800ea6 | 2010-04-05 21:09:15 +0000 | [diff] [blame] | 126 | |
Fariborz Jahanian | 679a502 | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 127 | llvm::Function *Fn = CGM.getObjCRuntime().GenerateMethod(OMD, CD); |
Daniel Dunbar | f80519b | 2008-09-04 23:41:35 +0000 | [diff] [blame] | 128 | |
Daniel Dunbar | 0e4f40e | 2009-04-17 00:48:04 +0000 | [diff] [blame] | 129 | const CGFunctionInfo &FI = CGM.getTypes().getFunctionInfo(OMD); |
| 130 | CGM.SetInternalFunctionAttributes(OMD, Fn, FI); |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 131 | |
John McCall | d26bc76 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 132 | args.push_back(OMD->getSelfDecl()); |
| 133 | args.push_back(OMD->getCmdDecl()); |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 134 | |
Chris Lattner | 89951a8 | 2009-02-20 18:43:26 +0000 | [diff] [blame] | 135 | for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(), |
| 136 | E = OMD->param_end(); PI != E; ++PI) |
John McCall | d26bc76 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 137 | args.push_back(*PI); |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 138 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 139 | CurGD = OMD; |
| 140 | |
John McCall | d26bc76 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 141 | StartFunction(OMD, OMD->getResultType(), Fn, FI, args, OMD->getLocStart()); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 142 | } |
Daniel Dunbar | b7ec246 | 2008-08-16 03:19:19 +0000 | [diff] [blame] | 143 | |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 144 | void CodeGenFunction::GenerateObjCGetterBody(ObjCIvarDecl *Ivar, |
| 145 | bool IsAtomic, bool IsStrong) { |
| 146 | LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), |
| 147 | Ivar, 0); |
| 148 | llvm::Value *GetCopyStructFn = |
| 149 | CGM.getObjCRuntime().GetGetStructFunction(); |
| 150 | CodeGenTypes &Types = CGM.getTypes(); |
| 151 | // objc_copyStruct (ReturnValue, &structIvar, |
| 152 | // sizeof (Type of Ivar), isAtomic, false); |
| 153 | CallArgList Args; |
| 154 | RValue RV = RValue::get(Builder.CreateBitCast(ReturnValue, |
| 155 | Types.ConvertType(getContext().VoidPtrTy))); |
| 156 | Args.push_back(std::make_pair(RV, getContext().VoidPtrTy)); |
| 157 | RV = RValue::get(Builder.CreateBitCast(LV.getAddress(), |
| 158 | Types.ConvertType(getContext().VoidPtrTy))); |
| 159 | Args.push_back(std::make_pair(RV, getContext().VoidPtrTy)); |
| 160 | // sizeof (Type of Ivar) |
| 161 | CharUnits Size = getContext().getTypeSizeInChars(Ivar->getType()); |
| 162 | llvm::Value *SizeVal = |
| 163 | llvm::ConstantInt::get(Types.ConvertType(getContext().LongTy), |
| 164 | Size.getQuantity()); |
| 165 | Args.push_back(std::make_pair(RValue::get(SizeVal), |
| 166 | getContext().LongTy)); |
| 167 | llvm::Value *isAtomic = |
| 168 | llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), |
| 169 | IsAtomic ? 1 : 0); |
| 170 | Args.push_back(std::make_pair(RValue::get(isAtomic), |
| 171 | getContext().BoolTy)); |
| 172 | llvm::Value *hasStrong = |
| 173 | llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), |
| 174 | IsStrong ? 1 : 0); |
| 175 | Args.push_back(std::make_pair(RValue::get(hasStrong), |
| 176 | getContext().BoolTy)); |
| 177 | EmitCall(Types.getFunctionInfo(getContext().VoidTy, Args, |
| 178 | FunctionType::ExtInfo()), |
| 179 | GetCopyStructFn, ReturnValueSlot(), Args); |
| 180 | } |
| 181 | |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 182 | /// Generate an Objective-C method. An Objective-C method is a C function with |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | /// its pointer, name, and types registered in the class struture. |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 184 | void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) { |
Fariborz Jahanian | 679a502 | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 185 | StartObjCMethod(OMD, OMD->getClassInterface()); |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 186 | EmitStmt(OMD->getBody()); |
| 187 | FinishFunction(OMD->getBodyRBrace()); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Mike Stump | f5408fe | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 190 | // FIXME: I wasn't sure about the synthesis approach. If we end up generating an |
| 191 | // AST for the whole body we can just fall back to having a GenerateFunction |
| 192 | // which takes the body Stmt. |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 193 | |
| 194 | /// GenerateObjCGetter - Generate an Objective-C property getter |
Steve Naroff | 489034c | 2009-01-10 22:55:25 +0000 | [diff] [blame] | 195 | /// function. The given Decl must be an ObjCImplementationDecl. @synthesize |
| 196 | /// is illegal within a category. |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 197 | void CodeGenFunction::GenerateObjCGetter(ObjCImplementationDecl *IMP, |
| 198 | const ObjCPropertyImplDecl *PID) { |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 199 | ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl(); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 200 | const ObjCPropertyDecl *PD = PID->getPropertyDecl(); |
Fariborz Jahanian | 15bd588 | 2010-04-13 18:32:24 +0000 | [diff] [blame] | 201 | bool IsAtomic = |
| 202 | !(PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 203 | ObjCMethodDecl *OMD = PD->getGetterMethodDecl(); |
| 204 | assert(OMD && "Invalid call to generate getter (empty method)"); |
Fariborz Jahanian | 679a502 | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 205 | StartObjCMethod(OMD, IMP->getClassInterface()); |
Fariborz Jahanian | 15bd588 | 2010-04-13 18:32:24 +0000 | [diff] [blame] | 206 | |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 207 | // Determine if we should use an objc_getProperty call for |
Fariborz Jahanian | 447d7ae | 2008-12-08 23:56:17 +0000 | [diff] [blame] | 208 | // this. Non-atomic properties are directly evaluated. |
| 209 | // atomic 'copy' and 'retain' properties are also directly |
| 210 | // evaluated in gc-only mode. |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 211 | if (CGM.getLangOptions().getGCMode() != LangOptions::GCOnly && |
Fariborz Jahanian | 15bd588 | 2010-04-13 18:32:24 +0000 | [diff] [blame] | 212 | IsAtomic && |
Fariborz Jahanian | 447d7ae | 2008-12-08 23:56:17 +0000 | [diff] [blame] | 213 | (PD->getSetterKind() == ObjCPropertyDecl::Copy || |
| 214 | PD->getSetterKind() == ObjCPropertyDecl::Retain)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 215 | llvm::Value *GetPropertyFn = |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 216 | CGM.getObjCRuntime().GetPropertyGetFunction(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 217 | |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 218 | if (!GetPropertyFn) { |
| 219 | CGM.ErrorUnsupported(PID, "Obj-C getter requiring atomic copy"); |
| 220 | FinishFunction(); |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | // Return (ivar-type) objc_getProperty((id) self, _cmd, offset, true). |
| 225 | // FIXME: Can't this be simpler? This might even be worse than the |
| 226 | // corresponding gcc code. |
| 227 | CodeGenTypes &Types = CGM.getTypes(); |
| 228 | ValueDecl *Cmd = OMD->getCmdDecl(); |
| 229 | llvm::Value *CmdVal = Builder.CreateLoad(LocalDeclMap[Cmd], "cmd"); |
| 230 | QualType IdTy = getContext().getObjCIdType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 231 | llvm::Value *SelfAsId = |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 232 | Builder.CreateBitCast(LoadObjCSelf(), Types.ConvertType(IdTy)); |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 233 | llvm::Value *Offset = EmitIvarOffset(IMP->getClassInterface(), Ivar); |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 234 | llvm::Value *True = |
Owen Anderson | 4a28d5d | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 235 | llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), 1); |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 236 | CallArgList Args; |
| 237 | Args.push_back(std::make_pair(RValue::get(SelfAsId), IdTy)); |
| 238 | Args.push_back(std::make_pair(RValue::get(CmdVal), Cmd->getType())); |
David Chisnall | ab5824e | 2011-03-22 20:03:13 +0000 | [diff] [blame] | 239 | Args.push_back(std::make_pair(RValue::get(Offset), |
| 240 | getContext().getPointerDiffType())); |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 241 | Args.push_back(std::make_pair(RValue::get(True), getContext().BoolTy)); |
Daniel Dunbar | e4be5a6 | 2009-02-03 23:43:59 +0000 | [diff] [blame] | 242 | // FIXME: We shouldn't need to get the function info here, the |
| 243 | // runtime already should have computed it to build the function. |
John McCall | 04a67a6 | 2010-02-05 21:31:56 +0000 | [diff] [blame] | 244 | RValue RV = EmitCall(Types.getFunctionInfo(PD->getType(), Args, |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 245 | FunctionType::ExtInfo()), |
Anders Carlsson | f3c47c9 | 2009-12-24 19:25:24 +0000 | [diff] [blame] | 246 | GetPropertyFn, ReturnValueSlot(), Args); |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 247 | // We need to fix the type here. Ivars with copy & retain are |
| 248 | // always objects so we don't need to worry about complex or |
| 249 | // aggregates. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 250 | RV = RValue::get(Builder.CreateBitCast(RV.getScalarVal(), |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 251 | Types.ConvertType(PD->getType()))); |
| 252 | EmitReturnOfRValue(RV, PD->getType()); |
| 253 | } else { |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 254 | const llvm::Triple &Triple = getContext().Target.getTriple(); |
| 255 | QualType IVART = Ivar->getType(); |
| 256 | if (IsAtomic && |
| 257 | IVART->isScalarType() && |
| 258 | (Triple.getArch() == llvm::Triple::arm || |
| 259 | Triple.getArch() == llvm::Triple::thumb) && |
| 260 | (getContext().getTypeSizeInChars(IVART) |
| 261 | > CharUnits::fromQuantity(4)) && |
| 262 | CGM.getObjCRuntime().GetGetStructFunction()) { |
| 263 | GenerateObjCGetterBody(Ivar, true, false); |
| 264 | } |
| 265 | else if (IVART->isAnyComplexType()) { |
Fariborz Jahanian | 97a73cd | 2010-05-06 15:45:36 +0000 | [diff] [blame] | 266 | LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), |
| 267 | Ivar, 0); |
Fariborz Jahanian | 1b23fe6 | 2010-03-25 21:56:43 +0000 | [diff] [blame] | 268 | ComplexPairTy Pair = LoadComplexFromAddr(LV.getAddress(), |
| 269 | LV.isVolatileQualified()); |
| 270 | StoreComplexToAddr(Pair, ReturnValue, LV.isVolatileQualified()); |
| 271 | } |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 272 | else if (hasAggregateLLVMType(IVART)) { |
Fariborz Jahanian | 15bd588 | 2010-04-13 18:32:24 +0000 | [diff] [blame] | 273 | bool IsStrong = false; |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 274 | if ((IsAtomic || (IsStrong = IvarTypeWithAggrGCObjects(IVART))) |
Fariborz Jahanian | 0b2bd47 | 2010-04-13 00:38:05 +0000 | [diff] [blame] | 275 | && CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect |
David Chisnall | 8fac25d | 2010-12-26 22:13:16 +0000 | [diff] [blame] | 276 | && CGM.getObjCRuntime().GetGetStructFunction()) { |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 277 | GenerateObjCGetterBody(Ivar, IsAtomic, IsStrong); |
Fariborz Jahanian | 0b2bd47 | 2010-04-13 00:38:05 +0000 | [diff] [blame] | 278 | } |
Fariborz Jahanian | 97a73cd | 2010-05-06 15:45:36 +0000 | [diff] [blame] | 279 | else { |
| 280 | if (PID->getGetterCXXConstructor()) { |
| 281 | ReturnStmt *Stmt = |
| 282 | new (getContext()) ReturnStmt(SourceLocation(), |
Douglas Gregor | 5077c38 | 2010-05-15 06:01:05 +0000 | [diff] [blame] | 283 | PID->getGetterCXXConstructor(), |
| 284 | 0); |
Fariborz Jahanian | 97a73cd | 2010-05-06 15:45:36 +0000 | [diff] [blame] | 285 | EmitReturnStmt(*Stmt); |
| 286 | } |
| 287 | else { |
| 288 | LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), |
| 289 | Ivar, 0); |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 290 | EmitAggregateCopy(ReturnValue, LV.getAddress(), IVART); |
Fariborz Jahanian | 97a73cd | 2010-05-06 15:45:36 +0000 | [diff] [blame] | 291 | } |
| 292 | } |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 293 | } |
| 294 | else { |
| 295 | LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), |
Fariborz Jahanian | 97a73cd | 2010-05-06 15:45:36 +0000 | [diff] [blame] | 296 | Ivar, 0); |
Fariborz Jahanian | 1408676 | 2011-03-28 23:47:18 +0000 | [diff] [blame^] | 297 | if (PD->getType()->isReferenceType()) { |
| 298 | RValue RV = RValue::get(LV.getAddress()); |
| 299 | EmitReturnOfRValue(RV, PD->getType()); |
| 300 | } |
| 301 | else { |
| 302 | CodeGenTypes &Types = CGM.getTypes(); |
| 303 | RValue RV = EmitLoadOfLValue(LV, IVART); |
| 304 | RV = RValue::get(Builder.CreateBitCast(RV.getScalarVal(), |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 305 | Types.ConvertType(PD->getType()))); |
Fariborz Jahanian | 1408676 | 2011-03-28 23:47:18 +0000 | [diff] [blame^] | 306 | EmitReturnOfRValue(RV, PD->getType()); |
| 307 | } |
Fariborz Jahanian | ed1d29d | 2009-03-03 18:49:40 +0000 | [diff] [blame] | 308 | } |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 309 | } |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 310 | |
| 311 | FinishFunction(); |
| 312 | } |
| 313 | |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 314 | void CodeGenFunction::GenerateObjCAtomicSetterBody(ObjCMethodDecl *OMD, |
| 315 | ObjCIvarDecl *Ivar) { |
| 316 | // objc_copyStruct (&structIvar, &Arg, |
| 317 | // sizeof (struct something), true, false); |
| 318 | llvm::Value *GetCopyStructFn = |
| 319 | CGM.getObjCRuntime().GetSetStructFunction(); |
| 320 | CodeGenTypes &Types = CGM.getTypes(); |
| 321 | CallArgList Args; |
| 322 | LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), Ivar, 0); |
| 323 | RValue RV = |
| 324 | RValue::get(Builder.CreateBitCast(LV.getAddress(), |
| 325 | Types.ConvertType(getContext().VoidPtrTy))); |
| 326 | Args.push_back(std::make_pair(RV, getContext().VoidPtrTy)); |
| 327 | llvm::Value *Arg = LocalDeclMap[*OMD->param_begin()]; |
| 328 | llvm::Value *ArgAsPtrTy = |
| 329 | Builder.CreateBitCast(Arg, |
| 330 | Types.ConvertType(getContext().VoidPtrTy)); |
| 331 | RV = RValue::get(ArgAsPtrTy); |
| 332 | Args.push_back(std::make_pair(RV, getContext().VoidPtrTy)); |
| 333 | // sizeof (Type of Ivar) |
| 334 | CharUnits Size = getContext().getTypeSizeInChars(Ivar->getType()); |
| 335 | llvm::Value *SizeVal = |
| 336 | llvm::ConstantInt::get(Types.ConvertType(getContext().LongTy), |
| 337 | Size.getQuantity()); |
| 338 | Args.push_back(std::make_pair(RValue::get(SizeVal), |
| 339 | getContext().LongTy)); |
| 340 | llvm::Value *True = |
| 341 | llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), 1); |
| 342 | Args.push_back(std::make_pair(RValue::get(True), getContext().BoolTy)); |
| 343 | llvm::Value *False = |
| 344 | llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), 0); |
| 345 | Args.push_back(std::make_pair(RValue::get(False), getContext().BoolTy)); |
| 346 | EmitCall(Types.getFunctionInfo(getContext().VoidTy, Args, |
| 347 | FunctionType::ExtInfo()), |
| 348 | GetCopyStructFn, ReturnValueSlot(), Args); |
| 349 | } |
| 350 | |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 351 | /// GenerateObjCSetter - Generate an Objective-C property setter |
Steve Naroff | 489034c | 2009-01-10 22:55:25 +0000 | [diff] [blame] | 352 | /// function. The given Decl must be an ObjCImplementationDecl. @synthesize |
| 353 | /// is illegal within a category. |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 354 | void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP, |
| 355 | const ObjCPropertyImplDecl *PID) { |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 356 | ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl(); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 357 | const ObjCPropertyDecl *PD = PID->getPropertyDecl(); |
| 358 | ObjCMethodDecl *OMD = PD->getSetterMethodDecl(); |
| 359 | assert(OMD && "Invalid call to generate setter (empty method)"); |
Fariborz Jahanian | 679a502 | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 360 | StartObjCMethod(OMD, IMP->getClassInterface()); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 361 | |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 362 | bool IsCopy = PD->getSetterKind() == ObjCPropertyDecl::Copy; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | bool IsAtomic = |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 364 | !(PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic); |
| 365 | |
| 366 | // Determine if we should use an objc_setProperty call for |
| 367 | // this. Properties with 'copy' semantics always use it, as do |
| 368 | // non-atomic properties with 'release' semantics as long as we are |
| 369 | // not in gc-only mode. |
| 370 | if (IsCopy || |
| 371 | (CGM.getLangOptions().getGCMode() != LangOptions::GCOnly && |
| 372 | PD->getSetterKind() == ObjCPropertyDecl::Retain)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | llvm::Value *SetPropertyFn = |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 374 | CGM.getObjCRuntime().GetPropertySetFunction(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 376 | if (!SetPropertyFn) { |
| 377 | CGM.ErrorUnsupported(PID, "Obj-C getter requiring atomic copy"); |
| 378 | FinishFunction(); |
| 379 | return; |
| 380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
| 382 | // Emit objc_setProperty((id) self, _cmd, offset, arg, |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 383 | // <is-atomic>, <is-copy>). |
| 384 | // FIXME: Can't this be simpler? This might even be worse than the |
| 385 | // corresponding gcc code. |
| 386 | CodeGenTypes &Types = CGM.getTypes(); |
| 387 | ValueDecl *Cmd = OMD->getCmdDecl(); |
| 388 | llvm::Value *CmdVal = Builder.CreateLoad(LocalDeclMap[Cmd], "cmd"); |
| 389 | QualType IdTy = getContext().getObjCIdType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 390 | llvm::Value *SelfAsId = |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 391 | Builder.CreateBitCast(LoadObjCSelf(), Types.ConvertType(IdTy)); |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 392 | llvm::Value *Offset = EmitIvarOffset(IMP->getClassInterface(), Ivar); |
Chris Lattner | 89951a8 | 2009-02-20 18:43:26 +0000 | [diff] [blame] | 393 | llvm::Value *Arg = LocalDeclMap[*OMD->param_begin()]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 394 | llvm::Value *ArgAsId = |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 395 | Builder.CreateBitCast(Builder.CreateLoad(Arg, "arg"), |
| 396 | Types.ConvertType(IdTy)); |
| 397 | llvm::Value *True = |
Owen Anderson | 4a28d5d | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 398 | llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), 1); |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 399 | llvm::Value *False = |
Owen Anderson | 4a28d5d | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 400 | llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), 0); |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 401 | CallArgList Args; |
| 402 | Args.push_back(std::make_pair(RValue::get(SelfAsId), IdTy)); |
| 403 | Args.push_back(std::make_pair(RValue::get(CmdVal), Cmd->getType())); |
David Chisnall | ab5824e | 2011-03-22 20:03:13 +0000 | [diff] [blame] | 404 | Args.push_back(std::make_pair(RValue::get(Offset), |
| 405 | getContext().getPointerDiffType())); |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 406 | Args.push_back(std::make_pair(RValue::get(ArgAsId), IdTy)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 407 | Args.push_back(std::make_pair(RValue::get(IsAtomic ? True : False), |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 408 | getContext().BoolTy)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | Args.push_back(std::make_pair(RValue::get(IsCopy ? True : False), |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 410 | getContext().BoolTy)); |
Mike Stump | f5408fe | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 411 | // FIXME: We shouldn't need to get the function info here, the runtime |
| 412 | // already should have computed it to build the function. |
John McCall | 04a67a6 | 2010-02-05 21:31:56 +0000 | [diff] [blame] | 413 | EmitCall(Types.getFunctionInfo(getContext().VoidTy, Args, |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 414 | FunctionType::ExtInfo()), |
| 415 | SetPropertyFn, |
Anders Carlsson | f3c47c9 | 2009-12-24 19:25:24 +0000 | [diff] [blame] | 416 | ReturnValueSlot(), Args); |
Fariborz Jahanian | 0b2bd47 | 2010-04-13 00:38:05 +0000 | [diff] [blame] | 417 | } else if (IsAtomic && hasAggregateLLVMType(Ivar->getType()) && |
| 418 | !Ivar->getType()->isAnyComplexType() && |
| 419 | IndirectObjCSetterArg(*CurFnInfo) |
David Chisnall | 8fac25d | 2010-12-26 22:13:16 +0000 | [diff] [blame] | 420 | && CGM.getObjCRuntime().GetSetStructFunction()) { |
Fariborz Jahanian | 0b2bd47 | 2010-04-13 00:38:05 +0000 | [diff] [blame] | 421 | // objc_copyStruct (&structIvar, &Arg, |
| 422 | // sizeof (struct something), true, false); |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 423 | GenerateObjCAtomicSetterBody(OMD, Ivar); |
Fariborz Jahanian | 97a73cd | 2010-05-06 15:45:36 +0000 | [diff] [blame] | 424 | } else if (PID->getSetterCXXAssignment()) { |
John McCall | 2a41637 | 2010-12-05 02:00:02 +0000 | [diff] [blame] | 425 | EmitIgnoredExpr(PID->getSetterCXXAssignment()); |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 426 | } else { |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 427 | const llvm::Triple &Triple = getContext().Target.getTriple(); |
| 428 | QualType IVART = Ivar->getType(); |
| 429 | if (IsAtomic && |
| 430 | IVART->isScalarType() && |
| 431 | (Triple.getArch() == llvm::Triple::arm || |
| 432 | Triple.getArch() == llvm::Triple::thumb) && |
| 433 | (getContext().getTypeSizeInChars(IVART) |
| 434 | > CharUnits::fromQuantity(4)) && |
| 435 | CGM.getObjCRuntime().GetGetStructFunction()) { |
| 436 | GenerateObjCAtomicSetterBody(OMD, Ivar); |
| 437 | } |
| 438 | else { |
| 439 | // FIXME: Find a clean way to avoid AST node creation. |
| 440 | SourceLocation Loc = PD->getLocation(); |
| 441 | ValueDecl *Self = OMD->getSelfDecl(); |
| 442 | ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl(); |
| 443 | DeclRefExpr Base(Self, Self->getType(), VK_RValue, Loc); |
| 444 | ParmVarDecl *ArgDecl = *OMD->param_begin(); |
Fariborz Jahanian | 1408676 | 2011-03-28 23:47:18 +0000 | [diff] [blame^] | 445 | QualType T = ArgDecl->getType(); |
| 446 | if (T->isReferenceType()) |
| 447 | T = cast<ReferenceType>(T)->getPointeeType(); |
| 448 | DeclRefExpr Arg(ArgDecl, T, VK_LValue, Loc); |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 449 | ObjCIvarRefExpr IvarRef(Ivar, Ivar->getType(), Loc, &Base, true, true); |
Daniel Dunbar | 45e8423 | 2009-10-27 19:21:30 +0000 | [diff] [blame] | 450 | |
Fariborz Jahanian | 2846b97 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 451 | // The property type can differ from the ivar type in some situations with |
| 452 | // Objective-C pointer types, we can always bit cast the RHS in these cases. |
| 453 | if (getContext().getCanonicalType(Ivar->getType()) != |
| 454 | getContext().getCanonicalType(ArgDecl->getType())) { |
| 455 | ImplicitCastExpr ArgCasted(ImplicitCastExpr::OnStack, |
| 456 | Ivar->getType(), CK_BitCast, &Arg, |
| 457 | VK_RValue); |
| 458 | BinaryOperator Assign(&IvarRef, &ArgCasted, BO_Assign, |
| 459 | Ivar->getType(), VK_RValue, OK_Ordinary, Loc); |
| 460 | EmitStmt(&Assign); |
| 461 | } else { |
| 462 | BinaryOperator Assign(&IvarRef, &Arg, BO_Assign, |
| 463 | Ivar->getType(), VK_RValue, OK_Ordinary, Loc); |
| 464 | EmitStmt(&Assign); |
| 465 | } |
Daniel Dunbar | 45e8423 | 2009-10-27 19:21:30 +0000 | [diff] [blame] | 466 | } |
Daniel Dunbar | 86957eb | 2008-09-24 06:32:09 +0000 | [diff] [blame] | 467 | } |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 468 | |
| 469 | FinishFunction(); |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 470 | } |
| 471 | |
John McCall | e81ac69 | 2011-03-22 07:05:39 +0000 | [diff] [blame] | 472 | // FIXME: these are stolen from CGClass.cpp, which is lame. |
| 473 | namespace { |
| 474 | struct CallArrayIvarDtor : EHScopeStack::Cleanup { |
| 475 | const ObjCIvarDecl *ivar; |
| 476 | llvm::Value *self; |
| 477 | CallArrayIvarDtor(const ObjCIvarDecl *ivar, llvm::Value *self) |
| 478 | : ivar(ivar), self(self) {} |
| 479 | |
| 480 | void Emit(CodeGenFunction &CGF, bool IsForEH) { |
| 481 | LValue lvalue = |
| 482 | CGF.EmitLValueForIvar(CGF.TypeOfSelfObject(), self, ivar, 0); |
| 483 | |
| 484 | QualType type = ivar->getType(); |
| 485 | const ConstantArrayType *arrayType |
| 486 | = CGF.getContext().getAsConstantArrayType(type); |
| 487 | QualType baseType = CGF.getContext().getBaseElementType(arrayType); |
| 488 | const CXXRecordDecl *classDecl = baseType->getAsCXXRecordDecl(); |
| 489 | |
| 490 | llvm::Value *base |
| 491 | = CGF.Builder.CreateBitCast(lvalue.getAddress(), |
| 492 | CGF.ConvertType(baseType)->getPointerTo()); |
| 493 | CGF.EmitCXXAggrDestructorCall(classDecl->getDestructor(), |
| 494 | arrayType, base); |
| 495 | } |
| 496 | }; |
| 497 | |
| 498 | struct CallIvarDtor : EHScopeStack::Cleanup { |
| 499 | const ObjCIvarDecl *ivar; |
| 500 | llvm::Value *self; |
| 501 | CallIvarDtor(const ObjCIvarDecl *ivar, llvm::Value *self) |
| 502 | : ivar(ivar), self(self) {} |
| 503 | |
| 504 | void Emit(CodeGenFunction &CGF, bool IsForEH) { |
| 505 | LValue lvalue = |
| 506 | CGF.EmitLValueForIvar(CGF.TypeOfSelfObject(), self, ivar, 0); |
| 507 | |
| 508 | QualType type = ivar->getType(); |
| 509 | const CXXRecordDecl *classDecl = type->getAsCXXRecordDecl(); |
| 510 | |
| 511 | CGF.EmitCXXDestructorCall(classDecl->getDestructor(), |
| 512 | Dtor_Complete, /*ForVirtualBase=*/false, |
| 513 | lvalue.getAddress()); |
| 514 | } |
| 515 | }; |
| 516 | } |
| 517 | |
| 518 | static void emitCXXDestructMethod(CodeGenFunction &CGF, |
| 519 | ObjCImplementationDecl *impl) { |
| 520 | CodeGenFunction::RunCleanupsScope scope(CGF); |
| 521 | |
| 522 | llvm::Value *self = CGF.LoadObjCSelf(); |
| 523 | |
| 524 | ObjCInterfaceDecl *iface |
| 525 | = const_cast<ObjCInterfaceDecl*>(impl->getClassInterface()); |
| 526 | for (ObjCIvarDecl *ivar = iface->all_declared_ivar_begin(); |
| 527 | ivar; ivar = ivar->getNextIvar()) { |
| 528 | QualType type = ivar->getType(); |
| 529 | |
| 530 | // Drill down to the base element type. |
| 531 | QualType baseType = type; |
| 532 | const ConstantArrayType *arrayType = |
| 533 | CGF.getContext().getAsConstantArrayType(baseType); |
| 534 | if (arrayType) baseType = CGF.getContext().getBaseElementType(arrayType); |
| 535 | |
| 536 | // Check whether the ivar is a destructible type. |
| 537 | QualType::DestructionKind destructKind = baseType.isDestructedType(); |
| 538 | assert(destructKind == type.isDestructedType()); |
| 539 | |
| 540 | switch (destructKind) { |
| 541 | case QualType::DK_none: |
| 542 | continue; |
| 543 | |
| 544 | case QualType::DK_cxx_destructor: |
| 545 | if (arrayType) |
| 546 | CGF.EHStack.pushCleanup<CallArrayIvarDtor>(NormalAndEHCleanup, |
| 547 | ivar, self); |
| 548 | else |
| 549 | CGF.EHStack.pushCleanup<CallIvarDtor>(NormalAndEHCleanup, |
| 550 | ivar, self); |
| 551 | break; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | assert(scope.requiresCleanups() && "nothing to do in .cxx_destruct?"); |
| 556 | } |
| 557 | |
Fariborz Jahanian | 109dfc6 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 558 | void CodeGenFunction::GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, |
| 559 | ObjCMethodDecl *MD, |
| 560 | bool ctor) { |
Fariborz Jahanian | 109dfc6 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 561 | MD->createImplicitParams(CGM.getContext(), IMP->getClassInterface()); |
| 562 | StartObjCMethod(MD, IMP->getClassInterface()); |
John McCall | e81ac69 | 2011-03-22 07:05:39 +0000 | [diff] [blame] | 563 | |
| 564 | // Emit .cxx_construct. |
Fariborz Jahanian | 109dfc6 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 565 | if (ctor) { |
John McCall | e81ac69 | 2011-03-22 07:05:39 +0000 | [diff] [blame] | 566 | llvm::SmallVector<CXXCtorInitializer *, 8> IvarInitializers; |
| 567 | for (ObjCImplementationDecl::init_const_iterator B = IMP->init_begin(), |
| 568 | E = IMP->init_end(); B != E; ++B) { |
| 569 | CXXCtorInitializer *IvarInit = (*B); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 570 | FieldDecl *Field = IvarInit->getAnyMember(); |
Fariborz Jahanian | 109dfc6 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 571 | ObjCIvarDecl *Ivar = cast<ObjCIvarDecl>(Field); |
Fariborz Jahanian | 9b4d4fc | 2010-04-28 22:30:33 +0000 | [diff] [blame] | 572 | LValue LV = EmitLValueForIvar(TypeOfSelfObject(), |
| 573 | LoadObjCSelf(), Ivar, 0); |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 574 | EmitAggExpr(IvarInit->getInit(), AggValueSlot::forLValue(LV, true)); |
Fariborz Jahanian | 109dfc6 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 575 | } |
| 576 | // constructor returns 'self'. |
| 577 | CodeGenTypes &Types = CGM.getTypes(); |
| 578 | QualType IdTy(CGM.getContext().getObjCIdType()); |
| 579 | llvm::Value *SelfAsId = |
| 580 | Builder.CreateBitCast(LoadObjCSelf(), Types.ConvertType(IdTy)); |
| 581 | EmitReturnOfRValue(RValue::get(SelfAsId), IdTy); |
John McCall | e81ac69 | 2011-03-22 07:05:39 +0000 | [diff] [blame] | 582 | |
| 583 | // Emit .cxx_destruct. |
Chandler Carruth | bc397cf | 2010-05-06 00:20:39 +0000 | [diff] [blame] | 584 | } else { |
John McCall | e81ac69 | 2011-03-22 07:05:39 +0000 | [diff] [blame] | 585 | emitCXXDestructMethod(*this, IMP); |
Fariborz Jahanian | 109dfc6 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 586 | } |
| 587 | FinishFunction(); |
| 588 | } |
| 589 | |
Fariborz Jahanian | 0b2bd47 | 2010-04-13 00:38:05 +0000 | [diff] [blame] | 590 | bool CodeGenFunction::IndirectObjCSetterArg(const CGFunctionInfo &FI) { |
| 591 | CGFunctionInfo::const_arg_iterator it = FI.arg_begin(); |
| 592 | it++; it++; |
| 593 | const ABIArgInfo &AI = it->info; |
| 594 | // FIXME. Is this sufficient check? |
| 595 | return (AI.getKind() == ABIArgInfo::Indirect); |
| 596 | } |
| 597 | |
Fariborz Jahanian | 15bd588 | 2010-04-13 18:32:24 +0000 | [diff] [blame] | 598 | bool CodeGenFunction::IvarTypeWithAggrGCObjects(QualType Ty) { |
| 599 | if (CGM.getLangOptions().getGCMode() == LangOptions::NonGC) |
| 600 | return false; |
| 601 | if (const RecordType *FDTTy = Ty.getTypePtr()->getAs<RecordType>()) |
| 602 | return FDTTy->getDecl()->hasObjectMember(); |
| 603 | return false; |
| 604 | } |
| 605 | |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 606 | llvm::Value *CodeGenFunction::LoadObjCSelf() { |
Daniel Dunbar | b7ec246 | 2008-08-16 03:19:19 +0000 | [diff] [blame] | 607 | const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl); |
| 608 | return Builder.CreateLoad(LocalDeclMap[OMD->getSelfDecl()], "self"); |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Fariborz Jahanian | 45012a7 | 2009-02-03 00:09:52 +0000 | [diff] [blame] | 611 | QualType CodeGenFunction::TypeOfSelfObject() { |
| 612 | const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl); |
| 613 | ImplicitParamDecl *selfDecl = OMD->getSelfDecl(); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 614 | const ObjCObjectPointerType *PTy = cast<ObjCObjectPointerType>( |
| 615 | getContext().getCanonicalType(selfDecl->getType())); |
Fariborz Jahanian | 45012a7 | 2009-02-03 00:09:52 +0000 | [diff] [blame] | 616 | return PTy->getPointeeType(); |
| 617 | } |
| 618 | |
John McCall | e68b984 | 2010-12-04 03:11:00 +0000 | [diff] [blame] | 619 | LValue |
| 620 | CodeGenFunction::EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E) { |
| 621 | // This is a special l-value that just issues sends when we load or |
| 622 | // store through it. |
| 623 | |
| 624 | // For certain base kinds, we need to emit the base immediately. |
| 625 | llvm::Value *Base; |
| 626 | if (E->isSuperReceiver()) |
| 627 | Base = LoadObjCSelf(); |
| 628 | else if (E->isClassReceiver()) |
| 629 | Base = CGM.getObjCRuntime().GetClass(Builder, E->getClassReceiver()); |
| 630 | else |
| 631 | Base = EmitScalarExpr(E->getBase()); |
| 632 | return LValue::MakePropertyRef(E, Base); |
| 633 | } |
| 634 | |
| 635 | static RValue GenerateMessageSendSuper(CodeGenFunction &CGF, |
| 636 | ReturnValueSlot Return, |
| 637 | QualType ResultType, |
| 638 | Selector S, |
| 639 | llvm::Value *Receiver, |
| 640 | const CallArgList &CallArgs) { |
| 641 | const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CGF.CurFuncDecl); |
Fariborz Jahanian | f469557 | 2009-03-20 19:18:21 +0000 | [diff] [blame] | 642 | bool isClassMessage = OMD->isClassMethod(); |
| 643 | bool isCategoryImpl = isa<ObjCCategoryImplDecl>(OMD->getDeclContext()); |
John McCall | e68b984 | 2010-12-04 03:11:00 +0000 | [diff] [blame] | 644 | return CGF.CGM.getObjCRuntime() |
| 645 | .GenerateMessageSendSuper(CGF, Return, ResultType, |
| 646 | S, OMD->getClassInterface(), |
| 647 | isCategoryImpl, Receiver, |
| 648 | isClassMessage, CallArgs); |
Fariborz Jahanian | f469557 | 2009-03-20 19:18:21 +0000 | [diff] [blame] | 649 | } |
| 650 | |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 651 | RValue CodeGenFunction::EmitLoadOfPropertyRefLValue(LValue LV, |
| 652 | ReturnValueSlot Return) { |
| 653 | const ObjCPropertyRefExpr *E = LV.getPropertyRefExpr(); |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 654 | QualType ResultType; |
| 655 | Selector S; |
| 656 | if (E->isExplicitProperty()) { |
| 657 | const ObjCPropertyDecl *Property = E->getExplicitProperty(); |
| 658 | S = Property->getGetterName(); |
| 659 | ResultType = E->getType(); |
Mike Stump | b3589f4 | 2009-07-30 22:28:39 +0000 | [diff] [blame] | 660 | } else { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 661 | const ObjCMethodDecl *Getter = E->getImplicitPropertyGetter(); |
| 662 | S = Getter->getSelector(); |
| 663 | ResultType = Getter->getResultType(); // with reference! |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 664 | } |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 665 | |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 666 | llvm::Value *Receiver = LV.getPropertyRefBaseAddr(); |
John McCall | e68b984 | 2010-12-04 03:11:00 +0000 | [diff] [blame] | 667 | |
| 668 | // Accesses to 'super' follow a different code path. |
| 669 | if (E->isSuperReceiver()) |
| 670 | return GenerateMessageSendSuper(*this, Return, ResultType, |
| 671 | S, Receiver, CallArgList()); |
| 672 | |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 673 | const ObjCInterfaceDecl *ReceiverClass |
| 674 | = (E->isClassReceiver() ? E->getClassReceiver() : 0); |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 675 | return CGM.getObjCRuntime(). |
| 676 | GenerateMessageSend(*this, Return, ResultType, S, |
| 677 | Receiver, CallArgList(), ReceiverClass); |
Daniel Dunbar | 9c3fc70 | 2008-08-27 06:57:25 +0000 | [diff] [blame] | 678 | } |
| 679 | |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 680 | void CodeGenFunction::EmitStoreThroughPropertyRefLValue(RValue Src, |
| 681 | LValue Dst) { |
| 682 | const ObjCPropertyRefExpr *E = Dst.getPropertyRefExpr(); |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 683 | Selector S = E->getSetterSelector(); |
| 684 | QualType ArgType; |
| 685 | if (E->isImplicitProperty()) { |
| 686 | const ObjCMethodDecl *Setter = E->getImplicitPropertySetter(); |
| 687 | ObjCMethodDecl::param_iterator P = Setter->param_begin(); |
| 688 | ArgType = (*P)->getType(); |
| 689 | } else { |
| 690 | ArgType = E->getType(); |
| 691 | } |
Fariborz Jahanian | b19c76e | 2011-02-08 22:33:23 +0000 | [diff] [blame] | 692 | // FIXME. Other than scalars, AST is not adequate for setter and |
| 693 | // getter type mismatches which require conversion. |
| 694 | if (Src.isScalar()) { |
| 695 | llvm::Value *SrcVal = Src.getScalarVal(); |
| 696 | QualType DstType = getContext().getCanonicalType(ArgType); |
| 697 | const llvm::Type *DstTy = ConvertType(DstType); |
| 698 | if (SrcVal->getType() != DstTy) |
| 699 | Src = |
| 700 | RValue::get(EmitScalarConversion(SrcVal, E->getType(), DstType)); |
| 701 | } |
| 702 | |
John McCall | e68b984 | 2010-12-04 03:11:00 +0000 | [diff] [blame] | 703 | CallArgList Args; |
| 704 | Args.push_back(std::make_pair(Src, ArgType)); |
| 705 | |
| 706 | llvm::Value *Receiver = Dst.getPropertyRefBaseAddr(); |
| 707 | QualType ResultType = getContext().VoidTy; |
| 708 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 709 | if (E->isSuperReceiver()) { |
John McCall | e68b984 | 2010-12-04 03:11:00 +0000 | [diff] [blame] | 710 | GenerateMessageSendSuper(*this, ReturnValueSlot(), |
| 711 | ResultType, S, Receiver, Args); |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 715 | const ObjCInterfaceDecl *ReceiverClass |
| 716 | = (E->isClassReceiver() ? E->getClassReceiver() : 0); |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 717 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 718 | CGM.getObjCRuntime().GenerateMessageSend(*this, ReturnValueSlot(), |
John McCall | e68b984 | 2010-12-04 03:11:00 +0000 | [diff] [blame] | 719 | ResultType, S, Receiver, Args, |
| 720 | ReceiverClass); |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Chris Lattner | 74391b4 | 2009-03-22 21:03:39 +0000 | [diff] [blame] | 723 | void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 724 | llvm::Constant *EnumerationMutationFn = |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 725 | CGM.getObjCRuntime().EnumerationMutationFunction(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | |
Daniel Dunbar | c1cf4a5 | 2008-09-24 04:04:31 +0000 | [diff] [blame] | 727 | if (!EnumerationMutationFn) { |
| 728 | CGM.ErrorUnsupported(&S, "Obj-C fast enumeration for this runtime"); |
| 729 | return; |
| 730 | } |
| 731 | |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 732 | // The local variable comes into scope immediately. |
| 733 | AutoVarEmission variable = AutoVarEmission::invalid(); |
| 734 | if (const DeclStmt *SD = dyn_cast<DeclStmt>(S.getElement())) |
| 735 | variable = EmitAutoVarAlloca(*cast<VarDecl>(SD->getSingleDecl())); |
| 736 | |
Devang Patel | bcbd03a | 2011-01-19 01:36:36 +0000 | [diff] [blame] | 737 | CGDebugInfo *DI = getDebugInfo(); |
| 738 | if (DI) { |
| 739 | DI->setLocation(S.getSourceRange().getBegin()); |
| 740 | DI->EmitRegionStart(Builder); |
| 741 | } |
| 742 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 743 | JumpDest LoopEnd = getJumpDestInCurrentScope("forcoll.end"); |
| 744 | JumpDest AfterBody = getJumpDestInCurrentScope("forcoll.next"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 745 | |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 746 | // Fast enumeration state. |
| 747 | QualType StateTy = getContext().getObjCFastEnumerationStateType(); |
Daniel Dunbar | 195337d | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 748 | llvm::Value *StatePtr = CreateMemTemp(StateTy, "state.ptr"); |
Anders Carlsson | 1884eb0 | 2010-05-22 17:35:42 +0000 | [diff] [blame] | 749 | EmitNullInitialization(StatePtr, StateTy); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 751 | // Number of elements in the items array. |
Anders Carlsson | 2abd89c | 2008-08-31 04:05:03 +0000 | [diff] [blame] | 752 | static const unsigned NumItems = 16; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 753 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 754 | // Fetch the countByEnumeratingWithState:objects:count: selector. |
Benjamin Kramer | ad46886 | 2010-03-30 11:36:44 +0000 | [diff] [blame] | 755 | IdentifierInfo *II[] = { |
| 756 | &CGM.getContext().Idents.get("countByEnumeratingWithState"), |
| 757 | &CGM.getContext().Idents.get("objects"), |
| 758 | &CGM.getContext().Idents.get("count") |
| 759 | }; |
| 760 | Selector FastEnumSel = |
| 761 | CGM.getContext().Selectors.getSelector(llvm::array_lengthof(II), &II[0]); |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 762 | |
| 763 | QualType ItemsTy = |
| 764 | getContext().getConstantArrayType(getContext().getObjCIdType(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 765 | llvm::APInt(32, NumItems), |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 766 | ArrayType::Normal, 0); |
Daniel Dunbar | 195337d | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 767 | llvm::Value *ItemsPtr = CreateMemTemp(ItemsTy, "items.ptr"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 769 | // Emit the collection pointer. |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 770 | llvm::Value *Collection = EmitScalarExpr(S.getCollection()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 771 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 772 | // Send it our message: |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 773 | CallArgList Args; |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 774 | |
| 775 | // The first argument is a temporary of the enumeration-state type. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 776 | Args.push_back(std::make_pair(RValue::get(StatePtr), |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 777 | getContext().getPointerType(StateTy))); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 779 | // The second argument is a temporary array with space for NumItems |
| 780 | // pointers. We'll actually be loading elements from the array |
| 781 | // pointer written into the control state; this buffer is so that |
| 782 | // collections that *aren't* backed by arrays can still queue up |
| 783 | // batches of elements. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 784 | Args.push_back(std::make_pair(RValue::get(ItemsPtr), |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 785 | getContext().getPointerType(ItemsTy))); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 786 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 787 | // The third argument is the capacity of that temporary array. |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 788 | const llvm::Type *UnsignedLongLTy = ConvertType(getContext().UnsignedLongTy); |
Owen Anderson | 4a28d5d | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 789 | llvm::Constant *Count = llvm::ConstantInt::get(UnsignedLongLTy, NumItems); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | Args.push_back(std::make_pair(RValue::get(Count), |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 791 | getContext().UnsignedLongTy)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 792 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 793 | // Start the enumeration. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 794 | RValue CountRV = |
John McCall | ef072fd | 2010-05-22 01:48:05 +0000 | [diff] [blame] | 795 | CGM.getObjCRuntime().GenerateMessageSend(*this, ReturnValueSlot(), |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 796 | getContext().UnsignedLongTy, |
| 797 | FastEnumSel, |
David Chisnall | c6cd5fd | 2010-04-28 19:33:36 +0000 | [diff] [blame] | 798 | Collection, Args); |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 799 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 800 | // The initial number of objects that were returned in the buffer. |
| 801 | llvm::Value *initialBufferLimit = CountRV.getScalarVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 802 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 803 | llvm::BasicBlock *EmptyBB = createBasicBlock("forcoll.empty"); |
| 804 | llvm::BasicBlock *LoopInitBB = createBasicBlock("forcoll.loopinit"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 805 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 806 | llvm::Value *zero = llvm::Constant::getNullValue(UnsignedLongLTy); |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 807 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 808 | // If the limit pointer was zero to begin with, the collection is |
| 809 | // empty; skip all this. |
| 810 | Builder.CreateCondBr(Builder.CreateICmpEQ(initialBufferLimit, zero, "iszero"), |
| 811 | EmptyBB, LoopInitBB); |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 812 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 813 | // Otherwise, initialize the loop. |
| 814 | EmitBlock(LoopInitBB); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 815 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 816 | // Save the initial mutations value. This is the value at an |
| 817 | // address that was written into the state object by |
| 818 | // countByEnumeratingWithState:objects:count:. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 819 | llvm::Value *StateMutationsPtrPtr = |
Anders Carlsson | 2abd89c | 2008-08-31 04:05:03 +0000 | [diff] [blame] | 820 | Builder.CreateStructGEP(StatePtr, 2, "mutationsptr.ptr"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 821 | llvm::Value *StateMutationsPtr = Builder.CreateLoad(StateMutationsPtrPtr, |
Anders Carlsson | 2abd89c | 2008-08-31 04:05:03 +0000 | [diff] [blame] | 822 | "mutationsptr"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 823 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 824 | llvm::Value *initialMutations = |
| 825 | Builder.CreateLoad(StateMutationsPtr, "forcoll.initial-mutations"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 827 | // Start looping. This is the point we return to whenever we have a |
| 828 | // fresh, non-empty batch of objects. |
| 829 | llvm::BasicBlock *LoopBodyBB = createBasicBlock("forcoll.loopbody"); |
| 830 | EmitBlock(LoopBodyBB); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 831 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 832 | // The current index into the buffer. |
| 833 | llvm::PHINode *index = Builder.CreatePHI(UnsignedLongLTy, "forcoll.index"); |
| 834 | index->addIncoming(zero, LoopInitBB); |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 835 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 836 | // The current buffer size. |
| 837 | llvm::PHINode *count = Builder.CreatePHI(UnsignedLongLTy, "forcoll.count"); |
| 838 | count->addIncoming(initialBufferLimit, LoopInitBB); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 840 | // Check whether the mutations value has changed from where it was |
| 841 | // at start. StateMutationsPtr should actually be invariant between |
| 842 | // refreshes. |
Anders Carlsson | 2abd89c | 2008-08-31 04:05:03 +0000 | [diff] [blame] | 843 | StateMutationsPtr = Builder.CreateLoad(StateMutationsPtrPtr, "mutationsptr"); |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 844 | llvm::Value *currentMutations |
| 845 | = Builder.CreateLoad(StateMutationsPtr, "statemutations"); |
Anders Carlsson | 2abd89c | 2008-08-31 04:05:03 +0000 | [diff] [blame] | 846 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 847 | llvm::BasicBlock *WasMutatedBB = createBasicBlock("forcoll.mutated"); |
Dan Gohman | 361cf98 | 2011-03-02 22:39:34 +0000 | [diff] [blame] | 848 | llvm::BasicBlock *WasNotMutatedBB = createBasicBlock("forcoll.notmutated"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 849 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 850 | Builder.CreateCondBr(Builder.CreateICmpEQ(currentMutations, initialMutations), |
| 851 | WasNotMutatedBB, WasMutatedBB); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 852 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 853 | // If so, call the enumeration-mutation function. |
| 854 | EmitBlock(WasMutatedBB); |
Anders Carlsson | 2abd89c | 2008-08-31 04:05:03 +0000 | [diff] [blame] | 855 | llvm::Value *V = |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | Builder.CreateBitCast(Collection, |
Anders Carlsson | 2abd89c | 2008-08-31 04:05:03 +0000 | [diff] [blame] | 857 | ConvertType(getContext().getObjCIdType()), |
| 858 | "tmp"); |
Daniel Dunbar | 2b2105e | 2009-02-03 23:55:40 +0000 | [diff] [blame] | 859 | CallArgList Args2; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 860 | Args2.push_back(std::make_pair(RValue::get(V), |
Daniel Dunbar | 2b2105e | 2009-02-03 23:55:40 +0000 | [diff] [blame] | 861 | getContext().getObjCIdType())); |
Mike Stump | f5408fe | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 862 | // FIXME: We shouldn't need to get the function info here, the runtime already |
| 863 | // should have computed it to build the function. |
John McCall | 04a67a6 | 2010-02-05 21:31:56 +0000 | [diff] [blame] | 864 | EmitCall(CGM.getTypes().getFunctionInfo(getContext().VoidTy, Args2, |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 865 | FunctionType::ExtInfo()), |
Anders Carlsson | f3c47c9 | 2009-12-24 19:25:24 +0000 | [diff] [blame] | 866 | EnumerationMutationFn, ReturnValueSlot(), Args2); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 867 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 868 | // Otherwise, or if the mutation function returns, just continue. |
| 869 | EmitBlock(WasNotMutatedBB); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 871 | // Initialize the element variable. |
| 872 | RunCleanupsScope elementVariableScope(*this); |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 873 | bool elementIsVariable; |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 874 | LValue elementLValue; |
| 875 | QualType elementType; |
| 876 | if (const DeclStmt *SD = dyn_cast<DeclStmt>(S.getElement())) { |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 877 | // Initialize the variable, in case it's a __block variable or something. |
| 878 | EmitAutoVarInit(variable); |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 879 | |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 880 | const VarDecl* D = cast<VarDecl>(SD->getSingleDecl()); |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 881 | DeclRefExpr tempDRE(const_cast<VarDecl*>(D), D->getType(), |
| 882 | VK_LValue, SourceLocation()); |
| 883 | elementLValue = EmitLValue(&tempDRE); |
| 884 | elementType = D->getType(); |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 885 | elementIsVariable = true; |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 886 | } else { |
| 887 | elementLValue = LValue(); // suppress warning |
| 888 | elementType = cast<Expr>(S.getElement())->getType(); |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 889 | elementIsVariable = false; |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 890 | } |
| 891 | const llvm::Type *convertedElementType = ConvertType(elementType); |
| 892 | |
| 893 | // Fetch the buffer out of the enumeration state. |
| 894 | // TODO: this pointer should actually be invariant between |
| 895 | // refreshes, which would help us do certain loop optimizations. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 896 | llvm::Value *StateItemsPtr = |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 897 | Builder.CreateStructGEP(StatePtr, 1, "stateitems.ptr"); |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 898 | llvm::Value *EnumStateItems = |
| 899 | Builder.CreateLoad(StateItemsPtr, "stateitems"); |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 900 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 901 | // Fetch the value at the current index from the buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | llvm::Value *CurrentItemPtr = |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 903 | Builder.CreateGEP(EnumStateItems, index, "currentitem.ptr"); |
| 904 | llvm::Value *CurrentItem = Builder.CreateLoad(CurrentItemPtr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 906 | // Cast that value to the right type. |
| 907 | CurrentItem = Builder.CreateBitCast(CurrentItem, convertedElementType, |
| 908 | "currentitem"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 909 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 910 | // Make sure we have an l-value. Yes, this gets evaluated every |
| 911 | // time through the loop. |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 912 | if (!elementIsVariable) |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 913 | elementLValue = EmitLValue(cast<Expr>(S.getElement())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 914 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 915 | EmitStoreThroughLValue(RValue::get(CurrentItem), elementLValue, elementType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 916 | |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 917 | // If we do have an element variable, this assignment is the end of |
| 918 | // its initialization. |
| 919 | if (elementIsVariable) |
| 920 | EmitAutoVarCleanups(variable); |
| 921 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 922 | // Perform the loop body, setting up break and continue labels. |
Anders Carlsson | e4b6d34 | 2009-02-10 05:52:02 +0000 | [diff] [blame] | 923 | BreakContinueStack.push_back(BreakContinue(LoopEnd, AfterBody)); |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 924 | { |
| 925 | RunCleanupsScope Scope(*this); |
| 926 | EmitStmt(S.getBody()); |
| 927 | } |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 928 | BreakContinueStack.pop_back(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 930 | // Destroy the element variable now. |
| 931 | elementVariableScope.ForceCleanup(); |
| 932 | |
| 933 | // Check whether there are more elements. |
John McCall | ff8e115 | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 934 | EmitBlock(AfterBody.getBlock()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 935 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 936 | llvm::BasicBlock *FetchMoreBB = createBasicBlock("forcoll.refetch"); |
Fariborz Jahanian | f0906c4 | 2009-01-06 18:56:31 +0000 | [diff] [blame] | 937 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 938 | // First we check in the local buffer. |
| 939 | llvm::Value *indexPlusOne |
| 940 | = Builder.CreateAdd(index, llvm::ConstantInt::get(UnsignedLongLTy, 1)); |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 941 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 942 | // If we haven't overrun the buffer yet, we can continue. |
| 943 | Builder.CreateCondBr(Builder.CreateICmpULT(indexPlusOne, count), |
| 944 | LoopBodyBB, FetchMoreBB); |
| 945 | |
| 946 | index->addIncoming(indexPlusOne, AfterBody.getBlock()); |
| 947 | count->addIncoming(count, AfterBody.getBlock()); |
| 948 | |
| 949 | // Otherwise, we have to fetch more elements. |
| 950 | EmitBlock(FetchMoreBB); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 951 | |
| 952 | CountRV = |
John McCall | ef072fd | 2010-05-22 01:48:05 +0000 | [diff] [blame] | 953 | CGM.getObjCRuntime().GenerateMessageSend(*this, ReturnValueSlot(), |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 954 | getContext().UnsignedLongTy, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 955 | FastEnumSel, |
David Chisnall | c6cd5fd | 2010-04-28 19:33:36 +0000 | [diff] [blame] | 956 | Collection, Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 957 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 958 | // If we got a zero count, we're done. |
| 959 | llvm::Value *refetchCount = CountRV.getScalarVal(); |
| 960 | |
| 961 | // (note that the message send might split FetchMoreBB) |
| 962 | index->addIncoming(zero, Builder.GetInsertBlock()); |
| 963 | count->addIncoming(refetchCount, Builder.GetInsertBlock()); |
| 964 | |
| 965 | Builder.CreateCondBr(Builder.CreateICmpEQ(refetchCount, zero), |
| 966 | EmptyBB, LoopBodyBB); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 967 | |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 968 | // No more elements. |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 969 | EmitBlock(EmptyBB); |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 970 | |
John McCall | 57b3b6a | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 971 | if (!elementIsVariable) { |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 972 | // If the element was not a declaration, set it to be null. |
| 973 | |
John McCall | d88687f | 2011-01-07 01:49:06 +0000 | [diff] [blame] | 974 | llvm::Value *null = llvm::Constant::getNullValue(convertedElementType); |
| 975 | elementLValue = EmitLValue(cast<Expr>(S.getElement())); |
| 976 | EmitStoreThroughLValue(RValue::get(null), elementLValue, elementType); |
Anders Carlsson | f484c31 | 2008-08-31 02:33:12 +0000 | [diff] [blame] | 977 | } |
| 978 | |
Devang Patel | bcbd03a | 2011-01-19 01:36:36 +0000 | [diff] [blame] | 979 | if (DI) { |
| 980 | DI->setLocation(S.getSourceRange().getEnd()); |
| 981 | DI->EmitRegionEnd(Builder); |
| 982 | } |
| 983 | |
John McCall | ff8e115 | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 984 | EmitBlock(LoopEnd.getBlock()); |
Anders Carlsson | 3d8400d | 2008-08-30 19:51:14 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 987 | void CodeGenFunction::EmitObjCAtTryStmt(const ObjCAtTryStmt &S) { |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 988 | CGM.getObjCRuntime().EmitTryStmt(*this, S); |
Anders Carlsson | 64d5d6c | 2008-09-09 10:04:29 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | void CodeGenFunction::EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S) { |
Anders Carlsson | 64d5d6c | 2008-09-09 10:04:29 +0000 | [diff] [blame] | 992 | CGM.getObjCRuntime().EmitThrowStmt(*this, S); |
| 993 | } |
| 994 | |
Chris Lattner | 10cac6f | 2008-11-15 21:26:17 +0000 | [diff] [blame] | 995 | void CodeGenFunction::EmitObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 996 | const ObjCAtSynchronizedStmt &S) { |
John McCall | f1549f6 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 997 | CGM.getObjCRuntime().EmitSynchronizedStmt(*this, S); |
Chris Lattner | 10cac6f | 2008-11-15 21:26:17 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Ted Kremenek | 2979ec7 | 2008-04-09 15:51:31 +0000 | [diff] [blame] | 1000 | CGObjCRuntime::~CGObjCRuntime() {} |