[cfe-commits] r100772 - in /cfe/trunk: lib/CodeGen/CGRTTI.cpp lib/CodeGen/CGVtable.cpp lib/CodeGen/CodeGenModule.cpp test/CodeGenCXX/rtti-fundamental.cpp

Douglas Gregor dgregor at apple.com
Thu Apr 8 08:52:03 PDT 2010


Author: dgregor
Date: Thu Apr  8 10:52:03 2010
New Revision: 100772

URL: http://llvm.org/viewvc/llvm-project?rev=100772&view=rev
Log:
Eliminate excessive PCH deserialization caused by the search for
__cxxabiv1::__fundamental_type_info in every translation
unit. Previously, we would perform name lookup for
__cxxabiv1::__fundamental_type_info at the end of IRGen for a each
translation unit, to determine whether it was present. If so, we we
produce type information for all of the fundamental types. However,
this name lookup causes PCH deserialization of a significant part of the
translation unit, which has a woeful impact on performance.

With this change, we now look at each record type after we've
generated its vtable to see if it is
__cxxabiv1::__fundamental_type_info. If so, we generate type info for
all of the fundamental types. This works because
__cxxabiv1::__fundamental_type_info should always have a key function
(typically the virtual destructor), that will be defined once in the
support library. The fundamental type information will end up there.

Fixes <rdar://problem/7840011>.


Modified:
    cfe/trunk/lib/CodeGen/CGRTTI.cpp
    cfe/trunk/lib/CodeGen/CGVtable.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGenCXX/rtti-fundamental.cpp

Modified: cfe/trunk/lib/CodeGen/CGRTTI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRTTI.cpp?rev=100772&r1=100771&r2=100772&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRTTI.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRTTI.cpp Thu Apr  8 10:52:03 2010
@@ -791,35 +791,6 @@
   return RTTIBuilder(*this).BuildTypeInfo(Ty);
 }
 
-// Try to find the magic class __cxxabiv1::__fundamental_type_info. If
-// exists and has a destructor, we will emit the typeinfo for the fundamental
-// types. This is the same behaviour as GCC.
-static CXXRecordDecl *FindMagicClass(ASTContext &AC) {
-  const IdentifierInfo &NamespaceII = AC.Idents.get("__cxxabiv1");
-  DeclarationName NamespaceDN = AC.DeclarationNames.getIdentifier(&NamespaceII);
-  TranslationUnitDecl *TUD = AC.getTranslationUnitDecl();
-  DeclContext::lookup_result NamespaceLookup = TUD->lookup(NamespaceDN);
-  if (NamespaceLookup.first == NamespaceLookup.second)
-    return NULL;
-  const NamespaceDecl *Namespace =
-    dyn_cast<NamespaceDecl>(*NamespaceLookup.first);
-  if (!Namespace)
-    return NULL;
-
-  const IdentifierInfo &ClassII = AC.Idents.get("__fundamental_type_info");
-  DeclarationName ClassDN =  AC.DeclarationNames.getIdentifier(&ClassII);
-  DeclContext::lookup_const_result ClassLookup =  Namespace->lookup(ClassDN);
-  if (ClassLookup.first == ClassLookup.second)
-    return NULL;
-  CXXRecordDecl *Class = dyn_cast<CXXRecordDecl>(*ClassLookup.first);
-
-  if (Class->hasDefinition() && Class->isDynamicClass() &&
-      Class->getDestructor(AC))
-    return Class;
-
-  return NULL;
-}
-
 void CodeGenModule::EmitFundamentalRTTIDescriptor(QualType Type) {
   QualType PointerType = Context.getPointerType(Type);
   QualType PointerTypeConst = Context.getPointerType(Type.withConst());
@@ -829,12 +800,6 @@
 }
 
 void CodeGenModule::EmitFundamentalRTTIDescriptors() {
-  CXXRecordDecl *RD = FindMagicClass(getContext());
-  if (!RD)
-    return;
-
-  getVTables().GenerateClassData(getVtableLinkage(RD), RD);
-
   QualType FundamentalTypes[] = { Context.VoidTy, Context.Char32Ty,
                                   Context.Char16Ty, Context.UnsignedLongLongTy,
                                   Context.LongLongTy, Context.WCharTy,

Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=100772&r1=100771&r2=100772&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Thu Apr  8 10:52:03 2010
@@ -3121,6 +3121,18 @@
   EmitVTableDefinition(VTable, Linkage, RD);
 
   GenerateVTT(Linkage, /*GenerateDefinition=*/true, RD);
+
+  // If this is the magic class __cxxabiv1::__fundamental_type_info,
+  // we will emit the typeinfo for the fundamental types. This is the
+  // same behaviour as GCC.
+  const DeclContext *DC = RD->getDeclContext();
+  if (RD->getIdentifier() &&
+      RD->getIdentifier()->isStr("__fundamental_type_info") &&
+      isa<NamespaceDecl>(DC) &&
+      cast<NamespaceDecl>(DC)->getIdentifier() &&
+      cast<NamespaceDecl>(DC)->getIdentifier()->isStr("__cxxabiv1") &&
+      DC->getParent()->isTranslationUnit())
+    CGM.EmitFundamentalRTTIDescriptors();
 }
 
 void CodeGenVTables::EmitVTableRelatedData(GlobalDecl GD) {

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=100772&r1=100771&r2=100772&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Apr  8 10:52:03 2010
@@ -78,7 +78,6 @@
 }
 
 void CodeGenModule::Release() {
-  EmitFundamentalRTTIDescriptors();
   EmitDeferred();
   EmitCXXGlobalInitFunc();
   EmitCXXGlobalDtorFunc();

Modified: cfe/trunk/test/CodeGenCXX/rtti-fundamental.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/rtti-fundamental.cpp?rev=100772&r1=100771&r2=100772&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/rtti-fundamental.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/rtti-fundamental.cpp Thu Apr  8 10:52:03 2010
@@ -8,8 +8,10 @@
 
 namespace __cxxabiv1 {
   struct __fundamental_type_info {
-    virtual ~__fundamental_type_info() {}
+    virtual ~__fundamental_type_info();
   };
+
+  __fundamental_type_info::~__fundamental_type_info() { }
 }
 
 // CHECK: @_ZTIv = weak_odr constant





More information about the cfe-commits mailing list