56 #define DEBUG_TYPE "legalizedag" 62 struct FloatSignAsInt {
85 class SelectionDAGLegalize {
97 EVT getSetCCResultType(
EVT VT)
const {
108 LegalizedNodes(LegalizedNodes), UpdatedNodes(UpdatedNodes) {}
111 void LegalizeOp(
SDNode *Node);
116 void LegalizeLoadOps(
SDNode *Node);
117 void LegalizeStoreOps(
SDNode *Node);
138 bool IsSignaling =
false);
153 void ExpandArgFPLibCall(
SDNode *Node,
168 void ExpandDYNAMIC_STACKALLOC(
SDNode *Node,
170 void getSignAsIntValue(FloatSignAsInt &State,
const SDLoc &DL,
172 SDValue modifySignAsInt(
const FloatSignAsInt &State,
const SDLoc &DL,
179 void PromoteLegalFP_TO_INT(
SDNode *N,
const SDLoc &dl,
193 bool ExpandNode(
SDNode *Node);
194 void ConvertNodeToLibcall(
SDNode *Node);
195 void PromoteNode(
SDNode *Node);
200 void ReplacedNode(
SDNode *N) {
201 LegalizedNodes.
erase(N);
208 dbgs() <<
" with: "; New->
dump(&DAG));
211 "Replacing one node with another that produces a different number " 215 UpdatedNodes->
insert(New);
221 dbgs() <<
" with: "; New->
dump(&DAG));
237 UpdatedNodes->
insert(New[i].getNode());
244 dbgs() <<
" with: "; New->
dump(&DAG));
259 SDValue SelectionDAGLegalize::ShuffleWithNarrowerEltType(
264 unsigned NumEltsGrowth = NumDestElts / NumMaskElts;
266 assert(NumEltsGrowth &&
"Cannot promote to vector type with fewer elts!");
268 if (NumEltsGrowth == 1)
269 return DAG.getVectorShuffle(NVT, dl, N1, N2, Mask);
272 for (
unsigned i = 0; i != NumMaskElts; ++i) {
274 for (
unsigned j = 0; j != NumEltsGrowth; ++j) {
278 NewMask.
push_back(Idx * NumEltsGrowth + j);
281 assert(NewMask.
size() == NumDestElts &&
"Non-integer NumEltsGrowth?");
282 assert(TLI.isShuffleMaskLegal(NewMask, NVT) &&
"Shuffle not legal?");
283 return DAG.getVectorShuffle(NVT, dl, N1, N2, NewMask);
320 TLI.ShouldShrinkFPConstant(OrigVT)) {
330 DAG.getConstantPool(LLVMC, TLI.getPointerTy(DAG.getDataLayout()));
331 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->
getAlignment();
333 SDValue Result = DAG.getExtLoad(
340 OrigVT, dl, DAG.getEntryNode(), CPIdx,
350 TLI.getPointerTy(DAG.getDataLayout()));
351 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->
getAlignment();
353 VT, dl, DAG.getEntryNode(), CPIdx,
362 SDValue SelectionDAGLegalize::PerformInsertVectorEltInMemory(
SDValue Vec,
378 SDValue StackPtr = DAG.CreateStackTemporary(VT);
380 int SPFI = cast<FrameIndexSDNode>(StackPtr.
getNode())->getIndex();
384 DAG.getEntryNode(), dl, Tmp1, StackPtr,
387 SDValue StackPtr2 = TLI.getVectorElementPointer(DAG, StackPtr, VT, Tmp3);
393 DAG.getMachineFunction(), SPFI));
414 for (
unsigned i = 0; i != NumElts; ++i)
415 ShufOps.
push_back(i != InsertPos->getZExtValue() ? i : NumElts);
417 return DAG.getVectorShuffle(Vec.
getValueType(), dl, Vec, ScVec, ShufOps);
420 return PerformInsertVectorEltInMemory(Vec, Val, Idx, dl);
445 bitcastToAPInt().zextOrTrunc(32),
447 return DAG.getStore(Chain, dl, Con, Ptr, ST->
getPointerInfo(), Alignment,
457 Alignment, MMOFlags, AAInfo);
467 if (DAG.getDataLayout().isBigEndian())
470 Lo = DAG.getStore(Chain, dl, Lo, Ptr, ST->
getPointerInfo(), Alignment,
472 Ptr = DAG.getMemBasePlusOffset(Ptr, 4, dl);
473 Hi = DAG.getStore(Chain, dl, Hi, Ptr,
475 MinAlign(Alignment, 4U), MMOFlags, AAInfo);
484 void SelectionDAGLegalize::LegalizeStoreOps(
SDNode *Node) {
496 if (
SDNode *OptStore = OptimizeFloatStore(ST).getNode()) {
497 ReplaceNode(ST, OptStore);
503 switch (TLI.getOperationAction(
ISD::STORE, VT)) {
510 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(), DL, MemVT,
513 SDValue Result = TLI.expandUnalignedStore(ST, DAG);
514 ReplaceNode(
SDValue(ST, 0), Result);
522 if (Res && Res !=
SDValue(Node, 0))
523 ReplaceNode(
SDValue(Node, 0), Res);
529 "Can only promote stores to same size type");
533 Alignment, MMOFlags, AAInfo);
534 ReplaceNode(
SDValue(Node, 0), Result);
545 auto &DL = DAG.getDataLayout();
553 Value = DAG.getZeroExtendInReg(Value, dl, StVT);
555 DAG.getTruncStore(Chain, dl, Value, Ptr, ST->
getPointerInfo(), NVT,
556 Alignment, MMOFlags, AAInfo);
557 ReplaceNode(
SDValue(Node, 0), Result);
558 }
else if (StWidth & (StWidth - 1)) {
561 unsigned LogStWidth =
Log2_32(StWidth);
563 unsigned RoundWidth = 1 << LogStWidth;
564 assert(RoundWidth < StWidth);
565 unsigned ExtraWidth = StWidth - RoundWidth;
566 assert(ExtraWidth < RoundWidth);
567 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
568 "Store size not an integral number of bytes!");
572 unsigned IncrementSize;
574 if (DL.isLittleEndian()) {
577 Lo = DAG.getTruncStore(Chain, dl, Value, Ptr, ST->
getPointerInfo(),
578 RoundVT, Alignment, MMOFlags, AAInfo);
581 IncrementSize = RoundWidth / 8;
582 Ptr = DAG.getMemBasePlusOffset(Ptr, IncrementSize, dl);
585 DAG.getConstant(RoundWidth, dl,
587 Hi = DAG.getTruncStore(
590 MinAlign(Alignment, IncrementSize), MMOFlags, AAInfo);
597 DAG.getConstant(ExtraWidth, dl,
600 RoundVT, Alignment, MMOFlags, AAInfo);
603 IncrementSize = RoundWidth / 8;
605 DAG.getConstant(IncrementSize, dl,
607 Lo = DAG.getTruncStore(
608 Chain, dl, Value, Ptr,
610 MinAlign(Alignment, IncrementSize), MMOFlags, AAInfo);
615 ReplaceNode(
SDValue(Node, 0), Result);
623 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(), DL, MemVT,
625 SDValue Result = TLI.expandUnalignedStore(ST, DAG);
626 ReplaceNode(
SDValue(ST, 0), Result);
632 if (Res && Res !=
SDValue(Node, 0))
633 ReplaceNode(
SDValue(Node, 0), Res);
638 "Vector Stores are handled in LegalizeVectorOps");
643 if (TLI.isTypeLegal(StVT)) {
645 Result = DAG.getStore(Chain, dl, Value, Ptr, ST->
getPointerInfo(),
646 Alignment, MMOFlags, AAInfo);
651 TLI.getTypeToTransformTo(*DAG.getContext(), StVT),
653 Result = DAG.getTruncStore(Chain, dl, Value, Ptr, ST->
getPointerInfo(),
654 StVT, Alignment, MMOFlags, AAInfo);
657 ReplaceNode(
SDValue(Node, 0), Result);
663 void SelectionDAGLegalize::LegalizeLoadOps(
SDNode *Node) {
672 LLVM_DEBUG(
dbgs() <<
"Legalizing non-extending load operation\n");
677 switch (TLI.getOperationAction(Node->
getOpcode(), VT)) {
684 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(), DL, MemVT,
686 std::tie(RVal, RChain) = TLI.expandUnalignedLoad(LD, DAG);
691 if (
SDValue Res = TLI.LowerOperation(RVal, DAG)) {
698 MVT NVT = TLI.getTypeToPromoteTo(Node->
getOpcode(), VT);
700 "Can only promote loads to same size type");
708 if (RChain.
getNode() != Node) {
709 assert(RVal.
getNode() != Node &&
"Load must be completely replaced");
710 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 0), RVal);
711 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 1), RChain);
713 UpdatedNodes->insert(RVal.
getNode());
714 UpdatedNodes->insert(RChain.
getNode());
752 DAG.getExtLoad(NewExtType, dl, Node->
getValueType(0), Chain, Ptr,
770 }
else if (SrcWidth & (SrcWidth - 1)) {
773 unsigned LogSrcWidth =
Log2_32(SrcWidth);
775 unsigned RoundWidth = 1 << LogSrcWidth;
776 assert(RoundWidth < SrcWidth);
777 unsigned ExtraWidth = SrcWidth - RoundWidth;
778 assert(ExtraWidth < RoundWidth);
779 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
780 "Load size not an integral number of bytes!");
784 unsigned IncrementSize;
785 auto &DL = DAG.getDataLayout();
787 if (DL.isLittleEndian()) {
795 IncrementSize = RoundWidth / 8;
796 Ptr = DAG.getMemBasePlusOffset(Ptr, IncrementSize, dl);
797 Hi = DAG.getExtLoad(ExtType, dl, Node->
getValueType(0), Chain, Ptr,
799 ExtraVT,
MinAlign(Alignment, IncrementSize), MMOFlags,
810 DAG.getConstant(RoundWidth, dl,
811 TLI.getShiftAmountTy(Hi.getValueType(), DL)));
819 Hi = DAG.getExtLoad(ExtType, dl, Node->
getValueType(0), Chain, Ptr,
824 IncrementSize = RoundWidth / 8;
825 Ptr = DAG.getMemBasePlusOffset(Ptr, IncrementSize, dl);
828 ExtraVT,
MinAlign(Alignment, IncrementSize), MMOFlags,
839 DAG.getConstant(ExtraWidth, dl,
840 TLI.getShiftAmountTy(Hi.getValueType(), DL)));
848 bool isCustom =
false;
849 switch (TLI.getLoadExtAction(ExtType, Node->
getValueType(0),
869 if (!TLI.allowsMemoryAccess(*DAG.getContext(), DL, MemVT,
871 std::tie(Value, Chain) = TLI.expandUnalignedLoad(LD, DAG);
882 if (TLI.isTypeLegal(SrcVT) ||
883 TLI.isLoadExtLegal(ExtType, LoadVT, SrcVT)) {
889 SDValue Load = DAG.getExtLoad(MidExtType, dl, LoadVT, Chain, Ptr,
916 "Vector Loads are handled in LegalizeVectorOps");
923 "EXTLOAD should always be supported!");
936 ValRes = DAG.getZeroExtendInReg(Result, dl, SrcVT.getScalarType());
946 if (Chain.getNode() != Node) {
947 assert(Value.
getNode() != Node &&
"Load must be completely replaced");
948 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 0), Value);
949 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 1), Chain);
951 UpdatedNodes->insert(Value.
getNode());
952 UpdatedNodes->insert(Chain.getNode());
959 void SelectionDAGLegalize::LegalizeOp(
SDNode *Node) {
971 "Unexpected illegal type!");
974 assert((TLI.getTypeAction(*DAG.getContext(),
Op.getValueType()) ==
978 "Unexpected illegal type!");
983 bool SimpleFinishLegalizing =
true;
992 Action = TLI.getOperationAction(Node->
getOpcode(),
996 Action = TLI.getOperationAction(Node->
getOpcode(),
1009 Action = TLI.getOperationAction(Node->
getOpcode(),
1021 Action = TLI.getOperationAction(Node->
getOpcode(),
1025 EVT InnerType = cast<VTSDNode>(Node->
getOperand(1))->getVT();
1026 Action = TLI.getOperationAction(Node->
getOpcode(), InnerType);
1030 Action = TLI.getOperationAction(Node->
getOpcode(),
1047 cast<CondCodeSDNode>(Node->
getOperand(CCOperand))->
get();
1048 Action = TLI.getCondCodeAction(CCCode, OpVT);
1051 Action = TLI.getOperationAction(Node->
getOpcode(),
1054 Action = TLI.getOperationAction(Node->
getOpcode(), OpVT);
1062 SimpleFinishLegalizing =
false;
1069 SimpleFinishLegalizing =
false;
1117 ReplaceNode(Node, NewVal.
getNode());
1136 Action = TLI.getFixedPointOperationAction(Node->
getOpcode(),
1141 Action = TLI.getOperationAction(Node->
getOpcode(),
1142 cast<MaskedScatterSDNode>(Node)->getValue().getValueType());
1145 Action = TLI.getOperationAction(Node->
getOpcode(),
1146 cast<MaskedStoreSDNode>(Node)->getValue().getValueType());
1161 Action = TLI.getOperationAction(
1173 if (SimpleFinishLegalizing) {
1194 NewNode = DAG.UpdateNodeOperands(Node, Op0, SAO);
1214 NewNode = DAG.UpdateNodeOperands(Node, Op0, Op1, SAO);
1220 if (NewNode != Node) {
1221 ReplaceNode(Node, NewNode);
1233 if (!(Res.getNode() != Node || Res.getResNo() != 0))
1239 ReplaceNode(
SDValue(Node, 0), Res);
1247 ReplaceNode(Node, ResultVals.
data());
1253 if (ExpandNode(Node))
1257 ConvertNodeToLibcall(Node);
1278 return LegalizeLoadOps(Node);
1280 return LegalizeStoreOps(Node);
1284 SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(
SDValue Op) {
1305 if (
StoreSDNode *ST = dyn_cast<StoreSDNode>(User)) {
1334 StackPtr = DAG.CreateStackTemporary(VecVT);
1335 Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr,
1339 StackPtr = TLI.getVectorElementPointer(DAG, StackPtr, VecVT, Idx);
1352 DAG.ReplaceAllUsesOfValueWith(Ch,
SDValue(NewLoad.
getNode(), 1));
1358 NewLoadOperands[0] = Ch;
1360 SDValue(DAG.UpdateNodeOperands(NewLoad.
getNode(), NewLoadOperands), 0);
1364 SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(
SDValue Op) {
1373 EVT VecVT = Vec.getValueType();
1374 SDValue StackPtr = DAG.CreateStackTemporary(VecVT);
1375 int FI = cast<FrameIndexSDNode>(StackPtr.
getNode())->getIndex();
1380 SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, PtrInfo);
1383 SDValue SubStackPtr = TLI.getVectorElementPointer(DAG, StackPtr, VecVT, Idx);
1389 return DAG.getLoad(Op.
getValueType(), dl, Ch, StackPtr, PtrInfo);
1392 SDValue SelectionDAGLegalize::ExpandVectorBuildThroughStack(
SDNode* Node) {
1400 SDValue FIPtr = DAG.CreateStackTemporary(VT);
1401 int FI = cast<FrameIndexSDNode>(FIPtr.
getNode())->getIndex();
1408 assert(TypeByteSize > 0 &&
"Vector element type too small for stack store!");
1414 unsigned Offset = TypeByteSize*i;
1417 Idx = DAG.getMemBasePlusOffset(FIPtr, Idx, dl);
1422 Stores.push_back(DAG.getTruncStore(DAG.getEntryNode(), dl,
1426 Stores.push_back(DAG.getStore(DAG.getEntryNode(), dl, Node->
getOperand(i),
1431 if (!Stores.empty())
1434 StoreChain = DAG.getEntryNode();
1437 return DAG.getLoad(VT, dl, StoreChain, FIPtr, PtrInfo);
1443 void SelectionDAGLegalize::getSignAsIntValue(FloatSignAsInt &State,
1448 State.FloatVT = FloatVT;
1451 if (TLI.isTypeLegal(IVT)) {
1452 State.IntValue = DAG.getNode(
ISD::BITCAST, DL, IVT, Value);
1454 State.SignBit = NumBits - 1;
1460 MVT LoadTy = TLI.getRegisterType(*DAG.getContext(),
MVT::i8);
1462 SDValue StackPtr = DAG.CreateStackTemporary(FloatVT, LoadTy);
1463 int FI = cast<FrameIndexSDNode>(StackPtr.
getNode())->getIndex();
1465 State.FloatPtr = StackPtr;
1468 State.Chain = DAG.getStore(DAG.getEntryNode(), DL,
Value, State.FloatPtr,
1469 State.FloatPointerInfo);
1476 State.IntPointerInfo = State.FloatPointerInfo;
1480 IntPtr = DAG.getMemBasePlusOffset(StackPtr, ByteOffset, DL);
1485 State.IntPtr = IntPtr;
1486 State.IntValue = DAG.getExtLoad(
ISD::EXTLOAD, DL, LoadTy, State.Chain, IntPtr,
1487 State.IntPointerInfo,
MVT::i8);
1494 SDValue SelectionDAGLegalize::modifySignAsInt(
const FloatSignAsInt &State,
1501 SDValue Chain = DAG.getTruncStore(State.Chain, DL, NewIntValue, State.IntPtr,
1502 State.IntPointerInfo,
MVT::i8);
1503 return DAG.getLoad(State.FloatVT, DL, Chain, State.FloatPtr,
1504 State.FloatPointerInfo);
1507 SDValue SelectionDAGLegalize::ExpandFCOPYSIGN(
SDNode *Node)
const {
1513 FloatSignAsInt SignAsInt;
1514 getSignAsIntValue(SignAsInt, DL, Sign);
1516 EVT IntVT = SignAsInt.IntValue.getValueType();
1517 SDValue SignMask = DAG.getConstant(SignAsInt.SignMask, DL, IntVT);
1523 if (TLI.isOperationLegalOrCustom(
ISD::FABS, FloatVT) &&
1524 TLI.isOperationLegalOrCustom(
ISD::FNEG, FloatVT)) {
1527 SDValue Cond = DAG.getSetCC(DL, getSetCCResultType(IntVT), SignBit,
1529 return DAG.getSelect(DL, FloatVT, Cond, NegValue, AbsValue);
1533 FloatSignAsInt MagAsInt;
1534 getSignAsIntValue(MagAsInt, DL, Mag);
1535 EVT MagVT = MagAsInt.IntValue.getValueType();
1536 SDValue ClearSignMask = DAG.getConstant(~MagAsInt.SignMask, DL, MagVT);
1541 int ShiftAmount = SignAsInt.SignBit - MagAsInt.SignBit;
1542 EVT ShiftVT = IntVT;
1547 if (ShiftAmount > 0) {
1548 SDValue ShiftCnst = DAG.getConstant(ShiftAmount, DL, ShiftVT);
1550 }
else if (ShiftAmount < 0) {
1551 SDValue ShiftCnst = DAG.getConstant(-ShiftAmount, DL, ShiftVT);
1560 return modifySignAsInt(MagAsInt, DL, CopiedSign);
1563 SDValue SelectionDAGLegalize::ExpandFABS(
SDNode *Node)
const {
1570 SDValue Zero = DAG.getConstantFP(0.0, DL, FloatVT);
1575 FloatSignAsInt ValueAsInt;
1576 getSignAsIntValue(ValueAsInt, DL, Value);
1577 EVT IntVT = ValueAsInt.IntValue.getValueType();
1578 SDValue ClearSignMask = DAG.getConstant(~ValueAsInt.SignMask, DL, IntVT);
1581 return modifySignAsInt(ValueAsInt, DL, ClearedSign);
1584 void SelectionDAGLegalize::ExpandDYNAMIC_STACKALLOC(
SDNode* Node,
1586 unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore();
1587 assert(SPReg &&
"Target cannot require DYNAMIC_STACKALLOC expansion and" 1588 " not tell us which reg is the stack pointer!");
1598 Chain = DAG.getCALLSEQ_START(Chain, 0, 0, dl);
1601 SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
1603 unsigned Align = cast<ConstantSDNode>(Tmp3)->getZExtValue();
1604 unsigned StackAlign =
1605 DAG.getSubtarget().getFrameLowering()->getStackAlignment();
1607 if (Align > StackAlign)
1609 DAG.getConstant(-(uint64_t)Align, dl, VT));
1610 Chain = DAG.getCopyToReg(Chain, dl, SPReg, Tmp1);
1612 Tmp2 = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, dl,
true),
1613 DAG.getIntPtrConstant(0, dl,
true),
SDValue(), dl);
1637 bool SelectionDAGLegalize::LegalizeSetCCCondCode(
1643 switch (TLI.getCondCodeAction(CCCode, OpVT)) {
1650 if (TLI.isCondCodeLegalOrCustom(InvCC, OpVT)) {
1652 CC = DAG.getCondCode(InvCC);
1656 bool NeedSwap =
false;
1658 if (!TLI.isCondCodeLegalOrCustom(InvCC, OpVT)) {
1664 if (TLI.isCondCodeLegalOrCustom(InvCC, OpVT)) {
1665 CC = DAG.getCondCode(InvCC);
1678 &&
"If SETO is expanded, SETOEQ must be legal!");
1682 &&
"If SETUO is expanded, SETUNE must be legal!");
1722 SetCC1 = DAG.getSetCC(dl, VT, LHS, RHS, CC1, Chain, IsSignaling);
1723 SetCC2 = DAG.getSetCC(dl, VT, LHS, RHS, CC2, Chain, IsSignaling);
1726 SetCC1 = DAG.getSetCC(dl, VT, LHS, LHS, CC1, Chain, IsSignaling);
1727 SetCC2 = DAG.getSetCC(dl, VT, RHS, RHS, CC2, Chain, IsSignaling);
1732 LHS = DAG.
getNode(Opc, dl, VT, SetCC1, SetCC2);
1747 return EmitStackConvert(SrcOp, SlotVT, DestVT, dl, DAG.getEntryNode());
1754 unsigned SrcAlign = DAG.getDataLayout().getPrefTypeAlignment(
1756 SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign);
1767 unsigned DestAlign = DAG.getDataLayout().getPrefTypeAlignment(DestType);
1773 if (SrcSize > SlotSize)
1774 Store = DAG.getTruncStore(Chain, dl, SrcOp, FIPtr, PtrInfo,
1777 assert(SrcSize == SlotSize &&
"Invalid store");
1779 DAG.getStore(Chain, dl, SrcOp, FIPtr, PtrInfo, SrcAlign);
1783 if (SlotSize == DestSize)
1784 return DAG.getLoad(DestVT, dl, Store, FIPtr, PtrInfo, DestAlign);
1786 assert(SlotSize < DestSize &&
"Unknown extension!");
1787 return DAG.getExtLoad(
ISD::EXTLOAD, dl, DestVT, Store, FIPtr, PtrInfo, SlotVT,
1791 SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(
SDNode *Node) {
1800 SDValue Ch = DAG.getTruncStore(
1801 DAG.getEntryNode(), dl, Node->
getOperand(0), StackPtr,
1826 for (
unsigned i = 0; i < NumElems; ++i) {
1837 while (IntermedVals.
size() > 2) {
1838 NewIntermedVals.
clear();
1839 for (
unsigned i = 0,
e = (IntermedVals.
size() & ~1u); i <
e; i += 2) {
1846 IntermedVals[i+1].second.
size());
1849 for (
unsigned j = 0, f = IntermedVals[i].
second.size(); j != f;
1854 for (
unsigned j = 0, f = IntermedVals[i+1].
second.size(); j != f;
1856 ShuffleVec[k] = NumElems + j;
1863 IntermedVals[i+1].first,
1868 std::make_pair(Shuffle, std::move(FinalIndices)));
1873 if ((IntermedVals.
size() & 1) != 0)
1876 IntermedVals.
swap(NewIntermedVals);
1880 "Invalid number of intermediate vectors");
1881 SDValue Vec1 = IntermedVals[0].first;
1883 if (IntermedVals.
size() > 1)
1884 Vec2 = IntermedVals[1].
first;
1889 for (
unsigned i = 0,
e = IntermedVals[0].
second.size(); i !=
e; ++i)
1890 ShuffleVec[IntermedVals[0].
second[i]] = i;
1891 for (
unsigned i = 0,
e = IntermedVals[1].
second.size(); i !=
e; ++i)
1892 ShuffleVec[IntermedVals[1].
second[i]] = NumElems + i;
1905 SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(
SDNode *Node) {
1915 bool isOnlyLowElement =
true;
1916 bool MoreThanTwoValues =
false;
1918 for (
unsigned i = 0; i < NumElems; ++i) {
1923 isOnlyLowElement =
false;
1924 if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V))
1929 }
else if (!Value2.
getNode()) {
1932 }
else if (V != Value1 && V != Value2) {
1933 MoreThanTwoValues =
true;
1938 return DAG.getUNDEF(VT);
1940 if (isOnlyLowElement)
1946 for (
unsigned i = 0,
e = NumElems; i !=
e; ++i) {
1948 dyn_cast<ConstantFPSDNode>(Node->
getOperand(i))) {
1949 CV.
push_back(const_cast<ConstantFP *>(V->getConstantFPValue()));
1951 dyn_cast<ConstantSDNode>(Node->
getOperand(i))) {
1953 CV.
push_back(const_cast<ConstantInt *>(V->getConstantIntValue()));
1970 DAG.getConstantPool(CP, TLI.getPointerTy(DAG.getDataLayout()));
1971 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->
getAlignment();
1973 VT, dl, DAG.getEntryNode(), CPIdx,
1979 for (
unsigned i = 0; i < NumElems; ++i) {
1985 if (TLI.shouldExpandBuildVectorWithShuffles(VT, DefinedValues.
size())) {
1986 if (!MoreThanTwoValues) {
1988 for (
unsigned i = 0; i < NumElems; ++i) {
1992 ShuffleVec[i] = V == Value1 ? 0 : NumElems;
1994 if (TLI.isShuffleMaskLegal(ShuffleVec, Node->
getValueType(0))) {
2001 Vec2 = DAG.getUNDEF(VT);
2004 return DAG.getVectorShuffle(VT, dl, Vec1, Vec2, ShuffleVec);
2014 return ExpandVectorBuildThroughStack(Node);
2017 SDValue SelectionDAGLegalize::ExpandSPLAT_VECTOR(
SDNode *Node) {
2022 return DAG.getSplatBuildVector(VT, DL, SplatVal);
2032 TargetLowering::ArgListEntry
Entry;
2038 Entry.IsSExt = TLI.shouldSignExtendTypeInLibCall(ArgVT, isSigned);
2039 Entry.IsZExt = !TLI.shouldSignExtendTypeInLibCall(ArgVT, isSigned);
2040 Args.push_back(Entry);
2042 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2043 TLI.getPointerTy(DAG.getDataLayout()));
2052 SDValue InChain = DAG.getEntryNode();
2057 const Function &
F = DAG.getMachineFunction().getFunction();
2059 TLI.isInTailCallPosition(DAG, Node, TCChain) &&
2065 bool signExtend = TLI.shouldSignExtendTypeInLibCall(RetVT, isSigned);
2068 .
setLibCallee(TLI.getLibcallCallingConv(LC), RetTy, Callee,
2070 .setTailCall(isTailCall)
2075 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2077 if (!CallInfo.second.getNode()) {
2078 LLVM_DEBUG(
dbgs() <<
"Created tailcall: "; DAG.getRoot().dump(&DAG));
2080 return DAG.getRoot();
2083 LLVM_DEBUG(
dbgs() <<
"Created libcall: "; CallInfo.first.dump(&DAG));
2084 return CallInfo.first;
2087 void SelectionDAGLegalize::ExpandFPLibCall(
SDNode* Node,
2097 case MVT::f32: LC = Call_F32;
break;
2098 case MVT::f64: LC = Call_F64;
break;
2099 case MVT::f80: LC = Call_F80;
break;
2109 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, RetVT,
2116 SDValue Tmp = ExpandLibCall(LC, Node,
false);
2121 SDValue SelectionDAGLegalize::ExpandIntLibCall(
SDNode* Node,
bool isSigned,
2130 case MVT::i8: LC = Call_I8;
break;
2131 case MVT::i16: LC = Call_I16;
break;
2132 case MVT::i32: LC = Call_I32;
break;
2133 case MVT::i64: LC = Call_I64;
break;
2136 return ExpandLibCall(LC, Node, isSigned);
2141 void SelectionDAGLegalize::ExpandArgFPLibCall(
SDNode* Node,
2153 case MVT::f32: LC = Call_F32;
break;
2154 case MVT::f64: LC = Call_F64;
break;
2155 case MVT::f80: LC = Call_F80;
break;
2165 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, RetVT,
2172 SDValue Tmp = ExpandLibCall(LC, Node,
false);
2179 SelectionDAGLegalize::ExpandDivRemLibCall(
SDNode *Node,
2187 case MVT::i8: LC= isSigned ? RTLIB::SDIVREM_I8 : RTLIB::UDIVREM_I8;
break;
2188 case MVT::i16: LC= isSigned ? RTLIB::SDIVREM_I16 : RTLIB::UDIVREM_I16;
break;
2189 case MVT::i32: LC= isSigned ? RTLIB::SDIVREM_I32 : RTLIB::UDIVREM_I32;
break;
2190 case MVT::i64: LC= isSigned ? RTLIB::SDIVREM_I64 : RTLIB::UDIVREM_I64;
break;
2191 case MVT::i128: LC= isSigned ? RTLIB::SDIVREM_I128:RTLIB::UDIVREM_I128;
break;
2197 SDValue InChain = DAG.getEntryNode();
2203 TargetLowering::ArgListEntry
Entry;
2209 Entry.IsSExt = isSigned;
2210 Entry.IsZExt = !isSigned;
2211 Args.push_back(Entry);
2215 SDValue FIPtr = DAG.CreateStackTemporary(RetVT);
2218 Entry.IsSExt = isSigned;
2219 Entry.IsZExt = !isSigned;
2220 Args.push_back(Entry);
2222 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2223 TLI.getPointerTy(DAG.getDataLayout()));
2229 .
setLibCallee(TLI.getLibcallCallingConv(LC), RetTy, Callee,
2231 .setSExtResult(isSigned)
2234 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2248 case MVT::f32: LC = RTLIB::SINCOS_F32;
break;
2249 case MVT::f64: LC = RTLIB::SINCOS_F64;
break;
2250 case MVT::f80: LC = RTLIB::SINCOS_F80;
break;
2251 case MVT::f128: LC = RTLIB::SINCOS_F128;
break;
2277 SelectionDAGLegalize::ExpandSinCosLibCall(
SDNode *Node,
2282 case MVT::f32: LC = RTLIB::SINCOS_F32;
break;
2283 case MVT::f64: LC = RTLIB::SINCOS_F64;
break;
2284 case MVT::f80: LC = RTLIB::SINCOS_F80;
break;
2285 case MVT::f128: LC = RTLIB::SINCOS_F128;
break;
2292 SDValue InChain = DAG.getEntryNode();
2298 TargetLowering::ArgListEntry
Entry;
2303 Entry.IsSExt =
false;
2304 Entry.IsZExt =
false;
2305 Args.push_back(Entry);
2308 SDValue SinPtr = DAG.CreateStackTemporary(RetVT);
2309 Entry.Node = SinPtr;
2311 Entry.IsSExt =
false;
2312 Entry.IsZExt =
false;
2313 Args.push_back(Entry);
2316 SDValue CosPtr = DAG.CreateStackTemporary(RetVT);
2317 Entry.Node = CosPtr;
2319 Entry.IsSExt =
false;
2320 Entry.IsZExt =
false;
2321 Args.push_back(Entry);
2323 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2324 TLI.getPointerTy(DAG.getDataLayout()));
2329 TLI.getLibcallCallingConv(LC),
Type::getVoidTy(*DAG.getContext()), Callee,
2332 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2344 SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(
SDNode *Node,
2357 LLVM_DEBUG(
dbgs() <<
"32-bit [signed|unsigned] integer to float/double " 2364 SDValue WordOff = DAG.getConstant(
sizeof(
int), dl,
2369 StackSlot, WordOff);
2370 if (DAG.getDataLayout().isLittleEndian())
2383 SDValue Store1 = DAG.getStore(DAG.getEntryNode(), dl, Op0Mapped,
Lo,
2394 SDValue Bias = DAG.getConstantFP(isSigned ?
2406 std::pair<SDValue, SDValue> ResultPair;
2408 DAG.getStrictFPExtendOrRound(Sub, Chain, dl, DestVT);
2409 Result = ResultPair.first;
2410 Chain = ResultPair.second;
2416 Result = DAG.getFPExtendOrRound(Sub, dl, DestVT);
2420 assert(!isSigned &&
"Legalize cannot Expand SINT_TO_FP for i64 yet");
2432 SDValue SignSet = DAG.getSetCC(dl, getSetCCResultType(SrcVT), Op0,
2434 SDValue Zero = DAG.getIntPtrConstant(0, dl),
2435 Four = DAG.getIntPtrConstant(4, dl);
2437 SignSet, Four, Zero);
2445 case MVT::i8 : FF = 0x43800000ULL;
break;
2446 case MVT::i16: FF = 0x47800000ULL;
break;
2447 case MVT::i32: FF = 0x4F800000ULL;
break;
2448 case MVT::i64: FF = 0x5F800000ULL;
break;
2450 if (DAG.getDataLayout().isLittleEndian())
2456 DAG.getConstantPool(FudgeFactor, TLI.getPointerTy(DAG.getDataLayout()));
2457 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->
getAlignment();
2459 Alignment = std::min(Alignment, 4u);
2462 FudgeInReg = DAG.getLoad(
2463 MVT::f32, dl, DAG.getEntryNode(), CPIdx,
2478 { Tmp1.
getValue(1), Tmp1, FudgeInReg });
2491 void SelectionDAGLegalize::PromoteLegalINT_TO_FP(
2504 unsigned OpToUse = 0;
2512 if (TLI.isOperationLegalOrCustom(SIntOp, NewInTy)) {
2520 if (TLI.isOperationLegalOrCustom(UIntOp, NewInTy)) {
2535 dl, NewInTy, LegalOp)});
2542 DAG.getNode(OpToUse, dl, DestVT,
2544 dl, NewInTy, LegalOp)));
2552 void SelectionDAGLegalize::PromoteLegalFP_TO_INT(
SDNode *N,
const SDLoc &dl,
2560 EVT NewOutTy = DestVT;
2562 unsigned OpToUse = 0;
2572 if (TLI.isOperationLegalOrCustom(OpToUse, NewOutTy))
2577 if (!IsSigned && TLI.isOperationLegalOrCustom(OpToUse, NewOutTy))
2589 Operation = DAG.
getNode(OpToUse, dl, NewOutTy, LegalOp);
2602 EVT SHVT = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
2620 Tmp = (Sz > 8 ? DAG.getNode(
ISD::BSWAP, dl, VT, Op) :
Op);
2623 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskHi4, dl, VT));
2624 Tmp3 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskLo4, dl, VT));
2625 Tmp2 = DAG.
getNode(
ISD::SRL, dl, VT, Tmp2, DAG.getConstant(4, dl, SHVT));
2626 Tmp3 = DAG.
getNode(
ISD::SHL, dl, VT, Tmp3, DAG.getConstant(4, dl, SHVT));
2630 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskHi2, dl, VT));
2631 Tmp3 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskLo2, dl, VT));
2632 Tmp2 = DAG.
getNode(
ISD::SRL, dl, VT, Tmp2, DAG.getConstant(2, dl, SHVT));
2633 Tmp3 = DAG.
getNode(
ISD::SHL, dl, VT, Tmp3, DAG.getConstant(2, dl, SHVT));
2637 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskHi1, dl, VT));
2638 Tmp3 = DAG.
getNode(
ISD::AND, dl, VT, Tmp, DAG.getConstant(MaskLo1, dl, VT));
2639 Tmp2 = DAG.
getNode(
ISD::SRL, dl, VT, Tmp2, DAG.getConstant(1, dl, SHVT));
2640 Tmp3 = DAG.
getNode(
ISD::SHL, dl, VT, Tmp3, DAG.getConstant(1, dl, SHVT));
2645 Tmp = DAG.getConstant(0, dl, VT);
2646 for (
unsigned I = 0, J = Sz-1;
I < Sz; ++
I, --J) {
2656 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp2, DAG.getConstant(Shift, dl, VT));
2666 EVT SHVT = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
2667 SDValue Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8;
2672 return DAG.getNode(
ISD::ROTL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2674 Tmp4 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(24, dl, SHVT));
2675 Tmp3 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2676 Tmp2 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2677 Tmp1 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(24, dl, SHVT));
2679 DAG.getConstant(0xFF0000, dl, VT));
2680 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp2, DAG.getConstant(0xFF00, dl, VT));
2683 return DAG.getNode(
ISD::OR, dl, VT, Tmp4, Tmp2);
2685 Tmp8 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(56, dl, SHVT));
2686 Tmp7 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(40, dl, SHVT));
2687 Tmp6 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(24, dl, SHVT));
2688 Tmp5 = DAG.
getNode(
ISD::SHL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2689 Tmp4 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(8, dl, SHVT));
2690 Tmp3 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(24, dl, SHVT));
2691 Tmp2 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(40, dl, SHVT));
2692 Tmp1 = DAG.
getNode(
ISD::SRL, dl, VT, Op, DAG.getConstant(56, dl, SHVT));
2694 DAG.getConstant(255ULL<<48, dl, VT));
2696 DAG.getConstant(255ULL<<40, dl, VT));
2698 DAG.getConstant(255ULL<<32, dl, VT));
2700 DAG.getConstant(255ULL<<24, dl, VT));
2702 DAG.getConstant(255ULL<<16, dl, VT));
2704 DAG.getConstant(255ULL<<8 , dl, VT));
2711 return DAG.getNode(
ISD::OR, dl, VT, Tmp8, Tmp4);
2715 bool SelectionDAGLegalize::ExpandNode(
SDNode *Node) {
2719 SDValue Tmp1, Tmp2, Tmp3, Tmp4;
2723 if (TLI.expandABS(Node, Tmp1, DAG))
2727 if (TLI.expandCTPOP(Node, Tmp1, DAG))
2732 if (TLI.expandCTLZ(Node, Tmp1, DAG))
2737 if (TLI.expandCTTZ(Node, Tmp1, DAG))
2753 TLI.getPointerTy(DAG.getDataLayout()));
2761 DAG.getConstant(0, dl, TLI.getPointerTy(DAG.getDataLayout())));
2795 SDValue Swap = DAG.getAtomicCmpSwap(
2798 cast<AtomicSDNode>(Node)->getMemOperand());
2806 cast<AtomicSDNode>(Node)->getMemoryVT(),
2809 cast<AtomicSDNode>(Node)->getMemOperand());
2818 SDValue Res = DAG.getAtomicCmpSwap(
2821 Node->
getOperand(3), cast<MemSDNode>(Node)->getMemOperand());
2827 EVT AtomicType = cast<AtomicSDNode>(Node)->getMemoryVT();
2829 switch (TLI.getExtendForAtomicOps()) {
2840 RHS = DAG.getZeroExtendInReg(Node->
getOperand(2), dl, AtomicType);
2844 LHS = DAG.getZeroExtendInReg(Res, dl, AtomicType);
2845 RHS = DAG.getZeroExtendInReg(Node->
getOperand(2), dl, AtomicType);
2860 ExpandDYNAMIC_STACKALLOC(Node, Results);
2869 Results.
push_back(DAG.getConstant(0, dl, VT));
2872 Results.
push_back(DAG.getConstantFP(0, dl, VT));
2879 if (TLI.isStrictFPEnabled())
2883 if (TLI.getStrictFPOperationAction(Node->
getOpcode(),
2892 ReplaceNode(Node, Tmp1.
getNode());
2893 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_ROUND node\n");
2905 if (TLI.isStrictFPEnabled())
2909 if (TLI.getStrictFPOperationAction(Node->
getOpcode(),
2918 ReplaceNode(Node, Tmp1.
getNode());
2919 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_EXTEND node\n");
2939 SDValue One = DAG.getConstant(1, dl, VT);
2941 SDValue Zero = DAG.getConstant(0, dl, VT);
2949 EVT ShiftAmountTy = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
2952 SDValue ShiftCst = DAG.getConstant(BitsDiff, dl, ShiftAmountTy);
2961 if (TLI.expandUINT_TO_FP(Node, Tmp1, Tmp2, DAG)) {
2970 Tmp1 = ExpandLegalINT_TO_FP(Node, Tmp2);
2976 if (TLI.expandFP_TO_SINT(Node, Tmp1, DAG))
2980 if (TLI.expandFP_TO_SINT(Node, Tmp1, DAG)) {
2981 ReplaceNode(Node, Tmp1.
getNode());
2982 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_TO_SINT node\n");
2987 if (TLI.expandFP_TO_UINT(Node, Tmp1, Tmp2, DAG))
2991 if (TLI.expandFP_TO_UINT(Node, Tmp1, Tmp2, DAG)) {
2993 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node,1), Tmp2);
2995 ReplaceNodeWithValue(
SDValue(Node, 0), Tmp1);
2996 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_TO_UINT node\n");
3001 Results.
push_back(DAG.expandVAArg(Node));
3002 Results.
push_back(Results[0].getValue(1));
3005 Results.
push_back(DAG.expandVACopy(Node));
3013 Tmp1 = ExpandExtractFromVectorThroughStack(
SDValue(Node, 0));
3023 Results.
push_back(ExpandVectorBuildThroughStack(Node));
3026 Results.
push_back(ExpandSCALAR_TO_VECTOR(Node));
3035 ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(Node)->getMask();
3041 if (!TLI.isTypeLegal(EltVT)) {
3042 EVT NewEltVT = TLI.getTypeToTransformTo(*DAG.getContext(), EltVT);
3047 if (NewEltVT.
bitsLT(EltVT)) {
3063 unsigned int factor =
3071 for (
unsigned fi = 0; fi < factor; ++fi)
3075 for (
unsigned fi = 0; fi < factor; ++fi)
3086 for (
unsigned i = 0; i != NumElems; ++i) {
3091 unsigned Idx = Mask[i];
3095 DAG.getConstant(Idx, dl, TLI.getVectorIdxTy(DAG.getDataLayout()))));
3099 DAG.getConstant(Idx - NumElems, dl,
3100 TLI.getVectorIdxTy(DAG.getDataLayout()))));
3103 Tmp1 = DAG.getBuildVector(VT, dl, Ops);
3111 if (cast<ConstantSDNode>(Node->
getOperand(1))->getZExtValue()) {
3115 TLI.getShiftAmountTy(
3117 DAG.getDataLayout())));
3130 if (
unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) {
3133 Results.
push_back(Results[0].getValue(1));
3142 if (
unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) {
3151 Results.
push_back(Results[0].getValue(0));
3154 Results.
push_back(ExpandFCOPYSIGN(Node));
3158 Tmp1 = DAG.getConstantFP(-0.0, dl, Node->
getValueType(0));
3182 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp1, Tmp2, Pred);
3188 if (
SDValue Expanded = TLI.expandFMINNUM_FMAXNUM(Node, DAG))
3200 SDVTList VTs = DAG.getVTList(VT, VT);
3224 if (!TLI.useSoftFloat() &&
TM.Options.UnsafeFPMath) {
3232 DAG.getIntPtrConstant(0, dl));
3243 DAG.getMachineFunction().getFunction().hasOptSize()))
3244 Results.
push_back(ExpandConstantFP(CFP,
true));
3254 if (TLI.isOperationLegalOrCustom(
ISD::FADD, VT) &&
3255 TLI.isOperationLegalOrCustom(
ISD::FNEG, VT)) {
3266 TLI.isOperationLegalOrCustom(
ISD::XOR, VT) &&
3267 "Don't know how to expand this subtraction!");
3271 Tmp1 = DAG.getNode(
ISD::ADD, dl, VT, Tmp1, DAG.getConstant(1, dl, VT));
3283 if (TLI.isOperationLegalOrCustom(DivRemOpc, VT)) {
3284 SDVTList VTs = DAG.getVTList(VT, VT);
3285 Tmp1 = DAG.
getNode(DivRemOpc, dl, VTs, Tmp2, Tmp3).getValue(1);
3287 }
else if (TLI.isOperationLegalOrCustom(DivOpc, VT)) {
3289 Tmp1 = DAG.
getNode(DivOpc, dl, VT, Tmp2, Tmp3);
3301 if (TLI.isOperationLegalOrCustom(DivRemOpc, VT)) {
3302 SDVTList VTs = DAG.getVTList(VT, VT);
3311 unsigned ExpandOpcode =
3314 SDVTList VTs = DAG.getVTList(VT, VT);
3326 unsigned MULHOpcode =
3329 if (TLI.isOperationLegalOrCustom(MULHOpcode, VT)) {
3331 Results.
push_back(DAG.getNode(MULHOpcode, dl, VT, LHS, RHS));
3337 assert(TLI.isTypeLegal(HalfType));
3338 if (TLI.expandMUL_LOHI(Node->
getOpcode(), VT, Node, LHS, RHS, Halves,
3341 for (
unsigned i = 0; i < 2; ++i) {
3344 SDValue Shift = DAG.getConstant(
3345 HalfType.getScalarSizeInBits(), dl,
3346 TLI.getShiftAmountTy(HalfType, DAG.getDataLayout()));
3356 SDVTList VTs = DAG.getVTList(VT, VT);
3362 bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::SMUL_LOHI, VT);
3363 bool HasUMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::UMUL_LOHI, VT);
3364 bool HasMULHS = TLI.isOperationLegalOrCustom(
ISD::MULHS, VT);
3365 bool HasMULHU = TLI.isOperationLegalOrCustom(
ISD::MULHU, VT);
3366 unsigned OpToUse = 0;
3367 if (HasSMUL_LOHI && !HasMULHS) {
3369 }
else if (HasUMUL_LOHI && !HasMULHU) {
3371 }
else if (HasSMUL_LOHI) {
3373 }
else if (HasUMUL_LOHI) {
3386 TLI.isOperationLegalOrCustom(
ISD::SHL, VT) &&
3387 TLI.isOperationLegalOrCustom(
ISD::OR, VT) &&
3388 TLI.expandMUL(Node, Lo, Hi, HalfType, DAG,
3394 TLI.getShiftAmountTy(HalfType, DAG.getDataLayout()));
3402 if (TLI.expandFunnelShift(Node, Tmp1, DAG))
3407 if (TLI.expandROT(Node, Tmp1, DAG))
3414 Results.
push_back(TLI.expandAddSubSat(Node, DAG));
3420 Results.
push_back(TLI.expandFixedPointMul(Node, DAG));
3457 SDValue Overflow = DAG.getSetCC(dl, SetCCType, Sum, LHS, CC);
3461 DAG.getZeroExtendInReg(DAG.getZExtOrTrunc(Carry, dl, VT), dl,
MVT::i1);
3468 SDValue Zero = DAG.getConstant(0, dl, VT);
3470 IsAdd ? DAG.getSetCC(dl, SetCCType, Sum2, Zero,
ISD::SETEQ)
3471 : DAG.getSetCC(dl, SetCCType, Sum, Zero,
ISD::SETEQ);
3473 DAG.getZExtOrTrunc(Carry, dl, SetCCType));
3479 Results.
push_back(DAG.getBoolExtOrTrunc(ResultCarry, dl, CarryType, VT));
3485 TLI.expandSADDSUBO(Node, Result, Overflow, DAG);
3493 TLI.expandUADDSUBO(Node, Result, Overflow, DAG);
3501 if (TLI.expandMULO(Node, Result, Overflow, DAG)) {
3514 TLI.getShiftAmountTy(PairTy, DAG.getDataLayout())));
3525 cast<CondCodeSDNode>(Tmp1.
getOperand(2))->
get());
3527 Tmp1 = DAG.getSelectCC(dl, Tmp1,
3540 EVT PTy = TLI.getPointerTy(TD);
3542 unsigned EntrySize =
3543 DAG.getMachineFunction().getJumpTableInfo()->getEntrySize(TD);
3564 if (TLI.isJumpTableRelative()) {
3569 TLI.getPICJumpTableRelocBase(Table, DAG));
3572 Tmp1 = TLI.expandIndirectJTBranch(dl, LD.getValue(1), Addr, DAG);
3591 cast<ConstantSDNode>(Tmp2.
getOperand(1))->getZExtValue() == 1))
3609 unsigned Offset = IsStrict ? 1 : 0;
3614 LegalizeSetCCCondCode(Node->
getValueType(0), Tmp1, Tmp2, Tmp3,
3615 NeedInvert, dl, Chain, IsSignaling);
3622 Tmp1, Tmp2, Tmp3, Node->
getFlags());
3627 Tmp1 = DAG.getLogicalNOT(dl, Tmp1, Tmp1->
getValueType(0));
3638 assert(!IsStrict &&
"Don't know how to expand for strict nodes.");
3654 DAG.getConstant(TrueValue, dl, VT),
3655 DAG.getConstant(0, dl, VT),
3677 "Cannot expand ISD::SELECT_CC when ISD::SELECT also needs to be " 3679 EVT CCVT = getSetCCResultType(CmpVT);
3681 Results.
push_back(DAG.getSelect(dl, VT, Cond, Tmp3, Tmp4));
3686 bool Legalized =
false;
3694 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp4, Tmp3, InvCC);
3704 Tmp1 = DAG.getSelectCC(dl, Tmp2, Tmp1, Tmp4, Tmp3, SwapInvCC);
3710 Legalized = LegalizeSetCCCondCode(getSetCCResultType(Tmp1.
getValueType()),
3711 Tmp1, Tmp2, CC, NeedInvert, dl, Chain);
3713 assert(Legalized &&
"Can't legalize SELECT_CC with legal condition!");
3724 Tmp1, Tmp2, Tmp3, Tmp4, CC);
3729 Tmp2, Tmp3, Tmp4, CC);
3745 LegalizeSetCCCondCode(getSetCCResultType(Tmp2.
getValueType()), Tmp2,
3746 Tmp3, Tmp4, NeedInvert, dl, Chain);
3748 assert(Legalized &&
"Can't legalize BR_CC with legal condition!");
3750 assert(!NeedInvert &&
"Don't know how to invert BR_CC!");
3767 Results.
push_back(ExpandBUILD_VECTOR(Node));
3770 Results.
push_back(ExpandSPLAT_VECTOR(Node));
3782 for (
unsigned Idx = 0; Idx < NumElem; Idx++) {
3785 DAG.getConstant(Idx, dl, TLI.getVectorIdxTy(DAG.getDataLayout())));
3788 DAG.getConstant(Idx, dl, TLI.getVectorIdxTy(DAG.getDataLayout())));
3810 Results.
push_back(TLI.expandVecReduce(Node, DAG));
3835 if (TLI.getStrictFPOperationAction(Node->
getOpcode(),
3846 if (TLI.getStrictFPOperationAction(Node->
getOpcode(),
3855 if (Results.
empty()) {
3861 ReplaceNode(Node, Results.
data());
3865 void SelectionDAGLegalize::ConvertNodeToLibcall(
SDNode *Node) {
3882 DAG.getExternalSymbol(
"__sync_synchronize",
3883 TLI.getPointerTy(DAG.getDataLayout())),
3886 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
3909 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected atomic op or value type!");
3914 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, RetVT,
3929 DAG.getExternalSymbol(
3930 "abort", TLI.getPointerTy(DAG.getDataLayout())),
3932 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
3939 ExpandFPLibCall(Node, RTLIB::FMIN_F32, RTLIB::FMIN_F64,
3940 RTLIB::FMIN_F80, RTLIB::FMIN_F128,
3941 RTLIB::FMIN_PPCF128, Results);
3945 ExpandFPLibCall(Node, RTLIB::FMAX_F32, RTLIB::FMAX_F64,
3946 RTLIB::FMAX_F80, RTLIB::FMAX_F128,
3947 RTLIB::FMAX_PPCF128, Results);
3951 ExpandFPLibCall(Node, RTLIB::SQRT_F32, RTLIB::SQRT_F64,
3952 RTLIB::SQRT_F80, RTLIB::SQRT_F128,
3953 RTLIB::SQRT_PPCF128, Results);
3956 ExpandFPLibCall(Node, RTLIB::CBRT_F32, RTLIB::CBRT_F64,
3957 RTLIB::CBRT_F80, RTLIB::CBRT_F128,
3958 RTLIB::CBRT_PPCF128, Results);
3962 ExpandFPLibCall(Node, RTLIB::SIN_F32, RTLIB::SIN_F64,
3963 RTLIB::SIN_F80, RTLIB::SIN_F128,
3964 RTLIB::SIN_PPCF128, Results);
3968 ExpandFPLibCall(Node, RTLIB::COS_F32, RTLIB::COS_F64,
3969 RTLIB::COS_F80, RTLIB::COS_F128,
3970 RTLIB::COS_PPCF128, Results);
3974 ExpandSinCosLibCall(Node, Results);
3978 ExpandFPLibCall(Node, RTLIB::LOG_F32, RTLIB::LOG_F64, RTLIB::LOG_F80,
3979 RTLIB::LOG_F128, RTLIB::LOG_PPCF128, Results);
3983 ExpandFPLibCall(Node, RTLIB::LOG2_F32, RTLIB::LOG2_F64, RTLIB::LOG2_F80,
3984 RTLIB::LOG2_F128, RTLIB::LOG2_PPCF128, Results);
3988 ExpandFPLibCall(Node, RTLIB::LOG10_F32, RTLIB::LOG10_F64, RTLIB::LOG10_F80,
3989 RTLIB::LOG10_F128, RTLIB::LOG10_PPCF128, Results);
3993 ExpandFPLibCall(Node, RTLIB::EXP_F32, RTLIB::EXP_F64, RTLIB::EXP_F80,
3994 RTLIB::EXP_F128, RTLIB::EXP_PPCF128, Results);
3998 ExpandFPLibCall(Node, RTLIB::EXP2_F32, RTLIB::EXP2_F64, RTLIB::EXP2_F80,
3999 RTLIB::EXP2_F128, RTLIB::EXP2_PPCF128, Results);
4003 ExpandFPLibCall(Node, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64,
4004 RTLIB::TRUNC_F80, RTLIB::TRUNC_F128,
4005 RTLIB::TRUNC_PPCF128, Results);
4009 ExpandFPLibCall(Node, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64,
4010 RTLIB::FLOOR_F80, RTLIB::FLOOR_F128,
4011 RTLIB::FLOOR_PPCF128, Results);
4015 ExpandFPLibCall(Node, RTLIB::CEIL_F32, RTLIB::CEIL_F64,
4016 RTLIB::CEIL_F80, RTLIB::CEIL_F128,
4017 RTLIB::CEIL_PPCF128, Results);
4021 ExpandFPLibCall(Node, RTLIB::RINT_F32, RTLIB::RINT_F64,
4022 RTLIB::RINT_F80, RTLIB::RINT_F128,
4023 RTLIB::RINT_PPCF128, Results);
4027 ExpandFPLibCall(Node, RTLIB::NEARBYINT_F32,
4028 RTLIB::NEARBYINT_F64,
4029 RTLIB::NEARBYINT_F80,
4030 RTLIB::NEARBYINT_F128,
4031 RTLIB::NEARBYINT_PPCF128, Results);
4035 ExpandFPLibCall(Node, RTLIB::ROUND_F32,
4039 RTLIB::ROUND_PPCF128, Results);
4046 case MVT::f32: LC = RTLIB::POWI_F32;
break;
4047 case MVT::f64: LC = RTLIB::POWI_F64;
break;
4048 case MVT::f80: LC = RTLIB::POWI_F80;
break;
4049 case MVT::f128: LC = RTLIB::POWI_F128;
break;
4052 if (!TLI.getLibcallName(LC)) {
4062 ExpandFPLibCall(Node, RTLIB::POWI_F32, RTLIB::POWI_F64,
4063 RTLIB::POWI_F80, RTLIB::POWI_F128,
4064 RTLIB::POWI_PPCF128, Results);
4069 ExpandFPLibCall(Node, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80,
4070 RTLIB::POW_F128, RTLIB::POW_PPCF128, Results);
4074 ExpandArgFPLibCall(Node, RTLIB::LROUND_F32,
4075 RTLIB::LROUND_F64, RTLIB::LROUND_F80,
4077 RTLIB::LROUND_PPCF128, Results);
4081 ExpandArgFPLibCall(Node, RTLIB::LLROUND_F32,
4082 RTLIB::LLROUND_F64, RTLIB::LLROUND_F80,
4083 RTLIB::LLROUND_F128,
4084 RTLIB::LLROUND_PPCF128, Results);
4088 ExpandArgFPLibCall(Node, RTLIB::LRINT_F32,
4089 RTLIB::LRINT_F64, RTLIB::LRINT_F80,
4091 RTLIB::LRINT_PPCF128, Results);
4095 ExpandArgFPLibCall(Node, RTLIB::LLRINT_F32,
4096 RTLIB::LLRINT_F64, RTLIB::LLRINT_F80,
4098 RTLIB::LLRINT_PPCF128, Results);
4102 ExpandFPLibCall(Node, RTLIB::DIV_F32, RTLIB::DIV_F64,
4103 RTLIB::DIV_F80, RTLIB::DIV_F128,
4104 RTLIB::DIV_PPCF128, Results);
4108 ExpandFPLibCall(Node, RTLIB::REM_F32, RTLIB::REM_F64,
4109 RTLIB::REM_F80, RTLIB::REM_F128,
4110 RTLIB::REM_PPCF128, Results);
4114 ExpandFPLibCall(Node, RTLIB::FMA_F32, RTLIB::FMA_F64,
4115 RTLIB::FMA_F80, RTLIB::FMA_F128,
4116 RTLIB::FMA_PPCF128, Results);
4120 ExpandFPLibCall(Node, RTLIB::ADD_F32, RTLIB::ADD_F64,
4121 RTLIB::ADD_F80, RTLIB::ADD_F128,
4122 RTLIB::ADD_PPCF128, Results);
4126 ExpandFPLibCall(Node, RTLIB::MUL_F32, RTLIB::MUL_F64,
4127 RTLIB::MUL_F80, RTLIB::MUL_F128,
4128 RTLIB::MUL_PPCF128, Results);
4132 Results.
push_back(ExpandLibCall(RTLIB::FPEXT_F16_F32, Node,
false));
4138 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unable to expand fp_to_fp16");
4139 Results.
push_back(ExpandLibCall(LC, Node,
false));
4144 ExpandFPLibCall(Node, RTLIB::SUB_F32, RTLIB::SUB_F64,
4145 RTLIB::SUB_F80, RTLIB::SUB_F128,
4146 RTLIB::SUB_PPCF128, Results);
4149 Results.
push_back(ExpandIntLibCall(Node,
true,
4151 RTLIB::SREM_I16, RTLIB::SREM_I32,
4152 RTLIB::SREM_I64, RTLIB::SREM_I128));
4155 Results.
push_back(ExpandIntLibCall(Node,
false,
4157 RTLIB::UREM_I16, RTLIB::UREM_I32,
4158 RTLIB::UREM_I64, RTLIB::UREM_I128));
4161 Results.
push_back(ExpandIntLibCall(Node,
true,
4163 RTLIB::SDIV_I16, RTLIB::SDIV_I32,
4164 RTLIB::SDIV_I64, RTLIB::SDIV_I128));
4167 Results.
push_back(ExpandIntLibCall(Node,
false,
4169 RTLIB::UDIV_I16, RTLIB::UDIV_I32,
4170 RTLIB::UDIV_I64, RTLIB::UDIV_I128));
4175 ExpandDivRemLibCall(Node, Results);
4178 Results.
push_back(ExpandIntLibCall(Node,
false,
4180 RTLIB::MUL_I16, RTLIB::MUL_I32,
4181 RTLIB::MUL_I64, RTLIB::MUL_I128));
4188 Results.
push_back(ExpandLibCall(RTLIB::CTLZ_I32, Node,
false));
4191 Results.
push_back(ExpandLibCall(RTLIB::CTLZ_I64, Node,
false));
4194 Results.
push_back(ExpandLibCall(RTLIB::CTLZ_I128, Node,
false));
4201 if (!Results.
empty()) {
4202 LLVM_DEBUG(
dbgs() <<
"Successfully converted node to libcall\n");
4203 ReplaceNode(Node, Results.
data());
4211 MVT EltVT,
MVT NewEltVT) {
4218 void SelectionDAGLegalize::PromoteNode(
SDNode *Node) {
4234 MVT NVT = TLI.getTypeToPromoteTo(Node->
getOpcode(), OVT);
4252 DAG.getConstant(TopBit, dl, NVT));
4261 DAG.getConstant(NVT.getSizeInBits() -
4268 unsigned DiffBits = NVT.getSizeInBits() - OVT.
getSizeInBits();
4273 DAG.getConstant(DiffBits, dl,
4274 TLI.getShiftAmountTy(NVT, DAG.getDataLayout())));
4283 PromoteLegalFP_TO_INT(Node, dl, Results);
4289 PromoteLegalINT_TO_FP(Node, dl, Results);
4300 &&
"VAARG promotion is supported only for vectors or integer types");
4305 Tmp1 = DAG.getVAArg(NVT, dl, Chain, Ptr, Node->
getOperand(2),
4309 Tmp2 = DAG.
getNode(TruncOp, dl, OVT, Tmp1);
4313 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 0), Tmp2);
4314 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 1), Chain);
4316 UpdatedNodes->insert(Tmp2.
getNode());
4317 UpdatedNodes->insert(Chain.
getNode());
4330 unsigned ExtOp, TruncOp;
4357 Results.
push_back(DAG.getNode(TruncOp, dl, OVT, Tmp1));
4369 auto &DL = DAG.getDataLayout();
4373 DAG.getConstant(OriginalSize, dl, TLI.getScalarShiftAmountTy(DL, NVT)));
4379 unsigned ExtOp, TruncOp;
4396 Tmp1 = DAG.getSelect(dl, NVT, Tmp1, Tmp2, Tmp3);
4402 DAG.getIntPtrConstant(0, dl));
4407 ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(Node)->getMask();
4414 Tmp1 = ShuffleWithNarrowerEltType(NVT, OVT, dl, Tmp1, Tmp2, Mask);
4421 if (NVT.isInteger()) {
4423 cast<CondCodeSDNode>(Node->
getOperand(2))->
get();
4434 if (NVT.isInteger()) {
4436 cast<CondCodeSDNode>(Node->
getOperand(1))->
get();
4459 Tmp3, DAG.getIntPtrConstant(0, dl)));
4469 Tmp1 = DAG.getNode(Node->
getOpcode(), dl, {NVT, MVT::Other},
4470 {Tmp3, Tmp1, Tmp2});
4472 {Tmp1.getValue(1), Tmp1, DAG.getIntPtrConstant(0, dl)});
4482 DAG.getNode(Node->
getOpcode(), dl, NVT, Tmp1, Tmp2, Tmp3),
4483 DAG.getIntPtrConstant(0, dl)));
4498 Tmp3, DAG.getIntPtrConstant(isTrunc, dl)));
4518 Tmp2 = DAG.getNode(Node->
getOpcode(), dl, NVT, Tmp1);
4520 Tmp2, DAG.getIntPtrConstant(0, dl)));
4531 Tmp2 = DAG.getNode(Node->
getOpcode(), dl, {NVT, MVT::Other},
4532 {Tmp1.getValue(1), Tmp1});
4534 {Tmp2.getValue(1), Tmp2, DAG.getIntPtrConstant(0, dl)});
4549 "Invalid promote type for build_vector");
4582 "Invalid promote type for extract_vector_elt");
4586 unsigned NewEltsPerOldElt = MidVT.getVectorNumElements();
4591 SDValue Factor = DAG.getConstant(NewEltsPerOldElt, SL, IdxVT);
4597 for (
unsigned I = 0;
I < NewEltsPerOldElt; ++
I) {
4598 SDValue IdxOffset = DAG.getConstant(
I, SL, IdxVT);
4606 SDValue NewVec = DAG.getBuildVector(MidVT, SL, NewOps);
4628 "Invalid promote type for insert_vector_elt");
4632 unsigned NewEltsPerOldElt = MidVT.getVectorNumElements();
4639 SDValue Factor = DAG.getConstant(NewEltsPerOldElt,
SDLoc(), IdxVT);
4646 for (
unsigned I = 0;
I < NewEltsPerOldElt; ++
I) {
4647 SDValue IdxOffset = DAG.getConstant(
I, SL, IdxVT);
4651 CastVal, IdxOffset);
4654 NewVec, Elt, InEltIdx);
4693 "unexpected promotion type");
4695 "unexpected atomic_swap with illegal type");
4699 DAG.getVTList(NVT, MVT::Other),
4703 Results.
push_back(NewAtomic.getValue(1));
4709 if (!Results.
empty()) {
4711 ReplaceNode(Node, Results.
data());
4718 AssignTopologicalOrder();
4729 SelectionDAGLegalize
Legalizer(*
this, LegalizedNodes);
4736 bool AnyLegalized =
false;
4737 for (
auto NI = allnodes_end(); NI != allnodes_begin();) {
4741 if (N->
use_empty() && N != getRoot().getNode()) {
4747 if (LegalizedNodes.
insert(N).second) {
4748 AnyLegalized =
true;
4749 Legalizer.LegalizeOp(N);
4751 if (N->
use_empty() && N != getRoot().getNode()) {
4769 SelectionDAGLegalize
Legalizer(*
this, LegalizedNodes, &UpdatedNodes);
4773 LegalizedNodes.
insert(N);
4774 Legalizer.LegalizeOp(N);
4776 return LegalizedNodes.
count(N);
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 ...
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.
EVT getValueType() const
Return the ValueType of the referenced return value.
bool isInteger() const
Return true if this is an integer or a vector integer type.
void setFlags(SDNodeFlags NewFlags)
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.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
NodeType getExtForLoadExtType(bool IsFP, LoadExtType)
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an vector value) starting with the ...
CondCode getSetCCInverse(CondCode Operation, EVT Type)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
BR_CC - Conditional branch.
This class represents lattice values for constants.
static MVT getVectorVT(MVT VT, unsigned NumElements)
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
const SDValue & getVal() const
This structure is used to pass arguments to makeLibCall function.
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
bool isVector() const
Return true if this is a vector value type.
CallLoweringInfo & setIsPostTypeLegalization(bool Value=true)
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...
const SDValue & getBasePtr() const
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
void push_back(const T &Elt)
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
const SDValue & getValue() const
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain...
SDVTList getVTList() const
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit...
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
const SDValue & getBasePtr() const
unsigned getVectorNumElements() const
const SDValue & getChain() const
Function Alias Analysis Results
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
static MVT getPromotedVectorElementType(const TargetLowering &TLI, MVT EltVT, MVT NewEltVT)
unsigned getAlignment() const
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
C - The default llvm calling convention, compatible with C.
APInt trunc(unsigned width) const
Truncate to new width.
Constrained versions of the binary floating point operators.
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
bool isInteger() const
Return true if this is an integer or a vector integer type.
CallLoweringInfo & setDebugLoc(const SDLoc &dl)
static IntegerType * getInt64Ty(LLVMContext &C)
[US]{MIN/MAX} - Binary minimum or maximum or signed or unsigned integers.
const SDNodeFlags getFlags() const
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
void reserve(size_type N)
bool isByteSized() const
Return true if the bit size is a multiple of 8.
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
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) ...
std::pair< MCSymbol *, MachineModuleInfoImpl::StubValueTy > PairTy
Libcall getFPROUND(EVT OpVT, EVT RetVT)
getFPROUND - Return the FPROUND_*_* value for the given types, or UNKNOWN_LIBCALL if there is none...
const ConstantFP * getConstantFPValue() const
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
bool isTruncatingStore() const
Return true if the op does a truncation before store.
static bool hasPredecessorHelper(const SDNode *N, SmallPtrSetImpl< const SDNode *> &Visited, SmallVectorImpl< const SDNode *> &Worklist, unsigned int MaxSteps=0, bool TopologicalPrune=false)
Returns true if N is a predecessor of any node in Worklist.
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.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations...
static uint32_t getAlignment(const MCSectionCOFF &Sec)
Shift and rotation operations.
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth...
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
CallLoweringInfo & setChain(SDValue InChain)
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
RESULT = [US]MULFIX(LHS, RHS, SCALE) - Perform fixed point multiplication on 2 integers with the same...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
op_iterator op_end() const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
FLT_ROUNDS_ - Returns current rounding mode: -1 Undefined 0 Round to 0 1 Round to nearest 2 Round to ...
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.
EH_DWARF_CFA - This node represents the pointer to the DWARF Canonical Frame Address (CFA)...
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.
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
const DataLayout & getDataLayout() const
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG...
This is an SDNode representing atomic operations.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This file implements a class to represent arbitrary precision integral constant values and operations...
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
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...
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only...
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
bool insert(const value_type &X)
Insert a new element into the SetVector.
OUTCHAIN = EH_SJLJ_SETUP_DISPATCH(INCHAIN) The target initializes the dispatch table here...
falkor hwpf fix Falkor HW Prefetch Fix Late Phase
const TargetMachine & getTarget() const
Simple integer binary arithmetic operators.
STRICT_[US]INT_TO_FP - Convert a signed or unsigned integer to a floating point value.
bool bitsLT(MVT VT) const
Return true if this has less bits than VT.
CallLoweringInfo & setZExtResult(bool Value=true)
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...
op_iterator op_begin() const
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification, or lowering of the constant.
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
static bool useSinCos(SDNode *Node)
Only issue sincos libcall if both sin and cos are needed.
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...
MVT getVectorElementType() const
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...
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
bool isVoidTy() const
Return true if this is 'void'.
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
const SDValue & getBasePtr() const
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2, ArrayRef< int > Mask)
Return an ISD::VECTOR_SHUFFLE node.
Type * getReturnType() const
Returns the type of the ret val.
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
These reductions are non-strict, and have a single vector operand.
READ_REGISTER, WRITE_REGISTER - This node represents llvm.register on the DAG, which implements the n...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
void Legalize()
This transforms the SelectionDAG into a SelectionDAG that is compatible with the target instruction s...
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
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.
PowerPC Reduce CR logical Operation
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE...
iterator_range< value_op_iterator > op_values() const
const SDValue & getOperand(unsigned Num) 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...
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.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
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.
void ReplaceAllUsesWith(SDValue From, SDValue To)
Modify anything using 'From' to use 'To' instead.
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.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
CondCode getSetCCSwappedOperands(CondCode Operation)
Return the operation corresponding to (Y op X) when given the operation for (X op Y)...
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.
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.
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
This structure contains all information that is necessary for lowering calls.
This class contains a discriminated union of information about pointers in memory operands...
unsigned getNumOperands() const
Return the number of values used by this operation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
const APFloat & getValueAPF() const
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
bool use_empty() const
Return true if there are no uses of this node.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
TokenFactor - This node takes multiple tokens as input and produces a single token result...
void dump() const
Dump this node, for debugging.
const TargetLowering & getTargetLoweringInfo() const
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.
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
EVT getVectorElementType() const
Given a vector type, return the type of each element.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
BRCOND - Conditional branch.
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...
TypeSize getScalarSizeInBits() const
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
CallLoweringInfo & setSExtResult(bool Value=true)
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.
double BitsToDouble(uint64_t Bits)
This function takes a 64-bit integer and returns the bit equivalent double.
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachinePointerInfo getWithOffset(int64_t O) const
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static 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...
EVT getMemoryVT() const
Return the type of the in-memory value.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
Class for arbitrary precision integers.
amdgpu Simplify well known AMD library false FunctionCallee Callee
Select(COND, TRUEVAL, FALSEVAL).
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
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.
Flags
Flags values. These may be or'd together.
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.
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.
bool isVector() const
Return true if this is a vector value type.
const SDValue & getValue() const
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...
LLVM_NODISCARD bool empty() const
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...
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const
Return the ValueType of the result of SETCC operations.
const ConstantInt * getConstantIntValue() const
Flags getFlags() const
Return the raw flags of the source value,.
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision ...
unsigned getOpcode() const
FSINCOS - Compute both fsin and fcos as a single operation.
SDValue getValue(unsigned R) const
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.
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...
OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 'eh_return' gcc dwarf builtin...
const MachinePointerInfo & getPointerInfo() const
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
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.
TypeSize getScalarSizeInBits() const
LLVM Value Representation.
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
FMA - Perform a * b + c with no intermediate rounding step.
Integer reductions may have a result type larger than the vector element type.
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
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...
#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.
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.getNode() alone...
Primary interface to the complete machine description for the target machine.
const APFloat & getValueAPF() const
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.
APInt bitcastToAPInt() const
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
virtual bool isShuffleMaskLegal(ArrayRef< int >, EVT) const
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations, those with specific masks.
bool isStrictFPOpcode()
Test if this node is a strict floating point pseudo-op.
const SDValue & getOperand(unsigned i) const
OUTCHAIN = ATOMIC_STORE(INCHAIN, ptr, val) This corresponds to "store atomic" instruction.
TRUNCATE - Completely drop the high bits.
bool hasPredecessor(const SDNode *N) const
Return true if N is a predecessor of this node.
TypeSize getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
RESULT = [US]DIVFIX(LHS, RHS, SCALE) - Perform fixed point division on 2 integers with the same width...
Perform various unary floating-point operations inspired by libm.
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.
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
LLVMContext * getContext() const
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
static Constant * get(ArrayRef< Constant *> V)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
CallLoweringInfo & setLibCallee(CallingConv::ID CC, Type *ResultType, SDValue Target, ArgListTy &&ArgsList)
Carry-using nodes for multiple precision addition and subtraction.
EVT getHalfSizedIntegerVT(LLVMContext &Context) const
Finds the smallest simple value type that is greater than or equal to half the width of this EVT...
This file describes how to lower LLVM code to machine code.
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
This class is used to represent ISD::LOAD nodes.
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary...