78 class AArch64FastISel final :
public FastISel {
87 BaseKind
Kind = RegBase;
93 unsigned OffsetReg = 0;
101 void setKind(BaseKind K) {
Kind = K; }
102 BaseKind getKind()
const {
return Kind; }
105 bool isRegBase()
const {
return Kind == RegBase; }
106 bool isFIBase()
const {
return Kind == FrameIndexBase; }
108 void setReg(
unsigned Reg) {
109 assert(isRegBase() &&
"Invalid base register access!");
114 assert(isRegBase() &&
"Invalid base register access!");
118 void setOffsetReg(
unsigned Reg) {
122 unsigned getOffsetReg()
const {
126 void setFI(
unsigned FI) {
127 assert(isFIBase() &&
"Invalid base frame index access!");
131 unsigned getFI()
const {
132 assert(isFIBase() &&
"Invalid base frame index access!");
136 void setOffset(int64_t O) {
Offset = O; }
138 void setShift(
unsigned S) { Shift = S; }
139 unsigned getShift() {
return Shift; }
150 bool fastLowerArguments()
override;
151 bool fastLowerCall(CallLoweringInfo &CLI)
override;
152 bool fastLowerIntrinsicCall(
const IntrinsicInst *II)
override;
168 bool selectRem(
const Instruction *
I,
unsigned ISDOpcode);
181 bool isTypeLegal(
Type *Ty,
MVT &VT);
182 bool isTypeSupported(
Type *Ty,
MVT &VT,
bool IsVectorAllowed =
false);
183 bool isValueAvailable(
const Value *V)
const;
190 bool isMemCpySmall(uint64_t Len,
unsigned Alignment);
197 std::pair<unsigned, bool> getRegForGEPIndex(
const Value *Idx);
200 unsigned emitAddSub(
bool UseAdd,
MVT RetVT,
const Value *LHS,
201 const Value *RHS,
bool SetFlags =
false,
202 bool WantResult =
true,
bool IsZExt =
false);
203 unsigned emitAddSub_rr(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
204 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
205 bool SetFlags =
false,
bool WantResult =
true);
206 unsigned emitAddSub_ri(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
207 bool LHSIsKill, uint64_t Imm,
bool SetFlags =
false,
208 bool WantResult =
true);
209 unsigned emitAddSub_rs(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
210 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
212 uint64_t ShiftImm,
bool SetFlags =
false,
213 bool WantResult =
true);
214 unsigned emitAddSub_rx(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
215 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
217 uint64_t ShiftImm,
bool SetFlags =
false,
218 bool WantResult =
true);
221 bool emitCompareAndBranch(
const BranchInst *BI);
223 bool emitICmp(
MVT RetVT,
const Value *LHS,
const Value *RHS,
bool IsZExt);
224 bool emitICmp_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill, uint64_t Imm);
225 bool emitFCmp(
MVT RetVT,
const Value *LHS,
const Value *RHS);
226 unsigned emitLoad(
MVT VT,
MVT ResultVT,
Address Addr,
bool WantZExt =
true,
228 bool emitStore(
MVT VT,
unsigned SrcReg,
Address Addr,
230 bool emitStoreRelease(
MVT VT,
unsigned SrcReg,
unsigned AddrReg,
232 unsigned emitIntExt(
MVT SrcVT,
unsigned SrcReg,
MVT DestVT,
bool isZExt);
233 unsigned emiti1Ext(
unsigned SrcReg,
MVT DestVT,
bool isZExt);
234 unsigned emitAdd(
MVT RetVT,
const Value *LHS,
const Value *RHS,
235 bool SetFlags =
false,
bool WantResult =
true,
236 bool IsZExt =
false);
237 unsigned emitAdd_ri_(
MVT VT,
unsigned Op0,
bool Op0IsKill, int64_t Imm);
238 unsigned emitSub(
MVT RetVT,
const Value *LHS,
const Value *RHS,
239 bool SetFlags =
false,
bool WantResult =
true,
240 bool IsZExt =
false);
241 unsigned emitSubs_rr(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
242 unsigned RHSReg,
bool RHSIsKill,
bool WantResult =
true);
243 unsigned emitSubs_rs(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
244 unsigned RHSReg,
bool RHSIsKill,
246 bool WantResult =
true);
247 unsigned emitLogicalOp(
unsigned ISDOpc,
MVT RetVT,
const Value *LHS,
249 unsigned emitLogicalOp_ri(
unsigned ISDOpc,
MVT RetVT,
unsigned LHSReg,
250 bool LHSIsKill, uint64_t Imm);
251 unsigned emitLogicalOp_rs(
unsigned ISDOpc,
MVT RetVT,
unsigned LHSReg,
252 bool LHSIsKill,
unsigned RHSReg,
bool RHSIsKill,
254 unsigned emitAnd_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill, uint64_t Imm);
255 unsigned emitMul_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
256 unsigned Op1,
bool Op1IsKill);
257 unsigned emitSMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
258 unsigned Op1,
bool Op1IsKill);
259 unsigned emitUMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
260 unsigned Op1,
bool Op1IsKill);
261 unsigned emitLSL_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
262 unsigned Op1Reg,
bool Op1IsKill);
263 unsigned emitLSL_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0Reg,
bool Op0IsKill,
264 uint64_t Imm,
bool IsZExt =
true);
265 unsigned emitLSR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
266 unsigned Op1Reg,
bool Op1IsKill);
267 unsigned emitLSR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0Reg,
bool Op0IsKill,
268 uint64_t Imm,
bool IsZExt =
true);
269 unsigned emitASR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
270 unsigned Op1Reg,
bool Op1IsKill);
271 unsigned emitASR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0Reg,
bool Op0IsKill,
272 uint64_t Imm,
bool IsZExt =
false);
283 bool finishCall(CallLoweringInfo &CLI,
MVT RetVT,
unsigned NumBytes);
287 unsigned fastMaterializeAlloca(
const AllocaInst *AI)
override;
288 unsigned fastMaterializeConstant(
const Constant *
C)
override;
289 unsigned fastMaterializeFloatZero(
const ConstantFP* CF)
override;
299 bool fastSelectInstruction(
const Instruction *
I)
override;
301 #include "AArch64GenFastISel.inc"
306 #include "AArch64GenCallingConv.inc"
310 assert((isa<ZExtInst>(I) || isa<SExtInst>(I)) &&
311 "Unexpected integer extend instruction.");
313 "Unexpected value type.");
314 bool IsZExt = isa<ZExtInst>(
I);
316 if (
const auto *LI = dyn_cast<LoadInst>(I->
getOperand(0)))
320 if (
const auto *Arg = dyn_cast<Argument>(I->
getOperand(0)))
321 if ((IsZExt && Arg->hasZExtAttr()) || (!IsZExt && Arg->hasSExtAttr()))
349 return CC_AArch64_WebKit_JS;
351 return CC_AArch64_GHC;
352 return Subtarget->isTargetDarwin() ? CC_AArch64_DarwinPCS : CC_AArch64_AAPCS;
355 unsigned AArch64FastISel::fastMaterializeAlloca(
const AllocaInst *AI) {
357 "Alloca should always return a pointer.");
360 if (!FuncInfo.StaticAllocaMap.count(AI))
364 FuncInfo.StaticAllocaMap.find(AI);
366 if (SI != FuncInfo.StaticAllocaMap.
end()) {
367 unsigned ResultReg = createResultReg(&AArch64::GPR64spRegClass);
368 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::ADDXri),
370 .addFrameIndex(SI->second)
379 unsigned AArch64FastISel::materializeInt(
const ConstantInt *CI,
MVT VT) {
388 : &AArch64::GPR32RegClass;
389 unsigned ZeroReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
390 unsigned ResultReg = createResultReg(RC);
391 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpcode::COPY),
396 unsigned AArch64FastISel::materializeFP(
const ConstantFP *CFP,
MVT VT) {
400 return fastMaterializeFloatZero(CFP);
409 if (TLI.isFPImmLegal(Val, VT)) {
412 assert((Imm != -1) &&
"Cannot encode floating-point constant.");
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)
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) {
461 if (!Subtarget->useSmallAddressing() && !Subtarget->isTargetMachO())
464 unsigned char OpFlags = Subtarget->ClassifyGlobalReference(GV,
TM);
466 EVT DestEVT = TLI.getValueType(
DL, GV->
getType(),
true);
470 unsigned ADRPReg = createResultReg(&AArch64::GPR64commonRegClass);
479 ResultReg = createResultReg(&AArch64::GPR64RegClass);
480 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::LDRXui),
491 ResultReg = createResultReg(&AArch64::GPR64spRegClass);
492 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::ADDXri),
501 unsigned AArch64FastISel::fastMaterializeConstant(
const Constant *
C) {
509 if (
const auto *CI = dyn_cast<ConstantInt>(C))
510 return materializeInt(CI, VT);
511 else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
512 return materializeFP(CFP, VT);
513 else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C))
514 return materializeGV(GV);
519 unsigned AArch64FastISel::fastMaterializeFloatZero(
const ConstantFP* CFP) {
521 "Floating-point constant is not a positive zero.");
523 if (!isTypeLegal(CFP->
getType(), VT))
530 unsigned ZReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
531 unsigned Opc = Is64Bit ? AArch64::FMOVXDr : AArch64::FMOVWSr;
532 return fastEmitInst_r(Opc, TLI.getRegClassFor(VT), ZReg,
true);
537 if (
const auto *
MI = dyn_cast<MulOperator>(I)) {
538 if (
const auto *C = dyn_cast<ConstantInt>(
MI->getOperand(0)))
539 if (C->getValue().isPowerOf2())
541 if (
const auto *C = dyn_cast<ConstantInt>(
MI->getOperand(1)))
542 if (C->getValue().isPowerOf2())
549 bool AArch64FastISel::computeAddress(
const Value *Obj,
Address &Addr,
Type *Ty)
551 const User *U =
nullptr;
552 unsigned Opcode = Instruction::UserOp1;
553 if (
const Instruction *
I = dyn_cast<Instruction>(Obj)) {
556 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
557 FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
558 Opcode =
I->getOpcode();
561 }
else if (
const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
562 Opcode = C->getOpcode();
566 if (
auto *Ty = dyn_cast<PointerType>(Obj->
getType()))
567 if (Ty->getAddressSpace() > 255)
575 case Instruction::BitCast:
577 return computeAddress(U->
getOperand(0), Addr, Ty);
579 case Instruction::IntToPtr:
582 TLI.getPointerTy(
DL))
583 return computeAddress(U->
getOperand(0), Addr, Ty);
586 case Instruction::PtrToInt:
588 if (TLI.getValueType(
DL, U->
getType()) == TLI.getPointerTy(
DL))
589 return computeAddress(U->
getOperand(0), Addr, Ty);
592 case Instruction::GetElementPtr: {
594 uint64_t TmpOffset = Addr.getOffset();
600 const Value *
Op = GTI.getOperand();
601 if (
StructType *STy = GTI.getStructTypeOrNull()) {
603 unsigned Idx = cast<ConstantInt>(
Op)->getZExtValue();
608 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
613 if (canFoldAddIntoGEP(U, Op)) {
616 cast<ConstantInt>(cast<AddOperator>(
Op)->getOperand(1));
619 Op = cast<AddOperator>(
Op)->getOperand(0);
623 goto unsupported_gep;
629 Addr.setOffset(TmpOffset);
630 if (computeAddress(U->
getOperand(0), Addr, Ty))
639 case Instruction::Alloca: {
642 FuncInfo.StaticAllocaMap.
find(AI);
643 if (SI != FuncInfo.StaticAllocaMap.end()) {
644 Addr.setKind(Address::FrameIndexBase);
645 Addr.setFI(SI->second);
655 if (isa<ConstantInt>(LHS))
658 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
660 return computeAddress(LHS, Addr, Ty);
664 if (computeAddress(LHS, Addr, Ty) && computeAddress(RHS, Addr, Ty))
670 case Instruction::Sub: {
675 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
677 return computeAddress(LHS, Addr, Ty);
681 case Instruction::Shl: {
682 if (Addr.getOffsetReg())
690 if (Val < 1 || Val > 3)
693 uint64_t NumBytes = 0;
696 NumBytes = NumBits / 8;
701 if (NumBytes != (1ULL << Val))
708 if (
const auto *
I = dyn_cast<Instruction>(Src)) {
709 if (FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
711 if (
const auto *ZE = dyn_cast<ZExtInst>(
I)) {
713 ZE->getOperand(0)->getType()->isIntegerTy(32)) {
715 Src = ZE->getOperand(0);
717 }
else if (
const auto *SE = dyn_cast<SExtInst>(
I)) {
719 SE->getOperand(0)->getType()->isIntegerTy(32)) {
721 Src = SE->getOperand(0);
727 if (
const auto *AI = dyn_cast<BinaryOperator>(Src))
728 if (AI->
getOpcode() == Instruction::And) {
732 if (
const auto *C = dyn_cast<ConstantInt>(LHS))
733 if (C->getValue() == 0xffffffff)
736 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
737 if (C->getValue() == 0xffffffff) {
739 unsigned Reg = getRegForValue(LHS);
742 bool RegIsKill = hasTrivialKill(LHS);
743 Reg = fastEmitInst_extractsubreg(
MVT::i32, Reg, RegIsKill,
745 Addr.setOffsetReg(Reg);
750 unsigned Reg = getRegForValue(Src);
753 Addr.setOffsetReg(Reg);
756 case Instruction::Mul: {
757 if (Addr.getOffsetReg())
767 if (
const auto *C = dyn_cast<ConstantInt>(LHS))
768 if (C->getValue().isPowerOf2())
771 assert(isa<ConstantInt>(RHS) &&
"Expected an ConstantInt.");
772 const auto *C = cast<ConstantInt>(RHS);
773 unsigned Val = C->getValue().logBase2();
774 if (Val < 1 || Val > 3)
777 uint64_t NumBytes = 0;
780 NumBytes = NumBits / 8;
785 if (NumBytes != (1ULL << Val))
791 const Value *Src = LHS;
792 if (
const auto *
I = dyn_cast<Instruction>(Src)) {
793 if (FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
795 if (
const auto *ZE = dyn_cast<ZExtInst>(
I)) {
797 ZE->getOperand(0)->getType()->isIntegerTy(32)) {
799 Src = ZE->getOperand(0);
801 }
else if (
const auto *SE = dyn_cast<SExtInst>(
I)) {
803 SE->getOperand(0)->getType()->isIntegerTy(32)) {
805 Src = SE->getOperand(0);
811 unsigned Reg = getRegForValue(Src);
814 Addr.setOffsetReg(Reg);
817 case Instruction::And: {
818 if (Addr.getOffsetReg())
827 if (
const auto *C = dyn_cast<ConstantInt>(LHS))
828 if (C->getValue() == 0xffffffff)
831 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
832 if (C->getValue() == 0xffffffff) {
837 unsigned Reg = getRegForValue(LHS);
840 bool RegIsKill = hasTrivialKill(LHS);
841 Reg = fastEmitInst_extractsubreg(
MVT::i32, Reg, RegIsKill,
843 Addr.setOffsetReg(Reg);
848 case Instruction::SExt:
849 case Instruction::ZExt: {
850 if (!Addr.getReg() || Addr.getOffsetReg())
853 const Value *Src =
nullptr;
855 if (
const auto *ZE = dyn_cast<ZExtInst>(U)) {
856 if (!
isIntExtFree(ZE) && ZE->getOperand(0)->getType()->isIntegerTy(32)) {
858 Src = ZE->getOperand(0);
860 }
else if (
const auto *SE = dyn_cast<SExtInst>(U)) {
861 if (!
isIntExtFree(SE) && SE->getOperand(0)->getType()->isIntegerTy(32)) {
863 Src = SE->getOperand(0);
871 unsigned Reg = getRegForValue(Src);
874 Addr.setOffsetReg(Reg);
879 if (Addr.isRegBase() && !Addr.getReg()) {
880 unsigned Reg = getRegForValue(Obj);
887 if (!Addr.getOffsetReg()) {
888 unsigned Reg = getRegForValue(Obj);
891 Addr.setOffsetReg(Reg);
898 bool AArch64FastISel::computeCallAddress(
const Value *V,
Address &Addr) {
899 const User *U =
nullptr;
900 unsigned Opcode = Instruction::UserOp1;
903 if (
const auto *
I = dyn_cast<Instruction>(V)) {
904 Opcode =
I->getOpcode();
906 InMBB =
I->getParent() == FuncInfo.MBB->getBasicBlock();
907 }
else if (
const auto *C = dyn_cast<ConstantExpr>(V)) {
908 Opcode = C->getOpcode();
914 case Instruction::BitCast:
917 return computeCallAddress(U->
getOperand(0), Addr);
919 case Instruction::IntToPtr:
923 TLI.getPointerTy(
DL))
924 return computeCallAddress(U->
getOperand(0), Addr);
926 case Instruction::PtrToInt:
928 if (InMBB && TLI.getValueType(
DL, U->
getType()) == TLI.getPointerTy(
DL))
929 return computeCallAddress(U->
getOperand(0), Addr);
933 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
934 Addr.setGlobalValue(GV);
939 if (!Addr.getGlobalValue()) {
940 Addr.setReg(getRegForValue(V));
941 return Addr.getReg() != 0;
948 bool AArch64FastISel::isTypeLegal(
Type *Ty,
MVT &VT) {
949 EVT evt = TLI.getValueType(
DL, Ty,
true);
962 return TLI.isTypeLegal(VT);
969 bool AArch64FastISel::isTypeSupported(
Type *Ty,
MVT &VT,
bool IsVectorAllowed) {
973 if (isTypeLegal(Ty, VT))
984 bool AArch64FastISel::isValueAvailable(
const Value *V)
const {
985 if (!isa<Instruction>(V))
988 const auto *
I = cast<Instruction>(V);
989 return FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB;
992 bool AArch64FastISel::simplifyAddress(
Address &Addr,
MVT VT) {
997 bool ImmediateOffsetNeedsLowering =
false;
998 bool RegisterOffsetNeedsLowering =
false;
999 int64_t
Offset = Addr.getOffset();
1000 if (((Offset < 0) || (Offset & (ScaleFactor - 1))) && !isInt<9>(Offset))
1001 ImmediateOffsetNeedsLowering =
true;
1002 else if (Offset > 0 && !(Offset & (ScaleFactor - 1)) &&
1003 !isUInt<12>(Offset / ScaleFactor))
1004 ImmediateOffsetNeedsLowering =
true;
1009 if (!ImmediateOffsetNeedsLowering && Addr.getOffset() && Addr.getOffsetReg())
1010 RegisterOffsetNeedsLowering =
true;
1013 if (Addr.isRegBase() && Addr.getOffsetReg() && !Addr.getReg())
1014 RegisterOffsetNeedsLowering =
true;
1019 if ((ImmediateOffsetNeedsLowering || Addr.getOffsetReg()) && Addr.isFIBase())
1021 unsigned ResultReg = createResultReg(&AArch64::GPR64spRegClass);
1022 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::ADDXri),
1024 .addFrameIndex(Addr.getFI())
1027 Addr.setKind(Address::RegBase);
1028 Addr.setReg(ResultReg);
1031 if (RegisterOffsetNeedsLowering) {
1032 unsigned ResultReg = 0;
1033 if (Addr.getReg()) {
1036 ResultReg = emitAddSub_rx(
true,
MVT::i64, Addr.getReg(),
1037 false, Addr.getOffsetReg(),
1038 false, Addr.getExtendType(),
1041 ResultReg = emitAddSub_rs(
true,
MVT::i64, Addr.getReg(),
1042 false, Addr.getOffsetReg(),
1048 false, Addr.getShift(),
1052 false, Addr.getShift(),
1056 false, Addr.getShift());
1061 Addr.setReg(ResultReg);
1062 Addr.setOffsetReg(0);
1069 if (ImmediateOffsetNeedsLowering) {
1079 Addr.setReg(ResultReg);
1085 void AArch64FastISel::addLoadStoreOperands(
Address &Addr,
1088 unsigned ScaleFactor,
1090 int64_t Offset = Addr.getOffset() / ScaleFactor;
1092 if (Addr.isFIBase()) {
1093 int FI = Addr.getFI();
1096 MMO = FuncInfo.MF->getMachineMemOperand(
1098 MFI.getObjectSize(FI), MFI.getObjectAlignment(FI));
1102 assert(Addr.isRegBase() &&
"Unexpected address kind.");
1109 if (Addr.getOffsetReg()) {
1110 assert(Addr.getOffset() == 0 &&
"Unexpected offset");
1113 MIB.
addReg(Addr.getReg());
1114 MIB.
addReg(Addr.getOffsetReg());
1116 MIB.
addImm(Addr.getShift() != 0);
1118 MIB.
addReg(Addr.getReg()).addImm(Offset);
1125 unsigned AArch64FastISel::emitAddSub(
bool UseAdd,
MVT RetVT,
const Value *LHS,
1126 const Value *RHS,
bool SetFlags,
1127 bool WantResult,
bool IsZExt) {
1129 bool NeedExtend =
false;
1152 if (UseAdd && isa<Constant>(LHS) && !isa<Constant>(RHS))
1156 if (UseAdd && LHS->
hasOneUse() && isValueAvailable(LHS))
1161 if (UseAdd && LHS->
hasOneUse() && isValueAvailable(LHS))
1162 if (
const auto *SI = dyn_cast<BinaryOperator>(LHS))
1163 if (isa<ConstantInt>(SI->getOperand(1)))
1164 if (SI->getOpcode() == Instruction::Shl ||
1165 SI->getOpcode() == Instruction::LShr ||
1166 SI->getOpcode() == Instruction::AShr )
1169 unsigned LHSReg = getRegForValue(LHS);
1172 bool LHSIsKill = hasTrivialKill(LHS);
1175 LHSReg = emitIntExt(SrcVT, LHSReg, RetVT, IsZExt);
1177 unsigned ResultReg = 0;
1178 if (
const auto *C = dyn_cast<ConstantInt>(RHS)) {
1179 uint64_t Imm = IsZExt ? C->getZExtValue() : C->getSExtValue();
1180 if (C->isNegative())
1181 ResultReg = emitAddSub_ri(!UseAdd, RetVT, LHSReg, LHSIsKill, -Imm,
1182 SetFlags, WantResult);
1184 ResultReg = emitAddSub_ri(UseAdd, RetVT, LHSReg, LHSIsKill, Imm, SetFlags,
1186 }
else if (
const auto *C = dyn_cast<Constant>(RHS))
1188 ResultReg = emitAddSub_ri(UseAdd, RetVT, LHSReg, LHSIsKill, 0, SetFlags,
1196 isValueAvailable(RHS)) {
1197 if (
const auto *SI = dyn_cast<BinaryOperator>(RHS))
1198 if (
const auto *C = dyn_cast<ConstantInt>(SI->getOperand(1)))
1199 if ((SI->getOpcode() == Instruction::Shl) && (C->getZExtValue() < 4)) {
1200 unsigned RHSReg = getRegForValue(SI->getOperand(0));
1203 bool RHSIsKill = hasTrivialKill(SI->getOperand(0));
1204 return emitAddSub_rx(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg,
1205 RHSIsKill, ExtendType, C->getZExtValue(),
1206 SetFlags, WantResult);
1208 unsigned RHSReg = getRegForValue(RHS);
1211 bool RHSIsKill = hasTrivialKill(RHS);
1212 return emitAddSub_rx(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg, RHSIsKill,
1213 ExtendType, 0, SetFlags, WantResult);
1217 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1219 const Value *MulLHS = cast<MulOperator>(RHS)->getOperand(0);
1220 const Value *MulRHS = cast<MulOperator>(RHS)->getOperand(1);
1222 if (
const auto *C = dyn_cast<ConstantInt>(MulLHS))
1223 if (C->getValue().isPowerOf2())
1226 assert(isa<ConstantInt>(MulRHS) &&
"Expected a ConstantInt.");
1227 uint64_t ShiftVal = cast<ConstantInt>(MulRHS)->getValue().logBase2();
1228 unsigned RHSReg = getRegForValue(MulLHS);
1231 bool RHSIsKill = hasTrivialKill(MulLHS);
1232 ResultReg = emitAddSub_rs(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg,
1241 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1242 if (
const auto *SI = dyn_cast<BinaryOperator>(RHS)) {
1243 if (
const auto *C = dyn_cast<ConstantInt>(SI->getOperand(1))) {
1245 switch (SI->getOpcode()) {
1251 uint64_t ShiftVal = C->getZExtValue();
1253 unsigned RHSReg = getRegForValue(SI->getOperand(0));
1256 bool RHSIsKill = hasTrivialKill(SI->getOperand(0));
1257 ResultReg = emitAddSub_rs(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg,
1258 RHSIsKill, ShiftType, ShiftVal, SetFlags,
1267 unsigned RHSReg = getRegForValue(RHS);
1270 bool RHSIsKill = hasTrivialKill(RHS);
1273 RHSReg = emitIntExt(SrcVT, RHSReg, RetVT, IsZExt);
1275 return emitAddSub_rr(UseAdd, RetVT, LHSReg, LHSIsKill, RHSReg, RHSIsKill,
1276 SetFlags, WantResult);
1279 unsigned AArch64FastISel::emitAddSub_rr(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1280 bool LHSIsKill,
unsigned RHSReg,
1281 bool RHSIsKill,
bool SetFlags,
1283 assert(LHSReg && RHSReg &&
"Invalid register number.");
1285 if (LHSReg == AArch64::SP || LHSReg == AArch64::WSP ||
1286 RHSReg == AArch64::SP || RHSReg == AArch64::WSP)
1292 static const unsigned OpcTable[2][2][2] = {
1293 { { AArch64::SUBWrr, AArch64::SUBXrr },
1294 { AArch64::ADDWrr, AArch64::ADDXrr } },
1295 { { AArch64::SUBSWrr, AArch64::SUBSXrr },
1296 { AArch64::ADDSWrr, AArch64::ADDSXrr } }
1299 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1301 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1304 ResultReg = createResultReg(RC);
1306 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1311 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1317 unsigned AArch64FastISel::emitAddSub_ri(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1318 bool LHSIsKill, uint64_t Imm,
1319 bool SetFlags,
bool WantResult) {
1320 assert(LHSReg &&
"Invalid register number.");
1326 if (isUInt<12>(Imm))
1328 else if ((Imm & 0xfff000) == Imm) {
1334 static const unsigned OpcTable[2][2][2] = {
1335 { { AArch64::SUBWri, AArch64::SUBXri },
1336 { AArch64::ADDWri, AArch64::ADDXri } },
1337 { { AArch64::SUBSWri, AArch64::SUBSXri },
1338 { AArch64::ADDSWri, AArch64::ADDSXri } }
1341 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1344 RC = Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1346 RC = Is64Bit ? &AArch64::GPR64spRegClass : &AArch64::GPR32spRegClass;
1349 ResultReg = createResultReg(RC);
1351 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1355 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1362 unsigned AArch64FastISel::emitAddSub_rs(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1363 bool LHSIsKill,
unsigned RHSReg,
1366 uint64_t ShiftImm,
bool SetFlags,
1368 assert(LHSReg && RHSReg &&
"Invalid register number.");
1369 assert(LHSReg != AArch64::SP && LHSReg != AArch64::WSP &&
1370 RHSReg != AArch64::SP && RHSReg != AArch64::WSP);
1379 static const unsigned OpcTable[2][2][2] = {
1380 { { AArch64::SUBWrs, AArch64::SUBXrs },
1381 { AArch64::ADDWrs, AArch64::ADDXrs } },
1382 { { AArch64::SUBSWrs, AArch64::SUBSXrs },
1383 { AArch64::ADDSWrs, AArch64::ADDSXrs } }
1386 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1388 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1391 ResultReg = createResultReg(RC);
1393 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1398 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1405 unsigned AArch64FastISel::emitAddSub_rx(
bool UseAdd,
MVT RetVT,
unsigned LHSReg,
1406 bool LHSIsKill,
unsigned RHSReg,
1409 uint64_t ShiftImm,
bool SetFlags,
1411 assert(LHSReg && RHSReg &&
"Invalid register number.");
1412 assert(LHSReg != AArch64::XZR && LHSReg != AArch64::WZR &&
1413 RHSReg != AArch64::XZR && RHSReg != AArch64::WZR);
1421 static const unsigned OpcTable[2][2][2] = {
1422 { { AArch64::SUBWrx, AArch64::SUBXrx },
1423 { AArch64::ADDWrx, AArch64::ADDXrx } },
1424 { { AArch64::SUBSWrx, AArch64::SUBSXrx },
1425 { AArch64::ADDSWrx, AArch64::ADDSXrx } }
1428 unsigned Opc = OpcTable[SetFlags][UseAdd][Is64Bit];
1431 RC = Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
1433 RC = Is64Bit ? &AArch64::GPR64spRegClass : &AArch64::GPR32spRegClass;
1436 ResultReg = createResultReg(RC);
1438 ResultReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
1443 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg)
1452 EVT EVT = TLI.getValueType(
DL, Ty,
true);
1465 return emitICmp(VT, LHS, RHS, IsZExt);
1468 return emitFCmp(VT, LHS, RHS);
1472 bool AArch64FastISel::emitICmp(
MVT RetVT,
const Value *LHS,
const Value *RHS,
1474 return emitSub(RetVT, LHS, RHS,
true,
false,
1478 bool AArch64FastISel::emitICmp_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
1480 return emitAddSub_ri(
false, RetVT, LHSReg, LHSIsKill, Imm,
1484 bool AArch64FastISel::emitFCmp(
MVT RetVT,
const Value *LHS,
const Value *RHS) {
1490 bool UseImm =
false;
1491 if (
const auto *CFP = dyn_cast<ConstantFP>(RHS))
1495 unsigned LHSReg = getRegForValue(LHS);
1498 bool LHSIsKill = hasTrivialKill(LHS);
1501 unsigned Opc = (RetVT ==
MVT::f64) ? AArch64::FCMPDri : AArch64::FCMPSri;
1502 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
1507 unsigned RHSReg = getRegForValue(RHS);
1510 bool RHSIsKill = hasTrivialKill(RHS);
1512 unsigned Opc = (RetVT ==
MVT::f64) ? AArch64::FCMPDrr : AArch64::FCMPSrr;
1513 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
1519 unsigned AArch64FastISel::emitAdd(
MVT RetVT,
const Value *LHS,
const Value *RHS,
1520 bool SetFlags,
bool WantResult,
bool IsZExt) {
1521 return emitAddSub(
true, RetVT, LHS, RHS, SetFlags, WantResult,
1530 unsigned AArch64FastISel::emitAdd_ri_(
MVT VT,
unsigned Op0,
bool Op0IsKill,
1534 ResultReg = emitAddSub_ri(
false, VT, Op0, Op0IsKill, -Imm);
1536 ResultReg = emitAddSub_ri(
true, VT, Op0, Op0IsKill, Imm);
1545 ResultReg = emitAddSub_rr(
true, VT, Op0, Op0IsKill, CReg,
true);
1549 unsigned AArch64FastISel::emitSub(
MVT RetVT,
const Value *LHS,
const Value *RHS,
1550 bool SetFlags,
bool WantResult,
bool IsZExt) {
1551 return emitAddSub(
false, RetVT, LHS, RHS, SetFlags, WantResult,
1555 unsigned AArch64FastISel::emitSubs_rr(
MVT RetVT,
unsigned LHSReg,
1556 bool LHSIsKill,
unsigned RHSReg,
1557 bool RHSIsKill,
bool WantResult) {
1558 return emitAddSub_rr(
false, RetVT, LHSReg, LHSIsKill, RHSReg,
1559 RHSIsKill,
true, WantResult);
1562 unsigned AArch64FastISel::emitSubs_rs(
MVT RetVT,
unsigned LHSReg,
1563 bool LHSIsKill,
unsigned RHSReg,
1566 uint64_t ShiftImm,
bool WantResult) {
1567 return emitAddSub_rs(
false, RetVT, LHSReg, LHSIsKill, RHSReg,
1568 RHSIsKill, ShiftType, ShiftImm,
true,
1572 unsigned AArch64FastISel::emitLogicalOp(
unsigned ISDOpc,
MVT RetVT,
1575 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS))
1579 if (LHS->
hasOneUse() && isValueAvailable(LHS))
1584 if (LHS->
hasOneUse() && isValueAvailable(LHS))
1585 if (
const auto *SI = dyn_cast<ShlOperator>(LHS))
1586 if (isa<ConstantInt>(SI->getOperand(1)))
1589 unsigned LHSReg = getRegForValue(LHS);
1592 bool LHSIsKill = hasTrivialKill(LHS);
1594 unsigned ResultReg = 0;
1595 if (
const auto *C = dyn_cast<ConstantInt>(RHS)) {
1596 uint64_t Imm = C->getZExtValue();
1597 ResultReg = emitLogicalOp_ri(ISDOpc, RetVT, LHSReg, LHSIsKill, Imm);
1603 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1605 const Value *MulLHS = cast<MulOperator>(RHS)->getOperand(0);
1606 const Value *MulRHS = cast<MulOperator>(RHS)->getOperand(1);
1608 if (
const auto *C = dyn_cast<ConstantInt>(MulLHS))
1609 if (C->getValue().isPowerOf2())
1612 assert(isa<ConstantInt>(MulRHS) &&
"Expected a ConstantInt.");
1613 uint64_t ShiftVal = cast<ConstantInt>(MulRHS)->getValue().logBase2();
1615 unsigned RHSReg = getRegForValue(MulLHS);
1618 bool RHSIsKill = hasTrivialKill(MulLHS);
1619 ResultReg = emitLogicalOp_rs(ISDOpc, RetVT, LHSReg, LHSIsKill, RHSReg,
1620 RHSIsKill, ShiftVal);
1627 if (RHS->
hasOneUse() && isValueAvailable(RHS)) {
1628 if (
const auto *SI = dyn_cast<ShlOperator>(RHS))
1629 if (
const auto *C = dyn_cast<ConstantInt>(SI->getOperand(1))) {
1630 uint64_t ShiftVal = C->getZExtValue();
1631 unsigned RHSReg = getRegForValue(SI->getOperand(0));
1634 bool RHSIsKill = hasTrivialKill(SI->getOperand(0));
1635 ResultReg = emitLogicalOp_rs(ISDOpc, RetVT, LHSReg, LHSIsKill, RHSReg,
1636 RHSIsKill, ShiftVal);
1642 unsigned RHSReg = getRegForValue(RHS);
1645 bool RHSIsKill = hasTrivialKill(RHS);
1648 ResultReg = fastEmit_rr(VT, VT, ISDOpc, LHSReg, LHSIsKill, RHSReg, RHSIsKill);
1650 uint64_t
Mask = (RetVT ==
MVT::i8) ? 0xff : 0xffff;
1651 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
1656 unsigned AArch64FastISel::emitLogicalOp_ri(
unsigned ISDOpc,
MVT RetVT,
1657 unsigned LHSReg,
bool LHSIsKill,
1660 "ISD nodes are not consecutive!");
1661 static const unsigned OpcTable[3][2] = {
1662 { AArch64::ANDWri, AArch64::ANDXri },
1663 { AArch64::ORRWri, AArch64::ORRXri },
1664 { AArch64::EORWri, AArch64::EORXri }
1677 Opc = OpcTable[Idx][0];
1678 RC = &AArch64::GPR32spRegClass;
1683 Opc = OpcTable[ISDOpc -
ISD::AND][1];
1684 RC = &AArch64::GPR64spRegClass;
1692 unsigned ResultReg =
1693 fastEmitInst_ri(Opc, RC, LHSReg, LHSIsKill,
1696 uint64_t
Mask = (RetVT ==
MVT::i8) ? 0xff : 0xffff;
1697 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
1702 unsigned AArch64FastISel::emitLogicalOp_rs(
unsigned ISDOpc,
MVT RetVT,
1703 unsigned LHSReg,
bool LHSIsKill,
1704 unsigned RHSReg,
bool RHSIsKill,
1705 uint64_t ShiftImm) {
1707 "ISD nodes are not consecutive!");
1708 static const unsigned OpcTable[3][2] = {
1709 { AArch64::ANDWrs, AArch64::ANDXrs },
1710 { AArch64::ORRWrs, AArch64::ORRXrs },
1711 { AArch64::EORWrs, AArch64::EORXrs }
1727 Opc = OpcTable[ISDOpc -
ISD::AND][0];
1728 RC = &AArch64::GPR32RegClass;
1731 Opc = OpcTable[ISDOpc -
ISD::AND][1];
1732 RC = &AArch64::GPR64RegClass;
1735 unsigned ResultReg =
1736 fastEmitInst_rri(Opc, RC, LHSReg, LHSIsKill, RHSReg, RHSIsKill,
1739 uint64_t
Mask = (RetVT ==
MVT::i8) ? 0xff : 0xffff;
1740 ResultReg = emitAnd_ri(
MVT::i32, ResultReg,
true, Mask);
1745 unsigned AArch64FastISel::emitAnd_ri(
MVT RetVT,
unsigned LHSReg,
bool LHSIsKill,
1747 return emitLogicalOp_ri(
ISD::AND, RetVT, LHSReg, LHSIsKill, Imm);
1750 unsigned AArch64FastISel::emitLoad(
MVT VT,
MVT RetVT,
Address Addr,
1752 if (!TLI.allowsMisalignedMemoryAccesses(VT))
1756 if (!simplifyAddress(Addr, VT))
1765 bool UseScaled =
true;
1766 if ((Addr.getOffset() < 0) || (Addr.getOffset() & (ScaleFactor - 1))) {
1771 static const unsigned GPOpcTable[2][8][4] = {
1773 { { AArch64::LDURSBWi, AArch64::LDURSHWi, AArch64::LDURWi,
1775 { AArch64::LDURSBXi, AArch64::LDURSHXi, AArch64::LDURSWi,
1777 { AArch64::LDRSBWui, AArch64::LDRSHWui, AArch64::LDRWui,
1779 { AArch64::LDRSBXui, AArch64::LDRSHXui, AArch64::LDRSWui,
1781 { AArch64::LDRSBWroX, AArch64::LDRSHWroX, AArch64::LDRWroX,
1783 { AArch64::LDRSBXroX, AArch64::LDRSHXroX, AArch64::LDRSWroX,
1785 { AArch64::LDRSBWroW, AArch64::LDRSHWroW, AArch64::LDRWroW,
1787 { AArch64::LDRSBXroW, AArch64::LDRSHXroW, AArch64::LDRSWroW,
1791 { { AArch64::LDURBBi, AArch64::LDURHHi, AArch64::LDURWi,
1793 { AArch64::LDURBBi, AArch64::LDURHHi, AArch64::LDURWi,
1795 { AArch64::LDRBBui, AArch64::LDRHHui, AArch64::LDRWui,
1797 { AArch64::LDRBBui, AArch64::LDRHHui, AArch64::LDRWui,
1799 { AArch64::LDRBBroX, AArch64::LDRHHroX, AArch64::LDRWroX,
1801 { AArch64::LDRBBroX, AArch64::LDRHHroX, AArch64::LDRWroX,
1803 { AArch64::LDRBBroW, AArch64::LDRHHroW, AArch64::LDRWroW,
1805 { AArch64::LDRBBroW, AArch64::LDRHHroW, AArch64::LDRWroW,
1810 static const unsigned FPOpcTable[4][2] = {
1811 { AArch64::LDURSi, AArch64::LDURDi },
1812 { AArch64::LDRSui, AArch64::LDRDui },
1813 { AArch64::LDRSroX, AArch64::LDRDroX },
1814 { AArch64::LDRSroW, AArch64::LDRDroW }
1819 bool UseRegOffset = Addr.isRegBase() && !Addr.getOffset() && Addr.getReg() &&
1820 Addr.getOffsetReg();
1821 unsigned Idx = UseRegOffset ? 2 : UseScaled ? 1 : 0;
1826 bool IsRet64Bit = RetVT ==
MVT::i64;
1832 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][0];
1833 RC = (IsRet64Bit && !WantZExt) ?
1834 &AArch64::GPR64RegClass: &AArch64::GPR32RegClass;
1837 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][1];
1838 RC = (IsRet64Bit && !WantZExt) ?
1839 &AArch64::GPR64RegClass: &AArch64::GPR32RegClass;
1842 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][2];
1843 RC = (IsRet64Bit && !WantZExt) ?
1844 &AArch64::GPR64RegClass: &AArch64::GPR32RegClass;
1847 Opc = GPOpcTable[WantZExt][2 * Idx + IsRet64Bit][3];
1848 RC = &AArch64::GPR64RegClass;
1851 Opc = FPOpcTable[Idx][0];
1852 RC = &AArch64::FPR32RegClass;
1855 Opc = FPOpcTable[Idx][1];
1856 RC = &AArch64::FPR64RegClass;
1861 unsigned ResultReg = createResultReg(RC);
1863 TII.get(Opc), ResultReg);
1868 unsigned ANDReg = emitAnd_ri(
MVT::i32, ResultReg,
true, 1);
1869 assert(ANDReg &&
"Unexpected AND instruction emission failure.");
1876 unsigned Reg64 = createResultReg(&AArch64::GPR64RegClass);
1877 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1878 TII.get(AArch64::SUBREG_TO_REG), Reg64)
1881 .
addImm(AArch64::sub_32);
1887 bool AArch64FastISel::selectAddSub(
const Instruction *
I) {
1889 if (!isTypeSupported(I->
getType(), VT,
true))
1893 return selectOperator(I, I->
getOpcode());
1902 case Instruction::Sub:
1909 updateValueMap(I, ResultReg);
1913 bool AArch64FastISel::selectLogicalOp(
const Instruction *I) {
1915 if (!isTypeSupported(I->
getType(), VT,
true))
1919 return selectOperator(I, I->
getOpcode());
1925 case Instruction::And:
1928 case Instruction::Or:
1931 case Instruction::Xor:
1938 updateValueMap(I, ResultReg);
1942 bool AArch64FastISel::selectLoad(
const Instruction *I) {
1947 if (!isTypeSupported(I->
getType(), VT,
true) ||
1948 cast<LoadInst>(I)->isAtomic())
1952 if (TLI.supportSwiftError()) {
1955 if (
const Argument *Arg = dyn_cast<Argument>(SV)) {
1956 if (Arg->hasSwiftErrorAttr())
1960 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(SV)) {
1961 if (Alloca->isSwiftError())
1972 bool WantZExt =
true;
1974 const Value *IntExtVal =
nullptr;
1976 if (
const auto *ZE = dyn_cast<ZExtInst>(I->
use_begin()->getUser())) {
1977 if (isTypeSupported(ZE->getType(), RetVT))
1981 }
else if (
const auto *SE = dyn_cast<SExtInst>(I->
use_begin()->getUser())) {
1982 if (isTypeSupported(SE->getType(), RetVT))
1990 unsigned ResultReg =
1991 emitLoad(VT, RetVT, Addr, WantZExt, createMachineMemOperandFor(I));
2011 unsigned Reg = lookUpRegForValue(IntExtVal);
2012 auto *
MI =
MRI.getUniqueVRegDef(Reg);
2017 std::prev(FuncInfo.InsertPt)->eraseFromParent();
2018 ResultReg = std::prev(FuncInfo.InsertPt)->getOperand(0).getReg();
2020 ResultReg = fastEmitInst_extractsubreg(
MVT::i32, ResultReg,
2024 updateValueMap(I, ResultReg);
2033 for (
auto &Opnd :
MI->uses()) {
2035 Reg = Opnd.getReg();
2039 MI->eraseFromParent();
2042 MI =
MRI.getUniqueVRegDef(Reg);
2044 updateValueMap(IntExtVal, ResultReg);
2048 updateValueMap(I, ResultReg);
2052 bool AArch64FastISel::emitStoreRelease(
MVT VT,
unsigned SrcReg,
2057 default:
return false;
2058 case MVT::i8: Opc = AArch64::STLRB;
break;
2059 case MVT::i16: Opc = AArch64::STLRH;
break;
2060 case MVT::i32: Opc = AArch64::STLRW;
break;
2061 case MVT::i64: Opc = AArch64::STLRX;
break;
2067 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
2074 bool AArch64FastISel::emitStore(
MVT VT,
unsigned SrcReg,
Address Addr,
2076 if (!TLI.allowsMisalignedMemoryAccesses(VT))
2080 if (!simplifyAddress(Addr, VT))
2089 bool UseScaled =
true;
2090 if ((Addr.getOffset() < 0) || (Addr.getOffset() & (ScaleFactor - 1))) {
2095 static const unsigned OpcTable[4][6] = {
2096 { AArch64::STURBBi, AArch64::STURHHi, AArch64::STURWi, AArch64::STURXi,
2097 AArch64::STURSi, AArch64::STURDi },
2098 { AArch64::STRBBui, AArch64::STRHHui, AArch64::STRWui, AArch64::STRXui,
2099 AArch64::STRSui, AArch64::STRDui },
2100 { AArch64::STRBBroX, AArch64::STRHHroX, AArch64::STRWroX, AArch64::STRXroX,
2101 AArch64::STRSroX, AArch64::STRDroX },
2102 { AArch64::STRBBroW, AArch64::STRHHroW, AArch64::STRWroW, AArch64::STRXroW,
2103 AArch64::STRSroW, AArch64::STRDroW }
2107 bool VTIsi1 =
false;
2108 bool UseRegOffset = Addr.isRegBase() && !Addr.getOffset() && Addr.getReg() &&
2109 Addr.getOffsetReg();
2110 unsigned Idx = UseRegOffset ? 2 : UseScaled ? 1 : 0;
2118 case MVT::i8: Opc = OpcTable[Idx][0];
break;
2119 case MVT::i16: Opc = OpcTable[Idx][1];
break;
2120 case MVT::i32: Opc = OpcTable[Idx][2];
break;
2121 case MVT::i64: Opc = OpcTable[Idx][3];
break;
2122 case MVT::f32: Opc = OpcTable[Idx][4];
break;
2123 case MVT::f64: Opc = OpcTable[Idx][5];
break;
2127 if (VTIsi1 && SrcReg != AArch64::WZR) {
2128 unsigned ANDReg = emitAnd_ri(
MVT::i32, SrcReg,
false, 1);
2129 assert(ANDReg &&
"Unexpected AND instruction emission failure.");
2136 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II).
addReg(SrcReg);
2142 bool AArch64FastISel::selectStore(
const Instruction *I) {
2148 if (!isTypeSupported(Op0->
getType(), VT,
true))
2152 if (TLI.supportSwiftError()) {
2155 if (
const Argument *Arg = dyn_cast<Argument>(PtrV)) {
2156 if (Arg->hasSwiftErrorAttr())
2160 if (
const AllocaInst *Alloca = dyn_cast<AllocaInst>(PtrV)) {
2161 if (Alloca->isSwiftError())
2168 unsigned SrcReg = 0;
2169 if (
const auto *CI = dyn_cast<ConstantInt>(Op0)) {
2171 SrcReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
2172 }
else if (
const auto *CF = dyn_cast<ConstantFP>(Op0)) {
2173 if (CF->isZero() && !CF->isNegative()) {
2175 SrcReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
2180 SrcReg = getRegForValue(Op0);
2185 auto *SI = cast<StoreInst>(
I);
2188 if (SI->isAtomic()) {
2193 unsigned AddrReg = getRegForValue(PtrV);
2194 return emitStoreRelease(VT, SrcReg, AddrReg,
2195 createMachineMemOperandFor(I));
2201 if (!computeAddress(PtrV, Addr, Op0->
getType()))
2204 if (!emitStore(VT, SrcReg, Addr, createMachineMemOperandFor(I)))
2256 bool AArch64FastISel::emitCompareAndBranch(
const BranchInst *BI) {
2265 if (!isTypeSupported(LHS->
getType(), VT))
2276 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
2283 switch (Predicate) {
2288 if (isa<Constant>(LHS) && cast<Constant>(LHS)->isNullValue())
2291 if (!isa<Constant>(RHS) || !cast<Constant>(RHS)->isNullValue())
2294 if (
const auto *AI = dyn_cast<BinaryOperator>(LHS))
2295 if (AI->
getOpcode() == Instruction::And && isValueAvailable(AI)) {
2299 if (
const auto *C = dyn_cast<ConstantInt>(AndLHS))
2300 if (C->getValue().isPowerOf2())
2303 if (
const auto *C = dyn_cast<ConstantInt>(AndRHS))
2304 if (C->getValue().isPowerOf2()) {
2305 TestBit = C->getValue().logBase2();
2317 if (!isa<Constant>(RHS) || !cast<Constant>(RHS)->isNullValue())
2325 if (!isa<ConstantInt>(RHS))
2328 if (cast<ConstantInt>(RHS)->getValue() !=
APInt(BW, -1,
true))
2336 static const unsigned OpcTable[2][2][2] = {
2337 { {AArch64::CBZW, AArch64::CBZX },
2338 {AArch64::CBNZW, AArch64::CBNZX} },
2339 { {AArch64::TBZW, AArch64::TBZX },
2340 {AArch64::TBNZW, AArch64::TBNZX} }
2343 bool IsBitTest = TestBit != -1;
2344 bool Is64Bit = BW == 64;
2345 if (TestBit < 32 && TestBit >= 0)
2348 unsigned Opc = OpcTable[IsBitTest][IsCmpNE][Is64Bit];
2351 unsigned SrcReg = getRegForValue(LHS);
2354 bool SrcIsKill = hasTrivialKill(LHS);
2356 if (BW == 64 && !Is64Bit)
2357 SrcReg = fastEmitInst_extractsubreg(
MVT::i32, SrcReg, SrcIsKill,
2360 if ((BW < 32) && !IsBitTest)
2361 SrcReg = emitIntExt(VT, SrcReg,
MVT::i32,
true);
2366 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
2372 finishCondBranch(BI->
getParent(), TBB, FBB);
2376 bool AArch64FastISel::selectBranch(
const Instruction *I) {
2388 if (CI->
hasOneUse() && isValueAvailable(CI)) {
2391 switch (Predicate) {
2395 fastEmitBranch(FBB, DbgLoc);
2398 fastEmitBranch(TBB, DbgLoc);
2403 if (emitCompareAndBranch(BI))
2407 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
2420 switch (Predicate) {
2436 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::Bcc))
2442 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::Bcc))
2446 finishCondBranch(BI->
getParent(), TBB, FBB);
2449 }
else if (
const auto *CI = dyn_cast<ConstantInt>(BI->
getCondition())) {
2450 uint64_t Imm = CI->getZExtValue();
2461 FuncInfo.MBB->addSuccessorWithoutProb(Target);
2473 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::Bcc))
2477 finishCondBranch(BI->
getParent(), TBB, FBB);
2485 bool CondRegIsKill = hasTrivialKill(BI->
getCondition());
2488 unsigned Opcode = AArch64::TBNZW;
2489 if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
2491 Opcode = AArch64::TBZW;
2495 unsigned ConstrainedCondReg
2497 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
2502 finishCondBranch(BI->
getParent(), TBB, FBB);
2506 bool AArch64FastISel::selectIndirectBr(
const Instruction *I) {
2508 unsigned AddrReg = getRegForValue(BI->
getOperand(0));
2515 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II).
addReg(AddrReg);
2519 FuncInfo.MBB->addSuccessor(FuncInfo.MBBMap[Succ]);
2524 bool AArch64FastISel::selectCmp(
const Instruction *I) {
2525 const CmpInst *CI = cast<CmpInst>(
I);
2533 unsigned ResultReg = 0;
2534 switch (Predicate) {
2538 ResultReg = createResultReg(&AArch64::GPR32RegClass);
2539 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
2540 TII.get(TargetOpcode::COPY), ResultReg)
2549 updateValueMap(I, ResultReg);
2557 ResultReg = createResultReg(&AArch64::GPR32RegClass);
2561 static unsigned CondCodeTable[2][2] = {
2566 switch (Predicate) {
2570 CondCodes = &CondCodeTable[0][0];
2573 CondCodes = &CondCodeTable[1][0];
2578 unsigned TmpReg1 = createResultReg(&AArch64::GPR32RegClass);
2579 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr),
2583 .addImm(CondCodes[0]);
2584 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr),
2588 .addImm(CondCodes[1]);
2590 updateValueMap(I, ResultReg);
2598 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr),
2602 .addImm(invertedCC);
2604 updateValueMap(I, ResultReg);
2610 bool AArch64FastISel::optimizeSelect(
const SelectInst *SI) {
2614 const Value *Src1Val, *Src2Val;
2616 bool NeedExtraOp =
false;
2617 if (
auto *CI = dyn_cast<ConstantInt>(SI->
getTrueValue())) {
2621 Opc = AArch64::ORRWrr;
2626 Opc = AArch64::BICWrr;
2628 }
else if (
auto *CI = dyn_cast<ConstantInt>(SI->
getFalseValue())) {
2632 Opc = AArch64::ORRWrr;
2638 Opc = AArch64::ANDWrr;
2645 unsigned Src1Reg = getRegForValue(Src1Val);
2648 bool Src1IsKill = hasTrivialKill(Src1Val);
2650 unsigned Src2Reg = getRegForValue(Src2Val);
2653 bool Src2IsKill = hasTrivialKill(Src2Val);
2659 unsigned ResultReg = fastEmitInst_rr(Opc, &AArch64::GPR32RegClass, Src1Reg,
2660 Src1IsKill, Src2Reg, Src2IsKill);
2661 updateValueMap(SI, ResultReg);
2665 bool AArch64FastISel::selectSelect(
const Instruction *I) {
2666 assert(isa<SelectInst>(I) &&
"Expected a select instruction.");
2668 if (!isTypeSupported(I->
getType(), VT))
2680 Opc = AArch64::CSELWr;
2681 RC = &AArch64::GPR32RegClass;
2684 Opc = AArch64::CSELXr;
2685 RC = &AArch64::GPR64RegClass;
2688 Opc = AArch64::FCSELSrrr;
2689 RC = &AArch64::FPR32RegClass;
2692 Opc = AArch64::FCSELDrrr;
2693 RC = &AArch64::FPR64RegClass;
2702 if (optimizeSelect(SI))
2706 if (foldXALUIntrinsic(CC, I, Cond)) {
2708 unsigned CondReg = getRegForValue(Cond);
2711 }
else if (isa<CmpInst>(Cond) && cast<CmpInst>(Cond)->hasOneUse() &&
2712 isValueAvailable(Cond)) {
2713 const auto *Cmp = cast<CmpInst>(Cond);
2716 const Value *FoldSelect =
nullptr;
2717 switch (Predicate) {
2729 unsigned SrcReg = getRegForValue(FoldSelect);
2732 unsigned UseReg = lookUpRegForValue(SI);
2734 MRI.clearKillFlags(UseReg);
2736 updateValueMap(I, SrcReg);
2741 if (!
emitCmp(Cmp->getOperand(0), Cmp->getOperand(1), Cmp->isUnsigned()))
2746 switch (Predicate) {
2760 unsigned CondReg = getRegForValue(Cond);
2763 bool CondIsKill = hasTrivialKill(Cond);
2769 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II,
2781 if (!Src1Reg || !Src2Reg)
2785 Src2Reg = fastEmitInst_rri(Opc, RC, Src1Reg, Src1IsKill, Src2Reg,
2786 Src2IsKill, ExtraCC);
2789 unsigned ResultReg = fastEmitInst_rri(Opc, RC, Src1Reg, Src1IsKill, Src2Reg,
2791 updateValueMap(I, ResultReg);
2795 bool AArch64FastISel::selectFPExt(
const Instruction *I) {
2800 unsigned Op = getRegForValue(V);
2804 unsigned ResultReg = createResultReg(&AArch64::FPR64RegClass);
2805 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::FCVTDSr),
2806 ResultReg).addReg(Op);
2807 updateValueMap(I, ResultReg);
2811 bool AArch64FastISel::selectFPTrunc(
const Instruction *I) {
2816 unsigned Op = getRegForValue(V);
2820 unsigned ResultReg = createResultReg(&AArch64::FPR32RegClass);
2821 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::FCVTSDr),
2822 ResultReg).addReg(Op);
2823 updateValueMap(I, ResultReg);
2833 unsigned SrcReg = getRegForValue(I->
getOperand(0));
2844 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZSUWDr : AArch64::FCVTZSUXDr;
2846 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZUUWDr : AArch64::FCVTZUUXDr;
2849 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZSUWSr : AArch64::FCVTZSUXSr;
2851 Opc = (DestVT ==
MVT::i32) ? AArch64::FCVTZUUWSr : AArch64::FCVTZUUXSr;
2853 unsigned ResultReg = createResultReg(
2854 DestVT ==
MVT::i32 ? &AArch64::GPR32RegClass : &AArch64::GPR64RegClass);
2855 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
2857 updateValueMap(I, ResultReg);
2861 bool AArch64FastISel::selectIntToFP(
const Instruction *I,
bool Signed) {
2870 "Unexpected value type.");
2872 unsigned SrcReg = getRegForValue(I->
getOperand(0));
2875 bool SrcIsKill = hasTrivialKill(I->
getOperand(0));
2891 Opc = (DestVT ==
MVT::f32) ? AArch64::SCVTFUXSri : AArch64::SCVTFUXDri;
2893 Opc = (DestVT ==
MVT::f32) ? AArch64::UCVTFUXSri : AArch64::UCVTFUXDri;
2896 Opc = (DestVT ==
MVT::f32) ? AArch64::SCVTFUWSri : AArch64::SCVTFUWDri;
2898 Opc = (DestVT ==
MVT::f32) ? AArch64::UCVTFUWSri : AArch64::UCVTFUWDri;
2901 unsigned ResultReg = fastEmitInst_r(Opc, TLI.getRegClassFor(DestVT), SrcReg,
2903 updateValueMap(I, ResultReg);
2907 bool AArch64FastISel::fastLowerArguments() {
2908 if (!FuncInfo.CanLowerReturn)
2920 unsigned GPRCnt = 0;
2921 unsigned FPRCnt = 0;
2922 for (
auto const &Arg : F->
args()) {
2923 if (Arg.hasAttribute(Attribute::ByVal) ||
2924 Arg.hasAttribute(Attribute::InReg) ||
2925 Arg.hasAttribute(Attribute::StructRet) ||
2926 Arg.hasAttribute(Attribute::SwiftSelf) ||
2927 Arg.hasAttribute(Attribute::SwiftError) ||
2928 Arg.hasAttribute(Attribute::Nest))
2931 Type *ArgTy = Arg.getType();
2935 EVT ArgVT = TLI.getValueType(
DL, ArgTy);
2944 (!Subtarget->hasNEON() || !Subtarget->isLittleEndian()))
2955 if (GPRCnt > 8 || FPRCnt > 8)
2959 static const MCPhysReg Registers[6][8] = {
2960 { AArch64::W0, AArch64::W1, AArch64::W2, AArch64::W3, AArch64::W4,
2961 AArch64::W5, AArch64::W6, AArch64::W7 },
2962 { AArch64::X0, AArch64::X1, AArch64::X2, AArch64::X3, AArch64::X4,
2963 AArch64::X5, AArch64::X6, AArch64::X7 },
2964 { AArch64::H0, AArch64::H1, AArch64::H2, AArch64::H3, AArch64::H4,
2965 AArch64::H5, AArch64::H6, AArch64::H7 },
2966 { AArch64::S0, AArch64::S1, AArch64::S2, AArch64::S3, AArch64::S4,
2967 AArch64::S5, AArch64::S6, AArch64::S7 },
2968 { AArch64::D0, AArch64::D1, AArch64::D2, AArch64::D3, AArch64::D4,
2969 AArch64::D5, AArch64::D6, AArch64::D7 },
2970 { AArch64::Q0, AArch64::Q1, AArch64::Q2, AArch64::Q3, AArch64::Q4,
2971 AArch64::Q5, AArch64::Q6, AArch64::Q7 }
2974 unsigned GPRIdx = 0;
2975 unsigned FPRIdx = 0;
2976 for (
auto const &Arg : F->
args()) {
2977 MVT VT = TLI.getSimpleValueType(
DL, Arg.getType());
2980 if (VT >=
MVT::i1 && VT <= MVT::i32) {
2981 SrcReg = Registers[0][GPRIdx++];
2982 RC = &AArch64::GPR32RegClass;
2985 SrcReg = Registers[1][GPRIdx++];
2986 RC = &AArch64::GPR64RegClass;
2988 SrcReg = Registers[2][FPRIdx++];
2989 RC = &AArch64::FPR16RegClass;
2991 SrcReg = Registers[3][FPRIdx++];
2992 RC = &AArch64::FPR32RegClass;
2994 SrcReg = Registers[4][FPRIdx++];
2995 RC = &AArch64::FPR64RegClass;
2997 SrcReg = Registers[5][FPRIdx++];
2998 RC = &AArch64::FPR128RegClass;
3002 unsigned DstReg = FuncInfo.MF->addLiveIn(SrcReg, RC);
3006 unsigned ResultReg = createResultReg(RC);
3007 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3008 TII.get(TargetOpcode::COPY), ResultReg)
3010 updateValueMap(&Arg, ResultReg);
3015 bool AArch64FastISel::processCallArgs(CallLoweringInfo &CLI,
3017 unsigned &NumBytes) {
3021 CCInfo.AnalyzeCallOperands(OutVTs, CLI.OutFlags, CCAssignFnForCall(CC));
3024 NumBytes = CCInfo.getNextStackOffset();
3027 unsigned AdjStackDown =
TII.getCallFrameSetupOpcode();
3028 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AdjStackDown))
3029 .addImm(NumBytes).
addImm(0);
3033 const Value *ArgVal = CLI.OutVals[VA.getValNo()];
3034 MVT ArgVT = OutVTs[VA.getValNo()];
3036 unsigned ArgReg = getRegForValue(ArgVal);
3041 switch (VA.getLocInfo()) {
3045 MVT DestVT = VA.getLocVT();
3047 ArgReg = emitIntExt(SrcVT, ArgReg, DestVT,
false);
3055 MVT DestVT = VA.getLocVT();
3057 ArgReg = emitIntExt(SrcVT, ArgReg, DestVT,
true);
3067 if (VA.isRegLoc() && !VA.needsCustom()) {
3068 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3069 TII.get(TargetOpcode::COPY), VA.getLocReg()).addReg(ArgReg);
3070 CLI.OutRegs.push_back(VA.getLocReg());
3071 }
else if (VA.needsCustom()) {
3075 assert(VA.isMemLoc() &&
"Assuming store on stack.");
3078 if (isa<UndefValue>(ArgVal))
3084 unsigned BEAlign = 0;
3085 if (ArgSize < 8 && !Subtarget->isLittleEndian())
3086 BEAlign = 8 - ArgSize;
3089 Addr.setKind(Address::RegBase);
3090 Addr.setReg(AArch64::SP);
3091 Addr.setOffset(VA.getLocMemOffset() + BEAlign);
3098 if (!emitStore(ArgVT, ArgReg, Addr, MMO))
3105 bool AArch64FastISel::finishCall(CallLoweringInfo &CLI,
MVT RetVT,
3106 unsigned NumBytes) {
3110 unsigned AdjStackUp =
TII.getCallFrameDestroyOpcode();
3111 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AdjStackUp))
3112 .addImm(NumBytes).
addImm(0);
3118 CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC));
3121 if (RVLocs.
size() != 1)
3125 MVT CopyVT = RVLocs[0].getValVT();
3128 if (CopyVT.
isVector() && !Subtarget->isLittleEndian())
3131 unsigned ResultReg = createResultReg(TLI.getRegClassFor(CopyVT));
3132 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3133 TII.get(TargetOpcode::COPY), ResultReg)
3134 .addReg(RVLocs[0].getLocReg());
3135 CLI.InRegs.push_back(RVLocs[0].getLocReg());
3137 CLI.ResultReg = ResultReg;
3138 CLI.NumResultRegs = 1;
3144 bool AArch64FastISel::fastLowerCall(CallLoweringInfo &CLI) {
3146 bool IsTailCall = CLI.IsTailCall;
3147 bool IsVarArg = CLI.IsVarArg;
3148 const Value *Callee = CLI.Callee;
3151 if (!Callee && !Symbol)
3173 if (CLI.RetTy->isVoidTy())
3175 else if (!isTypeLegal(CLI.RetTy, RetVT))
3178 for (
auto Flag : CLI.OutFlags)
3180 Flag.isSwiftSelf() ||
Flag.isSwiftError())
3185 OutVTs.
reserve(CLI.OutVals.size());
3187 for (
auto *Val : CLI.OutVals) {
3189 if (!isTypeLegal(Val->getType(), VT) &&
3201 if (Callee && !computeCallAddress(Callee, Addr))
3206 if (!processCallArgs(CLI, OutVTs, NumBytes))
3211 if (Subtarget->useSmallAddressing()) {
3212 const MCInstrDesc &II =
TII.get(Addr.getReg() ? AArch64::BLR : AArch64::BL);
3213 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II);
3216 else if (Addr.getGlobalValue())
3218 else if (Addr.getReg()) {
3224 unsigned CallReg = 0;
3226 unsigned ADRPReg = createResultReg(&AArch64::GPR64commonRegClass);
3231 CallReg = createResultReg(&AArch64::GPR64RegClass);
3232 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3233 TII.get(AArch64::LDRXui), CallReg)
3237 }
else if (Addr.getGlobalValue())
3238 CallReg = materializeGV(Addr.getGlobalValue());
3239 else if (Addr.getReg())
3240 CallReg = Addr.getReg();
3247 MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II).
addReg(CallReg);
3251 for (
auto Reg : CLI.OutRegs)
3256 MIB.
addRegMask(TRI.getCallPreservedMask(*FuncInfo.MF, CC));
3261 return finishCall(CLI, RetVT, NumBytes);
3264 bool AArch64FastISel::isMemCpySmall(uint64_t Len,
unsigned Alignment) {
3266 return Len / Alignment <= 4;
3271 bool AArch64FastISel::tryEmitSmallMemCpy(
Address Dest,
Address Src,
3272 uint64_t Len,
unsigned Alignment) {
3274 if (!isMemCpySmall(Len, Alignment))
3277 int64_t UnscaledOffset = 0;
3283 if (!Alignment || Alignment >= 8) {
3295 if (Len >= 4 && Alignment == 4)
3297 else if (Len >= 2 && Alignment == 2)
3304 unsigned ResultReg = emitLoad(VT, VT, Src);
3308 if (!emitStore(VT, ResultReg, Dest))
3313 UnscaledOffset +=
Size;
3316 Dest.setOffset(OrigDest.getOffset() + UnscaledOffset);
3317 Src.setOffset(OrigSrc.getOffset() + UnscaledOffset);
3327 const Value *Cond) {
3328 if (!isa<ExtractValueInst>(Cond))
3331 const auto *EV = cast<ExtractValueInst>(Cond);
3332 if (!isa<IntrinsicInst>(EV->getAggregateOperand()))
3335 const auto *II = cast<IntrinsicInst>(EV->getAggregateOperand());
3337 const Function *Callee = II->getCalledFunction();
3339 cast<StructType>(Callee->
getReturnType())->getTypeAtIndex(0U);
3340 if (!isTypeLegal(RetTy, RetVT))
3343 if (RetVT != MVT::i32 && RetVT !=
MVT::i64)
3346 const Value *LHS = II->getArgOperand(0);
3347 const Value *RHS = II->getArgOperand(1);
3350 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS) &&
3351 isCommutativeIntrinsic(II))
3359 case Intrinsic::smul_with_overflow:
3360 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3361 if (C->getValue() == 2)
3362 IID = Intrinsic::sadd_with_overflow;
3364 case Intrinsic::umul_with_overflow:
3365 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3366 if (C->getValue() == 2)
3367 IID = Intrinsic::uadd_with_overflow;
3375 case Intrinsic::sadd_with_overflow:
3376 case Intrinsic::ssub_with_overflow:
3379 case Intrinsic::uadd_with_overflow:
3382 case Intrinsic::usub_with_overflow:
3385 case Intrinsic::smul_with_overflow:
3386 case Intrinsic::umul_with_overflow:
3392 if (!isValueAvailable(II))
3398 for (
auto Itr = std::prev(Start); Itr !=
End; --Itr) {
3401 if (!isa<ExtractValueInst>(Itr))
3405 const auto *EVI = cast<ExtractValueInst>(Itr);
3406 if (EVI->getAggregateOperand() != II)
3414 bool AArch64FastISel::fastLowerIntrinsicCall(
const IntrinsicInst *II) {
3417 default:
return false;
3418 case Intrinsic::frameaddress: {
3424 unsigned SrcReg =
MRI.createVirtualRegister(&AArch64::GPR64RegClass);
3425 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3426 TII.get(TargetOpcode::COPY), SrcReg).addReg(FramePtr);
3433 unsigned Depth = cast<ConstantInt>(II->
getOperand(0))->getZExtValue();
3435 DestReg = fastEmitInst_ri(AArch64::LDRXui, &AArch64::GPR64RegClass,
3437 assert(DestReg &&
"Unexpected LDR instruction emission failure.");
3441 updateValueMap(II, SrcReg);
3444 case Intrinsic::memcpy:
3445 case Intrinsic::memmove: {
3446 const auto *MTI = cast<MemTransferInst>(II);
3448 if (MTI->isVolatile())
3454 if (isa<ConstantInt>(MTI->getLength()) && IsMemCpy) {
3457 uint64_t Len = cast<ConstantInt>(MTI->getLength())->getZExtValue();
3458 unsigned Alignment = MTI->getAlignment();
3459 if (isMemCpySmall(Len, Alignment)) {
3461 if (!computeAddress(MTI->getRawDest(), Dest) ||
3462 !computeAddress(MTI->getRawSource(), Src))
3464 if (tryEmitSmallMemCpy(Dest, Src, Len, Alignment))
3469 if (!MTI->getLength()->getType()->isIntegerTy(64))
3472 if (MTI->getSourceAddressSpace() > 255 || MTI->getDestAddressSpace() > 255)
3477 const char *IntrMemName = isa<MemCpyInst>(II) ?
"memcpy" :
"memmove";
3480 case Intrinsic::memset: {
3481 const MemSetInst *MSI = cast<MemSetInst>(II);
3496 case Intrinsic::sin:
3497 case Intrinsic::cos:
3498 case Intrinsic::pow: {
3500 if (!isTypeLegal(II->
getType(), RetVT))
3516 case Intrinsic::sin:
3517 LC = LibCallTable[0][Is64Bit];
3519 case Intrinsic::cos:
3520 LC = LibCallTable[1][Is64Bit];
3522 case Intrinsic::pow:
3523 LC = LibCallTable[2][Is64Bit];
3534 Entry.Ty = Arg->getType();
3535 Args.push_back(Entry);
3538 CallLoweringInfo CLI;
3540 CLI.setCallee(
DL, Ctx, TLI.getLibcallCallingConv(LC), II->
getType(),
3541 TLI.getLibcallName(LC), std::move(Args));
3542 if (!lowerCallTo(CLI))
3544 updateValueMap(II, CLI.ResultReg);
3547 case Intrinsic::fabs: {
3549 if (!isTypeLegal(II->
getType(), VT))
3557 Opc = AArch64::FABSSr;
3560 Opc = AArch64::FABSDr;
3563 unsigned SrcReg = getRegForValue(II->
getOperand(0));
3566 bool SrcRegIsKill = hasTrivialKill(II->
getOperand(0));
3567 unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
3568 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
3570 updateValueMap(II, ResultReg);
3573 case Intrinsic::trap:
3574 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::BRK))
3578 case Intrinsic::sqrt: {
3582 if (!isTypeLegal(RetTy, VT))
3585 unsigned Op0Reg = getRegForValue(II->
getOperand(0));
3588 bool Op0IsKill = hasTrivialKill(II->
getOperand(0));
3590 unsigned ResultReg = fastEmit_r(VT, VT,
ISD::FSQRT, Op0Reg, Op0IsKill);
3594 updateValueMap(II, ResultReg);
3597 case Intrinsic::sadd_with_overflow:
3598 case Intrinsic::uadd_with_overflow:
3599 case Intrinsic::ssub_with_overflow:
3600 case Intrinsic::usub_with_overflow:
3601 case Intrinsic::smul_with_overflow:
3602 case Intrinsic::umul_with_overflow: {
3606 Type *RetTy = Ty->getTypeAtIndex(0U);
3609 if (!isTypeLegal(RetTy, VT))
3612 if (VT != MVT::i32 && VT !=
MVT::i64)
3618 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS) &&
3619 isCommutativeIntrinsic(II))
3627 case Intrinsic::smul_with_overflow:
3628 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3629 if (C->getValue() == 2) {
3630 IID = Intrinsic::sadd_with_overflow;
3634 case Intrinsic::umul_with_overflow:
3635 if (
const auto *C = dyn_cast<ConstantInt>(RHS))
3636 if (C->getValue() == 2) {
3637 IID = Intrinsic::uadd_with_overflow;
3643 unsigned ResultReg1 = 0, ResultReg2 = 0, MulReg = 0;
3647 case Intrinsic::sadd_with_overflow:
3648 ResultReg1 = emitAdd(VT, LHS, RHS,
true);
3651 case Intrinsic::uadd_with_overflow:
3652 ResultReg1 = emitAdd(VT, LHS, RHS,
true);
3655 case Intrinsic::ssub_with_overflow:
3656 ResultReg1 = emitSub(VT, LHS, RHS,
true);
3659 case Intrinsic::usub_with_overflow:
3660 ResultReg1 = emitSub(VT, LHS, RHS,
true);
3663 case Intrinsic::smul_with_overflow: {
3665 unsigned LHSReg = getRegForValue(LHS);
3668 bool LHSIsKill = hasTrivialKill(LHS);
3670 unsigned RHSReg = getRegForValue(RHS);
3673 bool RHSIsKill = hasTrivialKill(RHS);
3675 if (VT == MVT::i32) {
3676 MulReg = emitSMULL_rr(
MVT::i64, LHSReg, LHSIsKill, RHSReg, RHSIsKill);
3679 MulReg = fastEmitInst_extractsubreg(VT, MulReg,
true,
3681 ShiftReg = fastEmitInst_extractsubreg(VT, ShiftReg,
true,
3683 emitSubs_rs(VT, ShiftReg,
true, MulReg,
false,
3689 MulReg = emitMul_rr(VT, LHSReg,
false, RHSReg,
3691 unsigned SMULHReg = fastEmit_rr(VT, VT,
ISD::MULHS, LHSReg, LHSIsKill,
3693 emitSubs_rs(VT, SMULHReg,
true, MulReg,
false,
3698 case Intrinsic::umul_with_overflow: {
3700 unsigned LHSReg = getRegForValue(LHS);
3703 bool LHSIsKill = hasTrivialKill(LHS);
3705 unsigned RHSReg = getRegForValue(RHS);
3708 bool RHSIsKill = hasTrivialKill(RHS);
3710 if (VT == MVT::i32) {
3711 MulReg = emitUMULL_rr(
MVT::i64, LHSReg, LHSIsKill, RHSReg, RHSIsKill);
3712 emitSubs_rs(
MVT::i64, AArch64::XZR,
true, MulReg,
3715 MulReg = fastEmitInst_extractsubreg(VT, MulReg,
true,
3721 MulReg = emitMul_rr(VT, LHSReg,
false, RHSReg,
3723 unsigned UMULHReg = fastEmit_rr(VT, VT,
ISD::MULHU, LHSReg, LHSIsKill,
3725 emitSubs_rr(VT, AArch64::XZR,
true, UMULHReg,
3733 ResultReg1 = createResultReg(TLI.getRegClassFor(VT));
3734 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3735 TII.get(TargetOpcode::COPY), ResultReg1).addReg(MulReg);
3738 ResultReg2 = fastEmitInst_rri(AArch64::CSINCWr, &AArch64::GPR32RegClass,
3739 AArch64::WZR,
true, AArch64::WZR,
3742 assert((ResultReg1 + 1) == ResultReg2 &&
3743 "Nonconsecutive result registers.");
3744 updateValueMap(II, ResultReg1, 2);
3751 bool AArch64FastISel::selectRet(
const Instruction *I) {
3755 if (!FuncInfo.CanLowerReturn)
3761 if (TLI.supportSwiftError() &&
3762 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError))
3765 if (TLI.supportSplitCSR(FuncInfo.MF))
3780 : RetCC_AArch64_AAPCS;
3781 CCInfo.AnalyzeReturn(Outs, RetCC);
3784 if (ValLocs.size() != 1)
3799 unsigned Reg = getRegForValue(RV);
3803 unsigned SrcReg = Reg + VA.
getValNo();
3806 if (!
MRI.getRegClass(SrcReg)->contains(DestReg))
3809 EVT RVEVT = TLI.getValueType(
DL, RV->
getType());
3815 !Subtarget->isLittleEndian())
3824 if (RVVT != DestVT) {
3828 if (!Outs[0].Flags.isZExt() && !Outs[0].Flags.isSExt())
3831 bool IsZExt = Outs[0].Flags.isZExt();
3832 SrcReg = emitIntExt(RVVT, SrcReg, DestVT, IsZExt);
3838 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3839 TII.get(TargetOpcode::COPY), DestReg).addReg(SrcReg);
3846 TII.get(AArch64::RET_ReallyLR));
3847 for (
unsigned RetReg : RetRegs)
3852 bool AArch64FastISel::selectTrunc(
const Instruction *I) {
3857 EVT SrcEVT = TLI.getValueType(
DL, SrcTy,
true);
3858 EVT DestEVT = TLI.getValueType(
DL, DestTy,
true);
3874 unsigned SrcReg = getRegForValue(Op);
3877 bool SrcIsKill = hasTrivialKill(Op);
3902 unsigned Reg32 = fastEmitInst_extractsubreg(MVT::i32, SrcReg, SrcIsKill,
3905 ResultReg = emitAnd_ri(MVT::i32, Reg32,
true, Mask);
3906 assert(ResultReg &&
"Unexpected AND instruction emission failure.");
3908 ResultReg = createResultReg(&AArch64::GPR32RegClass);
3909 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3910 TII.get(TargetOpcode::COPY), ResultReg)
3914 updateValueMap(I, ResultReg);
3918 unsigned AArch64FastISel::emiti1Ext(
unsigned SrcReg,
MVT DestVT,
bool IsZExt) {
3921 "Unexpected value type.");
3927 unsigned ResultReg = emitAnd_ri(MVT::i32, SrcReg,
false, 1);
3928 assert(ResultReg &&
"Unexpected AND instruction emission failure.");
3932 unsigned Reg64 =
MRI.createVirtualRegister(&AArch64::GPR64RegClass);
3933 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
3934 TII.get(AArch64::SUBREG_TO_REG), Reg64)
3937 .
addImm(AArch64::sub_32);
3946 return fastEmitInst_rii(AArch64::SBFMWri, &AArch64::GPR32RegClass, SrcReg,
3951 unsigned AArch64FastISel::emitMul_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
3952 unsigned Op1,
bool Op1IsKill) {
3960 Opc = AArch64::MADDWrrr; ZReg = AArch64::WZR;
break;
3962 Opc = AArch64::MADDXrrr; ZReg = AArch64::XZR;
break;
3966 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
3967 return fastEmitInst_rrr(Opc, RC, Op0, Op0IsKill, Op1, Op1IsKill,
3971 unsigned AArch64FastISel::emitSMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
3972 unsigned Op1,
bool Op1IsKill) {
3976 return fastEmitInst_rrr(AArch64::SMADDLrrr, &AArch64::GPR64RegClass,
3977 Op0, Op0IsKill, Op1, Op1IsKill,
3978 AArch64::XZR,
true);
3981 unsigned AArch64FastISel::emitUMULL_rr(
MVT RetVT,
unsigned Op0,
bool Op0IsKill,
3982 unsigned Op1,
bool Op1IsKill) {
3986 return fastEmitInst_rrr(AArch64::UMADDLrrr, &AArch64::GPR64RegClass,
3987 Op0, Op0IsKill, Op1, Op1IsKill,
3988 AArch64::XZR,
true);
3991 unsigned AArch64FastISel::emitLSL_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
3992 unsigned Op1Reg,
bool Op1IsKill) {
3994 bool NeedTrunc =
false;
3998 case MVT::i8: Opc = AArch64::LSLVWr; NeedTrunc =
true; Mask = 0xff;
break;
3999 case MVT::i16: Opc = AArch64::LSLVWr; NeedTrunc =
true; Mask = 0xffff;
break;
4000 case MVT::i32: Opc = AArch64::LSLVWr;
break;
4001 case MVT::i64: Opc = AArch64::LSLVXr;
break;
4005 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4007 Op1Reg = emitAnd_ri(MVT::i32, Op1Reg, Op1IsKill, Mask);
4010 unsigned ResultReg = fastEmitInst_rr(Opc, RC, Op0Reg, Op0IsKill, Op1Reg,
4013 ResultReg = emitAnd_ri(MVT::i32, ResultReg,
true, Mask);
4017 unsigned AArch64FastISel::emitLSL_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0,
4018 bool Op0IsKill, uint64_t Shift,
4021 "Unexpected source/return type pair.");
4023 SrcVT == MVT::i32 || SrcVT ==
MVT::i64) &&
4024 "Unexpected source value type.");
4026 RetVT ==
MVT::i64) &&
"Unexpected return value type.");
4028 bool Is64Bit = (RetVT ==
MVT::i64);
4029 unsigned RegSize = Is64Bit ? 64 : 32;
4033 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4037 if (RetVT == SrcVT) {
4038 unsigned ResultReg = createResultReg(RC);
4039 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4040 TII.get(TargetOpcode::COPY), ResultReg)
4044 return emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4048 if (Shift >= DstBits)
4076 unsigned ImmR = RegSize - Shift;
4078 unsigned ImmS = std::min<unsigned>(SrcBits - 1, DstBits - 1 - Shift);
4079 static const unsigned OpcTable[2][2] = {
4080 {AArch64::SBFMWri, AArch64::SBFMXri},
4081 {AArch64::UBFMWri, AArch64::UBFMXri}
4083 unsigned Opc = OpcTable[IsZExt][Is64Bit];
4085 unsigned TmpReg =
MRI.createVirtualRegister(RC);
4086 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4087 TII.get(AArch64::SUBREG_TO_REG), TmpReg)
4090 .
addImm(AArch64::sub_32);
4094 return fastEmitInst_rii(Opc, RC, Op0, Op0IsKill, ImmR, ImmS);
4097 unsigned AArch64FastISel::emitLSR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
4098 unsigned Op1Reg,
bool Op1IsKill) {
4100 bool NeedTrunc =
false;
4104 case MVT::i8: Opc = AArch64::LSRVWr; NeedTrunc =
true; Mask = 0xff;
break;
4105 case MVT::i16: Opc = AArch64::LSRVWr; NeedTrunc =
true; Mask = 0xffff;
break;
4106 case MVT::i32: Opc = AArch64::LSRVWr;
break;
4107 case MVT::i64: Opc = AArch64::LSRVXr;
break;
4111 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4113 Op0Reg = emitAnd_ri(MVT::i32, Op0Reg, Op0IsKill, Mask);
4114 Op1Reg = emitAnd_ri(MVT::i32, Op1Reg, Op1IsKill, Mask);
4115 Op0IsKill = Op1IsKill =
true;
4117 unsigned ResultReg = fastEmitInst_rr(Opc, RC, Op0Reg, Op0IsKill, Op1Reg,
4120 ResultReg = emitAnd_ri(MVT::i32, ResultReg,
true, Mask);
4124 unsigned AArch64FastISel::emitLSR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0,
4125 bool Op0IsKill, uint64_t Shift,
4128 "Unexpected source/return type pair.");
4130 SrcVT == MVT::i32 || SrcVT ==
MVT::i64) &&
4131 "Unexpected source value type.");
4133 RetVT ==
MVT::i64) &&
"Unexpected return value type.");
4135 bool Is64Bit = (RetVT ==
MVT::i64);
4136 unsigned RegSize = Is64Bit ? 64 : 32;
4140 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4144 if (RetVT == SrcVT) {
4145 unsigned ResultReg = createResultReg(RC);
4146 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4147 TII.get(TargetOpcode::COPY), ResultReg)
4151 return emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4155 if (Shift >= DstBits)
4183 if (Shift >= SrcBits && IsZExt)
4189 Op0 = emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4198 unsigned ImmR = std::min<unsigned>(SrcBits - 1, Shift);
4199 unsigned ImmS = SrcBits - 1;
4200 static const unsigned OpcTable[2][2] = {
4201 {AArch64::SBFMWri, AArch64::SBFMXri},
4202 {AArch64::UBFMWri, AArch64::UBFMXri}
4204 unsigned Opc = OpcTable[IsZExt][Is64Bit];
4206 unsigned TmpReg =
MRI.createVirtualRegister(RC);
4207 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4208 TII.get(AArch64::SUBREG_TO_REG), TmpReg)
4211 .
addImm(AArch64::sub_32);
4215 return fastEmitInst_rii(Opc, RC, Op0, Op0IsKill, ImmR, ImmS);
4218 unsigned AArch64FastISel::emitASR_rr(
MVT RetVT,
unsigned Op0Reg,
bool Op0IsKill,
4219 unsigned Op1Reg,
bool Op1IsKill) {
4221 bool NeedTrunc =
false;
4225 case MVT::i8: Opc = AArch64::ASRVWr; NeedTrunc =
true; Mask = 0xff;
break;
4226 case MVT::i16: Opc = AArch64::ASRVWr; NeedTrunc =
true; Mask = 0xffff;
break;
4227 case MVT::i32: Opc = AArch64::ASRVWr;
break;
4228 case MVT::i64: Opc = AArch64::ASRVXr;
break;
4232 (RetVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4234 Op0Reg = emitIntExt(RetVT, Op0Reg, MVT::i32,
false);
4235 Op1Reg = emitAnd_ri(MVT::i32, Op1Reg, Op1IsKill, Mask);
4236 Op0IsKill = Op1IsKill =
true;
4238 unsigned ResultReg = fastEmitInst_rr(Opc, RC, Op0Reg, Op0IsKill, Op1Reg,
4241 ResultReg = emitAnd_ri(MVT::i32, ResultReg,
true, Mask);
4245 unsigned AArch64FastISel::emitASR_ri(
MVT RetVT,
MVT SrcVT,
unsigned Op0,
4246 bool Op0IsKill, uint64_t Shift,
4249 "Unexpected source/return type pair.");
4251 SrcVT == MVT::i32 || SrcVT ==
MVT::i64) &&
4252 "Unexpected source value type.");
4254 RetVT ==
MVT::i64) &&
"Unexpected return value type.");
4256 bool Is64Bit = (RetVT ==
MVT::i64);
4257 unsigned RegSize = Is64Bit ? 64 : 32;
4261 Is64Bit ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4265 if (RetVT == SrcVT) {
4266 unsigned ResultReg = createResultReg(RC);
4267 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4268 TII.get(TargetOpcode::COPY), ResultReg)
4272 return emitIntExt(SrcVT, Op0, RetVT, IsZExt);
4276 if (Shift >= DstBits)
4304 if (Shift >= SrcBits && IsZExt)
4307 unsigned ImmR = std::min<unsigned>(SrcBits - 1, Shift);
4308 unsigned ImmS = SrcBits - 1;
4309 static const unsigned OpcTable[2][2] = {
4310 {AArch64::SBFMWri, AArch64::SBFMXri},
4311 {AArch64::UBFMWri, AArch64::UBFMXri}
4313 unsigned Opc = OpcTable[IsZExt][Is64Bit];
4315 unsigned TmpReg =
MRI.createVirtualRegister(RC);
4316 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4317 TII.get(AArch64::SUBREG_TO_REG), TmpReg)
4320 .
addImm(AArch64::sub_32);
4324 return fastEmitInst_rii(Opc, RC, Op0, Op0IsKill, ImmR, ImmS);
4327 unsigned AArch64FastISel::emitIntExt(
MVT SrcVT,
unsigned SrcReg,
MVT DestVT,
4336 (DestVT != MVT::i32) && (DestVT !=
MVT::i64)) ||
4338 (SrcVT !=
MVT::i16) && (SrcVT != MVT::i32)))
4348 return emiti1Ext(SrcReg, DestVT, IsZExt);
4351 Opc = IsZExt ? AArch64::UBFMXri : AArch64::SBFMXri;
4353 Opc = IsZExt ? AArch64::UBFMWri : AArch64::SBFMWri;
4358 Opc = IsZExt ? AArch64::UBFMXri : AArch64::SBFMXri;
4360 Opc = IsZExt ? AArch64::UBFMWri : AArch64::SBFMWri;
4365 Opc = IsZExt ? AArch64::UBFMXri : AArch64::SBFMXri;
4374 unsigned Src64 =
MRI.createVirtualRegister(&AArch64::GPR64RegClass);
4375 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4376 TII.get(AArch64::SUBREG_TO_REG), Src64)
4379 .
addImm(AArch64::sub_32);
4384 (DestVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4385 return fastEmitInst_rii(Opc, RC, SrcReg,
false, 0, Imm);
4392 case AArch64::LDURBBi:
4393 case AArch64::LDURHHi:
4394 case AArch64::LDURWi:
4395 case AArch64::LDRBBui:
4396 case AArch64::LDRHHui:
4397 case AArch64::LDRWui:
4398 case AArch64::LDRBBroX:
4399 case AArch64::LDRHHroX:
4400 case AArch64::LDRWroX:
4401 case AArch64::LDRBBroW:
4402 case AArch64::LDRHHroW:
4403 case AArch64::LDRWroW:
4412 case AArch64::LDURSBWi:
4413 case AArch64::LDURSHWi:
4414 case AArch64::LDURSBXi:
4415 case AArch64::LDURSHXi:
4416 case AArch64::LDURSWi:
4417 case AArch64::LDRSBWui:
4418 case AArch64::LDRSHWui:
4419 case AArch64::LDRSBXui:
4420 case AArch64::LDRSHXui:
4421 case AArch64::LDRSWui:
4422 case AArch64::LDRSBWroX:
4423 case AArch64::LDRSHWroX:
4424 case AArch64::LDRSBXroX:
4425 case AArch64::LDRSHXroX:
4426 case AArch64::LDRSWroX:
4427 case AArch64::LDRSBWroW:
4428 case AArch64::LDRSHWroW:
4429 case AArch64::LDRSBXroW:
4430 case AArch64::LDRSHXroW:
4431 case AArch64::LDRSWroW:
4436 bool AArch64FastISel::optimizeIntExtLoad(
const Instruction *I,
MVT RetVT,
4439 if (!LI || !LI->hasOneUse())
4443 unsigned Reg = lookUpRegForValue(LI);
4453 bool IsZExt = isa<ZExtInst>(
I);
4454 const auto *LoadMI =
MI;
4455 if (LoadMI->getOpcode() == TargetOpcode::COPY &&
4456 LoadMI->getOperand(1).getSubReg() == AArch64::sub_32) {
4458 LoadMI =
MRI.getUniqueVRegDef(LoadReg);
4459 assert(LoadMI &&
"Expected valid instruction");
4465 if (RetVT !=
MVT::i64 || SrcVT > MVT::i32) {
4466 updateValueMap(I, Reg);
4471 unsigned Reg64 = createResultReg(&AArch64::GPR64RegClass);
4472 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4473 TII.get(AArch64::SUBREG_TO_REG), Reg64)
4476 .
addImm(AArch64::sub_32);
4481 "Expected copy instruction");
4485 updateValueMap(I, Reg);
4489 bool AArch64FastISel::selectIntExt(
const Instruction *I) {
4490 assert((isa<ZExtInst>(I) || isa<SExtInst>(I)) &&
4491 "Unexpected integer extend instruction.");
4494 if (!isTypeSupported(I->
getType(), RetVT))
4501 if (optimizeIntExtLoad(I, RetVT, SrcVT))
4504 unsigned SrcReg = getRegForValue(I->
getOperand(0));
4507 bool SrcIsKill = hasTrivialKill(I->
getOperand(0));
4510 bool IsZExt = isa<ZExtInst>(
I);
4511 if (
const auto *Arg = dyn_cast<Argument>(I->
getOperand(0))) {
4512 if ((IsZExt && Arg->hasZExtAttr()) || (!IsZExt && Arg->hasSExtAttr())) {
4514 unsigned ResultReg = createResultReg(&AArch64::GPR64RegClass);
4515 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
4516 TII.get(AArch64::SUBREG_TO_REG), ResultReg)
4519 .
addImm(AArch64::sub_32);
4526 unsigned UseReg = lookUpRegForValue(I);
4528 MRI.clearKillFlags(UseReg);
4530 updateValueMap(I, SrcReg);
4535 unsigned ResultReg = emitIntExt(SrcVT, SrcReg, RetVT, IsZExt);
4539 updateValueMap(I, ResultReg);
4543 bool AArch64FastISel::selectRem(
const Instruction *I,
unsigned ISDOpcode) {
4544 EVT DestEVT = TLI.getValueType(
DL, I->
getType(),
true);
4549 if (DestVT !=
MVT::i64 && DestVT != MVT::i32)
4553 bool Is64bit = (DestVT ==
MVT::i64);
4554 switch (ISDOpcode) {
4558 DivOpc = Is64bit ? AArch64::SDIVXr : AArch64::SDIVWr;
4561 DivOpc = Is64bit ? AArch64::UDIVXr : AArch64::UDIVWr;
4564 unsigned MSubOpc = Is64bit ? AArch64::MSUBXrrr : AArch64::MSUBWrrr;
4565 unsigned Src0Reg = getRegForValue(I->
getOperand(0));
4568 bool Src0IsKill = hasTrivialKill(I->
getOperand(0));
4570 unsigned Src1Reg = getRegForValue(I->
getOperand(1));
4573 bool Src1IsKill = hasTrivialKill(I->
getOperand(1));
4576 (DestVT ==
MVT::i64) ? &AArch64::GPR64RegClass : &AArch64::GPR32RegClass;
4577 unsigned QuotReg = fastEmitInst_rr(DivOpc, RC, Src0Reg,
false,
4579 assert(QuotReg &&
"Unexpected DIV instruction emission failure.");
4582 unsigned ResultReg = fastEmitInst_rrr(MSubOpc, RC, QuotReg,
true,
4583 Src1Reg, Src1IsKill, Src0Reg,
4585 updateValueMap(I, ResultReg);
4589 bool AArch64FastISel::selectMul(
const Instruction *I) {
4591 if (!isTypeSupported(I->
getType(), VT,
true))
4599 if (
const auto *C = dyn_cast<ConstantInt>(Src0))
4600 if (C->getValue().isPowerOf2())
4604 if (
const auto *C = dyn_cast<ConstantInt>(Src1))
4605 if (C->getValue().isPowerOf2()) {
4606 uint64_t ShiftVal = C->getValue().logBase2();
4609 if (
const auto *ZExt = dyn_cast<ZExtInst>(Src0)) {
4612 if (isValueAvailable(ZExt) && isTypeSupported(ZExt->getSrcTy(), VT)) {
4615 Src0 = ZExt->getOperand(0);
4618 }
else if (
const auto *SExt = dyn_cast<SExtInst>(Src0)) {
4621 if (isValueAvailable(SExt) && isTypeSupported(SExt->getSrcTy(), VT)) {
4624 Src0 = SExt->getOperand(0);
4629 unsigned Src0Reg = getRegForValue(Src0);
4632 bool Src0IsKill = hasTrivialKill(Src0);
4634 unsigned ResultReg =
4635 emitLSL_ri(VT, SrcVT, Src0Reg, Src0IsKill, ShiftVal, IsZExt);
4638 updateValueMap(I, ResultReg);
4643 unsigned Src0Reg = getRegForValue(I->
getOperand(0));
4646 bool Src0IsKill = hasTrivialKill(I->
getOperand(0));
4648 unsigned Src1Reg = getRegForValue(I->
getOperand(1));
4651 bool Src1IsKill = hasTrivialKill(I->
getOperand(1));
4653 unsigned ResultReg = emitMul_rr(VT, Src0Reg, Src0IsKill, Src1Reg, Src1IsKill);
4658 updateValueMap(I, ResultReg);
4662 bool AArch64FastISel::selectShift(
const Instruction *I) {
4664 if (!isTypeSupported(I->
getType(), RetVT,
true))
4668 return selectOperator(I, I->
getOpcode());
4670 if (
const auto *C = dyn_cast<ConstantInt>(I->
getOperand(1))) {
4671 unsigned ResultReg = 0;
4672 uint64_t ShiftVal = C->getZExtValue();
4674 bool IsZExt = I->
getOpcode() != Instruction::AShr;
4676 if (
const auto *ZExt = dyn_cast<ZExtInst>(Op0)) {
4679 if (isValueAvailable(ZExt) && isTypeSupported(ZExt->getSrcTy(), TmpVT)) {
4682 Op0 = ZExt->getOperand(0);
4685 }
else if (
const auto *SExt = dyn_cast<SExtInst>(Op0)) {
4688 if (isValueAvailable(SExt) && isTypeSupported(SExt->getSrcTy(), TmpVT)) {
4691 Op0 = SExt->getOperand(0);
4696 unsigned Op0Reg = getRegForValue(Op0);
4699 bool Op0IsKill = hasTrivialKill(Op0);
4703 case Instruction::Shl:
4704 ResultReg = emitLSL_ri(RetVT, SrcVT, Op0Reg, Op0IsKill, ShiftVal, IsZExt);
4706 case Instruction::AShr:
4707 ResultReg = emitASR_ri(RetVT, SrcVT, Op0Reg, Op0IsKill, ShiftVal, IsZExt);
4709 case Instruction::LShr:
4710 ResultReg = emitLSR_ri(RetVT, SrcVT, Op0Reg, Op0IsKill, ShiftVal, IsZExt);
4716 updateValueMap(I, ResultReg);
4720 unsigned Op0Reg = getRegForValue(I->
getOperand(0));
4723 bool Op0IsKill = hasTrivialKill(I->
getOperand(0));
4725 unsigned Op1Reg = getRegForValue(I->
getOperand(1));
4728 bool Op1IsKill = hasTrivialKill(I->
getOperand(1));
4730 unsigned ResultReg = 0;
4733 case Instruction::Shl:
4734 ResultReg = emitLSL_rr(RetVT, Op0Reg, Op0IsKill, Op1Reg, Op1IsKill);
4736 case Instruction::AShr:
4737 ResultReg = emitASR_rr(RetVT, Op0Reg, Op0IsKill, Op1Reg, Op1IsKill);
4739 case Instruction::LShr:
4740 ResultReg = emitLSR_rr(RetVT, Op0Reg, Op0IsKill, Op1Reg, Op1IsKill);
4747 updateValueMap(I, ResultReg);
4751 bool AArch64FastISel::selectBitCast(
const Instruction *I) {
4756 if (!isTypeLegal(I->
getType(), RetVT))
4760 if (RetVT ==
MVT::f32 && SrcVT == MVT::i32)
4761 Opc = AArch64::FMOVWSr;
4763 Opc = AArch64::FMOVXDr;
4764 else if (RetVT == MVT::i32 && SrcVT ==
MVT::f32)
4765 Opc = AArch64::FMOVSWr;
4767 Opc = AArch64::FMOVDXr;
4774 case MVT::i32: RC = &AArch64::GPR32RegClass;
break;
4775 case MVT::i64: RC = &AArch64::GPR64RegClass;
break;
4776 case MVT::f32: RC = &AArch64::FPR32RegClass;
break;
4777 case MVT::f64: RC = &AArch64::FPR64RegClass;
break;
4779 unsigned Op0Reg = getRegForValue(I->
getOperand(0));
4782 bool Op0IsKill = hasTrivialKill(I->
getOperand(0));
4783 unsigned ResultReg = fastEmitInst_r(Opc, RC, Op0Reg, Op0IsKill);
4788 updateValueMap(I, ResultReg);
4792 bool AArch64FastISel::selectFRem(
const Instruction *I) {
4794 if (!isTypeLegal(I->
getType(), RetVT))
4816 Entry.Ty = Arg->getType();
4817 Args.push_back(Entry);
4820 CallLoweringInfo CLI;
4822 CLI.setCallee(
DL, Ctx, TLI.getLibcallCallingConv(LC), I->
getType(),
4823 TLI.getLibcallName(LC), std::move(Args));
4824 if (!lowerCallTo(CLI))
4826 updateValueMap(I, CLI.ResultReg);
4830 bool AArch64FastISel::selectSDiv(
const Instruction *I) {
4832 if (!isTypeLegal(I->
getType(), VT))
4839 if ((VT != MVT::i32 && VT !=
MVT::i64) || !C ||
4844 unsigned Src0Reg = getRegForValue(I->
getOperand(0));
4847 bool Src0IsKill = hasTrivialKill(I->
getOperand(0));
4849 if (cast<BinaryOperator>(I)->isExact()) {
4850 unsigned ResultReg = emitASR_ri(VT, VT, Src0Reg, Src0IsKill, Lg2);
4853 updateValueMap(I, ResultReg);
4857 int64_t Pow2MinusOne = (1ULL << Lg2) - 1;
4858 unsigned AddReg = emitAdd_ri_(VT, Src0Reg,
false, Pow2MinusOne);
4863 if (!emitICmp_ri(VT, Src0Reg,
false, 0))
4869 SelectOpc = AArch64::CSELXr;
4870 RC = &AArch64::GPR64RegClass;
4872 SelectOpc = AArch64::CSELWr;
4873 RC = &AArch64::GPR32RegClass;
4875 unsigned SelectReg =
4876 fastEmitInst_rri(SelectOpc, RC, AddReg,
true, Src0Reg,
4883 unsigned ZeroReg = (VT ==
MVT::i64) ? AArch64::XZR : AArch64::WZR;
4886 ResultReg = emitAddSub_rs(
false, VT, ZeroReg,
true,
4889 ResultReg = emitASR_ri(VT, VT, SelectReg,
true, Lg2);
4894 updateValueMap(I, ResultReg);
4901 std::pair<unsigned, bool> AArch64FastISel::getRegForGEPIndex(
const Value *Idx) {
4902 unsigned IdxN = getRegForValue(Idx);
4905 return std::pair<unsigned, bool>(0,
false);
4907 bool IdxNIsKill = hasTrivialKill(Idx);
4910 MVT PtrVT = TLI.getPointerTy(
DL);
4912 if (IdxVT.
bitsLT(PtrVT)) {
4913 IdxN = emitIntExt(IdxVT.
getSimpleVT(), IdxN, PtrVT,
false);
4915 }
else if (IdxVT.
bitsGT(PtrVT))
4916 llvm_unreachable(
"AArch64 FastISel doesn't support types larger than i64");
4917 return std::pair<unsigned, bool>(IdxN, IdxNIsKill);
4924 bool AArch64FastISel::selectGetElementPtr(
const Instruction *I) {
4928 bool NIsKill = hasTrivialKill(I->
getOperand(0));
4932 uint64_t TotalOffs = 0;
4933 MVT VT = TLI.getPointerTy(
DL);
4936 const Value *Idx = GTI.getOperand();
4937 if (
auto *StTy = GTI.getStructTypeOrNull()) {
4938 unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
4943 Type *Ty = GTI.getIndexedType();
4946 if (
const auto *CI = dyn_cast<ConstantInt>(Idx)) {
4955 N = emitAdd_ri_(VT, N, NIsKill, TotalOffs);
4964 std::pair<unsigned, bool> Pair = getRegForGEPIndex(Idx);
4965 unsigned IdxN = Pair.first;
4966 bool IdxNIsKill = Pair.second;
4970 if (ElementSize != 1) {
4971 unsigned C = fastEmit_i(VT, VT,
ISD::Constant, ElementSize);
4974 IdxN = emitMul_rr(VT, IdxN, IdxNIsKill, C,
true);
4979 N = fastEmit_rr(VT, VT,
ISD::ADD, N, NIsKill, IdxN, IdxNIsKill);
4985 N = emitAdd_ri_(VT, N, NIsKill, TotalOffs);
4989 updateValueMap(I, N);
4995 "cmpxchg survived AtomicExpand at optlevel > -O0");
4997 auto *RetPairTy = cast<StructType>(I->
getType());
4998 Type *RetTy = RetPairTy->getTypeAtIndex(0U);
4999 assert(RetPairTy->getTypeAtIndex(1U)->isIntegerTy(1) &&
5000 "cmpxchg has a non-i1 status result");
5003 if (!isTypeLegal(RetTy, VT))
5007 unsigned Opc, CmpOpc;
5010 if (VT == MVT::i32) {
5011 Opc = AArch64::CMP_SWAP_32;
5012 CmpOpc = AArch64::SUBSWrs;
5013 ResRC = &AArch64::GPR32RegClass;
5015 Opc = AArch64::CMP_SWAP_64;
5016 CmpOpc = AArch64::SUBSXrs;
5017 ResRC = &AArch64::GPR64RegClass;
5031 const unsigned ResultReg1 = createResultReg(ResRC);
5032 const unsigned ResultReg2 = createResultReg(&AArch64::GPR32RegClass);
5033 const unsigned ScratchReg = createResultReg(&AArch64::GPR32RegClass);
5036 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
5043 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(CmpOpc))
5044 .addDef(VT == MVT::i32 ? AArch64::WZR : AArch64::XZR)
5049 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(AArch64::CSINCWr))
5055 assert((ResultReg1 + 1) == ResultReg2 &&
"Nonconsecutive result registers.");
5056 updateValueMap(I, ResultReg1, 2);
5060 bool AArch64FastISel::fastSelectInstruction(
const Instruction *I) {
5065 case Instruction::Sub:
5066 return selectAddSub(I);
5067 case Instruction::Mul:
5068 return selectMul(I);
5069 case Instruction::SDiv:
5070 return selectSDiv(I);
5071 case Instruction::SRem:
5075 case Instruction::URem:
5079 case Instruction::Shl:
5080 case Instruction::LShr:
5081 case Instruction::AShr:
5082 return selectShift(I);
5083 case Instruction::And:
5084 case Instruction::Or:
5085 case Instruction::Xor:
5086 return selectLogicalOp(I);
5087 case Instruction::Br:
5088 return selectBranch(I);
5089 case Instruction::IndirectBr:
5090 return selectIndirectBr(I);
5091 case Instruction::BitCast:
5093 return selectBitCast(I);
5095 case Instruction::FPToSI:
5097 return selectFPToInt(I,
true);
5099 case Instruction::FPToUI:
5100 return selectFPToInt(I,
false);
5101 case Instruction::ZExt:
5102 case Instruction::SExt:
5103 return selectIntExt(I);
5104 case Instruction::Trunc:
5106 return selectTrunc(I);
5108 case Instruction::FPExt:
5109 return selectFPExt(I);
5110 case Instruction::FPTrunc:
5111 return selectFPTrunc(I);
5112 case Instruction::SIToFP:
5114 return selectIntToFP(I,
true);
5116 case Instruction::UIToFP:
5117 return selectIntToFP(I,
false);
5119 return selectLoad(I);
5121 return selectStore(I);
5122 case Instruction::FCmp:
5123 case Instruction::ICmp:
5124 return selectCmp(I);
5126 return selectSelect(I);
5128 return selectRet(I);
5129 case Instruction::FRem:
5130 return selectFRem(I);
5131 case Instruction::GetElementPtr:
5132 return selectGetElementPtr(I);
5133 case Instruction::AtomicCmpXchg:
5134 return selectAtomicCmpXchg(cast<AtomicCmpXchgInst>(I));
5138 return selectOperator(I, I->
getOpcode());
5140 (void)&CC_AArch64_DarwinPCS_VarArg;
5141 (void)&CC_AArch64_Win64_VarArg;
5148 return new AArch64FastISel(FuncInfo, LibInfo);
void setFrameAddressIsTaken(bool T)
Return a value (possibly void), from a function.
static MVT getIntegerVT(unsigned BitWidth)
void push_back(const T &Elt)
This class is the base class for the comparison instructions.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
uint64_t getZExtValue() const
Get zero extended value.
Atomic ordering constants.
LocInfo getLocInfo() const
MO_PAGE - A symbol operand with this flag represents the pc-relative offset of the 4K page containing...
unsigned constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const MCInstrDesc &II, unsigned Reg, unsigned OpIdx)
Try to constrain Reg so that it is usable by argument OpIdx of the provided MCInstrDesc II...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
unsigned getNumOperands() const
static CondCode getInvertedCondCode(CondCode Code)
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Describe properties that are true of each instruction in the target description file.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
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)
0 1 0 0 True if ordered and less than
unsigned getSizeInBits() const
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
1 1 1 0 True if unordered or not equal
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
This class wraps the llvm.memset intrinsic.
const Function * getParent() const
Return the enclosing method, or null if none.
Value * getNewValOperand()
An instruction for reading from memory.
void reserve(size_type N)
unsigned getValNo() const
const MachineInstrBuilder & addDef(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
unsigned getFrameRegister(const MachineFunction &MF) const override
bool isNegative() const
Determine sign of this APInt.
bool isVector() const
Return true if this is a vector value type.
1 0 0 1 True if unordered or equal
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
bool isUnconditional() const
A description of a memory reference used in the backend.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This class represents the LLVM 'select' instruction.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
const HexagonInstrInfo * TII
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Class to represent struct types.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
unsigned getNumArgOperands() const
Return the number of call arguments.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Reg
All possible values of the reg field in the ModR/M byte.
0 1 0 1 True if ordered and less than or equal
This file contains the simple types necessary to represent the attributes associated with functions a...
APInt bitcastToAPInt() const
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 getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
This file implements a class to represent arbitrary precision integral constant values and operations...
AtomicOrdering
Atomic ordering for LLVM's memory model.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Context object for machine code objects.
Value * getPointerOperand()
unsigned getLocReg() const
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
A constant value that is initialized with an expression using other constant values.
[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...
static bool isZExtLoad(const MachineInstr *LI)
Simple integer binary arithmetic operators.
BasicBlock * getSuccessor(unsigned i) const
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
bool isArrayTy() const
True if this is an instance of ArrayType.
bool isZero() const
Return true if the value is positive or negative zero.
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo)
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset)
Stack pointer relative access.
unsigned getKillRegState(bool B)
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
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.
iterator find(const_arg_type_t< KeyT > Val)
uint64_t getElementOffset(unsigned Idx) const
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
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.
Type * getReturnType() const
Returns the type of the ret val.
Control flow instructions. These all have token chains.
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.
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.
bool isVectorTy() const
True if this is an instance of VectorType.
This is an important base class in LLVM.
PointerType * getType() const
Overload to return most specific pointer type.
bool isVector() const
Return true if this is a vector value type.
const Value * getCondition() const
Value * getCompareOperand()
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
const MachineOperand & getOperand(unsigned i) const
Indirect Branch Instruction.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static bool isIntExtFree(const Instruction *I)
Check if the sign-/zero-extend will be a noop.
ConstantFP - Floating Point Values [float, double].
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
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...
static bool isSExtLoad(const MachineInstr *LI)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static const unsigned End
static AArch64CC::CondCode getCompareCC(CmpInst::Predicate Pred)
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
1 1 1 1 Always true (always folded)
static unsigned getImplicitScaleFactor(MVT VT)
Determine the implicit scale factor that is applied by a memory operation for a given value type...
unsigned getSubReg() const
LLVMContext & getContext() const
All values hold a context through their type.
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
const Value * getTrueValue() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
1 1 0 1 True if unordered, less than, or equal
static bool isReleaseOrStronger(AtomicOrdering ao)
The memory access writes data.
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
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...
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
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.
CCState - This class holds information needed while lowering arguments and return values...
This is the shared class of boolean and integer constants.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
CCValAssign - Represent assignment of one arg/retval to a location.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Value * getLength() const
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.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
bool is64BitVector() const
Return true if this is a 64-bit vector type.
const MachineInstrBuilder & addFrameIndex(int Idx) const
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
C - The default llvm calling convention, compatible with C.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool is128BitVector() const
Return true if this is a 128-bit vector type.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
bool selectBitCast(const User *I)
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
bool isIntegerTy() const
True if this is an instance of IntegerType.
This file defines the FastISel class.
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
Flags
Flags values. These may be or'd together.
llvm_unreachable("Unknown RegBank!")
bool isStructTy() const
True if this is an instance of StructType.
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.
static std::vector< std::string > Flags
Representation of each machine instruction.
bool isNegative() const
Return true if the sign bit is set.
PointerType * getType() const
Global values are always pointers.
Value * getCondition() const
Bitwise operators - logical and, logical or, logical xor.
unsigned greater or equal
static unsigned UseReg(const MachineOperand &MO)
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
MO_PAGEOFF - A symbol operand with this flag represents the offset of that symbol within a 4K page...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
0 1 1 0 True if ordered and operands are unequal
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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.
const APFloat & getValueAPF() const
unsigned getReg() const
getReg - Returns the register number.
iterator_range< op_iterator > arg_operands()
Iteration adapter for range-for loops.
bool isUnsigned() const
Determine if this instruction is using an unsigned comparison.
static SDValue emitCmp(SelectionDAG &DAG, const SDLoc &DL, Comparison &C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void GetReturnInfo(Type *ReturnType, AttributeList attr, SmallVectorImpl< ISD::OutputArg > &Outs, const TargetLowering &TLI, const DataLayout &DL)
Given an LLVM IR type and return type attributes, compute the return value EVTs and flags...
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
const MachineInstrBuilder & addUse(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
unsigned getDestAddressSpace() const
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static const unsigned FramePtr
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
const Value * getFalseValue() const
MO_NC - Indicates whether the linker is expected to check the symbol reference for overflow...
TRUNCATE - Completely drop the high bits.
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
0 0 1 1 True if ordered and greater than or equal
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const BasicBlock * getParent() const
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
iterator_range< arg_iterator > args()
0 0 0 0 Always false (always folded)
A wrapper class for inspecting calls to intrinsic functions.
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...
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.