diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2010-05-21 16:42:30 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2010-05-21 16:42:30 +0000 |
commit | 00c53caa339f954cb3590a05e8653b864b4355cf (patch) | |
tree | d161bd9675e4372981b504dcc0ac3e3fb8d041cb /lib/CodeGen/MachineInstr.cpp | |
parent | 2afb7505c5e9ffd08a96fdd4c43f962a50160053 (diff) | |
download | llvm-00c53caa339f954cb3590a05e8653b864b4355cf.tar.gz llvm-00c53caa339f954cb3590a05e8653b864b4355cf.tar.bz2 llvm-00c53caa339f954cb3590a05e8653b864b4355cf.tar.xz |
Use MachineInstr::readsWritesVirtualRegister to determine if a register is read.
This correctly handles partial redefines and undef uses.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104322 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MachineInstr.cpp')
-rw-r--r-- | lib/CodeGen/MachineInstr.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 595fddda6f..319059b4bb 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -782,27 +782,31 @@ 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 +/// readsWritesVirtualRegister - Return a pair of bools (reads, writes) +/// indicating if this instruction reads or writes Reg. This also considers +/// partial defines. +std::pair<bool,bool> +MachineInstr::readsWritesVirtualRegister(unsigned Reg, + SmallVectorImpl<unsigned> *Ops) const { + bool PartDef = false; // Partial redefine. + bool FullDef = false; // Full define. + bool Use = false; for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { const MachineOperand &MO = getOperand(i); if (!MO.isReg() || MO.getReg() != Reg) continue; + if (Ops) + Ops->push_back(i); if (MO.isUse()) - return true; - if (MO.getSubReg()) + Use |= !MO.isUndef(); + else 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; + // A partial redefine uses Reg unless there is also a full define. + return std::make_pair(Use || (PartDef && !FullDef), PartDef || FullDef); } /// findRegisterDefOperandIdx() - Returns the operand index that is a def of |