LLVM 22.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
60void verifyMisExpect(const Instruction &I, ArrayRef<uint32_t> RealWeights,
61 ArrayRef<uint32_t> ExpectedWeights);
62
63/// checkExpectAnnotations - compares PGO counters to the thresholds used
64/// for llvm.expect and warns if the PGO counters are outside of the expected
65/// range. It extracts the expected weights from the MD_prof weights attached
66/// to the instruction, which are assumed to come from lowered llvm.expect
67/// intrinsics. The RealWeights parameter and the extracted expected weights are
68/// then passed to verifyMisexpect() for verification. It is a thin wrapper
69/// around the checkFrontendInstrumentation and checkBackendInstrumentation APIs
70///
71/// \param I The Instruction being checked
72/// \param ExistingWeights A vector of profile weights for each target block
73/// \param IsFrontend A boolean describing if this is Frontend instrumentation
75 ArrayRef<uint32_t> ExistingWeights,
76 bool IsFrontend);
77
78} // namespace llvm::misexpect
79
80#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 checkBackendInstrumentation(const Instruction &I, ArrayRef< uint32_t > RealWeights)
checkBackendInstrumentation - compares PGO counters to the thresholds used for llvm....
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...
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...
void checkFrontendInstrumentation(const Instruction &I, ArrayRef< uint32_t > ExpectedWeights)
checkFrontendInstrumentation - compares PGO counters to the thresholds used for llvm....