Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
SampleProfileLoaderBaseImpl.h
Go to the documentation of this file.
1////===- SampleProfileLoadBaseImpl.h - Profile loader base impl --*- C++-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This file provides the interface for the sampled PGO profile loader base
11/// implementation.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_UTILS_SAMPLEPROFILELOADERBASEIMPL_H
16#define LLVM_TRANSFORMS_UTILS_SAMPLEPROFILELOADERBASEIMPL_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/DenseSet.h"
21#include "llvm/ADT/IntrusiveRefCntPtr.h"
22#include "llvm/ADT/SmallPtrSet.h"
23#include "llvm/ADT/SmallSet.h"
24#include "llvm/ADT/SmallVector.h"
25#include "llvm/Analysis/LazyCallGraph.h"
26#include "llvm/Analysis/LoopInfo.h"
27#include "llvm/Analysis/OptimizationRemarkEmitter.h"
28#include "llvm/Analysis/PostDominators.h"
29#include "llvm/IR/BasicBlock.h"
30#include "llvm/IR/CFG.h"
31#include "llvm/IR/DebugInfoMetadata.h"
32#include "llvm/IR/DebugLoc.h"
33#include "llvm/IR/Dominators.h"
34#include "llvm/IR/Function.h"
35#include "llvm/IR/Instruction.h"
36#include "llvm/IR/Instructions.h"
37#include "llvm/IR/Module.h"
38#include "llvm/IR/PseudoProbe.h"
39#include "llvm/ProfileData/SampleProf.h"
40#include "llvm/ProfileData/SampleProfReader.h"
41#include "llvm/Support/CommandLine.h"
42#include "llvm/Support/GenericDomTree.h"
43#include "llvm/Support/raw_ostream.h"
44#include "llvm/Transforms/Utils/SampleProfileInference.h"
45#include "llvm/Transforms/Utils/SampleProfileLoaderBaseUtil.h"
46
47namespacellvm {
48using namespacesampleprof;
49using namespacesampleprofutil;
50usingProfileCount =Function::ProfileCount;
51
52namespacevfs {
53classFileSystem;
54}// namespace vfs
55
56#define DEBUG_TYPE "sample-profile-impl"
57
58namespaceafdo_detail {
59
60template <typename BlockT>structIRTraits;
61template <>structIRTraits<BasicBlock> {
62usingInstructionT =Instruction;
63usingBasicBlockT =BasicBlock;
64usingFunctionT =Function;
65usingBlockFrequencyInfoT =BlockFrequencyInfo;
66usingLoopT =Loop;
67usingLoopInfoPtrT = std::unique_ptr<LoopInfo>;
68usingDominatorTreePtrT = std::unique_ptr<DominatorTree>;
69usingPostDominatorTreeT =PostDominatorTree;
70usingPostDominatorTreePtrT = std::unique_ptr<PostDominatorTree>;
71usingOptRemarkEmitterT =OptimizationRemarkEmitter;
72usingOptRemarkAnalysisT =OptimizationRemarkAnalysis;
73usingPredRangeT =pred_range;
74usingSuccRangeT =succ_range;
75staticFunction &getFunction(Function &F) {returnF; }
76staticconstBasicBlock *getEntryBB(constFunction *F) {
77return &F->getEntryBlock();
78 }
79staticpred_rangegetPredecessors(BasicBlock *BB) {returnpredecessors(BB); }
80staticsucc_rangegetSuccessors(BasicBlock *BB) {returnsuccessors(BB); }
81};
82
83}// end namespace afdo_detail
84
85// This class serves sample counts correlation for SampleProfileLoader by
86// analyzing pseudo probes and their function descriptors injected by
87// SampleProfileProber.
88classPseudoProbeManager {
89DenseMap<uint64_t, PseudoProbeDescriptor> GUIDToProbeDescMap;
90
91public:
92PseudoProbeManager(constModule &M) {
93if (NamedMDNode *FuncInfo =
94 M.getNamedMetadata(PseudoProbeDescMetadataName)) {
95for (constauto *Operand : FuncInfo->operands()) {
96constauto *MD = cast<MDNode>(Operand);
97auto GUID = mdconst::dyn_extract<ConstantInt>(MD->getOperand(0))
98 ->getZExtValue();
99auto Hash = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1))
100 ->getZExtValue();
101 GUIDToProbeDescMap.try_emplace(GUID,PseudoProbeDescriptor(GUID, Hash));
102 }
103 }
104 }
105
106constPseudoProbeDescriptor *getDesc(uint64_t GUID) const{
107autoI = GUIDToProbeDescMap.find(GUID);
108returnI == GUIDToProbeDescMap.end() ? nullptr : &I->second;
109 }
110
111constPseudoProbeDescriptor *getDesc(StringRef FProfileName) const{
112returngetDesc(Function::getGUID(FProfileName));
113 }
114
115constPseudoProbeDescriptor *getDesc(constFunction &F) const{
116returngetDesc(Function::getGUID(FunctionSamples::getCanonicalFnName(F)));
117 }
118
119boolprofileIsHashMismatched(constPseudoProbeDescriptor &FuncDesc,
120constFunctionSamples &Samples) const{
121return FuncDesc.getFunctionHash() != Samples.getFunctionHash();
122 }
123
124boolmoduleIsProbed(constModule &M) const{
125return M.getNamedMetadata(PseudoProbeDescMetadataName);
126 }
127
128boolprofileIsValid(constFunction &F,constFunctionSamples &Samples) const{
129constauto *Desc =getDesc(F);
130bool IsAvailableExternallyLinkage =
131GlobalValue::isAvailableExternallyLinkage(F.getLinkage());
132// Always check the function attribute to determine checksum mismatch for
133// `available_externally` functions even if their desc are available. This
134// is because the desc is computed based on the original internal function
135// and it's substituted by the `available_externally` function during link
136// time. However, when unstable IR or ODR violation issue occurs, the
137// definitions of the same function across different translation units could
138// be different and result in different checksums. So we should use the
139// state from the new (available_externally) function, which is saved in its
140// attribute.
141// TODO: If the function's profile only exists as nested inlinee profile in
142// a different module, we don't have the attr mismatch state(unknown), we
143// need to fix it later.
144if (IsAvailableExternallyLinkage || !Desc)
145return !F.hasFnAttribute("profile-checksum-mismatch");
146
147returnDesc && !profileIsHashMismatched(*Desc, Samples);
148 }
149};
150
151
152
153extern cl::opt<bool>SampleProfileUseProfi;
154
155staticinlineboolskipProfileForFunction(constFunction &F) {
156returnF.isDeclaration() || !F.hasFnAttribute("use-sample-profile");
157}
158
159staticinlinevoid
160buildTopDownFuncOrder(LazyCallGraph &CG,
161 std::vector<Function *> &FunctionOrderList) {
162 CG.buildRefSCCs();
163for (LazyCallGraph::RefSCC &RC : CG.postorder_ref_sccs()) {
164for (LazyCallGraph::SCC &C : RC) {
165for (LazyCallGraph::Node &N :C) {
166Function &F =N.getFunction();
167if (!skipProfileForFunction(F))
168 FunctionOrderList.push_back(&F);
169 }
170 }
171 }
172 std::reverse(FunctionOrderList.begin(), FunctionOrderList.end());
173}
174
175template <typename FT>classSampleProfileLoaderBaseImpl {
176public:
177SampleProfileLoaderBaseImpl(std::stringName, std::string RemapName,
178IntrusiveRefCntPtr<vfs::FileSystem>FS)
179 :Filename(Name),RemappingFilename(RemapName),FS(std::move(FS)) {}
180voiddump() {Reader->dump(); }
181
182usingNodeRef =typenameGraphTraits<FT *>::NodeRef;
183usingBT = std::remove_pointer_t<NodeRef>;
184usingInstructionT =typenameafdo_detail::IRTraits<BT>::InstructionT;
185usingBasicBlockT =typenameafdo_detail::IRTraits<BT>::BasicBlockT;
186usingBlockFrequencyInfoT =
187typenameafdo_detail::IRTraits<BT>::BlockFrequencyInfoT;
188usingFunctionT =typenameafdo_detail::IRTraits<BT>::FunctionT;
189usingLoopT =typenameafdo_detail::IRTraits<BT>::LoopT;
190usingLoopInfoPtrT =typenameafdo_detail::IRTraits<BT>::LoopInfoPtrT;
191usingDominatorTreePtrT =
192typenameafdo_detail::IRTraits<BT>::DominatorTreePtrT;
193usingPostDominatorTreePtrT =
194typenameafdo_detail::IRTraits<BT>::PostDominatorTreePtrT;
195usingPostDominatorTreeT =
196typenameafdo_detail::IRTraits<BT>::PostDominatorTreeT;
197usingOptRemarkEmitterT =
198typenameafdo_detail::IRTraits<BT>::OptRemarkEmitterT;
199usingOptRemarkAnalysisT =
200typenameafdo_detail::IRTraits<BT>::OptRemarkAnalysisT;
201usingPredRangeT =typenameafdo_detail::IRTraits<BT>::PredRangeT;
202usingSuccRangeT =typenameafdo_detail::IRTraits<BT>::SuccRangeT;
203
204usingBlockWeightMap =DenseMap<const BasicBlockT *, uint64_t>;
205usingEquivalenceClassMap =
206DenseMap<const BasicBlockT *, const BasicBlockT *>;
207usingEdge = std::pair<const BasicBlockT *, const BasicBlockT *>;
208usingEdgeWeightMap =DenseMap<Edge, uint64_t>;
209usingBlockEdgeMap =
210DenseMap<const BasicBlockT *, SmallVector<const BasicBlockT *, 8>>;
211
212protected:
213~SampleProfileLoaderBaseImpl() =default;
214friendclassSampleCoverageTracker;
215
216Function &getFunction(FunctionT &F) {
217returnafdo_detail::IRTraits<BT>::getFunction(F);
218 }
219constBasicBlockT *getEntryBB(constFunctionT *F) {
220returnafdo_detail::IRTraits<BT>::getEntryBB(F);
221 }
222PredRangeTgetPredecessors(BasicBlockT *BB) {
223returnafdo_detail::IRTraits<BT>::getPredecessors(BB);
224 }
225SuccRangeTgetSuccessors(BasicBlockT *BB) {
226returnafdo_detail::IRTraits<BT>::getSuccessors(BB);
227 }
228
229unsignedgetFunctionLoc(FunctionT &Func);
230virtualErrorOr<uint64_t>getInstWeight(constInstructionT &Inst);
231ErrorOr<uint64_t>getInstWeightImpl(constInstructionT &Inst);
232virtualErrorOr<uint64_t>getProbeWeight(constInstructionT &Inst);
233ErrorOr<uint64_t>getBlockWeight(constBasicBlockT *BB);
234mutableDenseMap<const DILocation *, const FunctionSamples *>
235DILocation2SampleMap;
236virtualconstFunctionSamples *
237findFunctionSamples(constInstructionT &I)const;
238voidprintEdgeWeight(raw_ostream &OS,EdgeE);
239voidprintBlockWeight(raw_ostream &OS,constBasicBlockT *BB)const;
240voidprintBlockEquivalence(raw_ostream &OS,constBasicBlockT *BB);
241boolcomputeBlockWeights(FunctionT &F);
242voidfindEquivalenceClasses(FunctionT &F);
243voidfindEquivalencesFor(BasicBlockT *BB1,
244ArrayRef<BasicBlockT *> Descendants,
245PostDominatorTreeT *DomTree);
246voidpropagateWeights(FunctionT &F);
247voidapplyProfi(FunctionT &F,BlockEdgeMap &Successors,
248BlockWeightMap &SampleBlockWeights,
249BlockWeightMap &BlockWeights,EdgeWeightMap &EdgeWeights);
250uint64_tvisitEdge(EdgeE,unsigned *NumUnknownEdges,Edge *UnknownEdge);
251voidbuildEdges(FunctionT &F);
252boolpropagateThroughEdges(FunctionT &F,bool UpdateBlockCount);
253voidclearFunctionData(bool ResetDT =true);
254voidcomputeDominanceAndLoopInfo(FunctionT &F);
255bool
256computeAndPropagateWeights(FunctionT &F,
257constDenseSet<GlobalValue::GUID> &InlinedGUIDs);
258voidinitWeightPropagation(FunctionT &F,
259constDenseSet<GlobalValue::GUID> &InlinedGUIDs);
260void
261finalizeWeightPropagation(FunctionT &F,
262constDenseSet<GlobalValue::GUID> &InlinedGUIDs);
263voidemitCoverageRemarks(FunctionT &F);
264
265 /// Map basic blocks to their computed weights.
266 ///
267 /// The weight of a basic block is defined to be the maximum
268 /// of all the instruction weights in that block.
269BlockWeightMapBlockWeights;
270
271 /// Map edges to their computed weights.
272 ///
273 /// Edge weights are computed by propagating basic block weights in
274 /// SampleProfile::propagateWeights.
275EdgeWeightMapEdgeWeights;
276
277 /// Set of visited blocks during propagation.
278SmallPtrSet<const BasicBlockT *, 32>VisitedBlocks;
279
280 /// Set of visited edges during propagation.
281SmallSet<Edge, 32>VisitedEdges;
282
283 /// Equivalence classes for block weights.
284 ///
285 /// Two blocks BB1 and BB2 are in the same equivalence class if they
286 /// dominate and post-dominate each other, and they are in the same loop
287 /// nest. When this happens, the two blocks are guaranteed to execute
288 /// the same number of times.
289EquivalenceClassMapEquivalenceClass;
290
291 /// Dominance, post-dominance and loop information.
292DominatorTreePtrTDT;
293PostDominatorTreePtrTPDT;
294LoopInfoPtrTLI;
295
296 /// Predecessors for each basic block in the CFG.
297BlockEdgeMapPredecessors;
298
299 /// Successors for each basic block in the CFG.
300BlockEdgeMapSuccessors;
301
302 /// Profile coverage tracker.
303SampleCoverageTrackerCoverageTracker;
304
305 /// Profile reader object.
306 std::unique_ptr<SampleProfileReader>Reader;
307
308 /// Synthetic samples created by duplicating the samples of inlined functions
309 /// from the original profile as if they were top level sample profiles.
310 /// Use std::map because insertion may happen while its content is referenced.
311 std::map<SampleContext, FunctionSamples>OutlineFunctionSamples;
312
313// A pseudo probe helper to correlate the imported sample counts.
314 std::unique_ptr<PseudoProbeManager>ProbeManager;
315
316 /// Samples collected for the body of this function.
317FunctionSamples *Samples =nullptr;
318
319 /// Name of the profile file to load.
320 std::stringFilename;
321
322 /// Name of the profile remapping file to load.
323 std::stringRemappingFilename;
324
325 /// VirtualFileSystem to load profile files from.
326IntrusiveRefCntPtr<vfs::FileSystem>FS;
327
328 /// Profile Summary Info computed from sample profile.
329ProfileSummaryInfo *PSI =nullptr;
330
331 /// Optimization Remark Emitter used to emit diagnostic remarks.
332OptRemarkEmitterT *ORE =nullptr;
333};
334
335/// Clear all the per-function data used to load samples and propagate weights.
336template <typename BT>
337voidSampleProfileLoaderBaseImpl<BT>::clearFunctionData(bool ResetDT) {
338 BlockWeights.clear();
339 EdgeWeights.clear();
340 VisitedBlocks.clear();
341 VisitedEdges.clear();
342 EquivalenceClass.clear();
343if (ResetDT) {
344 DT =nullptr;
345 PDT =nullptr;
346 LI =nullptr;
347 }
348 Predecessors.clear();
349 Successors.clear();
350 CoverageTracker.clear();
351}
352
353#ifndef NDEBUG
354/// Print the weight of edge \p E on stream \p OS.
355///
356/// \param OS Stream to emit the output to.
357/// \param E Edge to print.
358template <typename BT>
359voidSampleProfileLoaderBaseImpl<BT>::printEdgeWeight(raw_ostream &OS,EdgeE) {
360OS <<"weight[" <<E.first->getName() <<"->" <<E.second->getName()
361 <<"]: " << EdgeWeights[E] <<"\n";
362}
363
364/// Print the equivalence class of block \p BB on stream \p OS.
365///
366/// \param OS Stream to emit the output to.
367/// \param BB Block to print.
368template <typename BT>
369voidSampleProfileLoaderBaseImpl<BT>::printBlockEquivalence(
370raw_ostream &OS,constBasicBlockT *BB) {
371constBasicBlockT *Equiv = EquivalenceClass[BB];
372OS <<"equivalence[" << BB->getName()
373 <<"]: " << ((Equiv) ? EquivalenceClass[BB]->getName() :"NONE") <<"\n";
374}
375
376/// Print the weight of block \p BB on stream \p OS.
377///
378/// \param OS Stream to emit the output to.
379/// \param BB Block to print.
380template <typename BT>
381voidSampleProfileLoaderBaseImpl<BT>::printBlockWeight(
382raw_ostream &OS,constBasicBlockT *BB) const{
383constauto &I = BlockWeights.find(BB);
384uint64_t W = (I == BlockWeights.end() ? 0 :I->second);
385OS <<"weight[" << BB->getName() <<"]: " << W <<"\n";
386}
387#endif
388
389/// Get the weight for an instruction.
390///
391/// The "weight" of an instruction \p Inst is the number of samples
392/// collected on that instruction at runtime. To retrieve it, we
393/// need to compute the line number of \p Inst relative to the start of its
394/// function. We use HeaderLineno to compute the offset. We then
395/// look up the samples collected for \p Inst using BodySamples.
396///
397/// \param Inst Instruction to query.
398///
399/// \returns the weight of \p Inst.
400template <typename BT>
401ErrorOr<uint64_t>
402SampleProfileLoaderBaseImpl<BT>::getInstWeight(constInstructionT &Inst) {
403if (FunctionSamples::ProfileIsProbeBased)
404return getProbeWeight(Inst);
405return getInstWeightImpl(Inst);
406}
407
408template <typename BT>
409ErrorOr<uint64_t>
410SampleProfileLoaderBaseImpl<BT>::getInstWeightImpl(constInstructionT &Inst) {
411constFunctionSamples *FS = findFunctionSamples(Inst);
412if (!FS)
413return std::error_code();
414
415constDebugLoc &DLoc = Inst.getDebugLoc();
416if (!DLoc)
417return std::error_code();
418
419constDILocation *DIL = DLoc;
420uint32_t LineOffset =FunctionSamples::getOffset(DIL);
421uint32_t Discriminator;
422if (EnableFSDiscriminator)
423 Discriminator = DIL->getDiscriminator();
424else
425 Discriminator = DIL->getBaseDiscriminator();
426
427ErrorOr<uint64_t> R = FS->findSamplesAt(LineOffset, Discriminator);
428if (R) {
429bool FirstMark =
430 CoverageTracker.markSamplesUsed(FS, LineOffset, Discriminator, R.get());
431if (FirstMark) {
432 ORE->emit([&]() {
433OptRemarkAnalysisTRemark(DEBUG_TYPE,"AppliedSamples", &Inst);
434Remark <<"Applied " <<ore::NV("NumSamples", *R);
435Remark <<" samples from profile (offset: ";
436Remark <<ore::NV("LineOffset", LineOffset);
437if (Discriminator) {
438Remark <<".";
439Remark <<ore::NV("Discriminator", Discriminator);
440 }
441Remark <<")";
442returnRemark;
443 });
444 }
445LLVM_DEBUG(dbgs() <<" " << DLoc.getLine() <<"." << Discriminator <<":"
446 << Inst <<" (line offset: " << LineOffset <<"."
447 << Discriminator <<" - weight: " << R.get() <<")\n");
448 }
449return R;
450}
451
452template <typename BT>
453ErrorOr<uint64_t>
454SampleProfileLoaderBaseImpl<BT>::getProbeWeight(constInstructionT &Inst) {
455assert(FunctionSamples::ProfileIsProbeBased &&
456"Profile is not pseudo probe based");
457 std::optional<PseudoProbe> Probe =extractProbe(Inst);
458// Ignore the non-probe instruction. If none of the instruction in the BB is
459// probe, we choose to infer the BB's weight.
460if (!Probe)
461return std::error_code();
462
463constFunctionSamples *FS = findFunctionSamples(Inst);
464if (!FS) {
465// If we can't find the function samples for a probe, it could be due to the
466// probe is later optimized away or the inlining context is mismatced. We
467// treat it as unknown, leaving it to profile inference instead of forcing a
468// zero count.
469return std::error_code();
470 }
471
472auto R = FS->findSamplesAt(Probe->Id, Probe->Discriminator);
473if (R) {
474uint64_t Samples = R.get() * Probe->Factor;
475bool FirstMark = CoverageTracker.markSamplesUsed(FS, Probe->Id, 0, Samples);
476if (FirstMark) {
477 ORE->emit([&]() {
478OptRemarkAnalysisTRemark(DEBUG_TYPE,"AppliedSamples", &Inst);
479Remark <<"Applied " <<ore::NV("NumSamples", Samples);
480Remark <<" samples from profile (ProbeId=";
481Remark <<ore::NV("ProbeId", Probe->Id);
482if (Probe->Discriminator) {
483Remark <<".";
484Remark <<ore::NV("Discriminator", Probe->Discriminator);
485 }
486Remark <<", Factor=";
487Remark <<ore::NV("Factor", Probe->Factor);
488Remark <<", OriginalSamples=";
489Remark <<ore::NV("OriginalSamples", R.get());
490Remark <<")";
491returnRemark;
492 });
493 }
494LLVM_DEBUG({dbgs() <<" " << Probe->Id;
495if (Probe->Discriminator)
496dbgs() <<"." << Probe->Discriminator;
497dbgs() <<":" << Inst <<" - weight: " << R.get()
498 <<" - factor: " <<format("%0.2f", Probe->Factor) <<")\n";});
499return Samples;
500 }
501return R;
502}
503
504/// Compute the weight of a basic block.
505///
506/// The weight of basic block \p BB is the maximum weight of all the
507/// instructions in BB.
508///
509/// \param BB The basic block to query.
510///
511/// \returns the weight for \p BB.
512template <typename BT>
513ErrorOr<uint64_t>
514SampleProfileLoaderBaseImpl<BT>::getBlockWeight(constBasicBlockT *BB) {
515uint64_t Max = 0;
516bool HasWeight =false;
517for (auto &I : *BB) {
518constErrorOr<uint64_t> &R = getInstWeight(I);
519if (R) {
520 Max = std::max(Max, R.get());
521 HasWeight =true;
522 }
523 }
524return HasWeight ?ErrorOr<uint64_t>(Max) : std::error_code();
525}
526
527/// Compute and store the weights of every basic block.
528///
529/// This populates the BlockWeights map by computing
530/// the weights of every basic block in the CFG.
531///
532/// \param F The function to query.
533template <typename BT>
534boolSampleProfileLoaderBaseImpl<BT>::computeBlockWeights(FunctionT &F) {
535bool Changed =false;
536LLVM_DEBUG(dbgs() <<"Block weights\n");
537for (constauto &BB :F) {
538ErrorOr<uint64_t> Weight = getBlockWeight(&BB);
539if (Weight) {
540 BlockWeights[&BB] = Weight.get();
541 VisitedBlocks.insert(&BB);
542 Changed =true;
543 }
544LLVM_DEBUG(printBlockWeight(dbgs(), &BB));
545 }
546
547return Changed;
548}
549
550/// Get the FunctionSamples for an instruction.
551///
552/// The FunctionSamples of an instruction \p Inst is the inlined instance
553/// in which that instruction is coming from. We traverse the inline stack
554/// of that instruction, and match it with the tree nodes in the profile.
555///
556/// \param Inst Instruction to query.
557///
558/// \returns the FunctionSamples pointer to the inlined instance.
559template <typename BT>
560constFunctionSamples *SampleProfileLoaderBaseImpl<BT>::findFunctionSamples(
561constInstructionT &Inst) const{
562constDILocation *DIL = Inst.getDebugLoc();
563if (!DIL)
564return Samples;
565
566auto it = DILocation2SampleMap.try_emplace(DIL,nullptr);
567if (it.second) {
568 it.first->second = Samples->findFunctionSamples(DIL, Reader->getRemapper());
569 }
570return it.first->second;
571}
572
573/// Find equivalence classes for the given block.
574///
575/// This finds all the blocks that are guaranteed to execute the same
576/// number of times as \p BB1. To do this, it traverses all the
577/// descendants of \p BB1 in the dominator or post-dominator tree.
578///
579/// A block BB2 will be in the same equivalence class as \p BB1 if
580/// the following holds:
581///
582/// 1- \p BB1 is a descendant of BB2 in the opposite tree. So, if BB2
583/// is a descendant of \p BB1 in the dominator tree, then BB2 should
584/// dominate BB1 in the post-dominator tree.
585///
586/// 2- Both BB2 and \p BB1 must be in the same loop.
587///
588/// For every block BB2 that meets those two requirements, we set BB2's
589/// equivalence class to \p BB1.
590///
591/// \param BB1 Block to check.
592/// \param Descendants Descendants of \p BB1 in either the dom or pdom tree.
593/// \param DomTree Opposite dominator tree. If \p Descendants is filled
594/// with blocks from \p BB1's dominator tree, then
595/// this is the post-dominator tree, and vice versa.
596template <typename BT>
597voidSampleProfileLoaderBaseImpl<BT>::findEquivalencesFor(
598BasicBlockT *BB1,ArrayRef<BasicBlockT *> Descendants,
599PostDominatorTreeT *DomTree) {
600constBasicBlockT *EC = EquivalenceClass[BB1];
601uint64_t Weight = BlockWeights[EC];
602for (constauto *BB2 : Descendants) {
603bool IsDomParent = DomTree->dominates(BB2, BB1);
604bool IsInSameLoop = LI->getLoopFor(BB1) == LI->getLoopFor(BB2);
605if (BB1 != BB2 && IsDomParent && IsInSameLoop) {
606 EquivalenceClass[BB2] = EC;
607// If BB2 is visited, then the entire EC should be marked as visited.
608if (VisitedBlocks.count(BB2)) {
609 VisitedBlocks.insert(EC);
610 }
611
612// If BB2 is heavier than BB1, make BB2 have the same weight
613// as BB1.
614//
615// Note that we don't worry about the opposite situation here
616// (when BB2 is lighter than BB1). We will deal with this
617// during the propagation phase. Right now, we just want to
618// make sure that BB1 has the largest weight of all the
619// members of its equivalence set.
620 Weight = std::max(Weight, BlockWeights[BB2]);
621 }
622 }
623constBasicBlockT *EntryBB = getEntryBB(EC->getParent());
624if (EC == EntryBB) {
625 BlockWeights[EC] = Samples->getHeadSamples() + 1;
626 }else {
627 BlockWeights[EC] = Weight;
628 }
629}
630
631/// Find equivalence classes.
632///
633/// Since samples may be missing from blocks, we can fill in the gaps by setting
634/// the weights of all the blocks in the same equivalence class to the same
635/// weight. To compute the concept of equivalence, we use dominance and loop
636/// information. Two blocks B1 and B2 are in the same equivalence class if B1
637/// dominates B2, B2 post-dominates B1 and both are in the same loop.
638///
639/// \param F The function to query.
640template <typename BT>
641voidSampleProfileLoaderBaseImpl<BT>::findEquivalenceClasses(FunctionT &F) {
642SmallVector<BasicBlockT *, 8> DominatedBBs;
643LLVM_DEBUG(dbgs() <<"\nBlock equivalence classes\n");
644// Find equivalence sets based on dominance and post-dominance information.
645for (auto &BB :F) {
646BasicBlockT *BB1 = &BB;
647
648// Compute BB1's equivalence class once.
649if (EquivalenceClass.count(BB1)) {
650LLVM_DEBUG(printBlockEquivalence(dbgs(), BB1));
651continue;
652 }
653
654// By default, blocks are in their own equivalence class.
655 EquivalenceClass[BB1] = BB1;
656
657// Traverse all the blocks dominated by BB1. We are looking for
658// every basic block BB2 such that:
659//
660// 1- BB1 dominates BB2.
661// 2- BB2 post-dominates BB1.
662// 3- BB1 and BB2 are in the same loop nest.
663//
664// If all those conditions hold, it means that BB2 is executed
665// as many times as BB1, so they are placed in the same equivalence
666// class by making BB2's equivalence class be BB1.
667 DominatedBBs.clear();
668 DT->getDescendants(BB1, DominatedBBs);
669 findEquivalencesFor(BB1, DominatedBBs, &*PDT);
670
671LLVM_DEBUG(printBlockEquivalence(dbgs(), BB1));
672 }
673
674// Assign weights to equivalence classes.
675//
676// All the basic blocks in the same equivalence class will execute
677// the same number of times. Since we know that the head block in
678// each equivalence class has the largest weight, assign that weight
679// to all the blocks in that equivalence class.
680LLVM_DEBUG(
681dbgs() <<"\nAssign the same weight to all blocks in the same class\n");
682for (auto &BI :F) {
683constBasicBlockT *BB = &BI;
684constBasicBlockT *EquivBB = EquivalenceClass[BB];
685if (BB != EquivBB)
686 BlockWeights[BB] = BlockWeights[EquivBB];
687LLVM_DEBUG(printBlockWeight(dbgs(), BB));
688 }
689}
690
691/// Visit the given edge to decide if it has a valid weight.
692///
693/// If \p E has not been visited before, we copy to \p UnknownEdge
694/// and increment the count of unknown edges.
695///
696/// \param E Edge to visit.
697/// \param NumUnknownEdges Current number of unknown edges.
698/// \param UnknownEdge Set if E has not been visited before.
699///
700/// \returns E's weight, if known. Otherwise, return 0.
701template <typename BT>
702uint64_tSampleProfileLoaderBaseImpl<BT>::visitEdge(EdgeE,
703unsigned *NumUnknownEdges,
704Edge *UnknownEdge) {
705if (!VisitedEdges.count(E)) {
706 (*NumUnknownEdges)++;
707 *UnknownEdge =E;
708return 0;
709 }
710
711return EdgeWeights[E];
712}
713
714/// Propagate weights through incoming/outgoing edges.
715///
716/// If the weight of a basic block is known, and there is only one edge
717/// with an unknown weight, we can calculate the weight of that edge.
718///
719/// Similarly, if all the edges have a known count, we can calculate the
720/// count of the basic block, if needed.
721///
722/// \param F Function to process.
723/// \param UpdateBlockCount Whether we should update basic block counts that
724/// has already been annotated.
725///
726/// \returns True if new weights were assigned to edges or blocks.
727template <typename BT>
728boolSampleProfileLoaderBaseImpl<BT>::propagateThroughEdges(
729FunctionT &F,bool UpdateBlockCount) {
730bool Changed =false;
731LLVM_DEBUG(dbgs() <<"\nPropagation through edges\n");
732for (constauto &BI :F) {
733constBasicBlockT *BB = &BI;
734constBasicBlockT *EC = EquivalenceClass[BB];
735
736// Visit all the predecessor and successor edges to determine
737// which ones have a weight assigned already. Note that it doesn't
738// matter that we only keep track of a single unknown edge. The
739// only case we are interested in handling is when only a single
740// edge is unknown (see setEdgeOrBlockWeight).
741for (unsigned i = 0; i < 2; i++) {
742uint64_t TotalWeight = 0;
743unsigned NumUnknownEdges = 0, NumTotalEdges = 0;
744Edge UnknownEdge, SelfReferentialEdge, SingleEdge;
745
746if (i == 0) {
747// First, visit all predecessor edges.
748 NumTotalEdges = Predecessors[BB].size();
749for (auto *Pred : Predecessors[BB]) {
750EdgeE = std::make_pair(Pred, BB);
751 TotalWeight += visitEdge(E, &NumUnknownEdges, &UnknownEdge);
752if (E.first ==E.second)
753 SelfReferentialEdge =E;
754 }
755if (NumTotalEdges == 1) {
756 SingleEdge = std::make_pair(Predecessors[BB][0], BB);
757 }
758 }else {
759// On the second round, visit all successor edges.
760 NumTotalEdges = Successors[BB].size();
761for (auto *Succ : Successors[BB]) {
762EdgeE = std::make_pair(BB, Succ);
763 TotalWeight += visitEdge(E, &NumUnknownEdges, &UnknownEdge);
764 }
765if (NumTotalEdges == 1) {
766 SingleEdge = std::make_pair(BB, Successors[BB][0]);
767 }
768 }
769
770// After visiting all the edges, there are three cases that we
771// can handle immediately:
772//
773// - All the edge weights are known (i.e., NumUnknownEdges == 0).
774// In this case, we simply check that the sum of all the edges
775// is the same as BB's weight. If not, we change BB's weight
776// to match. Additionally, if BB had not been visited before,
777// we mark it visited.
778//
779// - Only one edge is unknown and BB has already been visited.
780// In this case, we can compute the weight of the edge by
781// subtracting the total block weight from all the known
782// edge weights. If the edges weight more than BB, then the
783// edge of the last remaining edge is set to zero.
784//
785// - There exists a self-referential edge and the weight of BB is
786// known. In this case, this edge can be based on BB's weight.
787// We add up all the other known edges and set the weight on
788// the self-referential edge as we did in the previous case.
789//
790// In any other case, we must continue iterating. Eventually,
791// all edges will get a weight, or iteration will stop when
792// it reaches SampleProfileMaxPropagateIterations.
793if (NumUnknownEdges <= 1) {
794uint64_t &BBWeight = BlockWeights[EC];
795if (NumUnknownEdges == 0) {
796if (!VisitedBlocks.count(EC)) {
797// If we already know the weight of all edges, the weight of the
798// basic block can be computed. It should be no larger than the sum
799// of all edge weights.
800if (TotalWeight > BBWeight) {
801 BBWeight = TotalWeight;
802 Changed =true;
803LLVM_DEBUG(dbgs() <<"All edge weights for " << BB->getName()
804 <<" known. Set weight for block: ";
805 printBlockWeight(dbgs(), BB););
806 }
807 }elseif (NumTotalEdges == 1 &&
808 EdgeWeights[SingleEdge] < BlockWeights[EC]) {
809// If there is only one edge for the visited basic block, use the
810// block weight to adjust edge weight if edge weight is smaller.
811 EdgeWeights[SingleEdge] = BlockWeights[EC];
812 Changed =true;
813 }
814 }elseif (NumUnknownEdges == 1 && VisitedBlocks.count(EC)) {
815// If there is a single unknown edge and the block has been
816// visited, then we can compute E's weight.
817if (BBWeight >= TotalWeight)
818 EdgeWeights[UnknownEdge] = BBWeight - TotalWeight;
819else
820 EdgeWeights[UnknownEdge] = 0;
821constBasicBlockT *OtherEC;
822if (i == 0)
823 OtherEC = EquivalenceClass[UnknownEdge.first];
824else
825 OtherEC = EquivalenceClass[UnknownEdge.second];
826// Edge weights should never exceed the BB weights it connects.
827if (VisitedBlocks.count(OtherEC) &&
828 EdgeWeights[UnknownEdge] > BlockWeights[OtherEC])
829 EdgeWeights[UnknownEdge] = BlockWeights[OtherEC];
830 VisitedEdges.insert(UnknownEdge);
831 Changed =true;
832LLVM_DEBUG(dbgs() <<"Set weight for edge: ";
833 printEdgeWeight(dbgs(), UnknownEdge));
834 }
835 }elseif (VisitedBlocks.count(EC) && BlockWeights[EC] == 0) {
836// If a block Weights 0, all its in/out edges should weight 0.
837if (i == 0) {
838for (auto *Pred : Predecessors[BB]) {
839EdgeE = std::make_pair(Pred, BB);
840 EdgeWeights[E] = 0;
841 VisitedEdges.insert(E);
842 }
843 }else {
844for (auto *Succ : Successors[BB]) {
845EdgeE = std::make_pair(BB, Succ);
846 EdgeWeights[E] = 0;
847 VisitedEdges.insert(E);
848 }
849 }
850 }elseif (SelfReferentialEdge.first && VisitedBlocks.count(EC)) {
851uint64_t &BBWeight = BlockWeights[BB];
852// We have a self-referential edge and the weight of BB is known.
853if (BBWeight >= TotalWeight)
854 EdgeWeights[SelfReferentialEdge] = BBWeight - TotalWeight;
855else
856 EdgeWeights[SelfReferentialEdge] = 0;
857 VisitedEdges.insert(SelfReferentialEdge);
858 Changed =true;
859LLVM_DEBUG(dbgs() <<"Set self-referential edge weight to: ";
860 printEdgeWeight(dbgs(), SelfReferentialEdge));
861 }
862if (UpdateBlockCount && TotalWeight > 0 &&
863 VisitedBlocks.insert(EC).second) {
864 BlockWeights[EC] = TotalWeight;
865 Changed =true;
866 }
867 }
868 }
869
870return Changed;
871}
872
873/// Build in/out edge lists for each basic block in the CFG.
874///
875/// We are interested in unique edges. If a block B1 has multiple
876/// edges to another block B2, we only add a single B1->B2 edge.
877template <typename BT>
878voidSampleProfileLoaderBaseImpl<BT>::buildEdges(FunctionT &F) {
879for (auto &BI :F) {
880BasicBlockT *B1 = &BI;
881
882// Add predecessors for B1.
883SmallPtrSet<BasicBlockT *, 16> Visited;
884if (!Predecessors[B1].empty())
885llvm_unreachable("Found a stale predecessors list in a basic block.");
886for (auto *B2 : getPredecessors(B1))
887if (Visited.insert(B2).second)
888 Predecessors[B1].push_back(B2);
889
890// Add successors for B1.
891 Visited.clear();
892if (!Successors[B1].empty())
893llvm_unreachable("Found a stale successors list in a basic block.");
894for (auto *B2 : getSuccessors(B1))
895if (Visited.insert(B2).second)
896 Successors[B1].push_back(B2);
897 }
898}
899
900/// Propagate weights into edges
901///
902/// The following rules are applied to every block BB in the CFG:
903///
904/// - If BB has a single predecessor/successor, then the weight
905/// of that edge is the weight of the block.
906///
907/// - If all incoming or outgoing edges are known except one, and the
908/// weight of the block is already known, the weight of the unknown
909/// edge will be the weight of the block minus the sum of all the known
910/// edges. If the sum of all the known edges is larger than BB's weight,
911/// we set the unknown edge weight to zero.
912///
913/// - If there is a self-referential edge, and the weight of the block is
914/// known, the weight for that edge is set to the weight of the block
915/// minus the weight of the other incoming edges to that block (if
916/// known).
917template <typename BT>
918voidSampleProfileLoaderBaseImpl<BT>::propagateWeights(FunctionT &F) {
919// Flow-based profile inference is only usable with BasicBlock instantiation
920// of SampleProfileLoaderBaseImpl.
921if (SampleProfileUseProfi) {
922// Prepare block sample counts for inference.
923BlockWeightMap SampleBlockWeights;
924for (constauto &BI :F) {
925ErrorOr<uint64_t> Weight = getBlockWeight(&BI);
926if (Weight)
927 SampleBlockWeights[&BI] = Weight.get();
928 }
929// Fill in BlockWeights and EdgeWeights using an inference algorithm.
930 applyProfi(F, Successors, SampleBlockWeights, BlockWeights, EdgeWeights);
931 }else {
932bool Changed =true;
933unsignedI = 0;
934
935// If BB weight is larger than its corresponding loop's header BB weight,
936// use the BB weight to replace the loop header BB weight.
937for (auto &BI :F) {
938BasicBlockT *BB = &BI;
939LoopT *L = LI->getLoopFor(BB);
940if (!L) {
941continue;
942 }
943BasicBlockT *Header = L->getHeader();
944if (Header && BlockWeights[BB] > BlockWeights[Header]) {
945 BlockWeights[Header] = BlockWeights[BB];
946 }
947 }
948
949// Propagate until we converge or we go past the iteration limit.
950while (Changed &&I++ <SampleProfileMaxPropagateIterations) {
951 Changed = propagateThroughEdges(F,false);
952 }
953
954// The first propagation propagates BB counts from annotated BBs to unknown
955// BBs. The 2nd propagation pass resets edges weights, and use all BB
956// weights to propagate edge weights.
957 VisitedEdges.clear();
958 Changed =true;
959while (Changed &&I++ <SampleProfileMaxPropagateIterations) {
960 Changed = propagateThroughEdges(F,false);
961 }
962
963// The 3rd propagation pass allows adjust annotated BB weights that are
964// obviously wrong.
965 Changed =true;
966while (Changed &&I++ <SampleProfileMaxPropagateIterations) {
967 Changed = propagateThroughEdges(F,true);
968 }
969 }
970}
971
972template <typename FT>
973voidSampleProfileLoaderBaseImpl<FT>::applyProfi(
974FunctionT &F,BlockEdgeMap &Successors,BlockWeightMap &SampleBlockWeights,
975BlockWeightMap &BlockWeights,EdgeWeightMap &EdgeWeights) {
976auto Infer =SampleProfileInference<FT>(F, Successors, SampleBlockWeights);
977 Infer.apply(BlockWeights, EdgeWeights);
978}
979
980/// Generate branch weight metadata for all branches in \p F.
981///
982/// Branch weights are computed out of instruction samples using a
983/// propagation heuristic. Propagation proceeds in 3 phases:
984///
985/// 1- Assignment of block weights. All the basic blocks in the function
986/// are initial assigned the same weight as their most frequently
987/// executed instruction.
988///
989/// 2- Creation of equivalence classes. Since samples may be missing from
990/// blocks, we can fill in the gaps by setting the weights of all the
991/// blocks in the same equivalence class to the same weight. To compute
992/// the concept of equivalence, we use dominance and loop information.
993/// Two blocks B1 and B2 are in the same equivalence class if B1
994/// dominates B2, B2 post-dominates B1 and both are in the same loop.
995///
996/// 3- Propagation of block weights into edges. This uses a simple
997/// propagation heuristic. The following rules are applied to every
998/// block BB in the CFG:
999///
1000/// - If BB has a single predecessor/successor, then the weight
1001/// of that edge is the weight of the block.
1002///
1003/// - If all the edges are known except one, and the weight of the
1004/// block is already known, the weight of the unknown edge will
1005/// be the weight of the block minus the sum of all the known
1006/// edges. If the sum of all the known edges is larger than BB's weight,
1007/// we set the unknown edge weight to zero.
1008///
1009/// - If there is a self-referential edge, and the weight of the block is
1010/// known, the weight for that edge is set to the weight of the block
1011/// minus the weight of the other incoming edges to that block (if
1012/// known).
1013///
1014/// Since this propagation is not guaranteed to finalize for every CFG, we
1015/// only allow it to proceed for a limited number of iterations (controlled
1016/// by -sample-profile-max-propagate-iterations).
1017///
1018/// FIXME: Try to replace this propagation heuristic with a scheme
1019/// that is guaranteed to finalize. A work-list approach similar to
1020/// the standard value propagation algorithm used by SSA-CCP might
1021/// work here.
1022///
1023/// \param F The function to query.
1024///
1025/// \returns true if \p F was modified. Returns false, otherwise.
1026template <typename BT>
1027boolSampleProfileLoaderBaseImpl<BT>::computeAndPropagateWeights(
1028FunctionT &F,constDenseSet<GlobalValue::GUID> &InlinedGUIDs) {
1029bool Changed = (InlinedGUIDs.size() != 0);
1030
1031// Compute basic block weights.
1032 Changed |= computeBlockWeights(F);
1033
1034if (Changed) {
1035// Initialize propagation.
1036 initWeightPropagation(F, InlinedGUIDs);
1037
1038// Propagate weights to all edges.
1039 propagateWeights(F);
1040
1041// Post-process propagated weights.
1042 finalizeWeightPropagation(F, InlinedGUIDs);
1043 }
1044
1045return Changed;
1046}
1047
1048template <typename BT>
1049voidSampleProfileLoaderBaseImpl<BT>::initWeightPropagation(
1050FunctionT &F,constDenseSet<GlobalValue::GUID> &InlinedGUIDs) {
1051// Add an entry count to the function using the samples gathered at the
1052// function entry.
1053// Sets the GUIDs that are inlined in the profiled binary. This is used
1054// for ThinLink to make correct liveness analysis, and also make the IR
1055// match the profiled binary before annotation.
1056getFunction(F).setEntryCount(
1057ProfileCount(Samples->getHeadSamples() + 1,Function::PCT_Real),
1058 &InlinedGUIDs);
1059
1060if (!SampleProfileUseProfi) {
1061// Compute dominance and loop info needed for propagation.
1062 computeDominanceAndLoopInfo(F);
1063
1064// Find equivalence classes.
1065 findEquivalenceClasses(F);
1066 }
1067
1068// Before propagation starts, build, for each block, a list of
1069// unique predecessors and successors. This is necessary to handle
1070// identical edges in multiway branches. Since we visit all blocks and all
1071// edges of the CFG, it is cleaner to build these lists once at the start
1072// of the pass.
1073 buildEdges(F);
1074}
1075
1076template <typename BT>
1077voidSampleProfileLoaderBaseImpl<BT>::finalizeWeightPropagation(
1078FunctionT &F,constDenseSet<GlobalValue::GUID> &InlinedGUIDs) {
1079// If we utilize a flow-based count inference, then we trust the computed
1080// counts and set the entry count as computed by the algorithm. This is
1081// primarily done to sync the counts produced by profi and BFI inference,
1082// which uses the entry count for mass propagation.
1083// If profi produces a zero-value for the entry count, we fallback to
1084// Samples->getHeadSamples() + 1 to avoid functions with zero count.
1085if (SampleProfileUseProfi) {
1086constBasicBlockT *EntryBB = getEntryBB(&F);
1087ErrorOr<uint64_t> EntryWeight = getBlockWeight(EntryBB);
1088if (BlockWeights[EntryBB] > 0) {
1089getFunction(F).setEntryCount(
1090ProfileCount(BlockWeights[EntryBB],Function::PCT_Real),
1091 &InlinedGUIDs);
1092 }
1093 }
1094}
1095
1096template <typename BT>
1097voidSampleProfileLoaderBaseImpl<BT>::emitCoverageRemarks(FunctionT &F) {
1098// If coverage checking was requested, compute it now.
1099constFunction &Func =getFunction(F);
1100if (SampleProfileRecordCoverage) {
1101unsigned Used = CoverageTracker.countUsedRecords(Samples, PSI);
1102unsignedTotal = CoverageTracker.countBodyRecords(Samples, PSI);
1103unsigned Coverage = CoverageTracker.computeCoverage(Used,Total);
1104if (Coverage <SampleProfileRecordCoverage) {
1105 Func.getContext().diagnose(DiagnosticInfoSampleProfile(
1106 Func.getSubprogram()->getFilename(), getFunctionLoc(F),
1107Twine(Used) +" of " +Twine(Total) +" available profile records (" +
1108Twine(Coverage) +"%) were applied",
1109DS_Warning));
1110 }
1111 }
1112
1113if (SampleProfileSampleCoverage) {
1114uint64_t Used = CoverageTracker.getTotalUsedSamples();
1115uint64_tTotal = CoverageTracker.countBodySamples(Samples, PSI);
1116unsigned Coverage = CoverageTracker.computeCoverage(Used,Total);
1117if (Coverage <SampleProfileSampleCoverage) {
1118 Func.getContext().diagnose(DiagnosticInfoSampleProfile(
1119 Func.getSubprogram()->getFilename(), getFunctionLoc(F),
1120Twine(Used) +" of " +Twine(Total) +" available profile samples (" +
1121Twine(Coverage) +"%) were applied",
1122DS_Warning));
1123 }
1124 }
1125}
1126
1127/// Get the line number for the function header.
1128///
1129/// This looks up function \p F in the current compilation unit and
1130/// retrieves the line number where the function is defined. This is
1131/// line 0 for all the samples read from the profile file. Every line
1132/// number is relative to this line.
1133///
1134/// \param F Function object to query.
1135///
1136/// \returns the line number where \p F is defined. If it returns 0,
1137/// it means that there is no debug information available for \p F.
1138template <typename BT>
1139unsignedSampleProfileLoaderBaseImpl<BT>::getFunctionLoc(FunctionT &F) {
1140constFunction &Func =getFunction(F);
1141if (DISubprogram *S = Func.getSubprogram())
1142return S->getLine();
1143
1144if (NoWarnSampleUnused)
1145return 0;
1146
1147// If the start of \p F is missing, emit a diagnostic to inform the user
1148// about the missed opportunity.
1149 Func.getContext().diagnose(DiagnosticInfoSampleProfile(
1150"No debug information found in function " + Func.getName() +
1151": Function profile not used",
1152DS_Warning));
1153return 0;
1154}
1155
1156#undef DEBUG_TYPE
1157
1158}// namespace llvm
1159#endif// LLVM_TRANSFORMS_UTILS_SAMPLEPROFILELOADERBASEIMPL_H
ArrayRef.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
CommandLine.h
DebugInfoMetadata.h
DebugLoc.h
LLVM_DEBUG
#define LLVM_DEBUG(...)
Definition:Debug.h:106
DenseMap.h
This file defines the DenseMap class.
DenseSet.h
This file defines the DenseSet and SmallDenseSet classes.
Dominators.h
Name
std::string Name
Definition:ELFObjHandler.cpp:77
getFunction
static Function * getFunction(Constant *C)
Definition:Evaluator.cpp:235
DEBUG_TYPE
#define DEBUG_TYPE
Definition:GenericCycleImpl.h:31
GenericDomTree.h
This file defines a set of templates that efficiently compute a dominator tree over a generic graph.
BasicBlock.h
CFG.h
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Function.h
Instruction.h
Module.h
Module.h This file contains the declarations for the Module class.
Instructions.h
IntrusiveRefCntPtr.h
This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes.
LazyCallGraph.h
Implements a lazy call graph analysis and related passes for the new pass manager.
LoopInfo.h
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
OptimizationRemarkEmitter.h
PostDominators.h
getName
static StringRef getName(Value *V)
Definition:ProvenanceAnalysisEvaluator.cpp:20
PseudoProbe.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SampleProfReader.h
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
SampleProf.h
SampleProfileInference.h
This file provides the interface for the profile inference algorithm, profi.
SampleProfileLoaderBaseUtil.h
This file provides the utility functions for the sampled PGO loader base implementation.
SmallPtrSet.h
This file defines the SmallPtrSet class.
SmallSet.h
This file defines the SmallSet class.
SmallVector.h
This file defines the SmallVector class.
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::BasicBlock
LLVM Basic Block Representation.
Definition:BasicBlock.h:61
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition:BlockFrequencyInfo.h:37
llvm::DILocation
Debug location.
Definition:DebugInfoMetadata.h:1988
llvm::DILocation::getBaseDiscriminator
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
Definition:DebugInfoMetadata.h:2406
llvm::DISubprogram
Subprogram description.
Definition:DebugInfoMetadata.h:1710
llvm::DebugLoc
A debug info location.
Definition:DebugLoc.h:33
llvm::DebugLoc::getLine
unsigned getLine() const
Definition:DebugLoc.cpp:24
llvm::DenseMapBase::find
iterator find(const_arg_type_t< KeyT > Val)
Definition:DenseMap.h:156
llvm::DenseMapBase::try_emplace
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition:DenseMap.h:226
llvm::DenseMapBase::end
iterator end()
Definition:DenseMap.h:84
llvm::DenseMap
Definition:DenseMap.h:727
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition:DenseSet.h:278
llvm::DiagnosticInfoSampleProfile
Diagnostic information for the sample profiler.
Definition:DiagnosticInfo.h:257
llvm::DominatorTreeBase::getDescendants
void getDescendants(NodeT *R, SmallVectorImpl< NodeT * > &Result) const
Get all nodes dominated by R, including R itself.
Definition:GenericDomTree.h:425
llvm::ErrorOr
Represents either an error or a value T.
Definition:ErrorOr.h:56
llvm::ErrorOr::get
reference get()
Definition:ErrorOr.h:149
llvm::Function::ProfileCount
Class to represent profile counts.
Definition:Function.h:292
llvm::Function
Definition:Function.h:63
llvm::Function::PCT_Real
@ PCT_Real
Definition:Function.h:287
llvm::Function::setEntryCount
void setEntryCount(ProfileCount Count, const DenseSet< GlobalValue::GUID > *Imports=nullptr)
Set the entry count for this function.
Definition:Function.cpp:1111
llvm::GlobalValue::isAvailableExternallyLinkage
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
Definition:GlobalValue.h:380
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition:GlobalValue.h:596
llvm::Instruction
Definition:Instruction.h:68
llvm::IntrusiveRefCntPtr
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
Definition:IntrusiveRefCntPtr.h:173
llvm::LazyCallGraph::Node
A node in the call graph.
Definition:LazyCallGraph.h:312
llvm::LazyCallGraph::RefSCC
A RefSCC of the call graph.
Definition:LazyCallGraph.h:541
llvm::LazyCallGraph::SCC
An SCC of the call graph.
Definition:LazyCallGraph.h:416
llvm::LazyCallGraph
A lazily constructed view of the call graph of a module.
Definition:LazyCallGraph.h:108
llvm::LazyCallGraph::buildRefSCCs
void buildRefSCCs()
Definition:LazyCallGraph.cpp:1935
llvm::LazyCallGraph::postorder_ref_sccs
iterator_range< postorder_ref_scc_iterator > postorder_ref_sccs()
Definition:LazyCallGraph.h:970
llvm::Loop
Represents a single loop in the control flow graph.
Definition:LoopInfo.h:39
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition:Module.h:65
llvm::NamedMDNode
A tuple of MDNodes.
Definition:Metadata.h:1737
llvm::OptimizationRemarkAnalysis
Diagnostic information for optimization analysis remarks.
Definition:DiagnosticInfo.h:853
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition:OptimizationRemarkEmitter.h:32
llvm::PostDominatorTree
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
Definition:PostDominators.h:28
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition:ProfileSummaryInfo.h:41
llvm::PseudoProbeDescriptor
Definition:PseudoProbe.h:106
llvm::PseudoProbeDescriptor::getFunctionHash
uint64_t getFunctionHash() const
Definition:PseudoProbe.h:114
llvm::PseudoProbeManager
Definition:SampleProfileLoaderBaseImpl.h:88
llvm::PseudoProbeManager::getDesc
const PseudoProbeDescriptor * getDesc(StringRef FProfileName) const
Definition:SampleProfileLoaderBaseImpl.h:111
llvm::PseudoProbeManager::profileIsHashMismatched
bool profileIsHashMismatched(const PseudoProbeDescriptor &FuncDesc, const FunctionSamples &Samples) const
Definition:SampleProfileLoaderBaseImpl.h:119
llvm::PseudoProbeManager::getDesc
const PseudoProbeDescriptor * getDesc(const Function &F) const
Definition:SampleProfileLoaderBaseImpl.h:115
llvm::PseudoProbeManager::moduleIsProbed
bool moduleIsProbed(const Module &M) const
Definition:SampleProfileLoaderBaseImpl.h:124
llvm::PseudoProbeManager::profileIsValid
bool profileIsValid(const Function &F, const FunctionSamples &Samples) const
Definition:SampleProfileLoaderBaseImpl.h:128
llvm::PseudoProbeManager::PseudoProbeManager
PseudoProbeManager(const Module &M)
Definition:SampleProfileLoaderBaseImpl.h:92
llvm::PseudoProbeManager::getDesc
const PseudoProbeDescriptor * getDesc(uint64_t GUID) const
Definition:SampleProfileLoaderBaseImpl.h:106
llvm::SampleProfileInference
Sample profile inference pass.
Definition:SampleProfileInference.h:119
llvm::SampleProfileLoaderBaseImpl
Definition:SampleProfileLoaderBaseImpl.h:175
llvm::SampleProfileLoaderBaseImpl::computeAndPropagateWeights
bool computeAndPropagateWeights(FunctionT &F, const DenseSet< GlobalValue::GUID > &InlinedGUIDs)
Generate branch weight metadata for all branches in F.
Definition:SampleProfileLoaderBaseImpl.h:1027
llvm::SampleProfileLoaderBaseImpl::computeDominanceAndLoopInfo
void computeDominanceAndLoopInfo(FunctionT &F)
llvm::SampleProfileLoaderBaseImpl::BasicBlockT
typename afdo_detail::IRTraits< BT >::BasicBlockT BasicBlockT
Definition:SampleProfileLoaderBaseImpl.h:185
llvm::SampleProfileLoaderBaseImpl::FS
IntrusiveRefCntPtr< vfs::FileSystem > FS
VirtualFileSystem to load profile files from.
Definition:SampleProfileLoaderBaseImpl.h:326
llvm::SampleProfileLoaderBaseImpl::dump
void dump()
Definition:SampleProfileLoaderBaseImpl.h:180
llvm::SampleProfileLoaderBaseImpl::OptRemarkAnalysisT
typename afdo_detail::IRTraits< BT >::OptRemarkAnalysisT OptRemarkAnalysisT
Definition:SampleProfileLoaderBaseImpl.h:200
llvm::SampleProfileLoaderBaseImpl::SuccRangeT
typename afdo_detail::IRTraits< BT >::SuccRangeT SuccRangeT
Definition:SampleProfileLoaderBaseImpl.h:202
llvm::SampleProfileLoaderBaseImpl::EdgeWeights
EdgeWeightMap EdgeWeights
Map edges to their computed weights.
Definition:SampleProfileLoaderBaseImpl.h:275
llvm::SampleProfileLoaderBaseImpl::getFunction
Function & getFunction(FunctionT &F)
Definition:SampleProfileLoaderBaseImpl.h:216
llvm::SampleProfileLoaderBaseImpl::VisitedEdges
SmallSet< Edge, 32 > VisitedEdges
Set of visited edges during propagation.
Definition:SampleProfileLoaderBaseImpl.h:281
llvm::SampleProfileLoaderBaseImpl::OutlineFunctionSamples
std::map< SampleContext, FunctionSamples > OutlineFunctionSamples
Synthetic samples created by duplicating the samples of inlined functions from the original profile a...
Definition:SampleProfileLoaderBaseImpl.h:311
llvm::SampleProfileLoaderBaseImpl::ORE
OptRemarkEmitterT * ORE
Optimization Remark Emitter used to emit diagnostic remarks.
Definition:SampleProfileLoaderBaseImpl.h:332
llvm::SampleProfileLoaderBaseImpl::getEntryBB
const BasicBlockT * getEntryBB(const FunctionT *F)
Definition:SampleProfileLoaderBaseImpl.h:219
llvm::SampleProfileLoaderBaseImpl::getBlockWeight
ErrorOr< uint64_t > getBlockWeight(const BasicBlockT *BB)
Compute the weight of a basic block.
Definition:SampleProfileLoaderBaseImpl.h:514
llvm::SampleProfileLoaderBaseImpl::getFunctionLoc
unsigned getFunctionLoc(FunctionT &Func)
Get the line number for the function header.
Definition:SampleProfileLoaderBaseImpl.h:1139
llvm::SampleProfileLoaderBaseImpl::getPredecessors
PredRangeT getPredecessors(BasicBlockT *BB)
Definition:SampleProfileLoaderBaseImpl.h:222
llvm::SampleProfileLoaderBaseImpl::getInstWeightImpl
ErrorOr< uint64_t > getInstWeightImpl(const InstructionT &Inst)
Definition:SampleProfileLoaderBaseImpl.h:410
llvm::SampleProfileLoaderBaseImpl::getInstWeight
virtual ErrorOr< uint64_t > getInstWeight(const InstructionT &Inst)
Get the weight for an instruction.
Definition:SampleProfileLoaderBaseImpl.h:402
llvm::SampleProfileLoaderBaseImpl::VisitedBlocks
SmallPtrSet< const BasicBlockT *, 32 > VisitedBlocks
Set of visited blocks during propagation.
Definition:SampleProfileLoaderBaseImpl.h:278
llvm::SampleProfileLoaderBaseImpl::EquivalenceClass
EquivalenceClassMap EquivalenceClass
Equivalence classes for block weights.
Definition:SampleProfileLoaderBaseImpl.h:289
llvm::SampleProfileLoaderBaseImpl::DominatorTreePtrT
typename afdo_detail::IRTraits< BT >::DominatorTreePtrT DominatorTreePtrT
Definition:SampleProfileLoaderBaseImpl.h:192
llvm::SampleProfileLoaderBaseImpl::CoverageTracker
SampleCoverageTracker CoverageTracker
Profile coverage tracker.
Definition:SampleProfileLoaderBaseImpl.h:303
llvm::SampleProfileLoaderBaseImpl::LoopT
typename afdo_detail::IRTraits< BT >::LoopT LoopT
Definition:SampleProfileLoaderBaseImpl.h:189
llvm::SampleProfileLoaderBaseImpl::NodeRef
typename GraphTraits< FT * >::NodeRef NodeRef
Definition:SampleProfileLoaderBaseImpl.h:182
llvm::SampleProfileLoaderBaseImpl::Reader
std::unique_ptr< SampleProfileReader > Reader
Profile reader object.
Definition:SampleProfileLoaderBaseImpl.h:306
llvm::SampleProfileLoaderBaseImpl::OptRemarkEmitterT
typename afdo_detail::IRTraits< BT >::OptRemarkEmitterT OptRemarkEmitterT
Definition:SampleProfileLoaderBaseImpl.h:198
llvm::SampleProfileLoaderBaseImpl::printBlockWeight
void printBlockWeight(raw_ostream &OS, const BasicBlockT *BB) const
Print the weight of block BB on stream OS.
Definition:SampleProfileLoaderBaseImpl.h:381
llvm::SampleProfileLoaderBaseImpl::DT
DominatorTreePtrT DT
Dominance, post-dominance and loop information.
Definition:SampleProfileLoaderBaseImpl.h:292
llvm::SampleProfileLoaderBaseImpl::printBlockEquivalence
void printBlockEquivalence(raw_ostream &OS, const BasicBlockT *BB)
Print the equivalence class of block BB on stream OS.
Definition:SampleProfileLoaderBaseImpl.h:369
llvm::SampleProfileLoaderBaseImpl::BT
std::remove_pointer_t< NodeRef > BT
Definition:SampleProfileLoaderBaseImpl.h:183
llvm::SampleProfileLoaderBaseImpl::SampleProfileLoaderBaseImpl
SampleProfileLoaderBaseImpl(std::string Name, std::string RemapName, IntrusiveRefCntPtr< vfs::FileSystem > FS)
Definition:SampleProfileLoaderBaseImpl.h:177
llvm::SampleProfileLoaderBaseImpl::ProbeManager
std::unique_ptr< PseudoProbeManager > ProbeManager
Definition:SampleProfileLoaderBaseImpl.h:314
llvm::SampleProfileLoaderBaseImpl::~SampleProfileLoaderBaseImpl
~SampleProfileLoaderBaseImpl()=default
llvm::SampleProfileLoaderBaseImpl::LoopInfoPtrT
typename afdo_detail::IRTraits< BT >::LoopInfoPtrT LoopInfoPtrT
Definition:SampleProfileLoaderBaseImpl.h:190
llvm::SampleProfileLoaderBaseImpl::emitCoverageRemarks
void emitCoverageRemarks(FunctionT &F)
Definition:SampleProfileLoaderBaseImpl.h:1097
llvm::SampleProfileLoaderBaseImpl::getSuccessors
SuccRangeT getSuccessors(BasicBlockT *BB)
Definition:SampleProfileLoaderBaseImpl.h:225
llvm::SampleProfileLoaderBaseImpl::Filename
std::string Filename
Name of the profile file to load.
Definition:SampleProfileLoaderBaseImpl.h:320
llvm::SampleProfileLoaderBaseImpl::propagateThroughEdges
bool propagateThroughEdges(FunctionT &F, bool UpdateBlockCount)
Propagate weights through incoming/outgoing edges.
Definition:SampleProfileLoaderBaseImpl.h:728
llvm::SampleProfileLoaderBaseImpl::PDT
PostDominatorTreePtrT PDT
Definition:SampleProfileLoaderBaseImpl.h:293
llvm::SampleProfileLoaderBaseImpl::InstructionT
typename afdo_detail::IRTraits< BT >::InstructionT InstructionT
Definition:SampleProfileLoaderBaseImpl.h:184
llvm::SampleProfileLoaderBaseImpl::visitEdge
uint64_t visitEdge(Edge E, unsigned *NumUnknownEdges, Edge *UnknownEdge)
Visit the given edge to decide if it has a valid weight.
Definition:SampleProfileLoaderBaseImpl.h:702
llvm::SampleProfileLoaderBaseImpl::PostDominatorTreePtrT
typename afdo_detail::IRTraits< BT >::PostDominatorTreePtrT PostDominatorTreePtrT
Definition:SampleProfileLoaderBaseImpl.h:194
llvm::SampleProfileLoaderBaseImpl::initWeightPropagation
void initWeightPropagation(FunctionT &F, const DenseSet< GlobalValue::GUID > &InlinedGUIDs)
Definition:SampleProfileLoaderBaseImpl.h:1049
llvm::SampleProfileLoaderBaseImpl::Predecessors
BlockEdgeMap Predecessors
Predecessors for each basic block in the CFG.
Definition:SampleProfileLoaderBaseImpl.h:297
llvm::SampleProfileLoaderBaseImpl::finalizeWeightPropagation
void finalizeWeightPropagation(FunctionT &F, const DenseSet< GlobalValue::GUID > &InlinedGUIDs)
Definition:SampleProfileLoaderBaseImpl.h:1077
llvm::SampleProfileLoaderBaseImpl::computeBlockWeights
bool computeBlockWeights(FunctionT &F)
Compute and store the weights of every basic block.
Definition:SampleProfileLoaderBaseImpl.h:534
llvm::SampleProfileLoaderBaseImpl::findFunctionSamples
virtual const FunctionSamples * findFunctionSamples(const InstructionT &I) const
Get the FunctionSamples for an instruction.
Definition:SampleProfileLoaderBaseImpl.h:560
llvm::SampleProfileLoaderBaseImpl::PostDominatorTreeT
typename afdo_detail::IRTraits< BT >::PostDominatorTreeT PostDominatorTreeT
Definition:SampleProfileLoaderBaseImpl.h:196
llvm::SampleProfileLoaderBaseImpl::getProbeWeight
virtual ErrorOr< uint64_t > getProbeWeight(const InstructionT &Inst)
Definition:SampleProfileLoaderBaseImpl.h:454
llvm::SampleProfileLoaderBaseImpl::RemappingFilename
std::string RemappingFilename
Name of the profile remapping file to load.
Definition:SampleProfileLoaderBaseImpl.h:323
llvm::SampleProfileLoaderBaseImpl::PredRangeT
typename afdo_detail::IRTraits< BT >::PredRangeT PredRangeT
Definition:SampleProfileLoaderBaseImpl.h:201
llvm::SampleProfileLoaderBaseImpl::applyProfi
void applyProfi(FunctionT &F, BlockEdgeMap &Successors, BlockWeightMap &SampleBlockWeights, BlockWeightMap &BlockWeights, EdgeWeightMap &EdgeWeights)
Definition:SampleProfileLoaderBaseImpl.h:973
llvm::SampleProfileLoaderBaseImpl::BlockFrequencyInfoT
typename afdo_detail::IRTraits< BT >::BlockFrequencyInfoT BlockFrequencyInfoT
Definition:SampleProfileLoaderBaseImpl.h:187
llvm::SampleProfileLoaderBaseImpl::Successors
BlockEdgeMap Successors
Successors for each basic block in the CFG.
Definition:SampleProfileLoaderBaseImpl.h:300
llvm::SampleProfileLoaderBaseImpl::Samples
FunctionSamples * Samples
Samples collected for the body of this function.
Definition:SampleProfileLoaderBaseImpl.h:317
llvm::SampleProfileLoaderBaseImpl::findEquivalenceClasses
void findEquivalenceClasses(FunctionT &F)
Find equivalence classes.
Definition:SampleProfileLoaderBaseImpl.h:641
llvm::SampleProfileLoaderBaseImpl::Edge
std::pair< const BasicBlockT *, const BasicBlockT * > Edge
Definition:SampleProfileLoaderBaseImpl.h:207
llvm::SampleProfileLoaderBaseImpl::PSI
ProfileSummaryInfo * PSI
Profile Summary Info computed from sample profile.
Definition:SampleProfileLoaderBaseImpl.h:329
llvm::SampleProfileLoaderBaseImpl::LI
LoopInfoPtrT LI
Definition:SampleProfileLoaderBaseImpl.h:294
llvm::SampleProfileLoaderBaseImpl::clearFunctionData
void clearFunctionData(bool ResetDT=true)
Clear all the per-function data used to load samples and propagate weights.
Definition:SampleProfileLoaderBaseImpl.h:337
llvm::SampleProfileLoaderBaseImpl::DILocation2SampleMap
DenseMap< const DILocation *, const FunctionSamples * > DILocation2SampleMap
Definition:SampleProfileLoaderBaseImpl.h:235
llvm::SampleProfileLoaderBaseImpl::buildEdges
void buildEdges(FunctionT &F)
Build in/out edge lists for each basic block in the CFG.
Definition:SampleProfileLoaderBaseImpl.h:878
llvm::SampleProfileLoaderBaseImpl::findEquivalencesFor
void findEquivalencesFor(BasicBlockT *BB1, ArrayRef< BasicBlockT * > Descendants, PostDominatorTreeT *DomTree)
Find equivalence classes for the given block.
Definition:SampleProfileLoaderBaseImpl.h:597
llvm::SampleProfileLoaderBaseImpl::printEdgeWeight
void printEdgeWeight(raw_ostream &OS, Edge E)
Print the weight of edge E on stream OS.
Definition:SampleProfileLoaderBaseImpl.h:359
llvm::SampleProfileLoaderBaseImpl::FunctionT
typename afdo_detail::IRTraits< BT >::FunctionT FunctionT
Definition:SampleProfileLoaderBaseImpl.h:188
llvm::SampleProfileLoaderBaseImpl::BlockWeights
BlockWeightMap BlockWeights
Map basic blocks to their computed weights.
Definition:SampleProfileLoaderBaseImpl.h:269
llvm::SampleProfileLoaderBaseImpl::propagateWeights
void propagateWeights(FunctionT &F)
Propagate weights into edges.
Definition:SampleProfileLoaderBaseImpl.h:918
llvm::SmallPtrSetImplBase::clear
void clear()
Definition:SmallPtrSet.h:97
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition:SmallPtrSet.h:384
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition:SmallPtrSet.h:519
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition:SmallSet.h:132
llvm::SmallVectorImpl::clear
void clear()
Definition:SmallVector.h:610
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::detail::DenseSetImpl::size
size_type size() const
Definition:DenseSet.h:81
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition:iterator_range.h:42
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
llvm::sampleprof::FunctionSamples
Representation of the samples collected for a function.
Definition:SampleProf.h:745
llvm::sampleprof::FunctionSamples::getFunctionHash
uint64_t getFunctionHash() const
Definition:SampleProf.h:1081
llvm::sampleprof::FunctionSamples::ProfileIsProbeBased
static bool ProfileIsProbeBased
Definition:SampleProf.h:1186
llvm::sampleprof::FunctionSamples::getCanonicalFnName
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
Definition:SampleProf.h:1090
llvm::sampleprof::FunctionSamples::getOffset
static unsigned getOffset(const DILocation *DIL)
Returns the line offset to the start line of the subprogram.
Definition:SampleProf.cpp:216
llvm::sampleprofutil::SampleCoverageTracker
Definition:SampleProfileLoaderBaseUtil.h:35
uint32_t
uint64_t
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::ore::NV
DiagnosticInfoOptimizationBase::Argument NV
Definition:OptimizationRemarkEmitter.h:135
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::ProfileCount
Function::ProfileCount ProfileCount
Definition:SampleProfileLoaderBaseImpl.h:50
llvm::successors
auto successors(const MachineBasicBlock *BB)
Definition:MachineBasicBlock.h:1376
llvm::SampleProfileSampleCoverage
cl::opt< unsigned > SampleProfileSampleCoverage
llvm::buildTopDownFuncOrder
static void buildTopDownFuncOrder(LazyCallGraph &CG, std::vector< Function * > &FunctionOrderList)
Definition:SampleProfileLoaderBaseImpl.h:160
llvm::SampleProfileRecordCoverage
cl::opt< unsigned > SampleProfileRecordCoverage
llvm::SampleProfileMaxPropagateIterations
cl::opt< unsigned > SampleProfileMaxPropagateIterations
llvm::SampleProfileUseProfi
cl::opt< bool > SampleProfileUseProfi
llvm::EnableFSDiscriminator
cl::opt< bool > EnableFSDiscriminator
Definition:TargetPassConfig.cpp:392
llvm::extractProbe
std::optional< PseudoProbe > extractProbe(const Instruction &Inst)
Definition:PseudoProbe.cpp:56
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::succ_range
iterator_range< succ_iterator > succ_range
Definition:CFG.h:244
llvm::NoWarnSampleUnused
cl::opt< bool > NoWarnSampleUnused
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition:Format.h:125
llvm::pred_range
iterator_range< pred_iterator > pred_range
Definition:CFG.h:107
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1873
llvm::DS_Warning
@ DS_Warning
Definition:DiagnosticInfo.h:51
llvm::HighlightColor::Remark
@ Remark
llvm::skipProfileForFunction
static bool skipProfileForFunction(const Function &F)
Definition:SampleProfileLoaderBaseImpl.h:155
llvm::predecessors
auto predecessors(const MachineBasicBlock *BB)
Definition:MachineBasicBlock.h:1377
llvm::TensorType::Total
@ Total
llvm::PseudoProbeDescMetadataName
constexpr const char * PseudoProbeDescMetadataName
Definition:PseudoProbe.h:25
std
Implement std::hash so that hash_code can be used in STL containers.
Definition:BitVector.h:858
raw_ostream.h
N
#define N
llvm::DWARFExpression::Operation::Description
Description of the encoding of one expression Op.
Definition:DWARFExpression.h:66
llvm::GraphTraits::NodeRef
typename GraphType::UnknownGraphTypeError NodeRef
Definition:GraphTraits.h:95
llvm::afdo_detail::IRTraits< BasicBlock >::LoopInfoPtrT
std::unique_ptr< LoopInfo > LoopInfoPtrT
Definition:SampleProfileLoaderBaseImpl.h:67
llvm::afdo_detail::IRTraits< BasicBlock >::PostDominatorTreePtrT
std::unique_ptr< PostDominatorTree > PostDominatorTreePtrT
Definition:SampleProfileLoaderBaseImpl.h:70
llvm::afdo_detail::IRTraits< BasicBlock >::getFunction
static Function & getFunction(Function &F)
Definition:SampleProfileLoaderBaseImpl.h:75
llvm::afdo_detail::IRTraits< BasicBlock >::getPredecessors
static pred_range getPredecessors(BasicBlock *BB)
Definition:SampleProfileLoaderBaseImpl.h:79
llvm::afdo_detail::IRTraits< BasicBlock >::getSuccessors
static succ_range getSuccessors(BasicBlock *BB)
Definition:SampleProfileLoaderBaseImpl.h:80
llvm::afdo_detail::IRTraits< BasicBlock >::DominatorTreePtrT
std::unique_ptr< DominatorTree > DominatorTreePtrT
Definition:SampleProfileLoaderBaseImpl.h:68
llvm::afdo_detail::IRTraits< BasicBlock >::getEntryBB
static const BasicBlock * getEntryBB(const Function *F)
Definition:SampleProfileLoaderBaseImpl.h:76
llvm::afdo_detail::IRTraits
Definition:SampleProfileLoaderBaseImpl.h:60

Generated on Fri Jul 18 2025 09:55:18 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp