[cfe-commits] r90681 - /cfe/trunk/lib/CodeGen/CGVtable.cpp

Anders Carlsson andersca at mac.com
Sat Dec 5 14:42:55 PST 2009


Author: andersca
Date: Sat Dec  5 16:42:54 2009
New Revision: 90681

URL: http://llvm.org/viewvc/llvm-project?rev=90681&view=rev
Log:
Only emit the vtable definition if the class has a key function and we're emitting it, or if the class doesn't have a key function and we are emitting the complete constructor.

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

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Sat Dec  5 16:42:54 2009
@@ -1388,27 +1388,11 @@
 }
 
 llvm::Constant *CGVtableInfo::getVtable(const CXXRecordDecl *RD) {
-  llvm::Constant *&vtbl = Vtables[RD];
-  if (vtbl)
-    return vtbl;
-  vtbl = CGM.GenerateVtable(RD, RD);
+  llvm::Constant *&Vtable = Vtables[RD];
+  if (!Vtable)
+    Vtable = CGM.GenerateVtable(RD, RD);
 
-  bool CreateDefinition = true;
-
-  const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
-  if (const CXXMethodDecl *KeyFunction = Layout.getKeyFunction()) {
-    if (!KeyFunction->getBody()) {
-      // If there is a KeyFunction, and it isn't defined, just build a
-      // reference to the vtable.
-      CreateDefinition = false;
-    }
-  }
-
-  if (CreateDefinition) {
-    CGM.GenerateRTTI(RD);
-    CGM.GenerateVTT(RD);
-  }
-  return vtbl;
+  return Vtable;
 }
 
 llvm::Constant *CGVtableInfo::getCtorVtable(const CXXRecordDecl *LayoutClass,
@@ -1421,25 +1405,31 @@
   const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
   const CXXRecordDecl *RD = MD->getParent();
 
+  // If the class doesn't have a vtable we don't need to emit one.
+  if (!RD->isDynamicClass())
+    return;
+  
   const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
   
   // Get the key function.
   const CXXMethodDecl *KeyFunction = Layout.getKeyFunction();
   
-  if (!KeyFunction) {
-    // If there's no key function, we don't want to emit the vtable here.
-    return;
+  if (KeyFunction) {
+    // We don't have the right key function.
+    if (KeyFunction->getCanonicalDecl() != MD->getCanonicalDecl())
+      return;
+    
+    // If the key function is a destructor, we only want to emit the vtable 
+    // once, so do it for the complete destructor.
+    if (isa<CXXDestructorDecl>(MD) && GD.getDtorType() != Dtor_Complete)
+      return;
+  } else {
+    // If there is no key function, we only want to emit the vtable if we are
+    // emitting a constructor.
+    if (!isa<CXXConstructorDecl>(MD) || GD.getCtorType() != Ctor_Complete)
+      return;
   }
 
-  // Check if we have the key function.
-  if (KeyFunction->getCanonicalDecl() != MD->getCanonicalDecl())
-    return;
-  
-  // If the key function is a destructor, we only want to emit the vtable once,
-  // so do it for the complete destructor.
-  if (isa<CXXDestructorDecl>(MD) && GD.getDtorType() != Dtor_Complete)
-    return;
-
   // Emit the data.
   GenerateClassData(RD);
 }





More information about the cfe-commits mailing list