LLVM  13.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 
17 #include "llvm/InitializePasses.h"
18 #include "llvm/Transforms/IPO.h"
20 
21 using namespace llvm;
22 
24  const DataLayout &DL = M.getDataLayout();
25  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
26  auto GetTLI = [&FAM](Function &F) -> const TargetLibraryInfo & {
27  return FAM.getResult<TargetLibraryAnalysis>(F);
28  };
29  auto getAnalysis = [&FAM](Function &F) -> AnalysisResultsForFn {
30  DominatorTree &DT = FAM.getResult<DominatorTreeAnalysis>(F);
31  return {
32  std::make_unique<PredicateInfo>(F, DT, FAM.getResult<AssumptionAnalysis>(F)),
33  &DT, FAM.getCachedResult<PostDominatorTreeAnalysis>(F)};
34  };
35 
36  if (!runIPSCCP(M, DL, GetTLI, getAnalysis))
37  return PreservedAnalyses::all();
38 
43  return PA;
44 }
45 
46 namespace {
47 
48 //===--------------------------------------------------------------------===//
49 //
50 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
51 /// Constant Propagation.
52 ///
53 class IPSCCPLegacyPass : public ModulePass {
54 public:
55  static char ID;
56 
57  IPSCCPLegacyPass() : ModulePass(ID) {
59  }
60 
61  bool runOnModule(Module &M) override {
62  if (skipModule(M))
63  return false;
64  const DataLayout &DL = M.getDataLayout();
65  auto GetTLI = [this](Function &F) -> const TargetLibraryInfo & {
66  return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
67  };
68  auto getAnalysis = [this](Function &F) -> AnalysisResultsForFn {
69  DominatorTree &DT =
70  this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
71  return {
72  std::make_unique<PredicateInfo>(
73  F, DT,
74  this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
75  F)),
76  nullptr, // We cannot preserve the DT or PDT with the legacy pass
77  nullptr}; // manager, so set them to nullptr.
78  };
79 
80  return runIPSCCP(M, DL, GetTLI, getAnalysis);
81  }
82 
83  void getAnalysisUsage(AnalysisUsage &AU) const override {
87  }
88 };
89 
90 } // end anonymous namespace
91 
92 char IPSCCPLegacyPass::ID = 0;
93 
94 INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp",
95  "Interprocedural Sparse Conditional Constant Propagation",
96  false, false)
100 INITIALIZE_PASS_END(IPSCCPLegacyPass, "ipsccp",
101  "Interprocedural Sparse Conditional Constant Propagation",
103 
104 // createIPSCCPPass - This is the public interface to this file.
105 ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
AssumptionCache.h
llvm
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
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
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:785
llvm::AnalysisResultsForFn
Helper struct for bundling up the analysis results per function for IPSCCP.
Definition: SCCPSolver.h:31
llvm::Function
Definition: Function.h:61
SCCP.h
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
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:101
TargetLibraryInfo.h
false
Definition: StackSlotColoring.cpp:142
llvm::IPSCCPPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: SCCP.cpp:23
llvm::DominatorTreeWrapperPass
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:281
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:413
llvm::createIPSCCPPass
ModulePass * createIPSCCPPass()
createIPSCCPPass - This pass propagates constants from call sites into the bodies of functions,...
Definition: SCCP.cpp:105
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:446
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::AssumptionCacheTracker
An immutable pass that tracks lazily created AssumptionCache objects.
Definition: AssumptionCache.h:200
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
SCCP.h
ipsccp
ipsccp
Definition: SCCP.cpp:100
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:207
llvm::DominatorTreeAnalysis
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:252
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:945
llvm::PostDominatorTreeAnalysis
Analysis pass which computes a PostDominatorTree.
Definition: PostDominators.h:47
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::initializeIPSCCPLegacyPassPass
void initializeIPSCCPLegacyPassPass(PassRegistry &)
InitializePasses.h
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:421
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38