LLVM  16.0.0git
MLInlineAdvisor.cpp
Go to the documentation of this file.
1 //===- MLInlineAdvisor.cpp - machine learned InlineAdvisor ----------------===//
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 the interface between the inliner and a learned model.
10 // It delegates model evaluation to either the AOT compiled model (the
11 // 'release' mode) or a runtime-loaded model (the 'development' case).
12 //
13 //===----------------------------------------------------------------------===//
15 #include "llvm/ADT/SCCIterator.h"
22 #include "llvm/Analysis/LoopInfo.h"
26 #include "llvm/IR/Dominators.h"
27 #include "llvm/IR/InstIterator.h"
28 #include "llvm/IR/PassManager.h"
30 
31 using namespace llvm;
32 
33 #if defined(LLVM_HAVE_TF_AOT_INLINERSIZEMODEL)
35 // codegen-ed file
36 #include "InlinerSizeModel.h" // NOLINT
37 
38 std::unique_ptr<InlineAdvisor>
40  auto AOTRunner =
41  std::make_unique<ReleaseModeModelRunner<llvm::InlinerSizeModel>>(
42  M.getContext(), FeatureMap, DecisionName);
43  return std::make_unique<MLInlineAdvisor>(M, MAM, std::move(AOTRunner));
44 }
45 #endif
46 
47 #define DEBUG_TYPE "inline-ml"
48 
50  "ml-advisor-size-increase-threshold", cl::Hidden,
51  cl::desc("Maximum factor by which expected native size may increase before "
52  "blocking any further inlining."),
53  cl::init(2.0));
54 
56  "ml-advisor-keep-fpi-cache", cl::Hidden,
57  cl::desc(
58  "For test - keep the ML Inline advisor's FunctionPropertiesInfo cache"),
59  cl::init(false));
60 
61 // clang-format off
62 const std::array<TensorSpec, NumberOfFeatures> llvm::FeatureMap{
63 #define POPULATE_NAMES(_, NAME) TensorSpec::createSpec<int64_t>(NAME, {1} ),
64 // InlineCost features - these must come first
66 #undef POPULATE_NAMES
67 
68 // Non-cost features
69 #define POPULATE_NAMES(_, NAME, __) TensorSpec::createSpec<int64_t>(NAME, {1} ),
71 #undef POPULATE_NAMES
72 };
73 // clang-format on
74 
75 const char *const llvm::DecisionName = "inlining_decision";
76 const char *const llvm::DefaultDecisionName = "inlining_default";
77 const char *const llvm::RewardName = "delta_size";
78 
80  if (auto *CS = dyn_cast<CallBase>(&I))
81  if (Function *Callee = CS->getCalledFunction()) {
82  if (!Callee->isDeclaration()) {
83  return CS;
84  }
85  }
86  return nullptr;
87 }
88 
90  std::unique_ptr<MLModelRunner> Runner)
91  : InlineAdvisor(
92  M, MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager()),
93  ModelRunner(std::move(Runner)),
94  CG(MAM.getResult<LazyCallGraphAnalysis>(M)),
95  InitialIRSize(getModuleIRSize()), CurrentIRSize(InitialIRSize) {
97 
98  // Extract the 'call site height' feature - the position of a call site
99  // relative to the farthest statically reachable SCC node. We don't mutate
100  // this value while inlining happens. Empirically, this feature proved
101  // critical in behavioral cloning - i.e. training a model to mimic the manual
102  // heuristic's decisions - and, thus, equally important for training for
103  // improvement.
104  CallGraph CGraph(M);
105  for (auto I = scc_begin(&CGraph); !I.isAtEnd(); ++I) {
106  const std::vector<CallGraphNode *> &CGNodes = *I;
107  unsigned Level = 0;
108  for (auto *CGNode : CGNodes) {
109  Function *F = CGNode->getFunction();
110  if (!F || F->isDeclaration())
111  continue;
112  for (auto &I : instructions(F)) {
113  if (auto *CS = getInlinableCS(I)) {
114  auto *Called = CS->getCalledFunction();
115  auto Pos = FunctionLevels.find(&CG.get(*Called));
116  // In bottom up traversal, an inlinable callee is either in the
117  // same SCC, or to a function in a visited SCC. So not finding its
118  // level means we haven't visited it yet, meaning it's in this SCC.
119  if (Pos == FunctionLevels.end())
120  continue;
121  Level = std::max(Level, Pos->second + 1);
122  }
123  }
124  }
125  for (auto *CGNode : CGNodes) {
126  Function *F = CGNode->getFunction();
127  if (F && !F->isDeclaration())
128  FunctionLevels[&CG.get(*F)] = Level;
129  }
130  }
131  for (auto KVP : FunctionLevels) {
132  AllNodes.insert(KVP.first);
133  EdgeCount += getLocalCalls(KVP.first->getFunction());
134  }
135  NodeCount = AllNodes.size();
136 }
137 
139  return CG.lookup(F) ? FunctionLevels.at(CG.lookup(F)) : 0;
140 }
141 
143  if (!LastSCC || ForceStop)
144  return;
145  FPICache.clear();
146  // Function passes executed between InlinerPass runs may have changed the
147  // module-wide features.
148  // The cgscc pass manager rules are such that:
149  // - if a pass leads to merging SCCs, then the pipeline is restarted on the
150  // merged SCC
151  // - if a pass leads to splitting the SCC, then we continue with one of the
152  // splits
153  // This means that the NodesInLastSCC is a superset (not strict) of the nodes
154  // that subsequent passes would have processed
155  // - in addition, if new Nodes were created by a pass (e.g. CoroSplit),
156  // they'd be adjacent to Nodes in the last SCC. So we just need to check the
157  // boundary of Nodes in NodesInLastSCC for Nodes we haven't seen. We don't
158  // care about the nature of the Edge (call or ref).
159  NodeCount -= static_cast<int64_t>(NodesInLastSCC.size());
160  while (!NodesInLastSCC.empty()) {
161  const auto *N = *NodesInLastSCC.begin();
162  NodesInLastSCC.erase(N);
163  // The Function wrapped by N could have been deleted since we last saw it.
164  if (N->isDead()) {
165  assert(!N->getFunction().isDeclaration());
166  continue;
167  }
168  ++NodeCount;
169  EdgeCount += getLocalCalls(N->getFunction());
170  for (const auto &E : *(*N)) {
171  const auto *AdjNode = &E.getNode();
172  assert(!AdjNode->isDead() && !AdjNode->getFunction().isDeclaration());
173  auto I = AllNodes.insert(AdjNode);
174  if (I.second)
175  NodesInLastSCC.insert(AdjNode);
176  }
177  }
178 
179  EdgeCount -= EdgesOfLastSeenNodes;
180  EdgesOfLastSeenNodes = 0;
181 
182  // (Re)use NodesInLastSCC to remember the nodes in the SCC right now,
183  // in case the SCC is split before onPassExit and some nodes are split out
184  assert(NodesInLastSCC.empty());
185  for (const auto &N : *LastSCC)
186  NodesInLastSCC.insert(&N);
187 }
188 
190  // No need to keep this around - function passes will invalidate it.
191  if (!KeepFPICache)
192  FPICache.clear();
193  if (!LastSCC || ForceStop)
194  return;
195  // Keep track of the nodes and edges we last saw. Then, in onPassEntry,
196  // we update the node count and edge count from the subset of these nodes that
197  // survived.
198  EdgesOfLastSeenNodes = 0;
199 
200  // Check on nodes that were in SCC onPassEntry
201  for (auto I = NodesInLastSCC.begin(); I != NodesInLastSCC.end();) {
202  if ((*I)->isDead())
203  NodesInLastSCC.erase(*I++);
204  else
205  EdgesOfLastSeenNodes += getLocalCalls((*I++)->getFunction());
206  }
207 
208  // Check on nodes that may have got added to SCC
209  for (const auto &N : *LastSCC) {
210  assert(!N.isDead());
211  auto I = NodesInLastSCC.insert(&N);
212  if (I.second)
213  EdgesOfLastSeenNodes += getLocalCalls(N.getFunction());
214  }
215  assert(NodeCount >= NodesInLastSCC.size());
216  assert(EdgeCount >= EdgesOfLastSeenNodes);
217 }
218 
221 }
222 
223 // Update the internal state of the advisor, and force invalidate feature
224 // analysis. Currently, we maintain minimal (and very simple) global state - the
225 // number of functions and the number of static calls. We also keep track of the
226 // total IR size in this module, to stop misbehaving policies at a certain bloat
227 // factor (SizeIncreaseThreshold)
229  bool CalleeWasDeleted) {
230  assert(!ForceStop);
231  Function *Caller = Advice.getCaller();
232  Function *Callee = Advice.getCallee();
233  // The caller features aren't valid anymore.
234  {
238  PA.abandon<LoopAnalysis>();
239  FAM.invalidate(*Caller, PA);
240  }
241  Advice.updateCachedCallerFPI(FAM);
242  int64_t IRSizeAfter =
243  getIRSize(*Caller) + (CalleeWasDeleted ? 0 : Advice.CalleeIRSize);
244  CurrentIRSize += IRSizeAfter - (Advice.CallerIRSize + Advice.CalleeIRSize);
245  if (CurrentIRSize > SizeIncreaseThreshold * InitialIRSize)
246  ForceStop = true;
247 
248  // We can delta-update module-wide features. We know the inlining only changed
249  // the caller, and maybe the callee (by deleting the latter).
250  // Nodes are simple to update.
251  // For edges, we 'forget' the edges that the caller and callee used to have
252  // before inlining, and add back what they currently have together.
253  int64_t NewCallerAndCalleeEdges =
255 
256  if (CalleeWasDeleted)
257  --NodeCount;
258  else
259  NewCallerAndCalleeEdges +=
261  EdgeCount += (NewCallerAndCalleeEdges - Advice.CallerAndCalleeEdges);
262  assert(CurrentIRSize >= 0 && EdgeCount >= 0 && NodeCount >= 0);
263 }
264 
265 int64_t MLInlineAdvisor::getModuleIRSize() const {
266  int64_t Ret = 0;
267  for (auto &F : M)
268  if (!F.isDeclaration())
269  Ret += getIRSize(F);
270  return Ret;
271 }
272 
274  auto InsertPair =
275  FPICache.insert(std::make_pair(&F, FunctionPropertiesInfo()));
276  if (!InsertPair.second)
277  return InsertPair.first->second;
278  InsertPair.first->second = FAM.getResult<FunctionPropertiesAnalysis>(F);
279  return InsertPair.first->second;
280 }
281 
282 std::unique_ptr<InlineAdvice> MLInlineAdvisor::getAdviceImpl(CallBase &CB) {
283  if (auto Skip = getSkipAdviceIfUnreachableCallsite(CB))
284  return Skip;
285 
286  auto &Caller = *CB.getCaller();
287  auto &Callee = *CB.getCalledFunction();
288 
289  auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
291  };
292  auto &TIR = FAM.getResult<TargetIRAnalysis>(Callee);
293  auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(Caller);
294 
295  auto MandatoryKind = InlineAdvisor::getMandatoryKind(CB, FAM, ORE);
296  // If this is a "never inline" case, there won't be any changes to internal
297  // state we need to track, so we can just return the base InlineAdvice, which
298  // will do nothing interesting.
299  // Same thing if this is a recursive case.
300  if (MandatoryKind == InlineAdvisor::MandatoryInliningKind::Never ||
301  &Caller == &Callee)
302  return getMandatoryAdvice(CB, false);
303 
304  bool Mandatory =
306 
307  // If we need to stop, we won't want to track anymore any state changes, so
308  // we just return the base InlineAdvice, which acts as a noop.
309  if (ForceStop) {
310  ORE.emit([&] {
311  return OptimizationRemarkMissed(DEBUG_TYPE, "ForceStop", &CB)
312  << "Won't attempt inlining because module size grew too much.";
313  });
314  return std::make_unique<InlineAdvice>(this, CB, ORE, Mandatory);
315  }
316 
317  int CostEstimate = 0;
318  if (!Mandatory) {
319  auto IsCallSiteInlinable =
320  llvm::getInliningCostEstimate(CB, TIR, GetAssumptionCache);
321  if (!IsCallSiteInlinable) {
322  // We can't inline this for correctness reasons, so return the base
323  // InlineAdvice, as we don't care about tracking any state changes (which
324  // won't happen).
325  return std::make_unique<InlineAdvice>(this, CB, ORE, false);
326  }
327  CostEstimate = *IsCallSiteInlinable;
328  }
329 
330  const auto CostFeatures =
331  llvm::getInliningCostFeatures(CB, TIR, GetAssumptionCache);
332  if (!CostFeatures) {
333  return std::make_unique<InlineAdvice>(this, CB, ORE, false);
334  }
335 
336  if (Mandatory)
337  return getMandatoryAdvice(CB, true);
338 
339  auto NrCtantParams = 0;
340  for (auto I = CB.arg_begin(), E = CB.arg_end(); I != E; ++I) {
341  NrCtantParams += (isa<Constant>(*I));
342  }
343 
344  auto &CallerBefore = getCachedFPI(Caller);
345  auto &CalleeBefore = getCachedFPI(Callee);
346 
347  *ModelRunner->getTensor<int64_t>(FeatureIndex::CalleeBasicBlockCount) =
348  CalleeBefore.BasicBlockCount;
349  *ModelRunner->getTensor<int64_t>(FeatureIndex::CallSiteHeight) =
350  getInitialFunctionLevel(Caller);
351  *ModelRunner->getTensor<int64_t>(FeatureIndex::NodeCount) = NodeCount;
352  *ModelRunner->getTensor<int64_t>(FeatureIndex::NrCtantParams) = NrCtantParams;
353  *ModelRunner->getTensor<int64_t>(FeatureIndex::EdgeCount) = EdgeCount;
354  *ModelRunner->getTensor<int64_t>(FeatureIndex::CallerUsers) =
355  CallerBefore.Uses;
356  *ModelRunner->getTensor<int64_t>(
357  FeatureIndex::CallerConditionallyExecutedBlocks) =
358  CallerBefore.BlocksReachedFromConditionalInstruction;
359  *ModelRunner->getTensor<int64_t>(FeatureIndex::CallerBasicBlockCount) =
360  CallerBefore.BasicBlockCount;
361  *ModelRunner->getTensor<int64_t>(
362  FeatureIndex::CalleeConditionallyExecutedBlocks) =
363  CalleeBefore.BlocksReachedFromConditionalInstruction;
364  *ModelRunner->getTensor<int64_t>(FeatureIndex::CalleeUsers) =
365  CalleeBefore.Uses;
366  *ModelRunner->getTensor<int64_t>(FeatureIndex::CostEstimate) = CostEstimate;
367 
368  // Add the cost features
369  for (size_t I = 0;
370  I < static_cast<size_t>(InlineCostFeatureIndex::NumberOfFeatures); ++I) {
371  *ModelRunner->getTensor<int64_t>(inlineCostFeatureToMlFeature(
372  static_cast<InlineCostFeatureIndex>(I))) = CostFeatures->at(I);
373  }
374 
375  return getAdviceFromModel(CB, ORE);
376 }
377 
378 std::unique_ptr<MLInlineAdvice>
381  return std::make_unique<MLInlineAdvice>(
382  this, CB, ORE, static_cast<bool>(ModelRunner->evaluate<int64_t>()));
383 }
384 
385 std::unique_ptr<InlineAdvice>
386 MLInlineAdvisor::getSkipAdviceIfUnreachableCallsite(CallBase &CB) {
388  .isReachableFromEntry(CB.getParent()))
389  return std::make_unique<InlineAdvice>(this, CB, getCallerORE(CB), false);
390  return nullptr;
391 }
392 
393 std::unique_ptr<InlineAdvice> MLInlineAdvisor::getMandatoryAdvice(CallBase &CB,
394  bool Advice) {
395  // Make sure we track inlinings in all cases - mandatory or not.
396  if (auto Skip = getSkipAdviceIfUnreachableCallsite(CB))
397  return Skip;
398  if (Advice && !ForceStop)
399  return getMandatoryAdviceImpl(CB);
400 
401  // If this is a "never inline" case, there won't be any changes to internal
402  // state we need to track, so we can just return the base InlineAdvice, which
403  // will do nothing interesting.
404  // Same if we are forced to stop - we don't track anymore.
405  return std::make_unique<InlineAdvice>(this, CB, getCallerORE(CB), Advice);
406 }
407 
408 std::unique_ptr<MLInlineAdvice>
410  return std::make_unique<MLInlineAdvice>(this, CB, getCallerORE(CB), true);
411 }
412 
413 void MLInlineAdvisor::print(raw_ostream &OS) const {
414  OS << "[MLInlineAdvisor] Nodes: " << NodeCount << " Edges: " << EdgeCount
415  << " EdgesOfLastSeenNodes: " << EdgesOfLastSeenNodes << "\n";
416  OS << "[MLInlineAdvisor] FPI:\n";
417  for (auto I : FPICache) {
418  OS << I.first->getName() << ":\n";
419  I.second.print(OS);
420  OS << "\n";
421  }
422  OS << "\n";
423 }
424 
427  bool Recommendation)
428  : InlineAdvice(Advisor, CB, ORE, Recommendation),
429  CallerIRSize(Advisor->isForcedToStop() ? 0 : Advisor->getIRSize(*Caller)),
430  CalleeIRSize(Advisor->isForcedToStop() ? 0 : Advisor->getIRSize(*Callee)),
431  CallerAndCalleeEdges(Advisor->isForcedToStop()
432  ? 0
433  : (Advisor->getLocalCalls(*Caller) +
434  Advisor->getLocalCalls(*Callee))),
435  PreInlineCallerFPI(Advisor->getCachedFPI(*Caller)) {
436  if (Recommendation)
437  FPU.emplace(Advisor->getCachedFPI(*getCaller()), CB);
438 }
439 
440 void MLInlineAdvice::reportContextForRemark(
442  using namespace ore;
443  OR << NV("Callee", Callee->getName());
444  for (size_t I = 0; I < NumberOfFeatures; ++I)
445  OR << NV(FeatureMap[I].name(),
446  *getAdvisor()->getModelRunner().getTensor<int64_t>(I));
447  OR << NV("ShouldInline", isInliningRecommended());
448 }
449 
451  FPU->finish(FAM);
452 }
453 
455  ORE.emit([&]() {
456  OptimizationRemark R(DEBUG_TYPE, "InliningSuccess", DLoc, Block);
457  reportContextForRemark(R);
458  return R;
459  });
460  getAdvisor()->onSuccessfulInlining(*this, /*CalleeWasDeleted*/ false);
461 }
462 
464  ORE.emit([&]() {
465  OptimizationRemark R(DEBUG_TYPE, "InliningSuccessWithCalleeDeleted", DLoc,
466  Block);
467  reportContextForRemark(R);
468  return R;
469  });
470  getAdvisor()->onSuccessfulInlining(*this, /*CalleeWasDeleted*/ true);
471 }
472 
474  const InlineResult &Result) {
475  getAdvisor()->getCachedFPI(*Caller) = PreInlineCallerFPI;
476  ORE.emit([&]() {
477  OptimizationRemarkMissed R(DEBUG_TYPE, "InliningAttemptedAndUnsuccessful",
478  DLoc, Block);
479  reportContextForRemark(R);
480  return R;
481  });
482 }
484  assert(!FPU);
485  ORE.emit([&]() {
486  OptimizationRemarkMissed R(DEBUG_TYPE, "IniningNotAttempted", DLoc, Block);
487  reportContextForRemark(R);
488  return R;
489  });
490 }
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
SizeIncreaseThreshold
static cl::opt< float > SizeIncreaseThreshold("ml-advisor-size-increase-threshold", cl::Hidden, cl::desc("Maximum factor by which expected native size may increase before " "blocking any further inlining."), cl::init(2.0))
AssumptionCache.h
llvm::TargetIRAnalysis
Analysis pass providing the TargetTransformInfo.
Definition: TargetTransformInfo.h:2585
INLINE_COST_FEATURE_ITERATOR
#define INLINE_COST_FEATURE_ITERATOR(M)
Definition: InlineModelFeatureMaps.h:24
llvm::OptimizationRemarkMissed
Diagnostic information for missed-optimization remarks.
Definition: DiagnosticInfo.h:734
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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::ISD::OR
@ OR
Definition: ISDOpcodes.h:667
llvm::inlineCostFeatureToMlFeature
constexpr FeatureIndex inlineCostFeatureToMlFeature(InlineCostFeatureIndex Feature)
Definition: InlineModelFeatureMaps.h:125
llvm::MLInlineAdvisor::getLocalCalls
int64_t getLocalCalls(Function &F)
Definition: MLInlineAdvisor.cpp:219
llvm::InlineAdvisor::M
Module & M
Definition: InlineAdvisor.h:208
llvm::FeatureMap
const std::array< TensorSpec, NumberOfFeatures > FeatureMap
Definition: MLInlineAdvisor.cpp:62
SCCIterator.h
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:774
InstIterator.h
llvm::Function
Definition: Function.h:60
getFunction
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:236
llvm::AnalysisManager::invalidate
void invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Invalidate cached analyses for an IR unit.
Definition: PassManagerImpl.h:89
MLModelRunner.h
getInlinableCS
CallBase * getInlinableCS(Instruction &I)
Definition: MLInlineAdvisor.cpp:79
name
static const char * name
Definition: SMEABIPass.cpp:49
llvm::InlineAdvice::Caller
Function *const Caller
Caller and Callee are pre-inlining.
Definition: InlineAdvisor.h:122
OptimizationRemarkEmitter.h
llvm::CallGraph
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:72
llvm::PreservedAnalyses::abandon
void abandon()
Mark an analysis as abandoned.
Definition: PassManager.h:206
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:140
llvm::LazyCallGraph::lookup
Node * lookup(const Function &F) const
Lookup a function in the graph which has already been scanned and added.
Definition: LazyCallGraph.h:973
llvm::InlineAdvisor::MandatoryInliningKind::Always
@ Always
POPULATE_NAMES
#define POPULATE_NAMES(_, NAME)
llvm::ore::NV
DiagnosticInfoOptimizationBase::Argument NV
Definition: OptimizationRemarkEmitter.h:136
llvm::InlineAdvisor::MandatoryInliningKind::Never
@ Never
llvm::MLInlineAdvisor::ModelRunner
std::unique_ptr< MLModelRunner > ModelRunner
Definition: MLInlineAdvisor.h:64
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:119
llvm::CallBase::arg_begin
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
Definition: InstrTypes.h:1316
llvm::MLInlineAdvice::CalleeIRSize
const int64_t CalleeIRSize
Definition: MLInlineAdvisor.h:108
llvm::DiagnosticInfoOptimizationBase
Common features for diagnostics dealing with optimization remarks that are used by both IR and MIR pa...
Definition: DiagnosticInfo.h:413
llvm::MLInlineAdvice::recordInliningImpl
void recordInliningImpl() override
Definition: MLInlineAdvisor.cpp:454
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::MLInlineAdvice::getCallee
Function * getCallee() const
Definition: MLInlineAdvisor.h:105
llvm::InlineAdvisor::getCallerORE
OptimizationRemarkEmitter & getCallerORE(CallBase &CB)
Definition: InlineAdvisor.cpp:618
CommandLine.h
llvm::LazyCallGraph::SCC
An SCC of the call graph.
Definition: LazyCallGraph.h:419
llvm::DecisionName
const char *const DecisionName
Definition: MLInlineAdvisor.cpp:75
llvm::MLInlineAdvice::recordInliningWithCalleeDeletedImpl
void recordInliningWithCalleeDeletedImpl() override
Definition: MLInlineAdvisor.cpp:463
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::InlineAdvice::ORE
OptimizationRemarkEmitter & ORE
Definition: InlineAdvisor.h:130
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::MLInlineAdvice::recordUnsuccessfulInliningImpl
void recordUnsuccessfulInliningImpl(const InlineResult &Result) override
Definition: MLInlineAdvisor.cpp:473
llvm::InlineCostFeatureIndex
InlineCostFeatureIndex
Definition: InlineModelFeatureMaps.h:51
KeepFPICache
static cl::opt< bool > KeepFPICache("ml-advisor-keep-fpi-cache", cl::Hidden, cl::desc("For test - keep the ML Inline advisor's FunctionPropertiesInfo cache"), cl::init(false))
llvm::DefaultDecisionName
const char *const DefaultDecisionName
Definition: MLInlineAdvisor.cpp:76
llvm::Instruction
Definition: Instruction.h:42
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::MLInlineAdvice::getCaller
Function * getCaller() const
Definition: MLInlineAdvisor.h:104
LazyCallGraph.h
llvm::CallBase::getCaller
Function * getCaller()
Helper to get the caller (the parent function).
Definition: Instructions.cpp:284
LoopInfo.h
llvm::MLInlineAdvisor::getMandatoryAdviceImpl
virtual std::unique_ptr< MLInlineAdvice > getMandatoryAdviceImpl(CallBase &CB)
Definition: MLInlineAdvisor.cpp:409
llvm::LazyCallGraph::get
Node & get(Function &F)
Get a graph node for a given function, scanning it to populate the graph data as necessary.
Definition: LazyCallGraph.h:994
llvm::scc_begin
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
Definition: SCCIterator.h:232
llvm::InlineAdvice
Capture state between an inlining decision having had been made, and its impact being observable.
Definition: InlineAdvisor.h:74
llvm::cl::opt
Definition: CommandLine.h:1412
llvm::instructions
inst_range instructions(Function *F)
Definition: InstIterator.h:133
llvm::MLInlineAdvisor::MLInlineAdvisor
MLInlineAdvisor(Module &M, ModuleAnalysisManager &MAM, std::unique_ptr< MLModelRunner > ModelRunner)
Definition: MLInlineAdvisor.cpp:89
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
ReleaseModeModelRunner.h
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::InlineAdvice::Block
const BasicBlock *const Block
Definition: InlineAdvisor.h:129
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:447
llvm::MLInlineAdvisor::getMandatoryAdvice
std::unique_ptr< InlineAdvice > getMandatoryAdvice(CallBase &CB, bool Advice) override
Definition: MLInlineAdvisor.cpp:393
llvm::MLInlineAdvice::CallerAndCalleeEdges
const int64_t CallerAndCalleeEdges
Definition: MLInlineAdvisor.h:109
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1836
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::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::CallBase::arg_end
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
Definition: InstrTypes.h:1322
llvm::MLInlineAdvisor::getCachedFPI
FunctionPropertiesInfo & getCachedFPI(Function &) const
Definition: MLInlineAdvisor.cpp:273
llvm::InlineAdvice::isInliningRecommended
bool isInliningRecommended() const
Get the inlining recommendation.
Definition: InlineAdvisor.h:110
llvm::FunctionPropertiesAnalysis
Definition: FunctionPropertiesAnalysis.h:82
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: OptimizationRemarkEmitter.h:33
llvm::MLInlineAdvisor::getInitialFunctionLevel
unsigned getInitialFunctionLevel(const Function &F) const
Definition: MLInlineAdvisor.cpp:138
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
if
if(llvm_vc STREQUAL "") set(fake_version_inc "$
Definition: CMakeLists.txt:14
llvm::MLInlineAdvice::MLInlineAdvice
MLInlineAdvice(MLInlineAdvisor *Advisor, CallBase &CB, OptimizationRemarkEmitter &ORE, bool Recommendation)
Definition: MLInlineAdvisor.cpp:425
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:308
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:187
FunctionPropertiesAnalysis.h
llvm::MLInlineAdvice::updateCachedCallerFPI
void updateCachedCallerFPI(FunctionAnalysisManager &FAM) const
Definition: MLInlineAdvisor.cpp:450
llvm::InlineAdvisor::FAM
FunctionAnalysisManager & FAM
Definition: InlineAdvisor.h:209
std
Definition: BitVector.h:851
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
llvm::getInliningCostFeatures
Optional< InlineCostFeatures > getInliningCostFeatures(CallBase &Call, TargetTransformInfo &CalleeTTI, function_ref< AssumptionCache &(Function &)> GetAssumptionCache, function_ref< BlockFrequencyInfo &(Function &)> GetBFI=nullptr, ProfileSummaryInfo *PSI=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Get the expanded cost features.
Definition: InlineCost.cpp:2857
llvm::MLInlineAdvisor::onPassExit
void onPassExit(LazyCallGraph::SCC *SCC) override
This must be called when the Inliner pass is exited, as function passes may be run subsequently.
Definition: MLInlineAdvisor.cpp:189
llvm::LazyCallGraphAnalysis
An analysis pass which computes the call graph for a module.
Definition: LazyCallGraph.h:1257
PassManager.h
llvm::MLInlineAdvice::CallerIRSize
const int64_t CallerIRSize
Definition: MLInlineAdvisor.h:107
DEBUG_TYPE
#define DEBUG_TYPE
Definition: MLInlineAdvisor.cpp:47
llvm::InlineCostFeatureIndex::NumberOfFeatures
@ NumberOfFeatures
MLInlineAdvisor.h
llvm::MLInlineAdvisor::getIRSize
int64_t getIRSize(Function &F) const
Definition: MLInlineAdvisor.h:37
llvm::MLInlineAdvisor::onSuccessfulInlining
void onSuccessfulInlining(const MLInlineAdvice &Advice, bool CalleeWasDeleted)
Definition: MLInlineAdvisor.cpp:228
CallGraph.h
llvm::InlineAdvisor::getMandatoryKind
static MandatoryInliningKind getMandatoryKind(CallBase &CB, FunctionAnalysisManager &FAM, OptimizationRemarkEmitter &ORE)
Definition: InlineAdvisor.cpp:586
llvm::DominatorTreeAnalysis
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:267
llvm::getInliningCostEstimate
Optional< int > getInliningCostEstimate(CallBase &Call, TargetTransformInfo &CalleeTTI, function_ref< AssumptionCache &(Function &)> GetAssumptionCache, function_ref< BlockFrequencyInfo &(Function &)> GetBFI=nullptr, ProfileSummaryInfo *PSI=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Get the cost estimate ignoring thresholds.
Definition: InlineCost.cpp:2832
llvm::OptimizationRemark
Diagnostic information for applied optimization remarks.
Definition: DiagnosticInfo.h:689
llvm::MLInlineAdvisor
Definition: MLInlineAdvisor.h:27
Dominators.h
llvm::MLInlineAdvisor::getAdviceImpl
std::unique_ptr< InlineAdvice > getAdviceImpl(CallBase &CB) override
Definition: MLInlineAdvisor.cpp:282
N
#define N
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:91
TargetTransformInfo.h
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:931
InlineModelFeatureMaps.h
llvm::MLInlineAdvisor::getAdviceFromModel
virtual std::unique_ptr< MLInlineAdvice > getAdviceFromModel(CallBase &CB, OptimizationRemarkEmitter &ORE)
Definition: MLInlineAdvisor.cpp:379
llvm::cl::desc
Definition: CommandLine.h:413
llvm::NumberOfFeatures
constexpr size_t NumberOfFeatures
Definition: InlineModelFeatureMaps.h:129
INLINE_FEATURE_ITERATOR
#define INLINE_FEATURE_ITERATOR(M)
Definition: InlineModelFeatureMaps.h:83
llvm::FunctionPropertiesInfo
Definition: FunctionPropertiesAnalysis.h:26
llvm::MLInlineAdvice
InlineAdvice that tracks changes post inlining.
Definition: MLInlineAdvisor.h:93
llvm::InlineAdvice::Advisor
InlineAdvisor *const Advisor
Definition: InlineAdvisor.h:120
llvm::OptimizationRemarkEmitterAnalysis
Definition: OptimizationRemarkEmitter.h:164
llvm::InlineResult
InlineResult is basically true or false.
Definition: InlineCost.h:177
llvm::RewardName
const char *const RewardName
Definition: MLInlineAdvisor.cpp:77
llvm::InlineAdvice::Callee
Function *const Callee
Definition: InlineAdvisor.h:123
llvm::MLInlineAdvice::recordUnattemptedInliningImpl
void recordUnattemptedInliningImpl() override
Definition: MLInlineAdvisor.cpp:483
llvm::LoopAnalysis
Analysis pass that exposes the LoopInfo for a function.
Definition: LoopInfo.h:1268
llvm::FunctionPropertiesInfo::DirectCallsToDefinedFunctions
int64_t DirectCallsToDefinedFunctions
Number of direct calls made from this function to other functions defined in this module.
Definition: FunctionPropertiesAnalysis.h:63
llvm::MLInlineAdvisor::onPassEntry
void onPassEntry(LazyCallGraph::SCC *SCC) override
This must be called when the Inliner pass is entered, to allow the InlineAdvisor update internal stat...
Definition: MLInlineAdvisor.cpp:142