[compiler-rt] [llvm] [InstrProf] Add vtables with type metadata into symtab (PR #81051)

David Li via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 11:32:59 PDT 2024


================
@@ -476,11 +476,46 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) {
       return E;
   }
 
+  SmallVector<MDNode *, 2> Types;
+  for (GlobalVariable &G : M.globals()) {
+    if (!G.hasName() || !G.hasMetadata(LLVMContext::MD_type))
+      continue;
+    if (Error E = addVTableWithName(
+              G, getIRPGOObjectName(G, InLTO, /* PGONameMetadata */ nullptr)))
+        return E;
+  }
+
   Sorted = false;
   finalizeSymtab();
   return Error::success();
 }
 
+Error InstrProfSymtab::addVTableWithName(GlobalVariable &VTable,
+                                         StringRef VTablePGOName) {
+
+  auto mapName = [&](StringRef Name) -> Error {
+    // Use 'addSymbolName' rather than 'addVTableName' as 'VTableNames' is
----------------
david-xl wrote:

Perhaps the 'addVTableName' should be renamed to 'addVTableNameForWrite'?

Can the lambda be folded into addSymbolName method ? The method can take an additional bool parameter indicating if MD5VTableMap needs to be updated.

https://github.com/llvm/llvm-project/pull/81051


More information about the llvm-commits mailing list