LLVM  10.0.0svn
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 &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
13  auto GetTLI = [&FAM](Function &F) -> const TargetLibraryInfo & {
14  return FAM.getResult<TargetLibraryAnalysis>(F);
15  };
16  auto getAnalysis = [&FAM](Function &F) -> AnalysisResultsForFn {
17  DominatorTree &DT = FAM.getResult<DominatorTreeAnalysis>(F);
18  return {
19  std::make_unique<PredicateInfo>(F, DT, FAM.getResult<AssumptionAnalysis>(F)),
20  &DT, FAM.getCachedResult<PostDominatorTreeAnalysis>(F)};
21  };
22 
23  if (!runIPSCCP(M, DL, GetTLI, getAnalysis))
24  return PreservedAnalyses::all();
25 
30  return PA;
31 }
32 
33 namespace {
34 
35 //===--------------------------------------------------------------------===//
36 //
37 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
38 /// Constant Propagation.
39 ///
40 class IPSCCPLegacyPass : public ModulePass {
41 public:
42  static char ID;
43 
44  IPSCCPLegacyPass() : ModulePass(ID) {
46  }
47 
48  bool runOnModule(Module &M) override {
49  if (skipModule(M))
50  return false;
51  const DataLayout &DL = M.getDataLayout();
52  auto GetTLI = [this](Function &F) -> const TargetLibraryInfo & {
53  return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
54  };
55  auto getAnalysis = [this](Function &F) -> AnalysisResultsForFn {
56  DominatorTree &DT =
57  this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
58  return {
59  std::make_unique<PredicateInfo>(
60  F, DT,
61  this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
62  F)),
63  nullptr, // We cannot preserve the DT or PDT with the legacy pass
64  nullptr}; // manager, so set them to nullptr.
65  };
66 
67  return runIPSCCP(M, DL, GetTLI, getAnalysis);
68  }
69 
70  void getAnalysisUsage(AnalysisUsage &AU) const override {
74  }
75 };
76 
77 } // end anonymous namespace
78 
79 char IPSCCPLegacyPass::ID = 0;
80 
81 INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp",
82  "Interprocedural Sparse Conditional Constant Propagation",
83  false, false)
87 INITIALIZE_PASS_END(IPSCCPLegacyPass, "ipsccp",
88  "Interprocedural Sparse Conditional Constant Propagation",
89  false, false)
90 
91 // createIPSCCPPass - This is the public interface to this file.
92 ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:112
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Interprocedural Sparse Conditional Constant Propagation
Definition: SCCP.cpp:87
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:776
This class represents lattice values for constants.
Definition: AllocatorList.h:23
ipsccp
Definition: SCCP.cpp:87
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:92
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:153
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:159
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:2004
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:224
void preserve()
Mark an analysis as preserved.
Definition: PassManager.h:174
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:1044