1 //===--- MisExpect.h - Check the use of llvm.expect with PGO data ---------===//
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
7 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/Instructions.h"
19 #include "llvm/IR/LLVMContext.h"
24 /// verifyMisExpect - compares PGO counters to the thresholds used for
25 /// llvm.expect and warns if the PGO counters are outside of the expected
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
30 void verifyMisExpect(llvm::Instruction
*I
,
31 const llvm::SmallVector
<uint32_t, 4> &Weights
,
32 llvm::LLVMContext
&Ctx
);
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.
39 /// \param I the Instruction being checked
40 void checkFrontendInstrumentation(Instruction
&I
);
42 } // namespace misexpect