LLVM 23.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"
46
47namespace llvm {
48using namespace sampleprof;
49using namespace sampleprofutil;
51
52namespace vfs {
53class FileSystem;
54} // namespace vfs
55
56#define DEBUG_TYPE "sample-profile-impl"
57
58namespace afdo_detail {
59
60template <typename BlockT> struct IRTraits;
61template <> struct IRTraits<BasicBlock> {
66 using LoopT = Loop;
67 using LoopInfoPtrT = std::unique_ptr<LoopInfo>;
68 using DominatorTreePtrT = std::unique_ptr<DominatorTree>;
70 using PostDominatorTreePtrT = std::unique_ptr<PostDominatorTree>;
75 static Function &getFunction(Function &F) { return F; }
76 static const BasicBlock *getEntryBB(const Function *F) {
77 return &F->getEntryBlock();
78 }
80 static succ_range getSuccessors(BasicBlock *BB) { return successors(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.
90 DenseSet<uint64_t> GUIDIsWeakSymbol;
91
92public:
94 if (NamedMDNode *FuncInfo =
95 M.getNamedMetadata(PseudoProbeDescMetadataName)) {
96 for (const auto *Operand : FuncInfo->operands()) {
97 const auto *MD = cast<MDNode>(Operand);
98 auto GUID = mdconst::dyn_extract<ConstantInt>(MD->getOperand(0))
99 ->getZExtValue();
100 auto Hash = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1))
101 ->getZExtValue();
102 GUIDToProbeDescMap.try_emplace(GUID, PseudoProbeDescriptor(GUID, Hash));
103 }
104 for (const auto &Func : M) {
105 if (Func.hasWeakLinkage() || Func.hasExternalWeakLinkage()) {
108 if (GUIDToProbeDescMap.contains(GUID))
109 GUIDIsWeakSymbol.insert(GUID);
110 }
111 }
112 }
113 }
114
116 auto I = GUIDToProbeDescMap.find(GUID);
117 return I == GUIDToProbeDescMap.end() ? nullptr : &I->second;
118 }
119
124
129
130 bool probeFromWeakSymbol(uint64_t GUID) const {
131 return GUIDIsWeakSymbol.count(GUID);
132 }
133
135 const FunctionSamples &Samples) const {
136 return FuncDesc.getFunctionHash() != Samples.getFunctionHash();
137 }
138
139 bool moduleIsProbed(const Module &M) const {
140 return M.getNamedMetadata(PseudoProbeDescMetadataName);
141 }
142
143 bool profileIsValid(const Function &F, const FunctionSamples &Samples) const {
144 const auto *Desc = getDesc(F);
145 bool IsAvailableExternallyLinkage =
147 // Always check the function attribute to determine checksum mismatch for
148 // `available_externally` functions even if their desc are available. This
149 // is because the desc is computed based on the original internal function
150 // and it's substituted by the `available_externally` function during link
151 // time. However, when unstable IR or ODR violation issue occurs, the
152 // definitions of the same function across different translation units could
153 // be different and result in different checksums. So we should use the
154 // state from the new (available_externally) function, which is saved in its
155 // attribute.
156 // TODO: If the function's profile only exists as nested inlinee profile in
157 // a different module, we don't have the attr mismatch state(unknown), we
158 // need to fix it later.
159 if (IsAvailableExternallyLinkage || !Desc)
160 return !F.hasFnAttribute("profile-checksum-mismatch");
161
162 return Desc && !profileIsHashMismatched(*Desc, Samples);
163 }
164};
165
166
167
169
170static inline bool skipProfileForFunction(const Function &F) {
171 return F.isDeclaration() || !F.hasFnAttribute("use-sample-profile");
172}
173
174static inline void
176 std::vector<Function *> &FunctionOrderList) {
177 CG.buildRefSCCs();
179 for (LazyCallGraph::SCC &C : RC) {
180 for (LazyCallGraph::Node &N : C) {
181 Function &F = N.getFunction();
183 FunctionOrderList.push_back(&F);
184 }
185 }
186 }
187 std::reverse(FunctionOrderList.begin(), FunctionOrderList.end());
188}
189
190template <typename FT> class SampleProfileLoaderBaseImpl {
191public:
192 SampleProfileLoaderBaseImpl(std::string Name, std::string RemapName,
194 : Filename(Name), RemappingFilename(RemapName), FS(std::move(FS)) {}
195 void dump() { Reader->dump(); }
196
198 using BT = std::remove_pointer_t<NodeRef>;
218
222 using Edge = std::pair<const BasicBlockT *, const BasicBlockT *>;
226
227protected:
230
243
244 unsigned getFunctionLoc(FunctionT &Func);
251 virtual const FunctionSamples *
254 void printBlockWeight(raw_ostream &OS, const BasicBlockT *BB) const;
259 ArrayRef<BasicBlockT *> Descendants,
260 PostDominatorTreeT *DomTree);
263 BlockWeightMap &SampleBlockWeights,
265 uint64_t visitEdge(Edge E, unsigned *NumUnknownEdges, Edge *UnknownEdge);
267 bool propagateThroughEdges(FunctionT &F, bool UpdateBlockCount);
268 void clearFunctionData(bool ResetDT = true);
270 bool
272 const DenseSet<GlobalValue::GUID> &InlinedGUIDs);
274 const DenseSet<GlobalValue::GUID> &InlinedGUIDs);
275 void
277 const DenseSet<GlobalValue::GUID> &InlinedGUIDs);
279
280 /// Map basic blocks to their computed weights.
281 ///
282 /// The weight of a basic block is defined to be the maximum
283 /// of all the instruction weights in that block.
285
286 /// Map edges to their computed weights.
287 ///
288 /// Edge weights are computed by propagating basic block weights in
289 /// SampleProfile::propagateWeights.
291
292 /// Set of visited blocks during propagation.
294
295 /// Set of visited edges during propagation.
297
298 /// Equivalence classes for block weights.
299 ///
300 /// Two blocks BB1 and BB2 are in the same equivalence class if they
301 /// dominate and post-dominate each other, and they are in the same loop
302 /// nest. When this happens, the two blocks are guaranteed to execute
303 /// the same number of times.
305
306 /// Dominance, post-dominance and loop information.
310
311 /// Predecessors for each basic block in the CFG.
313
314 /// Successors for each basic block in the CFG.
316
317 /// Profile coverage tracker.
319
320 /// Profile reader object.
321 std::unique_ptr<SampleProfileReader> Reader;
322
323 /// Synthetic samples created by duplicating the samples of inlined functions
324 /// from the original profile as if they were top level sample profiles.
325 /// Use std::map because insertion may happen while its content is referenced.
326 std::map<SampleContext, FunctionSamples> OutlineFunctionSamples;
327
328 // A pseudo probe helper to correlate the imported sample counts.
329 std::unique_ptr<PseudoProbeManager> ProbeManager;
330
331 /// Samples collected for the body of this function.
333
334 /// Name of the profile file to load.
335 std::string Filename;
336
337 /// Name of the profile remapping file to load.
338 std::string RemappingFilename;
339
340 /// VirtualFileSystem to load profile files from.
342
343 /// Profile Summary Info computed from sample profile.
345
346 /// Optimization Remark Emitter used to emit diagnostic remarks.
348};
349
350/// Clear all the per-function data used to load samples and propagate weights.
351template <typename BT>
353 BlockWeights.clear();
354 EdgeWeights.clear();
355 VisitedBlocks.clear();
356 VisitedEdges.clear();
357 EquivalenceClass.clear();
358 if (ResetDT) {
359 DT = nullptr;
360 PDT = nullptr;
361 LI = nullptr;
362 }
363 Predecessors.clear();
364 Successors.clear();
365 CoverageTracker.clear();
366}
367
368#ifndef NDEBUG
369/// Print the weight of edge \p E on stream \p OS.
370///
371/// \param OS Stream to emit the output to.
372/// \param E Edge to print.
373template <typename BT>
375 OS << "weight[" << E.first->getName() << "->" << E.second->getName()
376 << "]: " << EdgeWeights[E] << "\n";
377}
378
379/// Print the equivalence class of block \p BB on stream \p OS.
380///
381/// \param OS Stream to emit the output to.
382/// \param BB Block to print.
383template <typename BT>
385 raw_ostream &OS, const BasicBlockT *BB) {
386 const BasicBlockT *Equiv = EquivalenceClass[BB];
387 OS << "equivalence[" << BB->getName()
388 << "]: " << ((Equiv) ? EquivalenceClass[BB]->getName() : "NONE") << "\n";
389}
390
391/// Print the weight of block \p BB on stream \p OS.
392///
393/// \param OS Stream to emit the output to.
394/// \param BB Block to print.
395template <typename BT>
397 raw_ostream &OS, const BasicBlockT *BB) const {
398 const auto &I = BlockWeights.find(BB);
399 uint64_t W = (I == BlockWeights.end() ? 0 : I->second);
400 OS << "weight[" << BB->getName() << "]: " << W << "\n";
401}
402#endif
403
404/// Get the weight for an instruction.
405///
406/// The "weight" of an instruction \p Inst is the number of samples
407/// collected on that instruction at runtime. To retrieve it, we
408/// need to compute the line number of \p Inst relative to the start of its
409/// function. We use HeaderLineno to compute the offset. We then
410/// look up the samples collected for \p Inst using BodySamples.
411///
412/// \param Inst Instruction to query.
413///
414/// \returns the weight of \p Inst.
415template <typename BT>
422
423template <typename BT>
427 if (!FS)
428 return std::error_code();
429
430 const DebugLoc &DLoc = Inst.getDebugLoc();
431 if (!DLoc)
432 return std::error_code();
433
434 const DILocation *DIL = DLoc;
435 uint32_t LineOffset = FunctionSamples::getOffset(DIL);
436 uint32_t Discriminator;
438 Discriminator = DIL->getDiscriminator();
439 else
440 Discriminator = DIL->getBaseDiscriminator();
441
442 ErrorOr<uint64_t> R = FS->findSamplesAt(LineOffset, Discriminator);
443 if (R) {
444 bool FirstMark =
445 CoverageTracker.markSamplesUsed(FS, LineOffset, Discriminator, R.get());
446 if (FirstMark) {
447 ORE->emit([&]() {
448 OptRemarkAnalysisT Remark(DEBUG_TYPE, "AppliedSamples", &Inst);
449 Remark << "Applied " << ore::NV("NumSamples", *R);
450 Remark << " samples from profile (offset: ";
451 Remark << ore::NV("LineOffset", LineOffset);
452 if (Discriminator) {
453 Remark << ".";
454 Remark << ore::NV("Discriminator", Discriminator);
455 }
456 Remark << ")";
457 return Remark;
458 });
459 }
460 LLVM_DEBUG(dbgs() << " " << DLoc.getLine() << "." << Discriminator << ":"
461 << Inst << " (line offset: " << LineOffset << "."
462 << Discriminator << " - weight: " << R.get() << ")\n");
463 }
464 return R;
465}
466
467template <typename BT>
471 "Profile is not pseudo probe based");
472 std::optional<PseudoProbe> Probe = extractProbe(Inst);
473 // Ignore the non-probe instruction. If none of the instruction in the BB is
474 // probe, we choose to infer the BB's weight.
475 if (!Probe)
476 return std::error_code();
477
479 if (!FS) {
480 // If we can't find the function samples for a probe, it could be due to the
481 // probe is later optimized away or the inlining context is mismatced. We
482 // treat it as unknown, leaving it to profile inference instead of forcing a
483 // zero count.
484 return std::error_code();
485 }
486
487 auto R = FS->findSamplesAt(Probe->Id, Probe->Discriminator);
488 if (R) {
489 uint64_t Samples = R.get() * Probe->Factor;
490 bool FirstMark = CoverageTracker.markSamplesUsed(FS, Probe->Id, 0, Samples);
491 if (FirstMark) {
492 ORE->emit([&]() {
493 OptRemarkAnalysisT Remark(DEBUG_TYPE, "AppliedSamples", &Inst);
494 Remark << "Applied " << ore::NV("NumSamples", Samples);
495 Remark << " samples from profile (ProbeId=";
496 Remark << ore::NV("ProbeId", Probe->Id);
497 if (Probe->Discriminator) {
498 Remark << ".";
499 Remark << ore::NV("Discriminator", Probe->Discriminator);
500 }
501 Remark << ", Factor=";
502 Remark << ore::NV("Factor", Probe->Factor);
503 Remark << ", OriginalSamples=";
504 Remark << ore::NV("OriginalSamples", R.get());
505 Remark << ")";
506 return Remark;
507 });
508 }
509 LLVM_DEBUG({dbgs() << " " << Probe->Id;
510 if (Probe->Discriminator)
511 dbgs() << "." << Probe->Discriminator;
512 dbgs() << ":" << Inst << " - weight: " << R.get()
513 << " - factor: " << format("%0.2f", Probe->Factor) << ")\n";});
514 return Samples;
515 }
516 return R;
517}
518
519/// Compute the weight of a basic block.
520///
521/// The weight of basic block \p BB is the maximum weight of all the
522/// instructions in BB.
523///
524/// \param BB The basic block to query.
525///
526/// \returns the weight for \p BB.
527template <typename BT>
530 uint64_t Max = 0;
531 bool HasWeight = false;
532 for (auto &I : *BB) {
534 if (R) {
535 Max = std::max(Max, R.get());
536 HasWeight = true;
537 }
538 }
539 return HasWeight ? ErrorOr<uint64_t>(Max) : std::error_code();
540}
541
542/// Compute and store the weights of every basic block.
543///
544/// This populates the BlockWeights map by computing
545/// the weights of every basic block in the CFG.
546///
547/// \param F The function to query.
548template <typename BT>
550 bool Changed = false;
551 LLVM_DEBUG(dbgs() << "Block weights\n");
552 for (const auto &BB : F) {
553 ErrorOr<uint64_t> Weight = getBlockWeight(&BB);
554 if (Weight) {
555 BlockWeights[&BB] = Weight.get();
556 VisitedBlocks.insert(&BB);
557 Changed = true;
558 }
560 }
561
562 return Changed;
563}
564
565/// Get the FunctionSamples for an instruction.
566///
567/// The FunctionSamples of an instruction \p Inst is the inlined instance
568/// in which that instruction is coming from. We traverse the inline stack
569/// of that instruction, and match it with the tree nodes in the profile.
570///
571/// \param Inst Instruction to query.
572///
573/// \returns the FunctionSamples pointer to the inlined instance.
574template <typename BT>
576 const InstructionT &Inst) const {
577 const DILocation *DIL = Inst.getDebugLoc();
578 if (!DIL)
579 return Samples;
580
581 auto it = DILocation2SampleMap.try_emplace(DIL, nullptr);
582 if (it.second) {
583 it.first->second = Samples->findFunctionSamples(DIL, Reader->getRemapper());
584 }
585 return it.first->second;
586}
587
588/// Find equivalence classes for the given block.
589///
590/// This finds all the blocks that are guaranteed to execute the same
591/// number of times as \p BB1. To do this, it traverses all the
592/// descendants of \p BB1 in the dominator or post-dominator tree.
593///
594/// A block BB2 will be in the same equivalence class as \p BB1 if
595/// the following holds:
596///
597/// 1- \p BB1 is a descendant of BB2 in the opposite tree. So, if BB2
598/// is a descendant of \p BB1 in the dominator tree, then BB2 should
599/// dominate BB1 in the post-dominator tree.
600///
601/// 2- Both BB2 and \p BB1 must be in the same loop.
602///
603/// For every block BB2 that meets those two requirements, we set BB2's
604/// equivalence class to \p BB1.
605///
606/// \param BB1 Block to check.
607/// \param Descendants Descendants of \p BB1 in either the dom or pdom tree.
608/// \param DomTree Opposite dominator tree. If \p Descendants is filled
609/// with blocks from \p BB1's dominator tree, then
610/// this is the post-dominator tree, and vice versa.
611template <typename BT>
613 BasicBlockT *BB1, ArrayRef<BasicBlockT *> Descendants,
614 PostDominatorTreeT *DomTree) {
615 const BasicBlockT *EC = EquivalenceClass[BB1];
616 uint64_t Weight = BlockWeights[EC];
617 for (const auto *BB2 : Descendants) {
618 bool IsDomParent = DomTree->dominates(BB2, BB1);
619 bool IsInSameLoop = LI->getLoopFor(BB1) == LI->getLoopFor(BB2);
620 if (BB1 != BB2 && IsDomParent && IsInSameLoop) {
621 EquivalenceClass[BB2] = EC;
622 // If BB2 is visited, then the entire EC should be marked as visited.
623 if (VisitedBlocks.count(BB2)) {
624 VisitedBlocks.insert(EC);
625 }
626
627 // If BB2 is heavier than BB1, make BB2 have the same weight
628 // as BB1.
629 //
630 // Note that we don't worry about the opposite situation here
631 // (when BB2 is lighter than BB1). We will deal with this
632 // during the propagation phase. Right now, we just want to
633 // make sure that BB1 has the largest weight of all the
634 // members of its equivalence set.
635 Weight = std::max(Weight, BlockWeights[BB2]);
636 }
637 }
638 const BasicBlockT *EntryBB = getEntryBB(EC->getParent());
639 if (EC == EntryBB) {
640 BlockWeights[EC] = Samples->getHeadSamples() + 1;
641 } else {
642 BlockWeights[EC] = Weight;
643 }
644}
645
646/// Find equivalence classes.
647///
648/// Since samples may be missing from blocks, we can fill in the gaps by setting
649/// the weights of all the blocks in the same equivalence class to the same
650/// weight. To compute the concept of equivalence, we use dominance and loop
651/// information. Two blocks B1 and B2 are in the same equivalence class if B1
652/// dominates B2, B2 post-dominates B1 and both are in the same loop.
653///
654/// \param F The function to query.
655template <typename BT>
658 LLVM_DEBUG(dbgs() << "\nBlock equivalence classes\n");
659 // Find equivalence sets based on dominance and post-dominance information.
660 for (auto &BB : F) {
661 BasicBlockT *BB1 = &BB;
662
663 // Compute BB1's equivalence class once.
664 // By default, blocks are in their own equivalence class.
665 auto [It, Inserted] = EquivalenceClass.try_emplace(BB1, BB1);
666 if (!Inserted) {
668 continue;
669 }
670
671 // Traverse all the blocks dominated by BB1. We are looking for
672 // every basic block BB2 such that:
673 //
674 // 1- BB1 dominates BB2.
675 // 2- BB2 post-dominates BB1.
676 // 3- BB1 and BB2 are in the same loop nest.
677 //
678 // If all those conditions hold, it means that BB2 is executed
679 // as many times as BB1, so they are placed in the same equivalence
680 // class by making BB2's equivalence class be BB1.
681 DominatedBBs.clear();
682 DT->getDescendants(BB1, DominatedBBs);
683 findEquivalencesFor(BB1, DominatedBBs, &*PDT);
684
686 }
687
688 // Assign weights to equivalence classes.
689 //
690 // All the basic blocks in the same equivalence class will execute
691 // the same number of times. Since we know that the head block in
692 // each equivalence class has the largest weight, assign that weight
693 // to all the blocks in that equivalence class.
695 dbgs() << "\nAssign the same weight to all blocks in the same class\n");
696 for (auto &BI : F) {
697 const BasicBlockT *BB = &BI;
698 const BasicBlockT *EquivBB = EquivalenceClass[BB];
699 if (BB != EquivBB)
700 BlockWeights[BB] = BlockWeights[EquivBB];
702 }
703}
704
705/// Visit the given edge to decide if it has a valid weight.
706///
707/// If \p E has not been visited before, we copy to \p UnknownEdge
708/// and increment the count of unknown edges.
709///
710/// \param E Edge to visit.
711/// \param NumUnknownEdges Current number of unknown edges.
712/// \param UnknownEdge Set if E has not been visited before.
713///
714/// \returns E's weight, if known. Otherwise, return 0.
715template <typename BT>
717 unsigned *NumUnknownEdges,
718 Edge *UnknownEdge) {
719 if (!VisitedEdges.count(E)) {
720 (*NumUnknownEdges)++;
721 *UnknownEdge = E;
722 return 0;
723 }
724
725 return EdgeWeights[E];
726}
727
728/// Propagate weights through incoming/outgoing edges.
729///
730/// If the weight of a basic block is known, and there is only one edge
731/// with an unknown weight, we can calculate the weight of that edge.
732///
733/// Similarly, if all the edges have a known count, we can calculate the
734/// count of the basic block, if needed.
735///
736/// \param F Function to process.
737/// \param UpdateBlockCount Whether we should update basic block counts that
738/// has already been annotated.
739///
740/// \returns True if new weights were assigned to edges or blocks.
741template <typename BT>
743 FunctionT &F, bool UpdateBlockCount) {
744 bool Changed = false;
745 LLVM_DEBUG(dbgs() << "\nPropagation through edges\n");
746 for (const auto &BI : F) {
747 const BasicBlockT *BB = &BI;
748 const BasicBlockT *EC = EquivalenceClass[BB];
749
750 // Visit all the predecessor and successor edges to determine
751 // which ones have a weight assigned already. Note that it doesn't
752 // matter that we only keep track of a single unknown edge. The
753 // only case we are interested in handling is when only a single
754 // edge is unknown (see setEdgeOrBlockWeight).
755 for (unsigned i = 0; i < 2; i++) {
756 uint64_t TotalWeight = 0;
757 unsigned NumUnknownEdges = 0, NumTotalEdges = 0;
758 Edge UnknownEdge, SelfReferentialEdge, SingleEdge;
759
760 if (i == 0) {
761 // First, visit all predecessor edges.
762 auto &Preds = Predecessors[BB];
763 NumTotalEdges = Preds.size();
764 for (auto *Pred : Preds) {
765 Edge E = std::make_pair(Pred, BB);
766 TotalWeight += visitEdge(E, &NumUnknownEdges, &UnknownEdge);
767 if (E.first == E.second)
768 SelfReferentialEdge = E;
769 }
770 if (NumTotalEdges == 1) {
771 SingleEdge = std::make_pair(Predecessors[BB][0], BB);
772 }
773 } else {
774 // On the second round, visit all successor edges.
775 auto &Succs = Successors[BB];
776 NumTotalEdges = Succs.size();
777 for (auto *Succ : Succs) {
778 Edge E = std::make_pair(BB, Succ);
779 TotalWeight += visitEdge(E, &NumUnknownEdges, &UnknownEdge);
780 }
781 if (NumTotalEdges == 1) {
782 SingleEdge = std::make_pair(BB, Successors[BB][0]);
783 }
784 }
785
786 // After visiting all the edges, there are three cases that we
787 // can handle immediately:
788 //
789 // - All the edge weights are known (i.e., NumUnknownEdges == 0).
790 // In this case, we simply check that the sum of all the edges
791 // is the same as BB's weight. If not, we change BB's weight
792 // to match. Additionally, if BB had not been visited before,
793 // we mark it visited.
794 //
795 // - Only one edge is unknown and BB has already been visited.
796 // In this case, we can compute the weight of the edge by
797 // subtracting the total block weight from all the known
798 // edge weights. If the edges weight more than BB, then the
799 // edge of the last remaining edge is set to zero.
800 //
801 // - There exists a self-referential edge and the weight of BB is
802 // known. In this case, this edge can be based on BB's weight.
803 // We add up all the other known edges and set the weight on
804 // the self-referential edge as we did in the previous case.
805 //
806 // In any other case, we must continue iterating. Eventually,
807 // all edges will get a weight, or iteration will stop when
808 // it reaches SampleProfileMaxPropagateIterations.
809 if (NumUnknownEdges <= 1) {
810 uint64_t &BBWeight = BlockWeights[EC];
811 if (NumUnknownEdges == 0) {
812 if (!VisitedBlocks.count(EC)) {
813 // If we already know the weight of all edges, the weight of the
814 // basic block can be computed. It should be no larger than the sum
815 // of all edge weights.
816 if (TotalWeight > BBWeight) {
817 BBWeight = TotalWeight;
818 Changed = true;
819 LLVM_DEBUG(dbgs() << "All edge weights for " << BB->getName()
820 << " known. Set weight for block: ";
821 printBlockWeight(dbgs(), BB););
822 }
823 } else if (NumTotalEdges == 1 &&
824 EdgeWeights[SingleEdge] < BlockWeights[EC]) {
825 // If there is only one edge for the visited basic block, use the
826 // block weight to adjust edge weight if edge weight is smaller.
827 EdgeWeights[SingleEdge] = BlockWeights[EC];
828 Changed = true;
829 }
830 } else if (NumUnknownEdges == 1 && VisitedBlocks.count(EC)) {
831 // If there is a single unknown edge and the block has been
832 // visited, then we can compute E's weight.
833 if (BBWeight >= TotalWeight)
834 EdgeWeights[UnknownEdge] = BBWeight - TotalWeight;
835 else
836 EdgeWeights[UnknownEdge] = 0;
837 const BasicBlockT *OtherEC;
838 if (i == 0)
839 OtherEC = EquivalenceClass[UnknownEdge.first];
840 else
841 OtherEC = EquivalenceClass[UnknownEdge.second];
842 // Edge weights should never exceed the BB weights it connects.
843 if (VisitedBlocks.count(OtherEC) &&
844 EdgeWeights[UnknownEdge] > BlockWeights[OtherEC])
845 EdgeWeights[UnknownEdge] = BlockWeights[OtherEC];
846 VisitedEdges.insert(UnknownEdge);
847 Changed = true;
848 LLVM_DEBUG(dbgs() << "Set weight for edge: ";
849 printEdgeWeight(dbgs(), UnknownEdge));
850 }
851 } else if (VisitedBlocks.count(EC) && BlockWeights[EC] == 0) {
852 // If a block Weights 0, all its in/out edges should weight 0.
853 if (i == 0) {
854 for (auto *Pred : Predecessors[BB]) {
855 Edge E = std::make_pair(Pred, BB);
856 EdgeWeights[E] = 0;
857 VisitedEdges.insert(E);
858 }
859 } else {
860 for (auto *Succ : Successors[BB]) {
861 Edge E = std::make_pair(BB, Succ);
862 EdgeWeights[E] = 0;
863 VisitedEdges.insert(E);
864 }
865 }
866 } else if (SelfReferentialEdge.first && VisitedBlocks.count(EC)) {
867 uint64_t &BBWeight = BlockWeights[BB];
868 // We have a self-referential edge and the weight of BB is known.
869 if (BBWeight >= TotalWeight)
870 EdgeWeights[SelfReferentialEdge] = BBWeight - TotalWeight;
871 else
872 EdgeWeights[SelfReferentialEdge] = 0;
873 VisitedEdges.insert(SelfReferentialEdge);
874 Changed = true;
875 LLVM_DEBUG(dbgs() << "Set self-referential edge weight to: ";
876 printEdgeWeight(dbgs(), SelfReferentialEdge));
877 }
878 if (UpdateBlockCount && TotalWeight > 0 &&
879 VisitedBlocks.insert(EC).second) {
880 BlockWeights[EC] = TotalWeight;
881 Changed = true;
882 }
883 }
884 }
885
886 return Changed;
887}
888
889/// Build in/out edge lists for each basic block in the CFG.
890///
891/// We are interested in unique edges. If a block B1 has multiple
892/// edges to another block B2, we only add a single B1->B2 edge.
893template <typename BT>
895 for (auto &BI : F) {
896 BasicBlockT *B1 = &BI;
897
898 // Add predecessors for B1.
900 auto &Preds = Predecessors[B1];
901 if (!Preds.empty())
902 llvm_unreachable("Found a stale predecessors list in a basic block.");
903 for (auto *B2 : getPredecessors(B1))
904 if (Visited.insert(B2).second)
905 Preds.push_back(B2);
906
907 // Add successors for B1.
908 Visited.clear();
909 auto &Succs = Successors[B1];
910 if (!Succs.empty())
911 llvm_unreachable("Found a stale successors list in a basic block.");
912 for (auto *B2 : getSuccessors(B1))
913 if (Visited.insert(B2).second)
914 Succs.push_back(B2);
915 }
916}
917
918/// Propagate weights into edges
919///
920/// The following rules are applied to every block BB in the CFG:
921///
922/// - If BB has a single predecessor/successor, then the weight
923/// of that edge is the weight of the block.
924///
925/// - If all incoming or outgoing edges are known except one, and the
926/// weight of the block is already known, the weight of the unknown
927/// edge will be the weight of the block minus the sum of all the known
928/// edges. If the sum of all the known edges is larger than BB's weight,
929/// we set the unknown edge weight to zero.
930///
931/// - If there is a self-referential edge, and the weight of the block is
932/// known, the weight for that edge is set to the weight of the block
933/// minus the weight of the other incoming edges to that block (if
934/// known).
935template <typename BT>
937 // Flow-based profile inference is only usable with BasicBlock instantiation
938 // of SampleProfileLoaderBaseImpl.
940 // Prepare block sample counts for inference.
941 BlockWeightMap SampleBlockWeights;
942 for (const auto &BI : F) {
943 ErrorOr<uint64_t> Weight = getBlockWeight(&BI);
944 if (Weight)
945 SampleBlockWeights[&BI] = Weight.get();
946 }
947 // Fill in BlockWeights and EdgeWeights using an inference algorithm.
948 applyProfi(F, Successors, SampleBlockWeights, BlockWeights, EdgeWeights);
949 } else {
950 bool Changed = true;
951 unsigned I = 0;
952
953 // If BB weight is larger than its corresponding loop's header BB weight,
954 // use the BB weight to replace the loop header BB weight.
955 for (auto &BI : F) {
956 BasicBlockT *BB = &BI;
957 LoopT *L = LI->getLoopFor(BB);
958 if (!L) {
959 continue;
960 }
961 BasicBlockT *Header = L->getHeader();
962 if (Header && BlockWeights[BB] > BlockWeights[Header]) {
963 BlockWeights[Header] = BlockWeights[BB];
964 }
965 }
966
967 // Propagate until we converge or we go past the iteration limit.
970 }
971
972 // The first propagation propagates BB counts from annotated BBs to unknown
973 // BBs. The 2nd propagation pass resets edges weights, and use all BB
974 // weights to propagate edge weights.
975 VisitedEdges.clear();
976 Changed = true;
979 }
980
981 // The 3rd propagation pass allows adjust annotated BB weights that are
982 // obviously wrong.
983 Changed = true;
986 }
987 }
988}
989
990template <typename FT>
997
998/// Generate branch weight metadata for all branches in \p F.
999///
1000/// Branch weights are computed out of instruction samples using a
1001/// propagation heuristic. Propagation proceeds in 3 phases:
1002///
1003/// 1- Assignment of block weights. All the basic blocks in the function
1004/// are initial assigned the same weight as their most frequently
1005/// executed instruction.
1006///
1007/// 2- Creation of equivalence classes. Since samples may be missing from
1008/// blocks, we can fill in the gaps by setting the weights of all the
1009/// blocks in the same equivalence class to the same weight. To compute
1010/// the concept of equivalence, we use dominance and loop information.
1011/// Two blocks B1 and B2 are in the same equivalence class if B1
1012/// dominates B2, B2 post-dominates B1 and both are in the same loop.
1013///
1014/// 3- Propagation of block weights into edges. This uses a simple
1015/// propagation heuristic. The following rules are applied to every
1016/// block BB in the CFG:
1017///
1018/// - If BB has a single predecessor/successor, then the weight
1019/// of that edge is the weight of the block.
1020///
1021/// - If all the edges are known except one, and the weight of the
1022/// block is already known, the weight of the unknown edge will
1023/// be the weight of the block minus the sum of all the known
1024/// edges. If the sum of all the known edges is larger than BB's weight,
1025/// we set the unknown edge weight to zero.
1026///
1027/// - If there is a self-referential edge, and the weight of the block is
1028/// known, the weight for that edge is set to the weight of the block
1029/// minus the weight of the other incoming edges to that block (if
1030/// known).
1031///
1032/// Since this propagation is not guaranteed to finalize for every CFG, we
1033/// only allow it to proceed for a limited number of iterations (controlled
1034/// by -sample-profile-max-propagate-iterations).
1035///
1036/// FIXME: Try to replace this propagation heuristic with a scheme
1037/// that is guaranteed to finalize. A work-list approach similar to
1038/// the standard value propagation algorithm used by SSA-CCP might
1039/// work here.
1040///
1041/// \param F The function to query.
1042///
1043/// \returns true if \p F was modified. Returns false, otherwise.
1044template <typename BT>
1046 FunctionT &F, const DenseSet<GlobalValue::GUID> &InlinedGUIDs) {
1047 bool Changed = (InlinedGUIDs.size() != 0);
1048
1049 // Compute basic block weights.
1051
1052 if (Changed) {
1053 // Initialize propagation.
1054 initWeightPropagation(F, InlinedGUIDs);
1055
1056 // Propagate weights to all edges.
1058
1059 // Post-process propagated weights.
1060 finalizeWeightPropagation(F, InlinedGUIDs);
1061 }
1062
1063 return Changed;
1064}
1065
1066template <typename BT>
1068 FunctionT &F, const DenseSet<GlobalValue::GUID> &InlinedGUIDs) {
1069 // Add an entry count to the function using the samples gathered at the
1070 // function entry.
1071 // Sets the GUIDs that are inlined in the profiled binary. This is used
1072 // for ThinLink to make correct liveness analysis, and also make the IR
1073 // match the profiled binary before annotation.
1075 ProfileCount(Samples->getHeadSamples() + 1, Function::PCT_Real),
1076 &InlinedGUIDs);
1077
1078 if (!SampleProfileUseProfi) {
1079 // Compute dominance and loop info needed for propagation.
1081
1082 // Find equivalence classes.
1084 }
1085
1086 // Before propagation starts, build, for each block, a list of
1087 // unique predecessors and successors. This is necessary to handle
1088 // identical edges in multiway branches. Since we visit all blocks and all
1089 // edges of the CFG, it is cleaner to build these lists once at the start
1090 // of the pass.
1091 buildEdges(F);
1092}
1093
1094template <typename BT>
1096 FunctionT &F, const DenseSet<GlobalValue::GUID> &InlinedGUIDs) {
1097 // If we utilize a flow-based count inference, then we trust the computed
1098 // counts and set the entry count as computed by the algorithm. This is
1099 // primarily done to sync the counts produced by profi and BFI inference,
1100 // which uses the entry count for mass propagation.
1101 // If profi produces a zero-value for the entry count, we fallback to
1102 // Samples->getHeadSamples() + 1 to avoid functions with zero count.
1104 const BasicBlockT *EntryBB = getEntryBB(&F);
1105 if (BlockWeights[EntryBB] > 0) {
1108 &InlinedGUIDs);
1109 }
1110 }
1111}
1112
1113template <typename BT>
1115 // If coverage checking was requested, compute it now.
1116 const Function &Func = getFunction(F);
1118 unsigned Used = CoverageTracker.countUsedRecords(Samples, PSI);
1119 unsigned Total = CoverageTracker.countBodyRecords(Samples, PSI);
1120 unsigned Coverage = CoverageTracker.computeCoverage(Used, Total);
1121 if (Coverage < SampleProfileRecordCoverage) {
1122 Func.getContext().diagnose(DiagnosticInfoSampleProfile(
1123 Func.getSubprogram()->getFilename(), getFunctionLoc(F),
1124 Twine(Used) + " of " + Twine(Total) + " available profile records (" +
1125 Twine(Coverage) + "%) were applied",
1126 DS_Warning));
1127 }
1128 }
1129
1131 uint64_t Used = CoverageTracker.getTotalUsedSamples();
1132 uint64_t Total = CoverageTracker.countBodySamples(Samples, PSI);
1133 unsigned Coverage = CoverageTracker.computeCoverage(Used, Total);
1134 if (Coverage < SampleProfileSampleCoverage) {
1135 Func.getContext().diagnose(DiagnosticInfoSampleProfile(
1136 Func.getSubprogram()->getFilename(), getFunctionLoc(F),
1137 Twine(Used) + " of " + Twine(Total) + " available profile samples (" +
1138 Twine(Coverage) + "%) were applied",
1139 DS_Warning));
1140 }
1141 }
1142}
1143
1144/// Get the line number for the function header.
1145///
1146/// This looks up function \p F in the current compilation unit and
1147/// retrieves the line number where the function is defined. This is
1148/// line 0 for all the samples read from the profile file. Every line
1149/// number is relative to this line.
1150///
1151/// \param F Function object to query.
1152///
1153/// \returns the line number where \p F is defined. If it returns 0,
1154/// it means that there is no debug information available for \p F.
1155template <typename BT>
1157 const Function &Func = getFunction(F);
1158 if (DISubprogram *S = Func.getSubprogram())
1159 return S->getLine();
1160
1162 return 0;
1163
1164 // If the start of \p F is missing, emit a diagnostic to inform the user
1165 // about the missed opportunity.
1166 Func.getContext().diagnose(DiagnosticInfoSampleProfile(
1167 "No debug information found in function " + Func.getName() +
1168 ": Function profile not used",
1169 DS_Warning));
1170 return 0;
1171}
1172
1173#undef DEBUG_TYPE
1174
1175} // namespace llvm
1176#endif // LLVM_TRANSFORMS_UTILS_SAMPLEPROFILELOADERBASEIMPL_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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:114
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
ArrayRef - 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:123
LLVM_ABI unsigned getLine() const
Definition DebugLoc.cpp:52
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
Diagnostic information for the sample profiler.
Represents either an error or a value T.
Definition ErrorOr.h:56
reference get()
Definition ErrorOr.h:149
Class to represent profile counts.
Definition Function.h:299
void setEntryCount(ProfileCount 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:67
A tuple of MDNodes.
Definition Metadata.h:1760
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
size_type size() const
Definition DenseSet.h:87
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:783
static LLVM_ABI bool ProfileIsProbeBased
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.
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
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:696
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< pred_iterator > pred_range
Definition CFG.h:108
iterator_range< succ_iterator > succ_range
Definition CFG.h:140
auto successors(const MachineBasicBlock *BB)
LLVM_ABI cl::opt< bool > EnableFSDiscriminator
cl::opt< unsigned > SampleProfileSampleCoverage
static void buildTopDownFuncOrder(LazyCallGraph &CG, std::vector< Function * > &FunctionOrderList)
Op::Description Desc
cl::opt< unsigned > SampleProfileRecordCoverage
cl::opt< unsigned > SampleProfileMaxPropagateIterations
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:207
Function::ProfileCount ProfileCount
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:129
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:1917
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:870
#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)