LLVM  10.0.0svn
Macros | Typedefs | Functions | Variables
SampleProfile.cpp File Reference
#include "llvm/Transforms/IPO/SampleProfile.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Dominators.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/ValueSymbolTable.h"
#include "llvm/Pass.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/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/GenericDomTree.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Transforms/Utils/CallPromotionUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <functional>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <string>
#include <system_error>
#include <utility>
#include <vector>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "sample-profile"
 

Typedefs

using ProfileCount = Function::ProfileCount
 

Functions

static bool callsiteIsHot (const FunctionSamples *CallsiteFS, ProfileSummaryInfo *PSI)
 Return true if the given callsite is hot wrt to hot cutoff threshold. More...
 
static SmallVector< InstrProfValueData, 2 > GetSortedValueDataFromCallTargets (const SampleRecord::CallTargetMap &M)
 Returns the sorted CallTargetMap M by count in descending order. More...
 
 INITIALIZE_PASS_BEGIN (SampleProfileLoaderLegacyPass, "sample-profile", "Sample Profile loader", false, false) INITIALIZE_PASS_END(SampleProfileLoaderLegacyPass
 

Variables

static cl::opt< std::string > SampleProfileFile ("sample-profile-file", cl::init(""), cl::value_desc("filename"), cl::desc("Profile file loaded by -sample-profile"), cl::Hidden)
 
static cl::opt< std::string > SampleProfileRemappingFile ("sample-profile-remapping-file", cl::init(""), cl::value_desc("filename"), cl::desc("Profile remapping file loaded by -sample-profile"), cl::Hidden)
 
static cl::opt< unsignedSampleProfileMaxPropagateIterations ("sample-profile-max-propagate-iterations", cl::init(100), cl::desc("Maximum number of iterations to go through when propagating " "sample block/edge weights through the CFG."))
 
static cl::opt< unsignedSampleProfileRecordCoverage ("sample-profile-check-record-coverage", cl::init(0), cl::value_desc("N"), cl::desc("Emit a warning if less than N% of records in the input profile " "are matched to the IR."))
 
static cl::opt< unsignedSampleProfileSampleCoverage ("sample-profile-check-sample-coverage", cl::init(0), cl::value_desc("N"), cl::desc("Emit a warning if less than N% of samples in the input profile " "are matched to the IR."))
 
static cl::opt< boolNoWarnSampleUnused ("no-warn-sample-unused", cl::init(false), cl::Hidden, cl::desc("Use this option to turn off/on warnings about function with " "samples but without debug information to use those samples. "))
 
static cl::opt< boolProfileSampleAccurate ("profile-sample-accurate", cl::Hidden, cl::init(false), cl::desc("If the sample profile is accurate, we will mark all un-sampled " "callsite and function as having 0 samples. Otherwise, treat " "un-sampled callsites and functions conservatively as unknown. "))
 
sample profile
 
sample Sample Profile loader
 
sample Sample Profile false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "sample-profile"

Definition at line 91 of file SampleProfile.cpp.

Referenced by callsiteIsHot(), and GetSortedValueDataFromCallTargets().

Typedef Documentation

◆ ProfileCount

Definition at line 90 of file SampleProfile.cpp.

Function Documentation

◆ callsiteIsHot()

static bool callsiteIsHot ( const FunctionSamples CallsiteFS,
ProfileSummaryInfo PSI 
)
static

Return true if the given callsite is hot wrt to hot cutoff threshold.

Functions that were inlined in the original binary will be represented in the inline stack in the sample profile. If the profile shows that the original inline decision was "good" (i.e., the callsite is executed frequently), then we will recreate the inline decision and apply the profile from the inlined callsite.

To decide whether an inlined callsite is hot, we compare the callsite sample count with the hot cutoff computed by ProfileSummaryInfo, it is regarded as hot if the count is above the cutoff value.

Definition at line 457 of file SampleProfile.cpp.

References assert(), llvm::SmallVectorTemplateCommon< T >::begin(), C, Callee, llvm::SmallPtrSetImplBase::clear(), llvm::SmallVectorImpl< T >::clear(), llvm::InlineParams::ComputeFullInlineCost, llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::count(), llvm::dbgs(), DEBUG_TYPE, llvm::DominatorTreeBase< NodeT, IsPostDom >::dominates(), E, llvm::empty(), llvm::Module::empty(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::erase(), F(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::sampleprof::FunctionSamples::findCallTargetMapAt(), llvm::sampleprof::FunctionSamples::findFunctionSamplesAt(), llvm::sampleprof::FunctionSamples::findFunctionSamplesMapAt(), llvm::sampleprof::FunctionSamples::findInlinedFunctions(), llvm::sampleprof::FunctionSamples::findSamplesAt(), llvm::ErrorOr< T >::get(), llvm::DILocation::getBaseDiscriminator(), llvm::sampleprof::FunctionSamples::getBodySamples(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, CallBrTy, IterTy >::getCalledFunction(), llvm::sampleprof::FunctionSamples::getCallsiteSamples(), llvm::Instruction::getDebugLoc(), llvm::Function::getEntryBlock(), llvm::sampleprof::FunctionSamples::getEntrySamples(), llvm::sampleprof::FunctionSamples::getFuncNameInModule(), llvm::sampleprof::FunctionSamples::getGUID(), llvm::getInlineCost(), llvm::getInlineParams(), llvm::BasicBlock::getInstList(), llvm::DebugLoc::getLine(), getName(), llvm::Value::getName(), llvm::sampleprof::FunctionSamples::getName(), llvm::sampleprof::FunctionSamples::getOffset(), llvm::ProfileSummaryInfo::getOrCompHotCountThreshold(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::Function::getSubprogram(), llvm::sampleprof::FunctionSamples::getTotalSamples(), I, if(), llvm::InlineFunction(), llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorImpl< T >::insert(), llvm::GlobalValue::isDeclaration(), llvm::ProfileSummaryInfo::isHotCount(), llvm::isLegalToPromote(), llvm::InlineCost::isNever(), LLVM_DEBUG, llvm_unreachable, llvm::max(), llvm::None, llvm::pred_begin(), llvm::pred_end(), llvm::pgo::promoteIndirectCall(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::Remark, SI, llvm::sort(), llvm::succ_begin(), llvm::succ_end(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace(), and llvm::RISCVFenceField::W.

◆ GetSortedValueDataFromCallTargets()

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

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( SampleProfileLoaderLegacyPass  ,
"sample-profile ,
"Sample Profile loader ,
false  ,
false   
)

Variable Documentation

◆ false

sample Sample Profile false

Definition at line 1623 of file SampleProfile.cpp.

◆ loader

sample Sample Profile loader

Definition at line 1623 of file SampleProfile.cpp.

◆ NoWarnSampleUnused

cl::opt<bool> NoWarnSampleUnused("no-warn-sample-unused", cl::init(false), cl::Hidden, cl::desc("Use this option to turn off/on warnings about function with " "samples but without debug information to use those samples. "))
static

◆ profile

sample profile

Definition at line 1623 of file SampleProfile.cpp.

◆ ProfileSampleAccurate

cl::opt<bool> ProfileSampleAccurate("profile-sample-accurate", cl::Hidden, cl::init(false), cl::desc("If the sample profile is accurate, we will mark all un-sampled " "callsite and function as having 0 samples. Otherwise, treat " "un-sampled callsites and functions conservatively as unknown. "))
static

◆ SampleProfileFile

cl::opt<std::string> SampleProfileFile("sample-profile-file", cl::init(""), cl::value_desc("filename"), cl::desc("Profile file loaded by -sample-profile"), cl::Hidden)
static

◆ SampleProfileMaxPropagateIterations

cl::opt<unsigned> SampleProfileMaxPropagateIterations("sample-profile-max-propagate-iterations", cl::init(100), cl::desc("Maximum number of iterations to go through when propagating " "sample block/edge weights through the CFG."))
static

◆ SampleProfileRecordCoverage

cl::opt<unsigned> SampleProfileRecordCoverage("sample-profile-check-record-coverage", cl::init(0), cl::value_desc("N"), cl::desc("Emit a warning if less than N% of records in the input profile " "are matched to the IR."))
static

◆ SampleProfileRemappingFile

cl::opt<std::string> SampleProfileRemappingFile("sample-profile-remapping-file", cl::init(""), cl::value_desc("filename"), cl::desc("Profile remapping file loaded by -sample-profile"), cl::Hidden)
static

◆ SampleProfileSampleCoverage

cl::opt<unsigned> SampleProfileSampleCoverage("sample-profile-check-sample-coverage", cl::init(0), cl::value_desc("N"), cl::desc("Emit a warning if less than N% of samples in the input profile " "are matched to the IR."))
static