From c176f038b917826ba07d2434f2a4569eb4ea1bc9 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Fri, 3 Nov 2006 03:05:24 +0000 Subject: [PATCH] Added isPredecessor. llvm-svn: 31409 --- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index c2ee956fff23..fe33ff5ed4a4 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2563,6 +2563,29 @@ bool SDNode::isOperand(SDNode *N) const { return false; } +static void findPredecessor(SDNode *N, const SDNode *P, bool &found, + std::set &Visited) { + if (found || !Visited.insert(N).second) + return; + + for (unsigned i = 0, e = N->getNumOperands(); !found && i != e; ++i) { + SDNode *Op = N->getOperand(i).Val; + if (Op == P) { + found = true; + return; + } + findPredecessor(Op, P, found, Visited); + } +} + +// isPredecessor - Return true if this node is a predecessor of N. +bool SDNode::isPredecessor(SDNode *N) const { + std::set Visited; + bool found = false; + findPredecessor(N, this, found, Visited); + return found; +} + uint64_t SDNode::getConstantOperandVal(unsigned Num) const { assert(Num < NumOperands && "Invalid child # of SDNode!"); return cast(OperandList[Num])->getValue();