1 //===- SyntheticCountsUtils.h - utilities for count propagation--*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines utilities for synthetic counts propagation.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_SYNTHETIC_COUNTS_UTILS_H
15 #define LLVM_ANALYSIS_SYNTHETIC_COUNTS_UTILS_H
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/Analysis/CallGraph.h"
19 #include "llvm/Support/ScaledNumber.h"
26 /// Class with methods to propagate synthetic entry counts.
28 /// This class is templated on the type of the call graph and designed to work
29 /// with the traditional per-module callgraph and the summary callgraphs used in
30 /// ThinLTO. This contains only static methods and alias templates.
31 template <typename CallGraphType> class SyntheticCountsUtils {
33 using Scaled64 = ScaledNumber<uint64_t>;
34 using CGT = GraphTraits<CallGraphType>;
35 using NodeRef = typename CGT::NodeRef;
36 using EdgeRef = typename CGT::EdgeRef;
37 using SccTy = std::vector<NodeRef>;
39 using GetRelBBFreqTy = function_ref<Optional<Scaled64>(EdgeRef)>;
40 using GetCountTy = function_ref<uint64_t(NodeRef)>;
41 using AddCountTy = function_ref<void(NodeRef, uint64_t)>;
43 static void propagate(const CallGraphType &CG, GetRelBBFreqTy GetRelBBFreq,
44 GetCountTy GetCount, AddCountTy AddCount);
47 static void propagateFromSCC(const SccTy &SCC, GetRelBBFreqTy GetRelBBFreq,
48 GetCountTy GetCount, AddCountTy AddCount);