diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/Analysis.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Analysis/DemandedBits.cpp | 64 | ||||
-rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Passes/PassRegistry.def | 2 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/BDCE.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 6 |
7 files changed, 58 insertions, 35 deletions
diff --git a/llvm/lib/Analysis/Analysis.cpp b/llvm/lib/Analysis/Analysis.cpp index 63292b2464a..efdfe091ea6 100644 --- a/llvm/lib/Analysis/Analysis.cpp +++ b/llvm/lib/Analysis/Analysis.cpp @@ -37,7 +37,7 @@ void llvm::initializeAnalysis(PassRegistry &Registry) { initializeCFLAAWrapperPassPass(Registry); initializeDependenceAnalysisPass(Registry); initializeDelinearizationPass(Registry); - initializeDemandedBitsPass(Registry); + initializeDemandedBitsWrapperPassPass(Registry); initializeDivergenceAnalysisPass(Registry); initializeDominanceFrontierWrapperPassPass(Registry); initializeDomViewerPass(Registry); 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(); } diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index adbd61b0d7a..17208c92136 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -24,6 +24,7 @@ #include "llvm/Analysis/CFLAliasAnalysis.h" #include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/Analysis/CallGraph.h" +#include "llvm/Analysis/DemandedBits.h" #include "llvm/Analysis/DominanceFrontier.h" #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/LazyCallGraph.h" diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index f4c449bcadb..dd95e4f49b1 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -68,6 +68,7 @@ FUNCTION_ANALYSIS("aa", AAManager()) FUNCTION_ANALYSIS("assumptions", AssumptionAnalysis()) FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis()) FUNCTION_ANALYSIS("postdomtree", PostDominatorTreeAnalysis()) +FUNCTION_ANALYSIS("demanded-bits", DemandedBitsAnalysis()) FUNCTION_ANALYSIS("domfrontier", DominanceFrontierAnalysis()) FUNCTION_ANALYSIS("loops", LoopAnalysis()) FUNCTION_ANALYSIS("memdep", MemoryDependenceAnalysis()) @@ -105,6 +106,7 @@ FUNCTION_PASS("print", PrintFunctionPass(dbgs())) FUNCTION_PASS("print<assumptions>", AssumptionPrinterPass(dbgs())) FUNCTION_PASS("print<domtree>", DominatorTreePrinterPass(dbgs())) FUNCTION_PASS("print<postdomtree>", PostDominatorTreePrinterPass(dbgs())) +FUNCTION_PASS("print<demanded-bits>", DemandedBitsPrinterPass(dbgs())) FUNCTION_PASS("print<domfrontier>", DominanceFrontierPrinterPass(dbgs())) FUNCTION_PASS("print<loops>", LoopPrinterPass(dbgs())) FUNCTION_PASS("print<regions>", RegionInfoPrinterPass(dbgs())) diff --git a/llvm/lib/Transforms/Scalar/BDCE.cpp b/llvm/lib/Transforms/Scalar/BDCE.cpp index cb9b8b6fffc..a27eab80046 100644 --- a/llvm/lib/Transforms/Scalar/BDCE.cpp +++ b/llvm/lib/Transforms/Scalar/BDCE.cpp @@ -45,7 +45,7 @@ struct BDCE : public FunctionPass { void getAnalysisUsage(AnalysisUsage& AU) const override { AU.setPreservesCFG(); - AU.addRequired<DemandedBits>(); + AU.addRequired<DemandedBitsWrapperPass>(); AU.addPreserved<GlobalsAAWrapperPass>(); } }; @@ -54,14 +54,14 @@ struct BDCE : public FunctionPass { char BDCE::ID = 0; INITIALIZE_PASS_BEGIN(BDCE, "bdce", "Bit-Tracking Dead Code Elimination", false, false) -INITIALIZE_PASS_DEPENDENCY(DemandedBits) +INITIALIZE_PASS_DEPENDENCY(DemandedBitsWrapperPass) INITIALIZE_PASS_END(BDCE, "bdce", "Bit-Tracking Dead Code Elimination", false, false) bool BDCE::runOnFunction(Function& F) { if (skipOptnoneFunction(F)) return false; - DemandedBits &DB = getAnalysis<DemandedBits>(); + auto &DB = getAnalysis<DemandedBitsWrapperPass>().getDemandedBits(); SmallVector<Instruction*, 128> Worklist; bool Changed = false; diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 8072d06c34b..d18576d1d5d 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1498,9 +1498,9 @@ public: LoopVectorizationCostModel(Loop *L, ScalarEvolution *SE, LoopInfo *LI, LoopVectorizationLegality *Legal, const TargetTransformInfo &TTI, - const TargetLibraryInfo *TLI, DemandedBits *DB, - AssumptionCache *AC, const Function *F, - const LoopVectorizeHints *Hints, + const TargetLibraryInfo *TLI, + DemandedBits *DB, AssumptionCache *AC, + const Function *F, const LoopVectorizeHints *Hints, SmallPtrSetImpl<const Value *> &ValuesToIgnore) : TheLoop(L), SE(SE), LI(LI), Legal(Legal), TTI(TTI), TLI(TLI), DB(DB), TheFunction(F), Hints(Hints), ValuesToIgnore(ValuesToIgnore) {} @@ -1717,7 +1717,7 @@ struct LoopVectorize : public FunctionPass { AA = &getAnalysis<AAResultsWrapperPass>().getAAResults(); AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); LAA = &getAnalysis<LoopAccessAnalysis>(); - DB = &getAnalysis<DemandedBits>(); + DB = &getAnalysis<DemandedBitsWrapperPass>().getDemandedBits(); // Compute some weights outside of the loop over the loops. Compute this // using a BranchProbability to re-use its scaling math. @@ -2035,7 +2035,7 @@ struct LoopVectorize : public FunctionPass { AU.addRequired<TargetTransformInfoWrapperPass>(); AU.addRequired<AAResultsWrapperPass>(); AU.addRequired<LoopAccessAnalysis>(); - AU.addRequired<DemandedBits>(); + AU.addRequired<DemandedBitsWrapperPass>(); AU.addPreserved<LoopInfoWrapperPass>(); AU.addPreserved<DominatorTreeWrapperPass>(); AU.addPreserved<BasicAAWrapperPass>(); @@ -6064,7 +6064,7 @@ INITIALIZE_PASS_DEPENDENCY(LCSSA) INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(LoopSimplify) INITIALIZE_PASS_DEPENDENCY(LoopAccessAnalysis) -INITIALIZE_PASS_DEPENDENCY(DemandedBits) +INITIALIZE_PASS_DEPENDENCY(DemandedBitsWrapperPass) INITIALIZE_PASS_END(LoopVectorize, LV_NAME, lv_name, false, false) namespace llvm { diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 2ce7a00a2e5..c6a910e641c 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -3407,7 +3407,7 @@ struct SLPVectorizer : public FunctionPass { LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); - DB = &getAnalysis<DemandedBits>(); + DB = &getAnalysis<DemandedBitsWrapperPass>().getDemandedBits(); Stores.clear(); GEPs.clear(); @@ -3484,7 +3484,7 @@ struct SLPVectorizer : public FunctionPass { AU.addRequired<TargetTransformInfoWrapperPass>(); AU.addRequired<LoopInfoWrapperPass>(); AU.addRequired<DominatorTreeWrapperPass>(); - AU.addRequired<DemandedBits>(); + AU.addRequired<DemandedBitsWrapperPass>(); AU.addPreserved<LoopInfoWrapperPass>(); AU.addPreserved<DominatorTreeWrapperPass>(); AU.addPreserved<AAResultsWrapperPass>(); @@ -4575,7 +4575,7 @@ INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass) INITIALIZE_PASS_DEPENDENCY(LoopSimplify) -INITIALIZE_PASS_DEPENDENCY(DemandedBits) +INITIALIZE_PASS_DEPENDENCY(DemandedBitsWrapperPass) INITIALIZE_PASS_END(SLPVectorizer, SV_NAME, lv_name, false, false) namespace llvm { |