#include "llvm/Transforms/IPO/SampleProfileProbe.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/EHUtils.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PseudoProbe.h"
#include "llvm/ProfileData/SampleProf.h"
#include "llvm/Support/CRC.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Utils/Instrumentation.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include <unordered_set>
#include <vector>
usingnamespacellvm;
#define DEBUG_TYPE …
STATISTIC(ArtificialDbgLine,
"Number of probes that have an artificial debug line");
static cl::opt<bool>
VerifyPseudoProbe("verify-pseudo-probe", cl::init(false), cl::Hidden,
cl::desc("Do pseudo probe verification"));
static cl::list<std::string> VerifyPseudoProbeFuncList(
"verify-pseudo-probe-funcs", cl::Hidden,
cl::desc("The option to specify the name of the functions to verify."));
static cl::opt<bool>
UpdatePseudoProbe("update-pseudo-probe", cl::init(true), cl::Hidden,
cl::desc("Update pseudo probe distribution factor"));
static uint64_t getCallStackHash(const DILocation *DIL) { … }
static uint64_t computeCallStackHash(const Instruction &Inst) { … }
bool PseudoProbeVerifier::shouldVerifyFunction(const Function *F) { … }
void PseudoProbeVerifier::registerCallbacks(PassInstrumentationCallbacks &PIC) { … }
void PseudoProbeVerifier::runAfterPass(StringRef PassID, Any IR) { … }
void PseudoProbeVerifier::runAfterPass(const Module *M) { … }
void PseudoProbeVerifier::runAfterPass(const LazyCallGraph::SCC *C) { … }
void PseudoProbeVerifier::runAfterPass(const Function *F) { … }
void PseudoProbeVerifier::runAfterPass(const Loop *L) { … }
void PseudoProbeVerifier::collectProbeFactors(const BasicBlock *Block,
ProbeFactorMap &ProbeFactors) { … }
void PseudoProbeVerifier::verifyProbeFactors(
const Function *F, const ProbeFactorMap &ProbeFactors) { … }
SampleProfileProber::SampleProfileProber(Function &Func,
const std::string &CurModuleUniqueId)
: … { … }
void SampleProfileProber::computeBlocksToIgnore(
DenseSet<BasicBlock *> &BlocksToIgnore,
DenseSet<BasicBlock *> &BlocksAndCallsToIgnore) { … }
void SampleProfileProber::findUnreachableBlocks(
DenseSet<BasicBlock *> &BlocksToIgnore) { … }
void SampleProfileProber::findInvokeNormalDests(
DenseSet<BasicBlock *> &InvokeNormalDests) { … }
const Instruction *SampleProfileProber::getOriginalTerminator(
const BasicBlock *Head, const DenseSet<BasicBlock *> &BlocksToIgnore) { … }
void SampleProfileProber::computeCFGHash(
const DenseSet<BasicBlock *> &BlocksToIgnore) { … }
void SampleProfileProber::computeProbeId(
const DenseSet<BasicBlock *> &BlocksToIgnore,
const DenseSet<BasicBlock *> &BlocksAndCallsToIgnore) { … }
uint32_t SampleProfileProber::getBlockId(const BasicBlock *BB) const { … }
uint32_t SampleProfileProber::getCallsiteId(const Instruction *Call) const { … }
void SampleProfileProber::instrumentOneFunc(Function &F, TargetMachine *TM) { … }
PreservedAnalyses SampleProfileProbePass::run(Module &M,
ModuleAnalysisManager &AM) { … }
void PseudoProbeUpdatePass::runOnFunction(Function &F,
FunctionAnalysisManager &FAM) { … }
PreservedAnalyses PseudoProbeUpdatePass::run(Module &M,
ModuleAnalysisManager &AM) { … }