47#include <unordered_map>
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 defintion "
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"));
169using VTableAddressPointOffsetValMap =
173struct VirtualCallSiteInfo {
183using VirtualCallSiteTypeInfoMap =
194static std::optional<uint64_t>
198 VTableVar.
getMetadata(LLVMContext::MD_type, Types);
201 if (
auto *TypeId = dyn_cast<MDString>(
Type->getOperand(1).get());
202 TypeId && TypeId->getString() == CompatibleType)
203 return cast<ConstantInt>(
204 cast<ConstantAsMetadata>(
Type->getOperand(0))->getValue())
216 assert(AddressPointOffset <
217 M.getDataLayout().getTypeAllocSize(
VTable->getValueType()) &&
218 "Out-of-bound access");
227 if (
PHINode *PN = dyn_cast<PHINode>(UserInst))
228 return PN->getIncomingBlock(U);
243 "Guaranteed by ICP transformation");
254 UserBB = getUserBasicBlock(
Use, UserInst);
257 if (UserBB != DestBB)
260 return UserBB !=
nullptr;
268 if (!isDestBBSuitableForSink(
I, DestBlock))
273 if (isa<PHINode>(
I) ||
I->isEHPad() ||
I->mayThrow() || !
I->willReturn() ||
278 if (
const auto *
C = dyn_cast<CallBase>(
I))
279 if (
C->isInlineAsm() ||
C->cannotMerge() ||
C->isConvergent())
283 if (
I->mayWriteToMemory())
288 if (
I->mayReadFromMemory()) {
291 E =
I->getParent()->end();
296 if (Scan->mayWriteToMemory())
302 I->moveBefore(*DestBlock, InsertPos);
313static int tryToSinkInstructions(
BasicBlock *OriginalBB,
322 if (tryToSinkInstruction(&
I, IndirectCallBB))
330class IndirectCallPromoter {
339 const bool SamplePGO;
342 const VirtualCallSiteTypeInfoMap &VirtualCSInfo;
344 VTableAddressPointOffsetValMap &VTableAddressPointOffsetVal;
351 struct PromotionCandidate {
363 VTableGUIDCountsMap VTableGUIDAndCounts;
367 : TargetFunction(
F), Count(
C),
Index(
I) {}
375 std::vector<PromotionCandidate> getPromotionCandidatesForCallSite(
382 bool tryToPromoteWithFuncCmp(
385 uint32_t NumCandidates, VTableGUIDCountsMap &VTableGUIDCounts);
390 bool tryToPromoteWithVTableCmp(
394 VTableGUIDCountsMap &VTableGUIDCounts);
397 bool isProfitableToCompareVTables(
const CallBase &CB,
402 bool shouldSkipVTable(
uint64_t VTableGUID);
412 VTableGUIDCountsMap &VTableGUIDCounts,
413 std::vector<PromotionCandidate> &Candidates);
418 void updateFuncValueProfiles(
CallBase &CB,
423 VTableGUIDCountsMap &VTableGUIDCounts);
428 IndirectCallPromoter(
430 const VirtualCallSiteTypeInfoMap &VirtualCSInfo,
431 VTableAddressPointOffsetValMap &VTableAddressPointOffsetVal,
434 :
F(
Func),
M(
M), Symtab(Symtab), SamplePGO(SamplePGO),
435 VirtualCSInfo(VirtualCSInfo),
436 VTableAddressPointOffsetVal(VTableAddressPointOffsetVal), ORE(ORE),
437 IgnoredBaseTypes(IgnoredBaseTypes) {}
438 IndirectCallPromoter(
const IndirectCallPromoter &) =
delete;
439 IndirectCallPromoter &operator=(
const IndirectCallPromoter &) =
delete;
457 if (TargetFunction ==
nullptr) {
461 <<
"Cannot promote indirect call: target with md5sum "
463 <<
" not found (count=" <<
NV(
"Count", Count) <<
")";
468 LLVM_DEBUG(
dbgs() <<
" Not promote: target definition is not available\n");
471 <<
"Do not promote indirect call: target with md5sum "
473 <<
" definition not available (count=" <<
ore::NV(
"Count", Count)
479 const char *Reason =
nullptr;
484 <<
"Cannot promote indirect call to "
485 <<
NV(
"TargetFunction", TargetFunction)
486 <<
" (count=" <<
NV(
"Count", Count) <<
"): " << Reason;
495std::vector<IndirectCallPromoter::PromotionCandidate>
496IndirectCallPromoter::getPromotionCandidatesForCallSite(
499 std::vector<PromotionCandidate>
Ret;
501 LLVM_DEBUG(
dbgs() <<
" \nWork on callsite #" << NumOfPGOICallsites << CB
502 <<
" Num_targets: " << ValueDataRef.
size()
503 <<
" Num_candidates: " << NumCandidates <<
"\n");
504 NumOfPGOICallsites++;
512 assert(Count <= TotalCount);
516 <<
" Target_func: " <<
Target <<
"\n");
522 <<
" Not promote: User options";
530 <<
" Not promote: User options";
538 <<
" Not promote: Cutoff reached";
544 if (!isValidTarget(
Target, TargetFunction, CB, Count)) {
551 Ret.push_back(PromotionCandidate(TargetFunction, Count,
I));
557Constant *IndirectCallPromoter::getOrCreateVTableAddressPointVar(
560 VTableAddressPointOffsetVal[GV].try_emplace(AddressPointOffset,
nullptr);
562 Iter->second = getVTableAddressPointOffset(GV, AddressPointOffset);
566Instruction *IndirectCallPromoter::computeVTableInfos(
567 const CallBase *CB, VTableGUIDCountsMap &GUIDCountsMap,
568 std::vector<PromotionCandidate> &Candidates) {
596 auto Iter = VirtualCSInfo.find(CB);
597 if (Iter == VirtualCSInfo.end())
601 << NumOfPGOICallsites <<
"\n");
603 const auto &VirtualCallInfo = Iter->second;
607 for (
size_t I = 0;
I < Candidates.size();
I++)
608 CalleeIndexMap[Candidates[
I].TargetFunction] =
I;
611 auto VTableValueDataArray =
614 if (VTableValueDataArray.empty())
618 for (
const auto &V : VTableValueDataArray) {
620 GUIDCountsMap[VTableVal] =
V.Count;
623 LLVM_DEBUG(
dbgs() <<
" Cannot find vtable definition for " << VTableVal
624 <<
"; maybe the vtable isn't imported\n");
628 std::optional<uint64_t> MaybeAddressPointOffset =
629 getAddressPointOffset(*VTableVar, VirtualCallInfo.CompatibleTypeStr);
630 if (!MaybeAddressPointOffset)
633 const uint64_t AddressPointOffset = *MaybeAddressPointOffset;
637 VTableVar, AddressPointOffset + VirtualCallInfo.FunctionOffset, M);
640 auto CalleeIndexIter = CalleeIndexMap.
find(Callee);
641 if (CalleeIndexIter == CalleeIndexMap.
end())
644 auto &Candidate = Candidates[CalleeIndexIter->second];
648 Candidate.VTableGUIDAndCounts[VTableVal] =
V.Count;
649 Candidate.AddressPoints.push_back(
650 getOrCreateVTableAddressPointVar(VTableVar, AddressPointOffset));
668 bool AttachProfToDirectCall,
674 if (AttachProfToDirectCall)
683 <<
"Promote indirect call to " << NV(
"DirectCallee", DirectCallee)
684 <<
" with count " << NV(
"Count", Count) <<
" out of "
685 << NV(
"TotalCount", TotalCount);
691bool IndirectCallPromoter::tryToPromoteWithFuncCmp(
694 uint32_t NumCandidates, VTableGUIDCountsMap &VTableGUIDCounts) {
697 for (
const auto &
C : Candidates) {
701 assert(TotalCount >= FuncCount);
702 TotalCount -= FuncCount;
703 NumOfPGOICallPromotion++;
707 ICallProfDataRef[
C.Index].Count = 0;
716 for (
const auto &[GUID, VTableCount] :
C.VTableGUIDAndCounts)
717 SumVTableCount += VTableCount;
719 for (
const auto &[GUID, VTableCount] :
C.VTableGUIDAndCounts) {
720 APInt APFuncCount((
unsigned)128, FuncCount,
false );
721 APFuncCount *= VTableCount;
722 VTableGUIDCounts[GUID] -= APFuncCount.udiv(SumVTableCount).getZExtValue();
725 if (NumPromoted == 0)
728 assert(NumPromoted <= ICallProfDataRef.
size() &&
729 "Number of promoted functions should not be greater than the number "
730 "of values in profile metadata");
732 updateFuncValueProfiles(CB, ICallProfDataRef, TotalCount, NumCandidates);
733 updateVPtrValueProfiles(VPtr, VTableGUIDCounts);
737void IndirectCallPromoter::updateFuncValueProfiles(
745 const InstrProfValueData &RHS) {
746 return LHS.Count >
RHS.Count;
752 [](
uint64_t Count,
const InstrProfValueData &ProfData) {
753 return ProfData.Count <= Count;
762void IndirectCallPromoter::updateVPtrValueProfiles(
763 Instruction *VPtr, VTableGUIDCountsMap &VTableGUIDCounts) {
768 std::vector<InstrProfValueData> VTableValueProfiles;
770 for (
auto [GUID, Count] : VTableGUIDCounts) {
774 VTableValueProfiles.push_back({
GUID, Count});
775 TotalVTableCount += Count;
778 [](
const InstrProfValueData &LHS,
const InstrProfValueData &RHS) {
779 return LHS.Count >
RHS.Count;
783 IPVK_VTableTarget, VTableValueProfiles.size());
786bool IndirectCallPromoter::tryToPromoteWithVTableCmp(
790 VTableGUIDCountsMap &VTableGUIDCounts) {
793 for (
const auto &Candidate : Candidates) {
794 for (
auto &[GUID, Count] : Candidate.VTableGUIDAndCounts)
795 VTableGUIDCounts[
GUID] -= Count;
802 CB, VPtr, Candidate.TargetFunction, Candidate.AddressPoints,
804 TotalFuncCount - Candidate.Count));
806 int SinkCount = tryToSinkInstructions(OriginalBB, CB.
getParent());
811 const auto &VTableGUIDAndCounts = Candidate.VTableGUIDAndCounts;
812 Remark <<
"Promote indirect call to "
813 <<
ore::NV(
"DirectCallee", Candidate.TargetFunction)
814 <<
" with count " <<
ore::NV(
"Count", Candidate.Count)
815 <<
" out of " <<
ore::NV(
"TotalCount", TotalFuncCount) <<
", sink "
816 <<
ore::NV(
"SinkCount", SinkCount)
817 <<
" instruction(s) and compare "
818 <<
ore::NV(
"VTable", VTableGUIDAndCounts.size())
822 std::set<uint64_t> GUIDSet;
823 for (
auto [GUID, Count] : VTableGUIDAndCounts)
824 GUIDSet.insert(GUID);
825 for (
auto Iter = GUIDSet.begin(); Iter != GUIDSet.end(); Iter++) {
826 if (Iter != GUIDSet.begin())
828 Remark <<
ore::NV(
"VTable", Symtab->getGlobalVariable(*Iter));
836 PromotedFuncCount.
push_back({Candidate.Index, Candidate.Count});
838 assert(TotalFuncCount >= Candidate.Count &&
839 "Within one prof metadata, total count is the sum of counts from "
840 "individual <target, count> pairs");
844 TotalFuncCount -= std::min(TotalFuncCount, Candidate.Count);
845 NumOfPGOICallPromotion++;
848 if (PromotedFuncCount.
empty())
857 for (
size_t I = 0;
I < PromotedFuncCount.
size();
I++) {
859 ICallProfDataRef[
Index].Count -=
860 std::max(PromotedFuncCount[
I].second, ICallProfDataRef[Index].Count);
862 updateFuncValueProfiles(CB, ICallProfDataRef, TotalFuncCount, NumCandidates);
863 updateVPtrValueProfiles(VPtr, VTableGUIDCounts);
870 bool Changed =
false;
876 CB, TotalCount, NumCandidates);
882 LLVM_DEBUG(
dbgs() <<
"Don't promote the cold candidate: TotalCount="
883 << TotalCount <<
"\n");
888 LLVM_DEBUG(
dbgs() <<
"Don't promote the non-hot candidate: TotalCount="
889 << TotalCount <<
"\n");
894 auto PromotionCandidates = getPromotionCandidatesForCallSite(
895 *CB, ICallProfDataRef, TotalCount, NumCandidates);
897 VTableGUIDCountsMap VTableGUIDCounts;
899 computeVTableInfos(CB, VTableGUIDCounts, PromotionCandidates);
901 if (isProfitableToCompareVTables(*CB, PromotionCandidates))
902 Changed |= tryToPromoteWithVTableCmp(*CB, VPtr, PromotionCandidates,
903 TotalCount, NumCandidates,
904 ICallProfDataRef, VTableGUIDCounts);
906 Changed |= tryToPromoteWithFuncCmp(*CB, VPtr, PromotionCandidates,
907 TotalCount, ICallProfDataRef,
908 NumCandidates, VTableGUIDCounts);
915bool IndirectCallPromoter::isProfitableToCompareVTables(
919 LLVM_DEBUG(
dbgs() <<
"\nEvaluating vtable profitability for callsite #"
920 << NumOfPGOICallsites << CB <<
"\n");
921 const size_t CandidateSize = Candidates.
size();
922 for (
size_t I = 0;
I < CandidateSize;
I++) {
923 auto &Candidate = Candidates[
I];
924 auto &VTableGUIDAndCounts = Candidate.VTableGUIDAndCounts;
927 dbgs() <<
" Candidate " <<
I <<
" FunctionCount: " << Candidate.Count
928 <<
", VTableCounts:";
929 for (
const auto &[GUID, Count] : VTableGUIDAndCounts)
930 dbgs() <<
" {" << Symtab->getGlobalVariable(GUID)->getName() <<
", "
937 for (
auto &[GUID, Count] : VTableGUIDAndCounts) {
938 CandidateVTableCount += Count;
940 if (shouldSkipVTable(GUID))
946 dbgs() <<
" function count " << Candidate.Count
947 <<
" and its vtable sum count " << CandidateVTableCount
948 <<
" have discrepancies. Bail out vtable comparison.\n");
958 int MaxNumVTable = 1;
959 if (
I == CandidateSize - 1)
962 if ((
int)Candidate.AddressPoints.size() > MaxNumVTable) {
963 LLVM_DEBUG(
dbgs() <<
" allow at most " << MaxNumVTable <<
" and got "
964 << Candidate.AddressPoints.size()
965 <<
" vtables. Bail out for vtable comparison.\n");
973bool IndirectCallPromoter::shouldSkipVTable(
uint64_t VTableGUID) {
974 if (IgnoredBaseTypes.empty())
977 auto *VTableVar = Symtab->getGlobalVariable(VTableGUID);
979 assert(VTableVar &&
"VTableVar must exist for GUID in VTableGUIDAndCounts");
982 VTableVar->
getMetadata(LLVMContext::MD_type, Types);
984 for (
auto *
Type : Types)
985 if (
auto *TypeId = dyn_cast<MDString>(
Type->getOperand(1).get()))
986 if (IgnoredBaseTypes.contains(TypeId->getString())) {
988 "out of vtable comparison.");
1002 VirtualCallSiteTypeInfoMap &VirtualCSInfo) {
1013 if (!TypeTestFunc || TypeTestFunc->
use_empty())
1022 auto *CI = dyn_cast<CallInst>(U.getUser());
1025 auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(1));
1028 auto *CompatibleTypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
1029 if (!CompatibleTypeId)
1036 auto &DT = LookupDomTree(*CI->getFunction());
1039 for (
auto &DevirtCall : DevirtCalls) {
1047 VirtualCSInfo[&CB] = {DevirtCall.Offset, VTablePtr,
1048 CompatibleTypeId->getString()};
1060 std::string SymtabFailure =
toString(std::move(E));
1061 M.getContext().emitError(
"Failed to create symtab: " + SymtabFailure);
1064 bool Changed =
false;
1065 VirtualCallSiteTypeInfoMap VirtualCSInfo;
1082 VTableAddressPointOffsetValMap VTableAddressPointOffsetVal;
1085 if (
F.isDeclaration() ||
F.hasOptNone())
1092 IndirectCallPromoter CallPromoter(
F, M, &Symtab, SamplePGO, VirtualCSInfo,
1093 VTableAddressPointOffsetVal,
1094 IgnoredBaseTypes, ORE);
1095 bool FuncChanged = CallPromoter.processFunction(PSI);
1100 Changed |= FuncChanged;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
This header defines various interfaces for pass management in LLVM.
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.
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - 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 if the block is well formed or null if the block is not well forme...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
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.
const Function & getFunction() const
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
A symbol table used for function [IR]PGO name look-up with keys (such as pointers,...
LLVM_ABI Error create(object::SectionRef &Section)
Create InstrProfSymtab from an object file section which contains function PGO names.
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.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
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 isHotCount(uint64_t C) const
Returns true if count C is considered hot.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - 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 * getInt8Ty(LLVMContext &C)
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.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< use_iterator > uses()
void insert_range(Range &&R)
const ParentTy * getParent() const
@ C
The default llvm calling convention, compatible with C.
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)
DiagnosticInfoOptimizationBase::Argument NV
LLVM_ABI CallBase & promoteIndirectCall(CallBase &CB, Function *F, uint64_t Count, uint64_t TotalCount, bool AttachProfToDirectCall, OptimizationRemarkEmitter *ORE)
NodeAddr< FuncNode * > Func
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)
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...
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)
LLVM_ABI void setBranchWeights(Instruction &I, ArrayRef< uint32_t > Weights, bool IsExpected)
Create a new branch_weights metadata node and add or overwrite a prof metadata reference to instructi...
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...
const char * toString(DWARFSectionKind Kind)
uint32_t scaleBranchCount(uint64_t Count, uint64_t Scale)
Scale an individual branch count.
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...
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 ...
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)