26#include "llvm/IR/IntrinsicsRISCV.h"
29#define DEBUG_TYPE "riscv-isel"
34#define GET_GLOBALISEL_PREDICATE_BITSET
35#include "RISCVGenGlobalISel.inc"
36#undef GET_GLOBALISEL_PREDICATE_BITSET
58 static constexpr unsigned MaxRecursionDepth = 6;
61 const unsigned Depth = 0)
const;
91 bool IsExternWeak =
false)
const;
100 unsigned &CurOp,
bool IsMasked,
101 bool IsStridedOrIndexed,
102 LLT *IndexVT =
nullptr)
const;
109 unsigned ShiftWidth)
const;
110 ComplexRendererFns selectShiftMaskXLen(
MachineOperand &Root)
const {
111 return selectShiftMask(Root, STI.
getXLen());
113 ComplexRendererFns selectShiftMask32(
MachineOperand &Root)
const {
114 return selectShiftMask(Root, 32);
118 ComplexRendererFns selectAddrRegImmLsb00000(
MachineOperand &Root)
const;
123 struct ConstAddrPlan {
124 enum { X0, LUI, InstSeq } Kind = X0;
129 ComplexRendererFns computeConstAddr(int64_t CVal,
bool IsPrefetch,
134 const ConstAddrPlan &Plan,
137 ComplexRendererFns selectSExtBits(
MachineOperand &Root,
unsigned Bits)
const;
138 template <
unsigned Bits>
140 return selectSExtBits(Root, Bits);
143 ComplexRendererFns selectZExtBits(
MachineOperand &Root,
unsigned Bits)
const;
144 template <
unsigned Bits>
146 return selectZExtBits(Root, Bits);
149 ComplexRendererFns selectSHXADDOp(
MachineOperand &Root,
unsigned ShAmt)
const;
150 template <
unsigned ShAmt>
152 return selectSHXADDOp(Root, ShAmt);
156 unsigned ShAmt)
const;
157 template <
unsigned ShAmt>
158 ComplexRendererFns selectSHXADD_UWOp(
MachineOperand &Root)
const {
159 return selectSHXADD_UWOp(Root, ShAmt);
163 ComplexRendererFns renderAddiPair(
Register BaseReg, int64_t AddiImm,
164 int64_t OffsetImm)
const;
198#define GET_GLOBALISEL_PREDICATES_DECL
199#include "RISCVGenGlobalISel.inc"
200#undef GET_GLOBALISEL_PREDICATES_DECL
202#define GET_GLOBALISEL_TEMPORARIES_DECL
203#include "RISCVGenGlobalISel.inc"
204#undef GET_GLOBALISEL_TEMPORARIES_DECL
209#define GET_GLOBALISEL_IMPL
210#include "RISCVGenGlobalISel.inc"
211#undef GET_GLOBALISEL_IMPL
213RISCVInstructionSelector::RISCVInstructionSelector(
216 : STI(STI),
TII(*STI.getInstrInfo()),
TRI(*STI.getRegisterInfo()), RBI(RBI),
220#include
"RISCVGenGlobalISel.inc"
223#include
"RISCVGenGlobalISel.inc"
229bool RISCVInstructionSelector::hasAllNBitUsers(
const MachineInstr &
MI,
231 const unsigned Depth)
const {
233 assert((
MI.getOpcode() == TargetOpcode::G_ADD ||
234 MI.getOpcode() == TargetOpcode::G_SUB ||
235 MI.getOpcode() == TargetOpcode::G_MUL ||
236 MI.getOpcode() == TargetOpcode::G_SHL ||
237 MI.getOpcode() == TargetOpcode::G_LSHR ||
238 MI.getOpcode() == TargetOpcode::G_AND ||
239 MI.getOpcode() == TargetOpcode::G_OR ||
240 MI.getOpcode() == TargetOpcode::G_XOR ||
241 MI.getOpcode() == TargetOpcode::G_SEXT_INREG ||
Depth != 0) &&
242 "Unexpected opcode");
244 if (
Depth >= RISCVInstructionSelector::MaxRecursionDepth)
247 auto DestReg =
MI.getOperand(0).getReg();
249 assert(UserOp.getParent() &&
"UserOp must have a parent");
250 const MachineInstr &UserMI = *UserOp.getParent();
251 unsigned OpIdx = UserOp.getOperandNo();
259 case RISCV::FCVT_D_W:
260 case RISCV::FCVT_S_W:
303InstructionSelector::ComplexRendererFns
304RISCVInstructionSelector::selectShiftMask(MachineOperand &Root,
305 unsigned ShiftWidth)
const {
309 using namespace llvm::MIPatternMatch;
315 ShAmtReg = ZExtSrcReg;
334 APInt ShMask(AndMask.
getBitWidth(), ShiftWidth - 1);
335 if (ShMask.isSubsetOf(AndMask)) {
336 ShAmtReg = AndSrcReg;
340 KnownBits
Known = VT->getKnownBits(AndSrcReg);
341 if (ShMask.isSubsetOf(AndMask |
Known.Zero))
342 ShAmtReg = AndSrcReg;
349 if (
Imm != 0 &&
Imm.urem(ShiftWidth) == 0)
354 if (
Imm != 0 &&
Imm.urem(ShiftWidth) == 0) {
358 unsigned NegOpc =
Subtarget->is64Bit() ? RISCV::SUBW : RISCV::SUB;
359 return {{[=](MachineInstrBuilder &MIB) {
360 MachineIRBuilder(*MIB.getInstr())
361 .buildInstr(NegOpc, {ShAmtReg}, {
Register(RISCV::X0),
Reg});
362 MIB.addReg(ShAmtReg);
365 if (
Imm.urem(ShiftWidth) == ShiftWidth - 1) {
369 return {{[=](MachineInstrBuilder &MIB) {
370 MachineIRBuilder(*MIB.getInstr())
371 .buildInstr(RISCV::XORI, {ShAmtReg}, {
Reg})
373 MIB.addReg(ShAmtReg);
378 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(ShAmtReg); }}};
381InstructionSelector::ComplexRendererFns
382RISCVInstructionSelector::selectSExtBits(MachineOperand &Root,
383 unsigned Bits)
const {
391 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(SrcReg); }}};
395 if ((
Size - VT->computeNumSignBits(RootReg)) < Bits)
396 return {{[=](MachineInstrBuilder &MIB) { MIB.add(Root); }}};
401InstructionSelector::ComplexRendererFns
402RISCVInstructionSelector::selectZExtBits(MachineOperand &Root,
403 unsigned Bits)
const {
411 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(RegX); }}};
416 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(RegX); }}};
420 return {{[=](MachineInstrBuilder &MIB) { MIB.add(Root); }}};
425InstructionSelector::ComplexRendererFns
426RISCVInstructionSelector::selectSHXADDOp(MachineOperand &Root,
427 unsigned ShAmt)
const {
428 using namespace llvm::MIPatternMatch;
434 const unsigned XLen = STI.
getXLen();
449 assert(
Mask.getBitWidth() == XLen &&
"Unexpected mask size!");
450 assert(C2 > 0 && C2 < XLen &&
"Unexpected shift amount!");
456 if (
Mask.isShiftedMask()) {
457 unsigned Leading = XLen -
Mask.getActiveBits();
458 unsigned Trailing =
Mask.countr_zero();
461 if (*LeftShift && Leading == 0 && C2 < Trailing && Trailing == ShAmt) {
463 return {{[=](MachineInstrBuilder &MIB) {
464 MachineIRBuilder(*MIB.getInstr())
465 .buildInstr(RISCV::SRLI, {DstReg}, {RegY})
466 .addImm(Trailing - C2);
473 if (!*LeftShift && Leading == C2 && Trailing == ShAmt) {
475 return {{[=](MachineInstrBuilder &MIB) {
476 MachineIRBuilder(*MIB.getInstr())
477 .buildInstr(RISCV::SRLI, {DstReg}, {RegY})
478 .addImm(Leading + Trailing);
498 unsigned Leading = XLen -
Mask.getActiveBits();
499 unsigned Trailing =
Mask.countr_zero();
504 *
LeftShift && Leading == 32 && Trailing > 0 && (Trailing + C2) == ShAmt;
509 (Trailing - C2) == ShAmt;
513 return {{[=](MachineInstrBuilder &MIB) {
514 MachineIRBuilder(*MIB.getInstr())
515 .buildInstr(RISCV::SRLIW, {DstReg}, {RegY})
525InstructionSelector::ComplexRendererFns
526RISCVInstructionSelector::selectSHXADD_UWOp(MachineOperand &Root,
527 unsigned ShAmt)
const {
528 using namespace llvm::MIPatternMatch;
543 assert(C2 > 0 && C2 <
Mask.getBitWidth() &&
"Unexpected shift amount!");
546 if (
Mask.isShiftedMask()) {
547 unsigned Leading =
Mask.countl_zero();
548 unsigned Trailing =
Mask.countr_zero();
549 if (Leading == 32 - ShAmt && C2 == Trailing && Trailing > ShAmt) {
551 return {{[=](MachineInstrBuilder &MIB) {
552 MachineIRBuilder(*MIB.getInstr())
553 .buildInstr(RISCV::SLLI, {DstReg}, {RegX})
564InstructionSelector::ComplexRendererFns
565RISCVInstructionSelector::renderVLOp(MachineOperand &Root)
const {
566 assert(Root.
isReg() &&
"Expected operand to be a Register");
567 std::optional<ValueAndVReg>
C;
569 if (
C->Value.isAllOnes())
573 return {{[=](MachineInstrBuilder &MIB) {
578 uint64_t ZExtC =
C->Value.getZExtValue();
579 return {{[=](MachineInstrBuilder &MIB) { MIB.addImm(ZExtC); }}};
582 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(Root.
getReg()); }}};
585InstructionSelector::ComplexRendererFns
586RISCVInstructionSelector::renderAddiPair(
Register BaseReg, int64_t AddiImm,
587 int64_t OffsetImm)
const {
588 return {{[=](MachineInstrBuilder &MIB) {
591 BuildMI(*MIB->getParent(), *MIB.getInstr(), MIB->getDebugLoc(),
592 TII.get(RISCV::ADDI), Tmp)
598 [=](MachineInstrBuilder &MIB) { MIB.addImm(OffsetImm); }}};
601InstructionSelector::ComplexRendererFns
602RISCVInstructionSelector::selectAddrRegImm(MachineOperand &Root)
const {
612 [=](MachineInstrBuilder &MIB) { MIB.addFrameIndex(FI); },
613 [=](MachineInstrBuilder &MIB) { MIB.addImm(0); },
625 [=](MachineInstrBuilder &MIB) { MIB.addFrameIndex(BaseFI); },
626 [=](MachineInstrBuilder &MIB) { MIB.addImm(RHSC); },
629 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(BaseReg); },
630 [=](MachineInstrBuilder &MIB) { MIB.addImm(RHSC); }}};
635 if (RHSC >= -4096 && RHSC <= 4094) {
636 int64_t Adj = RHSC < 0 ? -2048 : 2047;
637 return renderAddiPair(BaseReg, Adj, RHSC - Adj);
641 if (
auto Fns = computeConstAddr(RHSC,
false, BaseReg))
650 if (
auto Fns = computeConstAddr(CVal,
false,
Register()))
654 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(RootReg); },
655 [=](MachineInstrBuilder &MIB) { MIB.addImm(0); }}};
658InstructionSelector::ComplexRendererFns
659RISCVInstructionSelector::selectBrindRegImm(MachineOperand &Root)
const {
672 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(BaseReg); },
673 [=](MachineInstrBuilder &MIB) { MIB.addImm(RHSC); }}};
676 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(RootReg); },
677 [=](MachineInstrBuilder &MIB) { MIB.addImm(0); }}};
680InstructionSelector::ComplexRendererFns
681RISCVInstructionSelector::selectAddrRegImmLsb00000(MachineOperand &Root)
const {
691 [=](MachineInstrBuilder &MIB) { MIB.addFrameIndex(FI); },
692 [=](MachineInstrBuilder &MIB) { MIB.addImm(0); },
702 if ((RHSC & 0b11111) != 0) {
703 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(RootReg); },
704 [=](MachineInstrBuilder &MIB) { MIB.addImm(0); }}};
710 [=](MachineInstrBuilder &MIB) { MIB.addFrameIndex(BaseFI); },
711 [=](MachineInstrBuilder &MIB) { MIB.addImm(RHSC); },
713 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(BaseReg); },
714 [=](MachineInstrBuilder &MIB) { MIB.addImm(RHSC); }}};
718 if ((-2049 >= RHSC && RHSC >= -4096) || (4063 >= RHSC && RHSC >= 2017)) {
719 int64_t Adj = RHSC < 0 ? -2048 : 2016;
720 return renderAddiPair(BaseReg, RHSC - Adj, Adj);
725 if (
auto Fns = computeConstAddr(RHSC,
true, BaseReg))
734 if (
auto Fns = computeConstAddr(CVal,
true,
Register()))
738 return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(RootReg); },
739 [=](MachineInstrBuilder &MIB) { MIB.addImm(0); }}};
748 case CmpInst::Predicate::ICMP_EQ:
750 case CmpInst::Predicate::ICMP_NE:
752 case CmpInst::Predicate::ICMP_ULT:
754 case CmpInst::Predicate::ICMP_SLT:
756 case CmpInst::Predicate::ICMP_UGE:
758 case CmpInst::Predicate::ICMP_SGE:
824 CC = getRISCVCCFromICmp(
Pred);
831 const bool IsStore = GenericOpc == TargetOpcode::G_STORE;
836 return IsStore ? RISCV::SB_RL : RISCV::LB_AQ;
838 return IsStore ? RISCV::SH_RL : RISCV::LH_AQ;
840 return IsStore ? RISCV::SW_RL : RISCV::LW_AQ;
842 return IsStore ? RISCV::SD_RL : RISCV::LD_AQ;
851 unsigned GenericOpc,
unsigned OpSize) {
852 const bool IsStore = GenericOpc == TargetOpcode::G_STORE;
856 return IsStore ? RISCV::SB : RISCV::LBU;
858 return IsStore ? RISCV::SH : RISCV::LH;
860 return IsStore ? RISCV::SW : RISCV::LW;
864 if (!STI.
is64Bit() && STI.hasStdExtZilsd())
865 return IsStore ? RISCV::SD_RV32 : RISCV::LD_RV32;
866 return IsStore ? RISCV::SD : RISCV::LD;
872void RISCVInstructionSelector::addVectorLoadStoreOperands(
873 MachineInstr &
I, SmallVectorImpl<Register> &SrcOps,
unsigned &CurOp,
874 bool IsMasked,
bool IsStridedOrIndexed, LLT *IndexVT)
const {
876 auto PtrReg =
I.getOperand(CurOp++).getReg();
880 if (IsStridedOrIndexed) {
881 auto StrideReg =
I.getOperand(CurOp++).getReg();
889 auto MaskReg =
I.getOperand(CurOp++).getReg();
894bool RISCVInstructionSelector::selectIntrinsicWithSideEffects(
895 MachineInstr &
I)
const {
902 case Intrinsic::riscv_vlm:
903 case Intrinsic::riscv_vle:
904 case Intrinsic::riscv_vle_mask:
905 case Intrinsic::riscv_vlse:
906 case Intrinsic::riscv_vlse_mask: {
907 bool IsMasked = IntrinID == Intrinsic::riscv_vle_mask ||
908 IntrinID == Intrinsic::riscv_vlse_mask;
909 bool IsStrided = IntrinID == Intrinsic::riscv_vlse ||
910 IntrinID == Intrinsic::riscv_vlse_mask;
915 const Register DstReg =
I.getOperand(0).getReg();
918 bool HasPassthruOperand = IntrinID != Intrinsic::riscv_vlm;
923 if (HasPassthruOperand) {
924 auto PassthruReg =
I.getOperand(CurOp++).getReg();
930 addVectorLoadStoreOperands(
I, SrcOps, CurOp, IsMasked, IsStrided);
933 const RISCV::VLEPseudo *
P =
934 RISCV::getVLEPseudo(IsMasked, IsStrided,
false, Log2SEW,
935 static_cast<unsigned>(LMUL));
937 MachineInstrBuilder PseudoMI =
938 BuildMI(*
I.getParent(),
I,
I.getDebugLoc(),
TII.get(
P->Pseudo), DstReg);
943 auto VLOpFn = renderVLOp(
I.getOperand(CurOp++));
944 for (
auto &RenderFn : *VLOpFn)
953 Policy =
I.getOperand(CurOp++).getImm();
963 case Intrinsic::riscv_vloxei:
964 case Intrinsic::riscv_vloxei_mask:
965 case Intrinsic::riscv_vluxei:
966 case Intrinsic::riscv_vluxei_mask: {
967 bool IsMasked = IntrinID == Intrinsic::riscv_vloxei_mask ||
968 IntrinID == Intrinsic::riscv_vluxei_mask;
969 bool IsOrdered = IntrinID == Intrinsic::riscv_vloxei ||
970 IntrinID == Intrinsic::riscv_vloxei_mask;
975 const Register DstReg =
I.getOperand(0).getReg();
978 bool HasPassthruOperand = IntrinID != Intrinsic::riscv_vlm;
983 if (HasPassthruOperand) {
984 auto PassthruReg =
I.getOperand(CurOp++).getReg();
991 addVectorLoadStoreOperands(
I, SrcOps, CurOp, IsMasked,
true, &IndexVT);
997 if (IndexLog2EEW == 6 && !
Subtarget->is64Bit()) {
999 "values when XLEN=32");
1001 const RISCV::VLX_VSXPseudo *
P = RISCV::getVLXPseudo(
1002 IsMasked, IsOrdered, IndexLog2EEW,
static_cast<unsigned>(LMUL),
1003 static_cast<unsigned>(IndexLMUL));
1005 MachineInstrBuilder PseudoMI =
1006 BuildMI(*
I.getParent(),
I,
I.getDebugLoc(),
TII.get(
P->Pseudo), DstReg);
1011 auto VLOpFn = renderVLOp(
I.getOperand(CurOp++));
1012 for (
auto &RenderFn : *VLOpFn)
1016 PseudoMI.
addImm(Log2SEW);
1021 Policy =
I.getOperand(CurOp++).getImm();
1027 I.eraseFromParent();
1031 case Intrinsic::riscv_vsm:
1032 case Intrinsic::riscv_vse:
1033 case Intrinsic::riscv_vse_mask:
1034 case Intrinsic::riscv_vsse:
1035 case Intrinsic::riscv_vsse_mask: {
1036 bool IsMasked = IntrinID == Intrinsic::riscv_vse_mask ||
1037 IntrinID == Intrinsic::riscv_vsse_mask;
1038 bool IsStrided = IntrinID == Intrinsic::riscv_vsse ||
1039 IntrinID == Intrinsic::riscv_vsse_mask;
1048 auto PassthruReg =
I.getOperand(CurOp++).getReg();
1051 addVectorLoadStoreOperands(
I, SrcOps, CurOp, IsMasked, IsStrided);
1054 const RISCV::VSEPseudo *
P = RISCV::getVSEPseudo(
1055 IsMasked, IsStrided, Log2SEW,
static_cast<unsigned>(LMUL));
1057 MachineInstrBuilder PseudoMI =
1063 auto VLOpFn = renderVLOp(
I.getOperand(CurOp++));
1064 for (
auto &RenderFn : *VLOpFn)
1068 PseudoMI.
addImm(Log2SEW);
1073 I.eraseFromParent();
1077 case Intrinsic::riscv_vsoxei:
1078 case Intrinsic::riscv_vsoxei_mask:
1079 case Intrinsic::riscv_vsuxei:
1080 case Intrinsic::riscv_vsuxei_mask: {
1081 bool IsMasked = IntrinID == Intrinsic::riscv_vsoxei_mask ||
1082 IntrinID == Intrinsic::riscv_vsuxei_mask;
1083 bool IsOrdered = IntrinID == Intrinsic::riscv_vsoxei ||
1084 IntrinID == Intrinsic::riscv_vsoxei_mask;
1093 auto PassthruReg =
I.getOperand(CurOp++).getReg();
1097 addVectorLoadStoreOperands(
I, SrcOps, CurOp, IsMasked,
true, &IndexVT);
1103 if (IndexLog2EEW == 6 && !
Subtarget->is64Bit()) {
1105 "values when XLEN=32");
1107 const RISCV::VLX_VSXPseudo *
P = RISCV::getVSXPseudo(
1108 IsMasked, IsOrdered, IndexLog2EEW,
static_cast<unsigned>(LMUL),
1109 static_cast<unsigned>(IndexLMUL));
1111 MachineInstrBuilder PseudoMI =
1117 auto VLOpFn = renderVLOp(
I.getOperand(CurOp++));
1118 for (
auto &RenderFn : *VLOpFn)
1122 PseudoMI.
addImm(Log2SEW);
1127 I.eraseFromParent();
1134bool RISCVInstructionSelector::selectIntrinsic(MachineInstr &
I)
const {
1141 case Intrinsic::riscv_vsetvli:
1142 case Intrinsic::riscv_vsetvlimax: {
1144 bool VLMax = IntrinID == Intrinsic::riscv_vsetvlimax;
1146 unsigned Offset = VLMax ? 2 : 3;
1154 Register DstReg =
I.getOperand(0).getReg();
1157 unsigned Opcode = RISCV::PseudoVSETVLI;
1161 Register AVLReg =
I.getOperand(2).getReg();
1163 uint64_t AVL = AVLConst->Value.getZExtValue();
1164 if (
auto VLEN =
Subtarget->getRealVLen()) {
1176 Opcode = RISCV::PseudoVSETVLIX0;
1178 Register AVLReg =
I.getOperand(2).getReg();
1183 uint64_t AVL = AVLConst->Value.getZExtValue();
1185 MachineInstr *PseudoMI =
1187 TII.get(RISCV::PseudoVSETIVLI), DstReg)
1190 I.eraseFromParent();
1197 MachineInstr *PseudoMI =
1198 BuildMI(*
I.getParent(),
I,
I.getDebugLoc(),
TII.get(Opcode), DstReg)
1201 I.eraseFromParent();
1208bool RISCVInstructionSelector::selectSplatVector(MachineInstr &
MI) {
1210 Register ScalarReg =
MI.getOperand(1).getReg();
1218 MachineIRBuilder MIB(
MI);
1220 auto Passthru = MIB.buildUndef(VecTy);
1225 MIB.buildInstr(RISCV::G_VMV_V_X_VL, {DstReg}, {Passthru, ScalarReg, VL});
1226 MI.eraseFromParent();
1230 if (!selectImpl(*Vmv.getInstr(), *CoverageInfo))
1233 VL->eraseFromParent();
1234 return selectImplicitDef(*Passthru.getInstr());
1237bool RISCVInstructionSelector::selectExtractSubvector(MachineInstr &
MI)
const {
1238 assert(
MI.getOpcode() == TargetOpcode::G_EXTRACT_SUBVECTOR);
1246 unsigned Idx =
static_cast<unsigned>(
MI.getOperand(2).
getImm());
1252 std::tie(SubRegIdx, Idx) =
1254 SrcMVT, DstMVT, Idx, &
TRI);
1269 BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
TII.get(TargetOpcode::COPY),
1271 .
addReg(SrcReg, {}, SubRegIdx);
1273 MI.eraseFromParent();
1277bool RISCVInstructionSelector::selectInsertSubVector(MachineInstr &
MI)
const {
1278 assert(
MI.getOpcode() == TargetOpcode::G_INSERT_SUBVECTOR);
1282 Register SubVecReg =
MI.getOperand(2).getReg();
1290 unsigned Idx =
static_cast<unsigned>(
MI.getOperand(3).
getImm());
1293 std::tie(SubRegIdx, Idx) =
1295 VecMVT, SubVecMVT, Idx, &
TRI);
1311 if (SubRegIdx == RISCV::NoSubRegister) {
1314 "Unexpected subvector insert");
1315 BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
TII.get(TargetOpcode::COPY),
1318 MI.eraseFromParent();
1324 MachineInstr *Ins =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1325 TII.get(TargetOpcode::INSERT_SUBREG), DstReg)
1330 MI.eraseFromParent();
1335bool RISCVInstructionSelector::select(MachineInstr &
MI) {
1337 const unsigned Opc =
MI.getOpcode();
1339 if (!
MI.isPreISelOpcode() ||
Opc == TargetOpcode::G_PHI) {
1340 if (
Opc == TargetOpcode::PHI ||
Opc == TargetOpcode::G_PHI) {
1341 const Register DefReg =
MI.getOperand(0).getReg();
1356 DefRC =
TRI.getRegClassForTypeOnBank(DefTy, RB, STI.
is64Bit());
1363 MI.setDesc(
TII.get(TargetOpcode::PHI));
1374 if (selectImpl(
MI, *CoverageInfo))
1378 case TargetOpcode::G_BITCAST:
1379 case TargetOpcode::G_ANYEXT:
1380 case TargetOpcode::G_PTRTOINT:
1381 case TargetOpcode::G_INTTOPTR:
1382 case TargetOpcode::G_TRUNC:
1383 case TargetOpcode::G_FREEZE:
1385 case TargetOpcode::G_CONSTANT: {
1387 int64_t
Imm =
MI.getOperand(1).getCImm()->getSExtValue();
1389 if (!materializeImm(DstReg,
Imm,
MI))
1392 MI.eraseFromParent();
1395 case TargetOpcode::G_ZEXT:
1396 case TargetOpcode::G_SEXT: {
1397 bool IsSigned =
Opc != TargetOpcode::G_ZEXT;
1407 RISCV::GPRBRegBankID &&
1408 "Unexpected ext regbank");
1411 if (IsSigned && SrcSize == 32) {
1412 MI.setDesc(
TII.get(RISCV::ADDIW));
1419 if (!IsSigned && SrcSize == 32 && STI.hasStdExtZba()) {
1420 MI.setDesc(
TII.get(RISCV::ADD_UW));
1427 if (SrcSize == 16 &&
1428 (STI.hasStdExtZbb() || (!IsSigned && STI.hasStdExtZbkb()))) {
1429 MI.setDesc(
TII.get(IsSigned ? RISCV::SEXT_H
1430 : STI.
is64Bit() ? RISCV::ZEXT_H_RV64
1431 : RISCV::ZEXT_H_RV32));
1438 MachineInstr *ShiftLeft =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1439 TII.get(RISCV::SLLI), ShiftLeftReg)
1443 MachineInstr *ShiftRight =
1445 TII.get(IsSigned ? RISCV::SRAI : RISCV::SRLI), DstReg)
1449 MI.eraseFromParent();
1452 case TargetOpcode::G_FCONSTANT: {
1455 const APFloat &FPimm =
MI.getOperand(1).getFPImm()->getValueAPF();
1467 bool Negate =
false;
1473 unsigned FLIOpc =
Size == 64 ? RISCV::FLI_D
1474 :
Size == 32 ? RISCV::FLI_S
1483 MachineInstr *FLI =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1484 TII.get(FLIOpc), FLIReg)
1489 unsigned FNegOpc =
Size == 64 ? RISCV::FSGNJN_D
1490 :
Size == 32 ? RISCV::FSGNJN_S
1492 MachineInstr *FNeg =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1493 TII.get(FNegOpc), DstReg)
1499 MI.eraseFromParent();
1511 if (!materializeImm(GPRReg,
Imm.getSExtValue(),
MI))
1515 unsigned Opcode =
Size == 64 ? RISCV::FMV_D_X
1516 :
Size == 32 ? RISCV::FMV_W_X
1518 MachineInstr *FMV =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1519 TII.get(Opcode), DstReg)
1525 "Unexpected size or subtarget");
1529 MachineInstr *FCVT =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1530 TII.get(RISCV::FCVT_D_W), DstReg)
1535 MI.eraseFromParent();
1543 if (!materializeImm(GPRRegHigh,
Imm.extractBits(32, 32).getSExtValue(),
1546 if (!materializeImm(GPRRegLow,
Imm.trunc(32).getSExtValue(),
MI))
1548 MachineInstr *PairF64 =
1550 TII.get(RISCV::BuildPairF64Pseudo), DstReg)
1556 MI.eraseFromParent();
1559 case TargetOpcode::G_GLOBAL_VALUE: {
1560 auto *GV =
MI.getOperand(1).getGlobal();
1561 if (GV->isThreadLocal()) {
1566 return selectAddr(
MI, GV->isDSOLocal(), GV->hasExternalWeakLinkage());
1568 case TargetOpcode::G_JUMP_TABLE:
1569 case TargetOpcode::G_CONSTANT_POOL:
1570 return selectAddr(
MI);
1571 case TargetOpcode::G_BRCOND: {
1576 MachineInstr *Bcc =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1580 .
addMBB(
MI.getOperand(1).getMBB());
1581 MI.eraseFromParent();
1585 case TargetOpcode::G_SELECT:
1586 return selectSelect(
MI);
1587 case TargetOpcode::G_FCMP:
1588 return selectFPCompare(
MI);
1589 case TargetOpcode::G_FENCE: {
1594 emitFence(FenceOrdering, FenceSSID,
MI);
1595 MI.eraseFromParent();
1598 case TargetOpcode::G_IMPLICIT_DEF:
1599 return selectImplicitDef(
MI);
1600 case TargetOpcode::G_UNMERGE_VALUES:
1602 case TargetOpcode::G_MERGE_VALUES:
1604 case TargetOpcode::G_LOAD:
1605 case TargetOpcode::G_STORE: {
1612 if (RB.
getID() != RISCV::GPRBRegBankID)
1619 "Load/Store pointer operand isn't a GPR");
1620 assert(PtrTy.
isPointer() &&
"Load/Store pointer operand isn't a pointer");
1636 const unsigned NewOpc =
1638 if (NewOpc ==
MI.getOpcode())
1642 auto AddrModeFns = selectAddrRegImm(
MI.getOperand(1));
1647 MachineInstrBuilder NewInst =
1655 for (
auto &Fn : *AddrModeFns)
1657 MI.eraseFromParent();
1662 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
1663 return selectIntrinsicWithSideEffects(
MI);
1664 case TargetOpcode::G_INTRINSIC:
1665 return selectIntrinsic(
MI);
1666 case TargetOpcode::G_SPLAT_VECTOR:
1667 return selectSplatVector(
MI);
1668 case TargetOpcode::G_EXTRACT_SUBVECTOR:
1669 return selectExtractSubvector(
MI);
1670 case TargetOpcode::G_INSERT_SUBVECTOR:
1671 return selectInsertSubVector(
MI);
1677bool RISCVInstructionSelector::selectUnmergeValues(MachineInstr &
MI)
const {
1678 assert(
MI.getOpcode() == TargetOpcode::G_UNMERGE_VALUES);
1681 if (
MI.getNumOperands() != 3)
1690 isRegInGprb(
Lo) && isRegInGprb(
Hi)) {
1702 auto ExtractHalf = [&](
Register Dst,
unsigned SubIdx) {
1704 MachineInstr &
C = *
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1705 TII.get(TargetOpcode::COPY), Dst)
1706 .
addReg(Src, {}, SubIdx);
1709 ExtractHalf(
Lo, RISCV::sub_gpr_even);
1710 ExtractHalf(
Hi, RISCV::sub_gpr_odd);
1711 MI.eraseFromParent();
1718 if (!isRegInFprb(Src) || !isRegInGprb(
Lo) || !isRegInGprb(
Hi))
1721 MachineInstr *ExtractLo =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1722 TII.get(RISCV::FMV_X_W_FPR64),
Lo)
1726 MachineInstr *ExtractHi =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1727 TII.get(RISCV::FMVH_X_D),
Hi)
1731 MI.eraseFromParent();
1735bool RISCVInstructionSelector::selectMergeValues(MachineInstr &
MI)
const {
1736 assert(
MI.getOpcode() == TargetOpcode::G_MERGE_VALUES);
1738 if (
MI.getNumOperands() != 3)
1747 isRegInGprb(
Lo) && isRegInGprb(
Hi)) {
1753 MachineInstr &Seq = *
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1754 TII.get(TargetOpcode::REG_SEQUENCE), Dst)
1756 .
addImm(RISCV::sub_gpr_even)
1758 .
addImm(RISCV::sub_gpr_odd);
1759 MI.eraseFromParent();
1766bool RISCVInstructionSelector::replacePtrWithInt(MachineInstr &
MI,
1768 MachineOperand &
Op =
MI.getOperand(OpIdx);
1775 MachineInstr *PtrToInt =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
1776 TII.get(TargetOpcode::G_PTRTOINT), IntReg)
1779 return select(*PtrToInt);
1782void RISCVInstructionSelector::preISelLower(MachineInstr &
MI) {
1783 switch (
MI.getOpcode()) {
1784 case TargetOpcode::G_PTR_ADD: {
1788 replacePtrWithInt(
MI, 1);
1789 MI.setDesc(
TII.get(TargetOpcode::G_ADD));
1793 case TargetOpcode::G_PTRMASK: {
1796 replacePtrWithInt(
MI, 1);
1797 MI.setDesc(
TII.get(TargetOpcode::G_AND));
1804void RISCVInstructionSelector::renderNegImm(MachineInstrBuilder &MIB,
1805 const MachineInstr &
MI,
1807 assert(
MI.getOpcode() == TargetOpcode::G_CONSTANT && OpIdx == -1 &&
1808 "Expected G_CONSTANT");
1809 int64_t CstVal =
MI.getOperand(1).getCImm()->getSExtValue();
1813void RISCVInstructionSelector::renderImmSubFromXLen(MachineInstrBuilder &MIB,
1814 const MachineInstr &
MI,
1816 assert(
MI.getOpcode() == TargetOpcode::G_CONSTANT && OpIdx == -1 &&
1817 "Expected G_CONSTANT");
1818 uint64_t CstVal =
MI.getOperand(1).getCImm()->getZExtValue();
1822void RISCVInstructionSelector::renderImmSubFrom32(MachineInstrBuilder &MIB,
1823 const MachineInstr &
MI,
1825 assert(
MI.getOpcode() == TargetOpcode::G_CONSTANT && OpIdx == -1 &&
1826 "Expected G_CONSTANT");
1827 uint64_t CstVal =
MI.getOperand(1).getCImm()->getZExtValue();
1831void RISCVInstructionSelector::renderImmPlus1(MachineInstrBuilder &MIB,
1832 const MachineInstr &
MI,
1834 assert(
MI.getOpcode() == TargetOpcode::G_CONSTANT && OpIdx == -1 &&
1835 "Expected G_CONSTANT");
1836 int64_t CstVal =
MI.getOperand(1).getCImm()->getSExtValue();
1840void RISCVInstructionSelector::renderTrailingZeros(MachineInstrBuilder &MIB,
1841 const MachineInstr &
MI,
1843 assert(
MI.getOpcode() == TargetOpcode::G_CONSTANT && OpIdx == -1 &&
1844 "Expected G_CONSTANT");
1845 uint64_t C =
MI.getOperand(1).getCImm()->getZExtValue();
1849void RISCVInstructionSelector::renderXLenSubTrailingOnes(
1850 MachineInstrBuilder &MIB,
const MachineInstr &
MI,
int OpIdx)
const {
1851 assert(
MI.getOpcode() == TargetOpcode::G_CONSTANT && OpIdx == -1 &&
1852 "Expected G_CONSTANT");
1853 uint64_t C =
MI.getOperand(1).getCImm()->getZExtValue();
1857void RISCVInstructionSelector::renderAddiPairImmSmall(MachineInstrBuilder &MIB,
1858 const MachineInstr &
MI,
1860 assert(
MI.getOpcode() == TargetOpcode::G_CONSTANT && OpIdx == -1 &&
1861 "Expected G_CONSTANT");
1862 int64_t
Imm =
MI.getOperand(1).getCImm()->getSExtValue();
1863 int64_t Adj =
Imm < 0 ? -2048 : 2047;
1867void RISCVInstructionSelector::renderAddiPairImmLarge(MachineInstrBuilder &MIB,
1868 const MachineInstr &
MI,
1870 assert(
MI.getOpcode() == TargetOpcode::G_CONSTANT && OpIdx == -1 &&
1871 "Expected G_CONSTANT");
1872 int64_t
Imm =
MI.getOperand(1).getCImm()->getSExtValue() < 0 ? -2048 : 2047;
1876bool RISCVInstructionSelector::isRegInGprb(
Register Reg)
const {
1880bool RISCVInstructionSelector::isRegInFprb(
Register Reg)
const {
1888bool RISCVInstructionSelector::isWorthFoldingAdd(
Register AddResult)
const {
1906bool RISCVInstructionSelector::selectCopy(MachineInstr &
MI)
const {
1913 TRI.getConstrainedRegClassForReg(DstReg, *
MRI);
1916 "Register class not available for LLT, register bank combination");
1927 MI.setDesc(
TII.get(RISCV::COPY));
1931bool RISCVInstructionSelector::selectImplicitDef(MachineInstr &
MI)
const {
1932 assert(
MI.getOpcode() == TargetOpcode::G_IMPLICIT_DEF);
1934 const Register DstReg =
MI.getOperand(0).getReg();
1939 "Register class not available for LLT, register bank combination");
1945 MI.setDesc(
TII.get(TargetOpcode::IMPLICIT_DEF));
1949bool RISCVInstructionSelector::materializeImm(
Register DstReg, int64_t
Imm,
1950 MachineInstr &
MI)
const {
1960 return materializeInstSeq(DstReg, Seq,
MI);
1963bool RISCVInstructionSelector::materializeInstSeq(
1965 assert(!Seq.
empty() &&
"materializeInstSeq requires a non-empty sequence");
1969 unsigned NumInsts = Seq.
size();
1972 for (
unsigned i = 0; i < NumInsts; i++) {
1976 const RISCVMatInt::Inst &
I = Seq[i];
1979 switch (
I.getOpndKind()) {
2009InstructionSelector::ComplexRendererFns
2010RISCVInstructionSelector::computeConstAddr(int64_t CVal,
bool IsPrefetch,
2017 auto emit = [&](ConstAddrPlan Plan) -> ComplexRendererFns {
2018 return {{[=](MachineInstrBuilder &MIB) {
2019 MIB.
addReg(materializeConstBase(MIB, Plan, OrigBase));
2021 [=](MachineInstrBuilder &MIB) { MIB.
addImm(Plan.Lo12); }}};
2024 if (IsPrefetch && (Lo12 & 0b11111) != 0)
2025 return std::nullopt;
2029 Plan.Kind = ConstAddrPlan::LUI;
2030 Plan.Hi20 = (
Hi >> 12) & 0xfffff;
2032 return emit(std::move(Plan));
2038 if (Seq.
back().getOpcode() != RISCV::ADDI)
2039 return std::nullopt;
2040 Lo12 = Seq.
back().getImm();
2041 if (IsPrefetch && (Lo12 & 0b11111) != 0)
2042 return std::nullopt;
2045 return std::nullopt;
2047 Plan.Kind = ConstAddrPlan::InstSeq;
2048 Plan.Seq = std::move(Seq);
2050 return emit(std::move(Plan));
2054RISCVInstructionSelector::materializeConstBase(MachineInstrBuilder &MIB,
2055 const ConstAddrPlan &Plan,
2059 MachineInstr &InsertPt = *MIB.
getInstr();
2062 switch (Plan.Kind) {
2063 case ConstAddrPlan::X0:
2065 case ConstAddrPlan::LUI: {
2067 MachineInstr *LUI =
BuildMI(
MBB, InsertPt,
DL,
TII.get(RISCV::LUI), HiReg)
2072 case ConstAddrPlan::InstSeq: {
2074 materializeInstSeq(HiReg, Plan.Seq, InsertPt);
2081 if (OrigBase.
isValid() && HiReg != RISCV::X0) {
2089 return OrigBase.
isValid() ? OrigBase : HiReg;
2092bool RISCVInstructionSelector::selectAddr(MachineInstr &
MI,
bool IsLocal,
2093 bool IsExternWeak)
const {
2094 assert((
MI.getOpcode() == TargetOpcode::G_GLOBAL_VALUE ||
2095 MI.getOpcode() == TargetOpcode::G_JUMP_TABLE ||
2096 MI.getOpcode() == TargetOpcode::G_CONSTANT_POOL) &&
2097 "Unexpected opcode");
2099 const MachineOperand &DispMO =
MI.getOperand(1);
2109 if (IsLocal && !
Subtarget->allowTaggedGlobals()) {
2113 MI.setDesc(
TII.get(RISCV::PseudoLLA));
2130 TII.get(RISCV::PseudoLGA), DefReg)
2136 MI.eraseFromParent();
2143 "Unsupported code model for lowering",
MI);
2151 MachineInstr *AddrHi =
BuildMI(*
MI.getParent(),
MI,
MI.getDebugLoc(),
2152 TII.get(RISCV::LUI), AddrHiDest)
2158 TII.get(RISCV::ADDI), DefReg)
2164 MI.eraseFromParent();
2185 TII.get(RISCV::PseudoLGA), DefReg)
2191 MI.eraseFromParent();
2198 MI.setDesc(
TII.get(RISCV::PseudoLLA));
2206bool RISCVInstructionSelector::selectSelect(MachineInstr &
MI)
const {
2213 Register DstReg = SelectMI.getReg(0);
2215 unsigned Opc = RISCV::Select_GPR_Using_CC_GPR;
2218 Opc =
Size == 32 ? RISCV::Select_FPR32_Using_CC_GPR
2219 : RISCV::Select_FPR64_Using_CC_GPR;
2228 .
addReg(SelectMI.getTrueReg())
2229 .
addReg(SelectMI.getFalseReg());
2230 MI.eraseFromParent();
2242 return Size == 16 ? RISCV::FLT_H :
Size == 32 ? RISCV::FLT_S : RISCV::FLT_D;
2244 return Size == 16 ? RISCV::FLE_H :
Size == 32 ? RISCV::FLE_S : RISCV::FLE_D;
2246 return Size == 16 ? RISCV::FEQ_H :
Size == 32 ? RISCV::FEQ_S : RISCV::FEQ_D;
2259 assert(!isLegalFCmpPredicate(
Pred) &&
"Predicate already legal?");
2262 if (isLegalFCmpPredicate(InvPred)) {
2270 if (isLegalFCmpPredicate(InvPred)) {
2275 if (isLegalFCmpPredicate(InvPred)) {
2287bool RISCVInstructionSelector::selectFPCompare(MachineInstr &
MI)
const {
2300 bool NeedInvert =
false;
2315 MachineInstr *Cmp1 =
2323 MachineInstr *Cmp2 =
2333 TII.get(RISCV::OR), TmpReg)
2353 MachineInstr *Cmp1 =
2361 MachineInstr *Cmp2 =
2369 TII.get(RISCV::AND), TmpReg)
2380 TII.get(RISCV::XORI), DstReg)
2386 MI.eraseFromParent();
2390void RISCVInstructionSelector::emitFence(
AtomicOrdering FenceOrdering,
2392 MachineInstr &
MI)
const {
2396 if (STI.hasStdExtZtso()) {
2399 if (FenceOrdering == AtomicOrdering::SequentiallyConsistent &&
2423 unsigned Pred, Succ;
2424 switch (FenceOrdering) {
2427 case AtomicOrdering::AcquireRelease:
2431 case AtomicOrdering::Acquire:
2436 case AtomicOrdering::Release:
2441 case AtomicOrdering::SequentiallyConsistent:
2451InstructionSelector *
2455 return new RISCVInstructionSelector(TM,
Subtarget, RBI);
const AArch64Subtarget & Subtarget
#define GET_GLOBALISEL_PREDICATES_INIT
#define GET_GLOBALISEL_TEMPORARIES_INIT
static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool selectMergeValues(MachineInstrBuilder &MIB, const ARMBaseInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
static bool selectUnmergeValues(MachineInstrBuilder &MIB, const ARMBaseInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
Provides analysis for querying information about KnownBits during GISel passes.
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
const HexagonInstrInfo * TII
SmallVector< MachineOperand, 4 > Cond
static bool hasAllWUsers(const MachineInstr &OrigMI, const LoongArchSubtarget &ST, const MachineRegisterInfo &MRI)
static bool hasAllNBitUsers(const MachineInstr &OrigMI, const LoongArchSubtarget &ST, const MachineRegisterInfo &MRI, unsigned OrigBits)
Contains matchers for matching SSA Machine Instructions.
This file declares the MachineIRBuilder class.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static StringRef getName(Value *V)
static bool isWorthFoldingAdd(SDValue Add)
static unsigned selectRegImmLoadStoreOp(const RISCVSubtarget &STI, unsigned GenericOpc, unsigned OpSize)
Select the RISC-V regimm opcode for the G_LOAD or G_STORE operation GenericOpc on STI,...
static unsigned selectZalasrLoadStoreOp(unsigned GenericOpc, unsigned OpSize)
Select the RISC-V Zalasr opcode for the G_LOAD or G_STORE operation GenericOpc, appropriate for the G...
static unsigned getFCmpOpcode(CmpInst::Predicate Pred, unsigned Size)
static bool legalizeFCmpPredicate(Register &LHS, Register &RHS, CmpInst::Predicate &Pred, bool &NeedInvert)
static void getOperandsForBranch(Register CondReg, RISCVCC::CondCode &CC, Register &LHS, Register &RHS, MachineRegisterInfo &MRI)
MachineRegisterInfo & MRI
This file declares the targeting of the RegisterBankInfo class for RISC-V.
APInt bitcastToAPInt() const
unsigned getBitWidth() const
Return the number of bits in the APInt.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
@ ICMP_ULT
unsigned less than
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
@ ICMP_SGE
signed greater or equal
@ ICMP_ULE
unsigned less or equal
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
This is an important base class in LLVM.
virtual void setupMF(MachineFunction &mf, GISelValueTracking *vt, CodeGenCoverage *covinfo=nullptr, ProfileSummaryInfo *psi=nullptr, BlockFrequencyInfo *bfi=nullptr)
Setup per-MF executor state.
Register getPointerReg() const
Get the source register of the pointer value.
MachineMemOperand & getMMO() const
Get the MachineMemOperand on this instruction.
LocationSize getMemSizeInBits() const
Returns the size in bits of the memory access.
Register getReg(unsigned Idx) const
Access the Idx'th operand as a register and return it.
constexpr unsigned getScalarSizeInBits() const
constexpr bool isScalar() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
constexpr bool isVector() const
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isPointer() const
constexpr unsigned getAddressSpace() const
static LLT integer(unsigned SizeInBits)
TypeSize getValue() const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
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 MachineInstrBuilder & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addDisp(const MachineOperand &Disp, int64_t off, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
@ MODereferenceable
The memory access is dereferenceable (i.e., doesn't trap).
@ MOLoad
The memory access reads data.
@ MOInvariant
The memory access always returns the same value (or traps).
AtomicOrdering getSuccessOrdering() const
Return the atomic ordering requirements for this memory operation.
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static MachineOperand CreateImm(int64_t Val)
Register getReg() const
getReg - Returns the register number.
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)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
iterator_range< use_nodbg_iterator > use_nodbg_operands(Register Reg) const
bool use_nodbg_empty(Register RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register.
const RegClassOrRegBank & getRegClassOrRegBank(Register Reg) const
Return the register bank or register class of Reg.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
LLVM_ABI void setRegBank(Register Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
LLVM_ABI void setType(Register VReg, LLT Ty)
Set the low-level type of VReg to Ty.
LLVM_ABI Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
Analysis providing profile information.
This class provides the information for the target register banks.
static std::pair< unsigned, unsigned > decomposeSubvectorInsertExtractToSubRegs(MVT VecVT, MVT SubVecVT, unsigned InsertExtractIdx, const RISCVRegisterInfo *TRI)
static unsigned getRegClassIDForVecVT(MVT VT)
static RISCVVType::VLMUL getLMUL(MVT VT)
static const TargetRegisterClass * constrainGenericRegister(Register Reg, const TargetRegisterClass &RC, MachineRegisterInfo &MRI)
Constrain the (possibly generic) virtual register Reg to RC.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
unsigned getID() const
Get the identifier of this register bank.
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
bool isPositionIndependent() const
CodeModel::Model getCodeModel() const
Returns the code model.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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.
operand_type_match m_Reg()
SpecificConstantMatch m_SpecificICst(const APInt &RequestedValue)
Matches a constant equal to RequestedValue.
GCstAndRegMatch m_GCst(std::optional< ValueAndVReg > &ValReg)
operand_type_match m_Pred()
UnaryOp_match< SrcTy, TargetOpcode::G_ZEXT > m_GZExt(const SrcTy &Src)
ConstantMatch< APInt > m_ICst(APInt &Cst)
UnaryOp_match< SrcTy, TargetOpcode::G_INTTOPTR > m_GIntToPtr(const SrcTy &Src)
BinaryOp_match< LHS, RHS, TargetOpcode::G_ADD, true > m_GAdd(const LHS &L, const RHS &R)
SpecificImmMatch m_SpecificImm(int64_t RequestedValue)
Matches an immediate operand equal to RequestedValue.
AllOnesConstantMatch m_AllOnes()
CompareOp_match< Pred, LHS, RHS, TargetOpcode::G_ICMP > m_GICmp(const Pred &P, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, TargetOpcode::G_SUB > m_GSub(const LHS &L, const RHS &R)
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
BinaryOp_match< LHS, RHS, TargetOpcode::G_PTR_ADD, false > m_GPtrAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, TargetOpcode::G_SHL, false > m_GShl(const LHS &L, const RHS &R)
GFrameIndexMatch m_GFrameIndex(int &FI)
BinaryOp_match< LHS, RHS, TargetOpcode::G_AND, true > m_GAnd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, TargetOpcode::G_LSHR, false > m_GLShr(const LHS &L, const RHS &R)
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
SrcImmOp_match< SrcTy, AnyImmMatch, TargetOpcode::G_SEXT_INREG > m_GSExtInReg(const SrcTy &Src)
Matches a G_SEXT_INREG, binding its source and immediate width.
unsigned getBrCond(CondCode CC, unsigned SelectOpc=0)
int getLoadFPImm(APFloat FPImm)
getLoadFPImm - Return a 5-bit binary encoding of the floating-point immediate value.
InstSeq generateInstSeq(int64_t Val, const MCSubtargetInfo &STI)
SmallVector< Inst, 8 > InstSeq
static unsigned decodeVSEW(unsigned VSEW)
LLVM_ABI unsigned getSEWLMULRatio(unsigned SEW, VLMUL VLMul)
LLVM_ABI unsigned encodeVTYPE(VLMUL VLMUL, unsigned SEW, bool TailAgnostic, bool MaskAgnostic, bool AltFmt=false)
static constexpr int64_t VLMaxSentinel
@ SingleThread
Synchronized with respect to signal handlers executing in the same thread.
@ System
Synchronized with respect to all concurrently executing threads.
@ User
could "use" a pointer
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
This is an optimization pass for GlobalISel generic memory operations.
PointerUnion< const TargetRegisterClass *, const RegisterBank * > RegClassOrRegBank
Convenient type to represent either a register class or a register bank.
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.
@ Known
Known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isStrongerThanMonotonic(AtomicOrdering AO)
int countr_one(T Value)
Count the number of ones from the least significant bit to the first zero bit.
LLVM_ABI void 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...
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
LLVM_ABI MVT getMVTForLLT(LLT Ty)
Get a rough equivalent of an MVT for a given LLT.
InstructionSelector * createRISCVInstructionSelector(const RISCVTargetMachine &TM, const RISCVSubtarget &Subtarget, const RISCVRegisterBankInfo &RBI)
LLVM_ABI std::optional< int64_t > getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT fits in int64_t returns it.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void reportGISelFailure(MachineFunction &MF, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R)
Report an ISel error as a missed optimization remark to the LLVMContext's diagnostic stream.
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...
AtomicOrdering
Atomic ordering for LLVM's memory model.
constexpr T maskTrailingZeros(unsigned N)
Create a bitmask with the N right-most bits set to 0, and all other bits set to 1.
@ Or
Bitwise or logical OR of integers.
@ Xor
Bitwise or logical XOR of integers.
@ And
Bitwise or logical AND of integers.
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI std::optional< ValueAndVReg > getIConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_CONSTANT returns its...
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
constexpr T maskTrailingOnes(unsigned N)
Create a bitmask with the N right-most bits set to 1, and all other bits set to 0.
MCRegisterClass TargetRegisterClass
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static LLVM_ABI MachinePointerInfo getGOT(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a GOT entry.