llvm.org GIT mirror llvm / 2d1483c
[PM] Port Interprocedural SCCP to the new pass manager. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268684 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 3 years ago
8 changed file(s) with 93 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
145145 void initializeGlobalOptLegacyPassPass(PassRegistry&);
146146 void initializeGlobalsAAWrapperPassPass(PassRegistry&);
147147 void initializeIPCPPass(PassRegistry&);
148 void initializeIPSCCPPass(PassRegistry&);
148 void initializeIPSCCPLegacyPassPass(PassRegistry &);
149149 void initializeIVUsersPass(PassRegistry&);
150150 void initializeIfConverterPass(PassRegistry&);
151151 void initializeInductiveRangeCheckEliminationPass(PassRegistry&);
0 //===- SCCP.h - Optimize Global Variables ----------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass implements interprocedural sparse conditional constant
10 // propagation and merging.
11 //
12 // Specifically, this:
13 // * Assumes values are constant unless proven otherwise
14 // * Assumes BasicBlocks are dead unless proven otherwise
15 // * Proves values to be constant, and replaces them with constants
16 // * Proves conditional branches to be unconditional
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_TRANSFORMS_IPO_SCCP_H
21 #define LLVM_TRANSFORMS_IPO_SCCP_H
22
23 #include "llvm/IR/Module.h"
24 #include "llvm/IR/PassManager.h"
25
26 namespace llvm {
27 /// Pass to perform interprocedural constant propagation.
28 class IPSCCPPass : public PassInfoMixin {
29 public:
30 PreservedAnalyses run(Module &M, AnalysisManager &AM);
31 };
32 }
33 #endif // LLVM_TRANSFORMS_IPO_SCCP_H
9696 PassRegistry &R = *PassRegistry::getPassRegistry();
9797
9898 initializeInternalizeLegacyPassPass(R);
99 initializeIPSCCPPass(R);
99 initializeIPSCCPLegacyPassPass(R);
100100 initializeGlobalOptLegacyPassPass(R);
101101 initializeConstantMergeLegacyPassPass(R);
102102 initializeDAHPass(R);
5353 #include "llvm/Transforms/IPO/GlobalOpt.h"
5454 #include "llvm/Transforms/IPO/InferFunctionAttrs.h"
5555 #include "llvm/Transforms/IPO/Internalize.h"
56 #include "llvm/Transforms/IPO/SCCP.h"
5657 #include "llvm/Transforms/IPO/StripDeadPrototypes.h"
5758 #include "llvm/Transforms/InstCombine/InstCombine.h"
5859 #include "llvm/Transforms/InstrProfiling.h"
4343 MODULE_PASS("internalize", InternalizePass())
4444 MODULE_PASS("instrprof", InstrProfiling())
4545 MODULE_PASS("invalidate", InvalidateAllAnalysesPass())
46 MODULE_PASS("ipsccp", IPSCCPPass())
4647 MODULE_PASS("no-op-module", NoOpModulePass())
4748 MODULE_PASS("print", PrintModulePass(dbgs()))
4849 MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs()))
1616 //
1717 //===----------------------------------------------------------------------===//
1818
19 #include "llvm/Transforms/Scalar.h"
19 #include "llvm/Transforms/IPO/SCCP.h"
2020 #include "llvm/ADT/DenseMap.h"
2121 #include "llvm/ADT/DenseSet.h"
2222 #include "llvm/ADT/PointerIntPair.h"
2323 #include "llvm/ADT/SmallPtrSet.h"
2424 #include "llvm/ADT/SmallVector.h"
2525 #include "llvm/ADT/Statistic.h"
26 #include "llvm/Analysis/ConstantFolding.h"
2627 #include "llvm/Analysis/GlobalsModRef.h"
27 #include "llvm/Analysis/ConstantFolding.h"
2828 #include "llvm/Analysis/TargetLibraryInfo.h"
2929 #include "llvm/IR/CallSite.h"
3030 #include "llvm/IR/Constants.h"
3737 #include "llvm/Support/ErrorHandling.h"
3838 #include "llvm/Support/raw_ostream.h"
3939 #include "llvm/Transforms/IPO.h"
40 #include "llvm/Transforms/Scalar.h"
4041 #include "llvm/Transforms/Utils/Local.h"
4142 #include
4243 using namespace llvm;
16431644 return MadeChanges;
16441645 }
16451646
1646 namespace {
1647 //===--------------------------------------------------------------------===//
1648 //
1649 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
1650 /// Constant Propagation.
1651 ///
1652 struct IPSCCP : public ModulePass {
1653 void getAnalysisUsage(AnalysisUsage &AU) const override {
1654 AU.addRequired();
1655 }
1656 static char ID;
1657 IPSCCP() : ModulePass(ID) {
1658 initializeIPSCCPPass(*PassRegistry::getPassRegistry());
1659 }
1660 bool runOnModule(Module &M) override;
1661 };
1662 } // end anonymous namespace
1663
1664 char IPSCCP::ID = 0;
1665 INITIALIZE_PASS_BEGIN(IPSCCP, "ipsccp",
1666 "Interprocedural Sparse Conditional Constant Propagation",
1667 false, false)
1668 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
1669 INITIALIZE_PASS_END(IPSCCP, "ipsccp",
1670 "Interprocedural Sparse Conditional Constant Propagation",
1671 false, false)
1672
1673 // createIPSCCPPass - This is the public interface to this file.
1674 ModulePass *llvm::createIPSCCPPass() {
1675 return new IPSCCP();
1676 }
1677
1678
16791647 static bool AddressIsTaken(const GlobalValue *GV) {
16801648 // Delete any dead constantexpr klingons.
16811649 GV->removeDeadConstantUsers();
17031671 return false;
17041672 }
17051673
1706 bool IPSCCP::runOnModule(Module &M) {
1707 if (skipModule(M))
1708 return false;
1709
1710 const DataLayout &DL = M.getDataLayout();
1711 const TargetLibraryInfo *TLI =
1712 &getAnalysis().getTLI();
1674 static bool runIPSCCP(Module &M, const DataLayout &DL,
1675 const TargetLibraryInfo *TLI) {
17131676 SCCPSolver Solver(DL, TLI);
17141677
17151678 // AddressTakenFunctions - This set keeps track of the address-taken functions
19541917
19551918 return MadeChanges;
19561919 }
1920
1921 PreservedAnalyses IPSCCPPass::run(Module &M, AnalysisManager &AM) {
1922 const DataLayout &DL = M.getDataLayout();
1923 auto &TLI = AM.getResult(M);
1924 if (!runIPSCCP(M, DL, &TLI))
1925 return PreservedAnalyses::all();
1926 return PreservedAnalyses::none();
1927 }
1928
1929 namespace {
1930 //===--------------------------------------------------------------------===//
1931 //
1932 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
1933 /// Constant Propagation.
1934 ///
1935 struct IPSCCPLegacyPass : public ModulePass {
1936 static char ID;
1937
1938 IPSCCPLegacyPass() : ModulePass(ID) {
1939 initializeIPSCCPLegacyPassPass(*PassRegistry::getPassRegistry());
1940 }
1941
1942 bool runOnModule(Module &M) override {
1943 if (skipModule(M))
1944 return false;
1945 const DataLayout &DL = M.getDataLayout();
1946 const TargetLibraryInfo *TLI =
1947 &getAnalysis().getTLI();
1948 return runIPSCCP(M, DL, TLI);
1949 }
1950
1951 void getAnalysisUsage(AnalysisUsage &AU) const override {
1952 AU.addRequired();
1953 }
1954 };
1955 } // end anonymous namespace
1956
1957 char IPSCCPLegacyPass::ID = 0;
1958 INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp",
1959 "Interprocedural Sparse Conditional Constant Propagation",
1960 false, false)
1961 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
1962 INITIALIZE_PASS_END(IPSCCPLegacyPass, "ipsccp",
1963 "Interprocedural Sparse Conditional Constant Propagation",
1964 false, false)
1965
1966 // createIPSCCPPass - This is the public interface to this file.
1967 ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }
7070 initializeRegToMemPass(Registry);
7171 initializeRewriteStatepointsForGCPass(Registry);
7272 initializeSCCPPass(Registry);
73 initializeIPSCCPPass(Registry);
73 initializeIPSCCPLegacyPassPass(Registry);
7474 initializeSROALegacyPassPass(Registry);
7575 initializeSROA_DTPass(Registry);
7676 initializeSROA_SSAUpPass(Registry);
0 ; RUN: opt < %s -S -passes=ipsccp | FileCheck %s
1 ; RUN: opt < %s -S -ipsccp | FileCheck %s
12
23 @_ZL6test1g = internal global i32 42, align 4