Add MachineInstr::readsVirtualRegister() in preparation for proper handling of
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 19 May 2010 20:36:22 +0000 (20:36 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 19 May 2010 20:36:22 +0000 (20:36 +0000)
partial redefines.

We are going to treat a partial redefine of a virtual register as a
read-modify-write:

  %reg1024:6 = OP

Unless the register is fully clobbered:

  %reg1024:6 = OP, %reg1024<imp-def>

MachineInstr::readsVirtualRegister() knows the difference. The first case is a
read, the second isn't.

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

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

index eefbd36daaede8120308ff1e6a68e22e4c13398c..ffec00fd8cf31dbebe08b013766b9ae699e1d611 100644 (file)
@@ -230,10 +230,17 @@ public:
   /// readsRegister - Return true if the MachineInstr reads the specified
   /// register. If TargetRegisterInfo is passed, then it also checks if there
   /// is a read of a super-register.
+  /// This does not count partial redefines of virtual registers as reads:
+  ///   %reg1024:6 = OP.
   bool readsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
     return findRegisterUseOperandIdx(Reg, false, TRI) != -1;
   }
 
+  /// readsVirtualRegister - Return true if the MachineInstr reads the specified
+  /// virtual register. Take into account that a partial define is a
+  /// read-modify-write operation.
+  bool readsVirtualRegister(unsigned Reg) const;
+
   /// killsRegister - Return true if the MachineInstr kills the specified
   /// register. If TargetRegisterInfo is passed, then it also checks if there is
   /// a kill of a super-register.
index d909fb0ef3e3075f3c9826cdd6c4e581ca3be786..553b13938c9126ae3c0efc5d07656e86e809a461 100644 (file)
@@ -781,7 +781,30 @@ int MachineInstr::findRegisterUseOperandIdx(unsigned Reg, bool isKill,
   }
   return -1;
 }
-  
+
+/// readsVirtualRegister - Return true if the MachineInstr reads the specified
+/// virtual register. Take into account that a partial define is a
+/// read-modify-write operation.
+bool MachineInstr::readsVirtualRegister(unsigned Reg) const {
+  bool PartDef = false; // Partial redefine
+  bool FullDef = false; // Full define
+
+  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
+    const MachineOperand &MO = getOperand(i);
+    if (!MO.isReg() || MO.getReg() != Reg)
+      continue;
+    if (MO.isUse())
+      return true;
+    if (MO.getSubReg())
+      PartDef = true;
+    else
+      FullDef = true;
+  }
+  // A partial register definition causes a read unless the full register is
+  // also defined.
+  return PartDef && !FullDef;
+}
+
 /// findRegisterDefOperandIdx() - Returns the operand index that is a def of
 /// the specified register or -1 if it is not found. If isDead is true, defs
 /// that are not dead are skipped. If TargetRegisterInfo is non-null, then it