CodeLayout.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- CodeLayout.h - Code layout/placement algorithms ---------*- 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. /// \file
  15. /// Declares methods and data structures for code layout algorithms.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_TRANSFORMS_UTILS_CODELAYOUT_H
  19. #define LLVM_TRANSFORMS_UTILS_CODELAYOUT_H
  20. #include "llvm/ADT/DenseMap.h"
  21. #include <vector>
  22. namespace llvm {
  23. /// Find a layout of nodes (basic blocks) of a given CFG optimizing jump
  24. /// locality and thus processor I-cache utilization. This is achieved via
  25. /// increasing the number of fall-through jumps and co-locating frequently
  26. /// executed nodes together.
  27. /// The nodes are assumed to be indexed by integers from [0, |V|) so that the
  28. /// current order is the identity permutation.
  29. /// \p NodeSizes: The sizes of the nodes (in bytes).
  30. /// \p NodeCounts: The execution counts of the nodes in the profile.
  31. /// \p EdgeCounts: The execution counts of every edge (jump) in the profile. The
  32. /// map also defines the edges in CFG and should include 0-count edges.
  33. /// \returns The best block order found.
  34. std::vector<uint64_t> applyExtTspLayout(
  35. const std::vector<uint64_t> &NodeSizes,
  36. const std::vector<uint64_t> &NodeCounts,
  37. const DenseMap<std::pair<uint64_t, uint64_t>, uint64_t> &EdgeCounts);
  38. /// Estimate the "quality" of a given node order in CFG. The higher the score,
  39. /// the better the order is. The score is designed to reflect the locality of
  40. /// the given order, which is anti-correlated with the number of I-cache misses
  41. /// in a typical execution of the function.
  42. double calcExtTspScore(
  43. const std::vector<uint64_t> &Order, const std::vector<uint64_t> &NodeSizes,
  44. const std::vector<uint64_t> &NodeCounts,
  45. const DenseMap<std::pair<uint64_t, uint64_t>, uint64_t> &EdgeCounts);
  46. /// Estimate the "quality" of the current node order in CFG.
  47. double calcExtTspScore(
  48. const std::vector<uint64_t> &NodeSizes,
  49. const std::vector<uint64_t> &NodeCounts,
  50. const DenseMap<std::pair<uint64_t, uint64_t>, uint64_t> &EdgeCounts);
  51. } // end namespace llvm
  52. #endif // LLVM_TRANSFORMS_UTILS_CODELAYOUT_H
  53. #ifdef __GNUC__
  54. #pragma GCC diagnostic pop
  55. #endif