40 #define DEBUG_TYPE "legalizedag"
44 struct FloatSignAsInt;
58 class SelectionDAGLegalize {
70 EVT getSetCCResultType(
EVT VT)
const {
71 return TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
81 LegalizedNodes(LegalizedNodes), UpdatedNodes(UpdatedNodes) {}
84 void LegalizeOp(
SDNode *Node);
89 void LegalizeLoadOps(
SDNode *Node);
90 void LegalizeStoreOps(
SDNode *Node);
110 bool &NeedInvert,
const SDLoc &dl);
114 unsigned NumOps,
bool isSigned,
const SDLoc &dl);
117 SDNode *Node,
bool isSigned);
135 void ExpandDYNAMIC_STACKALLOC(
SDNode *Node,
137 void getSignAsIntValue(FloatSignAsInt &State,
const SDLoc &
DL,
139 SDValue modifySignAsInt(
const FloatSignAsInt &State,
const SDLoc &DL,
162 bool ExpandNode(
SDNode *Node);
163 void ConvertNodeToLibcall(
SDNode *Node);
164 void PromoteNode(
SDNode *Node);
169 LegalizedNodes.
erase(N);
171 UpdatedNodes->insert(N);
175 dbgs() <<
" with: "; New->
dump(&DAG));
178 "Replacing one node with another that produces a different number "
182 UpdatedNodes->insert(New);
187 dbgs() <<
" with: "; New->
dump(&DAG));
191 UpdatedNodes->insert(New.
getNode());
198 for (
unsigned i = 0, e = Old->
getNumValues(); i != e; ++i) {
203 UpdatedNodes->insert(New[i].getNode());
214 SDValue SelectionDAGLegalize::ShuffleWithNarrowerEltType(
219 unsigned NumEltsGrowth = NumDestElts / NumMaskElts;
221 assert(NumEltsGrowth &&
"Cannot promote to vector type with fewer elts!");
223 if (NumEltsGrowth == 1)
224 return DAG.getVectorShuffle(NVT, dl, N1, N2, Mask);
227 for (
unsigned i = 0; i != NumMaskElts; ++i) {
229 for (
unsigned j = 0; j != NumEltsGrowth; ++j) {
233 NewMask.
push_back(Idx * NumEltsGrowth + j);
236 assert(NewMask.
size() == NumDestElts &&
"Non-integer NumEltsGrowth?");
237 assert(TLI.isShuffleMaskLegal(NewMask, NVT) &&
"Shuffle not legal?");
238 return DAG.getVectorShuffle(NVT, dl, N1, N2, NewMask);
275 TLI.ShouldShrinkFPConstant(OrigVT)) {
285 DAG.getConstantPool(LLVMC, TLI.getPointerTy(DAG.getDataLayout()));
286 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->
getAlignment();
288 SDValue Result = DAG.getExtLoad(
295 OrigVT, dl, DAG.getEntryNode(), CPIdx,
305 TLI.getPointerTy(DAG.getDataLayout()));
306 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->
getAlignment();
308 VT, dl, DAG.getEntryNode(), CPIdx,
317 SDValue SelectionDAGLegalize::PerformInsertVectorEltInMemory(
SDValue Vec,
333 SDValue StackPtr = DAG.CreateStackTemporary(VT);
335 int SPFI = cast<FrameIndexSDNode>(StackPtr.
getNode())->getIndex();
339 DAG.getEntryNode(), dl, Tmp1, StackPtr,
342 SDValue StackPtr2 = TLI.getVectorElementPointer(DAG, StackPtr, VT, Tmp3);
348 DAG.getMachineFunction(), SPFI));
369 for (
unsigned i = 0; i != NumElts; ++i)
370 ShufOps.
push_back(i != InsertPos->getZExtValue() ? i : NumElts);
372 return DAG.getVectorShuffle(Vec.
getValueType(), dl, Vec, ScVec, ShufOps);
375 return PerformInsertVectorEltInMemory(Vec, Val, Idx, dl);
396 bitcastToAPInt().zextOrTrunc(32),
398 return DAG.getStore(Chain, dl, Con, Ptr, ST->
getPointerInfo(), Alignment,
408 Alignment, MMOFlags, AAInfo);
418 if (DAG.getDataLayout().isBigEndian())
421 Lo = DAG.getStore(Chain, dl, Lo, Ptr, ST->
getPointerInfo(), Alignment,
425 Hi = DAG.getStore(Chain, dl, Hi, Ptr,
427 MinAlign(Alignment, 4U), MMOFlags, AAInfo);
436 void SelectionDAGLegalize::LegalizeStoreOps(
SDNode *Node) {
447 if (
SDNode *OptStore = OptimizeFloatStore(ST).getNode()) {
448 ReplaceNode(ST, OptStore);
455 switch (TLI.getOperationAction(
ISD::STORE, VT)) {
464 if (!TLI.allowsMemoryAccess(*DAG.getContext(),
DL, MemVT, AS,
Align)) {
465 SDValue Result = TLI.expandUnalignedStore(ST, DAG);
466 ReplaceNode(
SDValue(ST, 0), Result);
472 if (Res && Res !=
SDValue(Node, 0))
473 ReplaceNode(
SDValue(Node, 0), Res);
479 "Can only promote stores to same size type");
483 Alignment, MMOFlags, AAInfo);
484 ReplaceNode(
SDValue(Node, 0), Result);
495 auto &DL = DAG.getDataLayout();
503 Value = DAG.getZeroExtendInReg(Value, dl, StVT);
505 DAG.getTruncStore(Chain, dl, Value, Ptr, ST->
getPointerInfo(), NVT,
506 Alignment, MMOFlags, AAInfo);
507 ReplaceNode(
SDValue(Node, 0), Result);
508 }
else if (StWidth & (StWidth - 1)) {
511 unsigned RoundWidth = 1 <<
Log2_32(StWidth);
512 assert(RoundWidth < StWidth);
513 unsigned ExtraWidth = StWidth - RoundWidth;
514 assert(ExtraWidth < RoundWidth);
515 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
516 "Store size not an integral number of bytes!");
520 unsigned IncrementSize;
525 Lo = DAG.getTruncStore(Chain, dl, Value, Ptr, ST->
getPointerInfo(),
526 RoundVT, Alignment, MMOFlags, AAInfo);
529 IncrementSize = RoundWidth / 8;
531 DAG.getConstant(IncrementSize, dl,
534 ISD::SRL, dl, Value.getValueType(), Value,
535 DAG.getConstant(RoundWidth, dl,
536 TLI.getShiftAmountTy(Value.getValueType(),
DL)));
537 Hi = DAG.getTruncStore(
540 MinAlign(Alignment, IncrementSize), MMOFlags, AAInfo);
546 ISD::SRL, dl, Value.getValueType(), Value,
547 DAG.getConstant(ExtraWidth, dl,
548 TLI.getShiftAmountTy(Value.getValueType(),
DL)));
550 RoundVT, Alignment, MMOFlags, AAInfo);
553 IncrementSize = RoundWidth / 8;
555 DAG.getConstant(IncrementSize, dl,
557 Lo = DAG.getTruncStore(
558 Chain, dl, Value, Ptr,
560 MinAlign(Alignment, IncrementSize), MMOFlags, AAInfo);
565 ReplaceNode(
SDValue(Node, 0), Result);
575 if (!TLI.allowsMemoryAccess(*DAG.getContext(),
DL, MemVT, AS,
Align)) {
576 SDValue Result = TLI.expandUnalignedStore(ST, DAG);
577 ReplaceNode(
SDValue(ST, 0), Result);
583 if (Res && Res !=
SDValue(Node, 0))
584 ReplaceNode(
SDValue(Node, 0), Res);
589 "Vector Stores are handled in LegalizeVectorOps");
592 assert(TLI.isTypeLegal(StVT) &&
593 "Do not know how to expand this store!");
597 Alignment, MMOFlags, AAInfo);
598 ReplaceNode(
SDValue(Node, 0), Result);
605 void SelectionDAGLegalize::LegalizeLoadOps(
SDNode *Node) {
618 switch (TLI.getOperationAction(Node->
getOpcode(), VT)) {
627 if (!TLI.allowsMemoryAccess(*DAG.getContext(),
DL, MemVT, AS,
Align)) {
628 std::tie(RVal, RChain) = TLI.expandUnalignedLoad(LD, DAG);
633 if (
SDValue Res = TLI.LowerOperation(RVal, DAG)) {
640 MVT NVT = TLI.getTypeToPromoteTo(Node->
getOpcode(), VT);
642 "Can only promote loads to same size type");
650 if (RChain.
getNode() != Node) {
651 assert(RVal.
getNode() != Node &&
"Load must be completely replaced");
652 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 0), RVal);
653 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 1), RChain);
655 UpdatedNodes->insert(RVal.
getNode());
656 UpdatedNodes->insert(RChain.
getNode());
711 }
else if (SrcWidth & (SrcWidth - 1)) {
714 unsigned RoundWidth = 1 <<
Log2_32(SrcWidth);
715 assert(RoundWidth < SrcWidth);
716 unsigned ExtraWidth = SrcWidth - RoundWidth;
717 assert(ExtraWidth < RoundWidth);
718 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
719 "Load size not an integral number of bytes!");
723 unsigned IncrementSize;
724 auto &DL = DAG.getDataLayout();
734 IncrementSize = RoundWidth / 8;
735 Ptr = DAG.getNode(
ISD::ADD, dl, Ptr.getValueType(),
Ptr,
736 DAG.getConstant(IncrementSize, dl,
737 Ptr.getValueType()));
740 ExtraVT,
MinAlign(Alignment, IncrementSize), MMOFlags,
751 DAG.getConstant(RoundWidth, dl,
752 TLI.getShiftAmountTy(Hi.getValueType(),
DL)));
765 IncrementSize = RoundWidth / 8;
766 Ptr = DAG.getNode(
ISD::ADD, dl, Ptr.getValueType(),
Ptr,
767 DAG.getConstant(IncrementSize, dl,
768 Ptr.getValueType()));
771 ExtraVT,
MinAlign(Alignment, IncrementSize), MMOFlags,
782 DAG.getConstant(ExtraWidth, dl,
783 TLI.getShiftAmountTy(Hi.getValueType(),
DL)));
791 bool isCustom =
false;
792 switch (TLI.getLoadExtAction(ExtType, Node->
getValueType(0),
814 if (!TLI.allowsMemoryAccess(*DAG.getContext(),
DL, MemVT, AS,
Align)) {
815 std::tie(Value, Chain) = TLI.expandUnalignedLoad(LD, DAG);
826 if (TLI.isTypeLegal(SrcVT) ||
827 TLI.isLoadExtLegal(ExtType, LoadVT, SrcVT)) {
833 SDValue Load = DAG.getExtLoad(MidExtType, dl, LoadVT, Chain, Ptr,
861 "Vector Loads are handled in LegalizeVectorOps");
868 "EXTLOAD should always be supported!");
881 ValRes = DAG.getZeroExtendInReg(Result, dl, SrcVT.getScalarType());
890 if (Chain.getNode() != Node) {
891 assert(Value.getNode() != Node &&
"Load must be completely replaced");
892 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 0), Value);
893 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 1), Chain);
895 UpdatedNodes->insert(Value.getNode());
896 UpdatedNodes->insert(Chain.getNode());
932 void SelectionDAGLegalize::LegalizeOp(
SDNode *Node) {
939 for (
unsigned i = 0, e = Node->
getNumValues(); i != e; ++i)
943 "Unexpected illegal type!");
946 assert((TLI.getTypeAction(*DAG.getContext(),
Op.getValueType()) ==
948 TLI.isTypeLegal(
Op.getValueType()) ||
950 "Unexpected illegal type!");
955 bool SimpleFinishLegalizing =
true;
964 Action = TLI.getOperationAction(Node->
getOpcode(),
968 Action = TLI.getOperationAction(Node->
getOpcode(),
977 Action = TLI.getOperationAction(Node->
getOpcode(),
982 EVT InnerType = cast<VTSDNode>(Node->
getOperand(1))->getVT();
983 Action = TLI.getOperationAction(Node->
getOpcode(), InnerType);
987 Action = TLI.getOperationAction(Node->
getOpcode(),
1000 cast<CondCodeSDNode>(Node->
getOperand(CCOperand))->
get();
1001 Action = TLI.getCondCodeAction(CCCode, OpVT);
1004 Action = TLI.getOperationAction(Node->
getOpcode(),
1007 Action = TLI.getOperationAction(Node->
getOpcode(), OpVT);
1015 SimpleFinishLegalizing =
false;
1022 SimpleFinishLegalizing =
false;
1069 ReplaceNode(Node, NewVal.
getNode());
1103 if (SimpleFinishLegalizing) {
1124 NewNode = DAG.UpdateNodeOperands(Node, Op0, SAO);
1142 NewNode = DAG.UpdateNodeOperands(Node, Op0, Op1, SAO);
1148 if (NewNode != Node) {
1149 ReplaceNode(Node, NewNode);
1159 if (!(Res.getNode() != Node || Res.getResNo() != 0))
1164 ReplaceNode(
SDValue(Node, 0), Res);
1169 for (
unsigned i = 0, e = Node->
getNumValues(); i != e; ++i)
1171 ReplaceNode(Node, ResultVals.
data());
1177 if (ExpandNode(Node))
1181 ConvertNodeToLibcall(Node);
1202 return LegalizeLoadOps(Node);
1205 return LegalizeStoreOps(Node);
1210 SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(
SDValue Op) {
1230 if (
StoreSDNode *ST = dyn_cast<StoreSDNode>(User)) {
1259 StackPtr = DAG.CreateStackTemporary(VecVT);
1260 Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr,
1264 StackPtr = TLI.getVectorElementPointer(DAG, StackPtr, VecVT, Idx);
1277 DAG.ReplaceAllUsesOfValueWith(Ch,
SDValue(NewLoad.
getNode(), 1));
1283 NewLoadOperands[0] = Ch;
1285 SDValue(DAG.UpdateNodeOperands(NewLoad.
getNode(), NewLoadOperands), 0);
1289 SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(
SDValue Op) {
1298 EVT VecVT = Vec.getValueType();
1299 SDValue StackPtr = DAG.CreateStackTemporary(VecVT);
1300 int FI = cast<FrameIndexSDNode>(StackPtr.
getNode())->getIndex();
1305 SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, PtrInfo);
1308 SDValue SubStackPtr = TLI.getVectorElementPointer(DAG, StackPtr, VecVT, Idx);
1314 return DAG.getLoad(Op.
getValueType(), dl, Ch, StackPtr, PtrInfo);
1317 SDValue SelectionDAGLegalize::ExpandVectorBuildThroughStack(
SDNode* Node) {
1325 SDValue FIPtr = DAG.CreateStackTemporary(VT);
1326 int FI = cast<FrameIndexSDNode>(FIPtr.
getNode())->getIndex();
1338 unsigned Offset = TypeByteSize*i;
1346 Stores.push_back(DAG.getTruncStore(DAG.getEntryNode(), dl,
1350 Stores.push_back(DAG.getStore(DAG.getEntryNode(), dl, Node->
getOperand(i),
1355 if (!Stores.empty())
1358 StoreChain = DAG.getEntryNode();
1361 return DAG.getLoad(VT, dl, StoreChain, FIPtr, PtrInfo);
1367 struct FloatSignAsInt {
1383 void SelectionDAGLegalize::getSignAsIntValue(FloatSignAsInt &State,
1388 State.FloatVT = FloatVT;
1391 if (TLI.isTypeLegal(IVT)) {
1392 State.IntValue = DAG.getNode(
ISD::BITCAST, DL, IVT, Value);
1394 State.SignBit = NumBits - 1;
1400 MVT LoadTy = TLI.getRegisterType(*DAG.getContext(),
MVT::i8);
1402 SDValue StackPtr = DAG.CreateStackTemporary(FloatVT, LoadTy);
1403 int FI = cast<FrameIndexSDNode>(StackPtr.
getNode())->getIndex();
1405 State.FloatPtr = StackPtr;
1408 State.Chain = DAG.getStore(DAG.getEntryNode(),
DL, Value, State.FloatPtr,
1409 State.FloatPointerInfo);
1416 State.IntPointerInfo = State.FloatPointerInfo;
1421 DAG.getConstant(ByteOffset, DL, StackPtr.
getValueType()));
1426 State.IntPtr = IntPtr;
1427 State.IntValue = DAG.getExtLoad(
ISD::EXTLOAD, DL, LoadTy, State.Chain, IntPtr,
1428 State.IntPointerInfo,
MVT::i8);
1435 SDValue SelectionDAGLegalize::modifySignAsInt(
const FloatSignAsInt &State,
1442 SDValue Chain = DAG.getTruncStore(State.Chain, DL, NewIntValue, State.IntPtr,
1443 State.IntPointerInfo,
MVT::i8);
1444 return DAG.getLoad(State.FloatVT, DL, Chain, State.FloatPtr,
1445 State.FloatPointerInfo);
1448 SDValue SelectionDAGLegalize::ExpandFCOPYSIGN(
SDNode *Node)
const {
1454 FloatSignAsInt SignAsInt;
1455 getSignAsIntValue(SignAsInt, DL, Sign);
1457 EVT IntVT = SignAsInt.IntValue.getValueType();
1458 SDValue SignMask = DAG.getConstant(SignAsInt.SignMask, DL, IntVT);
1464 if (TLI.isOperationLegalOrCustom(
ISD::FABS, FloatVT) &&
1465 TLI.isOperationLegalOrCustom(
ISD::FNEG, FloatVT)) {
1468 SDValue Cond = DAG.getSetCC(DL, getSetCCResultType(IntVT), SignBit,
1470 return DAG.getSelect(DL, FloatVT, Cond, NegValue, AbsValue);
1474 FloatSignAsInt MagAsInt;
1475 getSignAsIntValue(MagAsInt, DL, Mag);
1476 EVT MagVT = MagAsInt.IntValue.getValueType();
1477 SDValue ClearSignMask = DAG.getConstant(~MagAsInt.SignMask, DL, MagVT);
1482 int ShiftAmount = SignAsInt.SignBit - MagAsInt.SignBit;
1484 if (ShiftAmount > 0) {
1485 SDValue ShiftCnst = DAG.getConstant(ShiftAmount, DL, IntVT);
1487 }
else if (ShiftAmount < 0) {
1488 SDValue ShiftCnst = DAG.getConstant(-ShiftAmount, DL, IntVT);
1494 if (ShiftAmount > 0) {
1495 SDValue ShiftCnst = DAG.getConstant(ShiftAmount, DL, MagVT);
1497 }
else if (ShiftAmount < 0) {
1498 SDValue ShiftCnst = DAG.getConstant(-ShiftAmount, DL, MagVT);
1505 return modifySignAsInt(MagAsInt, DL, CopiedSign);
1508 SDValue SelectionDAGLegalize::ExpandFABS(
SDNode *Node)
const {
1515 SDValue Zero = DAG.getConstantFP(0.0, DL, FloatVT);
1520 FloatSignAsInt ValueAsInt;
1521 getSignAsIntValue(ValueAsInt, DL, Value);
1522 EVT IntVT = ValueAsInt.IntValue.getValueType();
1523 SDValue ClearSignMask = DAG.getConstant(~ValueAsInt.SignMask, DL, IntVT);
1526 return modifySignAsInt(ValueAsInt, DL, ClearedSign);
1529 void SelectionDAGLegalize::ExpandDYNAMIC_STACKALLOC(
SDNode* Node,
1531 unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore();
1532 assert(SPReg &&
"Target cannot require DYNAMIC_STACKALLOC expansion and"
1533 " not tell us which reg is the stack pointer!");
1543 Chain = DAG.getCALLSEQ_START(Chain, 0, 0, dl);
1546 SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
1548 unsigned Align = cast<ConstantSDNode>(Tmp3)->getZExtValue();
1549 unsigned StackAlign =
1550 DAG.getSubtarget().getFrameLowering()->getStackAlignment();
1552 if (Align > StackAlign)
1554 DAG.getConstant(-(uint64_t)Align, dl, VT));
1555 Chain = DAG.getCopyToReg(Chain, dl, SPReg, Tmp1);
1557 Tmp2 = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, dl,
true),
1558 DAG.getIntPtrConstant(0, dl,
true),
SDValue(), dl);
1582 bool SelectionDAGLegalize::LegalizeSetCCCondCode(
EVT VT,
SDValue &LHS,
1589 switch (TLI.getCondCodeAction(CCCode, OpVT)) {
1596 if (TLI.isCondCodeLegal(InvCC, OpVT)) {
1598 CC = DAG.getCondCode(InvCC);
1608 &&
"If SETO is expanded, SETOEQ must be legal!");
1613 &&
"If SETUO is expanded, SETUNE must be legal!");
1649 if (TLI.isCondCodeLegal(InvCC, OpVT)) {
1650 CC = DAG.getCondCode(InvCC);
1663 SetCC1 = DAG.getSetCC(dl, VT, LHS, RHS, CC1);
1664 SetCC2 = DAG.getSetCC(dl, VT, LHS, RHS, CC2);
1667 SetCC1 = DAG.getSetCC(dl, VT, LHS, LHS, CC1);
1668 SetCC2 = DAG.getSetCC(dl, VT, RHS, RHS, CC2);
1670 LHS = DAG.
getNode(Opc, dl, VT, SetCC1, SetCC2);
1686 unsigned SrcAlign = DAG.getDataLayout().getPrefTypeAlignment(
1688 SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign);
1699 unsigned DestAlign = DAG.getDataLayout().getPrefTypeAlignment(DestType);
1705 if (SrcSize > SlotSize)
1706 Store = DAG.getTruncStore(DAG.getEntryNode(), dl, SrcOp, FIPtr, PtrInfo,
1709 assert(SrcSize == SlotSize &&
"Invalid store");
1711 DAG.getStore(DAG.getEntryNode(), dl, SrcOp, FIPtr, PtrInfo, SrcAlign);
1715 if (SlotSize == DestSize)
1716 return DAG.getLoad(DestVT, dl, Store, FIPtr, PtrInfo, DestAlign);
1718 assert(SlotSize < DestSize &&
"Unknown extension!");
1719 return DAG.getExtLoad(
ISD::EXTLOAD, dl, DestVT, Store, FIPtr, PtrInfo, SlotVT,
1723 SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(
SDNode *Node) {
1732 SDValue Ch = DAG.getTruncStore(
1733 DAG.getEntryNode(), dl, Node->
getOperand(0), StackPtr,
1758 for (
unsigned i = 0; i < NumElems; ++i) {
1769 while (IntermedVals.
size() > 2) {
1770 NewIntermedVals.
clear();
1771 for (
unsigned i = 0, e = (IntermedVals.
size() & ~1u); i < e; i += 2) {
1778 IntermedVals[i+1].second.
size());
1781 for (
unsigned j = 0, f = IntermedVals[i].
second.size(); j != f;
1786 for (
unsigned j = 0, f = IntermedVals[i+1].
second.size(); j != f;
1788 ShuffleVec[k] = NumElems + j;
1795 IntermedVals[i+1].first,
1800 std::make_pair(Shuffle, std::move(FinalIndices)));
1805 if ((IntermedVals.
size() & 1) != 0)
1808 IntermedVals.
swap(NewIntermedVals);
1812 "Invalid number of intermediate vectors");
1813 SDValue Vec1 = IntermedVals[0].first;
1815 if (IntermedVals.
size() > 1)
1816 Vec2 = IntermedVals[1].
first;
1821 for (
unsigned i = 0, e = IntermedVals[0].
second.size(); i != e; ++i)
1822 ShuffleVec[IntermedVals[0].
second[i]] = i;
1823 for (
unsigned i = 0, e = IntermedVals[1].
second.size(); i != e; ++i)
1824 ShuffleVec[IntermedVals[1].
second[i]] = NumElems + i;
1837 SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(
SDNode *Node) {
1847 bool isOnlyLowElement =
true;
1848 bool MoreThanTwoValues =
false;
1850 for (
unsigned i = 0; i < NumElems; ++i) {
1855 isOnlyLowElement =
false;
1856 if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V))
1861 }
else if (!Value2.
getNode()) {
1864 }
else if (V != Value1 && V != Value2) {
1865 MoreThanTwoValues =
true;
1870 return DAG.getUNDEF(VT);
1872 if (isOnlyLowElement)
1878 for (
unsigned i = 0, e = NumElems; i != e; ++i) {
1880 dyn_cast<ConstantFPSDNode>(Node->
getOperand(i))) {
1881 CV.
push_back(const_cast<ConstantFP *>(V->getConstantFPValue()));
1883 dyn_cast<ConstantSDNode>(Node->
getOperand(i))) {
1885 CV.
push_back(const_cast<ConstantInt *>(V->getConstantIntValue()));
1902 DAG.getConstantPool(CP, TLI.getPointerTy(DAG.getDataLayout()));
1903 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->
getAlignment();
1905 VT, dl, DAG.getEntryNode(), CPIdx,
1911 for (
unsigned i = 0; i < NumElems; ++i) {
1917 if (TLI.shouldExpandBuildVectorWithShuffles(VT, DefinedValues.
size())) {
1918 if (!MoreThanTwoValues) {
1920 for (
unsigned i = 0; i < NumElems; ++i) {
1924 ShuffleVec[i] = V == Value1 ? 0 : NumElems;
1926 if (TLI.isShuffleMaskLegal(ShuffleVec, Node->
getValueType(0))) {
1933 Vec2 = DAG.getUNDEF(VT);
1936 return DAG.getVectorShuffle(VT, dl, Vec1, Vec2, ShuffleVec);
1946 return ExpandVectorBuildThroughStack(Node);
1956 TargetLowering::ArgListEntry Entry;
1962 Entry.IsSExt = isSigned;
1963 Entry.IsZExt = !isSigned;
1964 Args.push_back(Entry);
1966 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
1967 TLI.getPointerTy(DAG.getDataLayout()));
1975 SDValue InChain = DAG.getEntryNode();
1980 const Function *
F = DAG.getMachineFunction().getFunction();
1982 TLI.isInTailCallPosition(DAG, Node, TCChain) &&
1988 CLI.setDebugLoc(
SDLoc(Node))
1990 .setLibCallee(TLI.getLibcallCallingConv(LC), RetTy, Callee,
1992 .setTailCall(isTailCall)
1993 .setSExtResult(isSigned)
1994 .setZExtResult(!isSigned)
1995 .setIsPostTypeLegalization(
true);
1997 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
1999 if (!CallInfo.second.getNode())
2001 return DAG.getRoot();
2003 return CallInfo.first;
2009 const SDValue *Ops,
unsigned NumOps,
2010 bool isSigned,
const SDLoc &dl) {
2012 Args.reserve(NumOps);
2014 TargetLowering::ArgListEntry Entry;
2015 for (
unsigned i = 0; i != NumOps; ++i) {
2016 Entry.Node = Ops[i];
2018 Entry.IsSExt = isSigned;
2019 Entry.IsZExt = !isSigned;
2020 Args.push_back(Entry);
2022 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2023 TLI.getPointerTy(DAG.getDataLayout()));
2029 .setChain(DAG.getEntryNode())
2030 .setLibCallee(TLI.getLibcallCallingConv(LC), RetTy, Callee,
2032 .setSExtResult(isSigned)
2033 .setZExtResult(!isSigned)
2034 .setIsPostTypeLegalization(
true);
2036 std::pair<SDValue,SDValue> CallInfo = TLI.LowerCallTo(CLI);
2038 return CallInfo.first;
2043 std::pair<SDValue, SDValue>
2050 TargetLowering::ArgListEntry Entry;
2056 Entry.IsSExt = isSigned;
2057 Entry.IsZExt = !isSigned;
2058 Args.push_back(Entry);
2060 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2061 TLI.getPointerTy(DAG.getDataLayout()));
2066 CLI.setDebugLoc(
SDLoc(Node))
2068 .setLibCallee(TLI.getLibcallCallingConv(LC), RetTy, Callee,
2070 .setSExtResult(isSigned)
2071 .setZExtResult(!isSigned);
2073 std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
2085 Node = DAG.mutateStrictFPToFP(Node);
2090 case MVT::f32: LC = Call_F32;
break;
2091 case MVT::f64: LC = Call_F64;
break;
2092 case MVT::f80: LC = Call_F80;
break;
2096 return ExpandLibCall(LC, Node,
false);
2099 SDValue SelectionDAGLegalize::ExpandIntLibCall(
SDNode* Node,
bool isSigned,
2108 case MVT::i8: LC = Call_I8;
break;
2109 case MVT::i16: LC = Call_I16;
break;
2110 case MVT::i32: LC = Call_I32;
break;
2111 case MVT::i64: LC = Call_I64;
break;
2114 return ExpandLibCall(LC, Node, isSigned);
2119 SelectionDAGLegalize::ExpandDivRemLibCall(
SDNode *Node,
2137 SDValue InChain = DAG.getEntryNode();
2143 TargetLowering::ArgListEntry Entry;
2149 Entry.IsSExt = isSigned;
2150 Entry.IsZExt = !isSigned;
2151 Args.push_back(Entry);
2155 SDValue FIPtr = DAG.CreateStackTemporary(RetVT);
2158 Entry.IsSExt = isSigned;
2159 Entry.IsZExt = !isSigned;
2160 Args.push_back(Entry);
2162 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2163 TLI.getPointerTy(DAG.getDataLayout()));
2169 .setLibCallee(TLI.getLibcallCallingConv(LC), RetTy, Callee,
2171 .setSExtResult(isSigned)
2172 .setZExtResult(!isSigned);
2174 std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
2217 SelectionDAGLegalize::ExpandSinCosLibCall(
SDNode *Node,
2232 SDValue InChain = DAG.getEntryNode();
2238 TargetLowering::ArgListEntry Entry;
2243 Entry.IsSExt =
false;
2244 Entry.IsZExt =
false;
2245 Args.push_back(Entry);
2248 SDValue SinPtr = DAG.CreateStackTemporary(RetVT);
2249 Entry.Node = SinPtr;
2251 Entry.IsSExt =
false;
2252 Entry.IsZExt =
false;
2253 Args.push_back(Entry);
2256 SDValue CosPtr = DAG.CreateStackTemporary(RetVT);
2257 Entry.Node = CosPtr;
2259 Entry.IsSExt =
false;
2260 Entry.IsZExt =
false;
2261 Args.push_back(Entry);
2263 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2264 TLI.getPointerTy(DAG.getDataLayout()));
2268 CLI.setDebugLoc(dl).setChain(InChain).setLibCallee(
2269 TLI.getLibcallCallingConv(LC),
Type::getVoidTy(*DAG.getContext()), Callee,
2272 std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
2284 SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(
bool isSigned,
SDValue Op0,
2296 SDValue WordOff = DAG.getConstant(
sizeof(
int), dl,
2301 StackSlot, WordOff);
2302 if (DAG.getDataLayout().isLittleEndian())
2315 SDValue Store1 = DAG.getStore(DAG.getEntryNode(), dl, Op0Mapped,
Lo,
2326 SDValue Bias = DAG.getConstantFP(isSigned ?
2340 DAG.getIntPtrConstant(0, dl));
2346 assert(!isSigned &&
"Legalize cannot Expand SINT_TO_FP for i64 yet");
2356 DAG.getConstant(UINT64_C(0x4330000000000000), dl,
MVT::i64);
2358 DAG.getConstantFP(
BitsToDouble(UINT64_C(0x4530000000100000)), dl,
2361 DAG.getConstant(UINT64_C(0x4530000000000000), dl,
MVT::i64);
2365 DAG.getConstant(32, dl,
MVT::i64));
2383 SDValue ShiftConst = DAG.getConstant(
2384 1, dl, TLI.getShiftAmountTy(Op0.
getValueType(), DAG.getDataLayout()));
2399 return DAG.getSelect(dl,
MVT::f32, SignBitTest, Slow, Fast);
2405 DAG.getConstant(UINT64_C(0xfffffffffffff800), dl,
MVT::i64));
2407 DAG.getConstant(UINT64_C(0x800), dl,
MVT::i64));
2409 DAG.getConstant(UINT64_C(0x7ff), dl,
MVT::i64));
2411 DAG.getConstant(UINT64_C(0), dl,
MVT::i64),
2415 DAG.getConstant(UINT64_C(0x0020000000000000), dl,
2419 EVT SHVT = TLI.getShiftAmountTy(Sel2.
getValueType(), DAG.getDataLayout());
2422 DAG.getConstant(32, dl, SHVT));
2426 DAG.getConstantFP(
BitsToDouble(UINT64_C(0x41f0000000000000)), dl,
2433 DAG.getIntPtrConstant(0, dl));
2442 SDValue Zero = DAG.getIntPtrConstant(0, dl),
2443 Four = DAG.getIntPtrConstant(4, dl);
2445 SignSet, Four,
Zero);
2453 case MVT::i8 : FF = 0x43800000ULL;
break;
2454 case MVT::i16: FF = 0x47800000ULL;
break;
2455 case MVT::i32: FF = 0x4F800000ULL;
break;
2456 case MVT::i64: FF = 0x5F800000ULL;
break;
2458 if (DAG.getDataLayout().isLittleEndian())
2464 DAG.getConstantPool(FudgeFactor, TLI.getPointerTy(DAG.getDataLayout()));
2465 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->
getAlignment();
2467 Alignment =
std::min(Alignment, 4u);
2470 FudgeInReg = DAG.getLoad(
2471 MVT::f32, dl, DAG.getEntryNode(), CPIdx,
2475 SDValue Load = DAG.getExtLoad(
2492 SDValue SelectionDAGLegalize::PromoteLegalINT_TO_FP(
SDValue LegalOp,
EVT DestVT,
2498 unsigned OpToUse = 0;
2510 if (isSigned)
continue;
2523 return DAG.getNode(OpToUse, dl, DestVT,
2525 dl, NewInTy, LegalOp));
2533 SDValue SelectionDAGLegalize::PromoteLegalFP_TO_INT(
SDValue LegalOp,
EVT DestVT,
2537 EVT NewOutTy = DestVT;
2539 unsigned OpToUse = 0;
2554 if (!isSigned && TLI.isOperationLegalOrCustom(
ISD::FP_TO_UINT, NewOutTy)) {
2574 EVT SHVT = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
2584 APInt MaskHi4(Sz, 0), MaskHi2(Sz, 0), MaskHi1(Sz, 0);
2585 APInt MaskLo4(Sz, 0), MaskLo2(Sz, 0), MaskLo1(Sz, 0);
2586 for (
unsigned J = 0; J != Sz; J += 8) {
2587 MaskHi4 = MaskHi4 | (0xF0ull << J);
2588 MaskLo4 = MaskLo4 | (0x0Full << J);
2589 MaskHi2 = MaskHi2 | (0xCCull << J);
2590 MaskLo2 = MaskLo2 | (0x33ull << J);
2591 MaskHi1 = MaskHi1 | (0xAAull << J);
2592 MaskLo1 = MaskLo1 | (0x55ull << J);
2596 Tmp = (Sz > 8 ? DAG.getNode(
ISD::BSWAP, dl, VT, Op) :
Op);
2599 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskHi4, dl, VT));
2600 Tmp3 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskLo4, dl, VT));
2601 Tmp2 = DAG.
getNode(
ISD::SRL, dl, VT, Tmp2, DAG.getConstant(4, dl, VT));
2602 Tmp3 = DAG.
getNode(
ISD::SHL, dl, VT, Tmp3, DAG.getConstant(4, dl, VT));
2606 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskHi2, dl, VT));
2607 Tmp3 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskLo2, dl, VT));
2608 Tmp2 = DAG.
getNode(
ISD::SRL, dl, VT, Tmp2, DAG.getConstant(2, dl, VT));
2609 Tmp3 = DAG.
getNode(
ISD::SHL, dl, VT, Tmp3, DAG.getConstant(2, dl, VT));
2613 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskHi1, dl, VT));
2614 Tmp3 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskLo1, dl, VT));
2615 Tmp2 = DAG.
getNode(
ISD::SRL, dl, VT, Tmp2, DAG.getConstant(1, dl, VT));
2616 Tmp3 = DAG.
getNode(
ISD::SHL, dl, VT, Tmp3, DAG.getConstant(1, dl, VT));
2621 Tmp = DAG.getConstant(0, dl, VT);
2622 for (
unsigned I = 0, J = Sz-1;
I < Sz; ++
I, --J) {
2632 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp2, DAG.getConstant(Shift, dl, VT));
2642 EVT SHVT = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
2643 SDValue Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8;
2647 Tmp2 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2648 Tmp1 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2649 return DAG.getNode(
ISD::OR, dl, VT, Tmp1, Tmp2);
2651 Tmp4 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(24, dl, SHVT));
2652 Tmp3 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2653 Tmp2 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2654 Tmp1 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(24, dl, SHVT));
2656 DAG.getConstant(0xFF0000, dl, VT));
2657 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp2, DAG.getConstant(0xFF00, dl, VT));
2660 return DAG.getNode(
ISD::OR, dl, VT, Tmp4, Tmp2);
2662 Tmp8 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(56, dl, SHVT));
2663 Tmp7 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(40, dl, SHVT));
2664 Tmp6 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(24, dl, SHVT));
2665 Tmp5 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2666 Tmp4 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2667 Tmp3 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(24, dl, SHVT));
2668 Tmp2 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(40, dl, SHVT));
2669 Tmp1 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(56, dl, SHVT));
2671 DAG.getConstant(255ULL<<48, dl, VT));
2673 DAG.getConstant(255ULL<<40, dl, VT));
2675 DAG.getConstant(255ULL<<32, dl, VT));
2677 DAG.getConstant(255ULL<<24, dl, VT));
2679 DAG.getConstant(255ULL<<16, dl, VT));
2681 DAG.getConstant(255ULL<<8 , dl, VT));
2688 return DAG.getNode(
ISD::OR, dl, VT, Tmp8, Tmp4);
2693 SDValue SelectionDAGLegalize::ExpandBitCount(
unsigned Opc,
SDValue Op,
2699 EVT ShVT = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
2703 "CTPOP not implemented for this type.");
2721 DAG.getConstant(1, dl, ShVT)),
2725 DAG.getNode(
ISD::AND, dl, VT, Op, Mask33),
2728 DAG.getConstant(2, dl, ShVT)),
2734 DAG.getConstant(4, dl, ShVT))),
2738 DAG.getNode(
ISD::MUL, dl, VT, Op, Mask01),
2739 DAG.getConstant(Len - 8, dl, ShVT));
2751 EVT SetCCVT = getSetCCResultType(VT);
2753 SDValue Zero = DAG.getConstant(0, dl, VT);
2756 DAG.getConstant(len, dl, VT),
CTLZ);
2768 EVT ShVT = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
2769 for (
unsigned i = 0; (1U << i) <= (len / 2); ++i) {
2770 SDValue Tmp3 = DAG.getConstant(1ULL << i, dl, ShVT);
2774 Op = DAG.getNOT(dl, Op, VT);
2787 DAG.getNOT(dl, Op, VT),
2789 DAG.getConstant(1, dl, VT)));
2791 if (!TLI.isOperationLegalOrCustom(
ISD::CTPOP, VT) &&
2792 TLI.isOperationLegalOrCustom(
ISD::CTLZ, VT))
2793 return DAG.getNode(
ISD::SUB, dl, VT,
2796 return DAG.getNode(
ISD::CTPOP, dl, VT, Tmp3);
2801 bool SelectionDAGLegalize::ExpandNode(
SDNode *Node) {
2804 SDValue Tmp1, Tmp2, Tmp3, Tmp4;
2828 TLI.getPointerTy(DAG.getDataLayout()));
2836 DAG.getConstant(0, dl, TLI.getPointerTy(DAG.getDataLayout())));
2870 SDValue Swap = DAG.getAtomicCmpSwap(
2873 cast<AtomicSDNode>(Node)->getMemOperand());
2881 cast<AtomicSDNode>(Node)->getMemoryVT(),
2884 cast<AtomicSDNode>(Node)->getMemOperand());
2893 SDValue Res = DAG.getAtomicCmpSwap(
2896 Node->
getOperand(3), cast<MemSDNode>(Node)->getMemOperand());
2902 EVT AtomicType = cast<AtomicSDNode>(Node)->getMemoryVT();
2904 switch (TLI.getExtendForAtomicOps()) {
2919 LHS = DAG.getZeroExtendInReg(Res, dl, AtomicType);
2935 ExpandDYNAMIC_STACKALLOC(Node, Results);
2944 Results.
push_back(DAG.getConstant(0, dl, VT));
2947 Results.
push_back(DAG.getConstantFP(0, dl, VT));
2975 SDValue One = DAG.getConstant(1, dl, VT);
2977 SDValue Zero = DAG.getConstant(0, dl, VT);
2985 EVT ShiftAmountTy = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
2990 SDValue ShiftCst = DAG.getConstant(BitsDiff, dl, ShiftAmountTy);
3005 Tmp1 = EmitStackConvert(Node->
getOperand(0), ExtraVT,
3017 if (TLI.expandFP_TO_SINT(Node, Tmp1, DAG))
3024 APFloat apf(DAG.EVTToAPFloatSemantics(VT),
3028 Tmp1 = DAG.getConstantFP(apf, dl, VT);
3029 Tmp2 = DAG.getSetCC(dl, getSetCCResultType(VT),
3038 DAG.getConstant(x, dl, NVT));
3039 Tmp1 = DAG.getSelect(dl, NVT, Tmp2, True, False);
3044 Results.
push_back(DAG.expandVAArg(Node));
3045 Results.
push_back(Results[0].getValue(1));
3048 Results.
push_back(DAG.expandVACopy(Node));
3056 Tmp1 = ExpandExtractFromVectorThroughStack(
SDValue(Node, 0));
3066 Results.
push_back(ExpandVectorBuildThroughStack(Node));
3070 Results.
push_back(ExpandSCALAR_TO_VECTOR(Node));
3079 ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(Node)->getMask();
3085 if (!TLI.isTypeLegal(EltVT)) {
3087 EVT NewEltVT = TLI.getTypeToTransformTo(*DAG.getContext(), EltVT);
3092 if (NewEltVT.
bitsLT(EltVT)) {
3109 unsigned int factor =
3117 for (
unsigned fi = 0; fi < factor; ++fi)
3121 for (
unsigned fi = 0; fi < factor; ++fi)
3132 for (
unsigned i = 0; i != NumElems; ++i) {
3137 unsigned Idx = Mask[i];
3141 DAG.getConstant(Idx, dl, TLI.getVectorIdxTy(DAG.getDataLayout()))));
3145 DAG.getConstant(Idx - NumElems, dl,
3146 TLI.getVectorIdxTy(DAG.getDataLayout()))));
3149 Tmp1 = DAG.getBuildVector(VT, dl, Ops);
3157 if (cast<ConstantSDNode>(Node->
getOperand(1))->getZExtValue()) {
3161 TLI.getShiftAmountTy(
3163 DAG.getDataLayout())));
3176 if (
unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) {
3179 Results.
push_back(Results[0].getValue(1));
3188 if (
unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) {
3197 Results.
push_back(Results[0].getValue(0));
3200 Results.
push_back(ExpandFCOPYSIGN(Node));
3204 Tmp1 = DAG.getConstantFP(-0.0, dl, Node->
getValueType(0));
3228 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp1, Tmp2, Pred);
3241 SDVTList VTs = DAG.getVTList(VT, VT);
3264 if (!TLI.useSoftFloat() &&
TM.Options.UnsafeFPMath) {
3272 DAG.getIntPtrConstant(0, dl));
3283 Results.
push_back(ExpandConstantFP(CFP,
true));
3293 if (TLI.isOperationLegalOrCustom(
ISD::FADD, VT) &&
3294 TLI.isOperationLegalOrCustom(
ISD::FNEG, VT)) {
3305 TLI.isOperationLegalOrCustom(
ISD::XOR, VT) &&
3306 "Don't know how to expand this subtraction!");
3310 Tmp1 = DAG.getNode(
ISD::ADD, dl, VT, Tmp1, DAG.getConstant(1, dl, VT));
3322 if (TLI.isOperationLegalOrCustom(DivRemOpc, VT)) {
3323 SDVTList VTs = DAG.getVTList(VT, VT);
3324 Tmp1 = DAG.getNode(DivRemOpc, dl, VTs, Tmp2, Tmp3).getValue(1);
3326 }
else if (TLI.isOperationLegalOrCustom(DivOpc, VT)) {
3328 Tmp1 = DAG.getNode(DivOpc, dl, VT, Tmp2, Tmp3);
3329 Tmp1 = DAG.getNode(
ISD::MUL, dl, VT, Tmp1, Tmp3);
3330 Tmp1 = DAG.getNode(
ISD::SUB, dl, VT, Tmp2, Tmp1);
3340 if (TLI.isOperationLegalOrCustom(DivRemOpc, VT)) {
3341 SDVTList VTs = DAG.getVTList(VT, VT);
3342 Tmp1 = DAG.getNode(DivRemOpc, dl, VTs, Node->
getOperand(0),
3350 unsigned ExpandOpcode =
3353 SDVTList VTs = DAG.getVTList(VT, VT);
3355 Tmp1 = DAG.getNode(ExpandOpcode, dl, VTs, Node->
getOperand(0),
3365 unsigned MULHOpcode =
3368 if (TLI.isOperationLegalOrCustom(MULHOpcode, VT)) {
3370 Results.
push_back(DAG.getNode(MULHOpcode, dl, VT, LHS, RHS));
3376 assert(TLI.isTypeLegal(HalfType));
3377 if (TLI.expandMUL_LOHI(Node->
getOpcode(), VT, Node, LHS, RHS, Halves,
3380 for (
unsigned i = 0; i < 2; ++i) {
3383 SDValue Shift = DAG.getConstant(
3384 HalfType.getScalarSizeInBits(), dl,
3385 TLI.getShiftAmountTy(HalfType, DAG.getDataLayout()));
3394 EVT VT = Node->getValueType(0);
3395 SDVTList VTs = DAG.getVTList(VT, VT);
3401 bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::SMUL_LOHI, VT);
3402 bool HasUMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::UMUL_LOHI, VT);
3403 bool HasMULHS = TLI.isOperationLegalOrCustom(
ISD::MULHS, VT);
3404 bool HasMULHU = TLI.isOperationLegalOrCustom(
ISD::MULHU, VT);
3405 unsigned OpToUse = 0;
3406 if (HasSMUL_LOHI && !HasMULHS) {
3408 }
else if (HasUMUL_LOHI && !HasMULHU) {
3410 }
else if (HasSMUL_LOHI) {
3412 }
else if (HasUMUL_LOHI) {
3416 Results.
push_back(DAG.getNode(OpToUse, dl, VTs, Node->getOperand(0),
3417 Node->getOperand(1)));
3425 TLI.isOperationLegalOrCustom(
ISD::SHL, VT) &&
3426 TLI.isOperationLegalOrCustom(
ISD::OR, VT) &&
3427 TLI.expandMUL(Node, Lo, Hi, HalfType, DAG,
3433 TLI.getShiftAmountTy(HalfType, DAG.getDataLayout()));
3447 EVT ResultType = Node->getValueType(1);
3448 EVT OType = getSetCCResultType(Node->getValueType(0));
3463 SDValue SignsMatch = DAG.getSetCC(dl, OType, LHSSign, RHSSign,
3471 Results.
push_back(DAG.getBoolExtOrTrunc(Cmp, dl, ResultType, ResultType));
3483 EVT ResultType = Node->getValueType(1);
3484 EVT SetCCType = getSetCCResultType(Node->getValueType(0));
3487 SDValue SetCC = DAG.getSetCC(dl, SetCCType, Sum, LHS, CC);
3489 Results.
push_back(DAG.getBoolExtOrTrunc(SetCC, dl, ResultType, ResultType));
3494 EVT VT = Node->getValueType(0);
3500 static const unsigned Ops[2][3] =
3503 bool isSigned = Node->getOpcode() ==
ISD::SMULO;
3504 if (TLI.isOperationLegalOrCustom(Ops[isSigned][0], VT)) {
3506 TopHalf = DAG.
getNode(Ops[isSigned][0], dl, VT, LHS, RHS);
3507 }
else if (TLI.isOperationLegalOrCustom(Ops[isSigned][1], VT)) {
3508 BottomHalf = DAG.
getNode(Ops[isSigned][1], dl, DAG.getVTList(VT, VT), LHS,
3511 }
else if (TLI.isTypeLegal(WideVT)) {
3512 LHS = DAG.
getNode(Ops[isSigned][2], dl, WideVT, LHS);
3513 RHS = DAG.
getNode(Ops[isSigned][2], dl, WideVT, RHS);
3514 Tmp1 = DAG.getNode(
ISD::MUL, dl, WideVT, LHS, RHS);
3516 DAG.getIntPtrConstant(0, dl));
3518 DAG.getIntPtrConstant(1, dl));
3543 DAG.getConstant(LoSize - 1, dl,
3544 TLI.getPointerTy(DAG.getDataLayout())));
3547 DAG.getConstant(LoSize - 1, dl,
3548 TLI.getPointerTy(DAG.getDataLayout())));
3550 HiLHS = DAG.getConstant(0, dl, VT);
3551 HiRHS = DAG.getConstant(0, dl, VT);
3559 if(DAG.getDataLayout().isLittleEndian()) {
3564 SDValue Args[] = { LHS, HiLHS, RHS, HiRHS };
3565 Ret = ExpandLibCall(LC, WideVT, Args, 4, isSigned, dl);
3567 SDValue Args[] = { HiLHS, LHS, HiRHS, RHS };
3568 Ret = ExpandLibCall(LC, WideVT, Args, 4, isSigned, dl);
3571 "Ret value is a collection of constituent nodes holding result.");
3577 Tmp1 = DAG.getConstant(
3579 TLI.getShiftAmountTy(BottomHalf.getValueType(), DAG.getDataLayout()));
3581 TopHalf = DAG.getSetCC(dl, getSetCCResultType(VT), TopHalf, Tmp1,
3584 TopHalf = DAG.getSetCC(dl, getSetCCResultType(VT), TopHalf,
3589 EVT RType = Node->getValueType(1);
3594 "Unexpected result type for S/UMULO legalization");
3601 EVT PairTy = Node->getValueType(0);
3607 TLI.getShiftAmountTy(PairTy, DAG.getDataLayout())));
3612 Tmp1 = Node->getOperand(0);
3616 Tmp1 = DAG.getSelectCC(dl, Tmp1.getOperand(0), Tmp1.getOperand(1),
3618 cast<CondCodeSDNode>(Tmp1.getOperand(2))->
get());
3620 Tmp1 = DAG.getSelectCC(dl, Tmp1,
3621 DAG.getConstant(0, dl, Tmp1.getValueType()),
3632 EVT PTy = TLI.getPointerTy(TD);
3634 unsigned EntrySize =
3635 DAG.getMachineFunction().getJumpTableInfo()->getEntrySize(TD);
3647 if (TLI.isJumpTableRelative()) {
3652 TLI.getPICJumpTableRelocBase(Table, DAG));
3661 Tmp1 = Node->getOperand(0);
3670 Tmp3 = (Tmp2.
isUndef()) ? Tmp2 :
3675 DAG.getConstant(0, dl, Tmp3.getValueType()),
3676 Node->getOperand(2));
3681 Tmp1 = Node->getOperand(0);
3684 bool Legalized = LegalizeSetCCCondCode(Node->getValueType(0), Tmp1, Tmp2,
3685 Tmp3, NeedInvert, dl);
3697 Tmp1 = DAG.getLogicalNOT(dl, Tmp1, Tmp1->getValueType(0));
3705 EVT VT = Node->getValueType(0);
3707 switch (TLI.getBooleanContents(Tmp1->getValueType(0))) {
3717 DAG.getConstant(TrueValue, dl, VT),
3718 DAG.getConstant(0, dl, VT),
3724 Tmp1 = Node->getOperand(0);
3725 Tmp2 = Node->getOperand(1);
3726 Tmp3 = Node->getOperand(2);
3728 EVT VT = Node->getValueType(0);
3732 if (TLI.isCondCodeLegal(CCOp, Tmp1.getSimpleValueType())) {
3735 EVT CmpVT = Tmp1.getValueType();
3737 "Cannot expand ISD::SELECT_CC when ISD::SELECT also needs to be "
3740 TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), CmpVT);
3742 Results.
push_back(DAG.getSelect(dl, VT, Cond, Tmp3, Tmp4));
3747 bool Legalized =
false;
3752 Tmp1.getValueType().isInteger());
3753 if (TLI.isCondCodeLegal(InvCC, Tmp1.getSimpleValueType())) {
3756 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp4, Tmp3, InvCC);
3761 if (TLI.isCondCodeLegal(SwapInvCC, Tmp1.getSimpleValueType())) {
3765 Tmp1 = DAG.getSelectCC(dl, Tmp2, Tmp1, Tmp4, Tmp3, SwapInvCC);
3770 Legalized = LegalizeSetCCCondCode(
3771 getSetCCResultType(Tmp1.getValueType()), Tmp1, Tmp2, CC, NeedInvert,
3774 assert(Legalized &&
"Can't legalize SELECT_CC with legal condition!");
3785 Tmp1, Tmp2, Tmp3, Tmp4, CC);
3787 Tmp2 = DAG.getConstant(0, dl, Tmp1.getValueType());
3790 Tmp2, Tmp3, Tmp4, CC);
3797 Tmp1 = Node->getOperand(0);
3798 Tmp2 = Node->getOperand(2);
3799 Tmp3 = Node->getOperand(3);
3802 bool Legalized = LegalizeSetCCCondCode(getSetCCResultType(
3803 Tmp2.getValueType()), Tmp2, Tmp3, Tmp4, NeedInvert, dl);
3805 assert(Legalized &&
"Can't legalize BR_CC with legal condition!");
3818 Tmp3 = DAG.getConstant(0, dl, Tmp2.getValueType());
3820 Tmp1 = DAG.getNode(
ISD::BR_CC, dl, Node->getValueType(0), Tmp1, Tmp4,
3821 Tmp2, Tmp3, Node->getOperand(4));
3827 Results.
push_back(ExpandBUILD_VECTOR(Node));
3833 EVT VT = Node->getValueType(0);
3839 for (
unsigned Idx = 0; Idx < NumElem; Idx++) {
3842 DAG.getConstant(Idx, dl, TLI.getVectorIdxTy(DAG.getDataLayout())));
3845 DAG.getConstant(Idx, dl, TLI.getVectorIdxTy(DAG.getDataLayout())));
3846 Scalars.
push_back(DAG.getNode(Node->getOpcode(), dl,
3850 SDValue Result = DAG.getBuildVector(Node->getValueType(0), dl, Scalars);
3851 ReplaceNode(
SDValue(Node, 0), Result);
3868 if (Results.
empty())
3871 ReplaceNode(Node, Results.
data());
3875 void SelectionDAGLegalize::ConvertNodeToLibcall(
SDNode *Node) {
3878 SDValue Tmp1, Tmp2, Tmp3, Tmp4;
3891 DAG.getExternalSymbol(
"__sync_synchronize",
3892 TLI.getPointerTy(DAG.getDataLayout())),
3895 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
3919 std::pair<SDValue, SDValue> Tmp = ExpandChainLibCall(LC, Node,
false);
3931 DAG.getExternalSymbol(
3932 "abort", TLI.getPointerTy(DAG.getDataLayout())),
3934 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
3969 ExpandSinCosLibCall(Node, Results);
4083 Results.
push_back(ExpandLibCall(LC, Node,
false));
4092 Results.
push_back(ExpandIntLibCall(Node,
true,
4098 Results.
push_back(ExpandIntLibCall(Node,
false,
4104 Results.
push_back(ExpandIntLibCall(Node,
true,
4110 Results.
push_back(ExpandIntLibCall(Node,
false,
4118 ExpandDivRemLibCall(Node, Results);
4121 Results.
push_back(ExpandIntLibCall(Node,
false,
4129 if (!Results.
empty())
4130 ReplaceNode(Node, Results.
data());
4136 MVT EltVT,
MVT NewEltVT) {
4143 void SelectionDAGLegalize::PromoteNode(
SDNode *Node) {
4155 MVT NVT = TLI.getTypeToPromoteTo(Node->
getOpcode(), OVT);
4173 DAG.getConstant(TopBit, dl, NVT));
4177 Tmp1 = DAG.getNode(Node->
getOpcode(), dl, NVT, Tmp1);
4181 Tmp1 = DAG.getNode(
ISD::SUB, dl, NVT, Tmp1,
4182 DAG.getConstant(NVT.getSizeInBits() -
4189 unsigned DiffBits = NVT.getSizeInBits() - OVT.
getSizeInBits();
4191 Tmp1 = DAG.getNode(Node->
getOpcode(), dl, NVT, Tmp1);
4194 DAG.getConstant(DiffBits, dl,
4195 TLI.getShiftAmountTy(NVT, DAG.getDataLayout())));
4220 &&
"VAARG promotion is supported only for vectors or integer types");
4225 Tmp1 = DAG.getVAArg(NVT, dl, Chain, Ptr, Node->
getOperand(2),
4229 Tmp2 = DAG.
getNode(TruncOp, dl, OVT, Tmp1);
4233 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 0), Tmp2);
4234 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 1), Chain);
4236 UpdatedNodes->insert(Tmp2.
getNode());
4237 UpdatedNodes->insert(Chain.
getNode());
4250 unsigned ExtOp, TruncOp;
4273 Tmp1 = DAG.getNode(ExtOp, dl, NVT, Node->
getOperand(0));
4276 Tmp1 = DAG.getNode(Node->
getOpcode(), dl, NVT, Tmp1, Tmp2);
4277 Results.
push_back(DAG.getNode(TruncOp, dl, OVT, Tmp1));
4285 Tmp1 = DAG.getNode(ExtOp, dl, NVT, Node->
getOperand(0));
4287 Tmp1 = DAG.getNode(
ISD::MUL, dl, NVT, Tmp1, Tmp2);
4289 auto &DL = DAG.getDataLayout();
4293 DAG.getConstant(OriginalSize, dl, TLI.getScalarShiftAmountTy(DL, NVT)));
4299 unsigned ExtOp, TruncOp;
4316 Tmp1 = DAG.getSelect(dl, NVT, Tmp1, Tmp2, Tmp3);
4318 Tmp1 = DAG.getNode(TruncOp, dl, Node->
getValueType(0), Tmp1);
4320 Tmp1 = DAG.getNode(TruncOp, dl, Node->
getValueType(0), Tmp1,
4321 DAG.getIntPtrConstant(0, dl));
4326 ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(Node)->getMask();
4333 Tmp1 = ShuffleWithNarrowerEltType(NVT, OVT, dl, Tmp1, Tmp2, Mask);
4340 if (NVT.isInteger()) {
4342 cast<CondCodeSDNode>(Node->
getOperand(2))->
get();
4345 Tmp1 = DAG.getNode(ExtOp, dl, NVT, Node->
getOperand(0));
4353 if (NVT.isInteger()) {
4355 cast<CondCodeSDNode>(Node->
getOperand(1))->
get();
4358 Tmp1 = DAG.getNode(ExtOp, dl, NVT, Node->
getOperand(2));
4359 Tmp2 = DAG.getNode(ExtOp, dl, NVT, Node->
getOperand(3));
4378 Tmp3, DAG.getIntPtrConstant(0, dl)));
4387 DAG.getNode(Node->
getOpcode(), dl, NVT, Tmp1, Tmp2, Tmp3),
4388 DAG.getIntPtrConstant(0, dl)));
4404 Tmp3, DAG.getIntPtrConstant(isTrunc, dl)));
4424 Tmp2 = DAG.getNode(Node->
getOpcode(), dl, NVT, Tmp1);
4426 Tmp2, DAG.getIntPtrConstant(0, dl)));
4440 "Invalid promote type for build_vector");
4473 "Invalid promote type for extract_vector_elt");
4477 unsigned NewEltsPerOldElt = MidVT.getVectorNumElements();
4482 SDValue Factor = DAG.getConstant(NewEltsPerOldElt, SL, IdxVT);
4488 for (
unsigned I = 0;
I < NewEltsPerOldElt; ++
I) {
4489 SDValue IdxOffset = DAG.getConstant(
I, SL, IdxVT);
4497 SDValue NewVec = DAG.getBuildVector(MidVT, SL, NewOps);
4519 "Invalid promote type for insert_vector_elt");
4523 unsigned NewEltsPerOldElt = MidVT.getVectorNumElements();
4530 SDValue Factor = DAG.getConstant(NewEltsPerOldElt,
SDLoc(), IdxVT);
4537 for (
unsigned I = 0;
I < NewEltsPerOldElt; ++
I) {
4538 SDValue IdxOffset = DAG.getConstant(
I, SL, IdxVT);
4542 CastVal, IdxOffset);
4545 NewVec, Elt, InEltIdx);
4582 if (!Results.
empty())
4583 ReplaceNode(Node, Results.
data());
4599 SelectionDAGLegalize
Legalizer(*
this, LegalizedNodes);
4606 bool AnyLegalized =
false;
4617 if (LegalizedNodes.
insert(N).second) {
4618 AnyLegalized =
true;
4619 Legalizer.LegalizeOp(N);
4639 SelectionDAGLegalize
Legalizer(*
this, LegalizedNodes, &UpdatedNodes);
4643 LegalizedNodes.
insert(N);
4644 Legalizer.LegalizeOp(N);
4646 return LegalizedNodes.
count(N);
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
bool LegalizeOp(SDNode *N, SmallSetVector< SDNode *, 16 > &UpdatedNodes)
Transforms a SelectionDAG node and any operands to it into a node that is compatible with the target ...
ADJUST_TRAMPOLINE - This corresponds to the adjust_trampoline intrinsic.
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
bool use_empty() const
Return true if there are no uses of this node.
void push_back(const T &Elt)
BUILTIN_OP_END - This must be the last enum value in this list.
A parsed version of the target data layout string in and methods for querying it. ...
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
SDValue getValue(unsigned R) const
static bool isConstant(const MachineInstr &MI)
static MachinePointerInfo getJumpTable(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a jump table entry.
Constrained versions of libm-equivalent floating point intrinsics.
EXTRACT_ELEMENT - This is used to get the lower or upper (determined by a Constant, which is required to be operand #1) half of the integer or float value specified as operand #0.
Flags getFlags() const
Return the raw flags of the source value,.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
NodeType getExtForLoadExtType(bool IsFP, LoadExtType)
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an vector value) starting with the ...
BR_CC - Conditional branch.
static MVT getVectorVT(MVT VT, unsigned NumElements)
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
SDVTList getVTList() const
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
Libcall getSYNC(unsigned Opc, MVT VT)
Return the SYNC_FETCH_AND_* value for the given opcode and type, or UNKNOWN_LIBCALL if there is none...
static bool hasPredecessorHelper(const SDNode *N, SmallPtrSetImpl< const SDNode * > &Visited, SmallVectorImpl< const SDNode * > &Worklist, unsigned int MaxSteps=0)
Returns true if N is a predecessor of any node in Worklist.
const TargetMachine & getTarget() const
unsigned getScalarSizeInBits() const
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain...
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit...
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
Function Alias Analysis Results
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
unsigned getSizeInBits() const
static MVT getPromotedVectorElementType(const TargetLowering &TLI, MVT EltVT, MVT NewEltVT)
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
unsigned getNumOperands() const
Return the number of values used by this operation.
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned Num) const
bool bitsLT(MVT VT) const
Return true if this has less bits than VT.
static IntegerType * getInt64Ty(LLVMContext &C)
[US]{MIN/MAX} - Binary minimum or maximum or signed or unsigned integers.
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
void reserve(size_type N)
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
void DeleteNode(SDNode *N)
Remove the specified node from the system.
const SDValue & getBasePtr() const
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1 at the ...
OUTCHAIN = ATOMIC_FENCE(INCHAIN, ordering, scope) This corresponds to the fence instruction.
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Libcall getFPROUND(EVT OpVT, EVT RetVT)
getFPROUND - Return the FPROUND_*_* value for the given types, or UNKNOWN_LIBCALL if there is none...
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
OUTCHAIN = EH_SJLJ_LONGJMP(INCHAIN, buffer) This corresponds to the eh.sjlj.longjmp intrinsic...
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations...
bool isVector() const
Return true if this is a vector value type.
static uint32_t getAlignment(const MCSectionCOFF &Sec)
Shift and rotation operations.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static Constant * get(ArrayRef< Constant * > V)
FLT_ROUNDS_ - Returns current rounding mode: -1 Undefined 0 Round to 0 1 Round to nearest 2 Round to ...
MachinePointerInfo getWithOffset(int64_t O) const
APInt bitcastToAPInt() const
CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of a call sequence, and carry arbitrary information that target might want to know.
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
EH_DWARF_CFA - This node represents the pointer to the DWARF Canonical Frame Address (CFA)...
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt) For double-word atomic operations: ValLo, ValHi, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amtLo, amtHi) ValLo, ValHi, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amtLo, amtHi) These correspond to the atomicrmw instruction.
allnodes_const_iterator allnodes_end() const
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
bool isInteger() const
Return true if this is an integer or a vector integer type.
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
LLVM_NODISCARD bool empty() const
STACKSAVE - STACKSAVE has one operand, an input chain.
FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to first (possible) on-stack ar...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
EVT getVectorElementType() const
Given a vector type, return the type of each element.
unsigned AssignTopologicalOrder()
Topological-sort the AllNodes list and a assign a unique node id for each node in the DAG based on th...
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
OUTCHAIN = EH_SJLJ_SETUP_DISPATCH(INCHAIN) The target initializes the dispatch table here...
falkor hwpf fix Falkor HW Prefetch Fix Late Phase
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
Simple integer binary arithmetic operators.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isLittleEndian() const
Layout endianness...
const SDValue & getBasePtr() const
EVT getHalfSizedIntegerVT(LLVMContext &Context) const
Finds the smallest simple value type that is greater than or equal to half the width of this EVT...
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification, or lowering of the constant.
EVT getMemoryVT() const
Return the type of the in-memory value.
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
static bool useSinCos(SDNode *Node)
Only issue sincos libcall if both sin and cos are needed.
const ConstantInt * getConstantIntValue() const
bool isSignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs a signed comparison when used with integer o...
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
UNDEF - An undefined node.
This class is used to represent ISD::STORE nodes.
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
SDNode * getNode() const
get the SDNode which holds the desired result
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
bool hasPredecessor(const SDNode *N) const
Return true if N is a predecessor of this node.
unsigned getScalarSizeInBits() const
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
Type * getReturnType() const
Returns the type of the ret val.
SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2, ArrayRef< int > Mask)
Return an ISD::VECTOR_SHUFFLE node.
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
unsigned getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
bool isInteger() const
Return true if this is an integer or a vector integer type.
virtual bool isShuffleMaskLegal(const SmallVectorImpl< int > &, EVT) const
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations, those with specific masks.
READ_REGISTER, WRITE_REGISTER - This node represents llvm.register on the DAG, which implements the n...
unsigned getVectorNumElements() const
APInt trunc(unsigned width) const
Truncate to new width.
void Legalize()
This transforms the SelectionDAG into a SelectionDAG that is compatible with the target instruction s...
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
const SDValue & getOperand(unsigned i) const
The instances of the Type class are immutable: once they are created, they are never changed...
void swap(SmallVectorImpl &RHS)
Simple binary floating point operators.
This is an important base class in LLVM.
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE...
bool isVector() const
Return true if this is a vector value type.
const SDNodeFlags getFlags() const
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ConstantFP - Floating Point Values [float, double].
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
void RemoveDeadNodes()
This method deletes all unreachable nodes in the SelectionDAG.
static Type * getVoidTy(LLVMContext &C)
This class provides iterator support for SDUse operands that use a specific SDNode.
INIT_TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
unsigned getOpcode() const
static TargetLowering::LegalizeAction getStrictFPOpcodeAction(const TargetLowering &TLI, unsigned Opcode, EVT VT)
TRAP - Trapping instruction.
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
DEBUGTRAP - Trap intended to get the attention of a debugger.
CondCode getSetCCSwappedOperands(CondCode Operation)
Return the operation corresponding to (Y op X) when given the operation for (X op Y)...
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
const SDValue & getValue() const
static bool isValueValidForType(EVT VT, const APFloat &Val)
Bit counting operators with an undefined result for zero inputs.
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo...
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
std::vector< ArgListEntry > ArgListTy
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const APFloat & getValueAPF() const
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
const ConstantFP * getConstantFPValue() const
This structure contains all information that is necessary for lowering calls.
This class contains a discriminated union of information about pointers in memory operands...
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
const MachinePointerInfo & getPointerInfo() const
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
TokenFactor - This node takes multiple tokens as input and produces a single token result...
A SetVector that performs no allocations if smaller than a certain size.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
void dump() const
Dump this node, for debugging.
allnodes_const_iterator allnodes_begin() const
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and rounds it to a floating point val...
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
BRCOND - Conditional branch.
const SDValue & getChain() const
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Byte Swap and Counting operators.
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Represents one node in the SelectionDAG.
CondCode getSetCCInverse(CondCode Operation, bool isInteger)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
double BitsToDouble(uint64_t Bits)
This function takes a 64-bit integer and returns the bit equivalent double.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
C - The default llvm calling convention, compatible with C.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
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...
Class for arbitrary precision integers.
Select(COND, TRUEVAL, FALSEVAL).
op_iterator op_begin() const
static use_iterator use_end()
ZERO_EXTEND - Used for integer types, zeroing the new bits.
ANY_EXTEND - Used for integer types. The high bits are undefined.
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
iterator_range< value_op_iterator > op_values() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Flags
Flags values. These may be or'd together.
llvm_unreachable("Unknown RegBank!")
unsigned getAddressSpace() const
Return the address space for the associated pointer.
GET_DYNAMIC_AREA_OFFSET - get offset from native SP to the address of the most recent dynamic alloca...
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
BR_JT - Jumptable branch.
static std::vector< std::string > Flags
VACOPY - VACOPY has 5 operands: an input chain, a destination pointer, a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the source.
These are IR-level optimization flags that may be propagated to SDNodes.
Bitwise operators - logical and, logical or, logical xor.
pointer data()
Return a pointer to the vector's buffer, even if empty().
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
void ReplaceAllUsesWith(SDValue From, SDValue Op)
Modify anything using 'From' to use 'To' instead.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
op_iterator op_end() const
Fast - This calling convention attempts to make calls as fast as possible (e.g.
bool reachesChainWithoutSideEffects(SDValue Dest, unsigned Depth=2) const
Return true if this operand (which must be a chain) reaches the specified operand without crossing an...
FSINCOS - Compute both fsin and fcos as a single operation.
static MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
RESULT, OUTCHAIN = EH_SJLJ_SETJMP(INCHAIN, buffer) This corresponds to the eh.sjlj.setjmp intrinsic.
EVT getValueType() const
Return the ValueType of the referenced return value.
OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 'eh_return' gcc dwarf builtin...
Like SetCC, ops #0 and #1 are the LHS and RHS operands to compare, and op #2 is a carry value...
const APFloat & getValueAPF() const
bool isByteSized() const
Return true if the bit size is a multiple of 8.
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
This class is used to form a handle around another node that is persistent and is updated across invo...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isSinCosLibcallAvailable(SDNode *Node, const TargetLowering &TLI)
Return true if sincos libcall is available.
LLVM Value Representation.
FMA - Perform a * b + c with no intermediate rounding step.
static bool ExpandBVWithShuffles(SDNode *Node, SelectionDAG &DAG, const TargetLowering &TLI, SDValue &Res)
EVT changeTypeToInteger()
Return the type converted to an equivalently sized integer or vector with integer element type...
bool isTruncatingStore() const
Return true if the op does a truncation before store.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
PREFETCH - This corresponds to a prefetch intrinsic.
const TargetLowering & getTargetLoweringInfo() const
Primary interface to the complete machine description for the target machine.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations...
SetCC operator - This evaluates to a true value iff the condition is true.
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
MVT getVectorElementType() const
bool isStrictFPOpcode()
Test if this node is a strict floating point pseudo-op.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
OUTCHAIN = ATOMIC_STORE(INCHAIN, ptr, val) This corresponds to "store atomic" instruction.
TRUNCATE - Completely drop the high bits.
unsigned getAlignment() const
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, FLOG, FLOG2, FLOG10, FEXP, FEXP2, FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR - Perform various unary floating point operations.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
This file describes how to lower LLVM code to machine code.
bool isVoidTy() const
Return true if this is 'void'.
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
This class is used to represent ISD::LOAD nodes.
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary...