blob: cc53c4b8c46f7699291925d913e9a640f61a3a56 [file] [log] [blame]
David Blaikie3bbf5af2018-03-22 21:41:29 +00001#include "llvm/Transforms/IPO/SCCP.h"
2#include "llvm/Analysis/TargetLibraryInfo.h"
3#include "llvm/Transforms/IPO.h"
4#include "llvm/Transforms/Scalar/SCCP.h"
5
6using namespace llvm;
7
8PreservedAnalyses IPSCCPPass::run(Module &M, ModuleAnalysisManager &AM) {
9 const DataLayout &DL = M.getDataLayout();
10 auto &TLI = AM.getResult<TargetLibraryAnalysis>(M);
11 if (!runIPSCCP(M, DL, &TLI))
12 return PreservedAnalyses::all();
13 return PreservedAnalyses::none();
14}
15
16namespace {
17
18//===--------------------------------------------------------------------===//
19//
20/// IPSCCP Class - This class implements interprocedural Sparse Conditional
21/// Constant Propagation.
22///
23class IPSCCPLegacyPass : public ModulePass {
24public:
25 static char ID;
26
27 IPSCCPLegacyPass() : ModulePass(ID) {
28 initializeIPSCCPLegacyPassPass(*PassRegistry::getPassRegistry());
29 }
30
31 bool runOnModule(Module &M) override {
32 if (skipModule(M))
33 return false;
34 const DataLayout &DL = M.getDataLayout();
35 const TargetLibraryInfo *TLI =
36 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
37 return runIPSCCP(M, DL, TLI);
38 }
39
40 void getAnalysisUsage(AnalysisUsage &AU) const override {
41 AU.addRequired<TargetLibraryInfoWrapperPass>();
42 }
43};
44
45} // end anonymous namespace
46
47char IPSCCPLegacyPass::ID = 0;
48
49INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp",
50 "Interprocedural Sparse Conditional Constant Propagation",
51 false, false)
52INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
53INITIALIZE_PASS_END(IPSCCPLegacyPass, "ipsccp",
54 "Interprocedural Sparse Conditional Constant Propagation",
55 false, false)
56
57// createIPSCCPPass - This is the public interface to this file.
58ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }