diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2017-04-14 15:49:59 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2017-04-14 15:49:59 +0000 |
commit | e3a15e832cd1f62a51a734a0d083d51db4127494 (patch) | |
tree | c0e6ef903eacab99e56d670587f76ab6dbdac125 /llvm/lib/Analysis | |
parent | ac9f3ea0b437d881bc9879601b0777139b9fd864 (diff) | |
download | bcm5719-llvm-e3a15e832cd1f62a51a734a0d083d51db4127494.tar.gz bcm5719-llvm-e3a15e832cd1f62a51a734a0d083d51db4127494.zip |
Tighten the API for ScalarEvolutionNormalization
llvm-svn: 300331
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/IVUsers.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionNormalization.cpp | 40 |
3 files changed, 40 insertions, 16 deletions
diff --git a/llvm/lib/Analysis/IVUsers.cpp b/llvm/lib/Analysis/IVUsers.cpp index de38cf8366c..fde805a5fde 100644 --- a/llvm/lib/Analysis/IVUsers.cpp +++ b/llvm/lib/Analysis/IVUsers.cpp @@ -270,17 +270,15 @@ bool IVUsers::AddUsersImpl(Instruction *I, return Result; }; - ISE = TransformForPostIncUse(Normalize, ISE, - Optional<NormalizePredTy>(NormalizePred), - NewUse.PostIncLoops, *SE); + ISE = normalizeForPostIncUseIf(ISE, NormalizePred, *SE); // PostIncNormalization effectively simplifies the expression under // pre-increment assumptions. Those assumptions (no wrapping) might not // hold for the post-inc value. Catch such cases by making sure the // transformation is invertible. if (OriginalISE != ISE) { - const SCEV *DenormalizedISE = TransformForPostIncUse( - Denormalize, ISE, None, NewUse.PostIncLoops, *SE); + const SCEV *DenormalizedISE = + denormalizeForPostIncUse(ISE, NewUse.PostIncLoops, *SE); // If we normalized the expression, but denormalization doesn't give the // original one, discard this user. @@ -398,9 +396,8 @@ const SCEV *IVUsers::getReplacementExpr(const IVStrideUse &IU) const { /// getExpr - Return the expression for the use. const SCEV *IVUsers::getExpr(const IVStrideUse &IU) const { - return TransformForPostIncUse( - Normalize, getReplacementExpr(IU), None, - const_cast<PostIncLoopSet &>(IU.getPostIncLoops()), *SE); + return normalizeForPostIncUse(getReplacementExpr(IU), IU.getPostIncLoops(), + *SE); } static const SCEVAddRecExpr *findAddRecForLoop(const SCEV *S, const Loop *L) { diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index 66df34dbe7f..6dd10441c4c 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -1268,8 +1268,7 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) { if (PostIncLoops.count(L)) { PostIncLoopSet Loops; Loops.insert(L); - Normalized = cast<SCEVAddRecExpr>( - TransformForPostIncUse(Normalize, S, None, Loops, SE)); + Normalized = cast<SCEVAddRecExpr>(normalizeForPostIncUse(S, Loops, SE)); } // Strip off any non-loop-dominating component from the addrec start. diff --git a/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp b/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp index becc4bb6010..89237273d01 100644 --- a/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp @@ -19,19 +19,29 @@ using namespace llvm; namespace { +/// TransformKind - Different types of transformations that +/// TransformForPostIncUse can do. +enum TransformKind { + /// Normalize - Normalize according to the given loops. + Normalize, + /// Denormalize - Perform the inverse transform on the expression with the + /// given loop set. + Denormalize +}; + /// Hold the state used during post-inc expression transformation, including a /// map of transformed expressions. class PostIncTransform { TransformKind Kind; Optional<NormalizePredTy> Pred; - PostIncLoopSet &Loops; + const PostIncLoopSet &Loops; ScalarEvolution &SE; DenseMap<const SCEV*, const SCEV*> Transformed; public: PostIncTransform(TransformKind kind, Optional<NormalizePredTy> Pred, - PostIncLoopSet &loops, ScalarEvolution &se) + const PostIncLoopSet &loops, ScalarEvolution &se) : Kind(kind), Pred(Pred), Loops(loops), SE(se) {} const SCEV *TransformSubExpr(const SCEV *S); @@ -160,10 +170,28 @@ const SCEV *PostIncTransform::TransformSubExpr(const SCEV *S) { /// Top level driver for transforming an expression DAG into its requested /// post-inc form (either "Normalized" or "Denormalized"). -const SCEV *llvm::TransformForPostIncUse(TransformKind Kind, const SCEV *S, - Optional<NormalizePredTy> Pred, - PostIncLoopSet &Loops, - ScalarEvolution &SE) { +static const SCEV *TransformForPostIncUse(TransformKind Kind, const SCEV *S, + Optional<NormalizePredTy> Pred, + const PostIncLoopSet &Loops, + ScalarEvolution &SE) { PostIncTransform Transform(Kind, Pred, Loops, SE); return Transform.TransformSubExpr(S); } + +const SCEV *llvm::normalizeForPostIncUse(const SCEV *S, + const PostIncLoopSet &Loops, + ScalarEvolution &SE) { + return TransformForPostIncUse(Normalize, S, None, Loops, SE); +} + +const SCEV *llvm::normalizeForPostIncUseIf(const SCEV *S, NormalizePredTy Pred, + ScalarEvolution &SE) { + PostIncLoopSet Empty; + return TransformForPostIncUse(Normalize, S, Pred, Empty, SE); +} + +const SCEV *llvm::denormalizeForPostIncUse(const SCEV *S, + const PostIncLoopSet &Loops, + ScalarEvolution &SE) { + return TransformForPostIncUse(Denormalize, S, None, Loops, SE); +} |