1 //===-- ARM64AsmParser.cpp - Parse ARM64 assembly to MCInst instructions --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "MCTargetDesc/ARM64AddressingModes.h"
11 #include "MCTargetDesc/ARM64MCExpr.h"
12 #include "Utils/ARM64BaseInfo.h"
13 #include "llvm/MC/MCParser/MCAsmLexer.h"
14 #include "llvm/MC/MCParser/MCAsmParser.h"
15 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCStreamer.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/MC/MCSymbol.h"
23 #include "llvm/MC/MCTargetAsmParser.h"
24 #include "llvm/Support/SourceMgr.h"
25 #include "llvm/Support/TargetRegistry.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/raw_ostream.h"
28 #include "llvm/ADT/SmallString.h"
29 #include "llvm/ADT/SmallVector.h"
30 #include "llvm/ADT/STLExtras.h"
31 #include "llvm/ADT/StringSwitch.h"
32 #include "llvm/ADT/Twine.h"
40 class ARM64AsmParser : public MCTargetAsmParser {
42 typedef SmallVectorImpl<MCParsedAsmOperand *> OperandVector;
45 StringRef Mnemonic; ///< Instruction mnemonic.
49 MCAsmParser &getParser() const { return Parser; }
50 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
52 SMLoc getLoc() const { return Parser.getTok().getLoc(); }
54 bool parseSysAlias(StringRef Name, SMLoc NameLoc, OperandVector &Operands);
55 unsigned parseCondCodeString(StringRef Cond);
56 bool parseCondCode(OperandVector &Operands, bool invertCondCode);
57 int tryParseRegister();
58 int tryMatchVectorRegister(StringRef &Kind, bool expected);
59 bool parseOptionalShift(OperandVector &Operands);
60 bool parseOptionalExtend(OperandVector &Operands);
61 bool parseRegister(OperandVector &Operands);
62 bool parseMemory(OperandVector &Operands);
63 bool parseSymbolicImmVal(const MCExpr *&ImmVal);
64 bool parseVectorList(OperandVector &Operands);
65 bool parseOperand(OperandVector &Operands, bool isCondCode,
68 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
69 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
70 bool showMatchError(SMLoc Loc, unsigned ErrCode);
72 bool parseDirectiveWord(unsigned Size, SMLoc L);
73 bool parseDirectiveTLSDescCall(SMLoc L);
75 bool parseDirectiveLOH(StringRef LOH, SMLoc L);
77 bool validateInstruction(MCInst &Inst, SmallVectorImpl<SMLoc> &Loc);
78 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
79 OperandVector &Operands, MCStreamer &Out,
80 unsigned &ErrorInfo, bool MatchingInlineAsm);
81 /// @name Auto-generated Match Functions
84 #define GET_ASSEMBLER_HEADER
85 #include "ARM64GenAsmMatcher.inc"
89 OperandMatchResultTy tryParseNoIndexMemory(OperandVector &Operands);
90 OperandMatchResultTy tryParseBarrierOperand(OperandVector &Operands);
91 OperandMatchResultTy tryParseMRSSystemRegister(OperandVector &Operands);
92 OperandMatchResultTy tryParseMSRSystemRegister(OperandVector &Operands);
93 OperandMatchResultTy tryParseCPSRField(OperandVector &Operands);
94 OperandMatchResultTy tryParseSysCROperand(OperandVector &Operands);
95 OperandMatchResultTy tryParsePrefetch(OperandVector &Operands);
96 OperandMatchResultTy tryParseAdrpLabel(OperandVector &Operands);
97 OperandMatchResultTy tryParseAdrLabel(OperandVector &Operands);
98 OperandMatchResultTy tryParseFPImm(OperandVector &Operands);
99 bool tryParseVectorRegister(OperandVector &Operands);
102 enum ARM64MatchResultTy {
103 Match_InvalidSuffix = FIRST_TARGET_MATCH_RESULT_TY,
104 #define GET_OPERAND_DIAGNOSTIC_TYPES
105 #include "ARM64GenAsmMatcher.inc"
107 ARM64AsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
108 const MCInstrInfo &MII)
109 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
110 MCAsmParserExtension::Initialize(_Parser);
113 virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
114 SMLoc NameLoc, OperandVector &Operands);
115 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
116 virtual bool ParseDirective(AsmToken DirectiveID);
117 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
119 static bool classifySymbolRef(const MCExpr *Expr,
120 ARM64MCExpr::VariantKind &ELFRefKind,
121 MCSymbolRefExpr::VariantKind &DarwinRefKind,
122 const MCConstantExpr *&Addend);
124 } // end anonymous namespace
128 /// ARM64Operand - Instances of this class represent a parsed ARM64 machine
130 class ARM64Operand : public MCParsedAsmOperand {
133 ImmediateOffset, // pre-indexed, no writeback
134 RegisterOffset // register offset, with optional extend
155 SMLoc StartLoc, EndLoc, OffsetLoc;
160 bool IsSuffix; // Is the operand actually a suffix on the mnemonic.
168 struct VectorListOp {
171 unsigned NumElements;
172 unsigned ElementKind;
175 struct VectorIndexOp {
184 unsigned Val; // Encoded 8-bit representation.
188 unsigned Val; // Not the enum since not all values have names.
191 struct SystemRegisterOp {
192 // 16-bit immediate, usually from the ARM64SysReg::SysRegValues enum
193 // but not limited to those values.
198 ARM64PState::PStateValues Field;
217 // This is for all forms of ARM64 address expressions
219 unsigned BaseRegNum, OffsetRegNum;
220 ARM64_AM::ExtendType ExtType;
223 const MCExpr *OffsetImm;
230 struct VectorListOp VectorList;
231 struct VectorIndexOp VectorIndex;
233 struct FPImmOp FPImm;
234 struct BarrierOp Barrier;
235 struct SystemRegisterOp SystemRegister;
236 struct CPSRFieldOp CPSRField;
237 struct SysCRImmOp SysCRImm;
238 struct PrefetchOp Prefetch;
239 struct ShifterOp Shifter;
240 struct ExtendOp Extend;
244 // Keep the MCContext around as the MCExprs may need manipulated during
245 // the add<>Operands() calls.
248 ARM64Operand(KindTy K, MCContext &_Ctx)
249 : MCParsedAsmOperand(), Kind(K), Ctx(_Ctx) {}
252 ARM64Operand(const ARM64Operand &o) : MCParsedAsmOperand(), Ctx(o.Ctx) {
254 StartLoc = o.StartLoc;
269 case k_SystemRegister:
270 SystemRegister = o.SystemRegister;
273 CPSRField = o.CPSRField;
279 VectorList = o.VectorList;
282 VectorIndex = o.VectorIndex;
285 SysCRImm = o.SysCRImm;
288 Prefetch = o.Prefetch;
302 /// getStartLoc - Get the location of the first token of this operand.
303 SMLoc getStartLoc() const { return StartLoc; }
304 /// getEndLoc - Get the location of the last token of this operand.
305 SMLoc getEndLoc() const { return EndLoc; }
306 /// getOffsetLoc - Get the location of the offset of this memory operand.
307 SMLoc getOffsetLoc() const { return OffsetLoc; }
309 StringRef getToken() const {
310 assert(Kind == k_Token && "Invalid access!");
311 return StringRef(Tok.Data, Tok.Length);
314 bool isTokenSuffix() const {
315 assert(Kind == k_Token && "Invalid access!");
319 const MCExpr *getImm() const {
320 assert(Kind == k_Immediate && "Invalid access!");
324 unsigned getFPImm() const {
325 assert(Kind == k_FPImm && "Invalid access!");
329 unsigned getBarrier() const {
330 assert(Kind == k_Barrier && "Invalid access!");
334 uint16_t getSystemRegister() const {
335 assert(Kind == k_SystemRegister && "Invalid access!");
336 return SystemRegister.Val;
339 ARM64PState::PStateValues getCPSRField() const {
340 assert(Kind == k_CPSRField && "Invalid access!");
341 return CPSRField.Field;
344 unsigned getReg() const {
345 assert(Kind == k_Register && "Invalid access!");
349 unsigned getVectorListStart() const {
350 assert(Kind == k_VectorList && "Invalid access!");
351 return VectorList.RegNum;
354 unsigned getVectorListCount() const {
355 assert(Kind == k_VectorList && "Invalid access!");
356 return VectorList.Count;
359 unsigned getVectorIndex() const {
360 assert(Kind == k_VectorIndex && "Invalid access!");
361 return VectorIndex.Val;
364 unsigned getSysCR() const {
365 assert(Kind == k_SysCR && "Invalid access!");
369 unsigned getPrefetch() const {
370 assert(Kind == k_Prefetch && "Invalid access!");
374 unsigned getShifter() const {
375 assert(Kind == k_Shifter && "Invalid access!");
379 unsigned getExtend() const {
380 assert(Kind == k_Extend && "Invalid access!");
384 bool isImm() const { return Kind == k_Immediate; }
385 bool isSImm9() const {
388 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
391 int64_t Val = MCE->getValue();
392 return (Val >= -256 && Val < 256);
394 bool isSImm7s4() const {
397 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
400 int64_t Val = MCE->getValue();
401 return (Val >= -256 && Val <= 252 && (Val & 3) == 0);
403 bool isSImm7s8() const {
406 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
409 int64_t Val = MCE->getValue();
410 return (Val >= -512 && Val <= 504 && (Val & 7) == 0);
412 bool isSImm7s16() const {
415 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
418 int64_t Val = MCE->getValue();
419 return (Val >= -1024 && Val <= 1008 && (Val & 15) == 0);
421 bool isImm0_7() const {
424 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
427 int64_t Val = MCE->getValue();
428 return (Val >= 0 && Val < 8);
430 bool isImm1_8() const {
433 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
436 int64_t Val = MCE->getValue();
437 return (Val > 0 && Val < 9);
439 bool isImm0_15() const {
442 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
445 int64_t Val = MCE->getValue();
446 return (Val >= 0 && Val < 16);
448 bool isImm1_16() const {
451 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
454 int64_t Val = MCE->getValue();
455 return (Val > 0 && Val < 17);
457 bool isImm0_31() const {
460 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
463 int64_t Val = MCE->getValue();
464 return (Val >= 0 && Val < 32);
466 bool isImm1_31() const {
469 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
472 int64_t Val = MCE->getValue();
473 return (Val >= 1 && Val < 32);
475 bool isImm1_32() const {
478 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
481 int64_t Val = MCE->getValue();
482 return (Val >= 1 && Val < 33);
484 bool isImm0_63() const {
487 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
490 int64_t Val = MCE->getValue();
491 return (Val >= 0 && Val < 64);
493 bool isImm1_63() const {
496 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
499 int64_t Val = MCE->getValue();
500 return (Val >= 1 && Val < 64);
502 bool isImm1_64() const {
505 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
508 int64_t Val = MCE->getValue();
509 return (Val >= 1 && Val < 65);
511 bool isImm0_127() const {
514 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
517 int64_t Val = MCE->getValue();
518 return (Val >= 0 && Val < 128);
520 bool isImm0_255() const {
523 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
526 int64_t Val = MCE->getValue();
527 return (Val >= 0 && Val < 256);
529 bool isImm0_65535() const {
532 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
535 int64_t Val = MCE->getValue();
536 return (Val >= 0 && Val < 65536);
538 bool isLogicalImm32() const {
541 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
544 return ARM64_AM::isLogicalImmediate(MCE->getValue(), 32);
546 bool isLogicalImm64() const {
549 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
552 return ARM64_AM::isLogicalImmediate(MCE->getValue(), 64);
554 bool isSIMDImmType10() const {
557 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
560 return ARM64_AM::isAdvSIMDModImmType10(MCE->getValue());
562 bool isBranchTarget26() const {
565 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
568 int64_t Val = MCE->getValue();
571 return (Val >= -(0x2000000 << 2) && Val <= (0x1ffffff << 2));
573 bool isBranchTarget19() const {
576 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
579 int64_t Val = MCE->getValue();
582 return (Val >= -(0x40000 << 2) && Val <= (0x3ffff << 2));
584 bool isBranchTarget14() const {
587 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
590 int64_t Val = MCE->getValue();
593 return (Val >= -(0x2000 << 2) && Val <= (0x1fff << 2));
596 bool isMovWSymbol(ArrayRef<ARM64MCExpr::VariantKind> AllowedModifiers) const {
600 ARM64MCExpr::VariantKind ELFRefKind;
601 MCSymbolRefExpr::VariantKind DarwinRefKind;
602 const MCConstantExpr *Addend;
603 if (!ARM64AsmParser::classifySymbolRef(getImm(), ELFRefKind, DarwinRefKind,
607 if (DarwinRefKind != MCSymbolRefExpr::VK_None)
610 for (unsigned i = 0; i != AllowedModifiers.size(); ++i) {
611 if (ELFRefKind == AllowedModifiers[i])
618 bool isMovZSymbolG3() const {
619 static ARM64MCExpr::VariantKind Variants[] = { ARM64MCExpr::VK_ABS_G3 };
620 return isMovWSymbol(Variants);
623 bool isMovZSymbolG2() const {
624 static ARM64MCExpr::VariantKind Variants[] = { ARM64MCExpr::VK_ABS_G2,
625 ARM64MCExpr::VK_TPREL_G2,
626 ARM64MCExpr::VK_DTPREL_G2 };
627 return isMovWSymbol(Variants);
630 bool isMovZSymbolG1() const {
631 static ARM64MCExpr::VariantKind Variants[] = { ARM64MCExpr::VK_ABS_G1,
632 ARM64MCExpr::VK_GOTTPREL_G1,
633 ARM64MCExpr::VK_TPREL_G1,
634 ARM64MCExpr::VK_DTPREL_G1, };
635 return isMovWSymbol(Variants);
638 bool isMovZSymbolG0() const {
639 static ARM64MCExpr::VariantKind Variants[] = { ARM64MCExpr::VK_ABS_G0,
640 ARM64MCExpr::VK_TPREL_G0,
641 ARM64MCExpr::VK_DTPREL_G0 };
642 return isMovWSymbol(Variants);
645 bool isMovKSymbolG2() const {
646 static ARM64MCExpr::VariantKind Variants[] = { ARM64MCExpr::VK_ABS_G2_NC };
647 return isMovWSymbol(Variants);
650 bool isMovKSymbolG1() const {
651 static ARM64MCExpr::VariantKind Variants[] = {
652 ARM64MCExpr::VK_ABS_G1_NC, ARM64MCExpr::VK_TPREL_G1_NC,
653 ARM64MCExpr::VK_DTPREL_G1_NC
655 return isMovWSymbol(Variants);
658 bool isMovKSymbolG0() const {
659 static ARM64MCExpr::VariantKind Variants[] = {
660 ARM64MCExpr::VK_ABS_G0_NC, ARM64MCExpr::VK_GOTTPREL_G0_NC,
661 ARM64MCExpr::VK_TPREL_G0_NC, ARM64MCExpr::VK_DTPREL_G0_NC
663 return isMovWSymbol(Variants);
666 bool isFPImm() const { return Kind == k_FPImm; }
667 bool isBarrier() const { return Kind == k_Barrier; }
668 bool isSystemRegister() const {
669 if (Kind == k_SystemRegister)
671 // SPSel is legal for both the system register and the CPSR-field
672 // variants of MSR, so special case that. Fugly.
673 return (Kind == k_CPSRField && getCPSRField() == ARM64PState::SPSel);
675 bool isSystemCPSRField() const { return Kind == k_CPSRField; }
676 bool isReg() const { return Kind == k_Register && !Reg.isVector; }
677 bool isVectorReg() const { return Kind == k_Register && Reg.isVector; }
679 /// Is this a vector list with the type implicit (presumably attached to the
680 /// instruction itself)?
681 template <unsigned NumRegs> bool isImplicitlyTypedVectorList() const {
682 return Kind == k_VectorList && VectorList.Count == NumRegs &&
683 !VectorList.ElementKind;
686 template <unsigned NumRegs, unsigned NumElements, char ElementKind>
687 bool isTypedVectorList() const {
688 if (Kind != k_VectorList)
690 if (VectorList.Count != NumRegs)
692 if (VectorList.ElementKind != ElementKind)
694 return VectorList.NumElements == NumElements;
697 bool isVectorIndexB() const {
698 return Kind == k_VectorIndex && VectorIndex.Val < 16;
700 bool isVectorIndexH() const {
701 return Kind == k_VectorIndex && VectorIndex.Val < 8;
703 bool isVectorIndexS() const {
704 return Kind == k_VectorIndex && VectorIndex.Val < 4;
706 bool isVectorIndexD() const {
707 return Kind == k_VectorIndex && VectorIndex.Val < 2;
709 bool isToken() const { return Kind == k_Token; }
710 bool isTokenEqual(StringRef Str) const {
711 return Kind == k_Token && getToken() == Str;
713 bool isMem() const { return Kind == k_Memory; }
714 bool isSysCR() const { return Kind == k_SysCR; }
715 bool isPrefetch() const { return Kind == k_Prefetch; }
716 bool isShifter() const { return Kind == k_Shifter; }
717 bool isExtend() const {
718 // lsl is an alias for UXTW but will be a parsed as a k_Shifter operand.
720 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(Shifter.Val);
721 return ST == ARM64_AM::LSL;
723 return Kind == k_Extend;
725 bool isExtend64() const {
726 if (Kind != k_Extend)
728 // UXTX and SXTX require a 64-bit source register (the ExtendLSL64 class).
729 ARM64_AM::ExtendType ET = ARM64_AM::getArithExtendType(Extend.Val);
730 return ET != ARM64_AM::UXTX && ET != ARM64_AM::SXTX;
732 bool isExtendLSL64() const {
733 // lsl is an alias for UXTX but will be a parsed as a k_Shifter operand.
735 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(Shifter.Val);
736 return ST == ARM64_AM::LSL;
738 if (Kind != k_Extend)
740 ARM64_AM::ExtendType ET = ARM64_AM::getArithExtendType(Extend.Val);
741 return ET == ARM64_AM::UXTX || ET == ARM64_AM::SXTX;
744 bool isArithmeticShifter() const {
748 // An arithmetic shifter is LSL, LSR, or ASR.
749 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(Shifter.Val);
750 return ST == ARM64_AM::LSL || ST == ARM64_AM::LSR || ST == ARM64_AM::ASR;
753 bool isMovImm32Shifter() const {
757 // A MOVi shifter is LSL of 0, 16, 32, or 48.
758 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(Shifter.Val);
759 if (ST != ARM64_AM::LSL)
761 uint64_t Val = ARM64_AM::getShiftValue(Shifter.Val);
762 return (Val == 0 || Val == 16);
765 bool isMovImm64Shifter() const {
769 // A MOVi shifter is LSL of 0 or 16.
770 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(Shifter.Val);
771 if (ST != ARM64_AM::LSL)
773 uint64_t Val = ARM64_AM::getShiftValue(Shifter.Val);
774 return (Val == 0 || Val == 16 || Val == 32 || Val == 48);
777 bool isAddSubShifter() const {
781 // An ADD/SUB shifter is either 'lsl #0' or 'lsl #12'.
782 unsigned Val = Shifter.Val;
783 return ARM64_AM::getShiftType(Val) == ARM64_AM::LSL &&
784 (ARM64_AM::getShiftValue(Val) == 0 ||
785 ARM64_AM::getShiftValue(Val) == 12);
788 bool isLogicalVecShifter() const {
792 // A logical vector shifter is a left shift by 0, 8, 16, or 24.
793 unsigned Val = Shifter.Val;
794 unsigned Shift = ARM64_AM::getShiftValue(Val);
795 return ARM64_AM::getShiftType(Val) == ARM64_AM::LSL &&
796 (Shift == 0 || Shift == 8 || Shift == 16 || Shift == 24);
799 bool isLogicalVecHalfWordShifter() const {
800 if (!isLogicalVecShifter())
803 // A logical vector shifter is a left shift by 0 or 8.
804 unsigned Val = Shifter.Val;
805 unsigned Shift = ARM64_AM::getShiftValue(Val);
806 return ARM64_AM::getShiftType(Val) == ARM64_AM::LSL &&
807 (Shift == 0 || Shift == 8);
810 bool isMoveVecShifter() const {
814 // A logical vector shifter is a left shift by 8 or 16.
815 unsigned Val = Shifter.Val;
816 unsigned Shift = ARM64_AM::getShiftValue(Val);
817 return ARM64_AM::getShiftType(Val) == ARM64_AM::MSL &&
818 (Shift == 8 || Shift == 16);
821 bool isMemoryRegisterOffset8() const {
822 return isMem() && Mem.Mode == RegisterOffset && Mem.ShiftVal == 0;
825 bool isMemoryRegisterOffset16() const {
826 return isMem() && Mem.Mode == RegisterOffset &&
827 (Mem.ShiftVal == 0 || Mem.ShiftVal == 1);
830 bool isMemoryRegisterOffset32() const {
831 return isMem() && Mem.Mode == RegisterOffset &&
832 (Mem.ShiftVal == 0 || Mem.ShiftVal == 2);
835 bool isMemoryRegisterOffset64() const {
836 return isMem() && Mem.Mode == RegisterOffset &&
837 (Mem.ShiftVal == 0 || Mem.ShiftVal == 3);
840 bool isMemoryRegisterOffset128() const {
841 return isMem() && Mem.Mode == RegisterOffset &&
842 (Mem.ShiftVal == 0 || Mem.ShiftVal == 4);
845 bool isMemoryUnscaled() const {
848 if (Mem.Mode != ImmediateOffset)
852 // Make sure the immediate value is valid.
853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
856 // The offset must fit in a signed 9-bit unscaled immediate.
857 int64_t Value = CE->getValue();
858 return (Value >= -256 && Value < 256);
860 // Fallback unscaled operands are for aliases of LDR/STR that fall back
861 // to LDUR/STUR when the offset is not legal for the former but is for
862 // the latter. As such, in addition to checking for being a legal unscaled
863 // address, also check that it is not a legal scaled address. This avoids
864 // ambiguity in the matcher.
865 bool isMemoryUnscaledFB8() const {
866 return isMemoryUnscaled() && !isMemoryIndexed8();
868 bool isMemoryUnscaledFB16() const {
869 return isMemoryUnscaled() && !isMemoryIndexed16();
871 bool isMemoryUnscaledFB32() const {
872 return isMemoryUnscaled() && !isMemoryIndexed32();
874 bool isMemoryUnscaledFB64() const {
875 return isMemoryUnscaled() && !isMemoryIndexed64();
877 bool isMemoryUnscaledFB128() const {
878 return isMemoryUnscaled() && !isMemoryIndexed128();
880 bool isMemoryIndexed(unsigned Scale) const {
883 if (Mem.Mode != ImmediateOffset)
887 // Make sure the immediate value is valid.
888 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
891 // The offset must be a positive multiple of the scale and in range of
892 // encoding with a 12-bit immediate.
893 int64_t Value = CE->getValue();
894 return (Value >= 0 && (Value % Scale) == 0 && Value <= (4095 * Scale));
897 // If it's not a constant, check for some expressions we know.
898 const MCExpr *Expr = Mem.OffsetImm;
899 ARM64MCExpr::VariantKind ELFRefKind;
900 MCSymbolRefExpr::VariantKind DarwinRefKind;
901 const MCConstantExpr *Addend;
902 if (!ARM64AsmParser::classifySymbolRef(Expr, ELFRefKind, DarwinRefKind,
904 // If we don't understand the expression, assume the best and
905 // let the fixup and relocation code deal with it.
909 if (DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
910 ELFRefKind == ARM64MCExpr::VK_LO12 ||
911 ELFRefKind == ARM64MCExpr::VK_GOT_LO12 ||
912 ELFRefKind == ARM64MCExpr::VK_DTPREL_LO12 ||
913 ELFRefKind == ARM64MCExpr::VK_DTPREL_LO12_NC ||
914 ELFRefKind == ARM64MCExpr::VK_TPREL_LO12 ||
915 ELFRefKind == ARM64MCExpr::VK_TPREL_LO12_NC ||
916 ELFRefKind == ARM64MCExpr::VK_GOTTPREL_LO12_NC ||
917 ELFRefKind == ARM64MCExpr::VK_TLSDESC_LO12) {
918 // Note that we don't range-check the addend. It's adjusted modulo page
919 // size when converted, so there is no "out of range" condition when using
921 int64_t Value = Addend ? Addend->getValue() : 0;
922 return Value >= 0 && (Value % Scale) == 0;
923 } else if (DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGEOFF ||
924 DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGEOFF) {
925 // @gotpageoff/@tlvppageoff can only be used directly, not with an addend.
931 bool isMemoryIndexed128() const { return isMemoryIndexed(16); }
932 bool isMemoryIndexed64() const { return isMemoryIndexed(8); }
933 bool isMemoryIndexed32() const { return isMemoryIndexed(4); }
934 bool isMemoryIndexed16() const { return isMemoryIndexed(2); }
935 bool isMemoryIndexed8() const { return isMemoryIndexed(1); }
936 bool isMemoryNoIndex() const {
939 if (Mem.Mode != ImmediateOffset)
944 // Make sure the immediate value is valid. Only zero is allowed.
945 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
946 if (!CE || CE->getValue() != 0)
950 bool isMemorySIMDNoIndex() const {
953 if (Mem.Mode != ImmediateOffset)
955 return Mem.OffsetImm == 0;
957 bool isMemoryIndexedSImm9() const {
958 if (!isMem() || Mem.Mode != ImmediateOffset)
962 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
963 assert(CE && "Non-constant pre-indexed offset!");
964 int64_t Value = CE->getValue();
965 return Value >= -256 && Value <= 255;
967 bool isMemoryIndexed32SImm7() const {
968 if (!isMem() || Mem.Mode != ImmediateOffset)
972 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
973 assert(CE && "Non-constant pre-indexed offset!");
974 int64_t Value = CE->getValue();
975 return ((Value % 4) == 0) && Value >= -256 && Value <= 252;
977 bool isMemoryIndexed64SImm7() const {
978 if (!isMem() || Mem.Mode != ImmediateOffset)
982 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
983 assert(CE && "Non-constant pre-indexed offset!");
984 int64_t Value = CE->getValue();
985 return ((Value % 8) == 0) && Value >= -512 && Value <= 504;
987 bool isMemoryIndexed128SImm7() const {
988 if (!isMem() || Mem.Mode != ImmediateOffset)
992 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
993 assert(CE && "Non-constant pre-indexed offset!");
994 int64_t Value = CE->getValue();
995 return ((Value % 16) == 0) && Value >= -1024 && Value <= 1008;
998 bool isAdrpLabel() const {
999 // Validation was handled during parsing, so we just sanity check that
1000 // something didn't go haywire.
1004 bool isAdrLabel() const {
1005 // Validation was handled during parsing, so we just sanity check that
1006 // something didn't go haywire.
1010 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1011 // Add as immediates when possible. Null MCExpr = 0.
1013 Inst.addOperand(MCOperand::CreateImm(0));
1014 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1015 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1017 Inst.addOperand(MCOperand::CreateExpr(Expr));
1020 void addRegOperands(MCInst &Inst, unsigned N) const {
1021 assert(N == 1 && "Invalid number of operands!");
1022 Inst.addOperand(MCOperand::CreateReg(getReg()));
1025 void addVectorRegOperands(MCInst &Inst, unsigned N) const {
1026 assert(N == 1 && "Invalid number of operands!");
1027 Inst.addOperand(MCOperand::CreateReg(getReg()));
1030 template <unsigned NumRegs>
1031 void addVectorList64Operands(MCInst &Inst, unsigned N) const {
1032 assert(N == 1 && "Invalid number of operands!");
1033 static unsigned FirstRegs[] = { ARM64::D0, ARM64::D0_D1,
1034 ARM64::D0_D1_D2, ARM64::D0_D1_D2_D3 };
1035 unsigned FirstReg = FirstRegs[NumRegs - 1];
1038 MCOperand::CreateReg(FirstReg + getVectorListStart() - ARM64::Q0));
1041 template <unsigned NumRegs>
1042 void addVectorList128Operands(MCInst &Inst, unsigned N) const {
1043 assert(N == 1 && "Invalid number of operands!");
1044 static unsigned FirstRegs[] = { ARM64::Q0, ARM64::Q0_Q1,
1045 ARM64::Q0_Q1_Q2, ARM64::Q0_Q1_Q2_Q3 };
1046 unsigned FirstReg = FirstRegs[NumRegs - 1];
1049 MCOperand::CreateReg(FirstReg + getVectorListStart() - ARM64::Q0));
1052 void addVectorIndexBOperands(MCInst &Inst, unsigned N) const {
1053 assert(N == 1 && "Invalid number of operands!");
1054 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1057 void addVectorIndexHOperands(MCInst &Inst, unsigned N) const {
1058 assert(N == 1 && "Invalid number of operands!");
1059 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1062 void addVectorIndexSOperands(MCInst &Inst, unsigned N) const {
1063 assert(N == 1 && "Invalid number of operands!");
1064 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1067 void addVectorIndexDOperands(MCInst &Inst, unsigned N) const {
1068 assert(N == 1 && "Invalid number of operands!");
1069 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1072 void addImmOperands(MCInst &Inst, unsigned N) const {
1073 assert(N == 1 && "Invalid number of operands!");
1074 // If this is a pageoff symrefexpr with an addend, adjust the addend
1075 // to be only the page-offset portion. Otherwise, just add the expr
1077 addExpr(Inst, getImm());
1080 void addAdrpLabelOperands(MCInst &Inst, unsigned N) const {
1081 addImmOperands(Inst, N);
1084 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1085 addImmOperands(Inst, N);
1088 void addSImm9Operands(MCInst &Inst, unsigned N) const {
1089 assert(N == 1 && "Invalid number of operands!");
1090 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1091 assert(MCE && "Invalid constant immediate operand!");
1092 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1095 void addSImm7s4Operands(MCInst &Inst, unsigned N) const {
1096 assert(N == 1 && "Invalid number of operands!");
1097 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1098 assert(MCE && "Invalid constant immediate operand!");
1099 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() / 4));
1102 void addSImm7s8Operands(MCInst &Inst, unsigned N) const {
1103 assert(N == 1 && "Invalid number of operands!");
1104 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1105 assert(MCE && "Invalid constant immediate operand!");
1106 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() / 8));
1109 void addSImm7s16Operands(MCInst &Inst, unsigned N) const {
1110 assert(N == 1 && "Invalid number of operands!");
1111 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1112 assert(MCE && "Invalid constant immediate operand!");
1113 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() / 16));
1116 void addImm0_7Operands(MCInst &Inst, unsigned N) const {
1117 assert(N == 1 && "Invalid number of operands!");
1118 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1119 assert(MCE && "Invalid constant immediate operand!");
1120 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1123 void addImm1_8Operands(MCInst &Inst, unsigned N) const {
1124 assert(N == 1 && "Invalid number of operands!");
1125 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1126 assert(MCE && "Invalid constant immediate operand!");
1127 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1130 void addImm0_15Operands(MCInst &Inst, unsigned N) const {
1131 assert(N == 1 && "Invalid number of operands!");
1132 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1133 assert(MCE && "Invalid constant immediate operand!");
1134 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1137 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1138 assert(N == 1 && "Invalid number of operands!");
1139 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1140 assert(MCE && "Invalid constant immediate operand!");
1141 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1144 void addImm0_31Operands(MCInst &Inst, unsigned N) const {
1145 assert(N == 1 && "Invalid number of operands!");
1146 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1147 assert(MCE && "Invalid constant immediate operand!");
1148 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1151 void addImm1_31Operands(MCInst &Inst, unsigned N) const {
1152 assert(N == 1 && "Invalid number of operands!");
1153 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1154 assert(MCE && "Invalid constant immediate operand!");
1155 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1158 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1159 assert(N == 1 && "Invalid number of operands!");
1160 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1161 assert(MCE && "Invalid constant immediate operand!");
1162 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1165 void addImm0_63Operands(MCInst &Inst, unsigned N) const {
1166 assert(N == 1 && "Invalid number of operands!");
1167 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1168 assert(MCE && "Invalid constant immediate operand!");
1169 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1172 void addImm1_63Operands(MCInst &Inst, unsigned N) const {
1173 assert(N == 1 && "Invalid number of operands!");
1174 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1175 assert(MCE && "Invalid constant immediate operand!");
1176 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1179 void addImm1_64Operands(MCInst &Inst, unsigned N) const {
1180 assert(N == 1 && "Invalid number of operands!");
1181 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1182 assert(MCE && "Invalid constant immediate operand!");
1183 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1186 void addImm0_127Operands(MCInst &Inst, unsigned N) const {
1187 assert(N == 1 && "Invalid number of operands!");
1188 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1189 assert(MCE && "Invalid constant immediate operand!");
1190 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1193 void addImm0_255Operands(MCInst &Inst, unsigned N) const {
1194 assert(N == 1 && "Invalid number of operands!");
1195 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1196 assert(MCE && "Invalid constant immediate operand!");
1197 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1200 void addImm0_65535Operands(MCInst &Inst, unsigned N) const {
1201 assert(N == 1 && "Invalid number of operands!");
1202 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1203 assert(MCE && "Invalid constant immediate operand!");
1204 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1207 void addLogicalImm32Operands(MCInst &Inst, unsigned N) const {
1208 assert(N == 1 && "Invalid number of operands!");
1209 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1210 assert(MCE && "Invalid logical immediate operand!");
1211 uint64_t encoding = ARM64_AM::encodeLogicalImmediate(MCE->getValue(), 32);
1212 Inst.addOperand(MCOperand::CreateImm(encoding));
1215 void addLogicalImm64Operands(MCInst &Inst, unsigned N) const {
1216 assert(N == 1 && "Invalid number of operands!");
1217 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1218 assert(MCE && "Invalid logical immediate operand!");
1219 uint64_t encoding = ARM64_AM::encodeLogicalImmediate(MCE->getValue(), 64);
1220 Inst.addOperand(MCOperand::CreateImm(encoding));
1223 void addSIMDImmType10Operands(MCInst &Inst, unsigned N) const {
1224 assert(N == 1 && "Invalid number of operands!");
1225 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1226 assert(MCE && "Invalid immediate operand!");
1227 uint64_t encoding = ARM64_AM::encodeAdvSIMDModImmType10(MCE->getValue());
1228 Inst.addOperand(MCOperand::CreateImm(encoding));
1231 void addBranchTarget26Operands(MCInst &Inst, unsigned N) const {
1232 // Branch operands don't encode the low bits, so shift them off
1233 // here. If it's a label, however, just put it on directly as there's
1234 // not enough information now to do anything.
1235 assert(N == 1 && "Invalid number of operands!");
1236 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1238 addExpr(Inst, getImm());
1241 assert(MCE && "Invalid constant immediate operand!");
1242 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() >> 2));
1245 void addBranchTarget19Operands(MCInst &Inst, unsigned N) const {
1246 // Branch operands don't encode the low bits, so shift them off
1247 // here. If it's a label, however, just put it on directly as there's
1248 // not enough information now to do anything.
1249 assert(N == 1 && "Invalid number of operands!");
1250 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1252 addExpr(Inst, getImm());
1255 assert(MCE && "Invalid constant immediate operand!");
1256 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() >> 2));
1259 void addBranchTarget14Operands(MCInst &Inst, unsigned N) const {
1260 // Branch operands don't encode the low bits, so shift them off
1261 // here. If it's a label, however, just put it on directly as there's
1262 // not enough information now to do anything.
1263 assert(N == 1 && "Invalid number of operands!");
1264 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1266 addExpr(Inst, getImm());
1269 assert(MCE && "Invalid constant immediate operand!");
1270 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() >> 2));
1273 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1274 assert(N == 1 && "Invalid number of operands!");
1275 Inst.addOperand(MCOperand::CreateImm(getFPImm()));
1278 void addBarrierOperands(MCInst &Inst, unsigned N) const {
1279 assert(N == 1 && "Invalid number of operands!");
1280 Inst.addOperand(MCOperand::CreateImm(getBarrier()));
1283 void addSystemRegisterOperands(MCInst &Inst, unsigned N) const {
1284 assert(N == 1 && "Invalid number of operands!");
1285 if (Kind == k_SystemRegister)
1286 Inst.addOperand(MCOperand::CreateImm(getSystemRegister()));
1288 assert(Kind == k_CPSRField && getCPSRField() == ARM64PState::SPSel);
1289 Inst.addOperand(MCOperand::CreateImm(ARM64SysReg::SPSel));
1293 void addSystemCPSRFieldOperands(MCInst &Inst, unsigned N) const {
1294 assert(N == 1 && "Invalid number of operands!");
1295 Inst.addOperand(MCOperand::CreateImm(getCPSRField()));
1298 void addSysCROperands(MCInst &Inst, unsigned N) const {
1299 assert(N == 1 && "Invalid number of operands!");
1300 Inst.addOperand(MCOperand::CreateImm(getSysCR()));
1303 void addPrefetchOperands(MCInst &Inst, unsigned N) const {
1304 assert(N == 1 && "Invalid number of operands!");
1305 Inst.addOperand(MCOperand::CreateImm(getPrefetch()));
1308 void addShifterOperands(MCInst &Inst, unsigned N) const {
1309 assert(N == 1 && "Invalid number of operands!");
1310 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1313 void addArithmeticShifterOperands(MCInst &Inst, unsigned N) const {
1314 assert(N == 1 && "Invalid number of operands!");
1315 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1318 void addMovImm32ShifterOperands(MCInst &Inst, unsigned N) const {
1319 assert(N == 1 && "Invalid number of operands!");
1320 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1323 void addMovImm64ShifterOperands(MCInst &Inst, unsigned N) const {
1324 assert(N == 1 && "Invalid number of operands!");
1325 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1328 void addAddSubShifterOperands(MCInst &Inst, unsigned N) const {
1329 assert(N == 1 && "Invalid number of operands!");
1330 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1333 void addLogicalVecShifterOperands(MCInst &Inst, unsigned N) const {
1334 assert(N == 1 && "Invalid number of operands!");
1335 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1338 void addLogicalVecHalfWordShifterOperands(MCInst &Inst, unsigned N) const {
1339 assert(N == 1 && "Invalid number of operands!");
1340 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1343 void addMoveVecShifterOperands(MCInst &Inst, unsigned N) const {
1344 assert(N == 1 && "Invalid number of operands!");
1345 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1348 void addExtendOperands(MCInst &Inst, unsigned N) const {
1349 assert(N == 1 && "Invalid number of operands!");
1350 // lsl is an alias for UXTW but will be a parsed as a k_Shifter operand.
1352 assert(ARM64_AM::getShiftType(getShifter()) == ARM64_AM::LSL);
1353 unsigned imm = getArithExtendImm(ARM64_AM::UXTW,
1354 ARM64_AM::getShiftValue(getShifter()));
1355 Inst.addOperand(MCOperand::CreateImm(imm));
1357 Inst.addOperand(MCOperand::CreateImm(getExtend()));
1360 void addExtend64Operands(MCInst &Inst, unsigned N) const {
1361 assert(N == 1 && "Invalid number of operands!");
1362 Inst.addOperand(MCOperand::CreateImm(getExtend()));
1365 void addExtendLSL64Operands(MCInst &Inst, unsigned N) const {
1366 assert(N == 1 && "Invalid number of operands!");
1367 // lsl is an alias for UXTX but will be a parsed as a k_Shifter operand.
1369 assert(ARM64_AM::getShiftType(getShifter()) == ARM64_AM::LSL);
1370 unsigned imm = getArithExtendImm(ARM64_AM::UXTX,
1371 ARM64_AM::getShiftValue(getShifter()));
1372 Inst.addOperand(MCOperand::CreateImm(imm));
1374 Inst.addOperand(MCOperand::CreateImm(getExtend()));
1377 void addMemoryRegisterOffsetOperands(MCInst &Inst, unsigned N, bool DoShift) {
1378 assert(N == 3 && "Invalid number of operands!");
1380 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1381 Inst.addOperand(MCOperand::CreateReg(Mem.OffsetRegNum));
1382 unsigned ExtendImm = ARM64_AM::getMemExtendImm(Mem.ExtType, DoShift);
1383 Inst.addOperand(MCOperand::CreateImm(ExtendImm));
1386 void addMemoryRegisterOffset8Operands(MCInst &Inst, unsigned N) {
1387 addMemoryRegisterOffsetOperands(Inst, N, Mem.ExplicitShift);
1390 void addMemoryRegisterOffset16Operands(MCInst &Inst, unsigned N) {
1391 addMemoryRegisterOffsetOperands(Inst, N, Mem.ShiftVal == 1);
1394 void addMemoryRegisterOffset32Operands(MCInst &Inst, unsigned N) {
1395 addMemoryRegisterOffsetOperands(Inst, N, Mem.ShiftVal == 2);
1398 void addMemoryRegisterOffset64Operands(MCInst &Inst, unsigned N) {
1399 addMemoryRegisterOffsetOperands(Inst, N, Mem.ShiftVal == 3);
1402 void addMemoryRegisterOffset128Operands(MCInst &Inst, unsigned N) {
1403 addMemoryRegisterOffsetOperands(Inst, N, Mem.ShiftVal == 4);
1406 void addMemoryIndexedOperands(MCInst &Inst, unsigned N,
1407 unsigned Scale) const {
1408 // Add the base register operand.
1409 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1411 if (!Mem.OffsetImm) {
1412 // There isn't an offset.
1413 Inst.addOperand(MCOperand::CreateImm(0));
1417 // Add the offset operand.
1418 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm)) {
1419 assert(CE->getValue() % Scale == 0 &&
1420 "Offset operand must be multiple of the scale!");
1422 // The MCInst offset operand doesn't include the low bits (like the
1423 // instruction encoding).
1424 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / Scale));
1427 // If this is a pageoff symrefexpr with an addend, the linker will
1428 // do the scaling of the addend.
1430 // Otherwise we don't know what this is, so just add the scaling divide to
1431 // the expression and let the MC fixup evaluation code deal with it.
1432 const MCExpr *Expr = Mem.OffsetImm;
1433 ARM64MCExpr::VariantKind ELFRefKind;
1434 MCSymbolRefExpr::VariantKind DarwinRefKind;
1435 const MCConstantExpr *Addend;
1437 (!ARM64AsmParser::classifySymbolRef(Expr, ELFRefKind, DarwinRefKind,
1439 (Addend != 0 && DarwinRefKind != MCSymbolRefExpr::VK_PAGEOFF))) {
1440 Expr = MCBinaryExpr::CreateDiv(Expr, MCConstantExpr::Create(Scale, Ctx),
1444 Inst.addOperand(MCOperand::CreateExpr(Expr));
1447 void addMemoryUnscaledOperands(MCInst &Inst, unsigned N) const {
1448 assert(N == 2 && isMemoryUnscaled() && "Invalid number of operands!");
1449 // Add the base register operand.
1450 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1452 // Add the offset operand.
1454 Inst.addOperand(MCOperand::CreateImm(0));
1456 // Only constant offsets supported.
1457 const MCConstantExpr *CE = cast<MCConstantExpr>(Mem.OffsetImm);
1458 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1462 void addMemoryIndexed128Operands(MCInst &Inst, unsigned N) const {
1463 assert(N == 2 && isMemoryIndexed128() && "Invalid number of operands!");
1464 addMemoryIndexedOperands(Inst, N, 16);
1467 void addMemoryIndexed64Operands(MCInst &Inst, unsigned N) const {
1468 assert(N == 2 && isMemoryIndexed64() && "Invalid number of operands!");
1469 addMemoryIndexedOperands(Inst, N, 8);
1472 void addMemoryIndexed32Operands(MCInst &Inst, unsigned N) const {
1473 assert(N == 2 && isMemoryIndexed32() && "Invalid number of operands!");
1474 addMemoryIndexedOperands(Inst, N, 4);
1477 void addMemoryIndexed16Operands(MCInst &Inst, unsigned N) const {
1478 assert(N == 2 && isMemoryIndexed16() && "Invalid number of operands!");
1479 addMemoryIndexedOperands(Inst, N, 2);
1482 void addMemoryIndexed8Operands(MCInst &Inst, unsigned N) const {
1483 assert(N == 2 && isMemoryIndexed8() && "Invalid number of operands!");
1484 addMemoryIndexedOperands(Inst, N, 1);
1487 void addMemoryNoIndexOperands(MCInst &Inst, unsigned N) const {
1488 assert(N == 1 && isMemoryNoIndex() && "Invalid number of operands!");
1489 // Add the base register operand (the offset is always zero, so ignore it).
1490 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1493 void addMemorySIMDNoIndexOperands(MCInst &Inst, unsigned N) const {
1494 assert(N == 1 && isMemorySIMDNoIndex() && "Invalid number of operands!");
1495 // Add the base register operand (the offset is always zero, so ignore it).
1496 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1499 void addMemoryWritebackIndexedOperands(MCInst &Inst, unsigned N,
1500 unsigned Scale) const {
1501 assert(N == 2 && "Invalid number of operands!");
1503 // Add the base register operand.
1504 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1506 // Add the offset operand.
1508 if (Mem.OffsetImm) {
1509 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
1510 assert(CE && "Non-constant indexed offset operand!");
1511 Offset = CE->getValue();
1515 assert(Offset % Scale == 0 &&
1516 "Offset operand must be a multiple of the scale!");
1520 Inst.addOperand(MCOperand::CreateImm(Offset));
1523 void addMemoryIndexedSImm9Operands(MCInst &Inst, unsigned N) const {
1524 addMemoryWritebackIndexedOperands(Inst, N, 1);
1527 void addMemoryIndexed32SImm7Operands(MCInst &Inst, unsigned N) const {
1528 addMemoryWritebackIndexedOperands(Inst, N, 4);
1531 void addMemoryIndexed64SImm7Operands(MCInst &Inst, unsigned N) const {
1532 addMemoryWritebackIndexedOperands(Inst, N, 8);
1535 void addMemoryIndexed128SImm7Operands(MCInst &Inst, unsigned N) const {
1536 addMemoryWritebackIndexedOperands(Inst, N, 16);
1539 virtual void print(raw_ostream &OS) const;
1541 static ARM64Operand *CreateToken(StringRef Str, bool IsSuffix, SMLoc S,
1543 ARM64Operand *Op = new ARM64Operand(k_Token, Ctx);
1544 Op->Tok.Data = Str.data();
1545 Op->Tok.Length = Str.size();
1546 Op->Tok.IsSuffix = IsSuffix;
1552 static ARM64Operand *CreateReg(unsigned RegNum, bool isVector, SMLoc S,
1553 SMLoc E, MCContext &Ctx) {
1554 ARM64Operand *Op = new ARM64Operand(k_Register, Ctx);
1555 Op->Reg.RegNum = RegNum;
1556 Op->Reg.isVector = isVector;
1562 static ARM64Operand *CreateVectorList(unsigned RegNum, unsigned Count,
1563 unsigned NumElements, char ElementKind,
1564 SMLoc S, SMLoc E, MCContext &Ctx) {
1565 ARM64Operand *Op = new ARM64Operand(k_VectorList, Ctx);
1566 Op->VectorList.RegNum = RegNum;
1567 Op->VectorList.Count = Count;
1568 Op->VectorList.NumElements = NumElements;
1569 Op->VectorList.ElementKind = ElementKind;
1575 static ARM64Operand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
1577 ARM64Operand *Op = new ARM64Operand(k_VectorIndex, Ctx);
1578 Op->VectorIndex.Val = Idx;
1584 static ARM64Operand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E,
1586 ARM64Operand *Op = new ARM64Operand(k_Immediate, Ctx);
1593 static ARM64Operand *CreateFPImm(unsigned Val, SMLoc S, MCContext &Ctx) {
1594 ARM64Operand *Op = new ARM64Operand(k_FPImm, Ctx);
1595 Op->FPImm.Val = Val;
1601 static ARM64Operand *CreateBarrier(unsigned Val, SMLoc S, MCContext &Ctx) {
1602 ARM64Operand *Op = new ARM64Operand(k_Barrier, Ctx);
1603 Op->Barrier.Val = Val;
1609 static ARM64Operand *CreateSystemRegister(uint16_t Val, SMLoc S,
1611 ARM64Operand *Op = new ARM64Operand(k_SystemRegister, Ctx);
1612 Op->SystemRegister.Val = Val;
1618 static ARM64Operand *CreateCPSRField(ARM64PState::PStateValues Field, SMLoc S,
1620 ARM64Operand *Op = new ARM64Operand(k_CPSRField, Ctx);
1621 Op->CPSRField.Field = Field;
1627 static ARM64Operand *CreateMem(unsigned BaseRegNum, const MCExpr *Off,
1628 SMLoc S, SMLoc E, SMLoc OffsetLoc,
1630 ARM64Operand *Op = new ARM64Operand(k_Memory, Ctx);
1631 Op->Mem.BaseRegNum = BaseRegNum;
1632 Op->Mem.OffsetRegNum = 0;
1633 Op->Mem.OffsetImm = Off;
1634 Op->Mem.ExtType = ARM64_AM::UXTX;
1635 Op->Mem.ShiftVal = 0;
1636 Op->Mem.ExplicitShift = false;
1637 Op->Mem.Mode = ImmediateOffset;
1638 Op->OffsetLoc = OffsetLoc;
1644 static ARM64Operand *CreateRegOffsetMem(unsigned BaseReg, unsigned OffsetReg,
1645 ARM64_AM::ExtendType ExtType,
1646 unsigned ShiftVal, bool ExplicitShift,
1647 SMLoc S, SMLoc E, MCContext &Ctx) {
1648 ARM64Operand *Op = new ARM64Operand(k_Memory, Ctx);
1649 Op->Mem.BaseRegNum = BaseReg;
1650 Op->Mem.OffsetRegNum = OffsetReg;
1651 Op->Mem.OffsetImm = 0;
1652 Op->Mem.ExtType = ExtType;
1653 Op->Mem.ShiftVal = ShiftVal;
1654 Op->Mem.ExplicitShift = ExplicitShift;
1655 Op->Mem.Mode = RegisterOffset;
1661 static ARM64Operand *CreateSysCR(unsigned Val, SMLoc S, SMLoc E,
1663 ARM64Operand *Op = new ARM64Operand(k_SysCR, Ctx);
1664 Op->SysCRImm.Val = Val;
1670 static ARM64Operand *CreatePrefetch(unsigned Val, SMLoc S, MCContext &Ctx) {
1671 ARM64Operand *Op = new ARM64Operand(k_Prefetch, Ctx);
1672 Op->Prefetch.Val = Val;
1678 static ARM64Operand *CreateShifter(ARM64_AM::ShiftType ShOp, unsigned Val,
1679 SMLoc S, SMLoc E, MCContext &Ctx) {
1680 ARM64Operand *Op = new ARM64Operand(k_Shifter, Ctx);
1681 Op->Shifter.Val = ARM64_AM::getShifterImm(ShOp, Val);
1687 static ARM64Operand *CreateExtend(ARM64_AM::ExtendType ExtOp, unsigned Val,
1688 SMLoc S, SMLoc E, MCContext &Ctx) {
1689 ARM64Operand *Op = new ARM64Operand(k_Extend, Ctx);
1690 Op->Extend.Val = ARM64_AM::getArithExtendImm(ExtOp, Val);
1697 } // end anonymous namespace.
1699 void ARM64Operand::print(raw_ostream &OS) const {
1702 OS << "<fpimm " << getFPImm() << "(" << ARM64_AM::getFPImmFloat(getFPImm())
1707 StringRef Name = ARM64DB::DBarrierMapper().toString(getBarrier(), Valid);
1709 OS << "<barrier " << Name << ">";
1711 OS << "<barrier invalid #" << getCPSRField() << ">";
1714 case k_SystemRegister: {
1716 StringRef Name = ARM64SysReg::MRSMapper().toString(getSystemRegister(), Valid);
1718 Name = ARM64SysReg::MSRMapper().toString(getSystemRegister(), Valid);
1720 OS << "<systemreg " << Name << ">";
1722 OS << "<systemreg invalid #" << getSystemRegister() << ">";
1727 StringRef Name = ARM64PState::PStateMapper().toString(getCPSRField(), Valid);
1729 OS << "<cpsrfield " << Name << ">";
1731 OS << "<cpsrfield invalid #" << getCPSRField() << ">";
1735 getImm()->print(OS);
1741 OS << "<register " << getReg() << ">";
1743 case k_VectorList: {
1744 OS << "<vectorlist ";
1745 unsigned Reg = getVectorListStart();
1746 for (unsigned i = 0, e = getVectorListCount(); i != e; ++i)
1747 OS << Reg + i << " ";
1752 OS << "<vectorindex " << getVectorIndex() << ">";
1755 OS << "'" << getToken() << "'";
1758 OS << "c" << getSysCR();
1762 if (ARM64_AM::isNamedPrefetchOp(getPrefetch()))
1763 OS << ARM64_AM::getPrefetchOpName((ARM64_AM::PrefetchOp)getPrefetch());
1765 OS << "#" << getPrefetch();
1769 unsigned Val = getShifter();
1770 OS << "<" << ARM64_AM::getShiftName(ARM64_AM::getShiftType(Val)) << " #"
1771 << ARM64_AM::getShiftValue(Val) << ">";
1775 unsigned Val = getExtend();
1776 OS << "<" << ARM64_AM::getExtendName(ARM64_AM::getArithExtendType(Val))
1777 << " #" << ARM64_AM::getArithShiftValue(Val) << ">";
1783 /// @name Auto-generated Match Functions
1786 static unsigned MatchRegisterName(StringRef Name);
1790 static unsigned matchVectorRegName(StringRef Name) {
1791 return StringSwitch<unsigned>(Name)
1792 .Case("v0", ARM64::Q0)
1793 .Case("v1", ARM64::Q1)
1794 .Case("v2", ARM64::Q2)
1795 .Case("v3", ARM64::Q3)
1796 .Case("v4", ARM64::Q4)
1797 .Case("v5", ARM64::Q5)
1798 .Case("v6", ARM64::Q6)
1799 .Case("v7", ARM64::Q7)
1800 .Case("v8", ARM64::Q8)
1801 .Case("v9", ARM64::Q9)
1802 .Case("v10", ARM64::Q10)
1803 .Case("v11", ARM64::Q11)
1804 .Case("v12", ARM64::Q12)
1805 .Case("v13", ARM64::Q13)
1806 .Case("v14", ARM64::Q14)
1807 .Case("v15", ARM64::Q15)
1808 .Case("v16", ARM64::Q16)
1809 .Case("v17", ARM64::Q17)
1810 .Case("v18", ARM64::Q18)
1811 .Case("v19", ARM64::Q19)
1812 .Case("v20", ARM64::Q20)
1813 .Case("v21", ARM64::Q21)
1814 .Case("v22", ARM64::Q22)
1815 .Case("v23", ARM64::Q23)
1816 .Case("v24", ARM64::Q24)
1817 .Case("v25", ARM64::Q25)
1818 .Case("v26", ARM64::Q26)
1819 .Case("v27", ARM64::Q27)
1820 .Case("v28", ARM64::Q28)
1821 .Case("v29", ARM64::Q29)
1822 .Case("v30", ARM64::Q30)
1823 .Case("v31", ARM64::Q31)
1827 static bool isValidVectorKind(StringRef Name) {
1828 return StringSwitch<bool>(Name.lower())
1838 // Accept the width neutral ones, too, for verbose syntax. If those
1839 // aren't used in the right places, the token operand won't match so
1840 // all will work out.
1848 static void parseValidVectorKind(StringRef Name, unsigned &NumElements,
1849 char &ElementKind) {
1850 assert(isValidVectorKind(Name));
1852 ElementKind = Name.lower()[Name.size() - 1];
1855 if (Name.size() == 2)
1858 // Parse the lane count
1859 Name = Name.drop_front();
1860 while (isdigit(Name.front())) {
1861 NumElements = 10 * NumElements + (Name.front() - '0');
1862 Name = Name.drop_front();
1866 bool ARM64AsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
1868 StartLoc = getLoc();
1869 RegNo = tryParseRegister();
1870 EndLoc = SMLoc::getFromPointer(getLoc().getPointer() - 1);
1871 return (RegNo == (unsigned)-1);
1874 /// tryParseRegister - Try to parse a register name. The token must be an
1875 /// Identifier when called, and if it is a register name the token is eaten and
1876 /// the register is added to the operand list.
1877 int ARM64AsmParser::tryParseRegister() {
1878 const AsmToken &Tok = Parser.getTok();
1879 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1881 std::string lowerCase = Tok.getString().lower();
1882 unsigned RegNum = MatchRegisterName(lowerCase);
1883 // Also handle a few aliases of registers.
1885 RegNum = StringSwitch<unsigned>(lowerCase)
1886 .Case("x29", ARM64::FP)
1887 .Case("x30", ARM64::LR)
1888 .Case("x31", ARM64::XZR)
1889 .Case("w31", ARM64::WZR)
1895 Parser.Lex(); // Eat identifier token.
1899 /// tryMatchVectorRegister - Try to parse a vector register name with optional
1900 /// kind specifier. If it is a register specifier, eat the token and return it.
1901 int ARM64AsmParser::tryMatchVectorRegister(StringRef &Kind, bool expected) {
1902 if (Parser.getTok().isNot(AsmToken::Identifier)) {
1903 TokError("vector register expected");
1907 StringRef Name = Parser.getTok().getString();
1908 // If there is a kind specifier, it's separated from the register name by
1910 size_t Start = 0, Next = Name.find('.');
1911 StringRef Head = Name.slice(Start, Next);
1912 unsigned RegNum = matchVectorRegName(Head);
1914 if (Next != StringRef::npos) {
1915 Kind = Name.slice(Next, StringRef::npos);
1916 if (!isValidVectorKind(Kind)) {
1917 TokError("invalid vector kind qualifier");
1921 Parser.Lex(); // Eat the register token.
1926 TokError("vector register expected");
1930 static int MatchSysCRName(StringRef Name) {
1931 // Use the same layout as the tablegen'erated register name matcher. Ugly,
1933 switch (Name.size()) {
1937 if (Name[0] != 'c' && Name[0] != 'C')
1965 if ((Name[0] != 'c' && Name[0] != 'C') || Name[1] != '1')
1986 llvm_unreachable("Unhandled SysCR operand string!");
1990 /// tryParseSysCROperand - Try to parse a system instruction CR operand name.
1991 ARM64AsmParser::OperandMatchResultTy
1992 ARM64AsmParser::tryParseSysCROperand(OperandVector &Operands) {
1994 const AsmToken &Tok = Parser.getTok();
1995 if (Tok.isNot(AsmToken::Identifier))
1996 return MatchOperand_NoMatch;
1998 int Num = MatchSysCRName(Tok.getString());
2000 return MatchOperand_NoMatch;
2002 Parser.Lex(); // Eat identifier token.
2003 Operands.push_back(ARM64Operand::CreateSysCR(Num, S, getLoc(), getContext()));
2004 return MatchOperand_Success;
2007 /// tryParsePrefetch - Try to parse a prefetch operand.
2008 ARM64AsmParser::OperandMatchResultTy
2009 ARM64AsmParser::tryParsePrefetch(OperandVector &Operands) {
2011 const AsmToken &Tok = Parser.getTok();
2012 // Either an identifier for named values or a 5-bit immediate.
2013 if (Tok.is(AsmToken::Hash)) {
2014 Parser.Lex(); // Eat hash token.
2015 const MCExpr *ImmVal;
2016 if (getParser().parseExpression(ImmVal))
2017 return MatchOperand_ParseFail;
2019 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2021 TokError("immediate value expected for prefetch operand");
2022 return MatchOperand_ParseFail;
2024 unsigned prfop = MCE->getValue();
2026 TokError("prefetch operand out of range, [0,31] expected");
2027 return MatchOperand_ParseFail;
2030 Operands.push_back(ARM64Operand::CreatePrefetch(prfop, S, getContext()));
2031 return MatchOperand_Success;
2034 if (Tok.isNot(AsmToken::Identifier)) {
2035 TokError("pre-fetch hint expected");
2036 return MatchOperand_ParseFail;
2039 unsigned prfop = StringSwitch<unsigned>(Tok.getString())
2040 .Case("pldl1keep", ARM64_AM::PLDL1KEEP)
2041 .Case("pldl1strm", ARM64_AM::PLDL1STRM)
2042 .Case("pldl2keep", ARM64_AM::PLDL2KEEP)
2043 .Case("pldl2strm", ARM64_AM::PLDL2STRM)
2044 .Case("pldl3keep", ARM64_AM::PLDL3KEEP)
2045 .Case("pldl3strm", ARM64_AM::PLDL3STRM)
2046 .Case("pstl1keep", ARM64_AM::PSTL1KEEP)
2047 .Case("pstl1strm", ARM64_AM::PSTL1STRM)
2048 .Case("pstl2keep", ARM64_AM::PSTL2KEEP)
2049 .Case("pstl2strm", ARM64_AM::PSTL2STRM)
2050 .Case("pstl3keep", ARM64_AM::PSTL3KEEP)
2051 .Case("pstl3strm", ARM64_AM::PSTL3STRM)
2053 if (prfop == 0xff) {
2054 TokError("pre-fetch hint expected");
2055 return MatchOperand_ParseFail;
2058 Parser.Lex(); // Eat identifier token.
2059 Operands.push_back(ARM64Operand::CreatePrefetch(prfop, S, getContext()));
2060 return MatchOperand_Success;
2063 /// tryParseAdrpLabel - Parse and validate a source label for the ADRP
2065 ARM64AsmParser::OperandMatchResultTy
2066 ARM64AsmParser::tryParseAdrpLabel(OperandVector &Operands) {
2069 if (parseSymbolicImmVal(Expr))
2070 return MatchOperand_ParseFail;
2072 ARM64MCExpr::VariantKind ELFRefKind;
2073 MCSymbolRefExpr::VariantKind DarwinRefKind;
2074 const MCConstantExpr *Addend;
2075 if (!classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
2076 Error(S, "modified label reference + constant expected");
2077 return MatchOperand_ParseFail;
2080 if (DarwinRefKind == MCSymbolRefExpr::VK_None &&
2081 ELFRefKind == ARM64MCExpr::VK_INVALID) {
2082 // No modifier was specified at all; this is the syntax for an ELF basic
2083 // ADRP relocation (unfortunately).
2084 Expr = ARM64MCExpr::Create(Expr, ARM64MCExpr::VK_ABS_PAGE, getContext());
2085 } else if ((DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGE ||
2086 DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGE) &&
2088 Error(S, "gotpage label reference not allowed an addend");
2089 return MatchOperand_ParseFail;
2090 } else if (DarwinRefKind != MCSymbolRefExpr::VK_PAGE &&
2091 DarwinRefKind != MCSymbolRefExpr::VK_GOTPAGE &&
2092 DarwinRefKind != MCSymbolRefExpr::VK_TLVPPAGE &&
2093 ELFRefKind != ARM64MCExpr::VK_GOT_PAGE &&
2094 ELFRefKind != ARM64MCExpr::VK_GOTTPREL_PAGE &&
2095 ELFRefKind != ARM64MCExpr::VK_TLSDESC_PAGE) {
2096 // The operand must be an @page or @gotpage qualified symbolref.
2097 Error(S, "page or gotpage label reference expected");
2098 return MatchOperand_ParseFail;
2101 // We have a label reference possibly with addend. The addend is a raw value
2102 // here. The linker will adjust it to only reference the page.
2103 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2104 Operands.push_back(ARM64Operand::CreateImm(Expr, S, E, getContext()));
2106 return MatchOperand_Success;
2109 /// tryParseAdrLabel - Parse and validate a source label for the ADR
2111 ARM64AsmParser::OperandMatchResultTy
2112 ARM64AsmParser::tryParseAdrLabel(OperandVector &Operands) {
2115 if (getParser().parseExpression(Expr))
2116 return MatchOperand_ParseFail;
2118 // The operand must be an un-qualified assembler local symbolref.
2119 // FIXME: wrong for ELF.
2120 if (const MCSymbolRefExpr *SRE = dyn_cast<const MCSymbolRefExpr>(Expr)) {
2121 // FIXME: Should reference the MachineAsmInfo to get the private prefix.
2122 bool isTemporary = SRE->getSymbol().getName().startswith("L");
2123 if (!isTemporary || SRE->getKind() != MCSymbolRefExpr::VK_None) {
2124 Error(S, "unqualified, assembler-local label name expected");
2125 return MatchOperand_ParseFail;
2129 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2130 Operands.push_back(ARM64Operand::CreateImm(Expr, S, E, getContext()));
2132 return MatchOperand_Success;
2135 /// tryParseFPImm - A floating point immediate expression operand.
2136 ARM64AsmParser::OperandMatchResultTy
2137 ARM64AsmParser::tryParseFPImm(OperandVector &Operands) {
2140 if (Parser.getTok().isNot(AsmToken::Hash))
2141 return MatchOperand_NoMatch;
2142 Parser.Lex(); // Eat the '#'.
2144 // Handle negation, as that still comes through as a separate token.
2145 bool isNegative = false;
2146 if (Parser.getTok().is(AsmToken::Minus)) {
2150 const AsmToken &Tok = Parser.getTok();
2151 if (Tok.is(AsmToken::Real)) {
2152 APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
2153 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
2154 // If we had a '-' in front, toggle the sign bit.
2155 IntVal ^= (uint64_t)isNegative << 63;
2156 int Val = ARM64_AM::getFP64Imm(APInt(64, IntVal));
2157 Parser.Lex(); // Eat the token.
2158 // Check for out of range values. As an exception, we let Zero through,
2159 // as we handle that special case in post-processing before matching in
2160 // order to use the zero register for it.
2161 if (Val == -1 && !RealVal.isZero()) {
2162 TokError("floating point value out of range");
2163 return MatchOperand_ParseFail;
2165 Operands.push_back(ARM64Operand::CreateFPImm(Val, S, getContext()));
2166 return MatchOperand_Success;
2168 if (Tok.is(AsmToken::Integer)) {
2170 if (!isNegative && Tok.getString().startswith("0x")) {
2171 Val = Tok.getIntVal();
2172 if (Val > 255 || Val < 0) {
2173 TokError("encoded floating point value out of range");
2174 return MatchOperand_ParseFail;
2177 APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
2178 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
2179 // If we had a '-' in front, toggle the sign bit.
2180 IntVal ^= (uint64_t)isNegative << 63;
2181 Val = ARM64_AM::getFP64Imm(APInt(64, IntVal));
2183 Parser.Lex(); // Eat the token.
2184 Operands.push_back(ARM64Operand::CreateFPImm(Val, S, getContext()));
2185 return MatchOperand_Success;
2188 TokError("invalid floating point immediate");
2189 return MatchOperand_ParseFail;
2192 /// parseCondCodeString - Parse a Condition Code string.
2193 unsigned ARM64AsmParser::parseCondCodeString(StringRef Cond) {
2194 unsigned CC = StringSwitch<unsigned>(Cond.lower())
2195 .Case("eq", ARM64CC::EQ)
2196 .Case("ne", ARM64CC::NE)
2197 .Case("cs", ARM64CC::CS)
2198 .Case("hs", ARM64CC::CS)
2199 .Case("cc", ARM64CC::CC)
2200 .Case("lo", ARM64CC::CC)
2201 .Case("mi", ARM64CC::MI)
2202 .Case("pl", ARM64CC::PL)
2203 .Case("vs", ARM64CC::VS)
2204 .Case("vc", ARM64CC::VC)
2205 .Case("hi", ARM64CC::HI)
2206 .Case("ls", ARM64CC::LS)
2207 .Case("ge", ARM64CC::GE)
2208 .Case("lt", ARM64CC::LT)
2209 .Case("gt", ARM64CC::GT)
2210 .Case("le", ARM64CC::LE)
2211 .Case("al", ARM64CC::AL)
2212 .Case("nv", ARM64CC::NV)
2213 .Default(ARM64CC::Invalid);
2217 /// parseCondCode - Parse a Condition Code operand.
2218 bool ARM64AsmParser::parseCondCode(OperandVector &Operands,
2219 bool invertCondCode) {
2221 const AsmToken &Tok = Parser.getTok();
2222 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2224 StringRef Cond = Tok.getString();
2225 unsigned CC = parseCondCodeString(Cond);
2226 if (CC == ARM64CC::Invalid)
2227 return TokError("invalid condition code");
2228 Parser.Lex(); // Eat identifier token.
2231 CC = ARM64CC::getInvertedCondCode(ARM64CC::CondCode(CC));
2233 const MCExpr *CCExpr = MCConstantExpr::Create(CC, getContext());
2235 ARM64Operand::CreateImm(CCExpr, S, getLoc(), getContext()));
2239 /// ParseOptionalShift - Some operands take an optional shift argument. Parse
2240 /// them if present.
2241 bool ARM64AsmParser::parseOptionalShift(OperandVector &Operands) {
2242 const AsmToken &Tok = Parser.getTok();
2243 ARM64_AM::ShiftType ShOp = StringSwitch<ARM64_AM::ShiftType>(Tok.getString())
2244 .Case("lsl", ARM64_AM::LSL)
2245 .Case("lsr", ARM64_AM::LSR)
2246 .Case("asr", ARM64_AM::ASR)
2247 .Case("ror", ARM64_AM::ROR)
2248 .Case("msl", ARM64_AM::MSL)
2249 .Case("LSL", ARM64_AM::LSL)
2250 .Case("LSR", ARM64_AM::LSR)
2251 .Case("ASR", ARM64_AM::ASR)
2252 .Case("ROR", ARM64_AM::ROR)
2253 .Case("MSL", ARM64_AM::MSL)
2254 .Default(ARM64_AM::InvalidShift);
2255 if (ShOp == ARM64_AM::InvalidShift)
2258 SMLoc S = Tok.getLoc();
2261 // We expect a number here.
2262 if (getLexer().isNot(AsmToken::Hash))
2263 return TokError("immediate value expected for shifter operand");
2264 Parser.Lex(); // Eat the '#'.
2266 SMLoc ExprLoc = getLoc();
2267 const MCExpr *ImmVal;
2268 if (getParser().parseExpression(ImmVal))
2271 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2273 return TokError("immediate value expected for shifter operand");
2275 if ((MCE->getValue() & 0x3f) != MCE->getValue())
2276 return Error(ExprLoc, "immediate value too large for shifter operand");
2278 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2280 ARM64Operand::CreateShifter(ShOp, MCE->getValue(), S, E, getContext()));
2284 /// parseOptionalExtend - Some operands take an optional extend argument. Parse
2285 /// them if present.
2286 bool ARM64AsmParser::parseOptionalExtend(OperandVector &Operands) {
2287 const AsmToken &Tok = Parser.getTok();
2288 ARM64_AM::ExtendType ExtOp =
2289 StringSwitch<ARM64_AM::ExtendType>(Tok.getString())
2290 .Case("uxtb", ARM64_AM::UXTB)
2291 .Case("uxth", ARM64_AM::UXTH)
2292 .Case("uxtw", ARM64_AM::UXTW)
2293 .Case("uxtx", ARM64_AM::UXTX)
2294 .Case("lsl", ARM64_AM::UXTX) // Alias for UXTX
2295 .Case("sxtb", ARM64_AM::SXTB)
2296 .Case("sxth", ARM64_AM::SXTH)
2297 .Case("sxtw", ARM64_AM::SXTW)
2298 .Case("sxtx", ARM64_AM::SXTX)
2299 .Case("UXTB", ARM64_AM::UXTB)
2300 .Case("UXTH", ARM64_AM::UXTH)
2301 .Case("UXTW", ARM64_AM::UXTW)
2302 .Case("UXTX", ARM64_AM::UXTX)
2303 .Case("LSL", ARM64_AM::UXTX) // Alias for UXTX
2304 .Case("SXTB", ARM64_AM::SXTB)
2305 .Case("SXTH", ARM64_AM::SXTH)
2306 .Case("SXTW", ARM64_AM::SXTW)
2307 .Case("SXTX", ARM64_AM::SXTX)
2308 .Default(ARM64_AM::InvalidExtend);
2309 if (ExtOp == ARM64_AM::InvalidExtend)
2312 SMLoc S = Tok.getLoc();
2315 if (getLexer().is(AsmToken::EndOfStatement) ||
2316 getLexer().is(AsmToken::Comma)) {
2317 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2319 ARM64Operand::CreateExtend(ExtOp, 0, S, E, getContext()));
2323 if (getLexer().isNot(AsmToken::Hash)) {
2324 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2326 ARM64Operand::CreateExtend(ExtOp, 0, S, E, getContext()));
2330 Parser.Lex(); // Eat the '#'.
2332 const MCExpr *ImmVal;
2333 if (getParser().parseExpression(ImmVal))
2336 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2338 return TokError("immediate value expected for extend operand");
2340 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2342 ARM64Operand::CreateExtend(ExtOp, MCE->getValue(), S, E, getContext()));
2346 /// parseSysAlias - The IC, DC, AT, and TLBI instructions are simple aliases for
2347 /// the SYS instruction. Parse them specially so that we create a SYS MCInst.
2348 bool ARM64AsmParser::parseSysAlias(StringRef Name, SMLoc NameLoc,
2349 OperandVector &Operands) {
2350 if (Name.find('.') != StringRef::npos)
2351 return TokError("invalid operand");
2355 ARM64Operand::CreateToken("sys", false, NameLoc, getContext()));
2357 const AsmToken &Tok = Parser.getTok();
2358 StringRef Op = Tok.getString();
2359 SMLoc S = Tok.getLoc();
2361 const MCExpr *Expr = 0;
2363 #define SYS_ALIAS(op1, Cn, Cm, op2) \
2365 Expr = MCConstantExpr::Create(op1, getContext()); \
2366 Operands.push_back( \
2367 ARM64Operand::CreateImm(Expr, S, getLoc(), getContext())); \
2368 Operands.push_back( \
2369 ARM64Operand::CreateSysCR(Cn, S, getLoc(), getContext())); \
2370 Operands.push_back( \
2371 ARM64Operand::CreateSysCR(Cm, S, getLoc(), getContext())); \
2372 Expr = MCConstantExpr::Create(op2, getContext()); \
2373 Operands.push_back( \
2374 ARM64Operand::CreateImm(Expr, S, getLoc(), getContext())); \
2377 if (Mnemonic == "ic") {
2378 if (!Op.compare_lower("ialluis")) {
2379 // SYS #0, C7, C1, #0
2380 SYS_ALIAS(0, 7, 1, 0);
2381 } else if (!Op.compare_lower("iallu")) {
2382 // SYS #0, C7, C5, #0
2383 SYS_ALIAS(0, 7, 5, 0);
2384 } else if (!Op.compare_lower("ivau")) {
2385 // SYS #3, C7, C5, #1
2386 SYS_ALIAS(3, 7, 5, 1);
2388 return TokError("invalid operand for IC instruction");
2390 } else if (Mnemonic == "dc") {
2391 if (!Op.compare_lower("zva")) {
2392 // SYS #3, C7, C4, #1
2393 SYS_ALIAS(3, 7, 4, 1);
2394 } else if (!Op.compare_lower("ivac")) {
2395 // SYS #3, C7, C6, #1
2396 SYS_ALIAS(0, 7, 6, 1);
2397 } else if (!Op.compare_lower("isw")) {
2398 // SYS #0, C7, C6, #2
2399 SYS_ALIAS(0, 7, 6, 2);
2400 } else if (!Op.compare_lower("cvac")) {
2401 // SYS #3, C7, C10, #1
2402 SYS_ALIAS(3, 7, 10, 1);
2403 } else if (!Op.compare_lower("csw")) {
2404 // SYS #0, C7, C10, #2
2405 SYS_ALIAS(0, 7, 10, 2);
2406 } else if (!Op.compare_lower("cvau")) {
2407 // SYS #3, C7, C11, #1
2408 SYS_ALIAS(3, 7, 11, 1);
2409 } else if (!Op.compare_lower("civac")) {
2410 // SYS #3, C7, C14, #1
2411 SYS_ALIAS(3, 7, 14, 1);
2412 } else if (!Op.compare_lower("cisw")) {
2413 // SYS #0, C7, C14, #2
2414 SYS_ALIAS(0, 7, 14, 2);
2416 return TokError("invalid operand for DC instruction");
2418 } else if (Mnemonic == "at") {
2419 if (!Op.compare_lower("s1e1r")) {
2420 // SYS #0, C7, C8, #0
2421 SYS_ALIAS(0, 7, 8, 0);
2422 } else if (!Op.compare_lower("s1e2r")) {
2423 // SYS #4, C7, C8, #0
2424 SYS_ALIAS(4, 7, 8, 0);
2425 } else if (!Op.compare_lower("s1e3r")) {
2426 // SYS #6, C7, C8, #0
2427 SYS_ALIAS(6, 7, 8, 0);
2428 } else if (!Op.compare_lower("s1e1w")) {
2429 // SYS #0, C7, C8, #1
2430 SYS_ALIAS(0, 7, 8, 1);
2431 } else if (!Op.compare_lower("s1e2w")) {
2432 // SYS #4, C7, C8, #1
2433 SYS_ALIAS(4, 7, 8, 1);
2434 } else if (!Op.compare_lower("s1e3w")) {
2435 // SYS #6, C7, C8, #1
2436 SYS_ALIAS(6, 7, 8, 1);
2437 } else if (!Op.compare_lower("s1e0r")) {
2438 // SYS #0, C7, C8, #3
2439 SYS_ALIAS(0, 7, 8, 2);
2440 } else if (!Op.compare_lower("s1e0w")) {
2441 // SYS #0, C7, C8, #3
2442 SYS_ALIAS(0, 7, 8, 3);
2443 } else if (!Op.compare_lower("s12e1r")) {
2444 // SYS #4, C7, C8, #4
2445 SYS_ALIAS(4, 7, 8, 4);
2446 } else if (!Op.compare_lower("s12e1w")) {
2447 // SYS #4, C7, C8, #5
2448 SYS_ALIAS(4, 7, 8, 5);
2449 } else if (!Op.compare_lower("s12e0r")) {
2450 // SYS #4, C7, C8, #6
2451 SYS_ALIAS(4, 7, 8, 6);
2452 } else if (!Op.compare_lower("s12e0w")) {
2453 // SYS #4, C7, C8, #7
2454 SYS_ALIAS(4, 7, 8, 7);
2456 return TokError("invalid operand for AT instruction");
2458 } else if (Mnemonic == "tlbi") {
2459 if (!Op.compare_lower("vmalle1is")) {
2460 // SYS #0, C8, C3, #0
2461 SYS_ALIAS(0, 8, 3, 0);
2462 } else if (!Op.compare_lower("alle2is")) {
2463 // SYS #4, C8, C3, #0
2464 SYS_ALIAS(4, 8, 3, 0);
2465 } else if (!Op.compare_lower("alle3is")) {
2466 // SYS #6, C8, C3, #0
2467 SYS_ALIAS(6, 8, 3, 0);
2468 } else if (!Op.compare_lower("vae1is")) {
2469 // SYS #0, C8, C3, #1
2470 SYS_ALIAS(0, 8, 3, 1);
2471 } else if (!Op.compare_lower("vae2is")) {
2472 // SYS #4, C8, C3, #1
2473 SYS_ALIAS(4, 8, 3, 1);
2474 } else if (!Op.compare_lower("vae3is")) {
2475 // SYS #6, C8, C3, #1
2476 SYS_ALIAS(6, 8, 3, 1);
2477 } else if (!Op.compare_lower("aside1is")) {
2478 // SYS #0, C8, C3, #2
2479 SYS_ALIAS(0, 8, 3, 2);
2480 } else if (!Op.compare_lower("vaae1is")) {
2481 // SYS #0, C8, C3, #3
2482 SYS_ALIAS(0, 8, 3, 3);
2483 } else if (!Op.compare_lower("alle1is")) {
2484 // SYS #4, C8, C3, #4
2485 SYS_ALIAS(4, 8, 3, 4);
2486 } else if (!Op.compare_lower("vale1is")) {
2487 // SYS #0, C8, C3, #5
2488 SYS_ALIAS(0, 8, 3, 5);
2489 } else if (!Op.compare_lower("vaale1is")) {
2490 // SYS #0, C8, C3, #7
2491 SYS_ALIAS(0, 8, 3, 7);
2492 } else if (!Op.compare_lower("vmalle1")) {
2493 // SYS #0, C8, C7, #0
2494 SYS_ALIAS(0, 8, 7, 0);
2495 } else if (!Op.compare_lower("alle2")) {
2496 // SYS #4, C8, C7, #0
2497 SYS_ALIAS(4, 8, 7, 0);
2498 } else if (!Op.compare_lower("vale2is")) {
2499 // SYS #4, C8, C3, #5
2500 SYS_ALIAS(4, 8, 3, 5);
2501 } else if (!Op.compare_lower("vale3is")) {
2502 // SYS #6, C8, C3, #5
2503 SYS_ALIAS(6, 8, 3, 5);
2504 } else if (!Op.compare_lower("alle3")) {
2505 // SYS #6, C8, C7, #0
2506 SYS_ALIAS(6, 8, 7, 0);
2507 } else if (!Op.compare_lower("vae1")) {
2508 // SYS #0, C8, C7, #1
2509 SYS_ALIAS(0, 8, 7, 1);
2510 } else if (!Op.compare_lower("vae2")) {
2511 // SYS #4, C8, C7, #1
2512 SYS_ALIAS(4, 8, 7, 1);
2513 } else if (!Op.compare_lower("vae3")) {
2514 // SYS #6, C8, C7, #1
2515 SYS_ALIAS(6, 8, 7, 1);
2516 } else if (!Op.compare_lower("aside1")) {
2517 // SYS #0, C8, C7, #2
2518 SYS_ALIAS(0, 8, 7, 2);
2519 } else if (!Op.compare_lower("vaae1")) {
2520 // SYS #0, C8, C7, #3
2521 SYS_ALIAS(0, 8, 7, 3);
2522 } else if (!Op.compare_lower("alle1")) {
2523 // SYS #4, C8, C7, #4
2524 SYS_ALIAS(4, 8, 7, 4);
2525 } else if (!Op.compare_lower("vale1")) {
2526 // SYS #0, C8, C7, #5
2527 SYS_ALIAS(0, 8, 7, 5);
2528 } else if (!Op.compare_lower("vale2")) {
2529 // SYS #4, C8, C7, #5
2530 SYS_ALIAS(4, 8, 7, 5);
2531 } else if (!Op.compare_lower("vale3")) {
2532 // SYS #6, C8, C7, #5
2533 SYS_ALIAS(6, 8, 7, 5);
2534 } else if (!Op.compare_lower("vaale1")) {
2535 // SYS #0, C8, C7, #7
2536 SYS_ALIAS(0, 8, 7, 7);
2537 } else if (!Op.compare_lower("ipas2e1")) {
2538 // SYS #4, C8, C4, #1
2539 SYS_ALIAS(4, 8, 4, 1);
2540 } else if (!Op.compare_lower("ipas2le1")) {
2541 // SYS #4, C8, C4, #5
2542 SYS_ALIAS(4, 8, 4, 5);
2543 } else if (!Op.compare_lower("vmalls12e1")) {
2544 // SYS #4, C8, C7, #6
2545 SYS_ALIAS(4, 8, 7, 6);
2546 } else if (!Op.compare_lower("vmalls12e1is")) {
2547 // SYS #4, C8, C3, #6
2548 SYS_ALIAS(4, 8, 3, 6);
2550 return TokError("invalid operand for TLBI instruction");
2556 Parser.Lex(); // Eat operand.
2558 // Check for the optional register operand.
2559 if (getLexer().is(AsmToken::Comma)) {
2560 Parser.Lex(); // Eat comma.
2562 if (Tok.isNot(AsmToken::Identifier) || parseRegister(Operands))
2563 return TokError("expected register operand");
2566 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2567 Parser.eatToEndOfStatement();
2568 return TokError("unexpected token in argument list");
2571 Parser.Lex(); // Consume the EndOfStatement
2575 ARM64AsmParser::OperandMatchResultTy
2576 ARM64AsmParser::tryParseBarrierOperand(OperandVector &Operands) {
2577 const AsmToken &Tok = Parser.getTok();
2579 // Can be either a #imm style literal or an option name
2580 if (Tok.is(AsmToken::Hash)) {
2581 // Immediate operand.
2582 Parser.Lex(); // Eat the '#'
2583 const MCExpr *ImmVal;
2584 SMLoc ExprLoc = getLoc();
2585 if (getParser().parseExpression(ImmVal))
2586 return MatchOperand_ParseFail;
2587 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2589 Error(ExprLoc, "immediate value expected for barrier operand");
2590 return MatchOperand_ParseFail;
2592 if (MCE->getValue() < 0 || MCE->getValue() > 15) {
2593 Error(ExprLoc, "barrier operand out of range");
2594 return MatchOperand_ParseFail;
2597 ARM64Operand::CreateBarrier(MCE->getValue(), ExprLoc, getContext()));
2598 return MatchOperand_Success;
2601 if (Tok.isNot(AsmToken::Identifier)) {
2602 TokError("invalid operand for instruction");
2603 return MatchOperand_ParseFail;
2607 unsigned Opt = ARM64DB::DBarrierMapper().fromString(Tok.getString(), Valid);
2609 TokError("invalid barrier option name");
2610 return MatchOperand_ParseFail;
2613 // The only valid named option for ISB is 'sy'
2614 if (Mnemonic == "isb" && Opt != ARM64DB::SY) {
2615 TokError("'sy' or #imm operand expected");
2616 return MatchOperand_ParseFail;
2619 Operands.push_back(ARM64Operand::CreateBarrier(Opt, getLoc(), getContext()));
2620 Parser.Lex(); // Consume the option
2622 return MatchOperand_Success;
2625 ARM64AsmParser::OperandMatchResultTy
2626 ARM64AsmParser::tryParseMRSSystemRegister(OperandVector &Operands) {
2627 const AsmToken &Tok = Parser.getTok();
2629 if (Tok.isNot(AsmToken::Identifier))
2630 return MatchOperand_NoMatch;
2633 auto Mapper = ARM64SysReg::MRSMapper();
2634 uint32_t Reg = Mapper.fromString(Tok.getString(), Valid);
2638 ARM64Operand::CreateSystemRegister((uint16_t)Reg, getLoc(),
2640 Parser.Lex(); // Consume the register name.
2641 return MatchOperand_Success;
2644 return MatchOperand_NoMatch;
2647 ARM64AsmParser::OperandMatchResultTy
2648 ARM64AsmParser::tryParseMSRSystemRegister(OperandVector &Operands) {
2649 const AsmToken &Tok = Parser.getTok();
2651 if (Tok.isNot(AsmToken::Identifier))
2652 return MatchOperand_NoMatch;
2655 auto Mapper = ARM64SysReg::MSRMapper();
2656 uint32_t Reg = Mapper.fromString(Tok.getString(), Valid);
2660 ARM64Operand::CreateSystemRegister((uint16_t)Reg, getLoc(),
2662 Parser.Lex(); // Consume the register name.
2663 return MatchOperand_Success;
2666 return MatchOperand_NoMatch;
2669 ARM64AsmParser::OperandMatchResultTy
2670 ARM64AsmParser::tryParseCPSRField(OperandVector &Operands) {
2671 const AsmToken &Tok = Parser.getTok();
2673 if (Tok.isNot(AsmToken::Identifier))
2674 return MatchOperand_NoMatch;
2677 ARM64PState::PStateValues Field = (ARM64PState::PStateValues)
2678 ARM64PState::PStateMapper().fromString(Tok.getString(), Valid);
2681 return MatchOperand_NoMatch;
2683 ARM64Operand::CreateCPSRField(Field, getLoc(), getContext()));
2684 Parser.Lex(); // Consume the register name.
2686 return MatchOperand_Success;
2689 /// tryParseVectorRegister - Parse a vector register operand.
2690 bool ARM64AsmParser::tryParseVectorRegister(OperandVector &Operands) {
2691 if (Parser.getTok().isNot(AsmToken::Identifier))
2695 // Check for a vector register specifier first.
2697 int64_t Reg = tryMatchVectorRegister(Kind, false);
2701 ARM64Operand::CreateReg(Reg, true, S, getLoc(), getContext()));
2702 // If there was an explicit qualifier, that goes on as a literal text
2705 Operands.push_back(ARM64Operand::CreateToken(Kind, false, S, getContext()));
2707 // If there is an index specifier following the register, parse that too.
2708 if (Parser.getTok().is(AsmToken::LBrac)) {
2709 SMLoc SIdx = getLoc();
2710 Parser.Lex(); // Eat left bracket token.
2712 const MCExpr *ImmVal;
2713 if (getParser().parseExpression(ImmVal))
2715 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2717 TokError("immediate value expected for vector index");
2722 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2723 Error(E, "']' expected");
2727 Parser.Lex(); // Eat right bracket token.
2729 Operands.push_back(ARM64Operand::CreateVectorIndex(MCE->getValue(), SIdx, E,
2736 /// parseRegister - Parse a non-vector register operand.
2737 bool ARM64AsmParser::parseRegister(OperandVector &Operands) {
2739 // Try for a vector register.
2740 if (!tryParseVectorRegister(Operands))
2743 // Try for a scalar register.
2744 int64_t Reg = tryParseRegister();
2748 ARM64Operand::CreateReg(Reg, false, S, getLoc(), getContext()));
2750 // A small number of instructions (FMOVXDhighr, for example) have "[1]"
2751 // as a string token in the instruction itself.
2752 if (getLexer().getKind() == AsmToken::LBrac) {
2753 SMLoc LBracS = getLoc();
2755 const AsmToken &Tok = Parser.getTok();
2756 if (Tok.is(AsmToken::Integer)) {
2757 SMLoc IntS = getLoc();
2758 int64_t Val = Tok.getIntVal();
2761 if (getLexer().getKind() == AsmToken::RBrac) {
2762 SMLoc RBracS = getLoc();
2765 ARM64Operand::CreateToken("[", false, LBracS, getContext()));
2767 ARM64Operand::CreateToken("1", false, IntS, getContext()));
2769 ARM64Operand::CreateToken("]", false, RBracS, getContext()));
2779 /// tryParseNoIndexMemory - Custom parser method for memory operands that
2780 /// do not allow base regisrer writeback modes,
2781 /// or those that handle writeback separately from
2782 /// the memory operand (like the AdvSIMD ldX/stX
2784 ARM64AsmParser::OperandMatchResultTy
2785 ARM64AsmParser::tryParseNoIndexMemory(OperandVector &Operands) {
2786 if (Parser.getTok().isNot(AsmToken::LBrac))
2787 return MatchOperand_NoMatch;
2789 Parser.Lex(); // Eat left bracket token.
2791 const AsmToken &BaseRegTok = Parser.getTok();
2792 if (BaseRegTok.isNot(AsmToken::Identifier)) {
2793 Error(BaseRegTok.getLoc(), "register expected");
2794 return MatchOperand_ParseFail;
2797 int64_t Reg = tryParseRegister();
2799 Error(BaseRegTok.getLoc(), "register expected");
2800 return MatchOperand_ParseFail;
2804 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2805 Error(E, "']' expected");
2806 return MatchOperand_ParseFail;
2809 Parser.Lex(); // Eat right bracket token.
2811 Operands.push_back(ARM64Operand::CreateMem(Reg, 0, S, E, E, getContext()));
2812 return MatchOperand_Success;
2815 /// parseMemory - Parse a memory operand for a basic load/store instruction.
2816 bool ARM64AsmParser::parseMemory(OperandVector &Operands) {
2817 assert(Parser.getTok().is(AsmToken::LBrac) && "Token is not a Left Bracket");
2819 Parser.Lex(); // Eat left bracket token.
2821 const AsmToken &BaseRegTok = Parser.getTok();
2822 if (BaseRegTok.isNot(AsmToken::Identifier))
2823 return Error(BaseRegTok.getLoc(), "register expected");
2825 int64_t Reg = tryParseRegister();
2827 return Error(BaseRegTok.getLoc(), "register expected");
2829 // If there is an offset expression, parse it.
2830 const MCExpr *OffsetExpr = 0;
2832 if (Parser.getTok().is(AsmToken::Comma)) {
2833 Parser.Lex(); // Eat the comma.
2834 OffsetLoc = getLoc();
2837 const AsmToken &OffsetRegTok = Parser.getTok();
2838 int Reg2 = OffsetRegTok.is(AsmToken::Identifier) ? tryParseRegister() : -1;
2840 // Default shift is LSL, with an omitted shift. We use the third bit of
2841 // the extend value to indicate presence/omission of the immediate offset.
2842 ARM64_AM::ExtendType ExtOp = ARM64_AM::UXTX;
2843 int64_t ShiftVal = 0;
2844 bool ExplicitShift = false;
2846 if (Parser.getTok().is(AsmToken::Comma)) {
2847 // Embedded extend operand.
2848 Parser.Lex(); // Eat the comma
2850 SMLoc ExtLoc = getLoc();
2851 const AsmToken &Tok = Parser.getTok();
2852 ExtOp = StringSwitch<ARM64_AM::ExtendType>(Tok.getString())
2853 .Case("uxtw", ARM64_AM::UXTW)
2854 .Case("lsl", ARM64_AM::UXTX) // Alias for UXTX
2855 .Case("sxtw", ARM64_AM::SXTW)
2856 .Case("sxtx", ARM64_AM::SXTX)
2857 .Case("UXTW", ARM64_AM::UXTW)
2858 .Case("LSL", ARM64_AM::UXTX) // Alias for UXTX
2859 .Case("SXTW", ARM64_AM::SXTW)
2860 .Case("SXTX", ARM64_AM::SXTX)
2861 .Default(ARM64_AM::InvalidExtend);
2862 if (ExtOp == ARM64_AM::InvalidExtend)
2863 return Error(ExtLoc, "expected valid extend operation");
2865 Parser.Lex(); // Eat the extend op.
2867 if (getLexer().is(AsmToken::RBrac)) {
2868 // No immediate operand.
2869 if (ExtOp == ARM64_AM::UXTX)
2870 return Error(ExtLoc, "LSL extend requires immediate operand");
2871 } else if (getLexer().is(AsmToken::Hash)) {
2872 // Immediate operand.
2873 Parser.Lex(); // Eat the '#'
2874 const MCExpr *ImmVal;
2875 SMLoc ExprLoc = getLoc();
2876 if (getParser().parseExpression(ImmVal))
2878 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2880 return TokError("immediate value expected for extend operand");
2882 ExplicitShift = true;
2883 ShiftVal = MCE->getValue();
2884 if (ShiftVal < 0 || ShiftVal > 4)
2885 return Error(ExprLoc, "immediate operand out of range");
2887 return Error(getLoc(), "expected immediate operand");
2890 if (Parser.getTok().isNot(AsmToken::RBrac))
2891 return Error(getLoc(), "']' expected");
2893 Parser.Lex(); // Eat right bracket token.
2896 Operands.push_back(ARM64Operand::CreateRegOffsetMem(
2897 Reg, Reg2, ExtOp, ShiftVal, ExplicitShift, S, E, getContext()));
2900 // Immediate expressions.
2901 } else if (Parser.getTok().is(AsmToken::Hash)) {
2902 Parser.Lex(); // Eat hash token.
2904 if (parseSymbolicImmVal(OffsetExpr))
2907 // FIXME: We really should make sure that we're dealing with a LDR/STR
2908 // instruction that can legally have a symbolic expression here.
2909 // Symbol reference.
2910 if (Parser.getTok().isNot(AsmToken::Identifier) &&
2911 Parser.getTok().isNot(AsmToken::String))
2912 return Error(getLoc(), "identifier or immediate expression expected");
2913 if (getParser().parseExpression(OffsetExpr))
2915 // If this is a plain ref, Make sure a legal variant kind was specified.
2916 // Otherwise, it's a more complicated expression and we have to just
2917 // assume it's OK and let the relocation stuff puke if it's not.
2918 ARM64MCExpr::VariantKind ELFRefKind;
2919 MCSymbolRefExpr::VariantKind DarwinRefKind;
2920 const MCConstantExpr *Addend;
2921 if (classifySymbolRef(OffsetExpr, ELFRefKind, DarwinRefKind, Addend) &&
2923 assert(ELFRefKind == ARM64MCExpr::VK_INVALID &&
2924 "ELF symbol modifiers not supported here yet");
2926 switch (DarwinRefKind) {
2928 return Error(getLoc(), "expected @pageoff or @gotpageoff modifier");
2929 case MCSymbolRefExpr::VK_GOTPAGEOFF:
2930 case MCSymbolRefExpr::VK_PAGEOFF:
2931 case MCSymbolRefExpr::VK_TLVPPAGEOFF:
2932 // These are what we're expecting.
2940 if (Parser.getTok().isNot(AsmToken::RBrac))
2941 return Error(E, "']' expected");
2943 Parser.Lex(); // Eat right bracket token.
2945 // Create the memory operand.
2947 ARM64Operand::CreateMem(Reg, OffsetExpr, S, E, OffsetLoc, getContext()));
2949 // Check for a '!', indicating pre-indexed addressing with writeback.
2950 if (Parser.getTok().is(AsmToken::Exclaim)) {
2951 // There needs to have been an immediate or wback doesn't make sense.
2953 return Error(E, "missing offset for pre-indexed addressing");
2954 // Pre-indexed with writeback must have a constant expression for the
2955 // offset. FIXME: Theoretically, we'd like to allow fixups so long
2956 // as they don't require a relocation.
2957 if (!isa<MCConstantExpr>(OffsetExpr))
2958 return Error(OffsetLoc, "constant immediate expression expected");
2960 // Create the Token operand for the '!'.
2961 Operands.push_back(ARM64Operand::CreateToken(
2962 "!", false, Parser.getTok().getLoc(), getContext()));
2963 Parser.Lex(); // Eat the '!' token.
2969 bool ARM64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) {
2970 bool HasELFModifier = false;
2971 ARM64MCExpr::VariantKind RefKind;
2973 if (Parser.getTok().is(AsmToken::Colon)) {
2974 Parser.Lex(); // Eat ':"
2975 HasELFModifier = true;
2977 if (Parser.getTok().isNot(AsmToken::Identifier)) {
2978 Error(Parser.getTok().getLoc(),
2979 "expect relocation specifier in operand after ':'");
2983 std::string LowerCase = Parser.getTok().getIdentifier().lower();
2984 RefKind = StringSwitch<ARM64MCExpr::VariantKind>(LowerCase)
2985 .Case("lo12", ARM64MCExpr::VK_LO12)
2986 .Case("abs_g3", ARM64MCExpr::VK_ABS_G3)
2987 .Case("abs_g2", ARM64MCExpr::VK_ABS_G2)
2988 .Case("abs_g2_nc", ARM64MCExpr::VK_ABS_G2_NC)
2989 .Case("abs_g1", ARM64MCExpr::VK_ABS_G1)
2990 .Case("abs_g1_nc", ARM64MCExpr::VK_ABS_G1_NC)
2991 .Case("abs_g0", ARM64MCExpr::VK_ABS_G0)
2992 .Case("abs_g0_nc", ARM64MCExpr::VK_ABS_G0_NC)
2993 .Case("dtprel_g2", ARM64MCExpr::VK_DTPREL_G2)
2994 .Case("dtprel_g1", ARM64MCExpr::VK_DTPREL_G1)
2995 .Case("dtprel_g1_nc", ARM64MCExpr::VK_DTPREL_G1_NC)
2996 .Case("dtprel_g0", ARM64MCExpr::VK_DTPREL_G0)
2997 .Case("dtprel_g0_nc", ARM64MCExpr::VK_DTPREL_G0_NC)
2998 .Case("dtprel_lo12", ARM64MCExpr::VK_DTPREL_LO12)
2999 .Case("dtprel_lo12_nc", ARM64MCExpr::VK_DTPREL_LO12_NC)
3000 .Case("tprel_g2", ARM64MCExpr::VK_TPREL_G2)
3001 .Case("tprel_g1", ARM64MCExpr::VK_TPREL_G1)
3002 .Case("tprel_g1_nc", ARM64MCExpr::VK_TPREL_G1_NC)
3003 .Case("tprel_g0", ARM64MCExpr::VK_TPREL_G0)
3004 .Case("tprel_g0_nc", ARM64MCExpr::VK_TPREL_G0_NC)
3005 .Case("tprel_lo12", ARM64MCExpr::VK_TPREL_LO12)
3006 .Case("tprel_lo12_nc", ARM64MCExpr::VK_TPREL_LO12_NC)
3007 .Case("tlsdesc_lo12", ARM64MCExpr::VK_TLSDESC_LO12)
3008 .Case("got", ARM64MCExpr::VK_GOT_PAGE)
3009 .Case("got_lo12", ARM64MCExpr::VK_GOT_LO12)
3010 .Case("gottprel", ARM64MCExpr::VK_GOTTPREL_PAGE)
3011 .Case("gottprel_lo12", ARM64MCExpr::VK_GOTTPREL_LO12_NC)
3012 .Case("gottprel_g1", ARM64MCExpr::VK_GOTTPREL_G1)
3013 .Case("gottprel_g0_nc", ARM64MCExpr::VK_GOTTPREL_G0_NC)
3014 .Case("tlsdesc", ARM64MCExpr::VK_TLSDESC_PAGE)
3015 .Default(ARM64MCExpr::VK_INVALID);
3017 if (RefKind == ARM64MCExpr::VK_INVALID) {
3018 Error(Parser.getTok().getLoc(),
3019 "expect relocation specifier in operand after ':'");
3023 Parser.Lex(); // Eat identifier
3025 if (Parser.getTok().isNot(AsmToken::Colon)) {
3026 Error(Parser.getTok().getLoc(), "expect ':' after relocation specifier");
3029 Parser.Lex(); // Eat ':'
3032 if (getParser().parseExpression(ImmVal))
3036 ImmVal = ARM64MCExpr::Create(ImmVal, RefKind, getContext());
3041 /// parseVectorList - Parse a vector list operand for AdvSIMD instructions.
3042 bool ARM64AsmParser::parseVectorList(OperandVector &Operands) {
3043 assert(Parser.getTok().is(AsmToken::LCurly) && "Token is not a Left Bracket");
3045 Parser.Lex(); // Eat left bracket token.
3047 int64_t FirstReg = tryMatchVectorRegister(Kind, true);
3050 int64_t PrevReg = FirstReg;
3053 if (Parser.getTok().is(AsmToken::Minus)) {
3054 Parser.Lex(); // Eat the minus.
3056 SMLoc Loc = getLoc();
3058 int64_t Reg = tryMatchVectorRegister(NextKind, true);
3061 // Any Kind suffices must match on all regs in the list.
3062 if (Kind != NextKind)
3063 return Error(Loc, "mismatched register size suffix");
3065 unsigned Space = (PrevReg < Reg) ? (Reg - PrevReg) : (Reg + 32 - PrevReg);
3067 if (Space == 0 || Space > 3) {
3068 return Error(Loc, "invalid number of vectors");
3074 while (Parser.getTok().is(AsmToken::Comma)) {
3075 Parser.Lex(); // Eat the comma token.
3077 SMLoc Loc = getLoc();
3079 int64_t Reg = tryMatchVectorRegister(NextKind, true);
3082 // Any Kind suffices must match on all regs in the list.
3083 if (Kind != NextKind)
3084 return Error(Loc, "mismatched register size suffix");
3086 // Registers must be incremental (with wraparound at 31)
3087 if (getContext().getRegisterInfo()->getEncodingValue(Reg) !=
3088 (getContext().getRegisterInfo()->getEncodingValue(PrevReg) + 1) % 32)
3089 return Error(Loc, "registers must be sequential");
3096 if (Parser.getTok().is(AsmToken::EndOfStatement))
3097 Error(getLoc(), "'}' expected");
3098 Parser.Lex(); // Eat the '}' token.
3100 unsigned NumElements = 0;
3101 char ElementKind = 0;
3103 parseValidVectorKind(Kind, NumElements, ElementKind);
3105 Operands.push_back(ARM64Operand::CreateVectorList(
3106 FirstReg, Count, NumElements, ElementKind, S, getLoc(), getContext()));
3108 // If there is an index specifier following the list, parse that too.
3109 if (Parser.getTok().is(AsmToken::LBrac)) {
3110 SMLoc SIdx = getLoc();
3111 Parser.Lex(); // Eat left bracket token.
3113 const MCExpr *ImmVal;
3114 if (getParser().parseExpression(ImmVal))
3116 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
3118 TokError("immediate value expected for vector index");
3123 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3124 Error(E, "']' expected");
3128 Parser.Lex(); // Eat right bracket token.
3130 Operands.push_back(ARM64Operand::CreateVectorIndex(MCE->getValue(), SIdx, E,
3136 /// parseOperand - Parse a arm instruction operand. For now this parses the
3137 /// operand regardless of the mnemonic.
3138 bool ARM64AsmParser::parseOperand(OperandVector &Operands, bool isCondCode,
3139 bool invertCondCode) {
3140 // Check if the current operand has a custom associated parser, if so, try to
3141 // custom parse the operand, or fallback to the general approach.
3142 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
3143 if (ResTy == MatchOperand_Success)
3145 // If there wasn't a custom match, try the generic matcher below. Otherwise,
3146 // there was a match, but an error occurred, in which case, just return that
3147 // the operand parsing failed.
3148 if (ResTy == MatchOperand_ParseFail)
3151 // Nothing custom, so do general case parsing.
3153 switch (getLexer().getKind()) {
3157 if (parseSymbolicImmVal(Expr))
3158 return Error(S, "invalid operand");
3160 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
3161 Operands.push_back(ARM64Operand::CreateImm(Expr, S, E, getContext()));
3164 case AsmToken::LBrac:
3165 return parseMemory(Operands);
3166 case AsmToken::LCurly:
3167 return parseVectorList(Operands);
3168 case AsmToken::Identifier: {
3169 // If we're expecting a Condition Code operand, then just parse that.
3171 return parseCondCode(Operands, invertCondCode);
3173 // If it's a register name, parse it.
3174 if (!parseRegister(Operands))
3177 // This could be an optional "shift" operand.
3178 if (!parseOptionalShift(Operands))
3181 // Or maybe it could be an optional "extend" operand.
3182 if (!parseOptionalExtend(Operands))
3185 // This was not a register so parse other operands that start with an
3186 // identifier (like labels) as expressions and create them as immediates.
3187 const MCExpr *IdVal;
3189 if (getParser().parseExpression(IdVal))
3192 E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
3193 Operands.push_back(ARM64Operand::CreateImm(IdVal, S, E, getContext()));
3196 case AsmToken::Hash: {
3197 // #42 -> immediate.
3201 // The only Real that should come through here is a literal #0.0 for
3202 // the fcmp[e] r, #0.0 instructions. They expect raw token operands,
3203 // so convert the value.
3204 const AsmToken &Tok = Parser.getTok();
3205 if (Tok.is(AsmToken::Real)) {
3206 APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
3207 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
3208 if (IntVal != 0 || (Mnemonic != "fcmp" && Mnemonic != "fcmpe"))
3209 return TokError("unexpected floating point literal");
3210 Parser.Lex(); // Eat the token.
3213 ARM64Operand::CreateToken("#0", false, S, getContext()));
3215 ARM64Operand::CreateToken(".0", false, S, getContext()));
3219 const MCExpr *ImmVal;
3220 if (parseSymbolicImmVal(ImmVal))
3223 E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
3224 Operands.push_back(ARM64Operand::CreateImm(ImmVal, S, E, getContext()));
3230 /// ParseInstruction - Parse an ARM64 instruction mnemonic followed by its
3232 bool ARM64AsmParser::ParseInstruction(ParseInstructionInfo &Info,
3233 StringRef Name, SMLoc NameLoc,
3234 OperandVector &Operands) {
3235 // Create the leading tokens for the mnemonic, split by '.' characters.
3236 size_t Start = 0, Next = Name.find('.');
3237 StringRef Head = Name.slice(Start, Next);
3239 // IC, DC, AT, and TLBI instructions are aliases for the SYS instruction.
3240 if (Head == "ic" || Head == "dc" || Head == "at" || Head == "tlbi")
3241 return parseSysAlias(Head, NameLoc, Operands);
3244 ARM64Operand::CreateToken(Head, false, NameLoc, getContext()));
3247 // Handle condition codes for a branch mnemonic
3248 if (Head == "b" && Next != StringRef::npos) {
3250 Next = Name.find('.', Start + 1);
3251 Head = Name.slice(Start + 1, Next);
3253 SMLoc SuffixLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
3254 (Head.data() - Name.data()));
3255 unsigned CC = parseCondCodeString(Head);
3256 if (CC == ARM64CC::Invalid)
3257 return Error(SuffixLoc, "invalid condition code");
3258 const MCExpr *CCExpr = MCConstantExpr::Create(CC, getContext());
3260 ARM64Operand::CreateImm(CCExpr, NameLoc, NameLoc, getContext()));
3263 // Add the remaining tokens in the mnemonic.
3264 while (Next != StringRef::npos) {
3266 Next = Name.find('.', Start + 1);
3267 Head = Name.slice(Start, Next);
3268 SMLoc SuffixLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
3269 (Head.data() - Name.data()) + 1);
3271 ARM64Operand::CreateToken(Head, true, SuffixLoc, getContext()));
3274 // Conditional compare instructions have a Condition Code operand, which needs
3275 // to be parsed and an immediate operand created.
3276 bool condCodeFourthOperand =
3277 (Head == "ccmp" || Head == "ccmn" || Head == "fccmp" ||
3278 Head == "fccmpe" || Head == "fcsel" || Head == "csel" ||
3279 Head == "csinc" || Head == "csinv" || Head == "csneg");
3281 // These instructions are aliases to some of the conditional select
3282 // instructions. However, the condition code is inverted in the aliased
3285 // FIXME: Is this the correct way to handle these? Or should the parser
3286 // generate the aliased instructions directly?
3287 bool condCodeSecondOperand = (Head == "cset" || Head == "csetm");
3288 bool condCodeThirdOperand =
3289 (Head == "cinc" || Head == "cinv" || Head == "cneg");
3291 // Read the remaining operands.
3292 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3293 // Read the first operand.
3294 if (parseOperand(Operands, false, false)) {
3295 Parser.eatToEndOfStatement();
3300 while (getLexer().is(AsmToken::Comma)) {
3301 Parser.Lex(); // Eat the comma.
3303 // Parse and remember the operand.
3304 if (parseOperand(Operands, (N == 4 && condCodeFourthOperand) ||
3305 (N == 3 && condCodeThirdOperand) ||
3306 (N == 2 && condCodeSecondOperand),
3307 condCodeSecondOperand || condCodeThirdOperand)) {
3308 Parser.eatToEndOfStatement();
3316 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3317 SMLoc Loc = Parser.getTok().getLoc();
3318 Parser.eatToEndOfStatement();
3319 return Error(Loc, "unexpected token in argument list");
3322 Parser.Lex(); // Consume the EndOfStatement
3326 /// isFPR32Register - Check if a register is in the FPR32 register class.
3327 /// (The parser does not have the target register info to check the register
3328 /// class directly.)
3329 static bool isFPR32Register(unsigned Reg) {
3330 using namespace ARM64;
3334 case S0: case S1: case S2: case S3: case S4: case S5: case S6:
3335 case S7: case S8: case S9: case S10: case S11: case S12: case S13:
3336 case S14: case S15: case S16: case S17: case S18: case S19: case S20:
3337 case S21: case S22: case S23: case S24: case S25: case S26: case S27:
3338 case S28: case S29: case S30: case S31:
3344 /// isGPR32Register - Check if a register is in the GPR32sp register class.
3345 /// (The parser does not have the target register info to check the register
3346 /// class directly.)
3347 static bool isGPR32Register(unsigned Reg) {
3348 using namespace ARM64;
3352 case W0: case W1: case W2: case W3: case W4: case W5: case W6:
3353 case W7: case W8: case W9: case W10: case W11: case W12: case W13:
3354 case W14: case W15: case W16: case W17: case W18: case W19: case W20:
3355 case W21: case W22: case W23: case W24: case W25: case W26: case W27:
3356 case W28: case W29: case W30: case WSP: case WZR:
3362 static bool isGPR64Reg(unsigned Reg) {
3363 using namespace ARM64;
3365 case X0: case X1: case X2: case X3: case X4: case X5: case X6:
3366 case X7: case X8: case X9: case X10: case X11: case X12: case X13:
3367 case X14: case X15: case X16: case X17: case X18: case X19: case X20:
3368 case X21: case X22: case X23: case X24: case X25: case X26: case X27:
3369 case X28: case FP: case LR: case SP: case XZR:
3377 // FIXME: This entire function is a giant hack to provide us with decent
3378 // operand range validation/diagnostics until TableGen/MC can be extended
3379 // to support autogeneration of this kind of validation.
3380 bool ARM64AsmParser::validateInstruction(MCInst &Inst,
3381 SmallVectorImpl<SMLoc> &Loc) {
3382 const MCRegisterInfo *RI = getContext().getRegisterInfo();
3383 // Check for indexed addressing modes w/ the base register being the
3384 // same as a destination/source register or pair load where
3385 // the Rt == Rt2. All of those are undefined behaviour.
3386 switch (Inst.getOpcode()) {
3387 case ARM64::LDPSWpre:
3388 case ARM64::LDPWpost:
3389 case ARM64::LDPWpre:
3390 case ARM64::LDPXpost:
3391 case ARM64::LDPXpre: {
3392 unsigned Rt = Inst.getOperand(0).getReg();
3393 unsigned Rt2 = Inst.getOperand(1).getReg();
3394 unsigned Rn = Inst.getOperand(2).getReg();
3395 if (RI->isSubRegisterEq(Rn, Rt))
3396 return Error(Loc[0], "unpredictable LDP instruction, writeback base "
3397 "is also a destination");
3398 if (RI->isSubRegisterEq(Rn, Rt2))
3399 return Error(Loc[1], "unpredictable LDP instruction, writeback base "
3400 "is also a destination");
3403 case ARM64::LDPDpost:
3404 case ARM64::LDPDpre:
3405 case ARM64::LDPQpost:
3406 case ARM64::LDPQpre:
3407 case ARM64::LDPSpost:
3408 case ARM64::LDPSpre:
3409 case ARM64::LDPSWpost:
3415 case ARM64::LDPXi: {
3416 unsigned Rt = Inst.getOperand(0).getReg();
3417 unsigned Rt2 = Inst.getOperand(1).getReg();
3419 return Error(Loc[1], "unpredictable LDP instruction, Rt2==Rt");
3422 case ARM64::STPDpost:
3423 case ARM64::STPDpre:
3424 case ARM64::STPQpost:
3425 case ARM64::STPQpre:
3426 case ARM64::STPSpost:
3427 case ARM64::STPSpre:
3428 case ARM64::STPWpost:
3429 case ARM64::STPWpre:
3430 case ARM64::STPXpost:
3431 case ARM64::STPXpre: {
3432 unsigned Rt = Inst.getOperand(0).getReg();
3433 unsigned Rt2 = Inst.getOperand(1).getReg();
3434 unsigned Rn = Inst.getOperand(2).getReg();
3435 if (RI->isSubRegisterEq(Rn, Rt))
3436 return Error(Loc[0], "unpredictable STP instruction, writeback base "
3437 "is also a source");
3438 if (RI->isSubRegisterEq(Rn, Rt2))
3439 return Error(Loc[1], "unpredictable STP instruction, writeback base "
3440 "is also a source");
3443 case ARM64::LDRBBpre:
3444 case ARM64::LDRBpre:
3445 case ARM64::LDRHHpre:
3446 case ARM64::LDRHpre:
3447 case ARM64::LDRSBWpre:
3448 case ARM64::LDRSBXpre:
3449 case ARM64::LDRSHWpre:
3450 case ARM64::LDRSHXpre:
3451 case ARM64::LDRSWpre:
3452 case ARM64::LDRWpre:
3453 case ARM64::LDRXpre:
3454 case ARM64::LDRBBpost:
3455 case ARM64::LDRBpost:
3456 case ARM64::LDRHHpost:
3457 case ARM64::LDRHpost:
3458 case ARM64::LDRSBWpost:
3459 case ARM64::LDRSBXpost:
3460 case ARM64::LDRSHWpost:
3461 case ARM64::LDRSHXpost:
3462 case ARM64::LDRSWpost:
3463 case ARM64::LDRWpost:
3464 case ARM64::LDRXpost: {
3465 unsigned Rt = Inst.getOperand(0).getReg();
3466 unsigned Rn = Inst.getOperand(1).getReg();
3467 if (RI->isSubRegisterEq(Rn, Rt))
3468 return Error(Loc[0], "unpredictable LDR instruction, writeback base "
3469 "is also a source");
3472 case ARM64::STRBBpost:
3473 case ARM64::STRBpost:
3474 case ARM64::STRHHpost:
3475 case ARM64::STRHpost:
3476 case ARM64::STRWpost:
3477 case ARM64::STRXpost:
3478 case ARM64::STRBBpre:
3479 case ARM64::STRBpre:
3480 case ARM64::STRHHpre:
3481 case ARM64::STRHpre:
3482 case ARM64::STRWpre:
3483 case ARM64::STRXpre: {
3484 unsigned Rt = Inst.getOperand(0).getReg();
3485 unsigned Rn = Inst.getOperand(1).getReg();
3486 if (RI->isSubRegisterEq(Rn, Rt))
3487 return Error(Loc[0], "unpredictable STR instruction, writeback base "
3488 "is also a source");
3493 // Now check immediate ranges. Separate from the above as there is overlap
3494 // in the instructions being checked and this keeps the nested conditionals
3496 switch (Inst.getOpcode()) {
3498 case ARM64::ANDSWrs:
3500 case ARM64::ORRWrs: {
3501 if (!Inst.getOperand(3).isImm())
3502 return Error(Loc[3], "immediate value expected");
3503 int64_t shifter = Inst.getOperand(3).getImm();
3504 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(shifter);
3505 if (ST == ARM64_AM::LSL && shifter > 31)
3506 return Error(Loc[3], "shift value out of range");
3509 case ARM64::ADDSWri:
3510 case ARM64::ADDSXri:
3513 case ARM64::SUBSWri:
3514 case ARM64::SUBSXri:
3516 case ARM64::SUBXri: {
3517 if (!Inst.getOperand(3).isImm())
3518 return Error(Loc[3], "immediate value expected");
3519 int64_t shifter = Inst.getOperand(3).getImm();
3520 if (shifter != 0 && shifter != 12)
3521 return Error(Loc[3], "shift value out of range");
3522 // The imm12 operand can be an expression. Validate that it's legit.
3523 // FIXME: We really, really want to allow arbitrary expressions here
3524 // and resolve the value and validate the result at fixup time, but
3525 // that's hard as we have long since lost any source information we
3526 // need to generate good diagnostics by that point.
3527 if (Inst.getOpcode() == ARM64::ADDXri && Inst.getOperand(2).isExpr()) {
3528 const MCExpr *Expr = Inst.getOperand(2).getExpr();
3529 ARM64MCExpr::VariantKind ELFRefKind;
3530 MCSymbolRefExpr::VariantKind DarwinRefKind;
3531 const MCConstantExpr *Addend;
3532 if (!classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
3533 return Error(Loc[2], "invalid immediate expression");
3536 if (DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
3537 DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGEOFF ||
3538 ELFRefKind == ARM64MCExpr::VK_LO12 ||
3539 ELFRefKind == ARM64MCExpr::VK_DTPREL_LO12 ||
3540 ELFRefKind == ARM64MCExpr::VK_DTPREL_LO12_NC ||
3541 ELFRefKind == ARM64MCExpr::VK_TPREL_LO12 ||
3542 ELFRefKind == ARM64MCExpr::VK_TPREL_LO12_NC ||
3543 ELFRefKind == ARM64MCExpr::VK_TLSDESC_LO12) {
3544 // Note that we don't range-check the addend. It's adjusted
3545 // modulo page size when converted, so there is no "out of range"
3546 // condition when using @pageoff. Any validity checking for the value
3547 // was done in the is*() predicate function.
3549 } else if (DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGEOFF) {
3550 // @gotpageoff can only be used directly, not with an addend.
3554 // Otherwise, we're not sure, so don't allow it for now.
3555 return Error(Loc[2], "invalid immediate expression");
3558 // If it's anything but an immediate, it's not legit.
3559 if (!Inst.getOperand(2).isImm())
3560 return Error(Loc[2], "invalid immediate expression");
3561 int64_t imm = Inst.getOperand(2).getImm();
3562 if (imm > 4095 || imm < 0)
3563 return Error(Loc[2], "immediate value out of range");
3566 case ARM64::LDRBpre:
3567 case ARM64::LDRHpre:
3568 case ARM64::LDRSBWpre:
3569 case ARM64::LDRSBXpre:
3570 case ARM64::LDRSHWpre:
3571 case ARM64::LDRSHXpre:
3572 case ARM64::LDRWpre:
3573 case ARM64::LDRXpre:
3574 case ARM64::LDRSpre:
3575 case ARM64::LDRDpre:
3576 case ARM64::LDRQpre:
3577 case ARM64::STRBpre:
3578 case ARM64::STRHpre:
3579 case ARM64::STRWpre:
3580 case ARM64::STRXpre:
3581 case ARM64::STRSpre:
3582 case ARM64::STRDpre:
3583 case ARM64::STRQpre:
3584 case ARM64::LDRBpost:
3585 case ARM64::LDRHpost:
3586 case ARM64::LDRSBWpost:
3587 case ARM64::LDRSBXpost:
3588 case ARM64::LDRSHWpost:
3589 case ARM64::LDRSHXpost:
3590 case ARM64::LDRWpost:
3591 case ARM64::LDRXpost:
3592 case ARM64::LDRSpost:
3593 case ARM64::LDRDpost:
3594 case ARM64::LDRQpost:
3595 case ARM64::STRBpost:
3596 case ARM64::STRHpost:
3597 case ARM64::STRWpost:
3598 case ARM64::STRXpost:
3599 case ARM64::STRSpost:
3600 case ARM64::STRDpost:
3601 case ARM64::STRQpost:
3606 case ARM64::LDTRSHWi:
3607 case ARM64::LDTRSHXi:
3608 case ARM64::LDTRSBWi:
3609 case ARM64::LDTRSBXi:
3610 case ARM64::LDTRSWi:
3622 case ARM64::LDURSHWi:
3623 case ARM64::LDURSHXi:
3624 case ARM64::LDURSBWi:
3625 case ARM64::LDURSBXi:
3626 case ARM64::LDURSWi:
3634 case ARM64::STURBi: {
3635 // FIXME: Should accept expressions and error in fixup evaluation
3637 if (!Inst.getOperand(2).isImm())
3638 return Error(Loc[1], "immediate value expected");
3639 int64_t offset = Inst.getOperand(2).getImm();
3640 if (offset > 255 || offset < -256)
3641 return Error(Loc[1], "offset value out of range");
3646 case ARM64::LDRSWro:
3648 case ARM64::STRSro: {
3649 // FIXME: Should accept expressions and error in fixup evaluation
3651 if (!Inst.getOperand(3).isImm())
3652 return Error(Loc[1], "immediate value expected");
3653 int64_t shift = Inst.getOperand(3).getImm();
3654 ARM64_AM::ExtendType type = ARM64_AM::getMemExtendType(shift);
3655 if (type != ARM64_AM::UXTW && type != ARM64_AM::UXTX &&
3656 type != ARM64_AM::SXTW && type != ARM64_AM::SXTX)
3657 return Error(Loc[1], "shift type invalid");
3666 case ARM64::STRQro: {
3667 // FIXME: Should accept expressions and error in fixup evaluation
3669 if (!Inst.getOperand(3).isImm())
3670 return Error(Loc[1], "immediate value expected");
3671 int64_t shift = Inst.getOperand(3).getImm();
3672 ARM64_AM::ExtendType type = ARM64_AM::getMemExtendType(shift);
3673 if (type != ARM64_AM::UXTW && type != ARM64_AM::UXTX &&
3674 type != ARM64_AM::SXTW && type != ARM64_AM::SXTX)
3675 return Error(Loc[1], "shift type invalid");
3679 case ARM64::LDRHHro:
3680 case ARM64::LDRSHWro:
3681 case ARM64::LDRSHXro:
3683 case ARM64::STRHHro: {
3684 // FIXME: Should accept expressions and error in fixup evaluation
3686 if (!Inst.getOperand(3).isImm())
3687 return Error(Loc[1], "immediate value expected");
3688 int64_t shift = Inst.getOperand(3).getImm();
3689 ARM64_AM::ExtendType type = ARM64_AM::getMemExtendType(shift);
3690 if (type != ARM64_AM::UXTW && type != ARM64_AM::UXTX &&
3691 type != ARM64_AM::SXTW && type != ARM64_AM::SXTX)
3692 return Error(Loc[1], "shift type invalid");
3696 case ARM64::LDRBBro:
3697 case ARM64::LDRSBWro:
3698 case ARM64::LDRSBXro:
3700 case ARM64::STRBBro: {
3701 // FIXME: Should accept expressions and error in fixup evaluation
3703 if (!Inst.getOperand(3).isImm())
3704 return Error(Loc[1], "immediate value expected");
3705 int64_t shift = Inst.getOperand(3).getImm();
3706 ARM64_AM::ExtendType type = ARM64_AM::getMemExtendType(shift);
3707 if (type != ARM64_AM::UXTW && type != ARM64_AM::UXTX &&
3708 type != ARM64_AM::SXTW && type != ARM64_AM::SXTX)
3709 return Error(Loc[1], "shift type invalid");
3723 case ARM64::LDPWpre:
3724 case ARM64::LDPXpre:
3725 case ARM64::LDPSpre:
3726 case ARM64::LDPDpre:
3727 case ARM64::LDPQpre:
3728 case ARM64::LDPSWpre:
3729 case ARM64::STPWpre:
3730 case ARM64::STPXpre:
3731 case ARM64::STPSpre:
3732 case ARM64::STPDpre:
3733 case ARM64::STPQpre:
3734 case ARM64::LDPWpost:
3735 case ARM64::LDPXpost:
3736 case ARM64::LDPSpost:
3737 case ARM64::LDPDpost:
3738 case ARM64::LDPQpost:
3739 case ARM64::LDPSWpost:
3740 case ARM64::STPWpost:
3741 case ARM64::STPXpost:
3742 case ARM64::STPSpost:
3743 case ARM64::STPDpost:
3744 case ARM64::STPQpost:
3754 case ARM64::STNPQi: {
3755 // FIXME: Should accept expressions and error in fixup evaluation
3757 if (!Inst.getOperand(3).isImm())
3758 return Error(Loc[2], "immediate value expected");
3759 int64_t offset = Inst.getOperand(3).getImm();
3760 if (offset > 63 || offset < -64)
3761 return Error(Loc[2], "offset value out of range");
3769 static void rewriteMOV(ARM64AsmParser::OperandVector &Operands,
3770 StringRef mnemonic, uint64_t imm, unsigned shift,
3771 MCContext &Context) {
3772 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[0]);
3773 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
3775 ARM64Operand::CreateToken(mnemonic, false, Op->getStartLoc(), Context);
3777 const MCExpr *NewImm = MCConstantExpr::Create(imm >> shift, Context);
3778 Operands[2] = ARM64Operand::CreateImm(NewImm, Op2->getStartLoc(),
3779 Op2->getEndLoc(), Context);
3781 Operands.push_back(ARM64Operand::CreateShifter(
3782 ARM64_AM::LSL, shift, Op2->getStartLoc(), Op2->getEndLoc(), Context));
3787 bool ARM64AsmParser::showMatchError(SMLoc Loc, unsigned ErrCode) {
3789 case Match_MissingFeature:
3791 "instruction requires a CPU feature not currently enabled");
3792 case Match_InvalidOperand:
3793 return Error(Loc, "invalid operand for instruction");
3794 case Match_InvalidSuffix:
3795 return Error(Loc, "invalid type suffix for instruction");
3796 case Match_InvalidMemoryIndexedSImm9:
3797 return Error(Loc, "index must be an integer in range [-256,255].");
3798 case Match_InvalidMemoryIndexed32SImm7:
3799 return Error(Loc, "index must be a multiple of 4 in range [-256,252].");
3800 case Match_InvalidMemoryIndexed64SImm7:
3801 return Error(Loc, "index must be a multiple of 8 in range [-512,504].");
3802 case Match_InvalidMemoryIndexed128SImm7:
3803 return Error(Loc, "index must be a multiple of 16 in range [-1024,1008].");
3804 case Match_InvalidMemoryIndexed8:
3805 return Error(Loc, "index must be an integer in range [0,4095].");
3806 case Match_InvalidMemoryIndexed16:
3807 return Error(Loc, "index must be a multiple of 2 in range [0,8190].");
3808 case Match_InvalidMemoryIndexed32:
3809 return Error(Loc, "index must be a multiple of 4 in range [0,16380].");
3810 case Match_InvalidMemoryIndexed64:
3811 return Error(Loc, "index must be a multiple of 8 in range [0,32760].");
3812 case Match_InvalidMemoryIndexed128:
3813 return Error(Loc, "index must be a multiple of 16 in range [0,65520].");
3814 case Match_InvalidImm1_8:
3815 return Error(Loc, "immediate must be an integer in range [1,8].");
3816 case Match_InvalidImm1_16:
3817 return Error(Loc, "immediate must be an integer in range [1,16].");
3818 case Match_InvalidImm1_32:
3819 return Error(Loc, "immediate must be an integer in range [1,32].");
3820 case Match_InvalidImm1_64:
3821 return Error(Loc, "immediate must be an integer in range [1,64].");
3822 case Match_MnemonicFail:
3823 return Error(Loc, "unrecognized instruction mnemonic");
3825 assert(0 && "unexpected error code!");
3826 return Error(Loc, "invalid instruction format");
3830 bool ARM64AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
3831 OperandVector &Operands,
3833 unsigned &ErrorInfo,
3834 bool MatchingInlineAsm) {
3835 assert(!Operands.empty() && "Unexpect empty operand list!");
3836 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[0]);
3837 assert(Op->isToken() && "Leading operand should always be a mnemonic!");
3839 StringRef Tok = Op->getToken();
3840 // Translate CMN/CMP pseudos to ADDS/SUBS with zero register destination.
3841 // This needs to be done before the special handling of ADD/SUB immediates.
3842 if (Tok == "cmp" || Tok == "cmn") {
3843 // Replace the opcode with either ADDS or SUBS.
3844 const char *Repl = StringSwitch<const char *>(Tok)
3845 .Case("cmp", "subs")
3846 .Case("cmn", "adds")
3848 assert(Repl && "Unknown compare instruction");
3850 Operands[0] = ARM64Operand::CreateToken(Repl, false, IDLoc, getContext());
3852 // Insert WZR or XZR as destination operand.
3853 ARM64Operand *RegOp = static_cast<ARM64Operand *>(Operands[1]);
3855 if (RegOp->isReg() && isGPR32Register(RegOp->getReg()))
3856 ZeroReg = ARM64::WZR;
3858 ZeroReg = ARM64::XZR;
3860 Operands.begin() + 1,
3861 ARM64Operand::CreateReg(ZeroReg, false, IDLoc, IDLoc, getContext()));
3862 // Update since we modified it above.
3863 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[0]);
3864 Tok = Op->getToken();
3867 unsigned NumOperands = Operands.size();
3869 if (Tok == "mov" && NumOperands == 3) {
3870 // The MOV mnemomic is aliased to movn/movz, depending on the value of
3871 // the immediate being instantiated.
3872 // FIXME: Catching this here is a total hack, and we should use tblgen
3873 // support to implement this instead as soon as it is available.
3875 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
3877 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op2->getImm())) {
3878 uint64_t Val = CE->getValue();
3879 uint64_t NVal = ~Val;
3881 // If this is a 32-bit register and the value has none of the upper
3882 // set, clear the complemented upper 32-bits so the logic below works
3883 // for 32-bit registers too.
3884 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
3885 if (Op1->isReg() && isGPR32Register(Op1->getReg()) &&
3886 (Val & 0xFFFFFFFFULL) == Val)
3887 NVal &= 0x00000000FFFFFFFFULL;
3889 // MOVK Rd, imm << 0
3890 if ((Val & 0xFFFF) == Val)
3891 rewriteMOV(Operands, "movz", Val, 0, getContext());
3893 // MOVK Rd, imm << 16
3894 else if ((Val & 0xFFFF0000ULL) == Val)
3895 rewriteMOV(Operands, "movz", Val, 16, getContext());
3897 // MOVK Rd, imm << 32
3898 else if ((Val & 0xFFFF00000000ULL) == Val)
3899 rewriteMOV(Operands, "movz", Val, 32, getContext());
3901 // MOVK Rd, imm << 48
3902 else if ((Val & 0xFFFF000000000000ULL) == Val)
3903 rewriteMOV(Operands, "movz", Val, 48, getContext());
3905 // MOVN Rd, (~imm << 0)
3906 else if ((NVal & 0xFFFFULL) == NVal)
3907 rewriteMOV(Operands, "movn", NVal, 0, getContext());
3909 // MOVN Rd, ~(imm << 16)
3910 else if ((NVal & 0xFFFF0000ULL) == NVal)
3911 rewriteMOV(Operands, "movn", NVal, 16, getContext());
3913 // MOVN Rd, ~(imm << 32)
3914 else if ((NVal & 0xFFFF00000000ULL) == NVal)
3915 rewriteMOV(Operands, "movn", NVal, 32, getContext());
3917 // MOVN Rd, ~(imm << 48)
3918 else if ((NVal & 0xFFFF000000000000ULL) == NVal)
3919 rewriteMOV(Operands, "movn", NVal, 48, getContext());
3922 } else if (NumOperands == 4) {
3923 if (Tok == "add" || Tok == "adds" || Tok == "sub" || Tok == "subs") {
3924 // Handle the uimm24 immediate form, where the shift is not specified.
3925 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
3927 if (const MCConstantExpr *CE =
3928 dyn_cast<MCConstantExpr>(Op3->getImm())) {
3929 uint64_t Val = CE->getValue();
3930 if (Val >= (1 << 24)) {
3931 Error(IDLoc, "immediate value is too large");
3934 if (Val < (1 << 12)) {
3935 Operands.push_back(ARM64Operand::CreateShifter(
3936 ARM64_AM::LSL, 0, IDLoc, IDLoc, getContext()));
3937 } else if ((Val & 0xfff) == 0) {
3939 CE = MCConstantExpr::Create(Val >> 12, getContext());
3941 ARM64Operand::CreateImm(CE, IDLoc, IDLoc, getContext());
3942 Operands.push_back(ARM64Operand::CreateShifter(
3943 ARM64_AM::LSL, 12, IDLoc, IDLoc, getContext()));
3945 Error(IDLoc, "immediate value is too large");
3949 Operands.push_back(ARM64Operand::CreateShifter(
3950 ARM64_AM::LSL, 0, IDLoc, IDLoc, getContext()));
3954 // FIXME: Horible hack to handle the LSL -> UBFM alias.
3955 } else if (NumOperands == 4 && Tok == "lsl") {
3956 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
3957 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
3958 if (Op2->isReg() && Op3->isImm()) {
3959 const MCConstantExpr *Op3CE = dyn_cast<MCConstantExpr>(Op3->getImm());
3961 uint64_t Op3Val = Op3CE->getValue();
3962 uint64_t NewOp3Val = 0;
3963 uint64_t NewOp4Val = 0;
3964 if (isGPR32Register(Op2->getReg())) {
3965 NewOp3Val = (32 - Op3Val) & 0x1f;
3966 NewOp4Val = 31 - Op3Val;
3968 NewOp3Val = (64 - Op3Val) & 0x3f;
3969 NewOp4Val = 63 - Op3Val;
3972 const MCExpr *NewOp3 =
3973 MCConstantExpr::Create(NewOp3Val, getContext());
3974 const MCExpr *NewOp4 =
3975 MCConstantExpr::Create(NewOp4Val, getContext());
3977 Operands[0] = ARM64Operand::CreateToken(
3978 "ubfm", false, Op->getStartLoc(), getContext());
3979 Operands[3] = ARM64Operand::CreateImm(NewOp3, Op3->getStartLoc(),
3980 Op3->getEndLoc(), getContext());
3981 Operands.push_back(ARM64Operand::CreateImm(
3982 NewOp4, Op3->getStartLoc(), Op3->getEndLoc(), getContext()));
3988 // FIXME: Horrible hack to handle the optional LSL shift for vector
3990 } else if (NumOperands == 4 && (Tok == "bic" || Tok == "orr")) {
3991 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
3992 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
3993 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
3994 if ((Op1->isToken() && Op2->isVectorReg() && Op3->isImm()) ||
3995 (Op1->isVectorReg() && Op2->isToken() && Op3->isImm()))
3996 Operands.push_back(ARM64Operand::CreateShifter(ARM64_AM::LSL, 0, IDLoc,
3997 IDLoc, getContext()));
3998 } else if (NumOperands == 4 && (Tok == "movi" || Tok == "mvni")) {
3999 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
4000 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
4001 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
4002 if ((Op1->isToken() && Op2->isVectorReg() && Op3->isImm()) ||
4003 (Op1->isVectorReg() && Op2->isToken() && Op3->isImm())) {
4004 StringRef Suffix = Op1->isToken() ? Op1->getToken() : Op2->getToken();
4005 // Canonicalize on lower-case for ease of comparison.
4006 std::string CanonicalSuffix = Suffix.lower();
4007 if (Tok != "movi" ||
4008 (CanonicalSuffix != ".1d" && CanonicalSuffix != ".2d" &&
4009 CanonicalSuffix != ".8b" && CanonicalSuffix != ".16b"))
4010 Operands.push_back(ARM64Operand::CreateShifter(
4011 ARM64_AM::LSL, 0, IDLoc, IDLoc, getContext()));
4014 } else if (NumOperands == 5) {
4015 // FIXME: Horrible hack to handle the BFI -> BFM, SBFIZ->SBFM, and
4016 // UBFIZ -> UBFM aliases.
4017 if (Tok == "bfi" || Tok == "sbfiz" || Tok == "ubfiz") {
4018 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
4019 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
4020 ARM64Operand *Op4 = static_cast<ARM64Operand *>(Operands[4]);
4022 if (Op1->isReg() && Op3->isImm() && Op4->isImm()) {
4023 const MCConstantExpr *Op3CE = dyn_cast<MCConstantExpr>(Op3->getImm());
4024 const MCConstantExpr *Op4CE = dyn_cast<MCConstantExpr>(Op4->getImm());
4026 if (Op3CE && Op4CE) {
4027 uint64_t Op3Val = Op3CE->getValue();
4028 uint64_t Op4Val = Op4CE->getValue();
4030 uint64_t NewOp3Val = 0;
4031 if (isGPR32Register(Op1->getReg()))
4032 NewOp3Val = (32 - Op3Val) & 0x1f;
4034 NewOp3Val = (64 - Op3Val) & 0x3f;
4036 uint64_t NewOp4Val = Op4Val - 1;
4038 const MCExpr *NewOp3 =
4039 MCConstantExpr::Create(NewOp3Val, getContext());
4040 const MCExpr *NewOp4 =
4041 MCConstantExpr::Create(NewOp4Val, getContext());
4042 Operands[3] = ARM64Operand::CreateImm(NewOp3, Op3->getStartLoc(),
4043 Op3->getEndLoc(), getContext());
4044 Operands[4] = ARM64Operand::CreateImm(NewOp4, Op4->getStartLoc(),
4045 Op4->getEndLoc(), getContext());
4047 Operands[0] = ARM64Operand::CreateToken(
4048 "bfm", false, Op->getStartLoc(), getContext());
4049 else if (Tok == "sbfiz")
4050 Operands[0] = ARM64Operand::CreateToken(
4051 "sbfm", false, Op->getStartLoc(), getContext());
4052 else if (Tok == "ubfiz")
4053 Operands[0] = ARM64Operand::CreateToken(
4054 "ubfm", false, Op->getStartLoc(), getContext());
4056 llvm_unreachable("No valid mnemonic for alias?");
4064 // FIXME: Horrible hack to handle the BFXIL->BFM, SBFX->SBFM, and
4065 // UBFX -> UBFM aliases.
4066 } else if (NumOperands == 5 &&
4067 (Tok == "bfxil" || Tok == "sbfx" || Tok == "ubfx")) {
4068 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
4069 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
4070 ARM64Operand *Op4 = static_cast<ARM64Operand *>(Operands[4]);
4072 if (Op1->isReg() && Op3->isImm() && Op4->isImm()) {
4073 const MCConstantExpr *Op3CE = dyn_cast<MCConstantExpr>(Op3->getImm());
4074 const MCConstantExpr *Op4CE = dyn_cast<MCConstantExpr>(Op4->getImm());
4076 if (Op3CE && Op4CE) {
4077 uint64_t Op3Val = Op3CE->getValue();
4078 uint64_t Op4Val = Op4CE->getValue();
4079 uint64_t NewOp4Val = Op3Val + Op4Val - 1;
4081 if (NewOp4Val >= Op3Val) {
4082 const MCExpr *NewOp4 =
4083 MCConstantExpr::Create(NewOp4Val, getContext());
4084 Operands[4] = ARM64Operand::CreateImm(
4085 NewOp4, Op4->getStartLoc(), Op4->getEndLoc(), getContext());
4087 Operands[0] = ARM64Operand::CreateToken(
4088 "bfm", false, Op->getStartLoc(), getContext());
4089 else if (Tok == "sbfx")
4090 Operands[0] = ARM64Operand::CreateToken(
4091 "sbfm", false, Op->getStartLoc(), getContext());
4092 else if (Tok == "ubfx")
4093 Operands[0] = ARM64Operand::CreateToken(
4094 "ubfm", false, Op->getStartLoc(), getContext());
4096 llvm_unreachable("No valid mnemonic for alias?");
4105 // FIXME: Horrible hack for tbz and tbnz with Wn register operand.
4106 // InstAlias can't quite handle this since the reg classes aren't
4108 if (NumOperands == 4 && (Tok == "tbz" || Tok == "tbnz")) {
4109 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[2]);
4111 if (const MCConstantExpr *OpCE = dyn_cast<MCConstantExpr>(Op->getImm())) {
4112 if (OpCE->getValue() < 32) {
4113 // The source register can be Wn here, but the matcher expects a
4114 // GPR64. Twiddle it here if necessary.
4115 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[1]);
4117 unsigned Reg = getXRegFromWReg(Op->getReg());
4118 Operands[1] = ARM64Operand::CreateReg(
4119 Reg, false, Op->getStartLoc(), Op->getEndLoc(), getContext());
4126 // FIXME: Horrible hack for sxtw and uxtw with Wn src and Xd dst operands.
4127 // InstAlias can't quite handle this since the reg classes aren't
4129 if (NumOperands == 3 && (Tok == "sxtw" || Tok == "uxtw")) {
4130 // The source register can be Wn here, but the matcher expects a
4131 // GPR64. Twiddle it here if necessary.
4132 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[2]);
4134 unsigned Reg = getXRegFromWReg(Op->getReg());
4135 Operands[2] = ARM64Operand::CreateReg(Reg, false, Op->getStartLoc(),
4136 Op->getEndLoc(), getContext());
4140 // FIXME: Likewise for [su]xt[bh] with a Xd dst operand
4141 else if (NumOperands == 3 &&
4142 (Tok == "sxtb" || Tok == "uxtb" || Tok == "sxth" || Tok == "uxth")) {
4143 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[1]);
4144 if (Op->isReg() && isGPR64Reg(Op->getReg())) {
4145 // The source register can be Wn here, but the matcher expects a
4146 // GPR64. Twiddle it here if necessary.
4147 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[2]);
4149 unsigned Reg = getXRegFromWReg(Op->getReg());
4150 Operands[2] = ARM64Operand::CreateReg(Reg, false, Op->getStartLoc(),
4151 Op->getEndLoc(), getContext());
4157 // Yet another horrible hack to handle FMOV Rd, #0.0 using [WX]ZR.
4158 if (NumOperands == 3 && Tok == "fmov") {
4159 ARM64Operand *RegOp = static_cast<ARM64Operand *>(Operands[1]);
4160 ARM64Operand *ImmOp = static_cast<ARM64Operand *>(Operands[2]);
4161 if (RegOp->isReg() && ImmOp->isFPImm() &&
4162 ImmOp->getFPImm() == (unsigned)-1) {
4164 isFPR32Register(RegOp->getReg()) ? ARM64::WZR : ARM64::XZR;
4165 Operands[2] = ARM64Operand::CreateReg(zreg, false, Op->getStartLoc(),
4166 Op->getEndLoc(), getContext());
4171 // FIXME: Horrible hack to handle the literal .d[1] vector index on
4172 // FMOV instructions. The index isn't an actual instruction operand
4173 // but rather syntactic sugar. It really should be part of the mnemonic,
4174 // not the operand, but whatever.
4175 if ((NumOperands == 5) && Tok == "fmov") {
4176 // If the last operand is a vectorindex of '1', then replace it with
4177 // a '[' '1' ']' token sequence, which is what the matcher
4178 // (annoyingly) expects for a literal vector index operand.
4179 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[NumOperands - 1]);
4180 if (Op->isVectorIndexD() && Op->getVectorIndex() == 1) {
4181 SMLoc Loc = Op->getStartLoc();
4182 Operands.pop_back();
4184 ARM64Operand::CreateToken("[", false, Loc, getContext()));
4186 ARM64Operand::CreateToken("1", false, Loc, getContext()));
4188 ARM64Operand::CreateToken("]", false, Loc, getContext()));
4189 } else if (Op->isReg()) {
4190 // Similarly, check the destination operand for the GPR->High-lane
4192 unsigned OpNo = NumOperands - 2;
4193 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[OpNo]);
4194 if (Op->isVectorIndexD() && Op->getVectorIndex() == 1) {
4195 SMLoc Loc = Op->getStartLoc();
4197 ARM64Operand::CreateToken("[", false, Loc, getContext());
4199 Operands.begin() + OpNo + 1,
4200 ARM64Operand::CreateToken("1", false, Loc, getContext()));
4202 Operands.begin() + OpNo + 2,
4203 ARM64Operand::CreateToken("]", false, Loc, getContext()));
4209 // First try to match against the secondary set of tables containing the
4210 // short-form NEON instructions (e.g. "fadd.2s v0, v1, v2").
4211 unsigned MatchResult =
4212 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm, 1);
4214 // If that fails, try against the alternate table containing long-form NEON:
4215 // "fadd v0.2s, v1.2s, v2.2s"
4216 if (MatchResult != Match_Success)
4218 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm, 0);
4220 switch (MatchResult) {
4221 case Match_Success: {
4222 // Perform range checking and other semantic validations
4223 SmallVector<SMLoc, 8> OperandLocs;
4224 NumOperands = Operands.size();
4225 for (unsigned i = 1; i < NumOperands; ++i)
4226 OperandLocs.push_back(Operands[i]->getStartLoc());
4227 if (validateInstruction(Inst, OperandLocs))
4231 Out.EmitInstruction(Inst, STI);
4234 case Match_MissingFeature:
4235 case Match_MnemonicFail:
4236 return showMatchError(IDLoc, MatchResult);
4237 case Match_InvalidOperand: {
4238 SMLoc ErrorLoc = IDLoc;
4239 if (ErrorInfo != ~0U) {
4240 if (ErrorInfo >= Operands.size())
4241 return Error(IDLoc, "too few operands for instruction");
4243 ErrorLoc = ((ARM64Operand *)Operands[ErrorInfo])->getStartLoc();
4244 if (ErrorLoc == SMLoc())
4247 // If the match failed on a suffix token operand, tweak the diagnostic
4249 if (((ARM64Operand *)Operands[ErrorInfo])->isToken() &&
4250 ((ARM64Operand *)Operands[ErrorInfo])->isTokenSuffix())
4251 MatchResult = Match_InvalidSuffix;
4253 return showMatchError(ErrorLoc, MatchResult);
4255 case Match_InvalidMemoryIndexedSImm9: {
4256 // If there is not a '!' after the memory operand that failed, we really
4257 // want the diagnostic for the non-pre-indexed instruction variant instead.
4258 // Be careful to check for the post-indexed variant as well, which also
4259 // uses this match diagnostic. Also exclude the explicitly unscaled
4260 // mnemonics, as they want the unscaled diagnostic as well.
4261 if (Operands.size() == ErrorInfo + 1 &&
4262 !((ARM64Operand *)Operands[ErrorInfo])->isImm() &&
4263 !Tok.startswith("stur") && !Tok.startswith("ldur")) {
4264 // whether we want an Indexed64 or Indexed32 diagnostic depends on
4265 // the register class of the previous operand. Default to 64 in case
4266 // we see something unexpected.
4267 MatchResult = Match_InvalidMemoryIndexed64;
4269 ARM64Operand *PrevOp = (ARM64Operand *)Operands[ErrorInfo - 1];
4270 if (PrevOp->isReg() && ARM64MCRegisterClasses[ARM64::GPR32RegClassID]
4271 .contains(PrevOp->getReg()))
4272 MatchResult = Match_InvalidMemoryIndexed32;
4275 SMLoc ErrorLoc = ((ARM64Operand *)Operands[ErrorInfo])->getStartLoc();
4276 if (ErrorLoc == SMLoc())
4278 return showMatchError(ErrorLoc, MatchResult);
4280 case Match_InvalidMemoryIndexed32:
4281 case Match_InvalidMemoryIndexed64:
4282 case Match_InvalidMemoryIndexed128:
4283 // If there is a '!' after the memory operand that failed, we really
4284 // want the diagnostic for the pre-indexed instruction variant instead.
4285 if (Operands.size() > ErrorInfo + 1 &&
4286 ((ARM64Operand *)Operands[ErrorInfo + 1])->isTokenEqual("!"))
4287 MatchResult = Match_InvalidMemoryIndexedSImm9;
4289 case Match_InvalidMemoryIndexed8:
4290 case Match_InvalidMemoryIndexed16:
4291 case Match_InvalidMemoryIndexed32SImm7:
4292 case Match_InvalidMemoryIndexed64SImm7:
4293 case Match_InvalidMemoryIndexed128SImm7:
4294 case Match_InvalidImm1_8:
4295 case Match_InvalidImm1_16:
4296 case Match_InvalidImm1_32:
4297 case Match_InvalidImm1_64: {
4298 // Any time we get here, there's nothing fancy to do. Just get the
4299 // operand SMLoc and display the diagnostic.
4300 SMLoc ErrorLoc = ((ARM64Operand *)Operands[ErrorInfo])->getStartLoc();
4301 // If it's a memory operand, the error is with the offset immediate,
4302 // so get that location instead.
4303 if (((ARM64Operand *)Operands[ErrorInfo])->isMem())
4304 ErrorLoc = ((ARM64Operand *)Operands[ErrorInfo])->getOffsetLoc();
4305 if (ErrorLoc == SMLoc())
4307 return showMatchError(ErrorLoc, MatchResult);
4311 llvm_unreachable("Implement any new match types added!");
4315 /// ParseDirective parses the arm specific directives
4316 bool ARM64AsmParser::ParseDirective(AsmToken DirectiveID) {
4317 StringRef IDVal = DirectiveID.getIdentifier();
4318 SMLoc Loc = DirectiveID.getLoc();
4319 if (IDVal == ".hword")
4320 return parseDirectiveWord(2, Loc);
4321 if (IDVal == ".word")
4322 return parseDirectiveWord(4, Loc);
4323 if (IDVal == ".xword")
4324 return parseDirectiveWord(8, Loc);
4325 if (IDVal == ".tlsdesccall")
4326 return parseDirectiveTLSDescCall(Loc);
4328 return parseDirectiveLOH(IDVal, Loc);
4331 /// parseDirectiveWord
4332 /// ::= .word [ expression (, expression)* ]
4333 bool ARM64AsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
4334 if (getLexer().isNot(AsmToken::EndOfStatement)) {
4336 const MCExpr *Value;
4337 if (getParser().parseExpression(Value))
4340 getParser().getStreamer().EmitValue(Value, Size);
4342 if (getLexer().is(AsmToken::EndOfStatement))
4345 // FIXME: Improve diagnostic.
4346 if (getLexer().isNot(AsmToken::Comma))
4347 return Error(L, "unexpected token in directive");
4356 // parseDirectiveTLSDescCall:
4357 // ::= .tlsdesccall symbol
4358 bool ARM64AsmParser::parseDirectiveTLSDescCall(SMLoc L) {
4360 if (getParser().parseIdentifier(Name))
4361 return Error(L, "expected symbol after directive");
4363 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
4364 const MCExpr *Expr = MCSymbolRefExpr::Create(Sym, getContext());
4365 Expr = ARM64MCExpr::Create(Expr, ARM64MCExpr::VK_TLSDESC, getContext());
4368 Inst.setOpcode(ARM64::TLSDESCCALL);
4369 Inst.addOperand(MCOperand::CreateExpr(Expr));
4371 getParser().getStreamer().EmitInstruction(Inst, STI);
4375 /// ::= .loh <lohName | lohId> label1, ..., labelN
4376 /// The number of arguments depends on the loh identifier.
4377 bool ARM64AsmParser::parseDirectiveLOH(StringRef IDVal, SMLoc Loc) {
4378 if (IDVal != MCLOHDirectiveName())
4381 if (getParser().getTok().isNot(AsmToken::Identifier)) {
4382 if (getParser().getTok().isNot(AsmToken::Integer))
4383 return TokError("expected an identifier or a number in directive");
4384 // We successfully get a numeric value for the identifier.
4385 // Check if it is valid.
4386 int64_t Id = getParser().getTok().getIntVal();
4387 Kind = (MCLOHType)Id;
4388 // Check that Id does not overflow MCLOHType.
4389 if (!isValidMCLOHType(Kind) || Id != Kind)
4390 return TokError("invalid numeric identifier in directive");
4392 StringRef Name = getTok().getIdentifier();
4393 // We successfully parse an identifier.
4394 // Check if it is a recognized one.
4395 int Id = MCLOHNameToId(Name);
4398 return TokError("invalid identifier in directive");
4399 Kind = (MCLOHType)Id;
4401 // Consume the identifier.
4403 // Get the number of arguments of this LOH.
4404 int NbArgs = MCLOHIdToNbArgs(Kind);
4406 assert(NbArgs != -1 && "Invalid number of arguments");
4408 SmallVector<MCSymbol *, 3> Args;
4409 for (int Idx = 0; Idx < NbArgs; ++Idx) {
4411 if (getParser().parseIdentifier(Name))
4412 return TokError("expected identifier in directive");
4413 Args.push_back(getContext().GetOrCreateSymbol(Name));
4415 if (Idx + 1 == NbArgs)
4417 if (getLexer().isNot(AsmToken::Comma))
4418 return TokError("unexpected token in '" + Twine(IDVal) + "' directive");
4421 if (getLexer().isNot(AsmToken::EndOfStatement))
4422 return TokError("unexpected token in '" + Twine(IDVal) + "' directive");
4424 getStreamer().EmitLOHDirective((MCLOHType)Kind, Args);
4429 ARM64AsmParser::classifySymbolRef(const MCExpr *Expr,
4430 ARM64MCExpr::VariantKind &ELFRefKind,
4431 MCSymbolRefExpr::VariantKind &DarwinRefKind,
4432 const MCConstantExpr *&Addend) {
4433 ELFRefKind = ARM64MCExpr::VK_INVALID;
4434 DarwinRefKind = MCSymbolRefExpr::VK_None;
4436 if (const ARM64MCExpr *AE = dyn_cast<ARM64MCExpr>(Expr)) {
4437 ELFRefKind = AE->getKind();
4438 Expr = AE->getSubExpr();
4441 const MCSymbolRefExpr *SE = dyn_cast<MCSymbolRefExpr>(Expr);
4443 // It's a simple symbol reference with no addend.
4444 DarwinRefKind = SE->getKind();
4449 const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr);
4453 SE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
4456 DarwinRefKind = SE->getKind();
4458 if (BE->getOpcode() != MCBinaryExpr::Add)
4461 // See if the addend is is a constant, otherwise there's more going
4462 // on here than we can deal with.
4463 Addend = dyn_cast<MCConstantExpr>(BE->getRHS());
4467 // It's some symbol reference + a constant addend, but really
4468 // shouldn't use both Darwin and ELF syntax.
4469 return ELFRefKind == ARM64MCExpr::VK_INVALID ||
4470 DarwinRefKind == MCSymbolRefExpr::VK_None;
4473 /// Force static initialization.
4474 extern "C" void LLVMInitializeARM64AsmParser() {
4475 RegisterMCAsmParser<ARM64AsmParser> X(TheARM64Target);
4478 #define GET_REGISTER_MATCHER
4479 #define GET_MATCHER_IMPLEMENTATION
4480 #include "ARM64GenAsmMatcher.inc"
4482 // Define this matcher function after the auto-generated include so we
4483 // have the match class enum definitions.
4484 unsigned ARM64AsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
4486 ARM64Operand *Op = static_cast<ARM64Operand *>(AsmOp);
4487 // If the kind is a token for a literal immediate, check if our asm
4488 // operand matches. This is for InstAliases which have a fixed-value
4489 // immediate in the syntax.
4490 int64_t ExpectedVal;
4493 return Match_InvalidOperand;
4535 return Match_InvalidOperand;
4536 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
4538 return Match_InvalidOperand;
4539 if (CE->getValue() == ExpectedVal)
4540 return Match_Success;
4541 return Match_InvalidOperand;