13#ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64ADDRESSINGMODES_H
14#define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64ADDRESSINGMODES_H
87 switch ((Imm >> 6) & 0x7) {
113 assert((Imm & 0x3f) == Imm &&
"Illegal shifted immediate value!");
123 return (STEnc << 6) | (Imm & 0x3f);
137 assert((Imm & 0x7) == Imm &&
"invalid immediate!");
185 assert((Imm & 0x7) == Imm &&
"Illegal shifted immediate value!");
192 return (Imm & 0x1) != 0;
219 return ((elt & 1) << (
size-1)) | (elt >> 1);
228 if (Imm == 0ULL || Imm == ~0ULL ||
240 if ((Imm & Mask) != ((Imm >>
Size) & Mask)) {
253 assert(
I < 64 &&
"undefined behavior");
268 assert(
Size >
I &&
"I should be smaller than element size");
280 unsigned N = ((NImms >> 6) & 1) ^ 1;
282 Encoding = (
N << 12) | (Immr << 6) | (NImms & 0x3f);
298 assert(res &&
"invalid logical immediate");
308 unsigned N = (val >> 12) & 1;
309 unsigned immr = (val >> 6) & 0x3f;
310 unsigned imms = val & 0x3f;
312 assert((regSize == 64 ||
N == 0) &&
"undefined logical immediate encoding");
314 assert(len >= 0 &&
"undefined logical immediate encoding");
315 unsigned size = (1 << len);
316 unsigned R = immr & (
size - 1);
317 unsigned S = imms & (
size - 1);
318 assert(S !=
size - 1 &&
"undefined logical immediate encoding");
319 uint64_t pattern = (1ULL << (S + 1)) - 1;
320 for (
unsigned i = 0; i < R; ++i)
324 while (
size != regSize) {
325 pattern |= (pattern <<
size);
337 unsigned N = (val >> 12) & 1;
338 unsigned imms = val & 0x3f;
340 if (regSize == 32 &&
N != 0)
345 unsigned size = (1 << len);
346 unsigned S = imms & (
size - 1);
356 return (
C >> 12 == 0) || ((
C & 0xFFFULL) == 0 &&
C >> 24 == 0);
363 "Tried to get the shift amount for an illegal immediate");
364 return C >> 12 == 0 ? 0 : 12;
381 uint8_t Sign = (Imm >> 7) & 0x1;
382 uint8_t Exp = (Imm >> 4) & 0x7;
392 I |= ((Exp & 0x4) != 0 ? 0 : 1) << 30;
393 I |= ((Exp & 0x4) != 0 ? 0x1f : 0) << 25;
394 I |= (Exp & 0x3) << 23;
403 uint32_t Sign = Imm.lshr(15).getZExtValue() & 1;
404 int32_t Exp = (Imm.lshr(10).getSExtValue() & 0x1f) - 15;
405 int32_t Mantissa = Imm.getZExtValue() & 0x3ff;
414 if (Exp < -3 || Exp > 4)
416 Exp = ((Exp+3) & 0x7) ^ 4;
418 return ((
int)Sign << 7) | (Exp << 4) | Mantissa;
429 uint32_t Sign = Imm.lshr(31).getZExtValue() & 1;
430 int32_t Exp = (Imm.lshr(23).getSExtValue() & 0xff) - 127;
431 int64_t Mantissa = Imm.getZExtValue() & 0x7fffff;
435 if (Mantissa & 0x7ffff)
438 if ((Mantissa & 0xf) != Mantissa)
442 if (Exp < -3 || Exp > 4)
444 Exp = ((Exp+3) & 0x7) ^ 4;
446 return ((
int)Sign << 7) | (Exp << 4) | Mantissa;
457 uint64_t Sign = Imm.lshr(63).getZExtValue() & 1;
458 int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023;
459 uint64_t Mantissa = Imm.getZExtValue() & 0xfffffffffffffULL;
463 if (Mantissa & 0xffffffffffffULL)
466 if ((Mantissa & 0xf) != Mantissa)
470 if (Exp < -3 || Exp > 4)
472 Exp = ((Exp+3) & 0x7) ^ 4;
474 return ((
int)Sign << 7) | (Exp << 4) | Mantissa;
487 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
488 ((Imm & 0xffffff00ffffff00ULL) == 0);
492 return (Imm & 0xffULL);
497 return (EncVal << 32) | EncVal;
502 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
503 ((Imm & 0xffff00ffffff00ffULL) == 0);
507 return (Imm & 0xff00ULL) >> 8;
512 return (EncVal << 40) | (EncVal << 8);
517 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
518 ((Imm & 0xff00ffffff00ffffULL) == 0);
522 return (Imm & 0xff0000ULL) >> 16;
527 return (EncVal << 48) | (EncVal << 16);
532 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
533 ((Imm & 0x00ffffff00ffffffULL) == 0);
537 return (Imm & 0xff000000ULL) >> 24;
542 return (EncVal << 56) | (EncVal << 24);
547 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
548 (((Imm & 0x00ff0000ULL) >> 16) == (Imm & 0x000000ffULL)) &&
549 ((Imm & 0xff00ff00ff00ff00ULL) == 0);
553 return (Imm & 0xffULL);
558 return (EncVal << 48) | (EncVal << 32) | (EncVal << 16) | EncVal;
563 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
564 (((Imm & 0xff000000ULL) >> 16) == (Imm & 0x0000ff00ULL)) &&
565 ((Imm & 0x00ff00ff00ff00ffULL) == 0);
569 return (Imm & 0xff00ULL) >> 8;
574 return (EncVal << 56) | (EncVal << 40) | (EncVal << 24) | (EncVal << 8);
579 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
580 ((Imm & 0xffff00ffffff00ffULL) == 0x000000ff000000ffULL);
584 return (Imm & 0xff00ULL) >> 8;
589 return (EncVal << 40) | (EncVal << 8) | 0x000000ff000000ffULL;
594 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
595 ((Imm & 0xff00ffffff00ffffULL) == 0x0000ffff0000ffffULL);
600 return (EncVal << 48) | (EncVal << 16) | 0x0000ffff0000ffffULL;
604 return (Imm & 0x00ff0000ULL) >> 16;
609 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
610 ((Imm >> 48) == (Imm & 0x0000ffffULL)) &&
611 ((Imm >> 56) == (Imm & 0x000000ffULL));
615 return (Imm & 0xffULL);
620 EncVal |= (EncVal << 8);
621 EncVal |= (EncVal << 16);
622 EncVal |= (EncVal << 32);
629#if defined(_MSC_VER) && _MSC_VER == 1937 && !defined(__clang__) && \
636 uint64_t ByteA = (Imm >> 56) & Mask;
637 uint64_t ByteB = (Imm >> 48) & Mask;
638 uint64_t ByteC = (Imm >> 40) & Mask;
639 uint64_t ByteD = (Imm >> 32) & Mask;
640 uint64_t ByteE = (Imm >> 24) & Mask;
641 uint64_t ByteF = (Imm >> 16) & Mask;
645 return (ByteA == 0ULL || ByteA == Mask) && (ByteB == 0ULL || ByteB == Mask) &&
646 (ByteC == 0ULL || ByteC == Mask) && (ByteD == 0ULL || ByteD == Mask) &&
647 (ByteE == 0ULL || ByteE == Mask) && (ByteF == 0ULL || ByteF == Mask) &&
648 (ByteG == 0ULL || ByteG == Mask) && (ByteH == 0ULL || ByteH == Mask);
650 uint64_t ByteA = Imm & 0xff00000000000000ULL;
651 uint64_t ByteB = Imm & 0x00ff000000000000ULL;
652 uint64_t ByteC = Imm & 0x0000ff0000000000ULL;
653 uint64_t ByteD = Imm & 0x000000ff00000000ULL;
654 uint64_t ByteE = Imm & 0x00000000ff000000ULL;
655 uint64_t ByteF = Imm & 0x0000000000ff0000ULL;
656 uint64_t ByteG = Imm & 0x000000000000ff00ULL;
657 uint64_t ByteH = Imm & 0x00000000000000ffULL;
659 return (ByteA == 0ULL || ByteA == 0xff00000000000000ULL) &&
660 (ByteB == 0ULL || ByteB == 0x00ff000000000000ULL) &&
661 (ByteC == 0ULL || ByteC == 0x0000ff0000000000ULL) &&
662 (ByteD == 0ULL || ByteD == 0x000000ff00000000ULL) &&
663 (ByteE == 0ULL || ByteE == 0x00000000ff000000ULL) &&
664 (ByteF == 0ULL || ByteF == 0x0000000000ff0000ULL) &&
665 (ByteG == 0ULL || ByteG == 0x000000000000ff00ULL) &&
666 (ByteH == 0ULL || ByteH == 0x00000000000000ffULL);
671 uint8_t BitA = (Imm & 0xff00000000000000ULL) != 0;
672 uint8_t BitB = (Imm & 0x00ff000000000000ULL) != 0;
673 uint8_t BitC = (Imm & 0x0000ff0000000000ULL) != 0;
674 uint8_t BitD = (Imm & 0x000000ff00000000ULL) != 0;
675 uint8_t BitE = (Imm & 0x00000000ff000000ULL) != 0;
676 uint8_t BitF = (Imm & 0x0000000000ff0000ULL) != 0;
677 uint8_t BitG = (Imm & 0x000000000000ff00ULL) != 0;
678 uint8_t BitH = (Imm & 0x00000000000000ffULL) != 0;
700 if (Imm & 0x80) EncVal |= 0xff00000000000000ULL;
701 if (Imm & 0x40) EncVal |= 0x00ff000000000000ULL;
702 if (Imm & 0x20) EncVal |= 0x0000ff0000000000ULL;
703 if (Imm & 0x10) EncVal |= 0x000000ff00000000ULL;
704 if (Imm & 0x08) EncVal |= 0x00000000ff000000ULL;
705 if (Imm & 0x04) EncVal |= 0x0000000000ff0000ULL;
706 if (Imm & 0x02) EncVal |= 0x000000000000ff00ULL;
707 if (Imm & 0x01) EncVal |= 0x00000000000000ffULL;
713 uint64_t BString = (Imm & 0x7E000000ULL) >> 25;
714 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
715 (BString == 0x1f || BString == 0x20) &&
716 ((Imm & 0x0007ffff0007ffffULL) == 0);
720 uint8_t BitA = (Imm & 0x80000000ULL) != 0;
721 uint8_t BitB = (Imm & 0x20000000ULL) != 0;
722 uint8_t BitC = (Imm & 0x01000000ULL) != 0;
723 uint8_t BitD = (Imm & 0x00800000ULL) != 0;
724 uint8_t BitE = (Imm & 0x00400000ULL) != 0;
725 uint8_t BitF = (Imm & 0x00200000ULL) != 0;
726 uint8_t BitG = (Imm & 0x00100000ULL) != 0;
727 uint8_t BitH = (Imm & 0x00080000ULL) != 0;
749 if (Imm & 0x80) EncVal |= 0x80000000ULL;
750 if (Imm & 0x40) EncVal |= 0x3e000000ULL;
751 else EncVal |= 0x40000000ULL;
752 if (Imm & 0x20) EncVal |= 0x01000000ULL;
753 if (Imm & 0x10) EncVal |= 0x00800000ULL;
754 if (Imm & 0x08) EncVal |= 0x00400000ULL;
755 if (Imm & 0x04) EncVal |= 0x00200000ULL;
756 if (Imm & 0x02) EncVal |= 0x00100000ULL;
757 if (Imm & 0x01) EncVal |= 0x00080000ULL;
758 return (EncVal << 32) | EncVal;
763 uint64_t BString = (Imm & 0x7fc0000000000000ULL) >> 54;
764 return ((BString == 0xff || BString == 0x100) &&
765 ((Imm & 0x0000ffffffffffffULL) == 0));
769 uint8_t BitA = (Imm & 0x8000000000000000ULL) != 0;
770 uint8_t BitB = (Imm & 0x0040000000000000ULL) != 0;
771 uint8_t BitC = (Imm & 0x0020000000000000ULL) != 0;
772 uint8_t BitD = (Imm & 0x0010000000000000ULL) != 0;
773 uint8_t BitE = (Imm & 0x0008000000000000ULL) != 0;
774 uint8_t BitF = (Imm & 0x0004000000000000ULL) != 0;
775 uint8_t BitG = (Imm & 0x0002000000000000ULL) != 0;
776 uint8_t BitH = (Imm & 0x0001000000000000ULL) != 0;
798 if (Imm & 0x80) EncVal |= 0x8000000000000000ULL;
799 if (Imm & 0x40) EncVal |= 0x3fc0000000000000ULL;
800 else EncVal |= 0x4000000000000000ULL;
801 if (Imm & 0x20) EncVal |= 0x0020000000000000ULL;
802 if (Imm & 0x10) EncVal |= 0x0010000000000000ULL;
803 if (Imm & 0x08) EncVal |= 0x0008000000000000ULL;
804 if (Imm & 0x04) EncVal |= 0x0004000000000000ULL;
805 if (Imm & 0x02) EncVal |= 0x0002000000000000ULL;
806 if (Imm & 0x01) EncVal |= 0x0001000000000000ULL;
813 auto Parts =
bit_cast<std::array<
T,
sizeof(int64_t) /
sizeof(
T)>>(Imm);
823 int64_t Mask = ~int64_t(std::numeric_limits<std::make_unsigned_t<T>>
::max());
824 if ((Imm & Mask) != 0 && (Imm & Mask) != Mask)
830 return int8_t(Imm) ==
T(Imm);
835 return int16_t(Imm) ==
T(Imm);
843 bool IsInt8t = std::is_same<int8_t, std::make_signed_t<T>>::value ||
844 std::is_same<int8_t, T>::value;
845 return uint8_t(Imm) == Imm || (!IsInt8t &&
uint16_t(Imm & ~0xff) == Imm);
867 for (
int Shift = 0; Shift <= RegWidth - 16; Shift += 16)
868 if ((
Value & ~(0xffffULL << Shift)) == 0)
876 Value &= 0xffffffffULL;
879 if (
Value == 0 && Shift != 0)
882 return (
Value & ~(0xffffULL << Shift)) == 0;
892 Value &= 0xffffffffULL;
904 Value &= 0xffffffffULL;
911 switch (SizeInBits) {
921 if (Val >= -128 && Val <= 127) {
927 if (Val >= -32768 && Val <= 32512 && Val % 256 == 0) {
929 Imm = (Val >> 8) & 0xFF;
942 switch (SizeInBits) {
945 ImmVal |= ImmVal << 8;
946 ImmVal |= ImmVal << 16;
947 ImmVal |= ImmVal << 32;
951 ImmVal |= ImmVal << 16;
952 ImmVal |= ImmVal << 32;
955 ImmVal &= 0xFFFFFFFF;
956 ImmVal |= ImmVal << 32;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file implements the C++20 <bit> header.
APInt bitcastToAPInt() const
Class for arbitrary precision integers.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
AArch64_AM - AArch64 Addressing Mode Stuff.
static bool isValidDecodeLogicalImmediate(uint64_t val, unsigned regSize)
isValidDecodeLogicalImmediate - Check to see if the logical immediate value in the form "N:immr:imms"...
static bool isSVEMoveMaskPreferredLogicalImmediate(int64_t Imm)
Return true if Imm is valid for DUPM and has no single CPY/DUP equivalent.
static bool isAnyMOVZMovAlias(uint64_t Value, int RegWidth)
static bool isMOVNMovAlias(uint64_t Value, int Shift, int RegWidth)
static uint64_t decodeLogicalImmediate(uint64_t val, unsigned regSize)
decodeLogicalImmediate - Decode a logical immediate value in the form "N:immr:imms" (where the immr a...
static unsigned getMemExtendImm(AArch64_AM::ShiftExtendType ET, bool DoShift)
getExtendImm - Encode the extend type and amount for a load/store inst: doshift: should the offset be...
static unsigned getShiftValue(unsigned Imm)
getShiftValue - Extract the shift value.
static uint64_t decodeAdvSIMDModImmType4(uint8_t Imm)
static bool isLogicalImmediate(uint64_t imm, unsigned regSize)
isLogicalImmediate - Return true if the immediate is valid for a logical immediate instruction of the...
static uint8_t encodeAdvSIMDModImmType2(uint64_t Imm)
static bool isSVEAddSubImm(int64_t Imm)
Returns true if Imm is valid for ADD/SUB.
static bool processLogicalImmediate(uint64_t Imm, unsigned RegSize, uint64_t &Encoding)
processLogicalImmediate - Determine if an immediate value can be encoded as the immediate operand of ...
static bool isAdvSIMDModImmType9(uint64_t Imm)
static uint64_t decodeAdvSIMDModImmType2(uint8_t Imm)
static bool isAdvSIMDModImmType4(uint64_t Imm)
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
static uint64_t decodeAdvSIMDModImmType12(uint8_t Imm)
constexpr bool isLegalArithImmed(const uint64_t C)
isLegalArithImmed -
static bool isAdvSIMDModImmType5(uint64_t Imm)
static bool isAnyMOVWMovAlias(uint64_t Value, int RegWidth)
static unsigned getArithShiftValue(unsigned Imm)
getArithShiftValue - get the arithmetic shift value.
static uint64_t decodeAdvSIMDModImmType11(uint8_t Imm)
static int getFP32Imm(const APInt &Imm)
getFP32Imm - Return an 8-bit floating-point version of the 32-bit floating-point value.
static float getFPImmFloat(unsigned Imm)
static AArch64_AM::ShiftExtendType getMemExtendType(unsigned Imm)
getExtendType - Extract the extend type for the offset operand of loads/stores.
static uint8_t encodeAdvSIMDModImmType7(uint64_t Imm)
static uint64_t decodeAdvSIMDModImmType1(uint8_t Imm)
static uint8_t encodeAdvSIMDModImmType12(uint64_t Imm)
static uint8_t encodeAdvSIMDModImmType10(uint64_t Imm)
static uint8_t encodeAdvSIMDModImmType9(uint64_t Imm)
static bool isSVEMaskOfIdenticalElements(int64_t Imm)
Returns true if Imm is the concatenation of a repeating pattern of type T.
static bool isMOVZMovAlias(uint64_t Value, int Shift, int RegWidth)
static uint64_t encodeLogicalImmediate(uint64_t imm, unsigned regSize)
encodeLogicalImmediate - Return the encoded immediate value for a logical immediate instruction of th...
static const char * getShiftExtendName(AArch64_AM::ShiftExtendType ST)
getShiftName - Get the string encoding for the shift type.
static bool isLegalCmpImmed(const APInt &C)
isLegalCmpImmed -
static bool isAdvSIMDModImmType7(uint64_t Imm)
static uint64_t decodeAdvSIMDModImmType3(uint8_t Imm)
static uint64_t decodeAdvSIMDModImmType7(uint8_t Imm)
unsigned getExtendEncoding(AArch64_AM::ShiftExtendType ET)
Mapping from extend bits to required operation: shifter: 000 ==> uxtb 001 ==> uxth 010 ==> uxtw 011 =...
static bool isSVECpyImm(int64_t Imm)
Returns true if Imm is valid for CPY/DUP.
static uint8_t encodeAdvSIMDModImmType5(uint64_t Imm)
static int getFP64Imm(const APInt &Imm)
getFP64Imm - Return an 8-bit floating-point version of the 64-bit floating-point value.
static uint64_t ror(uint64_t elt, unsigned size)
static bool isAdvSIMDModImmType10(uint64_t Imm)
static AArch64_AM::ShiftExtendType getExtendType(unsigned Imm)
getExtendType - Extract the extend type for operands of arithmetic ops.
static int getFP16Imm(const APInt &Imm)
getFP16Imm - Return an 8-bit floating-point version of the 16-bit floating-point value.
static uint64_t decodeAdvSIMDModImmType9(uint8_t Imm)
static uint64_t decodeAdvSIMDModImmType10(uint8_t Imm)
static uint64_t decodeAdvSIMDModImmType5(uint8_t Imm)
static uint64_t decodeAdvSIMDModImmType8(uint8_t Imm)
static uint8_t encodeAdvSIMDModImmType8(uint64_t Imm)
static bool isAdvSIMDModImmType12(uint64_t Imm)
static bool isSVELogicalImm(unsigned SizeInBits, uint64_t ImmVal, uint64_t &Encoding)
constexpr unsigned getArithImmedShift(const uint64_t C)
getArithImmedShift - assumes C is a legal immediate for arithmetic instructions and
static uint8_t encodeAdvSIMDModImmType11(uint64_t Imm)
static AArch64_AM::ShiftExtendType getArithExtendType(unsigned Imm)
static bool isSVECpyDupImm(int SizeInBits, int64_t Val, int32_t &Imm, int32_t &Shift)
static bool isAdvSIMDModImmType11(uint64_t Imm)
static uint8_t encodeAdvSIMDModImmType6(uint64_t Imm)
static AArch64_AM::ShiftExtendType getShiftType(unsigned Imm)
getShiftType - Extract the shift type.
static bool isAdvSIMDModImmType8(uint64_t Imm)
static uint8_t encodeAdvSIMDModImmType4(uint64_t Imm)
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 ==...
static bool isAdvSIMDModImmType6(uint64_t Imm)
static bool getMemDoShift(unsigned Imm)
getMemDoShift - Extract the "do shift" flag value for load/store instructions.
static uint8_t encodeAdvSIMDModImmType1(uint64_t Imm)
static uint8_t encodeAdvSIMDModImmType3(uint64_t Imm)
static bool isAdvSIMDModImmType2(uint64_t Imm)
static uint64_t decodeAdvSIMDModImmType6(uint8_t Imm)
static bool isAdvSIMDModImmType3(uint64_t Imm)
static bool isSignExtendShiftType(AArch64_AM::ShiftExtendType Type)
isSignExtendShiftType - Returns true if Type is sign extending.
static bool isAdvSIMDModImmType1(uint64_t Imm)
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
int countr_one(T Value)
Count the number of ones from the least significant bit to the first zero bit.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
int countl_one(T Value)
Count the number of ones from the most significant bit to the first zero bit.
To bit_cast(const From &from) noexcept
constexpr NextUseDistance max(NextUseDistance A, NextUseDistance B)
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.