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

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 05:07:56 PDT 2024


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

>From 667897082b9eed6d8b6e4873bcd5ffd76092e31c Mon Sep 17 00:00:00 2001
From: Mircea Trofin <mtrofin at google.com>
Date: Mon, 5 Aug 2024 17:07:48 -0700
Subject: [PATCH 1/4] [ctx_prof] CtxProfAnalysis

This is an immutable analysis that loads and makes the contextual profile
available to other passes. This patch just introduces the analysis and
an analysis printer pass. Subsequent patches will introduce the APIs that
IPO passes will call to modify the profile as result of their changes.
---
 llvm/include/llvm/Analysis/CtxProfAnalysis.h | 53 ++++++++++++
 llvm/lib/Analysis/CMakeLists.txt             |  1 +
 llvm/lib/Analysis/CtxProfAnalysis.cpp        | 91 ++++++++++++++++++++
 llvm/lib/Passes/PassBuilder.cpp              |  3 +
 llvm/lib/Passes/PassBuilderPipelines.cpp     |  2 +-
 llvm/lib/Passes/PassRegistry.def             |  2 +
 llvm/test/Analysis/CtxProfAnalysis/load.ll   | 56 ++++++++++++
 7 files changed, 207 insertions(+), 1 deletion(-)
 create mode 100644 llvm/include/llvm/Analysis/CtxProfAnalysis.h
 create mode 100644 llvm/lib/Analysis/CtxProfAnalysis.cpp
 create mode 100644 llvm/test/Analysis/CtxProfAnalysis/load.ll

diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
new file mode 100644
index 0000000000000..dbdbc3a64a0ac
--- /dev/null
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -0,0 +1,53 @@
+//===- CtxProfAnalysis.h - maintain contextual profile info   -*- C++ ---*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+#ifndef LLVM_ANALYSIS_CTXPROFANALYSIS_H
+#define LLVM_ANALYSIS_CTXPROFANALYSIS_H
+
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/ProfileData/PGOCtxProfReader.h"
+#include <map>
+
+namespace llvm {
+class CtxProfAnalysis : public AnalysisInfoMixin<CtxProfAnalysis> {
+  StringRef Profile;
+public:
+  static AnalysisKey Key;
+  explicit CtxProfAnalysis(StringRef Profile) : Profile(Profile) {};
+
+  class Result {
+    std::optional<PGOContextualProfile::CallTargetMapTy> Profiles;
+    public:
+      explicit Result(PGOContextualProfile::CallTargetMapTy &&Profiles)
+          : Profiles(std::move(Profiles)) {}
+      Result() = default;
+      Result(const Result&) = delete;
+      Result(Result &&) = default;
+
+      operator bool() const { return !!Profiles; }
+      const PGOContextualProfile::CallTargetMapTy &profiles() const {
+        return *Profiles;
+      }
+  };
+
+  Result run(Module &M, ModuleAnalysisManager &MAM);
+};
+
+class CtxProfAnalysisPrinterPass
+    : public PassInfoMixin<CtxProfAnalysisPrinterPass> {
+  raw_ostream &OS;
+
+public:
+  explicit CtxProfAnalysisPrinterPass(raw_ostream &OS) : OS(OS) {}
+
+  PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
+  static bool isRequired() { return true; }
+};
+} // namespace llvm
+#endif // LLVM_ANALYSIS_CTXPROFANALYSIS_H
diff --git a/llvm/lib/Analysis/CMakeLists.txt b/llvm/lib/Analysis/CMakeLists.txt
index 997bb7a0bb178..2cb3547ec4047 100644
--- a/llvm/lib/Analysis/CMakeLists.txt
+++ b/llvm/lib/Analysis/CMakeLists.txt
@@ -46,6 +46,7 @@ add_llvm_component_library(LLVMAnalysis
   CostModel.cpp
   CodeMetrics.cpp
   ConstantFolding.cpp
+  CtxProfAnalysis.cpp
   CycleAnalysis.cpp
   DDG.cpp
   DDGPrinter.cpp
diff --git a/llvm/lib/Analysis/CtxProfAnalysis.cpp b/llvm/lib/Analysis/CtxProfAnalysis.cpp
new file mode 100644
index 0000000000000..0ac67ac863ee2
--- /dev/null
+++ b/llvm/lib/Analysis/CtxProfAnalysis.cpp
@@ -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/MemoryBuffer.h"
+#include "llvm/Support/JSON.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) {
+      CSites.push_back(Array());
+      Array &Targets = *CSites.back().getAsArray();
+      if (P.hasCallsite(I))
+        for (const auto &[_, Ctx] : P.callsite(I))
+          Targets.push_back(toJSON(Ctx));
+    }
+    Ret["Callsites"] = std::move(CSites);
+  }
+  return Ret;
+}
+
+Value toJSON(const PGOContextualProfile::CallTargetMapTy &P) { 
+  Array Ret;
+  for (const auto &[_, Ctx] : P)
+    Ret.push_back(toJSON(Ctx));
+  return Ret;
+}
+} // namespace json
+} // namespace llvm
+
+using namespace llvm;
+#define DEBUG_TYPE "ctx_prof"
+
+AnalysisKey CtxProfAnalysis::Key;
+
+CtxProfAnalysis::Result CtxProfAnalysis::run(Module &M,
+                                             ModuleAnalysisManager &MAM) {
+  ErrorOr<std::unique_ptr<MemoryBuffer>> MB = MemoryBuffer::getFile(Profile);
+  if (auto EC = MB.getError()) {
+    M.getContext().emitError("could not open contextual profile file: " +
+                             EC.message());
+    return {};
+  }
+  PGOCtxProfileReader Reader(MB.get()->getBuffer());
+  auto MaybeCtx = Reader.loadContexts();
+  if (!MaybeCtx) {
+    M.getContext().emitError("contextual profile file is invalid: " +
+                             toString(MaybeCtx.takeError()));
+    return {};
+  }
+  return Result(std::move(*MaybeCtx));
+}
+
+PreservedAnalyses CtxProfAnalysisPrinterPass::run(Module &M,
+                                                  ModuleAnalysisManager &MAM) {
+  CtxProfAnalysis::Result &C = MAM.getResult<CtxProfAnalysis>(M);
+  if (!C) {
+    M.getContext().emitError("Invalid CtxProfAnalysis");
+    return PreservedAnalyses::all();
+  }
+  const auto JSONed = ::llvm::json::toJSON(C.profiles());
+  
+  OS << formatv("{0:2}", JSONed);
+  OS << "\n";
+  return PreservedAnalyses::all();
+}
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 5dbb1e2f49871..bcc69d5ac3db6 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -28,6 +28,7 @@
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Analysis/CallPrinter.h"
 #include "llvm/Analysis/CostModel.h"
+#include "llvm/Analysis/CtxProfAnalysis.h"
 #include "llvm/Analysis/CycleAnalysis.h"
 #include "llvm/Analysis/DDG.h"
 #include "llvm/Analysis/DDGPrinter.h"
@@ -330,6 +331,8 @@ cl::opt<bool> PrintPipelinePasses(
              "(best-effort only)."));
 } // namespace llvm
 
+extern cl::opt<std::string> UseCtxProfile;
+
 AnalysisKey NoOpModuleAnalysis::Key;
 AnalysisKey NoOpCGSCCAnalysis::Key;
 AnalysisKey NoOpFunctionAnalysis::Key;
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index adebbb5eeba32..c175ee8980984 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -304,7 +304,7 @@ static cl::opt<bool> UseLoopVersioningLICM(
     "enable-loop-versioning-licm", cl::init(false), cl::Hidden,
     cl::desc("Enable the experimental Loop Versioning LICM pass"));
 
-static cl::opt<std::string>
+cl::opt<std::string>
     UseCtxProfile("use-ctx-profile", cl::init(""), cl::Hidden,
                   cl::desc("Use the specified contextual profile file"));
 
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 3b92823cd283b..2365ca4d3d88a 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -20,6 +20,7 @@
 #endif
 MODULE_ANALYSIS("callgraph", CallGraphAnalysis())
 MODULE_ANALYSIS("collector-metadata", CollectorMetadataAnalysis())
+MODULE_ANALYSIS("ctx-prof-analysis", CtxProfAnalysis(UseCtxProfile))
 MODULE_ANALYSIS("inline-advisor", InlineAdvisorAnalysis())
 MODULE_ANALYSIS("ir-similarity", IRSimilarityAnalysis())
 MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis())
@@ -79,6 +80,7 @@ MODULE_PASS("insert-gcov-profiling", GCOVProfilerPass())
 MODULE_PASS("instrorderfile", InstrOrderFilePass())
 MODULE_PASS("instrprof", InstrProfilingLoweringPass())
 MODULE_PASS("ctx-instr-lower", PGOCtxProfLoweringPass())
+MODULE_PASS("print<ctx-prof-analysis>", CtxProfAnalysisPrinterPass(dbgs()))
 MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
 MODULE_PASS("iroutliner", IROutlinerPass())
 MODULE_PASS("jmc-instrumenter", JMCInstrumenterPass())
diff --git a/llvm/test/Analysis/CtxProfAnalysis/load.ll b/llvm/test/Analysis/CtxProfAnalysis/load.ll
new file mode 100644
index 0000000000000..fdf40d1b7f136
--- /dev/null
+++ b/llvm/test/Analysis/CtxProfAnalysis/load.ll
@@ -0,0 +1,56 @@
+; RUN: split-file %s %t
+; RUN: llvm-ctxprof-util fromJSON --input=%t/profile.json --output=%t/profile.ctxprofdata
+; RUN: not opt -passes='require<ctx-prof-analysis>,print<ctx-prof-analysis>' \
+; RUN:   %t/empty.ll -S 2>&1 | FileCheck %s --check-prefix=NO-FILE
+
+; RUN: not opt -passes='require<ctx-prof-analysis>,print<ctx-prof-analysis>' \
+; RUN:   -use-ctx-profile=does_not_exist.ctxprofdata %t/empty.ll -S 2>&1 | FileCheck %s --check-prefix=NO-FILE
+
+; RUN: opt -passes='require<ctx-prof-analysis>,print<ctx-prof-analysis>' \
+; RUN:   -use-ctx-profile=%t/profile.ctxprofdata %t/empty.ll -S 2> %t/output.json
+; RUN: diff %t/profile.json %t/output.json
+
+; NO-FILE: error: could not open contextual profile file
+;
+; This is the reference profile, laid out in the format the json formatter will
+; output it from opt.
+;--- profile.json
+[
+  {
+    "Callsites": [
+      [],
+      [
+        {
+          "Counters": [
+            4,
+            5
+          ],
+          "Guid": 2000
+        },
+        {
+          "Counters": [
+            6,
+            7,
+            8
+          ],
+          "Guid": 18446744073709551613
+        }
+      ]
+    ],
+    "Counters": [
+      1,
+      2,
+      3
+    ],
+    "Guid": 1000
+  },
+  {
+    "Counters": [
+      5,
+      9,
+      10
+    ],
+    "Guid": 18446744073709551612
+  }
+]
+;--- empty.ll

>From 3ecd4d0be2d57df4e49cbd37416457edd31765a2 Mon Sep 17 00:00:00 2001
From: Mircea Trofin <mtrofin at google.com>
Date: Tue, 6 Aug 2024 06:59:38 -0700
Subject: [PATCH 2/4] clang-format

---
 llvm/include/llvm/Analysis/CtxProfAnalysis.h | 24 +++++++++++---------
 llvm/lib/Analysis/CtxProfAnalysis.cpp        |  8 +++----
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index dbdbc3a64a0ac..d942d8ca7e000 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -17,23 +17,25 @@
 namespace llvm {
 class CtxProfAnalysis : public AnalysisInfoMixin<CtxProfAnalysis> {
   StringRef Profile;
+
 public:
   static AnalysisKey Key;
   explicit CtxProfAnalysis(StringRef Profile) : Profile(Profile) {};
 
   class Result {
     std::optional<PGOContextualProfile::CallTargetMapTy> Profiles;
-    public:
-      explicit Result(PGOContextualProfile::CallTargetMapTy &&Profiles)
-          : Profiles(std::move(Profiles)) {}
-      Result() = default;
-      Result(const Result&) = delete;
-      Result(Result &&) = default;
-
-      operator bool() const { return !!Profiles; }
-      const PGOContextualProfile::CallTargetMapTy &profiles() const {
-        return *Profiles;
-      }
+
+  public:
+    explicit Result(PGOContextualProfile::CallTargetMapTy &&Profiles)
+        : Profiles(std::move(Profiles)) {}
+    Result() = default;
+    Result(const Result &) = delete;
+    Result(Result &&) = default;
+
+    operator bool() const { return !!Profiles; }
+    const PGOContextualProfile::CallTargetMapTy &profiles() const {
+      return *Profiles;
+    }
   };
 
   Result run(Module &M, ModuleAnalysisManager &MAM);
diff --git a/llvm/lib/Analysis/CtxProfAnalysis.cpp b/llvm/lib/Analysis/CtxProfAnalysis.cpp
index 0ac67ac863ee2..851b7b65c6112 100644
--- a/llvm/lib/Analysis/CtxProfAnalysis.cpp
+++ b/llvm/lib/Analysis/CtxProfAnalysis.cpp
@@ -17,12 +17,12 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/ProfileData/PGOCtxProfReader.h"
-#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/JSON.h"
+#include "llvm/Support/MemoryBuffer.h"
 
 namespace llvm {
 namespace json {
-Value toJSON(const PGOContextualProfile &P) { 
+Value toJSON(const PGOContextualProfile &P) {
   Object Ret;
   Ret["Guid"] = P.guid();
   Ret["Counters"] = Array(P.counters());
@@ -44,7 +44,7 @@ Value toJSON(const PGOContextualProfile &P) {
   return Ret;
 }
 
-Value toJSON(const PGOContextualProfile::CallTargetMapTy &P) { 
+Value toJSON(const PGOContextualProfile::CallTargetMapTy &P) {
   Array Ret;
   for (const auto &[_, Ctx] : P)
     Ret.push_back(toJSON(Ctx));
@@ -84,7 +84,7 @@ PreservedAnalyses CtxProfAnalysisPrinterPass::run(Module &M,
     return PreservedAnalyses::all();
   }
   const auto JSONed = ::llvm::json::toJSON(C.profiles());
-  
+
   OS << formatv("{0:2}", JSONed);
   OS << "\n";
   return PreservedAnalyses::all();

>From 6785fb0093e32b0f6ef7efa972790dc5ddb8d775 Mon Sep 17 00:00:00 2001
From: Mircea Trofin <mtrofin at google.com>
Date: Wed, 7 Aug 2024 04:44:52 -0700
Subject: [PATCH 3/4] comments

---
 llvm/include/llvm/Analysis/CtxProfAnalysis.h |  2 +-
 llvm/lib/Analysis/CtxProfAnalysis.cpp        | 28 +++++++++++---------
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index d942d8ca7e000..073f54cd66002 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -32,7 +32,7 @@ class CtxProfAnalysis : public AnalysisInfoMixin<CtxProfAnalysis> {
     Result(const Result &) = delete;
     Result(Result &&) = default;
 
-    operator bool() const { return !!Profiles; }
+    operator bool() const { return Profiles.has_value(); }
     const PGOContextualProfile::CallTargetMapTy &profiles() const {
       return *Profiles;
     }
diff --git a/llvm/lib/Analysis/CtxProfAnalysis.cpp b/llvm/lib/Analysis/CtxProfAnalysis.cpp
index 851b7b65c6112..d32a8db78d9b6 100644
--- a/llvm/lib/Analysis/CtxProfAnalysis.cpp
+++ b/llvm/lib/Analysis/CtxProfAnalysis.cpp
@@ -20,27 +20,32 @@
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/MemoryBuffer.h"
 
+#define DEBUG_TYPE "ctx_prof"
+
 namespace llvm {
 namespace json {
 Value toJSON(const PGOContextualProfile &P) {
   Object Ret;
   Ret["Guid"] = P.guid();
   Ret["Counters"] = Array(P.counters());
+  if (P.callsites().empty())
+    return Ret;
   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) {
-      CSites.push_back(Array());
-      Array &Targets = *CSites.back().getAsArray();
-      if (P.hasCallsite(I))
-        for (const auto &[_, Ctx] : P.callsite(I))
-          Targets.push_back(toJSON(Ctx));
-    }
-    Ret["Callsites"] = std::move(CSites);
+  assert(MaxIt != AllCS.end() && "We should have a max value because the "
+                                 "callsites collection is not empty.");
+  Array CSites;
+  // Iterate to, and including, the maximum index.
+  for (auto I = 0U, Max = *MaxIt; I <= Max; ++I) {
+    CSites.push_back(Array());
+    Array &Targets = *CSites.back().getAsArray();
+    if (P.hasCallsite(I))
+      for (const auto &[_, Ctx] : P.callsite(I))
+        Targets.push_back(toJSON(Ctx));
   }
+  Ret["Callsites"] = std::move(CSites);
+
   return Ret;
 }
 
@@ -54,7 +59,6 @@ Value toJSON(const PGOContextualProfile::CallTargetMapTy &P) {
 } // namespace llvm
 
 using namespace llvm;
-#define DEBUG_TYPE "ctx_prof"
 
 AnalysisKey CtxProfAnalysis::Key;
 

>From f423a872e8def18993f3d4b0c875f3780cb05934 Mon Sep 17 00:00:00 2001
From: Mircea Trofin <mtrofin at google.com>
Date: Wed, 7 Aug 2024 05:06:59 -0700
Subject: [PATCH 4/4] Fixed post- branch merge; also moved the `Result` to be a
 standalone class with a nice name.

---
 llvm/include/llvm/Analysis/CtxProfAnalysis.h | 47 +++++++++++++-------
 llvm/lib/Analysis/CtxProfAnalysis.cpp        |  4 +-
 2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index 073f54cd66002..d77c81d03582e 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -15,6 +15,35 @@
 #include <map>
 
 namespace llvm {
+
+class CtxProfAnalysis;
+
+/// The instrumented contextual profile, produced by the CtxProfAnalysis.
+class PGOContextualProfile {
+  std::optional<PGOCtxProfContext::CallTargetMapTy> Profiles;
+
+public:
+  explicit PGOContextualProfile(PGOCtxProfContext::CallTargetMapTy &&Profiles)
+      : Profiles(std::move(Profiles)) {}
+  PGOContextualProfile() = default;
+  PGOContextualProfile(const PGOContextualProfile &) = delete;
+  PGOContextualProfile(PGOContextualProfile &&) = default;
+
+  operator bool() const { return Profiles.has_value(); }
+
+  const PGOCtxProfContext::CallTargetMapTy &profiles() const {
+    return *Profiles;
+  }
+
+  bool invalidate(Module &, const PreservedAnalyses &PA,
+                  ModuleAnalysisManager::Invalidator &) {
+    // Check whether the analysis has been explicitly invalidated. Otherwise,
+    // it's stateless and remains preserved.
+    auto PAC = PA.getChecker<CtxProfAnalysis>();
+    return !PAC.preservedWhenStateless();
+  }
+};
+
 class CtxProfAnalysis : public AnalysisInfoMixin<CtxProfAnalysis> {
   StringRef Profile;
 
@@ -22,23 +51,9 @@ class CtxProfAnalysis : public AnalysisInfoMixin<CtxProfAnalysis> {
   static AnalysisKey Key;
   explicit CtxProfAnalysis(StringRef Profile) : Profile(Profile) {};
 
-  class Result {
-    std::optional<PGOContextualProfile::CallTargetMapTy> Profiles;
-
-  public:
-    explicit Result(PGOContextualProfile::CallTargetMapTy &&Profiles)
-        : Profiles(std::move(Profiles)) {}
-    Result() = default;
-    Result(const Result &) = delete;
-    Result(Result &&) = default;
-
-    operator bool() const { return Profiles.has_value(); }
-    const PGOContextualProfile::CallTargetMapTy &profiles() const {
-      return *Profiles;
-    }
-  };
+  using Result = PGOContextualProfile;
 
-  Result run(Module &M, ModuleAnalysisManager &MAM);
+  PGOContextualProfile run(Module &M, ModuleAnalysisManager &MAM);
 };
 
 class CtxProfAnalysisPrinterPass
diff --git a/llvm/lib/Analysis/CtxProfAnalysis.cpp b/llvm/lib/Analysis/CtxProfAnalysis.cpp
index d32a8db78d9b6..f56f910bd7784 100644
--- a/llvm/lib/Analysis/CtxProfAnalysis.cpp
+++ b/llvm/lib/Analysis/CtxProfAnalysis.cpp
@@ -24,7 +24,7 @@
 
 namespace llvm {
 namespace json {
-Value toJSON(const PGOContextualProfile &P) {
+Value toJSON(const PGOCtxProfContext &P) {
   Object Ret;
   Ret["Guid"] = P.guid();
   Ret["Counters"] = Array(P.counters());
@@ -49,7 +49,7 @@ Value toJSON(const PGOContextualProfile &P) {
   return Ret;
 }
 
-Value toJSON(const PGOContextualProfile::CallTargetMapTy &P) {
+Value toJSON(const PGOCtxProfContext::CallTargetMapTy &P) {
   Array Ret;
   for (const auto &[_, Ctx] : P)
     Ret.push_back(toJSON(Ctx));



More information about the llvm-commits mailing list