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 tryParseSysReg(OperandVector &Operands);
93 OperandMatchResultTy tryParseSysCROperand(OperandVector &Operands);
94 OperandMatchResultTy tryParsePrefetch(OperandVector &Operands);
95 OperandMatchResultTy tryParseAdrpLabel(OperandVector &Operands);
96 OperandMatchResultTy tryParseAdrLabel(OperandVector &Operands);
97 OperandMatchResultTy tryParseFPImm(OperandVector &Operands);
98 bool tryParseVectorRegister(OperandVector &Operands);
101 enum ARM64MatchResultTy {
102 Match_InvalidSuffix = FIRST_TARGET_MATCH_RESULT_TY,
103 #define GET_OPERAND_DIAGNOSTIC_TYPES
104 #include "ARM64GenAsmMatcher.inc"
106 ARM64AsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
107 const MCInstrInfo &MII)
108 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
109 MCAsmParserExtension::Initialize(_Parser);
112 virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
113 SMLoc NameLoc, OperandVector &Operands);
114 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
115 virtual bool ParseDirective(AsmToken DirectiveID);
116 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
118 static bool classifySymbolRef(const MCExpr *Expr,
119 ARM64MCExpr::VariantKind &ELFRefKind,
120 MCSymbolRefExpr::VariantKind &DarwinRefKind,
121 const MCConstantExpr *&Addend);
123 } // end anonymous namespace
127 /// ARM64Operand - Instances of this class represent a parsed ARM64 machine
129 class ARM64Operand : public MCParsedAsmOperand {
132 ImmediateOffset, // pre-indexed, no writeback
133 RegisterOffset // register offset, with optional extend
153 SMLoc StartLoc, EndLoc, OffsetLoc;
158 bool IsSuffix; // Is the operand actually a suffix on the mnemonic.
166 struct VectorListOp {
169 unsigned NumElements;
170 unsigned ElementKind;
173 struct VectorIndexOp {
182 unsigned Val; // Encoded 8-bit representation.
186 unsigned Val; // Not the enum since not all values have names.
210 // This is for all forms of ARM64 address expressions
212 unsigned BaseRegNum, OffsetRegNum;
213 ARM64_AM::ExtendType ExtType;
216 const MCExpr *OffsetImm;
223 struct VectorListOp VectorList;
224 struct VectorIndexOp VectorIndex;
226 struct FPImmOp FPImm;
227 struct BarrierOp Barrier;
228 struct SysRegOp SysReg;
229 struct SysCRImmOp SysCRImm;
230 struct PrefetchOp Prefetch;
231 struct ShifterOp Shifter;
232 struct ExtendOp Extend;
236 // Keep the MCContext around as the MCExprs may need manipulated during
237 // the add<>Operands() calls.
240 ARM64Operand(KindTy K, MCContext &_Ctx)
241 : MCParsedAsmOperand(), Kind(K), Ctx(_Ctx) {}
244 ARM64Operand(const ARM64Operand &o) : MCParsedAsmOperand(), Ctx(o.Ctx) {
246 StartLoc = o.StartLoc;
265 VectorList = o.VectorList;
268 VectorIndex = o.VectorIndex;
274 SysCRImm = o.SysCRImm;
277 Prefetch = o.Prefetch;
291 /// getStartLoc - Get the location of the first token of this operand.
292 SMLoc getStartLoc() const { return StartLoc; }
293 /// getEndLoc - Get the location of the last token of this operand.
294 SMLoc getEndLoc() const { return EndLoc; }
295 /// getOffsetLoc - Get the location of the offset of this memory operand.
296 SMLoc getOffsetLoc() const { return OffsetLoc; }
298 StringRef getToken() const {
299 assert(Kind == k_Token && "Invalid access!");
300 return StringRef(Tok.Data, Tok.Length);
303 bool isTokenSuffix() const {
304 assert(Kind == k_Token && "Invalid access!");
308 const MCExpr *getImm() const {
309 assert(Kind == k_Immediate && "Invalid access!");
313 unsigned getFPImm() const {
314 assert(Kind == k_FPImm && "Invalid access!");
318 unsigned getBarrier() const {
319 assert(Kind == k_Barrier && "Invalid access!");
323 unsigned getReg() const {
324 assert(Kind == k_Register && "Invalid access!");
328 unsigned getVectorListStart() const {
329 assert(Kind == k_VectorList && "Invalid access!");
330 return VectorList.RegNum;
333 unsigned getVectorListCount() const {
334 assert(Kind == k_VectorList && "Invalid access!");
335 return VectorList.Count;
338 unsigned getVectorIndex() const {
339 assert(Kind == k_VectorIndex && "Invalid access!");
340 return VectorIndex.Val;
343 StringRef getSysReg() const {
344 assert(Kind == k_SysReg && "Invalid access!");
345 return StringRef(SysReg.Data, SysReg.Length);
348 unsigned getSysCR() const {
349 assert(Kind == k_SysCR && "Invalid access!");
353 unsigned getPrefetch() const {
354 assert(Kind == k_Prefetch && "Invalid access!");
358 unsigned getShifter() const {
359 assert(Kind == k_Shifter && "Invalid access!");
363 unsigned getExtend() const {
364 assert(Kind == k_Extend && "Invalid access!");
368 bool isImm() const { return Kind == k_Immediate; }
369 bool isSImm9() const {
372 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
375 int64_t Val = MCE->getValue();
376 return (Val >= -256 && Val < 256);
378 bool isSImm7s4() const {
381 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
384 int64_t Val = MCE->getValue();
385 return (Val >= -256 && Val <= 252 && (Val & 3) == 0);
387 bool isSImm7s8() const {
390 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
393 int64_t Val = MCE->getValue();
394 return (Val >= -512 && Val <= 504 && (Val & 7) == 0);
396 bool isSImm7s16() const {
399 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
402 int64_t Val = MCE->getValue();
403 return (Val >= -1024 && Val <= 1008 && (Val & 15) == 0);
405 bool isImm0_7() const {
408 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
411 int64_t Val = MCE->getValue();
412 return (Val >= 0 && Val < 8);
414 bool isImm1_8() const {
417 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
420 int64_t Val = MCE->getValue();
421 return (Val > 0 && Val < 9);
423 bool isImm0_15() const {
426 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
429 int64_t Val = MCE->getValue();
430 return (Val >= 0 && Val < 16);
432 bool isImm1_16() const {
435 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
438 int64_t Val = MCE->getValue();
439 return (Val > 0 && Val < 17);
441 bool isImm0_31() const {
444 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
447 int64_t Val = MCE->getValue();
448 return (Val >= 0 && Val < 32);
450 bool isImm1_31() const {
453 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
456 int64_t Val = MCE->getValue();
457 return (Val >= 1 && Val < 32);
459 bool isImm1_32() const {
462 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
465 int64_t Val = MCE->getValue();
466 return (Val >= 1 && Val < 33);
468 bool isImm0_63() const {
471 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
474 int64_t Val = MCE->getValue();
475 return (Val >= 0 && Val < 64);
477 bool isImm1_63() const {
480 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
483 int64_t Val = MCE->getValue();
484 return (Val >= 1 && Val < 64);
486 bool isImm1_64() const {
489 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
492 int64_t Val = MCE->getValue();
493 return (Val >= 1 && Val < 65);
495 bool isImm0_127() const {
498 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
501 int64_t Val = MCE->getValue();
502 return (Val >= 0 && Val < 128);
504 bool isImm0_255() const {
507 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
510 int64_t Val = MCE->getValue();
511 return (Val >= 0 && Val < 256);
513 bool isImm0_65535() const {
516 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
519 int64_t Val = MCE->getValue();
520 return (Val >= 0 && Val < 65536);
522 bool isLogicalImm32() const {
525 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
528 return ARM64_AM::isLogicalImmediate(MCE->getValue(), 32);
530 bool isLogicalImm64() const {
533 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
536 return ARM64_AM::isLogicalImmediate(MCE->getValue(), 64);
538 bool isSIMDImmType10() const {
541 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
544 return ARM64_AM::isAdvSIMDModImmType10(MCE->getValue());
546 bool isBranchTarget26() const {
549 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
552 int64_t Val = MCE->getValue();
555 return (Val >= -(0x2000000 << 2) && Val <= (0x1ffffff << 2));
557 bool isBranchTarget19() const {
560 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
563 int64_t Val = MCE->getValue();
566 return (Val >= -(0x40000 << 2) && Val <= (0x3ffff << 2));
568 bool isBranchTarget14() const {
571 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
574 int64_t Val = MCE->getValue();
577 return (Val >= -(0x2000 << 2) && Val <= (0x1fff << 2));
580 bool isMovWSymbol(ArrayRef<ARM64MCExpr::VariantKind> AllowedModifiers) const {
584 ARM64MCExpr::VariantKind ELFRefKind;
585 MCSymbolRefExpr::VariantKind DarwinRefKind;
586 const MCConstantExpr *Addend;
587 if (!ARM64AsmParser::classifySymbolRef(getImm(), ELFRefKind, DarwinRefKind,
591 if (DarwinRefKind != MCSymbolRefExpr::VK_None)
594 for (unsigned i = 0; i != AllowedModifiers.size(); ++i) {
595 if (ELFRefKind == AllowedModifiers[i])
602 bool isMovZSymbolG3() const {
603 static ARM64MCExpr::VariantKind Variants[] = { ARM64MCExpr::VK_ABS_G3 };
604 return isMovWSymbol(Variants);
607 bool isMovZSymbolG2() const {
608 static ARM64MCExpr::VariantKind Variants[] = { ARM64MCExpr::VK_ABS_G2,
609 ARM64MCExpr::VK_TPREL_G2,
610 ARM64MCExpr::VK_DTPREL_G2 };
611 return isMovWSymbol(Variants);
614 bool isMovZSymbolG1() const {
615 static ARM64MCExpr::VariantKind Variants[] = { ARM64MCExpr::VK_ABS_G1,
616 ARM64MCExpr::VK_GOTTPREL_G1,
617 ARM64MCExpr::VK_TPREL_G1,
618 ARM64MCExpr::VK_DTPREL_G1, };
619 return isMovWSymbol(Variants);
622 bool isMovZSymbolG0() const {
623 static ARM64MCExpr::VariantKind Variants[] = { ARM64MCExpr::VK_ABS_G0,
624 ARM64MCExpr::VK_TPREL_G0,
625 ARM64MCExpr::VK_DTPREL_G0 };
626 return isMovWSymbol(Variants);
629 bool isMovKSymbolG2() const {
630 static ARM64MCExpr::VariantKind Variants[] = { ARM64MCExpr::VK_ABS_G2_NC };
631 return isMovWSymbol(Variants);
634 bool isMovKSymbolG1() const {
635 static ARM64MCExpr::VariantKind Variants[] = {
636 ARM64MCExpr::VK_ABS_G1_NC, ARM64MCExpr::VK_TPREL_G1_NC,
637 ARM64MCExpr::VK_DTPREL_G1_NC
639 return isMovWSymbol(Variants);
642 bool isMovKSymbolG0() const {
643 static ARM64MCExpr::VariantKind Variants[] = {
644 ARM64MCExpr::VK_ABS_G0_NC, ARM64MCExpr::VK_GOTTPREL_G0_NC,
645 ARM64MCExpr::VK_TPREL_G0_NC, ARM64MCExpr::VK_DTPREL_G0_NC
647 return isMovWSymbol(Variants);
650 bool isFPImm() const { return Kind == k_FPImm; }
651 bool isBarrier() const { return Kind == k_Barrier; }
652 bool isSysReg() const { return Kind == k_SysReg; }
653 bool isMRSSystemRegister() const {
654 if (!isSysReg()) return false;
656 bool IsKnownRegister;
657 ARM64SysReg::MRSMapper().fromString(getSysReg(), IsKnownRegister);
659 return IsKnownRegister;
661 bool isMSRSystemRegister() const {
662 if (!isSysReg()) return false;
664 bool IsKnownRegister;
665 ARM64SysReg::MSRMapper().fromString(getSysReg(), IsKnownRegister);
667 return IsKnownRegister;
669 bool isSystemCPSRField() const {
670 if (!isSysReg()) return false;
672 bool IsKnownRegister;
673 ARM64PState::PStateMapper().fromString(getSysReg(), IsKnownRegister);
675 return IsKnownRegister;
677 bool isReg() const { return Kind == k_Register && !Reg.isVector; }
678 bool isVectorReg() const { return Kind == k_Register && Reg.isVector; }
680 /// Is this a vector list with the type implicit (presumably attached to the
681 /// instruction itself)?
682 template <unsigned NumRegs> bool isImplicitlyTypedVectorList() const {
683 return Kind == k_VectorList && VectorList.Count == NumRegs &&
684 !VectorList.ElementKind;
687 template <unsigned NumRegs, unsigned NumElements, char ElementKind>
688 bool isTypedVectorList() const {
689 if (Kind != k_VectorList)
691 if (VectorList.Count != NumRegs)
693 if (VectorList.ElementKind != ElementKind)
695 return VectorList.NumElements == NumElements;
698 bool isVectorIndexB() const {
699 return Kind == k_VectorIndex && VectorIndex.Val < 16;
701 bool isVectorIndexH() const {
702 return Kind == k_VectorIndex && VectorIndex.Val < 8;
704 bool isVectorIndexS() const {
705 return Kind == k_VectorIndex && VectorIndex.Val < 4;
707 bool isVectorIndexD() const {
708 return Kind == k_VectorIndex && VectorIndex.Val < 2;
710 bool isToken() const { return Kind == k_Token; }
711 bool isTokenEqual(StringRef Str) const {
712 return Kind == k_Token && getToken() == Str;
714 bool isMem() const { return Kind == k_Memory; }
715 bool isSysCR() const { return Kind == k_SysCR; }
716 bool isPrefetch() const { return Kind == k_Prefetch; }
717 bool isShifter() const { return Kind == k_Shifter; }
718 bool isExtend() const {
719 // lsl is an alias for UXTW but will be a parsed as a k_Shifter operand.
721 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(Shifter.Val);
722 return ST == ARM64_AM::LSL;
724 return Kind == k_Extend;
726 bool isExtend64() const {
727 if (Kind != k_Extend)
729 // UXTX and SXTX require a 64-bit source register (the ExtendLSL64 class).
730 ARM64_AM::ExtendType ET = ARM64_AM::getArithExtendType(Extend.Val);
731 return ET != ARM64_AM::UXTX && ET != ARM64_AM::SXTX;
733 bool isExtendLSL64() const {
734 // lsl is an alias for UXTX but will be a parsed as a k_Shifter operand.
736 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(Shifter.Val);
737 return ST == ARM64_AM::LSL;
739 if (Kind != k_Extend)
741 ARM64_AM::ExtendType ET = ARM64_AM::getArithExtendType(Extend.Val);
742 return ET == ARM64_AM::UXTX || ET == ARM64_AM::SXTX;
745 bool isArithmeticShifter() const {
749 // An arithmetic shifter is LSL, LSR, or ASR.
750 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(Shifter.Val);
751 return ST == ARM64_AM::LSL || ST == ARM64_AM::LSR || ST == ARM64_AM::ASR;
754 bool isMovImm32Shifter() const {
758 // A MOVi shifter is LSL of 0, 16, 32, or 48.
759 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(Shifter.Val);
760 if (ST != ARM64_AM::LSL)
762 uint64_t Val = ARM64_AM::getShiftValue(Shifter.Val);
763 return (Val == 0 || Val == 16);
766 bool isMovImm64Shifter() const {
770 // A MOVi shifter is LSL of 0 or 16.
771 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(Shifter.Val);
772 if (ST != ARM64_AM::LSL)
774 uint64_t Val = ARM64_AM::getShiftValue(Shifter.Val);
775 return (Val == 0 || Val == 16 || Val == 32 || Val == 48);
778 bool isAddSubShifter() const {
782 // An ADD/SUB shifter is either 'lsl #0' or 'lsl #12'.
783 unsigned Val = Shifter.Val;
784 return ARM64_AM::getShiftType(Val) == ARM64_AM::LSL &&
785 (ARM64_AM::getShiftValue(Val) == 0 ||
786 ARM64_AM::getShiftValue(Val) == 12);
789 bool isLogicalVecShifter() const {
793 // A logical vector shifter is a left shift by 0, 8, 16, or 24.
794 unsigned Val = Shifter.Val;
795 unsigned Shift = ARM64_AM::getShiftValue(Val);
796 return ARM64_AM::getShiftType(Val) == ARM64_AM::LSL &&
797 (Shift == 0 || Shift == 8 || Shift == 16 || Shift == 24);
800 bool isLogicalVecHalfWordShifter() const {
801 if (!isLogicalVecShifter())
804 // A logical vector shifter is a left shift by 0 or 8.
805 unsigned Val = Shifter.Val;
806 unsigned Shift = ARM64_AM::getShiftValue(Val);
807 return ARM64_AM::getShiftType(Val) == ARM64_AM::LSL &&
808 (Shift == 0 || Shift == 8);
811 bool isMoveVecShifter() const {
815 // A logical vector shifter is a left shift by 8 or 16.
816 unsigned Val = Shifter.Val;
817 unsigned Shift = ARM64_AM::getShiftValue(Val);
818 return ARM64_AM::getShiftType(Val) == ARM64_AM::MSL &&
819 (Shift == 8 || Shift == 16);
822 bool isMemoryRegisterOffset8() const {
823 return isMem() && Mem.Mode == RegisterOffset && Mem.ShiftVal == 0;
826 bool isMemoryRegisterOffset16() const {
827 return isMem() && Mem.Mode == RegisterOffset &&
828 (Mem.ShiftVal == 0 || Mem.ShiftVal == 1);
831 bool isMemoryRegisterOffset32() const {
832 return isMem() && Mem.Mode == RegisterOffset &&
833 (Mem.ShiftVal == 0 || Mem.ShiftVal == 2);
836 bool isMemoryRegisterOffset64() const {
837 return isMem() && Mem.Mode == RegisterOffset &&
838 (Mem.ShiftVal == 0 || Mem.ShiftVal == 3);
841 bool isMemoryRegisterOffset128() const {
842 return isMem() && Mem.Mode == RegisterOffset &&
843 (Mem.ShiftVal == 0 || Mem.ShiftVal == 4);
846 bool isMemoryUnscaled() const {
849 if (Mem.Mode != ImmediateOffset)
853 // Make sure the immediate value is valid.
854 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
857 // The offset must fit in a signed 9-bit unscaled immediate.
858 int64_t Value = CE->getValue();
859 return (Value >= -256 && Value < 256);
861 // Fallback unscaled operands are for aliases of LDR/STR that fall back
862 // to LDUR/STUR when the offset is not legal for the former but is for
863 // the latter. As such, in addition to checking for being a legal unscaled
864 // address, also check that it is not a legal scaled address. This avoids
865 // ambiguity in the matcher.
866 bool isMemoryUnscaledFB8() const {
867 return isMemoryUnscaled() && !isMemoryIndexed8();
869 bool isMemoryUnscaledFB16() const {
870 return isMemoryUnscaled() && !isMemoryIndexed16();
872 bool isMemoryUnscaledFB32() const {
873 return isMemoryUnscaled() && !isMemoryIndexed32();
875 bool isMemoryUnscaledFB64() const {
876 return isMemoryUnscaled() && !isMemoryIndexed64();
878 bool isMemoryUnscaledFB128() const {
879 return isMemoryUnscaled() && !isMemoryIndexed128();
881 bool isMemoryIndexed(unsigned Scale) const {
884 if (Mem.Mode != ImmediateOffset)
888 // Make sure the immediate value is valid.
889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
892 // The offset must be a positive multiple of the scale and in range of
893 // encoding with a 12-bit immediate.
894 int64_t Value = CE->getValue();
895 return (Value >= 0 && (Value % Scale) == 0 && Value <= (4095 * Scale));
898 // If it's not a constant, check for some expressions we know.
899 const MCExpr *Expr = Mem.OffsetImm;
900 ARM64MCExpr::VariantKind ELFRefKind;
901 MCSymbolRefExpr::VariantKind DarwinRefKind;
902 const MCConstantExpr *Addend;
903 if (!ARM64AsmParser::classifySymbolRef(Expr, ELFRefKind, DarwinRefKind,
905 // If we don't understand the expression, assume the best and
906 // let the fixup and relocation code deal with it.
910 if (DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
911 ELFRefKind == ARM64MCExpr::VK_LO12 ||
912 ELFRefKind == ARM64MCExpr::VK_GOT_LO12 ||
913 ELFRefKind == ARM64MCExpr::VK_DTPREL_LO12 ||
914 ELFRefKind == ARM64MCExpr::VK_DTPREL_LO12_NC ||
915 ELFRefKind == ARM64MCExpr::VK_TPREL_LO12 ||
916 ELFRefKind == ARM64MCExpr::VK_TPREL_LO12_NC ||
917 ELFRefKind == ARM64MCExpr::VK_GOTTPREL_LO12_NC ||
918 ELFRefKind == ARM64MCExpr::VK_TLSDESC_LO12) {
919 // Note that we don't range-check the addend. It's adjusted modulo page
920 // size when converted, so there is no "out of range" condition when using
922 int64_t Value = Addend ? Addend->getValue() : 0;
923 return Value >= 0 && (Value % Scale) == 0;
924 } else if (DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGEOFF ||
925 DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGEOFF) {
926 // @gotpageoff/@tlvppageoff can only be used directly, not with an addend.
932 bool isMemoryIndexed128() const { return isMemoryIndexed(16); }
933 bool isMemoryIndexed64() const { return isMemoryIndexed(8); }
934 bool isMemoryIndexed32() const { return isMemoryIndexed(4); }
935 bool isMemoryIndexed16() const { return isMemoryIndexed(2); }
936 bool isMemoryIndexed8() const { return isMemoryIndexed(1); }
937 bool isMemoryNoIndex() const {
940 if (Mem.Mode != ImmediateOffset)
945 // Make sure the immediate value is valid. Only zero is allowed.
946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
947 if (!CE || CE->getValue() != 0)
951 bool isMemorySIMDNoIndex() const {
954 if (Mem.Mode != ImmediateOffset)
956 return Mem.OffsetImm == 0;
958 bool isMemoryIndexedSImm9() const {
959 if (!isMem() || Mem.Mode != ImmediateOffset)
963 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
964 assert(CE && "Non-constant pre-indexed offset!");
965 int64_t Value = CE->getValue();
966 return Value >= -256 && Value <= 255;
968 bool isMemoryIndexed32SImm7() const {
969 if (!isMem() || Mem.Mode != ImmediateOffset)
973 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
974 assert(CE && "Non-constant pre-indexed offset!");
975 int64_t Value = CE->getValue();
976 return ((Value % 4) == 0) && Value >= -256 && Value <= 252;
978 bool isMemoryIndexed64SImm7() const {
979 if (!isMem() || Mem.Mode != ImmediateOffset)
983 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
984 assert(CE && "Non-constant pre-indexed offset!");
985 int64_t Value = CE->getValue();
986 return ((Value % 8) == 0) && Value >= -512 && Value <= 504;
988 bool isMemoryIndexed128SImm7() const {
989 if (!isMem() || Mem.Mode != ImmediateOffset)
993 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
994 assert(CE && "Non-constant pre-indexed offset!");
995 int64_t Value = CE->getValue();
996 return ((Value % 16) == 0) && Value >= -1024 && Value <= 1008;
999 bool isAdrpLabel() const {
1000 // Validation was handled during parsing, so we just sanity check that
1001 // something didn't go haywire.
1005 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
1006 int64_t Val = CE->getValue();
1007 int64_t Min = - (4096 * (1LL << (21 - 1)));
1008 int64_t Max = 4096 * ((1LL << (21 - 1)) - 1);
1009 return (Val % 4096) == 0 && Val >= Min && Val <= Max;
1015 bool isAdrLabel() const {
1016 // Validation was handled during parsing, so we just sanity check that
1017 // something didn't go haywire.
1021 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
1022 int64_t Val = CE->getValue();
1023 int64_t Min = - (1LL << (21 - 1));
1024 int64_t Max = ((1LL << (21 - 1)) - 1);
1025 return Val >= Min && Val <= Max;
1031 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1032 // Add as immediates when possible. Null MCExpr = 0.
1034 Inst.addOperand(MCOperand::CreateImm(0));
1035 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1036 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1038 Inst.addOperand(MCOperand::CreateExpr(Expr));
1041 void addRegOperands(MCInst &Inst, unsigned N) const {
1042 assert(N == 1 && "Invalid number of operands!");
1043 Inst.addOperand(MCOperand::CreateReg(getReg()));
1046 void addVectorRegOperands(MCInst &Inst, unsigned N) const {
1047 assert(N == 1 && "Invalid number of operands!");
1048 Inst.addOperand(MCOperand::CreateReg(getReg()));
1051 template <unsigned NumRegs>
1052 void addVectorList64Operands(MCInst &Inst, unsigned N) const {
1053 assert(N == 1 && "Invalid number of operands!");
1054 static unsigned FirstRegs[] = { ARM64::D0, ARM64::D0_D1,
1055 ARM64::D0_D1_D2, ARM64::D0_D1_D2_D3 };
1056 unsigned FirstReg = FirstRegs[NumRegs - 1];
1059 MCOperand::CreateReg(FirstReg + getVectorListStart() - ARM64::Q0));
1062 template <unsigned NumRegs>
1063 void addVectorList128Operands(MCInst &Inst, unsigned N) const {
1064 assert(N == 1 && "Invalid number of operands!");
1065 static unsigned FirstRegs[] = { ARM64::Q0, ARM64::Q0_Q1,
1066 ARM64::Q0_Q1_Q2, ARM64::Q0_Q1_Q2_Q3 };
1067 unsigned FirstReg = FirstRegs[NumRegs - 1];
1070 MCOperand::CreateReg(FirstReg + getVectorListStart() - ARM64::Q0));
1073 void addVectorIndexBOperands(MCInst &Inst, unsigned N) const {
1074 assert(N == 1 && "Invalid number of operands!");
1075 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1078 void addVectorIndexHOperands(MCInst &Inst, unsigned N) const {
1079 assert(N == 1 && "Invalid number of operands!");
1080 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1083 void addVectorIndexSOperands(MCInst &Inst, unsigned N) const {
1084 assert(N == 1 && "Invalid number of operands!");
1085 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1088 void addVectorIndexDOperands(MCInst &Inst, unsigned N) const {
1089 assert(N == 1 && "Invalid number of operands!");
1090 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1093 void addImmOperands(MCInst &Inst, unsigned N) const {
1094 assert(N == 1 && "Invalid number of operands!");
1095 // If this is a pageoff symrefexpr with an addend, adjust the addend
1096 // to be only the page-offset portion. Otherwise, just add the expr
1098 addExpr(Inst, getImm());
1101 void addAdrpLabelOperands(MCInst &Inst, unsigned N) const {
1102 assert(N == 1 && "Invalid number of operands!");
1103 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1105 addExpr(Inst, getImm());
1107 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() >> 12));
1110 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1111 addImmOperands(Inst, N);
1114 void addSImm9Operands(MCInst &Inst, unsigned N) const {
1115 assert(N == 1 && "Invalid number of operands!");
1116 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1117 assert(MCE && "Invalid constant immediate operand!");
1118 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1121 void addSImm7s4Operands(MCInst &Inst, unsigned N) const {
1122 assert(N == 1 && "Invalid number of operands!");
1123 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1124 assert(MCE && "Invalid constant immediate operand!");
1125 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() / 4));
1128 void addSImm7s8Operands(MCInst &Inst, unsigned N) const {
1129 assert(N == 1 && "Invalid number of operands!");
1130 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1131 assert(MCE && "Invalid constant immediate operand!");
1132 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() / 8));
1135 void addSImm7s16Operands(MCInst &Inst, unsigned N) const {
1136 assert(N == 1 && "Invalid number of operands!");
1137 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1138 assert(MCE && "Invalid constant immediate operand!");
1139 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() / 16));
1142 void addImm0_7Operands(MCInst &Inst, unsigned N) const {
1143 assert(N == 1 && "Invalid number of operands!");
1144 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1145 assert(MCE && "Invalid constant immediate operand!");
1146 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1149 void addImm1_8Operands(MCInst &Inst, unsigned N) const {
1150 assert(N == 1 && "Invalid number of operands!");
1151 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1152 assert(MCE && "Invalid constant immediate operand!");
1153 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1156 void addImm0_15Operands(MCInst &Inst, unsigned N) const {
1157 assert(N == 1 && "Invalid number of operands!");
1158 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1159 assert(MCE && "Invalid constant immediate operand!");
1160 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1163 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1164 assert(N == 1 && "Invalid number of operands!");
1165 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1166 assert(MCE && "Invalid constant immediate operand!");
1167 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1170 void addImm0_31Operands(MCInst &Inst, unsigned N) const {
1171 assert(N == 1 && "Invalid number of operands!");
1172 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1173 assert(MCE && "Invalid constant immediate operand!");
1174 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1177 void addImm1_31Operands(MCInst &Inst, unsigned N) const {
1178 assert(N == 1 && "Invalid number of operands!");
1179 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1180 assert(MCE && "Invalid constant immediate operand!");
1181 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1184 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1185 assert(N == 1 && "Invalid number of operands!");
1186 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1187 assert(MCE && "Invalid constant immediate operand!");
1188 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1191 void addImm0_63Operands(MCInst &Inst, unsigned N) const {
1192 assert(N == 1 && "Invalid number of operands!");
1193 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1194 assert(MCE && "Invalid constant immediate operand!");
1195 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1198 void addImm1_63Operands(MCInst &Inst, unsigned N) const {
1199 assert(N == 1 && "Invalid number of operands!");
1200 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1201 assert(MCE && "Invalid constant immediate operand!");
1202 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1205 void addImm1_64Operands(MCInst &Inst, unsigned N) const {
1206 assert(N == 1 && "Invalid number of operands!");
1207 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1208 assert(MCE && "Invalid constant immediate operand!");
1209 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1212 void addImm0_127Operands(MCInst &Inst, unsigned N) const {
1213 assert(N == 1 && "Invalid number of operands!");
1214 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1215 assert(MCE && "Invalid constant immediate operand!");
1216 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1219 void addImm0_255Operands(MCInst &Inst, unsigned N) const {
1220 assert(N == 1 && "Invalid number of operands!");
1221 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1222 assert(MCE && "Invalid constant immediate operand!");
1223 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1226 void addImm0_65535Operands(MCInst &Inst, unsigned N) const {
1227 assert(N == 1 && "Invalid number of operands!");
1228 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1229 assert(MCE && "Invalid constant immediate operand!");
1230 Inst.addOperand(MCOperand::CreateImm(MCE->getValue()));
1233 void addLogicalImm32Operands(MCInst &Inst, unsigned N) const {
1234 assert(N == 1 && "Invalid number of operands!");
1235 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1236 assert(MCE && "Invalid logical immediate operand!");
1237 uint64_t encoding = ARM64_AM::encodeLogicalImmediate(MCE->getValue(), 32);
1238 Inst.addOperand(MCOperand::CreateImm(encoding));
1241 void addLogicalImm64Operands(MCInst &Inst, unsigned N) const {
1242 assert(N == 1 && "Invalid number of operands!");
1243 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1244 assert(MCE && "Invalid logical immediate operand!");
1245 uint64_t encoding = ARM64_AM::encodeLogicalImmediate(MCE->getValue(), 64);
1246 Inst.addOperand(MCOperand::CreateImm(encoding));
1249 void addSIMDImmType10Operands(MCInst &Inst, unsigned N) const {
1250 assert(N == 1 && "Invalid number of operands!");
1251 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1252 assert(MCE && "Invalid immediate operand!");
1253 uint64_t encoding = ARM64_AM::encodeAdvSIMDModImmType10(MCE->getValue());
1254 Inst.addOperand(MCOperand::CreateImm(encoding));
1257 void addBranchTarget26Operands(MCInst &Inst, unsigned N) const {
1258 // Branch operands don't encode the low bits, so shift them off
1259 // here. If it's a label, however, just put it on directly as there's
1260 // not enough information now to do anything.
1261 assert(N == 1 && "Invalid number of operands!");
1262 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1264 addExpr(Inst, getImm());
1267 assert(MCE && "Invalid constant immediate operand!");
1268 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() >> 2));
1271 void addBranchTarget19Operands(MCInst &Inst, unsigned N) const {
1272 // Branch operands don't encode the low bits, so shift them off
1273 // here. If it's a label, however, just put it on directly as there's
1274 // not enough information now to do anything.
1275 assert(N == 1 && "Invalid number of operands!");
1276 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1278 addExpr(Inst, getImm());
1281 assert(MCE && "Invalid constant immediate operand!");
1282 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() >> 2));
1285 void addBranchTarget14Operands(MCInst &Inst, unsigned N) const {
1286 // Branch operands don't encode the low bits, so shift them off
1287 // here. If it's a label, however, just put it on directly as there's
1288 // not enough information now to do anything.
1289 assert(N == 1 && "Invalid number of operands!");
1290 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
1292 addExpr(Inst, getImm());
1295 assert(MCE && "Invalid constant immediate operand!");
1296 Inst.addOperand(MCOperand::CreateImm(MCE->getValue() >> 2));
1299 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1300 assert(N == 1 && "Invalid number of operands!");
1301 Inst.addOperand(MCOperand::CreateImm(getFPImm()));
1304 void addBarrierOperands(MCInst &Inst, unsigned N) const {
1305 assert(N == 1 && "Invalid number of operands!");
1306 Inst.addOperand(MCOperand::CreateImm(getBarrier()));
1309 void addMRSSystemRegisterOperands(MCInst &Inst, unsigned N) const {
1310 assert(N == 1 && "Invalid number of operands!");
1313 uint32_t Bits = ARM64SysReg::MRSMapper().fromString(getSysReg(), Valid);
1315 Inst.addOperand(MCOperand::CreateImm(Bits));
1318 void addMSRSystemRegisterOperands(MCInst &Inst, unsigned N) const {
1319 assert(N == 1 && "Invalid number of operands!");
1322 uint32_t Bits = ARM64SysReg::MSRMapper().fromString(getSysReg(), Valid);
1324 Inst.addOperand(MCOperand::CreateImm(Bits));
1327 void addSystemCPSRFieldOperands(MCInst &Inst, unsigned N) const {
1328 assert(N == 1 && "Invalid number of operands!");
1331 uint32_t Bits = ARM64PState::PStateMapper().fromString(getSysReg(), Valid);
1333 Inst.addOperand(MCOperand::CreateImm(Bits));
1336 void addSysCROperands(MCInst &Inst, unsigned N) const {
1337 assert(N == 1 && "Invalid number of operands!");
1338 Inst.addOperand(MCOperand::CreateImm(getSysCR()));
1341 void addPrefetchOperands(MCInst &Inst, unsigned N) const {
1342 assert(N == 1 && "Invalid number of operands!");
1343 Inst.addOperand(MCOperand::CreateImm(getPrefetch()));
1346 void addShifterOperands(MCInst &Inst, unsigned N) const {
1347 assert(N == 1 && "Invalid number of operands!");
1348 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1351 void addArithmeticShifterOperands(MCInst &Inst, unsigned N) const {
1352 assert(N == 1 && "Invalid number of operands!");
1353 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1356 void addMovImm32ShifterOperands(MCInst &Inst, unsigned N) const {
1357 assert(N == 1 && "Invalid number of operands!");
1358 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1361 void addMovImm64ShifterOperands(MCInst &Inst, unsigned N) const {
1362 assert(N == 1 && "Invalid number of operands!");
1363 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1366 void addAddSubShifterOperands(MCInst &Inst, unsigned N) const {
1367 assert(N == 1 && "Invalid number of operands!");
1368 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1371 void addLogicalVecShifterOperands(MCInst &Inst, unsigned N) const {
1372 assert(N == 1 && "Invalid number of operands!");
1373 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1376 void addLogicalVecHalfWordShifterOperands(MCInst &Inst, unsigned N) const {
1377 assert(N == 1 && "Invalid number of operands!");
1378 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1381 void addMoveVecShifterOperands(MCInst &Inst, unsigned N) const {
1382 assert(N == 1 && "Invalid number of operands!");
1383 Inst.addOperand(MCOperand::CreateImm(getShifter()));
1386 void addExtendOperands(MCInst &Inst, unsigned N) const {
1387 assert(N == 1 && "Invalid number of operands!");
1388 // lsl is an alias for UXTW but will be a parsed as a k_Shifter operand.
1390 assert(ARM64_AM::getShiftType(getShifter()) == ARM64_AM::LSL);
1391 unsigned imm = getArithExtendImm(ARM64_AM::UXTW,
1392 ARM64_AM::getShiftValue(getShifter()));
1393 Inst.addOperand(MCOperand::CreateImm(imm));
1395 Inst.addOperand(MCOperand::CreateImm(getExtend()));
1398 void addExtend64Operands(MCInst &Inst, unsigned N) const {
1399 assert(N == 1 && "Invalid number of operands!");
1400 Inst.addOperand(MCOperand::CreateImm(getExtend()));
1403 void addExtendLSL64Operands(MCInst &Inst, unsigned N) const {
1404 assert(N == 1 && "Invalid number of operands!");
1405 // lsl is an alias for UXTX but will be a parsed as a k_Shifter operand.
1407 assert(ARM64_AM::getShiftType(getShifter()) == ARM64_AM::LSL);
1408 unsigned imm = getArithExtendImm(ARM64_AM::UXTX,
1409 ARM64_AM::getShiftValue(getShifter()));
1410 Inst.addOperand(MCOperand::CreateImm(imm));
1412 Inst.addOperand(MCOperand::CreateImm(getExtend()));
1415 void addMemoryRegisterOffsetOperands(MCInst &Inst, unsigned N, bool DoShift) {
1416 assert(N == 3 && "Invalid number of operands!");
1418 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1419 Inst.addOperand(MCOperand::CreateReg(getXRegFromWReg(Mem.OffsetRegNum)));
1420 unsigned ExtendImm = ARM64_AM::getMemExtendImm(Mem.ExtType, DoShift);
1421 Inst.addOperand(MCOperand::CreateImm(ExtendImm));
1424 void addMemoryRegisterOffset8Operands(MCInst &Inst, unsigned N) {
1425 addMemoryRegisterOffsetOperands(Inst, N, Mem.ExplicitShift);
1428 void addMemoryRegisterOffset16Operands(MCInst &Inst, unsigned N) {
1429 addMemoryRegisterOffsetOperands(Inst, N, Mem.ShiftVal == 1);
1432 void addMemoryRegisterOffset32Operands(MCInst &Inst, unsigned N) {
1433 addMemoryRegisterOffsetOperands(Inst, N, Mem.ShiftVal == 2);
1436 void addMemoryRegisterOffset64Operands(MCInst &Inst, unsigned N) {
1437 addMemoryRegisterOffsetOperands(Inst, N, Mem.ShiftVal == 3);
1440 void addMemoryRegisterOffset128Operands(MCInst &Inst, unsigned N) {
1441 addMemoryRegisterOffsetOperands(Inst, N, Mem.ShiftVal == 4);
1444 void addMemoryIndexedOperands(MCInst &Inst, unsigned N,
1445 unsigned Scale) const {
1446 // Add the base register operand.
1447 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1449 if (!Mem.OffsetImm) {
1450 // There isn't an offset.
1451 Inst.addOperand(MCOperand::CreateImm(0));
1455 // Add the offset operand.
1456 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm)) {
1457 assert(CE->getValue() % Scale == 0 &&
1458 "Offset operand must be multiple of the scale!");
1460 // The MCInst offset operand doesn't include the low bits (like the
1461 // instruction encoding).
1462 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / Scale));
1465 // If this is a pageoff symrefexpr with an addend, the linker will
1466 // do the scaling of the addend.
1468 // Otherwise we don't know what this is, so just add the scaling divide to
1469 // the expression and let the MC fixup evaluation code deal with it.
1470 const MCExpr *Expr = Mem.OffsetImm;
1471 ARM64MCExpr::VariantKind ELFRefKind;
1472 MCSymbolRefExpr::VariantKind DarwinRefKind;
1473 const MCConstantExpr *Addend;
1475 (!ARM64AsmParser::classifySymbolRef(Expr, ELFRefKind, DarwinRefKind,
1477 (Addend != 0 && DarwinRefKind != MCSymbolRefExpr::VK_PAGEOFF))) {
1478 Expr = MCBinaryExpr::CreateDiv(Expr, MCConstantExpr::Create(Scale, Ctx),
1482 Inst.addOperand(MCOperand::CreateExpr(Expr));
1485 void addMemoryUnscaledOperands(MCInst &Inst, unsigned N) const {
1486 assert(N == 2 && isMemoryUnscaled() && "Invalid number of operands!");
1487 // Add the base register operand.
1488 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1490 // Add the offset operand.
1492 Inst.addOperand(MCOperand::CreateImm(0));
1494 // Only constant offsets supported.
1495 const MCConstantExpr *CE = cast<MCConstantExpr>(Mem.OffsetImm);
1496 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1500 void addMemoryIndexed128Operands(MCInst &Inst, unsigned N) const {
1501 assert(N == 2 && isMemoryIndexed128() && "Invalid number of operands!");
1502 addMemoryIndexedOperands(Inst, N, 16);
1505 void addMemoryIndexed64Operands(MCInst &Inst, unsigned N) const {
1506 assert(N == 2 && isMemoryIndexed64() && "Invalid number of operands!");
1507 addMemoryIndexedOperands(Inst, N, 8);
1510 void addMemoryIndexed32Operands(MCInst &Inst, unsigned N) const {
1511 assert(N == 2 && isMemoryIndexed32() && "Invalid number of operands!");
1512 addMemoryIndexedOperands(Inst, N, 4);
1515 void addMemoryIndexed16Operands(MCInst &Inst, unsigned N) const {
1516 assert(N == 2 && isMemoryIndexed16() && "Invalid number of operands!");
1517 addMemoryIndexedOperands(Inst, N, 2);
1520 void addMemoryIndexed8Operands(MCInst &Inst, unsigned N) const {
1521 assert(N == 2 && isMemoryIndexed8() && "Invalid number of operands!");
1522 addMemoryIndexedOperands(Inst, N, 1);
1525 void addMemoryNoIndexOperands(MCInst &Inst, unsigned N) const {
1526 assert(N == 1 && isMemoryNoIndex() && "Invalid number of operands!");
1527 // Add the base register operand (the offset is always zero, so ignore it).
1528 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1531 void addMemorySIMDNoIndexOperands(MCInst &Inst, unsigned N) const {
1532 assert(N == 1 && isMemorySIMDNoIndex() && "Invalid number of operands!");
1533 // Add the base register operand (the offset is always zero, so ignore it).
1534 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1537 void addMemoryWritebackIndexedOperands(MCInst &Inst, unsigned N,
1538 unsigned Scale) const {
1539 assert(N == 2 && "Invalid number of operands!");
1541 // Add the base register operand.
1542 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
1544 // Add the offset operand.
1546 if (Mem.OffsetImm) {
1547 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.OffsetImm);
1548 assert(CE && "Non-constant indexed offset operand!");
1549 Offset = CE->getValue();
1553 assert(Offset % Scale == 0 &&
1554 "Offset operand must be a multiple of the scale!");
1558 Inst.addOperand(MCOperand::CreateImm(Offset));
1561 void addMemoryIndexedSImm9Operands(MCInst &Inst, unsigned N) const {
1562 addMemoryWritebackIndexedOperands(Inst, N, 1);
1565 void addMemoryIndexed32SImm7Operands(MCInst &Inst, unsigned N) const {
1566 addMemoryWritebackIndexedOperands(Inst, N, 4);
1569 void addMemoryIndexed64SImm7Operands(MCInst &Inst, unsigned N) const {
1570 addMemoryWritebackIndexedOperands(Inst, N, 8);
1573 void addMemoryIndexed128SImm7Operands(MCInst &Inst, unsigned N) const {
1574 addMemoryWritebackIndexedOperands(Inst, N, 16);
1577 virtual void print(raw_ostream &OS) const;
1579 static ARM64Operand *CreateToken(StringRef Str, bool IsSuffix, SMLoc S,
1581 ARM64Operand *Op = new ARM64Operand(k_Token, Ctx);
1582 Op->Tok.Data = Str.data();
1583 Op->Tok.Length = Str.size();
1584 Op->Tok.IsSuffix = IsSuffix;
1590 static ARM64Operand *CreateReg(unsigned RegNum, bool isVector, SMLoc S,
1591 SMLoc E, MCContext &Ctx) {
1592 ARM64Operand *Op = new ARM64Operand(k_Register, Ctx);
1593 Op->Reg.RegNum = RegNum;
1594 Op->Reg.isVector = isVector;
1600 static ARM64Operand *CreateVectorList(unsigned RegNum, unsigned Count,
1601 unsigned NumElements, char ElementKind,
1602 SMLoc S, SMLoc E, MCContext &Ctx) {
1603 ARM64Operand *Op = new ARM64Operand(k_VectorList, Ctx);
1604 Op->VectorList.RegNum = RegNum;
1605 Op->VectorList.Count = Count;
1606 Op->VectorList.NumElements = NumElements;
1607 Op->VectorList.ElementKind = ElementKind;
1613 static ARM64Operand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
1615 ARM64Operand *Op = new ARM64Operand(k_VectorIndex, Ctx);
1616 Op->VectorIndex.Val = Idx;
1622 static ARM64Operand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E,
1624 ARM64Operand *Op = new ARM64Operand(k_Immediate, Ctx);
1631 static ARM64Operand *CreateFPImm(unsigned Val, SMLoc S, MCContext &Ctx) {
1632 ARM64Operand *Op = new ARM64Operand(k_FPImm, Ctx);
1633 Op->FPImm.Val = Val;
1639 static ARM64Operand *CreateBarrier(unsigned Val, SMLoc S, MCContext &Ctx) {
1640 ARM64Operand *Op = new ARM64Operand(k_Barrier, Ctx);
1641 Op->Barrier.Val = Val;
1647 static ARM64Operand *CreateSysReg(StringRef Str, SMLoc S, MCContext &Ctx) {
1648 ARM64Operand *Op = new ARM64Operand(k_SysReg, Ctx);
1649 Op->SysReg.Data = Str.data();
1650 Op->SysReg.Length = Str.size();
1656 static ARM64Operand *CreateMem(unsigned BaseRegNum, const MCExpr *Off,
1657 SMLoc S, SMLoc E, SMLoc OffsetLoc,
1659 ARM64Operand *Op = new ARM64Operand(k_Memory, Ctx);
1660 Op->Mem.BaseRegNum = BaseRegNum;
1661 Op->Mem.OffsetRegNum = 0;
1662 Op->Mem.OffsetImm = Off;
1663 Op->Mem.ExtType = ARM64_AM::UXTX;
1664 Op->Mem.ShiftVal = 0;
1665 Op->Mem.ExplicitShift = false;
1666 Op->Mem.Mode = ImmediateOffset;
1667 Op->OffsetLoc = OffsetLoc;
1673 static ARM64Operand *CreateRegOffsetMem(unsigned BaseReg, unsigned OffsetReg,
1674 ARM64_AM::ExtendType ExtType,
1675 unsigned ShiftVal, bool ExplicitShift,
1676 SMLoc S, SMLoc E, MCContext &Ctx) {
1677 ARM64Operand *Op = new ARM64Operand(k_Memory, Ctx);
1678 Op->Mem.BaseRegNum = BaseReg;
1679 Op->Mem.OffsetRegNum = OffsetReg;
1680 Op->Mem.OffsetImm = 0;
1681 Op->Mem.ExtType = ExtType;
1682 Op->Mem.ShiftVal = ShiftVal;
1683 Op->Mem.ExplicitShift = ExplicitShift;
1684 Op->Mem.Mode = RegisterOffset;
1690 static ARM64Operand *CreateSysCR(unsigned Val, SMLoc S, SMLoc E,
1692 ARM64Operand *Op = new ARM64Operand(k_SysCR, Ctx);
1693 Op->SysCRImm.Val = Val;
1699 static ARM64Operand *CreatePrefetch(unsigned Val, SMLoc S, MCContext &Ctx) {
1700 ARM64Operand *Op = new ARM64Operand(k_Prefetch, Ctx);
1701 Op->Prefetch.Val = Val;
1707 static ARM64Operand *CreateShifter(ARM64_AM::ShiftType ShOp, unsigned Val,
1708 SMLoc S, SMLoc E, MCContext &Ctx) {
1709 ARM64Operand *Op = new ARM64Operand(k_Shifter, Ctx);
1710 Op->Shifter.Val = ARM64_AM::getShifterImm(ShOp, Val);
1716 static ARM64Operand *CreateExtend(ARM64_AM::ExtendType ExtOp, unsigned Val,
1717 SMLoc S, SMLoc E, MCContext &Ctx) {
1718 ARM64Operand *Op = new ARM64Operand(k_Extend, Ctx);
1719 Op->Extend.Val = ARM64_AM::getArithExtendImm(ExtOp, Val);
1726 } // end anonymous namespace.
1728 void ARM64Operand::print(raw_ostream &OS) const {
1731 OS << "<fpimm " << getFPImm() << "(" << ARM64_AM::getFPImmFloat(getFPImm())
1736 StringRef Name = ARM64DB::DBarrierMapper().toString(getBarrier(), Valid);
1738 OS << "<barrier " << Name << ">";
1740 OS << "<barrier invalid #" << getBarrier() << ">";
1744 getImm()->print(OS);
1750 OS << "<register " << getReg() << ">";
1752 case k_VectorList: {
1753 OS << "<vectorlist ";
1754 unsigned Reg = getVectorListStart();
1755 for (unsigned i = 0, e = getVectorListCount(); i != e; ++i)
1756 OS << Reg + i << " ";
1761 OS << "<vectorindex " << getVectorIndex() << ">";
1764 OS << "<sysreg: " << getSysReg() << '>';
1767 OS << "'" << getToken() << "'";
1770 OS << "c" << getSysCR();
1774 StringRef Name = ARM64PRFM::PRFMMapper().toString(getPrefetch(), Valid);
1776 OS << "<prfop " << Name << ">";
1778 OS << "<prfop invalid #" << getPrefetch() << ">";
1782 unsigned Val = getShifter();
1783 OS << "<" << ARM64_AM::getShiftName(ARM64_AM::getShiftType(Val)) << " #"
1784 << ARM64_AM::getShiftValue(Val) << ">";
1788 unsigned Val = getExtend();
1789 OS << "<" << ARM64_AM::getExtendName(ARM64_AM::getArithExtendType(Val))
1790 << " #" << ARM64_AM::getArithShiftValue(Val) << ">";
1796 /// @name Auto-generated Match Functions
1799 static unsigned MatchRegisterName(StringRef Name);
1803 static unsigned matchVectorRegName(StringRef Name) {
1804 return StringSwitch<unsigned>(Name)
1805 .Case("v0", ARM64::Q0)
1806 .Case("v1", ARM64::Q1)
1807 .Case("v2", ARM64::Q2)
1808 .Case("v3", ARM64::Q3)
1809 .Case("v4", ARM64::Q4)
1810 .Case("v5", ARM64::Q5)
1811 .Case("v6", ARM64::Q6)
1812 .Case("v7", ARM64::Q7)
1813 .Case("v8", ARM64::Q8)
1814 .Case("v9", ARM64::Q9)
1815 .Case("v10", ARM64::Q10)
1816 .Case("v11", ARM64::Q11)
1817 .Case("v12", ARM64::Q12)
1818 .Case("v13", ARM64::Q13)
1819 .Case("v14", ARM64::Q14)
1820 .Case("v15", ARM64::Q15)
1821 .Case("v16", ARM64::Q16)
1822 .Case("v17", ARM64::Q17)
1823 .Case("v18", ARM64::Q18)
1824 .Case("v19", ARM64::Q19)
1825 .Case("v20", ARM64::Q20)
1826 .Case("v21", ARM64::Q21)
1827 .Case("v22", ARM64::Q22)
1828 .Case("v23", ARM64::Q23)
1829 .Case("v24", ARM64::Q24)
1830 .Case("v25", ARM64::Q25)
1831 .Case("v26", ARM64::Q26)
1832 .Case("v27", ARM64::Q27)
1833 .Case("v28", ARM64::Q28)
1834 .Case("v29", ARM64::Q29)
1835 .Case("v30", ARM64::Q30)
1836 .Case("v31", ARM64::Q31)
1840 static bool isValidVectorKind(StringRef Name) {
1841 return StringSwitch<bool>(Name.lower())
1851 // Accept the width neutral ones, too, for verbose syntax. If those
1852 // aren't used in the right places, the token operand won't match so
1853 // all will work out.
1861 static void parseValidVectorKind(StringRef Name, unsigned &NumElements,
1862 char &ElementKind) {
1863 assert(isValidVectorKind(Name));
1865 ElementKind = Name.lower()[Name.size() - 1];
1868 if (Name.size() == 2)
1871 // Parse the lane count
1872 Name = Name.drop_front();
1873 while (isdigit(Name.front())) {
1874 NumElements = 10 * NumElements + (Name.front() - '0');
1875 Name = Name.drop_front();
1879 bool ARM64AsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
1881 StartLoc = getLoc();
1882 RegNo = tryParseRegister();
1883 EndLoc = SMLoc::getFromPointer(getLoc().getPointer() - 1);
1884 return (RegNo == (unsigned)-1);
1887 /// tryParseRegister - Try to parse a register name. The token must be an
1888 /// Identifier when called, and if it is a register name the token is eaten and
1889 /// the register is added to the operand list.
1890 int ARM64AsmParser::tryParseRegister() {
1891 const AsmToken &Tok = Parser.getTok();
1892 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
1894 std::string lowerCase = Tok.getString().lower();
1895 unsigned RegNum = MatchRegisterName(lowerCase);
1896 // Also handle a few aliases of registers.
1898 RegNum = StringSwitch<unsigned>(lowerCase)
1899 .Case("fp", ARM64::FP)
1900 .Case("lr", ARM64::LR)
1901 .Case("x31", ARM64::XZR)
1902 .Case("w31", ARM64::WZR)
1908 Parser.Lex(); // Eat identifier token.
1912 /// tryMatchVectorRegister - Try to parse a vector register name with optional
1913 /// kind specifier. If it is a register specifier, eat the token and return it.
1914 int ARM64AsmParser::tryMatchVectorRegister(StringRef &Kind, bool expected) {
1915 if (Parser.getTok().isNot(AsmToken::Identifier)) {
1916 TokError("vector register expected");
1920 StringRef Name = Parser.getTok().getString();
1921 // If there is a kind specifier, it's separated from the register name by
1923 size_t Start = 0, Next = Name.find('.');
1924 StringRef Head = Name.slice(Start, Next);
1925 unsigned RegNum = matchVectorRegName(Head);
1927 if (Next != StringRef::npos) {
1928 Kind = Name.slice(Next, StringRef::npos);
1929 if (!isValidVectorKind(Kind)) {
1930 TokError("invalid vector kind qualifier");
1934 Parser.Lex(); // Eat the register token.
1939 TokError("vector register expected");
1943 static int MatchSysCRName(StringRef Name) {
1944 // Use the same layout as the tablegen'erated register name matcher. Ugly,
1946 switch (Name.size()) {
1950 if (Name[0] != 'c' && Name[0] != 'C')
1978 if ((Name[0] != 'c' && Name[0] != 'C') || Name[1] != '1')
1999 llvm_unreachable("Unhandled SysCR operand string!");
2003 /// tryParseSysCROperand - Try to parse a system instruction CR operand name.
2004 ARM64AsmParser::OperandMatchResultTy
2005 ARM64AsmParser::tryParseSysCROperand(OperandVector &Operands) {
2007 const AsmToken &Tok = Parser.getTok();
2008 if (Tok.isNot(AsmToken::Identifier))
2009 return MatchOperand_NoMatch;
2011 int Num = MatchSysCRName(Tok.getString());
2013 return MatchOperand_NoMatch;
2015 Parser.Lex(); // Eat identifier token.
2016 Operands.push_back(ARM64Operand::CreateSysCR(Num, S, getLoc(), getContext()));
2017 return MatchOperand_Success;
2020 /// tryParsePrefetch - Try to parse a prefetch operand.
2021 ARM64AsmParser::OperandMatchResultTy
2022 ARM64AsmParser::tryParsePrefetch(OperandVector &Operands) {
2024 const AsmToken &Tok = Parser.getTok();
2025 // Either an identifier for named values or a 5-bit immediate.
2026 bool Hash = Tok.is(AsmToken::Hash);
2027 if (Hash || Tok.is(AsmToken::Integer)) {
2029 Parser.Lex(); // Eat hash token.
2030 const MCExpr *ImmVal;
2031 if (getParser().parseExpression(ImmVal))
2032 return MatchOperand_ParseFail;
2034 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2036 TokError("immediate value expected for prefetch operand");
2037 return MatchOperand_ParseFail;
2039 unsigned prfop = MCE->getValue();
2041 TokError("prefetch operand out of range, [0,31] expected");
2042 return MatchOperand_ParseFail;
2045 Operands.push_back(ARM64Operand::CreatePrefetch(prfop, S, getContext()));
2046 return MatchOperand_Success;
2049 if (Tok.isNot(AsmToken::Identifier)) {
2050 TokError("pre-fetch hint expected");
2051 return MatchOperand_ParseFail;
2055 unsigned prfop = ARM64PRFM::PRFMMapper().fromString(Tok.getString(), Valid);
2057 TokError("pre-fetch hint expected");
2058 return MatchOperand_ParseFail;
2061 Parser.Lex(); // Eat identifier token.
2062 Operands.push_back(ARM64Operand::CreatePrefetch(prfop, S, getContext()));
2063 return MatchOperand_Success;
2066 /// tryParseAdrpLabel - Parse and validate a source label for the ADRP
2068 ARM64AsmParser::OperandMatchResultTy
2069 ARM64AsmParser::tryParseAdrpLabel(OperandVector &Operands) {
2073 if (Parser.getTok().is(AsmToken::Hash)) {
2074 Parser.Lex(); // Eat hash token.
2077 if (parseSymbolicImmVal(Expr))
2078 return MatchOperand_ParseFail;
2080 ARM64MCExpr::VariantKind ELFRefKind;
2081 MCSymbolRefExpr::VariantKind DarwinRefKind;
2082 const MCConstantExpr *Addend;
2083 if (classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
2084 if (DarwinRefKind == MCSymbolRefExpr::VK_None &&
2085 ELFRefKind == ARM64MCExpr::VK_INVALID) {
2086 // No modifier was specified at all; this is the syntax for an ELF basic
2087 // ADRP relocation (unfortunately).
2088 Expr = ARM64MCExpr::Create(Expr, ARM64MCExpr::VK_ABS_PAGE, getContext());
2089 } else if ((DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGE ||
2090 DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGE) &&
2092 Error(S, "gotpage label reference not allowed an addend");
2093 return MatchOperand_ParseFail;
2094 } else if (DarwinRefKind != MCSymbolRefExpr::VK_PAGE &&
2095 DarwinRefKind != MCSymbolRefExpr::VK_GOTPAGE &&
2096 DarwinRefKind != MCSymbolRefExpr::VK_TLVPPAGE &&
2097 ELFRefKind != ARM64MCExpr::VK_GOT_PAGE &&
2098 ELFRefKind != ARM64MCExpr::VK_GOTTPREL_PAGE &&
2099 ELFRefKind != ARM64MCExpr::VK_TLSDESC_PAGE) {
2100 // The operand must be an @page or @gotpage qualified symbolref.
2101 Error(S, "page or gotpage label reference expected");
2102 return MatchOperand_ParseFail;
2106 // We have either a label reference possibly with addend or an immediate. The
2107 // addend is a raw value here. The linker will adjust it to only reference the
2109 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2110 Operands.push_back(ARM64Operand::CreateImm(Expr, S, E, getContext()));
2112 return MatchOperand_Success;
2115 /// tryParseAdrLabel - Parse and validate a source label for the ADR
2117 ARM64AsmParser::OperandMatchResultTy
2118 ARM64AsmParser::tryParseAdrLabel(OperandVector &Operands) {
2122 if (Parser.getTok().is(AsmToken::Hash)) {
2123 Parser.Lex(); // Eat hash token.
2126 if (getParser().parseExpression(Expr))
2127 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) {
2141 if (Parser.getTok().is(AsmToken::Hash)) {
2142 Parser.Lex(); // Eat '#'
2146 // Handle negation, as that still comes through as a separate token.
2147 bool isNegative = false;
2148 if (Parser.getTok().is(AsmToken::Minus)) {
2152 const AsmToken &Tok = Parser.getTok();
2153 if (Tok.is(AsmToken::Real)) {
2154 APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
2155 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
2156 // If we had a '-' in front, toggle the sign bit.
2157 IntVal ^= (uint64_t)isNegative << 63;
2158 int Val = ARM64_AM::getFP64Imm(APInt(64, IntVal));
2159 Parser.Lex(); // Eat the token.
2160 // Check for out of range values. As an exception, we let Zero through,
2161 // as we handle that special case in post-processing before matching in
2162 // order to use the zero register for it.
2163 if (Val == -1 && !RealVal.isZero()) {
2164 TokError("floating point value out of range");
2165 return MatchOperand_ParseFail;
2167 Operands.push_back(ARM64Operand::CreateFPImm(Val, S, getContext()));
2168 return MatchOperand_Success;
2170 if (Tok.is(AsmToken::Integer)) {
2172 if (!isNegative && Tok.getString().startswith("0x")) {
2173 Val = Tok.getIntVal();
2174 if (Val > 255 || Val < 0) {
2175 TokError("encoded floating point value out of range");
2176 return MatchOperand_ParseFail;
2179 APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
2180 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
2181 // If we had a '-' in front, toggle the sign bit.
2182 IntVal ^= (uint64_t)isNegative << 63;
2183 Val = ARM64_AM::getFP64Imm(APInt(64, IntVal));
2185 Parser.Lex(); // Eat the token.
2186 Operands.push_back(ARM64Operand::CreateFPImm(Val, S, getContext()));
2187 return MatchOperand_Success;
2191 return MatchOperand_NoMatch;
2193 TokError("invalid floating point immediate");
2194 return MatchOperand_ParseFail;
2197 /// parseCondCodeString - Parse a Condition Code string.
2198 unsigned ARM64AsmParser::parseCondCodeString(StringRef Cond) {
2199 unsigned CC = StringSwitch<unsigned>(Cond.lower())
2200 .Case("eq", ARM64CC::EQ)
2201 .Case("ne", ARM64CC::NE)
2202 .Case("cs", ARM64CC::CS)
2203 .Case("hs", ARM64CC::CS)
2204 .Case("cc", ARM64CC::CC)
2205 .Case("lo", ARM64CC::CC)
2206 .Case("mi", ARM64CC::MI)
2207 .Case("pl", ARM64CC::PL)
2208 .Case("vs", ARM64CC::VS)
2209 .Case("vc", ARM64CC::VC)
2210 .Case("hi", ARM64CC::HI)
2211 .Case("ls", ARM64CC::LS)
2212 .Case("ge", ARM64CC::GE)
2213 .Case("lt", ARM64CC::LT)
2214 .Case("gt", ARM64CC::GT)
2215 .Case("le", ARM64CC::LE)
2216 .Case("al", ARM64CC::AL)
2217 .Case("nv", ARM64CC::NV)
2218 .Default(ARM64CC::Invalid);
2222 /// parseCondCode - Parse a Condition Code operand.
2223 bool ARM64AsmParser::parseCondCode(OperandVector &Operands,
2224 bool invertCondCode) {
2226 const AsmToken &Tok = Parser.getTok();
2227 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2229 StringRef Cond = Tok.getString();
2230 unsigned CC = parseCondCodeString(Cond);
2231 if (CC == ARM64CC::Invalid)
2232 return TokError("invalid condition code");
2233 Parser.Lex(); // Eat identifier token.
2236 CC = ARM64CC::getInvertedCondCode(ARM64CC::CondCode(CC));
2238 const MCExpr *CCExpr = MCConstantExpr::Create(CC, getContext());
2240 ARM64Operand::CreateImm(CCExpr, S, getLoc(), getContext()));
2244 /// ParseOptionalShift - Some operands take an optional shift argument. Parse
2245 /// them if present.
2246 bool ARM64AsmParser::parseOptionalShift(OperandVector &Operands) {
2247 const AsmToken &Tok = Parser.getTok();
2248 ARM64_AM::ShiftType ShOp = StringSwitch<ARM64_AM::ShiftType>(Tok.getString())
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 .Case("LSL", ARM64_AM::LSL)
2255 .Case("LSR", ARM64_AM::LSR)
2256 .Case("ASR", ARM64_AM::ASR)
2257 .Case("ROR", ARM64_AM::ROR)
2258 .Case("MSL", ARM64_AM::MSL)
2259 .Default(ARM64_AM::InvalidShift);
2260 if (ShOp == ARM64_AM::InvalidShift)
2263 SMLoc S = Tok.getLoc();
2266 // We expect a number here.
2267 bool Hash = getLexer().is(AsmToken::Hash);
2268 if (!Hash && getLexer().isNot(AsmToken::Integer))
2269 return TokError("immediate value expected for shifter operand");
2272 Parser.Lex(); // Eat the '#'.
2274 SMLoc ExprLoc = getLoc();
2275 const MCExpr *ImmVal;
2276 if (getParser().parseExpression(ImmVal))
2279 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2281 return TokError("immediate value expected for shifter operand");
2283 if ((MCE->getValue() & 0x3f) != MCE->getValue())
2284 return Error(ExprLoc, "immediate value too large for shifter operand");
2286 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2288 ARM64Operand::CreateShifter(ShOp, MCE->getValue(), S, E, getContext()));
2292 /// parseOptionalExtend - Some operands take an optional extend argument. Parse
2293 /// them if present.
2294 bool ARM64AsmParser::parseOptionalExtend(OperandVector &Operands) {
2295 const AsmToken &Tok = Parser.getTok();
2296 ARM64_AM::ExtendType ExtOp =
2297 StringSwitch<ARM64_AM::ExtendType>(Tok.getString())
2298 .Case("uxtb", ARM64_AM::UXTB)
2299 .Case("uxth", ARM64_AM::UXTH)
2300 .Case("uxtw", ARM64_AM::UXTW)
2301 .Case("uxtx", ARM64_AM::UXTX)
2302 .Case("lsl", ARM64_AM::UXTX) // Alias for UXTX
2303 .Case("sxtb", ARM64_AM::SXTB)
2304 .Case("sxth", ARM64_AM::SXTH)
2305 .Case("sxtw", ARM64_AM::SXTW)
2306 .Case("sxtx", ARM64_AM::SXTX)
2307 .Case("UXTB", ARM64_AM::UXTB)
2308 .Case("UXTH", ARM64_AM::UXTH)
2309 .Case("UXTW", ARM64_AM::UXTW)
2310 .Case("UXTX", ARM64_AM::UXTX)
2311 .Case("LSL", ARM64_AM::UXTX) // Alias for UXTX
2312 .Case("SXTB", ARM64_AM::SXTB)
2313 .Case("SXTH", ARM64_AM::SXTH)
2314 .Case("SXTW", ARM64_AM::SXTW)
2315 .Case("SXTX", ARM64_AM::SXTX)
2316 .Default(ARM64_AM::InvalidExtend);
2317 if (ExtOp == ARM64_AM::InvalidExtend)
2320 SMLoc S = Tok.getLoc();
2323 if (getLexer().is(AsmToken::EndOfStatement) ||
2324 getLexer().is(AsmToken::Comma)) {
2325 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2327 ARM64Operand::CreateExtend(ExtOp, 0, S, E, getContext()));
2331 bool Hash = getLexer().is(AsmToken::Hash);
2332 if (!Hash && getLexer().isNot(AsmToken::Integer)) {
2333 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2335 ARM64Operand::CreateExtend(ExtOp, 0, S, E, getContext()));
2340 Parser.Lex(); // Eat the '#'.
2342 const MCExpr *ImmVal;
2343 if (getParser().parseExpression(ImmVal))
2346 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2348 return TokError("immediate value expected for extend operand");
2350 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
2352 ARM64Operand::CreateExtend(ExtOp, MCE->getValue(), S, E, getContext()));
2356 /// parseSysAlias - The IC, DC, AT, and TLBI instructions are simple aliases for
2357 /// the SYS instruction. Parse them specially so that we create a SYS MCInst.
2358 bool ARM64AsmParser::parseSysAlias(StringRef Name, SMLoc NameLoc,
2359 OperandVector &Operands) {
2360 if (Name.find('.') != StringRef::npos)
2361 return TokError("invalid operand");
2365 ARM64Operand::CreateToken("sys", false, NameLoc, getContext()));
2367 const AsmToken &Tok = Parser.getTok();
2368 StringRef Op = Tok.getString();
2369 SMLoc S = Tok.getLoc();
2371 const MCExpr *Expr = 0;
2373 #define SYS_ALIAS(op1, Cn, Cm, op2) \
2375 Expr = MCConstantExpr::Create(op1, getContext()); \
2376 Operands.push_back( \
2377 ARM64Operand::CreateImm(Expr, S, getLoc(), getContext())); \
2378 Operands.push_back( \
2379 ARM64Operand::CreateSysCR(Cn, S, getLoc(), getContext())); \
2380 Operands.push_back( \
2381 ARM64Operand::CreateSysCR(Cm, S, getLoc(), getContext())); \
2382 Expr = MCConstantExpr::Create(op2, getContext()); \
2383 Operands.push_back( \
2384 ARM64Operand::CreateImm(Expr, S, getLoc(), getContext())); \
2387 if (Mnemonic == "ic") {
2388 if (!Op.compare_lower("ialluis")) {
2389 // SYS #0, C7, C1, #0
2390 SYS_ALIAS(0, 7, 1, 0);
2391 } else if (!Op.compare_lower("iallu")) {
2392 // SYS #0, C7, C5, #0
2393 SYS_ALIAS(0, 7, 5, 0);
2394 } else if (!Op.compare_lower("ivau")) {
2395 // SYS #3, C7, C5, #1
2396 SYS_ALIAS(3, 7, 5, 1);
2398 return TokError("invalid operand for IC instruction");
2400 } else if (Mnemonic == "dc") {
2401 if (!Op.compare_lower("zva")) {
2402 // SYS #3, C7, C4, #1
2403 SYS_ALIAS(3, 7, 4, 1);
2404 } else if (!Op.compare_lower("ivac")) {
2405 // SYS #3, C7, C6, #1
2406 SYS_ALIAS(0, 7, 6, 1);
2407 } else if (!Op.compare_lower("isw")) {
2408 // SYS #0, C7, C6, #2
2409 SYS_ALIAS(0, 7, 6, 2);
2410 } else if (!Op.compare_lower("cvac")) {
2411 // SYS #3, C7, C10, #1
2412 SYS_ALIAS(3, 7, 10, 1);
2413 } else if (!Op.compare_lower("csw")) {
2414 // SYS #0, C7, C10, #2
2415 SYS_ALIAS(0, 7, 10, 2);
2416 } else if (!Op.compare_lower("cvau")) {
2417 // SYS #3, C7, C11, #1
2418 SYS_ALIAS(3, 7, 11, 1);
2419 } else if (!Op.compare_lower("civac")) {
2420 // SYS #3, C7, C14, #1
2421 SYS_ALIAS(3, 7, 14, 1);
2422 } else if (!Op.compare_lower("cisw")) {
2423 // SYS #0, C7, C14, #2
2424 SYS_ALIAS(0, 7, 14, 2);
2426 return TokError("invalid operand for DC instruction");
2428 } else if (Mnemonic == "at") {
2429 if (!Op.compare_lower("s1e1r")) {
2430 // SYS #0, C7, C8, #0
2431 SYS_ALIAS(0, 7, 8, 0);
2432 } else if (!Op.compare_lower("s1e2r")) {
2433 // SYS #4, C7, C8, #0
2434 SYS_ALIAS(4, 7, 8, 0);
2435 } else if (!Op.compare_lower("s1e3r")) {
2436 // SYS #6, C7, C8, #0
2437 SYS_ALIAS(6, 7, 8, 0);
2438 } else if (!Op.compare_lower("s1e1w")) {
2439 // SYS #0, C7, C8, #1
2440 SYS_ALIAS(0, 7, 8, 1);
2441 } else if (!Op.compare_lower("s1e2w")) {
2442 // SYS #4, C7, C8, #1
2443 SYS_ALIAS(4, 7, 8, 1);
2444 } else if (!Op.compare_lower("s1e3w")) {
2445 // SYS #6, C7, C8, #1
2446 SYS_ALIAS(6, 7, 8, 1);
2447 } else if (!Op.compare_lower("s1e0r")) {
2448 // SYS #0, C7, C8, #3
2449 SYS_ALIAS(0, 7, 8, 2);
2450 } else if (!Op.compare_lower("s1e0w")) {
2451 // SYS #0, C7, C8, #3
2452 SYS_ALIAS(0, 7, 8, 3);
2453 } else if (!Op.compare_lower("s12e1r")) {
2454 // SYS #4, C7, C8, #4
2455 SYS_ALIAS(4, 7, 8, 4);
2456 } else if (!Op.compare_lower("s12e1w")) {
2457 // SYS #4, C7, C8, #5
2458 SYS_ALIAS(4, 7, 8, 5);
2459 } else if (!Op.compare_lower("s12e0r")) {
2460 // SYS #4, C7, C8, #6
2461 SYS_ALIAS(4, 7, 8, 6);
2462 } else if (!Op.compare_lower("s12e0w")) {
2463 // SYS #4, C7, C8, #7
2464 SYS_ALIAS(4, 7, 8, 7);
2466 return TokError("invalid operand for AT instruction");
2468 } else if (Mnemonic == "tlbi") {
2469 if (!Op.compare_lower("vmalle1is")) {
2470 // SYS #0, C8, C3, #0
2471 SYS_ALIAS(0, 8, 3, 0);
2472 } else if (!Op.compare_lower("alle2is")) {
2473 // SYS #4, C8, C3, #0
2474 SYS_ALIAS(4, 8, 3, 0);
2475 } else if (!Op.compare_lower("alle3is")) {
2476 // SYS #6, C8, C3, #0
2477 SYS_ALIAS(6, 8, 3, 0);
2478 } else if (!Op.compare_lower("vae1is")) {
2479 // SYS #0, C8, C3, #1
2480 SYS_ALIAS(0, 8, 3, 1);
2481 } else if (!Op.compare_lower("vae2is")) {
2482 // SYS #4, C8, C3, #1
2483 SYS_ALIAS(4, 8, 3, 1);
2484 } else if (!Op.compare_lower("vae3is")) {
2485 // SYS #6, C8, C3, #1
2486 SYS_ALIAS(6, 8, 3, 1);
2487 } else if (!Op.compare_lower("aside1is")) {
2488 // SYS #0, C8, C3, #2
2489 SYS_ALIAS(0, 8, 3, 2);
2490 } else if (!Op.compare_lower("vaae1is")) {
2491 // SYS #0, C8, C3, #3
2492 SYS_ALIAS(0, 8, 3, 3);
2493 } else if (!Op.compare_lower("alle1is")) {
2494 // SYS #4, C8, C3, #4
2495 SYS_ALIAS(4, 8, 3, 4);
2496 } else if (!Op.compare_lower("vale1is")) {
2497 // SYS #0, C8, C3, #5
2498 SYS_ALIAS(0, 8, 3, 5);
2499 } else if (!Op.compare_lower("vaale1is")) {
2500 // SYS #0, C8, C3, #7
2501 SYS_ALIAS(0, 8, 3, 7);
2502 } else if (!Op.compare_lower("vmalle1")) {
2503 // SYS #0, C8, C7, #0
2504 SYS_ALIAS(0, 8, 7, 0);
2505 } else if (!Op.compare_lower("alle2")) {
2506 // SYS #4, C8, C7, #0
2507 SYS_ALIAS(4, 8, 7, 0);
2508 } else if (!Op.compare_lower("vale2is")) {
2509 // SYS #4, C8, C3, #5
2510 SYS_ALIAS(4, 8, 3, 5);
2511 } else if (!Op.compare_lower("vale3is")) {
2512 // SYS #6, C8, C3, #5
2513 SYS_ALIAS(6, 8, 3, 5);
2514 } else if (!Op.compare_lower("alle3")) {
2515 // SYS #6, C8, C7, #0
2516 SYS_ALIAS(6, 8, 7, 0);
2517 } else if (!Op.compare_lower("vae1")) {
2518 // SYS #0, C8, C7, #1
2519 SYS_ALIAS(0, 8, 7, 1);
2520 } else if (!Op.compare_lower("vae2")) {
2521 // SYS #4, C8, C7, #1
2522 SYS_ALIAS(4, 8, 7, 1);
2523 } else if (!Op.compare_lower("vae3")) {
2524 // SYS #6, C8, C7, #1
2525 SYS_ALIAS(6, 8, 7, 1);
2526 } else if (!Op.compare_lower("aside1")) {
2527 // SYS #0, C8, C7, #2
2528 SYS_ALIAS(0, 8, 7, 2);
2529 } else if (!Op.compare_lower("vaae1")) {
2530 // SYS #0, C8, C7, #3
2531 SYS_ALIAS(0, 8, 7, 3);
2532 } else if (!Op.compare_lower("alle1")) {
2533 // SYS #4, C8, C7, #4
2534 SYS_ALIAS(4, 8, 7, 4);
2535 } else if (!Op.compare_lower("vale1")) {
2536 // SYS #0, C8, C7, #5
2537 SYS_ALIAS(0, 8, 7, 5);
2538 } else if (!Op.compare_lower("vale2")) {
2539 // SYS #4, C8, C7, #5
2540 SYS_ALIAS(4, 8, 7, 5);
2541 } else if (!Op.compare_lower("vale3")) {
2542 // SYS #6, C8, C7, #5
2543 SYS_ALIAS(6, 8, 7, 5);
2544 } else if (!Op.compare_lower("vaale1")) {
2545 // SYS #0, C8, C7, #7
2546 SYS_ALIAS(0, 8, 7, 7);
2547 } else if (!Op.compare_lower("ipas2e1")) {
2548 // SYS #4, C8, C4, #1
2549 SYS_ALIAS(4, 8, 4, 1);
2550 } else if (!Op.compare_lower("ipas2le1")) {
2551 // SYS #4, C8, C4, #5
2552 SYS_ALIAS(4, 8, 4, 5);
2553 } else if (!Op.compare_lower("ipas2e1is")) {
2554 // SYS #4, C8, C4, #1
2555 SYS_ALIAS(4, 8, 0, 1);
2556 } else if (!Op.compare_lower("ipas2le1is")) {
2557 // SYS #4, C8, C4, #5
2558 SYS_ALIAS(4, 8, 0, 5);
2559 } else if (!Op.compare_lower("vmalls12e1")) {
2560 // SYS #4, C8, C7, #6
2561 SYS_ALIAS(4, 8, 7, 6);
2562 } else if (!Op.compare_lower("vmalls12e1is")) {
2563 // SYS #4, C8, C3, #6
2564 SYS_ALIAS(4, 8, 3, 6);
2566 return TokError("invalid operand for TLBI instruction");
2572 Parser.Lex(); // Eat operand.
2574 bool ExpectRegister = (Op.lower().find("all") == StringRef::npos);
2575 bool HasRegister = false;
2577 // Check for the optional register operand.
2578 if (getLexer().is(AsmToken::Comma)) {
2579 Parser.Lex(); // Eat comma.
2581 if (Tok.isNot(AsmToken::Identifier) || parseRegister(Operands))
2582 return TokError("expected register operand");
2587 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2588 Parser.eatToEndOfStatement();
2589 return TokError("unexpected token in argument list");
2592 if (ExpectRegister && !HasRegister) {
2593 return TokError("specified " + Mnemonic + " op requires a register");
2595 else if (!ExpectRegister && HasRegister) {
2596 return TokError("specified " + Mnemonic + " op does not use a register");
2599 Parser.Lex(); // Consume the EndOfStatement
2603 ARM64AsmParser::OperandMatchResultTy
2604 ARM64AsmParser::tryParseBarrierOperand(OperandVector &Operands) {
2605 const AsmToken &Tok = Parser.getTok();
2607 // Can be either a #imm style literal or an option name
2608 bool Hash = Tok.is(AsmToken::Hash);
2609 if (Hash || Tok.is(AsmToken::Integer)) {
2610 // Immediate operand.
2612 Parser.Lex(); // Eat the '#'
2613 const MCExpr *ImmVal;
2614 SMLoc ExprLoc = getLoc();
2615 if (getParser().parseExpression(ImmVal))
2616 return MatchOperand_ParseFail;
2617 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2619 Error(ExprLoc, "immediate value expected for barrier operand");
2620 return MatchOperand_ParseFail;
2622 if (MCE->getValue() < 0 || MCE->getValue() > 15) {
2623 Error(ExprLoc, "barrier operand out of range");
2624 return MatchOperand_ParseFail;
2627 ARM64Operand::CreateBarrier(MCE->getValue(), ExprLoc, getContext()));
2628 return MatchOperand_Success;
2631 if (Tok.isNot(AsmToken::Identifier)) {
2632 TokError("invalid operand for instruction");
2633 return MatchOperand_ParseFail;
2637 unsigned Opt = ARM64DB::DBarrierMapper().fromString(Tok.getString(), Valid);
2639 TokError("invalid barrier option name");
2640 return MatchOperand_ParseFail;
2643 // The only valid named option for ISB is 'sy'
2644 if (Mnemonic == "isb" && Opt != ARM64DB::SY) {
2645 TokError("'sy' or #imm operand expected");
2646 return MatchOperand_ParseFail;
2649 Operands.push_back(ARM64Operand::CreateBarrier(Opt, getLoc(), getContext()));
2650 Parser.Lex(); // Consume the option
2652 return MatchOperand_Success;
2655 ARM64AsmParser::OperandMatchResultTy
2656 ARM64AsmParser::tryParseSysReg(OperandVector &Operands) {
2657 const AsmToken &Tok = Parser.getTok();
2659 if (Tok.isNot(AsmToken::Identifier))
2660 return MatchOperand_NoMatch;
2662 Operands.push_back(ARM64Operand::CreateSysReg(Tok.getString(), getLoc(),
2664 Parser.Lex(); // Eat identifier
2666 return MatchOperand_Success;
2669 /// tryParseVectorRegister - Parse a vector register operand.
2670 bool ARM64AsmParser::tryParseVectorRegister(OperandVector &Operands) {
2671 if (Parser.getTok().isNot(AsmToken::Identifier))
2675 // Check for a vector register specifier first.
2677 int64_t Reg = tryMatchVectorRegister(Kind, false);
2681 ARM64Operand::CreateReg(Reg, true, S, getLoc(), getContext()));
2682 // If there was an explicit qualifier, that goes on as a literal text
2685 Operands.push_back(ARM64Operand::CreateToken(Kind, false, S, getContext()));
2687 // If there is an index specifier following the register, parse that too.
2688 if (Parser.getTok().is(AsmToken::LBrac)) {
2689 SMLoc SIdx = getLoc();
2690 Parser.Lex(); // Eat left bracket token.
2692 const MCExpr *ImmVal;
2693 if (getParser().parseExpression(ImmVal))
2695 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2697 TokError("immediate value expected for vector index");
2702 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2703 Error(E, "']' expected");
2707 Parser.Lex(); // Eat right bracket token.
2709 Operands.push_back(ARM64Operand::CreateVectorIndex(MCE->getValue(), SIdx, E,
2716 /// parseRegister - Parse a non-vector register operand.
2717 bool ARM64AsmParser::parseRegister(OperandVector &Operands) {
2719 // Try for a vector register.
2720 if (!tryParseVectorRegister(Operands))
2723 // Try for a scalar register.
2724 int64_t Reg = tryParseRegister();
2728 ARM64Operand::CreateReg(Reg, false, S, getLoc(), getContext()));
2730 // A small number of instructions (FMOVXDhighr, for example) have "[1]"
2731 // as a string token in the instruction itself.
2732 if (getLexer().getKind() == AsmToken::LBrac) {
2733 SMLoc LBracS = getLoc();
2735 const AsmToken &Tok = Parser.getTok();
2736 if (Tok.is(AsmToken::Integer)) {
2737 SMLoc IntS = getLoc();
2738 int64_t Val = Tok.getIntVal();
2741 if (getLexer().getKind() == AsmToken::RBrac) {
2742 SMLoc RBracS = getLoc();
2745 ARM64Operand::CreateToken("[", false, LBracS, getContext()));
2747 ARM64Operand::CreateToken("1", false, IntS, getContext()));
2749 ARM64Operand::CreateToken("]", false, RBracS, getContext()));
2759 /// tryParseNoIndexMemory - Custom parser method for memory operands that
2760 /// do not allow base regisrer writeback modes,
2761 /// or those that handle writeback separately from
2762 /// the memory operand (like the AdvSIMD ldX/stX
2764 ARM64AsmParser::OperandMatchResultTy
2765 ARM64AsmParser::tryParseNoIndexMemory(OperandVector &Operands) {
2766 if (Parser.getTok().isNot(AsmToken::LBrac))
2767 return MatchOperand_NoMatch;
2769 Parser.Lex(); // Eat left bracket token.
2771 const AsmToken &BaseRegTok = Parser.getTok();
2772 if (BaseRegTok.isNot(AsmToken::Identifier)) {
2773 Error(BaseRegTok.getLoc(), "register expected");
2774 return MatchOperand_ParseFail;
2777 int64_t Reg = tryParseRegister();
2779 Error(BaseRegTok.getLoc(), "register expected");
2780 return MatchOperand_ParseFail;
2784 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2785 Error(E, "']' expected");
2786 return MatchOperand_ParseFail;
2789 Parser.Lex(); // Eat right bracket token.
2791 Operands.push_back(ARM64Operand::CreateMem(Reg, 0, S, E, E, getContext()));
2792 return MatchOperand_Success;
2795 /// parseMemory - Parse a memory operand for a basic load/store instruction.
2796 bool ARM64AsmParser::parseMemory(OperandVector &Operands) {
2797 assert(Parser.getTok().is(AsmToken::LBrac) && "Token is not a Left Bracket");
2799 Parser.Lex(); // Eat left bracket token.
2801 const AsmToken &BaseRegTok = Parser.getTok();
2802 if (BaseRegTok.isNot(AsmToken::Identifier))
2803 return Error(BaseRegTok.getLoc(), "register expected");
2805 int64_t Reg = tryParseRegister();
2807 return Error(BaseRegTok.getLoc(), "register expected");
2809 // If there is an offset expression, parse it.
2810 const MCExpr *OffsetExpr = 0;
2812 if (Parser.getTok().is(AsmToken::Comma)) {
2813 Parser.Lex(); // Eat the comma.
2814 OffsetLoc = getLoc();
2817 const AsmToken &OffsetRegTok = Parser.getTok();
2818 int Reg2 = OffsetRegTok.is(AsmToken::Identifier) ? tryParseRegister() : -1;
2820 // Default shift is LSL, with an omitted shift. We use the third bit of
2821 // the extend value to indicate presence/omission of the immediate offset.
2822 ARM64_AM::ExtendType ExtOp = ARM64_AM::UXTX;
2823 int64_t ShiftVal = 0;
2824 bool ExplicitShift = false;
2826 if (Parser.getTok().is(AsmToken::Comma)) {
2827 // Embedded extend operand.
2828 Parser.Lex(); // Eat the comma
2830 SMLoc ExtLoc = getLoc();
2831 const AsmToken &Tok = Parser.getTok();
2832 ExtOp = StringSwitch<ARM64_AM::ExtendType>(Tok.getString())
2833 .Case("uxtw", ARM64_AM::UXTW)
2834 .Case("lsl", ARM64_AM::UXTX) // Alias for UXTX
2835 .Case("sxtw", ARM64_AM::SXTW)
2836 .Case("sxtx", ARM64_AM::SXTX)
2837 .Case("UXTW", ARM64_AM::UXTW)
2838 .Case("LSL", ARM64_AM::UXTX) // Alias for UXTX
2839 .Case("SXTW", ARM64_AM::SXTW)
2840 .Case("SXTX", ARM64_AM::SXTX)
2841 .Default(ARM64_AM::InvalidExtend);
2842 if (ExtOp == ARM64_AM::InvalidExtend)
2843 return Error(ExtLoc, "expected valid extend operation");
2845 Parser.Lex(); // Eat the extend op.
2847 // A 32-bit offset register is only valid for [SU]/XTW extend
2849 if (ARM64MCRegisterClasses[ARM64::GPR32allRegClassID].contains(Reg2)) {
2850 if (ExtOp != ARM64_AM::UXTW &&
2851 ExtOp != ARM64_AM::SXTW)
2852 return Error(ExtLoc, "32-bit general purpose offset register "
2853 "requires sxtw or uxtw extend");
2854 } else if (!ARM64MCRegisterClasses[ARM64::GPR64allRegClassID].contains(
2856 return Error(OffsetLoc,
2857 "64-bit general purpose offset register expected");
2859 bool Hash = getLexer().is(AsmToken::Hash);
2860 if (getLexer().is(AsmToken::RBrac)) {
2861 // No immediate operand.
2862 if (ExtOp == ARM64_AM::UXTX)
2863 return Error(ExtLoc, "LSL extend requires immediate operand");
2864 } else if (Hash || getLexer().is(AsmToken::Integer)) {
2865 // Immediate operand.
2867 Parser.Lex(); // Eat the '#'
2868 const MCExpr *ImmVal;
2869 SMLoc ExprLoc = getLoc();
2870 if (getParser().parseExpression(ImmVal))
2872 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2874 return TokError("immediate value expected for extend operand");
2876 ExplicitShift = true;
2877 ShiftVal = MCE->getValue();
2878 if (ShiftVal < 0 || ShiftVal > 4)
2879 return Error(ExprLoc, "immediate operand out of range");
2881 return Error(getLoc(), "expected immediate operand");
2884 if (Parser.getTok().isNot(AsmToken::RBrac))
2885 return Error(getLoc(), "']' expected");
2887 Parser.Lex(); // Eat right bracket token.
2890 Operands.push_back(ARM64Operand::CreateRegOffsetMem(
2891 Reg, Reg2, ExtOp, ShiftVal, ExplicitShift, S, E, getContext()));
2894 // Immediate expressions.
2895 } else if (Parser.getTok().is(AsmToken::Hash) ||
2896 Parser.getTok().is(AsmToken::Integer)) {
2897 if (Parser.getTok().is(AsmToken::Hash))
2898 Parser.Lex(); // Eat hash token.
2900 if (parseSymbolicImmVal(OffsetExpr))
2903 // FIXME: We really should make sure that we're dealing with a LDR/STR
2904 // instruction that can legally have a symbolic expression here.
2905 // Symbol reference.
2906 if (Parser.getTok().isNot(AsmToken::Identifier) &&
2907 Parser.getTok().isNot(AsmToken::String))
2908 return Error(getLoc(), "identifier or immediate expression expected");
2909 if (getParser().parseExpression(OffsetExpr))
2911 // If this is a plain ref, Make sure a legal variant kind was specified.
2912 // Otherwise, it's a more complicated expression and we have to just
2913 // assume it's OK and let the relocation stuff puke if it's not.
2914 ARM64MCExpr::VariantKind ELFRefKind;
2915 MCSymbolRefExpr::VariantKind DarwinRefKind;
2916 const MCConstantExpr *Addend;
2917 if (classifySymbolRef(OffsetExpr, ELFRefKind, DarwinRefKind, Addend) &&
2919 assert(ELFRefKind == ARM64MCExpr::VK_INVALID &&
2920 "ELF symbol modifiers not supported here yet");
2922 switch (DarwinRefKind) {
2924 return Error(getLoc(), "expected @pageoff or @gotpageoff modifier");
2925 case MCSymbolRefExpr::VK_GOTPAGEOFF:
2926 case MCSymbolRefExpr::VK_PAGEOFF:
2927 case MCSymbolRefExpr::VK_TLVPPAGEOFF:
2928 // These are what we're expecting.
2936 if (Parser.getTok().isNot(AsmToken::RBrac))
2937 return Error(E, "']' expected");
2939 Parser.Lex(); // Eat right bracket token.
2941 // Create the memory operand.
2943 ARM64Operand::CreateMem(Reg, OffsetExpr, S, E, OffsetLoc, getContext()));
2945 // Check for a '!', indicating pre-indexed addressing with writeback.
2946 if (Parser.getTok().is(AsmToken::Exclaim)) {
2947 // There needs to have been an immediate or wback doesn't make sense.
2949 return Error(E, "missing offset for pre-indexed addressing");
2950 // Pre-indexed with writeback must have a constant expression for the
2951 // offset. FIXME: Theoretically, we'd like to allow fixups so long
2952 // as they don't require a relocation.
2953 if (!isa<MCConstantExpr>(OffsetExpr))
2954 return Error(OffsetLoc, "constant immediate expression expected");
2956 // Create the Token operand for the '!'.
2957 Operands.push_back(ARM64Operand::CreateToken(
2958 "!", false, Parser.getTok().getLoc(), getContext()));
2959 Parser.Lex(); // Eat the '!' token.
2965 bool ARM64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) {
2966 bool HasELFModifier = false;
2967 ARM64MCExpr::VariantKind RefKind;
2969 if (Parser.getTok().is(AsmToken::Colon)) {
2970 Parser.Lex(); // Eat ':"
2971 HasELFModifier = true;
2973 if (Parser.getTok().isNot(AsmToken::Identifier)) {
2974 Error(Parser.getTok().getLoc(),
2975 "expect relocation specifier in operand after ':'");
2979 std::string LowerCase = Parser.getTok().getIdentifier().lower();
2980 RefKind = StringSwitch<ARM64MCExpr::VariantKind>(LowerCase)
2981 .Case("lo12", ARM64MCExpr::VK_LO12)
2982 .Case("abs_g3", ARM64MCExpr::VK_ABS_G3)
2983 .Case("abs_g2", ARM64MCExpr::VK_ABS_G2)
2984 .Case("abs_g2_nc", ARM64MCExpr::VK_ABS_G2_NC)
2985 .Case("abs_g1", ARM64MCExpr::VK_ABS_G1)
2986 .Case("abs_g1_nc", ARM64MCExpr::VK_ABS_G1_NC)
2987 .Case("abs_g0", ARM64MCExpr::VK_ABS_G0)
2988 .Case("abs_g0_nc", ARM64MCExpr::VK_ABS_G0_NC)
2989 .Case("dtprel_g2", ARM64MCExpr::VK_DTPREL_G2)
2990 .Case("dtprel_g1", ARM64MCExpr::VK_DTPREL_G1)
2991 .Case("dtprel_g1_nc", ARM64MCExpr::VK_DTPREL_G1_NC)
2992 .Case("dtprel_g0", ARM64MCExpr::VK_DTPREL_G0)
2993 .Case("dtprel_g0_nc", ARM64MCExpr::VK_DTPREL_G0_NC)
2994 .Case("dtprel_lo12", ARM64MCExpr::VK_DTPREL_LO12)
2995 .Case("dtprel_lo12_nc", ARM64MCExpr::VK_DTPREL_LO12_NC)
2996 .Case("tprel_g2", ARM64MCExpr::VK_TPREL_G2)
2997 .Case("tprel_g1", ARM64MCExpr::VK_TPREL_G1)
2998 .Case("tprel_g1_nc", ARM64MCExpr::VK_TPREL_G1_NC)
2999 .Case("tprel_g0", ARM64MCExpr::VK_TPREL_G0)
3000 .Case("tprel_g0_nc", ARM64MCExpr::VK_TPREL_G0_NC)
3001 .Case("tprel_lo12", ARM64MCExpr::VK_TPREL_LO12)
3002 .Case("tprel_lo12_nc", ARM64MCExpr::VK_TPREL_LO12_NC)
3003 .Case("tlsdesc_lo12", ARM64MCExpr::VK_TLSDESC_LO12)
3004 .Case("got", ARM64MCExpr::VK_GOT_PAGE)
3005 .Case("got_lo12", ARM64MCExpr::VK_GOT_LO12)
3006 .Case("gottprel", ARM64MCExpr::VK_GOTTPREL_PAGE)
3007 .Case("gottprel_lo12", ARM64MCExpr::VK_GOTTPREL_LO12_NC)
3008 .Case("gottprel_g1", ARM64MCExpr::VK_GOTTPREL_G1)
3009 .Case("gottprel_g0_nc", ARM64MCExpr::VK_GOTTPREL_G0_NC)
3010 .Case("tlsdesc", ARM64MCExpr::VK_TLSDESC_PAGE)
3011 .Default(ARM64MCExpr::VK_INVALID);
3013 if (RefKind == ARM64MCExpr::VK_INVALID) {
3014 Error(Parser.getTok().getLoc(),
3015 "expect relocation specifier in operand after ':'");
3019 Parser.Lex(); // Eat identifier
3021 if (Parser.getTok().isNot(AsmToken::Colon)) {
3022 Error(Parser.getTok().getLoc(), "expect ':' after relocation specifier");
3025 Parser.Lex(); // Eat ':'
3028 if (getParser().parseExpression(ImmVal))
3032 ImmVal = ARM64MCExpr::Create(ImmVal, RefKind, getContext());
3037 /// parseVectorList - Parse a vector list operand for AdvSIMD instructions.
3038 bool ARM64AsmParser::parseVectorList(OperandVector &Operands) {
3039 assert(Parser.getTok().is(AsmToken::LCurly) && "Token is not a Left Bracket");
3041 Parser.Lex(); // Eat left bracket token.
3043 int64_t FirstReg = tryMatchVectorRegister(Kind, true);
3046 int64_t PrevReg = FirstReg;
3049 if (Parser.getTok().is(AsmToken::Minus)) {
3050 Parser.Lex(); // Eat the minus.
3052 SMLoc Loc = getLoc();
3054 int64_t Reg = tryMatchVectorRegister(NextKind, true);
3057 // Any Kind suffices must match on all regs in the list.
3058 if (Kind != NextKind)
3059 return Error(Loc, "mismatched register size suffix");
3061 unsigned Space = (PrevReg < Reg) ? (Reg - PrevReg) : (Reg + 32 - PrevReg);
3063 if (Space == 0 || Space > 3) {
3064 return Error(Loc, "invalid number of vectors");
3070 while (Parser.getTok().is(AsmToken::Comma)) {
3071 Parser.Lex(); // Eat the comma token.
3073 SMLoc Loc = getLoc();
3075 int64_t Reg = tryMatchVectorRegister(NextKind, true);
3078 // Any Kind suffices must match on all regs in the list.
3079 if (Kind != NextKind)
3080 return Error(Loc, "mismatched register size suffix");
3082 // Registers must be incremental (with wraparound at 31)
3083 if (getContext().getRegisterInfo()->getEncodingValue(Reg) !=
3084 (getContext().getRegisterInfo()->getEncodingValue(PrevReg) + 1) % 32)
3085 return Error(Loc, "registers must be sequential");
3092 if (Parser.getTok().is(AsmToken::EndOfStatement))
3093 Error(getLoc(), "'}' expected");
3094 Parser.Lex(); // Eat the '}' token.
3096 unsigned NumElements = 0;
3097 char ElementKind = 0;
3099 parseValidVectorKind(Kind, NumElements, ElementKind);
3101 Operands.push_back(ARM64Operand::CreateVectorList(
3102 FirstReg, Count, NumElements, ElementKind, S, getLoc(), getContext()));
3104 // If there is an index specifier following the list, parse that too.
3105 if (Parser.getTok().is(AsmToken::LBrac)) {
3106 SMLoc SIdx = getLoc();
3107 Parser.Lex(); // Eat left bracket token.
3109 const MCExpr *ImmVal;
3110 if (getParser().parseExpression(ImmVal))
3112 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
3114 TokError("immediate value expected for vector index");
3119 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3120 Error(E, "']' expected");
3124 Parser.Lex(); // Eat right bracket token.
3126 Operands.push_back(ARM64Operand::CreateVectorIndex(MCE->getValue(), SIdx, E,
3132 /// parseOperand - Parse a arm instruction operand. For now this parses the
3133 /// operand regardless of the mnemonic.
3134 bool ARM64AsmParser::parseOperand(OperandVector &Operands, bool isCondCode,
3135 bool invertCondCode) {
3136 // Check if the current operand has a custom associated parser, if so, try to
3137 // custom parse the operand, or fallback to the general approach.
3138 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
3139 if (ResTy == MatchOperand_Success)
3141 // If there wasn't a custom match, try the generic matcher below. Otherwise,
3142 // there was a match, but an error occurred, in which case, just return that
3143 // the operand parsing failed.
3144 if (ResTy == MatchOperand_ParseFail)
3147 // Nothing custom, so do general case parsing.
3149 switch (getLexer().getKind()) {
3153 if (parseSymbolicImmVal(Expr))
3154 return Error(S, "invalid operand");
3156 SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
3157 Operands.push_back(ARM64Operand::CreateImm(Expr, S, E, getContext()));
3160 case AsmToken::LBrac:
3161 return parseMemory(Operands);
3162 case AsmToken::LCurly:
3163 return parseVectorList(Operands);
3164 case AsmToken::Identifier: {
3165 // If we're expecting a Condition Code operand, then just parse that.
3167 return parseCondCode(Operands, invertCondCode);
3169 // If it's a register name, parse it.
3170 if (!parseRegister(Operands))
3173 // This could be an optional "shift" operand.
3174 if (!parseOptionalShift(Operands))
3177 // Or maybe it could be an optional "extend" operand.
3178 if (!parseOptionalExtend(Operands))
3181 // This was not a register so parse other operands that start with an
3182 // identifier (like labels) as expressions and create them as immediates.
3183 const MCExpr *IdVal;
3185 if (getParser().parseExpression(IdVal))
3188 E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
3189 Operands.push_back(ARM64Operand::CreateImm(IdVal, S, E, getContext()));
3192 case AsmToken::Integer:
3193 case AsmToken::Real:
3194 case AsmToken::Hash: {
3195 // #42 -> immediate.
3197 if (getLexer().is(AsmToken::Hash))
3200 // The only Real that should come through here is a literal #0.0 for
3201 // the fcmp[e] r, #0.0 instructions. They expect raw token operands,
3202 // so convert the value.
3203 const AsmToken &Tok = Parser.getTok();
3204 if (Tok.is(AsmToken::Real)) {
3205 APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
3206 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
3207 if (IntVal != 0 || (Mnemonic != "fcmp" && Mnemonic != "fcmpe"))
3208 return TokError("unexpected floating point literal");
3209 Parser.Lex(); // Eat the token.
3212 ARM64Operand::CreateToken("#0", false, S, getContext()));
3214 ARM64Operand::CreateToken(".0", false, S, getContext()));
3218 const MCExpr *ImmVal;
3219 if (parseSymbolicImmVal(ImmVal))
3222 E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
3223 Operands.push_back(ARM64Operand::CreateImm(ImmVal, S, E, getContext()));
3229 /// ParseInstruction - Parse an ARM64 instruction mnemonic followed by its
3231 bool ARM64AsmParser::ParseInstruction(ParseInstructionInfo &Info,
3232 StringRef Name, SMLoc NameLoc,
3233 OperandVector &Operands) {
3234 // Create the leading tokens for the mnemonic, split by '.' characters.
3235 size_t Start = 0, Next = Name.find('.');
3236 StringRef Head = Name.slice(Start, Next);
3238 // IC, DC, AT, and TLBI instructions are aliases for the SYS instruction.
3239 if (Head == "ic" || Head == "dc" || Head == "at" || Head == "tlbi")
3240 return parseSysAlias(Head, NameLoc, Operands);
3243 ARM64Operand::CreateToken(Head, false, NameLoc, getContext()));
3246 // Handle condition codes for a branch mnemonic
3247 if (Head == "b" && Next != StringRef::npos) {
3249 Next = Name.find('.', Start + 1);
3250 Head = Name.slice(Start + 1, Next);
3252 SMLoc SuffixLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
3253 (Head.data() - Name.data()));
3254 unsigned CC = parseCondCodeString(Head);
3255 if (CC == ARM64CC::Invalid)
3256 return Error(SuffixLoc, "invalid condition code");
3257 const MCExpr *CCExpr = MCConstantExpr::Create(CC, getContext());
3259 ARM64Operand::CreateImm(CCExpr, NameLoc, NameLoc, getContext()));
3262 // Add the remaining tokens in the mnemonic.
3263 while (Next != StringRef::npos) {
3265 Next = Name.find('.', Start + 1);
3266 Head = Name.slice(Start, Next);
3267 SMLoc SuffixLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
3268 (Head.data() - Name.data()) + 1);
3270 ARM64Operand::CreateToken(Head, true, SuffixLoc, getContext()));
3273 // Conditional compare instructions have a Condition Code operand, which needs
3274 // to be parsed and an immediate operand created.
3275 bool condCodeFourthOperand =
3276 (Head == "ccmp" || Head == "ccmn" || Head == "fccmp" ||
3277 Head == "fccmpe" || Head == "fcsel" || Head == "csel" ||
3278 Head == "csinc" || Head == "csinv" || Head == "csneg");
3280 // These instructions are aliases to some of the conditional select
3281 // instructions. However, the condition code is inverted in the aliased
3284 // FIXME: Is this the correct way to handle these? Or should the parser
3285 // generate the aliased instructions directly?
3286 bool condCodeSecondOperand = (Head == "cset" || Head == "csetm");
3287 bool condCodeThirdOperand =
3288 (Head == "cinc" || Head == "cinv" || Head == "cneg");
3290 // Read the remaining operands.
3291 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3292 // Read the first operand.
3293 if (parseOperand(Operands, false, false)) {
3294 Parser.eatToEndOfStatement();
3299 while (getLexer().is(AsmToken::Comma)) {
3300 Parser.Lex(); // Eat the comma.
3302 // Parse and remember the operand.
3303 if (parseOperand(Operands, (N == 4 && condCodeFourthOperand) ||
3304 (N == 3 && condCodeThirdOperand) ||
3305 (N == 2 && condCodeSecondOperand),
3306 condCodeSecondOperand || condCodeThirdOperand)) {
3307 Parser.eatToEndOfStatement();
3315 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3316 SMLoc Loc = Parser.getTok().getLoc();
3317 Parser.eatToEndOfStatement();
3318 return Error(Loc, "unexpected token in argument list");
3321 Parser.Lex(); // Consume the EndOfStatement
3325 // FIXME: This entire function is a giant hack to provide us with decent
3326 // operand range validation/diagnostics until TableGen/MC can be extended
3327 // to support autogeneration of this kind of validation.
3328 bool ARM64AsmParser::validateInstruction(MCInst &Inst,
3329 SmallVectorImpl<SMLoc> &Loc) {
3330 const MCRegisterInfo *RI = getContext().getRegisterInfo();
3331 // Check for indexed addressing modes w/ the base register being the
3332 // same as a destination/source register or pair load where
3333 // the Rt == Rt2. All of those are undefined behaviour.
3334 switch (Inst.getOpcode()) {
3335 case ARM64::LDPSWpre:
3336 case ARM64::LDPWpost:
3337 case ARM64::LDPWpre:
3338 case ARM64::LDPXpost:
3339 case ARM64::LDPXpre: {
3340 unsigned Rt = Inst.getOperand(0).getReg();
3341 unsigned Rt2 = Inst.getOperand(1).getReg();
3342 unsigned Rn = Inst.getOperand(2).getReg();
3343 if (RI->isSubRegisterEq(Rn, Rt))
3344 return Error(Loc[0], "unpredictable LDP instruction, writeback base "
3345 "is also a destination");
3346 if (RI->isSubRegisterEq(Rn, Rt2))
3347 return Error(Loc[1], "unpredictable LDP instruction, writeback base "
3348 "is also a destination");
3351 case ARM64::LDPDpost:
3352 case ARM64::LDPDpre:
3353 case ARM64::LDPQpost:
3354 case ARM64::LDPQpre:
3355 case ARM64::LDPSpost:
3356 case ARM64::LDPSpre:
3357 case ARM64::LDPSWpost:
3363 case ARM64::LDPXi: {
3364 unsigned Rt = Inst.getOperand(0).getReg();
3365 unsigned Rt2 = Inst.getOperand(1).getReg();
3367 return Error(Loc[1], "unpredictable LDP instruction, Rt2==Rt");
3370 case ARM64::STPDpost:
3371 case ARM64::STPDpre:
3372 case ARM64::STPQpost:
3373 case ARM64::STPQpre:
3374 case ARM64::STPSpost:
3375 case ARM64::STPSpre:
3376 case ARM64::STPWpost:
3377 case ARM64::STPWpre:
3378 case ARM64::STPXpost:
3379 case ARM64::STPXpre: {
3380 unsigned Rt = Inst.getOperand(0).getReg();
3381 unsigned Rt2 = Inst.getOperand(1).getReg();
3382 unsigned Rn = Inst.getOperand(2).getReg();
3383 if (RI->isSubRegisterEq(Rn, Rt))
3384 return Error(Loc[0], "unpredictable STP instruction, writeback base "
3385 "is also a source");
3386 if (RI->isSubRegisterEq(Rn, Rt2))
3387 return Error(Loc[1], "unpredictable STP instruction, writeback base "
3388 "is also a source");
3391 case ARM64::LDRBBpre:
3392 case ARM64::LDRBpre:
3393 case ARM64::LDRHHpre:
3394 case ARM64::LDRHpre:
3395 case ARM64::LDRSBWpre:
3396 case ARM64::LDRSBXpre:
3397 case ARM64::LDRSHWpre:
3398 case ARM64::LDRSHXpre:
3399 case ARM64::LDRSWpre:
3400 case ARM64::LDRWpre:
3401 case ARM64::LDRXpre:
3402 case ARM64::LDRBBpost:
3403 case ARM64::LDRBpost:
3404 case ARM64::LDRHHpost:
3405 case ARM64::LDRHpost:
3406 case ARM64::LDRSBWpost:
3407 case ARM64::LDRSBXpost:
3408 case ARM64::LDRSHWpost:
3409 case ARM64::LDRSHXpost:
3410 case ARM64::LDRSWpost:
3411 case ARM64::LDRWpost:
3412 case ARM64::LDRXpost: {
3413 unsigned Rt = Inst.getOperand(0).getReg();
3414 unsigned Rn = Inst.getOperand(1).getReg();
3415 if (RI->isSubRegisterEq(Rn, Rt))
3416 return Error(Loc[0], "unpredictable LDR instruction, writeback base "
3417 "is also a source");
3420 case ARM64::STRBBpost:
3421 case ARM64::STRBpost:
3422 case ARM64::STRHHpost:
3423 case ARM64::STRHpost:
3424 case ARM64::STRWpost:
3425 case ARM64::STRXpost:
3426 case ARM64::STRBBpre:
3427 case ARM64::STRBpre:
3428 case ARM64::STRHHpre:
3429 case ARM64::STRHpre:
3430 case ARM64::STRWpre:
3431 case ARM64::STRXpre: {
3432 unsigned Rt = Inst.getOperand(0).getReg();
3433 unsigned Rn = Inst.getOperand(1).getReg();
3434 if (RI->isSubRegisterEq(Rn, Rt))
3435 return Error(Loc[0], "unpredictable STR instruction, writeback base "
3436 "is also a source");
3441 // Now check immediate ranges. Separate from the above as there is overlap
3442 // in the instructions being checked and this keeps the nested conditionals
3444 switch (Inst.getOpcode()) {
3446 case ARM64::ANDSWrs:
3448 case ARM64::ORRWrs: {
3449 if (!Inst.getOperand(3).isImm())
3450 return Error(Loc[3], "immediate value expected");
3451 int64_t shifter = Inst.getOperand(3).getImm();
3452 ARM64_AM::ShiftType ST = ARM64_AM::getShiftType(shifter);
3453 if (ST == ARM64_AM::LSL && shifter > 31)
3454 return Error(Loc[3], "shift value out of range");
3457 case ARM64::ADDSWri:
3458 case ARM64::ADDSXri:
3461 case ARM64::SUBSWri:
3462 case ARM64::SUBSXri:
3464 case ARM64::SUBXri: {
3465 if (!Inst.getOperand(3).isImm())
3466 return Error(Loc[3], "immediate value expected");
3467 int64_t shifter = Inst.getOperand(3).getImm();
3468 if (shifter != 0 && shifter != 12)
3469 return Error(Loc[3], "shift value out of range");
3470 // The imm12 operand can be an expression. Validate that it's legit.
3471 // FIXME: We really, really want to allow arbitrary expressions here
3472 // and resolve the value and validate the result at fixup time, but
3473 // that's hard as we have long since lost any source information we
3474 // need to generate good diagnostics by that point.
3475 if (Inst.getOpcode() == ARM64::ADDXri && Inst.getOperand(2).isExpr()) {
3476 const MCExpr *Expr = Inst.getOperand(2).getExpr();
3477 ARM64MCExpr::VariantKind ELFRefKind;
3478 MCSymbolRefExpr::VariantKind DarwinRefKind;
3479 const MCConstantExpr *Addend;
3480 if (!classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
3481 return Error(Loc[2], "invalid immediate expression");
3484 if (DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
3485 DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGEOFF ||
3486 ELFRefKind == ARM64MCExpr::VK_LO12 ||
3487 ELFRefKind == ARM64MCExpr::VK_DTPREL_LO12 ||
3488 ELFRefKind == ARM64MCExpr::VK_DTPREL_LO12_NC ||
3489 ELFRefKind == ARM64MCExpr::VK_TPREL_LO12 ||
3490 ELFRefKind == ARM64MCExpr::VK_TPREL_LO12_NC ||
3491 ELFRefKind == ARM64MCExpr::VK_TLSDESC_LO12) {
3492 // Note that we don't range-check the addend. It's adjusted
3493 // modulo page size when converted, so there is no "out of range"
3494 // condition when using @pageoff. Any validity checking for the value
3495 // was done in the is*() predicate function.
3497 } else if (DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGEOFF) {
3498 // @gotpageoff can only be used directly, not with an addend.
3502 // Otherwise, we're not sure, so don't allow it for now.
3503 return Error(Loc[2], "invalid immediate expression");
3506 // If it's anything but an immediate, it's not legit.
3507 if (!Inst.getOperand(2).isImm())
3508 return Error(Loc[2], "invalid immediate expression");
3509 int64_t imm = Inst.getOperand(2).getImm();
3510 if (imm > 4095 || imm < 0)
3511 return Error(Loc[2], "immediate value out of range");
3514 case ARM64::LDRBpre:
3515 case ARM64::LDRHpre:
3516 case ARM64::LDRSBWpre:
3517 case ARM64::LDRSBXpre:
3518 case ARM64::LDRSHWpre:
3519 case ARM64::LDRSHXpre:
3520 case ARM64::LDRWpre:
3521 case ARM64::LDRXpre:
3522 case ARM64::LDRSpre:
3523 case ARM64::LDRDpre:
3524 case ARM64::LDRQpre:
3525 case ARM64::STRBpre:
3526 case ARM64::STRHpre:
3527 case ARM64::STRWpre:
3528 case ARM64::STRXpre:
3529 case ARM64::STRSpre:
3530 case ARM64::STRDpre:
3531 case ARM64::STRQpre:
3532 case ARM64::LDRBpost:
3533 case ARM64::LDRHpost:
3534 case ARM64::LDRSBWpost:
3535 case ARM64::LDRSBXpost:
3536 case ARM64::LDRSHWpost:
3537 case ARM64::LDRSHXpost:
3538 case ARM64::LDRWpost:
3539 case ARM64::LDRXpost:
3540 case ARM64::LDRSpost:
3541 case ARM64::LDRDpost:
3542 case ARM64::LDRQpost:
3543 case ARM64::STRBpost:
3544 case ARM64::STRHpost:
3545 case ARM64::STRWpost:
3546 case ARM64::STRXpost:
3547 case ARM64::STRSpost:
3548 case ARM64::STRDpost:
3549 case ARM64::STRQpost:
3554 case ARM64::LDTRSHWi:
3555 case ARM64::LDTRSHXi:
3556 case ARM64::LDTRSBWi:
3557 case ARM64::LDTRSBXi:
3558 case ARM64::LDTRSWi:
3570 case ARM64::LDURSHWi:
3571 case ARM64::LDURSHXi:
3572 case ARM64::LDURSBWi:
3573 case ARM64::LDURSBXi:
3574 case ARM64::LDURSWi:
3582 case ARM64::STURBi: {
3583 // FIXME: Should accept expressions and error in fixup evaluation
3585 if (!Inst.getOperand(2).isImm())
3586 return Error(Loc[1], "immediate value expected");
3587 int64_t offset = Inst.getOperand(2).getImm();
3588 if (offset > 255 || offset < -256)
3589 return Error(Loc[1], "offset value out of range");
3594 case ARM64::LDRSWro:
3596 case ARM64::STRSro: {
3597 // FIXME: Should accept expressions and error in fixup evaluation
3599 if (!Inst.getOperand(3).isImm())
3600 return Error(Loc[1], "immediate value expected");
3601 int64_t shift = Inst.getOperand(3).getImm();
3602 ARM64_AM::ExtendType type = ARM64_AM::getMemExtendType(shift);
3603 if (type != ARM64_AM::UXTW && type != ARM64_AM::UXTX &&
3604 type != ARM64_AM::SXTW && type != ARM64_AM::SXTX)
3605 return Error(Loc[1], "shift type invalid");
3614 case ARM64::STRQro: {
3615 // FIXME: Should accept expressions and error in fixup evaluation
3617 if (!Inst.getOperand(3).isImm())
3618 return Error(Loc[1], "immediate value expected");
3619 int64_t shift = Inst.getOperand(3).getImm();
3620 ARM64_AM::ExtendType type = ARM64_AM::getMemExtendType(shift);
3621 if (type != ARM64_AM::UXTW && type != ARM64_AM::UXTX &&
3622 type != ARM64_AM::SXTW && type != ARM64_AM::SXTX)
3623 return Error(Loc[1], "shift type invalid");
3627 case ARM64::LDRHHro:
3628 case ARM64::LDRSHWro:
3629 case ARM64::LDRSHXro:
3631 case ARM64::STRHHro: {
3632 // FIXME: Should accept expressions and error in fixup evaluation
3634 if (!Inst.getOperand(3).isImm())
3635 return Error(Loc[1], "immediate value expected");
3636 int64_t shift = Inst.getOperand(3).getImm();
3637 ARM64_AM::ExtendType type = ARM64_AM::getMemExtendType(shift);
3638 if (type != ARM64_AM::UXTW && type != ARM64_AM::UXTX &&
3639 type != ARM64_AM::SXTW && type != ARM64_AM::SXTX)
3640 return Error(Loc[1], "shift type invalid");
3644 case ARM64::LDRBBro:
3645 case ARM64::LDRSBWro:
3646 case ARM64::LDRSBXro:
3648 case ARM64::STRBBro: {
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");
3671 case ARM64::LDPWpre:
3672 case ARM64::LDPXpre:
3673 case ARM64::LDPSpre:
3674 case ARM64::LDPDpre:
3675 case ARM64::LDPQpre:
3676 case ARM64::LDPSWpre:
3677 case ARM64::STPWpre:
3678 case ARM64::STPXpre:
3679 case ARM64::STPSpre:
3680 case ARM64::STPDpre:
3681 case ARM64::STPQpre:
3682 case ARM64::LDPWpost:
3683 case ARM64::LDPXpost:
3684 case ARM64::LDPSpost:
3685 case ARM64::LDPDpost:
3686 case ARM64::LDPQpost:
3687 case ARM64::LDPSWpost:
3688 case ARM64::STPWpost:
3689 case ARM64::STPXpost:
3690 case ARM64::STPSpost:
3691 case ARM64::STPDpost:
3692 case ARM64::STPQpost:
3702 case ARM64::STNPQi: {
3703 // FIXME: Should accept expressions and error in fixup evaluation
3705 if (!Inst.getOperand(3).isImm())
3706 return Error(Loc[2], "immediate value expected");
3707 int64_t offset = Inst.getOperand(3).getImm();
3708 if (offset > 63 || offset < -64)
3709 return Error(Loc[2], "offset value out of range");
3717 static void rewriteMOVI(ARM64AsmParser::OperandVector &Operands,
3718 StringRef mnemonic, uint64_t imm, unsigned shift,
3719 MCContext &Context) {
3720 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[0]);
3721 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
3723 ARM64Operand::CreateToken(mnemonic, false, Op->getStartLoc(), Context);
3725 const MCExpr *NewImm = MCConstantExpr::Create(imm >> shift, Context);
3726 Operands[2] = ARM64Operand::CreateImm(NewImm, Op2->getStartLoc(),
3727 Op2->getEndLoc(), Context);
3729 Operands.push_back(ARM64Operand::CreateShifter(
3730 ARM64_AM::LSL, shift, Op2->getStartLoc(), Op2->getEndLoc(), Context));
3735 static void rewriteMOVRSP(ARM64AsmParser::OperandVector &Operands,
3736 MCContext &Context) {
3737 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[0]);
3738 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
3740 ARM64Operand::CreateToken("add", false, Op->getStartLoc(), Context);
3742 const MCExpr *Imm = MCConstantExpr::Create(0, Context);
3743 Operands.push_back(ARM64Operand::CreateImm(Imm, Op2->getStartLoc(),
3744 Op2->getEndLoc(), Context));
3745 Operands.push_back(ARM64Operand::CreateShifter(
3746 ARM64_AM::LSL, 0, Op2->getStartLoc(), Op2->getEndLoc(), Context));
3751 static void rewriteMOVR(ARM64AsmParser::OperandVector &Operands,
3752 MCContext &Context) {
3753 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[0]);
3754 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
3756 ARM64Operand::CreateToken("orr", false, Op->getStartLoc(), Context);
3758 // Operands[2] becomes Operands[3].
3759 Operands.push_back(Operands[2]);
3760 // And Operands[2] becomes ZR.
3761 unsigned ZeroReg = ARM64::XZR;
3762 if (ARM64MCRegisterClasses[ARM64::GPR32allRegClassID].contains(
3763 Operands[2]->getReg()))
3764 ZeroReg = ARM64::WZR;
3767 ARM64Operand::CreateReg(ZeroReg, false, Op2->getStartLoc(),
3768 Op2->getEndLoc(), Context);
3773 bool ARM64AsmParser::showMatchError(SMLoc Loc, unsigned ErrCode) {
3775 case Match_MissingFeature:
3777 "instruction requires a CPU feature not currently enabled");
3778 case Match_InvalidOperand:
3779 return Error(Loc, "invalid operand for instruction");
3780 case Match_InvalidSuffix:
3781 return Error(Loc, "invalid type suffix for instruction");
3782 case Match_InvalidMemoryIndexedSImm9:
3783 return Error(Loc, "index must be an integer in range [-256,255].");
3784 case Match_InvalidMemoryIndexed32SImm7:
3785 return Error(Loc, "index must be a multiple of 4 in range [-256,252].");
3786 case Match_InvalidMemoryIndexed64SImm7:
3787 return Error(Loc, "index must be a multiple of 8 in range [-512,504].");
3788 case Match_InvalidMemoryIndexed128SImm7:
3789 return Error(Loc, "index must be a multiple of 16 in range [-1024,1008].");
3790 case Match_InvalidMemoryIndexed8:
3791 return Error(Loc, "index must be an integer in range [0,4095].");
3792 case Match_InvalidMemoryIndexed16:
3793 return Error(Loc, "index must be a multiple of 2 in range [0,8190].");
3794 case Match_InvalidMemoryIndexed32:
3795 return Error(Loc, "index must be a multiple of 4 in range [0,16380].");
3796 case Match_InvalidMemoryIndexed64:
3797 return Error(Loc, "index must be a multiple of 8 in range [0,32760].");
3798 case Match_InvalidMemoryIndexed128:
3799 return Error(Loc, "index must be a multiple of 16 in range [0,65520].");
3800 case Match_InvalidImm1_8:
3801 return Error(Loc, "immediate must be an integer in range [1,8].");
3802 case Match_InvalidImm1_16:
3803 return Error(Loc, "immediate must be an integer in range [1,16].");
3804 case Match_InvalidImm1_32:
3805 return Error(Loc, "immediate must be an integer in range [1,32].");
3806 case Match_InvalidImm1_64:
3807 return Error(Loc, "immediate must be an integer in range [1,64].");
3808 case Match_InvalidLabel:
3809 return Error(Loc, "expected label or encodable integer pc offset");
3810 case Match_MnemonicFail:
3811 return Error(Loc, "unrecognized instruction mnemonic");
3813 assert(0 && "unexpected error code!");
3814 return Error(Loc, "invalid instruction format");
3818 bool ARM64AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
3819 OperandVector &Operands,
3821 unsigned &ErrorInfo,
3822 bool MatchingInlineAsm) {
3823 assert(!Operands.empty() && "Unexpect empty operand list!");
3824 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[0]);
3825 assert(Op->isToken() && "Leading operand should always be a mnemonic!");
3827 StringRef Tok = Op->getToken();
3828 // Translate CMN/CMP pseudos to ADDS/SUBS with zero register destination.
3829 // This needs to be done before the special handling of ADD/SUB immediates.
3830 if (Tok == "cmp" || Tok == "cmn") {
3831 // Replace the opcode with either ADDS or SUBS.
3832 const char *Repl = StringSwitch<const char *>(Tok)
3833 .Case("cmp", "subs")
3834 .Case("cmn", "adds")
3836 assert(Repl && "Unknown compare instruction");
3838 Operands[0] = ARM64Operand::CreateToken(Repl, false, IDLoc, getContext());
3840 // Insert WZR or XZR as destination operand.
3841 ARM64Operand *RegOp = static_cast<ARM64Operand *>(Operands[1]);
3843 if (RegOp->isReg() &&
3844 ARM64MCRegisterClasses[ARM64::GPR32allRegClassID].contains(
3846 ZeroReg = ARM64::WZR;
3848 ZeroReg = ARM64::XZR;
3850 Operands.begin() + 1,
3851 ARM64Operand::CreateReg(ZeroReg, false, IDLoc, IDLoc, getContext()));
3852 // Update since we modified it above.
3853 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[0]);
3854 Tok = Op->getToken();
3857 unsigned NumOperands = Operands.size();
3859 if (Tok == "mov" && NumOperands == 3) {
3860 // The MOV mnemomic is aliased to movn/movz, depending on the value of
3861 // the immediate being instantiated.
3862 // FIXME: Catching this here is a total hack, and we should use tblgen
3863 // support to implement this instead as soon as it is available.
3865 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
3866 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
3868 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op2->getImm())) {
3869 uint64_t Val = CE->getValue();
3870 uint64_t NVal = ~Val;
3872 // If this is a 32-bit register and the value has none of the upper
3873 // set, clear the complemented upper 32-bits so the logic below works
3874 // for 32-bit registers too.
3875 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
3877 ARM64MCRegisterClasses[ARM64::GPR32allRegClassID].contains(
3879 (Val & 0xFFFFFFFFULL) == Val)
3880 NVal &= 0x00000000FFFFFFFFULL;
3882 // MOVK Rd, imm << 0
3883 if ((Val & 0xFFFF) == Val)
3884 rewriteMOVI(Operands, "movz", Val, 0, getContext());
3886 // MOVK Rd, imm << 16
3887 else if ((Val & 0xFFFF0000ULL) == Val)
3888 rewriteMOVI(Operands, "movz", Val, 16, getContext());
3890 // MOVK Rd, imm << 32
3891 else if ((Val & 0xFFFF00000000ULL) == Val)
3892 rewriteMOVI(Operands, "movz", Val, 32, getContext());
3894 // MOVK Rd, imm << 48
3895 else if ((Val & 0xFFFF000000000000ULL) == Val)
3896 rewriteMOVI(Operands, "movz", Val, 48, getContext());
3898 // MOVN Rd, (~imm << 0)
3899 else if ((NVal & 0xFFFFULL) == NVal)
3900 rewriteMOVI(Operands, "movn", NVal, 0, getContext());
3902 // MOVN Rd, ~(imm << 16)
3903 else if ((NVal & 0xFFFF0000ULL) == NVal)
3904 rewriteMOVI(Operands, "movn", NVal, 16, getContext());
3906 // MOVN Rd, ~(imm << 32)
3907 else if ((NVal & 0xFFFF00000000ULL) == NVal)
3908 rewriteMOVI(Operands, "movn", NVal, 32, getContext());
3910 // MOVN Rd, ~(imm << 48)
3911 else if ((NVal & 0xFFFF000000000000ULL) == NVal)
3912 rewriteMOVI(Operands, "movn", NVal, 48, getContext());
3914 } else if (Op1->isReg() && Op2->isReg()) {
3916 unsigned Reg1 = Op1->getReg();
3917 unsigned Reg2 = Op2->getReg();
3918 if ((Reg1 == ARM64::SP &&
3919 ARM64MCRegisterClasses[ARM64::GPR64allRegClassID].contains(Reg2)) ||
3920 (Reg2 == ARM64::SP &&
3921 ARM64MCRegisterClasses[ARM64::GPR64allRegClassID].contains(Reg1)) ||
3922 (Reg1 == ARM64::WSP &&
3923 ARM64MCRegisterClasses[ARM64::GPR32allRegClassID].contains(Reg2)) ||
3924 (Reg2 == ARM64::WSP &&
3925 ARM64MCRegisterClasses[ARM64::GPR32allRegClassID].contains(Reg1)))
3926 rewriteMOVRSP(Operands, getContext());
3928 rewriteMOVR(Operands, getContext());
3930 } else if (NumOperands == 4) {
3931 if (Tok == "add" || Tok == "adds" || Tok == "sub" || Tok == "subs") {
3932 // Handle the uimm24 immediate form, where the shift is not specified.
3933 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
3935 if (const MCConstantExpr *CE =
3936 dyn_cast<MCConstantExpr>(Op3->getImm())) {
3937 uint64_t Val = CE->getValue();
3938 if (Val >= (1 << 24)) {
3939 Error(IDLoc, "immediate value is too large");
3942 if (Val < (1 << 12)) {
3943 Operands.push_back(ARM64Operand::CreateShifter(
3944 ARM64_AM::LSL, 0, IDLoc, IDLoc, getContext()));
3945 } else if ((Val & 0xfff) == 0) {
3947 CE = MCConstantExpr::Create(Val >> 12, getContext());
3949 ARM64Operand::CreateImm(CE, IDLoc, IDLoc, getContext());
3950 Operands.push_back(ARM64Operand::CreateShifter(
3951 ARM64_AM::LSL, 12, IDLoc, IDLoc, getContext()));
3953 Error(IDLoc, "immediate value is too large");
3957 Operands.push_back(ARM64Operand::CreateShifter(
3958 ARM64_AM::LSL, 0, IDLoc, IDLoc, getContext()));
3962 // FIXME: Horible hack to handle the LSL -> UBFM alias.
3963 } else if (NumOperands == 4 && Tok == "lsl") {
3964 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
3965 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
3966 if (Op2->isReg() && Op3->isImm()) {
3967 const MCConstantExpr *Op3CE = dyn_cast<MCConstantExpr>(Op3->getImm());
3969 uint64_t Op3Val = Op3CE->getValue();
3970 uint64_t NewOp3Val = 0;
3971 uint64_t NewOp4Val = 0;
3972 if (ARM64MCRegisterClasses[ARM64::GPR32allRegClassID].contains(
3974 NewOp3Val = (32 - Op3Val) & 0x1f;
3975 NewOp4Val = 31 - Op3Val;
3977 NewOp3Val = (64 - Op3Val) & 0x3f;
3978 NewOp4Val = 63 - Op3Val;
3981 const MCExpr *NewOp3 =
3982 MCConstantExpr::Create(NewOp3Val, getContext());
3983 const MCExpr *NewOp4 =
3984 MCConstantExpr::Create(NewOp4Val, getContext());
3986 Operands[0] = ARM64Operand::CreateToken(
3987 "ubfm", false, Op->getStartLoc(), getContext());
3988 Operands[3] = ARM64Operand::CreateImm(NewOp3, Op3->getStartLoc(),
3989 Op3->getEndLoc(), getContext());
3990 Operands.push_back(ARM64Operand::CreateImm(
3991 NewOp4, Op3->getStartLoc(), Op3->getEndLoc(), getContext()));
3997 // FIXME: Horrible hack to handle the optional LSL shift for vector
3999 } else if (NumOperands == 4 && (Tok == "bic" || Tok == "orr")) {
4000 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
4001 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
4002 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
4003 if ((Op1->isToken() && Op2->isVectorReg() && Op3->isImm()) ||
4004 (Op1->isVectorReg() && Op2->isToken() && Op3->isImm()))
4005 Operands.push_back(ARM64Operand::CreateShifter(ARM64_AM::LSL, 0, IDLoc,
4006 IDLoc, getContext()));
4007 } else if (NumOperands == 4 && (Tok == "movi" || Tok == "mvni")) {
4008 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
4009 ARM64Operand *Op2 = static_cast<ARM64Operand *>(Operands[2]);
4010 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
4011 if ((Op1->isToken() && Op2->isVectorReg() && Op3->isImm()) ||
4012 (Op1->isVectorReg() && Op2->isToken() && Op3->isImm())) {
4013 StringRef Suffix = Op1->isToken() ? Op1->getToken() : Op2->getToken();
4014 // Canonicalize on lower-case for ease of comparison.
4015 std::string CanonicalSuffix = Suffix.lower();
4016 if (Tok != "movi" ||
4017 (CanonicalSuffix != ".1d" && CanonicalSuffix != ".2d" &&
4018 CanonicalSuffix != ".8b" && CanonicalSuffix != ".16b"))
4019 Operands.push_back(ARM64Operand::CreateShifter(
4020 ARM64_AM::LSL, 0, IDLoc, IDLoc, getContext()));
4023 } else if (NumOperands == 5) {
4024 // FIXME: Horrible hack to handle the BFI -> BFM, SBFIZ->SBFM, and
4025 // UBFIZ -> UBFM aliases.
4026 if (Tok == "bfi" || Tok == "sbfiz" || Tok == "ubfiz") {
4027 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
4028 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
4029 ARM64Operand *Op4 = static_cast<ARM64Operand *>(Operands[4]);
4031 if (Op1->isReg() && Op3->isImm() && Op4->isImm()) {
4032 const MCConstantExpr *Op3CE = dyn_cast<MCConstantExpr>(Op3->getImm());
4033 const MCConstantExpr *Op4CE = dyn_cast<MCConstantExpr>(Op4->getImm());
4035 if (Op3CE && Op4CE) {
4036 uint64_t Op3Val = Op3CE->getValue();
4037 uint64_t Op4Val = Op4CE->getValue();
4039 uint64_t NewOp3Val = 0;
4040 if (ARM64MCRegisterClasses[ARM64::GPR32allRegClassID].contains(
4042 NewOp3Val = (32 - Op3Val) & 0x1f;
4044 NewOp3Val = (64 - Op3Val) & 0x3f;
4046 uint64_t NewOp4Val = Op4Val - 1;
4048 const MCExpr *NewOp3 =
4049 MCConstantExpr::Create(NewOp3Val, getContext());
4050 const MCExpr *NewOp4 =
4051 MCConstantExpr::Create(NewOp4Val, getContext());
4052 Operands[3] = ARM64Operand::CreateImm(NewOp3, Op3->getStartLoc(),
4053 Op3->getEndLoc(), getContext());
4054 Operands[4] = ARM64Operand::CreateImm(NewOp4, Op4->getStartLoc(),
4055 Op4->getEndLoc(), getContext());
4057 Operands[0] = ARM64Operand::CreateToken(
4058 "bfm", false, Op->getStartLoc(), getContext());
4059 else if (Tok == "sbfiz")
4060 Operands[0] = ARM64Operand::CreateToken(
4061 "sbfm", false, Op->getStartLoc(), getContext());
4062 else if (Tok == "ubfiz")
4063 Operands[0] = ARM64Operand::CreateToken(
4064 "ubfm", false, Op->getStartLoc(), getContext());
4066 llvm_unreachable("No valid mnemonic for alias?");
4074 // FIXME: Horrible hack to handle the BFXIL->BFM, SBFX->SBFM, and
4075 // UBFX -> UBFM aliases.
4076 } else if (NumOperands == 5 &&
4077 (Tok == "bfxil" || Tok == "sbfx" || Tok == "ubfx")) {
4078 ARM64Operand *Op1 = static_cast<ARM64Operand *>(Operands[1]);
4079 ARM64Operand *Op3 = static_cast<ARM64Operand *>(Operands[3]);
4080 ARM64Operand *Op4 = static_cast<ARM64Operand *>(Operands[4]);
4082 if (Op1->isReg() && Op3->isImm() && Op4->isImm()) {
4083 const MCConstantExpr *Op3CE = dyn_cast<MCConstantExpr>(Op3->getImm());
4084 const MCConstantExpr *Op4CE = dyn_cast<MCConstantExpr>(Op4->getImm());
4086 if (Op3CE && Op4CE) {
4087 uint64_t Op3Val = Op3CE->getValue();
4088 uint64_t Op4Val = Op4CE->getValue();
4089 uint64_t NewOp4Val = Op3Val + Op4Val - 1;
4091 if (NewOp4Val >= Op3Val) {
4092 const MCExpr *NewOp4 =
4093 MCConstantExpr::Create(NewOp4Val, getContext());
4094 Operands[4] = ARM64Operand::CreateImm(
4095 NewOp4, Op4->getStartLoc(), Op4->getEndLoc(), getContext());
4097 Operands[0] = ARM64Operand::CreateToken(
4098 "bfm", false, Op->getStartLoc(), getContext());
4099 else if (Tok == "sbfx")
4100 Operands[0] = ARM64Operand::CreateToken(
4101 "sbfm", false, Op->getStartLoc(), getContext());
4102 else if (Tok == "ubfx")
4103 Operands[0] = ARM64Operand::CreateToken(
4104 "ubfm", false, Op->getStartLoc(), getContext());
4106 llvm_unreachable("No valid mnemonic for alias?");
4115 // FIXME: Horrible hack for tbz and tbnz with Wn register operand.
4116 // InstAlias can't quite handle this since the reg classes aren't
4118 if (NumOperands == 4 && (Tok == "tbz" || Tok == "tbnz")) {
4119 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[2]);
4121 if (const MCConstantExpr *OpCE = dyn_cast<MCConstantExpr>(Op->getImm())) {
4122 if (OpCE->getValue() < 32) {
4123 // The source register can be Wn here, but the matcher expects a
4124 // GPR64. Twiddle it here if necessary.
4125 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[1]);
4127 unsigned Reg = getXRegFromWReg(Op->getReg());
4128 Operands[1] = ARM64Operand::CreateReg(
4129 Reg, false, Op->getStartLoc(), Op->getEndLoc(), getContext());
4136 // FIXME: Horrible hack for sxtw and uxtw with Wn src and Xd dst operands.
4137 // InstAlias can't quite handle this since the reg classes aren't
4139 if (NumOperands == 3 && (Tok == "sxtw" || Tok == "uxtw")) {
4140 // The source register can be Wn here, but the matcher expects a
4141 // GPR64. Twiddle it here if necessary.
4142 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[2]);
4144 unsigned Reg = getXRegFromWReg(Op->getReg());
4145 Operands[2] = ARM64Operand::CreateReg(Reg, false, Op->getStartLoc(),
4146 Op->getEndLoc(), getContext());
4150 // FIXME: Likewise for [su]xt[bh] with a Xd dst operand
4151 else if (NumOperands == 3 &&
4152 (Tok == "sxtb" || Tok == "uxtb" || Tok == "sxth" || Tok == "uxth")) {
4153 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[1]);
4155 ARM64MCRegisterClasses[ARM64::GPR64allRegClassID].contains(
4157 // The source register can be Wn here, but the matcher expects a
4158 // GPR64. Twiddle it here if necessary.
4159 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[2]);
4161 unsigned Reg = getXRegFromWReg(Op->getReg());
4162 Operands[2] = ARM64Operand::CreateReg(Reg, false, Op->getStartLoc(),
4163 Op->getEndLoc(), getContext());
4169 // Yet another horrible hack to handle FMOV Rd, #0.0 using [WX]ZR.
4170 if (NumOperands == 3 && Tok == "fmov") {
4171 ARM64Operand *RegOp = static_cast<ARM64Operand *>(Operands[1]);
4172 ARM64Operand *ImmOp = static_cast<ARM64Operand *>(Operands[2]);
4173 if (RegOp->isReg() && ImmOp->isFPImm() &&
4174 ImmOp->getFPImm() == (unsigned)-1) {
4175 unsigned zreg = ARM64MCRegisterClasses[ARM64::FPR32RegClassID].contains(
4179 Operands[2] = ARM64Operand::CreateReg(zreg, false, Op->getStartLoc(),
4180 Op->getEndLoc(), getContext());
4185 // FIXME: Horrible hack to handle the literal .d[1] vector index on
4186 // FMOV instructions. The index isn't an actual instruction operand
4187 // but rather syntactic sugar. It really should be part of the mnemonic,
4188 // not the operand, but whatever.
4189 if ((NumOperands == 5) && Tok == "fmov") {
4190 // If the last operand is a vectorindex of '1', then replace it with
4191 // a '[' '1' ']' token sequence, which is what the matcher
4192 // (annoyingly) expects for a literal vector index operand.
4193 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[NumOperands - 1]);
4194 if (Op->isVectorIndexD() && Op->getVectorIndex() == 1) {
4195 SMLoc Loc = Op->getStartLoc();
4196 Operands.pop_back();
4199 ARM64Operand::CreateToken("[", false, Loc, getContext()));
4201 ARM64Operand::CreateToken("1", false, Loc, getContext()));
4203 ARM64Operand::CreateToken("]", false, Loc, getContext()));
4204 } else if (Op->isReg()) {
4205 // Similarly, check the destination operand for the GPR->High-lane
4207 unsigned OpNo = NumOperands - 2;
4208 ARM64Operand *Op = static_cast<ARM64Operand *>(Operands[OpNo]);
4209 if (Op->isVectorIndexD() && Op->getVectorIndex() == 1) {
4210 SMLoc Loc = Op->getStartLoc();
4212 ARM64Operand::CreateToken("[", false, Loc, getContext());
4214 Operands.begin() + OpNo + 1,
4215 ARM64Operand::CreateToken("1", false, Loc, getContext()));
4217 Operands.begin() + OpNo + 2,
4218 ARM64Operand::CreateToken("]", false, Loc, getContext()));
4225 // First try to match against the secondary set of tables containing the
4226 // short-form NEON instructions (e.g. "fadd.2s v0, v1, v2").
4227 unsigned MatchResult =
4228 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm, 1);
4230 // If that fails, try against the alternate table containing long-form NEON:
4231 // "fadd v0.2s, v1.2s, v2.2s"
4232 if (MatchResult != Match_Success)
4234 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm, 0);
4236 switch (MatchResult) {
4237 case Match_Success: {
4238 // Perform range checking and other semantic validations
4239 SmallVector<SMLoc, 8> OperandLocs;
4240 NumOperands = Operands.size();
4241 for (unsigned i = 1; i < NumOperands; ++i)
4242 OperandLocs.push_back(Operands[i]->getStartLoc());
4243 if (validateInstruction(Inst, OperandLocs))
4247 Out.EmitInstruction(Inst, STI);
4250 case Match_MissingFeature:
4251 case Match_MnemonicFail:
4252 return showMatchError(IDLoc, MatchResult);
4253 case Match_InvalidOperand: {
4254 SMLoc ErrorLoc = IDLoc;
4255 if (ErrorInfo != ~0U) {
4256 if (ErrorInfo >= Operands.size())
4257 return Error(IDLoc, "too few operands for instruction");
4259 ErrorLoc = ((ARM64Operand *)Operands[ErrorInfo])->getStartLoc();
4260 if (ErrorLoc == SMLoc())
4263 // If the match failed on a suffix token operand, tweak the diagnostic
4265 if (((ARM64Operand *)Operands[ErrorInfo])->isToken() &&
4266 ((ARM64Operand *)Operands[ErrorInfo])->isTokenSuffix())
4267 MatchResult = Match_InvalidSuffix;
4269 return showMatchError(ErrorLoc, MatchResult);
4271 case Match_InvalidMemoryIndexedSImm9: {
4272 // If there is not a '!' after the memory operand that failed, we really
4273 // want the diagnostic for the non-pre-indexed instruction variant instead.
4274 // Be careful to check for the post-indexed variant as well, which also
4275 // uses this match diagnostic. Also exclude the explicitly unscaled
4276 // mnemonics, as they want the unscaled diagnostic as well.
4277 if (Operands.size() == ErrorInfo + 1 &&
4278 !((ARM64Operand *)Operands[ErrorInfo])->isImm() &&
4279 !Tok.startswith("stur") && !Tok.startswith("ldur")) {
4280 // whether we want an Indexed64 or Indexed32 diagnostic depends on
4281 // the register class of the previous operand. Default to 64 in case
4282 // we see something unexpected.
4283 MatchResult = Match_InvalidMemoryIndexed64;
4285 ARM64Operand *PrevOp = (ARM64Operand *)Operands[ErrorInfo - 1];
4286 if (PrevOp->isReg() &&
4287 ARM64MCRegisterClasses[ARM64::GPR32RegClassID].contains(
4289 MatchResult = Match_InvalidMemoryIndexed32;
4292 SMLoc ErrorLoc = ((ARM64Operand *)Operands[ErrorInfo])->getStartLoc();
4293 if (ErrorLoc == SMLoc())
4295 return showMatchError(ErrorLoc, MatchResult);
4297 case Match_InvalidMemoryIndexed32:
4298 case Match_InvalidMemoryIndexed64:
4299 case Match_InvalidMemoryIndexed128:
4300 // If there is a '!' after the memory operand that failed, we really
4301 // want the diagnostic for the pre-indexed instruction variant instead.
4302 if (Operands.size() > ErrorInfo + 1 &&
4303 ((ARM64Operand *)Operands[ErrorInfo + 1])->isTokenEqual("!"))
4304 MatchResult = Match_InvalidMemoryIndexedSImm9;
4306 case Match_InvalidMemoryIndexed8:
4307 case Match_InvalidMemoryIndexed16:
4308 case Match_InvalidMemoryIndexed32SImm7:
4309 case Match_InvalidMemoryIndexed64SImm7:
4310 case Match_InvalidMemoryIndexed128SImm7:
4311 case Match_InvalidImm1_8:
4312 case Match_InvalidImm1_16:
4313 case Match_InvalidImm1_32:
4314 case Match_InvalidImm1_64:
4315 case Match_InvalidLabel: {
4316 // Any time we get here, there's nothing fancy to do. Just get the
4317 // operand SMLoc and display the diagnostic.
4318 SMLoc ErrorLoc = ((ARM64Operand *)Operands[ErrorInfo])->getStartLoc();
4319 // If it's a memory operand, the error is with the offset immediate,
4320 // so get that location instead.
4321 if (((ARM64Operand *)Operands[ErrorInfo])->isMem())
4322 ErrorLoc = ((ARM64Operand *)Operands[ErrorInfo])->getOffsetLoc();
4323 if (ErrorLoc == SMLoc())
4325 return showMatchError(ErrorLoc, MatchResult);
4329 llvm_unreachable("Implement any new match types added!");
4333 /// ParseDirective parses the arm specific directives
4334 bool ARM64AsmParser::ParseDirective(AsmToken DirectiveID) {
4335 StringRef IDVal = DirectiveID.getIdentifier();
4336 SMLoc Loc = DirectiveID.getLoc();
4337 if (IDVal == ".hword")
4338 return parseDirectiveWord(2, Loc);
4339 if (IDVal == ".word")
4340 return parseDirectiveWord(4, Loc);
4341 if (IDVal == ".xword")
4342 return parseDirectiveWord(8, Loc);
4343 if (IDVal == ".tlsdesccall")
4344 return parseDirectiveTLSDescCall(Loc);
4346 return parseDirectiveLOH(IDVal, Loc);
4349 /// parseDirectiveWord
4350 /// ::= .word [ expression (, expression)* ]
4351 bool ARM64AsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
4352 if (getLexer().isNot(AsmToken::EndOfStatement)) {
4354 const MCExpr *Value;
4355 if (getParser().parseExpression(Value))
4358 getParser().getStreamer().EmitValue(Value, Size);
4360 if (getLexer().is(AsmToken::EndOfStatement))
4363 // FIXME: Improve diagnostic.
4364 if (getLexer().isNot(AsmToken::Comma))
4365 return Error(L, "unexpected token in directive");
4374 // parseDirectiveTLSDescCall:
4375 // ::= .tlsdesccall symbol
4376 bool ARM64AsmParser::parseDirectiveTLSDescCall(SMLoc L) {
4378 if (getParser().parseIdentifier(Name))
4379 return Error(L, "expected symbol after directive");
4381 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
4382 const MCExpr *Expr = MCSymbolRefExpr::Create(Sym, getContext());
4383 Expr = ARM64MCExpr::Create(Expr, ARM64MCExpr::VK_TLSDESC, getContext());
4386 Inst.setOpcode(ARM64::TLSDESCCALL);
4387 Inst.addOperand(MCOperand::CreateExpr(Expr));
4389 getParser().getStreamer().EmitInstruction(Inst, STI);
4393 /// ::= .loh <lohName | lohId> label1, ..., labelN
4394 /// The number of arguments depends on the loh identifier.
4395 bool ARM64AsmParser::parseDirectiveLOH(StringRef IDVal, SMLoc Loc) {
4396 if (IDVal != MCLOHDirectiveName())
4399 if (getParser().getTok().isNot(AsmToken::Identifier)) {
4400 if (getParser().getTok().isNot(AsmToken::Integer))
4401 return TokError("expected an identifier or a number in directive");
4402 // We successfully get a numeric value for the identifier.
4403 // Check if it is valid.
4404 int64_t Id = getParser().getTok().getIntVal();
4405 Kind = (MCLOHType)Id;
4406 // Check that Id does not overflow MCLOHType.
4407 if (!isValidMCLOHType(Kind) || Id != Kind)
4408 return TokError("invalid numeric identifier in directive");
4410 StringRef Name = getTok().getIdentifier();
4411 // We successfully parse an identifier.
4412 // Check if it is a recognized one.
4413 int Id = MCLOHNameToId(Name);
4416 return TokError("invalid identifier in directive");
4417 Kind = (MCLOHType)Id;
4419 // Consume the identifier.
4421 // Get the number of arguments of this LOH.
4422 int NbArgs = MCLOHIdToNbArgs(Kind);
4424 assert(NbArgs != -1 && "Invalid number of arguments");
4426 SmallVector<MCSymbol *, 3> Args;
4427 for (int Idx = 0; Idx < NbArgs; ++Idx) {
4429 if (getParser().parseIdentifier(Name))
4430 return TokError("expected identifier in directive");
4431 Args.push_back(getContext().GetOrCreateSymbol(Name));
4433 if (Idx + 1 == NbArgs)
4435 if (getLexer().isNot(AsmToken::Comma))
4436 return TokError("unexpected token in '" + Twine(IDVal) + "' directive");
4439 if (getLexer().isNot(AsmToken::EndOfStatement))
4440 return TokError("unexpected token in '" + Twine(IDVal) + "' directive");
4442 getStreamer().EmitLOHDirective((MCLOHType)Kind, Args);
4447 ARM64AsmParser::classifySymbolRef(const MCExpr *Expr,
4448 ARM64MCExpr::VariantKind &ELFRefKind,
4449 MCSymbolRefExpr::VariantKind &DarwinRefKind,
4450 const MCConstantExpr *&Addend) {
4451 ELFRefKind = ARM64MCExpr::VK_INVALID;
4452 DarwinRefKind = MCSymbolRefExpr::VK_None;
4454 if (const ARM64MCExpr *AE = dyn_cast<ARM64MCExpr>(Expr)) {
4455 ELFRefKind = AE->getKind();
4456 Expr = AE->getSubExpr();
4459 const MCSymbolRefExpr *SE = dyn_cast<MCSymbolRefExpr>(Expr);
4461 // It's a simple symbol reference with no addend.
4462 DarwinRefKind = SE->getKind();
4467 const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr);
4471 SE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
4474 DarwinRefKind = SE->getKind();
4476 if (BE->getOpcode() != MCBinaryExpr::Add)
4479 // See if the addend is is a constant, otherwise there's more going
4480 // on here than we can deal with.
4481 Addend = dyn_cast<MCConstantExpr>(BE->getRHS());
4485 // It's some symbol reference + a constant addend, but really
4486 // shouldn't use both Darwin and ELF syntax.
4487 return ELFRefKind == ARM64MCExpr::VK_INVALID ||
4488 DarwinRefKind == MCSymbolRefExpr::VK_None;
4491 /// Force static initialization.
4492 extern "C" void LLVMInitializeARM64AsmParser() {
4493 RegisterMCAsmParser<ARM64AsmParser> X(TheARM64Target);
4496 #define GET_REGISTER_MATCHER
4497 #define GET_MATCHER_IMPLEMENTATION
4498 #include "ARM64GenAsmMatcher.inc"
4500 // Define this matcher function after the auto-generated include so we
4501 // have the match class enum definitions.
4502 unsigned ARM64AsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
4504 ARM64Operand *Op = static_cast<ARM64Operand *>(AsmOp);
4505 // If the kind is a token for a literal immediate, check if our asm
4506 // operand matches. This is for InstAliases which have a fixed-value
4507 // immediate in the syntax.
4508 int64_t ExpectedVal;
4511 return Match_InvalidOperand;
4553 return Match_InvalidOperand;
4554 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
4556 return Match_InvalidOperand;
4557 if (CE->getValue() == ExpectedVal)
4558 return Match_Success;
4559 return Match_InvalidOperand;