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,
129 bool X86SelectFPExtOrFPTrunc(
const Instruction *
I,
unsigned Opc,
137 return Subtarget->getInstrInfo();
148 unsigned fastMaterializeConstant(
const Constant *
C)
override;
150 unsigned fastMaterializeAlloca(
const AllocaInst *
C)
override;
152 unsigned fastMaterializeFloatZero(
const ConstantFP *CF)
override;
156 bool isScalarFPTypeInSSEReg(
EVT VT)
const {
157 return (VT ==
MVT::f64 && X86ScalarSSEf64) ||
158 (VT ==
MVT::f32 && X86ScalarSSEf32);
161 bool isTypeLegal(
Type *Ty,
MVT &VT,
bool AllowI1 =
false);
163 bool IsMemcpySmall(uint64_t Len);
174 unsigned fastEmitInst_rrrr(
unsigned MachineInstOpcode,
176 bool Op0IsKill,
unsigned Op1,
bool Op1IsKill,
177 unsigned Op2,
bool Op2IsKill,
unsigned Op3,
183 static std::pair<unsigned, bool>
186 bool NeedSwap =
false;
215 return std::make_pair(CC, NeedSwap);
236 if (!isa<ExtractValueInst>(Cond))
239 const auto *EV = cast<ExtractValueInst>(Cond);
240 if (!isa<IntrinsicInst>(EV->getAggregateOperand()))
243 const auto *II = cast<IntrinsicInst>(EV->getAggregateOperand());
245 const Function *Callee = II->getCalledFunction();
247 cast<StructType>(Callee->
getReturnType())->getTypeAtIndex(0U);
248 if (!isTypeLegal(RetTy, RetVT))
255 switch (II->getIntrinsicID()) {
256 default:
return false;
257 case Intrinsic::sadd_with_overflow:
258 case Intrinsic::ssub_with_overflow:
259 case Intrinsic::smul_with_overflow:
260 case Intrinsic::umul_with_overflow: TmpCC =
X86::COND_O;
break;
261 case Intrinsic::uadd_with_overflow:
262 case Intrinsic::usub_with_overflow: TmpCC =
X86::COND_B;
break;
272 for (
auto Itr = std::prev(Start); Itr !=
End; --Itr) {
275 if (!isa<ExtractValueInst>(Itr))
279 const auto *EVI = cast<ExtractValueInst>(Itr);
280 if (EVI->getAggregateOperand() != II)
288 bool X86FastISel::isTypeLegal(
Type *Ty,
MVT &VT,
bool AllowI1) {
289 EVT evt = TLI.getValueType(
DL, Ty,
true);
297 if (VT ==
MVT::f64 && !X86ScalarSSEf64)
299 if (VT ==
MVT::f32 && !X86ScalarSSEf32)
308 return (AllowI1 && VT ==
MVT::i1) || TLI.isTypeLegal(VT);
311 #include "X86GenCallingConv.inc"
318 unsigned Alignment) {
319 bool HasSSE41 = Subtarget->hasSSE41();
320 bool HasAVX = Subtarget->hasAVX();
321 bool HasAVX2 = Subtarget->hasAVX2();
322 bool HasAVX512 = Subtarget->hasAVX512();
323 bool HasVLX = Subtarget->hasVLX();
330 default:
return false;
333 if (Subtarget->hasAVX512())
338 RC = &X86::GR8RegClass;
342 RC = &X86::GR16RegClass;
346 RC = &X86::GR32RegClass;
351 RC = &X86::GR64RegClass;
354 if (X86ScalarSSEf32) {
355 Opc = HasAVX512 ? X86::VMOVSSZrm : HasAVX ? X86::VMOVSSrm : X86::MOVSSrm;
356 RC = &X86::FR32RegClass;
359 RC = &X86::RFP32RegClass;
363 if (X86ScalarSSEf64) {
364 Opc = HasAVX512 ? X86::VMOVSDZrm : HasAVX ? X86::VMOVSDrm : X86::MOVSDrm;
365 RC = &X86::FR64RegClass;
368 RC = &X86::RFP64RegClass;
375 if (IsNonTemporal && Alignment >= 16 && HasSSE41)
376 Opc = HasVLX ? X86::VMOVNTDQAZ128rm :
377 HasAVX ? X86::VMOVNTDQArm : X86::MOVNTDQArm;
378 else if (Alignment >= 16)
379 Opc = HasVLX ? X86::VMOVAPSZ128rm :
380 HasAVX ? X86::VMOVAPSrm : X86::MOVAPSrm;
382 Opc = HasVLX ? X86::VMOVUPSZ128rm :
383 HasAVX ? X86::VMOVUPSrm : X86::MOVUPSrm;
384 RC = &X86::VR128RegClass;
387 if (IsNonTemporal && Alignment >= 16 && HasSSE41)
388 Opc = HasVLX ? X86::VMOVNTDQAZ128rm :
389 HasAVX ? X86::VMOVNTDQArm : X86::MOVNTDQArm;
390 else if (Alignment >= 16)
391 Opc = HasVLX ? X86::VMOVAPDZ128rm :
392 HasAVX ? X86::VMOVAPDrm : X86::MOVAPDrm;
394 Opc = HasVLX ? X86::VMOVUPDZ128rm :
395 HasAVX ? X86::VMOVUPDrm : X86::MOVUPDrm;
396 RC = &X86::VR128RegClass;
402 if (IsNonTemporal && Alignment >= 16)
403 Opc = HasVLX ? X86::VMOVNTDQAZ128rm :
404 HasAVX ? X86::VMOVNTDQArm : X86::MOVNTDQArm;
405 else if (Alignment >= 16)
406 Opc = HasVLX ? X86::VMOVDQA64Z128rm :
407 HasAVX ? X86::VMOVDQArm : X86::MOVDQArm;
409 Opc = HasVLX ? X86::VMOVDQU64Z128rm :
410 HasAVX ? X86::VMOVDQUrm : X86::MOVDQUrm;
411 RC = &X86::VR128RegClass;
415 if (IsNonTemporal && Alignment >= 32 && HasAVX2)
416 Opc = HasVLX ? X86::VMOVNTDQAZ256rm : X86::VMOVNTDQAYrm;
417 else if (IsNonTemporal && Alignment >= 16)
419 else if (Alignment >= 32)
420 Opc = HasVLX ? X86::VMOVAPSZ256rm : X86::VMOVAPSYrm;
422 Opc = HasVLX ? X86::VMOVUPSZ256rm : X86::VMOVUPSYrm;
423 RC = &X86::VR256RegClass;
427 if (IsNonTemporal && Alignment >= 32 && HasAVX2)
428 Opc = X86::VMOVNTDQAYrm;
429 else if (IsNonTemporal && Alignment >= 16)
431 else if (Alignment >= 32)
432 Opc = HasVLX ? X86::VMOVAPDZ256rm : X86::VMOVAPDYrm;
434 Opc = HasVLX ? X86::VMOVUPDZ256rm : X86::VMOVUPDYrm;
435 RC = &X86::VR256RegClass;
442 if (IsNonTemporal && Alignment >= 32 && HasAVX2)
443 Opc = X86::VMOVNTDQAYrm;
444 else if (IsNonTemporal && Alignment >= 16)
446 else if (Alignment >= 32)
447 Opc = HasVLX ? X86::VMOVDQA64Z256rm : X86::VMOVDQAYrm;
449 Opc = HasVLX ? X86::VMOVDQU64Z256rm : X86::VMOVDQUYrm;
450 RC = &X86::VR256RegClass;
454 if (IsNonTemporal && Alignment >= 64)
455 Opc = X86::VMOVNTDQAZrm;
457 Opc = (Alignment >= 64) ? X86::VMOVAPSZrm : X86::VMOVUPSZrm;
458 RC = &X86::VR512RegClass;
462 if (IsNonTemporal && Alignment >= 64)
463 Opc = X86::VMOVNTDQAZrm;
465 Opc = (Alignment >= 64) ? X86::VMOVAPDZrm : X86::VMOVUPDZrm;
466 RC = &X86::VR512RegClass;
475 if (IsNonTemporal && Alignment >= 64)
476 Opc = X86::VMOVNTDQAZrm;
478 Opc = (Alignment >= 64) ? X86::VMOVDQA64Zrm : X86::VMOVDQU64Zrm;
479 RC = &X86::VR512RegClass;
483 ResultReg = createResultReg(RC);
485 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg);
496 bool X86FastISel::X86FastEmitStore(
EVT VT,
unsigned ValReg,
bool ValIsKill,
499 bool HasSSE1 = Subtarget->hasSSE1();
500 bool HasSSE2 = Subtarget->hasSSE2();
501 bool HasSSE4A = Subtarget->hasSSE4A();
502 bool HasAVX = Subtarget->hasAVX();
503 bool HasAVX512 = Subtarget->hasAVX512();
504 bool HasVLX = Subtarget->hasVLX();
511 default:
return false;
514 if (
MRI.getRegClass(ValReg) == &X86::VK1RegClass) {
515 unsigned KValReg = ValReg;
516 ValReg = createResultReg(&X86::GR32RegClass);
517 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
518 TII.get(TargetOpcode::COPY), ValReg)
520 ValReg = fastEmitInst_extractsubreg(
MVT::i8, ValReg,
true,
524 unsigned AndResult = createResultReg(&X86::GR8RegClass);
525 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
526 TII.get(X86::AND8ri), AndResult)
531 case MVT::i8: Opc = X86::MOV8mr;
break;
532 case MVT::i16: Opc = X86::MOV16mr;
break;
534 Opc = (IsNonTemporal && HasSSE2) ? X86::MOVNTImr : X86::MOV32mr;
538 Opc = (IsNonTemporal && HasSSE2) ? X86::MOVNTI_64mr : X86::MOV64mr;
541 if (X86ScalarSSEf32) {
542 if (IsNonTemporal && HasSSE4A)
545 Opc = HasAVX512 ? X86::VMOVSSZmr :
546 HasAVX ? X86::VMOVSSmr : X86::MOVSSmr;
551 if (X86ScalarSSEf32) {
552 if (IsNonTemporal && HasSSE4A)
555 Opc = HasAVX512 ? X86::VMOVSDZmr :
556 HasAVX ? X86::VMOVSDmr : X86::MOVSDmr;
561 Opc = (IsNonTemporal && HasSSE1) ? X86::MMX_MOVNTQmr : X86::MMX_MOVQ64mr;
566 Opc = HasVLX ? X86::VMOVNTPSZ128mr :
567 HasAVX ? X86::VMOVNTPSmr : X86::MOVNTPSmr;
569 Opc = HasVLX ? X86::VMOVAPSZ128mr :
570 HasAVX ? X86::VMOVAPSmr : X86::MOVAPSmr;
572 Opc = HasVLX ? X86::VMOVUPSZ128mr :
573 HasAVX ? X86::VMOVUPSmr : X86::MOVUPSmr;
578 Opc = HasVLX ? X86::VMOVNTPDZ128mr :
579 HasAVX ? X86::VMOVNTPDmr : X86::MOVNTPDmr;
581 Opc = HasVLX ? X86::VMOVAPDZ128mr :
582 HasAVX ? X86::VMOVAPDmr : X86::MOVAPDmr;
584 Opc = HasVLX ? X86::VMOVUPDZ128mr :
585 HasAVX ? X86::VMOVUPDmr : X86::MOVUPDmr;
593 Opc = HasVLX ? X86::VMOVNTDQZ128mr :
594 HasAVX ? X86::VMOVNTDQmr : X86::MOVNTDQmr;
596 Opc = HasVLX ? X86::VMOVDQA64Z128mr :
597 HasAVX ? X86::VMOVDQAmr : X86::MOVDQAmr;
599 Opc = HasVLX ? X86::VMOVDQU64Z128mr :
600 HasAVX ? X86::VMOVDQUmr : X86::MOVDQUmr;
606 Opc = HasVLX ? X86::VMOVNTPSZ256mr : X86::VMOVNTPSYmr;
608 Opc = HasVLX ? X86::VMOVAPSZ256mr : X86::VMOVAPSYmr;
610 Opc = HasVLX ? X86::VMOVUPSZ256mr : X86::VMOVUPSYmr;
616 Opc = HasVLX ? X86::VMOVNTPDZ256mr : X86::VMOVNTPDYmr;
618 Opc = HasVLX ? X86::VMOVAPDZ256mr : X86::VMOVAPDYmr;
620 Opc = HasVLX ? X86::VMOVUPDZ256mr : X86::VMOVUPDYmr;
629 Opc = HasVLX ? X86::VMOVNTDQZ256mr : X86::VMOVNTDQYmr;
631 Opc = HasVLX ? X86::VMOVDQA64Z256mr : X86::VMOVDQAYmr;
633 Opc = HasVLX ? X86::VMOVDQU64Z256mr : X86::VMOVDQUYmr;
638 Opc = IsNonTemporal ? X86::VMOVNTPSZmr : X86::VMOVAPSZmr;
640 Opc = X86::VMOVUPSZmr;
645 Opc = IsNonTemporal ? X86::VMOVNTPDZmr : X86::VMOVAPDZmr;
647 Opc = X86::VMOVUPDZmr;
657 Opc = IsNonTemporal ? X86::VMOVNTDQZmr : X86::VMOVDQA64Zmr;
659 Opc = X86::VMOVDQU64Zmr;
672 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, Desc);
680 bool X86FastISel::X86FastEmitStore(
EVT VT,
const Value *Val,
684 if (isa<ConstantPointerNull>(Val))
688 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
696 case MVT::i8: Opc = X86::MOV8mi;
break;
697 case MVT::i16: Opc = X86::MOV16mi;
break;
698 case MVT::i32: Opc = X86::MOV32mi;
break;
702 Opc = X86::MOV64mi32;
708 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc));
710 : CI->getZExtValue());
717 unsigned ValReg = getRegForValue(Val);
721 bool ValKill = hasTrivialKill(Val);
722 return X86FastEmitStore(VT, ValReg, ValKill, AM, MMO, Aligned);
729 unsigned Src,
EVT SrcVT,
730 unsigned &ResultReg) {
742 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
748 if (GV->isThreadLocal())
754 if (!Subtarget->isPICStyleRIPRel() ||
760 unsigned char GVFlags = Subtarget->classifyGlobalReference(GV);
765 AM.
Base.
Reg = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
771 if (Subtarget->isPICStyleRIPRel()) {
785 if (I != LocalValueMap.
end() && I->second != 0) {
797 SavePoint SaveInsertPt = enterLocalValueArea();
801 RC = &X86::GR64RegClass;
803 if (Subtarget->isPICStyleRIPRel())
807 RC = &X86::GR32RegClass;
810 LoadReg = createResultReg(RC);
812 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), LoadReg);
816 leaveLocalValueArea(SaveInsertPt);
819 LocalValueMap[V] = LoadReg;
831 if (!AM.
GV || !Subtarget->isPICStyleRIPRel()) {
833 AM.
Base.
Reg = getRegForValue(V);
851 const User *U =
nullptr;
852 unsigned Opcode = Instruction::UserOp1;
853 if (
const Instruction *I = dyn_cast<Instruction>(V)) {
857 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(V)) ||
858 FuncInfo.MBBMap[I->getParent()] == FuncInfo.MBB) {
859 Opcode = I->getOpcode();
862 }
else if (
const ConstantExpr *
C = dyn_cast<ConstantExpr>(V)) {
863 Opcode =
C->getOpcode();
868 if (Ty->getAddressSpace() > 255)
875 case Instruction::BitCast:
879 case Instruction::IntToPtr:
882 TLI.getPointerTy(
DL))
886 case Instruction::PtrToInt:
888 if (TLI.getValueType(
DL, U->
getType()) == TLI.getPointerTy(
DL))
892 case Instruction::Alloca: {
896 FuncInfo.StaticAllocaMap.find(A);
897 if (SI != FuncInfo.StaticAllocaMap.end()) {
908 uint64_t Disp = (int32_t)AM.
Disp + (uint64_t)CI->getSExtValue();
918 case Instruction::GetElementPtr: {
922 uint64_t Disp = (int32_t)AM.
Disp;
924 unsigned Scale = AM.
Scale;
929 i != e; ++i, ++GTI) {
931 if (
StructType *STy = GTI.getStructTypeOrNull()) {
941 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
943 Disp += CI->getSExtValue() * S;
946 if (canFoldAddIntoGEP(U, Op)) {
949 cast<ConstantInt>(cast<AddOperator>(
Op)->getOperand(1));
952 Op = cast<AddOperator>(
Op)->getOperand(0);
956 (!AM.
GV || !Subtarget->isPICStyleRIPRel()) &&
957 (S == 1 || S == 2 || S == 4 || S == 8)) {
960 IndexReg = getRegForGEPIndex(Op).first;
966 goto unsupported_gep;
980 dyn_cast<GetElementPtrInst>(U->
getOperand(0))) {
994 if (handleConstantAddresses(I, AM))
1004 return handleConstantAddresses(V, AM);
1010 const User *U =
nullptr;
1011 unsigned Opcode = Instruction::UserOp1;
1040 InMBB = I->
getParent() == FuncInfo.MBB->getBasicBlock();
1041 }
else if (
const ConstantExpr *
C = dyn_cast<ConstantExpr>(V)) {
1042 Opcode =
C->getOpcode();
1048 case Instruction::BitCast:
1051 return X86SelectCallAddress(U->
getOperand(0), AM);
1054 case Instruction::IntToPtr:
1058 TLI.getPointerTy(
DL))
1059 return X86SelectCallAddress(U->
getOperand(0), AM);
1062 case Instruction::PtrToInt:
1064 if (InMBB && TLI.getValueType(
DL, U->
getType()) == TLI.getPointerTy(
DL))
1065 return X86SelectCallAddress(U->
getOperand(0), AM);
1070 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1076 if (Subtarget->isPICStyleRIPRel() &&
1081 if (GV->hasDLLImportStorageClass())
1086 if (GVar->isThreadLocal())
1094 if (Subtarget->isPICStyleRIPRel()) {
1100 AM.
GVOpFlags = Subtarget->classifyLocalReference(
nullptr);
1107 if (!AM.
GV || !Subtarget->isPICStyleRIPRel()) {
1109 AM.
Base.
Reg = getRegForValue(V);
1124 bool X86FastISel::X86SelectStore(
const Instruction *I) {
1132 if (TLI.supportSwiftError()) {
1135 if (
const Argument *Arg = dyn_cast<Argument>(PtrV)) {
1136 if (Arg->hasSwiftErrorAttr())
1140 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(PtrV)) {
1141 if (Alloca->isSwiftError())
1150 if (!isTypeLegal(Val->
getType(), VT,
true))
1156 Alignment = ABIAlignment;
1157 bool Aligned = Alignment >= ABIAlignment;
1163 return X86FastEmitStore(VT, Val, AM, createMachineMemOperandFor(I), Aligned);
1167 bool X86FastISel::X86SelectRet(
const Instruction *I) {
1173 if (!FuncInfo.CanLowerReturn)
1176 if (TLI.supportSwiftError() &&
1177 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError))
1180 if (TLI.supportSplitCSR(FuncInfo.MF))
1219 unsigned Reg = getRegForValue(RV);
1224 if (ValLocs.size() != 1)
1241 unsigned SrcReg = Reg + VA.
getValNo();
1245 if (SrcVT != DstVT) {
1249 if (!Outs[0].
Flags.isZExt() && !Outs[0].Flags.isSExt())
1255 if (Outs[0].
Flags.isSExt())
1258 if (
MRI.getRegClass(SrcReg) == &X86::VK1RegClass) {
1259 unsigned KSrcReg = SrcReg;
1260 SrcReg = createResultReg(&X86::GR32RegClass);
1261 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1262 TII.get(TargetOpcode::COPY), SrcReg)
1264 SrcReg = fastEmitInst_extractsubreg(
MVT::i8, SrcReg,
true,
1267 SrcReg = fastEmitZExtFromI1(
MVT::i8, SrcReg,
false);
1282 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1283 TII.get(TargetOpcode::COPY), DstReg).addReg(SrcReg);
1299 "SRetReturnReg should have been set in LowerFormalArguments()!");
1300 unsigned RetReg = Subtarget->is64Bit() ? X86::RAX : X86::EAX;
1301 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1302 TII.get(TargetOpcode::COPY), RetReg).addReg(Reg);
1309 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1310 TII.get(Subtarget->is64Bit() ? X86::RETIQ : X86::RETIL))
1313 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1314 TII.get(Subtarget->is64Bit() ? X86::RETQ : X86::RETL));
1316 for (
unsigned i = 0, e = RetRegs.
size(); i != e; ++i)
1323 bool X86FastISel::X86SelectLoad(
const Instruction *I) {
1331 if (TLI.supportSwiftError()) {
1334 if (
const Argument *Arg = dyn_cast<Argument>(SV)) {
1335 if (Arg->hasSwiftErrorAttr())
1339 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(SV)) {
1340 if (Alloca->isSwiftError())
1346 if (!isTypeLegal(LI->
getType(), VT,
true))
1358 Alignment = ABIAlignment;
1360 unsigned ResultReg = 0;
1361 if (!X86FastEmitLoad(VT, AM, createMachineMemOperandFor(LI), ResultReg,
1365 updateValueMap(I, ResultReg);
1370 bool HasAVX = Subtarget->
hasAVX();
1371 bool X86ScalarSSEf32 = Subtarget->
hasSSE1();
1372 bool X86ScalarSSEf64 = Subtarget->
hasSSE2();
1376 case MVT::i8:
return X86::CMP8rr;
1377 case MVT::i16:
return X86::CMP16rr;
1378 case MVT::i32:
return X86::CMP32rr;
1379 case MVT::i64:
return X86::CMP64rr;
1381 return X86ScalarSSEf32 ? (HasAVX ? X86::VUCOMISSrr : X86::UCOMISSrr) : 0;
1383 return X86ScalarSSEf64 ? (HasAVX ? X86::VUCOMISDrr : X86::UCOMISDrr) : 0;
1399 return X86::CMP16ri8;
1400 return X86::CMP16ri;
1403 return X86::CMP32ri8;
1404 return X86::CMP32ri;
1407 return X86::CMP64ri8;
1411 return X86::CMP64ri32;
1416 bool X86FastISel::X86FastEmitCompare(
const Value *Op0,
const Value *Op1,
EVT VT,
1418 unsigned Op0Reg = getRegForValue(Op0);
1419 if (Op0Reg == 0)
return false;
1422 if (isa<ConstantPointerNull>(Op1))
1428 if (
const ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
1430 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, CurDbgLoc,
TII.get(CompareImmOpc))
1432 .
addImm(Op1C->getSExtValue());
1438 if (CompareOpc == 0)
return false;
1440 unsigned Op1Reg = getRegForValue(Op1);
1441 if (Op1Reg == 0)
return false;
1442 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, CurDbgLoc,
TII.get(CompareOpc))
1449 bool X86FastISel::X86SelectCmp(
const Instruction *I) {
1450 const CmpInst *CI = cast<CmpInst>(
I);
1461 unsigned ResultReg = 0;
1462 switch (Predicate) {
1465 ResultReg = createResultReg(&X86::GR32RegClass);
1466 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOV32r0),
1468 ResultReg = fastEmitInst_extractsubreg(
MVT::i8, ResultReg,
true,
1475 ResultReg = createResultReg(&X86::GR8RegClass);
1476 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOV8ri),
1477 ResultReg).addImm(1);
1483 updateValueMap(I, ResultReg);
1495 if (RHSC && RHSC->isNullValue())
1500 static const uint16_t SETFOpcTable[2][3] = {
1501 { X86::SETEr, X86::SETNPr, X86::AND8rr },
1502 { X86::SETNEr, X86::SETPr, X86::OR8rr }
1504 const uint16_t *SETFOpc =
nullptr;
1505 switch (Predicate) {
1511 ResultReg = createResultReg(&X86::GR8RegClass);
1513 if (!X86FastEmitCompare(LHS, RHS, VT, I->
getDebugLoc()))
1516 unsigned FlagReg1 = createResultReg(&X86::GR8RegClass);
1517 unsigned FlagReg2 = createResultReg(&X86::GR8RegClass);
1518 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(SETFOpc[0]),
1520 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(SETFOpc[1]),
1522 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(SETFOpc[2]),
1523 ResultReg).addReg(FlagReg1).
addReg(FlagReg2);
1524 updateValueMap(I, ResultReg);
1538 if (!X86FastEmitCompare(LHS, RHS, VT, I->
getDebugLoc()))
1541 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg);
1542 updateValueMap(I, ResultReg);
1546 bool X86FastISel::X86SelectZExt(
const Instruction *I) {
1548 if (!TLI.isTypeLegal(DstVT))
1551 unsigned ResultReg = getRegForValue(I->
getOperand(0));
1559 if (
MRI.getRegClass(ResultReg) == &X86::VK1RegClass) {
1560 unsigned KResultReg = ResultReg;
1561 ResultReg = createResultReg(&X86::GR32RegClass);
1562 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1563 TII.get(TargetOpcode::COPY), ResultReg)
1564 .addReg(KResultReg);
1565 ResultReg = fastEmitInst_extractsubreg(
MVT::i8, ResultReg,
true,
1570 ResultReg = fastEmitZExtFromI1(
MVT::i8, ResultReg,
false);
1582 case MVT::i8: MovInst = X86::MOVZX32rr8;
break;
1583 case MVT::i16: MovInst = X86::MOVZX32rr16;
break;
1584 case MVT::i32: MovInst = X86::MOV32rr;
break;
1588 unsigned Result32 = createResultReg(&X86::GR32RegClass);
1589 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(MovInst), Result32)
1592 ResultReg = createResultReg(&X86::GR64RegClass);
1593 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpcode::SUBREG_TO_REG),
1596 }
else if (DstVT !=
MVT::i8) {
1603 updateValueMap(I, ResultReg);
1607 bool X86FastISel::X86SelectBranch(
const Instruction *I) {
1624 switch (Predicate) {
1639 if (CmpRHSC && CmpRHSC->isNullValue())
1644 if (FuncInfo.MBB->isLayoutSuccessor(TrueMBB)) {
1654 bool NeedExtraBranch =
false;
1655 switch (Predicate) {
1661 NeedExtraBranch =
true;
1676 if (!X86FastEmitCompare(CmpLHS, CmpRHS, VT, CI->
getDebugLoc()))
1679 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(BranchOpc))
1684 if (NeedExtraBranch) {
1685 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::JP_1))
1689 finishCondBranch(BI->
getParent(), TrueMBB, FalseMBB);
1696 if (TI->hasOneUse() && TI->getParent() == I->
getParent() &&
1697 isTypeLegal(TI->getOperand(0)->getType(), SourceVT)) {
1698 unsigned TestOpc = 0;
1701 case MVT::i8: TestOpc = X86::TEST8ri;
break;
1702 case MVT::i16: TestOpc = X86::TEST16ri;
break;
1703 case MVT::i32: TestOpc = X86::TEST32ri;
break;
1704 case MVT::i64: TestOpc = X86::TEST64ri32;
break;
1707 unsigned OpReg = getRegForValue(TI->getOperand(0));
1708 if (OpReg == 0)
return false;
1710 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TestOpc))
1711 .addReg(OpReg).
addImm(1);
1713 unsigned JmpOpc = X86::JNE_1;
1714 if (FuncInfo.MBB->isLayoutSuccessor(TrueMBB)) {
1719 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(JmpOpc))
1722 finishCondBranch(BI->
getParent(), TrueMBB, FalseMBB);
1726 }
else if (foldX86XALUIntrinsic(CC, BI, BI->
getCondition())) {
1735 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(BranchOpc))
1737 finishCondBranch(BI->
getParent(), TrueMBB, FalseMBB);
1745 if (OpReg == 0)
return false;
1748 if (
MRI.getRegClass(OpReg) == &X86::VK1RegClass) {
1749 unsigned KOpReg = OpReg;
1750 OpReg = createResultReg(&X86::GR32RegClass);
1751 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1752 TII.get(TargetOpcode::COPY), OpReg)
1754 OpReg = fastEmitInst_extractsubreg(
MVT::i8, OpReg,
true,
1757 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::TEST8ri))
1760 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::JNE_1))
1762 finishCondBranch(BI->
getParent(), TrueMBB, FalseMBB);
1766 bool X86FastISel::X86SelectShift(
const Instruction *I) {
1767 unsigned CReg = 0, OpReg = 0;
1771 RC = &X86::GR8RegClass;
1773 case Instruction::LShr: OpReg = X86::SHR8rCL;
break;
1774 case Instruction::AShr: OpReg = X86::SAR8rCL;
break;
1775 case Instruction::Shl: OpReg = X86::SHL8rCL;
break;
1776 default:
return false;
1780 RC = &X86::GR16RegClass;
1782 case Instruction::LShr: OpReg = X86::SHR16rCL;
break;
1783 case Instruction::AShr: OpReg = X86::SAR16rCL;
break;
1784 case Instruction::Shl: OpReg = X86::SHL16rCL;
break;
1785 default:
return false;
1789 RC = &X86::GR32RegClass;
1791 case Instruction::LShr: OpReg = X86::SHR32rCL;
break;
1792 case Instruction::AShr: OpReg = X86::SAR32rCL;
break;
1793 case Instruction::Shl: OpReg = X86::SHL32rCL;
break;
1794 default:
return false;
1798 RC = &X86::GR64RegClass;
1800 case Instruction::LShr: OpReg = X86::SHR64rCL;
break;
1801 case Instruction::AShr: OpReg = X86::SAR64rCL;
break;
1802 case Instruction::Shl: OpReg = X86::SHL64rCL;
break;
1803 default:
return false;
1810 if (!isTypeLegal(I->
getType(), VT))
1813 unsigned Op0Reg = getRegForValue(I->
getOperand(0));
1814 if (Op0Reg == 0)
return false;
1816 unsigned Op1Reg = getRegForValue(I->
getOperand(1));
1817 if (Op1Reg == 0)
return false;
1818 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpcode::COPY),
1819 CReg).addReg(Op1Reg);
1823 if (CReg != X86::CL)
1824 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1828 unsigned ResultReg = createResultReg(RC);
1829 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(OpReg), ResultReg)
1831 updateValueMap(I, ResultReg);
1835 bool X86FastISel::X86SelectDivRem(
const Instruction *I) {
1836 const static unsigned NumTypes = 4;
1837 const static unsigned NumOps = 4;
1838 const static bool S =
true;
1839 const static bool U =
false;
1840 const static unsigned Copy = TargetOpcode::COPY;
1850 const static struct DivRemEntry {
1856 struct DivRemResult {
1858 unsigned OpSignExtend;
1862 unsigned DivRemResultReg;
1864 } ResultTable[NumOps];
1865 } OpTable[NumTypes] = {
1866 { &X86::GR8RegClass, X86::AX, 0, {
1867 { X86::IDIV8r, 0, X86::MOVSX16rr8, X86::AL, S },
1868 { X86::IDIV8r, 0, X86::MOVSX16rr8, X86::AH, S },
1869 { X86::DIV8r, 0, X86::MOVZX16rr8, X86::AL, U },
1870 { X86::DIV8r, 0, X86::MOVZX16rr8, X86::AH, U },
1873 { &X86::GR16RegClass, X86::AX, X86::DX, {
1874 { X86::IDIV16r, X86::CWD, Copy, X86::AX, S },
1875 { X86::IDIV16r, X86::CWD, Copy, X86::DX, S },
1876 { X86::DIV16r, X86::MOV32r0, Copy, X86::AX, U },
1877 { X86::DIV16r, X86::MOV32r0, Copy, X86::DX, U },
1880 { &X86::GR32RegClass, X86::EAX, X86::EDX, {
1881 { X86::IDIV32r, X86::CDQ, Copy, X86::EAX, S },
1882 { X86::IDIV32r, X86::CDQ, Copy, X86::EDX, S },
1883 { X86::DIV32r, X86::MOV32r0, Copy, X86::EAX, U },
1884 { X86::DIV32r, X86::MOV32r0, Copy, X86::EDX, U },
1887 { &X86::GR64RegClass, X86::RAX, X86::RDX, {
1888 { X86::IDIV64r, X86::CQO, Copy, X86::RAX, S },
1889 { X86::IDIV64r, X86::CQO, Copy, X86::RDX, S },
1890 { X86::DIV64r, X86::MOV32r0, Copy, X86::RAX, U },
1891 { X86::DIV64r, X86::MOV32r0, Copy, X86::RDX, U },
1897 if (!isTypeLegal(I->
getType(), VT))
1900 unsigned TypeIndex, OpIndex;
1902 default:
return false;
1903 case MVT::i8: TypeIndex = 0;
break;
1904 case MVT::i16: TypeIndex = 1;
break;
1905 case MVT::i32: TypeIndex = 2;
break;
1907 if (!Subtarget->is64Bit())
1914 case Instruction::SDiv: OpIndex = 0;
break;
1915 case Instruction::SRem: OpIndex = 1;
break;
1916 case Instruction::UDiv: OpIndex = 2;
break;
1917 case Instruction::URem: OpIndex = 3;
break;
1920 const DivRemEntry &TypeEntry = OpTable[TypeIndex];
1921 const DivRemEntry::DivRemResult &OpEntry = TypeEntry.ResultTable[OpIndex];
1922 unsigned Op0Reg = getRegForValue(I->
getOperand(0));
1925 unsigned Op1Reg = getRegForValue(I->
getOperand(1));
1930 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1931 TII.get(OpEntry.OpCopy), TypeEntry.LowInReg).addReg(Op0Reg);
1933 if (OpEntry.OpSignExtend) {
1934 if (OpEntry.IsOpSigned)
1935 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1936 TII.get(OpEntry.OpSignExtend));
1938 unsigned Zero32 = createResultReg(&X86::GR32RegClass);
1939 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1940 TII.get(X86::MOV32r0), Zero32);
1946 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1947 TII.get(Copy), TypeEntry.HighInReg)
1948 .addReg(Zero32, 0, X86::sub_16bit);
1950 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1951 TII.get(Copy), TypeEntry.HighInReg)
1954 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1955 TII.get(TargetOpcode::SUBREG_TO_REG), TypeEntry.HighInReg)
1961 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1962 TII.get(OpEntry.OpDivRem)).addReg(Op1Reg);
1971 unsigned ResultReg = 0;
1972 if ((I->
getOpcode() == Instruction::SRem ||
1974 OpEntry.DivRemResultReg == X86::AH && Subtarget->is64Bit()) {
1975 unsigned SourceSuperReg = createResultReg(&X86::GR16RegClass);
1976 unsigned ResultSuperReg = createResultReg(&X86::GR16RegClass);
1977 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1978 TII.get(Copy), SourceSuperReg).addReg(X86::AX);
1981 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::SHR16ri),
1982 ResultSuperReg).addReg(SourceSuperReg).
addImm(8);
1985 ResultReg = fastEmitInst_extractsubreg(
MVT::i8, ResultSuperReg,
1986 true, X86::sub_8bit);
1990 ResultReg = createResultReg(TypeEntry.RC);
1991 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Copy), ResultReg)
1992 .addReg(OpEntry.DivRemResultReg);
1994 updateValueMap(I, ResultReg);
2001 bool X86FastISel::X86FastEmitCMoveSelect(
MVT RetVT,
const Instruction *I) {
2003 if (!Subtarget->hasCMov())
2007 if (RetVT < MVT::i16 || RetVT >
MVT::i64)
2012 bool NeedTest =
true;
2023 static const uint16_t SETFOpcTable[2][3] = {
2024 { X86::SETNPr, X86::SETEr , X86::TEST8rr },
2025 { X86::SETPr, X86::SETNEr, X86::OR8rr }
2027 const uint16_t *SETFOpc =
nullptr;
2028 switch (Predicate) {
2031 SETFOpc = &SETFOpcTable[0][0];
2035 SETFOpc = &SETFOpcTable[1][0];
2051 if (!X86FastEmitCompare(CmpLHS, CmpRHS, CmpVT, CI->
getDebugLoc()))
2055 unsigned FlagReg1 = createResultReg(&X86::GR8RegClass);
2056 unsigned FlagReg2 = createResultReg(&X86::GR8RegClass);
2057 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(SETFOpc[0]),
2059 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(SETFOpc[1]),
2061 auto const &II =
TII.get(SETFOpc[2]);
2062 if (II.getNumDefs()) {
2063 unsigned TmpReg = createResultReg(&X86::GR8RegClass);
2064 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, TmpReg)
2067 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
2072 }
else if (foldX86XALUIntrinsic(CC, I, Cond)) {
2075 unsigned TmpReg = getRegForValue(Cond);
2088 unsigned CondReg = getRegForValue(Cond);
2091 bool CondIsKill = hasTrivialKill(Cond);
2094 if (
MRI.getRegClass(CondReg) == &X86::VK1RegClass) {
2095 unsigned KCondReg = CondReg;
2096 CondReg = createResultReg(&X86::GR32RegClass);
2097 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2098 TII.get(TargetOpcode::COPY), CondReg)
2100 CondReg = fastEmitInst_extractsubreg(
MVT::i8, CondReg,
true,
2103 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::TEST8ri))
2111 unsigned RHSReg = getRegForValue(RHS);
2112 bool RHSIsKill = hasTrivialKill(RHS);
2114 unsigned LHSReg = getRegForValue(LHS);
2115 bool LHSIsKill = hasTrivialKill(LHS);
2117 if (!LHSReg || !RHSReg)
2122 unsigned ResultReg = fastEmitInst_rr(Opc, RC, RHSReg, RHSIsKill,
2124 updateValueMap(I, ResultReg);
2133 bool X86FastISel::X86FastEmitSSESelect(
MVT RetVT,
const Instruction *I) {
2142 !((Subtarget->hasSSE1() && RetVT ==
MVT::f32) ||
2143 (Subtarget->hasSSE2() && RetVT ==
MVT::f64)))
2155 if (CmpRHSC && CmpRHSC->isNullValue())
2169 static const uint16_t OpcTable[2][4] = {
2170 { X86::CMPSSrr, X86::ANDPSrr, X86::ANDNPSrr, X86::ORPSrr },
2171 { X86::CMPSDrr, X86::ANDPDrr, X86::ANDNPDrr, X86::ORPDrr }
2174 const uint16_t *Opc =
nullptr;
2176 default:
return false;
2177 case MVT::f32: Opc = &OpcTable[0][0];
break;
2178 case MVT::f64: Opc = &OpcTable[1][0];
break;
2184 unsigned LHSReg = getRegForValue(LHS);
2185 bool LHSIsKill = hasTrivialKill(LHS);
2187 unsigned RHSReg = getRegForValue(RHS);
2188 bool RHSIsKill = hasTrivialKill(RHS);
2190 unsigned CmpLHSReg = getRegForValue(CmpLHS);
2191 bool CmpLHSIsKill = hasTrivialKill(CmpLHS);
2193 unsigned CmpRHSReg = getRegForValue(CmpRHS);
2194 bool CmpRHSIsKill = hasTrivialKill(CmpRHS);
2196 if (!LHSReg || !RHSReg || !CmpLHS || !CmpRHS)
2202 if (Subtarget->hasAVX512()) {
2207 unsigned CmpOpcode =
2208 (RetVT ==
MVT::f32) ? X86::VCMPSSZrr : X86::VCMPSDZrr;
2209 unsigned CmpReg = fastEmitInst_rri(CmpOpcode, VK1, CmpLHSReg, CmpLHSIsKill,
2210 CmpRHSReg, CmpRHSIsKill, CC);
2214 unsigned ImplicitDefReg = createResultReg(VR128X);
2215 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2216 TII.get(TargetOpcode::IMPLICIT_DEF), ImplicitDefReg);
2220 unsigned MovOpcode =
2221 (RetVT ==
MVT::f32) ? X86::VMOVSSZrrk : X86::VMOVSDZrrk;
2222 unsigned MovReg = fastEmitInst_rrrr(MovOpcode, VR128X, RHSReg, RHSIsKill,
2223 CmpReg,
true, ImplicitDefReg,
true,
2226 ResultReg = createResultReg(RC);
2227 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2228 TII.get(TargetOpcode::COPY), ResultReg).addReg(MovReg);
2230 }
else if (Subtarget->hasAVX()) {
2238 unsigned CmpOpcode =
2239 (RetVT ==
MVT::f32) ? X86::VCMPSSrr : X86::VCMPSDrr;
2240 unsigned BlendOpcode =
2241 (RetVT ==
MVT::f32) ? X86::VBLENDVPSrr : X86::VBLENDVPDrr;
2243 unsigned CmpReg = fastEmitInst_rri(CmpOpcode, RC, CmpLHSReg, CmpLHSIsKill,
2244 CmpRHSReg, CmpRHSIsKill, CC);
2245 unsigned VBlendReg = fastEmitInst_rrr(BlendOpcode, VR128, RHSReg, RHSIsKill,
2246 LHSReg, LHSIsKill, CmpReg,
true);
2247 ResultReg = createResultReg(RC);
2248 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2249 TII.get(TargetOpcode::COPY), ResultReg).addReg(VBlendReg);
2252 unsigned CmpReg = fastEmitInst_rri(Opc[0], RC, CmpLHSReg, CmpLHSIsKill,
2253 CmpRHSReg, CmpRHSIsKill, CC);
2254 unsigned AndReg = fastEmitInst_rr(Opc[1], VR128, CmpReg,
false,
2256 unsigned AndNReg = fastEmitInst_rr(Opc[2], VR128, CmpReg,
true,
2258 unsigned OrReg = fastEmitInst_rr(Opc[3], VR128, AndNReg,
true,
2260 ResultReg = createResultReg(RC);
2261 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2262 TII.get(TargetOpcode::COPY), ResultReg).addReg(OrReg);
2264 updateValueMap(I, ResultReg);
2268 bool X86FastISel::X86FastEmitPseudoSelect(
MVT RetVT,
const Instruction *I) {
2273 default:
return false;
2274 case MVT::i8: Opc = X86::CMOV_GR8;
break;
2275 case MVT::i16: Opc = X86::CMOV_GR16;
break;
2276 case MVT::i32: Opc = X86::CMOV_GR32;
break;
2277 case MVT::f32: Opc = X86::CMOV_FR32;
break;
2278 case MVT::f64: Opc = X86::CMOV_FR64;
break;
2301 if (!X86FastEmitCompare(CmpLHS, CmpRHS, CmpVT, CI->
getDebugLoc()))
2304 unsigned CondReg = getRegForValue(Cond);
2307 bool CondIsKill = hasTrivialKill(Cond);
2310 if (
MRI.getRegClass(CondReg) == &X86::VK1RegClass) {
2311 unsigned KCondReg = CondReg;
2312 CondReg = createResultReg(&X86::GR32RegClass);
2313 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2314 TII.get(TargetOpcode::COPY), CondReg)
2316 CondReg = fastEmitInst_extractsubreg(
MVT::i8, CondReg,
true,
2319 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::TEST8ri))
2327 unsigned LHSReg = getRegForValue(LHS);
2328 bool LHSIsKill = hasTrivialKill(LHS);
2330 unsigned RHSReg = getRegForValue(RHS);
2331 bool RHSIsKill = hasTrivialKill(RHS);
2333 if (!LHSReg || !RHSReg)
2338 unsigned ResultReg =
2339 fastEmitInst_rri(Opc, RC, RHSReg, RHSIsKill, LHSReg, LHSIsKill, CC);
2340 updateValueMap(I, ResultReg);
2344 bool X86FastISel::X86SelectSelect(
const Instruction *I) {
2346 if (!isTypeLegal(I->
getType(), RetVT))
2350 if (
const auto *CI = dyn_cast<CmpInst>(I->
getOperand(0))) {
2352 const Value *Opnd =
nullptr;
2353 switch (Predicate) {
2360 unsigned OpReg = getRegForValue(Opnd);
2363 bool OpIsKill = hasTrivialKill(Opnd);
2365 unsigned ResultReg = createResultReg(RC);
2366 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2367 TII.get(TargetOpcode::COPY), ResultReg)
2369 updateValueMap(I, ResultReg);
2375 if (X86FastEmitCMoveSelect(RetVT, I))
2379 if (X86FastEmitSSESelect(RetVT, I))
2384 if (X86FastEmitPseudoSelect(RetVT, I))
2390 bool X86FastISel::X86SelectSIToFP(
const Instruction *I) {
2394 if (!Subtarget->hasAVX())
2401 unsigned OpReg = getRegForValue(I->
getOperand(0));
2410 Opcode = X86::VCVTSI2SDrr;
2411 RC = &X86::FR64RegClass;
2414 Opcode = X86::VCVTSI2SSrr;
2415 RC = &X86::FR32RegClass;
2419 unsigned ImplicitDefReg = createResultReg(RC);
2420 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2421 TII.get(TargetOpcode::IMPLICIT_DEF), ImplicitDefReg);
2422 unsigned ResultReg =
2423 fastEmitInst_rr(Opcode, RC, ImplicitDefReg,
true, OpReg,
false);
2424 updateValueMap(I, ResultReg);
2429 bool X86FastISel::X86SelectFPExtOrFPTrunc(
const Instruction *I,
2433 I->
getOpcode() == Instruction::FPTrunc) &&
2434 "Instruction must be an FPExt or FPTrunc!");
2436 unsigned OpReg = getRegForValue(I->
getOperand(0));
2440 unsigned ImplicitDefReg;
2441 if (Subtarget->hasAVX()) {
2442 ImplicitDefReg = createResultReg(RC);
2443 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2444 TII.get(TargetOpcode::IMPLICIT_DEF), ImplicitDefReg);
2448 unsigned ResultReg = createResultReg(RC);
2450 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpc),
2453 if (Subtarget->hasAVX())
2454 MIB.
addReg(ImplicitDefReg);
2457 updateValueMap(I, ResultReg);
2461 bool X86FastISel::X86SelectFPExt(
const Instruction *I) {
2465 unsigned Opc = Subtarget->hasAVX() ? X86::VCVTSS2SDrr : X86::CVTSS2SDrr;
2466 return X86SelectFPExtOrFPTrunc(I, Opc, &X86::FR64RegClass);
2472 bool X86FastISel::X86SelectFPTrunc(
const Instruction *I) {
2476 unsigned Opc = Subtarget->hasAVX() ? X86::VCVTSD2SSrr : X86::CVTSD2SSrr;
2477 return X86SelectFPExtOrFPTrunc(I, Opc, &X86::FR32RegClass);
2483 bool X86FastISel::X86SelectTrunc(
const Instruction *I) {
2489 if (DstVT !=
MVT::i8 && (DstVT !=
MVT::i1 || Subtarget->hasAVX512()))
2491 if (!TLI.isTypeLegal(SrcVT))
2494 unsigned InputReg = getRegForValue(I->
getOperand(0));
2501 updateValueMap(I, InputReg);
2505 bool KillInputReg =
false;
2506 if (!Subtarget->is64Bit()) {
2510 (SrcVT ==
MVT::i16) ? &X86::GR16_ABCDRegClass : &X86::GR32_ABCDRegClass;
2511 unsigned CopyReg = createResultReg(CopyRC);
2512 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2513 TII.get(TargetOpcode::COPY), CopyReg).addReg(InputReg);
2515 KillInputReg =
true;
2519 unsigned ResultReg = fastEmitInst_extractsubreg(
MVT::i8,
2520 InputReg, KillInputReg,
2525 updateValueMap(I, ResultReg);
2529 bool X86FastISel::IsMemcpySmall(uint64_t Len) {
2530 return Len <= (Subtarget->is64Bit() ? 32 : 16);
2537 if (!IsMemcpySmall(Len))
2540 bool i64Legal = Subtarget->is64Bit();
2545 if (Len >= 8 && i64Legal)
2555 bool RV = X86FastEmitLoad(VT, SrcAM,
nullptr, Reg);
2556 RV &= X86FastEmitStore(VT, Reg,
true, DestAM);
2557 assert(RV &&
"Failed to emit load or store??");
2568 bool X86FastISel::fastLowerIntrinsicCall(
const IntrinsicInst *II) {
2571 default:
return false;
2572 case Intrinsic::convert_from_fp16:
2573 case Intrinsic::convert_to_fp16: {
2574 if (Subtarget->useSoftFloat() || !Subtarget->hasF16C())
2578 unsigned InputReg = getRegForValue(Op);
2583 bool IsFloatToHalf = II->
getIntrinsicID() == Intrinsic::convert_to_fp16;
2584 if (IsFloatToHalf) {
2592 unsigned ResultReg = 0;
2594 if (IsFloatToHalf) {
2602 InputReg = fastEmitInst_ri(X86::VCVTPS2PHrr, RC, InputReg,
false, 4);
2605 ResultReg = createResultReg(&X86::GR32RegClass);
2606 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2607 TII.get(X86::VMOVPDI2DIrr), ResultReg)
2611 unsigned RegIdx = X86::sub_16bit;
2612 ResultReg = fastEmitInst_extractsubreg(
MVT::i16, ResultReg,
true, RegIdx);
2623 InputReg = fastEmitInst_r(X86::VCVTPH2PSrr, RC, InputReg,
true);
2627 ResultReg = createResultReg(&X86::FR32RegClass);
2628 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2629 TII.get(TargetOpcode::COPY), ResultReg)
2633 updateValueMap(II, ResultReg);
2636 case Intrinsic::frameaddress: {
2644 if (!isTypeLegal(RetTy, VT))
2652 case MVT::i32: Opc = X86::MOV32rm; RC = &X86::GR32RegClass;
break;
2653 case MVT::i64: Opc = X86::MOV64rm; RC = &X86::GR64RegClass;
break;
2663 assert(((FrameReg == X86::RBP && VT == MVT::i64) ||
2664 (FrameReg == X86::EBP && VT ==
MVT::i32)) &&
2665 "Invalid Frame Register!");
2670 unsigned SrcReg = createResultReg(RC);
2671 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2672 TII.get(TargetOpcode::COPY), SrcReg).addReg(FrameReg);
2680 unsigned Depth = cast<ConstantInt>(II->
getOperand(0))->getZExtValue();
2682 DestReg = createResultReg(RC);
2684 TII.get(Opc), DestReg), SrcReg);
2688 updateValueMap(II, SrcReg);
2691 case Intrinsic::memcpy: {
2692 const MemCpyInst *MCI = cast<MemCpyInst>(II);
2697 if (isa<ConstantInt>(MCI->
getLength())) {
2700 uint64_t Len = cast<ConstantInt>(MCI->
getLength())->getZExtValue();
2701 if (IsMemcpySmall(Len)) {
2706 TryEmitSmallMemcpy(DestAM, SrcAM, Len);
2711 unsigned SizeWidth = Subtarget->is64Bit() ? 64 : 32;
2720 case Intrinsic::memset: {
2721 const MemSetInst *MSI = cast<MemSetInst>(II);
2726 unsigned SizeWidth = Subtarget->is64Bit() ? 64 : 32;
2735 case Intrinsic::stackprotector: {
2737 EVT PtrTy = TLI.getPointerTy(
DL);
2747 if (!X86FastEmitStore(PtrTy, Op1, AM))
return false;
2750 case Intrinsic::dbg_declare: {
2760 "Expected inlined-at fields to agree");
2767 case Intrinsic::trap: {
2771 case Intrinsic::sqrt: {
2772 if (!Subtarget->hasSSE1())
2775 Type *RetTy = II->getCalledFunction()->getReturnType();
2778 if (!isTypeLegal(RetTy, VT))
2784 static const uint16_t SqrtOpc[2][2] = {
2785 {X86::SQRTSSr, X86::VSQRTSSr},
2786 {X86::SQRTSDr, X86::VSQRTSDr}
2788 bool HasAVX = Subtarget->hasAVX();
2792 default:
return false;
2793 case MVT::f32: Opc = SqrtOpc[0][HasAVX]; RC = &X86::FR32RegClass;
break;
2794 case MVT::f64: Opc = SqrtOpc[1][HasAVX]; RC = &X86::FR64RegClass;
break;
2797 const Value *SrcVal = II->getArgOperand(0);
2798 unsigned SrcReg = getRegForValue(SrcVal);
2803 unsigned ImplicitDefReg = 0;
2805 ImplicitDefReg = createResultReg(RC);
2806 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2807 TII.get(TargetOpcode::IMPLICIT_DEF), ImplicitDefReg);
2810 unsigned ResultReg = createResultReg(RC);
2812 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc),
2816 MIB.
addReg(ImplicitDefReg);
2820 updateValueMap(II, ResultReg);
2823 case Intrinsic::sadd_with_overflow:
2824 case Intrinsic::uadd_with_overflow:
2825 case Intrinsic::ssub_with_overflow:
2826 case Intrinsic::usub_with_overflow:
2827 case Intrinsic::smul_with_overflow:
2828 case Intrinsic::umul_with_overflow: {
2831 const Function *Callee = II->getCalledFunction();
2833 Type *RetTy = Ty->getTypeAtIndex(0U);
2836 "Overflow value expected to be an i1");
2839 if (!isTypeLegal(RetTy, VT))
2842 if (VT < MVT::i8 || VT > MVT::i64)
2845 const Value *LHS = II->getArgOperand(0);
2846 const Value *RHS = II->getArgOperand(1);
2849 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS) &&
2850 isCommutativeIntrinsic(II))
2853 bool UseIncDec =
false;
2854 if (isa<ConstantInt>(RHS) && cast<ConstantInt>(RHS)->isOne())
2857 unsigned BaseOpc, CondOpc;
2858 switch (II->getIntrinsicID()) {
2860 case Intrinsic::sadd_with_overflow:
2862 CondOpc = X86::SETOr;
2864 case Intrinsic::uadd_with_overflow:
2865 BaseOpc =
ISD::ADD; CondOpc = X86::SETBr;
break;
2866 case Intrinsic::ssub_with_overflow:
2867 BaseOpc = UseIncDec ? unsigned(
X86ISD::DEC) : unsigned(ISD::
SUB);
2868 CondOpc = X86::SETOr;
2870 case Intrinsic::usub_with_overflow:
2871 BaseOpc =
ISD::SUB; CondOpc = X86::SETBr;
break;
2872 case Intrinsic::smul_with_overflow:
2874 case Intrinsic::umul_with_overflow:
2878 unsigned LHSReg = getRegForValue(LHS);
2881 bool LHSIsKill = hasTrivialKill(LHS);
2883 unsigned ResultReg = 0;
2885 if (
const auto *CI = dyn_cast<ConstantInt>(RHS)) {
2886 static const uint16_t Opc[2][4] = {
2887 { X86::INC8r, X86::INC16r, X86::INC32r, X86::INC64r },
2888 { X86::DEC8r, X86::DEC16r, X86::DEC32r, X86::DEC64r }
2892 ResultReg = createResultReg(TLI.getRegClassFor(VT));
2894 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2895 TII.get(Opc[IsDec][VT.SimpleTy-
MVT::i8]), ResultReg)
2898 ResultReg = fastEmit_ri(VT, VT, BaseOpc, LHSReg, LHSIsKill,
2899 CI->getZExtValue());
2905 RHSReg = getRegForValue(RHS);
2908 RHSIsKill = hasTrivialKill(RHS);
2909 ResultReg = fastEmit_rr(VT, VT, BaseOpc, LHSReg, LHSIsKill, RHSReg,
2916 static const uint16_t MULOpc[] =
2917 { X86::MUL8r, X86::MUL16r, X86::MUL32r, X86::MUL64r };
2918 static const MCPhysReg Reg[] = { X86::AL, X86::AX, X86::EAX, X86::RAX };
2921 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2922 TII.get(TargetOpcode::COPY), Reg[VT.SimpleTy-
MVT::i8])
2924 ResultReg = fastEmitInst_r(MULOpc[VT.SimpleTy-
MVT::i8],
2925 TLI.getRegClassFor(VT), RHSReg, RHSIsKill);
2927 static const uint16_t MULOpc[] =
2928 { X86::IMUL8r, X86::IMUL16rr, X86::IMUL32rr, X86::IMUL64rr };
2932 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2933 TII.get(TargetOpcode::COPY), X86::AL)
2935 ResultReg = fastEmitInst_r(MULOpc[0], TLI.getRegClassFor(VT), RHSReg,
2938 ResultReg = fastEmitInst_rr(MULOpc[VT.SimpleTy-
MVT::i8],
2939 TLI.getRegClassFor(VT), LHSReg, LHSIsKill,
2947 unsigned ResultReg2 = createResultReg(&X86::GR8RegClass);
2948 assert((ResultReg+1) == ResultReg2 &&
"Nonconsecutive result registers.");
2949 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(CondOpc),
2952 updateValueMap(II, ResultReg, 2);
2955 case Intrinsic::x86_sse_cvttss2si:
2956 case Intrinsic::x86_sse_cvttss2si64:
2957 case Intrinsic::x86_sse2_cvttsd2si:
2958 case Intrinsic::x86_sse2_cvttsd2si64: {
2960 switch (II->getIntrinsicID()) {
2962 case Intrinsic::x86_sse_cvttss2si:
2963 case Intrinsic::x86_sse_cvttss2si64:
2964 if (!Subtarget->hasSSE1())
2966 IsInputDouble =
false;
2968 case Intrinsic::x86_sse2_cvttsd2si:
2969 case Intrinsic::x86_sse2_cvttsd2si64:
2970 if (!Subtarget->hasSSE2())
2972 IsInputDouble =
true;
2976 Type *RetTy = II->getCalledFunction()->getReturnType();
2978 if (!isTypeLegal(RetTy, VT))
2981 static const uint16_t CvtOpc[2][2][2] = {
2982 { { X86::CVTTSS2SIrr, X86::VCVTTSS2SIrr },
2983 { X86::CVTTSS2SI64rr, X86::VCVTTSS2SI64rr } },
2984 { { X86::CVTTSD2SIrr, X86::VCVTTSD2SIrr },
2985 { X86::CVTTSD2SI64rr, X86::VCVTTSD2SI64rr } }
2987 bool HasAVX = Subtarget->hasAVX();
2991 case MVT::i32: Opc = CvtOpc[IsInputDouble][0][HasAVX];
break;
2992 case MVT::i64: Opc = CvtOpc[IsInputDouble][1][HasAVX];
break;
2996 const Value *Op = II->getArgOperand(0);
2997 while (
auto *
IE = dyn_cast<InsertElementInst>(Op)) {
2998 const Value *Index =
IE->getOperand(2);
2999 if (!isa<ConstantInt>(Index))
3001 unsigned Idx = cast<ConstantInt>(Index)->getZExtValue();
3004 Op =
IE->getOperand(1);
3007 Op =
IE->getOperand(0);
3010 unsigned Reg = getRegForValue(Op);
3014 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
3015 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
3018 updateValueMap(II, ResultReg);
3024 bool X86FastISel::fastLowerArguments() {
3025 if (!FuncInfo.CanLowerReturn)
3036 if (Subtarget->isCallingConvWin64(CC))
3039 if (!Subtarget->is64Bit())
3042 if (Subtarget->useSoftFloat())
3046 unsigned GPRCnt = 0;
3047 unsigned FPRCnt = 0;
3048 for (
auto const &Arg : F->
args()) {
3049 if (Arg.hasAttribute(Attribute::ByVal) ||
3050 Arg.hasAttribute(Attribute::InReg) ||
3051 Arg.hasAttribute(Attribute::StructRet) ||
3052 Arg.hasAttribute(Attribute::SwiftSelf) ||
3053 Arg.hasAttribute(Attribute::SwiftError) ||
3054 Arg.hasAttribute(Attribute::Nest))
3057 Type *ArgTy = Arg.getType();
3061 EVT ArgVT = TLI.getValueType(
DL, ArgTy);
3062 if (!ArgVT.
isSimple())
return false;
3064 default:
return false;
3071 if (!Subtarget->hasSSE1())
3084 static const MCPhysReg GPR32ArgRegs[] = {
3085 X86::EDI, X86::ESI, X86::EDX, X86::ECX, X86::R8D, X86::R9D
3087 static const MCPhysReg GPR64ArgRegs[] = {
3088 X86::RDI, X86::RSI, X86::RDX, X86::RCX, X86::R8 , X86::R9
3091 X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3,
3092 X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7
3095 unsigned GPRIdx = 0;
3096 unsigned FPRIdx = 0;
3097 for (
auto const &Arg : F->
args()) {
3098 MVT VT = TLI.getSimpleValueType(
DL, Arg.getType());
3103 case MVT::i32: SrcReg = GPR32ArgRegs[GPRIdx++];
break;
3104 case MVT::i64: SrcReg = GPR64ArgRegs[GPRIdx++];
break;
3106 case MVT::f64: SrcReg = XMMArgRegs[FPRIdx++];
break;
3108 unsigned DstReg = FuncInfo.MF->addLiveIn(SrcReg, RC);
3112 unsigned ResultReg = createResultReg(RC);
3113 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3114 TII.get(TargetOpcode::COPY), ResultReg)
3116 updateValueMap(&Arg, ResultReg);
3140 bool X86FastISel::fastLowerCall(CallLoweringInfo &CLI) {
3141 auto &OutVals = CLI.OutVals;
3142 auto &OutFlags = CLI.OutFlags;
3143 auto &OutRegs = CLI.OutRegs;
3144 auto &
Ins = CLI.Ins;
3145 auto &InRegs = CLI.InRegs;
3147 bool &IsTailCall = CLI.IsTailCall;
3148 bool IsVarArg = CLI.IsVarArg;
3149 const Value *Callee = CLI.Callee;
3152 bool Is64Bit = Subtarget->is64Bit();
3153 bool IsWin64 = Subtarget->isCallingConvWin64(CC);
3160 if ((CI && CI->
hasFnAttr(
"no_caller_saved_registers")) ||
3161 (CalledFn && CalledFn->hasFnAttribute(
"no_caller_saved_registers")))
3166 default:
return false;
3190 if (IsVarArg && IsWin64)
3194 if (CLI.CS && CLI.CS->hasInAllocaArgument())
3197 for (
auto Flag : CLI.OutFlags)
3198 if (
Flag.isSwiftError())
3207 for (
int i = 0, e = OutVals.size(); i != e; ++i) {
3208 Value *&Val = OutVals[i];
3210 if (
auto *CI = dyn_cast<ConstantInt>(Val)) {
3211 if (CI->getBitWidth() < 32) {
3224 if (TI && TI->getType()->isIntegerTy(1) && CLI.CS &&
3225 (TI->getParent() == CLI.CS->getInstruction()->getParent()) &&
3227 Value *PrevVal = TI->getOperand(0);
3228 ResultReg = getRegForValue(PrevVal);
3233 if (!isTypeLegal(PrevVal->
getType(), VT))
3237 fastEmit_ri(VT, VT,
ISD::AND, ResultReg, hasTrivialKill(PrevVal), 1);
3239 if (!isTypeLegal(Val->
getType(), VT))
3241 ResultReg = getRegForValue(Val);
3253 CCState CCInfo(CC, IsVarArg, *FuncInfo.MF, ArgLocs, CLI.RetTy->getContext());
3259 CCInfo.AnalyzeCallOperands(OutVTs, OutFlags, CC_X86);
3262 unsigned NumBytes = CCInfo.getAlignedCallFrameSize();
3265 unsigned AdjStackDown =
TII.getCallFrameSetupOpcode();
3266 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AdjStackDown))
3271 for (
unsigned i = 0, e = ArgLocs.
size(); i != e; ++i) {
3279 unsigned ArgReg = ArgRegs[VA.
getValNo()];
3286 "Unexpected extend");
3293 assert(Emitted &&
"Failed to emit a sext!"); (void)Emitted;
3299 "Unexpected extend");
3304 if (
MRI.getRegClass(ArgReg) == &X86::VK1RegClass) {
3305 unsigned KArgReg = ArgReg;
3306 ArgReg = createResultReg(&X86::GR32RegClass);
3307 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3308 TII.get(TargetOpcode::COPY), ArgReg)
3310 ArgReg = fastEmitInst_extractsubreg(
MVT::i8, ArgReg,
true,
3314 ArgReg = fastEmitZExtFromI1(
MVT::i8, ArgReg,
false);
3323 assert(Emitted &&
"Failed to emit a zext!"); (void)Emitted;
3329 "Unexpected extend");
3339 assert(Emitted &&
"Failed to emit a aext!"); (void)Emitted;
3346 assert(ArgReg &&
"Failed to emit a bitcast!");
3366 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3367 TII.get(TargetOpcode::COPY), VA.
getLocReg()).addReg(ArgReg);
3373 if (isa<UndefValue>(ArgVal))
3379 AM.
Disp = LocMemOffset;
3388 if (!TryEmitSmallMemcpy(AM, SrcAM, Flags.
getByValSize()))
3390 }
else if (isa<ConstantInt>(ArgVal) || isa<ConstantPointerNull>(ArgVal)) {
3394 if (!X86FastEmitStore(ArgVT, ArgVal, AM, MMO))
3397 bool ValIsKill = hasTrivialKill(ArgVal);
3398 if (!X86FastEmitStore(ArgVT, ArgReg, ValIsKill, AM, MMO))
3406 if (Subtarget->isPICStyleGOT()) {
3407 unsigned Base = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
3408 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3409 TII.get(TargetOpcode::COPY), X86::EBX).addReg(Base);
3412 if (Is64Bit && IsVarArg && !IsWin64) {
3423 X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3,
3424 X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7
3426 unsigned NumXMMRegs = CCInfo.getFirstUnallocated(XMMArgRegs);
3427 assert((Subtarget->hasSSE1() || !NumXMMRegs)
3428 &&
"SSE registers cannot be used when SSE is disabled");
3429 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOV8ri),
3430 X86::AL).addImm(NumXMMRegs);
3436 if (!X86SelectCallAddress(Callee, CalleeAM))
3439 unsigned CalleeOp = 0;
3441 if (CalleeAM.
GV !=
nullptr) {
3443 }
else if (CalleeAM.
Base.
Reg != 0) {
3452 unsigned CallOpc = Is64Bit ? X86::CALL64r : X86::CALL32r;
3453 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(CallOpc))
3457 assert(GV &&
"Not a direct call");
3458 unsigned CallOpc = Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32;
3461 unsigned char OpFlags = Subtarget->classifyGlobalFunctionReference(GV);
3466 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(CallOpc));
3468 MIB.
addSym(Symbol, OpFlags);
3478 if (Subtarget->isPICStyleGOT())
3481 if (Is64Bit && IsVarArg && !IsWin64)
3485 for (
auto Reg : OutRegs)
3489 unsigned NumBytesForCalleeToPop =
3491 TM.Options.GuaranteedTailCallOpt)
3494 unsigned AdjStackUp =
TII.getCallFrameDestroyOpcode();
3495 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AdjStackUp))
3496 .addImm(NumBytes).
addImm(NumBytesForCalleeToPop);
3500 CCState CCRetInfo(CC, IsVarArg, *FuncInfo.MF, RVLocs,
3501 CLI.RetTy->getContext());
3505 unsigned ResultReg = FuncInfo.CreateRegs(CLI.RetTy);
3506 for (
unsigned i = 0; i != RVLocs.
size(); ++i) {
3509 unsigned CopyReg = ResultReg + i;
3514 ((Is64Bit ||
Ins[i].Flags.
isInReg()) && !Subtarget->hasSSE1())) {
3520 if (CopyVT ==
MVT::i1 && SrcReg == X86::AL && Subtarget->hasAVX512()) {
3523 SrcReg = createResultReg(&X86::GR32RegClass);
3524 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3525 TII.get(X86::MOVZX32rr8), SrcReg).addReg(X86::AL);
3530 if ((SrcReg == X86::FP0 || SrcReg == X86::FP1) &&
3531 isScalarFPTypeInSSEReg(VA.
getValVT())) {
3533 CopyReg = createResultReg(&X86::RFP80RegClass);
3537 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3538 TII.get(TargetOpcode::COPY), CopyReg).addReg(SrcReg);
3546 unsigned Opc = ResVT ==
MVT::f32 ? X86::ST_Fp80m32 : X86::ST_Fp80m64;
3552 Opc = ResVT ==
MVT::f32 ? X86::MOVSSrm : X86::MOVSDrm;
3554 TII.get(Opc), ResultReg + i), FI);
3558 CLI.ResultReg = ResultReg;
3559 CLI.NumResultRegs = RVLocs.
size();
3566 X86FastISel::fastSelectInstruction(
const Instruction *I) {
3570 return X86SelectLoad(I);
3572 return X86SelectStore(I);
3574 return X86SelectRet(I);
3575 case Instruction::ICmp:
3576 case Instruction::FCmp:
3577 return X86SelectCmp(I);
3578 case Instruction::ZExt:
3579 return X86SelectZExt(I);
3580 case Instruction::Br:
3581 return X86SelectBranch(I);
3582 case Instruction::LShr:
3583 case Instruction::AShr:
3584 case Instruction::Shl:
3585 return X86SelectShift(I);
3586 case Instruction::SDiv:
3587 case Instruction::UDiv:
3588 case Instruction::SRem:
3589 case Instruction::URem:
3590 return X86SelectDivRem(I);
3592 return X86SelectSelect(I);
3593 case Instruction::Trunc:
3594 return X86SelectTrunc(I);
3595 case Instruction::FPExt:
3596 return X86SelectFPExt(I);
3597 case Instruction::FPTrunc:
3598 return X86SelectFPTrunc(I);
3599 case Instruction::SIToFP:
3600 return X86SelectSIToFP(I);
3601 case Instruction::IntToPtr:
3602 case Instruction::PtrToInt: {
3606 return X86SelectZExt(I);
3608 return X86SelectTrunc(I);
3609 unsigned Reg = getRegForValue(I->
getOperand(0));
3610 if (Reg == 0)
return false;
3611 updateValueMap(I, Reg);
3614 case Instruction::BitCast: {
3616 if (!Subtarget->hasSSE2())
3635 unsigned Reg = getRegForValue(I->
getOperand(0));
3641 updateValueMap(I, Reg);
3649 unsigned X86FastISel::X86MaterializeInt(
const ConstantInt *CI,
MVT VT) {
3655 unsigned SrcReg = fastEmitInst_(X86::MOV32r0, &X86::GR32RegClass);
3660 return fastEmitInst_extractsubreg(
MVT::i8, SrcReg,
true,
3663 return fastEmitInst_extractsubreg(
MVT::i16, SrcReg,
true,
3668 unsigned ResultReg = createResultReg(&X86::GR64RegClass);
3669 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3670 TII.get(TargetOpcode::SUBREG_TO_REG), ResultReg)
3682 if (Subtarget->hasAVX512())
3686 case MVT::i8: Opc = X86::MOV8ri;
break;
3687 case MVT::i16: Opc = X86::MOV16ri;
break;
3688 case MVT::i32: Opc = X86::MOV32ri;
break;
3693 Opc = X86::MOV64ri32;
3699 if (VT == MVT::i64 && Opc == X86::MOV32ri) {
3700 unsigned SrcReg = fastEmitInst_i(Opc, &X86::GR32RegClass, Imm);
3701 unsigned ResultReg = createResultReg(&X86::GR64RegClass);
3702 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3703 TII.get(TargetOpcode::SUBREG_TO_REG), ResultReg)
3707 return fastEmitInst_i(Opc, TLI.getRegClassFor(VT), Imm);
3710 unsigned X86FastISel::X86MaterializeFP(
const ConstantFP *CFP,
MVT VT) {
3712 return fastMaterializeFloatZero(CFP);
3725 if (X86ScalarSSEf32) {
3726 Opc = Subtarget->hasAVX() ? X86::VMOVSSrm : X86::MOVSSrm;
3727 RC = &X86::FR32RegClass;
3729 Opc = X86::LD_Fp32m;
3730 RC = &X86::RFP32RegClass;
3734 if (X86ScalarSSEf64) {
3735 Opc = Subtarget->hasAVX() ? X86::VMOVSDrm : X86::MOVSDrm;
3736 RC = &X86::FR64RegClass;
3738 Opc = X86::LD_Fp64m;
3739 RC = &X86::RFP64RegClass;
3755 unsigned PICBase = 0;
3756 unsigned char OpFlag = Subtarget->classifyLocalReference(
nullptr);
3758 PICBase = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
3760 PICBase = getInstrInfo()->getGlobalBaseReg(FuncInfo.MF);
3765 unsigned CPI = MCP.getConstantPoolIndex(CFP, Align);
3766 unsigned ResultReg = createResultReg(RC);
3769 unsigned AddrReg = createResultReg(&X86::GR64RegClass);
3770 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOV64ri),
3772 .addConstantPoolIndex(CPI, 0, OpFlag);
3774 TII.get(Opc), ResultReg);
3784 TII.get(Opc), ResultReg),
3785 CPI, PICBase, OpFlag);
3789 unsigned X86FastISel::X86MaterializeGV(
const GlobalValue *GV,
MVT VT) {
3803 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
3808 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(X86::MOV64ri),
3810 .addGlobalAddress(GV);
3814 ? (Subtarget->isTarget64BitILP32() ? X86::LEA64_32r : X86::LEA32r)
3817 TII.get(Opc), ResultReg), AM);
3824 unsigned X86FastISel::fastMaterializeConstant(
const Constant *
C) {
3832 if (
const auto *CI = dyn_cast<ConstantInt>(C))
3833 return X86MaterializeInt(CI, VT);
3834 else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
3835 return X86MaterializeFP(CFP, VT);
3836 else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C))
3837 return X86MaterializeGV(GV, VT);
3842 unsigned X86FastISel::fastMaterializeAlloca(
const AllocaInst *C) {
3850 if (!FuncInfo.StaticAllocaMap.count(C))
3859 ? (Subtarget->isTarget64BitILP32() ? X86::LEA64_32r : X86::LEA32r)
3862 unsigned ResultReg = createResultReg(RC);
3864 TII.get(Opc), ResultReg), AM);
3868 unsigned X86FastISel::fastMaterializeFloatZero(
const ConstantFP *CF) {
3870 if (!isTypeLegal(CF->
getType(), VT))
3879 if (X86ScalarSSEf32) {
3880 Opc = X86::FsFLD0SS;
3881 RC = &X86::FR32RegClass;
3883 Opc = X86::LD_Fp032;
3884 RC = &X86::RFP32RegClass;
3888 if (X86ScalarSSEf64) {
3889 Opc = X86::FsFLD0SD;
3890 RC = &X86::FR64RegClass;
3892 Opc = X86::LD_Fp064;
3893 RC = &X86::RFP64RegClass;
3901 unsigned ResultReg = createResultReg(RC);
3902 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg);
3907 bool X86FastISel::tryToFoldLoadIntoMI(
MachineInstr *
MI,
unsigned OpNo,
3926 *FuncInfo.MF, *MI, OpNo, AddrOps, FuncInfo.InsertPt, Size, Alignment,
3936 unsigned OperandNo = 0;
3945 if (IndexReg == MO.
getReg())
3950 Result->
addMemOperand(*FuncInfo.MF, createMachineMemOperandFor(LI));
3955 unsigned X86FastISel::fastEmitInst_rrrr(
unsigned MachineInstOpcode,
3957 unsigned Op0,
bool Op0IsKill,
3958 unsigned Op1,
bool Op1IsKill,
3959 unsigned Op2,
bool Op2IsKill,
3960 unsigned Op3,
bool Op3IsKill) {
3963 unsigned ResultReg = createResultReg(RC);
3970 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
3976 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
3981 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3991 return new X86FastISel(funcInfo, libInfo);
void setFrameAddressIsTaken(bool T)
unsigned GetCondBranchFromCond(CondCode CC)
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
constexpr bool isUInt< 32 >(uint64_t x)
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
Return a value (possibly void), from a function.
Value * getValueOperand()
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
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...
void push_back(const T &Elt)
mop_iterator operands_end()
This class is the base class for the comparison instructions.
This class represents an incoming formal argument to a Function.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
LocInfo getLocInfo() 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...
unsigned constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const MCInstrDesc &II, unsigned Reg, unsigned OpIdx)
Try to constrain Reg so that it is usable by argument OpIdx of the provided MCInstrDesc II...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
unsigned getNumOperands() const
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Describe properties that are true of each instruction in the target description file.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
unsigned getScalarSizeInBits() const
bool is512BitVector() const
Return true if this is a 512-bit vector type.
This class represents a function call, abstracting a target machine's calling convention.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
0 1 0 0 True if ordered and less than
constexpr bool isInt< 8 >(int64_t x)
unsigned getSizeInBits() const
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
unsigned getByValSize() const
1 1 1 0 True if unordered or not equal
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
This class wraps the llvm.memset intrinsic.
const Function * getParent() const
Return the enclosing method, or null if none.
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...
X86_ThisCall - Similar to X86_StdCall.
bool isCalleePop(CallingConv::ID CallingConv, bool is64Bit, bool IsVarArg, bool GuaranteeTCO)
Determines whether the callee is required to pop its own arguments.
unsigned getValNo() const
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
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...
1 0 0 1 True if unordered or equal
Value * getAddress() const
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.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
const HexagonInstrInfo * TII
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static bool isGlobalStubReference(unsigned char TargetFlag)
isGlobalStubReference - Return true if the specified TargetFlag operand is a reference to a stub for ...
unsigned getNumArgOperands() const
Return the number of call arguments.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Reg
All possible values of the reg field in the ModR/M byte.
0 1 0 1 True if ordered and less than or equal
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
const Triple & getTargetTriple() const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
union llvm::X86AddressMode::@422 Base
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
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)
unsigned getLocReg() const
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.
bool is64Bit() const
Is this x86_64? (disregarding specific ABI / programming model)
Simple integer binary arithmetic operators.
This instruction compares its operands according to the predicate given to the constructor.
BasicBlock * getSuccessor(unsigned i) const
An instruction for storing to memory.
bool isArrayTy() const
True if this is an instance of ArrayType.
void addMemOperand(MachineFunction &MF, MachineMemOperand *MO)
Add a MachineMemOperand to the machine instruction.
void setStackProtectorIndex(int I)
This class represents a truncation of integer types.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset)
Stack pointer relative access.
Class to represent pointers.
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.
uint64_t getElementOffset(unsigned Idx) const
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...
enum llvm::X86AddressMode::@421 BaseType
bool isInteger() const
Return true if this is an integer or a vector integer type.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
unsigned const MachineRegisterInfo * MRI
The instances of the Type class are immutable: once they are created, they are never changed...
DIExpression * getExpression() const
Conditional or Unconditional Branch instruction.
bool isVectorTy() const
True if this is an instance of VectorType.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
This is an important base class in LLVM.
bool isVector() const
Return true if this is a vector value type.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
ConstantFP - Floating Point Values [float, double].
const MCPhysReg * ImplicitDefs
Value * getRawDest() const
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
static std::pair< unsigned, bool > getX86SSEConditionCode(CmpInst::Predicate Predicate)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static const unsigned End
TRAP - Trapping instruction.
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
Value * getPointerOperand()
Predicate getPredicate() const
Return the predicate for this instruction.
X86_FastCall - 'fast' analog of X86_StdCall.
void X86SelectAddress(const MachineInstr &I, const MachineRegisterInfo &MRI, X86AddressMode &AM)
1 1 1 1 Always true (always folded)
unsigned getSETFromCond(CondCode CC, bool HasMemoryOperand=false)
Return a set opcode for the given condition and whether it has a memory operand.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVMContext & getContext() const
All values hold a context through their type.
1 1 0 1 True if unordered, less than, or equal
unsigned getStackRegister() const
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.
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
0 0 1 0 True if ordered and greater than
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Iterator for intrusive lists based on ilist_node.
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)
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
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
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
CCValAssign - Represent assignment of one arg/retval to a location.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Value * getLength() const
void getFullAddress(SmallVectorImpl< MachineOperand > &MO)
This class wraps the llvm.memcpy intrinsic.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
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.
bool is128BitVector() const
Return true if this is a 128-bit vector type.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
virtual const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const
Return a mask of call-preserved registers for the given calling convention on the current function...
bool isIntegerTy() const
True if this is an instance of IntegerType.
This file defines the FastISel class.
unsigned getCMovFromCond(CondCode CC, unsigned RegBytes, bool HasMemoryOperand=false)
Return a cmov opcode for the given condition, register size in bytes, and operand type...
ZERO_EXTEND - Used for integer types, zeroing the new bits.
ANY_EXTEND - Used for integer types. The high bits are undefined.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
The C convention as implemented on Windows/x86-64 and AArch64.
llvm_unreachable("Unknown RegBank!")
bool isNonTemporal() const
bool isStructTy() const
True if this is an instance of StructType.
The memory access reads data.
static std::vector< std::string > Flags
MachineInstr * foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI, ArrayRef< unsigned > Ops, MachineBasicBlock::iterator InsertPt, int FrameIndex, LiveIntervals *LIS=nullptr) const override
foldMemoryOperand - If this target supports it, fold a load or store of the specified stack slot into...
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 – th...
Value * getCondition() const
Bitwise operators - logical and, logical or, logical xor.
bool is256BitVector() const
Return true if this is a 256-bit vector type.
unsigned getSRetReturnReg() const
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned getBytesToPopOnReturn() const
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Establish a view to a call site for examination.
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
bool isOSMSVCRT() const
Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeReturn - Analyze the returned values of a return, incorporating info about the result values i...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
0 1 1 0 True if ordered and operands are unequal
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Fast - This calling convention attempts to make calls as fast as possible (e.g.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
1 0 1 0 True if unordered or greater than
constexpr bool isUInt< 16 >(uint64_t x)
static MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
Value * getRawSource() const
Return the arguments to the instruction.
unsigned getReg() const
getReg - Returns the register number.
DILocalVariable * getVariable() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void GetReturnInfo(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...
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
0 0 0 1 True if ordered and equal
LLVM Value Representation.
mop_iterator operands_begin()
1 0 1 1 True if unordered, greater than, or equal
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
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.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
unsigned getDestAddressSpace() const
MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the immediate should get the value of th...
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
unsigned getLocMemOffset() const
X86AddressMode - This struct holds a generalized full x86 address mode.
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
0 0 1 1 True if ordered and greater than or equal
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
This represents the llvm.dbg.declare instruction.
unsigned getSourceAddressSpace() const
Value * getPointerOperand()
unsigned AllocateStack(unsigned Size, unsigned Align)
AllocateStack - Allocate a chunk of stack space with the specified size and alignment.
const BasicBlock * getParent() 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)
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
iterator_range< arg_iterator > args()
0 0 0 0 Always false (always folded)
static unsigned computeBytesPoppedByCalleeForSRet(const X86Subtarget *Subtarget, CallingConv::ID CC, ImmutableCallSite *CS)
A wrapper class for inspecting calls to intrinsic functions.
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)
unsigned getPtrSizedFrameRegister(const MachineFunction &MF) const
bool usesWindowsCFI() const
bool contains(unsigned Reg) const
Return true if the specified register is included in this register class.