PGOInstrumentation.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- Transforms/Instrumentation/PGOInstrumentation.h ----------*- C++ -*-===//
  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. /// \file
  15. /// This file provides the interface for IR based instrumentation passes (
  16. /// (profile-gen, and profile-use).
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_PGOINSTRUMENTATION_H
  20. #define LLVM_TRANSFORMS_INSTRUMENTATION_PGOINSTRUMENTATION_H
  21. #include "llvm/ADT/ArrayRef.h"
  22. #include "llvm/IR/PassManager.h"
  23. #include <cstdint>
  24. #include <string>
  25. namespace llvm {
  26. class Function;
  27. class Instruction;
  28. class Module;
  29. /// The instrumentation (profile-instr-gen) pass for IR based PGO.
  30. // We use this pass to create COMDAT profile variables for context
  31. // sensitive PGO (CSPGO). The reason to have a pass for this is CSPGO
  32. // can be run after LTO/ThinLTO linking. Lld linker needs to see
  33. // all the COMDAT variables before linking. So we have this pass
  34. // always run before linking for CSPGO.
  35. class PGOInstrumentationGenCreateVar
  36. : public PassInfoMixin<PGOInstrumentationGenCreateVar> {
  37. public:
  38. PGOInstrumentationGenCreateVar(std::string CSInstrName = "")
  39. : CSInstrName(CSInstrName) {}
  40. PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
  41. private:
  42. std::string CSInstrName;
  43. };
  44. /// The instrumentation (profile-instr-gen) pass for IR based PGO.
  45. class PGOInstrumentationGen : public PassInfoMixin<PGOInstrumentationGen> {
  46. public:
  47. PGOInstrumentationGen(bool IsCS = false) : IsCS(IsCS) {}
  48. PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
  49. private:
  50. // If this is a context sensitive instrumentation.
  51. bool IsCS;
  52. };
  53. /// The profile annotation (profile-instr-use) pass for IR based PGO.
  54. class PGOInstrumentationUse : public PassInfoMixin<PGOInstrumentationUse> {
  55. public:
  56. PGOInstrumentationUse(std::string Filename = "",
  57. std::string RemappingFilename = "", bool IsCS = false);
  58. PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
  59. private:
  60. std::string ProfileFileName;
  61. std::string ProfileRemappingFileName;
  62. // If this is a context sensitive instrumentation.
  63. bool IsCS;
  64. };
  65. /// The indirect function call promotion pass.
  66. class PGOIndirectCallPromotion : public PassInfoMixin<PGOIndirectCallPromotion> {
  67. public:
  68. PGOIndirectCallPromotion(bool IsInLTO = false, bool SamplePGO = false)
  69. : InLTO(IsInLTO), SamplePGO(SamplePGO) {}
  70. PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
  71. private:
  72. bool InLTO;
  73. bool SamplePGO;
  74. };
  75. /// The profile size based optimization pass for memory intrinsics.
  76. class PGOMemOPSizeOpt : public PassInfoMixin<PGOMemOPSizeOpt> {
  77. public:
  78. PGOMemOPSizeOpt() = default;
  79. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  80. };
  81. void setProfMetadata(Module *M, Instruction *TI, ArrayRef<uint64_t> EdgeCounts,
  82. uint64_t MaxCount);
  83. void setIrrLoopHeaderMetadata(Module *M, Instruction *TI, uint64_t Count);
  84. } // end namespace llvm
  85. #endif // LLVM_TRANSFORMS_INSTRUMENTATION_PGOINSTRUMENTATION_H
  86. #ifdef __GNUC__
  87. #pragma GCC diagnostic pop
  88. #endif