1 //===-- ARMAsmParser.cpp - Parse ARM 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 "ARMFeatures.h"
11 #include "llvm/MC/MCTargetAsmParser.h"
12 #include "MCTargetDesc/ARMAddressingModes.h"
13 #include "MCTargetDesc/ARMBaseInfo.h"
14 #include "MCTargetDesc/ARMMCExpr.h"
15 #include "llvm/ADT/BitVector.h"
16 #include "llvm/ADT/OwningPtr.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCAssembler.h"
23 #include "llvm/MC/MCContext.h"
24 #include "llvm/MC/MCELFStreamer.h"
25 #include "llvm/MC/MCExpr.h"
26 #include "llvm/MC/MCInst.h"
27 #include "llvm/MC/MCInstrDesc.h"
28 #include "llvm/MC/MCInstrInfo.h"
29 #include "llvm/MC/MCParser/MCAsmLexer.h"
30 #include "llvm/MC/MCParser/MCAsmParser.h"
31 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
32 #include "llvm/MC/MCRegisterInfo.h"
33 #include "llvm/MC/MCStreamer.h"
34 #include "llvm/MC/MCSubtargetInfo.h"
35 #include "llvm/Support/ELF.h"
36 #include "llvm/Support/MathExtras.h"
37 #include "llvm/Support/SourceMgr.h"
38 #include "llvm/Support/TargetRegistry.h"
39 #include "llvm/Support/raw_ostream.h"
47 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
49 class ARMAsmParser : public MCTargetAsmParser {
52 const MCInstrInfo &MII;
53 const MCRegisterInfo *MRI;
55 // Unwind directives state
61 void resetUnwindDirectiveParserState() {
63 CantUnwindLoc = SMLoc();
64 PersonalityLoc = SMLoc();
65 HandlerDataLoc = SMLoc();
69 // Map of register aliases registers via the .req directive.
70 StringMap<unsigned> RegisterReqs;
73 ARMCC::CondCodes Cond; // Condition for IT block.
74 unsigned Mask:4; // Condition mask for instructions.
75 // Starting at first 1 (from lsb).
76 // '1' condition as indicated in IT.
77 // '0' inverse of condition (else).
78 // Count of instructions in IT block is
79 // 4 - trailingzeroes(mask)
81 bool FirstCond; // Explicit flag for when we're parsing the
82 // First instruction in the IT block. It's
83 // implied in the mask, so needs special
86 unsigned CurPosition; // Current position in parsing of IT
87 // block. In range [0,3]. Initialized
88 // according to count of instructions in block.
89 // ~0U if no active IT block.
91 bool inITBlock() { return ITState.CurPosition != ~0U;}
92 void forwardITPosition() {
93 if (!inITBlock()) return;
94 // Move to the next instruction in the IT block, if there is one. If not,
95 // mark the block as done.
96 unsigned TZ = countTrailingZeros(ITState.Mask);
97 if (++ITState.CurPosition == 5 - TZ)
98 ITState.CurPosition = ~0U; // Done with the IT block after this.
102 MCAsmParser &getParser() const { return Parser; }
103 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
105 bool Warning(SMLoc L, const Twine &Msg,
106 ArrayRef<SMRange> Ranges = None) {
107 return Parser.Warning(L, Msg, Ranges);
109 bool Error(SMLoc L, const Twine &Msg,
110 ArrayRef<SMRange> Ranges = None) {
111 return Parser.Error(L, Msg, Ranges);
114 int tryParseRegister();
115 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
116 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
117 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
118 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
119 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
120 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
121 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
122 unsigned &ShiftAmount);
123 bool parseDirectiveWord(unsigned Size, SMLoc L);
124 bool parseDirectiveThumb(SMLoc L);
125 bool parseDirectiveARM(SMLoc L);
126 bool parseDirectiveThumbFunc(SMLoc L);
127 bool parseDirectiveCode(SMLoc L);
128 bool parseDirectiveSyntax(SMLoc L);
129 bool parseDirectiveReq(StringRef Name, SMLoc L);
130 bool parseDirectiveUnreq(SMLoc L);
131 bool parseDirectiveArch(SMLoc L);
132 bool parseDirectiveEabiAttr(SMLoc L);
133 bool parseDirectiveFnStart(SMLoc L);
134 bool parseDirectiveFnEnd(SMLoc L);
135 bool parseDirectiveCantUnwind(SMLoc L);
136 bool parseDirectivePersonality(SMLoc L);
137 bool parseDirectiveHandlerData(SMLoc L);
138 bool parseDirectiveSetFP(SMLoc L);
139 bool parseDirectivePad(SMLoc L);
140 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
142 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
143 bool &CarrySetting, unsigned &ProcessorIMod,
145 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
146 bool &CanAcceptCarrySet,
147 bool &CanAcceptPredicationCode);
149 bool isThumb() const {
150 // FIXME: Can tablegen auto-generate this?
151 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
153 bool isThumbOne() const {
154 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
156 bool isThumbTwo() const {
157 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
159 bool hasThumb() const {
160 return STI.getFeatureBits() & ARM::HasV4TOps;
162 bool hasV6Ops() const {
163 return STI.getFeatureBits() & ARM::HasV6Ops;
165 bool hasV6MOps() const {
166 return STI.getFeatureBits() & ARM::HasV6MOps;
168 bool hasV7Ops() const {
169 return STI.getFeatureBits() & ARM::HasV7Ops;
171 bool hasV8Ops() const {
172 return STI.getFeatureBits() & ARM::HasV8Ops;
174 bool hasARM() const {
175 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
179 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
180 setAvailableFeatures(FB);
182 bool isMClass() const {
183 return STI.getFeatureBits() & ARM::FeatureMClass;
186 /// @name Auto-generated Match Functions
189 #define GET_ASSEMBLER_HEADER
190 #include "ARMGenAsmMatcher.inc"
194 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
195 OperandMatchResultTy parseCoprocNumOperand(
196 SmallVectorImpl<MCParsedAsmOperand*>&);
197 OperandMatchResultTy parseCoprocRegOperand(
198 SmallVectorImpl<MCParsedAsmOperand*>&);
199 OperandMatchResultTy parseCoprocOptionOperand(
200 SmallVectorImpl<MCParsedAsmOperand*>&);
201 OperandMatchResultTy parseMemBarrierOptOperand(
202 SmallVectorImpl<MCParsedAsmOperand*>&);
203 OperandMatchResultTy parseInstSyncBarrierOptOperand(
204 SmallVectorImpl<MCParsedAsmOperand*>&);
205 OperandMatchResultTy parseProcIFlagsOperand(
206 SmallVectorImpl<MCParsedAsmOperand*>&);
207 OperandMatchResultTy parseMSRMaskOperand(
208 SmallVectorImpl<MCParsedAsmOperand*>&);
209 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
210 StringRef Op, int Low, int High);
211 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
212 return parsePKHImm(O, "lsl", 0, 31);
214 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
215 return parsePKHImm(O, "asr", 1, 32);
217 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
218 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
219 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
220 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
221 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
222 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
223 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
224 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
225 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
228 // Asm Match Converter Methods
229 void cvtThumbMultiply(MCInst &Inst,
230 const SmallVectorImpl<MCParsedAsmOperand*> &);
231 void cvtThumbBranches(MCInst &Inst,
232 const SmallVectorImpl<MCParsedAsmOperand*> &);
234 bool validateInstruction(MCInst &Inst,
235 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
236 bool processInstruction(MCInst &Inst,
237 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
238 bool shouldOmitCCOutOperand(StringRef Mnemonic,
239 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
240 bool shouldOmitPredicateOperand(StringRef Mnemonic,
241 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
243 enum ARMMatchResultTy {
244 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
245 Match_RequiresNotITBlock,
247 Match_RequiresThumb2,
248 #define GET_OPERAND_DIAGNOSTIC_TYPES
249 #include "ARMGenAsmMatcher.inc"
253 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
254 const MCInstrInfo &MII)
255 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
256 MCAsmParserExtension::Initialize(_Parser);
258 // Cache the MCRegisterInfo.
259 MRI = getContext().getRegisterInfo();
261 // Initialize the set of available features.
262 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
264 // Not in an ITBlock to start with.
265 ITState.CurPosition = ~0U;
268 // Implementation of the MCTargetAsmParser interface:
269 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
270 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
272 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
273 bool ParseDirective(AsmToken DirectiveID);
275 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
276 unsigned checkTargetMatchPredicate(MCInst &Inst);
278 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
279 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
280 MCStreamer &Out, unsigned &ErrorInfo,
281 bool MatchingInlineAsm);
283 } // end anonymous namespace
287 /// ARMOperand - Instances of this class represent a parsed ARM machine
289 class ARMOperand : public MCParsedAsmOperand {
299 k_InstSyncBarrierOpt,
310 k_VectorListAllLanes,
316 k_BitfieldDescriptor,
320 SMLoc StartLoc, EndLoc;
321 SmallVector<unsigned, 8> Registers;
324 ARMCC::CondCodes Val;
331 struct CoprocOptionOp {
344 ARM_ISB::InstSyncBOpt Val;
348 ARM_PROC::IFlags Val;
364 // A vector register list is a sequential list of 1 to 4 registers.
365 struct VectorListOp {
372 struct VectorIndexOp {
380 /// Combined record for all forms of ARM address expressions.
383 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
385 const MCConstantExpr *OffsetImm; // Offset immediate value
386 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
387 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
388 unsigned ShiftImm; // shift for OffsetReg.
389 unsigned Alignment; // 0 = no alignment specified
390 // n = alignment in bytes (2, 4, 8, 16, or 32)
391 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
394 struct PostIdxRegOp {
397 ARM_AM::ShiftOpc ShiftTy;
401 struct ShifterImmOp {
406 struct RegShiftedRegOp {
407 ARM_AM::ShiftOpc ShiftTy;
413 struct RegShiftedImmOp {
414 ARM_AM::ShiftOpc ShiftTy;
431 struct CoprocOptionOp CoprocOption;
432 struct MBOptOp MBOpt;
433 struct ISBOptOp ISBOpt;
434 struct ITMaskOp ITMask;
435 struct IFlagsOp IFlags;
436 struct MMaskOp MMask;
439 struct VectorListOp VectorList;
440 struct VectorIndexOp VectorIndex;
442 struct MemoryOp Memory;
443 struct PostIdxRegOp PostIdxReg;
444 struct ShifterImmOp ShifterImm;
445 struct RegShiftedRegOp RegShiftedReg;
446 struct RegShiftedImmOp RegShiftedImm;
447 struct RotImmOp RotImm;
448 struct BitfieldOp Bitfield;
451 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
453 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
455 StartLoc = o.StartLoc;
472 case k_DPRRegisterList:
473 case k_SPRRegisterList:
474 Registers = o.Registers;
477 case k_VectorListAllLanes:
478 case k_VectorListIndexed:
479 VectorList = o.VectorList;
486 CoprocOption = o.CoprocOption;
491 case k_MemBarrierOpt:
494 case k_InstSyncBarrierOpt:
499 case k_PostIndexRegister:
500 PostIdxReg = o.PostIdxReg;
508 case k_ShifterImmediate:
509 ShifterImm = o.ShifterImm;
511 case k_ShiftedRegister:
512 RegShiftedReg = o.RegShiftedReg;
514 case k_ShiftedImmediate:
515 RegShiftedImm = o.RegShiftedImm;
517 case k_RotateImmediate:
520 case k_BitfieldDescriptor:
521 Bitfield = o.Bitfield;
524 VectorIndex = o.VectorIndex;
529 /// getStartLoc - Get the location of the first token of this operand.
530 SMLoc getStartLoc() const { return StartLoc; }
531 /// getEndLoc - Get the location of the last token of this operand.
532 SMLoc getEndLoc() const { return EndLoc; }
533 /// getLocRange - Get the range between the first and last token of this
535 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
537 ARMCC::CondCodes getCondCode() const {
538 assert(Kind == k_CondCode && "Invalid access!");
542 unsigned getCoproc() const {
543 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
547 StringRef getToken() const {
548 assert(Kind == k_Token && "Invalid access!");
549 return StringRef(Tok.Data, Tok.Length);
552 unsigned getReg() const {
553 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
557 const SmallVectorImpl<unsigned> &getRegList() const {
558 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
559 Kind == k_SPRRegisterList) && "Invalid access!");
563 const MCExpr *getImm() const {
564 assert(isImm() && "Invalid access!");
568 unsigned getVectorIndex() const {
569 assert(Kind == k_VectorIndex && "Invalid access!");
570 return VectorIndex.Val;
573 ARM_MB::MemBOpt getMemBarrierOpt() const {
574 assert(Kind == k_MemBarrierOpt && "Invalid access!");
578 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
579 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
583 ARM_PROC::IFlags getProcIFlags() const {
584 assert(Kind == k_ProcIFlags && "Invalid access!");
588 unsigned getMSRMask() const {
589 assert(Kind == k_MSRMask && "Invalid access!");
593 bool isCoprocNum() const { return Kind == k_CoprocNum; }
594 bool isCoprocReg() const { return Kind == k_CoprocReg; }
595 bool isCoprocOption() const { return Kind == k_CoprocOption; }
596 bool isCondCode() const { return Kind == k_CondCode; }
597 bool isCCOut() const { return Kind == k_CCOut; }
598 bool isITMask() const { return Kind == k_ITCondMask; }
599 bool isITCondCode() const { return Kind == k_CondCode; }
600 bool isImm() const { return Kind == k_Immediate; }
601 // checks whether this operand is an unsigned offset which fits is a field
602 // of specified width and scaled by a specific number of bits
603 template<unsigned width, unsigned scale>
604 bool isUnsignedOffset() const {
605 if (!isImm()) return false;
606 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
607 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
608 int64_t Val = CE->getValue();
609 int64_t Align = 1LL << scale;
610 int64_t Max = Align * ((1LL << width) - 1);
611 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
615 // checks whether this operand is an signed offset which fits is a field
616 // of specified width and scaled by a specific number of bits
617 template<unsigned width, unsigned scale>
618 bool isSignedOffset() const {
619 if (!isImm()) return false;
620 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
621 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
622 int64_t Val = CE->getValue();
623 int64_t Align = 1LL << scale;
624 int64_t Max = Align * ((1LL << (width-1)) - 1);
625 int64_t Min = -Align * (1LL << (width-1));
626 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
631 // checks whether this operand is a memory operand computed as an offset
632 // applied to PC. the offset may have 8 bits of magnitude and is represented
633 // with two bits of shift. textually it may be either [pc, #imm], #imm or
634 // relocable expression...
635 bool isThumbMemPC() const {
638 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
639 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
640 if (!CE) return false;
641 Val = CE->getValue();
644 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
645 if(Memory.BaseRegNum != ARM::PC) return false;
646 Val = Memory.OffsetImm->getValue();
649 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
651 bool isFPImm() const {
652 if (!isImm()) return false;
653 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
654 if (!CE) return false;
655 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
658 bool isFBits16() const {
659 if (!isImm()) return false;
660 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
661 if (!CE) return false;
662 int64_t Value = CE->getValue();
663 return Value >= 0 && Value <= 16;
665 bool isFBits32() const {
666 if (!isImm()) return false;
667 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
668 if (!CE) return false;
669 int64_t Value = CE->getValue();
670 return Value >= 1 && Value <= 32;
672 bool isImm8s4() const {
673 if (!isImm()) return false;
674 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
675 if (!CE) return false;
676 int64_t Value = CE->getValue();
677 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
679 bool isImm0_1020s4() const {
680 if (!isImm()) return false;
681 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
682 if (!CE) return false;
683 int64_t Value = CE->getValue();
684 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
686 bool isImm0_508s4() const {
687 if (!isImm()) return false;
688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
689 if (!CE) return false;
690 int64_t Value = CE->getValue();
691 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
693 bool isImm0_508s4Neg() const {
694 if (!isImm()) return false;
695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
696 if (!CE) return false;
697 int64_t Value = -CE->getValue();
698 // explicitly exclude zero. we want that to use the normal 0_508 version.
699 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
701 bool isImm0_255() const {
702 if (!isImm()) return false;
703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
704 if (!CE) return false;
705 int64_t Value = CE->getValue();
706 return Value >= 0 && Value < 256;
708 bool isImm0_4095() const {
709 if (!isImm()) return false;
710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
711 if (!CE) return false;
712 int64_t Value = CE->getValue();
713 return Value >= 0 && Value < 4096;
715 bool isImm0_4095Neg() const {
716 if (!isImm()) return false;
717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
718 if (!CE) return false;
719 int64_t Value = -CE->getValue();
720 return Value > 0 && Value < 4096;
722 bool isImm0_1() const {
723 if (!isImm()) return false;
724 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
725 if (!CE) return false;
726 int64_t Value = CE->getValue();
727 return Value >= 0 && Value < 2;
729 bool isImm0_3() const {
730 if (!isImm()) return false;
731 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
732 if (!CE) return false;
733 int64_t Value = CE->getValue();
734 return Value >= 0 && Value < 4;
736 bool isImm0_7() const {
737 if (!isImm()) return false;
738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
739 if (!CE) return false;
740 int64_t Value = CE->getValue();
741 return Value >= 0 && Value < 8;
743 bool isImm0_15() const {
744 if (!isImm()) return false;
745 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
746 if (!CE) return false;
747 int64_t Value = CE->getValue();
748 return Value >= 0 && Value < 16;
750 bool isImm0_31() const {
751 if (!isImm()) return false;
752 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
753 if (!CE) return false;
754 int64_t Value = CE->getValue();
755 return Value >= 0 && Value < 32;
757 bool isImm0_63() const {
758 if (!isImm()) return false;
759 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
760 if (!CE) return false;
761 int64_t Value = CE->getValue();
762 return Value >= 0 && Value < 64;
764 bool isImm8() const {
765 if (!isImm()) return false;
766 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
767 if (!CE) return false;
768 int64_t Value = CE->getValue();
771 bool isImm16() const {
772 if (!isImm()) return false;
773 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
774 if (!CE) return false;
775 int64_t Value = CE->getValue();
778 bool isImm32() const {
779 if (!isImm()) return false;
780 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
781 if (!CE) return false;
782 int64_t Value = CE->getValue();
785 bool isShrImm8() const {
786 if (!isImm()) return false;
787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
788 if (!CE) return false;
789 int64_t Value = CE->getValue();
790 return Value > 0 && Value <= 8;
792 bool isShrImm16() const {
793 if (!isImm()) return false;
794 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
795 if (!CE) return false;
796 int64_t Value = CE->getValue();
797 return Value > 0 && Value <= 16;
799 bool isShrImm32() const {
800 if (!isImm()) return false;
801 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
802 if (!CE) return false;
803 int64_t Value = CE->getValue();
804 return Value > 0 && Value <= 32;
806 bool isShrImm64() const {
807 if (!isImm()) return false;
808 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
809 if (!CE) return false;
810 int64_t Value = CE->getValue();
811 return Value > 0 && Value <= 64;
813 bool isImm1_7() const {
814 if (!isImm()) return false;
815 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
816 if (!CE) return false;
817 int64_t Value = CE->getValue();
818 return Value > 0 && Value < 8;
820 bool isImm1_15() const {
821 if (!isImm()) return false;
822 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
823 if (!CE) return false;
824 int64_t Value = CE->getValue();
825 return Value > 0 && Value < 16;
827 bool isImm1_31() const {
828 if (!isImm()) return false;
829 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
830 if (!CE) return false;
831 int64_t Value = CE->getValue();
832 return Value > 0 && Value < 32;
834 bool isImm1_16() const {
835 if (!isImm()) return false;
836 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
837 if (!CE) return false;
838 int64_t Value = CE->getValue();
839 return Value > 0 && Value < 17;
841 bool isImm1_32() const {
842 if (!isImm()) return false;
843 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
844 if (!CE) return false;
845 int64_t Value = CE->getValue();
846 return Value > 0 && Value < 33;
848 bool isImm0_32() const {
849 if (!isImm()) return false;
850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
851 if (!CE) return false;
852 int64_t Value = CE->getValue();
853 return Value >= 0 && Value < 33;
855 bool isImm0_65535() const {
856 if (!isImm()) return false;
857 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
858 if (!CE) return false;
859 int64_t Value = CE->getValue();
860 return Value >= 0 && Value < 65536;
862 bool isImm256_65535Expr() const {
863 if (!isImm()) return false;
864 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
865 // If it's not a constant expression, it'll generate a fixup and be
867 if (!CE) return true;
868 int64_t Value = CE->getValue();
869 return Value >= 256 && Value < 65536;
871 bool isImm0_65535Expr() const {
872 if (!isImm()) return false;
873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
874 // If it's not a constant expression, it'll generate a fixup and be
876 if (!CE) return true;
877 int64_t Value = CE->getValue();
878 return Value >= 0 && Value < 65536;
880 bool isImm24bit() const {
881 if (!isImm()) return false;
882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
883 if (!CE) return false;
884 int64_t Value = CE->getValue();
885 return Value >= 0 && Value <= 0xffffff;
887 bool isImmThumbSR() const {
888 if (!isImm()) return false;
889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
890 if (!CE) return false;
891 int64_t Value = CE->getValue();
892 return Value > 0 && Value < 33;
894 bool isPKHLSLImm() const {
895 if (!isImm()) return false;
896 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
897 if (!CE) return false;
898 int64_t Value = CE->getValue();
899 return Value >= 0 && Value < 32;
901 bool isPKHASRImm() const {
902 if (!isImm()) return false;
903 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
904 if (!CE) return false;
905 int64_t Value = CE->getValue();
906 return Value > 0 && Value <= 32;
908 bool isAdrLabel() const {
909 // If we have an immediate that's not a constant, treat it as a label
910 // reference needing a fixup. If it is a constant, but it can't fit
911 // into shift immediate encoding, we reject it.
912 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
913 else return (isARMSOImm() || isARMSOImmNeg());
915 bool isARMSOImm() const {
916 if (!isImm()) return false;
917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
918 if (!CE) return false;
919 int64_t Value = CE->getValue();
920 return ARM_AM::getSOImmVal(Value) != -1;
922 bool isARMSOImmNot() const {
923 if (!isImm()) return false;
924 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
925 if (!CE) return false;
926 int64_t Value = CE->getValue();
927 return ARM_AM::getSOImmVal(~Value) != -1;
929 bool isARMSOImmNeg() const {
930 if (!isImm()) return false;
931 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
932 if (!CE) return false;
933 int64_t Value = CE->getValue();
934 // Only use this when not representable as a plain so_imm.
935 return ARM_AM::getSOImmVal(Value) == -1 &&
936 ARM_AM::getSOImmVal(-Value) != -1;
938 bool isT2SOImm() const {
939 if (!isImm()) return false;
940 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
941 if (!CE) return false;
942 int64_t Value = CE->getValue();
943 return ARM_AM::getT2SOImmVal(Value) != -1;
945 bool isT2SOImmNot() const {
946 if (!isImm()) return false;
947 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
948 if (!CE) return false;
949 int64_t Value = CE->getValue();
950 return ARM_AM::getT2SOImmVal(Value) == -1 &&
951 ARM_AM::getT2SOImmVal(~Value) != -1;
953 bool isT2SOImmNeg() const {
954 if (!isImm()) return false;
955 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
956 if (!CE) return false;
957 int64_t Value = CE->getValue();
958 // Only use this when not representable as a plain so_imm.
959 return ARM_AM::getT2SOImmVal(Value) == -1 &&
960 ARM_AM::getT2SOImmVal(-Value) != -1;
962 bool isSetEndImm() const {
963 if (!isImm()) return false;
964 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
965 if (!CE) return false;
966 int64_t Value = CE->getValue();
967 return Value == 1 || Value == 0;
969 bool isReg() const { return Kind == k_Register; }
970 bool isRegList() const { return Kind == k_RegisterList; }
971 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
972 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
973 bool isToken() const { return Kind == k_Token; }
974 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
975 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
976 bool isMem() const { return Kind == k_Memory; }
977 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
978 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
979 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
980 bool isRotImm() const { return Kind == k_RotateImmediate; }
981 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
982 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
983 bool isPostIdxReg() const {
984 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
986 bool isMemNoOffset(bool alignOK = false) const {
989 // No offset of any kind.
990 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
991 (alignOK || Memory.Alignment == 0);
993 bool isMemPCRelImm12() const {
994 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
996 // Base register must be PC.
997 if (Memory.BaseRegNum != ARM::PC)
999 // Immediate offset in range [-4095, 4095].
1000 if (!Memory.OffsetImm) return true;
1001 int64_t Val = Memory.OffsetImm->getValue();
1002 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1004 bool isAlignedMemory() const {
1005 return isMemNoOffset(true);
1007 bool isAddrMode2() const {
1008 if (!isMem() || Memory.Alignment != 0) return false;
1009 // Check for register offset.
1010 if (Memory.OffsetRegNum) return true;
1011 // Immediate offset in range [-4095, 4095].
1012 if (!Memory.OffsetImm) return true;
1013 int64_t Val = Memory.OffsetImm->getValue();
1014 return Val > -4096 && Val < 4096;
1016 bool isAM2OffsetImm() const {
1017 if (!isImm()) return false;
1018 // Immediate offset in range [-4095, 4095].
1019 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1020 if (!CE) return false;
1021 int64_t Val = CE->getValue();
1022 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1024 bool isAddrMode3() const {
1025 // If we have an immediate that's not a constant, treat it as a label
1026 // reference needing a fixup. If it is a constant, it's something else
1027 // and we reject it.
1028 if (isImm() && !isa<MCConstantExpr>(getImm()))
1030 if (!isMem() || Memory.Alignment != 0) return false;
1031 // No shifts are legal for AM3.
1032 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1033 // Check for register offset.
1034 if (Memory.OffsetRegNum) return true;
1035 // Immediate offset in range [-255, 255].
1036 if (!Memory.OffsetImm) return true;
1037 int64_t Val = Memory.OffsetImm->getValue();
1038 // The #-0 offset is encoded as INT32_MIN, and we have to check
1040 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1042 bool isAM3Offset() const {
1043 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1045 if (Kind == k_PostIndexRegister)
1046 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1047 // Immediate offset in range [-255, 255].
1048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1049 if (!CE) return false;
1050 int64_t Val = CE->getValue();
1051 // Special case, #-0 is INT32_MIN.
1052 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1054 bool isAddrMode5() const {
1055 // If we have an immediate that's not a constant, treat it as a label
1056 // reference needing a fixup. If it is a constant, it's something else
1057 // and we reject it.
1058 if (isImm() && !isa<MCConstantExpr>(getImm()))
1060 if (!isMem() || Memory.Alignment != 0) return false;
1061 // Check for register offset.
1062 if (Memory.OffsetRegNum) return false;
1063 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1064 if (!Memory.OffsetImm) return true;
1065 int64_t Val = Memory.OffsetImm->getValue();
1066 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1069 bool isMemTBB() const {
1070 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1071 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1075 bool isMemTBH() const {
1076 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1077 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1078 Memory.Alignment != 0 )
1082 bool isMemRegOffset() const {
1083 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1087 bool isT2MemRegOffset() const {
1088 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1089 Memory.Alignment != 0)
1091 // Only lsl #{0, 1, 2, 3} allowed.
1092 if (Memory.ShiftType == ARM_AM::no_shift)
1094 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1098 bool isMemThumbRR() const {
1099 // Thumb reg+reg addressing is simple. Just two registers, a base and
1100 // an offset. No shifts, negations or any other complicating factors.
1101 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1102 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1104 return isARMLowRegister(Memory.BaseRegNum) &&
1105 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1107 bool isMemThumbRIs4() const {
1108 if (!isMem() || Memory.OffsetRegNum != 0 ||
1109 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1111 // Immediate offset, multiple of 4 in range [0, 124].
1112 if (!Memory.OffsetImm) return true;
1113 int64_t Val = Memory.OffsetImm->getValue();
1114 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1116 bool isMemThumbRIs2() const {
1117 if (!isMem() || Memory.OffsetRegNum != 0 ||
1118 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1120 // Immediate offset, multiple of 4 in range [0, 62].
1121 if (!Memory.OffsetImm) return true;
1122 int64_t Val = Memory.OffsetImm->getValue();
1123 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1125 bool isMemThumbRIs1() const {
1126 if (!isMem() || Memory.OffsetRegNum != 0 ||
1127 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1129 // Immediate offset in range [0, 31].
1130 if (!Memory.OffsetImm) return true;
1131 int64_t Val = Memory.OffsetImm->getValue();
1132 return Val >= 0 && Val <= 31;
1134 bool isMemThumbSPI() const {
1135 if (!isMem() || Memory.OffsetRegNum != 0 ||
1136 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1138 // Immediate offset, multiple of 4 in range [0, 1020].
1139 if (!Memory.OffsetImm) return true;
1140 int64_t Val = Memory.OffsetImm->getValue();
1141 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1143 bool isMemImm8s4Offset() const {
1144 // If we have an immediate that's not a constant, treat it as a label
1145 // reference needing a fixup. If it is a constant, it's something else
1146 // and we reject it.
1147 if (isImm() && !isa<MCConstantExpr>(getImm()))
1149 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1151 // Immediate offset a multiple of 4 in range [-1020, 1020].
1152 if (!Memory.OffsetImm) return true;
1153 int64_t Val = Memory.OffsetImm->getValue();
1154 // Special case, #-0 is INT32_MIN.
1155 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1157 bool isMemImm0_1020s4Offset() const {
1158 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1160 // Immediate offset a multiple of 4 in range [0, 1020].
1161 if (!Memory.OffsetImm) return true;
1162 int64_t Val = Memory.OffsetImm->getValue();
1163 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1165 bool isMemImm8Offset() const {
1166 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1168 // Base reg of PC isn't allowed for these encodings.
1169 if (Memory.BaseRegNum == ARM::PC) return false;
1170 // Immediate offset in range [-255, 255].
1171 if (!Memory.OffsetImm) return true;
1172 int64_t Val = Memory.OffsetImm->getValue();
1173 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1175 bool isMemPosImm8Offset() const {
1176 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1178 // Immediate offset in range [0, 255].
1179 if (!Memory.OffsetImm) return true;
1180 int64_t Val = Memory.OffsetImm->getValue();
1181 return Val >= 0 && Val < 256;
1183 bool isMemNegImm8Offset() const {
1184 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1186 // Base reg of PC isn't allowed for these encodings.
1187 if (Memory.BaseRegNum == ARM::PC) return false;
1188 // Immediate offset in range [-255, -1].
1189 if (!Memory.OffsetImm) return false;
1190 int64_t Val = Memory.OffsetImm->getValue();
1191 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1193 bool isMemUImm12Offset() const {
1194 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1196 // Immediate offset in range [0, 4095].
1197 if (!Memory.OffsetImm) return true;
1198 int64_t Val = Memory.OffsetImm->getValue();
1199 return (Val >= 0 && Val < 4096);
1201 bool isMemImm12Offset() const {
1202 // If we have an immediate that's not a constant, treat it as a label
1203 // reference needing a fixup. If it is a constant, it's something else
1204 // and we reject it.
1205 if (isImm() && !isa<MCConstantExpr>(getImm()))
1208 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1210 // Immediate offset in range [-4095, 4095].
1211 if (!Memory.OffsetImm) return true;
1212 int64_t Val = Memory.OffsetImm->getValue();
1213 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1215 bool isPostIdxImm8() const {
1216 if (!isImm()) return false;
1217 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1218 if (!CE) return false;
1219 int64_t Val = CE->getValue();
1220 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1222 bool isPostIdxImm8s4() const {
1223 if (!isImm()) return false;
1224 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1225 if (!CE) return false;
1226 int64_t Val = CE->getValue();
1227 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1231 bool isMSRMask() const { return Kind == k_MSRMask; }
1232 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1235 bool isSingleSpacedVectorList() const {
1236 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1238 bool isDoubleSpacedVectorList() const {
1239 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1241 bool isVecListOneD() const {
1242 if (!isSingleSpacedVectorList()) return false;
1243 return VectorList.Count == 1;
1246 bool isVecListDPair() const {
1247 if (!isSingleSpacedVectorList()) return false;
1248 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1249 .contains(VectorList.RegNum));
1252 bool isVecListThreeD() const {
1253 if (!isSingleSpacedVectorList()) return false;
1254 return VectorList.Count == 3;
1257 bool isVecListFourD() const {
1258 if (!isSingleSpacedVectorList()) return false;
1259 return VectorList.Count == 4;
1262 bool isVecListDPairSpaced() const {
1263 if (isSingleSpacedVectorList()) return false;
1264 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1265 .contains(VectorList.RegNum));
1268 bool isVecListThreeQ() const {
1269 if (!isDoubleSpacedVectorList()) return false;
1270 return VectorList.Count == 3;
1273 bool isVecListFourQ() const {
1274 if (!isDoubleSpacedVectorList()) return false;
1275 return VectorList.Count == 4;
1278 bool isSingleSpacedVectorAllLanes() const {
1279 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1281 bool isDoubleSpacedVectorAllLanes() const {
1282 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1284 bool isVecListOneDAllLanes() const {
1285 if (!isSingleSpacedVectorAllLanes()) return false;
1286 return VectorList.Count == 1;
1289 bool isVecListDPairAllLanes() const {
1290 if (!isSingleSpacedVectorAllLanes()) return false;
1291 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1292 .contains(VectorList.RegNum));
1295 bool isVecListDPairSpacedAllLanes() const {
1296 if (!isDoubleSpacedVectorAllLanes()) return false;
1297 return VectorList.Count == 2;
1300 bool isVecListThreeDAllLanes() const {
1301 if (!isSingleSpacedVectorAllLanes()) return false;
1302 return VectorList.Count == 3;
1305 bool isVecListThreeQAllLanes() const {
1306 if (!isDoubleSpacedVectorAllLanes()) return false;
1307 return VectorList.Count == 3;
1310 bool isVecListFourDAllLanes() const {
1311 if (!isSingleSpacedVectorAllLanes()) return false;
1312 return VectorList.Count == 4;
1315 bool isVecListFourQAllLanes() const {
1316 if (!isDoubleSpacedVectorAllLanes()) return false;
1317 return VectorList.Count == 4;
1320 bool isSingleSpacedVectorIndexed() const {
1321 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1323 bool isDoubleSpacedVectorIndexed() const {
1324 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1326 bool isVecListOneDByteIndexed() const {
1327 if (!isSingleSpacedVectorIndexed()) return false;
1328 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1331 bool isVecListOneDHWordIndexed() const {
1332 if (!isSingleSpacedVectorIndexed()) return false;
1333 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1336 bool isVecListOneDWordIndexed() const {
1337 if (!isSingleSpacedVectorIndexed()) return false;
1338 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1341 bool isVecListTwoDByteIndexed() const {
1342 if (!isSingleSpacedVectorIndexed()) return false;
1343 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1346 bool isVecListTwoDHWordIndexed() const {
1347 if (!isSingleSpacedVectorIndexed()) return false;
1348 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1351 bool isVecListTwoQWordIndexed() const {
1352 if (!isDoubleSpacedVectorIndexed()) return false;
1353 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1356 bool isVecListTwoQHWordIndexed() const {
1357 if (!isDoubleSpacedVectorIndexed()) return false;
1358 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1361 bool isVecListTwoDWordIndexed() const {
1362 if (!isSingleSpacedVectorIndexed()) return false;
1363 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1366 bool isVecListThreeDByteIndexed() const {
1367 if (!isSingleSpacedVectorIndexed()) return false;
1368 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1371 bool isVecListThreeDHWordIndexed() const {
1372 if (!isSingleSpacedVectorIndexed()) return false;
1373 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1376 bool isVecListThreeQWordIndexed() const {
1377 if (!isDoubleSpacedVectorIndexed()) return false;
1378 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1381 bool isVecListThreeQHWordIndexed() const {
1382 if (!isDoubleSpacedVectorIndexed()) return false;
1383 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1386 bool isVecListThreeDWordIndexed() const {
1387 if (!isSingleSpacedVectorIndexed()) return false;
1388 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1391 bool isVecListFourDByteIndexed() const {
1392 if (!isSingleSpacedVectorIndexed()) return false;
1393 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1396 bool isVecListFourDHWordIndexed() const {
1397 if (!isSingleSpacedVectorIndexed()) return false;
1398 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1401 bool isVecListFourQWordIndexed() const {
1402 if (!isDoubleSpacedVectorIndexed()) return false;
1403 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1406 bool isVecListFourQHWordIndexed() const {
1407 if (!isDoubleSpacedVectorIndexed()) return false;
1408 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1411 bool isVecListFourDWordIndexed() const {
1412 if (!isSingleSpacedVectorIndexed()) return false;
1413 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1416 bool isVectorIndex8() const {
1417 if (Kind != k_VectorIndex) return false;
1418 return VectorIndex.Val < 8;
1420 bool isVectorIndex16() const {
1421 if (Kind != k_VectorIndex) return false;
1422 return VectorIndex.Val < 4;
1424 bool isVectorIndex32() const {
1425 if (Kind != k_VectorIndex) return false;
1426 return VectorIndex.Val < 2;
1429 bool isNEONi8splat() const {
1430 if (!isImm()) return false;
1431 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1432 // Must be a constant.
1433 if (!CE) return false;
1434 int64_t Value = CE->getValue();
1435 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1437 return Value >= 0 && Value < 256;
1440 bool isNEONi16splat() const {
1441 if (!isImm()) return false;
1442 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1443 // Must be a constant.
1444 if (!CE) return false;
1445 int64_t Value = CE->getValue();
1446 // i16 value in the range [0,255] or [0x0100, 0xff00]
1447 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1450 bool isNEONi32splat() const {
1451 if (!isImm()) return false;
1452 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1453 // Must be a constant.
1454 if (!CE) return false;
1455 int64_t Value = CE->getValue();
1456 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1457 return (Value >= 0 && Value < 256) ||
1458 (Value >= 0x0100 && Value <= 0xff00) ||
1459 (Value >= 0x010000 && Value <= 0xff0000) ||
1460 (Value >= 0x01000000 && Value <= 0xff000000);
1463 bool isNEONi32vmov() const {
1464 if (!isImm()) return false;
1465 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1466 // Must be a constant.
1467 if (!CE) return false;
1468 int64_t Value = CE->getValue();
1469 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1470 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1471 return (Value >= 0 && Value < 256) ||
1472 (Value >= 0x0100 && Value <= 0xff00) ||
1473 (Value >= 0x010000 && Value <= 0xff0000) ||
1474 (Value >= 0x01000000 && Value <= 0xff000000) ||
1475 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1476 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1478 bool isNEONi32vmovNeg() const {
1479 if (!isImm()) return false;
1480 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1481 // Must be a constant.
1482 if (!CE) return false;
1483 int64_t Value = ~CE->getValue();
1484 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1485 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1486 return (Value >= 0 && Value < 256) ||
1487 (Value >= 0x0100 && Value <= 0xff00) ||
1488 (Value >= 0x010000 && Value <= 0xff0000) ||
1489 (Value >= 0x01000000 && Value <= 0xff000000) ||
1490 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1491 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1494 bool isNEONi64splat() const {
1495 if (!isImm()) return false;
1496 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1497 // Must be a constant.
1498 if (!CE) return false;
1499 uint64_t Value = CE->getValue();
1500 // i64 value with each byte being either 0 or 0xff.
1501 for (unsigned i = 0; i < 8; ++i)
1502 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1506 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1507 // Add as immediates when possible. Null MCExpr = 0.
1509 Inst.addOperand(MCOperand::CreateImm(0));
1510 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1511 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1513 Inst.addOperand(MCOperand::CreateExpr(Expr));
1516 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1517 assert(N == 2 && "Invalid number of operands!");
1518 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1519 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1520 Inst.addOperand(MCOperand::CreateReg(RegNum));
1523 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1524 assert(N == 1 && "Invalid number of operands!");
1525 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1528 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1529 assert(N == 1 && "Invalid number of operands!");
1530 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1533 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1534 assert(N == 1 && "Invalid number of operands!");
1535 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1538 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1539 assert(N == 1 && "Invalid number of operands!");
1540 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1543 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1544 assert(N == 1 && "Invalid number of operands!");
1545 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1548 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1549 assert(N == 1 && "Invalid number of operands!");
1550 Inst.addOperand(MCOperand::CreateReg(getReg()));
1553 void addRegOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 Inst.addOperand(MCOperand::CreateReg(getReg()));
1558 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1559 assert(N == 3 && "Invalid number of operands!");
1560 assert(isRegShiftedReg() &&
1561 "addRegShiftedRegOperands() on non RegShiftedReg!");
1562 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1563 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1564 Inst.addOperand(MCOperand::CreateImm(
1565 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1568 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1569 assert(N == 2 && "Invalid number of operands!");
1570 assert(isRegShiftedImm() &&
1571 "addRegShiftedImmOperands() on non RegShiftedImm!");
1572 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1573 // Shift of #32 is encoded as 0 where permitted
1574 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1575 Inst.addOperand(MCOperand::CreateImm(
1576 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1579 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1580 assert(N == 1 && "Invalid number of operands!");
1581 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1585 void addRegListOperands(MCInst &Inst, unsigned N) const {
1586 assert(N == 1 && "Invalid number of operands!");
1587 const SmallVectorImpl<unsigned> &RegList = getRegList();
1588 for (SmallVectorImpl<unsigned>::const_iterator
1589 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1590 Inst.addOperand(MCOperand::CreateReg(*I));
1593 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1594 addRegListOperands(Inst, N);
1597 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1598 addRegListOperands(Inst, N);
1601 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1602 assert(N == 1 && "Invalid number of operands!");
1603 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1604 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1607 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1608 assert(N == 1 && "Invalid number of operands!");
1609 // Munge the lsb/width into a bitfield mask.
1610 unsigned lsb = Bitfield.LSB;
1611 unsigned width = Bitfield.Width;
1612 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1613 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1614 (32 - (lsb + width)));
1615 Inst.addOperand(MCOperand::CreateImm(Mask));
1618 void addImmOperands(MCInst &Inst, unsigned N) const {
1619 assert(N == 1 && "Invalid number of operands!");
1620 addExpr(Inst, getImm());
1623 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1624 assert(N == 1 && "Invalid number of operands!");
1625 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1626 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1629 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1630 assert(N == 1 && "Invalid number of operands!");
1631 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1632 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1635 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
1637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1638 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1639 Inst.addOperand(MCOperand::CreateImm(Val));
1642 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1643 assert(N == 1 && "Invalid number of operands!");
1644 // FIXME: We really want to scale the value here, but the LDRD/STRD
1645 // instruction don't encode operands that way yet.
1646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1647 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1650 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 // The immediate is scaled by four in the encoding and is stored
1653 // in the MCInst as such. Lop off the low two bits here.
1654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1655 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1658 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1659 assert(N == 1 && "Invalid number of operands!");
1660 // The immediate is scaled by four in the encoding and is stored
1661 // in the MCInst as such. Lop off the low two bits here.
1662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1666 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1667 assert(N == 1 && "Invalid number of operands!");
1668 // The immediate is scaled by four in the encoding and is stored
1669 // in the MCInst as such. Lop off the low two bits here.
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1674 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1675 assert(N == 1 && "Invalid number of operands!");
1676 // The constant encodes as the immediate-1, and we store in the instruction
1677 // the bits as encoded, so subtract off one here.
1678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1679 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1682 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1683 assert(N == 1 && "Invalid number of operands!");
1684 // The constant encodes as the immediate-1, and we store in the instruction
1685 // the bits as encoded, so subtract off one here.
1686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1687 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1690 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1691 assert(N == 1 && "Invalid number of operands!");
1692 // The constant encodes as the immediate, except for 32, which encodes as
1694 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1695 unsigned Imm = CE->getValue();
1696 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1699 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1700 assert(N == 1 && "Invalid number of operands!");
1701 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1702 // the instruction as well.
1703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1704 int Val = CE->getValue();
1705 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1708 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1709 assert(N == 1 && "Invalid number of operands!");
1710 // The operand is actually a t2_so_imm, but we have its bitwise
1711 // negation in the assembly source, so twiddle it here.
1712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1713 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1716 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1717 assert(N == 1 && "Invalid number of operands!");
1718 // The operand is actually a t2_so_imm, but we have its
1719 // negation in the assembly source, so twiddle it here.
1720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1721 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1724 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1725 assert(N == 1 && "Invalid number of operands!");
1726 // The operand is actually an imm0_4095, but we have its
1727 // negation in the assembly source, so twiddle it here.
1728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1729 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1732 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1733 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1734 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1738 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1739 assert(SR && "Unknown value type!");
1740 Inst.addOperand(MCOperand::CreateExpr(SR));
1743 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1744 assert(N == 1 && "Invalid number of operands!");
1746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1748 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1752 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1753 assert(SR && "Unknown value type!");
1754 Inst.addOperand(MCOperand::CreateExpr(SR));
1758 assert(isMem() && "Unknown value type!");
1759 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1760 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1763 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1764 assert(N == 1 && "Invalid number of operands!");
1765 // The operand is actually a so_imm, but we have its bitwise
1766 // negation in the assembly source, so twiddle it here.
1767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1768 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1771 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1772 assert(N == 1 && "Invalid number of operands!");
1773 // The operand is actually a so_imm, but we have its
1774 // negation in the assembly source, so twiddle it here.
1775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1776 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1779 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1780 assert(N == 1 && "Invalid number of operands!");
1781 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1784 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1785 assert(N == 1 && "Invalid number of operands!");
1786 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1789 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1790 assert(N == 1 && "Invalid number of operands!");
1791 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1794 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1795 assert(N == 1 && "Invalid number of operands!");
1796 int32_t Imm = Memory.OffsetImm->getValue();
1797 Inst.addOperand(MCOperand::CreateImm(Imm));
1800 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1801 assert(N == 1 && "Invalid number of operands!");
1802 assert(isImm() && "Not an immediate!");
1804 // If we have an immediate that's not a constant, treat it as a label
1805 // reference needing a fixup.
1806 if (!isa<MCConstantExpr>(getImm())) {
1807 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1812 int Val = CE->getValue();
1813 Inst.addOperand(MCOperand::CreateImm(Val));
1816 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1817 assert(N == 2 && "Invalid number of operands!");
1818 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1819 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1822 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1823 assert(N == 3 && "Invalid number of operands!");
1824 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1825 if (!Memory.OffsetRegNum) {
1826 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1827 // Special case for #-0
1828 if (Val == INT32_MIN) Val = 0;
1829 if (Val < 0) Val = -Val;
1830 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1832 // For register offset, we encode the shift type and negation flag
1834 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1835 Memory.ShiftImm, Memory.ShiftType);
1837 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1838 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1839 Inst.addOperand(MCOperand::CreateImm(Val));
1842 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1843 assert(N == 2 && "Invalid number of operands!");
1844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1845 assert(CE && "non-constant AM2OffsetImm operand!");
1846 int32_t Val = CE->getValue();
1847 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1848 // Special case for #-0
1849 if (Val == INT32_MIN) Val = 0;
1850 if (Val < 0) Val = -Val;
1851 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1852 Inst.addOperand(MCOperand::CreateReg(0));
1853 Inst.addOperand(MCOperand::CreateImm(Val));
1856 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1857 assert(N == 3 && "Invalid number of operands!");
1858 // If we have an immediate that's not a constant, treat it as a label
1859 // reference needing a fixup. If it is a constant, it's something else
1860 // and we reject it.
1862 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1863 Inst.addOperand(MCOperand::CreateReg(0));
1864 Inst.addOperand(MCOperand::CreateImm(0));
1868 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1869 if (!Memory.OffsetRegNum) {
1870 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1871 // Special case for #-0
1872 if (Val == INT32_MIN) Val = 0;
1873 if (Val < 0) Val = -Val;
1874 Val = ARM_AM::getAM3Opc(AddSub, Val);
1876 // For register offset, we encode the shift type and negation flag
1878 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1880 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1881 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1882 Inst.addOperand(MCOperand::CreateImm(Val));
1885 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1886 assert(N == 2 && "Invalid number of operands!");
1887 if (Kind == k_PostIndexRegister) {
1889 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1890 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1891 Inst.addOperand(MCOperand::CreateImm(Val));
1896 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1897 int32_t Val = CE->getValue();
1898 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1899 // Special case for #-0
1900 if (Val == INT32_MIN) Val = 0;
1901 if (Val < 0) Val = -Val;
1902 Val = ARM_AM::getAM3Opc(AddSub, Val);
1903 Inst.addOperand(MCOperand::CreateReg(0));
1904 Inst.addOperand(MCOperand::CreateImm(Val));
1907 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1908 assert(N == 2 && "Invalid number of operands!");
1909 // If we have an immediate that's not a constant, treat it as a label
1910 // reference needing a fixup. If it is a constant, it's something else
1911 // and we reject it.
1913 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1914 Inst.addOperand(MCOperand::CreateImm(0));
1918 // The lower two bits are always zero and as such are not encoded.
1919 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1920 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1921 // Special case for #-0
1922 if (Val == INT32_MIN) Val = 0;
1923 if (Val < 0) Val = -Val;
1924 Val = ARM_AM::getAM5Opc(AddSub, Val);
1925 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1926 Inst.addOperand(MCOperand::CreateImm(Val));
1929 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1930 assert(N == 2 && "Invalid number of operands!");
1931 // If we have an immediate that's not a constant, treat it as a label
1932 // reference needing a fixup. If it is a constant, it's something else
1933 // and we reject it.
1935 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1936 Inst.addOperand(MCOperand::CreateImm(0));
1940 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1941 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1942 Inst.addOperand(MCOperand::CreateImm(Val));
1945 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1946 assert(N == 2 && "Invalid number of operands!");
1947 // The lower two bits are always zero and as such are not encoded.
1948 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1949 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1950 Inst.addOperand(MCOperand::CreateImm(Val));
1953 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1954 assert(N == 2 && "Invalid number of operands!");
1955 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1956 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1957 Inst.addOperand(MCOperand::CreateImm(Val));
1960 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1961 addMemImm8OffsetOperands(Inst, N);
1964 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1965 addMemImm8OffsetOperands(Inst, N);
1968 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1969 assert(N == 2 && "Invalid number of operands!");
1970 // If this is an immediate, it's a label reference.
1972 addExpr(Inst, getImm());
1973 Inst.addOperand(MCOperand::CreateImm(0));
1977 // Otherwise, it's a normal memory reg+offset.
1978 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1979 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1980 Inst.addOperand(MCOperand::CreateImm(Val));
1983 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1984 assert(N == 2 && "Invalid number of operands!");
1985 // If this is an immediate, it's a label reference.
1987 addExpr(Inst, getImm());
1988 Inst.addOperand(MCOperand::CreateImm(0));
1992 // Otherwise, it's a normal memory reg+offset.
1993 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1994 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1995 Inst.addOperand(MCOperand::CreateImm(Val));
1998 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1999 assert(N == 2 && "Invalid number of operands!");
2000 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2001 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2004 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2005 assert(N == 2 && "Invalid number of operands!");
2006 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2007 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2010 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2011 assert(N == 3 && "Invalid number of operands!");
2013 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2014 Memory.ShiftImm, Memory.ShiftType);
2015 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2016 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2017 Inst.addOperand(MCOperand::CreateImm(Val));
2020 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2021 assert(N == 3 && "Invalid number of operands!");
2022 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2023 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2024 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2027 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2028 assert(N == 2 && "Invalid number of operands!");
2029 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2030 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2033 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2034 assert(N == 2 && "Invalid number of operands!");
2035 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2036 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2037 Inst.addOperand(MCOperand::CreateImm(Val));
2040 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2041 assert(N == 2 && "Invalid number of operands!");
2042 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2043 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2044 Inst.addOperand(MCOperand::CreateImm(Val));
2047 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2048 assert(N == 2 && "Invalid number of operands!");
2049 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2050 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2051 Inst.addOperand(MCOperand::CreateImm(Val));
2054 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2055 assert(N == 2 && "Invalid number of operands!");
2056 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2057 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2058 Inst.addOperand(MCOperand::CreateImm(Val));
2061 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2062 assert(N == 1 && "Invalid number of operands!");
2063 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2064 assert(CE && "non-constant post-idx-imm8 operand!");
2065 int Imm = CE->getValue();
2066 bool isAdd = Imm >= 0;
2067 if (Imm == INT32_MIN) Imm = 0;
2068 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2069 Inst.addOperand(MCOperand::CreateImm(Imm));
2072 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2073 assert(N == 1 && "Invalid number of operands!");
2074 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2075 assert(CE && "non-constant post-idx-imm8s4 operand!");
2076 int Imm = CE->getValue();
2077 bool isAdd = Imm >= 0;
2078 if (Imm == INT32_MIN) Imm = 0;
2079 // Immediate is scaled by 4.
2080 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2081 Inst.addOperand(MCOperand::CreateImm(Imm));
2084 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2085 assert(N == 2 && "Invalid number of operands!");
2086 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2087 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2090 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2091 assert(N == 2 && "Invalid number of operands!");
2092 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2093 // The sign, shift type, and shift amount are encoded in a single operand
2094 // using the AM2 encoding helpers.
2095 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2096 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2097 PostIdxReg.ShiftTy);
2098 Inst.addOperand(MCOperand::CreateImm(Imm));
2101 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2102 assert(N == 1 && "Invalid number of operands!");
2103 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2106 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2107 assert(N == 1 && "Invalid number of operands!");
2108 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2111 void addVecListOperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 1 && "Invalid number of operands!");
2113 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2116 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2117 assert(N == 2 && "Invalid number of operands!");
2118 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2119 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2122 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2123 assert(N == 1 && "Invalid number of operands!");
2124 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2127 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2128 assert(N == 1 && "Invalid number of operands!");
2129 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2132 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2133 assert(N == 1 && "Invalid number of operands!");
2134 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2137 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2138 assert(N == 1 && "Invalid number of operands!");
2139 // The immediate encodes the type of constant as well as the value.
2140 // Mask in that this is an i8 splat.
2141 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2142 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2145 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2146 assert(N == 1 && "Invalid number of operands!");
2147 // The immediate encodes the type of constant as well as the value.
2148 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2149 unsigned Value = CE->getValue();
2151 Value = (Value >> 8) | 0xa00;
2154 Inst.addOperand(MCOperand::CreateImm(Value));
2157 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2158 assert(N == 1 && "Invalid number of operands!");
2159 // The immediate encodes the type of constant as well as the value.
2160 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2161 unsigned Value = CE->getValue();
2162 if (Value >= 256 && Value <= 0xff00)
2163 Value = (Value >> 8) | 0x200;
2164 else if (Value > 0xffff && Value <= 0xff0000)
2165 Value = (Value >> 16) | 0x400;
2166 else if (Value > 0xffffff)
2167 Value = (Value >> 24) | 0x600;
2168 Inst.addOperand(MCOperand::CreateImm(Value));
2171 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2172 assert(N == 1 && "Invalid number of operands!");
2173 // The immediate encodes the type of constant as well as the value.
2174 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2175 unsigned Value = CE->getValue();
2176 if (Value >= 256 && Value <= 0xffff)
2177 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2178 else if (Value > 0xffff && Value <= 0xffffff)
2179 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2180 else if (Value > 0xffffff)
2181 Value = (Value >> 24) | 0x600;
2182 Inst.addOperand(MCOperand::CreateImm(Value));
2185 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2186 assert(N == 1 && "Invalid number of operands!");
2187 // The immediate encodes the type of constant as well as the value.
2188 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2189 unsigned Value = ~CE->getValue();
2190 if (Value >= 256 && Value <= 0xffff)
2191 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2192 else if (Value > 0xffff && Value <= 0xffffff)
2193 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2194 else if (Value > 0xffffff)
2195 Value = (Value >> 24) | 0x600;
2196 Inst.addOperand(MCOperand::CreateImm(Value));
2199 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2200 assert(N == 1 && "Invalid number of operands!");
2201 // The immediate encodes the type of constant as well as the value.
2202 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2203 uint64_t Value = CE->getValue();
2205 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2206 Imm |= (Value & 1) << i;
2208 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2211 virtual void print(raw_ostream &OS) const;
2213 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2214 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2215 Op->ITMask.Mask = Mask;
2221 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2222 ARMOperand *Op = new ARMOperand(k_CondCode);
2229 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2230 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2231 Op->Cop.Val = CopVal;
2237 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2238 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2239 Op->Cop.Val = CopVal;
2245 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2246 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2253 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2254 ARMOperand *Op = new ARMOperand(k_CCOut);
2255 Op->Reg.RegNum = RegNum;
2261 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2262 ARMOperand *Op = new ARMOperand(k_Token);
2263 Op->Tok.Data = Str.data();
2264 Op->Tok.Length = Str.size();
2270 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2271 ARMOperand *Op = new ARMOperand(k_Register);
2272 Op->Reg.RegNum = RegNum;
2278 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2283 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2284 Op->RegShiftedReg.ShiftTy = ShTy;
2285 Op->RegShiftedReg.SrcReg = SrcReg;
2286 Op->RegShiftedReg.ShiftReg = ShiftReg;
2287 Op->RegShiftedReg.ShiftImm = ShiftImm;
2293 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2297 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2298 Op->RegShiftedImm.ShiftTy = ShTy;
2299 Op->RegShiftedImm.SrcReg = SrcReg;
2300 Op->RegShiftedImm.ShiftImm = ShiftImm;
2306 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2308 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2309 Op->ShifterImm.isASR = isASR;
2310 Op->ShifterImm.Imm = Imm;
2316 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2317 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2318 Op->RotImm.Imm = Imm;
2324 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2326 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2327 Op->Bitfield.LSB = LSB;
2328 Op->Bitfield.Width = Width;
2335 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2336 SMLoc StartLoc, SMLoc EndLoc) {
2337 assert (Regs.size() > 0 && "RegList contains no registers?");
2338 KindTy Kind = k_RegisterList;
2340 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2341 Kind = k_DPRRegisterList;
2342 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2343 contains(Regs.front().second))
2344 Kind = k_SPRRegisterList;
2346 // Sort based on the register encoding values.
2347 array_pod_sort(Regs.begin(), Regs.end());
2349 ARMOperand *Op = new ARMOperand(Kind);
2350 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2351 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2352 Op->Registers.push_back(I->second);
2353 Op->StartLoc = StartLoc;
2354 Op->EndLoc = EndLoc;
2358 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2359 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2360 ARMOperand *Op = new ARMOperand(k_VectorList);
2361 Op->VectorList.RegNum = RegNum;
2362 Op->VectorList.Count = Count;
2363 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2369 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2370 bool isDoubleSpaced,
2372 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2373 Op->VectorList.RegNum = RegNum;
2374 Op->VectorList.Count = Count;
2375 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2381 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2383 bool isDoubleSpaced,
2385 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2386 Op->VectorList.RegNum = RegNum;
2387 Op->VectorList.Count = Count;
2388 Op->VectorList.LaneIndex = Index;
2389 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2395 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2397 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2398 Op->VectorIndex.Val = Idx;
2404 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2405 ARMOperand *Op = new ARMOperand(k_Immediate);
2412 static ARMOperand *CreateMem(unsigned BaseRegNum,
2413 const MCConstantExpr *OffsetImm,
2414 unsigned OffsetRegNum,
2415 ARM_AM::ShiftOpc ShiftType,
2420 ARMOperand *Op = new ARMOperand(k_Memory);
2421 Op->Memory.BaseRegNum = BaseRegNum;
2422 Op->Memory.OffsetImm = OffsetImm;
2423 Op->Memory.OffsetRegNum = OffsetRegNum;
2424 Op->Memory.ShiftType = ShiftType;
2425 Op->Memory.ShiftImm = ShiftImm;
2426 Op->Memory.Alignment = Alignment;
2427 Op->Memory.isNegative = isNegative;
2433 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2434 ARM_AM::ShiftOpc ShiftTy,
2437 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2438 Op->PostIdxReg.RegNum = RegNum;
2439 Op->PostIdxReg.isAdd = isAdd;
2440 Op->PostIdxReg.ShiftTy = ShiftTy;
2441 Op->PostIdxReg.ShiftImm = ShiftImm;
2447 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2448 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2449 Op->MBOpt.Val = Opt;
2455 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2457 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2458 Op->ISBOpt.Val = Opt;
2464 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2465 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2466 Op->IFlags.Val = IFlags;
2472 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2473 ARMOperand *Op = new ARMOperand(k_MSRMask);
2474 Op->MMask.Val = MMask;
2481 } // end anonymous namespace.
2483 void ARMOperand::print(raw_ostream &OS) const {
2486 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2489 OS << "<ccout " << getReg() << ">";
2491 case k_ITCondMask: {
2492 static const char *const MaskStr[] = {
2493 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2494 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2496 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2497 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2501 OS << "<coprocessor number: " << getCoproc() << ">";
2504 OS << "<coprocessor register: " << getCoproc() << ">";
2506 case k_CoprocOption:
2507 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2510 OS << "<mask: " << getMSRMask() << ">";
2513 getImm()->print(OS);
2515 case k_MemBarrierOpt:
2516 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2518 case k_InstSyncBarrierOpt:
2519 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2523 << " base:" << Memory.BaseRegNum;
2526 case k_PostIndexRegister:
2527 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2528 << PostIdxReg.RegNum;
2529 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2530 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2531 << PostIdxReg.ShiftImm;
2534 case k_ProcIFlags: {
2535 OS << "<ARM_PROC::";
2536 unsigned IFlags = getProcIFlags();
2537 for (int i=2; i >= 0; --i)
2538 if (IFlags & (1 << i))
2539 OS << ARM_PROC::IFlagsToString(1 << i);
2544 OS << "<register " << getReg() << ">";
2546 case k_ShifterImmediate:
2547 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2548 << " #" << ShifterImm.Imm << ">";
2550 case k_ShiftedRegister:
2551 OS << "<so_reg_reg "
2552 << RegShiftedReg.SrcReg << " "
2553 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2554 << " " << RegShiftedReg.ShiftReg << ">";
2556 case k_ShiftedImmediate:
2557 OS << "<so_reg_imm "
2558 << RegShiftedImm.SrcReg << " "
2559 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2560 << " #" << RegShiftedImm.ShiftImm << ">";
2562 case k_RotateImmediate:
2563 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2565 case k_BitfieldDescriptor:
2566 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2567 << ", width: " << Bitfield.Width << ">";
2569 case k_RegisterList:
2570 case k_DPRRegisterList:
2571 case k_SPRRegisterList: {
2572 OS << "<register_list ";
2574 const SmallVectorImpl<unsigned> &RegList = getRegList();
2575 for (SmallVectorImpl<unsigned>::const_iterator
2576 I = RegList.begin(), E = RegList.end(); I != E; ) {
2578 if (++I < E) OS << ", ";
2585 OS << "<vector_list " << VectorList.Count << " * "
2586 << VectorList.RegNum << ">";
2588 case k_VectorListAllLanes:
2589 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2590 << VectorList.RegNum << ">";
2592 case k_VectorListIndexed:
2593 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2594 << VectorList.Count << " * " << VectorList.RegNum << ">";
2597 OS << "'" << getToken() << "'";
2600 OS << "<vectorindex " << getVectorIndex() << ">";
2605 /// @name Auto-generated Match Functions
2608 static unsigned MatchRegisterName(StringRef Name);
2612 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2613 SMLoc &StartLoc, SMLoc &EndLoc) {
2614 StartLoc = Parser.getTok().getLoc();
2615 EndLoc = Parser.getTok().getEndLoc();
2616 RegNo = tryParseRegister();
2618 return (RegNo == (unsigned)-1);
2621 /// Try to parse a register name. The token must be an Identifier when called,
2622 /// and if it is a register name the token is eaten and the register number is
2623 /// returned. Otherwise return -1.
2625 int ARMAsmParser::tryParseRegister() {
2626 const AsmToken &Tok = Parser.getTok();
2627 if (Tok.isNot(AsmToken::Identifier)) return -1;
2629 std::string lowerCase = Tok.getString().lower();
2630 unsigned RegNum = MatchRegisterName(lowerCase);
2632 RegNum = StringSwitch<unsigned>(lowerCase)
2633 .Case("r13", ARM::SP)
2634 .Case("r14", ARM::LR)
2635 .Case("r15", ARM::PC)
2636 .Case("ip", ARM::R12)
2637 // Additional register name aliases for 'gas' compatibility.
2638 .Case("a1", ARM::R0)
2639 .Case("a2", ARM::R1)
2640 .Case("a3", ARM::R2)
2641 .Case("a4", ARM::R3)
2642 .Case("v1", ARM::R4)
2643 .Case("v2", ARM::R5)
2644 .Case("v3", ARM::R6)
2645 .Case("v4", ARM::R7)
2646 .Case("v5", ARM::R8)
2647 .Case("v6", ARM::R9)
2648 .Case("v7", ARM::R10)
2649 .Case("v8", ARM::R11)
2650 .Case("sb", ARM::R9)
2651 .Case("sl", ARM::R10)
2652 .Case("fp", ARM::R11)
2656 // Check for aliases registered via .req. Canonicalize to lower case.
2657 // That's more consistent since register names are case insensitive, and
2658 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2659 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2660 // If no match, return failure.
2661 if (Entry == RegisterReqs.end())
2663 Parser.Lex(); // Eat identifier token.
2664 return Entry->getValue();
2667 Parser.Lex(); // Eat identifier token.
2672 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2673 // If a recoverable error occurs, return 1. If an irrecoverable error
2674 // occurs, return -1. An irrecoverable error is one where tokens have been
2675 // consumed in the process of trying to parse the shifter (i.e., when it is
2676 // indeed a shifter operand, but malformed).
2677 int ARMAsmParser::tryParseShiftRegister(
2678 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2679 SMLoc S = Parser.getTok().getLoc();
2680 const AsmToken &Tok = Parser.getTok();
2681 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2683 std::string lowerCase = Tok.getString().lower();
2684 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2685 .Case("asl", ARM_AM::lsl)
2686 .Case("lsl", ARM_AM::lsl)
2687 .Case("lsr", ARM_AM::lsr)
2688 .Case("asr", ARM_AM::asr)
2689 .Case("ror", ARM_AM::ror)
2690 .Case("rrx", ARM_AM::rrx)
2691 .Default(ARM_AM::no_shift);
2693 if (ShiftTy == ARM_AM::no_shift)
2696 Parser.Lex(); // Eat the operator.
2698 // The source register for the shift has already been added to the
2699 // operand list, so we need to pop it off and combine it into the shifted
2700 // register operand instead.
2701 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2702 if (!PrevOp->isReg())
2703 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2704 int SrcReg = PrevOp->getReg();
2709 if (ShiftTy == ARM_AM::rrx) {
2710 // RRX Doesn't have an explicit shift amount. The encoder expects
2711 // the shift register to be the same as the source register. Seems odd,
2715 // Figure out if this is shifted by a constant or a register (for non-RRX).
2716 if (Parser.getTok().is(AsmToken::Hash) ||
2717 Parser.getTok().is(AsmToken::Dollar)) {
2718 Parser.Lex(); // Eat hash.
2719 SMLoc ImmLoc = Parser.getTok().getLoc();
2720 const MCExpr *ShiftExpr = 0;
2721 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2722 Error(ImmLoc, "invalid immediate shift value");
2725 // The expression must be evaluatable as an immediate.
2726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2728 Error(ImmLoc, "invalid immediate shift value");
2731 // Range check the immediate.
2732 // lsl, ror: 0 <= imm <= 31
2733 // lsr, asr: 0 <= imm <= 32
2734 Imm = CE->getValue();
2736 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2737 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2738 Error(ImmLoc, "immediate shift value out of range");
2741 // shift by zero is a nop. Always send it through as lsl.
2742 // ('as' compatibility)
2744 ShiftTy = ARM_AM::lsl;
2745 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2746 SMLoc L = Parser.getTok().getLoc();
2747 EndLoc = Parser.getTok().getEndLoc();
2748 ShiftReg = tryParseRegister();
2749 if (ShiftReg == -1) {
2750 Error (L, "expected immediate or register in shift operand");
2754 Error (Parser.getTok().getLoc(),
2755 "expected immediate or register in shift operand");
2760 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2761 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2765 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2772 /// Try to parse a register name. The token must be an Identifier when called.
2773 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2774 /// if there is a "writeback". 'true' if it's not a register.
2776 /// TODO this is likely to change to allow different register types and or to
2777 /// parse for a specific register type.
2779 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2780 const AsmToken &RegTok = Parser.getTok();
2781 int RegNo = tryParseRegister();
2785 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2786 RegTok.getEndLoc()));
2788 const AsmToken &ExclaimTok = Parser.getTok();
2789 if (ExclaimTok.is(AsmToken::Exclaim)) {
2790 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2791 ExclaimTok.getLoc()));
2792 Parser.Lex(); // Eat exclaim token
2796 // Also check for an index operand. This is only legal for vector registers,
2797 // but that'll get caught OK in operand matching, so we don't need to
2798 // explicitly filter everything else out here.
2799 if (Parser.getTok().is(AsmToken::LBrac)) {
2800 SMLoc SIdx = Parser.getTok().getLoc();
2801 Parser.Lex(); // Eat left bracket token.
2803 const MCExpr *ImmVal;
2804 if (getParser().parseExpression(ImmVal))
2806 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2808 return TokError("immediate value expected for vector index");
2810 if (Parser.getTok().isNot(AsmToken::RBrac))
2811 return Error(Parser.getTok().getLoc(), "']' expected");
2813 SMLoc E = Parser.getTok().getEndLoc();
2814 Parser.Lex(); // Eat right bracket token.
2816 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2824 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2825 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2827 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2828 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2830 switch (Name.size()) {
2833 if (Name[0] != CoprocOp)
2849 if (Name[0] != CoprocOp || Name[1] != '1')
2853 case '0': return 10;
2854 case '1': return 11;
2855 case '2': return 12;
2856 case '3': return 13;
2857 case '4': return 14;
2858 case '5': return 15;
2863 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2864 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2865 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2866 SMLoc S = Parser.getTok().getLoc();
2867 const AsmToken &Tok = Parser.getTok();
2868 if (!Tok.is(AsmToken::Identifier))
2869 return MatchOperand_NoMatch;
2870 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2871 .Case("eq", ARMCC::EQ)
2872 .Case("ne", ARMCC::NE)
2873 .Case("hs", ARMCC::HS)
2874 .Case("cs", ARMCC::HS)
2875 .Case("lo", ARMCC::LO)
2876 .Case("cc", ARMCC::LO)
2877 .Case("mi", ARMCC::MI)
2878 .Case("pl", ARMCC::PL)
2879 .Case("vs", ARMCC::VS)
2880 .Case("vc", ARMCC::VC)
2881 .Case("hi", ARMCC::HI)
2882 .Case("ls", ARMCC::LS)
2883 .Case("ge", ARMCC::GE)
2884 .Case("lt", ARMCC::LT)
2885 .Case("gt", ARMCC::GT)
2886 .Case("le", ARMCC::LE)
2887 .Case("al", ARMCC::AL)
2890 return MatchOperand_NoMatch;
2891 Parser.Lex(); // Eat the token.
2893 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2895 return MatchOperand_Success;
2898 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2899 /// token must be an Identifier when called, and if it is a coprocessor
2900 /// number, the token is eaten and the operand is added to the operand list.
2901 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2902 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2903 SMLoc S = Parser.getTok().getLoc();
2904 const AsmToken &Tok = Parser.getTok();
2905 if (Tok.isNot(AsmToken::Identifier))
2906 return MatchOperand_NoMatch;
2908 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2910 return MatchOperand_NoMatch;
2912 Parser.Lex(); // Eat identifier token.
2913 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2914 return MatchOperand_Success;
2917 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2918 /// token must be an Identifier when called, and if it is a coprocessor
2919 /// number, the token is eaten and the operand is added to the operand list.
2920 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2921 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2922 SMLoc S = Parser.getTok().getLoc();
2923 const AsmToken &Tok = Parser.getTok();
2924 if (Tok.isNot(AsmToken::Identifier))
2925 return MatchOperand_NoMatch;
2927 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2929 return MatchOperand_NoMatch;
2931 Parser.Lex(); // Eat identifier token.
2932 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2933 return MatchOperand_Success;
2936 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2937 /// coproc_option : '{' imm0_255 '}'
2938 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2939 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2940 SMLoc S = Parser.getTok().getLoc();
2942 // If this isn't a '{', this isn't a coprocessor immediate operand.
2943 if (Parser.getTok().isNot(AsmToken::LCurly))
2944 return MatchOperand_NoMatch;
2945 Parser.Lex(); // Eat the '{'
2948 SMLoc Loc = Parser.getTok().getLoc();
2949 if (getParser().parseExpression(Expr)) {
2950 Error(Loc, "illegal expression");
2951 return MatchOperand_ParseFail;
2953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2954 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2955 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2956 return MatchOperand_ParseFail;
2958 int Val = CE->getValue();
2960 // Check for and consume the closing '}'
2961 if (Parser.getTok().isNot(AsmToken::RCurly))
2962 return MatchOperand_ParseFail;
2963 SMLoc E = Parser.getTok().getEndLoc();
2964 Parser.Lex(); // Eat the '}'
2966 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2967 return MatchOperand_Success;
2970 // For register list parsing, we need to map from raw GPR register numbering
2971 // to the enumeration values. The enumeration values aren't sorted by
2972 // register number due to our using "sp", "lr" and "pc" as canonical names.
2973 static unsigned getNextRegister(unsigned Reg) {
2974 // If this is a GPR, we need to do it manually, otherwise we can rely
2975 // on the sort ordering of the enumeration since the other reg-classes
2977 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2980 default: llvm_unreachable("Invalid GPR number!");
2981 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2982 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2983 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2984 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2985 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2986 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2987 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2988 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2992 // Return the low-subreg of a given Q register.
2993 static unsigned getDRegFromQReg(unsigned QReg) {
2995 default: llvm_unreachable("expected a Q register!");
2996 case ARM::Q0: return ARM::D0;
2997 case ARM::Q1: return ARM::D2;
2998 case ARM::Q2: return ARM::D4;
2999 case ARM::Q3: return ARM::D6;
3000 case ARM::Q4: return ARM::D8;
3001 case ARM::Q5: return ARM::D10;
3002 case ARM::Q6: return ARM::D12;
3003 case ARM::Q7: return ARM::D14;
3004 case ARM::Q8: return ARM::D16;
3005 case ARM::Q9: return ARM::D18;
3006 case ARM::Q10: return ARM::D20;
3007 case ARM::Q11: return ARM::D22;
3008 case ARM::Q12: return ARM::D24;
3009 case ARM::Q13: return ARM::D26;
3010 case ARM::Q14: return ARM::D28;
3011 case ARM::Q15: return ARM::D30;
3015 /// Parse a register list.
3017 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3018 assert(Parser.getTok().is(AsmToken::LCurly) &&
3019 "Token is not a Left Curly Brace");
3020 SMLoc S = Parser.getTok().getLoc();
3021 Parser.Lex(); // Eat '{' token.
3022 SMLoc RegLoc = Parser.getTok().getLoc();
3024 // Check the first register in the list to see what register class
3025 // this is a list of.
3026 int Reg = tryParseRegister();
3028 return Error(RegLoc, "register expected");
3030 // The reglist instructions have at most 16 registers, so reserve
3031 // space for that many.
3033 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3035 // Allow Q regs and just interpret them as the two D sub-registers.
3036 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3037 Reg = getDRegFromQReg(Reg);
3038 EReg = MRI->getEncodingValue(Reg);
3039 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3042 const MCRegisterClass *RC;
3043 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3044 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3045 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3046 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3047 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3048 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3050 return Error(RegLoc, "invalid register in register list");
3052 // Store the register.
3053 EReg = MRI->getEncodingValue(Reg);
3054 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3056 // This starts immediately after the first register token in the list,
3057 // so we can see either a comma or a minus (range separator) as a legal
3059 while (Parser.getTok().is(AsmToken::Comma) ||
3060 Parser.getTok().is(AsmToken::Minus)) {
3061 if (Parser.getTok().is(AsmToken::Minus)) {
3062 Parser.Lex(); // Eat the minus.
3063 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3064 int EndReg = tryParseRegister();
3066 return Error(AfterMinusLoc, "register expected");
3067 // Allow Q regs and just interpret them as the two D sub-registers.
3068 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3069 EndReg = getDRegFromQReg(EndReg) + 1;
3070 // If the register is the same as the start reg, there's nothing
3074 // The register must be in the same register class as the first.
3075 if (!RC->contains(EndReg))
3076 return Error(AfterMinusLoc, "invalid register in register list");
3077 // Ranges must go from low to high.
3078 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3079 return Error(AfterMinusLoc, "bad range in register list");
3081 // Add all the registers in the range to the register list.
3082 while (Reg != EndReg) {
3083 Reg = getNextRegister(Reg);
3084 EReg = MRI->getEncodingValue(Reg);
3085 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3089 Parser.Lex(); // Eat the comma.
3090 RegLoc = Parser.getTok().getLoc();
3092 const AsmToken RegTok = Parser.getTok();
3093 Reg = tryParseRegister();
3095 return Error(RegLoc, "register expected");
3096 // Allow Q regs and just interpret them as the two D sub-registers.
3097 bool isQReg = false;
3098 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3099 Reg = getDRegFromQReg(Reg);
3102 // The register must be in the same register class as the first.
3103 if (!RC->contains(Reg))
3104 return Error(RegLoc, "invalid register in register list");
3105 // List must be monotonically increasing.
3106 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3107 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3108 Warning(RegLoc, "register list not in ascending order");
3110 return Error(RegLoc, "register list not in ascending order");
3112 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3113 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3114 ") in register list");
3117 // VFP register lists must also be contiguous.
3118 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3120 return Error(RegLoc, "non-contiguous register range");
3121 EReg = MRI->getEncodingValue(Reg);
3122 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3124 EReg = MRI->getEncodingValue(++Reg);
3125 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3129 if (Parser.getTok().isNot(AsmToken::RCurly))
3130 return Error(Parser.getTok().getLoc(), "'}' expected");
3131 SMLoc E = Parser.getTok().getEndLoc();
3132 Parser.Lex(); // Eat '}' token.
3134 // Push the register list operand.
3135 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3137 // The ARM system instruction variants for LDM/STM have a '^' token here.
3138 if (Parser.getTok().is(AsmToken::Caret)) {
3139 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3140 Parser.Lex(); // Eat '^' token.
3146 // Helper function to parse the lane index for vector lists.
3147 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3148 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3149 Index = 0; // Always return a defined index value.
3150 if (Parser.getTok().is(AsmToken::LBrac)) {
3151 Parser.Lex(); // Eat the '['.
3152 if (Parser.getTok().is(AsmToken::RBrac)) {
3153 // "Dn[]" is the 'all lanes' syntax.
3154 LaneKind = AllLanes;
3155 EndLoc = Parser.getTok().getEndLoc();
3156 Parser.Lex(); // Eat the ']'.
3157 return MatchOperand_Success;
3160 // There's an optional '#' token here. Normally there wouldn't be, but
3161 // inline assemble puts one in, and it's friendly to accept that.
3162 if (Parser.getTok().is(AsmToken::Hash))
3163 Parser.Lex(); // Eat '#' or '$'.
3165 const MCExpr *LaneIndex;
3166 SMLoc Loc = Parser.getTok().getLoc();
3167 if (getParser().parseExpression(LaneIndex)) {
3168 Error(Loc, "illegal expression");
3169 return MatchOperand_ParseFail;
3171 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3173 Error(Loc, "lane index must be empty or an integer");
3174 return MatchOperand_ParseFail;
3176 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3177 Error(Parser.getTok().getLoc(), "']' expected");
3178 return MatchOperand_ParseFail;
3180 EndLoc = Parser.getTok().getEndLoc();
3181 Parser.Lex(); // Eat the ']'.
3182 int64_t Val = CE->getValue();
3184 // FIXME: Make this range check context sensitive for .8, .16, .32.
3185 if (Val < 0 || Val > 7) {
3186 Error(Parser.getTok().getLoc(), "lane index out of range");
3187 return MatchOperand_ParseFail;
3190 LaneKind = IndexedLane;
3191 return MatchOperand_Success;
3194 return MatchOperand_Success;
3197 // parse a vector register list
3198 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3199 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3200 VectorLaneTy LaneKind;
3202 SMLoc S = Parser.getTok().getLoc();
3203 // As an extension (to match gas), support a plain D register or Q register
3204 // (without encosing curly braces) as a single or double entry list,
3206 if (Parser.getTok().is(AsmToken::Identifier)) {
3207 SMLoc E = Parser.getTok().getEndLoc();
3208 int Reg = tryParseRegister();
3210 return MatchOperand_NoMatch;
3211 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3212 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3213 if (Res != MatchOperand_Success)
3217 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3220 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3224 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3229 return MatchOperand_Success;
3231 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3232 Reg = getDRegFromQReg(Reg);
3233 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3234 if (Res != MatchOperand_Success)
3238 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3239 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3240 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3243 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3244 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3245 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3249 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3254 return MatchOperand_Success;
3256 Error(S, "vector register expected");
3257 return MatchOperand_ParseFail;
3260 if (Parser.getTok().isNot(AsmToken::LCurly))
3261 return MatchOperand_NoMatch;
3263 Parser.Lex(); // Eat '{' token.
3264 SMLoc RegLoc = Parser.getTok().getLoc();
3266 int Reg = tryParseRegister();
3268 Error(RegLoc, "register expected");
3269 return MatchOperand_ParseFail;
3273 unsigned FirstReg = Reg;
3274 // The list is of D registers, but we also allow Q regs and just interpret
3275 // them as the two D sub-registers.
3276 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3277 FirstReg = Reg = getDRegFromQReg(Reg);
3278 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3279 // it's ambiguous with four-register single spaced.
3285 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3286 return MatchOperand_ParseFail;
3288 while (Parser.getTok().is(AsmToken::Comma) ||
3289 Parser.getTok().is(AsmToken::Minus)) {
3290 if (Parser.getTok().is(AsmToken::Minus)) {
3292 Spacing = 1; // Register range implies a single spaced list.
3293 else if (Spacing == 2) {
3294 Error(Parser.getTok().getLoc(),
3295 "sequential registers in double spaced list");
3296 return MatchOperand_ParseFail;
3298 Parser.Lex(); // Eat the minus.
3299 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3300 int EndReg = tryParseRegister();
3302 Error(AfterMinusLoc, "register expected");
3303 return MatchOperand_ParseFail;
3305 // Allow Q regs and just interpret them as the two D sub-registers.
3306 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3307 EndReg = getDRegFromQReg(EndReg) + 1;
3308 // If the register is the same as the start reg, there's nothing
3312 // The register must be in the same register class as the first.
3313 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3314 Error(AfterMinusLoc, "invalid register in register list");
3315 return MatchOperand_ParseFail;
3317 // Ranges must go from low to high.
3319 Error(AfterMinusLoc, "bad range in register list");
3320 return MatchOperand_ParseFail;
3322 // Parse the lane specifier if present.
3323 VectorLaneTy NextLaneKind;
3324 unsigned NextLaneIndex;
3325 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3326 MatchOperand_Success)
3327 return MatchOperand_ParseFail;
3328 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3329 Error(AfterMinusLoc, "mismatched lane index in register list");
3330 return MatchOperand_ParseFail;
3333 // Add all the registers in the range to the register list.
3334 Count += EndReg - Reg;
3338 Parser.Lex(); // Eat the comma.
3339 RegLoc = Parser.getTok().getLoc();
3341 Reg = tryParseRegister();
3343 Error(RegLoc, "register expected");
3344 return MatchOperand_ParseFail;
3346 // vector register lists must be contiguous.
3347 // It's OK to use the enumeration values directly here rather, as the
3348 // VFP register classes have the enum sorted properly.
3350 // The list is of D registers, but we also allow Q regs and just interpret
3351 // them as the two D sub-registers.
3352 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3354 Spacing = 1; // Register range implies a single spaced list.
3355 else if (Spacing == 2) {
3357 "invalid register in double-spaced list (must be 'D' register')");
3358 return MatchOperand_ParseFail;
3360 Reg = getDRegFromQReg(Reg);
3361 if (Reg != OldReg + 1) {
3362 Error(RegLoc, "non-contiguous register range");
3363 return MatchOperand_ParseFail;
3367 // Parse the lane specifier if present.
3368 VectorLaneTy NextLaneKind;
3369 unsigned NextLaneIndex;
3370 SMLoc LaneLoc = Parser.getTok().getLoc();
3371 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3372 MatchOperand_Success)
3373 return MatchOperand_ParseFail;
3374 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3375 Error(LaneLoc, "mismatched lane index in register list");
3376 return MatchOperand_ParseFail;
3380 // Normal D register.
3381 // Figure out the register spacing (single or double) of the list if
3382 // we don't know it already.
3384 Spacing = 1 + (Reg == OldReg + 2);
3386 // Just check that it's contiguous and keep going.
3387 if (Reg != OldReg + Spacing) {
3388 Error(RegLoc, "non-contiguous register range");
3389 return MatchOperand_ParseFail;
3392 // Parse the lane specifier if present.
3393 VectorLaneTy NextLaneKind;
3394 unsigned NextLaneIndex;
3395 SMLoc EndLoc = Parser.getTok().getLoc();
3396 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3397 return MatchOperand_ParseFail;
3398 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3399 Error(EndLoc, "mismatched lane index in register list");
3400 return MatchOperand_ParseFail;
3404 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3405 Error(Parser.getTok().getLoc(), "'}' expected");
3406 return MatchOperand_ParseFail;
3408 E = Parser.getTok().getEndLoc();
3409 Parser.Lex(); // Eat '}' token.
3413 // Two-register operands have been converted to the
3414 // composite register classes.
3416 const MCRegisterClass *RC = (Spacing == 1) ?
3417 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3418 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3419 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3422 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3423 (Spacing == 2), S, E));
3426 // Two-register operands have been converted to the
3427 // composite register classes.
3429 const MCRegisterClass *RC = (Spacing == 1) ?
3430 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3431 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3432 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3434 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3439 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3445 return MatchOperand_Success;
3448 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3449 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3450 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3451 SMLoc S = Parser.getTok().getLoc();
3452 const AsmToken &Tok = Parser.getTok();
3455 if (Tok.is(AsmToken::Identifier)) {
3456 StringRef OptStr = Tok.getString();
3458 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3459 .Case("sy", ARM_MB::SY)
3460 .Case("st", ARM_MB::ST)
3461 .Case("ld", ARM_MB::LD)
3462 .Case("sh", ARM_MB::ISH)
3463 .Case("ish", ARM_MB::ISH)
3464 .Case("shst", ARM_MB::ISHST)
3465 .Case("ishst", ARM_MB::ISHST)
3466 .Case("ishld", ARM_MB::ISHLD)
3467 .Case("nsh", ARM_MB::NSH)
3468 .Case("un", ARM_MB::NSH)
3469 .Case("nshst", ARM_MB::NSHST)
3470 .Case("nshld", ARM_MB::NSHLD)
3471 .Case("unst", ARM_MB::NSHST)
3472 .Case("osh", ARM_MB::OSH)
3473 .Case("oshst", ARM_MB::OSHST)
3474 .Case("oshld", ARM_MB::OSHLD)
3477 // ishld, oshld, nshld and ld are only available from ARMv8.
3478 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3479 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3483 return MatchOperand_NoMatch;
3485 Parser.Lex(); // Eat identifier token.
3486 } else if (Tok.is(AsmToken::Hash) ||
3487 Tok.is(AsmToken::Dollar) ||
3488 Tok.is(AsmToken::Integer)) {
3489 if (Parser.getTok().isNot(AsmToken::Integer))
3490 Parser.Lex(); // Eat '#' or '$'.
3491 SMLoc Loc = Parser.getTok().getLoc();
3493 const MCExpr *MemBarrierID;
3494 if (getParser().parseExpression(MemBarrierID)) {
3495 Error(Loc, "illegal expression");
3496 return MatchOperand_ParseFail;
3499 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3501 Error(Loc, "constant expression expected");
3502 return MatchOperand_ParseFail;
3505 int Val = CE->getValue();
3507 Error(Loc, "immediate value out of range");
3508 return MatchOperand_ParseFail;
3511 Opt = ARM_MB::RESERVED_0 + Val;
3513 return MatchOperand_ParseFail;
3515 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3516 return MatchOperand_Success;
3519 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3520 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3521 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3522 SMLoc S = Parser.getTok().getLoc();
3523 const AsmToken &Tok = Parser.getTok();
3526 if (Tok.is(AsmToken::Identifier)) {
3527 StringRef OptStr = Tok.getString();
3529 if (OptStr.lower() == "sy")
3532 return MatchOperand_NoMatch;
3534 Parser.Lex(); // Eat identifier token.
3535 } else if (Tok.is(AsmToken::Hash) ||
3536 Tok.is(AsmToken::Dollar) ||
3537 Tok.is(AsmToken::Integer)) {
3538 if (Parser.getTok().isNot(AsmToken::Integer))
3539 Parser.Lex(); // Eat '#' or '$'.
3540 SMLoc Loc = Parser.getTok().getLoc();
3542 const MCExpr *ISBarrierID;
3543 if (getParser().parseExpression(ISBarrierID)) {
3544 Error(Loc, "illegal expression");
3545 return MatchOperand_ParseFail;
3548 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3550 Error(Loc, "constant expression expected");
3551 return MatchOperand_ParseFail;
3554 int Val = CE->getValue();
3556 Error(Loc, "immediate value out of range");
3557 return MatchOperand_ParseFail;
3560 Opt = ARM_ISB::RESERVED_0 + Val;
3562 return MatchOperand_ParseFail;
3564 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3565 (ARM_ISB::InstSyncBOpt)Opt, S));
3566 return MatchOperand_Success;
3570 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3571 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3572 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3573 SMLoc S = Parser.getTok().getLoc();
3574 const AsmToken &Tok = Parser.getTok();
3575 if (!Tok.is(AsmToken::Identifier))
3576 return MatchOperand_NoMatch;
3577 StringRef IFlagsStr = Tok.getString();
3579 // An iflags string of "none" is interpreted to mean that none of the AIF
3580 // bits are set. Not a terribly useful instruction, but a valid encoding.
3581 unsigned IFlags = 0;
3582 if (IFlagsStr != "none") {
3583 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3584 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3585 .Case("a", ARM_PROC::A)
3586 .Case("i", ARM_PROC::I)
3587 .Case("f", ARM_PROC::F)
3590 // If some specific iflag is already set, it means that some letter is
3591 // present more than once, this is not acceptable.
3592 if (Flag == ~0U || (IFlags & Flag))
3593 return MatchOperand_NoMatch;
3599 Parser.Lex(); // Eat identifier token.
3600 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3601 return MatchOperand_Success;
3604 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3605 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3606 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3607 SMLoc S = Parser.getTok().getLoc();
3608 const AsmToken &Tok = Parser.getTok();
3609 if (!Tok.is(AsmToken::Identifier))
3610 return MatchOperand_NoMatch;
3611 StringRef Mask = Tok.getString();
3614 // See ARMv6-M 10.1.1
3615 std::string Name = Mask.lower();
3616 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3617 // Note: in the documentation:
3618 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3619 // for MSR APSR_nzcvq.
3620 // but we do make it an alias here. This is so to get the "mask encoding"
3621 // bits correct on MSR APSR writes.
3623 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3624 // should really only be allowed when writing a special register. Note
3625 // they get dropped in the MRS instruction reading a special register as
3626 // the SYSm field is only 8 bits.
3628 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3629 // includes the DSP extension but that is not checked.
3630 .Case("apsr", 0x800)
3631 .Case("apsr_nzcvq", 0x800)
3632 .Case("apsr_g", 0x400)
3633 .Case("apsr_nzcvqg", 0xc00)
3634 .Case("iapsr", 0x801)
3635 .Case("iapsr_nzcvq", 0x801)
3636 .Case("iapsr_g", 0x401)
3637 .Case("iapsr_nzcvqg", 0xc01)
3638 .Case("eapsr", 0x802)
3639 .Case("eapsr_nzcvq", 0x802)
3640 .Case("eapsr_g", 0x402)
3641 .Case("eapsr_nzcvqg", 0xc02)
3642 .Case("xpsr", 0x803)
3643 .Case("xpsr_nzcvq", 0x803)
3644 .Case("xpsr_g", 0x403)
3645 .Case("xpsr_nzcvqg", 0xc03)
3646 .Case("ipsr", 0x805)
3647 .Case("epsr", 0x806)
3648 .Case("iepsr", 0x807)
3651 .Case("primask", 0x810)
3652 .Case("basepri", 0x811)
3653 .Case("basepri_max", 0x812)
3654 .Case("faultmask", 0x813)
3655 .Case("control", 0x814)
3658 if (FlagsVal == ~0U)
3659 return MatchOperand_NoMatch;
3661 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3662 // basepri, basepri_max and faultmask only valid for V7m.
3663 return MatchOperand_NoMatch;
3665 Parser.Lex(); // Eat identifier token.
3666 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3667 return MatchOperand_Success;
3670 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3671 size_t Start = 0, Next = Mask.find('_');
3672 StringRef Flags = "";
3673 std::string SpecReg = Mask.slice(Start, Next).lower();
3674 if (Next != StringRef::npos)
3675 Flags = Mask.slice(Next+1, Mask.size());
3677 // FlagsVal contains the complete mask:
3679 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3680 unsigned FlagsVal = 0;
3682 if (SpecReg == "apsr") {
3683 FlagsVal = StringSwitch<unsigned>(Flags)
3684 .Case("nzcvq", 0x8) // same as CPSR_f
3685 .Case("g", 0x4) // same as CPSR_s
3686 .Case("nzcvqg", 0xc) // same as CPSR_fs
3689 if (FlagsVal == ~0U) {
3691 return MatchOperand_NoMatch;
3693 FlagsVal = 8; // No flag
3695 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3696 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3697 if (Flags == "all" || Flags == "")
3699 for (int i = 0, e = Flags.size(); i != e; ++i) {
3700 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3707 // If some specific flag is already set, it means that some letter is
3708 // present more than once, this is not acceptable.
3709 if (FlagsVal == ~0U || (FlagsVal & Flag))
3710 return MatchOperand_NoMatch;
3713 } else // No match for special register.
3714 return MatchOperand_NoMatch;
3716 // Special register without flags is NOT equivalent to "fc" flags.
3717 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3718 // two lines would enable gas compatibility at the expense of breaking
3724 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3725 if (SpecReg == "spsr")
3728 Parser.Lex(); // Eat identifier token.
3729 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3730 return MatchOperand_Success;
3733 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3734 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3735 int Low, int High) {
3736 const AsmToken &Tok = Parser.getTok();
3737 if (Tok.isNot(AsmToken::Identifier)) {
3738 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3739 return MatchOperand_ParseFail;
3741 StringRef ShiftName = Tok.getString();
3742 std::string LowerOp = Op.lower();
3743 std::string UpperOp = Op.upper();
3744 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3745 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3746 return MatchOperand_ParseFail;
3748 Parser.Lex(); // Eat shift type token.
3750 // There must be a '#' and a shift amount.
3751 if (Parser.getTok().isNot(AsmToken::Hash) &&
3752 Parser.getTok().isNot(AsmToken::Dollar)) {
3753 Error(Parser.getTok().getLoc(), "'#' expected");
3754 return MatchOperand_ParseFail;
3756 Parser.Lex(); // Eat hash token.
3758 const MCExpr *ShiftAmount;
3759 SMLoc Loc = Parser.getTok().getLoc();
3761 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3762 Error(Loc, "illegal expression");
3763 return MatchOperand_ParseFail;
3765 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3767 Error(Loc, "constant expression expected");
3768 return MatchOperand_ParseFail;
3770 int Val = CE->getValue();
3771 if (Val < Low || Val > High) {
3772 Error(Loc, "immediate value out of range");
3773 return MatchOperand_ParseFail;
3776 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3778 return MatchOperand_Success;
3781 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3782 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3783 const AsmToken &Tok = Parser.getTok();
3784 SMLoc S = Tok.getLoc();
3785 if (Tok.isNot(AsmToken::Identifier)) {
3786 Error(S, "'be' or 'le' operand expected");
3787 return MatchOperand_ParseFail;
3789 int Val = StringSwitch<int>(Tok.getString().lower())
3793 Parser.Lex(); // Eat the token.
3796 Error(S, "'be' or 'le' operand expected");
3797 return MatchOperand_ParseFail;
3799 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3801 S, Tok.getEndLoc()));
3802 return MatchOperand_Success;
3805 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3806 /// instructions. Legal values are:
3807 /// lsl #n 'n' in [0,31]
3808 /// asr #n 'n' in [1,32]
3809 /// n == 32 encoded as n == 0.
3810 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3811 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3812 const AsmToken &Tok = Parser.getTok();
3813 SMLoc S = Tok.getLoc();
3814 if (Tok.isNot(AsmToken::Identifier)) {
3815 Error(S, "shift operator 'asr' or 'lsl' expected");
3816 return MatchOperand_ParseFail;
3818 StringRef ShiftName = Tok.getString();
3820 if (ShiftName == "lsl" || ShiftName == "LSL")
3822 else if (ShiftName == "asr" || ShiftName == "ASR")
3825 Error(S, "shift operator 'asr' or 'lsl' expected");
3826 return MatchOperand_ParseFail;
3828 Parser.Lex(); // Eat the operator.
3830 // A '#' and a shift amount.
3831 if (Parser.getTok().isNot(AsmToken::Hash) &&
3832 Parser.getTok().isNot(AsmToken::Dollar)) {
3833 Error(Parser.getTok().getLoc(), "'#' expected");
3834 return MatchOperand_ParseFail;
3836 Parser.Lex(); // Eat hash token.
3837 SMLoc ExLoc = Parser.getTok().getLoc();
3839 const MCExpr *ShiftAmount;
3841 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3842 Error(ExLoc, "malformed shift expression");
3843 return MatchOperand_ParseFail;
3845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3847 Error(ExLoc, "shift amount must be an immediate");
3848 return MatchOperand_ParseFail;
3851 int64_t Val = CE->getValue();
3853 // Shift amount must be in [1,32]
3854 if (Val < 1 || Val > 32) {
3855 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3856 return MatchOperand_ParseFail;
3858 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3859 if (isThumb() && Val == 32) {
3860 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3861 return MatchOperand_ParseFail;
3863 if (Val == 32) Val = 0;
3865 // Shift amount must be in [1,32]
3866 if (Val < 0 || Val > 31) {
3867 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3868 return MatchOperand_ParseFail;
3872 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3874 return MatchOperand_Success;
3877 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3878 /// of instructions. Legal values are:
3879 /// ror #n 'n' in {0, 8, 16, 24}
3880 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3881 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3882 const AsmToken &Tok = Parser.getTok();
3883 SMLoc S = Tok.getLoc();
3884 if (Tok.isNot(AsmToken::Identifier))
3885 return MatchOperand_NoMatch;
3886 StringRef ShiftName = Tok.getString();
3887 if (ShiftName != "ror" && ShiftName != "ROR")
3888 return MatchOperand_NoMatch;
3889 Parser.Lex(); // Eat the operator.
3891 // A '#' and a rotate amount.
3892 if (Parser.getTok().isNot(AsmToken::Hash) &&
3893 Parser.getTok().isNot(AsmToken::Dollar)) {
3894 Error(Parser.getTok().getLoc(), "'#' expected");
3895 return MatchOperand_ParseFail;
3897 Parser.Lex(); // Eat hash token.
3898 SMLoc ExLoc = Parser.getTok().getLoc();
3900 const MCExpr *ShiftAmount;
3902 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3903 Error(ExLoc, "malformed rotate expression");
3904 return MatchOperand_ParseFail;
3906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3908 Error(ExLoc, "rotate amount must be an immediate");
3909 return MatchOperand_ParseFail;
3912 int64_t Val = CE->getValue();
3913 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3914 // normally, zero is represented in asm by omitting the rotate operand
3916 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3917 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
3918 return MatchOperand_ParseFail;
3921 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
3923 return MatchOperand_Success;
3926 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3927 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3928 SMLoc S = Parser.getTok().getLoc();
3929 // The bitfield descriptor is really two operands, the LSB and the width.
3930 if (Parser.getTok().isNot(AsmToken::Hash) &&
3931 Parser.getTok().isNot(AsmToken::Dollar)) {
3932 Error(Parser.getTok().getLoc(), "'#' expected");
3933 return MatchOperand_ParseFail;
3935 Parser.Lex(); // Eat hash token.
3937 const MCExpr *LSBExpr;
3938 SMLoc E = Parser.getTok().getLoc();
3939 if (getParser().parseExpression(LSBExpr)) {
3940 Error(E, "malformed immediate expression");
3941 return MatchOperand_ParseFail;
3943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3945 Error(E, "'lsb' operand must be an immediate");
3946 return MatchOperand_ParseFail;
3949 int64_t LSB = CE->getValue();
3950 // The LSB must be in the range [0,31]
3951 if (LSB < 0 || LSB > 31) {
3952 Error(E, "'lsb' operand must be in the range [0,31]");
3953 return MatchOperand_ParseFail;
3955 E = Parser.getTok().getLoc();
3957 // Expect another immediate operand.
3958 if (Parser.getTok().isNot(AsmToken::Comma)) {
3959 Error(Parser.getTok().getLoc(), "too few operands");
3960 return MatchOperand_ParseFail;
3962 Parser.Lex(); // Eat hash token.
3963 if (Parser.getTok().isNot(AsmToken::Hash) &&
3964 Parser.getTok().isNot(AsmToken::Dollar)) {
3965 Error(Parser.getTok().getLoc(), "'#' expected");
3966 return MatchOperand_ParseFail;
3968 Parser.Lex(); // Eat hash token.
3970 const MCExpr *WidthExpr;
3972 if (getParser().parseExpression(WidthExpr, EndLoc)) {
3973 Error(E, "malformed immediate expression");
3974 return MatchOperand_ParseFail;
3976 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3978 Error(E, "'width' operand must be an immediate");
3979 return MatchOperand_ParseFail;
3982 int64_t Width = CE->getValue();
3983 // The LSB must be in the range [1,32-lsb]
3984 if (Width < 1 || Width > 32 - LSB) {
3985 Error(E, "'width' operand must be in the range [1,32-lsb]");
3986 return MatchOperand_ParseFail;
3989 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
3991 return MatchOperand_Success;
3994 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3995 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3996 // Check for a post-index addressing register operand. Specifically:
3997 // postidx_reg := '+' register {, shift}
3998 // | '-' register {, shift}
3999 // | register {, shift}
4001 // This method must return MatchOperand_NoMatch without consuming any tokens
4002 // in the case where there is no match, as other alternatives take other
4004 AsmToken Tok = Parser.getTok();
4005 SMLoc S = Tok.getLoc();
4006 bool haveEaten = false;
4008 if (Tok.is(AsmToken::Plus)) {
4009 Parser.Lex(); // Eat the '+' token.
4011 } else if (Tok.is(AsmToken::Minus)) {
4012 Parser.Lex(); // Eat the '-' token.
4017 SMLoc E = Parser.getTok().getEndLoc();
4018 int Reg = tryParseRegister();
4021 return MatchOperand_NoMatch;
4022 Error(Parser.getTok().getLoc(), "register expected");
4023 return MatchOperand_ParseFail;
4026 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4027 unsigned ShiftImm = 0;
4028 if (Parser.getTok().is(AsmToken::Comma)) {
4029 Parser.Lex(); // Eat the ','.
4030 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4031 return MatchOperand_ParseFail;
4033 // FIXME: Only approximates end...may include intervening whitespace.
4034 E = Parser.getTok().getLoc();
4037 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4040 return MatchOperand_Success;
4043 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4044 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4045 // Check for a post-index addressing register operand. Specifically:
4046 // am3offset := '+' register
4053 // This method must return MatchOperand_NoMatch without consuming any tokens
4054 // in the case where there is no match, as other alternatives take other
4056 AsmToken Tok = Parser.getTok();
4057 SMLoc S = Tok.getLoc();
4059 // Do immediates first, as we always parse those if we have a '#'.
4060 if (Parser.getTok().is(AsmToken::Hash) ||
4061 Parser.getTok().is(AsmToken::Dollar)) {
4062 Parser.Lex(); // Eat '#' or '$'.
4063 // Explicitly look for a '-', as we need to encode negative zero
4065 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4066 const MCExpr *Offset;
4068 if (getParser().parseExpression(Offset, E))
4069 return MatchOperand_ParseFail;
4070 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4072 Error(S, "constant expression expected");
4073 return MatchOperand_ParseFail;
4075 // Negative zero is encoded as the flag value INT32_MIN.
4076 int32_t Val = CE->getValue();
4077 if (isNegative && Val == 0)
4081 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4083 return MatchOperand_Success;
4087 bool haveEaten = false;
4089 if (Tok.is(AsmToken::Plus)) {
4090 Parser.Lex(); // Eat the '+' token.
4092 } else if (Tok.is(AsmToken::Minus)) {
4093 Parser.Lex(); // Eat the '-' token.
4098 Tok = Parser.getTok();
4099 int Reg = tryParseRegister();
4102 return MatchOperand_NoMatch;
4103 Error(Tok.getLoc(), "register expected");
4104 return MatchOperand_ParseFail;
4107 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4108 0, S, Tok.getEndLoc()));
4110 return MatchOperand_Success;
4113 /// Convert parsed operands to MCInst. Needed here because this instruction
4114 /// only has two register operands, but multiplication is commutative so
4115 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4117 cvtThumbMultiply(MCInst &Inst,
4118 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4119 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4120 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4121 // If we have a three-operand form, make sure to set Rn to be the operand
4122 // that isn't the same as Rd.
4124 if (Operands.size() == 6 &&
4125 ((ARMOperand*)Operands[4])->getReg() ==
4126 ((ARMOperand*)Operands[3])->getReg())
4128 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4129 Inst.addOperand(Inst.getOperand(0));
4130 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4134 cvtThumbBranches(MCInst &Inst,
4135 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4136 int CondOp = -1, ImmOp = -1;
4137 switch(Inst.getOpcode()) {
4139 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4142 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4144 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4146 // first decide whether or not the branch should be conditional
4147 // by looking at it's location relative to an IT block
4149 // inside an IT block we cannot have any conditional branches. any
4150 // such instructions needs to be converted to unconditional form
4151 switch(Inst.getOpcode()) {
4152 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4153 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4156 // outside IT blocks we can only have unconditional branches with AL
4157 // condition code or conditional branches with non-AL condition code
4158 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4159 switch(Inst.getOpcode()) {
4162 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4166 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4171 // now decide on encoding size based on branch target range
4172 switch(Inst.getOpcode()) {
4173 // classify tB as either t2B or t1B based on range of immediate operand
4175 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4176 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4177 Inst.setOpcode(ARM::t2B);
4180 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4182 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4183 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4184 Inst.setOpcode(ARM::t2Bcc);
4188 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4189 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4192 /// Parse an ARM memory expression, return false if successful else return true
4193 /// or an error. The first token must be a '[' when called.
4195 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4197 assert(Parser.getTok().is(AsmToken::LBrac) &&
4198 "Token is not a Left Bracket");
4199 S = Parser.getTok().getLoc();
4200 Parser.Lex(); // Eat left bracket token.
4202 const AsmToken &BaseRegTok = Parser.getTok();
4203 int BaseRegNum = tryParseRegister();
4204 if (BaseRegNum == -1)
4205 return Error(BaseRegTok.getLoc(), "register expected");
4207 // The next token must either be a comma, a colon or a closing bracket.
4208 const AsmToken &Tok = Parser.getTok();
4209 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4210 !Tok.is(AsmToken::RBrac))
4211 return Error(Tok.getLoc(), "malformed memory operand");
4213 if (Tok.is(AsmToken::RBrac)) {
4214 E = Tok.getEndLoc();
4215 Parser.Lex(); // Eat right bracket token.
4217 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4218 0, 0, false, S, E));
4220 // If there's a pre-indexing writeback marker, '!', just add it as a token
4221 // operand. It's rather odd, but syntactically valid.
4222 if (Parser.getTok().is(AsmToken::Exclaim)) {
4223 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4224 Parser.Lex(); // Eat the '!'.
4230 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4231 "Lost colon or comma in memory operand?!");
4232 if (Tok.is(AsmToken::Comma)) {
4233 Parser.Lex(); // Eat the comma.
4236 // If we have a ':', it's an alignment specifier.
4237 if (Parser.getTok().is(AsmToken::Colon)) {
4238 Parser.Lex(); // Eat the ':'.
4239 E = Parser.getTok().getLoc();
4242 if (getParser().parseExpression(Expr))
4245 // The expression has to be a constant. Memory references with relocations
4246 // don't come through here, as they use the <label> forms of the relevant
4248 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4250 return Error (E, "constant expression expected");
4253 switch (CE->getValue()) {
4256 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4257 case 16: Align = 2; break;
4258 case 32: Align = 4; break;
4259 case 64: Align = 8; break;
4260 case 128: Align = 16; break;
4261 case 256: Align = 32; break;
4264 // Now we should have the closing ']'
4265 if (Parser.getTok().isNot(AsmToken::RBrac))
4266 return Error(Parser.getTok().getLoc(), "']' expected");
4267 E = Parser.getTok().getEndLoc();
4268 Parser.Lex(); // Eat right bracket token.
4270 // Don't worry about range checking the value here. That's handled by
4271 // the is*() predicates.
4272 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4273 ARM_AM::no_shift, 0, Align,
4276 // If there's a pre-indexing writeback marker, '!', just add it as a token
4278 if (Parser.getTok().is(AsmToken::Exclaim)) {
4279 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4280 Parser.Lex(); // Eat the '!'.
4286 // If we have a '#', it's an immediate offset, else assume it's a register
4287 // offset. Be friendly and also accept a plain integer (without a leading
4288 // hash) for gas compatibility.
4289 if (Parser.getTok().is(AsmToken::Hash) ||
4290 Parser.getTok().is(AsmToken::Dollar) ||
4291 Parser.getTok().is(AsmToken::Integer)) {
4292 if (Parser.getTok().isNot(AsmToken::Integer))
4293 Parser.Lex(); // Eat '#' or '$'.
4294 E = Parser.getTok().getLoc();
4296 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4297 const MCExpr *Offset;
4298 if (getParser().parseExpression(Offset))
4301 // The expression has to be a constant. Memory references with relocations
4302 // don't come through here, as they use the <label> forms of the relevant
4304 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4306 return Error (E, "constant expression expected");
4308 // If the constant was #-0, represent it as INT32_MIN.
4309 int32_t Val = CE->getValue();
4310 if (isNegative && Val == 0)
4311 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4313 // Now we should have the closing ']'
4314 if (Parser.getTok().isNot(AsmToken::RBrac))
4315 return Error(Parser.getTok().getLoc(), "']' expected");
4316 E = Parser.getTok().getEndLoc();
4317 Parser.Lex(); // Eat right bracket token.
4319 // Don't worry about range checking the value here. That's handled by
4320 // the is*() predicates.
4321 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4322 ARM_AM::no_shift, 0, 0,
4325 // If there's a pre-indexing writeback marker, '!', just add it as a token
4327 if (Parser.getTok().is(AsmToken::Exclaim)) {
4328 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4329 Parser.Lex(); // Eat the '!'.
4335 // The register offset is optionally preceded by a '+' or '-'
4336 bool isNegative = false;
4337 if (Parser.getTok().is(AsmToken::Minus)) {
4339 Parser.Lex(); // Eat the '-'.
4340 } else if (Parser.getTok().is(AsmToken::Plus)) {
4342 Parser.Lex(); // Eat the '+'.
4345 E = Parser.getTok().getLoc();
4346 int OffsetRegNum = tryParseRegister();
4347 if (OffsetRegNum == -1)
4348 return Error(E, "register expected");
4350 // If there's a shift operator, handle it.
4351 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4352 unsigned ShiftImm = 0;
4353 if (Parser.getTok().is(AsmToken::Comma)) {
4354 Parser.Lex(); // Eat the ','.
4355 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4359 // Now we should have the closing ']'
4360 if (Parser.getTok().isNot(AsmToken::RBrac))
4361 return Error(Parser.getTok().getLoc(), "']' expected");
4362 E = Parser.getTok().getEndLoc();
4363 Parser.Lex(); // Eat right bracket token.
4365 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4366 ShiftType, ShiftImm, 0, isNegative,
4369 // If there's a pre-indexing writeback marker, '!', just add it as a token
4371 if (Parser.getTok().is(AsmToken::Exclaim)) {
4372 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4373 Parser.Lex(); // Eat the '!'.
4379 /// parseMemRegOffsetShift - one of these two:
4380 /// ( lsl | lsr | asr | ror ) , # shift_amount
4382 /// return true if it parses a shift otherwise it returns false.
4383 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4385 SMLoc Loc = Parser.getTok().getLoc();
4386 const AsmToken &Tok = Parser.getTok();
4387 if (Tok.isNot(AsmToken::Identifier))
4389 StringRef ShiftName = Tok.getString();
4390 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4391 ShiftName == "asl" || ShiftName == "ASL")
4393 else if (ShiftName == "lsr" || ShiftName == "LSR")
4395 else if (ShiftName == "asr" || ShiftName == "ASR")
4397 else if (ShiftName == "ror" || ShiftName == "ROR")
4399 else if (ShiftName == "rrx" || ShiftName == "RRX")
4402 return Error(Loc, "illegal shift operator");
4403 Parser.Lex(); // Eat shift type token.
4405 // rrx stands alone.
4407 if (St != ARM_AM::rrx) {
4408 Loc = Parser.getTok().getLoc();
4409 // A '#' and a shift amount.
4410 const AsmToken &HashTok = Parser.getTok();
4411 if (HashTok.isNot(AsmToken::Hash) &&
4412 HashTok.isNot(AsmToken::Dollar))
4413 return Error(HashTok.getLoc(), "'#' expected");
4414 Parser.Lex(); // Eat hash token.
4417 if (getParser().parseExpression(Expr))
4419 // Range check the immediate.
4420 // lsl, ror: 0 <= imm <= 31
4421 // lsr, asr: 0 <= imm <= 32
4422 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4424 return Error(Loc, "shift amount must be an immediate");
4425 int64_t Imm = CE->getValue();
4427 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4428 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4429 return Error(Loc, "immediate shift value out of range");
4430 // If <ShiftTy> #0, turn it into a no_shift.
4433 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4442 /// parseFPImm - A floating point immediate expression operand.
4443 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4444 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4445 // Anything that can accept a floating point constant as an operand
4446 // needs to go through here, as the regular parseExpression is
4449 // This routine still creates a generic Immediate operand, containing
4450 // a bitcast of the 64-bit floating point value. The various operands
4451 // that accept floats can check whether the value is valid for them
4452 // via the standard is*() predicates.
4454 SMLoc S = Parser.getTok().getLoc();
4456 if (Parser.getTok().isNot(AsmToken::Hash) &&
4457 Parser.getTok().isNot(AsmToken::Dollar))
4458 return MatchOperand_NoMatch;
4460 // Disambiguate the VMOV forms that can accept an FP immediate.
4461 // vmov.f32 <sreg>, #imm
4462 // vmov.f64 <dreg>, #imm
4463 // vmov.f32 <dreg>, #imm @ vector f32x2
4464 // vmov.f32 <qreg>, #imm @ vector f32x4
4466 // There are also the NEON VMOV instructions which expect an
4467 // integer constant. Make sure we don't try to parse an FPImm
4469 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4470 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4471 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4472 TyOp->getToken() != ".f64"))
4473 return MatchOperand_NoMatch;
4475 Parser.Lex(); // Eat '#' or '$'.
4477 // Handle negation, as that still comes through as a separate token.
4478 bool isNegative = false;
4479 if (Parser.getTok().is(AsmToken::Minus)) {
4483 const AsmToken &Tok = Parser.getTok();
4484 SMLoc Loc = Tok.getLoc();
4485 if (Tok.is(AsmToken::Real)) {
4486 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4487 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4488 // If we had a '-' in front, toggle the sign bit.
4489 IntVal ^= (uint64_t)isNegative << 31;
4490 Parser.Lex(); // Eat the token.
4491 Operands.push_back(ARMOperand::CreateImm(
4492 MCConstantExpr::Create(IntVal, getContext()),
4493 S, Parser.getTok().getLoc()));
4494 return MatchOperand_Success;
4496 // Also handle plain integers. Instructions which allow floating point
4497 // immediates also allow a raw encoded 8-bit value.
4498 if (Tok.is(AsmToken::Integer)) {
4499 int64_t Val = Tok.getIntVal();
4500 Parser.Lex(); // Eat the token.
4501 if (Val > 255 || Val < 0) {
4502 Error(Loc, "encoded floating point value out of range");
4503 return MatchOperand_ParseFail;
4505 double RealVal = ARM_AM::getFPImmFloat(Val);
4506 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4507 Operands.push_back(ARMOperand::CreateImm(
4508 MCConstantExpr::Create(Val, getContext()), S,
4509 Parser.getTok().getLoc()));
4510 return MatchOperand_Success;
4513 Error(Loc, "invalid floating point immediate");
4514 return MatchOperand_ParseFail;
4517 /// Parse a arm instruction operand. For now this parses the operand regardless
4518 /// of the mnemonic.
4519 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4520 StringRef Mnemonic) {
4523 // Check if the current operand has a custom associated parser, if so, try to
4524 // custom parse the operand, or fallback to the general approach.
4525 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4526 if (ResTy == MatchOperand_Success)
4528 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4529 // there was a match, but an error occurred, in which case, just return that
4530 // the operand parsing failed.
4531 if (ResTy == MatchOperand_ParseFail)
4534 switch (getLexer().getKind()) {
4536 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4538 case AsmToken::Identifier: {
4539 // If we've seen a branch mnemonic, the next operand must be a label. This
4540 // is true even if the label is a register name. So "br r1" means branch to
4542 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4544 if (!tryParseRegisterWithWriteBack(Operands))
4546 int Res = tryParseShiftRegister(Operands);
4547 if (Res == 0) // success
4549 else if (Res == -1) // irrecoverable error
4551 // If this is VMRS, check for the apsr_nzcv operand.
4552 if (Mnemonic == "vmrs" &&
4553 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4554 S = Parser.getTok().getLoc();
4556 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4561 // Fall though for the Identifier case that is not a register or a
4564 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4565 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4566 case AsmToken::String: // quoted label names.
4567 case AsmToken::Dot: { // . as a branch target
4568 // This was not a register so parse other operands that start with an
4569 // identifier (like labels) as expressions and create them as immediates.
4570 const MCExpr *IdVal;
4571 S = Parser.getTok().getLoc();
4572 if (getParser().parseExpression(IdVal))
4574 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4575 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4578 case AsmToken::LBrac:
4579 return parseMemory(Operands);
4580 case AsmToken::LCurly:
4581 return parseRegisterList(Operands);
4582 case AsmToken::Dollar:
4583 case AsmToken::Hash: {
4584 // #42 -> immediate.
4585 S = Parser.getTok().getLoc();
4588 if (Parser.getTok().isNot(AsmToken::Colon)) {
4589 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4590 const MCExpr *ImmVal;
4591 if (getParser().parseExpression(ImmVal))
4593 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4595 int32_t Val = CE->getValue();
4596 if (isNegative && Val == 0)
4597 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4599 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4600 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4602 // There can be a trailing '!' on operands that we want as a separate
4603 // '!' Token operand. Handle that here. For example, the compatibilty
4604 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4605 if (Parser.getTok().is(AsmToken::Exclaim)) {
4606 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4607 Parser.getTok().getLoc()));
4608 Parser.Lex(); // Eat exclaim token
4612 // w/ a ':' after the '#', it's just like a plain ':'.
4615 case AsmToken::Colon: {
4616 // ":lower16:" and ":upper16:" expression prefixes
4617 // FIXME: Check it's an expression prefix,
4618 // e.g. (FOO - :lower16:BAR) isn't legal.
4619 ARMMCExpr::VariantKind RefKind;
4620 if (parsePrefix(RefKind))
4623 const MCExpr *SubExprVal;
4624 if (getParser().parseExpression(SubExprVal))
4627 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4629 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4630 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4636 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4637 // :lower16: and :upper16:.
4638 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4639 RefKind = ARMMCExpr::VK_ARM_None;
4641 // :lower16: and :upper16: modifiers
4642 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4643 Parser.Lex(); // Eat ':'
4645 if (getLexer().isNot(AsmToken::Identifier)) {
4646 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4650 StringRef IDVal = Parser.getTok().getIdentifier();
4651 if (IDVal == "lower16") {
4652 RefKind = ARMMCExpr::VK_ARM_LO16;
4653 } else if (IDVal == "upper16") {
4654 RefKind = ARMMCExpr::VK_ARM_HI16;
4656 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4661 if (getLexer().isNot(AsmToken::Colon)) {
4662 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4665 Parser.Lex(); // Eat the last ':'
4669 /// \brief Given a mnemonic, split out possible predication code and carry
4670 /// setting letters to form a canonical mnemonic and flags.
4672 // FIXME: Would be nice to autogen this.
4673 // FIXME: This is a bit of a maze of special cases.
4674 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4675 unsigned &PredicationCode,
4677 unsigned &ProcessorIMod,
4678 StringRef &ITMask) {
4679 PredicationCode = ARMCC::AL;
4680 CarrySetting = false;
4683 // Ignore some mnemonics we know aren't predicated forms.
4685 // FIXME: Would be nice to autogen this.
4686 if ((Mnemonic == "movs" && isThumb()) ||
4687 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4688 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4689 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4690 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4691 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
4692 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4693 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4694 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4695 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4696 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4697 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4698 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4701 // First, split out any predication code. Ignore mnemonics we know aren't
4702 // predicated but do have a carry-set and so weren't caught above.
4703 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4704 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4705 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4706 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4707 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4708 .Case("eq", ARMCC::EQ)
4709 .Case("ne", ARMCC::NE)
4710 .Case("hs", ARMCC::HS)
4711 .Case("cs", ARMCC::HS)
4712 .Case("lo", ARMCC::LO)
4713 .Case("cc", ARMCC::LO)
4714 .Case("mi", ARMCC::MI)
4715 .Case("pl", ARMCC::PL)
4716 .Case("vs", ARMCC::VS)
4717 .Case("vc", ARMCC::VC)
4718 .Case("hi", ARMCC::HI)
4719 .Case("ls", ARMCC::LS)
4720 .Case("ge", ARMCC::GE)
4721 .Case("lt", ARMCC::LT)
4722 .Case("gt", ARMCC::GT)
4723 .Case("le", ARMCC::LE)
4724 .Case("al", ARMCC::AL)
4727 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4728 PredicationCode = CC;
4732 // Next, determine if we have a carry setting bit. We explicitly ignore all
4733 // the instructions we know end in 's'.
4734 if (Mnemonic.endswith("s") &&
4735 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4736 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4737 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4738 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4739 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4740 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4741 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4742 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4743 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4744 (Mnemonic == "movs" && isThumb()))) {
4745 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4746 CarrySetting = true;
4749 // The "cps" instruction can have a interrupt mode operand which is glued into
4750 // the mnemonic. Check if this is the case, split it and parse the imod op
4751 if (Mnemonic.startswith("cps")) {
4752 // Split out any imod code.
4754 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4755 .Case("ie", ARM_PROC::IE)
4756 .Case("id", ARM_PROC::ID)
4759 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4760 ProcessorIMod = IMod;
4764 // The "it" instruction has the condition mask on the end of the mnemonic.
4765 if (Mnemonic.startswith("it")) {
4766 ITMask = Mnemonic.slice(2, Mnemonic.size());
4767 Mnemonic = Mnemonic.slice(0, 2);
4773 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4774 /// inclusion of carry set or predication code operands.
4776 // FIXME: It would be nice to autogen this.
4778 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4779 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
4780 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4781 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4782 Mnemonic == "add" || Mnemonic == "adc" ||
4783 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4784 Mnemonic == "orr" || Mnemonic == "mvn" ||
4785 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4786 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4787 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4788 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4789 Mnemonic == "mla" || Mnemonic == "smlal" ||
4790 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4791 CanAcceptCarrySet = true;
4793 CanAcceptCarrySet = false;
4795 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4796 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4797 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
4798 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4799 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4800 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4801 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4802 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4803 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4804 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
4805 // These mnemonics are never predicable
4806 CanAcceptPredicationCode = false;
4807 } else if (!isThumb()) {
4808 // Some instructions are only predicable in Thumb mode
4809 CanAcceptPredicationCode
4810 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4811 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4812 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4813 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4814 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4815 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4816 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4817 } else if (isThumbOne()) {
4819 CanAcceptPredicationCode = Mnemonic != "movs";
4821 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4823 CanAcceptPredicationCode = true;
4826 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4827 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4828 // FIXME: This is all horribly hacky. We really need a better way to deal
4829 // with optional operands like this in the matcher table.
4831 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4832 // another does not. Specifically, the MOVW instruction does not. So we
4833 // special case it here and remove the defaulted (non-setting) cc_out
4834 // operand if that's the instruction we're trying to match.
4836 // We do this as post-processing of the explicit operands rather than just
4837 // conditionally adding the cc_out in the first place because we need
4838 // to check the type of the parsed immediate operand.
4839 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4840 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4841 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4842 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4845 // Register-register 'add' for thumb does not have a cc_out operand
4846 // when there are only two register operands.
4847 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4848 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4849 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4850 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4852 // Register-register 'add' for thumb does not have a cc_out operand
4853 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4854 // have to check the immediate range here since Thumb2 has a variant
4855 // that can handle a different range and has a cc_out operand.
4856 if (((isThumb() && Mnemonic == "add") ||
4857 (isThumbTwo() && Mnemonic == "sub")) &&
4858 Operands.size() == 6 &&
4859 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4860 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4861 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4862 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4863 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4864 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4866 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4867 // imm0_4095 variant. That's the least-preferred variant when
4868 // selecting via the generic "add" mnemonic, so to know that we
4869 // should remove the cc_out operand, we have to explicitly check that
4870 // it's not one of the other variants. Ugh.
4871 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4872 Operands.size() == 6 &&
4873 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4874 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4875 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4876 // Nest conditions rather than one big 'if' statement for readability.
4878 // If both registers are low, we're in an IT block, and the immediate is
4879 // in range, we should use encoding T1 instead, which has a cc_out.
4881 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4882 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4883 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4885 // Check against T3. If the second register is the PC, this is an
4886 // alternate form of ADR, which uses encoding T4, so check for that too.
4887 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4888 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4891 // Otherwise, we use encoding T4, which does not have a cc_out
4896 // The thumb2 multiply instruction doesn't have a CCOut register, so
4897 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4898 // use the 16-bit encoding or not.
4899 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4900 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4901 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4902 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4903 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4904 // If the registers aren't low regs, the destination reg isn't the
4905 // same as one of the source regs, or the cc_out operand is zero
4906 // outside of an IT block, we have to use the 32-bit encoding, so
4907 // remove the cc_out operand.
4908 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4909 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4910 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4912 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4913 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4914 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4915 static_cast<ARMOperand*>(Operands[4])->getReg())))
4918 // Also check the 'mul' syntax variant that doesn't specify an explicit
4919 // destination register.
4920 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4921 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4922 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4923 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4924 // If the registers aren't low regs or the cc_out operand is zero
4925 // outside of an IT block, we have to use the 32-bit encoding, so
4926 // remove the cc_out operand.
4927 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4928 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4934 // Register-register 'add/sub' for thumb does not have a cc_out operand
4935 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4936 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4937 // right, this will result in better diagnostics (which operand is off)
4939 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4940 (Operands.size() == 5 || Operands.size() == 6) &&
4941 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4942 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4943 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4944 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4945 (Operands.size() == 6 &&
4946 static_cast<ARMOperand*>(Operands[5])->isImm())))
4952 bool ARMAsmParser::shouldOmitPredicateOperand(
4953 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4954 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4955 unsigned RegIdx = 3;
4956 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4957 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4958 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4959 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4962 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4963 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4964 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4965 ARMMCRegisterClasses[ARM::QPRRegClassID]
4966 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4972 static bool isDataTypeToken(StringRef Tok) {
4973 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4974 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4975 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4976 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4977 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4978 Tok == ".f" || Tok == ".d";
4981 // FIXME: This bit should probably be handled via an explicit match class
4982 // in the .td files that matches the suffix instead of having it be
4983 // a literal string token the way it is now.
4984 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4985 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4987 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4988 unsigned VariantID);
4989 /// Parse an arm instruction mnemonic followed by its operands.
4990 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4992 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4993 // Apply mnemonic aliases before doing anything else, as the destination
4994 // mnemnonic may include suffices and we want to handle them normally.
4995 // The generic tblgen'erated code does this later, at the start of
4996 // MatchInstructionImpl(), but that's too late for aliases that include
4997 // any sort of suffix.
4998 unsigned AvailableFeatures = getAvailableFeatures();
4999 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5000 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5002 // First check for the ARM-specific .req directive.
5003 if (Parser.getTok().is(AsmToken::Identifier) &&
5004 Parser.getTok().getIdentifier() == ".req") {
5005 parseDirectiveReq(Name, NameLoc);
5006 // We always return 'error' for this, as we're done with this
5007 // statement and don't need to match the 'instruction."
5011 // Create the leading tokens for the mnemonic, split by '.' characters.
5012 size_t Start = 0, Next = Name.find('.');
5013 StringRef Mnemonic = Name.slice(Start, Next);
5015 // Split out the predication code and carry setting flag from the mnemonic.
5016 unsigned PredicationCode;
5017 unsigned ProcessorIMod;
5020 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5021 ProcessorIMod, ITMask);
5023 // In Thumb1, only the branch (B) instruction can be predicated.
5024 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5025 Parser.eatToEndOfStatement();
5026 return Error(NameLoc, "conditional execution not supported in Thumb1");
5029 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5031 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5032 // is the mask as it will be for the IT encoding if the conditional
5033 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5034 // where the conditional bit0 is zero, the instruction post-processing
5035 // will adjust the mask accordingly.
5036 if (Mnemonic == "it") {
5037 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5038 if (ITMask.size() > 3) {
5039 Parser.eatToEndOfStatement();
5040 return Error(Loc, "too many conditions on IT instruction");
5043 for (unsigned i = ITMask.size(); i != 0; --i) {
5044 char pos = ITMask[i - 1];
5045 if (pos != 't' && pos != 'e') {
5046 Parser.eatToEndOfStatement();
5047 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5050 if (ITMask[i - 1] == 't')
5053 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5056 // FIXME: This is all a pretty gross hack. We should automatically handle
5057 // optional operands like this via tblgen.
5059 // Next, add the CCOut and ConditionCode operands, if needed.
5061 // For mnemonics which can ever incorporate a carry setting bit or predication
5062 // code, our matching model involves us always generating CCOut and
5063 // ConditionCode operands to match the mnemonic "as written" and then we let
5064 // the matcher deal with finding the right instruction or generating an
5065 // appropriate error.
5066 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5067 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5069 // If we had a carry-set on an instruction that can't do that, issue an
5071 if (!CanAcceptCarrySet && CarrySetting) {
5072 Parser.eatToEndOfStatement();
5073 return Error(NameLoc, "instruction '" + Mnemonic +
5074 "' can not set flags, but 's' suffix specified");
5076 // If we had a predication code on an instruction that can't do that, issue an
5078 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5079 Parser.eatToEndOfStatement();
5080 return Error(NameLoc, "instruction '" + Mnemonic +
5081 "' is not predicable, but condition code specified");
5084 // Add the carry setting operand, if necessary.
5085 if (CanAcceptCarrySet) {
5086 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5087 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5091 // Add the predication code operand, if necessary.
5092 if (CanAcceptPredicationCode) {
5093 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5095 Operands.push_back(ARMOperand::CreateCondCode(
5096 ARMCC::CondCodes(PredicationCode), Loc));
5099 // Add the processor imod operand, if necessary.
5100 if (ProcessorIMod) {
5101 Operands.push_back(ARMOperand::CreateImm(
5102 MCConstantExpr::Create(ProcessorIMod, getContext()),
5106 // Add the remaining tokens in the mnemonic.
5107 while (Next != StringRef::npos) {
5109 Next = Name.find('.', Start + 1);
5110 StringRef ExtraToken = Name.slice(Start, Next);
5112 // Some NEON instructions have an optional datatype suffix that is
5113 // completely ignored. Check for that.
5114 if (isDataTypeToken(ExtraToken) &&
5115 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5118 // For for ARM mode generate an error if the .n qualifier is used.
5119 if (ExtraToken == ".n" && !isThumb()) {
5120 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5121 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5125 // The .n qualifier is always discarded as that is what the tables
5126 // and matcher expect. In ARM mode the .w qualifier has no effect,
5127 // so discard it to avoid errors that can be caused by the matcher.
5128 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5129 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5130 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5134 // Read the remaining operands.
5135 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5136 // Read the first operand.
5137 if (parseOperand(Operands, Mnemonic)) {
5138 Parser.eatToEndOfStatement();
5142 while (getLexer().is(AsmToken::Comma)) {
5143 Parser.Lex(); // Eat the comma.
5145 // Parse and remember the operand.
5146 if (parseOperand(Operands, Mnemonic)) {
5147 Parser.eatToEndOfStatement();
5153 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5154 SMLoc Loc = getLexer().getLoc();
5155 Parser.eatToEndOfStatement();
5156 return Error(Loc, "unexpected token in argument list");
5159 Parser.Lex(); // Consume the EndOfStatement
5161 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5162 // do and don't have a cc_out optional-def operand. With some spot-checks
5163 // of the operand list, we can figure out which variant we're trying to
5164 // parse and adjust accordingly before actually matching. We shouldn't ever
5165 // try to remove a cc_out operand that was explicitly set on the the
5166 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5167 // table driven matcher doesn't fit well with the ARM instruction set.
5168 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5169 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5170 Operands.erase(Operands.begin() + 1);
5174 // Some instructions have the same mnemonic, but don't always
5175 // have a predicate. Distinguish them here and delete the
5176 // predicate if needed.
5177 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5178 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5179 Operands.erase(Operands.begin() + 1);
5183 // ARM mode 'blx' need special handling, as the register operand version
5184 // is predicable, but the label operand version is not. So, we can't rely
5185 // on the Mnemonic based checking to correctly figure out when to put
5186 // a k_CondCode operand in the list. If we're trying to match the label
5187 // version, remove the k_CondCode operand here.
5188 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5189 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5190 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5191 Operands.erase(Operands.begin() + 1);
5195 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5196 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5197 // a single GPRPair reg operand is used in the .td file to replace the two
5198 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5199 // expressed as a GPRPair, so we have to manually merge them.
5200 // FIXME: We would really like to be able to tablegen'erate this.
5201 if (!isThumb() && Operands.size() > 4 &&
5202 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5203 Mnemonic == "stlexd")) {
5204 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5205 unsigned Idx = isLoad ? 2 : 3;
5206 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5207 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5209 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5210 // Adjust only if Op1 and Op2 are GPRs.
5211 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5212 MRC.contains(Op2->getReg())) {
5213 unsigned Reg1 = Op1->getReg();
5214 unsigned Reg2 = Op2->getReg();
5215 unsigned Rt = MRI->getEncodingValue(Reg1);
5216 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5218 // Rt2 must be Rt + 1 and Rt must be even.
5219 if (Rt + 1 != Rt2 || (Rt & 1)) {
5220 Error(Op2->getStartLoc(), isLoad ?
5221 "destination operands must be sequential" :
5222 "source operands must be sequential");
5225 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5226 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5227 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5228 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5229 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5235 // FIXME: As said above, this is all a pretty gross hack. This instruction
5236 // does not fit with other "subs" and tblgen.
5237 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5238 // so the Mnemonic is the original name "subs" and delete the predicate
5239 // operand so it will match the table entry.
5240 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5241 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5242 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5243 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5244 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5245 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5246 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5247 Operands.erase(Operands.begin());
5249 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5251 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5252 Operands.erase(Operands.begin() + 1);
5258 // Validate context-sensitive operand constraints.
5260 // return 'true' if register list contains non-low GPR registers,
5261 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5262 // 'containsReg' to true.
5263 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5264 unsigned HiReg, bool &containsReg) {
5265 containsReg = false;
5266 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5267 unsigned OpReg = Inst.getOperand(i).getReg();
5270 // Anything other than a low register isn't legal here.
5271 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5277 // Check if the specified regisgter is in the register list of the inst,
5278 // starting at the indicated operand number.
5279 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5280 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5281 unsigned OpReg = Inst.getOperand(i).getReg();
5288 // Return true if instruction has the interesting property of being
5289 // allowed in IT blocks, but not being predicable.
5290 static bool instIsBreakpoint(const MCInst &Inst) {
5291 return Inst.getOpcode() == ARM::tBKPT ||
5292 Inst.getOpcode() == ARM::BKPT ||
5293 Inst.getOpcode() == ARM::tHLT ||
5294 Inst.getOpcode() == ARM::HLT;
5298 // FIXME: We would really like to be able to tablegen'erate this.
5300 validateInstruction(MCInst &Inst,
5301 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5302 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5303 SMLoc Loc = Operands[0]->getStartLoc();
5305 // Check the IT block state first.
5306 // NOTE: BKPT and HLT instructions have the interesting property of being
5307 // allowed in IT blocks, but not being predicable. They just always execute.
5308 if (inITBlock() && !instIsBreakpoint(Inst)) {
5310 if (ITState.FirstCond)
5311 ITState.FirstCond = false;
5313 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5314 // The instruction must be predicable.
5315 if (!MCID.isPredicable())
5316 return Error(Loc, "instructions in IT block must be predicable");
5317 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5318 unsigned ITCond = Bit ? ITState.Cond :
5319 ARMCC::getOppositeCondition(ITState.Cond);
5320 if (Cond != ITCond) {
5321 // Find the condition code Operand to get its SMLoc information.
5323 for (unsigned I = 1; I < Operands.size(); ++I)
5324 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5325 CondLoc = Operands[I]->getStartLoc();
5326 return Error(CondLoc, "incorrect condition in IT block; got '" +
5327 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5328 "', but expected '" +
5329 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5331 // Check for non-'al' condition codes outside of the IT block.
5332 } else if (isThumbTwo() && MCID.isPredicable() &&
5333 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5334 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5335 Inst.getOpcode() != ARM::t2Bcc)
5336 return Error(Loc, "predicated instructions must be in IT block");
5338 const unsigned Opcode = Inst.getOpcode();
5342 case ARM::LDRD_POST: {
5343 const unsigned RtReg = Inst.getOperand(0).getReg();
5346 if (RtReg == ARM::LR)
5347 return Error(Operands[3]->getStartLoc(),
5350 const unsigned Rt = MRI->getEncodingValue(RtReg);
5351 // Rt must be even-numbered.
5353 return Error(Operands[3]->getStartLoc(),
5354 "Rt must be even-numbered");
5356 // Rt2 must be Rt + 1.
5357 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5359 return Error(Operands[3]->getStartLoc(),
5360 "destination operands must be sequential");
5362 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5363 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5364 // For addressing modes with writeback, the base register needs to be
5365 // different from the destination registers.
5366 if (Rn == Rt || Rn == Rt2)
5367 return Error(Operands[3]->getStartLoc(),
5368 "base register needs to be different from destination "
5375 case ARM::t2LDRD_PRE:
5376 case ARM::t2LDRD_POST: {
5377 // Rt2 must be different from Rt.
5378 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5379 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5381 return Error(Operands[3]->getStartLoc(),
5382 "destination operands can't be identical");
5386 // Rt2 must be Rt + 1.
5387 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5388 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5390 return Error(Operands[3]->getStartLoc(),
5391 "source operands must be sequential");
5395 case ARM::STRD_POST: {
5396 // Rt2 must be Rt + 1.
5397 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5398 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5400 return Error(Operands[3]->getStartLoc(),
5401 "source operands must be sequential");
5406 // Width must be in range [1, 32-lsb].
5407 unsigned LSB = Inst.getOperand(2).getImm();
5408 unsigned Widthm1 = Inst.getOperand(3).getImm();
5409 if (Widthm1 >= 32 - LSB)
5410 return Error(Operands[5]->getStartLoc(),
5411 "bitfield width must be in range [1,32-lsb]");
5415 // If we're parsing Thumb2, the .w variant is available and handles
5416 // most cases that are normally illegal for a Thumb1 LDM instruction.
5417 // We'll make the transformation in processInstruction() if necessary.
5419 // Thumb LDM instructions are writeback iff the base register is not
5420 // in the register list.
5421 unsigned Rn = Inst.getOperand(0).getReg();
5422 bool HasWritebackToken =
5423 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5424 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5425 bool ListContainsBase;
5426 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5427 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
5428 "registers must be in range r0-r7");
5429 // If we should have writeback, then there should be a '!' token.
5430 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
5431 return Error(Operands[2]->getStartLoc(),
5432 "writeback operator '!' expected");
5433 // If we should not have writeback, there must not be a '!'. This is
5434 // true even for the 32-bit wide encodings.
5435 if (ListContainsBase && HasWritebackToken)
5436 return Error(Operands[3]->getStartLoc(),
5437 "writeback operator '!' not allowed when base register "
5438 "in register list");
5442 case ARM::t2LDMIA_UPD: {
5443 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5444 return Error(Operands[4]->getStartLoc(),
5445 "writeback operator '!' not allowed when base register "
5446 "in register list");
5450 // The second source operand must be the same register as the destination
5453 // In this case, we must directly check the parsed operands because the
5454 // cvtThumbMultiply() function is written in such a way that it guarantees
5455 // this first statement is always true for the new Inst. Essentially, the
5456 // destination is unconditionally copied into the second source operand
5457 // without checking to see if it matches what we actually parsed.
5458 if (Operands.size() == 6 &&
5459 (((ARMOperand*)Operands[3])->getReg() !=
5460 ((ARMOperand*)Operands[5])->getReg()) &&
5461 (((ARMOperand*)Operands[3])->getReg() !=
5462 ((ARMOperand*)Operands[4])->getReg())) {
5463 return Error(Operands[3]->getStartLoc(),
5464 "destination register must match source register");
5468 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5469 // so only issue a diagnostic for thumb1. The instructions will be
5470 // switched to the t2 encodings in processInstruction() if necessary.
5472 bool ListContainsBase;
5473 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
5475 return Error(Operands[2]->getStartLoc(),
5476 "registers must be in range r0-r7 or pc");
5480 bool ListContainsBase;
5481 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
5483 return Error(Operands[2]->getStartLoc(),
5484 "registers must be in range r0-r7 or lr");
5487 case ARM::tSTMIA_UPD: {
5488 bool ListContainsBase;
5489 if (checkLowRegisterList(Inst, 4, 0, 0, ListContainsBase) && !isThumbTwo())
5490 return Error(Operands[4]->getStartLoc(),
5491 "registers must be in range r0-r7");
5494 case ARM::tADDrSP: {
5495 // If the non-SP source operand and the destination operand are not the
5496 // same, we need thumb2 (for the wide encoding), or we have an error.
5497 if (!isThumbTwo() &&
5498 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5499 return Error(Operands[4]->getStartLoc(),
5500 "source register must be the same as destination");
5504 // Final range checking for Thumb unconditional branch instructions.
5506 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5507 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5510 int op = (Operands[2]->isImm()) ? 2 : 3;
5511 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5512 return Error(Operands[op]->getStartLoc(), "branch target out of range");
5515 // Final range checking for Thumb conditional branch instructions.
5517 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5518 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5521 int Op = (Operands[2]->isImm()) ? 2 : 3;
5522 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5523 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
5531 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5533 default: llvm_unreachable("unexpected opcode!");
5535 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5536 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5537 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5538 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5539 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5540 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5541 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5542 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5543 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5546 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5547 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5548 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5549 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5550 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5552 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5553 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5554 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5555 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5556 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5558 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5559 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5560 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5561 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5562 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5565 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5566 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5567 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5568 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5569 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5570 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5571 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5572 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5573 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5574 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5575 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5576 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5577 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5578 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5579 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5582 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5583 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5584 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5585 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5586 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5587 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5588 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5589 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5590 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5591 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5592 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5593 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5594 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5595 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5596 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5597 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5598 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5599 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5602 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5603 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5604 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5605 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5606 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5607 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5608 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5609 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5610 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5611 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5612 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5613 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5614 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5615 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5616 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5619 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5620 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5621 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5622 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5623 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5624 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5625 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5626 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5627 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5628 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5629 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5630 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5631 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5632 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5633 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5634 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5635 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5636 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5640 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5642 default: llvm_unreachable("unexpected opcode!");
5644 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5645 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5646 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5647 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5648 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5649 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5650 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5651 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5652 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5655 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5656 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5657 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5658 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5659 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5660 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5661 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5662 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5663 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5664 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5665 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5666 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5667 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5668 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5669 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5672 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5673 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5674 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5675 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5676 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5677 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5678 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5679 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5680 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5681 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5682 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5683 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5684 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5685 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5686 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5687 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5688 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5689 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5692 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5693 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5694 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5695 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5696 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5697 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5698 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5699 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5700 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5701 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5702 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5703 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5704 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5705 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5706 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5709 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5710 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5711 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5712 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5713 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5714 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5715 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5716 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5717 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5718 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5719 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5720 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5721 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5722 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5723 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5724 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5725 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5726 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5729 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5730 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5731 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5732 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5733 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5734 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5735 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5736 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5737 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5738 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5739 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5740 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5741 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5742 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5743 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5746 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5747 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5748 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5749 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5750 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5751 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5752 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5753 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5754 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5755 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5756 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5757 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5758 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5759 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5760 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5761 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5762 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5763 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5766 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5767 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5768 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5769 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5770 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5771 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5772 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5773 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5774 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5775 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5776 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5777 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5778 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5779 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5780 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5781 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5782 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5783 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5788 processInstruction(MCInst &Inst,
5789 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5790 switch (Inst.getOpcode()) {
5791 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5793 if (Inst.getOperand(1).getReg() != ARM::PC ||
5794 Inst.getOperand(5).getReg() != 0)
5797 TmpInst.setOpcode(ARM::ADR);
5798 TmpInst.addOperand(Inst.getOperand(0));
5799 TmpInst.addOperand(Inst.getOperand(2));
5800 TmpInst.addOperand(Inst.getOperand(3));
5801 TmpInst.addOperand(Inst.getOperand(4));
5805 // Aliases for alternate PC+imm syntax of LDR instructions.
5806 case ARM::t2LDRpcrel:
5807 // Select the narrow version if the immediate will fit.
5808 if (Inst.getOperand(1).getImm() > 0 &&
5809 Inst.getOperand(1).getImm() <= 0xff &&
5810 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5811 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
5812 Inst.setOpcode(ARM::tLDRpci);
5814 Inst.setOpcode(ARM::t2LDRpci);
5816 case ARM::t2LDRBpcrel:
5817 Inst.setOpcode(ARM::t2LDRBpci);
5819 case ARM::t2LDRHpcrel:
5820 Inst.setOpcode(ARM::t2LDRHpci);
5822 case ARM::t2LDRSBpcrel:
5823 Inst.setOpcode(ARM::t2LDRSBpci);
5825 case ARM::t2LDRSHpcrel:
5826 Inst.setOpcode(ARM::t2LDRSHpci);
5828 // Handle NEON VST complex aliases.
5829 case ARM::VST1LNdWB_register_Asm_8:
5830 case ARM::VST1LNdWB_register_Asm_16:
5831 case ARM::VST1LNdWB_register_Asm_32: {
5833 // Shuffle the operands around so the lane index operand is in the
5836 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5837 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5838 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5839 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5840 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5841 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5842 TmpInst.addOperand(Inst.getOperand(1)); // lane
5843 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5844 TmpInst.addOperand(Inst.getOperand(6));
5849 case ARM::VST2LNdWB_register_Asm_8:
5850 case ARM::VST2LNdWB_register_Asm_16:
5851 case ARM::VST2LNdWB_register_Asm_32:
5852 case ARM::VST2LNqWB_register_Asm_16:
5853 case ARM::VST2LNqWB_register_Asm_32: {
5855 // Shuffle the operands around so the lane index operand is in the
5858 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5859 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5860 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5861 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5862 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5863 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5866 TmpInst.addOperand(Inst.getOperand(1)); // lane
5867 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5868 TmpInst.addOperand(Inst.getOperand(6));
5873 case ARM::VST3LNdWB_register_Asm_8:
5874 case ARM::VST3LNdWB_register_Asm_16:
5875 case ARM::VST3LNdWB_register_Asm_32:
5876 case ARM::VST3LNqWB_register_Asm_16:
5877 case ARM::VST3LNqWB_register_Asm_32: {
5879 // Shuffle the operands around so the lane index operand is in the
5882 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5883 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5884 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5885 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5886 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5887 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5888 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5890 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5892 TmpInst.addOperand(Inst.getOperand(1)); // lane
5893 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5894 TmpInst.addOperand(Inst.getOperand(6));
5899 case ARM::VST4LNdWB_register_Asm_8:
5900 case ARM::VST4LNdWB_register_Asm_16:
5901 case ARM::VST4LNdWB_register_Asm_32:
5902 case ARM::VST4LNqWB_register_Asm_16:
5903 case ARM::VST4LNqWB_register_Asm_32: {
5905 // Shuffle the operands around so the lane index operand is in the
5908 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5909 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5910 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5911 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5912 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5913 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5914 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5916 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5918 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5920 TmpInst.addOperand(Inst.getOperand(1)); // lane
5921 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5922 TmpInst.addOperand(Inst.getOperand(6));
5927 case ARM::VST1LNdWB_fixed_Asm_8:
5928 case ARM::VST1LNdWB_fixed_Asm_16:
5929 case ARM::VST1LNdWB_fixed_Asm_32: {
5931 // Shuffle the operands around so the lane index operand is in the
5934 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5935 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5936 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5937 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5938 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5939 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5940 TmpInst.addOperand(Inst.getOperand(1)); // lane
5941 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5942 TmpInst.addOperand(Inst.getOperand(5));
5947 case ARM::VST2LNdWB_fixed_Asm_8:
5948 case ARM::VST2LNdWB_fixed_Asm_16:
5949 case ARM::VST2LNdWB_fixed_Asm_32:
5950 case ARM::VST2LNqWB_fixed_Asm_16:
5951 case ARM::VST2LNqWB_fixed_Asm_32: {
5953 // Shuffle the operands around so the lane index operand is in the
5956 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5957 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5958 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5959 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5960 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5961 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5962 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5964 TmpInst.addOperand(Inst.getOperand(1)); // lane
5965 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5966 TmpInst.addOperand(Inst.getOperand(5));
5971 case ARM::VST3LNdWB_fixed_Asm_8:
5972 case ARM::VST3LNdWB_fixed_Asm_16:
5973 case ARM::VST3LNdWB_fixed_Asm_32:
5974 case ARM::VST3LNqWB_fixed_Asm_16:
5975 case ARM::VST3LNqWB_fixed_Asm_32: {
5977 // Shuffle the operands around so the lane index operand is in the
5980 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5981 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5982 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5983 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5984 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5985 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5986 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5988 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5990 TmpInst.addOperand(Inst.getOperand(1)); // lane
5991 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5992 TmpInst.addOperand(Inst.getOperand(5));
5997 case ARM::VST4LNdWB_fixed_Asm_8:
5998 case ARM::VST4LNdWB_fixed_Asm_16:
5999 case ARM::VST4LNdWB_fixed_Asm_32:
6000 case ARM::VST4LNqWB_fixed_Asm_16:
6001 case ARM::VST4LNqWB_fixed_Asm_32: {
6003 // Shuffle the operands around so the lane index operand is in the
6006 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6007 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6008 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6009 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6010 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6011 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6012 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6014 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6018 TmpInst.addOperand(Inst.getOperand(1)); // lane
6019 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6020 TmpInst.addOperand(Inst.getOperand(5));
6025 case ARM::VST1LNdAsm_8:
6026 case ARM::VST1LNdAsm_16:
6027 case ARM::VST1LNdAsm_32: {
6029 // Shuffle the operands around so the lane index operand is in the
6032 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6033 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6034 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6035 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6036 TmpInst.addOperand(Inst.getOperand(1)); // lane
6037 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6038 TmpInst.addOperand(Inst.getOperand(5));
6043 case ARM::VST2LNdAsm_8:
6044 case ARM::VST2LNdAsm_16:
6045 case ARM::VST2LNdAsm_32:
6046 case ARM::VST2LNqAsm_16:
6047 case ARM::VST2LNqAsm_32: {
6049 // Shuffle the operands around so the lane index operand is in the
6052 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6053 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6054 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6055 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6056 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6058 TmpInst.addOperand(Inst.getOperand(1)); // lane
6059 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6060 TmpInst.addOperand(Inst.getOperand(5));
6065 case ARM::VST3LNdAsm_8:
6066 case ARM::VST3LNdAsm_16:
6067 case ARM::VST3LNdAsm_32:
6068 case ARM::VST3LNqAsm_16:
6069 case ARM::VST3LNqAsm_32: {
6071 // Shuffle the operands around so the lane index operand is in the
6074 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6075 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6076 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6077 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6078 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6082 TmpInst.addOperand(Inst.getOperand(1)); // lane
6083 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6084 TmpInst.addOperand(Inst.getOperand(5));
6089 case ARM::VST4LNdAsm_8:
6090 case ARM::VST4LNdAsm_16:
6091 case ARM::VST4LNdAsm_32:
6092 case ARM::VST4LNqAsm_16:
6093 case ARM::VST4LNqAsm_32: {
6095 // Shuffle the operands around so the lane index operand is in the
6098 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6099 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6100 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6101 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6102 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6104 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6108 TmpInst.addOperand(Inst.getOperand(1)); // lane
6109 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6110 TmpInst.addOperand(Inst.getOperand(5));
6115 // Handle NEON VLD complex aliases.
6116 case ARM::VLD1LNdWB_register_Asm_8:
6117 case ARM::VLD1LNdWB_register_Asm_16:
6118 case ARM::VLD1LNdWB_register_Asm_32: {
6120 // Shuffle the operands around so the lane index operand is in the
6123 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6124 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6125 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6126 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6127 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6128 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6129 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6130 TmpInst.addOperand(Inst.getOperand(1)); // lane
6131 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6132 TmpInst.addOperand(Inst.getOperand(6));
6137 case ARM::VLD2LNdWB_register_Asm_8:
6138 case ARM::VLD2LNdWB_register_Asm_16:
6139 case ARM::VLD2LNdWB_register_Asm_32:
6140 case ARM::VLD2LNqWB_register_Asm_16:
6141 case ARM::VLD2LNqWB_register_Asm_32: {
6143 // Shuffle the operands around so the lane index operand is in the
6146 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6147 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6148 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6150 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6151 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6152 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6153 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6154 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6155 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6157 TmpInst.addOperand(Inst.getOperand(1)); // lane
6158 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6159 TmpInst.addOperand(Inst.getOperand(6));
6164 case ARM::VLD3LNdWB_register_Asm_8:
6165 case ARM::VLD3LNdWB_register_Asm_16:
6166 case ARM::VLD3LNdWB_register_Asm_32:
6167 case ARM::VLD3LNqWB_register_Asm_16:
6168 case ARM::VLD3LNqWB_register_Asm_32: {
6170 // Shuffle the operands around so the lane index operand is in the
6173 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6174 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6175 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6177 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6179 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6180 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6181 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6182 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6183 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6184 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6186 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6188 TmpInst.addOperand(Inst.getOperand(1)); // lane
6189 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6190 TmpInst.addOperand(Inst.getOperand(6));
6195 case ARM::VLD4LNdWB_register_Asm_8:
6196 case ARM::VLD4LNdWB_register_Asm_16:
6197 case ARM::VLD4LNdWB_register_Asm_32:
6198 case ARM::VLD4LNqWB_register_Asm_16:
6199 case ARM::VLD4LNqWB_register_Asm_32: {
6201 // Shuffle the operands around so the lane index operand is in the
6204 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6205 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6206 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6208 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6210 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6212 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6213 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6214 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6215 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6216 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6217 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6219 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6221 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6223 TmpInst.addOperand(Inst.getOperand(1)); // lane
6224 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6225 TmpInst.addOperand(Inst.getOperand(6));
6230 case ARM::VLD1LNdWB_fixed_Asm_8:
6231 case ARM::VLD1LNdWB_fixed_Asm_16:
6232 case ARM::VLD1LNdWB_fixed_Asm_32: {
6234 // Shuffle the operands around so the lane index operand is in the
6237 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6238 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6239 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6240 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6241 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6242 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6243 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6244 TmpInst.addOperand(Inst.getOperand(1)); // lane
6245 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6246 TmpInst.addOperand(Inst.getOperand(5));
6251 case ARM::VLD2LNdWB_fixed_Asm_8:
6252 case ARM::VLD2LNdWB_fixed_Asm_16:
6253 case ARM::VLD2LNdWB_fixed_Asm_32:
6254 case ARM::VLD2LNqWB_fixed_Asm_16:
6255 case ARM::VLD2LNqWB_fixed_Asm_32: {
6257 // Shuffle the operands around so the lane index operand is in the
6260 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6261 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6262 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6264 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6265 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6266 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6267 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6268 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6269 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6271 TmpInst.addOperand(Inst.getOperand(1)); // lane
6272 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6273 TmpInst.addOperand(Inst.getOperand(5));
6278 case ARM::VLD3LNdWB_fixed_Asm_8:
6279 case ARM::VLD3LNdWB_fixed_Asm_16:
6280 case ARM::VLD3LNdWB_fixed_Asm_32:
6281 case ARM::VLD3LNqWB_fixed_Asm_16:
6282 case ARM::VLD3LNqWB_fixed_Asm_32: {
6284 // Shuffle the operands around so the lane index operand is in the
6287 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6288 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6293 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6294 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6295 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6296 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6297 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 TmpInst.addOperand(Inst.getOperand(1)); // lane
6303 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6304 TmpInst.addOperand(Inst.getOperand(5));
6309 case ARM::VLD4LNdWB_fixed_Asm_8:
6310 case ARM::VLD4LNdWB_fixed_Asm_16:
6311 case ARM::VLD4LNdWB_fixed_Asm_32:
6312 case ARM::VLD4LNqWB_fixed_Asm_16:
6313 case ARM::VLD4LNqWB_fixed_Asm_32: {
6315 // Shuffle the operands around so the lane index operand is in the
6318 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6319 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6320 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6322 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6324 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6326 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6327 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6328 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6329 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6330 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6335 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6337 TmpInst.addOperand(Inst.getOperand(1)); // lane
6338 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6339 TmpInst.addOperand(Inst.getOperand(5));
6344 case ARM::VLD1LNdAsm_8:
6345 case ARM::VLD1LNdAsm_16:
6346 case ARM::VLD1LNdAsm_32: {
6348 // Shuffle the operands around so the lane index operand is in the
6351 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6352 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6353 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6354 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6355 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6356 TmpInst.addOperand(Inst.getOperand(1)); // lane
6357 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6358 TmpInst.addOperand(Inst.getOperand(5));
6363 case ARM::VLD2LNdAsm_8:
6364 case ARM::VLD2LNdAsm_16:
6365 case ARM::VLD2LNdAsm_32:
6366 case ARM::VLD2LNqAsm_16:
6367 case ARM::VLD2LNqAsm_32: {
6369 // Shuffle the operands around so the lane index operand is in the
6372 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6373 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6374 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6376 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6377 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6378 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6379 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6381 TmpInst.addOperand(Inst.getOperand(1)); // lane
6382 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6383 TmpInst.addOperand(Inst.getOperand(5));
6388 case ARM::VLD3LNdAsm_8:
6389 case ARM::VLD3LNdAsm_16:
6390 case ARM::VLD3LNdAsm_32:
6391 case ARM::VLD3LNqAsm_16:
6392 case ARM::VLD3LNqAsm_32: {
6394 // Shuffle the operands around so the lane index operand is in the
6397 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6398 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6399 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6401 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6403 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6404 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6405 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6408 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6410 TmpInst.addOperand(Inst.getOperand(1)); // lane
6411 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6412 TmpInst.addOperand(Inst.getOperand(5));
6417 case ARM::VLD4LNdAsm_8:
6418 case ARM::VLD4LNdAsm_16:
6419 case ARM::VLD4LNdAsm_32:
6420 case ARM::VLD4LNqAsm_16:
6421 case ARM::VLD4LNqAsm_32: {
6423 // Shuffle the operands around so the lane index operand is in the
6426 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6427 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6430 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6432 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6434 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6435 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6436 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6437 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6439 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6441 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6443 TmpInst.addOperand(Inst.getOperand(1)); // lane
6444 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6445 TmpInst.addOperand(Inst.getOperand(5));
6450 // VLD3DUP single 3-element structure to all lanes instructions.
6451 case ARM::VLD3DUPdAsm_8:
6452 case ARM::VLD3DUPdAsm_16:
6453 case ARM::VLD3DUPdAsm_32:
6454 case ARM::VLD3DUPqAsm_8:
6455 case ARM::VLD3DUPqAsm_16:
6456 case ARM::VLD3DUPqAsm_32: {
6459 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6460 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6461 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6463 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6465 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6466 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6467 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6468 TmpInst.addOperand(Inst.getOperand(4));
6473 case ARM::VLD3DUPdWB_fixed_Asm_8:
6474 case ARM::VLD3DUPdWB_fixed_Asm_16:
6475 case ARM::VLD3DUPdWB_fixed_Asm_32:
6476 case ARM::VLD3DUPqWB_fixed_Asm_8:
6477 case ARM::VLD3DUPqWB_fixed_Asm_16:
6478 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6481 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6482 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6483 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6485 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6487 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6488 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6489 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6490 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6491 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6492 TmpInst.addOperand(Inst.getOperand(4));
6497 case ARM::VLD3DUPdWB_register_Asm_8:
6498 case ARM::VLD3DUPdWB_register_Asm_16:
6499 case ARM::VLD3DUPdWB_register_Asm_32:
6500 case ARM::VLD3DUPqWB_register_Asm_8:
6501 case ARM::VLD3DUPqWB_register_Asm_16:
6502 case ARM::VLD3DUPqWB_register_Asm_32: {
6505 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6506 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6507 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6509 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6511 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6512 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6513 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6514 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6515 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6516 TmpInst.addOperand(Inst.getOperand(5));
6521 // VLD3 multiple 3-element structure instructions.
6522 case ARM::VLD3dAsm_8:
6523 case ARM::VLD3dAsm_16:
6524 case ARM::VLD3dAsm_32:
6525 case ARM::VLD3qAsm_8:
6526 case ARM::VLD3qAsm_16:
6527 case ARM::VLD3qAsm_32: {
6530 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6531 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6534 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6536 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6537 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6538 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6539 TmpInst.addOperand(Inst.getOperand(4));
6544 case ARM::VLD3dWB_fixed_Asm_8:
6545 case ARM::VLD3dWB_fixed_Asm_16:
6546 case ARM::VLD3dWB_fixed_Asm_32:
6547 case ARM::VLD3qWB_fixed_Asm_8:
6548 case ARM::VLD3qWB_fixed_Asm_16:
6549 case ARM::VLD3qWB_fixed_Asm_32: {
6552 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6553 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6558 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6559 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6560 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6561 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6562 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6563 TmpInst.addOperand(Inst.getOperand(4));
6568 case ARM::VLD3dWB_register_Asm_8:
6569 case ARM::VLD3dWB_register_Asm_16:
6570 case ARM::VLD3dWB_register_Asm_32:
6571 case ARM::VLD3qWB_register_Asm_8:
6572 case ARM::VLD3qWB_register_Asm_16:
6573 case ARM::VLD3qWB_register_Asm_32: {
6576 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6577 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6578 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6582 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6583 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6584 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6585 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6586 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6587 TmpInst.addOperand(Inst.getOperand(5));
6592 // VLD4DUP single 3-element structure to all lanes instructions.
6593 case ARM::VLD4DUPdAsm_8:
6594 case ARM::VLD4DUPdAsm_16:
6595 case ARM::VLD4DUPdAsm_32:
6596 case ARM::VLD4DUPqAsm_8:
6597 case ARM::VLD4DUPqAsm_16:
6598 case ARM::VLD4DUPqAsm_32: {
6601 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6602 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6603 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6605 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6607 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6609 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6610 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6611 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6612 TmpInst.addOperand(Inst.getOperand(4));
6617 case ARM::VLD4DUPdWB_fixed_Asm_8:
6618 case ARM::VLD4DUPdWB_fixed_Asm_16:
6619 case ARM::VLD4DUPdWB_fixed_Asm_32:
6620 case ARM::VLD4DUPqWB_fixed_Asm_8:
6621 case ARM::VLD4DUPqWB_fixed_Asm_16:
6622 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6625 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6626 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6627 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6629 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6631 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6634 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6635 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6636 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6637 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6638 TmpInst.addOperand(Inst.getOperand(4));
6643 case ARM::VLD4DUPdWB_register_Asm_8:
6644 case ARM::VLD4DUPdWB_register_Asm_16:
6645 case ARM::VLD4DUPdWB_register_Asm_32:
6646 case ARM::VLD4DUPqWB_register_Asm_8:
6647 case ARM::VLD4DUPqWB_register_Asm_16:
6648 case ARM::VLD4DUPqWB_register_Asm_32: {
6651 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6652 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6653 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6659 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6660 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6661 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6662 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6663 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6664 TmpInst.addOperand(Inst.getOperand(5));
6669 // VLD4 multiple 4-element structure instructions.
6670 case ARM::VLD4dAsm_8:
6671 case ARM::VLD4dAsm_16:
6672 case ARM::VLD4dAsm_32:
6673 case ARM::VLD4qAsm_8:
6674 case ARM::VLD4qAsm_16:
6675 case ARM::VLD4qAsm_32: {
6678 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6679 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6680 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6682 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6684 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6686 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6687 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6688 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6689 TmpInst.addOperand(Inst.getOperand(4));
6694 case ARM::VLD4dWB_fixed_Asm_8:
6695 case ARM::VLD4dWB_fixed_Asm_16:
6696 case ARM::VLD4dWB_fixed_Asm_32:
6697 case ARM::VLD4qWB_fixed_Asm_8:
6698 case ARM::VLD4qWB_fixed_Asm_16:
6699 case ARM::VLD4qWB_fixed_Asm_32: {
6702 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6703 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6704 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6706 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6708 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6710 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6711 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6712 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6713 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6714 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6715 TmpInst.addOperand(Inst.getOperand(4));
6720 case ARM::VLD4dWB_register_Asm_8:
6721 case ARM::VLD4dWB_register_Asm_16:
6722 case ARM::VLD4dWB_register_Asm_32:
6723 case ARM::VLD4qWB_register_Asm_8:
6724 case ARM::VLD4qWB_register_Asm_16:
6725 case ARM::VLD4qWB_register_Asm_32: {
6728 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6729 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6730 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6734 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6736 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6737 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6738 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6739 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6740 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6741 TmpInst.addOperand(Inst.getOperand(5));
6746 // VST3 multiple 3-element structure instructions.
6747 case ARM::VST3dAsm_8:
6748 case ARM::VST3dAsm_16:
6749 case ARM::VST3dAsm_32:
6750 case ARM::VST3qAsm_8:
6751 case ARM::VST3qAsm_16:
6752 case ARM::VST3qAsm_32: {
6755 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6756 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6757 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6758 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6761 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6763 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6764 TmpInst.addOperand(Inst.getOperand(4));
6769 case ARM::VST3dWB_fixed_Asm_8:
6770 case ARM::VST3dWB_fixed_Asm_16:
6771 case ARM::VST3dWB_fixed_Asm_32:
6772 case ARM::VST3qWB_fixed_Asm_8:
6773 case ARM::VST3qWB_fixed_Asm_16:
6774 case ARM::VST3qWB_fixed_Asm_32: {
6777 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6778 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6779 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6780 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6781 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6782 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6787 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6788 TmpInst.addOperand(Inst.getOperand(4));
6793 case ARM::VST3dWB_register_Asm_8:
6794 case ARM::VST3dWB_register_Asm_16:
6795 case ARM::VST3dWB_register_Asm_32:
6796 case ARM::VST3qWB_register_Asm_8:
6797 case ARM::VST3qWB_register_Asm_16:
6798 case ARM::VST3qWB_register_Asm_32: {
6801 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6802 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6803 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6804 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6805 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6806 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6809 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6811 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6812 TmpInst.addOperand(Inst.getOperand(5));
6817 // VST4 multiple 3-element structure instructions.
6818 case ARM::VST4dAsm_8:
6819 case ARM::VST4dAsm_16:
6820 case ARM::VST4dAsm_32:
6821 case ARM::VST4qAsm_8:
6822 case ARM::VST4qAsm_16:
6823 case ARM::VST4qAsm_32: {
6826 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6827 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6828 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6829 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6830 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6832 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6834 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6836 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6837 TmpInst.addOperand(Inst.getOperand(4));
6842 case ARM::VST4dWB_fixed_Asm_8:
6843 case ARM::VST4dWB_fixed_Asm_16:
6844 case ARM::VST4dWB_fixed_Asm_32:
6845 case ARM::VST4qWB_fixed_Asm_8:
6846 case ARM::VST4qWB_fixed_Asm_16:
6847 case ARM::VST4qWB_fixed_Asm_32: {
6850 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6851 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6852 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6853 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6854 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6855 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6856 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6862 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6863 TmpInst.addOperand(Inst.getOperand(4));
6868 case ARM::VST4dWB_register_Asm_8:
6869 case ARM::VST4dWB_register_Asm_16:
6870 case ARM::VST4dWB_register_Asm_32:
6871 case ARM::VST4qWB_register_Asm_8:
6872 case ARM::VST4qWB_register_Asm_16:
6873 case ARM::VST4qWB_register_Asm_32: {
6876 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6877 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6878 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6879 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6880 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6881 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6886 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6888 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6889 TmpInst.addOperand(Inst.getOperand(5));
6894 // Handle encoding choice for the shift-immediate instructions.
6897 case ARM::t2ASRri: {
6898 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6899 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6900 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6901 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6902 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6904 switch (Inst.getOpcode()) {
6905 default: llvm_unreachable("unexpected opcode");
6906 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6907 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6908 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6910 // The Thumb1 operands aren't in the same order. Awesome, eh?
6912 TmpInst.setOpcode(NewOpc);
6913 TmpInst.addOperand(Inst.getOperand(0));
6914 TmpInst.addOperand(Inst.getOperand(5));
6915 TmpInst.addOperand(Inst.getOperand(1));
6916 TmpInst.addOperand(Inst.getOperand(2));
6917 TmpInst.addOperand(Inst.getOperand(3));
6918 TmpInst.addOperand(Inst.getOperand(4));
6925 // Handle the Thumb2 mode MOV complex aliases.
6927 case ARM::t2MOVSsr: {
6928 // Which instruction to expand to depends on the CCOut operand and
6929 // whether we're in an IT block if the register operands are low
6931 bool isNarrow = false;
6932 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6933 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6934 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6935 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6936 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6940 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6941 default: llvm_unreachable("unexpected opcode!");
6942 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6943 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6944 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6945 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6947 TmpInst.setOpcode(newOpc);
6948 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6950 TmpInst.addOperand(MCOperand::CreateReg(
6951 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6952 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6953 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6954 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6955 TmpInst.addOperand(Inst.getOperand(5));
6957 TmpInst.addOperand(MCOperand::CreateReg(
6958 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6963 case ARM::t2MOVSsi: {
6964 // Which instruction to expand to depends on the CCOut operand and
6965 // whether we're in an IT block if the register operands are low
6967 bool isNarrow = false;
6968 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6969 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6970 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6974 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6975 default: llvm_unreachable("unexpected opcode!");
6976 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6977 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6978 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6979 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
6980 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
6982 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6983 if (Amount == 32) Amount = 0;
6984 TmpInst.setOpcode(newOpc);
6985 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6987 TmpInst.addOperand(MCOperand::CreateReg(
6988 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6989 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6990 if (newOpc != ARM::t2RRX)
6991 TmpInst.addOperand(MCOperand::CreateImm(Amount));
6992 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6993 TmpInst.addOperand(Inst.getOperand(4));
6995 TmpInst.addOperand(MCOperand::CreateReg(
6996 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7000 // Handle the ARM mode MOV complex aliases.
7005 ARM_AM::ShiftOpc ShiftTy;
7006 switch(Inst.getOpcode()) {
7007 default: llvm_unreachable("unexpected opcode!");
7008 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7009 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7010 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7011 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7013 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7015 TmpInst.setOpcode(ARM::MOVsr);
7016 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7017 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7018 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7019 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7020 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7021 TmpInst.addOperand(Inst.getOperand(4));
7022 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7030 ARM_AM::ShiftOpc ShiftTy;
7031 switch(Inst.getOpcode()) {
7032 default: llvm_unreachable("unexpected opcode!");
7033 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7034 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7035 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7036 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7038 // A shift by zero is a plain MOVr, not a MOVsi.
7039 unsigned Amt = Inst.getOperand(2).getImm();
7040 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7041 // A shift by 32 should be encoded as 0 when permitted
7042 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7044 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7046 TmpInst.setOpcode(Opc);
7047 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7048 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7049 if (Opc == ARM::MOVsi)
7050 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7051 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7052 TmpInst.addOperand(Inst.getOperand(4));
7053 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7058 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7060 TmpInst.setOpcode(ARM::MOVsi);
7061 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7062 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7063 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7064 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7065 TmpInst.addOperand(Inst.getOperand(3));
7066 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7070 case ARM::t2LDMIA_UPD: {
7071 // If this is a load of a single register, then we should use
7072 // a post-indexed LDR instruction instead, per the ARM ARM.
7073 if (Inst.getNumOperands() != 5)
7076 TmpInst.setOpcode(ARM::t2LDR_POST);
7077 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7078 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7079 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7080 TmpInst.addOperand(MCOperand::CreateImm(4));
7081 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7082 TmpInst.addOperand(Inst.getOperand(3));
7086 case ARM::t2STMDB_UPD: {
7087 // If this is a store of a single register, then we should use
7088 // a pre-indexed STR instruction instead, per the ARM ARM.
7089 if (Inst.getNumOperands() != 5)
7092 TmpInst.setOpcode(ARM::t2STR_PRE);
7093 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7094 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7095 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7096 TmpInst.addOperand(MCOperand::CreateImm(-4));
7097 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7098 TmpInst.addOperand(Inst.getOperand(3));
7102 case ARM::LDMIA_UPD:
7103 // If this is a load of a single register via a 'pop', then we should use
7104 // a post-indexed LDR instruction instead, per the ARM ARM.
7105 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7106 Inst.getNumOperands() == 5) {
7108 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7109 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7110 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7111 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7112 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7113 TmpInst.addOperand(MCOperand::CreateImm(4));
7114 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7115 TmpInst.addOperand(Inst.getOperand(3));
7120 case ARM::STMDB_UPD:
7121 // If this is a store of a single register via a 'push', then we should use
7122 // a pre-indexed STR instruction instead, per the ARM ARM.
7123 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7124 Inst.getNumOperands() == 5) {
7126 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7127 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7128 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7129 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7130 TmpInst.addOperand(MCOperand::CreateImm(-4));
7131 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7132 TmpInst.addOperand(Inst.getOperand(3));
7136 case ARM::t2ADDri12:
7137 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7138 // mnemonic was used (not "addw"), encoding T3 is preferred.
7139 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7140 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7142 Inst.setOpcode(ARM::t2ADDri);
7143 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7145 case ARM::t2SUBri12:
7146 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7147 // mnemonic was used (not "subw"), encoding T3 is preferred.
7148 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7149 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7151 Inst.setOpcode(ARM::t2SUBri);
7152 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7155 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7156 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7157 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7158 // to encoding T1 if <Rd> is omitted."
7159 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7160 Inst.setOpcode(ARM::tADDi3);
7165 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7166 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7167 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7168 // to encoding T1 if <Rd> is omitted."
7169 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7170 Inst.setOpcode(ARM::tSUBi3);
7175 case ARM::t2SUBri: {
7176 // If the destination and first source operand are the same, and
7177 // the flags are compatible with the current IT status, use encoding T2
7178 // instead of T3. For compatibility with the system 'as'. Make sure the
7179 // wide encoding wasn't explicit.
7180 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7181 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7182 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7183 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7184 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7185 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7186 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7189 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7190 ARM::tADDi8 : ARM::tSUBi8);
7191 TmpInst.addOperand(Inst.getOperand(0));
7192 TmpInst.addOperand(Inst.getOperand(5));
7193 TmpInst.addOperand(Inst.getOperand(0));
7194 TmpInst.addOperand(Inst.getOperand(2));
7195 TmpInst.addOperand(Inst.getOperand(3));
7196 TmpInst.addOperand(Inst.getOperand(4));
7200 case ARM::t2ADDrr: {
7201 // If the destination and first source operand are the same, and
7202 // there's no setting of the flags, use encoding T2 instead of T3.
7203 // Note that this is only for ADD, not SUB. This mirrors the system
7204 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7205 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7206 Inst.getOperand(5).getReg() != 0 ||
7207 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7208 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7211 TmpInst.setOpcode(ARM::tADDhirr);
7212 TmpInst.addOperand(Inst.getOperand(0));
7213 TmpInst.addOperand(Inst.getOperand(0));
7214 TmpInst.addOperand(Inst.getOperand(2));
7215 TmpInst.addOperand(Inst.getOperand(3));
7216 TmpInst.addOperand(Inst.getOperand(4));
7220 case ARM::tADDrSP: {
7221 // If the non-SP source operand and the destination operand are not the
7222 // same, we need to use the 32-bit encoding if it's available.
7223 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7224 Inst.setOpcode(ARM::t2ADDrr);
7225 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7231 // A Thumb conditional branch outside of an IT block is a tBcc.
7232 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7233 Inst.setOpcode(ARM::tBcc);
7238 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7239 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7240 Inst.setOpcode(ARM::t2Bcc);
7245 // If the conditional is AL or we're in an IT block, we really want t2B.
7246 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7247 Inst.setOpcode(ARM::t2B);
7252 // If the conditional is AL, we really want tB.
7253 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7254 Inst.setOpcode(ARM::tB);
7259 // If the register list contains any high registers, or if the writeback
7260 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7261 // instead if we're in Thumb2. Otherwise, this should have generated
7262 // an error in validateInstruction().
7263 unsigned Rn = Inst.getOperand(0).getReg();
7264 bool hasWritebackToken =
7265 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7266 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7267 bool listContainsBase;
7268 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7269 (!listContainsBase && !hasWritebackToken) ||
7270 (listContainsBase && hasWritebackToken)) {
7271 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7272 assert (isThumbTwo());
7273 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7274 // If we're switching to the updating version, we need to insert
7275 // the writeback tied operand.
7276 if (hasWritebackToken)
7277 Inst.insert(Inst.begin(),
7278 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7283 case ARM::tSTMIA_UPD: {
7284 // If the register list contains any high registers, we need to use
7285 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7286 // should have generated an error in validateInstruction().
7287 unsigned Rn = Inst.getOperand(0).getReg();
7288 bool listContainsBase;
7289 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7290 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7291 assert (isThumbTwo());
7292 Inst.setOpcode(ARM::t2STMIA_UPD);
7298 bool listContainsBase;
7299 // If the register list contains any high registers, we need to use
7300 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7301 // should have generated an error in validateInstruction().
7302 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7304 assert (isThumbTwo());
7305 Inst.setOpcode(ARM::t2LDMIA_UPD);
7306 // Add the base register and writeback operands.
7307 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7308 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7312 bool listContainsBase;
7313 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7315 assert (isThumbTwo());
7316 Inst.setOpcode(ARM::t2STMDB_UPD);
7317 // Add the base register and writeback operands.
7318 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7319 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7323 // If we can use the 16-bit encoding and the user didn't explicitly
7324 // request the 32-bit variant, transform it here.
7325 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7326 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7327 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7328 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7329 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7330 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7331 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7332 // The operands aren't in the same order for tMOVi8...
7334 TmpInst.setOpcode(ARM::tMOVi8);
7335 TmpInst.addOperand(Inst.getOperand(0));
7336 TmpInst.addOperand(Inst.getOperand(4));
7337 TmpInst.addOperand(Inst.getOperand(1));
7338 TmpInst.addOperand(Inst.getOperand(2));
7339 TmpInst.addOperand(Inst.getOperand(3));
7346 // If we can use the 16-bit encoding and the user didn't explicitly
7347 // request the 32-bit variant, transform it here.
7348 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7349 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7350 Inst.getOperand(2).getImm() == ARMCC::AL &&
7351 Inst.getOperand(4).getReg() == ARM::CPSR &&
7352 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7353 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7354 // The operands aren't the same for tMOV[S]r... (no cc_out)
7356 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7357 TmpInst.addOperand(Inst.getOperand(0));
7358 TmpInst.addOperand(Inst.getOperand(1));
7359 TmpInst.addOperand(Inst.getOperand(2));
7360 TmpInst.addOperand(Inst.getOperand(3));
7370 // If we can use the 16-bit encoding and the user didn't explicitly
7371 // request the 32-bit variant, transform it here.
7372 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7373 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7374 Inst.getOperand(2).getImm() == 0 &&
7375 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7376 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7378 switch (Inst.getOpcode()) {
7379 default: llvm_unreachable("Illegal opcode!");
7380 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7381 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7382 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7383 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7385 // The operands aren't the same for thumb1 (no rotate operand).
7387 TmpInst.setOpcode(NewOpc);
7388 TmpInst.addOperand(Inst.getOperand(0));
7389 TmpInst.addOperand(Inst.getOperand(1));
7390 TmpInst.addOperand(Inst.getOperand(3));
7391 TmpInst.addOperand(Inst.getOperand(4));
7398 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7399 // rrx shifts and asr/lsr of #32 is encoded as 0
7400 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7402 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7403 // Shifting by zero is accepted as a vanilla 'MOVr'
7405 TmpInst.setOpcode(ARM::MOVr);
7406 TmpInst.addOperand(Inst.getOperand(0));
7407 TmpInst.addOperand(Inst.getOperand(1));
7408 TmpInst.addOperand(Inst.getOperand(3));
7409 TmpInst.addOperand(Inst.getOperand(4));
7410 TmpInst.addOperand(Inst.getOperand(5));
7423 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7424 if (SOpc == ARM_AM::rrx) return false;
7425 switch (Inst.getOpcode()) {
7426 default: llvm_unreachable("unexpected opcode!");
7427 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7428 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7429 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7430 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7431 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7432 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7434 // If the shift is by zero, use the non-shifted instruction definition.
7435 // The exception is for right shifts, where 0 == 32
7436 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7437 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7439 TmpInst.setOpcode(newOpc);
7440 TmpInst.addOperand(Inst.getOperand(0));
7441 TmpInst.addOperand(Inst.getOperand(1));
7442 TmpInst.addOperand(Inst.getOperand(2));
7443 TmpInst.addOperand(Inst.getOperand(4));
7444 TmpInst.addOperand(Inst.getOperand(5));
7445 TmpInst.addOperand(Inst.getOperand(6));
7453 // The mask bits for all but the first condition are represented as
7454 // the low bit of the condition code value implies 't'. We currently
7455 // always have 1 implies 't', so XOR toggle the bits if the low bit
7456 // of the condition code is zero.
7457 MCOperand &MO = Inst.getOperand(1);
7458 unsigned Mask = MO.getImm();
7459 unsigned OrigMask = Mask;
7460 unsigned TZ = countTrailingZeros(Mask);
7461 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7462 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7463 Mask ^= (0xE << TZ) & 0xF;
7467 // Set up the IT block state according to the IT instruction we just
7469 assert(!inITBlock() && "nested IT blocks?!");
7470 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7471 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7472 ITState.CurPosition = 0;
7473 ITState.FirstCond = true;
7483 // Assemblers should use the narrow encodings of these instructions when permissible.
7484 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7485 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7486 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7487 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7488 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7489 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7490 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7492 switch (Inst.getOpcode()) {
7493 default: llvm_unreachable("unexpected opcode");
7494 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7495 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7496 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7497 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7498 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7499 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7502 TmpInst.setOpcode(NewOpc);
7503 TmpInst.addOperand(Inst.getOperand(0));
7504 TmpInst.addOperand(Inst.getOperand(5));
7505 TmpInst.addOperand(Inst.getOperand(1));
7506 TmpInst.addOperand(Inst.getOperand(2));
7507 TmpInst.addOperand(Inst.getOperand(3));
7508 TmpInst.addOperand(Inst.getOperand(4));
7519 // Assemblers should use the narrow encodings of these instructions when permissible.
7520 // These instructions are special in that they are commutable, so shorter encodings
7521 // are available more often.
7522 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7523 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7524 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7525 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7526 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7527 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7528 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7529 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7531 switch (Inst.getOpcode()) {
7532 default: llvm_unreachable("unexpected opcode");
7533 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7534 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7535 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7536 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7539 TmpInst.setOpcode(NewOpc);
7540 TmpInst.addOperand(Inst.getOperand(0));
7541 TmpInst.addOperand(Inst.getOperand(5));
7542 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7543 TmpInst.addOperand(Inst.getOperand(1));
7544 TmpInst.addOperand(Inst.getOperand(2));
7546 TmpInst.addOperand(Inst.getOperand(2));
7547 TmpInst.addOperand(Inst.getOperand(1));
7549 TmpInst.addOperand(Inst.getOperand(3));
7550 TmpInst.addOperand(Inst.getOperand(4));
7560 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7561 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7562 // suffix depending on whether they're in an IT block or not.
7563 unsigned Opc = Inst.getOpcode();
7564 const MCInstrDesc &MCID = MII.get(Opc);
7565 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7566 assert(MCID.hasOptionalDef() &&
7567 "optionally flag setting instruction missing optional def operand");
7568 assert(MCID.NumOperands == Inst.getNumOperands() &&
7569 "operand count mismatch!");
7570 // Find the optional-def operand (cc_out).
7573 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7576 // If we're parsing Thumb1, reject it completely.
7577 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7578 return Match_MnemonicFail;
7579 // If we're parsing Thumb2, which form is legal depends on whether we're
7581 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7583 return Match_RequiresITBlock;
7584 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7586 return Match_RequiresNotITBlock;
7588 // Some high-register supporting Thumb1 encodings only allow both registers
7589 // to be from r0-r7 when in Thumb2.
7590 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7591 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7592 isARMLowRegister(Inst.getOperand(2).getReg()))
7593 return Match_RequiresThumb2;
7594 // Others only require ARMv6 or later.
7595 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7596 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7597 isARMLowRegister(Inst.getOperand(1).getReg()))
7598 return Match_RequiresV6;
7599 return Match_Success;
7602 static const char *getSubtargetFeatureName(unsigned Val);
7604 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7605 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7606 MCStreamer &Out, unsigned &ErrorInfo,
7607 bool MatchingInlineAsm) {
7609 unsigned MatchResult;
7611 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7613 switch (MatchResult) {
7616 // Context sensitive operand constraints aren't handled by the matcher,
7617 // so check them here.
7618 if (validateInstruction(Inst, Operands)) {
7619 // Still progress the IT block, otherwise one wrong condition causes
7620 // nasty cascading errors.
7621 forwardITPosition();
7625 { // processInstruction() updates inITBlock state, we need to save it away
7626 bool wasInITBlock = inITBlock();
7628 // Some instructions need post-processing to, for example, tweak which
7629 // encoding is selected. Loop on it while changes happen so the
7630 // individual transformations can chain off each other. E.g.,
7631 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7632 while (processInstruction(Inst, Operands))
7635 // Only after the instruction is fully processed, we can validate it
7636 if (wasInITBlock && hasV8Ops() && isThumb() &&
7637 !isV8EligibleForIT(&Inst, 2)) {
7638 Warning(IDLoc, "deprecated instruction in IT block");
7642 // Only move forward at the very end so that everything in validate
7643 // and process gets a consistent answer about whether we're in an IT
7645 forwardITPosition();
7647 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7648 // doesn't actually encode.
7649 if (Inst.getOpcode() == ARM::ITasm)
7653 Out.EmitInstruction(Inst);
7655 case Match_MissingFeature: {
7656 assert(ErrorInfo && "Unknown missing feature!");
7657 // Special case the error message for the very common case where only
7658 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7659 std::string Msg = "instruction requires:";
7661 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7662 if (ErrorInfo & Mask) {
7664 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7668 return Error(IDLoc, Msg);
7670 case Match_InvalidOperand: {
7671 SMLoc ErrorLoc = IDLoc;
7672 if (ErrorInfo != ~0U) {
7673 if (ErrorInfo >= Operands.size())
7674 return Error(IDLoc, "too few operands for instruction");
7676 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7677 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7680 return Error(ErrorLoc, "invalid operand for instruction");
7682 case Match_MnemonicFail:
7683 return Error(IDLoc, "invalid instruction",
7684 ((ARMOperand*)Operands[0])->getLocRange());
7685 case Match_RequiresNotITBlock:
7686 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7687 case Match_RequiresITBlock:
7688 return Error(IDLoc, "instruction only valid inside IT block");
7689 case Match_RequiresV6:
7690 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7691 case Match_RequiresThumb2:
7692 return Error(IDLoc, "instruction variant requires Thumb2");
7693 case Match_ImmRange0_15: {
7694 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7695 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7696 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7700 llvm_unreachable("Implement any new match types added!");
7703 /// parseDirective parses the arm specific directives
7704 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7705 StringRef IDVal = DirectiveID.getIdentifier();
7706 if (IDVal == ".word")
7707 return parseDirectiveWord(4, DirectiveID.getLoc());
7708 else if (IDVal == ".thumb")
7709 return parseDirectiveThumb(DirectiveID.getLoc());
7710 else if (IDVal == ".arm")
7711 return parseDirectiveARM(DirectiveID.getLoc());
7712 else if (IDVal == ".thumb_func")
7713 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7714 else if (IDVal == ".code")
7715 return parseDirectiveCode(DirectiveID.getLoc());
7716 else if (IDVal == ".syntax")
7717 return parseDirectiveSyntax(DirectiveID.getLoc());
7718 else if (IDVal == ".unreq")
7719 return parseDirectiveUnreq(DirectiveID.getLoc());
7720 else if (IDVal == ".arch")
7721 return parseDirectiveArch(DirectiveID.getLoc());
7722 else if (IDVal == ".eabi_attribute")
7723 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7724 else if (IDVal == ".fnstart")
7725 return parseDirectiveFnStart(DirectiveID.getLoc());
7726 else if (IDVal == ".fnend")
7727 return parseDirectiveFnEnd(DirectiveID.getLoc());
7728 else if (IDVal == ".cantunwind")
7729 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7730 else if (IDVal == ".personality")
7731 return parseDirectivePersonality(DirectiveID.getLoc());
7732 else if (IDVal == ".handlerdata")
7733 return parseDirectiveHandlerData(DirectiveID.getLoc());
7734 else if (IDVal == ".setfp")
7735 return parseDirectiveSetFP(DirectiveID.getLoc());
7736 else if (IDVal == ".pad")
7737 return parseDirectivePad(DirectiveID.getLoc());
7738 else if (IDVal == ".save")
7739 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7740 else if (IDVal == ".vsave")
7741 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7745 /// parseDirectiveWord
7746 /// ::= .word [ expression (, expression)* ]
7747 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7748 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7750 const MCExpr *Value;
7751 if (getParser().parseExpression(Value))
7754 getParser().getStreamer().EmitValue(Value, Size);
7756 if (getLexer().is(AsmToken::EndOfStatement))
7759 // FIXME: Improve diagnostic.
7760 if (getLexer().isNot(AsmToken::Comma))
7761 return Error(L, "unexpected token in directive");
7770 /// parseDirectiveThumb
7772 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7773 if (getLexer().isNot(AsmToken::EndOfStatement))
7774 return Error(L, "unexpected token in directive");
7778 return Error(L, "target does not support Thumb mode");
7782 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7786 /// parseDirectiveARM
7788 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7789 if (getLexer().isNot(AsmToken::EndOfStatement))
7790 return Error(L, "unexpected token in directive");
7794 return Error(L, "target does not support ARM mode");
7798 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7802 /// parseDirectiveThumbFunc
7803 /// ::= .thumbfunc symbol_name
7804 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7805 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7806 bool isMachO = MAI->hasSubsectionsViaSymbols();
7808 bool needFuncName = true;
7810 // Darwin asm has (optionally) function name after .thumb_func direction
7813 const AsmToken &Tok = Parser.getTok();
7814 if (Tok.isNot(AsmToken::EndOfStatement)) {
7815 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7816 return Error(L, "unexpected token in .thumb_func directive");
7817 Name = Tok.getIdentifier();
7818 Parser.Lex(); // Consume the identifier token.
7819 needFuncName = false;
7823 if (getLexer().isNot(AsmToken::EndOfStatement))
7824 return Error(L, "unexpected token in directive");
7826 // Eat the end of statement and any blank lines that follow.
7827 while (getLexer().is(AsmToken::EndOfStatement))
7830 // FIXME: assuming function name will be the line following .thumb_func
7831 // We really should be checking the next symbol definition even if there's
7832 // stuff in between.
7834 Name = Parser.getTok().getIdentifier();
7837 // Mark symbol as a thumb symbol.
7838 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7839 getParser().getStreamer().EmitThumbFunc(Func);
7843 /// parseDirectiveSyntax
7844 /// ::= .syntax unified | divided
7845 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7846 const AsmToken &Tok = Parser.getTok();
7847 if (Tok.isNot(AsmToken::Identifier))
7848 return Error(L, "unexpected token in .syntax directive");
7849 StringRef Mode = Tok.getString();
7850 if (Mode == "unified" || Mode == "UNIFIED")
7852 else if (Mode == "divided" || Mode == "DIVIDED")
7853 return Error(L, "'.syntax divided' arm asssembly not supported");
7855 return Error(L, "unrecognized syntax mode in .syntax directive");
7857 if (getLexer().isNot(AsmToken::EndOfStatement))
7858 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7861 // TODO tell the MC streamer the mode
7862 // getParser().getStreamer().Emit???();
7866 /// parseDirectiveCode
7867 /// ::= .code 16 | 32
7868 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7869 const AsmToken &Tok = Parser.getTok();
7870 if (Tok.isNot(AsmToken::Integer))
7871 return Error(L, "unexpected token in .code directive");
7872 int64_t Val = Parser.getTok().getIntVal();
7878 return Error(L, "invalid operand to .code directive");
7880 if (getLexer().isNot(AsmToken::EndOfStatement))
7881 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7886 return Error(L, "target does not support Thumb mode");
7890 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7893 return Error(L, "target does not support ARM mode");
7897 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7903 /// parseDirectiveReq
7904 /// ::= name .req registername
7905 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7906 Parser.Lex(); // Eat the '.req' token.
7908 SMLoc SRegLoc, ERegLoc;
7909 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7910 Parser.eatToEndOfStatement();
7911 return Error(SRegLoc, "register name expected");
7914 // Shouldn't be anything else.
7915 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7916 Parser.eatToEndOfStatement();
7917 return Error(Parser.getTok().getLoc(),
7918 "unexpected input in .req directive.");
7921 Parser.Lex(); // Consume the EndOfStatement
7923 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7924 return Error(SRegLoc, "redefinition of '" + Name +
7925 "' does not match original.");
7930 /// parseDirectiveUneq
7931 /// ::= .unreq registername
7932 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7933 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7934 Parser.eatToEndOfStatement();
7935 return Error(L, "unexpected input in .unreq directive.");
7937 RegisterReqs.erase(Parser.getTok().getIdentifier());
7938 Parser.Lex(); // Eat the identifier.
7942 /// parseDirectiveArch
7944 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7948 /// parseDirectiveEabiAttr
7949 /// ::= .eabi_attribute int, int
7950 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7954 /// parseDirectiveFnStart
7956 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7957 if (FnStartLoc.isValid()) {
7958 Error(L, ".fnstart starts before the end of previous one");
7959 Error(FnStartLoc, "previous .fnstart starts here");
7964 getParser().getStreamer().EmitFnStart();
7968 /// parseDirectiveFnEnd
7970 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7971 // Check the ordering of unwind directives
7972 if (!FnStartLoc.isValid())
7973 return Error(L, ".fnstart must precede .fnend directive");
7975 // Reset the unwind directives parser state
7976 resetUnwindDirectiveParserState();
7978 getParser().getStreamer().EmitFnEnd();
7982 /// parseDirectiveCantUnwind
7984 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7985 // Check the ordering of unwind directives
7987 if (!FnStartLoc.isValid())
7988 return Error(L, ".fnstart must precede .cantunwind directive");
7989 if (HandlerDataLoc.isValid()) {
7990 Error(L, ".cantunwind can't be used with .handlerdata directive");
7991 Error(HandlerDataLoc, ".handlerdata was specified here");
7994 if (PersonalityLoc.isValid()) {
7995 Error(L, ".cantunwind can't be used with .personality directive");
7996 Error(PersonalityLoc, ".personality was specified here");
8000 getParser().getStreamer().EmitCantUnwind();
8004 /// parseDirectivePersonality
8005 /// ::= .personality name
8006 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8007 // Check the ordering of unwind directives
8009 if (!FnStartLoc.isValid())
8010 return Error(L, ".fnstart must precede .personality directive");
8011 if (CantUnwindLoc.isValid()) {
8012 Error(L, ".personality can't be used with .cantunwind directive");
8013 Error(CantUnwindLoc, ".cantunwind was specified here");
8016 if (HandlerDataLoc.isValid()) {
8017 Error(L, ".personality must precede .handlerdata directive");
8018 Error(HandlerDataLoc, ".handlerdata was specified here");
8022 // Parse the name of the personality routine
8023 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8024 Parser.eatToEndOfStatement();
8025 return Error(L, "unexpected input in .personality directive.");
8027 StringRef Name(Parser.getTok().getIdentifier());
8030 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8031 getParser().getStreamer().EmitPersonality(PR);
8035 /// parseDirectiveHandlerData
8036 /// ::= .handlerdata
8037 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8038 // Check the ordering of unwind directives
8040 if (!FnStartLoc.isValid())
8041 return Error(L, ".fnstart must precede .personality directive");
8042 if (CantUnwindLoc.isValid()) {
8043 Error(L, ".handlerdata can't be used with .cantunwind directive");
8044 Error(CantUnwindLoc, ".cantunwind was specified here");
8048 getParser().getStreamer().EmitHandlerData();
8052 /// parseDirectiveSetFP
8053 /// ::= .setfp fpreg, spreg [, offset]
8054 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8055 // Check the ordering of unwind directives
8056 if (!FnStartLoc.isValid())
8057 return Error(L, ".fnstart must precede .setfp directive");
8058 if (HandlerDataLoc.isValid())
8059 return Error(L, ".setfp must precede .handlerdata directive");
8062 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8063 int NewFPReg = tryParseRegister();
8065 return Error(NewFPRegLoc, "frame pointer register expected");
8068 if (!Parser.getTok().is(AsmToken::Comma))
8069 return Error(Parser.getTok().getLoc(), "comma expected");
8070 Parser.Lex(); // skip comma
8073 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8074 int NewSPReg = tryParseRegister();
8076 return Error(NewSPRegLoc, "stack pointer register expected");
8078 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8079 return Error(NewSPRegLoc,
8080 "register should be either $sp or the latest fp register");
8082 // Update the frame pointer register
8087 if (Parser.getTok().is(AsmToken::Comma)) {
8088 Parser.Lex(); // skip comma
8090 if (Parser.getTok().isNot(AsmToken::Hash) &&
8091 Parser.getTok().isNot(AsmToken::Dollar)) {
8092 return Error(Parser.getTok().getLoc(), "'#' expected");
8094 Parser.Lex(); // skip hash token.
8096 const MCExpr *OffsetExpr;
8097 SMLoc ExLoc = Parser.getTok().getLoc();
8099 if (getParser().parseExpression(OffsetExpr, EndLoc))
8100 return Error(ExLoc, "malformed setfp offset");
8101 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8103 return Error(ExLoc, "setfp offset must be an immediate");
8105 Offset = CE->getValue();
8108 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8109 static_cast<unsigned>(NewSPReg),
8116 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8117 // Check the ordering of unwind directives
8118 if (!FnStartLoc.isValid())
8119 return Error(L, ".fnstart must precede .pad directive");
8120 if (HandlerDataLoc.isValid())
8121 return Error(L, ".pad must precede .handlerdata directive");
8124 if (Parser.getTok().isNot(AsmToken::Hash) &&
8125 Parser.getTok().isNot(AsmToken::Dollar)) {
8126 return Error(Parser.getTok().getLoc(), "'#' expected");
8128 Parser.Lex(); // skip hash token.
8130 const MCExpr *OffsetExpr;
8131 SMLoc ExLoc = Parser.getTok().getLoc();
8133 if (getParser().parseExpression(OffsetExpr, EndLoc))
8134 return Error(ExLoc, "malformed pad offset");
8135 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8137 return Error(ExLoc, "pad offset must be an immediate");
8139 getParser().getStreamer().EmitPad(CE->getValue());
8143 /// parseDirectiveRegSave
8144 /// ::= .save { registers }
8145 /// ::= .vsave { registers }
8146 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8147 // Check the ordering of unwind directives
8148 if (!FnStartLoc.isValid())
8149 return Error(L, ".fnstart must precede .save or .vsave directives");
8150 if (HandlerDataLoc.isValid())
8151 return Error(L, ".save or .vsave must precede .handlerdata directive");
8153 // RAII object to make sure parsed operands are deleted.
8154 struct CleanupObject {
8155 SmallVector<MCParsedAsmOperand *, 1> Operands;
8157 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8162 // Parse the register list
8163 if (parseRegisterList(CO.Operands))
8165 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
8166 if (!IsVector && !Op->isRegList())
8167 return Error(L, ".save expects GPR registers");
8168 if (IsVector && !Op->isDPRRegList())
8169 return Error(L, ".vsave expects DPR registers");
8171 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8175 /// Force static initialization.
8176 extern "C" void LLVMInitializeARMAsmParser() {
8177 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8178 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8181 #define GET_REGISTER_MATCHER
8182 #define GET_SUBTARGET_FEATURE_NAME
8183 #define GET_MATCHER_IMPLEMENTATION
8184 #include "ARMGenAsmMatcher.inc"
8186 // Define this matcher function after the auto-generated include so we
8187 // have the match class enum definitions.
8188 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8190 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8191 // If the kind is a token for a literal immediate, check if our asm
8192 // operand matches. This is for InstAliases which have a fixed-value
8193 // immediate in the syntax.
8194 if (Kind == MCK__35_0 && Op->isImm()) {
8195 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8197 return Match_InvalidOperand;
8198 if (CE->getValue() == 0)
8199 return Match_Success;
8201 return Match_InvalidOperand;