1 //===- SyntheticCountsUtils.h - utilities for count propagation--*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines utilities for synthetic counts propagation.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_ANALYSIS_SYNTHETIC_COUNTS_UTILS_H
14 #define LLVM_ANALYSIS_SYNTHETIC_COUNTS_UTILS_H
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/Analysis/CallGraph.h"
18 #include "llvm/Support/ScaledNumber.h"
25 /// Class with methods to propagate synthetic entry counts.
27 /// This class is templated on the type of the call graph and designed to work
28 /// with the traditional per-module callgraph and the summary callgraphs used in
29 /// ThinLTO. This contains only static methods and alias templates.
30 template <typename CallGraphType
> class SyntheticCountsUtils
{
32 using Scaled64
= ScaledNumber
<uint64_t>;
33 using CGT
= GraphTraits
<CallGraphType
>;
34 using NodeRef
= typename
CGT::NodeRef
;
35 using EdgeRef
= typename
CGT::EdgeRef
;
36 using SccTy
= std::vector
<NodeRef
>;
38 // Not all EdgeRef have information about the source of the edge. Hence
39 // NodeRef corresponding to the source of the EdgeRef is explicitly passed.
40 using GetProfCountTy
= function_ref
<Optional
<Scaled64
>(NodeRef
, EdgeRef
)>;
41 using AddCountTy
= function_ref
<void(NodeRef
, Scaled64
)>;
43 static void propagate(const CallGraphType
&CG
, GetProfCountTy GetProfCount
,
47 static void propagateFromSCC(const SccTy
&SCC
, GetProfCountTy GetProfCount
,