21#include "llvm/IR/IntrinsicsHexagon.h"
30static const MVT LegalV64[] = { MVT::v64i8, MVT::v32i16, MVT::v16i32 };
31static const MVT LegalW64[] = { MVT::v128i8, MVT::v64i16, MVT::v32i32 };
32static const MVT LegalV128[] = { MVT::v128i8, MVT::v64i16, MVT::v32i32 };
33static const MVT LegalW128[] = { MVT::v256i8, MVT::v128i16, MVT::v64i32 };
42 return std::make_tuple(5, 15, 10);
44 return std::make_tuple(8, 127, 23);
46 return std::make_tuple(11, 1023, 52);
54HexagonTargetLowering::initializeHVXLowering() {
55 if (Subtarget.useHVX64BOps()) {
73 }
else if (Subtarget.useHVX128BOps()) {
83 if (Subtarget.useHVXV68Ops() && Subtarget.useHVXFloatingPoint()) {
89 if (Subtarget.useHVXV81Ops()) {
97 bool Use64b = Subtarget.useHVX64BOps();
100 MVT ByteV = Use64b ? MVT::v64i8 : MVT::v128i8;
101 MVT WordV = Use64b ? MVT::v16i32 : MVT::v32i32;
102 MVT ByteW = Use64b ? MVT::v128i8 : MVT::v256i8;
104 auto setPromoteTo = [
this] (
unsigned Opc, MVT FromTy, MVT ToTy) {
122 if (Subtarget.useHVX128BOps()) {
132 if (Subtarget.useHVX128BOps() && Subtarget.useHVXV68Ops() &&
133 Subtarget.useHVXFloatingPoint()) {
135 static const MVT FloatV[] = { MVT::v64f16, MVT::v32f32 };
136 static const MVT FloatW[] = { MVT::v128f16, MVT::v64f32 };
138 for (MVT
T : FloatV) {
186 if (!Subtarget.useHVXV81Ops())
190 if (Subtarget.useHVXV81Ops()) {
193 setPromoteTo(
ISD::SETCC, MVT::v64bf16, MVT::v64f32);
194 setPromoteTo(
ISD::FADD, MVT::v64bf16, MVT::v64f32);
195 setPromoteTo(
ISD::FSUB, MVT::v64bf16, MVT::v64f32);
196 setPromoteTo(
ISD::FMUL, MVT::v64bf16, MVT::v64f32);
221 for (MVT
P : FloatW) {
251 if (Subtarget.useHVXQFloatOps()) {
254 }
else if (Subtarget.useHVXIEEEFPOps()) {
260 for (MVT
T : LegalV) {
287 if (
T.getScalarType() != MVT::i32) {
296 if (
T.getScalarType() != MVT::i32) {
324 if (Subtarget.useHVXFloatingPoint()) {
341 for (MVT
T : LegalW) {
396 if (
T.getScalarType() != MVT::i32) {
401 if (Subtarget.useHVXFloatingPoint()) {
448 for (MVT
T : LegalW) {
465 for (MVT
T : LegalV) {
480 for (MVT
T: {MVT::v32i8, MVT::v32i16, MVT::v16i8, MVT::v16i16, MVT::v16i32})
483 for (MVT
T: {MVT::v64i8, MVT::v64i16, MVT::v32i8, MVT::v32i16, MVT::v32i32})
488 unsigned HwLen = Subtarget.getVectorLength();
489 for (MVT ElemTy : Subtarget.getHVXElementTypes()) {
490 if (ElemTy == MVT::i1)
492 int ElemWidth = ElemTy.getFixedSizeInBits();
493 int MaxElems = (8*HwLen) / ElemWidth;
494 for (
int N = 2;
N < MaxElems;
N *= 2) {
505 if (Subtarget.useHVXFloatingPoint()) {
535 auto HvxType = [=](MVT ScalarT,
unsigned Factor = 1) {
544 typedef std::tuple<MVT, MVT, bool> ReductionSignature;
546 static const std::vector<ReductionSignature> NativeReductions = {
547 {MVT::i32, MVT::i8,
false},
550 for (
const auto &R : NativeReductions) {
552 MVT AccType = std::get<0>(R);
553 MVT InputType = std::get<1>(R);
554 unsigned Factor = std::get<2>(R) ? 2 : 1;
576 for (
unsigned ConcatFactor = 1; ConcatFactor <=
MaxExpandMLA;
578 for (
unsigned ReductionFactor = 1; ReductionFactor <=
MaxExpandMLA;
579 ReductionFactor <<= 1)
580 if (ConcatFactor * ReductionFactor != 1 &&
583 MLAOps, HvxType(AccType, Factor * ConcatFactor),
584 HvxType(InputType, Factor * ConcatFactor * ReductionFactor),
591HexagonTargetLowering::getPreferredHvxVectorAction(
MVT VecTy)
const {
598 unsigned HwLen = Subtarget.getVectorLength();
601 if (ElemTy == MVT::i1 && VecLen > HwLen)
607 if (ElemTy == MVT::i1) {
622 unsigned HwWidth = 8*HwLen;
623 if (VecWidth > 2*HwWidth)
626 bool HaveThreshold = Subtarget.getCLOpts().hvx_widen.has_value();
627 if (HaveThreshold && 8 * *Subtarget.getCLOpts().hvx_widen <= VecWidth)
629 if (VecWidth >= HwWidth/2 && VecWidth < HwWidth)
638HexagonTargetLowering::getCustomHvxOperationAction(
SDNode &
Op)
const {
639 unsigned Opc =
Op.getOpcode();
641 case HexagonISD::SMUL_LOHI:
642 case HexagonISD::UMUL_LOHI:
643 case HexagonISD::USMUL_LOHI:
659HexagonTargetLowering::typeJoin(
const TypePair &Tys)
const {
660 assert(Tys.first.getVectorElementType() == Tys.second.getVectorElementType());
664 Tys.second.getVectorNumElements());
667HexagonTargetLowering::TypePair
668HexagonTargetLowering::typeSplit(
MVT VecTy)
const {
671 assert((NumElem % 2) == 0 &&
"Expecting even-sized vector type");
673 return { HalfTy, HalfTy };
677HexagonTargetLowering::typeExtElem(
MVT VecTy,
unsigned Factor)
const {
684HexagonTargetLowering::typeTruncElem(
MVT VecTy,
unsigned Factor)
const {
691HexagonTargetLowering::opCastElem(
SDValue Vec,
MVT ElemTy,
700HexagonTargetLowering::opJoin(
const VectorPair &
Ops,
const SDLoc &dl,
706HexagonTargetLowering::VectorPair
707HexagonTargetLowering::opSplit(
SDValue Vec,
const SDLoc &dl,
709 TypePair Tys = typeSplit(ty(Vec));
712 return DAG.
SplitVector(Vec, dl, Tys.first, Tys.second);
716HexagonTargetLowering::isHvxSingleTy(
MVT Ty)
const {
717 return Subtarget.isHVXVectorType(Ty) &&
722HexagonTargetLowering::isHvxPairTy(
MVT Ty)
const {
723 return Subtarget.isHVXVectorType(Ty) &&
728HexagonTargetLowering::isHvxBoolTy(
MVT Ty)
const {
729 return Subtarget.isHVXVectorType(Ty,
true) &&
733bool HexagonTargetLowering::allowsHvxMemoryAccess(
741 if (!Subtarget.isHVXVectorType(VecTy,
false))
748bool HexagonTargetLowering::allowsHvxMisalignedMemoryAccesses(
750 if (!Subtarget.isHVXVectorType(VecTy))
758void HexagonTargetLowering::AdjustHvxInstrPostInstrSelection(
760 unsigned Opc =
MI.getOpcode();
761 const TargetInstrInfo &
TII = *Subtarget.getInstrInfo();
762 MachineBasicBlock &MB = *
MI.getParent();
769 case Hexagon::PS_vsplatib:
770 if (Subtarget.useHVXV62Ops()) {
775 .
add(
MI.getOperand(1));
777 BuildMI(MB, At,
DL,
TII.get(Hexagon::V6_lvsplatb), OutV)
783 const MachineOperand &InpOp =
MI.getOperand(1);
785 uint32_t
V = InpOp.
getImm() & 0xFF;
793 case Hexagon::PS_vsplatrb:
794 if (Subtarget.useHVXV62Ops()) {
797 BuildMI(MB, At,
DL,
TII.get(Hexagon::V6_lvsplatb), OutV)
798 .
add(
MI.getOperand(1));
801 const MachineOperand &InpOp =
MI.getOperand(1);
802 BuildMI(MB, At,
DL,
TII.get(Hexagon::S2_vsplatrb), SplatV)
805 BuildMI(MB, At,
DL,
TII.get(Hexagon::V6_lvsplatw), OutV)
810 case Hexagon::PS_vsplatih:
811 if (Subtarget.useHVXV62Ops()) {
816 .
add(
MI.getOperand(1));
818 BuildMI(MB, At,
DL,
TII.get(Hexagon::V6_lvsplath), OutV)
824 const MachineOperand &InpOp =
MI.getOperand(1);
826 uint32_t
V = InpOp.
getImm() & 0xFFFF;
834 case Hexagon::PS_vsplatrh:
835 if (Subtarget.useHVXV62Ops()) {
838 BuildMI(MB, At,
DL,
TII.get(Hexagon::V6_lvsplath), OutV)
839 .
add(
MI.getOperand(1));
844 const MachineOperand &InpOp =
MI.getOperand(1);
845 BuildMI(MB, At,
DL,
TII.get(Hexagon::A2_combine_ll), SplatV)
853 case Hexagon::PS_vsplatiw:
854 case Hexagon::PS_vsplatrw:
855 if (
Opc == Hexagon::PS_vsplatiw) {
859 .
add(
MI.getOperand(1));
860 MI.getOperand(1).ChangeToRegister(SplatV,
false);
863 MI.setDesc(
TII.get(Hexagon::V6_lvsplatw));
869HexagonTargetLowering::convertToByteIndex(
SDValue ElemIdx,
MVT ElemTy,
879 const SDLoc &dl(ElemIdx);
885HexagonTargetLowering::getIndexInWord32(
SDValue Idx,
MVT ElemTy,
888 assert(ElemWidth >= 8 && ElemWidth <= 32);
892 if (ty(Idx) != MVT::i32)
894 const SDLoc &dl(Idx);
901HexagonTargetLowering::getByteShuffle(
const SDLoc &dl,
SDValue Op0,
908 if (ElemTy == MVT::i8)
912 MVT ResTy = tyVector(OpTy, MVT::i8);
915 SmallVector<int,128> ByteMask;
918 for (
unsigned I = 0;
I != ElemSize; ++
I)
921 int NewM =
M*ElemSize;
922 for (
unsigned I = 0;
I != ElemSize; ++
I)
928 opCastElem(Op1, MVT::i8, DAG), ByteMask);
935 unsigned VecLen =
Values.size();
939 unsigned HwLen = Subtarget.getVectorLength();
941 unsigned ElemSize = ElemWidth / 8;
942 assert(ElemSize*VecLen == HwLen);
946 !(Subtarget.useHVXFloatingPoint() &&
948 assert((ElemSize == 1 || ElemSize == 2) &&
"Invalid element size");
949 unsigned OpsPerWord = (ElemSize == 1) ? 4 : 2;
951 for (
unsigned i = 0; i != VecLen; i += OpsPerWord) {
952 SDValue W = buildVector32(
Values.slice(i, OpsPerWord), dl, PartVT, DAG);
960 unsigned NumValues =
Values.size();
963 for (
unsigned i = 0; i != NumValues; ++i) {
967 if (!SplatV.getNode())
969 else if (SplatV !=
Values[i])
977 unsigned NumWords = Words.
size();
979 bool IsSplat =
isSplat(Words, SplatV);
980 if (IsSplat && isUndef(SplatV))
985 return getZero(dl, VecTy, DAG);
994 bool AllConst = getBuildVectorConstInts(
Values, VecTy, DAG, Consts);
997 (Constant**)Consts.end());
1015 SmallVectorImpl<int> &SrcIdx) {
1019 SrcIdx.push_back(-1);
1032 int I =
C->getSExtValue();
1033 assert(
I >= 0 &&
"Negative element index");
1034 SrcIdx.push_back(
I);
1040 SmallVector<int,128> ExtIdx;
1042 if (IsBuildFromExtracts(ExtVec, ExtIdx)) {
1043 MVT ExtTy = ty(ExtVec);
1045 if (ExtLen == VecLen || ExtLen == 2*VecLen) {
1049 SmallVector<int,128>
Mask;
1050 BitVector
Used(ExtLen);
1052 for (
int M : ExtIdx) {
1062 for (
unsigned I = 0;
I != ExtLen; ++
I) {
1063 if (
Mask.size() == ExtLen)
1071 return ExtLen == VecLen ? S : LoHalf(S, DAG);
1079 assert(4*Words.
size() == Subtarget.getVectorLength());
1082 for (
unsigned i = 0; i != NumWords; ++i) {
1084 if (Words[i].isUndef())
1086 for (
unsigned j = i;
j != NumWords; ++
j)
1087 if (Words[i] == Words[j])
1090 if (VecHist[i] > VecHist[n])
1094 SDValue HalfV = getZero(dl, VecTy, DAG);
1095 if (VecHist[n] > 1) {
1103 HalfV = DAG.
getNode(HexagonISD::VALIGN, dl, VecTy,
1104 {HalfV, SplatV, DAG.
getConstant(HwLen/2, dl, MVT::i32)});
1116 for (
unsigned i = 0; i != NumWords/2; ++i) {
1118 if (Words[i] != Words[n] || VecHist[n] <= 1) {
1121 N = DAG.
getNode(HexagonISD::VINSERTW0, dl, VecTy,
1122 {HalfV0, Words[i]});
1125 if (Words[i+NumWords/2] != Words[n] || VecHist[n] <= 1) {
1128 M = DAG.
getNode(HexagonISD::VINSERTW0, dl, VecTy,
1129 {HalfV1, Words[i+NumWords/2]});
1152HexagonTargetLowering::createHvxPrefixPred(
SDValue PredV,
const SDLoc &dl,
1153 unsigned BitBytes,
bool ZeroFill,
SelectionDAG &DAG)
const {
1154 MVT PredTy = ty(PredV);
1155 unsigned HwLen = Subtarget.getVectorLength();
1158 if (Subtarget.isHVXVectorType(PredTy,
true)) {
1168 SmallVector<int,128>
Mask(HwLen);
1173 for (
unsigned i = 0; i != HwLen; ++i) {
1174 unsigned Num = i % Scale;
1175 unsigned Off = i / Scale;
1184 assert(BlockLen < HwLen &&
"vsetq(v1) prerequisite");
1186 SDValue Q = getInstr(Hexagon::V6_pred_scalar2, dl, BoolTy,
1193 assert(PredTy == MVT::v2i1 || PredTy == MVT::v4i1 || PredTy == MVT::v8i1);
1205 while (Bytes < BitBytes) {
1207 Words[IdxW].
clear();
1210 for (
const SDValue &W : Words[IdxW ^ 1]) {
1211 SDValue T = expandPredicate(W, dl, DAG);
1216 for (
const SDValue &W : Words[IdxW ^ 1]) {
1224 assert(Bytes == BitBytes);
1225 SDValue Vec = ZeroFill ? getZero(dl, ByteTy, DAG) : DAG.getUNDEF(ByteTy);
1227 for (
const SDValue &W : Words[IdxW]) {
1229 Vec = DAG.
getNode(HexagonISD::VINSERTW0, dl, ByteTy, Vec, W);
1241 unsigned VecLen =
Values.size();
1242 unsigned HwLen = Subtarget.getVectorLength();
1243 assert(VecLen <= HwLen || VecLen == 8*HwLen);
1245 bool AllT =
true, AllF =
true;
1249 return !
N->isZero();
1258 if (VecLen <= HwLen) {
1262 assert(HwLen % VecLen == 0);
1263 unsigned BitBytes = HwLen / VecLen;
1270 for (
unsigned B = 0;
B != BitBytes; ++
B)
1277 for (
unsigned I = 0;
I != VecLen;
I += 8) {
1280 for (;
B != 8; ++
B) {
1299 return DAG.
getNode(HexagonISD::QTRUE, dl, VecTy);
1301 return DAG.
getNode(HexagonISD::QFALSE, dl, VecTy);
1304 SDValue ByteVec = buildHvxVectorReg(Bytes, dl, ByteTy, DAG);
1309HexagonTargetLowering::extractHvxElementReg(
SDValue VecV,
SDValue IdxV,
1314 assert(ElemWidth >= 8 && ElemWidth <= 32);
1317 SDValue ByteIdx = convertToByteIndex(IdxV, ElemTy, DAG);
1318 SDValue ExWord = DAG.
getNode(HexagonISD::VEXTRACTW, dl, MVT::i32,
1320 if (ElemTy == MVT::i32)
1326 SDValue SubIdx = getIndexInWord32(IdxV, ElemTy, DAG);
1329 return extractVector(ExVec, SubIdx, dl, ElemTy, MVT::i32, DAG);
1333HexagonTargetLowering::extractHvxElementPred(
SDValue VecV,
SDValue IdxV,
1336 assert(ResTy == MVT::i1);
1338 unsigned HwLen = Subtarget.getVectorLength();
1342 unsigned Scale = HwLen / ty(VecV).getVectorNumElements();
1346 SDValue ExtB = extractHvxElementReg(ByteVec, IdxV, dl, MVT::i32, DAG);
1348 return getInstr(Hexagon::C2_cmpgtui, dl, MVT::i1, {ExtB,
Zero}, DAG);
1352HexagonTargetLowering::insertHvxElementReg(
SDValue VecV,
SDValue IdxV,
1357 assert(ElemWidth >= 8 && ElemWidth <= 32);
1362 MVT VecTy = ty(VecV);
1363 unsigned HwLen = Subtarget.getVectorLength();
1368 SDValue InsV = DAG.
getNode(HexagonISD::VINSERTW0, dl, VecTy, {RotV, ValV});
1375 SDValue ByteIdx = convertToByteIndex(IdxV, ElemTy, DAG);
1376 if (ElemTy == MVT::i32)
1377 return InsertWord(VecV, ValV, ByteIdx);
1383 SDValue Ext = extractHvxElementReg(opCastElem(VecV, MVT::i32, DAG), WordIdx,
1388 SDValue SubIdx = getIndexInWord32(IdxV, ElemTy, DAG);
1389 MVT
SubVecTy = tyVector(ty(Ext), ElemTy);
1391 ValV, SubIdx, dl, ElemTy, DAG);
1394 return InsertWord(VecV, Ins, ByteIdx);
1398HexagonTargetLowering::insertHvxElementPred(
SDValue VecV,
SDValue IdxV,
1400 unsigned HwLen = Subtarget.getVectorLength();
1404 unsigned Scale = HwLen / ty(VecV).getVectorNumElements();
1409 SDValue InsV = insertHvxElementReg(ByteVec, IdxV, ValV, dl, DAG);
1414HexagonTargetLowering::extractHvxSubvectorReg(
SDValue OrigOp,
SDValue VecV,
1416 MVT VecTy = ty(VecV);
1417 unsigned HwLen = Subtarget.getVectorLength();
1425 if (isHvxPairTy(VecTy)) {
1426 unsigned SubIdx = Hexagon::vsub_lo;
1427 if (Idx * ElemWidth >= 8 * HwLen) {
1428 SubIdx = Hexagon::vsub_hi;
1432 VecTy = typeSplit(VecTy).first;
1442 MVT WordTy = tyVector(VecTy, MVT::i32);
1444 unsigned WordIdx = (
Idx*ElemWidth) / 32;
1447 SDValue W0 = extractHvxElementReg(WordVec, W0Idx, dl, MVT::i32, DAG);
1452 SDValue W1 = extractHvxElementReg(WordVec, W1Idx, dl, MVT::i32, DAG);
1453 SDValue WW = getCombine(W1, W0, dl, MVT::i64, DAG);
1458HexagonTargetLowering::extractHvxSubvectorPred(
SDValue VecV,
SDValue IdxV,
1460 MVT VecTy = ty(VecV);
1461 unsigned HwLen = Subtarget.getVectorLength();
1471 SmallVector<int,128>
Mask;
1473 if (Subtarget.isHVXVectorType(ResTy,
true)) {
1480 for (
unsigned i = 0; i != HwLen/Rep; ++i) {
1481 for (
unsigned j = 0;
j != Rep; ++
j)
1498 unsigned Rep = 8 / ResLen;
1501 for (
unsigned r = 0; r != HwLen / 8; ++r) {
1503 for (
unsigned i = 0; i != ResLen; ++i) {
1504 for (
unsigned j = 0;
j != Rep; ++
j)
1516 SDValue Vec64 = getCombine(W1, W0, dl, MVT::v8i8, DAG);
1517 return getInstr(Hexagon::A4_vcmpbgtui, dl, ResTy,
1522HexagonTargetLowering::insertHvxSubvectorReg(
SDValue VecV,
SDValue SubV,
1524 MVT VecTy = ty(VecV);
1525 MVT SubTy = ty(SubV);
1526 unsigned HwLen = Subtarget.getVectorLength();
1530 bool IsPair = isHvxPairTy(VecTy);
1538 V0 = LoHalf(VecV, DAG);
1539 V1 = HiHalf(VecV, DAG);
1544 if (isHvxSingleTy(SubTy)) {
1546 unsigned Idx = CN->getZExtValue();
1548 unsigned SubIdx = (
Idx == 0) ? Hexagon::vsub_lo : Hexagon::vsub_hi;
1571 if (!IdxN || !IdxN->isZero()) {
1579 unsigned RolBase = HwLen;
1582 SingleV = DAG.
getNode(HexagonISD::VINSERTW0, dl, SingleTy, SingleV,
V);
1587 SingleV = DAG.
getNode(HexagonISD::VINSERTW0, dl, SingleTy, SingleV, R0);
1590 SingleV = DAG.
getNode(HexagonISD::VINSERTW0, dl, SingleTy, SingleV, R1);
1594 if (RolBase != 4 || !IdxN || !IdxN->isZero()) {
1609HexagonTargetLowering::insertHvxSubvectorPred(
SDValue VecV,
SDValue SubV,
1611 MVT VecTy = ty(VecV);
1612 MVT SubTy = ty(SubV);
1613 assert(Subtarget.isHVXVectorType(VecTy,
true));
1618 unsigned HwLen = Subtarget.getVectorLength();
1619 assert(HwLen % VecLen == 0 &&
"Unexpected vector type");
1622 unsigned BitBytes = HwLen / VecLen;
1623 unsigned BlockLen = HwLen / Scale;
1627 if (!Subtarget.isHVXVectorType(SubTy,
true)) {
1629 unsigned SubBitBytes = 8 / SubLen;
1630 if (SubBitBytes > BitBytes) {
1631 unsigned WideLen = 8 / BitBytes;
1638 SDValue ByteSub = createHvxPrefixPred(SubV, dl, BitBytes,
false, DAG);
1642 if (!IdxN || !IdxN->isZero()) {
1651 assert(BlockLen < HwLen &&
"vsetq(v1) prerequisite");
1653 SDValue Q = getInstr(Hexagon::V6_pred_scalar2, dl, BoolTy,
1655 ByteVec = getInstr(Hexagon::V6_vmux, dl, ByteTy, {Q, ByteSub, ByteVec}, DAG);
1657 if (!IdxN || !IdxN->isZero()) {
1666HexagonTargetLowering::extendHvxVectorPred(
SDValue VecV,
const SDLoc &dl,
1671 assert(Subtarget.isHVXVectorType(ResTy));
1683HexagonTargetLowering::compressHvxPred(
SDValue VecQ,
const SDLoc &dl,
1691 unsigned HwLen = Subtarget.getVectorLength();
1693 MVT PredTy = ty(VecQ);
1695 assert(HwLen % PredLen == 0);
1702 for (
unsigned i = 0; i != HwLen/8; ++i) {
1703 for (
unsigned j = 0;
j != 8; ++
j)
1704 Tmp.
push_back(ConstantInt::get(Int8Ty, 1ull << j));
1717 getZero(dl, VecTy, DAG));
1723 SDValue Vrmpy = getInstr(Hexagon::V6_vrmpyub, dl, ByteTy, {Sel, All1}, DAG);
1725 SDValue Rot = getInstr(Hexagon::V6_valignbi, dl, ByteTy,
1732 SmallVector<int,128>
Mask;
1733 for (
unsigned i = 0; i != HwLen; ++i)
1734 Mask.push_back((8*i) % HwLen + i/(HwLen/8));
1744 MVT InpTy = ty(VecV);
1752 return InpWidth < ResWidth
1760 if (InpWidth < ResWidth) {
1762 return DAG.
getNode(ExtOpc, dl, ResTy, VecV);
1764 unsigned NarOpc =
Signed ? HexagonISD::SSAT : HexagonISD::USAT;
1770HexagonTargetLowering::extractSubvector(
SDValue Vec,
MVT SubTy,
unsigned SubIdx,
1774 const SDLoc &dl(Vec);
1783 const SDLoc &dl(
Op);
1788 for (
unsigned i = 0; i !=
Size; ++i)
1789 Ops.push_back(
Op.getOperand(i));
1792 return buildHvxVectorPred(
Ops, dl, VecTy, DAG);
1800 for (
unsigned i = 0; i !=
Size; i++)
1811 if (VecTy.
getSizeInBits() == 16 * Subtarget.getVectorLength()) {
1813 MVT SingleTy = typeSplit(VecTy).first;
1814 SDValue V0 = buildHvxVectorReg(
A.take_front(
Size / 2), dl, SingleTy, DAG);
1815 SDValue V1 = buildHvxVectorReg(
A.drop_front(
Size / 2), dl, SingleTy, DAG);
1819 return buildHvxVectorReg(
Ops, dl, VecTy, DAG);
1825 const SDLoc &dl(
Op);
1827 MVT ArgTy = ty(
Op.getOperand(0));
1829 if (ArgTy == MVT::f16 || ArgTy == MVT::bf16) {
1847 const SDLoc &dl(
Op);
1864 MVT NTy = typeLegalize(Ty, DAG);
1868 V.getOperand(0),
V.getOperand(1)),
1873 switch (
V.getOpcode()) {
1892 unsigned HwLen = Subtarget.getVectorLength();
1899 if (Subtarget.isHVXVectorType(ty(Op0),
true)) {
1901 return DAG.
getNode(HexagonISD::QCAT, dl, VecTy, Op0,
Op.getOperand(1));
1907 MVT HalfTy = typeSplit(VecTy).first;
1909 Ops.take_front(NumOp/2));
1911 Ops.take_back(NumOp/2));
1912 return DAG.
getNode(HexagonISD::QCAT, dl, VecTy, V0,
V1);
1922 SDValue Combined = combineConcatOfScalarPreds(
Op, BitBytes, DAG);
1925 SDValue P = createHvxPrefixPred(
V, dl, BitBytes,
true, DAG);
1929 unsigned InpLen = ty(Combined.
getOperand(0)).getVectorNumElements();
1932 SDValue Res = getZero(dl, ByteTy, DAG);
1933 for (
unsigned i = 0, e = Prefixes.
size(); i != e; ++i) {
1946 const SDLoc &dl(
Op);
1948 if (ElemTy == MVT::i1)
1949 return extractHvxElementPred(VecV, IdxV, dl, ty(
Op), DAG);
1951 return extractHvxElementReg(VecV, IdxV, dl, ty(
Op), DAG);
1957 const SDLoc &dl(
Op);
1962 if (ElemTy == MVT::i1)
1963 return insertHvxElementPred(VecV, IdxV, ValV, dl, DAG);
1965 return insertHvxElementReg(VecV, IdxV, ValV, dl, DAG);
1972 MVT SrcTy = ty(SrcV);
1978 const SDLoc &dl(
Op);
1981 if (ElemTy == MVT::i1)
1982 return extractHvxSubvectorPred(SrcV, IdxV, dl, DstTy, DAG);
1984 return extractHvxSubvectorReg(
Op, SrcV, IdxV, dl, DstTy, DAG);
1995 const SDLoc &dl(
Op);
1996 MVT VecTy = ty(VecV);
1998 if (ElemTy == MVT::i1)
1999 return insertHvxSubvectorPred(VecV, ValV, IdxV, dl, DAG);
2001 return insertHvxSubvectorReg(VecV, ValV, IdxV, dl, DAG);
2013 if (ElemTy == MVT::i1 && Subtarget.isHVXVectorType(ResTy))
2014 return LowerHvxSignExt(
Op, DAG);
2023 if (ElemTy == MVT::i1 && Subtarget.isHVXVectorType(ResTy))
2024 return extendHvxVectorPred(InpV, SDLoc(
Op), ty(
Op),
false, DAG);
2033 if (ElemTy == MVT::i1 && Subtarget.isHVXVectorType(ResTy))
2034 return extendHvxVectorPred(InpV, SDLoc(
Op), ty(
Op),
true, DAG);
2042 const SDLoc &dl(
Op);
2045 assert(ResTy == ty(InpV));
2070 const SDLoc &dl(
Op);
2077 SDVTList ResTys = DAG.
getVTList(ResTy, ResTy);
2078 unsigned Opc =
Op.getOpcode();
2082 return DAG.
getNode(HexagonISD::UMUL_LOHI, dl, ResTys, {Vs, Vt}).
getValue(1);
2084 return DAG.
getNode(HexagonISD::SMUL_LOHI, dl, ResTys, {Vs, Vt}).
getValue(1);
2094 const SDLoc &dl(
Op);
2095 unsigned Opc =
Op.getOpcode();
2100 if (
auto HiVal =
Op.getValue(1); HiVal.use_empty()) {
2107 bool SignedVu =
Opc == HexagonISD::SMUL_LOHI;
2108 bool SignedVv =
Opc == HexagonISD::SMUL_LOHI ||
Opc == HexagonISD::USMUL_LOHI;
2112 if (Subtarget.useHVXV62Ops())
2113 return emitHvxMulLoHiV62(Vu, SignedVu, Vv, SignedVv, dl, DAG);
2115 if (
Opc == HexagonISD::SMUL_LOHI) {
2118 if (
auto LoVal =
Op.getValue(0); LoVal.use_empty()) {
2119 SDValue Hi = emitHvxMulHsV60(Vu, Vv, dl, DAG);
2125 return emitHvxMulLoHiV60(Vu, SignedVu, Vv, SignedVv, dl, DAG);
2132 MVT ValTy = ty(Val);
2133 const SDLoc &dl(
Op);
2136 unsigned HwLen = Subtarget.getVectorLength();
2144 if (PredLen < HwLen) {
2147 if (HwLen > PredLen * 2) {
2148 assert(HwLen == PredLen * 4);
2150 Val = getInstr(Hexagon::V6_vdealh, dl, ByteTy, Val, DAG);
2152 if (HwLen > PredLen) {
2153 assert(HwLen == PredLen * 2);
2154 Val = getInstr(Hexagon::V6_vdealb, dl, ByteTy, Val, DAG);
2159 SDValue VQ = compressHvxPred(Val, dl, WordTy, DAG);
2174 for (
unsigned i = 0; i !=
BitWidth/32; ++i) {
2176 VQ, DAG.
getConstant(i, dl, MVT::i32), dl, MVT::i32, DAG);
2181 for (
unsigned i = 0, e = Words.
size(); i < e; i += 2) {
2182 SDValue C = getCombine(Words[i+1], Words[i], dl, MVT::i64, DAG);
2195 auto bitcastI32ToV32I1 = [&](
SDValue Val32) {
2196 assert(Val32.getValueType().getSizeInBits() == 32 &&
2197 "Input must be 32 bits");
2201 for (
unsigned i = 0; i < 32; ++i)
2209 if (ResTy == MVT::v32i1 &&
2210 (ValTy == MVT::i32 || ValTy == MVT::v2i16 || ValTy == MVT::v4i8) &&
2211 Subtarget.useHVX128BOps()) {
2213 if (ValTy == MVT::v2i16 || ValTy == MVT::v4i8)
2215 return bitcastI32ToV32I1(Val32);
2218 if (ResTy == MVT::v64i1 && ValTy == MVT::i64 && Subtarget.useHVX128BOps()) {
2236 unsigned HwLen = Subtarget.getVectorLength();
2248 for (
unsigned I = 0;
I != HwLen / 8; ++
I) {
2252 for (
unsigned J = 0; J != 8; ++J) {
2260 SDValue I2V = buildHvxVectorReg(Bytes, dl, ConstantVecTy, DAG);
2272 const SDLoc &dl(
Op);
2275 MVT ValTy = ty(Val);
2278 if (!isHvxBoolTy(ValTy))
2285 unsigned RequiredAlign = (NumBits == 32) ? 4 : 8;
2289 unsigned HwLen = Subtarget.getVectorLength();
2293 SDValue VQ = compressHvxPred(Val, dl, WordTy, DAG);
2297 for (
unsigned i = 0; i != NumBits / 32; ++i) {
2308 return DAG.
getStore(Chain, dl, Words[0], BasePtr, PtrInfo,
2311 if (NumBits == 64) {
2312 SDValue W64 = getCombine(Words[1], Words[0], dl, MVT::i64, DAG);
2316 if (NumBits == 128) {
2317 SDValue Lo64 = getCombine(Words[1], Words[0], dl, MVT::i64, DAG);
2318 SDValue Hi64 = getCombine(Words[3], Words[2], dl, MVT::i64, DAG);
2334 const SDLoc &dl(
Op);
2339 if (!isHvxBoolTy(ResTy))
2345 unsigned RequiredAlign = (NumBits == 32) ? 4 : 8;
2353 if (NumBits == 32) {
2361 if (NumBits == 64) {
2369 if (NumBits == 128) {
2405 const SDLoc &dl(
Op);
2406 unsigned HwLen = Subtarget.getVectorLength();
2408 assert(HwLen % VecLen == 0);
2409 unsigned ElemSize = HwLen / VecLen;
2421 if (
SDValue S = getVectorShiftByInt(
Op, DAG))
2427HexagonTargetLowering::LowerHvxFunnelShift(
SDValue Op,
2429 unsigned Opc =
Op.getOpcode();
2441 const SDLoc &dl(
Op);
2447 bool UseShifts = ElemTy != MVT::i8;
2448 if (Subtarget.useHVXV65Ops() && ElemTy == MVT::i32)
2451 if (
SDValue SplatV = getSplatValue(S, DAG); SplatV && UseShifts) {
2459 {DAG.
getConstant(ElemWidth, dl, MVT::i32), ModS});
2465 DAG.
getNode(HexagonISD::VASL, dl, InpTy, {
A, IsLeft ? ModS : NegS});
2467 DAG.
getNode(HexagonISD::VLSR, dl, InpTy, {
B, IsLeft ? NegS : ModS});
2475 InpTy, dl, DAG.
getConstant(ElemWidth - 1, dl, ElemTy));
2477 unsigned MOpc =
Opc ==
ISD::FSHL ? HexagonISD::MFSHL : HexagonISD::MFSHR;
2484 const SDLoc &dl(
Op);
2485 unsigned IntNo =
Op.getConstantOperandVal(0);
2492 const SDLoc &
DL(
Op);
2497 case Intrinsic::hexagon_V6_vcvt_b_hf_128B:
2498 case Intrinsic::hexagon_V6_vcvt_h_hf_128B:
2499 case Intrinsic::hexagon_V6_vcvt_ub_hf_128B:
2500 case Intrinsic::hexagon_V6_vcvt_uh_hf_128B: {
2504 if (!HST.useHVXV79OpsOnly())
2513 "Expecting a vector argument type for V6_vcvt_h_hf instrinsic.");
2515 Args.push_back(Entry);
2519 bool LongCalls = HST.useLongCalls();
2522 const char *
Name =
nullptr;
2524 case Intrinsic::hexagon_V6_vcvt_b_hf_128B: {
2525 Name = Subtarget.getCLOpts().qf_fast_convert
2526 ?
"__qf_fast_convert_hf_to_b_rne"
2527 :
"__qf_convert_hf_to_b_rne";
2530 case Intrinsic::hexagon_V6_vcvt_h_hf_128B: {
2531 Name = Subtarget.getCLOpts().qf_fast_convert
2532 ?
"__qf_fast_convert_hf_to_h_rne"
2533 :
"__qf_convert_hf_to_h_rne";
2536 case Intrinsic::hexagon_V6_vcvt_ub_hf_128B: {
2537 Name = Subtarget.getCLOpts().qf_fast_convert
2538 ?
"__qf_fast_convert_hf_to_ub_rne"
2539 :
"__qf_convert_hf_to_ub_rne";
2542 case Intrinsic::hexagon_V6_vcvt_uh_hf_128B: {
2543 Name = Subtarget.getCLOpts().qf_fast_convert
2544 ?
"__qf_fast_convert_hf_to_uh_rne"
2545 :
"__qf_convert_hf_to_uh_rne";
2551 "' in HexagonTargetLowering::LowerHvxIntrinsic");
2557 TargetLowering::CallLoweringInfo CLI(DAG);
2561 std::pair<SDValue, SDValue> CallResult =
LowerCallTo(CLI);
2562 return CallResult.first;
2564 case Intrinsic::hexagon_V6_pred_typecast:
2565 case Intrinsic::hexagon_V6_pred_typecast_128B: {
2566 MVT ResTy = ty(
Op), InpTy = ty(
Ops[1]);
2567 if (isHvxBoolTy(ResTy) && isHvxBoolTy(InpTy)) {
2574 case Intrinsic::hexagon_V6_vmpyss_parts:
2575 case Intrinsic::hexagon_V6_vmpyss_parts_128B:
2576 return Swap(DAG.
getNode(HexagonISD::SMUL_LOHI, dl,
Op->getVTList(),
2578 case Intrinsic::hexagon_V6_vmpyuu_parts:
2579 case Intrinsic::hexagon_V6_vmpyuu_parts_128B:
2580 return Swap(DAG.
getNode(HexagonISD::UMUL_LOHI, dl,
Op->getVTList(),
2582 case Intrinsic::hexagon_V6_vmpyus_parts:
2583 case Intrinsic::hexagon_V6_vmpyus_parts_128B: {
2584 return Swap(DAG.
getNode(HexagonISD::USMUL_LOHI, dl,
Op->getVTList(),
2594 const SDLoc &dl(
Op);
2595 unsigned HwLen = Subtarget.getVectorLength();
2599 SDValue Chain = MaskN->getChain();
2603 unsigned Opc =
Op->getOpcode();
2620 unsigned StoreOpc = Hexagon::V6_vS32b_qpred_ai;
2624 if (MaskN->getAlign().value() % HwLen == 0) {
2637 SDValue LoV = getInstr(Hexagon::V6_vlalignb, dl, ty(
V), {
V,
Z,
A}, DAG);
2638 SDValue HiV = getInstr(Hexagon::V6_vlalignb, dl, ty(
V), {
Z,
V,
A}, DAG);
2639 return std::make_pair(LoV, HiV);
2645 VectorPair Tmp = StoreAlign(MaskV,
Base);
2648 VectorPair ValueU = StoreAlign(
Value,
Base);
2652 getInstr(StoreOpc, dl, MVT::Other,
2653 {MaskU.first,
Base, Offset0, ValueU.first, Chain}, DAG);
2664 uint64_t StoreMemSize = MaskN->getMemoryVT().getStoreSize().getFixedValue();
2665 if (StoreMemSize <= MaskN->
getAlign().value())
2669 getInstr(StoreOpc, dl, MVT::Other,
2670 {MaskU.second,
Base, Offset1, ValueU.second, Chain}, DAG);
2679 assert(Subtarget.useHVXQFloatOps());
2684 MVT ArgTy = ty(
Op.getOperand(0));
2685 const SDLoc &dl(
Op);
2687 if (ArgTy == MVT::v64bf16) {
2688 MVT HalfTy = typeSplit(VecTy).first;
2691 getInstr(Hexagon::V6_vxor, dl, HalfTy, {BF16Vec, BF16Vec}, DAG);
2696 getInstr(Hexagon::V6_vshufoeh, dl, VecTy, {BF16Vec, Zeroes}, DAG);
2697 VectorPair VecPair = opSplit(ShuffVec, dl, DAG);
2699 {VecPair.second, VecPair.first,
2705 assert(VecTy == MVT::v64f32 && ArgTy == MVT::v64f16);
2714 getInstr(Hexagon::V6_vmpy_qf32_hf, dl, VecTy, {F16Vec, Fp16Ones}, DAG);
2716 MVT HalfTy = typeSplit(VecTy).first;
2717 VectorPair Pair = opSplit(VmpyVec, dl, DAG);
2719 getInstr(Hexagon::V6_vconv_sf_qf32, dl, HalfTy, {Pair.first}, DAG);
2721 getInstr(Hexagon::V6_vconv_sf_qf32, dl, HalfTy, {Pair.second}, DAG);
2724 getInstr(Hexagon::V6_vshuffvdd, dl, VecTy,
2737 MVT FpTy = ty(
Op.getOperand(0)).getVectorElementType();
2740 if (Subtarget.useHVXIEEEFPOps()) {
2742 if (FpTy == MVT::f16) {
2744 assert(IntTy == MVT::i8 || IntTy == MVT::i16 || IntTy == MVT::i32);
2746 if (IntTy == MVT::i8 || IntTy == MVT::i16)
2752 return EqualizeFpIntConversion(
Op, DAG);
2754 return ExpandHvxFpToInt(
Op, DAG);
2770 MVT ResTy = ty(PredOp);
2771 const SDLoc &dl(PredOp);
2774 SDNode *RegConst = DAG.
getMachineNode(Hexagon::A2_tfrsi, dl, MVT::i32, Const);
2775 SDNode *SplatConst = DAG.
getMachineNode(Hexagon::V6_lvsplatw, dl, MVT::v32i32,
2777 SDNode *PredTransfer =
2780 SDNode *PrefixSum = DAG.
getMachineNode(Hexagon::V6_vprefixqw, dl, MVT::v32i32,
2783 Hexagon::V6_lvsplatw, dl, MVT::v32i32,
2788 SDNode *IndexShift =
2794 SDNode *Convert = DAG.
getMachineNode(Hexagon::V6_vconv_sf_w, dl, ResTy,
2819 MVT ResTy = ty(PredOp);
2820 const SDLoc &dl(PredOp);
2830 SDNode *RegConst = DAG.
getMachineNode(Hexagon::A2_tfrsi, dl, MVT::i32, Const);
2831 SDNode *SplatConst = DAG.
getMachineNode(Hexagon::V6_lvsplatw, dl, MVT::v32i32,
2841 SDNode *PredTransfer =
2845 SDNode *PrefixSum = DAG.
getMachineNode(Hexagon::V6_vprefixqw, dl, MVT::v32i32,
2852 SDNode *IndexShift_hi =
2855 SDNode *IndexShift_lo =
2859 SDNode *MaskOff_hi =
2862 SDNode *MaskOff_lo =
2885 if (ResTy == MVT::v32f32 && ty(
Op.getOperand(0)) == MVT::v32i1)
2886 return LowerHvxPred32ToFp(
Op, DAG);
2887 if (ResTy == MVT::v64f16 && ty(
Op.getOperand(0)) == MVT::v64i1)
2888 return LowerHvxPred64ToFp(
Op, DAG);
2891 if (Subtarget.useHVXIEEEFPOps()) {
2893 if (FpTy == MVT::f16) {
2895 assert(IntTy == MVT::i8 || IntTy == MVT::i16 || IntTy == MVT::i32);
2897 if (IntTy == MVT::i8 || IntTy == MVT::i16)
2903 return EqualizeFpIntConversion(
Op, DAG);
2905 return ExpandHvxIntToFp(
Op, DAG);
2908HexagonTargetLowering::TypePair
2909HexagonTargetLowering::typeExtendToWider(
MVT Ty0,
MVT Ty1)
const {
2920 unsigned MaxWidth = std::max(Width0, Width1);
2922 auto getScalarWithWidth = [](MVT ScalarTy,
unsigned Width) {
2929 MVT WideETy0 = getScalarWithWidth(ElemTy0, MaxWidth);
2930 MVT WideETy1 = getScalarWithWidth(ElemTy1, MaxWidth);
2934 return {WideETy0, WideETy1};
2945HexagonTargetLowering::TypePair
2946HexagonTargetLowering::typeWidenToWider(
MVT Ty0,
MVT Ty1)
const {
2956 unsigned MaxLen = std::max(Len0, Len1);
2969HexagonTargetLowering::typeWidenToHvx(
MVT Ty)
const {
2970 unsigned HwWidth = 8 * Subtarget.getVectorLength();
2979HexagonTargetLowering::VectorPair
3010HexagonTargetLowering::VectorPair
3011HexagonTargetLowering::emitHvxShiftRightRnd(
SDValue Val,
unsigned Amt,
3016 const SDLoc &dl(Val);
3017 MVT ValTy = ty(Val);
3031 MVT IntTy = tyVector(ValTy, ElemTy);
3043 auto [Tmp0, Ovf] = emitHvxAddWithOverflow(Inp, LowBits, dl,
Signed, DAG);
3062 MVT
PairTy = typeJoin({VecTy, VecTy});
3088 SDValue T0 = getInstr(Hexagon::V6_vmpyewuh, dl, VecTy, {
B,
A}, DAG);
3090 SDValue T1 = getInstr(Hexagon::V6_vasrw, dl, VecTy, {
A,
S16}, DAG);
3098 SDValue P1 = getInstr(Hexagon::V6_vadduhw, dl,
PairTy, {T0, T2}, DAG);
3103 SDValue T3 = getInstr(Hexagon::V6_vasrw_acc, dl, VecTy,
3104 {HiHalf(P2, DAG), LoHalf(P1, DAG),
S16}, DAG);
3105 SDValue T4 = getInstr(Hexagon::V6_vasrw, dl, VecTy, {
B,
S16}, DAG);
3116HexagonTargetLowering::emitHvxMulLoHiV60(
SDValue A,
bool SignedA,
SDValue B,
3117 bool SignedB,
const SDLoc &dl,
3120 MVT
PairTy = typeJoin({VecTy, VecTy});
3125 if (SignedA && !SignedB) {
3141 SDValue T0 = getInstr(Hexagon::V6_lvsplatw, dl, VecTy,
3142 {DAG.
getConstant(0x02020202, dl, MVT::i32)}, DAG);
3143 SDValue T1 = getInstr(Hexagon::V6_vdelta, dl, VecTy, {
B, T0}, DAG);
3152 {HiHalf(P1, DAG), LoHalf(P1, DAG)}, DAG);
3155 getInstr(Hexagon::V6_vlsrw, dl, VecTy, {LoHalf(P0, DAG),
S16}, DAG);
3159 SDValue T4 = getInstr(Hexagon::V6_vasrw_acc, dl, VecTy,
3160 {HiHalf(P2, DAG), T3,
S16}, DAG);
3163 Lo = getInstr(Hexagon::V6_vaslw_acc, dl, VecTy,
3164 {LoHalf(P0, DAG), LoHalf(P2, DAG),
S16}, DAG);
3168 assert(SignedB &&
"Signed A and unsigned B should have been inverted");
3175 SDValue X1 = getInstr(Hexagon::V6_vaddwq, dl, VecTy, {Q1, X0,
A}, DAG);
3176 Hi = getInstr(Hexagon::V6_vsubw, dl, VecTy, {
Hi, X1}, DAG);
3177 }
else if (SignedB) {
3183 Hi = getInstr(Hexagon::V6_vsubwq, dl, VecTy, {Q1,
Hi,
A}, DAG);
3185 assert(!SignedA && !SignedB);
3192HexagonTargetLowering::emitHvxMulLoHiV62(
SDValue A,
bool SignedA,
3197 MVT
PairTy = typeJoin({VecTy, VecTy});
3200 if (SignedA && !SignedB) {
3209 getInstr(Hexagon::V6_vmpyowh_64_acc, dl,
PairTy, {
P0,
A,
B}, DAG);
3214 assert(!SignedA &&
"Signed A and unsigned B should have been inverted");
3226 SDValue T0 = getInstr(Hexagon::V6_vandvqv, dl, VecTy, {Q0,
B}, DAG);
3227 SDValue T1 = getInstr(Hexagon::V6_vaddwq, dl, VecTy, {Q1, T0,
A}, DAG);
3228 Hi = getInstr(Hexagon::V6_vaddw, dl, VecTy, {
Hi,
T1}, DAG);
3229 }
else if (!SignedA) {
3239 Hi = getInstr(Hexagon::V6_vaddwq, dl, VecTy, {Q0,
Hi,
B}, DAG);
3257 unsigned Opc =
Op.getOpcode();
3262 MVT InpTy = ty(Inp);
3268 const SDLoc &dl(
Op);
3271 auto [WInpTy, WResTy] = typeExtendToWider(InpTy, ResTy);
3280 unsigned Opc =
Op.getOpcode();
3283 const SDLoc &dl(
Op);
3285 MVT InpTy = ty(Op0);
3300 if (Subtarget.useHVXV73Ops()) {
3301 if (InpTy == MVT::v64f16) {
3302 if (Subtarget.useHVXV81Ops()) {
3305 getInstr(Hexagon::V6_vconv_h_hf_rnd, dl, ResTy, {Op0}, DAG);
3307 }
else if (Subtarget.getCLOpts().fp_fast_convert) {
3310 getInstr(Hexagon::V6_vconv_h_hf, dl, ResTy, {Op0}, DAG);
3313 }
else if (Subtarget.getCLOpts().fp_fast_convert && InpTy == MVT::v32f32) {
3315 SDValue ConvVec = getInstr(Hexagon::V6_vconv_w_sf, dl, ResTy, {Op0}, DAG);
3396 unsigned ElemWidth = 1 + ExpWidth + FracWidth;
3397 assert((1ull << (ExpWidth - 1)) == (1 + ExpBias));
3440 unsigned Opc =
Op.getOpcode();
3443 const SDLoc &dl(
Op);
3445 MVT InpTy = ty(Op0);
3478 unsigned ElemWidth = 1 + ExpWidth + FracWidth;
3488 auto [Frac, Ovf] = emitHvxShiftRightRnd(Frac0, ExpWidth + 1,
false, DAG);
3511 unsigned Opc =
Op.getOpcode();
3528 const SDLoc &dl(
Op);
3529 return DAG.
getNode(TLOpc, dl, ty(
Op),
Op.getOperand(0),
3538 unsigned Opc =
Op.getConstantOperandVal(2);
3542HexagonTargetLowering::VectorPair
3546 const SDLoc &dl(
Op);
3548 auto SplitVTNode = [&DAG,
this](
const VTSDNode *
N) {
3549 MVT Ty = typeSplit(
N->getVT().getSimpleVT()).first;
3551 return std::make_pair(TV, TV);
3556 ty(
A).isVector() ? opSplit(
A, dl, DAG) : std::make_pair(
A,
A);
3558 switch (
Op.getOpcode()) {
3559 case ISD::SIGN_EXTEND_INREG:
3560 case HexagonISD::SSAT:
3561 case HexagonISD::USAT:
3562 if (const auto *N = dyn_cast<const VTSDNode>(A.getNode()))
3563 std::tie(Lo, Hi) = SplitVTNode(N);
3571 MVT HalfTy = typeSplit(ResTy).first;
3580 unsigned MemOpc =
MemN->getOpcode();
3581 EVT MemTy =
MemN->getMemoryVT();
3598 EVT LoMemVT, HiMemVT;
3599 bool HiIsEmpty =
false;
3600 std::tie(LoMemVT, HiMemVT) =
3606 const SDLoc &dl(
Op);
3612 MachineMemOperand *MOp0 =
nullptr, *MOp1 =
nullptr;
3613 if (MachineMemOperand *MMO =
MemN->getMemOperand()) {
3649 assert(MaskN->isUnindexed());
3650 VectorPair Masks = opSplit(MaskN->getMask(), dl, DAG);
3657 Masks.first, Thru.first, LoMemVT, MOp0,
3666 Masks.second, Thru.second, HiMemVT, MOp1,
3688 std::string
Name =
"Unexpected operation: " +
Op->getOperationName(&DAG);
3694 const SDLoc &dl(
Op);
3696 assert(LoadN->isUnindexed() &&
"Not widening indexed loads yet");
3697 assert(LoadN->getMemoryVT().getVectorElementType() != MVT::i1 &&
3698 "Not widening loads of i1 yet");
3700 SDValue Chain = LoadN->getChain();
3705 unsigned HwLen = Subtarget.getVectorLength();
3707 assert(ResLen < HwLen &&
"vsetq(v1) prerequisite");
3710 SDValue Mask = getInstr(Hexagon::V6_pred_scalar2, dl, BoolTy,
3718 DAG.
getUNDEF(LoadTy), LoadTy, MemOp,
3726 const SDLoc &dl(
Op);
3728 assert(StoreN->isUnindexed() &&
"Not widening indexed stores yet");
3729 assert(StoreN->getMemoryVT().getVectorElementType() != MVT::i1 &&
3730 "Not widening stores of i1 yet");
3732 SDValue Chain = StoreN->getChain();
3736 SDValue Value = opCastElem(StoreN->getValue(), MVT::i8, DAG);
3737 MVT ValueTy = ty(
Value);
3739 unsigned HwLen = Subtarget.getVectorLength();
3742 for (
unsigned Len = ValueLen;
Len < HwLen; ) {
3744 Len = ty(
Value).getVectorNumElements();
3746 assert(ty(
Value).getVectorNumElements() == HwLen);
3748 assert(ValueLen < HwLen &&
"vsetq(v1) prerequisite");
3750 SDValue Mask = getInstr(Hexagon::V6_pred_scalar2, dl, BoolTy,
3753 auto *MemOp = MF.getMachineMemOperand(StoreN->getMemOperand(), 0, HwLen);
3761 const SDLoc &dl(
Op);
3762 SDValue Op0 =
Op.getOperand(0), Op1 =
Op.getOperand(1);
3764 unsigned HwLen = Subtarget.getVectorLength();
3769 if (!Subtarget.isHVXVectorType(WideOpTy,
true))
3772 SDValue WideOp0 = appendUndef(Op0, WideOpTy, DAG);
3773 SDValue WideOp1 = appendUndef(Op1, WideOpTy, DAG);
3777 {WideOp0, WideOp1,
Op.getOperand(2)});
3779 EVT RetTy = typeLegalize(ty(
Op), DAG);
3781 {SetCC, getZero(dl, MVT::i32, DAG)});
3791 const SDLoc &dl(
Op);
3793 MVT InpTy = ty(Inp);
3797 "Expected boolean result type");
3800 unsigned HwLen = Subtarget.getVectorLength();
3805 if (!Subtarget.isHVXVectorType(WideInpTy,
false))
3809 SDValue WideInp = appendUndef(Inp, WideInpTy, DAG);
3816 EVT RetTy = typeLegalize(ResTy, DAG);
3818 {WideTrunc, getZero(dl, MVT::i32, DAG)});
3823 unsigned Opc =
Op.getOpcode();
3824 bool IsPairOp = isHvxPairTy(ty(
Op)) ||
3826 return isHvxPairTy(ty(V));
3837 return SplitHvxMemOp(
Op, DAG);
3842 if (ty(
Op).getSizeInBits() == ty(
Op.getOperand(0)).getSizeInBits())
3843 return opJoin(SplitVectorOp(
Op, DAG), SDLoc(
Op), DAG);
3877 return opJoin(SplitVectorOp(
Op, DAG), SDLoc(
Op), DAG);
3882 if (ty(
Op.getOperand(0)).getVectorElementType() == MVT::i1)
3883 return opJoin(SplitVectorOp(
Op, DAG), SDLoc(
Op), DAG);
3907 case ISD::SRL:
return LowerHvxShift(
Op, DAG);
3909 case ISD::FSHR:
return LowerHvxFunnelShift(
Op, DAG);
3918 ty(
Op.getOperand(0)).getScalarType().isFloatingPoint())
3919 return LowerHvxFpSetoeq(
Op, DAG);
3937 case HexagonISD::SMUL_LOHI:
3938 case HexagonISD::UMUL_LOHI:
3939 case HexagonISD::USMUL_LOHI:
return LowerHvxMulLoHi(
Op, DAG);
3944 return LowerHvxPartialReduceMLA(
Op, DAG);
3946 return LowerHvxVecReduceFMin(
Op, DAG);
3948 return LowerHvxVecReduceFMax(
Op, DAG);
3950 return LowerHvxVecReduceFMinimum(
Op, DAG);
3952 return LowerHvxVecReduceFMaximum(
Op, DAG);
3954 return LowerHvxFMinNum(
Op, DAG);
3956 return LowerHvxFMaxNum(
Op, DAG);
3974 unsigned Opc =
Op.getOpcode();
3976 case HexagonISD::SSAT:
3977 case HexagonISD::USAT:
3994 MVT InpTy = ty(Inp);
3999 assert(InpWidth != ResWidth);
4001 if (InpWidth == 2 * ResWidth || ResWidth == 2 * InpWidth)
4004 const SDLoc &dl(
Op);
4008 auto repeatOp = [&](
unsigned NewWidth,
SDValue Arg) {
4011 case HexagonISD::SSAT:
4012 case HexagonISD::USAT:
4016 return DAG.
getNode(
Opc, dl, Ty, {Arg,
Op.getOperand(1),
Op.getOperand(2)});
4023 if (InpWidth < ResWidth) {
4025 while (InpWidth * 2 <= ResWidth)
4026 S = repeatOp(InpWidth *= 2, S);
4030 while (InpWidth / 2 >= ResWidth)
4031 S = repeatOp(InpWidth /= 2, S);
4039 MVT InpTy = ty(Inp0);
4043 unsigned Opc =
Op.getOpcode();
4045 if (shouldWidenToHvx(InpTy, DAG) || shouldWidenToHvx(ResTy, DAG)) {
4050 auto [WInpTy, WResTy] =
4051 InpWidth < ResWidth ? typeWidenToWider(typeWidenToHvx(InpTy), ResTy)
4052 : typeWidenToWider(InpTy, typeWidenToHvx(ResTy));
4053 SDValue W = appendUndef(Inp0, WInpTy, DAG);
4061 SDValue T = ExpandHvxResizeIntoSteps(S, DAG);
4062 return extractSubvector(
T, typeLegalize(ResTy, DAG), 0, DAG);
4063 }
else if (shouldSplitToHvx(InpWidth < ResWidth ? ResTy : InpTy, DAG)) {
4070 SDValue T = ExpandHvxResizeIntoSteps(
Op, DAG);
4073 return opJoin(SplitVectorOp(
Op, DAG), SDLoc(
Op), DAG);
4076 return RemoveTLWrapper(
Op, DAG);
4082HexagonTargetLowering::LowerHvxOperationWrapper(
SDNode *
N,
4084 unsigned Opc =
N->getOpcode();
4087 if (
N->getNumOperands() > 0)
4088 Inp0 =
Op.getOperand(0);
4094 if (Subtarget.isHVXElementType(ty(
Op)) &&
4095 Subtarget.isHVXElementType(ty(Inp0))) {
4096 Results.push_back(CreateTLWrapper(
Op, DAG));
4108 !Subtarget.isHVXVectorType(ty(Inp0),
false)) {
4109 if (
SDValue T = WidenHvxTruncateToBool(
Op, DAG))
4111 }
else if (Subtarget.isHVXElementType(ty(
Op)) &&
4112 Subtarget.isHVXElementType(ty(Inp0))) {
4113 Results.push_back(CreateTLWrapper(
Op, DAG));
4117 if (shouldWidenToHvx(ty(Inp0), DAG)) {
4130 if (isHvxPairTy(ty(
Op))) {
4138 if (isHvxPairTy(ty(
Op->getOperand(1)))) {
4147 if (ty(
Op).getSizeInBits() != ty(Inp0).getSizeInBits()) {
4148 SDValue T = EqualizeFpIntConversion(
Op, DAG);
4152 case HexagonISD::SSAT:
4153 case HexagonISD::USAT:
4156 Results.push_back(LegalizeHvxResize(
Op, DAG));
4164HexagonTargetLowering::ReplaceHvxNodeResults(
SDNode *
N,
4166 unsigned Opc =
N->getOpcode();
4169 if (
N->getNumOperands() > 0)
4170 Inp0 =
Op.getOperand(0);
4176 if (Subtarget.isHVXElementType(ty(
Op)) &&
4177 Subtarget.isHVXElementType(ty(Inp0))) {
4178 Results.push_back(CreateTLWrapper(
Op, DAG));
4185 !Subtarget.isHVXVectorType(ty(Inp0),
false)) {
4186 if (
SDValue T = WidenHvxTruncateToBool(
Op, DAG))
4188 }
else if (Subtarget.isHVXElementType(ty(
Op)) &&
4189 Subtarget.isHVXElementType(ty(Inp0))) {
4190 Results.push_back(CreateTLWrapper(
Op, DAG));
4194 if (shouldWidenToHvx(ty(
Op), DAG)) {
4200 if (shouldWidenToHvx(ty(
Op), DAG)) {
4209 if (isHvxBoolTy(ty(Inp0))) {
4216 if (ty(
Op).getSizeInBits() != ty(Inp0).getSizeInBits()) {
4217 SDValue T = EqualizeFpIntConversion(
Op, DAG);
4221 case HexagonISD::SSAT:
4222 case HexagonISD::USAT:
4225 Results.push_back(LegalizeHvxResize(
Op, DAG));
4233HexagonTargetLowering::combineTruncateBeforeLegal(
SDValue Op,
4234 DAGCombinerInfo &DCI)
const {
4239 SelectionDAG &DAG = DCI.DAG;
4240 const SDLoc &dl(
Op);
4247 EVT TruncTy =
Op.getValueType();
4249 EVT SrcTy = Src.getValueType();
4256 if (2 * CastLen != SrcLen)
4259 SmallVector<int, 128>
Mask(SrcLen);
4260 for (
int i = 0; i !=
static_cast<int>(CastLen); ++i) {
4262 Mask[i + CastLen] = 2 * i + 1;
4266 return opSplit(Deal, dl, DAG).first;
4270HexagonTargetLowering::combineConcatOfShuffles(
SDValue Op,
4279 const SDLoc &dl(
Op);
4288 SetVector<SDValue> Order;
4294 if (Order.
size() > 2)
4299 EVT InpTy =
V0.getValueType();
4303 SmallVector<int, 128> LongMask;
4304 auto AppendToMask = [&](
SDValue Shuffle) {
4306 ArrayRef<int>
Mask =
SV->getMask();
4309 for (
int M : Mask) {
4314 SDValue Src =
static_cast<unsigned>(
M) < InpLen ?
X :
Y;
4315 if (
static_cast<unsigned>(M) >= InpLen)
4318 int OutOffset = Order[0] == Src ? 0 : InpLen;
4341HexagonTargetLowering::combineConcatOfScalarPreds(
SDValue Op,
unsigned BitBytes,
4343 const SDLoc &dl(
Op);
4346 MVT InpTy = ty(
Ops[0]);
4349 assert(InpLen <= 8 &&
"Too long for scalar predicate");
4350 assert(ResLen > 8 &&
"Too short for HVX vector predicate");
4352 unsigned Bytes = 8 / InpLen;
4355 if (Bytes <= BitBytes)
4359 unsigned SliceLen = Bytes / BitBytes;
4364 for (
unsigned i = 0; i != ResLen / (8 / BitBytes); ++i) {
4366 Inputs.slice(SliceLen * i, SliceLen));
4373SDValue HexagonTargetLowering::combineConcatVectorsBeforeLegal(
4374 SDValue Op, DAGCombinerInfo &DCI)
const {
4378 if (ElemTy != MVT::i1) {
4379 return combineConcatOfShuffles(
Op, DCI.DAG);
4386SDValue HexagonTargetLowering::createExtendingPartialReduceMLA(
4387 unsigned Opcode,
EVT AccEltType,
unsigned AccNumElements,
EVT InputType,
4390 const auto &Subtarget = DAG.
getSubtarget<HexagonSubtarget>();
4391 if (!Subtarget.useHVXOps())
4397 unsigned NativeRatio;
4398 if (AccEltType == MVT::i32 && InputEltType == MVT::i8)
4410 RemainingReductionRatio = InputNumElements / (AccNumElements * NativeRatio);
4411 if (RemainingReductionRatio == 1)
4416 InputNumElements / NativeRatio);
4425 EVT AccType =
Mul.getValueType();
4431 A =
Mul->getOperand(0);
4432 B =
Mul->getOperand(1);
4452 A =
A->getOperand(0);
4453 B =
B->getOperand(0);
4454 if (
A.getValueType() !=
B.getValueType())
4465 if (!Subtarget.useHVXOps())
4468 EVT ScalarType =
N->getValueType(0);
4475 unsigned RemainingReductionRatio;
4477 createExtendingPartialReduceMLA(Opcode, ScalarType, 1,
A.getValueType(),
4478 A,
B, RemainingReductionRatio,
DL, DAG);
4494SDValue HexagonTargetLowering::LowerHvxVecReduceFMinMax(
4498 MVT VecTy = ty(Vec);
4499 SDNodeFlags
Flags =
Op->getFlags();
4500 bool ShouldStripNaN = IgnoreNaN && !
Flags.hasNoNaNs();
4504 MVT OrigVecTy = VecTy;
4519 if (isHvxPairTy(VecTy)) {
4520 auto [
Lo,
Hi] = opSplit(Vec,
DL, DAG);
4521 MVT SingleTy = ty(
Lo);
4522 if (ShouldStripNaN) {
4523 Lo = ReplaceNaN(
Lo, SingleTy);
4524 Hi = ReplaceNaN(
Hi, SingleTy);
4526 Vec = DAG.
getNode(PairwiseOpc,
DL, SingleTy,
Lo,
Hi, Flags);
4528 }
else if (ShouldStripNaN) {
4529 Vec = ReplaceNaN(Vec, VecTy);
4536 unsigned HwLen = Subtarget.getVectorLength();
4537 unsigned NumElems = HwLen / ElemBytes;
4540 for (
unsigned Width = NumElems / 2; Width >= 1; Width /= 2) {
4543 Curr = DAG.
getNode(PairwiseOpc,
DL, VecTy, Curr, Rotated, Flags);
4547 MVT ScalarTy =
Op.getSimpleValueType();
4555 if (ShouldStripNaN) {
4586HexagonTargetLowering::LowerHvxVecReduceFMinimum(
SDValue Op,
4592HexagonTargetLowering::LowerHvxVecReduceFMaximum(
SDValue Op,
4604 auto A =
Op.getOperand(0),
B =
Op.getOperand(1);
4608 if (!
Flags.hasNoNaNs()) {
4631 auto A =
Op.getOperand(0),
B =
Op.getOperand(1);
4635 if (!
Flags.hasNoNaNs()) {
4661HexagonTargetLowering::splitExtendingPartialReduceMLA(
SDNode *
N,
4663 if (!Subtarget.useHVXOps())
4669 if (
A.getValueType() !=
B.getValueType())
4675 EVT InputType =
A.getValueType();
4680 unsigned RemainingReductionRatio;
4681 SDValue Partial = createExtendingPartialReduceMLA(
4695 DL, AccType, Acc, Partial, One);
4699HexagonTargetLowering::LowerHvxPartialReduceMLA(
SDValue Op,
4701 const SDLoc &
DL(
Op);
4707 unsigned HwVectorSizeInBits = Subtarget.getVectorLength() * 8;
4711 unsigned AccSubvectorNumElements =
4713 EVT AccSubvectorType =
4716 EVT InputType =
A.getValueType();
4719 unsigned InputSubvectorNumElements =
4722 InputSubvectorNumElements);
4727 for (
unsigned I = 0;
I != SubvectorNum; ++
I) {
4729 I * AccSubvectorNumElements);
4731 I * InputSubvectorNumElements);
4733 I * InputSubvectorNumElements);
4735 SubvectorAcc, SubvectorA, SubvectorB);
4775 auto ResTy = ty(
Op);
4776 auto A =
Op.getOperand(0),
B =
Op->getOperand(1);
4777 MVT FloatTy = ty(
A);
4779 bool IsF32 = (ElemTy == MVT::f32);
4781 assert((ElemTy == MVT::f16));
4783 const SDLoc &
DL(
Op);
4784 MVT IntElemTy = IsF32 ? MVT::i32 : MVT::i16;
4785 MVT IntVecTy = tyVector(FloatTy, IntElemTy);
4789 bool NoNaN =
Op->getFlags().hasNoNaNs();
4807 uint64_t AbsMask = IsF32 ? 0x7FFFFFFFull : 0x7FFFull;
4808 uint64_t NaNThresh = IsF32 ? 0x7F800000ull : 0x7C00ull;
4830HexagonTargetLowering::PerformHvxDAGCombine(
SDNode *
N, DAGCombinerInfo &DCI)
4833 SelectionDAG &DAG = DCI.DAG;
4835 unsigned Opc =
Op.getOpcode();
4840 return combineTruncateBeforeLegal(
Op, DCI);
4842 return combineConcatVectorsBeforeLegal(
Op, DCI);
4844 if (DCI.isBeforeLegalizeOps())
4851 return C->isZero() ? DAG.
getNode(HexagonISD::QFALSE, dl, ty(
Op))
4852 : DAG.
getNode(HexagonISD::QTRUE, dl, ty(
Op));
4860 return getZero(dl, ty(
Op), DAG);
4862 case HexagonISD::VINSERTW0:
4863 if (isUndef(
Ops[1]))
4881HexagonTargetLowering::shouldSplitToHvx(
MVT Ty,
SelectionDAG &DAG)
const {
4882 if (Subtarget.isHVXVectorType(Ty,
true))
4884 auto Action = getPreferredHvxVectorAction(Ty);
4886 return Subtarget.isHVXVectorType(typeLegalize(Ty, DAG),
true);
4891HexagonTargetLowering::shouldWidenToHvx(
MVT Ty,
SelectionDAG &DAG)
const {
4892 if (Subtarget.isHVXVectorType(Ty,
true))
4894 auto Action = getPreferredHvxVectorAction(Ty);
4896 return Subtarget.isHVXVectorType(typeLegalize(Ty, DAG),
true);
4902 if (!Subtarget.useHVXOps())
4906 auto IsHvxTy = [
this](EVT Ty) {
4907 return Ty.isSimple() && Subtarget.isHVXVectorType(Ty.getSimpleVT(),
true);
4910 return Op.getValueType().isSimple() &&
4911 Subtarget.isHVXVectorType(ty(
Op),
true);
4917 auto IsWidenedToHvx = [
this, &DAG](
SDValue Op) {
4918 if (!
Op.getValueType().isSimple())
4921 return ValTy.
isVector() && shouldWidenToHvx(ValTy, DAG);
4924 for (
int i = 0, e =
N->getNumValues(); i != e; ++i) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static std::tuple< unsigned, unsigned, unsigned > getIEEEProperties(MVT Ty)
static const unsigned MaxExpandMLA
static const MVT LegalV128[]
static const MVT LegalW128[]
static const MVT LegalW64[]
static const MVT LegalV64[]
static bool DetectExtendingMultiply(const SDValue &N, EVT ScalarType, unsigned &Opcode, SDValue &A, SDValue &B)
static MaybeAlign getAlign(Value *Ptr)
static constexpr Value * getValue(Ty &ValueOrUse)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static bool isSplat(Value *V)
Return true if V is a splat of a value (which is used when multiplying a matrix with a scalar).
std::pair< MCSymbol *, MachineModuleInfoImpl::StubValueTy > PairTy
Promote Memory to Register
This file provides utility analysis objects describing memory locations.
MachineRegisterInfo & MRI
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static constexpr roundingMode rmNearestTiesToEven
static constexpr const fltSemantics & IEEEhalf()
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
uint64_t getNumOperands() const
SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const
EVT getSetCCResultType(const DataLayout &, LLVMContext &C, EVT VT) const override
Return the ValueType of the result of SETCC operations.
LegalizeTypeAction getPreferredVectorAction(MVT VT) const override
Return the preferred vector type legalization action.
const SDValue & getBasePtr() const
static MVT getFloatingPointVT(unsigned BitWidth)
uint64_t getScalarSizeInBits() const
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
bool isInteger() const
Return true if this is an integer or a vector integer type.
MVT changeTypeToInteger()
Return the type converted to an equivalently sized integer or vector with integer element type.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
LLVM_ABI const fltSemantics & getFltSemantics() const
Returns an APFloat semantics tag appropriate for the value type.
ElementCount getVectorElementCount() const
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
bool isScalarInteger() const
Return true if this is an integer, not including vectors.
static MVT getVectorVT(MVT VT, unsigned NumElements)
MVT getVectorElementType() const
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
static MVT getIntegerVT(unsigned BitWidth)
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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 & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
Flags
Flags values. These may be or'd together.
const MachinePointerInfo & getPointerInfo() const
Align getBaseAlign() const
Return the minimum known alignment in bytes of the base address, without the offset.
unsigned getSubReg() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
Register getReg() const
getReg - Returns the register number.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
MachineMemOperand * getMemOperand() const
Return the unique MachineMemOperand object describing the memory reference performed by operation.
const SDValue & getChain() const
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
iterator_range< value_op_iterator > op_values() const
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
const SDValue & getOperand(unsigned Num) const
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
const SDValue & getOperand(unsigned i) const
unsigned getOpcode() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
const TargetSubtargetInfo & getSubtarget() const
LLVM_ABI SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget=false, bool IsOpaque=false)
LLVM_ABI MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s),...
LLVM_ABI void ExtractVectorElements(SDValue Op, SmallVectorImpl< SDValue > &Args, unsigned Start=0, unsigned Count=0, EVT EltVT=EVT())
Append the extracted elements from Start to Count out of the vector Op in Args.
LLVM_ABI SDValue getConstantPool(const Constant *C, EVT VT, MaybeAlign Align=std::nullopt, int Offs=0, bool isT=false, unsigned TargetFlags=0)
LLVM_ABI SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
SDValue getExtractSubvector(const SDLoc &DL, EVT VT, SDValue Vec, unsigned Idx)
Return the VT typed sub-vector of Vec at Idx.
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false, SDNodeFlags Flags={})
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
LLVM_ABI std::pair< EVT, EVT > GetSplitDestVTs(const EVT &VT) const
Compute the VTs needed for the low/hi parts of a type which is split (or expanded) into two not neces...
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
LLVM_ABI SDValue getBitcast(EVT VT, SDValue V)
Return a bitcast using the SDLoc of the value operand, and casting to the provided type.
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build Select's if you just have operands and don't want to check...
LLVM_ABI void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand * > NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Helper function to build ISD::STORE nodes.
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
LLVM_ABI SDValue getMemBasePlusOffset(SDValue Base, TypeSize Offset, const SDLoc &DL, const SDNodeFlags Flags=SDNodeFlags())
Returns sum of the base pointer and offset.
LLVM_ABI std::pair< SDValue, SDValue > SplitVector(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the vector with EXTRACT_SUBVECTOR using the provided VTs and return the low/high part.
LLVM_ABI SDValue getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
LLVM_ABI SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand)
A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
LLVM_ABI SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either sign-extending or trunca...
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Loads are not normal binary operators: their result type is not determined by their operands,...
LLVM_ABI SDValue getMaskedStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Base, SDValue Offset, SDValue Mask, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexedMode AM, bool IsTruncating=false, bool IsCompressing=false)
LLVM_ABI SDValue getValueType(EVT)
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
MachineFunction & getMachineFunction() const
SDValue getPOISON(EVT VT)
Return a POISON node. POISON does not have a useful SDLoc.
SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op)
Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all elements.
LLVM_ABI SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
LLVMContext * getContext() const
LLVM_ABI SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned TargetFlags=0)
LLVM_ABI std::pair< EVT, EVT > GetDependentSplitDestVTs(const EVT &VT, const EVT &EnvVT, bool *HiIsEmpty) const
Compute the VTs needed for the low/hi parts of a type, dependent on an enveloping VT that has been sp...
LLVM_ABI SDValue getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand, SDValue Subreg)
A convenience function for creating TargetInstrInfo::INSERT_SUBREG nodes.
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
LLVM_ABI SDValue getMaskedLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Base, SDValue Offset, SDValue Mask, SDValue Src0, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexedMode AM, ISD::LoadExtType, bool IsExpanding=false)
LLVM_ABI SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2, ArrayRef< int > Mask)
Return an ISD::VECTOR_SHUFFLE node.
size_type size() const
Determine the number of elements in the SetVector.
const value_type & front() const
Return the first element of the SetVector.
const value_type & back() const
Return the last element of the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
const SDValue & getBasePtr() const
const SDValue & getValue() const
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
void setIndexedLoadAction(ArrayRef< unsigned > IdxModes, MVT VT, LegalizeAction Action)
Indicate that the specified indexed load does or does not work with the specified type and indicate w...
virtual EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
void setIndexedStoreAction(ArrayRef< unsigned > IdxModes, MVT VT, LegalizeAction Action)
Indicate that the specified indexed store does or does not work with the specified type and indicate ...
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
void setPartialReduceMLAAction(unsigned Opc, MVT AccVT, MVT InputVT, LegalizeAction Action)
Indicate how a PARTIAL_REDUCE_U/SMLA node with Acc type AccVT and Input type InputVT should be treate...
LegalizeAction getPartialReduceMLAAction(unsigned Opc, EVT AccVT, EVT InputVT) const
Return how a PARTIAL_REDUCE_U/SMLA node with Acc type AccVT and Input type InputVT should be treated.
void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
If Opc/OrigVT is specified as being promoted, the promotion code defaults to trying a larger integer/...
void setCondCodeAction(ArrayRef< ISD::CondCode > CCs, MVT VT, LegalizeAction Action)
Indicate that the specified condition code is or isn't supported on the target and indicate what to d...
void setTargetDAGCombine(ArrayRef< ISD::NodeType > NTs)
Targets should invoke this method for each target independent node that they want to provide a custom...
std::vector< ArgListEntry > ArgListTy
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
This function lowers an abstract call to a function into an actual call.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
constexpr bool isKnownMultipleOf(ScalarTy RHS) const
This function tells the caller whether the element count is known at compile time to be a multiple of...
constexpr ScalarTy getFixedValue() const
self_iterator getIterator()
#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 char Args[]
Key for Kernel::Metadata::mArgs.
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.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
@ MERGE_VALUES
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
@ PARTIAL_REDUCE_SMLA
PARTIAL_REDUCE_[U|S]MLA(Accumulator, Input1, Input2) The partial reduction nodes sign or zero extend ...
@ MLOAD
Masked load and store - consecutive vector load and store operations with additional mask operand tha...
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
@ INSERT_SUBVECTOR
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1.
@ BSWAP
Byte Swap and Counting operators.
@ ADD
Simple integer binary arithmetic operators.
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
@ INTRINSIC_VOID
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
@ CONCAT_VECTORS
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
@ VECREDUCE_FMAX
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
@ FADD
Simple binary floating point operators.
@ VECREDUCE_FMAXIMUM
FMINIMUM/FMAXIMUM nodes propatate NaNs and signed zeroes using the llvm.minimum and llvm....
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
@ SIGN_EXTEND_VECTOR_INREG
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
@ SIGN_EXTEND
Conversion operators.
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
@ UNDEF
UNDEF - An undefined node.
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
@ VECREDUCE_ADD
Integer reductions may have a result type larger than the vector element type.
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
@ SHL
Shift and rotation operations.
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
@ EXTRACT_SUBVECTOR
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR.
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
@ FMINNUM
FMINNUM/FMAXNUM - Same semantics as the llvm.minnum/maxnum intrinsics.
@ ANY_EXTEND_VECTOR_INREG
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
@ FMINIMUM
FMINIMUM/FMAXIMUM - Same semantics as the llvm.minimum/maximum intrinsics.
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
@ AND
Bitwise operators - logical and, logical or, logical xor.
@ INTRINSIC_WO_CHAIN
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - Same semantics as the llvm.minimumnum/maximumnum intrinsics.
@ INTRINSIC_W_CHAIN
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Flag
These should be considered private to the implementation of the MCInstrDesc class.
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM_ABI bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
RelativeUniformCounterPtr Values
@ Undef
Value of the register doesn't matter.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
@ Off
Use window algorithm after SMS algorithm fails.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
@ Or
Bitwise or logical OR of integers.
@ And
Bitwise or logical AND of integers.
@ Fast
Assign the register banks as fast as possible (default).
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
ElementCount getVectorElementCount() const
EVT getDoubleNumVectorElementsVT(LLVMContext &Context) const
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
bool isVector() const
Return true if this is a vector value type.
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
static LLVM_ABI MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
MachinePointerInfo getWithOffset(int64_t O) const