LLVM  14.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"
23 #include "llvm/IR/Instructions.h"
24 #include "llvm/IR/PassManager.h"
27 
28 using namespace llvm;
29 #define DEBUG_TYPE "inline"
30 #ifdef LLVM_HAVE_TF_AOT_INLINERSIZEMODEL
31 #define LLVM_HAVE_TF_AOT
32 #endif
33 
34 // This weirdly named statistic tracks the number of times that, when attempting
35 // to inline a function A into B, we analyze the callers of B in order to see
36 // if those would be more profitable and blocked inline steps.
37 STATISTIC(NumCallerCallersAnalyzed, "Number of caller-callers analyzed");
38 
39 /// Flag to add inline messages as callsite attributes 'inline-remark'.
40 static cl::opt<bool>
41  InlineRemarkAttribute("inline-remark-attribute", cl::init(false),
42  cl::Hidden,
43  cl::desc("Enable adding inline-remark attribute to"
44  " callsites processed by inliner but decided"
45  " to be not inlined"));
46 
47 static cl::opt<bool> EnableInlineDeferral("inline-deferral", cl::init(false),
48  cl::Hidden,
49  cl::desc("Enable deferred inlining"));
50 
51 // An integer used to limit the cost of inline deferral. The default negative
52 // number tells shouldBeDeferred to only take the secondary cost into account.
53 static cl::opt<int>
54  InlineDeferralScale("inline-deferral-scale",
55  cl::desc("Scale to limit the cost of inline deferral"),
56  cl::init(2), cl::Hidden);
57 
59 
60 namespace {
61 using namespace llvm::ore;
62 class MandatoryInlineAdvice : public InlineAdvice {
63 public:
64  MandatoryInlineAdvice(InlineAdvisor *Advisor, CallBase &CB,
66  bool IsInliningMandatory)
67  : InlineAdvice(Advisor, CB, ORE, IsInliningMandatory) {}
68 
69 private:
70  void recordInliningWithCalleeDeletedImpl() override { recordInliningImpl(); }
71 
72  void recordInliningImpl() override {
73  if (IsInliningRecommended)
74  emitInlinedInto(ORE, DLoc, Block, *Callee, *Caller, IsInliningRecommended,
75  [&](OptimizationRemark &Remark) {
76  Remark << ": always inline attribute";
77  });
78  }
79 
80  void recordUnsuccessfulInliningImpl(const InlineResult &Result) override {
81  if (IsInliningRecommended)
82  ORE.emit([&]() {
83  return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
84  << "'" << NV("Callee", Callee) << "' is not AlwaysInline into '"
85  << NV("Caller", Caller)
86  << "': " << NV("Reason", Result.getFailureReason());
87  });
88  }
89 
90  void recordUnattemptedInliningImpl() override {
91  assert(!IsInliningRecommended && "Expected to attempt inlining");
92  }
93 };
94 } // namespace
95 
96 void DefaultInlineAdvice::recordUnsuccessfulInliningImpl(
97  const InlineResult &Result) {
98  using namespace ore;
99  llvm::setInlineRemark(*OriginalCB, std::string(Result.getFailureReason()) +
100  "; " + inlineCostStr(*OIC));
101  ORE.emit([&]() {
102  return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
103  << "'" << NV("Callee", Callee) << "' is not inlined into '"
104  << NV("Caller", Caller)
105  << "': " << NV("Reason", Result.getFailureReason());
106  });
107 }
108 
109 void DefaultInlineAdvice::recordInliningWithCalleeDeletedImpl() {
110  if (EmitRemarks)
112 }
113 
114 void DefaultInlineAdvice::recordInliningImpl() {
115  if (EmitRemarks)
117 }
118 
120  CallBase &CB, FunctionAnalysisManager &FAM, const InlineParams &Params) {
121  Function &Caller = *CB.getCaller();
122  ProfileSummaryInfo *PSI =
124  .getCachedResult<ProfileSummaryAnalysis>(
125  *CB.getParent()->getParent()->getParent());
126 
128  auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
130  };
131  auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {
133  };
134  auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & {
136  };
137 
138  auto GetInlineCost = [&](CallBase &CB) {
140  auto &CalleeTTI = FAM.getResult<TargetIRAnalysis>(Callee);
141  bool RemarksEnabled =
143  DEBUG_TYPE);
144  return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, GetTLI,
145  GetBFI, PSI, RemarksEnabled ? &ORE : nullptr);
146  };
147  return llvm::shouldInline(
148  CB, GetInlineCost, ORE,
150 }
151 
152 std::unique_ptr<InlineAdvice>
153 DefaultInlineAdvisor::getAdviceImpl(CallBase &CB) {
154  auto OIC = getDefaultInlineAdvice(CB, FAM, Params);
155  return std::make_unique<DefaultInlineAdvice>(
156  this, CB, OIC,
158 }
159 
163  : Advisor(Advisor), Caller(CB.getCaller()), Callee(CB.getCalledFunction()),
164  DLoc(CB.getDebugLoc()), Block(CB.getParent()), ORE(ORE),
166 
167 void InlineAdvice::recordInlineStatsIfNeeded() {
169  Advisor->ImportedFunctionsStats->recordInline(*Caller, *Callee);
170 }
171 
173  markRecorded();
174  recordInlineStatsIfNeeded();
176 }
177 
179  markRecorded();
180  recordInlineStatsIfNeeded();
182 }
183 
185 
188  const ReplayInlinerSettings &ReplaySettings) {
189  auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
190  switch (Mode) {
192  LLVM_DEBUG(dbgs() << "Using default inliner heuristic.\n");
193  Advisor.reset(new DefaultInlineAdvisor(M, FAM, Params));
194  // Restrict replay to default advisor, ML advisors are stateful so
195  // replay will need augmentations to interleave with them correctly.
196  if (!ReplaySettings.ReplayFile.empty()) {
197  Advisor = llvm::getReplayInlineAdvisor(M, FAM, M.getContext(),
198  std::move(Advisor), ReplaySettings,
199  /* EmitRemarks =*/true);
200  }
201  break;
203 #ifdef LLVM_HAVE_TF_API
204  LLVM_DEBUG(dbgs() << "Using development-mode inliner policy.\n");
205  Advisor =
206  llvm::getDevelopmentModeAdvisor(M, MAM, [&FAM, Params](CallBase &CB) {
207  auto OIC = getDefaultInlineAdvice(CB, FAM, Params);
208  return OIC.hasValue();
209  });
210 #endif
211  break;
213 #ifdef LLVM_HAVE_TF_AOT
214  LLVM_DEBUG(dbgs() << "Using release-mode inliner policy.\n");
215  Advisor = llvm::getReleaseModeAdvisor(M, MAM);
216 #endif
217  break;
218  }
219 
220  return !!Advisor;
221 }
222 
223 /// Return true if inlining of CB can block the caller from being
224 /// inlined which is proved to be more beneficial. \p IC is the
225 /// estimated inline cost associated with callsite \p CB.
226 /// \p TotalSecondaryCost will be set to the estimated cost of inlining the
227 /// caller if \p CB is suppressed for inlining.
228 static bool
229 shouldBeDeferred(Function *Caller, InlineCost IC, int &TotalSecondaryCost,
230  function_ref<InlineCost(CallBase &CB)> GetInlineCost) {
231  // For now we only handle local or inline functions.
232  if (!Caller->hasLocalLinkage() && !Caller->hasLinkOnceODRLinkage())
233  return false;
234  // If the cost of inlining CB is non-positive, it is not going to prevent the
235  // caller from being inlined into its callers and hence we don't need to
236  // defer.
237  if (IC.getCost() <= 0)
238  return false;
239  // Try to detect the case where the current inlining candidate caller (call
240  // it B) is a static or linkonce-ODR function and is an inlining candidate
241  // elsewhere, and the current candidate callee (call it C) is large enough
242  // that inlining it into B would make B too big to inline later. In these
243  // circumstances it may be best not to inline C into B, but to inline B into
244  // its callers.
245  //
246  // This only applies to static and linkonce-ODR functions because those are
247  // expected to be available for inlining in the translation units where they
248  // are used. Thus we will always have the opportunity to make local inlining
249  // decisions. Importantly the linkonce-ODR linkage covers inline functions
250  // and templates in C++.
251  //
252  // FIXME: All of this logic should be sunk into getInlineCost. It relies on
253  // the internal implementation of the inline cost metrics rather than
254  // treating them as truly abstract units etc.
255  TotalSecondaryCost = 0;
256  // The candidate cost to be imposed upon the current function.
257  int CandidateCost = IC.getCost() - 1;
258  // If the caller has local linkage and can be inlined to all its callers, we
259  // can apply a huge negative bonus to TotalSecondaryCost.
260  bool ApplyLastCallBonus = Caller->hasLocalLinkage() && !Caller->hasOneUse();
261  // This bool tracks what happens if we DO inline C into B.
262  bool InliningPreventsSomeOuterInline = false;
263  unsigned NumCallerUsers = 0;
264  for (User *U : Caller->users()) {
265  CallBase *CS2 = dyn_cast<CallBase>(U);
266 
267  // If this isn't a call to Caller (it could be some other sort
268  // of reference) skip it. Such references will prevent the caller
269  // from being removed.
270  if (!CS2 || CS2->getCalledFunction() != Caller) {
271  ApplyLastCallBonus = false;
272  continue;
273  }
274 
275  InlineCost IC2 = GetInlineCost(*CS2);
276  ++NumCallerCallersAnalyzed;
277  if (!IC2) {
278  ApplyLastCallBonus = false;
279  continue;
280  }
281  if (IC2.isAlways())
282  continue;
283 
284  // See if inlining of the original callsite would erase the cost delta of
285  // this callsite. We subtract off the penalty for the call instruction,
286  // which we would be deleting.
287  if (IC2.getCostDelta() <= CandidateCost) {
288  InliningPreventsSomeOuterInline = true;
289  TotalSecondaryCost += IC2.getCost();
290  NumCallerUsers++;
291  }
292  }
293 
294  if (!InliningPreventsSomeOuterInline)
295  return false;
296 
297  // If all outer calls to Caller would get inlined, the cost for the last
298  // one is set very low by getInlineCost, in anticipation that Caller will
299  // be removed entirely. We did not account for this above unless there
300  // is only one caller of Caller.
301  if (ApplyLastCallBonus)
302  TotalSecondaryCost -= InlineConstants::LastCallToStaticBonus;
303 
304  // If InlineDeferralScale is negative, then ignore the cost of primary
305  // inlining -- IC.getCost() multiplied by the number of callers to Caller.
306  if (InlineDeferralScale < 0)
307  return TotalSecondaryCost < IC.getCost();
308 
309  int TotalCost = TotalSecondaryCost + IC.getCost() * NumCallerUsers;
310  int Allowance = IC.getCost() * InlineDeferralScale;
311  return TotalCost < Allowance;
312 }
313 
314 namespace llvm {
316  return R << Arg.Val;
317 }
318 
319 template <class RemarkT>
320 RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
321  using namespace ore;
322  if (IC.isAlways()) {
323  R << "(cost=always)";
324  } else if (IC.isNever()) {
325  R << "(cost=never)";
326  } else {
327  R << "(cost=" << ore::NV("Cost", IC.getCost())
328  << ", threshold=" << ore::NV("Threshold", IC.getThreshold()) << ")";
329  }
330  if (const char *Reason = IC.getReason())
331  R << ": " << ore::NV("Reason", Reason);
332  return R;
333 }
334 } // namespace llvm
335 
336 std::string llvm::inlineCostStr(const InlineCost &IC) {
337  std::string Buffer;
338  raw_string_ostream Remark(Buffer);
339  Remark << IC;
340  return Remark.str();
341 }
342 
345  return;
346 
347  Attribute Attr = Attribute::get(CB.getContext(), "inline-remark", Message);
348  CB.addFnAttr(Attr);
349 }
350 
351 /// Return the cost only if the inliner should attempt to inline at the given
352 /// CallSite. If we return the cost, we will emit an optimisation remark later
353 /// using that cost, so we won't do so from this function. Return None if
354 /// inlining should not be attempted.
357  function_ref<InlineCost(CallBase &CB)> GetInlineCost,
358  OptimizationRemarkEmitter &ORE, bool EnableDeferral) {
359  using namespace ore;
360 
361  InlineCost IC = GetInlineCost(CB);
362  Instruction *Call = &CB;
364  Function *Caller = CB.getCaller();
365 
366  if (IC.isAlways()) {
367  LLVM_DEBUG(dbgs() << " Inlining " << inlineCostStr(IC)
368  << ", Call: " << CB << "\n");
369  return IC;
370  }
371 
372  if (!IC) {
373  LLVM_DEBUG(dbgs() << " NOT Inlining " << inlineCostStr(IC)
374  << ", Call: " << CB << "\n");
375  if (IC.isNever()) {
376  ORE.emit([&]() {
377  return OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline", Call)
378  << "'" << NV("Callee", Callee) << "' not inlined into '"
379  << NV("Caller", Caller)
380  << "' because it should never be inlined " << IC;
381  });
382  } else {
383  ORE.emit([&]() {
384  return OptimizationRemarkMissed(DEBUG_TYPE, "TooCostly", Call)
385  << "'" << NV("Callee", Callee) << "' not inlined into '"
386  << NV("Caller", Caller) << "' because too costly to inline "
387  << IC;
388  });
389  }
391  return None;
392  }
393 
394  int TotalSecondaryCost = 0;
395  if (EnableDeferral &&
396  shouldBeDeferred(Caller, IC, TotalSecondaryCost, GetInlineCost)) {
397  LLVM_DEBUG(dbgs() << " NOT Inlining: " << CB
398  << " Cost = " << IC.getCost()
399  << ", outer Cost = " << TotalSecondaryCost << '\n');
400  ORE.emit([&]() {
401  return OptimizationRemarkMissed(DEBUG_TYPE, "IncreaseCostInOtherContexts",
402  Call)
403  << "Not inlining. Cost of inlining '" << NV("Callee", Callee)
404  << "' increases the cost of inlining '" << NV("Caller", Caller)
405  << "' in other contexts";
406  });
407  setInlineRemark(CB, "deferred");
408  return None;
409  }
410 
411  LLVM_DEBUG(dbgs() << " Inlining " << inlineCostStr(IC) << ", Call: " << CB
412  << '\n');
413  return IC;
414 }
415 
417  const CallSiteFormat &Format) {
418  std::string Buffer;
419  raw_string_ostream CallSiteLoc(Buffer);
420  bool First = true;
421  for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {
422  if (!First)
423  CallSiteLoc << " @ ";
424  // Note that negative line offset is actually possible, but we use
425  // unsigned int to match line offset representation in remarks so
426  // it's directly consumable by relay advisor.
427  uint32_t Offset =
428  DIL->getLine() - DIL->getScope()->getSubprogram()->getLine();
429  uint32_t Discriminator = DIL->getBaseDiscriminator();
430  StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();
431  if (Name.empty())
432  Name = DIL->getScope()->getSubprogram()->getName();
433  CallSiteLoc << Name.str() << ":" << llvm::utostr(Offset);
434  if (Format.outputColumn())
435  CallSiteLoc << ":" << llvm::utostr(DIL->getColumn());
436  if (Format.outputDiscriminator() && Discriminator)
437  CallSiteLoc << "." << llvm::utostr(Discriminator);
438  First = false;
439  }
440 
441  return CallSiteLoc.str();
442 }
443 
445  if (!DLoc.get()) {
446  return;
447  }
448 
449  bool First = true;
450  Remark << " at callsite ";
451  for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {
452  if (!First)
453  Remark << " @ ";
454  unsigned int Offset = DIL->getLine();
455  Offset -= DIL->getScope()->getSubprogram()->getLine();
456  unsigned int Discriminator = DIL->getBaseDiscriminator();
457  StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();
458  if (Name.empty())
459  Name = DIL->getScope()->getSubprogram()->getName();
460  Remark << Name << ":" << ore::NV("Line", Offset) << ":"
461  << ore::NV("Column", DIL->getColumn());
462  if (Discriminator)
463  Remark << "." << ore::NV("Disc", Discriminator);
464  First = false;
465  }
466 
467  Remark << ";";
468 }
469 
471  OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block,
472  const Function &Callee, const Function &Caller, bool AlwaysInline,
473  function_ref<void(OptimizationRemark &)> ExtraContext,
474  const char *PassName) {
475  ORE.emit([&]() {
476  StringRef RemarkName = AlwaysInline ? "AlwaysInline" : "Inlined";
478  DLoc, Block);
479  Remark << "'" << ore::NV("Callee", &Callee) << "' inlined into '"
480  << ore::NV("Caller", &Caller) << "'";
481  if (ExtraContext)
482  ExtraContext(Remark);
484  return Remark;
485  });
486 }
487 
489  OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block,
490  const Function &Callee, const Function &Caller, const InlineCost &IC,
491  bool ForProfileContext, const char *PassName) {
493  ORE, DLoc, Block, Callee, Caller, IC.isAlways(),
494  [&](OptimizationRemark &Remark) {
495  if (ForProfileContext)
496  Remark << " to match profiling context";
497  Remark << " with " << IC;
498  },
499  PassName);
500 }
501 
503  : M(M), FAM(FAM) {
506  std::make_unique<ImportedFunctionsInliningStatistics>();
507  ImportedFunctionsStats->setModuleInfo(M);
508  }
509 }
510 
516  }
517 }
518 
519 std::unique_ptr<InlineAdvice> InlineAdvisor::getMandatoryAdvice(CallBase &CB,
520  bool Advice) {
521  return std::make_unique<MandatoryInlineAdvice>(this, CB, getCallerORE(CB),
522  Advice);
523 }
524 
528  auto &Callee = *CB.getCalledFunction();
529 
530  auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & {
532  };
533 
534  auto &TIR = FAM.getResult<TargetIRAnalysis>(Callee);
535 
536  auto TrivialDecision =
538 
539  if (TrivialDecision.hasValue()) {
540  if (TrivialDecision->isSuccess())
542  else
544  }
546 }
547 
548 std::unique_ptr<InlineAdvice> InlineAdvisor::getAdvice(CallBase &CB,
549  bool MandatoryOnly) {
550  if (!MandatoryOnly)
551  return getAdviceImpl(CB);
552  bool Advice = CB.getCaller() != CB.getCalledFunction() &&
555  return getMandatoryAdvice(CB, Advice);
556 }
557 
560 }
561 
564  const auto *IA = MAM.getCachedResult<InlineAdvisorAnalysis>(M);
565  if (!IA)
566  OS << "No Inline Advisor\n";
567  else
568  IA->getAdvisor()->print(OS);
569  return PreservedAnalyses::all();
570 }
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm::InlineCost::isAlways
bool isAlways() const
Definition: InlineCost.h:123
llvm::OuterAnalysisManagerProxy
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:1065
llvm::getReplayInlineAdvisor
std::unique_ptr< InlineAdvisor > getReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM, LLVMContext &Context, std::unique_ptr< InlineAdvisor > OriginalAdvisor, const ReplayInlinerSettings &ReplaySettings, bool EmitRemarks)
Definition: ReplayInlineAdvisor.cpp:79
llvm::InlineCost::getCost
int getCost() const
Get the inline cost estimate.
Definition: InlineCost.h:129
llvm::TargetIRAnalysis
Analysis pass providing the TargetTransformInfo.
Definition: TargetTransformInfo.h:2418
llvm::OptimizationRemarkMissed
Diagnostic information for missed-optimization remarks.
Definition: DiagnosticInfo.h:730
llvm::InlineAdvice::recordInlining
void recordInlining()
Exactly one of the record* APIs must be called.
Definition: InlineAdvisor.cpp:172
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
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:181
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:107
llvm::InlineAdvisor::M
Module & M
Definition: InlineAdvisor.h:179
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:783
DebugInfoMetadata.h
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:78
llvm::Function
Definition: Function.h:62
llvm::Attribute
Definition: Attributes.h:52
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:631
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:95
Statistic.h
llvm::InlineAdvisorAnalysisPrinterPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Definition: InlineAdvisor.cpp:563
llvm::InlineAdvice::Caller
Function *const Caller
Caller and Callee are pre-inlining.
Definition: InlineAdvisor.h:99
OptimizationRemarkEmitter.h
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
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:488
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1580
llvm::Function::getContext
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:321
llvm::Optional< llvm::InlineCost >
llvm::InlineParams
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:184
llvm::InlineAdvisor::MandatoryInliningKind::Always
@ Always
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
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:135
llvm::InlineCost::isNever
bool isNever() const
Definition: InlineCost.h:124
llvm::addLocationToRemarks
void addLocationToRemarks(OptimizationRemark &Remark, DebugLoc DLoc)
Add location info to ORE message.
Definition: InlineAdvisor.cpp:444
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:558
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
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:185
CommandLine.h
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition: BlockFrequencyInfo.h:37
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:470
llvm::InlineAdvice::IsInliningRecommended
const bool IsInliningRecommended
Definition: InlineAdvisor.h:108
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:2788
llvm::InlineAdvice::ORE
OptimizationRemarkEmitter & ORE
Definition: InlineAdvisor.h:107
llvm::User
Definition: User.h:44
llvm::DefaultInlineAdvisor
The default (manual heuristics) implementation of the InlineAdvisor.
Definition: InlineAdvisor.h:198
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1398
MAM
ModuleAnalysisManager MAM
Definition: PassBuilderBindings.cpp:61
llvm::InlineCost
Represents the cost of inlining a function.
Definition: InlineCost.h:81
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
TargetLibraryInfo.h
First
into llvm powi allowing the code generator to produce balanced multiplication trees First
Definition: README.txt:54
InlineAdvisor.h
llvm::Instruction
Definition: Instruction.h:45
llvm::CallBase::addFnAttr
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
Definition: InstrTypes.h:1505
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:53
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
llvm::BlockFrequencyAnalysis
Analysis pass which computes BlockFrequencyInfo.
Definition: BlockFrequencyInfo.h:112
llvm::None
const NoneType None
Definition: None.h:23
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:416
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:183
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:223
llvm::LLVMContext::getDiagHandlerPtr
const DiagnosticHandler * getDiagHandlerPtr() const
getDiagHandlerPtr - Returns const raw pointer of DiagnosticHandler set by setDiagnosticHandler.
Definition: LLVMContext.cpp:343
llvm::HighlightColor::Remark
@ Remark
llvm::Optional::getValueOr
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Definition: Optional.h:297
llvm::InlineAdvice
Capture state between an inlining decision having had been made, and its impact being observable.
Definition: InlineAdvisor.h:51
llvm::cl::opt< bool >
ReplayInlineAdvisor.h
llvm::InliningAdvisorMode
InliningAdvisorMode
There are 3 scenarios we can use the InlineAdvisor:
Definition: InlineAdvisor.h:41
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:229
llvm::DiagnosticInfoOptimizationBase::Argument
Used in the streaming interface as the general argument type.
Definition: DiagnosticInfo.h:422
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:152
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:578
llvm::InlineAdvice::recordInliningWithCalleeDeleted
void recordInliningWithCalleeDeleted()
Call after inlining succeeded, and results in the callee being delete-able, meaning,...
Definition: InlineAdvisor.cpp:178
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:72
llvm::DebugLoc::get
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:21
getCalledFunction
static const Function * getCalledFunction(const Value *V, bool &IsNoBuiltin)
Definition: MemoryBuiltins.cpp:117
llvm::InlineAdvice::Block
const BasicBlock *const Block
Definition: InlineAdvisor.h:106
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:441
llvm::InlineCost::getCostDelta
int getCostDelta() const
Get the cost delta from the threshold for inlining.
Definition: InlineCost.h:153
llvm::InlineAdvice::recordInliningImpl
virtual void recordInliningImpl()
Definition: InlineAdvisor.h:92
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::setInlineRemark
void setInlineRemark(CallBase &CB, StringRef Message)
Set the inline-remark attribute.
Definition: InlineAdvisor.cpp:343
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:105
InlineCost.h
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
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:109
llvm::InlineAdvisor::MandatoryInliningKind::NotMandatory
@ NotMandatory
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:57
llvm::CallSiteFormat
Definition: ReplayInlineAdvisor.h:21
llvm::InlineCost::getReason
const char * getReason() const
Get the reason of Always or Never.
Definition: InlineCost.h:144
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:140
getParent
static const Function * getParent(const Value *V)
Definition: BasicAliasAnalysis.cpp:870
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:93
InlinerFunctionImportStats
cl::opt< InlinerFunctionImportStatsOpts > InlinerFunctionImportStats
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:185
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:519
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:2836
llvm::InlineAdvisor::FAM
FunctionAnalysisManager & FAM
Definition: InlineAdvisor.h:180
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
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:548
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
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:802
llvm::Module::getContext
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:259
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:221
llvm::inlineCostStr
std::string inlineCostStr(const InlineCost &IC)
Utility for extracting the inline cost message to a string.
Definition: InlineAdvisor.cpp:336
llvm::InlineAdvisor::getMandatoryKind
static MandatoryInliningKind getMandatoryKind(CallBase &CB, FunctionAnalysisManager &FAM, OptimizationRemarkEmitter &ORE)
Definition: InlineAdvisor.cpp:526
llvm::OptimizationRemark
Diagnostic information for applied optimization remarks.
Definition: DiagnosticInfo.h:685
Instructions.h
llvm::InlineAdvisorAnalysis
The InlineAdvisorAnalysis is a module pass because the InlineAdvisor needs to capture state right bef...
Definition: InlineAdvisor.h:212
llvm::InlineConstants::LastCallToStaticBonus
const int LastCallToStaticBonus
Definition: InlineCost.h:47
llvm::InlineAdvisorAnalysis::Key
static AnalysisKey Key
Definition: InlineAdvisor.h:214
llvm::InliningAdvisorMode::Default
@ Default
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:94
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:160
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1176
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:940
llvm::InliningAdvisorMode::Release
@ Release
DEBUG_TYPE
#define DEBUG_TYPE
Definition: InlineAdvisor.cpp:29
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:412
raw_ostream.h
llvm::InlineParams::EnableDeferral
Optional< bool > EnableDeferral
Indicate whether we should allow inline deferral.
Definition: InlineCost.h:214
getDefaultInlineAdvice
static llvm::Optional< llvm::InlineCost > getDefaultInlineAdvice(CallBase &CB, FunctionAnalysisManager &FAM, const InlineParams &Params)
Definition: InlineAdvisor.cpp:119
llvm::raw_string_ostream::str
std::string & str()
Returns the string's reference.
Definition: raw_ostream.h:649
llvm::InlineAdvice::Advisor
InlineAdvisor *const Advisor
Definition: InlineAdvisor.h:97
llvm::OptimizationRemarkEmitterAnalysis
Definition: OptimizationRemarkEmitter.h:164
llvm::InlineResult
InlineResult is basically true or false.
Definition: InlineCost.h:158
llvm::InlineAdvice::Callee
Function *const Callee
Definition: InlineAdvisor.h:100
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:440
llvm::ReplayInlinerSettings
Replay Inliner Setup.
Definition: ReplayInlineAdvisor.h:43
llvm::InlineAdvisor::~InlineAdvisor
virtual ~InlineAdvisor()
Definition: InlineAdvisor.cpp:511
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:670
llvm::InlineAdvisorAnalysis::Result::tryCreate
bool tryCreate(InlineParams Params, InliningAdvisorMode Mode, const ReplayInlinerSettings &ReplaySettings)
Definition: InlineAdvisor.cpp:186
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:356