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