]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Analysis/SyntheticCountsUtils.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Analysis / SyntheticCountsUtils.h
1 //===- 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
21 namespace llvm {
22
23 class CallGraph;
24 class 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.
31 template <typename CallGraphType> class SyntheticCountsUtils {
32 public:
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
46 private:
47   static void propagateFromSCC(const SccTy &SCC, GetRelBBFreqTy GetRelBBFreq,
48                                GetCountTy GetCount, AddCountTy AddCount);
49 };
50 } // namespace llvm
51
52 #endif