Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
14 | pmbaty | 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 | |||
13 | #ifndef LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H |
||
14 | #define LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H |
||
15 | |||
16 | #include "llvm/ProfileData/InstrProf.h" |
||
17 | |||
18 | namespace llvm { |
||
19 | |||
20 | class Instruction; |
||
21 | |||
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 | |||
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); |
||
35 | |||
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, |
||
39 | uint32_t NumVals, |
||
40 | uint64_t TotalCount); |
||
41 | |||
42 | // Noncopyable |
||
43 | ICallPromotionAnalysis(const ICallPromotionAnalysis &other) = delete; |
||
44 | ICallPromotionAnalysis & |
||
45 | operator=(const ICallPromotionAnalysis &other) = delete; |
||
46 | |||
47 | public: |
||
48 | ICallPromotionAnalysis(); |
||
49 | |||
50 | /// Returns reference to array of InstrProfValueData for the given |
||
51 | /// instruction \p I. |
||
52 | /// |
||
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). |
||
57 | /// |
||
58 | /// The returned array space is owned by this class, and overwritten on |
||
59 | /// subsequent calls. |
||
60 | ArrayRef<InstrProfValueData> |
||
61 | getPromotionCandidatesForInstruction(const Instruction *I, uint32_t &NumVals, |
||
62 | uint64_t &TotalCount, |
||
63 | uint32_t &NumCandidates); |
||
64 | }; |
||
65 | |||
66 | } // end namespace llvm |
||
67 | |||
68 | #endif |