1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00
llvm-mirror/include/llvm/Analysis/IndirectCallPromotionAnalysis.h
Dehao Chen 51e33719c4 Separate the ICP total threshold and remaining threshold.
Summary: In the current implementation, isPromotionProfitable only checks if the call count to a direct target is no less than a certain percentage threshold of the remaining call counts that have not been promoted. This causes code size problems when the target count is small but greater than a large portion of remaining counts. E.g. target1 takes 99.9%, while target2 takes 0.1%. Both targets will be promoted and inlined, makes the function size too large, which potentially prevents it from further inlining into its callers. This patch adds another percentage threshold against the total indirect call count. If the target count needs to be no less than both thresholds in order to be promoted speculatively.

Reviewers: davidxl, tejohnson

Reviewed By: tejohnson

Subscribers: sanjoy, llvm-commits

Differential Revision: https://reviews.llvm.org/D35962

llvm-svn: 309345
2017-07-28 01:02:54 +00:00

70 lines
2.6 KiB
C++

//===- IndirectCallPromotionAnalysis.h - Indirect call analysis -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
/// \file
/// Interface to identify indirect call promotion candidates.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
#define LLVM_ANALYSIS_INDIRECTCALLPROMOTIONANALYSIS_H
#include "llvm/ProfileData/InstrProf.h"
namespace llvm {
class Instruction;
// Class for identifying profitable indirect call promotion candidates when
// the indirect-call value profile metadata is available.
class ICallPromotionAnalysis {
private:
// Allocate space to read the profile annotation.
std::unique_ptr<InstrProfValueData[]> ValueDataArray;
// Count is the call count for the direct-call target.
// TotalCount is the total call count for the indirect-call callsite.
// RemainingCount is the TotalCount minus promoted-direct-call count.
// Return true we should promote this indirect-call target.
bool isPromotionProfitable(uint64_t Count, uint64_t TotalCount,
uint64_t RemainingCount);
// Returns the number of profitable candidates to promote for the
// current ValueDataArray and the given \p Inst.
uint32_t getProfitablePromotionCandidates(const Instruction *Inst,
uint32_t NumVals,
uint64_t TotalCount);
// Noncopyable
ICallPromotionAnalysis(const ICallPromotionAnalysis &other) = delete;
ICallPromotionAnalysis &
operator=(const ICallPromotionAnalysis &other) = delete;
public:
ICallPromotionAnalysis();
/// \brief Returns reference to array of InstrProfValueData for the given
/// instruction \p I.
///
/// The \p NumVals, \p TotalCount and \p NumCandidates
/// are set to the number of values in the array, the total profile count
/// of the indirect call \p I, and the number of profitable candidates
/// in the given array (which is sorted in reverse order of profitability).
///
/// The returned array space is owned by this class, and overwritten on
/// subsequent calls.
ArrayRef<InstrProfValueData>
getPromotionCandidatesForInstruction(const Instruction *I, uint32_t &NumVals,
uint64_t &TotalCount,
uint32_t &NumCandidates);
};
} // end namespace llvm
#endif