26 #define DEBUG_TYPE "aarch64-legalinfo" 34 using namespace TargetOpcode;
61 getActionDefinitionsBuilder(G_IMPLICIT_DEF)
62 .legalFor({p0, s1, s8, s16, s32, s64, v2s32, v4s32, v2s64})
63 .clampScalar(0, s1, s64)
64 .widenScalarToNextPow2(0, 8)
67 return Query.
Types[0].isVector() &&
68 (Query.
Types[0].getElementType() != s64 ||
69 Query.
Types[0].getNumElements() != 2);
72 LLT EltTy = Query.
Types[0].getElementType();
75 return std::make_pair(0, EltTy);
78 getActionDefinitionsBuilder(G_PHI)
79 .legalFor({p0, s16, s32, s64, v2s32, v4s32, v2s64})
80 .clampScalar(0, s16, s64)
81 .widenScalarToNextPow2(0);
83 getActionDefinitionsBuilder(G_BSWAP)
84 .legalFor({s32, s64, v4s32, v2s32, v2s64})
85 .clampScalar(0, s32, s64)
86 .widenScalarToNextPow2(0);
88 getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
89 .legalFor({s32, s64, v2s32, v4s32, v2s64, v8s16, v16s8})
90 .clampScalar(0, s32, s64)
91 .widenScalarToNextPow2(0)
92 .clampNumElements(0, v2s32, v4s32)
93 .clampNumElements(0, v2s64, v2s64)
94 .moreElementsToNextPow2(0);
96 getActionDefinitionsBuilder(G_SHL)
97 .legalFor({{s32, s32}, {s64, s64},
98 {v2s32, v2s32}, {v4s32, v4s32}, {v2s64, v2s64}})
99 .clampScalar(1, s32, s64)
100 .clampScalar(0, s32, s64)
101 .widenScalarToNextPow2(0)
102 .clampNumElements(0, v2s32, v4s32)
103 .clampNumElements(0, v2s64, v2s64)
104 .moreElementsToNextPow2(0)
105 .minScalarSameAs(1, 0);
107 getActionDefinitionsBuilder(G_PTR_ADD)
108 .legalFor({{p0, s64}})
109 .clampScalar(1, s64, s64);
111 getActionDefinitionsBuilder(G_PTR_MASK).legalFor({p0});
113 getActionDefinitionsBuilder({G_SDIV, G_UDIV})
114 .legalFor({s32, s64})
116 .clampScalar(0, s32, s64)
117 .widenScalarToNextPow2(0)
120 getActionDefinitionsBuilder({G_LSHR, G_ASHR})
122 const auto &SrcTy = Query.
Types[0];
123 const auto &AmtTy = Query.
Types[1];
124 return !SrcTy.isVector() && SrcTy.getSizeInBits() == 32 &&
125 AmtTy.getSizeInBits() == 32;
127 .legalFor({{s32, s32},
133 .clampScalar(1, s32, s64)
134 .clampScalar(0, s32, s64)
135 .minScalarSameAs(1, 0);
137 getActionDefinitionsBuilder({G_SREM, G_UREM})
138 .lowerFor({s1, s8, s16, s32, s64});
140 getActionDefinitionsBuilder({G_SMULO, G_UMULO})
141 .lowerFor({{s64, s1}});
143 getActionDefinitionsBuilder({G_SMULH, G_UMULH}).legalFor({s32, s64});
145 getActionDefinitionsBuilder({G_UADDE, G_USUBE, G_SADDO, G_SSUBO, G_UADDO})
146 .legalFor({{s32, s1}, {s64, s1}})
149 getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FNEG})
150 .legalFor({s32, s64, v2s64, v4s32, v2s32});
152 getActionDefinitionsBuilder(G_FREM).libcallFor({s32, s64});
154 getActionDefinitionsBuilder({G_FCEIL, G_FABS, G_FSQRT, G_FFLOOR, G_FRINT,
155 G_FMA, G_INTRINSIC_TRUNC, G_INTRINSIC_ROUND,
161 const auto &Ty = Query.
Types[0];
162 return Ty.isVector() && Ty.getElementType() == s16 &&
165 [=](
const LegalityQuery &Query) {
return std::make_pair(0, s16); })
172 [=](
const LegalityQuery &Query) {
return std::make_pair(0, s32); })
173 .legalFor({s16, s32, s64, v2s32, v4s32, v2s64, v2s16, v4s16, v8s16});
175 getActionDefinitionsBuilder(
176 {G_FCOS, G_FSIN, G_FLOG10, G_FLOG, G_FLOG2, G_FEXP, G_FEXP2, G_FPOW})
181 .libcallFor({s32, s64, v2s32, v4s32, v2s64});
183 getActionDefinitionsBuilder(G_INSERT)
185 return Query.
Types[0].getSizeInBits() <= Query.
Types[1].getSizeInBits();
190 if (Ty0 != s32 && Ty0 != s64 && Ty0 != p0)
195 .clampScalar(0, s32, s64)
196 .widenScalarToNextPow2(0)
197 .maxScalarIf(
typeInSet(0, {s32}), 1, s16)
198 .maxScalarIf(
typeInSet(0, {s64}), 1, s32)
199 .widenScalarToNextPow2(1);
201 getActionDefinitionsBuilder(G_EXTRACT)
203 return Query.
Types[0].getSizeInBits() >= Query.
Types[1].getSizeInBits();
208 if (Ty1 != s32 && Ty1 != s64 && Ty1 != s128)
215 .clampScalar(1, s32, s128)
216 .widenScalarToNextPow2(1)
217 .maxScalarIf(
typeInSet(1, {s32}), 0, s16)
218 .maxScalarIf(
typeInSet(1, {s64}), 0, s32)
219 .widenScalarToNextPow2(0);
221 getActionDefinitionsBuilder({G_SEXTLOAD, G_ZEXTLOAD})
222 .legalForTypesWithMemDesc({{s32, p0, 8, 8},
231 .clampScalar(0, s32, s64)
232 .widenScalarToNextPow2(0)
235 .unsupportedIfMemSizeNotPow2()
247 getActionDefinitionsBuilder(G_LOAD)
248 .legalForTypesWithMemDesc({{s8, p0, 8, 8},
260 {v2s64, p0, 128, 8}})
262 .legalForTypesWithMemDesc({{s32, p0, 8, 8},
264 .clampScalar(0, s8, s64)
265 .lowerIfMemSizeNotPow2()
268 return Query.
Types[0].getSizeInBits() != Query.
MMODescrs[0].SizeInBits;
270 .widenScalarToNextPow2(0)
271 .clampMaxNumElements(0, s32, 2)
272 .clampMaxNumElements(0, s64, 1)
273 .customIf(IsPtrVecPred);
275 getActionDefinitionsBuilder(G_STORE)
276 .legalForTypesWithMemDesc({{s8, p0, 8, 8},
289 {v2s64, p0, 128, 8}})
290 .clampScalar(0, s8, s64)
291 .lowerIfMemSizeNotPow2()
293 return Query.
Types[0].isScalar() &&
296 .clampMaxNumElements(0, s32, 2)
297 .clampMaxNumElements(0, s64, 1)
298 .customIf(IsPtrVecPred);
301 getActionDefinitionsBuilder(G_CONSTANT)
302 .legalFor({p0, s8, s16, s32, s64})
303 .clampScalar(0, s8, s64)
304 .widenScalarToNextPow2(0);
305 getActionDefinitionsBuilder(G_FCONSTANT)
306 .legalFor({s32, s64})
307 .clampScalar(0, s32, s64);
309 getActionDefinitionsBuilder(G_ICMP)
310 .legalFor({{s32, s32},
321 .clampScalar(1, s32, s64)
322 .clampScalar(0, s32, s32)
323 .minScalarEltSameAsIf(
339 getActionDefinitionsBuilder(G_FCMP)
340 .legalFor({{s32, s32}, {s32, s64}})
341 .clampScalar(0, s32, s32)
342 .clampScalar(1, s32, s64)
343 .widenScalarToNextPow2(1);
347 unsigned DstSize = Query.
Types[0].getSizeInBits();
349 if (DstSize == 128 && !Query.
Types[0].isVector())
372 getActionDefinitionsBuilder({G_ZEXT, G_SEXT, G_ANYEXT})
373 .legalIf(ExtLegalFunc)
374 .clampScalar(0, s64, s64);
376 getActionDefinitionsBuilder(G_TRUNC).alwaysLegal();
378 getActionDefinitionsBuilder(G_SEXT_INREG).lower();
381 getActionDefinitionsBuilder(G_FPTRUNC).legalFor(
382 {{s16, s32}, {s16, s64}, {s32, s64}, {v4s16, v4s32}, {v2s32, v2s64}});
383 getActionDefinitionsBuilder(G_FPEXT).legalFor(
384 {{s32, s16}, {s64, s16}, {s64, s32}, {v4s32, v4s16}, {v2s64, v2s32}});
387 getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
388 .legalForCartesianProduct({s32, s64, v2s64, v4s32, v2s32})
389 .clampScalar(0, s32, s64)
390 .widenScalarToNextPow2(0)
391 .clampScalar(1, s32, s64)
392 .widenScalarToNextPow2(1);
394 getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
395 .legalForCartesianProduct({s32, s64, v2s64, v4s32, v2s32})
396 .clampScalar(1, s32, s64)
397 .widenScalarToNextPow2(1)
398 .clampScalar(0, s32, s64)
399 .widenScalarToNextPow2(0);
402 getActionDefinitionsBuilder(G_BRCOND).legalFor({s1, s8, s16, s32});
403 getActionDefinitionsBuilder(G_BRINDIRECT).legalFor({p0});
408 getActionDefinitionsBuilder(G_SELECT)
409 .legalFor({{s32, s1}, {s64, s1}, {p0, s1}})
410 .clampScalar(0, s32, s64)
411 .widenScalarToNextPow2(0)
415 getActionDefinitionsBuilder(G_FRAME_INDEX).legalFor({p0});
416 getActionDefinitionsBuilder(G_GLOBAL_VALUE).legalFor({p0});
418 getActionDefinitionsBuilder(G_PTRTOINT)
419 .legalForCartesianProduct({s1, s8, s16, s32, s64}, {p0})
421 .widenScalarToNextPow2(0, 8);
423 getActionDefinitionsBuilder(G_INTTOPTR)
425 return Query.
Types[0].getSizeInBits() != Query.
Types[1].getSizeInBits();
427 .legalFor({{p0, s64}});
431 getActionDefinitionsBuilder(G_BITCAST)
435 .legalForCartesianProduct({s1, s8, s16, s32, s64, s128, v16s8, v8s8, v4s8,
436 v8s16, v4s16, v2s16, v4s32, v2s32, v2s64,
439 getActionDefinitionsBuilder(G_VASTART).legalFor({p0});
443 getActionDefinitionsBuilder(G_VAARG)
444 .customForCartesianProduct({s8, s16, s32, s64, p0}, {p0})
445 .clampScalar(0, s8, s64)
446 .widenScalarToNextPow2(0, 8);
449 getActionDefinitionsBuilder(G_ATOMIC_CMPXCHG_WITH_SUCCESS)
454 getActionDefinitionsBuilder(
455 {G_ATOMICRMW_XCHG, G_ATOMICRMW_ADD, G_ATOMICRMW_SUB, G_ATOMICRMW_AND,
456 G_ATOMICRMW_OR, G_ATOMICRMW_XOR, G_ATOMICRMW_MIN, G_ATOMICRMW_MAX,
457 G_ATOMICRMW_UMIN, G_ATOMICRMW_UMAX, G_ATOMIC_CMPXCHG})
463 getActionDefinitionsBuilder(G_BLOCK_ADDR).legalFor({p0});
466 for (
unsigned Op : {G_MERGE_VALUES, G_UNMERGE_VALUES}) {
467 unsigned BigTyIdx =
Op == G_MERGE_VALUES ? 0 : 1;
468 unsigned LitTyIdx =
Op == G_MERGE_VALUES ? 1 : 0;
470 auto notValidElt = [](
const LegalityQuery &Query,
unsigned TypeIdx) {
471 const LLT &Ty = Query.
Types[TypeIdx];
490 getActionDefinitionsBuilder(
Op)
493 [=](
const LegalityQuery &Query) {
return notValidElt(Query, 0); },
496 [=](
const LegalityQuery &Query) {
return notValidElt(Query, 1); },
500 .clampScalar(BigTyIdx, s8, s512)
503 const LLT &Ty = Query.
Types[BigTyIdx];
510 const LLT &Ty = Query.
Types[BigTyIdx];
511 unsigned NewSizeInBits = 1
513 if (NewSizeInBits >= 256) {
515 if (RoundedTo < NewSizeInBits)
516 NewSizeInBits = RoundedTo;
518 return std::make_pair(BigTyIdx,
LLT::scalar(NewSizeInBits));
523 .clampScalar(LitTyIdx, s8, s256)
524 .widenScalarToNextPow2(LitTyIdx, 8)
529 const LLT &BigTy = Query.
Types[BigTyIdx];
530 const LLT &LitTy = Query.
Types[LitTyIdx];
542 getActionDefinitionsBuilder(G_EXTRACT_VECTOR_ELT)
544 const LLT &EltTy = Query.
Types[1].getElementType();
545 return Query.
Types[0] != EltTy;
550 return VecTy == v2s16 || VecTy == v4s16 || VecTy == v8s16 ||
551 VecTy == v4s32 || VecTy == v2s64 || VecTy == v2s32;
554 getActionDefinitionsBuilder(G_INSERT_VECTOR_ELT)
558 return VecTy == v2s32 || VecTy == v4s32 || VecTy == v2s64;
561 getActionDefinitionsBuilder(G_BUILD_VECTOR)
562 .legalFor({{v4s16, s16},
568 .clampNumElements(0, v4s32, v4s32)
569 .clampNumElements(0, v2s64, v2s64)
573 return Query.
Types[0].getScalarSizeInBits() <
574 Query.
Types[1].getSizeInBits();
576 .minScalarSameAs(1, 0);
578 getActionDefinitionsBuilder(G_CTLZ).legalForCartesianProduct(
579 {s32, s64, v8s8, v16s8, v4s16, v8s16, v2s32, v4s32})
582 getActionDefinitionsBuilder(G_SHUFFLE_VECTOR)
590 for (
auto &Ty : {v2s32, v4s32, v2s64}) {
599 return !Query.
Types[1].isVector();
601 .clampNumElements(0, v4s32, v4s32)
602 .clampNumElements(0, v2s64, v2s64);
604 getActionDefinitionsBuilder(G_CONCAT_VECTORS)
605 .legalFor({{v4s32, v2s32}, {v8s16, v4s16}});
607 getActionDefinitionsBuilder(G_JUMP_TABLE)
608 .legalFor({{p0}, {s64}});
610 getActionDefinitionsBuilder(G_BRJT).legalIf([=](
const LegalityQuery &Query) {
611 return Query.
Types[0] == p0 && Query.
Types[1] == s64;
614 getActionDefinitionsBuilder(G_DYN_STACKALLOC).lower();
628 case TargetOpcode::G_VAARG:
629 return legalizeVaArg(MI, MRI, MIRBuilder);
630 case TargetOpcode::G_LOAD:
631 case TargetOpcode::G_STORE:
632 return legalizeLoadStore(MI, MRI, MIRBuilder, Observer);
633 case TargetOpcode::G_SHL:
634 case TargetOpcode::G_ASHR:
635 case TargetOpcode::G_LSHR:
636 return legalizeShlAshrLshr(MI, MRI, MIRBuilder, Observer);
646 case Intrinsic::memcpy:
647 case Intrinsic::memset:
648 case Intrinsic::memmove:
660 bool AArch64LegalizerInfo::legalizeShlAshrLshr(
664 MI.
getOpcode() == TargetOpcode::G_LSHR ||
670 assert(CstMI &&
"expected to find a vreg def");
671 if (CstMI->getOpcode() != TargetOpcode::G_CONSTANT)
674 unsigned Amount = CstMI->getOperand(1).getCImm()->getZExtValue();
684 bool AArch64LegalizerInfo::legalizeLoadStore(
703 LLVM_DEBUG(
dbgs() <<
"Tried to do custom legalization on wrong load/store");
711 if (MI.
getOpcode() == TargetOpcode::G_STORE) {
723 bool AArch64LegalizerInfo::legalizeVaArg(
MachineInstr &MI,
743 if (Align > PtrSize) {
745 auto AlignMinus1 = MIRBuilder.
buildConstant(IntPtrTy, Align - 1);
747 auto ListTmp = MIRBuilder.
buildPtrAdd(PtrTy, List, AlignMinus1.getReg(0));
758 ValSize,
std::max(Align, PtrSize)));
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
static LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
This class represents lattice values for constants.
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert Res = G_PTR_ADD Op0, Op1.
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
LegalityPredicate typeIs(unsigned TypeIdx, LLT TypesInit)
True iff the given type index is the specified types.
bool legalizeIntrinsic(MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &MIRBuilder) const override
Return true if MI is either legal or has been legalized and false if not legal.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
LegalityPredicate atomicOrderingAtLeastOrStrongerThan(unsigned MMOIdx, AtomicOrdering Ordering)
True iff the specified MMO index has at an atomic ordering of at Ordering or stronger.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
This file declares the targeting of the Machinelegalizer class for AArch64.
Predicate all(Predicate P0, Predicate P1)
True iff P0 and P1 are true.
MachineFunction & getMF()
Getter for the function we currently build.
void setReg(Register Reg)
Change the register this operand corresponds to.
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
LegalizeMutation scalarize(unsigned TypeIdx)
Break up the vector type for the given type index into the element type.
Abstract class that contains various methods for clients to notify about changes. ...
unsigned const MachineRegisterInfo * MRI
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
MachineInstrBuilder buildZExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ZEXT Op.
AArch64LegalizerInfo(const AArch64Subtarget &ST)
Helper class to build MachineInstr.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
LegalizerHelper::LegalizeResult createMemLibcall(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI, MachineInstr &MI)
Create a libcall to memcpy et al.
unsigned getAddressSpace() const
Some kind of error has occurred and we could not legalize this instruction.
bool legalizeCustom(MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &MIRBuilder, GISelChangeObserver &Observer) const override
This class contains a discriminated union of information about pointers in memory operands...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool verify(const TargetRegisterInfo &TRI) const
Check that information hold by this instance make sense for the given TRI.
This struct is a compact representation of a valid (non-zero power of two) alignment.
The memory access writes data.
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
Align max(MaybeAlign Lhs, Align Rhs)
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
MachineInstrBuilder buildPtrMask(const DstOp &Res, const SrcOp &Op0, uint32_t NumBits)
Build and insert Res = G_PTR_MASK Op0, NumBits.
This file declares the MachineIRBuilder class.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
The memory access reads data.
Representation of each machine instruction.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
LegalizeMutation widenScalarOrEltToNextPow2(unsigned TypeIdx, unsigned Min=0)
Widen the scalar type or vector element type for the given type index to the next power of 2...
LegalityPredicate typeInSet(unsigned TypeIdx, std::initializer_list< LLT > TypesInit)
True iff the given type index is one of the specified types.
MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
MachineInstrBuilder buildBitcast(const DstOp &Dst, const SrcOp &Src)
Build and insert Dst = G_BITCAST Src.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getIntrinsicID() const
Returns the Intrinsic::ID for this instruction.
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
const AArch64InstrInfo * getInstrInfo() const override
static LLT vector(uint16_t NumElements, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
Register getReg() const
getReg - Returns the register number.
ArrayRef< MemDesc > MMODescrs
Operations which require memory can use this to place requirements on the memory type for each MMO...
const MachineOperand & getOperand(unsigned i) const
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Wrapper class representing virtual and physical registers.