LLVM  10.0.0
SCCP.cpp
Go to the documentation of this file.
6 #include "llvm/Transforms/IPO.h"
8 
9 using namespace llvm;
10 
12  const DataLayout &DL = M.getDataLayout();
13  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
14  auto GetTLI = [&FAM](Function &F) -> const TargetLibraryInfo & {
15  return FAM.getResult<TargetLibraryAnalysis>(F);
16  };
17  auto getAnalysis = [&FAM](Function &F) -> AnalysisResultsForFn {
18  DominatorTree &DT = FAM.getResult<DominatorTreeAnalysis>(F);
19  return {
20  std::make_unique<PredicateInfo>(F, DT, FAM.getResult<AssumptionAnalysis>(F)),
21  &DT, FAM.getCachedResult<PostDominatorTreeAnalysis>(F)};
22  };
23 
24  if (!runIPSCCP(M, DL, GetTLI, getAnalysis))
25  return PreservedAnalyses::all();
26 
31  return PA;
32 }
33 
34 namespace {
35 
36 //===--------------------------------------------------------------------===//
37 //
38 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
39 /// Constant Propagation.
40 ///
41 class IPSCCPLegacyPass : public ModulePass {
42 public:
43  static char ID;
44 
45  IPSCCPLegacyPass() : ModulePass(ID) {
47  }
48 
49  bool runOnModule(Module &M) override {
50  if (skipModule(M))
51  return false;
52  const DataLayout &DL = M.getDataLayout();
53  auto GetTLI = [this](Function &F) -> const TargetLibraryInfo & {
54  return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
55  };
56  auto getAnalysis = [this](Function &F) -> AnalysisResultsForFn {
57  DominatorTree &DT =
58  this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
59  return {
60  std::make_unique<PredicateInfo>(
61  F, DT,
62  this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
63  F)),
64  nullptr, // We cannot preserve the DT or PDT with the legacy pass
65  nullptr}; // manager, so set them to nullptr.
66  };
67 
68  return runIPSCCP(M, DL, GetTLI, getAnalysis);
69  }
70 
71  void getAnalysisUsage(AnalysisUsage &AU) const override {
75  }
76 };
77 
78 } // end anonymous namespace
79 
80 char IPSCCPLegacyPass::ID = 0;
81 
82 INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp",
83  "Interprocedural Sparse Conditional Constant Propagation",
84  false, false)
88 INITIALIZE_PASS_END(IPSCCPLegacyPass, "ipsccp",
89  "Interprocedural Sparse Conditional Constant Propagation",
90  false, false)
91 
92 // createIPSCCPPass - This is the public interface to this file.
93 ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Interprocedural Sparse Conditional Constant Propagation
Definition: SCCP.cpp:88
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:777
This class represents lattice values for constants.
Definition: AllocatorList.h:23
ipsccp
Definition: SCCP.cpp:88
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
An immutable pass that tracks lazily created AssumptionCache objects.
ModulePass * createIPSCCPPass()
createIPSCCPPass - This pass propagates constants from call sites into the bodies of functions...
Definition: SCCP.cpp:93
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:230
F(f)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:50
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:369
Helper struct for bundling up the analysis results per function for IPSCCP.
Definition: SCCP.h:42
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
This is an important base class in LLVM.
Definition: Constant.h:41
Represent the analysis usage information of a pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:160
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
bool runIPSCCP(Module &M, const DataLayout &DL, std::function< const TargetLibraryInfo &(Function &)> GetTLI, function_ref< AnalysisResultsForFn(Function &)> getAnalysis)
Definition: SCCP.cpp:2005
A function analysis which provides an AssumptionCache.
INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp", "Interprocedural Sparse Conditional Constant Propagation", false, false) INITIALIZE_PASS_END(IPSCCPLegacyPass
Analysis pass which computes a PostDominatorTree.
Provides information about what library functions are available for the current target.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: SCCP.cpp:11
void initializeIPSCCPLegacyPassPass(PassRegistry &)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:222
void preserve()
Mark an analysis as preserved.
Definition: PassManager.h:175
Analysis pass providing the TargetLibraryInfo.
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:259
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:1045