36 #define DEBUG_TYPE "mccodeemitter" 46 : MCII(mcii), Ctx(ctx) {
48 X86MCCodeEmitter(
const X86MCCodeEmitter &) =
delete;
49 X86MCCodeEmitter &operator=(
const X86MCCodeEmitter &) =
delete;
50 ~X86MCCodeEmitter()
override =
default;
66 bool Is16BitMemOperand(
const MCInst &
MI,
unsigned Op,
72 if (is16BitMode(STI) && BaseReg.
getReg() == 0 &&
75 if ((BaseReg.
getReg() != 0 &&
76 X86MCRegisterClasses[X86::GR16RegClassID].contains(BaseReg.
getReg())) ||
78 X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg.
getReg())))
83 unsigned GetX86RegNum(
const MCOperand &MO)
const {
87 unsigned getX86RegEncoding(
const MCInst &MI,
unsigned OpNum)
const {
93 bool isREXExtendedReg(
const MCInst &MI,
unsigned OpNum)
const {
94 return (getX86RegEncoding(MI, OpNum) >> 3) & 1;
97 void EmitByte(uint8_t
C,
unsigned &CurByte,
raw_ostream &OS)
const {
102 void EmitConstant(uint64_t Val,
unsigned Size,
unsigned &CurByte,
105 for (
unsigned i = 0; i !=
Size; ++i) {
106 EmitByte(Val & 255, CurByte, OS);
115 int ImmOffset = 0)
const;
117 static uint8_t ModRMByte(
unsigned Mod,
unsigned RegOpcode,
unsigned RM) {
118 assert(Mod < 4 && RegOpcode < 8 && RM < 8 &&
"ModRM Fields out of range!");
119 return RM | (RegOpcode << 3) | (Mod << 6);
122 void EmitRegModRMByte(
const MCOperand &ModRMReg,
unsigned RegOpcodeFld,
124 EmitByte(ModRMByte(3, RegOpcodeFld, GetX86RegNum(ModRMReg)), CurByte, OS);
127 void EmitSIBByte(
unsigned SS,
unsigned Index,
unsigned Base,
130 EmitByte(ModRMByte(SS, Index, Base), CurByte, OS);
133 void emitMemModRMByte(
const MCInst &MI,
unsigned Op,
unsigned RegOpcodeField,
134 uint64_t TSFlags,
bool Rex,
unsigned &CurByte,
142 void EmitVEXOpcodePrefix(uint64_t TSFlags,
unsigned &CurByte,
int MemOperand,
146 void EmitSegmentOverridePrefix(
unsigned &CurByte,
unsigned SegOperand,
149 bool emitOpcodePrefix(uint64_t TSFlags,
unsigned &CurByte,
int MemOperand,
153 uint8_t DetermineREXPrefix(
const MCInst &MI, uint64_t TSFlags,
156 bool isPCRel32Branch(
const MCInst &MI)
const;
164 return Value == (int8_t)Value;
171 "Compressed 8-bit displacement is only valid for EVEX inst.");
175 if (CD8_Scale == 0) {
180 unsigned Mask = CD8_Scale - 1;
181 assert((CD8_Scale & Mask) == 0 &&
"Invalid memory object size.");
184 Value /= (int)CD8_Scale;
185 bool Ret = (Value == (int8_t)Value);
213 if ((BaseReg.
getReg() != 0 &&
214 X86MCRegisterClasses[X86::GR32RegClassID].contains(BaseReg.
getReg())) ||
215 (IndexReg.
getReg() != 0 &&
216 X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg.
getReg())))
218 if (BaseReg.
getReg() == X86::EIP) {
219 assert(IndexReg.
getReg() == 0 &&
"Invalid eip-based address.");
222 if (IndexReg.
getReg() == X86::EIZ)
234 if ((BaseReg.
getReg() != 0 &&
235 X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg.
getReg())) ||
236 (IndexReg.
getReg() != 0 &&
237 X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg.
getReg())))
256 const MCExpr *RHS =
nullptr;
268 if (S.
getName() !=
"_GLOBAL_OFFSET_TABLE_")
283 bool X86MCCodeEmitter::isPCRel32Branch(
const MCInst &
MI)
const {
286 if ((Opcode != X86::CALL64pcrel32 && Opcode != X86::JMP_4) ||
299 void X86MCCodeEmitter::
303 const MCExpr *Expr =
nullptr;
304 if (DispOp.
isImm()) {
310 EmitConstant(DispOp.
getImm()+ImmOffset,
Size, CurByte, OS);
374 EmitConstant(0, Size, CurByte, OS);
377 void X86MCCodeEmitter::emitMemModRMByte(
const MCInst &MI,
unsigned Op,
378 unsigned RegOpcodeField,
379 uint64_t TSFlags,
bool Rex,
387 unsigned BaseReg = Base.
getReg();
391 if (BaseReg == X86::RIP ||
392 BaseReg == X86::EIP) {
393 assert(is64BitMode(STI) &&
"Rip-relative addressing requires 64-bit mode");
394 assert(IndexReg.
getReg() == 0 &&
"Invalid rip-relative address");
395 EmitByte(ModRMByte(0, RegOpcodeField, 5), CurByte, OS);
410 case X86::TAILJMPm64:
437 CurByte, OS,
Fixups, -ImmSize);
441 unsigned BaseRegNo = BaseReg ? GetX86RegNum(Base) : -1U;
445 if (Is16BitMemOperand(MI, Op, STI)) {
458 static const unsigned R16Table[] = { 0, 0, 0, 7, 0, 6, 4, 5 };
459 unsigned RMfield = R16Table[BaseRegNo];
461 assert(RMfield &&
"invalid 16-bit base register");
464 unsigned IndexReg16 = R16Table[GetX86RegNum(IndexReg)];
466 assert(IndexReg16 &&
"invalid 16-bit index register");
468 assert(((IndexReg16 ^ RMfield) & 2) &&
469 "invalid 16-bit base/index register combination");
471 "invalid scale for 16-bit memory reference");
475 RMfield = (RMfield & 1) | ((7 - IndexReg16) << 1);
477 RMfield = (IndexReg16 & 1) | ((7 - RMfield) << 1);
481 if (Disp.
getImm() == 0 && RMfield != 6) {
483 EmitByte(ModRMByte(0, RegOpcodeField, RMfield), CurByte, OS);
487 EmitByte(ModRMByte(1, RegOpcodeField, RMfield), CurByte, OS);
492 EmitByte(ModRMByte(2, RegOpcodeField, RMfield), CurByte, OS);
495 EmitByte(ModRMByte(0, RegOpcodeField, 6), CurByte, OS);
516 (!is64BitMode(STI) || BaseReg != 0)) {
519 EmitByte(ModRMByte(0, RegOpcodeField, 5), CurByte, OS);
529 EmitByte(ModRMByte(0, RegOpcodeField, BaseRegNo), CurByte, OS);
536 EmitByte(ModRMByte(1, RegOpcodeField, BaseRegNo), CurByte, OS);
544 EmitByte(ModRMByte(1, RegOpcodeField, BaseRegNo), CurByte, OS);
552 EmitByte(ModRMByte(2, RegOpcodeField, BaseRegNo), CurByte, OS);
563 IndexReg.
getReg() != X86::RSP &&
"Cannot use ESP as index reg!");
565 bool ForceDisp32 =
false;
566 bool ForceDisp8 =
false;
572 EmitByte(ModRMByte(0, RegOpcodeField, 4), CurByte, OS);
574 }
else if (!Disp.
isImm()) {
576 EmitByte(ModRMByte(2, RegOpcodeField, 4), CurByte, OS);
578 }
else if (Disp.
getImm() == 0 &&
583 EmitByte(ModRMByte(0, RegOpcodeField, 4), CurByte, OS);
586 EmitByte(ModRMByte(1, RegOpcodeField, 4), CurByte, OS);
590 EmitByte(ModRMByte(1, RegOpcodeField, 4), CurByte, OS);
592 ImmOffset = CDisp8 - Disp.
getImm();
595 EmitByte(ModRMByte(2, RegOpcodeField, 4), CurByte, OS);
599 static const unsigned SSTable[] = { ~0U, 0, 1, ~0U, 2, ~0U, ~0U, ~0U, 3 };
600 unsigned SS = SSTable[Scale.
getImm()];
607 IndexRegNo = GetX86RegNum(IndexReg);
610 EmitSIBByte(SS, IndexRegNo, 5, CurByte, OS);
614 IndexRegNo = GetX86RegNum(IndexReg);
617 EmitSIBByte(SS, IndexRegNo, GetX86RegNum(Base), CurByte, OS);
623 else if (ForceDisp32 || Disp.
getImm() != 0)
630 void X86MCCodeEmitter::EmitVEXOpcodePrefix(uint64_t TSFlags,
unsigned &CurByte,
631 int MemOperand,
const MCInst &MI,
648 uint8_t EVEX_R2 = 0x1;
692 uint8_t EVEX_V2 = 0x1;
723 uint8_t EVEX_z = (HasEVEX_K && (TSFlags &
X86II::EVEX_Z)) ? 1 : 0;
732 uint8_t EVEX_aaa = 0;
734 bool EncodeRC =
false;
751 VEX_B = ~(BaseRegEnc >> 3) & 1;
753 VEX_X = ~(IndexRegEnc >> 3) & 1;
755 EVEX_V2 = ~(IndexRegEnc >> 4) & 1;
760 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
763 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
764 VEX_4V = ~VRegEnc & 0xf;
765 EVEX_V2 = ~(VRegEnc >> 4) & 1;
768 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
769 VEX_R = ~(RegEnc >> 3) & 1;
770 EVEX_R2 = ~(RegEnc >> 4) & 1;
782 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
783 VEX_R = ~(RegEnc >> 3) & 1;
784 EVEX_R2 = ~(RegEnc >> 4) & 1;
787 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
790 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
791 VEX_4V = ~VRegEnc & 0xf;
792 EVEX_V2 = ~(VRegEnc >> 4) & 1;
796 VEX_B = ~(BaseRegEnc >> 3) & 1;
798 VEX_X = ~(IndexRegEnc >> 3) & 1;
800 EVEX_V2 = ~(IndexRegEnc >> 4) & 1;
807 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
808 VEX_R = ~(RegEnc >> 3) & 1;
811 VEX_B = ~(BaseRegEnc >> 3) & 1;
813 VEX_X = ~(IndexRegEnc >> 3) & 1;
820 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
821 VEX_R = ~(RegEnc >> 3) & 1;
823 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
824 VEX_4V = ~VRegEnc & 0xf;
827 VEX_B = ~(BaseRegEnc >> 3) & 1;
829 VEX_X = ~(IndexRegEnc >> 3) & 1;
840 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
841 VEX_4V = ~VRegEnc & 0xf;
842 EVEX_V2 = ~(VRegEnc >> 4) & 1;
846 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
849 VEX_B = ~(BaseRegEnc >> 3) & 1;
851 VEX_X = ~(IndexRegEnc >> 3) & 1;
862 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
863 VEX_R = ~(RegEnc >> 3) & 1;
864 EVEX_R2 = ~(RegEnc >> 4) & 1;
867 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
870 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
871 VEX_4V = ~VRegEnc & 0xf;
872 EVEX_V2 = ~(VRegEnc >> 4) & 1;
875 RegEnc = getX86RegEncoding(MI, CurOp++);
876 VEX_B = ~(RegEnc >> 3) & 1;
877 VEX_X = ~(RegEnc >> 4) & 1;
881 unsigned RcOperand = NumOps-1;
882 assert(RcOperand >= CurOp);
892 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
893 VEX_R = ~(RegEnc >> 3) & 1;
895 RegEnc = getX86RegEncoding(MI, CurOp++);
896 VEX_B = ~(RegEnc >> 3) & 1;
898 VEX_4V = ~getX86RegEncoding(MI, CurOp++) & 0xf;
903 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
904 VEX_R = ~(RegEnc >> 3) & 1;
906 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
907 VEX_4V = ~VRegEnc & 0xf;
912 RegEnc = getX86RegEncoding(MI, CurOp++);
913 VEX_B = ~(RegEnc >> 3) & 1;
914 VEX_X = ~(RegEnc >> 4) & 1;
922 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
923 VEX_B = ~(RegEnc >> 3) & 1;
924 VEX_X = ~(RegEnc >> 4) & 1;
927 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
930 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
931 VEX_4V = ~VRegEnc & 0xf;
932 EVEX_V2 = ~(VRegEnc >> 4) & 1;
935 RegEnc = getX86RegEncoding(MI, CurOp++);
936 VEX_R = ~(RegEnc >> 3) & 1;
937 EVEX_R2 = ~(RegEnc >> 4) & 1;
949 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
950 VEX_4V = ~VRegEnc & 0xf;
951 EVEX_V2 = ~(VRegEnc >> 4) & 1;
954 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
956 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
957 VEX_B = ~(RegEnc >> 3) & 1;
958 VEX_X = ~(RegEnc >> 4) & 1;
979 uint8_t LastByte = VEX_PP | (VEX_L << 2) | (VEX_4V << 3);
982 if (Encoding ==
X86II::VEX && VEX_B && VEX_X && !VEX_W && (VEX_5M == 1)) {
983 EmitByte(0xC5, CurByte, OS);
984 EmitByte(LastByte | (VEX_R << 7), CurByte, OS);
989 EmitByte(Encoding ==
X86II::XOP ? 0x8F : 0xC4, CurByte, OS);
990 EmitByte(VEX_R << 7 | VEX_X << 6 | VEX_B << 5 | VEX_5M, CurByte, OS);
991 EmitByte(LastByte | (VEX_W << 7), CurByte, OS);
999 assert((VEX_5M & 0x3) == VEX_5M
1000 &&
"More than 2 significant bits in VEX.m-mmmm fields for EVEX!");
1002 EmitByte(0x62, CurByte, OS);
1003 EmitByte((VEX_R << 7) |
1007 VEX_5M, CurByte, OS);
1008 EmitByte((VEX_W << 7) |
1011 VEX_PP, CurByte, OS);
1013 EmitByte((EVEX_z << 7) |
1017 EVEX_aaa, CurByte, OS);
1019 EmitByte((EVEX_z << 7) |
1024 EVEX_aaa, CurByte, OS);
1031 uint8_t X86MCCodeEmitter::DetermineREXPrefix(
const MCInst &MI, uint64_t TSFlags,
1035 bool UsesHighByteReg =
false;
1046 for (
unsigned i = CurOp; i != NumOps; ++i) {
1048 if (!MO.
isReg())
continue;
1050 if (Reg == X86::AH || Reg == X86::BH || Reg == X86::CH || Reg == X86::DH)
1051 UsesHighByteReg =
true;
1060 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1063 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1064 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1067 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1074 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1075 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1081 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1096 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1099 if (REX && UsesHighByteReg)
1106 void X86MCCodeEmitter::EmitSegmentOverridePrefix(
unsigned &CurByte,
1107 unsigned SegOperand,
1114 case X86::CS: EmitByte(0x2E, CurByte, OS);
break;
1115 case X86::SS: EmitByte(0x36, CurByte, OS);
break;
1116 case X86::DS: EmitByte(0x3E, CurByte, OS);
break;
1117 case X86::ES: EmitByte(0x26, CurByte, OS);
break;
1118 case X86::FS: EmitByte(0x64, CurByte, OS);
break;
1119 case X86::GS: EmitByte(0x65, CurByte, OS);
break;
1129 bool X86MCCodeEmitter::emitOpcodePrefix(uint64_t TSFlags,
unsigned &CurByte,
1130 int MemOperand,
const MCInst &MI,
1138 EmitByte(0x66, CurByte, OS);
1142 EmitByte(0xF0, CurByte, OS);
1146 EmitByte(0x3E, CurByte, OS);
1150 EmitByte(0x66, CurByte, OS);
1153 EmitByte(0xF3, CurByte, OS);
1156 EmitByte(0xF2, CurByte, OS);
1162 if (is64BitMode(STI)) {
1163 if (uint8_t REX = DetermineREXPrefix(MI, TSFlags, MemOperand, Desc)) {
1164 EmitByte(0x40 | REX, CurByte, OS);
1177 EmitByte(0x0F, CurByte, OS);
1181 switch (TSFlags & X86II::OpMapMask) {
1183 EmitByte(0x38, CurByte, OS);
1186 EmitByte(0x3A, CurByte, OS);
1192 void X86MCCodeEmitter::
1198 uint64_t TSFlags = Desc.
TSFlags;
1209 unsigned CurByte = 0;
1223 unsigned I8RegNum = 0;
1227 if (MemoryOperand != -1) MemoryOperand += CurOp;
1230 if (MemoryOperand >= 0)
1236 EmitByte(0xF3, CurByte, OS);
1238 EmitByte(0xF2, CurByte, OS);
1241 bool need_address_override;
1246 need_address_override =
true;
1247 }
else if (MemoryOperand < 0) {
1248 need_address_override =
false;
1249 }
else if (is64BitMode(STI)) {
1250 assert(!Is16BitMemOperand(MI, MemoryOperand, STI));
1252 }
else if (is32BitMode(STI)) {
1254 need_address_override = Is16BitMemOperand(MI, MemoryOperand, STI);
1256 assert(is16BitMode(STI));
1258 need_address_override = !Is16BitMemOperand(MI, MemoryOperand, STI);
1261 if (need_address_override)
1262 EmitByte(0x67, CurByte, OS);
1266 Rex = emitOpcodePrefix(TSFlags, CurByte, MemoryOperand, MI, Desc, STI, OS);
1268 EmitVEXOpcodePrefix(TSFlags, CurByte, MemoryOperand, MI, Desc, OS);
1277 default:
errs() <<
"FORM: " << Form <<
"\n";
1286 "SI and DI register sizes do not match");
1289 EmitSegmentOverridePrefix(CurByte, 2, MI, OS);
1291 if ((!is32BitMode(STI) && siReg ==
X86::ESI) ||
1292 (is32BitMode(STI) && siReg ==
X86::SI))
1293 EmitByte(0x67, CurByte, OS);
1295 EmitByte(BaseOpcode, CurByte, OS);
1302 EmitSegmentOverridePrefix(CurByte, 1, MI, OS);
1304 if ((!is32BitMode(STI) && siReg ==
X86::ESI) ||
1305 (is32BitMode(STI) && siReg ==
X86::SI))
1306 EmitByte(0x67, CurByte, OS);
1308 EmitByte(BaseOpcode, CurByte, OS);
1314 if ((!is32BitMode(STI) && siReg ==
X86::EDI) ||
1315 (is32BitMode(STI) && siReg == X86::DI))
1316 EmitByte(0x67, CurByte, OS);
1318 EmitByte(BaseOpcode, CurByte, OS);
1322 EmitByte(BaseOpcode, CurByte, OS);
1324 if (!is64BitMode(STI) || !isPCRel32Branch(MI))
1335 EmitSegmentOverridePrefix(CurByte, 1, MI, OS);
1336 EmitByte(BaseOpcode, CurByte, OS);
1343 EmitByte(BaseOpcode, CurByte, OS);
1351 EmitByte(BaseOpcode, CurByte, OS);
1360 EmitByte(BaseOpcode + GetX86RegNum(MI.
getOperand(CurOp++)), CurByte, OS);
1364 EmitByte(BaseOpcode, CurByte, OS);
1365 unsigned SrcRegNum = CurOp + 1;
1374 GetX86RegNum(MI.
getOperand(SrcRegNum)), CurByte, OS);
1375 CurOp = SrcRegNum + 1;
1379 EmitByte(BaseOpcode, CurByte, OS);
1388 emitMemModRMByte(MI, CurOp, GetX86RegNum(MI.
getOperand(SrcRegNum)), TSFlags,
1389 Rex, CurByte, OS, Fixups, STI);
1390 CurOp = SrcRegNum + 1;
1394 EmitByte(BaseOpcode, CurByte, OS);
1395 unsigned SrcRegNum = CurOp + 1;
1404 GetX86RegNum(MI.
getOperand(CurOp)), CurByte, OS);
1405 CurOp = SrcRegNum + 1;
1407 I8RegNum = getX86RegEncoding(MI, CurOp++);
1414 EmitByte(BaseOpcode, CurByte, OS);
1415 unsigned SrcRegNum = CurOp + 1;
1418 GetX86RegNum(MI.
getOperand(CurOp)), CurByte, OS);
1419 CurOp = SrcRegNum + 1;
1424 EmitByte(BaseOpcode, CurByte, OS);
1425 unsigned SrcRegNum = CurOp + 1;
1431 assert(HasVEX_I8Reg &&
"MRMSrcRegOp4 should imply VEX_I8Reg");
1432 I8RegNum = getX86RegEncoding(MI, SrcRegNum++);
1435 GetX86RegNum(MI.
getOperand(CurOp)), CurByte, OS);
1436 CurOp = SrcRegNum + 1;
1440 unsigned FirstMemOp = CurOp+1;
1448 EmitByte(BaseOpcode, CurByte, OS);
1450 emitMemModRMByte(MI, FirstMemOp, GetX86RegNum(MI.
getOperand(CurOp)),
1451 TSFlags, Rex, CurByte, OS, Fixups, STI);
1454 I8RegNum = getX86RegEncoding(MI, CurOp++);
1458 unsigned FirstMemOp = CurOp+1;
1460 EmitByte(BaseOpcode, CurByte, OS);
1462 emitMemModRMByte(MI, FirstMemOp, GetX86RegNum(MI.
getOperand(CurOp)),
1463 TSFlags, Rex, CurByte, OS, Fixups, STI);
1469 unsigned FirstMemOp = CurOp+1;
1474 assert(HasVEX_I8Reg &&
"MRMSrcRegOp4 should imply VEX_I8Reg");
1475 I8RegNum = getX86RegEncoding(MI, FirstMemOp++);
1477 EmitByte(BaseOpcode, CurByte, OS);
1479 emitMemModRMByte(MI, FirstMemOp, GetX86RegNum(MI.
getOperand(CurOp)),
1480 TSFlags, Rex, CurByte, OS, Fixups, STI);
1494 EmitByte(BaseOpcode, CurByte, OS);
1509 EmitByte(BaseOpcode, CurByte, OS);
1510 emitMemModRMByte(MI, CurOp,
1512 Rex, CurByte, OS, Fixups, STI);
1538 EmitByte(BaseOpcode, CurByte, OS);
1546 assert(I8RegNum < 16 &&
"Register encoding out of range");
1548 if (CurOp != NumOps) {
1550 assert(Val < 16 &&
"Immediate operand value out of range");
1559 while (CurOp != NumOps && NumOps - CurOp <= 2) {
1571 if ( CurOp != NumOps) {
1572 errs() <<
"Cannot encode all operands of: ";
1583 return new X86MCCodeEmitter(MCII, Ctx);
static bool HasSecRelSymbolRef(const MCExpr *Expr)
MRMSrcRegOp4 - This form is used for instructions that use the Mod/RM byte to specify the fourth sour...
static bool Is64BitMemOperand(const MCInst &MI, unsigned Op)
Is64BitMemOperand - Return true if the specified instruction has a 64-bit memory operand.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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
static bool isDisp8(int Value)
isDisp8 - Return true if this signed displacement fits in a 8-bit sign-extended field.
void push_back(const T &Elt)
Describe properties that are true of each instruction in the target description file.
RawFrmDstSrc - This form is for instructions that use the source index register SI/ESI/RSI with a pos...
static GlobalOffsetTableExprKind StartsWithGlobalOffsetTable(const MCExpr *Expr)
RawFrmMemOffs - This form is for instructions that store an absolute memory offset as an immediate wi...
AddrNumOperands - Total number of operands in a memory reference.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
static MCFixupKind getKindForSize(unsigned Size, bool isPCRel)
Return the generic fixup kind for a value with the given size.
MRMXm - This form is used for instructions that use the Mod/RM byte to specify a memory source...
static Lanai::Fixups FixupKind(const MCExpr *Expr)
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.
MRM_XX - A mod/rm byte of exactly 0xXX.
RawFrmDst - This form is for instructions that use the destination index register DI/EDI/RDI...
unsigned isImmPCRel(uint64_t TSFlags)
isImmPCRel - Return true if the immediate of the specified instruction's TSFlags indicates that it is...
A one-byte pc relative fixup.
MRMSrcMemOp4 - This form is used for instructions that use the Mod/RM byte to specify the fourth sour...
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const FeatureBitset & getFeatureBits() const
MCCodeEmitter * createX86MCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
ThreeDNow - This indicates that the instruction uses the wacky 0x0F 0x0F prefix for 3DNow! instructio...
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.
MRMSrcReg - 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.
MRMDestReg - This form is used for instructions that use the Mod/RM byte to specify a destination...
uint8_t getBaseOpcodeFor(uint64_t TSFlags)
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
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)
isCDisp8 - Return true if this signed displacement fits in a 8-bit compressed dispacement field...
Instances of this class represent a single low-level machine instruction.
MRMSrcMem4VOp3 - This form is used for instructions that encode operand 3 with VEX.VVVV and load from memory.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
static MCFixupKind getImmFixupKind(uint64_t TSFlags)
getImmFixupKind - Return the appropriate fixup kind to use for an immediate in an instruction with th...
unsigned const MachineRegisterInfo * MRI
AddRegFrm - This form is used for instructions like 'push r32' that have their one register operand a...
unsigned getFlags() const
MCCodeEmitter - Generic instruction encoding interface.
Interface to description of machine instruction set.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
unsigned getOperandBias(const MCInstrDesc &Desc)
getOperandBias - compute whether all of the def operands are repeated in the uses and therefore shoul...
unsigned getNumOperands() const
unsigned isImmSigned(uint64_t TSFlags)
isImmSigned - Return true if the immediate of the specified instruction's TSFlags indicates that it i...
Binary assembler expressions.
RawFrmImm8 - This is used for the ENTER instruction, which has two immediates, the first of which is ...
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.
static bool Is32BitMemOperand(const MCInst &MI, unsigned Op)
Is32BitMemOperand - Return true if the specified instruction has a 32-bit memory operand.
A two-byte pc relative fixup.
MRMXr - This form is used for instructions that use the Mod/RM byte to specify a register source...
A four-byte pc relative fixup.
const MCSymbol & getSymbol() const
Raw - This form is for instructions that don't have any operands, so they are just a fixed opcode val...
const MCOperand & getOperand(unsigned i) const
RawFrmImm16 - This is used for CALL FAR instructions, which have two immediates, the first of which i...
The access may modify the value stored in memory.
MRMSrcMem - This form is used for instructions that use the Mod/RM byte to specify a source...
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
MRMSrcReg4VOp3 - This form is used for instructions that encode operand 3 with VEX.VVVV and do not load from memory.
unsigned getSizeOfImm(uint64_t TSFlags)
getSizeOfImm - Decode the "size of immediate" field from the TSFlags field of the specified instructi...
Generic base class for all target subtargets.
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.
XOP - Opcode prefix used by XOP instructions.
StringRef getName() const
getName - Get the symbol name.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCRegisterInfo * getRegisterInfo() const
LLVM Value Representation.
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...
GlobalOffsetTableExprKind
StartsWithGlobalOffsetTable - Check if this expression starts with GLOBAL_OFFSET_TABLE and if it is o...
AddrSegmentReg - The operand # of the segment in the memory operand.
static bool isPCRel(unsigned Kind)
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)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
int getMemoryOperandNo(uint64_t TSFlags)
getMemoryOperandNo - The function returns the MCInst operand # for the first field of the memory oper...
RawFrmSrc - This form is for instructions that use the source index register SI/ESI/RSI with a possib...