[cfe-commits] r129250 - /cfe/trunk/lib/CodeGen/CGVTables.cpp

Anders Carlsson andersca at mac.com
Sun Apr 10 10:42:45 PDT 2011


Author: andersca
Date: Sun Apr 10 12:42:45 2011
New Revision: 129250

URL: http://llvm.org/viewvc/llvm-project?rev=129250&view=rev
Log:
Make -fdump-vtable-layouts also dump vtable indices for all virtual member functions in the class.

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

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=129250&r1=129249&r2=129250&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Sun Apr 10 12:42:45 2011
@@ -2254,9 +2254,51 @@
       }
       
       Out << '\n';
+    }
+  }
+
+  // Compute the vtable indices for all the member functions.
+  // Store them in a map keyed by the index so we'll get a sorted table.
+  std::map<uint64_t, std::string> IndicesMap;
+
+  for (CXXRecordDecl::method_iterator i = MostDerivedClass->method_begin(),
+       e = MostDerivedClass->method_end(); i != e; ++i) {
+    const CXXMethodDecl *MD = *i;
+    
+    // We only want virtual member functions.
+    if (!MD->isVirtual())
+      continue;
 
+    std::string MethodName =
+      PredefinedExpr::ComputeName(PredefinedExpr::PrettyFunctionNoVirtual,
+                                  MD);
+
+    if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
+      IndicesMap[VTables.getMethodVTableIndex(GlobalDecl(DD, Dtor_Complete))] =
+        MethodName + " [complete]";
+      IndicesMap[VTables.getMethodVTableIndex(GlobalDecl(DD, Dtor_Deleting))] =
+        MethodName + " [deleting]";
+    } else {
+      IndicesMap[VTables.getMethodVTableIndex(MD)] = MethodName;
+    }
+  }
+
+  // Print the vtable indices for all the member functions.
+  if (!IndicesMap.empty()) {
+    Out << "VTable indices for '";
+    Out << MostDerivedClass->getQualifiedNameAsString();
+    Out << "' (" << IndicesMap.size() << " entries).\n";
+
+    for (std::map<uint64_t, std::string>::const_iterator I = IndicesMap.begin(),
+         E = IndicesMap.end(); I != E; ++I) {
+      uint64_t VTableIndex = I->first;
+      const std::string &MethodName = I->second;
+
+      Out << llvm::format(" %4u | ", VTableIndex) << MethodName << '\n';
     }
   }
+
+  Out << '\n';
 }
   
 }





More information about the cfe-commits mailing list