LLVM  15.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 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Instructions.h"
20 #include "llvm/IR/LLVMContext.h"
21 
22 namespace llvm {
23 namespace misexpect {
24 
25 /// checkBackendInstrumentation - compares PGO counters to the thresholds used
26 /// for llvm.expect and warns if the PGO counters are outside of the expected
27 /// range. It extracts the expected weights from the MD_prof weights attatched
28 /// to the instruction, which are are assumed to come from lowered llvm.expect
29 /// intrinsics. The RealWeights parameter and the extracted expected weights are
30 /// then passed to verifyMisexpect() for verification
31 ///
32 /// \param I The Instruction being checked
33 /// \param RealWeights A vector of profile weights for each target block
35  const llvm::ArrayRef<uint32_t> RealWeights);
36 
37 /// checkFrontendInstrumentation - compares PGO counters to the thresholds used
38 /// for llvm.expect and warns if the PGO counters are outside of the expected
39 /// range. It extracts the expected weights from the MD_prof weights attatched
40 /// to the instruction, which are are assumed to come from profiling data
41 /// attached by the frontend prior to llvm.expect intrinsic lowering. The
42 /// ExpectedWeights parameter and the extracted real weights are then passed to
43 /// verifyMisexpect() for verification
44 ///
45 /// \param I The Instruction being checked
46 /// \param ExpectedWeights A vector of the expected weights for each target
47 /// block, this determines the threshold values used when emiting diagnostics
49  const ArrayRef<uint32_t> ExpectedWeights);
50 
51 /// veryifyMisExpect - compares RealWeights to the thresholds used
52 /// for llvm.expect and warns if the PGO counters are outside of the expected
53 /// range.
54 ///
55 /// \param I The Instruction being checked
56 /// \param RealWeights A vector of profile weights from the profile data
57 /// \param ExpectedWeights A vector of the weights attatch by llvm.expect
59  const ArrayRef<uint32_t> ExpectedWeights);
60 
61 /// checkExpectAnnotations - compares PGO counters to the thresholds used
62 /// for llvm.expect and warns if the PGO counters are outside of the expected
63 /// range. It extracts the expected weights from the MD_prof weights attatched
64 /// to the instruction, which are are assumed to come from lowered llvm.expect
65 /// intrinsics. The RealWeights parameter and the extracted expected weights are
66 /// then passed to verifyMisexpect() for verification. It is a thin wrapper
67 /// around the checkFrontendInstrumentation and checkBackendInstrumentation APIs
68 ///
69 /// \param I The Instruction being checked
70 /// \param RealWeights A vector of profile weights for each target block
71 /// \param IsBackend A boolean describing if this is Frontend instrumentation
73  const ArrayRef<uint32_t> ExistingWeights,
74  bool IsFrontend);
75 
76 } // namespace misexpect
77 } // namespace llvm
llvm::misexpect::checkFrontendInstrumentation
void checkFrontendInstrumentation(Instruction &I, const ArrayRef< uint32_t > ExpectedWeights)
checkFrontendInstrumentation - compares PGO counters to the thresholds used for llvm....
Definition: MisExpect.cpp:228
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::Instruction
Definition: Instruction.h:42
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::misexpect::checkExpectAnnotations
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:237
llvm::misexpect::checkBackendInstrumentation
void checkBackendInstrumentation(Instruction &I, const llvm::ArrayRef< uint32_t > RealWeights)
checkBackendInstrumentation - compares PGO counters to the thresholds used for llvm....
Definition: MisExpect.cpp:219
llvm::ArrayRef< uint32_t >
llvm::misexpect::verifyMisExpect
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:158
Function.h
Instructions.h
SmallVector.h
LLVMContext.h