2008-06-01 22:13:53 +08:00
|
|
|
//===------- CGObjCGNU.cpp - Emit LLVM Code from ASTs for a Module --------===//
|
2008-03-01 16:50:34 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-04-15 13:22:18 +08:00
|
|
|
// This provides Objective-C code generation targeting the GNU runtime. The
|
2008-06-01 22:13:53 +08:00
|
|
|
// class in this file generates structures used by the GNU Objective-C runtime
|
|
|
|
// library. These structures are defined in objc/objc.h and objc/objc-api.h in
|
|
|
|
// the GNU runtime distribution.
|
2008-03-01 16:50:34 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CGObjCRuntime.h"
|
2008-06-26 12:19:03 +08:00
|
|
|
#include "CodeGenModule.h"
|
2008-08-23 11:46:30 +08:00
|
|
|
#include "CodeGenFunction.h"
|
2011-01-28 19:13:47 +08:00
|
|
|
#include "CGCleanup.h"
|
2009-05-08 08:11:50 +08:00
|
|
|
|
2008-06-26 12:19:03 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2008-08-11 12:54:23 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
2008-08-13 08:59:25 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2009-07-19 03:43:29 +08:00
|
|
|
#include "clang/AST/RecordLayout.h"
|
2009-04-26 09:32:48 +08:00
|
|
|
#include "clang/AST/StmtObjC.h"
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "clang/Basic/FileManager.h"
|
2009-05-08 08:11:50 +08:00
|
|
|
|
|
|
|
#include "llvm/Intrinsics.h"
|
2008-03-01 16:50:34 +08:00
|
|
|
#include "llvm/Module.h"
|
2010-04-29 03:33:36 +08:00
|
|
|
#include "llvm/LLVMContext.h"
|
2008-03-01 16:50:34 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2008-06-01 22:13:53 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2011-03-21 05:35:39 +08:00
|
|
|
#include "llvm/Support/CallSite.h"
|
2008-08-16 06:20:32 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Target/TargetData.h"
|
2009-05-08 08:11:50 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
#include <cstdarg>
|
2009-01-27 13:06:01 +08:00
|
|
|
|
|
|
|
|
2008-06-26 12:19:03 +08:00
|
|
|
using namespace clang;
|
2008-09-09 09:06:48 +08:00
|
|
|
using namespace CodeGen;
|
2008-06-01 22:13:53 +08:00
|
|
|
|
2008-03-01 16:50:34 +08:00
|
|
|
|
|
|
|
namespace {
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Class that lazily initialises the runtime function. Avoids inserting the
|
|
|
|
/// types and the function declaration into a module if they're not used, and
|
|
|
|
/// avoids constructing the type more than once if it's used more than once.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
class LazyRuntimeFunction {
|
|
|
|
CodeGenModule *CGM;
|
2011-07-10 01:41:47 +08:00
|
|
|
std::vector<llvm::Type*> ArgTys;
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
const char *FunctionName;
|
2011-05-24 06:33:28 +08:00
|
|
|
llvm::Constant *Function;
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
public:
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Constructor leaves this class uninitialized, because it is intended to
|
|
|
|
/// be used as a field in another class and not all of the types that are
|
|
|
|
/// used as arguments will necessarily be available at construction time.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LazyRuntimeFunction() : CGM(0), FunctionName(0), Function(0) {}
|
|
|
|
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Initialises the lazy function with the name, return type, and the types
|
|
|
|
/// of the arguments.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
END_WITH_NULL
|
|
|
|
void init(CodeGenModule *Mod, const char *name,
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *RetTy, ...) {
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
CGM =Mod;
|
|
|
|
FunctionName = name;
|
|
|
|
Function = 0;
|
2011-03-25 19:57:33 +08:00
|
|
|
ArgTys.clear();
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
va_list Args;
|
|
|
|
va_start(Args, RetTy);
|
2011-07-10 01:41:47 +08:00
|
|
|
while (llvm::Type *ArgTy = va_arg(Args, llvm::Type*))
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
ArgTys.push_back(ArgTy);
|
|
|
|
va_end(Args);
|
|
|
|
// Push the return type on at the end so we can pop it off easily
|
|
|
|
ArgTys.push_back(RetTy);
|
|
|
|
}
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Overloaded cast operator, allows the class to be implicitly cast to an
|
|
|
|
/// LLVM constant.
|
2011-05-24 06:33:28 +08:00
|
|
|
operator llvm::Constant*() {
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
if (!Function) {
|
2011-03-25 19:57:33 +08:00
|
|
|
if (0 == FunctionName) return 0;
|
|
|
|
// We put the return type on the end of the vector, so pop it back off
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *RetTy = ArgTys.back();
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
ArgTys.pop_back();
|
|
|
|
llvm::FunctionType *FTy = llvm::FunctionType::get(RetTy, ArgTys, false);
|
|
|
|
Function =
|
2011-05-24 06:33:28 +08:00
|
|
|
cast<llvm::Constant>(CGM->CreateRuntimeFunction(FTy, FunctionName));
|
2011-03-25 19:57:33 +08:00
|
|
|
// We won't need to use the types again, so we may as well clean up the
|
|
|
|
// vector now
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
ArgTys.resize(0);
|
|
|
|
}
|
|
|
|
return Function;
|
|
|
|
}
|
2011-05-24 06:33:28 +08:00
|
|
|
operator llvm::Function*() {
|
2011-05-24 07:15:11 +08:00
|
|
|
return cast<llvm::Function>((llvm::Constant*)*this);
|
2011-05-24 06:33:28 +08:00
|
|
|
}
|
2011-05-24 07:15:11 +08:00
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-26 19:48:37 +08:00
|
|
|
/// GNU Objective-C runtime code generation. This class implements the parts of
|
|
|
|
/// Objective-C support that are specific to the GNU family of runtimes (GCC and
|
|
|
|
/// GNUstep).
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
class CGObjCGNU : public CGObjCRuntime {
|
2011-03-24 06:52:06 +08:00
|
|
|
protected:
|
2011-03-26 19:48:37 +08:00
|
|
|
/// The module that is using this class
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
CodeGenModule &CGM;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// The LLVM module into which output is inserted
|
2008-03-01 16:50:34 +08:00
|
|
|
llvm::Module &TheModule;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// strut objc_super. Used for sending messages to super. This structure
|
|
|
|
/// contains the receiver (object) and the expected class.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::StructType *ObjCSuperTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// struct objc_super*. The type of the argument to the superclass message
|
|
|
|
/// lookup functions.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::PointerType *PtrToObjCSuperTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// LLVM type for selectors. Opaque pointer (i8*) unless a header declaring
|
|
|
|
/// SEL is included in a header somewhere, in which case it will be whatever
|
|
|
|
/// type is declared in that header, most likely {i8*, i8*}.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::PointerType *SelectorTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// LLVM i8 type. Cached here to avoid repeatedly getting it in all of the
|
|
|
|
/// places where it's used
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::IntegerType *Int8Ty;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Pointer to i8 - LLVM type of char*, for all of the places where the
|
|
|
|
/// runtime needs to deal with C strings.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::PointerType *PtrToInt8Ty;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Instance Method Pointer type. This is a pointer to a function that takes,
|
|
|
|
/// at a minimum, an object and a selector, and is the generic type for
|
|
|
|
/// Objective-C methods. Due to differences between variadic / non-variadic
|
|
|
|
/// calling conventions, it must always be cast to the correct type before
|
|
|
|
/// actually being used.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::PointerType *IMPTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Type of an untyped Objective-C object. Clang treats id as a built-in type
|
|
|
|
/// when compiling Objective-C code, so this may be an opaque pointer (i8*),
|
|
|
|
/// but if the runtime header declaring it is included then it may be a
|
|
|
|
/// pointer to a structure.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::PointerType *IdTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Pointer to a pointer to an Objective-C object. Used in the new ABI
|
|
|
|
/// message lookup function and some GC-related functions.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::PointerType *PtrToIdTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// The clang type of id. Used when using the clang CGCall infrastructure to
|
|
|
|
/// call Objective-C methods.
|
2010-02-26 08:48:12 +08:00
|
|
|
CanQualType ASTIdTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// LLVM type for C int type.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::IntegerType *IntTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// LLVM type for an opaque pointer. This is identical to PtrToInt8Ty, but is
|
|
|
|
/// used in the code to document the difference between i8* meaning a pointer
|
|
|
|
/// to a C string and i8* meaning a pointer to some opaque type.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::PointerType *PtrTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// LLVM type for C long type. The runtime uses this in a lot of places where
|
|
|
|
/// it should be using intptr_t, but we can't fix this without breaking
|
|
|
|
/// compatibility with GCC...
|
2011-07-11 17:56:20 +08:00
|
|
|
llvm::IntegerType *LongTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// LLVM type for C size_t. Used in various runtime data structures.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::IntegerType *SizeTy;
|
2011-10-08 16:54:36 +08:00
|
|
|
/// LLVM type for C intptr_t.
|
|
|
|
llvm::IntegerType *IntPtrTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// LLVM type for C ptrdiff_t. Mainly used in property accessor functions.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::IntegerType *PtrDiffTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// LLVM type for C int*. Used for GCC-ABI-compatible non-fragile instance
|
|
|
|
/// variables.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::PointerType *PtrToIntTy;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// LLVM type for Objective-C BOOL type.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *BoolTy;
|
2011-10-04 23:35:30 +08:00
|
|
|
/// 32-bit integer type, to save us needing to look it up every time it's used.
|
|
|
|
llvm::IntegerType *Int32Ty;
|
|
|
|
/// 64-bit integer type, to save us needing to look it up every time it's used.
|
|
|
|
llvm::IntegerType *Int64Ty;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Metadata kind used to tie method lookups to message sends. The GNUstep
|
|
|
|
/// runtime provides some LLVM passes that can use this to do things like
|
|
|
|
/// automatic IMP caching and speculative inlining.
|
2011-03-24 06:52:06 +08:00
|
|
|
unsigned msgSendMDKind;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Helper function that generates a constant string and returns a pointer to
|
|
|
|
/// the start of the string. The result of this function can be used anywhere
|
|
|
|
/// where the C code specifies const char*.
|
2011-03-25 19:57:33 +08:00
|
|
|
llvm::Constant *MakeConstantString(const std::string &Str,
|
|
|
|
const std::string &Name="") {
|
|
|
|
llvm::Constant *ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
|
2011-07-21 22:31:17 +08:00
|
|
|
return llvm::ConstantExpr::getGetElementPtr(ConstStr, Zeros);
|
2011-03-25 19:57:33 +08:00
|
|
|
}
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Emits a linkonce_odr string, whose name is the prefix followed by the
|
|
|
|
/// string value. This allows the linker to combine the strings between
|
|
|
|
/// different modules. Used for EH typeinfo names, selector strings, and a
|
|
|
|
/// few other things.
|
2011-03-25 19:57:33 +08:00
|
|
|
llvm::Constant *ExportUniqueString(const std::string &Str,
|
|
|
|
const std::string prefix) {
|
|
|
|
std::string name = prefix + Str;
|
|
|
|
llvm::Constant *ConstStr = TheModule.getGlobalVariable(name);
|
|
|
|
if (!ConstStr) {
|
|
|
|
llvm::Constant *value = llvm::ConstantArray::get(VMContext, Str, true);
|
|
|
|
ConstStr = new llvm::GlobalVariable(TheModule, value->getType(), true,
|
|
|
|
llvm::GlobalValue::LinkOnceODRLinkage, value, prefix + Str);
|
|
|
|
}
|
2011-07-21 22:31:17 +08:00
|
|
|
return llvm::ConstantExpr::getGetElementPtr(ConstStr, Zeros);
|
2011-03-25 19:57:33 +08:00
|
|
|
}
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Generates a global structure, initialized by the elements in the vector.
|
|
|
|
/// The element types must match the types of the structure elements in the
|
|
|
|
/// first argument.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::GlobalVariable *MakeGlobal(llvm::StructType *Ty,
|
2011-10-04 23:35:30 +08:00
|
|
|
llvm::ArrayRef<llvm::Constant*> V,
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Name="",
|
2011-03-25 19:57:33 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes linkage
|
|
|
|
=llvm::GlobalValue::InternalLinkage) {
|
|
|
|
llvm::Constant *C = llvm::ConstantStruct::get(Ty, V);
|
|
|
|
return new llvm::GlobalVariable(TheModule, Ty, false,
|
|
|
|
linkage, C, Name);
|
|
|
|
}
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Generates a global array. The vector must contain the same number of
|
|
|
|
/// elements that the array type declares, of the type specified as the array
|
|
|
|
/// element type.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::GlobalVariable *MakeGlobal(llvm::ArrayType *Ty,
|
2011-10-04 23:35:30 +08:00
|
|
|
llvm::ArrayRef<llvm::Constant*> V,
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Name="",
|
2011-03-25 19:57:33 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes linkage
|
|
|
|
=llvm::GlobalValue::InternalLinkage) {
|
|
|
|
llvm::Constant *C = llvm::ConstantArray::get(Ty, V);
|
|
|
|
return new llvm::GlobalVariable(TheModule, Ty, false,
|
|
|
|
linkage, C, Name);
|
|
|
|
}
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Generates a global array, inferring the array type from the specified
|
|
|
|
/// element type and the size of the initialiser.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::GlobalVariable *MakeGlobalArray(llvm::Type *Ty,
|
2011-10-04 23:35:30 +08:00
|
|
|
llvm::ArrayRef<llvm::Constant*> V,
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Name="",
|
2011-03-25 19:57:33 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes linkage
|
|
|
|
=llvm::GlobalValue::InternalLinkage) {
|
|
|
|
llvm::ArrayType *ArrayTy = llvm::ArrayType::get(Ty, V.size());
|
|
|
|
return MakeGlobal(ArrayTy, V, Name, linkage);
|
|
|
|
}
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Ensures that the value has the required type, by inserting a bitcast if
|
|
|
|
/// required. This function lets us avoid inserting bitcasts that are
|
|
|
|
/// redundant.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Value* EnforceType(CGBuilderTy B, llvm::Value *V, llvm::Type *Ty){
|
2011-03-24 06:52:06 +08:00
|
|
|
if (V->getType() == Ty) return V;
|
|
|
|
return B.CreateBitCast(V, Ty);
|
|
|
|
}
|
|
|
|
// Some zeros used for GEPs in lots of places.
|
|
|
|
llvm::Constant *Zeros[2];
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Null pointer value. Mainly used as a terminator in various arrays.
|
2011-03-24 06:52:06 +08:00
|
|
|
llvm::Constant *NULLPtr;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// LLVM context.
|
2011-03-24 06:52:06 +08:00
|
|
|
llvm::LLVMContext &VMContext;
|
|
|
|
private:
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Placeholder for the class. Lots of things refer to the class before we've
|
|
|
|
/// actually emitted it. We use this alias as a placeholder, and then replace
|
|
|
|
/// it with a pointer to the class structure before finally emitting the
|
|
|
|
/// module.
|
2009-05-04 23:31:17 +08:00
|
|
|
llvm::GlobalAlias *ClassPtrAlias;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Placeholder for the metaclass. Lots of things refer to the class before
|
|
|
|
/// we've / actually emitted it. We use this alias as a placeholder, and then
|
|
|
|
/// replace / it with a pointer to the metaclass structure before finally
|
|
|
|
/// emitting the / module.
|
2009-05-04 23:31:17 +08:00
|
|
|
llvm::GlobalAlias *MetaClassPtrAlias;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// All of the classes that have been generated for this compilation units.
|
2008-06-01 22:13:53 +08:00
|
|
|
std::vector<llvm::Constant*> Classes;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// All of the categories that have been generated for this compilation units.
|
2008-06-01 22:13:53 +08:00
|
|
|
std::vector<llvm::Constant*> Categories;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// All of the Objective-C constant strings that have been generated for this
|
|
|
|
/// compilation units.
|
2008-06-01 22:13:53 +08:00
|
|
|
std::vector<llvm::Constant*> ConstantStrings;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Map from string values to Objective-C constant strings in the output.
|
|
|
|
/// Used to prevent emitting Objective-C strings more than once. This should
|
|
|
|
/// not be required at all - CodeGenModule should manage this list.
|
2010-01-27 20:49:23 +08:00
|
|
|
llvm::StringMap<llvm::Constant*> ObjCStrings;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// All of the protocols that have been declared.
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::StringMap<llvm::Constant*> ExistingProtocols;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// For each variant of a selector, we store the type encoding and a
|
|
|
|
/// placeholder value. For an untyped selector, the type will be the empty
|
|
|
|
/// string. Selector references are all done via the module's selector table,
|
|
|
|
/// so we create an alias as a placeholder and then replace it with the real
|
|
|
|
/// value later.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
typedef std::pair<std::string, llvm::GlobalAlias*> TypedSelector;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Type of the selector map. This is roughly equivalent to the structure
|
|
|
|
/// used in the GNUstep runtime, which maintains a list of all of the valid
|
|
|
|
/// types for a selector in a table.
|
2011-07-23 18:55:15 +08:00
|
|
|
typedef llvm::DenseMap<Selector, SmallVector<TypedSelector, 2> >
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
SelectorMap;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// A map from selectors to selector types. This allows us to emit all
|
|
|
|
/// selectors of the same name and type together.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
SelectorMap SelectorTable;
|
|
|
|
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Selectors related to memory management. When compiling in GC mode, we
|
|
|
|
/// omit these.
|
2010-02-03 23:59:02 +08:00
|
|
|
Selector RetainSel, ReleaseSel, AutoreleaseSel;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Runtime functions used for memory management in GC mode. Note that clang
|
|
|
|
/// supports code generation for calling these functions, but neither GNU
|
|
|
|
/// runtime actually supports this API properly yet.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LazyRuntimeFunction IvarAssignFn, StrongCastAssignFn, MemMoveFn, WeakReadFn,
|
|
|
|
WeakAssignFn, GlobalAssignFn;
|
|
|
|
|
2011-03-25 19:57:33 +08:00
|
|
|
protected:
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function used for throwing Objective-C exceptions.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LazyRuntimeFunction ExceptionThrowFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function used for rethrowing exceptions, used at the end of @finally or
|
|
|
|
/// @synchronize blocks.
|
2011-03-25 19:57:33 +08:00
|
|
|
LazyRuntimeFunction ExceptionReThrowFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function called when entering a catch function. This is required for
|
|
|
|
/// differentiating Objective-C exceptions and foreign exceptions.
|
2011-03-25 19:57:33 +08:00
|
|
|
LazyRuntimeFunction EnterCatchFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function called when exiting from a catch block. Used to do exception
|
|
|
|
/// cleanup.
|
2011-03-25 19:57:33 +08:00
|
|
|
LazyRuntimeFunction ExitCatchFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function called when entering an @synchronize block. Acquires the lock.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LazyRuntimeFunction SyncEnterFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function called when exiting an @synchronize block. Releases the lock.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LazyRuntimeFunction SyncExitFn;
|
|
|
|
|
2011-03-25 19:57:33 +08:00
|
|
|
private:
|
|
|
|
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function called if fast enumeration detects that the collection is
|
|
|
|
/// modified during the update.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LazyRuntimeFunction EnumerationMutationFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function for implementing synthesized property getters that return an
|
|
|
|
/// object.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LazyRuntimeFunction GetPropertyFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function for implementing synthesized property setters that return an
|
|
|
|
/// object.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LazyRuntimeFunction SetPropertyFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function used for non-object declared property getters.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LazyRuntimeFunction GetStructPropertyFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Function used for non-object declared property setters.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LazyRuntimeFunction SetStructPropertyFn;
|
|
|
|
|
2011-03-26 19:48:37 +08:00
|
|
|
/// The version of the runtime that this class targets. Must match the
|
|
|
|
/// version in the runtime.
|
2011-05-23 06:37:08 +08:00
|
|
|
int RuntimeVersion;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// The version of the protocol class. Used to differentiate between ObjC1
|
|
|
|
/// and ObjC2 protocols. Objective-C 1 protocols can not contain optional
|
|
|
|
/// components and can not contain declared properties. We always emit
|
|
|
|
/// Objective-C 2 property structures, but we have to pretend that they're
|
|
|
|
/// Objective-C 1 property structures when targeting the GCC runtime or it
|
|
|
|
/// will abort.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
const int ProtocolVersion;
|
2008-06-01 22:13:53 +08:00
|
|
|
private:
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Generates an instance variable list structure. This is a structure
|
|
|
|
/// containing a size and an array of structures containing instance variable
|
|
|
|
/// metadata. This is used purely for introspection in the fragile ABI. In
|
|
|
|
/// the non-fragile ABI, it's used for instance variable fixup.
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *GenerateIvarList(
|
2011-07-23 18:55:15 +08:00
|
|
|
const SmallVectorImpl<llvm::Constant *> &IvarNames,
|
|
|
|
const SmallVectorImpl<llvm::Constant *> &IvarTypes,
|
|
|
|
const SmallVectorImpl<llvm::Constant *> &IvarOffsets);
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Generates a method list structure. This is a structure containing a size
|
|
|
|
/// and an array of structures containing method metadata.
|
|
|
|
///
|
|
|
|
/// This structure is used by both classes and categories, and contains a next
|
|
|
|
/// pointer allowing them to be chained together in a linked list.
|
2011-07-23 18:55:15 +08:00
|
|
|
llvm::Constant *GenerateMethodList(const StringRef &ClassName,
|
|
|
|
const StringRef &CategoryName,
|
|
|
|
const SmallVectorImpl<Selector> &MethodSels,
|
|
|
|
const SmallVectorImpl<llvm::Constant *> &MethodTypes,
|
2008-06-01 22:13:53 +08:00
|
|
|
bool isClassMethodList);
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Emits an empty protocol. This is used for @protocol() where no protocol
|
|
|
|
/// is found. The runtime will (hopefully) fix up the pointer to refer to the
|
|
|
|
/// real protocol.
|
2009-04-01 02:27:22 +08:00
|
|
|
llvm::Constant *GenerateEmptyProtocol(const std::string &ProtocolName);
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Generates a list of property metadata structures. This follows the same
|
|
|
|
/// pattern as method and instance variable metadata lists.
|
2009-09-11 05:48:21 +08:00
|
|
|
llvm::Constant *GeneratePropertyList(const ObjCImplementationDecl *OID,
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVectorImpl<Selector> &InstanceMethodSels,
|
|
|
|
SmallVectorImpl<llvm::Constant*> &InstanceMethodTypes);
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Generates a list of referenced protocols. Classes, categories, and
|
|
|
|
/// protocols all use this structure.
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *GenerateProtocolList(
|
2011-07-23 18:55:15 +08:00
|
|
|
const SmallVectorImpl<std::string> &Protocols);
|
2011-03-26 19:48:37 +08:00
|
|
|
/// To ensure that all protocols are seen by the runtime, we add a category on
|
|
|
|
/// a class defined in the runtime, declaring no methods, but adopting the
|
|
|
|
/// protocols. This is a horribly ugly hack, but it allows us to collect all
|
|
|
|
/// of the protocols without changing the ABI.
|
2009-09-11 05:48:21 +08:00
|
|
|
void GenerateProtocolHolderCategory(void);
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Generates a class structure.
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *GenerateClassStructure(
|
|
|
|
llvm::Constant *MetaClass,
|
|
|
|
llvm::Constant *SuperClass,
|
|
|
|
unsigned info,
|
2008-06-26 12:47:04 +08:00
|
|
|
const char *Name,
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *Version,
|
|
|
|
llvm::Constant *InstanceSize,
|
|
|
|
llvm::Constant *IVars,
|
|
|
|
llvm::Constant *Methods,
|
2009-09-11 05:48:21 +08:00
|
|
|
llvm::Constant *Protocols,
|
|
|
|
llvm::Constant *IvarOffsets,
|
2010-04-28 22:29:56 +08:00
|
|
|
llvm::Constant *Properties,
|
2011-10-04 23:35:30 +08:00
|
|
|
llvm::Constant *StrongIvarBitmap,
|
|
|
|
llvm::Constant *WeakIvarBitmap,
|
2010-04-28 22:29:56 +08:00
|
|
|
bool isMeta=false);
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Generates a method list. This is used by protocols to define the required
|
|
|
|
/// and optional methods.
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *GenerateProtocolMethodList(
|
2011-07-23 18:55:15 +08:00
|
|
|
const SmallVectorImpl<llvm::Constant *> &MethodNames,
|
|
|
|
const SmallVectorImpl<llvm::Constant *> &MethodTypes);
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Returns a selector with the specified type encoding. An empty string is
|
|
|
|
/// used to return an untyped selector (with the types field set to NULL).
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
llvm::Value *GetSelector(CGBuilderTy &Builder, Selector Sel,
|
|
|
|
const std::string &TypeEncoding, bool lval);
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Returns the variable used to store the offset of an instance variable.
|
2009-05-21 02:41:51 +08:00
|
|
|
llvm::GlobalVariable *ObjCIvarOffsetVariable(const ObjCInterfaceDecl *ID,
|
|
|
|
const ObjCIvarDecl *Ivar);
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Emits a reference to a class. This allows the linker to object if there
|
|
|
|
/// is no class of the matching name.
|
2009-06-15 09:09:11 +08:00
|
|
|
void EmitClassRef(const std::string &className);
|
2011-06-29 21:16:41 +08:00
|
|
|
/// Emits a pointer to the named class
|
2011-06-30 18:14:37 +08:00
|
|
|
llvm::Value *GetClassNamed(CGBuilderTy &Builder, const std::string &Name,
|
|
|
|
bool isWeak);
|
2011-03-24 06:52:06 +08:00
|
|
|
protected:
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Looks up the method for sending a message to the specified object. This
|
|
|
|
/// mechanism differs between the GCC and GNU runtimes, so this method must be
|
|
|
|
/// overridden in subclasses.
|
2011-03-24 06:52:06 +08:00
|
|
|
virtual llvm::Value *LookupIMP(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *&Receiver,
|
|
|
|
llvm::Value *cmd,
|
|
|
|
llvm::MDNode *node) = 0;
|
2011-10-04 23:35:30 +08:00
|
|
|
/// Looks up the method for sending a message to a superclass. This
|
|
|
|
/// mechanism differs between the GCC and GNU runtimes, so this method must
|
|
|
|
/// be overridden in subclasses.
|
2011-03-24 06:52:06 +08:00
|
|
|
virtual llvm::Value *LookupIMPSuper(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *ObjCSuper,
|
|
|
|
llvm::Value *cmd) = 0;
|
2011-10-04 23:35:30 +08:00
|
|
|
/// Libobjc2 uses a bitfield representation where small(ish) bitfields are
|
|
|
|
/// stored in a 64-bit value with the low bit set to 1 and the remaining 63
|
|
|
|
/// bits set to their values, LSB first, while larger ones are stored in a
|
|
|
|
/// structure of this / form:
|
|
|
|
///
|
|
|
|
/// struct { int32_t length; int32_t values[length]; };
|
|
|
|
///
|
|
|
|
/// The values in the array are stored in host-endian format, with the least
|
|
|
|
/// significant bit being assumed to come first in the bitfield. Therefore,
|
|
|
|
/// a bitfield with the 64th bit set will be (int64_t)&{ 2, [0, 1<<31] },
|
|
|
|
/// while a bitfield / with the 63rd bit set will be 1<<64.
|
|
|
|
llvm::Constant *MakeBitField(llvm::SmallVectorImpl<bool> &bits);
|
2008-03-01 16:50:34 +08:00
|
|
|
public:
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
CGObjCGNU(CodeGenModule &cgm, unsigned runtimeABIVersion,
|
|
|
|
unsigned protocolClassVersion);
|
|
|
|
|
2010-01-23 10:40:42 +08:00
|
|
|
virtual llvm::Constant *GenerateConstantString(const StringLiteral *);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
|
|
|
|
virtual RValue
|
|
|
|
GenerateMessageSend(CodeGenFunction &CGF,
|
2010-05-22 09:48:05 +08:00
|
|
|
ReturnValueSlot Return,
|
2008-08-30 13:35:15 +08:00
|
|
|
QualType ResultType,
|
|
|
|
Selector Sel,
|
2008-08-25 16:19:24 +08:00
|
|
|
llvm::Value *Receiver,
|
2009-05-06 05:36:57 +08:00
|
|
|
const CallArgList &CallArgs,
|
2010-04-29 03:33:36 +08:00
|
|
|
const ObjCInterfaceDecl *Class,
|
2009-05-06 05:36:57 +08:00
|
|
|
const ObjCMethodDecl *Method);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual RValue
|
|
|
|
GenerateMessageSendSuper(CodeGenFunction &CGF,
|
2010-05-22 09:48:05 +08:00
|
|
|
ReturnValueSlot Return,
|
2008-08-30 13:35:15 +08:00
|
|
|
QualType ResultType,
|
|
|
|
Selector Sel,
|
2008-08-25 16:19:24 +08:00
|
|
|
const ObjCInterfaceDecl *Class,
|
2009-03-01 04:07:56 +08:00
|
|
|
bool isCategoryImpl,
|
2008-08-25 16:19:24 +08:00
|
|
|
llvm::Value *Receiver,
|
2008-08-30 11:02:31 +08:00
|
|
|
bool IsClassMessage,
|
2009-09-17 12:01:22 +08:00
|
|
|
const CallArgList &CallArgs,
|
|
|
|
const ObjCMethodDecl *Method);
|
2008-11-01 09:53:16 +08:00
|
|
|
virtual llvm::Value *GetClass(CGBuilderTy &Builder,
|
2008-08-16 08:25:02 +08:00
|
|
|
const ObjCInterfaceDecl *OID);
|
2010-06-18 03:56:20 +08:00
|
|
|
virtual llvm::Value *GetSelector(CGBuilderTy &Builder, Selector Sel,
|
|
|
|
bool lval = false);
|
2010-02-04 04:11:42 +08:00
|
|
|
virtual llvm::Value *GetSelector(CGBuilderTy &Builder, const ObjCMethodDecl
|
|
|
|
*Method);
|
2011-06-24 03:00:08 +08:00
|
|
|
virtual llvm::Constant *GetEHType(QualType T);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
|
2009-01-11 05:06:09 +08:00
|
|
|
const ObjCContainerDecl *CD);
|
2008-08-16 06:20:32 +08:00
|
|
|
virtual void GenerateCategory(const ObjCCategoryImplDecl *CMD);
|
|
|
|
virtual void GenerateClass(const ObjCImplementationDecl *ClassDecl);
|
2008-11-01 09:53:16 +08:00
|
|
|
virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder,
|
2008-08-13 08:59:25 +08:00
|
|
|
const ObjCProtocolDecl *PD);
|
|
|
|
virtual void GenerateProtocol(const ObjCProtocolDecl *PD);
|
2008-06-01 22:13:53 +08:00
|
|
|
virtual llvm::Function *ModuleInitFunction();
|
2011-05-24 06:33:28 +08:00
|
|
|
virtual llvm::Constant *GetPropertyGetFunction();
|
|
|
|
virtual llvm::Constant *GetPropertySetFunction();
|
|
|
|
virtual llvm::Constant *GetSetStructFunction();
|
|
|
|
virtual llvm::Constant *GetGetStructFunction();
|
2009-07-24 15:40:24 +08:00
|
|
|
virtual llvm::Constant *EnumerationMutationFunction();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual void EmitTryStmt(CodeGenFunction &CGF,
|
2010-07-06 09:34:17 +08:00
|
|
|
const ObjCAtTryStmt &S);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual void EmitSynchronizedStmt(CodeGenFunction &CGF,
|
2010-07-06 09:34:17 +08:00
|
|
|
const ObjCAtSynchronizedStmt &S);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual void EmitThrowStmt(CodeGenFunction &CGF,
|
2008-09-09 18:04:29 +08:00
|
|
|
const ObjCAtThrowStmt &S);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual llvm::Value * EmitObjCWeakRead(CodeGenFunction &CGF,
|
2008-11-19 05:45:40 +08:00
|
|
|
llvm::Value *AddrWeakObj);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual void EmitObjCWeakAssign(CodeGenFunction &CGF,
|
2008-11-19 06:37:34 +08:00
|
|
|
llvm::Value *src, llvm::Value *dst);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual void EmitObjCGlobalAssign(CodeGenFunction &CGF,
|
2010-07-21 04:30:03 +08:00
|
|
|
llvm::Value *src, llvm::Value *dest,
|
|
|
|
bool threadlocal=false);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual void EmitObjCIvarAssign(CodeGenFunction &CGF,
|
2009-09-25 06:25:38 +08:00
|
|
|
llvm::Value *src, llvm::Value *dest,
|
|
|
|
llvm::Value *ivarOffset);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual void EmitObjCStrongCastAssign(CodeGenFunction &CGF,
|
2008-11-19 08:59:10 +08:00
|
|
|
llvm::Value *src, llvm::Value *dest);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual void EmitGCMemmoveCollectable(CodeGenFunction &CGF,
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Value *DestPtr,
|
2009-07-08 09:18:33 +08:00
|
|
|
llvm::Value *SrcPtr,
|
2010-06-16 06:44:06 +08:00
|
|
|
llvm::Value *Size);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual LValue EmitObjCValueForIvar(CodeGenFunction &CGF,
|
2009-02-04 03:03:09 +08:00
|
|
|
QualType ObjectTy,
|
|
|
|
llvm::Value *BaseValue,
|
|
|
|
const ObjCIvarDecl *Ivar,
|
|
|
|
unsigned CVRQualifiers);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual llvm::Value *EmitIvarOffset(CodeGenFunction &CGF,
|
2009-04-22 13:08:15 +08:00
|
|
|
const ObjCInterfaceDecl *Interface,
|
2009-02-11 03:02:04 +08:00
|
|
|
const ObjCIvarDecl *Ivar);
|
2011-06-29 21:16:41 +08:00
|
|
|
virtual llvm::Value *EmitNSAutoreleasePoolClassRef(CGBuilderTy &Builder);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
virtual llvm::Constant *BuildGCBlockLayout(CodeGenModule &CGM,
|
2011-02-07 18:33:21 +08:00
|
|
|
const CGBlockInfo &blockInfo) {
|
2010-08-05 00:57:49 +08:00
|
|
|
return NULLPtr;
|
|
|
|
}
|
2011-05-18 06:21:16 +08:00
|
|
|
|
|
|
|
virtual llvm::GlobalVariable *GetClassGlobal(const std::string &Name) {
|
|
|
|
return 0;
|
|
|
|
}
|
2008-03-01 16:50:34 +08:00
|
|
|
};
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Class representing the legacy GCC Objective-C ABI. This is the default when
|
|
|
|
/// -fobjc-nonfragile-abi is not specified.
|
|
|
|
///
|
|
|
|
/// The GCC ABI target actually generates code that is approximately compatible
|
|
|
|
/// with the new GNUstep runtime ABI, but refrains from using any features that
|
|
|
|
/// would not work with the GCC runtime. For example, clang always generates
|
|
|
|
/// the extended form of the class structure, and the extra fields are simply
|
|
|
|
/// ignored by GCC libobjc.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
class CGObjCGCC : public CGObjCGNU {
|
2011-03-26 19:48:37 +08:00
|
|
|
/// The GCC ABI message lookup function. Returns an IMP pointing to the
|
|
|
|
/// method implementation for this message.
|
2011-03-24 06:52:06 +08:00
|
|
|
LazyRuntimeFunction MsgLookupFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// The GCC ABI superclass message lookup function. Takes a pointer to a
|
|
|
|
/// structure describing the receiver and the class, and a selector as
|
|
|
|
/// arguments. Returns the IMP for the corresponding method.
|
2011-03-24 06:52:06 +08:00
|
|
|
LazyRuntimeFunction MsgLookupSuperFn;
|
|
|
|
protected:
|
|
|
|
virtual llvm::Value *LookupIMP(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *&Receiver,
|
|
|
|
llvm::Value *cmd,
|
|
|
|
llvm::MDNode *node) {
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
2011-10-29 01:55:06 +08:00
|
|
|
llvm::Value *args[] = {
|
2011-03-24 06:52:06 +08:00
|
|
|
EnforceType(Builder, Receiver, IdTy),
|
2011-10-29 01:55:06 +08:00
|
|
|
EnforceType(Builder, cmd, SelectorTy) };
|
|
|
|
llvm::CallSite imp = CGF.EmitCallOrInvoke(MsgLookupFn, args);
|
|
|
|
imp->setMetadata(msgSendMDKind, node);
|
|
|
|
return imp.getInstruction();
|
2011-03-24 06:52:06 +08:00
|
|
|
}
|
|
|
|
virtual llvm::Value *LookupIMPSuper(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *ObjCSuper,
|
|
|
|
llvm::Value *cmd) {
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::Value *lookupArgs[] = {EnforceType(Builder, ObjCSuper,
|
|
|
|
PtrToObjCSuperTy), cmd};
|
2011-07-15 16:37:34 +08:00
|
|
|
return Builder.CreateCall(MsgLookupSuperFn, lookupArgs);
|
2011-03-24 06:52:06 +08:00
|
|
|
}
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
public:
|
2011-03-24 06:52:06 +08:00
|
|
|
CGObjCGCC(CodeGenModule &Mod) : CGObjCGNU(Mod, 8, 2) {
|
|
|
|
// IMP objc_msg_lookup(id, SEL);
|
|
|
|
MsgLookupFn.init(&CGM, "objc_msg_lookup", IMPTy, IdTy, SelectorTy, NULL);
|
|
|
|
// IMP objc_msg_lookup_super(struct objc_super*, SEL);
|
|
|
|
MsgLookupSuperFn.init(&CGM, "objc_msg_lookup_super", IMPTy,
|
|
|
|
PtrToObjCSuperTy, SelectorTy, NULL);
|
|
|
|
}
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
};
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Class used when targeting the new GNUstep runtime ABI.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
class CGObjCGNUstep : public CGObjCGNU {
|
2011-03-26 19:48:37 +08:00
|
|
|
/// The slot lookup function. Returns a pointer to a cacheable structure
|
|
|
|
/// that contains (among other things) the IMP.
|
2011-03-24 06:52:06 +08:00
|
|
|
LazyRuntimeFunction SlotLookupFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// The GNUstep ABI superclass message lookup function. Takes a pointer to
|
|
|
|
/// a structure describing the receiver and the class, and a selector as
|
|
|
|
/// arguments. Returns the slot for the corresponding method. Superclass
|
|
|
|
/// message lookup rarely changes, so this is a good caching opportunity.
|
2011-03-24 06:52:06 +08:00
|
|
|
LazyRuntimeFunction SlotLookupSuperFn;
|
2011-03-26 19:48:37 +08:00
|
|
|
/// Type of an slot structure pointer. This is returned by the various
|
|
|
|
/// lookup functions.
|
2011-03-24 06:52:06 +08:00
|
|
|
llvm::Type *SlotTy;
|
|
|
|
protected:
|
|
|
|
virtual llvm::Value *LookupIMP(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *&Receiver,
|
|
|
|
llvm::Value *cmd,
|
|
|
|
llvm::MDNode *node) {
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::Function *LookupFn = SlotLookupFn;
|
|
|
|
|
|
|
|
// Store the receiver on the stack so that we can reload it later
|
|
|
|
llvm::Value *ReceiverPtr = CGF.CreateTempAlloca(Receiver->getType());
|
|
|
|
Builder.CreateStore(Receiver, ReceiverPtr);
|
|
|
|
|
|
|
|
llvm::Value *self;
|
|
|
|
|
|
|
|
if (isa<ObjCMethodDecl>(CGF.CurCodeDecl)) {
|
|
|
|
self = CGF.LoadObjCSelf();
|
|
|
|
} else {
|
|
|
|
self = llvm::ConstantPointerNull::get(IdTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The lookup function is guaranteed not to capture the receiver pointer.
|
|
|
|
LookupFn->setDoesNotCapture(1);
|
|
|
|
|
2011-10-29 01:55:06 +08:00
|
|
|
llvm::Value *args[] = {
|
2011-03-24 06:52:06 +08:00
|
|
|
EnforceType(Builder, ReceiverPtr, PtrToIdTy),
|
|
|
|
EnforceType(Builder, cmd, SelectorTy),
|
2011-10-29 01:55:06 +08:00
|
|
|
EnforceType(Builder, self, IdTy) };
|
|
|
|
llvm::CallSite slot = CGF.EmitCallOrInvoke(LookupFn, args);
|
|
|
|
slot.setOnlyReadsMemory();
|
2011-03-24 06:52:06 +08:00
|
|
|
slot->setMetadata(msgSendMDKind, node);
|
|
|
|
|
|
|
|
// Load the imp from the slot
|
2011-10-29 01:55:06 +08:00
|
|
|
llvm::Value *imp =
|
|
|
|
Builder.CreateLoad(Builder.CreateStructGEP(slot.getInstruction(), 4));
|
2011-03-24 06:52:06 +08:00
|
|
|
|
|
|
|
// The lookup function may have changed the receiver, so make sure we use
|
|
|
|
// the new one.
|
|
|
|
Receiver = Builder.CreateLoad(ReceiverPtr, true);
|
|
|
|
return imp;
|
|
|
|
}
|
|
|
|
virtual llvm::Value *LookupIMPSuper(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *ObjCSuper,
|
|
|
|
llvm::Value *cmd) {
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::Value *lookupArgs[] = {ObjCSuper, cmd};
|
|
|
|
|
2011-07-15 16:37:34 +08:00
|
|
|
llvm::CallInst *slot = Builder.CreateCall(SlotLookupSuperFn, lookupArgs);
|
2011-03-24 06:52:06 +08:00
|
|
|
slot->setOnlyReadsMemory();
|
|
|
|
|
|
|
|
return Builder.CreateLoad(Builder.CreateStructGEP(slot, 4));
|
|
|
|
}
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
public:
|
2011-03-24 06:52:06 +08:00
|
|
|
CGObjCGNUstep(CodeGenModule &Mod) : CGObjCGNU(Mod, 9, 3) {
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *SlotStructTy = llvm::StructType::get(PtrTy,
|
2011-03-24 06:52:06 +08:00
|
|
|
PtrTy, PtrTy, IntTy, IMPTy, NULL);
|
|
|
|
SlotTy = llvm::PointerType::getUnqual(SlotStructTy);
|
|
|
|
// Slot_t objc_msg_lookup_sender(id *receiver, SEL selector, id sender);
|
|
|
|
SlotLookupFn.init(&CGM, "objc_msg_lookup_sender", SlotTy, PtrToIdTy,
|
|
|
|
SelectorTy, IdTy, NULL);
|
|
|
|
// Slot_t objc_msg_lookup_super(struct objc_super*, SEL);
|
|
|
|
SlotLookupSuperFn.init(&CGM, "objc_slot_lookup_super", SlotTy,
|
|
|
|
PtrToObjCSuperTy, SelectorTy, NULL);
|
2011-03-25 19:57:33 +08:00
|
|
|
// If we're in ObjC++ mode, then we want to make
|
|
|
|
if (CGM.getLangOptions().CPlusPlus) {
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
|
2011-03-25 19:57:33 +08:00
|
|
|
// void *__cxa_begin_catch(void *e)
|
|
|
|
EnterCatchFn.init(&CGM, "__cxa_begin_catch", PtrTy, PtrTy, NULL);
|
|
|
|
// void __cxa_end_catch(void)
|
2011-08-09 01:26:06 +08:00
|
|
|
ExitCatchFn.init(&CGM, "__cxa_end_catch", VoidTy, NULL);
|
2011-03-25 19:57:33 +08:00
|
|
|
// void _Unwind_Resume_or_Rethrow(void*)
|
2011-04-06 01:15:18 +08:00
|
|
|
ExceptionReThrowFn.init(&CGM, "_Unwind_Resume_or_Rethrow", VoidTy, PtrTy, NULL);
|
2011-03-25 19:57:33 +08:00
|
|
|
}
|
2011-03-24 06:52:06 +08:00
|
|
|
}
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
};
|
|
|
|
|
2008-03-01 16:50:34 +08:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
|
2009-06-15 09:09:11 +08:00
|
|
|
/// Emits a reference to a dummy variable which is emitted with each class.
|
|
|
|
/// This ensures that a linker error will be generated when trying to link
|
|
|
|
/// together modules where a referenced class is not defined.
|
2009-08-01 05:31:32 +08:00
|
|
|
void CGObjCGNU::EmitClassRef(const std::string &className) {
|
2009-06-15 09:09:11 +08:00
|
|
|
std::string symbolRef = "__objc_class_ref_" + className;
|
|
|
|
// Don't emit two copies of the same symbol
|
2009-08-01 05:31:32 +08:00
|
|
|
if (TheModule.getGlobalVariable(symbolRef))
|
|
|
|
return;
|
2009-06-15 09:09:11 +08:00
|
|
|
std::string symbolName = "__objc_class_name_" + className;
|
|
|
|
llvm::GlobalVariable *ClassSymbol = TheModule.getGlobalVariable(symbolName);
|
|
|
|
if (!ClassSymbol) {
|
2009-07-09 03:05:04 +08:00
|
|
|
ClassSymbol = new llvm::GlobalVariable(TheModule, LongTy, false,
|
|
|
|
llvm::GlobalValue::ExternalLinkage, 0, symbolName);
|
2009-06-15 09:09:11 +08:00
|
|
|
}
|
2009-07-09 03:05:04 +08:00
|
|
|
new llvm::GlobalVariable(TheModule, ClassSymbol->getType(), true,
|
2009-08-05 13:25:18 +08:00
|
|
|
llvm::GlobalValue::WeakAnyLinkage, ClassSymbol, symbolRef);
|
2009-06-15 09:09:11 +08:00
|
|
|
}
|
2008-06-01 22:13:53 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
static std::string SymbolNameForMethod(const StringRef &ClassName,
|
|
|
|
const StringRef &CategoryName, const Selector MethodName,
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
bool isClassMethod) {
|
|
|
|
std::string MethodNameColonStripped = MethodName.getAsString();
|
2010-01-14 22:08:19 +08:00
|
|
|
std::replace(MethodNameColonStripped.begin(), MethodNameColonStripped.end(),
|
|
|
|
':', '_');
|
2011-07-23 18:55:15 +08:00
|
|
|
return (Twine(isClassMethod ? "_c_" : "_i_") + ClassName + "_" +
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
CategoryName + "_" + MethodNameColonStripped).str();
|
2010-05-09 04:58:05 +08:00
|
|
|
}
|
2008-06-01 22:13:53 +08:00
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned runtimeABIVersion,
|
|
|
|
unsigned protocolClassVersion)
|
2011-03-24 06:52:06 +08:00
|
|
|
: CGM(cgm), TheModule(CGM.getModule()), VMContext(cgm.getLLVMContext()),
|
|
|
|
ClassPtrAlias(0), MetaClassPtrAlias(0), RuntimeVersion(runtimeABIVersion),
|
|
|
|
ProtocolVersion(protocolClassVersion) {
|
2010-04-29 03:33:36 +08:00
|
|
|
|
|
|
|
msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
CodeGenTypes &Types = CGM.getTypes();
|
2009-01-27 13:06:01 +08:00
|
|
|
IntTy = cast<llvm::IntegerType>(
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
Types.ConvertType(CGM.getContext().IntTy));
|
2009-01-27 13:06:01 +08:00
|
|
|
LongTy = cast<llvm::IntegerType>(
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
Types.ConvertType(CGM.getContext().LongTy));
|
2010-12-27 06:13:16 +08:00
|
|
|
SizeTy = cast<llvm::IntegerType>(
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
Types.ConvertType(CGM.getContext().getSizeType()));
|
2010-12-27 06:13:16 +08:00
|
|
|
PtrDiffTy = cast<llvm::IntegerType>(
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
Types.ConvertType(CGM.getContext().getPointerDiffType()));
|
2010-12-27 06:13:16 +08:00
|
|
|
BoolTy = CGM.getTypes().ConvertType(CGM.getContext().BoolTy);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-11 05:48:21 +08:00
|
|
|
Int8Ty = llvm::Type::getInt8Ty(VMContext);
|
|
|
|
// C string type. Used in lots of places.
|
|
|
|
PtrToInt8Ty = llvm::PointerType::getUnqual(Int8Ty);
|
|
|
|
|
2009-07-25 07:12:58 +08:00
|
|
|
Zeros[0] = llvm::ConstantInt::get(LongTy, 0);
|
2008-06-01 22:13:53 +08:00
|
|
|
Zeros[1] = Zeros[0];
|
2009-09-11 05:48:21 +08:00
|
|
|
NULLPtr = llvm::ConstantPointerNull::get(PtrToInt8Ty);
|
2008-03-31 07:03:07 +08:00
|
|
|
// Get the selector Type.
|
2010-01-23 10:40:42 +08:00
|
|
|
QualType selTy = CGM.getContext().getObjCSelType();
|
|
|
|
if (QualType() == selTy) {
|
|
|
|
SelectorTy = PtrToInt8Ty;
|
|
|
|
} else {
|
|
|
|
SelectorTy = cast<llvm::PointerType>(CGM.getTypes().ConvertType(selTy));
|
|
|
|
}
|
2009-01-27 13:06:01 +08:00
|
|
|
|
2009-07-30 06:16:19 +08:00
|
|
|
PtrToIntTy = llvm::PointerType::getUnqual(IntTy);
|
2008-03-31 07:03:07 +08:00
|
|
|
PtrTy = PtrToInt8Ty;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-04 23:35:30 +08:00
|
|
|
Int32Ty = llvm::Type::getInt32Ty(VMContext);
|
|
|
|
Int64Ty = llvm::Type::getInt64Ty(VMContext);
|
|
|
|
|
2011-10-08 16:54:36 +08:00
|
|
|
IntPtrTy =
|
|
|
|
TheModule.getPointerSize() == llvm::Module::Pointer32 ? Int32Ty : Int64Ty;
|
|
|
|
|
2008-03-31 07:03:07 +08:00
|
|
|
// Object type
|
2011-04-29 22:10:35 +08:00
|
|
|
QualType UnqualIdTy = CGM.getContext().getObjCIdType();
|
|
|
|
ASTIdTy = CanQualType();
|
|
|
|
if (UnqualIdTy != QualType()) {
|
|
|
|
ASTIdTy = CGM.getContext().getCanonicalType(UnqualIdTy);
|
2010-01-23 10:40:42 +08:00
|
|
|
IdTy = cast<llvm::PointerType>(CGM.getTypes().ConvertType(ASTIdTy));
|
2011-04-29 22:10:35 +08:00
|
|
|
} else {
|
|
|
|
IdTy = PtrToInt8Ty;
|
2010-01-23 10:40:42 +08:00
|
|
|
}
|
2010-02-03 23:59:02 +08:00
|
|
|
PtrToIdTy = llvm::PointerType::getUnqual(IdTy);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-06-19 06:49:11 +08:00
|
|
|
ObjCSuperTy = llvm::StructType::get(IdTy, IdTy, NULL);
|
2011-03-24 06:52:06 +08:00
|
|
|
PtrToObjCSuperTy = llvm::PointerType::getUnqual(ObjCSuperTy);
|
|
|
|
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
|
|
|
|
// void objc_exception_throw(id);
|
|
|
|
ExceptionThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy, NULL);
|
2011-03-25 19:57:33 +08:00
|
|
|
ExceptionReThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy, NULL);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
// int objc_sync_enter(id);
|
|
|
|
SyncEnterFn.init(&CGM, "objc_sync_enter", IntTy, IdTy, NULL);
|
|
|
|
// int objc_sync_exit(id);
|
|
|
|
SyncExitFn.init(&CGM, "objc_sync_exit", IntTy, IdTy, NULL);
|
|
|
|
|
|
|
|
// void objc_enumerationMutation (id)
|
|
|
|
EnumerationMutationFn.init(&CGM, "objc_enumerationMutation", VoidTy,
|
|
|
|
IdTy, NULL);
|
|
|
|
|
|
|
|
// id objc_getProperty(id, SEL, ptrdiff_t, BOOL)
|
|
|
|
GetPropertyFn.init(&CGM, "objc_getProperty", IdTy, IdTy, SelectorTy,
|
|
|
|
PtrDiffTy, BoolTy, NULL);
|
|
|
|
// void objc_setProperty(id, SEL, ptrdiff_t, id, BOOL, BOOL)
|
|
|
|
SetPropertyFn.init(&CGM, "objc_setProperty", VoidTy, IdTy, SelectorTy,
|
|
|
|
PtrDiffTy, IdTy, BoolTy, BoolTy, NULL);
|
|
|
|
// void objc_setPropertyStruct(void*, void*, ptrdiff_t, BOOL, BOOL)
|
|
|
|
GetStructPropertyFn.init(&CGM, "objc_getPropertyStruct", VoidTy, PtrTy, PtrTy,
|
|
|
|
PtrDiffTy, BoolTy, BoolTy, NULL);
|
|
|
|
// void objc_setPropertyStruct(void*, void*, ptrdiff_t, BOOL, BOOL)
|
|
|
|
SetStructPropertyFn.init(&CGM, "objc_setPropertyStruct", VoidTy, PtrTy, PtrTy,
|
|
|
|
PtrDiffTy, BoolTy, BoolTy, NULL);
|
|
|
|
|
2008-03-31 07:03:07 +08:00
|
|
|
// IMP type
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *IMPArgs[] = { IdTy, SelectorTy };
|
2011-03-24 06:52:06 +08:00
|
|
|
IMPTy = llvm::PointerType::getUnqual(llvm::FunctionType::get(IdTy, IMPArgs,
|
|
|
|
true));
|
2010-02-03 23:59:02 +08:00
|
|
|
|
2011-07-07 19:22:31 +08:00
|
|
|
const LangOptions &Opts = CGM.getLangOptions();
|
2011-09-14 01:21:33 +08:00
|
|
|
if ((Opts.getGC() != LangOptions::NonGC) || Opts.ObjCAutoRefCount)
|
2011-07-07 19:22:31 +08:00
|
|
|
RuntimeVersion = 10;
|
|
|
|
|
2011-03-25 19:57:33 +08:00
|
|
|
// Don't bother initialising the GC stuff unless we're compiling in GC mode
|
2011-09-14 01:21:33 +08:00
|
|
|
if (Opts.getGC() != LangOptions::NonGC) {
|
2011-05-23 06:37:08 +08:00
|
|
|
// This is a bit of an hack. We should sort this out by having a proper
|
|
|
|
// CGObjCGNUstep subclass for GC, but we may want to really support the old
|
|
|
|
// ABI and GC added in ObjectiveC2.framework, so we fudge it a bit for now
|
2010-02-03 23:59:02 +08:00
|
|
|
// Get selectors needed in GC mode
|
|
|
|
RetainSel = GetNullarySelector("retain", CGM.getContext());
|
|
|
|
ReleaseSel = GetNullarySelector("release", CGM.getContext());
|
|
|
|
AutoreleaseSel = GetNullarySelector("autorelease", CGM.getContext());
|
|
|
|
|
|
|
|
// Get functions needed in GC mode
|
|
|
|
|
|
|
|
// id objc_assign_ivar(id, id, ptrdiff_t);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
IvarAssignFn.init(&CGM, "objc_assign_ivar", IdTy, IdTy, IdTy, PtrDiffTy,
|
|
|
|
NULL);
|
2010-02-03 23:59:02 +08:00
|
|
|
// id objc_assign_strongCast (id, id*)
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
StrongCastAssignFn.init(&CGM, "objc_assign_strongCast", IdTy, IdTy,
|
|
|
|
PtrToIdTy, NULL);
|
2010-02-03 23:59:02 +08:00
|
|
|
// id objc_assign_global(id, id*);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
GlobalAssignFn.init(&CGM, "objc_assign_global", IdTy, IdTy, PtrToIdTy,
|
|
|
|
NULL);
|
2010-02-03 23:59:02 +08:00
|
|
|
// id objc_assign_weak(id, id*);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
WeakAssignFn.init(&CGM, "objc_assign_weak", IdTy, IdTy, PtrToIdTy, NULL);
|
2010-02-03 23:59:02 +08:00
|
|
|
// id objc_read_weak(id*);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
WeakReadFn.init(&CGM, "objc_read_weak", IdTy, PtrToIdTy, NULL);
|
2010-02-03 23:59:02 +08:00
|
|
|
// void *objc_memmove_collectable(void*, void *, size_t);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
MemMoveFn.init(&CGM, "objc_memmove_collectable", PtrTy, PtrTy, PtrTy,
|
|
|
|
SizeTy, NULL);
|
2010-02-03 23:59:02 +08:00
|
|
|
}
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
2009-08-01 05:31:32 +08:00
|
|
|
|
2011-06-29 21:16:41 +08:00
|
|
|
llvm::Value *CGObjCGNU::GetClassNamed(CGBuilderTy &Builder,
|
2011-06-30 18:14:37 +08:00
|
|
|
const std::string &Name,
|
|
|
|
bool isWeak) {
|
2011-06-29 21:16:41 +08:00
|
|
|
llvm::Value *ClassName = CGM.GetAddrOfConstantCString(Name);
|
2010-01-08 08:14:31 +08:00
|
|
|
// With the incompatible ABI, this will need to be replaced with a direct
|
|
|
|
// reference to the class symbol. For the compatible nonfragile ABI we are
|
|
|
|
// still performing this lookup at run time but emitting the symbol for the
|
|
|
|
// class externally so that we can make the switch later.
|
2011-06-29 21:16:41 +08:00
|
|
|
//
|
|
|
|
// Libobjc2 contains an LLVM pass that replaces calls to objc_lookup_class
|
|
|
|
// with memoized versions or with static references if it's safe to do so.
|
2011-06-30 18:14:37 +08:00
|
|
|
if (!isWeak)
|
|
|
|
EmitClassRef(Name);
|
2008-08-16 08:25:02 +08:00
|
|
|
ClassName = Builder.CreateStructGEP(ClassName, 0);
|
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *ClassLookupFn =
|
2011-07-29 21:56:53 +08:00
|
|
|
CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, PtrToInt8Ty, true),
|
2009-03-31 02:02:14 +08:00
|
|
|
"objc_lookup_class");
|
2008-06-01 22:13:53 +08:00
|
|
|
return Builder.CreateCall(ClassLookupFn, ClassName);
|
2008-03-31 07:03:07 +08:00
|
|
|
}
|
|
|
|
|
2011-06-29 21:16:41 +08:00
|
|
|
// This has to perform the lookup every time, since posing and related
|
|
|
|
// techniques can modify the name -> class mapping.
|
|
|
|
llvm::Value *CGObjCGNU::GetClass(CGBuilderTy &Builder,
|
|
|
|
const ObjCInterfaceDecl *OID) {
|
2011-06-30 18:14:37 +08:00
|
|
|
return GetClassNamed(Builder, OID->getNameAsString(), OID->isWeakImported());
|
2011-06-29 21:16:41 +08:00
|
|
|
}
|
|
|
|
llvm::Value *CGObjCGNU::EmitNSAutoreleasePoolClassRef(CGBuilderTy &Builder) {
|
2011-06-30 18:14:37 +08:00
|
|
|
return GetClassNamed(Builder, "NSAutoreleasePool", false);
|
2011-06-29 21:16:41 +08:00
|
|
|
}
|
|
|
|
|
2010-06-18 03:56:20 +08:00
|
|
|
llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, Selector Sel,
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
const std::string &TypeEncoding, bool lval) {
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<TypedSelector, 2> &Types = SelectorTable[Sel];
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
llvm::GlobalAlias *SelValue = 0;
|
|
|
|
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
for (SmallVectorImpl<TypedSelector>::iterator i = Types.begin(),
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
e = Types.end() ; i!=e ; i++) {
|
|
|
|
if (i->first == TypeEncoding) {
|
|
|
|
SelValue = i->second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (0 == SelValue) {
|
2011-03-24 06:52:06 +08:00
|
|
|
SelValue = new llvm::GlobalAlias(SelectorTy,
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
llvm::GlobalValue::PrivateLinkage,
|
|
|
|
".objc_selector_"+Sel.getAsString(), NULL,
|
|
|
|
&TheModule);
|
|
|
|
Types.push_back(TypedSelector(TypeEncoding, SelValue));
|
|
|
|
}
|
|
|
|
|
2011-03-24 06:52:06 +08:00
|
|
|
if (lval) {
|
|
|
|
llvm::Value *tmp = Builder.CreateAlloca(SelValue->getType());
|
|
|
|
Builder.CreateStore(SelValue, tmp);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
return SelValue;
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, Selector Sel,
|
|
|
|
bool lval) {
|
|
|
|
return GetSelector(Builder, Sel, std::string(), lval);
|
2009-05-06 05:36:57 +08:00
|
|
|
}
|
|
|
|
|
2010-02-04 04:11:42 +08:00
|
|
|
llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, const ObjCMethodDecl
|
2009-05-06 05:36:57 +08:00
|
|
|
*Method) {
|
|
|
|
std::string SelTypes;
|
|
|
|
CGM.getContext().getObjCEncodingForMethodDecl(Method, SelTypes);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
return GetSelector(Builder, Method->getSelector(), SelTypes, false);
|
2008-06-26 12:37:12 +08:00
|
|
|
}
|
|
|
|
|
2011-06-24 03:00:08 +08:00
|
|
|
llvm::Constant *CGObjCGNU::GetEHType(QualType T) {
|
2011-03-25 19:57:33 +08:00
|
|
|
if (!CGM.getLangOptions().CPlusPlus) {
|
|
|
|
if (T->isObjCIdType()
|
|
|
|
|| T->isObjCQualifiedIdType()) {
|
|
|
|
// With the old ABI, there was only one kind of catchall, which broke
|
|
|
|
// foreign exceptions. With the new ABI, we use __objc_id_typeinfo as
|
|
|
|
// a pointer indicating object catchalls, and NULL to indicate real
|
|
|
|
// catchalls
|
|
|
|
if (CGM.getLangOptions().ObjCNonFragileABI) {
|
|
|
|
return MakeConstantString("@id");
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// All other types should be Objective-C interface pointer types.
|
|
|
|
const ObjCObjectPointerType *OPT =
|
|
|
|
T->getAs<ObjCObjectPointerType>();
|
|
|
|
assert(OPT && "Invalid @catch type.");
|
|
|
|
const ObjCInterfaceDecl *IDecl =
|
|
|
|
OPT->getObjectType()->getInterface();
|
|
|
|
assert(IDecl && "Invalid @catch type.");
|
|
|
|
return MakeConstantString(IDecl->getIdentifier()->getName());
|
|
|
|
}
|
2011-03-21 05:35:39 +08:00
|
|
|
// For Objective-C++, we want to provide the ability to catch both C++ and
|
|
|
|
// Objective-C objects in the same function.
|
|
|
|
|
|
|
|
// There's a particular fixed type info for 'id'.
|
|
|
|
if (T->isObjCIdType() ||
|
|
|
|
T->isObjCQualifiedIdType()) {
|
|
|
|
llvm::Constant *IDEHType =
|
|
|
|
CGM.getModule().getGlobalVariable("__objc_id_type_info");
|
|
|
|
if (!IDEHType)
|
|
|
|
IDEHType =
|
|
|
|
new llvm::GlobalVariable(CGM.getModule(), PtrToInt8Ty,
|
|
|
|
false,
|
|
|
|
llvm::GlobalValue::ExternalLinkage,
|
|
|
|
0, "__objc_id_type_info");
|
|
|
|
return llvm::ConstantExpr::getBitCast(IDEHType, PtrToInt8Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ObjCObjectPointerType *PT =
|
|
|
|
T->getAs<ObjCObjectPointerType>();
|
|
|
|
assert(PT && "Invalid @catch type.");
|
|
|
|
const ObjCInterfaceType *IT = PT->getInterfaceType();
|
|
|
|
assert(IT && "Invalid @catch type.");
|
|
|
|
std::string className = IT->getDecl()->getIdentifier()->getName();
|
|
|
|
|
|
|
|
std::string typeinfoName = "__objc_eh_typeinfo_" + className;
|
|
|
|
|
|
|
|
// Return the existing typeinfo if it exists
|
|
|
|
llvm::Constant *typeinfo = TheModule.getGlobalVariable(typeinfoName);
|
|
|
|
if (typeinfo) return typeinfo;
|
|
|
|
|
|
|
|
// Otherwise create it.
|
|
|
|
|
|
|
|
// vtable for gnustep::libobjc::__objc_class_type_info
|
|
|
|
// It's quite ugly hard-coding this. Ideally we'd generate it using the host
|
|
|
|
// platform's name mangling.
|
|
|
|
const char *vtableName = "_ZTVN7gnustep7libobjc22__objc_class_type_infoE";
|
|
|
|
llvm::Constant *Vtable = TheModule.getGlobalVariable(vtableName);
|
|
|
|
if (!Vtable) {
|
|
|
|
Vtable = new llvm::GlobalVariable(TheModule, PtrToInt8Ty, true,
|
|
|
|
llvm::GlobalValue::ExternalLinkage, 0, vtableName);
|
|
|
|
}
|
|
|
|
llvm::Constant *Two = llvm::ConstantInt::get(IntTy, 2);
|
2011-07-21 22:31:17 +08:00
|
|
|
Vtable = llvm::ConstantExpr::getGetElementPtr(Vtable, Two);
|
2011-03-21 05:35:39 +08:00
|
|
|
Vtable = llvm::ConstantExpr::getBitCast(Vtable, PtrToInt8Ty);
|
|
|
|
|
|
|
|
llvm::Constant *typeName =
|
|
|
|
ExportUniqueString(className, "__objc_eh_typename_");
|
|
|
|
|
|
|
|
std::vector<llvm::Constant*> fields;
|
|
|
|
fields.push_back(Vtable);
|
|
|
|
fields.push_back(typeName);
|
|
|
|
llvm::Constant *TI =
|
2011-06-19 06:49:11 +08:00
|
|
|
MakeGlobal(llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty,
|
2011-03-21 05:35:39 +08:00
|
|
|
NULL), fields, "__objc_eh_typeinfo_" + className,
|
|
|
|
llvm::GlobalValue::LinkOnceODRLinkage);
|
|
|
|
return llvm::ConstantExpr::getBitCast(TI, PtrToInt8Ty);
|
2010-07-24 08:37:23 +08:00
|
|
|
}
|
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
/// Generate an NSConstantString object.
|
2010-01-23 10:40:42 +08:00
|
|
|
llvm::Constant *CGObjCGNU::GenerateConstantString(const StringLiteral *SL) {
|
2010-01-27 20:49:23 +08:00
|
|
|
|
2010-08-17 20:54:38 +08:00
|
|
|
std::string Str = SL->getString().str();
|
2010-01-23 10:40:42 +08:00
|
|
|
|
2010-01-27 20:49:23 +08:00
|
|
|
// Look for an existing one
|
|
|
|
llvm::StringMap<llvm::Constant*>::iterator old = ObjCStrings.find(Str);
|
|
|
|
if (old != ObjCStrings.end())
|
|
|
|
return old->getValue();
|
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
std::vector<llvm::Constant*> Ivars;
|
|
|
|
Ivars.push_back(NULLPtr);
|
2008-06-22 05:44:18 +08:00
|
|
|
Ivars.push_back(MakeConstantString(Str));
|
2009-07-25 07:12:58 +08:00
|
|
|
Ivars.push_back(llvm::ConstantInt::get(IntTy, Str.size()));
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *ObjCStr = MakeGlobal(
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, IntTy, NULL),
|
2008-06-01 22:13:53 +08:00
|
|
|
Ivars, ".objc_str");
|
2010-01-27 20:49:23 +08:00
|
|
|
ObjCStr = llvm::ConstantExpr::getBitCast(ObjCStr, PtrToInt8Ty);
|
|
|
|
ObjCStrings[Str] = ObjCStr;
|
|
|
|
ConstantStrings.push_back(ObjCStr);
|
2008-06-01 22:13:53 +08:00
|
|
|
return ObjCStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
///Generates a message send where the super is the receiver. This is a message
|
|
|
|
///send to self with special delivery semantics indicating which class's method
|
|
|
|
///should be called.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
RValue
|
|
|
|
CGObjCGNU::GenerateMessageSendSuper(CodeGenFunction &CGF,
|
2010-05-22 09:48:05 +08:00
|
|
|
ReturnValueSlot Return,
|
2008-08-30 13:35:15 +08:00
|
|
|
QualType ResultType,
|
|
|
|
Selector Sel,
|
2008-08-25 16:19:24 +08:00
|
|
|
const ObjCInterfaceDecl *Class,
|
2009-03-01 04:07:56 +08:00
|
|
|
bool isCategoryImpl,
|
2008-08-25 16:19:24 +08:00
|
|
|
llvm::Value *Receiver,
|
2008-08-30 11:02:31 +08:00
|
|
|
bool IsClassMessage,
|
2009-09-17 12:01:22 +08:00
|
|
|
const CallArgList &CallArgs,
|
|
|
|
const ObjCMethodDecl *Method) {
|
2011-05-28 22:09:01 +08:00
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
2011-09-14 01:21:33 +08:00
|
|
|
if (CGM.getLangOptions().getGC() == LangOptions::GCOnly) {
|
2010-02-03 23:59:02 +08:00
|
|
|
if (Sel == RetainSel || Sel == AutoreleaseSel) {
|
2011-05-28 22:09:01 +08:00
|
|
|
return RValue::get(EnforceType(Builder, Receiver,
|
|
|
|
CGM.getTypes().ConvertType(ResultType)));
|
2010-02-03 23:59:02 +08:00
|
|
|
}
|
|
|
|
if (Sel == ReleaseSel) {
|
|
|
|
return RValue::get(0);
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:37:16 +08:00
|
|
|
|
|
|
|
llvm::Value *cmd = GetSelector(Builder, Sel);
|
|
|
|
|
2009-02-05 04:31:19 +08:00
|
|
|
|
|
|
|
CallArgList ActualArgs;
|
|
|
|
|
2011-05-03 01:57:46 +08:00
|
|
|
ActualArgs.add(RValue::get(EnforceType(Builder, Receiver, IdTy)), ASTIdTy);
|
|
|
|
ActualArgs.add(RValue::get(cmd), CGF.getContext().getObjCSelType());
|
2011-06-16 07:02:42 +08:00
|
|
|
ActualArgs.addFrom(CallArgs);
|
2009-02-05 04:31:19 +08:00
|
|
|
|
|
|
|
CodeGenTypes &Types = CGM.getTypes();
|
2010-02-06 05:31:56 +08:00
|
|
|
const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs,
|
2010-03-31 04:24:48 +08:00
|
|
|
FunctionType::ExtInfo());
|
2009-02-05 04:31:19 +08:00
|
|
|
|
2009-05-04 23:31:17 +08:00
|
|
|
llvm::Value *ReceiverClass = 0;
|
2009-05-08 23:39:58 +08:00
|
|
|
if (isCategoryImpl) {
|
|
|
|
llvm::Constant *classLookupFunction = 0;
|
|
|
|
if (IsClassMessage) {
|
2009-07-30 06:16:19 +08:00
|
|
|
classLookupFunction = CGM.CreateRuntimeFunction(llvm::FunctionType::get(
|
2011-07-29 21:56:53 +08:00
|
|
|
IdTy, PtrTy, true), "objc_get_meta_class");
|
2009-05-08 23:39:58 +08:00
|
|
|
} else {
|
2009-07-30 06:16:19 +08:00
|
|
|
classLookupFunction = CGM.CreateRuntimeFunction(llvm::FunctionType::get(
|
2011-07-29 21:56:53 +08:00
|
|
|
IdTy, PtrTy, true), "objc_get_class");
|
2009-05-04 23:31:17 +08:00
|
|
|
}
|
2010-05-01 20:37:16 +08:00
|
|
|
ReceiverClass = Builder.CreateCall(classLookupFunction,
|
2009-05-08 23:39:58 +08:00
|
|
|
MakeConstantString(Class->getNameAsString()));
|
2009-05-04 23:31:17 +08:00
|
|
|
} else {
|
2009-05-08 23:39:58 +08:00
|
|
|
// Set up global aliases for the metaclass or class pointer if they do not
|
|
|
|
// already exist. These will are forward-references which will be set to
|
2009-08-01 05:31:32 +08:00
|
|
|
// pointers to the class and metaclass structure created for the runtime
|
|
|
|
// load function. To send a message to super, we look up the value of the
|
2009-05-08 23:39:58 +08:00
|
|
|
// super_class pointer from either the class or metaclass structure.
|
|
|
|
if (IsClassMessage) {
|
|
|
|
if (!MetaClassPtrAlias) {
|
|
|
|
MetaClassPtrAlias = new llvm::GlobalAlias(IdTy,
|
|
|
|
llvm::GlobalValue::InternalLinkage, ".objc_metaclass_ref" +
|
|
|
|
Class->getNameAsString(), NULL, &TheModule);
|
|
|
|
}
|
|
|
|
ReceiverClass = MetaClassPtrAlias;
|
|
|
|
} else {
|
|
|
|
if (!ClassPtrAlias) {
|
|
|
|
ClassPtrAlias = new llvm::GlobalAlias(IdTy,
|
|
|
|
llvm::GlobalValue::InternalLinkage, ".objc_class_ref" +
|
|
|
|
Class->getNameAsString(), NULL, &TheModule);
|
|
|
|
}
|
|
|
|
ReceiverClass = ClassPtrAlias;
|
2009-05-04 23:31:17 +08:00
|
|
|
}
|
2009-04-26 07:19:45 +08:00
|
|
|
}
|
2009-05-04 23:31:17 +08:00
|
|
|
// Cast the pointer to a simplified version of the class structure
|
2010-05-01 20:37:16 +08:00
|
|
|
ReceiverClass = Builder.CreateBitCast(ReceiverClass,
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::PointerType::getUnqual(
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType::get(IdTy, IdTy, NULL)));
|
2009-05-04 23:31:17 +08:00
|
|
|
// Get the superclass pointer
|
2010-05-01 20:37:16 +08:00
|
|
|
ReceiverClass = Builder.CreateStructGEP(ReceiverClass, 1);
|
2009-05-04 23:31:17 +08:00
|
|
|
// Load the superclass pointer
|
2010-05-01 20:37:16 +08:00
|
|
|
ReceiverClass = Builder.CreateLoad(ReceiverClass);
|
2008-06-01 22:13:53 +08:00
|
|
|
// Construct the structure used to look up the IMP
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ObjCSuperTy = llvm::StructType::get(
|
2009-08-06 07:18:46 +08:00
|
|
|
Receiver->getType(), IdTy, NULL);
|
2010-05-01 20:37:16 +08:00
|
|
|
llvm::Value *ObjCSuper = Builder.CreateAlloca(ObjCSuperTy);
|
2009-02-05 04:31:19 +08:00
|
|
|
|
2010-05-01 20:37:16 +08:00
|
|
|
Builder.CreateStore(Receiver, Builder.CreateStructGEP(ObjCSuper, 0));
|
|
|
|
Builder.CreateStore(ReceiverClass, Builder.CreateStructGEP(ObjCSuper, 1));
|
2008-06-01 22:13:53 +08:00
|
|
|
|
2011-03-24 06:52:06 +08:00
|
|
|
ObjCSuper = EnforceType(Builder, ObjCSuper, PtrToObjCSuperTy);
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::FunctionType *impType =
|
2011-03-24 06:52:06 +08:00
|
|
|
Types.GetFunctionType(FnInfo, Method ? Method->isVariadic() : false);
|
2010-05-01 20:37:16 +08:00
|
|
|
|
2011-03-24 06:52:06 +08:00
|
|
|
// Get the IMP
|
|
|
|
llvm::Value *imp = LookupIMPSuper(CGF, ObjCSuper, cmd);
|
|
|
|
imp = EnforceType(Builder, imp, llvm::PointerType::getUnqual(impType));
|
2008-06-01 22:13:53 +08:00
|
|
|
|
2010-05-01 19:15:56 +08:00
|
|
|
llvm::Value *impMD[] = {
|
|
|
|
llvm::MDString::get(VMContext, Sel.getAsString()),
|
|
|
|
llvm::MDString::get(VMContext, Class->getSuperClass()->getNameAsString()),
|
|
|
|
llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), IsClassMessage)
|
|
|
|
};
|
2011-04-22 03:59:12 +08:00
|
|
|
llvm::MDNode *node = llvm::MDNode::get(VMContext, impMD);
|
2010-05-01 19:15:56 +08:00
|
|
|
|
2010-05-02 21:41:58 +08:00
|
|
|
llvm::Instruction *call;
|
2010-05-22 09:48:05 +08:00
|
|
|
RValue msgRet = CGF.EmitCall(FnInfo, imp, Return, ActualArgs,
|
2010-05-02 21:41:58 +08:00
|
|
|
0, &call);
|
|
|
|
call->setMetadata(msgSendMDKind, node);
|
|
|
|
return msgRet;
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// Generate code for a message send expression.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
RValue
|
|
|
|
CGObjCGNU::GenerateMessageSend(CodeGenFunction &CGF,
|
2010-05-22 09:48:05 +08:00
|
|
|
ReturnValueSlot Return,
|
2008-08-30 13:35:15 +08:00
|
|
|
QualType ResultType,
|
|
|
|
Selector Sel,
|
2008-08-25 16:19:24 +08:00
|
|
|
llvm::Value *Receiver,
|
2009-05-06 05:36:57 +08:00
|
|
|
const CallArgList &CallArgs,
|
2010-04-29 03:33:36 +08:00
|
|
|
const ObjCInterfaceDecl *Class,
|
2009-05-06 05:36:57 +08:00
|
|
|
const ObjCMethodDecl *Method) {
|
2011-05-28 22:09:01 +08:00
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
|
2010-04-27 23:08:48 +08:00
|
|
|
// Strip out message sends to retain / release in GC mode
|
2011-09-14 01:21:33 +08:00
|
|
|
if (CGM.getLangOptions().getGC() == LangOptions::GCOnly) {
|
2010-02-03 23:59:02 +08:00
|
|
|
if (Sel == RetainSel || Sel == AutoreleaseSel) {
|
2011-05-28 22:09:01 +08:00
|
|
|
return RValue::get(EnforceType(Builder, Receiver,
|
|
|
|
CGM.getTypes().ConvertType(ResultType)));
|
2010-02-03 23:59:02 +08:00
|
|
|
}
|
|
|
|
if (Sel == ReleaseSel) {
|
|
|
|
return RValue::get(0);
|
|
|
|
}
|
|
|
|
}
|
2010-04-27 23:08:48 +08:00
|
|
|
|
|
|
|
// If the return type is something that goes in an integer register, the
|
|
|
|
// runtime will handle 0 returns. For other cases, we fill in the 0 value
|
|
|
|
// ourselves.
|
|
|
|
//
|
|
|
|
// The language spec says the result of this kind of message send is
|
|
|
|
// undefined, but lots of people seem to have forgotten to read that
|
|
|
|
// paragraph and insist on sending messages to nil that have structure
|
|
|
|
// returns. With GCC, this generates a random return value (whatever happens
|
|
|
|
// to be on the stack / in those registers at the time) on most platforms,
|
2011-03-24 06:52:06 +08:00
|
|
|
// and generates an illegal instruction trap on SPARC. With LLVM it corrupts
|
|
|
|
// the stack.
|
|
|
|
bool isPointerSizedReturn = (ResultType->isAnyPointerType() ||
|
|
|
|
ResultType->isIntegralOrEnumerationType() || ResultType->isVoidType());
|
2010-04-27 23:08:48 +08:00
|
|
|
|
|
|
|
llvm::BasicBlock *startBB = 0;
|
|
|
|
llvm::BasicBlock *messageBB = 0;
|
2010-05-20 21:45:48 +08:00
|
|
|
llvm::BasicBlock *continueBB = 0;
|
2010-04-27 23:08:48 +08:00
|
|
|
|
|
|
|
if (!isPointerSizedReturn) {
|
|
|
|
startBB = Builder.GetInsertBlock();
|
|
|
|
messageBB = CGF.createBasicBlock("msgSend");
|
2010-05-20 21:45:48 +08:00
|
|
|
continueBB = CGF.createBasicBlock("continue");
|
2010-04-27 23:08:48 +08:00
|
|
|
|
|
|
|
llvm::Value *isNil = Builder.CreateICmpEQ(Receiver,
|
|
|
|
llvm::Constant::getNullValue(Receiver->getType()));
|
2010-05-20 21:45:48 +08:00
|
|
|
Builder.CreateCondBr(isNil, continueBB, messageBB);
|
2010-04-27 23:08:48 +08:00
|
|
|
CGF.EmitBlock(messageBB);
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:35:33 +08:00
|
|
|
IdTy = cast<llvm::PointerType>(CGM.getTypes().ConvertType(ASTIdTy));
|
2009-05-06 05:36:57 +08:00
|
|
|
llvm::Value *cmd;
|
|
|
|
if (Method)
|
2009-09-11 05:48:21 +08:00
|
|
|
cmd = GetSelector(Builder, Method);
|
2009-05-06 05:36:57 +08:00
|
|
|
else
|
2009-09-11 05:48:21 +08:00
|
|
|
cmd = GetSelector(Builder, Sel);
|
2011-03-24 06:52:06 +08:00
|
|
|
cmd = EnforceType(Builder, cmd, SelectorTy);
|
|
|
|
Receiver = EnforceType(Builder, Receiver, IdTy);
|
|
|
|
|
|
|
|
llvm::Value *impMD[] = {
|
|
|
|
llvm::MDString::get(VMContext, Sel.getAsString()),
|
|
|
|
llvm::MDString::get(VMContext, Class ? Class->getNameAsString() :""),
|
|
|
|
llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), Class!=0)
|
|
|
|
};
|
2011-04-22 03:59:12 +08:00
|
|
|
llvm::MDNode *node = llvm::MDNode::get(VMContext, impMD);
|
2009-02-05 04:31:19 +08:00
|
|
|
|
2011-10-24 22:07:03 +08:00
|
|
|
CodeGenTypes &Types = CGM.getTypes();
|
2011-03-24 06:52:06 +08:00
|
|
|
CallArgList ActualArgs;
|
2011-05-03 01:57:46 +08:00
|
|
|
ActualArgs.add(RValue::get(Receiver), ASTIdTy);
|
|
|
|
ActualArgs.add(RValue::get(cmd), CGF.getContext().getObjCSelType());
|
2011-06-16 07:02:42 +08:00
|
|
|
ActualArgs.addFrom(CallArgs);
|
2010-02-06 05:31:56 +08:00
|
|
|
const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs,
|
2010-03-31 04:24:48 +08:00
|
|
|
FunctionType::ExtInfo());
|
2011-10-24 22:07:03 +08:00
|
|
|
// Get the IMP to call
|
|
|
|
llvm::Value *imp;
|
|
|
|
|
|
|
|
// If we have non-legacy dispatch specified, we try using the objc_msgSend()
|
|
|
|
// functions. These are not supported on all platforms (or all runtimes on a
|
|
|
|
// given platform), so we
|
|
|
|
switch (CGM.getCodeGenOpts().getObjCDispatchMethod()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Invalid dispatch method!");
|
|
|
|
case CodeGenOptions::Legacy:
|
|
|
|
imp = LookupIMP(CGF, Receiver, cmd, node);
|
|
|
|
break;
|
|
|
|
case CodeGenOptions::Mixed:
|
|
|
|
case CodeGenOptions::NonLegacy:
|
2011-10-29 01:55:06 +08:00
|
|
|
if (CGM.ReturnTypeUsesFPRet(ResultType)) {
|
|
|
|
imp = CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, IdTy, true),
|
|
|
|
"objc_msgSend_fpret");
|
2011-10-24 22:07:03 +08:00
|
|
|
} else if (CGM.ReturnTypeUsesSRet(FnInfo)) {
|
|
|
|
// The actual types here don't matter - we're going to bitcast the
|
|
|
|
// function anyway
|
|
|
|
imp = CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, IdTy, true),
|
|
|
|
"objc_msgSend_stret");
|
|
|
|
} else {
|
|
|
|
imp = CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, IdTy, true),
|
|
|
|
"objc_msgSend");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::FunctionType *impType =
|
2009-09-17 12:01:40 +08:00
|
|
|
Types.GetFunctionType(FnInfo, Method ? Method->isVariadic() : false);
|
2011-03-24 06:52:06 +08:00
|
|
|
imp = EnforceType(Builder, imp, llvm::PointerType::getUnqual(impType));
|
2010-05-01 20:56:56 +08:00
|
|
|
|
2010-05-02 21:41:58 +08:00
|
|
|
llvm::Instruction *call;
|
2010-05-22 09:48:05 +08:00
|
|
|
RValue msgRet = CGF.EmitCall(FnInfo, imp, Return, ActualArgs,
|
2010-05-02 21:41:58 +08:00
|
|
|
0, &call);
|
|
|
|
call->setMetadata(msgSendMDKind, node);
|
2010-04-27 23:08:48 +08:00
|
|
|
|
2010-05-20 21:45:48 +08:00
|
|
|
|
2010-04-27 23:08:48 +08:00
|
|
|
if (!isPointerSizedReturn) {
|
2010-05-20 21:45:48 +08:00
|
|
|
messageBB = CGF.Builder.GetInsertBlock();
|
|
|
|
CGF.Builder.CreateBr(continueBB);
|
|
|
|
CGF.EmitBlock(continueBB);
|
2010-04-27 23:08:48 +08:00
|
|
|
if (msgRet.isScalar()) {
|
|
|
|
llvm::Value *v = msgRet.getScalarVal();
|
2011-03-30 19:28:58 +08:00
|
|
|
llvm::PHINode *phi = Builder.CreatePHI(v->getType(), 2);
|
2010-04-27 23:08:48 +08:00
|
|
|
phi->addIncoming(v, messageBB);
|
|
|
|
phi->addIncoming(llvm::Constant::getNullValue(v->getType()), startBB);
|
|
|
|
msgRet = RValue::get(phi);
|
|
|
|
} else if (msgRet.isAggregate()) {
|
|
|
|
llvm::Value *v = msgRet.getAggregateAddr();
|
2011-03-30 19:28:58 +08:00
|
|
|
llvm::PHINode *phi = Builder.CreatePHI(v->getType(), 2);
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::PointerType *RetTy = cast<llvm::PointerType>(v->getType());
|
2010-04-30 21:36:12 +08:00
|
|
|
llvm::AllocaInst *NullVal =
|
|
|
|
CGF.CreateTempAlloca(RetTy->getElementType(), "null");
|
2010-04-27 23:08:48 +08:00
|
|
|
CGF.InitTempAlloca(NullVal,
|
|
|
|
llvm::Constant::getNullValue(RetTy->getElementType()));
|
|
|
|
phi->addIncoming(v, messageBB);
|
|
|
|
phi->addIncoming(NullVal, startBB);
|
|
|
|
msgRet = RValue::getAggregate(phi);
|
|
|
|
} else /* isComplex() */ {
|
|
|
|
std::pair<llvm::Value*,llvm::Value*> v = msgRet.getComplexVal();
|
2011-03-30 19:28:58 +08:00
|
|
|
llvm::PHINode *phi = Builder.CreatePHI(v.first->getType(), 2);
|
2010-04-27 23:08:48 +08:00
|
|
|
phi->addIncoming(v.first, messageBB);
|
|
|
|
phi->addIncoming(llvm::Constant::getNullValue(v.first->getType()),
|
|
|
|
startBB);
|
2011-03-30 19:28:58 +08:00
|
|
|
llvm::PHINode *phi2 = Builder.CreatePHI(v.second->getType(), 2);
|
2010-04-27 23:08:48 +08:00
|
|
|
phi2->addIncoming(v.second, messageBB);
|
|
|
|
phi2->addIncoming(llvm::Constant::getNullValue(v.second->getType()),
|
|
|
|
startBB);
|
|
|
|
msgRet = RValue::getComplex(phi, phi2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return msgRet;
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// Generates a MethodList. Used in construction of a objc_class and
|
2008-06-01 22:13:53 +08:00
|
|
|
/// objc_category structures.
|
2011-07-23 18:55:15 +08:00
|
|
|
llvm::Constant *CGObjCGNU::GenerateMethodList(const StringRef &ClassName,
|
|
|
|
const StringRef &CategoryName,
|
|
|
|
const SmallVectorImpl<Selector> &MethodSels,
|
|
|
|
const SmallVectorImpl<llvm::Constant *> &MethodTypes,
|
2008-06-01 22:13:53 +08:00
|
|
|
bool isClassMethodList) {
|
2009-08-18 00:35:33 +08:00
|
|
|
if (MethodSels.empty())
|
|
|
|
return NULLPtr;
|
2009-09-09 23:08:12 +08:00
|
|
|
// Get the method structure type.
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ObjCMethodTy = llvm::StructType::get(
|
2008-06-01 22:13:53 +08:00
|
|
|
PtrToInt8Ty, // Really a selector, but the runtime creates it us.
|
|
|
|
PtrToInt8Ty, // Method types
|
2011-03-24 06:52:06 +08:00
|
|
|
IMPTy, //Method pointer
|
2008-06-01 22:13:53 +08:00
|
|
|
NULL);
|
|
|
|
std::vector<llvm::Constant*> Methods;
|
|
|
|
std::vector<llvm::Constant*> Elements;
|
|
|
|
for (unsigned int i = 0, e = MethodTypes.size(); i < e; ++i) {
|
|
|
|
Elements.clear();
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
llvm::Constant *Method =
|
2008-06-01 22:13:53 +08:00
|
|
|
TheModule.getFunction(SymbolNameForMethod(ClassName, CategoryName,
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
MethodSels[i],
|
|
|
|
isClassMethodList));
|
|
|
|
assert(Method && "Can't generate metadata for method that doesn't exist");
|
|
|
|
llvm::Constant *C = MakeConstantString(MethodSels[i].getAsString());
|
|
|
|
Elements.push_back(C);
|
|
|
|
Elements.push_back(MethodTypes[i]);
|
|
|
|
Method = llvm::ConstantExpr::getBitCast(Method,
|
2011-03-24 06:52:06 +08:00
|
|
|
IMPTy);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
Elements.push_back(Method);
|
|
|
|
Methods.push_back(llvm::ConstantStruct::get(ObjCMethodTy, Elements));
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Array of method structures
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::ArrayType *ObjCMethodArrayTy = llvm::ArrayType::get(ObjCMethodTy,
|
2009-05-18 00:49:27 +08:00
|
|
|
Methods.size());
|
2009-07-29 02:33:04 +08:00
|
|
|
llvm::Constant *MethodArray = llvm::ConstantArray::get(ObjCMethodArrayTy,
|
2008-06-26 12:52:29 +08:00
|
|
|
Methods);
|
2008-06-01 22:13:53 +08:00
|
|
|
|
|
|
|
// Structure containing list pointer, array and array count
|
2011-08-13 01:43:31 +08:00
|
|
|
llvm::StructType *ObjCMethodListTy = llvm::StructType::create(VMContext);
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *NextPtrTy = llvm::PointerType::getUnqual(ObjCMethodListTy);
|
|
|
|
ObjCMethodListTy->setBody(
|
2009-09-09 23:08:12 +08:00
|
|
|
NextPtrTy,
|
|
|
|
IntTy,
|
2008-06-01 22:13:53 +08:00
|
|
|
ObjCMethodArrayTy,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Methods.clear();
|
2009-07-31 07:11:26 +08:00
|
|
|
Methods.push_back(llvm::ConstantPointerNull::get(
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::PointerType::getUnqual(ObjCMethodListTy)));
|
2011-10-04 23:35:30 +08:00
|
|
|
Methods.push_back(llvm::ConstantInt::get(Int32Ty, MethodTypes.size()));
|
2008-06-01 22:13:53 +08:00
|
|
|
Methods.push_back(MethodArray);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
// Create an instance of the structure
|
|
|
|
return MakeGlobal(ObjCMethodListTy, Methods, ".objc_method_list");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generates an IvarList. Used in construction of a objc_class.
|
|
|
|
llvm::Constant *CGObjCGNU::GenerateIvarList(
|
2011-07-23 18:55:15 +08:00
|
|
|
const SmallVectorImpl<llvm::Constant *> &IvarNames,
|
|
|
|
const SmallVectorImpl<llvm::Constant *> &IvarTypes,
|
|
|
|
const SmallVectorImpl<llvm::Constant *> &IvarOffsets) {
|
2009-11-17 03:05:54 +08:00
|
|
|
if (IvarNames.size() == 0)
|
|
|
|
return NULLPtr;
|
2009-09-09 23:08:12 +08:00
|
|
|
// Get the method structure type.
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ObjCIvarTy = llvm::StructType::get(
|
2008-06-01 22:13:53 +08:00
|
|
|
PtrToInt8Ty,
|
|
|
|
PtrToInt8Ty,
|
|
|
|
IntTy,
|
|
|
|
NULL);
|
|
|
|
std::vector<llvm::Constant*> Ivars;
|
|
|
|
std::vector<llvm::Constant*> Elements;
|
|
|
|
for (unsigned int i = 0, e = IvarNames.size() ; i < e ; i++) {
|
|
|
|
Elements.clear();
|
2009-09-01 00:41:57 +08:00
|
|
|
Elements.push_back(IvarNames[i]);
|
|
|
|
Elements.push_back(IvarTypes[i]);
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.push_back(IvarOffsets[i]);
|
2009-07-28 06:29:56 +08:00
|
|
|
Ivars.push_back(llvm::ConstantStruct::get(ObjCIvarTy, Elements));
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Array of method structures
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::ArrayType *ObjCIvarArrayTy = llvm::ArrayType::get(ObjCIvarTy,
|
2008-06-01 22:13:53 +08:00
|
|
|
IvarNames.size());
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.clear();
|
2009-07-25 07:12:58 +08:00
|
|
|
Elements.push_back(llvm::ConstantInt::get(IntTy, (int)IvarNames.size()));
|
2009-07-29 02:33:04 +08:00
|
|
|
Elements.push_back(llvm::ConstantArray::get(ObjCIvarArrayTy, Ivars));
|
2008-06-01 22:13:53 +08:00
|
|
|
// Structure containing array and array count
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ObjCIvarListTy = llvm::StructType::get(IntTy,
|
2008-06-01 22:13:53 +08:00
|
|
|
ObjCIvarArrayTy,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
// Create an instance of the structure
|
|
|
|
return MakeGlobal(ObjCIvarListTy, Elements, ".objc_ivar_list");
|
2008-03-01 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
/// Generate a class structure
|
|
|
|
llvm::Constant *CGObjCGNU::GenerateClassStructure(
|
|
|
|
llvm::Constant *MetaClass,
|
|
|
|
llvm::Constant *SuperClass,
|
|
|
|
unsigned info,
|
2008-06-26 12:47:04 +08:00
|
|
|
const char *Name,
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *Version,
|
|
|
|
llvm::Constant *InstanceSize,
|
|
|
|
llvm::Constant *IVars,
|
|
|
|
llvm::Constant *Methods,
|
2009-09-11 05:48:21 +08:00
|
|
|
llvm::Constant *Protocols,
|
|
|
|
llvm::Constant *IvarOffsets,
|
2010-04-28 22:29:56 +08:00
|
|
|
llvm::Constant *Properties,
|
2011-10-04 23:35:30 +08:00
|
|
|
llvm::Constant *StrongIvarBitmap,
|
|
|
|
llvm::Constant *WeakIvarBitmap,
|
2010-04-28 22:29:56 +08:00
|
|
|
bool isMeta) {
|
2008-06-01 22:13:53 +08:00
|
|
|
// Set up the class structure
|
|
|
|
// Note: Several of these are char*s when they should be ids. This is
|
|
|
|
// because the runtime performs this translation on load.
|
2009-09-11 05:48:21 +08:00
|
|
|
//
|
|
|
|
// Fields marked New ABI are part of the GNUstep runtime. We emit them
|
|
|
|
// anyway; the classes will still work with the GNU runtime, they will just
|
|
|
|
// be ignored.
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ClassTy = llvm::StructType::get(
|
2008-06-01 22:13:53 +08:00
|
|
|
PtrToInt8Ty, // class_pointer
|
|
|
|
PtrToInt8Ty, // super_class
|
|
|
|
PtrToInt8Ty, // name
|
|
|
|
LongTy, // version
|
|
|
|
LongTy, // info
|
|
|
|
LongTy, // instance_size
|
|
|
|
IVars->getType(), // ivars
|
|
|
|
Methods->getType(), // methods
|
2009-09-09 23:08:12 +08:00
|
|
|
// These are all filled in by the runtime, so we pretend
|
2008-06-01 22:13:53 +08:00
|
|
|
PtrTy, // dtable
|
|
|
|
PtrTy, // subclass_list
|
|
|
|
PtrTy, // sibling_class
|
|
|
|
PtrTy, // protocols
|
|
|
|
PtrTy, // gc_object_type
|
2009-09-11 05:48:21 +08:00
|
|
|
// New ABI:
|
|
|
|
LongTy, // abi_version
|
|
|
|
IvarOffsets->getType(), // ivar_offsets
|
|
|
|
Properties->getType(), // properties
|
2011-10-25 18:12:21 +08:00
|
|
|
IntPtrTy, // strong_pointers
|
|
|
|
IntPtrTy, // weak_pointers
|
2008-06-01 22:13:53 +08:00
|
|
|
NULL);
|
2009-07-25 07:12:58 +08:00
|
|
|
llvm::Constant *Zero = llvm::ConstantInt::get(LongTy, 0);
|
2008-06-01 22:13:53 +08:00
|
|
|
// Fill in the structure
|
|
|
|
std::vector<llvm::Constant*> Elements;
|
2009-07-30 02:54:39 +08:00
|
|
|
Elements.push_back(llvm::ConstantExpr::getBitCast(MetaClass, PtrToInt8Ty));
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.push_back(SuperClass);
|
2008-06-26 12:47:04 +08:00
|
|
|
Elements.push_back(MakeConstantString(Name, ".class_name"));
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.push_back(Zero);
|
2009-07-25 07:12:58 +08:00
|
|
|
Elements.push_back(llvm::ConstantInt::get(LongTy, info));
|
2011-02-22 07:47:40 +08:00
|
|
|
if (isMeta) {
|
|
|
|
llvm::TargetData td(&TheModule);
|
2011-04-23 01:59:22 +08:00
|
|
|
Elements.push_back(
|
|
|
|
llvm::ConstantInt::get(LongTy,
|
|
|
|
td.getTypeSizeInBits(ClassTy) /
|
|
|
|
CGM.getContext().getCharWidth()));
|
2011-02-22 07:47:40 +08:00
|
|
|
} else
|
|
|
|
Elements.push_back(InstanceSize);
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.push_back(IVars);
|
|
|
|
Elements.push_back(Methods);
|
2009-09-11 05:48:21 +08:00
|
|
|
Elements.push_back(NULLPtr);
|
|
|
|
Elements.push_back(NULLPtr);
|
|
|
|
Elements.push_back(NULLPtr);
|
2009-07-30 02:54:39 +08:00
|
|
|
Elements.push_back(llvm::ConstantExpr::getBitCast(Protocols, PtrTy));
|
2009-09-11 05:48:21 +08:00
|
|
|
Elements.push_back(NULLPtr);
|
2011-10-04 23:35:30 +08:00
|
|
|
Elements.push_back(llvm::ConstantInt::get(LongTy, 1));
|
2009-09-11 05:48:21 +08:00
|
|
|
Elements.push_back(IvarOffsets);
|
|
|
|
Elements.push_back(Properties);
|
2011-10-04 23:35:30 +08:00
|
|
|
Elements.push_back(StrongIvarBitmap);
|
|
|
|
Elements.push_back(WeakIvarBitmap);
|
2008-06-01 22:13:53 +08:00
|
|
|
// Create an instance of the structure
|
2010-01-08 08:14:31 +08:00
|
|
|
// This is now an externally visible symbol, so that we can speed up class
|
|
|
|
// messages in the next ABI.
|
2010-04-28 22:29:56 +08:00
|
|
|
return MakeGlobal(ClassTy, Elements, (isMeta ? "_OBJC_METACLASS_":
|
|
|
|
"_OBJC_CLASS_") + std::string(Name), llvm::GlobalValue::ExternalLinkage);
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Constant *CGObjCGNU::GenerateProtocolMethodList(
|
2011-07-23 18:55:15 +08:00
|
|
|
const SmallVectorImpl<llvm::Constant *> &MethodNames,
|
|
|
|
const SmallVectorImpl<llvm::Constant *> &MethodTypes) {
|
2009-09-09 23:08:12 +08:00
|
|
|
// Get the method structure type.
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ObjCMethodDescTy = llvm::StructType::get(
|
2008-06-01 22:13:53 +08:00
|
|
|
PtrToInt8Ty, // Really a selector, but the runtime does the casting for us.
|
|
|
|
PtrToInt8Ty,
|
|
|
|
NULL);
|
|
|
|
std::vector<llvm::Constant*> Methods;
|
|
|
|
std::vector<llvm::Constant*> Elements;
|
|
|
|
for (unsigned int i = 0, e = MethodTypes.size() ; i < e ; i++) {
|
|
|
|
Elements.clear();
|
2009-09-09 23:08:12 +08:00
|
|
|
Elements.push_back(MethodNames[i]);
|
2009-09-01 00:41:57 +08:00
|
|
|
Elements.push_back(MethodTypes[i]);
|
2009-07-28 06:29:56 +08:00
|
|
|
Methods.push_back(llvm::ConstantStruct::get(ObjCMethodDescTy, Elements));
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::ArrayType *ObjCMethodArrayTy = llvm::ArrayType::get(ObjCMethodDescTy,
|
2008-06-01 22:13:53 +08:00
|
|
|
MethodNames.size());
|
2009-07-29 02:33:04 +08:00
|
|
|
llvm::Constant *Array = llvm::ConstantArray::get(ObjCMethodArrayTy,
|
2009-08-01 05:31:32 +08:00
|
|
|
Methods);
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ObjCMethodDescListTy = llvm::StructType::get(
|
2008-06-01 22:13:53 +08:00
|
|
|
IntTy, ObjCMethodArrayTy, NULL);
|
|
|
|
Methods.clear();
|
2009-07-25 07:12:58 +08:00
|
|
|
Methods.push_back(llvm::ConstantInt::get(IntTy, MethodNames.size()));
|
2008-06-01 22:13:53 +08:00
|
|
|
Methods.push_back(Array);
|
|
|
|
return MakeGlobal(ObjCMethodDescListTy, Methods, ".objc_method_list");
|
|
|
|
}
|
2009-08-01 05:31:32 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
// Create the protocol list structure used in classes, categories and so on
|
|
|
|
llvm::Constant *CGObjCGNU::GenerateProtocolList(
|
2011-07-23 18:55:15 +08:00
|
|
|
const SmallVectorImpl<std::string> &Protocols) {
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::ArrayType *ProtocolArrayTy = llvm::ArrayType::get(PtrToInt8Ty,
|
2008-06-01 22:13:53 +08:00
|
|
|
Protocols.size());
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ProtocolListTy = llvm::StructType::get(
|
2008-06-01 22:13:53 +08:00
|
|
|
PtrTy, //Should be a recurisve pointer, but it's always NULL here.
|
2010-12-27 06:13:16 +08:00
|
|
|
SizeTy,
|
2008-06-01 22:13:53 +08:00
|
|
|
ProtocolArrayTy,
|
|
|
|
NULL);
|
2009-09-09 23:08:12 +08:00
|
|
|
std::vector<llvm::Constant*> Elements;
|
2008-06-01 22:13:53 +08:00
|
|
|
for (const std::string *iter = Protocols.begin(), *endIter = Protocols.end();
|
|
|
|
iter != endIter ; iter++) {
|
2009-11-20 22:50:59 +08:00
|
|
|
llvm::Constant *protocol = 0;
|
|
|
|
llvm::StringMap<llvm::Constant*>::iterator value =
|
|
|
|
ExistingProtocols.find(*iter);
|
|
|
|
if (value == ExistingProtocols.end()) {
|
2009-04-01 02:27:22 +08:00
|
|
|
protocol = GenerateEmptyProtocol(*iter);
|
2009-11-20 22:50:59 +08:00
|
|
|
} else {
|
|
|
|
protocol = value->getValue();
|
|
|
|
}
|
2009-07-30 02:54:39 +08:00
|
|
|
llvm::Constant *Ptr = llvm::ConstantExpr::getBitCast(protocol,
|
2009-07-15 07:10:40 +08:00
|
|
|
PtrToInt8Ty);
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.push_back(Ptr);
|
|
|
|
}
|
2009-07-29 02:33:04 +08:00
|
|
|
llvm::Constant * ProtocolArray = llvm::ConstantArray::get(ProtocolArrayTy,
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements);
|
|
|
|
Elements.clear();
|
|
|
|
Elements.push_back(NULLPtr);
|
2009-07-25 07:12:58 +08:00
|
|
|
Elements.push_back(llvm::ConstantInt::get(LongTy, Protocols.size()));
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.push_back(ProtocolArray);
|
|
|
|
return MakeGlobal(ProtocolListTy, Elements, ".objc_protocol_list");
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Value *CGObjCGNU::GenerateProtocolRef(CGBuilderTy &Builder,
|
2008-08-13 08:59:25 +08:00
|
|
|
const ObjCProtocolDecl *PD) {
|
2009-04-01 02:27:22 +08:00
|
|
|
llvm::Value *protocol = ExistingProtocols[PD->getNameAsString()];
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *T =
|
2009-04-01 02:27:22 +08:00
|
|
|
CGM.getTypes().ConvertType(CGM.getContext().getObjCProtoType());
|
2009-07-30 06:16:19 +08:00
|
|
|
return Builder.CreateBitCast(protocol, llvm::PointerType::getUnqual(T));
|
2009-04-01 02:27:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Constant *CGObjCGNU::GenerateEmptyProtocol(
|
|
|
|
const std::string &ProtocolName) {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<std::string, 0> EmptyStringVector;
|
|
|
|
SmallVector<llvm::Constant*, 0> EmptyConstantVector;
|
2009-04-01 02:27:22 +08:00
|
|
|
|
|
|
|
llvm::Constant *ProtocolList = GenerateProtocolList(EmptyStringVector);
|
2009-09-11 05:48:21 +08:00
|
|
|
llvm::Constant *MethodList =
|
2009-04-01 02:27:22 +08:00
|
|
|
GenerateProtocolMethodList(EmptyConstantVector, EmptyConstantVector);
|
|
|
|
// Protocols are objects containing lists of the methods implemented and
|
|
|
|
// protocols adopted.
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ProtocolTy = llvm::StructType::get(IdTy,
|
2009-04-01 02:27:22 +08:00
|
|
|
PtrToInt8Ty,
|
|
|
|
ProtocolList->getType(),
|
2009-09-11 05:48:21 +08:00
|
|
|
MethodList->getType(),
|
|
|
|
MethodList->getType(),
|
|
|
|
MethodList->getType(),
|
|
|
|
MethodList->getType(),
|
2009-04-01 02:27:22 +08:00
|
|
|
NULL);
|
2009-09-09 23:08:12 +08:00
|
|
|
std::vector<llvm::Constant*> Elements;
|
2009-04-01 02:27:22 +08:00
|
|
|
// The isa pointer must be set to a magic number so the runtime knows it's
|
|
|
|
// the correct layout.
|
2009-07-30 02:54:39 +08:00
|
|
|
Elements.push_back(llvm::ConstantExpr::getIntToPtr(
|
2011-10-04 23:35:30 +08:00
|
|
|
llvm::ConstantInt::get(Int32Ty, ProtocolVersion), IdTy));
|
2009-04-01 02:27:22 +08:00
|
|
|
Elements.push_back(MakeConstantString(ProtocolName, ".objc_protocol_name"));
|
|
|
|
Elements.push_back(ProtocolList);
|
2009-09-11 05:48:21 +08:00
|
|
|
Elements.push_back(MethodList);
|
|
|
|
Elements.push_back(MethodList);
|
|
|
|
Elements.push_back(MethodList);
|
|
|
|
Elements.push_back(MethodList);
|
2009-04-01 02:27:22 +08:00
|
|
|
return MakeGlobal(ProtocolTy, Elements, ".objc_protocol");
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
|
|
|
|
2008-08-13 08:59:25 +08:00
|
|
|
void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) {
|
|
|
|
ASTContext &Context = CGM.getContext();
|
2008-11-24 11:54:41 +08:00
|
|
|
std::string ProtocolName = PD->getNameAsString();
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<std::string, 16> Protocols;
|
2008-08-13 08:59:25 +08:00
|
|
|
for (ObjCProtocolDecl::protocol_iterator PI = PD->protocol_begin(),
|
|
|
|
E = PD->protocol_end(); PI != E; ++PI)
|
2008-11-24 13:29:24 +08:00
|
|
|
Protocols.push_back((*PI)->getNameAsString());
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<llvm::Constant*, 16> InstanceMethodNames;
|
|
|
|
SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
|
|
|
|
SmallVector<llvm::Constant*, 16> OptionalInstanceMethodNames;
|
|
|
|
SmallVector<llvm::Constant*, 16> OptionalInstanceMethodTypes;
|
2009-06-30 10:36:12 +08:00
|
|
|
for (ObjCProtocolDecl::instmeth_iterator iter = PD->instmeth_begin(),
|
|
|
|
E = PD->instmeth_end(); iter != E; iter++) {
|
2008-08-13 08:59:25 +08:00
|
|
|
std::string TypeStr;
|
|
|
|
Context.getObjCEncodingForMethodDecl(*iter, TypeStr);
|
2009-09-11 05:48:21 +08:00
|
|
|
if ((*iter)->getImplementationControl() == ObjCMethodDecl::Optional) {
|
|
|
|
InstanceMethodNames.push_back(
|
|
|
|
MakeConstantString((*iter)->getSelector().getAsString()));
|
|
|
|
InstanceMethodTypes.push_back(MakeConstantString(TypeStr));
|
|
|
|
} else {
|
|
|
|
OptionalInstanceMethodNames.push_back(
|
|
|
|
MakeConstantString((*iter)->getSelector().getAsString()));
|
|
|
|
OptionalInstanceMethodTypes.push_back(MakeConstantString(TypeStr));
|
|
|
|
}
|
2008-08-13 08:59:25 +08:00
|
|
|
}
|
|
|
|
// Collect information about class methods:
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<llvm::Constant*, 16> ClassMethodNames;
|
|
|
|
SmallVector<llvm::Constant*, 16> ClassMethodTypes;
|
|
|
|
SmallVector<llvm::Constant*, 16> OptionalClassMethodNames;
|
|
|
|
SmallVector<llvm::Constant*, 16> OptionalClassMethodTypes;
|
2009-09-09 23:08:12 +08:00
|
|
|
for (ObjCProtocolDecl::classmeth_iterator
|
2009-06-30 10:36:12 +08:00
|
|
|
iter = PD->classmeth_begin(), endIter = PD->classmeth_end();
|
|
|
|
iter != endIter ; iter++) {
|
2008-08-13 08:59:25 +08:00
|
|
|
std::string TypeStr;
|
|
|
|
Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
|
2009-09-11 05:48:21 +08:00
|
|
|
if ((*iter)->getImplementationControl() == ObjCMethodDecl::Optional) {
|
|
|
|
ClassMethodNames.push_back(
|
|
|
|
MakeConstantString((*iter)->getSelector().getAsString()));
|
|
|
|
ClassMethodTypes.push_back(MakeConstantString(TypeStr));
|
|
|
|
} else {
|
|
|
|
OptionalClassMethodNames.push_back(
|
|
|
|
MakeConstantString((*iter)->getSelector().getAsString()));
|
|
|
|
OptionalClassMethodTypes.push_back(MakeConstantString(TypeStr));
|
|
|
|
}
|
2008-08-13 08:59:25 +08:00
|
|
|
}
|
2008-06-01 22:13:53 +08:00
|
|
|
|
|
|
|
llvm::Constant *ProtocolList = GenerateProtocolList(Protocols);
|
|
|
|
llvm::Constant *InstanceMethodList =
|
|
|
|
GenerateProtocolMethodList(InstanceMethodNames, InstanceMethodTypes);
|
|
|
|
llvm::Constant *ClassMethodList =
|
|
|
|
GenerateProtocolMethodList(ClassMethodNames, ClassMethodTypes);
|
2009-09-11 05:48:21 +08:00
|
|
|
llvm::Constant *OptionalInstanceMethodList =
|
|
|
|
GenerateProtocolMethodList(OptionalInstanceMethodNames,
|
|
|
|
OptionalInstanceMethodTypes);
|
|
|
|
llvm::Constant *OptionalClassMethodList =
|
|
|
|
GenerateProtocolMethodList(OptionalClassMethodNames,
|
|
|
|
OptionalClassMethodTypes);
|
|
|
|
|
|
|
|
// Property metadata: name, attributes, isSynthesized, setter name, setter
|
|
|
|
// types, getter name, getter types.
|
|
|
|
// The isSynthesized value is always set to 0 in a protocol. It exists to
|
|
|
|
// simplify the runtime library by allowing it to use the same data
|
|
|
|
// structures for protocol metadata everywhere.
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *PropertyMetadataTy = llvm::StructType::get(
|
2009-09-11 05:48:21 +08:00
|
|
|
PtrToInt8Ty, Int8Ty, Int8Ty, PtrToInt8Ty, PtrToInt8Ty, PtrToInt8Ty,
|
|
|
|
PtrToInt8Ty, NULL);
|
|
|
|
std::vector<llvm::Constant*> Properties;
|
|
|
|
std::vector<llvm::Constant*> OptionalProperties;
|
|
|
|
|
|
|
|
// Add all of the property methods need adding to the method list and to the
|
|
|
|
// property metadata list.
|
|
|
|
for (ObjCContainerDecl::prop_iterator
|
|
|
|
iter = PD->prop_begin(), endIter = PD->prop_end();
|
|
|
|
iter != endIter ; iter++) {
|
|
|
|
std::vector<llvm::Constant*> Fields;
|
|
|
|
ObjCPropertyDecl *property = (*iter);
|
|
|
|
|
|
|
|
Fields.push_back(MakeConstantString(property->getNameAsString()));
|
|
|
|
Fields.push_back(llvm::ConstantInt::get(Int8Ty,
|
|
|
|
property->getPropertyAttributes()));
|
|
|
|
Fields.push_back(llvm::ConstantInt::get(Int8Ty, 0));
|
|
|
|
if (ObjCMethodDecl *getter = property->getGetterMethodDecl()) {
|
|
|
|
std::string TypeStr;
|
|
|
|
Context.getObjCEncodingForMethodDecl(getter,TypeStr);
|
|
|
|
llvm::Constant *TypeEncoding = MakeConstantString(TypeStr);
|
|
|
|
InstanceMethodTypes.push_back(TypeEncoding);
|
|
|
|
Fields.push_back(MakeConstantString(getter->getSelector().getAsString()));
|
|
|
|
Fields.push_back(TypeEncoding);
|
|
|
|
} else {
|
|
|
|
Fields.push_back(NULLPtr);
|
|
|
|
Fields.push_back(NULLPtr);
|
|
|
|
}
|
|
|
|
if (ObjCMethodDecl *setter = property->getSetterMethodDecl()) {
|
|
|
|
std::string TypeStr;
|
|
|
|
Context.getObjCEncodingForMethodDecl(setter,TypeStr);
|
|
|
|
llvm::Constant *TypeEncoding = MakeConstantString(TypeStr);
|
|
|
|
InstanceMethodTypes.push_back(TypeEncoding);
|
|
|
|
Fields.push_back(MakeConstantString(setter->getSelector().getAsString()));
|
|
|
|
Fields.push_back(TypeEncoding);
|
|
|
|
} else {
|
|
|
|
Fields.push_back(NULLPtr);
|
|
|
|
Fields.push_back(NULLPtr);
|
|
|
|
}
|
|
|
|
if (property->getPropertyImplementation() == ObjCPropertyDecl::Optional) {
|
|
|
|
OptionalProperties.push_back(llvm::ConstantStruct::get(PropertyMetadataTy, Fields));
|
|
|
|
} else {
|
|
|
|
Properties.push_back(llvm::ConstantStruct::get(PropertyMetadataTy, Fields));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
llvm::Constant *PropertyArray = llvm::ConstantArray::get(
|
|
|
|
llvm::ArrayType::get(PropertyMetadataTy, Properties.size()), Properties);
|
|
|
|
llvm::Constant* PropertyListInitFields[] =
|
|
|
|
{llvm::ConstantInt::get(IntTy, Properties.size()), NULLPtr, PropertyArray};
|
|
|
|
|
|
|
|
llvm::Constant *PropertyListInit =
|
2011-06-20 12:01:35 +08:00
|
|
|
llvm::ConstantStruct::getAnon(PropertyListInitFields);
|
2009-09-11 05:48:21 +08:00
|
|
|
llvm::Constant *PropertyList = new llvm::GlobalVariable(TheModule,
|
|
|
|
PropertyListInit->getType(), false, llvm::GlobalValue::InternalLinkage,
|
|
|
|
PropertyListInit, ".objc_property_list");
|
|
|
|
|
|
|
|
llvm::Constant *OptionalPropertyArray =
|
|
|
|
llvm::ConstantArray::get(llvm::ArrayType::get(PropertyMetadataTy,
|
|
|
|
OptionalProperties.size()) , OptionalProperties);
|
|
|
|
llvm::Constant* OptionalPropertyListInitFields[] = {
|
|
|
|
llvm::ConstantInt::get(IntTy, OptionalProperties.size()), NULLPtr,
|
|
|
|
OptionalPropertyArray };
|
|
|
|
|
|
|
|
llvm::Constant *OptionalPropertyListInit =
|
2011-06-20 12:01:35 +08:00
|
|
|
llvm::ConstantStruct::getAnon(OptionalPropertyListInitFields);
|
2009-09-11 05:48:21 +08:00
|
|
|
llvm::Constant *OptionalPropertyList = new llvm::GlobalVariable(TheModule,
|
|
|
|
OptionalPropertyListInit->getType(), false,
|
|
|
|
llvm::GlobalValue::InternalLinkage, OptionalPropertyListInit,
|
|
|
|
".objc_property_list");
|
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
// Protocols are objects containing lists of the methods implemented and
|
|
|
|
// protocols adopted.
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ProtocolTy = llvm::StructType::get(IdTy,
|
2008-06-01 22:13:53 +08:00
|
|
|
PtrToInt8Ty,
|
|
|
|
ProtocolList->getType(),
|
|
|
|
InstanceMethodList->getType(),
|
|
|
|
ClassMethodList->getType(),
|
2009-09-11 05:48:21 +08:00
|
|
|
OptionalInstanceMethodList->getType(),
|
|
|
|
OptionalClassMethodList->getType(),
|
|
|
|
PropertyList->getType(),
|
|
|
|
OptionalPropertyList->getType(),
|
2008-06-01 22:13:53 +08:00
|
|
|
NULL);
|
2009-09-09 23:08:12 +08:00
|
|
|
std::vector<llvm::Constant*> Elements;
|
2008-06-01 22:13:53 +08:00
|
|
|
// The isa pointer must be set to a magic number so the runtime knows it's
|
|
|
|
// the correct layout.
|
2009-07-30 02:54:39 +08:00
|
|
|
Elements.push_back(llvm::ConstantExpr::getIntToPtr(
|
2011-10-04 23:35:30 +08:00
|
|
|
llvm::ConstantInt::get(Int32Ty, ProtocolVersion), IdTy));
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.push_back(MakeConstantString(ProtocolName, ".objc_protocol_name"));
|
|
|
|
Elements.push_back(ProtocolList);
|
|
|
|
Elements.push_back(InstanceMethodList);
|
|
|
|
Elements.push_back(ClassMethodList);
|
2009-09-11 05:48:21 +08:00
|
|
|
Elements.push_back(OptionalInstanceMethodList);
|
|
|
|
Elements.push_back(OptionalClassMethodList);
|
|
|
|
Elements.push_back(PropertyList);
|
|
|
|
Elements.push_back(OptionalPropertyList);
|
2009-09-09 23:08:12 +08:00
|
|
|
ExistingProtocols[ProtocolName] =
|
2009-07-30 02:54:39 +08:00
|
|
|
llvm::ConstantExpr::getBitCast(MakeGlobal(ProtocolTy, Elements,
|
2008-06-01 22:13:53 +08:00
|
|
|
".objc_protocol"), IdTy);
|
|
|
|
}
|
2009-09-11 05:48:21 +08:00
|
|
|
void CGObjCGNU::GenerateProtocolHolderCategory(void) {
|
|
|
|
// Collect information about instance methods
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Selector, 1> MethodSels;
|
|
|
|
SmallVector<llvm::Constant*, 1> MethodTypes;
|
2009-09-11 05:48:21 +08:00
|
|
|
|
|
|
|
std::vector<llvm::Constant*> Elements;
|
|
|
|
const std::string ClassName = "__ObjC_Protocol_Holder_Ugly_Hack";
|
|
|
|
const std::string CategoryName = "AnotherHack";
|
|
|
|
Elements.push_back(MakeConstantString(CategoryName));
|
|
|
|
Elements.push_back(MakeConstantString(ClassName));
|
|
|
|
// Instance method list
|
|
|
|
Elements.push_back(llvm::ConstantExpr::getBitCast(GenerateMethodList(
|
|
|
|
ClassName, CategoryName, MethodSels, MethodTypes, false), PtrTy));
|
|
|
|
// Class method list
|
|
|
|
Elements.push_back(llvm::ConstantExpr::getBitCast(GenerateMethodList(
|
|
|
|
ClassName, CategoryName, MethodSels, MethodTypes, true), PtrTy));
|
|
|
|
// Protocol list
|
|
|
|
llvm::ArrayType *ProtocolArrayTy = llvm::ArrayType::get(PtrTy,
|
|
|
|
ExistingProtocols.size());
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *ProtocolListTy = llvm::StructType::get(
|
2009-09-11 05:48:21 +08:00
|
|
|
PtrTy, //Should be a recurisve pointer, but it's always NULL here.
|
2010-12-27 06:13:16 +08:00
|
|
|
SizeTy,
|
2009-09-11 05:48:21 +08:00
|
|
|
ProtocolArrayTy,
|
|
|
|
NULL);
|
|
|
|
std::vector<llvm::Constant*> ProtocolElements;
|
|
|
|
for (llvm::StringMapIterator<llvm::Constant*> iter =
|
|
|
|
ExistingProtocols.begin(), endIter = ExistingProtocols.end();
|
|
|
|
iter != endIter ; iter++) {
|
|
|
|
llvm::Constant *Ptr = llvm::ConstantExpr::getBitCast(iter->getValue(),
|
|
|
|
PtrTy);
|
|
|
|
ProtocolElements.push_back(Ptr);
|
|
|
|
}
|
|
|
|
llvm::Constant * ProtocolArray = llvm::ConstantArray::get(ProtocolArrayTy,
|
|
|
|
ProtocolElements);
|
|
|
|
ProtocolElements.clear();
|
|
|
|
ProtocolElements.push_back(NULLPtr);
|
|
|
|
ProtocolElements.push_back(llvm::ConstantInt::get(LongTy,
|
|
|
|
ExistingProtocols.size()));
|
|
|
|
ProtocolElements.push_back(ProtocolArray);
|
|
|
|
Elements.push_back(llvm::ConstantExpr::getBitCast(MakeGlobal(ProtocolListTy,
|
|
|
|
ProtocolElements, ".objc_protocol_list"), PtrTy));
|
|
|
|
Categories.push_back(llvm::ConstantExpr::getBitCast(
|
2011-06-19 06:49:11 +08:00
|
|
|
MakeGlobal(llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty,
|
2009-09-11 05:48:21 +08:00
|
|
|
PtrTy, PtrTy, PtrTy, NULL), Elements), PtrTy));
|
|
|
|
}
|
2008-06-01 22:13:53 +08:00
|
|
|
|
2011-10-04 23:35:30 +08:00
|
|
|
/// Libobjc2 uses a bitfield representation where small(ish) bitfields are
|
|
|
|
/// stored in a 64-bit value with the low bit set to 1 and the remaining 63
|
|
|
|
/// bits set to their values, LSB first, while larger ones are stored in a
|
|
|
|
/// structure of this / form:
|
|
|
|
///
|
|
|
|
/// struct { int32_t length; int32_t values[length]; };
|
|
|
|
///
|
|
|
|
/// The values in the array are stored in host-endian format, with the least
|
|
|
|
/// significant bit being assumed to come first in the bitfield. Therefore, a
|
|
|
|
/// bitfield with the 64th bit set will be (int64_t)&{ 2, [0, 1<<31] }, while a
|
|
|
|
/// bitfield / with the 63rd bit set will be 1<<64.
|
|
|
|
llvm::Constant *CGObjCGNU::MakeBitField(llvm::SmallVectorImpl<bool> &bits) {
|
|
|
|
int bitCount = bits.size();
|
2011-10-25 18:12:21 +08:00
|
|
|
int ptrBits =
|
|
|
|
(TheModule.getPointerSize() == llvm::Module::Pointer32) ? 32 : 64;
|
|
|
|
if (bitCount < ptrBits) {
|
2011-10-04 23:35:30 +08:00
|
|
|
uint64_t val = 1;
|
|
|
|
for (int i=0 ; i<bitCount ; ++i) {
|
2011-10-08 09:03:47 +08:00
|
|
|
if (bits[i]) val |= 1ULL<<(i+1);
|
2011-10-04 23:35:30 +08:00
|
|
|
}
|
2011-10-25 18:12:21 +08:00
|
|
|
return llvm::ConstantInt::get(IntPtrTy, val);
|
2011-10-04 23:35:30 +08:00
|
|
|
}
|
|
|
|
llvm::SmallVector<llvm::Constant*, 8> values;
|
|
|
|
int v=0;
|
|
|
|
while (v < bitCount) {
|
|
|
|
int32_t word = 0;
|
|
|
|
for (int i=0 ; (i<32) && (v<bitCount) ; ++i) {
|
|
|
|
if (bits[v]) word |= 1<<i;
|
|
|
|
v++;
|
|
|
|
}
|
|
|
|
values.push_back(llvm::ConstantInt::get(Int32Ty, word));
|
|
|
|
}
|
|
|
|
llvm::ArrayType *arrayTy = llvm::ArrayType::get(Int32Ty, values.size());
|
|
|
|
llvm::Constant *array = llvm::ConstantArray::get(arrayTy, values);
|
|
|
|
llvm::Constant *fields[2] = {
|
|
|
|
llvm::ConstantInt::get(Int32Ty, values.size()),
|
|
|
|
array };
|
|
|
|
llvm::Constant *GS = MakeGlobal(llvm::StructType::get(Int32Ty, arrayTy,
|
|
|
|
NULL), fields);
|
2011-10-08 16:54:36 +08:00
|
|
|
llvm::Constant *ptr = llvm::ConstantExpr::getPtrToInt(GS, IntPtrTy);
|
|
|
|
return ptr;
|
2011-10-04 23:35:30 +08:00
|
|
|
}
|
|
|
|
|
2008-08-16 06:20:32 +08:00
|
|
|
void CGObjCGNU::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
|
2008-11-24 11:54:41 +08:00
|
|
|
std::string ClassName = OCD->getClassInterface()->getNameAsString();
|
|
|
|
std::string CategoryName = OCD->getNameAsString();
|
2008-08-16 06:20:32 +08:00
|
|
|
// Collect information about instance methods
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Selector, 16> InstanceMethodSels;
|
|
|
|
SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
|
2009-04-23 09:02:12 +08:00
|
|
|
for (ObjCCategoryImplDecl::instmeth_iterator
|
2009-06-30 10:36:12 +08:00
|
|
|
iter = OCD->instmeth_begin(), endIter = OCD->instmeth_end();
|
2009-04-23 09:02:12 +08:00
|
|
|
iter != endIter ; iter++) {
|
2008-08-16 06:20:32 +08:00
|
|
|
InstanceMethodSels.push_back((*iter)->getSelector());
|
|
|
|
std::string TypeStr;
|
|
|
|
CGM.getContext().getObjCEncodingForMethodDecl(*iter,TypeStr);
|
2009-09-01 00:41:57 +08:00
|
|
|
InstanceMethodTypes.push_back(MakeConstantString(TypeStr));
|
2008-08-16 06:20:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect information about class methods
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Selector, 16> ClassMethodSels;
|
|
|
|
SmallVector<llvm::Constant*, 16> ClassMethodTypes;
|
2009-09-09 23:08:12 +08:00
|
|
|
for (ObjCCategoryImplDecl::classmeth_iterator
|
2009-06-30 10:36:12 +08:00
|
|
|
iter = OCD->classmeth_begin(), endIter = OCD->classmeth_end();
|
2009-04-23 09:02:12 +08:00
|
|
|
iter != endIter ; iter++) {
|
2008-08-16 06:20:32 +08:00
|
|
|
ClassMethodSels.push_back((*iter)->getSelector());
|
|
|
|
std::string TypeStr;
|
|
|
|
CGM.getContext().getObjCEncodingForMethodDecl(*iter,TypeStr);
|
2009-09-01 00:41:57 +08:00
|
|
|
ClassMethodTypes.push_back(MakeConstantString(TypeStr));
|
2008-08-16 06:20:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect the names of referenced protocols
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<std::string, 16> Protocols;
|
2010-03-14 06:20:45 +08:00
|
|
|
const ObjCCategoryDecl *CatDecl = OCD->getCategoryDecl();
|
|
|
|
const ObjCList<ObjCProtocolDecl> &Protos = CatDecl->getReferencedProtocols();
|
2008-08-16 06:20:32 +08:00
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protos.begin(),
|
|
|
|
E = Protos.end(); I != E; ++I)
|
2008-11-24 13:29:24 +08:00
|
|
|
Protocols.push_back((*I)->getNameAsString());
|
2008-08-16 06:20:32 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
std::vector<llvm::Constant*> Elements;
|
|
|
|
Elements.push_back(MakeConstantString(CategoryName));
|
|
|
|
Elements.push_back(MakeConstantString(ClassName));
|
2009-09-09 23:08:12 +08:00
|
|
|
// Instance method list
|
2009-07-30 02:54:39 +08:00
|
|
|
Elements.push_back(llvm::ConstantExpr::getBitCast(GenerateMethodList(
|
2008-06-26 13:08:00 +08:00
|
|
|
ClassName, CategoryName, InstanceMethodSels, InstanceMethodTypes,
|
2008-06-01 22:13:53 +08:00
|
|
|
false), PtrTy));
|
|
|
|
// Class method list
|
2009-07-30 02:54:39 +08:00
|
|
|
Elements.push_back(llvm::ConstantExpr::getBitCast(GenerateMethodList(
|
2008-06-26 13:08:00 +08:00
|
|
|
ClassName, CategoryName, ClassMethodSels, ClassMethodTypes, true),
|
2008-06-01 22:13:53 +08:00
|
|
|
PtrTy));
|
|
|
|
// Protocol list
|
2009-07-30 02:54:39 +08:00
|
|
|
Elements.push_back(llvm::ConstantExpr::getBitCast(
|
2008-06-01 22:13:53 +08:00
|
|
|
GenerateProtocolList(Protocols), PtrTy));
|
2009-07-30 02:54:39 +08:00
|
|
|
Categories.push_back(llvm::ConstantExpr::getBitCast(
|
2011-06-19 06:49:11 +08:00
|
|
|
MakeGlobal(llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty,
|
2009-08-06 07:18:46 +08:00
|
|
|
PtrTy, PtrTy, PtrTy, NULL), Elements), PtrTy));
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
2008-08-16 06:20:32 +08:00
|
|
|
|
2009-09-11 05:48:21 +08:00
|
|
|
llvm::Constant *CGObjCGNU::GeneratePropertyList(const ObjCImplementationDecl *OID,
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVectorImpl<Selector> &InstanceMethodSels,
|
|
|
|
SmallVectorImpl<llvm::Constant*> &InstanceMethodTypes) {
|
2009-09-11 05:48:21 +08:00
|
|
|
ASTContext &Context = CGM.getContext();
|
|
|
|
//
|
|
|
|
// Property metadata: name, attributes, isSynthesized, setter name, setter
|
|
|
|
// types, getter name, getter types.
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *PropertyMetadataTy = llvm::StructType::get(
|
2009-09-11 05:48:21 +08:00
|
|
|
PtrToInt8Ty, Int8Ty, Int8Ty, PtrToInt8Ty, PtrToInt8Ty, PtrToInt8Ty,
|
|
|
|
PtrToInt8Ty, NULL);
|
|
|
|
std::vector<llvm::Constant*> Properties;
|
|
|
|
|
|
|
|
|
|
|
|
// Add all of the property methods need adding to the method list and to the
|
|
|
|
// property metadata list.
|
|
|
|
for (ObjCImplDecl::propimpl_iterator
|
|
|
|
iter = OID->propimpl_begin(), endIter = OID->propimpl_end();
|
|
|
|
iter != endIter ; iter++) {
|
|
|
|
std::vector<llvm::Constant*> Fields;
|
|
|
|
ObjCPropertyDecl *property = (*iter)->getPropertyDecl();
|
2010-02-26 09:11:38 +08:00
|
|
|
ObjCPropertyImplDecl *propertyImpl = *iter;
|
|
|
|
bool isSynthesized = (propertyImpl->getPropertyImplementation() ==
|
|
|
|
ObjCPropertyImplDecl::Synthesize);
|
2009-09-11 05:48:21 +08:00
|
|
|
|
|
|
|
Fields.push_back(MakeConstantString(property->getNameAsString()));
|
|
|
|
Fields.push_back(llvm::ConstantInt::get(Int8Ty,
|
|
|
|
property->getPropertyAttributes()));
|
2010-02-26 09:11:38 +08:00
|
|
|
Fields.push_back(llvm::ConstantInt::get(Int8Ty, isSynthesized));
|
2009-09-11 05:48:21 +08:00
|
|
|
if (ObjCMethodDecl *getter = property->getGetterMethodDecl()) {
|
|
|
|
std::string TypeStr;
|
|
|
|
Context.getObjCEncodingForMethodDecl(getter,TypeStr);
|
|
|
|
llvm::Constant *TypeEncoding = MakeConstantString(TypeStr);
|
2010-02-26 09:11:38 +08:00
|
|
|
if (isSynthesized) {
|
|
|
|
InstanceMethodTypes.push_back(TypeEncoding);
|
|
|
|
InstanceMethodSels.push_back(getter->getSelector());
|
|
|
|
}
|
2009-09-11 05:48:21 +08:00
|
|
|
Fields.push_back(MakeConstantString(getter->getSelector().getAsString()));
|
|
|
|
Fields.push_back(TypeEncoding);
|
|
|
|
} else {
|
|
|
|
Fields.push_back(NULLPtr);
|
|
|
|
Fields.push_back(NULLPtr);
|
|
|
|
}
|
|
|
|
if (ObjCMethodDecl *setter = property->getSetterMethodDecl()) {
|
|
|
|
std::string TypeStr;
|
|
|
|
Context.getObjCEncodingForMethodDecl(setter,TypeStr);
|
|
|
|
llvm::Constant *TypeEncoding = MakeConstantString(TypeStr);
|
2010-02-26 09:11:38 +08:00
|
|
|
if (isSynthesized) {
|
|
|
|
InstanceMethodTypes.push_back(TypeEncoding);
|
|
|
|
InstanceMethodSels.push_back(setter->getSelector());
|
|
|
|
}
|
2009-09-11 05:48:21 +08:00
|
|
|
Fields.push_back(MakeConstantString(setter->getSelector().getAsString()));
|
|
|
|
Fields.push_back(TypeEncoding);
|
|
|
|
} else {
|
|
|
|
Fields.push_back(NULLPtr);
|
|
|
|
Fields.push_back(NULLPtr);
|
|
|
|
}
|
|
|
|
Properties.push_back(llvm::ConstantStruct::get(PropertyMetadataTy, Fields));
|
|
|
|
}
|
|
|
|
llvm::ArrayType *PropertyArrayTy =
|
|
|
|
llvm::ArrayType::get(PropertyMetadataTy, Properties.size());
|
|
|
|
llvm::Constant *PropertyArray = llvm::ConstantArray::get(PropertyArrayTy,
|
|
|
|
Properties);
|
|
|
|
llvm::Constant* PropertyListInitFields[] =
|
|
|
|
{llvm::ConstantInt::get(IntTy, Properties.size()), NULLPtr, PropertyArray};
|
|
|
|
|
|
|
|
llvm::Constant *PropertyListInit =
|
2011-06-20 12:01:35 +08:00
|
|
|
llvm::ConstantStruct::getAnon(PropertyListInitFields);
|
2009-09-11 05:48:21 +08:00
|
|
|
return new llvm::GlobalVariable(TheModule, PropertyListInit->getType(), false,
|
|
|
|
llvm::GlobalValue::InternalLinkage, PropertyListInit,
|
|
|
|
".objc_property_list");
|
|
|
|
}
|
|
|
|
|
2008-08-16 06:20:32 +08:00
|
|
|
void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
|
|
|
|
ASTContext &Context = CGM.getContext();
|
|
|
|
|
|
|
|
// Get the superclass name.
|
2009-09-09 23:08:12 +08:00
|
|
|
const ObjCInterfaceDecl * SuperClassDecl =
|
2008-08-16 06:20:32 +08:00
|
|
|
OID->getClassInterface()->getSuperClass();
|
2008-11-24 11:54:41 +08:00
|
|
|
std::string SuperClassName;
|
2009-06-15 09:09:11 +08:00
|
|
|
if (SuperClassDecl) {
|
2008-11-24 11:54:41 +08:00
|
|
|
SuperClassName = SuperClassDecl->getNameAsString();
|
2009-06-15 09:09:11 +08:00
|
|
|
EmitClassRef(SuperClassName);
|
|
|
|
}
|
2008-08-16 06:20:32 +08:00
|
|
|
|
|
|
|
// Get the class name
|
2009-04-01 10:00:48 +08:00
|
|
|
ObjCInterfaceDecl *ClassDecl =
|
|
|
|
const_cast<ObjCInterfaceDecl *>(OID->getClassInterface());
|
2008-11-24 11:54:41 +08:00
|
|
|
std::string ClassName = ClassDecl->getNameAsString();
|
2009-06-15 09:09:11 +08:00
|
|
|
// Emit the symbol that is used to generate linker errors if this class is
|
|
|
|
// referenced in other modules but not declared.
|
2009-07-03 23:10:14 +08:00
|
|
|
std::string classSymbolName = "__objc_class_name_" + ClassName;
|
2009-09-09 23:08:12 +08:00
|
|
|
if (llvm::GlobalVariable *symbol =
|
2009-07-03 23:10:14 +08:00
|
|
|
TheModule.getGlobalVariable(classSymbolName)) {
|
2009-07-25 07:12:58 +08:00
|
|
|
symbol->setInitializer(llvm::ConstantInt::get(LongTy, 0));
|
2009-07-03 23:10:14 +08:00
|
|
|
} else {
|
2009-07-09 03:05:04 +08:00
|
|
|
new llvm::GlobalVariable(TheModule, LongTy, false,
|
2009-07-25 07:12:58 +08:00
|
|
|
llvm::GlobalValue::ExternalLinkage, llvm::ConstantInt::get(LongTy, 0),
|
2009-07-09 03:05:04 +08:00
|
|
|
classSymbolName);
|
2009-07-03 23:10:14 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-03 18:46:44 +08:00
|
|
|
// Get the size of instances.
|
2011-02-09 09:59:34 +08:00
|
|
|
int instanceSize =
|
|
|
|
Context.getASTObjCImplementationLayout(OID).getSize().getQuantity();
|
2008-08-16 06:20:32 +08:00
|
|
|
|
|
|
|
// Collect information about instance variables.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<llvm::Constant*, 16> IvarNames;
|
|
|
|
SmallVector<llvm::Constant*, 16> IvarTypes;
|
|
|
|
SmallVector<llvm::Constant*, 16> IvarOffsets;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-11 05:48:21 +08:00
|
|
|
std::vector<llvm::Constant*> IvarOffsetValues;
|
2011-10-04 23:35:30 +08:00
|
|
|
SmallVector<bool, 16> WeakIvars;
|
|
|
|
SmallVector<bool, 16> StrongIvars;
|
2009-09-11 05:48:21 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
int superInstanceSize = !SuperClassDecl ? 0 :
|
2011-02-09 09:59:34 +08:00
|
|
|
Context.getASTObjCInterfaceLayout(SuperClassDecl).getSize().getQuantity();
|
2009-05-21 02:41:51 +08:00
|
|
|
// For non-fragile ivars, set the instance size to 0 - {the size of just this
|
|
|
|
// class}. The runtime will then set this to the correct value on load.
|
|
|
|
if (CGM.getContext().getLangOptions().ObjCNonFragileABI) {
|
|
|
|
instanceSize = 0 - (instanceSize - superInstanceSize);
|
|
|
|
}
|
2010-04-19 08:45:34 +08:00
|
|
|
|
2011-07-22 10:08:32 +08:00
|
|
|
for (const ObjCIvarDecl *IVD = ClassDecl->all_declared_ivar_begin(); IVD;
|
|
|
|
IVD = IVD->getNextIvar()) {
|
2008-08-16 06:20:32 +08:00
|
|
|
// Store the name
|
2010-04-19 08:45:34 +08:00
|
|
|
IvarNames.push_back(MakeConstantString(IVD->getNameAsString()));
|
2008-08-16 06:20:32 +08:00
|
|
|
// Get the type encoding for this ivar
|
|
|
|
std::string TypeStr;
|
2010-04-19 08:45:34 +08:00
|
|
|
Context.getObjCEncodingForType(IVD->getType(), TypeStr);
|
2009-09-01 00:41:57 +08:00
|
|
|
IvarTypes.push_back(MakeConstantString(TypeStr));
|
2008-08-16 06:20:32 +08:00
|
|
|
// Get the offset
|
2010-04-19 09:37:25 +08:00
|
|
|
uint64_t BaseOffset = ComputeIvarBaseOffset(CGM, OID, IVD);
|
2009-11-18 03:32:15 +08:00
|
|
|
uint64_t Offset = BaseOffset;
|
2009-05-21 02:41:51 +08:00
|
|
|
if (CGM.getContext().getLangOptions().ObjCNonFragileABI) {
|
2009-09-11 05:48:21 +08:00
|
|
|
Offset = BaseOffset - superInstanceSize;
|
2009-05-21 02:41:51 +08:00
|
|
|
}
|
2011-07-07 20:34:51 +08:00
|
|
|
llvm::Constant *OffsetValue = llvm::ConstantInt::get(IntTy, Offset);
|
|
|
|
// Create the direct offset value
|
|
|
|
std::string OffsetName = "__objc_ivar_offset_value_" + ClassName +"." +
|
|
|
|
IVD->getNameAsString();
|
|
|
|
llvm::GlobalVariable *OffsetVar = TheModule.getGlobalVariable(OffsetName);
|
|
|
|
if (OffsetVar) {
|
|
|
|
OffsetVar->setInitializer(OffsetValue);
|
|
|
|
// If this is the real definition, change its linkage type so that
|
|
|
|
// different modules will use this one, rather than their private
|
|
|
|
// copy.
|
|
|
|
OffsetVar->setLinkage(llvm::GlobalValue::ExternalLinkage);
|
|
|
|
} else
|
|
|
|
OffsetVar = new llvm::GlobalVariable(TheModule, IntTy,
|
2009-09-11 05:48:21 +08:00
|
|
|
false, llvm::GlobalValue::ExternalLinkage,
|
2011-07-07 20:34:51 +08:00
|
|
|
OffsetValue,
|
2009-09-11 05:48:21 +08:00
|
|
|
"__objc_ivar_offset_value_" + ClassName +"." +
|
2011-07-07 20:34:51 +08:00
|
|
|
IVD->getNameAsString());
|
|
|
|
IvarOffsets.push_back(OffsetValue);
|
|
|
|
IvarOffsetValues.push_back(OffsetVar);
|
2011-10-04 23:35:30 +08:00
|
|
|
Qualifiers::ObjCLifetime lt = IVD->getType().getQualifiers().getObjCLifetime();
|
|
|
|
switch (lt) {
|
|
|
|
case Qualifiers::OCL_Strong:
|
|
|
|
StrongIvars.push_back(true);
|
|
|
|
WeakIvars.push_back(false);
|
|
|
|
break;
|
|
|
|
case Qualifiers::OCL_Weak:
|
|
|
|
StrongIvars.push_back(false);
|
|
|
|
WeakIvars.push_back(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
StrongIvars.push_back(false);
|
|
|
|
WeakIvars.push_back(false);
|
|
|
|
}
|
2008-08-16 06:20:32 +08:00
|
|
|
}
|
2011-10-04 23:35:30 +08:00
|
|
|
llvm::Constant *StrongIvarBitmap = MakeBitField(StrongIvars);
|
|
|
|
llvm::Constant *WeakIvarBitmap = MakeBitField(WeakIvars);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
llvm::GlobalVariable *IvarOffsetArray =
|
|
|
|
MakeGlobalArray(PtrToIntTy, IvarOffsetValues, ".ivar.offsets");
|
|
|
|
|
2008-08-16 06:20:32 +08:00
|
|
|
|
|
|
|
// Collect information about instance methods
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Selector, 16> InstanceMethodSels;
|
|
|
|
SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
|
2009-09-09 23:08:12 +08:00
|
|
|
for (ObjCImplementationDecl::instmeth_iterator
|
2009-06-30 10:36:12 +08:00
|
|
|
iter = OID->instmeth_begin(), endIter = OID->instmeth_end();
|
2009-04-23 09:02:12 +08:00
|
|
|
iter != endIter ; iter++) {
|
2008-08-16 06:20:32 +08:00
|
|
|
InstanceMethodSels.push_back((*iter)->getSelector());
|
|
|
|
std::string TypeStr;
|
|
|
|
Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
|
2009-09-01 00:41:57 +08:00
|
|
|
InstanceMethodTypes.push_back(MakeConstantString(TypeStr));
|
2008-08-16 06:20:32 +08:00
|
|
|
}
|
2009-09-11 05:48:21 +08:00
|
|
|
|
|
|
|
llvm::Constant *Properties = GeneratePropertyList(OID, InstanceMethodSels,
|
|
|
|
InstanceMethodTypes);
|
|
|
|
|
2008-08-16 06:20:32 +08:00
|
|
|
|
|
|
|
// Collect information about class methods
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Selector, 16> ClassMethodSels;
|
|
|
|
SmallVector<llvm::Constant*, 16> ClassMethodTypes;
|
2009-04-23 09:02:12 +08:00
|
|
|
for (ObjCImplementationDecl::classmeth_iterator
|
2009-06-30 10:36:12 +08:00
|
|
|
iter = OID->classmeth_begin(), endIter = OID->classmeth_end();
|
2009-04-23 09:02:12 +08:00
|
|
|
iter != endIter ; iter++) {
|
2008-08-16 06:20:32 +08:00
|
|
|
ClassMethodSels.push_back((*iter)->getSelector());
|
|
|
|
std::string TypeStr;
|
|
|
|
Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
|
2009-09-01 00:41:57 +08:00
|
|
|
ClassMethodTypes.push_back(MakeConstantString(TypeStr));
|
2008-08-16 06:20:32 +08:00
|
|
|
}
|
|
|
|
// Collect the names of referenced protocols
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<std::string, 16> Protocols;
|
2008-08-16 06:20:32 +08:00
|
|
|
const ObjCList<ObjCProtocolDecl> &Protos =ClassDecl->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protos.begin(),
|
|
|
|
E = Protos.end(); I != E; ++I)
|
2008-11-24 13:29:24 +08:00
|
|
|
Protocols.push_back((*I)->getNameAsString());
|
2008-08-16 06:20:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
// Get the superclass pointer.
|
|
|
|
llvm::Constant *SuperClass;
|
2008-11-24 11:54:41 +08:00
|
|
|
if (!SuperClassName.empty()) {
|
2008-06-01 22:13:53 +08:00
|
|
|
SuperClass = MakeConstantString(SuperClassName, ".super_class_name");
|
|
|
|
} else {
|
2009-07-31 07:11:26 +08:00
|
|
|
SuperClass = llvm::ConstantPointerNull::get(PtrToInt8Ty);
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
|
|
|
// Empty vector used to construct empty method lists
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<llvm::Constant*, 1> empty;
|
2008-06-01 22:13:53 +08:00
|
|
|
// Generate the method and instance variable lists
|
|
|
|
llvm::Constant *MethodList = GenerateMethodList(ClassName, "",
|
2008-06-26 13:08:00 +08:00
|
|
|
InstanceMethodSels, InstanceMethodTypes, false);
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *ClassMethodList = GenerateMethodList(ClassName, "",
|
2008-06-26 13:08:00 +08:00
|
|
|
ClassMethodSels, ClassMethodTypes, true);
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *IvarList = GenerateIvarList(IvarNames, IvarTypes,
|
|
|
|
IvarOffsets);
|
2009-09-09 23:08:12 +08:00
|
|
|
// Irrespective of whether we are compiling for a fragile or non-fragile ABI,
|
2009-09-01 00:41:57 +08:00
|
|
|
// we emit a symbol containing the offset for each ivar in the class. This
|
|
|
|
// allows code compiled for the non-Fragile ABI to inherit from code compiled
|
|
|
|
// for the legacy ABI, without causing problems. The converse is also
|
|
|
|
// possible, but causes all ivar accesses to be fragile.
|
2010-11-04 00:12:44 +08:00
|
|
|
|
2009-09-01 00:41:57 +08:00
|
|
|
// Offset pointer for getting at the correct field in the ivar list when
|
|
|
|
// setting up the alias. These are: The base address for the global, the
|
|
|
|
// ivar array (second field), the ivar in this list (set for each ivar), and
|
|
|
|
// the offset (third field in ivar structure)
|
2011-10-04 23:35:30 +08:00
|
|
|
llvm::Type *IndexTy = Int32Ty;
|
2009-09-01 00:41:57 +08:00
|
|
|
llvm::Constant *offsetPointerIndexes[] = {Zeros[0],
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::ConstantInt::get(IndexTy, 1), 0,
|
2009-09-01 00:41:57 +08:00
|
|
|
llvm::ConstantInt::get(IndexTy, 2) };
|
|
|
|
|
2011-07-22 10:08:32 +08:00
|
|
|
unsigned ivarIndex = 0;
|
|
|
|
for (const ObjCIvarDecl *IVD = ClassDecl->all_declared_ivar_begin(); IVD;
|
|
|
|
IVD = IVD->getNextIvar()) {
|
2009-09-01 00:41:57 +08:00
|
|
|
const std::string Name = "__objc_ivar_offset_" + ClassName + '.'
|
2010-11-04 00:12:44 +08:00
|
|
|
+ IVD->getNameAsString();
|
2011-07-22 10:08:32 +08:00
|
|
|
offsetPointerIndexes[2] = llvm::ConstantInt::get(IndexTy, ivarIndex);
|
2009-09-01 00:41:57 +08:00
|
|
|
// Get the correct ivar field
|
|
|
|
llvm::Constant *offsetValue = llvm::ConstantExpr::getGetElementPtr(
|
2011-07-21 22:31:17 +08:00
|
|
|
IvarList, offsetPointerIndexes);
|
2010-11-04 00:12:44 +08:00
|
|
|
// Get the existing variable, if one exists.
|
2009-09-01 00:41:57 +08:00
|
|
|
llvm::GlobalVariable *offset = TheModule.getNamedGlobal(Name);
|
|
|
|
if (offset) {
|
|
|
|
offset->setInitializer(offsetValue);
|
|
|
|
// If this is the real definition, change its linkage type so that
|
|
|
|
// different modules will use this one, rather than their private
|
|
|
|
// copy.
|
|
|
|
offset->setLinkage(llvm::GlobalValue::ExternalLinkage);
|
|
|
|
} else {
|
|
|
|
// Add a new alias if there isn't one already.
|
|
|
|
offset = new llvm::GlobalVariable(TheModule, offsetValue->getType(),
|
|
|
|
false, llvm::GlobalValue::ExternalLinkage, offsetValue, Name);
|
|
|
|
}
|
2011-07-22 10:08:32 +08:00
|
|
|
++ivarIndex;
|
2009-09-01 00:41:57 +08:00
|
|
|
}
|
2011-10-25 18:12:21 +08:00
|
|
|
llvm::Constant *ZeroPtr = llvm::ConstantInt::get(IntPtrTy, 0);
|
2008-06-01 22:13:53 +08:00
|
|
|
//Generate metaclass for class methods
|
|
|
|
llvm::Constant *MetaClassStruct = GenerateClassStructure(NULLPtr,
|
2009-11-17 03:05:54 +08:00
|
|
|
NULLPtr, 0x12L, ClassName.c_str(), 0, Zeros[0], GenerateIvarList(
|
2011-10-04 23:35:30 +08:00
|
|
|
empty, empty, empty), ClassMethodList, NULLPtr,
|
2011-10-25 18:12:21 +08:00
|
|
|
NULLPtr, NULLPtr, ZeroPtr, ZeroPtr, true);
|
2009-05-04 23:31:17 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
// Generate the class structure
|
2008-11-24 11:54:41 +08:00
|
|
|
llvm::Constant *ClassStruct =
|
2009-09-11 05:48:21 +08:00
|
|
|
GenerateClassStructure(MetaClassStruct, SuperClass, 0x11L,
|
2008-11-24 11:54:41 +08:00
|
|
|
ClassName.c_str(), 0,
|
2009-07-25 07:12:58 +08:00
|
|
|
llvm::ConstantInt::get(LongTy, instanceSize), IvarList,
|
2009-09-11 05:48:21 +08:00
|
|
|
MethodList, GenerateProtocolList(Protocols), IvarOffsetArray,
|
2011-10-04 23:35:30 +08:00
|
|
|
Properties, StrongIvarBitmap, WeakIvarBitmap);
|
2009-05-04 23:31:17 +08:00
|
|
|
|
|
|
|
// Resolve the class aliases, if they exist.
|
|
|
|
if (ClassPtrAlias) {
|
2010-11-09 19:21:43 +08:00
|
|
|
ClassPtrAlias->replaceAllUsesWith(
|
2009-07-30 02:54:39 +08:00
|
|
|
llvm::ConstantExpr::getBitCast(ClassStruct, IdTy));
|
2010-11-09 19:21:43 +08:00
|
|
|
ClassPtrAlias->eraseFromParent();
|
2009-05-04 23:31:17 +08:00
|
|
|
ClassPtrAlias = 0;
|
|
|
|
}
|
|
|
|
if (MetaClassPtrAlias) {
|
2010-11-09 19:21:43 +08:00
|
|
|
MetaClassPtrAlias->replaceAllUsesWith(
|
2009-07-30 02:54:39 +08:00
|
|
|
llvm::ConstantExpr::getBitCast(MetaClassStruct, IdTy));
|
2010-11-09 19:21:43 +08:00
|
|
|
MetaClassPtrAlias->eraseFromParent();
|
2009-05-04 23:31:17 +08:00
|
|
|
MetaClassPtrAlias = 0;
|
|
|
|
}
|
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
// Add class structure to list to be added to the symtab later
|
2009-07-30 02:54:39 +08:00
|
|
|
ClassStruct = llvm::ConstantExpr::getBitCast(ClassStruct, PtrToInt8Ty);
|
2008-06-01 22:13:53 +08:00
|
|
|
Classes.push_back(ClassStruct);
|
|
|
|
}
|
|
|
|
|
2009-06-24 05:47:46 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Function *CGObjCGNU::ModuleInitFunction() {
|
2008-06-01 22:13:53 +08:00
|
|
|
// Only emit an ObjC load function if no Objective-C stuff has been called
|
|
|
|
if (Classes.empty() && Categories.empty() && ConstantStrings.empty() &&
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
ExistingProtocols.empty() && SelectorTable.empty())
|
2008-06-01 22:13:53 +08:00
|
|
|
return NULL;
|
2008-06-02 00:00:02 +08:00
|
|
|
|
2009-09-11 05:48:21 +08:00
|
|
|
// Add all referenced protocols to a category.
|
|
|
|
GenerateProtocolHolderCategory();
|
|
|
|
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::StructType *SelStructTy = dyn_cast<llvm::StructType>(
|
2009-01-27 13:06:01 +08:00
|
|
|
SelectorTy->getElementType());
|
2011-07-11 17:56:20 +08:00
|
|
|
llvm::Type *SelStructPtrTy = SelectorTy;
|
2009-01-27 13:06:01 +08:00
|
|
|
if (SelStructTy == 0) {
|
2011-06-19 06:49:11 +08:00
|
|
|
SelStructTy = llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, NULL);
|
2009-07-30 06:16:19 +08:00
|
|
|
SelStructPtrTy = llvm::PointerType::getUnqual(SelStructTy);
|
2009-01-27 13:06:01 +08:00
|
|
|
}
|
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
std::vector<llvm::Constant*> Elements;
|
2009-04-26 07:19:45 +08:00
|
|
|
llvm::Constant *Statics = NULLPtr;
|
2008-06-01 22:13:53 +08:00
|
|
|
// Generate statics list:
|
2009-04-26 07:19:45 +08:00
|
|
|
if (ConstantStrings.size()) {
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::ArrayType *StaticsArrayTy = llvm::ArrayType::get(PtrToInt8Ty,
|
2009-04-26 07:19:45 +08:00
|
|
|
ConstantStrings.size() + 1);
|
|
|
|
ConstantStrings.push_back(NULLPtr);
|
2009-09-01 00:41:57 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef StringClass = CGM.getLangOptions().ObjCConstantStringClass;
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
|
2009-11-29 10:38:47 +08:00
|
|
|
if (StringClass.empty()) StringClass = "NXConstantString";
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
|
2009-09-01 00:41:57 +08:00
|
|
|
Elements.push_back(MakeConstantString(StringClass,
|
|
|
|
".objc_static_class_name"));
|
2009-07-29 02:33:04 +08:00
|
|
|
Elements.push_back(llvm::ConstantArray::get(StaticsArrayTy,
|
2009-04-26 07:19:45 +08:00
|
|
|
ConstantStrings));
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::StructType *StaticsListTy =
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType::get(PtrToInt8Ty, StaticsArrayTy, NULL);
|
2009-07-15 07:10:40 +08:00
|
|
|
llvm::Type *StaticsListPtrTy =
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::PointerType::getUnqual(StaticsListTy);
|
2009-04-26 07:19:45 +08:00
|
|
|
Statics = MakeGlobal(StaticsListTy, Elements, ".objc_statics");
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::ArrayType *StaticsListArrayTy =
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::ArrayType::get(StaticsListPtrTy, 2);
|
2009-04-26 07:19:45 +08:00
|
|
|
Elements.clear();
|
|
|
|
Elements.push_back(Statics);
|
2009-08-01 04:28:54 +08:00
|
|
|
Elements.push_back(llvm::Constant::getNullValue(StaticsListPtrTy));
|
2009-04-26 07:19:45 +08:00
|
|
|
Statics = MakeGlobal(StaticsListArrayTy, Elements, ".objc_statics_ptr");
|
2009-07-30 02:54:39 +08:00
|
|
|
Statics = llvm::ConstantExpr::getBitCast(Statics, PtrTy);
|
2009-04-26 07:19:45 +08:00
|
|
|
}
|
2008-06-01 22:13:53 +08:00
|
|
|
// Array of classes, categories, and constant objects
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::ArrayType *ClassListTy = llvm::ArrayType::get(PtrToInt8Ty,
|
2008-06-01 22:13:53 +08:00
|
|
|
Classes.size() + Categories.size() + 2);
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType *SymTabTy = llvm::StructType::get(LongTy, SelStructPtrTy,
|
2009-08-14 05:57:51 +08:00
|
|
|
llvm::Type::getInt16Ty(VMContext),
|
|
|
|
llvm::Type::getInt16Ty(VMContext),
|
2008-06-26 12:10:42 +08:00
|
|
|
ClassListTy, NULL);
|
2008-06-01 22:13:53 +08:00
|
|
|
|
|
|
|
Elements.clear();
|
|
|
|
// Pointer to an array of selectors used in this module.
|
|
|
|
std::vector<llvm::Constant*> Selectors;
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
std::vector<llvm::GlobalAlias*> SelectorAliases;
|
|
|
|
for (SelectorMap::iterator iter = SelectorTable.begin(),
|
|
|
|
iterEnd = SelectorTable.end(); iter != iterEnd ; ++iter) {
|
|
|
|
|
|
|
|
std::string SelNameStr = iter->first.getAsString();
|
|
|
|
llvm::Constant *SelName = ExportUniqueString(SelNameStr, ".objc_sel_name");
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVectorImpl<TypedSelector> &Types = iter->second;
|
|
|
|
for (SmallVectorImpl<TypedSelector>::iterator i = Types.begin(),
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
e = Types.end() ; i!=e ; i++) {
|
|
|
|
|
|
|
|
llvm::Constant *SelectorTypeEncoding = NULLPtr;
|
|
|
|
if (!i->first.empty())
|
|
|
|
SelectorTypeEncoding = MakeConstantString(i->first, ".objc_sel_types");
|
|
|
|
|
|
|
|
Elements.push_back(SelName);
|
|
|
|
Elements.push_back(SelectorTypeEncoding);
|
|
|
|
Selectors.push_back(llvm::ConstantStruct::get(SelStructTy, Elements));
|
|
|
|
Elements.clear();
|
|
|
|
|
|
|
|
// Store the selector alias for later replacement
|
|
|
|
SelectorAliases.push_back(i->second);
|
|
|
|
}
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
unsigned SelectorCount = Selectors.size();
|
|
|
|
// NULL-terminate the selector list. This should not actually be required,
|
|
|
|
// because the selector list has a length field. Unfortunately, the GCC
|
|
|
|
// runtime decides to ignore the length field and expects a NULL terminator,
|
|
|
|
// and GCC cooperates with this by always setting the length to 0.
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.push_back(NULLPtr);
|
|
|
|
Elements.push_back(NULLPtr);
|
2009-07-28 06:29:56 +08:00
|
|
|
Selectors.push_back(llvm::ConstantStruct::get(SelStructTy, Elements));
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.clear();
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
// Number of static selectors
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
Elements.push_back(llvm::ConstantInt::get(LongTy, SelectorCount));
|
|
|
|
llvm::Constant *SelectorList = MakeGlobalArray(SelStructTy, Selectors,
|
2008-06-01 22:13:53 +08:00
|
|
|
".objc_selector_list");
|
2009-09-09 23:08:12 +08:00
|
|
|
Elements.push_back(llvm::ConstantExpr::getBitCast(SelectorList,
|
2009-01-27 13:06:01 +08:00
|
|
|
SelStructPtrTy));
|
2008-06-01 22:13:53 +08:00
|
|
|
|
|
|
|
// Now that all of the static selectors exist, create pointers to them.
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
for (unsigned int i=0 ; i<SelectorCount ; i++) {
|
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *Idxs[] = {Zeros[0],
|
2011-10-04 23:35:30 +08:00
|
|
|
llvm::ConstantInt::get(Int32Ty, i), Zeros[0]};
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
// FIXME: We're generating redundant loads and stores here!
|
2011-03-24 06:52:06 +08:00
|
|
|
llvm::Constant *SelPtr = llvm::ConstantExpr::getGetElementPtr(SelectorList,
|
2011-07-21 22:31:17 +08:00
|
|
|
makeArrayRef(Idxs, 2));
|
2009-01-27 13:06:01 +08:00
|
|
|
// If selectors are defined as an opaque type, cast the pointer to this
|
|
|
|
// type.
|
2011-03-24 06:52:06 +08:00
|
|
|
SelPtr = llvm::ConstantExpr::getBitCast(SelPtr, SelectorTy);
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
SelectorAliases[i]->replaceAllUsesWith(SelPtr);
|
|
|
|
SelectorAliases[i]->eraseFromParent();
|
2008-06-01 22:13:53 +08:00
|
|
|
}
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
// Number of classes defined.
|
2009-09-09 23:08:12 +08:00
|
|
|
Elements.push_back(llvm::ConstantInt::get(llvm::Type::getInt16Ty(VMContext),
|
2008-06-01 22:13:53 +08:00
|
|
|
Classes.size()));
|
|
|
|
// Number of categories defined
|
2009-09-09 23:08:12 +08:00
|
|
|
Elements.push_back(llvm::ConstantInt::get(llvm::Type::getInt16Ty(VMContext),
|
2008-06-01 22:13:53 +08:00
|
|
|
Categories.size()));
|
|
|
|
// Create an array of classes, then categories, then static object instances
|
|
|
|
Classes.insert(Classes.end(), Categories.begin(), Categories.end());
|
|
|
|
// NULL-terminated list of static object instances (mainly constant strings)
|
|
|
|
Classes.push_back(Statics);
|
|
|
|
Classes.push_back(NULLPtr);
|
2009-07-29 02:33:04 +08:00
|
|
|
llvm::Constant *ClassList = llvm::ConstantArray::get(ClassListTy, Classes);
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.push_back(ClassList);
|
2009-09-09 23:08:12 +08:00
|
|
|
// Construct the symbol table
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Constant *SymTab= MakeGlobal(SymTabTy, Elements);
|
|
|
|
|
|
|
|
// The symbol table is contained in a module which has some version-checking
|
|
|
|
// constants
|
2011-06-19 06:49:11 +08:00
|
|
|
llvm::StructType * ModuleTy = llvm::StructType::get(LongTy, LongTy,
|
2011-05-23 06:37:08 +08:00
|
|
|
PtrToInt8Ty, llvm::PointerType::getUnqual(SymTabTy),
|
2011-07-07 19:22:31 +08:00
|
|
|
(RuntimeVersion >= 10) ? IntTy : NULL, NULL);
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.clear();
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
// Runtime version, used for ABI compatibility checking.
|
|
|
|
Elements.push_back(llvm::ConstantInt::get(LongTy, RuntimeVersion));
|
2009-04-02 03:49:42 +08:00
|
|
|
// sizeof(ModuleTy)
|
2010-02-10 03:31:24 +08:00
|
|
|
llvm::TargetData td(&TheModule);
|
2011-04-23 01:59:22 +08:00
|
|
|
Elements.push_back(
|
|
|
|
llvm::ConstantInt::get(LongTy,
|
|
|
|
td.getTypeSizeInBits(ModuleTy) /
|
|
|
|
CGM.getContext().getCharWidth()));
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
|
|
|
|
// The path to the source file where this module was declared
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
const FileEntry *mainFile = SM.getFileEntryForID(SM.getMainFileID());
|
|
|
|
std::string path =
|
|
|
|
std::string(mainFile->getDir()->getName()) + '/' + mainFile->getName();
|
|
|
|
Elements.push_back(MakeConstantString(path, ".objc_source_file_name"));
|
2008-06-01 22:13:53 +08:00
|
|
|
Elements.push_back(SymTab);
|
2011-05-23 06:37:08 +08:00
|
|
|
|
2011-07-07 19:22:31 +08:00
|
|
|
if (RuntimeVersion >= 10)
|
2011-09-14 01:21:33 +08:00
|
|
|
switch (CGM.getLangOptions().getGC()) {
|
2011-07-07 19:22:31 +08:00
|
|
|
case LangOptions::GCOnly:
|
2011-05-23 06:37:08 +08:00
|
|
|
Elements.push_back(llvm::ConstantInt::get(IntTy, 2));
|
|
|
|
break;
|
2011-07-07 19:22:31 +08:00
|
|
|
case LangOptions::NonGC:
|
|
|
|
if (CGM.getLangOptions().ObjCAutoRefCount)
|
|
|
|
Elements.push_back(llvm::ConstantInt::get(IntTy, 1));
|
|
|
|
else
|
|
|
|
Elements.push_back(llvm::ConstantInt::get(IntTy, 0));
|
|
|
|
break;
|
|
|
|
case LangOptions::HybridGC:
|
|
|
|
Elements.push_back(llvm::ConstantInt::get(IntTy, 1));
|
|
|
|
break;
|
|
|
|
}
|
2011-05-23 06:37:08 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::Value *Module = MakeGlobal(ModuleTy, Elements);
|
|
|
|
|
|
|
|
// Create the load function calling the runtime entry point with the module
|
|
|
|
// structure
|
|
|
|
llvm::Function * LoadFunction = llvm::Function::Create(
|
2009-08-14 05:57:51 +08:00
|
|
|
llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), false),
|
2008-06-01 22:13:53 +08:00
|
|
|
llvm::GlobalValue::InternalLinkage, ".objc_load_function",
|
|
|
|
&TheModule);
|
2009-08-14 05:57:51 +08:00
|
|
|
llvm::BasicBlock *EntryBB =
|
|
|
|
llvm::BasicBlock::Create(VMContext, "entry", LoadFunction);
|
2009-07-15 07:10:40 +08:00
|
|
|
CGBuilderTy Builder(VMContext);
|
2008-06-01 22:13:53 +08:00
|
|
|
Builder.SetInsertPoint(EntryBB);
|
2009-03-31 02:02:14 +08:00
|
|
|
|
2011-05-28 22:26:31 +08:00
|
|
|
llvm::FunctionType *FT =
|
2011-07-29 21:56:53 +08:00
|
|
|
llvm::FunctionType::get(Builder.getVoidTy(),
|
|
|
|
llvm::PointerType::getUnqual(ModuleTy), true);
|
2011-05-28 22:26:31 +08:00
|
|
|
llvm::Value *Register = CGM.CreateRuntimeFunction(FT, "__objc_exec_class");
|
2008-06-01 22:13:53 +08:00
|
|
|
Builder.CreateCall(Register, Module);
|
|
|
|
Builder.CreateRetVoid();
|
2009-05-21 02:41:51 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
return LoadFunction;
|
|
|
|
}
|
2008-08-16 06:20:32 +08:00
|
|
|
|
2009-01-11 05:06:09 +08:00
|
|
|
llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD,
|
2009-09-09 23:08:12 +08:00
|
|
|
const ObjCContainerDecl *CD) {
|
|
|
|
const ObjCCategoryImplDecl *OCD =
|
2009-01-09 03:41:02 +08:00
|
|
|
dyn_cast<ObjCCategoryImplDecl>(OMD->getDeclContext());
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef CategoryName = OCD ? OCD->getName() : "";
|
|
|
|
StringRef ClassName = CD->getName();
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
Selector MethodName = OMD->getSelector();
|
2009-01-10 01:18:27 +08:00
|
|
|
bool isClassMethod = !OMD->isInstanceMethod();
|
2008-03-31 07:03:07 +08:00
|
|
|
|
2009-02-03 07:23:47 +08:00
|
|
|
CodeGenTypes &Types = CGM.getTypes();
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::FunctionType *MethodTy =
|
2009-02-03 07:23:47 +08:00
|
|
|
Types.GetFunctionType(Types.getFunctionInfo(OMD), OMD->isVariadic());
|
2008-06-01 22:13:53 +08:00
|
|
|
std::string FunctionName = SymbolNameForMethod(ClassName, CategoryName,
|
|
|
|
MethodName, isClassMethod);
|
|
|
|
|
2009-09-17 12:01:22 +08:00
|
|
|
llvm::Function *Method
|
2009-09-09 23:08:12 +08:00
|
|
|
= llvm::Function::Create(MethodTy,
|
|
|
|
llvm::GlobalValue::InternalLinkage,
|
|
|
|
FunctionName,
|
|
|
|
&TheModule);
|
2008-03-31 07:03:07 +08:00
|
|
|
return Method;
|
|
|
|
}
|
|
|
|
|
2011-05-24 06:33:28 +08:00
|
|
|
llvm::Constant *CGObjCGNU::GetPropertyGetFunction() {
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
return GetPropertyFn;
|
2008-09-24 11:38:44 +08:00
|
|
|
}
|
|
|
|
|
2011-05-24 06:33:28 +08:00
|
|
|
llvm::Constant *CGObjCGNU::GetPropertySetFunction() {
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
return SetPropertyFn;
|
2008-09-24 11:38:44 +08:00
|
|
|
}
|
|
|
|
|
2011-05-24 06:33:28 +08:00
|
|
|
llvm::Constant *CGObjCGNU::GetGetStructFunction() {
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
return GetStructPropertyFn;
|
2010-12-27 06:13:16 +08:00
|
|
|
}
|
2011-05-24 06:33:28 +08:00
|
|
|
llvm::Constant *CGObjCGNU::GetSetStructFunction() {
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
return SetStructPropertyFn;
|
2010-04-13 02:18:10 +08:00
|
|
|
}
|
|
|
|
|
2009-07-24 15:40:24 +08:00
|
|
|
llvm::Constant *CGObjCGNU::EnumerationMutationFunction() {
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
return EnumerationMutationFn;
|
2008-08-31 12:05:03 +08:00
|
|
|
}
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
void CGObjCGNU::EmitSynchronizedStmt(CodeGenFunction &CGF,
|
2010-07-06 09:34:17 +08:00
|
|
|
const ObjCAtSynchronizedStmt &S) {
|
2011-03-25 19:57:33 +08:00
|
|
|
EmitAtSynchronizedStmt(CGF, S, SyncEnterFn, SyncExitFn);
|
2010-07-06 09:34:17 +08:00
|
|
|
}
|
2009-05-08 08:11:50 +08:00
|
|
|
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
void CGObjCGNU::EmitTryStmt(CodeGenFunction &CGF,
|
2010-07-06 09:34:17 +08:00
|
|
|
const ObjCAtTryStmt &S) {
|
|
|
|
// Unlike the Apple non-fragile runtimes, which also uses
|
|
|
|
// unwind-based zero cost exceptions, the GNU Objective C runtime's
|
|
|
|
// EH support isn't a veneer over C++ EH. Instead, exception
|
|
|
|
// objects are created by __objc_exception_throw and destroyed by
|
|
|
|
// the personality function; this avoids the need for bracketing
|
|
|
|
// catch handlers with calls to __blah_begin_catch/__blah_end_catch
|
|
|
|
// (or even _Unwind_DeleteException), but probably doesn't
|
|
|
|
// interoperate very well with foreign exceptions.
|
2011-03-25 19:57:33 +08:00
|
|
|
//
|
2011-03-21 05:35:39 +08:00
|
|
|
// In Objective-C++ mode, we actually emit something equivalent to the C++
|
2011-03-25 19:57:33 +08:00
|
|
|
// exception handler.
|
|
|
|
EmitTryCatchStmt(CGF, S, EnterCatchFn, ExitCatchFn, ExceptionReThrowFn);
|
|
|
|
return ;
|
2008-09-09 18:04:29 +08:00
|
|
|
}
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
void CGObjCGNU::EmitThrowStmt(CodeGenFunction &CGF,
|
2008-09-24 11:38:44 +08:00
|
|
|
const ObjCAtThrowStmt &S) {
|
2009-05-08 08:11:50 +08:00
|
|
|
llvm::Value *ExceptionAsObject;
|
|
|
|
|
|
|
|
if (const Expr *ThrowExpr = S.getThrowExpr()) {
|
2011-10-01 18:32:24 +08:00
|
|
|
llvm::Value *Exception = CGF.EmitObjCThrowOperand(ThrowExpr);
|
2009-05-18 00:49:27 +08:00
|
|
|
ExceptionAsObject = Exception;
|
2009-05-08 08:11:50 +08:00
|
|
|
} else {
|
2009-09-09 23:08:12 +08:00
|
|
|
assert((!CGF.ObjCEHValueStack.empty() && CGF.ObjCEHValueStack.back()) &&
|
2009-05-08 08:11:50 +08:00
|
|
|
"Unexpected rethrow outside @catch block.");
|
|
|
|
ExceptionAsObject = CGF.ObjCEHValueStack.back();
|
|
|
|
}
|
2011-09-28 05:06:10 +08:00
|
|
|
ExceptionAsObject = CGF.Builder.CreateBitCast(ExceptionAsObject, IdTy);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-08 08:11:50 +08:00
|
|
|
// Note: This may have to be an invoke, if we want to support constructs like:
|
|
|
|
// @try {
|
|
|
|
// @throw(obj);
|
|
|
|
// }
|
|
|
|
// @catch(id) ...
|
|
|
|
//
|
|
|
|
// This is effectively turning @throw into an incredibly-expensive goto, but
|
|
|
|
// it may happen as a result of inlining followed by missed optimizations, or
|
|
|
|
// as a result of stupidity.
|
|
|
|
llvm::BasicBlock *UnwindBB = CGF.getInvokeDest();
|
|
|
|
if (!UnwindBB) {
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
CGF.Builder.CreateCall(ExceptionThrowFn, ExceptionAsObject);
|
2009-05-08 08:11:50 +08:00
|
|
|
CGF.Builder.CreateUnreachable();
|
|
|
|
} else {
|
2011-07-15 16:37:34 +08:00
|
|
|
CGF.Builder.CreateInvoke(ExceptionThrowFn, UnwindBB, UnwindBB,
|
|
|
|
ExceptionAsObject);
|
2009-05-08 08:11:50 +08:00
|
|
|
}
|
|
|
|
// Clear the insertion point to indicate we are in unreachable code.
|
|
|
|
CGF.Builder.ClearInsertionPoint();
|
2008-09-09 18:04:29 +08:00
|
|
|
}
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
llvm::Value * CGObjCGNU::EmitObjCWeakRead(CodeGenFunction &CGF,
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Value *AddrWeakObj) {
|
2010-02-03 23:59:02 +08:00
|
|
|
CGBuilderTy B = CGF.Builder;
|
2011-05-30 20:00:26 +08:00
|
|
|
AddrWeakObj = EnforceType(B, AddrWeakObj, PtrToIdTy);
|
2010-02-03 23:59:02 +08:00
|
|
|
return B.CreateCall(WeakReadFn, AddrWeakObj);
|
2008-11-19 05:45:40 +08:00
|
|
|
}
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
void CGObjCGNU::EmitObjCWeakAssign(CodeGenFunction &CGF,
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Value *src, llvm::Value *dst) {
|
2010-02-03 23:59:02 +08:00
|
|
|
CGBuilderTy B = CGF.Builder;
|
|
|
|
src = EnforceType(B, src, IdTy);
|
|
|
|
dst = EnforceType(B, dst, PtrToIdTy);
|
|
|
|
B.CreateCall2(WeakAssignFn, src, dst);
|
2008-11-19 06:37:34 +08:00
|
|
|
}
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
void CGObjCGNU::EmitObjCGlobalAssign(CodeGenFunction &CGF,
|
2010-07-21 04:30:03 +08:00
|
|
|
llvm::Value *src, llvm::Value *dst,
|
|
|
|
bool threadlocal) {
|
2010-02-03 23:59:02 +08:00
|
|
|
CGBuilderTy B = CGF.Builder;
|
|
|
|
src = EnforceType(B, src, IdTy);
|
|
|
|
dst = EnforceType(B, dst, PtrToIdTy);
|
2010-07-21 04:30:03 +08:00
|
|
|
if (!threadlocal)
|
|
|
|
B.CreateCall2(GlobalAssignFn, src, dst);
|
|
|
|
else
|
|
|
|
// FIXME. Add threadloca assign API
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("EmitObjCGlobalAssign - Threal Local API NYI");
|
2008-11-19 08:59:10 +08:00
|
|
|
}
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
void CGObjCGNU::EmitObjCIvarAssign(CodeGenFunction &CGF,
|
2009-09-25 06:25:38 +08:00
|
|
|
llvm::Value *src, llvm::Value *dst,
|
|
|
|
llvm::Value *ivarOffset) {
|
2010-02-03 23:59:02 +08:00
|
|
|
CGBuilderTy B = CGF.Builder;
|
|
|
|
src = EnforceType(B, src, IdTy);
|
2011-05-26 04:33:17 +08:00
|
|
|
dst = EnforceType(B, dst, IdTy);
|
2010-02-03 23:59:02 +08:00
|
|
|
B.CreateCall3(IvarAssignFn, src, dst, ivarOffset);
|
2008-11-21 03:23:36 +08:00
|
|
|
}
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
void CGObjCGNU::EmitObjCStrongCastAssign(CodeGenFunction &CGF,
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Value *src, llvm::Value *dst) {
|
2010-02-03 23:59:02 +08:00
|
|
|
CGBuilderTy B = CGF.Builder;
|
|
|
|
src = EnforceType(B, src, IdTy);
|
|
|
|
dst = EnforceType(B, dst, PtrToIdTy);
|
|
|
|
B.CreateCall2(StrongCastAssignFn, src, dst);
|
2008-11-19 08:59:10 +08:00
|
|
|
}
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
void CGObjCGNU::EmitGCMemmoveCollectable(CodeGenFunction &CGF,
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Value *DestPtr,
|
2009-07-08 09:18:33 +08:00
|
|
|
llvm::Value *SrcPtr,
|
2010-06-16 06:44:06 +08:00
|
|
|
llvm::Value *Size) {
|
2010-02-03 23:59:02 +08:00
|
|
|
CGBuilderTy B = CGF.Builder;
|
2011-05-28 22:23:43 +08:00
|
|
|
DestPtr = EnforceType(B, DestPtr, PtrTy);
|
|
|
|
SrcPtr = EnforceType(B, SrcPtr, PtrTy);
|
2010-02-03 23:59:02 +08:00
|
|
|
|
2010-06-16 06:44:06 +08:00
|
|
|
B.CreateCall3(MemMoveFn, DestPtr, SrcPtr, Size);
|
2009-07-08 09:18:33 +08:00
|
|
|
}
|
|
|
|
|
2009-05-21 02:41:51 +08:00
|
|
|
llvm::GlobalVariable *CGObjCGNU::ObjCIvarOffsetVariable(
|
|
|
|
const ObjCInterfaceDecl *ID,
|
|
|
|
const ObjCIvarDecl *Ivar) {
|
|
|
|
const std::string Name = "__objc_ivar_offset_" + ID->getNameAsString()
|
|
|
|
+ '.' + Ivar->getNameAsString();
|
|
|
|
// Emit the variable and initialize it with what we think the correct value
|
|
|
|
// is. This allows code compiled with non-fragile ivars to work correctly
|
|
|
|
// when linked against code which isn't (most of the time).
|
2009-09-01 00:41:57 +08:00
|
|
|
llvm::GlobalVariable *IvarOffsetPointer = TheModule.getNamedGlobal(Name);
|
|
|
|
if (!IvarOffsetPointer) {
|
2010-11-04 00:12:44 +08:00
|
|
|
// This will cause a run-time crash if we accidentally use it. A value of
|
|
|
|
// 0 would seem more sensible, but will silently overwrite the isa pointer
|
|
|
|
// causing a great deal of confusion.
|
|
|
|
uint64_t Offset = -1;
|
|
|
|
// We can't call ComputeIvarBaseOffset() here if we have the
|
|
|
|
// implementation, because it will create an invalid ASTRecordLayout object
|
|
|
|
// that we are then stuck with forever, so we only initialize the ivar
|
|
|
|
// offset variable with a guess if we only have the interface. The
|
|
|
|
// initializer will be reset later anyway, when we are generating the class
|
|
|
|
// description.
|
|
|
|
if (!CGM.getContext().getObjCImplementation(
|
2010-04-20 00:39:44 +08:00
|
|
|
const_cast<ObjCInterfaceDecl *>(ID)))
|
2010-04-19 09:37:25 +08:00
|
|
|
Offset = ComputeIvarBaseOffset(CGM, ID, Ivar);
|
|
|
|
|
2011-10-08 16:54:36 +08:00
|
|
|
llvm::ConstantInt *OffsetGuess = llvm::ConstantInt::get(Int32Ty, Offset,
|
2011-09-21 10:46:06 +08:00
|
|
|
/*isSigned*/true);
|
2009-09-01 00:41:57 +08:00
|
|
|
// Don't emit the guess in non-PIC code because the linker will not be able
|
|
|
|
// to replace it with the real version for a library. In non-PIC code you
|
|
|
|
// must compile with the fragile ABI if you want to use ivars from a
|
2009-09-09 23:08:12 +08:00
|
|
|
// GCC-compiled class.
|
2009-09-01 00:41:57 +08:00
|
|
|
if (CGM.getLangOptions().PICLevel) {
|
|
|
|
llvm::GlobalVariable *IvarOffsetGV = new llvm::GlobalVariable(TheModule,
|
2011-10-04 23:35:30 +08:00
|
|
|
Int32Ty, false,
|
2009-09-01 00:41:57 +08:00
|
|
|
llvm::GlobalValue::PrivateLinkage, OffsetGuess, Name+".guess");
|
|
|
|
IvarOffsetPointer = new llvm::GlobalVariable(TheModule,
|
|
|
|
IvarOffsetGV->getType(), false, llvm::GlobalValue::LinkOnceAnyLinkage,
|
|
|
|
IvarOffsetGV, Name);
|
|
|
|
} else {
|
|
|
|
IvarOffsetPointer = new llvm::GlobalVariable(TheModule,
|
2009-10-13 18:07:13 +08:00
|
|
|
llvm::Type::getInt32PtrTy(VMContext), false,
|
|
|
|
llvm::GlobalValue::ExternalLinkage, 0, Name);
|
2009-09-01 00:41:57 +08:00
|
|
|
}
|
2009-05-21 02:41:51 +08:00
|
|
|
}
|
2009-09-01 00:41:57 +08:00
|
|
|
return IvarOffsetPointer;
|
2009-05-21 02:41:51 +08:00
|
|
|
}
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
LValue CGObjCGNU::EmitObjCValueForIvar(CodeGenFunction &CGF,
|
2009-02-04 03:03:09 +08:00
|
|
|
QualType ObjectTy,
|
|
|
|
llvm::Value *BaseValue,
|
|
|
|
const ObjCIvarDecl *Ivar,
|
|
|
|
unsigned CVRQualifiers) {
|
2010-05-15 19:32:37 +08:00
|
|
|
const ObjCInterfaceDecl *ID =
|
|
|
|
ObjectTy->getAs<ObjCObjectType>()->getInterface();
|
2009-04-22 15:32:20 +08:00
|
|
|
return EmitValueForIvarAtOffset(CGF, ID, BaseValue, Ivar, CVRQualifiers,
|
|
|
|
EmitIvarOffset(CGF, ID, Ivar));
|
2009-02-03 04:02:29 +08:00
|
|
|
}
|
2009-08-01 05:31:32 +08:00
|
|
|
|
2009-05-21 02:41:51 +08:00
|
|
|
static const ObjCInterfaceDecl *FindIvarInterface(ASTContext &Context,
|
|
|
|
const ObjCInterfaceDecl *OID,
|
|
|
|
const ObjCIvarDecl *OIVD) {
|
2011-07-22 10:08:32 +08:00
|
|
|
for (const ObjCIvarDecl *next = OID->all_declared_ivar_begin(); next;
|
|
|
|
next = next->getNextIvar()) {
|
|
|
|
if (OIVD == next)
|
2009-05-21 02:41:51 +08:00
|
|
|
return OID;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-21 02:41:51 +08:00
|
|
|
// Otherwise check in the super class.
|
|
|
|
if (const ObjCInterfaceDecl *Super = OID->getSuperClass())
|
|
|
|
return FindIvarInterface(Context, Super, OIVD);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-21 02:41:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-02-03 04:02:29 +08:00
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
llvm::Value *CGObjCGNU::EmitIvarOffset(CodeGenFunction &CGF,
|
2009-04-22 13:08:15 +08:00
|
|
|
const ObjCInterfaceDecl *Interface,
|
2009-02-11 03:02:04 +08:00
|
|
|
const ObjCIvarDecl *Ivar) {
|
2009-09-01 00:41:57 +08:00
|
|
|
if (CGM.getLangOptions().ObjCNonFragileABI) {
|
2009-05-21 02:41:51 +08:00
|
|
|
Interface = FindIvarInterface(CGM.getContext(), Interface, Ivar);
|
2011-07-07 20:34:51 +08:00
|
|
|
if (RuntimeVersion < 10)
|
|
|
|
return CGF.Builder.CreateZExtOrBitCast(
|
|
|
|
CGF.Builder.CreateLoad(CGF.Builder.CreateLoad(
|
|
|
|
ObjCIvarOffsetVariable(Interface, Ivar), false, "ivar")),
|
|
|
|
PtrDiffTy);
|
|
|
|
std::string name = "__objc_ivar_offset_value_" +
|
|
|
|
Interface->getNameAsString() +"." + Ivar->getNameAsString();
|
|
|
|
llvm::Value *Offset = TheModule.getGlobalVariable(name);
|
|
|
|
if (!Offset)
|
|
|
|
Offset = new llvm::GlobalVariable(TheModule, IntTy,
|
2011-08-02 01:36:53 +08:00
|
|
|
false, llvm::GlobalValue::LinkOnceAnyLinkage,
|
|
|
|
llvm::Constant::getNullValue(IntTy), name);
|
2011-07-07 20:34:51 +08:00
|
|
|
return CGF.Builder.CreateLoad(Offset);
|
2009-05-21 02:41:51 +08:00
|
|
|
}
|
2009-04-22 15:32:20 +08:00
|
|
|
uint64_t Offset = ComputeIvarBaseOffset(CGF.CGM, Interface, Ivar);
|
2011-09-21 10:46:06 +08:00
|
|
|
return llvm::ConstantInt::get(PtrDiffTy, Offset, /*isSigned*/true);
|
2009-02-11 03:02:04 +08:00
|
|
|
}
|
|
|
|
|
Initial work on refactoring GNU runtime code (long overdue - it's quite obvious
that I hadn't used C++ for several years before writing most of this code).
Still lots more to do. This set of changes includes:
- Remove the distinction between typed and untyped selectors. More accurately
reflect what the runtime does, by using typed selectors everywhere, with an
empty type field if the types are unknown. Now we just store a small list of
types for each selector (in theory, this should always be exactly one, but
this constraint was not enforced back in 1986 when it should have been).
- Add some consistency to how runtime functions are created. These are all
generated via the LazyRuntimeFunction class (which might be useful outside
CGObjCGNU - feel free to move it into a header if it is). This function
stores the types of a function, looks it up the first time it's used, and
caches the result. This means that we're now not wasting time constructing
the llvm::FunctionType every time some of the functions are looked up, but
also not inserting references to runtime functions into the module if they're
not actually used.
- Started separating out the fragile and non-fragile ABI behaviours into two
subclasses of CGObjCGNU: CGObjCGCC for the legacy GCC runtime ABI and
CGObjCGNUstep for the new GNUstep ABI. Not all of the differences in
behaviour are factored out yet, but they will be in future commits.
- Removed all of the CodeGen:: things: we've been using namespace CodeGen in
this file for ages, so having explicit namespace specifiers is just a bit
confusing.
- Added a few more comments.
- Used llvm::StringRef instead of std::string in a few places.
- Finally got around to storing the module path in the module structure. The
ABI says that the compiler should do this, although it's not used in the
runtime or exposed outside the runtime, so it's pretty useless.
Still to do:
- We currently have two code paths for generating try blocks, one for ObjC and
one for ObjC++. Not only are these substantially similar, they are also very
similar to the CGObjCMac version. These need factoring out into a single
parameterised implementation, either in CGObjCRuntime or CodeGenFunction.
The EmitObjCXXTryStmt() function was added so that the changes to fix a bug
in time for the 2.9 release would be self-contained and reduce the chances of
breaking anything else, but these should be done properly as soon as
possible.
- Split up some large functions (e.g. GenerateClass()) into smaller functions
for generating the various data structures.
- The method lookup code into the two subclasses, removing the conditionals in
the message send functions.
- Add doxygen comments on the remaining undocumented functions.
- We seem to be generating global pointer variables for selectors, then storing
a pointer to the selector, then generating a load of this pointer (and then a
load of the real selector later) every time a static selector is used. I can
only assume I was asleep or drunk when I did this - we should just be
referencing the selectors directly in the selector array.
llvm-svn: 128152
2011-03-24 00:36:54 +08:00
|
|
|
CGObjCRuntime *
|
|
|
|
clang::CodeGen::CreateGNUObjCRuntime(CodeGenModule &CGM) {
|
|
|
|
if (CGM.getLangOptions().ObjCNonFragileABI)
|
|
|
|
return new CGObjCGNUstep(CGM);
|
|
|
|
return new CGObjCGCC(CGM);
|
2008-03-01 16:50:34 +08:00
|
|
|
}
|