53#define DEBUG_TYPE "pgo-icall-prom"
55STATISTIC(NumOfPGOICallPromotion,
"Number of indirect call promotions.");
56STATISTIC(NumOfPGOICallsites,
"Number of indirect call candidate sites.");
67 cl::desc(
"Disable indirect call promotion"));
75 cl::desc(
"Max number of promotions for this compilation"));
81 cl::desc(
"Skip Callsite up to this number for this compilation"));
86 cl::desc(
"Promote the target candidate even when the definition "
87 " is not available"));
93 cl::desc(
"Promote the target candidate only if it is a "
94 "hot function. Otherwise, warm functions can "
101 cl::desc(
"Continue with the remaining targets instead of exiting "
102 "when failing in a candidate"));
108 cl::desc(
"Run indirect-call promotion in LTO "
115 cl::desc(
"Run indirect-call promotion in SamplePGO mode"));
121 cl::desc(
"Run indirect-call promotion for call instructions "
128 cl::desc(
"Run indirect-call promotion for "
129 "invoke instruction only"));
135 cl::desc(
"Dump IR after transformation happens"));
141 cl::desc(
"The percentage threshold of vtable-count / function-count for "
142 "cost-benefit analysis."));
153 cl::desc(
"The maximum number of vtable for the last candidate."));
158 "A list of mangled vtable type info names. Classes specified by the "
159 "type info names and their derived ones will not be vtable-ICP'ed. "
160 "Useful when the profiled types and actual types in the optimized "
161 "binary could be different due to profiling limitations. Type info "
162 "names are those string literals used in LLVM type metadata"));
166 cl::desc(
"A count is hot for indirect call promotion if it exceeds "
167 "the minimum count to reach this percentile of total counts."
168 "Note that this percentile is specified as "
169 "percentile * 10000 = HotFuncCutoffForICP."
170 "Default value -1 means that if the flag is unspecified then "
171 "the value of ProfileSummaryCutoffHot will be used instead."));
177using VTableAddressPointOffsetValMap =
181struct VirtualCallSiteInfo {
191using VirtualCallSiteTypeInfoMap =
202static std::optional<uint64_t>
206 VTableVar.
getMetadata(LLVMContext::MD_type, Types);
210 TypeId && TypeId->getString() == CompatibleType)
224 assert(AddressPointOffset < VTable->getGlobalSize(M.getDataLayout()) &&
225 "Out-of-bound access");
235 return PN->getIncomingBlock(U);
250 "Guaranteed by ICP transformation");
261 UserBB = getUserBasicBlock(
Use, UserInst);
264 if (UserBB != DestBB)
267 return UserBB !=
nullptr;
275 if (!isDestBBSuitableForSink(
I, DestBlock))
286 if (
C->isInlineAsm() ||
C->cannotMerge() ||
C->isConvergent())
290 if (
I->mayWriteToMemory())
295 if (
I->mayReadFromMemory()) {
298 E =
I->getParent()->end();
303 if (Scan->mayWriteToMemory())
309 I->moveBefore(*DestBlock, InsertPos);
320static int tryToSinkInstructions(
BasicBlock *OriginalBB,
329 if (tryToSinkInstruction(&
I, IndirectCallBB))
337class IndirectCallPromoter {
344 InstrProfSymtab *
const Symtab;
346 const bool SamplePGO;
349 const VirtualCallSiteTypeInfoMap &VirtualCSInfo;
351 VTableAddressPointOffsetValMap &VTableAddressPointOffsetVal;
353 OptimizationRemarkEmitter &ORE;
355 const DenseSet<StringRef> &IgnoredBaseTypes;
358 struct PromotionCandidate {
360 const uint64_t Count;
361 const uint32_t Index;
370 VTableGUIDCountsMap VTableGUIDAndCounts;
373 PromotionCandidate(Function *
F, uint64_t
C, uint32_t
I)
374 : TargetFunction(
F), Count(
C), Index(
I) {}
382 std::vector<PromotionCandidate> getPromotionCandidatesForCallSite(
384 uint64_t TotalCount, uint32_t NumCandidates);
389 bool tryToPromoteWithFuncCmp(
392 uint32_t NumCandidates, VTableGUIDCountsMap &VTableGUIDCounts);
397 bool tryToPromoteWithVTableCmp(
399 uint64_t TotalFuncCount, uint32_t NumCandidates,
401 VTableGUIDCountsMap &VTableGUIDCounts);
404 bool isProfitableToCompareVTables(
const CallBase &CB,
409 bool shouldSkipVTable(uint64_t VTableGUID);
418 Instruction *computeVTableInfos(
const CallBase *CB,
419 VTableGUIDCountsMap &VTableGUIDCounts,
420 std::vector<PromotionCandidate> &Candidates);
422 Constant *getOrCreateVTableAddressPointVar(GlobalVariable *GV,
423 uint64_t AddressPointOffset);
425 void updateFuncValueProfiles(CallBase &CB,
427 uint64_t Sum, uint32_t MaxMDCount);
429 void updateVPtrValueProfiles(Instruction *VPtr,
430 VTableGUIDCountsMap &VTableGUIDCounts);
432 bool isValidTarget(uint64_t, Function *,
const CallBase &, uint64_t);
435 IndirectCallPromoter(
436 Function &Func,
Module &M, InstrProfSymtab *Symtab,
bool SamplePGO,
437 const VirtualCallSiteTypeInfoMap &VirtualCSInfo,
438 VTableAddressPointOffsetValMap &VTableAddressPointOffsetVal,
439 const DenseSet<StringRef> &IgnoredBaseTypes,
440 OptimizationRemarkEmitter &ORE)
441 : F(
Func), M(M), Symtab(Symtab), SamplePGO(SamplePGO),
442 VirtualCSInfo(VirtualCSInfo),
443 VTableAddressPointOffsetVal(VTableAddressPointOffsetVal), ORE(ORE),
444 IgnoredBaseTypes(IgnoredBaseTypes) {}
445 IndirectCallPromoter(
const IndirectCallPromoter &) =
delete;
446 IndirectCallPromoter &operator=(
const IndirectCallPromoter &) =
delete;
464 if (TargetFunction ==
nullptr) {
467 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UnableToFindTarget", &CB)
468 <<
"Cannot promote indirect call: target with md5sum "
469 <<
NV(
"target md5sum", Target)
470 <<
" not found (count=" <<
NV(
"Count",
Count) <<
")";
475 LLVM_DEBUG(
dbgs() <<
" Not promote: target definition is not available\n");
477 return OptimizationRemarkMissed(
DEBUG_TYPE,
"NoTargetDef", &CB)
478 <<
"Do not promote indirect call: target with md5sum "
479 <<
NV(
"target md5sum", Target)
480 <<
" definition not available (count=" <<
ore::NV(
"Count",
Count)
486 const char *Reason =
nullptr;
490 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UnableToPromote", &CB)
491 <<
"Cannot promote indirect call to "
492 <<
NV(
"TargetFunction", TargetFunction)
493 <<
" (count=" <<
NV(
"Count",
Count) <<
"): " << Reason;
502std::vector<IndirectCallPromoter::PromotionCandidate>
503IndirectCallPromoter::getPromotionCandidatesForCallSite(
505 uint64_t TotalCount, uint32_t NumCandidates) {
506 std::vector<PromotionCandidate> Ret;
508 LLVM_DEBUG(
dbgs() <<
" \nWork on callsite #" << NumOfPGOICallsites << CB
509 <<
" Num_targets: " << ValueDataRef.
size()
510 <<
" Num_candidates: " << NumCandidates <<
"\n");
511 NumOfPGOICallsites++;
517 for (uint32_t
I = 0;
I < NumCandidates;
I++) {
518 uint64_t
Count = ValueDataRef[
I].Count;
521 uint64_t
Target = ValueDataRef[
I].Value;
523 <<
" Target_func: " << Target <<
"\n");
528 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UserOptions", &CB)
529 <<
" Not promote: User options";
536 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UserOptions", &CB)
537 <<
" Not promote: User options";
544 return OptimizationRemarkMissed(
DEBUG_TYPE,
"CutOffReached", &CB)
545 <<
" Not promote: Cutoff reached";
551 if (!isValidTarget(Target, TargetFunction, CB,
Count)) {
558 Ret.push_back(PromotionCandidate(TargetFunction,
Count,
I));
564Constant *IndirectCallPromoter::getOrCreateVTableAddressPointVar(
565 GlobalVariable *GV, uint64_t AddressPointOffset) {
567 VTableAddressPointOffsetVal[GV].try_emplace(AddressPointOffset,
nullptr);
569 Iter->second = getVTableAddressPointOffset(GV, AddressPointOffset);
573Instruction *IndirectCallPromoter::computeVTableInfos(
574 const CallBase *CB, VTableGUIDCountsMap &GUIDCountsMap,
575 std::vector<PromotionCandidate> &Candidates) {
603 auto Iter = VirtualCSInfo.find(CB);
604 if (Iter == VirtualCSInfo.end())
608 << NumOfPGOICallsites <<
"\n");
610 const auto &VirtualCallInfo = Iter->second;
613 SmallDenseMap<Function *, int, 4> CalleeIndexMap;
614 for (
size_t I = 0;
I < Candidates.size();
I++)
615 CalleeIndexMap[Candidates[
I].TargetFunction] =
I;
617 uint64_t TotalVTableCount = 0;
618 auto VTableValueDataArray =
621 if (VTableValueDataArray.empty())
625 for (
const auto &V : VTableValueDataArray) {
626 uint64_t VTableVal =
V.Value;
627 GUIDCountsMap[VTableVal] =
V.Count;
630 LLVM_DEBUG(
dbgs() <<
" Cannot find vtable definition for " << VTableVal
631 <<
"; maybe the vtable isn't imported\n");
635 std::optional<uint64_t> MaybeAddressPointOffset =
636 getAddressPointOffset(*VTableVar, VirtualCallInfo.CompatibleTypeStr);
637 if (!MaybeAddressPointOffset)
640 const uint64_t AddressPointOffset = *MaybeAddressPointOffset;
644 VTableVar, AddressPointOffset + VirtualCallInfo.FunctionOffset, M);
647 auto CalleeIndexIter = CalleeIndexMap.
find(Callee);
648 if (CalleeIndexIter == CalleeIndexMap.
end())
651 auto &Candidate = Candidates[CalleeIndexIter->second];
655 Candidate.VTableGUIDAndCounts[VTableVal] =
V.Count;
656 Candidate.AddressPoints.push_back(
657 getOrCreateVTableAddressPointVar(VTableVar, AddressPointOffset));
675 bool AttachProfToDirectCall,
681 if (AttachProfToDirectCall)
690 <<
"Promote indirect call to " << NV(
"DirectCallee", DirectCallee)
691 <<
" with count " << NV(
"Count",
Count) <<
" out of "
692 << NV(
"TotalCount", TotalCount);
698bool IndirectCallPromoter::tryToPromoteWithFuncCmp(
701 uint32_t NumCandidates, VTableGUIDCountsMap &VTableGUIDCounts) {
704 for (
const auto &
C : Candidates) {
708 assert(TotalCount >= FuncCount);
709 TotalCount -= FuncCount;
710 NumOfPGOICallPromotion++;
714 ICallProfDataRef[
C.Index].Count = 0;
723 for (
const auto &[GUID, VTableCount] :
C.VTableGUIDAndCounts)
724 SumVTableCount += VTableCount;
726 for (
const auto &[GUID, VTableCount] :
C.VTableGUIDAndCounts) {
727 APInt APFuncCount((
unsigned)128, FuncCount,
false );
728 APFuncCount *= VTableCount;
729 VTableGUIDCounts[GUID] -= APFuncCount.udiv(SumVTableCount).getZExtValue();
732 if (NumPromoted == 0)
735 assert(NumPromoted <= ICallProfDataRef.
size() &&
736 "Number of promoted functions should not be greater than the number "
737 "of values in profile metadata");
739 updateFuncValueProfiles(CB, ICallProfDataRef, TotalCount, NumCandidates);
740 updateVPtrValueProfiles(VPtr, VTableGUIDCounts);
744void IndirectCallPromoter::updateFuncValueProfiles(
746 uint64_t TotalCount, uint32_t MaxMDCount) {
752 const InstrProfValueData &
RHS) {
753 return LHS.Count >
RHS.Count;
759 [](uint64_t
Count,
const InstrProfValueData &ProfData) {
760 return ProfData.Count <= Count;
769void IndirectCallPromoter::updateVPtrValueProfiles(
770 Instruction *VPtr, VTableGUIDCountsMap &VTableGUIDCounts) {
775 std::vector<InstrProfValueData> VTableValueProfiles;
776 uint64_t TotalVTableCount = 0;
777 for (
auto [GUID,
Count] : VTableGUIDCounts) {
781 VTableValueProfiles.push_back({
GUID,
Count});
782 TotalVTableCount +=
Count;
785 [](
const InstrProfValueData &
LHS,
const InstrProfValueData &
RHS) {
786 return LHS.Count >
RHS.Count;
790 IPVK_VTableTarget, VTableValueProfiles.size());
793bool IndirectCallPromoter::tryToPromoteWithVTableCmp(
795 uint64_t TotalFuncCount, uint32_t NumCandidates,
797 VTableGUIDCountsMap &VTableGUIDCounts) {
800 for (
const auto &Candidate : Candidates) {
801 for (
auto &[GUID,
Count] : Candidate.VTableGUIDAndCounts)
809 CB, VPtr, Candidate.TargetFunction, Candidate.AddressPoints,
811 TotalFuncCount - Candidate.Count));
813 int SinkCount = tryToSinkInstructions(OriginalBB, CB.
getParent());
818 const auto &VTableGUIDAndCounts = Candidate.VTableGUIDAndCounts;
819 Remark <<
"Promote indirect call to "
820 <<
ore::NV(
"DirectCallee", Candidate.TargetFunction)
821 <<
" with count " <<
ore::NV(
"Count", Candidate.Count)
822 <<
" out of " <<
ore::NV(
"TotalCount", TotalFuncCount) <<
", sink "
823 <<
ore::NV(
"SinkCount", SinkCount)
824 <<
" instruction(s) and compare "
825 <<
ore::NV(
"VTable", VTableGUIDAndCounts.size())
829 std::set<uint64_t> GUIDSet;
830 for (
auto [GUID,
Count] : VTableGUIDAndCounts)
831 GUIDSet.insert(GUID);
832 for (
auto Iter = GUIDSet.begin(); Iter != GUIDSet.end(); Iter++) {
833 if (Iter != GUIDSet.begin())
843 PromotedFuncCount.
push_back({Candidate.Index, Candidate.Count});
845 assert(TotalFuncCount >= Candidate.Count &&
846 "Within one prof metadata, total count is the sum of counts from "
847 "individual <target, count> pairs");
851 TotalFuncCount -= std::min(TotalFuncCount, Candidate.Count);
852 NumOfPGOICallPromotion++;
855 if (PromotedFuncCount.
empty())
864 for (
size_t I = 0;
I < PromotedFuncCount.
size();
I++) {
865 uint32_t
Index = PromotedFuncCount[
I].first;
866 ICallProfDataRef[
Index].Count -=
867 std::max(PromotedFuncCount[
I].second, ICallProfDataRef[Index].
Count);
869 updateFuncValueProfiles(CB, ICallProfDataRef, TotalFuncCount, NumCandidates);
870 updateVPtrValueProfiles(VPtr, VTableGUIDCounts);
876bool IndirectCallPromoter::processFunction(ProfileSummaryInfo *PSI) {
878 ICallPromotionAnalysis ICallAnalysis;
880 uint32_t NumCandidates;
883 CB, TotalCount, NumCandidates);
889 LLVM_DEBUG(
dbgs() <<
"Don't promote the cold candidate: TotalCount="
890 << TotalCount <<
"\n");
901 LLVM_DEBUG(
dbgs() <<
"Don't promote the non-hot candidate: TotalCount="
902 << TotalCount <<
"\n");
907 auto PromotionCandidates = getPromotionCandidatesForCallSite(
908 *CB, ICallProfDataRef, TotalCount, NumCandidates);
910 VTableGUIDCountsMap VTableGUIDCounts;
912 computeVTableInfos(CB, VTableGUIDCounts, PromotionCandidates);
914 if (isProfitableToCompareVTables(*CB, PromotionCandidates))
915 Changed |= tryToPromoteWithVTableCmp(*CB, VPtr, PromotionCandidates,
916 TotalCount, NumCandidates,
917 ICallProfDataRef, VTableGUIDCounts);
919 Changed |= tryToPromoteWithFuncCmp(*CB, VPtr, PromotionCandidates,
920 TotalCount, ICallProfDataRef,
921 NumCandidates, VTableGUIDCounts);
928bool IndirectCallPromoter::isProfitableToCompareVTables(
932 LLVM_DEBUG(
dbgs() <<
"\nEvaluating vtable profitability for callsite #"
933 << NumOfPGOICallsites << CB <<
"\n");
934 const size_t CandidateSize = Candidates.
size();
935 for (
size_t I = 0;
I < CandidateSize;
I++) {
936 auto &Candidate = Candidates[
I];
937 auto &VTableGUIDAndCounts = Candidate.VTableGUIDAndCounts;
940 dbgs() <<
" Candidate " <<
I <<
" FunctionCount: " << Candidate.Count
941 <<
", VTableCounts:";
942 for (
const auto &[GUID,
Count] : VTableGUIDAndCounts)
948 uint64_t CandidateVTableCount = 0;
950 for (
auto &[GUID,
Count] : VTableGUIDAndCounts) {
951 CandidateVTableCount +=
Count;
953 if (shouldSkipVTable(GUID))
959 dbgs() <<
" function count " << Candidate.Count
960 <<
" and its vtable sum count " << CandidateVTableCount
961 <<
" have discrepancies. Bail out vtable comparison.\n");
971 int MaxNumVTable = 1;
972 if (
I == CandidateSize - 1)
975 if ((
int)Candidate.AddressPoints.size() > MaxNumVTable) {
976 LLVM_DEBUG(
dbgs() <<
" allow at most " << MaxNumVTable <<
" and got "
977 << Candidate.AddressPoints.size()
978 <<
" vtables. Bail out for vtable comparison.\n");
986bool IndirectCallPromoter::shouldSkipVTable(uint64_t VTableGUID) {
987 if (IgnoredBaseTypes.empty())
992 assert(VTableVar &&
"VTableVar must exist for GUID in VTableGUIDAndCounts");
995 VTableVar->
getMetadata(LLVMContext::MD_type, Types);
997 for (
auto *
Type : Types)
999 if (IgnoredBaseTypes.contains(TypeId->getString())) {
1001 "out of vtable comparison.");
1015 VirtualCallSiteTypeInfoMap &VirtualCSInfo) {
1026 if (!TypeTestFunc || TypeTestFunc->
use_empty())
1042 if (!CompatibleTypeId)
1049 auto &DT = LookupDomTree(*CI->getFunction());
1052 for (
auto &DevirtCall : DevirtCalls) {
1060 VirtualCSInfo[&CB] = {DevirtCall.Offset, VTablePtr,
1061 CompatibleTypeId->getString()};
1073 std::string SymtabFailure =
toString(std::move(
E));
1074 M.getContext().emitError(
"Failed to create symtab: " + SymtabFailure);
1078 VirtualCallSiteTypeInfoMap VirtualCSInfo;
1095 VTableAddressPointOffsetValMap VTableAddressPointOffsetVal;
1098 if (
F.isDeclaration() ||
F.hasOptNone())
1105 IndirectCallPromoter CallPromoter(
F, M, &Symtab, SamplePGO, VirtualCSInfo,
1106 VTableAddressPointOffsetVal,
1107 IgnoredBaseTypes, ORE);
1108 bool FuncChanged = CallPromoter.processFunction(PSI);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
Machine Check Debug Module
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 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...
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 bool isDebugOrPseudoInst() const LLVM_READONLY
Return true if the instruction is a DbgInfoIntrinsic or PseudoProbeInst.
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.
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.
Target - Wrapper for Target specific information.
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
@ C
The default llvm calling convention, compatible with C.
@ 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.
initializer< Ty > init(const Ty &Val)
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.
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.
cl::opt< unsigned > MaxNumVTableAnnotations("icp-max-num-vtables", cl::init(6), cl::Hidden, cl::desc("Max number of vtables annotated for a vtable load instruction."))
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."))
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 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)