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"
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 // An integer used to limit the cost of inline deferral. The default negative
44 // number tells shouldBeDeferred to only take the secondary cost into account.
45 static cl::opt<int>
46  InlineDeferralScale("inline-deferral-scale",
47  cl::desc("Scale to limit the cost of inline deferral"),
48  cl::init(2), cl::Hidden);
49 
51 
52 void DefaultInlineAdvice::recordUnsuccessfulInliningImpl(
53  const InlineResult &Result) {
54  using namespace ore;
55  llvm::setInlineRemark(*OriginalCB, std::string(Result.getFailureReason()) +
56  "; " + inlineCostStr(*OIC));
57  ORE.emit([&]() {
58  return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
59  << "'" << NV("Callee", Callee) << "' is not inlined into '"
60  << "'" << NV("Caller", Caller)
61  << "': " << NV("Reason", Result.getFailureReason());
62  });
63 }
64 
65 void DefaultInlineAdvice::recordInliningWithCalleeDeletedImpl() {
66  if (EmitRemarks)
68 }
69 
70 void DefaultInlineAdvice::recordInliningImpl() {
71  if (EmitRemarks)
73 }
74 
76  CallBase &CB, FunctionAnalysisManager &FAM, const InlineParams &Params) {
77  Function &Caller = *CB.getCaller();
78  ProfileSummaryInfo *PSI =
80  .getCachedResult<ProfileSummaryAnalysis>(
81  *CB.getParent()->getParent()->getParent());
82 
84  auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
86  };
87  auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {
89  };
90  auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & {
92  };
93 
94  auto GetInlineCost = [&](CallBase &CB) {
96  auto &CalleeTTI = FAM.getResult<TargetIRAnalysis>(Callee);
97  bool RemarksEnabled =
99  DEBUG_TYPE);
100  return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, GetTLI,
101  GetBFI, PSI, RemarksEnabled ? &ORE : nullptr);
102  };
103  return llvm::shouldInline(CB, GetInlineCost, ORE,
104  Params.EnableDeferral.getValueOr(false));
105 }
106 
107 std::unique_ptr<InlineAdvice>
108 DefaultInlineAdvisor::getAdviceImpl(CallBase &CB) {
109  auto OIC = getDefaultInlineAdvice(CB, FAM, Params);
110  return std::make_unique<DefaultInlineAdvice>(
111  this, CB, OIC,
113 }
114 
118  : Advisor(Advisor), Caller(CB.getCaller()), Callee(CB.getCalledFunction()),
119  DLoc(CB.getDebugLoc()), Block(CB.getParent()), ORE(ORE),
121 
122 void InlineAdvisor::markFunctionAsDeleted(Function *F) {
123  assert((!DeletedFunctions.count(F)) &&
124  "Cannot put cause a function to become dead twice!");
125  DeletedFunctions.insert(F);
126 }
127 
129  for (auto *F : DeletedFunctions)
130  delete F;
131  DeletedFunctions.clear();
132 }
133 
134 void InlineAdvice::recordInlineStatsIfNeeded() {
136  Advisor->ImportedFunctionsStats->recordInline(*Caller, *Callee);
137 }
138 
140  markRecorded();
141  recordInlineStatsIfNeeded();
143 }
144 
146  markRecorded();
147  recordInlineStatsIfNeeded();
148  Advisor->markFunctionAsDeleted(Callee);
150 }
151 
153 
156  StringRef ReplayFile) {
157  auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
158  switch (Mode) {
160  LLVM_DEBUG(dbgs() << "Using default inliner heuristic.\n");
161  Advisor.reset(new DefaultInlineAdvisor(M, FAM, Params));
162  // Restrict replay to default advisor, ML advisors are stateful so
163  // replay will need augmentations to interleave with them correctly.
164  if (!ReplayFile.empty()) {
165  Advisor = std::make_unique<ReplayInlineAdvisor>(
166  M, FAM, M.getContext(), std::move(Advisor), ReplayFile,
167  /* EmitRemarks =*/true);
168  }
169  break;
171 #ifdef LLVM_HAVE_TF_API
172  LLVM_DEBUG(dbgs() << "Using development-mode inliner policy.\n");
173  Advisor =
174  llvm::getDevelopmentModeAdvisor(M, MAM, [&FAM, Params](CallBase &CB) {
175  auto OIC = getDefaultInlineAdvice(CB, FAM, Params);
176  return OIC.hasValue();
177  });
178 #endif
179  break;
181 #ifdef LLVM_HAVE_TF_AOT
182  LLVM_DEBUG(dbgs() << "Using release-mode inliner policy.\n");
183  Advisor = llvm::getReleaseModeAdvisor(M, MAM);
184 #endif
185  break;
186  }
187 
188  return !!Advisor;
189 }
190 
191 /// Return true if inlining of CB can block the caller from being
192 /// inlined which is proved to be more beneficial. \p IC is the
193 /// estimated inline cost associated with callsite \p CB.
194 /// \p TotalSecondaryCost will be set to the estimated cost of inlining the
195 /// caller if \p CB is suppressed for inlining.
196 static bool
197 shouldBeDeferred(Function *Caller, InlineCost IC, int &TotalSecondaryCost,
198  function_ref<InlineCost(CallBase &CB)> GetInlineCost) {
199  // For now we only handle local or inline functions.
200  if (!Caller->hasLocalLinkage() && !Caller->hasLinkOnceODRLinkage())
201  return false;
202  // If the cost of inlining CB is non-positive, it is not going to prevent the
203  // caller from being inlined into its callers and hence we don't need to
204  // defer.
205  if (IC.getCost() <= 0)
206  return false;
207  // Try to detect the case where the current inlining candidate caller (call
208  // it B) is a static or linkonce-ODR function and is an inlining candidate
209  // elsewhere, and the current candidate callee (call it C) is large enough
210  // that inlining it into B would make B too big to inline later. In these
211  // circumstances it may be best not to inline C into B, but to inline B into
212  // its callers.
213  //
214  // This only applies to static and linkonce-ODR functions because those are
215  // expected to be available for inlining in the translation units where they
216  // are used. Thus we will always have the opportunity to make local inlining
217  // decisions. Importantly the linkonce-ODR linkage covers inline functions
218  // and templates in C++.
219  //
220  // FIXME: All of this logic should be sunk into getInlineCost. It relies on
221  // the internal implementation of the inline cost metrics rather than
222  // treating them as truly abstract units etc.
223  TotalSecondaryCost = 0;
224  // The candidate cost to be imposed upon the current function.
225  int CandidateCost = IC.getCost() - 1;
226  // If the caller has local linkage and can be inlined to all its callers, we
227  // can apply a huge negative bonus to TotalSecondaryCost.
228  bool ApplyLastCallBonus = Caller->hasLocalLinkage() && !Caller->hasOneUse();
229  // This bool tracks what happens if we DO inline C into B.
230  bool InliningPreventsSomeOuterInline = false;
231  unsigned NumCallerUsers = 0;
232  for (User *U : Caller->users()) {
233  CallBase *CS2 = dyn_cast<CallBase>(U);
234 
235  // If this isn't a call to Caller (it could be some other sort
236  // of reference) skip it. Such references will prevent the caller
237  // from being removed.
238  if (!CS2 || CS2->getCalledFunction() != Caller) {
239  ApplyLastCallBonus = false;
240  continue;
241  }
242 
243  InlineCost IC2 = GetInlineCost(*CS2);
244  ++NumCallerCallersAnalyzed;
245  if (!IC2) {
246  ApplyLastCallBonus = false;
247  continue;
248  }
249  if (IC2.isAlways())
250  continue;
251 
252  // See if inlining of the original callsite would erase the cost delta of
253  // this callsite. We subtract off the penalty for the call instruction,
254  // which we would be deleting.
255  if (IC2.getCostDelta() <= CandidateCost) {
256  InliningPreventsSomeOuterInline = true;
257  TotalSecondaryCost += IC2.getCost();
258  NumCallerUsers++;
259  }
260  }
261 
262  if (!InliningPreventsSomeOuterInline)
263  return false;
264 
265  // If all outer calls to Caller would get inlined, the cost for the last
266  // one is set very low by getInlineCost, in anticipation that Caller will
267  // be removed entirely. We did not account for this above unless there
268  // is only one caller of Caller.
269  if (ApplyLastCallBonus)
270  TotalSecondaryCost -= InlineConstants::LastCallToStaticBonus;
271 
272  // If InlineDeferralScale is negative, then ignore the cost of primary
273  // inlining -- IC.getCost() multiplied by the number of callers to Caller.
274  if (InlineDeferralScale < 0)
275  return TotalSecondaryCost < IC.getCost();
276 
277  int TotalCost = TotalSecondaryCost + IC.getCost() * NumCallerUsers;
278  int Allowance = IC.getCost() * InlineDeferralScale;
279  return TotalCost < Allowance;
280 }
281 
282 namespace llvm {
284  return R << Arg.Val;
285 }
286 
287 template <class RemarkT>
288 RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
289  using namespace ore;
290  if (IC.isAlways()) {
291  R << "(cost=always)";
292  } else if (IC.isNever()) {
293  R << "(cost=never)";
294  } else {
295  R << "(cost=" << ore::NV("Cost", IC.getCost())
296  << ", threshold=" << ore::NV("Threshold", IC.getThreshold()) << ")";
297  }
298  if (const char *Reason = IC.getReason())
299  R << ": " << ore::NV("Reason", Reason);
300  return R;
301 }
302 } // namespace llvm
303 
304 std::string llvm::inlineCostStr(const InlineCost &IC) {
305  std::string Buffer;
306  raw_string_ostream Remark(Buffer);
307  Remark << IC;
308  return Remark.str();
309 }
310 
313  return;
314 
315  Attribute Attr = Attribute::get(CB.getContext(), "inline-remark", Message);
316  CB.addFnAttr(Attr);
317 }
318 
319 /// Return the cost only if the inliner should attempt to inline at the given
320 /// CallSite. If we return the cost, we will emit an optimisation remark later
321 /// using that cost, so we won't do so from this function. Return None if
322 /// inlining should not be attempted.
325  function_ref<InlineCost(CallBase &CB)> GetInlineCost,
326  OptimizationRemarkEmitter &ORE, bool EnableDeferral) {
327  using namespace ore;
328 
329  InlineCost IC = GetInlineCost(CB);
330  Instruction *Call = &CB;
332  Function *Caller = CB.getCaller();
333 
334  if (IC.isAlways()) {
335  LLVM_DEBUG(dbgs() << " Inlining " << inlineCostStr(IC)
336  << ", Call: " << CB << "\n");
337  return IC;
338  }
339 
340  if (!IC) {
341  LLVM_DEBUG(dbgs() << " NOT Inlining " << inlineCostStr(IC)
342  << ", Call: " << CB << "\n");
343  if (IC.isNever()) {
344  ORE.emit([&]() {
345  return OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline", Call)
346  << "'" << NV("Callee", Callee) << "' not inlined into '"
347  << NV("Caller", Caller)
348  << "' because it should never be inlined " << IC;
349  });
350  } else {
351  ORE.emit([&]() {
352  return OptimizationRemarkMissed(DEBUG_TYPE, "TooCostly", Call)
353  << "'" << NV("Callee", Callee) << "' not inlined into '"
354  << NV("Caller", Caller) << "' because too costly to inline "
355  << IC;
356  });
357  }
359  return None;
360  }
361 
362  int TotalSecondaryCost = 0;
363  if (EnableDeferral &&
364  shouldBeDeferred(Caller, IC, TotalSecondaryCost, GetInlineCost)) {
365  LLVM_DEBUG(dbgs() << " NOT Inlining: " << CB
366  << " Cost = " << IC.getCost()
367  << ", outer Cost = " << TotalSecondaryCost << '\n');
368  ORE.emit([&]() {
369  return OptimizationRemarkMissed(DEBUG_TYPE, "IncreaseCostInOtherContexts",
370  Call)
371  << "Not inlining. Cost of inlining '" << NV("Callee", Callee)
372  << "' increases the cost of inlining '" << NV("Caller", Caller)
373  << "' in other contexts";
374  });
375  setInlineRemark(CB, "deferred");
376  // IC does not bool() to false, so get an InlineCost that will.
377  // This will not be inspected to make an error message.
378  return None;
379  }
380 
381  LLVM_DEBUG(dbgs() << " Inlining " << inlineCostStr(IC) << ", Call: " << CB
382  << '\n');
383  return IC;
384 }
385 
387  std::string Buffer;
388  raw_string_ostream CallSiteLoc(Buffer);
389  bool First = true;
390  for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {
391  if (!First)
392  CallSiteLoc << " @ ";
393  // Note that negative line offset is actually possible, but we use
394  // unsigned int to match line offset representation in remarks so
395  // it's directly consumable by relay advisor.
396  uint32_t Offset =
397  DIL->getLine() - DIL->getScope()->getSubprogram()->getLine();
398  uint32_t Discriminator = DIL->getBaseDiscriminator();
399  StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();
400  if (Name.empty())
401  Name = DIL->getScope()->getSubprogram()->getName();
402  CallSiteLoc << Name.str() << ":" << llvm::utostr(Offset) << ":"
403  << llvm::utostr(DIL->getColumn());
404  if (Discriminator)
405  CallSiteLoc << "." << llvm::utostr(Discriminator);
406  First = false;
407  }
408 
409  return CallSiteLoc.str();
410 }
411 
413  if (!DLoc.get()) {
414  return;
415  }
416 
417  bool First = true;
418  Remark << " at callsite ";
419  for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {
420  if (!First)
421  Remark << " @ ";
422  unsigned int Offset = DIL->getLine();
423  Offset -= DIL->getScope()->getSubprogram()->getLine();
424  unsigned int Discriminator = DIL->getBaseDiscriminator();
425  StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();
426  if (Name.empty())
427  Name = DIL->getScope()->getSubprogram()->getName();
428  Remark << Name << ":" << ore::NV("Line", Offset) << ":"
429  << ore::NV("Column", DIL->getColumn());
430  if (Discriminator)
431  Remark << "." << ore::NV("Disc", Discriminator);
432  First = false;
433  }
434 
435  Remark << ";";
436 }
437 
439  const BasicBlock *Block, const Function &Callee,
440  const Function &Caller, const InlineCost &IC,
441  bool ForProfileContext, const char *PassName) {
442  ORE.emit([&]() {
443  bool AlwaysInline = IC.isAlways();
444  StringRef RemarkName = AlwaysInline ? "AlwaysInline" : "Inlined";
446  DLoc, Block);
447  Remark << "'" << ore::NV("Callee", &Callee) << "' inlined into '"
448  << ore::NV("Caller", &Caller) << "'";
449  if (ForProfileContext)
450  Remark << " to match profiling context";
451  Remark << " with " << IC;
453  return Remark;
454  });
455 }
456 
458  : M(M), FAM(FAM) {
461  std::make_unique<ImportedFunctionsInliningStatistics>();
462  ImportedFunctionsStats->setModuleInfo(M);
463  }
464 }
465 
471  }
472 
474 }
475 
476 std::unique_ptr<InlineAdvice> InlineAdvisor::getMandatoryAdvice(CallBase &CB,
477  bool Advice) {
478  return std::make_unique<InlineAdvice>(this, CB, getCallerORE(CB), Advice);
479 }
480 
484  auto &Callee = *CB.getCalledFunction();
485 
486  auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & {
488  };
489 
490  auto &TIR = FAM.getResult<TargetIRAnalysis>(Callee);
491 
492  auto TrivialDecision =
494 
495  if (TrivialDecision.hasValue()) {
496  if (TrivialDecision->isSuccess())
498  else
500  }
502 }
503 
504 std::unique_ptr<InlineAdvice> InlineAdvisor::getAdvice(CallBase &CB,
505  bool MandatoryOnly) {
506  if (!MandatoryOnly)
507  return getAdviceImpl(CB);
508  bool Advice = CB.getCaller() != CB.getCalledFunction() &&
511  return getMandatoryAdvice(CB, Advice);
512 }
513 
516 }
llvm::InlineCost::isAlways
bool isAlways() const
Definition: InlineCost.h:124
llvm::OuterAnalysisManagerProxy
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:1061
llvm::InlineCost::getCost
int getCost() const
Get the inline cost estimate.
Definition: InlineCost.h:130
llvm::TargetIRAnalysis
Analysis pass providing the TargetTransformInfo.
Definition: TargetTransformInfo.h:2331
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:139
llvm::InlineAdvisor::freeDeletedFunctions
void freeDeletedFunctions()
We may want to defer deleting functions to after the inlining for a whole module has finished.
Definition: InlineAdvisor.cpp:128
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
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::InlineAdvisorAnalysis::Result::tryCreate
bool tryCreate(InlineParams Params, InliningAdvisorMode Mode, StringRef ReplayFile)
Definition: InlineAdvisor.cpp:154
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::getCallSiteLocation
std::string getCallSiteLocation(DebugLoc DLoc)
get call site location as string
Definition: InlineAdvisor.cpp:386
llvm::InlineAdvisor::ImportedFunctionsStats
std::unique_ptr< ImportedFunctionsInliningStatistics > ImportedFunctionsStats
Definition: InlineAdvisor.h:168
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:166
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:779
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:61
llvm::Attribute
Definition: Attributes.h:52
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:625
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:92
Statistic.h
llvm::InlineAdvice::Caller
Function *const Caller
Caller and Callee are pre-inlining.
Definition: InlineAdvisor.h:95
OptimizationRemarkEmitter.h
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
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:185
llvm::InlineAdvisor::MandatoryInliningKind::Always
@ Always
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
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:136
llvm::InlineCost::isNever
bool isNever() const
Definition: InlineCost.h:125
llvm::addLocationToRemarks
void addLocationToRemarks(OptimizationRemark &Remark, DebugLoc DLoc)
Add location info to ORE message.
Definition: InlineAdvisor.cpp:412
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::InlineAdvisor::getCallerORE
OptimizationRemarkEmitter & getCallerORE(CallBase &CB)
Definition: InlineAdvisor.cpp:514
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:206
CommandLine.h
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition: BlockFrequencyInfo.h:37
llvm::InlinerFunctionImportStatsOpts::No
@ No
llvm::InlineAdvice::IsInliningRecommended
const bool IsInliningRecommended
Definition: InlineAdvisor.h:104
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:2753
llvm::InlineAdvice::ORE
OptimizationRemarkEmitter & ORE
Definition: InlineAdvisor.h:103
llvm::User
Definition: User.h:44
llvm::DefaultInlineAdvisor
The default (manual heuristics) implementation of the InlineAdvisor.
Definition: InlineAdvisor.h:200
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1393
llvm::InlineCost
Represents the cost of inlining a function.
Definition: InlineCost.h:82
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:1500
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::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
llvm::InlineAdvisor::MandatoryInliningKind
MandatoryInliningKind
Definition: InlineAdvisor.h:183
getCalledFunction
static const Function * getCalledFunction(const Value *V, bool LookThroughBitCast, bool &IsNoBuiltin)
Definition: MemoryBuiltins.cpp:118
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
llvm::emitInlinedInto
void emitInlinedInto(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.
Definition: InlineAdvisor.cpp:438
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::cl::opt< bool >
ReplayInlineAdvisor.h
llvm::InliningAdvisorMode
InliningAdvisorMode
There are 3 scenarios we can use the InlineAdvisor:
Definition: InlineAdvisor.h:39
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:197
llvm::DiagnosticInfoOptimizationBase::Argument
Used in the streaming interface as the general argument type.
Definition: DiagnosticInfo.h:422
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:572
llvm::InlineAdvice::recordInliningWithCalleeDeleted
void recordInliningWithCalleeDeleted()
Call after inlining succeeded, and resulted in deleting the callee.
Definition: InlineAdvisor.cpp:145
llvm::AssumptionAnalysis
A function analysis which provides an AssumptionCache.
Definition: AssumptionCache.h:169
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
llvm::InlineAdvice::Block
const BasicBlock *const Block
Definition: InlineAdvisor.h:102
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::InlineCost::getCostDelta
int getCostDelta() const
Get the cost delta from the threshold for inlining.
Definition: InlineCost.h:154
llvm::InlineAdvice::recordInliningImpl
virtual void recordInliningImpl()
Definition: InlineAdvisor.h:88
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::setInlineRemark
void setInlineRemark(CallBase &CB, StringRef Message)
Set the inline-remark attribute.
Definition: InlineAdvisor.cpp:311
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:101
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:67
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:58
llvm::InlineCost::getReason
const char * getReason() const
Get the reason of Always or Never.
Definition: InlineCost.h:145
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:41
llvm::InlineAdvisor
Interface for deciding whether to inline a call site or not.
Definition: InlineAdvisor.h:136
getParent
static const Function * getParent(const Value *V)
Definition: BasicAliasAnalysis.cpp:776
uint32_t
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:978
llvm::InlineAdvice::recordInliningWithCalleeDeletedImpl
virtual void recordInliningWithCalleeDeletedImpl()
Definition: InlineAdvisor.h:89
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:206
llvm::InlineAdvisor::getMandatoryAdvice
virtual std::unique_ptr< InlineAdvice > getMandatoryAdvice(CallBase &CB, bool Advice)
Definition: InlineAdvisor.cpp:476
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:2801
llvm::InlineAdvisor::FAM
FunctionAnalysisManager & FAM
Definition: InlineAdvisor.h:167
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
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:504
llvm::Module::getContext
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:261
llvm::InlineAdvisor::getAdviceImpl
virtual std::unique_ptr< InlineAdvice > getAdviceImpl(CallBase &CB)=0
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:219
llvm::inlineCostStr
std::string inlineCostStr(const InlineCost &IC)
Utility for extracting the inline cost message to a string.
Definition: InlineAdvisor.cpp:304
llvm::InlineAdvisor::getMandatoryKind
static MandatoryInliningKind getMandatoryKind(CallBase &CB, FunctionAnalysisManager &FAM, OptimizationRemarkEmitter &ORE)
Definition: InlineAdvisor.cpp:482
llvm::OptimizationRemark
Diagnostic information for applied optimization remarks.
Definition: DiagnosticInfo.h:685
Instructions.h
llvm::InlineConstants::LastCallToStaticBonus
const int LastCallToStaticBonus
Definition: InlineCost.h:48
llvm::InlineAdvisorAnalysis::Key
static AnalysisKey Key
Definition: InlineAdvisor.h:218
llvm::InliningAdvisorMode::Default
@ Default
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:94
TargetTransformInfo.h
llvm::InlineAdvice::InlineAdvice
InlineAdvice(InlineAdvisor *Advisor, CallBase &CB, OptimizationRemarkEmitter &ORE, bool IsInliningRecommended)
Definition: InlineAdvisor.cpp:115
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1161
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:936
llvm::InliningAdvisorMode::Release
@ Release
DEBUG_TYPE
#define DEBUG_TYPE
Definition: InlineAdvisor.cpp:28
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::cl::desc
Definition: CommandLine.h:414
raw_ostream.h
llvm::InlineParams::EnableDeferral
Optional< bool > EnableDeferral
Indicate whether we should allow inline deferral.
Definition: InlineCost.h:215
getDefaultInlineAdvice
static llvm::Optional< llvm::InlineCost > getDefaultInlineAdvice(CallBase &CB, FunctionAnalysisManager &FAM, const InlineParams &Params)
Definition: InlineAdvisor.cpp:75
llvm::raw_string_ostream::str
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
Definition: raw_ostream.h:643
llvm::InlineAdvice::Advisor
InlineAdvisor *const Advisor
Definition: InlineAdvisor.h:93
llvm::OptimizationRemarkEmitterAnalysis
Definition: OptimizationRemarkEmitter.h:164
llvm::InlineResult
InlineResult is basically true or false.
Definition: InlineCost.h:159
llvm::InlineAdvice::Callee
Function *const Callee
Definition: InlineAdvisor.h:96
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:438
llvm::InlineAdvisor::~InlineAdvisor
virtual ~InlineAdvisor()
Definition: InlineAdvisor.cpp:466
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:669
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:324