LLVM 24.0.0git
SampleProfile.cpp File Reference
#include "llvm/Transforms/IPO/SampleProfile.h"
#include "IPOOptions.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/PriorityQueue.h"
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/BlockFrequencyInfoImpl.h"
#include "llvm/Analysis/InlineAdvisor.h"
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/ReplayInlineAdvisor.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/IR/PseudoProbe.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/ProfileData/SampleProf.h"
#include "llvm/ProfileData/SampleProfReader.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/ProfiledCallGraph.h"
#include "llvm/Transforms/IPO/SampleContextTracker.h"
#include "llvm/Transforms/IPO/SampleProfileMatcher.h"
#include "llvm/Transforms/IPO/SampleProfileProbe.h"
#include "llvm/Transforms/Utils/CallPromotionUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/Instrumentation.h"
#include "llvm/Transforms/Utils/MisExpect.h"
#include "llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h"
#include "llvm/Transforms/Utils/SampleProfileLoaderBaseUtil.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <functional>
#include <limits>
#include <memory>
#include <queue>
#include <string>
#include <system_error>
#include <utility>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.

Macros

#define DEBUG_TYPE   "sample-profile"
#define CSINLINE_DEBUG   DEBUG_TYPE "-inline"

Functions

 STATISTIC (NumCSInlined, "Number of functions inlined with context sensitive profile")
 STATISTIC (NumCSNotInlined, "Number of functions not inlined with context sensitive profile")
 STATISTIC (NumMismatchedProfile, "Number of functions with CFG mismatched profile")
 STATISTIC (NumMatchedProfile, "Number of functions with CFG matched profile")
 STATISTIC (NumDuplicatedInlinesite, "Number of inlined callsites with a partial distribution factor")
 STATISTIC (NumCSInlinedHitMinLimit, "Number of functions with FDO inline stopped due to min size limit")
 STATISTIC (NumCSInlinedHitMaxLimit, "Number of functions with FDO inline stopped due to max size limit")
 STATISTIC (NumCSInlinedHitGrowthLimit, "Number of functions with FDO inline stopped due to growth size limit")
cl::opt< bool > llvm::SortProfiledSCC ("sort-profiled-scc-member", cl::init(true), cl::Hidden, cl::desc("Sort profiled recursion by edge weights."))
cl::opt< int > llvm::ProfileInlineGrowthLimit ("sample-profile-inline-growth-limit", cl::Hidden, cl::init(12), cl::desc("The size growth ratio limit for priority-based sample profile " "loader inlining."))
cl::opt< int > llvm::ProfileInlineLimitMin ("sample-profile-inline-limit-min", cl::Hidden, cl::init(100), cl::desc("The lower bound of size growth limit for " "priority-based sample profile loader inlining."))
cl::opt< int > llvm::ProfileInlineLimitMax ("sample-profile-inline-limit-max", cl::Hidden, cl::init(10000), cl::desc("The upper bound of size growth limit for " "priority-based sample profile loader inlining."))
cl::opt< int > llvm::SampleHotCallSiteThreshold ("sample-profile-hot-inline-threshold", cl::Hidden, cl::init(3000), cl::desc("Hot callsite threshold for priority-based sample profile loader " "inlining."))
cl::opt< int > llvm::SampleColdCallSiteThreshold ("sample-profile-cold-inline-threshold", cl::Hidden, cl::init(45), cl::desc("Threshold for inlining cold callsites"))
static bool doesHistoryAllowICP (const IPOOptions &Opts, const Instruction &Inst, StringRef Candidate)
 Check whether the indirect call promotion history of Inst allows the promotion for Candidate.
static void updateIDTMetaData (const IPOOptions &Opts, Instruction &Inst, const SmallVectorImpl< InstrProfValueData > &CallTargets, uint64_t Sum)
 Update indirect call target profile metadata for Inst.
static SmallVector< InstrProfValueData, 2 > GetSortedValueDataFromCallTargets (const SampleRecord::CallTargetMap &M)
 Returns the sorted CallTargetMap M by count in descending order.

Macro Definition Documentation

◆ CSINLINE_DEBUG

#define CSINLINE_DEBUG   DEBUG_TYPE "-inline"

Definition at line 98 of file SampleProfile.cpp.

◆ DEBUG_TYPE

#define DEBUG_TYPE   "sample-profile"

Definition at line 97 of file SampleProfile.cpp.

Function Documentation

◆ doesHistoryAllowICP()

bool doesHistoryAllowICP ( const IPOOptions & Opts,
const Instruction & Inst,
StringRef Candidate )
static

Check whether the indirect call promotion history of Inst allows the promotion for Candidate.

If the profile count for the promotion candidate Candidate is NOMORE_ICP_MAGICNUM, it means Candidate has already been promoted for Inst. If we already have at least MaxNumPromotions NOMORE_ICP_MAGICNUM count values in the value profile of Inst, we cannot promote for Inst anymore.

Definition at line 626 of file SampleProfile.cpp.

References llvm::GlobalValue::getGUIDAssumingExternalLinkage(), llvm::getValueProfDataFromInst(), llvm::NOMORE_ICP_MAGICNUM, uint64_t, and V.

◆ GetSortedValueDataFromCallTargets()

SmallVector< InstrProfValueData, 2 > GetSortedValueDataFromCallTargets ( const SampleRecord::CallTargetMap & M)
static

Returns the sorted CallTargetMap M by count in descending order.

Definition at line 1424 of file SampleProfile.cpp.

References I, and llvm::sampleprof::SampleRecord::sortCallTargets().

◆ STATISTIC() [1/8]

STATISTIC ( NumCSInlined ,
"Number of functions inlined with context sensitive profile"  )

◆ STATISTIC() [2/8]

STATISTIC ( NumCSInlinedHitGrowthLimit ,
"Number of functions with FDO inline stopped due to growth size limit"  )

◆ STATISTIC() [3/8]

STATISTIC ( NumCSInlinedHitMaxLimit ,
"Number of functions with FDO inline stopped due to max size limit"  )

◆ STATISTIC() [4/8]

STATISTIC ( NumCSInlinedHitMinLimit ,
"Number of functions with FDO inline stopped due to min size limit"  )

◆ STATISTIC() [5/8]

STATISTIC ( NumCSNotInlined ,
"Number of functions not inlined with context sensitive profile"  )

◆ STATISTIC() [6/8]

STATISTIC ( NumDuplicatedInlinesite ,
"Number of inlined callsites with a partial distribution factor"  )

◆ STATISTIC() [7/8]

STATISTIC ( NumMatchedProfile ,
"Number of functions with CFG matched profile"  )

◆ STATISTIC() [8/8]

STATISTIC ( NumMismatchedProfile ,
"Number of functions with CFG mismatched profile"  )

◆ updateIDTMetaData()

void updateIDTMetaData ( const IPOOptions & Opts,
Instruction & Inst,
const SmallVectorImpl< InstrProfValueData > & CallTargets,
uint64_t Sum )
static

Update indirect call target profile metadata for Inst.

Usually Sum is the sum of counts of all the targets for Inst. If it is 0, it means updateIDTMetaData is used to mark a certain target to be promoted already. If it is not zero, we expect to use it to update the total count in the value profile.

Definition at line 661 of file SampleProfile.cpp.

References llvm::annotateValueSite(), assert(), llvm::Count, llvm::Data, llvm::SmallVectorImpl< T >::emplace_back(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::getValueProfDataFromInst(), llvm::NOMORE_ICP_MAGICNUM, llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::sort(), llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace(), uint64_t, and V.