IndirectCallPromotionAnalysis.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //===- IndirectCallPromotionAnalysis.h - Indirect call analysis -*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. /// \file
  9. /// Interface to identify indirect call promotion candidates.
  10. ///
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
  13. #define LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
  14. #include "llvm/ProfileData/InstrProf.h"
  15. namespace llvm {
  16. class Instruction;
  17. // Class for identifying profitable indirect call promotion candidates when
  18. // the indirect-call value profile metadata is available.
  19. class ICallPromotionAnalysis {
  20. private:
  21. // Allocate space to read the profile annotation.
  22. std::unique_ptr<InstrProfValueData[]> ValueDataArray;
  23. // Count is the call count for the direct-call target.
  24. // TotalCount is the total call count for the indirect-call callsite.
  25. // RemainingCount is the TotalCount minus promoted-direct-call count.
  26. // Return true we should promote this indirect-call target.
  27. bool isPromotionProfitable(uint64_t Count, uint64_t TotalCount,
  28. uint64_t RemainingCount);
  29. // Returns the number of profitable candidates to promote for the
  30. // current ValueDataArray and the given \p Inst.
  31. uint32_t getProfitablePromotionCandidates(const Instruction *Inst,
  32. uint32_t NumVals,
  33. uint64_t TotalCount);
  34. // Noncopyable
  35. ICallPromotionAnalysis(const ICallPromotionAnalysis &other) = delete;
  36. ICallPromotionAnalysis &
  37. operator=(const ICallPromotionAnalysis &other) = delete;
  38. public:
  39. ICallPromotionAnalysis();
  40. /// Returns reference to array of InstrProfValueData for the given
  41. /// instruction \p I.
  42. ///
  43. /// The \p NumVals, \p TotalCount and \p NumCandidates
  44. /// are set to the number of values in the array, the total profile count
  45. /// of the indirect call \p I, and the number of profitable candidates
  46. /// in the given array (which is sorted in reverse order of profitability).
  47. ///
  48. /// The returned array space is owned by this class, and overwritten on
  49. /// subsequent calls.
  50. ArrayRef<InstrProfValueData>
  51. getPromotionCandidatesForInstruction(const Instruction *I, uint32_t &NumVals,
  52. uint64_t &TotalCount,
  53. uint32_t &NumCandidates);
  54. };
  55. } // end namespace llvm
  56. #endif