LLVM 19.0.0git
MisExpect.h
Go to the documentation of this file.
1//===--- MisExpect.h - Check the use of llvm.expect with PGO data ---------===//
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 contains code to emit diagnostic messages for potentially incorrect
10// usage of the llvm.expect intrinsic. This utility extracts the threshold
11// values from metadata associated with the instrumented Branch or Switch
12// instruction. The threshold values are then used to determine if a diagnostic
13// should be emitted.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_TRANSFORMS_UTILS_MISEXPECT_H
18#define LLVM_TRANSFORMS_UTILS_MISEXPECT_H
19
21#include "llvm/IR/Function.h"
23#include "llvm/IR/LLVMContext.h"
24
25namespace llvm {
26namespace misexpect {
27
28/// checkBackendInstrumentation - compares PGO counters to the thresholds used
29/// for llvm.expect and warns if the PGO counters are outside of the expected
30/// range. It extracts the expected weights from the MD_prof weights attached
31/// to the instruction, which are assumed to come from lowered llvm.expect
32/// intrinsics. The RealWeights parameter and the extracted expected weights are
33/// then passed to verifyMisexpect() for verification
34///
35/// \param I The Instruction being checked
36/// \param RealWeights A vector of profile weights for each target block
38 const llvm::ArrayRef<uint32_t> RealWeights);
39
40/// checkFrontendInstrumentation - compares PGO counters to the thresholds used
41/// for llvm.expect and warns if the PGO counters are outside of the expected
42/// range. It extracts the expected weights from the MD_prof weights attached
43/// to the instruction, which are assumed to come from profiling data
44/// attached by the frontend prior to llvm.expect intrinsic lowering. The
45/// ExpectedWeights parameter and the extracted real weights are then passed to
46/// verifyMisexpect() for verification
47///
48/// \param I The Instruction being checked
49/// \param ExpectedWeights A vector of the expected weights for each target
50/// block, this determines the threshold values used when emitting diagnostics
52 const ArrayRef<uint32_t> ExpectedWeights);
53
54/// veryifyMisExpect - compares RealWeights to the thresholds used
55/// for llvm.expect and warns if the PGO counters are outside of the expected
56/// range.
57///
58/// \param I The Instruction being checked
59/// \param RealWeights A vector of profile weights from the profile data
60/// \param ExpectedWeights A vector of the weights attatch by llvm.expect
62 const ArrayRef<uint32_t> ExpectedWeights);
63
64/// checkExpectAnnotations - compares PGO counters to the thresholds used
65/// for llvm.expect and warns if the PGO counters are outside of the expected
66/// range. It extracts the expected weights from the MD_prof weights attached
67/// to the instruction, which are assumed to come from lowered llvm.expect
68/// intrinsics. The RealWeights parameter and the extracted expected weights are
69/// then passed to verifyMisexpect() for verification. It is a thin wrapper
70/// around the checkFrontendInstrumentation and checkBackendInstrumentation APIs
71///
72/// \param I The Instruction being checked
73/// \param ExistingWeights A vector of profile weights for each target block
74/// \param IsFrontend A boolean describing if this is Frontend instrumentation
76 const ArrayRef<uint32_t> ExistingWeights,
77 bool IsFrontend);
78
79} // namespace misexpect
80} // namespace llvm
81
82#endif
#define I(x, y, z)
Definition: MD5.cpp:58
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
void checkFrontendInstrumentation(Instruction &I, const ArrayRef< uint32_t > ExpectedWeights)
checkFrontendInstrumentation - compares PGO counters to the thresholds used for llvm....
Definition: MisExpect.cpp:194
void checkExpectAnnotations(Instruction &I, const ArrayRef< uint32_t > ExistingWeights, bool IsFrontend)
checkExpectAnnotations - compares PGO counters to the thresholds used for llvm.expect and warns if th...
Definition: MisExpect.cpp:202
void checkBackendInstrumentation(Instruction &I, const llvm::ArrayRef< uint32_t > RealWeights)
checkBackendInstrumentation - compares PGO counters to the thresholds used for llvm....
Definition: MisExpect.cpp:186
void verifyMisExpect(Instruction &I, ArrayRef< uint32_t > RealWeights, const ArrayRef< uint32_t > ExpectedWeights)
veryifyMisExpect - compares RealWeights to the thresholds used for llvm.expect and warns if the PGO c...
Definition: MisExpect.cpp:123
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18