#include "llvm/Transforms/IPO/SampleProfileMatcher.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/Support/CommandLine.h"
usingnamespacellvm;
usingnamespacesampleprof;
#define DEBUG_TYPE …
static cl::opt<unsigned> FuncProfileSimilarityThreshold(
"func-profile-similarity-threshold", cl::Hidden, cl::init(80),
cl::desc("Consider a profile matches a function if the similarity of their "
"callee sequences is above the specified percentile."));
static cl::opt<unsigned> MinFuncCountForCGMatching(
"min-func-count-for-cg-matching", cl::Hidden, cl::init(5),
cl::desc("The minimum number of basic blocks required for a function to "
"run stale profile call graph matching."));
static cl::opt<unsigned> MinCallCountForCGMatching(
"min-call-count-for-cg-matching", cl::Hidden, cl::init(3),
cl::desc("The minimum number of call anchors required for a function to "
"run stale profile call graph matching."));
static cl::opt<bool> LoadFuncProfileforCGMatching(
"load-func-profile-for-cg-matching", cl::Hidden, cl::init(false),
cl::desc(
"Load top-level profiles that the sample reader initially skipped for "
"the call-graph matching (only meaningful for extended binary "
"format)"));
extern cl::opt<bool> SalvageStaleProfile;
extern cl::opt<bool> SalvageUnusedProfile;
extern cl::opt<bool> PersistProfileStaleness;
extern cl::opt<bool> ReportProfileStaleness;
static cl::opt<unsigned> SalvageStaleProfileMaxCallsites(
"salvage-stale-profile-max-callsites", cl::Hidden, cl::init(UINT_MAX),
cl::desc("The maximum number of callsites in a function, above which stale "
"profile matching will be skipped."));
void SampleProfileMatcher::findIRAnchors(const Function &F,
AnchorMap &IRAnchors) const { … }
void SampleProfileMatcher::findProfileAnchors(const FunctionSamples &FS,
AnchorMap &ProfileAnchors) const { … }
bool SampleProfileMatcher::functionHasProfile(const FunctionId &IRFuncName,
Function *&FuncWithoutProfile) { … }
bool SampleProfileMatcher::isProfileUnused(const FunctionId &ProfileFuncName) { … }
bool SampleProfileMatcher::functionMatchesProfile(
const FunctionId &IRFuncName, const FunctionId &ProfileFuncName,
bool FindMatchedProfileOnly) { … }
LocToLocMap
SampleProfileMatcher::longestCommonSequence(const AnchorList &AnchorList1,
const AnchorList &AnchorList2,
bool MatchUnusedFunction) { … }
void SampleProfileMatcher::matchNonCallsiteLocs(
const LocToLocMap &MatchedAnchors, const AnchorMap &IRAnchors,
LocToLocMap &IRToProfileLocationMap) { … }
void SampleProfileMatcher::getFilteredAnchorList(
const AnchorMap &IRAnchors, const AnchorMap &ProfileAnchors,
AnchorList &FilteredIRAnchorsList, AnchorList &FilteredProfileAnchorList) { … }
void SampleProfileMatcher::runStaleProfileMatching(
const Function &F, const AnchorMap &IRAnchors,
const AnchorMap &ProfileAnchors, LocToLocMap &IRToProfileLocationMap,
bool RunCFGMatching, bool RunCGMatching) { … }
void SampleProfileMatcher::runOnFunction(Function &F) { … }
void SampleProfileMatcher::recordCallsiteMatchStates(
const Function &F, const AnchorMap &IRAnchors,
const AnchorMap &ProfileAnchors,
const LocToLocMap *IRToProfileLocationMap) { … }
void SampleProfileMatcher::countMismatchedFuncSamples(const FunctionSamples &FS,
bool IsTopLevel) { … }
void SampleProfileMatcher::countMismatchedCallsiteSamples(
const FunctionSamples &FS) { … }
void SampleProfileMatcher::countMismatchCallsites(const FunctionSamples &FS) { … }
void SampleProfileMatcher::countCallGraphRecoveredSamples(
const FunctionSamples &FS,
std::unordered_set<FunctionId> &CallGraphRecoveredProfiles) { … }
void SampleProfileMatcher::computeAndReportProfileStaleness() { … }
void SampleProfileMatcher::findFunctionsWithoutProfile() { … }
bool SampleProfileMatcher::functionMatchesProfileHelper(
const Function &IRFunc, const FunctionId &ProfFunc) { … }
bool SampleProfileMatcher::functionMatchesProfile(Function &IRFunc,
const FunctionId &ProfFunc,
bool FindMatchedProfileOnly) { … }
void SampleProfileMatcher::UpdateWithSalvagedProfiles() { … }
void SampleProfileMatcher::runOnModule() { … }
void SampleProfileMatcher::distributeIRToProfileLocationMap(
FunctionSamples &FS) { … }
void SampleProfileMatcher::distributeIRToProfileLocationMap() { … }