49#define DEBUG_TYPE "globalisel-utils"
59 return MRI.createVirtualRegister(&RegClass);
71 assert(Reg.isVirtual() &&
"PhysReg not implemented");
77 auto *OldRegClass =
MRI.getRegClassOrNull(Reg);
81 if (ConstrainedReg != Reg) {
88 TII.get(TargetOpcode::COPY), ConstrainedReg)
93 TII.get(TargetOpcode::COPY), Reg)
97 Observer->changingInstr(*RegMO.
getParent());
99 RegMO.
setReg(ConstrainedReg);
101 Observer->changedInstr(*RegMO.
getParent());
103 }
else if (OldRegClass !=
MRI.getRegClassOrNull(Reg)) {
105 if (!RegMO.
isDef()) {
107 Observer->changedInstr(*RegDef);
109 Observer->changingAllUsesOfReg(
MRI, Reg);
110 Observer->finishedChangingAllUsesOfReg();
113 return ConstrainedReg;
123 assert(Reg.isVirtual() &&
"PhysReg not implemented");
136 if (
const auto *SubRC =
TRI.getCommonSubClass(
137 OpRC,
TRI.getConstrainedRegClassForReg(Reg,
MRI)))
140 OpRC =
TRI.getAllocatableClass(OpRC);
145 "Register class constraint is required unless either the "
146 "instruction is target independent or the operand is a use");
168 "A selected instruction is expected");
173 for (
unsigned OpI = 0, OpE =
I.getNumExplicitOperands(); OpI != OpE; ++OpI) {
184 if (Reg.isPhysical())
200 int DefIdx =
I.getDesc().getOperandConstraint(OpI,
MCOI::TIED_TO);
201 if (DefIdx != -1 && !
I.isRegTiedToUseOperand(DefIdx))
202 I.tieOperands(DefIdx, OpI);
213 if (
MRI.getType(DstReg) !=
MRI.getType(SrcReg))
217 const auto &DstRBC =
MRI.getRegClassOrRegBank(DstReg);
218 if (!DstRBC || DstRBC ==
MRI.getRegClassOrRegBank(SrcReg))
225 *
MRI.getRegClassOrNull(SrcReg));
233 for (
const auto &MO :
MI.all_defs()) {
235 if (Reg.isPhysical() || !
MRI.use_nodbg_empty(Reg))
238 return MI.wouldBeTriviallyDead();
245 bool IsGlobalISelAbortEnabled =
247 bool IsFatal = Severity ==
DS_Error && IsGlobalISelAbortEnabled;
250 if (!R.getLocation().isValid() || IsFatal)
251 R << (
" (in function: " + MF.
getName() +
")").str();
277 MI.getDebugLoc(),
MI.getParent());
288 case TargetOpcode::G_SMIN:
289 return TargetOpcode::G_SMAX;
290 case TargetOpcode::G_SMAX:
291 return TargetOpcode::G_SMIN;
292 case TargetOpcode::G_UMIN:
293 return TargetOpcode::G_UMAX;
294 case TargetOpcode::G_UMAX:
295 return TargetOpcode::G_UMIN;
305 assert((!ValAndVReg || ValAndVReg->VReg == VReg) &&
306 "Value found while looking through instrs");
309 return ValAndVReg->Value;
315 assert((Const && Const->getOpcode() == TargetOpcode::G_CONSTANT) &&
316 "expected a G_CONSTANT on Reg");
317 return Const->getOperand(1).getCImm()->getValue();
320std::optional<int64_t>
323 if (Val && Val->getBitWidth() <= 64)
324 return Val->getSExtValue();
342std::optional<ValueAndVReg>
344 bool LookThroughInstrs =
true,
345 bool LookThroughAnyExt =
false) {
349 while ((
MI =
MRI.getVRegDef(VReg)) && !IsConstantOpcode(
MI) &&
351 switch (
MI->getOpcode()) {
352 case TargetOpcode::G_ANYEXT:
353 if (!LookThroughAnyExt)
356 case TargetOpcode::G_TRUNC:
357 case TargetOpcode::G_SEXT:
358 case TargetOpcode::G_ZEXT:
361 MRI.getType(
MI->getOperand(0).getReg()).getSizeInBits()));
362 VReg =
MI->getOperand(1).getReg();
364 case TargetOpcode::COPY:
365 VReg =
MI->getOperand(1).getReg();
369 case TargetOpcode::G_INTTOPTR:
370 VReg =
MI->getOperand(1).getReg();
376 if (!
MI || !IsConstantOpcode(
MI))
380 if (!GetAPCstValue(
MI, Val))
382 for (
auto &Pair :
reverse(SeenOpcodes)) {
383 switch (Pair.first) {
384 case TargetOpcode::G_TRUNC:
385 Val = Val.
trunc(Pair.second);
387 case TargetOpcode::G_ANYEXT:
388 case TargetOpcode::G_SEXT:
389 Val = Val.
sext(Pair.second);
391 case TargetOpcode::G_ZEXT:
392 Val = Val.
zext(Pair.second);
403 return MI->getOpcode() == TargetOpcode::G_CONSTANT;
409 return MI->getOpcode() == TargetOpcode::G_FCONSTANT;
415 unsigned Opc =
MI->getOpcode();
416 return Opc == TargetOpcode::G_CONSTANT ||
Opc == TargetOpcode::G_FCONSTANT;
442 return getConstantVRegValWithLookThrough<isIConstant, getCImmAsAPInt>(
443 VReg,
MRI, LookThroughInstrs);
448 bool LookThroughAnyExt) {
449 return getConstantVRegValWithLookThrough<isAnyConstant,
450 getCImmOrFPImmAsAPInt>(
451 VReg,
MRI, LookThroughInstrs, LookThroughAnyExt);
457 getConstantVRegValWithLookThrough<isFConstant, getCImmOrFPImmAsAPInt>(
458 VReg,
MRI, LookThroughInstrs);
462 unsigned Width = Reg->Value.getBitWidth();
463 LLT Ty =
MRI.getType(VReg);
465 Ty = Ty.getScalarType();
468 if (Ty.isFloat() && Ty.getSizeInBits() == Width)
480 if (Width != 16 && Width != 32 && Width != 64 && Width != 128)
489 if (TargetOpcode::G_FCONSTANT !=
MI->getOpcode())
491 return MI->getOperand(1).getFPImm();
494std::optional<DefinitionAndSourceRegister>
499 auto DefIt =
MRI.def_begin(Reg);
500 if (DefIt ==
MRI.def_end())
504 auto DstTy =
MRI.getType(DefOpnd.
getReg());
505 if (!DstTy.isValid())
510 auto SrcTy =
MRI.getType(SrcReg);
511 if (!SrcTy.isValid())
522 std::optional<DefinitionAndSourceRegister> DefSrcReg =
524 return DefSrcReg ? DefSrcReg->MI :
nullptr;
529 std::optional<DefinitionAndSourceRegister> DefSrcReg =
531 return DefSrcReg ? DefSrcReg->Reg :
Register();
556 if (LeftoverSize == 0) {
558 VRegs.
push_back(
MRI.createGenericVirtualRegister(MainTy));
571 unsigned LeftoverNumElts = RegNumElts % MainNumElts;
573 if (MainNumElts % LeftoverNumElts == 0 &&
574 RegNumElts % LeftoverNumElts == 0 &&
576 LeftoverNumElts > 1) {
581 extractParts(Reg, LeftoverTy, RegNumElts / LeftoverNumElts, UnmergeValues,
585 unsigned LeftoverPerMain = MainNumElts / LeftoverNumElts;
586 unsigned NumOfLeftoverVal =
587 ((RegNumElts % MainNumElts) / LeftoverNumElts);
591 for (
unsigned I = 0;
I < UnmergeValues.
size() - NumOfLeftoverVal;
I++) {
593 if (MergeValues.
size() == LeftoverPerMain) {
600 for (
unsigned I = UnmergeValues.
size() - NumOfLeftoverVal;
601 I < UnmergeValues.
size();
I++) {
612 for (
unsigned i = 0; i < RegPieces.
size() - 1; ++i)
615 LeftoverTy =
MRI.getType(LeftoverRegs[0]);
622 Register NewReg =
MRI.createGenericVirtualRegister(MainTy);
629 Register NewReg =
MRI.createGenericVirtualRegister(LeftoverTy);
641 LLT RegTy =
MRI.getType(Reg);
647 unsigned LeftoverNumElts = RegNumElts % NumElts;
648 unsigned NumNarrowTyPieces = RegNumElts / NumElts;
651 if (LeftoverNumElts == 0)
652 return extractParts(Reg, NarrowTy, NumNarrowTyPieces, VRegs, MIRBuilder,
663 for (
unsigned i = 0; i < NumNarrowTyPieces; ++i,
Offset += NumElts) {
669 if (LeftoverNumElts == 1) {
697 const APInt &
C1 = MaybeOp1Cst->Value;
698 const APInt &C2 = MaybeOp2Cst->Value;
702 case TargetOpcode::G_ADD:
704 case TargetOpcode::G_PTR_ADD:
707 return C1 + C2.sextOrTrunc(
C1.getBitWidth());
708 case TargetOpcode::G_AND:
710 case TargetOpcode::G_ASHR:
712 case TargetOpcode::G_LSHR:
714 case TargetOpcode::G_MUL:
716 case TargetOpcode::G_OR:
718 case TargetOpcode::G_SHL:
720 case TargetOpcode::G_SUB:
722 case TargetOpcode::G_XOR:
724 case TargetOpcode::G_UDIV:
725 if (!C2.getBoolValue())
728 case TargetOpcode::G_SDIV:
729 if (!C2.getBoolValue())
732 case TargetOpcode::G_UREM:
733 if (!C2.getBoolValue())
736 case TargetOpcode::G_SREM:
737 if (!C2.getBoolValue())
740 case TargetOpcode::G_SMIN:
742 case TargetOpcode::G_SMAX:
744 case TargetOpcode::G_UMIN:
746 case TargetOpcode::G_UMAX:
753std::optional<APFloat>
767 case TargetOpcode::G_FADD:
770 case TargetOpcode::G_FSUB:
773 case TargetOpcode::G_FMUL:
776 case TargetOpcode::G_FDIV:
779 case TargetOpcode::G_FREM:
782 case TargetOpcode::G_FCOPYSIGN:
785 case TargetOpcode::G_FMINNUM:
787 case TargetOpcode::G_FMAXNUM:
789 case TargetOpcode::G_FMINIMUM:
791 case TargetOpcode::G_FMAXIMUM:
793 case TargetOpcode::G_FMINIMUMNUM:
795 case TargetOpcode::G_FMAXIMUMNUM:
797 case TargetOpcode::G_FMINNUM_IEEE:
798 case TargetOpcode::G_FMAXNUM_IEEE:
820 auto [Dst, DstTy, Src, SrcTy] = Bitcast->getFirst2RegLLTs();
821 if (!SrcTy.isVector() || !DstTy.isVector())
823 if (SrcTy.getElementCount() != DstTy.getElementCount())
825 if (SrcTy.getScalarSizeInBits() != DstTy.getScalarSizeInBits())
844 for (
unsigned Idx = 0, E = SrcVec1->getNumSources(); Idx < E; ++Idx) {
846 SrcVec2->getSourceReg(Idx),
MRI);
851 return FoldedElements;
869 for (
unsigned Idx = 0, E = SrcVec1->getNumSources(); Idx < E; ++Idx) {
871 SrcVec2->getSourceReg(Idx),
MRI);
876 return FoldedElements;
890 return V->getPointerAlignment(M->getDataLayout());
908 assert(Def->getParent() == &EntryMBB &&
"live-in copy not in entry block");
919 MRI.setType(LiveIn, RegTy);
937 case TargetOpcode::G_SEXT_INREG: {
938 LLT Ty =
MRI.getType(Op1);
939 return MaybeOp1Cst->trunc(
Imm).sext(Ty.getScalarSizeInBits());
956 case TargetOpcode::G_SEXT:
957 return Val->sext(DstSize);
958 case TargetOpcode::G_ZEXT:
959 case TargetOpcode::G_ANYEXT:
961 return Val->zext(DstSize);
969std::optional<APFloat>
972 assert(Opcode == TargetOpcode::G_SITOFP || Opcode == TargetOpcode::G_UITOFP);
986 auto Fold = [Opcode, EltBits](
const APInt &V) ->
APInt {
988 case TargetOpcode::G_CTLZ:
989 case TargetOpcode::G_CTLZ_ZERO_POISON:
990 return APInt(EltBits, V.countl_zero());
991 case TargetOpcode::G_CTTZ:
992 case TargetOpcode::G_CTTZ_ZERO_POISON:
993 return APInt(EltBits, V.countr_zero());
994 case TargetOpcode::G_CTPOP:
995 return APInt(EltBits, V.popcount());
996 case TargetOpcode::G_ABS:
998 case TargetOpcode::G_BSWAP:
1000 case TargetOpcode::G_BITREVERSE:
1001 return V.reverseBits();
1006 auto tryFoldScalar = [&](
Register R) -> std::optional<APInt> {
1008 return Fold(*MaybeCst);
1009 return std::nullopt;
1011 if (
MRI.getType(Src).isVector()) {
1016 for (
unsigned SrcIdx = 0; SrcIdx < BV->getNumSources(); ++SrcIdx) {
1017 if (
auto MaybeFold = tryFoldScalar(BV->getSourceReg(SrcIdx))) {
1018 Folded.emplace_back(std::move(*MaybeFold));
1025 if (
auto MaybeCst = tryFoldScalar(Src))
1026 return {std::move(*MaybeCst)};
1034 auto Fold = [Opcode, DstEltTy,
1035 &
MRI](
const APFloat &V) -> std::optional<APFloat> {
1039 case TargetOpcode::G_FNEG:
1040 Result.changeSign();
1042 case TargetOpcode::G_FABS:
1045 case TargetOpcode::G_FCEIL:
1048 case TargetOpcode::G_FFLOOR:
1051 case TargetOpcode::G_INTRINSIC_TRUNC:
1054 case TargetOpcode::G_INTRINSIC_ROUND:
1057 case TargetOpcode::G_INTRINSIC_ROUNDEVEN:
1058 case TargetOpcode::G_FRINT:
1059 case TargetOpcode::G_FNEARBYINT:
1062 case TargetOpcode::G_FPEXT:
1063 case TargetOpcode::G_FPTRUNC:
1067 case TargetOpcode::G_FSQRT:
1068 case TargetOpcode::G_FLOG2: {
1073 return std::nullopt;
1075 MRI.getMF().getFunction().getContext(), FltSem);
1076 Constant *
C = Opcode == TargetOpcode::G_FSQRT
1080 return std::nullopt;
1088 auto tryFoldScalar = [&](
Register R) -> std::optional<APFloat> {
1090 return Fold(Cst->getValueAPF());
1091 return std::nullopt;
1093 if (
MRI.getType(Src).isVector()) {
1098 for (
unsigned SrcIdx = 0; SrcIdx < BV->getNumSources(); ++SrcIdx) {
1099 if (
auto MaybeFold = tryFoldScalar(BV->getSourceReg(SrcIdx))) {
1100 Folded.emplace_back(std::move(*MaybeFold));
1107 if (
auto MaybeCst = tryFoldScalar(Src))
1108 return {std::move(*MaybeCst)};
1112std::optional<SmallVector<APInt>>
1114 unsigned DstScalarSizeInBits,
unsigned ExtOp,
1116 assert(ExtOp == TargetOpcode::G_SEXT || ExtOp == TargetOpcode::G_ZEXT ||
1117 ExtOp == TargetOpcode::G_ANYEXT);
1119 const LLT Ty =
MRI.getType(Op1);
1121 auto GetICmpResultCst = [&](
bool IsTrue) {
1123 return ExtOp == TargetOpcode::G_SEXT
1129 auto TryFoldScalar = [&](
Register LHS,
Register RHS) -> std::optional<APInt> {
1132 return std::nullopt;
1135 return std::nullopt;
1139 return GetICmpResultCst(LHSCst->eq(*RHSCst));
1141 return GetICmpResultCst(LHSCst->ne(*RHSCst));
1143 return GetICmpResultCst(LHSCst->ugt(*RHSCst));
1145 return GetICmpResultCst(LHSCst->uge(*RHSCst));
1147 return GetICmpResultCst(LHSCst->ult(*RHSCst));
1149 return GetICmpResultCst(LHSCst->ule(*RHSCst));
1151 return GetICmpResultCst(LHSCst->sgt(*RHSCst));
1153 return GetICmpResultCst(LHSCst->sge(*RHSCst));
1155 return GetICmpResultCst(LHSCst->slt(*RHSCst));
1157 return GetICmpResultCst(LHSCst->sle(*RHSCst));
1159 return std::nullopt;
1165 if (Ty.isVector()) {
1170 return std::nullopt;
1171 assert(BV1->getNumSources() == BV2->getNumSources() &&
"Invalid vectors");
1172 for (
unsigned I = 0;
I < BV1->getNumSources(); ++
I) {
1173 if (
auto MaybeFold =
1174 TryFoldScalar(BV1->getSourceReg(
I), BV2->getSourceReg(
I))) {
1178 return std::nullopt;
1183 if (
auto MaybeCst = TryFoldScalar(Op1, Op2)) {
1188 return std::nullopt;
1194 std::optional<DefinitionAndSourceRegister> DefSrcReg =
1200 const LLT Ty =
MRI.getType(Reg);
1202 auto IsPow2 = [OrNegative, OrZero](
const APInt &V) {
1203 return V.isPowerOf2() || (OrNegative && V.isNegatedPowerOf2()) ||
1204 (OrZero && V.isZero());
1207 switch (
MI.getOpcode()) {
1208 case TargetOpcode::G_CONSTANT: {
1209 unsigned BitWidth = Ty.getScalarSizeInBits();
1213 case TargetOpcode::G_SHL: {
1233 case TargetOpcode::G_LSHR: {
1235 if (ConstLHS->isSignMask())
1249 case TargetOpcode::G_TRUNC: {
1260 case TargetOpcode::G_BUILD_VECTOR: {
1269 case TargetOpcode::G_BUILD_VECTOR_TRUNC: {
1272 const unsigned BitWidth = Ty.getScalarSizeInBits();
1275 if (!Const || !IsPow2(Const->zextOrTrunc(
BitWidth)))
1293 return (
Known.countMaxPopulation() == 1) && (
Known.countMinPopulation() == 1);
1316 "getLCMType not implemented between fixed and scalable vectors.");
1336 LLT VecTy = OrigTy.
isVector() ? OrigTy : TargetTy;
1337 LLT ScalarTy = OrigTy.
isVector() ? TargetTy : OrigTy;
1372 "getCoverTy not implemented between fixed and scalable vectors.");
1380 if (OrigTyNumElts % TargetTyNumElts == 0)
1383 unsigned NumElts =
alignTo(OrigTyNumElts, TargetTyNumElts);
1403 "getGCDType not implemented between fixed and scalable vectors.");
1443 assert(
MI.getOpcode() == TargetOpcode::G_SHUFFLE_VECTOR &&
1444 "Only G_SHUFFLE_VECTOR can have a splat index!");
1446 auto FirstDefinedIdx =
find_if(Mask, [](
int Elt) {
return Elt >= 0; });
1450 if (FirstDefinedIdx == Mask.end())
1455 int SplatValue = *FirstDefinedIdx;
1457 [&SplatValue](
int Elt) { return Elt >= 0 && Elt != SplatValue; }))
1458 return std::nullopt;
1464 return Opcode == TargetOpcode::G_BUILD_VECTOR ||
1465 Opcode == TargetOpcode::G_BUILD_VECTOR_TRUNC;
1470std::optional<ValueAndVReg> getAnyConstantSplat(
Register VReg,
1475 return std::nullopt;
1477 bool isConcatVectorsOp =
MI->getOpcode() == TargetOpcode::G_CONCAT_VECTORS;
1479 return std::nullopt;
1481 std::optional<ValueAndVReg> SplatValAndReg;
1486 auto ElementValAndReg =
1488 ? getAnyConstantSplat(Element,
MRI, AllowUndef)
1492 if (!ElementValAndReg) {
1495 return std::nullopt;
1499 if (!SplatValAndReg)
1500 SplatValAndReg = ElementValAndReg;
1503 if (SplatValAndReg->Value != ElementValAndReg->Value)
1504 return std::nullopt;
1507 return SplatValAndReg;
1514 int64_t SplatValue,
bool AllowUndef) {
1515 if (
auto SplatValAndReg = getAnyConstantSplat(Reg,
MRI, AllowUndef))
1516 return SplatValAndReg->Value.getSExtValue() == SplatValue;
1523 const APInt &SplatValue,
1525 if (
auto SplatValAndReg = getAnyConstantSplat(Reg,
MRI, AllowUndef)) {
1526 if (SplatValAndReg->Value.getBitWidth() < SplatValue.
getBitWidth())
1528 SplatValAndReg->Value.sext(SplatValue.
getBitWidth()), SplatValue);
1530 SplatValAndReg->Value,
1531 SplatValue.
sext(SplatValAndReg->Value.getBitWidth()));
1539 int64_t SplatValue,
bool AllowUndef) {
1546 const APInt &SplatValue,
1554 if (
auto SplatValAndReg =
1555 getAnyConstantSplat(Reg,
MRI,
false)) {
1556 if (std::optional<ValueAndVReg> ValAndVReg =
1558 return ValAndVReg->Value;
1561 return std::nullopt;
1570std::optional<int64_t>
1573 if (
auto SplatValAndReg =
1574 getAnyConstantSplat(Reg,
MRI,
false))
1576 return std::nullopt;
1579std::optional<int64_t>
1585std::optional<FPValueAndVReg>
1588 if (
auto SplatValAndReg = getAnyConstantSplat(VReg,
MRI, AllowUndef))
1590 return std::nullopt;
1607 unsigned Opc =
MI.getOpcode();
1608 if (
Opc == TargetOpcode::G_SPLAT_VECTOR)
1609 return MI.getOperand(1).getReg();
1612 return std::nullopt;
1613 auto Reg =
MI.getOperand(1).getReg();
1616 return std::nullopt;
1622 bool AllowFP =
true,
1623 bool AllowOpaqueConstants =
true) {
1624 switch (
MI.getOpcode()) {
1625 case TargetOpcode::G_CONSTANT:
1626 case TargetOpcode::G_IMPLICIT_DEF:
1628 case TargetOpcode::G_FCONSTANT:
1630 case TargetOpcode::G_GLOBAL_VALUE:
1631 case TargetOpcode::G_FRAME_INDEX:
1632 case TargetOpcode::G_BLOCK_ADDR:
1633 case TargetOpcode::G_JUMP_TABLE:
1634 return AllowOpaqueConstants;
1648 for (
unsigned SrcIdx = 0; SrcIdx < BV->
getNumSources(); ++SrcIdx) {
1659 bool AllowFP,
bool AllowOpaqueConstants) {
1666 const unsigned NumOps =
MI.getNumOperands();
1667 for (
unsigned I = 1;
I !=
NumOps; ++
I) {
1683 return std::nullopt;
1684 const unsigned ScalarSize =
MRI.getType(Def).getScalarSizeInBits();
1685 return APInt(ScalarSize, *MaybeCst,
true);
1688std::optional<APFloat>
1692 return FpConst->Value;
1695 return std::nullopt;
1696 return MaybeCstFP->Value;
1701 switch (
MI.getOpcode()) {
1702 case TargetOpcode::G_IMPLICIT_DEF:
1704 case TargetOpcode::G_CONSTANT:
1705 return MI.getOperand(1).getCImm()->isNullValue();
1706 case TargetOpcode::G_FCONSTANT: {
1720 switch (
MI.getOpcode()) {
1721 case TargetOpcode::G_IMPLICIT_DEF:
1723 case TargetOpcode::G_CONSTANT:
1724 return MI.getOperand(1).getCImm()->isAllOnesValue();
1738 if (AllowUndefs && Def->getOpcode() == TargetOpcode::G_IMPLICIT_DEF)
1739 return Match(
nullptr);
1742 if (Def->getOpcode() == TargetOpcode::G_CONSTANT)
1743 return Match(Def->getOperand(1).getCImm());
1745 if (Def->getOpcode() != TargetOpcode::G_BUILD_VECTOR)
1748 for (
unsigned I = 1, E = Def->getNumOperands();
I != E; ++
I) {
1749 Register SrcElt = Def->getOperand(
I).getReg();
1751 if (AllowUndefs && SrcDef->
getOpcode() == TargetOpcode::G_IMPLICIT_DEF) {
1752 if (!Match(
nullptr))
1757 if (SrcDef->
getOpcode() != TargetOpcode::G_CONSTANT ||
1767 switch (
TLI.getBooleanContents(IsVector, IsFP)) {
1779 bool IsVector,
bool IsFP) {
1780 switch (
TLI.getBooleanContents(IsVector, IsFP)) {
1792 switch (
TLI.getBooleanContents(IsVector, IsFP)) {
1806 if (
Op.isReg() &&
Op.getReg().isVirtual())
1807 DeadInstChain.
insert(
MRI.getVRegDef(
Op.getReg()));
1812 MI.eraseFromParent();
1824 while (!DeadInstChain.
empty()) {
1838 for (
auto &Def :
MI.defs()) {
1839 assert(Def.isReg() &&
"Must be a reg");
1842 for (
auto &MOUse :
MRI.use_operands(Def.getReg())) {
1850 if (!DbgUsers.
empty()) {
1856 MRI.markUsesInDebugValueAsUndef(Def.getReg());
1862 case TargetOpcode::G_FABS:
1863 case TargetOpcode::G_FADD:
1864 case TargetOpcode::G_FCANONICALIZE:
1865 case TargetOpcode::G_FCEIL:
1866 case TargetOpcode::G_FCONSTANT:
1867 case TargetOpcode::G_FCOPYSIGN:
1868 case TargetOpcode::G_FCOS:
1869 case TargetOpcode::G_FDIV:
1870 case TargetOpcode::G_FEXP2:
1871 case TargetOpcode::G_FEXP:
1872 case TargetOpcode::G_FFLOOR:
1873 case TargetOpcode::G_FLOG10:
1874 case TargetOpcode::G_FLOG2:
1875 case TargetOpcode::G_FLOG:
1876 case TargetOpcode::G_FMA:
1877 case TargetOpcode::G_FMAD:
1878 case TargetOpcode::G_FMAXIMUM:
1879 case TargetOpcode::G_FMAXIMUMNUM:
1880 case TargetOpcode::G_FMAXNUM:
1881 case TargetOpcode::G_FMAXNUM_IEEE:
1882 case TargetOpcode::G_FMINIMUM:
1883 case TargetOpcode::G_FMINIMUMNUM:
1884 case TargetOpcode::G_FMINNUM:
1885 case TargetOpcode::G_FMINNUM_IEEE:
1886 case TargetOpcode::G_FMUL:
1887 case TargetOpcode::G_FNEARBYINT:
1888 case TargetOpcode::G_FNEG:
1889 case TargetOpcode::G_FPEXT:
1890 case TargetOpcode::G_FPEXTLOAD:
1891 case TargetOpcode::G_FPOW:
1892 case TargetOpcode::G_FPTRUNC:
1893 case TargetOpcode::G_FPTRUNCSTORE:
1894 case TargetOpcode::G_FREM:
1895 case TargetOpcode::G_FRINT:
1896 case TargetOpcode::G_FSIN:
1897 case TargetOpcode::G_FTAN:
1898 case TargetOpcode::G_FACOS:
1899 case TargetOpcode::G_FASIN:
1900 case TargetOpcode::G_FATAN:
1901 case TargetOpcode::G_FATAN2:
1902 case TargetOpcode::G_FCOSH:
1903 case TargetOpcode::G_FSINH:
1904 case TargetOpcode::G_FTANH:
1905 case TargetOpcode::G_FSQRT:
1906 case TargetOpcode::G_FSUB:
1907 case TargetOpcode::G_INTRINSIC_ROUND:
1908 case TargetOpcode::G_INTRINSIC_ROUNDEVEN:
1909 case TargetOpcode::G_INTRINSIC_TRUNC:
1919 LLT Ty =
MRI.getType(ShiftAmount);
1921 if (Ty.isScalableVector())
1924 if (Ty.isScalar()) {
1925 std::optional<ValueAndVReg> Val =
1929 return Val->Value.ult(Ty.getScalarSizeInBits());
1937 for (
unsigned I = 0;
I < Sources; ++
I) {
1938 std::optional<ValueAndVReg> Val =
1942 if (!Val->Value.ult(Ty.getScalarSizeInBits()))
1950 bool ConsiderFlagsAndMetadata,
1956 if (GMI->hasPoisonGeneratingFlags())
1961 case TargetOpcode::G_BUILD_VECTOR:
1962 case TargetOpcode::G_CONSTANT_FOLD_BARRIER:
1964 case TargetOpcode::G_SHL:
1965 case TargetOpcode::G_ASHR:
1966 case TargetOpcode::G_LSHR:
1969 case TargetOpcode::G_FPTOSI:
1970 case TargetOpcode::G_FPTOUI:
1974 case TargetOpcode::G_CTLZ:
1975 case TargetOpcode::G_CTTZ:
1976 case TargetOpcode::G_CTLS:
1977 case TargetOpcode::G_ABS:
1978 case TargetOpcode::G_CTPOP:
1979 case TargetOpcode::G_BSWAP:
1980 case TargetOpcode::G_BITREVERSE:
1981 case TargetOpcode::G_FSHL:
1982 case TargetOpcode::G_FSHR:
1983 case TargetOpcode::G_SMAX:
1984 case TargetOpcode::G_SMIN:
1985 case TargetOpcode::G_SCMP:
1986 case TargetOpcode::G_UMAX:
1987 case TargetOpcode::G_UMIN:
1988 case TargetOpcode::G_UCMP:
1989 case TargetOpcode::G_PTRMASK:
1990 case TargetOpcode::G_SADDO:
1991 case TargetOpcode::G_SSUBO:
1992 case TargetOpcode::G_UADDO:
1993 case TargetOpcode::G_USUBO:
1994 case TargetOpcode::G_SMULO:
1995 case TargetOpcode::G_UMULO:
1996 case TargetOpcode::G_SADDSAT:
1997 case TargetOpcode::G_UADDSAT:
1998 case TargetOpcode::G_SSUBSAT:
1999 case TargetOpcode::G_USUBSAT:
2000 case TargetOpcode::G_SBFX:
2001 case TargetOpcode::G_UBFX:
2003 case TargetOpcode::G_SSHLSAT:
2004 case TargetOpcode::G_USHLSAT:
2007 case TargetOpcode::G_INSERT_VECTOR_ELT: {
2010 std::optional<ValueAndVReg> Index =
2014 LLT VecTy =
MRI.getType(Insert->getVectorReg());
2019 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
2022 std::optional<ValueAndVReg> Index =
2031 case TargetOpcode::G_SHUFFLE_VECTOR: {
2036 case TargetOpcode::G_FNEG:
2037 case TargetOpcode::G_PHI:
2038 case TargetOpcode::G_SELECT:
2039 case TargetOpcode::G_UREM:
2040 case TargetOpcode::G_SREM:
2041 case TargetOpcode::G_FREEZE:
2042 case TargetOpcode::G_ICMP:
2043 case TargetOpcode::G_FCMP:
2044 case TargetOpcode::G_FADD:
2045 case TargetOpcode::G_FSUB:
2046 case TargetOpcode::G_FMUL:
2047 case TargetOpcode::G_FDIV:
2048 case TargetOpcode::G_FREM:
2049 case TargetOpcode::G_PTR_ADD:
2066 case TargetOpcode::G_FREEZE:
2068 case TargetOpcode::G_IMPLICIT_DEF:
2070 case TargetOpcode::G_CONSTANT:
2071 case TargetOpcode::G_FCONSTANT:
2073 case TargetOpcode::G_BUILD_VECTOR: {
2076 for (
unsigned I = 0;
I < NumSources; ++
I)
2082 case TargetOpcode::G_PHI: {
2084 unsigned NumIncoming = Phi->getNumIncomingValues();
2085 for (
unsigned I = 0;
I < NumIncoming; ++
I)
2095 return ::isGuaranteedNotToBeUndefOrPoison(MO.getReg(),
MRI,
Depth + 1,
2106 bool ConsiderFlagsAndMetadata) {
2107 return ::canCreateUndefOrPoison(Reg,
MRI, ConsiderFlagsAndMetadata,
2112 bool ConsiderFlagsAndMetadata =
true) {
2113 return ::canCreateUndefOrPoison(
Reg,
MRI, ConsiderFlagsAndMetadata,
2120 return ::isGuaranteedNotToBeUndefOrPoison(Reg,
MRI,
Depth,
2127 return ::isGuaranteedNotToBeUndefOrPoison(Reg,
MRI,
Depth,
2134 return ::isGuaranteedNotToBeUndefOrPoison(Reg,
MRI,
Depth,
2141 Ty.getElementCount());
2146 switch (
MI.getOpcode()) {
2149 case TargetOpcode::G_ASSERT_ALIGN:
2150 case TargetOpcode::G_ASSERT_SEXT:
2151 case TargetOpcode::G_ASSERT_ZEXT:
2162std::optional<GIConstant>
2167 std::optional<ValueAndVReg> MayBeConstant =
2170 return std::nullopt;
2176 unsigned NumSources = Build->getNumSources();
2177 for (
unsigned I = 0;
I < NumSources; ++
I) {
2178 Register SrcReg = Build->getSourceReg(
I);
2179 std::optional<ValueAndVReg> MayBeConstant =
2182 return std::nullopt;
2183 Values.push_back(MayBeConstant->Value);
2188 std::optional<ValueAndVReg> MayBeConstant =
2191 return std::nullopt;
2202std::optional<GFConstant>
2207 std::optional<FPValueAndVReg> MayBeConstant =
2210 return std::nullopt;
2216 unsigned NumSources = Build->getNumSources();
2217 for (
unsigned I = 0;
I < NumSources; ++
I) {
2218 Register SrcReg = Build->getSourceReg(
I);
2219 std::optional<FPValueAndVReg> MayBeConstant =
2222 return std::nullopt;
2223 Values.push_back(MayBeConstant->Value);
2228 std::optional<FPValueAndVReg> MayBeConstant =
2231 return std::nullopt;
2239 unsigned Limit,
const MemOp &
Op,
2240 unsigned DstAS,
unsigned SrcAS,
2243 if (
Op.isMemcpyOrMemmoveWithFixedDstAlign() &&
2244 Op.getSrcAlign() <
Op.getDstAlign())
2247 LLT Ty =
TLI.getOptimalMemOpLLT(
Op, FuncAttributes);
2254 if (
Op.isFixedDstAlign())
2255 while (
Op.getDstAlign() < Ty.getSizeInBytes() &&
2256 !
TLI.allowsMisalignedMemoryAccesses(Ty, DstAS,
Op.getDstAlign()))
2258 assert(Ty.getSizeInBits() > 0 &&
"Could not find valid type");
2262 unsigned NumMemOps = 0;
2265 unsigned TySize = Ty.getSizeInBytes();
2266 while (TySize >
Size) {
2276 assert(NewTySize > 0 &&
"Could not find appropriate type");
2283 if (NumMemOps && !
Op.isVolatile() && NewTySize <
Size &&
2284 TLI.allowsMisalignedMemoryAccesses(
2285 VT, DstAS,
Op.isFixedDstAlign() ?
Op.getDstAlign() :
Align(1),
2295 if (++NumMemOps > Limit)
2298 MemOps.push_back(Ty);
2308 uint64_t &KnownLen,
Align &Alignment,
2309 bool &DstAlignCanChange,
2310 std::vector<LLT> &MemOps) {
2311 const unsigned Opc =
MI.getOpcode();
2312 assert((
Opc == TargetOpcode::G_MEMCPY ||
2313 Opc == TargetOpcode::G_MEMCPY_INLINE ||
2314 Opc == TargetOpcode::G_MEMMOVE ||
Opc == TargetOpcode::G_MEMSET ||
2315 Opc == TargetOpcode::G_MEMSET_INLINE) &&
2316 "Expected memcpy like instruction");
2318 auto MMOIt =
MI.memoperands_begin();
2323 Alignment = DstAlign;
2325 std::tie(Dst, Src, Len) =
MI.getFirst3Regs();
2327 if (
Opc != TargetOpcode::G_MEMSET &&
Opc != TargetOpcode::G_MEMSET_INLINE) {
2328 assert(MMOIt !=
MI.memoperands_end() &&
"Expected a second MMO on MI");
2330 SrcAlign =
MemOp->getBaseAlign();
2331 Alignment = std::min(DstAlign, SrcAlign);
2336 if (!LenVRegAndVal) {
2338 assert(
Opc != TargetOpcode::G_MEMCPY_INLINE &&
2339 Opc != TargetOpcode::G_MEMSET_INLINE &&
2340 "inline memcpy and memset with dynamic size are not yet supported");
2344 KnownLen = LenVRegAndVal->Value.getZExtValue();
2345 DstAlignCanChange =
false;
2350 if (
Opc != TargetOpcode::G_MEMCPY_INLINE &&
2351 Opc != TargetOpcode::G_MEMSET_INLINE && MaxLen && KnownLen > MaxLen)
2366 DstAlignCanChange =
true;
2368 const auto &DstMMO = **
MI.memoperands_begin();
2372 case TargetOpcode::G_MEMCPY_INLINE:
2373 case TargetOpcode::G_MEMCPY: {
2374 const auto &SrcMMO = **std::next(
MI.memoperands_begin());
2376 uint64_t Limit =
Opc == TargetOpcode::G_MEMCPY_INLINE
2377 ? std::numeric_limits<uint64_t>::max()
2378 :
TLI.getMaxStoresPerMemcpy(OptSize);
2381 MemOp::Copy(KnownLen, DstAlignCanChange, std::min(DstAlign, SrcAlign),
2382 SrcAlign, IsVolatile),
2386 case TargetOpcode::G_MEMMOVE: {
2387 const auto &SrcMMO = **std::next(
MI.memoperands_begin());
2389 unsigned Limit =
TLI.getMaxStoresPerMemmove(OptSize);
2392 MemOp::Move(KnownLen, DstAlignCanChange, std::min(DstAlign, SrcAlign),
2393 SrcAlign, IsVolatile),
2397 case TargetOpcode::G_MEMSET:
2398 case TargetOpcode::G_MEMSET_INLINE: {
2399 unsigned Limit =
Opc == TargetOpcode::G_MEMSET_INLINE
2400 ? std::numeric_limits<unsigned>::max()
2401 :
TLI.getMaxStoresPerMemset(OptSize);
2403 bool IsZeroVal = ValVRegAndVal && ValVRegAndVal->Value == 0;
2406 MemOp::Set(KnownLen, DstAlignCanChange, DstAlign,
MachineInstrBuilder MachineInstrBuilder & DefMI
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static bool findGISelOptimalMemOpLowering(std::vector< LLT > &MemOps, unsigned Limit, const MemOp &Op, unsigned DstAS, unsigned SrcAS, const AttributeList &FuncAttributes, const TargetLowering &TLI)
static void reportGISelDiagnostic(DiagnosticSeverity Severity, MachineFunction &MF, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R)
static bool shiftAmountKnownInRange(Register ShiftAmount, const MachineRegisterInfo &MRI)
Shifts return poison if shiftwidth is larger than the bitwidth.
static bool isBuildVectorOp(unsigned Opcode)
static bool isConstantScalar(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowFP=true, bool AllowOpaqueConstants=true)
static GBuildVector * getBuildVectorLikeDef(Register Reg, const MachineRegisterInfo &MRI)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This contains common code to allow clients to notify changes to machine instr.
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
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
Tracks DebugLocs between checkpoints and verifies that they are transferred.
Implement a low-level type suitable for MachineInstr level instruction selection.
Contains matchers for matching SSA Machine Instructions.
This file declares the MachineIRBuilder class.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
uint64_t IntrinsicInst * II
MachineBasicBlock * Folded
MachineRegisterInfo & MRI
This file describes how to lower LLVM code to machine code.
Target-Independent Code Generator Pass Configuration Options pass.
This file contains the UndefPoisonKind enum and helper functions.
static const char PassName[]
Class recording the (high level) value of a variable.
static constexpr roundingMode rmTowardZero
static LLVM_ABI unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
static constexpr roundingMode rmTowardNegative
static constexpr roundingMode rmNearestTiesToEven
static constexpr roundingMode rmTowardPositive
static LLVM_ABI bool isIEEELikeFP(const fltSemantics &)
static constexpr roundingMode rmNearestTiesToAway
const fltSemantics & getSemantics() const
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
APInt bitcastToAPInt() const
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
LLVM_ABI APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static bool isSameValue(const APInt &I1, const APInt &I2, bool SignedCompare=false)
Determine if two APInts have the same value, after zero-extending or sign-extending (if SignedCompare...
LLVM_ABI APInt sext(unsigned width) const
Sign extend to a new width.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Represent the analysis usage information of a pass.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ ICMP_ULT
unsigned less than
@ ICMP_SGE
signed greater or equal
@ ICMP_ULE
unsigned less or equal
ConstantFP - Floating Point Values [float, double].
const APFloat & getValueAPF() const
bool isNegative() const
Return true if the sign bit is set.
bool isZero() const
Return true if the value is positive or negative zero.
This is the shared class of boolean and integer constants.
const APInt & getValue() const
Return the constant as an APInt value reference.
This is an important base class in LLVM.
static constexpr ElementCount getFixed(ScalarTy MinVal)
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
AttributeList getAttributes() const
Return the attribute list for this Function.
Represents a G_BUILD_VECTOR.
static LLVM_ABI std::optional< GFConstant > getConstant(Register Const, const MachineRegisterInfo &MRI)
GFConstant(ArrayRef< APFloat > Values)
LLVM_ABI APFloat getScalarValue() const
Returns the value, if this constant is a scalar.
LLVM_ABI APInt getScalarValue() const
Returns the value, if this constant is a scalar.
static LLVM_ABI std::optional< GIConstant > getConstant(Register Const, const MachineRegisterInfo &MRI)
GIConstant(ArrayRef< APInt > Values)
Abstract class that contains various methods for clients to notify about changes.
KnownBits getKnownBits(Register R)
bool isKnownNeverZero(Register R, unsigned Depth=0)
Return true if the value defined by R is provably never zero.
void insert(MachineInstr *I)
Add the specified instruction to the worklist if it isn't already in it.
MachineInstr * pop_back_val()
void remove(const MachineInstr *I)
Remove I from the worklist if it exists.
Represents an insert vector element.
Register getSourceReg(unsigned I) const
Returns the I'th source register.
unsigned getNumSources() const
Returns the number of source registers.
Represents a G_SHUFFLE_VECTOR.
ArrayRef< int > getMask() const
Represents a splat vector.
Module * getParent()
Get the module that this global value is contained inside of...
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
constexpr unsigned getScalarSizeInBits() const
static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
LLT getScalarType() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
constexpr bool isScalable() const
Returns true if the LLT is a scalable vector.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr ElementCount getElementCount() const
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
static LLT integer(unsigned SizeInBits)
constexpr TypeSize getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
static constexpr LLT scalarOrVector(ElementCount EC, LLT ScalarTy)
This is an important class for using LLVM in a threaded context.
void checkpoint(bool CheckDebugLocs=true)
Call this to indicate that it's a good point to assess whether locations have been lost.
Describe properties that are true of each instruction in the target description file.
Wrapper class representing physical registers. Should be passed by value.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
GISelChangeObserver * getObserver() const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineBasicBlock & front() const
Register addLiveIn(MCRegister PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Helper class to build MachineInstr.
MachineInstrBuilder buildUnmerge(ArrayRef< LLT > Res, const SrcOp &Op)
Build and insert Res0, ... = G_UNMERGE_VALUES Op.
MachineInstrBuilder buildExtract(const DstOp &Res, const SrcOp &Src, uint64_t Index)
Build and insert Res0, ... = G_EXTRACT Src, Idx0.
MachineInstrBuilder buildMergeLikeInstr(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ... or Res = G_BUILD_VECTOR Op0, ... or Res = G_CONCAT_VEC...
Register getReg(unsigned Idx) const
Get the register for the operand index.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
mop_range uses()
Returns all operands which may be register uses.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
MachineOperand class - Representation of each machine instruction operand.
const ConstantInt * getCImm() const
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
Register getReg() const
getReg - Returns the register number.
const ConstantFP * getFPImm() const
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A Module instance is used to store all the information related to an LLVM module.
Holds all the information related to register banks.
static const TargetRegisterClass * constrainGenericRegister(Register Reg, const TargetRegisterClass &RC, MachineRegisterInfo &MRI)
Constrain the (possibly generic) virtual register Reg to RC.
Wrapper class representing virtual and physical registers.
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...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
@ ZeroOrOneBooleanContent
@ UndefinedBooleanContent
@ ZeroOrNegativeOneBooleanContent
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
const Triple & getTargetTriple() const
GlobalISelAbortMode GlobalISelAbort
EnableGlobalISelAbort - Control abort behaviour when global instruction selection fails to lower/sele...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetLowering * getTargetLowering() const
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, DriverKit, XROS, or bridgeOS).
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI Type * getFloatingPointTy(LLVMContext &C, const fltSemantics &S)
LLVM Value Representation.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
constexpr ScalarTy getFixedValue() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be unsigned.
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
ImplicitDefMatch m_GImplicitDef()
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
DiagnosticInfoMIROptimization::MachineArgument MNV
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Register getFunctionLiveInPhysReg(MachineFunction &MF, const TargetInstrInfo &TII, MCRegister PhysReg, const TargetRegisterClass &RC, const DebugLoc &DL, LLT RegTy=LLT())
Return a virtual register corresponding to the incoming argument register PhysReg.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
LLVM_ABI std::optional< SmallVector< APInt > > ConstantFoldICmp(unsigned Pred, const Register Op1, const Register Op2, unsigned DstScalarSizeInBits, unsigned ExtOp, const MachineRegisterInfo &MRI)
LLVM_ABI std::optional< APInt > isConstantOrConstantSplatVector(Register Def, const MachineRegisterInfo &MRI)
Determines if Def defines a constant integer or a splat vector of constant integers.
LLVM_ABI bool isBuildVectorAllZeros(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndef=false)
Return true if the specified instruction is a G_BUILD_VECTOR or G_BUILD_VECTOR_TRUNC where all of the...
LLVM_ABI Type * getTypeForLLT(LLT Ty, LLVMContext &C)
Get the type back from LLT.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Register constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, MachineOperand &RegMO)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
LLVM_ABI MachineInstr * getOpcodeDef(unsigned Opcode, Register Reg, const MachineRegisterInfo &MRI)
See if Reg is defined by an single def instruction that is Opcode.
static double log2(double V)
LLVM_ABI std::optional< APFloat > isConstantOrConstantSplatVectorFP(Register Def, const MachineRegisterInfo &MRI)
Determines if Def defines a float constant integer or a splat vector of float constant integers.
LLVM_ABI const ConstantFP * getConstantFPVRegVal(Register VReg, const MachineRegisterInfo &MRI)
LLVM_ABI bool canCreatePoison(const Operator *Op, bool ConsiderFlagsAndMetadata=true)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM_ABI std::optional< APInt > getIConstantVRegVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT, return the corresponding value.
LLVM_ABI std::optional< APFloat > ConstantFoldIntToFloat(unsigned Opcode, LLT DstTy, Register Src, const MachineRegisterInfo &MRI)
LLVM_ABI std::optional< APInt > getIConstantSplatVal(const Register Reg, const MachineRegisterInfo &MRI)
LLVM_ABI bool isAllOnesOrAllOnesSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant -1 integer or a splatted vector of a constant -1 integer (with...
@ 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.
LLVM_ABI const llvm::fltSemantics & getFltSemanticForLLT(LLT Ty)
Get the appropriate floating point arithmetic semantic based on the bit size of the given scalar LLT.
LLVM_ABI std::optional< APFloat > ConstantFoldFPBinOp(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
LLVM_ABI void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
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...
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel.
LLVM_ABI bool matchUnaryPredicate(const MachineRegisterInfo &MRI, Register Reg, llvm::function_ref< bool(const Constant *ConstVal)> Match, bool AllowUndefs=false)
Attempt to match a unary predicate against a scalar/splat constant or every element of a constant G_B...
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI std::optional< APInt > ConstantFoldExtOp(unsigned Opcode, const Register Op1, uint64_t Imm, const MachineRegisterInfo &MRI)
LLVM_ABI MVT getMVTForLLT(LLT Ty)
Get a rough equivalent of an MVT for a given LLT.
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximum semantics.
GISelWorkList< 4 > SmallInstListTy
LLVM_ABI bool isNullOrNullSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant 0 integer or a splatted vector of a constant 0 integer (with n...
LLVM_ABI MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
bool isPreISelGenericOptimizationHint(unsigned Opcode)
LLVM_ABI void reportGISelWarning(MachineFunction &MF, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R)
Report an ISel warning as a missed optimization remark to the LLVMContext's diagnostic stream.
LLVM_ABI bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be undef, but may be poison.
LLVM_ABI bool isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector, bool IsFP)
Returns true if given the TargetLowering's boolean contents information, the value Val contains a tru...
LLVM_ABI LLVM_READNONE LLT getLCMType(LLT OrigTy, LLT TargetTy)
Return the least common multiple type of OrigTy and TargetTy, by changing the number of vector elemen...
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Return true if the given value is known to have exactly one bit set when defined.
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.
LLVM_ABI std::optional< APInt > ConstantFoldBinOp(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
auto dyn_cast_or_null(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI const APInt & getIConstantFromReg(Register VReg, const MachineRegisterInfo &MRI)
VReg is defined by a G_CONSTANT, return the corresponding value.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2008 maxNum semantics.
LLVM_ABI bool isConstantOrConstantVector(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowFP=true, bool AllowOpaqueConstants=true)
Return true if the specified instruction is known to be a constant, or a vector of constants.
constexpr unsigned MaxAnalysisRecursionDepth
auto reverse(ContainerTy &&C)
LLVM_ABI bool canReplaceReg(Register DstReg, Register SrcReg, MachineRegisterInfo &MRI)
Check if DstReg can be replaced with SrcReg depending on the register constraints.
LLVM_READONLY APFloat minimumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimumNumber semantics.
LLVM_ABI void saveUsesAndErase(MachineInstr &MI, MachineRegisterInfo &MRI, LostDebugLocObserver *LocObserver, SmallInstListTy &DeadInstChain)
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 uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
LLVM_ABI std::optional< ValueAndVReg > getAnyConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true, bool LookThroughAnyExt=false)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_CONSTANT or G_FCONST...
LLVM_ABI bool isBuildVectorAllOnes(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndef=false)
Return true if the specified instruction is a G_BUILD_VECTOR or G_BUILD_VECTOR_TRUNC where all of the...
LLVM_ABI bool canCreateUndefOrPoison(const Operator *Op, bool ConsiderFlagsAndMetadata=true)
canCreateUndefOrPoison returns true if Op can create undef or poison from non-undef & non-poison oper...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI SmallVector< APInt > ConstantFoldVectorBinop(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
Tries to constant fold a vector binop with sources Op1 and Op2.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI std::optional< FPValueAndVReg > getFConstantSplat(Register VReg, const MachineRegisterInfo &MRI, bool AllowUndef=true)
Returns a floating point scalar constant of a build vector splat if it exists.
bool includesPoison(UndefPoisonKind Kind)
Returns true if Kind includes the Poison bit.
LLVM_ABI std::optional< APInt > ConstantFoldCastOp(unsigned Opcode, LLT DstTy, const Register Op0, const MachineRegisterInfo &MRI)
LLVM_ABI void extractParts(Register Reg, LLT Ty, int NumParts, SmallVectorImpl< Register > &VRegs, MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
Helper function to split a wide generic register into bitwise blocks with the given Type (which impli...
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
LLVM_ABI bool canLowerMemCpyFamily(const MachineInstr &MI, const MachineRegisterInfo &MRI, unsigned MaxLen, Register &Dst, Register &Src, uint64_t &KnownLen, Align &Alignment, bool &DstAlignCanChange, std::vector< LLT > &MemOps)
Matcher for memcpy-like instructions.
LLVM_ABI LLVM_READNONE LLT getCoverTy(LLT OrigTy, LLT TargetTy)
Return smallest type that covers both OrigTy and TargetTy and is multiple of TargetTy.
bool includesUndef(UndefPoisonKind Kind)
Returns true if Kind includes the Undef bit.
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2008 minNum semantics.
LLVM_ABI SmallVector< APFloat > ConstantFoldUnaryFPOp(unsigned Opcode, LLT DstTy, Register Src, const MachineRegisterInfo &MRI)
Tries to constant fold a unary floating-point operation on Src.
LLVM_ABI unsigned getInverseGMinMaxOpcode(unsigned MinMaxOpc)
Returns the inverse opcode of MinMaxOpc, which is a generic min/max opcode like G_SMIN.
LLVM_ABI SmallVector< APFloat > ConstantFoldVectorFPBinop(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
Tries to constant fold a vector floating-point binop with sources Op1 and Op2.
@ Mul
Product of integers.
@ Fast
Assign the register banks as fast as possible (default).
bool isTargetSpecificOpcode(unsigned Opcode)
Check whether the given Opcode is a target-specific opcode.
DWARFExpression::Operation Op
LLVM_ABI bool isGuaranteedNotToBeUndefOrPoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Return true if this function can prove that V does not have undef bits and is never poison.
LLVM_ABI std::optional< FPValueAndVReg > getFConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_FCONSTANT returns it...
LLVM_ABI bool isConstFalseVal(const TargetLowering &TLI, int64_t Val, bool IsVector, bool IsFP)
constexpr unsigned BitWidth
LLVM_ABI bool isBuildVectorConstantSplat(const Register Reg, const MachineRegisterInfo &MRI, int64_t SplatValue, bool AllowUndef)
Return true if the specified register is defined by G_BUILD_VECTOR or G_BUILD_VECTOR_TRUNC where all ...
LLVM_ABI void eraseInstr(MachineInstr &MI, MachineRegisterInfo &MRI, LostDebugLocObserver *LocObserver=nullptr)
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
LLVM_ABI Register constrainRegToClass(MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, Register Reg, const TargetRegisterClass &RegClass)
Try to constrain Reg to the specified register class.
LLVM_ABI int64_t getICmpTrueVal(const TargetLowering &TLI, bool IsVector, bool IsFP)
Returns an integer representing true, as defined by the TargetBooleanContents.
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...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
UndefPoisonKind
Enumeration to track whether we are interested in Undef, Poison, or both.
LLVM_ABI bool isPreISelGenericFloatingPointOpcode(unsigned Opc)
Returns whether opcode Opc is a pre-isel generic floating-point opcode, having only floating-point op...
LLVM_ABI std::optional< DefinitionAndSourceRegister > getDefSrcRegIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, and underlying value Register folding away any copies.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
LLVM_ABI SmallVector< APInt > ConstantFoldUnaryIntOp(unsigned Opcode, LLT DstTy, Register Src, const MachineRegisterInfo &MRI)
Tries to constant fold a unary integer operation (G_CTLZ, G_CTTZ, G_CTPOP and their _ZERO_POISON vari...
LLVM_ABI std::optional< Register > getVectorSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI)
LLVM_ABI void eraseInstrs(ArrayRef< MachineInstr * > DeadInstrs, MachineRegisterInfo &MRI, LostDebugLocObserver *LocObserver=nullptr)
LLVM_ABI void salvageDebugInfoForDbgValue(const MachineRegisterInfo &MRI, MachineInstr &MI, ArrayRef< MachineOperand * > DbgUsers)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
LLVM_ABI Register getSrcRegIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the source register for Reg, folding away any trivial copies.
LLVM_ABI LLVM_READNONE LLT getGCDType(LLT OrigTy, LLT TargetTy)
Return a type where the total size is the greatest common divisor of OrigTy and TargetTy.
LLVM_ABI bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be poison, but may be undef.
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimum semantics.
LLVM_READONLY APFloat maximumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximumNumber semantics.
LLVM_ABI std::optional< int64_t > getIConstantSplatSExtVal(const Register Reg, const MachineRegisterInfo &MRI)
LLVM_ABI bool isAssertMI(const MachineInstr &MI)
Returns true if the instruction MI is one of the assert instructions.
LLVM_ABI void extractVectorParts(Register Reg, unsigned NumElts, SmallVectorImpl< Register > &VRegs, MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
Version which handles irregular sub-vector splits.
LLVM_ABI Constant * ConstantFoldFP(double(*NativeFP)(double), const APFloat &V, Type *Ty, DenormalMode DenormMode=DenormalMode::getIEEE())
Evaluate NativeFP on V using the host libm, then convert the result to Ty.
LLVM_ABI int getSplatIndex(ArrayRef< int > Mask)
If all non-negative Mask elements are the same value, return that value.
LLVM_ABI bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
Check whether an instruction MI is dead: it only defines dead virtual registers, and doesn't have oth...
MCRegisterClass TargetRegisterClass
LLVM_ABI Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO)
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Simple struct used to hold a Register value and the instruction which defines it.
This class contains a discriminated union of information about pointers in memory operands,...
LLVM_ABI unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
int64_t Offset
Offset - This is an offset from the base Value*.
PointerUnion< const Value *, const PseudoSourceValue * > V
This is the IR pointer value for the access, or it is null if unknown.
static MemOp Set(uint64_t Size, bool DstAlignCanChange, Align DstAlign, bool IsZeroMemset, bool IsVolatile)
static MemOp Copy(uint64_t Size, bool DstAlignCanChange, Align DstAlign, Align SrcAlign, bool IsVolatile, bool MemcpyStrSrc=false)
static MemOp Move(uint64_t Size, bool DstAlignCanChange, Align DstAlign, Align SrcAlign, bool IsVolatile)
Simple struct used to hold a constant integer value and a virtual register.