PGOOptions.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===------ PGOOptions.h -- PGO option tunables ----------------*- 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. /// \file
  14. ///
  15. /// Define option tunables for PGO.
  16. ///
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_SUPPORT_PGOOPTIONS_H
  19. #define LLVM_SUPPORT_PGOOPTIONS_H
  20. #include "llvm/Support/Error.h"
  21. namespace llvm {
  22. /// A struct capturing PGO tunables.
  23. struct PGOOptions {
  24. enum PGOAction { NoAction, IRInstr, IRUse, SampleUse };
  25. enum CSPGOAction { NoCSAction, CSIRInstr, CSIRUse };
  26. PGOOptions(std::string ProfileFile = "", std::string CSProfileGenFile = "",
  27. std::string ProfileRemappingFile = "", PGOAction Action = NoAction,
  28. CSPGOAction CSAction = NoCSAction,
  29. bool DebugInfoForProfiling = false,
  30. bool PseudoProbeForProfiling = false)
  31. : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
  32. ProfileRemappingFile(ProfileRemappingFile), Action(Action),
  33. CSAction(CSAction), DebugInfoForProfiling(DebugInfoForProfiling ||
  34. (Action == SampleUse &&
  35. !PseudoProbeForProfiling)),
  36. PseudoProbeForProfiling(PseudoProbeForProfiling) {
  37. // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
  38. // callback with IRUse action without ProfileFile.
  39. // If there is a CSAction, PGOAction cannot be IRInstr or SampleUse.
  40. assert(this->CSAction == NoCSAction ||
  41. (this->Action != IRInstr && this->Action != SampleUse));
  42. // For CSIRInstr, CSProfileGenFile also needs to be nonempty.
  43. assert(this->CSAction != CSIRInstr || !this->CSProfileGenFile.empty());
  44. // If CSAction is CSIRUse, PGOAction needs to be IRUse as they share
  45. // a profile.
  46. assert(this->CSAction != CSIRUse || this->Action == IRUse);
  47. // If neither Action nor CSAction, DebugInfoForProfiling or
  48. // PseudoProbeForProfiling needs to be true.
  49. assert(this->Action != NoAction || this->CSAction != NoCSAction ||
  50. this->DebugInfoForProfiling || this->PseudoProbeForProfiling);
  51. }
  52. std::string ProfileFile;
  53. std::string CSProfileGenFile;
  54. std::string ProfileRemappingFile;
  55. PGOAction Action;
  56. CSPGOAction CSAction;
  57. bool DebugInfoForProfiling;
  58. bool PseudoProbeForProfiling;
  59. };
  60. } // namespace llvm
  61. #endif
  62. #ifdef __GNUC__
  63. #pragma GCC diagnostic pop
  64. #endif