38 #include "llvm/IR/IntrinsicsX86.h" 48 class X86FastISel final :
public FastISel {
65 X86ScalarSSEf64 = Subtarget->hasSSE2();
66 X86ScalarSSEf32 = Subtarget->hasSSE1();
69 bool fastSelectInstruction(
const Instruction *
I)
override;
78 bool fastLowerArguments()
override;
79 bool fastLowerCall(CallLoweringInfo &CLI)
override;
80 bool fastLowerIntrinsicCall(
const IntrinsicInst *II)
override;
82 #include "X86GenFastISel.inc" 85 bool X86FastEmitCompare(
const Value *LHS,
const Value *RHS,
EVT VT,
89 unsigned &ResultReg,
unsigned Alignment = 1);
93 bool X86FastEmitStore(
EVT VT,
unsigned ValReg,
bool ValIsKill,
131 bool X86SelectFPExtOrFPTrunc(
const Instruction *
I,
unsigned Opc,
138 bool X86SelectIntToFP(
const Instruction *
I,
bool IsSigned);
141 return Subtarget->getInstrInfo();
152 unsigned fastMaterializeConstant(
const Constant *
C)
override;
154 unsigned fastMaterializeAlloca(
const AllocaInst *
C)
override;
156 unsigned fastMaterializeFloatZero(
const ConstantFP *CF)
override;
160 bool isScalarFPTypeInSSEReg(
EVT VT)
const {
161 return (VT ==
MVT::f64 && X86ScalarSSEf64) ||
162 (VT ==
MVT::f32 && X86ScalarSSEf32);
165 bool isTypeLegal(
Type *Ty,
MVT &VT,
bool AllowI1 =
false);
167 bool IsMemcpySmall(uint64_t Len);
178 unsigned fastEmitInst_rrrr(
unsigned MachineInstOpcode,
180 bool Op0IsKill,
unsigned Op1,
bool Op1IsKill,
181 unsigned Op2,
bool Op2IsKill,
unsigned Op3,
187 static std::pair<unsigned, bool>
190 bool NeedSwap =
false;
219 return std::make_pair(CC, NeedSwap);
240 if (!isa<ExtractValueInst>(Cond))
243 const auto *EV = cast<ExtractValueInst>(Cond);
244 if (!isa<IntrinsicInst>(EV->getAggregateOperand()))
247 const auto *II = cast<IntrinsicInst>(EV->getAggregateOperand());
251 cast<StructType>(Callee->
getReturnType())->getTypeAtIndex(0U);
252 if (!isTypeLegal(RetTy, RetVT))
259 switch (II->getIntrinsicID()) {
260 default:
return false;
261 case Intrinsic::sadd_with_overflow:
262 case Intrinsic::ssub_with_overflow:
263 case Intrinsic::smul_with_overflow:
264 case Intrinsic::umul_with_overflow: TmpCC =
X86::COND_O;
break;
265 case Intrinsic::uadd_with_overflow:
266 case Intrinsic::usub_with_overflow: TmpCC =
X86::COND_B;
break;
276 for (
auto Itr = std::prev(Start); Itr != End; --Itr) {
279 if (!isa<ExtractValueInst>(Itr))
283 const auto *EVI = cast<ExtractValueInst>(Itr);
284 if (EVI->getAggregateOperand() != II)
292 bool X86FastISel::isTypeLegal(
Type *Ty,
MVT &VT,
bool AllowI1) {
293 EVT evt = TLI.getValueType(DL, Ty,
true);
301 if (VT ==
MVT::f64 && !X86ScalarSSEf64)
303 if (VT ==
MVT::f32 && !X86ScalarSSEf32)
312 return (AllowI1 && VT ==
MVT::i1) || TLI.isTypeLegal(VT);
320 unsigned Alignment) {
321 bool HasSSE41 = Subtarget->hasSSE41();
322 bool HasAVX = Subtarget->hasAVX();
323 bool HasAVX2 = Subtarget->hasAVX2();
324 bool HasAVX512 = Subtarget->hasAVX512();
325 bool HasVLX = Subtarget->hasVLX();
335 default:
return false;
351 Opc = HasAVX512 ? X86::VMOVSSZrm_alt :
352 HasAVX ? X86::VMOVSSrm_alt :
359 Opc = HasAVX512 ? X86::VMOVSDZrm_alt :
360 HasAVX ? X86::VMOVSDrm_alt :
369 if (IsNonTemporal && Alignment >= 16 && HasSSE41)
370 Opc = HasVLX ? X86::VMOVNTDQAZ128rm :
371 HasAVX ? X86::VMOVNTDQArm : X86::MOVNTDQArm;
372 else if (Alignment >= 16)
373 Opc = HasVLX ? X86::VMOVAPSZ128rm :
374 HasAVX ? X86::VMOVAPSrm : X86::MOVAPSrm;
376 Opc = HasVLX ? X86::VMOVUPSZ128rm :
377 HasAVX ? X86::VMOVUPSrm : X86::MOVUPSrm;
380 if (IsNonTemporal && Alignment >= 16 && HasSSE41)
381 Opc = HasVLX ? X86::VMOVNTDQAZ128rm :
382 HasAVX ? X86::VMOVNTDQArm : X86::MOVNTDQArm;
383 else if (Alignment >= 16)
384 Opc = HasVLX ? X86::VMOVAPDZ128rm :
385 HasAVX ? X86::VMOVAPDrm : X86::MOVAPDrm;
387 Opc = HasVLX ? X86::VMOVUPDZ128rm :
388 HasAVX ? X86::VMOVUPDrm : X86::MOVUPDrm;
394 if (IsNonTemporal && Alignment >= 16 && HasSSE41)
395 Opc = HasVLX ? X86::VMOVNTDQAZ128rm :
396 HasAVX ? X86::VMOVNTDQArm : X86::MOVNTDQArm;
397 else if (Alignment >= 16)
398 Opc = HasVLX ? X86::VMOVDQA64Z128rm :
399 HasAVX ? X86::VMOVDQArm : X86::MOVDQArm;
401 Opc = HasVLX ? X86::VMOVDQU64Z128rm :
402 HasAVX ? X86::VMOVDQUrm : X86::MOVDQUrm;
406 if (IsNonTemporal && Alignment >= 32 && HasAVX2)
407 Opc = HasVLX ? X86::VMOVNTDQAZ256rm : X86::VMOVNTDQAYrm;
408 else if (IsNonTemporal && Alignment >= 16)
410 else if (Alignment >= 32)
411 Opc = HasVLX ? X86::VMOVAPSZ256rm : X86::VMOVAPSYrm;
413 Opc = HasVLX ? X86::VMOVUPSZ256rm : X86::VMOVUPSYrm;
417 if (IsNonTemporal && Alignment >= 32 && HasAVX2)
418 Opc = HasVLX ? X86::VMOVNTDQAZ256rm : X86::VMOVNTDQAYrm;
419 else if (IsNonTemporal && Alignment >= 16)
421 else if (Alignment >= 32)
422 Opc = HasVLX ? X86::VMOVAPDZ256rm : X86::VMOVAPDYrm;
424 Opc = HasVLX ? X86::VMOVUPDZ256rm : X86::VMOVUPDYrm;
431 if (IsNonTemporal && Alignment >= 32 && HasAVX2)
432 Opc = HasVLX ? X86::VMOVNTDQAZ256rm : X86::VMOVNTDQAYrm;
433 else if (IsNonTemporal && Alignment >= 16)
435 else if (Alignment >= 32)
436 Opc = HasVLX ? X86::VMOVDQA64Z256rm : X86::VMOVDQAYrm;
438 Opc = HasVLX ? X86::VMOVDQU64Z256rm : X86::VMOVDQUYrm;
442 if (IsNonTemporal && Alignment >= 64)
443 Opc = X86::VMOVNTDQAZrm;
445 Opc = (Alignment >= 64) ? X86::VMOVAPSZrm : X86::VMOVUPSZrm;
449 if (IsNonTemporal && Alignment >= 64)
450 Opc = X86::VMOVNTDQAZrm;
452 Opc = (Alignment >= 64) ? X86::VMOVAPDZrm : X86::VMOVUPDZrm;
461 if (IsNonTemporal && Alignment >= 64)
462 Opc = X86::VMOVNTDQAZrm;
464 Opc = (Alignment >= 64) ? X86::VMOVDQA64Zrm : X86::VMOVDQU64Zrm;
470 ResultReg = createResultReg(RC);
472 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg);
483 bool X86FastISel::X86FastEmitStore(
EVT VT,
unsigned ValReg,
bool ValIsKill,
486 bool HasSSE1 = Subtarget->hasSSE1();
487 bool HasSSE2 = Subtarget->hasSSE2();
488 bool HasSSE4A = Subtarget->hasSSE4A();
489 bool HasAVX = Subtarget->hasAVX();
490 bool HasAVX512 = Subtarget->hasAVX512();
491 bool HasVLX = Subtarget->hasVLX();
498 default:
return false;
501 unsigned AndResult = createResultReg(&X86::GR8RegClass);
502 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
503 TII.get(X86::AND8ri), AndResult)
508 case MVT::i8: Opc = X86::MOV8mr;
break;
509 case MVT::i16: Opc = X86::MOV16mr;
break;
511 Opc = (IsNonTemporal && HasSSE2) ? X86::MOVNTImr : X86::MOV32mr;
515 Opc = (IsNonTemporal && HasSSE2) ? X86::MOVNTI_64mr : X86::MOV64mr;
518 if (X86ScalarSSEf32) {
519 if (IsNonTemporal && HasSSE4A)
522 Opc = HasAVX512 ? X86::VMOVSSZmr :
523 HasAVX ? X86::VMOVSSmr : X86::MOVSSmr;
528 if (X86ScalarSSEf32) {
529 if (IsNonTemporal && HasSSE4A)
532 Opc = HasAVX512 ? X86::VMOVSDZmr :
533 HasAVX ? X86::VMOVSDmr : X86::MOVSDmr;
538 Opc = (IsNonTemporal && HasSSE1) ? X86::MMX_MOVNTQmr : X86::MMX_MOVQ64mr;
543 Opc = HasVLX ? X86::VMOVNTPSZ128mr :
544 HasAVX ? X86::VMOVNTPSmr : X86::MOVNTPSmr;
546 Opc = HasVLX ? X86::VMOVAPSZ128mr :
547 HasAVX ? X86::VMOVAPSmr : X86::MOVAPSmr;
549 Opc = HasVLX ? X86::VMOVUPSZ128mr :
550 HasAVX ? X86::VMOVUPSmr : X86::MOVUPSmr;
555 Opc = HasVLX ? X86::VMOVNTPDZ128mr :
556 HasAVX ? X86::VMOVNTPDmr : X86::MOVNTPDmr;
558 Opc = HasVLX ? X86::VMOVAPDZ128mr :
559 HasAVX ? X86::VMOVAPDmr : X86::MOVAPDmr;
561 Opc = HasVLX ? X86::VMOVUPDZ128mr :
562 HasAVX ? X86::VMOVUPDmr : X86::MOVUPDmr;
570 Opc = HasVLX ? X86::VMOVNTDQZ128mr :
571 HasAVX ? X86::VMOVNTDQmr : X86::MOVNTDQmr;
573 Opc = HasVLX ? X86::VMOVDQA64Z128mr :
574 HasAVX ? X86::VMOVDQAmr : X86::MOVDQAmr;
576 Opc = HasVLX ? X86::VMOVDQU64Z128mr :
577 HasAVX ? X86::VMOVDQUmr : X86::MOVDQUmr;
583 Opc = HasVLX ? X86::VMOVNTPSZ256mr : X86::VMOVNTPSYmr;
585 Opc = HasVLX ? X86::VMOVAPSZ256mr : X86::VMOVAPSYmr;
587 Opc = HasVLX ? X86::VMOVUPSZ256mr : X86::VMOVUPSYmr;
593 Opc = HasVLX ? X86::VMOVNTPDZ256mr : X86::VMOVNTPDYmr;
595 Opc = HasVLX ? X86::VMOVAPDZ256mr : X86::VMOVAPDYmr;
597 Opc = HasVLX ? X86::VMOVUPDZ256mr : X86::VMOVUPDYmr;
606 Opc = HasVLX ? X86::VMOVNTDQZ256mr : X86::VMOVNTDQYmr;
608 Opc = HasVLX ? X86::VMOVDQA64Z256mr : X86::VMOVDQAYmr;
610 Opc = HasVLX ? X86::VMOVDQU64Z256mr : X86::VMOVDQUYmr;
615 Opc = IsNonTemporal ? X86::VMOVNTPSZmr : X86::VMOVAPSZmr;
617 Opc = X86::VMOVUPSZmr;
622 Opc = IsNonTemporal ? X86::VMOVNTPDZmr : X86::VMOVAPDZmr;
624 Opc = X86::VMOVUPDZmr;
634 Opc = IsNonTemporal ? X86::VMOVNTDQZmr : X86::VMOVDQA64Zmr;
636 Opc = X86::VMOVDQU64Zmr;
649 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, Desc);
657 bool X86FastISel::X86FastEmitStore(
EVT VT,
const Value *Val,
661 if (isa<ConstantPointerNull>(Val))
665 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
673 case MVT::i8: Opc = X86::MOV8mi;
break;
674 case MVT::i16: Opc = X86::MOV16mi;
break;
675 case MVT::i32: Opc = X86::MOV32mi;
break;
679 Opc = X86::MOV64mi32;
685 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc));
687 : CI->getZExtValue());
694 unsigned ValReg = getRegForValue(Val);
698 bool ValKill = hasTrivialKill(Val);
699 return X86FastEmitStore(VT, ValReg, ValKill, AM, MMO, Aligned);
706 unsigned Src,
EVT SrcVT,
707 unsigned &ResultReg) {
719 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
725 if (GV->isThreadLocal())
729 if (GV->isAbsoluteSymbolRef())
735 if (!Subtarget->isPICStyleRIPRel() ||
741 unsigned char GVFlags = Subtarget->classifyGlobalReference(GV);
746 AM.
Base.
Reg = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
752 if (Subtarget->isPICStyleRIPRel()) {
766 if (I != LocalValueMap.
end() && I->second != 0) {
778 SavePoint SaveInsertPt = enterLocalValueArea();
780 if (TLI.getPointerTy(DL) ==
MVT::i64) {
782 RC = &X86::GR64RegClass;
784 if (Subtarget->isPICStyleRIPRel())
788 RC = &X86::GR32RegClass;
791 LoadReg = createResultReg(RC);
793 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), LoadReg);
797 leaveLocalValueArea(SaveInsertPt);
800 LocalValueMap[V] = LoadReg;
812 if (!AM.
GV || !Subtarget->isPICStyleRIPRel()) {
814 AM.
Base.
Reg = getRegForValue(V);
832 const User *U =
nullptr;
833 unsigned Opcode = Instruction::UserOp1;
834 if (
const Instruction *I = dyn_cast<Instruction>(V)) {
838 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(V)) ||
839 FuncInfo.MBBMap[I->
getParent()] == FuncInfo.MBB) {
843 }
else if (
const ConstantExpr *
C = dyn_cast<ConstantExpr>(V)) {
849 if (Ty->getAddressSpace() > 255)
856 case Instruction::BitCast:
860 case Instruction::IntToPtr:
863 TLI.getPointerTy(DL))
867 case Instruction::PtrToInt:
869 if (TLI.getValueType(DL, U->
getType()) == TLI.getPointerTy(DL))
873 case Instruction::Alloca: {
877 FuncInfo.StaticAllocaMap.find(A);
878 if (SI != FuncInfo.StaticAllocaMap.end()) {
889 uint64_t Disp = (int32_t)AM.
Disp + (uint64_t)CI->getSExtValue();
899 case Instruction::GetElementPtr: {
903 uint64_t Disp = (int32_t)AM.
Disp;
905 unsigned Scale = AM.
Scale;
910 i !=
e; ++i, ++GTI) {
912 if (
StructType *STy = GTI.getStructTypeOrNull()) {
920 uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
922 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
924 Disp += CI->getSExtValue() * S;
927 if (canFoldAddIntoGEP(U, Op)) {
930 cast<ConstantInt>(cast<AddOperator>(
Op)->getOperand(1));
933 Op = cast<AddOperator>(
Op)->getOperand(0);
937 (!AM.
GV || !Subtarget->isPICStyleRIPRel()) &&
938 (S == 1 || S == 2 || S == 4 || S == 8)) {
941 IndexReg = getRegForGEPIndex(Op).first;
947 goto unsupported_gep;
961 dyn_cast<GetElementPtrInst>(U->
getOperand(0))) {
975 if (handleConstantAddresses(I, AM))
985 return handleConstantAddresses(V, AM);
991 const User *U =
nullptr;
992 unsigned Opcode = Instruction::UserOp1;
1021 InMBB = I->
getParent() == FuncInfo.MBB->getBasicBlock();
1022 }
else if (
const ConstantExpr *
C = dyn_cast<ConstantExpr>(V)) {
1029 case Instruction::BitCast:
1032 return X86SelectCallAddress(U->
getOperand(0), AM);
1035 case Instruction::IntToPtr:
1039 TLI.getPointerTy(DL))
1040 return X86SelectCallAddress(U->
getOperand(0), AM);
1043 case Instruction::PtrToInt:
1045 if (InMBB && TLI.getValueType(DL, U->
getType()) == TLI.getPointerTy(DL))
1046 return X86SelectCallAddress(U->
getOperand(0), AM);
1051 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1057 if (Subtarget->isPICStyleRIPRel() &&
1063 if (GVar->isThreadLocal())
1072 if (Subtarget->isPICStyleRIPRel()) {
1078 AM.
GVOpFlags = Subtarget->classifyLocalReference(
nullptr);
1085 if (!AM.
GV || !Subtarget->isPICStyleRIPRel()) {
1087 AM.
Base.
Reg = getRegForValue(V);
1102 bool X86FastISel::X86SelectStore(
const Instruction *I) {
1110 if (TLI.supportSwiftError()) {
1113 if (
const Argument *
Arg = dyn_cast<Argument>(PtrV)) {
1114 if (
Arg->hasSwiftErrorAttr())
1118 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(PtrV)) {
1119 if (Alloca->isSwiftError())
1128 if (!isTypeLegal(Val->
getType(), VT,
true))
1132 unsigned ABIAlignment = DL.getABITypeAlignment(Val->
getType());
1134 Alignment = ABIAlignment;
1135 bool Aligned = Alignment >= ABIAlignment;
1141 return X86FastEmitStore(VT, Val, AM, createMachineMemOperandFor(I), Aligned);
1145 bool X86FastISel::X86SelectRet(
const Instruction *I) {
1151 if (!FuncInfo.CanLowerReturn)
1154 if (TLI.supportSwiftError() &&
1155 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError))
1158 if (TLI.supportSplitCSR(FuncInfo.MF))
1191 GetReturnInfo(CC, F.getReturnType(), F.getAttributes(), Outs, TLI, DL);
1199 unsigned Reg = getRegForValue(RV);
1204 if (ValLocs.size() != 1)
1221 unsigned SrcReg = Reg + VA.
getValNo();
1222 EVT SrcVT = TLI.getValueType(DL, RV->
getType());
1225 if (SrcVT != DstVT) {
1229 if (!Outs[0].Flags.isZExt() && !Outs[0].Flags.isSExt())
1235 if (Outs[0].Flags.isSExt())
1237 SrcReg = fastEmitZExtFromI1(
MVT::i8, SrcReg,
false);
1252 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1253 TII.get(TargetOpcode::COPY), DstReg).addReg(SrcReg);
1269 "SRetReturnReg should have been set in LowerFormalArguments()!");
1270 unsigned RetReg = Subtarget->isTarget64BitLP64() ? X86::RAX :
X86::EAX;
1271 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1272 TII.get(TargetOpcode::COPY), RetReg).addReg(Reg);
1279 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1280 TII.get(Subtarget->is64Bit() ? X86::RETIQ : X86::RETIL))
1283 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1284 TII.get(Subtarget->is64Bit() ? X86::RETQ : X86::RETL));
1286 for (
unsigned i = 0,
e = RetRegs.
size(); i !=
e; ++i)
1293 bool X86FastISel::X86SelectLoad(
const Instruction *I) {
1301 if (TLI.supportSwiftError()) {
1304 if (
const Argument *
Arg = dyn_cast<Argument>(SV)) {
1305 if (
Arg->hasSwiftErrorAttr())
1309 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(SV)) {
1310 if (Alloca->isSwiftError())
1316 if (!isTypeLegal(LI->
getType(), VT,
true))
1326 unsigned ABIAlignment = DL.getABITypeAlignment(LI->
getType());
1328 Alignment = ABIAlignment;
1330 unsigned ResultReg = 0;
1331 if (!X86FastEmitLoad(VT, AM, createMachineMemOperandFor(LI), ResultReg,
1335 updateValueMap(I, ResultReg);
1340 bool HasAVX512 = Subtarget->
hasAVX512();
1341 bool HasAVX = Subtarget->
hasAVX();
1342 bool X86ScalarSSEf32 = Subtarget->
hasSSE1();
1343 bool X86ScalarSSEf64 = Subtarget->
hasSSE2();
1347 case MVT::i8:
return X86::CMP8rr;
1348 case MVT::i16:
return X86::CMP16rr;
1349 case MVT::i32:
return X86::CMP32rr;
1350 case MVT::i64:
return X86::CMP64rr;
1352 return X86ScalarSSEf32
1353 ? (HasAVX512 ? X86::VUCOMISSZrr
1354 : HasAVX ? X86::VUCOMISSrr : X86::UCOMISSrr)
1357 return X86ScalarSSEf64
1358 ? (HasAVX512 ? X86::VUCOMISDZrr
1359 : HasAVX ? X86::VUCOMISDrr : X86::UCOMISDrr)
1376 return X86::CMP16ri8;
1377 return X86::CMP16ri;
1380 return X86::CMP32ri8;
1381 return X86::CMP32ri;
1384 return X86::CMP64ri8;
1388 return X86::CMP64ri32;
1393 bool X86FastISel::X86FastEmitCompare(
const Value *Op0,
const Value *Op1,
EVT VT,
1395 unsigned Op0Reg = getRegForValue(Op0);
1396 if (Op0Reg == 0)
return false;
1399 if (isa<ConstantPointerNull>(Op1))
1405 if (
const ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
1407 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, CurDbgLoc,
TII.get(CompareImmOpc))
1409 .
addImm(Op1C->getSExtValue());
1415 if (CompareOpc == 0)
return false;
1417 unsigned Op1Reg = getRegForValue(Op1);
1418 if (Op1Reg == 0)
return false;
1419 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, CurDbgLoc,
TII.get(CompareOpc))
1426 bool X86FastISel::X86SelectCmp(
const Instruction *I) {
1427 const CmpInst *CI = cast<CmpInst>(
I);
1435 unsigned ResultReg = 0;
1436 switch (Predicate) {
1439 ResultReg = createResultReg(&X86::GR32RegClass);
1440 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOV32r0),
1442 ResultReg = fastEmitInst_extractsubreg(
MVT::i8, ResultReg,
true,
1449 ResultReg = createResultReg(&X86::GR8RegClass);
1450 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOV8ri),
1451 ResultReg).addImm(1);
1457 updateValueMap(I, ResultReg);
1469 if (RHSC && RHSC->isNullValue())
1474 static const uint16_t SETFOpcTable[2][3] = {
1479 switch (Predicate) {
1485 ResultReg = createResultReg(&X86::GR8RegClass);
1487 if (!X86FastEmitCompare(LHS, RHS, VT, I->
getDebugLoc()))
1490 unsigned FlagReg1 = createResultReg(&X86::GR8RegClass);
1491 unsigned FlagReg2 = createResultReg(&X86::GR8RegClass);
1492 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::SETCCr),
1493 FlagReg1).addImm(SETFOpc[0]);
1494 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::SETCCr),
1495 FlagReg2).addImm(SETFOpc[1]);
1496 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(SETFOpc[2]),
1497 ResultReg).addReg(FlagReg1).
addReg(FlagReg2);
1498 updateValueMap(I, ResultReg);
1511 if (!X86FastEmitCompare(LHS, RHS, VT, I->
getDebugLoc()))
1514 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::SETCCr),
1515 ResultReg).addImm(CC);
1516 updateValueMap(I, ResultReg);
1520 bool X86FastISel::X86SelectZExt(
const Instruction *I) {
1521 EVT DstVT = TLI.getValueType(DL, I->
getType());
1522 if (!TLI.isTypeLegal(DstVT))
1525 unsigned ResultReg = getRegForValue(I->
getOperand(0));
1533 ResultReg = fastEmitZExtFromI1(
MVT::i8, ResultReg,
false);
1545 case MVT::i8: MovInst = X86::MOVZX32rr8;
break;
1546 case MVT::i16: MovInst = X86::MOVZX32rr16;
break;
1547 case MVT::i32: MovInst = X86::MOV32rr;
break;
1551 unsigned Result32 = createResultReg(&X86::GR32RegClass);
1552 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(MovInst), Result32)
1555 ResultReg = createResultReg(&X86::GR64RegClass);
1556 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpcode::SUBREG_TO_REG),
1562 unsigned Result32 = createResultReg(&X86::GR32RegClass);
1563 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOVZX32rr8),
1564 Result32).addReg(ResultReg);
1566 ResultReg = fastEmitInst_extractsubreg(
MVT::i16, Result32,
true,
1568 }
else if (DstVT !=
MVT::i8) {
1575 updateValueMap(I, ResultReg);
1579 bool X86FastISel::X86SelectSExt(
const Instruction *I) {
1580 EVT DstVT = TLI.getValueType(DL, I->
getType());
1581 if (!TLI.isTypeLegal(DstVT))
1584 unsigned ResultReg = getRegForValue(I->
getOperand(0));
1592 unsigned ZExtReg = fastEmitZExtFromI1(
MVT::i8, ResultReg,
1598 ResultReg = createResultReg(&X86::GR8RegClass);
1599 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::NEG8r),
1600 ResultReg).addReg(ZExtReg);
1608 unsigned Result32 = createResultReg(&X86::GR32RegClass);
1609 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOVSX32rr8),
1610 Result32).addReg(ResultReg);
1612 ResultReg = fastEmitInst_extractsubreg(
MVT::i16, Result32,
true,
1614 }
else if (DstVT !=
MVT::i8) {
1621 updateValueMap(I, ResultReg);
1625 bool X86FastISel::X86SelectBranch(
const Instruction *I) {
1637 if (CI->hasOneUse() && CI->getParent() == I->
getParent()) {
1638 EVT VT = TLI.getValueType(DL, CI->getOperand(0)->getType());
1642 switch (Predicate) {
1648 const Value *CmpLHS = CI->getOperand(0);
1649 const Value *CmpRHS = CI->getOperand(1);
1657 if (CmpRHSC && CmpRHSC->isNullValue())
1662 if (FuncInfo.MBB->isLayoutSuccessor(TrueMBB)) {
1672 bool NeedExtraBranch =
false;
1673 switch (Predicate) {
1679 NeedExtraBranch =
true;
1692 if (!X86FastEmitCompare(CmpLHS, CmpRHS, VT, CI->getDebugLoc()))
1695 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::JCC_1))
1696 .addMBB(TrueMBB).
addImm(CC);
1700 if (NeedExtraBranch) {
1701 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::JCC_1))
1705 finishCondBranch(BI->
getParent(), TrueMBB, FalseMBB);
1712 if (TI->hasOneUse() && TI->getParent() == I->
getParent() &&
1713 isTypeLegal(TI->getOperand(0)->getType(), SourceVT)) {
1714 unsigned TestOpc = 0;
1717 case MVT::i8: TestOpc = X86::TEST8ri;
break;
1718 case MVT::i16: TestOpc = X86::TEST16ri;
break;
1719 case MVT::i32: TestOpc = X86::TEST32ri;
break;
1720 case MVT::i64: TestOpc = X86::TEST64ri32;
break;
1723 unsigned OpReg = getRegForValue(TI->getOperand(0));
1724 if (OpReg == 0)
return false;
1726 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TestOpc))
1727 .addReg(OpReg).
addImm(1);
1730 if (FuncInfo.MBB->isLayoutSuccessor(TrueMBB)) {
1735 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::JCC_1))
1736 .addMBB(TrueMBB).
addImm(JmpCond);
1738 finishCondBranch(BI->
getParent(), TrueMBB, FalseMBB);
1742 }
else if (foldX86XALUIntrinsic(CC, BI, BI->
getCondition())) {
1749 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::JCC_1))
1750 .addMBB(TrueMBB).
addImm(CC);
1751 finishCondBranch(BI->
getParent(), TrueMBB, FalseMBB);
1759 if (OpReg == 0)
return false;
1762 if (
MRI.getRegClass(OpReg) == &X86::VK1RegClass) {
1763 unsigned KOpReg = OpReg;
1764 OpReg = createResultReg(&X86::GR32RegClass);
1765 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1766 TII.get(TargetOpcode::COPY), OpReg)
1768 OpReg = fastEmitInst_extractsubreg(
MVT::i8, OpReg,
true,
1771 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::TEST8ri))
1774 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::JCC_1))
1776 finishCondBranch(BI->
getParent(), TrueMBB, FalseMBB);
1780 bool X86FastISel::X86SelectShift(
const Instruction *I) {
1781 unsigned CReg = 0, OpReg = 0;
1785 RC = &X86::GR8RegClass;
1787 case Instruction::LShr: OpReg = X86::SHR8rCL;
break;
1788 case Instruction::AShr: OpReg = X86::SAR8rCL;
break;
1789 case Instruction::Shl: OpReg = X86::SHL8rCL;
break;
1790 default:
return false;
1794 RC = &X86::GR16RegClass;
1797 case Instruction::LShr: OpReg = X86::SHR16rCL;
break;
1798 case Instruction::AShr: OpReg = X86::SAR16rCL;
break;
1799 case Instruction::Shl: OpReg = X86::SHL16rCL;
break;
1803 RC = &X86::GR32RegClass;
1806 case Instruction::LShr: OpReg = X86::SHR32rCL;
break;
1807 case Instruction::AShr: OpReg = X86::SAR32rCL;
break;
1808 case Instruction::Shl: OpReg = X86::SHL32rCL;
break;
1812 RC = &X86::GR64RegClass;
1815 case Instruction::LShr: OpReg = X86::SHR64rCL;
break;
1816 case Instruction::AShr: OpReg = X86::SAR64rCL;
break;
1817 case Instruction::Shl: OpReg = X86::SHL64rCL;
break;
1824 if (!isTypeLegal(I->
getType(), VT))
1827 unsigned Op0Reg = getRegForValue(I->
getOperand(0));
1828 if (Op0Reg == 0)
return false;
1830 unsigned Op1Reg = getRegForValue(I->
getOperand(1));
1831 if (Op1Reg == 0)
return false;
1832 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpcode::COPY),
1833 CReg).addReg(Op1Reg);
1837 if (CReg != X86::CL)
1838 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1842 unsigned ResultReg = createResultReg(RC);
1843 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(OpReg), ResultReg)
1845 updateValueMap(I, ResultReg);
1849 bool X86FastISel::X86SelectDivRem(
const Instruction *I) {
1850 const static unsigned NumTypes = 4;
1851 const static unsigned NumOps = 4;
1852 const static bool S =
true;
1853 const static bool U =
false;
1854 const static unsigned Copy = TargetOpcode::COPY;
1864 const static struct DivRemEntry {
1870 struct DivRemResult {
1872 unsigned OpSignExtend;
1876 unsigned DivRemResultReg;
1878 } ResultTable[NumOps];
1879 } OpTable[NumTypes] = {
1880 { &X86::GR8RegClass, X86::AX, 0, {
1881 { X86::IDIV8r, 0, X86::MOVSX16rr8,
X86::AL, S },
1882 { X86::IDIV8r, 0, X86::MOVSX16rr8, X86::AH, S },
1883 { X86::DIV8r, 0, X86::MOVZX16rr8,
X86::AL, U },
1884 { X86::DIV8r, 0, X86::MOVZX16rr8, X86::AH, U },
1887 { &X86::GR16RegClass, X86::AX, X86::DX, {
1888 { X86::IDIV16r, X86::CWD, Copy, X86::AX, S },
1889 { X86::IDIV16r, X86::CWD, Copy, X86::DX, S },
1890 { X86::DIV16r, X86::MOV32r0, Copy, X86::AX, U },
1891 { X86::DIV16r, X86::MOV32r0, Copy, X86::DX, U },
1895 { X86::IDIV32r, X86::CDQ, Copy,
X86::EAX, S },
1896 { X86::IDIV32r, X86::CDQ, Copy,
X86::EDX, S },
1897 { X86::DIV32r, X86::MOV32r0, Copy,
X86::EAX, U },
1898 { X86::DIV32r, X86::MOV32r0, Copy,
X86::EDX, U },
1901 { &X86::GR64RegClass, X86::RAX, X86::RDX, {
1902 { X86::IDIV64r, X86::CQO, Copy, X86::RAX, S },
1903 { X86::IDIV64r, X86::CQO, Copy, X86::RDX, S },
1904 { X86::DIV64r, X86::MOV32r0, Copy, X86::RAX, U },
1905 { X86::DIV64r, X86::MOV32r0, Copy, X86::RDX, U },
1911 if (!isTypeLegal(I->
getType(), VT))
1914 unsigned TypeIndex, OpIndex;
1916 default:
return false;
1917 case MVT::i8: TypeIndex = 0;
break;
1918 case MVT::i16: TypeIndex = 1;
break;
1919 case MVT::i32: TypeIndex = 2;
break;
1921 if (!Subtarget->is64Bit())
1928 case Instruction::SDiv: OpIndex = 0;
break;
1929 case Instruction::SRem: OpIndex = 1;
break;
1930 case Instruction::UDiv: OpIndex = 2;
break;
1931 case Instruction::URem: OpIndex = 3;
break;
1934 const DivRemEntry &TypeEntry = OpTable[TypeIndex];
1935 const DivRemEntry::DivRemResult &OpEntry = TypeEntry.ResultTable[OpIndex];
1936 unsigned Op0Reg = getRegForValue(I->
getOperand(0));
1939 unsigned Op1Reg = getRegForValue(I->
getOperand(1));
1944 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1945 TII.get(OpEntry.OpCopy), TypeEntry.LowInReg).addReg(Op0Reg);
1947 if (OpEntry.OpSignExtend) {
1948 if (OpEntry.IsOpSigned)
1949 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1950 TII.get(OpEntry.OpSignExtend));
1952 unsigned Zero32 = createResultReg(&X86::GR32RegClass);
1953 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1954 TII.get(X86::MOV32r0), Zero32);
1960 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1961 TII.get(Copy), TypeEntry.HighInReg)
1962 .addReg(Zero32, 0, X86::sub_16bit);
1964 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1965 TII.get(Copy), TypeEntry.HighInReg)
1968 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1969 TII.get(TargetOpcode::SUBREG_TO_REG), TypeEntry.HighInReg)
1975 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1976 TII.get(OpEntry.OpDivRem)).addReg(Op1Reg);
1985 unsigned ResultReg = 0;
1986 if ((I->
getOpcode() == Instruction::SRem ||
1988 OpEntry.DivRemResultReg == X86::AH && Subtarget->is64Bit()) {
1989 unsigned SourceSuperReg = createResultReg(&X86::GR16RegClass);
1990 unsigned ResultSuperReg = createResultReg(&X86::GR16RegClass);
1991 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1992 TII.get(Copy), SourceSuperReg).addReg(X86::AX);
1995 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::SHR16ri),
1996 ResultSuperReg).addReg(SourceSuperReg).
addImm(8);
1999 ResultReg = fastEmitInst_extractsubreg(
MVT::i8, ResultSuperReg,
2000 true, X86::sub_8bit);
2004 ResultReg = createResultReg(TypeEntry.RC);
2005 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Copy), ResultReg)
2006 .addReg(OpEntry.DivRemResultReg);
2008 updateValueMap(I, ResultReg);
2015 bool X86FastISel::X86FastEmitCMoveSelect(
MVT RetVT,
const Instruction *I) {
2017 if (!Subtarget->hasCMov())
2021 if (RetVT < MVT::i16 || RetVT >
MVT::i64)
2026 bool NeedTest =
true;
2033 if (CI && (CI->getParent() == I->
getParent())) {
2037 static const uint16_t SETFOpcTable[2][3] = {
2042 switch (Predicate) {
2045 SETFOpc = &SETFOpcTable[0][0];
2049 SETFOpc = &SETFOpcTable[1][0];
2058 const Value *CmpLHS = CI->getOperand(0);
2059 const Value *CmpRHS = CI->getOperand(1);
2063 EVT CmpVT = TLI.getValueType(DL, CmpLHS->
getType());
2065 if (!X86FastEmitCompare(CmpLHS, CmpRHS, CmpVT, CI->getDebugLoc()))
2069 unsigned FlagReg1 = createResultReg(&X86::GR8RegClass);
2070 unsigned FlagReg2 = createResultReg(&X86::GR8RegClass);
2071 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::SETCCr),
2072 FlagReg1).addImm(SETFOpc[0]);
2073 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::SETCCr),
2074 FlagReg2).addImm(SETFOpc[1]);
2075 auto const &II =
TII.get(SETFOpc[2]);
2076 if (II.getNumDefs()) {
2077 unsigned TmpReg = createResultReg(&X86::GR8RegClass);
2078 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, TmpReg)
2081 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
2086 }
else if (foldX86XALUIntrinsic(CC, I, Cond)) {
2089 unsigned TmpReg = getRegForValue(Cond);
2102 unsigned CondReg = getRegForValue(Cond);
2105 bool CondIsKill = hasTrivialKill(Cond);
2108 if (
MRI.getRegClass(CondReg) == &X86::VK1RegClass) {
2109 unsigned KCondReg = CondReg;
2110 CondReg = createResultReg(&X86::GR32RegClass);
2111 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2112 TII.get(TargetOpcode::COPY), CondReg)
2114 CondReg = fastEmitInst_extractsubreg(
MVT::i8, CondReg,
true,
2117 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::TEST8ri))
2125 unsigned RHSReg = getRegForValue(RHS);
2126 bool RHSIsKill = hasTrivialKill(RHS);
2128 unsigned LHSReg = getRegForValue(LHS);
2129 bool LHSIsKill = hasTrivialKill(LHS);
2131 if (!LHSReg || !RHSReg)
2136 unsigned ResultReg = fastEmitInst_rri(Opc, RC, RHSReg, RHSIsKill,
2137 LHSReg, LHSIsKill, CC);
2138 updateValueMap(I, ResultReg);
2147 bool X86FastISel::X86FastEmitSSESelect(
MVT RetVT,
const Instruction *I) {
2152 if (!CI || (CI->getParent() != I->
getParent()))
2155 if (I->
getType() != CI->getOperand(0)->getType() ||
2156 !((Subtarget->hasSSE1() && RetVT ==
MVT::f32) ||
2157 (Subtarget->hasSSE2() && RetVT ==
MVT::f64)))
2160 const Value *CmpLHS = CI->getOperand(0);
2161 const Value *CmpRHS = CI->getOperand(1);
2169 if (CmpRHSC && CmpRHSC->isNullValue())
2176 if (CC > 7 && !Subtarget->hasAVX())
2185 unsigned LHSReg = getRegForValue(LHS);
2186 bool LHSIsKill = hasTrivialKill(LHS);
2188 unsigned RHSReg = getRegForValue(RHS);
2189 bool RHSIsKill = hasTrivialKill(RHS);
2191 unsigned CmpLHSReg = getRegForValue(CmpLHS);
2192 bool CmpLHSIsKill = hasTrivialKill(CmpLHS);
2194 unsigned CmpRHSReg = getRegForValue(CmpRHS);
2195 bool CmpRHSIsKill = hasTrivialKill(CmpRHS);
2197 if (!LHSReg || !RHSReg || !CmpLHS || !CmpRHS)
2203 if (Subtarget->hasAVX512()) {
2208 unsigned CmpOpcode =
2209 (RetVT ==
MVT::f32) ? X86::VCMPSSZrr : X86::VCMPSDZrr;
2210 unsigned CmpReg = fastEmitInst_rri(CmpOpcode, VK1, CmpLHSReg, CmpLHSIsKill,
2211 CmpRHSReg, CmpRHSIsKill, CC);
2215 unsigned ImplicitDefReg = createResultReg(VR128X);
2216 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2217 TII.get(TargetOpcode::IMPLICIT_DEF), ImplicitDefReg);
2221 unsigned MovOpcode =
2222 (RetVT ==
MVT::f32) ? X86::VMOVSSZrrk : X86::VMOVSDZrrk;
2223 unsigned MovReg = fastEmitInst_rrrr(MovOpcode, VR128X, RHSReg, RHSIsKill,
2224 CmpReg,
true, ImplicitDefReg,
true,
2227 ResultReg = createResultReg(RC);
2228 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2229 TII.get(TargetOpcode::COPY), ResultReg).addReg(MovReg);
2231 }
else if (Subtarget->hasAVX()) {
2239 unsigned CmpOpcode =
2240 (RetVT ==
MVT::f32) ? X86::VCMPSSrr : X86::VCMPSDrr;
2241 unsigned BlendOpcode =
2242 (RetVT ==
MVT::f32) ? X86::VBLENDVPSrr : X86::VBLENDVPDrr;
2244 unsigned CmpReg = fastEmitInst_rri(CmpOpcode, RC, CmpLHSReg, CmpLHSIsKill,
2245 CmpRHSReg, CmpRHSIsKill, CC);
2246 unsigned VBlendReg = fastEmitInst_rrr(BlendOpcode, VR128, RHSReg, RHSIsKill,
2247 LHSReg, LHSIsKill, CmpReg,
true);
2248 ResultReg = createResultReg(RC);
2249 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2250 TII.get(TargetOpcode::COPY), ResultReg).addReg(VBlendReg);
2253 static const uint16_t OpcTable[2][4] = {
2254 { X86::CMPSSrr, X86::ANDPSrr, X86::ANDNPSrr, X86::ORPSrr },
2255 { X86::CMPSDrr, X86::ANDPDrr, X86::ANDNPDrr, X86::ORPDrr }
2260 default:
return false;
2261 case MVT::f32: Opc = &OpcTable[0][0];
break;
2262 case MVT::f64: Opc = &OpcTable[1][0];
break;
2266 unsigned CmpReg = fastEmitInst_rri(Opc[0], RC, CmpLHSReg, CmpLHSIsKill,
2267 CmpRHSReg, CmpRHSIsKill, CC);
2268 unsigned AndReg = fastEmitInst_rr(Opc[1], VR128, CmpReg,
false,
2270 unsigned AndNReg = fastEmitInst_rr(Opc[2], VR128, CmpReg,
true,
2272 unsigned OrReg = fastEmitInst_rr(Opc[3], VR128, AndNReg,
true,
2274 ResultReg = createResultReg(RC);
2275 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2276 TII.get(TargetOpcode::COPY), ResultReg).addReg(OrReg);
2278 updateValueMap(I, ResultReg);
2282 bool X86FastISel::X86FastEmitPseudoSelect(
MVT RetVT,
const Instruction *I) {
2287 default:
return false;
2288 case MVT::i8: Opc = X86::CMOV_GR8;
break;
2289 case MVT::i16: Opc = X86::CMOV_GR16;
break;
2290 case MVT::i32: Opc = X86::CMOV_GR32;
break;
2291 case MVT::f32: Opc = Subtarget->hasAVX512() ? X86::CMOV_FR32X
2292 : X86::CMOV_FR32;
break;
2293 case MVT::f64: Opc = Subtarget->hasAVX512() ? X86::CMOV_FR64X
2294 : X86::CMOV_FR64;
break;
2304 if (CI && (CI->getParent() == I->
getParent())) {
2310 const Value *CmpLHS = CI->getOperand(0);
2311 const Value *CmpRHS = CI->getOperand(1);
2316 EVT CmpVT = TLI.getValueType(DL, CmpLHS->
getType());
2317 if (!X86FastEmitCompare(CmpLHS, CmpRHS, CmpVT, CI->getDebugLoc()))
2320 unsigned CondReg = getRegForValue(Cond);
2323 bool CondIsKill = hasTrivialKill(Cond);
2326 if (
MRI.getRegClass(CondReg) == &X86::VK1RegClass) {
2327 unsigned KCondReg = CondReg;
2328 CondReg = createResultReg(&X86::GR32RegClass);
2329 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2330 TII.get(TargetOpcode::COPY), CondReg)
2332 CondReg = fastEmitInst_extractsubreg(
MVT::i8, CondReg,
true,
2335 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::TEST8ri))
2343 unsigned LHSReg = getRegForValue(LHS);
2344 bool LHSIsKill = hasTrivialKill(LHS);
2346 unsigned RHSReg = getRegForValue(RHS);
2347 bool RHSIsKill = hasTrivialKill(RHS);
2349 if (!LHSReg || !RHSReg)
2354 unsigned ResultReg =
2355 fastEmitInst_rri(Opc, RC, RHSReg, RHSIsKill, LHSReg, LHSIsKill, CC);
2356 updateValueMap(I, ResultReg);
2360 bool X86FastISel::X86SelectSelect(
const Instruction *I) {
2362 if (!isTypeLegal(I->
getType(), RetVT))
2366 if (
const auto *CI = dyn_cast<CmpInst>(I->
getOperand(0))) {
2368 const Value *Opnd =
nullptr;
2369 switch (Predicate) {
2376 unsigned OpReg = getRegForValue(Opnd);
2379 bool OpIsKill = hasTrivialKill(Opnd);
2381 unsigned ResultReg = createResultReg(RC);
2382 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2383 TII.get(TargetOpcode::COPY), ResultReg)
2385 updateValueMap(I, ResultReg);
2391 if (X86FastEmitCMoveSelect(RetVT, I))
2395 if (X86FastEmitSSESelect(RetVT, I))
2400 if (X86FastEmitPseudoSelect(RetVT, I))
2407 bool X86FastISel::X86SelectIntToFP(
const Instruction *I,
bool IsSigned) {
2412 bool HasAVX512 = Subtarget->hasAVX512();
2413 if (!Subtarget->hasAVX() || (!IsSigned && !HasAVX512))
2422 unsigned OpReg = getRegForValue(I->
getOperand(0));
2428 static const uint16_t SCvtOpc[2][2][2] = {
2429 { { X86::VCVTSI2SSrr, X86::VCVTSI642SSrr },
2430 { X86::VCVTSI2SDrr, X86::VCVTSI642SDrr } },
2431 { { X86::VCVTSI2SSZrr, X86::VCVTSI642SSZrr },
2432 { X86::VCVTSI2SDZrr, X86::VCVTSI642SDZrr } },
2434 static const uint16_t UCvtOpc[2][2] = {
2435 { X86::VCVTUSI2SSZrr, X86::VCVTUSI642SSZrr },
2436 { X86::VCVTUSI2SDZrr, X86::VCVTUSI642SDZrr },
2442 Opcode = IsSigned ? SCvtOpc[HasAVX512][1][Is64Bit] : UCvtOpc[1][Is64Bit];
2445 Opcode = IsSigned ? SCvtOpc[HasAVX512][0][Is64Bit] : UCvtOpc[0][Is64Bit];
2449 MVT DstVT = TLI.getValueType(DL, I->
getType()).getSimpleVT();
2451 unsigned ImplicitDefReg = createResultReg(RC);
2452 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2453 TII.get(TargetOpcode::IMPLICIT_DEF), ImplicitDefReg);
2454 unsigned ResultReg =
2455 fastEmitInst_rr(Opcode, RC, ImplicitDefReg,
true, OpReg,
false);
2456 updateValueMap(I, ResultReg);
2460 bool X86FastISel::X86SelectSIToFP(
const Instruction *I) {
2461 return X86SelectIntToFP(I,
true);
2464 bool X86FastISel::X86SelectUIToFP(
const Instruction *I) {
2465 return X86SelectIntToFP(I,
false);
2469 bool X86FastISel::X86SelectFPExtOrFPTrunc(
const Instruction *I,
2473 I->
getOpcode() == Instruction::FPTrunc) &&
2474 "Instruction must be an FPExt or FPTrunc!");
2475 bool HasAVX = Subtarget->hasAVX();
2477 unsigned OpReg = getRegForValue(I->
getOperand(0));
2481 unsigned ImplicitDefReg;
2483 ImplicitDefReg = createResultReg(RC);
2484 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2485 TII.get(TargetOpcode::IMPLICIT_DEF), ImplicitDefReg);
2489 unsigned ResultReg = createResultReg(RC);
2491 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpc),
2495 MIB.
addReg(ImplicitDefReg);
2498 updateValueMap(I, ResultReg);
2502 bool X86FastISel::X86SelectFPExt(
const Instruction *I) {
2505 bool HasAVX512 = Subtarget->hasAVX512();
2508 HasAVX512 ? X86::VCVTSS2SDZrr
2509 : Subtarget->hasAVX() ? X86::VCVTSS2SDrr : X86::CVTSS2SDrr;
2510 return X86SelectFPExtOrFPTrunc(I, Opc, TLI.getRegClassFor(
MVT::f64));
2516 bool X86FastISel::X86SelectFPTrunc(
const Instruction *I) {
2519 bool HasAVX512 = Subtarget->hasAVX512();
2522 HasAVX512 ? X86::VCVTSD2SSZrr
2523 : Subtarget->hasAVX() ? X86::VCVTSD2SSrr : X86::CVTSD2SSrr;
2524 return X86SelectFPExtOrFPTrunc(I, Opc, TLI.getRegClassFor(
MVT::f32));
2530 bool X86FastISel::X86SelectTrunc(
const Instruction *I) {
2532 EVT DstVT = TLI.getValueType(DL, I->
getType());
2537 if (!TLI.isTypeLegal(SrcVT))
2540 unsigned InputReg = getRegForValue(I->
getOperand(0));
2547 updateValueMap(I, InputReg);
2552 unsigned ResultReg = fastEmitInst_extractsubreg(
MVT::i8,
2558 updateValueMap(I, ResultReg);
2562 bool X86FastISel::IsMemcpySmall(uint64_t Len) {
2563 return Len <= (Subtarget->is64Bit() ? 32 : 16);
2570 if (!IsMemcpySmall(Len))
2573 bool i64Legal = Subtarget->is64Bit();
2578 if (Len >= 8 && i64Legal)
2588 bool RV = X86FastEmitLoad(VT, SrcAM,
nullptr, Reg);
2589 RV &= X86FastEmitStore(VT, Reg,
true, DestAM);
2590 assert(RV &&
"Failed to emit load or store??");
2601 bool X86FastISel::fastLowerIntrinsicCall(
const IntrinsicInst *II) {
2604 default:
return false;
2605 case Intrinsic::convert_from_fp16:
2606 case Intrinsic::convert_to_fp16: {
2607 if (Subtarget->useSoftFloat() || !Subtarget->hasF16C())
2611 unsigned InputReg = getRegForValue(Op);
2616 bool IsFloatToHalf = II->
getIntrinsicID() == Intrinsic::convert_to_fp16;
2617 if (IsFloatToHalf) {
2625 unsigned ResultReg = 0;
2627 if (IsFloatToHalf) {
2635 InputReg = fastEmitInst_ri(X86::VCVTPS2PHrr, RC, InputReg,
false, 4);
2638 ResultReg = createResultReg(&X86::GR32RegClass);
2639 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2640 TII.get(X86::VMOVPDI2DIrr), ResultReg)
2644 unsigned RegIdx = X86::sub_16bit;
2645 ResultReg = fastEmitInst_extractsubreg(
MVT::i16, ResultReg,
true, RegIdx);
2656 InputReg = fastEmitInst_r(X86::VCVTPH2PSrr, RC, InputReg,
true);
2660 ResultReg = createResultReg(&X86::FR32RegClass);
2661 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2662 TII.get(TargetOpcode::COPY), ResultReg)
2666 updateValueMap(II, ResultReg);
2669 case Intrinsic::frameaddress: {
2677 if (!isTypeLegal(RetTy, VT))
2685 case MVT::i32: Opc = X86::MOV32rm; RC = &X86::GR32RegClass;
break;
2686 case MVT::i64: Opc = X86::MOV64rm; RC = &X86::GR64RegClass;
break;
2697 (FrameReg == X86::EBP && VT ==
MVT::i32)) &&
2698 "Invalid Frame Register!");
2703 unsigned SrcReg = createResultReg(RC);
2704 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2705 TII.get(TargetOpcode::COPY), SrcReg).addReg(FrameReg);
2713 unsigned Depth = cast<ConstantInt>(II->
getOperand(0))->getZExtValue();
2715 DestReg = createResultReg(RC);
2717 TII.get(Opc), DestReg), SrcReg);
2721 updateValueMap(II, SrcReg);
2724 case Intrinsic::memcpy: {
2725 const MemCpyInst *MCI = cast<MemCpyInst>(II);
2730 if (isa<ConstantInt>(MCI->
getLength())) {
2733 uint64_t Len = cast<ConstantInt>(MCI->
getLength())->getZExtValue();
2734 if (IsMemcpySmall(Len)) {
2739 TryEmitSmallMemcpy(DestAM, SrcAM, Len);
2744 unsigned SizeWidth = Subtarget->is64Bit() ? 64 : 32;
2753 case Intrinsic::memset: {
2754 const MemSetInst *MSI = cast<MemSetInst>(II);
2759 unsigned SizeWidth = Subtarget->is64Bit() ? 64 : 32;
2768 case Intrinsic::stackprotector: {
2770 EVT PtrTy = TLI.getPointerTy(DL);
2775 MFI.setStackProtectorIndex(FuncInfo.StaticAllocaMap[Slot]);
2780 if (!X86FastEmitStore(PtrTy, Op1, AM))
return false;
2783 case Intrinsic::dbg_declare: {
2793 "Expected inlined-at fields to agree");
2800 case Intrinsic::trap: {
2804 case Intrinsic::sqrt: {
2805 if (!Subtarget->hasSSE1())
2811 if (!isTypeLegal(RetTy, VT))
2817 static const uint16_t SqrtOpc[3][2] = {
2818 { X86::SQRTSSr, X86::SQRTSDr },
2819 { X86::VSQRTSSr, X86::VSQRTSDr },
2820 { X86::VSQRTSSZr, X86::VSQRTSDZr },
2822 unsigned AVXLevel = Subtarget->hasAVX512() ? 2 :
2823 Subtarget->hasAVX() ? 1 :
2827 default:
return false;
2828 case MVT::f32: Opc = SqrtOpc[AVXLevel][0];
break;
2829 case MVT::f64: Opc = SqrtOpc[AVXLevel][1];
break;
2833 unsigned SrcReg = getRegForValue(SrcVal);
2839 unsigned ImplicitDefReg = 0;
2841 ImplicitDefReg = createResultReg(RC);
2842 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2843 TII.get(TargetOpcode::IMPLICIT_DEF), ImplicitDefReg);
2846 unsigned ResultReg = createResultReg(RC);
2848 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc),
2852 MIB.
addReg(ImplicitDefReg);
2856 updateValueMap(II, ResultReg);
2859 case Intrinsic::sadd_with_overflow:
2860 case Intrinsic::uadd_with_overflow:
2861 case Intrinsic::ssub_with_overflow:
2862 case Intrinsic::usub_with_overflow:
2863 case Intrinsic::smul_with_overflow:
2864 case Intrinsic::umul_with_overflow: {
2869 Type *RetTy = Ty->getTypeAtIndex(0U);
2872 "Overflow value expected to be an i1");
2875 if (!isTypeLegal(RetTy, VT))
2885 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS) &&
2886 isCommutativeIntrinsic(II))
2892 case Intrinsic::sadd_with_overflow:
2894 case Intrinsic::uadd_with_overflow:
2896 case Intrinsic::ssub_with_overflow:
2898 case Intrinsic::usub_with_overflow:
2900 case Intrinsic::smul_with_overflow:
2902 case Intrinsic::umul_with_overflow:
2906 unsigned LHSReg = getRegForValue(LHS);
2909 bool LHSIsKill = hasTrivialKill(LHS);
2911 unsigned ResultReg = 0;
2913 if (
const auto *CI = dyn_cast<ConstantInt>(RHS)) {
2914 static const uint16_t Opc[2][4] = {
2915 { X86::INC8r, X86::INC16r, X86::INC32r, X86::INC64r },
2916 { X86::DEC8r, X86::DEC16r, X86::DEC32r, X86::DEC64r }
2922 ResultReg = createResultReg(TLI.getRegClassFor(VT));
2924 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2925 TII.get(Opc[IsDec][VT.SimpleTy-
MVT::i8]), ResultReg)
2928 ResultReg = fastEmit_ri(VT, VT, BaseOpc, LHSReg, LHSIsKill,
2929 CI->getZExtValue());
2935 RHSReg = getRegForValue(RHS);
2938 RHSIsKill = hasTrivialKill(RHS);
2939 ResultReg = fastEmit_rr(VT, VT, BaseOpc, LHSReg, LHSIsKill, RHSReg,
2947 { X86::MUL8r, X86::MUL16r, X86::MUL32r, X86::MUL64r };
2951 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2952 TII.get(TargetOpcode::COPY), Reg[VT.SimpleTy-
MVT::i8])
2954 ResultReg = fastEmitInst_r(MULOpc[VT.SimpleTy-
MVT::i8],
2955 TLI.getRegClassFor(VT), RHSReg, RHSIsKill);
2958 { X86::IMUL8r, X86::IMUL16rr, X86::IMUL32rr, X86::IMUL64rr };
2962 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2965 ResultReg = fastEmitInst_r(MULOpc[0], TLI.getRegClassFor(VT), RHSReg,
2968 ResultReg = fastEmitInst_rr(MULOpc[VT.SimpleTy-
MVT::i8],
2969 TLI.getRegClassFor(VT), LHSReg, LHSIsKill,
2977 unsigned ResultReg2 = createResultReg(&X86::GR8RegClass);
2978 assert((ResultReg+1) == ResultReg2 &&
"Nonconsecutive result registers.");
2979 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::SETCCr),
2980 ResultReg2).addImm(CondCode);
2982 updateValueMap(II, ResultReg, 2);
2985 case Intrinsic::x86_sse_cvttss2si:
2986 case Intrinsic::x86_sse_cvttss2si64:
2987 case Intrinsic::x86_sse2_cvttsd2si:
2988 case Intrinsic::x86_sse2_cvttsd2si64: {
2992 case Intrinsic::x86_sse_cvttss2si:
2993 case Intrinsic::x86_sse_cvttss2si64:
2994 if (!Subtarget->hasSSE1())
2996 IsInputDouble =
false;
2998 case Intrinsic::x86_sse2_cvttsd2si:
2999 case Intrinsic::x86_sse2_cvttsd2si64:
3000 if (!Subtarget->hasSSE2())
3002 IsInputDouble =
true;
3008 if (!isTypeLegal(RetTy, VT))
3011 static const uint16_t CvtOpc[3][2][2] = {
3012 { { X86::CVTTSS2SIrr, X86::CVTTSS2SI64rr },
3013 { X86::CVTTSD2SIrr, X86::CVTTSD2SI64rr } },
3014 { { X86::VCVTTSS2SIrr, X86::VCVTTSS2SI64rr },
3015 { X86::VCVTTSD2SIrr, X86::VCVTTSD2SI64rr } },
3016 { { X86::VCVTTSS2SIZrr, X86::VCVTTSS2SI64Zrr },
3017 { X86::VCVTTSD2SIZrr, X86::VCVTTSD2SI64Zrr } },
3019 unsigned AVXLevel = Subtarget->hasAVX512() ? 2 :
3020 Subtarget->hasAVX() ? 1 :
3025 case MVT::i32: Opc = CvtOpc[AVXLevel][IsInputDouble][0];
break;
3026 case MVT::i64: Opc = CvtOpc[AVXLevel][IsInputDouble][1];
break;
3031 while (
auto *
IE = dyn_cast<InsertElementInst>(Op)) {
3033 if (!isa<ConstantInt>(Index))
3035 unsigned Idx = cast<ConstantInt>(
Index)->getZExtValue();
3038 Op =
IE->getOperand(1);
3041 Op =
IE->getOperand(0);
3044 unsigned Reg = getRegForValue(Op);
3048 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
3049 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
3052 updateValueMap(II, ResultReg);
3058 bool X86FastISel::fastLowerArguments() {
3059 if (!FuncInfo.CanLowerReturn)
3070 if (Subtarget->isCallingConvWin64(CC))
3073 if (!Subtarget->is64Bit())
3076 if (Subtarget->useSoftFloat())
3080 unsigned GPRCnt = 0;
3081 unsigned FPRCnt = 0;
3082 for (
auto const &
Arg : F->
args()) {
3083 if (
Arg.hasAttribute(Attribute::ByVal) ||
3084 Arg.hasAttribute(Attribute::InReg) ||
3085 Arg.hasAttribute(Attribute::StructRet) ||
3086 Arg.hasAttribute(Attribute::SwiftSelf) ||
3087 Arg.hasAttribute(Attribute::SwiftError) ||
3088 Arg.hasAttribute(Attribute::Nest))
3095 EVT ArgVT = TLI.getValueType(DL, ArgTy);
3096 if (!ArgVT.
isSimple())
return false;
3098 default:
return false;
3105 if (!Subtarget->hasSSE1())
3118 static const MCPhysReg GPR32ArgRegs[] = {
3121 static const MCPhysReg GPR64ArgRegs[] = {
3122 X86::RDI, X86::RSI, X86::RDX, X86::RCX, X86::R8 , X86::R9
3125 X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3,
3126 X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7
3130 unsigned FPRIdx = 0;
3131 for (
auto const &
Arg : F->
args()) {
3132 MVT VT = TLI.getSimpleValueType(DL,
Arg.getType());
3137 case MVT::i32: SrcReg = GPR32ArgRegs[GPRIdx++];
break;
3138 case MVT::i64: SrcReg = GPR64ArgRegs[GPRIdx++];
break;
3140 case MVT::f64: SrcReg = XMMArgRegs[FPRIdx++];
break;
3142 unsigned DstReg = FuncInfo.MF->addLiveIn(SrcReg, RC);
3146 unsigned ResultReg = createResultReg(RC);
3147 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3148 TII.get(TargetOpcode::COPY), ResultReg)
3150 updateValueMap(&
Arg, ResultReg);
3174 bool X86FastISel::fastLowerCall(CallLoweringInfo &CLI) {
3175 auto &OutVals = CLI.OutVals;
3176 auto &OutFlags = CLI.OutFlags;
3177 auto &OutRegs = CLI.OutRegs;
3178 auto &
Ins = CLI.Ins;
3179 auto &InRegs = CLI.InRegs;
3181 bool &IsTailCall = CLI.IsTailCall;
3182 bool IsVarArg = CLI.IsVarArg;
3186 bool Is64Bit = Subtarget->is64Bit();
3187 bool IsWin64 = Subtarget->isCallingConvWin64(CC);
3201 if ((CI && CI->
hasFnAttr(
"no_caller_saved_registers")) ||
3202 (CalledFn && CalledFn->hasFnAttribute(
"no_caller_saved_registers")))
3206 if (Subtarget->useRetpolineIndirectCalls())
3211 default:
return false;
3238 if (IsVarArg && IsWin64)
3242 if (CLI.CS && CLI.CS->hasInAllocaArgument())
3245 for (
auto Flag : CLI.OutFlags)
3246 if (
Flag.isSwiftError())
3255 for (
int i = 0,
e = OutVals.size(); i !=
e; ++i) {
3256 Value *&Val = OutVals[i];
3258 if (
auto *CI = dyn_cast<ConstantInt>(Val)) {
3259 if (CI->getBitWidth() < 32) {
3272 if (TI && TI->getType()->isIntegerTy(1) && CLI.CS &&
3273 (TI->getParent() == CLI.CS->getInstruction()->getParent()) &&
3275 Value *PrevVal = TI->getOperand(0);
3276 ResultReg = getRegForValue(PrevVal);
3281 if (!isTypeLegal(PrevVal->
getType(), VT))
3285 fastEmit_ri(VT, VT,
ISD::AND, ResultReg, hasTrivialKill(PrevVal), 1);
3287 if (!isTypeLegal(Val->
getType(), VT))
3289 ResultReg = getRegForValue(Val);
3301 CCState CCInfo(CC, IsVarArg, *FuncInfo.MF, ArgLocs, CLI.RetTy->getContext());
3307 CCInfo.AnalyzeCallOperands(OutVTs, OutFlags,
CC_X86);
3310 unsigned NumBytes = CCInfo.getAlignedCallFrameSize();
3313 unsigned AdjStackDown =
TII.getCallFrameSetupOpcode();
3314 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AdjStackDown))
3319 for (
unsigned i = 0,
e = ArgLocs.
size(); i !=
e; ++i) {
3327 unsigned ArgReg = ArgRegs[VA.
getValNo()];
3334 "Unexpected extend");
3341 assert(Emitted &&
"Failed to emit a sext!"); (void)Emitted;
3347 "Unexpected extend");
3352 ArgReg = fastEmitZExtFromI1(
MVT::i8, ArgReg,
false);
3361 assert(Emitted &&
"Failed to emit a zext!"); (void)Emitted;
3367 "Unexpected extend");
3377 assert(Emitted &&
"Failed to emit a aext!"); (void)Emitted;
3384 assert(ArgReg &&
"Failed to emit a bitcast!");
3405 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3406 TII.get(TargetOpcode::COPY), VA.
getLocReg()).addReg(ArgReg);
3412 if (isa<UndefValue>(ArgVal))
3418 AM.
Disp = LocMemOffset;
3420 unsigned Alignment = DL.getABITypeAlignment(ArgVal->
getType());
3427 if (!TryEmitSmallMemcpy(AM, SrcAM, Flags.
getByValSize()))
3429 }
else if (isa<ConstantInt>(ArgVal) || isa<ConstantPointerNull>(ArgVal)) {
3433 if (!X86FastEmitStore(ArgVT, ArgVal, AM, MMO))
3436 bool ValIsKill = hasTrivialKill(ArgVal);
3437 if (!X86FastEmitStore(ArgVT, ArgReg, ValIsKill, AM, MMO))
3445 if (Subtarget->isPICStyleGOT()) {
3446 unsigned Base = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
3447 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3448 TII.get(TargetOpcode::COPY),
X86::EBX).addReg(Base);
3451 if (Is64Bit && IsVarArg && !IsWin64) {
3462 X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3,
3463 X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7
3465 unsigned NumXMMRegs = CCInfo.getFirstUnallocated(XMMArgRegs);
3466 assert((Subtarget->hasSSE1() || !NumXMMRegs)
3467 &&
"SSE registers cannot be used when SSE is disabled");
3468 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOV8ri),
3475 if (!X86SelectCallAddress(Callee, CalleeAM))
3478 unsigned CalleeOp = 0;
3480 if (CalleeAM.
GV !=
nullptr) {
3482 }
else if (CalleeAM.
Base.
Reg != 0) {
3491 unsigned CallOpc = Is64Bit ? X86::CALL64r : X86::CALL32r;
3492 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(CallOpc))
3496 assert(GV &&
"Not a direct call");
3498 unsigned char OpFlags = Subtarget->classifyGlobalFunctionReference(GV);
3505 unsigned CallOpc = NeedLoad
3506 ? (Is64Bit ? X86::CALL64m : X86::CALL32m)
3507 : (Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32);
3509 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(CallOpc));
3513 MIB.
addSym(Symbol, OpFlags);
3525 if (Subtarget->isPICStyleGOT())
3528 if (Is64Bit && IsVarArg && !IsWin64)
3532 for (
auto Reg : OutRegs)
3536 unsigned NumBytesForCalleeToPop =
3538 TM.Options.GuaranteedTailCallOpt)
3541 unsigned AdjStackUp =
TII.getCallFrameDestroyOpcode();
3542 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AdjStackUp))
3543 .addImm(NumBytes).
addImm(NumBytesForCalleeToPop);
3547 CCState CCRetInfo(CC, IsVarArg, *FuncInfo.MF, RVLocs,
3548 CLI.RetTy->getContext());
3552 unsigned ResultReg = FuncInfo.CreateRegs(CLI.RetTy);
3553 for (
unsigned i = 0; i != RVLocs.
size(); ++i) {
3556 unsigned CopyReg = ResultReg + i;
3561 ((Is64Bit ||
Ins[i].Flags.isInReg()) && !Subtarget->hasSSE1())) {
3567 if ((SrcReg == X86::FP0 || SrcReg == X86::FP1) &&
3568 isScalarFPTypeInSSEReg(VA.
getValVT())) {
3570 CopyReg = createResultReg(&X86::RFP80RegClass);
3574 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3575 TII.get(TargetOpcode::COPY), CopyReg).addReg(SrcReg);
3583 unsigned Opc = ResVT ==
MVT::f32 ? X86::ST_Fp80m32 : X86::ST_Fp80m64;
3585 int FI = MFI.CreateStackObject(MemSize, MemSize,
false);
3589 Opc = ResVT ==
MVT::f32 ? X86::MOVSSrm_alt : X86::MOVSDrm_alt;
3591 TII.get(Opc), ResultReg + i), FI);
3595 CLI.ResultReg = ResultReg;
3596 CLI.NumResultRegs = RVLocs.
size();
3603 X86FastISel::fastSelectInstruction(
const Instruction *I) {
3607 return X86SelectLoad(I);
3609 return X86SelectStore(I);
3611 return X86SelectRet(I);
3612 case Instruction::ICmp:
3613 case Instruction::FCmp:
3614 return X86SelectCmp(I);
3615 case Instruction::ZExt:
3616 return X86SelectZExt(I);
3617 case Instruction::SExt:
3618 return X86SelectSExt(I);
3619 case Instruction::Br:
3620 return X86SelectBranch(I);
3621 case Instruction::LShr:
3622 case Instruction::AShr:
3623 case Instruction::Shl:
3624 return X86SelectShift(I);
3625 case Instruction::SDiv:
3626 case Instruction::UDiv:
3627 case Instruction::SRem:
3628 case Instruction::URem:
3629 return X86SelectDivRem(I);
3631 return X86SelectSelect(I);
3632 case Instruction::Trunc:
3633 return X86SelectTrunc(I);
3634 case Instruction::FPExt:
3635 return X86SelectFPExt(I);
3636 case Instruction::FPTrunc:
3637 return X86SelectFPTrunc(I);
3638 case Instruction::SIToFP:
3639 return X86SelectSIToFP(I);
3640 case Instruction::UIToFP:
3641 return X86SelectUIToFP(I);
3642 case Instruction::IntToPtr:
3643 case Instruction::PtrToInt: {
3645 EVT DstVT = TLI.getValueType(DL, I->
getType());
3647 return X86SelectZExt(I);
3649 return X86SelectTrunc(I);
3651 if (Reg == 0)
return false;
3652 updateValueMap(I, Reg);
3655 case Instruction::BitCast: {
3657 if (!Subtarget->hasSSE2())
3662 !isTypeLegal(I->
getType(), DstVT))
3677 updateValueMap(I, Reg);
3685 unsigned X86FastISel::X86MaterializeInt(
const ConstantInt *CI,
MVT VT) {
3691 unsigned SrcReg = fastEmitInst_(X86::MOV32r0, &X86::GR32RegClass);
3696 return fastEmitInst_extractsubreg(
MVT::i8, SrcReg,
true,
3699 return fastEmitInst_extractsubreg(
MVT::i16, SrcReg,
true,
3704 unsigned ResultReg = createResultReg(&X86::GR64RegClass);
3705 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3706 TII.get(TargetOpcode::SUBREG_TO_REG), ResultReg)
3719 case MVT::i8: Opc = X86::MOV8ri;
break;
3720 case MVT::i16: Opc = X86::MOV16ri;
break;
3721 case MVT::i32: Opc = X86::MOV32ri;
break;
3724 Opc = X86::MOV32ri64;
3726 Opc = X86::MOV64ri32;
3732 return fastEmitInst_i(Opc, TLI.getRegClassFor(VT), Imm);
3735 unsigned X86FastISel::X86MaterializeFP(
const ConstantFP *CFP,
MVT VT) {
3737 return fastMaterializeFloatZero(CFP);
3746 bool HasAVX = Subtarget->hasAVX();
3747 bool HasAVX512 = Subtarget->hasAVX512();
3751 if (X86ScalarSSEf32)
3752 Opc = HasAVX512 ? X86::VMOVSSZrm_alt :
3753 HasAVX ? X86::VMOVSSrm_alt :
3756 Opc = X86::LD_Fp32m;
3759 if (X86ScalarSSEf64)
3760 Opc = HasAVX512 ? X86::VMOVSDZrm_alt :
3761 HasAVX ? X86::VMOVSDrm_alt :
3764 Opc = X86::LD_Fp64m;
3772 unsigned Align = DL.getPrefTypeAlignment(CFP->
getType());
3775 Align = DL.getTypeAllocSize(CFP->
getType());
3779 unsigned PICBase = 0;
3780 unsigned char OpFlag = Subtarget->classifyLocalReference(
nullptr);
3782 PICBase = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
3784 PICBase = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
3789 unsigned CPI = MCP.getConstantPoolIndex(CFP, Align);
3790 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT.
SimpleTy));
3793 unsigned AddrReg = createResultReg(&X86::GR64RegClass);
3794 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOV64ri),
3796 .addConstantPoolIndex(CPI, 0, OpFlag);
3798 TII.get(Opc), ResultReg);
3808 TII.get(Opc), ResultReg),
3809 CPI, PICBase, OpFlag);
3813 unsigned X86FastISel::X86MaterializeGV(
const GlobalValue *GV,
MVT VT) {
3827 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
3829 TLI.getPointerTy(DL) ==
MVT::i64) {
3832 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOV64ri),
3834 .addGlobalAddress(GV);
3838 ? (Subtarget->isTarget64BitILP32() ? X86::LEA64_32r : X86::LEA32r)
3841 TII.get(Opc), ResultReg), AM);
3848 unsigned X86FastISel::fastMaterializeConstant(
const Constant *
C) {
3849 EVT CEVT = TLI.getValueType(DL, C->
getType(),
true);
3856 if (
const auto *CI = dyn_cast<ConstantInt>(C))
3857 return X86MaterializeInt(CI, VT);
3858 else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
3859 return X86MaterializeFP(CFP, VT);
3860 else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C))
3861 return X86MaterializeGV(GV, VT);
3866 unsigned X86FastISel::fastMaterializeAlloca(
const AllocaInst *C) {
3874 if (!FuncInfo.StaticAllocaMap.count(C))
3883 ? (Subtarget->isTarget64BitILP32() ? X86::LEA64_32r : X86::LEA32r)
3886 unsigned ResultReg = createResultReg(RC);
3888 TII.get(Opc), ResultReg), AM);
3892 unsigned X86FastISel::fastMaterializeFloatZero(
const ConstantFP *CF) {
3894 if (!isTypeLegal(CF->
getType(), VT))
3898 bool HasAVX512 = Subtarget->hasAVX512();
3903 if (X86ScalarSSEf32)
3904 Opc = HasAVX512 ? X86::AVX512_FsFLD0SS : X86::FsFLD0SS;
3906 Opc = X86::LD_Fp032;
3909 if (X86ScalarSSEf64)
3910 Opc = HasAVX512 ? X86::AVX512_FsFLD0SD : X86::FsFLD0SD;
3912 Opc = X86::LD_Fp064;
3919 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
3920 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg);
3925 bool X86FastISel::tryToFoldLoadIntoMI(
MachineInstr *
MI,
unsigned OpNo,
3934 unsigned Size = DL.getTypeAllocSize(LI->
getType());
3938 Alignment = DL.getABITypeAlignment(LI->
getType());
3944 *FuncInfo.MF, *MI, OpNo, AddrOps, FuncInfo.InsertPt, Size, Alignment,
3954 unsigned OperandNo = 0;
3963 if (IndexReg == MO.
getReg())
3968 Result->
addMemOperand(*FuncInfo.MF, createMachineMemOperandFor(LI));
3971 removeDeadCode(I, std::next(I));
3975 unsigned X86FastISel::fastEmitInst_rrrr(
unsigned MachineInstOpcode,
3977 unsigned Op0,
bool Op0IsKill,
3978 unsigned Op1,
bool Op1IsKill,
3979 unsigned Op2,
bool Op2IsKill,
3980 unsigned Op3,
bool Op3IsKill) {
3983 unsigned ResultReg = createResultReg(RC);
3990 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
3996 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
4001 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4011 return new X86FastISel(funcInfo, libInfo);
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
void setFrameAddressIsTaken(bool T)
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
constexpr bool isUInt< 32 >(uint64_t x)
Return a value (possibly void), from a function.
Value * getValueOperand()
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeCallResult - Analyze the return values of a call, incorporating info about the passed values i...
bool is64Bit() const
Is this x86_64? (disregarding specific ABI / programming model)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool usesWindowsCFI() const
mop_iterator operands_end()
bool isInteger() const
Return true if this is an integer or a vector integer type.
This class is the base class for the comparison instructions.
enum llvm::X86AddressMode::@522 BaseType
MO_COFFSTUB - On a symbol operand "FOO", this indicates that the reference is actually to the "...
This class represents an incoming formal argument to a Function.
bool contains(unsigned Reg) const
Return true if the specified register is included in this register class.
bool isOSMSVCRT() const
Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
unsigned constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, const MachineOperand &RegMO, unsigned OpIdx)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
Register getLocReg() const
static const MachineInstrBuilder & addConstantPoolReference(const MachineInstrBuilder &MIB, unsigned CPI, unsigned GlobalBaseReg, unsigned char OpFlags)
addConstantPoolReference - This function is used to add a reference to the base of a constant value s...
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isVector() const
Return true if this is a vector value type.
void push_back(const T &Elt)
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
Describe properties that are true of each instruction in the target description file.
This class represents a function call, abstracting a target machine's calling convention.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
0 1 0 0 True if ordered and less than
constexpr bool isInt< 8 >(int64_t x)
unsigned getSourceAddressSpace() const
unsigned getValNo() const
LLVMContext & getContext() const
All values hold a context through their type.
1 1 1 0 True if unordered or not equal
This class wraps the llvm.memset intrinsic.
C - The default llvm calling convention, compatible with C.
BasicBlock * getSuccessor(unsigned i) const
unsigned const TargetRegisterInfo * TRI
unsigned getPtrSizedFrameRegister(const MachineFunction &MF) const
An instruction for reading from memory.
MO_GOTPCREL - On a symbol operand this indicates that the immediate is offset to the GOT entry for th...
Value * getCondition() const
bool isVectorTy() const
True if this is an instance of VectorType.
bool isCalleePop(CallingConv::ID CallingConv, bool is64Bit, bool IsVarArg, bool GuaranteeTCO)
Determines whether the callee is required to pop its own arguments.
Value * getLength() const
bool CC_X86(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
Value * getArgOperand(unsigned i) const
1 0 0 1 True if unordered or equal
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
A description of a memory reference used in the backend.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const HexagonInstrInfo * TII
bool isNonTemporal() const
unsigned getNumOperands() const
Retuns the total number of operands.
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
static bool isGlobalStubReference(unsigned char TargetFlag)
isGlobalStubReference - Return true if the specified TargetFlag operand is a reference to a stub for ...
bool isIntegerTy() const
True if this is an instance of IntegerType.
0 1 0 1 True if ordered and less than or equal
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
LocInfo getLocInfo() const
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
static bool isGlobalRelativeToPICBase(unsigned char TargetFlag)
isGlobalRelativeToPICBase - Return true if the specified global value reference is relative to a 32-b...
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
A constant value that is initialized with an expression using other constant values.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Type * getType() const
All values are typed, get the type of this value.
Simple integer binary arithmetic operators.
This instruction compares its operands according to the predicate given to the constructor.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
An instruction for storing to memory.
void setReg(Register Reg)
Change the register this operand corresponds to.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
bool doesNoCfCheck() const
Determine if the call should not perform indirect branch tracking.
void addMemOperand(MachineFunction &MF, MachineMemOperand *MO)
Add a MachineMemOperand to the machine instruction.
This class represents a truncation of integer types.
MVT getVectorElementType() const
Value * getOperand(unsigned i) const
Class to represent pointers.
unsigned getByValSize() const
unsigned getKillRegState(bool B)
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Flag
These should be considered private to the implementation of the MCInstrDesc class.
unsigned getCMovOpcode(unsigned RegBytes, bool HasMemoryOperand=false)
Return a cmov opcode for the given register size in bytes, and operand type.
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
The C convention as implemented on Windows/x86-64 and AArch64.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Type * getReturnType() const
Returns the type of the ret val.
std::pair< CondCode, bool > getX86ConditionCode(CmpInst::Predicate Predicate)
Return a pair of condition code for the given predicate and whether the instruction operands should b...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
unsigned const MachineRegisterInfo * MRI
void cloneInstrSymbols(MachineFunction &MF, const MachineInstr &MI)
Clone another MachineInstr's pre- and post- instruction symbols and replace ours with it...
The instances of the Type class are immutable: once they are created, they are never changed...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Conditional or Unconditional Branch instruction.
Value * getAddress() const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
unsigned getSRetReturnReg() const
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
ConstantFP - Floating Point Values [float, double].
const MCPhysReg * ImplicitDefs
DIExpression * getExpression() const
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
static std::pair< unsigned, bool > getX86SSEConditionCode(CmpInst::Predicate Predicate)
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
TRAP - Trapping instruction.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
0 1 1 1 True if ordered (no nans)
Value * getPointerOperand()
MachineInstr * foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI, ArrayRef< unsigned > Ops, MachineBasicBlock::iterator InsertPt, int FrameIndex, LiveIntervals *LIS=nullptr, VirtRegMap *VRM=nullptr) const override
foldMemoryOperand - If this target supports it, fold a load or store of the specified stack slot into...
const Triple & getTargetTriple() const
static void X86SelectAddress(const MachineInstr &I, const MachineRegisterInfo &MRI, X86AddressMode &AM)
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
1 1 1 1 Always true (always folded)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
1 1 0 1 True if unordered, less than, or equal
#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.
static const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0, bool mem=true)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
The memory access writes data.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
void GetReturnInfo(CallingConv::ID CC, Type *ReturnType, AttributeList attr, SmallVectorImpl< ISD::OutputArg > &Outs, const TargetLowering &TLI, const DataLayout &DL)
Given an LLVM IR type and return type attributes, compute the return value EVTs and flags...
0 0 1 0 True if ordered and greater than
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
CCState - This class holds information needed while lowering arguments and return values...
This is the shared class of boolean and integer constants.
constexpr bool isInt< 32 >(int64_t x)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
1 1 0 0 True if unordered or less than
Provides information about what library functions are available for the current target.
CCValAssign - Represent assignment of one arg/retval to a location.
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
void getFullAddress(SmallVectorImpl< MachineOperand > &MO)
This class wraps the llvm.memcpy intrinsic.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Value * getRawSource() const
Return the arguments to the instruction.
bool RetCC_X86(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
X86_FastCall - 'fast' analog of X86_StdCall.
amdgpu Simplify well known AMD library false FunctionCallee Callee
This file defines the FastISel class.
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
ZERO_EXTEND - Used for integer types, zeroing the new bits.
ANY_EXTEND - Used for integer types. The high bits are undefined.
The memory access reads data.
Representation of each machine instruction.
MO_GOTOFF - On a symbol operand this indicates that the immediate is the offset to the location of th...
static const MachineInstrBuilder & addDirectMem(const MachineInstrBuilder &MIB, unsigned Reg)
addDirectMem - This function is used to add a direct memory reference to the current instruction – t...
unsigned getNumArgOperands() const
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
unsigned AllocateStack(unsigned Size, unsigned Alignment)
AllocateStack - Allocate a chunk of stack space with the specified size and alignment.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Bitwise operators - logical and, logical or, logical xor.
unsigned getDestAddressSpace() const
uint64_t getElementOffset(unsigned Idx) const
unsigned getAlignment() const
Return the alignment of the access that is being performed.
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned getLocMemOffset() const
Establish a view to a call site for examination.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
const Function * getParent() const
Return the enclosing method, or null if none.
void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeReturn - Analyze the returned values of a return, incorporating info about the result values i...
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
0 1 1 0 True if ordered and operands are unequal
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
DILocalVariable * getVariable() const
Tail - This calling convention attemps to make calls as fast as possible while guaranteeing that tail...
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
unsigned getBytesToPopOnReturn() const
1 0 1 0 True if unordered or greater than
constexpr bool isUInt< 16 >(uint64_t x)
union llvm::X86AddressMode::@523 Base
static MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
unsigned getAlignment() const
Return the alignment of the access that is being performed FIXME: Remove this function once transitio...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
0 0 0 1 True if ordered and equal
LLVM Value Representation.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
mop_iterator operands_begin()
1 0 1 1 True if unordered, greater than, or equal
static unsigned X86ChooseCmpImmediateOpcode(EVT VT, const ConstantInt *RHSC)
If we have a comparison with RHS as the RHS of the comparison, return an opcode that works for the co...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the immediate should get the value of th...
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
Register getReg() const
getReg - Returns the register number.
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
X86AddressMode - This struct holds a generalized full x86 address mode.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
0 0 1 1 True if ordered and greater than or equal
This represents the llvm.dbg.declare instruction.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Value * getPointerOperand()
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Value * getRawDest() const
static const MachineInstrBuilder & addFullAddress(const MachineInstrBuilder &MIB, const X86AddressMode &AM)
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo)
Register getStackRegister() const
X86_ThisCall - Similar to X86_StdCall.
iterator_range< arg_iterator > args()
0 0 0 0 Always false (always folded)
Wrapper class representing virtual and physical registers.
bool isStructTy() const
True if this is an instance of StructType.
MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the reference is actually to the "__imp...
static unsigned computeBytesPoppedByCalleeForSRet(const X86Subtarget *Subtarget, CallingConv::ID CC, ImmutableCallSite *CS)
bool isArrayTy() const
True if this is an instance of ArrayType.
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
static unsigned X86ChooseCmpOpcode(EVT VT, const X86Subtarget *Subtarget)
an instruction to allocate memory on the stack
gep_type_iterator gep_type_begin(const User *GEP)