MisExpect.h revision 360784
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 warnings for potentially incorrect usage of the
10// llvm.expect intrinsic. This utility extracts the threshold values from
11// metadata associated with the instrumented Branch or Switch instruction. The
12// threshold values are then used to determine if a warning should be emmited.
13//
14//===----------------------------------------------------------------------===//
15
16#include "llvm/ADT/SmallVector.h"
17#include "llvm/IR/Function.h"
18#include "llvm/IR/Instructions.h"
19#include "llvm/IR/LLVMContext.h"
20
21namespace llvm {
22namespace misexpect {
23
24/// verifyMisExpect - compares PGO counters to the thresholds used for
25/// llvm.expect and warns if the PGO counters are outside of the expected
26/// range.
27/// \param I The Instruction being checked
28/// \param Weights A vector of profile weights for each target block
29/// \param Ctx The current LLVM context
30void verifyMisExpect(llvm::Instruction *I,
31                     const llvm::SmallVector<uint32_t, 4> &Weights,
32                     llvm::LLVMContext &Ctx);
33
34/// checkClangInstrumentation - verify if llvm.expect matches PGO profile
35/// This function checks the frontend instrumentation in the backend when
36/// lowering llvm.expect intrinsics. It checks for existing metadata, and
37/// then validates the use of llvm.expect against the assigned branch weights.
38//
39/// \param I the Instruction being checked
40void checkFrontendInstrumentation(Instruction &I);
41
42} // namespace misexpect
43} // namespace llvm
44