[cfe-commits] r59553 - in /cfe/trunk/lib/CodeGen: CGExpr.cpp CGObjCGNU.cpp CGObjCMac.cpp CGObjCRuntime.h CGValue.h

Fariborz Jahanian fjahanian at apple.com
Tue Nov 18 13:45:40 PST 2008


Author: fjahanian
Date: Tue Nov 18 15:45:40 2008
New Revision: 59553

URL: http://llvm.org/viewvc/llvm-project?rev=59553&view=rev
Log:
Generate objc_read_weak for __weak objc loads.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/CodeGen/CGObjCRuntime.h
    cfe/trunk/lib/CodeGen/CGValue.h

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=59553&r1=59552&r2=59553&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Nov 18 15:45:40 2008
@@ -151,6 +151,14 @@
 /// this method emits the address of the lvalue, then loads the result as an
 /// rvalue, returning the rvalue.
 RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) {
+  if (LV.isObjcWeak()) {
+    // load of a __weak object. 
+    llvm::Value *AddrWeakObj = LV.getAddress();
+    llvm::Value *read_weak = CGM.getObjCRuntime().EmitObjCWeakCall(*this, 
+                                                                   AddrWeakObj);
+    return RValue::get(read_weak);
+  }
+      
   if (LV.isSimple()) {
     llvm::Value *Ptr = LV.getAddress();
     const llvm::Type *EltTy =

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=59553&r1=59552&r2=59553&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Tue Nov 18 15:45:40 2008
@@ -130,6 +130,8 @@
                              const ObjCAtThrowStmt &S);
   virtual void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
                                     const ObjCAtSynchronizedStmt &S);
+  virtual llvm::Value * EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF,
+                                         llvm::Value *AddrWeakObj);
 };
 } // end anonymous namespace
 
@@ -968,6 +970,12 @@
   CGF.ErrorUnsupported(&S, "@synchronized statement");
 }
 
+llvm::Value * CGObjCGNU::EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF,
+                                          llvm::Value *AddrWeakObj)
+{
+  return 0;
+}
+
 CodeGen::CGObjCRuntime *CodeGen::CreateGNUObjCRuntime(CodeGen::CodeGenModule &CGM){
   return new CGObjCGNU(CGM);
 }

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=59553&r1=59552&r2=59553&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Nov 18 15:45:40 2008
@@ -454,7 +454,8 @@
                              const ObjCAtThrowStmt &S);
   virtual void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
                                     const ObjCAtSynchronizedStmt &S);
-  
+  virtual llvm::Value * EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF,
+                                         llvm::Value *AddrWeakObj); 
 };
 } // end anonymous namespace
 
@@ -1775,6 +1776,17 @@
   EmitBranch(ExecuteTryExit ? E->FinallyBlock : E->FinallyNoExit);
 }
 
+/// EmitObjCWeakCall - Code gen for loading value of a __weak
+/// object: objc_read_weak (id *src)
+///
+llvm::Value * CGObjCMac::EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF,
+                                          llvm::Value *AddrWeakObj)
+{
+  llvm::Value *read_weak = CGF.Builder.CreateCall(ObjCTypes.GcReadWeakFn,
+                                                  AddrWeakObj, "weakobj");
+  return read_weak;
+}
+
 /// EmitSynchronizedStmt - Code gen for @synchronized(expr) stmt;
 /// Effectively generating code for:
 /// objc_sync_enter(expr);

Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.h?rev=59553&r1=59552&r2=59553&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.h Tue Nov 18 15:45:40 2008
@@ -145,6 +145,8 @@
                              const ObjCAtThrowStmt &S) = 0;
   virtual void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
                                     const ObjCAtSynchronizedStmt &S) = 0;
+  virtual llvm::Value * EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF,
+					 llvm::Value *AddrWeakObj) = 0;
 };
 
 /// Creates an instance of an Objective-C runtime class.  

Modified: cfe/trunk/lib/CodeGen/CGValue.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGValue.h?rev=59553&r1=59552&r2=59553&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGValue.h (original)
+++ cfe/trunk/lib/CodeGen/CGValue.h Tue Nov 18 15:45:40 2008
@@ -138,6 +138,10 @@
   static void SetQualifiers(unsigned Qualifiers, LValue& R) {
     R.Volatile = (Qualifiers&QualType::Volatile)!=0;
     R.Restrict = (Qualifiers&QualType::Restrict)!=0;
+    // FIXME: Convenient place to set objc flags to 0. This
+    // should really be done in a user-defined constructor instead.
+    R.ObjcWeak = 0;
+    R.ObjcStrong = 0;
   }
   
 public:





More information about the cfe-commits mailing list