• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- IndirectCallPromotionAnalysis.h - Indirect call analysis -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// Interface to identify indirect call promotion candidates.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
15 #define LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
16 
17 #include "llvm/ProfileData/InstrProf.h"
18 
19 namespace llvm {
20 
21 class Instruction;
22 
23 // Class for identifying profitable indirect call promotion candidates when
24 // the indirect-call value profile metadata is available.
25 class ICallPromotionAnalysis {
26 private:
27   // Allocate space to read the profile annotation.
28   std::unique_ptr<InstrProfValueData[]> ValueDataArray;
29 
30   // Count is the call count for the direct-call target and
31   // TotalCount is the call count for the indirect-call callsite.
32   // Return true we should promote this indirect-call target.
33   bool isPromotionProfitable(uint64_t Count, uint64_t TotalCount);
34 
35   // Returns the number of profitable candidates to promote for the
36   // current ValueDataArray and the given \p Inst.
37   uint32_t getProfitablePromotionCandidates(const Instruction *Inst,
38                                             uint32_t NumVals,
39                                             uint64_t TotalCount);
40 
41   // Noncopyable
42   ICallPromotionAnalysis(const ICallPromotionAnalysis &other) = delete;
43   ICallPromotionAnalysis &
44   operator=(const ICallPromotionAnalysis &other) = delete;
45 
46 public:
47   ICallPromotionAnalysis();
48 
49   /// \brief Returns reference to array of InstrProfValueData for the given
50   /// instruction \p I.
51   ///
52   /// The \p NumVals, \p TotalCount and \p NumCandidates
53   /// are set to the number of values in the array, the total profile count
54   /// of the indirect call \p I, and the number of profitable candidates
55   /// in the given array (which is sorted in reverse order of profitability).
56   ///
57   /// The returned array space is owned by this class, and overwritten on
58   /// subsequent calls.
59   ArrayRef<InstrProfValueData>
60   getPromotionCandidatesForInstruction(const Instruction *I, uint32_t &NumVals,
61                                        uint64_t &TotalCount,
62                                        uint32_t &NumCandidates);
63 };
64 
65 } // end namespace llvm
66 
67 #endif
68