[clang-tools-extra] [llvm] [compiler-rt] [clang] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

Mingming Liu via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 15 14:46:17 PST 2023


================
@@ -453,11 +471,94 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) {
     if (Error E = addFuncWithName(F, getPGOFuncName(F, InLTO)))
       return E;
   }
+
+  SmallVector<MDNode *, 2> Types;
+  for (GlobalVariable &G : M.globals()) {
+    if (!G.hasName())
+      continue;
+    Types.clear();
+    G.getMetadata(LLVMContext::MD_type, Types);
+    if (!Types.empty()) {
+      MD5VTableMap.emplace_back(G.getGUID(), &G);
+    }
+  }
   Sorted = false;
   finalizeSymtab();
   return Error::success();
 }
 
+/// \c NameStrings is a string composed of one of more possibly encoded
+/// sub-strings. The substrings are separated by 0 or more zero bytes. This
+/// method decodes the string and calls `NameCallback` for each substring.
+static Error
+readAndDecodeStrings(StringRef NameStrings,
----------------
minglotus-6 wrote:

Good point. Updated InstrProfTest.cpp to have test coverage for the added value type.  There are quite some common code for indirect_call and vtable test coverage, so factor them out. 

I could split the unit-test refactor as a pre-commit of this PR if that's better, but thought to put them here first for the whole picture how they are used.

Test case construction catches an edge case (see the comment in `InstrProfSymtab::getVTableHashFromAddress`), which should be rare at least under Itanium ABI.

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


More information about the cfe-commits mailing list