Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / include / llvm / Analysis / ReplayInlineAdvisor.h
blob6f6ce763746a16ce2e3343f3f6e1b617e8c2f562
1 //===- ReplayInlineAdvisor.h - Replay Inline Advisor interface -*- C++ --*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 #ifndef LLVM_ANALYSIS_REPLAYINLINEADVISOR_H
10 #define LLVM_ANALYSIS_REPLAYINLINEADVISOR_H
12 #include "llvm/ADT/StringSet.h"
13 #include "llvm/Analysis/InlineAdvisor.h"
15 namespace llvm {
16 class CallBase;
17 class LLVMContext;
18 class Module;
20 struct CallSiteFormat {
21 enum class Format : int {
22 Line,
23 LineColumn,
24 LineDiscriminator,
25 LineColumnDiscriminator
28 bool outputColumn() const {
29 return OutputFormat == Format::LineColumn ||
30 OutputFormat == Format::LineColumnDiscriminator;
33 bool outputDiscriminator() const {
34 return OutputFormat == Format::LineDiscriminator ||
35 OutputFormat == Format::LineColumnDiscriminator;
38 Format OutputFormat;
41 /// Replay Inliner Setup
42 struct ReplayInlinerSettings {
43 enum class Scope : int { Function, Module };
44 enum class Fallback : int { Original, AlwaysInline, NeverInline };
46 StringRef ReplayFile;
47 Scope ReplayScope;
48 Fallback ReplayFallback;
49 CallSiteFormat ReplayFormat;
52 /// Get call site location as a string with the given format
53 std::string formatCallSiteLocation(DebugLoc DLoc, const CallSiteFormat &Format);
55 std::unique_ptr<InlineAdvisor>
56 getReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
57 LLVMContext &Context,
58 std::unique_ptr<InlineAdvisor> OriginalAdvisor,
59 const ReplayInlinerSettings &ReplaySettings,
60 bool EmitRemarks, InlineContext IC);
62 /// Replay inline advisor that uses optimization remarks from inlining of
63 /// previous build to guide current inlining. This is useful for inliner tuning.
64 class ReplayInlineAdvisor : public InlineAdvisor {
65 public:
66 ReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
67 LLVMContext &Context,
68 std::unique_ptr<InlineAdvisor> OriginalAdvisor,
69 const ReplayInlinerSettings &ReplaySettings,
70 bool EmitRemarks, InlineContext IC);
71 std::unique_ptr<InlineAdvice> getAdviceImpl(CallBase &CB) override;
72 bool areReplayRemarksLoaded() const { return HasReplayRemarks; }
74 private:
75 bool hasInlineAdvice(Function &F) const {
76 return (ReplaySettings.ReplayScope ==
77 ReplayInlinerSettings::Scope::Module) ||
78 CallersToReplay.contains(F.getName());
80 std::unique_ptr<InlineAdvisor> OriginalAdvisor;
81 bool HasReplayRemarks = false;
82 const ReplayInlinerSettings ReplaySettings;
83 bool EmitRemarks = false;
85 StringMap<bool> InlineSitesFromRemarks;
86 StringSet<> CallersToReplay;
88 } // namespace llvm
89 #endif // LLVM_ANALYSIS_REPLAYINLINEADVISOR_H