53 if (Scale != 1 && Scale != 2 && Scale != 4 && Scale != 8) {
54 ErrMsg =
"scale factor in address must be 1, 2, 4 or 8";
63#define GET_X86_SSE2AVX_TABLE
64#include "X86GenInstrMapping.inc"
66static const char OpPrecedence[] = {
92 const X86MCOptions &CLOpts;
93 ParseInstructionInfo *InstInfo;
95 unsigned ForcedDataPrefix = 0;
107 OpcodePrefix ForcedOpcodePrefix = OpcodePrefix_Default;
110 DispEncoding_Default,
115 DispEncoding ForcedDispEncoding = DispEncoding_Default;
118 bool UseApxExtendedReg =
false;
120 bool ForcedNoFlag =
false;
123 SMLoc consumeToken() {
124 MCAsmParser &Parser = getParser();
134 X86TargetStreamer &getTargetStreamer() {
135 assert(getParser().getStreamer().getTargetStreamer() &&
136 "do not have a target streamer");
137 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
138 return static_cast<X86TargetStreamer &
>(TS);
142 uint64_t &ErrorInfo, FeatureBitset &MissingFeatures,
143 bool matchingInlineAsm,
unsigned VariantID = 0) {
146 SwitchMode(X86::Is32Bit);
147 unsigned rv = MatchInstructionImpl(
Operands, Inst, ErrorInfo,
148 MissingFeatures, matchingInlineAsm,
151 SwitchMode(X86::Is16Bit);
155 enum InfixCalculatorTok {
180 enum IntelOperatorKind {
187 enum MasmOperatorKind {
194 class InfixCalculator {
195 typedef std::pair< InfixCalculatorTok, int64_t > ICToken;
199 bool isUnaryOperator(InfixCalculatorTok
Op)
const {
200 return Op == IC_NEG ||
Op == IC_NOT;
204 int64_t popOperand() {
205 assert (!PostfixStack.empty() &&
"Poped an empty stack!");
206 ICToken
Op = PostfixStack.pop_back_val();
207 if (!(
Op.first == IC_IMM ||
Op.first == IC_REGISTER))
211 void pushOperand(InfixCalculatorTok
Op, int64_t Val = 0) {
212 assert ((
Op == IC_IMM ||
Op == IC_REGISTER) &&
213 "Unexpected operand!");
214 PostfixStack.push_back(std::make_pair(
Op, Val));
217 void popOperator() { InfixOperatorStack.pop_back(); }
218 void pushOperator(InfixCalculatorTok
Op) {
220 if (InfixOperatorStack.empty()) {
221 InfixOperatorStack.push_back(
Op);
228 unsigned Idx = InfixOperatorStack.size() - 1;
229 InfixCalculatorTok StackOp = InfixOperatorStack[
Idx];
230 if (OpPrecedence[
Op] > OpPrecedence[StackOp] || StackOp == IC_LPAREN) {
231 InfixOperatorStack.push_back(
Op);
237 unsigned ParenCount = 0;
240 if (InfixOperatorStack.empty())
243 Idx = InfixOperatorStack.size() - 1;
244 StackOp = InfixOperatorStack[
Idx];
245 if (!(OpPrecedence[StackOp] >= OpPrecedence[
Op] || ParenCount))
250 if (!ParenCount && StackOp == IC_LPAREN)
253 if (StackOp == IC_RPAREN) {
255 InfixOperatorStack.pop_back();
256 }
else if (StackOp == IC_LPAREN) {
258 InfixOperatorStack.pop_back();
260 InfixOperatorStack.pop_back();
261 PostfixStack.push_back(std::make_pair(StackOp, 0));
265 InfixOperatorStack.push_back(
Op);
268 int64_t execute(StringRef &ErrMsg) {
270 while (!InfixOperatorStack.empty()) {
271 InfixCalculatorTok StackOp = InfixOperatorStack.pop_back_val();
272 if (StackOp != IC_LPAREN && StackOp != IC_RPAREN)
273 PostfixStack.push_back(std::make_pair(StackOp, 0));
276 if (PostfixStack.empty())
280 for (
const ICToken &
Op : PostfixStack) {
281 if (
Op.first == IC_IMM ||
Op.first == IC_REGISTER) {
283 }
else if (isUnaryOperator(
Op.first)) {
284 assert (OperandStack.
size() > 0 &&
"Too few operands.");
286 assert (Operand.first == IC_IMM &&
287 "Unary operation with a register!");
294 std::make_pair(IC_IMM, -
uint64_t(Operand.second)));
297 OperandStack.
push_back(std::make_pair(IC_IMM, ~Operand.second));
301 assert (OperandStack.
size() > 1 &&
"Too few operands.");
310 Val =
uint64_t(Op1.second) + Op2.second;
311 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
314 Val =
uint64_t(Op1.second) - Op2.second;
315 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
318 assert (Op1.first == IC_IMM && Op2.first == IC_IMM &&
319 "Multiply operation with an immediate and a register!");
320 Val =
uint64_t(Op1.second) * Op2.second;
321 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
325 assert(Op1.first == IC_IMM && Op2.first == IC_IMM &&
326 "Divide operation with an immediate and a register!");
327 if (Op2.second == 0) {
328 ErrMsg =
Op.first == IC_DIVIDE
329 ?
"division by zero in assembly expression"
330 :
"modulo by zero in assembly expression";
334 ErrMsg =
"division result out of range";
337 Val =
Op.first == IC_DIVIDE ? Op1.second / Op2.second
338 : Op1.second % Op2.second;
339 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
342 assert (Op1.first == IC_IMM && Op2.first == IC_IMM &&
343 "Or operation with an immediate and a register!");
344 Val = Op1.second | Op2.second;
345 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
348 assert(Op1.first == IC_IMM && Op2.first == IC_IMM &&
349 "Xor operation with an immediate and a register!");
350 Val = Op1.second ^ Op2.second;
351 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
354 assert (Op1.first == IC_IMM && Op2.first == IC_IMM &&
355 "And operation with an immediate and a register!");
356 Val = Op1.second & Op2.second;
357 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
361 assert(Op1.first == IC_IMM && Op2.first == IC_IMM &&
362 "Shift operation with an immediate and a register!");
364 ErrMsg =
"invalid shift count in assembly expression";
367 Val =
Op.first == IC_LSHIFT ?
uint64_t(Op1.second) << Op2.second
368 : Op1.second >> Op2.second;
369 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
372 assert(Op1.first == IC_IMM && Op2.first == IC_IMM &&
373 "Equals operation with an immediate and a register!");
374 Val = (Op1.second == Op2.second) ? -1 : 0;
375 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
378 assert(Op1.first == IC_IMM && Op2.first == IC_IMM &&
379 "Not-equals operation with an immediate and a register!");
380 Val = (Op1.second != Op2.second) ? -1 : 0;
381 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
384 assert(Op1.first == IC_IMM && Op2.first == IC_IMM &&
385 "Less-than operation with an immediate and a register!");
386 Val = (Op1.second < Op2.second) ? -1 : 0;
387 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
390 assert(Op1.first == IC_IMM && Op2.first == IC_IMM &&
391 "Less-than-or-equal operation with an immediate and a "
393 Val = (Op1.second <= Op2.second) ? -1 : 0;
394 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
397 assert(Op1.first == IC_IMM && Op2.first == IC_IMM &&
398 "Greater-than operation with an immediate and a register!");
399 Val = (Op1.second > Op2.second) ? -1 : 0;
400 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
403 assert(Op1.first == IC_IMM && Op2.first == IC_IMM &&
404 "Greater-than-or-equal operation with an immediate and a "
406 Val = (Op1.second >= Op2.second) ? -1 : 0;
407 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
412 assert (OperandStack.
size() == 1 &&
"Expected a single result.");
417 enum IntelExprState {
447 class IntelExprStateMachine {
448 IntelExprState State = IES_INIT, PrevState = IES_ERROR;
449 MCRegister BaseReg, IndexReg, TmpReg;
451 std::optional<unsigned> TmpScale = {};
453 const MCExpr *Sym =
nullptr;
456 InlineAsmIdentifierInfo Info;
458 short ParenCount = 0;
460 bool MemExpr =
false;
461 bool BracketUsed =
false;
462 bool NegativeAdditiveTerm =
false;
463 SMLoc NegativeAdditiveTermLoc;
464 bool OffsetOperator =
false;
465 bool AttachToOperandIdx =
false;
469 bool setSymRef(
const MCExpr *Val, StringRef ID, StringRef &ErrMsg) {
471 ErrMsg =
"cannot use more than one symbol in memory operand";
480 IntelExprStateMachine() =
default;
482 void addImm(int64_t imm) { Imm += imm; }
483 short getBracCount()
const {
return BracCount; }
484 bool isMemExpr()
const {
return MemExpr; }
485 bool isRegisterScale()
const {
return TmpReg && State == IES_MULTIPLY; }
487 return !BaseReg && !IndexReg && !TmpReg && !Sym && !MemExpr;
489 bool isBracketUsed()
const {
return BracketUsed; }
490 bool isOffsetOperator()
const {
return OffsetOperator; }
491 MCRegister getBaseReg()
const {
return BaseReg; }
492 MCRegister getIndexReg()
const {
return IndexReg; }
493 unsigned getScale()
const {
return Scale; }
494 const MCExpr *
getSym()
const {
return Sym; }
495 StringRef getSymName()
const {
return SymName; }
496 StringRef
getType()
const {
return CurType.Name; }
497 unsigned getSize()
const {
return CurType.Size; }
498 unsigned getElementSize()
const {
return CurType.ElementSize; }
499 unsigned getLength()
const {
return CurType.Length; }
500 int64_t
getImm()
const {
return Imm; }
501 bool onEnd(StringRef &ErrMsg) {
502 Imm =
uint64_t(Imm) + IC.execute(ErrMsg);
503 return !ErrMsg.
empty();
505 bool isValidEndState()
const {
506 return State == IES_RBRAC || State == IES_RPAREN ||
507 State == IES_INTEGER || State == IES_REGISTER ||
510 bool hasUnmatchedParen()
const {
return ParenCount != 0; }
511 SMLoc getLParenLoc()
const {
return LParenLoc; }
517 void setAppendAfterOperand() { AttachToOperandIdx =
true; }
519 bool isPIC()
const {
return IsPIC; }
520 void setPIC() { IsPIC =
true; }
522 bool hadError()
const {
return State == IES_ERROR; }
523 SMLoc getErrorLoc(SMLoc DefaultLoc)
const {
524 return NegativeAdditiveTerm ? NegativeAdditiveTermLoc : DefaultLoc;
526 const InlineAsmIdentifierInfo &getIdentifierInfo()
const {
return Info; }
528 bool regsUseUpError(StringRef &ErrMsg) {
531 if (IsPIC && AttachToOperandIdx)
532 ErrMsg =
"Don't use 2 or more regs for mem offset in PIC model!";
534 ErrMsg =
"BaseReg/IndexReg already set!";
539 IntelExprState CurrState = State;
548 IC.pushOperator(IC_OR);
551 PrevState = CurrState;
554 IntelExprState CurrState = State;
563 IC.pushOperator(IC_XOR);
566 PrevState = CurrState;
569 IntelExprState CurrState = State;
578 IC.pushOperator(IC_AND);
581 PrevState = CurrState;
584 IntelExprState CurrState = State;
593 IC.pushOperator(IC_EQ);
596 PrevState = CurrState;
599 IntelExprState CurrState = State;
608 IC.pushOperator(IC_NE);
611 PrevState = CurrState;
614 IntelExprState CurrState = State;
623 IC.pushOperator(IC_LT);
626 PrevState = CurrState;
629 IntelExprState CurrState = State;
638 IC.pushOperator(IC_LE);
641 PrevState = CurrState;
644 IntelExprState CurrState = State;
653 IC.pushOperator(IC_GT);
656 PrevState = CurrState;
659 IntelExprState CurrState = State;
668 IC.pushOperator(IC_GE);
671 PrevState = CurrState;
674 IntelExprState CurrState = State;
683 IC.pushOperator(IC_LSHIFT);
686 PrevState = CurrState;
689 IntelExprState CurrState = State;
698 IC.pushOperator(IC_RSHIFT);
701 PrevState = CurrState;
703 bool onPlus(StringRef &ErrMsg) {
704 IntelExprState CurrState = State;
714 IC.pushOperator(IC_PLUS);
718 if (!BaseReg && !TmpScale.has_value()) {
723 return regsUseUpError(ErrMsg);
726 if (NegativeAdditiveTerm) {
727 ErrMsg =
"Scale can't be negative";
730 if (TmpScale.has_value() &&
checkScale(TmpScale.value(), ErrMsg)) {
733 Scale = TmpScale.value_or(0);
738 NegativeAdditiveTerm =
false;
739 NegativeAdditiveTermLoc = SMLoc();
742 PrevState = CurrState;
745 bool onMinus(SMLoc MinusLoc, StringRef &ErrMsg) {
746 IntelExprState CurrState = State;
776 NegativeAdditiveTerm =
true;
777 NegativeAdditiveTermLoc = MinusLoc;
779 if (CurrState == IES_REGISTER || CurrState == IES_RPAREN ||
780 CurrState == IES_INTEGER || CurrState == IES_RBRAC ||
781 CurrState == IES_OFFSET) {
782 IC.pushOperator(IC_MINUS);
786 if (!BaseReg && !TmpScale.has_value()) {
791 return regsUseUpError(ErrMsg);
794 if (TmpScale.has_value() &&
798 Scale = TmpScale.value_or(0);
801 }
else if (PrevState == IES_REGISTER && CurrState == IES_MULTIPLY) {
803 ErrMsg =
"Scale can't be negative";
806 IC.pushOperator(IC_NEG);
811 PrevState = CurrState;
815 IntelExprState CurrState = State;
841 IC.pushOperator(IC_NOT);
844 PrevState = CurrState;
846 bool onRegister(MCRegister
Reg,
bool IsScale, StringRef &ErrMsg) {
850 (TmpReg && (State == IES_LPAREN || State == IES_MULTIPLY))) {
851 ErrMsg =
"Register can't be multiplied with register!";
855 IntelExprState CurrState = State;
863 State = IES_REGISTER;
865 IC.pushOperand(IC_REGISTER);
866 if (NegativeAdditiveTerm) {
867 ErrMsg =
"Scale can't be negative";
873 State = IES_REGISTER;
878 if (TmpScale.has_value()) {
880 return regsUseUpError(ErrMsg);
881 if (NegativeAdditiveTerm) {
882 ErrMsg =
"Scale can't be negative";
887 IC.pushOperand(IC_IMM);
889 IC.pushOperand(IC_REGISTER);
893 PrevState = CurrState;
896 bool onIdentifierExpr(
const MCExpr *SymRef, StringRef SymRefName,
897 const InlineAsmIdentifierInfo &IDInfo,
898 const AsmTypeInfo &
Type,
bool ParsingMSInlineAsm,
901 if (ParsingMSInlineAsm)
906 return onInteger(
CE->getValue(), ErrMsg);
919 if (setSymRef(SymRef, SymRefName, ErrMsg))
925 IC.pushOperand(IC_IMM);
926 if (ParsingMSInlineAsm)
933 bool onInteger(int64_t TmpInt, StringRef &ErrMsg) {
934 IntelExprState CurrState = State;
941 ErrMsg =
"division by zero in assembly expression";
948 ErrMsg =
"modulo by zero in assembly expression";
973 if (TmpScale.has_value()) {
974 TmpScale.value() *= TmpInt;
979 if (TmpReg && NegativeAdditiveTerm) {
980 ErrMsg =
"Scale can't be negative";
983 if (TmpReg &&
checkScale(TmpScale.value(), ErrMsg))
985 IC.pushOperand(IC_IMM, TmpInt);
988 PrevState = CurrState;
998 State = IES_MULTIPLY;
999 IC.pushOperator(IC_MULTIPLY);
1006 if (TmpReg && (!TmpScale.has_value())) {
1008 IC.pushOperand(IC_IMM);
1010 State = IES_MULTIPLY;
1011 IC.pushOperator(IC_MULTIPLY);
1024 IC.pushOperator(IC_DIVIDE);
1037 IC.pushOperator(IC_MOD);
1053 IC.pushOperator(IC_PLUS);
1055 CurType.Size = CurType.ElementSize;
1059 assert(!BracCount &&
"BracCount should be zero on parsing's start");
1063 NegativeAdditiveTerm =
false;
1064 NegativeAdditiveTermLoc = SMLoc();
1072 bool onRBrac(StringRef &ErrMsg) {
1073 IntelExprState CurrState = State;
1082 if (BracCount-- != 1) {
1083 ErrMsg =
"unexpected bracket encountered";
1091 if (!BaseReg && !TmpScale.has_value()) {
1094 }
else if (!IndexReg) {
1095 if (NegativeAdditiveTerm) {
1096 ErrMsg =
"Scale can't be negative";
1101 if (TmpScale.has_value() &&
checkScale(TmpScale.value(), ErrMsg)) {
1104 Scale = TmpScale.value_or(0);
1106 return regsUseUpError(ErrMsg);
1109 NegativeAdditiveTerm =
false;
1110 NegativeAdditiveTermLoc = SMLoc();
1115 PrevState = CurrState;
1118 void onLParen(SMLoc Loc) {
1119 IntelExprState CurrState = State;
1147 IC.pushOperator(IC_LPAREN);
1150 PrevState = CurrState;
1152 bool onRParen(StringRef &ErrMsg) {
1153 IntelExprState CurrState = State;
1163 if (ParenCount == 0) {
1164 ErrMsg =
"unmatched parenthesis";
1169 IC.pushOperator(IC_RPAREN);
1172 PrevState = CurrState;
1175 bool onOffset(
const MCExpr *Val, StringRef ID,
1176 const InlineAsmIdentifierInfo &IDInfo,
1177 bool ParsingMSInlineAsm, StringRef &ErrMsg) {
1181 ErrMsg =
"unexpected offset operator expression";
1186 if (setSymRef(Val, ID, ErrMsg))
1188 OffsetOperator =
true;
1192 IC.pushOperand(IC_IMM);
1193 if (ParsingMSInlineAsm) {
1203 bool onImagerel(
const MCExpr *Val, StringRef ID, StringRef &ErrMsg) {
1209 if (setSymRef(Val, ID, ErrMsg))
1212 IC.pushOperand(IC_IMM);
1215 ErrMsg =
"unexpected imagerel operator expression";
1219 void onCast(AsmTypeInfo Info) {
1231 void setTypeInfo(AsmTypeInfo
Type) { CurType =
Type; }
1235 bool MatchingInlineAsm =
false) {
1236 MCAsmParser &Parser = getParser();
1237 if (MatchingInlineAsm) {
1243 bool MatchRegisterByName(MCRegister &RegNo, StringRef
RegName, SMLoc StartLoc,
1245 bool ParseRegister(MCRegister &RegNo, SMLoc &StartLoc, SMLoc &EndLoc,
1246 bool RestoreOnFailure);
1248 std::unique_ptr<X86Operand> DefaultMemSIOperand(SMLoc Loc);
1249 std::unique_ptr<X86Operand> DefaultMemDIOperand(SMLoc Loc);
1250 bool IsSIReg(MCRegister
Reg);
1251 MCRegister GetSIDIForRegClass(
unsigned RegClassID,
bool IsSIReg);
1254 std::unique_ptr<llvm::MCParsedAsmOperand> &&Src,
1255 std::unique_ptr<llvm::MCParsedAsmOperand> &&Dst);
1261 bool ParseIntelOffsetOperator(
const MCExpr *&Val, StringRef &ID,
1262 InlineAsmIdentifierInfo &Info, SMLoc &
End);
1263 bool ParseIntelImagerelOperator(
const MCExpr *&Val, StringRef &ID,
1264 InlineAsmIdentifierInfo &Info, SMLoc &
End);
1265 bool ParseIntelDotOperator(IntelExprStateMachine &SM, SMLoc &
End);
1266 unsigned IdentifyIntelInlineAsmOperator(StringRef Name);
1267 unsigned ParseIntelInlineAsmOperator(
unsigned OpKind);
1268 unsigned IdentifyMasmOperator(StringRef Name);
1269 bool ParseMasmOperator(
unsigned OpKind, int64_t &Val);
1272 bool ParseIntelNamedOperator(StringRef Name, IntelExprStateMachine &SM,
1273 bool &ParseError, SMLoc &
End);
1274 bool ParseMasmNamedOperator(StringRef Name, IntelExprStateMachine &SM,
1275 bool &ParseError, SMLoc &
End);
1276 void RewriteIntelExpression(IntelExprStateMachine &SM, SMLoc Start,
1278 bool ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &
End,
1279 bool IsScale =
false);
1280 bool ParseIntelInlineAsmIdentifier(
const MCExpr *&Val, StringRef &Identifier,
1281 InlineAsmIdentifierInfo &Info,
1282 bool IsUnevaluatedOperand, SMLoc &
End,
1283 bool IsParsingOffsetOperator =
false);
1285 IntelExprStateMachine &SM);
1287 bool CheckDispOverflow(MCRegister BaseReg, MCRegister IndexReg,
1288 const MCExpr *Disp, SMLoc Loc);
1290 bool ParseMemOperand(MCRegister SegReg,
const MCExpr *Disp, SMLoc StartLoc,
1295 bool ParseIntelMemoryOperandSize(
unsigned &
Size, StringRef *SizeStr);
1296 bool CreateMemForMSInlineAsm(MCRegister SegReg,
const MCExpr *Disp,
1297 MCRegister BaseReg, MCRegister IndexReg,
1298 unsigned Scale,
bool NonAbsMem, SMLoc Start,
1299 SMLoc
End,
unsigned Size, StringRef Identifier,
1300 const InlineAsmIdentifierInfo &Info,
1303 bool parseDirectiveArch();
1304 bool parseDirectiveNops(SMLoc L);
1305 bool parseDirectiveEven(SMLoc L);
1306 bool ParseDirectiveCode(StringRef IDVal, SMLoc L);
1309 bool parseDirectiveFPOProc(SMLoc L);
1310 bool parseDirectiveFPOSetFrame(SMLoc L);
1311 bool parseDirectiveFPOPushReg(SMLoc L);
1312 bool parseDirectiveFPOStackAlloc(SMLoc L);
1313 bool parseDirectiveFPOStackAlign(SMLoc L);
1314 bool parseDirectiveFPOEndPrologue(SMLoc L);
1315 bool parseDirectiveFPOEndProc(SMLoc L);
1318 bool parseSEHRegisterNumber(
unsigned RegClassID, MCRegister &RegNo);
1319 bool parseDirectiveSEHPushReg(SMLoc);
1320 bool parseDirectiveSEHPush2Regs(SMLoc,
bool SwapRegs =
false);
1321 bool parseDirectiveSEHSetFrame(SMLoc);
1322 bool parseDirectiveSEHSaveReg(SMLoc);
1323 bool parseDirectiveSEHSaveXMM(SMLoc);
1324 bool parseDirectiveSEHPushFrame(SMLoc);
1326 bool ensureMasmEpilogContext(SMLoc Loc);
1327 bool ensureMasmPrologContext(SMLoc Loc);
1329 unsigned checkTargetMatchPredicate(MCInst &Inst)
override;
1335 void emitWarningForSpecialLVIInstruction(SMLoc Loc);
1336 void applyLVICFIMitigation(MCInst &Inst, MCStreamer &Out);
1337 void applyLVILoadHardeningMitigation(MCInst &Inst, MCStreamer &Out);
1343 bool matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
1346 bool MatchingInlineAsm)
override;
1349 MCStreamer &Out,
bool MatchingInlineAsm);
1351 bool ErrorMissingFeature(SMLoc IDLoc,
const FeatureBitset &MissingFeatures,
1352 bool MatchingInlineAsm);
1354 bool matchAndEmitATTInstruction(SMLoc IDLoc,
unsigned &Opcode, MCInst &Inst,
1356 uint64_t &ErrorInfo,
bool MatchingInlineAsm);
1358 bool matchAndEmitIntelInstruction(SMLoc IDLoc,
unsigned &Opcode, MCInst &Inst,
1361 bool MatchingInlineAsm);
1363 bool omitRegisterFromClobberLists(MCRegister
Reg)
override;
1370 bool ParseZ(std::unique_ptr<X86Operand> &Z, SMLoc StartLoc);
1372 bool is64BitMode()
const {
1374 return getSTI().hasFeature(X86::Is64Bit);
1376 bool is32BitMode()
const {
1378 return getSTI().hasFeature(X86::Is32Bit);
1380 bool is16BitMode()
const {
1382 return getSTI().hasFeature(X86::Is16Bit);
1384 void SwitchMode(
unsigned mode) {
1385 MCSubtargetInfo &STI = copySTI();
1386 FeatureBitset AllModes({X86::Is64Bit, X86::Is32Bit, X86::Is16Bit});
1388 FeatureBitset FB = ComputeAvailableFeatures(
1390 setAvailableFeatures(FB);
1395 unsigned getPointerWidth() {
1396 if (is16BitMode())
return 16;
1397 if (is32BitMode())
return 32;
1398 if (is64BitMode())
return 64;
1402 bool isParsingIntelSyntax() {
1403 return getParser().getAssemblerDialect();
1409#define GET_ASSEMBLER_HEADER
1410#include "X86GenAsmMatcher.inc"
1415 enum X86MatchResultTy {
1416 Match_Unsupported = FIRST_TARGET_MATCH_RESULT_TY,
1417#define GET_OPERAND_DIAGNOSTIC_TYPES
1418#include "X86GenAsmMatcher.inc"
1421 X86AsmParser(
const MCSubtargetInfo &sti, MCAsmParser &Parser,
1422 const MCInstrInfo &mii)
1423 : MCTargetAsmParser(sti, mii),
1425 InstInfo(nullptr), Code16GCC(
false) {
1430 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
1433 bool parseRegister(MCRegister &
Reg, SMLoc &StartLoc, SMLoc &EndLoc)
override;
1434 ParseStatus tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1435 SMLoc &EndLoc)
override;
1437 bool parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc)
override;
1439 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
1442 bool ParseDirective(AsmToken DirectiveID)
override;
1446#define GET_REGISTER_MATCHER
1447#define GET_SUBTARGET_FEATURE_NAME
1448#include "X86GenAsmMatcher.inc"
1459 !(BaseReg == X86::RIP || BaseReg == X86::EIP ||
1460 getX86MCRegisterClass(X86::GR16RegClassID).
contains(BaseReg) ||
1461 getX86MCRegisterClass(X86::GR32RegClassID).
contains(BaseReg) ||
1462 getX86MCRegisterClass(X86::GR64RegClassID).
contains(BaseReg))) {
1463 ErrMsg =
"invalid base+index expression";
1468 !(IndexReg == X86::EIZ || IndexReg == X86::RIZ ||
1469 getX86MCRegisterClass(X86::GR16RegClassID).
contains(IndexReg) ||
1470 getX86MCRegisterClass(X86::GR32RegClassID).
contains(IndexReg) ||
1471 getX86MCRegisterClass(X86::GR64RegClassID).
contains(IndexReg) ||
1472 getX86MCRegisterClass(X86::VR128XRegClassID).
contains(IndexReg) ||
1473 getX86MCRegisterClass(X86::VR256XRegClassID).
contains(IndexReg) ||
1474 getX86MCRegisterClass(X86::VR512RegClassID).
contains(IndexReg))) {
1475 ErrMsg =
"invalid base+index expression";
1479 if (((BaseReg == X86::RIP || BaseReg == X86::EIP) && IndexReg) ||
1480 IndexReg == X86::EIP || IndexReg == X86::RIP || IndexReg == X86::ESP ||
1481 IndexReg == X86::RSP) {
1482 ErrMsg =
"invalid base+index expression";
1488 if (getX86MCRegisterClass(X86::GR16RegClassID).
contains(BaseReg) &&
1489 (Is64BitMode || (BaseReg != X86::BX && BaseReg != X86::BP &&
1490 BaseReg != X86::SI && BaseReg != X86::DI))) {
1491 ErrMsg =
"invalid 16-bit base register";
1496 getX86MCRegisterClass(X86::GR16RegClassID).
contains(IndexReg)) {
1497 ErrMsg =
"16-bit memory operand may not include only index register";
1501 if (BaseReg && IndexReg) {
1502 if (getX86MCRegisterClass(X86::GR64RegClassID).
contains(BaseReg) &&
1503 (getX86MCRegisterClass(X86::GR16RegClassID).
contains(IndexReg) ||
1504 getX86MCRegisterClass(X86::GR32RegClassID).
contains(IndexReg) ||
1505 IndexReg == X86::EIZ)) {
1506 ErrMsg =
"base register is 64-bit, but index register is not";
1509 if (getX86MCRegisterClass(X86::GR32RegClassID).
contains(BaseReg) &&
1510 (getX86MCRegisterClass(X86::GR16RegClassID).
contains(IndexReg) ||
1511 getX86MCRegisterClass(X86::GR64RegClassID).
contains(IndexReg) ||
1512 IndexReg == X86::RIZ)) {
1513 ErrMsg =
"base register is 32-bit, but index register is not";
1516 if (getX86MCRegisterClass(X86::GR16RegClassID).
contains(BaseReg)) {
1517 if (getX86MCRegisterClass(X86::GR32RegClassID).
contains(IndexReg) ||
1518 getX86MCRegisterClass(X86::GR64RegClassID).
contains(IndexReg)) {
1519 ErrMsg =
"base register is 16-bit, but index register is not";
1522 if ((BaseReg != X86::BX && BaseReg != X86::BP) ||
1523 (IndexReg != X86::SI && IndexReg != X86::DI)) {
1524 ErrMsg =
"invalid 16-bit base/index register combination";
1531 if (!Is64BitMode && (BaseReg == X86::RIP || BaseReg == X86::EIP)) {
1532 ErrMsg =
"IP-relative addressing requires 64-bit mode";
1553 if (isParsingMSInlineAsm() && isParsingIntelSyntax() &&
1554 (RegNo == X86::EFLAGS || RegNo == X86::MXCSR))
1555 RegNo = MCRegister();
1557 if (!is64BitMode()) {
1561 if (RegNo == X86::RIZ || RegNo == X86::RIP ||
1562 getX86MCRegisterClass(X86::GR64RegClassID).
contains(RegNo) ||
1565 return Error(StartLoc,
1566 "register %" +
RegName +
" is only available in 64-bit mode",
1567 SMRange(StartLoc, EndLoc));
1572 UseApxExtendedReg =
true;
1576 if (!RegNo &&
RegName.starts_with(
"db")) {
1635 if (isParsingIntelSyntax())
1637 return Error(StartLoc,
"invalid register name", SMRange(StartLoc, EndLoc));
1642bool X86AsmParser::ParseRegister(MCRegister &RegNo, SMLoc &StartLoc,
1643 SMLoc &EndLoc,
bool RestoreOnFailure) {
1644 MCAsmParser &Parser = getParser();
1645 AsmLexer &Lexer = getLexer();
1646 RegNo = MCRegister();
1649 auto OnFailure = [RestoreOnFailure, &Lexer, &Tokens]() {
1650 if (RestoreOnFailure) {
1651 while (!Tokens.
empty()) {
1657 const AsmToken &PercentTok = Parser.
getTok();
1658 StartLoc = PercentTok.
getLoc();
1667 const AsmToken &Tok = Parser.
getTok();
1672 if (isParsingIntelSyntax())
return true;
1673 return Error(StartLoc,
"invalid register name",
1674 SMRange(StartLoc, EndLoc));
1677 if (MatchRegisterByName(RegNo, Tok.
getString(), StartLoc, EndLoc)) {
1683 if (RegNo == X86::ST0) {
1694 const AsmToken &IntTok = Parser.
getTok();
1697 return Error(IntTok.
getLoc(),
"expected stack index");
1700 case 0: RegNo = X86::ST0;
break;
1701 case 1: RegNo = X86::ST1;
break;
1702 case 2: RegNo = X86::ST2;
break;
1703 case 3: RegNo = X86::ST3;
break;
1704 case 4: RegNo = X86::ST4;
break;
1705 case 5: RegNo = X86::ST5;
break;
1706 case 6: RegNo = X86::ST6;
break;
1707 case 7: RegNo = X86::ST7;
break;
1710 return Error(IntTok.
getLoc(),
"invalid stack index");
1730 if (isParsingIntelSyntax())
return true;
1731 return Error(StartLoc,
"invalid register name",
1732 SMRange(StartLoc, EndLoc));
1739bool X86AsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1741 return ParseRegister(
Reg, StartLoc, EndLoc,
false);
1744ParseStatus X86AsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1746 bool Result = ParseRegister(
Reg, StartLoc, EndLoc,
true);
1747 bool PendingErrors = getParser().hasPendingError();
1748 getParser().clearPendingErrors();
1756std::unique_ptr<X86Operand> X86AsmParser::DefaultMemSIOperand(SMLoc Loc) {
1757 bool Parse32 = is32BitMode() || Code16GCC;
1758 MCRegister Basereg =
1759 is64BitMode() ? X86::RSI : (Parse32 ? X86::ESI : X86::SI);
1766std::unique_ptr<X86Operand> X86AsmParser::DefaultMemDIOperand(SMLoc Loc) {
1767 bool Parse32 = is32BitMode() || Code16GCC;
1768 MCRegister Basereg =
1769 is64BitMode() ? X86::RDI : (Parse32 ? X86::EDI : X86::DI);
1776bool X86AsmParser::IsSIReg(MCRegister
Reg) {
1790MCRegister X86AsmParser::GetSIDIForRegClass(
unsigned RegClassID,
bool IsSIReg) {
1791 switch (RegClassID) {
1793 case X86::GR64RegClassID:
1794 return IsSIReg ? X86::RSI : X86::RDI;
1795 case X86::GR32RegClassID:
1796 return IsSIReg ? X86::ESI : X86::EDI;
1797 case X86::GR16RegClassID:
1798 return IsSIReg ? X86::SI : X86::DI;
1802void X86AsmParser::AddDefaultSrcDestOperands(
1804 std::unique_ptr<llvm::MCParsedAsmOperand> &&Dst) {
1805 if (isParsingIntelSyntax()) {
1806 Operands.push_back(std::move(Dst));
1807 Operands.push_back(std::move(Src));
1810 Operands.push_back(std::move(Src));
1811 Operands.push_back(std::move(Dst));
1815bool X86AsmParser::VerifyAndAdjustOperands(
OperandVector &OrigOperands,
1818 if (OrigOperands.
size() > 1) {
1821 "Operand size mismatch");
1825 int RegClassID = -1;
1826 for (
unsigned int i = 0; i < FinalOperands.
size(); ++i) {
1827 X86Operand &OrigOp =
static_cast<X86Operand &
>(*OrigOperands[i + 1]);
1828 X86Operand &FinalOp =
static_cast<X86Operand &
>(*FinalOperands[i]);
1830 if (FinalOp.
isReg() &&
1835 if (FinalOp.
isMem()) {
1837 if (!OrigOp.
isMem())
1846 if (RegClassID != -1 &&
1847 !getX86MCRegisterClass(RegClassID).
contains(OrigReg)) {
1849 "mismatching source and destination index registers");
1852 if (getX86MCRegisterClass(X86::GR64RegClassID).
contains(OrigReg))
1853 RegClassID = X86::GR64RegClassID;
1854 else if (getX86MCRegisterClass(X86::GR32RegClassID).
contains(OrigReg))
1855 RegClassID = X86::GR32RegClassID;
1856 else if (getX86MCRegisterClass(X86::GR16RegClassID).
contains(OrigReg))
1857 RegClassID = X86::GR16RegClassID;
1863 bool IsSI = IsSIReg(FinalReg);
1864 FinalReg = GetSIDIForRegClass(RegClassID, IsSI);
1866 if (FinalReg != OrigReg) {
1867 std::string
RegName = IsSI ?
"ES:(R|E)SI" :
"ES:(R|E)DI";
1870 "memory operand is only for determining the size, " +
RegName +
1871 " will be used for the location"));
1882 for (
auto &WarningMsg : Warnings) {
1883 Warning(WarningMsg.first, WarningMsg.second);
1887 for (
unsigned int i = 0; i < FinalOperands.
size(); ++i)
1891 for (
auto &
Op : FinalOperands)
1898 if (isParsingIntelSyntax())
1899 return parseIntelOperand(
Operands, Name);
1904bool X86AsmParser::CreateMemForMSInlineAsm(
1905 MCRegister SegReg,
const MCExpr *Disp, MCRegister BaseReg,
1906 MCRegister IndexReg,
unsigned Scale,
bool NonAbsMem, SMLoc Start, SMLoc
End,
1907 unsigned Size, StringRef Identifier,
const InlineAsmIdentifierInfo &Info,
1922 unsigned FrontendSize = 0;
1923 void *Decl =
nullptr;
1924 bool IsGlobalLV =
false;
1927 FrontendSize =
Info.Var.Type * 8;
1928 Decl =
Info.Var.Decl;
1929 IsGlobalLV =
Info.Var.IsGlobalLV;
1934 if (BaseReg || IndexReg) {
1936 End,
Size, Identifier, Decl, 0,
1937 BaseReg && IndexReg));
1944 getPointerWidth(), SegReg, Disp, BaseReg, IndexReg, Scale, Start,
End,
1946 X86::RIP, Identifier, Decl, FrontendSize));
1953bool X86AsmParser::ParseIntelNamedOperator(StringRef Name,
1954 IntelExprStateMachine &SM,
1955 bool &ParseError, SMLoc &
End) {
1958 if (Name !=
Name.lower() && Name !=
Name.upper() &&
1959 !getParser().isParsingMasm())
1963 bool AlreadyConsumed =
false;
1964 if (
Name.equals_insensitive(
"not")) {
1966 }
else if (
Name.equals_insensitive(
"or")) {
1968 }
else if (
Name.equals_insensitive(
"shl")) {
1970 }
else if (
Name.equals_insensitive(
"shr")) {
1972 }
else if (
Name.equals_insensitive(
"xor")) {
1974 }
else if (
Name.equals_insensitive(
"and")) {
1976 }
else if (
Name.equals_insensitive(
"mod")) {
1978 }
else if (
Name.equals_insensitive(
"offset")) {
1979 const MCExpr *Val =
nullptr;
1981 InlineAsmIdentifierInfo
Info;
1986 ParseError = SM.onOffset(Val, ID, Info, isParsingMSInlineAsm(), ErrMsg);
1989 AlreadyConsumed =
true;
1990 }
else if (
Name.equals_insensitive(
"imagerel")) {
1993 InlineAsmIdentifierInfo
Info;
1994 ParseError = ParseIntelImagerelOperator(Val, ID, Info,
End);
2001 AlreadyConsumed =
true;
2005 if (!AlreadyConsumed)
2006 End = consumeToken();
2009bool X86AsmParser::ParseMasmNamedOperator(StringRef Name,
2010 IntelExprStateMachine &SM,
2011 bool &ParseError, SMLoc &
End) {
2012 if (
Name.equals_insensitive(
"eq")) {
2014 }
else if (
Name.equals_insensitive(
"ne")) {
2016 }
else if (
Name.equals_insensitive(
"lt")) {
2018 }
else if (
Name.equals_insensitive(
"le")) {
2020 }
else if (
Name.equals_insensitive(
"gt")) {
2022 }
else if (
Name.equals_insensitive(
"ge")) {
2027 End = consumeToken();
2034 IntelExprStateMachine &SM) {
2038 SM.setAppendAfterOperand();
2041bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &
End,
2043 MCAsmParser &Parser = getParser();
2048 if (
getContext().getObjectFileInfo()->isPositionIndependent())
2055 const AsmToken &Tok = Parser.
getTok();
2057 bool UpdateLocLex =
true;
2062 if ((
Done = SM.isValidEndState()))
2064 return Error(Tok.
getLoc(),
"unknown token in expression");
2066 return Error(getLexer().getErrLoc(), getLexer().getErr());
2070 UpdateLocLex =
false;
2071 if (ParseIntelDotOperator(SM,
End))
2076 if ((
Done = SM.isValidEndState()))
2078 return Error(Tok.
getLoc(),
"unknown token in expression");
2082 UpdateLocLex =
false;
2083 if (ParseIntelDotOperator(SM,
End))
2088 if ((
Done = SM.isValidEndState()))
2090 return Error(Tok.
getLoc(),
"unknown token in expression");
2096 SMLoc ValueLoc = Tok.
getLoc();
2101 UpdateLocLex =
false;
2102 if (!Val->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
2103 return Error(ValueLoc,
"expected absolute value");
2104 if (SM.onInteger(Res, ErrMsg))
2105 return Error(SM.getErrorLoc(ValueLoc), ErrMsg);
2112 SMLoc IdentLoc = Tok.
getLoc();
2114 UpdateLocLex =
false;
2116 size_t DotOffset =
Identifier.find_first_of(
'.');
2120 StringRef Dot =
Identifier.substr(DotOffset, 1);
2134 const AsmToken &NextTok = getLexer().peekTok();
2143 End = consumeToken();
2150 if (!ParseRegister(
Reg, IdentLoc,
End,
true)) {
2151 if (SM.onRegister(
Reg, IsScale, ErrMsg))
2152 return Error(SM.getErrorLoc(IdentLoc), ErrMsg);
2156 const std::pair<StringRef, StringRef> IDField =
2158 const StringRef
ID = IDField.first,
Field = IDField.second;
2160 if (!
Field.empty() &&
2161 !MatchRegisterByName(
Reg, ID, IdentLoc, IDEndLoc)) {
2162 if (SM.onRegister(
Reg, IsScale, ErrMsg))
2163 return Error(SM.getErrorLoc(IdentLoc), ErrMsg);
2168 return Error(FieldStartLoc,
"unknown offset");
2169 else if (SM.onPlus(ErrMsg))
2170 return Error(getTok().getLoc(), ErrMsg);
2171 else if (SM.onInteger(
Info.Offset, ErrMsg))
2172 return Error(SM.getErrorLoc(IdentLoc), ErrMsg);
2173 SM.setTypeInfo(
Info.Type);
2175 End = consumeToken();
2182 if (ParseIntelNamedOperator(Identifier, SM, ParseError,
End)) {
2188 ParseMasmNamedOperator(Identifier, SM, ParseError,
End)) {
2194 InlineAsmIdentifierInfo
Info;
2195 AsmFieldInfo FieldInfo;
2201 if (ParseIntelDotOperator(SM,
End))
2206 if (isParsingMSInlineAsm()) {
2208 if (
unsigned OpKind = IdentifyIntelInlineAsmOperator(Identifier)) {
2209 if (int64_t Val = ParseIntelInlineAsmOperator(OpKind)) {
2210 if (SM.onInteger(Val, ErrMsg))
2211 return Error(SM.getErrorLoc(IdentLoc), ErrMsg);
2220 return Error(IdentLoc,
"expected identifier");
2221 if (ParseIntelInlineAsmIdentifier(Val, Identifier, Info,
false,
End))
2223 else if (SM.onIdentifierExpr(Val, Identifier, Info, FieldInfo.
Type,
2225 return Error(SM.getErrorLoc(IdentLoc), ErrMsg);
2229 if (
unsigned OpKind = IdentifyMasmOperator(Identifier)) {
2231 if (ParseMasmOperator(OpKind, Val))
2233 if (SM.onInteger(Val, ErrMsg))
2234 return Error(SM.getErrorLoc(IdentLoc), ErrMsg);
2237 if (!getParser().lookUpType(Identifier, FieldInfo.
Type)) {
2243 getParser().parseIdentifier(Identifier);
2247 if (getParser().lookUpField(FieldInfo.
Type.
Name, Identifier,
2251 return Error(IdentLoc,
"Unable to lookup field reference!",
2252 SMRange(IdentLoc, IDEnd));
2257 if (SM.onInteger(FieldInfo.
Offset, ErrMsg))
2258 return Error(SM.getErrorLoc(IdentLoc), ErrMsg);
2262 if (getParser().parsePrimaryExpr(Val,
End, &FieldInfo.
Type)) {
2263 return Error(Tok.
getLoc(),
"Unexpected identifier!");
2264 }
else if (SM.onIdentifierExpr(Val, Identifier, Info, FieldInfo.
Type,
2266 return Error(SM.getErrorLoc(IdentLoc), ErrMsg);
2272 SMLoc Loc = getTok().getLoc();
2273 int64_t
IntVal = getTok().getIntVal();
2274 End = consumeToken();
2275 UpdateLocLex =
false;
2277 StringRef IDVal = getTok().getString();
2278 if (IDVal ==
"f" || IDVal ==
"b") {
2280 getContext().getDirectionalLocalSymbol(IntVal, IDVal ==
"b");
2285 return Error(Loc,
"invalid reference to undefined symbol");
2287 InlineAsmIdentifierInfo
Info;
2289 if (SM.onIdentifierExpr(Val, Identifier, Info,
Type,
2290 isParsingMSInlineAsm(), ErrMsg))
2291 return Error(SM.getErrorLoc(Loc), ErrMsg);
2292 End = consumeToken();
2294 if (SM.onInteger(IntVal, ErrMsg))
2295 return Error(SM.getErrorLoc(Loc), ErrMsg);
2298 if (SM.onInteger(IntVal, ErrMsg))
2299 return Error(SM.getErrorLoc(Loc), ErrMsg);
2304 if (SM.onPlus(ErrMsg))
2305 return Error(getTok().getLoc(), ErrMsg);
2308 if (SM.onMinus(getTok().getLoc(), ErrMsg))
2309 return Error(SM.getErrorLoc(getTok().getLoc()), ErrMsg);
2319 SM.onLShift();
break;
2321 SM.onRShift();
break;
2324 return Error(Tok.
getLoc(),
"unexpected bracket encountered");
2325 tryParseOperandIdx(PrevTK, SM);
2332 if (SM.onRBrac(ErrMsg)) {
2333 return Error(SM.getErrorLoc(Tok.
getLoc()), ErrMsg);
2337 if (SM.isRegisterScale()) {
2339 SMLoc ValueLoc = Tok.
getLoc();
2340 IntelExprStateMachine ScaleSM;
2341 ScaleSM.onLParen(ValueLoc);
2342 End = consumeToken();
2343 if (ParseIntelExpression(ScaleSM,
End,
true))
2345 UpdateLocLex =
false;
2346 int64_t Scale = ScaleSM.getImm();
2348 return Error(ValueLoc,
"Scale can't be negative");
2349 if (
checkScale(Scale, ErrMsg) || SM.onInteger(Scale, ErrMsg))
2350 return Error(SM.getErrorLoc(ValueLoc), ErrMsg);
2352 SM.onLParen(Tok.
getLoc());
2356 if (SM.onRParen(ErrMsg)) {
2357 return Error(SM.getErrorLoc(Tok.
getLoc()), ErrMsg);
2359 if (IsScale && !SM.hasUnmatchedParen()) {
2360 End = consumeToken();
2366 return Error(Tok.
getLoc(),
"unknown token in expression");
2368 if (!
Done && UpdateLocLex)
2369 End = consumeToken();
2373 if (SM.hasUnmatchedParen())
2374 return Error(SM.getLParenLoc(),
"unmatched parenthesis");
2375 if (IsScale && !SM.isAbsolute())
2376 return Error(SM.getLParenLoc(),
"expected absolute value");
2377 if (SM.onEnd(ErrMsg))
2378 return Error(getTok().getLoc(), ErrMsg);
2382void X86AsmParser::RewriteIntelExpression(IntelExprStateMachine &SM,
2383 SMLoc Start, SMLoc
End) {
2385 unsigned ExprLen =
End.getPointer() -
Start.getPointer();
2387 if (SM.getSym() && !SM.isOffsetOperator()) {
2388 StringRef SymName = SM.getSymName();
2389 if (
unsigned Len = SymName.
data() -
Start.getPointer())
2392 ExprLen =
End.getPointer() - (SymName.
data() + SymName.
size());
2395 if (!(SM.getBaseReg() || SM.getIndexReg() || SM.getImm())) {
2402 StringRef BaseRegStr;
2403 StringRef IndexRegStr;
2404 StringRef OffsetNameStr;
2405 if (SM.getBaseReg())
2407 if (SM.getIndexReg())
2409 if (SM.isOffsetOperator())
2410 OffsetNameStr = SM.getSymName();
2412 IntelExpr Expr(BaseRegStr, IndexRegStr, SM.getScale(), OffsetNameStr,
2413 SM.getImm(), SM.isMemExpr());
2414 InstInfo->
AsmRewrites->emplace_back(Loc, ExprLen, Expr);
2418bool X86AsmParser::ParseIntelInlineAsmIdentifier(
2419 const MCExpr *&Val, StringRef &Identifier, InlineAsmIdentifierInfo &Info,
2420 bool IsUnevaluatedOperand, SMLoc &
End,
bool IsParsingOffsetOperator) {
2421 MCAsmParser &Parser = getParser();
2422 assert(isParsingMSInlineAsm() &&
"Expected to be parsing inline assembly.");
2426 SemaCallback->LookupInlineAsmIdentifier(LineBuf, Info, IsUnevaluatedOperand);
2428 const AsmToken &Tok = Parser.
getTok();
2429 SMLoc Loc = Tok.
getLoc();
2437 }
while (
End.getPointer() < EndPtr);
2444 "frontend claimed part of a token?");
2449 StringRef InternalName =
2450 SemaCallback->LookupInlineAsmLabel(Identifier, getSourceManager(),
2452 assert(InternalName.
size() &&
"We should have an internal name here.");
2455 if (!IsParsingOffsetOperator)
2471 MCAsmParser &Parser = getParser();
2472 const AsmToken &Tok = Parser.
getTok();
2474 const SMLoc consumedToken = consumeToken();
2476 return Error(Tok.
getLoc(),
"Expected an identifier after {");
2479 .Case(
"rn", X86::STATIC_ROUNDING::TO_NEAREST_INT)
2480 .Case(
"rd", X86::STATIC_ROUNDING::TO_NEG_INF)
2481 .Case(
"ru", X86::STATIC_ROUNDING::TO_POS_INF)
2482 .Case(
"rz", X86::STATIC_ROUNDING::TO_ZERO)
2485 return Error(Tok.
getLoc(),
"Invalid rounding mode.");
2488 return Error(Tok.
getLoc(),
"Expected - at this point");
2492 return Error(Tok.
getLoc(),
"Expected } at this point");
2495 const MCExpr *RndModeOp =
2503 return Error(Tok.
getLoc(),
"Expected } at this point");
2508 return Error(Tok.
getLoc(),
"unknown token in expression");
2514 MCAsmParser &Parser = getParser();
2515 AsmToken Tok = Parser.
getTok();
2518 return Error(Tok.
getLoc(),
"Expected { at this point");
2522 return Error(Tok.
getLoc(),
"Expected dfv at this point");
2526 return Error(Tok.
getLoc(),
"Expected = at this point");
2538 unsigned CFlags = 0;
2539 for (
unsigned I = 0;
I < 4; ++
I) {
2548 return Error(Tok.
getLoc(),
"Invalid conditional flags");
2551 return Error(Tok.
getLoc(),
"Duplicated conditional flag");
2562 }
else if (
I == 3) {
2563 return Error(Tok.
getLoc(),
"Expected } at this point");
2565 return Error(Tok.
getLoc(),
"Expected } or , at this point");
2573bool X86AsmParser::ParseIntelDotOperator(IntelExprStateMachine &SM,
2575 const AsmToken &Tok = getTok();
2581 bool TrailingDot =
false;
2589 }
else if ((isParsingMSInlineAsm() || getParser().isParsingMasm()) &&
2592 const std::pair<StringRef, StringRef> BaseMember = DotDispStr.
split(
'.');
2593 const StringRef
Base = BaseMember.first,
Member = BaseMember.second;
2594 if (getParser().lookUpField(SM.getType(), DotDispStr, Info) &&
2595 getParser().lookUpField(SM.getSymName(), DotDispStr, Info) &&
2596 getParser().lookUpField(DotDispStr, Info) &&
2598 SemaCallback->LookupInlineAsmField(
Base, Member,
Info.Offset)))
2599 return Error(Tok.
getLoc(),
"Unable to lookup field reference!");
2601 return Error(Tok.
getLoc(),
"Unexpected token type!");
2606 const char *DotExprEndLoc = DotDispStr.
data() + DotDispStr.
size();
2611 SM.addImm(
Info.Offset);
2612 SM.setTypeInfo(
Info.Type);
2618bool X86AsmParser::ParseIntelOffsetOperator(
const MCExpr *&Val, StringRef &ID,
2619 InlineAsmIdentifierInfo &Info,
2622 SMLoc
Start = Lex().getLoc();
2623 ID = getTok().getString();
2624 if (!isParsingMSInlineAsm()) {
2627 getParser().parsePrimaryExpr(Val,
End,
nullptr))
2628 return Error(Start,
"unexpected token!");
2629 }
else if (ParseIntelInlineAsmIdentifier(Val, ID, Info,
false,
End,
true)) {
2630 return Error(Start,
"unable to lookup expression");
2632 return Error(Start,
"offset operator cannot yet handle constants");
2639bool X86AsmParser::ParseIntelImagerelOperator(
const MCExpr *&Val, StringRef &ID,
2640 InlineAsmIdentifierInfo &Info,
2643 SMLoc
Start = Lex().getLoc();
2644 ID = getTok().getString();
2645 if (!isParsingMSInlineAsm()) {
2648 getParser().parsePrimaryExpr(Val,
End,
nullptr))
2649 return Error(Start,
"unexpected token!");
2650 }
else if (ParseIntelInlineAsmIdentifier(Val, ID, Info,
false,
End,
true)) {
2651 return Error(Start,
"unable to lookup expression");
2653 return Error(Start,
"imagerel operator cannot yet handle constants");
2656 const MCExpr *ModifiedVal =
2659 return Error(Start,
"cannot apply 'imagerel' to this expression");
2666unsigned X86AsmParser::IdentifyIntelInlineAsmOperator(StringRef Name) {
2667 return StringSwitch<unsigned>(Name)
2668 .Cases({
"TYPE",
"type"}, IOK_TYPE)
2669 .Cases({
"SIZE",
"size"}, IOK_SIZE)
2670 .Cases({
"LENGTH",
"length"}, IOK_LENGTH)
2680unsigned X86AsmParser::ParseIntelInlineAsmOperator(
unsigned OpKind) {
2681 MCAsmParser &Parser = getParser();
2682 const AsmToken &Tok = Parser.
getTok();
2685 const MCExpr *Val =
nullptr;
2686 InlineAsmIdentifierInfo
Info;
2689 if (ParseIntelInlineAsmIdentifier(Val, Identifier, Info,
2694 Error(Start,
"unable to lookup expression");
2701 case IOK_LENGTH: CVal =
Info.Var.Length;
break;
2702 case IOK_SIZE: CVal =
Info.Var.Size;
break;
2703 case IOK_TYPE: CVal =
Info.Var.Type;
break;
2711unsigned X86AsmParser::IdentifyMasmOperator(StringRef Name) {
2712 return StringSwitch<unsigned>(
Name.lower())
2713 .Case(
"type", MOK_TYPE)
2714 .Cases({
"size",
"sizeof"}, MOK_SIZEOF)
2715 .Cases({
"length",
"lengthof"}, MOK_LENGTHOF)
2725bool X86AsmParser::ParseMasmOperator(
unsigned OpKind, int64_t &Val) {
2726 MCAsmParser &Parser = getParser();
2731 if (OpKind == MOK_SIZEOF || OpKind == MOK_TYPE) {
2734 const AsmToken &IDTok = InParens ? getLexer().peekTok() : Parser.
getTok();
2750 IntelExprStateMachine SM;
2752 if (ParseIntelExpression(SM,
End))
2762 Val = SM.getLength();
2765 Val = SM.getElementSize();
2770 return Error(OpLoc,
"expression has unknown type", SMRange(Start,
End));
2776bool X86AsmParser::ParseIntelMemoryOperandSize(
unsigned &
Size,
2777 StringRef *SizeStr) {
2778 Size = StringSwitch<unsigned>(getTok().getString())
2779 .Cases({
"BYTE",
"byte"}, 8)
2780 .Cases({
"WORD",
"word"}, 16)
2781 .Cases({
"DWORD",
"dword"}, 32)
2782 .Cases({
"FLOAT",
"float"}, 32)
2783 .Cases({
"LONG",
"long"}, 32)
2784 .Cases({
"FWORD",
"fword"}, 48)
2785 .Cases({
"DOUBLE",
"double"}, 64)
2786 .Cases({
"QWORD",
"qword"}, 64)
2787 .Cases({
"MMWORD",
"mmword"}, 64)
2788 .Cases({
"XWORD",
"xword"}, 80)
2789 .Cases({
"TBYTE",
"tbyte"}, 80)
2790 .Cases({
"XMMWORD",
"xmmword"}, 128)
2791 .Cases({
"YMMWORD",
"ymmword"}, 256)
2792 .Cases({
"ZMMWORD",
"zmmword"}, 512)
2796 *SizeStr = getTok().getString();
2797 const AsmToken &Tok = Lex();
2799 return Error(Tok.
getLoc(),
"Expected 'PTR' or 'ptr' token!");
2806 if (getX86MCRegisterClass(X86::GR8RegClassID).
contains(RegNo))
2808 if (getX86MCRegisterClass(X86::GR16RegClassID).
contains(RegNo))
2810 if (getX86MCRegisterClass(X86::GR32RegClassID).
contains(RegNo))
2812 if (getX86MCRegisterClass(X86::GR64RegClassID).
contains(RegNo))
2819 MCAsmParser &Parser = getParser();
2820 const AsmToken &Tok = Parser.
getTok();
2826 if (ParseIntelMemoryOperandSize(
Size, &SizeStr))
2828 bool PtrInOperand = bool(
Size);
2834 return ParseRoundingModeOp(Start,
Operands);
2839 if (RegNo == X86::RIP)
2840 return Error(Start,
"rip can only be used as a base register");
2845 return Error(Start,
"expected memory operand after 'ptr', "
2846 "found register operand instead");
2855 "cannot cast register '" +
2857 "'; its size is not easily defined.");
2861 std::to_string(
RegSize) +
"-bit register '" +
2863 "' cannot be used as a " + std::to_string(
Size) +
"-bit " +
2870 if (!getX86MCRegisterClass(X86::SEGMENT_REGRegClassID).
contains(RegNo))
2871 return Error(Start,
"invalid segment register");
2873 Start = Lex().getLoc();
2877 IntelExprStateMachine SM;
2878 if (ParseIntelExpression(SM,
End))
2881 if (isParsingMSInlineAsm())
2882 RewriteIntelExpression(SM, Start, Tok.
getLoc());
2884 int64_t
Imm = SM.getImm();
2885 const MCExpr *Disp = SM.getSym();
2894 if (!SM.isMemExpr() && !RegNo) {
2895 if (isParsingMSInlineAsm() && SM.isOffsetOperator()) {
2896 const InlineAsmIdentifierInfo &
Info = SM.getIdentifierInfo();
2901 SM.getSymName(),
Info.Var.Decl,
2902 Info.Var.IsGlobalLV));
2912 MCRegister
BaseReg = SM.getBaseReg();
2913 MCRegister IndexReg = SM.getIndexReg();
2914 if (IndexReg && BaseReg == X86::RIP)
2916 unsigned Scale = SM.getScale();
2918 Size = SM.getElementSize() << 3;
2920 if (Scale == 0 && BaseReg != X86::ESP && BaseReg != X86::RSP &&
2921 (IndexReg == X86::ESP || IndexReg == X86::RSP))
2927 !(getX86MCRegisterClass(X86::VR128XRegClassID).
contains(IndexReg) ||
2928 getX86MCRegisterClass(X86::VR256XRegClassID).
contains(IndexReg) ||
2929 getX86MCRegisterClass(X86::VR512RegClassID).
contains(IndexReg)) &&
2930 (getX86MCRegisterClass(X86::VR128XRegClassID).
contains(BaseReg) ||
2931 getX86MCRegisterClass(X86::VR256XRegClassID).
contains(BaseReg) ||
2932 getX86MCRegisterClass(X86::VR512RegClassID).
contains(BaseReg)))
2936 getX86MCRegisterClass(X86::GR16RegClassID).
contains(IndexReg))
2937 return Error(Start,
"16-bit addresses cannot have a scale");
2946 if ((BaseReg == X86::SI || BaseReg == X86::DI) &&
2947 (IndexReg == X86::BX || IndexReg == X86::BP))
2950 if ((BaseReg || IndexReg) &&
2953 return Error(Start, ErrMsg);
2954 bool IsUnconditionalBranch =
2955 Name.equals_insensitive(
"jmp") ||
Name.equals_insensitive(
"call");
2956 if (isParsingMSInlineAsm())
2957 return CreateMemForMSInlineAsm(RegNo, Disp, BaseReg, IndexReg, Scale,
2958 IsUnconditionalBranch && is64BitMode(),
2959 Start,
End,
Size, SM.getSymName(),
2964 MCRegister DefaultBaseReg;
2965 bool MaybeDirectBranchDest =
true;
2968 if (is64BitMode() &&
2969 ((PtrInOperand && !IndexReg) || SM.getElementSize() > 0)) {
2970 DefaultBaseReg = X86::RIP;
2972 if (IsUnconditionalBranch) {
2974 MaybeDirectBranchDest =
false;
2976 DefaultBaseReg = X86::RIP;
2977 }
else if (!BaseReg && !IndexReg && Disp &&
2979 if (is64BitMode()) {
2980 if (SM.getSize() == 8) {
2981 MaybeDirectBranchDest =
false;
2982 DefaultBaseReg = X86::RIP;
2985 if (SM.getSize() == 4 || SM.getSize() == 2)
2986 MaybeDirectBranchDest =
false;
2990 }
else if (IsUnconditionalBranch) {
2992 if (!PtrInOperand && SM.isOffsetOperator())
2994 Start,
"`OFFSET` operator cannot be used in an unconditional branch");
2995 if (PtrInOperand || SM.isBracketUsed())
2996 MaybeDirectBranchDest =
false;
2999 if (CheckDispOverflow(BaseReg, IndexReg, Disp, Start))
3002 if ((BaseReg || IndexReg || RegNo || DefaultBaseReg))
3004 getPointerWidth(), RegNo, Disp, BaseReg, IndexReg, Scale, Start,
End,
3005 Size, DefaultBaseReg, StringRef(),
nullptr,
3006 0,
false, MaybeDirectBranchDest));
3009 getPointerWidth(), Disp, Start,
End,
Size, StringRef(),
3011 MaybeDirectBranchDest));
3016 MCAsmParser &Parser = getParser();
3017 switch (getLexer().getKind()) {
3027 "expected immediate expression") ||
3028 getParser().parseExpression(Val,
End) ||
3036 return ParseRoundingModeOp(Start,
Operands);
3045 const MCExpr *Expr =
nullptr;
3057 if (
Reg == X86::EIZ ||
Reg == X86::RIZ)
3059 Loc,
"%eiz and %riz can only be used as index registers",
3060 SMRange(Loc, EndLoc));
3061 if (
Reg == X86::RIP)
3062 return Error(Loc,
"%rip can only be used as a base register",
3063 SMRange(Loc, EndLoc));
3069 if (!getX86MCRegisterClass(X86::SEGMENT_REGRegClassID).
contains(
Reg))
3070 return Error(Loc,
"invalid segment register");
3078 return ParseMemOperand(
Reg, Expr, Loc, EndLoc,
Operands);
3086 return StringSwitch<X86::CondCode>(
CC)
3108bool X86AsmParser::ParseZ(std::unique_ptr<X86Operand> &Z, SMLoc StartLoc) {
3109 MCAsmParser &Parser = getParser();
3114 (getLexer().getTok().getIdentifier() ==
"z")))
3119 return Error(getLexer().getLoc(),
"Expected } at this point");
3128 MCAsmParser &Parser = getParser();
3131 const SMLoc consumedToken = consumeToken();
3135 if (getLexer().getTok().getIntVal() != 1)
3136 return TokError(
"Expected 1to<NUM> at this point");
3137 StringRef
Prefix = getLexer().getTok().getString();
3140 return TokError(
"Expected 1to<NUM> at this point");
3143 StringRef BroadcastString = (
Prefix + getLexer().getTok().getIdentifier())
3146 return TokError(
"Expected 1to<NUM> at this point");
3147 const char *BroadcastPrimitive =
3148 StringSwitch<const char *>(BroadcastString)
3149 .Case(
"1to2",
"{1to2}")
3150 .Case(
"1to4",
"{1to4}")
3151 .Case(
"1to8",
"{1to8}")
3152 .Case(
"1to16",
"{1to16}")
3153 .Case(
"1to32",
"{1to32}")
3155 if (!BroadcastPrimitive)
3156 return TokError(
"Invalid memory broadcast primitive.");
3159 return TokError(
"Expected } at this point");
3170 std::unique_ptr<X86Operand>
Z;
3171 if (ParseZ(Z, consumedToken))
3177 SMLoc StartLoc =
Z ? consumeToken() : consumedToken;
3182 if (!parseRegister(RegNo, RegLoc, StartLoc) &&
3183 getX86MCRegisterClass(X86::VK1RegClassID).
contains(RegNo)) {
3184 if (RegNo == X86::K0)
3185 return Error(RegLoc,
"Register k0 can't be used as write mask");
3187 return Error(getLexer().getLoc(),
"Expected } at this point");
3193 return Error(getLexer().getLoc(),
3194 "Expected an op-mask register at this point");
3199 if (ParseZ(Z, consumeToken()) || !Z)
3200 return Error(getLexer().getLoc(),
3201 "Expected a {z} mark at this point");
3216bool X86AsmParser::CheckDispOverflow(MCRegister BaseReg, MCRegister IndexReg,
3217 const MCExpr *Disp, SMLoc Loc) {
3223 if (BaseReg || IndexReg) {
3225 auto Imm =
CE->getValue();
3227 getX86MCRegisterClass(X86::GR64RegClassID).contains(BaseReg) ||
3228 getX86MCRegisterClass(X86::GR64RegClassID).contains(IndexReg);
3229 bool Is16 = getX86MCRegisterClass(X86::GR16RegClassID).contains(BaseReg);
3232 return Error(Loc,
"displacement " + Twine(
Imm) +
3233 " is not within [-2147483648, 2147483647]");
3237 " shortened to 32-bit signed " +
3238 Twine(
static_cast<int32_t
>(
Imm)));
3242 " shortened to 16-bit signed " +
3243 Twine(
static_cast<int16_t
>(
Imm)));
3252bool X86AsmParser::ParseMemOperand(MCRegister SegReg,
const MCExpr *Disp,
3253 SMLoc StartLoc, SMLoc EndLoc,
3255 MCAsmParser &Parser = getParser();
3273 auto isAtMemOperand = [
this]() {
3278 auto TokCount = this->getLexer().peekTokens(Buf,
true);
3281 switch (Buf[0].getKind()) {
3288 if ((TokCount > 1) &&
3292 Buf[1].getIdentifier().
size() + 1);
3314 if (!isAtMemOperand()) {
3320 return Error(Loc,
"unexpected register in memory operand",
3321 SMRange(Loc, EndLoc));
3337 0, 0, 1, StartLoc, EndLoc));
3345 SMLoc BaseLoc = getLexer().getLoc();
3357 if (BaseReg == X86::EIZ || BaseReg == X86::RIZ)
3358 return Error(BaseLoc,
"eiz and riz can only be used as index registers",
3359 SMRange(BaseLoc, EndLoc));
3377 if (!
E->evaluateAsAbsolute(ScaleVal, getStreamer().getAssemblerPtr()))
3378 return Error(Loc,
"expected absolute expression");
3380 Warning(Loc,
"scale factor without index register is ignored");
3385 if (BaseReg == X86::RIP)
3387 "%rip as base register can not have an index register");
3388 if (IndexReg == X86::RIP)
3389 return Error(Loc,
"%rip is not allowed as an index register");
3400 return Error(Loc,
"expected scale expression");
3401 Scale = (unsigned)ScaleVal;
3403 if (getX86MCRegisterClass(X86::GR16RegClassID).
contains(BaseReg) &&
3405 return Error(Loc,
"scale factor in 16-bit address must be 1");
3407 return Error(Loc, ErrMsg);
3421 if (BaseReg == X86::DX && !IndexReg && Scale == 1 && !SegReg &&
3430 return Error(BaseLoc, ErrMsg);
3432 if (CheckDispOverflow(BaseReg, IndexReg, Disp, BaseLoc))
3435 if (SegReg || BaseReg || IndexReg)
3437 BaseReg, IndexReg, Scale, StartLoc,
3446bool X86AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
3447 MCAsmParser &Parser = getParser();
3454 if (parseRegister(RegNo, StartLoc, EndLoc))
3462bool X86AsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
3464 MCAsmParser &Parser = getParser();
3468 ForcedOpcodePrefix = OpcodePrefix_Default;
3469 ForcedDispEncoding = DispEncoding_Default;
3470 UseApxExtendedReg =
false;
3471 ForcedNoFlag =
false;
3484 if (Prefix ==
"rex")
3485 ForcedOpcodePrefix = OpcodePrefix_REX;
3486 else if (Prefix ==
"rex2")
3487 ForcedOpcodePrefix = OpcodePrefix_REX2;
3488 else if (Prefix ==
"vex")
3489 ForcedOpcodePrefix = OpcodePrefix_VEX;
3490 else if (Prefix ==
"vex2")
3491 ForcedOpcodePrefix = OpcodePrefix_VEX2;
3492 else if (Prefix ==
"vex3")
3493 ForcedOpcodePrefix = OpcodePrefix_VEX3;
3494 else if (Prefix ==
"evex")
3495 ForcedOpcodePrefix = OpcodePrefix_EVEX;
3496 else if (Prefix ==
"disp8")
3497 ForcedDispEncoding = DispEncoding_Disp8;
3498 else if (Prefix ==
"disp32")
3499 ForcedDispEncoding = DispEncoding_Disp32;
3500 else if (Prefix ==
"nf")
3501 ForcedNoFlag =
true;
3503 return Error(NameLoc,
"unknown prefix");
3519 if (isParsingMSInlineAsm()) {
3520 if (
Name.equals_insensitive(
"vex"))
3521 ForcedOpcodePrefix = OpcodePrefix_VEX;
3522 else if (
Name.equals_insensitive(
"vex2"))
3523 ForcedOpcodePrefix = OpcodePrefix_VEX2;
3524 else if (
Name.equals_insensitive(
"vex3"))
3525 ForcedOpcodePrefix = OpcodePrefix_VEX3;
3526 else if (
Name.equals_insensitive(
"evex"))
3527 ForcedOpcodePrefix = OpcodePrefix_EVEX;
3529 if (ForcedOpcodePrefix != OpcodePrefix_Default) {
3542 if (
Name.consume_back(
".d32")) {
3543 ForcedDispEncoding = DispEncoding_Disp32;
3544 }
else if (
Name.consume_back(
".d8")) {
3545 ForcedDispEncoding = DispEncoding_Disp8;
3548 StringRef PatchedName =
Name;
3551 if (isParsingIntelSyntax() &&
3552 (PatchedName ==
"jmp" || PatchedName ==
"jc" || PatchedName ==
"jnc" ||
3553 PatchedName ==
"jcxz" || PatchedName ==
"jecxz" ||
3558 : NextTok ==
"short") {
3567 NextTok.
size() + 1);
3573 PatchedName !=
"setzub" && PatchedName !=
"setzunb" &&
3574 PatchedName !=
"setb" && PatchedName !=
"setnb")
3575 PatchedName = PatchedName.
substr(0,
Name.size()-1);
3577 unsigned ComparisonPredicate = ~0
U;
3585 bool IsVCMP = PatchedName[0] ==
'v';
3586 unsigned CCIdx =
IsVCMP ? 4 : 3;
3587 unsigned suffixLength = PatchedName.
ends_with(
"bf16") ? 5 : 2;
3588 unsigned CC = StringSwitch<unsigned>(
3589 PatchedName.
slice(CCIdx, PatchedName.
size() - suffixLength))
3591 .Case(
"eq_oq", 0x00)
3593 .Case(
"lt_os", 0x01)
3595 .Case(
"le_os", 0x02)
3596 .Case(
"unord", 0x03)
3597 .Case(
"unord_q", 0x03)
3599 .Case(
"neq_uq", 0x04)
3601 .Case(
"nlt_us", 0x05)
3603 .Case(
"nle_us", 0x06)
3605 .Case(
"ord_q", 0x07)
3607 .Case(
"eq_uq", 0x08)
3609 .Case(
"nge_us", 0x09)
3611 .Case(
"ngt_us", 0x0A)
3612 .Case(
"false", 0x0B)
3613 .Case(
"false_oq", 0x0B)
3614 .Case(
"neq_oq", 0x0C)
3616 .Case(
"ge_os", 0x0D)
3618 .Case(
"gt_os", 0x0E)
3620 .Case(
"true_uq", 0x0F)
3621 .Case(
"eq_os", 0x10)
3622 .Case(
"lt_oq", 0x11)
3623 .Case(
"le_oq", 0x12)
3624 .Case(
"unord_s", 0x13)
3625 .Case(
"neq_us", 0x14)
3626 .Case(
"nlt_uq", 0x15)
3627 .Case(
"nle_uq", 0x16)
3628 .Case(
"ord_s", 0x17)
3629 .Case(
"eq_us", 0x18)
3630 .Case(
"nge_uq", 0x19)
3631 .Case(
"ngt_uq", 0x1A)
3632 .Case(
"false_os", 0x1B)
3633 .Case(
"neq_os", 0x1C)
3634 .Case(
"ge_oq", 0x1D)
3635 .Case(
"gt_oq", 0x1E)
3636 .Case(
"true_us", 0x1F)
3641 PatchedName =
IsVCMP ?
"vcmpss" :
"cmpss";
3643 PatchedName =
IsVCMP ?
"vcmpsd" :
"cmpsd";
3645 PatchedName =
IsVCMP ?
"vcmpps" :
"cmpps";
3647 PatchedName =
IsVCMP ?
"vcmppd" :
"cmppd";
3649 PatchedName =
"vcmpsh";
3651 PatchedName =
"vcmpph";
3653 PatchedName =
"vcmpbf16";
3657 ComparisonPredicate =
CC;
3663 (PatchedName.
back() ==
'b' || PatchedName.
back() ==
'w' ||
3664 PatchedName.
back() ==
'd' || PatchedName.
back() ==
'q')) {
3665 unsigned SuffixSize = PatchedName.
drop_back().
back() ==
'u' ? 2 : 1;
3666 unsigned CC = StringSwitch<unsigned>(
3667 PatchedName.
slice(5, PatchedName.
size() - SuffixSize))
3677 if (
CC != ~0U && (
CC != 0 || SuffixSize == 2)) {
3678 switch (PatchedName.
back()) {
3680 case 'b': PatchedName = SuffixSize == 2 ?
"vpcmpub" :
"vpcmpb";
break;
3681 case 'w': PatchedName = SuffixSize == 2 ?
"vpcmpuw" :
"vpcmpw";
break;
3682 case 'd': PatchedName = SuffixSize == 2 ?
"vpcmpud" :
"vpcmpd";
break;
3683 case 'q': PatchedName = SuffixSize == 2 ?
"vpcmpuq" :
"vpcmpq";
break;
3686 ComparisonPredicate =
CC;
3692 (PatchedName.
back() ==
'b' || PatchedName.
back() ==
'w' ||
3693 PatchedName.
back() ==
'd' || PatchedName.
back() ==
'q')) {
3694 unsigned SuffixSize = PatchedName.
drop_back().
back() ==
'u' ? 2 : 1;
3695 unsigned CC = StringSwitch<unsigned>(
3696 PatchedName.
slice(5, PatchedName.
size() - SuffixSize))
3707 switch (PatchedName.
back()) {
3709 case 'b': PatchedName = SuffixSize == 2 ?
"vpcomub" :
"vpcomb";
break;
3710 case 'w': PatchedName = SuffixSize == 2 ?
"vpcomuw" :
"vpcomw";
break;
3711 case 'd': PatchedName = SuffixSize == 2 ?
"vpcomud" :
"vpcomd";
break;
3712 case 'q': PatchedName = SuffixSize == 2 ?
"vpcomuq" :
"vpcomq";
break;
3715 ComparisonPredicate =
CC;
3727 StringSwitch<bool>(Name)
3728 .Cases({
"cs",
"ds",
"es",
"fs",
"gs",
"ss"},
true)
3729 .Cases({
"rex64",
"data32",
"data16",
"addr32",
"addr16"},
true)
3730 .Cases({
"xacquire",
"xrelease"},
true)
3731 .Cases({
"acquire",
"release"}, isParsingIntelSyntax())
3734 auto isLockRepeatNtPrefix = [](StringRef
N) {
3735 return StringSwitch<bool>(
N)
3736 .Cases({
"lock",
"rep",
"repe",
"repz",
"repne",
"repnz",
"notrack"},
3741 bool CurlyAsEndOfStatement =
false;
3744 while (isLockRepeatNtPrefix(
Name.lower())) {
3746 StringSwitch<unsigned>(Name)
3765 while (
Name.starts_with(
";") ||
Name.starts_with(
"\n") ||
3766 Name.starts_with(
"#") ||
Name.starts_with(
"\t") ||
3767 Name.starts_with(
"/")) {
3778 if (PatchedName ==
"data16" && is16BitMode()) {
3779 return Error(NameLoc,
"redundant data16 prefix");
3781 if (PatchedName ==
"data32") {
3783 return Error(NameLoc,
"redundant data32 prefix");
3785 return Error(NameLoc,
"'data32' is not supported in 64-bit mode");
3787 PatchedName =
"data16";
3794 if (
Next ==
"callw")
3796 if (
Next ==
"ljmpw")
3801 ForcedDataPrefix = X86::Is32Bit;
3809 if (ComparisonPredicate != ~0U && !isParsingIntelSyntax()) {
3816 if ((
Name.starts_with(
"ccmp") ||
Name.starts_with(
"ctest")) &&
3845 CurlyAsEndOfStatement =
3846 isParsingIntelSyntax() && isParsingMSInlineAsm() &&
3849 return TokError(
"unexpected token in argument list");
3853 if (ComparisonPredicate != ~0U && isParsingIntelSyntax()) {
3863 else if (CurlyAsEndOfStatement)
3866 getLexer().getTok().getLoc(), 0);
3873 if (IsFp &&
Operands.size() == 1) {
3874 const char *Repl = StringSwitch<const char *>(Name)
3875 .Case(
"fsub",
"fsubp")
3876 .Case(
"fdiv",
"fdivp")
3877 .Case(
"fsubr",
"fsubrp")
3878 .Case(
"fdivr",
"fdivrp");
3879 static_cast<X86Operand &
>(*
Operands[0]).setTokenValue(Repl);
3882 if ((Name ==
"mov" || Name ==
"movw" || Name ==
"movl") &&
3884 X86Operand &Op1 = (X86Operand &)*
Operands[1];
3885 X86Operand &Op2 = (X86Operand &)*
Operands[2];
3890 getX86MCRegisterClass(X86::SEGMENT_REGRegClassID)
3892 (getX86MCRegisterClass(X86::GR16RegClassID).
contains(Op1.
getReg()) ||
3893 getX86MCRegisterClass(X86::GR32RegClassID).
contains(Op1.
getReg()))) {
3895 if (Name !=
"mov" && Name[3] == (is16BitMode() ?
'l' :
'w')) {
3896 Name = is16BitMode() ?
"movw" :
"movl";
3909 if ((Name ==
"outb" || Name ==
"outsb" || Name ==
"outw" || Name ==
"outsw" ||
3910 Name ==
"outl" || Name ==
"outsl" || Name ==
"out" || Name ==
"outs") &&
3912 X86Operand &
Op = (X86Operand &)*
Operands.back();
3918 if ((Name ==
"inb" || Name ==
"insb" || Name ==
"inw" || Name ==
"insw" ||
3919 Name ==
"inl" || Name ==
"insl" || Name ==
"in" || Name ==
"ins") &&
3928 bool HadVerifyError =
false;
3931 if (
Name.starts_with(
"ins") &&
3933 (Name ==
"insb" || Name ==
"insw" || Name ==
"insl" || Name ==
"insd" ||
3936 AddDefaultSrcDestOperands(TmpOperands,
3938 DefaultMemDIOperand(NameLoc));
3939 HadVerifyError = VerifyAndAdjustOperands(
Operands, TmpOperands);
3943 if (
Name.starts_with(
"outs") &&
3945 (Name ==
"outsb" || Name ==
"outsw" || Name ==
"outsl" ||
3946 Name ==
"outsd" || Name ==
"outs")) {
3947 AddDefaultSrcDestOperands(TmpOperands, DefaultMemSIOperand(NameLoc),
3949 HadVerifyError = VerifyAndAdjustOperands(
Operands, TmpOperands);
3955 if (
Name.starts_with(
"lods") &&
3957 (Name ==
"lods" || Name ==
"lodsb" || Name ==
"lodsw" ||
3958 Name ==
"lodsl" || Name ==
"lodsd" || Name ==
"lodsq")) {
3959 TmpOperands.
push_back(DefaultMemSIOperand(NameLoc));
3960 HadVerifyError = VerifyAndAdjustOperands(
Operands, TmpOperands);
3966 if (
Name.starts_with(
"stos") &&
3968 (Name ==
"stos" || Name ==
"stosb" || Name ==
"stosw" ||
3969 Name ==
"stosl" || Name ==
"stosd" || Name ==
"stosq")) {
3970 TmpOperands.
push_back(DefaultMemDIOperand(NameLoc));
3971 HadVerifyError = VerifyAndAdjustOperands(
Operands, TmpOperands);
3977 if (
Name.starts_with(
"scas") &&
3979 (Name ==
"scas" || Name ==
"scasb" || Name ==
"scasw" ||
3980 Name ==
"scasl" || Name ==
"scasd" || Name ==
"scasq")) {
3981 TmpOperands.
push_back(DefaultMemDIOperand(NameLoc));
3982 HadVerifyError = VerifyAndAdjustOperands(
Operands, TmpOperands);
3986 if (
Name.starts_with(
"cmps") &&
3988 (Name ==
"cmps" || Name ==
"cmpsb" || Name ==
"cmpsw" ||
3989 Name ==
"cmpsl" || Name ==
"cmpsd" || Name ==
"cmpsq")) {
3990 AddDefaultSrcDestOperands(TmpOperands, DefaultMemDIOperand(NameLoc),
3991 DefaultMemSIOperand(NameLoc));
3992 HadVerifyError = VerifyAndAdjustOperands(
Operands, TmpOperands);
3996 if (((
Name.starts_with(
"movs") &&
3997 (Name ==
"movs" || Name ==
"movsb" || Name ==
"movsw" ||
3998 Name ==
"movsl" || Name ==
"movsd" || Name ==
"movsq")) ||
3999 (
Name.starts_with(
"smov") &&
4000 (Name ==
"smov" || Name ==
"smovb" || Name ==
"smovw" ||
4001 Name ==
"smovl" || Name ==
"smovd" || Name ==
"smovq"))) &&
4003 if (Name ==
"movsd" &&
Operands.size() == 1 && !isParsingIntelSyntax())
4005 AddDefaultSrcDestOperands(TmpOperands, DefaultMemSIOperand(NameLoc),
4006 DefaultMemDIOperand(NameLoc));
4007 HadVerifyError = VerifyAndAdjustOperands(
Operands, TmpOperands);
4011 if (HadVerifyError) {
4012 return HadVerifyError;
4016 if ((Name ==
"xlat" || Name ==
"xlatb") &&
Operands.size() == 2) {
4017 X86Operand &Op1 =
static_cast<X86Operand &
>(*
Operands[1]);
4020 "size, (R|E)BX will be used for the location");
4022 static_cast<X86Operand &
>(*
Operands[0]).setTokenValue(
"xlatb");
4035 if (
I ==
Table.end() ||
I->OldOpc != Opcode)
4041 if (X86::isBLENDVPD(Opcode) || X86::isBLENDVPS(Opcode) ||
4042 X86::isPBLENDVB(Opcode))
4048bool X86AsmParser::processInstruction(MCInst &Inst,
const OperandVector &
Ops) {
4052 if (ForcedOpcodePrefix != OpcodePrefix_VEX3 &&
4059 auto replaceWithCCMPCTEST = [&](
unsigned Opcode) ->
bool {
4060 if (ForcedOpcodePrefix == OpcodePrefix_EVEX) {
4071 default:
return false;
4076 if (ForcedDispEncoding == DispEncoding_Disp32) {
4077 Inst.
setOpcode(is16BitMode() ? X86::JMP_2 : X86::JMP_4);
4086 if (ForcedDispEncoding == DispEncoding_Disp32) {
4087 Inst.
setOpcode(is16BitMode() ? X86::JCC_2 : X86::JCC_4);
4103#define FROM_TO(FROM, TO) \
4105 return replaceWithCCMPCTEST(X86::TO);
4107 FROM_TO(CMP64mi32, CCMP64mi32)
4110 FROM_TO(CMP64ri32, CCMP64ri32)
4137 FROM_TO(TEST64mi32, CTEST64mi32)
4139 FROM_TO(TEST64ri32, CTEST64ri32)
4159bool X86AsmParser::validateInstruction(MCInst &Inst,
const OperandVector &
Ops) {
4160 using namespace X86;
4163 uint64_t TSFlags = MII.get(Opcode).TSFlags;
4164 if (isVFCMADDCPH(Opcode) || isVFCMADDCSH(Opcode) || isVFMADDCPH(Opcode) ||
4165 isVFMADDCSH(Opcode)) {
4169 return Warning(
Ops[0]->getStartLoc(),
"Destination register should be "
4170 "distinct from source registers");
4171 }
else if (isVFCMULCPH(Opcode) || isVFCMULCSH(Opcode) || isVFMULCPH(Opcode) ||
4172 isVFMULCSH(Opcode)) {
4182 return Warning(
Ops[0]->getStartLoc(),
"Destination register should be "
4183 "distinct from source registers");
4184 }
else if (isV4FMADDPS(Opcode) || isV4FMADDSS(Opcode) ||
4185 isV4FNMADDPS(Opcode) || isV4FNMADDSS(Opcode) ||
4186 isVP4DPWSSDS(Opcode) || isVP4DPWSSD(Opcode)) {
4190 unsigned Src2Enc =
MRI->getEncodingValue(Src2);
4191 if (Src2Enc % 4 != 0) {
4193 unsigned GroupStart = (Src2Enc / 4) * 4;
4194 unsigned GroupEnd = GroupStart + 3;
4196 "source register '" +
RegName +
"' implicitly denotes '" +
4197 RegName.take_front(3) + Twine(GroupStart) +
"' to '" +
4198 RegName.take_front(3) + Twine(GroupEnd) +
4201 }
else if (isVGATHERDPD(Opcode) || isVGATHERDPS(Opcode) ||
4202 isVGATHERQPD(Opcode) || isVGATHERQPS(Opcode) ||
4203 isVPGATHERDD(Opcode) || isVPGATHERDQ(Opcode) ||
4204 isVPGATHERQD(Opcode) || isVPGATHERQQ(Opcode)) {
4208 unsigned Index =
MRI->getEncodingValue(
4211 return Warning(
Ops[0]->getStartLoc(),
"index and destination registers "
4212 "should be distinct");
4216 unsigned Index =
MRI->getEncodingValue(
4218 if (Dest == Mask || Dest == Index || Mask == Index)
4219 return Warning(
Ops[0]->getStartLoc(),
"mask, index, and destination "
4220 "registers should be distinct");
4222 }
else if (isTCMMIMFP16PS(Opcode) || isTCMMRLFP16PS(Opcode) ||
4223 isTDPBF16PS(Opcode) || isTDPFP16PS(Opcode) || isTDPBSSD(Opcode) ||
4224 isTDPBSUD(Opcode) || isTDPBUSD(Opcode) || isTDPBUUD(Opcode)) {
4228 if (SrcDest == Src1 || SrcDest == Src2 || Src1 == Src2)
4229 return Error(
Ops[0]->getStartLoc(),
"all tmm registers must be distinct");
4243 for (
unsigned i = 0; i !=
NumOps; ++i) {
4248 if (
Reg == X86::AH ||
Reg == X86::BH ||
Reg == X86::CH ||
Reg == X86::DH)
4256 (Enc ==
X86II::EVEX || ForcedOpcodePrefix == OpcodePrefix_REX2 ||
4257 ForcedOpcodePrefix == OpcodePrefix_REX || UsesRex)) {
4259 return Error(
Ops[0]->getStartLoc(),
4260 "can't encode '" +
RegName.str() +
4261 "' in an instruction requiring EVEX/REX2/REX prefix");
4265 if ((Opcode == X86::PREFETCHIT0 || Opcode == X86::PREFETCHIT1)) {
4269 Ops[0]->getStartLoc(),
4270 Twine((Inst.
getOpcode() == X86::PREFETCHIT0 ?
"'prefetchit0'"
4271 :
"'prefetchit1'")) +
4272 " only supports RIP-relative address");
4277void X86AsmParser::emitWarningForSpecialLVIInstruction(SMLoc Loc) {
4278 Warning(Loc,
"Instruction may be vulnerable to LVI and "
4279 "requires manual mitigation");
4280 Note(SMLoc(),
"See https://software.intel.com/"
4281 "security-software-guidance/insights/"
4282 "deep-dive-load-value-injection#specialinstructions"
4283 " for more information");
4295void X86AsmParser::applyLVICFIMitigation(MCInst &Inst, MCStreamer &Out) {
4306 MCInst ShlInst, FenceInst;
4307 bool Parse32 = is32BitMode() || Code16GCC;
4308 MCRegister Basereg =
4309 is64BitMode() ? X86::RSP : (Parse32 ? X86::ESP : X86::SP);
4313 1, SMLoc{}, SMLoc{}, 0);
4315 ShlMemOp->addMemOperands(ShlInst, 5);
4318 Out.emitInstruction(ShlInst, getSTI());
4319 Out.emitInstruction(FenceInst, getSTI());
4328 emitWarningForSpecialLVIInstruction(Inst.
getLoc());
4340void X86AsmParser::applyLVILoadHardeningMitigation(MCInst &Inst,
4357 emitWarningForSpecialLVIInstruction(Inst.
getLoc());
4360 }
else if (Opcode == X86::REP_PREFIX || Opcode == X86::REPNE_PREFIX) {
4363 emitWarningForSpecialLVIInstruction(Inst.
getLoc());
4367 const MCInstrDesc &MCID = MII.get(Inst.
getOpcode());
4378 Out.emitInstruction(FenceInst, getSTI());
4384 if (CLOpts.experimental_lvi_inline_asm_hardening &&
4385 getSTI().
hasFeature(X86::FeatureLVIControlFlowIntegrity))
4386 applyLVICFIMitigation(Inst, Out);
4388 Out.emitInstruction(Inst, getSTI());
4390 if (CLOpts.experimental_lvi_inline_asm_hardening &&
4391 getSTI().
hasFeature(X86::FeatureLVILoadHardening))
4392 applyLVILoadHardeningMitigation(Inst, Out);
4396 unsigned Result = 0;
4398 if (Prefix.isPrefix()) {
4399 Result = Prefix.getPrefix();
4405bool X86AsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
4407 MCStreamer &Out,
uint64_t &ErrorInfo,
4408 bool MatchingInlineAsm) {
4410 assert((*
Operands[0]).isToken() &&
"Leading operand should always be a mnemonic!");
4413 MatchFPUWaitAlias(IDLoc,
static_cast<X86Operand &
>(*
Operands[0]),
Operands,
4414 Out, MatchingInlineAsm);
4421 if (ForcedOpcodePrefix == OpcodePrefix_REX)
4423 else if (ForcedOpcodePrefix == OpcodePrefix_REX2)
4425 else if (ForcedOpcodePrefix == OpcodePrefix_VEX)
4427 else if (ForcedOpcodePrefix == OpcodePrefix_VEX2)
4429 else if (ForcedOpcodePrefix == OpcodePrefix_VEX3)
4431 else if (ForcedOpcodePrefix == OpcodePrefix_EVEX)
4435 if (ForcedDispEncoding == DispEncoding_Disp8)
4437 else if (ForcedDispEncoding == DispEncoding_Disp32)
4443 return isParsingIntelSyntax()
4444 ? matchAndEmitIntelInstruction(IDLoc, Opcode, Inst,
Operands, Out,
4445 ErrorInfo, MatchingInlineAsm)
4446 : matchAndEmitATTInstruction(IDLoc, Opcode, Inst,
Operands,
Out,
4447 ErrorInfo, MatchingInlineAsm);
4450void X86AsmParser::MatchFPUWaitAlias(SMLoc IDLoc, X86Operand &
Op,
4452 bool MatchingInlineAsm) {
4456 const char *Repl = StringSwitch<const char *>(
Op.getToken())
4457 .Case(
"finit",
"fninit")
4458 .Case(
"fsave",
"fnsave")
4459 .Case(
"fstcw",
"fnstcw")
4460 .Case(
"fstcww",
"fnstcw")
4461 .Case(
"fstenv",
"fnstenv")
4462 .Case(
"fstsw",
"fnstsw")
4463 .Case(
"fstsww",
"fnstsw")
4464 .Case(
"fclex",
"fnclex")
4470 if (!MatchingInlineAsm)
4476bool X86AsmParser::ErrorMissingFeature(SMLoc IDLoc,
4477 const FeatureBitset &MissingFeatures,
4478 bool MatchingInlineAsm) {
4479 assert(MissingFeatures.
any() &&
"Unknown missing feature!");
4480 SmallString<126>
Msg;
4481 raw_svector_ostream OS(
Msg);
4482 OS <<
"instruction requires:";
4483 for (
unsigned Feature : MissingFeatures)
4485 return Error(IDLoc, OS.str(), SMRange(), MatchingInlineAsm);
4488unsigned X86AsmParser::checkTargetMatchPredicate(MCInst &Inst) {
4490 const MCInstrDesc &MCID = MII.get(
Opc);
4494 return Match_Unsupported;
4496 return Match_Unsupported;
4498 switch (ForcedOpcodePrefix) {
4499 case OpcodePrefix_Default:
4501 case OpcodePrefix_REX:
4502 case OpcodePrefix_REX2:
4504 return Match_Unsupported;
4506 case OpcodePrefix_VEX:
4507 case OpcodePrefix_VEX2:
4508 case OpcodePrefix_VEX3:
4510 return Match_Unsupported;
4512 case OpcodePrefix_EVEX:
4514 !X86::isCMP(
Opc) && !X86::isTEST(
Opc))
4515 return Match_Unsupported;
4517 return Match_Unsupported;
4522 (ForcedOpcodePrefix != OpcodePrefix_VEX &&
4523 ForcedOpcodePrefix != OpcodePrefix_VEX2 &&
4524 ForcedOpcodePrefix != OpcodePrefix_VEX3))
4525 return Match_Unsupported;
4527 return Match_Success;
4530bool X86AsmParser::matchAndEmitATTInstruction(
4532 MCStreamer &Out,
uint64_t &ErrorInfo,
bool MatchingInlineAsm) {
4533 X86Operand &
Op =
static_cast<X86Operand &
>(*
Operands[0]);
4537 if (ForcedDataPrefix == X86::Is32Bit)
4538 SwitchMode(X86::Is32Bit);
4540 FeatureBitset MissingFeatures;
4541 unsigned OriginalError = MatchInstruction(
Operands, Inst, ErrorInfo,
4542 MissingFeatures, MatchingInlineAsm,
4543 isParsingIntelSyntax());
4544 if (ForcedDataPrefix == X86::Is32Bit) {
4545 SwitchMode(X86::Is16Bit);
4546 ForcedDataPrefix = 0;
4548 switch (OriginalError) {
4551 if (!MatchingInlineAsm && validateInstruction(Inst,
Operands))
4556 if (!MatchingInlineAsm)
4557 while (processInstruction(Inst,
Operands))
4561 if (!MatchingInlineAsm)
4565 case Match_InvalidImmUnsignedi4: {
4566 SMLoc ErrorLoc = ((X86Operand &)*
Operands[ErrorInfo]).getStartLoc();
4567 if (ErrorLoc == SMLoc())
4569 return Error(ErrorLoc,
"immediate must be an integer in range [0, 15]",
4570 EmptyRange, MatchingInlineAsm);
4572 case Match_InvalidImmUnsignedi6: {
4573 SMLoc ErrorLoc = ((X86Operand &)*
Operands[ErrorInfo]).getStartLoc();
4574 if (ErrorLoc == SMLoc())
4576 return Error(ErrorLoc,
"immediate must be an integer in range [0, 63]",
4577 EmptyRange, MatchingInlineAsm);
4579 case Match_MissingFeature:
4580 return ErrorMissingFeature(IDLoc, MissingFeatures, MatchingInlineAsm);
4581 case Match_InvalidOperand:
4582 case Match_MnemonicFail:
4583 case Match_Unsupported:
4586 if (
Op.getToken().empty()) {
4587 Error(IDLoc,
"instruction must have size higher than 0", EmptyRange,
4598 StringRef
Base =
Op.getToken();
4599 SmallString<16> Tmp;
4602 Op.setTokenValue(Tmp);
4610 const char *Suffixes =
Base[0] !=
'f' ?
"bwlq" :
"slt\0";
4612 const char *MemSize =
Base[0] !=
'f' ?
"\x08\x10\x20\x40" :
"\x20\x40\x50\0";
4616 FeatureBitset ErrorInfoMissingFeatures;
4624 bool HasVectorReg =
false;
4625 X86Operand *MemOp =
nullptr;
4627 X86Operand *X86Op =
static_cast<X86Operand *
>(
Op.get());
4629 HasVectorReg =
true;
4630 else if (X86Op->
isMem()) {
4632 assert(MemOp->Mem.Size == 0 &&
"Memory size always 0 under ATT syntax");
4639 for (
unsigned I = 0,
E = std::size(Match);
I !=
E; ++
I) {
4640 Tmp.
back() = Suffixes[
I];
4641 if (MemOp && HasVectorReg)
4642 MemOp->Mem.Size = MemSize[
I];
4643 Match[
I] = Match_MnemonicFail;
4644 if (MemOp || !HasVectorReg) {
4646 MatchInstruction(
Operands, Inst, ErrorInfoIgnore, MissingFeatures,
4647 MatchingInlineAsm, isParsingIntelSyntax());
4649 if (Match[
I] == Match_MissingFeature)
4650 ErrorInfoMissingFeatures = MissingFeatures;
4660 unsigned NumSuccessfulMatches =
llvm::count(Match, Match_Success);
4661 if (NumSuccessfulMatches == 1) {
4662 if (!MatchingInlineAsm && validateInstruction(Inst,
Operands))
4667 if (!MatchingInlineAsm)
4668 while (processInstruction(Inst,
Operands))
4672 if (!MatchingInlineAsm)
4682 if (NumSuccessfulMatches > 1) {
4684 unsigned NumMatches = 0;
4685 for (
unsigned I = 0,
E = std::size(Match);
I !=
E; ++
I)
4686 if (Match[
I] == Match_Success)
4687 MatchChars[NumMatches++] = Suffixes[
I];
4689 SmallString<126>
Msg;
4690 raw_svector_ostream OS(
Msg);
4691 OS <<
"ambiguous instructions require an explicit suffix (could be ";
4692 for (
unsigned i = 0; i != NumMatches; ++i) {
4695 if (i + 1 == NumMatches)
4697 OS <<
"'" <<
Base << MatchChars[i] <<
"'";
4700 Error(IDLoc, OS.str(), EmptyRange, MatchingInlineAsm);
4708 if (
llvm::count(Match, Match_MnemonicFail) == 4) {
4709 if (OriginalError == Match_MnemonicFail)
4710 return Error(IDLoc,
"invalid instruction mnemonic '" +
Base +
"'",
4711 Op.getLocRange(), MatchingInlineAsm);
4713 if (OriginalError == Match_Unsupported)
4714 return Error(IDLoc,
"unsupported instruction", EmptyRange,
4717 assert(OriginalError == Match_InvalidOperand &&
"Unexpected error");
4719 if (ErrorInfo != ~0ULL) {
4721 return Error(IDLoc,
"too few operands for instruction", EmptyRange,
4724 X86Operand &Operand = (X86Operand &)*
Operands[ErrorInfo];
4728 OperandRange, MatchingInlineAsm);
4732 return Error(IDLoc,
"invalid operand for instruction", EmptyRange,
4738 return Error(IDLoc,
"unsupported instruction", EmptyRange,
4744 if (
llvm::count(Match, Match_MissingFeature) == 1) {
4745 ErrorInfo = Match_MissingFeature;
4746 return ErrorMissingFeature(IDLoc, ErrorInfoMissingFeatures,
4752 if (
llvm::count(Match, Match_InvalidOperand) == 1) {
4753 return Error(IDLoc,
"invalid operand for instruction", EmptyRange,
4758 Error(IDLoc,
"unknown use of instruction mnemonic without a size suffix",
4759 EmptyRange, MatchingInlineAsm);
4763bool X86AsmParser::matchAndEmitIntelInstruction(
4765 MCStreamer &Out,
uint64_t &ErrorInfo,
bool MatchingInlineAsm) {
4766 X86Operand &
Op =
static_cast<X86Operand &
>(*
Operands[0]);
4771 const bool ForcedData32 = ForcedDataPrefix == X86::Is32Bit;
4772 auto RestoreMode = [&] {
4774 SwitchMode(X86::Is16Bit);
4775 ForcedDataPrefix = 0;
4779 SwitchMode(X86::Is32Bit);
4781 X86Operand *UnsizedMemOp =
nullptr;
4783 X86Operand *X86Op =
static_cast<X86Operand *
>(
Op.get());
4785 UnsizedMemOp = X86Op;
4796 static const char *
const PtrSizedInstrs[] = {
"call",
"jmp",
"push",
"pop"};
4797 for (
const char *Instr : PtrSizedInstrs) {
4798 if (Mnemonic == Instr) {
4799 UnsizedMemOp->
Mem.
Size = getPointerWidth();
4805 SmallVector<unsigned, 8> Match;
4806 FeatureBitset ErrorInfoMissingFeatures;
4807 FeatureBitset MissingFeatures;
4812 if (Mnemonic ==
"push" &&
Operands.size() == 2) {
4813 auto *X86Op =
static_cast<X86Operand *
>(
Operands[1].get());
4814 if (X86Op->
isImm()) {
4817 unsigned Size = getPointerWidth();
4820 SmallString<16> Tmp;
4822 Tmp += (is64BitMode())
4824 : (is32BitMode()) ?
"l" : (is16BitMode()) ?
"w" :
" ";
4825 Op.setTokenValue(Tmp);
4828 MissingFeatures, MatchingInlineAsm,
4839 static const unsigned MopSizes[] = {8, 16, 32, 64, 80, 128, 256, 512};
4840 for (
unsigned Size : MopSizes) {
4844 unsigned M = MatchInstruction(
Operands, Inst, ErrorInfoIgnore,
4845 MissingFeatures, MatchingInlineAsm,
4846 isParsingIntelSyntax());
4851 if (Match.
back() == Match_MissingFeature)
4852 ErrorInfoMissingFeatures = MissingFeatures;
4862 if (Match.
empty()) {
4864 Operands, Inst, ErrorInfo, MissingFeatures, MatchingInlineAsm,
4865 isParsingIntelSyntax()));
4867 if (Match.
back() == Match_MissingFeature)
4868 ErrorInfoMissingFeatures = MissingFeatures;
4876 if (Match.
back() == Match_MnemonicFail) {
4878 return Error(IDLoc,
"invalid instruction mnemonic '" + Mnemonic +
"'",
4879 Op.getLocRange(), MatchingInlineAsm);
4882 unsigned NumSuccessfulMatches =
llvm::count(Match, Match_Success);
4886 if (UnsizedMemOp && NumSuccessfulMatches > 1 &&
4889 unsigned M = MatchInstruction(
4890 Operands, Inst, ErrorInfo, MissingFeatures, MatchingInlineAsm,
4891 isParsingIntelSyntax());
4892 if (M == Match_Success)
4893 NumSuccessfulMatches = 1;
4908 if (NumSuccessfulMatches == 1) {
4909 if (!MatchingInlineAsm && validateInstruction(Inst,
Operands))
4914 if (!MatchingInlineAsm)
4915 while (processInstruction(Inst,
Operands))
4918 if (!MatchingInlineAsm)
4922 }
else if (NumSuccessfulMatches > 1) {
4924 "multiple matches only possible with unsized memory operands");
4926 "ambiguous operand size for instruction '" + Mnemonic +
"\'",
4932 return Error(IDLoc,
"unsupported instruction", EmptyRange,
4938 if (
llvm::count(Match, Match_MissingFeature) == 1) {
4939 ErrorInfo = Match_MissingFeature;
4940 return ErrorMissingFeature(IDLoc, ErrorInfoMissingFeatures,
4946 if (
llvm::count(Match, Match_InvalidOperand) == 1) {
4947 return Error(IDLoc,
"invalid operand for instruction", EmptyRange,
4951 if (
llvm::count(Match, Match_InvalidImmUnsignedi4) == 1) {
4952 SMLoc ErrorLoc = ((X86Operand &)*
Operands[ErrorInfo]).getStartLoc();
4953 if (ErrorLoc == SMLoc())
4955 return Error(ErrorLoc,
"immediate must be an integer in range [0, 15]",
4956 EmptyRange, MatchingInlineAsm);
4959 if (
llvm::count(Match, Match_InvalidImmUnsignedi6) == 1) {
4960 SMLoc ErrorLoc = ((X86Operand &)*
Operands[ErrorInfo]).getStartLoc();
4961 if (ErrorLoc == SMLoc())
4963 return Error(ErrorLoc,
"immediate must be an integer in range [0, 63]",
4964 EmptyRange, MatchingInlineAsm);
4968 return Error(IDLoc,
"unknown instruction mnemonic", EmptyRange,
4972bool X86AsmParser::omitRegisterFromClobberLists(MCRegister
Reg) {
4973 return getX86MCRegisterClass(X86::SEGMENT_REGRegClassID).contains(
Reg);
4976bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
4977 MCAsmParser &Parser = getParser();
4980 return parseDirectiveArch();
4982 return ParseDirectiveCode(IDVal, DirectiveID.
getLoc());
4988 return Error(DirectiveID.
getLoc(),
"'.att_syntax noprefix' is not "
4989 "supported: registers must have a "
4990 "'%' prefix in .att_syntax");
4992 getParser().setAssemblerDialect(0);
4995 getParser().setAssemblerDialect(1);
5000 return Error(DirectiveID.
getLoc(),
"'.intel_syntax prefix' is not "
5001 "supported: registers must not have "
5002 "a '%' prefix in .intel_syntax");
5005 }
else if (IDVal ==
".nops")
5006 return parseDirectiveNops(DirectiveID.
getLoc());
5007 else if (IDVal ==
".even")
5008 return parseDirectiveEven(DirectiveID.
getLoc());
5009 else if (IDVal ==
".cv_fpo_proc")
5010 return parseDirectiveFPOProc(DirectiveID.
getLoc());
5011 else if (IDVal ==
".cv_fpo_setframe")
5012 return parseDirectiveFPOSetFrame(DirectiveID.
getLoc());
5013 else if (IDVal ==
".cv_fpo_pushreg")
5014 return parseDirectiveFPOPushReg(DirectiveID.
getLoc());
5015 else if (IDVal ==
".cv_fpo_stackalloc")
5016 return parseDirectiveFPOStackAlloc(DirectiveID.
getLoc());
5017 else if (IDVal ==
".cv_fpo_stackalign")
5018 return parseDirectiveFPOStackAlign(DirectiveID.
getLoc());
5019 else if (IDVal ==
".cv_fpo_endprologue")
5020 return parseDirectiveFPOEndPrologue(DirectiveID.
getLoc());
5021 else if (IDVal ==
".cv_fpo_endproc")
5022 return parseDirectiveFPOEndProc(DirectiveID.
getLoc());
5023 else if (IDVal ==
".seh_pushreg")
5024 return parseDirectiveSEHPushReg(DirectiveID.
getLoc());
5025 else if (IDVal ==
".seh_push2regs")
5026 return parseDirectiveSEHPush2Regs(DirectiveID.
getLoc());
5027 else if (IDVal ==
".seh_setframe")
5028 return parseDirectiveSEHSetFrame(DirectiveID.
getLoc());
5029 else if (IDVal ==
".seh_savereg")
5030 return parseDirectiveSEHSaveReg(DirectiveID.
getLoc());
5031 else if (IDVal ==
".seh_savexmm")
5032 return parseDirectiveSEHSaveXMM(DirectiveID.
getLoc());
5033 else if (IDVal ==
".seh_pushframe")
5034 return parseDirectiveSEHPushFrame(DirectiveID.
getLoc());
5038 return ensureMasmPrologContext(DirectiveID.
getLoc()) ||
5039 parseDirectiveSEHPushReg(DirectiveID.
getLoc());
5041 return ensureMasmPrologContext(DirectiveID.
getLoc()) ||
5042 parseDirectiveSEHPush2Regs(DirectiveID.
getLoc());
5044 return ensureMasmPrologContext(DirectiveID.
getLoc()) ||
5045 parseDirectiveSEHSetFrame(DirectiveID.
getLoc());
5047 return ensureMasmPrologContext(DirectiveID.
getLoc()) ||
5048 parseDirectiveSEHSaveReg(DirectiveID.
getLoc());
5050 return ensureMasmPrologContext(DirectiveID.
getLoc()) ||
5051 parseDirectiveSEHSaveXMM(DirectiveID.
getLoc());
5053 return ensureMasmPrologContext(DirectiveID.
getLoc()) ||
5054 parseDirectiveSEHPushFrame(DirectiveID.
getLoc());
5058 return ensureMasmEpilogContext(DirectiveID.
getLoc()) ||
5059 parseDirectiveSEHPushReg(DirectiveID.
getLoc());
5063 return ensureMasmEpilogContext(DirectiveID.
getLoc()) ||
5064 parseDirectiveSEHPush2Regs(DirectiveID.
getLoc(),
5067 return ensureMasmEpilogContext(DirectiveID.
getLoc()) ||
5068 parseDirectiveSEHSetFrame(DirectiveID.
getLoc());
5070 return ensureMasmEpilogContext(DirectiveID.
getLoc()) ||
5071 parseDirectiveSEHSaveReg(DirectiveID.
getLoc());
5073 return ensureMasmEpilogContext(DirectiveID.
getLoc()) ||
5074 parseDirectiveSEHSaveXMM(DirectiveID.
getLoc());
5081bool X86AsmParser::parseDirectiveArch() {
5083 getParser().parseStringToEndOfStatement();
5089bool X86AsmParser::parseDirectiveNops(SMLoc L) {
5090 int64_t NumBytes = 0, Control = 0;
5091 SMLoc NumBytesLoc, ControlLoc;
5092 const MCSubtargetInfo& STI = getSTI();
5093 NumBytesLoc = getTok().getLoc();
5094 if (getParser().checkForValidSection() ||
5095 getParser().parseAbsoluteExpression(NumBytes))
5099 ControlLoc = getTok().getLoc();
5100 if (getParser().parseAbsoluteExpression(Control))
5103 if (getParser().parseEOL())
5106 if (NumBytes <= 0) {
5107 Error(NumBytesLoc,
"'.nops' directive with non-positive size");
5112 Error(ControlLoc,
"'.nops' directive with negative NOP size");
5117 getParser().getStreamer().emitNops(NumBytes, Control, L, STI);
5124bool X86AsmParser::parseDirectiveEven(SMLoc L) {
5128 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
5130 getStreamer().initSections(getSTI());
5131 Section = getStreamer().getCurrentSectionOnly();
5133 if (
getContext().getAsmInfo().useCodeAlign(*Section))
5134 getStreamer().emitCodeAlignment(
Align(2), getSTI(), 0);
5136 getStreamer().emitValueToAlignment(
Align(2), 0, 1, 0);
5142bool X86AsmParser::ParseDirectiveCode(StringRef IDVal, SMLoc L) {
5143 MCAsmParser &Parser = getParser();
5145 if (IDVal ==
".code16") {
5147 if (!is16BitMode()) {
5148 SwitchMode(X86::Is16Bit);
5149 getTargetStreamer().emitCode16();
5151 }
else if (IDVal ==
".code16gcc") {
5155 if (!is16BitMode()) {
5156 SwitchMode(X86::Is16Bit);
5157 getTargetStreamer().emitCode16();
5159 }
else if (IDVal ==
".code32") {
5161 if (!is32BitMode()) {
5162 SwitchMode(X86::Is32Bit);
5163 getTargetStreamer().emitCode32();
5165 }
else if (IDVal ==
".code64") {
5167 if (!is64BitMode()) {
5168 SwitchMode(X86::Is64Bit);
5169 getTargetStreamer().emitCode64();
5172 Error(L,
"unknown directive " + IDVal);
5180bool X86AsmParser::parseDirectiveFPOProc(SMLoc L) {
5181 MCAsmParser &Parser = getParser();
5185 return Parser.
TokError(
"expected symbol name");
5186 if (Parser.
parseIntToken(ParamsSize,
"expected parameter byte count"))
5189 return Parser.
TokError(
"parameters size out of range");
5193 return getTargetStreamer().emitFPOProc(ProcSym, ParamsSize, L);
5197bool X86AsmParser::parseDirectiveFPOSetFrame(SMLoc L) {
5200 if (parseRegister(
Reg, DummyLoc, DummyLoc) || parseEOL())
5202 return getTargetStreamer().emitFPOSetFrame(
Reg, L);
5206bool X86AsmParser::parseDirectiveFPOPushReg(SMLoc L) {
5209 if (parseRegister(
Reg, DummyLoc, DummyLoc) || parseEOL())
5211 return getTargetStreamer().emitFPOPushReg(
Reg, L);
5215bool X86AsmParser::parseDirectiveFPOStackAlloc(SMLoc L) {
5216 MCAsmParser &Parser = getParser();
5220 return getTargetStreamer().emitFPOStackAlloc(
Offset, L);
5224bool X86AsmParser::parseDirectiveFPOStackAlign(SMLoc L) {
5225 MCAsmParser &Parser = getParser();
5229 return getTargetStreamer().emitFPOStackAlign(
Offset, L);
5233bool X86AsmParser::parseDirectiveFPOEndPrologue(SMLoc L) {
5234 MCAsmParser &Parser = getParser();
5237 return getTargetStreamer().emitFPOEndPrologue(L);
5241bool X86AsmParser::parseDirectiveFPOEndProc(SMLoc L) {
5242 MCAsmParser &Parser = getParser();
5245 return getTargetStreamer().emitFPOEndProc(L);
5248bool X86AsmParser::parseSEHRegisterNumber(
unsigned RegClassID,
5249 MCRegister &RegNo) {
5250 SMLoc startLoc = getLexer().getLoc();
5256 if (parseRegister(RegNo, startLoc, endLoc))
5259 if (!getX86MCRegisterClass(RegClassID).
contains(RegNo)) {
5260 return Error(startLoc,
5261 "register is not supported for use with this directive");
5267 if (getParser().parseAbsoluteExpression(EncodedReg))
5272 RegNo = MCRegister();
5273 for (
MCPhysReg Reg : getX86MCRegisterClass(RegClassID)) {
5274 if (
MRI->getEncodingValue(
Reg) == EncodedReg) {
5280 return Error(startLoc,
5281 "incorrect register number for use with this directive");
5288bool X86AsmParser::parseDirectiveSEHPushReg(SMLoc Loc) {
5290 if (parseSEHRegisterNumber(X86::GR64RegClassID,
Reg))
5294 return TokError(
"expected end of directive");
5297 getStreamer().emitWinCFIPushReg(
Reg, Loc);
5301bool X86AsmParser::parseDirectiveSEHPush2Regs(SMLoc Loc,
bool SwapRegs) {
5303 if (parseSEHRegisterNumber(X86::GR64RegClassID, Reg1))
5307 return TokError(
"expected comma between registers");
5311 if (parseSEHRegisterNumber(X86::GR64RegClassID, Reg2))
5315 return TokError(
"expected end of directive");
5321 getStreamer().emitWinCFIPush2Regs(Reg1, Reg2, Loc);
5325bool X86AsmParser::parseDirectiveSEHSetFrame(SMLoc Loc) {
5328 if (parseSEHRegisterNumber(X86::GR64RegClassID,
Reg))
5331 return TokError(
"you must specify a stack pointer offset");
5334 if (getParser().parseAbsoluteExpression(
Off))
5338 return TokError(
"expected end of directive");
5341 getStreamer().emitWinCFISetFrame(
Reg,
Off, Loc);
5345bool X86AsmParser::parseDirectiveSEHSaveReg(SMLoc Loc) {
5348 if (parseSEHRegisterNumber(X86::GR64RegClassID,
Reg))
5351 return TokError(
"you must specify an offset on the stack");
5354 if (getParser().parseAbsoluteExpression(
Off))
5358 return TokError(
"expected end of directive");
5361 getStreamer().emitWinCFISaveReg(
Reg,
Off, Loc);
5365bool X86AsmParser::parseDirectiveSEHSaveXMM(SMLoc Loc) {
5368 if (parseSEHRegisterNumber(X86::VR128XRegClassID,
Reg))
5371 return TokError(
"you must specify an offset on the stack");
5374 if (getParser().parseAbsoluteExpression(
Off))
5378 return TokError(
"expected end of directive");
5381 getStreamer().emitWinCFISaveXMM(
Reg,
Off, Loc);
5385bool X86AsmParser::ensureMasmPrologContext(SMLoc Loc) {
5386 if (getStreamer().isWinCFIPrologEnded()) {
5387 return Error(Loc,
"prolog directive must be used inside a prolog");
5392bool X86AsmParser::ensureMasmEpilogContext(SMLoc Loc) {
5393 if (!getStreamer().isInEpilogCFI()) {
5394 return Error(Loc,
"epilog directive must be used inside an epilog");
5399bool X86AsmParser::parseDirectiveSEHPushFrame(SMLoc Loc) {
5403 SMLoc startLoc = getLexer().getLoc();
5405 if (!getParser().parseIdentifier(CodeID)) {
5406 if (CodeID !=
"code")
5407 return Error(startLoc,
"expected @code");
5410 }
else if (getParser().isParsingMasm() &&
5412 getTok().getString().equals_insensitive(
"code")) {
5418 return TokError(
"expected end of directive");
5421 getStreamer().emitWinCFIPushFrame(Code, Loc);
5431#define GET_MATCHER_IMPLEMENTATION
5432#include "X86GenAsmMatcher.inc"
static MCRegister MatchRegisterName(StringRef Name)
static const char * getSubtargetFeatureName(uint64_t Val)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
Function Alias Analysis false
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
amode Optimize addressing mode
Value * getPointer(Value *Ptr)
static ModuleSymbolTable::Symbol getSym(DataRefImpl &Symb)
static constexpr Value * getValue(Ty &ValueOrUse)
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits, ArrayRef< SubtargetFeatureKV > ProcFeatures)
static bool IsVCMP(unsigned Opcode)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
OptimizedStructLayoutField Field
static StringRef getName(Value *V)
MachineRegisterInfo & MRI
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the SmallString class.
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static bool isAbsolute(SDValue CmpOp, SDValue Pos, SDValue Neg)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static SymbolRef::Type getType(const Symbol *Sym)
#define LLVM_C_ABI
LLVM_C_ABI is the export/visibility macro used to mark symbols declared in llvm-c as exported when bu...
LLVM_C_ABI void LLVMInitializeX86AsmParser()
static bool convertSSEToAVX(MCInst &Inst)
static unsigned getPrefixes(OperandVector &Operands)
static bool checkScale(int64_t Scale, StringRef &ErrMsg)
static bool CheckBaseRegAndIndexRegAndScale(MCRegister BaseReg, MCRegister IndexReg, unsigned Scale, bool Is64BitMode, StringRef &ErrMsg)
#define FROM_TO(FROM, TO)
uint16_t RegSizeInBits(const MCRegisterInfo &MRI, MCRegister RegNo)
static unsigned getSize(unsigned Kind)
uint64_t getZExtValue() const
Get zero extended value.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
void UnLex(AsmToken const &Token)
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
LLVM_ABI SMLoc getLoc() const
int64_t getIntVal() const
bool isNot(TokenKind K) const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
bool is(TokenKind K) const
TokenKind getKind() const
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
bool Error(SMLoc L, const Twine &Msg, SMRange Range={})
Return an error at the location L, with the message Msg.
bool parseIntToken(int64_t &V, const Twine &ErrMsg="expected integer")
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual bool isParsingMasm() const
virtual bool parseIdentifier(StringRef &Res)=0
Parse an identifier or string (as a quoted identifier) and set Res to the identifier contents.
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc, AsmTypeInfo *TypeInfo=nullptr)=0
Parse a primary expression.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
bool TokError(const Twine &Msg, SMRange Range={})
Report an error at the current lexer location.
virtual void addAliasForDirective(StringRef Directive, StringRef Alias)=0
virtual bool lookUpType(StringRef Name, AsmTypeInfo &Info) const
virtual bool parseAbsoluteExpression(int64_t &Res)=0
Parse an expression which must evaluate to an absolute value.
virtual bool lookUpField(StringRef Name, AsmFieldInfo &Info) const
bool parseTokenLoc(SMLoc &Loc)
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
@ SymbolRef
References to labels and assigned expressions.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getFlags() const
unsigned getOpcode() const
void setFlags(unsigned F)
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
bool mayLoad() const
Return true if this instruction could possibly read memory.
bool isCall() const
Return true if the instruction is a call.
bool isTerminator() const
Returns true if this instruction part of the terminator for a basic block.
static MCOperand createImm(int64_t Val)
MCRegister getReg() const
Returns the register number.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
static constexpr unsigned NoRegister
const FeatureBitset & getFeatureBits() const
const FeatureBitset & ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
StringRef getName() const
getName - Get the symbol name.
bool isVariable() const
isVariable - Check if this is a variable symbol.
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
static constexpr StatusTy Failure
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
constexpr unsigned id() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
constexpr bool isValid() const
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
static constexpr size_t npos
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
LLVM_ABI std::string upper() const
Convert the given ASCII string to uppercase.
char back() const
Get the last character in the string.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
Get the string size.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
LLVM_ABI std::string lower() const
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
static const char * getRegisterName(MCRegister Reg)
static const X86MCExpr * create(MCRegister Reg, MCContext &Ctx)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
std::variant< std::monostate, Loc::Single, Loc::Multi, Loc::MMI, Loc::EntryValue > Variant
Alias for the std::variant specialization base class of DbgVariable.
@ CE
Windows NT (Windows on ARM)
@ X86
Windows x64, Windows Itanium (IA-64)
bool isX86_64NonExtLowByteReg(MCRegister Reg)
@ EVEX
EVEX - Specifies that this instruction use EVEX form which provides syntax support up to 32 512-bit r...
@ VEX
VEX - encoding using 0xC4/0xC5.
@ XOP
XOP - Opcode prefix used by XOP instructions.
@ ExplicitVEXPrefix
For instructions that use VEX encoding only when {vex}, {vex2} or {vex3} is present.
bool canUseApxExtendedReg(const MCInstrDesc &Desc)
bool isX86_64ExtendedReg(MCRegister Reg)
bool isApxExtendedReg(MCRegister Reg)
void emitInstruction(MCObjectStreamer &, const MCInst &Inst, const MCSubtargetInfo &STI)
bool optimizeShiftRotateWithImmediateOne(MCInst &MI)
bool optimizeInstFromVEX3ToVEX2(MCInst &MI, const MCInstrDesc &Desc)
LLVM_ABI TargetOptions getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions, const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
NodeAddr< CodeNode * > Code
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
This is an optimization pass for GlobalISel generic memory operations.
constexpr bool divideSignedWouldOverflow(U Numerator, V Denominator)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
Target & getTheX86_32Target()
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
@ End
Run the machine verifier once, at the end of the pipeline.
Target & getTheX86_64Target()
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool isKind(IdKind kind) const
SmallVectorImpl< AsmRewrite > * AsmRewrites
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...
X86Operand - Instances of this class represent a parsed X86 machine instruction.
SMLoc getStartLoc() const override
getStartLoc - Get the location of the first token of this operand.
bool isImm() const override
isImm - Is this an immediate operand?
static std::unique_ptr< X86Operand > CreateImm(const MCExpr *Val, SMLoc StartLoc, SMLoc EndLoc, StringRef SymName=StringRef(), void *OpDecl=nullptr, bool GlobalRef=true)
static std::unique_ptr< X86Operand > CreatePrefix(unsigned Prefixes, SMLoc StartLoc, SMLoc EndLoc)
static std::unique_ptr< X86Operand > CreateDXReg(SMLoc StartLoc, SMLoc EndLoc)
static std::unique_ptr< X86Operand > CreateReg(MCRegister Reg, SMLoc StartLoc, SMLoc EndLoc, bool AddressOf=false, SMLoc OffsetOfLoc=SMLoc(), StringRef SymName=StringRef(), void *OpDecl=nullptr)
SMRange getLocRange() const
getLocRange - Get the range between the first and last token of this operand.
SMLoc getEndLoc() const override
getEndLoc - Get the location of the last token of this operand.
bool isReg() const override
isReg - Is this a register operand?
bool isMem() const override
isMem - Is this a memory operand?
static std::unique_ptr< X86Operand > CreateMem(unsigned ModeSize, const MCExpr *Disp, SMLoc StartLoc, SMLoc EndLoc, unsigned Size=0, StringRef SymName=StringRef(), void *OpDecl=nullptr, unsigned FrontendSize=0, bool UseUpRegs=false, bool MaybeDirectBranchDest=true)
Create an absolute memory operand.
static std::unique_ptr< X86Operand > CreateToken(StringRef Str, SMLoc Loc)
bool isMemUnsized() const
const MCExpr * getImm() const
unsigned getMemFrontendSize() const
MCRegister getReg() const override