SyntheticCountsUtils.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_SYNTHETIC_COUNTS_UTILS_H
  18. #define LLVM_ANALYSIS_SYNTHETIC_COUNTS_UTILS_H
  19. #include "llvm/ADT/STLExtras.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 = function_ref<Optional<Scaled64>(NodeRef, EdgeRef)>;
  38. using AddCountTy = function_ref<void(NodeRef, Scaled64)>;
  39. static void propagate(const CallGraphType &CG, GetProfCountTy GetProfCount,
  40. AddCountTy AddCount);
  41. private:
  42. static void propagateFromSCC(const SccTy &SCC, GetProfCountTy GetProfCount,
  43. AddCountTy AddCount);
  44. };
  45. } // namespace llvm
  46. #endif
  47. #ifdef __GNUC__
  48. #pragma GCC diagnostic pop
  49. #endif