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 SmallVector<InstrProfValueData, 4> 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 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() = default; 48 49 /// 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 MutableArrayRef<InstrProfValueData> getPromotionCandidatesForInstruction( 60 const Instruction *I, uint64_t &TotalCount, uint32_t &NumCandidates); 61 }; 62 63 } // end namespace llvm 64 65 #endif 66