[cfe-commits] r83900 - in /cfe/trunk/lib/CodeGen: CGRecordLayoutBuilder.cpp CodeGenTypes.h

Anders Carlsson andersca at mac.com
Mon Oct 12 14:16:22 PDT 2009


Author: andersca
Date: Mon Oct 12 16:16:22 2009
New Revision: 83900

URL: http://llvm.org/viewvc/llvm-project?rev=83900&view=rev
Log:
Store the key function of a record decl inside CGRecordLayout.

Modified:
    cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Mon Oct 12 16:16:22 2009
@@ -326,6 +326,31 @@
 
 }
 
+static const CXXMethodDecl *GetKeyFunction(const RecordDecl *D) {
+  const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D);
+  if (!RD || !RD->isDynamicClass())
+    return 0;
+  
+  for (CXXRecordDecl::method_iterator I = RD->method_begin(), 
+       E = RD->method_end(); I != E; ++I) {
+    const CXXMethodDecl *MD = *I;
+    
+    if (!MD->isVirtual())
+      continue;
+    
+    if (MD->isPure())
+      continue;
+
+    if (MD->getBody())
+      continue;
+
+    // We found it.
+    return MD;
+  }
+  
+  return 0;
+}
+
 CGRecordLayout *
 CGRecordLayoutBuilder::ComputeLayout(CodeGenTypes &Types,
                                      const RecordDecl *D) {
@@ -355,5 +380,7 @@
     Types.addBitFieldInfo(Info.FD, Info.FieldNo, Info.Start, Info.Size);
   }
 
-  return new CGRecordLayout(Ty, Builder.ContainsMemberPointer);
+  const CXXMethodDecl *KeyFunction = GetKeyFunction(D);
+
+  return new CGRecordLayout(Ty, Builder.ContainsMemberPointer, KeyFunction);
 }

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.h Mon Oct 12 16:16:22 2009
@@ -61,9 +61,17 @@
     /// is a member pointer, or a struct that contains a member pointer.
     bool ContainsMemberPointer;
 
+    /// KeyFunction - The key function of the record layout (if one exists),
+    /// which is the first non-pure virtual function that is not inline at the
+    /// point of class definition.
+    /// See http://www.codesourcery.com/public/cxx-abi/abi.html#vague-vtable.
+    const CXXMethodDecl *KeyFunction;
+    
   public:
-    CGRecordLayout(const llvm::Type *T, bool ContainsMemberPointer)
-      : LLVMType(T), ContainsMemberPointer(ContainsMemberPointer) { }
+    CGRecordLayout(const llvm::Type *T, bool ContainsMemberPointer,
+                   const CXXMethodDecl *KeyFunction)
+      : LLVMType(T), ContainsMemberPointer(ContainsMemberPointer),
+        KeyFunction(KeyFunction) { }
 
     /// getLLVMType - Return llvm type associated with this record.
     const llvm::Type *getLLVMType() const {
@@ -74,6 +82,9 @@
       return ContainsMemberPointer;
     }
 
+    const CXXMethodDecl *getKeyFunction() const {
+      return KeyFunction;
+    }
   };
 
 /// CodeGenTypes - This class organizes the cross-module state that is used





More information about the cfe-commits mailing list