LLVM 24.0.0git
SampleProfileProbe.cpp
Go to the documentation of this file.
1//===- SampleProfileProbe.cpp - Pseudo probe Instrumentation -------------===//
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// This file implements the SampleProfileProber transformation.
10//
11//===----------------------------------------------------------------------===//
12
14#include "IPOOptions.h"
15#include "llvm/ADT/STLExtras.h"
17#include "llvm/ADT/Statistic.h"
18#include "llvm/ADT/StringSet.h"
22#include "llvm/IR/BasicBlock.h"
25#include "llvm/IR/IRBuilder.h"
26#include "llvm/IR/Instruction.h"
28#include "llvm/IR/MDBuilder.h"
29#include "llvm/IR/Module.h"
31#include "llvm/IR/PseudoProbe.h"
33#include "llvm/Support/CRC.h"
37#include <vector>
38
39using namespace llvm;
40#define DEBUG_TYPE "pseudo-probe"
41
42STATISTIC(ArtificialDbgLine,
43 "Number of probes that have an artificial debug line");
44
46 uint64_t Hash = 0;
47 const DILocation *InlinedAt = DIL ? DIL->getInlinedAt() : nullptr;
48 while (InlinedAt) {
49 Hash ^= MD5Hash(std::to_string(InlinedAt->getLine()));
50 Hash ^= MD5Hash(std::to_string(InlinedAt->getColumn()));
51 auto Name = InlinedAt->getSubprogramLinkageName();
52 Hash ^= MD5Hash(Name);
53 InlinedAt = InlinedAt->getInlinedAt();
54 }
55 return Hash;
56}
57
59 return getCallStackHash(Inst.getDebugLoc());
60}
61
62bool PseudoProbeVerifier::shouldVerifyFunction(const Function *F) {
63 // Skip function declaration.
64 if (F->isDeclaration())
65 return false;
66 // Skip function that will not be emitted into object file. The prevailing
67 // defintion will be verified instead.
68 if (F->hasAvailableExternallyLinkage())
69 return false;
70 return VerifyFuncNames.empty() || VerifyFuncNames.contains(F->getName());
71}
72
74 : Enabled(getIPOOptions(C).verify_pseudo_probe),
75 VerifyFuncNames(llvm::from_range,
76 getIPOOptions(C).verify_pseudo_probe_funcs) {}
77
79 if (Enabled) {
80 PIC.registerAfterPassCallback(
81 [this](StringRef P, IRUnitRef IR, const PreservedAnalyses &) {
82 this->runAfterPass(P, IR);
83 });
84 }
85}
86
87// Callback to run after each transformation for the new pass manager.
89 std::string Banner =
90 "\n*** Pseudo Probe Verification After " + PassID.str() + " ***\n";
91 dbgs() << Banner;
92 if (const auto *M = dyn_cast<Module>(IR))
93 runAfterPass(M);
94 else if (const auto *F = dyn_cast<Function>(IR))
96 else if (const auto *C = dyn_cast<LazyCallGraph::SCC>(IR))
98 else if (const auto *L = dyn_cast<Loop>(IR))
99 runAfterPass(L);
100 else
101 llvm_unreachable("Unknown IR unit");
102}
103
105 for (const Function &F : *M)
106 runAfterPass(&F);
107}
108
110 for (const LazyCallGraph::Node &N : *C)
111 runAfterPass(&N.getFunction());
112}
113
115 if (!shouldVerifyFunction(F))
116 return;
117 ProbeFactorMap ProbeFactors;
118 for (const auto &BB : *F)
119 collectProbeFactors(&BB, ProbeFactors);
120 verifyProbeFactors(F, ProbeFactors);
121}
122
124 const Function *F = L->getHeader()->getParent();
126}
127
128void PseudoProbeVerifier::collectProbeFactors(const BasicBlock *Block,
129 ProbeFactorMap &ProbeFactors) {
130 for (const auto &I : *Block) {
131 if (std::optional<PseudoProbe> Probe = extractProbe(I)) {
133 ProbeFactors[{Probe->Id, Hash}] += Probe->Factor;
134 }
135 }
136}
137
138void PseudoProbeVerifier::verifyProbeFactors(
139 const Function *F, const ProbeFactorMap &ProbeFactors) {
140 bool BannerPrinted = false;
141 auto &PrevProbeFactors = FunctionProbeFactors[F->getName()];
142 for (const auto &I : ProbeFactors) {
143 float CurProbeFactor = I.second;
144 auto [It, Inserted] = PrevProbeFactors.try_emplace(I.first);
145 if (!Inserted) {
146 float PrevProbeFactor = It->second;
147 if (std::abs(CurProbeFactor - PrevProbeFactor) >
148 DistributionFactorVariance) {
149 if (!BannerPrinted) {
150 dbgs() << "Function " << F->getName() << ":\n";
151 BannerPrinted = true;
152 }
153 dbgs() << "Probe " << I.first.first << "\tprevious factor "
154 << format("%0.2f", PrevProbeFactor) << "\tcurrent factor "
155 << format("%0.2f", CurProbeFactor) << "\n";
156 }
157 }
158
159 // Update
160 It->second = I.second;
161 }
162}
163
165 BlockProbeIds.clear();
166 CallProbeIds.clear();
168
169 DenseSet<BasicBlock *> BlocksToIgnore;
170 DenseSet<BasicBlock *> BlocksAndCallsToIgnore;
171 computeBlocksToIgnore(BlocksToIgnore, BlocksAndCallsToIgnore);
172
173 computeProbeId(BlocksToIgnore, BlocksAndCallsToIgnore);
174 computeCFGHash(BlocksToIgnore);
175}
176
177// Two purposes to compute the blocks to ignore:
178// 1. Reduce the IR size.
179// 2. Make the instrumentation(checksum) stable. e.g. the frondend may
180// generate unstable IR while optimizing nounwind attribute, some versions are
181// optimized with the call-to-invoke conversion, while other versions do not.
182// This discrepancy in probe ID could cause profile mismatching issues.
183// Note that those ignored blocks are either cold blocks or new split blocks
184// whose original blocks are instrumented, so it shouldn't degrade the profile
185// quality.
186void SampleProfileProber::computeBlocksToIgnore(
187 DenseSet<BasicBlock *> &BlocksToIgnore,
188 DenseSet<BasicBlock *> &BlocksAndCallsToIgnore) {
189 // Ignore the cold EH and unreachable blocks and calls.
190 computeEHOnlyBlocks(*F, BlocksAndCallsToIgnore);
191 findUnreachableBlocks(BlocksAndCallsToIgnore);
192
193 BlocksToIgnore.insert_range(BlocksAndCallsToIgnore);
194
195 // Handle the call-to-invoke conversion case: make sure that the probe id and
196 // callsite id are consistent before and after the block split. For block
197 // probe, we only keep the head block probe id and ignore the block ids of the
198 // normal dests. For callsite probe, it's different to block probe, there is
199 // no additional callsite in the normal dests, so we don't ignore the
200 // callsites.
201 findInvokeNormalDests(BlocksToIgnore);
202}
203
204// Unreachable blocks and calls are always cold, ignore them.
205void SampleProfileProber::findUnreachableBlocks(
206 DenseSet<BasicBlock *> &BlocksToIgnore) {
207 for (auto &BB : *F) {
208 if (&BB != &F->getEntryBlock() && pred_size(&BB) == 0)
209 BlocksToIgnore.insert(&BB);
210 }
211}
212
213// Follow invoke normal-dest edges and record blocks that sit on a cycle.
214static void
216 DenseSet<const BasicBlock *> &CycleBlocks) {
218 DenseSet<const BasicBlock *> OnCurrentPath;
220
221 for (const BasicBlock &Start : F) {
222 if (Processed.contains(&Start))
223 continue;
224
225 CurrentPath.clear();
226 OnCurrentPath.clear();
227 const BasicBlock *Cur = &Start;
228 while (Cur) {
229 if (OnCurrentPath.contains(Cur)) {
230 // Back-edge onto CurrentPath: the cycle is the suffix starting at Cur.
231 auto CycleStart = llvm::find(CurrentPath, Cur);
232 assert(CycleStart != CurrentPath.end() &&
233 "OnCurrentPath must hold exactly the blocks in CurrentPath");
234 CycleBlocks.insert(CycleStart, CurrentPath.end());
235 break;
236 }
237 if (Processed.contains(Cur))
238 break;
239 OnCurrentPath.insert(Cur);
240 CurrentPath.push_back(Cur);
241 if (const auto *II = dyn_cast<InvokeInst>(Cur->getTerminator()))
242 Cur = II->getNormalDest();
243 else
244 Cur = nullptr;
245 }
246 for (const BasicBlock *B : CurrentPath)
247 Processed.insert(B);
248 }
249}
250
251// In call-to-invoke conversion, basic block can be split into multiple blocks,
252// only instrument probe in the head block, ignore the normal dests.
253void SampleProfileProber::findInvokeNormalDests(
254 DenseSet<BasicBlock *> &InvokeNormalDests) {
255 DenseSet<const BasicBlock *> CycleBlocks;
256 findInvokeNormalDestCycles(*F, CycleBlocks);
257
258 for (auto &BB : *F) {
259 auto *TI = BB.getTerminator();
260 if (auto *II = dyn_cast<InvokeInst>(TI)) {
261 auto *ND = II->getNormalDest();
262 // Cycle members are original loop blocks, not split continuations.
263 if (!CycleBlocks.contains(ND))
264 InvokeNormalDests.insert(ND);
265
266 // The normal dest and the try/catch block are connected by an
267 // unconditional branch.
268 while (pred_size(ND) == 1) {
269 auto *Pred = *pred_begin(ND);
270 if (succ_size(Pred) == 1) {
271 InvokeNormalDests.insert(Pred);
272 ND = Pred;
273 } else
274 break;
275 }
276 }
277 }
278}
279
280// The call-to-invoke conversion splits the original block into a list of block,
281// we need to compute the hash using the original block's successors to keep the
282// CFG Hash consistent. For a given head block, we keep searching the
283// succesor(normal dest or unconditional branch dest) to find the tail block,
284// the tail block's successors are the original block's successors.
285const Instruction *SampleProfileProber::getOriginalTerminator(
286 const BasicBlock *Head, const DenseSet<BasicBlock *> &BlocksToIgnore) {
287 // Follow invoke dests and ignored blocks to the original terminator. Stop
288 // if a block repeats; a cycle of invokes has no unique tail.
289 DenseSet<const BasicBlock *> Visited;
290 const BasicBlock *BB = Head;
291 Visited.insert(BB);
292 while (true) {
293 auto *TI = BB->getTerminator();
294 const BasicBlock *Next = nullptr;
295 if (const auto *II = dyn_cast<InvokeInst>(TI))
296 Next = II->getNormalDest();
297 else if (succ_size(BB) == 1 && BlocksToIgnore.contains(*succ_begin(BB)))
298 Next = *succ_begin(BB);
299 else
300 return TI;
301
302 // A cycle has no tail block whose terminator represents the original
303 // block. Stop at the terminator that closes the cycle.
304 if (!Visited.insert(Next).second)
305 return TI;
306
307 BB = Next;
308 }
309}
310
311// Compute Hash value for the CFG: the lower 32 bits are CRC32 of the index
312// value of each BB in the CFG. The higher 32 bits record the number of edges
313// preceded by the number of indirect calls.
314// This is derived from FuncPGOInstrumentation<Edge, BBInfo>::computeCFGHash().
315void SampleProfileProber::computeCFGHash(
316 const DenseSet<BasicBlock *> &BlocksToIgnore) {
317 std::vector<uint8_t> Indexes;
318 JamCRC JC;
319 for (auto &BB : *F) {
320 if (BlocksToIgnore.contains(&BB))
321 continue;
322
323 auto *TI = getOriginalTerminator(&BB, BlocksToIgnore);
324 for (unsigned I = 0, E = TI->getNumSuccessors(); I != E; ++I) {
325 auto *Succ = TI->getSuccessor(I);
326 auto Index = getBlockId(Succ);
327 // Ingore ignored-block(zero ID) to avoid unstable checksum.
328 if (Index == 0)
329 continue;
330 for (int J = 0; J < 4; J++)
331 Indexes.push_back((uint8_t)(Index >> (J * 8)));
332 }
333 }
334
335 JC.update(Indexes);
336
337 FunctionHash = (uint64_t)CallProbeIds.size() << 48 |
338 (uint64_t)Indexes.size() << 32 | JC.getCRC();
339 // Reserve bit 60-63 for other information purpose.
340 FunctionHash &= 0x0FFFFFFFFFFFFFFF;
341 assert(FunctionHash && "Function checksum should not be zero");
342 LLVM_DEBUG(dbgs() << "\nFunction Hash Computation for " << F->getName()
343 << ":\n"
344 << " CRC = " << JC.getCRC() << ", Edges = "
345 << Indexes.size() << ", ICSites = " << CallProbeIds.size()
346 << ", Hash = " << FunctionHash << "\n");
347}
348
349void SampleProfileProber::computeProbeId(
350 const DenseSet<BasicBlock *> &BlocksToIgnore,
351 const DenseSet<BasicBlock *> &BlocksAndCallsToIgnore) {
352 LLVMContext &Ctx = F->getContext();
353 Module *M = F->getParent();
354
355 for (auto &BB : *F) {
356 if (!BlocksToIgnore.contains(&BB))
357 BlockProbeIds[&BB] = ++LastProbeId;
358
359 if (BlocksAndCallsToIgnore.contains(&BB))
360 continue;
361 for (auto &I : BB) {
363 continue;
364
365 // The current implementation uses the lower 16 bits of the discriminator
366 // so anything larger than 0xFFFF will be ignored.
367 if (LastProbeId >= 0xFFFF) {
368 std::string Msg = "Pseudo instrumentation incomplete for " +
369 std::string(F->getName()) + " because it's too large";
370 Ctx.diagnose(
371 DiagnosticInfoSampleProfile(M->getName().data(), Msg, DS_Warning));
372 return;
373 }
374
375 CallProbeIds[&I] = ++LastProbeId;
376 }
377 }
378}
379
380uint32_t SampleProfileProber::getBlockId(const BasicBlock *BB) const {
381 auto I = BlockProbeIds.find(const_cast<BasicBlock *>(BB));
382 return I == BlockProbeIds.end() ? 0 : I->second;
383}
384
385uint32_t SampleProfileProber::getCallsiteId(const Instruction *Call) const {
386 auto Iter = CallProbeIds.find(const_cast<Instruction *>(Call));
387 return Iter == CallProbeIds.end() ? 0 : Iter->second;
388}
389
391 Module *M = F.getParent();
392 MDBuilder MDB(F.getContext());
393 // Since the GUID from probe desc and inline stack are computed separately, we
394 // need to make sure their names are consistent, so here also use the name
395 // from debug info.
396 StringRef FName = F.getName();
397 if (auto *SP = F.getSubprogram()) {
398 FName = SP->getLinkageName();
399 if (FName.empty())
400 FName = SP->getName();
401 }
403
404 // Assign an artificial debug line to a probe that doesn't come with a real
405 // line. A probe not having a debug line will get an incomplete inline
406 // context. This will cause samples collected on the probe to be counted
407 // into the base profile instead of a context profile. The line number
408 // itself is not important though.
409 auto AssignDebugLoc = [&](Instruction *I) {
411 "Expecting pseudo probe or call instructions");
412 if (!I->getDebugLoc()) {
413 if (auto *SP = F.getSubprogram()) {
414 auto DIL = DILocation::get(SP->getContext(), 0, 0, SP);
415 I->setDebugLoc(DIL);
416 ArtificialDbgLine++;
417 LLVM_DEBUG({
418 dbgs() << "\nIn Function " << F.getName()
419 << " Probe gets an artificial debug line\n";
420 I->dump();
421 });
422 }
423 }
424 };
425
426 // Probe basic blocks.
427 for (auto &I : BlockProbeIds) {
428 BasicBlock *BB = I.first;
429 uint32_t Index = I.second;
430 // Insert a probe before an instruction with a valid debug line number which
431 // will be assigned to the probe. The line number will be used later to
432 // model the inline context when the probe is inlined into other functions.
433 // Debug instructions, phi nodes and lifetime markers do not have an valid
434 // line number. Real instructions generated by optimizations may not come
435 // with a line number either.
436 auto HasValidDbgLine = [](Instruction *J) {
437 return !isa<PHINode>(J) && !J->isLifetimeStartOrEnd() && J->getDebugLoc();
438 };
439
440 Instruction *J = &*BB->getFirstInsertionPt();
441 while (J != BB->getTerminator() && !HasValidDbgLine(J)) {
442 J = J->getNextNode();
443 }
444
445 // A pseudo probe must not be inserted between a `musttail` or
446 // `llvm.experimental.deoptimize` call and its following `ret`, as this
447 // produces invalid IR. Such a call is required to immediately precede the
448 // block's `ret`, so only that position needs to be checked. Insert the
449 // probe before the call instead.
450 if (auto *Ret = dyn_cast<ReturnInst>(BB->getTerminator()))
451 if (auto *CI = dyn_cast_or_null<CallInst>(Ret->getPrevNode()))
452 if ((CI->isMustTailCall() ||
453 CI->getIntrinsicID() == Intrinsic::experimental_deoptimize) &&
454 !J->comesBefore(CI))
455 J = CI;
456
457 IRBuilder<> Builder(J);
458 assert(Builder.GetInsertPoint() != BB->end() &&
459 "Cannot get the probing point");
460 Function *ProbeFn =
461 llvm::Intrinsic::getOrInsertDeclaration(M, Intrinsic::pseudoprobe);
462 Value *Args[] = {Builder.getInt64(Guid), Builder.getInt64(Index),
463 Builder.getInt32(0),
464 Builder.getInt64(PseudoProbeFullDistributionFactor)};
465 auto *Probe = Builder.CreateCall(ProbeFn, Args);
466 AssignDebugLoc(Probe);
467 // Reset the dwarf discriminator if the debug location comes with any. The
468 // discriminator field may be used by FS-AFDO later in the pipeline.
469 if (auto DIL = Probe->getDebugLoc()) {
470 if (DIL->getDiscriminator()) {
471 DIL = DIL->cloneWithDiscriminator(0);
472 Probe->setDebugLoc(DIL);
473 }
474 }
475 }
476
477 // Probe both direct calls and indirect calls. Direct calls are probed so that
478 // their probe ID can be used as an call site identifier to represent a
479 // calling context.
480 for (auto &I : CallProbeIds) {
481 auto *Call = I.first;
482 uint32_t Index = I.second;
483 uint32_t Type = cast<CallBase>(Call)->getCalledFunction()
486 AssignDebugLoc(Call);
487 if (auto DIL = Call->getDebugLoc()) {
488 // Levarge the 32-bit discriminator field of debug data to store the ID
489 // and type of a callsite probe. This gets rid of the dependency on
490 // plumbing a customized metadata through the codegen pipeline.
493 DIL->getBaseDiscriminator());
494 DIL = DIL->cloneWithDiscriminator(V);
495 Call->setDebugLoc(DIL);
496 }
497 }
498
499 // Create module-level metadata that contains function info necessary to
500 // synthesize probe-based sample counts, which are
501 // - FunctionGUID
502 // - FunctionHash.
503 // - FunctionName
504 auto Hash = getFunctionHash();
505 auto *MD = MDB.createPseudoProbeDesc(Guid, Hash, FName);
506 auto *NMD = M->getNamedMetadata(PseudoProbeDescMetadataName);
507 assert(NMD && "llvm.pseudo_probe_desc should be pre-created");
508 NMD->addOperand(MD);
509}
510
513 // Create the pseudo probe desc metadata beforehand.
514 // Note that modules with only data but no functions will require this to
515 // be set up so that they will be known as probed later.
516 M.getOrInsertNamedMetadata(PseudoProbeDescMetadataName);
517
518 for (auto &F : M) {
519 if (F.isDeclaration())
520 continue;
521 SampleProfileProber ProbeManager(F);
522 ProbeManager.instrumentOneFunc(F, TM);
523 }
524
526}
527
528void PseudoProbeUpdatePass::runOnFunction(Function &F,
531 auto BBProfileCount = [&BFI](BasicBlock *BB) {
532 return BFI.getBlockProfileCount(BB).value_or(0);
533 };
534
535 // Collect the sum of execution weight for each probe.
536 ProbeFactorMap ProbeFactors;
537 for (auto &Block : F) {
538 for (auto &I : Block) {
539 if (std::optional<PseudoProbe> Probe = extractProbe(I)) {
541 ProbeFactors[{Probe->Id, Hash}] += BBProfileCount(&Block);
542 }
543 }
544 }
545
546 // Fix up over-counted probes.
547 for (auto &Block : F) {
548 for (auto &I : Block) {
549 if (std::optional<PseudoProbe> Probe = extractProbe(I)) {
551 float Sum = ProbeFactors[{Probe->Id, Hash}];
552 if (Sum != 0)
553 setProbeDistributionFactor(I, BBProfileCount(&Block) / Sum);
554 }
555 }
556 }
557}
558
561 if (getIPOOptions(M).update_pseudo_probe) {
562 for (auto &F : M) {
563 if (F.isDeclaration())
564 continue;
567 runOnFunction(F, FAM);
568 }
569 }
571}
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t 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")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Module.h This file contains the declarations for the Module class.
Legalize the Machine IR a function s Machine IR
Definition Legalizer.cpp:85
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
#define P(N)
FunctionAnalysisManager FAM
PassInstrumentationCallbacks PIC
This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...
const char * Msg
This file contains some templates that are useful if you are working with the STL at all.
static void findInvokeNormalDestCycles(const Function &F, DenseSet< const BasicBlock * > &CycleBlocks)
static uint64_t computeCallStackHash(const Instruction &Inst)
static uint64_t getCallStackHash(const DILocation *DIL)
This file provides the interface for the pseudo probe implementation for AutoFDO.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
StringSet - A set-like wrapper for the StringMap.
#define LLVM_DEBUG(...)
Definition Debug.h:119
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator end()
Definition BasicBlock.h:453
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
LLVM_ABI std::optional< uint64_t > getBlockProfileCount(const BasicBlock *BB) const
Returns the estimated profile count of BB.
Implements a dense probed hash-table based set.
Definition DenseSet.h:283
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
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2987
A type-erased reference to the IR unit a pass or analysis is running on, together with the kind of IR...
Definition IRUnitRef.h:60
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
uint32_t getCRC() const
Definition CRC.h:77
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Definition CRC.cpp:103
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
A node in the call graph.
An SCC of the call graph.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
LLVM_ABI MDNode * createPseudoProbeDesc(uint64_t GUID, uint64_t Hash, StringRef FName)
Return metadata containing the pseudo probe descriptor for a function.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1579
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI void registerCallbacks(PassInstrumentationCallbacks &PIC)
LLVM_ABI void runAfterPass(StringRef PassID, IRUnitRef IR)
LLVM_ABI PseudoProbeVerifier(const LLVMContext &C)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Sample profile pseudo prober.
LLVM_ABI SampleProfileProber(Function &F)
LLVM_ABI void instrumentOneFunc(Function &F, TargetMachine *TM)
void push_back(const T &Elt)
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
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Primary interface to the complete machine description for the target machine.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:210
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition DenseSet.h:183
void insert_range(Range &&R)
Definition DenseSet.h:236
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Definition ilist_node.h:348
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:83
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
uint64_t MD5Hash(const FunctionId &Obj)
Definition FunctionId.h:167
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1781
DenseMap< std::pair< uint64_t, uint64_t >, float > ProbeFactorMap
static constexpr uint64_t PseudoProbeFullDistributionFactor
Definition PseudoProbe.h:39
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
constexpr from_range_t from_range
auto pred_size(const MachineBasicBlock *BB)
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
LLVM_ABI void setProbeDistributionFactor(Instruction &Inst, float Factor)
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
const IPOOptions & getIPOOptions(const LLVMContext &C)
Definition IPOOptions.h:36
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
auto succ_size(const MachineBasicBlock *BB)
static void computeEHOnlyBlocks(FunctionT &F, DenseSet< BlockT * > &EHBlocks)
Compute a list of blocks that are only reachable via EH paths.
Definition EHUtils.h:18
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:102
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
auto pred_begin(const MachineBasicBlock *BB)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
constexpr const char * PseudoProbeDescMetadataName
Definition PseudoProbe.h:26
#define N
static constexpr uint8_t FullDistributionFactor
static uint32_t packProbeData(uint32_t Index, uint32_t Type, uint32_t Flags, uint32_t Factor, std::optional< uint32_t > DwarfBaseDiscriminator)
Definition PseudoProbe.h:57