MisExpect.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- MisExpect.h - Check the use of llvm.expect with PGO data ---------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This contains code to emit diagnostic messages for potentially incorrect
  15. // usage of the llvm.expect intrinsic. This utility extracts the threshold
  16. // values from metadata associated with the instrumented Branch or Switch
  17. // instruction. The threshold values are then used to determine if a diagnostic
  18. // should be emitted.
  19. //
  20. //===----------------------------------------------------------------------===//
  21. #ifndef LLVM_TRANSFORMS_UTILS_MISEXPECT_H
  22. #define LLVM_TRANSFORMS_UTILS_MISEXPECT_H
  23. #include "llvm/ADT/SmallVector.h"
  24. #include "llvm/IR/Function.h"
  25. #include "llvm/IR/Instructions.h"
  26. #include "llvm/IR/LLVMContext.h"
  27. namespace llvm {
  28. namespace misexpect {
  29. /// checkBackendInstrumentation - compares PGO counters to the thresholds used
  30. /// for llvm.expect and warns if the PGO counters are outside of the expected
  31. /// range. It extracts the expected weights from the MD_prof weights attatched
  32. /// to the instruction, which are are assumed to come from lowered llvm.expect
  33. /// intrinsics. The RealWeights parameter and the extracted expected weights are
  34. /// then passed to verifyMisexpect() for verification
  35. ///
  36. /// \param I The Instruction being checked
  37. /// \param RealWeights A vector of profile weights for each target block
  38. void checkBackendInstrumentation(Instruction &I,
  39. const llvm::ArrayRef<uint32_t> RealWeights);
  40. /// checkFrontendInstrumentation - compares PGO counters to the thresholds used
  41. /// for llvm.expect and warns if the PGO counters are outside of the expected
  42. /// range. It extracts the expected weights from the MD_prof weights attatched
  43. /// to the instruction, which are are assumed to come from profiling data
  44. /// attached by the frontend prior to llvm.expect intrinsic lowering. The
  45. /// ExpectedWeights parameter and the extracted real weights are then passed to
  46. /// verifyMisexpect() for verification
  47. ///
  48. /// \param I The Instruction being checked
  49. /// \param ExpectedWeights A vector of the expected weights for each target
  50. /// block, this determines the threshold values used when emiting diagnostics
  51. void checkFrontendInstrumentation(Instruction &I,
  52. const ArrayRef<uint32_t> ExpectedWeights);
  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
  60. void verifyMisExpect(Instruction &I, ArrayRef<uint32_t> RealWeights,
  61. const ArrayRef<uint32_t> ExpectedWeights);
  62. /// checkExpectAnnotations - compares PGO counters to the thresholds used
  63. /// for llvm.expect and warns if the PGO counters are outside of the expected
  64. /// range. It extracts the expected weights from the MD_prof weights attatched
  65. /// to the instruction, which are are assumed to come from lowered llvm.expect
  66. /// intrinsics. The RealWeights parameter and the extracted expected weights are
  67. /// then passed to verifyMisexpect() for verification. It is a thin wrapper
  68. /// around the checkFrontendInstrumentation and checkBackendInstrumentation APIs
  69. ///
  70. /// \param I The Instruction being checked
  71. /// \param ExistingWeights A vector of profile weights for each target block
  72. /// \param IsFrontend A boolean describing if this is Frontend instrumentation
  73. void checkExpectAnnotations(Instruction &I,
  74. const ArrayRef<uint32_t> ExistingWeights,
  75. bool IsFrontend);
  76. } // namespace misexpect
  77. } // namespace llvm
  78. #endif
  79. #ifdef __GNUC__
  80. #pragma GCC diagnostic pop
  81. #endif