79 class AArch64FastISel final :
public FastISel {
82 using BaseKind =
enum {
88 BaseKind
Kind = RegBase;
94 unsigned OffsetReg = 0;
102 void setKind(BaseKind K) { Kind = K; }
103 BaseKind getKind()
const {
return Kind; }
106 bool isRegBase()
const {
return Kind == RegBase; }
107 bool isFIBase()
const {
return Kind == FrameIndexBase; }
109 void setReg(
unsigned Reg) {
110 assert(isRegBase() &&
"Invalid base register access!");
115 assert(isRegBase() &&
"Invalid base register access!");
119 void setOffsetReg(
unsigned Reg) {
123 unsigned getOffsetReg()
const {
127 void setFI(
unsigned FI) {
128 assert(isFIBase() &&
"Invalid base frame index access!");
132 unsigned getFI()
const {
133 assert(isFIBase() &&
"Invalid base frame index access!");
137 void setOffset(int64_t
O) { Offset =
O; }
139 void setShift(
unsigned S) { Shift = S; }
140 unsigned getShift() {
return Shift; }
151 bool fastLowerArguments()
override;
152 bool fastLowerCall(CallLoweringInfo &CLI)
override;
153 bool fastLowerIntrinsicCall(
const IntrinsicInst *II)
override;
169 bool selectRem(
const Instruction *
I,
unsigned ISDOpcode);
182 bool isTypeLegal(
Type *Ty,
MVT &VT);
183 bool isTypeSupported(
Type *Ty,
MVT &VT,
bool IsVectorAllowed =
false);
184 bool isValueAvailable(
const Value *V)
const;
191 bool isMemCpySmall(uint64_t Len,
unsigned Alignment);
198 std::pair<unsigned, bool> getRegForGEPIndex(
const Value *Idx);
201 unsigned emitAddSub(
bool UseAdd,
MVT RetVT,
const Value *LHS,
202 const Value *RHS,
bool SetFlags =
false,
203 bool WantResult =
true,
bool IsZExt =
false);
204 unsigned emitAddSub_rr(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
205 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
206 bool SetFlags =
false,
bool WantResult =
true);
207 unsigned emitAddSub_ri(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
208 bool LHSIsKill, uint64_t Imm,
bool SetFlags =
false,
209 bool WantResult =
true);
210 unsigned emitAddSub_rs(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
211 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
213 uint64_t ShiftImm,
bool SetFlags =
false,
214 bool WantResult =
true);
215 unsigned emitAddSub_rx(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
216 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
218 uint64_t ShiftImm,
bool SetFlags =
false,
219 bool WantResult =
true);
222 bool emitCompareAndBranch(
const BranchInst *BI);
224 bool emitICmp(
MVT RetVT,
const Value *LHS,
const Value *RHS,
bool IsZExt);
225 bool emitICmp_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill, uint64_t Imm);
226 bool emitFCmp(
MVT RetVT,
const Value *LHS,
const Value *RHS);
227 unsigned emitLoad(
MVT VT,
MVT ResultVT,
Address Addr,
bool WantZExt =
true,
229 bool emitStore(
MVT VT,
unsigned SrcReg,
Address Addr,
231 bool emitStoreRelease(
MVT VT,
unsigned SrcReg,
unsigned AddrReg,
233 unsigned emitIntExt(
MVT SrcVT,
unsigned SrcReg,
MVT DestVT,
bool isZExt);
234 unsigned emiti1Ext(
unsigned SrcReg,
MVT DestVT,
bool isZExt);
235 unsigned emitAdd(
MVT RetVT,
const Value *LHS,
const Value *RHS,
236 bool SetFlags =
false,
bool WantResult =
true,
237 bool IsZExt =
false);
238 unsigned emitAdd_ri_(
MVT VT,
unsigned Op0,
bool Op0IsKill, int64_t Imm);
239 unsigned emitSub(
MVT RetVT,
const Value *LHS,
const Value *RHS,
240 bool SetFlags =
false,
bool WantResult =
true,
241 bool IsZExt =
false);
242 unsigned emitSubs_rr(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
243 unsigned RHSReg,
bool RHSIsKill,
bool WantResult =
true);
244 unsigned emitSubs_rs(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
245 unsigned RHSReg,
bool RHSIsKill,
247 bool WantResult =
true);
248 unsigned emitLogicalOp(
unsigned ISDOpc,
MVT RetVT,
const Value *LHS,
250 unsigned emitLogicalOp_ri(
unsigned ISDOpc,
MVT RetVT,
unsigned LHSReg,
251 bool LHSIsKill, uint64_t Imm);
252 unsigned emitLogicalOp_rs(
unsigned ISDOpc,
MVT RetVT,
unsigned LHSReg,
253 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
255 unsigned emitAnd_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill, uint64_t Imm);
256 unsigned emitMul_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
257 unsigned Op1,
bool Op1IsKill);
258 unsigned emitSMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
259 unsigned Op1,
bool Op1IsKill);
260 unsigned emitUMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
261 unsigned Op1,
bool Op1IsKill);
262 unsigned emitLSL_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
263 unsigned Op1Reg,
bool Op1IsKill);
264 unsigned emitLSL_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0Reg,
bool Op0IsKill,
265 uint64_t Imm,
bool IsZExt =
true);
266 unsigned emitLSR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
267 unsigned Op1Reg,
bool Op1IsKill);
268 unsigned emitLSR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0Reg,
bool Op0IsKill,
269 uint64_t Imm,
bool IsZExt =
true);
270 unsigned emitASR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
271 unsigned Op1Reg,
bool Op1IsKill);
272 unsigned emitASR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0Reg,
bool Op0IsKill,
273 uint64_t Imm,
bool IsZExt =
false);
284 bool finishCall(CallLoweringInfo &CLI,
MVT RetVT,
unsigned NumBytes);
288 unsigned fastMaterializeAlloca(
const AllocaInst *AI)
override;
289 unsigned fastMaterializeConstant(
const Constant *
C)
override;
290 unsigned fastMaterializeFloatZero(
const ConstantFP* CF)
override;
300 bool fastSelectInstruction(
const Instruction *
I)
override;
302 #include "AArch64GenFastISel.inc" 309 assert((isa<ZExtInst>(I) || isa<SExtInst>(I)) &&
310 "Unexpected integer extend instruction.");
312 "Unexpected value type.");
313 bool IsZExt = isa<ZExtInst>(
I);
315 if (
const auto *LI = dyn_cast<LoadInst>(I->
getOperand(0)))
320 if ((IsZExt &&
Arg->hasZExtAttr()) || (!IsZExt &&
Arg->hasSExtAttr()))
356 unsigned AArch64FastISel::fastMaterializeAlloca(
const AllocaInst *AI) {
358 "Alloca should always return a pointer.");
361 if (!FuncInfo.StaticAllocaMap.count(AI))
365 FuncInfo.StaticAllocaMap.find(AI);
367 if (SI != FuncInfo.StaticAllocaMap.
end()) {
368 unsigned ResultReg = createResultReg(&AArch64::GPR64spRegClass);
369 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::ADDXri),
371 .addFrameIndex(SI->second)
380 unsigned AArch64FastISel::materializeInt(
const ConstantInt *CI,
MVT VT) {
389 : &AArch64::GPR32RegClass;
390 unsigned ZeroReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
391 unsigned ResultReg = createResultReg(RC);
392 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpcode::COPY),
397 unsigned AArch64FastISel::materializeFP(
const ConstantFP *CFP,
MVT VT) {
401 return fastMaterializeFloatZero(CFP);
413 unsigned Opc = Is64Bit ? AArch64::FMOVDi : AArch64::FMOVSi;
414 return fastEmitInst_i(Opc, TLI.getRegClassFor(VT), Imm);
419 unsigned Opc1 = Is64Bit ? AArch64::MOVi64imm : AArch64::MOVi32imm;
421 &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
423 unsigned TmpReg = createResultReg(RC);
424 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc1), TmpReg)
427 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
428 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
429 TII.get(TargetOpcode::COPY), ResultReg)
437 unsigned Align = DL.getPrefTypeAlignment(CFP->
getType());
439 Align = DL.getTypeAllocSize(CFP->
getType());
441 unsigned CPI = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align);
442 unsigned ADRPReg = createResultReg(&AArch64::GPR64commonRegClass);
446 unsigned Opc = Is64Bit ? AArch64::LDRDui : AArch64::LDRSui;
447 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
448 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
454 unsigned AArch64FastISel::materializeGV(
const GlobalValue *GV) {
466 EVT DestEVT = TLI.getValueType(DL, GV->
getType(),
true);
470 unsigned ADRPReg = createResultReg(&AArch64::GPR64commonRegClass);
481 ResultReg = createResultReg(&AArch64::GPR32RegClass);
482 LdrOpc = AArch64::LDRWui;
484 ResultReg = createResultReg(&AArch64::GPR64RegClass);
485 LdrOpc = AArch64::LDRXui;
487 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(LdrOpc),
497 unsigned Result64 = createResultReg(&AArch64::GPR64RegClass);
498 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
499 TII.get(TargetOpcode::SUBREG_TO_REG))
511 ResultReg = createResultReg(&AArch64::GPR64spRegClass);
512 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::ADDXri),
522 unsigned AArch64FastISel::fastMaterializeConstant(
const Constant *
C) {
523 EVT CEVT = TLI.getValueType(DL, C->
getType(),
true);
531 if (
const auto *CPN = dyn_cast<ConstantPointerNull>(C)) {
533 assert(CPN->getType()->getPointerAddressSpace() == 0 &&
534 "Unexpected address space");
539 if (
const auto *CI = dyn_cast<ConstantInt>(C))
540 return materializeInt(CI, VT);
541 else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
542 return materializeFP(CFP, VT);
543 else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C))
544 return materializeGV(GV);
549 unsigned AArch64FastISel::fastMaterializeFloatZero(
const ConstantFP* CFP) {
551 "Floating-point constant is not a positive zero.");
553 if (!isTypeLegal(CFP->
getType(), VT))
560 unsigned ZReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
561 unsigned Opc = Is64Bit ? AArch64::FMOVXDr : AArch64::FMOVWSr;
562 return fastEmitInst_r(Opc, TLI.getRegClassFor(VT), ZReg,
true);
567 if (
const auto *
MI = dyn_cast<MulOperator>(I)) {
568 if (
const auto *C = dyn_cast<ConstantInt>(
MI->getOperand(0)))
569 if (C->getValue().isPowerOf2())
571 if (
const auto *C = dyn_cast<ConstantInt>(
MI->getOperand(1)))
572 if (C->getValue().isPowerOf2())
579 bool AArch64FastISel::computeAddress(
const Value *Obj,
Address &Addr,
Type *Ty)
581 const User *U =
nullptr;
582 unsigned Opcode = Instruction::UserOp1;
583 if (
const Instruction *
I = dyn_cast<Instruction>(Obj)) {
586 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
587 FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
588 Opcode =
I->getOpcode();
591 }
else if (
const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
592 Opcode = C->getOpcode();
596 if (
auto *Ty = dyn_cast<PointerType>(Obj->
getType()))
597 if (Ty->getAddressSpace() > 255)
605 case Instruction::BitCast:
607 return computeAddress(U->
getOperand(0), Addr, Ty);
609 case Instruction::IntToPtr:
612 TLI.getPointerTy(DL))
613 return computeAddress(U->
getOperand(0), Addr, Ty);
616 case Instruction::PtrToInt:
618 if (TLI.getValueType(DL, U->
getType()) == TLI.getPointerTy(DL))
619 return computeAddress(U->
getOperand(0), Addr, Ty);
622 case Instruction::GetElementPtr: {
624 uint64_t TmpOffset = Addr.getOffset();
630 const Value *
Op = GTI.getOperand();
631 if (
StructType *STy = GTI.getStructTypeOrNull()) {
633 unsigned Idx = cast<ConstantInt>(
Op)->getZExtValue();
636 uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
638 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
643 if (canFoldAddIntoGEP(U, Op)) {
646 cast<ConstantInt>(cast<AddOperator>(
Op)->getOperand(1));
649 Op = cast<AddOperator>(
Op)->getOperand(0);
653 goto unsupported_gep;
659 Addr.setOffset(TmpOffset);
660 if (computeAddress(U->
getOperand(0), Addr, Ty))
669 case Instruction::Alloca: {
672 FuncInfo.StaticAllocaMap.find(AI);
673 if (SI != FuncInfo.StaticAllocaMap.end()) {
674 Addr.setKind(Address::FrameIndexBase);
675 Addr.setFI(SI->second);
685 if (isa<ConstantInt>(LHS))
688 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
690 return computeAddress(LHS, Addr, Ty);
694 if (computeAddress(LHS, Addr, Ty) && computeAddress(RHS, Addr, Ty))
700 case Instruction::Sub: {
705 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
707 return computeAddress(LHS, Addr, Ty);
711 case Instruction::Shl: {
712 if (Addr.getOffsetReg())
720 if (Val < 1 || Val > 3)
723 uint64_t NumBytes = 0;
725 uint64_t NumBits = DL.getTypeSizeInBits(Ty);
726 NumBytes = NumBits / 8;
731 if (NumBytes != (1ULL << Val))
738 if (
const auto *
I = dyn_cast<Instruction>(Src)) {
739 if (FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
741 if (
const auto *ZE = dyn_cast<ZExtInst>(
I)) {
743 ZE->getOperand(0)->getType()->isIntegerTy(32)) {
745 Src = ZE->getOperand(0);
747 }
else if (
const auto *SE = dyn_cast<SExtInst>(
I)) {
749 SE->getOperand(0)->getType()->isIntegerTy(32)) {
751 Src = SE->getOperand(0);
757 if (
const auto *AI = dyn_cast<BinaryOperator>(Src))
758 if (AI->
getOpcode() == Instruction::And) {
762 if (
const auto *C = dyn_cast<ConstantInt>(LHS))
763 if (C->getValue() == 0xffffffff)
766 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
767 if (C->getValue() == 0xffffffff) {
769 unsigned Reg = getRegForValue(LHS);
772 bool RegIsKill = hasTrivialKill(LHS);
773 Reg = fastEmitInst_extractsubreg(
MVT::i32, Reg, RegIsKill,
775 Addr.setOffsetReg(Reg);
780 unsigned Reg = getRegForValue(Src);
783 Addr.setOffsetReg(Reg);
786 case Instruction::Mul: {
787 if (Addr.getOffsetReg())
797 if (
const auto *C = dyn_cast<ConstantInt>(LHS))
798 if (C->getValue().isPowerOf2())
801 assert(isa<ConstantInt>(RHS) &&
"Expected an ConstantInt.");
802 const auto *C = cast<ConstantInt>(RHS);
803 unsigned Val = C->getValue().logBase2();
804 if (Val < 1 || Val > 3)
807 uint64_t NumBytes = 0;
809 uint64_t NumBits = DL.getTypeSizeInBits(Ty);
810 NumBytes = NumBits / 8;
815 if (NumBytes != (1ULL << Val))
821 const Value *Src = LHS;
822 if (
const auto *
I = dyn_cast<Instruction>(Src)) {
823 if (FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
825 if (
const auto *ZE = dyn_cast<ZExtInst>(
I)) {
827 ZE->getOperand(0)->getType()->isIntegerTy(32)) {
829 Src = ZE->getOperand(0);
831 }
else if (
const auto *SE = dyn_cast<SExtInst>(
I)) {
833 SE->getOperand(0)->getType()->isIntegerTy(32)) {
835 Src = SE->getOperand(0);
841 unsigned Reg = getRegForValue(Src);
844 Addr.setOffsetReg(Reg);
847 case Instruction::And: {
848 if (Addr.getOffsetReg())
851 if (!Ty || DL.getTypeSizeInBits(Ty) != 8)
857 if (
const auto *C = dyn_cast<ConstantInt>(LHS))
858 if (C->getValue() == 0xffffffff)
861 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
862 if (C->getValue() == 0xffffffff) {
867 unsigned Reg = getRegForValue(LHS);
870 bool RegIsKill = hasTrivialKill(LHS);
871 Reg = fastEmitInst_extractsubreg(
MVT::i32, Reg, RegIsKill,
873 Addr.setOffsetReg(Reg);
878 case Instruction::SExt:
879 case Instruction::ZExt: {
880 if (!Addr.getReg() || Addr.getOffsetReg())
883 const Value *Src =
nullptr;
885 if (
const auto *ZE = dyn_cast<ZExtInst>(U)) {
886 if (!
isIntExtFree(ZE) && ZE->getOperand(0)->getType()->isIntegerTy(32)) {
888 Src = ZE->getOperand(0);
890 }
else if (
const auto *SE = dyn_cast<SExtInst>(U)) {
891 if (!
isIntExtFree(SE) && SE->getOperand(0)->getType()->isIntegerTy(32)) {
893 Src = SE->getOperand(0);
901 unsigned Reg = getRegForValue(Src);
904 Addr.setOffsetReg(Reg);
909 if (Addr.isRegBase() && !Addr.getReg()) {
910 unsigned Reg = getRegForValue(Obj);
917 if (!Addr.getOffsetReg()) {
918 unsigned Reg = getRegForValue(Obj);
921 Addr.setOffsetReg(Reg);
928 bool AArch64FastISel::computeCallAddress(
const Value *V,
Address &Addr) {
929 const User *U =
nullptr;
930 unsigned Opcode = Instruction::UserOp1;
933 if (
const auto *
I = dyn_cast<Instruction>(V)) {
934 Opcode =
I->getOpcode();
936 InMBB =
I->getParent() == FuncInfo.MBB->getBasicBlock();
937 }
else if (
const auto *C = dyn_cast<ConstantExpr>(V)) {
938 Opcode = C->getOpcode();
944 case Instruction::BitCast:
947 return computeCallAddress(U->
getOperand(0), Addr);
949 case Instruction::IntToPtr:
953 TLI.getPointerTy(DL))
954 return computeCallAddress(U->
getOperand(0), Addr);
956 case Instruction::PtrToInt:
958 if (InMBB && TLI.getValueType(DL, U->
getType()) == TLI.getPointerTy(DL))
959 return computeCallAddress(U->
getOperand(0), Addr);
963 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
964 Addr.setGlobalValue(GV);
969 if (!Addr.getGlobalValue()) {
970 Addr.setReg(getRegForValue(V));
971 return Addr.getReg() != 0;
977 bool AArch64FastISel::isTypeLegal(
Type *Ty,
MVT &VT) {
978 EVT evt = TLI.getValueType(DL, Ty,
true);
994 return TLI.isTypeLegal(VT);
1001 bool AArch64FastISel::isTypeSupported(
Type *Ty,
MVT &VT,
bool IsVectorAllowed) {
1005 if (isTypeLegal(Ty, VT))
1016 bool AArch64FastISel::isValueAvailable(
const Value *V)
const {
1017 if (!isa<Instruction>(V))
1020 const auto *
I = cast<Instruction>(V);
1021 return FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB;
1024 bool AArch64FastISel::simplifyAddress(
Address &Addr,
MVT VT) {
1032 bool ImmediateOffsetNeedsLowering =
false;
1033 bool RegisterOffsetNeedsLowering =
false;
1034 int64_t Offset = Addr.getOffset();
1035 if (((Offset < 0) || (Offset & (ScaleFactor - 1))) && !isInt<9>(Offset))
1036 ImmediateOffsetNeedsLowering =
true;
1037 else if (Offset > 0 && !(Offset & (ScaleFactor - 1)) &&
1038 !isUInt<12>(Offset / ScaleFactor))
1039 ImmediateOffsetNeedsLowering =
true;
1044 if (!ImmediateOffsetNeedsLowering && Addr.getOffset() && Addr.getOffsetReg())
1045 RegisterOffsetNeedsLowering =
true;
1048 if (Addr.isRegBase() && Addr.getOffsetReg() && !Addr.getReg())
1049 RegisterOffsetNeedsLowering =
true;
1054 if ((ImmediateOffsetNeedsLowering || Addr.getOffsetReg()) && Addr.isFIBase())
1056 unsigned ResultReg = createResultReg(&AArch64::GPR64spRegClass);
1057 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::ADDXri),
1059 .addFrameIndex(Addr.getFI())
1062 Addr.setKind(Address::RegBase);
1063 Addr.setReg(ResultReg);
1066 if (RegisterOffsetNeedsLowering) {
1067 unsigned ResultReg = 0;
1068 if (Addr.getReg()) {
1071 ResultReg = emitAddSub_rx(
true,
MVT::i64, Addr.getReg(),
1072 false, Addr.getOffsetReg(),
1073 false, Addr.getExtendType(),
1076 ResultReg = emitAddSub_rs(
true,
MVT::i64, Addr.getReg(),
1077 false, Addr.getOffsetReg(),
1083 false, Addr.getShift(),
1087 false, Addr.getShift(),
1091 false, Addr.getShift());
1096 Addr.setReg(ResultReg);
1097 Addr.setOffsetReg(0);
1104 if (ImmediateOffsetNeedsLowering) {
1114 Addr.setReg(ResultReg);
1120 void AArch64FastISel::addLoadStoreOperands(
Address &Addr,
1123 unsigned ScaleFactor,
1125 int64_t Offset = Addr.getOffset() / ScaleFactor;
1127 if (Addr.isFIBase()) {
1128 int FI = Addr.getFI();
1131 MMO = FuncInfo.MF->getMachineMemOperand(
1133 MFI.getObjectSize(FI), MFI.getObjectAlignment(FI));
1137 assert(Addr.isRegBase() &&
"Unexpected address kind.");
1144 if (Addr.getOffsetReg()) {
1145 assert(Addr.getOffset() == 0 &&
"Unexpected offset");
1148 MIB.
addReg(Addr.getReg());
1149 MIB.
addReg(Addr.getOffsetReg());
1151 MIB.
addImm(Addr.getShift() != 0);
1153 MIB.
addReg(Addr.getReg()).addImm(Offset);
1160 unsigned AArch64FastISel::emitAddSub(
bool UseAdd,
MVT RetVT,
const Value *LHS,
1161 const Value *RHS,
bool SetFlags,
1162 bool WantResult,
bool IsZExt) {
1164 bool NeedExtend =
false;
1187 if (UseAdd && isa<Constant>(LHS) && !isa<Constant>(RHS))
1191 if (UseAdd && LHS->
hasOneUse() && isValueAvailable(LHS))
1196 if (UseAdd && LHS->
hasOneUse() && isValueAvailable(LHS))
1197 if (
const auto *
SI = dyn_cast<BinaryOperator>(LHS))
1198 if (isa<ConstantInt>(
SI->getOperand(1)))
1199 if (
SI->getOpcode() == Instruction::Shl ||
1200 SI->getOpcode() == Instruction::LShr ||
1201 SI->getOpcode() == Instruction::AShr )
1204 unsigned LHSReg = getRegForValue(LHS);
1207 bool LHSIsKill = hasTrivialKill(LHS);
1210 LHSReg = emitIntExt(SrcVT, LHSReg, RetVT, IsZExt);
1212 unsigned ResultReg = 0;
1213 if (
const auto *C = dyn_cast<ConstantInt>(RHS)) {
1214 uint64_t Imm = IsZExt ? C->getZExtValue() : C->getSExtValue();
1215 if (C->isNegative())
1216 ResultReg = emitAddSub_ri(!UseAdd, RetVT, LHSReg, LHSIsKill, -Imm,
1217 SetFlags, WantResult);
1219 ResultReg = emitAddSub_ri(UseAdd, RetVT, LHSReg, LHSIsKill, Imm, SetFlags,
1221 }
else if (
const auto *C = dyn_cast<Constant>(RHS))
1223 ResultReg = emitAddSub_ri(UseAdd, RetVT, LHSReg, LHSIsKill, 0, SetFlags,
1231 isValueAvailable(RHS)) {
1232 if (
const auto *
SI = dyn_cast<BinaryOperator>(RHS))
1233 if (
const auto *C = dyn_cast<ConstantInt>(
SI->getOperand(1)))
1234 if ((
SI->getOpcode() == Instruction::Shl) && (C->getZExtValue() < 4)) {
1235 unsigned RHSReg = getRegForValue(
SI->getOperand(0));
1238 bool RHSIsKill = hasTrivialKill(
SI->getOperand(0));
1239 return emitAddSub_rx(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg,
1240 RHSIsKill, ExtendType, C->getZExtValue(),
1241 SetFlags, WantResult);
1243 unsigned RHSReg = getRegForValue(RHS);
1246 bool RHSIsKill = hasTrivialKill(RHS);
1247 return emitAddSub_rx(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg, RHSIsKill,
1248 ExtendType, 0, SetFlags, WantResult);
1252 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1254 const Value *MulLHS = cast<MulOperator>(RHS)->getOperand(0);
1255 const Value *MulRHS = cast<MulOperator>(RHS)->getOperand(1);
1257 if (
const auto *C = dyn_cast<ConstantInt>(MulLHS))
1258 if (C->getValue().isPowerOf2())
1261 assert(isa<ConstantInt>(MulRHS) &&
"Expected a ConstantInt.");
1262 uint64_t ShiftVal = cast<ConstantInt>(MulRHS)->getValue().logBase2();
1263 unsigned RHSReg = getRegForValue(MulLHS);
1266 bool RHSIsKill = hasTrivialKill(MulLHS);
1267 ResultReg = emitAddSub_rs(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg,
1276 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1277 if (
const auto *
SI = dyn_cast<BinaryOperator>(RHS)) {
1278 if (
const auto *C = dyn_cast<ConstantInt>(
SI->getOperand(1))) {
1280 switch (
SI->getOpcode()) {
1286 uint64_t ShiftVal = C->getZExtValue();
1288 unsigned RHSReg = getRegForValue(
SI->getOperand(0));
1291 bool RHSIsKill = hasTrivialKill(
SI->getOperand(0));
1292 ResultReg = emitAddSub_rs(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg,
1293 RHSIsKill, ShiftType, ShiftVal, SetFlags,
1302 unsigned RHSReg = getRegForValue(RHS);
1305 bool RHSIsKill = hasTrivialKill(RHS);
1308 RHSReg = emitIntExt(SrcVT, RHSReg, RetVT, IsZExt);
1310 return emitAddSub_rr(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg, RHSIsKill,
1311 SetFlags, WantResult);
1314 unsigned AArch64FastISel::emitAddSub_rr(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1315 bool LHSIsKill,
unsigned RHSReg,
1316 bool RHSIsKill,
bool SetFlags,
1318 assert(LHSReg && RHSReg &&
"Invalid register number.");
1320 if (LHSReg == AArch64::SP || LHSReg == AArch64::WSP ||
1321 RHSReg == AArch64::SP || RHSReg == AArch64::WSP)
1327 static const unsigned OpcTable[2][2][2] = {
1328 { { AArch64::SUBWrr, AArch64::SUBXrr },
1329 { AArch64::ADDWrr, AArch64::ADDXrr } },
1330 { { AArch64::SUBSWrr, AArch64::SUBSXrr },
1331 { AArch64::ADDSWrr, AArch64::ADDSXrr } }
1334 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1336 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1339 ResultReg = createResultReg(RC);
1341 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1346 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1352 unsigned AArch64FastISel::emitAddSub_ri(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1353 bool LHSIsKill, uint64_t Imm,
1354 bool SetFlags,
bool WantResult) {
1355 assert(LHSReg &&
"Invalid register number.");
1361 if (isUInt<12>(Imm))
1363 else if ((Imm & 0xfff000) == Imm) {
1369 static const unsigned OpcTable[2][2][2] = {
1370 { { AArch64::SUBWri, AArch64::SUBXri },
1371 { AArch64::ADDWri, AArch64::ADDXri } },
1372 { { AArch64::SUBSWri, AArch64::SUBSXri },
1373 { AArch64::ADDSWri, AArch64::ADDSXri } }
1376 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1379 RC = Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1381 RC = Is64Bit ? &AArch64::GPR64spRegClass : &AArch64::GPR32spRegClass;
1384 ResultReg = createResultReg(RC);
1386 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1390 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1397 unsigned AArch64FastISel::emitAddSub_rs(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1398 bool LHSIsKill,
unsigned RHSReg,
1401 uint64_t ShiftImm,
bool SetFlags,
1403 assert(LHSReg && RHSReg &&
"Invalid register number.");
1404 assert(LHSReg != AArch64::SP && LHSReg != AArch64::WSP &&
1405 RHSReg != AArch64::SP && RHSReg != AArch64::WSP);
1414 static const unsigned OpcTable[2][2][2] = {
1415 { { AArch64::SUBWrs, AArch64::SUBXrs },
1416 { AArch64::ADDWrs, AArch64::ADDXrs } },
1417 { { AArch64::SUBSWrs, AArch64::SUBSXrs },
1418 { AArch64::ADDSWrs, AArch64::ADDSXrs } }
1421 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1423 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1426 ResultReg = createResultReg(RC);
1428 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1433 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1440 unsigned AArch64FastISel::emitAddSub_rx(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1441 bool LHSIsKill,
unsigned RHSReg,
1444 uint64_t ShiftImm,
bool SetFlags,
1446 assert(LHSReg && RHSReg &&
"Invalid register number.");
1447 assert(LHSReg != AArch64::XZR && LHSReg != AArch64::WZR &&
1448 RHSReg != AArch64::XZR && RHSReg != AArch64::WZR);
1456 static const unsigned OpcTable[2][2][2] = {
1457 { { AArch64::SUBWrx, AArch64::SUBXrx },
1458 { AArch64::ADDWrx, AArch64::ADDXrx } },
1459 { { AArch64::SUBSWrx, AArch64::SUBSXrx },
1460 { AArch64::ADDSWrx, AArch64::ADDSXrx } }
1463 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1466 RC = Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1468 RC = Is64Bit ? &AArch64::GPR64spRegClass : &AArch64::GPR32spRegClass;
1471 ResultReg = createResultReg(RC);
1473 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1478 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1487 EVT EVT = TLI.getValueType(DL, Ty,
true);
1500 return emitICmp(VT, LHS, RHS, IsZExt);
1503 return emitFCmp(VT, LHS, RHS);
1507 bool AArch64FastISel::emitICmp(
MVT RetVT,
const Value *LHS,
const Value *RHS,
1509 return emitSub(RetVT, LHS, RHS,
true,
false,
1513 bool AArch64FastISel::emitICmp_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
1515 return emitAddSub_ri(
false, RetVT, LHSReg, LHSIsKill, Imm,
1519 bool AArch64FastISel::emitFCmp(
MVT RetVT,
const Value *LHS,
const Value *RHS) {
1525 bool UseImm =
false;
1526 if (
const auto *CFP = dyn_cast<ConstantFP>(RHS))
1530 unsigned LHSReg = getRegForValue(LHS);
1533 bool LHSIsKill = hasTrivialKill(LHS);
1536 unsigned Opc = (RetVT ==
MVT::f64) ? AArch64::FCMPDri : AArch64::FCMPSri;
1537 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
1542 unsigned RHSReg = getRegForValue(RHS);
1545 bool RHSIsKill = hasTrivialKill(RHS);
1547 unsigned Opc = (RetVT ==
MVT::f64) ? AArch64::FCMPDrr : AArch64::FCMPSrr;
1548 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
1554 unsigned AArch64FastISel::emitAdd(
MVT RetVT,
const Value *LHS,
const Value *RHS,
1555 bool SetFlags,
bool WantResult,
bool IsZExt) {
1556 return emitAddSub(
true, RetVT, LHS, RHS, SetFlags, WantResult,
1565 unsigned AArch64FastISel::emitAdd_ri_(
MVT VT,
unsigned Op0,
bool Op0IsKill,
1569 ResultReg = emitAddSub_ri(
false, VT, Op0, Op0IsKill, -Imm);
1571 ResultReg = emitAddSub_ri(
true, VT, Op0, Op0IsKill, Imm);
1580 ResultReg = emitAddSub_rr(
true, VT, Op0, Op0IsKill, CReg,
true);
1584 unsigned AArch64FastISel::emitSub(
MVT RetVT,
const Value *LHS,
const Value *RHS,
1585 bool SetFlags,
bool WantResult,
bool IsZExt) {
1586 return emitAddSub(
false, RetVT, LHS, RHS, SetFlags, WantResult,
1590 unsigned AArch64FastISel::emitSubs_rr(
MVT RetVT,
unsigned LHSReg,
1591 bool LHSIsKill,
unsigned RHSReg,
1592 bool RHSIsKill,
bool WantResult) {
1593 return emitAddSub_rr(
false, RetVT, LHSReg, LHSIsKill, RHSReg,
1594 RHSIsKill,
true, WantResult);
1597 unsigned AArch64FastISel::emitSubs_rs(
MVT RetVT,
unsigned LHSReg,
1598 bool LHSIsKill,
unsigned RHSReg,
1601 uint64_t ShiftImm,
bool WantResult) {
1602 return emitAddSub_rs(
false, RetVT, LHSReg, LHSIsKill, RHSReg,
1603 RHSIsKill, ShiftType, ShiftImm,
true,
1607 unsigned AArch64FastISel::emitLogicalOp(
unsigned ISDOpc,
MVT RetVT,
1610 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS))
1614 if (LHS->
hasOneUse() && isValueAvailable(LHS))
1619 if (LHS->
hasOneUse() && isValueAvailable(LHS))
1620 if (
const auto *
SI = dyn_cast<ShlOperator>(LHS))
1621 if (isa<ConstantInt>(
SI->getOperand(1)))
1624 unsigned LHSReg = getRegForValue(LHS);
1627 bool LHSIsKill = hasTrivialKill(LHS);
1629 unsigned ResultReg = 0;
1630 if (
const auto *C = dyn_cast<ConstantInt>(RHS)) {
1631 uint64_t Imm = C->getZExtValue();
1632 ResultReg = emitLogicalOp_ri(ISDOpc, RetVT, LHSReg, LHSIsKill, Imm);
1638 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1640 const Value *MulLHS = cast<MulOperator>(RHS)->getOperand(0);
1641 const Value *MulRHS = cast<MulOperator>(RHS)->getOperand(1);
1643 if (
const auto *C = dyn_cast<ConstantInt>(MulLHS))
1644 if (C->getValue().isPowerOf2())
1647 assert(isa<ConstantInt>(MulRHS) &&
"Expected a ConstantInt.");
1648 uint64_t ShiftVal = cast<ConstantInt>(MulRHS)->getValue().logBase2();
1650 unsigned RHSReg = getRegForValue(MulLHS);
1653 bool RHSIsKill = hasTrivialKill(MulLHS);
1654 ResultReg = emitLogicalOp_rs(ISDOpc, RetVT, LHSReg, LHSIsKill, RHSReg,
1655 RHSIsKill, ShiftVal);
1662 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1663 if (
const auto *
SI = dyn_cast<ShlOperator>(RHS))
1664 if (
const auto *C = dyn_cast<ConstantInt>(
SI->getOperand(1))) {
1665 uint64_t ShiftVal = C->getZExtValue();
1666 unsigned RHSReg = getRegForValue(
SI->getOperand(0));
1669 bool RHSIsKill = hasTrivialKill(
SI->getOperand(0));
1670 ResultReg = emitLogicalOp_rs(ISDOpc, RetVT, LHSReg, LHSIsKill, RHSReg,
1671 RHSIsKill, ShiftVal);
1677 unsigned RHSReg = getRegForValue(RHS);
1680 bool RHSIsKill = hasTrivialKill(RHS);
1683 ResultReg = fastEmit_rr(VT, VT, ISDOpc, LHSReg, LHSIsKill, RHSReg, RHSIsKill);
1685 uint64_t
Mask = (RetVT ==
MVT::i8) ? 0xff : 0xffff;
1686 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
1691 unsigned AArch64FastISel::emitLogicalOp_ri(
unsigned ISDOpc,
MVT RetVT,
1692 unsigned LHSReg,
bool LHSIsKill,
1695 "ISD nodes are not consecutive!");
1696 static const unsigned OpcTable[3][2] = {
1697 { AArch64::ANDWri, AArch64::ANDXri },
1698 { AArch64::ORRWri, AArch64::ORRXri },
1699 { AArch64::EORWri, AArch64::EORXri }
1712 Opc = OpcTable[Idx][0];
1713 RC = &AArch64::GPR32spRegClass;
1718 Opc = OpcTable[ISDOpc -
ISD::AND][1];
1719 RC = &AArch64::GPR64spRegClass;
1727 unsigned ResultReg =
1728 fastEmitInst_ri(Opc, RC, LHSReg, LHSIsKill,
1731 uint64_t
Mask = (RetVT ==
MVT::i8) ? 0xff : 0xffff;
1732 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
1737 unsigned AArch64FastISel::emitLogicalOp_rs(
unsigned ISDOpc,
MVT RetVT,
1738 unsigned LHSReg,
bool LHSIsKill,
1739 unsigned RHSReg,
bool RHSIsKill,
1740 uint64_t ShiftImm) {
1742 "ISD nodes are not consecutive!");
1743 static const unsigned OpcTable[3][2] = {
1744 { AArch64::ANDWrs, AArch64::ANDXrs },
1745 { AArch64::ORRWrs, AArch64::ORRXrs },
1746 { AArch64::EORWrs, AArch64::EORXrs }
1762 Opc = OpcTable[ISDOpc -
ISD::AND][0];
1763 RC = &AArch64::GPR32RegClass;
1766 Opc = OpcTable[ISDOpc -
ISD::AND][1];
1767 RC = &AArch64::GPR64RegClass;
1770 unsigned ResultReg =
1771 fastEmitInst_rri(Opc, RC, LHSReg, LHSIsKill, RHSReg, RHSIsKill,
1774 uint64_t
Mask = (RetVT ==
MVT::i8) ? 0xff : 0xffff;
1775 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
1780 unsigned AArch64FastISel::emitAnd_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
1782 return emitLogicalOp_ri(
ISD::AND, RetVT, LHSReg, LHSIsKill, Imm);
1785 unsigned AArch64FastISel::emitLoad(
MVT VT,
MVT RetVT,
Address Addr,
1787 if (!TLI.allowsMisalignedMemoryAccesses(VT))
1791 if (!simplifyAddress(Addr, VT))
1800 bool UseScaled =
true;
1801 if ((Addr.getOffset() < 0) || (Addr.getOffset() & (ScaleFactor - 1))) {
1806 static const unsigned GPOpcTable[2][8][4] = {
1808 { { AArch64::LDURSBWi, AArch64::LDURSHWi, AArch64::LDURWi,
1810 { AArch64::LDURSBXi, AArch64::LDURSHXi, AArch64::LDURSWi,
1812 { AArch64::LDRSBWui, AArch64::LDRSHWui, AArch64::LDRWui,
1814 { AArch64::LDRSBXui, AArch64::LDRSHXui, AArch64::LDRSWui,
1816 { AArch64::LDRSBWroX, AArch64::LDRSHWroX, AArch64::LDRWroX,
1818 { AArch64::LDRSBXroX, AArch64::LDRSHXroX, AArch64::LDRSWroX,
1820 { AArch64::LDRSBWroW, AArch64::LDRSHWroW, AArch64::LDRWroW,
1822 { AArch64::LDRSBXroW, AArch64::LDRSHXroW, AArch64::LDRSWroW,
1826 { { AArch64::LDURBBi, AArch64::LDURHHi, AArch64::LDURWi,
1828 { AArch64::LDURBBi, AArch64::LDURHHi, AArch64::LDURWi,
1830 { AArch64::LDRBBui, AArch64::LDRHHui, AArch64::LDRWui,
1832 { AArch64::LDRBBui, AArch64::LDRHHui, AArch64::LDRWui,
1834 { AArch64::LDRBBroX, AArch64::LDRHHroX, AArch64::LDRWroX,
1836 { AArch64::LDRBBroX, AArch64::LDRHHroX, AArch64::LDRWroX,
1838 { AArch64::LDRBBroW, AArch64::LDRHHroW, AArch64::LDRWroW,
1840 { AArch64::LDRBBroW, AArch64::LDRHHroW, AArch64::LDRWroW,
1845 static const unsigned FPOpcTable[4][2] = {
1846 { AArch64::LDURSi, AArch64::LDURDi },
1847 { AArch64::LDRSui, AArch64::LDRDui },
1848 { AArch64::LDRSroX, AArch64::LDRDroX },
1849 { AArch64::LDRSroW, AArch64::LDRDroW }
1854 bool UseRegOffset = Addr.isRegBase() && !Addr.getOffset() && Addr.getReg() &&
1855 Addr.getOffsetReg();
1856 unsigned Idx = UseRegOffset ? 2 : UseScaled ? 1 : 0;
1861 bool IsRet64Bit = RetVT ==
MVT::i64;
1867 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][0];
1868 RC = (IsRet64Bit && !WantZExt) ?
1869 &AArch64::GPR64RegClass: &AArch64::GPR32RegClass;
1872 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][1];
1873 RC = (IsRet64Bit && !WantZExt) ?
1874 &AArch64::GPR64RegClass: &AArch64::GPR32RegClass;
1877 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][2];
1878 RC = (IsRet64Bit && !WantZExt) ?
1879 &AArch64::GPR64RegClass: &AArch64::GPR32RegClass;
1882 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][3];
1883 RC = &AArch64::GPR64RegClass;
1886 Opc = FPOpcTable[Idx][0];
1887 RC = &AArch64::FPR32RegClass;
1890 Opc = FPOpcTable[Idx][1];
1891 RC = &AArch64::FPR64RegClass;
1896 unsigned ResultReg = createResultReg(RC);
1898 TII.get(Opc), ResultReg);
1903 unsigned ANDReg = emitAnd_ri(
MVT::i32, ResultReg,
true, 1);
1904 assert(ANDReg &&
"Unexpected AND instruction emission failure.");
1911 unsigned Reg64 = createResultReg(&AArch64::GPR64RegClass);
1912 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1913 TII.get(AArch64::SUBREG_TO_REG), Reg64)
1916 .
addImm(AArch64::sub_32);
1922 bool AArch64FastISel::selectAddSub(
const Instruction *
I) {
1924 if (!isTypeSupported(I->
getType(), VT,
true))
1928 return selectOperator(I, I->
getOpcode());
1937 case Instruction::Sub:
1944 updateValueMap(I, ResultReg);
1948 bool AArch64FastISel::selectLogicalOp(
const Instruction *I) {
1950 if (!isTypeSupported(I->
getType(), VT,
true))
1954 return selectOperator(I, I->
getOpcode());
1960 case Instruction::And:
1963 case Instruction::Or:
1966 case Instruction::Xor:
1973 updateValueMap(I, ResultReg);
1977 bool AArch64FastISel::selectLoad(
const Instruction *I) {
1982 if (!isTypeSupported(I->
getType(), VT,
true) ||
1983 cast<LoadInst>(I)->isAtomic())
1987 if (TLI.supportSwiftError()) {
1990 if (
const Argument *
Arg = dyn_cast<Argument>(SV)) {
1991 if (
Arg->hasSwiftErrorAttr())
1995 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(SV)) {
1996 if (Alloca->isSwiftError())
2007 bool WantZExt =
true;
2009 const Value *IntExtVal =
nullptr;
2011 if (
const auto *ZE = dyn_cast<ZExtInst>(I->
use_begin()->getUser())) {
2012 if (isTypeSupported(ZE->getType(), RetVT))
2016 }
else if (
const auto *SE = dyn_cast<SExtInst>(I->
use_begin()->getUser())) {
2017 if (isTypeSupported(SE->getType(), RetVT))
2025 unsigned ResultReg =
2026 emitLoad(VT, RetVT, Addr, WantZExt, createMachineMemOperandFor(I));
2046 unsigned Reg = lookUpRegForValue(IntExtVal);
2047 auto *
MI =
MRI.getUniqueVRegDef(Reg);
2053 ResultReg = std::prev(I)->getOperand(0).getReg();
2054 removeDeadCode(I, std::next(I));
2056 ResultReg = fastEmitInst_extractsubreg(
MVT::i32, ResultReg,
2060 updateValueMap(I, ResultReg);
2069 for (
auto &Opnd :
MI->uses()) {
2071 Reg = Opnd.getReg();
2076 removeDeadCode(I, std::next(I));
2079 MI =
MRI.getUniqueVRegDef(Reg);
2081 updateValueMap(IntExtVal, ResultReg);
2085 updateValueMap(I, ResultReg);
2089 bool AArch64FastISel::emitStoreRelease(
MVT VT,
unsigned SrcReg,
2094 default:
return false;
2095 case MVT::i8: Opc = AArch64::STLRB;
break;
2096 case MVT::i16: Opc = AArch64::STLRH;
break;
2097 case MVT::i32: Opc = AArch64::STLRW;
break;
2098 case MVT::i64: Opc = AArch64::STLRX;
break;
2104 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
2111 bool AArch64FastISel::emitStore(
MVT VT,
unsigned SrcReg,
Address Addr,
2113 if (!TLI.allowsMisalignedMemoryAccesses(VT))
2117 if (!simplifyAddress(Addr, VT))
2126 bool UseScaled =
true;
2127 if ((Addr.getOffset() < 0) || (Addr.getOffset() & (ScaleFactor - 1))) {
2132 static const unsigned OpcTable[4][6] = {
2133 { AArch64::STURBBi, AArch64::STURHHi, AArch64::STURWi, AArch64::STURXi,
2134 AArch64::STURSi, AArch64::STURDi },
2135 { AArch64::STRBBui, AArch64::STRHHui, AArch64::STRWui, AArch64::STRXui,
2136 AArch64::STRSui, AArch64::STRDui },
2137 { AArch64::STRBBroX, AArch64::STRHHroX, AArch64::STRWroX, AArch64::STRXroX,
2138 AArch64::STRSroX, AArch64::STRDroX },
2139 { AArch64::STRBBroW, AArch64::STRHHroW, AArch64::STRWroW, AArch64::STRXroW,
2140 AArch64::STRSroW, AArch64::STRDroW }
2144 bool VTIsi1 =
false;
2145 bool UseRegOffset = Addr.isRegBase() && !Addr.getOffset() && Addr.getReg() &&
2146 Addr.getOffsetReg();
2147 unsigned Idx = UseRegOffset ? 2 : UseScaled ? 1 : 0;
2155 case MVT::i8: Opc = OpcTable[Idx][0];
break;
2156 case MVT::i16: Opc = OpcTable[Idx][1];
break;
2157 case MVT::i32: Opc = OpcTable[Idx][2];
break;
2158 case MVT::i64: Opc = OpcTable[Idx][3];
break;
2159 case MVT::f32: Opc = OpcTable[Idx][4];
break;
2160 case MVT::f64: Opc = OpcTable[Idx][5];
break;
2164 if (VTIsi1 && SrcReg != AArch64::WZR) {
2165 unsigned ANDReg = emitAnd_ri(
MVT::i32, SrcReg,
false, 1);
2166 assert(ANDReg &&
"Unexpected AND instruction emission failure.");
2173 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II).
addReg(SrcReg);
2179 bool AArch64FastISel::selectStore(
const Instruction *I) {
2185 if (!isTypeSupported(Op0->
getType(), VT,
true))
2189 if (TLI.supportSwiftError()) {
2192 if (
const Argument *
Arg = dyn_cast<Argument>(PtrV)) {
2193 if (
Arg->hasSwiftErrorAttr())
2197 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(PtrV)) {
2198 if (Alloca->isSwiftError())
2205 unsigned SrcReg = 0;
2206 if (
const auto *CI = dyn_cast<ConstantInt>(Op0)) {
2208 SrcReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
2209 }
else if (
const auto *CF = dyn_cast<ConstantFP>(Op0)) {
2210 if (CF->isZero() && !CF->isNegative()) {
2212 SrcReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
2217 SrcReg = getRegForValue(Op0);
2222 auto *
SI = cast<StoreInst>(
I);
2225 if (
SI->isAtomic()) {
2230 unsigned AddrReg = getRegForValue(PtrV);
2231 return emitStoreRelease(VT, SrcReg, AddrReg,
2232 createMachineMemOperandFor(I));
2238 if (!computeAddress(PtrV, Addr, Op0->
getType()))
2241 if (!emitStore(VT, SrcReg, Addr, createMachineMemOperandFor(I)))
2293 bool AArch64FastISel::emitCompareAndBranch(
const BranchInst *BI) {
2297 if (FuncInfo.MF->getFunction().hasFnAttribute(
2298 Attribute::SpeculativeLoadHardening))
2309 if (!isTypeSupported(LHS->
getType(), VT))
2320 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
2327 switch (Predicate) {
2332 if (isa<Constant>(LHS) && cast<Constant>(LHS)->isNullValue())
2335 if (!isa<Constant>(RHS) || !cast<Constant>(RHS)->isNullValue())
2338 if (
const auto *AI = dyn_cast<BinaryOperator>(LHS))
2339 if (AI->
getOpcode() == Instruction::And && isValueAvailable(AI)) {
2343 if (
const auto *C = dyn_cast<ConstantInt>(AndLHS))
2344 if (C->getValue().isPowerOf2())
2347 if (
const auto *C = dyn_cast<ConstantInt>(AndRHS))
2348 if (C->getValue().isPowerOf2()) {
2349 TestBit = C->getValue().logBase2();
2361 if (!isa<Constant>(RHS) || !cast<Constant>(RHS)->isNullValue())
2369 if (!isa<ConstantInt>(RHS))
2372 if (cast<ConstantInt>(RHS)->getValue() !=
APInt(BW, -1,
true))
2380 static const unsigned OpcTable[2][2][2] = {
2381 { {AArch64::CBZW, AArch64::CBZX },
2382 {AArch64::CBNZW, AArch64::CBNZX} },
2383 { {AArch64::TBZW, AArch64::TBZX },
2384 {AArch64::TBNZW, AArch64::TBNZX} }
2387 bool IsBitTest = TestBit != -1;
2388 bool Is64Bit = BW == 64;
2389 if (TestBit < 32 && TestBit >= 0)
2392 unsigned Opc = OpcTable[IsBitTest][IsCmpNE][Is64Bit];
2395 unsigned SrcReg = getRegForValue(LHS);
2398 bool SrcIsKill = hasTrivialKill(LHS);
2400 if (BW == 64 && !Is64Bit)
2401 SrcReg = fastEmitInst_extractsubreg(
MVT::i32, SrcReg, SrcIsKill,
2404 if ((BW < 32) && !IsBitTest)
2405 SrcReg = emitIntExt(VT, SrcReg,
MVT::i32,
true);
2410 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
2416 finishCondBranch(BI->
getParent(), TBB, FBB);
2420 bool AArch64FastISel::selectBranch(
const Instruction *I) {
2432 if (CI->
hasOneUse() && isValueAvailable(CI)) {
2435 switch (Predicate) {
2439 fastEmitBranch(FBB, DbgLoc);
2442 fastEmitBranch(TBB, DbgLoc);
2447 if (emitCompareAndBranch(BI))
2451 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
2464 switch (Predicate) {
2480 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::Bcc))
2486 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::Bcc))
2490 finishCondBranch(BI->
getParent(), TBB, FBB);
2493 }
else if (
const auto *CI = dyn_cast<ConstantInt>(BI->
getCondition())) {
2505 FuncInfo.MBB->addSuccessorWithoutProb(Target);
2517 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::Bcc))
2521 finishCondBranch(BI->
getParent(), TBB, FBB);
2529 bool CondRegIsKill = hasTrivialKill(BI->
getCondition());
2532 unsigned Opcode = AArch64::TBNZW;
2533 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
2535 Opcode = AArch64::TBZW;
2539 unsigned ConstrainedCondReg
2541 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
2546 finishCondBranch(BI->
getParent(), TBB, FBB);
2550 bool AArch64FastISel::selectIndirectBr(
const Instruction *I) {
2552 unsigned AddrReg = getRegForValue(BI->
getOperand(0));
2559 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II).
addReg(AddrReg);
2563 FuncInfo.MBB->addSuccessor(FuncInfo.MBBMap[Succ]);
2568 bool AArch64FastISel::selectCmp(
const Instruction *I) {
2569 const CmpInst *CI = cast<CmpInst>(
I);
2577 unsigned ResultReg = 0;
2578 switch (Predicate) {
2582 ResultReg = createResultReg(&AArch64::GPR32RegClass);
2583 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2584 TII.get(TargetOpcode::COPY), ResultReg)
2593 updateValueMap(I, ResultReg);
2601 ResultReg = createResultReg(&AArch64::GPR32RegClass);
2605 static unsigned CondCodeTable[2][2] = {
2610 switch (Predicate) {
2614 CondCodes = &CondCodeTable[0][0];
2617 CondCodes = &CondCodeTable[1][0];
2622 unsigned TmpReg1 = createResultReg(&AArch64::GPR32RegClass);
2623 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr),
2627 .addImm(CondCodes[0]);
2628 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr),
2632 .addImm(CondCodes[1]);
2634 updateValueMap(I, ResultReg);
2642 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr),
2646 .addImm(invertedCC);
2648 updateValueMap(I, ResultReg);
2654 bool AArch64FastISel::optimizeSelect(
const SelectInst *
SI) {
2658 const Value *Src1Val, *Src2Val;
2660 bool NeedExtraOp =
false;
2661 if (
auto *CI = dyn_cast<ConstantInt>(SI->
getTrueValue())) {
2665 Opc = AArch64::ORRWrr;
2670 Opc = AArch64::BICWrr;
2672 }
else if (
auto *CI = dyn_cast<ConstantInt>(SI->
getFalseValue())) {
2676 Opc = AArch64::ORRWrr;
2682 Opc = AArch64::ANDWrr;
2689 unsigned Src1Reg = getRegForValue(Src1Val);
2692 bool Src1IsKill = hasTrivialKill(Src1Val);
2694 unsigned Src2Reg = getRegForValue(Src2Val);
2697 bool Src2IsKill = hasTrivialKill(Src2Val);
2703 unsigned ResultReg = fastEmitInst_rr(Opc, &AArch64::GPR32RegClass, Src1Reg,
2704 Src1IsKill, Src2Reg, Src2IsKill);
2705 updateValueMap(SI, ResultReg);
2709 bool AArch64FastISel::selectSelect(
const Instruction *I) {
2710 assert(isa<SelectInst>(I) &&
"Expected a select instruction.");
2712 if (!isTypeSupported(I->
getType(), VT))
2724 Opc = AArch64::CSELWr;
2725 RC = &AArch64::GPR32RegClass;
2728 Opc = AArch64::CSELXr;
2729 RC = &AArch64::GPR64RegClass;
2732 Opc = AArch64::FCSELSrrr;
2733 RC = &AArch64::FPR32RegClass;
2736 Opc = AArch64::FCSELDrrr;
2737 RC = &AArch64::FPR64RegClass;
2746 if (optimizeSelect(SI))
2750 if (foldXALUIntrinsic(CC, I, Cond)) {
2752 unsigned CondReg = getRegForValue(Cond);
2755 }
else if (isa<CmpInst>(Cond) && cast<CmpInst>(Cond)->
hasOneUse() &&
2756 isValueAvailable(Cond)) {
2757 const auto *Cmp = cast<CmpInst>(Cond);
2760 const Value *FoldSelect =
nullptr;
2761 switch (Predicate) {
2773 unsigned SrcReg = getRegForValue(FoldSelect);
2776 unsigned UseReg = lookUpRegForValue(SI);
2778 MRI.clearKillFlags(UseReg);
2780 updateValueMap(I, SrcReg);
2785 if (!
emitCmp(Cmp->getOperand(0), Cmp->getOperand(1), Cmp->isUnsigned()))
2790 switch (Predicate) {
2804 unsigned CondReg = getRegForValue(Cond);
2807 bool CondIsKill = hasTrivialKill(Cond);
2813 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II,
2825 if (!Src1Reg || !Src2Reg)
2829 Src2Reg = fastEmitInst_rri(Opc, RC, Src1Reg, Src1IsKill, Src2Reg,
2830 Src2IsKill, ExtraCC);
2833 unsigned ResultReg = fastEmitInst_rri(Opc, RC, Src1Reg, Src1IsKill, Src2Reg,
2835 updateValueMap(I, ResultReg);
2839 bool AArch64FastISel::selectFPExt(
const Instruction *I) {
2844 unsigned Op = getRegForValue(V);
2848 unsigned ResultReg = createResultReg(&AArch64::FPR64RegClass);
2849 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::FCVTDSr),
2850 ResultReg).addReg(Op);
2851 updateValueMap(I, ResultReg);
2855 bool AArch64FastISel::selectFPTrunc(
const Instruction *I) {
2860 unsigned Op = getRegForValue(V);
2864 unsigned ResultReg = createResultReg(&AArch64::FPR32RegClass);
2865 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::FCVTSDr),
2866 ResultReg).addReg(Op);
2867 updateValueMap(I, ResultReg);
2877 unsigned SrcReg = getRegForValue(I->
getOperand(0));
2888 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZSUWDr : AArch64::FCVTZSUXDr;
2890 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZUUWDr : AArch64::FCVTZUUXDr;
2893 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZSUWSr : AArch64::FCVTZSUXSr;
2895 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZUUWSr : AArch64::FCVTZUUXSr;
2897 unsigned ResultReg = createResultReg(
2898 DestVT ==
MVT::i32 ? &AArch64::GPR32RegClass : &AArch64::GPR64RegClass);
2899 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
2901 updateValueMap(I, ResultReg);
2905 bool AArch64FastISel::selectIntToFP(
const Instruction *I,
bool Signed) {
2914 "Unexpected value type.");
2916 unsigned SrcReg = getRegForValue(I->
getOperand(0));
2919 bool SrcIsKill = hasTrivialKill(I->
getOperand(0));
2935 Opc = (DestVT ==
MVT::f32) ? AArch64::SCVTFUXSri : AArch64::SCVTFUXDri;
2937 Opc = (DestVT ==
MVT::f32) ? AArch64::UCVTFUXSri : AArch64::UCVTFUXDri;
2940 Opc = (DestVT ==
MVT::f32) ? AArch64::SCVTFUWSri : AArch64::SCVTFUWDri;
2942 Opc = (DestVT ==
MVT::f32) ? AArch64::UCVTFUWSri : AArch64::UCVTFUWDri;
2945 unsigned ResultReg = fastEmitInst_r(Opc, TLI.getRegClassFor(DestVT), SrcReg,
2947 updateValueMap(I, ResultReg);
2951 bool AArch64FastISel::fastLowerArguments() {
2952 if (!FuncInfo.CanLowerReturn)
2967 unsigned GPRCnt = 0;
2968 unsigned FPRCnt = 0;
2969 for (
auto const &
Arg : F->
args()) {
2970 if (
Arg.hasAttribute(Attribute::ByVal) ||
2971 Arg.hasAttribute(Attribute::InReg) ||
2972 Arg.hasAttribute(Attribute::StructRet) ||
2973 Arg.hasAttribute(Attribute::SwiftSelf) ||
2974 Arg.hasAttribute(Attribute::SwiftError) ||
2975 Arg.hasAttribute(Attribute::Nest))
2982 EVT ArgVT = TLI.getValueType(DL, ArgTy);
3002 if (GPRCnt > 8 || FPRCnt > 8)
3007 { AArch64::W0, AArch64::W1, AArch64::W2, AArch64::W3, AArch64::W4,
3008 AArch64::W5, AArch64::W6, AArch64::W7 },
3009 { AArch64::X0, AArch64::X1, AArch64::X2, AArch64::X3, AArch64::X4,
3010 AArch64::X5, AArch64::X6, AArch64::X7 },
3011 { AArch64::H0, AArch64::H1, AArch64::H2, AArch64::H3, AArch64::H4,
3012 AArch64::H5, AArch64::H6, AArch64::H7 },
3013 { AArch64::S0, AArch64::S1, AArch64::S2, AArch64::S3, AArch64::S4,
3014 AArch64::S5, AArch64::S6, AArch64::S7 },
3015 { AArch64::D0, AArch64::D1, AArch64::D2, AArch64::D3, AArch64::D4,
3016 AArch64::D5, AArch64::D6, AArch64::D7 },
3017 { AArch64::Q0, AArch64::Q1, AArch64::Q2, AArch64::Q3, AArch64::Q4,
3018 AArch64::Q5, AArch64::Q6, AArch64::Q7 }
3022 unsigned FPRIdx = 0;
3023 for (
auto const &
Arg : F->
args()) {
3024 MVT VT = TLI.getSimpleValueType(DL,
Arg.getType());
3028 SrcReg = Registers[0][GPRIdx++];
3029 RC = &AArch64::GPR32RegClass;
3032 SrcReg = Registers[1][GPRIdx++];
3033 RC = &AArch64::GPR64RegClass;
3035 SrcReg = Registers[2][FPRIdx++];
3036 RC = &AArch64::FPR16RegClass;
3038 SrcReg = Registers[3][FPRIdx++];
3039 RC = &AArch64::FPR32RegClass;
3041 SrcReg = Registers[4][FPRIdx++];
3042 RC = &AArch64::FPR64RegClass;
3044 SrcReg = Registers[5][FPRIdx++];
3045 RC = &AArch64::FPR128RegClass;
3049 unsigned DstReg = FuncInfo.MF->addLiveIn(SrcReg, RC);
3053 unsigned ResultReg = createResultReg(RC);
3054 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3055 TII.get(TargetOpcode::COPY), ResultReg)
3057 updateValueMap(&
Arg, ResultReg);
3062 bool AArch64FastISel::processCallArgs(CallLoweringInfo &CLI,
3064 unsigned &NumBytes) {
3067 CCState CCInfo(CC,
false, *FuncInfo.MF, ArgLocs, *Context);
3074 unsigned AdjStackDown =
TII.getCallFrameSetupOpcode();
3075 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AdjStackDown))
3076 .addImm(NumBytes).
addImm(0);
3080 const Value *ArgVal = CLI.OutVals[VA.getValNo()];
3081 MVT ArgVT = OutVTs[VA.getValNo()];
3083 unsigned ArgReg = getRegForValue(ArgVal);
3088 switch (VA.getLocInfo()) {
3092 MVT DestVT = VA.getLocVT();
3094 ArgReg = emitIntExt(SrcVT, ArgReg, DestVT,
false);
3102 MVT DestVT = VA.getLocVT();
3104 ArgReg = emitIntExt(SrcVT, ArgReg, DestVT,
true);
3114 if (VA.isRegLoc() && !VA.needsCustom()) {
3115 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3116 TII.get(TargetOpcode::COPY), VA.getLocReg()).addReg(ArgReg);
3117 CLI.OutRegs.push_back(VA.getLocReg());
3118 }
else if (VA.needsCustom()) {
3122 assert(VA.isMemLoc() &&
"Assuming store on stack.");
3125 if (isa<UndefValue>(ArgVal))
3131 unsigned BEAlign = 0;
3132 if (ArgSize < 8 && !Subtarget->isLittleEndian())
3133 BEAlign = 8 - ArgSize;
3136 Addr.setKind(Address::RegBase);
3137 Addr.setReg(AArch64::SP);
3138 Addr.setOffset(VA.getLocMemOffset() + BEAlign);
3140 unsigned Alignment = DL.getABITypeAlignment(ArgVal->
getType());
3145 if (!emitStore(ArgVT, ArgReg, Addr, MMO))
3152 bool AArch64FastISel::finishCall(CallLoweringInfo &CLI,
MVT RetVT,
3153 unsigned NumBytes) {
3157 unsigned AdjStackUp =
TII.getCallFrameDestroyOpcode();
3158 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AdjStackUp))
3159 .addImm(NumBytes).
addImm(0);
3164 CCState CCInfo(CC,
false, *FuncInfo.MF, RVLocs, *Context);
3168 if (RVLocs.
size() != 1)
3172 MVT CopyVT = RVLocs[0].getValVT();
3178 unsigned ResultReg = createResultReg(TLI.getRegClassFor(CopyVT));
3179 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3180 TII.get(TargetOpcode::COPY), ResultReg)
3181 .addReg(RVLocs[0].getLocReg());
3182 CLI.InRegs.push_back(RVLocs[0].getLocReg());
3184 CLI.ResultReg = ResultReg;
3185 CLI.NumResultRegs = 1;
3191 bool AArch64FastISel::fastLowerCall(CallLoweringInfo &CLI) {
3193 bool IsTailCall = CLI.IsTailCall;
3194 bool IsVarArg = CLI.IsVarArg;
3198 if (!Callee && !Symbol)
3225 if (CLI.RetTy->isVoidTy())
3227 else if (!isTypeLegal(CLI.RetTy, RetVT))
3230 for (
auto Flag : CLI.OutFlags)
3232 Flag.isSwiftSelf() ||
Flag.isSwiftError())
3237 OutVTs.
reserve(CLI.OutVals.size());
3239 for (
auto *Val : CLI.OutVals) {
3241 if (!isTypeLegal(Val->getType(), VT) &&
3253 if (Callee && !computeCallAddress(Callee, Addr))
3260 Addr.getGlobalValue()->hasExternalWeakLinkage())
3265 if (!processCallArgs(CLI, OutVTs, NumBytes))
3276 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II);
3279 else if (Addr.getGlobalValue())
3281 else if (Addr.getReg()) {
3287 unsigned CallReg = 0;
3289 unsigned ADRPReg = createResultReg(&AArch64::GPR64commonRegClass);
3294 CallReg = createResultReg(&AArch64::GPR64RegClass);
3295 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3296 TII.get(AArch64::LDRXui), CallReg)
3300 }
else if (Addr.getGlobalValue())
3301 CallReg = materializeGV(Addr.getGlobalValue());
3302 else if (Addr.getReg())
3303 CallReg = Addr.getReg();
3310 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II).
addReg(CallReg);
3314 for (
auto Reg : CLI.OutRegs)
3324 return finishCall(CLI, RetVT, NumBytes);
3327 bool AArch64FastISel::isMemCpySmall(uint64_t Len,
unsigned Alignment) {
3329 return Len / Alignment <= 4;
3334 bool AArch64FastISel::tryEmitSmallMemCpy(
Address Dest,
Address Src,
3335 uint64_t Len,
unsigned Alignment) {
3337 if (!isMemCpySmall(Len, Alignment))
3340 int64_t UnscaledOffset = 0;
3346 if (!Alignment || Alignment >= 8) {
3358 if (Len >= 4 && Alignment == 4)
3360 else if (Len >= 2 && Alignment == 2)
3367 unsigned ResultReg = emitLoad(VT, VT, Src);
3371 if (!emitStore(VT, ResultReg, Dest))
3376 UnscaledOffset +=
Size;
3379 Dest.setOffset(OrigDest.getOffset() + UnscaledOffset);
3380 Src.setOffset(OrigSrc.getOffset() + UnscaledOffset);
3390 const Value *Cond) {
3391 if (!isa<ExtractValueInst>(Cond))
3394 const auto *EV = cast<ExtractValueInst>(Cond);
3395 if (!isa<IntrinsicInst>(EV->getAggregateOperand()))
3398 const auto *II = cast<IntrinsicInst>(EV->getAggregateOperand());
3402 cast<StructType>(Callee->
getReturnType())->getTypeAtIndex(0U);
3403 if (!isTypeLegal(RetTy, RetVT))
3409 const Value *LHS = II->getArgOperand(0);
3410 const Value *RHS = II->getArgOperand(1);
3413 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS) &&
3414 isCommutativeIntrinsic(II))
3422 case Intrinsic::smul_with_overflow:
3423 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3424 if (C->getValue() == 2)
3425 IID = Intrinsic::sadd_with_overflow;
3427 case Intrinsic::umul_with_overflow:
3428 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3429 if (C->getValue() == 2)
3430 IID = Intrinsic::uadd_with_overflow;
3438 case Intrinsic::sadd_with_overflow:
3439 case Intrinsic::ssub_with_overflow:
3442 case Intrinsic::uadd_with_overflow:
3445 case Intrinsic::usub_with_overflow:
3448 case Intrinsic::smul_with_overflow:
3449 case Intrinsic::umul_with_overflow:
3455 if (!isValueAvailable(II))
3461 for (
auto Itr = std::prev(Start); Itr != End; --Itr) {
3464 if (!isa<ExtractValueInst>(Itr))
3468 const auto *EVI = cast<ExtractValueInst>(Itr);
3469 if (EVI->getAggregateOperand() != II)
3477 bool AArch64FastISel::fastLowerIntrinsicCall(
const IntrinsicInst *II) {
3480 default:
return false;
3481 case Intrinsic::frameaddress: {
3487 Register SrcReg =
MRI.createVirtualRegister(&AArch64::GPR64RegClass);
3488 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3489 TII.get(TargetOpcode::COPY), SrcReg).addReg(FramePtr);
3496 unsigned Depth = cast<ConstantInt>(II->
getOperand(0))->getZExtValue();
3498 DestReg = fastEmitInst_ri(AArch64::LDRXui, &AArch64::GPR64RegClass,
3500 assert(DestReg &&
"Unexpected LDR instruction emission failure.");
3504 updateValueMap(II, SrcReg);
3507 case Intrinsic::sponentry: {
3512 unsigned ResultReg = createResultReg(&AArch64::GPR64spRegClass);
3513 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3514 TII.get(AArch64::ADDXri), ResultReg)
3519 updateValueMap(II, ResultReg);
3522 case Intrinsic::memcpy:
3523 case Intrinsic::memmove: {
3524 const auto *MTI = cast<MemTransferInst>(II);
3526 if (MTI->isVolatile())
3532 if (isa<ConstantInt>(MTI->getLength()) && IsMemCpy) {
3535 uint64_t Len = cast<ConstantInt>(MTI->getLength())->getZExtValue();
3536 unsigned Alignment =
MinAlign(MTI->getDestAlignment(),
3537 MTI->getSourceAlignment());
3538 if (isMemCpySmall(Len, Alignment)) {
3540 if (!computeAddress(MTI->getRawDest(), Dest) ||
3541 !computeAddress(MTI->getRawSource(), Src))
3543 if (tryEmitSmallMemCpy(Dest, Src, Len, Alignment))
3548 if (!MTI->getLength()->getType()->isIntegerTy(64))
3551 if (MTI->getSourceAddressSpace() > 255 || MTI->getDestAddressSpace() > 255)
3556 const char *IntrMemName = isa<MemCpyInst>(II) ?
"memcpy" :
"memmove";
3559 case Intrinsic::memset: {
3560 const MemSetInst *MSI = cast<MemSetInst>(II);
3575 case Intrinsic::sin:
3576 case Intrinsic::cos:
3577 case Intrinsic::pow: {
3579 if (!isTypeLegal(II->
getType(), RetVT))
3586 { RTLIB::SIN_F32, RTLIB::SIN_F64 },
3587 { RTLIB::COS_F32, RTLIB::COS_F64 },
3588 { RTLIB::POW_F32, RTLIB::POW_F64 }
3595 case Intrinsic::sin:
3596 LC = LibCallTable[0][Is64Bit];
3598 case Intrinsic::cos:
3599 LC = LibCallTable[1][Is64Bit];
3601 case Intrinsic::pow:
3602 LC = LibCallTable[2][Is64Bit];
3613 Entry.Ty =
Arg->getType();
3614 Args.push_back(Entry);
3617 CallLoweringInfo CLI;
3619 CLI.setCallee(DL, Ctx, TLI.getLibcallCallingConv(LC), II->
getType(),
3620 TLI.getLibcallName(LC), std::move(Args));
3621 if (!lowerCallTo(CLI))
3623 updateValueMap(II, CLI.ResultReg);
3626 case Intrinsic::fabs: {
3628 if (!isTypeLegal(II->
getType(), VT))
3636 Opc = AArch64::FABSSr;
3639 Opc = AArch64::FABSDr;
3642 unsigned SrcReg = getRegForValue(II->
getOperand(0));
3645 bool SrcRegIsKill = hasTrivialKill(II->
getOperand(0));
3646 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
3647 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
3649 updateValueMap(II, ResultReg);
3652 case Intrinsic::trap:
3653 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::BRK))
3656 case Intrinsic::debugtrap: {
3658 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::BRK))
3665 case Intrinsic::sqrt: {
3669 if (!isTypeLegal(RetTy, VT))
3672 unsigned Op0Reg = getRegForValue(II->
getOperand(0));
3675 bool Op0IsKill = hasTrivialKill(II->
getOperand(0));
3677 unsigned ResultReg = fastEmit_r(VT, VT,
ISD::FSQRT, Op0Reg, Op0IsKill);
3681 updateValueMap(II, ResultReg);
3684 case Intrinsic::sadd_with_overflow:
3685 case Intrinsic::uadd_with_overflow:
3686 case Intrinsic::ssub_with_overflow:
3687 case Intrinsic::usub_with_overflow:
3688 case Intrinsic::smul_with_overflow:
3689 case Intrinsic::umul_with_overflow: {
3693 Type *RetTy = Ty->getTypeAtIndex(0U);
3696 if (!isTypeLegal(RetTy, VT))
3705 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS) &&
3706 isCommutativeIntrinsic(II))
3714 case Intrinsic::smul_with_overflow:
3715 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3716 if (C->getValue() == 2) {
3717 IID = Intrinsic::sadd_with_overflow;
3721 case Intrinsic::umul_with_overflow:
3722 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3723 if (C->getValue() == 2) {
3724 IID = Intrinsic::uadd_with_overflow;
3730 unsigned ResultReg1 = 0, ResultReg2 = 0, MulReg = 0;
3734 case Intrinsic::sadd_with_overflow:
3735 ResultReg1 = emitAdd(VT, LHS, RHS,
true);
3738 case Intrinsic::uadd_with_overflow:
3739 ResultReg1 = emitAdd(VT, LHS, RHS,
true);
3742 case Intrinsic::ssub_with_overflow:
3743 ResultReg1 = emitSub(VT, LHS, RHS,
true);
3746 case Intrinsic::usub_with_overflow:
3747 ResultReg1 = emitSub(VT, LHS, RHS,
true);
3750 case Intrinsic::smul_with_overflow: {
3752 unsigned LHSReg = getRegForValue(LHS);
3755 bool LHSIsKill = hasTrivialKill(LHS);
3757 unsigned RHSReg = getRegForValue(RHS);
3760 bool RHSIsKill = hasTrivialKill(RHS);
3763 MulReg = emitSMULL_rr(
MVT::i64, LHSReg, LHSIsKill, RHSReg, RHSIsKill);
3766 MulReg = fastEmitInst_extractsubreg(VT, MulReg,
true,
3768 ShiftReg = fastEmitInst_extractsubreg(VT, ShiftReg,
true,
3770 emitSubs_rs(VT, ShiftReg,
true, MulReg,
false,
3776 MulReg = emitMul_rr(VT, LHSReg,
false, RHSReg,
3778 unsigned SMULHReg = fastEmit_rr(VT, VT,
ISD::MULHS, LHSReg, LHSIsKill,
3780 emitSubs_rs(VT, SMULHReg,
true, MulReg,
false,
3785 case Intrinsic::umul_with_overflow: {
3787 unsigned LHSReg = getRegForValue(LHS);
3790 bool LHSIsKill = hasTrivialKill(LHS);
3792 unsigned RHSReg = getRegForValue(RHS);
3795 bool RHSIsKill = hasTrivialKill(RHS);
3798 MulReg = emitUMULL_rr(
MVT::i64, LHSReg, LHSIsKill, RHSReg, RHSIsKill);
3799 emitSubs_rs(
MVT::i64, AArch64::XZR,
true, MulReg,
3802 MulReg = fastEmitInst_extractsubreg(VT, MulReg,
true,
3808 MulReg = emitMul_rr(VT, LHSReg,
false, RHSReg,
3810 unsigned UMULHReg = fastEmit_rr(VT, VT,
ISD::MULHU, LHSReg, LHSIsKill,
3812 emitSubs_rr(VT, AArch64::XZR,
true, UMULHReg,
3820 ResultReg1 = createResultReg(TLI.getRegClassFor(VT));
3821 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3822 TII.get(TargetOpcode::COPY), ResultReg1).addReg(MulReg);
3828 ResultReg2 = fastEmitInst_rri(AArch64::CSINCWr, &AArch64::GPR32RegClass,
3829 AArch64::WZR,
true, AArch64::WZR,
3832 assert((ResultReg1 + 1) == ResultReg2 &&
3833 "Nonconsecutive result registers.");
3834 updateValueMap(II, ResultReg1, 2);
3841 bool AArch64FastISel::selectRet(
const Instruction *I) {
3845 if (!FuncInfo.CanLowerReturn)
3851 if (TLI.supportSwiftError() &&
3852 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError))
3855 if (TLI.supportSplitCSR(FuncInfo.MF))
3864 GetReturnInfo(CC, F.getReturnType(), F.getAttributes(), Outs, TLI, DL);
3871 CCInfo.AnalyzeReturn(Outs, RetCC);
3874 if (ValLocs.size() != 1)
3889 unsigned Reg = getRegForValue(RV);
3893 unsigned SrcReg = Reg + VA.
getValNo();
3896 if (!
MRI.getRegClass(SrcReg)->contains(DestReg))
3899 EVT RVEVT = TLI.getValueType(DL, RV->
getType());
3914 if (RVVT != DestVT) {
3918 if (!Outs[0].Flags.isZExt() && !Outs[0].Flags.isSExt())
3921 bool IsZExt = Outs[0].Flags.isZExt();
3922 SrcReg = emitIntExt(RVVT, SrcReg, DestVT, IsZExt);
3930 SrcReg = emitAnd_ri(
MVT::i64, SrcReg,
false, 0xffffffff);
3933 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3934 TII.get(TargetOpcode::COPY), DestReg).addReg(SrcReg);
3941 TII.get(AArch64::RET_ReallyLR));
3942 for (
unsigned RetReg : RetRegs)
3947 bool AArch64FastISel::selectTrunc(
const Instruction *I) {
3952 EVT SrcEVT = TLI.getValueType(DL, SrcTy,
true);
3953 EVT DestEVT = TLI.getValueType(DL, DestTy,
true);
3969 unsigned SrcReg = getRegForValue(Op);
3972 bool SrcIsKill = hasTrivialKill(Op);
3997 unsigned Reg32 = fastEmitInst_extractsubreg(
MVT::i32, SrcReg, SrcIsKill,
4000 ResultReg = emitAnd_ri(
MVT::i32, Reg32,
true, Mask);
4001 assert(ResultReg &&
"Unexpected AND instruction emission failure.");
4003 ResultReg = createResultReg(&AArch64::GPR32RegClass);
4004 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4005 TII.get(TargetOpcode::COPY), ResultReg)
4009 updateValueMap(I, ResultReg);
4013 unsigned AArch64FastISel::emiti1Ext(
unsigned SrcReg,
MVT DestVT,
bool IsZExt) {
4016 "Unexpected value type.");
4022 unsigned ResultReg = emitAnd_ri(
MVT::i32, SrcReg,
false, 1);
4023 assert(ResultReg &&
"Unexpected AND instruction emission failure.");
4027 Register Reg64 =
MRI.createVirtualRegister(&AArch64::GPR64RegClass);
4028 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4029 TII.get(AArch64::SUBREG_TO_REG), Reg64)
4032 .
addImm(AArch64::sub_32);
4041 return fastEmitInst_rii(AArch64::SBFMWri, &AArch64::GPR32RegClass, SrcReg,
4046 unsigned AArch64FastISel::emitMul_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
4047 unsigned Op1,
bool Op1IsKill) {
4055 Opc = AArch64::MADDWrrr; ZReg = AArch64::WZR;
break;
4057 Opc = AArch64::MADDXrrr; ZReg = AArch64::XZR;
break;
4061 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4062 return fastEmitInst_rrr(Opc, RC, Op0, Op0IsKill, Op1, Op1IsKill,
4066 unsigned AArch64FastISel::emitSMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
4067 unsigned Op1,
bool Op1IsKill) {
4071 return fastEmitInst_rrr(AArch64::SMADDLrrr, &AArch64::GPR64RegClass,
4072 Op0, Op0IsKill, Op1, Op1IsKill,
4073 AArch64::XZR,
true);
4076 unsigned AArch64FastISel::emitUMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
4077 unsigned Op1,
bool Op1IsKill) {
4081 return fastEmitInst_rrr(AArch64::UMADDLrrr, &AArch64::GPR64RegClass,
4082 Op0, Op0IsKill, Op1, Op1IsKill,
4083 AArch64::XZR,
true);
4086 unsigned AArch64FastISel::emitLSL_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
4087 unsigned Op1Reg,
bool Op1IsKill) {
4089 bool NeedTrunc =
false;
4093 case MVT::i8: Opc = AArch64::LSLVWr; NeedTrunc =
true; Mask = 0xff;
break;
4094 case MVT::i16: Opc = AArch64::LSLVWr; NeedTrunc =
true; Mask = 0xffff;
break;
4095 case MVT::i32: Opc = AArch64::LSLVWr;
break;
4096 case MVT::i64: Opc = AArch64::LSLVXr;
break;
4100 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4102 Op1Reg = emitAnd_ri(
MVT::i32, Op1Reg, Op1IsKill, Mask);
4105 unsigned ResultReg = fastEmitInst_rr(Opc, RC, Op0Reg, Op0IsKill, Op1Reg,
4108 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
4112 unsigned AArch64FastISel::emitLSL_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0,
4113 bool Op0IsKill, uint64_t Shift,
4116 "Unexpected source/return type pair.");
4119 "Unexpected source value type.");
4121 RetVT ==
MVT::i64) &&
"Unexpected return value type.");
4123 bool Is64Bit = (RetVT ==
MVT::i64);
4124 unsigned RegSize = Is64Bit ? 64 : 32;
4128 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4132 if (RetVT == SrcVT) {
4133 unsigned ResultReg = createResultReg(RC);
4134 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4135 TII.get(TargetOpcode::COPY), ResultReg)
4139 return emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4143 if (Shift >= DstBits)
4171 unsigned ImmR = RegSize - Shift;
4173 unsigned ImmS = std::min<unsigned>(SrcBits - 1, DstBits - 1 - Shift);
4174 static const unsigned OpcTable[2][2] = {
4175 {AArch64::SBFMWri, AArch64::SBFMXri},
4176 {AArch64::UBFMWri, AArch64::UBFMXri}
4178 unsigned Opc = OpcTable[IsZExt][Is64Bit];
4181 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4182 TII.get(AArch64::SUBREG_TO_REG), TmpReg)
4185 .
addImm(AArch64::sub_32);
4189 return fastEmitInst_rii(Opc, RC, Op0, Op0IsKill, ImmR, ImmS);
4192 unsigned AArch64FastISel::emitLSR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
4193 unsigned Op1Reg,
bool Op1IsKill) {
4195 bool NeedTrunc =
false;
4199 case MVT::i8: Opc = AArch64::LSRVWr; NeedTrunc =
true; Mask = 0xff;
break;
4200 case MVT::i16: Opc = AArch64::LSRVWr; NeedTrunc =
true; Mask = 0xffff;
break;
4201 case MVT::i32: Opc = AArch64::LSRVWr;
break;
4202 case MVT::i64: Opc = AArch64::LSRVXr;
break;
4206 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4208 Op0Reg = emitAnd_ri(
MVT::i32, Op0Reg, Op0IsKill, Mask);
4209 Op1Reg = emitAnd_ri(
MVT::i32, Op1Reg, Op1IsKill, Mask);
4210 Op0IsKill = Op1IsKill =
true;
4212 unsigned ResultReg = fastEmitInst_rr(Opc, RC, Op0Reg, Op0IsKill, Op1Reg,
4215 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
4219 unsigned AArch64FastISel::emitLSR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0,
4220 bool Op0IsKill, uint64_t Shift,
4223 "Unexpected source/return type pair.");
4226 "Unexpected source value type.");
4228 RetVT ==
MVT::i64) &&
"Unexpected return value type.");
4230 bool Is64Bit = (RetVT ==
MVT::i64);
4231 unsigned RegSize = Is64Bit ? 64 : 32;
4235 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4239 if (RetVT == SrcVT) {
4240 unsigned ResultReg = createResultReg(RC);
4241 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4242 TII.get(TargetOpcode::COPY), ResultReg)
4246 return emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4250 if (Shift >= DstBits)
4278 if (Shift >= SrcBits && IsZExt)
4284 Op0 = emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4293 unsigned ImmR = std::min<unsigned>(SrcBits - 1, Shift);
4294 unsigned ImmS = SrcBits - 1;
4295 static const unsigned OpcTable[2][2] = {
4296 {AArch64::SBFMWri, AArch64::SBFMXri},
4297 {AArch64::UBFMWri, AArch64::UBFMXri}
4299 unsigned Opc = OpcTable[IsZExt][Is64Bit];
4302 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4303 TII.get(AArch64::SUBREG_TO_REG), TmpReg)
4306 .
addImm(AArch64::sub_32);
4310 return fastEmitInst_rii(Opc, RC, Op0, Op0IsKill, ImmR, ImmS);
4313 unsigned AArch64FastISel::emitASR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
4314 unsigned Op1Reg,
bool Op1IsKill) {
4316 bool NeedTrunc =
false;
4320 case MVT::i8: Opc = AArch64::ASRVWr; NeedTrunc =
true; Mask = 0xff;
break;
4321 case MVT::i16: Opc = AArch64::ASRVWr; NeedTrunc =
true; Mask = 0xffff;
break;
4322 case MVT::i32: Opc = AArch64::ASRVWr;
break;
4323 case MVT::i64: Opc = AArch64::ASRVXr;
break;
4327 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4329 Op0Reg = emitIntExt(RetVT, Op0Reg,
MVT::i32,
false);
4330 Op1Reg = emitAnd_ri(
MVT::i32, Op1Reg, Op1IsKill, Mask);
4331 Op0IsKill = Op1IsKill =
true;
4333 unsigned ResultReg = fastEmitInst_rr(Opc, RC, Op0Reg, Op0IsKill, Op1Reg,
4336 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
4340 unsigned AArch64FastISel::emitASR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0,
4341 bool Op0IsKill, uint64_t Shift,
4344 "Unexpected source/return type pair.");
4347 "Unexpected source value type.");
4349 RetVT ==
MVT::i64) &&
"Unexpected return value type.");
4351 bool Is64Bit = (RetVT ==
MVT::i64);
4352 unsigned RegSize = Is64Bit ? 64 : 32;
4356 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4360 if (RetVT == SrcVT) {
4361 unsigned ResultReg = createResultReg(RC);
4362 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4363 TII.get(TargetOpcode::COPY), ResultReg)
4367 return emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4371 if (Shift >= DstBits)
4399 if (Shift >= SrcBits && IsZExt)
4402 unsigned ImmR = std::min<unsigned>(SrcBits - 1, Shift);
4403 unsigned ImmS = SrcBits - 1;
4404 static const unsigned OpcTable[2][2] = {
4405 {AArch64::SBFMWri, AArch64::SBFMXri},
4406 {AArch64::UBFMWri, AArch64::UBFMXri}
4408 unsigned Opc = OpcTable[IsZExt][Is64Bit];
4411 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4412 TII.get(AArch64::SUBREG_TO_REG), TmpReg)
4415 .
addImm(AArch64::sub_32);
4419 return fastEmitInst_rii(Opc, RC, Op0, Op0IsKill, ImmR, ImmS);
4422 unsigned AArch64FastISel::emitIntExt(
MVT SrcVT,
unsigned SrcReg,
MVT DestVT,
4443 return emiti1Ext(SrcReg, DestVT, IsZExt);
4446 Opc = IsZExt ? AArch64::UBFMXri : AArch64::SBFMXri;
4448 Opc = IsZExt ? AArch64::UBFMWri : AArch64::SBFMWri;
4453 Opc = IsZExt ? AArch64::UBFMXri : AArch64::SBFMXri;
4455 Opc = IsZExt ? AArch64::UBFMWri : AArch64::SBFMWri;
4460 Opc = IsZExt ? AArch64::UBFMXri : AArch64::SBFMXri;
4469 Register Src64 =
MRI.createVirtualRegister(&AArch64::GPR64RegClass);
4470 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4471 TII.get(AArch64::SUBREG_TO_REG), Src64)
4474 .
addImm(AArch64::sub_32);
4479 (DestVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4480 return fastEmitInst_rii(Opc, RC, SrcReg,
false, 0, Imm);
4487 case AArch64::LDURBBi:
4488 case AArch64::LDURHHi:
4489 case AArch64::LDURWi:
4490 case AArch64::LDRBBui:
4491 case AArch64::LDRHHui:
4492 case AArch64::LDRWui:
4493 case AArch64::LDRBBroX:
4494 case AArch64::LDRHHroX:
4495 case AArch64::LDRWroX:
4496 case AArch64::LDRBBroW:
4497 case AArch64::LDRHHroW:
4498 case AArch64::LDRWroW:
4507 case AArch64::LDURSBWi:
4508 case AArch64::LDURSHWi:
4509 case AArch64::LDURSBXi:
4510 case AArch64::LDURSHXi:
4511 case AArch64::LDURSWi:
4512 case AArch64::LDRSBWui:
4513 case AArch64::LDRSHWui:
4514 case AArch64::LDRSBXui:
4515 case AArch64::LDRSHXui:
4516 case AArch64::LDRSWui:
4517 case AArch64::LDRSBWroX:
4518 case AArch64::LDRSHWroX:
4519 case AArch64::LDRSBXroX:
4520 case AArch64::LDRSHXroX:
4521 case AArch64::LDRSWroX:
4522 case AArch64::LDRSBWroW:
4523 case AArch64::LDRSHWroW:
4524 case AArch64::LDRSBXroW:
4525 case AArch64::LDRSHXroW:
4526 case AArch64::LDRSWroW:
4531 bool AArch64FastISel::optimizeIntExtLoad(
const Instruction *I,
MVT RetVT,
4534 if (!LI || !LI->hasOneUse())
4538 unsigned Reg = lookUpRegForValue(LI);
4548 bool IsZExt = isa<ZExtInst>(
I);
4549 const auto *LoadMI =
MI;
4550 if (LoadMI->getOpcode() == TargetOpcode::COPY &&
4551 LoadMI->getOperand(1).getSubReg() == AArch64::sub_32) {
4553 LoadMI =
MRI.getUniqueVRegDef(LoadReg);
4554 assert(LoadMI &&
"Expected valid instruction");
4561 updateValueMap(I, Reg);
4566 unsigned Reg64 = createResultReg(&AArch64::GPR64RegClass);
4567 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4568 TII.get(AArch64::SUBREG_TO_REG), Reg64)
4571 .
addImm(AArch64::sub_32);
4576 "Expected copy instruction");
4579 removeDeadCode(I, std::next(I));
4581 updateValueMap(I, Reg);
4585 bool AArch64FastISel::selectIntExt(
const Instruction *I) {
4586 assert((isa<ZExtInst>(I) || isa<SExtInst>(I)) &&
4587 "Unexpected integer extend instruction.");
4590 if (!isTypeSupported(I->
getType(), RetVT))
4597 if (optimizeIntExtLoad(I, RetVT, SrcVT))
4600 unsigned SrcReg = getRegForValue(I->
getOperand(0));
4603 bool SrcIsKill = hasTrivialKill(I->
getOperand(0));
4606 bool IsZExt = isa<ZExtInst>(
I);
4607 if (
const auto *
Arg = dyn_cast<Argument>(I->
getOperand(0))) {
4608 if ((IsZExt &&
Arg->hasZExtAttr()) || (!IsZExt &&
Arg->hasSExtAttr())) {
4610 unsigned ResultReg = createResultReg(&AArch64::GPR64RegClass);
4611 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4612 TII.get(AArch64::SUBREG_TO_REG), ResultReg)
4615 .
addImm(AArch64::sub_32);
4622 unsigned UseReg = lookUpRegForValue(I);
4624 MRI.clearKillFlags(UseReg);
4626 updateValueMap(I, SrcReg);
4631 unsigned ResultReg = emitIntExt(SrcVT, SrcReg, RetVT, IsZExt);
4635 updateValueMap(I, ResultReg);
4639 bool AArch64FastISel::selectRem(
const Instruction *I,
unsigned ISDOpcode) {
4640 EVT DestEVT = TLI.getValueType(DL, I->
getType(),
true);
4649 bool Is64bit = (DestVT ==
MVT::i64);
4650 switch (ISDOpcode) {
4654 DivOpc = Is64bit ? AArch64::SDIVXr : AArch64::SDIVWr;
4657 DivOpc = Is64bit ? AArch64::UDIVXr : AArch64::UDIVWr;
4660 unsigned MSubOpc = Is64bit ? AArch64::MSUBXrrr : AArch64::MSUBWrrr;
4661 unsigned Src0Reg = getRegForValue(I->
getOperand(0));
4664 bool Src0IsKill = hasTrivialKill(I->
getOperand(0));
4666 unsigned Src1Reg = getRegForValue(I->
getOperand(1));
4669 bool Src1IsKill = hasTrivialKill(I->
getOperand(1));
4672 (DestVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4673 unsigned QuotReg = fastEmitInst_rr(DivOpc, RC, Src0Reg,
false,
4675 assert(QuotReg &&
"Unexpected DIV instruction emission failure.");
4678 unsigned ResultReg = fastEmitInst_rrr(MSubOpc, RC, QuotReg,
true,
4679 Src1Reg, Src1IsKill, Src0Reg,
4681 updateValueMap(I, ResultReg);
4685 bool AArch64FastISel::selectMul(
const Instruction *I) {
4687 if (!isTypeSupported(I->
getType(), VT,
true))
4695 if (
const auto *C = dyn_cast<ConstantInt>(Src0))
4696 if (C->getValue().isPowerOf2())
4700 if (
const auto *C = dyn_cast<ConstantInt>(Src1))
4701 if (C->getValue().isPowerOf2()) {
4702 uint64_t ShiftVal = C->getValue().logBase2();
4705 if (
const auto *ZExt = dyn_cast<ZExtInst>(Src0)) {
4708 if (isValueAvailable(ZExt) && isTypeSupported(ZExt->getSrcTy(), VT)) {
4711 Src0 = ZExt->getOperand(0);
4714 }
else if (
const auto *SExt = dyn_cast<SExtInst>(Src0)) {
4717 if (isValueAvailable(SExt) && isTypeSupported(SExt->getSrcTy(), VT)) {
4720 Src0 = SExt->getOperand(0);
4725 unsigned Src0Reg = getRegForValue(Src0);
4728 bool Src0IsKill = hasTrivialKill(Src0);
4730 unsigned ResultReg =
4731 emitLSL_ri(VT, SrcVT, Src0Reg, Src0IsKill, ShiftVal, IsZExt);
4734 updateValueMap(I, ResultReg);
4739 unsigned Src0Reg = getRegForValue(I->
getOperand(0));
4742 bool Src0IsKill = hasTrivialKill(I->
getOperand(0));
4744 unsigned Src1Reg = getRegForValue(I->
getOperand(1));
4747 bool Src1IsKill = hasTrivialKill(I->
getOperand(1));
4749 unsigned ResultReg = emitMul_rr(VT, Src0Reg, Src0IsKill, Src1Reg, Src1IsKill);
4754 updateValueMap(I, ResultReg);
4758 bool AArch64FastISel::selectShift(
const Instruction *I) {
4760 if (!isTypeSupported(I->
getType(), RetVT,
true))
4764 return selectOperator(I, I->
getOpcode());
4766 if (
const auto *C = dyn_cast<ConstantInt>(I->
getOperand(1))) {
4767 unsigned ResultReg = 0;
4768 uint64_t ShiftVal = C->getZExtValue();
4770 bool IsZExt = I->
getOpcode() != Instruction::AShr;
4772 if (
const auto *ZExt = dyn_cast<ZExtInst>(Op0)) {
4775 if (isValueAvailable(ZExt) && isTypeSupported(ZExt->getSrcTy(), TmpVT)) {
4778 Op0 = ZExt->getOperand(0);
4781 }
else if (
const auto *SExt = dyn_cast<SExtInst>(Op0)) {
4784 if (isValueAvailable(SExt) && isTypeSupported(SExt->getSrcTy(), TmpVT)) {
4787 Op0 = SExt->getOperand(0);
4792 unsigned Op0Reg = getRegForValue(Op0);
4795 bool Op0IsKill = hasTrivialKill(Op0);
4799 case Instruction::Shl:
4800 ResultReg = emitLSL_ri(RetVT, SrcVT, Op0Reg, Op0IsKill, ShiftVal, IsZExt);
4802 case Instruction::AShr:
4803 ResultReg = emitASR_ri(RetVT, SrcVT, Op0Reg, Op0IsKill, ShiftVal, IsZExt);
4805 case Instruction::LShr:
4806 ResultReg = emitLSR_ri(RetVT, SrcVT, Op0Reg, Op0IsKill, ShiftVal, IsZExt);
4812 updateValueMap(I, ResultReg);
4816 unsigned Op0Reg = getRegForValue(I->
getOperand(0));
4819 bool Op0IsKill = hasTrivialKill(I->
getOperand(0));
4821 unsigned Op1Reg = getRegForValue(I->
getOperand(1));
4824 bool Op1IsKill = hasTrivialKill(I->
getOperand(1));
4826 unsigned ResultReg = 0;
4829 case Instruction::Shl:
4830 ResultReg = emitLSL_rr(RetVT, Op0Reg, Op0IsKill, Op1Reg, Op1IsKill);
4832 case Instruction::AShr:
4833 ResultReg = emitASR_rr(RetVT, Op0Reg, Op0IsKill, Op1Reg, Op1IsKill);
4835 case Instruction::LShr:
4836 ResultReg = emitLSR_rr(RetVT, Op0Reg, Op0IsKill, Op1Reg, Op1IsKill);
4843 updateValueMap(I, ResultReg);
4847 bool AArch64FastISel::selectBitCast(
const Instruction *I) {
4852 if (!isTypeLegal(I->
getType(), RetVT))
4857 Opc = AArch64::FMOVWSr;
4859 Opc = AArch64::FMOVXDr;
4861 Opc = AArch64::FMOVSWr;
4863 Opc = AArch64::FMOVDXr;
4870 case MVT::i32: RC = &AArch64::GPR32RegClass;
break;
4871 case MVT::i64: RC = &AArch64::GPR64RegClass;
break;
4872 case MVT::f32: RC = &AArch64::FPR32RegClass;
break;
4873 case MVT::f64: RC = &AArch64::FPR64RegClass;
break;
4875 unsigned Op0Reg = getRegForValue(I->
getOperand(0));
4878 bool Op0IsKill = hasTrivialKill(I->
getOperand(0));
4879 unsigned ResultReg = fastEmitInst_r(Opc, RC, Op0Reg, Op0IsKill);
4884 updateValueMap(I, ResultReg);
4888 bool AArch64FastISel::selectFRem(
const Instruction *I) {
4890 if (!isTypeLegal(I->
getType(), RetVT))
4898 LC = RTLIB::REM_F32;
4901 LC = RTLIB::REM_F64;
4912 Entry.Ty =
Arg->getType();
4913 Args.push_back(Entry);
4916 CallLoweringInfo CLI;
4918 CLI.setCallee(DL, Ctx, TLI.getLibcallCallingConv(LC), I->
getType(),
4919 TLI.getLibcallName(LC), std::move(Args));
4920 if (!lowerCallTo(CLI))
4922 updateValueMap(I, CLI.ResultReg);
4926 bool AArch64FastISel::selectSDiv(
const Instruction *I) {
4928 if (!isTypeLegal(I->
getType(), VT))
4940 unsigned Src0Reg = getRegForValue(I->
getOperand(0));
4943 bool Src0IsKill = hasTrivialKill(I->
getOperand(0));
4945 if (cast<BinaryOperator>(I)->isExact()) {
4946 unsigned ResultReg = emitASR_ri(VT, VT, Src0Reg, Src0IsKill, Lg2);
4949 updateValueMap(I, ResultReg);
4953 int64_t Pow2MinusOne = (1ULL << Lg2) - 1;
4954 unsigned AddReg = emitAdd_ri_(VT, Src0Reg,
false, Pow2MinusOne);
4959 if (!emitICmp_ri(VT, Src0Reg,
false, 0))
4965 SelectOpc = AArch64::CSELXr;
4966 RC = &AArch64::GPR64RegClass;
4968 SelectOpc = AArch64::CSELWr;
4969 RC = &AArch64::GPR32RegClass;
4971 unsigned SelectReg =
4972 fastEmitInst_rri(SelectOpc, RC, AddReg,
true, Src0Reg,
4979 unsigned ZeroReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
4982 ResultReg = emitAddSub_rs(
false, VT, ZeroReg,
true,
4985 ResultReg = emitASR_ri(VT, VT, SelectReg,
true, Lg2);
4990 updateValueMap(I, ResultReg);
4997 std::pair<unsigned, bool> AArch64FastISel::getRegForGEPIndex(
const Value *Idx) {
4998 unsigned IdxN = getRegForValue(Idx);
5001 return std::pair<unsigned, bool>(0,
false);
5003 bool IdxNIsKill = hasTrivialKill(Idx);
5006 MVT PtrVT = TLI.getPointerTy(DL);
5008 if (IdxVT.
bitsLT(PtrVT)) {
5009 IdxN = emitIntExt(IdxVT.
getSimpleVT(), IdxN, PtrVT,
false);
5011 }
else if (IdxVT.
bitsGT(PtrVT))
5012 llvm_unreachable(
"AArch64 FastISel doesn't support types larger than i64");
5013 return std::pair<unsigned, bool>(IdxN, IdxNIsKill);
5020 bool AArch64FastISel::selectGetElementPtr(
const Instruction *I) {
5027 bool NIsKill = hasTrivialKill(I->
getOperand(0));
5031 uint64_t TotalOffs = 0;
5032 MVT VT = TLI.getPointerTy(DL);
5035 const Value *Idx = GTI.getOperand();
5036 if (
auto *StTy = GTI.getStructTypeOrNull()) {
5037 unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
5040 TotalOffs += DL.getStructLayout(StTy)->getElementOffset(Field);
5042 Type *Ty = GTI.getIndexedType();
5045 if (
const auto *CI = dyn_cast<ConstantInt>(Idx)) {
5050 DL.getTypeAllocSize(Ty) * cast<ConstantInt>(CI)->getSExtValue();
5054 N = emitAdd_ri_(VT, N, NIsKill, TotalOffs);
5062 uint64_t ElementSize = DL.getTypeAllocSize(Ty);
5063 std::pair<unsigned, bool> Pair = getRegForGEPIndex(Idx);
5064 unsigned IdxN = Pair.first;
5065 bool IdxNIsKill = Pair.second;
5069 if (ElementSize != 1) {
5070 unsigned C = fastEmit_i(VT, VT,
ISD::Constant, ElementSize);
5073 IdxN = emitMul_rr(VT, IdxN, IdxNIsKill, C,
true);
5078 N = fastEmit_rr(VT, VT,
ISD::ADD, N, NIsKill, IdxN, IdxNIsKill);
5084 N = emitAdd_ri_(VT, N, NIsKill, TotalOffs);
5088 updateValueMap(I, N);
5094 "cmpxchg survived AtomicExpand at optlevel > -O0");
5096 auto *RetPairTy = cast<StructType>(I->
getType());
5097 Type *RetTy = RetPairTy->getTypeAtIndex(0U);
5098 assert(RetPairTy->getTypeAtIndex(1U)->isIntegerTy(1) &&
5099 "cmpxchg has a non-i1 status result");
5102 if (!isTypeLegal(RetTy, VT))
5106 unsigned Opc, CmpOpc;
5110 Opc = AArch64::CMP_SWAP_32;
5111 CmpOpc = AArch64::SUBSWrs;
5112 ResRC = &AArch64::GPR32RegClass;
5114 Opc = AArch64::CMP_SWAP_64;
5115 CmpOpc = AArch64::SUBSXrs;
5116 ResRC = &AArch64::GPR64RegClass;
5130 const unsigned ResultReg1 = createResultReg(ResRC);
5131 const unsigned ResultReg2 = createResultReg(&AArch64::GPR32RegClass);
5132 const unsigned ScratchReg = createResultReg(&AArch64::GPR32RegClass);
5135 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
5142 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(CmpOpc))
5143 .addDef(VT ==
MVT::i32 ? AArch64::WZR : AArch64::XZR)
5148 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr))
5154 assert((ResultReg1 + 1) == ResultReg2 &&
"Nonconsecutive result registers.");
5155 updateValueMap(I, ResultReg1, 2);
5159 bool AArch64FastISel::fastSelectInstruction(
const Instruction *I) {
5164 case Instruction::Sub:
5165 return selectAddSub(I);
5166 case Instruction::Mul:
5167 return selectMul(I);
5168 case Instruction::SDiv:
5169 return selectSDiv(I);
5170 case Instruction::SRem:
5174 case Instruction::URem:
5178 case Instruction::Shl:
5179 case Instruction::LShr:
5180 case Instruction::AShr:
5181 return selectShift(I);
5182 case Instruction::And:
5183 case Instruction::Or:
5184 case Instruction::Xor:
5185 return selectLogicalOp(I);
5186 case Instruction::Br:
5187 return selectBranch(I);
5188 case Instruction::IndirectBr:
5189 return selectIndirectBr(I);
5190 case Instruction::BitCast:
5192 return selectBitCast(I);
5194 case Instruction::FPToSI:
5196 return selectFPToInt(I,
true);
5198 case Instruction::FPToUI:
5199 return selectFPToInt(I,
false);
5200 case Instruction::ZExt:
5201 case Instruction::SExt:
5202 return selectIntExt(I);
5203 case Instruction::Trunc:
5205 return selectTrunc(I);
5207 case Instruction::FPExt:
5208 return selectFPExt(I);
5209 case Instruction::FPTrunc:
5210 return selectFPTrunc(I);
5211 case Instruction::SIToFP:
5213 return selectIntToFP(I,
true);
5215 case Instruction::UIToFP:
5216 return selectIntToFP(I,
false);
5218 return selectLoad(I);
5220 return selectStore(I);
5221 case Instruction::FCmp:
5222 case Instruction::ICmp:
5223 return selectCmp(I);
5225 return selectSelect(I);
5227 return selectRet(I);
5228 case Instruction::FRem:
5229 return selectFRem(I);
5230 case Instruction::GetElementPtr:
5231 return selectGetElementPtr(I);
5232 case Instruction::AtomicCmpXchg:
5233 return selectAtomicCmpXchg(cast<AtomicCmpXchgInst>(I));
5237 return selectOperator(I, I->
getOpcode());
5244 return new AArch64FastISel(FuncInfo, LibInfo);
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
void setFrameAddressIsTaken(bool T)
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...
This class is the base class for the comparison instructions.
unsigned ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const
ClassifyGlobalReference - Find the target operand flags that describe how a global value should be re...
bool isLittleEndian() const
uint64_t getZExtValue() const
Get zero extended value.
This class represents an incoming formal argument to a Function.
Atomic ordering constants.
unsigned constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, const MachineOperand &RegMO, unsigned OpIdx)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
This class represents lattice values for constants.
Register getLocReg() const
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 hasCustomCallingConv() const
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.
void push_back(const T &Elt)
static CondCode getInvertedCondCode(CondCode Code)
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
Describe properties that are true of each instruction in the target description file.
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.
C - The default llvm calling convention, compatible with C.
BasicBlock * getSuccessor(unsigned i) const
Value * getNewValOperand()
unsigned const TargetRegisterInfo * TRI
block Block Frequency true
An instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
Value * getCondition() const
bool isVectorTy() const
True if this is an instance of VectorType.
void reserve(size_type N)
Value * getLength() const
bool isAnyArgRegReserved(const MachineFunction &MF) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Value * getArgOperand(unsigned i) const
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.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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...
bool RetCC_AArch64_WebKit_JS(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
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
LocInfo getLocInfo() const
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
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.
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned TargetFlags=0) 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.
iterator_range< succ_op_iterator > successors()
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.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
iterator_range< User::op_iterator > arg_operands()
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
SI Pre allocate WWM Registers
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo)
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.
bool is128BitVector() const
Return true if this is a 128-bit vector type.
bool isTargetWindows() const
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.
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
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.
bool CC_AArch64_DarwinPCS(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
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()
static Register UseReg(const MachineOperand &MO)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
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)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
0 1 1 1 True if ordered (no nans)
Register getFrameRegister(const MachineFunction &MF) const override
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...
1 1 0 1 True if unordered, less than, or equal
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
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.
Align max(MaybeAlign Lhs, Align Rhs)
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
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
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.
amdgpu Simplify well known AMD library false FunctionCallee Callee
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.
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.
void emitReservedArgRegCallError(const MachineFunction &MF) const
unsigned getNumArgOperands() const
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.
bool CC_AArch64_Win64_CFGuard_Check(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
bool CC_AArch64_WebKit_JS(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
Bitwise operators - logical and, logical or, logical xor.
unsigned getDestAddressSpace() const
uint64_t getElementOffset(unsigned Idx) const
unsigned greater or equal
bool isZero() const
Return true if the value is positive or negative zero.
static bool hasOneUse(unsigned Reg, MachineInstr *Def, MachineRegisterInfo &MRI, MachineDominatorTree &MDT, LiveIntervals &LIS)
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
const Function * getParent() const
Return the enclosing method, or null if none.
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.
bool CC_AArch64_AAPCS(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
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)
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.
bool CC_AArch64_GHC(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
bool isTargetILP32() const
static SDValue emitCmp(SelectionDAG &DAG, const SDLoc &DL, Comparison &C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool 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.
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...
APInt bitcastToAPInt() const
Register getReg() const
getReg - Returns the register number.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
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 RetCC_AArch64_AAPCS(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
PointerType * getType() const
Global values are always pointers.
iterator_range< arg_iterator > args()
Wrapper class representing virtual and physical registers.
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...