Path: blob/main/contrib/llvm-project/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
35294 views
//===-- X86BaseInfo.h - Top level definitions for X86 -------- --*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains small standalone helper functions and enum definitions for9// the X86 target useful for the compiler back-end and the MC libraries.10// As such, it deliberately does not include references to LLVM core11// code gen types, passes, etc..12//13//===----------------------------------------------------------------------===//1415#ifndef LLVM_LIB_TARGET_X86_MCTARGETDESC_X86BASEINFO_H16#define LLVM_LIB_TARGET_X86_MCTARGETDESC_X86BASEINFO_H1718#include "X86MCTargetDesc.h"19#include "llvm/MC/MCInstrDesc.h"20#include "llvm/Support/DataTypes.h"21#include "llvm/Support/ErrorHandling.h"2223namespace llvm {24namespace X86 {25// Enums for memory operand decoding. Each memory operand is represented with26// a 5 operand sequence in the form: [Base, Scale, Index, Disp, Segment]27enum {28AddrBaseReg = 0,29AddrScaleAmt = 1,30AddrIndexReg = 2,31AddrDisp = 3,32// The operand # of the segment in the memory operand.33AddrSegmentReg = 4,34// Total number of operands in a memory reference.35AddrNumOperands = 536};3738/// AVX512 static rounding constants. These need to match the values in39/// avx512fintrin.h.40enum STATIC_ROUNDING {41TO_NEAREST_INT = 0,42TO_NEG_INF = 1,43TO_POS_INF = 2,44TO_ZERO = 3,45CUR_DIRECTION = 4,46NO_EXC = 847};4849/// The constants to describe instr prefixes if there are50enum IPREFIXES {51IP_NO_PREFIX = 0,52IP_HAS_OP_SIZE = 1U << 0,53IP_HAS_AD_SIZE = 1U << 1,54IP_HAS_REPEAT_NE = 1U << 2,55IP_HAS_REPEAT = 1U << 3,56IP_HAS_LOCK = 1U << 4,57IP_HAS_NOTRACK = 1U << 5,58IP_USE_REX = 1U << 6,59IP_USE_REX2 = 1U << 7,60IP_USE_VEX = 1U << 8,61IP_USE_VEX2 = 1U << 9,62IP_USE_VEX3 = 1U << 10,63IP_USE_EVEX = 1U << 11,64IP_USE_DISP8 = 1U << 12,65IP_USE_DISP32 = 1U << 13,66};6768enum OperandType : unsigned {69// AVX512 embedded rounding control. This should only have values 0-3.70OPERAND_ROUNDING_CONTROL = MCOI::OPERAND_FIRST_TARGET,71OPERAND_COND_CODE,72};7374// X86 specific condition code. These correspond to X86_*_COND in75// X86InstrInfo.td. They must be kept in synch.76enum CondCode {77COND_O = 0,78COND_NO = 1,79COND_B = 2,80COND_AE = 3,81COND_E = 4,82COND_NE = 5,83COND_BE = 6,84COND_A = 7,85COND_S = 8,86COND_NS = 9,87COND_P = 10,88COND_NP = 11,89COND_L = 12,90COND_GE = 13,91COND_LE = 14,92COND_G = 15,93LAST_VALID_COND = COND_G,94// Artificial condition codes. These are used by analyzeBranch95// to indicate a block terminated with two conditional branches that together96// form a compound condition. They occur in code using FCMP_OEQ or FCMP_UNE,97// which can't be represented on x86 with a single condition. These98// are never used in MachineInstrs and are inverses of one another.99COND_NE_OR_P,100COND_E_AND_NP,101COND_INVALID102};103104// The classification for the first instruction in macro fusion.105// FIXME: Zen 3 support branch fusion for OR/XOR.106enum class FirstMacroFusionInstKind {107Test, // TEST108Cmp, // CMP109And, // AND110AddSub, // ADD, SUB111IncDec, // INC, DEC112Invalid // Not valid as a first macro fusion instruction113};114115enum class SecondMacroFusionInstKind {116AB, // JA, JB and variants117ELG, // JE, JL, JG and variants118SPO, // JS, JP, JO and variants119Invalid, // Not a fusible jump.120};121122/// \returns the type of the first instruction in macro-fusion.123// FIXME: Zen 3 support branch fusion for OR/XOR.124inline FirstMacroFusionInstKind125classifyFirstOpcodeInMacroFusion(unsigned Opcode) {126switch (Opcode) {127default:128return FirstMacroFusionInstKind::Invalid;129// TEST130case X86::TEST16i16:131case X86::TEST16mr:132case X86::TEST16ri:133case X86::TEST16rr:134case X86::TEST32i32:135case X86::TEST32mr:136case X86::TEST32ri:137case X86::TEST32rr:138case X86::TEST64i32:139case X86::TEST64mr:140case X86::TEST64ri32:141case X86::TEST64rr:142case X86::TEST8i8:143case X86::TEST8mr:144case X86::TEST8ri:145case X86::TEST8rr:146return FirstMacroFusionInstKind::Test;147case X86::AND16i16:148case X86::AND16ri:149case X86::AND16ri8:150case X86::AND16rm:151case X86::AND16rr:152case X86::AND32i32:153case X86::AND32ri:154case X86::AND32ri8:155case X86::AND32rm:156case X86::AND32rr:157case X86::AND64i32:158case X86::AND64ri32:159case X86::AND64ri8:160case X86::AND64rm:161case X86::AND64rr:162case X86::AND8i8:163case X86::AND8ri:164case X86::AND8ri8:165case X86::AND8rm:166case X86::AND8rr:167return FirstMacroFusionInstKind::And;168// CMP169case X86::CMP16i16:170case X86::CMP16mr:171case X86::CMP16ri:172case X86::CMP16ri8:173case X86::CMP16rm:174case X86::CMP16rr:175case X86::CMP32i32:176case X86::CMP32mr:177case X86::CMP32ri:178case X86::CMP32ri8:179case X86::CMP32rm:180case X86::CMP32rr:181case X86::CMP64i32:182case X86::CMP64mr:183case X86::CMP64ri32:184case X86::CMP64ri8:185case X86::CMP64rm:186case X86::CMP64rr:187case X86::CMP8i8:188case X86::CMP8mr:189case X86::CMP8ri:190case X86::CMP8ri8:191case X86::CMP8rm:192case X86::CMP8rr:193return FirstMacroFusionInstKind::Cmp;194// ADD195case X86::ADD16i16:196case X86::ADD16ri:197case X86::ADD16ri8:198case X86::ADD16rm:199case X86::ADD16rr:200case X86::ADD32i32:201case X86::ADD32ri:202case X86::ADD32ri8:203case X86::ADD32rm:204case X86::ADD32rr:205case X86::ADD64i32:206case X86::ADD64ri32:207case X86::ADD64ri8:208case X86::ADD64rm:209case X86::ADD64rr:210case X86::ADD8i8:211case X86::ADD8ri:212case X86::ADD8ri8:213case X86::ADD8rm:214case X86::ADD8rr:215// SUB216case X86::SUB16i16:217case X86::SUB16ri:218case X86::SUB16ri8:219case X86::SUB16rm:220case X86::SUB16rr:221case X86::SUB32i32:222case X86::SUB32ri:223case X86::SUB32ri8:224case X86::SUB32rm:225case X86::SUB32rr:226case X86::SUB64i32:227case X86::SUB64ri32:228case X86::SUB64ri8:229case X86::SUB64rm:230case X86::SUB64rr:231case X86::SUB8i8:232case X86::SUB8ri:233case X86::SUB8ri8:234case X86::SUB8rm:235case X86::SUB8rr:236return FirstMacroFusionInstKind::AddSub;237// INC238case X86::INC16r:239case X86::INC16r_alt:240case X86::INC32r:241case X86::INC32r_alt:242case X86::INC64r:243case X86::INC8r:244// DEC245case X86::DEC16r:246case X86::DEC16r_alt:247case X86::DEC32r:248case X86::DEC32r_alt:249case X86::DEC64r:250case X86::DEC8r:251return FirstMacroFusionInstKind::IncDec;252}253}254255/// \returns the type of the second instruction in macro-fusion.256inline SecondMacroFusionInstKind257classifySecondCondCodeInMacroFusion(X86::CondCode CC) {258if (CC == X86::COND_INVALID)259return SecondMacroFusionInstKind::Invalid;260switch (CC) {261default:262return SecondMacroFusionInstKind::Invalid;263case X86::COND_E: // JE,JZ264case X86::COND_NE: // JNE,JNZ265case X86::COND_L: // JL,JNGE266case X86::COND_LE: // JLE,JNG267case X86::COND_G: // JG,JNLE268case X86::COND_GE: // JGE,JNL269return SecondMacroFusionInstKind::ELG;270case X86::COND_B: // JB,JC271case X86::COND_BE: // JNA,JBE272case X86::COND_A: // JA,JNBE273case X86::COND_AE: // JAE,JNC,JNB274return SecondMacroFusionInstKind::AB;275case X86::COND_S: // JS276case X86::COND_NS: // JNS277case X86::COND_P: // JP,JPE278case X86::COND_NP: // JNP,JPO279case X86::COND_O: // JO280case X86::COND_NO: // JNO281return SecondMacroFusionInstKind::SPO;282}283}284285/// \param FirstKind kind of the first instruction in macro fusion.286/// \param SecondKind kind of the second instruction in macro fusion.287///288/// \returns true if the two instruction can be macro fused.289inline bool isMacroFused(FirstMacroFusionInstKind FirstKind,290SecondMacroFusionInstKind SecondKind) {291switch (FirstKind) {292case X86::FirstMacroFusionInstKind::Test:293case X86::FirstMacroFusionInstKind::And:294return true;295case X86::FirstMacroFusionInstKind::Cmp:296case X86::FirstMacroFusionInstKind::AddSub:297return SecondKind == X86::SecondMacroFusionInstKind::AB ||298SecondKind == X86::SecondMacroFusionInstKind::ELG;299case X86::FirstMacroFusionInstKind::IncDec:300return SecondKind == X86::SecondMacroFusionInstKind::ELG;301case X86::FirstMacroFusionInstKind::Invalid:302return false;303}304llvm_unreachable("unknown fusion type");305}306307/// Defines the possible values of the branch boundary alignment mask.308enum AlignBranchBoundaryKind : uint8_t {309AlignBranchNone = 0,310AlignBranchFused = 1U << 0,311AlignBranchJcc = 1U << 1,312AlignBranchJmp = 1U << 2,313AlignBranchCall = 1U << 3,314AlignBranchRet = 1U << 4,315AlignBranchIndirect = 1U << 5316};317318/// Defines the encoding values for segment override prefix.319enum EncodingOfSegmentOverridePrefix : uint8_t {320CS_Encoding = 0x2E,321DS_Encoding = 0x3E,322ES_Encoding = 0x26,323FS_Encoding = 0x64,324GS_Encoding = 0x65,325SS_Encoding = 0x36326};327328/// Given a segment register, return the encoding of the segment override329/// prefix for it.330inline EncodingOfSegmentOverridePrefix331getSegmentOverridePrefixForReg(unsigned Reg) {332switch (Reg) {333default:334llvm_unreachable("Unknown segment register!");335case X86::CS:336return CS_Encoding;337case X86::DS:338return DS_Encoding;339case X86::ES:340return ES_Encoding;341case X86::FS:342return FS_Encoding;343case X86::GS:344return GS_Encoding;345case X86::SS:346return SS_Encoding;347}348}349350} // namespace X86351352/// X86II - This namespace holds all of the target specific flags that353/// instruction info tracks.354///355namespace X86II {356/// Target Operand Flag enum.357enum TOF {358//===------------------------------------------------------------------===//359// X86 Specific MachineOperand flags.360//361/// MO_NO_FLAG - No flag for the operand362MO_NO_FLAG,363/// MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a364/// relocation of:365/// SYMBOL_LABEL + [. - PICBASELABEL]366MO_GOT_ABSOLUTE_ADDRESS,367/// MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the368/// immediate should get the value of the symbol minus the PIC base label:369/// SYMBOL_LABEL - PICBASELABEL370MO_PIC_BASE_OFFSET,371/// MO_GOT - On a symbol operand this indicates that the immediate is the372/// offset to the GOT entry for the symbol name from the base of the GOT.373/// See the X86-64 ELF ABI supplement for more details.374/// SYMBOL_LABEL @GOT375MO_GOT,376/// MO_GOTOFF - On a symbol operand this indicates that the immediate is377/// the offset to the location of the symbol name from the base of the GOT.378/// See the X86-64 ELF ABI supplement for more details.379/// SYMBOL_LABEL @GOTOFF380MO_GOTOFF,381/// MO_GOTPCREL - On a symbol operand this indicates that the immediate is382/// offset to the GOT entry for the symbol name from the current code383/// location.384/// See the X86-64 ELF ABI supplement for more details.385/// SYMBOL_LABEL @GOTPCREL386MO_GOTPCREL,387/// MO_GOTPCREL_NORELAX - Same as MO_GOTPCREL except that R_X86_64_GOTPCREL388/// relocations are guaranteed to be emitted by the integrated assembler389/// instead of the relaxable R_X86_64[_REX]_GOTPCRELX relocations.390MO_GOTPCREL_NORELAX,391/// MO_PLT - On a symbol operand this indicates that the immediate is392/// offset to the PLT entry of symbol name from the current code location.393/// See the X86-64 ELF ABI supplement for more details.394/// SYMBOL_LABEL @PLT395MO_PLT,396/// MO_TLSGD - On a symbol operand this indicates that the immediate is397/// the offset of the GOT entry with the TLS index structure that contains398/// the module number and variable offset for the symbol. Used in the399/// general dynamic TLS access model.400/// See 'ELF Handling for Thread-Local Storage' for more details.401/// SYMBOL_LABEL @TLSGD402MO_TLSGD,403/// MO_TLSLD - On a symbol operand this indicates that the immediate is404/// the offset of the GOT entry with the TLS index for the module that405/// contains the symbol. When this index is passed to a call to406/// __tls_get_addr, the function will return the base address of the TLS407/// block for the symbol. Used in the x86-64 local dynamic TLS access model.408/// See 'ELF Handling for Thread-Local Storage' for more details.409/// SYMBOL_LABEL @TLSLD410MO_TLSLD,411/// MO_TLSLDM - On a symbol operand this indicates that the immediate is412/// the offset of the GOT entry with the TLS index for the module that413/// contains the symbol. When this index is passed to a call to414/// ___tls_get_addr, the function will return the base address of the TLS415/// block for the symbol. Used in the IA32 local dynamic TLS access model.416/// See 'ELF Handling for Thread-Local Storage' for more details.417/// SYMBOL_LABEL @TLSLDM418MO_TLSLDM,419/// MO_GOTTPOFF - On a symbol operand this indicates that the immediate is420/// the offset of the GOT entry with the thread-pointer offset for the421/// symbol. Used in the x86-64 initial exec TLS access model.422/// See 'ELF Handling for Thread-Local Storage' for more details.423/// SYMBOL_LABEL @GOTTPOFF424MO_GOTTPOFF,425/// MO_INDNTPOFF - On a symbol operand this indicates that the immediate is426/// the absolute address of the GOT entry with the negative thread-pointer427/// offset for the symbol. Used in the non-PIC IA32 initial exec TLS access428/// model.429/// See 'ELF Handling for Thread-Local Storage' for more details.430/// SYMBOL_LABEL @INDNTPOFF431MO_INDNTPOFF,432/// MO_TPOFF - On a symbol operand this indicates that the immediate is433/// the thread-pointer offset for the symbol. Used in the x86-64 local434/// exec TLS access model.435/// See 'ELF Handling for Thread-Local Storage' for more details.436/// SYMBOL_LABEL @TPOFF437MO_TPOFF,438/// MO_DTPOFF - On a symbol operand this indicates that the immediate is439/// the offset of the GOT entry with the TLS offset of the symbol. Used440/// in the local dynamic TLS access model.441/// See 'ELF Handling for Thread-Local Storage' for more details.442/// SYMBOL_LABEL @DTPOFF443MO_DTPOFF,444/// MO_NTPOFF - On a symbol operand this indicates that the immediate is445/// the negative thread-pointer offset for the symbol. Used in the IA32446/// local exec TLS access model.447/// See 'ELF Handling for Thread-Local Storage' for more details.448/// SYMBOL_LABEL @NTPOFF449MO_NTPOFF,450/// MO_GOTNTPOFF - On a symbol operand this indicates that the immediate is451/// the offset of the GOT entry with the negative thread-pointer offset for452/// the symbol. Used in the PIC IA32 initial exec TLS access model.453/// See 'ELF Handling for Thread-Local Storage' for more details.454/// SYMBOL_LABEL @GOTNTPOFF455MO_GOTNTPOFF,456/// MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the457/// reference is actually to the "__imp_FOO" symbol. This is used for458/// dllimport linkage on windows.459MO_DLLIMPORT,460/// MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the461/// reference is actually to the "FOO$non_lazy_ptr" symbol, which is a462/// non-PIC-base-relative reference to a non-hidden dyld lazy pointer stub.463MO_DARWIN_NONLAZY,464/// MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates465/// that the reference is actually to "FOO$non_lazy_ptr - PICBASE", which is466/// a PIC-base-relative reference to a non-hidden dyld lazy pointer stub.467MO_DARWIN_NONLAZY_PIC_BASE,468/// MO_TLVP - On a symbol operand this indicates that the immediate is469/// some TLS offset.470/// This is the TLS offset for the Darwin TLS mechanism.471MO_TLVP,472/// MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate473/// is some TLS offset from the picbase.474/// This is the 32-bit TLS offset for Darwin TLS in PIC mode.475MO_TLVP_PIC_BASE,476/// MO_SECREL - On a symbol operand this indicates that the immediate is477/// the offset from beginning of section.478/// This is the TLS offset for the COFF/Windows TLS mechanism.479MO_SECREL,480/// MO_ABS8 - On a symbol operand this indicates that the symbol is known481/// to be an absolute symbol in range [0,128), so we can use the @ABS8482/// symbol modifier.483MO_ABS8,484/// MO_COFFSTUB - On a symbol operand "FOO", this indicates that the485/// reference is actually to the ".refptr.FOO" symbol. This is used for486/// stub symbols on windows.487MO_COFFSTUB,488};489490enum : uint64_t {491//===------------------------------------------------------------------===//492// Instruction encodings. These are the standard/most common forms for X86493// instructions.494//495/// PseudoFrm - This represents an instruction that is a pseudo instruction496/// or one that has not been implemented yet. It is illegal to code generate497/// it, but tolerated for intermediate implementation stages.498Pseudo = 0,499/// Raw - This form is for instructions that don't have any operands, so500/// they are just a fixed opcode value, like 'leave'.501RawFrm = 1,502/// AddRegFrm - This form is used for instructions like 'push r32' that have503/// their one register operand added to their opcode.504AddRegFrm = 2,505/// RawFrmMemOffs - This form is for instructions that store an absolute506/// memory offset as an immediate with a possible segment override.507RawFrmMemOffs = 3,508/// RawFrmSrc - This form is for instructions that use the source index509/// register SI/ESI/RSI with a possible segment override.510RawFrmSrc = 4,511/// RawFrmDst - This form is for instructions that use the destination index512/// register DI/EDI/RDI.513RawFrmDst = 5,514/// RawFrmDstSrc - This form is for instructions that use the source index515/// register SI/ESI/RSI with a possible segment override, and also the516/// destination index register DI/EDI/RDI.517RawFrmDstSrc = 6,518/// RawFrmImm8 - This is used for the ENTER instruction, which has two519/// immediates, the first of which is a 16-bit immediate (specified by520/// the imm encoding) and the second is a 8-bit fixed value.521RawFrmImm8 = 7,522/// RawFrmImm16 - This is used for CALL FAR instructions, which have two523/// immediates, the first of which is a 16 or 32-bit immediate (specified by524/// the imm encoding) and the second is a 16-bit fixed value. In the AMD525/// manual, this operand is described as pntr16:32 and pntr16:16526RawFrmImm16 = 8,527/// AddCCFrm - This form is used for Jcc that encode the condition code528/// in the lower 4 bits of the opcode.529AddCCFrm = 9,530/// PrefixByte - This form is used for instructions that represent a prefix531/// byte like data16 or rep.532PrefixByte = 10,533/// MRMDestRegCC - This form is used for the cfcmov instructions, which use534/// the Mod/RM byte to specify the operands reg(r/m) and reg(reg) and also535/// encodes a condition code.536MRMDestRegCC = 18,537/// MRMDestMemCC - This form is used for the cfcmov instructions, which use538/// the Mod/RM byte to specify the operands mem(r/m) and reg(reg) and also539/// encodes a condition code.540MRMDestMemCC = 19,541/// MRMDestMem4VOp3CC - This form is used for instructions that use the Mod/RM542/// byte to specify a destination which in this case is memory and operand 3543/// with VEX.VVVV, and also encodes a condition code.544MRMDestMem4VOp3CC = 20,545/// Instructions operate on a register Reg/Opcode operand not the r/m field.546MRMr0 = 21,547/// MRMSrcMem - But force to use the SIB field.548MRMSrcMemFSIB = 22,549/// MRMDestMem - But force to use the SIB field.550MRMDestMemFSIB = 23,551/// MRMDestMem - This form is used for instructions that use the Mod/RM byte552/// to specify a destination, which in this case is memory.553MRMDestMem = 24,554/// MRMSrcMem - This form is used for instructions that use the Mod/RM byte555/// to specify a source, which in this case is memory.556MRMSrcMem = 25,557/// MRMSrcMem4VOp3 - This form is used for instructions that encode558/// operand 3 with VEX.VVVV and load from memory.559MRMSrcMem4VOp3 = 26,560/// MRMSrcMemOp4 - This form is used for instructions that use the Mod/RM561/// byte to specify the fourth source, which in this case is memory.562MRMSrcMemOp4 = 27,563/// MRMSrcMemCC - This form is used for instructions that use the Mod/RM564/// byte to specify the operands and also encodes a condition code.565MRMSrcMemCC = 28,566/// MRMXm - This form is used for instructions that use the Mod/RM byte567/// to specify a memory source, but doesn't use the middle field. And has568/// a condition code.569MRMXmCC = 30,570/// MRMXm - This form is used for instructions that use the Mod/RM byte571/// to specify a memory source, but doesn't use the middle field.572MRMXm = 31,573/// MRM0m-MRM7m - Instructions that operate on a memory r/m operand and use574/// reg field to hold extended opcode, which is represented as /0, /1, ...575MRM0m = 32, // Format /0576MRM1m = 33, // Format /1577MRM2m = 34, // Format /2578MRM3m = 35, // Format /3579MRM4m = 36, // Format /4580MRM5m = 37, // Format /5581MRM6m = 38, // Format /6582MRM7m = 39, // Format /7583/// MRMDestReg - This form is used for instructions that use the Mod/RM byte584/// to specify a destination, which in this case is a register.585MRMDestReg = 40,586/// MRMSrcReg - This form is used for instructions that use the Mod/RM byte587/// to specify a source, which in this case is a register.588MRMSrcReg = 41,589/// MRMSrcReg4VOp3 - This form is used for instructions that encode590/// operand 3 with VEX.VVVV and do not load from memory.591MRMSrcReg4VOp3 = 42,592/// MRMSrcRegOp4 - This form is used for instructions that use the Mod/RM593/// byte to specify the fourth source, which in this case is a register.594MRMSrcRegOp4 = 43,595/// MRMSrcRegCC - This form is used for instructions that use the Mod/RM596/// byte to specify the operands and also encodes a condition code597MRMSrcRegCC = 44,598/// MRMXCCr - This form is used for instructions that use the Mod/RM byte599/// to specify a register source, but doesn't use the middle field. And has600/// a condition code.601MRMXrCC = 46,602/// MRMXr - This form is used for instructions that use the Mod/RM byte603/// to specify a register source, but doesn't use the middle field.604MRMXr = 47,605/// MRM0r-MRM7r - Instructions that operate on a register r/m operand and use606/// reg field to hold extended opcode, which is represented as /0, /1, ...607MRM0r = 48, // Format /0608MRM1r = 49, // Format /1609MRM2r = 50, // Format /2610MRM3r = 51, // Format /3611MRM4r = 52, // Format /4612MRM5r = 53, // Format /5613MRM6r = 54, // Format /6614MRM7r = 55, // Format /7615/// MRM0X-MRM7X - Instructions that operate that have mod=11 and an opcode but616/// ignore r/m.617MRM0X = 56, // Format /0618MRM1X = 57, // Format /1619MRM2X = 58, // Format /2620MRM3X = 59, // Format /3621MRM4X = 60, // Format /4622MRM5X = 61, // Format /5623MRM6X = 62, // Format /6624MRM7X = 63, // Format /7625/// MRM_XX (XX: C0-FF)- A mod/rm byte of exactly 0xXX.626MRM_C0 = 64,627MRM_C1 = 65,628MRM_C2 = 66,629MRM_C3 = 67,630MRM_C4 = 68,631MRM_C5 = 69,632MRM_C6 = 70,633MRM_C7 = 71,634MRM_C8 = 72,635MRM_C9 = 73,636MRM_CA = 74,637MRM_CB = 75,638MRM_CC = 76,639MRM_CD = 77,640MRM_CE = 78,641MRM_CF = 79,642MRM_D0 = 80,643MRM_D1 = 81,644MRM_D2 = 82,645MRM_D3 = 83,646MRM_D4 = 84,647MRM_D5 = 85,648MRM_D6 = 86,649MRM_D7 = 87,650MRM_D8 = 88,651MRM_D9 = 89,652MRM_DA = 90,653MRM_DB = 91,654MRM_DC = 92,655MRM_DD = 93,656MRM_DE = 94,657MRM_DF = 95,658MRM_E0 = 96,659MRM_E1 = 97,660MRM_E2 = 98,661MRM_E3 = 99,662MRM_E4 = 100,663MRM_E5 = 101,664MRM_E6 = 102,665MRM_E7 = 103,666MRM_E8 = 104,667MRM_E9 = 105,668MRM_EA = 106,669MRM_EB = 107,670MRM_EC = 108,671MRM_ED = 109,672MRM_EE = 110,673MRM_EF = 111,674MRM_F0 = 112,675MRM_F1 = 113,676MRM_F2 = 114,677MRM_F3 = 115,678MRM_F4 = 116,679MRM_F5 = 117,680MRM_F6 = 118,681MRM_F7 = 119,682MRM_F8 = 120,683MRM_F9 = 121,684MRM_FA = 122,685MRM_FB = 123,686MRM_FC = 124,687MRM_FD = 125,688MRM_FE = 126,689MRM_FF = 127,690FormMask = 127,691//===------------------------------------------------------------------===//692// Actual flags...693/// OpSize - OpSizeFixed implies instruction never needs a 0x66 prefix.694/// OpSize16 means this is a 16-bit instruction and needs 0x66 prefix in695/// 32-bit mode. OpSize32 means this is a 32-bit instruction needs a 0x66696/// prefix in 16-bit mode.697OpSizeShift = 7,698OpSizeMask = 0x3 << OpSizeShift,699OpSizeFixed = 0 << OpSizeShift,700OpSize16 = 1 << OpSizeShift,701OpSize32 = 2 << OpSizeShift,702/// AsSize - AdSizeX implies this instruction determines its need of 0x67703/// prefix from a normal ModRM memory operand. The other types indicate that704/// an operand is encoded with a specific width and a prefix is needed if705/// it differs from the current mode.706AdSizeShift = OpSizeShift + 2,707AdSizeMask = 0x3 << AdSizeShift,708AdSizeX = 0 << AdSizeShift,709AdSize16 = 1 << AdSizeShift,710AdSize32 = 2 << AdSizeShift,711AdSize64 = 3 << AdSizeShift,712//===------------------------------------------------------------------===//713/// OpPrefix - There are several prefix bytes that are used as opcode714/// extensions. These are 0x66, 0xF3, and 0xF2. If this field is 0 there is715/// no prefix.716OpPrefixShift = AdSizeShift + 2,717OpPrefixMask = 0x3 << OpPrefixShift,718/// PD - Prefix code for packed double precision vector floating point719/// operations performed in the SSE registers.720PD = 1 << OpPrefixShift,721/// XS, XD - These prefix codes are for single and double precision scalar722/// floating point operations performed in the SSE registers.723XS = 2 << OpPrefixShift,724XD = 3 << OpPrefixShift,725//===------------------------------------------------------------------===//726/// OpMap - This field determines which opcode map this instruction727/// belongs to. i.e. one-byte, two-byte, 0x0f 0x38, 0x0f 0x3a, etc.728OpMapShift = OpPrefixShift + 2,729OpMapMask = 0xF << OpMapShift,730/// OB - OneByte - Set if this instruction has a one byte opcode.731OB = 0 << OpMapShift,732/// TB - TwoByte - Set if this instruction has a two byte opcode, which733/// starts with a 0x0F byte before the real opcode.734TB = 1 << OpMapShift,735/// T8, TA - Prefix after the 0x0F prefix.736T8 = 2 << OpMapShift,737TA = 3 << OpMapShift,738/// XOP8 - Prefix to include use of imm byte.739XOP8 = 4 << OpMapShift,740/// XOP9 - Prefix to exclude use of imm byte.741XOP9 = 5 << OpMapShift,742/// XOPA - Prefix to encode 0xA in VEX.MMMM of XOP instructions.743XOPA = 6 << OpMapShift,744/// ThreeDNow - This indicates that the instruction uses the745/// wacky 0x0F 0x0F prefix for 3DNow! instructions. The manual documents746/// this as having a 0x0F prefix with a 0x0F opcode, and each instruction747/// storing a classifier in the imm8 field. To simplify our implementation,748/// we handle this by storeing the classifier in the opcode field and using749/// this flag to indicate that the encoder should do the wacky 3DNow! thing.750ThreeDNow = 7 << OpMapShift,751/// MAP4, MAP5, MAP6, MAP7 - Prefix after the 0x0F prefix.752T_MAP4 = 8 << OpMapShift,753T_MAP5 = 9 << OpMapShift,754T_MAP6 = 10 << OpMapShift,755T_MAP7 = 11 << OpMapShift,756//===------------------------------------------------------------------===//757/// REX_W - REX prefixes are instruction prefixes used in 64-bit mode.758/// They are used to specify GPRs and SSE registers, 64-bit operand size,759/// etc. We only cares about REX.W and REX.R bits and only the former is760/// statically determined.761REXShift = OpMapShift + 4,762REX_W = 1 << REXShift,763//===------------------------------------------------------------------===//764// This 4-bit field describes the size of an immediate operand. Zero is765// unused so that we can tell if we forgot to set a value.766ImmShift = REXShift + 1,767Imm8 = 1 << ImmShift,768Imm8PCRel = 2 << ImmShift,769Imm8Reg = 3 << ImmShift,770Imm16 = 4 << ImmShift,771Imm16PCRel = 5 << ImmShift,772Imm32 = 6 << ImmShift,773Imm32PCRel = 7 << ImmShift,774Imm32S = 8 << ImmShift,775Imm64 = 9 << ImmShift,776ImmMask = 15 << ImmShift,777//===------------------------------------------------------------------===//778/// FP Instruction Classification... Zero is non-fp instruction.779/// FPTypeMask - Mask for all of the FP types...780FPTypeShift = ImmShift + 4,781FPTypeMask = 7 << FPTypeShift,782/// NotFP - The default, set for instructions that do not use FP registers.783NotFP = 0 << FPTypeShift,784/// ZeroArgFP - 0 arg FP instruction which implicitly pushes ST(0), f.e. fld0785ZeroArgFP = 1 << FPTypeShift,786/// OneArgFP - 1 arg FP instructions which implicitly read ST(0), such as fst787OneArgFP = 2 << FPTypeShift,788/// OneArgFPRW - 1 arg FP instruction which implicitly read ST(0) and write a789/// result back to ST(0). For example, fcos, fsqrt, etc.790OneArgFPRW = 3 << FPTypeShift,791/// TwoArgFP - 2 arg FP instructions which implicitly read ST(0), and an792/// explicit argument, storing the result to either ST(0) or the implicit793/// argument. For example: fadd, fsub, fmul, etc...794TwoArgFP = 4 << FPTypeShift,795/// CompareFP - 2 arg FP instructions which implicitly read ST(0) and an796/// explicit argument, but have no destination. Example: fucom, fucomi, ...797CompareFP = 5 << FPTypeShift,798/// CondMovFP - "2 operand" floating point conditional move instructions.799CondMovFP = 6 << FPTypeShift,800/// SpecialFP - Special instruction forms. Dispatch by opcode explicitly.801SpecialFP = 7 << FPTypeShift,802/// Lock prefix803LOCKShift = FPTypeShift + 3,804LOCK = 1 << LOCKShift,805/// REP prefix806REPShift = LOCKShift + 1,807REP = 1 << REPShift,808/// Execution domain for SSE instructions.809/// 0 means normal, non-SSE instruction.810SSEDomainShift = REPShift + 1,811/// Encoding812EncodingShift = SSEDomainShift + 2,813EncodingMask = 0x3 << EncodingShift,814/// LEGACY - encoding using REX/REX2 or w/o opcode prefix.815LEGACY = 0 << EncodingShift,816/// VEX - encoding using 0xC4/0xC5817VEX = 1 << EncodingShift,818/// XOP - Opcode prefix used by XOP instructions.819XOP = 2 << EncodingShift,820/// EVEX - Specifies that this instruction use EVEX form which provides821/// syntax support up to 32 512-bit register operands and up to 7 16-bit822/// mask operands as well as source operand data swizzling/memory operand823/// conversion, eviction hint, and rounding mode.824EVEX = 3 << EncodingShift,825/// Opcode826OpcodeShift = EncodingShift + 2,827/// VEX_4V - Used to specify an additional AVX/SSE register. Several 2828/// address instructions in SSE are represented as 3 address ones in AVX829/// and the additional register is encoded in VEX_VVVV prefix.830VEX_4VShift = OpcodeShift + 8,831VEX_4V = 1ULL << VEX_4VShift,832/// VEX_L - Stands for a bit in the VEX opcode prefix meaning the current833/// instruction uses 256-bit wide registers. This is usually auto detected834/// if a VR256 register is used, but some AVX instructions also have this835/// field marked when using a f256 memory references.836VEX_LShift = VEX_4VShift + 1,837VEX_L = 1ULL << VEX_LShift,838/// EVEX_K - Set if this instruction requires masking839EVEX_KShift = VEX_LShift + 1,840EVEX_K = 1ULL << EVEX_KShift,841/// EVEX_Z - Set if this instruction has EVEX.Z field set.842EVEX_ZShift = EVEX_KShift + 1,843EVEX_Z = 1ULL << EVEX_ZShift,844/// EVEX_L2 - Set if this instruction has EVEX.L' field set.845EVEX_L2Shift = EVEX_ZShift + 1,846EVEX_L2 = 1ULL << EVEX_L2Shift,847/// EVEX_B - Set if this instruction has EVEX.B field set.848EVEX_BShift = EVEX_L2Shift + 1,849EVEX_B = 1ULL << EVEX_BShift,850/// The scaling factor for the AVX512's 8-bit compressed displacement.851CD8_Scale_Shift = EVEX_BShift + 1,852CD8_Scale_Mask = 7ULL << CD8_Scale_Shift,853/// Explicitly specified rounding control854EVEX_RCShift = CD8_Scale_Shift + 3,855EVEX_RC = 1ULL << EVEX_RCShift,856/// NOTRACK prefix857NoTrackShift = EVEX_RCShift + 1,858NOTRACK = 1ULL << NoTrackShift,859/// Force REX2/VEX/EVEX encoding860ExplicitOpPrefixShift = NoTrackShift + 1,861/// For instructions that require REX2 prefix even if EGPR is not used.862ExplicitREX2Prefix = 1ULL << ExplicitOpPrefixShift,863/// For instructions that use VEX encoding only when {vex}, {vex2} or {vex3}864/// is present.865ExplicitVEXPrefix = 2ULL << ExplicitOpPrefixShift,866/// For instructions that are promoted to EVEX space for EGPR.867ExplicitEVEXPrefix = 3ULL << ExplicitOpPrefixShift,868ExplicitOpPrefixMask = 3ULL << ExplicitOpPrefixShift,869/// EVEX_NF - Set if this instruction has EVEX.NF field set.870EVEX_NFShift = ExplicitOpPrefixShift + 2,871EVEX_NF = 1ULL << EVEX_NFShift,872// TwoConditionalOps - Set if this instruction has two conditional operands873TwoConditionalOps_Shift = EVEX_NFShift + 1,874TwoConditionalOps = 1ULL << TwoConditionalOps_Shift875};876877/// \returns true if the instruction with given opcode is a prefix.878inline bool isPrefix(uint64_t TSFlags) {879return (TSFlags & X86II::FormMask) == PrefixByte;880}881882/// \returns true if the instruction with given opcode is a pseudo.883inline bool isPseudo(uint64_t TSFlags) {884return (TSFlags & X86II::FormMask) == Pseudo;885}886887/// \returns the "base" X86 opcode for the specified machine888/// instruction.889inline uint8_t getBaseOpcodeFor(uint64_t TSFlags) {890return TSFlags >> X86II::OpcodeShift;891}892893inline bool hasImm(uint64_t TSFlags) { return (TSFlags & X86II::ImmMask) != 0; }894895/// Decode the "size of immediate" field from the TSFlags field of the896/// specified instruction.897inline unsigned getSizeOfImm(uint64_t TSFlags) {898switch (TSFlags & X86II::ImmMask) {899default:900llvm_unreachable("Unknown immediate size");901case X86II::Imm8:902case X86II::Imm8PCRel:903case X86II::Imm8Reg:904return 1;905case X86II::Imm16:906case X86II::Imm16PCRel:907return 2;908case X86II::Imm32:909case X86II::Imm32S:910case X86II::Imm32PCRel:911return 4;912case X86II::Imm64:913return 8;914}915}916917/// \returns true if the immediate of the specified instruction's TSFlags918/// indicates that it is pc relative.919inline bool isImmPCRel(uint64_t TSFlags) {920switch (TSFlags & X86II::ImmMask) {921default:922llvm_unreachable("Unknown immediate size");923case X86II::Imm8PCRel:924case X86II::Imm16PCRel:925case X86II::Imm32PCRel:926return true;927case X86II::Imm8:928case X86II::Imm8Reg:929case X86II::Imm16:930case X86II::Imm32:931case X86II::Imm32S:932case X86II::Imm64:933return false;934}935}936937/// \returns true if the immediate of the specified instruction's938/// TSFlags indicates that it is signed.939inline bool isImmSigned(uint64_t TSFlags) {940switch (TSFlags & X86II::ImmMask) {941default:942llvm_unreachable("Unknown immediate signedness");943case X86II::Imm32S:944return true;945case X86II::Imm8:946case X86II::Imm8PCRel:947case X86II::Imm8Reg:948case X86II::Imm16:949case X86II::Imm16PCRel:950case X86II::Imm32:951case X86II::Imm32PCRel:952case X86II::Imm64:953return false;954}955}956957/// Compute whether all of the def operands are repeated in the uses and958/// therefore should be skipped.959/// This determines the start of the unique operand list. We need to determine960/// if all of the defs have a corresponding tied operand in the uses.961/// Unfortunately, the tied operand information is encoded in the uses not962/// the defs so we have to use some heuristics to find which operands to963/// query.964inline unsigned getOperandBias(const MCInstrDesc &Desc) {965unsigned NumDefs = Desc.getNumDefs();966unsigned NumOps = Desc.getNumOperands();967switch (NumDefs) {968default:969llvm_unreachable("Unexpected number of defs");970case 0:971return 0;972case 1:973// Common two addr case.974if (NumOps > 1 && Desc.getOperandConstraint(1, MCOI::TIED_TO) == 0)975return 1;976// Check for AVX-512 scatter which has a TIED_TO in the second to last977// operand.978if (NumOps == 8 && Desc.getOperandConstraint(6, MCOI::TIED_TO) == 0)979return 1;980return 0;981case 2:982// XCHG/XADD have two destinations and two sources.983if (NumOps >= 4 && Desc.getOperandConstraint(2, MCOI::TIED_TO) == 0 &&984Desc.getOperandConstraint(3, MCOI::TIED_TO) == 1)985return 2;986// Check for gather. AVX-512 has the second tied operand early. AVX2987// has it as the last op.988if (NumOps == 9 && Desc.getOperandConstraint(2, MCOI::TIED_TO) == 0 &&989(Desc.getOperandConstraint(3, MCOI::TIED_TO) == 1 ||990Desc.getOperandConstraint(8, MCOI::TIED_TO) == 1))991return 2;992return 0;993}994}995996/// \returns true if the instruction has a NDD (new data destination).997inline bool hasNewDataDest(uint64_t TSFlags) {998return (TSFlags & X86II::OpMapMask) == X86II::T_MAP4 &&999(TSFlags & X86II::EVEX_B) && (TSFlags & X86II::VEX_4V);1000}10011002/// \returns operand # for the first field of the memory operand or -1 if no1003/// memory operands.1004/// NOTE: This ignores tied operands. If there is a tied register which is1005/// duplicated in the MCInst (e.g. "EAX = addl EAX, [mem]") it is only counted1006/// as one operand.1007inline int getMemoryOperandNo(uint64_t TSFlags) {1008bool HasVEX_4V = TSFlags & X86II::VEX_4V;1009bool HasEVEX_K = TSFlags & X86II::EVEX_K;10101011switch (TSFlags & X86II::FormMask) {1012default:1013llvm_unreachable("Unknown FormMask value in getMemoryOperandNo!");1014case X86II::Pseudo:1015case X86II::RawFrm:1016case X86II::AddRegFrm:1017case X86II::RawFrmImm8:1018case X86II::RawFrmImm16:1019case X86II::RawFrmMemOffs:1020case X86II::RawFrmSrc:1021case X86II::RawFrmDst:1022case X86II::RawFrmDstSrc:1023case X86II::AddCCFrm:1024case X86II::PrefixByte:1025return -1;1026case X86II::MRMDestMem:1027case X86II::MRMDestMemFSIB:1028case X86II::MRMDestMemCC:1029return hasNewDataDest(TSFlags);1030case X86II::MRMSrcMem:1031case X86II::MRMSrcMemFSIB:1032// Start from 1, skip any registers encoded in VEX_VVVV or I8IMM, or a1033// mask register.1034return 1 + HasVEX_4V + HasEVEX_K;1035case X86II::MRMSrcMem4VOp3:1036// Skip registers encoded in reg.1037return 1 + HasEVEX_K;1038case X86II::MRMSrcMemOp4:1039// Skip registers encoded in reg, VEX_VVVV, and I8IMM.1040return 3;1041case X86II::MRMSrcMemCC:1042return 1 + hasNewDataDest(TSFlags);1043case X86II::MRMDestMem4VOp3CC:1044// Start from 1, skip any registers encoded in VEX_VVVV or I8IMM, or a1045// mask register.1046return 1;1047case X86II::MRMDestReg:1048case X86II::MRMDestRegCC:1049case X86II::MRMSrcReg:1050case X86II::MRMSrcReg4VOp3:1051case X86II::MRMSrcRegOp4:1052case X86II::MRMSrcRegCC:1053case X86II::MRMXrCC:1054case X86II::MRMr0:1055case X86II::MRMXr:1056case X86II::MRM0r:1057case X86II::MRM1r:1058case X86II::MRM2r:1059case X86II::MRM3r:1060case X86II::MRM4r:1061case X86II::MRM5r:1062case X86II::MRM6r:1063case X86II::MRM7r:1064return -1;1065case X86II::MRM0X:1066case X86II::MRM1X:1067case X86II::MRM2X:1068case X86II::MRM3X:1069case X86II::MRM4X:1070case X86II::MRM5X:1071case X86II::MRM6X:1072case X86II::MRM7X:1073return -1;1074case X86II::MRMXmCC:1075case X86II::MRMXm:1076case X86II::MRM0m:1077case X86II::MRM1m:1078case X86II::MRM2m:1079case X86II::MRM3m:1080case X86II::MRM4m:1081case X86II::MRM5m:1082case X86II::MRM6m:1083case X86II::MRM7m:1084// Start from 0, skip registers encoded in VEX_VVVV or a mask register.1085return 0 + HasVEX_4V + HasEVEX_K;1086case X86II::MRM_C0:1087case X86II::MRM_C1:1088case X86II::MRM_C2:1089case X86II::MRM_C3:1090case X86II::MRM_C4:1091case X86II::MRM_C5:1092case X86II::MRM_C6:1093case X86II::MRM_C7:1094case X86II::MRM_C8:1095case X86II::MRM_C9:1096case X86II::MRM_CA:1097case X86II::MRM_CB:1098case X86II::MRM_CC:1099case X86II::MRM_CD:1100case X86II::MRM_CE:1101case X86II::MRM_CF:1102case X86II::MRM_D0:1103case X86II::MRM_D1:1104case X86II::MRM_D2:1105case X86II::MRM_D3:1106case X86II::MRM_D4:1107case X86II::MRM_D5:1108case X86II::MRM_D6:1109case X86II::MRM_D7:1110case X86II::MRM_D8:1111case X86II::MRM_D9:1112case X86II::MRM_DA:1113case X86II::MRM_DB:1114case X86II::MRM_DC:1115case X86II::MRM_DD:1116case X86II::MRM_DE:1117case X86II::MRM_DF:1118case X86II::MRM_E0:1119case X86II::MRM_E1:1120case X86II::MRM_E2:1121case X86II::MRM_E3:1122case X86II::MRM_E4:1123case X86II::MRM_E5:1124case X86II::MRM_E6:1125case X86II::MRM_E7:1126case X86II::MRM_E8:1127case X86II::MRM_E9:1128case X86II::MRM_EA:1129case X86II::MRM_EB:1130case X86II::MRM_EC:1131case X86II::MRM_ED:1132case X86II::MRM_EE:1133case X86II::MRM_EF:1134case X86II::MRM_F0:1135case X86II::MRM_F1:1136case X86II::MRM_F2:1137case X86II::MRM_F3:1138case X86II::MRM_F4:1139case X86II::MRM_F5:1140case X86II::MRM_F6:1141case X86II::MRM_F7:1142case X86II::MRM_F8:1143case X86II::MRM_F9:1144case X86II::MRM_FA:1145case X86II::MRM_FB:1146case X86II::MRM_FC:1147case X86II::MRM_FD:1148case X86II::MRM_FE:1149case X86II::MRM_FF:1150return -1;1151}1152}11531154/// \returns true if the register is a XMM.1155inline bool isXMMReg(unsigned RegNo) {1156static_assert(X86::XMM15 - X86::XMM0 == 15,1157"XMM0-15 registers are not continuous");1158static_assert(X86::XMM31 - X86::XMM16 == 15,1159"XMM16-31 registers are not continuous");1160return (RegNo >= X86::XMM0 && RegNo <= X86::XMM15) ||1161(RegNo >= X86::XMM16 && RegNo <= X86::XMM31);1162}11631164/// \returns true if the register is a YMM.1165inline bool isYMMReg(unsigned RegNo) {1166static_assert(X86::YMM15 - X86::YMM0 == 15,1167"YMM0-15 registers are not continuous");1168static_assert(X86::YMM31 - X86::YMM16 == 15,1169"YMM16-31 registers are not continuous");1170return (RegNo >= X86::YMM0 && RegNo <= X86::YMM15) ||1171(RegNo >= X86::YMM16 && RegNo <= X86::YMM31);1172}11731174/// \returns true if the register is a ZMM.1175inline bool isZMMReg(unsigned RegNo) {1176static_assert(X86::ZMM31 - X86::ZMM0 == 31,1177"ZMM registers are not continuous");1178return RegNo >= X86::ZMM0 && RegNo <= X86::ZMM31;1179}11801181/// \returns true if \p RegNo is an apx extended register.1182inline bool isApxExtendedReg(unsigned RegNo) {1183static_assert(X86::R31WH - X86::R16 == 95, "EGPRs are not continuous");1184return RegNo >= X86::R16 && RegNo <= X86::R31WH;1185}11861187/// \returns true if the MachineOperand is a x86-64 extended (r8 or1188/// higher) register, e.g. r8, xmm8, xmm13, etc.1189inline bool isX86_64ExtendedReg(unsigned RegNo) {1190if ((RegNo >= X86::XMM8 && RegNo <= X86::XMM15) ||1191(RegNo >= X86::XMM16 && RegNo <= X86::XMM31) ||1192(RegNo >= X86::YMM8 && RegNo <= X86::YMM15) ||1193(RegNo >= X86::YMM16 && RegNo <= X86::YMM31) ||1194(RegNo >= X86::ZMM8 && RegNo <= X86::ZMM31))1195return true;11961197if (isApxExtendedReg(RegNo))1198return true;11991200switch (RegNo) {1201default:1202break;1203case X86::R8:1204case X86::R9:1205case X86::R10:1206case X86::R11:1207case X86::R12:1208case X86::R13:1209case X86::R14:1210case X86::R15:1211case X86::R8D:1212case X86::R9D:1213case X86::R10D:1214case X86::R11D:1215case X86::R12D:1216case X86::R13D:1217case X86::R14D:1218case X86::R15D:1219case X86::R8W:1220case X86::R9W:1221case X86::R10W:1222case X86::R11W:1223case X86::R12W:1224case X86::R13W:1225case X86::R14W:1226case X86::R15W:1227case X86::R8B:1228case X86::R9B:1229case X86::R10B:1230case X86::R11B:1231case X86::R12B:1232case X86::R13B:1233case X86::R14B:1234case X86::R15B:1235case X86::CR8:1236case X86::CR9:1237case X86::CR10:1238case X86::CR11:1239case X86::CR12:1240case X86::CR13:1241case X86::CR14:1242case X86::CR15:1243case X86::DR8:1244case X86::DR9:1245case X86::DR10:1246case X86::DR11:1247case X86::DR12:1248case X86::DR13:1249case X86::DR14:1250case X86::DR15:1251return true;1252}1253return false;1254}12551256inline bool canUseApxExtendedReg(const MCInstrDesc &Desc) {1257uint64_t TSFlags = Desc.TSFlags;1258uint64_t Encoding = TSFlags & EncodingMask;1259// EVEX can always use egpr.1260if (Encoding == X86II::EVEX)1261return true;12621263unsigned Opcode = Desc.Opcode;1264// MOV32r0 is always expanded to XOR32rr1265if (Opcode == X86::MOV32r0)1266return true;1267// To be conservative, egpr is not used for all pseudo instructions1268// because we are not sure what instruction it will become.1269// FIXME: Could we improve it in X86ExpandPseudo?1270if (isPseudo(TSFlags))1271return false;12721273// MAP OB/TB in legacy encoding space can always use egpr except1274// XSAVE*/XRSTOR*.1275switch (Opcode) {1276default:1277break;1278case X86::XSAVE:1279case X86::XSAVE64:1280case X86::XSAVEOPT:1281case X86::XSAVEOPT64:1282case X86::XSAVEC:1283case X86::XSAVEC64:1284case X86::XSAVES:1285case X86::XSAVES64:1286case X86::XRSTOR:1287case X86::XRSTOR64:1288case X86::XRSTORS:1289case X86::XRSTORS64:1290return false;1291}1292uint64_t OpMap = TSFlags & X86II::OpMapMask;1293return !Encoding && (OpMap == X86II::OB || OpMap == X86II::TB);1294}12951296/// \returns true if the MemoryOperand is a 32 extended (zmm16 or higher)1297/// registers, e.g. zmm21, etc.1298static inline bool is32ExtendedReg(unsigned RegNo) {1299return ((RegNo >= X86::XMM16 && RegNo <= X86::XMM31) ||1300(RegNo >= X86::YMM16 && RegNo <= X86::YMM31) ||1301(RegNo >= X86::ZMM16 && RegNo <= X86::ZMM31));1302}13031304inline bool isX86_64NonExtLowByteReg(unsigned reg) {1305return (reg == X86::SPL || reg == X86::BPL || reg == X86::SIL ||1306reg == X86::DIL);1307}13081309/// \returns true if this is a masked instruction.1310inline bool isKMasked(uint64_t TSFlags) {1311return (TSFlags & X86II::EVEX_K) != 0;1312}13131314/// \returns true if this is a merge masked instruction.1315inline bool isKMergeMasked(uint64_t TSFlags) {1316return isKMasked(TSFlags) && (TSFlags & X86II::EVEX_Z) == 0;1317}13181319/// \returns true if the intruction needs a SIB.1320inline bool needSIB(unsigned BaseReg, unsigned IndexReg, bool In64BitMode) {1321// The SIB byte must be used if there is an index register.1322if (IndexReg)1323return true;13241325// The SIB byte must be used if the base is ESP/RSP/R12/R20/R28, all of1326// which encode to an R/M value of 4, which indicates that a SIB byte is1327// present.1328switch (BaseReg) {1329default:1330// If there is no base register and we're in 64-bit mode, we need a SIB1331// byte to emit an addr that is just 'disp32' (the non-RIP relative form).1332return In64BitMode && !BaseReg;1333case X86::ESP:1334case X86::RSP:1335case X86::R12:1336case X86::R12D:1337case X86::R20:1338case X86::R20D:1339case X86::R28:1340case X86::R28D:1341return true;1342}1343}13441345} // namespace X86II1346} // namespace llvm1347#endif134813491350