xref: /freebsd-src/contrib/llvm-project/llvm/lib/Analysis/InlineAdvisor.cpp (revision 0eae32dcef82f6f06de6419a0d623d7def0cc8f6)
1 //===- InlineAdvisor.cpp - analysis pass implementation -------------------===//
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 // This file implements InlineAdvisorAnalysis and DefaultInlineAdvisor, and
10 // related types.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/Analysis/InlineAdvisor.h"
15 #include "llvm/ADT/Statistic.h"
16 #include "llvm/Analysis/InlineCost.h"
17 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
18 #include "llvm/Analysis/ProfileSummaryInfo.h"
19 #include "llvm/Analysis/ReplayInlineAdvisor.h"
20 #include "llvm/Analysis/TargetLibraryInfo.h"
21 #include "llvm/Analysis/TargetTransformInfo.h"
22 #include "llvm/IR/DebugInfoMetadata.h"
23 #include "llvm/IR/Instructions.h"
24 #include "llvm/Support/CommandLine.h"
25 #include "llvm/Support/raw_ostream.h"
26 
27 using namespace llvm;
28 #define DEBUG_TYPE "inline"
29 
30 // This weirdly named statistic tracks the number of times that, when attempting
31 // to inline a function A into B, we analyze the callers of B in order to see
32 // if those would be more profitable and blocked inline steps.
33 STATISTIC(NumCallerCallersAnalyzed, "Number of caller-callers analyzed");
34 
35 /// Flag to add inline messages as callsite attributes 'inline-remark'.
36 static cl::opt<bool>
37     InlineRemarkAttribute("inline-remark-attribute", cl::init(false),
38                           cl::Hidden,
39                           cl::desc("Enable adding inline-remark attribute to"
40                                    " callsites processed by inliner but decided"
41                                    " to be not inlined"));
42 
43 static cl::opt<bool> EnableInlineDeferral("inline-deferral", cl::init(false),
44                                           cl::Hidden,
45                                           cl::desc("Enable deferred inlining"));
46 
47 // An integer used to limit the cost of inline deferral.  The default negative
48 // number tells shouldBeDeferred to only take the secondary cost into account.
49 static cl::opt<int>
50     InlineDeferralScale("inline-deferral-scale",
51                         cl::desc("Scale to limit the cost of inline deferral"),
52                         cl::init(2), cl::Hidden);
53 
54 extern cl::opt<InlinerFunctionImportStatsOpts> InlinerFunctionImportStats;
55 
56 namespace {
57 using namespace llvm::ore;
58 class MandatoryInlineAdvice : public InlineAdvice {
59 public:
60   MandatoryInlineAdvice(InlineAdvisor *Advisor, CallBase &CB,
61                         OptimizationRemarkEmitter &ORE,
62                         bool IsInliningMandatory)
63       : InlineAdvice(Advisor, CB, ORE, IsInliningMandatory) {}
64 
65 private:
66   void recordInliningWithCalleeDeletedImpl() override { recordInliningImpl(); }
67 
68   void recordInliningImpl() override {
69     if (IsInliningRecommended)
70       emitInlinedInto(ORE, DLoc, Block, *Callee, *Caller, IsInliningRecommended,
71                       [&](OptimizationRemark &Remark) {
72                         Remark << ": always inline attribute";
73                       });
74   }
75 
76   void recordUnsuccessfulInliningImpl(const InlineResult &Result) override {
77     if (IsInliningRecommended)
78       ORE.emit([&]() {
79         return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
80                << "'" << NV("Callee", Callee) << "' is not AlwaysInline into '"
81                << NV("Caller", Caller)
82                << "': " << NV("Reason", Result.getFailureReason());
83       });
84   }
85 
86   void recordUnattemptedInliningImpl() override {
87     assert(!IsInliningRecommended && "Expected to attempt inlining");
88   }
89 };
90 } // namespace
91 
92 void DefaultInlineAdvice::recordUnsuccessfulInliningImpl(
93     const InlineResult &Result) {
94   using namespace ore;
95   llvm::setInlineRemark(*OriginalCB, std::string(Result.getFailureReason()) +
96                                          "; " + inlineCostStr(*OIC));
97   ORE.emit([&]() {
98     return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
99            << "'" << NV("Callee", Callee) << "' is not inlined into '"
100            << NV("Caller", Caller)
101            << "': " << NV("Reason", Result.getFailureReason());
102   });
103 }
104 
105 void DefaultInlineAdvice::recordInliningWithCalleeDeletedImpl() {
106   if (EmitRemarks)
107     emitInlinedIntoBasedOnCost(ORE, DLoc, Block, *Callee, *Caller, *OIC);
108 }
109 
110 void DefaultInlineAdvice::recordInliningImpl() {
111   if (EmitRemarks)
112     emitInlinedIntoBasedOnCost(ORE, DLoc, Block, *Callee, *Caller, *OIC);
113 }
114 
115 llvm::Optional<llvm::InlineCost> static getDefaultInlineAdvice(
116     CallBase &CB, FunctionAnalysisManager &FAM, const InlineParams &Params) {
117   Function &Caller = *CB.getCaller();
118   ProfileSummaryInfo *PSI =
119       FAM.getResult<ModuleAnalysisManagerFunctionProxy>(Caller)
120           .getCachedResult<ProfileSummaryAnalysis>(
121               *CB.getParent()->getParent()->getParent());
122 
123   auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(Caller);
124   auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
125     return FAM.getResult<AssumptionAnalysis>(F);
126   };
127   auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {
128     return FAM.getResult<BlockFrequencyAnalysis>(F);
129   };
130   auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & {
131     return FAM.getResult<TargetLibraryAnalysis>(F);
132   };
133 
134   auto GetInlineCost = [&](CallBase &CB) {
135     Function &Callee = *CB.getCalledFunction();
136     auto &CalleeTTI = FAM.getResult<TargetIRAnalysis>(Callee);
137     bool RemarksEnabled =
138         Callee.getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled(
139             DEBUG_TYPE);
140     return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, GetTLI,
141                          GetBFI, PSI, RemarksEnabled ? &ORE : nullptr);
142   };
143   return llvm::shouldInline(
144       CB, GetInlineCost, ORE,
145       Params.EnableDeferral.getValueOr(EnableInlineDeferral));
146 }
147 
148 std::unique_ptr<InlineAdvice>
149 DefaultInlineAdvisor::getAdviceImpl(CallBase &CB) {
150   auto OIC = getDefaultInlineAdvice(CB, FAM, Params);
151   return std::make_unique<DefaultInlineAdvice>(
152       this, CB, OIC,
153       FAM.getResult<OptimizationRemarkEmitterAnalysis>(*CB.getCaller()));
154 }
155 
156 InlineAdvice::InlineAdvice(InlineAdvisor *Advisor, CallBase &CB,
157                            OptimizationRemarkEmitter &ORE,
158                            bool IsInliningRecommended)
159     : Advisor(Advisor), Caller(CB.getCaller()), Callee(CB.getCalledFunction()),
160       DLoc(CB.getDebugLoc()), Block(CB.getParent()), ORE(ORE),
161       IsInliningRecommended(IsInliningRecommended) {}
162 
163 void InlineAdvisor::markFunctionAsDeleted(Function *F) {
164   assert((!DeletedFunctions.count(F)) &&
165          "Cannot put cause a function to become dead twice!");
166   DeletedFunctions.insert(F);
167 }
168 
169 void InlineAdvisor::freeDeletedFunctions() {
170   for (auto *F : DeletedFunctions)
171     delete F;
172   DeletedFunctions.clear();
173 }
174 
175 void InlineAdvice::recordInlineStatsIfNeeded() {
176   if (Advisor->ImportedFunctionsStats)
177     Advisor->ImportedFunctionsStats->recordInline(*Caller, *Callee);
178 }
179 
180 void InlineAdvice::recordInlining() {
181   markRecorded();
182   recordInlineStatsIfNeeded();
183   recordInliningImpl();
184 }
185 
186 void InlineAdvice::recordInliningWithCalleeDeleted() {
187   markRecorded();
188   recordInlineStatsIfNeeded();
189   Advisor->markFunctionAsDeleted(Callee);
190   recordInliningWithCalleeDeletedImpl();
191 }
192 
193 AnalysisKey InlineAdvisorAnalysis::Key;
194 
195 bool InlineAdvisorAnalysis::Result::tryCreate(
196     InlineParams Params, InliningAdvisorMode Mode,
197     const ReplayInlinerSettings &ReplaySettings) {
198   auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
199   switch (Mode) {
200   case InliningAdvisorMode::Default:
201     LLVM_DEBUG(dbgs() << "Using default inliner heuristic.\n");
202     Advisor.reset(new DefaultInlineAdvisor(M, FAM, Params));
203     // Restrict replay to default advisor, ML advisors are stateful so
204     // replay will need augmentations to interleave with them correctly.
205     if (!ReplaySettings.ReplayFile.empty()) {
206       Advisor = llvm::getReplayInlineAdvisor(M, FAM, M.getContext(),
207                                              std::move(Advisor), ReplaySettings,
208                                              /* EmitRemarks =*/true);
209     }
210     break;
211   case InliningAdvisorMode::Development:
212 #ifdef LLVM_HAVE_TF_API
213     LLVM_DEBUG(dbgs() << "Using development-mode inliner policy.\n");
214     Advisor =
215         llvm::getDevelopmentModeAdvisor(M, MAM, [&FAM, Params](CallBase &CB) {
216           auto OIC = getDefaultInlineAdvice(CB, FAM, Params);
217           return OIC.hasValue();
218         });
219 #endif
220     break;
221   case InliningAdvisorMode::Release:
222 #ifdef LLVM_HAVE_TF_AOT
223     LLVM_DEBUG(dbgs() << "Using release-mode inliner policy.\n");
224     Advisor = llvm::getReleaseModeAdvisor(M, MAM);
225 #endif
226     break;
227   }
228 
229   return !!Advisor;
230 }
231 
232 /// Return true if inlining of CB can block the caller from being
233 /// inlined which is proved to be more beneficial. \p IC is the
234 /// estimated inline cost associated with callsite \p CB.
235 /// \p TotalSecondaryCost will be set to the estimated cost of inlining the
236 /// caller if \p CB is suppressed for inlining.
237 static bool
238 shouldBeDeferred(Function *Caller, InlineCost IC, int &TotalSecondaryCost,
239                  function_ref<InlineCost(CallBase &CB)> GetInlineCost) {
240   // For now we only handle local or inline functions.
241   if (!Caller->hasLocalLinkage() && !Caller->hasLinkOnceODRLinkage())
242     return false;
243   // If the cost of inlining CB is non-positive, it is not going to prevent the
244   // caller from being inlined into its callers and hence we don't need to
245   // defer.
246   if (IC.getCost() <= 0)
247     return false;
248   // Try to detect the case where the current inlining candidate caller (call
249   // it B) is a static or linkonce-ODR function and is an inlining candidate
250   // elsewhere, and the current candidate callee (call it C) is large enough
251   // that inlining it into B would make B too big to inline later. In these
252   // circumstances it may be best not to inline C into B, but to inline B into
253   // its callers.
254   //
255   // This only applies to static and linkonce-ODR functions because those are
256   // expected to be available for inlining in the translation units where they
257   // are used. Thus we will always have the opportunity to make local inlining
258   // decisions. Importantly the linkonce-ODR linkage covers inline functions
259   // and templates in C++.
260   //
261   // FIXME: All of this logic should be sunk into getInlineCost. It relies on
262   // the internal implementation of the inline cost metrics rather than
263   // treating them as truly abstract units etc.
264   TotalSecondaryCost = 0;
265   // The candidate cost to be imposed upon the current function.
266   int CandidateCost = IC.getCost() - 1;
267   // If the caller has local linkage and can be inlined to all its callers, we
268   // can apply a huge negative bonus to TotalSecondaryCost.
269   bool ApplyLastCallBonus = Caller->hasLocalLinkage() && !Caller->hasOneUse();
270   // This bool tracks what happens if we DO inline C into B.
271   bool InliningPreventsSomeOuterInline = false;
272   unsigned NumCallerUsers = 0;
273   for (User *U : Caller->users()) {
274     CallBase *CS2 = dyn_cast<CallBase>(U);
275 
276     // If this isn't a call to Caller (it could be some other sort
277     // of reference) skip it.  Such references will prevent the caller
278     // from being removed.
279     if (!CS2 || CS2->getCalledFunction() != Caller) {
280       ApplyLastCallBonus = false;
281       continue;
282     }
283 
284     InlineCost IC2 = GetInlineCost(*CS2);
285     ++NumCallerCallersAnalyzed;
286     if (!IC2) {
287       ApplyLastCallBonus = false;
288       continue;
289     }
290     if (IC2.isAlways())
291       continue;
292 
293     // See if inlining of the original callsite would erase the cost delta of
294     // this callsite. We subtract off the penalty for the call instruction,
295     // which we would be deleting.
296     if (IC2.getCostDelta() <= CandidateCost) {
297       InliningPreventsSomeOuterInline = true;
298       TotalSecondaryCost += IC2.getCost();
299       NumCallerUsers++;
300     }
301   }
302 
303   if (!InliningPreventsSomeOuterInline)
304     return false;
305 
306   // If all outer calls to Caller would get inlined, the cost for the last
307   // one is set very low by getInlineCost, in anticipation that Caller will
308   // be removed entirely.  We did not account for this above unless there
309   // is only one caller of Caller.
310   if (ApplyLastCallBonus)
311     TotalSecondaryCost -= InlineConstants::LastCallToStaticBonus;
312 
313   // If InlineDeferralScale is negative, then ignore the cost of primary
314   // inlining -- IC.getCost() multiplied by the number of callers to Caller.
315   if (InlineDeferralScale < 0)
316     return TotalSecondaryCost < IC.getCost();
317 
318   int TotalCost = TotalSecondaryCost + IC.getCost() * NumCallerUsers;
319   int Allowance = IC.getCost() * InlineDeferralScale;
320   return TotalCost < Allowance;
321 }
322 
323 namespace llvm {
324 static raw_ostream &operator<<(raw_ostream &R, const ore::NV &Arg) {
325   return R << Arg.Val;
326 }
327 
328 template <class RemarkT>
329 RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
330   using namespace ore;
331   if (IC.isAlways()) {
332     R << "(cost=always)";
333   } else if (IC.isNever()) {
334     R << "(cost=never)";
335   } else {
336     R << "(cost=" << ore::NV("Cost", IC.getCost())
337       << ", threshold=" << ore::NV("Threshold", IC.getThreshold()) << ")";
338   }
339   if (const char *Reason = IC.getReason())
340     R << ": " << ore::NV("Reason", Reason);
341   return R;
342 }
343 } // namespace llvm
344 
345 std::string llvm::inlineCostStr(const InlineCost &IC) {
346   std::string Buffer;
347   raw_string_ostream Remark(Buffer);
348   Remark << IC;
349   return Remark.str();
350 }
351 
352 void llvm::setInlineRemark(CallBase &CB, StringRef Message) {
353   if (!InlineRemarkAttribute)
354     return;
355 
356   Attribute Attr = Attribute::get(CB.getContext(), "inline-remark", Message);
357   CB.addFnAttr(Attr);
358 }
359 
360 /// Return the cost only if the inliner should attempt to inline at the given
361 /// CallSite. If we return the cost, we will emit an optimisation remark later
362 /// using that cost, so we won't do so from this function. Return None if
363 /// inlining should not be attempted.
364 Optional<InlineCost>
365 llvm::shouldInline(CallBase &CB,
366                    function_ref<InlineCost(CallBase &CB)> GetInlineCost,
367                    OptimizationRemarkEmitter &ORE, bool EnableDeferral) {
368   using namespace ore;
369 
370   InlineCost IC = GetInlineCost(CB);
371   Instruction *Call = &CB;
372   Function *Callee = CB.getCalledFunction();
373   Function *Caller = CB.getCaller();
374 
375   if (IC.isAlways()) {
376     LLVM_DEBUG(dbgs() << "    Inlining " << inlineCostStr(IC)
377                       << ", Call: " << CB << "\n");
378     return IC;
379   }
380 
381   if (!IC) {
382     LLVM_DEBUG(dbgs() << "    NOT Inlining " << inlineCostStr(IC)
383                       << ", Call: " << CB << "\n");
384     if (IC.isNever()) {
385       ORE.emit([&]() {
386         return OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline", Call)
387                << "'" << NV("Callee", Callee) << "' not inlined into '"
388                << NV("Caller", Caller)
389                << "' because it should never be inlined " << IC;
390       });
391     } else {
392       ORE.emit([&]() {
393         return OptimizationRemarkMissed(DEBUG_TYPE, "TooCostly", Call)
394                << "'" << NV("Callee", Callee) << "' not inlined into '"
395                << NV("Caller", Caller) << "' because too costly to inline "
396                << IC;
397       });
398     }
399     setInlineRemark(CB, inlineCostStr(IC));
400     return None;
401   }
402 
403   int TotalSecondaryCost = 0;
404   if (EnableDeferral &&
405       shouldBeDeferred(Caller, IC, TotalSecondaryCost, GetInlineCost)) {
406     LLVM_DEBUG(dbgs() << "    NOT Inlining: " << CB
407                       << " Cost = " << IC.getCost()
408                       << ", outer Cost = " << TotalSecondaryCost << '\n');
409     ORE.emit([&]() {
410       return OptimizationRemarkMissed(DEBUG_TYPE, "IncreaseCostInOtherContexts",
411                                       Call)
412              << "Not inlining. Cost of inlining '" << NV("Callee", Callee)
413              << "' increases the cost of inlining '" << NV("Caller", Caller)
414              << "' in other contexts";
415     });
416     setInlineRemark(CB, "deferred");
417     return None;
418   }
419 
420   LLVM_DEBUG(dbgs() << "    Inlining " << inlineCostStr(IC) << ", Call: " << CB
421                     << '\n');
422   return IC;
423 }
424 
425 std::string llvm::formatCallSiteLocation(DebugLoc DLoc,
426                                          const CallSiteFormat &Format) {
427   std::string Buffer;
428   raw_string_ostream CallSiteLoc(Buffer);
429   bool First = true;
430   for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {
431     if (!First)
432       CallSiteLoc << " @ ";
433     // Note that negative line offset is actually possible, but we use
434     // unsigned int to match line offset representation in remarks so
435     // it's directly consumable by relay advisor.
436     uint32_t Offset =
437         DIL->getLine() - DIL->getScope()->getSubprogram()->getLine();
438     uint32_t Discriminator = DIL->getBaseDiscriminator();
439     StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();
440     if (Name.empty())
441       Name = DIL->getScope()->getSubprogram()->getName();
442     CallSiteLoc << Name.str() << ":" << llvm::utostr(Offset);
443     if (Format.outputColumn())
444       CallSiteLoc << ":" << llvm::utostr(DIL->getColumn());
445     if (Format.outputDiscriminator() && Discriminator)
446       CallSiteLoc << "." << llvm::utostr(Discriminator);
447     First = false;
448   }
449 
450   return CallSiteLoc.str();
451 }
452 
453 void llvm::addLocationToRemarks(OptimizationRemark &Remark, DebugLoc DLoc) {
454   if (!DLoc.get()) {
455     return;
456   }
457 
458   bool First = true;
459   Remark << " at callsite ";
460   for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {
461     if (!First)
462       Remark << " @ ";
463     unsigned int Offset = DIL->getLine();
464     Offset -= DIL->getScope()->getSubprogram()->getLine();
465     unsigned int Discriminator = DIL->getBaseDiscriminator();
466     StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();
467     if (Name.empty())
468       Name = DIL->getScope()->getSubprogram()->getName();
469     Remark << Name << ":" << ore::NV("Line", Offset) << ":"
470            << ore::NV("Column", DIL->getColumn());
471     if (Discriminator)
472       Remark << "." << ore::NV("Disc", Discriminator);
473     First = false;
474   }
475 
476   Remark << ";";
477 }
478 
479 void llvm::emitInlinedInto(
480     OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block,
481     const Function &Callee, const Function &Caller, bool AlwaysInline,
482     function_ref<void(OptimizationRemark &)> ExtraContext,
483     const char *PassName) {
484   ORE.emit([&]() {
485     StringRef RemarkName = AlwaysInline ? "AlwaysInline" : "Inlined";
486     OptimizationRemark Remark(PassName ? PassName : DEBUG_TYPE, RemarkName,
487                               DLoc, Block);
488     Remark << "'" << ore::NV("Callee", &Callee) << "' inlined into '"
489            << ore::NV("Caller", &Caller) << "'";
490     if (ExtraContext)
491       ExtraContext(Remark);
492     addLocationToRemarks(Remark, DLoc);
493     return Remark;
494   });
495 }
496 
497 void llvm::emitInlinedIntoBasedOnCost(
498     OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block,
499     const Function &Callee, const Function &Caller, const InlineCost &IC,
500     bool ForProfileContext, const char *PassName) {
501   llvm::emitInlinedInto(
502       ORE, DLoc, Block, Callee, Caller, IC.isAlways(),
503       [&](OptimizationRemark &Remark) {
504         if (ForProfileContext)
505           Remark << " to match profiling context";
506         Remark << " with " << IC;
507       },
508       PassName);
509 }
510 
511 InlineAdvisor::InlineAdvisor(Module &M, FunctionAnalysisManager &FAM)
512     : M(M), FAM(FAM) {
513   if (InlinerFunctionImportStats != InlinerFunctionImportStatsOpts::No) {
514     ImportedFunctionsStats =
515         std::make_unique<ImportedFunctionsInliningStatistics>();
516     ImportedFunctionsStats->setModuleInfo(M);
517   }
518 }
519 
520 InlineAdvisor::~InlineAdvisor() {
521   if (ImportedFunctionsStats) {
522     assert(InlinerFunctionImportStats != InlinerFunctionImportStatsOpts::No);
523     ImportedFunctionsStats->dump(InlinerFunctionImportStats ==
524                                  InlinerFunctionImportStatsOpts::Verbose);
525   }
526 
527   freeDeletedFunctions();
528 }
529 
530 std::unique_ptr<InlineAdvice> InlineAdvisor::getMandatoryAdvice(CallBase &CB,
531                                                                 bool Advice) {
532   return std::make_unique<MandatoryInlineAdvice>(this, CB, getCallerORE(CB),
533                                                  Advice);
534 }
535 
536 InlineAdvisor::MandatoryInliningKind
537 InlineAdvisor::getMandatoryKind(CallBase &CB, FunctionAnalysisManager &FAM,
538                                 OptimizationRemarkEmitter &ORE) {
539   auto &Callee = *CB.getCalledFunction();
540 
541   auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & {
542     return FAM.getResult<TargetLibraryAnalysis>(F);
543   };
544 
545   auto &TIR = FAM.getResult<TargetIRAnalysis>(Callee);
546 
547   auto TrivialDecision =
548       llvm::getAttributeBasedInliningDecision(CB, &Callee, TIR, GetTLI);
549 
550   if (TrivialDecision.hasValue()) {
551     if (TrivialDecision->isSuccess())
552       return MandatoryInliningKind::Always;
553     else
554       return MandatoryInliningKind::Never;
555   }
556   return MandatoryInliningKind::NotMandatory;
557 }
558 
559 std::unique_ptr<InlineAdvice> InlineAdvisor::getAdvice(CallBase &CB,
560                                                        bool MandatoryOnly) {
561   if (!MandatoryOnly)
562     return getAdviceImpl(CB);
563   bool Advice = CB.getCaller() != CB.getCalledFunction() &&
564                 MandatoryInliningKind::Always ==
565                     getMandatoryKind(CB, FAM, getCallerORE(CB));
566   return getMandatoryAdvice(CB, Advice);
567 }
568 
569 OptimizationRemarkEmitter &InlineAdvisor::getCallerORE(CallBase &CB) {
570   return FAM.getResult<OptimizationRemarkEmitterAnalysis>(*CB.getCaller());
571 }
572