[compiler-rt] [llvm] [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 llvm-commits llvm-commits at lists.llvm.org
Wed Nov 1 10:05:01 PDT 2023


================
@@ -560,42 +609,79 @@ Error collectPGOFuncNameStrings(ArrayRef<GlobalVariable *> NameVars,
       NameStrs, compression::zlib::isAvailable() && doCompression, Result);
 }
 
-Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {
+Error collectVTableStrings(ArrayRef<GlobalVariable *> VTables,
+                           std::string &Result, bool doCompression) {
+  std::vector<std::string> VTableNameStrs;
+  for (auto *VTable : VTables) {
+    VTableNameStrs.push_back(getPGOName(*VTable));
+  }
+  return collectGlobalObjectNameStrings(
+      VTableNameStrs, compression::zlib::isAvailable() && doCompression,
+      Result);
+}
+
+instrprof_error decodeAndSplitStrings(
+    const uint8_t *Input, SmallVector<uint8_t, 128> &UncompressedNameStrings,
+    StringRef &NameStrings, uint32_t &Dist, bool &isCompressed) {
+  Dist = 0;
+  const uint8_t *Start = Input;
+  uint32_t UncompressedSizeLen = 0;
+  uint64_t UncompressedSize = decodeULEB128(Start, &UncompressedSizeLen);
+  Start += UncompressedSizeLen;
+  Dist += UncompressedSizeLen;
+  uint32_t CompressedSizeLen = 0;
+  uint64_t CompressedSize = decodeULEB128(Start, &CompressedSizeLen);
+  Start += CompressedSizeLen;
+  Dist += CompressedSizeLen;
+  isCompressed = (CompressedSize != 0);
+  if (isCompressed) {
+    if (!llvm::compression::zlib::isAvailable())
+      return instrprof_error::zlib_unavailable;
+
+    if (Error E = compression::zlib::decompress(ArrayRef(Start, CompressedSize),
+                                                UncompressedNameStrings,
+                                                UncompressedSize)) {
+      consumeError(std::move(E));
+      return instrprof_error::uncompress_failed;
+    }
+    Dist += CompressedSize;
+  } else {
----------------
minglotus-6 wrote:

done.

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


More information about the llvm-commits mailing list