Make removeUser more efficient, add a matching addUser.

Fix the setOperands methods I added to update use/def information correctly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22832 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-08-17 18:58:38 +00:00
parent 02659d2363
commit 8c3484c518

View File

@ -641,25 +641,33 @@ protected:
void setOperands(SDOperand Op0) { void setOperands(SDOperand Op0) {
Operands.reserve(1); Operands.reserve(1);
Operands.push_back(Op0); Operands.push_back(Op0);
Op0.Val->Uses.push_back(this);
} }
void setOperands(SDOperand Op0, SDOperand Op1) { void setOperands(SDOperand Op0, SDOperand Op1) {
Operands.reserve(2); Operands.reserve(2);
Operands.push_back(Op0); Operands.push_back(Op0);
Operands.push_back(Op1); Operands.push_back(Op1);
Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
} }
void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) { void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) {
Operands.reserve(3); Operands.reserve(3);
Operands.push_back(Op0); Operands.push_back(Op0);
Operands.push_back(Op1); Operands.push_back(Op1);
Operands.push_back(Op2); Operands.push_back(Op2);
Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
Op2.Val->Uses.push_back(this);
}
void addUser(SDNode *User) {
Uses.push_back(User);
} }
void removeUser(SDNode *User) { void removeUser(SDNode *User) {
// Remove this user from the operand's use list. // Remove this user from the operand's use list.
for (unsigned i = Uses.size(); ; --i) { for (unsigned i = Uses.size(); ; --i) {
assert(i != 0 && "Didn't find user!"); assert(i != 0 && "Didn't find user!");
if (Uses[i-1] == User) { if (Uses[i-1] == User) {
Uses.erase(Uses.begin()+i-1); Uses[i-1] = Uses.back();
break; Uses.pop_back();
return;
} }
} }
} }