MisExpect.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include "llvm/ADT/SmallVector.h"
  16. #include "llvm/IR/Function.h"
  17. #include "llvm/IR/Instructions.h"
  18. #include "llvm/IR/LLVMContext.h"
  19. namespace llvm {
  20. namespace misexpect {
  21. /// verifyMisExpect - compares PGO counters to the thresholds used for
  22. /// llvm.expect and warns if the PGO counters are outside of the expected
  23. /// range.
  24. /// \param I The Instruction being checked
  25. /// \param Weights A vector of profile weights for each target block
  26. /// \param Ctx The current LLVM context
  27. void verifyMisExpect(llvm::Instruction *I,
  28. const llvm::SmallVector<uint32_t, 4> &Weights,
  29. llvm::LLVMContext &Ctx);
  30. /// checkClangInstrumentation - verify if llvm.expect matches PGO profile
  31. /// This function checks the frontend instrumentation in the backend when
  32. /// lowering llvm.expect intrinsics. It checks for existing metadata, and
  33. /// then validates the use of llvm.expect against the assigned branch weights.
  34. //
  35. /// \param I the Instruction being checked
  36. void checkFrontendInstrumentation(Instruction &I);
  37. } // namespace misexpect
  38. } // namespace llvm