ReplayInlineAdvisor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ReplayInlineAdvisor.h - Replay Inline Advisor interface -*- 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. #ifndef LLVM_ANALYSIS_REPLAYINLINEADVISOR_H
  15. #define LLVM_ANALYSIS_REPLAYINLINEADVISOR_H
  16. #include "llvm/ADT/StringSet.h"
  17. #include "llvm/Analysis/InlineAdvisor.h"
  18. namespace llvm {
  19. class CallBase;
  20. class Function;
  21. class LLVMContext;
  22. class Module;
  23. struct CallSiteFormat {
  24. enum class Format : int {
  25. Line,
  26. LineColumn,
  27. LineDiscriminator,
  28. LineColumnDiscriminator
  29. };
  30. bool outputColumn() const {
  31. return OutputFormat == Format::LineColumn ||
  32. OutputFormat == Format::LineColumnDiscriminator;
  33. }
  34. bool outputDiscriminator() const {
  35. return OutputFormat == Format::LineDiscriminator ||
  36. OutputFormat == Format::LineColumnDiscriminator;
  37. }
  38. Format OutputFormat;
  39. };
  40. /// Replay Inliner Setup
  41. struct ReplayInlinerSettings {
  42. enum class Scope : int { Function, Module };
  43. enum class Fallback : int { Original, AlwaysInline, NeverInline };
  44. StringRef ReplayFile;
  45. Scope ReplayScope;
  46. Fallback ReplayFallback;
  47. CallSiteFormat ReplayFormat;
  48. };
  49. /// Get call site location as a string with the given format
  50. std::string formatCallSiteLocation(DebugLoc DLoc, const CallSiteFormat &Format);
  51. std::unique_ptr<InlineAdvisor>
  52. getReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
  53. LLVMContext &Context,
  54. std::unique_ptr<InlineAdvisor> OriginalAdvisor,
  55. const ReplayInlinerSettings &ReplaySettings,
  56. bool EmitRemarks, InlineContext IC);
  57. /// Replay inline advisor that uses optimization remarks from inlining of
  58. /// previous build to guide current inlining. This is useful for inliner tuning.
  59. class ReplayInlineAdvisor : public InlineAdvisor {
  60. public:
  61. ReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
  62. LLVMContext &Context,
  63. std::unique_ptr<InlineAdvisor> OriginalAdvisor,
  64. const ReplayInlinerSettings &ReplaySettings,
  65. bool EmitRemarks, InlineContext IC);
  66. std::unique_ptr<InlineAdvice> getAdviceImpl(CallBase &CB) override;
  67. bool areReplayRemarksLoaded() const { return HasReplayRemarks; }
  68. private:
  69. bool hasInlineAdvice(Function &F) const {
  70. return (ReplaySettings.ReplayScope ==
  71. ReplayInlinerSettings::Scope::Module) ||
  72. CallersToReplay.contains(F.getName());
  73. }
  74. std::unique_ptr<InlineAdvisor> OriginalAdvisor;
  75. bool HasReplayRemarks = false;
  76. const ReplayInlinerSettings ReplaySettings;
  77. bool EmitRemarks = false;
  78. StringMap<bool> InlineSitesFromRemarks;
  79. StringSet<> CallersToReplay;
  80. };
  81. } // namespace llvm
  82. #endif // LLVM_ANALYSIS_REPLAYINLINEADVISOR_H
  83. #ifdef __GNUC__
  84. #pragma GCC diagnostic pop
  85. #endif