From 33d5595d667ba4a880bd7fe785724e8197bef70c Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Thu, 2 Aug 2007 05:29:38 +0000 Subject: Do not emit copies for physical register output if it's not used. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40722 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/SelectionDAG/SelectionDAG.cpp') diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 4b7863d896..7ac8ea81aa 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -3242,7 +3242,7 @@ bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) const { // If there is only one value, this is easy. if (getNumValues() == 1) return use_size() == NUses; - if (Uses.size() < NUses) return false; + if (use_size() < NUses) return false; SDOperand TheValue(const_cast(this), Value); @@ -3265,6 +3265,31 @@ bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) const { } +/// hasAnyUseOfValue - Return true if there are any use of the indicated +/// value. This method ignores uses of other values defined by this operation. +bool SDNode::hasAnyUseOfValue(unsigned Value) const { + assert(Value < getNumValues() && "Bad value!"); + + if (use_size() == 0) return false; + + SDOperand TheValue(const_cast(this), Value); + + SmallPtrSet UsersHandled; + + for (SDNode::use_iterator UI = Uses.begin(), E = Uses.end(); UI != E; ++UI) { + SDNode *User = *UI; + if (User->getNumOperands() == 1 || + UsersHandled.insert(User)) // First time we've seen this? + for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) + if (User->getOperand(i) == TheValue) { + return true; + } + } + + return false; +} + + /// isOnlyUse - Return true if this node is the only use of N. /// bool SDNode::isOnlyUse(SDNode *N) const { -- cgit v1.2.3-70-g09d2