1 //===- IndirectCallPromotionAnalysis.h - Indirect call analysis -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 /// Interface to identify indirect call promotion candidates.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
14 #define LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
16 #include "llvm/ProfileData/InstrProf.h"
22 // Class for identifying profitable indirect call promotion candidates when
23 // the indirect-call value profile metadata is available.
24 class ICallPromotionAnalysis
{
26 // Allocate space to read the profile annotation.
27 std::unique_ptr
<InstrProfValueData
[]> ValueDataArray
;
29 // Count is the call count for the direct-call target.
30 // TotalCount is the total call count for the indirect-call callsite.
31 // RemainingCount is the TotalCount minus promoted-direct-call count.
32 // Return true we should promote this indirect-call target.
33 bool isPromotionProfitable(uint64_t Count
, uint64_t TotalCount
,
34 uint64_t RemainingCount
);
36 // Returns the number of profitable candidates to promote for the
37 // current ValueDataArray and the given \p Inst.
38 uint32_t getProfitablePromotionCandidates(const Instruction
*Inst
,
43 ICallPromotionAnalysis(const ICallPromotionAnalysis
&other
) = delete;
44 ICallPromotionAnalysis
&
45 operator=(const ICallPromotionAnalysis
&other
) = delete;
48 ICallPromotionAnalysis();
50 /// Returns reference to array of InstrProfValueData for the given
53 /// The \p NumVals, \p TotalCount and \p NumCandidates
54 /// are set to the number of values in the array, the total profile count
55 /// of the indirect call \p I, and the number of profitable candidates
56 /// in the given array (which is sorted in reverse order of profitability).
58 /// The returned array space is owned by this class, and overwritten on
60 ArrayRef
<InstrProfValueData
>
61 getPromotionCandidatesForInstruction(const Instruction
*I
, uint32_t &NumVals
,
63 uint32_t &NumCandidates
);
66 } // end namespace llvm