35 #include "llvm/IR/IntrinsicsAArch64.h" 39 #define DEBUG_TYPE "aarch64-isel" 45 #define GET_GLOBALISEL_PREDICATE_BITSET 46 #include "AArch64GenGlobalISel.inc" 47 #undef GET_GLOBALISEL_PREDICATE_BITSET 64 ProduceNonFlagSettingCondBr =
169 ComplexRendererFns selectShiftA_32(
const MachineOperand &Root)
const;
170 ComplexRendererFns selectShiftB_32(
const MachineOperand &Root)
const;
171 ComplexRendererFns selectShiftA_64(
const MachineOperand &Root)
const;
172 ComplexRendererFns selectShiftB_64(
const MachineOperand &Root)
const;
174 ComplexRendererFns select12BitValueWithLeftShift(uint64_t Immed)
const;
176 ComplexRendererFns selectNegArithImmed(
MachineOperand &Root)
const;
179 unsigned Size)
const;
181 ComplexRendererFns selectAddrModeUnscaled8(
MachineOperand &Root)
const {
182 return selectAddrModeUnscaled(Root, 1);
184 ComplexRendererFns selectAddrModeUnscaled16(
MachineOperand &Root)
const {
185 return selectAddrModeUnscaled(Root, 2);
187 ComplexRendererFns selectAddrModeUnscaled32(
MachineOperand &Root)
const {
188 return selectAddrModeUnscaled(Root, 4);
190 ComplexRendererFns selectAddrModeUnscaled64(
MachineOperand &Root)
const {
191 return selectAddrModeUnscaled(Root, 8);
193 ComplexRendererFns selectAddrModeUnscaled128(
MachineOperand &Root)
const {
194 return selectAddrModeUnscaled(Root, 16);
198 unsigned Size)
const;
200 ComplexRendererFns selectAddrModeIndexed(
MachineOperand &Root)
const {
201 return selectAddrModeIndexed(Root,
Width / 8);
208 unsigned SizeInBytes)
const;
216 bool WantsExt)
const;
217 ComplexRendererFns selectAddrModeRegisterOffset(
MachineOperand &Root)
const;
219 unsigned SizeInBytes)
const;
221 ComplexRendererFns selectAddrModeXRO(
MachineOperand &Root)
const {
222 return selectAddrModeXRO(Root,
Width / 8);
226 unsigned SizeInBytes)
const;
228 ComplexRendererFns selectAddrModeWRO(
MachineOperand &Root)
const {
229 return selectAddrModeWRO(Root,
Width / 8);
232 ComplexRendererFns selectShiftedRegister(
MachineOperand &Root)
const;
234 ComplexRendererFns selectArithShiftedRegister(
MachineOperand &Root)
const {
235 return selectShiftedRegister(Root);
238 ComplexRendererFns selectLogicalShiftedRegister(
MachineOperand &Root)
const {
243 return selectShiftedRegister(Root);
253 bool IsLoadStore =
false)
const;
261 ComplexRendererFns selectArithExtendedRegister(
MachineOperand &Root)
const;
264 int OpIdx = -1)
const;
266 int OpIdx = -1)
const;
268 int OpIdx = -1)
const;
272 unsigned OpFlags)
const;
283 bool isLoadStoreOfNumBytes(
const MachineInstr &MI,
unsigned NumBytes)
const;
296 bool ProduceNonFlagSettingCondBr =
false;
298 #define GET_GLOBALISEL_PREDICATES_DECL 299 #include "AArch64GenGlobalISel.inc" 300 #undef GET_GLOBALISEL_PREDICATES_DECL 304 #define GET_GLOBALISEL_TEMPORARIES_DECL 305 #include "AArch64GenGlobalISel.inc" 306 #undef GET_GLOBALISEL_TEMPORARIES_DECL 311 #define GET_GLOBALISEL_IMPL 312 #include "AArch64GenGlobalISel.inc" 313 #undef GET_GLOBALISEL_IMPL 315 AArch64InstructionSelector::AArch64InstructionSelector(
319 TRI(*STI.getRegisterInfo()), RBI(RBI),
321 #include
"AArch64GenGlobalISel.inc" 324 #include
"AArch64GenGlobalISel.inc" 334 bool GetAllRegSet =
false) {
335 if (RB.
getID() == AArch64::GPRRegBankID) {
337 return GetAllRegSet ? &AArch64::GPR32allRegClass
338 : &AArch64::GPR32RegClass;
340 return GetAllRegSet ? &AArch64::GPR64allRegClass
341 : &AArch64::GPR64RegClass;
345 if (RB.
getID() == AArch64::FPRRegBankID) {
347 return &AArch64::FPR16RegClass;
349 return &AArch64::FPR32RegClass;
351 return &AArch64::FPR64RegClass;
353 return &AArch64::FPR128RegClass;
364 bool GetAllRegSet =
false) {
365 unsigned RegBankID = RB.
getID();
367 if (RegBankID == AArch64::GPRRegBankID) {
368 if (SizeInBits <= 32)
369 return GetAllRegSet ? &AArch64::GPR32allRegClass
370 : &AArch64::GPR32RegClass;
371 if (SizeInBits == 64)
372 return GetAllRegSet ? &AArch64::GPR64allRegClass
373 : &AArch64::GPR64RegClass;
376 if (RegBankID == AArch64::FPRRegBankID) {
377 switch (SizeInBits) {
381 return &AArch64::FPR8RegClass;
383 return &AArch64::FPR16RegClass;
385 return &AArch64::FPR32RegClass;
387 return &AArch64::FPR64RegClass;
389 return &AArch64::FPR128RegClass;
401 SubReg = AArch64::bsub;
404 SubReg = AArch64::hsub;
407 if (RC != &AArch64::FPR32RegClass)
408 SubReg = AArch64::sub_32;
410 SubReg = AArch64::ssub;
413 SubReg = AArch64::dsub;
417 dbgs() <<
"Couldn't find appropriate subregister for register class.");
444 LLVM_DEBUG(
dbgs() <<
"Generic inst non-reg operands are unsupported\n");
452 if (!Register::isVirtualRegister(MO.getReg())) {
453 LLVM_DEBUG(
dbgs() <<
"Generic inst has physical register operand\n");
463 if (PrevOpBank && OpBank != PrevOpBank) {
464 LLVM_DEBUG(
dbgs() <<
"Generic inst operands have different banks\n");
479 case AArch64::GPRRegBankID:
481 switch (GenericOpc) {
482 case TargetOpcode::G_SHL:
483 return AArch64::LSLVWr;
484 case TargetOpcode::G_LSHR:
485 return AArch64::LSRVWr;
486 case TargetOpcode::G_ASHR:
487 return AArch64::ASRVWr;
491 }
else if (OpSize == 64) {
492 switch (GenericOpc) {
493 case TargetOpcode::G_PTR_ADD:
494 return AArch64::ADDXrr;
495 case TargetOpcode::G_SHL:
496 return AArch64::LSLVXr;
497 case TargetOpcode::G_LSHR:
498 return AArch64::LSRVXr;
499 case TargetOpcode::G_ASHR:
500 return AArch64::ASRVXr;
506 case AArch64::FPRRegBankID:
509 switch (GenericOpc) {
510 case TargetOpcode::G_FADD:
511 return AArch64::FADDSrr;
512 case TargetOpcode::G_FSUB:
513 return AArch64::FSUBSrr;
514 case TargetOpcode::G_FMUL:
515 return AArch64::FMULSrr;
516 case TargetOpcode::G_FDIV:
517 return AArch64::FDIVSrr;
522 switch (GenericOpc) {
523 case TargetOpcode::G_FADD:
524 return AArch64::FADDDrr;
525 case TargetOpcode::G_FSUB:
526 return AArch64::FSUBDrr;
527 case TargetOpcode::G_FMUL:
528 return AArch64::FMULDrr;
529 case TargetOpcode::G_FDIV:
530 return AArch64::FDIVDrr;
531 case TargetOpcode::G_OR:
532 return AArch64::ORRv8i8;
549 const bool isStore = GenericOpc == TargetOpcode::G_STORE;
551 case AArch64::GPRRegBankID:
554 return isStore ? AArch64::STRBBui : AArch64::LDRBBui;
556 return isStore ? AArch64::STRHHui : AArch64::LDRHHui;
558 return isStore ? AArch64::STRWui : AArch64::LDRWui;
560 return isStore ? AArch64::STRXui : AArch64::LDRXui;
563 case AArch64::FPRRegBankID:
566 return isStore ? AArch64::STRBui : AArch64::LDRBui;
568 return isStore ? AArch64::STRHui : AArch64::LDRHui;
570 return isStore ? AArch64::STRSui : AArch64::LDRSui;
572 return isStore ? AArch64::STRDui : AArch64::LDRDui;
589 const unsigned DstSize = RBI.getSizeInBits(DstReg, MRI, TRI);
590 const unsigned SrcSize = RBI.getSizeInBits(SrcReg, MRI, TRI);
594 (DstSize == SrcSize ||
597 (Register::isPhysicalRegister(SrcReg) && DstSize <= SrcSize) ||
601 (((DstSize + 31) / 32 == (SrcSize + 31) / 32) && DstSize > SrcSize)) &&
602 "Copy with different width?!");
605 assert((DstSize <= 64 || DstBank.
getID() == AArch64::FPRRegBankID) &&
606 "GPRs cannot get more than 64-bit width values");
626 auto Copy = MIB.
buildCopy({From}, {SrcReg});
627 auto SubRegCopy = MIB.
buildInstr(TargetOpcode::COPY, {To}, {})
628 .addReg(Copy.getReg(0), 0,
SubReg);
630 RegOp.
setReg(SubRegCopy.getReg(0));
644 static std::pair<const TargetRegisterClass *, const TargetRegisterClass *>
652 unsigned DstSize = RBI.getSizeInBits(DstReg, MRI, TRI);
653 unsigned SrcSize = RBI.getSizeInBits(SrcReg, MRI, TRI);
663 if (SrcRegBank != DstRegBank && (DstSize == 1 && SrcSize == 1))
664 SrcSize = DstSize = 32;
686 << RBI.getSizeInBits(DstReg, MRI, TRI) <<
'\n');
695 bool KnownValid =
false;
700 auto CheckCopy = [&]() {
705 "No phys reg on generic operator!");
716 LLVM_DEBUG(
dbgs() <<
"Couldn't determine source register class\n");
725 if (SrcSize > DstSize) {
731 assert(SubregRC &&
"Didn't get a register class for subreg?");
736 LLVM_DEBUG(
dbgs() <<
"Couldn't determine subregister for copy.\n");
746 if (DstRegBank.
getID() != SrcRegBank.
getID()) {
747 if (DstRegBank.
getID() == AArch64::GPRRegBankID && DstSize == 32 &&
754 TII.
get(AArch64::SUBREG_TO_REG), PromoteReg)
768 if (Register::isPhysicalRegister(DstReg))
794 switch (GenericOpc) {
795 case TargetOpcode::G_SITOFP:
796 return AArch64::SCVTFUWSri;
797 case TargetOpcode::G_UITOFP:
798 return AArch64::UCVTFUWSri;
799 case TargetOpcode::G_FPTOSI:
800 return AArch64::FCVTZSUWSr;
801 case TargetOpcode::G_FPTOUI:
802 return AArch64::FCVTZUUWSr;
807 switch (GenericOpc) {
808 case TargetOpcode::G_SITOFP:
809 return AArch64::SCVTFUXSri;
810 case TargetOpcode::G_UITOFP:
811 return AArch64::UCVTFUXSri;
812 case TargetOpcode::G_FPTOSI:
813 return AArch64::FCVTZSUWDr;
814 case TargetOpcode::G_FPTOUI:
815 return AArch64::FCVTZUUWDr;
825 switch (GenericOpc) {
826 case TargetOpcode::G_SITOFP:
827 return AArch64::SCVTFUWDri;
828 case TargetOpcode::G_UITOFP:
829 return AArch64::UCVTFUWDri;
830 case TargetOpcode::G_FPTOSI:
831 return AArch64::FCVTZSUXSr;
832 case TargetOpcode::G_FPTOUI:
833 return AArch64::FCVTZUUXSr;
838 switch (GenericOpc) {
839 case TargetOpcode::G_SITOFP:
840 return AArch64::SCVTFUXDri;
841 case TargetOpcode::G_UITOFP:
842 return AArch64::UCVTFUXDri;
843 case TargetOpcode::G_FPTOSI:
844 return AArch64::FCVTZSUXDr;
845 case TargetOpcode::G_FPTOUI:
846 return AArch64::FCVTZUUXDr;
863 AArch64::GPRRegBankID);
865 if (Ty == LLT::scalar(32))
866 return IsFP ? AArch64::FCSELSrrr : AArch64::CSELWr;
867 else if (Ty == LLT::scalar(64) || Ty == LLT::pointer(0, 64))
868 return IsFP ? AArch64::FCSELDrrr : AArch64::CSELXr;
879 if (OpSize != 32 && OpSize != 64)
881 unsigned CmpOpcTbl[2][2] = {{AArch64::FCMPSrr, AArch64::FCMPDrr},
882 {AArch64::FCMPSri, AArch64::FCMPDri}};
883 return CmpOpcTbl[ShouldUseImm][OpSize == 64];
891 case CmpInst::ICMP_UGT:
892 case CmpInst::ICMP_UGE:
893 case CmpInst::ICMP_ULT:
894 case CmpInst::ICMP_ULE:
903 case CmpInst::ICMP_NE:
905 case CmpInst::ICMP_EQ:
907 case CmpInst::ICMP_SGT:
909 case CmpInst::ICMP_SGE:
911 case CmpInst::ICMP_SLT:
913 case CmpInst::ICMP_SLE:
915 case CmpInst::ICMP_UGT:
917 case CmpInst::ICMP_UGE:
919 case CmpInst::ICMP_ULT:
921 case CmpInst::ICMP_ULE:
933 case CmpInst::FCMP_OEQ:
936 case CmpInst::FCMP_OGT:
939 case CmpInst::FCMP_OGE:
942 case CmpInst::FCMP_OLT:
945 case CmpInst::FCMP_OLE:
948 case CmpInst::FCMP_ONE:
952 case CmpInst::FCMP_ORD:
955 case CmpInst::FCMP_UNO:
958 case CmpInst::FCMP_UEQ:
962 case CmpInst::FCMP_UGT:
965 case CmpInst::FCMP_UGE:
968 case CmpInst::FCMP_ULT:
971 case CmpInst::FCMP_ULE:
974 case CmpInst::FCMP_UNE:
980 bool AArch64InstructionSelector::selectCompareBranch(
986 if (CCMI->
getOpcode() == TargetOpcode::G_TRUNC)
988 if (CCMI->
getOpcode() != TargetOpcode::G_ICMP)
998 if (!VRegAndVal || VRegAndVal->Value != 0) {
1012 if (RB.
getID() != AArch64::GPRRegBankID)
1016 if (Pred != CmpInst::ICMP_NE && Pred != CmpInst::ICMP_EQ)
1022 CBOpc = (Pred == CmpInst::ICMP_EQ ? AArch64::CBZW : AArch64::CBNZW);
1023 else if (CmpWidth == 64)
1024 CBOpc = (Pred == CmpInst::ICMP_EQ ? AArch64::CBZX : AArch64::CBNZX);
1043 assert(OpMI &&
"Expected to find a vreg def for vector shift operand");
1044 if (OpMI->getOpcode() != TargetOpcode::G_BUILD_VECTOR)
1049 for (
unsigned Idx = 1; Idx < OpMI->getNumOperands(); ++Idx) {
1055 ImmVal = VRegAndVal->Value;
1056 if (ImmVal != VRegAndVal->Value)
1070 int64_t Imm = *ShiftImm;
1097 bool AArch64InstructionSelector::selectVectorSHL(
1113 if (Ty == LLT::vector(2, 64)) {
1114 Opc = ImmVal ? AArch64::SHLv2i64_shift : AArch64::USHLv2i64;
1115 }
else if (Ty == LLT::vector(4, 32)) {
1116 Opc = ImmVal ? AArch64::SHLv4i32_shift : AArch64::USHLv4i32;
1117 }
else if (Ty == LLT::vector(2, 32)) {
1118 Opc = ImmVal ? AArch64::SHLv2i32_shift : AArch64::USHLv2i32;
1125 auto Shl = MIB.
buildInstr(Opc, {DstReg}, {Src1Reg});
1135 bool AArch64InstructionSelector::selectVectorASHR(
1151 unsigned NegOpc = 0;
1153 if (Ty == LLT::vector(2, 64)) {
1154 Opc = AArch64::SSHLv2i64;
1155 NegOpc = AArch64::NEGv2i64;
1156 RC = &AArch64::FPR128RegClass;
1157 }
else if (Ty == LLT::vector(4, 32)) {
1158 Opc = AArch64::SSHLv4i32;
1159 NegOpc = AArch64::NEGv4i32;
1160 RC = &AArch64::FPR128RegClass;
1161 }
else if (Ty == LLT::vector(2, 32)) {
1162 Opc = AArch64::SSHLv2i32;
1163 NegOpc = AArch64::NEGv2i32;
1164 RC = &AArch64::FPR64RegClass;
1171 auto Neg = MIB.
buildInstr(NegOpc, {RC}, {Src2Reg});
1173 auto SShl = MIB.
buildInstr(Opc, {DstReg}, {Src1Reg, Neg});
1179 bool AArch64InstructionSelector::selectVaStartAAPCS(
1184 bool AArch64InstructionSelector::selectVaStartDarwin(
1193 .addDef(ArgsAddrReg)
1201 .addUse(ArgsAddrReg)
1211 void AArch64InstructionSelector::materializeLargeCMVal(
1218 auto MovZ = MIB.
buildInstr(AArch64::MOVZXi, {&AArch64::GPR64RegClass}, {});
1222 MovZ->addOperand(MF, MachineOperand::CreateImm(0));
1225 auto BuildMovK = [&](
Register SrcReg,
unsigned char Flags,
unsigned Offset,
1231 if (
auto *GV = dyn_cast<GlobalValue>(V)) {
1232 MovI->
addOperand(MF, MachineOperand::CreateGA(
1233 GV, MovZ->getOperand(1).getOffset(), Flags));
1236 MF, MachineOperand::CreateBA(cast<BlockAddress>(V),
1237 MovZ->getOperand(1).getOffset(), Flags));
1239 MovI->addOperand(MF, MachineOperand::CreateImm(Offset));
1243 Register DstReg = BuildMovK(MovZ.getReg(0),
1250 void AArch64InstructionSelector::preISelLower(
MachineInstr &I)
const {
1256 case TargetOpcode::G_SHL:
1257 case TargetOpcode::G_ASHR:
1258 case TargetOpcode::G_LSHR: {
1275 assert(AmtMI &&
"could not find a vreg definition for shift amount");
1276 if (AmtMI->getOpcode() != TargetOpcode::G_CONSTANT) {
1279 auto Trunc = MIB.
buildInstr(TargetOpcode::COPY, {SrcTy}, {})
1280 .addReg(ShiftReg, 0, AArch64::sub_32);
1286 case TargetOpcode::G_STORE:
1287 contractCrossBankCopyIntoStore(I, MRI);
1294 bool AArch64InstructionSelector::earlySelectSHL(
1309 auto Imm1Fn = Is64Bit ? selectShiftA_64(MO) : selectShiftA_32(MO);
1310 auto Imm2Fn = Is64Bit ? selectShiftB_64(MO) : selectShiftB_32(MO);
1313 if (!Imm1Fn || !Imm2Fn)
1317 MIB.
buildInstr(Is64Bit ? AArch64::UBFMXri : AArch64::UBFMWri,
1320 for (
auto &RenderFn : *Imm1Fn)
1322 for (
auto &RenderFn : *Imm2Fn)
1329 void AArch64InstructionSelector::contractCrossBankCopyIntoStore(
1349 Register DefDstReg = Def->getOperand(0).getReg();
1371 bool AArch64InstructionSelector::earlySelect(
MachineInstr &I)
const {
1380 case TargetOpcode::G_SHL:
1381 return earlySelectSHL(I, MRI);
1382 case TargetOpcode::G_CONSTANT: {
1383 bool IsZero =
false;
1394 if (Ty != LLT::scalar(64) && Ty != LLT::scalar(32))
1397 if (Ty == LLT::scalar(64)) {
1412 bool AArch64InstructionSelector::select(
MachineInstr &I) {
1425 if (Opcode == TargetOpcode::LOAD_STACK_GUARD)
1428 if (Opcode == TargetOpcode::PHI || Opcode == TargetOpcode::G_PHI) {
1443 DefRC = getRegClassForTypeOnBank(DefTy, RB, RBI);
1464 dbgs() <<
"Generic instruction has unexpected implicit operands\n");
1490 case TargetOpcode::G_BRCOND: {
1496 <<
", expected at most 32-bits");
1506 bool ProduceNonFlagSettingCondBr =
1508 if (ProduceNonFlagSettingCondBr && selectCompareBranch(I, MF, MRI))
1511 if (ProduceNonFlagSettingCondBr) {
1521 .addDef(AArch64::WZR)
1535 case TargetOpcode::G_BRINDIRECT: {
1540 case TargetOpcode::G_BRJT:
1541 return selectBrJT(I, MRI);
1543 case TargetOpcode::G_BSWAP: {
1551 LLVM_DEBUG(
dbgs() <<
"Dst type for G_BSWAP currently unsupported.\n");
1558 if (NumElts != 4 && NumElts != 2) {
1559 LLVM_DEBUG(
dbgs() <<
"Unsupported number of elements for G_BSWAP.\n");
1569 : AArch64::REV32v16i8;
1570 else if (EltSize == 64)
1571 Opc = AArch64::REV64v16i8;
1574 assert(Opc != 0 &&
"Didn't get an opcode for G_BSWAP?");
1580 case TargetOpcode::G_FCONSTANT:
1581 case TargetOpcode::G_CONSTANT: {
1582 const bool isFP = Opcode == TargetOpcode::G_FCONSTANT;
1584 const LLT s8 = LLT::scalar(8);
1585 const LLT s16 = LLT::scalar(16);
1586 const LLT s32 = LLT::scalar(32);
1587 const LLT s64 = LLT::scalar(64);
1588 const LLT p0 = LLT::pointer(0, 64);
1597 if (Ty != s32 && Ty != s64) {
1599 <<
" constant, expected: " << s32 <<
" or " << s64
1604 if (RB.
getID() != AArch64::FPRRegBankID) {
1606 <<
" constant on bank: " << RB
1607 <<
", expected: FPR\n");
1617 if (Ty != p0 && Ty != s8 && Ty != s16) {
1619 <<
" constant, expected: " << s32 <<
", " << s64
1620 <<
", or " << p0 <<
'\n');
1624 if (RB.
getID() != AArch64::GPRRegBankID) {
1626 <<
" constant on bank: " << RB
1627 <<
", expected: GPR\n");
1633 const unsigned MovOpc =
1634 DefSize == 64 ? AArch64::MOVi64imm : AArch64::MOVi32imm;
1639 DefSize == 32 ? AArch64::GPR32RegClass : AArch64::GPR64RegClass;
1641 DefSize == 32 ? AArch64::FPR32RegClass : AArch64::FPR64RegClass;
1644 if (emitFMovForFConstant(I, MRI))
1655 LLVM_DEBUG(
dbgs() <<
"Failed to constrain G_FCONSTANT def operand\n");
1675 case TargetOpcode::G_EXTRACT: {
1695 DstRB.
getID() == AArch64::FPRRegBankID &&
1696 "Wrong extract regbank!");
1702 if (Offset % 64 != 0)
1704 unsigned LaneIdx = Offset / 64;
1707 DstReg, DstRB, LLT::scalar(64), SrcReg, LaneIdx, MIB);
1714 I.
setDesc(
TII.get(SrcSize == 64 ? AArch64::UBFMXri : AArch64::UBFMWri));
1720 "unexpected G_EXTRACT types");
1727 .addReg(DstReg, 0, AArch64::sub_32);
1729 AArch64::GPR32RegClass,
MRI);
1735 case TargetOpcode::G_INSERT: {
1744 I.
setDesc(
TII.get(DstSize == 64 ? AArch64::BFMXri : AArch64::BFMWri));
1752 "unexpected G_INSERT types");
1758 TII.get(AArch64::SUBREG_TO_REG))
1762 .addImm(AArch64::sub_32);
1764 AArch64::GPR32RegClass,
MRI);
1769 case TargetOpcode::G_FRAME_INDEX: {
1771 if (Ty != LLT::pointer(0, 64)) {
1773 <<
", expected: " << LLT::pointer(0, 64) <<
'\n');
1785 case TargetOpcode::G_GLOBAL_VALUE: {
1787 if (GV->isThreadLocal())
1788 return selectTLSGlobalValue(I, MRI);
1790 unsigned OpFlags = STI.ClassifyGlobalReference(GV,
TM);
1796 materializeLargeCMVal(I, GV, OpFlags);
1812 case TargetOpcode::G_ZEXTLOAD:
1813 case TargetOpcode::G_LOAD:
1814 case TargetOpcode::G_STORE: {
1815 bool IsZExtLoad = I.
getOpcode() == TargetOpcode::G_ZEXTLOAD;
1820 if (PtrTy != LLT::pointer(0, 64)) {
1822 <<
", expected: " << LLT::pointer(0, 64) <<
'\n');
1827 if (MemOp.isAtomic()) {
1830 if (MemOp.getOrdering() == AtomicOrdering::Acquire &&
1831 MemOp.getSize() == 1) {
1835 LLVM_DEBUG(
dbgs() <<
"Atomic load/store not fully supported yet\n");
1838 unsigned MemSizeInBits = MemOp.getSize() * 8;
1845 "Load/Store pointer operand isn't a GPR");
1847 "Load/Store pointer operand isn't a pointer");
1853 const unsigned NewOpc =
1864 if (PtrMI->getOpcode() == TargetOpcode::G_PTR_ADD) {
1866 int64_t Imm = *COff;
1867 const unsigned Size = MemSizeInBits / 8;
1868 const unsigned Scale =
Log2_32(Size);
1869 if ((Imm & (Size - 1)) == 0 && Imm >= 0 && Imm < (0x1000 << Scale)) {
1870 Register Ptr2Reg = PtrMI->getOperand(1).getReg();
1873 Offset = Imm /
Size;
1880 if (!Offset && PtrMI->getOpcode() == TargetOpcode::G_FRAME_INDEX)
1883 I.
addOperand(MachineOperand::CreateImm(Offset));
1887 if (*CVal == 0 && Opcode == TargetOpcode::G_STORE) {
1890 else if (I.
getOpcode() == AArch64::STRXui)
1906 MIB.
buildInstr(AArch64::SUBREG_TO_REG, {DstReg}, {})
1909 .
addImm(AArch64::sub_32);
1917 case TargetOpcode::G_SMULH:
1918 case TargetOpcode::G_UMULH: {
1926 if (RB.
getID() != AArch64::GPRRegBankID) {
1927 LLVM_DEBUG(
dbgs() <<
"G_[SU]MULH on bank: " << RB <<
", expected: GPR\n");
1931 if (Ty != LLT::scalar(64)) {
1933 <<
", expected: " << LLT::scalar(64) <<
'\n');
1937 unsigned NewOpc = I.
getOpcode() == TargetOpcode::G_SMULH ? AArch64::SMULHrr
1945 case TargetOpcode::G_FADD:
1946 case TargetOpcode::G_FSUB:
1947 case TargetOpcode::G_FMUL:
1948 case TargetOpcode::G_FDIV:
1950 case TargetOpcode::G_ASHR:
1952 return selectVectorASHR(I, MRI);
1954 case TargetOpcode::G_SHL:
1955 if (Opcode == TargetOpcode::G_SHL &&
1957 return selectVectorSHL(I, MRI);
1959 case TargetOpcode::G_OR:
1960 case TargetOpcode::G_LSHR: {
1982 case TargetOpcode::G_PTR_ADD: {
1989 case TargetOpcode::G_UADDO: {
1992 if (OpSize != 32 && OpSize != 64) {
1995 <<
"G_UADDO currently only supported for 32 and 64 b types.\n");
2001 LLVM_DEBUG(
dbgs() <<
"G_UADDO currently only supported for scalars.\n");
2006 unsigned AddsOpc = OpSize == 32 ? AArch64::ADDSWrr : AArch64::ADDSXrr;
2017 auto CsetMI = MIRBuilder
2026 case TargetOpcode::G_PTR_MASK: {
2028 if (Align >= 64 || Align == 0)
2037 case TargetOpcode::G_PTRTOINT:
2038 case TargetOpcode::G_TRUNC: {
2050 dbgs() <<
"G_TRUNC/G_PTRTOINT input/output on different banks\n");
2054 if (DstRB.
getID() == AArch64::GPRRegBankID) {
2056 getRegClassForTypeOnBank(DstTy, DstRB, RBI);
2061 getRegClassForTypeOnBank(SrcTy, SrcRB, RBI);
2067 LLVM_DEBUG(
dbgs() <<
"Failed to constrain G_TRUNC/G_PTRTOINT\n");
2071 if (DstRC == SrcRC) {
2073 }
else if (Opcode == TargetOpcode::G_TRUNC && DstTy == LLT::scalar(32) &&
2074 SrcTy == LLT::scalar(64)) {
2077 }
else if (DstRC == &AArch64::GPR32RegClass &&
2078 SrcRC == &AArch64::GPR64RegClass) {
2082 dbgs() <<
"Unhandled mismatched classes in G_TRUNC/G_PTRTOINT\n");
2088 }
else if (DstRB.
getID() == AArch64::FPRRegBankID) {
2089 if (DstTy == LLT::vector(4, 16) && SrcTy == LLT::vector(4, 32)) {
2098 DstReg, DstRB, LLT::scalar(DstTy.
getSizeInBits()), SrcReg, 0, MIB);
2109 case TargetOpcode::G_ANYEXT: {
2114 if (RBDst.
getID() != AArch64::GPRRegBankID) {
2116 <<
", expected: GPR\n");
2121 if (RBSrc.
getID() != AArch64::GPRRegBankID) {
2123 <<
", expected: GPR\n");
2130 LLVM_DEBUG(
dbgs() <<
"G_ANYEXT operand has no size, not a gvreg?\n");
2134 if (DstSize != 64 && DstSize > 32) {
2136 <<
", expected: 32 or 64\n");
2147 .
addImm(AArch64::sub_32);
2153 case TargetOpcode::G_ZEXT:
2154 case TargetOpcode::G_SEXT: {
2156 const bool IsSigned = Opcode == TargetOpcode::G_SEXT;
2168 AArch64::GPRRegBankID &&
2169 "Unexpected ext regbank");
2181 auto *LoadMI =
getOpcodeDef(TargetOpcode::G_LOAD, SrcReg, MRI);
2185 unsigned BytesLoaded = MemOp->
getSize();
2191 if (DstSize == 64) {
2200 MIB.buildInstr(AArch64::SUBREG_TO_REG, {&AArch64::GPR64RegClass}, {})
2203 .addImm(AArch64::sub_32);
2205 ExtI = MIB.buildInstr(IsSigned ? AArch64::SBFMXri : AArch64::UBFMXri,
2206 {DefReg}, {SubregToReg})
2208 .addImm(SrcSize - 1);
2209 }
else if (DstSize <= 32) {
2210 ExtI = MIB.buildInstr(IsSigned ? AArch64::SBFMWri : AArch64::UBFMWri,
2213 .addImm(SrcSize - 1);
2223 case TargetOpcode::G_SITOFP:
2224 case TargetOpcode::G_UITOFP:
2225 case TargetOpcode::G_FPTOSI:
2226 case TargetOpcode::G_FPTOUI: {
2230 if (NewOpc == Opcode)
2240 case TargetOpcode::G_INTTOPTR:
2245 case TargetOpcode::G_BITCAST:
2253 case TargetOpcode::G_SELECT: {
2256 <<
", expected: " << LLT::scalar(1) <<
'\n');
2264 if (tryOptSelect(I))
2270 .addDef(AArch64::WZR)
2286 case TargetOpcode::G_ICMP: {
2288 return selectVectorICmp(I, MRI);
2290 if (Ty != LLT::scalar(32)) {
2292 <<
", expected: " << LLT::scalar(32) <<
'\n');
2306 case TargetOpcode::G_FCMP: {
2307 if (Ty != LLT::scalar(32)) {
2309 <<
", expected: " << LLT::scalar(32) <<
'\n');
2331 if (CmpOpc != AArch64::FCMPSri && CmpOpc != AArch64::FCMPDri)
2368 case TargetOpcode::G_VASTART:
2369 return STI.isTargetDarwin() ? selectVaStartDarwin(I, MF, MRI)
2370 : selectVaStartAAPCS(I, MF, MRI);
2371 case TargetOpcode::G_INTRINSIC:
2372 return selectIntrinsic(I, MRI);
2373 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
2374 return selectIntrinsicWithSideEffects(I, MRI);
2375 case TargetOpcode::G_IMPLICIT_DEF: {
2376 I.
setDesc(
TII.get(TargetOpcode::IMPLICIT_DEF));
2381 getRegClassForTypeOnBank(DstTy, DstRB, RBI);
2385 case TargetOpcode::G_BLOCK_ADDR: {
2403 case TargetOpcode::G_INTRINSIC_TRUNC:
2404 return selectIntrinsicTrunc(I, MRI);
2405 case TargetOpcode::G_INTRINSIC_ROUND:
2406 return selectIntrinsicRound(I, MRI);
2407 case TargetOpcode::G_BUILD_VECTOR:
2408 return selectBuildVector(I, MRI);
2409 case TargetOpcode::G_MERGE_VALUES:
2411 case TargetOpcode::G_UNMERGE_VALUES:
2413 case TargetOpcode::G_SHUFFLE_VECTOR:
2414 return selectShuffleVector(I, MRI);
2415 case TargetOpcode::G_EXTRACT_VECTOR_ELT:
2416 return selectExtractElt(I, MRI);
2417 case TargetOpcode::G_INSERT_VECTOR_ELT:
2418 return selectInsertElt(I, MRI);
2419 case TargetOpcode::G_CONCAT_VECTORS:
2420 return selectConcatVectors(I, MRI);
2421 case TargetOpcode::G_JUMP_TABLE:
2422 return selectJumpTable(I, MRI);
2428 bool AArch64InstructionSelector::selectBrJT(
MachineInstr &I,
2438 MIB.
buildInstr(AArch64::JumpTableDest32, {TargetReg, ScratchReg},
2440 .addJumpTableIndex(JTI);
2448 bool AArch64InstructionSelector::selectJumpTable(
2450 assert(I.
getOpcode() == TargetOpcode::G_JUMP_TABLE &&
"Expected jump table");
2458 MIB.
buildInstr(AArch64::MOVaddrJT, {DstReg}, {})
2465 bool AArch64InstructionSelector::selectTLSGlobalValue(
2467 if (!STI.isTargetMachO())
2478 auto Load = MIB.
buildInstr(AArch64::LDRXui, {&AArch64::GPR64commonRegClass},
2496 bool AArch64InstructionSelector::selectIntrinsicTrunc(
2506 Opc = AArch64::FRINTZHr;
2509 Opc = AArch64::FRINTZSr;
2512 Opc = AArch64::FRINTZDr;
2522 Opc = AArch64::FRINTZv4f16;
2523 else if (NumElts == 8)
2524 Opc = AArch64::FRINTZv8f16;
2528 Opc = AArch64::FRINTZv2f32;
2529 else if (NumElts == 4)
2530 Opc = AArch64::FRINTZv4f32;
2534 Opc = AArch64::FRINTZv2f64;
2541 LLVM_DEBUG(
dbgs() <<
"Unsupported type for G_INTRINSIC_TRUNC!\n");
2551 bool AArch64InstructionSelector::selectIntrinsicRound(
2561 Opc = AArch64::FRINTAHr;
2564 Opc = AArch64::FRINTASr;
2567 Opc = AArch64::FRINTADr;
2577 Opc = AArch64::FRINTAv4f16;
2578 else if (NumElts == 8)
2579 Opc = AArch64::FRINTAv8f16;
2583 Opc = AArch64::FRINTAv2f32;
2584 else if (NumElts == 4)
2585 Opc = AArch64::FRINTAv4f32;
2589 Opc = AArch64::FRINTAv2f64;
2596 LLVM_DEBUG(
dbgs() <<
"Unsupported type for G_INTRINSIC_ROUND!\n");
2606 bool AArch64InstructionSelector::selectVectorICmp(
2637 unsigned PredIdx = 0;
2638 bool SwapOperands =
false;
2641 case CmpInst::ICMP_NE:
2642 case CmpInst::ICMP_EQ:
2645 case CmpInst::ICMP_UGT:
2648 case CmpInst::ICMP_UGE:
2651 case CmpInst::ICMP_ULT:
2653 SwapOperands =
true;
2655 case CmpInst::ICMP_ULE:
2657 SwapOperands =
true;
2659 case CmpInst::ICMP_SGT:
2662 case CmpInst::ICMP_SGE:
2665 case CmpInst::ICMP_SLT:
2667 SwapOperands =
true;
2669 case CmpInst::ICMP_SLE:
2671 SwapOperands =
true;
2681 static const unsigned OpcTable[4][4][9] = {
2689 {AArch64::CMEQv8i8, AArch64::CMHIv8i8, AArch64::CMHSv8i8,
2690 AArch64::CMHIv8i8, AArch64::CMHSv8i8, AArch64::CMGTv8i8,
2691 AArch64::CMGEv8i8, AArch64::CMGTv8i8, AArch64::CMGEv8i8},
2692 {AArch64::CMEQv16i8, AArch64::CMHIv16i8, AArch64::CMHSv16i8,
2693 AArch64::CMHIv16i8, AArch64::CMHSv16i8, AArch64::CMGTv16i8,
2694 AArch64::CMGEv16i8, AArch64::CMGTv16i8, AArch64::CMGEv16i8}
2700 {AArch64::CMEQv4i16, AArch64::CMHIv4i16, AArch64::CMHSv4i16,
2701 AArch64::CMHIv4i16, AArch64::CMHSv4i16, AArch64::CMGTv4i16,
2702 AArch64::CMGEv4i16, AArch64::CMGTv4i16, AArch64::CMGEv4i16},
2703 {AArch64::CMEQv8i16, AArch64::CMHIv8i16, AArch64::CMHSv8i16,
2704 AArch64::CMHIv8i16, AArch64::CMHSv8i16, AArch64::CMGTv8i16,
2705 AArch64::CMGEv8i16, AArch64::CMGTv8i16, AArch64::CMGEv8i16},
2711 {AArch64::CMEQv2i32, AArch64::CMHIv2i32, AArch64::CMHSv2i32,
2712 AArch64::CMHIv2i32, AArch64::CMHSv2i32, AArch64::CMGTv2i32,
2713 AArch64::CMGEv2i32, AArch64::CMGTv2i32, AArch64::CMGEv2i32},
2714 {AArch64::CMEQv4i32, AArch64::CMHIv4i32, AArch64::CMHSv4i32,
2715 AArch64::CMHIv4i32, AArch64::CMHSv4i32, AArch64::CMGTv4i32,
2716 AArch64::CMGEv4i32, AArch64::CMGTv4i32, AArch64::CMGEv4i32},
2725 {AArch64::CMEQv2i64, AArch64::CMHIv2i64, AArch64::CMHSv2i64,
2726 AArch64::CMHIv2i64, AArch64::CMHSv2i64, AArch64::CMGTv2i64,
2727 AArch64::CMGEv2i64, AArch64::CMGTv2i64, AArch64::CMGEv2i64},
2739 unsigned EltIdx =
Log2_32(SrcEltSize / 8);
2740 unsigned NumEltsIdx =
Log2_32(NumElts / 2);
2741 unsigned Opc = OpcTable[EltIdx][NumEltsIdx][PredIdx];
2749 getRegClassForTypeOnBank(SrcTy, VecRB, RBI,
true);
2751 LLVM_DEBUG(
dbgs() <<
"Could not determine source register class.\n");
2755 unsigned NotOpc = Pred == ICmpInst::ICMP_NE ? AArch64::NOTv8i8 : 0;
2757 NotOpc = NotOpc ? AArch64::NOTv16i8 : 0;
2763 auto Cmp = MIB.
buildInstr(Opc, {SrcRC}, {SrcReg, Src2Reg});
2768 Cmp = MIB.
buildInstr(NotOpc, {DstReg}, {Cmp});
2778 MachineInstr *AArch64InstructionSelector::emitScalarToVector(
2781 auto Undef = MIRBuilder.
buildInstr(TargetOpcode::IMPLICIT_DEF, {DstRC}, {});
2783 auto BuildFn = [&](
unsigned SubregIndex) {
2787 .addImm(SubregIndex);
2795 return BuildFn(AArch64::hsub);
2797 return BuildFn(AArch64::ssub);
2799 return BuildFn(AArch64::dsub);
2807 assert(I.
getOpcode() == TargetOpcode::G_MERGE_VALUES &&
"unexpected opcode");
2810 assert(!DstTy.isVector() && !SrcTy.
isVector() &&
"invalid merge operation");
2817 if (DstTy == LLT::scalar(128)) {
2824 auto Tmp = MIB.
buildInstr(TargetOpcode::IMPLICIT_DEF, {DstTy}, {});
2826 emitLaneInsert(
None, Tmp.getReg(0), Src1Reg, 0, RB, MIB);
2830 Src2Reg, 1, RB, MIB);
2839 if (RB.getID() != AArch64::GPRRegBankID)
2842 if (DstTy.getSizeInBits() != 64 || SrcTy.
getSizeInBits() != 32)
2845 auto *DstRC = &AArch64::GPR64RegClass;
2848 TII.get(TargetOpcode::SUBREG_TO_REG))
2849 .addDef(SubToRegDef)
2852 .addImm(AArch64::sub_32);
2856 TII.get(TargetOpcode::SUBREG_TO_REG))
2857 .addDef(SubToRegDef2)
2860 .addImm(AArch64::sub_32);
2864 .addUse(SubToRegDef)
2876 const unsigned EltSize) {
2881 CopyOpc = AArch64::CPYi16;
2882 ExtractSubReg = AArch64::hsub;
2885 CopyOpc = AArch64::CPYi32;
2886 ExtractSubReg = AArch64::ssub;
2889 CopyOpc = AArch64::CPYi64;
2890 ExtractSubReg = AArch64::dsub;
2894 LLVM_DEBUG(
dbgs() <<
"Elt size '" << EltSize <<
"' unsupported.\n");
2900 MachineInstr *AArch64InstructionSelector::emitExtractVectorElt(
2904 unsigned CopyOpc = 0;
2905 unsigned ExtractSubReg = 0;
2908 dbgs() <<
"Couldn't determine lane copy opcode for instruction.\n");
2913 getRegClassForTypeOnBank(ScalarTy, DstRB, RBI,
true);
2915 LLVM_DEBUG(
dbgs() <<
"Could not determine destination register class.\n");
2922 getRegClassForTypeOnBank(VecTy, VecRB, RBI,
true);
2924 LLVM_DEBUG(
dbgs() <<
"Could not determine source register class.\n");
2934 auto Copy = MIRBuilder.
buildInstr(TargetOpcode::COPY, {*DstReg}, {})
2935 .addReg(VecReg, 0, ExtractSubReg);
2945 VecTy.
getSizeInBits(), &AArch64::FPR128RegClass, VecReg, MIRBuilder);
2946 if (!ScalarToVector)
2952 MIRBuilder.
buildInstr(CopyOpc, {*DstReg}, {InsertReg}).addImm(LaneIdx);
2960 bool AArch64InstructionSelector::selectExtractElt(
2963 "unexpected opcode!");
2970 "source register size too small!");
2971 assert(NarrowTy.
isScalar() &&
"cannot extract vector into vector!");
2975 assert(LaneIdxOp.isReg() &&
"Lane index operand was not a register?");
2986 unsigned LaneIdx = VRegAndVal->Value;
2991 MachineInstr *Extract = emitExtractVectorElt(DstReg, DstRB, NarrowTy, SrcReg,
2992 LaneIdx, MIRBuilder);
3000 bool AArch64InstructionSelector::selectSplitVectorUnmerge(
3007 assert(NarrowTy.
isVector() &&
"Expected an unmerge into vectors");
3009 LLVM_DEBUG(
dbgs() <<
"Unexpected vector type for vec split unmerge");
3019 for (
unsigned OpIdx = 0; OpIdx < NumElts; ++OpIdx) {
3022 emitExtractVectorElt(Dst, DstRB, NarrowTy, SrcReg, OpIdx, MIB);
3033 "unexpected opcode");
3037 AArch64::FPRRegBankID ||
3039 AArch64::FPRRegBankID) {
3040 LLVM_DEBUG(
dbgs() <<
"Unmerging vector-to-gpr and scalar-to-scalar " 3041 "currently unsupported.\n");
3053 "can only unmerge from vector or s128 types!");
3055 "source register size too small!");
3058 return selectSplitVectorUnmerge(I, MRI);
3064 unsigned CopyOpc = 0;
3065 unsigned ExtractSubReg = 0;
3076 unsigned NumInsertRegs = NumElts - 1;
3086 for (
unsigned Idx = 0; Idx < NumInsertRegs; ++Idx) {
3096 TII.get(TargetOpcode::INSERT_SUBREG), InsertReg)
3114 auto FirstCopy = MIB.
buildInstr(TargetOpcode::COPY, {CopyTo}, {})
3115 .addReg(InsertRegs[0], 0, ExtractSubReg);
3119 unsigned LaneIdx = 1;
3120 for (
Register InsReg : InsertRegs) {
3145 bool AArch64InstructionSelector::selectConcatVectors(
3148 "Unexpected opcode");
3153 MachineInstr *ConcatMI = emitVectorConcat(Dst, Op1, Op2, MIRBuilder);
3161 AArch64InstructionSelector::emitConstantPoolEntry(
Constant *CPVal,
3172 MachineInstr *AArch64InstructionSelector::emitLoadFromConstantPool(
3174 unsigned CPIdx = emitConstantPoolEntry(CPVal, MIRBuilder.
getMF());
3185 .
buildInstr(AArch64::LDRQui, {&AArch64::FPR128RegClass}, {Adrp})
3186 .addConstantPoolIndex(CPIdx, 0,
3190 LoadMI = &*MIRBuilder
3191 .
buildInstr(AArch64::LDRDui, {&AArch64::FPR64RegClass}, {Adrp})
3192 .addConstantPoolIndex(
3196 LLVM_DEBUG(
dbgs() <<
"Could not load from constant pool of type " 3207 static std::pair<unsigned, unsigned>
3209 unsigned Opc, SubregIdx;
3210 if (RB.
getID() == AArch64::GPRRegBankID) {
3211 if (EltSize == 32) {
3212 Opc = AArch64::INSvi32gpr;
3213 SubregIdx = AArch64::ssub;
3214 }
else if (EltSize == 64) {
3215 Opc = AArch64::INSvi64gpr;
3216 SubregIdx = AArch64::dsub;
3222 Opc = AArch64::INSvi8lane;
3223 SubregIdx = AArch64::bsub;
3224 }
else if (EltSize == 16) {
3225 Opc = AArch64::INSvi16lane;
3226 SubregIdx = AArch64::hsub;
3227 }
else if (EltSize == 32) {
3228 Opc = AArch64::INSvi32lane;
3229 SubregIdx = AArch64::ssub;
3230 }
else if (EltSize == 64) {
3231 Opc = AArch64::INSvi64lane;
3232 SubregIdx = AArch64::dsub;
3237 return std::make_pair(Opc, SubregIdx);
3244 assert(LHS.
isReg() && RHS.
isReg() &&
"Expected LHS and RHS to be registers!");
3246 static const unsigned OpcTable[2][2]{{AArch64::ADDXrr, AArch64::ADDXri},
3247 {AArch64::ADDWrr, AArch64::ADDWri}};
3249 auto ImmFns = selectArithImmed(RHS);
3250 unsigned Opc = OpcTable[Is32Bit][ImmFns.hasValue()];
3255 for (
auto &RenderFn : *ImmFns)
3258 AddMI.addUse(RHS.
getReg());
3268 assert(LHS.
isReg() && RHS.
isReg() &&
"Expected LHS and RHS to be registers!");
3270 static const unsigned OpcTable[2][2]{{AArch64::ADDSXrr, AArch64::ADDSXri},
3271 {AArch64::ADDSWrr, AArch64::ADDSWri}};
3273 auto ImmFns = selectArithImmed(RHS);
3274 unsigned Opc = OpcTable[Is32Bit][ImmFns.hasValue()];
3275 Register ZReg = Is32Bit ? AArch64::WZR : AArch64::XZR;
3281 for (
auto &RenderFn : *ImmFns)
3284 CmpMI.addUse(RHS.
getReg());
3292 AArch64InstructionSelector::emitTST(
const Register &LHS,
const Register &RHS,
3296 bool Is32Bit = (RegSize == 32);
3297 static const unsigned OpcTable[2][2]{{AArch64::ANDSXrr, AArch64::ANDSXri},
3298 {AArch64::ANDSWrr, AArch64::ANDSWri}};
3299 Register ZReg = Is32Bit ? AArch64::WZR : AArch64::XZR;
3304 bool IsImmForm = ValAndVReg.hasValue() &&
3306 unsigned Opc = OpcTable[Is32Bit][IsImmForm];
3307 auto TstMI = MIRBuilder.
buildInstr(Opc, {ZReg}, {LHS});
3319 MachineInstr *AArch64InstructionSelector::emitIntegerCompare(
3322 assert(LHS.
isReg() && RHS.
isReg() &&
"Expected LHS and RHS to be registers!");
3327 tryFoldIntegerCompare(LHS, RHS, Predicate, MIRBuilder);
3332 unsigned CmpOpc = 0;
3337 "Expected scalar or pointer");
3338 if (CmpTy == LLT::scalar(32)) {
3339 CmpOpc = AArch64::SUBSWrr;
3340 ZReg = AArch64::WZR;
3341 }
else if (CmpTy == LLT::scalar(64) || CmpTy.
isPointer()) {
3342 CmpOpc = AArch64::SUBSXrr;
3343 ZReg = AArch64::XZR;
3349 auto ImmFns = selectArithImmed(RHS);
3351 CmpOpc = CmpOpc == AArch64::SUBSWrr ? AArch64::SUBSWri : AArch64::SUBSXri;
3356 for (
auto &RenderFn : *ImmFns)
3359 CmpMI.addUse(RHS.
getReg());
3367 MachineInstr *AArch64InstructionSelector::emitVectorConcat(
3379 if (Op1Ty != Op2Ty) {
3380 LLVM_DEBUG(
dbgs() <<
"Could not do vector concat of differing vector tys");
3383 assert(Op1Ty.
isVector() &&
"Expected a vector for vector concat");
3386 LLVM_DEBUG(
dbgs() <<
"Vector concat not supported for full size vectors");
3402 emitScalarToVector(ScalarTy.
getSizeInBits(), DstRC, Op1, MIRBuilder);
3404 emitScalarToVector(ScalarTy.
getSizeInBits(), DstRC, Op2, MIRBuilder);
3405 if (!WidenedOp1 || !WidenedOp2) {
3406 LLVM_DEBUG(
dbgs() <<
"Could not emit a vector from scalar value");
3411 unsigned InsertOpc, InsSubRegIdx;
3412 std::tie(InsertOpc, InsSubRegIdx) =
3419 .
buildInstr(InsertOpc, {*Dst}, {WidenedOp1->getOperand(0).getReg()})
3421 .
addUse(WidenedOp2->getOperand(0).getReg())
3427 MachineInstr *AArch64InstructionSelector::emitFMovForFConstant(
3430 "Expected a G_FCONSTANT!");
3435 if (DefSize != 32 && DefSize != 64)
3439 if (ImmOp.getFPImm()->isNullValue())
3443 const APFloat &ImmValAPF = ImmOp.getFPImm()->getValueAPF();
3453 ImmOp.ChangeToImmediate(Imm);
3454 unsigned MovOpc = DefSize == 32 ? AArch64::FMOVSi : AArch64::FMOVDi;
3461 AArch64InstructionSelector::emitCSetForICMP(
Register DefReg,
unsigned Pred,
3474 bool AArch64InstructionSelector::tryOptSelect(
MachineInstr &I)
const {
3506 if (Opc != TargetOpcode::COPY && Opc != TargetOpcode::G_TRUNC)
3510 if (Opc == TargetOpcode::COPY &&
3521 unsigned CondOpc = CondDef->
getOpcode();
3522 if (CondOpc != TargetOpcode::G_ICMP && CondOpc != TargetOpcode::G_FCMP)
3526 if (CondOpc == TargetOpcode::G_ICMP) {
3555 if (CmpOpc != AArch64::FCMPSri && CmpOpc != AArch64::FCMPDri)
3571 MachineInstr *AArch64InstructionSelector::tryFoldIntegerCompare(
3575 "Unexpected MachineOperand");
3589 if (!DefMI || DefMI->
getOpcode() != TargetOpcode::G_SUB)
3597 if (DefMI->
getOpcode() != TargetOpcode::G_SUB)
3604 if (!ValAndVReg || ValAndVReg->Value != 0)
3625 if (IsCMN(LHSDef, CC))
3626 return emitCMN(LHSDef->
getOperand(2), RHS, MIRBuilder);
3638 if (IsCMN(RHSDef, CC))
3639 return emitCMN(LHS, RHSDef->getOperand(2), MIRBuilder);
3650 LHSDef->
getOpcode() == TargetOpcode::G_AND) {
3653 if (!ValAndVReg || ValAndVReg->Value != 0)
3663 bool AArch64InstructionSelector::tryOptVectorDup(
MachineInstr &I)
const {
3680 using namespace TargetOpcode;
3681 using namespace MIPatternMatch;
3694 Register ScalarReg = InsMI->getOperand(2).getReg();
3703 if (!
all_of(Mask, [](
int Elem) {
return Elem == 0; }))
3710 LLVM_DEBUG(
dbgs() <<
"Could not optimize splat pattern < 32b elts yet");
3713 bool IsFP = ScalarRB->
getID() == AArch64::FPRRegBankID;
3719 Opc = AArch64::DUPv2i32lane;
3721 Opc = AArch64::DUPv4i32lane;
3727 Opc = AArch64::DUPv2i64lane;
3734 Opc = AArch64::DUPv2i32gpr;
3736 Opc = AArch64::DUPv4i32gpr;
3742 Opc = AArch64::DUPv2i64gpr;
3746 assert(Opc &&
"Did not compute an opcode for a dup");
3751 EltTy.
getSizeInBits(), &AArch64::FPR128RegClass, ScalarReg, MIB);
3764 bool AArch64InstructionSelector::tryOptVectorShuffle(
MachineInstr &I)
const {
3767 if (tryOptVectorDup(I))
3772 bool AArch64InstructionSelector::selectShuffleVector(
3774 if (tryOptVectorShuffle(I))
3791 LLVM_DEBUG(
dbgs() <<
"Could not select a \"scalar\" G_SHUFFLE_VECTOR\n");
3798 for (
int Val : Mask) {
3801 Val = Val < 0 ? 0 : Val;
3802 for (
unsigned Byte = 0; Byte < BytesPerElt; ++Byte) {
3803 unsigned Offset = Byte + Val * BytesPerElt;
3804 CstIdxs.
emplace_back(ConstantInt::get(Type::getInt8Ty(Ctx), Offset));
3811 Constant *CPVal = ConstantVector::get(CstIdxs);
3812 MachineInstr *IndexLoad = emitLoadFromConstantPool(CPVal, MIRBuilder);
3829 emitScalarToVector(64, &AArch64::FPR128RegClass,
3833 AArch64::TBLv16i8One, {&AArch64::FPR128RegClass},
3840 .addReg(TBL1.getReg(0), 0, AArch64::dsub);
3848 auto RegSeq = MIRBuilder
3850 {&AArch64::QQRegClass}, {Src1Reg})
3851 .addImm(AArch64::qsub0)
3864 MachineInstr *AArch64InstructionSelector::emitLaneInsert(
3879 if (RB.
getID() == AArch64::FPRRegBankID) {
3880 auto InsSub = emitScalarToVector(EltSize, DstRC, EltReg, MIRBuilder);
3881 InsElt = MIRBuilder.
buildInstr(Opc, {*DstReg}, {SrcReg})
3883 .
addUse(InsSub->getOperand(0).getReg())
3886 InsElt = MIRBuilder.
buildInstr(Opc, {*DstReg}, {SrcReg})
3895 bool AArch64InstructionSelector::selectInsertElt(
3908 if (EltSize < 16 || EltSize > 64)
3917 unsigned LaneIdx = VRegAndVal->Value;
3924 if (VecSize < 128) {
3928 VecSize, &AArch64::FPR128RegClass, SrcReg, MIRBuilder);
3938 emitLaneInsert(
None, SrcReg, EltReg, LaneIdx, EltRB, MIRBuilder);
3940 if (VecSize < 128) {
3946 if (RC != &AArch64::FPR32RegClass && RC != &AArch64::FPR64RegClass) {
3953 if (SubReg != AArch64::ssub && SubReg != AArch64::dsub) {
3954 LLVM_DEBUG(
dbgs() <<
"Unsupported destination size! (" << VecSize
3958 MIRBuilder.
buildInstr(TargetOpcode::COPY, {DstReg}, {})
3959 .addReg(DemoteVec, 0, SubReg);
3971 bool AArch64InstructionSelector::selectBuildVector(
3979 if (EltSize < 16 || EltSize > 64)
3986 emitScalarToVector(DstTy.getElementType().getSizeInBits(), DstRC,
3992 unsigned DstSize = DstTy.getSizeInBits();
3997 for (
unsigned i = 2,
e = DstSize / EltSize + 1; i <
e; ++i) {
4007 if (DstSize < 128) {
4013 if (RC != &AArch64::FPR32RegClass && RC != &AArch64::FPR64RegClass) {
4021 if (SubReg != AArch64::ssub && SubReg != AArch64::dsub) {
4022 LLVM_DEBUG(
dbgs() <<
"Unsupported destination size! (" << DstSize
4030 MIRBuilder.
buildInstr(TargetOpcode::COPY, {DstReg}, {})
4031 .addReg(DstVec, 0, SubReg);
4038 assert(PrevMI &&
"PrevMI was null?");
4051 return Op.isIntrinsicID();
4055 return IntrinOp->getIntrinsicID();
4058 bool AArch64InstructionSelector::selectIntrinsicWithSideEffects(
4070 case Intrinsic::trap:
4071 MIRBuilder.
buildInstr(AArch64::BRK, {}, {}).addImm(1);
4073 case Intrinsic::debugtrap:
4074 if (!STI.isTargetWindows())
4076 MIRBuilder.
buildInstr(AArch64::BRK, {}, {}).addImm(0xF000);
4084 bool AArch64InstructionSelector::selectIntrinsic(
4094 case Intrinsic::aarch64_crypto_sha1h:
4111 AArch64::GPR32RegClass,
MRI);
4118 auto SHA1Inst = MIRBuilder.
buildInstr(AArch64::SHA1Hrr, {DstReg}, {SrcReg});
4127 AArch64::GPR32RegClass,
MRI);
4138 auto &MBB = *
MI.getParent();
4139 auto &MF = *MBB.getParent();
4146 else if (Root.
isReg()) {
4151 Immed = ValAndVReg->Value;
4158 AArch64InstructionSelector::selectShiftA_32(
const MachineOperand &Root)
const {
4160 if (MaybeImmed ==
None || *MaybeImmed > 31)
4162 uint64_t Enc = (32 - *MaybeImmed) & 0x1f;
4167 AArch64InstructionSelector::selectShiftB_32(
const MachineOperand &Root)
const {
4169 if (MaybeImmed ==
None || *MaybeImmed > 31)
4171 uint64_t Enc = 31 - *MaybeImmed;
4176 AArch64InstructionSelector::selectShiftA_64(
const MachineOperand &Root)
const {
4178 if (MaybeImmed ==
None || *MaybeImmed > 63)
4180 uint64_t Enc = (64 - *MaybeImmed) & 0x3f;
4185 AArch64InstructionSelector::selectShiftB_64(
const MachineOperand &Root)
const {
4187 if (MaybeImmed ==
None || *MaybeImmed > 63)
4189 uint64_t Enc = 63 - *MaybeImmed;
4199 AArch64InstructionSelector::select12BitValueWithLeftShift(
4200 uint64_t Immed)
const {
4202 if (Immed >> 12 == 0) {
4204 }
else if ((Immed & 0xfff) == 0 && Immed >> 24 == 0) {
4206 Immed = Immed >> 12;
4221 AArch64InstructionSelector::selectArithImmed(
MachineOperand &Root)
const {
4228 if (MaybeImmed ==
None)
4230 return select12BitValueWithLeftShift(*MaybeImmed);
4236 AArch64InstructionSelector::selectNegArithImmed(
MachineOperand &Root)
const {
4242 if (MaybeImmed ==
None)
4244 uint64_t Immed = *MaybeImmed;
4258 Immed = ~Immed + 1ULL;
4260 if (Immed & 0xFFFFFFFFFF000000ULL)
4263 Immed &= 0xFFFFFFULL;
4264 return select12BitValueWithLeftShift(Immed);
4270 bool AArch64InstructionSelector::isWorthFoldingIntoExtendedReg(
4280 if (!STI.hasLSLFast())
4291 AArch64InstructionSelector::selectExtendedSHL(
4293 unsigned SizeInBytes,
bool WantsExt)
const {
4294 assert(Base.
isReg() &&
"Expected base to be a register operand");
4295 assert(Offset.
isReg() &&
"Expected offset to be a register operand");
4302 unsigned OffsetOpc = OffsetInst->
getOpcode();
4303 if (OffsetOpc != TargetOpcode::G_SHL && OffsetOpc != TargetOpcode::G_MUL)
4307 int64_t LegalShiftVal =
Log2_32(SizeInBytes);
4308 if (LegalShiftVal == 0)
4310 if (!isWorthFoldingIntoExtendedReg(*OffsetInst, MRI))
4322 if (OffsetOpc == TargetOpcode::G_SHL)
4334 int64_t ImmVal = ValAndVReg->Value;
4338 if (OffsetOpc == TargetOpcode::G_MUL) {
4346 if ((ImmVal & 0x7) != ImmVal)
4351 if (ImmVal != LegalShiftVal)
4354 unsigned SignExtend = 0;
4358 auto Ext = getExtendTypeForInst(*ExtInst, MRI,
true);
4367 OffsetReg = narrowExtendRegIfNeeded(OffsetReg, MIB);
4377 MIB.addImm(SignExtend);
4391 AArch64InstructionSelector::selectAddrModeShiftedExtendXReg(
4411 if (!PtrAdd || !isWorthFoldingIntoExtendedReg(*PtrAdd, MRI))
4418 return selectExtendedSHL(Root, PtrAdd->
getOperand(1),
4432 AArch64InstructionSelector::selectAddrModeRegisterOffset(
4438 if (!Gep || Gep->
getOpcode() != TargetOpcode::G_PTR_ADD)
4465 AArch64InstructionSelector::selectAddrModeXRO(
MachineOperand &Root,
4466 unsigned SizeInBytes)
const {
4471 if (isBaseWithConstantOffset(Root, MRI))
4475 auto AddrModeFns = selectAddrModeShiftedExtendXReg(Root, SizeInBytes);
4481 return selectAddrModeRegisterOffset(Root);
4491 AArch64InstructionSelector::selectAddrModeWRO(
MachineOperand &Root,
4492 unsigned SizeInBytes)
const {
4497 if (!PtrAdd || !isWorthFoldingIntoExtendedReg(*PtrAdd, MRI))
4519 auto ExtendedShl = selectExtendedSHL(Root, LHS, OffsetInst->
getOperand(0),
4528 if (!isWorthFoldingIntoExtendedReg(*OffsetInst, MRI))
4533 getExtendTypeForInst(*OffsetInst, MRI,
true);
4547 MIB.addImm(SignExtend);
4558 AArch64InstructionSelector::selectAddrModeUnscaled(
MachineOperand &Root,
4559 unsigned Size)
const {
4566 if (!isBaseWithConstantOffset(Root, MRI))
4574 if (!OffImm.
isReg())
4577 if (!RHS || RHS->
getOpcode() != TargetOpcode::G_CONSTANT)
4586 if ((RHSC & (Size - 1)) == 0 && RHSC >= 0 && RHSC < (0x1000 <<
Log2_32(Size)))
4588 if (RHSC >= -256 && RHSC < 256) {
4602 AArch64InstructionSelector::selectAddrModeIndexed(
MachineOperand &Root,
4603 unsigned Size)
const {
4614 if (RootDef->
getOpcode() == TargetOpcode::G_FRAME_INDEX) {
4621 if (isBaseWithConstantOffset(Root, MRI)) {
4626 if (LHSDef && RHSDef) {
4628 unsigned Scale =
Log2_32(Size);
4629 if ((RHSC & (Size - 1)) == 0 && RHSC >= 0 && RHSC < (0x1000 << Scale)) {
4630 if (LHSDef->
getOpcode() == TargetOpcode::G_FRAME_INDEX)
4646 if (selectAddrModeUnscaled(Root, Size).hasValue())
4662 case TargetOpcode::G_SHL:
4664 case TargetOpcode::G_LSHR:
4666 case TargetOpcode::G_ASHR:
4676 AArch64InstructionSelector::selectShiftedRegister(
MachineOperand &Root)
const {
4692 if (!isWorthFoldingIntoExtendedReg(*ShiftInst, MRI))
4707 unsigned Val = *Immed & (NumBits - 1);
4719 if (Opc == TargetOpcode::G_SEXT || Opc == TargetOpcode::G_SEXT_INREG) {
4721 assert(Size != 64 &&
"Extend from 64 bits?");
4734 if (Opc == TargetOpcode::G_ZEXT || Opc == TargetOpcode::G_ANYEXT) {
4736 assert(Size != 64 &&
"Extend from 64 bits?");
4751 if (Opc != TargetOpcode::G_AND)
4757 uint64_t AndMask = *MaybeAndMask;
4770 Register AArch64InstructionSelector::narrowExtendRegIfNeeded(
4778 auto Copy = MIB.
buildCopy({NarrowReg}, {ExtReg});
4782 return Copy.getReg(0);
4788 AArch64InstructionSelector::selectArithExtendedRegister(
4795 uint64_t ShiftVal = 0;
4802 if (!isWorthFoldingIntoExtendedReg(*RootDef, MRI))
4806 if (RootDef->
getOpcode() == TargetOpcode::G_SHL) {
4812 ShiftVal = *MaybeShiftVal;
4820 Ext = getExtendTypeForInst(*ExtDef, MRI);
4826 Ext = getExtendTypeForInst(*RootDef, MRI);
4837 if (ExtInst && isDef32(*ExtInst))
4845 ExtReg = narrowExtendRegIfNeeded(ExtReg, MIB);
4858 "Expected G_CONSTANT");
4860 assert(CstVal &&
"Expected constant value");
4861 MIB.
addImm(CstVal.getValue());
4864 void AArch64InstructionSelector::renderLogicalImm32(
4867 "Expected G_CONSTANT");
4873 void AArch64InstructionSelector::renderLogicalImm64(
4876 "Expected G_CONSTANT");
4882 bool AArch64InstructionSelector::isLoadStoreOfNumBytes(
4887 "Expected load/store to have only one mem op!");
4891 bool AArch64InstructionSelector::isDef32(
const MachineInstr &MI)
const {
4903 case TargetOpcode::COPY:
4904 case TargetOpcode::G_BITCAST:
4905 case TargetOpcode::G_TRUNC:
4906 case TargetOpcode::G_PHI:
4916 return new AArch64InstructionSelector(TM, Subtarget, RBI);
ArrayRef< int > getShuffleMask() const
static std::pair< const TargetRegisterClass *, const TargetRegisterClass * > getRegClassesForCopy(MachineInstr &I, const TargetInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Helper function to get the source and destination register classes for a copy.
reference emplace_back(ArgTypes &&... Args)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
mop_iterator operands_end()
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
MO_G3 - A symbol operand with this flag (granule 3) represents the high 16-bits of a 64-bit address...
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
uint64_t getZExtValue() const
Get zero extended value.
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
MachineBasicBlock * getMBB() const
static std::pair< unsigned, unsigned > getInsertVecEltOpInfo(const RegisterBank &RB, unsigned EltSize)
Return an <Opcode, SubregIndex> pair to do an vector elt insert of a given size and RB...
static bool selectMergeValues(MachineInstrBuilder &MIB, const ARMBaseInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
This class represents lattice values for constants.
MO_PAGE - A symbol operand with this flag represents the pc-relative offset of the 4K page containing...
void setTargetFlags(unsigned F)
virtual void setupMF(MachineFunction &mf, GISelKnownBits &KB, CodeGenCoverage &covinfo)
Setup per-MF selector state.
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
int getVarArgsStackIndex() const
unsigned getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
const ConstantFP * getConstantFPVRegVal(unsigned VReg, const MachineRegisterInfo &MRI)
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
static CondCode getInvertedCondCode(CondCode Code)
const MachineInstrBuilder & addJumpTableIndex(unsigned Idx, unsigned TargetFlags=0) const
static uint64_t selectImpl(uint64_t CandidateMask, uint64_t &NextInSequenceMask)
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
uint64_t getSize() const
Return the size in bytes of the memory reference.
bool mayLoadOrStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read or modify memory.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
unsigned const TargetRegisterInfo * TRI
MO_G0 - A symbol operand with this flag (granule 0) represents the bits 0-15 of a 64-bit address...
void setRegBank(unsigned Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
iterator_range< mop_iterator > operands()
static const TargetRegisterClass * getMinClassForRegBank(const RegisterBank &RB, unsigned SizeInBits, bool GetAllRegSet=false)
Given a register bank, and size in bits, return the smallest register class that can represent that c...
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
T get() const
Returns the value of the specified pointer type.
MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
unsigned getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
MO_G2 - A symbol operand with this flag (granule 2) represents the bits 32-47 of a 64-bit address...
This file declares the targeting of the RegisterBankInfo class for AArch64.
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwises returns null...
Holds all the information related to register banks.
A description of a memory reference used in the backend.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
const HexagonInstrInfo * TII
const ConstantFP * getFPImm() const
unsigned getNumOperands() const
Retuns the total number of operands.
A Use represents the edge between a Value definition and its users.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
static StringRef getName(Value *V)
static bool isLogicalImmediate(uint64_t imm, unsigned regSize)
isLogicalImmediate - Return true if the immediate is valid for a logical immediate instruction of the...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
static Optional< int64_t > getVectorSHLImm(LLT SrcTy, Register Reg, MachineRegisterInfo &MRI)
Matches and returns the shift immediate value for a SHL instruction given a shift operand...
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
Type * getType() const
All values are typed, get the type of this value.
MO_GOT - This flag indicates that a symbol operand represents the address of the GOT entry for the sy...
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
const RegClassOrRegBank & getRegClassOrRegBank(unsigned Reg) const
Return the register bank or register class of Reg.
bool isNegative() const
Return true if the sign bit is set.
static bool isStore(int Opcode)
MachineFunction & getMF()
Getter for the function we currently build.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
static bool isUnsignedICMPPred(const CmpInst::Predicate P)
Returns true if P is an unsigned integer comparison predicate.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
void setReg(Register Reg)
Change the register this operand corresponds to.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
static unsigned getShifterImm(AArch64_AM::ShiftExtendType ST, unsigned Imm)
getShifterImm - Encode the shift type and amount: imm: 6-bit shift amount shifter: 000 ==> lsl 001 ==...
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
TargetInstrInfo - Interface to description of machine instruction set.
static bool selectSubregisterCopy(MachineInstr &I, MachineRegisterInfo &MRI, const RegisterBankInfo &RBI, Register SrcReg, const TargetRegisterClass *From, const TargetRegisterClass *To, unsigned SubReg)
Helper function for selectCopy.
static unsigned selectBinaryOp(unsigned GenericOpc, unsigned RegBankID, unsigned OpSize)
Select the AArch64 opcode for the basic binary operation GenericOpc (such as G_OR or G_SDIV)...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
MachineRegisterInfo * getMRI()
Getter for MRI.
Control flow instructions. These all have token chains.
const TargetRegisterInfo * getTargetRegisterInfo() const
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
MO_G1 - A symbol operand with this flag (granule 1) represents the bits 16-31 of a 64-bit address...
static bool getLaneCopyOpcode(unsigned &CopyOpc, unsigned &ExtractSubReg, const unsigned EltSize)
unsigned const MachineRegisterInfo * MRI
static int getFP32Imm(const APInt &Imm)
getFP32Imm - Return an 8-bit floating-point version of the 32-bit floating-point value.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
static unsigned selectLoadStoreUIOp(unsigned GenericOpc, unsigned RegBankID, unsigned OpSize)
Select the AArch64 opcode for the G_LOAD or G_STORE operation GenericOpc, appropriate for the (value)...
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
static unsigned selectFPConvOpc(unsigned GenericOpc, LLT DstTy, LLT SrcTy)
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
This is an important base class in LLVM.
static Optional< int64_t > getVectorShiftImm(Register Reg, MachineRegisterInfo &MRI)
Returns the element immediate value of a vector shift operand if found.
const GlobalValue * getGlobal() const
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
ConstantFP - Floating Point Values [float, double].
Helper class to build MachineInstr.
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
void setImm(int64_t immVal)
static bool selectUnmergeValues(MachineInstrBuilder &MIB, const ARMBaseInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
self_iterator getIterator()
Optional< ValueAndVReg > getConstantVRegValWithLookThrough(unsigned VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true, bool HandleFConstants=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_F/CONSTANT (LookThro...
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
const MachineInstrBuilder & addFrameIndex(int Idx) const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MachineInstr * getOpcodeDef(unsigned Opcode, Register Reg, const MachineRegisterInfo &MRI)
See if Reg is defined by an single def instruction that is Opcode.
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
MO_TLS - Indicates that the operand being accessed is some kind of thread-local symbol.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static SDValue Widen(SelectionDAG *CurDAG, SDValue N)
#define GET_GLOBALISEL_TEMPORARIES_INIT
const APFloat & getValueAPF() const
static Optional< uint64_t > getImmedFromMO(const MachineOperand &Root)
static uint64_t encodeLogicalImmediate(uint64_t imm, unsigned regSize)
encodeLogicalImmediate - Return the encoded immediate value for a logical immediate instruction of th...
static int getFP64Imm(const APInt &Imm)
getFP64Imm - Return an 8-bit floating-point version of the 64-bit floating-point value.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
BlockVerifier::State From
void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
MachineInstrBuilder MachineInstrBuilder & DefMI
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Promote Memory to Register
bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
void setAdjustsStack(bool V)
This class implements the register bank concept.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
This file declares the MachineIRBuilder class.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static bool isValidCopy(const MachineInstr &I, const RegisterBank &DstBank, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Helper function that verifies that we have a valid copy at the end of selectCopy. ...
Optional< int64_t > getConstantVRegVal(unsigned VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT fits in int64_t returns it.
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Provides the logic to select generic machine instructions.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
This class provides the information for the target register banks.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
bool hasOneUse(unsigned RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
ConstantMatch m_ICst(int64_t &Cst)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static AArch64CC::CondCode changeICMPPredToAArch64CC(CmpInst::Predicate P)
bool isZero() const
Return true if the value is positive or negative zero.
InstructionSelector * createAArch64InstructionSelector(const AArch64TargetMachine &, AArch64Subtarget &, AArch64RegisterBankInfo &)
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
int64_t getOffset() const
Return the offset from the symbol in this operand.
const BlockAddress * getBlockAddress() const
static unsigned findIntrinsicID(MachineInstr &I)
Helper function to find an intrinsic ID on an a MachineInstr.
MO_PAGEOFF - A symbol operand with this flag represents the offset of that symbol within a 4K page...
void ChangeToRegister(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
ChangeToRegister - Replace this operand with a new register operand of the specified value...
void setSubReg(unsigned subReg)
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
#define GET_GLOBALISEL_PREDICATES_INIT
const DataLayout & getDataLayout() const
static unsigned selectSelectOpc(MachineInstr &I, MachineRegisterInfo &MRI, const RegisterBankInfo &RBI)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
iterator_range< use_instr_iterator > use_instructions(unsigned Reg) const
const TargetRegisterClass * getRegClassOrNull(unsigned Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void changeFCMPPredToAArch64CC(CmpInst::Predicate P, AArch64CC::CondCode &CondCode, AArch64CC::CondCode &CondCode2)
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel...
LLVM Value Representation.
static unsigned selectFCMPOpc(MachineInstr &I, MachineRegisterInfo &MRI)
Helper function to select the opcode for a G_FCMP.
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
void ChangeToFrameIndex(int Idx)
Replace this operand with a frame index.
static bool unsupportedBinOp(const MachineInstr &I, const AArch64RegisterBankInfo &RBI, const MachineRegisterInfo &MRI, const AArch64RegisterInfo &TRI)
Check whether I is a currently unsupported binary operation:
MO_NC - Indicates whether the linker is expected to check the symbol reference for overflow...
APInt bitcastToAPInt() const
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
Register getReg() const
getReg - Returns the register number.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
const MachineOperand & getOperand(unsigned i) const
static bool getSubRegForClass(const TargetRegisterClass *RC, const TargetRegisterInfo &TRI, unsigned &SubReg)
Returns the correct subregister to use for a given register class.
const ConstantInt * getCImm() const
static const TargetRegisterClass * constrainGenericRegister(Register Reg, const TargetRegisterClass &RC, MachineRegisterInfo &MRI)
Constrain the (possibly generic) virtual register Reg to RC.
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one...
static AArch64_AM::ShiftExtendType getShiftTypeForInst(MachineInstr &MI)
Given a shift instruction, return the correct shift type for that instruction.
bool constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
Wrapper class representing virtual and physical registers.
unsigned getID() const
Get the identifier of this register bank.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
unsigned getPredicate() const