2007-08-21 21:43:55 +04:00
|
|
|
//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 22:59:25 +03:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-08-21 21:43:55 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This contains code to emit Objective-C code as LLVM code.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-19 04:36:36 +03:00
|
|
|
#include "CGDebugInfo.h"
|
2008-04-09 19:51:31 +04:00
|
|
|
#include "CGObjCRuntime.h"
|
2007-08-21 21:43:55 +04:00
|
|
|
#include "CodeGenFunction.h"
|
|
|
|
#include "CodeGenModule.h"
|
2008-08-29 12:11:39 +04:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2008-08-11 09:35:13 +04:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2009-04-26 05:32:48 +04:00
|
|
|
#include "clang/AST/StmtObjC.h"
|
2008-09-03 04:27:26 +04:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2008-08-30 23:51:14 +04:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2008-09-24 08:04:31 +04:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2007-08-21 21:43:55 +04:00
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
|
|
|
|
2008-06-24 21:04:18 +04:00
|
|
|
/// Emits an instance of NSConstantString representing the object.
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::Value *CodeGenFunction::EmitObjCStringLiteral(const ObjCStringLiteral *E)
|
2008-11-26 00:53:21 +03:00
|
|
|
{
|
2010-01-23 05:40:42 +03:00
|
|
|
llvm::Constant *C =
|
|
|
|
CGM.getObjCRuntime().GenerateConstantString(E->getString());
|
2008-08-20 04:28:19 +04:00
|
|
|
// FIXME: This bitcast should just be made an invariant on the Runtime.
|
2009-07-29 22:54:39 +04:00
|
|
|
return llvm::ConstantExpr::getBitCast(C, ConvertType(E->getType()));
|
2008-06-24 21:04:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit a selector.
|
|
|
|
llvm::Value *CodeGenFunction::EmitObjCSelectorExpr(const ObjCSelectorExpr *E) {
|
|
|
|
// Untyped selector.
|
|
|
|
// Note that this implementation allows for non-constant strings to be passed
|
|
|
|
// as arguments to @selector(). Currently, the only thing preventing this
|
|
|
|
// behaviour is the type checking in the front end.
|
2010-02-03 23:11:42 +03:00
|
|
|
return CGM.getObjCRuntime().GetSelector(Builder, E->getSelector());
|
2008-06-24 21:04:18 +04:00
|
|
|
}
|
|
|
|
|
2008-08-20 04:28:19 +04:00
|
|
|
llvm::Value *CodeGenFunction::EmitObjCProtocolExpr(const ObjCProtocolExpr *E) {
|
|
|
|
// FIXME: This should pass the Decl not the name.
|
|
|
|
return CGM.getObjCRuntime().GenerateProtocolRef(Builder, E->getProtocol());
|
|
|
|
}
|
2008-06-24 21:04:18 +04:00
|
|
|
|
|
|
|
|
2010-05-22 05:48:05 +04:00
|
|
|
RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E,
|
|
|
|
ReturnValueSlot Return) {
|
2008-06-24 21:04:18 +04:00
|
|
|
// Only the lookup mechanism and first two arguments of the method
|
|
|
|
// implementation vary between runtimes. We can get the receiver and
|
|
|
|
// arguments in generic code.
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-08-11 22:12:00 +04:00
|
|
|
CGObjCRuntime &Runtime = CGM.getObjCRuntime();
|
2008-06-24 21:04:18 +04:00
|
|
|
bool isSuperMessage = false;
|
2008-08-25 12:19:24 +04:00
|
|
|
bool isClassMessage = false;
|
2010-04-28 23:33:36 +04:00
|
|
|
ObjCInterfaceDecl *OID = 0;
|
2008-06-24 21:04:18 +04:00
|
|
|
// Find the receiver
|
2010-04-22 07:17:06 +04:00
|
|
|
llvm::Value *Receiver = 0;
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
switch (E->getReceiverKind()) {
|
|
|
|
case ObjCMessageExpr::Instance:
|
|
|
|
Receiver = EmitScalarExpr(E->getInstanceReceiver());
|
|
|
|
break;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
case ObjCMessageExpr::Class: {
|
2010-05-18 00:12:43 +04:00
|
|
|
const ObjCObjectType *ObjTy
|
|
|
|
= E->getClassReceiver()->getAs<ObjCObjectType>();
|
|
|
|
assert(ObjTy && "Invalid Objective-C class message send");
|
|
|
|
OID = ObjTy->getInterface();
|
|
|
|
assert(OID && "Invalid Objective-C class message send");
|
2010-04-28 23:33:36 +04:00
|
|
|
Receiver = Runtime.GetClass(Builder, OID);
|
2008-08-25 12:19:24 +04:00
|
|
|
isClassMessage = true;
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ObjCMessageExpr::SuperInstance:
|
|
|
|
Receiver = LoadObjCSelf();
|
2008-06-24 21:04:18 +04:00
|
|
|
isSuperMessage = true;
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ObjCMessageExpr::SuperClass:
|
2008-06-24 21:04:18 +04:00
|
|
|
Receiver = LoadObjCSelf();
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101972 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 04:45:42 +04:00
|
|
|
isSuperMessage = true;
|
|
|
|
isClassMessage = true;
|
|
|
|
break;
|
2008-06-24 21:04:18 +04:00
|
|
|
}
|
|
|
|
|
2008-08-30 07:02:31 +04:00
|
|
|
CallArgList Args;
|
2009-04-19 00:29:27 +04:00
|
|
|
EmitCallArgs(Args, E->getMethodDecl(), E->arg_begin(), E->arg_end());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-06-22 00:59:55 +04:00
|
|
|
QualType ResultType =
|
|
|
|
E->getMethodDecl() ? E->getMethodDecl()->getResultType() : E->getType();
|
|
|
|
|
2008-06-24 21:04:18 +04:00
|
|
|
if (isSuperMessage) {
|
2008-06-26 08:42:20 +04:00
|
|
|
// super is only valid in an Objective-C method
|
|
|
|
const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl);
|
2009-02-28 23:07:56 +03:00
|
|
|
bool isCategoryImpl = isa<ObjCCategoryImplDecl>(OMD->getDeclContext());
|
2010-06-22 00:59:55 +04:00
|
|
|
return Runtime.GenerateMessageSendSuper(*this, Return, ResultType,
|
2008-08-30 09:35:15 +04:00
|
|
|
E->getSelector(),
|
2008-08-25 12:19:24 +04:00
|
|
|
OMD->getClassInterface(),
|
2009-02-28 23:07:56 +03:00
|
|
|
isCategoryImpl,
|
2008-08-25 12:19:24 +04:00
|
|
|
Receiver,
|
2008-08-30 07:02:31 +04:00
|
|
|
isClassMessage,
|
2009-09-17 08:01:22 +04:00
|
|
|
Args,
|
|
|
|
E->getMethodDecl());
|
2008-06-24 21:04:18 +04:00
|
|
|
}
|
2009-09-17 08:01:22 +04:00
|
|
|
|
2010-06-22 00:59:55 +04:00
|
|
|
return Runtime.GenerateMessageSend(*this, Return, ResultType,
|
2010-05-22 05:48:05 +04:00
|
|
|
E->getSelector(),
|
2010-04-28 23:33:36 +04:00
|
|
|
Receiver, Args, OID,
|
2009-05-06 01:36:57 +04:00
|
|
|
E->getMethodDecl());
|
2007-08-21 21:43:55 +04:00
|
|
|
}
|
|
|
|
|
2008-08-26 12:29:31 +04:00
|
|
|
/// StartObjCMethod - Begin emission of an ObjCMethod. This generates
|
|
|
|
/// the LLVM function and sets the other context used by
|
|
|
|
/// CodeGenFunction.
|
2009-01-11 00:06:09 +03:00
|
|
|
void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD,
|
|
|
|
const ObjCContainerDecl *CD) {
|
2008-09-10 03:14:03 +04:00
|
|
|
FunctionArgList Args;
|
2010-04-06 01:09:15 +04:00
|
|
|
// Check if we should generate debug info for this method.
|
|
|
|
if (CGM.getDebugInfo() && !OMD->hasAttr<NoDebugAttr>())
|
|
|
|
DebugInfo = CGM.getDebugInfo();
|
|
|
|
|
2009-01-11 00:06:09 +03:00
|
|
|
llvm::Function *Fn = CGM.getObjCRuntime().GenerateMethod(OMD, CD);
|
2008-09-05 03:41:35 +04:00
|
|
|
|
2009-04-17 04:48:04 +04:00
|
|
|
const CGFunctionInfo &FI = CGM.getTypes().getFunctionInfo(OMD);
|
|
|
|
CGM.SetInternalFunctionAttributes(OMD, Fn, FI);
|
2008-06-17 22:05:57 +04:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
Args.push_back(std::make_pair(OMD->getSelfDecl(),
|
2008-09-10 03:14:03 +04:00
|
|
|
OMD->getSelfDecl()->getType()));
|
|
|
|
Args.push_back(std::make_pair(OMD->getCmdDecl(),
|
|
|
|
OMD->getCmdDecl()->getType()));
|
2008-06-17 22:05:57 +04:00
|
|
|
|
2009-02-20 21:43:26 +03:00
|
|
|
for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
|
|
|
|
E = OMD->param_end(); PI != E; ++PI)
|
|
|
|
Args.push_back(std::make_pair(*PI, (*PI)->getType()));
|
2008-08-16 07:19:19 +04:00
|
|
|
|
2011-01-13 21:57:25 +03:00
|
|
|
CurGD = OMD;
|
|
|
|
|
2010-02-15 21:08:38 +03:00
|
|
|
StartFunction(OMD, OMD->getResultType(), Fn, Args, OMD->getLocStart());
|
2008-08-26 12:29:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Generate an Objective-C method. An Objective-C method is a C function with
|
2009-09-09 19:08:12 +04:00
|
|
|
/// its pointer, name, and types registered in the class struture.
|
2008-08-26 12:29:31 +04:00
|
|
|
void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) {
|
2009-01-11 00:06:09 +03:00
|
|
|
StartObjCMethod(OMD, OMD->getClassInterface());
|
2009-06-30 06:35:26 +04:00
|
|
|
EmitStmt(OMD->getBody());
|
|
|
|
FinishFunction(OMD->getBodyRBrace());
|
2008-08-26 12:29:31 +04:00
|
|
|
}
|
|
|
|
|
2009-05-16 11:57:57 +04:00
|
|
|
// FIXME: I wasn't sure about the synthesis approach. If we end up generating an
|
|
|
|
// AST for the whole body we can just fall back to having a GenerateFunction
|
|
|
|
// which takes the body Stmt.
|
2008-08-26 12:29:31 +04:00
|
|
|
|
|
|
|
/// GenerateObjCGetter - Generate an Objective-C property getter
|
2009-01-11 01:55:25 +03:00
|
|
|
/// function. The given Decl must be an ObjCImplementationDecl. @synthesize
|
|
|
|
/// is illegal within a category.
|
2008-12-09 23:23:04 +03:00
|
|
|
void CodeGenFunction::GenerateObjCGetter(ObjCImplementationDecl *IMP,
|
|
|
|
const ObjCPropertyImplDecl *PID) {
|
2008-09-24 08:04:31 +04:00
|
|
|
ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl();
|
2008-08-26 12:29:31 +04:00
|
|
|
const ObjCPropertyDecl *PD = PID->getPropertyDecl();
|
2010-04-13 22:32:24 +04:00
|
|
|
bool IsAtomic =
|
|
|
|
!(PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic);
|
2008-08-26 12:29:31 +04:00
|
|
|
ObjCMethodDecl *OMD = PD->getGetterMethodDecl();
|
|
|
|
assert(OMD && "Invalid call to generate getter (empty method)");
|
2009-01-11 00:06:09 +03:00
|
|
|
StartObjCMethod(OMD, IMP->getClassInterface());
|
2010-04-13 22:32:24 +04:00
|
|
|
|
2008-09-24 08:04:31 +04:00
|
|
|
// Determine if we should use an objc_getProperty call for
|
2008-12-09 02:56:17 +03:00
|
|
|
// this. Non-atomic properties are directly evaluated.
|
|
|
|
// atomic 'copy' and 'retain' properties are also directly
|
|
|
|
// evaluated in gc-only mode.
|
2008-09-24 08:04:31 +04:00
|
|
|
if (CGM.getLangOptions().getGCMode() != LangOptions::GCOnly &&
|
2010-04-13 22:32:24 +04:00
|
|
|
IsAtomic &&
|
2008-12-09 02:56:17 +03:00
|
|
|
(PD->getSetterKind() == ObjCPropertyDecl::Copy ||
|
|
|
|
PD->getSetterKind() == ObjCPropertyDecl::Retain)) {
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::Value *GetPropertyFn =
|
2008-09-24 08:04:31 +04:00
|
|
|
CGM.getObjCRuntime().GetPropertyGetFunction();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-09-24 08:04:31 +04:00
|
|
|
if (!GetPropertyFn) {
|
|
|
|
CGM.ErrorUnsupported(PID, "Obj-C getter requiring atomic copy");
|
|
|
|
FinishFunction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return (ivar-type) objc_getProperty((id) self, _cmd, offset, true).
|
|
|
|
// FIXME: Can't this be simpler? This might even be worse than the
|
|
|
|
// corresponding gcc code.
|
|
|
|
CodeGenTypes &Types = CGM.getTypes();
|
|
|
|
ValueDecl *Cmd = OMD->getCmdDecl();
|
|
|
|
llvm::Value *CmdVal = Builder.CreateLoad(LocalDeclMap[Cmd], "cmd");
|
|
|
|
QualType IdTy = getContext().getObjCIdType();
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::Value *SelfAsId =
|
2008-09-24 08:04:31 +04:00
|
|
|
Builder.CreateBitCast(LoadObjCSelf(), Types.ConvertType(IdTy));
|
2008-12-09 23:23:04 +03:00
|
|
|
llvm::Value *Offset = EmitIvarOffset(IMP->getClassInterface(), Ivar);
|
2008-09-24 08:04:31 +04:00
|
|
|
llvm::Value *True =
|
2009-07-25 03:12:58 +04:00
|
|
|
llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), 1);
|
2008-09-24 08:04:31 +04:00
|
|
|
CallArgList Args;
|
|
|
|
Args.push_back(std::make_pair(RValue::get(SelfAsId), IdTy));
|
|
|
|
Args.push_back(std::make_pair(RValue::get(CmdVal), Cmd->getType()));
|
|
|
|
Args.push_back(std::make_pair(RValue::get(Offset), getContext().LongTy));
|
|
|
|
Args.push_back(std::make_pair(RValue::get(True), getContext().BoolTy));
|
2009-02-04 02:43:59 +03:00
|
|
|
// FIXME: We shouldn't need to get the function info here, the
|
|
|
|
// runtime already should have computed it to build the function.
|
2010-02-06 00:31:56 +03:00
|
|
|
RValue RV = EmitCall(Types.getFunctionInfo(PD->getType(), Args,
|
2010-03-31 00:24:48 +04:00
|
|
|
FunctionType::ExtInfo()),
|
2009-12-24 22:25:24 +03:00
|
|
|
GetPropertyFn, ReturnValueSlot(), Args);
|
2008-09-24 08:04:31 +04:00
|
|
|
// We need to fix the type here. Ivars with copy & retain are
|
|
|
|
// always objects so we don't need to worry about complex or
|
|
|
|
// aggregates.
|
2009-09-09 19:08:12 +04:00
|
|
|
RV = RValue::get(Builder.CreateBitCast(RV.getScalarVal(),
|
2008-09-24 08:04:31 +04:00
|
|
|
Types.ConvertType(PD->getType())));
|
|
|
|
EmitReturnOfRValue(RV, PD->getType());
|
|
|
|
} else {
|
2010-03-26 00:56:43 +03:00
|
|
|
if (Ivar->getType()->isAnyComplexType()) {
|
2010-05-06 19:45:36 +04:00
|
|
|
LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(),
|
|
|
|
Ivar, 0);
|
2010-03-26 00:56:43 +03:00
|
|
|
ComplexPairTy Pair = LoadComplexFromAddr(LV.getAddress(),
|
|
|
|
LV.isVolatileQualified());
|
|
|
|
StoreComplexToAddr(Pair, ReturnValue, LV.isVolatileQualified());
|
|
|
|
}
|
|
|
|
else if (hasAggregateLLVMType(Ivar->getType())) {
|
2010-04-13 22:32:24 +04:00
|
|
|
bool IsStrong = false;
|
|
|
|
if ((IsAtomic || (IsStrong = IvarTypeWithAggrGCObjects(Ivar->getType())))
|
2010-04-13 04:38:05 +04:00
|
|
|
&& CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect
|
2010-12-27 01:13:16 +03:00
|
|
|
&& CGM.getObjCRuntime().GetGetStructFunction()) {
|
2010-05-06 19:45:36 +04:00
|
|
|
LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(),
|
|
|
|
Ivar, 0);
|
2010-04-13 04:38:05 +04:00
|
|
|
llvm::Value *GetCopyStructFn =
|
2010-12-27 01:13:16 +03:00
|
|
|
CGM.getObjCRuntime().GetGetStructFunction();
|
2010-04-13 04:38:05 +04:00
|
|
|
CodeGenTypes &Types = CGM.getTypes();
|
|
|
|
// objc_copyStruct (ReturnValue, &structIvar,
|
|
|
|
// sizeof (Type of Ivar), isAtomic, false);
|
|
|
|
CallArgList Args;
|
|
|
|
RValue RV = RValue::get(Builder.CreateBitCast(ReturnValue,
|
|
|
|
Types.ConvertType(getContext().VoidPtrTy)));
|
|
|
|
Args.push_back(std::make_pair(RV, getContext().VoidPtrTy));
|
|
|
|
RV = RValue::get(Builder.CreateBitCast(LV.getAddress(),
|
|
|
|
Types.ConvertType(getContext().VoidPtrTy)));
|
|
|
|
Args.push_back(std::make_pair(RV, getContext().VoidPtrTy));
|
|
|
|
// sizeof (Type of Ivar)
|
2011-01-19 04:58:38 +03:00
|
|
|
CharUnits Size = getContext().getTypeSizeInChars(Ivar->getType());
|
2010-04-13 04:38:05 +04:00
|
|
|
llvm::Value *SizeVal =
|
2011-01-19 04:58:38 +03:00
|
|
|
llvm::ConstantInt::get(Types.ConvertType(getContext().LongTy),
|
|
|
|
Size.getQuantity());
|
2010-04-13 04:38:05 +04:00
|
|
|
Args.push_back(std::make_pair(RValue::get(SizeVal),
|
|
|
|
getContext().LongTy));
|
|
|
|
llvm::Value *isAtomic =
|
2010-04-13 22:43:37 +04:00
|
|
|
llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy),
|
|
|
|
IsAtomic ? 1 : 0);
|
2010-04-13 04:38:05 +04:00
|
|
|
Args.push_back(std::make_pair(RValue::get(isAtomic),
|
|
|
|
getContext().BoolTy));
|
2010-04-13 22:32:24 +04:00
|
|
|
llvm::Value *hasStrong =
|
|
|
|
llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy),
|
|
|
|
IsStrong ? 1 : 0);
|
|
|
|
Args.push_back(std::make_pair(RValue::get(hasStrong),
|
|
|
|
getContext().BoolTy));
|
2010-04-13 04:38:05 +04:00
|
|
|
EmitCall(Types.getFunctionInfo(getContext().VoidTy, Args,
|
|
|
|
FunctionType::ExtInfo()),
|
|
|
|
GetCopyStructFn, ReturnValueSlot(), Args);
|
|
|
|
}
|
2010-05-06 19:45:36 +04:00
|
|
|
else {
|
|
|
|
if (PID->getGetterCXXConstructor()) {
|
|
|
|
ReturnStmt *Stmt =
|
|
|
|
new (getContext()) ReturnStmt(SourceLocation(),
|
2010-05-15 10:01:05 +04:00
|
|
|
PID->getGetterCXXConstructor(),
|
|
|
|
0);
|
2010-05-06 19:45:36 +04:00
|
|
|
EmitReturnStmt(*Stmt);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(),
|
|
|
|
Ivar, 0);
|
|
|
|
EmitAggregateCopy(ReturnValue, LV.getAddress(), Ivar->getType());
|
|
|
|
}
|
|
|
|
}
|
2009-07-31 02:28:39 +04:00
|
|
|
} else {
|
2010-05-06 19:45:36 +04:00
|
|
|
LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(),
|
|
|
|
Ivar, 0);
|
2009-03-03 21:49:40 +03:00
|
|
|
CodeGenTypes &Types = CGM.getTypes();
|
|
|
|
RValue RV = EmitLoadOfLValue(LV, Ivar->getType());
|
|
|
|
RV = RValue::get(Builder.CreateBitCast(RV.getScalarVal(),
|
2009-09-09 19:08:12 +04:00
|
|
|
Types.ConvertType(PD->getType())));
|
2009-03-03 21:49:40 +03:00
|
|
|
EmitReturnOfRValue(RV, PD->getType());
|
|
|
|
}
|
2008-09-24 08:04:31 +04:00
|
|
|
}
|
2008-08-26 12:29:31 +04:00
|
|
|
|
|
|
|
FinishFunction();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GenerateObjCSetter - Generate an Objective-C property setter
|
2009-01-11 01:55:25 +03:00
|
|
|
/// function. The given Decl must be an ObjCImplementationDecl. @synthesize
|
|
|
|
/// is illegal within a category.
|
2008-12-09 23:23:04 +03:00
|
|
|
void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP,
|
|
|
|
const ObjCPropertyImplDecl *PID) {
|
2008-09-24 10:32:09 +04:00
|
|
|
ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl();
|
2008-08-26 12:29:31 +04:00
|
|
|
const ObjCPropertyDecl *PD = PID->getPropertyDecl();
|
|
|
|
ObjCMethodDecl *OMD = PD->getSetterMethodDecl();
|
|
|
|
assert(OMD && "Invalid call to generate setter (empty method)");
|
2009-01-11 00:06:09 +03:00
|
|
|
StartObjCMethod(OMD, IMP->getClassInterface());
|
2008-08-16 07:19:19 +04:00
|
|
|
|
2008-09-24 10:32:09 +04:00
|
|
|
bool IsCopy = PD->getSetterKind() == ObjCPropertyDecl::Copy;
|
2009-09-09 19:08:12 +04:00
|
|
|
bool IsAtomic =
|
2008-09-24 10:32:09 +04:00
|
|
|
!(PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic);
|
|
|
|
|
|
|
|
// Determine if we should use an objc_setProperty call for
|
|
|
|
// this. Properties with 'copy' semantics always use it, as do
|
|
|
|
// non-atomic properties with 'release' semantics as long as we are
|
|
|
|
// not in gc-only mode.
|
|
|
|
if (IsCopy ||
|
|
|
|
(CGM.getLangOptions().getGCMode() != LangOptions::GCOnly &&
|
|
|
|
PD->getSetterKind() == ObjCPropertyDecl::Retain)) {
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::Value *SetPropertyFn =
|
2008-09-24 10:32:09 +04:00
|
|
|
CGM.getObjCRuntime().GetPropertySetFunction();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-09-24 10:32:09 +04:00
|
|
|
if (!SetPropertyFn) {
|
|
|
|
CGM.ErrorUnsupported(PID, "Obj-C getter requiring atomic copy");
|
|
|
|
FinishFunction();
|
|
|
|
return;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
// Emit objc_setProperty((id) self, _cmd, offset, arg,
|
2008-09-24 10:32:09 +04:00
|
|
|
// <is-atomic>, <is-copy>).
|
|
|
|
// FIXME: Can't this be simpler? This might even be worse than the
|
|
|
|
// corresponding gcc code.
|
|
|
|
CodeGenTypes &Types = CGM.getTypes();
|
|
|
|
ValueDecl *Cmd = OMD->getCmdDecl();
|
|
|
|
llvm::Value *CmdVal = Builder.CreateLoad(LocalDeclMap[Cmd], "cmd");
|
|
|
|
QualType IdTy = getContext().getObjCIdType();
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::Value *SelfAsId =
|
2008-09-24 10:32:09 +04:00
|
|
|
Builder.CreateBitCast(LoadObjCSelf(), Types.ConvertType(IdTy));
|
2008-12-09 23:23:04 +03:00
|
|
|
llvm::Value *Offset = EmitIvarOffset(IMP->getClassInterface(), Ivar);
|
2009-02-20 21:43:26 +03:00
|
|
|
llvm::Value *Arg = LocalDeclMap[*OMD->param_begin()];
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::Value *ArgAsId =
|
2008-09-24 10:32:09 +04:00
|
|
|
Builder.CreateBitCast(Builder.CreateLoad(Arg, "arg"),
|
|
|
|
Types.ConvertType(IdTy));
|
|
|
|
llvm::Value *True =
|
2009-07-25 03:12:58 +04:00
|
|
|
llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), 1);
|
2008-09-24 10:32:09 +04:00
|
|
|
llvm::Value *False =
|
2009-07-25 03:12:58 +04:00
|
|
|
llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), 0);
|
2008-09-24 10:32:09 +04:00
|
|
|
CallArgList Args;
|
|
|
|
Args.push_back(std::make_pair(RValue::get(SelfAsId), IdTy));
|
|
|
|
Args.push_back(std::make_pair(RValue::get(CmdVal), Cmd->getType()));
|
|
|
|
Args.push_back(std::make_pair(RValue::get(Offset), getContext().LongTy));
|
|
|
|
Args.push_back(std::make_pair(RValue::get(ArgAsId), IdTy));
|
2009-09-09 19:08:12 +04:00
|
|
|
Args.push_back(std::make_pair(RValue::get(IsAtomic ? True : False),
|
2008-09-24 10:32:09 +04:00
|
|
|
getContext().BoolTy));
|
2009-09-09 19:08:12 +04:00
|
|
|
Args.push_back(std::make_pair(RValue::get(IsCopy ? True : False),
|
2008-09-24 10:32:09 +04:00
|
|
|
getContext().BoolTy));
|
2009-05-16 11:57:57 +04:00
|
|
|
// FIXME: We shouldn't need to get the function info here, the runtime
|
|
|
|
// already should have computed it to build the function.
|
2010-02-06 00:31:56 +03:00
|
|
|
EmitCall(Types.getFunctionInfo(getContext().VoidTy, Args,
|
2010-03-31 00:24:48 +04:00
|
|
|
FunctionType::ExtInfo()),
|
|
|
|
SetPropertyFn,
|
2009-12-24 22:25:24 +03:00
|
|
|
ReturnValueSlot(), Args);
|
2010-04-13 04:38:05 +04:00
|
|
|
} else if (IsAtomic && hasAggregateLLVMType(Ivar->getType()) &&
|
|
|
|
!Ivar->getType()->isAnyComplexType() &&
|
|
|
|
IndirectObjCSetterArg(*CurFnInfo)
|
2010-12-27 01:13:16 +03:00
|
|
|
&& CGM.getObjCRuntime().GetSetStructFunction()) {
|
2010-04-13 04:38:05 +04:00
|
|
|
// objc_copyStruct (&structIvar, &Arg,
|
|
|
|
// sizeof (struct something), true, false);
|
|
|
|
llvm::Value *GetCopyStructFn =
|
2010-12-27 01:13:16 +03:00
|
|
|
CGM.getObjCRuntime().GetSetStructFunction();
|
2010-04-13 04:38:05 +04:00
|
|
|
CodeGenTypes &Types = CGM.getTypes();
|
|
|
|
CallArgList Args;
|
|
|
|
LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), Ivar, 0);
|
|
|
|
RValue RV = RValue::get(Builder.CreateBitCast(LV.getAddress(),
|
|
|
|
Types.ConvertType(getContext().VoidPtrTy)));
|
|
|
|
Args.push_back(std::make_pair(RV, getContext().VoidPtrTy));
|
|
|
|
llvm::Value *Arg = LocalDeclMap[*OMD->param_begin()];
|
|
|
|
llvm::Value *ArgAsPtrTy =
|
|
|
|
Builder.CreateBitCast(Arg,
|
|
|
|
Types.ConvertType(getContext().VoidPtrTy));
|
|
|
|
RV = RValue::get(ArgAsPtrTy);
|
|
|
|
Args.push_back(std::make_pair(RV, getContext().VoidPtrTy));
|
|
|
|
// sizeof (Type of Ivar)
|
2011-01-19 04:58:38 +03:00
|
|
|
CharUnits Size = getContext().getTypeSizeInChars(Ivar->getType());
|
2010-04-13 04:38:05 +04:00
|
|
|
llvm::Value *SizeVal =
|
2011-01-19 04:58:38 +03:00
|
|
|
llvm::ConstantInt::get(Types.ConvertType(getContext().LongTy),
|
|
|
|
Size.getQuantity());
|
2010-04-13 04:38:05 +04:00
|
|
|
Args.push_back(std::make_pair(RValue::get(SizeVal),
|
|
|
|
getContext().LongTy));
|
|
|
|
llvm::Value *True =
|
|
|
|
llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), 1);
|
|
|
|
Args.push_back(std::make_pair(RValue::get(True), getContext().BoolTy));
|
|
|
|
llvm::Value *False =
|
|
|
|
llvm::ConstantInt::get(Types.ConvertType(getContext().BoolTy), 0);
|
|
|
|
Args.push_back(std::make_pair(RValue::get(False), getContext().BoolTy));
|
|
|
|
EmitCall(Types.getFunctionInfo(getContext().VoidTy, Args,
|
|
|
|
FunctionType::ExtInfo()),
|
|
|
|
GetCopyStructFn, ReturnValueSlot(), Args);
|
2010-05-06 19:45:36 +04:00
|
|
|
} else if (PID->getSetterCXXAssignment()) {
|
2010-12-05 05:00:02 +03:00
|
|
|
EmitIgnoredExpr(PID->getSetterCXXAssignment());
|
2008-09-24 10:32:09 +04:00
|
|
|
} else {
|
2009-10-27 22:21:30 +03:00
|
|
|
// FIXME: Find a clean way to avoid AST node creation.
|
2008-09-24 10:32:09 +04:00
|
|
|
SourceLocation Loc = PD->getLocation();
|
|
|
|
ValueDecl *Self = OMD->getSelfDecl();
|
|
|
|
ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl();
|
2010-11-18 09:31:45 +03:00
|
|
|
DeclRefExpr Base(Self, Self->getType(), VK_RValue, Loc);
|
2009-02-20 21:43:26 +03:00
|
|
|
ParmVarDecl *ArgDecl = *OMD->param_begin();
|
2010-11-18 09:31:45 +03:00
|
|
|
DeclRefExpr Arg(ArgDecl, ArgDecl->getType(), VK_LValue, Loc);
|
2009-10-27 22:21:30 +03:00
|
|
|
ObjCIvarRefExpr IvarRef(Ivar, Ivar->getType(), Loc, &Base, true, true);
|
|
|
|
|
|
|
|
// The property type can differ from the ivar type in some situations with
|
|
|
|
// Objective-C pointer types, we can always bit cast the RHS in these cases.
|
|
|
|
if (getContext().getCanonicalType(Ivar->getType()) !=
|
|
|
|
getContext().getCanonicalType(ArgDecl->getType())) {
|
2010-08-07 10:22:56 +04:00
|
|
|
ImplicitCastExpr ArgCasted(ImplicitCastExpr::OnStack,
|
2010-08-25 15:45:40 +04:00
|
|
|
Ivar->getType(), CK_BitCast, &Arg,
|
2010-08-25 14:28:54 +04:00
|
|
|
VK_RValue);
|
2010-08-25 15:45:40 +04:00
|
|
|
BinaryOperator Assign(&IvarRef, &ArgCasted, BO_Assign,
|
2010-11-18 09:31:45 +03:00
|
|
|
Ivar->getType(), VK_RValue, OK_Ordinary, Loc);
|
2009-10-27 22:21:30 +03:00
|
|
|
EmitStmt(&Assign);
|
|
|
|
} else {
|
2010-08-25 15:45:40 +04:00
|
|
|
BinaryOperator Assign(&IvarRef, &Arg, BO_Assign,
|
2010-11-18 09:31:45 +03:00
|
|
|
Ivar->getType(), VK_RValue, OK_Ordinary, Loc);
|
2009-10-27 22:21:30 +03:00
|
|
|
EmitStmt(&Assign);
|
|
|
|
}
|
2008-09-24 10:32:09 +04:00
|
|
|
}
|
2008-08-26 12:29:31 +04:00
|
|
|
|
|
|
|
FinishFunction();
|
2008-06-17 22:05:57 +04:00
|
|
|
}
|
|
|
|
|
2010-04-29 01:28:56 +04:00
|
|
|
void CodeGenFunction::GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP,
|
|
|
|
ObjCMethodDecl *MD,
|
|
|
|
bool ctor) {
|
2011-01-08 23:30:50 +03:00
|
|
|
llvm::SmallVector<CXXCtorInitializer *, 8> IvarInitializers;
|
2010-04-29 01:28:56 +04:00
|
|
|
MD->createImplicitParams(CGM.getContext(), IMP->getClassInterface());
|
|
|
|
StartObjCMethod(MD, IMP->getClassInterface());
|
|
|
|
for (ObjCImplementationDecl::init_const_iterator B = IMP->init_begin(),
|
|
|
|
E = IMP->init_end(); B != E; ++B) {
|
2011-01-08 23:30:50 +03:00
|
|
|
CXXCtorInitializer *Member = (*B);
|
2010-04-29 01:28:56 +04:00
|
|
|
IvarInitializers.push_back(Member);
|
|
|
|
}
|
|
|
|
if (ctor) {
|
|
|
|
for (unsigned I = 0, E = IvarInitializers.size(); I != E; ++I) {
|
2011-01-08 23:30:50 +03:00
|
|
|
CXXCtorInitializer *IvarInit = IvarInitializers[I];
|
2010-12-04 12:14:42 +03:00
|
|
|
FieldDecl *Field = IvarInit->getAnyMember();
|
2010-04-29 01:28:56 +04:00
|
|
|
ObjCIvarDecl *Ivar = cast<ObjCIvarDecl>(Field);
|
2010-04-29 02:30:33 +04:00
|
|
|
LValue LV = EmitLValueForIvar(TypeOfSelfObject(),
|
|
|
|
LoadObjCSelf(), Ivar, 0);
|
2010-09-15 14:14:12 +04:00
|
|
|
EmitAggExpr(IvarInit->getInit(), AggValueSlot::forLValue(LV, true));
|
2010-04-29 01:28:56 +04:00
|
|
|
}
|
|
|
|
// constructor returns 'self'.
|
|
|
|
CodeGenTypes &Types = CGM.getTypes();
|
|
|
|
QualType IdTy(CGM.getContext().getObjCIdType());
|
|
|
|
llvm::Value *SelfAsId =
|
|
|
|
Builder.CreateBitCast(LoadObjCSelf(), Types.ConvertType(IdTy));
|
|
|
|
EmitReturnOfRValue(RValue::get(SelfAsId), IdTy);
|
2010-05-06 04:20:39 +04:00
|
|
|
} else {
|
2010-04-29 01:28:56 +04:00
|
|
|
// dtor
|
|
|
|
for (size_t i = IvarInitializers.size(); i > 0; --i) {
|
2010-12-04 12:14:42 +03:00
|
|
|
FieldDecl *Field = IvarInitializers[i - 1]->getAnyMember();
|
2010-04-29 01:28:56 +04:00
|
|
|
QualType FieldType = Field->getType();
|
2010-04-29 02:30:33 +04:00
|
|
|
const ConstantArrayType *Array =
|
|
|
|
getContext().getAsConstantArrayType(FieldType);
|
|
|
|
if (Array)
|
|
|
|
FieldType = getContext().getBaseElementType(FieldType);
|
|
|
|
|
2010-04-29 01:28:56 +04:00
|
|
|
ObjCIvarDecl *Ivar = cast<ObjCIvarDecl>(Field);
|
|
|
|
LValue LV = EmitLValueForIvar(TypeOfSelfObject(),
|
|
|
|
LoadObjCSelf(), Ivar, 0);
|
|
|
|
const RecordType *RT = FieldType->getAs<RecordType>();
|
|
|
|
CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getDecl());
|
2010-07-01 18:13:13 +04:00
|
|
|
CXXDestructorDecl *Dtor = FieldClassDecl->getDestructor();
|
2010-05-06 04:20:39 +04:00
|
|
|
if (!Dtor->isTrivial()) {
|
2010-05-04 23:29:32 +04:00
|
|
|
if (Array) {
|
|
|
|
const llvm::Type *BasePtr = ConvertType(FieldType);
|
|
|
|
BasePtr = llvm::PointerType::getUnqual(BasePtr);
|
|
|
|
llvm::Value *BaseAddrPtr =
|
|
|
|
Builder.CreateBitCast(LV.getAddress(), BasePtr);
|
|
|
|
EmitCXXAggrDestructorCall(Dtor,
|
|
|
|
Array, BaseAddrPtr);
|
2010-05-06 04:20:39 +04:00
|
|
|
} else {
|
2010-05-04 23:29:32 +04:00
|
|
|
EmitCXXDestructorCall(Dtor,
|
|
|
|
Dtor_Complete, /*ForVirtualBase=*/false,
|
|
|
|
LV.getAddress());
|
2010-05-06 04:20:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-29 01:28:56 +04:00
|
|
|
}
|
|
|
|
FinishFunction();
|
|
|
|
}
|
|
|
|
|
2010-04-13 04:38:05 +04:00
|
|
|
bool CodeGenFunction::IndirectObjCSetterArg(const CGFunctionInfo &FI) {
|
|
|
|
CGFunctionInfo::const_arg_iterator it = FI.arg_begin();
|
|
|
|
it++; it++;
|
|
|
|
const ABIArgInfo &AI = it->info;
|
|
|
|
// FIXME. Is this sufficient check?
|
|
|
|
return (AI.getKind() == ABIArgInfo::Indirect);
|
|
|
|
}
|
|
|
|
|
2010-04-13 22:32:24 +04:00
|
|
|
bool CodeGenFunction::IvarTypeWithAggrGCObjects(QualType Ty) {
|
|
|
|
if (CGM.getLangOptions().getGCMode() == LangOptions::NonGC)
|
|
|
|
return false;
|
|
|
|
if (const RecordType *FDTTy = Ty.getTypePtr()->getAs<RecordType>())
|
|
|
|
return FDTTy->getDecl()->hasObjectMember();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-24 08:04:31 +04:00
|
|
|
llvm::Value *CodeGenFunction::LoadObjCSelf() {
|
2008-08-16 07:19:19 +04:00
|
|
|
const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl);
|
|
|
|
return Builder.CreateLoad(LocalDeclMap[OMD->getSelfDecl()], "self");
|
2008-06-17 22:05:57 +04:00
|
|
|
}
|
|
|
|
|
2009-02-03 03:09:52 +03:00
|
|
|
QualType CodeGenFunction::TypeOfSelfObject() {
|
|
|
|
const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl);
|
|
|
|
ImplicitParamDecl *selfDecl = OMD->getSelfDecl();
|
2009-07-11 03:34:53 +04:00
|
|
|
const ObjCObjectPointerType *PTy = cast<ObjCObjectPointerType>(
|
|
|
|
getContext().getCanonicalType(selfDecl->getType()));
|
2009-02-03 03:09:52 +03:00
|
|
|
return PTy->getPointeeType();
|
|
|
|
}
|
|
|
|
|
2010-12-04 06:11:00 +03:00
|
|
|
LValue
|
|
|
|
CodeGenFunction::EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E) {
|
|
|
|
// This is a special l-value that just issues sends when we load or
|
|
|
|
// store through it.
|
|
|
|
|
|
|
|
// For certain base kinds, we need to emit the base immediately.
|
|
|
|
llvm::Value *Base;
|
|
|
|
if (E->isSuperReceiver())
|
|
|
|
Base = LoadObjCSelf();
|
|
|
|
else if (E->isClassReceiver())
|
|
|
|
Base = CGM.getObjCRuntime().GetClass(Builder, E->getClassReceiver());
|
|
|
|
else
|
|
|
|
Base = EmitScalarExpr(E->getBase());
|
|
|
|
return LValue::MakePropertyRef(E, Base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static RValue GenerateMessageSendSuper(CodeGenFunction &CGF,
|
|
|
|
ReturnValueSlot Return,
|
|
|
|
QualType ResultType,
|
|
|
|
Selector S,
|
|
|
|
llvm::Value *Receiver,
|
|
|
|
const CallArgList &CallArgs) {
|
|
|
|
const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CGF.CurFuncDecl);
|
2009-03-20 22:18:21 +03:00
|
|
|
bool isClassMessage = OMD->isClassMethod();
|
|
|
|
bool isCategoryImpl = isa<ObjCCategoryImplDecl>(OMD->getDeclContext());
|
2010-12-04 06:11:00 +03:00
|
|
|
return CGF.CGM.getObjCRuntime()
|
|
|
|
.GenerateMessageSendSuper(CGF, Return, ResultType,
|
|
|
|
S, OMD->getClassInterface(),
|
|
|
|
isCategoryImpl, Receiver,
|
|
|
|
isClassMessage, CallArgs);
|
2009-03-20 22:18:21 +03:00
|
|
|
}
|
|
|
|
|
2010-12-04 05:32:38 +03:00
|
|
|
RValue CodeGenFunction::EmitLoadOfPropertyRefLValue(LValue LV,
|
|
|
|
ReturnValueSlot Return) {
|
|
|
|
const ObjCPropertyRefExpr *E = LV.getPropertyRefExpr();
|
2010-12-02 04:19:52 +03:00
|
|
|
QualType ResultType;
|
|
|
|
Selector S;
|
|
|
|
if (E->isExplicitProperty()) {
|
|
|
|
const ObjCPropertyDecl *Property = E->getExplicitProperty();
|
|
|
|
S = Property->getGetterName();
|
|
|
|
ResultType = E->getType();
|
2009-07-31 02:28:39 +04:00
|
|
|
} else {
|
2010-12-02 04:19:52 +03:00
|
|
|
const ObjCMethodDecl *Getter = E->getImplicitPropertyGetter();
|
|
|
|
S = Getter->getSelector();
|
|
|
|
ResultType = Getter->getResultType(); // with reference!
|
2008-11-22 21:39:36 +03:00
|
|
|
}
|
2010-12-02 04:19:52 +03:00
|
|
|
|
2010-12-04 06:11:00 +03:00
|
|
|
llvm::Value *Receiver = LV.getPropertyRefBaseAddr();
|
|
|
|
|
|
|
|
// Accesses to 'super' follow a different code path.
|
2010-12-02 04:19:52 +03:00
|
|
|
if (E->isSuperReceiver())
|
2010-12-04 06:11:00 +03:00
|
|
|
return GenerateMessageSendSuper(*this, Return, ResultType,
|
|
|
|
S, Receiver, CallArgList());
|
2010-12-02 04:19:52 +03:00
|
|
|
|
2010-12-04 05:32:38 +03:00
|
|
|
const ObjCInterfaceDecl *ReceiverClass
|
|
|
|
= (E->isClassReceiver() ? E->getClassReceiver() : 0);
|
2010-12-02 04:19:52 +03:00
|
|
|
return CGM.getObjCRuntime().
|
|
|
|
GenerateMessageSend(*this, Return, ResultType, S,
|
|
|
|
Receiver, CallArgList(), ReceiverClass);
|
2008-08-27 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2010-12-04 05:32:38 +03:00
|
|
|
void CodeGenFunction::EmitStoreThroughPropertyRefLValue(RValue Src,
|
|
|
|
LValue Dst) {
|
|
|
|
const ObjCPropertyRefExpr *E = Dst.getPropertyRefExpr();
|
2010-12-02 04:19:52 +03:00
|
|
|
Selector S = E->getSetterSelector();
|
|
|
|
QualType ArgType;
|
|
|
|
if (E->isImplicitProperty()) {
|
|
|
|
const ObjCMethodDecl *Setter = E->getImplicitPropertySetter();
|
|
|
|
ObjCMethodDecl::param_iterator P = Setter->param_begin();
|
|
|
|
ArgType = (*P)->getType();
|
|
|
|
} else {
|
|
|
|
ArgType = E->getType();
|
|
|
|
}
|
|
|
|
|
2010-12-04 06:11:00 +03:00
|
|
|
CallArgList Args;
|
|
|
|
Args.push_back(std::make_pair(Src, ArgType));
|
|
|
|
|
|
|
|
llvm::Value *Receiver = Dst.getPropertyRefBaseAddr();
|
|
|
|
QualType ResultType = getContext().VoidTy;
|
|
|
|
|
2010-12-02 04:19:52 +03:00
|
|
|
if (E->isSuperReceiver()) {
|
2010-12-04 06:11:00 +03:00
|
|
|
GenerateMessageSendSuper(*this, ReturnValueSlot(),
|
|
|
|
ResultType, S, Receiver, Args);
|
2010-12-02 04:19:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-04 05:32:38 +03:00
|
|
|
const ObjCInterfaceDecl *ReceiverClass
|
|
|
|
= (E->isClassReceiver() ? E->getClassReceiver() : 0);
|
2010-12-02 04:19:52 +03:00
|
|
|
|
|
|
|
CGM.getObjCRuntime().GenerateMessageSend(*this, ReturnValueSlot(),
|
2010-12-04 06:11:00 +03:00
|
|
|
ResultType, S, Receiver, Args,
|
|
|
|
ReceiverClass);
|
2008-08-29 12:11:39 +04:00
|
|
|
}
|
|
|
|
|
2009-03-23 00:03:39 +03:00
|
|
|
void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::Constant *EnumerationMutationFn =
|
2008-09-24 08:04:31 +04:00
|
|
|
CGM.getObjCRuntime().EnumerationMutationFunction();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-09-24 08:04:31 +04:00
|
|
|
if (!EnumerationMutationFn) {
|
|
|
|
CGM.ErrorUnsupported(&S, "Obj-C fast enumeration for this runtime");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-19 04:36:36 +03:00
|
|
|
CGDebugInfo *DI = getDebugInfo();
|
|
|
|
if (DI) {
|
|
|
|
DI->setLocation(S.getSourceRange().getBegin());
|
|
|
|
DI->EmitRegionStart(Builder);
|
|
|
|
}
|
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
JumpDest LoopEnd = getJumpDestInCurrentScope("forcoll.end");
|
|
|
|
JumpDest AfterBody = getJumpDestInCurrentScope("forcoll.next");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-08-31 06:33:12 +04:00
|
|
|
// Fast enumeration state.
|
|
|
|
QualType StateTy = getContext().getObjCFastEnumerationStateType();
|
2010-02-09 05:48:28 +03:00
|
|
|
llvm::Value *StatePtr = CreateMemTemp(StateTy, "state.ptr");
|
2010-05-22 21:35:42 +04:00
|
|
|
EmitNullInitialization(StatePtr, StateTy);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-08-31 06:33:12 +04:00
|
|
|
// Number of elements in the items array.
|
2008-08-31 08:05:03 +04:00
|
|
|
static const unsigned NumItems = 16;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Fetch the countByEnumeratingWithState:objects:count: selector.
|
2010-03-30 15:36:44 +04:00
|
|
|
IdentifierInfo *II[] = {
|
|
|
|
&CGM.getContext().Idents.get("countByEnumeratingWithState"),
|
|
|
|
&CGM.getContext().Idents.get("objects"),
|
|
|
|
&CGM.getContext().Idents.get("count")
|
|
|
|
};
|
|
|
|
Selector FastEnumSel =
|
|
|
|
CGM.getContext().Selectors.getSelector(llvm::array_lengthof(II), &II[0]);
|
2008-08-31 06:33:12 +04:00
|
|
|
|
|
|
|
QualType ItemsTy =
|
|
|
|
getContext().getConstantArrayType(getContext().getObjCIdType(),
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::APInt(32, NumItems),
|
2008-08-31 06:33:12 +04:00
|
|
|
ArrayType::Normal, 0);
|
2010-02-09 05:48:28 +03:00
|
|
|
llvm::Value *ItemsPtr = CreateMemTemp(ItemsTy, "items.ptr");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Emit the collection pointer.
|
2008-08-31 06:33:12 +04:00
|
|
|
llvm::Value *Collection = EmitScalarExpr(S.getCollection());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Send it our message:
|
2008-08-31 06:33:12 +04:00
|
|
|
CallArgList Args;
|
2011-01-07 04:49:06 +03:00
|
|
|
|
|
|
|
// The first argument is a temporary of the enumeration-state type.
|
2009-09-09 19:08:12 +04:00
|
|
|
Args.push_back(std::make_pair(RValue::get(StatePtr),
|
2008-08-31 06:33:12 +04:00
|
|
|
getContext().getPointerType(StateTy)));
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// The second argument is a temporary array with space for NumItems
|
|
|
|
// pointers. We'll actually be loading elements from the array
|
|
|
|
// pointer written into the control state; this buffer is so that
|
|
|
|
// collections that *aren't* backed by arrays can still queue up
|
|
|
|
// batches of elements.
|
2009-09-09 19:08:12 +04:00
|
|
|
Args.push_back(std::make_pair(RValue::get(ItemsPtr),
|
2008-08-31 06:33:12 +04:00
|
|
|
getContext().getPointerType(ItemsTy)));
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// The third argument is the capacity of that temporary array.
|
2008-08-31 06:33:12 +04:00
|
|
|
const llvm::Type *UnsignedLongLTy = ConvertType(getContext().UnsignedLongTy);
|
2009-07-25 03:12:58 +04:00
|
|
|
llvm::Constant *Count = llvm::ConstantInt::get(UnsignedLongLTy, NumItems);
|
2009-09-09 19:08:12 +04:00
|
|
|
Args.push_back(std::make_pair(RValue::get(Count),
|
2008-09-09 05:06:48 +04:00
|
|
|
getContext().UnsignedLongTy));
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Start the enumeration.
|
2009-09-09 19:08:12 +04:00
|
|
|
RValue CountRV =
|
2010-05-22 05:48:05 +04:00
|
|
|
CGM.getObjCRuntime().GenerateMessageSend(*this, ReturnValueSlot(),
|
2008-08-31 06:33:12 +04:00
|
|
|
getContext().UnsignedLongTy,
|
|
|
|
FastEnumSel,
|
2010-04-28 23:33:36 +04:00
|
|
|
Collection, Args);
|
2008-08-31 06:33:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// The initial number of objects that were returned in the buffer.
|
|
|
|
llvm::Value *initialBufferLimit = CountRV.getScalarVal();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
llvm::BasicBlock *EmptyBB = createBasicBlock("forcoll.empty");
|
|
|
|
llvm::BasicBlock *LoopInitBB = createBasicBlock("forcoll.loopinit");
|
2008-08-31 06:33:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
llvm::Value *zero = llvm::Constant::getNullValue(UnsignedLongLTy);
|
2008-08-31 06:33:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// If the limit pointer was zero to begin with, the collection is
|
|
|
|
// empty; skip all this.
|
|
|
|
Builder.CreateCondBr(Builder.CreateICmpEQ(initialBufferLimit, zero, "iszero"),
|
|
|
|
EmptyBB, LoopInitBB);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Otherwise, initialize the loop.
|
|
|
|
EmitBlock(LoopInitBB);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Save the initial mutations value. This is the value at an
|
|
|
|
// address that was written into the state object by
|
|
|
|
// countByEnumeratingWithState:objects:count:.
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::Value *StateMutationsPtrPtr =
|
2008-08-31 08:05:03 +04:00
|
|
|
Builder.CreateStructGEP(StatePtr, 2, "mutationsptr.ptr");
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::Value *StateMutationsPtr = Builder.CreateLoad(StateMutationsPtrPtr,
|
2008-08-31 08:05:03 +04:00
|
|
|
"mutationsptr");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
llvm::Value *initialMutations =
|
|
|
|
Builder.CreateLoad(StateMutationsPtr, "forcoll.initial-mutations");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Start looping. This is the point we return to whenever we have a
|
|
|
|
// fresh, non-empty batch of objects.
|
|
|
|
llvm::BasicBlock *LoopBodyBB = createBasicBlock("forcoll.loopbody");
|
|
|
|
EmitBlock(LoopBodyBB);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// The current index into the buffer.
|
|
|
|
llvm::PHINode *index = Builder.CreatePHI(UnsignedLongLTy, "forcoll.index");
|
|
|
|
index->addIncoming(zero, LoopInitBB);
|
2008-08-31 06:33:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// The current buffer size.
|
|
|
|
llvm::PHINode *count = Builder.CreatePHI(UnsignedLongLTy, "forcoll.count");
|
|
|
|
count->addIncoming(initialBufferLimit, LoopInitBB);
|
2008-08-31 06:33:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Check whether the mutations value has changed from where it was
|
|
|
|
// at start. StateMutationsPtr should actually be invariant between
|
|
|
|
// refreshes.
|
2008-08-31 08:05:03 +04:00
|
|
|
StateMutationsPtr = Builder.CreateLoad(StateMutationsPtrPtr, "mutationsptr");
|
2011-01-07 04:49:06 +03:00
|
|
|
llvm::Value *currentMutations
|
|
|
|
= Builder.CreateLoad(StateMutationsPtr, "statemutations");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
llvm::BasicBlock *WasMutatedBB = createBasicBlock("forcoll.mutated");
|
|
|
|
llvm::BasicBlock *WasNotMutatedBB = createBasicBlock("forcool.notmutated");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
Builder.CreateCondBr(Builder.CreateICmpEQ(currentMutations, initialMutations),
|
|
|
|
WasNotMutatedBB, WasMutatedBB);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// If so, call the enumeration-mutation function.
|
|
|
|
EmitBlock(WasMutatedBB);
|
2008-08-31 08:05:03 +04:00
|
|
|
llvm::Value *V =
|
2009-09-09 19:08:12 +04:00
|
|
|
Builder.CreateBitCast(Collection,
|
2008-08-31 08:05:03 +04:00
|
|
|
ConvertType(getContext().getObjCIdType()),
|
|
|
|
"tmp");
|
2009-02-04 02:55:40 +03:00
|
|
|
CallArgList Args2;
|
2009-09-09 19:08:12 +04:00
|
|
|
Args2.push_back(std::make_pair(RValue::get(V),
|
2009-02-04 02:55:40 +03:00
|
|
|
getContext().getObjCIdType()));
|
2009-05-16 11:57:57 +04:00
|
|
|
// FIXME: We shouldn't need to get the function info here, the runtime already
|
|
|
|
// should have computed it to build the function.
|
2010-02-06 00:31:56 +03:00
|
|
|
EmitCall(CGM.getTypes().getFunctionInfo(getContext().VoidTy, Args2,
|
2010-03-31 00:24:48 +04:00
|
|
|
FunctionType::ExtInfo()),
|
2009-12-24 22:25:24 +03:00
|
|
|
EnumerationMutationFn, ReturnValueSlot(), Args2);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Otherwise, or if the mutation function returns, just continue.
|
|
|
|
EmitBlock(WasNotMutatedBB);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Initialize the element variable.
|
|
|
|
RunCleanupsScope elementVariableScope(*this);
|
|
|
|
bool elementIsDecl;
|
|
|
|
LValue elementLValue;
|
|
|
|
QualType elementType;
|
|
|
|
if (const DeclStmt *SD = dyn_cast<DeclStmt>(S.getElement())) {
|
|
|
|
EmitStmt(SD);
|
|
|
|
const VarDecl* D = cast<VarDecl>(SD->getSingleDecl());
|
2008-08-31 06:33:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
DeclRefExpr tempDRE(const_cast<VarDecl*>(D), D->getType(),
|
|
|
|
VK_LValue, SourceLocation());
|
|
|
|
elementLValue = EmitLValue(&tempDRE);
|
|
|
|
elementType = D->getType();
|
|
|
|
elementIsDecl = true;
|
|
|
|
} else {
|
|
|
|
elementLValue = LValue(); // suppress warning
|
|
|
|
elementType = cast<Expr>(S.getElement())->getType();
|
|
|
|
elementIsDecl = false;
|
|
|
|
}
|
|
|
|
const llvm::Type *convertedElementType = ConvertType(elementType);
|
2008-08-31 06:33:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Fetch the buffer out of the enumeration state.
|
|
|
|
// TODO: this pointer should actually be invariant between
|
|
|
|
// refreshes, which would help us do certain loop optimizations.
|
|
|
|
llvm::Value *StateItemsPtr =
|
|
|
|
Builder.CreateStructGEP(StatePtr, 1, "stateitems.ptr");
|
|
|
|
llvm::Value *EnumStateItems =
|
|
|
|
Builder.CreateLoad(StateItemsPtr, "stateitems");
|
2008-08-31 06:33:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Fetch the value at the current index from the buffer.
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::Value *CurrentItemPtr =
|
2011-01-07 04:49:06 +03:00
|
|
|
Builder.CreateGEP(EnumStateItems, index, "currentitem.ptr");
|
|
|
|
llvm::Value *CurrentItem = Builder.CreateLoad(CurrentItemPtr);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Cast that value to the right type.
|
|
|
|
CurrentItem = Builder.CreateBitCast(CurrentItem, convertedElementType,
|
|
|
|
"currentitem");
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Make sure we have an l-value. Yes, this gets evaluated every
|
|
|
|
// time through the loop.
|
|
|
|
if (!elementIsDecl)
|
|
|
|
elementLValue = EmitLValue(cast<Expr>(S.getElement()));
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
EmitStoreThroughLValue(RValue::get(CurrentItem), elementLValue, elementType);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Perform the loop body, setting up break and continue labels.
|
2009-02-10 08:52:02 +03:00
|
|
|
BreakContinueStack.push_back(BreakContinue(LoopEnd, AfterBody));
|
2011-01-07 04:49:06 +03:00
|
|
|
{
|
|
|
|
RunCleanupsScope Scope(*this);
|
|
|
|
EmitStmt(S.getBody());
|
|
|
|
}
|
2008-08-31 06:33:12 +04:00
|
|
|
BreakContinueStack.pop_back();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Destroy the element variable now.
|
|
|
|
elementVariableScope.ForceCleanup();
|
|
|
|
|
|
|
|
// Check whether there are more elements.
|
2010-07-24 01:56:41 +04:00
|
|
|
EmitBlock(AfterBody.getBlock());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
llvm::BasicBlock *FetchMoreBB = createBasicBlock("forcoll.refetch");
|
|
|
|
|
|
|
|
// First we check in the local buffer.
|
|
|
|
llvm::Value *indexPlusOne
|
|
|
|
= Builder.CreateAdd(index, llvm::ConstantInt::get(UnsignedLongLTy, 1));
|
|
|
|
|
|
|
|
// If we haven't overrun the buffer yet, we can continue.
|
|
|
|
Builder.CreateCondBr(Builder.CreateICmpULT(indexPlusOne, count),
|
|
|
|
LoopBodyBB, FetchMoreBB);
|
2009-01-06 21:56:31 +03:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
index->addIncoming(indexPlusOne, AfterBody.getBlock());
|
|
|
|
count->addIncoming(count, AfterBody.getBlock());
|
2008-08-31 06:33:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// Otherwise, we have to fetch more elements.
|
|
|
|
EmitBlock(FetchMoreBB);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
CountRV =
|
2010-05-22 05:48:05 +04:00
|
|
|
CGM.getObjCRuntime().GenerateMessageSend(*this, ReturnValueSlot(),
|
2008-08-31 06:33:12 +04:00
|
|
|
getContext().UnsignedLongTy,
|
2009-09-09 19:08:12 +04:00
|
|
|
FastEnumSel,
|
2010-04-28 23:33:36 +04:00
|
|
|
Collection, Args);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
// If we got a zero count, we're done.
|
|
|
|
llvm::Value *refetchCount = CountRV.getScalarVal();
|
|
|
|
|
|
|
|
// (note that the message send might split FetchMoreBB)
|
|
|
|
index->addIncoming(zero, Builder.GetInsertBlock());
|
|
|
|
count->addIncoming(refetchCount, Builder.GetInsertBlock());
|
|
|
|
|
|
|
|
Builder.CreateCondBr(Builder.CreateICmpEQ(refetchCount, zero),
|
|
|
|
EmptyBB, LoopBodyBB);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-08-31 06:33:12 +04:00
|
|
|
// No more elements.
|
2011-01-07 04:49:06 +03:00
|
|
|
EmitBlock(EmptyBB);
|
2008-08-31 06:33:12 +04:00
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
if (!elementIsDecl) {
|
2008-08-31 06:33:12 +04:00
|
|
|
// If the element was not a declaration, set it to be null.
|
|
|
|
|
2011-01-07 04:49:06 +03:00
|
|
|
llvm::Value *null = llvm::Constant::getNullValue(convertedElementType);
|
|
|
|
elementLValue = EmitLValue(cast<Expr>(S.getElement()));
|
|
|
|
EmitStoreThroughLValue(RValue::get(null), elementLValue, elementType);
|
2008-08-31 06:33:12 +04:00
|
|
|
}
|
|
|
|
|
2011-01-19 04:36:36 +03:00
|
|
|
if (DI) {
|
|
|
|
DI->setLocation(S.getSourceRange().getEnd());
|
|
|
|
DI->EmitRegionEnd(Builder);
|
|
|
|
}
|
|
|
|
|
2010-07-24 01:56:41 +04:00
|
|
|
EmitBlock(LoopEnd.getBlock());
|
2008-08-30 23:51:14 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
void CodeGenFunction::EmitObjCAtTryStmt(const ObjCAtTryStmt &S) {
|
2010-07-06 05:34:17 +04:00
|
|
|
CGM.getObjCRuntime().EmitTryStmt(*this, S);
|
2008-09-09 14:04:29 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
void CodeGenFunction::EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S) {
|
2008-09-09 14:04:29 +04:00
|
|
|
CGM.getObjCRuntime().EmitThrowStmt(*this, S);
|
|
|
|
}
|
|
|
|
|
2008-11-16 00:26:17 +03:00
|
|
|
void CodeGenFunction::EmitObjCAtSynchronizedStmt(
|
2009-09-09 19:08:12 +04:00
|
|
|
const ObjCAtSynchronizedStmt &S) {
|
2010-07-06 05:34:17 +04:00
|
|
|
CGM.getObjCRuntime().EmitSynchronizedStmt(*this, S);
|
2008-11-16 00:26:17 +03:00
|
|
|
}
|
|
|
|
|
2008-04-09 19:51:31 +04:00
|
|
|
CGObjCRuntime::~CGObjCRuntime() {}
|