1 //===- IndirectCallPromotionAnalysis.h - Indirect call analysis -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// Interface to identify indirect call promotion candidates.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
15 #define LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
17 #include "llvm/ProfileData/InstrProf.h"
23 // Class for identifying profitable indirect call promotion candidates when
24 // the indirect-call value profile metadata is available.
25 class ICallPromotionAnalysis {
27 // Allocate space to read the profile annotation.
28 std::unique_ptr<InstrProfValueData[]> ValueDataArray;
30 // Count is the call count for the direct-call target.
31 // TotalCount is the total call count for the indirect-call callsite.
32 // RemainingCount is the TotalCount minus promoted-direct-call count.
33 // Return true we should promote this indirect-call target.
34 bool isPromotionProfitable(uint64_t Count, uint64_t TotalCount,
35 uint64_t RemainingCount);
37 // Returns the number of profitable candidates to promote for the
38 // current ValueDataArray and the given \p Inst.
39 uint32_t getProfitablePromotionCandidates(const Instruction *Inst,
44 ICallPromotionAnalysis(const ICallPromotionAnalysis &other) = delete;
45 ICallPromotionAnalysis &
46 operator=(const ICallPromotionAnalysis &other) = delete;
49 ICallPromotionAnalysis();
51 /// \brief Returns reference to array of InstrProfValueData for the given
54 /// The \p NumVals, \p TotalCount and \p NumCandidates
55 /// are set to the number of values in the array, the total profile count
56 /// of the indirect call \p I, and the number of profitable candidates
57 /// in the given array (which is sorted in reverse order of profitability).
59 /// The returned array space is owned by this class, and overwritten on
61 ArrayRef<InstrProfValueData>
62 getPromotionCandidatesForInstruction(const Instruction *I, uint32_t &NumVals,
64 uint32_t &NumCandidates);
67 } // end namespace llvm