[compiler-rt] [llvm] [TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling. (PR #81691)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 22:45:18 PST 2024


================
@@ -186,13 +207,28 @@ VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
 VALUE_PROF_KIND(IPVK_IndirectCallTarget, 0, "indirect call target")
 /* For memory intrinsic functions size profiling. */
 VALUE_PROF_KIND(IPVK_MemOPSize, 1, "memory intrinsic functions size")
+/* For virtual table address profiling, the address point of the virtual table
+ * (i.e., the address contained in objects pointing to a virtual table) are
+ * profiled. Note this may not be the address of the per C++ class virtual table
+ *  object (e.g., there might be an offset).
+ *
+ * The profiled addresses are stored in raw profile, together with the following
+ * two types of information.
+ * 1. The (starting and ending) addresses of per C++ class virtual table objects.
+ * 2. The (compressed) virtual table object names.
+ * RawInstrProfReader converts profiled virtual table addresses to virtual table
+ *  objects' MD5 hash.
+ */
+VALUE_PROF_KIND(IPVK_VTableTarget, 2, "The address of the compatible vtable (i.e., "
+                                      "there is an offset from this address to per C++ "
+                                      "class virtual table global variable.)")
 /* These two kinds must be the last to be
  * declared. This is to make sure the string
  * array created with the template can be
  * indexed with the kind value.
  */
 VALUE_PROF_KIND(IPVK_First, IPVK_IndirectCallTarget, "first")
-VALUE_PROF_KIND(IPVK_Last, IPVK_MemOPSize, "last")
----------------
minglotus-6 wrote:

Before the change, `IPVK_Last` has the value of `IPVK_MemOPSize`; it's intentional to update `IPVK_Last` to `IPVK_VTableTarget` such that value profiling code path handle the new type of value profile.

More specifically, the raw profile file contains memory dump of struct 
[`__llvm_profile_data`](https://github.com/llvm/llvm-project/blob/118a2a52fd465b7576c54bd102ee2e417a3b9a71/compiler-rt/lib/profile/InstrProfiling.h#L36), and we need the space for [`NumValueSites`](https://github.com/llvm/llvm-project/blob/118a2a52fd465b7576c54bd102ee2e417a3b9a71/compiler-rt/include/profile/InstrProfData.inc#L90) as a raw profile format change, and thereby the need to bump the raw profile version.
* `IPVK_Last` is used in other places besides raw profile format change. These code paths just work out (e.g., `pgo-instr-gen` pass will get an empty instrumented site for the new `IPVK_VTableTarget` kind in its [`ValueSite`](https://github.com/llvm/llvm-project/blob/118a2a52fd465b7576c54bd102ee2e417a3b9a71/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp#L570-L587) but that won't cause correctness problems)

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


More information about the llvm-commits mailing list