61 EVT getSetCCResultType(
EVT VT)
const {
62 return TLI.getSetCCResultType(*DAG.getContext(), VT);
74 void LegalizeOp(
SDNode *Node);
78 void LegalizeLoadOps(
SDNode *Node);
79 void LegalizeStoreOps(
SDNode *Node);
99 bool &NeedInvert,
SDLoc dl);
103 unsigned NumOps,
bool isSigned,
SDLoc dl);
106 SDNode *Node,
bool isSigned);
123 void ExpandDYNAMIC_STACKALLOC(
SDNode *Node,
142 std::pair<SDValue, SDValue> ExpandAtomic(
SDNode *Node);
144 void ExpandNode(
SDNode *Node);
145 void PromoteNode(
SDNode *Node);
148 LegalizedNodes.erase(N);
158 virtual void NodeUpdated(
SDNode *N) {}
161 void ReplacedNode(
SDNode *N) {
163 DAG.RemoveDeadNode(N);
169 DAG.ReplaceAllUsesWith(Old, New);
173 DAG.ReplaceAllUsesWith(Old, New);
177 DAG.ReplaceAllUsesWith(Old, New);
188 SelectionDAGLegalize::ShuffleWithNarrowerEltType(
EVT NVT,
EVT VT,
SDLoc dl,
193 unsigned NumEltsGrowth = NumDestElts / NumMaskElts;
195 assert(NumEltsGrowth &&
"Cannot promote to vector type with fewer elts!");
197 if (NumEltsGrowth == 1)
198 return DAG.getVectorShuffle(NVT, dl, N1, N2, &Mask[0]);
201 for (
unsigned i = 0; i != NumMaskElts; ++i) {
203 for (
unsigned j = 0; j != NumEltsGrowth; ++j) {
207 NewMask.
push_back(Idx * NumEltsGrowth + j);
210 assert(NewMask.
size() == NumDestElts &&
"Non-integer NumEltsGrowth?");
211 assert(TLI.isShuffleMaskLegal(NewMask, NVT) &&
"Shuffle not legal?");
212 return DAG.getVectorShuffle(NVT, dl, N1, N2, &NewMask[0]);
215 SelectionDAGLegalize::SelectionDAGLegalize(
SelectionDAG &dag)
217 TM(dag.getTarget()), TLI(dag.getTargetLoweringInfo()),
221 void SelectionDAGLegalize::LegalizeDAG() {
222 DAG.AssignTopologicalOrder();
229 bool AnyLegalized =
false;
230 for (LegalizePosition = DAG.allnodes_end();
231 LegalizePosition != DAG.allnodes_begin(); ) {
234 SDNode *N = LegalizePosition;
235 if (LegalizedNodes.insert(N)) {
246 DAG.RemoveDeadNodes();
278 TLI.ShouldShrinkFPConstant(OrigVT)) {
286 SDValue CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy());
287 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
293 VT,
false,
false, Alignment);
297 DAG.getLoad(OrigVT, dl, DAG.getEntryNode(), CPIdx,
306 SelectionDAGLegalize *DAGLegalize) {
308 "unaligned indexed stores not implemented!");
327 DAGLegalize->ReplaceNode(
SDValue(ST, 0), Result);
339 unsigned NumRegs = (StoredBytes + RegBytes - 1) / RegBytes;
347 StoredVT,
false,
false, 0);
353 for (
unsigned i = 1; i < NumRegs; i++) {
357 false,
false,
false, 0);
374 8 * (StoredBytes - Offset));
379 MemVT,
false,
false, 0);
392 DAGLegalize->ReplaceNode(
SDValue(ST, 0), Result);
397 "Unaligned store of unknown type.");
401 int IncrementSize = NumBits / 8;
417 Alignment =
MinAlign(Alignment, IncrementSize);
425 DAGLegalize->ReplaceNode(
SDValue(ST, 0), Result);
434 "unaligned indexed loads not implemented!");
462 unsigned NumRegs = (LoadedBytes + RegBytes - 1) / RegBytes;
473 for (
unsigned i = 1; i < NumRegs; i++) {
487 StackPtr = DAG.
getNode(
ISD::ADD, dl, StackPtr.getValueType(), StackPtr,
493 8 * (LoadedBytes - Offset));
521 "Unaligned load of unsupported type.");
531 unsigned IncrementSize = NumBits / 8;
546 Hi = DAG.
getExtLoad(HiExtType, dl, VT, Chain, Ptr,
597 EVT PtrVT = TLI.getPointerTy();
598 SDValue StackPtr = DAG.CreateStackTemporary(VT);
600 int SPFI = cast<FrameIndexSDNode>(StackPtr.
getNode())->getIndex();
603 SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Tmp1, StackPtr,
609 Tmp3 = DAG.
getNode(CastOpc, dl, PtrVT, Tmp3);
612 Tmp3 = DAG.
getNode(
ISD::MUL, dl, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT));
618 return DAG.getLoad(VT, dl, Ch, StackPtr,
641 for (
unsigned i = 0; i != NumElts; ++i)
642 ShufOps.
push_back(i != InsertPos->getZExtValue() ? i : NumElts);
644 return DAG.getVectorShuffle(Vec.
getValueType(), dl, Vec, ScVec,
648 return PerformInsertVectorEltInMemory(Vec, Val, Idx, dl);
670 bitcastToAPInt().zextOrTrunc(32),
673 isVolatile, isNonTemporal, Alignment, TBAAInfo);
682 isVolatile, isNonTemporal, Alignment, TBAAInfo);
692 if (TLI.isBigEndian())
std::swap(Lo, Hi);
694 Lo = DAG.getStore(Chain, dl, Lo, Ptr, ST->
getPointerInfo(), isVolatile,
695 isNonTemporal, Alignment, TBAAInfo);
698 Hi = DAG.getStore(Chain, dl, Hi, Ptr,
700 isVolatile, isNonTemporal,
MinAlign(Alignment, 4U),
710 void SelectionDAGLegalize::LegalizeStoreOps(
SDNode *Node) {
722 if (
SDNode *OptStore = OptimizeFloatStore(ST).getNode()) {
723 ReplaceNode(ST, OptStore);
730 switch (TLI.getOperationAction(
ISD::STORE, VT)) {
735 if (!TLI.allowsUnalignedMemoryAccesses(ST->
getMemoryVT())) {
737 unsigned ABIAlignment= TLI.getDataLayout()->getABITypeAlignment(Ty);
746 ReplaceNode(
SDValue(Node, 0), Res);
752 "Can only promote stores to same size type");
755 DAG.getStore(Chain, dl, Value, Ptr,
757 isNonTemporal, Alignment, TBAAInfo);
758 ReplaceNode(
SDValue(Node, 0), Result);
776 Value = DAG.getZeroExtendInReg(Value, dl, StVT);
779 NVT, isVolatile, isNonTemporal, Alignment,
781 ReplaceNode(
SDValue(Node, 0), Result);
782 }
else if (StWidth & (StWidth - 1)) {
784 assert(!StVT.
isVector() &&
"Unsupported truncstore!");
785 unsigned RoundWidth = 1 <<
Log2_32(StWidth);
786 assert(RoundWidth < StWidth);
787 unsigned ExtraWidth = StWidth - RoundWidth;
788 assert(ExtraWidth < RoundWidth);
789 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
790 "Store size not an integral number of bytes!");
794 unsigned IncrementSize;
796 if (TLI.isLittleEndian()) {
799 Lo = DAG.getTruncStore(Chain, dl, Value, Ptr, ST->
getPointerInfo(),
801 isVolatile, isNonTemporal, Alignment,
805 IncrementSize = RoundWidth / 8;
808 Hi = DAG.getNode(
ISD::SRL, dl, Value.getValueType(), Value,
809 DAG.getConstant(RoundWidth,
810 TLI.getShiftAmountTy(Value.getValueType())));
811 Hi = DAG.getTruncStore(Chain, dl, Hi, Ptr,
813 ExtraVT, isVolatile, isNonTemporal,
814 MinAlign(Alignment, IncrementSize), TBAAInfo);
819 Hi = DAG.getNode(
ISD::SRL, dl, Value.getValueType(), Value,
820 DAG.getConstant(ExtraWidth,
821 TLI.getShiftAmountTy(Value.getValueType())));
823 RoundVT, isVolatile, isNonTemporal, Alignment,
827 IncrementSize = RoundWidth / 8;
830 Lo = DAG.getTruncStore(Chain, dl, Value, Ptr,
832 ExtraVT, isVolatile, isNonTemporal,
833 MinAlign(Alignment, IncrementSize), TBAAInfo);
838 ReplaceNode(
SDValue(Node, 0), Result);
846 if (!TLI.allowsUnalignedMemoryAccesses(ST->
getMemoryVT())) {
848 unsigned ABIAlignment= TLI.getDataLayout()->getABITypeAlignment(Ty);
856 ReplaceNode(
SDValue(Node, 0), Res);
861 "Vector Stores are handled in LegalizeVectorOps");
864 assert(TLI.isTypeLegal(StVT) &&
865 "Do not know how to expand this store!");
869 isVolatile, isNonTemporal, Alignment, TBAAInfo);
870 ReplaceNode(
SDValue(Node, 0), Result);
877 void SelectionDAGLegalize::LegalizeLoadOps(
SDNode *Node) {
890 switch (TLI.getOperationAction(Node->
getOpcode(), VT)) {
895 if (!TLI.allowsUnalignedMemoryAccesses(LD->
getMemoryVT())) {
897 unsigned ABIAlignment =
898 TLI.getDataLayout()->getABITypeAlignment(Ty);
905 SDValue Res = TLI.LowerOperation(RVal, DAG);
913 MVT NVT = TLI.getTypeToPromoteTo(Node->
getOpcode(), VT);
915 "Can only promote loads to same size type");
923 if (RChain.
getNode() != Node) {
924 assert(RVal.
getNode() != Node &&
"Load must be completely replaced");
925 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 0), RVal);
926 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 1), RChain);
964 NVT, isVolatile, isNonTemporal, Alignment, TBAAInfo);
981 }
else if (SrcWidth & (SrcWidth - 1)) {
983 assert(!SrcVT.
isVector() &&
"Unsupported extload!");
984 unsigned RoundWidth = 1 <<
Log2_32(SrcWidth);
985 assert(RoundWidth < SrcWidth);
986 unsigned ExtraWidth = SrcWidth - RoundWidth;
987 assert(ExtraWidth < RoundWidth);
988 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
989 "Load size not an integral number of bytes!");
993 unsigned IncrementSize;
995 if (TLI.isLittleEndian()) {
1001 isNonTemporal, Alignment, TBAAInfo);
1004 IncrementSize = RoundWidth / 8;
1005 Ptr = DAG.getNode(
ISD::ADD, dl, Ptr.getValueType(), Ptr,
1006 DAG.getConstant(IncrementSize, Ptr.getValueType()));
1007 Hi = DAG.getExtLoad(ExtType, dl, Node->
getValueType(0), Chain, Ptr,
1009 ExtraVT, isVolatile, isNonTemporal,
1010 MinAlign(Alignment, IncrementSize), TBAAInfo);
1018 Hi = DAG.getNode(
ISD::SHL, dl, Hi.getValueType(),
Hi,
1019 DAG.getConstant(RoundWidth,
1020 TLI.getShiftAmountTy(Hi.getValueType())));
1028 Hi = DAG.getExtLoad(ExtType, dl, Node->
getValueType(0), Chain, Ptr,
1030 isNonTemporal, Alignment, TBAAInfo);
1033 IncrementSize = RoundWidth / 8;
1034 Ptr = DAG.getNode(
ISD::ADD, dl, Ptr.getValueType(), Ptr,
1035 DAG.getConstant(IncrementSize, Ptr.getValueType()));
1039 ExtraVT, isVolatile, isNonTemporal,
1040 MinAlign(Alignment, IncrementSize), TBAAInfo);
1048 Hi = DAG.getNode(
ISD::SHL, dl, Hi.getValueType(),
Hi,
1049 DAG.getConstant(ExtraWidth,
1050 TLI.getShiftAmountTy(Hi.getValueType())));
1058 bool isCustom =
false;
1059 switch (TLI.getLoadExtAction(ExtType, SrcVT.
getSimpleVT())) {
1077 if (!TLI.allowsUnalignedMemoryAccesses(LD->
getMemoryVT())) {
1080 unsigned ABIAlignment =
1081 TLI.getDataLayout()->getABITypeAlignment(Ty);
1084 DAG, TLI, Value, Chain);
1091 if (!TLI.isLoadExtLegal(
ISD::EXTLOAD, SrcVT) && TLI.isTypeLegal(SrcVT)) {
1110 "Vector Loads are handled in LegalizeVectorOps");
1117 "EXTLOAD should always be supported!");
1129 ValRes = DAG.getZeroExtendInReg(Result, dl, SrcVT.getScalarType());
1138 if (Chain.getNode() != Node) {
1139 assert(Value.
getNode() != Node &&
"Load must be completely replaced");
1140 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 0), Value);
1141 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 1), Chain);
1148 void SelectionDAGLegalize::LegalizeOp(
SDNode *Node) {
1152 for (
unsigned i = 0, e = Node->
getNumValues(); i != e; ++i)
1153 assert(TLI.getTypeAction(*DAG.getContext(), Node->
getValueType(i)) ==
1155 "Unexpected illegal type!");
1158 assert((TLI.getTypeAction(*DAG.getContext(),
1162 "Unexpected illegal type!");
1166 bool SimpleFinishLegalizing =
true;
1175 Action = TLI.getOperationAction(Node->
getOpcode(),
1183 Action = TLI.getOperationAction(Node->
getOpcode(),
1188 EVT InnerType = cast<VTSDNode>(Node->
getOperand(1))->getVT();
1189 Action = TLI.getOperationAction(Node->
getOpcode(), InnerType);
1193 Action = TLI.getOperationAction(Node->
getOpcode(),
1205 cast<CondCodeSDNode>(Node->
getOperand(CCOperand))->
get();
1206 Action = TLI.getCondCodeAction(CCCode, OpVT);
1209 Action = TLI.getOperationAction(Node->
getOpcode(),
1212 Action = TLI.getOperationAction(Node->
getOpcode(), OpVT);
1220 SimpleFinishLegalizing =
false;
1227 SimpleFinishLegalizing =
false;
1266 ReplaceNode(Node, NewVal.
getNode());
1281 if (SimpleFinishLegalizing) {
1298 NewNode = DAG.UpdateNodeOperands(Node, Node->
getOperand(0),
1313 NewNode = DAG.UpdateNodeOperands(Node, Node->
getOperand(0),
1320 if (NewNode != Node) {
1321 DAG.ReplaceAllUsesWith(Node, NewNode);
1322 for (
unsigned i = 0, e = Node->
getNumValues(); i != e; ++i)
1336 for (
unsigned i = 0, e = Node->
getNumValues(); i != e; ++i) {
1343 DAG.ReplaceAllUsesWith(Node, ResultVals.
data());
1344 for (
unsigned i = 0, e = Node->
getNumValues(); i != e; ++i)
1345 DAG.TransferDbgValues(
SDValue(Node, i), ResultVals[i]);
1374 return LegalizeLoadOps(Node);
1377 return LegalizeStoreOps(Node);
1382 SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(
SDValue Op) {
1388 SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr,
1393 Vec.getValueType().getVectorElementType().getSizeInBits()/8;
1397 Idx = DAG.getZExtOrTrunc(Idx, dl, TLI.getPointerTy());
1402 false,
false,
false, 0);
1405 Vec.getValueType().getVectorElementType(),
1409 SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(
SDValue Op) {
1419 SDValue StackPtr = DAG.CreateStackTemporary(Vec.getValueType());
1420 int FI = cast<FrameIndexSDNode>(StackPtr.
getNode())->getIndex();
1424 SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, PtrInfo,
1431 Vec.getValueType().getVectorElementType().getSizeInBits()/8;
1435 Idx = DAG.getZExtOrTrunc(Idx, dl, TLI.getPointerTy());
1441 Ch = DAG.getStore(DAG.getEntryNode(), dl, Part, SubStackPtr,
1445 return DAG.getLoad(Op.
getValueType(), dl, Ch, StackPtr, PtrInfo,
1446 false,
false,
false, 0);
1449 SDValue SelectionDAGLegalize::ExpandVectorBuildThroughStack(
SDNode* Node) {
1457 SDValue FIPtr = DAG.CreateStackTemporary(VT);
1458 int FI = cast<FrameIndexSDNode>(FIPtr.
getNode())->getIndex();
1469 unsigned Offset = TypeByteSize*i;
1477 Stores.
push_back(DAG.getTruncStore(DAG.getEntryNode(), dl,
1480 EltVT,
false,
false, 0));
1482 Stores.
push_back(DAG.getStore(DAG.getEntryNode(), dl,
1489 if (!Stores.
empty())
1491 &Stores[0], Stores.
size());
1493 StoreChain = DAG.getEntryNode();
1496 return DAG.getLoad(VT, dl, StoreChain, FIPtr, PtrInfo,
1497 false,
false,
false, 0);
1500 SDValue SelectionDAGLegalize::ExpandFCOPYSIGN(
SDNode* Node) {
1510 if (TLI.isTypeLegal(IVT)) {
1515 MVT LoadTy = TLI.getPointerTy();
1517 SDValue StackPtr = DAG.CreateStackTemporary(FloatVT, LoadTy);
1522 if (TLI.isBigEndian()) {
1523 assert(FloatVT.
isByteSized() &&
"Unsupported floating point type!");
1526 false,
false,
false, 0);
1532 unsigned ByteOffset = (Strides * LoadTy.
getSizeInBits()) / 8;
1538 false,
false,
false, 0);
1542 assert(BitShift < LoadTy.
getSizeInBits() &&
"Pointer advanced wrong?");
1544 SignBit = DAG.getNode(
ISD::SHL, dl, LoadTy, SignBit,
1545 DAG.getConstant(BitShift,
1546 TLI.getShiftAmountTy(SignBit.getValueType())));
1550 SignBit = DAG.getSetCC(dl, getSetCCResultType(SignBit.getValueType()),
1551 SignBit, DAG.getConstant(0, SignBit.getValueType()),
1557 return DAG.getSelect(dl, AbsVal.
getValueType(), SignBit,
1562 void SelectionDAGLegalize::ExpandDYNAMIC_STACKALLOC(
SDNode* Node,
1564 unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore();
1565 assert(SPReg &&
"Target cannot require DYNAMIC_STACKALLOC expansion and"
1566 " not tell us which reg is the stack pointer!");
1576 Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(0,
true),
1580 SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
1582 unsigned Align = cast<ConstantSDNode>(Tmp3)->getZExtValue();
1583 unsigned StackAlign =
TM.getFrameLowering()->getStackAlignment();
1585 if (Align > StackAlign)
1587 DAG.getConstant(-(uint64_t)Align, VT));
1588 Chain = DAG.getCopyToReg(Chain, dl, SPReg, Tmp1);
1590 Tmp2 = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0,
true),
1591 DAG.getIntPtrConstant(0,
true),
SDValue(),
1616 bool SelectionDAGLegalize::LegalizeSetCCCondCode(
EVT VT,
1624 switch (TLI.getCondCodeAction(CCCode, OpVT)) {
1631 if (TLI.isCondCodeLegal(InvCC, OpVT)) {
1633 CC = DAG.getCondCode(InvCC);
1643 &&
"If SETO is expanded, SETOEQ must be legal!");
1648 &&
"If SETUO is expanded, SETUNE must be legal!");
1683 if (TLI.isCondCodeLegal(InvCC, OpVT)) {
1684 CC = DAG.getCondCode(InvCC);
1697 SetCC1 = DAG.getSetCC(dl, VT, LHS, RHS, CC1);
1698 SetCC2 = DAG.getSetCC(dl, VT, LHS, RHS, CC2);
1701 SetCC1 = DAG.getSetCC(dl, VT, LHS, LHS, CC1);
1702 SetCC2 = DAG.getSetCC(dl, VT, RHS, RHS, CC2);
1704 LHS = DAG.
getNode(Opc, dl, VT, SetCC1, SetCC2);
1723 TLI.getDataLayout()->getPrefTypeAlignment(SrcOp.
getValueType().
1724 getTypeForEVT(*DAG.getContext()));
1725 SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign);
1735 unsigned DestAlign = TLI.getDataLayout()->getPrefTypeAlignment(DestType);
1741 if (SrcSize > SlotSize)
1742 Store = DAG.getTruncStore(DAG.getEntryNode(), dl, SrcOp, FIPtr,
1743 PtrInfo, SlotVT,
false,
false, SrcAlign);
1745 assert(SrcSize == SlotSize &&
"Invalid store");
1746 Store = DAG.getStore(DAG.getEntryNode(), dl, SrcOp, FIPtr,
1747 PtrInfo,
false,
false, SrcAlign);
1751 if (SlotSize == DestSize)
1752 return DAG.getLoad(DestVT, dl, Store, FIPtr, PtrInfo,
1753 false,
false,
false, DestAlign);
1755 assert(SlotSize < DestSize &&
"Unknown extension!");
1756 return DAG.getExtLoad(
ISD::EXTLOAD, dl, DestVT, Store, FIPtr,
1757 PtrInfo, SlotVT,
false,
false, DestAlign);
1760 SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(
SDNode *Node) {
1774 return DAG.getLoad(Node->
getValueType(0), dl, Ch, StackPtr,
1776 false,
false,
false, 0);
1782 SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(
SDNode *Node) {
1792 bool isOnlyLowElement =
true;
1793 bool MoreThanTwoValues =
false;
1794 bool isConstant =
true;
1795 for (
unsigned i = 0; i < NumElems; ++i) {
1800 isOnlyLowElement =
false;
1801 if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V))
1806 }
else if (!Value2.
getNode()) {
1809 }
else if (V != Value1 && V != Value2) {
1810 MoreThanTwoValues =
true;
1815 return DAG.getUNDEF(VT);
1817 if (isOnlyLowElement)
1823 for (
unsigned i = 0, e = NumElems; i != e; ++i) {
1825 dyn_cast<ConstantFPSDNode>(Node->
getOperand(i))) {
1826 CV.
push_back(const_cast<ConstantFP *>(V->getConstantFPValue()));
1828 dyn_cast<ConstantSDNode>(Node->
getOperand(i))) {
1830 CV.
push_back(const_cast<ConstantInt *>(V->getConstantIntValue()));
1846 SDValue CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy());
1847 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
1848 return DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
1850 false,
false,
false, Alignment);
1853 if (!MoreThanTwoValues) {
1855 for (
unsigned i = 0; i < NumElems; ++i) {
1859 ShuffleVec[i] = V == Value1 ? 0 : NumElems;
1861 if (TLI.isShuffleMaskLegal(ShuffleVec, Node->
getValueType(0))) {
1868 Vec2 = DAG.getUNDEF(VT);
1871 return DAG.getVectorShuffle(VT, dl, Vec1, Vec2, ShuffleVec.data());
1876 return ExpandVectorBuildThroughStack(Node);
1892 Entry.
isZExt = !isSigned;
1893 Args.push_back(Entry);
1895 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
1896 TLI.getPointerTy());
1904 SDValue InChain = DAG.getEntryNode();
1909 bool isTailCall = TLI.isInTailCallPosition(DAG, Node, TCChain);
1915 0, TLI.getLibcallCallingConv(LC), isTailCall,
1917 Callee, Args, DAG,
SDLoc(Node));
1918 std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
1921 if (!CallInfo.second.getNode())
1923 return DAG.getRoot();
1925 return CallInfo.first;
1931 const SDValue *Ops,
unsigned NumOps,
1932 bool isSigned,
SDLoc dl) {
1934 Args.reserve(NumOps);
1937 for (
unsigned i = 0; i != NumOps; ++i) {
1938 Entry.
Node = Ops[i];
1941 Entry.
isZExt = !isSigned;
1942 Args.push_back(Entry);
1944 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
1945 TLI.getPointerTy());
1949 CallLoweringInfo CLI(DAG.getEntryNode(), RetTy, isSigned, !isSigned,
false,
1950 false, 0, TLI.getLibcallCallingConv(LC),
1953 Callee, Args, DAG, dl);
1954 std::pair<SDValue,SDValue> CallInfo = TLI.LowerCallTo(CLI);
1956 return CallInfo.first;
1961 std::pair<SDValue, SDValue>
1975 Entry.
isZExt = !isSigned;
1976 Args.push_back(Entry);
1978 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
1979 TLI.getPointerTy());
1984 0, TLI.getLibcallCallingConv(LC),
false,
1986 Callee, Args, DAG,
SDLoc(Node));
1987 std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
2001 case MVT::f32: LC = Call_F32;
break;
2002 case MVT::f64: LC = Call_F64;
break;
2003 case MVT::f80: LC = Call_F80;
break;
2007 return ExpandLibCall(LC, Node,
false);
2010 SDValue SelectionDAGLegalize::ExpandIntLibCall(
SDNode* Node,
bool isSigned,
2019 case MVT::i8: LC = Call_I8;
break;
2020 case MVT::i16: LC = Call_I16;
break;
2021 case MVT::i32: LC = Call_I32;
break;
2022 case MVT::i64: LC = Call_I64;
break;
2025 return ExpandLibCall(LC, Node, isSigned);
2049 unsigned OtherOpcode = 0;
2073 SelectionDAGLegalize::ExpandDivRemLibCall(
SDNode *Node,
2091 SDValue InChain = DAG.getEntryNode();
2103 Entry.
isZExt = !isSigned;
2104 Args.push_back(Entry);
2108 SDValue FIPtr = DAG.CreateStackTemporary(RetVT);
2112 Entry.
isZExt = !isSigned;
2113 Args.push_back(Entry);
2115 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2116 TLI.getPointerTy());
2121 0, TLI.getLibcallCallingConv(LC),
false,
2123 Callee, Args, DAG, dl);
2124 std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
2127 SDValue Rem = DAG.getLoad(RetVT, dl, CallInfo.second, FIPtr,
2183 SelectionDAGLegalize::ExpandSinCosLibCall(
SDNode *Node,
2198 SDValue InChain = DAG.getEntryNode();
2211 Args.push_back(Entry);
2214 SDValue SinPtr = DAG.CreateStackTemporary(RetVT);
2215 Entry.
Node = SinPtr;
2219 Args.push_back(Entry);
2222 SDValue CosPtr = DAG.CreateStackTemporary(RetVT);
2223 Entry.
Node = CosPtr;
2227 Args.push_back(Entry);
2229 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2230 TLI.getPointerTy());
2235 false,
false,
false,
false,
2236 0, TLI.getLibcallCallingConv(LC),
false,
2238 Callee, Args, DAG, dl);
2239 std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
2241 Results.
push_back(DAG.getLoad(RetVT, dl, CallInfo.second, SinPtr,
2243 Results.
push_back(DAG.getLoad(RetVT, dl, CallInfo.second, CosPtr,
2251 SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(
bool isSigned,
2266 StackSlot, WordOff);
2267 if (TLI.isLittleEndian())
2280 SDValue Store1 = DAG.getStore(DAG.getEntryNode(), dl,
2286 SDValue Store2 = DAG.getStore(Store1, dl, InitialHi, Hi,
2293 SDValue Bias = DAG.getConstantFP(isSigned ?
2307 DAG.getIntPtrConstant(0));
2313 assert(!isSigned &&
"Legalize cannot Expand SINT_TO_FP for i64 yet");
2323 DAG.getConstant(UINT64_C(0x4330000000000000),
MVT::i64);
2327 DAG.getConstant(UINT64_C(0x4530000000000000),
MVT::i64);
2350 DAG.getConstant(1, TLI.getShiftAmountTy(Op0.
getValueType()));
2365 return DAG.getSelect(dl,
MVT::f32, SignBitTest, Slow, Fast);
2371 DAG.getConstant(UINT64_C(0xfffffffffffff800),
MVT::i64));
2373 DAG.getConstant(UINT64_C(0x800),
MVT::i64));
2375 DAG.getConstant(UINT64_C(0x7ff),
MVT::i64));
2380 Op0, DAG.getConstant(UINT64_C(0x0020000000000000),
MVT::i64),
2386 DAG.getConstant(32, SHVT));
2396 DAG.getIntPtrConstant(0));
2404 SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4);
2406 SignSet, Four, Zero);
2414 case MVT::i8 : FF = 0x43800000ULL;
break;
2415 case MVT::i16: FF = 0x47800000ULL;
break;
2416 case MVT::i32: FF = 0x4F800000ULL;
break;
2417 case MVT::i64: FF = 0x5F800000ULL;
break;
2419 if (TLI.isLittleEndian()) FF <<= 32;
2423 SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
2424 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
2426 Alignment = std::min(Alignment, 4u);
2429 FudgeInReg = DAG.getLoad(
MVT::f32, dl, DAG.getEntryNode(), CPIdx,
2431 false,
false,
false, Alignment);
2434 DAG.getEntryNode(), CPIdx,
2436 MVT::f32,
false,
false, Alignment);
2450 SDValue SelectionDAGLegalize::PromoteLegalINT_TO_FP(
SDValue LegalOp,
2457 unsigned OpToUse = 0;
2462 assert(NewInTy.
isInteger() &&
"Ran out of possibilities!");
2469 if (isSigned)
continue;
2482 return DAG.getNode(OpToUse, dl, DestVT,
2484 dl, NewInTy, LegalOp));
2492 SDValue SelectionDAGLegalize::PromoteLegalFP_TO_INT(
SDValue LegalOp,
2497 EVT NewOutTy = DestVT;
2499 unsigned OpToUse = 0;
2504 assert(NewOutTy.
isInteger() &&
"Ran out of possibilities!");
2532 EVT SHVT = TLI.getShiftAmountTy(VT);
2533 SDValue Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8;
2539 return DAG.getNode(
ISD::OR, dl, VT, Tmp1, Tmp2);
2545 Tmp3 = DAG.
getNode(
ISD::AND, dl, VT, Tmp3, DAG.getConstant(0xFF0000, VT));
2546 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp2, DAG.getConstant(0xFF00, VT));
2549 return DAG.getNode(
ISD::OR, dl, VT, Tmp4, Tmp2);
2559 Tmp7 = DAG.
getNode(
ISD::AND, dl, VT, Tmp7, DAG.getConstant(255ULL<<48, VT));
2560 Tmp6 = DAG.
getNode(
ISD::AND, dl, VT, Tmp6, DAG.getConstant(255ULL<<40, VT));
2561 Tmp5 = DAG.
getNode(
ISD::AND, dl, VT, Tmp5, DAG.getConstant(255ULL<<32, VT));
2562 Tmp4 = DAG.
getNode(
ISD::AND, dl, VT, Tmp4, DAG.getConstant(255ULL<<24, VT));
2563 Tmp3 = DAG.
getNode(
ISD::AND, dl, VT, Tmp3, DAG.getConstant(255ULL<<16, VT));
2564 Tmp2 = DAG.
getNode(
ISD::AND, dl, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT));
2571 return DAG.getNode(
ISD::OR, dl, VT, Tmp8, Tmp4);
2577 SDValue SelectionDAGLegalize::ExpandBitCount(
unsigned Opc,
SDValue Op,
2583 EVT ShVT = TLI.getShiftAmountTy(VT);
2586 assert(VT.
isInteger() && Len <= 128 && Len % 8 == 0 &&
2587 "CTPOP not implemented for this type.");
2601 DAG.getConstant(1, ShVT)),
2605 DAG.getNode(
ISD::AND, dl, VT, Op, Mask33),
2608 DAG.getConstant(2, ShVT)),
2614 DAG.getConstant(4, ShVT))),
2618 DAG.getNode(
ISD::MUL, dl, VT, Op, Mask01),
2619 DAG.getConstant(Len - 8, ShVT));
2637 EVT ShVT = TLI.getShiftAmountTy(VT);
2639 for (
unsigned i = 0; (1U << i) <= (len / 2); ++i) {
2640 SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT);
2644 Op = DAG.getNOT(dl, Op, VT);
2657 DAG.getNOT(dl, Op, VT),
2659 DAG.getConstant(1, VT)));
2661 if (!TLI.isOperationLegalOrCustom(
ISD::CTPOP, VT) &&
2662 TLI.isOperationLegalOrCustom(
ISD::CTLZ, VT))
2663 return DAG.getNode(
ISD::SUB, dl, VT,
2666 return DAG.getNode(
ISD::CTPOP, dl, VT, Tmp3);
2671 std::pair <SDValue, SDValue> SelectionDAGLegalize::ExpandAtomic(
SDNode *Node) {
2801 return ExpandChainLibCall(LC, Node,
false);
2804 void SelectionDAGLegalize::ExpandNode(
SDNode *Node) {
2807 SDValue Tmp1, Tmp2, Tmp3, Tmp4;
2854 DAG.getExternalSymbol(
"__sync_synchronize",
2855 TLI.getPointerTy()),
2857 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
2866 cast<AtomicSDNode>(Node)->getMemoryVT(),
2869 cast<AtomicSDNode>(Node)->getMemOperand(),
2870 cast<AtomicSDNode>(Node)->getOrdering(),
2871 cast<AtomicSDNode>(Node)->getSynchScope());
2879 cast<AtomicSDNode>(Node)->getMemoryVT(),
2882 cast<AtomicSDNode>(Node)->getMemOperand(),
2883 cast<AtomicSDNode>(Node)->getOrdering(),
2884 cast<AtomicSDNode>(Node)->getSynchScope());
2903 std::pair<SDValue, SDValue> Tmp = ExpandAtomic(Node);
2909 ExpandDYNAMIC_STACKALLOC(Node, Results);
2918 Results.
push_back(DAG.getConstant(0, VT));
2921 Results.
push_back(DAG.getConstantFP(0, VT));
2934 DAG.getExternalSymbol(
"abort", TLI.getPointerTy()),
2936 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
2958 EVT ShiftAmountTy = TLI.getShiftAmountTy(VT);
2963 SDValue ShiftCst = DAG.getConstant(BitsDiff, ShiftAmountTy);
2978 Tmp1 = EmitStackConvert(Node->
getOperand(0), ExtraVT,
2993 APFloat apf(DAG.EVTToAPFloatSemantics(VT),
2997 Tmp1 = DAG.getConstantFP(apf, VT);
2998 Tmp2 = DAG.getSetCC(dl, getSetCCResultType(VT),
3006 DAG.getConstant(x, NVT));
3007 Tmp1 = DAG.getSelect(dl, NVT, Tmp2, True, False);
3012 const Value *V = cast<SrcValueSDNode>(Node->
getOperand(2))->getValue();
3018 SDValue VAListLoad = DAG.getLoad(TLI.getPointerTy(), dl, Tmp1, Tmp2,
3020 false,
false,
false, 0);
3023 if (Align > TLI.getMinStackArgumentAlignment()) {
3024 assert(((Align & (Align-1)) == 0) &&
"Expected Align to be a power of 2");
3027 DAG.getConstant(Align - 1,
3031 DAG.getConstant(-(int64_t)Align,
3037 DAG.getConstant(TLI.getDataLayout()->
3041 Tmp3 = DAG.getStore(VAListLoad.
getValue(1), dl, Tmp3, Tmp2,
3045 false,
false,
false, 0));
3046 Results.
push_back(Results[0].getValue(1));
3052 const Value *VD = cast<SrcValueSDNode>(Node->
getOperand(3))->getValue();
3053 const Value *
VS = cast<SrcValueSDNode>(Node->
getOperand(4))->getValue();
3054 Tmp1 = DAG.getLoad(TLI.getPointerTy(), dl, Node->
getOperand(0),
3056 false,
false,
false, 0);
3057 Tmp1 = DAG.getStore(Tmp1.getValue(1), dl, Tmp1, Node->
getOperand(1),
3068 Tmp1 = ExpandExtractFromVectorThroughStack(
SDValue(Node, 0));
3078 Results.
push_back(ExpandVectorBuildThroughStack(Node));
3082 Results.
push_back(ExpandSCALAR_TO_VECTOR(Node));
3091 ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(Node)->getMask();
3097 if (!TLI.isTypeLegal(EltVT)) {
3099 EVT NewEltVT = TLI.getTypeToTransformTo(*DAG.getContext(), EltVT);
3103 if (NewEltVT.
bitsLT(EltVT)) {
3112 assert(NewVT.
bitsEq(VT));
3126 for (
unsigned fi = 0; fi < factor; ++fi)
3130 for (
unsigned fi = 0; fi < factor; ++fi)
3141 for (
unsigned i = 0; i != NumElems; ++i) {
3146 unsigned Idx = Mask[i];
3150 DAG.getConstant(Idx, TLI.getVectorIdxTy())));
3154 DAG.getConstant(Idx - NumElems,
3155 TLI.getVectorIdxTy())));
3166 if (cast<ConstantSDNode>(Node->
getOperand(1))->getZExtValue()) {
3183 if (
unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) {
3186 Results.
push_back(Results[0].getValue(1));
3195 if (
unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) {
3203 Results.
push_back(ExpandFCOPYSIGN(Node));
3216 Tmp2 = DAG.getConstantFP(0.0, VT);
3217 Tmp2 = DAG.getSetCC(dl, getSetCCResultType(Tmp1.getValueType()),
3220 Tmp1 = DAG.getSelect(dl, VT, Tmp2, Tmp1, Tmp3);
3238 SDVTList VTs = DAG.getVTList(VT, VT);
3241 Tmp1 = Tmp1.getValue(1);
3256 ExpandSinCosLibCall(Node, Results);
3353 Results.
push_back(ExpandConstantFP(CFP,
true));
3358 assert(TLI.isOperationLegalOrCustom(
ISD::FADD, VT) &&
3359 TLI.isOperationLegalOrCustom(
ISD::FNEG, VT) &&
3360 "Don't know how to expand this FP subtraction!");
3368 assert(TLI.isOperationLegalOrCustom(
ISD::ADD, VT) &&
3369 TLI.isOperationLegalOrCustom(
ISD::XOR, VT) &&
3370 "Don't know how to expand this subtraction!");
3373 Tmp1 = DAG.getNode(
ISD::ADD, dl, VT, Tmp1, DAG.getConstant(1, VT));
3385 if (TLI.isOperationLegalOrCustom(DivRemOpc, VT) ||
3388 !TLI.isOperationLegalOrCustom(DivOpc, Node->
getValueType(0)) &&
3390 SDVTList VTs = DAG.getVTList(VT, VT);
3391 Tmp1 = DAG.getNode(DivRemOpc, dl, VTs, Tmp2, Tmp3).getValue(1);
3392 }
else if (TLI.isOperationLegalOrCustom(DivOpc, VT)) {
3394 Tmp1 = DAG.getNode(DivOpc, dl, VT, Tmp2, Tmp3);
3395 Tmp1 = DAG.getNode(
ISD::MUL, dl, VT, Tmp1, Tmp3);
3396 Tmp1 = DAG.getNode(
ISD::SUB, dl, VT, Tmp2, Tmp1);
3397 }
else if (isSigned)
3398 Tmp1 = ExpandIntLibCall(Node,
true,
3403 Tmp1 = ExpandIntLibCall(Node,
false,
3415 SDVTList VTs = DAG.getVTList(VT, VT);
3416 if (TLI.isOperationLegalOrCustom(DivRemOpc, VT) ||
3419 Tmp1 = DAG.getNode(DivRemOpc, dl, VTs, Node->
getOperand(0),
3422 Tmp1 = ExpandIntLibCall(Node,
true,
3427 Tmp1 = ExpandIntLibCall(Node,
false,
3439 SDVTList VTs = DAG.getVTList(VT, VT);
3440 assert(TLI.isOperationLegalOrCustom(ExpandOpcode, VT) &&
3441 "If this wasn't legal, it shouldn't have been created!");
3442 Tmp1 = DAG.getNode(ExpandOpcode, dl, VTs, Node->
getOperand(0),
3450 ExpandDivRemLibCall(Node, Results);
3454 SDVTList VTs = DAG.getVTList(VT, VT);
3460 bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::SMUL_LOHI, VT);
3461 bool HasUMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::UMUL_LOHI, VT);
3462 bool HasMULHS = TLI.isOperationLegalOrCustom(
ISD::MULHS, VT);
3463 bool HasMULHU = TLI.isOperationLegalOrCustom(
ISD::MULHU, VT);
3464 unsigned OpToUse = 0;
3465 if (HasSMUL_LOHI && !HasMULHS) {
3467 }
else if (HasUMUL_LOHI && !HasMULHU) {
3469 }
else if (HasSMUL_LOHI) {
3471 }
else if (HasUMUL_LOHI) {
3479 Tmp1 = ExpandIntLibCall(Node,
false,
3509 SDValue SignsMatch = DAG.getSetCC(dl, OType, LHSSign, RHSSign,
3541 static const unsigned Ops[2][3] =
3545 if (TLI.isOperationLegalOrCustom(Ops[isSigned][0], VT)) {
3547 TopHalf = DAG.
getNode(Ops[isSigned][0], dl, VT, LHS, RHS);
3548 }
else if (TLI.isOperationLegalOrCustom(Ops[isSigned][1], VT)) {
3549 BottomHalf = DAG.
getNode(Ops[isSigned][1], dl, DAG.getVTList(VT, VT), LHS,
3554 LHS = DAG.
getNode(Ops[isSigned][2], dl, WideVT, LHS);
3555 RHS = DAG.
getNode(Ops[isSigned][2], dl, WideVT, RHS);
3556 Tmp1 = DAG.getNode(
ISD::MUL, dl, WideVT, LHS, RHS);
3558 DAG.getIntPtrConstant(0));
3560 DAG.getIntPtrConstant(1));
3581 DAG.getConstant(LoSize-1, TLI.getPointerTy()));
3583 DAG.getConstant(LoSize-1, TLI.getPointerTy()));
3589 SDValue Args[] = { LHS, HiLHS, RHS, HiRHS };
3590 SDValue Ret = ExpandLibCall(LC, WideVT, Args, 4, isSigned, dl);
3592 DAG.getIntPtrConstant(0));
3594 DAG.getIntPtrConstant(1));
3598 DAG.DeleteNode(Ret.
getNode());
3604 Tmp1 = DAG.getNode(
ISD::SRA, dl, VT, BottomHalf, Tmp1);
3605 TopHalf = DAG.getSetCC(dl, getSetCCResultType(VT), TopHalf, Tmp1,
3608 TopHalf = DAG.getSetCC(dl, getSetCCResultType(VT), TopHalf,
3619 Tmp2 = DAG.getNode(
ISD::SHL, dl, PairTy, Tmp2,
3621 TLI.getShiftAmountTy(PairTy)));
3630 Tmp1 = DAG.getSelectCC(dl, Tmp1.getOperand(0), Tmp1.getOperand(1),
3632 cast<CondCodeSDNode>(Tmp1.getOperand(2))->
get());
3634 Tmp1 = DAG.getSelectCC(dl, Tmp1,
3635 DAG.getConstant(0, Tmp1.getValueType()),
3645 EVT PTy = TLI.getPointerTy();
3648 unsigned EntrySize =
3649 DAG.getMachineFunction().getJumpTableInfo()->getEntrySize(TD);
3652 Index, DAG.getConstant(EntrySize, Index.
getValueType()));
3666 TLI.getPICJumpTableRelocBase(Table, DAG));
3679 Tmp1, Tmp2.getOperand(2),
3680 Tmp2.getOperand(0), Tmp2.getOperand(1),
3684 Tmp3 = (Tmp2.getOpcode() ==
ISD::UNDEF) ? Tmp2 :
3685 DAG.getNode(
ISD::AND, dl, Tmp2.getValueType(), Tmp2,
3686 DAG.getConstant(1, Tmp2.getValueType()));
3689 DAG.getConstant(0, Tmp3.getValueType()),
3698 bool Legalized = LegalizeSetCCCondCode(Node->
getValueType(0), Tmp1, Tmp2,
3699 Tmp3, NeedInvert, dl);
3711 Tmp1 = DAG.getNOT(dl, Tmp1, Tmp1->getValueType(0));
3721 switch (TLI.getBooleanContents(VT.
isVector())) {
3731 DAG.getConstant(TrueValue, VT), DAG.getConstant(0, VT),
3743 bool Legalized =
false;
3748 Tmp1.getValueType().isInteger());
3749 if (TLI.isCondCodeLegal(InvCC, Tmp1.getSimpleValueType())) {
3752 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp4, Tmp3, InvCC);
3757 if (TLI.isCondCodeLegal(SwapInvCC, Tmp1.getSimpleValueType())) {
3761 Tmp1 = DAG.getSelectCC(dl, Tmp2, Tmp1, Tmp4, Tmp3, SwapInvCC);
3766 Legalized = LegalizeSetCCCondCode(
3767 getSetCCResultType(Tmp1.getValueType()), Tmp1, Tmp2, CC, NeedInvert,
3770 assert(Legalized &&
"Can't legalize SELECT_CC with legal condition!");
3781 Tmp1, Tmp2, Tmp3, Tmp4, CC);
3783 Tmp2 = DAG.getConstant(0, Tmp1.getValueType());
3798 bool Legalized = LegalizeSetCCCondCode(getSetCCResultType(
3799 Tmp2.getValueType()), Tmp2, Tmp3, Tmp4, NeedInvert, dl);
3801 assert(Legalized &&
"Can't legalize BR_CC with legal condition!");
3814 Tmp3 = DAG.getConstant(0, Tmp2.getValueType());
3823 Results.
push_back(ExpandBUILD_VECTOR(Node));
3830 assert(VT.
isVector() &&
"Unable to legalize non-vector shift");
3831 assert(TLI.isTypeLegal(VT.
getScalarType())&&
"Element type must be legal");
3835 for (
unsigned Idx = 0; Idx < NumElem; Idx++) {
3839 TLI.getVectorIdxTy()));
3843 TLI.getVectorIdxTy()));
3849 &Scalars[0], Scalars.
size());
3850 ReplaceNode(
SDValue(Node, 0), Result);
3867 if (!Results.
empty())
3868 ReplaceNode(Node, Results.
data());
3871 void SelectionDAGLegalize::PromoteNode(
SDNode *Node) {
3879 MVT NVT = TLI.getTypeToPromoteTo(Node->
getOpcode(), OVT);
3895 Tmp2 = DAG.getSetCC(dl, getSetCCResultType(NVT),
3896 Tmp1, DAG.getConstant(NVT.getSizeInBits(), NVT),
3898 Tmp1 = DAG.getSelect(dl, NVT, Tmp2,
3904 DAG.getConstant(NVT.getSizeInBits() -
3910 unsigned DiffBits = NVT.getSizeInBits() - OVT.
getSizeInBits();
3914 DAG.getConstant(DiffBits, TLI.getShiftAmountTy(NVT)));
3939 &&
"VAARG promotion is supported only for vectors or integer types");
3944 Tmp1 = DAG.getVAArg(NVT, dl, Chain, Ptr, Node->
getOperand(2),
3948 Tmp2 = DAG.
getNode(TruncOp, dl, OVT, Tmp1);
3952 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 0), Tmp2);
3953 DAG.ReplaceAllUsesOfValueWith(
SDValue(Node, 1), Chain);
3960 unsigned ExtOp, TruncOp;
3965 assert(OVT.
isInteger() &&
"Cannot promote logic operation");
3974 Results.
push_back(DAG.getNode(TruncOp, dl, OVT, Tmp1));
3978 unsigned ExtOp, TruncOp;
3994 Tmp1 = DAG.getSelect(dl, NVT, Tmp1, Tmp2, Tmp3);
3996 Tmp1 = DAG.getNode(TruncOp, dl, Node->
getValueType(0), Tmp1);
3998 Tmp1 = DAG.getNode(TruncOp, dl, Node->
getValueType(0), Tmp1,
3999 DAG.getIntPtrConstant(0));
4004 ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(Node)->getMask();
4011 Tmp1 = ShuffleWithNarrowerEltType(NVT, OVT, dl, Tmp1, Tmp2, Mask);
4018 if (NVT.isInteger()) {
4020 cast<CondCodeSDNode>(Node->
getOperand(2))->
get();
4023 Tmp1 = DAG.getNode(ExtOp, dl, NVT, Node->
getOperand(0));
4036 Tmp3, DAG.getIntPtrConstant(0)));
4044 Tmp2 = DAG.getNode(Node->
getOpcode(), dl, NVT, Tmp1);
4046 Tmp2, DAG.getIntPtrConstant(0)));
4052 if (!Results.
empty())
4053 ReplaceNode(Node, Results.
data());
4061 SelectionDAGLegalize(*this).LegalizeDAG();
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
void push_back(const T &Elt)
SDValue getConstant(uint64_t Val, EVT VT, bool isTarget=false)
SDValue getValue(unsigned R) const
static APInt getSignBit(unsigned BitWidth)
Get the SignBit for a specific bit width.
static void ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG, const TargetLowering &TLI, SDValue &ValResult, SDValue &ChainResult)
ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
LLVMContext * getContext() const
void dump() const
dump - Dump this node, for debugging.
static MachinePointerInfo getJumpTable()
SDVTList getVTList() const
static bool isDivRemLibcallAvailable(SDNode *Node, bool isSigned, const TargetLowering &TLI)
isDivRemLibcallAvailable - Return true if divmod libcall is available.
unsigned getOpcode() const
Type * getTypeForEVT(LLVMContext &Context) const
unsigned getSizeInBits() const
unsigned getNumOperands() const
MDNode - a tuple of other values.
const SDValue & getOperand(unsigned Num) const
static MachinePointerInfo getConstantPool()
static IntegerType * getInt64Ty(LLVMContext &C)
const SDValue & getBasePtr() const
unsigned getResNo() const
get the index which selects a specific result in the SDNode
bool bitsLT(EVT VT) const
bitsLT - Return true if this has less bits than VT.
static MachinePointerInfo getFixedStack(int FI, int64_t offset=0)
SDValue getLoad(EVT VT, SDLoc dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, bool isVolatile, bool isNonTemporal, bool isInvariant, unsigned Alignment, const MDNode *TBAAInfo=0, const MDNode *Ranges=0)
bool isVector() const
isVector - Return true if this is a vector value type.
EVT getShiftAmountTy(EVT LHSTy) const
bool isLittleEndian() const
SDValue getStore(SDValue Chain, SDLoc dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, bool isVolatile, bool isNonTemporal, unsigned Alignment, const MDNode *TBAAInfo=0)
#define llvm_unreachable(msg)
EVT getValueType(unsigned ResNo) const
APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const
Logical right-shift function.
static Constant * get(ArrayRef< Constant * > V)
MachinePointerInfo getWithOffset(int64_t O) const
EVT getScalarType() const
bool bitsGE(EVT VT) const
bitsGE - Return true if this has no less bits than VT.
virtual MVT getPointerTy(uint32_t=0) const
bool isInteger() const
isInteger - Return true if this is an integer, or a vector integer type.
uint64_t getZExtValue() const
Return the zero extended value.
EVT getVectorElementType() const
unsigned getNumValues() const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Simple integer binary arithmetic operators.
const SDValue & getBasePtr() const
EVT getHalfSizedIntegerVT(LLVMContext &Context) const
EVT getMemoryVT() const
getMemoryVT - Return the type of the in-memory value.
static void ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG, const TargetLowering &TLI, SelectionDAGLegalize *DAGLegalize)
ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores.
static bool useSinCos(SDNode *Node)
bool isSignedIntSetCC(CondCode Code)
UNDEF - An undefined node.
static bool useDivRem(SDNode *Node, bool isSigned, bool isDIV)
SDNode * getNode() const
get the SDNode which holds the desired result
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
bool isTypeLegal(EVT VT) const
unsigned getStoreSizeInBits() const
bool isInteger() const
isInteger - Return true if this is an integer, or a vector integer type.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const
Truncate to new width.
const SDValue & getOperand(unsigned i) const
Simple binary floating point operators.
bool isNonTemporal() const
LLVM Constant Representation.
bool isVector() const
isVector - Return true if this is a vector value type.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
static Type * getVoidTy(LLVMContext &C)
unsigned getOpcode() const
TRAP - Trapping instruction.
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
DEBUGTRAP - Trap intended to get the attention of a debugger.
static Constant * getFPTrunc(Constant *C, Type *Ty)
CondCode getSetCCSwappedOperands(CondCode Operation)
use_iterator use_begin() const
const SDValue & getValue() const
static bool isValueValidForType(EVT VT, const APFloat &Val)
Bit counting operators with an undefined result for zero inputs.
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
static UndefValue * get(Type *T)
std::vector< ArgListEntry > ArgListTy
const APFloat & getValueAPF() const
bool bitsEq(EVT VT) const
bitsEq - Return true if this has the same number of bits as VT.
const ConstantFP * getConstantFPValue() const
ISD::MemIndexedMode getAddressingMode() const
PointerType * getPointerTo(unsigned AddrSpace=0)
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements)
uint64_t getConstantOperandVal(unsigned Num) const
SDValue CreateStackTemporary(EVT VT, unsigned minAlign=1)
const MachinePointerInfo & getPointerInfo() const
bool bitsGT(EVT VT) const
bitsGT - Return true if this has more bits than VT.
Class for constant integers.
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
SDValue getExtLoad(ISD::LoadExtType ExtType, SDLoc dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, bool isVolatile, bool isNonTemporal, unsigned Alignment, const MDNode *TBAAInfo=0)
const SDValue & getChain() const
Byte Swap and Counting operators.
MachineMemOperand * getMemOperand() const
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
CondCode getSetCCInverse(CondCode Operation, bool isInteger)
double BitsToDouble(uint64_t Bits)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
unsigned Log2_32(uint32_t Value)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
const MDNode * getTBAAInfo() const
Returns the TBAAInfo that describes the dereference.
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
ISD::LoadExtType getExtensionType() const
Class for arbitrary precision integers.
static use_iterator use_end()
ZERO_EXTEND - Used for integer types, zeroing the new bits.
APInt bitcastToAPInt() const
SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT)
ANY_EXTEND - Used for integer types. The high bits are undefined.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
const StringRef getTargetTriple() const
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
unsigned getAddressSpace() const
getAddressSpace - Return the address space for the associated pointer
uint64_t MinAlign(uint64_t A, uint64_t B)
Bitwise operators - logical and, logical or, logical xor.
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
unsigned getSizeInBits() const
getSizeInBits - Return the size of the specified value type in bits.
SDValue getTruncStore(SDValue Chain, SDLoc dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, EVT TVT, bool isNonTemporal, bool isVolatile, unsigned Alignment, const MDNode *TBAAInfo=0)
FSINCOS - Compute both fsin and fcos as a single operation.
const APFloat & getValueAPF() const
bool isByteSized() const
isByteSized - Return true if the bit size is a multiple of 8.
bool isFloatingPoint() const
isFloatingPoint - Return true if this is a FP, or a vector FP type.
static bool isSinCosLibcallAvailable(SDNode *Node, const TargetLowering &TLI)
isSinCosLibcallAvailable - Return true if sincos libcall is available.
LLVM Value Representation.
bool isTruncatingStore() const
static APInt getNullValue(unsigned numBits)
Get the '0' value.
TRUNCATE - Completely drop the high bits.
unsigned getAlignment() const
static bool canCombineSinCosLibcall(SDNode *Node, const TargetLowering &TLI, const TargetMachine &TM)
MVT getSimpleValueType(unsigned ResNo) const
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
unsigned getVectorNumElements() const