]> granicus.if.org Git - clang/commitdiff
This patch adds support for sender-aware dispatch in Objective-C for the GNU runtime...
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 22 May 2009 20:17:16 +0000 (20:17 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 22 May 2009 20:17:16 +0000 (20:17 +0000)
compiled with -fobjc-sender-dependent-dispatch.  This is used in AOP, COP, implementing object
planes, and a few other things.
Patch by David Chisnall.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72275 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/LangOptions.h
include/clang/Driver/Options.def
lib/CodeGen/CGObjCGNU.cpp
lib/Driver/Tools.cpp
lib/Frontend/InitPreprocessor.cpp
tools/clang-cc/clang-cc.cpp

index 1214afacd0ef50c5efc0853f6b4a982c776dbd59..74e70a69850169d28a54d4ea02f6301aa1273e2e 100644 (file)
@@ -36,6 +36,8 @@ public:
     
   unsigned ObjC1             : 1;  // Objective-C 1 support enabled.
   unsigned ObjC2             : 1;  // Objective-C 2 support enabled.
+  unsigned ObjCSenderDispatch: 1;  // Objective-C 2 three-dimensional dispatch
+                                   // enabled.
   unsigned ObjCNonFragileABI : 1;  // Objective-C modern abi enabled
     
   unsigned PascalStrings     : 1;  // Allow Pascal strings
index 2ec2336c8dc4707b71551ee25d666ec8c5b34978..cd046bc930ff347fd1cee0b74c959009ad1d404f 100644 (file)
@@ -425,6 +425,7 @@ OPTION("-fobjc-gc-only", fobjc_gc_only, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc-gc", fobjc_gc, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc-new-property", fobjc_new_property, Flag, clang_ignored_f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc-nonfragile-abi", fobjc_nonfragile_abi, Flag, f_Group, INVALID, "", 0, 0, 0)
+OPTION("-fobjc-sender-dependent-dispatch", fobjc_sender_dependent_dispatch, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc-tight-layout", fobjc_tight_layout, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc", fobjc, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fomit-frame-pointer", fomit_frame_pointer, Flag, f_Group, INVALID, "", 0, 0, 0)
index 2cae9a0ea877fadf7f02efb969c9c2d8b7254ccc..5e7eec9819c82c61bf9fb86ccd3a081c24c8743d 100644 (file)
@@ -417,8 +417,8 @@ CGObjCGNU::GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
   CallArgList ActualArgs;
 
   ActualArgs.push_back(
-         std::make_pair(RValue::get(CGF.Builder.CreateBitCast(Receiver, IdTy)), 
-         CGF.getContext().getObjCIdType()));
+    std::make_pair(RValue::get(CGF.Builder.CreateBitCast(Receiver, IdTy)), 
+    CGF.getContext().getObjCIdType()));
   ActualArgs.push_back(std::make_pair(RValue::get(cmd),
                                       CGF.getContext().getObjCSelType()));
   ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
@@ -427,15 +427,36 @@ CGObjCGNU::GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
   const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs);
   const llvm::FunctionType *impType = Types.GetFunctionType(FnInfo, false);
 
+  llvm::Value *imp;
   std::vector<const llvm::Type*> Params;
   Params.push_back(Receiver->getType());
   Params.push_back(SelectorTy);
-  llvm::Constant *lookupFunction = 
-    CGM.CreateRuntimeFunction(llvm::FunctionType::get(
+  // For sender-aware dispatch, we pass the sender as the third argument to a
+  // lookup function.  When sending messages from C code, the sender is nil.
+  // objc_msg_lookup_sender(id receiver, SEL selector, id sender);
+  if (CGM.getContext().getLangOptions().ObjCSenderDispatch) {
+    llvm::Value *self;
+
+    if (isa<ObjCMethodDecl>(CGF.CurFuncDecl)) {
+      self = CGF.LoadObjCSelf();
+    } else {
+      self = llvm::ConstantPointerNull::get(IdTy);
+    }
+    Params.push_back(self->getType());
+    llvm::Constant *lookupFunction = 
+      CGM.CreateRuntimeFunction(llvm::FunctionType::get(
           llvm::PointerType::getUnqual(impType), Params, true),
-        "objc_msg_lookup");
+        "objc_msg_lookup_sender");
 
-  llvm::Value *imp = CGF.Builder.CreateCall2(lookupFunction, Receiver, cmd);
+    imp = CGF.Builder.CreateCall3(lookupFunction, Receiver, cmd, self);
+  } else {
+    llvm::Constant *lookupFunction = 
+    CGM.CreateRuntimeFunction(llvm::FunctionType::get(
+        llvm::PointerType::getUnqual(impType), Params, true),
+      "objc_msg_lookup");
+
+    imp = CGF.Builder.CreateCall2(lookupFunction, Receiver, cmd);
+  }
 
   return CGF.EmitCall(FnInfo, imp, ActualArgs);
 }
index fd071dfe2827c02a85858785dd266b06b0ef37ab..abfabbb721a1329793b46342a5035aa638e8d713 100644 (file)
@@ -479,6 +479,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   Args.AddLastArg(CmdArgs, options::OPT_fno_show_column);
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc_only);
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc);
+  Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
   // FIXME: Should we remove this?
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_nonfragile_abi);
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_tight_layout);
index 1ad9d5c8d3b83c27afb13f51a558072b7db44a85..8f4cdbc5f5d8e6fa8ff37c2fdd5ffdc965786d6d 100644 (file)
@@ -280,6 +280,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
   if (LangOpts.ObjC2)
     DefineBuiltinMacro(Buf, "OBJC_NEW_PROPERTIES");
 
+  if (LangOpts.ObjCSenderDispatch)
+    DefineBuiltinMacro(Buf, "__OBJC_SENDER_AWARE_DISPATCH__");
+
   if (LangOpts.PascalStrings)
     DefineBuiltinMacro(Buf, "__PASCAL_STRINGS__");
 
index f2f05237a2aaefcd351b21f4042e7d2c82eebc0b..5b0f86403496e9d9828935a6ae5852c73feab0cc 100644 (file)
@@ -445,6 +445,10 @@ OverflowChecking("ftrapv",
                  llvm::cl::desc("Trap on integer overflow"),
                  llvm::cl::init(false));
 
+static llvm::cl::opt<bool>
+ObjCSenderDispatch("fobjc-sender-dependent-dispatch",
+                                llvm::cl::desc("Enable sender-dependent dispatch for"
+                                        "Objective-C messages"), llvm::cl::init(false));
 
 /// InitializeBaseLanguage - Handle the -x foo options.
 static void InitializeBaseLanguage() {
@@ -827,6 +831,8 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
 
   if (ObjCNonFragileABI)
     Options.ObjCNonFragileABI = 1;
+
+  Options.ObjCSenderDispatch = ObjCSenderDispatch;
   
   if (EmitAllDecls)
     Options.EmitAllDecls = 1;