Add getUniqueVRegDef to MachineRegisterInfo.
authorManman Ren <mren@apple.com>
Fri, 29 Jun 2012 19:16:05 +0000 (19:16 +0000)
committerManman Ren <mren@apple.com>
Fri, 29 Jun 2012 19:16:05 +0000 (19:16 +0000)
This comes in handy during peephole optimization.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159453 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineRegisterInfo.h
lib/CodeGen/MachineRegisterInfo.cpp

index 5a82caa9acddb9637414c859f55034a215773a94..2bcd1c72ce934640ae70b6a6a1386ec22810022d 100644 (file)
@@ -237,6 +237,11 @@ public:
   /// form, so there should only be one definition.
   MachineInstr *getVRegDef(unsigned Reg) const;
 
+  /// getUniqueVRegDef - Return the unique machine instr that defines the
+  /// specified virtual register or null if none is found.  If there are
+  /// multiple definitions or no definition, return null.
+  MachineInstr *getUniqueVRegDef(unsigned Reg) const;
+
   /// clearKillFlags - Iterate over all the uses of the given register and
   /// clear the kill flag from the MachineOperand. This function is used by
   /// optimization passes which extend register lifetimes and need only
index 9c0d749a266b64178a291e0fa62d2fb9920ddbbe..863da72774e2d3a4de7b3dd30debf62f5d98ac95 100644 (file)
@@ -165,6 +165,17 @@ MachineInstr *MachineRegisterInfo::getVRegDef(unsigned Reg) const {
   return !I.atEnd() ? &*I : 0;
 }
 
+/// getUniqueVRegDef - Return the unique machine instr that defines the
+/// specified virtual register or null if none is found.  If there are
+/// multiple definitions or no definition, return null.
+MachineInstr *MachineRegisterInfo::getUniqueVRegDef(unsigned Reg) const {
+  if (def_empty(Reg)) return 0;
+  def_iterator I = def_begin(Reg);
+  if (llvm::next(I) != def_end())
+    return 0;
+  return &*I;
+}
+
 bool MachineRegisterInfo::hasOneUse(unsigned RegNo) const {
   use_iterator UI = use_begin(RegNo);
   if (UI == use_end())