diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-11-09 18:22:43 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-11-09 18:22:43 +0000 |
commit | e3d8a20a5e35855b2fe7fc7e6621be8dc26a6276 (patch) | |
tree | 47d9ef52876e7723d68616c9baab7f3f6e5dbc29 /include | |
parent | 7deb9eea891dc7216c1e0477c3a692e96e685146 (diff) |
[SCEV] Refactor out a useful pattern; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286386 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Analysis/ScalarEvolutionExpressions.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/llvm/Analysis/ScalarEvolutionExpressions.h b/include/llvm/Analysis/ScalarEvolutionExpressions.h index 9113880ef25..fdcd8be00dd 100644 --- a/include/llvm/Analysis/ScalarEvolutionExpressions.h +++ b/include/llvm/Analysis/ScalarEvolutionExpressions.h @@ -537,6 +537,31 @@ namespace llvm { T.visitAll(Root); } + /// Return true if any node in \p Root satisfies the predicate \p Pred. + template <typename PredTy> + bool SCEVExprContains(const SCEV *Root, PredTy Pred) { + struct FindClosure { + bool Found = false; + PredTy Pred; + + FindClosure(PredTy Pred) : Pred(Pred) {} + + bool follow(const SCEV *S) { + if (!Pred(S)) + return true; + + Found = true; + return false; + } + + bool isDone() const { return Found; } + }; + + FindClosure FC(Pred); + visitAll(Root, FC); + return FC.Found; + } + /// This visitor recursively visits a SCEV expression and re-writes it. /// The result from each visit is cached, so it will return the same /// SCEV for the same input. |