42 #define DEBUG_TYPE "x86-isel"
44 STATISTIC(NumLoadMoved,
"Number of loads moved below TokenFactor");
53 struct X86ISelAddressMode {
74 unsigned char SymbolFlags;
77 :
BaseType(RegBase), Base_FrameIndex(0), Scale(1), IndexReg(), Disp(0),
78 Segment(), GV(nullptr),
CP(nullptr), BlockAddr(nullptr),
ES(nullptr),
81 bool hasSymbolicDisplacement()
const {
82 return GV !=
nullptr ||
CP !=
nullptr ||
ES !=
nullptr ||
83 MCSym !=
nullptr ||
JT != -1 || BlockAddr !=
nullptr;
86 bool hasBaseOrIndexReg()
const {
88 IndexReg.getNode() !=
nullptr || Base_Reg.getNode() !=
nullptr;
92 bool isRIPRelative()
const {
93 if (
BaseType != RegBase)
return false;
95 dyn_cast_or_null<RegisterSDNode>(Base_Reg.getNode()))
96 return RegNode->getReg() == X86::RIP;
105 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
107 dbgs() <<
"X86ISelAddressMode " <<
this <<
'\n';
108 dbgs() <<
"Base_Reg ";
109 if (Base_Reg.getNode())
110 Base_Reg.getNode()->dump();
113 dbgs() <<
" Base.FrameIndex " << Base_FrameIndex <<
'\n'
114 <<
" Scale" << Scale <<
'\n'
116 if (IndexReg.getNode())
117 IndexReg.getNode()->dump();
120 dbgs() <<
" Disp " << Disp <<
'\n'
142 dbgs() <<
" JT" <<
JT <<
" Align" <<
Align <<
'\n';
168 OptForMinSize(
false) {}
171 return "X86 DAG->DAG Instruction Selection";
181 void EmitFunctionEntryCode()
override;
185 void PreprocessISelDAG()
override;
188 #include "X86GenDAGISel.inc"
193 bool foldOffsetIntoAddress(uint64_t
Offset, X86ISelAddressMode &AM);
194 bool matchLoadInAddress(
LoadSDNode *
N, X86ISelAddressMode &AM);
195 bool matchWrapper(
SDValue N, X86ISelAddressMode &AM);
196 bool matchAddress(
SDValue N, X86ISelAddressMode &AM);
197 bool matchAdd(
SDValue N, X86ISelAddressMode &AM,
unsigned Depth);
198 bool matchAddressRecursively(
SDValue N, X86ISelAddressMode &AM,
200 bool matchAddressBase(
SDValue N, X86ISelAddressMode &AM);
207 template <
class GatherScatterSDNode>
208 bool selectAddrOfGatherScatterNode(GatherScatterSDNode *Parent,
SDValue N,
235 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
236 unsigned ConstraintID,
237 std::vector<SDValue> &OutOps)
override;
239 void emitSpecialCodeForMain();
241 inline void getAddressOperands(X86ISelAddressMode &AM,
const SDLoc &
DL,
245 Base = (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
246 ? CurDAG->getTargetFrameIndex(
248 TLI->getPointerTy(CurDAG->getDataLayout()))
250 Scale = getI8Imm(AM.Scale, DL);
255 Disp = CurDAG->getTargetGlobalAddress(AM.GV,
SDLoc(),
259 Disp = CurDAG->getTargetConstantPool(AM.CP,
MVT::i32,
260 AM.Align, AM.Disp, AM.SymbolFlags);
262 assert(!AM.Disp &&
"Non-zero displacement is ignored with ES.");
263 Disp = CurDAG->getTargetExternalSymbol(AM.ES,
MVT::i32, AM.SymbolFlags);
264 }
else if (AM.MCSym) {
265 assert(!AM.Disp &&
"Non-zero displacement is ignored with MCSym.");
266 assert(AM.SymbolFlags == 0 &&
"oo");
267 Disp = CurDAG->getMCSymbol(AM.MCSym,
MVT::i32);
268 }
else if (AM.JT != -1) {
269 assert(!AM.Disp &&
"Non-zero displacement is ignored with JT.");
270 Disp = CurDAG->getTargetJumpTable(AM.JT,
MVT::i32, AM.SymbolFlags);
271 }
else if (AM.BlockAddr)
272 Disp = CurDAG->getTargetBlockAddress(AM.BlockAddr,
MVT::i32, AM.Disp,
275 Disp = CurDAG->getTargetConstant(AM.Disp, DL,
MVT::i32);
277 if (AM.Segment.getNode())
278 Segment = AM.Segment;
280 Segment = CurDAG->getRegister(0,
MVT::i32);
289 bool shouldAvoidImmediateInstFormsForSize(
SDNode *
N)
const {
300 UE = N->
use_end(); (UI != UE) && (UseCount < 2); ++UI) {
344 (RegNode = dyn_cast_or_null<RegisterSDNode>(
346 if ((RegNode->getReg() == X86::ESP) ||
347 (RegNode->getReg() == X86::RSP))
356 return (UseCount > 1);
360 inline SDValue getI8Imm(
unsigned Imm,
const SDLoc &DL) {
361 return CurDAG->getTargetConstant(Imm, DL,
MVT::i8);
365 inline SDValue getI32Imm(
unsigned Imm,
const SDLoc &DL) {
366 return CurDAG->getTargetConstant(Imm, DL,
MVT::i32);
372 SDNode *getGlobalBaseReg();
383 return Subtarget->getInstrInfo();
389 bool ComplexPatternFuncMutatesDAG()
const override {
393 bool isSExtAbsoluteSymbolRef(
unsigned Width,
SDNode *N)
const;
397 template <
unsigned W
idth>
bool isSExtRelocImm(
SDNode *N)
const {
398 if (
auto *CN = dyn_cast<ConstantSDNode>(N))
399 return isInt<Width>(CN->getSExtValue());
400 return isSExtAbsoluteSymbolRef(Width, N);
443 if (Imm->getAPIntValue().isSignedIntN(8))
478 "Unexpected chain operand");
530 if (isa<MemSDNode>(Chain.
getNode()) &&
531 cast<MemSDNode>(Chain.
getNode())->writeMem())
542 void X86DAGToDAGISel::PreprocessISelDAG() {
544 OptForSize = MF->getFunction()->optForSize();
545 OptForMinSize = MF->getFunction()->optForMinSize();
546 assert((!OptForMinSize || OptForSize) &&
"OptForMinSize implies OptForSize");
549 E = CurDAG->allnodes_end();
I !=
E; ) {
558 (Subtarget->is64Bit() ||
559 !getTargetMachine().isPositionIndependent())))) {
613 if (SrcIsSSE && DstIsSSE)
616 if (!SrcIsSSE && !DstIsSSE) {
632 MemVT = SrcIsSSE ? SrcVT : DstVT;
634 SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT);
639 CurDAG->getTruncStore(CurDAG->getEntryNode(), dl, N->
getOperand(0),
649 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Result);
654 CurDAG->DeleteNode(N);
660 void X86DAGToDAGISel::emitSpecialCodeForMain() {
661 if (Subtarget->isTargetCygMing()) {
663 auto &DL = CurDAG->getDataLayout();
666 CLI.setChain(CurDAG->getRoot())
668 CurDAG->getExternalSymbol(
"__main", TLI->getPointerTy(DL)),
671 std::pair<SDValue, SDValue> Result = TLI.
LowerCallTo(CLI);
672 CurDAG->setRoot(Result.second);
676 void X86DAGToDAGISel::EmitFunctionEntryCode() {
678 if (
const Function *Fn = MF->getFunction())
679 if (Fn->hasExternalLinkage() && Fn->getName() ==
"main")
680 emitSpecialCodeForMain();
690 return isInt<31>(Val);
693 bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t
Offset,
694 X86ISelAddressMode &AM) {
696 if (Offset != 0 && (AM.ES || AM.MCSym))
698 int64_t Val = AM.Disp +
Offset;
700 if (Subtarget->is64Bit()) {
702 AM.hasSymbolicDisplacement()))
706 if (AM.BaseType == X86ISelAddressMode::FrameIndexBase &&
715 bool X86DAGToDAGISel::matchLoadInAddress(
LoadSDNode *N, X86ISelAddressMode &AM){
725 if (
C->getSExtValue() == 0 && AM.Segment.getNode() ==
nullptr &&
726 (Subtarget->isTargetGlibc() || Subtarget->isTargetAndroid() ||
727 Subtarget->isTargetFuchsia()))
730 AM.Segment = CurDAG->getRegister(X86::GS,
MVT::i16);
733 AM.Segment = CurDAG->getRegister(X86::FS,
MVT::i16);
745 bool X86DAGToDAGISel::matchWrapper(
SDValue N, X86ISelAddressMode &AM) {
748 if (AM.hasSymbolicDisplacement())
762 if (AM.hasBaseOrIndexReg())
765 X86ISelAddressMode Backup = AM;
766 AM.GV =
G->getGlobal();
767 AM.SymbolFlags =
G->getTargetFlags();
768 if (foldOffsetIntoAddress(
G->getOffset(), AM)) {
773 X86ISelAddressMode Backup = AM;
774 AM.CP =
CP->getConstVal();
775 AM.Align =
CP->getAlignment();
776 AM.SymbolFlags =
CP->getTargetFlags();
777 if (foldOffsetIntoAddress(
CP->getOffset(), AM)) {
782 AM.ES = S->getSymbol();
783 AM.SymbolFlags = S->getTargetFlags();
784 }
else if (
auto *S = dyn_cast<MCSymbolSDNode>(N0)) {
785 AM.MCSym = S->getMCSymbol();
787 AM.JT = J->getIndex();
788 AM.SymbolFlags = J->getTargetFlags();
790 X86ISelAddressMode Backup = AM;
791 AM.BlockAddr = BA->getBlockAddress();
792 AM.SymbolFlags = BA->getTargetFlags();
793 if (foldOffsetIntoAddress(BA->getOffset(), AM)) {
801 AM.setBaseReg(CurDAG->getRegister(X86::RIP,
MVT::i64));
808 if (!Subtarget->is64Bit() ||
811 "RIP-relative addressing already handled");
813 AM.GV =
G->getGlobal();
814 AM.Disp +=
G->getOffset();
815 AM.SymbolFlags =
G->getTargetFlags();
817 AM.CP =
CP->getConstVal();
818 AM.Align =
CP->getAlignment();
819 AM.Disp +=
CP->getOffset();
820 AM.SymbolFlags =
CP->getTargetFlags();
822 AM.ES = S->getSymbol();
823 AM.SymbolFlags = S->getTargetFlags();
824 }
else if (
auto *S = dyn_cast<MCSymbolSDNode>(N0)) {
825 AM.MCSym = S->getMCSymbol();
827 AM.JT = J->getIndex();
828 AM.SymbolFlags = J->getTargetFlags();
830 AM.BlockAddr = BA->getBlockAddress();
831 AM.Disp += BA->getOffset();
832 AM.SymbolFlags = BA->getTargetFlags();
843 bool X86DAGToDAGISel::matchAddress(
SDValue N, X86ISelAddressMode &AM) {
844 if (matchAddressRecursively(N, AM, 0))
850 AM.BaseType == X86ISelAddressMode::RegBase &&
851 AM.Base_Reg.getNode() ==
nullptr) {
852 AM.Base_Reg = AM.IndexReg;
860 Subtarget->is64Bit() &&
862 AM.BaseType == X86ISelAddressMode::RegBase &&
863 AM.Base_Reg.getNode() ==
nullptr &&
864 AM.IndexReg.getNode() ==
nullptr &&
866 AM.hasSymbolicDisplacement())
867 AM.Base_Reg = CurDAG->getRegister(X86::RIP,
MVT::i64);
872 bool X86DAGToDAGISel::matchAdd(
SDValue N, X86ISelAddressMode &AM,
878 X86ISelAddressMode Backup = AM;
879 if (!matchAddressRecursively(N.
getOperand(0), AM, Depth+1) &&
880 !matchAddressRecursively(Handle.getValue().getOperand(1), AM, Depth+1))
885 if (!matchAddressRecursively(Handle.getValue().getOperand(1), AM, Depth+1) &&
886 !matchAddressRecursively(Handle.getValue().getOperand(0), AM, Depth+1))
893 if (AM.BaseType == X86ISelAddressMode::RegBase &&
894 !AM.Base_Reg.getNode() &&
895 !AM.IndexReg.getNode()) {
926 X86ISelAddressMode &AM) {
933 if (ScaleLog <= 0 || ScaleLog >= 4 ||
934 Mask != (0xffu << ScaleLog))
959 AM.Scale = (1 << ScaleLog);
969 X86ISelAddressMode &AM) {
982 if (ShiftAmt != 1 && ShiftAmt != 2 && ShiftAmt != 3)
1001 AM.Scale = 1 << ShiftAmt;
1002 AM.IndexReg = NewAnd;
1036 X86ISelAddressMode &AM) {
1047 unsigned AMShiftAmt = MaskTZ;
1051 if (AMShiftAmt <= 0 || AMShiftAmt > 3)
return true;
1059 if (MaskLZ < ScaleDown)
1061 MaskLZ -= ScaleDown;
1069 bool ReplacingAnyExtend =
false;
1076 MaskLZ = ExtendBits > MaskLZ ? 0 : MaskLZ - ExtendBits;
1077 ReplacingAnyExtend =
true;
1079 APInt MaskedHighBits =
1083 if (MaskedHighBits != Known.Zero)
return true;
1088 if (ReplacingAnyExtend) {
1112 AM.Scale = 1 << AMShiftAmt;
1113 AM.IndexReg = NewSRL;
1117 bool X86DAGToDAGISel::matchAddressRecursively(
SDValue N, X86ISelAddressMode &AM,
1121 dbgs() <<
"MatchAddress: ";
1126 return matchAddressBase(N, AM);
1131 if (AM.isRIPRelative()) {
1135 if (!(AM.ES || AM.MCSym) && AM.JT != -1)
1139 if (!foldOffsetIntoAddress(Cst->getSExtValue(), AM))
1147 if (!AM.hasSymbolicDisplacement() && AM.Disp == 0)
1148 if (
const auto *ESNode = dyn_cast<MCSymbolSDNode>(N.
getOperand(0))) {
1150 AM.MCSym = ESNode->getMCSymbol();
1156 uint64_t Val = cast<ConstantSDNode>(
N)->getSExtValue();
1157 if (!foldOffsetIntoAddress(Val, AM))
1164 if (!matchWrapper(N, AM))
1169 if (!matchLoadInAddress(cast<LoadSDNode>(N), AM))
1174 if (AM.BaseType == X86ISelAddressMode::RegBase &&
1175 AM.Base_Reg.getNode() ==
nullptr &&
1177 AM.BaseType = X86ISelAddressMode::FrameIndexBase;
1178 AM.Base_FrameIndex = cast<FrameIndexSDNode>(
N)->getIndex();
1184 if (AM.IndexReg.getNode() !=
nullptr || AM.Scale != 1)
1188 unsigned Val = CN->getZExtValue();
1193 if (Val == 1 || Val == 2 || Val == 3) {
1194 AM.Scale = 1 << Val;
1200 if (CurDAG->isBaseWithConstantOffset(ShVal)) {
1203 uint64_t Disp = (uint64_t)AddVal->
getSExtValue() << Val;
1204 if (!foldOffsetIntoAddress(Disp, AM))
1208 AM.IndexReg = ShVal;
1216 if (AM.IndexReg.getNode() !=
nullptr || AM.Scale != 1)
break;
1249 if (AM.BaseType == X86ISelAddressMode::RegBase &&
1250 AM.Base_Reg.getNode() ==
nullptr &&
1251 AM.IndexReg.getNode() ==
nullptr) {
1253 if (CN->getZExtValue() == 3 || CN->getZExtValue() == 5 ||
1254 CN->getZExtValue() == 9) {
1255 AM.Scale =
unsigned(CN->getZExtValue())-1;
1263 if (MulVal.getNode()->getOpcode() ==
ISD::ADD && MulVal.hasOneUse() &&
1264 isa<ConstantSDNode>(MulVal.getOperand(1))) {
1267 cast<ConstantSDNode>(MulVal.getOperand(1));
1268 uint64_t Disp = AddVal->
getSExtValue() * CN->getZExtValue();
1269 if (foldOffsetIntoAddress(Disp, AM))
1275 AM.IndexReg = AM.Base_Reg =
Reg;
1294 X86ISelAddressMode Backup = AM;
1295 if (matchAddressRecursively(N.
getOperand(0), AM, Depth+1)) {
1300 if (AM.IndexReg.getNode() || AM.isRIPRelative()) {
1320 if ((AM.BaseType == X86ISelAddressMode::RegBase && AM.Base_Reg.getNode() &&
1322 !AM.Base_Reg.getNode()->hasOneUse()) ||
1323 AM.BaseType == X86ISelAddressMode::FrameIndexBase)
1327 if ((AM.hasSymbolicDisplacement() && !Backup.hasSymbolicDisplacement()) +
1328 ((AM.Disp != 0) && (Backup.Disp == 0)) +
1329 (AM.Segment.getNode() && !Backup.Segment.getNode()) >= 2)
1350 if (!matchAdd(N, AM, Depth))
1362 !matchAdd(N, AM, Depth))
1371 if (AM.IndexReg.getNode() !=
nullptr || AM.Scale != 1)
break;
1401 return matchAddressBase(N, AM);
1406 bool X86DAGToDAGISel::matchAddressBase(
SDValue N, X86ISelAddressMode &AM) {
1408 if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base_Reg.getNode()) {
1410 if (!AM.IndexReg.getNode()) {
1421 AM.BaseType = X86ISelAddressMode::RegBase;
1426 template <
class GatherScatterSDNode>
1427 bool X86DAGToDAGISel::selectAddrOfGatherScatterNode(
1430 X86ISelAddressMode AM;
1431 unsigned AddrSpace = Mgs->getPointerInfo().getAddrSpace();
1433 if (AddrSpace == 256)
1434 AM.Segment = CurDAG->getRegister(X86::GS,
MVT::i16);
1435 if (AddrSpace == 257)
1436 AM.Segment = CurDAG->getRegister(X86::FS,
MVT::i16);
1437 if (AddrSpace == 258)
1438 AM.Segment = CurDAG->getRegister(X86::SS,
MVT::i16);
1441 Base = Mgs->getBasePtr();
1442 Index = Mgs->getIndex();
1443 unsigned ScalarSize = Mgs->getValue().getScalarValueSizeInBits();
1444 Scale = getI8Imm(ScalarSize/8, DL);
1447 if (isa<ConstantSDNode>(Base)) {
1448 assert(cast<ConstantSDNode>(Base)->isNullValue() &&
1449 "Unexpected base in gather/scatter");
1450 Scale = getI8Imm(1, DL);
1451 Base = CurDAG->getRegister(0,
MVT::i32);
1453 if (AM.Segment.getNode())
1454 Segment = AM.Segment;
1456 Segment = CurDAG->getRegister(0,
MVT::i32);
1457 Disp = CurDAG->getTargetConstant(0, DL,
MVT::i32);
1464 if (
auto Mgs = dyn_cast<MaskedGatherScatterSDNode>(Parent))
1465 return selectAddrOfGatherScatterNode<MaskedGatherScatterSDNode>(
1466 Mgs,
N, Base, Scale, Index, Disp, Segment);
1467 if (
auto X86Gather = dyn_cast<X86MaskedGatherSDNode>(Parent))
1468 return selectAddrOfGatherScatterNode<X86MaskedGatherSDNode>(
1469 X86Gather, N, Base, Scale, Index, Disp, Segment);
1483 X86ISelAddressMode AM;
1493 unsigned AddrSpace =
1494 cast<MemSDNode>(Parent)->getPointerInfo().getAddrSpace();
1496 if (AddrSpace == 256)
1497 AM.Segment = CurDAG->getRegister(X86::GS,
MVT::i16);
1498 if (AddrSpace == 257)
1499 AM.Segment = CurDAG->getRegister(X86::FS,
MVT::i16);
1500 if (AddrSpace == 258)
1501 AM.Segment = CurDAG->getRegister(X86::SS,
MVT::i16);
1504 if (matchAddress(N, AM))
1508 if (AM.BaseType == X86ISelAddressMode::RegBase) {
1509 if (!AM.Base_Reg.getNode())
1510 AM.Base_Reg = CurDAG->getRegister(0, VT);
1513 if (!AM.IndexReg.getNode())
1514 AM.IndexReg = CurDAG->getRegister(0, VT);
1516 getAddressOperands(AM,
SDLoc(N), Base, Scale, Index, Disp, Segment);
1527 bool X86DAGToDAGISel::selectScalarSSELoad(
SDNode *Root,
1531 SDValue &PatternNodeWithChain) {
1534 PatternNodeWithChain =
N;
1535 if (IsProfitableToFold(PatternNodeWithChain, N.
getNode(), Root) &&
1536 IsLegalToFold(PatternNodeWithChain, *N->
use_begin(), Root, OptLevel)) {
1537 LoadSDNode *
LD = cast<LoadSDNode>(PatternNodeWithChain);
1538 return selectAddr(LD, LD->
getBasePtr(), Base, Scale, Index, Disp,
1545 PatternNodeWithChain =
N;
1546 if (IsProfitableToFold(PatternNodeWithChain, N.
getNode(), Root) &&
1547 IsLegalToFold(PatternNodeWithChain, *N->
use_begin(), Root, OptLevel)) {
1548 auto *
MI = cast<MemIntrinsicSDNode>(PatternNodeWithChain);
1549 return selectAddr(
MI,
MI->getBasePtr(), Base, Scale, Index, Disp,
1560 IsProfitableToFold(PatternNodeWithChain, N.
getNode(), Root) &&
1561 IsLegalToFold(PatternNodeWithChain, N.
getNode(), Root, OptLevel)) {
1562 LoadSDNode *
LD = cast<LoadSDNode>(PatternNodeWithChain);
1563 return selectAddr(LD, LD->
getBasePtr(), Base, Scale, Index, Disp,
1576 IsProfitableToFold(PatternNodeWithChain, N.
getNode(), Root) &&
1577 IsLegalToFold(PatternNodeWithChain, N.
getNode(), Root, OptLevel)) {
1579 LoadSDNode *
LD = cast<LoadSDNode>(PatternNodeWithChain);
1580 return selectAddr(LD, LD->
getBasePtr(), Base, Scale, Index, Disp,
1589 bool X86DAGToDAGISel::selectMOV64Imm32(
SDValue N,
SDValue &Imm) {
1591 uint64_t ImmVal = CN->getZExtValue();
1592 if ((
uint32_t)ImmVal != (uint64_t)ImmVal)
1595 Imm = CurDAG->getTargetConstant(ImmVal,
SDLoc(N),
MVT::i64);
1603 "Unexpected node type for MOV32ri64");
1616 cast<GlobalAddressSDNode>(
N)->getGlobal()->getAbsoluteSymbolRange();
1623 bool X86DAGToDAGISel::selectLEA64_32Addr(
SDValue N,
SDValue &Base,
1629 if (!selectLEAAddr(N, Base, Scale, Index, Disp, Segment))
1633 if (RN && RN->
getReg() == 0)
1634 Base = CurDAG->getRegister(0,
MVT::i64);
1637 Base =
SDValue(CurDAG->getMachineNode(
1638 TargetOpcode::SUBREG_TO_REG, DL,
MVT::i64,
1639 CurDAG->getTargetConstant(0, DL,
MVT::i64),
1641 CurDAG->getTargetConstant(X86::sub_32bit, DL,
MVT::i32)),
1646 if (RN && RN->
getReg() == 0)
1647 Index = CurDAG->getRegister(0,
MVT::i64);
1650 "Expect to be extending 32-bit registers for use in LEA");
1651 Index =
SDValue(CurDAG->getMachineNode(
1652 TargetOpcode::SUBREG_TO_REG, DL,
MVT::i64,
1653 CurDAG->getTargetConstant(0, DL,
MVT::i64),
1655 CurDAG->getTargetConstant(X86::sub_32bit, DL,
1665 bool X86DAGToDAGISel::selectLEAAddr(
SDValue N,
1669 X86ISelAddressMode AM;
1680 if (matchAddress(N, AM))
1682 assert (T == AM.Segment);
1685 unsigned Complexity = 0;
1686 if (AM.BaseType == X86ISelAddressMode::RegBase)
1687 if (AM.Base_Reg.getNode())
1690 AM.Base_Reg = CurDAG->getRegister(0, VT);
1691 else if (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
1694 if (AM.IndexReg.getNode())
1697 AM.IndexReg = CurDAG->getRegister(0, VT);
1709 if (AM.hasSymbolicDisplacement()) {
1711 if (Subtarget->is64Bit())
1717 if (AM.Disp && (AM.Base_Reg.getNode() || AM.IndexReg.getNode()))
1721 if (Complexity <= 2)
1724 getAddressOperands(AM, DL, Base, Scale, Index, Disp, Segment);
1729 bool X86DAGToDAGISel::selectTLSADDRAddr(
SDValue N,
SDValue &Base,
1735 X86ISelAddressMode AM;
1736 AM.GV = GA->getGlobal();
1737 AM.Disp += GA->getOffset();
1738 AM.Base_Reg = CurDAG->getRegister(0, N.
getValueType());
1739 AM.SymbolFlags = GA->getTargetFlags();
1743 AM.IndexReg = CurDAG->getRegister(X86::EBX,
MVT::i32);
1745 AM.IndexReg = CurDAG->getRegister(0,
MVT::i64);
1748 getAddressOperands(AM,
SDLoc(N), Base, Scale, Index, Disp, Segment);
1753 if (
auto *CN = dyn_cast<ConstantSDNode>(N)) {
1754 Op = CurDAG->getTargetConstant(CN->getAPIntValue(),
SDLoc(CN),
1763 bool WasTruncated =
false;
1765 WasTruncated =
true;
1780 return !WasTruncated;
1784 auto *GA = cast<GlobalAddressSDNode>(N.
getOperand(0));
1786 if (!CR || CR->getUnsignedMax().uge(1ull << VT.
getSizeInBits()))
1790 Op = CurDAG->getTargetGlobalAddress(GA->getGlobal(),
SDLoc(N), VT,
1791 GA->getOffset(), GA->getTargetFlags());
1800 !IsProfitableToFold(N, P, P) ||
1801 !IsLegalToFold(N, P, P, OptLevel))
1804 return selectAddr(N.
getNode(),
1805 N.
getOperand(1), Base, Scale, Index, Disp, Segment);
1811 SDNode *X86DAGToDAGISel::getGlobalBaseReg() {
1812 unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
1813 auto &DL = MF->getDataLayout();
1814 return CurDAG->getRegister(GlobalBaseReg, TLI->
getPointerTy(DL)).getNode();
1817 bool X86DAGToDAGISel::isSExtAbsoluteSymbolRef(
unsigned Width,
SDNode *N)
const {
1837 UE = N->
use_end(); UI != UE; ++UI) {
1842 if (cast<RegisterSDNode>(UI->getOperand(1))->
getReg() !=
1847 FlagUE = UI->
use_end(); FlagUI != FlagUE; ++FlagUI) {
1849 if (FlagUI.getUse().getResNo() != 1)
continue;
1851 if (!FlagUI->isMachineOpcode())
return false;
1853 switch (FlagUI->getMachineOpcode()) {
1855 case X86::SETAr:
case X86::SETAEr:
case X86::SETBr:
case X86::SETBEr:
1856 case X86::SETEr:
case X86::SETNEr:
case X86::SETPr:
case X86::SETNPr:
1857 case X86::SETAm:
case X86::SETAEm:
case X86::SETBm:
case X86::SETBEm:
1858 case X86::SETEm:
case X86::SETNEm:
case X86::SETPm:
case X86::SETNPm:
1859 case X86::JA_1:
case X86::JAE_1:
case X86::JB_1:
case X86::JBE_1:
1860 case X86::JE_1:
case X86::JNE_1:
case X86::JP_1:
case X86::JNP_1:
1861 case X86::CMOVA16rr:
case X86::CMOVA16rm:
1862 case X86::CMOVA32rr:
case X86::CMOVA32rm:
1863 case X86::CMOVA64rr:
case X86::CMOVA64rm:
1864 case X86::CMOVAE16rr:
case X86::CMOVAE16rm:
1865 case X86::CMOVAE32rr:
case X86::CMOVAE32rm:
1866 case X86::CMOVAE64rr:
case X86::CMOVAE64rm:
1867 case X86::CMOVB16rr:
case X86::CMOVB16rm:
1868 case X86::CMOVB32rr:
case X86::CMOVB32rm:
1869 case X86::CMOVB64rr:
case X86::CMOVB64rm:
1870 case X86::CMOVBE16rr:
case X86::CMOVBE16rm:
1871 case X86::CMOVBE32rr:
case X86::CMOVBE32rm:
1872 case X86::CMOVBE64rr:
case X86::CMOVBE64rm:
1873 case X86::CMOVE16rr:
case X86::CMOVE16rm:
1874 case X86::CMOVE32rr:
case X86::CMOVE32rm:
1875 case X86::CMOVE64rr:
case X86::CMOVE64rm:
1876 case X86::CMOVNE16rr:
case X86::CMOVNE16rm:
1877 case X86::CMOVNE32rr:
case X86::CMOVNE32rm:
1878 case X86::CMOVNE64rr:
case X86::CMOVNE64rm:
1879 case X86::CMOVNP16rr:
case X86::CMOVNP16rm:
1880 case X86::CMOVNP32rr:
case X86::CMOVNP32rm:
1881 case X86::CMOVNP64rr:
case X86::CMOVNP64rm:
1882 case X86::CMOVP16rr:
case X86::CMOVP16rm:
1883 case X86::CMOVP32rr:
case X86::CMOVP32rm:
1884 case X86::CMOVP64rr:
case X86::CMOVP64rm:
1887 default:
return false;
1904 if (StoredVal.
getResNo() != 0)
return false;
1918 LoadNode = cast<LoadSDNode>(
Load);
1938 bool ChainCheck =
false;
1959 UE = UI->
use_end(); UI != UE; ++UI) {
1960 if (UI.getUse().getResNo() != 0)
1962 if (UI->getNodeId() > LoadId)
1985 if (LdVT ==
MVT::i64)
return X86::DEC64m;
1986 if (LdVT ==
MVT::i32)
return X86::DEC32m;
1987 if (LdVT ==
MVT::i16)
return X86::DEC16m;
1988 if (LdVT ==
MVT::i8)
return X86::DEC8m;
1991 if (LdVT ==
MVT::i64)
return X86::INC64m;
1992 if (LdVT ==
MVT::i32)
return X86::INC32m;
1993 if (LdVT ==
MVT::i16)
return X86::INC16m;
1994 if (LdVT ==
MVT::i8)
return X86::INC8m;
2016 if (Subtarget->isTargetNaCl())
2020 if (Subtarget->isTarget64BitILP32()) {
2029 ReplaceNode(Node, Brind.
getNode());
2030 SelectCode(ZextTarget.getNode());
2037 ReplaceNode(Node, getGlobalBaseReg());
2042 SDValue VSelect = CurDAG->getNode(
2045 ReplaceUses(
SDValue(Node, 0), VSelect);
2046 SelectCode(VSelect.
getNode());
2068 if (!Cst || !ShlCst)
2072 uint64_t ShlVal = ShlCst->getZExtValue();
2076 uint64_t RemovedBitsMask = (1ULL << ShlVal) - 1;
2077 if (Opcode !=
ISD::AND && (Val & RemovedBitsMask) != 0)
2080 unsigned ShlOp, AddOp,
Op;
2100 ShlOp = X86::SHL32ri;
2101 AddOp = X86::ADD32rr;
2105 case ISD::AND: Op = X86::AND32ri8;
break;
2106 case ISD::OR: Op = X86::OR32ri8;
break;
2107 case ISD::XOR: Op = X86::XOR32ri8;
break;
2112 ShlOp = X86::SHL64ri;
2113 AddOp = X86::ADD64rr;
2117 case ISD::AND: Op = CstVT==
MVT::i8? X86::AND64ri8 : X86::AND64ri32;
break;
2118 case ISD::OR: Op = CstVT==
MVT::i8? X86::OR64ri8 : X86::OR64ri32;
break;
2119 case ISD::XOR: Op = CstVT==
MVT::i8? X86::XOR64ri8 : X86::XOR64ri32;
break;
2125 SDValue NewCst = CurDAG->getTargetConstant(Val >> ShlVal, dl, CstVT);
2126 SDNode *New = CurDAG->getMachineNode(Op, dl, NVT, N0->
getOperand(0),NewCst);
2128 CurDAG->SelectNodeTo(Node, AddOp, NVT,
SDValue(New, 0),
2131 CurDAG->SelectNodeTo(Node, ShlOp, NVT,
SDValue(New, 0),
2132 getI8Imm(ShlVal, dl));
2142 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, X86::AL,
2147 SDNode *CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
2149 ReplaceNode(Node, CNode);
2160 case MVT::i8: LoReg = X86::AL; Opc = X86::MUL8r;
break;
2161 case MVT::i16: LoReg = X86::AX; Opc = X86::MUL16r;
break;
2162 case MVT::i32: LoReg = X86::EAX; Opc = X86::MUL32r;
break;
2163 case MVT::i64: LoReg = X86::RAX; Opc = X86::MUL64r;
break;
2166 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, LoReg,
2171 SDNode *CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
2173 ReplaceNode(Node, CNode);
2183 bool hasBMI2 = Subtarget->hasBMI2();
2187 case MVT::i8: Opc = X86::MUL8r; MOpc = X86::MUL8m;
break;
2188 case MVT::i16: Opc = X86::MUL16r; MOpc = X86::MUL16m;
break;
2189 case MVT::i32: Opc = hasBMI2 ? X86::MULX32rr : X86::MUL32r;
2190 MOpc = hasBMI2 ? X86::MULX32rm : X86::MUL32m;
break;
2191 case MVT::i64: Opc = hasBMI2 ? X86::MULX64rr : X86::MUL64r;
2192 MOpc = hasBMI2 ? X86::MULX64rm : X86::MUL64m;
break;
2197 case MVT::i8: Opc = X86::IMUL8r; MOpc = X86::IMUL8m;
break;
2198 case MVT::i16: Opc = X86::IMUL16r; MOpc = X86::IMUL16m;
break;
2199 case MVT::i32: Opc = X86::IMUL32r; MOpc = X86::IMUL32m;
break;
2200 case MVT::i64: Opc = X86::IMUL64r; MOpc = X86::IMUL64m;
break;
2204 unsigned SrcReg, LoReg, HiReg;
2209 SrcReg = LoReg = X86::AL; HiReg = X86::AH;
2213 SrcReg = LoReg = X86::AX; HiReg = X86::DX;
2217 SrcReg = LoReg = X86::EAX; HiReg = X86::EDX;
2221 SrcReg = LoReg = X86::RAX; HiReg = X86::RDX;
2224 SrcReg = X86::EDX; LoReg = HiReg = 0;
2227 SrcReg = X86::RDX; LoReg = HiReg = 0;
2231 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
2232 bool foldedLoad = tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
2235 foldedLoad = tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
2240 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, SrcReg,
2249 if (MOpc == X86::MULX32rm || MOpc == X86::MULX64rm) {
2251 CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
2258 CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
2264 ReplaceUses(N1.
getValue(1), Chain);
2269 MemOp[0] = LoadNode->getMemOperand();
2273 SDValue Ops[] = { N1, InFlag };
2274 if (Opc == X86::MULX32rr || Opc == X86::MULX64rr) {
2276 SDNode *CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
2282 SDNode *CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
2288 if (HiReg == X86::AH && Subtarget->is64Bit() &&
2290 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2295 if (!
SDValue(Node, 0).use_empty())
2297 CurDAG->getTargetExtractSubreg(X86::sub_8bit, dl,
MVT::i8, Result));
2300 Result =
SDValue(CurDAG->getMachineNode(X86::SHR16ri, dl, MVT::i16,
2302 CurDAG->getTargetConstant(8, dl,
MVT::i8)),
2306 CurDAG->getTargetExtractSubreg(X86::sub_8bit, dl,
MVT::i8, Result));
2311 assert(LoReg &&
"Register for low half is not defined!");
2312 ResLo = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, LoReg, NVT,
2316 ReplaceUses(
SDValue(Node, 0), ResLo);
2322 assert(HiReg &&
"Register for high half is not defined!");
2323 ResHi = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, HiReg, NVT,
2327 ReplaceUses(
SDValue(Node, 1), ResHi);
2344 switch (NVT.SimpleTy) {
2346 case MVT::i8: Opc = X86::DIV8r; MOpc = X86::DIV8m;
break;
2347 case MVT::i16: Opc = X86::DIV16r; MOpc = X86::DIV16m;
break;
2348 case MVT::i32: Opc = X86::DIV32r; MOpc = X86::DIV32m;
break;
2349 case MVT::i64: Opc = X86::DIV64r; MOpc = X86::DIV64m;
break;
2352 switch (NVT.SimpleTy) {
2354 case MVT::i8: Opc = X86::IDIV8r; MOpc = X86::IDIV8m;
break;
2355 case MVT::i16: Opc = X86::IDIV16r; MOpc = X86::IDIV16m;
break;
2356 case MVT::i32: Opc = X86::IDIV32r; MOpc = X86::IDIV32m;
break;
2357 case MVT::i64: Opc = X86::IDIV64r; MOpc = X86::IDIV64m;
break;
2361 unsigned LoReg, HiReg, ClrReg;
2362 unsigned SExtOpcode;
2363 switch (NVT.SimpleTy) {
2366 LoReg = X86::AL; ClrReg = HiReg = X86::AH;
2367 SExtOpcode = X86::CBW;
2370 LoReg = X86::AX; HiReg = X86::DX;
2372 SExtOpcode = X86::CWD;
2375 LoReg = X86::EAX; ClrReg = HiReg = X86::EDX;
2376 SExtOpcode = X86::CDQ;
2379 LoReg = X86::RAX; ClrReg = HiReg = X86::RDX;
2380 SExtOpcode = X86::CQO;
2384 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
2385 bool foldedLoad = tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
2386 bool signBitIsZero = CurDAG->SignBitIsZero(N0);
2389 if (NVT ==
MVT::i8 && (!isSigned || signBitIsZero)) {
2392 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Move, Chain;
2393 if (tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
2399 ReplaceUses(N0.
getValue(1), Chain);
2403 Chain = CurDAG->getEntryNode();
2405 Chain = CurDAG->getCopyToReg(Chain, dl, X86::EAX, Move,
SDValue());
2409 CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
2410 LoReg, N0,
SDValue()).getValue(1);
2411 if (isSigned && !signBitIsZero) {
2417 SDValue ClrNode =
SDValue(CurDAG->getMachineNode(X86::MOV32r0, dl, NVT), 0);
2418 switch (NVT.SimpleTy) {
2421 SDValue(CurDAG->getMachineNode(
2422 TargetOpcode::EXTRACT_SUBREG, dl, MVT::i16, ClrNode,
2423 CurDAG->getTargetConstant(X86::sub_16bit, dl,
2431 SDValue(CurDAG->getMachineNode(
2432 TargetOpcode::SUBREG_TO_REG, dl,
MVT::i64,
2433 CurDAG->getTargetConstant(0, dl,
MVT::i64), ClrNode,
2434 CurDAG->getTargetConstant(X86::sub_32bit, dl,
2442 InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ClrReg,
2443 ClrNode, InFlag).getValue(1);
2469 unsigned AHExtOpcode =
2470 isSigned ? X86::MOVSX32_NOREXrr8 : X86::MOVZX32_NOREXrr8;
2472 SDNode *RNode = CurDAG->getMachineNode(AHExtOpcode, dl,
MVT::i32,
2483 "Unexpected i64 sext of h-register");
2485 SDValue(CurDAG->getMachineNode(
2486 TargetOpcode::SUBREG_TO_REG, dl,
MVT::i64,
2487 CurDAG->getTargetConstant(0, dl,
MVT::i64), Result,
2488 CurDAG->getTargetConstant(X86::sub_32bit, dl,
2494 CurDAG->getTargetExtractSubreg(X86::sub_8bit, dl,
MVT::i8, Result);
2496 ReplaceUses(
SDValue(Node, 1), Result);
2497 DEBUG(
dbgs() <<
"=> "; Result.getNode()->dump(CurDAG);
dbgs() <<
'\n');
2501 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2502 LoReg, NVT, InFlag);
2504 ReplaceUses(
SDValue(Node, 0), Result);
2509 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2510 HiReg, NVT, InFlag);
2512 ReplaceUses(
SDValue(Node, 1), Result);
2550 if (!Subtarget->is64Bit()) {
2553 case MVT::i32: TRC = &X86::GR32_ABCDRegClass;
break;
2554 case MVT::i16: TRC = &X86::GR16_ABCDRegClass;
break;
2558 Reg =
SDValue(CurDAG->getMachineNode(X86::COPY_TO_REGCLASS, dl,
2563 SDValue Subreg = CurDAG->getTargetExtractSubreg(X86::sub_8bit, dl,
2567 SDNode *NewNode = CurDAG->getMachineNode(X86::TEST8ri, dl,
MVT::i32,
2588 case MVT::i64: TRC = &X86::GR64_ABCDRegClass;
break;
2589 case MVT::i32: TRC = &X86::GR32_ABCDRegClass;
break;
2590 case MVT::i16: TRC = &X86::GR16_ABCDRegClass;
break;
2594 Reg =
SDValue(CurDAG->getMachineNode(X86::COPY_TO_REGCLASS, dl,
2598 SDValue Subreg = CurDAG->getTargetExtractSubreg(X86::sub_8bit_hi, dl,
2604 SDNode *NewNode = CurDAG->getMachineNode(X86::TEST8ri_NOREX, dl,
2623 SDValue Subreg = CurDAG->getTargetExtractSubreg(X86::sub_16bit, dl,
2627 SDNode *NewNode = CurDAG->getMachineNode(X86::TEST16ri, dl,
MVT::i32,
2637 if ((C->
getZExtValue() & ~UINT64_C(0xffffffff)) == 0 &&
2646 SDValue Subreg = CurDAG->getTargetExtractSubreg(X86::sub_32bit, dl,
2650 SDNode *NewNode = CurDAG->getMachineNode(X86::TEST32ri, dl,
MVT::i32,
2681 unsigned Opc = StoredVal->getOpcode();
2686 LoadNode, InputChain))
2689 SDValue Base, Scale, Index, Disp, Segment;
2690 if (!selectAddr(LoadNode, LoadNode->
getBasePtr(),
2691 Base, Scale, Index, Disp, Segment))
2697 const SDValue Ops[] = { Base, Scale, Index, Disp, Segment, InputChain };
2706 ReplaceUses(
SDValue(StoredVal.getNode(), 1),
SDValue(Result, 0));
2707 CurDAG->RemoveDeadNode(Node);
2715 bool X86DAGToDAGISel::
2716 SelectInlineAsmMemoryOperand(
const SDValue &Op,
unsigned ConstraintID,
2717 std::vector<SDValue> &OutOps) {
2718 SDValue Op0, Op1, Op2, Op3, Op4;
2719 switch (ConstraintID) {
2730 if (!selectAddr(
nullptr, Op, Op0, Op1, Op2, Op3, Op4))
2735 OutOps.push_back(Op0);
2736 OutOps.push_back(Op1);
2737 OutOps.push_back(Op2);
2738 OutOps.push_back(Op3);
2739 OutOps.push_back(Op4);
2747 return new X86DAGToDAGISel(TM, OptLevel);
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
static bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq)
Return true if call address is a load and it can be moved below CALLSEQ_START and the chains leading ...
void push_back(const T &Elt)
APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
SDValue getValue(unsigned R) const
DELETED_NODE - This is an illegal value that is used to catch errors.
STATISTIC(NumFunctions,"Total number of functions")
static void insertDAGNode(SelectionDAG &DAG, SDValue Pos, SDValue N)
bool ult(const APInt &RHS) const
Unsigned less than comparison.
void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd)
Assign this MachineSDNodes's memory reference descriptor list.
bool hasOneUse() const
Return true if there is exactly one use of this node.
bool hasNUsesOfValue(unsigned NUses, unsigned Value) const
Return true if there are exactly NUSES uses of the indicated value.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
unsigned getID() const
Return the register class ID number.
constexpr bool isInt< 8 >(int64_t x)
unsigned getSizeInBits() const
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
unsigned getNumOperands() const
Return the number of values used by this operation.
unsigned getNumOperands() const
const SDValue & getOperand(unsigned Num) const
void setNodeId(int Id)
Set unique node id.
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
const SDValue & getBasePtr() const
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
unsigned getResNo() const
get the index which selects a specific result in the SDNode
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
GlobalBaseReg - On Darwin, this node represents the result of the mflr at function entry...
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
X86 compare and logical compare instructions.
The address of a basic block.
A description of a memory reference used in the backend.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Shift and rotation operations.
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
std::size_t countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
CopyToReg - This node has three operands: a chain, a register number to set to this value...
Reg
All possible values of the reg field in the ModR/M byte.
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.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
This function lowers an abstract call to a function into an actual call.
static bool isLoadIncOrDecStore(StoreSDNode *StoreNode, unsigned Opc, SDValue StoredVal, SelectionDAG *CurDAG, LoadSDNode *&LoadNode, SDValue &InputChain)
Check whether or not the chain ending in StoreNode is suitable for doing the {load; increment or decr...
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Simple integer binary arithmetic operators.
const SDValue & getBasePtr() const
EVT getMemoryVT() const
Return the type of the in-memory value.
This class is used to represent ISD::STORE nodes.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
SDNode * getNode() const
get the SDNode which holds the desired result
Function Alias Analysis false
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
LOCAL_RECOVER - Represents the llvm.localrecover intrinsic.
const SDValue & getOperand(unsigned i) const
static bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, uint64_t Mask, SDValue Shift, SDValue X, X86ISelAddressMode &AM)
bool isNonTemporal() const
bool sge(const APInt &RHS) const
Signed greather or equal comparison.
This is an important base class in LLVM.
bool isVector() const
Return true if this is a vector value type.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static Type * getVoidTy(LLVMContext &C)
This class provides iterator support for SDUse operands that use a specific SDNode.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
void RepositionNode(allnodes_iterator Position, SDNode *N)
Move node N in the AllNodes list to be immediately before the given iterator Position.
unsigned getOpcode() const
FunctionPass class - This class is used to implement most global optimizations.
On Darwin, this node represents the result of the popl at function entry, used for PIC code...
self_iterator getIterator()
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
static bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, uint64_t Mask, SDValue Shift, SDValue X, X86ISelAddressMode &AM)
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
std::vector< ArgListEntry > ArgListTy
This structure contains all information that is necessary for lowering calls.
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc, or post-dec.
This class contains a discriminated union of information about pointers in memory operands...
const MachinePointerInfo & getPointerInfo() const
const SDValue & getOffset() const
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
These operations represent an abstract X86 call instruction, which includes a bunch of information...
TokenFactor - This node takes multiple tokens as input and produces a single token result...
Iterator for intrusive lists based on ilist_node.
constexpr bool isInt< 32 >(int64_t x)
void dump() const
Dump this node, for debugging.
void computeKnownBits(SDValue Op, KnownBits &Known, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
Mutate the specified node in-place to have the specified operands.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
An SDNode that represents everything that will be needed to construct a MachineInstr.
const SDValue & getChain() const
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
Represents one node in the SelectionDAG.
bool use_empty() const
Return true if there are no nodes using value ResNo of Node.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
C - The default llvm calling convention, compatible with C.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
static bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, uint64_t Mask, SDValue Shift, SDValue X, X86ISelAddressMode &AM)
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
int64_t getSExtValue() const
op_iterator op_begin() const
static use_iterator use_end()
ZERO_EXTEND - Used for integer types, zeroing the new bits.
ANY_EXTEND - Used for integer types. The high bits are undefined.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
llvm_unreachable("Unknown RegBank!")
static bool isDispSafeForFrameIndex(int64_t Val)
uint64_t getConstantOperandVal(unsigned i) const
static unsigned getFusedLdStOpcode(EVT &LdVT, unsigned Opc)
Get the appropriate X86 opcode for an in-memory increment or decrement.
Bitwise operators - logical and, logical or, logical xor.
bool hasAnyUseOfValue(unsigned Value) const
Return true if there are any use of the indicated value.
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
A wrapper node for TargetConstantPool, TargetJumpTable, TargetExternalSymbol, TargetGlobalAddress, TargetGlobalTLSAddress, MCSymbol and TargetBlockAddress.
FunctionPass * createX86ISelDag(X86TargetMachine &TM, CodeGenOpt::Level OptLevel)
This pass converts a legalized DAG into a X86-specific DAG, ready for instruction scheduling...
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
void ReplaceAllUsesWith(SDValue From, SDValue Op)
Modify anything using 'From' to use 'To' instead.
bool isOperandOf(const SDNode *N) const
Return true if this node is an operand of N.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
op_iterator op_end() const
const SDValue & getOffset() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isNON_EXTLoad(const SDNode *N)
Returns true if the specified node is a non-extending load.
int getNodeId() const
Return the unique node id.
static bool hasNoSignedComparisonUses(SDNode *N)
Test whether the given X86ISD::CMP node has any uses which require the SF or OF bits to be accurate...
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
EVT getValueType() const
Return the ValueType of the referenced return value.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
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())
MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
Dynamic (non-constant condition) vector blend where only the sign bits of the condition elements are ...
#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.
bool isZeroNode(SDValue Elt)
Returns true if Elt is a constant zero or floating point constant +0.0.
StringRef - Represent a constant reference to a string, i.e.
bool isOffsetSuitableForCodeModel(int64_t Offset, CodeModel::Model M, bool hasSymbolicDisplacement=true)
Returns true of the given offset can be fit into displacement field of the instruction.
APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
TRUNCATE - Completely drop the high bits.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
bool isScalarFPTypeInSSEReg(EVT VT) const
Return true if the specified scalar FP type is computed in an SSE register, not on the X87 floating p...
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
static void moveBelowOrigChain(SelectionDAG *CurDAG, SDValue Load, SDValue Call, SDValue OrigChain)
Replace the original chain operand of the call with load's chain operand and move load below the call...
Carry-using nodes for multiple precision addition and subtraction.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
Special wrapper used under X86-64 PIC mode for RIP relative displacements.
uint64_t getZExtValue() const
bool slt(const APInt &RHS) const
Signed less than comparison.
This class is used to represent ISD::LOAD nodes.