[llvm] [ctxprof] dump profiles using yaml (for testing) (PR #123108)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 13:52:47 PST 2025


================
@@ -176,3 +180,87 @@ PGOCtxProfileReader::loadContexts() {
   }
   return std::move(Ret);
 }
+
+namespace {
+// We want to pass `const` values PGOCtxProfContext references to the yaml
+// converter, and the regular yaml mapping APIs are designed to handle both
+// serialization and deserialization, which prevents using const for
+// serialization. Using an intermediate datastructure is overkill, both
+// space-wise and design complexity-wise. Instead, we use the lower-level APIs.
+void toYaml(yaml::Output &Out, const PGOCtxProfContext &Ctx);
+
+void toYaml(yaml::Output &Out,
+            const PGOCtxProfContext::CallTargetMapTy &CallTargets) {
+  Out.beginSequence();
+  size_t Index = 0;
+  void *SaveData = nullptr;
+  for (const auto &[_, Ctx] : CallTargets) {
+    Out.preflightElement(Index++, SaveData);
+    toYaml(Out, Ctx);
+    Out.postflightElement(nullptr);
+  }
+  Out.endSequence();
+}
+
+void toYaml(yaml::Output &Out,
+            const PGOCtxProfContext::CallsiteMapTy &Callsites) {
+  auto AllCS =
+      ::llvm::map_range(Callsites, [](const auto &P) { return P.first; });
----------------
mtrofin wrote:

yes, nice! thanks.

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


More information about the llvm-commits mailing list