ReplayInlineAdvisor.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #include "llvm/IR/LLVMContext.h"
  19. namespace llvm {
  20. class CallBase;
  21. class Function;
  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> getReplayInlineAdvisor(
  52. Module &M, FunctionAnalysisManager &FAM, LLVMContext &Context,
  53. std::unique_ptr<InlineAdvisor> OriginalAdvisor,
  54. const ReplayInlinerSettings &ReplaySettings, bool EmitRemarks);
  55. /// Replay inline advisor that uses optimization remarks from inlining of
  56. /// previous build to guide current inlining. This is useful for inliner tuning.
  57. class ReplayInlineAdvisor : public InlineAdvisor {
  58. public:
  59. ReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
  60. LLVMContext &Context,
  61. std::unique_ptr<InlineAdvisor> OriginalAdvisor,
  62. const ReplayInlinerSettings &ReplaySettings,
  63. bool EmitRemarks);
  64. std::unique_ptr<InlineAdvice> getAdviceImpl(CallBase &CB) override;
  65. bool areReplayRemarksLoaded() const { return HasReplayRemarks; }
  66. private:
  67. bool hasInlineAdvice(Function &F) const {
  68. return (ReplaySettings.ReplayScope ==
  69. ReplayInlinerSettings::Scope::Module) ||
  70. CallersToReplay.contains(F.getName());
  71. }
  72. std::unique_ptr<InlineAdvisor> OriginalAdvisor;
  73. bool HasReplayRemarks = false;
  74. const ReplayInlinerSettings ReplaySettings;
  75. bool EmitRemarks = false;
  76. StringMap<bool> InlineSitesFromRemarks;
  77. StringSet<> CallersToReplay;
  78. };
  79. } // namespace llvm
  80. #endif // LLVM_ANALYSIS_REPLAYINLINEADVISOR_H
  81. #ifdef __GNUC__
  82. #pragma GCC diagnostic pop
  83. #endif