aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm14/include/llvm/Analysis/ReplayInlineAdvisor.h
blob: 80409ad51e7029d78e2ecf6be5f41f0252b0336f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif

//===- ReplayInlineAdvisor.h - Replay Inline Advisor interface -*- C++ --*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
#ifndef LLVM_ANALYSIS_REPLAYINLINEADVISOR_H
#define LLVM_ANALYSIS_REPLAYINLINEADVISOR_H

#include "llvm/ADT/StringSet.h"
#include "llvm/Analysis/InlineAdvisor.h"
#include "llvm/IR/LLVMContext.h"

namespace llvm {
class CallBase;
class Function;
class Module;

struct CallSiteFormat {
  enum class Format : int {
    Line,
    LineColumn,
    LineDiscriminator,
    LineColumnDiscriminator
  };

  bool outputColumn() const {
    return OutputFormat == Format::LineColumn ||
           OutputFormat == Format::LineColumnDiscriminator;
  }

  bool outputDiscriminator() const {
    return OutputFormat == Format::LineDiscriminator ||
           OutputFormat == Format::LineColumnDiscriminator;
  }

  Format OutputFormat;
};

/// Replay Inliner Setup
struct ReplayInlinerSettings {
  enum class Scope : int { Function, Module };
  enum class Fallback : int { Original, AlwaysInline, NeverInline };

  StringRef ReplayFile;
  Scope ReplayScope;
  Fallback ReplayFallback;
  CallSiteFormat ReplayFormat;
};

/// Get call site location as a string with the given format
std::string formatCallSiteLocation(DebugLoc DLoc, const CallSiteFormat &Format);

std::unique_ptr<InlineAdvisor> getReplayInlineAdvisor(
    Module &M, FunctionAnalysisManager &FAM, LLVMContext &Context,
    std::unique_ptr<InlineAdvisor> OriginalAdvisor,
    const ReplayInlinerSettings &ReplaySettings, bool EmitRemarks);

/// Replay inline advisor that uses optimization remarks from inlining of
/// previous build to guide current inlining. This is useful for inliner tuning.
class ReplayInlineAdvisor : public InlineAdvisor {
public:
  ReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
                      LLVMContext &Context,
                      std::unique_ptr<InlineAdvisor> OriginalAdvisor,
                      const ReplayInlinerSettings &ReplaySettings,
                      bool EmitRemarks);
  std::unique_ptr<InlineAdvice> getAdviceImpl(CallBase &CB) override;
  bool areReplayRemarksLoaded() const { return HasReplayRemarks; }

private:
  bool hasInlineAdvice(Function &F) const {
    return (ReplaySettings.ReplayScope ==
            ReplayInlinerSettings::Scope::Module) ||
           CallersToReplay.contains(F.getName());
  }
  std::unique_ptr<InlineAdvisor> OriginalAdvisor;
  bool HasReplayRemarks = false;
  const ReplayInlinerSettings ReplaySettings;
  bool EmitRemarks = false;

  StringMap<bool> InlineSitesFromRemarks;
  StringSet<> CallersToReplay;
};
} // namespace llvm
#endif // LLVM_ANALYSIS_REPLAYINLINEADVISOR_H

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif