Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:40

0001 //===- Inliner.h - Inliner pass and infrastructure --------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_TRANSFORMS_IPO_INLINER_H
0010 #define LLVM_TRANSFORMS_IPO_INLINER_H
0011 
0012 #include "llvm/Analysis/CGSCCPassManager.h"
0013 #include "llvm/Analysis/InlineAdvisor.h"
0014 #include "llvm/Analysis/InlineCost.h"
0015 #include "llvm/Analysis/LazyCallGraph.h"
0016 #include "llvm/Analysis/Utils/ImportedFunctionsInliningStatistics.h"
0017 #include "llvm/IR/PassManager.h"
0018 
0019 namespace llvm {
0020 
0021 /// The inliner pass for the new pass manager.
0022 ///
0023 /// This pass wires together the inlining utilities and the inline cost
0024 /// analysis into a CGSCC pass. It considers every call in every function in
0025 /// the SCC and tries to inline if profitable. It can be tuned with a number of
0026 /// parameters to control what cost model is used and what tradeoffs are made
0027 /// when making the decision.
0028 ///
0029 /// It should be noted that the legacy inliners do considerably more than this
0030 /// inliner pass does. They provide logic for manually merging allocas, and
0031 /// doing considerable DCE including the DCE of dead functions. This pass makes
0032 /// every attempt to be simpler. DCE of functions requires complex reasoning
0033 /// about comdat groups, etc. Instead, it is expected that other more focused
0034 /// passes be composed to achieve the same end result.
0035 class InlinerPass : public PassInfoMixin<InlinerPass> {
0036 public:
0037   InlinerPass(bool OnlyMandatory = false,
0038               ThinOrFullLTOPhase LTOPhase = ThinOrFullLTOPhase::None)
0039       : OnlyMandatory(OnlyMandatory), LTOPhase(LTOPhase) {}
0040   InlinerPass(InlinerPass &&Arg) = default;
0041 
0042   PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM,
0043                         LazyCallGraph &CG, CGSCCUpdateResult &UR);
0044 
0045   void printPipeline(raw_ostream &OS,
0046                      function_ref<StringRef(StringRef)> MapClassName2PassName);
0047 
0048 private:
0049   InlineAdvisor &getAdvisor(const ModuleAnalysisManagerCGSCCProxy::Result &MAM,
0050                             FunctionAnalysisManager &FAM, Module &M);
0051   std::unique_ptr<InlineAdvisor> OwnedAdvisor;
0052   const bool OnlyMandatory;
0053   const ThinOrFullLTOPhase LTOPhase;
0054 };
0055 
0056 /// Module pass, wrapping the inliner pass. This works in conjunction with the
0057 /// InlineAdvisorAnalysis to facilitate inlining decisions taking into account
0058 /// module-wide state, that need to keep track of inter-inliner pass runs, for
0059 /// a given module. An InlineAdvisor is configured and kept alive for the
0060 /// duration of the ModuleInlinerWrapperPass::run.
0061 class ModuleInlinerWrapperPass
0062     : public PassInfoMixin<ModuleInlinerWrapperPass> {
0063 public:
0064   ModuleInlinerWrapperPass(
0065       InlineParams Params = getInlineParams(), bool MandatoryFirst = true,
0066       InlineContext IC = {},
0067       InliningAdvisorMode Mode = InliningAdvisorMode::Default,
0068       unsigned MaxDevirtIterations = 0);
0069   ModuleInlinerWrapperPass(ModuleInlinerWrapperPass &&Arg) = default;
0070 
0071   PreservedAnalyses run(Module &, ModuleAnalysisManager &);
0072 
0073   /// Allow adding more CGSCC passes, besides inlining. This should be called
0074   /// before run is called, as part of pass pipeline building.
0075   CGSCCPassManager &getPM() { return PM; }
0076 
0077   /// Add a module pass that runs before the CGSCC passes.
0078   template <class T> void addModulePass(T Pass) {
0079     MPM.addPass(std::move(Pass));
0080   }
0081 
0082   /// Add a module pass that runs after the CGSCC passes.
0083   template <class T> void addLateModulePass(T Pass) {
0084     AfterCGMPM.addPass(std::move(Pass));
0085   }
0086 
0087   void printPipeline(raw_ostream &OS,
0088                      function_ref<StringRef(StringRef)> MapClassName2PassName);
0089 
0090 private:
0091   const InlineParams Params;
0092   const InlineContext IC;
0093   const InliningAdvisorMode Mode;
0094   const unsigned MaxDevirtIterations;
0095   // TODO: Clean this up so we only have one ModulePassManager.
0096   CGSCCPassManager PM;
0097   ModulePassManager MPM;
0098   ModulePassManager AfterCGMPM;
0099 };
0100 } // end namespace llvm
0101 
0102 #endif // LLVM_TRANSFORMS_IPO_INLINER_H