LLVM  14.0.0git
SCCP.cpp
Go to the documentation of this file.
1 //===-- SCCP.cpp ----------------------------------------------------------===//
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 Interprocedural Sparse Conditional Constant Propagation.
10 //
11 //===----------------------------------------------------------------------===//
12 
18 #include "llvm/InitializePasses.h"
19 #include "llvm/Transforms/IPO.h"
21 
22 using namespace llvm;
23 
25  const DataLayout &DL = M.getDataLayout();
26  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
27  auto GetTLI = [&FAM](Function &F) -> const TargetLibraryInfo & {
29  };
30  auto getAnalysis = [&FAM](Function &F) -> AnalysisResultsForFn {
32  return {
33  std::make_unique<PredicateInfo>(F, DT, FAM.getResult<AssumptionAnalysis>(F)),
35  };
36 
37  if (!runIPSCCP(M, DL, GetTLI, getAnalysis))
38  return PreservedAnalyses::all();
39 
44  return PA;
45 }
46 
47 namespace {
48 
49 //===--------------------------------------------------------------------===//
50 //
51 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
52 /// Constant Propagation.
53 ///
54 class IPSCCPLegacyPass : public ModulePass {
55 public:
56  static char ID;
57 
58  IPSCCPLegacyPass() : ModulePass(ID) {
60  }
61 
62  bool runOnModule(Module &M) override {
63  if (skipModule(M))
64  return false;
65  const DataLayout &DL = M.getDataLayout();
66  auto GetTLI = [this](Function &F) -> const TargetLibraryInfo & {
67  return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
68  };
69  auto getAnalysis = [this](Function &F) -> AnalysisResultsForFn {
70  DominatorTree &DT =
71  this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
72  return {
73  std::make_unique<PredicateInfo>(
74  F, DT,
75  this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
76  F)),
77  nullptr, // We cannot preserve the DT or PDT with the legacy pass
78  nullptr}; // manager, so set them to nullptr.
79  };
80 
81  return runIPSCCP(M, DL, GetTLI, getAnalysis);
82  }
83 
84  void getAnalysisUsage(AnalysisUsage &AU) const override {
88  }
89 };
90 
91 } // end anonymous namespace
92 
93 char IPSCCPLegacyPass::ID = 0;
94 
95 INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp",
96  "Interprocedural Sparse Conditional Constant Propagation",
97  false, false)
101 INITIALIZE_PASS_END(IPSCCPLegacyPass, "ipsccp",
102  "Interprocedural Sparse Conditional Constant Propagation",
104 
105 // createIPSCCPPass - This is the public interface to this file.
106 ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }
107 
109  ModuleAnalysisManager &AM) {
110  const DataLayout &DL = M.getDataLayout();
111  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
112  auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
114  };
115  auto GetTTI = [&FAM](Function &F) -> TargetTransformInfo & {
116  return FAM.getResult<TargetIRAnalysis>(F);
117  };
118  auto GetAC = [&FAM](Function &F) -> AssumptionCache & {
120  };
121  auto GetAnalysis = [&FAM](Function &F) -> AnalysisResultsForFn {
123  return {std::make_unique<PredicateInfo>(
126  };
127 
128  if (!runFunctionSpecialization(M, DL, GetTLI, GetTTI, GetAC, GetAnalysis))
129  return PreservedAnalyses::all();
130 
135  return PA;
136 }
137 
139  static char ID; // Pass identification, replacement for typeid
141 
142  void getAnalysisUsage(AnalysisUsage &AU) const override {
147  }
148 
149  virtual bool runOnModule(Module &M) override {
150  if (skipModule(M))
151  return false;
152 
153  const DataLayout &DL = M.getDataLayout();
154  auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {
155  return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
156  };
157  auto GetTTI = [this](Function &F) -> TargetTransformInfo & {
158  return this->getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
159  };
160  auto GetAC = [this](Function &F) -> AssumptionCache & {
161  return this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
162  };
163 
164  auto GetAnalysis = [this](Function &F) -> AnalysisResultsForFn {
165  DominatorTree &DT =
166  this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
167  return {
168  std::make_unique<PredicateInfo>(
169  F, DT,
170  this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
171  F)),
172  nullptr, // We cannot preserve the DT or PDT with the legacy pass
173  nullptr}; // manager, so set them to nullptr.
174  };
175  return runFunctionSpecialization(M, DL, GetTLI, GetTTI, GetAC, GetAnalysis);
176  }
177 };
178 
180 
182  FunctionSpecializationLegacyPass, "function-specialization",
183  "Propagate constant arguments by specializing the function", false, false)
184 
190  "Propagate constant arguments by specializing the function",
191  false, false)
192 
195 }
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
AssumptionCache.h
llvm::TargetIRAnalysis
Analysis pass providing the TargetTransformInfo.
Definition: TargetTransformInfo.h:2331
constant
we should consider alternate ways to model stack dependencies Lots of things could be done in WebAssemblyTargetTransformInfo cpp there are numerous optimization related hooks that can be overridden in WebAssemblyTargetLowering Instead of the OptimizeReturned which should consider preserving the returned attribute through to MachineInstrs and extending the MemIntrinsicResults pass to do this optimization on calls too That would also let the WebAssemblyPeephole pass clean up dead defs for such as it does for stores Consider implementing and or getMachineCombinerPatterns Find a clean way to fix the problem which leads to the Shrink Wrapping pass being run after the WebAssembly PEI pass When setting multiple variables to the same constant
Definition: README.txt:91
llvm
This file implements support for optimizing divisions by a constant.
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
specialization
function specialization
Definition: SCCP.cpp:189
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:238
llvm::AnalysisManager::getResult
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:783
llvm::AnalysisResultsForFn
Helper struct for bundling up the analysis results per function for IPSCCP.
Definition: SCCPSolver.h:31
llvm::Function
Definition: Function.h:62
llvm::FunctionSpecializationPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: SCCP.cpp:108
function
function Propagate constant arguments by specializing the function
Definition: SCCP.cpp:190
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:168
SCCP.h
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
PostDominators.h
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp", "Interprocedural Sparse Conditional Constant Propagation", false, false) INITIALIZE_PASS_END(IPSCCPLegacyPass
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
Propagation
Interprocedural Sparse Conditional Constant Propagation
Definition: SCCP.cpp:102
TargetLibraryInfo.h
false
Definition: StackSlotColoring.cpp:142
llvm::IPSCCPPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: SCCP.cpp:24
FunctionSpecializationLegacyPass::ID
static char ID
Definition: SCCP.cpp:139
llvm::DominatorTreeWrapperPass
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:287
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::runIPSCCP
bool runIPSCCP(Module &M, const DataLayout &DL, std::function< const TargetLibraryInfo &(Function &)> GetTLI, function_ref< AnalysisResultsForFn(Function &)> getAnalysis)
Definition: SCCP.cpp:409
FunctionSpecializationLegacyPass
Definition: SCCP.cpp:138
llvm::createIPSCCPPass
ModulePass * createIPSCCPPass()
createIPSCCPPass - This pass propagates constants from call sites into the bodies of functions,...
Definition: SCCP.cpp:106
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
FunctionSpecializationLegacyPass::runOnModule
virtual bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
Definition: SCCP.cpp:149
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:465
llvm::TargetTransformInfoWrapperPass
Wrapper pass for TargetTransformInfo.
Definition: TargetTransformInfo.h:2387
llvm::AssumptionAnalysis
A function analysis which provides an AssumptionCache.
Definition: AssumptionCache.h:169
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::PreservedAnalyses::preserve
void preserve()
Mark an analysis as preserved.
Definition: PassManager.h:176
IPO.h
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::runFunctionSpecialization
bool runFunctionSpecialization(Module &M, const DataLayout &DL, std::function< TargetLibraryInfo &(Function &)> GetTLI, std::function< TargetTransformInfo &(Function &)> GetTTI, std::function< AssumptionCache &(Function &)> GetAC, function_ref< AnalysisResultsForFn(Function &)> GetAnalysis)
Definition: FunctionSpecialization.cpp:741
llvm::AssumptionCacheTracker
An immutable pass that tracks lazily created AssumptionCache objects.
Definition: AssumptionCache.h:200
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:41
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
SCCP.h
FunctionSpecializationLegacyPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: SCCP.cpp:142
ipsccp
ipsccp
Definition: SCCP.cpp:101
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
llvm::AnalysisManager::getCachedResult
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Definition: PassManager.h:802
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:221
arguments
we compile this esp call L1 $pb L1 esp je LBB1_2 esp ret but is currently always computed in the entry block It would be better to sink the picbase computation down into the block for the as it is the only one that uses it This happens for a lot of code with early outs Another example is loads of arguments
Definition: README.txt:425
llvm::DominatorTreeAnalysis
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:252
TargetTransformInfo.h
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:940
llvm::PostDominatorTreeAnalysis
Analysis pass which computes a PostDominatorTree.
Definition: PostDominators.h:47
FunctionSpecializationLegacyPass::FunctionSpecializationLegacyPass
FunctionSpecializationLegacyPass()
Definition: SCCP.cpp:140
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::initializeIPSCCPLegacyPassPass
void initializeIPSCCPLegacyPassPass(PassRegistry &)
llvm::createFunctionSpecializationPass
ModulePass * createFunctionSpecializationPass()
createFunctionSpecializationPass - This pass propagates constants from call sites to the specialized ...
Definition: SCCP.cpp:193
InitializePasses.h
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:440
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37