blob: 358f757314ee5a5b1088dfa5d9a31c3d02882e21 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- SyntheticCountsUtils.h - utilities for count propagation--*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8//
9// This file defines utilities for synthetic counts propagation.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_ANALYSIS_SYNTHETIC_COUNTS_UTILS_H
14#define LLVM_ANALYSIS_SYNTHETIC_COUNTS_UTILS_H
15
16#include "llvm/ADT/STLExtras.h"
17#include "llvm/Analysis/CallGraph.h"
18#include "llvm/Support/ScaledNumber.h"
19
20namespace llvm {
21
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010022/// Class with methods to propagate synthetic entry counts.
23///
24/// This class is templated on the type of the call graph and designed to work
25/// with the traditional per-module callgraph and the summary callgraphs used in
26/// ThinLTO. This contains only static methods and alias templates.
27template <typename CallGraphType> class SyntheticCountsUtils {
28public:
29 using Scaled64 = ScaledNumber<uint64_t>;
30 using CGT = GraphTraits<CallGraphType>;
31 using NodeRef = typename CGT::NodeRef;
32 using EdgeRef = typename CGT::EdgeRef;
33 using SccTy = std::vector<NodeRef>;
34
Andrew Walbran16937d02019-10-22 13:54:20 +010035 // Not all EdgeRef have information about the source of the edge. Hence
36 // NodeRef corresponding to the source of the EdgeRef is explicitly passed.
37 using GetProfCountTy = function_ref<Optional<Scaled64>(NodeRef, EdgeRef)>;
38 using AddCountTy = function_ref<void(NodeRef, Scaled64)>;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010039
Andrew Walbran16937d02019-10-22 13:54:20 +010040 static void propagate(const CallGraphType &CG, GetProfCountTy GetProfCount,
41 AddCountTy AddCount);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010042
43private:
Andrew Walbran16937d02019-10-22 13:54:20 +010044 static void propagateFromSCC(const SccTy &SCC, GetProfCountTy GetProfCount,
45 AddCountTy AddCount);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010046};
47} // namespace llvm
48
49#endif