diff options
author | Michael Kuperstein <michael.kuperstein@gmail.com> | 2016-04-18 23:55:01 +0000 |
---|---|---|
committer | Michael Kuperstein <michael.kuperstein@gmail.com> | 2016-04-18 23:55:01 +0000 |
commit | de16b44f74810286e2ff37c0c3ccdf053b689f30 (patch) | |
tree | e02b8ca65278580fa3f3485018d97d6fbc7f0454 /llvm/lib/Analysis/DemandedBits.cpp | |
parent | 2526fca8d891dad669e3a425b84d30bc7aaeb234 (diff) | |
download | bcm5719-llvm-de16b44f74810286e2ff37c0c3ccdf053b689f30.tar.gz bcm5719-llvm-de16b44f74810286e2ff37c0c3ccdf053b689f30.zip |
Port DemandedBits to the new pass manager.
Differential Revision: http://reviews.llvm.org/D18679
llvm-svn: 266699
Diffstat (limited to 'llvm/lib/Analysis/DemandedBits.cpp')
-rw-r--r-- | llvm/lib/Analysis/DemandedBits.cpp | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/llvm/lib/Analysis/DemandedBits.cpp b/llvm/lib/Analysis/DemandedBits.cpp index 2f1bca603ef..a3f8b7fda08 100644 --- a/llvm/lib/Analysis/DemandedBits.cpp +++ b/llvm/lib/Analysis/DemandedBits.cpp @@ -42,25 +42,29 @@ using namespace llvm; #define DEBUG_TYPE "demanded-bits" -char DemandedBits::ID = 0; -INITIALIZE_PASS_BEGIN(DemandedBits, "demanded-bits", "Demanded bits analysis", - false, false) +char DemandedBitsWrapperPass::ID = 0; +INITIALIZE_PASS_BEGIN(DemandedBitsWrapperPass, "demanded-bits", + "Demanded bits analysis", false, false) INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) -INITIALIZE_PASS_END(DemandedBits, "demanded-bits", "Demanded bits analysis", - false, false) +INITIALIZE_PASS_END(DemandedBitsWrapperPass, "demanded-bits", + "Demanded bits analysis", false, false) -DemandedBits::DemandedBits() : FunctionPass(ID), F(nullptr), Analyzed(false) { - initializeDemandedBitsPass(*PassRegistry::getPassRegistry()); +DemandedBitsWrapperPass::DemandedBitsWrapperPass() : FunctionPass(ID) { + initializeDemandedBitsWrapperPassPass(*PassRegistry::getPassRegistry()); } -void DemandedBits::getAnalysisUsage(AnalysisUsage &AU) const { +void DemandedBitsWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesCFG(); AU.addRequired<AssumptionCacheTracker>(); AU.addRequired<DominatorTreeWrapperPass>(); AU.setPreservesAll(); } +void DemandedBitsWrapperPass::print(raw_ostream &OS, const Module *M) const { + DB->print(OS); +} + static bool isAlwaysLive(Instruction *I) { return isa<TerminatorInst>(I) || isa<DbgInfoIntrinsic>(I) || I->isEHPad() || I->mayHaveSideEffects(); @@ -84,13 +88,13 @@ void DemandedBits::determineLiveOperandBits( KnownZero = APInt(BitWidth, 0); KnownOne = APInt(BitWidth, 0); computeKnownBits(const_cast<Value *>(V1), KnownZero, KnownOne, DL, 0, - AC, UserI, DT); + &AC, UserI, &DT); if (V2) { KnownZero2 = APInt(BitWidth, 0); KnownOne2 = APInt(BitWidth, 0); computeKnownBits(const_cast<Value *>(V2), KnownZero2, KnownOne2, DL, - 0, AC, UserI, DT); + 0, &AC, UserI, &DT); } }; @@ -243,19 +247,22 @@ void DemandedBits::determineLiveOperandBits( } } -bool DemandedBits::runOnFunction(Function& Fn) { - F = &Fn; - Analyzed = false; +bool DemandedBitsWrapperPass::runOnFunction(Function &F) { + auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); + auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); + DB.emplace(F, AC, DT); return false; } +void DemandedBitsWrapperPass::releaseMemory() { + DB.reset(); +} + void DemandedBits::performAnalysis() { if (Analyzed) // Analysis already completed for this function. return; Analyzed = true; - AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(*F); - DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); Visited.clear(); AliveBits.clear(); @@ -263,7 +270,7 @@ void DemandedBits::performAnalysis() { SmallVector<Instruction*, 128> Worklist; // Collect the set of "root" instructions that are known live. - for (Instruction &I : instructions(*F)) { + for (Instruction &I : instructions(F)) { if (!isAlwaysLive(&I)) continue; @@ -368,16 +375,29 @@ bool DemandedBits::isInstructionDead(Instruction *I) { !isAlwaysLive(I); } -void DemandedBits::print(raw_ostream &OS, const Module *M) const { - // This is gross. But the alternative is making all the state mutable - // just because of this one debugging method. - const_cast<DemandedBits*>(this)->performAnalysis(); +void DemandedBits::print(raw_ostream &OS) { + performAnalysis(); for (auto &KV : AliveBits) { OS << "DemandedBits: 0x" << utohexstr(KV.second.getLimitedValue()) << " for " << *KV.first << "\n"; } } -FunctionPass *llvm::createDemandedBitsPass() { - return new DemandedBits(); +FunctionPass *llvm::createDemandedBitsWrapperPass() { + return new DemandedBitsWrapperPass(); +} + +char DemandedBitsAnalysis::PassID; + +DemandedBits DemandedBitsAnalysis::run(Function &F, + AnalysisManager<Function> &AM) { + auto &AC = AM.getResult<AssumptionAnalysis>(F); + auto &DT = AM.getResult<DominatorTreeAnalysis>(F); + return DemandedBits(F, AC, DT); +} + +PreservedAnalyses DemandedBitsPrinterPass::run(Function &F, + FunctionAnalysisManager &AM) { + AM.getResult<DemandedBitsAnalysis>(F).print(OS); + return PreservedAnalyses::all(); } |