LLVM  15.0.0git
InlineAdvisor.cpp
Go to the documentation of this file.
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 
15 #include "llvm/ADT/Statistic.h"
25 #include "llvm/IR/PassManager.h"
28 
29 using namespace llvm;
30 #define DEBUG_TYPE "inline"
31 #ifdef LLVM_HAVE_TF_AOT_INLINERSIZEMODEL
32 #define LLVM_HAVE_TF_AOT
33 #endif
34 
35 // This weirdly named statistic tracks the number of times that, when attempting
36 // to inline a function A into B, we analyze the callers of B in order to see
37 // if those would be more profitable and blocked inline steps.
38 STATISTIC(NumCallerCallersAnalyzed, "Number of caller-callers analyzed");
39 
40 /// Flag to add inline messages as callsite attributes 'inline-remark'.
41 static cl::opt<bool>
42  InlineRemarkAttribute("inline-remark-attribute", cl::init(false),
43  cl::Hidden,
44  cl::desc("Enable adding inline-remark attribute to"
45  " callsites processed by inliner but decided"
46  " to be not inlined"));
47 
48 static cl::opt<bool> EnableInlineDeferral("inline-deferral", cl::init(false),
49  cl::Hidden,
50  cl::desc("Enable deferred inlining"));
51 
52 // An integer used to limit the cost of inline deferral. The default negative
53 // number tells shouldBeDeferred to only take the secondary cost into account.
54 static cl::opt<int>
55  InlineDeferralScale("inline-deferral-scale",
56  cl::desc("Scale to limit the cost of inline deferral"),
57  cl::init(2), cl::Hidden);
58 
60  "annotate-inline-phase", cl::Hidden, cl::init(false),
61  cl::desc("If true, annotate inline advisor remarks "
62  "with LTO and pass information."));
63 
65 
66 namespace {
67 using namespace llvm::ore;
68 class MandatoryInlineAdvice : public InlineAdvice {
69 public:
70  MandatoryInlineAdvice(InlineAdvisor *Advisor, CallBase &CB,
72  bool IsInliningMandatory)
73  : InlineAdvice(Advisor, CB, ORE, IsInliningMandatory) {}
74 
75 private:
76  void recordInliningWithCalleeDeletedImpl() override { recordInliningImpl(); }
77 
78  void recordInliningImpl() override {
79  if (IsInliningRecommended)
80  emitInlinedInto(ORE, DLoc, Block, *Callee, *Caller, IsInliningRecommended,
81  [&](OptimizationRemark &Remark) {
82  Remark << ": always inline attribute";
83  });
84  }
85 
86  void recordUnsuccessfulInliningImpl(const InlineResult &Result) override {
87  if (IsInliningRecommended)
88  ORE.emit([&]() {
89  return OptimizationRemarkMissed(Advisor->getAnnotatedInlinePassName(),
90  "NotInlined", DLoc, Block)
91  << "'" << NV("Callee", Callee) << "' is not AlwaysInline into '"
92  << NV("Caller", Caller)
93  << "': " << NV("Reason", Result.getFailureReason());
94  });
95  }
96 
97  void recordUnattemptedInliningImpl() override {
98  assert(!IsInliningRecommended && "Expected to attempt inlining");
99  }
100 };
101 } // namespace
102 
103 void DefaultInlineAdvice::recordUnsuccessfulInliningImpl(
104  const InlineResult &Result) {
105  using namespace ore;
106  llvm::setInlineRemark(*OriginalCB, std::string(Result.getFailureReason()) +
107  "; " + inlineCostStr(*OIC));
108  ORE.emit([&]() {
110  "NotInlined", DLoc, Block)
111  << "'" << NV("Callee", Callee) << "' is not inlined into '"
112  << NV("Caller", Caller)
113  << "': " << NV("Reason", Result.getFailureReason());
114  });
115 }
116 
117 void DefaultInlineAdvice::recordInliningWithCalleeDeletedImpl() {
118  if (EmitRemarks)
120  /* ForProfileContext= */ false,
122 }
123 
124 void DefaultInlineAdvice::recordInliningImpl() {
125  if (EmitRemarks)
127  /* ForProfileContext= */ false,
129 }
130 
132  CallBase &CB, FunctionAnalysisManager &FAM, const InlineParams &Params) {
133  Function &Caller = *CB.getCaller();
134  ProfileSummaryInfo *PSI =
136  .getCachedResult<ProfileSummaryAnalysis>(
137  *CB.getParent()->getParent()->getParent());
138 
140  auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
142  };
143  auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {
145  };
146  auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & {
148  };
149 
150  auto GetInlineCost = [&](CallBase &CB) {
152  auto &CalleeTTI = FAM.getResult<TargetIRAnalysis>(Callee);
153  bool RemarksEnabled =
155  DEBUG_TYPE);
156  return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, GetTLI,
157  GetBFI, PSI, RemarksEnabled ? &ORE : nullptr);
158  };
159  return llvm::shouldInline(
160  CB, GetInlineCost, ORE,
162 }
163 
164 std::unique_ptr<InlineAdvice>
165 DefaultInlineAdvisor::getAdviceImpl(CallBase &CB) {
166  auto OIC = getDefaultInlineAdvice(CB, FAM, Params);
167  return std::make_unique<DefaultInlineAdvice>(
168  this, CB, OIC,
170 }
171 
175  : Advisor(Advisor), Caller(CB.getCaller()), Callee(CB.getCalledFunction()),
176  DLoc(CB.getDebugLoc()), Block(CB.getParent()), ORE(ORE),
178 
179 void InlineAdvice::recordInlineStatsIfNeeded() {
181  Advisor->ImportedFunctionsStats->recordInline(*Caller, *Callee);
182 }
183 
185  markRecorded();
186  recordInlineStatsIfNeeded();
188 }
189 
191  markRecorded();
192  recordInlineStatsIfNeeded();
194 }
195 
197 
200  const ReplayInlinerSettings &ReplaySettings, InlineContext IC) {
201  auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
202  switch (Mode) {
204  LLVM_DEBUG(dbgs() << "Using default inliner heuristic.\n");
205  Advisor.reset(new DefaultInlineAdvisor(M, FAM, Params, IC));
206  // Restrict replay to default advisor, ML advisors are stateful so
207  // replay will need augmentations to interleave with them correctly.
208  if (!ReplaySettings.ReplayFile.empty()) {
209  Advisor = llvm::getReplayInlineAdvisor(M, FAM, M.getContext(),
210  std::move(Advisor), ReplaySettings,
211  /* EmitRemarks =*/true, IC);
212  }
213  break;
215 #ifdef LLVM_HAVE_TF_API
216  LLVM_DEBUG(dbgs() << "Using development-mode inliner policy.\n");
217  Advisor =
218  llvm::getDevelopmentModeAdvisor(M, MAM, [&FAM, Params](CallBase &CB) {
219  auto OIC = getDefaultInlineAdvice(CB, FAM, Params);
220  return OIC.hasValue();
221  });
222 #endif
223  break;
225 #ifdef LLVM_HAVE_TF_AOT
226  LLVM_DEBUG(dbgs() << "Using release-mode inliner policy.\n");
227  Advisor = llvm::getReleaseModeAdvisor(M, MAM);
228 #endif
229  break;
230  }
231 
232  return !!Advisor;
233 }
234 
235 /// Return true if inlining of CB can block the caller from being
236 /// inlined which is proved to be more beneficial. \p IC is the
237 /// estimated inline cost associated with callsite \p CB.
238 /// \p TotalSecondaryCost will be set to the estimated cost of inlining the
239 /// caller if \p CB is suppressed for inlining.
240 static bool
241 shouldBeDeferred(Function *Caller, InlineCost IC, int &TotalSecondaryCost,
242  function_ref<InlineCost(CallBase &CB)> GetInlineCost) {
243  // For now we only handle local or inline functions.
244  if (!Caller->hasLocalLinkage() && !Caller->hasLinkOnceODRLinkage())
245  return false;
246  // If the cost of inlining CB is non-positive, it is not going to prevent the
247  // caller from being inlined into its callers and hence we don't need to
248  // defer.
249  if (IC.getCost() <= 0)
250  return false;
251  // Try to detect the case where the current inlining candidate caller (call
252  // it B) is a static or linkonce-ODR function and is an inlining candidate
253  // elsewhere, and the current candidate callee (call it C) is large enough
254  // that inlining it into B would make B too big to inline later. In these
255  // circumstances it may be best not to inline C into B, but to inline B into
256  // its callers.
257  //
258  // This only applies to static and linkonce-ODR functions because those are
259  // expected to be available for inlining in the translation units where they
260  // are used. Thus we will always have the opportunity to make local inlining
261  // decisions. Importantly the linkonce-ODR linkage covers inline functions
262  // and templates in C++.
263  //
264  // FIXME: All of this logic should be sunk into getInlineCost. It relies on
265  // the internal implementation of the inline cost metrics rather than
266  // treating them as truly abstract units etc.
267  TotalSecondaryCost = 0;
268  // The candidate cost to be imposed upon the current function.
269  int CandidateCost = IC.getCost() - 1;
270  // If the caller has local linkage and can be inlined to all its callers, we
271  // can apply a huge negative bonus to TotalSecondaryCost.
272  bool ApplyLastCallBonus = Caller->hasLocalLinkage() && !Caller->hasOneUse();
273  // This bool tracks what happens if we DO inline C into B.
274  bool InliningPreventsSomeOuterInline = false;
275  unsigned NumCallerUsers = 0;
276  for (User *U : Caller->users()) {
277  CallBase *CS2 = dyn_cast<CallBase>(U);
278 
279  // If this isn't a call to Caller (it could be some other sort
280  // of reference) skip it. Such references will prevent the caller
281  // from being removed.
282  if (!CS2 || CS2->getCalledFunction() != Caller) {
283  ApplyLastCallBonus = false;
284  continue;
285  }
286 
287  InlineCost IC2 = GetInlineCost(*CS2);
288  ++NumCallerCallersAnalyzed;
289  if (!IC2) {
290  ApplyLastCallBonus = false;
291  continue;
292  }
293  if (IC2.isAlways())
294  continue;
295 
296  // See if inlining of the original callsite would erase the cost delta of
297  // this callsite. We subtract off the penalty for the call instruction,
298  // which we would be deleting.
299  if (IC2.getCostDelta() <= CandidateCost) {
300  InliningPreventsSomeOuterInline = true;
301  TotalSecondaryCost += IC2.getCost();
302  NumCallerUsers++;
303  }
304  }
305 
306  if (!InliningPreventsSomeOuterInline)
307  return false;
308 
309  // If all outer calls to Caller would get inlined, the cost for the last
310  // one is set very low by getInlineCost, in anticipation that Caller will
311  // be removed entirely. We did not account for this above unless there
312  // is only one caller of Caller.
313  if (ApplyLastCallBonus)
314  TotalSecondaryCost -= InlineConstants::LastCallToStaticBonus;
315 
316  // If InlineDeferralScale is negative, then ignore the cost of primary
317  // inlining -- IC.getCost() multiplied by the number of callers to Caller.
318  if (InlineDeferralScale < 0)
319  return TotalSecondaryCost < IC.getCost();
320 
321  int TotalCost = TotalSecondaryCost + IC.getCost() * NumCallerUsers;
322  int Allowance = IC.getCost() * InlineDeferralScale;
323  return TotalCost < Allowance;
324 }
325 
326 namespace llvm {
328  return R << Arg.Val;
329 }
330 
331 template <class RemarkT>
332 RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
333  using namespace ore;
334  if (IC.isAlways()) {
335  R << "(cost=always)";
336  } else if (IC.isNever()) {
337  R << "(cost=never)";
338  } else {
339  R << "(cost=" << ore::NV("Cost", IC.getCost())
340  << ", threshold=" << ore::NV("Threshold", IC.getThreshold()) << ")";
341  }
342  if (const char *Reason = IC.getReason())
343  R << ": " << ore::NV("Reason", Reason);
344  return R;
345 }
346 } // namespace llvm
347 
348 std::string llvm::inlineCostStr(const InlineCost &IC) {
349  std::string Buffer;
350  raw_string_ostream Remark(Buffer);
351  Remark << IC;
352  return Remark.str();
353 }
354 
357  return;
358 
359  Attribute Attr = Attribute::get(CB.getContext(), "inline-remark", Message);
360  CB.addFnAttr(Attr);
361 }
362 
363 /// Return the cost only if the inliner should attempt to inline at the given
364 /// CallSite. If we return the cost, we will emit an optimisation remark later
365 /// using that cost, so we won't do so from this function. Return None if
366 /// inlining should not be attempted.
369  function_ref<InlineCost(CallBase &CB)> GetInlineCost,
370  OptimizationRemarkEmitter &ORE, bool EnableDeferral) {
371  using namespace ore;
372 
373  InlineCost IC = GetInlineCost(CB);
374  Instruction *Call = &CB;
376  Function *Caller = CB.getCaller();
377 
378  if (IC.isAlways()) {
379  LLVM_DEBUG(dbgs() << " Inlining " << inlineCostStr(IC)
380  << ", Call: " << CB << "\n");
381  return IC;
382  }
383 
384  if (!IC) {
385  LLVM_DEBUG(dbgs() << " NOT Inlining " << inlineCostStr(IC)
386  << ", Call: " << CB << "\n");
387  if (IC.isNever()) {
388  ORE.emit([&]() {
389  return OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline", Call)
390  << "'" << NV("Callee", Callee) << "' not inlined into '"
391  << NV("Caller", Caller)
392  << "' because it should never be inlined " << IC;
393  });
394  } else {
395  ORE.emit([&]() {
396  return OptimizationRemarkMissed(DEBUG_TYPE, "TooCostly", Call)
397  << "'" << NV("Callee", Callee) << "' not inlined into '"
398  << NV("Caller", Caller) << "' because too costly to inline "
399  << IC;
400  });
401  }
403  return None;
404  }
405 
406  int TotalSecondaryCost = 0;
407  if (EnableDeferral &&
408  shouldBeDeferred(Caller, IC, TotalSecondaryCost, GetInlineCost)) {
409  LLVM_DEBUG(dbgs() << " NOT Inlining: " << CB
410  << " Cost = " << IC.getCost()
411  << ", outer Cost = " << TotalSecondaryCost << '\n');
412  ORE.emit([&]() {
413  return OptimizationRemarkMissed(DEBUG_TYPE, "IncreaseCostInOtherContexts",
414  Call)
415  << "Not inlining. Cost of inlining '" << NV("Callee", Callee)
416  << "' increases the cost of inlining '" << NV("Caller", Caller)
417  << "' in other contexts";
418  });
419  setInlineRemark(CB, "deferred");
420  return None;
421  }
422 
423  LLVM_DEBUG(dbgs() << " Inlining " << inlineCostStr(IC) << ", Call: " << CB
424  << '\n');
425  return IC;
426 }
427 
429  const CallSiteFormat &Format) {
430  std::string Buffer;
431  raw_string_ostream CallSiteLoc(Buffer);
432  bool First = true;
433  for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {
434  if (!First)
435  CallSiteLoc << " @ ";
436  // Note that negative line offset is actually possible, but we use
437  // unsigned int to match line offset representation in remarks so
438  // it's directly consumable by relay advisor.
439  uint32_t Offset =
440  DIL->getLine() - DIL->getScope()->getSubprogram()->getLine();
441  uint32_t Discriminator = DIL->getBaseDiscriminator();
442  StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();
443  if (Name.empty())
444  Name = DIL->getScope()->getSubprogram()->getName();
445  CallSiteLoc << Name.str() << ":" << llvm::utostr(Offset);
446  if (Format.outputColumn())
447  CallSiteLoc << ":" << llvm::utostr(DIL->getColumn());
448  if (Format.outputDiscriminator() && Discriminator)
449  CallSiteLoc << "." << llvm::utostr(Discriminator);
450  First = false;
451  }
452 
453  return CallSiteLoc.str();
454 }
455 
457  if (!DLoc) {
458  return;
459  }
460 
461  bool First = true;
462  Remark << " at callsite ";
463  for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {
464  if (!First)
465  Remark << " @ ";
466  unsigned int Offset = DIL->getLine();
467  Offset -= DIL->getScope()->getSubprogram()->getLine();
468  unsigned int Discriminator = DIL->getBaseDiscriminator();
469  StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();
470  if (Name.empty())
471  Name = DIL->getScope()->getSubprogram()->getName();
472  Remark << Name << ":" << ore::NV("Line", Offset) << ":"
473  << ore::NV("Column", DIL->getColumn());
474  if (Discriminator)
475  Remark << "." << ore::NV("Disc", Discriminator);
476  First = false;
477  }
478 
479  Remark << ";";
480 }
481 
483  OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block,
484  const Function &Callee, const Function &Caller, bool AlwaysInline,
485  function_ref<void(OptimizationRemark &)> ExtraContext,
486  const char *PassName) {
487  ORE.emit([&]() {
488  StringRef RemarkName = AlwaysInline ? "AlwaysInline" : "Inlined";
490  DLoc, Block);
491  Remark << "'" << ore::NV("Callee", &Callee) << "' inlined into '"
492  << ore::NV("Caller", &Caller) << "'";
493  if (ExtraContext)
494  ExtraContext(Remark);
496  return Remark;
497  });
498 }
499 
501  OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block,
502  const Function &Callee, const Function &Caller, const InlineCost &IC,
503  bool ForProfileContext, const char *PassName) {
505  ORE, DLoc, Block, Callee, Caller, IC.isAlways(),
506  [&](OptimizationRemark &Remark) {
507  if (ForProfileContext)
508  Remark << " to match profiling context";
509  Remark << " with " << IC;
510  },
511  PassName);
512 }
513 
516  : M(M), FAM(FAM), IC(IC),
517  AnnotatedInlinePassName((IC && AnnotateInlinePhase) ? llvm::AnnotateInlinePassName(*IC)
518  : DEBUG_TYPE) {
521  std::make_unique<ImportedFunctionsInliningStatistics>();
522  ImportedFunctionsStats->setModuleInfo(M);
523  }
524 }
525 
531  }
532 }
533 
534 std::unique_ptr<InlineAdvice> InlineAdvisor::getMandatoryAdvice(CallBase &CB,
535  bool Advice) {
536  return std::make_unique<MandatoryInlineAdvice>(this, CB, getCallerORE(CB),
537  Advice);
538 }
539 
540 static inline const char *getLTOPhase(ThinOrFullLTOPhase LTOPhase) {
541  switch (LTOPhase) {
543  return "main";
546  return "prelink";
549  return "postlink";
550  }
551  llvm_unreachable("unreachable");
552 }
553 
554 static inline const char *getInlineAdvisorContext(InlinePass IP) {
555  switch (IP) {
557  return "always-inline";
559  return "cgscc-inline";
561  return "early-inline";
562  case (InlinePass::MLInliner):
563  return "ml-inline";
565  return "module-inline";
567  return "replay-cgscc-inline";
569  return "replay-sample-profile-inline";
571  return "sample-profile-inline";
572  }
573 
574  llvm_unreachable("unreachable");
575 }
576 
578  return std::string(getLTOPhase(IC.LTOPhase)) + "-" +
579  std::string(getInlineAdvisorContext(IC.Pass));
580 }
581 
585  auto &Callee = *CB.getCalledFunction();
586 
587  auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & {
589  };
590 
591  auto &TIR = FAM.getResult<TargetIRAnalysis>(Callee);
592 
593  auto TrivialDecision =
595 
596  if (TrivialDecision) {
597  if (TrivialDecision->isSuccess())
599  else
601  }
603 }
604 
605 std::unique_ptr<InlineAdvice> InlineAdvisor::getAdvice(CallBase &CB,
606  bool MandatoryOnly) {
607  if (!MandatoryOnly)
608  return getAdviceImpl(CB);
609  bool Advice = CB.getCaller() != CB.getCalledFunction() &&
612  return getMandatoryAdvice(CB, Advice);
613 }
614 
617 }
618 
621  const auto *IA = MAM.getCachedResult<InlineAdvisorAnalysis>(M);
622  if (!IA)
623  OS << "No Inline Advisor\n";
624  else
625  IA->getAdvisor()->print(OS);
626  return PreservedAnalyses::all();
627 }
628 
631  CGSCCUpdateResult &UR) {
632  const auto &MAMProxy =
633  AM.getResult<ModuleAnalysisManagerCGSCCProxy>(InitialC, CG);
634 
635  if (InitialC.size() == 0) {
636  OS << "SCC is empty!\n";
637  return PreservedAnalyses::all();
638  }
639  Module &M = *InitialC.begin()->getFunction().getParent();
640  const auto *IA = MAMProxy.getCachedResult<InlineAdvisorAnalysis>(M);
641  if (!IA)
642  OS << "No Inline Advisor\n";
643  else
644  IA->getAdvisor()->print(OS);
645  return PreservedAnalyses::all();
646 }
llvm::InlinePass::AlwaysInliner
@ AlwaysInliner
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
llvm::InlineCost::isAlways
bool isAlways() const
Definition: InlineCost.h:129
llvm::OuterAnalysisManagerProxy
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:1062
llvm::InlineCost::getCost
int getCost() const
Get the inline cost estimate.
Definition: InlineCost.h:135
AssumptionCache.h
llvm::TargetIRAnalysis
Analysis pass providing the TargetTransformInfo.
Definition: TargetTransformInfo.h:2479
llvm::OptimizationRemarkMissed
Diagnostic information for missed-optimization remarks.
Definition: DiagnosticInfo.h:735
llvm::InlineAdvice::recordInlining
void recordInlining()
Exactly one of the record* APIs must be called.
Definition: InlineAdvisor.cpp:184
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::getReleaseModeAdvisor
std::unique_ptr< InlineAdvisor > getReleaseModeAdvisor(Module &M, ModuleAnalysisManager &MAM)
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::InlineAdvisor::ImportedFunctionsStats
std::unique_ptr< ImportedFunctionsInliningStatistics > ImportedFunctionsStats
Definition: InlineAdvisor.h:212
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:104
llvm::InlineAdvisor::M
Module & M
Definition: InlineAdvisor.h:208
llvm::AnalysisManager::getResult
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:780
DebugInfoMetadata.h
llvm::ThinOrFullLTOPhase::ThinLTOPostLink
@ ThinLTOPostLink
ThinLTO postlink (backend compile) phase.
llvm::DiagnosticHandler::isMissedOptRemarkEnabled
virtual bool isMissedOptRemarkEnabled(StringRef PassName) const
Return true if missed optimization remarks are enabled, override to provide different implementation.
Definition: DiagnosticHandler.cpp:75
llvm::Function
Definition: Function.h:60
llvm::Attribute
Definition: Attributes.h:65
llvm::InlinePass::EarlyInliner
@ EarlyInliner
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:632
llvm::InlinerFunctionImportStatsOpts::Verbose
@ Verbose
llvm::Attribute::get
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:90
Statistic.h
llvm::InlineAdvisorAnalysisPrinterPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Definition: InlineAdvisor.cpp:620
llvm::InlineAdvice::Caller
Function *const Caller
Caller and Callee are pre-inlining.
Definition: InlineAdvisor.h:122
OptimizationRemarkEmitter.h
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:139
llvm::emitInlinedIntoBasedOnCost
void emitInlinedIntoBasedOnCost(OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block, const Function &Callee, const Function &Caller, const InlineCost &IC, bool ForProfileContext=false, const char *PassName=nullptr)
Emit ORE message based in cost (default heuristic).
Definition: InlineAdvisor.cpp:500
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1557
llvm::Function::getContext
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:319
llvm::Optional< llvm::InlineCost >
llvm::InlineParams
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:190
llvm::InlineAdvisor::MandatoryInliningKind::Always
@ Always
llvm::InlineAdvisor::MandatoryInliningKind::Never
@ Never
llvm::ore::NV
DiagnosticInfoOptimizationBase::Argument NV
Definition: OptimizationRemarkEmitter.h:136
llvm::InlineCost::getThreshold
int getThreshold() const
Get the threshold against which the cost was computed.
Definition: InlineCost.h:141
llvm::ThinOrFullLTOPhase::ThinLTOPreLink
@ ThinLTOPreLink
ThinLTO prelink (summary) phase.
llvm::InlineCost::isNever
bool isNever() const
Definition: InlineCost.h:130
llvm::addLocationToRemarks
void addLocationToRemarks(OptimizationRemark &Remark, DebugLoc DLoc)
Add location info to ORE message.
Definition: InlineAdvisor.cpp:456
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::InlineAdvisor::getCallerORE
OptimizationRemarkEmitter & getCallerORE(CallBase &CB)
Definition: InlineAdvisor.cpp:615
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
llvm::ThinOrFullLTOPhase
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition: Pass.h:73
CommandLine.h
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition: BlockFrequencyInfo.h:37
ImportedFunctionsInliningStatistics.h
llvm::InlinerFunctionImportStatsOpts::No
@ No
llvm::emitInlinedInto
void emitInlinedInto(OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block, const Function &Callee, const Function &Caller, bool IsMandatory, function_ref< void(OptimizationRemark &)> ExtraContext={}, const char *PassName=nullptr)
Emit ORE message.
Definition: InlineAdvisor.cpp:482
llvm::InlineAdvice::IsInliningRecommended
const bool IsInliningRecommended
Definition: InlineAdvisor.h:131
llvm::LazyCallGraph::SCC
An SCC of the call graph.
Definition: LazyCallGraph.h:419
InlineRemarkAttribute
static cl::opt< bool > InlineRemarkAttribute("inline-remark-attribute", cl::init(false), cl::Hidden, cl::desc("Enable adding inline-remark attribute to" " callsites processed by inliner but decided" " to be not inlined"))
Flag to add inline messages as callsite attributes 'inline-remark'.
llvm::getInlineCost
InlineCost getInlineCost(CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI, function_ref< AssumptionCache &(Function &)> GetAssumptionCache, function_ref< const TargetLibraryInfo &(Function &)> GetTLI, function_ref< BlockFrequencyInfo &(Function &)> GetBFI=nullptr, ProfileSummaryInfo *PSI=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Get an InlineCost object representing the cost of inlining this callsite.
Definition: InlineCost.cpp:2803
llvm::InlineAdvice::ORE
OptimizationRemarkEmitter & ORE
Definition: InlineAdvisor.h:130
llvm::User
Definition: User.h:44
llvm::DefaultInlineAdvisor
The default (manual heuristics) implementation of the InlineAdvisor.
Definition: InlineAdvisor.h:229
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1396
MAM
ModuleAnalysisManager MAM
Definition: PassBuilderBindings.cpp:61
llvm::InlineCost
Represents the cost of inlining a function.
Definition: InlineCost.h:87
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
IP
Definition: NVPTXLowerArgs.cpp:167
TargetLibraryInfo.h
getLTOPhase
static const char * getLTOPhase(ThinOrFullLTOPhase LTOPhase)
Definition: InlineAdvisor.cpp:540
First
into llvm powi allowing the code generator to produce balanced multiplication trees First
Definition: README.txt:54
InlineAdvisor.h
getInlineAdvisorContext
static const char * getInlineAdvisorContext(InlinePass IP)
Definition: InlineAdvisor.cpp:554
llvm::Instruction
Definition: Instruction.h:42
llvm::CallBase::addFnAttr
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
Definition: InstrTypes.h:1506
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
llvm::InlineContext
Provides context on when an inline advisor is constructed in the pipeline (e.g., link phase,...
Definition: InlineAdvisor.h:58
llvm::BlockFrequencyAnalysis
Analysis pass which computes BlockFrequencyInfo.
Definition: BlockFrequencyInfo.h:112
llvm::None
const NoneType None
Definition: None.h:24
llvm::CallBase::getCaller
Function * getCaller()
Helper to get the caller (the parent function).
Definition: Instructions.cpp:282
llvm::formatCallSiteLocation
std::string formatCallSiteLocation(DebugLoc DLoc, const CallSiteFormat &Format)
Get call site location as a string with the given format.
Definition: InlineAdvisor.cpp:428
llvm::ReplayInlinerSettings::ReplayFile
StringRef ReplayFile
Definition: ReplayInlineAdvisor.h:47
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
llvm::InlineAdvisor::MandatoryInliningKind
MandatoryInliningKind
Definition: InlineAdvisor.h:214
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::LLVMContext::getDiagHandlerPtr
const DiagnosticHandler * getDiagHandlerPtr() const
getDiagHandlerPtr - Returns const raw pointer of DiagnosticHandler set by setDiagnosticHandler.
Definition: LLVMContext.cpp:358
llvm::HighlightColor::Remark
@ Remark
llvm::InlineAdvice
Capture state between an inlining decision having had been made, and its impact being observable.
Definition: InlineAdvisor.h:74
llvm::cl::opt< bool >
ReplayInlineAdvisor.h
llvm::InliningAdvisorMode
InliningAdvisorMode
There are 3 scenarios we can use the InlineAdvisor:
Definition: InlineAdvisor.h:42
shouldBeDeferred
static bool shouldBeDeferred(Function *Caller, InlineCost IC, int &TotalSecondaryCost, function_ref< InlineCost(CallBase &CB)> GetInlineCost)
Return true if inlining of CB can block the caller from being inlined which is proved to be more bene...
Definition: InlineAdvisor.cpp:241
llvm::DiagnosticInfoOptimizationBase::Argument
Used in the streaming interface as the general argument type.
Definition: DiagnosticInfo.h:427
llvm::InlineAdvisor::getAnnotatedInlinePassName
const char * getAnnotatedInlinePassName() const
NOTE pass name is annotated only when inline advisor constructor provides InlineContext.
Definition: InlineAdvisor.h:197
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::InlineAdvisor::InlineAdvisor
InlineAdvisor(InlineAdvisor &&)=delete
ProfileSummaryInfo.h
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:620
llvm::InlineAdvice::recordInliningWithCalleeDeleted
void recordInliningWithCalleeDeleted()
Call after inlining succeeded, and results in the callee being delete-able, meaning,...
Definition: InlineAdvisor.cpp:190
llvm::AssumptionAnalysis
A function analysis which provides an AssumptionCache.
Definition: AssumptionCache.h:173
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:69
llvm::InlinePass::MLInliner
@ MLInliner
llvm::DebugLoc::get
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:20
getCalledFunction
static const Function * getCalledFunction(const Value *V, bool &IsNoBuiltin)
Definition: MemoryBuiltins.cpp:160
llvm::InlineAdvice::Block
const BasicBlock *const Block
Definition: InlineAdvisor.h:129
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
llvm::InlineCost::getCostDelta
int getCostDelta() const
Get the cost delta from the threshold for inlining.
Definition: InlineCost.h:159
llvm::InlineAdvice::recordInliningImpl
virtual void recordInliningImpl()
Definition: InlineAdvisor.h:115
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::setInlineRemark
void setInlineRemark(CallBase &CB, StringRef Message)
Set the inline-remark attribute.
Definition: InlineAdvisor.cpp:355
llvm::OptimizationRemarkEmitter::emit
void emit(DiagnosticInfoOptimizationBase &OptDiag)
Output the remark via the diagnostic handler and to the optimization record file.
Definition: OptimizationRemarkEmitter.cpp:77
llvm::InlineAdvice::DLoc
const DebugLoc DLoc
Definition: InlineAdvisor.h:128
InlineCost.h
llvm::InlinePass::CGSCCInliner
@ CGSCCInliner
Mode
SI Whole Quad Mode
Definition: SIWholeQuadMode.cpp:262
llvm::InliningAdvisorMode::Development
@ Development
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::InlineContext::Pass
InlinePass Pass
Definition: InlineAdvisor.h:61
getDebugLoc
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
Definition: MachineInstrBundle.cpp:110
llvm::ThinOrFullLTOPhase::FullLTOPostLink
@ FullLTOPostLink
Full LTO postlink (backend compile) phase.
llvm::InlineAdvisor::MandatoryInliningKind::NotMandatory
@ NotMandatory
llvm::InlineAdvisorAnalysis::Result::tryCreate
bool tryCreate(InlineParams Params, InliningAdvisorMode Mode, const ReplayInlinerSettings &ReplaySettings, InlineContext IC)
Definition: InlineAdvisor.cpp:198
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: OptimizationRemarkEmitter.h:33
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::CallSiteFormat
Definition: ReplayInlineAdvisor.h:21
llvm::InlineCost::getReason
const char * getReason() const
Get the reason of Always or Never.
Definition: InlineCost.h:150
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:42
llvm::InlineAdvisor
Interface for deciding whether to inline a call site or not.
Definition: InlineAdvisor.h:163
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
getParent
static const Function * getParent(const Value *V)
Definition: BasicAliasAnalysis.cpp:845
uint32_t
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:991
llvm::InlineAdvice::recordInliningWithCalleeDeletedImpl
virtual void recordInliningWithCalleeDeletedImpl()
Definition: InlineAdvisor.h:116
InlinerFunctionImportStats
cl::opt< InlinerFunctionImportStatsOpts > InlinerFunctionImportStats
llvm::InlinePass::ReplaySampleProfileInliner
@ ReplaySampleProfileInliner
InlineDeferralScale
static cl::opt< int > InlineDeferralScale("inline-deferral-scale", cl::desc("Scale to limit the cost of inline deferral"), cl::init(2), cl::Hidden)
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:186
EnableInlineDeferral
static cl::opt< bool > EnableInlineDeferral("inline-deferral", cl::init(false), cl::Hidden, cl::desc("Enable deferred inlining"))
llvm::InlineAdvisor::getMandatoryAdvice
virtual std::unique_ptr< InlineAdvice > getMandatoryAdvice(CallBase &CB, bool Advice)
Definition: InlineAdvisor.cpp:534
llvm::getAttributeBasedInliningDecision
Optional< InlineResult > getAttributeBasedInliningDecision(CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI, function_ref< const TargetLibraryInfo &(Function &)> GetTLI)
Returns InlineResult::success() if the call site should be always inlined because of user directives,...
Definition: InlineCost.cpp:2851
llvm::CGSCCUpdateResult
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
Definition: CGSCCPassManager.h:232
llvm::InlineAdvisor::FAM
FunctionAnalysisManager & FAM
Definition: InlineAdvisor.h:209
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::InlinePass::ModuleInliner
@ ModuleInliner
llvm::InlineAdvisor::getAdvice
std::unique_ptr< InlineAdvice > getAdvice(CallBase &CB, bool MandatoryOnly=false)
Get an InlineAdvice containing a recommendation on whether to inline or not.
Definition: InlineAdvisor.cpp:605
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
llvm::InlinePass
InlinePass
Definition: InlineAdvisor.h:45
llvm::AnalysisManager::getCachedResult
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Definition: PassManager.h:799
llvm::Module::getContext
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:262
AnnotateInlinePhase
static cl::opt< bool > AnnotateInlinePhase("annotate-inline-phase", cl::Hidden, cl::init(false), cl::desc("If true, annotate inline advisor remarks " "with LTO and pass information."))
llvm::InlineAdvisor::getAdviceImpl
virtual std::unique_ptr< InlineAdvice > getAdviceImpl(CallBase &CB)=0
PassManager.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:222
llvm::ThinOrFullLTOPhase::None
@ None
No LTO/ThinLTO behavior needed.
llvm::inlineCostStr
std::string inlineCostStr(const InlineCost &IC)
Utility for extracting the inline cost message to a string.
Definition: InlineAdvisor.cpp:348
llvm::InlinePass::SampleProfileInliner
@ SampleProfileInliner
llvm::InlineAdvisor::getMandatoryKind
static MandatoryInliningKind getMandatoryKind(CallBase &CB, FunctionAnalysisManager &FAM, OptimizationRemarkEmitter &ORE)
Definition: InlineAdvisor.cpp:583
llvm::AnnotateInlinePassName
std::string AnnotateInlinePassName(InlineContext IC)
Definition: InlineAdvisor.cpp:577
llvm::ThinOrFullLTOPhase::FullLTOPreLink
@ FullLTOPreLink
Full LTO prelink phase.
llvm::OptimizationRemark
Diagnostic information for applied optimization remarks.
Definition: DiagnosticInfo.h:690
llvm::InlineAdvisorAnalysis
The InlineAdvisorAnalysis is a module pass because the InlineAdvisor needs to capture state right bef...
Definition: InlineAdvisor.h:243
llvm::InlineConstants::LastCallToStaticBonus
const int LastCallToStaticBonus
Definition: InlineCost.h:50
llvm::InlineAdvisorAnalysis::Key
static AnalysisKey Key
Definition: InlineAdvisor.h:245
llvm::InliningAdvisorMode::Default
@ Default
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:91
llvm::getDevelopmentModeAdvisor
std::unique_ptr< InlineAdvisor > getDevelopmentModeAdvisor(Module &M, ModuleAnalysisManager &MAM, std::function< bool(CallBase &)> GetDefaultAdvice)
TargetTransformInfo.h
llvm::InlineAdvice::InlineAdvice
InlineAdvice(InlineAdvisor *Advisor, CallBase &CB, OptimizationRemarkEmitter &ORE, bool IsInliningRecommended)
Definition: InlineAdvisor.cpp:172
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1174
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:937
llvm::InliningAdvisorMode::Release
@ Release
DEBUG_TYPE
#define DEBUG_TYPE
Definition: InlineAdvisor.cpp:30
llvm::ore
Add a small namespace to avoid name clashes with the classes used in the streaming interface.
Definition: OptimizationRemarkEmitter.h:135
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::cl::desc
Definition: CommandLine.h:405
llvm::LazyCallGraph
A lazily constructed view of the call graph of a module.
Definition: LazyCallGraph.h:110
raw_ostream.h
llvm::InlineParams::EnableDeferral
Optional< bool > EnableDeferral
Indicate whether we should allow inline deferral.
Definition: InlineCost.h:220
getDefaultInlineAdvice
static llvm::Optional< llvm::InlineCost > getDefaultInlineAdvice(CallBase &CB, FunctionAnalysisManager &FAM, const InlineParams &Params)
Definition: InlineAdvisor.cpp:131
llvm::raw_string_ostream::str
std::string & str()
Returns the string's reference.
Definition: raw_ostream.h:650
llvm::InlineAdvice::Advisor
InlineAdvisor *const Advisor
Definition: InlineAdvisor.h:120
llvm::Optional::value_or
constexpr T value_or(U &&alt) const &
Definition: Optional.h:318
llvm::OptimizationRemarkEmitterAnalysis
Definition: OptimizationRemarkEmitter.h:164
llvm::InlineResult
InlineResult is basically true or false.
Definition: InlineCost.h:164
llvm::InlineAdvice::Callee
Function *const Callee
Definition: InlineAdvisor.h:123
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:443
llvm::ReplayInlinerSettings
Replay Inliner Setup.
Definition: ReplayInlineAdvisor.h:43
llvm::InlineAdvisor::~InlineAdvisor
virtual ~InlineAdvisor()
Definition: InlineAdvisor.cpp:526
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:671
llvm::InlinePass::ReplayCGSCCInliner
@ ReplayCGSCCInliner
llvm::getReplayInlineAdvisor
std::unique_ptr< InlineAdvisor > getReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM, LLVMContext &Context, std::unique_ptr< InlineAdvisor > OriginalAdvisor, const ReplayInlinerSettings &ReplaySettings, bool EmitRemarks, InlineContext IC)
Definition: ReplayInlineAdvisor.cpp:80
llvm::shouldInline
Optional< InlineCost > shouldInline(CallBase &CB, function_ref< InlineCost(CallBase &CB)> GetInlineCost, OptimizationRemarkEmitter &ORE, bool EnableDeferral=true)
Return the cost only if the inliner should attempt to inline at the given CallSite.
Definition: InlineAdvisor.cpp:368
llvm::InlineContext::LTOPhase
ThinOrFullLTOPhase LTOPhase
Definition: InlineAdvisor.h:59