diff options
author | Sean Silva <chisophugis@gmail.com> | 2016-06-13 22:01:25 +0000 |
---|---|---|
committer | Sean Silva <chisophugis@gmail.com> | 2016-06-13 22:01:25 +0000 |
commit | 687019facb24f32c10d0b49068bc1295dc34b054 (patch) | |
tree | 5491b59f012ef2df504bbf671c1919402c32d034 /llvm/lib | |
parent | 755e4d2d176ae45869a757b53af7696fadc6e88b (diff) | |
download | bcm5719-llvm-687019facb24f32c10d0b49068bc1295dc34b054.tar.gz bcm5719-llvm-687019facb24f32c10d0b49068bc1295dc34b054.zip |
[PM] Port LVI to the new PM.
This is a bit gnarly since LVI is maintaining its own cache.
I think this port could be somewhat cleaner, but I'd rather not spend
too much time on it while we still have the old pass hanging around and
limiting how much we can clean things up.
Once the old pass is gone it will be easier (less time spent) to clean
it up anyway.
This is the last dependency needed for porting JumpThreading which I'll
do in a follow-up commit (there's no printer pass for LVI or anything to
test it, so porting a pass that depends on it seems best).
I've been mostly following:
r269370 / D18834 which ported Dependence Analysis
r268601 / D19839 which ported BPI
llvm-svn: 272593
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/Analysis.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Analysis/LazyValueInfo.cpp | 38 | ||||
-rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Passes/PassRegistry.def | 1 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 8 |
6 files changed, 36 insertions, 20 deletions
diff --git a/llvm/lib/Analysis/Analysis.cpp b/llvm/lib/Analysis/Analysis.cpp index adfca3caa2f..aba3c7dbde2 100644 --- a/llvm/lib/Analysis/Analysis.cpp +++ b/llvm/lib/Analysis/Analysis.cpp @@ -53,7 +53,7 @@ void llvm::initializeAnalysis(PassRegistry &Registry) { initializeIVUsersPass(Registry); initializeInstCountPass(Registry); initializeIntervalPartitionPass(Registry); - initializeLazyValueInfoPass(Registry); + initializeLazyValueInfoWrapperPassPass(Registry); initializeLintPass(Registry); initializeLoopInfoWrapperPassPass(Registry); initializeMemDepPrinterPass(Registry); diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index c8568452d5a..62568f29879 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -38,18 +38,19 @@ using namespace PatternMatch; #define DEBUG_TYPE "lazy-value-info" -char LazyValueInfo::ID = 0; -INITIALIZE_PASS_BEGIN(LazyValueInfo, "lazy-value-info", +char LazyValueInfoWrapperPass::ID = 0; +INITIALIZE_PASS_BEGIN(LazyValueInfoWrapperPass, "lazy-value-info", "Lazy Value Information Analysis", false, true) INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) -INITIALIZE_PASS_END(LazyValueInfo, "lazy-value-info", +INITIALIZE_PASS_END(LazyValueInfoWrapperPass, "lazy-value-info", "Lazy Value Information Analysis", false, true) namespace llvm { - FunctionPass *createLazyValueInfoPass() { return new LazyValueInfo(); } + FunctionPass *createLazyValueInfoPass() { return new LazyValueInfoWrapperPass(); } } +char LazyValueAnalysis::PassID; //===----------------------------------------------------------------------===// // LVILatticeVal @@ -1438,29 +1439,32 @@ static LazyValueInfoCache &getCache(void *&PImpl, AssumptionCache *AC, return *static_cast<LazyValueInfoCache*>(PImpl); } -bool LazyValueInfo::runOnFunction(Function &F) { - AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); +bool LazyValueInfoWrapperPass::runOnFunction(Function &F) { + Info.AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); const DataLayout &DL = F.getParent()->getDataLayout(); DominatorTreeWrapperPass *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>(); - DT = DTWP ? &DTWP->getDomTree() : nullptr; + Info.DT = DTWP ? &DTWP->getDomTree() : nullptr; + Info.TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(); - TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(); - - if (PImpl) - getCache(PImpl, AC, &DL, DT).clear(); + if (Info.PImpl) + getCache(Info.PImpl, Info.AC, &DL, Info.DT).clear(); // Fully lazy. return false; } -void LazyValueInfo::getAnalysisUsage(AnalysisUsage &AU) const { +void LazyValueInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); AU.addRequired<AssumptionCacheTracker>(); AU.addRequired<TargetLibraryInfoWrapperPass>(); } +LazyValueInfo &LazyValueInfoWrapperPass::getLVI() { return Info; } + +LazyValueInfo::~LazyValueInfo() { releaseMemory(); } + void LazyValueInfo::releaseMemory() { // If the cache was allocated, free it. if (PImpl) { @@ -1469,6 +1473,16 @@ void LazyValueInfo::releaseMemory() { } } +void LazyValueInfoWrapperPass::releaseMemory() { Info.releaseMemory(); } + +LazyValueInfo LazyValueAnalysis::run(Function &F, FunctionAnalysisManager &FAM) { + auto &AC = FAM.getResult<AssumptionAnalysis>(F); + auto &TLI = FAM.getResult<TargetLibraryAnalysis>(F); + auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(F); + + return LazyValueInfo(&AC, &TLI, DT); +} + Constant *LazyValueInfo::getConstant(Value *V, BasicBlock *BB, Instruction *CxtI) { const DataLayout &DL = BB->getModule()->getDataLayout(); diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index d67478cb56a..815d34ccbe1 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -32,6 +32,7 @@ #include "llvm/Analysis/DominanceFrontier.h" #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/LazyCallGraph.h" +#include "llvm/Analysis/LazyValueInfo.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/MemoryDependenceAnalysis.h" #include "llvm/Analysis/PostDominators.h" diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 26a63665d0c..44ef05e4d56 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -89,6 +89,7 @@ FUNCTION_ANALYSIS("postdomtree", PostDominatorTreeAnalysis()) FUNCTION_ANALYSIS("demanded-bits", DemandedBitsAnalysis()) FUNCTION_ANALYSIS("domfrontier", DominanceFrontierAnalysis()) FUNCTION_ANALYSIS("loops", LoopAnalysis()) +FUNCTION_ANALYSIS("lazy-value-info", LazyValueAnalysis()) FUNCTION_ANALYSIS("da", DependenceAnalysis()) FUNCTION_ANALYSIS("memdep", MemoryDependenceAnalysis()) FUNCTION_ANALYSIS("memoryssa", MemorySSAAnalysis()) diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 125899d6c31..ca0e62c2e14 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -49,7 +49,7 @@ namespace { bool runOnFunction(Function &F) override; void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequired<LazyValueInfo>(); + AU.addRequired<LazyValueInfoWrapperPass>(); AU.addPreserved<GlobalsAAWrapperPass>(); } }; @@ -58,7 +58,7 @@ namespace { char CorrelatedValuePropagation::ID = 0; INITIALIZE_PASS_BEGIN(CorrelatedValuePropagation, "correlated-propagation", "Value Propagation", false, false) -INITIALIZE_PASS_DEPENDENCY(LazyValueInfo) +INITIALIZE_PASS_DEPENDENCY(LazyValueInfoWrapperPass) INITIALIZE_PASS_END(CorrelatedValuePropagation, "correlated-propagation", "Value Propagation", false, false) @@ -389,7 +389,7 @@ bool CorrelatedValuePropagation::runOnFunction(Function &F) { if (skipFunction(F)) return false; - LVI = &getAnalysis<LazyValueInfo>(); + LVI = &getAnalysis<LazyValueInfoWrapperPass>().getLVI(); bool FnChanged = false; diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 75c340fd593..7f5f29f827e 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -131,8 +131,8 @@ namespace { bool runOnFunction(Function &F) override; void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequired<LazyValueInfo>(); - AU.addPreserved<LazyValueInfo>(); + AU.addRequired<LazyValueInfoWrapperPass>(); + AU.addPreserved<LazyValueInfoWrapperPass>(); AU.addPreserved<GlobalsAAWrapperPass>(); AU.addRequired<TargetLibraryInfoWrapperPass>(); } @@ -176,7 +176,7 @@ namespace { char JumpThreading::ID = 0; INITIALIZE_PASS_BEGIN(JumpThreading, "jump-threading", "Jump Threading", false, false) -INITIALIZE_PASS_DEPENDENCY(LazyValueInfo) +INITIALIZE_PASS_DEPENDENCY(LazyValueInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) INITIALIZE_PASS_END(JumpThreading, "jump-threading", "Jump Threading", false, false) @@ -192,7 +192,7 @@ bool JumpThreading::runOnFunction(Function &F) { DEBUG(dbgs() << "Jump threading on function '" << F.getName() << "'\n"); TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(); - LVI = &getAnalysis<LazyValueInfo>(); + LVI = &getAnalysis<LazyValueInfoWrapperPass>().getLVI(); BFI.reset(); BPI.reset(); // When profile data is available, we need to update edge weights after |