[llvm] [ProfileData] Clean up validateRecord (PR #95488)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 14 09:05:25 PDT 2024


================
@@ -1035,16 +1035,13 @@ static const char *ValueProfKindStr[] = {
 
 Error InstrProfWriter::validateRecord(const InstrProfRecord &Func) {
   for (uint32_t VK = 0; VK <= IPVK_Last; VK++) {
-    uint32_t NS = Func.getNumValueSites(VK);
-    if (!NS)
+    if (VK == IPVK_IndirectCallTarget || VK == IPVK_VTableTarget)
       continue;
+    uint32_t NS = Func.getNumValueSites(VK);
     for (uint32_t S = 0; S < NS; S++) {
-      uint32_t ND = Func.getNumValueDataForSite(VK, S);
-      std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S);
       DenseSet<uint64_t> SeenValues;
-      for (uint32_t I = 0; I < ND; I++)
-        if ((VK != IPVK_IndirectCallTarget && VK != IPVK_VTableTarget) &&
----------------
minglotus-6 wrote:

For `IPVK_VTableTarget`, a heuristic is used to find vtables in instrumented binary (https://github.com/llvm/llvm-project/blob/2d9b6a01c7a77ee76a5c279901bca1659a550499/llvm/include/llvm/Analysis/IndirectCallVisitor.h#L45-L57), so runtime address of non-vtables can be collected.
* https://gcc.godbolt.org/z/ddMfrWaYd is an example from [rfc](https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600#pick-instrumentation-points-and-instrument-runtime-types-7).The heuristic can find the IR sequence but it's not vtable.
* `InstrProfRecord::remapValue` will map such runtime address to zero. It should be rare for symbol GUID to be zero; in the rare case it happens, the profile use in ICP pass gates de-virtualization by comparing object pointers with vtables for correctness.



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


More information about the llvm-commits mailing list