diff options
Diffstat (limited to 'llvm/lib/CodeGen/DeadMachineInstructionElim.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/DeadMachineInstructionElim.cpp | 49 |
1 files changed, 1 insertions, 48 deletions
diff --git a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp index 578854cdb4a5..836a912a5e98 100644 --- a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp +++ b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp @@ -38,7 +38,6 @@ public: bool runImpl(MachineFunction &MF); private: - bool isDead(const MachineInstr *MI) const; bool eliminateDeadMI(MachineFunction &MF); }; @@ -79,50 +78,6 @@ char &llvm::DeadMachineInstructionElimID = DeadMachineInstructionElim::ID; INITIALIZE_PASS(DeadMachineInstructionElim, DEBUG_TYPE, "Remove dead machine instructions", false, false) -bool DeadMachineInstructionElimImpl::isDead(const MachineInstr *MI) const { - // Technically speaking inline asm without side effects and no defs can still - // be deleted. But there is so much bad inline asm code out there, we should - // let them be. - if (MI->isInlineAsm()) - return false; - - // Don't delete frame allocation labels. - if (MI->getOpcode() == TargetOpcode::LOCAL_ESCAPE) - return false; - - // Don't delete instructions with side effects. - bool SawStore = false; - if (!MI->isSafeToMove(nullptr, SawStore) && !MI->isPHI()) - return false; - - // Examine each operand. - for (const MachineOperand &MO : MI->all_defs()) { - Register Reg = MO.getReg(); - if (Reg.isPhysical()) { - // Don't delete live physreg defs, or any reserved register defs. - if (!LivePhysRegs.available(Reg) || MRI->isReserved(Reg)) - return false; - } else { - if (MO.isDead()) { -#ifndef NDEBUG - // Basic check on the register. All of them should be 'undef'. - for (auto &U : MRI->use_nodbg_operands(Reg)) - assert(U.isUndef() && "'Undef' use on a 'dead' register is found!"); -#endif - continue; - } - for (const MachineInstr &Use : MRI->use_nodbg_instructions(Reg)) { - if (&Use != MI) - // This def has a non-debug use. Don't delete the instruction! - return false; - } - } - } - - // If there are no defs with uses, the instruction is dead. - return true; -} - bool DeadMachineInstructionElimImpl::runImpl(MachineFunction &MF) { MRI = &MF.getRegInfo(); @@ -149,7 +104,7 @@ bool DeadMachineInstructionElimImpl::eliminateDeadMI(MachineFunction &MF) { // liveness as we go. for (MachineInstr &MI : make_early_inc_range(reverse(*MBB))) { // If the instruction is dead, delete it! - if (isDead(&MI)) { + if (MI.isDead(*MRI, &LivePhysRegs)) { LLVM_DEBUG(dbgs() << "DeadMachineInstructionElim: DELETING: " << MI); // It is possible that some DBG_VALUE instructions refer to this // instruction. They will be deleted in the live debug variable @@ -159,11 +114,9 @@ bool DeadMachineInstructionElimImpl::eliminateDeadMI(MachineFunction &MF) { ++NumDeletes; continue; } - LivePhysRegs.stepBackward(MI); } } - LivePhysRegs.clear(); return AnyChanges; } |
