Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:16

0001 //===- ReplayInlineAdvisor.h - Replay Inline Advisor interface -*- C++ --*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 #ifndef LLVM_ANALYSIS_REPLAYINLINEADVISOR_H
0010 #define LLVM_ANALYSIS_REPLAYINLINEADVISOR_H
0011 
0012 #include "llvm/ADT/StringSet.h"
0013 #include "llvm/Analysis/InlineAdvisor.h"
0014 
0015 namespace llvm {
0016 class CallBase;
0017 class LLVMContext;
0018 class Module;
0019 
0020 struct CallSiteFormat {
0021   enum class Format : int {
0022     Line,
0023     LineColumn,
0024     LineDiscriminator,
0025     LineColumnDiscriminator
0026   };
0027 
0028   bool outputColumn() const {
0029     return OutputFormat == Format::LineColumn ||
0030            OutputFormat == Format::LineColumnDiscriminator;
0031   }
0032 
0033   bool outputDiscriminator() const {
0034     return OutputFormat == Format::LineDiscriminator ||
0035            OutputFormat == Format::LineColumnDiscriminator;
0036   }
0037 
0038   Format OutputFormat;
0039 };
0040 
0041 /// Replay Inliner Setup
0042 struct ReplayInlinerSettings {
0043   enum class Scope : int { Function, Module };
0044   enum class Fallback : int { Original, AlwaysInline, NeverInline };
0045 
0046   StringRef ReplayFile;
0047   Scope ReplayScope;
0048   Fallback ReplayFallback;
0049   CallSiteFormat ReplayFormat;
0050 };
0051 
0052 /// Get call site location as a string with the given format
0053 std::string formatCallSiteLocation(DebugLoc DLoc, const CallSiteFormat &Format);
0054 
0055 std::unique_ptr<InlineAdvisor>
0056 getReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
0057                        LLVMContext &Context,
0058                        std::unique_ptr<InlineAdvisor> OriginalAdvisor,
0059                        const ReplayInlinerSettings &ReplaySettings,
0060                        bool EmitRemarks, InlineContext IC);
0061 
0062 /// Replay inline advisor that uses optimization remarks from inlining of
0063 /// previous build to guide current inlining. This is useful for inliner tuning.
0064 class ReplayInlineAdvisor : public InlineAdvisor {
0065 public:
0066   ReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
0067                       LLVMContext &Context,
0068                       std::unique_ptr<InlineAdvisor> OriginalAdvisor,
0069                       const ReplayInlinerSettings &ReplaySettings,
0070                       bool EmitRemarks, InlineContext IC);
0071   std::unique_ptr<InlineAdvice> getAdviceImpl(CallBase &CB) override;
0072   bool areReplayRemarksLoaded() const { return HasReplayRemarks; }
0073 
0074 private:
0075   bool hasInlineAdvice(Function &F) const {
0076     return (ReplaySettings.ReplayScope ==
0077             ReplayInlinerSettings::Scope::Module) ||
0078            CallersToReplay.contains(F.getName());
0079   }
0080   std::unique_ptr<InlineAdvisor> OriginalAdvisor;
0081   bool HasReplayRemarks = false;
0082   const ReplayInlinerSettings ReplaySettings;
0083   bool EmitRemarks = false;
0084 
0085   StringMap<bool> InlineSitesFromRemarks;
0086   StringSet<> CallersToReplay;
0087 };
0088 } // namespace llvm
0089 #endif // LLVM_ANALYSIS_REPLAYINLINEADVISOR_H