mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 07:31:53 +00:00
make CR spill and restore 64-bit clean (no functional change), and fix some other problems found with -verify-machineinstrs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146024 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6d0e014b1f
commit
234bb38d6c
@ -365,11 +365,12 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
||||
}
|
||||
|
||||
case PPC::MFCRpseud:
|
||||
case PPC::MFCR8pseud:
|
||||
// Transform: %R3 = MFCRpseud %CR7
|
||||
// Into: %R3 = MFCR ;; cr7
|
||||
OutStreamer.AddComment(PPCInstPrinter::
|
||||
getRegisterName(MI->getOperand(1).getReg()));
|
||||
TmpInst.setOpcode(PPC::MFCR);
|
||||
TmpInst.setOpcode(Subtarget.isPPC64() ? PPC::MFCR8 : PPC::MFCR);
|
||||
TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
|
||||
OutStreamer.EmitInstruction(TmpInst);
|
||||
return;
|
||||
|
@ -138,7 +138,8 @@ void PPCCodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
|
||||
unsigned PPCCodeEmitter::get_crbitm_encoding(const MachineInstr &MI,
|
||||
unsigned OpNo) const {
|
||||
const MachineOperand &MO = MI.getOperand(OpNo);
|
||||
assert((MI.getOpcode() == PPC::MTCRF || MI.getOpcode() == PPC::MFOCRF) &&
|
||||
assert((MI.getOpcode() == PPC::MTCRF || MI.getOpcode() == PPC::MTCRF8 ||
|
||||
MI.getOpcode() == PPC::MFOCRF) &&
|
||||
(MO.getReg() >= PPC::CR0 && MO.getReg() <= PPC::CR7));
|
||||
return 0x80 >> getPPCRegisterNumbering(MO.getReg());
|
||||
}
|
||||
@ -248,7 +249,8 @@ unsigned PPCCodeEmitter::getMachineOpValue(const MachineInstr &MI,
|
||||
if (MO.isReg()) {
|
||||
// MTCRF/MFOCRF should go through get_crbitm_encoding for the CR operand.
|
||||
// The GPR operand should come through here though.
|
||||
assert((MI.getOpcode() != PPC::MTCRF && MI.getOpcode() != PPC::MFOCRF) ||
|
||||
assert((MI.getOpcode() != PPC::MTCRF && MI.getOpcode() != PPC::MTCRF8 &&
|
||||
MI.getOpcode() != PPC::MFOCRF) ||
|
||||
MO.getReg() < PPC::CR0 || MO.getReg() > PPC::CR7);
|
||||
return getPPCRegisterNumbering(MO.getReg());
|
||||
}
|
||||
|
@ -223,6 +223,18 @@ def : Pat<(PPCtc_return (i64 texternalsym:$dst), imm:$imm),
|
||||
def : Pat<(PPCtc_return CTRRC8:$dst, imm:$imm),
|
||||
(TCRETURNri8 CTRRC8:$dst, imm:$imm)>;
|
||||
|
||||
// 64-but CR instructions
|
||||
def MTCRF8 : XFXForm_5<31, 144, (outs crbitm:$FXM), (ins G8RC:$rS),
|
||||
"mtcrf $FXM, $rS", BrMCRX>,
|
||||
PPC970_MicroCode, PPC970_Unit_CRU;
|
||||
|
||||
def MFCR8pseud: XFXForm_3<31, 19, (outs G8RC:$rT), (ins crbitm:$FXM),
|
||||
"", SprMFCR>,
|
||||
PPC970_MicroCode, PPC970_Unit_CRU;
|
||||
|
||||
def MFCR8 : XFXForm_3<31, 19, (outs G8RC:$rT), (ins),
|
||||
"mfcr $rT", SprMFCR>,
|
||||
PPC970_MicroCode, PPC970_Unit_CRU;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// 64-bit SPR manipulation instrs.
|
||||
@ -469,6 +481,12 @@ def RLDICR : MDForm_1<30, 1,
|
||||
(outs G8RC:$rA), (ins G8RC:$rS, u6imm:$SH, u6imm:$ME),
|
||||
"rldicr $rA, $rS, $SH, $ME", IntRotateD,
|
||||
[]>, isPPC64;
|
||||
|
||||
def RLWINM8 : MForm_2<21,
|
||||
(outs G8RC:$rA), (ins G8RC:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
|
||||
"rlwinm $rA, $rS, $SH, $MB, $ME", IntGeneral,
|
||||
[]>;
|
||||
|
||||
} // End FXU Operations.
|
||||
|
||||
|
||||
|
@ -410,11 +410,14 @@ PPCInstrInfo::StoreRegToStackSlot(MachineFunction &MF,
|
||||
// We hack this on Darwin by reserving R2. It's probably broken on Linux
|
||||
// at the moment.
|
||||
|
||||
bool is64Bit = TM.getSubtargetImpl()->isPPC64();
|
||||
// We need to store the CR in the low 4-bits of the saved value. First,
|
||||
// issue a MFCR to save all of the CRBits.
|
||||
unsigned ScratchReg = TM.getSubtargetImpl()->isDarwinABI() ?
|
||||
PPC::R2 : PPC::R0;
|
||||
NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFCRpseud), ScratchReg)
|
||||
(is64Bit ? PPC::X2 : PPC::R2) :
|
||||
(is64Bit ? PPC::X0 : PPC::R0);
|
||||
NewMIs.push_back(BuildMI(MF, DL, get(is64Bit ? PPC::MFCR8pseud :
|
||||
PPC::MFCRpseud), ScratchReg)
|
||||
.addReg(SrcReg, getKillRegState(isKill)));
|
||||
|
||||
// If the saved register wasn't CR0, shift the bits left so that they are
|
||||
@ -422,12 +425,14 @@ PPCInstrInfo::StoreRegToStackSlot(MachineFunction &MF,
|
||||
if (SrcReg != PPC::CR0) {
|
||||
unsigned ShiftBits = getPPCRegisterNumbering(SrcReg)*4;
|
||||
// rlwinm scratch, scratch, ShiftBits, 0, 31.
|
||||
NewMIs.push_back(BuildMI(MF, DL, get(PPC::RLWINM), ScratchReg)
|
||||
NewMIs.push_back(BuildMI(MF, DL, get(is64Bit ? PPC::RLWINM8 :
|
||||
PPC::RLWINM), ScratchReg)
|
||||
.addReg(ScratchReg).addImm(ShiftBits)
|
||||
.addImm(0).addImm(31));
|
||||
}
|
||||
|
||||
NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
|
||||
NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(is64Bit ?
|
||||
PPC::STW8 : PPC::STW))
|
||||
.addReg(ScratchReg,
|
||||
getKillRegState(isKill)),
|
||||
FrameIdx));
|
||||
@ -568,7 +573,8 @@ PPCInstrInfo::LoadRegFromStackSlot(MachineFunction &MF, DebugLoc DL,
|
||||
.addImm(31));
|
||||
}
|
||||
|
||||
NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTCRF), DestReg)
|
||||
NewMIs.push_back(BuildMI(MF, DL, get(TM.getSubtargetImpl()->isPPC64() ?
|
||||
PPC::MTCRF8 : PPC::MTCRF), DestReg)
|
||||
.addReg(ScratchReg));
|
||||
}
|
||||
} else if (PPC::CRBITRCRegisterClass->hasSubClassEq(RC)) {
|
||||
|
@ -1098,7 +1098,7 @@ def MFVRSAVE : XFXForm_1_ext<31, 339, 256, (outs GPRC:$rT), (ins),
|
||||
"mfspr $rT, 256", IntGeneral>,
|
||||
PPC970_DGroup_First, PPC970_Unit_FXU;
|
||||
|
||||
def MTCRF : XFXForm_5<31, 144, (outs), (ins crbitm:$FXM, GPRC:$rS),
|
||||
def MTCRF : XFXForm_5<31, 144, (outs crbitm:$FXM), (ins GPRC:$rS),
|
||||
"mtcrf $FXM, $rS", BrMCRX>,
|
||||
PPC970_MicroCode, PPC970_Unit_CRU;
|
||||
|
||||
|
@ -473,14 +473,14 @@ void PPCRegisterInfo::lowerCRSpilling(MachineBasicBlock::iterator II,
|
||||
|
||||
// We need to store the CR in the low 4-bits of the saved value. First, issue
|
||||
// an MFCRpsued to save all of the CRBits and, if needed, kill the SrcReg.
|
||||
BuildMI(MBB, II, dl, TII.get(PPC::MFCRpseud), Reg)
|
||||
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFCR8pseud : PPC::MFCRpseud), Reg)
|
||||
.addReg(SrcReg, getKillRegState(MI.getOperand(0).isKill()));
|
||||
|
||||
// If the saved register wasn't CR0, shift the bits left so that they are in
|
||||
// CR0's slot.
|
||||
if (SrcReg != PPC::CR0)
|
||||
// rlwinm rA, rA, ShiftBits, 0, 31.
|
||||
BuildMI(MBB, II, dl, TII.get(PPC::RLWINM), Reg)
|
||||
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
|
||||
.addReg(Reg, RegState::Kill)
|
||||
.addImm(getPPCRegisterNumbering(SrcReg) * 4)
|
||||
.addImm(0)
|
||||
@ -525,7 +525,7 @@ void PPCRegisterInfo::lowerCRRestore(MachineBasicBlock::iterator II,
|
||||
.addImm(31);
|
||||
}
|
||||
|
||||
BuildMI(MBB, II, dl, TII.get(PPC::MTCRF), DestReg)
|
||||
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MTCRF8 : PPC::MTCRF), DestReg)
|
||||
.addReg(Reg);
|
||||
|
||||
// Discard the pseudo instruction.
|
||||
|
Loading…
Reference in New Issue
Block a user