CodeLayout.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. using EdgeT = std::pair<uint64_t, uint64_t>;
  24. using EdgeCountT = std::pair<EdgeT, uint64_t>;
  25. /// Find a layout of nodes (basic blocks) of a given CFG optimizing jump
  26. /// locality and thus processor I-cache utilization. This is achieved via
  27. /// increasing the number of fall-through jumps and co-locating frequently
  28. /// executed nodes together.
  29. /// The nodes are assumed to be indexed by integers from [0, |V|) so that the
  30. /// current order is the identity permutation.
  31. /// \p NodeSizes: The sizes of the nodes (in bytes).
  32. /// \p NodeCounts: The execution counts of the nodes in the profile.
  33. /// \p EdgeCounts: The execution counts of every edge (jump) in the profile. The
  34. /// map also defines the edges in CFG and should include 0-count edges.
  35. /// \returns The best block order found.
  36. std::vector<uint64_t>
  37. applyExtTspLayout(const std::vector<uint64_t> &NodeSizes,
  38. const std::vector<uint64_t> &NodeCounts,
  39. const std::vector<EdgeCountT> &EdgeCounts);
  40. /// Estimate the "quality" of a given node order in CFG. The higher the score,
  41. /// the better the order is. The score is designed to reflect the locality of
  42. /// the given order, which is anti-correlated with the number of I-cache misses
  43. /// in a typical execution of the function.
  44. double calcExtTspScore(const std::vector<uint64_t> &Order,
  45. const std::vector<uint64_t> &NodeSizes,
  46. const std::vector<uint64_t> &NodeCounts,
  47. const std::vector<EdgeCountT> &EdgeCounts);
  48. /// Estimate the "quality" of the current node order in CFG.
  49. double calcExtTspScore(const std::vector<uint64_t> &NodeSizes,
  50. const std::vector<uint64_t> &NodeCounts,
  51. const std::vector<EdgeCountT> &EdgeCounts);
  52. } // end namespace llvm
  53. #endif // LLVM_TRANSFORMS_UTILS_CODELAYOUT_H
  54. #ifdef __GNUC__
  55. #pragma GCC diagnostic pop
  56. #endif