SyntheticCountsUtils.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- SyntheticCountsUtils.h - utilities for count propagation--*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines utilities for synthetic counts propagation.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_ANALYSIS_SYNTHETICCOUNTSUTILS_H
  18. #define LLVM_ANALYSIS_SYNTHETICCOUNTSUTILS_H
  19. #include "llvm/ADT/STLFunctionalExtras.h"
  20. #include "llvm/Analysis/CallGraph.h"
  21. #include "llvm/Support/ScaledNumber.h"
  22. namespace llvm {
  23. /// Class with methods to propagate synthetic entry counts.
  24. ///
  25. /// This class is templated on the type of the call graph and designed to work
  26. /// with the traditional per-module callgraph and the summary callgraphs used in
  27. /// ThinLTO. This contains only static methods and alias templates.
  28. template <typename CallGraphType> class SyntheticCountsUtils {
  29. public:
  30. using Scaled64 = ScaledNumber<uint64_t>;
  31. using CGT = GraphTraits<CallGraphType>;
  32. using NodeRef = typename CGT::NodeRef;
  33. using EdgeRef = typename CGT::EdgeRef;
  34. using SccTy = std::vector<NodeRef>;
  35. // 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 =
  38. function_ref<std::optional<Scaled64>(NodeRef, EdgeRef)>;
  39. using AddCountTy = function_ref<void(NodeRef, Scaled64)>;
  40. static void propagate(const CallGraphType &CG, GetProfCountTy GetProfCount,
  41. AddCountTy AddCount);
  42. private:
  43. static void propagateFromSCC(const SccTy &SCC, GetProfCountTy GetProfCount,
  44. AddCountTy AddCount);
  45. };
  46. } // namespace llvm
  47. #endif
  48. #ifdef __GNUC__
  49. #pragma GCC diagnostic pop
  50. #endif