summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-10-28 03:44:30 +0000
committerDan Gohman <gohman@apple.com>2009-10-28 03:44:30 +0000
commitcd139c037394c77e3113dd9c5afcd41d5b26c248 (patch)
treeaf47c894eb844ca438abceee3b79a3ef32c7994c /llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
parent3432c62d9310a5f64e068fbf9bdad4c36c1dcd60 (diff)
downloadbcm5719-llvm-cd139c037394c77e3113dd9c5afcd41d5b26c248.tar.gz
bcm5719-llvm-cd139c037394c77e3113dd9c5afcd41d5b26c248.zip
Rewrite SelectionDAG::isPredecessorOf to be iterative instead of
recursive to avoid consuming extraordinary amounts of stack space when processing tall graphs. llvm-svn: 85369
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp37
1 files changed, 16 insertions, 21 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 37736c04ab4..139eec3c2f8 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5307,31 +5307,26 @@ bool SDValue::reachesChainWithoutSideEffects(SDValue Dest,
return false;
}
-
-static void findPredecessor(SDNode *N, const SDNode *P, bool &found,
- SmallPtrSet<SDNode *, 32> &Visited) {
- if (found || !Visited.insert(N))
- return;
-
- for (unsigned i = 0, e = N->getNumOperands(); !found && i != e; ++i) {
- SDNode *Op = N->getOperand(i).getNode();
- if (Op == P) {
- found = true;
- return;
- }
- findPredecessor(Op, P, found, Visited);
- }
-}
-
/// isPredecessorOf - Return true if this node is a predecessor of N. This node
-/// is either an operand of N or it can be reached by recursively traversing
-/// up the operands.
+/// is either an operand of N or it can be reached by traversing up the operands.
/// NOTE: this is an expensive method. Use it carefully.
bool SDNode::isPredecessorOf(SDNode *N) const {
SmallPtrSet<SDNode *, 32> Visited;
- bool found = false;
- findPredecessor(N, this, found, Visited);
- return found;
+ SmallVector<SDNode *, 16> Worklist;
+ Worklist.push_back(N);
+
+ do {
+ N = Worklist.pop_back_val();
+ for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
+ SDNode *Op = N->getOperand(i).getNode();
+ if (Op == this)
+ return true;
+ if (Visited.insert(Op))
+ Worklist.push_back(Op);
+ }
+ } while (!Worklist.empty());
+
+ return false;
}
uint64_t SDNode::getConstantOperandVal(unsigned Num) const {
OpenPOWER on IntegriCloud