[cfe-commits] r54833 - in /cfe/trunk/lib/CodeGen: CGObjC.cpp CGObjCGNU.cpp CGObjCMac.cpp CGObjCRuntime.h
Daniel Dunbar
daniel at zuster.org
Fri Aug 15 17:25:04 PDT 2008
Author: ddunbar
Date: Fri Aug 15 19:25:02 2008
New Revision: 54833
URL: http://llvm.org/viewvc/llvm-project?rev=54833&view=rev
Log:
Change ObjCRuntime::LookupClass -> GetClass, and now takes the
ObjCInterfaceDecl.
Change ObjCRuntime::GenerateMessageSendSuper to take the
ObjCInterfaceDecl for the super class, instead of just its name.
Change EmitObjCMessageExpr to make the right runtime calls for super
sends in class methods (i.e. a super send with the class object as
the receiver).
Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.h
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=54833&r1=54832&r2=54833&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Fri Aug 15 19:25:02 2008
@@ -48,13 +48,18 @@
// Find the receiver
llvm::Value *Receiver;
if (!ReceiverExpr) {
- const char * classname = E->getClassName()->getName();
- if (!strcmp(classname, "super")) {
- classname = E->getMethodDecl()->getClassInterface()->getName();
+ const ObjCInterfaceDecl *OID = E->getClassInfo().first;
+
+ // Very special case, super send in class method. The receiver is
+ // self (the class object) and the send uses super semantics.
+ if (!OID) {
+ assert(!strcmp(E->getClassName()->getName(), "super") &&
+ "Unexpected missing class interface in message send.");
+ OID = E->getMethodDecl()->getClassInterface();
+ isSuperMessage = true;
}
- llvm::Value *ClassName = CGM.GetAddrOfConstantCString(classname);
- ClassName = Builder.CreateStructGEP(ClassName, 0);
- Receiver = Runtime.LookupClass(Builder, ClassName);
+
+ Receiver = Runtime.GetClass(Builder, OID);
} else if (const PredefinedExpr *PDE =
dyn_cast<PredefinedExpr>(E->getReceiver())) {
assert(PDE->getIdentType() == PredefinedExpr::ObjCSuper);
@@ -88,10 +93,8 @@
if (isSuperMessage) {
// super is only valid in an Objective-C method
const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl);
- const char *SuperClass =
- OMD->getClassInterface()->getSuperClass()->getName();
return Runtime.GenerateMessageSendSuper(Builder, ConvertType(E->getType()),
- SuperClass,
+ OMD->getClassInterface()->getSuperClass(),
Receiver, E->getSelector(),
&Args[0], Args.size());
}
Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=54833&r1=54832&r2=54833&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Fri Aug 15 19:25:02 2008
@@ -101,13 +101,13 @@
unsigned ArgC);
virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
const llvm::Type *ReturnTy,
- const char *SuperClassName,
+ const ObjCInterfaceDecl *SuperClass,
llvm::Value *Receiver,
Selector Sel,
llvm::Value** ArgV,
unsigned ArgC);
- virtual llvm::Value *LookupClass(llvm::IRBuilder<> &Builder,
- llvm::Value *ClassName);
+ virtual llvm::Value *GetClass(llvm::IRBuilder<> &Builder,
+ const ObjCInterfaceDecl *OID);
virtual llvm::Value *GetSelector(llvm::IRBuilder<> &Builder, Selector Sel);
virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD);
@@ -170,8 +170,11 @@
}
// This has to perform the lookup every time, since posing and related
// techniques can modify the name -> class mapping.
-llvm::Value *CGObjCGNU::LookupClass(llvm::IRBuilder<> &Builder,
- llvm::Value *ClassName) {
+llvm::Value *CGObjCGNU::GetClass(llvm::IRBuilder<> &Builder,
+ const ObjCInterfaceDecl *OID) {
+ llvm::Value *ClassName = CGM.GetAddrOfConstantCString(OID->getName());
+ ClassName = Builder.CreateStructGEP(ClassName, 0);
+
llvm::Constant *ClassLookupFn =
TheModule.getOrInsertFunction("objc_lookup_class", IdTy, PtrToInt8Ty,
NULL);
@@ -235,14 +238,13 @@
///should be called.
llvm::Value *CGObjCGNU::GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
const llvm::Type *ReturnTy,
- const char *SuperClassName,
+ const ObjCInterfaceDecl *SuperClass,
llvm::Value *Receiver,
Selector Sel,
llvm::Value** ArgV,
unsigned ArgC) {
// TODO: This should be cached, not looked up every time.
- llvm::Value *ReceiverClass = LookupClass(Builder,
- MakeConstantString(SuperClassName));
+ llvm::Value *ReceiverClass = GetClass(Builder, SuperClass);
llvm::Value *cmd = GetSelector(Builder, Sel);
std::vector<const llvm::Type*> impArgTypes;
impArgTypes.push_back(Receiver->getType());
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=54833&r1=54832&r2=54833&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Fri Aug 15 19:25:02 2008
@@ -205,16 +205,17 @@
llvm::Value** ArgV,
unsigned ArgC);
- virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
- const llvm::Type *ReturnTy,
- const char *SuperClassName,
- llvm::Value *Receiver,
- Selector Sel,
- llvm::Value** ArgV,
- unsigned ArgC);
-
- virtual llvm::Value *LookupClass(llvm::IRBuilder<> &Builder,
- llvm::Value *ClassName);
+ virtual llvm::Value *
+ GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
+ const llvm::Type *ReturnTy,
+ const ObjCInterfaceDecl *SuperClass,
+ llvm::Value *Receiver,
+ Selector Sel,
+ llvm::Value** ArgV,
+ unsigned ArgC);
+
+ virtual llvm::Value *GetClass(llvm::IRBuilder<> &Builder,
+ const ObjCInterfaceDecl *SuperClass);
virtual llvm::Value *GetSelector(llvm::IRBuilder<> &Builder, Selector Sel);
@@ -260,10 +261,10 @@
EmitImageInfo();
}
-// This has to perform the lookup every time, since posing and related
-// techniques can modify the name -> class mapping.
-llvm::Value *CGObjCMac::LookupClass(llvm::IRBuilder<> &Builder,
- llvm::Value *ClassName) {
+/// GetClass - Return a reference to the class for the given interface
+/// decl.
+llvm::Value *CGObjCMac::GetClass(llvm::IRBuilder<> &Builder,
+ const ObjCInterfaceDecl *OID) {
assert(0 && "Cannot lookup classes on Mac runtime.");
return 0;
}
@@ -323,13 +324,14 @@
/// 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.
-llvm::Value *CGObjCMac::GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
- const llvm::Type *ReturnTy,
- const char *SuperClassName,
- llvm::Value *Receiver,
- Selector Sel,
- llvm::Value** ArgV,
- unsigned ArgC) {
+llvm::Value *
+CGObjCMac::GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
+ const llvm::Type *ReturnTy,
+ const ObjCInterfaceDecl *SuperClass,
+ llvm::Value *Receiver,
+ Selector Sel,
+ llvm::Value** ArgV,
+ unsigned ArgC) {
assert(0 && "Cannot generate message send to super for Mac runtime.");
return 0;
}
Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.h?rev=54833&r1=54832&r2=54833&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.h Fri Aug 15 19:25:02 2008
@@ -31,6 +31,7 @@
namespace clang {
class ObjCCategoryImplDecl;
class ObjCImplementationDecl;
+ class ObjCInterfaceDecl;
class ObjCMethodDecl;
class ObjCProtocolDecl;
class Selector;
@@ -78,13 +79,14 @@
/// Generate an Objective-C message send operation to the super
/// class.
- virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<true> &Builder,
- const llvm::Type *ReturnTy,
- const char *SuperClassName,
- llvm::Value *Receiver,
- Selector Sel,
- llvm::Value** ArgV,
- unsigned ArgC) = 0;
+ virtual llvm::Value *
+ GenerateMessageSendSuper(llvm::IRBuilder<true> &Builder,
+ const llvm::Type *ReturnTy,
+ const ObjCInterfaceDecl *SuperClassName,
+ llvm::Value *Receiver,
+ Selector Sel,
+ llvm::Value** ArgV,
+ unsigned ArgC) = 0;
/// Emit the code to return the named protocol as an object, as in a
/// @protocol expression.
@@ -104,9 +106,10 @@
// parameters are passed.
virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD) = 0;
- /// Look up the class for the specified name
- virtual llvm::Value *LookupClass(BuilderType &Builder,
- llvm::Value *ClassName) = 0;
+ /// GetClass - Return a reference to the class for the given
+ /// interface decl.
+ virtual llvm::Value *GetClass(BuilderType &Builder,
+ const ObjCInterfaceDecl *OID) = 0;
/// If instance variable addresses are determined at runtime then this should
/// return true, otherwise instance variables will be accessed directly from
More information about the cfe-commits
mailing list