blob: 87f4a0100b38901f51f9ee36cbbfe93a7d42dc30 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- SyntheticCountsUtils.h - utilities for count propagation--*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines utilities for synthetic counts propagation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_SYNTHETIC_COUNTS_UTILS_H
15#define LLVM_ANALYSIS_SYNTHETIC_COUNTS_UTILS_H
16
17#include "llvm/ADT/STLExtras.h"
18#include "llvm/Analysis/CallGraph.h"
19#include "llvm/Support/ScaledNumber.h"
20
21namespace llvm {
22
23class CallGraph;
24class Function;
25
26/// Class with methods to propagate synthetic entry counts.
27///
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.
31template <typename CallGraphType> class SyntheticCountsUtils {
32public:
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>;
38
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)>;
42
43 static void propagate(const CallGraphType &CG, GetRelBBFreqTy GetRelBBFreq,
44 GetCountTy GetCount, AddCountTy AddCount);
45
46private:
47 static void propagateFromSCC(const SccTy &SCC, GetRelBBFreqTy GetRelBBFreq,
48 GetCountTy GetCount, AddCountTy AddCount);
49};
50} // namespace llvm
51
52#endif