LLVM  8.0.1
SCCP.cpp
Go to the documentation of this file.
5 #include "llvm/Transforms/IPO.h"
7 
8 using namespace llvm;
9 
11  const DataLayout &DL = M.getDataLayout();
12  auto &TLI = AM.getResult<TargetLibraryAnalysis>(M);
13  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
14  auto getAnalysis = [&FAM](Function &F) -> AnalysisResultsForFn {
15  DominatorTree &DT = FAM.getResult<DominatorTreeAnalysis>(F);
16  return {
17  make_unique<PredicateInfo>(F, DT, FAM.getResult<AssumptionAnalysis>(F)),
18  &DT, FAM.getCachedResult<PostDominatorTreeAnalysis>(F)};
19  };
20 
21  if (!runIPSCCP(M, DL, &TLI, getAnalysis))
22  return PreservedAnalyses::all();
23 
28  return PA;
29 }
30 
31 namespace {
32 
33 //===--------------------------------------------------------------------===//
34 //
35 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
36 /// Constant Propagation.
37 ///
38 class IPSCCPLegacyPass : public ModulePass {
39 public:
40  static char ID;
41 
42  IPSCCPLegacyPass() : ModulePass(ID) {
44  }
45 
46  bool runOnModule(Module &M) override {
47  if (skipModule(M))
48  return false;
49  const DataLayout &DL = M.getDataLayout();
50  const TargetLibraryInfo *TLI =
51  &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
52 
53  auto getAnalysis = [this](Function &F) -> AnalysisResultsForFn {
54  DominatorTree &DT =
55  this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
56  return {
57  make_unique<PredicateInfo>(
58  F, DT,
59  this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
60  F)),
61  nullptr, // We cannot preserve the DT or PDT with the legacy pass
62  nullptr}; // manager, so set them to nullptr.
63  };
64 
65  return runIPSCCP(M, DL, TLI, getAnalysis);
66  }
67 
68  void getAnalysisUsage(AnalysisUsage &AU) const override {
72  }
73 };
74 
75 } // end anonymous namespace
76 
77 char IPSCCPLegacyPass::ID = 0;
78 
79 INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp",
80  "Interprocedural Sparse Conditional Constant Propagation",
81  false, false)
84 INITIALIZE_PASS_END(IPSCCPLegacyPass, "ipsccp",
85  "Interprocedural Sparse Conditional Constant Propagation",
86  false, false)
87 
88 // createIPSCCPPass - This is the public interface to this file.
89 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:84
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:770
This class represents lattice values for constants.
Definition: AllocatorList.h:24
ipsccp
Definition: SCCP.cpp:84
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
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:89
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:231
F(f)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:371
Helper struct for bundling up the analysis results per function for IPSCCP.
Definition: SCCP.h:43
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:145
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:42
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
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:10
void initializeIPSCCPLegacyPassPass(PassRegistry &)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:225
void preserve()
Mark an analysis as preserved.
Definition: PassManager.h:175
Analysis pass providing the TargetLibraryInfo.
bool runIPSCCP(Module &M, const DataLayout &DL, const TargetLibraryInfo *TLI, function_ref< AnalysisResultsForFn(Function &)> getAnalysis)
Definition: SCCP.cpp:1936
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:260
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:1038