[cfe-commits] r69797 - in /cfe/trunk/lib/CodeGen: CGObjCMac.cpp CodeGenModule.cpp CodeGenTypes.cpp CodeGenTypes.h

Daniel Dunbar daniel at zuster.org
Wed Apr 22 03:28:47 PDT 2009


Author: ddunbar
Date: Wed Apr 22 05:28:39 2009
New Revision: 69797

URL: http://llvm.org/viewvc/llvm-project?rev=69797&view=rev
Log:
Don't convert interface types (to structs) as part of CodeGenTypes.
 - This has pros and cons, but for now the pros seem to significantly
   outway the con.

The con is that we will always need to cast in the runtime
implementation to a struct type, if we wish to access an interface
directly.

The pros are:
 - Avoid the cost of generating types which are used. Most
   manipulation of Objective-C objects is done through messages, and
   only the implementation of a class will directly access
   memory. Previously, we would convert the type even if it only
   appear as a function parameter, for example.

 - We don't need to worry about incomplete types, and
   UpdateCompletedType for interfaces is gone.

 - It becomes easier to narrow the interface to the shadow struct for
   Objective-C interfaces (so it can be eliminated).

Currently the runtimes still use the CodeGenTypes machinery to
generate the LLVM structure they need via ConvertTagDecl, but this can
eventually be replaced.

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Apr 22 05:28:39 2009
@@ -37,8 +37,8 @@
 CGObjCRuntime::GetConcreteClassStruct(CodeGen::CodeGenModule &CGM,
                                       const ObjCInterfaceDecl *OID) {
   assert(!OID->isForwardDecl() && "Invalid interface decl!");
-  QualType T = CGM.getContext().getObjCInterfaceType(OID);
-  return cast<llvm::StructType>(CGM.getTypes().ConvertType(T));
+  const RecordDecl *RD = CGM.getContext().addRecordToClass(OID);
+  return cast<llvm::StructType>(CGM.getTypes().ConvertTagDeclType(RD));
 }
 
 uint64_t CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
@@ -71,6 +71,11 @@
                                                const ObjCIvarDecl *Ivar,
                                                unsigned CVRQualifiers,
                                                llvm::Value *Offset) {
+  // Force generation of the codegen information for this structure.
+  //
+  // FIXME: Remove once we don't use the bit-field lookup map.
+  (void) GetConcreteClassStruct(CGF.CGM, OID);
+
   // FIXME: For now, we use an implementation based on just computing
   // the offset and calculating things directly. For optimization
   // purposes, it would be cleaner to use a GEP on the proper type

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Apr 22 05:28:39 2009
@@ -1369,11 +1369,7 @@
   case Decl::ObjCClass:
   case Decl::ObjCForwardProtocol:
   case Decl::ObjCCategory:
-    break;
   case Decl::ObjCInterface:
-    // If we already laid out this interface due to an @class, and if we
-    // codegen'd a reference it, update the 'opaque' type to be a real type now.
-    Types.UpdateCompletedType(cast<ObjCInterfaceDecl>(D));
     break;
 
   case Decl::ObjCProtocol:

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Wed Apr 22 05:28:39 2009
@@ -197,39 +197,6 @@
   }
 }
 
-void CodeGenTypes::UpdateCompletedType(const ObjCInterfaceDecl *OID) {
-  // Check to see if we have already laid this type out, if not, just return.
-  QualType OIDTy = Context.getObjCInterfaceType(OID);
-  llvm::DenseMap<Type *, llvm::PATypeHolder>::iterator TCI =
-    TypeCache.find(OIDTy.getTypePtr());
-  if (TCI == TypeCache.end()) return;
-
-  // Remember the opaque LLVM type for this interface.
-  llvm::PATypeHolder OpaqueHolder = TCI->second;
-  assert(isa<llvm::OpaqueType>(OpaqueHolder.get()) &&
-         "Updating compilation of an already non-opaque type?");
-  
-  // Remove it from TagDeclTypes so that it will be regenerated.
-  TypeCache.erase(TCI);
-
-  // Update the "shadow" struct that is laid out.
-  // FIXME: REMOVE THIS.
-  const RecordDecl *RD = Context.addRecordToClass(OID);
-  UpdateCompletedType(RD);
-  
-  // Generate the new type.
-  const llvm::Type *NT = ConvertType(OIDTy);
-  assert(!isa<llvm::OpaqueType>(NT) && "Didn't do layout!");
-
-  // FIXME: Remove this check when shadow structs go away.
-  if (isa<llvm::OpaqueType>(OpaqueHolder)) {
-  
-  // Refine the old opaque type to its new definition.
-  cast<llvm::OpaqueType>(OpaqueHolder.get())->refineAbstractTypeTo(NT);
-  }
-}
-
-
 static const llvm::Type* getTypeForFormat(const llvm::fltSemantics &format) {
   if (&format == &llvm::APFloat::IEEEsingle)
     return llvm::Type::FloatTy;
@@ -373,8 +340,13 @@
   }
       
   case Type::ObjCInterface: {
-    ObjCInterfaceDecl *ID = cast<ObjCInterfaceType>(Ty).getDecl();
-    return ConvertTagDeclType(Context.addRecordToClass(ID));
+    // Objective-C interfaces are always opaque (outside of the
+    // runtime, which can do whatever it likes); we never refine
+    // these.
+    const llvm::Type *&T = InterfaceTypes[cast<ObjCInterfaceType>(&Ty)];
+    if (!T)
+        T = llvm::OpaqueType::get();
+    return T;
   }
       
   case Type::ObjCQualifiedId:

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.h Wed Apr 22 05:28:39 2009
@@ -92,6 +92,12 @@
 
   llvm::DenseMap<const Type*, llvm::PATypeHolder> FunctionTypes;
 
+  /// The opaque type map for Objective-C interfaces. All direct
+  /// manipulation is done by the runtime interfaces, which are
+  /// responsible for coercing to the appropriate type; these opaque
+  /// types are never refined.
+  llvm::DenseMap<const ObjCInterfaceType*, const llvm::Type *> InterfaceTypes;
+
   /// CGRecordLayouts - This maps llvm struct type with corresponding 
   /// record layout info. 
   /// FIXME : If CGRecordLayout is less than 16 bytes then use 
@@ -162,8 +168,6 @@
   /// UpdateCompletedType - When we find the full definition for a TagDecl,
   /// replace the 'opaque' type we previously made for it if applicable.
   void UpdateCompletedType(const TagDecl *TD);
-  /// Likewise for an ObjC Interface.
-  void UpdateCompletedType(const ObjCInterfaceDecl *OID);
 
   /// getFunctionInfo - Get the CGFunctionInfo for this function signature.
   const CGFunctionInfo &getFunctionInfo(QualType RetTy, 





More information about the cfe-commits mailing list