80 class AArch64FastISel final :
public FastISel {
83 using BaseKind =
enum {
89 BaseKind
Kind = RegBase;
95 unsigned OffsetReg = 0;
103 void setKind(BaseKind K) { Kind = K; }
104 BaseKind getKind()
const {
return Kind; }
107 bool isRegBase()
const {
return Kind == RegBase; }
108 bool isFIBase()
const {
return Kind == FrameIndexBase; }
110 void setReg(
unsigned Reg) {
111 assert(isRegBase() &&
"Invalid base register access!");
116 assert(isRegBase() &&
"Invalid base register access!");
120 void setOffsetReg(
unsigned Reg) {
124 unsigned getOffsetReg()
const {
128 void setFI(
unsigned FI) {
129 assert(isFIBase() &&
"Invalid base frame index access!");
133 unsigned getFI()
const {
134 assert(isFIBase() &&
"Invalid base frame index access!");
138 void setOffset(int64_t
O) { Offset =
O; }
140 void setShift(
unsigned S) { Shift = S; }
141 unsigned getShift() {
return Shift; }
152 bool fastLowerArguments()
override;
153 bool fastLowerCall(CallLoweringInfo &CLI)
override;
154 bool fastLowerIntrinsicCall(
const IntrinsicInst *II)
override;
170 bool selectRem(
const Instruction *
I,
unsigned ISDOpcode);
183 bool isTypeLegal(
Type *Ty,
MVT &VT);
184 bool isTypeSupported(
Type *Ty,
MVT &VT,
bool IsVectorAllowed =
false);
185 bool isValueAvailable(
const Value *V)
const;
192 bool isMemCpySmall(uint64_t Len,
unsigned Alignment);
199 std::pair<unsigned, bool> getRegForGEPIndex(
const Value *Idx);
202 unsigned emitAddSub(
bool UseAdd,
MVT RetVT,
const Value *LHS,
203 const Value *RHS,
bool SetFlags =
false,
204 bool WantResult =
true,
bool IsZExt =
false);
205 unsigned emitAddSub_rr(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
206 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
207 bool SetFlags =
false,
bool WantResult =
true);
208 unsigned emitAddSub_ri(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
209 bool LHSIsKill, uint64_t Imm,
bool SetFlags =
false,
210 bool WantResult =
true);
211 unsigned emitAddSub_rs(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
212 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
214 uint64_t ShiftImm,
bool SetFlags =
false,
215 bool WantResult =
true);
216 unsigned emitAddSub_rx(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
217 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
219 uint64_t ShiftImm,
bool SetFlags =
false,
220 bool WantResult =
true);
223 bool emitCompareAndBranch(
const BranchInst *BI);
225 bool emitICmp(
MVT RetVT,
const Value *LHS,
const Value *RHS,
bool IsZExt);
226 bool emitICmp_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill, uint64_t Imm);
227 bool emitFCmp(
MVT RetVT,
const Value *LHS,
const Value *RHS);
228 unsigned emitLoad(
MVT VT,
MVT ResultVT,
Address Addr,
bool WantZExt =
true,
230 bool emitStore(
MVT VT,
unsigned SrcReg,
Address Addr,
232 bool emitStoreRelease(
MVT VT,
unsigned SrcReg,
unsigned AddrReg,
234 unsigned emitIntExt(
MVT SrcVT,
unsigned SrcReg,
MVT DestVT,
bool isZExt);
235 unsigned emiti1Ext(
unsigned SrcReg,
MVT DestVT,
bool isZExt);
236 unsigned emitAdd(
MVT RetVT,
const Value *LHS,
const Value *RHS,
237 bool SetFlags =
false,
bool WantResult =
true,
238 bool IsZExt =
false);
239 unsigned emitAdd_ri_(
MVT VT,
unsigned Op0,
bool Op0IsKill, int64_t Imm);
240 unsigned emitSub(
MVT RetVT,
const Value *LHS,
const Value *RHS,
241 bool SetFlags =
false,
bool WantResult =
true,
242 bool IsZExt =
false);
243 unsigned emitSubs_rr(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
244 unsigned RHSReg,
bool RHSIsKill,
bool WantResult =
true);
245 unsigned emitSubs_rs(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
246 unsigned RHSReg,
bool RHSIsKill,
248 bool WantResult =
true);
249 unsigned emitLogicalOp(
unsigned ISDOpc,
MVT RetVT,
const Value *LHS,
251 unsigned emitLogicalOp_ri(
unsigned ISDOpc,
MVT RetVT,
unsigned LHSReg,
252 bool LHSIsKill, uint64_t Imm);
253 unsigned emitLogicalOp_rs(
unsigned ISDOpc,
MVT RetVT,
unsigned LHSReg,
254 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
256 unsigned emitAnd_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill, uint64_t Imm);
257 unsigned emitMul_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
258 unsigned Op1,
bool Op1IsKill);
259 unsigned emitSMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
260 unsigned Op1,
bool Op1IsKill);
261 unsigned emitUMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
262 unsigned Op1,
bool Op1IsKill);
263 unsigned emitLSL_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
264 unsigned Op1Reg,
bool Op1IsKill);
265 unsigned emitLSL_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0Reg,
bool Op0IsKill,
266 uint64_t Imm,
bool IsZExt =
true);
267 unsigned emitLSR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
268 unsigned Op1Reg,
bool Op1IsKill);
269 unsigned emitLSR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0Reg,
bool Op0IsKill,
270 uint64_t Imm,
bool IsZExt =
true);
271 unsigned emitASR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
272 unsigned Op1Reg,
bool Op1IsKill);
273 unsigned emitASR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0Reg,
bool Op0IsKill,
274 uint64_t Imm,
bool IsZExt =
false);
285 bool finishCall(CallLoweringInfo &CLI,
MVT RetVT,
unsigned NumBytes);
289 unsigned fastMaterializeAlloca(
const AllocaInst *AI)
override;
290 unsigned fastMaterializeConstant(
const Constant *
C)
override;
291 unsigned fastMaterializeFloatZero(
const ConstantFP* CF)
override;
301 bool fastSelectInstruction(
const Instruction *
I)
override;
303 #include "AArch64GenFastISel.inc" 308 #include "AArch64GenCallingConv.inc" 312 assert((isa<ZExtInst>(I) || isa<SExtInst>(I)) &&
313 "Unexpected integer extend instruction.");
315 "Unexpected value type.");
316 bool IsZExt = isa<ZExtInst>(
I);
318 if (
const auto *LI = dyn_cast<LoadInst>(I->
getOperand(0)))
323 if ((IsZExt &&
Arg->hasZExtAttr()) || (!IsZExt &&
Arg->hasSExtAttr()))
351 return CC_AArch64_WebKit_JS;
353 return CC_AArch64_GHC;
354 return Subtarget->
isTargetDarwin() ? CC_AArch64_DarwinPCS : CC_AArch64_AAPCS;
357 unsigned AArch64FastISel::fastMaterializeAlloca(
const AllocaInst *AI) {
359 "Alloca should always return a pointer.");
362 if (!FuncInfo.StaticAllocaMap.count(AI))
366 FuncInfo.StaticAllocaMap.find(AI);
368 if (SI != FuncInfo.StaticAllocaMap.
end()) {
369 unsigned ResultReg = createResultReg(&AArch64::GPR64spRegClass);
370 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::ADDXri),
372 .addFrameIndex(SI->second)
381 unsigned AArch64FastISel::materializeInt(
const ConstantInt *CI,
MVT VT) {
390 : &AArch64::GPR32RegClass;
391 unsigned ZeroReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
392 unsigned ResultReg = createResultReg(RC);
393 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpcode::COPY),
398 unsigned AArch64FastISel::materializeFP(
const ConstantFP *CFP,
MVT VT) {
402 return fastMaterializeFloatZero(CFP);
411 if (TLI.isFPImmLegal(Val, VT)) {
414 assert((Imm != -1) &&
"Cannot encode floating-point constant.");
415 unsigned Opc = Is64Bit ? AArch64::FMOVDi : AArch64::FMOVSi;
416 return fastEmitInst_i(Opc, TLI.getRegClassFor(VT), Imm);
421 unsigned Opc1 = Is64Bit ? AArch64::MOVi64imm : AArch64::MOVi32imm;
423 &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
425 unsigned TmpReg = createResultReg(RC);
426 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc1), TmpReg)
429 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
430 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
431 TII.get(TargetOpcode::COPY), ResultReg)
439 unsigned Align = DL.getPrefTypeAlignment(CFP->
getType());
441 Align = DL.getTypeAllocSize(CFP->
getType());
443 unsigned CPI = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align);
444 unsigned ADRPReg = createResultReg(&AArch64::GPR64commonRegClass);
448 unsigned Opc = Is64Bit ? AArch64::LDRDui : AArch64::LDRSui;
449 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
450 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
456 unsigned AArch64FastISel::materializeGV(
const GlobalValue *GV) {
468 EVT DestEVT = TLI.getValueType(DL, GV->
getType(),
true);
472 unsigned ADRPReg = createResultReg(&AArch64::GPR64commonRegClass);
481 ResultReg = createResultReg(&AArch64::GPR64RegClass);
482 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::LDRXui),
493 ResultReg = createResultReg(&AArch64::GPR64spRegClass);
494 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::ADDXri),
504 unsigned AArch64FastISel::fastMaterializeConstant(
const Constant *
C) {
505 EVT CEVT = TLI.getValueType(DL, C->
getType(),
true);
512 if (
const auto *CI = dyn_cast<ConstantInt>(C))
513 return materializeInt(CI, VT);
514 else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
515 return materializeFP(CFP, VT);
516 else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C))
517 return materializeGV(GV);
522 unsigned AArch64FastISel::fastMaterializeFloatZero(
const ConstantFP* CFP) {
524 "Floating-point constant is not a positive zero.");
526 if (!isTypeLegal(CFP->
getType(), VT))
533 unsigned ZReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
534 unsigned Opc = Is64Bit ? AArch64::FMOVXDr : AArch64::FMOVWSr;
535 return fastEmitInst_r(Opc, TLI.getRegClassFor(VT), ZReg,
true);
540 if (
const auto *
MI = dyn_cast<MulOperator>(I)) {
541 if (
const auto *C = dyn_cast<ConstantInt>(
MI->getOperand(0)))
542 if (C->getValue().isPowerOf2())
544 if (
const auto *C = dyn_cast<ConstantInt>(
MI->getOperand(1)))
545 if (C->getValue().isPowerOf2())
552 bool AArch64FastISel::computeAddress(
const Value *Obj,
Address &Addr,
Type *Ty)
554 const User *U =
nullptr;
555 unsigned Opcode = Instruction::UserOp1;
556 if (
const Instruction *
I = dyn_cast<Instruction>(Obj)) {
559 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
560 FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
561 Opcode =
I->getOpcode();
564 }
else if (
const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
565 Opcode = C->getOpcode();
569 if (
auto *Ty = dyn_cast<PointerType>(Obj->
getType()))
570 if (Ty->getAddressSpace() > 255)
578 case Instruction::BitCast:
580 return computeAddress(U->
getOperand(0), Addr, Ty);
582 case Instruction::IntToPtr:
585 TLI.getPointerTy(DL))
586 return computeAddress(U->
getOperand(0), Addr, Ty);
589 case Instruction::PtrToInt:
591 if (TLI.getValueType(DL, U->
getType()) == TLI.getPointerTy(DL))
592 return computeAddress(U->
getOperand(0), Addr, Ty);
595 case Instruction::GetElementPtr: {
597 uint64_t TmpOffset = Addr.getOffset();
603 const Value *
Op = GTI.getOperand();
604 if (
StructType *STy = GTI.getStructTypeOrNull()) {
606 unsigned Idx = cast<ConstantInt>(
Op)->getZExtValue();
609 uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
611 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
616 if (canFoldAddIntoGEP(U, Op)) {
619 cast<ConstantInt>(cast<AddOperator>(
Op)->getOperand(1));
622 Op = cast<AddOperator>(
Op)->getOperand(0);
626 goto unsupported_gep;
632 Addr.setOffset(TmpOffset);
633 if (computeAddress(U->
getOperand(0), Addr, Ty))
642 case Instruction::Alloca: {
645 FuncInfo.StaticAllocaMap.find(AI);
646 if (SI != FuncInfo.StaticAllocaMap.end()) {
647 Addr.setKind(Address::FrameIndexBase);
648 Addr.setFI(SI->second);
658 if (isa<ConstantInt>(LHS))
661 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
663 return computeAddress(LHS, Addr, Ty);
667 if (computeAddress(LHS, Addr, Ty) && computeAddress(RHS, Addr, Ty))
673 case Instruction::Sub: {
678 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
680 return computeAddress(LHS, Addr, Ty);
684 case Instruction::Shl: {
685 if (Addr.getOffsetReg())
693 if (Val < 1 || Val > 3)
696 uint64_t NumBytes = 0;
698 uint64_t NumBits = DL.getTypeSizeInBits(Ty);
699 NumBytes = NumBits / 8;
704 if (NumBytes != (1ULL << Val))
711 if (
const auto *
I = dyn_cast<Instruction>(Src)) {
712 if (FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
714 if (
const auto *ZE = dyn_cast<ZExtInst>(
I)) {
716 ZE->getOperand(0)->getType()->isIntegerTy(32)) {
718 Src = ZE->getOperand(0);
720 }
else if (
const auto *SE = dyn_cast<SExtInst>(
I)) {
722 SE->getOperand(0)->getType()->isIntegerTy(32)) {
724 Src = SE->getOperand(0);
730 if (
const auto *AI = dyn_cast<BinaryOperator>(Src))
731 if (AI->
getOpcode() == Instruction::And) {
735 if (
const auto *C = dyn_cast<ConstantInt>(LHS))
736 if (C->getValue() == 0xffffffff)
739 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
740 if (C->getValue() == 0xffffffff) {
742 unsigned Reg = getRegForValue(LHS);
745 bool RegIsKill = hasTrivialKill(LHS);
746 Reg = fastEmitInst_extractsubreg(
MVT::i32, Reg, RegIsKill,
748 Addr.setOffsetReg(Reg);
753 unsigned Reg = getRegForValue(Src);
756 Addr.setOffsetReg(Reg);
759 case Instruction::Mul: {
760 if (Addr.getOffsetReg())
770 if (
const auto *C = dyn_cast<ConstantInt>(LHS))
771 if (C->getValue().isPowerOf2())
774 assert(isa<ConstantInt>(RHS) &&
"Expected an ConstantInt.");
775 const auto *C = cast<ConstantInt>(RHS);
776 unsigned Val = C->getValue().logBase2();
777 if (Val < 1 || Val > 3)
780 uint64_t NumBytes = 0;
782 uint64_t NumBits = DL.getTypeSizeInBits(Ty);
783 NumBytes = NumBits / 8;
788 if (NumBytes != (1ULL << Val))
794 const Value *Src = LHS;
795 if (
const auto *
I = dyn_cast<Instruction>(Src)) {
796 if (FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
798 if (
const auto *ZE = dyn_cast<ZExtInst>(
I)) {
800 ZE->getOperand(0)->getType()->isIntegerTy(32)) {
802 Src = ZE->getOperand(0);
804 }
else if (
const auto *SE = dyn_cast<SExtInst>(
I)) {
806 SE->getOperand(0)->getType()->isIntegerTy(32)) {
808 Src = SE->getOperand(0);
814 unsigned Reg = getRegForValue(Src);
817 Addr.setOffsetReg(Reg);
820 case Instruction::And: {
821 if (Addr.getOffsetReg())
824 if (!Ty || DL.getTypeSizeInBits(Ty) != 8)
830 if (
const auto *C = dyn_cast<ConstantInt>(LHS))
831 if (C->getValue() == 0xffffffff)
834 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
835 if (C->getValue() == 0xffffffff) {
840 unsigned Reg = getRegForValue(LHS);
843 bool RegIsKill = hasTrivialKill(LHS);
844 Reg = fastEmitInst_extractsubreg(
MVT::i32, Reg, RegIsKill,
846 Addr.setOffsetReg(Reg);
851 case Instruction::SExt:
852 case Instruction::ZExt: {
853 if (!Addr.getReg() || Addr.getOffsetReg())
856 const Value *Src =
nullptr;
858 if (
const auto *ZE = dyn_cast<ZExtInst>(U)) {
859 if (!
isIntExtFree(ZE) && ZE->getOperand(0)->getType()->isIntegerTy(32)) {
861 Src = ZE->getOperand(0);
863 }
else if (
const auto *SE = dyn_cast<SExtInst>(U)) {
864 if (!
isIntExtFree(SE) && SE->getOperand(0)->getType()->isIntegerTy(32)) {
866 Src = SE->getOperand(0);
874 unsigned Reg = getRegForValue(Src);
877 Addr.setOffsetReg(Reg);
882 if (Addr.isRegBase() && !Addr.getReg()) {
883 unsigned Reg = getRegForValue(Obj);
890 if (!Addr.getOffsetReg()) {
891 unsigned Reg = getRegForValue(Obj);
894 Addr.setOffsetReg(Reg);
901 bool AArch64FastISel::computeCallAddress(
const Value *V,
Address &Addr) {
902 const User *U =
nullptr;
903 unsigned Opcode = Instruction::UserOp1;
906 if (
const auto *
I = dyn_cast<Instruction>(V)) {
907 Opcode =
I->getOpcode();
909 InMBB =
I->getParent() == FuncInfo.MBB->getBasicBlock();
910 }
else if (
const auto *C = dyn_cast<ConstantExpr>(V)) {
911 Opcode = C->getOpcode();
917 case Instruction::BitCast:
920 return computeCallAddress(U->
getOperand(0), Addr);
922 case Instruction::IntToPtr:
926 TLI.getPointerTy(DL))
927 return computeCallAddress(U->
getOperand(0), Addr);
929 case Instruction::PtrToInt:
931 if (InMBB && TLI.getValueType(DL, U->
getType()) == TLI.getPointerTy(DL))
932 return computeCallAddress(U->
getOperand(0), Addr);
936 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
937 Addr.setGlobalValue(GV);
942 if (!Addr.getGlobalValue()) {
943 Addr.setReg(getRegForValue(V));
944 return Addr.getReg() != 0;
950 bool AArch64FastISel::isTypeLegal(
Type *Ty,
MVT &VT) {
951 EVT evt = TLI.getValueType(DL, Ty,
true);
964 return TLI.isTypeLegal(VT);
971 bool AArch64FastISel::isTypeSupported(
Type *Ty,
MVT &VT,
bool IsVectorAllowed) {
975 if (isTypeLegal(Ty, VT))
986 bool AArch64FastISel::isValueAvailable(
const Value *V)
const {
987 if (!isa<Instruction>(V))
990 const auto *
I = cast<Instruction>(V);
991 return FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB;
994 bool AArch64FastISel::simplifyAddress(
Address &Addr,
MVT VT) {
999 bool ImmediateOffsetNeedsLowering =
false;
1000 bool RegisterOffsetNeedsLowering =
false;
1001 int64_t Offset = Addr.getOffset();
1002 if (((Offset < 0) || (Offset & (ScaleFactor - 1))) && !isInt<9>(Offset))
1003 ImmediateOffsetNeedsLowering =
true;
1004 else if (Offset > 0 && !(Offset & (ScaleFactor - 1)) &&
1005 !isUInt<12>(Offset / ScaleFactor))
1006 ImmediateOffsetNeedsLowering =
true;
1011 if (!ImmediateOffsetNeedsLowering && Addr.getOffset() && Addr.getOffsetReg())
1012 RegisterOffsetNeedsLowering =
true;
1015 if (Addr.isRegBase() && Addr.getOffsetReg() && !Addr.getReg())
1016 RegisterOffsetNeedsLowering =
true;
1021 if ((ImmediateOffsetNeedsLowering || Addr.getOffsetReg()) && Addr.isFIBase())
1023 unsigned ResultReg = createResultReg(&AArch64::GPR64spRegClass);
1024 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::ADDXri),
1026 .addFrameIndex(Addr.getFI())
1029 Addr.setKind(Address::RegBase);
1030 Addr.setReg(ResultReg);
1033 if (RegisterOffsetNeedsLowering) {
1034 unsigned ResultReg = 0;
1035 if (Addr.getReg()) {
1038 ResultReg = emitAddSub_rx(
true,
MVT::i64, Addr.getReg(),
1039 false, Addr.getOffsetReg(),
1040 false, Addr.getExtendType(),
1043 ResultReg = emitAddSub_rs(
true,
MVT::i64, Addr.getReg(),
1044 false, Addr.getOffsetReg(),
1050 false, Addr.getShift(),
1054 false, Addr.getShift(),
1058 false, Addr.getShift());
1063 Addr.setReg(ResultReg);
1064 Addr.setOffsetReg(0);
1071 if (ImmediateOffsetNeedsLowering) {
1081 Addr.setReg(ResultReg);
1087 void AArch64FastISel::addLoadStoreOperands(
Address &Addr,
1090 unsigned ScaleFactor,
1092 int64_t Offset = Addr.getOffset() / ScaleFactor;
1094 if (Addr.isFIBase()) {
1095 int FI = Addr.getFI();
1098 MMO = FuncInfo.MF->getMachineMemOperand(
1100 MFI.getObjectSize(FI), MFI.getObjectAlignment(FI));
1104 assert(Addr.isRegBase() &&
"Unexpected address kind.");
1111 if (Addr.getOffsetReg()) {
1112 assert(Addr.getOffset() == 0 &&
"Unexpected offset");
1115 MIB.
addReg(Addr.getReg());
1116 MIB.
addReg(Addr.getOffsetReg());
1118 MIB.
addImm(Addr.getShift() != 0);
1120 MIB.
addReg(Addr.getReg()).addImm(Offset);
1127 unsigned AArch64FastISel::emitAddSub(
bool UseAdd,
MVT RetVT,
const Value *LHS,
1128 const Value *RHS,
bool SetFlags,
1129 bool WantResult,
bool IsZExt) {
1131 bool NeedExtend =
false;
1154 if (UseAdd && isa<Constant>(LHS) && !isa<Constant>(RHS))
1158 if (UseAdd && LHS->
hasOneUse() && isValueAvailable(LHS))
1163 if (UseAdd && LHS->
hasOneUse() && isValueAvailable(LHS))
1164 if (
const auto *
SI = dyn_cast<BinaryOperator>(LHS))
1165 if (isa<ConstantInt>(
SI->getOperand(1)))
1166 if (
SI->getOpcode() == Instruction::Shl ||
1167 SI->getOpcode() == Instruction::LShr ||
1168 SI->getOpcode() == Instruction::AShr )
1171 unsigned LHSReg = getRegForValue(LHS);
1174 bool LHSIsKill = hasTrivialKill(LHS);
1177 LHSReg = emitIntExt(SrcVT, LHSReg, RetVT, IsZExt);
1179 unsigned ResultReg = 0;
1180 if (
const auto *C = dyn_cast<ConstantInt>(RHS)) {
1181 uint64_t Imm = IsZExt ? C->getZExtValue() : C->getSExtValue();
1182 if (C->isNegative())
1183 ResultReg = emitAddSub_ri(!UseAdd, RetVT, LHSReg, LHSIsKill, -Imm,
1184 SetFlags, WantResult);
1186 ResultReg = emitAddSub_ri(UseAdd, RetVT, LHSReg, LHSIsKill, Imm, SetFlags,
1188 }
else if (
const auto *C = dyn_cast<Constant>(RHS))
1190 ResultReg = emitAddSub_ri(UseAdd, RetVT, LHSReg, LHSIsKill, 0, SetFlags,
1198 isValueAvailable(RHS)) {
1199 if (
const auto *
SI = dyn_cast<BinaryOperator>(RHS))
1200 if (
const auto *C = dyn_cast<ConstantInt>(
SI->getOperand(1)))
1201 if ((
SI->getOpcode() == Instruction::Shl) && (C->getZExtValue() < 4)) {
1202 unsigned RHSReg = getRegForValue(
SI->getOperand(0));
1205 bool RHSIsKill = hasTrivialKill(
SI->getOperand(0));
1206 return emitAddSub_rx(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg,
1207 RHSIsKill, ExtendType, C->getZExtValue(),
1208 SetFlags, WantResult);
1210 unsigned RHSReg = getRegForValue(RHS);
1213 bool RHSIsKill = hasTrivialKill(RHS);
1214 return emitAddSub_rx(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg, RHSIsKill,
1215 ExtendType, 0, SetFlags, WantResult);
1219 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1221 const Value *MulLHS = cast<MulOperator>(RHS)->getOperand(0);
1222 const Value *MulRHS = cast<MulOperator>(RHS)->getOperand(1);
1224 if (
const auto *C = dyn_cast<ConstantInt>(MulLHS))
1225 if (C->getValue().isPowerOf2())
1228 assert(isa<ConstantInt>(MulRHS) &&
"Expected a ConstantInt.");
1229 uint64_t ShiftVal = cast<ConstantInt>(MulRHS)->getValue().logBase2();
1230 unsigned RHSReg = getRegForValue(MulLHS);
1233 bool RHSIsKill = hasTrivialKill(MulLHS);
1234 ResultReg = emitAddSub_rs(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg,
1243 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1244 if (
const auto *
SI = dyn_cast<BinaryOperator>(RHS)) {
1245 if (
const auto *C = dyn_cast<ConstantInt>(
SI->getOperand(1))) {
1247 switch (
SI->getOpcode()) {
1253 uint64_t ShiftVal = C->getZExtValue();
1255 unsigned RHSReg = getRegForValue(
SI->getOperand(0));
1258 bool RHSIsKill = hasTrivialKill(
SI->getOperand(0));
1259 ResultReg = emitAddSub_rs(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg,
1260 RHSIsKill, ShiftType, ShiftVal, SetFlags,
1269 unsigned RHSReg = getRegForValue(RHS);
1272 bool RHSIsKill = hasTrivialKill(RHS);
1275 RHSReg = emitIntExt(SrcVT, RHSReg, RetVT, IsZExt);
1277 return emitAddSub_rr(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg, RHSIsKill,
1278 SetFlags, WantResult);
1281 unsigned AArch64FastISel::emitAddSub_rr(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1282 bool LHSIsKill,
unsigned RHSReg,
1283 bool RHSIsKill,
bool SetFlags,
1285 assert(LHSReg && RHSReg &&
"Invalid register number.");
1287 if (LHSReg == AArch64::SP || LHSReg == AArch64::WSP ||
1288 RHSReg == AArch64::SP || RHSReg == AArch64::WSP)
1294 static const unsigned OpcTable[2][2][2] = {
1295 { { AArch64::SUBWrr, AArch64::SUBXrr },
1296 { AArch64::ADDWrr, AArch64::ADDXrr } },
1297 { { AArch64::SUBSWrr, AArch64::SUBSXrr },
1298 { AArch64::ADDSWrr, AArch64::ADDSXrr } }
1301 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1303 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1306 ResultReg = createResultReg(RC);
1308 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1313 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1319 unsigned AArch64FastISel::emitAddSub_ri(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1320 bool LHSIsKill, uint64_t Imm,
1321 bool SetFlags,
bool WantResult) {
1322 assert(LHSReg &&
"Invalid register number.");
1328 if (isUInt<12>(Imm))
1330 else if ((Imm & 0xfff000) == Imm) {
1336 static const unsigned OpcTable[2][2][2] = {
1337 { { AArch64::SUBWri, AArch64::SUBXri },
1338 { AArch64::ADDWri, AArch64::ADDXri } },
1339 { { AArch64::SUBSWri, AArch64::SUBSXri },
1340 { AArch64::ADDSWri, AArch64::ADDSXri } }
1343 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1346 RC = Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1348 RC = Is64Bit ? &AArch64::GPR64spRegClass : &AArch64::GPR32spRegClass;
1351 ResultReg = createResultReg(RC);
1353 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1357 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1364 unsigned AArch64FastISel::emitAddSub_rs(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1365 bool LHSIsKill,
unsigned RHSReg,
1368 uint64_t ShiftImm,
bool SetFlags,
1370 assert(LHSReg && RHSReg &&
"Invalid register number.");
1371 assert(LHSReg != AArch64::SP && LHSReg != AArch64::WSP &&
1372 RHSReg != AArch64::SP && RHSReg != AArch64::WSP);
1381 static const unsigned OpcTable[2][2][2] = {
1382 { { AArch64::SUBWrs, AArch64::SUBXrs },
1383 { AArch64::ADDWrs, AArch64::ADDXrs } },
1384 { { AArch64::SUBSWrs, AArch64::SUBSXrs },
1385 { AArch64::ADDSWrs, AArch64::ADDSXrs } }
1388 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1390 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1393 ResultReg = createResultReg(RC);
1395 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1400 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1407 unsigned AArch64FastISel::emitAddSub_rx(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1408 bool LHSIsKill,
unsigned RHSReg,
1411 uint64_t ShiftImm,
bool SetFlags,
1413 assert(LHSReg && RHSReg &&
"Invalid register number.");
1414 assert(LHSReg != AArch64::XZR && LHSReg != AArch64::WZR &&
1415 RHSReg != AArch64::XZR && RHSReg != AArch64::WZR);
1423 static const unsigned OpcTable[2][2][2] = {
1424 { { AArch64::SUBWrx, AArch64::SUBXrx },
1425 { AArch64::ADDWrx, AArch64::ADDXrx } },
1426 { { AArch64::SUBSWrx, AArch64::SUBSXrx },
1427 { AArch64::ADDSWrx, AArch64::ADDSXrx } }
1430 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1433 RC = Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1435 RC = Is64Bit ? &AArch64::GPR64spRegClass : &AArch64::GPR32spRegClass;
1438 ResultReg = createResultReg(RC);
1440 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1445 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1454 EVT EVT = TLI.getValueType(DL, Ty,
true);
1467 return emitICmp(VT, LHS, RHS, IsZExt);
1470 return emitFCmp(VT, LHS, RHS);
1474 bool AArch64FastISel::emitICmp(
MVT RetVT,
const Value *LHS,
const Value *RHS,
1476 return emitSub(RetVT, LHS, RHS,
true,
false,
1480 bool AArch64FastISel::emitICmp_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
1482 return emitAddSub_ri(
false, RetVT, LHSReg, LHSIsKill, Imm,
1486 bool AArch64FastISel::emitFCmp(
MVT RetVT,
const Value *LHS,
const Value *RHS) {
1492 bool UseImm =
false;
1493 if (
const auto *CFP = dyn_cast<ConstantFP>(RHS))
1497 unsigned LHSReg = getRegForValue(LHS);
1500 bool LHSIsKill = hasTrivialKill(LHS);
1503 unsigned Opc = (RetVT ==
MVT::f64) ? AArch64::FCMPDri : AArch64::FCMPSri;
1504 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
1509 unsigned RHSReg = getRegForValue(RHS);
1512 bool RHSIsKill = hasTrivialKill(RHS);
1514 unsigned Opc = (RetVT ==
MVT::f64) ? AArch64::FCMPDrr : AArch64::FCMPSrr;
1515 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
1521 unsigned AArch64FastISel::emitAdd(
MVT RetVT,
const Value *LHS,
const Value *RHS,
1522 bool SetFlags,
bool WantResult,
bool IsZExt) {
1523 return emitAddSub(
true, RetVT, LHS, RHS, SetFlags, WantResult,
1532 unsigned AArch64FastISel::emitAdd_ri_(
MVT VT,
unsigned Op0,
bool Op0IsKill,
1536 ResultReg = emitAddSub_ri(
false, VT, Op0, Op0IsKill, -Imm);
1538 ResultReg = emitAddSub_ri(
true, VT, Op0, Op0IsKill, Imm);
1547 ResultReg = emitAddSub_rr(
true, VT, Op0, Op0IsKill, CReg,
true);
1551 unsigned AArch64FastISel::emitSub(
MVT RetVT,
const Value *LHS,
const Value *RHS,
1552 bool SetFlags,
bool WantResult,
bool IsZExt) {
1553 return emitAddSub(
false, RetVT, LHS, RHS, SetFlags, WantResult,
1557 unsigned AArch64FastISel::emitSubs_rr(
MVT RetVT,
unsigned LHSReg,
1558 bool LHSIsKill,
unsigned RHSReg,
1559 bool RHSIsKill,
bool WantResult) {
1560 return emitAddSub_rr(
false, RetVT, LHSReg, LHSIsKill, RHSReg,
1561 RHSIsKill,
true, WantResult);
1564 unsigned AArch64FastISel::emitSubs_rs(
MVT RetVT,
unsigned LHSReg,
1565 bool LHSIsKill,
unsigned RHSReg,
1568 uint64_t ShiftImm,
bool WantResult) {
1569 return emitAddSub_rs(
false, RetVT, LHSReg, LHSIsKill, RHSReg,
1570 RHSIsKill, ShiftType, ShiftImm,
true,
1574 unsigned AArch64FastISel::emitLogicalOp(
unsigned ISDOpc,
MVT RetVT,
1577 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS))
1581 if (LHS->
hasOneUse() && isValueAvailable(LHS))
1586 if (LHS->
hasOneUse() && isValueAvailable(LHS))
1587 if (
const auto *
SI = dyn_cast<ShlOperator>(LHS))
1588 if (isa<ConstantInt>(
SI->getOperand(1)))
1591 unsigned LHSReg = getRegForValue(LHS);
1594 bool LHSIsKill = hasTrivialKill(LHS);
1596 unsigned ResultReg = 0;
1597 if (
const auto *C = dyn_cast<ConstantInt>(RHS)) {
1598 uint64_t Imm = C->getZExtValue();
1599 ResultReg = emitLogicalOp_ri(ISDOpc, RetVT, LHSReg, LHSIsKill, Imm);
1605 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1607 const Value *MulLHS = cast<MulOperator>(RHS)->getOperand(0);
1608 const Value *MulRHS = cast<MulOperator>(RHS)->getOperand(1);
1610 if (
const auto *C = dyn_cast<ConstantInt>(MulLHS))
1611 if (C->getValue().isPowerOf2())
1614 assert(isa<ConstantInt>(MulRHS) &&
"Expected a ConstantInt.");
1615 uint64_t ShiftVal = cast<ConstantInt>(MulRHS)->getValue().logBase2();
1617 unsigned RHSReg = getRegForValue(MulLHS);
1620 bool RHSIsKill = hasTrivialKill(MulLHS);
1621 ResultReg = emitLogicalOp_rs(ISDOpc, RetVT, LHSReg, LHSIsKill, RHSReg,
1622 RHSIsKill, ShiftVal);
1629 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1630 if (
const auto *
SI = dyn_cast<ShlOperator>(RHS))
1631 if (
const auto *C = dyn_cast<ConstantInt>(
SI->getOperand(1))) {
1632 uint64_t ShiftVal = C->getZExtValue();
1633 unsigned RHSReg = getRegForValue(
SI->getOperand(0));
1636 bool RHSIsKill = hasTrivialKill(
SI->getOperand(0));
1637 ResultReg = emitLogicalOp_rs(ISDOpc, RetVT, LHSReg, LHSIsKill, RHSReg,
1638 RHSIsKill, ShiftVal);
1644 unsigned RHSReg = getRegForValue(RHS);
1647 bool RHSIsKill = hasTrivialKill(RHS);
1650 ResultReg = fastEmit_rr(VT, VT, ISDOpc, LHSReg, LHSIsKill, RHSReg, RHSIsKill);
1652 uint64_t
Mask = (RetVT ==
MVT::i8) ? 0xff : 0xffff;
1653 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
1658 unsigned AArch64FastISel::emitLogicalOp_ri(
unsigned ISDOpc,
MVT RetVT,
1659 unsigned LHSReg,
bool LHSIsKill,
1662 "ISD nodes are not consecutive!");
1663 static const unsigned OpcTable[3][2] = {
1664 { AArch64::ANDWri, AArch64::ANDXri },
1665 { AArch64::ORRWri, AArch64::ORRXri },
1666 { AArch64::EORWri, AArch64::EORXri }
1679 Opc = OpcTable[Idx][0];
1680 RC = &AArch64::GPR32spRegClass;
1685 Opc = OpcTable[ISDOpc -
ISD::AND][1];
1686 RC = &AArch64::GPR64spRegClass;
1694 unsigned ResultReg =
1695 fastEmitInst_ri(Opc, RC, LHSReg, LHSIsKill,
1698 uint64_t
Mask = (RetVT ==
MVT::i8) ? 0xff : 0xffff;
1699 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
1704 unsigned AArch64FastISel::emitLogicalOp_rs(
unsigned ISDOpc,
MVT RetVT,
1705 unsigned LHSReg,
bool LHSIsKill,
1706 unsigned RHSReg,
bool RHSIsKill,
1707 uint64_t ShiftImm) {
1709 "ISD nodes are not consecutive!");
1710 static const unsigned OpcTable[3][2] = {
1711 { AArch64::ANDWrs, AArch64::ANDXrs },
1712 { AArch64::ORRWrs, AArch64::ORRXrs },
1713 { AArch64::EORWrs, AArch64::EORXrs }
1729 Opc = OpcTable[ISDOpc -
ISD::AND][0];
1730 RC = &AArch64::GPR32RegClass;
1733 Opc = OpcTable[ISDOpc -
ISD::AND][1];
1734 RC = &AArch64::GPR64RegClass;
1737 unsigned ResultReg =
1738 fastEmitInst_rri(Opc, RC, LHSReg, LHSIsKill, RHSReg, RHSIsKill,
1741 uint64_t
Mask = (RetVT ==
MVT::i8) ? 0xff : 0xffff;
1742 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
1747 unsigned AArch64FastISel::emitAnd_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
1749 return emitLogicalOp_ri(
ISD::AND, RetVT, LHSReg, LHSIsKill, Imm);
1752 unsigned AArch64FastISel::emitLoad(
MVT VT,
MVT RetVT,
Address Addr,
1754 if (!TLI.allowsMisalignedMemoryAccesses(VT))
1758 if (!simplifyAddress(Addr, VT))
1767 bool UseScaled =
true;
1768 if ((Addr.getOffset() < 0) || (Addr.getOffset() & (ScaleFactor - 1))) {
1773 static const unsigned GPOpcTable[2][8][4] = {
1775 { { AArch64::LDURSBWi, AArch64::LDURSHWi, AArch64::LDURWi,
1777 { AArch64::LDURSBXi, AArch64::LDURSHXi, AArch64::LDURSWi,
1779 { AArch64::LDRSBWui, AArch64::LDRSHWui, AArch64::LDRWui,
1781 { AArch64::LDRSBXui, AArch64::LDRSHXui, AArch64::LDRSWui,
1783 { AArch64::LDRSBWroX, AArch64::LDRSHWroX, AArch64::LDRWroX,
1785 { AArch64::LDRSBXroX, AArch64::LDRSHXroX, AArch64::LDRSWroX,
1787 { AArch64::LDRSBWroW, AArch64::LDRSHWroW, AArch64::LDRWroW,
1789 { AArch64::LDRSBXroW, AArch64::LDRSHXroW, AArch64::LDRSWroW,
1793 { { AArch64::LDURBBi, AArch64::LDURHHi, AArch64::LDURWi,
1795 { AArch64::LDURBBi, AArch64::LDURHHi, AArch64::LDURWi,
1797 { AArch64::LDRBBui, AArch64::LDRHHui, AArch64::LDRWui,
1799 { AArch64::LDRBBui, AArch64::LDRHHui, AArch64::LDRWui,
1801 { AArch64::LDRBBroX, AArch64::LDRHHroX, AArch64::LDRWroX,
1803 { AArch64::LDRBBroX, AArch64::LDRHHroX, AArch64::LDRWroX,
1805 { AArch64::LDRBBroW, AArch64::LDRHHroW, AArch64::LDRWroW,
1807 { AArch64::LDRBBroW, AArch64::LDRHHroW, AArch64::LDRWroW,
1812 static const unsigned FPOpcTable[4][2] = {
1813 { AArch64::LDURSi, AArch64::LDURDi },
1814 { AArch64::LDRSui, AArch64::LDRDui },
1815 { AArch64::LDRSroX, AArch64::LDRDroX },
1816 { AArch64::LDRSroW, AArch64::LDRDroW }
1821 bool UseRegOffset = Addr.isRegBase() && !Addr.getOffset() && Addr.getReg() &&
1822 Addr.getOffsetReg();
1823 unsigned Idx = UseRegOffset ? 2 : UseScaled ? 1 : 0;
1828 bool IsRet64Bit = RetVT ==
MVT::i64;
1834 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][0];
1835 RC = (IsRet64Bit && !WantZExt) ?
1836 &AArch64::GPR64RegClass: &AArch64::GPR32RegClass;
1839 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][1];
1840 RC = (IsRet64Bit && !WantZExt) ?
1841 &AArch64::GPR64RegClass: &AArch64::GPR32RegClass;
1844 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][2];
1845 RC = (IsRet64Bit && !WantZExt) ?
1846 &AArch64::GPR64RegClass: &AArch64::GPR32RegClass;
1849 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][3];
1850 RC = &AArch64::GPR64RegClass;
1853 Opc = FPOpcTable[Idx][0];
1854 RC = &AArch64::FPR32RegClass;
1857 Opc = FPOpcTable[Idx][1];
1858 RC = &AArch64::FPR64RegClass;
1863 unsigned ResultReg = createResultReg(RC);
1865 TII.get(Opc), ResultReg);
1870 unsigned ANDReg = emitAnd_ri(
MVT::i32, ResultReg,
true, 1);
1871 assert(ANDReg &&
"Unexpected AND instruction emission failure.");
1878 unsigned Reg64 = createResultReg(&AArch64::GPR64RegClass);
1879 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1880 TII.get(AArch64::SUBREG_TO_REG), Reg64)
1883 .
addImm(AArch64::sub_32);
1889 bool AArch64FastISel::selectAddSub(
const Instruction *
I) {
1891 if (!isTypeSupported(I->
getType(), VT,
true))
1895 return selectOperator(I, I->
getOpcode());
1904 case Instruction::Sub:
1911 updateValueMap(I, ResultReg);
1915 bool AArch64FastISel::selectLogicalOp(
const Instruction *I) {
1917 if (!isTypeSupported(I->
getType(), VT,
true))
1921 return selectOperator(I, I->
getOpcode());
1927 case Instruction::And:
1930 case Instruction::Or:
1933 case Instruction::Xor:
1940 updateValueMap(I, ResultReg);
1944 bool AArch64FastISel::selectLoad(
const Instruction *I) {
1949 if (!isTypeSupported(I->
getType(), VT,
true) ||
1950 cast<LoadInst>(I)->isAtomic())
1954 if (TLI.supportSwiftError()) {
1957 if (
const Argument *
Arg = dyn_cast<Argument>(SV)) {
1958 if (
Arg->hasSwiftErrorAttr())
1962 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(SV)) {
1963 if (Alloca->isSwiftError())
1974 bool WantZExt =
true;
1976 const Value *IntExtVal =
nullptr;
1978 if (
const auto *ZE = dyn_cast<ZExtInst>(I->
use_begin()->getUser())) {
1979 if (isTypeSupported(ZE->getType(), RetVT))
1983 }
else if (
const auto *SE = dyn_cast<SExtInst>(I->
use_begin()->getUser())) {
1984 if (isTypeSupported(SE->getType(), RetVT))
1992 unsigned ResultReg =
1993 emitLoad(VT, RetVT, Addr, WantZExt, createMachineMemOperandFor(I));
2013 unsigned Reg = lookUpRegForValue(IntExtVal);
2014 auto *
MI =
MRI.getUniqueVRegDef(Reg);
2019 std::prev(FuncInfo.InsertPt)->eraseFromParent();
2020 ResultReg = std::prev(FuncInfo.InsertPt)->getOperand(0).getReg();
2022 ResultReg = fastEmitInst_extractsubreg(
MVT::i32, ResultReg,
2026 updateValueMap(I, ResultReg);
2035 for (
auto &Opnd :
MI->uses()) {
2037 Reg = Opnd.getReg();
2041 MI->eraseFromParent();
2044 MI =
MRI.getUniqueVRegDef(Reg);
2046 updateValueMap(IntExtVal, ResultReg);
2050 updateValueMap(I, ResultReg);
2054 bool AArch64FastISel::emitStoreRelease(
MVT VT,
unsigned SrcReg,
2059 default:
return false;
2060 case MVT::i8: Opc = AArch64::STLRB;
break;
2061 case MVT::i16: Opc = AArch64::STLRH;
break;
2062 case MVT::i32: Opc = AArch64::STLRW;
break;
2063 case MVT::i64: Opc = AArch64::STLRX;
break;
2069 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
2076 bool AArch64FastISel::emitStore(
MVT VT,
unsigned SrcReg,
Address Addr,
2078 if (!TLI.allowsMisalignedMemoryAccesses(VT))
2082 if (!simplifyAddress(Addr, VT))
2091 bool UseScaled =
true;
2092 if ((Addr.getOffset() < 0) || (Addr.getOffset() & (ScaleFactor - 1))) {
2097 static const unsigned OpcTable[4][6] = {
2098 { AArch64::STURBBi, AArch64::STURHHi, AArch64::STURWi, AArch64::STURXi,
2099 AArch64::STURSi, AArch64::STURDi },
2100 { AArch64::STRBBui, AArch64::STRHHui, AArch64::STRWui, AArch64::STRXui,
2101 AArch64::STRSui, AArch64::STRDui },
2102 { AArch64::STRBBroX, AArch64::STRHHroX, AArch64::STRWroX, AArch64::STRXroX,
2103 AArch64::STRSroX, AArch64::STRDroX },
2104 { AArch64::STRBBroW, AArch64::STRHHroW, AArch64::STRWroW, AArch64::STRXroW,
2105 AArch64::STRSroW, AArch64::STRDroW }
2109 bool VTIsi1 =
false;
2110 bool UseRegOffset = Addr.isRegBase() && !Addr.getOffset() && Addr.getReg() &&
2111 Addr.getOffsetReg();
2112 unsigned Idx = UseRegOffset ? 2 : UseScaled ? 1 : 0;
2120 case MVT::i8: Opc = OpcTable[Idx][0];
break;
2121 case MVT::i16: Opc = OpcTable[Idx][1];
break;
2122 case MVT::i32: Opc = OpcTable[Idx][2];
break;
2123 case MVT::i64: Opc = OpcTable[Idx][3];
break;
2124 case MVT::f32: Opc = OpcTable[Idx][4];
break;
2125 case MVT::f64: Opc = OpcTable[Idx][5];
break;
2129 if (VTIsi1 && SrcReg != AArch64::WZR) {
2130 unsigned ANDReg = emitAnd_ri(
MVT::i32, SrcReg,
false, 1);
2131 assert(ANDReg &&
"Unexpected AND instruction emission failure.");
2138 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II).
addReg(SrcReg);
2144 bool AArch64FastISel::selectStore(
const Instruction *I) {
2150 if (!isTypeSupported(Op0->
getType(), VT,
true))
2154 if (TLI.supportSwiftError()) {
2157 if (
const Argument *
Arg = dyn_cast<Argument>(PtrV)) {
2158 if (
Arg->hasSwiftErrorAttr())
2162 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(PtrV)) {
2163 if (Alloca->isSwiftError())
2170 unsigned SrcReg = 0;
2171 if (
const auto *CI = dyn_cast<ConstantInt>(Op0)) {
2173 SrcReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
2174 }
else if (
const auto *CF = dyn_cast<ConstantFP>(Op0)) {
2175 if (CF->isZero() && !CF->isNegative()) {
2177 SrcReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
2182 SrcReg = getRegForValue(Op0);
2187 auto *
SI = cast<StoreInst>(
I);
2190 if (
SI->isAtomic()) {
2195 unsigned AddrReg = getRegForValue(PtrV);
2196 return emitStoreRelease(VT, SrcReg, AddrReg,
2197 createMachineMemOperandFor(I));
2203 if (!computeAddress(PtrV, Addr, Op0->
getType()))
2206 if (!emitStore(VT, SrcReg, Addr, createMachineMemOperandFor(I)))
2258 bool AArch64FastISel::emitCompareAndBranch(
const BranchInst *BI) {
2267 if (!isTypeSupported(LHS->
getType(), VT))
2278 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
2285 switch (Predicate) {
2290 if (isa<Constant>(LHS) && cast<Constant>(LHS)->isNullValue())
2293 if (!isa<Constant>(RHS) || !cast<Constant>(RHS)->isNullValue())
2296 if (
const auto *AI = dyn_cast<BinaryOperator>(LHS))
2297 if (AI->
getOpcode() == Instruction::And && isValueAvailable(AI)) {
2301 if (
const auto *C = dyn_cast<ConstantInt>(AndLHS))
2302 if (C->getValue().isPowerOf2())
2305 if (
const auto *C = dyn_cast<ConstantInt>(AndRHS))
2306 if (C->getValue().isPowerOf2()) {
2307 TestBit = C->getValue().logBase2();
2319 if (!isa<Constant>(RHS) || !cast<Constant>(RHS)->isNullValue())
2327 if (!isa<ConstantInt>(RHS))
2330 if (cast<ConstantInt>(RHS)->getValue() !=
APInt(BW, -1,
true))
2338 static const unsigned OpcTable[2][2][2] = {
2339 { {AArch64::CBZW, AArch64::CBZX },
2340 {AArch64::CBNZW, AArch64::CBNZX} },
2341 { {AArch64::TBZW, AArch64::TBZX },
2342 {AArch64::TBNZW, AArch64::TBNZX} }
2345 bool IsBitTest = TestBit != -1;
2346 bool Is64Bit = BW == 64;
2347 if (TestBit < 32 && TestBit >= 0)
2350 unsigned Opc = OpcTable[IsBitTest][IsCmpNE][Is64Bit];
2353 unsigned SrcReg = getRegForValue(LHS);
2356 bool SrcIsKill = hasTrivialKill(LHS);
2358 if (BW == 64 && !Is64Bit)
2359 SrcReg = fastEmitInst_extractsubreg(
MVT::i32, SrcReg, SrcIsKill,
2362 if ((BW < 32) && !IsBitTest)
2363 SrcReg = emitIntExt(VT, SrcReg,
MVT::i32,
true);
2368 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
2374 finishCondBranch(BI->
getParent(), TBB, FBB);
2378 bool AArch64FastISel::selectBranch(
const Instruction *I) {
2390 if (CI->
hasOneUse() && isValueAvailable(CI)) {
2393 switch (Predicate) {
2397 fastEmitBranch(FBB, DbgLoc);
2400 fastEmitBranch(TBB, DbgLoc);
2405 if (emitCompareAndBranch(BI))
2409 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
2422 switch (Predicate) {
2438 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::Bcc))
2444 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::Bcc))
2448 finishCondBranch(BI->
getParent(), TBB, FBB);
2451 }
else if (
const auto *CI = dyn_cast<ConstantInt>(BI->
getCondition())) {
2463 FuncInfo.MBB->addSuccessorWithoutProb(Target);
2475 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::Bcc))
2479 finishCondBranch(BI->
getParent(), TBB, FBB);
2487 bool CondRegIsKill = hasTrivialKill(BI->
getCondition());
2490 unsigned Opcode = AArch64::TBNZW;
2491 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
2493 Opcode = AArch64::TBZW;
2497 unsigned ConstrainedCondReg
2499 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
2504 finishCondBranch(BI->
getParent(), TBB, FBB);
2508 bool AArch64FastISel::selectIndirectBr(
const Instruction *I) {
2510 unsigned AddrReg = getRegForValue(BI->
getOperand(0));
2517 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II).
addReg(AddrReg);
2521 FuncInfo.MBB->addSuccessor(FuncInfo.MBBMap[Succ]);
2526 bool AArch64FastISel::selectCmp(
const Instruction *I) {
2527 const CmpInst *CI = cast<CmpInst>(
I);
2535 unsigned ResultReg = 0;
2536 switch (Predicate) {
2540 ResultReg = createResultReg(&AArch64::GPR32RegClass);
2541 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2542 TII.get(TargetOpcode::COPY), ResultReg)
2551 updateValueMap(I, ResultReg);
2559 ResultReg = createResultReg(&AArch64::GPR32RegClass);
2563 static unsigned CondCodeTable[2][2] = {
2568 switch (Predicate) {
2572 CondCodes = &CondCodeTable[0][0];
2575 CondCodes = &CondCodeTable[1][0];
2580 unsigned TmpReg1 = createResultReg(&AArch64::GPR32RegClass);
2581 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr),
2585 .addImm(CondCodes[0]);
2586 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr),
2590 .addImm(CondCodes[1]);
2592 updateValueMap(I, ResultReg);
2600 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr),
2604 .addImm(invertedCC);
2606 updateValueMap(I, ResultReg);
2612 bool AArch64FastISel::optimizeSelect(
const SelectInst *
SI) {
2616 const Value *Src1Val, *Src2Val;
2618 bool NeedExtraOp =
false;
2619 if (
auto *CI = dyn_cast<ConstantInt>(SI->
getTrueValue())) {
2623 Opc = AArch64::ORRWrr;
2628 Opc = AArch64::BICWrr;
2630 }
else if (
auto *CI = dyn_cast<ConstantInt>(SI->
getFalseValue())) {
2634 Opc = AArch64::ORRWrr;
2640 Opc = AArch64::ANDWrr;
2647 unsigned Src1Reg = getRegForValue(Src1Val);
2650 bool Src1IsKill = hasTrivialKill(Src1Val);
2652 unsigned Src2Reg = getRegForValue(Src2Val);
2655 bool Src2IsKill = hasTrivialKill(Src2Val);
2661 unsigned ResultReg = fastEmitInst_rr(Opc, &AArch64::GPR32RegClass, Src1Reg,
2662 Src1IsKill, Src2Reg, Src2IsKill);
2663 updateValueMap(SI, ResultReg);
2667 bool AArch64FastISel::selectSelect(
const Instruction *I) {
2668 assert(isa<SelectInst>(I) &&
"Expected a select instruction.");
2670 if (!isTypeSupported(I->
getType(), VT))
2682 Opc = AArch64::CSELWr;
2683 RC = &AArch64::GPR32RegClass;
2686 Opc = AArch64::CSELXr;
2687 RC = &AArch64::GPR64RegClass;
2690 Opc = AArch64::FCSELSrrr;
2691 RC = &AArch64::FPR32RegClass;
2694 Opc = AArch64::FCSELDrrr;
2695 RC = &AArch64::FPR64RegClass;
2704 if (optimizeSelect(SI))
2708 if (foldXALUIntrinsic(CC, I, Cond)) {
2710 unsigned CondReg = getRegForValue(Cond);
2713 }
else if (isa<CmpInst>(Cond) && cast<CmpInst>(Cond)->hasOneUse() &&
2714 isValueAvailable(Cond)) {
2715 const auto *Cmp = cast<CmpInst>(Cond);
2718 const Value *FoldSelect =
nullptr;
2719 switch (Predicate) {
2731 unsigned SrcReg = getRegForValue(FoldSelect);
2734 unsigned UseReg = lookUpRegForValue(SI);
2736 MRI.clearKillFlags(UseReg);
2738 updateValueMap(I, SrcReg);
2743 if (!
emitCmp(Cmp->getOperand(0), Cmp->getOperand(1), Cmp->isUnsigned()))
2748 switch (Predicate) {
2762 unsigned CondReg = getRegForValue(Cond);
2765 bool CondIsKill = hasTrivialKill(Cond);
2771 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II,
2783 if (!Src1Reg || !Src2Reg)
2787 Src2Reg = fastEmitInst_rri(Opc, RC, Src1Reg, Src1IsKill, Src2Reg,
2788 Src2IsKill, ExtraCC);
2791 unsigned ResultReg = fastEmitInst_rri(Opc, RC, Src1Reg, Src1IsKill, Src2Reg,
2793 updateValueMap(I, ResultReg);
2797 bool AArch64FastISel::selectFPExt(
const Instruction *I) {
2802 unsigned Op = getRegForValue(V);
2806 unsigned ResultReg = createResultReg(&AArch64::FPR64RegClass);
2807 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::FCVTDSr),
2808 ResultReg).addReg(Op);
2809 updateValueMap(I, ResultReg);
2813 bool AArch64FastISel::selectFPTrunc(
const Instruction *I) {
2818 unsigned Op = getRegForValue(V);
2822 unsigned ResultReg = createResultReg(&AArch64::FPR32RegClass);
2823 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::FCVTSDr),
2824 ResultReg).addReg(Op);
2825 updateValueMap(I, ResultReg);
2835 unsigned SrcReg = getRegForValue(I->
getOperand(0));
2846 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZSUWDr : AArch64::FCVTZSUXDr;
2848 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZUUWDr : AArch64::FCVTZUUXDr;
2851 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZSUWSr : AArch64::FCVTZSUXSr;
2853 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZUUWSr : AArch64::FCVTZUUXSr;
2855 unsigned ResultReg = createResultReg(
2856 DestVT ==
MVT::i32 ? &AArch64::GPR32RegClass : &AArch64::GPR64RegClass);
2857 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
2859 updateValueMap(I, ResultReg);
2863 bool AArch64FastISel::selectIntToFP(
const Instruction *I,
bool Signed) {
2872 "Unexpected value type.");
2874 unsigned SrcReg = getRegForValue(I->
getOperand(0));
2877 bool SrcIsKill = hasTrivialKill(I->
getOperand(0));
2893 Opc = (DestVT ==
MVT::f32) ? AArch64::SCVTFUXSri : AArch64::SCVTFUXDri;
2895 Opc = (DestVT ==
MVT::f32) ? AArch64::UCVTFUXSri : AArch64::UCVTFUXDri;
2898 Opc = (DestVT ==
MVT::f32) ? AArch64::SCVTFUWSri : AArch64::SCVTFUWDri;
2900 Opc = (DestVT ==
MVT::f32) ? AArch64::UCVTFUWSri : AArch64::UCVTFUWDri;
2903 unsigned ResultReg = fastEmitInst_r(Opc, TLI.getRegClassFor(DestVT), SrcReg,
2905 updateValueMap(I, ResultReg);
2909 bool AArch64FastISel::fastLowerArguments() {
2910 if (!FuncInfo.CanLowerReturn)
2922 unsigned GPRCnt = 0;
2923 unsigned FPRCnt = 0;
2924 for (
auto const &
Arg : F->
args()) {
2925 if (
Arg.hasAttribute(Attribute::ByVal) ||
2926 Arg.hasAttribute(Attribute::InReg) ||
2927 Arg.hasAttribute(Attribute::StructRet) ||
2928 Arg.hasAttribute(Attribute::SwiftSelf) ||
2929 Arg.hasAttribute(Attribute::SwiftError) ||
2930 Arg.hasAttribute(Attribute::Nest))
2937 EVT ArgVT = TLI.getValueType(DL, ArgTy);
2957 if (GPRCnt > 8 || FPRCnt > 8)
2961 static const MCPhysReg Registers[6][8] = {
2962 { AArch64::W0, AArch64::W1, AArch64::W2, AArch64::W3, AArch64::W4,
2963 AArch64::W5, AArch64::W6, AArch64::W7 },
2964 { AArch64::X0, AArch64::X1, AArch64::X2, AArch64::X3, AArch64::X4,
2965 AArch64::X5, AArch64::X6, AArch64::X7 },
2966 { AArch64::H0, AArch64::H1, AArch64::H2, AArch64::H3, AArch64::H4,
2967 AArch64::H5, AArch64::H6, AArch64::H7 },
2968 { AArch64::S0, AArch64::S1, AArch64::S2, AArch64::S3, AArch64::S4,
2969 AArch64::S5, AArch64::S6, AArch64::S7 },
2970 { AArch64::D0, AArch64::D1, AArch64::D2, AArch64::D3, AArch64::D4,
2971 AArch64::D5, AArch64::D6, AArch64::D7 },
2972 { AArch64::Q0, AArch64::Q1, AArch64::Q2, AArch64::Q3, AArch64::Q4,
2973 AArch64::Q5, AArch64::Q6, AArch64::Q7 }
2977 unsigned FPRIdx = 0;
2978 for (
auto const &
Arg : F->
args()) {
2983 SrcReg = Registers[0][GPRIdx++];
2984 RC = &AArch64::GPR32RegClass;
2987 SrcReg = Registers[1][GPRIdx++];
2988 RC = &AArch64::GPR64RegClass;
2990 SrcReg = Registers[2][FPRIdx++];
2991 RC = &AArch64::FPR16RegClass;
2993 SrcReg = Registers[3][FPRIdx++];
2994 RC = &AArch64::FPR32RegClass;
2996 SrcReg = Registers[4][FPRIdx++];
2997 RC = &AArch64::FPR64RegClass;
2999 SrcReg = Registers[5][FPRIdx++];
3000 RC = &AArch64::FPR128RegClass;
3004 unsigned DstReg = FuncInfo.MF->addLiveIn(SrcReg, RC);
3008 unsigned ResultReg = createResultReg(RC);
3009 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3010 TII.get(TargetOpcode::COPY), ResultReg)
3012 updateValueMap(&
Arg, ResultReg);
3017 bool AArch64FastISel::processCallArgs(CallLoweringInfo &CLI,
3019 unsigned &NumBytes) {
3022 CCState CCInfo(CC,
false, *FuncInfo.MF, ArgLocs, *Context);
3029 unsigned AdjStackDown =
TII.getCallFrameSetupOpcode();
3030 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AdjStackDown))
3031 .addImm(NumBytes).
addImm(0);
3035 const Value *ArgVal = CLI.OutVals[VA.getValNo()];
3036 MVT ArgVT = OutVTs[VA.getValNo()];
3038 unsigned ArgReg = getRegForValue(ArgVal);
3043 switch (VA.getLocInfo()) {
3047 MVT DestVT = VA.getLocVT();
3049 ArgReg = emitIntExt(SrcVT, ArgReg, DestVT,
false);
3057 MVT DestVT = VA.getLocVT();
3059 ArgReg = emitIntExt(SrcVT, ArgReg, DestVT,
true);
3069 if (VA.isRegLoc() && !VA.needsCustom()) {
3070 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3071 TII.get(TargetOpcode::COPY), VA.getLocReg()).addReg(ArgReg);
3072 CLI.OutRegs.push_back(VA.getLocReg());
3073 }
else if (VA.needsCustom()) {
3077 assert(VA.isMemLoc() &&
"Assuming store on stack.");
3080 if (isa<UndefValue>(ArgVal))
3086 unsigned BEAlign = 0;
3087 if (ArgSize < 8 && !Subtarget->isLittleEndian())
3088 BEAlign = 8 - ArgSize;
3091 Addr.setKind(Address::RegBase);
3092 Addr.setReg(AArch64::SP);
3093 Addr.setOffset(VA.getLocMemOffset() + BEAlign);
3095 unsigned Alignment = DL.getABITypeAlignment(ArgVal->
getType());
3100 if (!emitStore(ArgVT, ArgReg, Addr, MMO))
3107 bool AArch64FastISel::finishCall(CallLoweringInfo &CLI,
MVT RetVT,
3108 unsigned NumBytes) {
3112 unsigned AdjStackUp =
TII.getCallFrameDestroyOpcode();
3113 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AdjStackUp))
3114 .addImm(NumBytes).
addImm(0);
3119 CCState CCInfo(CC,
false, *FuncInfo.MF, RVLocs, *Context);
3123 if (RVLocs.
size() != 1)
3127 MVT CopyVT = RVLocs[0].getValVT();
3133 unsigned ResultReg = createResultReg(TLI.getRegClassFor(CopyVT));
3134 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3135 TII.get(TargetOpcode::COPY), ResultReg)
3136 .addReg(RVLocs[0].getLocReg());
3137 CLI.InRegs.push_back(RVLocs[0].getLocReg());
3139 CLI.ResultReg = ResultReg;
3140 CLI.NumResultRegs = 1;
3146 bool AArch64FastISel::fastLowerCall(CallLoweringInfo &CLI) {
3148 bool IsTailCall = CLI.IsTailCall;
3149 bool IsVarArg = CLI.IsVarArg;
3153 if (!Callee && !Symbol)
3175 if (CLI.RetTy->isVoidTy())
3177 else if (!isTypeLegal(CLI.RetTy, RetVT))
3180 for (
auto Flag : CLI.OutFlags)
3182 Flag.isSwiftSelf() ||
Flag.isSwiftError())
3187 OutVTs.
reserve(CLI.OutVals.size());
3189 for (
auto *Val : CLI.OutVals) {
3191 if (!isTypeLegal(Val->getType(), VT) &&
3203 if (Callee && !computeCallAddress(Callee, Addr))
3208 if (!processCallArgs(CLI, OutVTs, NumBytes))
3215 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II);
3218 else if (Addr.getGlobalValue())
3220 else if (Addr.getReg()) {
3226 unsigned CallReg = 0;
3228 unsigned ADRPReg = createResultReg(&AArch64::GPR64commonRegClass);
3233 CallReg = createResultReg(&AArch64::GPR64RegClass);
3234 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3235 TII.get(AArch64::LDRXui), CallReg)
3239 }
else if (Addr.getGlobalValue())
3240 CallReg = materializeGV(Addr.getGlobalValue());
3241 else if (Addr.getReg())
3242 CallReg = Addr.getReg();
3249 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II).
addReg(CallReg);
3253 for (
auto Reg : CLI.OutRegs)
3263 return finishCall(CLI, RetVT, NumBytes);
3266 bool AArch64FastISel::isMemCpySmall(uint64_t Len,
unsigned Alignment) {
3268 return Len / Alignment <= 4;
3273 bool AArch64FastISel::tryEmitSmallMemCpy(
Address Dest,
Address Src,
3274 uint64_t Len,
unsigned Alignment) {
3276 if (!isMemCpySmall(Len, Alignment))
3279 int64_t UnscaledOffset = 0;
3285 if (!Alignment || Alignment >= 8) {
3297 if (Len >= 4 && Alignment == 4)
3299 else if (Len >= 2 && Alignment == 2)
3306 unsigned ResultReg = emitLoad(VT, VT, Src);
3310 if (!emitStore(VT, ResultReg, Dest))
3315 UnscaledOffset +=
Size;
3318 Dest.setOffset(OrigDest.getOffset() + UnscaledOffset);
3319 Src.setOffset(OrigSrc.getOffset() + UnscaledOffset);
3329 const Value *Cond) {
3330 if (!isa<ExtractValueInst>(Cond))
3333 const auto *EV = cast<ExtractValueInst>(Cond);
3334 if (!isa<IntrinsicInst>(EV->getAggregateOperand()))
3337 const auto *II = cast<IntrinsicInst>(EV->getAggregateOperand());
3341 cast<StructType>(Callee->
getReturnType())->getTypeAtIndex(0U);
3342 if (!isTypeLegal(RetTy, RetVT))
3348 const Value *LHS = II->getArgOperand(0);
3349 const Value *RHS = II->getArgOperand(1);
3352 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS) &&
3353 isCommutativeIntrinsic(II))
3361 case Intrinsic::smul_with_overflow:
3362 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3363 if (C->getValue() == 2)
3364 IID = Intrinsic::sadd_with_overflow;
3366 case Intrinsic::umul_with_overflow:
3367 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3368 if (C->getValue() == 2)
3369 IID = Intrinsic::uadd_with_overflow;
3377 case Intrinsic::sadd_with_overflow:
3378 case Intrinsic::ssub_with_overflow:
3381 case Intrinsic::uadd_with_overflow:
3384 case Intrinsic::usub_with_overflow:
3387 case Intrinsic::smul_with_overflow:
3388 case Intrinsic::umul_with_overflow:
3394 if (!isValueAvailable(II))
3400 for (
auto Itr = std::prev(Start); Itr != End; --Itr) {
3403 if (!isa<ExtractValueInst>(Itr))
3407 const auto *EVI = cast<ExtractValueInst>(Itr);
3408 if (EVI->getAggregateOperand() != II)
3416 bool AArch64FastISel::fastLowerIntrinsicCall(
const IntrinsicInst *II) {
3419 default:
return false;
3420 case Intrinsic::frameaddress: {
3426 unsigned SrcReg =
MRI.createVirtualRegister(&AArch64::GPR64RegClass);
3427 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3428 TII.get(TargetOpcode::COPY), SrcReg).addReg(FramePtr);
3435 unsigned Depth = cast<ConstantInt>(II->
getOperand(0))->getZExtValue();
3437 DestReg = fastEmitInst_ri(AArch64::LDRXui, &AArch64::GPR64RegClass,
3439 assert(DestReg &&
"Unexpected LDR instruction emission failure.");
3443 updateValueMap(II, SrcReg);
3446 case Intrinsic::memcpy:
3447 case Intrinsic::memmove: {
3448 const auto *MTI = cast<MemTransferInst>(II);
3450 if (MTI->isVolatile())
3456 if (isa<ConstantInt>(MTI->getLength()) && IsMemCpy) {
3459 uint64_t Len = cast<ConstantInt>(MTI->getLength())->getZExtValue();
3460 unsigned Alignment =
MinAlign(MTI->getDestAlignment(),
3461 MTI->getSourceAlignment());
3462 if (isMemCpySmall(Len, Alignment)) {
3464 if (!computeAddress(MTI->getRawDest(), Dest) ||
3465 !computeAddress(MTI->getRawSource(), Src))
3467 if (tryEmitSmallMemCpy(Dest, Src, Len, Alignment))
3472 if (!MTI->getLength()->getType()->isIntegerTy(64))
3475 if (MTI->getSourceAddressSpace() > 255 || MTI->getDestAddressSpace() > 255)
3480 const char *IntrMemName = isa<MemCpyInst>(II) ?
"memcpy" :
"memmove";
3483 case Intrinsic::memset: {
3484 const MemSetInst *MSI = cast<MemSetInst>(II);
3499 case Intrinsic::sin:
3500 case Intrinsic::cos:
3501 case Intrinsic::pow: {
3503 if (!isTypeLegal(II->
getType(), RetVT))
3510 { RTLIB::SIN_F32, RTLIB::SIN_F64 },
3511 { RTLIB::COS_F32, RTLIB::COS_F64 },
3512 { RTLIB::POW_F32, RTLIB::POW_F64 }
3519 case Intrinsic::sin:
3520 LC = LibCallTable[0][Is64Bit];
3522 case Intrinsic::cos:
3523 LC = LibCallTable[1][Is64Bit];
3525 case Intrinsic::pow:
3526 LC = LibCallTable[2][Is64Bit];
3538 Args.push_back(Entry);
3541 CallLoweringInfo CLI;
3543 CLI.setCallee(DL, Ctx, TLI.getLibcallCallingConv(LC), II->
getType(),
3544 TLI.getLibcallName(LC), std::move(Args));
3545 if (!lowerCallTo(CLI))
3547 updateValueMap(II, CLI.ResultReg);
3550 case Intrinsic::fabs: {
3552 if (!isTypeLegal(II->
getType(), VT))
3560 Opc = AArch64::FABSSr;
3563 Opc = AArch64::FABSDr;
3566 unsigned SrcReg = getRegForValue(II->
getOperand(0));
3569 bool SrcRegIsKill = hasTrivialKill(II->
getOperand(0));
3570 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
3571 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
3573 updateValueMap(II, ResultReg);
3576 case Intrinsic::trap:
3577 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::BRK))
3581 case Intrinsic::sqrt: {
3585 if (!isTypeLegal(RetTy, VT))
3588 unsigned Op0Reg = getRegForValue(II->
getOperand(0));
3591 bool Op0IsKill = hasTrivialKill(II->
getOperand(0));
3593 unsigned ResultReg = fastEmit_r(VT, VT,
ISD::FSQRT, Op0Reg, Op0IsKill);
3597 updateValueMap(II, ResultReg);
3600 case Intrinsic::sadd_with_overflow:
3601 case Intrinsic::uadd_with_overflow:
3602 case Intrinsic::ssub_with_overflow:
3603 case Intrinsic::usub_with_overflow:
3604 case Intrinsic::smul_with_overflow:
3605 case Intrinsic::umul_with_overflow: {
3609 Type *RetTy = Ty->getTypeAtIndex(0U);
3612 if (!isTypeLegal(RetTy, VT))
3621 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS) &&
3622 isCommutativeIntrinsic(II))
3630 case Intrinsic::smul_with_overflow:
3631 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3632 if (C->getValue() == 2) {
3633 IID = Intrinsic::sadd_with_overflow;
3637 case Intrinsic::umul_with_overflow:
3638 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3639 if (C->getValue() == 2) {
3640 IID = Intrinsic::uadd_with_overflow;
3646 unsigned ResultReg1 = 0, ResultReg2 = 0, MulReg = 0;
3650 case Intrinsic::sadd_with_overflow:
3651 ResultReg1 = emitAdd(VT, LHS, RHS,
true);
3654 case Intrinsic::uadd_with_overflow:
3655 ResultReg1 = emitAdd(VT, LHS, RHS,
true);
3658 case Intrinsic::ssub_with_overflow:
3659 ResultReg1 = emitSub(VT, LHS, RHS,
true);
3662 case Intrinsic::usub_with_overflow:
3663 ResultReg1 = emitSub(VT, LHS, RHS,
true);
3666 case Intrinsic::smul_with_overflow: {
3668 unsigned LHSReg = getRegForValue(LHS);
3671 bool LHSIsKill = hasTrivialKill(LHS);
3673 unsigned RHSReg = getRegForValue(RHS);
3676 bool RHSIsKill = hasTrivialKill(RHS);
3679 MulReg = emitSMULL_rr(
MVT::i64, LHSReg, LHSIsKill, RHSReg, RHSIsKill);
3682 MulReg = fastEmitInst_extractsubreg(VT, MulReg,
true,
3684 ShiftReg = fastEmitInst_extractsubreg(VT, ShiftReg,
true,
3686 emitSubs_rs(VT, ShiftReg,
true, MulReg,
false,
3692 MulReg = emitMul_rr(VT, LHSReg,
false, RHSReg,
3694 unsigned SMULHReg = fastEmit_rr(VT, VT,
ISD::MULHS, LHSReg, LHSIsKill,
3696 emitSubs_rs(VT, SMULHReg,
true, MulReg,
false,
3701 case Intrinsic::umul_with_overflow: {
3703 unsigned LHSReg = getRegForValue(LHS);
3706 bool LHSIsKill = hasTrivialKill(LHS);
3708 unsigned RHSReg = getRegForValue(RHS);
3711 bool RHSIsKill = hasTrivialKill(RHS);
3714 MulReg = emitUMULL_rr(
MVT::i64, LHSReg, LHSIsKill, RHSReg, RHSIsKill);
3715 emitSubs_rs(
MVT::i64, AArch64::XZR,
true, MulReg,
3718 MulReg = fastEmitInst_extractsubreg(VT, MulReg,
true,
3724 MulReg = emitMul_rr(VT, LHSReg,
false, RHSReg,
3726 unsigned UMULHReg = fastEmit_rr(VT, VT,
ISD::MULHU, LHSReg, LHSIsKill,
3728 emitSubs_rr(VT, AArch64::XZR,
true, UMULHReg,
3736 ResultReg1 = createResultReg(TLI.getRegClassFor(VT));
3737 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3738 TII.get(TargetOpcode::COPY), ResultReg1).addReg(MulReg);
3741 ResultReg2 = fastEmitInst_rri(AArch64::CSINCWr, &AArch64::GPR32RegClass,
3742 AArch64::WZR,
true, AArch64::WZR,
3745 assert((ResultReg1 + 1) == ResultReg2 &&
3746 "Nonconsecutive result registers.");
3747 updateValueMap(II, ResultReg1, 2);
3754 bool AArch64FastISel::selectRet(
const Instruction *I) {
3758 if (!FuncInfo.CanLowerReturn)
3764 if (TLI.supportSwiftError() &&
3765 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError))
3768 if (TLI.supportSplitCSR(FuncInfo.MF))
3777 GetReturnInfo(CC, F.getReturnType(), F.getAttributes(), Outs, TLI, DL);
3783 : RetCC_AArch64_AAPCS;
3784 CCInfo.AnalyzeReturn(Outs, RetCC);
3787 if (ValLocs.size() != 1)
3802 unsigned Reg = getRegForValue(RV);
3806 unsigned SrcReg = Reg + VA.
getValNo();
3809 if (!
MRI.getRegClass(SrcReg)->contains(DestReg))
3812 EVT RVEVT = TLI.getValueType(DL, RV->
getType());
3827 if (RVVT != DestVT) {
3831 if (!Outs[0].Flags.isZExt() && !Outs[0].Flags.isSExt())
3834 bool IsZExt = Outs[0].Flags.isZExt();
3835 SrcReg = emitIntExt(RVVT, SrcReg, DestVT, IsZExt);
3841 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3842 TII.get(TargetOpcode::COPY), DestReg).addReg(SrcReg);
3849 TII.get(AArch64::RET_ReallyLR));
3850 for (
unsigned RetReg : RetRegs)
3855 bool AArch64FastISel::selectTrunc(
const Instruction *I) {
3860 EVT SrcEVT = TLI.getValueType(DL, SrcTy,
true);
3861 EVT DestEVT = TLI.getValueType(DL, DestTy,
true);
3877 unsigned SrcReg = getRegForValue(Op);
3880 bool SrcIsKill = hasTrivialKill(Op);
3905 unsigned Reg32 = fastEmitInst_extractsubreg(
MVT::i32, SrcReg, SrcIsKill,
3908 ResultReg = emitAnd_ri(
MVT::i32, Reg32,
true, Mask);
3909 assert(ResultReg &&
"Unexpected AND instruction emission failure.");
3911 ResultReg = createResultReg(&AArch64::GPR32RegClass);
3912 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3913 TII.get(TargetOpcode::COPY), ResultReg)
3917 updateValueMap(I, ResultReg);
3921 unsigned AArch64FastISel::emiti1Ext(
unsigned SrcReg,
MVT DestVT,
bool IsZExt) {
3924 "Unexpected value type.");
3930 unsigned ResultReg = emitAnd_ri(
MVT::i32, SrcReg,
false, 1);
3931 assert(ResultReg &&
"Unexpected AND instruction emission failure.");
3935 unsigned Reg64 =
MRI.createVirtualRegister(&AArch64::GPR64RegClass);
3936 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3937 TII.get(AArch64::SUBREG_TO_REG), Reg64)
3940 .
addImm(AArch64::sub_32);
3949 return fastEmitInst_rii(AArch64::SBFMWri, &AArch64::GPR32RegClass, SrcReg,
3954 unsigned AArch64FastISel::emitMul_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
3955 unsigned Op1,
bool Op1IsKill) {
3963 Opc = AArch64::MADDWrrr; ZReg = AArch64::WZR;
break;
3965 Opc = AArch64::MADDXrrr; ZReg = AArch64::XZR;
break;
3969 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
3970 return fastEmitInst_rrr(Opc, RC, Op0, Op0IsKill, Op1, Op1IsKill,
3974 unsigned AArch64FastISel::emitSMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
3975 unsigned Op1,
bool Op1IsKill) {
3979 return fastEmitInst_rrr(AArch64::SMADDLrrr, &AArch64::GPR64RegClass,
3980 Op0, Op0IsKill, Op1, Op1IsKill,
3981 AArch64::XZR,
true);
3984 unsigned AArch64FastISel::emitUMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
3985 unsigned Op1,
bool Op1IsKill) {
3989 return fastEmitInst_rrr(AArch64::UMADDLrrr, &AArch64::GPR64RegClass,
3990 Op0, Op0IsKill, Op1, Op1IsKill,
3991 AArch64::XZR,
true);
3994 unsigned AArch64FastISel::emitLSL_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
3995 unsigned Op1Reg,
bool Op1IsKill) {
3997 bool NeedTrunc =
false;
4001 case MVT::i8: Opc = AArch64::LSLVWr; NeedTrunc =
true; Mask = 0xff;
break;
4002 case MVT::i16: Opc = AArch64::LSLVWr; NeedTrunc =
true; Mask = 0xffff;
break;
4003 case MVT::i32: Opc = AArch64::LSLVWr;
break;
4004 case MVT::i64: Opc = AArch64::LSLVXr;
break;
4008 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4010 Op1Reg = emitAnd_ri(
MVT::i32, Op1Reg, Op1IsKill, Mask);
4013 unsigned ResultReg = fastEmitInst_rr(Opc, RC, Op0Reg, Op0IsKill, Op1Reg,
4016 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
4020 unsigned AArch64FastISel::emitLSL_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0,
4021 bool Op0IsKill, uint64_t Shift,
4024 "Unexpected source/return type pair.");
4027 "Unexpected source value type.");
4029 RetVT ==
MVT::i64) &&
"Unexpected return value type.");
4031 bool Is64Bit = (RetVT ==
MVT::i64);
4032 unsigned RegSize = Is64Bit ? 64 : 32;
4036 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4040 if (RetVT == SrcVT) {
4041 unsigned ResultReg = createResultReg(RC);
4042 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4043 TII.get(TargetOpcode::COPY), ResultReg)
4047 return emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4051 if (Shift >= DstBits)
4079 unsigned ImmR = RegSize - Shift;
4081 unsigned ImmS = std::min<unsigned>(SrcBits - 1, DstBits - 1 - Shift);
4082 static const unsigned OpcTable[2][2] = {
4083 {AArch64::SBFMWri, AArch64::SBFMXri},
4084 {AArch64::UBFMWri, AArch64::UBFMXri}
4086 unsigned Opc = OpcTable[IsZExt][Is64Bit];
4088 unsigned TmpReg =
MRI.createVirtualRegister(RC);
4089 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4090 TII.get(AArch64::SUBREG_TO_REG), TmpReg)
4093 .
addImm(AArch64::sub_32);
4097 return fastEmitInst_rii(Opc, RC, Op0, Op0IsKill, ImmR, ImmS);
4100 unsigned AArch64FastISel::emitLSR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
4101 unsigned Op1Reg,
bool Op1IsKill) {
4103 bool NeedTrunc =
false;
4107 case MVT::i8: Opc = AArch64::LSRVWr; NeedTrunc =
true; Mask = 0xff;
break;
4108 case MVT::i16: Opc = AArch64::LSRVWr; NeedTrunc =
true; Mask = 0xffff;
break;
4109 case MVT::i32: Opc = AArch64::LSRVWr;
break;
4110 case MVT::i64: Opc = AArch64::LSRVXr;
break;
4114 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4116 Op0Reg = emitAnd_ri(
MVT::i32, Op0Reg, Op0IsKill, Mask);
4117 Op1Reg = emitAnd_ri(
MVT::i32, Op1Reg, Op1IsKill, Mask);
4118 Op0IsKill = Op1IsKill =
true;
4120 unsigned ResultReg = fastEmitInst_rr(Opc, RC, Op0Reg, Op0IsKill, Op1Reg,
4123 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
4127 unsigned AArch64FastISel::emitLSR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0,
4128 bool Op0IsKill, uint64_t Shift,
4131 "Unexpected source/return type pair.");
4134 "Unexpected source value type.");
4136 RetVT ==
MVT::i64) &&
"Unexpected return value type.");
4138 bool Is64Bit = (RetVT ==
MVT::i64);
4139 unsigned RegSize = Is64Bit ? 64 : 32;
4143 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4147 if (RetVT == SrcVT) {
4148 unsigned ResultReg = createResultReg(RC);
4149 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4150 TII.get(TargetOpcode::COPY), ResultReg)
4154 return emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4158 if (Shift >= DstBits)
4186 if (Shift >= SrcBits && IsZExt)
4192 Op0 = emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4201 unsigned ImmR = std::min<unsigned>(SrcBits - 1, Shift);
4202 unsigned ImmS = SrcBits - 1;
4203 static const unsigned OpcTable[2][2] = {
4204 {AArch64::SBFMWri, AArch64::SBFMXri},
4205 {AArch64::UBFMWri, AArch64::UBFMXri}
4207 unsigned Opc = OpcTable[IsZExt][Is64Bit];
4209 unsigned TmpReg =
MRI.createVirtualRegister(RC);
4210 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4211 TII.get(AArch64::SUBREG_TO_REG), TmpReg)
4214 .
addImm(AArch64::sub_32);
4218 return fastEmitInst_rii(Opc, RC, Op0, Op0IsKill, ImmR, ImmS);
4221 unsigned AArch64FastISel::emitASR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
4222 unsigned Op1Reg,
bool Op1IsKill) {
4224 bool NeedTrunc =
false;
4228 case MVT::i8: Opc = AArch64::ASRVWr; NeedTrunc =
true; Mask = 0xff;
break;
4229 case MVT::i16: Opc = AArch64::ASRVWr; NeedTrunc =
true; Mask = 0xffff;
break;
4230 case MVT::i32: Opc = AArch64::ASRVWr;
break;
4231 case MVT::i64: Opc = AArch64::ASRVXr;
break;
4235 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4237 Op0Reg = emitIntExt(RetVT, Op0Reg,
MVT::i32,
false);
4238 Op1Reg = emitAnd_ri(
MVT::i32, Op1Reg, Op1IsKill, Mask);
4239 Op0IsKill = Op1IsKill =
true;
4241 unsigned ResultReg = fastEmitInst_rr(Opc, RC, Op0Reg, Op0IsKill, Op1Reg,
4244 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
4248 unsigned AArch64FastISel::emitASR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0,
4249 bool Op0IsKill, uint64_t Shift,
4252 "Unexpected source/return type pair.");
4255 "Unexpected source value type.");
4257 RetVT ==
MVT::i64) &&
"Unexpected return value type.");
4259 bool Is64Bit = (RetVT ==
MVT::i64);
4260 unsigned RegSize = Is64Bit ? 64 : 32;
4264 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4268 if (RetVT == SrcVT) {
4269 unsigned ResultReg = createResultReg(RC);
4270 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4271 TII.get(TargetOpcode::COPY), ResultReg)
4275 return emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4279 if (Shift >= DstBits)
4307 if (Shift >= SrcBits && IsZExt)
4310 unsigned ImmR = std::min<unsigned>(SrcBits - 1, Shift);
4311 unsigned ImmS = SrcBits - 1;
4312 static const unsigned OpcTable[2][2] = {
4313 {AArch64::SBFMWri, AArch64::SBFMXri},
4314 {AArch64::UBFMWri, AArch64::UBFMXri}
4316 unsigned Opc = OpcTable[IsZExt][Is64Bit];
4318 unsigned TmpReg =
MRI.createVirtualRegister(RC);
4319 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4320 TII.get(AArch64::SUBREG_TO_REG), TmpReg)
4323 .
addImm(AArch64::sub_32);
4327 return fastEmitInst_rii(Opc, RC, Op0, Op0IsKill, ImmR, ImmS);
4330 unsigned AArch64FastISel::emitIntExt(
MVT SrcVT,
unsigned SrcReg,
MVT DestVT,
4351 return emiti1Ext(SrcReg, DestVT, IsZExt);
4354 Opc = IsZExt ? AArch64::UBFMXri : AArch64::SBFMXri;
4356 Opc = IsZExt ? AArch64::UBFMWri : AArch64::SBFMWri;
4361 Opc = IsZExt ? AArch64::UBFMXri : AArch64::SBFMXri;
4363 Opc = IsZExt ? AArch64::UBFMWri : AArch64::SBFMWri;
4368 Opc = IsZExt ? AArch64::UBFMXri : AArch64::SBFMXri;
4377 unsigned Src64 =
MRI.createVirtualRegister(&AArch64::GPR64RegClass);
4378 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4379 TII.get(AArch64::SUBREG_TO_REG), Src64)
4382 .
addImm(AArch64::sub_32);
4387 (DestVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4388 return fastEmitInst_rii(Opc, RC, SrcReg,
false, 0, Imm);
4395 case AArch64::LDURBBi:
4396 case AArch64::LDURHHi:
4397 case AArch64::LDURWi:
4398 case AArch64::LDRBBui:
4399 case AArch64::LDRHHui:
4400 case AArch64::LDRWui:
4401 case AArch64::LDRBBroX:
4402 case AArch64::LDRHHroX:
4403 case AArch64::LDRWroX:
4404 case AArch64::LDRBBroW:
4405 case AArch64::LDRHHroW:
4406 case AArch64::LDRWroW:
4415 case AArch64::LDURSBWi:
4416 case AArch64::LDURSHWi:
4417 case AArch64::LDURSBXi:
4418 case AArch64::LDURSHXi:
4419 case AArch64::LDURSWi:
4420 case AArch64::LDRSBWui:
4421 case AArch64::LDRSHWui:
4422 case AArch64::LDRSBXui:
4423 case AArch64::LDRSHXui:
4424 case AArch64::LDRSWui:
4425 case AArch64::LDRSBWroX:
4426 case AArch64::LDRSHWroX:
4427 case AArch64::LDRSBXroX:
4428 case AArch64::LDRSHXroX:
4429 case AArch64::LDRSWroX:
4430 case AArch64::LDRSBWroW:
4431 case AArch64::LDRSHWroW:
4432 case AArch64::LDRSBXroW:
4433 case AArch64::LDRSHXroW:
4434 case AArch64::LDRSWroW:
4439 bool AArch64FastISel::optimizeIntExtLoad(
const Instruction *I,
MVT RetVT,
4442 if (!LI || !LI->hasOneUse())
4446 unsigned Reg = lookUpRegForValue(LI);
4456 bool IsZExt = isa<ZExtInst>(
I);
4457 const auto *LoadMI =
MI;
4458 if (LoadMI->getOpcode() == TargetOpcode::COPY &&
4459 LoadMI->getOperand(1).getSubReg() == AArch64::sub_32) {
4461 LoadMI =
MRI.getUniqueVRegDef(LoadReg);
4462 assert(LoadMI &&
"Expected valid instruction");
4469 updateValueMap(I, Reg);
4474 unsigned Reg64 = createResultReg(&AArch64::GPR64RegClass);
4475 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4476 TII.get(AArch64::SUBREG_TO_REG), Reg64)
4479 .
addImm(AArch64::sub_32);
4484 "Expected copy instruction");
4488 updateValueMap(I, Reg);
4492 bool AArch64FastISel::selectIntExt(
const Instruction *I) {
4493 assert((isa<ZExtInst>(I) || isa<SExtInst>(I)) &&
4494 "Unexpected integer extend instruction.");
4497 if (!isTypeSupported(I->
getType(), RetVT))
4504 if (optimizeIntExtLoad(I, RetVT, SrcVT))
4507 unsigned SrcReg = getRegForValue(I->
getOperand(0));
4510 bool SrcIsKill = hasTrivialKill(I->
getOperand(0));
4513 bool IsZExt = isa<ZExtInst>(
I);
4514 if (
const auto *
Arg = dyn_cast<Argument>(I->
getOperand(0))) {
4515 if ((IsZExt &&
Arg->hasZExtAttr()) || (!IsZExt &&
Arg->hasSExtAttr())) {
4517 unsigned ResultReg = createResultReg(&AArch64::GPR64RegClass);
4518 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4519 TII.get(AArch64::SUBREG_TO_REG), ResultReg)
4522 .
addImm(AArch64::sub_32);
4529 unsigned UseReg = lookUpRegForValue(I);
4531 MRI.clearKillFlags(UseReg);
4533 updateValueMap(I, SrcReg);
4538 unsigned ResultReg = emitIntExt(SrcVT, SrcReg, RetVT, IsZExt);
4542 updateValueMap(I, ResultReg);
4546 bool AArch64FastISel::selectRem(
const Instruction *I,
unsigned ISDOpcode) {
4547 EVT DestEVT = TLI.getValueType(DL, I->
getType(),
true);
4556 bool Is64bit = (DestVT ==
MVT::i64);
4557 switch (ISDOpcode) {
4561 DivOpc = Is64bit ? AArch64::SDIVXr : AArch64::SDIVWr;
4564 DivOpc = Is64bit ? AArch64::UDIVXr : AArch64::UDIVWr;
4567 unsigned MSubOpc = Is64bit ? AArch64::MSUBXrrr : AArch64::MSUBWrrr;
4568 unsigned Src0Reg = getRegForValue(I->
getOperand(0));
4571 bool Src0IsKill = hasTrivialKill(I->
getOperand(0));
4573 unsigned Src1Reg = getRegForValue(I->
getOperand(1));
4576 bool Src1IsKill = hasTrivialKill(I->
getOperand(1));
4579 (DestVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4580 unsigned QuotReg = fastEmitInst_rr(DivOpc, RC, Src0Reg,
false,
4582 assert(QuotReg &&
"Unexpected DIV instruction emission failure.");
4585 unsigned ResultReg = fastEmitInst_rrr(MSubOpc, RC, QuotReg,
true,
4586 Src1Reg, Src1IsKill, Src0Reg,
4588 updateValueMap(I, ResultReg);
4592 bool AArch64FastISel::selectMul(
const Instruction *I) {
4594 if (!isTypeSupported(I->
getType(), VT,
true))
4602 if (
const auto *C = dyn_cast<ConstantInt>(Src0))
4603 if (C->getValue().isPowerOf2())
4607 if (
const auto *C = dyn_cast<ConstantInt>(Src1))
4608 if (C->getValue().isPowerOf2()) {
4609 uint64_t ShiftVal = C->getValue().logBase2();
4612 if (
const auto *ZExt = dyn_cast<ZExtInst>(Src0)) {
4615 if (isValueAvailable(ZExt) && isTypeSupported(ZExt->getSrcTy(), VT)) {
4618 Src0 = ZExt->getOperand(0);
4621 }
else if (
const auto *SExt = dyn_cast<SExtInst>(Src0)) {
4624 if (isValueAvailable(SExt) && isTypeSupported(SExt->getSrcTy(), VT)) {
4627 Src0 = SExt->getOperand(0);
4632 unsigned Src0Reg = getRegForValue(Src0);
4635 bool Src0IsKill = hasTrivialKill(Src0);
4637 unsigned ResultReg =
4638 emitLSL_ri(VT, SrcVT, Src0Reg, Src0IsKill, ShiftVal, IsZExt);
4641 updateValueMap(I, ResultReg);
4646 unsigned Src0Reg = getRegForValue(I->
getOperand(0));
4649 bool Src0IsKill = hasTrivialKill(I->
getOperand(0));
4651 unsigned Src1Reg = getRegForValue(I->
getOperand(1));
4654 bool Src1IsKill = hasTrivialKill(I->
getOperand(1));
4656 unsigned ResultReg = emitMul_rr(VT, Src0Reg, Src0IsKill, Src1Reg, Src1IsKill);
4661 updateValueMap(I, ResultReg);
4665 bool AArch64FastISel::selectShift(
const Instruction *I) {
4667 if (!isTypeSupported(I->
getType(), RetVT,
true))
4671 return selectOperator(I, I->
getOpcode());
4673 if (
const auto *C = dyn_cast<ConstantInt>(I->
getOperand(1))) {
4674 unsigned ResultReg = 0;
4675 uint64_t ShiftVal = C->getZExtValue();
4677 bool IsZExt = I->
getOpcode() != Instruction::AShr;
4679 if (
const auto *ZExt = dyn_cast<ZExtInst>(Op0)) {
4682 if (isValueAvailable(ZExt) && isTypeSupported(ZExt->getSrcTy(), TmpVT)) {
4685 Op0 = ZExt->getOperand(0);
4688 }
else if (
const auto *SExt = dyn_cast<SExtInst>(Op0)) {
4691 if (isValueAvailable(SExt) && isTypeSupported(SExt->getSrcTy(), TmpVT)) {
4694 Op0 = SExt->getOperand(0);
4699 unsigned Op0Reg = getRegForValue(Op0);
4702 bool Op0IsKill = hasTrivialKill(Op0);
4706 case Instruction::Shl:
4707 ResultReg = emitLSL_ri(RetVT, SrcVT, Op0Reg, Op0IsKill, ShiftVal, IsZExt);
4709 case Instruction::AShr:
4710 ResultReg = emitASR_ri(RetVT, SrcVT, Op0Reg, Op0IsKill, ShiftVal, IsZExt);
4712 case Instruction::LShr:
4713 ResultReg = emitLSR_ri(RetVT, SrcVT, Op0Reg, Op0IsKill, ShiftVal, IsZExt);
4719 updateValueMap(I, ResultReg);
4723 unsigned Op0Reg = getRegForValue(I->
getOperand(0));
4726 bool Op0IsKill = hasTrivialKill(I->
getOperand(0));
4728 unsigned Op1Reg = getRegForValue(I->
getOperand(1));
4731 bool Op1IsKill = hasTrivialKill(I->
getOperand(1));
4733 unsigned ResultReg = 0;
4736 case Instruction::Shl:
4737 ResultReg = emitLSL_rr(RetVT, Op0Reg, Op0IsKill, Op1Reg, Op1IsKill);
4739 case Instruction::AShr:
4740 ResultReg = emitASR_rr(RetVT, Op0Reg, Op0IsKill, Op1Reg, Op1IsKill);
4742 case Instruction::LShr:
4743 ResultReg = emitLSR_rr(RetVT, Op0Reg, Op0IsKill, Op1Reg, Op1IsKill);
4750 updateValueMap(I, ResultReg);
4754 bool AArch64FastISel::selectBitCast(
const Instruction *I) {
4759 if (!isTypeLegal(I->
getType(), RetVT))
4764 Opc = AArch64::FMOVWSr;
4766 Opc = AArch64::FMOVXDr;
4768 Opc = AArch64::FMOVSWr;
4770 Opc = AArch64::FMOVDXr;
4777 case MVT::i32: RC = &AArch64::GPR32RegClass;
break;
4778 case MVT::i64: RC = &AArch64::GPR64RegClass;
break;
4779 case MVT::f32: RC = &AArch64::FPR32RegClass;
break;
4780 case MVT::f64: RC = &AArch64::FPR64RegClass;
break;
4782 unsigned Op0Reg = getRegForValue(I->
getOperand(0));
4785 bool Op0IsKill = hasTrivialKill(I->
getOperand(0));
4786 unsigned ResultReg = fastEmitInst_r(Opc, RC, Op0Reg, Op0IsKill);
4791 updateValueMap(I, ResultReg);
4795 bool AArch64FastISel::selectFRem(
const Instruction *I) {
4797 if (!isTypeLegal(I->
getType(), RetVT))
4805 LC = RTLIB::REM_F32;
4808 LC = RTLIB::REM_F64;
4820 Args.push_back(Entry);
4823 CallLoweringInfo CLI;
4825 CLI.setCallee(DL, Ctx, TLI.getLibcallCallingConv(LC), I->
getType(),
4826 TLI.getLibcallName(LC), std::move(Args));
4827 if (!lowerCallTo(CLI))
4829 updateValueMap(I, CLI.ResultReg);
4833 bool AArch64FastISel::selectSDiv(
const Instruction *I) {
4835 if (!isTypeLegal(I->
getType(), VT))
4847 unsigned Src0Reg = getRegForValue(I->
getOperand(0));
4850 bool Src0IsKill = hasTrivialKill(I->
getOperand(0));
4852 if (cast<BinaryOperator>(I)->isExact()) {
4853 unsigned ResultReg = emitASR_ri(VT, VT, Src0Reg, Src0IsKill, Lg2);
4856 updateValueMap(I, ResultReg);
4860 int64_t Pow2MinusOne = (1ULL << Lg2) - 1;
4861 unsigned AddReg = emitAdd_ri_(VT, Src0Reg,
false, Pow2MinusOne);
4866 if (!emitICmp_ri(VT, Src0Reg,
false, 0))
4872 SelectOpc = AArch64::CSELXr;
4873 RC = &AArch64::GPR64RegClass;
4875 SelectOpc = AArch64::CSELWr;
4876 RC = &AArch64::GPR32RegClass;
4878 unsigned SelectReg =
4879 fastEmitInst_rri(SelectOpc, RC, AddReg,
true, Src0Reg,
4886 unsigned ZeroReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
4889 ResultReg = emitAddSub_rs(
false, VT, ZeroReg,
true,
4892 ResultReg = emitASR_ri(VT, VT, SelectReg,
true, Lg2);
4897 updateValueMap(I, ResultReg);
4904 std::pair<unsigned, bool> AArch64FastISel::getRegForGEPIndex(
const Value *Idx) {
4905 unsigned IdxN = getRegForValue(Idx);
4908 return std::pair<unsigned, bool>(0,
false);
4910 bool IdxNIsKill = hasTrivialKill(Idx);
4913 MVT PtrVT = TLI.getPointerTy(DL);
4915 if (IdxVT.
bitsLT(PtrVT)) {
4916 IdxN = emitIntExt(IdxVT.
getSimpleVT(), IdxN, PtrVT,
false);
4918 }
else if (IdxVT.
bitsGT(PtrVT))
4919 llvm_unreachable(
"AArch64 FastISel doesn't support types larger than i64");
4920 return std::pair<unsigned, bool>(IdxN, IdxNIsKill);
4927 bool AArch64FastISel::selectGetElementPtr(
const Instruction *I) {
4931 bool NIsKill = hasTrivialKill(I->
getOperand(0));
4935 uint64_t TotalOffs = 0;
4936 MVT VT = TLI.getPointerTy(DL);
4939 const Value *Idx = GTI.getOperand();
4940 if (
auto *StTy = GTI.getStructTypeOrNull()) {
4941 unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
4944 TotalOffs += DL.getStructLayout(StTy)->getElementOffset(Field);
4946 Type *Ty = GTI.getIndexedType();
4949 if (
const auto *CI = dyn_cast<ConstantInt>(Idx)) {
4954 DL.getTypeAllocSize(Ty) * cast<ConstantInt>(CI)->getSExtValue();
4958 N = emitAdd_ri_(VT, N, NIsKill, TotalOffs);
4966 uint64_t ElementSize = DL.getTypeAllocSize(Ty);
4967 std::pair<unsigned, bool> Pair = getRegForGEPIndex(Idx);
4968 unsigned IdxN = Pair.first;
4969 bool IdxNIsKill = Pair.second;
4973 if (ElementSize != 1) {
4974 unsigned C = fastEmit_i(VT, VT,
ISD::Constant, ElementSize);
4977 IdxN = emitMul_rr(VT, IdxN, IdxNIsKill, C,
true);
4982 N = fastEmit_rr(VT, VT,
ISD::ADD, N, NIsKill, IdxN, IdxNIsKill);
4988 N = emitAdd_ri_(VT, N, NIsKill, TotalOffs);
4992 updateValueMap(I, N);
4998 "cmpxchg survived AtomicExpand at optlevel > -O0");
5000 auto *RetPairTy = cast<StructType>(I->
getType());
5001 Type *RetTy = RetPairTy->getTypeAtIndex(0U);
5002 assert(RetPairTy->getTypeAtIndex(1U)->isIntegerTy(1) &&
5003 "cmpxchg has a non-i1 status result");
5006 if (!isTypeLegal(RetTy, VT))
5010 unsigned Opc, CmpOpc;
5014 Opc = AArch64::CMP_SWAP_32;
5015 CmpOpc = AArch64::SUBSWrs;
5016 ResRC = &AArch64::GPR32RegClass;
5018 Opc = AArch64::CMP_SWAP_64;
5019 CmpOpc = AArch64::SUBSXrs;
5020 ResRC = &AArch64::GPR64RegClass;
5034 const unsigned ResultReg1 = createResultReg(ResRC);
5035 const unsigned ResultReg2 = createResultReg(&AArch64::GPR32RegClass);
5036 const unsigned ScratchReg = createResultReg(&AArch64::GPR32RegClass);
5039 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
5046 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(CmpOpc))
5047 .addDef(VT ==
MVT::i32 ? AArch64::WZR : AArch64::XZR)
5052 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr))
5058 assert((ResultReg1 + 1) == ResultReg2 &&
"Nonconsecutive result registers.");
5059 updateValueMap(I, ResultReg1, 2);
5063 bool AArch64FastISel::fastSelectInstruction(
const Instruction *I) {
5068 case Instruction::Sub:
5069 return selectAddSub(I);
5070 case Instruction::Mul:
5071 return selectMul(I);
5072 case Instruction::SDiv:
5073 return selectSDiv(I);
5074 case Instruction::SRem:
5078 case Instruction::URem:
5082 case Instruction::Shl:
5083 case Instruction::LShr:
5084 case Instruction::AShr:
5085 return selectShift(I);
5086 case Instruction::And:
5087 case Instruction::Or:
5088 case Instruction::Xor:
5089 return selectLogicalOp(I);
5090 case Instruction::Br:
5091 return selectBranch(I);
5092 case Instruction::IndirectBr:
5093 return selectIndirectBr(I);
5094 case Instruction::BitCast:
5096 return selectBitCast(I);
5098 case Instruction::FPToSI:
5100 return selectFPToInt(I,
true);
5102 case Instruction::FPToUI:
5103 return selectFPToInt(I,
false);
5104 case Instruction::ZExt:
5105 case Instruction::SExt:
5106 return selectIntExt(I);
5107 case Instruction::Trunc:
5109 return selectTrunc(I);
5111 case Instruction::FPExt:
5112 return selectFPExt(I);
5113 case Instruction::FPTrunc:
5114 return selectFPTrunc(I);
5115 case Instruction::SIToFP:
5117 return selectIntToFP(I,
true);
5119 case Instruction::UIToFP:
5120 return selectIntToFP(I,
false);
5122 return selectLoad(I);
5124 return selectStore(I);
5125 case Instruction::FCmp:
5126 case Instruction::ICmp:
5127 return selectCmp(I);
5129 return selectSelect(I);
5131 return selectRet(I);
5132 case Instruction::FRem:
5133 return selectFRem(I);
5134 case Instruction::GetElementPtr:
5135 return selectGetElementPtr(I);
5136 case Instruction::AtomicCmpXchg:
5137 return selectAtomicCmpXchg(cast<AtomicCmpXchgInst>(I));
5141 (void)&CC_AArch64_DarwinPCS_VarArg;
5142 (void)&CC_AArch64_Win64_VarArg;
5145 return selectOperator(I, I->
getOpcode());
5152 return new AArch64FastISel(FuncInfo, LibInfo);
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
void setFrameAddressIsTaken(bool T)
Return a value (possibly void), from a function.
static MVT getIntegerVT(unsigned BitWidth)
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)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
This class is the base class for the comparison instructions.
bool isLittleEndian() const
uint64_t getZExtValue() const
Get zero extended value.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
Atomic ordering constants.
C - The default llvm calling convention, compatible with C.
Compute iterated dominance frontiers using a linear time algorithm.
MO_PAGE - A symbol operand with this flag represents the pc-relative offset of the 4K page containing...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
bool isVector() const
Return true if this is a vector value type.
static CondCode getInvertedCondCode(CondCode Code)
Describe properties that are true of each instruction in the target description file.
unsigned getReg() const
getReg - Returns the register number.
unsigned char ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const
ClassifyGlobalReference - Find the target operand flags that describe how a global value should be re...
unsigned getSubReg() const
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit...
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change...
gep_type_iterator gep_type_end(const User *GEP)
const Value * getTrueValue() const
0 1 0 0 True if ordered and less than
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.
BasicBlock * getSuccessor(unsigned i) const
Value * getNewValOperand()
unsigned const TargetRegisterInfo * TRI
block Block Frequency true
An instruction for reading from memory.
Value * getCondition() const
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
bool isVectorTy() const
True if this is an instance of VectorType.
void reserve(size_type N)
Value * getLength() const
unsigned getFrameRegister(const MachineFunction &MF) const override
1 0 0 1 True if unordered or equal
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
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.
bool isTargetDarwin() const
This class represents the LLVM 'select' instruction.
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 ...
const HexagonInstrInfo * TII
PointerType * getType() const
Overload to return most specific pointer type.
Class to represent struct types.
const MachineInstrBuilder & addUse(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool isIntegerTy() const
True if this is an instance of IntegerType.
0 1 0 1 True if ordered and less than or equal
This file contains the simple types necessary to represent the attributes associated with functions a...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
static bool isLogicalImmediate(uint64_t imm, unsigned regSize)
isLogicalImmediate - Return true if the immediate is valid for a logical immediate instruction of the...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isTargetMachO() const
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
LocInfo getLocInfo() const
This file implements a class to represent arbitrary precision integral constant values and operations...
bool is64BitVector() const
Return true if this is a 64-bit vector type.
AtomicOrdering
Atomic ordering for LLVM's memory model.
unsigned getSizeInBits() const
Context object for machine code objects.
Value * getPointerOperand()
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
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.
unsigned getNextStackOffset() const
getNextStackOffset - Return the next stack offset such that all stack slots satisfy their alignment r...
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.
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
MO_GOT - This flag indicates that a symbol operand represents the address of the GOT entry for the sy...
const AArch64RegisterInfo * getRegisterInfo() const override
static bool isZExtLoad(const MachineInstr *LI)
bool isNegative() const
Return true if the sign bit is set.
Simple integer binary arithmetic operators.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo)
amdgpu Simplify well known AMD library false Value * Callee
Value * getOperand(unsigned i) const
unsigned getKillRegState(bool B)
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
static unsigned getShifterImm(AArch64_AM::ShiftExtendType ST, unsigned Imm)
getShifterImm - Encode the shift type and amount: imm: 6-bit shift amount shifter: 000 ==> lsl 001 ==...
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.
Value * getOperand(unsigned i_nocapture) const
bool is128BitVector() const
Return true if this is a 128-bit vector type.
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
static unsigned selectBinaryOp(unsigned GenericOpc, unsigned RegBankID, unsigned OpSize)
Select the AArch64 opcode for the basic binary operation GenericOpc (such as G_OR or G_SDIV)...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool isNegative() const
Determine sign of this APInt.
Type * getReturnType() const
Returns the type of the ret val.
Control flow instructions. These all have token chains.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
static int getFP32Imm(const APInt &Imm)
getFP32Imm - Return an 8-bit floating-point version of the 32-bit floating-point value.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Value * getCompareOperand()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Indirect Branch Instruction.
static bool isIntExtFree(const Instruction *I)
Check if the sign-/zero-extend will be a noop.
ConstantFP - Floating Point Values [float, double].
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
bool useSmallAddressing() const
static bool isSExtLoad(const MachineInstr *LI)
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static AArch64CC::CondCode getCompareCC(CmpInst::Predicate Pred)
0 1 1 1 True if ordered (no nans)
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const Value * getCondition() const
1 1 1 1 Always true (always folded)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
static unsigned getImplicitScaleFactor(MVT VT)
Determine the implicit scale factor that is applied by a memory operation for a given value type...
iterator_range< User::op_iterator > arg_operands()
Iteration adapter for range-for loops.
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.
The memory access writes data.
const APFloat & getValueAPF() const
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
bool isReleaseOrStronger(AtomicOrdering ao)
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...
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
0 0 1 0 True if ordered and greater than
static uint64_t encodeLogicalImmediate(uint64_t imm, unsigned regSize)
encodeLogicalImmediate - Return the encoded immediate value for a logical immediate instruction of th...
static int getFP64Imm(const APInt &Imm)
getFP64Imm - Return an 8-bit floating-point version of the 64-bit floating-point value.
static AArch64_AM::ShiftExtendType getExtendType(unsigned Imm)
getExtendType - Extract the extend type for operands of arithmetic ops.
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.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
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.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned char TargetFlags=0) const
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool selectBitCast(const User *I)
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
This file defines the FastISel class.
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
void AnalyzeCallOperands(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeCallOperands - Analyze the outgoing arguments to a call, incorporating info about the passed v...
const Value * getFalseValue() const
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
Flags
Flags values. These may be or'd together.
amdgpu Simplify well known AMD library false Value Value * Arg
The memory access reads data.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Representation of each machine instruction.
bool isVector() const
Return true if this is a vector value type.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
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 getNumArgOperands() const
Return the number of call arguments.
unsigned greater or equal
bool isZero() const
Return true if the value is positive or negative zero.
static unsigned UseReg(const MachineOperand &MO)
const Function * getParent() const
Return the enclosing method, or null if none.
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
MO_PAGEOFF - A symbol operand with this flag represents the offset of that symbol within a 4K page...
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
0 1 1 0 True if ordered and operands are unequal
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool isUnconditional() const
1 0 1 0 True if unordered or greater than
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
static SDValue emitCmp(SelectionDAG &DAG, const SDLoc &DL, Comparison &C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static const unsigned FramePtr
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
bool hasOneUse() const
Return true if there is exactly one user of this value.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
MO_NC - Indicates whether the linker is expected to check the symbol reference for overflow...
unsigned constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const MCInstrDesc &II, const MachineOperand &RegMO, unsigned OpIdx)
Try to constrain Reg so that it is usable by argument OpIdx of the provided MCInstrDesc II...
APInt bitcastToAPInt() const
const MachineInstrBuilder & addDef(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
unsigned getLocReg() const
TRUNCATE - Completely drop the high bits.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
const MachineOperand & getOperand(unsigned i) const
0 0 1 1 True if ordered and greater than or equal
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
PointerType * getType() const
Global values are always pointers.
iterator_range< arg_iterator > args()
0 0 0 0 Always false (always folded)
bool isStructTy() const
True if this is an instance of StructType.
bool isArrayTy() const
True if this is an instance of ArrayType.
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
static bool isMulPowOf2(const Value *I)
Check if the multiply is by a power-of-2 constant.
gep_type_iterator gep_type_begin(const User *GEP)
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...