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

Devang Patel dpatel at apple.com
Wed Mar 4 10:21:40 PST 2009


Author: dpatel
Date: Wed Mar  4 12:21:39 2009
New Revision: 66043

URL: http://llvm.org/viewvc/llvm-project?rev=66043&view=rev
Log:

Refactor code. 


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=66043&r1=66042&r2=66043&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Mar  4 12:21:39 2009
@@ -381,7 +381,7 @@
   
   // FIXME: This is a horrible name.
   llvm::Constant *GetMethodVarType(const ObjCMethodDecl *D);
-  llvm::Constant *GetMethodVarType(const std::string &Name);
+  llvm::Constant *GetMethodVarType(FieldDecl *D);
   
   /// GetPropertyName - Return a unique constant for the given
   /// name. The return value has type char *.
@@ -1696,9 +1696,7 @@
       Ivar[0] = GetMethodVarName(Field->getIdentifier());
     else
       Ivar[0] = llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy);
-    std::string TypeStr;
-    CGM.getContext().getObjCEncodingForType(Field->getType(), TypeStr, Field);
-    Ivar[1] = GetMethodVarType(TypeStr);
+    Ivar[1] = GetMethodVarType(Field);
     Ivar[2] = llvm::ConstantInt::get(ObjCTypes.IntTy, Offset);
     Ivars.push_back(llvm::ConstantStruct::get(ObjCTypes.IvarTy, Ivar));
   }
@@ -2467,11 +2465,14 @@
   return GetMethodVarName(&CGM.getContext().Idents.get(Name));
 }
 
-llvm::Constant *CGObjCCommonMac::GetMethodVarType(const std::string &Name) {
-  llvm::GlobalVariable *&Entry = MethodVarTypes[Name];
+llvm::Constant *CGObjCCommonMac::GetMethodVarType(FieldDecl *Field) {
+  std::string TypeStr;
+  CGM.getContext().getObjCEncodingForType(Field->getType(), TypeStr, Field);
+
+  llvm::GlobalVariable *&Entry = MethodVarTypes[TypeStr];
 
   if (!Entry) {
-    llvm::Constant *C = llvm::ConstantArray::get(Name);
+    llvm::Constant *C = llvm::ConstantArray::get(TypeStr);
     Entry = 
       new llvm::GlobalVariable(C->getType(), false, 
                                llvm::GlobalValue::InternalLinkage,
@@ -2484,12 +2485,25 @@
   return getConstantGEP(Entry, 0, 0);
 }
 
-// FIXME: Merge into a single cstring creation function.
 llvm::Constant *CGObjCCommonMac::GetMethodVarType(const ObjCMethodDecl *D) {
   std::string TypeStr;
   CGM.getContext().getObjCEncodingForMethodDecl(const_cast<ObjCMethodDecl*>(D),
                                                 TypeStr);
-  return GetMethodVarType(TypeStr);
+
+  llvm::GlobalVariable *&Entry = MethodVarTypes[TypeStr];
+
+  if (!Entry) {
+    llvm::Constant *C = llvm::ConstantArray::get(TypeStr);
+    Entry = 
+      new llvm::GlobalVariable(C->getType(), false, 
+                               llvm::GlobalValue::InternalLinkage,
+                               C, "\01L_OBJC_METH_VAR_TYPE_", 
+                               &CGM.getModule());
+    Entry->setSection("__TEXT,__cstring,cstring_literals");
+    UsedGlobals.push_back(Entry);
+  }
+
+  return getConstantGEP(Entry, 0, 0);
 }
 
 // FIXME: Merge into a single cstring creation function.
@@ -4077,9 +4091,7 @@
       Ivar[1] = GetMethodVarName(Field->getIdentifier());
     else
       Ivar[1] = llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy);
-    std::string TypeStr;
-    CGM.getContext().getObjCEncodingForType(Field->getType(), TypeStr, Field);
-    Ivar[2] = GetMethodVarType(TypeStr);
+    Ivar[2] = GetMethodVarType(Field);
     const llvm::Type *FieldTy =
       CGM.getTypes().ConvertTypeForMem(Field->getType());
     unsigned Size = CGM.getTargetData().getTypePaddedSize(FieldTy);





More information about the cfe-commits mailing list