diff options
author | Bill Wendling <isanbard@gmail.com> | 2008-03-03 22:14:33 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2008-03-03 22:14:33 +0000 |
commit | 4a23d72ec21d1bdfda69fd16c9fc10cec39f1fed (patch) | |
tree | 9c389feb5a86806008b3c005a0e31a6fd8d3c020 /lib/CodeGen/MachineInstr.cpp | |
parent | a0a570cec647b860a724f4f70a191bc83cdcc947 (diff) |
Go through the machine instruction's operands to make sure that we're not
marking both a super- and sub-register as "killed". This removes implicit uses
that are marked as "killed".
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47862 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MachineInstr.cpp')
-rw-r--r-- | lib/CodeGen/MachineInstr.cpp | 64 |
1 files changed, 52 insertions, 12 deletions
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 52c42b3f11..b0a225831c 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -678,34 +678,74 @@ void MachineInstr::print(std::ostream &OS, const TargetMachine *TM) const { bool MachineInstr::addRegisterKilled(unsigned IncomingReg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound) { - bool Found = false; - for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { + // Go through the machine instruction's operands to eliminate any potentially + // illegal conditions. I.e., a super- and sub-register both marked "kill". + Restart: + for (unsigned i = 0, e = getNumOperands(); i < e; ++i) { MachineOperand &MO = getOperand(i); + if (MO.isRegister() && MO.isUse()) { unsigned Reg = MO.getReg(); - if (!Reg) + + if (!Reg || IncomingReg == Reg || + !TargetRegisterInfo::isPhysicalRegister(Reg) || + !TargetRegisterInfo::isPhysicalRegister(IncomingReg)) continue; + + if (RegInfo->isSubRegister(IncomingReg, Reg)) { + if (MO.isKill()) { + if (MO.isImplicit()) { + // Remove this implicit use that marks the sub-register "kill". Let + // the super-register take care of this information. + RemoveOperand(i); + goto Restart; // Instruction was modified, redo checking. + } else { + // The super-register is going to take care of this kill + // information. + MO.setIsKill(false); + } + } + } else if (RegInfo->isSuperRegister(IncomingReg, Reg) && MO.isKill()) { + // The kill information is already handled by a super-register. Don't + // add this sub-register as a kill. + return true; + } + } + } + + // If the register already exists, then make sure it or its super-register is + // marked "kill". + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { + MachineOperand &MO = getOperand(i); + + if (MO.isRegister() && MO.isUse()) { + unsigned Reg = MO.getReg(); + if (!Reg) continue; + if (Reg == IncomingReg) { MO.setIsKill(); - Found = true; - break; + return true; } else if (TargetRegisterInfo::isPhysicalRegister(Reg) && TargetRegisterInfo::isPhysicalRegister(IncomingReg) && RegInfo->isSuperRegister(IncomingReg, Reg) && - MO.isKill()) + MO.isKill()) { // A super-register kill already exists. - Found = true; + return true; + } } } - // If not found, this means an alias of one of the operand is killed. Add a + // If not found, this means an alias of one of the operands is killed. Add a // new implicit operand if required. - if (!Found && AddIfNotFound) { - addOperand(MachineOperand::CreateReg(IncomingReg, false/*IsDef*/, - true/*IsImp*/,true/*IsKill*/)); + if (AddIfNotFound) { + addOperand(MachineOperand::CreateReg(IncomingReg, + false /*IsDef*/, + true /*IsImp*/, + true /*IsKill*/)); return true; } - return Found; + + return false; } bool MachineInstr::addRegisterDead(unsigned IncomingReg, |