Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:17

0001 //===- SyntheticCountsUtils.h - utilities for count propagation--*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines utilities for synthetic counts propagation.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_ANALYSIS_SYNTHETICCOUNTSUTILS_H
0014 #define LLVM_ANALYSIS_SYNTHETICCOUNTSUTILS_H
0015 
0016 #include "llvm/ADT/GraphTraits.h"
0017 #include "llvm/ADT/STLFunctionalExtras.h"
0018 #include "llvm/Support/ScaledNumber.h"
0019 #include <vector>
0020 
0021 namespace llvm {
0022 
0023 /// Class with methods to propagate synthetic entry counts.
0024 ///
0025 /// This class is templated on the type of the call graph and designed to work
0026 /// with the traditional per-module callgraph and the summary callgraphs used in
0027 /// ThinLTO. This contains only static methods and alias templates.
0028 template <typename CallGraphType> class SyntheticCountsUtils {
0029 public:
0030   using Scaled64 = ScaledNumber<uint64_t>;
0031   using CGT = GraphTraits<CallGraphType>;
0032   using NodeRef = typename CGT::NodeRef;
0033   using EdgeRef = typename CGT::EdgeRef;
0034   using SccTy = std::vector<NodeRef>;
0035 
0036   // Not all EdgeRef have information about the source of the edge. Hence
0037   // NodeRef corresponding to the source of the EdgeRef is explicitly passed.
0038   using GetProfCountTy =
0039       function_ref<std::optional<Scaled64>(NodeRef, EdgeRef)>;
0040   using AddCountTy = function_ref<void(NodeRef, Scaled64)>;
0041 
0042   static void propagate(const CallGraphType &CG, GetProfCountTy GetProfCount,
0043                         AddCountTy AddCount);
0044 
0045 private:
0046   static void propagateFromSCC(const SccTy &SCC, GetProfCountTy GetProfCount,
0047                                AddCountTy AddCount);
0048 };
0049 } // namespace llvm
0050 
0051 #endif