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 {
84 return Ctx.getRegisterInfo()->getEncodingValue(MO.
getReg()) & 0x7;
87 unsigned getX86RegEncoding(
const MCInst &MI,
unsigned OpNum)
const {
88 return Ctx.getRegisterInfo()->getEncodingValue(
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,
162 return Value == (int8_t)Value;
169 "Compressed 8-bit displacement is only valid for EVEX inst.");
173 if (CD8_Scale == 0) {
178 unsigned Mask = CD8_Scale - 1;
179 assert((CD8_Scale & Mask) == 0 &&
"Invalid memory object size.");
182 Value /= (int)CD8_Scale;
183 bool Ret = (Value == (int8_t)Value);
211 if ((BaseReg.
getReg() != 0 &&
212 X86MCRegisterClasses[X86::GR32RegClassID].contains(BaseReg.
getReg())) ||
213 (IndexReg.
getReg() != 0 &&
214 X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg.
getReg())))
216 if (BaseReg.
getReg() == X86::EIP) {
217 assert(IndexReg.
getReg() == 0 &&
"Invalid eip-based address.");
230 if ((BaseReg.
getReg() != 0 &&
231 X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg.
getReg())) ||
232 (IndexReg.
getReg() != 0 &&
233 X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg.
getReg())))
252 const MCExpr *RHS =
nullptr;
264 if (S.
getName() !=
"_GLOBAL_OFFSET_TABLE_")
279 void X86MCCodeEmitter::
283 const MCExpr *Expr =
nullptr;
284 if (DispOp.
isImm()) {
290 EmitConstant(DispOp.
getImm()+ImmOffset,
Size, CurByte, OS);
347 EmitConstant(0, Size, CurByte, OS);
350 void X86MCCodeEmitter::emitMemModRMByte(
const MCInst &
MI,
unsigned Op,
351 unsigned RegOpcodeField,
352 uint64_t TSFlags,
bool Rex,
360 unsigned BaseReg = Base.
getReg();
364 if (BaseReg == X86::RIP ||
365 BaseReg == X86::EIP) {
366 assert(is64BitMode(STI) &&
"Rip-relative addressing requires 64-bit mode");
367 assert(IndexReg.
getReg() == 0 &&
"Invalid rip-relative address");
368 EmitByte(ModRMByte(0, RegOpcodeField, 5), CurByte, OS);
374 unsigned FixupKind = [=]() {
405 CurByte, OS,
Fixups, -ImmSize);
409 unsigned BaseRegNo = BaseReg ? GetX86RegNum(Base) : -1U;
413 if (Is16BitMemOperand(MI, Op, STI)) {
426 static const unsigned R16Table[] = { 0, 0, 0, 7, 0, 6, 4, 5 };
427 unsigned RMfield = R16Table[BaseRegNo];
429 assert(RMfield &&
"invalid 16-bit base register");
432 unsigned IndexReg16 = R16Table[GetX86RegNum(IndexReg)];
434 assert(IndexReg16 &&
"invalid 16-bit index register");
436 assert(((IndexReg16 ^ RMfield) & 2) &&
437 "invalid 16-bit base/index register combination");
439 "invalid scale for 16-bit memory reference");
443 RMfield = (RMfield & 1) | ((7 - IndexReg16) << 1);
445 RMfield = (IndexReg16 & 1) | ((7 - RMfield) << 1);
451 EmitByte(ModRMByte(0, RegOpcodeField, RMfield), CurByte, OS);
455 EmitByte(ModRMByte(1, RegOpcodeField, RMfield), CurByte, OS);
460 EmitByte(ModRMByte(2, RegOpcodeField, RMfield), CurByte, OS);
463 EmitByte(ModRMByte(0, RegOpcodeField, 6), CurByte, OS);
484 (!is64BitMode(STI) || BaseReg != 0)) {
487 EmitByte(ModRMByte(0, RegOpcodeField, 5), CurByte, OS);
497 EmitByte(ModRMByte(0, RegOpcodeField, BaseRegNo), CurByte, OS);
504 EmitByte(ModRMByte(1, RegOpcodeField, BaseRegNo), CurByte, OS);
512 EmitByte(ModRMByte(1, RegOpcodeField, BaseRegNo), CurByte, OS);
520 EmitByte(ModRMByte(2, RegOpcodeField, BaseRegNo), CurByte, OS);
531 IndexReg.
getReg() != X86::RSP &&
"Cannot use ESP as index reg!");
533 bool ForceDisp32 =
false;
534 bool ForceDisp8 =
false;
540 EmitByte(ModRMByte(0, RegOpcodeField, 4), CurByte, OS);
542 }
else if (!Disp.
isImm()) {
544 EmitByte(ModRMByte(2, RegOpcodeField, 4), CurByte, OS);
546 }
else if (Disp.
getImm() == 0 &&
551 EmitByte(ModRMByte(0, RegOpcodeField, 4), CurByte, OS);
554 EmitByte(ModRMByte(1, RegOpcodeField, 4), CurByte, OS);
558 EmitByte(ModRMByte(1, RegOpcodeField, 4), CurByte, OS);
560 ImmOffset = CDisp8 - Disp.
getImm();
563 EmitByte(ModRMByte(2, RegOpcodeField, 4), CurByte, OS);
567 static const unsigned SSTable[] = { ~0U, 0, 1, ~0U, 2, ~0U, ~0U, ~0U, 3 };
568 unsigned SS = SSTable[Scale.
getImm()];
575 IndexRegNo = GetX86RegNum(IndexReg);
578 EmitSIBByte(SS, IndexRegNo, 5, CurByte, OS);
582 IndexRegNo = GetX86RegNum(IndexReg);
585 EmitSIBByte(SS, IndexRegNo, GetX86RegNum(Base), CurByte, OS);
591 else if (ForceDisp32 || Disp.
getImm() != 0)
598 void X86MCCodeEmitter::EmitVEXOpcodePrefix(uint64_t TSFlags,
unsigned &CurByte,
599 int MemOperand,
const MCInst &MI,
616 uint8_t EVEX_R2 = 0x1;
660 uint8_t EVEX_V2 = 0x1;
693 uint8_t EVEX_z = (HasEVEX_K && (TSFlags &
X86II::EVEX_Z)) ? 1 : 0;
702 uint8_t EVEX_aaa = 0;
704 bool EncodeRC =
false;
721 VEX_B = ~(BaseRegEnc >> 3) & 1;
723 VEX_X = ~(IndexRegEnc >> 3) & 1;
725 EVEX_V2 = ~(IndexRegEnc >> 4) & 1;
730 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
733 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
734 VEX_4V = ~VRegEnc & 0xf;
735 EVEX_V2 = ~(VRegEnc >> 4) & 1;
738 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
739 VEX_R = ~(RegEnc >> 3) & 1;
740 EVEX_R2 = ~(RegEnc >> 4) & 1;
752 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
753 VEX_R = ~(RegEnc >> 3) & 1;
754 EVEX_R2 = ~(RegEnc >> 4) & 1;
757 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
760 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
761 VEX_4V = ~VRegEnc & 0xf;
762 EVEX_V2 = ~(VRegEnc >> 4) & 1;
766 VEX_B = ~(BaseRegEnc >> 3) & 1;
768 VEX_X = ~(IndexRegEnc >> 3) & 1;
770 EVEX_V2 = ~(IndexRegEnc >> 4) & 1;
777 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
778 VEX_R = ~(RegEnc >> 3) & 1;
781 VEX_B = ~(BaseRegEnc >> 3) & 1;
783 VEX_X = ~(IndexRegEnc >> 3) & 1;
790 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
791 VEX_R = ~(RegEnc >> 3) & 1;
793 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
794 VEX_4V = ~VRegEnc & 0xf;
797 VEX_B = ~(BaseRegEnc >> 3) & 1;
799 VEX_X = ~(IndexRegEnc >> 3) & 1;
810 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
811 VEX_4V = ~VRegEnc & 0xf;
812 EVEX_V2 = ~(VRegEnc >> 4) & 1;
816 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
819 VEX_B = ~(BaseRegEnc >> 3) & 1;
821 VEX_X = ~(IndexRegEnc >> 3) & 1;
832 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
833 VEX_R = ~(RegEnc >> 3) & 1;
834 EVEX_R2 = ~(RegEnc >> 4) & 1;
837 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
840 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
841 VEX_4V = ~VRegEnc & 0xf;
842 EVEX_V2 = ~(VRegEnc >> 4) & 1;
845 RegEnc = getX86RegEncoding(MI, CurOp++);
846 VEX_B = ~(RegEnc >> 3) & 1;
847 VEX_X = ~(RegEnc >> 4) & 1;
851 unsigned RcOperand = NumOps-1;
852 assert(RcOperand >= CurOp);
862 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
863 VEX_R = ~(RegEnc >> 3) & 1;
865 RegEnc = getX86RegEncoding(MI, CurOp++);
866 VEX_B = ~(RegEnc >> 3) & 1;
868 VEX_4V = ~getX86RegEncoding(MI, CurOp++) & 0xf;
873 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
874 VEX_R = ~(RegEnc >> 3) & 1;
876 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
877 VEX_4V = ~VRegEnc & 0xf;
882 RegEnc = getX86RegEncoding(MI, CurOp++);
883 VEX_B = ~(RegEnc >> 3) & 1;
884 VEX_X = ~(RegEnc >> 4) & 1;
892 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
893 VEX_B = ~(RegEnc >> 3) & 1;
894 VEX_X = ~(RegEnc >> 4) & 1;
897 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
900 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
901 VEX_4V = ~VRegEnc & 0xf;
902 EVEX_V2 = ~(VRegEnc >> 4) & 1;
905 RegEnc = getX86RegEncoding(MI, CurOp++);
906 VEX_R = ~(RegEnc >> 3) & 1;
907 EVEX_R2 = ~(RegEnc >> 4) & 1;
919 unsigned VRegEnc = getX86RegEncoding(MI, CurOp++);
920 VEX_4V = ~VRegEnc & 0xf;
921 EVEX_V2 = ~(VRegEnc >> 4) & 1;
924 EVEX_aaa = getX86RegEncoding(MI, CurOp++);
926 unsigned RegEnc = getX86RegEncoding(MI, CurOp++);
927 VEX_B = ~(RegEnc >> 3) & 1;
928 VEX_X = ~(RegEnc >> 4) & 1;
949 uint8_t LastByte = VEX_PP | (VEX_L << 2) | (VEX_4V << 3);
952 if (Encoding ==
X86II::VEX && VEX_B && VEX_X && !VEX_W && (VEX_5M == 1)) {
953 EmitByte(0xC5, CurByte, OS);
954 EmitByte(LastByte | (VEX_R << 7), CurByte, OS);
959 EmitByte(Encoding ==
X86II::XOP ? 0x8F : 0xC4, CurByte, OS);
960 EmitByte(VEX_R << 7 | VEX_X << 6 | VEX_B << 5 | VEX_5M, CurByte, OS);
961 EmitByte(LastByte | (VEX_W << 7), CurByte, OS);
969 assert((VEX_5M & 0x3) == VEX_5M
970 &&
"More than 2 significant bits in VEX.m-mmmm fields for EVEX!");
972 EmitByte(0x62, CurByte, OS);
973 EmitByte((VEX_R << 7) |
977 VEX_5M, CurByte, OS);
978 EmitByte((VEX_W << 7) |
981 VEX_PP, CurByte, OS);
983 EmitByte((EVEX_z << 7) |
987 EVEX_aaa, CurByte, OS);
989 EmitByte((EVEX_z << 7) |
994 EVEX_aaa, CurByte, OS);
1001 uint8_t X86MCCodeEmitter::DetermineREXPrefix(
const MCInst &MI, uint64_t TSFlags,
1005 bool UsesHighByteReg =
false;
1016 for (
unsigned i = CurOp; i != NumOps; ++i) {
1018 if (!MO.
isReg())
continue;
1020 if (Reg == X86::AH || Reg == X86::BH || Reg == X86::CH || Reg == X86::DH)
1021 UsesHighByteReg =
true;
1028 switch (TSFlags & X86II::FormMask) {
1030 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1033 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1034 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1037 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1044 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1045 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1051 REX |= isREXExtendedReg(MI, CurOp++) << 2;
1066 REX |= isREXExtendedReg(MI, CurOp++) << 0;
1069 if (REX && UsesHighByteReg)
1076 void X86MCCodeEmitter::EmitSegmentOverridePrefix(
unsigned &CurByte,
1077 unsigned SegOperand,
1084 case X86::CS: EmitByte(0x2E, CurByte, OS);
break;
1085 case X86::SS: EmitByte(0x36, CurByte, OS);
break;
1086 case X86::DS: EmitByte(0x3E, CurByte, OS);
break;
1087 case X86::ES: EmitByte(0x26, CurByte, OS);
break;
1088 case X86::FS: EmitByte(0x64, CurByte, OS);
break;
1089 case X86::GS: EmitByte(0x65, CurByte, OS);
break;
1099 bool X86MCCodeEmitter::emitOpcodePrefix(uint64_t TSFlags,
unsigned &CurByte,
1100 int MemOperand,
const MCInst &MI,
1108 EmitByte(0x66, CurByte, OS);
1112 EmitByte(0xF0, CurByte, OS);
1114 switch (TSFlags & X86II::OpPrefixMask) {
1116 EmitByte(0x66, CurByte, OS);
1119 EmitByte(0xF3, CurByte, OS);
1122 EmitByte(0xF2, CurByte, OS);
1128 if (is64BitMode(STI)) {
1129 if (uint8_t REX = DetermineREXPrefix(MI, TSFlags, MemOperand, Desc)) {
1130 EmitByte(0x40 | REX, CurByte, OS);
1136 switch (TSFlags & X86II::OpMapMask) {
1140 EmitByte(0x0F, CurByte, OS);
1144 switch (TSFlags & X86II::OpMapMask) {
1146 EmitByte(0x38, CurByte, OS);
1149 EmitByte(0x3A, CurByte, OS);
1155 void X86MCCodeEmitter::
1161 uint64_t TSFlags = Desc.
TSFlags;
1171 unsigned CurByte = 0;
1185 unsigned I8RegNum = 0;
1189 if (MemoryOperand != -1) MemoryOperand += CurOp;
1192 if (MemoryOperand >= 0)
1198 EmitByte(0xF3, CurByte, OS);
1201 bool need_address_override;
1206 need_address_override =
true;
1207 }
else if (MemoryOperand < 0) {
1208 need_address_override =
false;
1209 }
else if (is64BitMode(STI)) {
1210 assert(!Is16BitMemOperand(MI, MemoryOperand, STI));
1212 }
else if (is32BitMode(STI)) {
1214 need_address_override = Is16BitMemOperand(MI, MemoryOperand, STI);
1216 assert(is16BitMode(STI));
1218 need_address_override = !Is16BitMemOperand(MI, MemoryOperand, STI);
1221 if (need_address_override)
1222 EmitByte(0x67, CurByte, OS);
1226 Rex = emitOpcodePrefix(TSFlags, CurByte, MemoryOperand, MI, Desc, STI, OS);
1228 EmitVEXOpcodePrefix(TSFlags, CurByte, MemoryOperand, MI, Desc, OS);
1237 default:
errs() <<
"FORM: " << Form <<
"\n";
1246 "SI and DI register sizes do not match");
1249 EmitSegmentOverridePrefix(CurByte, 2, MI, OS);
1251 if ((!is32BitMode(STI) && siReg == X86::ESI) ||
1252 (is32BitMode(STI) && siReg == X86::SI))
1253 EmitByte(0x67, CurByte, OS);
1255 EmitByte(BaseOpcode, CurByte, OS);
1262 EmitSegmentOverridePrefix(CurByte, 1, MI, OS);
1264 if ((!is32BitMode(STI) && siReg == X86::ESI) ||
1265 (is32BitMode(STI) && siReg == X86::SI))
1266 EmitByte(0x67, CurByte, OS);
1268 EmitByte(BaseOpcode, CurByte, OS);
1274 if ((!is32BitMode(STI) && siReg == X86::EDI) ||
1275 (is32BitMode(STI) && siReg == X86::DI))
1276 EmitByte(0x67, CurByte, OS);
1278 EmitByte(BaseOpcode, CurByte, OS);
1282 EmitByte(BaseOpcode, CurByte, OS);
1286 EmitSegmentOverridePrefix(CurByte, 1, MI, OS);
1287 EmitByte(BaseOpcode, CurByte, OS);
1294 EmitByte(BaseOpcode, CurByte, OS);
1302 EmitByte(BaseOpcode, CurByte, OS);
1311 EmitByte(BaseOpcode + GetX86RegNum(MI.
getOperand(CurOp++)), CurByte, OS);
1315 EmitByte(BaseOpcode, CurByte, OS);
1316 unsigned SrcRegNum = CurOp + 1;
1325 GetX86RegNum(MI.
getOperand(SrcRegNum)), CurByte, OS);
1326 CurOp = SrcRegNum + 1;
1330 EmitByte(BaseOpcode, CurByte, OS);
1339 emitMemModRMByte(MI, CurOp, GetX86RegNum(MI.
getOperand(SrcRegNum)), TSFlags,
1340 Rex, CurByte, OS, Fixups, STI);
1341 CurOp = SrcRegNum + 1;
1345 EmitByte(BaseOpcode, CurByte, OS);
1346 unsigned SrcRegNum = CurOp + 1;
1355 GetX86RegNum(MI.
getOperand(CurOp)), CurByte, OS);
1356 CurOp = SrcRegNum + 1;
1358 I8RegNum = getX86RegEncoding(MI, CurOp++);
1365 EmitByte(BaseOpcode, CurByte, OS);
1366 unsigned SrcRegNum = CurOp + 1;
1369 GetX86RegNum(MI.
getOperand(CurOp)), CurByte, OS);
1370 CurOp = SrcRegNum + 1;
1375 EmitByte(BaseOpcode, CurByte, OS);
1376 unsigned SrcRegNum = CurOp + 1;
1382 assert(HasVEX_I8Reg &&
"MRMSrcRegOp4 should imply VEX_I8Reg");
1383 I8RegNum = getX86RegEncoding(MI, SrcRegNum++);
1386 GetX86RegNum(MI.
getOperand(CurOp)), CurByte, OS);
1387 CurOp = SrcRegNum + 1;
1391 unsigned FirstMemOp = CurOp+1;
1399 EmitByte(BaseOpcode, CurByte, OS);
1401 emitMemModRMByte(MI, FirstMemOp, GetX86RegNum(MI.
getOperand(CurOp)),
1402 TSFlags, Rex, CurByte, OS, Fixups, STI);
1405 I8RegNum = getX86RegEncoding(MI, CurOp++);
1409 unsigned FirstMemOp = CurOp+1;
1411 EmitByte(BaseOpcode, CurByte, OS);
1413 emitMemModRMByte(MI, FirstMemOp, GetX86RegNum(MI.
getOperand(CurOp)),
1414 TSFlags, Rex, CurByte, OS, Fixups, STI);
1420 unsigned FirstMemOp = CurOp+1;
1425 assert(HasVEX_I8Reg &&
"MRMSrcRegOp4 should imply VEX_I8Reg");
1426 I8RegNum = getX86RegEncoding(MI, FirstMemOp++);
1428 EmitByte(BaseOpcode, CurByte, OS);
1430 emitMemModRMByte(MI, FirstMemOp, GetX86RegNum(MI.
getOperand(CurOp)),
1431 TSFlags, Rex, CurByte, OS, Fixups, STI);
1445 EmitByte(BaseOpcode, CurByte, OS);
1460 EmitByte(BaseOpcode, CurByte, OS);
1461 emitMemModRMByte(MI, CurOp,
1463 Rex, CurByte, OS, Fixups, STI);
1489 EmitByte(BaseOpcode, CurByte, OS);
1497 assert(I8RegNum < 16 &&
"Register encoding out of range");
1499 if (CurOp != NumOps) {
1501 assert(Val < 16 &&
"Immediate operand value out of range");
1510 while (CurOp != NumOps && NumOps - CurOp <= 2) {
1517 if (TSFlags & X86II::Has3DNow0F0FOpcode)
1522 if ( CurOp != NumOps) {
1523 errs() <<
"Cannot encode all operands of: ";
1534 return new X86MCCodeEmitter(MCII, Ctx);
static bool HasSecRelSymbolRef(const MCExpr *Expr)
void push_back(const T &Elt)
RawFrmImm16 - This is used for CALL FAR instructions, which have two immediates, the first of which i...
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)
const MCSymbol & getSymbol() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
static bool isDisp8(int Value)
isDisp8 - Return true if this signed displacement fits in a 8-bit sign-extended field.
Describe properties that are true of each instruction in the target description file.
MRMSrcMemOp4 - This form is used for instructions that use the Mod/RM byte to specify the fourth sour...
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
static GlobalOffsetTableExprKind StartsWithGlobalOffsetTable(const MCExpr *Expr)
static MCFixupKind getKindForSize(unsigned Size, bool isPCRel)
Return the generic fixup kind for a value with the given size.
MRMSrcReg - This form is used for instructions that use the Mod/RM byte to specify a source...
MRMSrcReg4VOp3 - This form is used for instructions that encode operand 3 with VEX.VVVV and do not load from memory.
static Lanai::Fixups FixupKind(const MCExpr *Expr)
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.
MCCodeEmitter * createX86MCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
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.
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.
XOP - Opcode prefix used by XOP instructions.
Reg
All possible values of the reg field in the ModR/M byte.
Represent a reference to a symbol from inside an expression.
RawFrmMemOffs - This form is for instructions that store an absolute memory offset as an immediate wi...
A four-byte section relative fixup.
Context object for machine code objects.
MRMSrcMem4VOp3 - This form is used for instructions that encode operand 3 with VEX.VVVV and load from memory.
unsigned getReg() const
Returns the register number.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
bool hasImm(uint64_t TSFlags)
MRM_XX - A mod/rm byte of exactly 0xXX.
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.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
const MCExpr * getExpr() const
static MCFixupKind getImmFixupKind(uint64_t TSFlags)
getImmFixupKind - Return the appropriate fixup kind to use for an immediate in an instruction with th...
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
unsigned const MachineRegisterInfo * MRI
AddRegFrm - This form is used for instructions like 'push r32' that have their one register operand a...
MCCodeEmitter - Generic instruction encoding interface.
Interface to description of machine instruction set.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
MRMSrcMem - This form is used for instructions that use the Mod/RM byte to specify a source...
RawFrmSrc - This form is for instructions that use the source index register SI/ESI/RSI with a possib...
AddrNumOperands - Total number of operands in a memory reference.
MRMSrcRegOp4 - This form is used for instructions that use the Mod/RM byte to specify the fourth sour...
unsigned getOperandBias(const MCInstrDesc &Desc)
getOperandBias - compute any additional adjustment needed to the offset to the start of the memory op...
unsigned isImmSigned(uint64_t TSFlags)
isImmSigned - Return true if the immediate of the specified instruction's TSFlags indicates that it i...
Binary assembler expressions.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
static bool Is32BitMemOperand(const MCInst &MI, unsigned Op)
Is32BitMemOperand - Return true if the specified instruction has a 32-bit memory operand.
MRMXm - This form is used for instructions that use the Mod/RM byte to specify a memory source...
A two-byte pc relative fixup.
MRMDestReg - This form is used for instructions that use the Mod/RM byte to specify a destination...
A four-byte pc relative fixup.
AddrSegmentReg - The operand # of the segment in the memory operand.
MRMXr - This form is used for instructions that use the Mod/RM byte to specify a register source...
unsigned char getBaseOpcodeFor(uint64_t TSFlags)
const FeatureBitset & getFeatureBits() const
getFeatureBits - Return the feature bits.
unsigned getOpcode() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
StringRef getName() const
getName - Get the symbol name.
unsigned getSizeOfImm(uint64_t TSFlags)
getSizeOfImm - Decode the "size of immediate" field from the TSFlags field of the specified instructi...
unsigned getNumOperands() const
MCSubtargetInfo - Generic base class for all target subtargets.
References to labels and assigned expressions.
VariantKind getKind() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
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.
RawFrmImm8 - This is used for the ENTER instruction, which has two immediates, the first of which is ...
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...
RawFrmDst - This form is for instructions that use the destination index register DI/EDI/ESI...
Represents a location in source code.
RawFrmSrc - This form is for instructions that use the source index register SI/ESI/ERI with a possib...
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)
const MCOperand & getOperand(unsigned i) const
Raw - This form is for instructions that don't have any operands, so they are just a fixed opcode val...
int getMemoryOperandNo(uint64_t TSFlags)
getMemoryOperandNo - The function returns the MCInst operand # for the first field of the memory oper...