[llvm] [Analysis] Delete SyntheticCountUtils (PR #227741)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 07:46:04 PDT 2026
https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/227741
This isn't used anywhere, presumably getting dropped after we deleted much of the rest of the synthetic profile infrastructure.
>From 05d6232df280ed654fcbface33978dd61f659981 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Wed, 30 Sep 2026 14:44:57 +0000
Subject: [PATCH] [Analysis] Delete SyntheticCountUtils
This isn't used anywhere, presumably getting dropped after we deleted
much of the rest of the synthetic profile infrastructure.
---
.../llvm/Analysis/SyntheticCountsUtils.h | 51 ----------
llvm/lib/Analysis/CMakeLists.txt | 1 -
llvm/lib/Analysis/SyntheticCountsUtils.cpp | 97 -------------------
3 files changed, 149 deletions(-)
delete mode 100644 llvm/include/llvm/Analysis/SyntheticCountsUtils.h
delete mode 100644 llvm/lib/Analysis/SyntheticCountsUtils.cpp
diff --git a/llvm/include/llvm/Analysis/SyntheticCountsUtils.h b/llvm/include/llvm/Analysis/SyntheticCountsUtils.h
deleted file mode 100644
index d9a477b72451f..0000000000000
--- a/llvm/include/llvm/Analysis/SyntheticCountsUtils.h
+++ /dev/null
@@ -1,51 +0,0 @@
-//===- SyntheticCountsUtils.h - utilities for count propagation--*- 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines utilities for synthetic counts propagation.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ANALYSIS_SYNTHETICCOUNTSUTILS_H
-#define LLVM_ANALYSIS_SYNTHETICCOUNTSUTILS_H
-
-#include "llvm/ADT/GraphTraits.h"
-#include "llvm/ADT/STLFunctionalExtras.h"
-#include "llvm/Support/ScaledNumber.h"
-#include <vector>
-
-namespace llvm {
-
-/// Class with methods to propagate synthetic entry counts.
-///
-/// This class is templated on the type of the call graph and designed to work
-/// with the traditional per-module callgraph and the summary callgraphs used in
-/// ThinLTO. This contains only static methods and alias templates.
-template <typename CallGraphType> class SyntheticCountsUtils {
-public:
- using Scaled64 = ScaledNumber<uint64_t>;
- using CGT = GraphTraits<CallGraphType>;
- using NodeRef = typename CGT::NodeRef;
- using EdgeRef = typename CGT::EdgeRef;
- using SccTy = std::vector<NodeRef>;
-
- // Not all EdgeRef have information about the source of the edge. Hence
- // NodeRef corresponding to the source of the EdgeRef is explicitly passed.
- using GetProfCountTy =
- function_ref<std::optional<Scaled64>(NodeRef, EdgeRef)>;
- using AddCountTy = function_ref<void(NodeRef, Scaled64)>;
-
- static void propagate(const CallGraphType &CG, GetProfCountTy GetProfCount,
- AddCountTy AddCount);
-
-private:
- static void propagateFromSCC(const SccTy &SCC, GetProfCountTy GetProfCount,
- AddCountTy AddCount);
-};
-} // namespace llvm
-
-#endif
diff --git a/llvm/lib/Analysis/CMakeLists.txt b/llvm/lib/Analysis/CMakeLists.txt
index 73250fc99e5a7..823f1541f80e2 100644
--- a/llvm/lib/Analysis/CMakeLists.txt
+++ b/llvm/lib/Analysis/CMakeLists.txt
@@ -160,7 +160,6 @@ add_llvm_component_library(LLVMAnalysis
StackLifetime.cpp
StackSafetyAnalysis.cpp
StructuralHash.cpp
- SyntheticCountsUtils.cpp
TFLiteUtils.cpp
TargetLibraryInfo.cpp
TargetTransformInfo.cpp
diff --git a/llvm/lib/Analysis/SyntheticCountsUtils.cpp b/llvm/lib/Analysis/SyntheticCountsUtils.cpp
deleted file mode 100644
index 0893452436909..0000000000000
--- a/llvm/lib/Analysis/SyntheticCountsUtils.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-//===--- SyntheticCountsUtils.cpp - synthetic counts propagation utils ---===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines utilities for propagating synthetic counts.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Analysis/SyntheticCountsUtils.h"
-#include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/SCCIterator.h"
-#include "llvm/Analysis/CallGraph.h"
-#include "llvm/IR/ModuleSummaryIndex.h"
-
-using namespace llvm;
-
-// Given an SCC, propagate entry counts along the edge of the SCC nodes.
-template <typename CallGraphType>
-void SyntheticCountsUtils<CallGraphType>::propagateFromSCC(
- const SccTy &SCC, GetProfCountTy GetProfCount, AddCountTy AddCount) {
-
- DenseSet<NodeRef> SCCNodes(llvm::from_range, SCC);
- SmallVector<std::pair<NodeRef, EdgeRef>, 8> SCCEdges, NonSCCEdges;
-
- // Partition the edges coming out of the SCC into those whose destination is
- // in the SCC and the rest.
- for (const auto &Node : SCCNodes) {
- for (auto &E : children_edges<CallGraphType>(Node)) {
- if (SCCNodes.count(CGT::edge_dest(E)))
- SCCEdges.emplace_back(Node, E);
- else
- NonSCCEdges.emplace_back(Node, E);
- }
- }
-
- // For nodes in the same SCC, update the counts in two steps:
- // 1. Compute the additional count for each node by propagating the counts
- // along all incoming edges to the node that originate from within the same
- // SCC and summing them up.
- // 2. Add the additional counts to the nodes in the SCC.
- // This ensures that the order of
- // traversal of nodes within the SCC doesn't affect the final result.
-
- DenseMap<NodeRef, Scaled64> AdditionalCounts;
- for (auto &E : SCCEdges) {
- auto OptProfCount = GetProfCount(E.first, E.second);
- if (!OptProfCount)
- continue;
- auto Callee = CGT::edge_dest(E.second);
- AdditionalCounts[Callee] += *OptProfCount;
- }
-
- // Update the counts for the nodes in the SCC.
- for (auto &Entry : AdditionalCounts)
- AddCount(Entry.first, Entry.second);
-
- // Now update the counts for nodes outside the SCC.
- for (auto &E : NonSCCEdges) {
- auto OptProfCount = GetProfCount(E.first, E.second);
- if (!OptProfCount)
- continue;
- auto Callee = CGT::edge_dest(E.second);
- AddCount(Callee, *OptProfCount);
- }
-}
-
-/// Propgate synthetic entry counts on a callgraph \p CG.
-///
-/// This performs a reverse post-order traversal of the callgraph SCC. For each
-/// SCC, it first propagates the entry counts to the nodes within the SCC
-/// through call edges and updates them in one shot. Then the entry counts are
-/// propagated to nodes outside the SCC. This requires \p GraphTraits
-/// to have a specialization for \p CallGraphType.
-
-template <typename CallGraphType>
-void SyntheticCountsUtils<CallGraphType>::propagate(const CallGraphType &CG,
- GetProfCountTy GetProfCount,
- AddCountTy AddCount) {
- std::vector<SccTy> SCCs;
-
- // Collect all the SCCs.
- for (auto I = scc_begin(CG); !I.isAtEnd(); ++I)
- SCCs.push_back(*I);
-
- // The callgraph-scc needs to be visited in top-down order for propagation.
- // The scc iterator returns the scc in bottom-up order, so reverse the SCCs
- // and call propagateFromSCC.
- for (auto &SCC : reverse(SCCs))
- propagateFromSCC(SCC, GetProfCount, AddCount);
-}
-
-template class llvm::SyntheticCountsUtils<const CallGraph *>;
-template class llvm::SyntheticCountsUtils<ModuleSummaryIndex *>;
More information about the llvm-commits
mailing list