mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-23 02:29:18 +00:00
Add TargetInstrInfo::copyPhysReg hook and use it from LowerSubregs.
This target hook is intended to replace copyRegToReg entirely, but for now it calls copyRegToReg. Any remaining calls to copyRegToReg wil be replaced by COPY instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107854 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
515fe3a588
commit
3651d92d91
@ -369,7 +369,13 @@ public:
|
|||||||
assert(0 && "Target didn't implement TargetInstrInfo::copyRegToReg!");
|
assert(0 && "Target didn't implement TargetInstrInfo::copyRegToReg!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// copyPhysReg - Emit instructions to copy a pair of physical registers.
|
||||||
|
virtual void copyPhysReg(MachineBasicBlock &MBB,
|
||||||
|
MachineBasicBlock::iterator MI, DebugLoc DL,
|
||||||
|
unsigned DestReg, unsigned SrcReg,
|
||||||
|
bool KillSrc) const =0;
|
||||||
|
|
||||||
/// storeRegToStackSlot - Store the specified register of the given register
|
/// storeRegToStackSlot - Store the specified register of the given register
|
||||||
/// class to the specified stack frame index. The store instruction is to be
|
/// class to the specified stack frame index. The store instruction is to be
|
||||||
/// added to the given machine basic block before the specified machine
|
/// added to the given machine basic block before the specified machine
|
||||||
@ -661,6 +667,10 @@ public:
|
|||||||
|
|
||||||
virtual ScheduleHazardRecognizer *
|
virtual ScheduleHazardRecognizer *
|
||||||
CreateTargetPostRAHazardRecognizer(const InstrItineraryData&) const;
|
CreateTargetPostRAHazardRecognizer(const InstrItineraryData&) const;
|
||||||
|
virtual void copyPhysReg(MachineBasicBlock &MBB,
|
||||||
|
MachineBasicBlock::iterator MI, DebugLoc DL,
|
||||||
|
unsigned DestReg, unsigned SrcReg,
|
||||||
|
bool KillSrc) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
@ -85,7 +85,7 @@ LowerSubregsInstructionPass::TransferDeadFlag(MachineInstr *MI,
|
|||||||
if (MII->addRegisterDead(DstReg, TRI))
|
if (MII->addRegisterDead(DstReg, TRI))
|
||||||
break;
|
break;
|
||||||
assert(MII != MI->getParent()->begin() &&
|
assert(MII != MI->getParent()->begin() &&
|
||||||
"copyRegToReg output doesn't reference destination register!");
|
"copyPhysReg output doesn't reference destination register!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ LowerSubregsInstructionPass::TransferKillFlag(MachineInstr *MI,
|
|||||||
if (MII->addRegisterKilled(SrcReg, TRI, AddIfNotFound))
|
if (MII->addRegisterKilled(SrcReg, TRI, AddIfNotFound))
|
||||||
break;
|
break;
|
||||||
assert(MII != MI->getParent()->begin() &&
|
assert(MII != MI->getParent()->begin() &&
|
||||||
"copyRegToReg output doesn't reference source register!");
|
"copyPhysReg output doesn't reference source register!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,13 +155,7 @@ bool LowerSubregsInstructionPass::LowerExtract(MachineInstr *MI) {
|
|||||||
|
|
||||||
DEBUG(dbgs() << "subreg: eliminated!");
|
DEBUG(dbgs() << "subreg: eliminated!");
|
||||||
} else {
|
} else {
|
||||||
// Insert copy
|
TII->copyPhysReg(*MBB, MI, MI->getDebugLoc(), DstReg, SrcReg, false);
|
||||||
const TargetRegisterClass *TRCS = TRI->getPhysicalRegisterRegClass(DstReg);
|
|
||||||
const TargetRegisterClass *TRCD = TRI->getPhysicalRegisterRegClass(SrcReg);
|
|
||||||
bool Emitted = TII->copyRegToReg(*MBB, MI, DstReg, SrcReg, TRCD, TRCS,
|
|
||||||
MI->getDebugLoc());
|
|
||||||
(void)Emitted;
|
|
||||||
assert(Emitted && "Subreg and Dst must be of compatible register class");
|
|
||||||
// Transfer the kill/dead flags, if needed.
|
// Transfer the kill/dead flags, if needed.
|
||||||
if (MI->getOperand(0).isDead())
|
if (MI->getOperand(0).isDead())
|
||||||
TransferDeadFlag(MI, DstReg, TRI);
|
TransferDeadFlag(MI, DstReg, TRI);
|
||||||
@ -215,18 +209,11 @@ bool LowerSubregsInstructionPass::LowerSubregToReg(MachineInstr *MI) {
|
|||||||
}
|
}
|
||||||
DEBUG(dbgs() << "subreg: eliminated!");
|
DEBUG(dbgs() << "subreg: eliminated!");
|
||||||
} else {
|
} else {
|
||||||
// Insert sub-register copy
|
TII->copyPhysReg(*MBB, MI, MI->getDebugLoc(), DstSubReg, InsReg,
|
||||||
const TargetRegisterClass *TRC0= TRI->getPhysicalRegisterRegClass(DstSubReg);
|
MI->getOperand(2).isKill());
|
||||||
const TargetRegisterClass *TRC1= TRI->getPhysicalRegisterRegClass(InsReg);
|
|
||||||
bool Emitted = TII->copyRegToReg(*MBB, MI, DstSubReg, InsReg, TRC0, TRC1,
|
|
||||||
MI->getDebugLoc());
|
|
||||||
(void)Emitted;
|
|
||||||
assert(Emitted && "Subreg and Dst must be of compatible register class");
|
|
||||||
// Transfer the kill/dead flags, if needed.
|
// Transfer the kill/dead flags, if needed.
|
||||||
if (MI->getOperand(0).isDead())
|
if (MI->getOperand(0).isDead())
|
||||||
TransferDeadFlag(MI, DstSubReg, TRI);
|
TransferDeadFlag(MI, DstSubReg, TRI);
|
||||||
if (MI->getOperand(2).isKill())
|
|
||||||
TransferKillFlag(MI, InsReg, TRI);
|
|
||||||
DEBUG({
|
DEBUG({
|
||||||
MachineBasicBlock::iterator dMI = MI;
|
MachineBasicBlock::iterator dMI = MI;
|
||||||
dbgs() << "subreg: " << *(--dMI);
|
dbgs() << "subreg: " << *(--dMI);
|
||||||
@ -280,18 +267,13 @@ bool LowerSubregsInstructionPass::LowerInsert(MachineInstr *MI) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Insert sub-register copy
|
// Insert sub-register copy
|
||||||
const TargetRegisterClass *TRC0= TRI->getPhysicalRegisterRegClass(DstSubReg);
|
|
||||||
const TargetRegisterClass *TRC1= TRI->getPhysicalRegisterRegClass(InsReg);
|
|
||||||
if (MI->getOperand(2).isUndef())
|
if (MI->getOperand(2).isUndef())
|
||||||
// If the source register being inserted is undef, then this becomes a
|
// If the source register being inserted is undef, then this becomes a
|
||||||
// KILL.
|
// KILL.
|
||||||
BuildMI(*MBB, MI, MI->getDebugLoc(),
|
BuildMI(*MBB, MI, MI->getDebugLoc(),
|
||||||
TII->get(TargetOpcode::KILL), DstSubReg);
|
TII->get(TargetOpcode::KILL), DstSubReg);
|
||||||
else {
|
else {
|
||||||
bool Emitted = TII->copyRegToReg(*MBB, MI, DstSubReg, InsReg, TRC0, TRC1,
|
TII->copyPhysReg(*MBB, MI, MI->getDebugLoc(), DstSubReg, InsReg, false);
|
||||||
MI->getDebugLoc());
|
|
||||||
(void)Emitted;
|
|
||||||
assert(Emitted && "Subreg and Dst must be of compatible register class");
|
|
||||||
}
|
}
|
||||||
MachineBasicBlock::iterator CopyMI = MI;
|
MachineBasicBlock::iterator CopyMI = MI;
|
||||||
--CopyMI;
|
--CopyMI;
|
||||||
@ -343,21 +325,11 @@ bool LowerSubregsInstructionPass::LowerCopy(MachineInstr *MI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEBUG(dbgs() << "real copy: " << *MI);
|
DEBUG(dbgs() << "real copy: " << *MI);
|
||||||
// Ask target for a lowered copy instruction.
|
TII->copyPhysReg(*MI->getParent(), MI, MI->getDebugLoc(),
|
||||||
const TargetRegisterClass *DstRC =
|
DstMO.getReg(), SrcMO.getReg(), SrcMO.isKill());
|
||||||
TRI->getPhysicalRegisterRegClass(DstMO.getReg());
|
|
||||||
const TargetRegisterClass *SrcRC =
|
|
||||||
TRI->getPhysicalRegisterRegClass(SrcMO.getReg());
|
|
||||||
bool Emitted = TII->copyRegToReg(*MI->getParent(), MI,
|
|
||||||
DstMO.getReg(), SrcMO.getReg(),
|
|
||||||
DstRC, SrcRC, MI->getDebugLoc());
|
|
||||||
(void)Emitted;
|
|
||||||
assert(Emitted && "Cannot emit copy");
|
|
||||||
|
|
||||||
if (DstMO.isDead())
|
if (DstMO.isDead())
|
||||||
TransferDeadFlag(MI, DstMO.getReg(), TRI);
|
TransferDeadFlag(MI, DstMO.getReg(), TRI);
|
||||||
if (SrcMO.isKill())
|
|
||||||
TransferKillFlag(MI, SrcMO.getReg(), TRI, true);
|
|
||||||
if (MI->getNumOperands() > 2)
|
if (MI->getNumOperands() > 2)
|
||||||
TransferImplicitDefs(MI);
|
TransferImplicitDefs(MI);
|
||||||
DEBUG({
|
DEBUG({
|
||||||
|
@ -365,3 +365,20 @@ ScheduleHazardRecognizer *TargetInstrInfoImpl::
|
|||||||
CreateTargetPostRAHazardRecognizer(const InstrItineraryData &II) const {
|
CreateTargetPostRAHazardRecognizer(const InstrItineraryData &II) const {
|
||||||
return (ScheduleHazardRecognizer *)new PostRAHazardRecognizer(II);
|
return (ScheduleHazardRecognizer *)new PostRAHazardRecognizer(II);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default implementation of copyPhysReg using copyRegToReg.
|
||||||
|
void TargetInstrInfoImpl::copyPhysReg(MachineBasicBlock &MBB,
|
||||||
|
MachineBasicBlock::iterator MI,
|
||||||
|
DebugLoc DL,
|
||||||
|
unsigned DestReg, unsigned SrcReg,
|
||||||
|
bool KillSrc) const {
|
||||||
|
assert(TargetRegisterInfo::isPhysicalRegister(DestReg));
|
||||||
|
assert(TargetRegisterInfo::isPhysicalRegister(SrcReg));
|
||||||
|
const TargetRegisterInfo *TRI = MBB.getParent()->getTarget().getRegisterInfo();
|
||||||
|
const TargetRegisterClass *DRC = TRI->getPhysicalRegisterRegClass(DestReg);
|
||||||
|
const TargetRegisterClass *SRC = TRI->getPhysicalRegisterRegClass(SrcReg);
|
||||||
|
if (!copyRegToReg(MBB, MI, DestReg, SrcReg, DRC, SRC, DL))
|
||||||
|
llvm_unreachable("Cannot emit physreg copy instruction");
|
||||||
|
if (KillSrc)
|
||||||
|
llvm::prior(MI)->addRegisterKilled(SrcReg, TRI, true);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user