18#include "llvm/IR/IntrinsicsMips.h"
34 if (MemSize > AlignInBits)
41 std::initializer_list<TypesAndMemOps> SupportedValues) {
42 unsigned QueryMemSize = Query.
MMODescrs[0].MemoryTy.getSizeInBits();
48 for (
auto &Val : SupportedValues) {
49 if (Val.ValTy != Query.
Types[0])
51 if (Val.PtrTy != Query.
Types[1])
53 if (Val.MemSize != QueryMemSize)
55 if (!Val.SystemSupportsUnalignedAccess &&
64 std::initializer_list<LLT> SupportedValues) {
86 if (ST.hasMSA() &&
CheckTyN(0, Query, {v16s8, v8s16, v4s32, v2s64}))
90 .clampScalar(0, s32, s32);
93 .lowerFor({{s32, s1}});
104 bool NoAlignRequirements =
true;
109 Query, {{s32, p0, 8, NoAlignRequirements},
110 {s32, p0, 16, ST.systemSupportsUnalignedAccess()},
111 {s32, p0, 32, NoAlignRequirements},
112 {p0, p0, 32, NoAlignRequirements},
113 {s64, p0, 64, ST.systemSupportsUnalignedAccess()}}))
116 Query, {{v16s8, p0, 128, NoAlignRequirements},
117 {v8s16, p0, 128, NoAlignRequirements},
118 {v4s32, p0, 128, NoAlignRequirements},
119 {v2s64, p0, 128, NoAlignRequirements}}))
127 if (!Query.
Types[0].isScalar() || Query.
Types[1] != p0 ||
128 Query.
Types[0] == s1)
131 unsigned Size = Query.
Types[0].getSizeInBits();
132 unsigned QueryMemSize = Query.
MMODescrs[0].MemoryTy.getSizeInBits();
133 assert(QueryMemSize <=
Size &&
"Scalar can't hold MemSize");
135 if (
Size > 64 || QueryMemSize > 64)
141 if (!ST.systemSupportsUnalignedAccess() &&
144 assert(QueryMemSize != 32 &&
"4 byte load and store are legal");
163 .legalForTypesWithMemDesc({{s32, p0, s8, 8},
165 .clampScalar(0, s32, s32);
198 .clampScalar(0, s32, s32);
204 if (ST.hasMSA() &&
CheckTyN(0, Query, {v16s8, v8s16, v4s32, v2s64}))
212 .legalFor({{s32, s32}})
213 .clampScalar(1, s32, s32)
218 .clampScalar(1, s32, s32)
223 .clampScalar(0, s32, s32);
226 .legalFor({{p0, s32}});
245 if (ST.hasMips32r2() &&
CheckTyN(0, Query, {s32}))
250 if (!ST.hasMips32r2() &&
CheckTyN(0, Query, {s32}))
272 .
lowerFor({{s32, s32}, {s64, s64}});
276 .clampScalar(0, s32, s32)
287 if (ST.hasMSA() &&
CheckTyN(0, Query, {v16s8, v8s16, v4s32, v2s64}))
297 .libcallFor({s32, s64});
308 .libcallForCartesianProduct({s64}, {s64, s32})
313 .lowerForCartesianProduct({s32}, {s64, s32})
319 .libcallForCartesianProduct({s64, s32}, {s64})
324 .customForCartesianProduct({s64, s32}, {s32})
334 verify(*ST.getInstrInfo());
348 switch (
MI.getOpcode()) {
351 unsigned MemSize = (**
MI.memoperands_begin()).getSize().getValue();
357 assert(MemSize <= 8 &&
"MemSize is too large");
358 assert(
Size <= 64 &&
"Scalar size is too large");
362 unsigned P2HalfMemSize, RemMemSize;
364 P2HalfMemSize = RemMemSize = MemSize / 2;
366 P2HalfMemSize = 1 <<
Log2_32(MemSize);
367 RemMemSize = MemSize - P2HalfMemSize;
370 Register BaseAddr =
MI.getOperand(1).getReg();
374 unsigned FirstMemSize = IsLittle ? P2HalfMemSize : RemMemSize;
377 MMOBase, IsLittle ? 0 : RemMemSize, P2HalfMemSize);
379 MMOBase, IsLittle ? P2HalfMemSize : 0, RemMemSize);
381 if (
MI.getOpcode() == G_STORE) {
390 Register LoAddr = IsLittle ? BaseAddr : Addr;
391 Register HiAddr = IsLittle ? Addr : BaseAddr;
393 if (
MI.getOpcode() == G_STORE && MemSize <= 4) {
394 MIRBuilder.
buildStore(Val, LoAddr, *P2HalfMemOp);
395 auto C_P2Half_InBits = MIRBuilder.
buildConstant(s32, P2HalfMemSize * 8);
396 auto Shift = MIRBuilder.
buildLShr(s32, Val, C_P2Half_InBits);
397 MIRBuilder.
buildStore(Shift, HiAddr, *RemMemOp);
400 MIRBuilder.
buildStore(Unmerge.getReg(0), LoAddr, *P2HalfMemOp);
401 MIRBuilder.
buildStore(Unmerge.getReg(1), HiAddr, *RemMemOp);
405 if (
MI.getOpcode() == G_LOAD) {
413 auto ShiftAmt = MIRBuilder.
buildConstant(s32, (4 - MemSize) * 8);
416 }
else if (
Size == 32)
417 MIRBuilder.
buildLoad(Val, BaseAddr, *Load4MMO);
427 Register LoAddr = IsLittle ? BaseAddr : Addr;
428 Register HiAddr = IsLittle ? Addr : BaseAddr;
430 auto Load_P2Half = MIRBuilder.
buildLoad(s32, LoAddr, *P2HalfMemOp);
431 auto Load_Rem = MIRBuilder.
buildLoad(s32, HiAddr, *RemMemOp);
442 MI.eraseFromParent();
453 if (DstTy != s32 && DstTy != s64)
463 auto C_HiMask = MIRBuilder.
buildConstant(s32, UINT32_C(0x43300000));
471 MIRBuilder.
buildFSub(Dst, Bitcast, TwoP52FP);
477 MI.eraseFromParent();
490 assert(ST.hasMSA() &&
"MSA intrinsic not supported on target without MSA.");
492 .
add(
MI.getOperand(0))
493 .
add(
MI.getOperand(2))
494 .
add(
MI.getOperand(3))
496 *ST.getRegBankInfo());
497 MI.eraseFromParent();
504 assert(ST.hasMSA() &&
"MSA intrinsic not supported on target without MSA.");
506 .
add(
MI.getOperand(0))
507 .
add(
MI.getOperand(2))
508 .
add(
MI.getOperand(3));
509 MI.eraseFromParent();
516 assert(ST.hasMSA() &&
"MSA intrinsic not supported on target without MSA.");
518 .
add(
MI.getOperand(0))
519 .
add(
MI.getOperand(2));
520 MI.eraseFromParent();
530 case Intrinsic::vacopy: {
535 *
MI.getMF()->getMachineMemOperand(
538 *
MI.getMF()->getMachineMemOperand(
540 MI.eraseFromParent();
543 case Intrinsic::mips_addv_b:
544 case Intrinsic::mips_addv_h:
545 case Intrinsic::mips_addv_w:
546 case Intrinsic::mips_addv_d:
548 case Intrinsic::mips_addvi_b:
550 case Intrinsic::mips_addvi_h:
552 case Intrinsic::mips_addvi_w:
554 case Intrinsic::mips_addvi_d:
556 case Intrinsic::mips_subv_b:
557 case Intrinsic::mips_subv_h:
558 case Intrinsic::mips_subv_w:
559 case Intrinsic::mips_subv_d:
561 case Intrinsic::mips_subvi_b:
563 case Intrinsic::mips_subvi_h:
565 case Intrinsic::mips_subvi_w:
567 case Intrinsic::mips_subvi_d:
569 case Intrinsic::mips_mulv_b:
570 case Intrinsic::mips_mulv_h:
571 case Intrinsic::mips_mulv_w:
572 case Intrinsic::mips_mulv_d:
574 case Intrinsic::mips_div_s_b:
575 case Intrinsic::mips_div_s_h:
576 case Intrinsic::mips_div_s_w:
577 case Intrinsic::mips_div_s_d:
579 case Intrinsic::mips_mod_s_b:
580 case Intrinsic::mips_mod_s_h:
581 case Intrinsic::mips_mod_s_w:
582 case Intrinsic::mips_mod_s_d:
584 case Intrinsic::mips_div_u_b:
585 case Intrinsic::mips_div_u_h:
586 case Intrinsic::mips_div_u_w:
587 case Intrinsic::mips_div_u_d:
589 case Intrinsic::mips_mod_u_b:
590 case Intrinsic::mips_mod_u_h:
591 case Intrinsic::mips_mod_u_w:
592 case Intrinsic::mips_mod_u_d:
594 case Intrinsic::mips_fadd_w:
595 case Intrinsic::mips_fadd_d:
597 case Intrinsic::mips_fsub_w:
598 case Intrinsic::mips_fsub_d:
600 case Intrinsic::mips_fmul_w:
601 case Intrinsic::mips_fmul_d:
603 case Intrinsic::mips_fdiv_w:
604 case Intrinsic::mips_fdiv_d:
606 case Intrinsic::mips_fmax_a_w:
608 case Intrinsic::mips_fmax_a_d:
610 case Intrinsic::mips_fsqrt_w:
612 case Intrinsic::mips_fsqrt_d:
static unsigned getIntrinsicID(const SDNode *N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
This file declares the MachineIRBuilder class.
static bool CheckTy0Ty1MemSizeAlign(const LegalityQuery &Query, std::initializer_list< TypesAndMemOps > SupportedValues)
static bool CheckTyN(unsigned N, const LegalityQuery &Query, std::initializer_list< LLT > SupportedValues)
static bool MSA2OpIntrinsicToGeneric(MachineInstr &MI, unsigned Opcode, MachineIRBuilder &MIRBuilder, const MipsSubtarget &ST)
static bool SelectMSA3OpIntrinsic(MachineInstr &MI, unsigned Opcode, MachineIRBuilder &MIRBuilder, const MipsSubtarget &ST)
static bool isUnalignedMemmoryAccess(uint64_t MemSize, uint64_t AlignInBits)
static bool MSA3OpIntrinsicToGeneric(MachineInstr &MI, unsigned Opcode, MachineIRBuilder &MIRBuilder, const MipsSubtarget &ST)
This file declares the targeting of the Machinelegalizer class for Mips.
bool isLittleEndian() const
Layout endianness...
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
LegalizeRuleSet & minScalar(unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at least as wide as Ty.
LegalizeRuleSet & legalFor(std::initializer_list< LLT > Types)
The instruction is legal when type index 0 is any type in the given list.
LegalizeRuleSet & libcallFor(std::initializer_list< LLT > Types)
LegalizeRuleSet & maxScalar(unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at most as wide as Ty.
LegalizeRuleSet & libcallForCartesianProduct(std::initializer_list< LLT > Types)
LegalizeRuleSet & lower()
The instruction is lowered.
LegalizeRuleSet & lowerFor(std::initializer_list< LLT > Types)
The instruction is lowered when type index 0 is any type in the given list.
LegalizeRuleSet & clampScalar(unsigned TypeIdx, const LLT MinTy, const LLT MaxTy)
Limit the range of scalar sizes to MinTy and MaxTy.
LegalizeRuleSet & alwaysLegal()
LegalizeRuleSet & legalForCartesianProduct(std::initializer_list< LLT > Types)
The instruction is legal when type indexes 0 and 1 are both in the given list.
LegalizeRuleSet & legalIf(LegalityPredicate Predicate)
The instruction is legal if predicate is true.
MachineIRBuilder & MIRBuilder
Expose MIRBuilder so clients can set their own RecordInsertInstruction functions.
LegalizeRuleSet & getActionDefinitionsBuilder(unsigned Opcode)
Get the action definition builder for the given opcode.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
Helper class to build MachineInstr.
MachineInstrBuilder buildFSub(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FSUB Op0, Op1.
MachineInstrBuilder buildUnmerge(ArrayRef< LLT > Res, const SrcOp &Op)
Build and insert Res0, ... = G_UNMERGE_VALUES Op.
const TargetInstrInfo & getTII()
MachineInstrBuilder buildLShr(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildAnyExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Res = COPY Op depending on the differing sizes of Res and Op.
MachineInstrBuilder buildMergeLikeInstr(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ... or Res = G_BUILD_VECTOR Op0, ... or Res = G_CONCAT_VEC...
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_PTR_ADD Op0, Op1.
virtual MachineInstrBuilder buildFConstant(const DstOp &Res, const ConstantFP &Val)
Build and insert Res = G_FCONSTANT Val.
MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_TRUNC Op.
MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ANYEXT Op0.
MachineRegisterInfo * getMRI()
Getter for MRI.
MachineInstrBuilder buildFPTrunc(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FPTRUNC Op.
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
Register getReg(unsigned Idx) const
Get the register for the operand index.
void constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
const MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
A description of a memory reference used in the backend.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
MipsLegalizerInfo(const MipsSubtarget &ST)
bool legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI, LostDebugLocObserver &LocObserver) const override
Called for instructions with the Custom LegalizationAction.
bool legalizeIntrinsic(LegalizerHelper &Helper, MachineInstr &MI) const override
Wrapper class representing virtual and physical registers.
Invariant opcodes: All instruction sets have these as their low opcodes.
This is an optimization pass for GlobalISel generic memory operations.
@ Load
The value being inserted comes from a load (InsertElement only).
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
To bit_cast(const From &from) noexcept
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool SystemSupportsUnalignedAccess
This struct is a compact representation of a valid (non-zero power of two) alignment.
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
ArrayRef< MemDesc > MMODescrs
Operations which require memory can use this to place requirements on the memory type for each MMO.
This class contains a discriminated union of information about pointers in memory operands,...