aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/CodeGen
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-01 20:36:19 +0000
committerChris Lattner <sabre@nondot.org>2008-01-01 20:36:19 +0000
commite138b3dd1ff02d826233482831318708a166ed93 (patch)
tree9a7f8e2fa9b65ad0426d782bb694626846a17f2d /include/llvm/CodeGen
parentab477ccde9382b58d3883eeb574ba09469d4cde8 (diff)
switch the register iterator to act more like hte LLVM value iterator: dereferencing
it now returns the machineinstr of the use. To get the operand, use I.getOperand(). Add a new MachineRegisterInfo::replaceRegWith, which is basically like Value::replaceAllUsesWith. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45482 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/CodeGen')
-rw-r--r--include/llvm/CodeGen/MachineRegisterInfo.h34
1 files changed, 26 insertions, 8 deletions
diff --git a/include/llvm/CodeGen/MachineRegisterInfo.h b/include/llvm/CodeGen/MachineRegisterInfo.h
index 45069a2653..81eb69414a 100644
--- a/include/llvm/CodeGen/MachineRegisterInfo.h
+++ b/include/llvm/CodeGen/MachineRegisterInfo.h
@@ -70,6 +70,11 @@ public:
}
static reg_iterator reg_end() { return reg_iterator(0); }
+ /// replaceRegWith - Replace all instances of FromReg with ToReg in the
+ /// machine function. This is like llvm-level X->replaceAllUsesWith(Y),
+ /// except that it also changes any definitions of the register as well.
+ void replaceRegWith(unsigned FromReg, unsigned ToReg);
+
/// getRegUseDefListHead - Return the head pointer for the register use/def
/// list for the specified virtual or physical register.
MachineOperand *&getRegUseDefListHead(unsigned RegNo) {
@@ -171,15 +176,13 @@ private:
public:
/// reg_iterator - This class provides iterator support for machine
/// operands in the function that use or define a specific register.
- class reg_iterator : public forward_iterator<MachineOperand, ptrdiff_t> {
- typedef forward_iterator<MachineOperand, ptrdiff_t> super;
-
+ class reg_iterator : public forward_iterator<MachineInstr, ptrdiff_t> {
MachineOperand *Op;
reg_iterator(MachineOperand *op) : Op(op) {}
friend class MachineRegisterInfo;
public:
- typedef super::reference reference;
- typedef super::pointer pointer;
+ typedef forward_iterator<MachineInstr, ptrdiff_t>::reference reference;
+ typedef forward_iterator<MachineInstr, ptrdiff_t>::pointer pointer;
reg_iterator(const reg_iterator &I) : Op(I.Op) {}
reg_iterator() : Op(0) {}
@@ -204,13 +207,28 @@ public:
reg_iterator tmp = *this; ++*this; return tmp;
}
- // Retrieve a reference to the current operand.
- MachineOperand &operator*() const {
+ MachineOperand &getOperand() const {
assert(Op && "Cannot dereference end iterator!");
return *Op;
}
- MachineOperand *operator->() const { return Op; }
+ /// getOperandNo - Return the operand # of this MachineOperand in its
+ /// MachineInstr.
+ unsigned getOperandNo() const {
+ assert(Op && "Cannot dereference end iterator!");
+ return Op - &Op->getParent()->getOperand(0);
+ }
+
+ // Retrieve a reference to the current operand.
+ MachineInstr &operator*() const {
+ assert(Op && "Cannot dereference end iterator!");
+ return *Op->getParent();
+ }
+
+ MachineInstr *operator->() const {
+ assert(Op && "Cannot dereference end iterator!");
+ return Op->getParent();
+ }
};
};