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()) {
117 if (InlineSitesFromRemarks[Combined]) {
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,
135 return std::make_unique<DefaultInlineAdvice>(
141 return std::make_unique<DefaultInlineAdvice>(
this, CB, std::nullopt, ORE,
148 return OriginalAdvisor->getAdvice(CB);
FunctionAnalysisManager FAM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
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...
Function * getCaller()
Helper to get the caller (the parent function).
Interface for deciding whether to inline a call site or not.
FunctionAnalysisManager & FAM
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.
const Function * getFunction() const
Return the function this instruction belongs to.
This is an important class for using LLVM in a threaded context.
void emitError(uint64_t LocCookie, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
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
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
std::pair< typename Base::iterator, bool > insert(StringRef key)
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.
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.
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,...
CallSiteFormat ReplayFormat