LLVM 23.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::misexpect {
26
27/// checkBackendInstrumentation - compares PGO counters to the thresholds used
28/// for llvm.expect and warns if the PGO counters are outside of the expected
29/// range. It extracts the expected weights from the MD_prof weights attached
30/// to the instruction, which are assumed to come from lowered llvm.expect
31/// intrinsics. The RealWeights parameter and the extracted expected weights are
32/// then passed to verifyMisexpect() for verification
33///
34/// \param I The Instruction being checked
35/// \param RealWeights A vector of profile weights for each target block
37 ArrayRef<uint32_t> RealWeights);
38
39/// checkFrontendInstrumentation - compares PGO counters to the thresholds used
40/// for llvm.expect and warns if the PGO counters are outside of the expected
41/// range. It extracts the expected weights from the MD_prof weights attached
42/// to the instruction, which are assumed to come from profiling data
43/// attached by the frontend prior to llvm.expect intrinsic lowering. The
44/// ExpectedWeights parameter and the extracted real weights are then passed to
45/// verifyMisexpect() for verification
46///
47/// \param I The Instruction being checked
48/// \param ExpectedWeights A vector of the expected weights for each target
49/// block, this determines the threshold values used when emitting diagnostics
51 ArrayRef<uint32_t> ExpectedWeights);
52
53/// veryifyMisExpect - compares RealWeights to the thresholds used
54/// for llvm.expect and warns if the PGO counters are outside of the expected
55/// range.
56///
57/// \param I The Instruction being checked
58/// \param RealWeights A vector of profile weights from the profile data
59/// \param ExpectedWeights A vector of the weights attatch by llvm.expect
61 ArrayRef<uint32_t> RealWeights,
62 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 ArrayRef<uint32_t> ExistingWeights,
77 bool IsFrontend);
78
79} // namespace llvm::misexpect
80
81#endif
#define LLVM_ABI
Definition Compiler.h:213
#define I(x, y, z)
Definition MD5.cpp:57
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM_ABI void checkBackendInstrumentation(const Instruction &I, ArrayRef< uint32_t > RealWeights)
checkBackendInstrumentation - compares PGO counters to the thresholds used for llvm....
LLVM_ABI void verifyMisExpect(const Instruction &I, ArrayRef< uint32_t > RealWeights, ArrayRef< uint32_t > ExpectedWeights)
veryifyMisExpect - compares RealWeights to the thresholds used for llvm.expect and warns if the PGO c...
LLVM_ABI void checkExpectAnnotations(const Instruction &I, ArrayRef< uint32_t > ExistingWeights, bool IsFrontend)
checkExpectAnnotations - compares PGO counters to the thresholds used for llvm.expect and warns if th...
LLVM_ABI void checkFrontendInstrumentation(const Instruction &I, ArrayRef< uint32_t > ExpectedWeights)
checkFrontendInstrumentation - compares PGO counters to the thresholds used for llvm....