aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/MachineRegisterInfo.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-01 03:07:29 +0000
committerChris Lattner <sabre@nondot.org>2008-01-01 03:07:29 +0000
commita91a7d594ff1e1503731ca92f72e627bdfd18f3f (patch)
tree15c37e071b49da85dec69f1f307ecb9047ebdf1d /lib/CodeGen/MachineRegisterInfo.cpp
parent6c5757e4e85bb190097be13c1630bb107a1fbcfe (diff)
Add a trivial but handy function to efficiently return the machine
instruction that defines the specified vreg. Crazy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45480 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MachineRegisterInfo.cpp')
-rw-r--r--lib/CodeGen/MachineRegisterInfo.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/CodeGen/MachineRegisterInfo.cpp b/lib/CodeGen/MachineRegisterInfo.cpp
index f217c042be..b41a1e748c 100644
--- a/lib/CodeGen/MachineRegisterInfo.cpp
+++ b/lib/CodeGen/MachineRegisterInfo.cpp
@@ -44,3 +44,18 @@ void MachineRegisterInfo::HandleVRegListReallocation() {
List->Contents.Reg.Prev = &VRegInfo[i].second;
}
}
+
+
+/// 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
+/// form, so there should only be one definition.
+MachineInstr *MachineRegisterInfo::getVRegDef(unsigned Reg) const {
+ assert(Reg-MRegisterInfo::FirstVirtualRegister < VRegInfo.size() &&
+ "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();
+ }
+ return 0;
+}