summaryrefslogtreecommitdiff
path: root/lib/CodeGen/MachineRegisterInfo.cpp
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 /lib/CodeGen/MachineRegisterInfo.cpp
parentab477ccde9382b58d3883eeb574ba09469d4cde8 (diff)
downloadllvm-e138b3dd1ff02d826233482831318708a166ed93.tar.gz
llvm-e138b3dd1ff02d826233482831318708a166ed93.tar.bz2
llvm-e138b3dd1ff02d826233482831318708a166ed93.tar.xz
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 'lib/CodeGen/MachineRegisterInfo.cpp')
-rw-r--r--lib/CodeGen/MachineRegisterInfo.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/CodeGen/MachineRegisterInfo.cpp b/lib/CodeGen/MachineRegisterInfo.cpp
index b41a1e748c..dbb01c3e55 100644
--- a/lib/CodeGen/MachineRegisterInfo.cpp
+++ b/lib/CodeGen/MachineRegisterInfo.cpp
@@ -45,6 +45,20 @@ void MachineRegisterInfo::HandleVRegListReallocation() {
}
}
+/// 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 MachineRegisterInfo::replaceRegWith(unsigned FromReg, unsigned ToReg) {
+ assert(FromReg != ToReg && "Cannot replace a reg with itself");
+
+ // TODO: This could be more efficient by bulk changing the operands.
+ for (reg_iterator I = reg_begin(FromReg), E = reg_end(); I != E; ) {
+ MachineOperand &O = I.getOperand();
+ ++I;
+ O.setReg(ToReg);
+ }
+}
+
/// getVRegDef - Return the machine instr that defines the specified virtual
/// register or null if none is found. This assumes that the code is in SSA
@@ -54,8 +68,8 @@ MachineInstr *MachineRegisterInfo::getVRegDef(unsigned Reg) const {
"Invalid vreg!");
for (reg_iterator I = reg_begin(Reg), E = reg_end(); I != E; ++I) {
// Since we are in SSA form, we can stop at the first definition.
- if (I->isDef())
- return I->getParent();
+ if (I.getOperand().isDef())
+ return &*I;
}
return 0;
}