[llvm] [ctx_prof] CtxProfAnalysis (PR #102084)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 09:08:06 PDT 2024


================
@@ -0,0 +1,91 @@
+//===- CtxProfAnalysis.cpp - contextual profile analysis ------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation of the contextual profile analysis, which maintains contextual
+// profiling info through IPO passes.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Analysis/CtxProfAnalysis.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/IR/Analysis.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/ProfileData/PGOCtxProfReader.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace llvm {
+namespace json {
+Value toJSON(const PGOContextualProfile &P) {
+  Object Ret;
+  Ret["Guid"] = P.guid();
+  Ret["Counters"] = Array(P.counters());
+  auto AllCS =
+      ::llvm::map_range(P.callsites(), [](const auto &P) { return P.first; });
+  auto MaxIt = ::llvm::max_element(AllCS);
+  if (MaxIt != AllCS.end()) {
+    Array CSites;
+    // Iterate to, and including, the maximum index.
+    for (auto I = 0U; I <= *MaxIt; ++I) {
----------------
mtrofin wrote:

+1

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


More information about the llvm-commits mailing list