[cfe-commits] r63881 - /cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Feb 5 12:41:40 PST 2009


Author: fjahanian
Date: Thu Feb  5 14:41:40 2009
New Revision: 63881

URL: http://llvm.org/viewvc/llvm-project?rev=63881&view=rev
Log:
objc2's nonfragile-abi -  API selection for when receiver is a class

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Feb  5 14:41:40 2009
@@ -657,6 +657,11 @@
                                   bool IsSuper,
                                   const CallArgList &CallArgs);
   
+  /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
+  /// for the given class.
+  llvm::Value *EmitClassRef(CGBuilderTy &Builder, 
+                            const ObjCInterfaceDecl *ID);
+  
 public:
   CGObjCNonFragileABIMac(CodeGen::CodeGenModule &cgm);
   // FIXME. All stubs for now!
@@ -679,7 +684,7 @@
                            const CallArgList &CallArgs){ return RValue::get(0);}
   
   virtual llvm::Value *GetClass(CGBuilderTy &Builder,
-                                const ObjCInterfaceDecl *ID){ return 0; }
+                                const ObjCInterfaceDecl *ID);
   
   virtual llvm::Value *GetSelector(CGBuilderTy &Builder, Selector Sel)
     { return 0; }
@@ -3589,38 +3594,41 @@
     flags |= CLS_ROOT;
     std::string SuperClassName = ObjCClassName + ClassName;
     SuperClassGV = CGM.getModule().getGlobalVariable(SuperClassName);
-    if (!SuperClassGV)
+    if (!SuperClassGV) {
       SuperClassGV = 
         new llvm::GlobalVariable(ObjCTypes.ClassnfABITy, false,
                                 llvm::GlobalValue::ExternalLinkage,
                                  0,
                                  SuperClassName,
                                  &CGM.getModule());
-    UsedGlobals.push_back(SuperClassGV);
+      UsedGlobals.push_back(SuperClassGV);
+    }
     std::string IsAClassName = ObjCMetaClassName + ClassName;
     IsAGV = CGM.getModule().getGlobalVariable(IsAClassName);
-    if (!IsAGV)
+    if (!IsAGV) {
       IsAGV = 
         new llvm::GlobalVariable(ObjCTypes.ClassnfABITy, false,
                                  llvm::GlobalValue::ExternalLinkage,
                                  0,
                                  IsAClassName,
                                  &CGM.getModule());
-    UsedGlobals.push_back(IsAGV);
+      UsedGlobals.push_back(IsAGV);
+    }
   } else {
     // Has a root. Current class is not a root.
     std::string RootClassName = 
       ID->getClassInterface()->getSuperClass()->getNameAsString();
     std::string SuperClassName = ObjCMetaClassName + RootClassName;
     SuperClassGV = CGM.getModule().getGlobalVariable(SuperClassName);
-    if (!SuperClassGV)
+    if (!SuperClassGV) {
       SuperClassGV = 
         new llvm::GlobalVariable(ObjCTypes.ClassnfABITy, false,
                                  llvm::GlobalValue::ExternalLinkage,
                                  0,
                                  SuperClassName,
                                  &CGM.getModule());
-    UsedGlobals.push_back(SuperClassGV);
+      UsedGlobals.push_back(SuperClassGV);
+    }
     IsAGV = SuperClassGV;
   }
   llvm::GlobalVariable *CLASS_RO_GV = BuildClassRoTInitializer(flags,
@@ -3645,15 +3653,15 @@
       ID->getClassInterface()->getSuperClass()->getNameAsString();
     std::string SuperClassName = ObjCClassName + RootClassName;
     SuperClassGV = CGM.getModule().getGlobalVariable(SuperClassName);
-    if (!SuperClassGV)
+    if (!SuperClassGV) {
       SuperClassGV = 
       new llvm::GlobalVariable(ObjCTypes.ClassnfABITy, false,
                                llvm::GlobalValue::ExternalLinkage,
                                0,
                                SuperClassName,
                                &CGM.getModule());
-    UsedGlobals.push_back(SuperClassGV);
-    
+      UsedGlobals.push_back(SuperClassGV);
+    }
   }
   
   InstanceStart = InstanceSize = 0;
@@ -4394,6 +4402,47 @@
                          false, CallArgs);
 }
 
+llvm::Value *CGObjCNonFragileABIMac::EmitClassRef(CGBuilderTy &Builder, 
+                                     const ObjCInterfaceDecl *ID) {
+  
+  llvm::GlobalVariable *&Entry = ClassReferences[ID->getIdentifier()];
+  
+  if (!Entry) {
+    std::string ClassName("\01_OBJC_CLASS_$_" + ID->getNameAsString());
+    llvm::GlobalVariable *ClassGV = 
+      CGM.getModule().getGlobalVariable(ClassName);
+    if (!ClassGV) {
+      ClassGV =
+        new llvm::GlobalVariable(ObjCTypes.ClassnfABITy, false,
+                                 llvm::GlobalValue::ExternalLinkage,
+                                 0,
+                                 ClassName,
+                                 &CGM.getModule());
+      UsedGlobals.push_back(ClassGV);
+    }
+    Entry = 
+      new llvm::GlobalVariable(ObjCTypes.ClassnfABIPtrTy, false,
+                               llvm::GlobalValue::InternalLinkage,
+                               ClassGV, "\01L_OBJC_CLASSLIST_REFERENCES_$_",
+                               &CGM.getModule());
+    Entry->setAlignment(
+                     CGM.getTargetData().getPrefTypeAlignment(
+                                                  ObjCTypes.ClassnfABIPtrTy));
+
+    Entry->setSection("__OBJC,__objc_classrefs,regular,no_dead_strip");
+    UsedGlobals.push_back(Entry);
+  }
+  
+  return Builder.CreateLoad(Entry, false, "tmp");
+}
+
+/// GetClass - Return a reference to the class for the given interface
+/// decl.
+llvm::Value *CGObjCNonFragileABIMac::GetClass(CGBuilderTy &Builder,
+                                              const ObjCInterfaceDecl *ID) {
+  return EmitClassRef(Builder, ID);
+}
+
 /* *** */
 
 CodeGen::CGObjCRuntime *





More information about the cfe-commits mailing list