43 #define DEBUG_TYPE "ppc-instr-info"
45 #define GET_INSTRMAP_INFO
46 #define GET_INSTRINFO_CTOR_DTOR
47 #include "PPCGenInstrInfo.inc"
51 cl::desc(
"Disable analysis for CTR loops"));
57 cl::desc(
"Causes the backend to crash instead of generating a nop VSX copy"),
62 cl::desc(
"Use the old (incorrect) instruction latency calculation"));
65 void PPCInstrInfo::anchor() {}
70 STI.isPPC64() ? PPC::BLR8 : PPC::BLR),
71 Subtarget(STI), RI(STI.getTargetMachine()) {}
79 static_cast<const PPCSubtarget *
>(STI)->getDarwinDirective();
83 static_cast<const PPCSubtarget *
>(STI)->getInstrItineraryData();
115 unsigned *PredCost)
const {
117 return PPCGenInstrInfo::getInstrLatency(ItinData, MI, PredCost);
137 Latency =
std::max(Latency, (
unsigned) Cycle);
146 unsigned UseIdx)
const {
147 int Latency = PPCGenInstrInfo::getOperandLatency(ItinData, DefMI, DefIdx,
163 IsRegCR = PPC::CRRCRegClass.contains(Reg) ||
164 PPC::CRBITRCRegClass.contains(Reg);
252 unsigned &SrcReg,
unsigned &DstReg,
253 unsigned &SubIdx)
const {
255 default:
return false;
257 case PPC::EXTSW_32_64:
260 SubIdx = PPC::sub_32;
274 case PPC::RESTORE_CR:
275 case PPC::RESTORE_CRBIT:
282 case PPC::RESTORE_VRSAVE:
310 case PPC::ADDIStocHA:
312 case PPC::LOAD_STACK_GUARD:
328 case PPC::SPILL_CRBIT:
335 case PPC::SPILL_VRSAVE:
350 unsigned OpIdx2)
const {
373 assert(((OpIdx1 == 1 && OpIdx2 == 2) || (OpIdx1 == 2 && OpIdx2 == 1)) &&
374 "Only the operands 1 and 2 can be swapped in RLSIMI/RLWIMIo.");
382 bool ChangeReg0 =
false;
388 "Expecting a two-address instruction!");
400 if (MB == 0 && ME == 31)
411 .addImm((ME + 1) & 31)
412 .addImm((MB - 1) & 31);
433 unsigned &SrcOpIdx2)
const {
444 return fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 2, 3);
454 default: Opcode = PPC::NOP;
break;
463 BuildMI(MBB, MI, DL,
get(Opcode));
478 bool AllowModify)
const {
479 bool isPPC64 = Subtarget.
isPPC64();
499 }
else if (LastInst.
getOpcode() == PPC::BCC) {
507 }
else if (LastInst.
getOpcode() == PPC::BC) {
515 }
else if (LastInst.
getOpcode() == PPC::BCn) {
523 }
else if (LastInst.
getOpcode() == PPC::BDNZ8 ||
534 }
else if (LastInst.
getOpcode() == PPC::BDZ8 ||
559 if (SecondLastInst.
getOpcode() == PPC::BCC &&
569 }
else if (SecondLastInst.
getOpcode() == PPC::BC &&
579 }
else if (SecondLastInst.
getOpcode() == PPC::BCn &&
589 }
else if ((SecondLastInst.
getOpcode() == PPC::BDNZ8 ||
603 }
else if ((SecondLastInst.
getOpcode() == PPC::BDZ8 ||
627 I->eraseFromParent();
636 int *BytesRemoved)
const {
637 assert(!BytesRemoved &&
"code size not handled");
643 if (I->getOpcode() !=
PPC::B && I->getOpcode() != PPC::BCC &&
644 I->getOpcode() != PPC::BC && I->getOpcode() != PPC::BCn &&
645 I->getOpcode() != PPC::BDNZ8 && I->getOpcode() !=
PPC::BDNZ &&
646 I->getOpcode() != PPC::BDZ8 && I->getOpcode() !=
PPC::BDZ)
650 I->eraseFromParent();
654 if (I == MBB.
begin())
return 1;
656 if (I->getOpcode() != PPC::BCC &&
657 I->getOpcode() != PPC::BC && I->getOpcode() != PPC::BCn &&
658 I->getOpcode() != PPC::BDNZ8 && I->getOpcode() !=
PPC::BDNZ &&
659 I->getOpcode() != PPC::BDZ8 && I->getOpcode() !=
PPC::BDZ)
663 I->eraseFromParent();
672 int *BytesAdded)
const {
674 assert(TBB &&
"insertBranch must not be told to insert a fallthrough");
676 "PPC branch conditions have two components!");
677 assert(!BytesAdded &&
"code size not handled");
679 bool isPPC64 = Subtarget.
isPPC64();
685 else if (Cond[1].
getReg() == PPC::CTR || Cond[1].getReg() == PPC::CTR8)
686 BuildMI(&MBB, DL,
get(Cond[0].getImm() ?
688 (isPPC64 ? PPC::BDZ8 :
PPC::BDZ))).addMBB(TBB);
690 BuildMI(&MBB, DL,
get(PPC::BC)).
add(Cond[1]).addMBB(TBB);
694 BuildMI(&MBB, DL,
get(PPC::BCC))
702 if (Cond[1].
getReg() == PPC::CTR || Cond[1].
getReg() == PPC::CTR8)
703 BuildMI(&MBB, DL,
get(Cond[0].getImm() ?
711 BuildMI(&MBB, DL,
get(PPC::BCC))
722 unsigned TrueReg,
unsigned FalseReg,
723 int &CondCycles,
int &TrueCycles,
int &FalseCycles)
const {
724 if (Cond.
size() != 2)
729 if (Cond[1].
getReg() == PPC::CTR || Cond[1].getReg() == PPC::CTR8)
740 if (!PPC::GPRCRegClass.hasSubClassEq(RC) &&
741 !PPC::GPRC_NOR0RegClass.hasSubClassEq(RC) &&
742 !PPC::G8RCRegClass.hasSubClassEq(RC) &&
743 !PPC::G8RC_NOX0RegClass.hasSubClassEq(RC))
759 const DebugLoc &dl,
unsigned DestReg,
761 unsigned FalseReg)
const {
763 "PPC branch conditions have two components!");
768 RI.getCommonSubClass(MRI.getRegClass(TrueReg), MRI.getRegClass(FalseReg));
769 assert(RC &&
"TrueReg and FalseReg must have overlapping register classes");
771 bool Is64Bit = PPC::G8RCRegClass.hasSubClassEq(RC) ||
772 PPC::G8RC_NOX0RegClass.hasSubClassEq(RC);
774 PPC::GPRCRegClass.hasSubClassEq(RC) ||
775 PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) &&
776 "isel is for regular integer GPRs only");
778 unsigned OpCode = Is64Bit ? PPC::ISEL8 : PPC::ISEL;
782 bool SwapOps =
false;
783 switch (SelectPred) {
787 SubIdx = PPC::sub_eq; SwapOps =
false;
break;
791 SubIdx = PPC::sub_eq; SwapOps =
true;
break;
795 SubIdx = PPC::sub_lt; SwapOps =
false;
break;
799 SubIdx = PPC::sub_lt; SwapOps =
true;
break;
803 SubIdx = PPC::sub_gt; SwapOps =
false;
break;
807 SubIdx = PPC::sub_gt; SwapOps =
true;
break;
811 SubIdx = PPC::sub_un; SwapOps =
false;
break;
815 SubIdx = PPC::sub_un; SwapOps =
true;
break;
820 unsigned FirstReg = SwapOps ? FalseReg : TrueReg,
821 SecondReg = SwapOps ? TrueReg : FalseReg;
826 if (MRI.getRegClass(FirstReg)->contains(PPC::R0) ||
827 MRI.getRegClass(FirstReg)->contains(PPC::X0)) {
829 MRI.getRegClass(FirstReg)->
contains(PPC::X0) ?
830 &PPC::G8RC_NOX0RegClass : &PPC::GPRC_NOR0RegClass;
831 unsigned OldFirstReg = FirstReg;
832 FirstReg = MRI.createVirtualRegister(FirstRC);
833 BuildMI(MBB, MI, dl,
get(TargetOpcode::COPY), FirstReg)
837 BuildMI(MBB, MI, dl,
get(OpCode), DestReg)
844 if (CRBit == PPC::CR0LT || CRBit == PPC::CR1LT ||
845 CRBit == PPC::CR2LT || CRBit == PPC::CR3LT ||
846 CRBit == PPC::CR4LT || CRBit == PPC::CR5LT ||
847 CRBit == PPC::CR6LT || CRBit == PPC::CR7LT)
849 if (CRBit == PPC::CR0GT || CRBit == PPC::CR1GT ||
850 CRBit == PPC::CR2GT || CRBit == PPC::CR3GT ||
851 CRBit == PPC::CR4GT || CRBit == PPC::CR5GT ||
852 CRBit == PPC::CR6GT || CRBit == PPC::CR7GT)
854 if (CRBit == PPC::CR0EQ || CRBit == PPC::CR1EQ ||
855 CRBit == PPC::CR2EQ || CRBit == PPC::CR3EQ ||
856 CRBit == PPC::CR4EQ || CRBit == PPC::CR5EQ ||
857 CRBit == PPC::CR6EQ || CRBit == PPC::CR7EQ)
859 if (CRBit == PPC::CR0UN || CRBit == PPC::CR1UN ||
860 CRBit == PPC::CR2UN || CRBit == PPC::CR3UN ||
861 CRBit == PPC::CR4UN || CRBit == PPC::CR5UN ||
862 CRBit == PPC::CR6UN || CRBit == PPC::CR7UN)
865 assert(Ret != 4 &&
"Invalid CR bit register");
872 unsigned SrcReg,
bool KillSrc)
const {
876 if (PPC::F8RCRegClass.
contains(DestReg) &&
877 PPC::VSRCRegClass.
contains(SrcReg)) {
885 }
else if (PPC::F8RCRegClass.
contains(SrcReg) &&
886 PPC::VSRCRegClass.
contains(DestReg)) {
897 if (PPC::CRBITRCRegClass.
contains(SrcReg) &&
898 PPC::GPRCRegClass.
contains(DestReg)) {
904 BuildMI(MBB, I, DL,
get(PPC::RLWINM), DestReg)
910 }
else if (PPC::CRRCRegClass.
contains(SrcReg) &&
911 PPC::G8RCRegClass.
contains(DestReg)) {
912 BuildMI(MBB, I, DL,
get(PPC::MFOCRF8), DestReg).
addReg(SrcReg);
915 }
else if (PPC::CRRCRegClass.
contains(SrcReg) &&
916 PPC::GPRCRegClass.
contains(DestReg)) {
923 if (PPC::GPRCRegClass.
contains(DestReg, SrcReg))
925 else if (PPC::G8RCRegClass.
contains(DestReg, SrcReg))
927 else if (PPC::F4RCRegClass.
contains(DestReg, SrcReg))
929 else if (PPC::CRRCRegClass.
contains(DestReg, SrcReg))
931 else if (PPC::VRRCRegClass.
contains(DestReg, SrcReg))
933 else if (PPC::VSRCRegClass.
contains(DestReg, SrcReg))
943 else if (PPC::VSFRCRegClass.
contains(DestReg, SrcReg) ||
944 PPC::VSSRCRegClass.
contains(DestReg, SrcReg))
946 else if (PPC::QFRCRegClass.
contains(DestReg, SrcReg))
948 else if (PPC::QSRCRegClass.
contains(DestReg, SrcReg))
950 else if (PPC::QBRCRegClass.
contains(DestReg, SrcReg))
952 else if (PPC::CRBITRCRegClass.
contains(DestReg, SrcReg))
959 BuildMI(MBB, I, DL, MCID, DestReg)
968 unsigned SrcReg,
bool isKill,
972 bool &NonRI,
bool &SpillsVRS)
const{
977 if (PPC::GPRCRegClass.hasSubClassEq(RC) ||
978 PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) {
983 }
else if (PPC::G8RCRegClass.hasSubClassEq(RC) ||
984 PPC::G8RC_NOX0RegClass.hasSubClassEq(RC)) {
989 }
else if (PPC::F8RCRegClass.hasSubClassEq(RC)) {
994 }
else if (PPC::F4RCRegClass.hasSubClassEq(RC)) {
999 }
else if (PPC::CRRCRegClass.hasSubClassEq(RC)) {
1005 }
else if (PPC::CRBITRCRegClass.hasSubClassEq(RC)) {
1011 }
else if (PPC::VRRCRegClass.hasSubClassEq(RC)) {
1017 }
else if (PPC::VSRCRegClass.hasSubClassEq(RC)) {
1024 }
else if (PPC::VSFRCRegClass.hasSubClassEq(RC)) {
1025 unsigned Opc = Subtarget.
hasP9Vector() ? PPC::DFSTOREf64 : PPC::STXSDX;
1031 }
else if (PPC::VSSRCRegClass.hasSubClassEq(RC)) {
1032 unsigned Opc = Subtarget.
hasP9Vector() ? PPC::DFSTOREf32 : PPC::STXSSPX;
1038 }
else if (PPC::VRSAVERCRegClass.hasSubClassEq(RC)) {
1040 "VRSAVE only needs spill/restore on Darwin");
1046 }
else if (PPC::QFRCRegClass.hasSubClassEq(RC)) {
1052 }
else if (PPC::QSRCRegClass.hasSubClassEq(RC)) {
1058 }
else if (PPC::QBRCRegClass.hasSubClassEq(RC)) {
1074 unsigned SrcReg,
bool isKill,
int FrameIdx,
1092 bool NonRI =
false, SpillsVRS =
false;
1093 if (StoreRegToStackSlot(MF, SrcReg, isKill, FrameIdx, RC, NewMIs,
1103 for (
unsigned i = 0, e = NewMIs.
size(); i != e; ++i)
1104 MBB.
insert(MI, NewMIs[i]);
1111 NewMIs.
back()->addMemOperand(MF, MMO);
1115 unsigned DestReg,
int FrameIdx,
1118 bool &NonRI,
bool &SpillsVRS)
const {
1122 if (PPC::GPRCRegClass.hasSubClassEq(RC) ||
1123 PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) {
1125 DestReg), FrameIdx));
1126 }
else if (PPC::G8RCRegClass.hasSubClassEq(RC) ||
1127 PPC::G8RC_NOX0RegClass.hasSubClassEq(RC)) {
1130 }
else if (PPC::F8RCRegClass.hasSubClassEq(RC)) {
1133 }
else if (PPC::F4RCRegClass.hasSubClassEq(RC)) {
1136 }
else if (PPC::CRRCRegClass.hasSubClassEq(RC)) {
1138 get(PPC::RESTORE_CR), DestReg),
1141 }
else if (PPC::CRBITRCRegClass.hasSubClassEq(RC)) {
1143 get(PPC::RESTORE_CRBIT), DestReg),
1146 }
else if (PPC::VRRCRegClass.hasSubClassEq(RC)) {
1150 }
else if (PPC::VSRCRegClass.hasSubClassEq(RC)) {
1155 }
else if (PPC::VSFRCRegClass.hasSubClassEq(RC)) {
1156 unsigned Opc = Subtarget.
hasP9Vector() ? PPC::DFLOADf64 : PPC::LXSDX;
1158 DestReg), FrameIdx));
1160 }
else if (PPC::VSSRCRegClass.hasSubClassEq(RC)) {
1161 unsigned Opc = Subtarget.
hasP9Vector() ? PPC::DFLOADf32 : PPC::LXSSPX;
1163 DestReg), FrameIdx));
1165 }
else if (PPC::VRSAVERCRegClass.hasSubClassEq(RC)) {
1167 "VRSAVE only needs spill/restore on Darwin");
1169 get(PPC::RESTORE_VRSAVE),
1173 }
else if (PPC::QFRCRegClass.hasSubClassEq(RC)) {
1177 }
else if (PPC::QSRCRegClass.hasSubClassEq(RC)) {
1181 }
else if (PPC::QBRCRegClass.hasSubClassEq(RC)) {
1195 unsigned DestReg,
int FrameIdx,
1201 if (MI != MBB.
end()) DL = MI->getDebugLoc();
1213 if (Subtarget.
hasVSX() && RC == &PPC::VRRCRegClass)
1214 RC = &PPC::VSRCRegClass;
1216 bool NonRI =
false, SpillsVRS =
false;
1217 if (LoadRegFromStackSlot(MF, DL, DestReg, FrameIdx, RC, NewMIs,
1227 for (
unsigned i = 0, e = NewMIs.
size(); i != e; ++i)
1228 MBB.
insert(MI, NewMIs[i]);
1235 NewMIs.
back()->addMemOperand(MF, MMO);
1240 assert(Cond.
size() == 2 &&
"Invalid PPC branch opcode!");
1241 if (Cond[1].
getReg() == PPC::CTR8 || Cond[1].getReg() == PPC::CTR)
1242 Cond[0].setImm(Cond[0].getImm() == 0 ? 1 : 0);
1254 if (DefOpc != PPC::LI && DefOpc != PPC::LI8)
1284 if (UseInfo->isLookupPtrRegClass()) {
1285 if (UseInfo->RegClass != 1)
1288 if (UseInfo->RegClass != PPC::GPRC_NOR0RegClassID &&
1289 UseInfo->RegClass != PPC::G8RC_NOX0RegClassID)
1296 if (UseInfo->Constraints != 0)
1300 if (UseInfo->isLookupPtrRegClass()) {
1301 bool isPPC64 = Subtarget.
isPPC64();
1302 ZeroReg = isPPC64 ? PPC::ZERO8 : PPC::ZERO;
1304 ZeroReg = UseInfo->RegClass == PPC::G8RC_NOX0RegClassID ?
1305 PPC::ZERO8 : PPC::ZERO;
1320 if (
I->definesRegister(PPC::CTR) ||
I->definesRegister(PPC::CTR8))
1332 unsigned NumT,
unsigned ExtraT,
1334 unsigned NumF,
unsigned ExtraF,
1365 if (OpC == PPC::BLR || OpC == PPC::BLR8) {
1366 if (Pred[1].
getReg() == PPC::CTR8 || Pred[1].
getReg() == PPC::CTR) {
1367 bool isPPC64 = Subtarget.
isPPC64();
1368 MI.
setDesc(
get(Pred[0].getImm() ? (isPPC64 ? PPC::BDNZLR8 : PPC::BDNZLR)
1369 : (isPPC64 ? PPC::BDZLR8 : PPC::BDZLR)));
1373 .addReg(Pred[1].
getReg());
1377 .addReg(Pred[1].
getReg());
1381 .addImm(Pred[0].getImm())
1382 .addReg(Pred[1].
getReg());
1386 }
else if (OpC ==
PPC::B) {
1387 if (Pred[1].
getReg() == PPC::CTR8 || Pred[1].getReg() == PPC::CTR) {
1388 bool isPPC64 = Subtarget.
isPPC64();
1390 : (isPPC64 ? PPC::BDZ8 :
PPC::BDZ)));
1397 .addReg(Pred[1].
getReg())
1405 .addReg(Pred[1].
getReg())
1413 .addImm(Pred[0].getImm())
1414 .addReg(Pred[1].
getReg())
1419 }
else if (OpC == PPC::BCTR || OpC == PPC::BCTR8 ||
1421 if (Pred[1].
getReg() == PPC::CTR8 || Pred[1].
getReg() == PPC::CTR)
1424 bool setLR = OpC ==
PPC::BCTRL || OpC == PPC::BCTRL8;
1425 bool isPPC64 = Subtarget.
isPPC64();
1428 MI.
setDesc(
get(isPPC64 ? (setLR ? PPC::BCCTRL8 : PPC::BCCTR8)
1429 : (setLR ? PPC::BCCTRL : PPC::BCCTR)));
1431 .addReg(Pred[1].
getReg());
1434 MI.
setDesc(
get(isPPC64 ? (setLR ? PPC::BCCTRL8n : PPC::BCCTR8n)
1435 : (setLR ? PPC::BCCTRLn : PPC::BCCTRn)));
1437 .addReg(Pred[1].
getReg());
1441 MI.
setDesc(
get(isPPC64 ? (setLR ? PPC::BCCCTRL8 : PPC::BCCCTR8)
1442 : (setLR ? PPC::BCCCTRL : PPC::BCCCTR)));
1444 .addImm(Pred[0].getImm())
1445 .addReg(Pred[1].
getReg());
1454 assert(Pred1.
size() == 2 &&
"Invalid PPC first predicate");
1455 assert(Pred2.
size() == 2 &&
"Invalid PPC second predicate");
1457 if (Pred1[1].
getReg() == PPC::CTR8 || Pred1[1].getReg() == PPC::CTR)
1459 if (Pred2[1].
getReg() == PPC::CTR8 || Pred2[1].getReg() == PPC::CTR)
1463 if (Pred1[1].
getReg() != Pred2[1].getReg())
1484 std::vector<MachineOperand> &Pred)
const {
1492 { &PPC::CRRCRegClass, &PPC::CRBITRCRegClass,
1493 &PPC::CTRRCRegClass, &PPC::CTRRC8RegClass };
1536 unsigned &SrcReg2,
int &
Mask,
1541 default:
return false;
1576 if (OpC == PPC::FCMPUS || OpC == PPC::FCMPUD)
1587 bool isPPC64 = Subtarget.
isPPC64();
1588 bool is32BitSignedCompare = OpC == PPC::CMPWI || OpC == PPC::CMPW;
1589 bool is32BitUnsignedCompare = OpC == PPC::CMPLWI || OpC == PPC::CMPLW;
1590 bool is64BitUnsignedCompare = OpC == PPC::CMPLDI || OpC == PPC::CMPLD;
1594 if (!MI)
return false;
1597 bool equalityOnly =
false;
1600 if (is32BitSignedCompare) {
1602 if (MIOpC == PPC::SRAW || MIOpC == PPC::SRAWo ||
1603 MIOpC == PPC::SRAWI || MIOpC == PPC::SRAWIo ||
1604 MIOpC == PPC::EXTSB || MIOpC == PPC::EXTSBo ||
1605 MIOpC == PPC::EXTSH || MIOpC == PPC::EXTSHo ||
1606 MIOpC == PPC::EXTSW || MIOpC == PPC::EXTSWo) {
1610 }
else if (is32BitUnsignedCompare) {
1612 bool isZeroExtendingRotate =
1613 (MIOpC == PPC::RLWINM || MIOpC == PPC::RLWINMo ||
1614 MIOpC == PPC::RLWNM || MIOpC == PPC::RLWNMo)
1621 if (MIOpC == PPC::CNTLZW || MIOpC == PPC::CNTLZWo ||
1622 MIOpC == PPC::SLW || MIOpC == PPC::SLWo ||
1623 MIOpC == PPC::SRW || MIOpC == PPC::SRWo ||
1624 MIOpC == PPC::ANDIo ||
1625 isZeroExtendingRotate) {
1627 equalityOnly =
true;
1631 equalityOnly = is64BitUnsignedCompare;
1633 equalityOnly = is32BitUnsignedCompare;
1646 }
else if (UseMI->
getOpcode() == PPC::ISEL ||
1649 if (SubIdx != PPC::sub_eq)
1661 bool FoundUse =
false;
1690 else if (Value != 0) {
1694 if (!equalityOnly && MRI->
hasOneUse(CRReg)) {
1698 int16_t Immed = (int16_t)Value;
1728 for (; I != E && !noSub; --
I) {
1742 if ((OpC == PPC::CMPW || OpC == PPC::CMPLW ||
1743 OpC == PPC::CMPD || OpC == PPC::CMPLD) &&
1744 (IOpC == PPC::SUBF || IOpC == PPC::SUBF8) &&
1767 if (MIOpC == PPC::ANDIo || MIOpC == PPC::ANDIo8)
1770 NewOpC = PPC::getRecordFormOpcode(MIOpC);
1790 bool ShouldSwap =
false;
1791 if (Sub && Value == 0) {
1797 ShouldSwap = !ShouldSwap;
1809 "Invalid predicate for equality-only optimization");
1812 }
else if (UseMI->
getOpcode() == PPC::ISEL ||
1815 assert((!equalityOnly || NewSubReg == PPC::sub_eq) &&
1816 "Invalid CR bit for equality-only optimization");
1818 if (NewSubReg == PPC::sub_lt)
1819 NewSubReg = PPC::sub_gt;
1820 else if (NewSubReg == PPC::sub_gt)
1821 NewSubReg = PPC::sub_lt;
1828 assert(!(Value != 0 && ShouldSwap) &&
1829 "Non-zero immediate support and ShouldSwap"
1830 "may conflict in updating predicate");
1839 get(TargetOpcode::COPY), CRReg)
1846 if (MIOpC != NewOpC) {
1859 *ImpDefs; ++ImpDefs)
1865 *ImpUses; ++ImpUses)
1871 "Record-form instruction does not define cr0?");
1876 for (
unsigned i = 0, e = PredsToUpdate.
size(); i < e; i++)
1877 PredsToUpdate[i].
first->setImm(PredsToUpdate[i].second);
1879 for (
unsigned i = 0, e = SubRegsToUpdate.
size(); i < e; i++)
1880 SubRegsToUpdate[i].
first->setSubReg(SubRegsToUpdate[i].second);
1895 }
else if (Opcode == TargetOpcode::STACKMAP) {
1898 }
else if (Opcode == TargetOpcode::PATCHPOINT) {
1902 return get(Opcode).getSize();
1906 std::pair<unsigned, unsigned>
1909 return std::make_pair(TF & Mask, TF & ~Mask);
1914 using namespace PPCII;
1915 static const std::pair<unsigned, const char *>
TargetFlags[] = {
1929 using namespace PPCII;
1930 static const std::pair<unsigned, const char *>
TargetFlags[] = {
1942 case TargetOpcode::LOAD_STACK_GUARD: {
1944 "Only Linux target is expected to contain LOAD_STACK_GUARD");
1945 const int64_t
Offset = Subtarget.
isPPC64() ? -0x7010 : -0x7008;
1953 case PPC::DFLOADf32:
1954 case PPC::DFLOADf64:
1955 case PPC::DFSTOREf32:
1956 case PPC::DFSTOREf64: {
1958 "Invalid D-Form Pseudo-ops on non-P9 target.");
1960 "D-form op must have register and immediate operands");
1961 unsigned UpperOpcode, LowerOpcode;
1963 case PPC::DFLOADf32:
1964 UpperOpcode = PPC::LXSSP;
1965 LowerOpcode = PPC::LFS;
1967 case PPC::DFLOADf64:
1968 UpperOpcode = PPC::LXSD;
1969 LowerOpcode = PPC::LFD;
1971 case PPC::DFSTOREf32:
1972 UpperOpcode = PPC::STXSSP;
1973 LowerOpcode = PPC::STFS;
1975 case PPC::DFSTOREf64:
1976 UpperOpcode = PPC::STXSD;
1977 LowerOpcode = PPC::STFD;
1982 if ((TargetReg >= PPC::F0 && TargetReg <= PPC::F31) ||
1983 (TargetReg >= PPC::VSL0 && TargetReg <= PPC::VSL31))
1984 Opcode = LowerOpcode;
1986 Opcode = UpperOpcode;
1990 case PPC::CFENCE8: {
1993 BuildMI(MBB, MI, DL,
get(PPC::CTRL_DEP))
2007 if (Subtarget.
hasVSX() && RC == &PPC::VRRCRegClass)
2008 return &PPC::VSRCRegClass;
2013 return PPC::getRecordFormOpcode(Opcode);
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg, unsigned &DstReg, unsigned &SubIdx) const override
uint32_t getNumPatchBytes() const
Return the number of patchable bytes the given patchpoint should emit.
int getNonRecordFormOpcode(uint16_t)
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
virtual bool getMachineCombinerPatterns(MachineInstr &Root, SmallVectorImpl< MachineCombinerPattern > &Patterns) const
Return true when there is potentially a faster code sequence for an instruction chain ending in Root...
MachineBasicBlock * getMBB() const
const PPCTargetMachine & getTargetMachine() const
Describe properties that are true of each instruction in the target description file.
static int getRecordFormOpcode(unsigned Opcode)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const MachineInstrBuilder & add(const MachineOperand &MO) const
static cl::opt< bool > DisableCmpOpt("disable-ppc-cmp-opt", cl::desc("Disable compare instruction optimization"), cl::Hidden)
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
unsigned isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
bool isDarwin() const
isDarwin - True if this is any darwin platform.
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
const char * getSymbolName() const
CHAIN,FLAG = BCTRL(CHAIN, INFLAG) - Directly corresponds to a BCTRL instruction.
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
return AArch64::GPR64RegClass contains(Reg)
ScheduleHazardRecognizer * CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI, const ScheduleDAG *DAG) const override
CreateTargetHazardRecognizer - Return the hazard recognizer to use for this target when scheduling th...
MachineFunction & MF
Machine function.
bool isAssociativeAndCommutative(const MachineInstr &Inst) const override
int getOperandCycle(unsigned ItinClassIndx, unsigned OperandIdx) const
Return the cycle for the given class and operand.
PPCDispatchGroupSBHazardRecognizer - This class implements a scoreboard-based hazard recognizer for P...
A description of a memory reference used in the backend.
bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg, unsigned &SrcReg2, int &Mask, int &Value) const override
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false)
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
use_instr_iterator use_instr_begin(unsigned RegNo) const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
iterator begin() const
begin/end - Return all of the registers in this class.
Reg
All possible values of the reg field in the ModR/M byte.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool isReallyTriviallyReMaterializable(const MachineInstr &MI, AliasAnalysis *AA) const override
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
INLINEASM - Represents an inline asm block.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
defusechain_iterator - This class provides iterator support for machine operands in the function that...
void RemoveOperand(unsigned i)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
PPCInstrInfo(PPCSubtarget &STI)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based loops.
R32 = MFOCRF(CRREG, INFLAG) - Represents the MFOCRF instruction.
unsigned getMatchingSuperReg(unsigned Reg, unsigned SubIdx, const TargetRegisterClass *RC) const
Return a super-register of the specified register Reg so its sub-register of index SubIdx is Reg...
bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg, unsigned SrcReg2, int Mask, int Value, const MachineRegisterInfo *MRI) const override
MO_NLP_HIDDEN_FLAG - If this bit is set, the symbol reference is to a symbol with hidden visibility...
const MCPhysReg * getImplicitDefs() const
Return a list of registers that are potentially written by any instance of this machine instruction...
CHAIN = STXVD2X CHAIN, VSRC, Ptr - Occurs only for little endian.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Itinerary data supplied by a subtarget to be used by a target.
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
ArrayRef< std::pair< unsigned, const char * > > getSerializableBitmaskMachineOperandTargetFlags() const override
size_t size() const
size - Get the array size.
Instances of this class represent a single low-level machine instruction.
unsigned getKillRegState(bool B)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
const MachineBasicBlock * getParent() const
void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, unsigned DstReg, ArrayRef< MachineOperand > Cond, unsigned TrueReg, unsigned FalseReg) const override
unsigned getDeadRegState(bool B)
VSRC, CHAIN = LXVD2X_LE CHAIN, Ptr - Occurs only for little endian.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned UnsafeFPMath
UnsafeFPMath - This flag is enabled when the -enable-unsafe-fp-math flag is specified on the command ...
unsigned const MachineRegisterInfo * MRI
HazardRecognizer - This determines whether or not an instruction can be issued this cycle...
int getAltVSXFMAOpcode(uint16_t Opcode)
Simple binary floating point operators.
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, bool KillSrc) const override
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void clearRegisterDeads(unsigned Reg)
Clear all dead flags on operands defining register Reg.
MachineInstrBuilder & UseMI
MO_NLP_FLAG - If this bit is set, the symbol reference is actually to the non_lazy_ptr for the global...
const TargetRegisterClass * updatedRC(const TargetRegisterClass *RC) const
const MachineOperand & getOperand(unsigned i) const
static ManagedStatic< OptionRegistry > OR
const MCPhysReg * ImplicitDefs
virtual bool findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const
Returns true iff the routine could find two commutable operands in the given machine instruction...
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
void setImm(int64_t immVal)
MI-level patchpoint operands.
PPCHazardRecognizer970 - This class defines a finite state automata that models the dispatch logic on...
MachineInstr * commuteInstructionImpl(MachineInstr &MI, bool NewMI, unsigned OpIdx1, unsigned OpIdx2) const override
Commutes the operands in the given instruction.
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
bool empty() const
empty - Check if the array is empty.
unsigned getSubReg() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isPseudo() const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction...
static unsigned getCRFromCRBit(unsigned SrcReg)
MO_TLS - Indicates that the operand being accessed is some kind of thread-local symbol.
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specific constraint if it is set.
unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const override
bool definesRegister(unsigned Reg, const TargetRegisterInfo *TRI=nullptr) const
Return true if the MachineInstr fully defines the specified register.
bool isTargetLinux() const
void setIsKill(bool Val=true)
static const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0, bool mem=true)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
The next are not flags but distinct values.
The memory access writes data.
static bool MBBDefinesCTR(MachineBasicBlock &MBB)
bool readsRegister(unsigned Reg, const TargetRegisterInfo *TRI=nullptr) const
Return true if the MachineInstr reads the specified register.
void setOpcode(unsigned Op)
bool isUnpredicatedTerminator(const MachineInstr &MI) const override
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
void getNoop(MCInst &NopInst) const override
Return the noop instruction to use for a noop.
static unsigned getCRBitValue(unsigned CRBit)
MachineOperand class - Representation of each machine instruction operand.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
Predicate getSwappedPredicate(Predicate Opcode)
Assume the condition register is set by MI(a,b), return the predicate if we modify the instructions s...
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
static cl::opt< bool > VSXSelfCopyCrash("crash-on-ppc-vsx-self-copy", cl::desc("Causes the backend to crash instead of generating a nop VSX copy"), cl::Hidden)
static cl::opt< bool > UseOldLatencyCalc("ppc-old-latency-calc", cl::Hidden, cl::desc("Use the old (incorrect) instruction latency calculation"))
bool canInsertSelect(const MachineBasicBlock &, ArrayRef< MachineOperand > Cond, unsigned, unsigned, int &, int &, int &) const override
bool hasOneUse(unsigned RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
bool PredicateInstruction(MachineInstr &MI, ArrayRef< MachineOperand > Pred) const override
bool SubsumesPredicate(ArrayRef< MachineOperand > Pred1, ArrayRef< MachineOperand > Pred2) const override
bool DefinesPredicate(MachineInstr &MI, std::vector< MachineOperand > &Pred) const override
static bool clobbersPhysReg(const uint32_t *RegMask, unsigned PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
QVGPCI = This corresponds to the QPX qvgpci instruction.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
Predicate InvertPredicate(Predicate Opcode)
Invert the specified predicate. != -> ==, < -> >=.
MachineInstr * getUniqueVRegDef(unsigned Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
On a symbol operand, this represents the lo part.
uint32_t getNumPatchBytes() const
Return the number of patchable bytes the given stackmap should emit.
const MCPhysReg * iterator
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
The memory access reads data.
TargetSubtargetInfo - Generic base class for all target subtargets.
const PPCRegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
bool getMachineCombinerPatterns(MachineInstr &Root, SmallVectorImpl< MachineCombinerPattern > &P) const override
Return true when there is potentially a faster code sequence for an instruction chain ending in <Root...
bool isPredicated(const MachineInstr &MI) const override
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Representation of each machine instruction.
unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
unsigned getSchedClass() const
Return the scheduling class for this instruction.
bool FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, unsigned Reg, MachineRegisterInfo *MRI) const override
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MI-level stackmap operands.
virtual MachineInstr * commuteInstructionImpl(MachineInstr &MI, bool NewMI, unsigned OpIdx1, unsigned OpIdx2) const
This method commutes the operands of the given machine instruction MI.
bool hasOneNonDBGUse(unsigned RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug instruction using the specified regis...
void setReg(unsigned Reg)
Change the register this operand corresponds to.
static MachineOperand CreateImm(int64_t Val)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void setSubReg(unsigned subReg)
bool findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const override
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
GetInstSize - Return the number of bytes of code the specified instruction may be.
const MCPhysReg * getImplicitUses() const
Return a list of registers that are potentially read by any instance of this machine instruction...
const TargetInstrInfo * TII
Target instruction information.
virtual ScheduleHazardRecognizer * CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI, const ScheduleDAG *DAG) const
Allocate and return a hazard recognizer to use for this target when scheduling the machine instructio...
bool isPPC64() const
isPPC64 - Return true if we are generating code for 64-bit pointer mode.
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
int getOperandLatency(const InstrItineraryData *ItinData, const MachineInstr &DefMI, unsigned DefIdx, const MachineInstr &UseMI, unsigned UseIdx) const override
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
LLVM Value Representation.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
static use_instr_iterator use_instr_end()
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const MCOperandInfo * OpInfo
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned getDarwinDirective() const
getDarwinDirective - Returns the -m directive specified for the cpu.
ScheduleHazardRecognizer * CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, const ScheduleDAG *DAG) const override
CreateTargetPostRAHazardRecognizer - Return the postRA hazard recognizer to use for this target when ...
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
bool isPredicable(const MachineInstr &MI) const override
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
This holds information about one operand of a machine instruction, indicating the register class for ...
On a symbol operand "FOO", this indicates that the reference is actually to "FOO@plt".
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, unsigned ExtraPredCycles, BranchProbability Probability) const override
static cl::opt< bool > DisableCTRLoopAnal("disable-ppc-ctrloop-analysis", cl::Hidden, cl::desc("Disable analysis for CTR loops"))
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool modifiesRegister(unsigned Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr modifies (fully define or partially define) the specified register...
bool isBarrier(QueryType Type=AnyInBundle) const
Returns true if the specified instruction stops control flow from executing the instruction immediate...
MO_PIC_FLAG - If this bit is set, the symbol reference is relative to the function's picbase...
bool expandPostRAPseudo(MachineInstr &MI) const override
const MCPhysReg * ImplicitUses
bool contains(unsigned Reg) const
Return true if the specified register is included in this register class.