55#define DEBUG_TYPE "pgo-icall-prom"
57STATISTIC(NumOfPGOICallPromotion,
"Number of indirect call promotions.");
58STATISTIC(NumOfPGOICallsites,
"Number of indirect call candidate sites.");
69using VTableAddressPointOffsetValMap =
73struct VirtualCallSiteInfo {
83using VirtualCallSiteTypeInfoMap =
94static std::optional<uint64_t>
102 TypeId && TypeId->getString() == CompatibleType)
116 assert(AddressPointOffset < VTable->getGlobalSize(M.getDataLayout()) &&
117 "Out-of-bound access");
127 return PN->getIncomingBlock(U);
142 "Guaranteed by ICP transformation");
150 UserBB = getUserBasicBlock(
Use, UserInst);
153 if (UserBB != DestBB)
156 return UserBB !=
nullptr;
164 if (!isDestBBSuitableForSink(
I, DestBlock))
175 if (
C->isInlineAsm() ||
C->cannotMerge() ||
C->isConvergent())
179 if (
I->mayWriteToMemory())
184 if (
I->mayReadFromMemory()) {
187 E =
I->getParent()->end();
192 if (Scan->mayWriteToMemory())
198 I->moveBefore(*DestBlock, InsertPos);
209static int tryToSinkInstructions(
BasicBlock *OriginalBB,
218 if (tryToSinkInstruction(&
I, IndirectCallBB))
226class IndirectCallPromoter {
228 const InstrumentationOptions &Opts;
234 InstrProfSymtab *
const Symtab;
236 const bool SamplePGO;
239 const VirtualCallSiteTypeInfoMap &VirtualCSInfo;
241 VTableAddressPointOffsetValMap &VTableAddressPointOffsetVal;
243 OptimizationRemarkEmitter &ORE;
245 const DenseSet<StringRef> &IgnoredBaseTypes;
248 const ModuleSummaryIndex *
const ImportSummary;
251 struct PromotionCandidate {
254 const uint32_t Index;
263 VTableGUIDCountsMap VTableGUIDAndCounts;
267 : TargetFunction(
F), Count(
C), Index(
I) {}
275 std::vector<PromotionCandidate> getPromotionCandidatesForCallSite(
277 uint64_t TotalCount, uint32_t NumCandidates);
282 bool tryToPromoteWithFuncCmp(
285 uint32_t NumCandidates, VTableGUIDCountsMap &VTableGUIDCounts);
290 bool tryToPromoteWithVTableCmp(
292 uint64_t TotalFuncCount, uint32_t NumCandidates,
294 VTableGUIDCountsMap &VTableGUIDCounts);
297 bool isProfitableToCompareVTables(
const CallBase &CB,
302 bool shouldSkipVTable(
uint64_t VTableGUID);
311 Instruction *computeVTableInfos(
const CallBase *CB,
312 VTableGUIDCountsMap &VTableGUIDCounts,
313 std::vector<PromotionCandidate> &Candidates);
315 Constant *getOrCreateVTableAddressPointVar(GlobalVariable *GV,
318 void updateFuncValueProfiles(CallBase &CB,
322 void updateVPtrValueProfiles(Instruction *VPtr,
323 VTableGUIDCountsMap &VTableGUIDCounts);
330 bool isDeclaredTargetLiveInIndex(
const Function &TargetFunction)
const;
333 IndirectCallPromoter(
335 InstrProfSymtab *Symtab,
bool SamplePGO,
336 const VirtualCallSiteTypeInfoMap &VirtualCSInfo,
337 VTableAddressPointOffsetValMap &VTableAddressPointOffsetVal,
338 const DenseSet<StringRef> &IgnoredBaseTypes,
339 OptimizationRemarkEmitter &ORE,
const ModuleSummaryIndex *ImportSummary)
340 : Opts(Opts), F(
Func), M(M), Symtab(Symtab), SamplePGO(SamplePGO),
341 VirtualCSInfo(VirtualCSInfo),
342 VTableAddressPointOffsetVal(VTableAddressPointOffsetVal), ORE(ORE),
343 IgnoredBaseTypes(IgnoredBaseTypes), ImportSummary(ImportSummary) {}
344 IndirectCallPromoter(
const IndirectCallPromoter &) =
delete;
345 IndirectCallPromoter &operator=(
const IndirectCallPromoter &) =
delete;
352bool IndirectCallPromoter::isDeclaredTargetLiveInIndex(
353 const Function &TargetFunction)
const {
368 [](
const std::unique_ptr<GlobalValueSummary> &S) {
373bool IndirectCallPromoter::isValidTarget(
uint64_t Target,
384 if (TargetFunction ==
nullptr) {
387 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UnableToFindTarget", &CB)
388 <<
"Cannot promote indirect call: target with md5sum "
389 <<
NV(
"target md5sum", Target)
390 <<
" not found (count=" <<
NV(
"Count",
Count) <<
")";
395 (!Opts.icp_allow_decls ||
396 (ImportSummary && !isDeclaredTargetLiveInIndex(*TargetFunction)))) {
397 LLVM_DEBUG(
dbgs() <<
" Not promote: target definition is not available\n");
399 return OptimizationRemarkMissed(
DEBUG_TYPE,
"NoTargetDef", &CB)
400 <<
"Do not promote indirect call: target with md5sum "
401 <<
NV(
"target md5sum", Target)
402 <<
" definition not available (count=" <<
ore::NV(
"Count",
Count)
408 const char *Reason =
nullptr;
412 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UnableToPromote", &CB)
413 <<
"Cannot promote indirect call to "
414 <<
NV(
"TargetFunction", TargetFunction)
415 <<
" (count=" <<
NV(
"Count",
Count) <<
"): " << Reason;
424std::vector<IndirectCallPromoter::PromotionCandidate>
425IndirectCallPromoter::getPromotionCandidatesForCallSite(
427 uint64_t TotalCount, uint32_t NumCandidates) {
428 std::vector<PromotionCandidate> Ret;
430 LLVM_DEBUG(
dbgs() <<
" \nWork on callsite #" << NumOfPGOICallsites << CB
431 <<
" Num_targets: " << ValueDataRef.
size()
432 <<
" Num_candidates: " << NumCandidates <<
"\n");
433 NumOfPGOICallsites++;
434 if (Opts.icp_csskip != 0 && NumOfPGOICallsites <= Opts.icp_csskip) {
439 for (uint32_t
I = 0;
I < NumCandidates;
I++) {
445 <<
" Target_func: " << Target <<
"\n");
450 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UserOptions", &CB)
451 <<
" Not promote: User options";
458 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UserOptions", &CB)
459 <<
" Not promote: User options";
463 if (Opts.icp_cutoff != 0 && NumOfPGOICallPromotion >= Opts.icp_cutoff) {
466 return OptimizationRemarkMissed(
DEBUG_TYPE,
"CutOffReached", &CB)
467 <<
" Not promote: Cutoff reached";
473 if (!isValidTarget(Target, TargetFunction, CB,
Count)) {
474 if (Opts.icp_allow_candidate_skip)
480 Ret.push_back(PromotionCandidate(TargetFunction,
Count,
I));
486Constant *IndirectCallPromoter::getOrCreateVTableAddressPointVar(
487 GlobalVariable *GV,
uint64_t AddressPointOffset) {
489 VTableAddressPointOffsetVal[GV].try_emplace(AddressPointOffset,
nullptr);
491 Iter->second = getVTableAddressPointOffset(GV, AddressPointOffset);
495Instruction *IndirectCallPromoter::computeVTableInfos(
496 const CallBase *CB, VTableGUIDCountsMap &GUIDCountsMap,
497 std::vector<PromotionCandidate> &Candidates) {
525 auto Iter = VirtualCSInfo.find(CB);
526 if (Iter == VirtualCSInfo.end())
530 << NumOfPGOICallsites <<
"\n");
532 const auto &VirtualCallInfo = Iter->second;
535 SmallDenseMap<Function *, int, 4> CalleeIndexMap;
536 for (
size_t I = 0;
I < Candidates.size();
I++)
537 CalleeIndexMap[Candidates[
I].TargetFunction] =
I;
541 *VirtualCallInfo.VPtr, IPVK_VTableTarget,
543 if (VTableValueDataArray.empty())
547 for (
const auto &
V : VTableValueDataArray) {
549 GUIDCountsMap[VTableVal] =
V.Count;
552 LLVM_DEBUG(
dbgs() <<
" Cannot find vtable definition for " << VTableVal
553 <<
"; maybe the vtable isn't imported\n");
557 std::optional<uint64_t> MaybeAddressPointOffset =
558 getAddressPointOffset(*VTableVar, VirtualCallInfo.CompatibleTypeStr);
559 if (!MaybeAddressPointOffset)
562 const uint64_t AddressPointOffset = *MaybeAddressPointOffset;
566 VTableVar, AddressPointOffset + VirtualCallInfo.FunctionOffset, M);
569 auto CalleeIndexIter = CalleeIndexMap.
find(Callee);
570 if (CalleeIndexIter == CalleeIndexMap.
end())
573 auto &Candidate = Candidates[CalleeIndexIter->second];
577 Candidate.VTableGUIDAndCounts[VTableVal] =
V.Count;
578 Candidate.AddressPoints.push_back(
579 getOrCreateVTableAddressPointVar(VTableVar, AddressPointOffset));
596 uint64_t
Count, uint64_t TotalCount,
597 bool AttachProfToDirectCall,
603 if (AttachProfToDirectCall)
612 <<
"Promote indirect call to " << NV(
"DirectCallee", DirectCallee)
613 <<
" with count " << NV(
"Count",
Count) <<
" out of "
614 << NV(
"TotalCount", TotalCount);
620bool IndirectCallPromoter::tryToPromoteWithFuncCmp(
623 uint32_t NumCandidates, VTableGUIDCountsMap &VTableGUIDCounts) {
626 for (
const auto &
C : Candidates) {
627 uint64_t FuncCount =
C.Count;
630 assert(TotalCount >= FuncCount);
631 TotalCount -= FuncCount;
632 NumOfPGOICallPromotion++;
636 ICallProfDataRef[
C.Index].Count = 0;
644 uint64_t SumVTableCount = 0;
645 for (
const auto &[GUID, VTableCount] :
C.VTableGUIDAndCounts)
646 SumVTableCount += VTableCount;
648 for (
const auto &[GUID, VTableCount] :
C.VTableGUIDAndCounts) {
649 APInt APFuncCount((
unsigned)128, FuncCount,
false );
650 APFuncCount *= VTableCount;
651 VTableGUIDCounts[GUID] -= APFuncCount.udiv(SumVTableCount).getZExtValue();
654 if (NumPromoted == 0)
657 assert(NumPromoted <= ICallProfDataRef.
size() &&
658 "Number of promoted functions should not be greater than the number "
659 "of values in profile metadata");
661 updateFuncValueProfiles(CB, ICallProfDataRef, TotalCount, NumCandidates);
662 updateVPtrValueProfiles(VPtr, VTableGUIDCounts);
666void IndirectCallPromoter::updateFuncValueProfiles(
668 uint64_t TotalCount, uint32_t MaxMDCount) {
674 const InstrProfValueData &
RHS) {
675 return LHS.Count >
RHS.Count;
682 return ProfData.Count <= Count;
691void IndirectCallPromoter::updateVPtrValueProfiles(
692 Instruction *VPtr, VTableGUIDCountsMap &VTableGUIDCounts) {
697 std::vector<InstrProfValueData> VTableValueProfiles;
699 for (
auto [GUID,
Count] : VTableGUIDCounts) {
703 VTableValueProfiles.push_back({
GUID,
Count});
704 TotalVTableCount +=
Count;
707 [](
const InstrProfValueData &
LHS,
const InstrProfValueData &
RHS) {
708 return LHS.Count >
RHS.Count;
712 IPVK_VTableTarget, VTableValueProfiles.size());
715bool IndirectCallPromoter::tryToPromoteWithVTableCmp(
717 uint64_t TotalFuncCount, uint32_t NumCandidates,
719 VTableGUIDCountsMap &VTableGUIDCounts) {
722 for (
const auto &Candidate : Candidates) {
723 for (
auto &[GUID,
Count] : Candidate.VTableGUIDAndCounts)
731 CB, VPtr, Candidate.TargetFunction, Candidate.AddressPoints,
733 TotalFuncCount - Candidate.Count));
735 int SinkCount = tryToSinkInstructions(OriginalBB, CB.
getParent());
740 const auto &VTableGUIDAndCounts = Candidate.VTableGUIDAndCounts;
741 Remark <<
"Promote indirect call to "
742 <<
ore::NV(
"DirectCallee", Candidate.TargetFunction)
743 <<
" with count " <<
ore::NV(
"Count", Candidate.Count)
744 <<
" out of " <<
ore::NV(
"TotalCount", TotalFuncCount) <<
", sink "
745 <<
ore::NV(
"SinkCount", SinkCount)
746 <<
" instruction(s) and compare "
747 <<
ore::NV(
"VTable", VTableGUIDAndCounts.size())
751 std::set<uint64_t> GUIDSet;
752 for (
auto [GUID,
Count] : VTableGUIDAndCounts)
753 GUIDSet.insert(GUID);
754 for (
auto Iter = GUIDSet.begin(); Iter != GUIDSet.end(); Iter++) {
755 if (Iter != GUIDSet.begin())
765 PromotedFuncCount.
push_back({Candidate.Index, Candidate.Count});
767 assert(TotalFuncCount >= Candidate.Count &&
768 "Within one prof metadata, total count is the sum of counts from "
769 "individual <target, count> pairs");
773 TotalFuncCount -= std::min(TotalFuncCount, Candidate.Count);
774 NumOfPGOICallPromotion++;
777 if (PromotedFuncCount.
empty())
786 for (
size_t I = 0;
I < PromotedFuncCount.
size();
I++) {
787 uint32_t
Index = PromotedFuncCount[
I].first;
788 ICallProfDataRef[
Index].Count -=
789 std::max(PromotedFuncCount[
I].second, ICallProfDataRef[Index].
Count);
791 updateFuncValueProfiles(CB, ICallProfDataRef, TotalFuncCount, NumCandidates);
792 updateVPtrValueProfiles(VPtr, VTableGUIDCounts);
798bool IndirectCallPromoter::processFunction(ProfileSummaryInfo *PSI) {
800 ICallPromotionAnalysis ICallAnalysis;
802 uint32_t NumCandidates;
805 CB, TotalCount, NumCandidates);
811 LLVM_DEBUG(
dbgs() <<
"Don't promote the cold candidate: TotalCount="
812 << TotalCount <<
"\n");
818 if (Opts.icp_allow_hot_only &&
821 : Opts.hot_func_cutoff_for_icp,
823 LLVM_DEBUG(
dbgs() <<
"Don't promote the non-hot candidate: TotalCount="
824 << TotalCount <<
"\n");
829 auto PromotionCandidates = getPromotionCandidatesForCallSite(
830 *CB, ICallProfDataRef, TotalCount, NumCandidates);
832 VTableGUIDCountsMap VTableGUIDCounts;
834 computeVTableInfos(CB, VTableGUIDCounts, PromotionCandidates);
836 if (isProfitableToCompareVTables(*CB, PromotionCandidates))
837 Changed |= tryToPromoteWithVTableCmp(*CB, VPtr, PromotionCandidates,
838 TotalCount, NumCandidates,
839 ICallProfDataRef, VTableGUIDCounts);
841 Changed |= tryToPromoteWithFuncCmp(*CB, VPtr, PromotionCandidates,
842 TotalCount, ICallProfDataRef,
843 NumCandidates, VTableGUIDCounts);
850bool IndirectCallPromoter::isProfitableToCompareVTables(
854 LLVM_DEBUG(
dbgs() <<
"\nEvaluating vtable profitability for callsite #"
855 << NumOfPGOICallsites << CB <<
"\n");
856 const size_t CandidateSize = Candidates.
size();
857 for (
size_t I = 0;
I < CandidateSize;
I++) {
858 auto &Candidate = Candidates[
I];
859 auto &VTableGUIDAndCounts = Candidate.VTableGUIDAndCounts;
862 dbgs() <<
" Candidate " <<
I <<
" FunctionCount: " << Candidate.Count
863 <<
", VTableCounts:";
864 for (
const auto &[GUID,
Count] : VTableGUIDAndCounts)
872 for (
auto &[GUID,
Count] : VTableGUIDAndCounts) {
873 CandidateVTableCount +=
Count;
875 if (shouldSkipVTable(GUID))
879 if (CandidateVTableCount <
880 Candidate.Count * Opts.icp_vtable_percentage_threshold) {
882 dbgs() <<
" function count " << Candidate.Count
883 <<
" and its vtable sum count " << CandidateVTableCount
884 <<
" have discrepancies. Bail out vtable comparison.\n");
894 int MaxNumVTable = 1;
895 if (
I == CandidateSize - 1)
896 MaxNumVTable = Opts.icp_max_num_vtable_last_candidate;
898 if ((
int)Candidate.AddressPoints.size() > MaxNumVTable) {
899 LLVM_DEBUG(
dbgs() <<
" allow at most " << MaxNumVTable <<
" and got "
900 << Candidate.AddressPoints.size()
901 <<
" vtables. Bail out for vtable comparison.\n");
909bool IndirectCallPromoter::shouldSkipVTable(
uint64_t VTableGUID) {
910 if (IgnoredBaseTypes.empty())
915 assert(VTableVar &&
"VTableVar must exist for GUID in VTableGUIDAndCounts");
918 VTableVar->
getMetadata(LLVMContext::MD_type, Types);
920 for (
auto *
Type : Types)
922 if (IgnoredBaseTypes.contains(TypeId->getString())) {
924 "out of vtable comparison.");
938 VirtualCallSiteTypeInfoMap &VirtualCSInfo) {
949 if (!TypeTestFunc || TypeTestFunc->
use_empty())
965 if (!CompatibleTypeId)
972 auto &DT = LookupDomTree(*CI->getFunction());
975 for (
auto &DevirtCall : DevirtCalls) {
983 VirtualCSInfo[&CB] = {DevirtCall.Offset, VTablePtr,
984 CompatibleTypeId->getString()};
994 if (Opts.disable_icp)
998 std::string SymtabFailure =
toString(std::move(
E));
999 M.getContext().emitError(
"Failed to create symtab: " + SymtabFailure);
1003 VirtualCallSiteTypeInfoMap VirtualCSInfo;
1010 IgnoredBaseTypes.
insert_range(Opts.icp_ignored_base_types);
1020 VTableAddressPointOffsetValMap VTableAddressPointOffsetVal;
1023 if (
F.isDeclaration() ||
F.hasOptNone())
1030 IndirectCallPromoter CallPromoter(
1031 Opts,
F, M, &Symtab, SamplePGO, VirtualCSInfo,
1032 VTableAddressPointOffsetVal, IgnoredBaseTypes, ORE, ImportSummary);
1033 bool FuncChanged = CallPromoter.processFunction(PSI);
1034 if (Opts.icp_dumpafter && FuncChanged) {
1039 if (Opts.icp_cutoff != 0 && NumOfPGOICallPromotion >= Opts.icp_cutoff) {
1053 SamplePGO | Opts.icp_samplepgo,
MAM, ImportSummary))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
This header defines various interfaces for pass management in LLVM.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
static bool processFunction(Function &F, NVPTXTargetMachine &TM)
This file provides the interface for IR based instrumentation passes ( (profile-gen,...
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
This file contains the declarations for profiling metadata utility functions.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Class for arbitrary precision integers.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
LLVM Basic Block Representation.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
LLVM_ABI const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
static LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP Constant * getInBoundsPtrAdd(Constant *Ptr, Constant *Offset)
Create a getelementptr inbounds i8, ptr, offset constant expression.
This is an important base class in LLVM.
iterator find(const_arg_type_t< KeyT > Val)
Implements a dense probed hash-table based set.
Analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Lightweight error class with error context and mandatory checking.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this GlobalObject.
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
LLVM_ABI GUID getGUID() const
Return a 64-bit global unique ID for this value.
A symbol table used for function [IR]PGO name look-up with keys (such as pointers,...
GlobalVariable * getGlobalVariable(uint64_t MD5Hash) const
Return the global variable corresponding to md5 hash.
LLVM_ABI Error create(object::SectionRef &Section)
Create InstrProfSymtab from an object file section which contains function PGO names.
Function * getFunction(uint64_t FuncMD5Hash) const
Return function from the name's md5 hash. Return nullptr if not found.
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
This is an important class for using LLVM in a threaded context.
LLVM_ABI MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
A Module instance is used to store all the information related to an LLVM module.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
Analysis providing profile information.
bool hasProfileSummary() const
Returns true if profile summary is available.
LLVM_ABI bool isColdCount(uint64_t C) const
Returns true if count C is considered cold.
LLVM_ABI bool isHotCountNthPercentile(int PercentileCutoff, uint64_t C) const
Returns true if count C is considered hot with regard to a given hot percentile cutoff value.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
A Use represents the edge between a Value definition and its users.
User * getUser() const
Returns the User that contains this Use.
LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< use_iterator > uses()
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
void insert_range(Range &&R)
const ParentTy * getParent() const
@ BasicBlock
Various leaf nodes.
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
Add a small namespace to avoid name clashes with the classes used in the streaming interface.
DiagnosticInfoOptimizationBase::Argument NV
LLVM_ABI CallBase & promoteIndirectCall(CallBase &CB, Function *F, uint64_t Count, uint64_t TotalCount, bool AttachProfToDirectCall, OptimizationRemarkEmitter *ORE)
NodeAddr< FuncNode * > Func
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
const InstrumentationOptions & getInstrumentationOptions(const LLVMContext &C)
void stable_sort(R &&Range)
LLVM_ABI bool isLegalToPromote(const CallBase &CB, Function *Callee, const char **FailureReason=nullptr)
Return true if the given indirect call site can be made to call Callee.
std::vector< CallBase * > findIndirectCalls(Function &F)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI CallBase & promoteCallWithIfThenElse(CallBase &CB, Function *Callee, MDNode *BranchWeights=nullptr)
Promote the given indirect call site to conditionally call Callee.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
cl::opt< bool > EnableVTableProfileUse("enable-vtable-profile-use", cl::init(false), cl::desc("If ThinLTO and WPD is enabled and this option is true, vtable " "profiles will be used by ICP pass for more efficient indirect " "call sequence. If false, type profiles won't be used."))
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void annotateValueSite(Module &M, Instruction &Inst, const InstrProfRecord &InstrProfR, InstrProfValueKind ValueKind, uint32_t SiteIndx, uint32_t MaxMDCount=3)
Get the value profile data for value site SiteIdx from InstrProfR and annotate the instruction Inst w...
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI SmallVector< InstrProfValueData, 4 > getValueProfDataFromInst(const Instruction &Inst, InstrProfValueKind ValueKind, uint32_t MaxNumValueData, uint64_t &TotalC, bool GetNoICPValue=false)
Extract the value profile data from Inst and returns them if Inst is annotated with value profile dat...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
LLVM_ABI cl::opt< int > ProfileSummaryCutoffHot
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
uint32_t scaleBranchCount(uint64_t Count, uint64_t Scale)
Scale an individual branch count.
LLVM_ABI unsigned getMaxNumVTableAnnotations(const LLVMContext &C)
Return -icp-max-num-vtables.
LLVM_ABI void setFittedBranchWeights(Instruction &I, ArrayRef< uint64_t > Weights, bool IsExpected, bool ElideAllZero=false)
Variant of setBranchWeights where the Weights will be fit first to uint32_t by shifting right.
uint64_t calculateCountScale(uint64_t MaxCount)
Calculate what to divide by to scale counts.
LLVM_ABI CallBase & promoteCallWithVTableCmp(CallBase &CB, Instruction *VPtr, Function *Callee, ArrayRef< Constant * > AddressPoints, MDNode *BranchWeights)
This is similar to promoteCallWithIfThenElse except that the condition to promote a virtual call is t...
LLVM_ABI void findDevirtualizableCallsForTypeTest(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< CallInst * > &Assumes, const CallInst *CI, DominatorTree &DT)
Given a call to the intrinsic @llvm.type.test, find all devirtualizable call sites based on the call ...
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
LLVM_ABI std::pair< Function *, Constant * > getFunctionAtVTableOffset(GlobalVariable *GV, uint64_t Offset, Module &M)
Given a vtable and a specified offset, returns the function and the trivial pointer at the specified ...
static Instruction * tryGetVTableInstruction(CallBase *CB)