LLVM 24.0.0git
Inliner.cpp
Go to the documentation of this file.
1//===- Inliner.cpp - Code common to all inliners --------------------------===//
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 mechanics required to implement inlining without
10// missing any calls and updating the call graph. The decisions of which calls
11// are profitable to inline are implemented elsewhere.
12//
13//===----------------------------------------------------------------------===//
14
16#include "IPOOptions.h"
18#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/ScopeExit.h"
20#include "llvm/ADT/SetVector.h"
23#include "llvm/ADT/Statistic.h"
25#include "llvm/ADT/StringRef.h"
34#include "llvm/Analysis/Loads.h"
39#include "llvm/IR/Attributes.h"
40#include "llvm/IR/BasicBlock.h"
41#include "llvm/IR/DebugLoc.h"
44#include "llvm/IR/Function.h"
46#include "llvm/IR/Instruction.h"
49#include "llvm/IR/Metadata.h"
50#include "llvm/IR/Module.h"
51#include "llvm/IR/PassManager.h"
52#include "llvm/IR/Value.h"
53#include "llvm/Pass.h"
56#include "llvm/Support/Debug.h"
62#include <algorithm>
63#include <cassert>
64#include <utility>
65
66using namespace llvm;
67
68#define DEBUG_TYPE "inline"
69
70STATISTIC(NumInlined, "Number of functions inlined");
71STATISTIC(NumDeleted, "Number of functions deleted because all callers found");
72
73/// Allows printing the contents of the advisor after each SCC inliner pass.
74static cl::opt<bool>
75 EnablePostSCCAdvisorPrinting("enable-scc-inline-advisor-printing",
76 cl::init(false), cl::Hidden);
77
79InlinerPass::getAdvisor(const ModuleAnalysisManagerCGSCCProxy::Result &MAM,
81 if (OwnedAdvisor)
82 return *OwnedAdvisor;
83
84 auto *IAA = MAM.getCachedResult<InlineAdvisorAnalysis>(M);
85 if (!IAA) {
86 // It should still be possible to run the inliner as a stand-alone SCC pass,
87 // for test scenarios. In that case, we default to the
88 // DefaultInlineAdvisor, which doesn't need to keep state between SCC pass
89 // runs. It also uses just the default InlineParams.
90 // In this case, we need to use the provided FAM, which is valid for the
91 // duration of the inliner pass, and thus the lifetime of the owned advisor.
92 // The one we would get from the MAM can be invalidated as a result of the
93 // inliner's activity.
94 OwnedAdvisor = std::make_unique<DefaultInlineAdvisor>(
95 M, FAM, getInlineParams(M.getContext()),
96 InlineContext{LTOPhase, InlinePass::CGSCCInliner});
97
98 const IPOOptions &Opts = getIPOOptions(M);
99 if (!Opts.cgscc_inline_replay.empty())
100 OwnedAdvisor = getReplayInlineAdvisor(
101 M, FAM, M.getContext(), std::move(OwnedAdvisor),
102 ReplayInlinerSettings{Opts.cgscc_inline_replay,
103 Opts.cgscc_inline_replay_scope,
104 Opts.cgscc_inline_replay_fallback,
105 {Opts.cgscc_inline_replay_format}},
106 /*EmitRemarks=*/true,
107 InlineContext{LTOPhase, InlinePass::ReplayCGSCCInliner});
108
109 return *OwnedAdvisor;
110 }
111 assert(IAA->getAdvisor() &&
112 "Expected a present InlineAdvisorAnalysis also have an "
113 "InlineAdvisor initialized");
114 return *IAA->getAdvisor();
115}
116
118 F.dropAllReferences();
120 BB.eraseFromParent();
121 BasicBlock *BB = BasicBlock::Create(F.getContext(), "", &F);
122 new UnreachableInst(F.getContext(), BB);
123}
124
127 CGSCCUpdateResult &UR) {
128 const auto &MAMProxy =
130 bool Changed = false;
131
132 assert(InitialC.size() > 0 && "Cannot handle an empty SCC!");
133 Module &M = *InitialC.begin()->getFunction().getParent();
134 const IPOOptions &Opts = getIPOOptions(M);
135 ProfileSummaryInfo *PSI = MAMProxy.getCachedResult<ProfileSummaryAnalysis>(M);
136
139 .getManager();
140
141 InlineAdvisor &Advisor = getAdvisor(MAMProxy, FAM, M);
142 Advisor.onPassEntry(&InitialC);
143
144 // We use a single common worklist for calls across the entire SCC. We
145 // process these in-order and append new calls introduced during inlining to
146 // the end. The PriorityInlineOrder is optional here, in which the smaller
147 // callee would have a higher priority to inline.
148 //
149 // Note that this particular order of processing is actually critical to
150 // avoid very bad behaviors. Consider *highly connected* call graphs where
151 // each function contains a small amount of code and a couple of calls to
152 // other functions. Because the LLVM inliner is fundamentally a bottom-up
153 // inliner, it can handle gracefully the fact that these all appear to be
154 // reasonable inlining candidates as it will flatten things until they become
155 // too big to inline, and then move on and flatten another batch.
156 //
157 // However, when processing call edges *within* an SCC we cannot rely on this
158 // bottom-up behavior. As a consequence, with heavily connected *SCCs* of
159 // functions we can end up incrementally inlining N calls into each of
160 // N functions because each incremental inlining decision looks good and we
161 // don't have a topological ordering to prevent explosions.
162 //
163 // To compensate for this, we don't process transitive edges made immediate
164 // by inlining until we've done one pass of inlining across the entire SCC.
165 // Large, highly connected SCCs still lead to some amount of code bloat in
166 // this model, but it is uniformly spread across all the functions in the SCC
167 // and eventually they all become too large to inline, rather than
168 // incrementally making a single function grow in a super linear fashion.
170
171 // Populate the initial list of calls in this SCC.
172 for (auto &N : InitialC) {
173 auto &ORE =
174 FAM.getResult<OptimizationRemarkEmitterAnalysis>(N.getFunction());
175 // We want to generally process call sites top-down in order for
176 // simplifications stemming from replacing the call with the returned value
177 // after inlining to be visible to subsequent inlining decisions.
178 // FIXME: Using instructions sequence is a really bad way to do this.
179 // Instead we should do an actual RPO walk of the function body.
180 for (Instruction &I : instructions(N.getFunction()))
181 if (auto *CB = dyn_cast<CallBase>(&I))
182 if (Function *Callee = CB->getCalledFunction()) {
183 if (!Callee->isDeclaration())
184 Calls.push_back(CB);
185 else if (!isa<IntrinsicInst>(I)) {
186 using namespace ore;
187 setInlineRemark(*CB, "unavailable definition");
188 ORE.emit([&]() {
189 return OptimizationRemarkMissed(DEBUG_TYPE, "NoDefinition", &I)
190 << NV("Callee", Callee) << " will not be inlined into "
191 << NV("Caller", CB->getCaller())
192 << " because its definition is unavailable"
193 << setIsVerbose();
194 });
195 }
196 }
197 }
198
199 // Capture updatable variable for the current SCC.
200 auto *C = &InitialC;
201
202 llvm::scope_exit AdvisorOnExit([&] { Advisor.onPassExit(C); });
203
204 if (Calls.empty())
205 return PreservedAnalyses::all();
206
207 // Track a set vector of inlined callees so that we can augment the caller
208 // with all of their edges in the call graph before pruning out the ones that
209 // got simplified away.
210 SmallSetVector<Function *, 4> InlinedCallees;
211
212 // Track the dead functions to delete once finished with inlining calls. We
213 // defer deleting these to make it easier to handle the call graph updates.
214 SmallVector<Function *, 4> DeadFunctions;
215
216 // Track potentially dead non-local functions with comdats to see if they can
217 // be deleted as a batch after inlining.
218 SmallVector<Function *, 4> DeadFunctionsInComdats;
219
220 // Loop forward over all of the calls. Note that we cannot cache the size as
221 // inlining can introduce new calls that need to be processed.
222 for (int I = 0; I < (int)Calls.size(); ++I) {
223 // We expect the calls to typically be batched with sequences of calls that
224 // have the same caller, so we first set up some shared infrastructure for
225 // this caller. We also do any pruning we can at this layer on the caller
226 // alone.
227 Function &F = *Calls[I]->getCaller();
229 if (CG.lookupSCC(N) != C)
230 continue;
231
232 LLVM_DEBUG(dbgs() << "Inlining calls in: " << F.getName() << "\n"
233 << " Function size: " << F.getInstructionCount()
234 << "\n");
235
236 auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
237 return FAM.getResult<AssumptionAnalysis>(F);
238 };
239
240 // Now process as many calls as we have within this caller in the sequence.
241 // We bail out as soon as the caller has to change so we can update the
242 // call graph and prepare the context of that new caller.
243 bool DidInline = false;
244 for (; I < (int)Calls.size() && Calls[I]->getCaller() == &F; ++I) {
245 CallBase *CB = Calls[I];
246 Function &Callee = *CB->getCalledFunction();
247
248 // Check if this inlining may repeat breaking an SCC apart that has
249 // already been split once before. In that case, inlining here may
250 // trigger infinite inlining, much like is prevented within the inliner
251 // itself by the InlineHistory above, but spread across CGSCC iterations
252 // and thus hidden from the full inline history.
253 LazyCallGraph::Node &CalleeN = *CG.lookup(Callee);
254 LazyCallGraph::SCC *CalleeSCC = CG.lookupSCC(CalleeN);
255 if (CalleeSCC == C && UR.InlinedInternalEdges.count({&N, C})) {
256 LLVM_DEBUG(dbgs() << "Skipping inlining internal SCC edge from a node "
257 "previously split out of this SCC by inlining: "
258 << F.getName() << " -> " << Callee.getName() << "\n");
259 setInlineRemark(*CB, "recursive SCC split");
260 continue;
261 }
262
263 // Store-to-load forwarding, loads can be sometimes simplified to
264 // constants from stores introduced by previous inlining
265 if (DidInline) {
266 for (Value *Arg : CB->args()) {
267 auto *LI = dyn_cast<LoadInst>(Arg);
268 if (!LI || !LI->isSimple())
269 continue;
270 BasicBlock::iterator BBI = LI->getIterator();
272 LI, LI->getParent(), BBI, Opts.inliner_forwarding_scan_limit);
273 if (!Available)
274 continue;
276 if (!C)
277 continue;
278 // Handle type mismatches from memset forwarding (e.g. memset
279 // writes i64 0 but the load type is ptr).
280 if (C->getType() != LI->getType()) {
281 if (C->isNullValue())
282 C = Constant::getNullValue(LI->getType());
283 else
284 continue;
285 }
286 LI->replaceAllUsesWith(C);
287 LI->eraseFromParent();
288 }
289 }
290
291 std::unique_ptr<InlineAdvice> Advice =
292 Advisor.getAdvice(*CB, OnlyMandatory);
293
294 // Check whether we want to inline this callsite.
295 if (!Advice)
296 continue;
297
298 if (!Advice->isInliningRecommended()) {
299 Advice->recordUnattemptedInlining();
300 continue;
301 }
302
303 int CBCostMult =
306 .value_or(1);
307
308 // Setup the data structure used to plumb customization into the
309 // `InlineFunction` routine.
311 GetAssumptionCache, PSI,
312 &FAM.getResult<BlockFrequencyAnalysis>(*(CB->getCaller())),
313 &FAM.getResult<BlockFrequencyAnalysis>(Callee));
314
315 // For compile time reasons we try to only track inline history for the
316 // calls where it may actually prevent inlining, which is inlining through
317 // an SCC. This can happen if the callee is in a non-trivial SCC/RefSCC,
318 // or if an inlined call site was an indirect call, which can be
319 // devirtualized to call any target by replacing the indirectly called
320 // function with a function pointer referenced by the caller. The indirect
321 // call case is handled within InlineFunction.
322 bool TrackInlineHistory = CalleeSCC->size() != 1 ||
323 CalleeSCC->getOuterRefSCC().size() != 1 ||
324 CalleeN->lookup(CalleeN) != nullptr;
325
327 *CB, IFI, /*MergeAttributes=*/true,
328 &FAM.getResult<AAManager>(*CB->getCaller()), /*InsertLifetime=*/true,
329 TrackInlineHistory, nullptr,
331 if (!IR.isSuccess()) {
332 Advice->recordUnsuccessfulInlining(IR);
333 continue;
334 }
335 // TODO: Shouldn't we be invalidating all analyses on F here?
336 // The caller was modified, so invalidate Ephemeral Values.
337 FAM.getResult<EphemeralValuesAnalysis>(F).clear();
338
339 DidInline = true;
340 InlinedCallees.insert(&Callee);
341 ++NumInlined;
342
343 LLVM_DEBUG(dbgs() << " Size after inlining: "
344 << F.getInstructionCount() << "\n");
345
346 // Add any new callsites to defined functions to the worklist.
347 if (!IFI.InlinedCallSites.empty()) {
348 for (CallBase *ICB : reverse(IFI.InlinedCallSites)) {
349 Function *NewCallee = ICB->getCalledFunction();
350 assert(!(NewCallee && NewCallee->isIntrinsic()) &&
351 "Intrinsic calls should not be tracked.");
352 if (!NewCallee) {
353 // Try to promote an indirect (virtual) call without waiting for
354 // the post-inline cleanup and the next DevirtSCCRepeatedPass
355 // iteration because the next iteration may not happen and we may
356 // miss inlining it.
357 if (tryPromoteCall(*ICB))
358 NewCallee = ICB->getCalledFunction();
359 }
360 if (NewCallee) {
361 if (!NewCallee->isDeclaration()) {
362 Calls.push_back(ICB);
363 // Continually inlining through an SCC can result in huge compile
364 // times and bloated code since we arbitrarily stop at some point
365 // when the inliner decides it's not profitable to inline anymore.
366 // We attempt to mitigate this by making these calls exponentially
367 // more expensive.
368 // This doesn't apply to calls in the same SCC since if we do
369 // inline through the SCC the function will end up being
370 // self-recursive which the inliner bails out on, and inlining
371 // within an SCC is necessary for performance.
372 if (CalleeSCC != C &&
373 CalleeSCC == CG.lookupSCC(CG.get(*NewCallee))) {
374 Attribute NewCBCostMult = Attribute::get(
375 M.getContext(),
377 itostr(CBCostMult * Opts.intra_scc_cost_multiplier));
378 ICB->addFnAttr(NewCBCostMult);
379 }
380 }
381 }
382 }
383 }
384
385 // For local functions or discardable functions without comdats, check
386 // whether this makes the callee trivially dead. In that case, we can drop
387 // the body of the function eagerly which may reduce the number of callers
388 // of other functions to one, changing inline cost thresholds. Non-local
389 // discardable functions with comdats are checked later on.
390 bool CalleeWasDeleted = false;
391 if (Callee.isDiscardableIfUnused() && Callee.hasZeroLiveUses() &&
392 !CG.isLibFunction(Callee)) {
393 if (Callee.hasLocalLinkage() || !Callee.hasComdat()) {
394 Calls.erase(std::remove_if(Calls.begin() + I + 1, Calls.end(),
395 [&](const CallBase *CB) {
396 return CB->getCaller() == &Callee;
397 }),
398 Calls.end());
399
400 // Report inlining decision BEFORE deleting function contents, so we
401 // can still access e.g. the DebugLoc
402 Advice->recordInliningWithCalleeDeleted();
403 // Clear the body and queue the function itself for call graph
404 // updating when we finish inlining.
406 assert(!is_contained(DeadFunctions, &Callee) &&
407 "Cannot put cause a function to become dead twice!");
408 DeadFunctions.push_back(&Callee);
409 CalleeWasDeleted = true;
410 } else {
411 DeadFunctionsInComdats.push_back(&Callee);
412 }
413 }
414 if (!CalleeWasDeleted)
415 Advice->recordInlining();
416 }
417
418 // Back the call index up by one to put us in a good position to go around
419 // the outer loop.
420 --I;
421
422 if (!DidInline)
423 continue;
424 Changed = true;
425
426 // At this point, since we have made changes we have at least removed
427 // a call instruction. However, in the process we do some incremental
428 // simplification of the surrounding code. This simplification can
429 // essentially do all of the same things as a function pass and we can
430 // re-use the exact same logic for updating the call graph to reflect the
431 // change.
432
433 // Inside the update, we also update the FunctionAnalysisManager in the
434 // proxy for this particular SCC. We do this as the SCC may have changed and
435 // as we're going to mutate this particular function we want to make sure
436 // the proxy is in place to forward any invalidation events.
437 LazyCallGraph::SCC *OldC = C;
439 LLVM_DEBUG(dbgs() << "Updated inlining SCC: " << *C << "\n");
440
441 // If this causes an SCC to split apart into multiple smaller SCCs, there
442 // is a subtle risk we need to prepare for. Other transformations may
443 // expose an "infinite inlining" opportunity later, and because of the SCC
444 // mutation, we will revisit this function and potentially re-inline. If we
445 // do, and that re-inlining also has the potentially to mutate the SCC
446 // structure, the infinite inlining problem can manifest through infinite
447 // SCC splits and merges. To avoid this, we capture the originating caller
448 // node and the SCC containing the call edge. This is a slight over
449 // approximation of the possible inlining decisions that must be avoided,
450 // but is relatively efficient to store. We use C != OldC to know when
451 // a new SCC is generated and the original SCC may be generated via merge
452 // in later iterations.
453 //
454 // It is also possible that even if no new SCC is generated
455 // (i.e., C == OldC), the original SCC could be split and then merged
456 // into the same one as itself. and the original SCC will be added into
457 // UR.CWorklist again, we want to catch such cases too.
458 //
459 // FIXME: This seems like a very heavyweight way of retaining the inline
460 // history, we should look for a more efficient way of tracking it.
461 if ((C != OldC || UR.CWorklist.count(OldC)) &&
462 llvm::any_of(InlinedCallees, [&](Function *Callee) {
463 return CG.lookupSCC(*CG.lookup(*Callee)) == OldC;
464 })) {
465 LLVM_DEBUG(dbgs() << "Inlined an internal call edge and split an SCC, "
466 "retaining this to avoid infinite inlining.\n");
467 UR.InlinedInternalEdges.insert({&N, OldC});
468 }
469 InlinedCallees.clear();
470
471 // Invalidate analyses for this function now so that we don't have to
472 // invalidate analyses for all functions in this SCC later.
473 FAM.invalidate(F, PreservedAnalyses::none());
474 }
475
476 // We must ensure that we only delete functions with comdats if every function
477 // in the comdat is going to be deleted.
478 if (!DeadFunctionsInComdats.empty()) {
479 filterDeadComdatFunctions(DeadFunctionsInComdats);
480 for (auto *Callee : DeadFunctionsInComdats)
482 DeadFunctions.append(DeadFunctionsInComdats);
483 }
484
485 // Now that we've finished inlining all of the calls across this SCC, delete
486 // all of the trivially dead functions, updating the call graph and the CGSCC
487 // pass manager in the process.
488 //
489 // Note that this walks a pointer set which has non-deterministic order but
490 // that is OK as all we do is delete things and add pointers to unordered
491 // sets.
492 for (Function *DeadF : DeadFunctions) {
493 CG.markDeadFunction(*DeadF);
494 // Get the necessary information out of the call graph and nuke the
495 // function there. Also, clear out any cached analyses.
496 auto &DeadC = *CG.lookupSCC(*CG.lookup(*DeadF));
497 FAM.clear(*DeadF, DeadF->getName());
498 AM.clear(DeadC, DeadC.getName());
499
500 // Mark the relevant parts of the call graph as invalid so we don't visit
501 // them.
502 UR.InvalidatedSCCs.insert(&DeadC);
503
504 UR.DeadFunctions.push_back(DeadF);
505
506 ++NumDeleted;
507 }
508
509 if (!Changed)
510 return PreservedAnalyses::all();
511
513 // Even if we change the IR, we update the core CGSCC data structures and so
514 // can preserve the proxy to the function analysis manager.
516 // We have already invalidated all analyses on modified functions.
518 return PA;
519}
520
522 bool MandatoryFirst,
523 InlineContext IC,
525 unsigned MaxDevirtIterations)
526 : Params(Params), IC(IC), Mode(Mode),
527 MaxDevirtIterations(MaxDevirtIterations) {
528 // Run the inliner first. The theory is that we are walking bottom-up and so
529 // the callees have already been fully optimized, and we want to inline them
530 // into the callers so that our optimizations can reflect that.
531 // For PreLinkThinLTO pass, we disable hot-caller heuristic for sample PGO
532 // because it makes profile annotation in the backend inaccurate.
533 if (MandatoryFirst) {
534 PM.addPass(InlinerPass(/*OnlyMandatory*/ true));
537 }
538 PM.addPass(InlinerPass());
541}
542
545 auto &IAA = MAM.getResult<InlineAdvisorAnalysis>(M);
546 const IPOOptions &Opts = getIPOOptions(M);
547 if (!IAA.tryCreate(Params, Mode,
548 {Opts.cgscc_inline_replay,
549 Opts.cgscc_inline_replay_scope,
550 Opts.cgscc_inline_replay_fallback,
551 {Opts.cgscc_inline_replay_format}},
552 IC)) {
553 M.getContext().emitError(
554 "Could not setup Inlining Advisor for the requested "
555 "mode and/or options");
556 return PreservedAnalyses::all();
557 }
558
559 // We wrap the CGSCC pipeline in a devirtualization repeater. This will try
560 // to detect when we devirtualize indirect calls and iterate the SCC passes
561 // in that case to try and catch knock-on inlining or function attrs
562 // opportunities. Then we add it to the module pipeline by walking the SCCs
563 // in postorder (or bottom-up).
564 // If MaxDevirtIterations is 0, we just don't use the devirtualization
565 // wrapper.
566 if (MaxDevirtIterations == 0)
567 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(PM)));
568 else
570 createDevirtSCCRepeatedPass(std::move(PM), MaxDevirtIterations)));
571
572 MPM.addPass(std::move(AfterCGMPM));
573 MPM.run(M, MAM);
574
575 // Discard the InlineAdvisor, a subsequent inlining session should construct
576 // its own.
577 auto PA = PreservedAnalyses::all();
578 if (!Opts.keep_inline_advisor_for_printing)
579 PA.abandon<InlineAdvisorAnalysis>();
580 return PA;
581}
582
584 raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
585 static_cast<PassInfoMixin<InlinerPass> *>(this)->printPipeline(
586 OS, MapClassName2PassName);
587 if (OnlyMandatory)
588 OS << "<only-mandatory>";
589}
590
592 raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
593 // Print some info about passes added to the wrapper. This is however
594 // incomplete as InlineAdvisorAnalysis part isn't included (which also depends
595 // on Params and Mode).
596 if (!MPM.isEmpty()) {
597 MPM.printPipeline(OS, MapClassName2PassName);
598 OS << ',';
599 }
600 OS << "cgscc(";
601 if (MaxDevirtIterations != 0)
602 OS << "devirt<" << MaxDevirtIterations << ">(";
603 PM.printPipeline(OS, MapClassName2PassName);
604 if (MaxDevirtIterations != 0)
605 OS << ')';
606 OS << ')';
607}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Expand Atomic instructions
This file contains the simple types necessary to represent the attributes associated with functions a...
This is the interface for LLVM's primary stateless and local alias analysis.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This header provides classes for managing passes over SCCs of the call graph.
@ Available
We know the block is fully available. This is a fixpoint.
Definition GVN.cpp:1233
#define DEBUG_TYPE
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
static cl::opt< bool > EnablePostSCCAdvisorPrinting("enable-scc-inline-advisor-printing", cl::init(false), cl::Hidden)
Allows printing the contents of the advisor after each SCC inliner pass.
void makeFunctionBodyUnreachable(Function &F)
Definition Inliner.cpp:117
Implements a lazy call graph analysis and related passes for the new pass manager.
Legalize the Machine IR a function s Machine IR
Definition Legalizer.cpp:85
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
This file provides a priority worklist.
This file contains some templates that are useful if you are working with the STL at all.
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:119
A manager for alias analyses.
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
Definition Analysis.h:50
void clear(IRUnitT &IR, llvm::StringRef Name)
Clear any cached analysis results for a single unit of IR.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
A function analysis which provides an AssumptionCache.
A cache of @llvm.assume calls within a function.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:106
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition BasicBlock.h:206
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
Analysis pass which computes BlockFrequencyInfo.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
LLVM_ABI Function * getCaller()
Helper to get the caller (the parent function).
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A proxy from a FunctionAnalysisManager to an SCC.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition Function.h:252
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition Globals.cpp:408
Printer pass for the InlineAdvisorAnalysis results.
The InlineAdvisorAnalysis is a module pass because the InlineAdvisor needs to capture state right bef...
Interface for deciding whether to inline a call site or not.
virtual void onPassEntry(LazyCallGraph::SCC *SCC=nullptr)
This must be called when the Inliner pass is entered, to allow the InlineAdvisor update internal stat...
virtual void onPassExit(LazyCallGraph::SCC *SCC=nullptr)
This must be called when the Inliner pass is exited, as function passes may be run subsequently.
std::unique_ptr< InlineAdvice > getAdvice(CallBase &CB, bool MandatoryOnly=false)
Get an InlineAdvice containing a recommendation on whether to inline or not.
This class captures the data input to the InlineFunction call, and records the auxiliary results prod...
Definition Cloning.h:259
SmallVector< CallBase *, 8 > InlinedCallSites
All of the new call sites inlined into the caller.
Definition Cloning.h:282
InlineResult is basically true or false.
Definition InlineCost.h:184
The inliner pass for the new pass manager.
Definition Inliner.h:36
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition Inliner.cpp:583
LLVM_ABI PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
Definition Inliner.cpp:125
A node in the call graph.
An SCC of the call graph.
RefSCC & getOuterRefSCC() const
A lazily constructed view of the call graph of a module.
bool isLibFunction(Function &F) const
Test whether a function is a known and defined library function tracked by the call graph.
LLVM_ABI void markDeadFunction(Function &F)
Mark a function as dead to be removed later by removeDeadFunctions().
Node & get(Function &F)
Get a graph node for a given function, scanning it to populate the graph data as necessary.
SCC * lookupSCC(Node &N) const
Lookup a function's SCC in the graph.
Node * lookup(const Function &F) const
Lookup a function in the graph which has already been scanned and added.
LLVM_ABI PreservedAnalyses run(Module &, ModuleAnalysisManager &)
Definition Inliner.cpp:543
LLVM_ABI ModuleInlinerWrapperPass(InlineParams Params, bool MandatoryFirst=true, InlineContext IC={}, InliningAdvisorMode Mode=InliningAdvisorMode::Default, unsigned MaxDevirtIterations=0)
Definition Inliner.cpp:521
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition Inliner.cpp:591
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
Diagnostic information for missed-optimization remarks.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Definition Analysis.h:132
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
Analysis providing profile information.
void clear()
Completely clear the SetVector.
Definition SetVector.h:273
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:346
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This function has undefined behavior.
LLVM Value Representation.
Definition Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
const char FunctionInlineCostMultiplierAttributeName[]
Definition InlineCost.h:63
initializer< Ty > init(const Ty &Val)
Add a small namespace to avoid name clashes with the classes used in the streaming interface.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI InlineParams getInlineParams(const LLVMContext &C)
Generate the parameters to tune the inline cost analysis based only on the commandline options.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
InliningAdvisorMode
There are 4 scenarios we can use the InlineAdvisor:
LLVM_ABI std::optional< int > getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind)
DevirtSCCRepeatedPass createDevirtSCCRepeatedPass(CGSCCPassT &&Pass, int MaxIterations)
A function to deduce a function pass type and wrap it in the templated adaptor.
LLVM_ABI LazyCallGraph::SCC & updateCGAndAnalysisManagerForCGSCCPass(LazyCallGraph &G, LazyCallGraph::SCC &C, LazyCallGraph::Node &N, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR, FunctionAnalysisManager &FAM)
Helper to update the call graph after running a CGSCC pass.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:649
LLVM_ABI void setInlineRemark(CallBase &CB, StringRef Message)
Set the inline-remark attribute.
LLVM_ABI Value * FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan=DefMaxInstsToScan, BatchAAResults *AA=nullptr, bool *IsLoadCSE=nullptr, unsigned *NumScanedInst=nullptr)
Scan backwards to see if we have the value of the given load available locally within a small number ...
Definition Loads.cpp:554
LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, bool TrackInlineHistory=false, Function *ForwardVarArgsTo=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
This function inlines the called function into the basic block of the caller.
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
const IPOOptions & getIPOOptions(const LLVMContext &C)
Definition IPOOptions.h:36
ModuleToPostOrderCGSCCPassAdaptor createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT &&Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI std::unique_ptr< InlineAdvisor > getReplayInlineAdvisor(Module &M, FunctionAnalysisManager &FAM, LLVMContext &Context, std::unique_ptr< InlineAdvisor > OriginalAdvisor, const ReplayInlinerSettings &ReplaySettings, bool EmitRemarks, InlineContext IC)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
OuterAnalysisManagerProxy< ModuleAnalysisManager, LazyCallGraph::SCC, LazyCallGraph & > ModuleAnalysisManagerCGSCCProxy
A proxy from a ModuleAnalysisManager to an SCC.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
LLVM_ABI void filterDeadComdatFunctions(SmallVectorImpl< Function * > &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive.
LLVM_ABI bool tryPromoteCall(CallBase &CB)
Try to promote (devirtualize) a virtual call on an Alloca.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
std::string itostr(int64_t X)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
#define N
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
SmallPriorityWorklist< LazyCallGraph::SCC *, 1 > & CWorklist
Worklist of the SCCs queued for processing.
SmallDenseSet< std::pair< LazyCallGraph::Node *, LazyCallGraph::SCC * >, 4 > & InlinedInternalEdges
A hacky area where the inliner can retain history about inlining decisions that mutated the call grap...
SmallVector< Function *, 4 > & DeadFunctions
Functions that a pass has considered to be dead to be removed at the end of the call graph walk in ba...
SmallPtrSetImpl< LazyCallGraph::SCC * > & InvalidatedSCCs
The set of invalidated SCCs which should be skipped if they are found in CWorklist.
Provides context on when an inline advisor is constructed in the pipeline (e.g., link phase,...
Thresholds to tune inline cost analysis.
Definition InlineCost.h:210