SCEVTraversal: Add a visited set.

Expression trees may be DAGs. Make sure traversal has linear complexity.

llvm-svn: 160426
This commit is contained in:
Andrew Trick 2012-07-18 05:14:03 +00:00
parent 6bf3ed454a
commit 0d10225fa2
1 changed files with 3 additions and 1 deletions

View File

@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_SCALAREVOLUTION_EXPRESSIONS_H
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/ErrorHandling.h"
namespace llvm {
@ -505,9 +506,10 @@ namespace llvm {
class SCEVTraversal {
SV &Visitor;
SmallVector<const SCEV *, 8> Worklist;
SmallPtrSet<const SCEV *, 8> Visited;
void push(const SCEV *S) {
if (Visitor.follow(S))
if (Visited.insert(S) && Visitor.follow(S))
Worklist.push_back(S);
}
public: