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

Fariborz Jahanian fjahanian at apple.com
Tue Nov 18 12:18:12 PST 2008


Author: fjahanian
Date: Tue Nov 18 14:18:11 2008
New Revision: 59543

URL: http://llvm.org/viewvc/llvm-project?rev=59543&view=rev
Log:
Some basic support toward objective-c's GC code gen.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    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=59543&r1=59542&r2=59543&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Nov 18 14:18:11 2008
@@ -492,8 +492,14 @@
       return LValue::MakeAddr(V, E->getType().getCVRQualifiers());
     }
   } else if (VD && VD->isFileVarDecl()) {
-    return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
-                            E->getType().getCVRQualifiers());
+    LValue LV = LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
+                                 E->getType().getCVRQualifiers());
+    if (VD->getAttr<ObjCGCAttr>())
+    {
+      ObjCGCAttr::GCAttrTypes attrType = (VD->getAttr<ObjCGCAttr>())->getType();
+      LValue::SetObjCGCAttrs(attrType == ObjCGCAttr::Weak, attrType == ObjCGCAttr::Strong, LV);
+    }
+    return LV;
   } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) {
     return LValue::MakeAddr(CGM.GetAddrOfFunction(FD),
                             E->getType().getCVRQualifiers());

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Nov 18 14:18:11 2008
@@ -51,6 +51,10 @@
 
   /// ObjectPtrTy - LLVM type for object handles (typeof(id))
   const llvm::Type *ObjectPtrTy;
+  
+  /// PtrObjectPtrTy - LLVM type for id *
+  const llvm::Type *PtrObjectPtrTy;
+  
   /// SelectorPtrTy - LLVM type for selector handles (typeof(SEL))
   const llvm::Type *SelectorPtrTy;
   /// ProtocolPtrTy - LLVM type for external protocol handles
@@ -162,6 +166,18 @@
   /// SyncExitFn - LLVM object_sync_exit function.
   llvm::Function *SyncExitFn;
   
+  /// GcReadWeakFn -- LLVM objc_read_weak (id *src) function.
+  llvm::Function *GcReadWeakFn;
+  
+  /// GcAssignWeakFn -- LLVM objc_assign_weak function.
+  llvm::Function *GcAssignWeakFn;
+  
+  /// GcAssignGlobalFn -- LLVM objc_assign_global function.
+  llvm::Function *GcAssignGlobalFn;
+  
+  /// GcAssignStrongCastFn -- LLVM objc_assign_strongCast function.
+  llvm::Function *GcAssignStrongCastFn;
+  
 public:
   ObjCTypesHelper(CodeGen::CodeGenModule &cgm);
   ~ObjCTypesHelper();
@@ -2191,6 +2207,7 @@
   Int8PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
   
   ObjectPtrTy = Types.ConvertType(Ctx.getObjCIdType());
+  PtrObjectPtrTy = llvm::PointerType::getUnqual(ObjectPtrTy);
   SelectorPtrTy = Types.ConvertType(Ctx.getObjCSelType());
   
   // FIXME: It would be nice to unify this with the opaque type, so
@@ -2538,6 +2555,36 @@
                                                       Params,
                                                       false),
                               "_setjmp");
+  
+  // gc's API
+  // id objc_read_weak (id *)
+  Params.clear();
+  Params.push_back(PtrObjectPtrTy);
+  GcReadWeakFn =
+    CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy,
+                                                      Params,
+                                                      false),
+                              "objc_read_weak");
+  // id objc_assign_weak (id, id *)                                      
+  Params.clear();
+  Params.push_back(ObjectPtrTy);
+  Params.push_back(PtrObjectPtrTy);
+  GcAssignWeakFn = 
+  CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy,
+                                                    Params,
+                                                    false),
+                           "objc_assign_weak");
+  GcAssignGlobalFn =
+    CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy,
+                                                      Params,
+                                                      false),
+                           "objc_assign_global");
+  GcAssignStrongCastFn =
+    CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy,
+                                                      Params,
+                                                      false),
+                           "objc_assign_strongCast");
+  
 }
 
 ObjCTypesHelper::~ObjCTypesHelper() {

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGValue.h (original)
+++ cfe/trunk/lib/CodeGen/CGValue.h Tue Nov 18 14:18:11 2008
@@ -130,13 +130,16 @@
   bool Volatile:1;
   // FIXME: set but never used, what effect should it have?
   bool Restrict:1;
+  
+  bool ObjcWeak:1;
+  bool ObjcStrong:1;
 
 private:
   static void SetQualifiers(unsigned Qualifiers, LValue& R) {
     R.Volatile = (Qualifiers&QualType::Volatile)!=0;
     R.Restrict = (Qualifiers&QualType::Restrict)!=0;
   }
-
+  
 public:
   bool isSimple() const { return LVType == Simple; }
   bool isVectorElt() const { return LVType == VectorElt; }
@@ -146,7 +149,15 @@
 
   bool isVolatileQualified() const { return Volatile; }
   bool isRestrictQualified() const { return Restrict; }
-
+  
+  bool isObjcWeak() const { return ObjcWeak; }
+  bool isObjcStrong() const { return ObjcStrong; }
+  
+  static void SetObjCGCAttrs(unsigned Weak, unsigned Strong, LValue& R) {
+    R.ObjcWeak = Weak;
+    R.ObjcStrong = Strong;
+  }
+  
   // simple lvalue
   llvm::Value *getAddress() const { assert(isSimple()); return V; }
   // vector elt lvalue





More information about the cfe-commits mailing list