[llvm] r275698 - [PM] Convert IVUsers analysis to new pass manager.
Sean Silva via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 16 19:51:13 PDT 2016
Was the change to ilist intentional? In the orignal review I was thinking
that they were being used somewhere but looking again I don't see any uses
in this patch.
-- Sean Silva
On Sat, Jul 16, 2016 at 3:51 PM, Dehao Chen via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: dehao
> Date: Sat Jul 16 17:51:33 2016
> New Revision: 275698
>
> URL: http://llvm.org/viewvc/llvm-project?rev=275698&view=rev
> Log:
> [PM] Convert IVUsers analysis to new pass manager.
>
> Summary: Convert IVUsers analysis to new pass manager.
>
> Reviewers: davidxl, silvas
>
> Subscribers: junbuml, sanjoy, llvm-commits, mzolotukhin
>
> Differential Revision: https://reviews.llvm.org/D22434
>
> Modified:
> llvm/trunk/include/llvm/ADT/ilist.h
> llvm/trunk/include/llvm/Analysis/IVUsers.h
> llvm/trunk/include/llvm/InitializePasses.h
> llvm/trunk/lib/Analysis/Analysis.cpp
> llvm/trunk/lib/Analysis/IVUsers.cpp
> llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp
> llvm/trunk/lib/Passes/PassBuilder.cpp
> llvm/trunk/lib/Passes/PassRegistry.def
> llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
> llvm/trunk/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll
>
> Modified: llvm/trunk/include/llvm/ADT/ilist.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ilist.h?rev=275698&r1=275697&r2=275698&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/ilist.h (original)
> +++ llvm/trunk/include/llvm/ADT/ilist.h Sat Jul 16 17:51:33 2016
> @@ -422,6 +422,10 @@ public:
> return iterator(New);
> }
>
> + iterator insert(iterator where, const NodeTy &New) {
> + return this->insert(where, new NodeTy(New));
> + }
> +
> iterator insertAfter(iterator where, NodeTy *New) {
> if (empty())
> return insert(begin(), New);
> @@ -668,7 +672,7 @@ struct ilist : public iplist<NodeTy> {
> typedef typename iplist<NodeTy>::iterator iterator;
>
> ilist() {}
> - ilist(const ilist &right) {
> + ilist(const ilist &right) : iplist<NodeTy>() {
> insert(this->begin(), right.begin(), right.end());
> }
> explicit ilist(size_type count) {
>
> Modified: llvm/trunk/include/llvm/Analysis/IVUsers.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/IVUsers.h?rev=275698&r1=275697&r2=275698&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/IVUsers.h (original)
> +++ llvm/trunk/include/llvm/Analysis/IVUsers.h Sat Jul 16 17:51:33 2016
> @@ -117,7 +117,7 @@ private:
> mutable ilist_node<IVStrideUse> Sentinel;
> };
>
> -class IVUsers : public LoopPass {
> +class IVUsers {
> friend class IVStrideUse;
> Loop *L;
> AssumptionCache *AC;
> @@ -133,15 +133,9 @@ class IVUsers : public LoopPass {
> // Ephemeral values used by @llvm.assume in this function.
> SmallPtrSet<const Value *, 32> EphValues;
>
> - void getAnalysisUsage(AnalysisUsage &AU) const override;
> -
> - bool runOnLoop(Loop *L, LPPassManager &LPM) override;
> -
> - void releaseMemory() override;
> -
> public:
> - static char ID; // Pass ID, replacement for typeid
> - IVUsers();
> + IVUsers(Loop *L, AssumptionCache *AC, LoopInfo *LI, DominatorTree *DT,
> + ScalarEvolution *SE);
>
> Loop *getLoop() const { return L; }
>
> @@ -173,16 +167,58 @@ public:
> return Processed.count(Inst);
> }
>
> - void print(raw_ostream &OS, const Module* = nullptr) const override;
> + void releaseMemory();
> +
> + void print(raw_ostream &OS, const Module * = nullptr) const;
>
> /// dump - This method is used for debugging.
> void dump() const;
> +
> protected:
> bool AddUsersImpl(Instruction *I, SmallPtrSetImpl<Loop*>
> &SimpleLoopNests);
> };
>
> Pass *createIVUsersPass();
>
> +class IVUsersWrapperPass : public LoopPass {
> + std::unique_ptr<IVUsers> IU;
> +
> +public:
> + static char ID;
> +
> + IVUsersWrapperPass();
> +
> + IVUsers &getIU() { return *IU; }
> + const IVUsers &getIU() const { return *IU; }
> +
> + void getAnalysisUsage(AnalysisUsage &AU) const override;
> +
> + bool runOnLoop(Loop *L, LPPassManager &LPM) override;
> +
> + void releaseMemory() override;
> +
> + void print(raw_ostream &OS, const Module * = nullptr) const override;
> +};
> +
> +/// Analysis pass that exposes the \c IVUsers for a loop.
> +class IVUsersAnalysis : public AnalysisInfoMixin<IVUsersAnalysis> {
> + friend AnalysisInfoMixin<IVUsersAnalysis>;
> + static char PassID;
> +
> +public:
> + typedef IVUsers Result;
> +
> + IVUsers run(Loop &L, AnalysisManager<Loop> &AM);
> +};
> +
> +/// Printer pass for the \c IVUsers for a loop.
> +class IVUsersPrinterPass : public PassInfoMixin<IVUsersPrinterPass> {
> + raw_ostream &OS;
> +
> +public:
> + explicit IVUsersPrinterPass(raw_ostream &OS) : OS(OS) {}
> + PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &AM);
> +};
> }
>
> #endif
>
> Modified: llvm/trunk/include/llvm/InitializePasses.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=275698&r1=275697&r2=275698&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/InitializePasses.h (original)
> +++ llvm/trunk/include/llvm/InitializePasses.h Sat Jul 16 17:51:33 2016
> @@ -143,7 +143,7 @@ void initializeGuardWideningLegacyPassPa
> void initializeIPCPPass(PassRegistry&);
> void initializeIPSCCPLegacyPassPass(PassRegistry &);
> void initializeIRTranslatorPass(PassRegistry &);
> -void initializeIVUsersPass(PassRegistry&);
> +void initializeIVUsersWrapperPassPass(PassRegistry&);
> void initializeIfConverterPass(PassRegistry&);
> void initializeImplicitNullChecksPass(PassRegistry&);
> void initializeIndVarSimplifyLegacyPassPass(PassRegistry&);
>
> Modified: llvm/trunk/lib/Analysis/Analysis.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Analysis.cpp?rev=275698&r1=275697&r2=275698&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/Analysis.cpp (original)
> +++ llvm/trunk/lib/Analysis/Analysis.cpp Sat Jul 16 17:51:33 2016
> @@ -51,7 +51,7 @@ void llvm::initializeAnalysis(PassRegist
> initializePostDomOnlyPrinterPass(Registry);
> initializeAAResultsWrapperPassPass(Registry);
> initializeGlobalsAAWrapperPassPass(Registry);
> - initializeIVUsersPass(Registry);
> + initializeIVUsersWrapperPassPass(Registry);
> initializeInstCountPass(Registry);
> initializeIntervalPartitionPass(Registry);
> initializeLazyBlockFrequencyInfoPassPass(Registry);
>
> Modified: llvm/trunk/lib/Analysis/IVUsers.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IVUsers.cpp?rev=275698&r1=275697&r2=275698&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/IVUsers.cpp (original)
> +++ llvm/trunk/lib/Analysis/IVUsers.cpp Sat Jul 16 17:51:33 2016
> @@ -12,11 +12,12 @@
> //
>
> //===----------------------------------------------------------------------===//
>
> +#include "llvm/Analysis/IVUsers.h"
> #include "llvm/ADT/STLExtras.h"
> #include "llvm/Analysis/AssumptionCache.h"
> #include "llvm/Analysis/CodeMetrics.h"
> -#include "llvm/Analysis/IVUsers.h"
> #include "llvm/Analysis/LoopPass.h"
> +#include "llvm/Analysis/LoopPassManager.h"
> #include "llvm/Analysis/ScalarEvolutionExpressions.h"
> #include "llvm/Analysis/ValueTracking.h"
> #include "llvm/IR/Constants.h"
> @@ -33,19 +34,35 @@ using namespace llvm;
>
> #define DEBUG_TYPE "iv-users"
>
> -char IVUsers::ID = 0;
> -INITIALIZE_PASS_BEGIN(IVUsers, "iv-users",
> +char IVUsersAnalysis::PassID;
> +
> +IVUsers IVUsersAnalysis::run(Loop &L, AnalysisManager<Loop> &AM) {
> + const auto &FAM =
> + AM.getResult<FunctionAnalysisManagerLoopProxy>(L).getManager();
> + Function *F = L.getHeader()->getParent();
> +
> + return IVUsers(&L, FAM.getCachedResult<AssumptionAnalysis>(*F),
> + FAM.getCachedResult<LoopAnalysis>(*F),
> + FAM.getCachedResult<DominatorTreeAnalysis>(*F),
> + FAM.getCachedResult<ScalarEvolutionAnalysis>(*F));
> +}
> +
> +PreservedAnalyses IVUsersPrinterPass::run(Loop &L, AnalysisManager<Loop>
> &AM) {
> + AM.getResult<IVUsersAnalysis>(L).print(OS);
> + return PreservedAnalyses::all();
> +}
> +
> +char IVUsersWrapperPass::ID = 0;
> +INITIALIZE_PASS_BEGIN(IVUsersWrapperPass, "iv-users",
> "Induction Variable Users", false, true)
> INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
> INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
> INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
> INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
> -INITIALIZE_PASS_END(IVUsers, "iv-users",
> - "Induction Variable Users", false, true)
> +INITIALIZE_PASS_END(IVUsersWrapperPass, "iv-users", "Induction Variable
> Users",
> + false, true)
>
> -Pass *llvm::createIVUsersPass() {
> - return new IVUsers();
> -}
> +Pass *llvm::createIVUsersPass() { return new IVUsersWrapperPass(); }
>
> /// isInteresting - Test whether the given expression is "interesting"
> when
> /// used by the given expression, within the context of analyzing the
> @@ -246,28 +263,9 @@ IVStrideUse &IVUsers::AddUser(Instructio
> return IVUses.back();
> }
>
> -IVUsers::IVUsers()
> - : LoopPass(ID) {
> - initializeIVUsersPass(*PassRegistry::getPassRegistry());
> -}
> -
> -void IVUsers::getAnalysisUsage(AnalysisUsage &AU) const {
> - AU.addRequired<AssumptionCacheTracker>();
> - AU.addRequired<LoopInfoWrapperPass>();
> - AU.addRequired<DominatorTreeWrapperPass>();
> - AU.addRequired<ScalarEvolutionWrapperPass>();
> - AU.setPreservesAll();
> -}
> -
> -bool IVUsers::runOnLoop(Loop *l, LPPassManager &LPM) {
> -
> - L = l;
> - AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
> - *L->getHeader()->getParent());
> - LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
> - DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
> - SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
> -
> +IVUsers::IVUsers(Loop *L, AssumptionCache *AC, LoopInfo *LI,
> DominatorTree *DT,
> + ScalarEvolution *SE)
> + : L(L), AC(AC), LI(LI), DT(DT), SE(SE), IVUses() {
> // Collect ephemeral values so that AddUsersIfInteresting skips them.
> EphValues.clear();
> CodeMetrics::collectEphemeralValues(L, AC, EphValues);
> @@ -277,16 +275,13 @@ bool IVUsers::runOnLoop(Loop *l, LPPassM
> // this loop. If they are induction variables, inspect their uses.
> for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I);
> ++I)
> (void)AddUsersIfInteresting(&*I);
> -
> - return false;
> }
>
> void IVUsers::print(raw_ostream &OS, const Module *M) const {
> OS << "IV Users for loop ";
> L->getHeader()->printAsOperand(OS, false);
> if (SE->hasLoopInvariantBackedgeTakenCount(L)) {
> - OS << " with backedge-taken count "
> - << *SE->getBackedgeTakenCount(L);
> + OS << " with backedge-taken count " << *SE->getBackedgeTakenCount(L);
> }
> OS << ":\n";
>
> @@ -309,9 +304,7 @@ void IVUsers::print(raw_ostream &OS, con
> }
>
> #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
> -LLVM_DUMP_METHOD void IVUsers::dump() const {
> - print(dbgs());
> -}
> +LLVM_DUMP_METHOD void IVUsers::dump() const { print(dbgs()); }
> #endif
>
> void IVUsers::releaseMemory() {
> @@ -319,6 +312,35 @@ void IVUsers::releaseMemory() {
> IVUses.clear();
> }
>
> +IVUsersWrapperPass::IVUsersWrapperPass() : LoopPass(ID) {
> + initializeIVUsersWrapperPassPass(*PassRegistry::getPassRegistry());
> +}
> +
> +void IVUsersWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
> + AU.addRequired<AssumptionCacheTracker>();
> + AU.addRequired<LoopInfoWrapperPass>();
> + AU.addRequired<DominatorTreeWrapperPass>();
> + AU.addRequired<ScalarEvolutionWrapperPass>();
> + AU.setPreservesAll();
> +}
> +
> +bool IVUsersWrapperPass::runOnLoop(Loop *L, LPPassManager &LPM) {
> + auto *AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
> + *L->getHeader()->getParent());
> + auto *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
> + auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
> + auto *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
> +
> + IU.reset(new IVUsers(L, AC, LI, DT, SE));
> + return false;
> +}
> +
> +void IVUsersWrapperPass::print(raw_ostream &OS, const Module *M) const {
> + IU->print(OS, M);
> +}
> +
> +void IVUsersWrapperPass::releaseMemory() { IU->releaseMemory(); }
> +
> /// getReplacementExpr - Return a SCEV expression which computes the
> /// value of the OperandValToReplace.
> const SCEV *IVUsers::getReplacementExpr(const IVStrideUse &IU) const {
>
> Modified: llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp?rev=275698&r1=275697&r2=275698&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp Sat Jul 16 17:51:33 2016
> @@ -78,7 +78,7 @@ void MachineFunctionPass::getAnalysisUsa
> AU.addPreserved<DominatorTreeWrapperPass>();
> AU.addPreserved<AAResultsWrapperPass>();
> AU.addPreserved<GlobalsAAWrapperPass>();
> - AU.addPreserved<IVUsers>();
> + AU.addPreserved<IVUsersWrapperPass>();
> AU.addPreserved<LoopInfoWrapperPass>();
> AU.addPreserved<MemoryDependenceWrapperPass>();
> AU.addPreserved<ScalarEvolutionWrapperPass>();
>
> Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=275698&r1=275697&r2=275698&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
> +++ llvm/trunk/lib/Passes/PassBuilder.cpp Sat Jul 16 17:51:33 2016
> @@ -32,6 +32,7 @@
> #include "llvm/Analysis/DependenceAnalysis.h"
> #include "llvm/Analysis/DominanceFrontier.h"
> #include "llvm/Analysis/GlobalsModRef.h"
> +#include "llvm/Analysis/IVUsers.h"
> #include "llvm/Analysis/LazyCallGraph.h"
> #include "llvm/Analysis/LazyValueInfo.h"
> #include "llvm/Analysis/LoopAccessAnalysis.h"
>
> Modified: llvm/trunk/lib/Passes/PassRegistry.def
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=275698&r1=275697&r2=275698&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Passes/PassRegistry.def (original)
> +++ llvm/trunk/lib/Passes/PassRegistry.def Sat Jul 16 17:51:33 2016
> @@ -182,6 +182,7 @@ FUNCTION_PASS("verify<regions>", RegionI
> #endif
> LOOP_ANALYSIS("no-op-loop", NoOpLoopAnalysis())
> LOOP_ANALYSIS("access-info", LoopAccessAnalysis())
> +LOOP_ANALYSIS("ivusers", IVUsersAnalysis())
> #undef LOOP_ANALYSIS
>
> #ifndef LOOP_PASS
> @@ -198,4 +199,5 @@ LOOP_PASS("loop-deletion", LoopDeletionP
> LOOP_PASS("simplify-cfg", LoopSimplifyCFGPass())
> LOOP_PASS("indvars", IndVarSimplifyPass())
> LOOP_PASS("print-access-info", LoopAccessInfoPrinterPass(dbgs()))
> +LOOP_PASS("print<ivusers>", IVUsersPrinterPass(dbgs()))
> #undef LOOP_PASS
>
> Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=275698&r1=275697&r2=275698&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Sat Jul 16
> 17:51:33 2016
> @@ -4949,7 +4949,7 @@ INITIALIZE_PASS_BEGIN(LoopStrengthReduce
> INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
> INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
> INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
> -INITIALIZE_PASS_DEPENDENCY(IVUsers)
> +INITIALIZE_PASS_DEPENDENCY(IVUsersWrapperPass)
> INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
> INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
> INITIALIZE_PASS_END(LoopStrengthReduce, "loop-reduce",
> @@ -4979,8 +4979,8 @@ void LoopStrengthReduce::getAnalysisUsag
> // Requiring LoopSimplify a second time here prevents IVUsers from
> running
> // twice, since LoopSimplify was invalidated by running ScalarEvolution.
> AU.addRequiredID(LoopSimplifyID);
> - AU.addRequired<IVUsers>();
> - AU.addPreserved<IVUsers>();
> + AU.addRequired<IVUsersWrapperPass>();
> + AU.addPreserved<IVUsersWrapperPass>();
> AU.addRequired<TargetTransformInfoWrapperPass>();
> }
>
> @@ -4988,7 +4988,7 @@ bool LoopStrengthReduce::runOnLoop(Loop
> if (skipLoop(L))
> return false;
>
> - auto &IU = getAnalysis<IVUsers>();
> + auto &IU = getAnalysis<IVUsersWrapperPass>().getIU();
> auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
> auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
> auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
>
> Modified:
> llvm/trunk/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll?rev=275698&r1=275697&r2=275698&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll
> (original)
> +++ llvm/trunk/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll
> Sat Jul 16 17:51:33 2016
> @@ -1,4 +1,5 @@
> ; RUN: opt < %s -analyze -iv-users | FileCheck %s
> +; RUN: opt -passes='function(require<scalar-evolution>),print<ivusers>'
> -S < %s 2>&1| FileCheck %s
>
> ; Provide legal integer types.
> target datalayout = "n8:16:32:64"
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160716/119fbf69/attachment.html>
More information about the llvm-commits
mailing list