IndirectCallPromotionAnalysis.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- IndirectCallPromotionAnalysis.h - Indirect call analysis -*- 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. /// \file
  14. /// Interface to identify indirect call promotion candidates.
  15. ///
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
  18. #define LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
  19. #include "llvm/ProfileData/InstrProf.h"
  20. namespace llvm {
  21. class Instruction;
  22. // Class for identifying profitable indirect call promotion candidates when
  23. // the indirect-call value profile metadata is available.
  24. class ICallPromotionAnalysis {
  25. private:
  26. // Allocate space to read the profile annotation.
  27. std::unique_ptr<InstrProfValueData[]> ValueDataArray;
  28. // Count is the call count for the direct-call target.
  29. // TotalCount is the total call count for the indirect-call callsite.
  30. // RemainingCount is the TotalCount minus promoted-direct-call count.
  31. // Return true we should promote this indirect-call target.
  32. bool isPromotionProfitable(uint64_t Count, uint64_t TotalCount,
  33. uint64_t RemainingCount);
  34. // Returns the number of profitable candidates to promote for the
  35. // current ValueDataArray and the given \p Inst.
  36. uint32_t getProfitablePromotionCandidates(const Instruction *Inst,
  37. uint32_t NumVals,
  38. uint64_t TotalCount);
  39. // Noncopyable
  40. ICallPromotionAnalysis(const ICallPromotionAnalysis &other) = delete;
  41. ICallPromotionAnalysis &
  42. operator=(const ICallPromotionAnalysis &other) = delete;
  43. public:
  44. ICallPromotionAnalysis();
  45. /// Returns reference to array of InstrProfValueData for the given
  46. /// instruction \p I.
  47. ///
  48. /// The \p NumVals, \p TotalCount and \p NumCandidates
  49. /// are set to the number of values in the array, the total profile count
  50. /// of the indirect call \p I, and the number of profitable candidates
  51. /// in the given array (which is sorted in reverse order of profitability).
  52. ///
  53. /// The returned array space is owned by this class, and overwritten on
  54. /// subsequent calls.
  55. ArrayRef<InstrProfValueData>
  56. getPromotionCandidatesForInstruction(const Instruction *I, uint32_t &NumVals,
  57. uint64_t &TotalCount,
  58. uint32_t &NumCandidates);
  59. };
  60. } // end namespace llvm
  61. #endif
  62. #ifdef __GNUC__
  63. #pragma GCC diagnostic pop
  64. #endif