[llvm] [SampleFDO][TypeProf]Support vtable type profiling for ext-binary and text format (PR #148002)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 21 21:53:26 PDT 2025


================
@@ -197,8 +197,32 @@ enum class LineType {
   CallSiteProfile,
   BodyProfile,
   Metadata,
+  VirtualCallTypeProfile,
 };
 
+// Parse `Input` as a white-space separated list of `vtable:count` pairs. An
+// example input line is `_ZTVbar:1471 _ZTVfoo:630`.
+static bool parseTypeCountMap(StringRef Input,
+                              DenseMap<StringRef, uint64_t> &TypeCountMap) {
+  for (size_t Index = Input.find_first_not_of(' '); Index != StringRef::npos;) {
+    size_t n1 = Input.find(':', Index);
+    if (n1 == StringRef::npos)
+      return false; // No colon found, invalid format.
----------------
mingmingl-llvm wrote:

I took another look at this. It turns out there is quite a few early returns in [ParseLine](https://github.com/llvm/llvm-project/blob/6a7ade03d1fced72bbe25cb3cf9efde8c928e563/llvm/lib/ProfileData/SampleProfReader.cpp#L214-L317) function and its callee `parseMetadata` [1]. While returning `createStringError('specific error message')` makes debugging easier, the code looks a bit lengthy. So I took the liberty to prepare NFC https://github.com/llvm/llvm-project/pull/154885 to report errors based on LineType. After the NFC change is in, I can extend the switch to report a specific error for vtable lines. lmk your thoughts and I'd be glad to follow up!

[1]

https://github.com/llvm/llvm-project/blob/6a7ade03d1fced72bbe25cb3cf9efde8c928e563/llvm/lib/ProfileData/SampleProfReader.cpp#L181-L194

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


More information about the llvm-commits mailing list