forked from OSchip/llvm-project
Convert COPY instructions into KILLs if they have implicit defs.
MachineCopyPropagation doesn't understand super-register liveness well enough to be able to remove implicit defs of super-registers. This fixes a problem in ARM/2012-01-26-CopyPropKills.ll that is exposed by an future TwoAddressInstructionPass change. The KILL instructions are removed before the machine code is emitted. llvm-svn: 169060
This commit is contained in:
parent
0517508c00
commit
bb1e98318f
|
@ -17,6 +17,7 @@
|
||||||
#include "llvm/CodeGen/MachineFunction.h"
|
#include "llvm/CodeGen/MachineFunction.h"
|
||||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||||
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
||||||
|
#include "llvm/Target/TargetInstrInfo.h"
|
||||||
#include "llvm/Target/TargetRegisterInfo.h"
|
#include "llvm/Target/TargetRegisterInfo.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
|
@ -32,6 +33,7 @@ STATISTIC(NumDeletes, "Number of dead copies deleted");
|
||||||
namespace {
|
namespace {
|
||||||
class MachineCopyPropagation : public MachineFunctionPass {
|
class MachineCopyPropagation : public MachineFunctionPass {
|
||||||
const TargetRegisterInfo *TRI;
|
const TargetRegisterInfo *TRI;
|
||||||
|
const TargetInstrInfo *TII;
|
||||||
MachineRegisterInfo *MRI;
|
MachineRegisterInfo *MRI;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -50,6 +52,7 @@ namespace {
|
||||||
SourceMap &SrcMap,
|
SourceMap &SrcMap,
|
||||||
DenseMap<unsigned, MachineInstr*> &AvailCopyMap);
|
DenseMap<unsigned, MachineInstr*> &AvailCopyMap);
|
||||||
bool CopyPropagateBlock(MachineBasicBlock &MBB);
|
bool CopyPropagateBlock(MachineBasicBlock &MBB);
|
||||||
|
void removeCopy(MachineInstr *MI);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
char MachineCopyPropagation::ID = 0;
|
char MachineCopyPropagation::ID = 0;
|
||||||
|
@ -123,6 +126,16 @@ static bool isNopCopy(MachineInstr *CopyMI, unsigned Def, unsigned Src,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove MI from the function because it has been determined it is dead.
|
||||||
|
// Turn it into a noop KILL instruction if it has super-register liveness
|
||||||
|
// adjustments.
|
||||||
|
void MachineCopyPropagation::removeCopy(MachineInstr *MI) {
|
||||||
|
if (MI->getNumOperands() == 2)
|
||||||
|
MI->eraseFromParent();
|
||||||
|
else
|
||||||
|
MI->setDesc(TII->get(TargetOpcode::KILL));
|
||||||
|
}
|
||||||
|
|
||||||
bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
|
bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
|
||||||
SmallSetVector<MachineInstr*, 8> MaybeDeadCopies; // Candidates for deletion
|
SmallSetVector<MachineInstr*, 8> MaybeDeadCopies; // Candidates for deletion
|
||||||
DenseMap<unsigned, MachineInstr*> AvailCopyMap; // Def -> available copies map
|
DenseMap<unsigned, MachineInstr*> AvailCopyMap; // Def -> available copies map
|
||||||
|
@ -168,7 +181,7 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
|
||||||
for (MachineBasicBlock::iterator I = CopyMI, E = MI; I != E; ++I)
|
for (MachineBasicBlock::iterator I = CopyMI, E = MI; I != E; ++I)
|
||||||
I->clearRegisterKills(Def, TRI);
|
I->clearRegisterKills(Def, TRI);
|
||||||
|
|
||||||
MI->eraseFromParent();
|
removeCopy(MI);
|
||||||
Changed = true;
|
Changed = true;
|
||||||
++NumDeletes;
|
++NumDeletes;
|
||||||
continue;
|
continue;
|
||||||
|
@ -261,7 +274,7 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
|
||||||
unsigned Reg = (*DI)->getOperand(0).getReg();
|
unsigned Reg = (*DI)->getOperand(0).getReg();
|
||||||
if (MRI->isReserved(Reg) || !MaskMO.clobbersPhysReg(Reg))
|
if (MRI->isReserved(Reg) || !MaskMO.clobbersPhysReg(Reg))
|
||||||
continue;
|
continue;
|
||||||
(*DI)->eraseFromParent();
|
removeCopy(*DI);
|
||||||
Changed = true;
|
Changed = true;
|
||||||
++NumDeletes;
|
++NumDeletes;
|
||||||
}
|
}
|
||||||
|
@ -297,7 +310,7 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
|
||||||
DI = MaybeDeadCopies.begin(), DE = MaybeDeadCopies.end();
|
DI = MaybeDeadCopies.begin(), DE = MaybeDeadCopies.end();
|
||||||
DI != DE; ++DI) {
|
DI != DE; ++DI) {
|
||||||
if (!MRI->isReserved((*DI)->getOperand(0).getReg())) {
|
if (!MRI->isReserved((*DI)->getOperand(0).getReg())) {
|
||||||
(*DI)->eraseFromParent();
|
removeCopy(*DI);
|
||||||
Changed = true;
|
Changed = true;
|
||||||
++NumDeletes;
|
++NumDeletes;
|
||||||
}
|
}
|
||||||
|
@ -311,6 +324,7 @@ bool MachineCopyPropagation::runOnMachineFunction(MachineFunction &MF) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
|
|
||||||
TRI = MF.getTarget().getRegisterInfo();
|
TRI = MF.getTarget().getRegisterInfo();
|
||||||
|
TII = MF.getTarget().getInstrInfo();
|
||||||
MRI = &MF.getRegInfo();
|
MRI = &MF.getRegInfo();
|
||||||
|
|
||||||
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
|
||||||
|
|
Loading…
Reference in New Issue