61 using namespace sampleprof;
63 #define DEBUG_TYPE "sample-profile"
71 "sample-profile-max-propagate-iterations",
cl::init(100),
72 cl::desc(
"Maximum number of iterations to go through when propagating "
73 "sample block/edge weights through the CFG."));
76 cl::desc(
"Emit a warning if less than N% of records in the input profile "
77 "are matched to the IR."));
80 cl::desc(
"Emit a warning if less than N% of samples in the input profile "
81 "are matched to the IR."));
84 cl::desc(
"Inlined functions that account for more than N% of all samples "
85 "collected in the parent function, will be inlined again."));
90 typedef std::pair<const BasicBlock *, const BasicBlock *> Edge;
95 class SampleCoverageTracker {
97 SampleCoverageTracker() : SampleCoverage(), TotalUsedSamples(0) {}
100 uint32_t Discriminator, uint64_t Samples);
101 unsigned computeCoverage(
unsigned Used,
unsigned Total)
const;
104 uint64_t getTotalUsedSamples()
const {
return TotalUsedSamples; }
107 SampleCoverage.clear();
108 TotalUsedSamples = 0;
112 typedef std::map<LineLocation, unsigned> BodySampleCoverageMap;
114 FunctionSamplesCoverageMap;
125 FunctionSamplesCoverageMap SampleCoverage;
138 uint64_t TotalUsedSamples;
146 class SampleProfileLoader {
149 : DT(nullptr), PDT(nullptr), LI(nullptr), ACT(nullptr), Reader(),
150 Samples(nullptr), Filename(
Name), ProfileIsValid(
false),
151 TotalCollectedSamples(0) {}
153 bool doInitialization(
Module &M);
154 bool runOnModule(
Module &M);
157 void dump() { Reader->dump(); }
166 std::vector<const FunctionSamples *>
167 findIndirectCallFunctionSamples(
const Instruction &
I)
const;
175 void findEquivalenceClasses(
Function &
F);
176 template <
bool IsPostDom>
181 uint64_t visitEdge(Edge
E,
unsigned *NumUnknownEdges, Edge *UnknownEdge);
183 bool propagateThroughEdges(
Function &
F,
bool UpdateBlockCount);
184 void computeDominanceAndLoopInfo(
Function &
F);
186 void clearFunctionData();
192 BlockWeightMap BlockWeights;
198 EdgeWeightMap EdgeWeights;
212 EquivalenceClassMap EquivalenceClass;
221 std::unique_ptr<DominatorTree> DT;
222 std::unique_ptr<PostDomTreeBase<BasicBlock>> PDT;
223 std::unique_ptr<LoopInfo> LI;
228 BlockEdgeMap Predecessors;
231 BlockEdgeMap Successors;
233 SampleCoverageTracker CoverageTracker;
236 std::unique_ptr<SampleProfileReader> Reader;
242 std::string Filename;
251 uint64_t TotalCollectedSamples;
254 class SampleProfileLoaderLegacyPass :
public ModulePass {
265 void dump() { SampleLoader.dump(); }
267 bool doInitialization(
Module &M)
override {
268 return SampleLoader.doInitialization(M);
270 StringRef getPassName()
const override {
return "Sample profile pass"; }
271 bool runOnModule(
Module &M)
override;
278 SampleProfileLoader SampleLoader;
301 if (ParentTotalSamples == 0)
305 if (CallsiteTotalSamples == 0)
308 double PercentSamples =
309 (double)CallsiteTotalSamples / (
double)ParentTotalSamples * 100.0;
323 unsigned &Count = SampleCoverage[FS][Loc];
324 bool FirstTime = (++Count == 1);
326 TotalUsedSamples += Samples;
334 SampleCoverageTracker::countUsedRecords(
const FunctionSamples *FS)
const {
335 auto I = SampleCoverage.find(FS);
339 unsigned Count = (
I != SampleCoverage.end()) ?
I->second.size() : 0;
345 for (
const auto &J :
I.second) {
347 if (callsiteIsHot(FS, CalleeSamples))
348 Count += countUsedRecords(CalleeSamples);
358 SampleCoverageTracker::countBodyRecords(
const FunctionSamples *FS)
const {
363 for (
const auto &J :
I.second) {
365 if (callsiteIsHot(FS, CalleeSamples))
366 Count += countBodyRecords(CalleeSamples);
376 SampleCoverageTracker::countBodySamples(
const FunctionSamples *FS)
const {
379 Total +=
I.second.getSamples();
383 for (
const auto &J :
I.second) {
385 if (callsiteIsHot(FS, CalleeSamples))
386 Total += countBodySamples(CalleeSamples);
397 unsigned SampleCoverageTracker::computeCoverage(
unsigned Used,
398 unsigned Total)
const {
400 "number of used records cannot exceed the total number of records");
401 return Total > 0 ? Used * 100 / Total : 100;
405 void SampleProfileLoader::clearFunctionData() {
406 BlockWeights.clear();
408 VisitedBlocks.clear();
409 VisitedEdges.clear();
410 EquivalenceClass.clear();
414 Predecessors.clear();
416 CoverageTracker.clear();
422 return (DIL->getLine() - DIL->getScope()->getSubprogram()->getLine()) &
430 void SampleProfileLoader::printEdgeWeight(
raw_ostream &OS, Edge
E) {
431 OS <<
"weight[" << E.first->getName() <<
"->" << E.second->getName()
432 <<
"]: " << EdgeWeights[
E] <<
"\n";
439 void SampleProfileLoader::printBlockEquivalence(
raw_ostream &OS,
441 const BasicBlock *Equiv = EquivalenceClass[BB];
442 OS <<
"equivalence[" << BB->
getName()
443 <<
"]: " << ((Equiv) ? EquivalenceClass[BB]->
getName() :
"NONE") <<
"\n";
450 void SampleProfileLoader::printBlockWeight(
raw_ostream &OS,
452 const auto &
I = BlockWeights.find(BB);
453 uint64_t W = (
I == BlockWeights.end() ? 0 :
I->second);
454 OS <<
"weight[" << BB->
getName() <<
"]: " << W <<
"\n";
471 return std::error_code();
475 return std::error_code();
480 if (isa<BranchInst>(Inst) || isa<IntrinsicInst>(Inst))
481 return std::error_code();
486 if ((isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) &&
487 findCalleeFunctionSamples(Inst))
496 CoverageTracker.markSamplesUsed(FS, LineOffset, Discriminator, R.
get());
503 " samples from profile (offset: " +
Twine(LineOffset) +
504 ((Discriminator) ?
Twine(
".") +
Twine(Discriminator) :
"") +
")");
508 <<
" (line offset: " << LineOffset <<
"."
525 bool HasWeight =
false;
542 bool SampleProfileLoader::computeBlockWeights(
Function &F) {
543 bool Changed =
false;
545 for (
const auto &BB : F) {
548 BlockWeights[&BB] = Weight.
get();
549 VisitedBlocks.insert(&BB);
571 SampleProfileLoader::findCalleeFunctionSamples(
const Instruction &Inst)
const {
578 if (
const CallInst *CI = dyn_cast<CallInst>(&Inst))
579 if (
Function *Callee = CI->getCalledFunction())
580 CalleeName = Callee->getName();
592 std::vector<const FunctionSamples *>
593 SampleProfileLoader::findIndirectCallFunctionSamples(
596 std::vector<const FunctionSamples *> R;
610 for (
const auto &NameFS : *M) {
611 R.push_back(&NameFS.second);
631 SampleProfileLoader::findFunctionSamples(
const Instruction &Inst)
const {
638 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
641 PrevDIL->getScope()->getSubprogram()->getLinkageName()));
647 for (
int i = S.
size() - 1; i >= 0 && FS !=
nullptr; i--) {
666 bool SampleProfileLoader::inlineHotFunctions(
669 bool Changed =
false;
671 std::function<AssumptionCache &(Function &)> GetAssumptionCache = [&](
674 bool LocalChanged =
false;
681 if ((isa<CallInst>(
I) || isa<InvokeInst>(
I)) &&
682 !isa<IntrinsicInst>(
I) && (FS = findCalleeFunctionSamples(
I))) {
684 if (callsiteIsHot(Samples, FS))
696 if (CalledFunction == &F)
699 if (!CalledFunction && !PromotedInsns.
count(
I) &&
701 for (
const auto *FS : findIndirectCallFunctionSamples(*
I)) {
702 auto CalleeFunctionName = FS->
getName();
708 if (CalleeFunctionName == F.getName())
710 const char *Reason =
"Callee function not available";
711 auto R = SymbolMap.
find(CalleeFunctionName);
712 if (R == SymbolMap.end())
714 CalledFunction = R->getValue();
725 DEBUG(
dbgs() <<
"\nFailed to promote indirect call to "
726 << CalleeFunctionName <<
" because " << Reason
732 findCalleeFunctionSamples(*I)->findImportedFunctions(
733 ImportGUIDs, F.getParent(),
741 Twine(
"inlined hot callee '") +
742 CalledFunction->
getName() +
"' into '" +
778 template <
bool IsPostDom>
779 void SampleProfileLoader::findEquivalencesFor(
783 uint64_t Weight = BlockWeights[EC];
784 for (
const auto *BB2 : Descendants) {
785 bool IsDomParent = DomTree->
dominates(BB2, BB1);
786 bool IsInSameLoop = LI->getLoopFor(BB1) == LI->getLoopFor(BB2);
787 if (BB1 != BB2 && IsDomParent && IsInSameLoop) {
788 EquivalenceClass[BB2] = EC;
790 if (VisitedBlocks.count(BB2)) {
791 VisitedBlocks.insert(EC);
802 Weight =
std::max(Weight, BlockWeights[BB2]);
806 BlockWeights[EC] = Samples->getHeadSamples() + 1;
808 BlockWeights[EC] = Weight;
821 void SampleProfileLoader::findEquivalenceClasses(
Function &F) {
823 DEBUG(
dbgs() <<
"\nBlock equivalence classes\n");
829 if (EquivalenceClass.count(BB1)) {
830 DEBUG(printBlockEquivalence(
dbgs(), BB1));
835 EquivalenceClass[BB1] = BB1;
847 DominatedBBs.
clear();
848 DT->getDescendants(BB1, DominatedBBs);
849 findEquivalencesFor(BB1, DominatedBBs, PDT.get());
851 DEBUG(printBlockEquivalence(
dbgs(), BB1));
860 DEBUG(
dbgs() <<
"\nAssign the same weight to all blocks in the same class\n");
863 const BasicBlock *EquivBB = EquivalenceClass[BB];
865 BlockWeights[BB] = BlockWeights[EquivBB];
880 uint64_t SampleProfileLoader::visitEdge(Edge E,
unsigned *NumUnknownEdges,
882 if (!VisitedEdges.count(E)) {
883 (*NumUnknownEdges)++;
888 return EdgeWeights[
E];
904 bool SampleProfileLoader::propagateThroughEdges(
Function &F,
905 bool UpdateBlockCount) {
906 bool Changed =
false;
907 DEBUG(
dbgs() <<
"\nPropagation through edges\n");
908 for (
const auto &BI : F) {
917 for (
unsigned i = 0; i < 2; i++) {
918 uint64_t TotalWeight = 0;
919 unsigned NumUnknownEdges = 0, NumTotalEdges = 0;
920 Edge UnknownEdge, SelfReferentialEdge, SingleEdge;
924 NumTotalEdges = Predecessors[BB].size();
925 for (
auto *Pred : Predecessors[BB]) {
926 Edge E = std::make_pair(Pred, BB);
927 TotalWeight += visitEdge(E, &NumUnknownEdges, &UnknownEdge);
928 if (E.first == E.second)
929 SelfReferentialEdge =
E;
931 if (NumTotalEdges == 1) {
932 SingleEdge = std::make_pair(Predecessors[BB][0], BB);
936 NumTotalEdges = Successors[BB].size();
937 for (
auto *Succ : Successors[BB]) {
938 Edge E = std::make_pair(BB, Succ);
939 TotalWeight += visitEdge(E, &NumUnknownEdges, &UnknownEdge);
941 if (NumTotalEdges == 1) {
942 SingleEdge = std::make_pair(BB, Successors[BB][0]);
969 if (NumUnknownEdges <= 1) {
970 uint64_t &BBWeight = BlockWeights[EC];
971 if (NumUnknownEdges == 0) {
972 if (!VisitedBlocks.count(EC)) {
976 if (TotalWeight > BBWeight) {
977 BBWeight = TotalWeight;
979 DEBUG(
dbgs() <<
"All edge weights for " << BB->getName()
980 <<
" known. Set weight for block: ";
981 printBlockWeight(
dbgs(), BB););
983 }
else if (NumTotalEdges == 1 &&
984 EdgeWeights[SingleEdge] < BlockWeights[EC]) {
987 EdgeWeights[SingleEdge] = BlockWeights[EC];
990 }
else if (NumUnknownEdges == 1 && VisitedBlocks.count(EC)) {
993 if (BBWeight >= TotalWeight)
994 EdgeWeights[UnknownEdge] = BBWeight - TotalWeight;
996 EdgeWeights[UnknownEdge] = 0;
999 OtherEC = EquivalenceClass[UnknownEdge.first];
1001 OtherEC = EquivalenceClass[UnknownEdge.second];
1003 if (VisitedBlocks.count(OtherEC) &&
1004 EdgeWeights[UnknownEdge] > BlockWeights[OtherEC])
1005 EdgeWeights[UnknownEdge] = BlockWeights[OtherEC];
1006 VisitedEdges.insert(UnknownEdge);
1008 DEBUG(
dbgs() <<
"Set weight for edge: ";
1009 printEdgeWeight(
dbgs(), UnknownEdge));
1011 }
else if (VisitedBlocks.count(EC) && BlockWeights[EC] == 0) {
1014 for (
auto *Pred : Predecessors[BB]) {
1015 Edge E = std::make_pair(Pred, BB);
1017 VisitedEdges.insert(E);
1020 for (
auto *Succ : Successors[BB]) {
1021 Edge E = std::make_pair(BB, Succ);
1023 VisitedEdges.insert(E);
1026 }
else if (SelfReferentialEdge.first && VisitedBlocks.count(EC)) {
1027 uint64_t &BBWeight = BlockWeights[BB];
1029 if (BBWeight >= TotalWeight)
1030 EdgeWeights[SelfReferentialEdge] = BBWeight - TotalWeight;
1032 EdgeWeights[SelfReferentialEdge] = 0;
1033 VisitedEdges.insert(SelfReferentialEdge);
1035 DEBUG(
dbgs() <<
"Set self-referential edge weight to: ";
1036 printEdgeWeight(
dbgs(), SelfReferentialEdge));
1038 if (UpdateBlockCount && !VisitedBlocks.count(EC) && TotalWeight > 0) {
1039 BlockWeights[EC] = TotalWeight;
1040 VisitedBlocks.insert(EC);
1053 void SampleProfileLoader::buildEdges(
Function &F) {
1054 for (
auto &BI : F) {
1059 if (!Predecessors[B1].empty())
1063 if (Visited.
insert(B2).second)
1064 Predecessors[B1].push_back(B2);
1069 if (!Successors[B1].empty())
1073 if (Visited.
insert(B2).second)
1074 Successors[B1].push_back(B2);
1086 Sum +=
I->getValue();
1090 [](
const InstrProfValueData &
L,
const InstrProfValueData &R) {
1091 if (L.Count == R.Count)
1092 return L.Value > R.Value;
1094 return L.Count > R.Count;
1116 void SampleProfileLoader::propagateWeights(
Function &F) {
1117 bool Changed =
true;
1122 for (
auto &BI : F) {
1124 Loop *L = LI->getLoopFor(BB);
1129 if (Header && BlockWeights[BB] > BlockWeights[Header]) {
1130 BlockWeights[Header] = BlockWeights[BB];
1143 Changed = propagateThroughEdges(F,
false);
1149 VisitedEdges.clear();
1152 Changed = propagateThroughEdges(F,
false);
1159 Changed = propagateThroughEdges(F,
true);
1164 DEBUG(
dbgs() <<
"\nPropagation complete. Setting branch weights\n");
1167 for (
auto &BI : F) {
1170 if (BlockWeights[BB]) {
1171 for (
auto &I : BB->getInstList()) {
1172 if (!isa<CallInst>(I) && !isa<InvokeInst>(
I))
1175 if (!
CS.getCalledFunction()) {
1176 const DebugLoc &DLoc = I.getDebugLoc();
1187 if (!
T ||
T.get().size() == 0)
1192 SortedCallTargets, Sum, IPVK_IndirectCallTarget,
1193 SortedCallTargets.
size());
1194 }
else if (!dyn_cast<IntrinsicInst>(&I)) {
1204 if (!isa<BranchInst>(TI) && !isa<SwitchInst>(TI))
1208 DEBUG(
dbgs() <<
"\nGetting weights for branch at line "
1210 :
Twine(
"<UNKNOWN LOCATION>"))
1217 Edge E = std::make_pair(BB, Succ);
1218 uint64_t Weight = EdgeWeights[
E];
1224 DEBUG(
dbgs() <<
" (saturated due to uint32_t overflow)");
1229 Weights.
push_back(static_cast<uint32_t>(Weight + 1));
1231 if (Weight > MaxWeight) {
1238 uint64_t TempWeight;
1245 DEBUG(
dbgs() <<
"SUCCESS. Found non-zero weights.\n");
1247 MDB.createBranchWeights(Weights));
1250 Twine(
"most popular destination for conditional branches at ") +
1251 ((BranchLoc) ?
Twine(BranchLoc->getFilename() +
":" +
1254 :
Twine(
"<UNKNOWN LOCATION>")));
1256 DEBUG(
dbgs() <<
"SKIPPED. All branch weights are zero.\n");
1272 unsigned SampleProfileLoader::getFunctionLoc(
Function &F) {
1274 return S->getLine();
1279 "No debug information found in function " + F.
getName() +
1280 ": Function profile not used",
1285 void SampleProfileLoader::computeDominanceAndLoopInfo(
Function &F) {
1290 PDT->recalculate(F);
1345 bool SampleProfileLoader::emitAnnotations(
Function &F) {
1346 bool Changed =
false;
1348 if (getFunctionLoc(F) == 0)
1352 <<
": " << getFunctionLoc(F) <<
"\n");
1355 Changed |= inlineHotFunctions(F, ImportGUIDs);
1358 Changed |= computeBlockWeights(F);
1365 F.
setEntryCount(Samples->getHeadSamples() + 1, &ImportGUIDs);
1368 computeDominanceAndLoopInfo(F);
1371 findEquivalenceClasses(F);
1374 propagateWeights(F);
1379 unsigned Used = CoverageTracker.countUsedRecords(Samples);
1380 unsigned Total = CoverageTracker.countBodyRecords(Samples);
1381 unsigned Coverage = CoverageTracker.computeCoverage(Used, Total);
1385 Twine(Used) +
" of " +
Twine(Total) +
" available profile records (" +
1386 Twine(Coverage) +
"%) were applied",
1392 uint64_t Used = CoverageTracker.getTotalUsedSamples();
1393 uint64_t Total = CoverageTracker.countBodySamples(Samples);
1394 unsigned Coverage = CoverageTracker.computeCoverage(Used, Total);
1398 Twine(Used) +
" of " +
Twine(Total) +
" available profile samples (" +
1399 Twine(Coverage) +
"%) were applied",
1408 "Sample Profile loader",
false,
false)
1413 bool SampleProfileLoader::doInitialization(
Module &M) {
1414 auto &Ctx = M.getContext();
1416 if (std::error_code EC = ReaderOrErr.getError()) {
1417 std::string Msg =
"Could not open profile: " + EC.message();
1421 Reader = std::move(ReaderOrErr.get());
1431 return new SampleProfileLoaderLegacyPass(Name);
1434 bool SampleProfileLoader::runOnModule(
Module &M) {
1435 if (!ProfileIsValid)
1439 for (
const auto &I : Reader->getProfiles())
1440 TotalCollectedSamples += I.second.getTotalSamples();
1444 std::string OrigName = N_F.getKey();
1448 SymbolMap[OrigName] =
F;
1449 auto pos = OrigName.find(
'.');
1450 if (pos != std::string::npos) {
1451 std::string NewName = OrigName.substr(0, pos);
1452 auto r = SymbolMap.insert(std::make_pair(NewName, F));
1458 r.first->second =
nullptr;
1462 bool retval =
false;
1465 clearFunctionData();
1466 retval |= runOnFunction(F);
1468 if (M.getProfileSummary() ==
nullptr)
1469 M.setProfileSummary(Reader->getSummary().getMD(M.getContext()));
1473 bool SampleProfileLoaderLegacyPass::runOnModule(
Module &M) {
1475 SampleLoader.setACT(&getAnalysis<AssumptionCacheTracker>());
1476 return SampleLoader.runOnModule(M);
1479 bool SampleProfileLoader::runOnFunction(
Function &F) {
1481 Samples = Reader->getSamplesFor(F);
1482 if (Samples && !Samples->empty())
1483 return emitAnnotations(F);
1490 SampleProfileLoader SampleLoader(
1493 SampleLoader.doInitialization(M);
1495 if (!SampleLoader.runOnModule(M))
void push_back(const T &Elt)
Represents either an error or a value T.
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const BodySampleMap & getBodySamples() const
Return all the samples collected in the body of the function.
A Module instance is used to store all the information related to an LLVM module. ...
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Implements a dense probed hash-table based set.
This class represents a function call, abstracting a target machine's calling convention.
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of .assume calls within a function.
static ErrorOr< std::unique_ptr< SampleProfileReader > > create(const Twine &Filename, LLVMContext &C)
Create a sample profile reader appropriate to the file format.
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
const StringRef & getName() const
Return the function name.
InlineFunctionInfo - This class captures the data input to the InlineFunction call, and records the auxiliary results produced by it.
BlockT * getHeader() const
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
StringRef getName() const
Return a constant reference to the value's name.
Representation of the samples collected for a function.
bool InlineFunction(CallInst *C, InlineFunctionInfo &IFI, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true)
InlineFunction - This function inlines the called function into the basic block of the caller...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
static uint64_t SortCallTargets(SmallVector< InstrProfValueData, 2 > &Sorted, const SampleRecord::CallTargetMap &M)
Sorts the CallTargetMap M by count in descending order and stores the sorted result in Sorted...
static StringRef getName(Value *V)
StringRef getFilename() const
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
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)
ModulePass * createSampleProfileLoaderPass()
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Interval::succ_iterator succ_end(Interval *I)
Core dominator tree base class.
const FunctionSamples * findFunctionSamplesAt(const LineLocation &Loc, StringRef CalleeName) const
Returns a pointer to FunctionSamples at the given callsite location Loc with callee CalleeName...
void emitOptimizationRemark(LLVMContext &Ctx, const char *PassName, const Function &Fn, const DiagnosticLocation &Loc, const Twine &Msg)
Legacy interface to emit an optimization-applied message.
initializer< Ty > init(const Ty &Val)
bool isIndirectCall() const
Return true if the callsite is an indirect call.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Subclasses of this class are all able to terminate a basic block.
A set of analyses that are preserved following a run of a transformation pass.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(const ValueT &V)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Represent the analysis usage information of a pass.
bool isLegalToPromote(Instruction *Inst, Function *F, const char **Reason)
const InstListType & getInstList() const
Return the underlying instruction list container.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
Interval::pred_iterator pred_end(Interval *I)
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
Instruction * promoteIndirectCall(Instruction *Inst, Function *F, uint64_t Count, uint64_t TotalCount, bool AttachProfToDirectCall)
void initializeSampleProfileLoaderLegacyPassPass(PassRegistry &)
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...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
void setEntryCount(uint64_t Count, const DenseSet< GlobalValue::GUID > *Imports=nullptr)
Set the entry count for this function.
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
ErrorOr< SampleRecord::CallTargetMap > findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const
Returns the call target map collected at a given location.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static 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."))
Module.h This file contains the declarations for the Module class.
const BasicBlock & getEntryBlock() const
static 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."))
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
DISubprogram * getSubprogram() const
Get the attached subprogram.
static void clear(coro::Shape &Shape)
iterator insert(iterator I, T &&Elt)
llvm_unreachable("Unknown RegBank!")
static cl::opt< double > SampleProfileHotThreshold("sample-profile-inline-hot-threshold", cl::init(0.1), cl::value_desc("N"), cl::desc("Inlined functions that account for more than N% of all samples ""collected in the parent function, will be inlined again."))
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Represents the relative location of an instruction.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Represents a single loop in the control flow graph.
static 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."))
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
sample Sample Profile false
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
INITIALIZE_PASS_BEGIN(SampleProfileLoaderLegacyPass,"sample-profile","Sample Profile loader", false, false) INITIALIZE_PASS_END(SampleProfileLoaderLegacyPass
Provides ErrorOr<T> smart pointer.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const FunctionSamplesMap * findFunctionSamplesMapAt(const LineLocation &Loc) const
Returns the FunctionSamplesMap at the given Loc.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
sample Sample Profile loader
This class implements an extremely fast bulk output stream that can only output to a stream...
ErrorOr< uint64_t > findSamplesAt(uint32_t LineOffset, uint32_t Discriminator) const
Return the number of samples collected at the given location.
StringRef - Represent a constant reference to a string, i.e.
A container for analyses that lazily runs them and caches their results.
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
Diagnostic information for the sample profiler.
const Instruction * getFirstNonPHIOrDbgOrLifetime() const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic...
const BasicBlock * getParent() const
This file provides the interface for the sampled PGO loader pass.