Add a trivial but handy function to efficiently return the machine
[oota-llvm.git] / lib / CodeGen / MachineRegisterInfo.cpp
index f217c042be2ef0810c1fe4b9665c1f8f75c25e42..b41a1e748cc3b6329db0899939fa420c75e553c2 100644 (file)
@@ -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;
+}