46#define DEBUG_TYPE "ppc-instr-info"
48#define GET_INSTRMAP_INFO
49#define GET_INSTRINFO_CTOR_DTOR
50#include "PPCGenInstrInfo.inc"
53 "Number of spillvsrrc spilled to stack as vec");
55 "Number of spillvsrrc spilled to stack as gpr");
56STATISTIC(NumGPRtoVSRSpill,
"Number of gpr spills to spillvsrrc");
58 "Number of ISELs that depend on comparison of constants converted");
60 "Number of compare-immediate instructions fed by constants");
62 "Number of record-form rotates converted to record-form andi");
65void PPCInstrInfo::anchor() {}
70 STI.isPPC64() ?
PPC::BLR8 :
PPC::BLR),
71 Subtarget(STI), RI(STI.getTargetMachine()) {}
75 return Subtarget.isPPC64() ? &PPC::G8RC_NOX0RegClass
76 : &PPC::GPRC_NOR0RegClass;
85 static_cast<const PPCSubtarget *
>(STI)->getCPUDirective();
89 static_cast<const PPCSubtarget *
>(STI)->getInstrItineraryData();
121 unsigned *PredCost)
const {
122 if (!ItinData || Subtarget.getCLOpts().old_latency_calc)
123 return PPCGenInstrInfo::getInstrLatency(ItinData,
MI, PredCost);
133 unsigned DefClass =
MI.getDesc().getSchedClass();
134 for (
unsigned i = 0, e =
MI.getNumOperands(); i != e; ++i) {
139 std::optional<unsigned> Cycle = ItinData->
getOperandCycle(DefClass, i);
152 std::optional<unsigned>
Latency = PPCGenInstrInfo::getOperandLatency(
155 if (!
DefMI.getParent())
162 if (Reg.isVirtual()) {
164 &
DefMI.getParent()->getParent()->getRegInfo();
165 IsRegCR =
MRI->getRegClass(Reg)->hasSuperClassEq(&PPC::CRRCRegClass) ||
166 MRI->getRegClass(Reg)->hasSuperClassEq(&PPC::CRBITRCRegClass);
168 IsRegCR = PPC::CRRCRegClass.contains(Reg) ||
169 PPC::CRBITRCRegClass.contains(Reg);
172 if (
UseMI.isBranch() && IsRegCR) {
178 unsigned Directive = Subtarget.getCPUDirective();
252#define InfoArrayIdxFMAInst 0
253#define InfoArrayIdxFAddInst 1
254#define InfoArrayIdxFMULInst 2
255#define InfoArrayIdxAddOpIdx 3
256#define InfoArrayIdxMULOpIdx 4
257#define InfoArrayIdxFSubInst 5
268 {PPC::XSMADDADP, PPC::XSADDDP, PPC::XSMULDP, 1, 2, PPC::XSSUBDP},
269 {PPC::XSMADDASP, PPC::XSADDSP, PPC::XSMULSP, 1, 2, PPC::XSSUBSP},
270 {PPC::XVMADDADP, PPC::XVADDDP, PPC::XVMULDP, 1, 2, PPC::XVSUBDP},
271 {PPC::XVMADDASP, PPC::XVADDSP, PPC::XVMULSP, 1, 2, PPC::XVSUBSP},
272 {PPC::FMADD, PPC::FADD, PPC::FMUL, 3, 1, PPC::FSUB},
273 {PPC::FMADDS, PPC::FADDS, PPC::FMULS, 3, 1, PPC::FSUBS}};
277int16_t PPCInstrInfo::getFMAOpIdxInfo(
unsigned Opcode)
const {
334 bool DoRegPressureReduce)
const {
338 auto IsAllOpsVirtualReg = [](
const MachineInstr &Instr) {
339 for (
const auto &MO : Instr.explicit_operands())
340 if (!(MO.isReg() && MO.getReg().isVirtual()))
345 auto IsReassociableAddOrSub = [&](
const MachineInstr &Instr,
347 if (Instr.getOpcode() !=
358 if (!IsAllOpsVirtualReg(Instr))
364 !
MRI->hasOneNonDBGUse(Instr.getOperand(0).getReg()))
370 auto IsReassociableFMA = [&](
const MachineInstr &Instr, int16_t &AddOpIdx,
371 int16_t &MulOpIdx,
bool IsLeaf) {
372 int16_t Idx = getFMAOpIdxInfo(Instr.getOpcode());
383 if (!IsAllOpsVirtualReg(Instr))
400 return MRI->hasOneNonDBGUse(OpAdd.
getReg());
403 int16_t AddOpIdx = -1;
404 int16_t MulOpIdx = -1;
406 bool IsUsedOnceL =
false;
407 bool IsUsedOnceR =
false;
411 auto IsRPReductionCandidate = [&]() {
415 if (Opcode != PPC::XSMADDASP && Opcode != PPC::XSMADDADP)
420 if (IsReassociableFMA(Root, AddOpIdx, MulOpIdx,
true)) {
421 assert((MulOpIdx >= 0) &&
"mul operand index not right!");
422 Register MULRegL = RI.lookThruSingleUseCopyChain(
424 Register MULRegR = RI.lookThruSingleUseCopyChain(
426 if (!MULRegL && !MULRegR)
429 if (MULRegL && !MULRegR) {
433 }
else if (!MULRegL && MULRegR) {
444 MULInstrL =
MRI->getVRegDef(MULRegL);
445 MULInstrR =
MRI->getVRegDef(MULRegR);
446 return MULInstrL && MULInstrR;
452 if (DoRegPressureReduce && IsRPReductionCandidate()) {
453 assert((MULInstrL && MULInstrR) &&
"wrong register preduction candidate!");
474 if (!IsReassociableFMA(Root, AddOpIdx, MulOpIdx,
false))
477 assert((AddOpIdx >= 0) &&
"add operand index not right!");
484 if (!IsReassociableFMA(*Prev, AddOpIdx, MulOpIdx,
false))
487 assert((AddOpIdx >= 0) &&
"add operand index not right!");
492 if (IsReassociableFMA(*Leaf, AddOpIdx, MulOpIdx,
true)) {
508 assert(!InsInstrs.
empty() &&
"Instructions set to be inserted is empty!");
514 int16_t Idx = getFMAOpIdxInfo(Root.
getOpcode());
553 for (
auto *Inst : InsInstrs) {
555 assert(Operand.isReg() &&
"Invalid instruction in InsInstrs!");
556 if (Operand.getReg() == PPC::ZERO8) {
557 Placeholder = &Operand;
563 assert(Placeholder &&
"Placeholder does not exist!");
568 generateLoadForNewConst(ConstPoolIdx, &Root,
C->getType(), InsInstrs);
571 Placeholder->setReg(LoadNewConst);
577 if (!Subtarget.getCLOpts().fma_rp_reduction)
592 if (!(Subtarget.isPPC64() && Subtarget.hasP9Vector() &&
599 auto GetMBBPressure =
605 RPTracker.
init(
MBB->getParent(), RegClassInfo,
nullptr,
MBB,
MBB->end(),
609 if (
MI.isDebugValue() ||
MI.isDebugLabel())
615 RPTracker.
recede(RegOpers);
625 unsigned VSSRCLimit =
629 return GetMBBPressure(
MBB)[PPC::RegisterPressureSets::VSSRC] >
630 (float)VSSRCLimit * Subtarget.getCLOpts().fma_rp_factor;
635 if (!
I->hasOneMemOperand())
639 return Op->isLoad() &&
Op->getPseudoValue() &&
643Register PPCInstrInfo::generateLoadForNewConst(
651 "Target not supported!\n");
657 Register VReg1 =
MRI->createVirtualRegister(&PPC::G8RC_and_G8RC_NOX0RegClass);
659 BuildMI(*MF,
MI->getDebugLoc(),
get(PPC::ADDIStocHA8), VReg1)
663 assert((Ty->isFloatTy() || Ty->isDoubleTy()) &&
664 "Only float and double are supported!");
669 LoadOpcode = PPC::DFLOADf32;
671 LoadOpcode = PPC::DFLOADf64;
701 assert(
I->mayLoad() &&
"Should be a load instruction.\n");
702 for (
auto MO :
I->uses()) {
706 if (Reg == 0 || !Reg.isVirtual())
710 for (
auto MO2 :
DefMI->uses())
712 return (MCP->
getConstants())[MO2.getIndex()].Val.ConstVal;
732 bool DoRegPressureReduce)
const {
742 DoRegPressureReduce);
755 reassociateFMA(Root,
Pattern, InsInstrs, DelInstrs, InstrIdxForVirtReg);
760 DelInstrs, InstrIdxForVirtReg);
765void PPCInstrInfo::reassociateFMA(
775 MRI.constrainRegClass(RegC, RC);
778 int16_t Idx = getFMAOpIdxInfo(FmaOp);
779 assert(Idx >= 0 &&
"Root must be a FMA instruction");
781 bool IsILPReassociate =
801 Leaf =
MRI.getVRegDef(MULReg);
807 Leaf =
MRI.getVRegDef(MULReg);
812 uint32_t IntersectedFlags = 0;
813 if (IsILPReassociate)
818 auto GetOperandInfo = [&](
const MachineOperand &Operand,
Register &
Reg) {
823 auto GetFMAInstrInfo = [&](
const MachineInstr &
Instr,
Register &MulOp1,
825 GetOperandInfo(
Instr.getOperand(FirstMulOpIdx), MulOp1);
826 GetOperandInfo(
Instr.getOperand(FirstMulOpIdx + 1), MulOp2);
827 GetOperandInfo(
Instr.getOperand(AddOpIdx), AddOp);
830 Register RegM11, RegM12, RegX, RegY, RegM21, RegM22, RegM31, RegM32, RegA11,
833 GetFMAInstrInfo(Root, RegM31, RegM32, RegB);
835 if (IsILPReassociate)
836 GetFMAInstrInfo(*Prev, RegM21, RegM22, RegA21);
839 GetFMAInstrInfo(*Leaf, RegM11, RegM12, RegA11);
840 GetOperandInfo(Leaf->
getOperand(AddOpIdx), RegX);
857 InstrIdxForVirtReg.
insert(std::make_pair(NewVRA, 0));
860 if (IsILPReassociate) {
862 InstrIdxForVirtReg.
insert(std::make_pair(NewVRB, 1));
868 InstrIdxForVirtReg.
insert(std::make_pair(NewVRD, 2));
871 auto AdjustOperandOrder = [&](MachineInstr *
MI,
Register RegAdd,
873 MI->getOperand(AddOpIdx).setReg(RegAdd);
874 MI->getOperand(FirstMulOpIdx).setReg(RegMul1);
875 MI->getOperand(FirstMulOpIdx + 1).setReg(RegMul2);
878 MachineInstrBuilder NewARegPressure, NewCRegPressure;
884 MachineInstrBuilder MINewB =
889 MachineInstrBuilder MINewA =
896 AdjustOperandOrder(MINewB, RegX, RegM21, RegM22);
897 AdjustOperandOrder(MINewA, RegY, RegM31, RegM32);
900 MachineInstrBuilder MINewC =
918 assert(NewVRD &&
"new FMA register not created!");
920 MachineInstrBuilder MINewA =
925 MachineInstrBuilder MINewB =
930 MachineInstrBuilder MINewD =
937 AdjustOperandOrder(MINewB, RegX, RegM21, RegM22);
938 AdjustOperandOrder(MINewD, NewVRA, RegM31, RegM32);
941 MachineInstrBuilder MINewC =
986 if (!IsILPReassociate) {
995 "Insertion instructions set should not be empty!");
999 if (IsILPReassociate)
1007 unsigned &SubIdx)
const {
1008 switch (
MI.getOpcode()) {
1009 default:
return false;
1012 case PPC::EXTSW_32_64:
1013 SrcReg =
MI.getOperand(1).getReg();
1014 DstReg =
MI.getOperand(0).getReg();
1015 SubIdx = PPC::sub_32;
1021 int &FrameIndex)
const {
1025 if (
MI.getOperand(1).isImm() && !
MI.getOperand(1).getImm() &&
1026 MI.getOperand(2).isFI()) {
1027 FrameIndex =
MI.getOperand(2).getIndex();
1028 return MI.getOperand(0).getReg();
1038 switch (
MI.getOpcode()) {
1048 case PPC::ADDIStocHA:
1049 case PPC::ADDIStocHA8:
1051 case PPC::ADDItocL8:
1052 case PPC::LOAD_STACK_GUARD:
1053 case PPC::PPCLdFixedAddr:
1055 case PPC::XXLXORspz:
1056 case PPC::XXLXORdpz:
1057 case PPC::XXLEQVOnes:
1058 case PPC::XXSPLTI32DX:
1060 case PPC::XXSPLTIDP:
1064 case PPC::V_SETALLONESB:
1065 case PPC::V_SETALLONESH:
1066 case PPC::V_SETALLONES:
1069 case PPC::XXSETACCZ:
1070 case PPC::DMXXSETACCZ:
1077 int &FrameIndex)
const {
1079 if (
MI.getOperand(1).isImm() && !
MI.getOperand(1).getImm() &&
1080 MI.getOperand(2).isFI()) {
1081 FrameIndex =
MI.getOperand(2).getIndex();
1082 return MI.getOperand(0).getReg();
1090 unsigned OpIdx2)
const {
1094 if (
MI.getOpcode() != PPC::RLWIMI &&
MI.getOpcode() != PPC::RLWIMI_rec)
1102 if (
MI.getOperand(3).getImm() != 0)
1113 assert(((OpIdx1 == 1 && OpIdx2 == 2) || (OpIdx1 == 2 && OpIdx2 == 1)) &&
1114 "Only the operands 1 and 2 can be swapped in RLSIMI/RLWIMI_rec.");
1118 unsigned SubReg1 =
MI.getOperand(1).getSubReg();
1119 unsigned SubReg2 =
MI.getOperand(2).getSubReg();
1120 bool Reg1IsKill =
MI.getOperand(1).isKill();
1121 bool Reg2IsKill =
MI.getOperand(2).isKill();
1122 bool ChangeReg0 =
false;
1128 "Expecting a two-address instruction!");
1129 assert(
MI.getOperand(0).getSubReg() == SubReg1 &&
"Tied subreg mismatch");
1135 unsigned MB =
MI.getOperand(4).getImm();
1136 unsigned ME =
MI.getOperand(5).getImm();
1140 if (MB == 0 && ME == 31)
1145 Register Reg0 = ChangeReg0 ? Reg2 :
MI.getOperand(0).getReg();
1146 bool Reg0IsDead =
MI.getOperand(0).isDead();
1147 return BuildMI(MF,
MI.getDebugLoc(),
MI.getDesc())
1156 MI.getOperand(0).setReg(Reg2);
1157 MI.getOperand(0).setSubReg(SubReg2);
1159 MI.getOperand(2).setReg(Reg1);
1160 MI.getOperand(1).setReg(Reg2);
1161 MI.getOperand(2).setSubReg(SubReg1);
1162 MI.getOperand(1).setSubReg(SubReg2);
1163 MI.getOperand(2).setIsKill(Reg1IsKill);
1164 MI.getOperand(1).setIsKill(Reg2IsKill);
1167 MI.getOperand(4).setImm((ME + 1) & 31);
1168 MI.getOperand(5).setImm((MB - 1) & 31);
1173 unsigned &SrcOpIdx1,
1174 unsigned &SrcOpIdx2)
const {
1185 return fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 2, 3);
1192 unsigned Directive = Subtarget.getCPUDirective();
1195 default: Opcode = PPC::NOP;
break;
1221 bool AllowModify)
const {
1222 bool isPPC64 = Subtarget.isPPC64();
1229 if (!isUnpredicatedTerminator(*
I))
1235 if (
I->getOpcode() == PPC::B &&
1236 MBB.isLayoutSuccessor(
I->getOperand(0).getMBB())) {
1237 I->eraseFromParent();
1240 I =
MBB.getLastNonDebugInstr();
1241 if (
I ==
MBB.end() || !isUnpredicatedTerminator(*
I))
1250 if (
I ==
MBB.begin() || !isUnpredicatedTerminator(*--
I)) {
1256 }
else if (LastInst.
getOpcode() == PPC::BCC) {
1264 }
else if (LastInst.
getOpcode() == PPC::BC) {
1272 }
else if (LastInst.
getOpcode() == PPC::BCn) {
1280 }
else if (LastInst.
getOpcode() == PPC::BDNZ8 ||
1284 if (!Subtarget.getCLOpts().ctr_loop_analysis)
1291 }
else if (LastInst.
getOpcode() == PPC::BDZ8 ||
1295 if (!Subtarget.getCLOpts().ctr_loop_analysis)
1312 if (
I !=
MBB.begin() && isUnpredicatedTerminator(*--
I))
1316 if (SecondLastInst.
getOpcode() == PPC::BCC &&
1326 }
else if (SecondLastInst.
getOpcode() == PPC::BC &&
1336 }
else if (SecondLastInst.
getOpcode() == PPC::BCn &&
1346 }
else if ((SecondLastInst.
getOpcode() == PPC::BDNZ8 ||
1347 SecondLastInst.
getOpcode() == PPC::BDNZ) &&
1352 if (!Subtarget.getCLOpts().ctr_loop_analysis)
1360 }
else if ((SecondLastInst.
getOpcode() == PPC::BDZ8 ||
1361 SecondLastInst.
getOpcode() == PPC::BDZ) &&
1366 if (!Subtarget.getCLOpts().ctr_loop_analysis)
1384 I->eraseFromParent();
1393 int *BytesRemoved)
const {
1394 assert(!BytesRemoved &&
"code size not handled");
1400 if (
I->getOpcode() != PPC::B &&
I->getOpcode() != PPC::BCC &&
1401 I->getOpcode() != PPC::BC &&
I->getOpcode() != PPC::BCn &&
1402 I->getOpcode() != PPC::BDNZ8 &&
I->getOpcode() != PPC::BDNZ &&
1403 I->getOpcode() != PPC::BDZ8 &&
I->getOpcode() != PPC::BDZ)
1407 I->eraseFromParent();
1411 if (
I ==
MBB.begin())
return 1;
1413 if (
I->getOpcode() != PPC::BCC &&
1414 I->getOpcode() != PPC::BC &&
I->getOpcode() != PPC::BCn &&
1415 I->getOpcode() != PPC::BDNZ8 &&
I->getOpcode() != PPC::BDNZ &&
1416 I->getOpcode() != PPC::BDZ8 &&
I->getOpcode() != PPC::BDZ)
1420 I->eraseFromParent();
1429 int *BytesAdded)
const {
1431 assert(
TBB &&
"insertBranch must not be told to insert a fallthrough");
1433 "PPC branch conditions have two components!");
1434 assert(!BytesAdded &&
"code size not handled");
1436 bool isPPC64 = Subtarget.isPPC64();
1444 (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ) :
1445 (isPPC64 ? PPC::BDZ8 : PPC::BDZ))).
addMBB(
TBB);
1461 (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ) :
1462 (isPPC64 ? PPC::BDZ8 : PPC::BDZ))).
addMBB(
TBB);
1481 SelectExpansion &Exp)
const {
1482 if (!Subtarget.hasISEL())
1485 if (
Cond.size() != 2)
1501 RI.getCommonSubClass(
MRI.getRegClass(TrueReg),
MRI.getRegClass(FalseReg));
1506 if (!PPC::GPRCRegClass.hasSubClassEq(RC) &&
1507 !PPC::GPRC_NOR0RegClass.hasSubClassEq(RC) &&
1508 !PPC::G8RCRegClass.hasSubClassEq(RC) &&
1509 !PPC::G8RC_NOX0RegClass.hasSubClassEq(RC))
1518 Exp.FalseCycles = 1;
1529 "PPC branch conditions have two components!");
1534 RI.getCommonSubClass(
MRI.getRegClass(TrueReg),
MRI.getRegClass(FalseReg));
1535 assert(RC &&
"TrueReg and FalseReg must have overlapping register classes");
1537 bool Is64Bit = PPC::G8RCRegClass.hasSubClassEq(RC) ||
1538 PPC::G8RC_NOX0RegClass.hasSubClassEq(RC);
1540 PPC::GPRCRegClass.hasSubClassEq(RC) ||
1541 PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) &&
1542 "isel is for regular integer GPRs only");
1544 unsigned OpCode = Is64Bit ? PPC::ISEL8 : PPC::ISEL;
1547 unsigned SubIdx = 0;
1548 bool SwapOps =
false;
1549 switch (SelectPred) {
1553 SubIdx = PPC::sub_eq; SwapOps =
false;
break;
1557 SubIdx = PPC::sub_eq; SwapOps =
true;
break;
1561 SubIdx = PPC::sub_lt; SwapOps =
false;
break;
1565 SubIdx = PPC::sub_lt; SwapOps =
true;
break;
1569 SubIdx = PPC::sub_gt; SwapOps =
false;
break;
1573 SubIdx = PPC::sub_gt; SwapOps =
true;
break;
1577 SubIdx = PPC::sub_un; SwapOps =
false;
break;
1581 SubIdx = PPC::sub_un; SwapOps =
true;
break;
1586 Register FirstReg = SwapOps ? FalseReg : TrueReg,
1587 SecondReg = SwapOps ? TrueReg : FalseReg;
1592 if (
MRI.getRegClass(FirstReg)->contains(PPC::R0) ||
1593 MRI.getRegClass(FirstReg)->contains(PPC::X0)) {
1595 MRI.getRegClass(FirstReg)->contains(PPC::X0) ?
1596 &PPC::G8RC_NOX0RegClass : &PPC::GPRC_NOR0RegClass;
1598 FirstReg =
MRI.createVirtualRegister(FirstRC);
1611 if (CRBit == PPC::CR0LT || CRBit == PPC::CR1LT ||
1612 CRBit == PPC::CR2LT || CRBit == PPC::CR3LT ||
1613 CRBit == PPC::CR4LT || CRBit == PPC::CR5LT ||
1614 CRBit == PPC::CR6LT || CRBit == PPC::CR7LT)
1616 if (CRBit == PPC::CR0GT || CRBit == PPC::CR1GT ||
1617 CRBit == PPC::CR2GT || CRBit == PPC::CR3GT ||
1618 CRBit == PPC::CR4GT || CRBit == PPC::CR5GT ||
1619 CRBit == PPC::CR6GT || CRBit == PPC::CR7GT)
1621 if (CRBit == PPC::CR0EQ || CRBit == PPC::CR1EQ ||
1622 CRBit == PPC::CR2EQ || CRBit == PPC::CR3EQ ||
1623 CRBit == PPC::CR4EQ || CRBit == PPC::CR5EQ ||
1624 CRBit == PPC::CR6EQ || CRBit == PPC::CR7EQ)
1626 if (CRBit == PPC::CR0UN || CRBit == PPC::CR1UN ||
1627 CRBit == PPC::CR2UN || CRBit == PPC::CR3UN ||
1628 CRBit == PPC::CR4UN || CRBit == PPC::CR5UN ||
1629 CRBit == PPC::CR6UN || CRBit == PPC::CR7UN)
1632 assert(Ret != 4 &&
"Invalid CR bit register");
1640 bool RenamableDest,
bool RenamableSrc)
const {
1643 if (PPC::F8RCRegClass.
contains(DestReg) &&
1644 PPC::VSRCRegClass.
contains(SrcReg)) {
1646 RI.getMatchingSuperReg(DestReg, PPC::sub_64, &PPC::VSRCRegClass);
1648 if (Subtarget.getCLOpts().crash_on_vsx_self_copy && SrcReg == SuperReg)
1652 }
else if (PPC::F8RCRegClass.
contains(SrcReg) &&
1653 PPC::VSRCRegClass.
contains(DestReg)) {
1655 RI.getMatchingSuperReg(SrcReg, PPC::sub_64, &PPC::VSRCRegClass);
1657 if (Subtarget.getCLOpts().crash_on_vsx_self_copy && DestReg == SuperReg)
1664 if (PPC::CRBITRCRegClass.
contains(SrcReg) &&
1665 PPC::GPRCRegClass.
contains(DestReg)) {
1677 }
else if (PPC::CRRCRegClass.
contains(SrcReg) &&
1678 (PPC::G8RCRegClass.
contains(DestReg) ||
1679 PPC::GPRCRegClass.
contains(DestReg))) {
1680 bool Is64Bit = PPC::G8RCRegClass.contains(DestReg);
1681 unsigned MvCode = Is64Bit ? PPC::MFOCRF8 : PPC::MFOCRF;
1682 unsigned ShCode = Is64Bit ? PPC::RLWINM8 : PPC::RLWINM;
1683 unsigned CRNum = RI.getEncodingValue(SrcReg);
1695 }
else if (PPC::G8RCRegClass.
contains(SrcReg) &&
1696 PPC::VSFRCRegClass.
contains(DestReg)) {
1697 assert(Subtarget.hasDirectMove() &&
1698 "Subtarget doesn't support directmove, don't know how to copy.");
1703 }
else if (PPC::VSFRCRegClass.
contains(SrcReg) &&
1704 PPC::G8RCRegClass.
contains(DestReg)) {
1705 assert(Subtarget.hasDirectMove() &&
1706 "Subtarget doesn't support directmove, don't know how to copy.");
1710 }
else if (PPC::SPERCRegClass.
contains(SrcReg) &&
1711 PPC::GPRCRegClass.
contains(DestReg)) {
1715 }
else if (PPC::GPRCRegClass.
contains(SrcReg) &&
1716 PPC::SPERCRegClass.
contains(DestReg)) {
1720 }
else if ((PPC::G8RCRegClass.
contains(DestReg) ||
1721 PPC::GPRCRegClass.
contains(DestReg)) &&
1722 SrcReg == PPC::CARRY) {
1723 bool Is64Bit = PPC::G8RCRegClass.contains(DestReg);
1728 }
else if ((PPC::G8RCRegClass.
contains(SrcReg) ||
1729 PPC::GPRCRegClass.
contains(SrcReg)) &&
1730 DestReg == PPC::CARRY) {
1731 bool Is64Bit = PPC::G8RCRegClass.contains(SrcReg);
1740 if (PPC::GPRCRegClass.
contains(DestReg, SrcReg))
1742 else if (PPC::G8RCRegClass.
contains(DestReg, SrcReg))
1744 else if (PPC::F4RCRegClass.
contains(DestReg, SrcReg))
1746 else if (PPC::CRRCRegClass.
contains(DestReg, SrcReg))
1748 else if (PPC::VRRCRegClass.
contains(DestReg, SrcReg))
1750 else if (PPC::VSRCRegClass.
contains(DestReg, SrcReg))
1760 else if (PPC::VSFRCRegClass.
contains(DestReg, SrcReg) ||
1761 PPC::VSSRCRegClass.
contains(DestReg, SrcReg))
1762 Opc = (Subtarget.hasP9Vector()) ? PPC::XSCPSGNDP : PPC::XXLORf;
1763 else if (Subtarget.pairedVectorMemops() &&
1764 PPC::VSRpRCRegClass.contains(DestReg, SrcReg)) {
1765 if (SrcReg > PPC::VSRp15)
1766 SrcReg = PPC::V0 + (SrcReg - PPC::VSRp16) * 2;
1768 SrcReg = PPC::VSL0 + (SrcReg - PPC::VSRp0) * 2;
1769 if (DestReg > PPC::VSRp15)
1770 DestReg = PPC::V0 + (DestReg - PPC::VSRp16) * 2;
1772 DestReg = PPC::VSL0 + (DestReg - PPC::VSRp0) * 2;
1779 else if (PPC::CRBITRCRegClass.
contains(DestReg, SrcReg))
1781 else if (PPC::SPERCRegClass.
contains(DestReg, SrcReg))
1783 else if ((PPC::ACCRCRegClass.
contains(DestReg) ||
1784 PPC::UACCRCRegClass.
contains(DestReg)) &&
1785 (PPC::ACCRCRegClass.
contains(SrcReg) ||
1786 PPC::UACCRCRegClass.
contains(SrcReg))) {
1792 bool DestPrimed = PPC::ACCRCRegClass.contains(DestReg);
1793 bool SrcPrimed = PPC::ACCRCRegClass.contains(SrcReg);
1795 PPC::VSL0 + (SrcReg - (SrcPrimed ? PPC::ACC0 : PPC::UACC0)) * 4;
1797 PPC::VSL0 + (DestReg - (DestPrimed ? PPC::ACC0 : PPC::UACC0)) * 4;
1800 for (
unsigned Idx = 0; Idx < 4; Idx++)
1806 if (SrcPrimed && !KillSrc)
1809 }
else if (PPC::G8pRCRegClass.
contains(DestReg) &&
1810 PPC::G8pRCRegClass.
contains(SrcReg)) {
1812 unsigned DestRegIdx = DestReg - PPC::G8p0;
1813 MCRegister DestRegSub0 = PPC::X0 + 2 * DestRegIdx;
1814 MCRegister DestRegSub1 = PPC::X0 + 2 * DestRegIdx + 1;
1815 unsigned SrcRegIdx = SrcReg - PPC::G8p0;
1816 MCRegister SrcRegSub0 = PPC::X0 + 2 * SrcRegIdx;
1817 MCRegister SrcRegSub1 = PPC::X0 + 2 * SrcRegIdx + 1;
1825 }
else if ((PPC::WACCRCRegClass.
contains(DestReg) ||
1826 PPC::WACC_HIRCRegClass.
contains(DestReg)) &&
1827 (PPC::WACCRCRegClass.
contains(SrcReg) ||
1828 PPC::WACC_HIRCRegClass.
contains(SrcReg))) {
1830 Opc = PPC::WACCRCRegClass.contains(SrcReg) ? PPC::DMXXEXTFDMR512
1831 : PPC::DMXXEXTFDMR512_HI;
1834 RS.enterBasicBlockEnd(
MBB);
1835 RS.backward(std::next(
I));
1837 Register TmpReg1 = RS.scavengeRegisterBackwards(PPC::VSRpRCRegClass,
I,
1841 RS.setRegUsed(TmpReg1);
1842 Register TmpReg2 = RS.scavengeRegisterBackwards(PPC::VSRpRCRegClass,
I,
1851 Opc = PPC::WACCRCRegClass.contains(DestReg) ? PPC::DMXXINSTDMR512
1852 : PPC::DMXXINSTDMR512_HI;
1859 }
else if (PPC::DMRRCRegClass.
contains(DestReg) &&
1860 PPC::DMRRCRegClass.
contains(SrcReg)) {
1871 if (
MCID.getNumOperands() == 3)
1881 if (PPC::GPRCRegClass.hasSubClassEq(RC) ||
1882 PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) {
1884 }
else if (PPC::G8RCRegClass.hasSubClassEq(RC) ||
1885 PPC::G8RC_NOX0RegClass.hasSubClassEq(RC)) {
1887 }
else if (PPC::F8RCRegClass.hasSubClassEq(RC)) {
1889 }
else if (PPC::F4RCRegClass.hasSubClassEq(RC)) {
1891 }
else if (PPC::SPERCRegClass.hasSubClassEq(RC)) {
1893 }
else if (PPC::CRRCRegClass.hasSubClassEq(RC)) {
1895 }
else if (PPC::CRBITRCRegClass.hasSubClassEq(RC)) {
1897 }
else if (PPC::VRRCRegClass.hasSubClassEq(RC)) {
1899 }
else if (PPC::VSRCRegClass.hasSubClassEq(RC)) {
1901 }
else if (PPC::VSFRCRegClass.hasSubClassEq(RC)) {
1903 }
else if (PPC::VSSRCRegClass.hasSubClassEq(RC)) {
1905 }
else if (PPC::SPILLTOVSRRCRegClass.hasSubClassEq(RC)) {
1907 }
else if (PPC::ACCRCRegClass.hasSubClassEq(RC)) {
1908 assert(Subtarget.pairedVectorMemops() &&
1909 "Register unexpected when paired memops are disabled.");
1911 }
else if (PPC::UACCRCRegClass.hasSubClassEq(RC)) {
1912 assert(Subtarget.pairedVectorMemops() &&
1913 "Register unexpected when paired memops are disabled.");
1915 }
else if (PPC::WACCRCRegClass.hasSubClassEq(RC)) {
1916 assert(Subtarget.pairedVectorMemops() &&
1917 "Register unexpected when paired memops are disabled.");
1919 }
else if (PPC::VSRpRCRegClass.hasSubClassEq(RC)) {
1920 assert(Subtarget.pairedVectorMemops() &&
1921 "Register unexpected when paired memops are disabled.");
1923 }
else if (PPC::G8pRCRegClass.hasSubClassEq(RC)) {
1925 }
else if (PPC::DMRROWRCRegClass.hasSubClassEq(RC)) {
1927 }
else if (PPC::DMRROWpRCRegClass.hasSubClassEq(RC)) {
1929 }
else if (PPC::DMRpRCRegClass.hasSubClassEq(RC)) {
1931 }
else if (PPC::DMRRCRegClass.hasSubClassEq(RC)) {
1942 return OpcodesForSpill[getSpillIndex(RC)];
1948 return OpcodesForSpill[getSpillIndex(RC)];
1951void PPCInstrInfo::StoreRegToStackSlot(
1965 if (PPC::CRRCRegClass.hasSubClassEq(RC) ||
1966 PPC::CRBITRCRegClass.hasSubClassEq(RC))
1979 StoreRegToStackSlot(MF, SrcReg, isKill, FrameIdx, RC, NewMIs);
1982 MBB.insert(
MI, NewMI);
1989 NewMIs.
back()->addMemOperand(MF, MMO);
2008 unsigned DestReg,
int FrameIdx,
2023 if (
MI !=
MBB.end())
DL =
MI->getDebugLoc();
2025 LoadRegFromStackSlot(MF,
DL, DestReg, FrameIdx, RC, NewMIs);
2028 MBB.insert(
MI, NewMI);
2035 NewMIs.
back()->addMemOperand(MF, MMO);
2058 assert(
Cond.size() == 2 &&
"Invalid PPC branch opcode!");
2073 unsigned DefOpc =
DefMI.getOpcode();
2074 if (DefOpc != PPC::LI && DefOpc != PPC::LI8)
2076 if (!
DefMI.getOperand(1).isImm())
2078 if (
DefMI.getOperand(1).getImm() != 0)
2094 for (UseIdx = 0; UseIdx <
UseMI.getNumOperands(); ++UseIdx)
2095 if (
UseMI.getOperand(UseIdx).isReg() &&
2096 UseMI.getOperand(UseIdx).getReg() == Reg)
2099 assert(UseIdx <
UseMI.getNumOperands() &&
"Cannot find Reg in UseMI");
2106 int16_t RegClass = getOpRegClassID(UseInfo);
2107 if (UseInfo.RegClass != PPC::GPRC_NOR0RegClassID &&
2108 UseInfo.RegClass != PPC::G8RC_NOX0RegClassID)
2114 if (UseInfo.Constraints != 0)
2118 RegClass == PPC::G8RC_NOX0RegClassID ? PPC::ZERO8 : PPC::ZERO;
2122 UseMI.getOperand(UseIdx).setReg(ZeroReg);
2134 if (
MRI->use_nodbg_empty(Reg))
2135 DefMI.eraseFromParent();
2141 if (
MI.definesRegister(PPC::CTR,
nullptr) ||
2142 MI.definesRegister(PPC::CTR8,
nullptr))
2154 unsigned NumT,
unsigned ExtraT,
2156 unsigned NumF,
unsigned ExtraF,
2176 switch (
MI.getOpcode()) {
2192 unsigned OpC =
MI.getOpcode();
2193 if (OpC == PPC::BLR || OpC == PPC::BLR8) {
2194 if (Pred[1].
getReg() == PPC::CTR8 || Pred[1].
getReg() == PPC::CTR) {
2195 bool isPPC64 = Subtarget.isPPC64();
2196 MI.setDesc(
get(Pred[0].
getImm() ? (isPPC64 ? PPC::BDNZLR8 : PPC::BDNZLR)
2197 : (isPPC64 ? PPC::BDZLR8 : PPC::BDZLR)));
2203 MI.setDesc(
get(PPC::BCLR));
2206 MI.setDesc(
get(PPC::BCLRn));
2209 MI.setDesc(
get(PPC::BCCLR));
2216 }
else if (OpC == PPC::B) {
2217 if (Pred[1].
getReg() == PPC::CTR8 || Pred[1].
getReg() == PPC::CTR) {
2218 bool isPPC64 = Subtarget.isPPC64();
2219 MI.setDesc(
get(Pred[0].
getImm() ? (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ)
2220 : (isPPC64 ? PPC::BDZ8 : PPC::BDZ)));
2227 MI.removeOperand(0);
2229 MI.setDesc(
get(PPC::BC));
2235 MI.removeOperand(0);
2237 MI.setDesc(
get(PPC::BCn));
2243 MI.removeOperand(0);
2245 MI.setDesc(
get(PPC::BCC));
2253 }
else if (OpC == PPC::BCTR || OpC == PPC::BCTR8 || OpC == PPC::BCTRL ||
2254 OpC == PPC::BCTRL8 || OpC == PPC::BCTRL_RM ||
2255 OpC == PPC::BCTRL8_RM) {
2256 if (Pred[1].
getReg() == PPC::CTR8 || Pred[1].
getReg() == PPC::CTR)
2259 bool setLR = OpC == PPC::BCTRL || OpC == PPC::BCTRL8 ||
2260 OpC == PPC::BCTRL_RM || OpC == PPC::BCTRL8_RM;
2261 bool isPPC64 = Subtarget.isPPC64();
2264 MI.setDesc(
get(isPPC64 ? (setLR ? PPC::BCCTRL8 : PPC::BCCTR8)
2265 : (setLR ? PPC::BCCTRL : PPC::BCCTR)));
2268 MI.setDesc(
get(isPPC64 ? (setLR ? PPC::BCCTRL8n : PPC::BCCTR8n)
2269 : (setLR ? PPC::BCCTRLn : PPC::BCCTRn)));
2272 MI.setDesc(
get(isPPC64 ? (setLR ? PPC::BCCCTRL8 : PPC::BCCCTR8)
2273 : (setLR ? PPC::BCCCTRL : PPC::BCCCTR)));
2284 if (OpC == PPC::BCTRL_RM || OpC == PPC::BCTRL8_RM)
2296 assert(Pred1.
size() == 2 &&
"Invalid PPC first predicate");
2297 assert(Pred2.
size() == 2 &&
"Invalid PPC second predicate");
2299 if (Pred1[1].
getReg() == PPC::CTR8 || Pred1[1].
getReg() == PPC::CTR)
2301 if (Pred2[1].
getReg() == PPC::CTR8 || Pred2[1].
getReg() == PPC::CTR)
2326 std::vector<MachineOperand> &Pred,
2327 bool SkipDead)
const {
2335 { &PPC::CRRCRegClass, &PPC::CRBITRCRegClass,
2336 &PPC::CTRRCRegClass, &PPC::CTRRC8RegClass };
2340 for (
unsigned c = 0; c < std::size(RCs) && !Found; ++c) {
2343 if (MO.isDef() && RC->
contains(MO.getReg())) {
2347 }
else if (MO.isRegMask()) {
2349 if (MO.clobbersPhysReg(R)) {
2362 int64_t &
Value)
const {
2363 unsigned Opc =
MI.getOpcode();
2366 default:
return false;
2371 SrcReg =
MI.getOperand(1).getReg();
2373 Value =
MI.getOperand(2).getImm();
2382 SrcReg =
MI.getOperand(1).getReg();
2383 SrcReg2 =
MI.getOperand(2).getReg();
2394 if (!Subtarget.getCLOpts().cmp_opt)
2402 if (OpC == PPC::FCMPUS || OpC == PPC::FCMPUD)
2413 bool isPPC64 = Subtarget.isPPC64();
2414 bool is32BitSignedCompare = OpC == PPC::CMPWI || OpC == PPC::CMPW;
2415 bool is32BitUnsignedCompare = OpC == PPC::CMPLWI || OpC == PPC::CMPLW;
2416 bool is64BitUnsignedCompare = OpC == PPC::CMPLDI || OpC == PPC::CMPLD;
2419 Register ActualSrc = RI.lookThruCopyLike(SrcReg,
MRI);
2425 if (!
MI)
return false;
2427 bool equalityOnly =
false;
2430 if (is32BitSignedCompare) {
2436 }
else if (is32BitUnsignedCompare) {
2441 equalityOnly =
true;
2445 equalityOnly = is64BitUnsignedCompare;
2447 equalityOnly = is32BitUnsignedCompare;
2453 I =
MRI->use_instr_begin(CRReg), IE =
MRI->use_instr_end();
2456 if (
UseMI->getOpcode() == PPC::BCC) {
2462 }
else if (
UseMI->getOpcode() == PPC::ISEL ||
2463 UseMI->getOpcode() == PPC::ISEL8) {
2464 unsigned SubIdx =
UseMI->getOperand(3).getSubReg();
2465 if (SubIdx != PPC::sub_eq)
2477 bool FoundUse =
false;
2479 J =
MRI->use_instr_begin(CRReg), JE =
MRI->use_instr_end();
2506 else if (
Value != 0) {
2515 if (equalityOnly || !
MRI->hasOneUse(CRReg))
2519 if (
UseMI->getOpcode() != PPC::BCC)
2525 int16_t Immed = (int16_t)
Value;
2549 UseMI->getOperand(0).setImm(Pred);
2559 for (;
I != E && !noSub; --
I) {
2561 unsigned IOpC = Instr.getOpcode();
2563 if (&*
I != &CmpInstr && (Instr.modifiesRegister(PPC::CR0, &RI) ||
2564 Instr.readsRegister(PPC::CR0, &RI)))
2573 if ((OpC == PPC::CMPW || OpC == PPC::CMPLW ||
2574 OpC == PPC::CMPD || OpC == PPC::CMPLD) &&
2575 (IOpC == PPC::SUBF || IOpC == PPC::SUBF8) &&
2576 ((Instr.getOperand(1).getReg() == SrcReg &&
2577 Instr.getOperand(2).getReg() == SrcReg2) ||
2578 (Instr.getOperand(1).getReg() == SrcReg2 &&
2579 Instr.getOperand(2).getReg() == SrcReg))) {
2597 int MIOpC =
MI->getOpcode();
2598 if (MIOpC == PPC::ANDI_rec || MIOpC == PPC::ANDI8_rec ||
2599 MIOpC == PPC::ANDIS_rec || MIOpC == PPC::ANDIS8_rec)
2602 NewOpC = PPC::getRecordFormOpcode(MIOpC);
2626 const bool IntroducesRecFormInstr = MIOpC != NewOpC;
2627 if (IntroducesRecFormInstr) {
2629 if (
MBB->computeRegisterLiveness(
2639 if (!equalityOnly && (NewOpC == PPC::SUBF_rec || NewOpC == PPC::SUBF8_rec) &&
2649 bool ShouldSwap =
false;
2651 ShouldSwap = SrcReg2 != 0 &&
Sub->getOperand(1).getReg() == SrcReg2 &&
2652 Sub->getOperand(2).getReg() == SrcReg;
2656 ShouldSwap = !ShouldSwap;
2661 I =
MRI->use_instr_begin(CRReg), IE =
MRI->use_instr_end();
2664 if (
UseMI->getOpcode() == PPC::BCC) {
2669 "Invalid predicate for equality-only optimization");
2673 }
else if (
UseMI->getOpcode() == PPC::ISEL ||
2674 UseMI->getOpcode() == PPC::ISEL8) {
2675 unsigned NewSubReg =
UseMI->getOperand(3).getSubReg();
2676 assert((!equalityOnly || NewSubReg == PPC::sub_eq) &&
2677 "Invalid CR bit for equality-only optimization");
2679 if (NewSubReg == PPC::sub_lt)
2680 NewSubReg = PPC::sub_gt;
2681 else if (NewSubReg == PPC::sub_gt)
2682 NewSubReg = PPC::sub_lt;
2684 SubRegsToUpdate.
push_back(std::make_pair(&(
UseMI->getOperand(3)),
2690 "Non-zero immediate support and ShouldSwap"
2691 "may conflict in updating predicate");
2699 BuildMI(*
MI->getParent(), std::next(MII),
MI->getDebugLoc(),
2700 get(TargetOpcode::COPY), CRReg)
2705 MI->clearRegisterDeads(PPC::CR0);
2707 if (MIOpC != NewOpC) {
2717 if (MIOpC == PPC::RLWINM || MIOpC == PPC::RLWINM8) {
2718 Register GPRRes =
MI->getOperand(0).getReg();
2719 int64_t SH =
MI->getOperand(2).getImm();
2720 int64_t MB =
MI->getOperand(3).getImm();
2721 int64_t ME =
MI->getOperand(4).getImm();
2724 bool MBInLoHWord = MB >= 16;
2725 bool MEInLoHWord = ME >= 16;
2726 uint64_t Mask = ~0LLU;
2728 if (MB <= ME && MBInLoHWord == MEInLoHWord && SH == 0) {
2729 Mask = ((1LLU << (32 - MB)) - 1) & ~((1LLU << (31 - ME)) - 1);
2731 Mask >>= MBInLoHWord ? 0 : 16;
2732 NewOpC = MIOpC == PPC::RLWINM
2733 ? (MBInLoHWord ? PPC::ANDI_rec : PPC::ANDIS_rec)
2734 : (MBInLoHWord ? PPC::ANDI8_rec : PPC::ANDIS8_rec);
2735 }
else if (
MRI->use_empty(GPRRes) && (ME == 31) &&
2736 (ME - MB + 1 == SH) && (MB >= 16)) {
2740 Mask = ((1LLU << 32) - 1) & ~((1LLU << (32 - SH)) - 1);
2742 NewOpC = MIOpC == PPC::RLWINM ? PPC::ANDIS_rec : PPC::ANDIS8_rec;
2745 if (Mask != ~0LLU) {
2746 MI->removeOperand(4);
2747 MI->removeOperand(3);
2748 MI->getOperand(2).setImm(Mask);
2749 NumRcRotatesConvertedToRcAnd++;
2751 }
else if (MIOpC == PPC::RLDICL &&
MI->getOperand(2).getImm() == 0) {
2752 int64_t MB =
MI->getOperand(3).getImm();
2754 uint64_t Mask = (1LLU << (63 - MB + 1)) - 1;
2755 NewOpC = PPC::ANDI8_rec;
2756 MI->removeOperand(3);
2757 MI->getOperand(2).setImm(Mask);
2758 NumRcRotatesConvertedToRcAnd++;
2763 MI->setDesc(NewDesc);
2766 if (!
MI->definesRegister(ImpDef,
nullptr)) {
2767 MI->addOperand(*
MI->getParent()->getParent(),
2772 if (!
MI->readsRegister(ImpUse,
nullptr)) {
2773 MI->addOperand(*
MI->getParent()->getParent(),
2778 assert(
MI->definesRegister(PPC::CR0,
nullptr) &&
2779 "Record-form instruction does not define cr0?");
2784 for (
unsigned i = 0, e = PredsToUpdate.
size(); i < e; i++)
2785 PredsToUpdate[i].first->setImm(PredsToUpdate[i].second);
2787 for (
unsigned i = 0, e = SubRegsToUpdate.
size(); i < e; i++)
2788 SubRegsToUpdate[i].first->setSubReg(SubRegsToUpdate[i].second);
2799 int64_t CmpMask, CmpValue;
2804 if (CmpValue || !CmpMask || SrcReg2)
2812 if (
Opc == PPC::CMPLWI ||
Opc == PPC::CMPLDI)
2819 if (Subtarget.isPPC64() &&
Opc == PPC::CMPWI)
2826 bool SrcRegHasOtherUse =
false;
2833 if (CRReg != PPC::CR0)
2837 bool SeenUseOfCRReg =
false;
2838 bool IsCRRegKilled =
false;
2839 if (!isRegElgibleForForwarding(RegMO, *SrcMI, CmpMI,
false, IsCRRegKilled,
2845 int NewOpC = PPC::getRecordFormOpcode(SrcMIOpc);
2859 "Record-form instruction does not define cr0?");
2872 OffsetIsScalable =
false;
2907 case PPC::DFSTOREf64:
2908 return FirstOpc == SecondOpc;
2914 return SecondOpc == PPC::STW || SecondOpc == PPC::STW8;
2921 int64_t OpOffset2,
bool OffsetIsScalable2,
unsigned ClusterSize,
2922 unsigned NumBytes)
const {
2928 "Only base registers and frame indices are supported.");
2933 if (ClusterSize > 2)
2947 unsigned FirstOpc = FirstLdSt.
getOpcode();
2948 unsigned SecondOpc = SecondLdSt.
getOpcode();
2959 int64_t Offset1 = 0, Offset2 = 0;
2968 assert(Base1 == &BaseOp1 && Base2 == &BaseOp2 &&
2969 "getMemOperandWithOffsetWidth return incorrect base op");
2971 assert(Offset1 <= Offset2 &&
"Caller should have ordered offsets.");
2972 return Offset1 + (int64_t)Width1.
getValue() == Offset2;
2979 unsigned Opcode =
MI.getOpcode();
2982 case PPC::INLINEASM:
2983 case PPC::INLINEASM_BR: {
2985 const char *AsmStr =
MI.getOperand(0).getSymbolName();
2988 case TargetOpcode::STACKMAP: {
2992 case TargetOpcode::PATCHPOINT: {
2996 case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
2999 unsigned Num =
F.getFnAttributeAsParsedInteger(
"patchable-function-entry");
3006 case TargetOpcode::PATCHABLE_RET: {
3008 unsigned RetOpcode =
MI.getOperand(0).getImm();
3009 bool IsConditional = RetOpcode == PPC::BCCLR;
3010 return (8 + IsConditional) * 4;
3012 case TargetOpcode::BUNDLE:
3013 return getInstBundleSize(
MI);
3015 return get(Opcode).getSize();
3022 return MI.getOpcode() == TargetOpcode::STACKMAP
3023 ? InstSizeVerifyMode::AllowOverEstimate
3024 : InstSizeVerifyMode::ExactSize;
3027std::pair<unsigned, unsigned>
3030 return std::make_pair(TF, 0u);
3035 using namespace PPCII;
3036 static const std::pair<unsigned, const char *> TargetFlags[] = {
3037 {MO_PLT,
"ppc-plt"},
3038 {MO_PIC_FLAG,
"ppc-pic"},
3039 {MO_PCREL_FLAG,
"ppc-pcrel"},
3040 {MO_GOT_FLAG,
"ppc-got"},
3041 {MO_PCREL_OPT_FLAG,
"ppc-opt-pcrel"},
3042 {MO_TLSGD_FLAG,
"ppc-tlsgd"},
3043 {MO_TPREL_FLAG,
"ppc-tprel"},
3044 {MO_TLSLDM_FLAG,
"ppc-tlsldm"},
3045 {MO_TLSLD_FLAG,
"ppc-tlsld"},
3046 {MO_TLSGDM_FLAG,
"ppc-tlsgdm"},
3047 {MO_GOT_TLSGD_PCREL_FLAG,
"ppc-got-tlsgd-pcrel"},
3048 {MO_GOT_TLSLD_PCREL_FLAG,
"ppc-got-tlsld-pcrel"},
3049 {MO_GOT_TPREL_PCREL_FLAG,
"ppc-got-tprel-pcrel"},
3052 {MO_TPREL_LO,
"ppc-tprel-lo"},
3053 {MO_TPREL_HA,
"ppc-tprel-ha"},
3054 {MO_DTPREL_LO,
"ppc-dtprel-lo"},
3055 {MO_TLSLD_LO,
"ppc-tlsld-lo"},
3056 {MO_TOC_LO,
"ppc-toc-lo"},
3057 {MO_TLS,
"ppc-tls"},
3058 {MO_PIC_HA_FLAG,
"ppc-ha-pic"},
3059 {MO_PIC_LO_FLAG,
"ppc-lo-pic"},
3060 {MO_TPREL_PCREL_FLAG,
"ppc-tprel-pcrel"},
3061 {MO_TLS_PCREL_FLAG,
"ppc-tls-pcrel"},
3062 {MO_GOT_PCREL_FLAG,
"ppc-got-pcrel"},
3074 unsigned UpperOpcode, LowerOpcode;
3075 switch (
MI.getOpcode()) {
3076 case PPC::DFLOADf32:
3077 UpperOpcode = PPC::LXSSP;
3078 LowerOpcode = PPC::LFS;
3080 case PPC::DFLOADf64:
3081 UpperOpcode = PPC::LXSD;
3082 LowerOpcode = PPC::LFD;
3084 case PPC::DFSTOREf32:
3085 UpperOpcode = PPC::STXSSP;
3086 LowerOpcode = PPC::STFS;
3088 case PPC::DFSTOREf64:
3089 UpperOpcode = PPC::STXSD;
3090 LowerOpcode = PPC::STFD;
3092 case PPC::XFLOADf32:
3093 UpperOpcode = PPC::LXSSPX;
3094 LowerOpcode = PPC::LFSX;
3096 case PPC::XFLOADf64:
3097 UpperOpcode = PPC::LXSDX;
3098 LowerOpcode = PPC::LFDX;
3100 case PPC::XFSTOREf32:
3101 UpperOpcode = PPC::STXSSPX;
3102 LowerOpcode = PPC::STFSX;
3104 case PPC::XFSTOREf64:
3105 UpperOpcode = PPC::STXSDX;
3106 LowerOpcode = PPC::STFDX;
3109 UpperOpcode = PPC::LXSIWAX;
3110 LowerOpcode = PPC::LFIWAX;
3113 UpperOpcode = PPC::LXSIWZX;
3114 LowerOpcode = PPC::LFIWZX;
3117 UpperOpcode = PPC::STXSIWX;
3118 LowerOpcode = PPC::STFIWX;
3124 Register TargetReg =
MI.getOperand(0).getReg();
3126 if ((TargetReg >= PPC::F0 && TargetReg <= PPC::F31) ||
3127 (TargetReg >= PPC::VSL0 && TargetReg <= PPC::VSL31))
3128 Opcode = LowerOpcode;
3130 Opcode = UpperOpcode;
3131 MI.setDesc(
get(Opcode));
3140 auto &
MBB = *
MI.getParent();
3141 auto DL =
MI.getDebugLoc();
3143 switch (
MI.getOpcode()) {
3144 case PPC::BUILD_UACC: {
3147 if (ACC - PPC::ACC0 != UACC - PPC::UACC0) {
3148 MCRegister SrcVSR = PPC::VSL0 + (UACC - PPC::UACC0) * 4;
3149 MCRegister DstVSR = PPC::VSL0 + (ACC - PPC::ACC0) * 4;
3153 for (
int VecNo = 0; VecNo < 4; VecNo++)
3163 case PPC::KILL_PAIR: {
3164 MI.setDesc(
get(PPC::UNENCODED_NOP));
3165 MI.removeOperand(1);
3166 MI.removeOperand(0);
3169 case TargetOpcode::LOAD_STACK_GUARD: {
3170 auto M =
MBB.getParent()->getFunction().getParent();
3172 (Subtarget.isTargetLinux() || M->getStackProtectorGuard() ==
"tls") &&
3173 "Only Linux target or tls mode are expected to contain "
3174 "LOAD_STACK_GUARD");
3176 if (M->getStackProtectorGuard() ==
"tls")
3177 Offset = M->getStackProtectorGuardOffset();
3179 Offset = Subtarget.isPPC64() ? -0x7010 : -0x7008;
3180 const unsigned Reg = Subtarget.isPPC64() ? PPC::X13 : PPC::R2;
3181 MI.setDesc(
get(Subtarget.isPPC64() ? PPC::LD : PPC::LWZ));
3187 case PPC::PPCLdFixedAddr: {
3188 assert((Subtarget.getTargetTriple().isOSGlibc() ||
3189 Subtarget.getTargetTriple().isMusl()) &&
3190 "Only targets with Glibc expected to contain PPCLdFixedAddr");
3192 const unsigned Reg = Subtarget.isPPC64() ? PPC::X13 : PPC::R2;
3193 MI.setDesc(
get(PPC::LWZ));
3194 uint64_t FAType =
MI.getOperand(1).getImm();
3195#undef PPC_LNX_FEATURE
3197#define PPC_LNX_DEFINE_OFFSETS
3198#include "llvm/TargetParser/PPCTargetParser.def"
3199 bool IsLE = Subtarget.isLittleEndian();
3200 bool Is64 = Subtarget.isPPC64();
3201 if (FAType == PPC_FAWORD_HWCAP) {
3203 Offset = Is64 ? PPC_HWCAP_OFFSET_LE64 : PPC_HWCAP_OFFSET_LE32;
3205 Offset = Is64 ? PPC_HWCAP_OFFSET_BE64 : PPC_HWCAP_OFFSET_BE32;
3206 }
else if (FAType == PPC_FAWORD_HWCAP2) {
3208 Offset = Is64 ? PPC_HWCAP2_OFFSET_LE64 : PPC_HWCAP2_OFFSET_LE32;
3210 Offset = Is64 ? PPC_HWCAP2_OFFSET_BE64 : PPC_HWCAP2_OFFSET_BE32;
3211 }
else if (FAType == PPC_FAWORD_CPUID) {
3213 Offset = Is64 ? PPC_CPUID_OFFSET_LE64 : PPC_CPUID_OFFSET_LE32;
3215 Offset = Is64 ? PPC_CPUID_OFFSET_BE64 : PPC_CPUID_OFFSET_BE32;
3217 assert(
Offset &&
"Do not know the offset for this fixed addr load");
3218 MI.removeOperand(1);
3219 Subtarget.getTargetMachine().setGlibcHWCAPAccess();
3224#define PPC_TGT_PARSER_UNDEF_MACROS
3225#include "llvm/TargetParser/PPCTargetParser.def"
3226#undef PPC_TGT_PARSER_UNDEF_MACROS
3228 case PPC::DFLOADf32:
3229 case PPC::DFLOADf64:
3230 case PPC::DFSTOREf32:
3231 case PPC::DFSTOREf64: {
3232 assert(Subtarget.hasP9Vector() &&
3233 "Invalid D-Form Pseudo-ops on Pre-P9 target.");
3236 "D-form op must have register and immediate operands");
3239 case PPC::XFLOADf32:
3240 case PPC::XFSTOREf32:
3244 assert(Subtarget.hasP8Vector() &&
3245 "Invalid X-Form Pseudo-ops on Pre-P8 target.");
3246 assert(
MI.getOperand(2).isReg() &&
MI.getOperand(1).isReg() &&
3247 "X-form op must have register and register operands");
3250 case PPC::XFLOADf64:
3251 case PPC::XFSTOREf64: {
3252 assert(Subtarget.hasVSX() &&
3253 "Invalid X-Form Pseudo-ops on target that has no VSX.");
3254 assert(
MI.getOperand(2).isReg() &&
MI.getOperand(1).isReg() &&
3255 "X-form op must have register and register operands");
3258 case PPC::SPILLTOVSR_LD: {
3259 Register TargetReg =
MI.getOperand(0).getReg();
3260 if (PPC::VSFRCRegClass.
contains(TargetReg)) {
3261 MI.setDesc(
get(PPC::DFLOADf64));
3265 MI.setDesc(
get(PPC::LD));
3268 case PPC::SPILLTOVSR_ST: {
3270 if (PPC::VSFRCRegClass.
contains(SrcReg)) {
3271 NumStoreSPILLVSRRCAsVec++;
3272 MI.setDesc(
get(PPC::DFSTOREf64));
3275 NumStoreSPILLVSRRCAsGpr++;
3276 MI.setDesc(
get(PPC::STD));
3280 case PPC::SPILLTOVSR_LDX: {
3281 Register TargetReg =
MI.getOperand(0).getReg();
3282 if (PPC::VSFRCRegClass.
contains(TargetReg))
3283 MI.setDesc(
get(PPC::LXSDX));
3285 MI.setDesc(
get(PPC::LDX));
3288 case PPC::SPILLTOVSR_STX: {
3290 if (PPC::VSFRCRegClass.
contains(SrcReg)) {
3291 NumStoreSPILLVSRRCAsVec++;
3292 MI.setDesc(
get(PPC::STXSDX));
3294 NumStoreSPILLVSRRCAsGpr++;
3295 MI.setDesc(
get(PPC::STDX));
3302 case PPC::CFENCE8: {
3303 auto Val =
MI.getOperand(0).getReg();
3304 unsigned CmpOp = Subtarget.isPPC64() ? PPC::CMPD : PPC::CMPW;
3310 MI.setDesc(
get(PPC::ISYNC));
3311 MI.removeOperand(0);
3314 case PPC::LWAT_CSNE_PSEUDO:
3315 case PPC::LDAT_CSNE_PSEUDO:
3325static unsigned selectReg(int64_t Imm1, int64_t Imm2,
unsigned CompareOpc,
3326 unsigned TrueReg,
unsigned FalseReg,
3327 unsigned CRSubReg) {
3329 if (CompareOpc == PPC::CMPWI || CompareOpc == PPC::CMPDI) {
3333 return Imm1 < Imm2 ? TrueReg : FalseReg;
3335 return Imm1 > Imm2 ? TrueReg : FalseReg;
3337 return Imm1 == Imm2 ? TrueReg : FalseReg;
3341 else if (CompareOpc == PPC::CMPLWI || CompareOpc == PPC::CMPLDI) {
3349 return Imm1 == Imm2 ? TrueReg : FalseReg;
3352 return PPC::NoRegister;
3357 int64_t
Imm)
const {
3358 assert(
MI.getOperand(OpNo).isReg() &&
"Operand must be a REG");
3360 Register InUseReg =
MI.getOperand(OpNo).getReg();
3361 MI.getOperand(OpNo).ChangeToImmediate(
Imm);
3368 int UseOpIdx =
MI.findRegisterUseOperandIdx(InUseReg, &RI,
false);
3369 if (UseOpIdx >= 0) {
3379 MI.removeOperand(UseOpIdx);
3388 int OperandToKeep = LII.
SetCR ? 1 : 0;
3389 for (
int i =
MI.getNumOperands() - 1; i > OperandToKeep; i--)
3390 MI.removeOperand(i);
3394 MI.setDesc(
get(LII.
Is64Bit ? PPC::ANDI8_rec : PPC::ANDI_rec));
3409 bool &SeenIntermediateUse)
const {
3410 assert(!
MI.getParent()->getParent()->getRegInfo().isSSA() &&
3411 "Should be called after register allocation.");
3414 SeenIntermediateUse =
false;
3415 for (; It != E; ++It) {
3416 if (It->modifiesRegister(Reg, &RI))
3418 if (It->readsRegister(Reg, &RI))
3419 SeenIntermediateUse =
true;
3427 int64_t
Imm)
const {
3428 assert(!
MBB.getParent()->getRegInfo().isSSA() &&
3429 "Register should be in non-SSA form after RA");
3430 bool isPPC64 = Subtarget.isPPC64();
3444 assert(isPPC64 &&
"Materializing 64-bit immediate to single register is "
3445 "only supported in PPC64");
3447 if ((
Imm >> 32) & 0xFFFF)
3467 unsigned &OpNoForForwarding,
3468 bool &SeenIntermediateUse)
const {
3469 OpNoForForwarding = ~0U;
3476 for (
int i = 1, e =
MI.getNumOperands(); i < e; i++) {
3477 if (!
MI.getOperand(i).isReg())
3480 if (!Reg.isVirtual())
3485 if (!DefMIForTrueReg)
3487 if (DefMIForTrueReg->
getOpcode() == PPC::LI ||
3488 DefMIForTrueReg->
getOpcode() == PPC::LI8 ||
3489 DefMIForTrueReg->
getOpcode() == PPC::ADDI ||
3490 DefMIForTrueReg->
getOpcode() == PPC::ADDI8) {
3491 OpNoForForwarding = i;
3492 DefMI = DefMIForTrueReg;
3497 if (
DefMI->getOpcode() == PPC::LI ||
DefMI->getOpcode() == PPC::LI8)
3507 unsigned Opc =
MI.getOpcode();
3508 bool ConvertibleImmForm =
3509 Opc == PPC::CMPWI ||
Opc == PPC::CMPLWI ||
Opc == PPC::CMPDI ||
3510 Opc == PPC::CMPLDI ||
Opc == PPC::ADDI ||
Opc == PPC::ADDI8 ||
3511 Opc == PPC::ORI ||
Opc == PPC::ORI8 ||
Opc == PPC::XORI ||
3512 Opc == PPC::XORI8 ||
Opc == PPC::RLDICL ||
Opc == PPC::RLDICL_rec ||
3513 Opc == PPC::RLDICL_32 ||
Opc == PPC::RLDICL_32_64 ||
3514 Opc == PPC::RLWINM ||
Opc == PPC::RLWINM_rec ||
Opc == PPC::RLWINM8 ||
3515 Opc == PPC::RLWINM8_rec;
3516 bool IsVFReg = (
MI.getNumOperands() &&
MI.getOperand(0).isReg())
3523 if ((
Opc == PPC::OR ||
Opc == PPC::OR8) &&
3524 MI.getOperand(1).getReg() ==
MI.getOperand(2).getReg())
3526 for (
int i = 1, e =
MI.getNumOperands(); i < e; i++) {
3527 MachineOperand &MO =
MI.getOperand(i);
3528 SeenIntermediateUse =
false;
3542 case PPC::ADDItocL8:
3545 OpNoForForwarding = i;
3552 return OpNoForForwarding == ~0
U ? nullptr :
DefMI;
3555unsigned PPCInstrInfo::getSpillTarget()
const {
3558 bool IsP10Variant = Subtarget.isISA3_1() || Subtarget.pairedVectorMemops();
3560 return Subtarget.isISAFuture() ? 3 : IsP10Variant ?
3561 2 : Subtarget.hasP9Vector() ?
3600 bool PostRA = !
MRI->isSSA();
3606 unsigned ToBeDeletedReg = 0;
3607 int64_t OffsetImm = 0;
3608 unsigned XFormOpcode = 0;
3616 bool OtherIntermediateUse =
false;
3620 if (OtherIntermediateUse || !ADDMI)
3627 unsigned ScaleRegIdx = 0;
3628 int64_t OffsetAddi = 0;
3642 assert(ADDIMI &&
"There should be ADDIMI for valid ToBeChangedReg.");
3647 for (
auto It = ++Start; It !=
End; It++)
3656 (ScaleReg == PPC::R0 || ScaleReg == PPC::X0))
3661 if (NewDefFor(ToBeChangedReg, *ADDMI,
MI) || NewDefFor(ScaleReg, *ADDMI,
MI))
3677 MI.setDesc(
get(XFormOpcode));
3679 .ChangeToRegister(ScaleReg,
false,
false,
3683 .ChangeToRegister(ToBeChangedReg,
false,
false,
true);
3695 int64_t &
Imm)
const {
3699 if (
Opc != PPC::ADDI &&
Opc != PPC::ADDI8)
3715 return Opc == PPC::ADD4 ||
Opc == PPC::ADD8;
3719 unsigned &ToBeDeletedReg,
3720 unsigned &XFormOpcode,
3724 if (!
MI.mayLoadOrStore())
3727 unsigned Opc =
MI.getOpcode();
3729 XFormOpcode = RI.getMappedIdxOpcForImmOpc(
Opc);
3732 if (XFormOpcode == PPC::INSTRUCTION_LIST_END)
3746 if (!ImmOperand.
isImm())
3749 assert(RegOperand.
isReg() &&
"Instruction format is not right");
3752 if (!RegOperand.
isKill())
3755 ToBeDeletedReg = RegOperand.
getReg();
3756 OffsetImm = ImmOperand.
getImm();
3763 int64_t &OffsetAddi,
3764 int64_t OffsetImm)
const {
3765 assert((Index == 1 || Index == 2) &&
"Invalid operand index for add.");
3771 bool OtherIntermediateUse =
false;
3792 if (OtherIntermediateUse || !ADDIMI)
3811 bool PostRA = !
MRI->isSSA();
3812 bool SeenIntermediateUse =
true;
3813 unsigned ForwardingOperand = ~0U;
3815 SeenIntermediateUse);
3818 assert(ForwardingOperand <
MI.getNumOperands() &&
3819 "The forwarding operand needs to be valid at this point");
3820 bool IsForwardingOperandKilled =
MI.getOperand(ForwardingOperand).isKill();
3821 bool KillFwdDefMI = !SeenIntermediateUse && IsForwardingOperandKilled;
3822 if (KilledDef && KillFwdDefMI)
3836 if (RI.getMappedIdxOpcForImmOpc(
MI.getOpcode()) !=
3837 PPC::INSTRUCTION_LIST_END &&
3838 transformToNewImmFormFedByAdd(
MI, *
DefMI, ForwardingOperand))
3842 bool IsVFReg =
MI.getOperand(0).isReg() &&
3843 MI.getOperand(0).getReg().isPhysical() &&
3850 transformToImmFormFedByAdd(
MI, III, ForwardingOperand, *
DefMI,
3857 transformToImmFormFedByLI(
MI, III, ForwardingOperand, *
DefMI))
3863 simplifyToLI(
MI, *
DefMI, ForwardingOperand, KilledDef, &RegsToUpdate))
3872 Register FoldingReg =
MI.getOperand(1).getReg();
3878 if (SrcMI->
getOpcode() != PPC::RLWINM &&
3879 SrcMI->
getOpcode() != PPC::RLWINM_rec &&
3883 assert((
MI.getOperand(2).isImm() &&
MI.getOperand(3).isImm() &&
3886 "Invalid PPC::RLWINM Instruction!");
3888 uint64_t SHMI =
MI.getOperand(2).getImm();
3890 uint64_t MBMI =
MI.getOperand(3).getImm();
3892 uint64_t MEMI =
MI.getOperand(4).getImm();
3894 assert((MEMI < 32 && MESrc < 32 && MBMI < 32 && MBSrc < 32) &&
3895 "Invalid PPC::RLWINM Instruction!");
3917 bool SrcMaskFull = (MBSrc - MESrc == 1) || (MBSrc == 0 && MESrc == 31);
3920 if ((MBMI > MEMI) && !SrcMaskFull)
3930 APInt RotatedSrcMask = MaskSrc.
rotl(SHMI);
3931 APInt FinalMask = RotatedSrcMask & MaskMI;
3933 bool Simplified =
false;
3936 if (FinalMask.
isZero()) {
3938 (
MI.getOpcode() == PPC::RLWINM8 ||
MI.getOpcode() == PPC::RLWINM8_rec);
3943 if (
MI.getOpcode() == PPC::RLWINM ||
MI.getOpcode() == PPC::RLWINM8) {
3945 MI.removeOperand(4);
3946 MI.removeOperand(3);
3947 MI.removeOperand(2);
3948 MI.getOperand(1).ChangeToImmediate(0);
3949 MI.setDesc(
get(Is64Bit ? PPC::LI8 : PPC::LI));
3952 MI.removeOperand(4);
3953 MI.removeOperand(3);
3954 MI.getOperand(2).setImm(0);
3955 MI.setDesc(
get(Is64Bit ? PPC::ANDI8_rec : PPC::ANDI_rec));
3958 MI.getOperand(1).setIsKill(
true);
3962 MI.getOperand(1).setIsKill(
false);
3978 uint16_t NewSH = (SHSrc + SHMI) % 32;
3979 MI.getOperand(2).setImm(NewSH);
3982 MI.getOperand(3).setImm(NewMB);
3983 MI.getOperand(4).setImm(NewME);
3987 MI.getOperand(1).setIsKill(
true);
3991 MI.getOperand(1).setIsKill(
false);
3996 if (Simplified &
MRI->use_nodbg_empty(FoldingReg) &&
4021 default:
return false;
4029 III.
ImmOpcode =
Opc == PPC::ADD4 ? PPC::ADDI : PPC::ADDI8;
4038 III.
ImmOpcode =
Opc == PPC::ADDC ? PPC::ADDIC : PPC::ADDIC8;
4054 III.
ImmOpcode =
Opc == PPC::SUBFC ? PPC::SUBFIC : PPC::SUBFIC8;
4062 III.
ImmOpcode =
Opc == PPC::CMPW ? PPC::CMPWI : PPC::CMPDI;
4070 III.
ImmOpcode =
Opc == PPC::CMPLW ? PPC::CMPLWI : PPC::CMPLDI;
4090 case PPC::OR: III.
ImmOpcode = PPC::ORI;
break;
4091 case PPC::OR8: III.
ImmOpcode = PPC::ORI8;
break;
4092 case PPC::XOR: III.
ImmOpcode = PPC::XORI;
break;
4093 case PPC::XOR8: III.
ImmOpcode = PPC::XORI8;
break;
4098 case PPC::RLWNM_rec:
4099 case PPC::RLWNM8_rec:
4119 if (
Opc == PPC::RLWNM ||
Opc == PPC::RLWNM8 ||
Opc == PPC::RLWNM_rec ||
4120 Opc == PPC::RLWNM8_rec)
4126 case PPC::RLWNM: III.
ImmOpcode = PPC::RLWINM;
break;
4127 case PPC::RLWNM8: III.
ImmOpcode = PPC::RLWINM8;
break;
4128 case PPC::RLWNM_rec:
4131 case PPC::RLWNM8_rec:
4134 case PPC::SLW: III.
ImmOpcode = PPC::RLWINM;
break;
4135 case PPC::SLW8: III.
ImmOpcode = PPC::RLWINM8;
break;
4142 case PPC::SRW: III.
ImmOpcode = PPC::RLWINM;
break;
4143 case PPC::SRW8: III.
ImmOpcode = PPC::RLWINM8;
break;
4163 case PPC::RLDCL_rec:
4165 case PPC::RLDCR_rec:
4181 if (
Opc == PPC::RLDCL ||
Opc == PPC::RLDCL_rec ||
Opc == PPC::RLDCR ||
4182 Opc == PPC::RLDCR_rec)
4188 case PPC::RLDCL: III.
ImmOpcode = PPC::RLDICL;
break;
4189 case PPC::RLDCL_rec:
4192 case PPC::RLDCR: III.
ImmOpcode = PPC::RLDICR;
break;
4193 case PPC::RLDCR_rec:
4196 case PPC::SLD: III.
ImmOpcode = PPC::RLDICR;
break;
4200 case PPC::SRD: III.
ImmOpcode = PPC::RLDICL;
break;
4247 case PPC::LBZX: III.
ImmOpcode = PPC::LBZ;
break;
4248 case PPC::LBZX8: III.
ImmOpcode = PPC::LBZ8;
break;
4249 case PPC::LHZX: III.
ImmOpcode = PPC::LHZ;
break;
4250 case PPC::LHZX8: III.
ImmOpcode = PPC::LHZ8;
break;
4251 case PPC::LHAX: III.
ImmOpcode = PPC::LHA;
break;
4252 case PPC::LHAX8: III.
ImmOpcode = PPC::LHA8;
break;
4253 case PPC::LWZX: III.
ImmOpcode = PPC::LWZ;
break;
4254 case PPC::LWZX8: III.
ImmOpcode = PPC::LWZ8;
break;
4260 case PPC::LFSX: III.
ImmOpcode = PPC::LFS;
break;
4261 case PPC::LFDX: III.
ImmOpcode = PPC::LFD;
break;
4262 case PPC::STBX: III.
ImmOpcode = PPC::STB;
break;
4263 case PPC::STBX8: III.
ImmOpcode = PPC::STB8;
break;
4264 case PPC::STHX: III.
ImmOpcode = PPC::STH;
break;
4265 case PPC::STHX8: III.
ImmOpcode = PPC::STH8;
break;
4266 case PPC::STWX: III.
ImmOpcode = PPC::STW;
break;
4267 case PPC::STWX8: III.
ImmOpcode = PPC::STW8;
break;
4272 case PPC::STFSX: III.
ImmOpcode = PPC::STFS;
break;
4273 case PPC::STFDX: III.
ImmOpcode = PPC::STFD;
break;
4305 case PPC::LBZUX: III.
ImmOpcode = PPC::LBZU;
break;
4306 case PPC::LBZUX8: III.
ImmOpcode = PPC::LBZU8;
break;
4307 case PPC::LHZUX: III.
ImmOpcode = PPC::LHZU;
break;
4308 case PPC::LHZUX8: III.
ImmOpcode = PPC::LHZU8;
break;
4309 case PPC::LHAUX: III.
ImmOpcode = PPC::LHAU;
break;
4310 case PPC::LHAUX8: III.
ImmOpcode = PPC::LHAU8;
break;
4311 case PPC::LWZUX: III.
ImmOpcode = PPC::LWZU;
break;
4312 case PPC::LWZUX8: III.
ImmOpcode = PPC::LWZU8;
break;
4317 case PPC::LFSUX: III.
ImmOpcode = PPC::LFSU;
break;
4318 case PPC::LFDUX: III.
ImmOpcode = PPC::LFDU;
break;
4319 case PPC::STBUX: III.
ImmOpcode = PPC::STBU;
break;
4320 case PPC::STBUX8: III.
ImmOpcode = PPC::STBU8;
break;
4321 case PPC::STHUX: III.
ImmOpcode = PPC::STHU;
break;
4322 case PPC::STHUX8: III.
ImmOpcode = PPC::STHU8;
break;
4323 case PPC::STWUX: III.
ImmOpcode = PPC::STWU;
break;
4324 case PPC::STWUX8: III.
ImmOpcode = PPC::STWU8;
break;
4329 case PPC::STFSUX: III.
ImmOpcode = PPC::STFSU;
break;
4330 case PPC::STFDUX: III.
ImmOpcode = PPC::STFDU;
break;
4343 case PPC::XFLOADf32:
4344 case PPC::XFLOADf64:
4345 case PPC::XFSTOREf32:
4346 case PPC::XFSTOREf64:
4347 if (!Subtarget.hasP9Vector())
4374 case PPC::XFLOADf32:
4388 case PPC::XFLOADf64:
4406 case PPC::XFSTOREf32:
4420 case PPC::XFSTOREf64:
4431 assert(Op1 != Op2 &&
"Cannot swap operand with itself.");
4433 unsigned MaxOp = std::max(Op1, Op2);
4434 unsigned MinOp = std::min(Op1, Op2);
4437 MI.removeOperand(std::max(Op1, Op2));
4438 MI.removeOperand(std::min(Op1, Op2));
4442 if (MaxOp - MinOp == 1 &&
MI.getNumOperands() == MinOp) {
4443 MI.addOperand(MOp2);
4444 MI.addOperand(MOp1);
4449 unsigned TotalOps =
MI.getNumOperands() + 2;
4450 for (
unsigned i =
MI.getNumOperands() - 1; i >= MinOp; i--) {
4452 MI.removeOperand(i);
4455 MI.addOperand(MOp2);
4457 for (
unsigned i =
MI.getNumOperands(); i < TotalOps; i++) {
4459 MI.addOperand(MOp1);
4461 MI.addOperand(MOps.
back());
4472 unsigned OpNoForForwarding
4476 MachineRegisterInfo &
MRI =
MI.getParent()->getParent()->getRegInfo();
4513 if (
Opc != PPC::ADDItocL8 &&
Opc != PPC::ADDI &&
Opc != PPC::ADDI8)
4519 if (
Opc == PPC::ADDItocL8 && Subtarget.isAIX())
4523 "Add inst must have at least three operands");
4524 RegMO = &
DefMI.getOperand(1);
4525 ImmMO = &
DefMI.getOperand(2);
4528 if (!RegMO->
isReg())
4537bool PPCInstrInfo::isRegElgibleForForwarding(
4540 bool &IsFwdFeederRegKilled,
bool &SeenIntermediateUse)
const {
4547 const MachineRegisterInfo &
MRI =
MI.getParent()->getParent()->getRegInfo();
4557 for (; It !=
E; ++It) {
4561 IsFwdFeederRegKilled =
true;
4563 SeenIntermediateUse =
true;
4565 if ((&*It) == &
DefMI)
4578bool PPCInstrInfo::isImmElgibleForForwarding(
const MachineOperand &ImmMO,
4582 int64_t BaseImm)
const {
4584 if (
DefMI.getOpcode() == PPC::ADDItocL8) {
4605 if (ImmMO.
isImm()) {
4610 APInt ActualValue(64, ImmMO.
getImm() + BaseImm,
true);
4631 unsigned OpNoForForwarding,
4634 if ((
DefMI.getOpcode() != PPC::LI &&
DefMI.getOpcode() != PPC::LI8) ||
4635 !
DefMI.getOperand(1).isImm())
4642 int64_t Immediate =
DefMI.getOperand(1).getImm();
4646 bool ReplaceWithLI =
false;
4647 bool Is64BitLI =
false;
4650 unsigned Opc =
MI.getOpcode();
4673 int64_t Comparand =
MI.getOperand(2).getImm();
4674 int64_t SExtComparand = ((
uint64_t)Comparand & ~0x7FFFuLL) != 0
4675 ? (Comparand | 0xFFFFFFFFFFFF0000)
4679 unsigned UseOpc = CompareUseMI.getOpcode();
4680 if (UseOpc != PPC::ISEL && UseOpc != PPC::ISEL8)
4682 unsigned CRSubReg = CompareUseMI.getOperand(3).getSubReg();
4683 Register TrueReg = CompareUseMI.getOperand(1).getReg();
4684 Register FalseReg = CompareUseMI.getOperand(2).getReg();
4685 unsigned RegToCopy =
4686 selectReg(SExtImm, SExtComparand,
Opc, TrueReg, FalseReg, CRSubReg);
4687 if (RegToCopy == PPC::NoRegister)
4690 if (RegToCopy == PPC::ZERO || RegToCopy == PPC::ZERO8) {
4691 CompareUseMI.setDesc(
get(UseOpc == PPC::ISEL8 ? PPC::LI8 : PPC::LI));
4693 CompareUseMI.removeOperand(3);
4694 CompareUseMI.removeOperand(2);
4698 dbgs() <<
"Found LI -> CMPI -> ISEL, replacing with a copy.\n");
4702 for (
const MachineOperand &MO : CompareUseMI.operands())
4707 CompareUseMI.setDesc(
get(PPC::COPY));
4708 CompareUseMI.removeOperand(3);
4709 CompareUseMI.removeOperand(RegToCopy == TrueReg ? 2 : 1);
4710 CmpIselsConverted++;
4719 MissedConvertibleImmediateInstrs++;
4727 int64_t Addend =
MI.getOperand(2).getImm();
4729 ReplaceWithLI =
true;
4730 Is64BitLI =
Opc == PPC::ADDI8;
4731 NewImm = Addend + SExtImm;
4737 case PPC::SUBFIC8: {
4739 if (
MI.getNumOperands() > 3 && !
MI.getOperand(3).isDead())
4741 int64_t Minuend =
MI.getOperand(2).getImm();
4743 ReplaceWithLI =
true;
4744 Is64BitLI =
Opc == PPC::SUBFIC8;
4745 NewImm = Minuend - SExtImm;
4751 case PPC::RLDICL_rec:
4752 case PPC::RLDICL_32:
4753 case PPC::RLDICL_32_64: {
4755 int64_t SH =
MI.getOperand(2).getImm();
4756 int64_t MB =
MI.getOperand(3).getImm();
4757 APInt InVal((
Opc == PPC::RLDICL ||
Opc == PPC::RLDICL_rec) ? 64 : 32,
4759 InVal = InVal.rotl(SH);
4766 (
Opc == PPC::RLDICL_rec &&
isUInt<16>(InVal.getSExtValue()))) {
4767 ReplaceWithLI =
true;
4768 Is64BitLI =
Opc != PPC::RLDICL_32;
4769 NewImm = InVal.getSExtValue();
4770 SetCR =
Opc == PPC::RLDICL_rec;
4777 case PPC::RLWINM_rec:
4778 case PPC::RLWINM8_rec: {
4779 int64_t SH =
MI.getOperand(2).getImm();
4780 int64_t MB =
MI.getOperand(3).getImm();
4781 int64_t ME =
MI.getOperand(4).getImm();
4782 APInt InVal(32, SExtImm,
true);
4783 InVal = InVal.rotl(SH);
4789 bool ValueFits =
isUInt<15>(InVal.getSExtValue());
4790 ValueFits |= ((
Opc == PPC::RLWINM_rec ||
Opc == PPC::RLWINM8_rec) &&
4793 ReplaceWithLI =
true;
4794 Is64BitLI =
Opc == PPC::RLWINM8 ||
Opc == PPC::RLWINM8_rec;
4795 NewImm = InVal.getSExtValue();
4796 SetCR =
Opc == PPC::RLWINM_rec ||
Opc == PPC::RLWINM8_rec;
4805 int64_t LogicalImm =
MI.getOperand(2).getImm();
4807 if (
Opc == PPC::ORI ||
Opc == PPC::ORI8)
4808 Result = LogicalImm | SExtImm;
4810 Result = LogicalImm ^ SExtImm;
4812 ReplaceWithLI =
true;
4813 Is64BitLI =
Opc == PPC::ORI8 ||
Opc == PPC::XORI8;
4821 if (ReplaceWithLI) {
4826 bool ImmChanged = (SExtImm & NewImm) != NewImm;
4827 if (PostRA && ImmChanged)
4834 DefMI.getOperand(1).setImm(NewImm);
4840 assert(Immediate &&
"Transformation converted zero to non-zero?");
4843 }
else if (ImmChanged)
4852 LoadImmediateInfo LII;
4858 if (KilledDef && SetCR)
4859 *KilledDef =
nullptr;
4872bool PPCInstrInfo::transformToNewImmFormFedByAdd(
4874 MachineRegisterInfo *
MRI = &
MI.getParent()->getParent()->getRegInfo();
4882 if (!
MI.mayLoadOrStore())
4885 unsigned XFormOpcode = RI.getMappedIdxOpcForImmOpc(
MI.getOpcode());
4887 assert((XFormOpcode != PPC::INSTRUCTION_LIST_END) &&
4888 "MI must have x-form opcode");
4892 bool IsVFReg =
MI.getOperand(0).isReg() &&
4893 MI.getOperand(0).getReg().isPhysical() &&
4905 MachineOperand ImmOperandMI =
MI.getOperand(III.
ImmOpNo);
4906 if (!ImmOperandMI.
isImm())
4910 MachineOperand *ImmMO =
nullptr;
4911 MachineOperand *RegMO =
nullptr;
4912 if (!isDefMIElgibleForForwarding(
DefMI, III, ImmMO, RegMO))
4914 assert(ImmMO && RegMO &&
"Imm and Reg operand must have been set");
4919 int64_t ImmBase = ImmOperandMI.
getImm();
4921 if (!isImmElgibleForForwarding(*ImmMO,
DefMI, III,
Imm, ImmBase))
4925 LLVM_DEBUG(
dbgs() <<
"Replacing existing reg+imm instruction:\n");
4942bool PPCInstrInfo::transformToImmFormFedByAdd(
4952 if (!isUseMIElgibleForForwarding(
MI, III, OpNoForForwarding))
4957 MachineOperand *ImmMO =
nullptr;
4958 MachineOperand *RegMO =
nullptr;
4959 if (!isDefMIElgibleForForwarding(
DefMI, III, ImmMO, RegMO))
4961 assert(ImmMO && RegMO &&
"Imm and Reg operand must have been set");
4966 if (!isImmElgibleForForwarding(*ImmMO,
DefMI, III,
Imm))
4969 bool IsFwdFeederRegKilled =
false;
4970 bool SeenIntermediateUse =
false;
4972 if (!isRegElgibleForForwarding(*RegMO,
DefMI,
MI, KillDefMI,
4973 IsFwdFeederRegKilled, SeenIntermediateUse))
4976 MachineRegisterInfo &
MRI =
MI.getParent()->getParent()->getRegInfo();
4993 if (ImmMO->
isImm()) {
5004 if (
DefMI.getOpcode() == PPC::ADDItocL8)
5014 MI.removeOperand(i);
5020 MI.addOperand(*ImmMO);
5022 for (
auto &MO : MOps)
5039 unsigned ConstantOpNo,
5042 if ((
DefMI.getOpcode() != PPC::LI &&
DefMI.getOpcode() != PPC::LI8) ||
5043 !
DefMI.getOperand(1).isImm())
5049 MachineRegisterInfo &
MRI =
MI.getParent()->getParent()->getRegInfo();
5059 APInt ActualValue(64,
Imm,
true);
5060 if (!ActualValue.isSignedIntN(III.
ImmWidth))
5074 Register OrigZeroReg =
MI.getOperand(PosForOrigZero).getReg();
5078 if ((NewZeroReg == PPC::R0 || NewZeroReg == PPC::X0) &&
5081 if ((OrigZeroReg == PPC::R0 || OrigZeroReg == PPC::X0) &&
5082 ConstantOpNo != PosForOrigZero)
5086 unsigned Opc =
MI.getOpcode();
5087 bool SpecialShift32 =
Opc == PPC::SLW ||
Opc == PPC::SLW_rec ||
5088 Opc == PPC::SRW ||
Opc == PPC::SRW_rec ||
5089 Opc == PPC::SLW8 ||
Opc == PPC::SLW8_rec ||
5090 Opc == PPC::SRW8 ||
Opc == PPC::SRW8_rec;
5091 bool SpecialShift64 =
Opc == PPC::SLD ||
Opc == PPC::SLD_rec ||
5092 Opc == PPC::SRD ||
Opc == PPC::SRD_rec;
5093 bool SetCR =
Opc == PPC::SLW_rec ||
Opc == PPC::SRW_rec ||
5094 Opc == PPC::SLD_rec ||
Opc == PPC::SRD_rec;
5096 Opc == PPC::SRD_rec;
5110 if (SpecialShift32 || SpecialShift64) {
5111 LoadImmediateInfo LII;
5115 uint64_t ShAmt =
Imm & (SpecialShift32 ? 0x1F : 0x3F);
5116 if (
Imm & (SpecialShift32 ? 0x20 : 0x40))
5121 else if (!SetCR && ShAmt == 0 && !PostRA) {
5122 MI.removeOperand(2);
5123 MI.setDesc(
get(PPC::COPY));
5126 if (SpecialShift32) {
5134 MachineInstrBuilder(*
MI.getParent()->getParent(),
MI).addImm(MB)
5143 MachineInstrBuilder(*
MI.getParent()->getParent(),
MI).addImm(ME);
5173 &PPC::GPRC_and_GPRC_NOR0RegClass : &PPC::G8RC_and_G8RC_NOX0RegClass;
5190 if (Subtarget.hasVSX() && RC == &PPC::VRRCRegClass)
5191 return &PPC::VSRCRegClass;
5196 return PPC::getRecordFormOpcode(Opcode);
5200 return (Opcode == PPC::LBZU || Opcode == PPC::LBZUX || Opcode == PPC::LBZU8 ||
5201 Opcode == PPC::LBZUX8 || Opcode == PPC::LHZU ||
5202 Opcode == PPC::LHZUX || Opcode == PPC::LHZU8 ||
5203 Opcode == PPC::LHZUX8);
5217 int Opcode =
MI->getOpcode();
5218 if (
TII.isSExt32To64(Opcode))
5227 if (Opcode == PPC::RLDICL &&
MI->getOperand(3).getImm() >= 33)
5233 if ((Opcode == PPC::RLWINM || Opcode == PPC::RLWINM_rec ||
5234 Opcode == PPC::RLWNM || Opcode == PPC::RLWNM_rec) &&
5235 MI->getOperand(3).getImm() > 0 &&
5236 MI->getOperand(3).getImm() <=
MI->getOperand(4).getImm())
5241 if (Opcode == PPC::ANDIS_rec || Opcode == PPC::ANDIS8_rec) {
5243 if ((
Imm & 0x8000) == 0)
5263 int Opcode =
MI->getOpcode();
5264 if (
TII.isZExt32To64(Opcode))
5269 Opcode == PPC::LWZUX || Opcode == PPC::LWZU8 || Opcode == PPC::LWZUX8) &&
5270 MI->getOperand(0).getReg() ==
Reg)
5275 if (Opcode == PPC::LI || Opcode == PPC::LI8 ||
5276 Opcode == PPC::LIS || Opcode == PPC::LIS8) {
5277 int64_t
Imm =
MI->getOperand(1).getImm();
5284 if ((Opcode == PPC::RLDICL || Opcode == PPC::RLDICL_rec ||
5285 Opcode == PPC::RLDCL || Opcode == PPC::RLDCL_rec ||
5286 Opcode == PPC::RLDICL_32_64) &&
5287 MI->getOperand(3).getImm() >= 32)
5290 if ((Opcode == PPC::RLDIC || Opcode == PPC::RLDIC_rec) &&
5291 MI->getOperand(3).getImm() >= 32 &&
5292 MI->getOperand(3).getImm() <= 63 -
MI->getOperand(2).getImm())
5295 if ((Opcode == PPC::RLWINM || Opcode == PPC::RLWINM_rec ||
5296 Opcode == PPC::RLWNM || Opcode == PPC::RLWNM_rec ||
5297 Opcode == PPC::RLWINM8 || Opcode == PPC::RLWNM8) &&
5298 MI->getOperand(3).getImm() <=
MI->getOperand(4).getImm())
5307 if (!
MI.getOperand(1).isImm() || !
MI.getOperand(2).isReg())
5309 unsigned TOCSaveOffset = Subtarget.getFrameLowering()->getTOCSaveOffset();
5311 Register StackReg =
MI.getOperand(2).getReg();
5334 unsigned BinOpDepth)
const {
5335 if (!Reg.isVirtual())
5342 unsigned Opcode =
MI->getOpcode();
5351 unsigned OperandEnd = 3, OperandStride = 1;
5352 if (Opcode == PPC::PHI) {
5353 OperandEnd =
MI->getNumOperands();
5357 for (
unsigned I = 1;
I < OperandEnd;
I += OperandStride) {
5358 assert(
MI->getOperand(
I).isReg() &&
"Operand must be register");
5369 Register SrcReg =
MI->getOperand(1).getReg();
5383 if (SrcReg != PPC::X3)
5412 if (RC == &PPC::G8RCRegClass || RC == &PPC::G8RC_and_G8RC_NOX0RegClass)
5419 {PPC::OR, PPC::OR8}, {PPC::ISEL, PPC::ISEL8},
5420 {PPC::ORI, PPC::ORI8}, {PPC::XORI, PPC::XORI8},
5421 {PPC::ORIS, PPC::ORIS8}, {PPC::XORIS, PPC::XORIS8},
5422 {PPC::AND, PPC::AND8}};
5425 auto It = OpcodeMap.
find(Opcode);
5426 if (It != OpcodeMap.
end()) {
5428 NewOpcode = It->second;
5436 NewOpcode = PPC::get64BitInstrFromSignedExt32BitInstr(Opcode);
5439 assert(NewOpcode != -1 &&
5440 "Must have a 64-bit opcode to map the 32-bit opcode!");
5444 RI.getRegClass(
MCID.operands()[0].RegClass);
5446 Register SrcReg =
MI->getOperand(0).getReg();
5456 auto MBB =
MI->getParent();
5463 for (
unsigned i = 1; i <
MI->getNumOperands(); i++) {
5465 if (!Operand.
isReg())
5473 RI.getRegClass(
MCID.operands()[i].RegClass);
5479 if (Operand.
getSubReg() == PPC::sub_32) {
5481 "sub_32 source register class is incompatible with the promoted "
5482 "operand register class");
5487 if (NewUsedRegRC != OrgRC && (OrgRC == &PPC::GPRCRegClass ||
5488 OrgRC == &PPC::GPRC_and_GPRC_NOR0RegClass)) {
5490 Register TmpReg =
MRI->createVirtualRegister(NewUsedRegRC);
5491 Register DstTmpReg =
MRI->createVirtualRegister(NewUsedRegRC);
5497 Operand.
setReg(DstTmpReg);
5501 Register NewDefinedReg =
MRI->createVirtualRegister(NewRC);
5503 MI->getOperand(0).setReg(NewDefinedReg);
5510 .
addReg(NewDefinedReg, {}, PPC::sub_32);
5518std::pair<bool, bool>
5520 const unsigned BinOpDepth,
5523 return std::pair<bool, bool>(
false,
false);
5527 return std::pair<bool, bool>(
false,
false);
5534 if (IsSExt && IsZExt)
5535 return std::pair<bool, bool>(IsSExt, IsZExt);
5537 switch (
MI->getOpcode()) {
5539 Register SrcReg =
MI->getOperand(1).getReg();
5548 return std::pair<bool, bool>(SrcExt.first || IsSExt,
5549 SrcExt.second || IsZExt);
5555 if (
MI->getParent()->getBasicBlock() ==
5561 return std::pair<bool, bool>(IsSExt, IsZExt);
5565 if (SrcReg != PPC::X3) {
5568 return std::pair<bool, bool>(SrcExt.first || IsSExt,
5569 SrcExt.second || IsZExt);
5579 std::pair<bool, bool> IsExtendPair = std::pair<bool, bool>(IsSExt, IsZExt);
5582 if (
II ==
MBB->instr_begin() || (--
II)->getOpcode() != PPC::ADJCALLSTACKUP)
5583 return IsExtendPair;
5587 return IsExtendPair;
5592 return IsExtendPair;
5594 if (IntTy && IntTy->getBitWidth() <= 32) {
5596 IsSExt |= Attrs.hasAttribute(Attribute::SExt);
5597 IsZExt |= Attrs.hasAttribute(Attribute::ZExt);
5598 return std::pair<bool, bool>(IsSExt, IsZExt);
5601 return IsExtendPair;
5610 Register SrcReg =
MI->getOperand(1).getReg();
5612 return std::pair<bool, bool>(SrcExt.first || IsSExt,
5613 SrcExt.second || IsZExt);
5624 Register SrcReg =
MI->getOperand(1).getReg();
5626 uint16_t
Imm =
MI->getOperand(2).getImm();
5628 return std::pair<bool, bool>(
false, SrcExt.second || IsZExt);
5630 return std::pair<bool, bool>(SrcExt.first || IsSExt,
5631 SrcExt.second || IsZExt);
5641 return std::pair<bool, bool>(
false,
false);
5645 unsigned OperandEnd = 3, OperandStride = 1;
5646 if (
MI->getOpcode() == PPC::PHI) {
5647 OperandEnd =
MI->getNumOperands();
5653 for (
unsigned I = 1;
I != OperandEnd;
I += OperandStride) {
5654 if (!
MI->getOperand(
I).isReg())
5655 return std::pair<bool, bool>(
false,
false);
5659 IsSExt &= SrcExt.first;
5660 IsZExt &= SrcExt.second;
5662 return std::pair<bool, bool>(IsSExt, IsZExt);
5671 return std::pair<bool, bool>(
false,
false);
5673 Register SrcReg1 =
MI->getOperand(1).getReg();
5674 Register SrcReg2 =
MI->getOperand(2).getReg();
5677 return std::pair<bool, bool>(Src1Ext.first && Src2Ext.first,
5678 Src1Ext.second || Src2Ext.second);
5684 return std::pair<bool, bool>(IsSExt, IsZExt);
5688 return (Opcode == (Subtarget.isPPC64() ? PPC::BDNZ8 : PPC::BDNZ));
5701 :
Loop(
Loop), EndLoop(EndLoop), LoopCount(LoopCount),
5703 TII(MF->getSubtarget().getInstrInfo()) {
5712 bool shouldIgnoreForPipelining(
const MachineInstr *
MI)
const override {
5714 return MI == EndLoop;
5717 std::optional<bool> createTripCountGreaterCondition(
5718 int TC, MachineBasicBlock &
MBB,
5719 SmallVectorImpl<MachineOperand> &
Cond)
override {
5720 if (TripCount == -1) {
5725 MF->
getSubtarget<PPCSubtarget>().isPPC64() ? PPC::CTR8 : PPC::CTR,
5730 return TripCount > TC;
5733 void setPreheader(MachineBasicBlock *NewPreheader)
override {
5738 void adjustTripCount(
int TripCountAdjust)
override {
5741 if (LoopCount->
getOpcode() == PPC::LI8 ||
5752 void disposed(LiveIntervals *LIS)
override {
5757 Loop->eraseFromParent();
5764std::unique_ptr<TargetInstrInfo::PipelinerLoopInfo>
5769 if (Preheader == LoopBB)
5770 Preheader = *std::next(LoopBB->
pred_begin());
5773 if (
I != LoopBB->
end() &&
isBDNZ(
I->getOpcode())) {
5776 Register LoopCountReg = LoopInst->getOperand(0).getReg();
5779 return std::make_unique<PPCPipelinerLoopInfo>(LoopInst, &*
I, LoopCount);
5789 unsigned LOOPi = (Subtarget.isPPC64() ? PPC::MTCTR8loop : PPC::MTCTRloop);
5792 for (
auto &
I : PreHeader.
instrs())
5793 if (
I.getOpcode() == LOOPi)
5836 int64_t OffsetA = 0, OffsetB = 0;
5842 int LowOffset = std::min(OffsetA, OffsetB);
5843 int HighOffset = std::max(OffsetA, OffsetB);
5844 LocationSize LowWidth = (LowOffset == OffsetA) ? WidthA : WidthB;
5846 LowOffset + (
int)LowWidth.
getValue() <= HighOffset)
5860 bool IsLDAT =
MI.getOpcode() == PPC::LDAT_CSNE_PSEUDO;
5866 if (PtrReg == PPC::X8 || PtrReg == PPC::X9 || PtrReg == PPC::X10) {
5870 Register DstReg64 = IsLDAT ? DstReg
5872 DstReg, PPC::sub_32, &PPC::G8RCRegClass));
5874 ScratchReg = DstReg64;
5882 if (DstReg != (IsLDAT ? PPC::X8 : PPC::R8)) {
5884 .
addReg(IsLDAT ? PPC::X8 : PPC::R8)
5885 .
addReg(IsLDAT ? PPC::X8 : PPC::R8);
5887 MI.eraseFromParent();
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
const AArch64Subtarget & Subtarget
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
Function Alias Analysis false
static const Function * getParent(const Value *V)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
uint64_t IntrinsicInst * II
static bool isOpZeroOfSubwordPreincLoad(int Opcode)
static bool MBBDefinesCTR(MachineBasicBlock &MBB)
#define InfoArrayIdxMULOpIdx
static unsigned selectReg(int64_t Imm1, int64_t Imm2, unsigned CompareOpc, unsigned TrueReg, unsigned FalseReg, unsigned CRSubReg)
static unsigned getCRBitValue(unsigned CRBit)
static bool isAnImmediateOperand(const MachineOperand &MO)
static const uint16_t FMAOpIdxInfo[][6]
#define InfoArrayIdxAddOpIdx
static bool definedBySignExtendingOp(const PPCInstrInfo &TII, const unsigned Reg, const MachineRegisterInfo *MRI)
#define InfoArrayIdxFMAInst
static bool isClusterableLdStOpcPair(unsigned FirstOpc, unsigned SecondOpc, const PPCSubtarget &Subtarget)
static bool isLdStSafeToCluster(const MachineInstr &LdSt, const TargetRegisterInfo *TRI)
const unsigned MAX_BINOP_DEPTH
#define InfoArrayIdxFSubInst
#define InfoArrayIdxFAddInst
static bool definedByZeroExtendingOp(const PPCInstrInfo &TII, const unsigned Reg, const MachineRegisterInfo *MRI)
#define InfoArrayIdxFMULInst
static void swapMIOperands(MachineInstr &MI, unsigned Op1, unsigned Op2)
static constexpr MCPhysReg SPReg
SmallVector< MachineOperand, 4 > Cond
MachineRegisterInfo & MRI
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
static bool isPhysical(const MachineOperand &MO)
This file declares the machine register scavenger class.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
LLVM_ABI APInt rotl(unsigned rotateAmt) const
Rotate left by rotateAmt.
static APInt getBitsSetWithWrap(unsigned numBits, unsigned loBit, unsigned hiBit)
Wrap version of getBitsSet.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & front() const
Get the first element.
size_t size() const
Get the array size.
This class holds the attributes for a particular argument, parameter, function, or return value.
This is an important base class in LLVM.
LLVM_ABI Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
const BasicBlock & getEntryBlock() const
AttributeList getAttributes() const
Return the attribute list for this Function.
Type * getReturnType() const
Returns the type of the ret val.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Itinerary data supplied by a subtarget to be used by a target.
std::optional< unsigned > getOperandCycle(unsigned ItinClassIndx, unsigned OperandIdx) const
Return the cycle for the given class and operand.
Class to represent integer types.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
static LocationSize precise(uint64_t Value)
TypeSize getValue() const
Represents a single loop in the control flow graph.
Instances of this class represent a single low-level machine instruction.
void setOpcode(unsigned Op)
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
ArrayRef< MCPhysReg > implicit_defs() const
Return a list of registers that are potentially written by any instance of this machine instruction.
ArrayRef< MCPhysReg > implicit_uses() const
Return a list of registers that are potentially read by any instance of this machine instruction.
bool isPseudo() const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction.
This holds information about one operand of a machine instruction, indicating the register class for ...
bool hasSuperClassEq(const MCRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
bool hasSubClassEq(const MCRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
Wrapper class representing physical registers. Should be passed by value.
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
pred_iterator pred_begin()
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
Instructions::const_iterator const_instr_iterator
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
@ LQR_Dead
Register is known to be fully dead.
MachineInstrBundleIterator< const MachineInstr, true > const_reverse_iterator
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
const std::vector< MachineConstantPoolEntry > & getConstants() const
LLVM_ABI unsigned getConstantPoolIndex(const Constant *C, Align Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Register getReg(unsigned Idx) const
Get the register for the operand index.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool mayLoadOrStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read or modify memory.
const MachineBasicBlock * getParent() const
bool isCall(QueryType Type=AnyInBundle) const
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
LLVM_ABI unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
bool hasImplicitDef() const
Returns true if the instruction has implicit definition.
bool modifiesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr modifies (fully define or partially define) the specified register.
LLVM_ABI bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore,...
bool definesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr fully defines the specified register.
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
LLVM_ABI bool hasOrderedMemoryRef() const
Return true if this instruction may have an ordered or volatile memory reference, or if the informati...
LLVM_ABI const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI void dump() const
LLVM_ABI void clearRegisterDeads(Register Reg)
Clear all dead flags on operands defining register Reg.
const MachineOperand & getOperand(unsigned i) const
uint32_t getFlags() const
Return the MI flags bitvector.
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
A description of a memory reference used in the backend.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
unsigned getSubReg() const
const GlobalValue * getGlobal() const
void setImm(int64_t immVal)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void setIsKill(bool Val=true)
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
static MachineOperand CreateImm(int64_t Val)
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Register getReg() const
getReg - Returns the register number.
void setTargetFlags(unsigned F)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
LLVM_ABI bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
static MachineOperand CreateReg(Register 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, bool isRenamable=false)
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
defusechain_instr_iterator< true, false, false, true > use_instr_iterator
use_instr_iterator/use_instr_begin/use_instr_end - Walk all uses of the specified register,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool hasOneUse(Register RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
LLVM_ABI bool isLiveIn(Register Reg) const
LLVM_ABI void setRegClass(Register Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
iterator_range< use_instr_iterator > use_instructions(Register Reg) const
LLVM_ABI const TargetRegisterClass * constrainRegClass(Register Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
bool use_empty(Register RegNo) const
use_empty - Return true if there are no instructions using the specified register.
PPCDispatchGroupSBHazardRecognizer - This class implements a scoreboard-based hazard recognizer for P...
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
bool isLiveInSExt(Register VReg) const
This function returns true if the specified vreg is a live-in register and sign-extended.
bool isLiveInZExt(Register VReg) const
This function returns true if the specified vreg is a live-in register and zero-extended.
PPCHazardRecognizer970 - This class defines a finite state automata that models the dispatch logic on...
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const override
bool getFMAPatterns(MachineInstr &Root, SmallVectorImpl< unsigned > &Patterns, bool DoRegPressureReduce) const
Return true when there is potentially a faster code sequence for a fma chain ending in Root.
bool combineRLWINM(MachineInstr &MI, MachineInstr **ToErase=nullptr) const
bool isReMaterializableImpl(const MachineInstr &MI) const override
PPCInstrInfo(const PPCSubtarget &STI)
const TargetRegisterClass * updatedRC(const TargetRegisterClass *RC) const
bool isPredicated(const MachineInstr &MI) const override
bool expandVSXMemPseudo(MachineInstr &MI) const
bool onlyFoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, Register Reg) const
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, Register DestReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
void finalizeInsInstrs(MachineInstr &Root, unsigned &Pattern, SmallVectorImpl< MachineInstr * > &InsInstrs) const override
Fixup the placeholders we put in genAlternativeCodeSequence() for MachineCombiner.
MCInst getNop() const override
Return the noop instruction to use for a noop.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
static int getRecordFormOpcode(unsigned Opcode)
MachineInstr * commuteInstructionImpl(MachineInstr &MI, bool NewMI, unsigned OpIdx1, unsigned OpIdx2) const override
Commutes the operands in the given instruction.
bool isXFormMemOp(unsigned Opcode) const
const PPCRegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
CombinerObjective getCombinerObjective(unsigned Pattern) const override
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
unsigned getStoreOpcodeForSpill(const TargetRegisterClass *RC) const
unsigned getLoadOpcodeForSpill(const TargetRegisterClass *RC) const
bool expandAMOCSNEPseudo(MachineInstr &MI) const
bool isTOCSaveMI(const MachineInstr &MI) const
ScheduleHazardRecognizer * CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, const ScheduleDAG *DAG) const override
CreateTargetPostRAHazardRecognizer - Return the postRA hazard recognizer to use for this target when ...
bool isSExt32To64(unsigned Opcode) const
bool foldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, Register Reg, MachineRegisterInfo *MRI) const override
bool isBDNZ(unsigned Opcode) const
Check Opcode is BDNZ (Decrement CTR and branch if it is still nonzero).
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
bool isZeroExtended(const unsigned Reg, const MachineRegisterInfo *MRI) const
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
std::pair< bool, bool > isSignOrZeroExtended(const unsigned Reg, const unsigned BinOpDepth, const MachineRegisterInfo *MRI) const
bool expandPostRAPseudo(MachineInstr &MI) const override
bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, unsigned ExtraPredCycles, BranchProbability Probability) const override
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
bool isValidToBeChangedReg(MachineInstr *ADDMI, unsigned Index, MachineInstr *&ADDIMI, int64_t &OffsetAddi, int64_t OffsetImm) const
bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg, Register SrcReg2, int64_t Mask, int64_t Value, const MachineRegisterInfo *MRI) const override
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
std::optional< unsigned > getOperandLatency(const InstrItineraryData *ItinData, const MachineInstr &DefMI, unsigned DefIdx, const MachineInstr &UseMI, unsigned UseIdx) const override
void materializeImmPostRA(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register Reg, int64_t Imm) const
bool isADDInstrEligibleForFolding(MachineInstr &ADDMI) const
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override
Return true if two MIs access different memory addresses and false otherwise.
bool SubsumesPredicate(ArrayRef< MachineOperand > Pred1, ArrayRef< MachineOperand > Pred2) const override
ScheduleHazardRecognizer * CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI, const ScheduleDAG *DAG) const override
CreateTargetHazardRecognizer - Return the hazard recognizer to use for this target when scheduling th...
void setSpecialOperandAttr(MachineInstr &MI, uint32_t Flags) const
bool isADDIInstrEligibleForFolding(MachineInstr &ADDIMI, int64_t &Imm) const
bool getMemOperandsWithOffsetWidth(const MachineInstr &LdSt, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width) const override
Get the base operand and byte offset of an instruction that reads/writes memory.
void loadRegFromStackSlotNoUpd(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC) const
bool foldFrameOffset(MachineInstr &MI) const
bool isLoadFromConstantPool(MachineInstr *I) const
MachineInstr * findLoopInstr(MachineBasicBlock &PreHeader, SmallPtrSet< MachineBasicBlock *, 8 > &Visited) const
Find the hardware loop instruction used to set-up the specified loop.
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const override
void storeRegToStackSlotNoUpd(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC) const
bool isCoalescableExtInstr(const MachineInstr &MI, Register &SrcReg, Register &DstReg, unsigned &SubIdx) const override
bool convertToImmediateForm(MachineInstr &MI, SmallSet< Register, 4 > &RegsToUpdate, MachineInstr **KilledDef=nullptr) const
bool isAssociativeAndCommutative(const MachineInstr &Inst, bool Invert) const override
bool getMemOperandWithOffsetWidth(const MachineInstr &LdSt, const MachineOperand *&BaseOp, int64_t &Offset, LocationSize &Width) const
Return true if get the base operand, byte offset of an instruction and the memory width.
bool analyzeCompare(const MachineInstr &MI, Register &SrcReg, Register &SrcReg2, int64_t &Mask, int64_t &Value) const override
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
bool shouldReduceRegisterPressure(const MachineBasicBlock *MBB, const RegisterClassInfo *RegClassInfo) const override
On PowerPC, we leverage machine combiner pass to reduce register pressure when the register pressure ...
const TargetRegisterClass * getInlineAsmMemoryOperandRegClass(InlineAsm::ConstraintCode C) const override
void genAlternativeCodeSequence(MachineInstr &Root, unsigned Pattern, SmallVectorImpl< MachineInstr * > &InsInstrs, SmallVectorImpl< MachineInstr * > &DelInstrs, DenseMap< Register, unsigned > &InstrIdxForVirtReg) const override
When getMachineCombinerPatterns() finds patterns, this function generates the instructions that could...
InstSizeVerifyMode getInstSizeVerifyMode(const MachineInstr &MI) const override
bool isSignExtended(const unsigned Reg, const MachineRegisterInfo *MRI) const
void replaceInstrOperandWithImm(MachineInstr &MI, unsigned OpNo, int64_t Imm) const
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
GetInstSize - Return the number of bytes of code the specified instruction may be.
std::unique_ptr< TargetInstrInfo::PipelinerLoopInfo > analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const override
Analyze loop L, which must be a single-basic-block loop, and if the conditions can be understood enou...
bool shouldClusterMemOps(ArrayRef< const MachineOperand * > BaseOps1, int64_t Offset1, bool OffsetIsScalable1, ArrayRef< const MachineOperand * > BaseOps2, int64_t Offset2, bool OffsetIsScalable2, unsigned ClusterSize, unsigned NumBytes) const override
Returns true if the two given memory operations should be scheduled adjacent.
void replaceInstrWithLI(MachineInstr &MI, const LoadImmediateInfo &LII) const
bool isImmInstrEligibleForFolding(MachineInstr &MI, unsigned &BaseReg, unsigned &XFormOpcode, int64_t &OffsetOfImmInstr, ImmInstrInfo &III) const
bool PredicateInstruction(MachineInstr &MI, ArrayRef< MachineOperand > Pred) const override
bool getMachineCombinerPatterns(MachineInstr &Root, SmallVectorImpl< unsigned > &Patterns, bool DoRegPressureReduce) const override
Return true when there is potentially a faster code sequence for an instruction chain ending in <Root...
bool optimizeCmpPostRA(MachineInstr &MI) const
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
const Constant * getConstantFromConstantPool(MachineInstr *I) const
bool ClobbersPredicate(MachineInstr &MI, std::vector< MachineOperand > &Pred, bool SkipDead) const override
bool canInsertSelect(const MachineBasicBlock &, ArrayRef< MachineOperand > Cond, Register, Register, Register, SelectExpansion &) const override
void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, Register DstReg, ArrayRef< MachineOperand > Cond, Register TrueReg, Register FalseReg) const override
void promoteInstr32To64ForElimEXTSW(const Register &Reg, MachineRegisterInfo *MRI, unsigned BinOpDepth) const
bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const override
bool instrHasImmForm(unsigned Opc, bool IsVFReg, ImmInstrInfo &III, bool PostRA) const
MachineInstr * getDefMIPostRA(unsigned Reg, MachineInstr &MI, bool &SeenIntermediateUse) const
static void emitAccCopyInfo(MachineBasicBlock &MBB, MCRegister DestReg, MCRegister SrcReg)
MI-level patchpoint operands.
uint32_t getNumPatchBytes() const
Return the number of patchable bytes the given patchpoint should emit.
Track the current register pressure at some position in the instruction stream, and remember the high...
LLVM_ABI void init(const MachineFunction *mf, const RegisterClassInfo *rci, LiveIntervals *lis, const MachineBasicBlock *mbb, MachineBasicBlock::const_iterator pos, bool TrackLaneMasks, bool TrackUntiedDefs)
Setup the RegPressureTracker.
LLVM_ABI void closeRegion()
Finalize the region boundaries and recored live ins and live outs.
LLVM_ABI void recede(SmallVectorImpl< VRegMaskOrUnit > *LiveUses=nullptr)
Recede across the previous instruction.
RegisterPressure & getPressure()
Get the resulting register pressure over the traversed region.
LLVM_ABI void recedeSkipDebugValues()
Recede until we find an instruction which is not a DebugValue.
MachineBasicBlock::const_iterator getPos() const
Get the MI position corresponding to this register pressure.
unsigned getRegPressureSetLimit(unsigned Idx) const
Get the register unit limit for the given pressure set index.
List of registers defined and used by a machine instruction.
LLVM_ABI void collect(const MachineInstr &MI, const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, bool TrackLaneMasks, bool IgnoreDead)
Analyze the given instruction MI and fill in the Uses, Defs and DeadDefs list based on the MachineOpe...
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
static constexpr bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const TargetInstrInfo * TII
Target instruction information.
MachineFunction & MF
Machine function.
HazardRecognizer - This determines whether or not an instruction can be issued this cycle,...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MI-level stackmap operands.
uint32_t getNumPatchBytes() const
Return the number of patchable bytes the given stackmap should emit.
StackOffset holds a fixed and a scalable offset in bytes.
Object returned by analyzeLoopForPipelining.
TargetInstrInfo - Interface to description of machine instruction set.
virtual bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const
Returns true iff the routine could find two commutable operands in the given machine instruction.
virtual void genAlternativeCodeSequence(MachineInstr &Root, unsigned Pattern, SmallVectorImpl< MachineInstr * > &InsInstrs, SmallVectorImpl< MachineInstr * > &DelInstrs, DenseMap< Register, unsigned > &InstIdxForVirtReg) const
When getMachineCombinerPatterns() finds patterns, this function generates the instructions that could...
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...
virtual bool getMachineCombinerPatterns(MachineInstr &Root, SmallVectorImpl< unsigned > &Patterns, bool DoRegPressureReduce) const
Return true when there is potentially a faster code sequence for an instruction chain ending in Root.
virtual bool isReMaterializableImpl(const MachineInstr &MI) const
For instructions with opcodes for which the M_REMATERIALIZABLE flag is set, this hook lets the target...
virtual bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const
Test if the given instruction should be considered a scheduling boundary.
virtual CombinerObjective getCombinerObjective(unsigned Pattern) const
Return the objective of a combiner pattern.
virtual MachineInstr * commuteInstructionImpl(MachineInstr &MI, bool NewMI, unsigned OpIdx1, unsigned OpIdx2) const
This method commutes the operands of the given machine instruction MI.
const Triple & getTargetTriple() const
const MCAsmInfo & getMCAsmInfo() const
Return target specific asm information.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
LLVM_ABI bool isLittleEndian() const
Tests whether the target triple is little endian.
bool isOSAIX() const
Tests whether the OS is AIX.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
LLVM_ABI Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
PPCII - This namespace holds all of the PowerPC target-specific per-instruction flags.
Define some predicates that are used for node matching.
Predicate getSwappedPredicate(Predicate Opcode)
Assume the condition register is set by MI(a,b), return the predicate if we modify the instructions s...
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
unsigned getPredicateCondition(Predicate Opcode)
Return the condition without hint bits.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
unsigned getPredicateHint(Predicate Opcode)
Return the hint bits of the predicate.
Predicate InvertPredicate(Predicate Opcode)
Invert the specified predicate. != -> ==, < -> >=.
int32_t getNonRecordFormOpcode(uint32_t)
int32_t getAltVSXFMAOpcode(uint32_t Opcode)
static bool isVFRegister(MCRegister Reg)
NodeAddr< InstrNode * > Instr
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Kill
The last use of a register.
@ Define
Register definition.
constexpr RegState getKillRegState(bool B)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
@ Load
The value being inserted comes from a load (InsertElement only).
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
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...
static unsigned getCRFromCRBit(unsigned SrcReg)
constexpr RegState getDeadRegState(bool B)
auto reverse(ContainerTy &&C)
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
CombinerObjective
The combiner's goal may differ based on which pattern it is attempting to optimize.
@ MustReduceRegisterPressure
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI void recomputeLivenessFlags(MachineBasicBlock &MBB)
Recomputes dead and kill flags in MBB.
@ Sub
Subtraction of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
static bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME)
Returns true iff Val consists of one contiguous run of 1s with any number of 0s on either side.
@ End
Run the machine verifier once, at the end of the pipeline.
MCRegisterClass TargetRegisterClass
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t IsSummingOperands
uint64_t OpNoForForwarding
uint64_t ImmMustBeMultipleOf
uint64_t ZeroIsSpecialNew
uint64_t ZeroIsSpecialOrig
static LLVM_ABI MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
RegisterPressure computed within a region of instructions delimited by TopPos and BottomPos.
std::vector< unsigned > MaxSetPressure
Map of max reg pressure indexed by pressure set ID, not class ID.