24#define DEBUG_TYPE "replay-inline"
28 std::unique_ptr<InlineAdvisor> OriginalAdvisor,
32 ReplaySettings(ReplaySettings), EmitRemarks(EmitRemarks) {
35 std::error_code EC = BufferOrErr.getError();
37 Context.emitError(
"Could not open remarks file: " + EC.message());
46 const std::string PositiveRemark =
"' inlined into '";
47 const std::string NegativeRemark =
"' will not be inlined into '";
51 auto Pair = Line.split(
" at callsite ");
53 bool IsPositiveRemark =
true;
54 if (Pair.first.contains(NegativeRemark))
55 IsPositiveRemark =
false;
58 Pair.first.split(IsPositiveRemark ? PositiveRemark : NegativeRemark);
60 StringRef Callee = CalleeCaller.first.rsplit(
": '").second;
61 StringRef Caller = CalleeCaller.second.rsplit(
"'").first;
63 auto CallSite = Pair.second.split(
";").first;
65 if (Callee.empty() || Caller.empty() || CallSite.empty()) {
66 Context.emitError(
"Invalid remark format: " + Line);
70 std::string Combined = (Callee + CallSite).str();
71 InlineSitesFromRemarks[Combined] = IsPositiveRemark;
73 CallersToReplay.insert(Caller);
76 HasReplayRemarks =
true;
79std::unique_ptr<InlineAdvisor>
82 std::unique_ptr<InlineAdvisor> OriginalAdvisor,
85 auto Advisor = std::make_unique<ReplayInlineAdvisor>(
86 M,
FAM, Context, std::move(OriginalAdvisor), ReplaySettings, EmitRemarks,
88 if (!Advisor->areReplayRemarksLoaded())
103 return OriginalAdvisor->getAdvice(CB);
109 std::string CallSiteLoc =
112 std::string Combined = (Callee + CallSiteLoc).str();
115 auto Iter = InlineSitesFromRemarks.
find(Combined);
116 if (Iter != InlineSitesFromRemarks.end()) {
118 LLVM_DEBUG(
dbgs() <<
"Replay Inliner: Inlined " << Callee <<
" @ "
119 << CallSiteLoc <<
"\n");
120 return std::make_unique<DefaultInlineAdvice>(
124 LLVM_DEBUG(
dbgs() <<
"Replay Inliner: Not Inlined " << Callee <<
" @ "
125 << CallSiteLoc <<
"\n");
127 return std::make_unique<DefaultInlineAdvice>(
this, CB, std::nullopt, ORE,
133 if (ReplaySettings.ReplayFallback ==
135 return std::make_unique<DefaultInlineAdvice>(
138 else if (ReplaySettings.ReplayFallback ==
141 return std::make_unique<DefaultInlineAdvice>(
this, CB, std::nullopt, ORE,
144 assert(ReplaySettings.ReplayFallback ==
148 return OriginalAdvisor->getAdvice(CB);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
FunctionAnalysisManager FAM
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
LLVM_ABI Function * getCaller()
Helper to get the caller (the parent function).
const std::optional< InlineContext > IC
FunctionAnalysisManager & FAM
InlineAdvisor(InlineAdvisor &&)=delete
static InlineCost getAlways(const char *Reason, std::optional< CostBenefitPair > CostBenefit=std::nullopt)
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
This is an important class for using LLVM in a threaded context.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
A Module instance is used to store all the information related to an LLVM module.
ReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM, LLVMContext &Context, std::unique_ptr< InlineAdvisor > OriginalAdvisor, const ReplayInlinerSettings &ReplaySettings, bool EmitRemarks, InlineContext IC)
std::unique_ptr< InlineAdvice > getAdviceImpl(CallBase &CB) override
StringRef - Represent a constant reference to a string, i.e.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
A forward iterator which reads text lines from a buffer.
bool is_at_eof() const
Return true if we've reached EOF or are an "end" iterator.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::unique_ptr< InlineAdvisor > getReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM, LLVMContext &Context, std::unique_ptr< InlineAdvisor > OriginalAdvisor, const ReplayInlinerSettings &ReplaySettings, bool EmitRemarks, InlineContext IC)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
std::string formatCallSiteLocation(DebugLoc DLoc, const CallSiteFormat &Format)
Get call site location as a string with the given format.
Implement std::hash so that hash_code can be used in STL containers.
Provides context on when an inline advisor is constructed in the pipeline (e.g., link phase,...