35 #define DEBUG_TYPE "mccodeemitter" 45 : MCII(mcii), Ctx(ctx) {}
46 X86MCCodeEmitter(
const X86MCCodeEmitter &) =
delete;
47 X86MCCodeEmitter &operator=(
const X86MCCodeEmitter &) =
delete;
48 ~X86MCCodeEmitter()
override =
default;
58 unsigned getX86RegNum(
const MCOperand &MO)
const {
62 unsigned getX86RegEncoding(
const MCInst &MI,
unsigned OpNum)
const {
71 bool isREXExtendedReg(
const MCInst &MI,
unsigned OpNum)
const {
72 return (getX86RegEncoding(MI, OpNum) >> 3) & 1;
75 void emitByte(uint8_t
C,
unsigned &CurByte,
raw_ostream &OS)
const {
80 void emitConstant(uint64_t Val,
unsigned Size,
unsigned &CurByte,
83 for (
unsigned i = 0; i !=
Size; ++i) {
84 emitByte(Val & 255, CurByte, OS);
89 void emitImmediate(
const MCOperand &Disp,
SMLoc Loc,
unsigned ImmSize,
93 static uint8_t modRMByte(
unsigned Mod,
unsigned RegOpcode,
unsigned RM) {
94 assert(Mod < 4 && RegOpcode < 8 && RM < 8 &&
"ModRM Fields out of range!");
95 return RM | (RegOpcode << 3) | (Mod << 6);
98 void emitRegModRMByte(
const MCOperand &ModRMReg,
unsigned RegOpcodeFld,
100 emitByte(modRMByte(3, RegOpcodeFld, getX86RegNum(ModRMReg)), CurByte, OS);
103 void emitSIBByte(
unsigned SS,
unsigned Index,
unsigned Base,
106 emitByte(modRMByte(SS, Index, Base), CurByte, OS);
109 void emitMemModRMByte(
const MCInst &MI,
unsigned Op,
unsigned RegOpcodeField,
110 uint64_t TSFlags,
bool Rex,
unsigned &CurByte,
114 void emitPrefixImpl(uint64_t TSFlags,
unsigned &CurOp,
unsigned &CurByte,
118 void emitVEXOpcodePrefix(uint64_t TSFlags,
unsigned &CurByte,
int MemOperand,
122 void emitSegmentOverridePrefix(
unsigned &CurByte,
unsigned SegOperand,
125 bool emitOpcodePrefix(uint64_t TSFlags,
unsigned &CurByte,
int MemOperand,
129 uint8_t determineREXPrefix(
const MCInst &MI, uint64_t TSFlags,
int MemOperand,
143 "Compressed 8-bit displacement is only valid for EVEX inst.");
147 if (CD8_Scale == 0) {
152 unsigned Mask = CD8_Scale - 1;
153 assert((CD8_Scale & Mask) == 0 &&
"Invalid memory object size.");
156 Value /= (int)CD8_Scale;
157 bool Ret = (Value == (int8_t)Value);
193 if ((BaseReg.
getReg() != 0 &&
194 X86MCRegisterClasses[X86::GR16RegClassID].contains(BaseReg.
getReg())) ||
195 (IndexReg.
getReg() != 0 &&
196 X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg.
getReg())))
208 if ((BaseReg.
getReg() != 0 &&
209 X86MCRegisterClasses[X86::GR32RegClassID].contains(BaseReg.
getReg())) ||
210 (IndexReg.
getReg() != 0 &&
211 X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg.
getReg())))
213 if (BaseReg.
getReg() == X86::EIP) {
214 assert(IndexReg.
getReg() == 0 &&
"Invalid eip-based address.");
217 if (IndexReg.
getReg() == X86::EIZ)
230 if ((BaseReg.
getReg() != 0 &&
231 X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg.
getReg())) ||
232 (IndexReg.
getReg() != 0 &&
233 X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg.
getReg())))
248 const MCExpr *RHS =
nullptr;
260 if (S.
getName() !=
"_GLOBAL_OFFSET_TABLE_")
278 if ((Opcode != X86::CALL64pcrel32 && Opcode != X86::JMP_4) ||
291 void X86MCCodeEmitter::emitImmediate(
const MCOperand &DispOp,
SMLoc Loc,
295 int ImmOffset)
const {
296 const MCExpr *Expr =
nullptr;
297 if (DispOp.
isImm()) {
302 emitConstant(DispOp.
getImm() + ImmOffset,
Size, CurByte, OS);
365 emitConstant(0, Size, CurByte, OS);
368 void X86MCCodeEmitter::emitMemModRMByte(
const MCInst &
MI,
unsigned Op,
369 unsigned RegOpcodeField,
370 uint64_t TSFlags,
bool Rex,
378 unsigned BaseReg = Base.
getReg();
382 if (BaseReg == X86::RIP ||
383 BaseReg == X86::EIP) {
385 "Rip-relative addressing requires 64-bit mode");
386 assert(IndexReg.
getReg() == 0 &&
"Invalid rip-relative address");
387 emitByte(modRMByte(0, RegOpcodeField, 5), CurByte, OS);
402 case X86::TAILJMPm64:
433 unsigned BaseRegNo = BaseReg ? getX86RegNum(Base) : -1U;
450 static const unsigned R16Table[] = {0, 0, 0, 7, 0, 6, 4, 5};
451 unsigned RMfield = R16Table[BaseRegNo];
453 assert(RMfield &&
"invalid 16-bit base register");
456 unsigned IndexReg16 = R16Table[getX86RegNum(IndexReg)];
458 assert(IndexReg16 &&
"invalid 16-bit index register");
460 assert(((IndexReg16 ^ RMfield) & 2) &&
461 "invalid 16-bit base/index register combination");
463 "invalid scale for 16-bit memory reference");
467 RMfield = (RMfield & 1) | ((7 - IndexReg16) << 1);
469 RMfield = (IndexReg16 & 1) | ((7 - RMfield) << 1);
473 if (Disp.
getImm() == 0 && RMfield != 6) {
475 emitByte(modRMByte(0, RegOpcodeField, RMfield), CurByte, OS);
479 emitByte(modRMByte(1, RegOpcodeField, RMfield), CurByte, OS);
484 emitByte(modRMByte(2, RegOpcodeField, RMfield), CurByte, OS);
487 emitByte(modRMByte(0, RegOpcodeField, 6), CurByte, OS);
508 (!STI.
hasFeature(X86::Mode64Bit) || BaseReg != 0)) {
511 emitByte(modRMByte(0, RegOpcodeField, 5), CurByte, OS);
522 emitByte(modRMByte(0, RegOpcodeField, BaseRegNo), CurByte, OS);
533 emitByte(modRMByte(0, RegOpcodeField, BaseRegNo), CurByte, OS);
542 emitByte(modRMByte(1, RegOpcodeField, BaseRegNo), CurByte, OS);
550 emitByte(modRMByte(1, RegOpcodeField, BaseRegNo), CurByte, OS);
558 emitByte(modRMByte(2, RegOpcodeField, BaseRegNo), CurByte, OS);
569 "Cannot use ESP as index reg!");
571 bool ForceDisp32 =
false;
572 bool ForceDisp8 =
false;
578 emitByte(modRMByte(0, RegOpcodeField, 4), CurByte, OS);
580 }
else if (!Disp.
isImm()) {
582 emitByte(modRMByte(2, RegOpcodeField, 4), CurByte, OS);
584 }
else if (Disp.
getImm() == 0 &&
589 emitByte(modRMByte(0, RegOpcodeField, 4), CurByte, OS);
592 emitByte(modRMByte(1, RegOpcodeField, 4), CurByte, OS);
596 emitByte(modRMByte(1, RegOpcodeField, 4), CurByte, OS);
598 ImmOffset = CDisp8 - Disp.
getImm();
601 emitByte(modRMByte(2, RegOpcodeField, 4), CurByte, OS);
605 static const unsigned SSTable[] = {~0U, 0, 1, ~0U, 2, ~0U, ~0U, ~0U, 3};
606 unsigned SS = SSTable[Scale.
getImm()];
613 IndexRegNo = getX86RegNum(IndexReg);
616 emitSIBByte(SS, IndexRegNo, 5, CurByte, OS);
620 IndexRegNo = getX86RegNum(IndexReg);
623 emitSIBByte(SS, IndexRegNo, getX86RegNum(Base), CurByte, OS);
630 else if (ForceDisp32 || Disp.
getImm() != 0)
635 void X86MCCodeEmitter::emitPrefixImpl(uint64_t TSFlags,
unsigned &CurOp,
636 unsigned &CurByte,
bool &Rex,
642 if (MemoryOperand != -1)
643 MemoryOperand += CurOp;
646 if (MemoryOperand >= 0)
653 emitByte(0xF3, CurByte, OS);
655 emitByte(0xF2, CurByte, OS);
658 bool need_address_override;
663 need_address_override =
true;
664 }
else if (MemoryOperand < 0) {
665 need_address_override =
false;
678 if (need_address_override)
679 emitByte(0x67, CurByte, OS);
684 Rex = emitOpcodePrefix(TSFlags, CurByte, MemoryOperand, MI, Desc, STI, OS);
686 emitVEXOpcodePrefix(TSFlags, CurByte, MemoryOperand, MI, Desc, OS);
697 "SI and DI register sizes do not match");
700 emitSegmentOverridePrefix(CurByte, 2, MI, OS);
704 emitByte(0x67, CurByte, OS);
712 emitSegmentOverridePrefix(CurByte, 1, MI, OS);
716 emitByte(0x67, CurByte, OS);
724 (STI.
hasFeature(X86::Mode32Bit) && siReg == X86::DI))
725 emitByte(0x67, CurByte, OS);
731 emitSegmentOverridePrefix(CurByte, 1, MI, OS);
739 void X86MCCodeEmitter::emitVEXOpcodePrefix(uint64_t TSFlags,
unsigned &CurByte,
740 int MemOperand,
const MCInst &MI,
757 uint8_t EVEX_R2 = 0x1;
814 uint8_t EVEX_V2 = 0x1;
851 uint8_t EVEX_z = (HasEVEX_K && (TSFlags &
X86II::EVEX_Z)) ? 1 : 0;
860 uint8_t EVEX_aaa = 0;
862 bool EncodeRC =
false;
880 VEX_B = ~(BaseRegEnc >> 3) & 1;
881 unsigned IndexRegEnc =
883 VEX_X = ~(IndexRegEnc >> 3) & 1;
885 EVEX_V2 = ~(IndexRegEnc >> 4) & 1;
890 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
893 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
894 VEX_4V = ~VRegEnc & 0xf;
895 EVEX_V2 = ~(VRegEnc >> 4) & 1;
898 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
899 VEX_R = ~(RegEnc >> 3) & 1;
900 EVEX_R2 = ~(RegEnc >> 4) & 1;
912 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
913 VEX_R = ~(RegEnc >> 3) & 1;
914 EVEX_R2 = ~(RegEnc >> 4) & 1;
917 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
920 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
921 VEX_4V = ~VRegEnc & 0xf;
922 EVEX_V2 = ~(VRegEnc >> 4) & 1;
926 VEX_B = ~(BaseRegEnc >> 3) & 1;
927 unsigned IndexRegEnc =
929 VEX_X = ~(IndexRegEnc >> 3) & 1;
931 EVEX_V2 = ~(IndexRegEnc >> 4) & 1;
938 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
939 VEX_R = ~(RegEnc >> 3) & 1;
942 VEX_B = ~(BaseRegEnc >> 3) & 1;
943 unsigned IndexRegEnc =
945 VEX_X = ~(IndexRegEnc >> 3) & 1;
952 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
953 VEX_R = ~(RegEnc >> 3) & 1;
955 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
956 VEX_4V = ~VRegEnc & 0xf;
959 VEX_B = ~(BaseRegEnc >> 3) & 1;
960 unsigned IndexRegEnc =
962 VEX_X = ~(IndexRegEnc >> 3) & 1;
977 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
978 VEX_4V = ~VRegEnc & 0xf;
979 EVEX_V2 = ~(VRegEnc >> 4) & 1;
983 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
986 VEX_B = ~(BaseRegEnc >> 3) & 1;
987 unsigned IndexRegEnc =
989 VEX_X = ~(IndexRegEnc >> 3) & 1;
991 EVEX_V2 = ~(IndexRegEnc >> 4) & 1;
1003 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
1004 VEX_R = ~(RegEnc >> 3) & 1;
1005 EVEX_R2 = ~(RegEnc >> 4) & 1;
1008 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
1011 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
1012 VEX_4V = ~VRegEnc & 0xf;
1013 EVEX_V2 = ~(VRegEnc >> 4) & 1;
1016 RegEnc = getX86RegEncoding(MI, CurOp++);
1017 VEX_B = ~(RegEnc >> 3) & 1;
1018 VEX_X = ~(RegEnc >> 4) & 1;
1022 unsigned RcOperand = NumOps - 1;
1023 assert(RcOperand >= CurOp);
1025 assert(EVEX_rc <= 3 &&
"Invalid rounding control!");
1034 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
1035 VEX_R = ~(RegEnc >> 3) & 1;
1037 RegEnc = getX86RegEncoding(MI, CurOp++);
1038 VEX_B = ~(RegEnc >> 3) & 1;
1040 VEX_4V = ~getX86RegEncoding(MI, CurOp++) & 0xf;
1045 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
1046 VEX_R = ~(RegEnc >> 3) & 1;
1048 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
1049 VEX_4V = ~VRegEnc & 0xf;
1054 RegEnc = getX86RegEncoding(MI, CurOp++);
1055 VEX_B = ~(RegEnc >> 3) & 1;
1056 VEX_X = ~(RegEnc >> 4) & 1;
1064 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
1065 VEX_B = ~(RegEnc >> 3) & 1;
1066 VEX_X = ~(RegEnc >> 4) & 1;
1069 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
1072 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
1073 VEX_4V = ~VRegEnc & 0xf;
1074 EVEX_V2 = ~(VRegEnc >> 4) & 1;
1077 RegEnc = getX86RegEncoding(MI, CurOp++);
1078 VEX_R = ~(RegEnc >> 3) & 1;
1079 EVEX_R2 = ~(RegEnc >> 4) & 1;
1095 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
1096 VEX_4V = ~VRegEnc & 0xf;
1097 EVEX_V2 = ~(VRegEnc >> 4) & 1;
1100 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
1102 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
1103 VEX_B = ~(RegEnc >> 3) & 1;
1104 VEX_X = ~(RegEnc >> 4) & 1;
1125 uint8_t LastByte = VEX_PP | (VEX_L << 2) | (VEX_4V << 3);
1129 VEX_B && VEX_X && !VEX_W && (VEX_5M == 1)) {
1130 emitByte(0xC5, CurByte, OS);
1131 emitByte(LastByte | (VEX_R << 7), CurByte, OS);
1136 emitByte(Encoding ==
X86II::XOP ? 0x8F : 0xC4, CurByte, OS);
1137 emitByte(VEX_R << 7 | VEX_X << 6 | VEX_B << 5 | VEX_5M, CurByte, OS);
1138 emitByte(LastByte | (VEX_W << 7), CurByte, OS);
1146 assert((VEX_5M & 0x3) == VEX_5M &&
1147 "More than 2 significant bits in VEX.m-mmmm fields for EVEX!");
1149 emitByte(0x62, CurByte, OS);
1150 emitByte((VEX_R << 7) | (VEX_X << 6) | (VEX_B << 5) | (EVEX_R2 << 4) |
1153 emitByte((VEX_W << 7) | (VEX_4V << 3) | (EVEX_U << 2) | VEX_PP, CurByte,
1156 emitByte((EVEX_z << 7) | (EVEX_rc << 5) | (EVEX_b << 4) | (EVEX_V2 << 3) |
1160 emitByte((EVEX_z << 7) | (EVEX_L2 << 6) | (VEX_L << 5) | (EVEX_b << 4) |
1161 (EVEX_V2 << 3) | EVEX_aaa,
1169 uint8_t X86MCCodeEmitter::determineREXPrefix(
const MCInst &MI, uint64_t TSFlags,
1173 bool UsesHighByteReg =
false;
1185 for (
unsigned i = CurOp; i != NumOps; ++i) {
1190 if (Reg == X86::AH || Reg == X86::BH || Reg == X86::CH || Reg == X86::DH)
1191 UsesHighByteReg =
true;
1200 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1204 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1205 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1209 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1215 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1216 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1222 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1247 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1250 if (REX && UsesHighByteReg)
1252 "Cannot encode high byte register in REX-prefixed instruction");
1258 void X86MCCodeEmitter::emitSegmentOverridePrefix(
unsigned &CurByte,
1259 unsigned SegOperand,
1269 emitByte(0x2E, CurByte, OS);
1272 emitByte(0x36, CurByte, OS);
1275 emitByte(0x3E, CurByte, OS);
1278 emitByte(0x26, CurByte, OS);
1281 emitByte(0x64, CurByte, OS);
1284 emitByte(0x65, CurByte, OS);
1295 bool X86MCCodeEmitter::emitOpcodePrefix(uint64_t TSFlags,
unsigned &CurByte,
1296 int MemOperand,
const MCInst &MI,
1304 emitByte(0x66, CurByte, OS);
1308 emitByte(0xF0, CurByte, OS);
1312 emitByte(0x3E, CurByte, OS);
1316 emitByte(0x66, CurByte, OS);
1319 emitByte(0xF3, CurByte, OS);
1322 emitByte(0xF2, CurByte, OS);
1329 if (uint8_t REX = determineREXPrefix(MI, TSFlags, MemOperand, Desc)) {
1330 emitByte(0x40 | REX, CurByte, OS);
1343 emitByte(0x0F, CurByte, OS);
1347 switch (TSFlags & X86II::OpMapMask) {
1349 emitByte(0x38, CurByte, OS);
1352 emitByte(0x3A, CurByte, OS);
1362 uint64_t TSFlags = Desc.
TSFlags;
1371 unsigned CurByte = 0;
1374 emitPrefixImpl(TSFlags, CurOp, CurByte, Rex, MI, Desc, STI, OS);
1382 uint64_t TSFlags = Desc.
TSFlags;
1392 unsigned CurByte = 0;
1395 emitPrefixImpl(TSFlags, CurOp, CurByte, Rex, MI, Desc, STI, OS);
1406 unsigned I8RegNum = 0;
1413 unsigned OpcodeOffset = 0;
1418 errs() <<
"FORM: " << Form <<
"\n";
1425 emitByte(BaseOpcode, CurByte, OS);
1430 assert(OpcodeOffset < 16 &&
"Unexpected opcode offset!");
1434 emitByte(BaseOpcode + OpcodeOffset, CurByte, OS);
1446 emitByte(BaseOpcode, CurByte, OS);
1453 emitByte(BaseOpcode, CurByte, OS);
1461 emitByte(BaseOpcode, CurByte, OS);
1470 emitByte(BaseOpcode + getX86RegNum(MI.
getOperand(CurOp++)), CurByte, OS);
1474 emitByte(BaseOpcode, CurByte, OS);
1475 unsigned SrcRegNum = CurOp + 1;
1484 getX86RegNum(MI.
getOperand(SrcRegNum)), CurByte, OS);
1485 CurOp = SrcRegNum + 1;
1489 emitByte(BaseOpcode, CurByte, OS);
1498 emitMemModRMByte(MI, CurOp, getX86RegNum(MI.
getOperand(SrcRegNum)), TSFlags,
1499 Rex, CurByte, OS, Fixups, STI);
1500 CurOp = SrcRegNum + 1;
1504 emitByte(BaseOpcode, CurByte, OS);
1505 unsigned SrcRegNum = CurOp + 1;
1514 getX86RegNum(MI.
getOperand(CurOp)), CurByte, OS);
1515 CurOp = SrcRegNum + 1;
1517 I8RegNum = getX86RegEncoding(MI, CurOp++);
1524 emitByte(BaseOpcode, CurByte, OS);
1525 unsigned SrcRegNum = CurOp + 1;
1528 getX86RegNum(MI.
getOperand(CurOp)), CurByte, OS);
1529 CurOp = SrcRegNum + 1;
1534 emitByte(BaseOpcode, CurByte, OS);
1535 unsigned SrcRegNum = CurOp + 1;
1541 assert(HasVEX_I8Reg &&
"MRMSrcRegOp4 should imply VEX_I8Reg");
1542 I8RegNum = getX86RegEncoding(MI, SrcRegNum++);
1545 getX86RegNum(MI.
getOperand(CurOp)), CurByte, OS);
1546 CurOp = SrcRegNum + 1;
1550 unsigned FirstOp = CurOp++;
1551 unsigned SecondOp = CurOp++;
1554 emitByte(BaseOpcode + CC, CurByte, OS);
1557 getX86RegNum(MI.
getOperand(FirstOp)), CurByte, OS);
1561 unsigned FirstMemOp = CurOp + 1;
1569 emitByte(BaseOpcode, CurByte, OS);
1571 emitMemModRMByte(MI, FirstMemOp, getX86RegNum(MI.
getOperand(CurOp)),
1572 TSFlags, Rex, CurByte, OS, Fixups, STI);
1575 I8RegNum = getX86RegEncoding(MI, CurOp++);
1579 unsigned FirstMemOp = CurOp + 1;
1581 emitByte(BaseOpcode, CurByte, OS);
1583 emitMemModRMByte(MI, FirstMemOp, getX86RegNum(MI.
getOperand(CurOp)),
1584 TSFlags, Rex, CurByte, OS, Fixups, STI);
1590 unsigned FirstMemOp = CurOp + 1;
1595 assert(HasVEX_I8Reg &&
"MRMSrcRegOp4 should imply VEX_I8Reg");
1596 I8RegNum = getX86RegEncoding(MI, FirstMemOp++);
1598 emitByte(BaseOpcode, CurByte, OS);
1600 emitMemModRMByte(MI, FirstMemOp, getX86RegNum(MI.
getOperand(CurOp)),
1601 TSFlags, Rex, CurByte, OS, Fixups, STI);
1606 unsigned RegOp = CurOp++;
1607 unsigned FirstMemOp = CurOp;
1611 emitByte(BaseOpcode + CC, CurByte, OS);
1613 emitMemModRMByte(MI, FirstMemOp, getX86RegNum(MI.
getOperand(RegOp)),
1614 TSFlags, Rex, CurByte, OS, Fixups, STI);
1619 unsigned RegOp = CurOp++;
1622 emitByte(BaseOpcode + CC, CurByte, OS);
1623 emitRegModRMByte(MI.
getOperand(RegOp), 0, CurByte, OS);
1640 emitByte(BaseOpcode, CurByte, OS);
1647 unsigned FirstMemOp = CurOp;
1651 emitByte(BaseOpcode + CC, CurByte, OS);
1653 emitMemModRMByte(MI, FirstMemOp, 0, TSFlags, Rex, CurByte, OS, Fixups, STI);
1670 emitByte(BaseOpcode, CurByte, OS);
1671 emitMemModRMByte(MI, CurOp,
1673 Rex, CurByte, OS, Fixups, STI);
1741 emitByte(BaseOpcode, CurByte, OS);
1749 assert(I8RegNum < 16 &&
"Register encoding out of range");
1751 if (CurOp != NumOps) {
1753 assert(Val < 16 &&
"Immediate operand value out of range");
1762 while (CurOp != NumOps && NumOps - CurOp <= 2) {
1774 if ( CurOp != NumOps) {
1775 errs() <<
"Cannot encode all operands of: ";
1786 return new X86MCCodeEmitter(MCII, Ctx);
MRMSrcMem4VOp3 - This form is used for instructions that encode operand 3 with VEX.VVVV and load from memory.
static bool hasSecRelSymbolRef(const MCExpr *Expr)
static bool isPCRel32Branch(const MCInst &MI, const MCInstrInfo &MCII)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static GlobalOffsetTableExprKind startsWithGlobalOffsetTable(const MCExpr *Expr)
Check if this expression starts with GLOBAL_OFFSET_TABLE and if it is of the form GLOBAL_OFFSET_TABLE...
bool isX86_64NonExtLowByteReg(unsigned reg)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
VariantKind getKind() const
RawFrmDstSrc - This form is for instructions that use the source index register SI/ESI/RSI with a pos...
static bool isDisp8(int Value)
MRMXCCr - This form is used for instructions that use the Mod/RM byte to specify a register source...
AddRegFrm - This form is used for instructions like 'push r32' that have their one register operand a...
void push_back(const T &Elt)
Describe properties that are true of each instruction in the target description file.
AddrNumOperands - Total number of operands in a memory reference.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
MRMSrcMemOp4 - This form is used for instructions that use the Mod/RM byte to specify the fourth sour...
MRMXr - This form is used for instructions that use the Mod/RM byte to specify a register source...
static Lanai::Fixups FixupKind(const MCExpr *Expr)
MRMSrcReg - This form is used for instructions that use the Mod/RM byte to specify a source...
A one-byte pc relative fixup.
MRMDestReg - This form is used for instructions that use the Mod/RM byte to specify a destination...
static bool is16BitMemOperand(const MCInst &MI, unsigned Op, const MCSubtargetInfo &STI)
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ThreeDNow - This indicates that the instruction uses the wacky 0x0F 0x0F prefix for 3DNow! instructio...
MCCodeEmitter * createX86MCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
RawFrmMemOffs - This form is for instructions that store an absolute memory offset as an immediate wi...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
The access may reference the value stored in memory.
MRMSrcMem - This form is used for instructions that use the Mod/RM byte to specify a source...
Represent a reference to a symbol from inside an expression.
A four-byte section relative fixup.
unsigned getReg() const
Returns the register number.
Context object for machine code objects.
MRMSrcReg4VOp3 - This form is used for instructions that encode operand 3 with VEX.VVVV and do not load from memory.
uint8_t getBaseOpcodeFor(uint64_t TSFlags)
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
MRMXm - This form is used for instructions that use the Mod/RM byte to specify a memory source...
const MCExpr * getExpr() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
bool hasImm(uint64_t TSFlags)
static bool isCDisp8(uint64_t TSFlags, int Value, int &CValue)
Instances of this class represent a single low-level machine instruction.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
static MCFixupKind getImmFixupKind(uint64_t TSFlags)
unsigned const MachineRegisterInfo * MRI
AddCCFrm - This form is used for Jcc that encode the condition code in the lower 4 bits of the opcode...
unsigned getFlags() const
MRMSrcMemCC - This form is used for instructions that use the Mod/RM byte to specify the operands and...
MCCodeEmitter - Generic instruction encoding interface.
Interface to description of machine instruction set.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
RawFrmSrc - This form is for instructions that use the source index register SI/ESI/RSI with a possib...
unsigned getOperandBias(const MCInstrDesc &Desc)
Compute whether all of the def operands are repeated in the uses and therefore should be skipped...
unsigned getNumOperands() const
uint16_t getEncodingValue(MCRegister RegNo) const
Returns the encoding for RegNo.
Binary assembler expressions.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
XOP - Opcode prefix used by XOP instructions.
A two-byte pc relative fixup.
bool isImmSigned(uint64_t TSFlags)
A four-byte pc relative fixup.
MRMSrcRegOp4 - This form is used for instructions that use the Mod/RM byte to specify the fourth sour...
const MCSymbol & getSymbol() const
AddrSegmentReg - The operand # of the segment in the memory operand.
const MCOperand & getOperand(unsigned i) const
The access may modify the value stored in memory.
Raw - This form is for instructions that don't have any operands, so they are just a fixed opcode val...
static bool is32BitMemOperand(const MCInst &MI, unsigned Op)
static bool is64BitMemOperand(const MCInst &MI, unsigned Op)
unsigned getSizeOfImm(uint64_t TSFlags)
Decode the "size of immediate" field from the TSFlags field of the specified instruction.
MRMSrcRegCC - This form is used for instructions that use the Mod/RM byte to specify the operands and...
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
MRM_XX - A mod/rm byte of exactly 0xXX.
bool hasFeature(unsigned Feature) const
MRM[0-7][rm] - These forms are used to represent instructions that use a Mod/RM byte, and use the middle field to hold extended opcode information.
Generic base class for all target subtargets.
RawFrmImm16 - This is used for CALL FAR instructions, which have two immediates, the first of which i...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
References to labels and assigned expressions.
StringRef getName() const
getName - Get the symbol name.
static MCFixupKind getKindForSize(unsigned Size, bool IsPCRel)
Return the generic fixup kind for a value with the given size.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MRMXm - This form is used for instructions that use the Mod/RM byte to specify a memory source...
const MCRegisterInfo * getRegisterInfo() const
LLVM Value Representation.
RawFrmDst - This form is for instructions that use the destination index register DI/EDI/RDI...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
This class implements an extremely fast bulk output stream that can only output to a stream...
bool isImmPCRel(uint64_t TSFlags)
GlobalOffsetTableExprKind
static bool isPCRel(unsigned Kind)
RawFrmImm8 - This is used for the ENTER instruction, which has two immediates, the first of which is ...
Represents a location in source code.
unsigned getOpcode() const
Instances of this class represent operands of the MCInst class.
static MCOperand createImm(int64_t Val)
int getMemoryOperandNo(uint64_t TSFlags)
The function returns the MCInst operand # for the first field of the memory operand.