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 "MCTargetDesc/ARMBaseInfo.h"
11 #include "MCTargetDesc/ARMAddressingModes.h"
12 #include "MCTargetDesc/ARMMCExpr.h"
13 #include "llvm/MC/MCParser/MCAsmLexer.h"
14 #include "llvm/MC/MCParser/MCAsmParser.h"
15 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrDesc.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/MCTargetAsmParser.h"
25 #include "llvm/Support/MathExtras.h"
26 #include "llvm/Support/SourceMgr.h"
27 #include "llvm/Support/TargetRegistry.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include "llvm/ADT/BitVector.h"
30 #include "llvm/ADT/OwningPtr.h"
31 #include "llvm/ADT/STLExtras.h"
32 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/ADT/StringSwitch.h"
34 #include "llvm/ADT/Twine.h"
42 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
44 class ARMAsmParser : public MCTargetAsmParser {
47 const MCRegisterInfo *MRI;
49 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
53 ARMCC::CondCodes Cond; // Condition for IT block.
54 unsigned Mask:4; // Condition mask for instructions.
55 // Starting at first 1 (from lsb).
56 // '1' condition as indicated in IT.
57 // '0' inverse of condition (else).
58 // Count of instructions in IT block is
59 // 4 - trailingzeroes(mask)
61 bool FirstCond; // Explicit flag for when we're parsing the
62 // First instruction in the IT block. It's
63 // implied in the mask, so needs special
66 unsigned CurPosition; // Current position in parsing of IT
67 // block. In range [0,3]. Initialized
68 // according to count of instructions in block.
69 // ~0U if no active IT block.
71 bool inITBlock() { return ITState.CurPosition != ~0U;}
72 void forwardITPosition() {
73 if (!inITBlock()) return;
74 // Move to the next instruction in the IT block, if there is one. If not,
75 // mark the block as done.
76 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
77 if (++ITState.CurPosition == 5 - TZ)
78 ITState.CurPosition = ~0U; // Done with the IT block after this.
82 MCAsmParser &getParser() const { return Parser; }
83 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
85 bool Warning(SMLoc L, const Twine &Msg,
86 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
87 return Parser.Warning(L, Msg, Ranges);
89 bool Error(SMLoc L, const Twine &Msg,
90 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
91 return Parser.Error(L, Msg, Ranges);
94 int tryParseRegister();
95 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
96 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
97 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
98 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
99 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
100 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
101 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
102 unsigned &ShiftAmount);
103 bool parseDirectiveWord(unsigned Size, SMLoc L);
104 bool parseDirectiveThumb(SMLoc L);
105 bool parseDirectiveARM(SMLoc L);
106 bool parseDirectiveThumbFunc(SMLoc L);
107 bool parseDirectiveCode(SMLoc L);
108 bool parseDirectiveSyntax(SMLoc L);
109 bool parseDirectiveReq(StringRef Name, SMLoc L);
110 bool parseDirectiveUnreq(SMLoc L);
111 bool parseDirectiveArch(SMLoc L);
112 bool parseDirectiveEabiAttr(SMLoc L);
114 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
115 bool &CarrySetting, unsigned &ProcessorIMod,
117 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
118 bool &CanAcceptPredicationCode);
120 bool isThumb() const {
121 // FIXME: Can tablegen auto-generate this?
122 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
124 bool isThumbOne() const {
125 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
127 bool isThumbTwo() const {
128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
130 bool hasV6Ops() const {
131 return STI.getFeatureBits() & ARM::HasV6Ops;
133 bool hasV7Ops() const {
134 return STI.getFeatureBits() & ARM::HasV7Ops;
137 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
138 setAvailableFeatures(FB);
140 bool isMClass() const {
141 return STI.getFeatureBits() & ARM::FeatureMClass;
144 /// @name Auto-generated Match Functions
147 #define GET_ASSEMBLER_HEADER
148 #include "ARMGenAsmMatcher.inc"
152 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
153 OperandMatchResultTy parseCoprocNumOperand(
154 SmallVectorImpl<MCParsedAsmOperand*>&);
155 OperandMatchResultTy parseCoprocRegOperand(
156 SmallVectorImpl<MCParsedAsmOperand*>&);
157 OperandMatchResultTy parseCoprocOptionOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
159 OperandMatchResultTy parseMemBarrierOptOperand(
160 SmallVectorImpl<MCParsedAsmOperand*>&);
161 OperandMatchResultTy parseProcIFlagsOperand(
162 SmallVectorImpl<MCParsedAsmOperand*>&);
163 OperandMatchResultTy parseMSRMaskOperand(
164 SmallVectorImpl<MCParsedAsmOperand*>&);
165 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
166 StringRef Op, int Low, int High);
167 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
168 return parsePKHImm(O, "lsl", 0, 31);
170 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
171 return parsePKHImm(O, "asr", 1, 32);
173 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
174 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
175 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
176 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
177 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
178 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
179 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
180 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
181 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
183 // Asm Match Converter Methods
184 bool cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
185 const SmallVectorImpl<MCParsedAsmOperand*> &);
186 bool cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
187 const SmallVectorImpl<MCParsedAsmOperand*> &);
188 bool cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
189 const SmallVectorImpl<MCParsedAsmOperand*> &);
190 bool cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
191 const SmallVectorImpl<MCParsedAsmOperand*> &);
192 bool cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
193 const SmallVectorImpl<MCParsedAsmOperand*> &);
194 bool cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
195 const SmallVectorImpl<MCParsedAsmOperand*> &);
196 bool cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
197 const SmallVectorImpl<MCParsedAsmOperand*> &);
198 bool cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
199 const SmallVectorImpl<MCParsedAsmOperand*> &);
200 bool cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
201 const SmallVectorImpl<MCParsedAsmOperand*> &);
202 bool cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
203 const SmallVectorImpl<MCParsedAsmOperand*> &);
204 bool cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
205 const SmallVectorImpl<MCParsedAsmOperand*> &);
206 bool cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
207 const SmallVectorImpl<MCParsedAsmOperand*> &);
208 bool cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
209 const SmallVectorImpl<MCParsedAsmOperand*> &);
210 bool cvtLdrdPre(MCInst &Inst, unsigned Opcode,
211 const SmallVectorImpl<MCParsedAsmOperand*> &);
212 bool cvtStrdPre(MCInst &Inst, unsigned Opcode,
213 const SmallVectorImpl<MCParsedAsmOperand*> &);
214 bool cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
215 const SmallVectorImpl<MCParsedAsmOperand*> &);
216 bool cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
217 const SmallVectorImpl<MCParsedAsmOperand*> &);
218 bool cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
219 const SmallVectorImpl<MCParsedAsmOperand*> &);
220 bool cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
221 const SmallVectorImpl<MCParsedAsmOperand*> &);
222 bool cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
223 const SmallVectorImpl<MCParsedAsmOperand*> &);
224 bool cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
225 const SmallVectorImpl<MCParsedAsmOperand*> &);
227 bool validateInstruction(MCInst &Inst,
228 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
229 bool processInstruction(MCInst &Inst,
230 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
231 bool shouldOmitCCOutOperand(StringRef Mnemonic,
232 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
235 enum ARMMatchResultTy {
236 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
237 Match_RequiresNotITBlock,
242 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
243 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
244 MCAsmParserExtension::Initialize(_Parser);
246 // Cache the MCRegisterInfo.
247 MRI = &getContext().getRegisterInfo();
249 // Initialize the set of available features.
250 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
252 // Not in an ITBlock to start with.
253 ITState.CurPosition = ~0U;
256 // Implementation of the MCTargetAsmParser interface:
257 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
258 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
259 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
260 bool ParseDirective(AsmToken DirectiveID);
262 unsigned checkTargetMatchPredicate(MCInst &Inst);
264 bool MatchAndEmitInstruction(SMLoc IDLoc,
265 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
268 } // end anonymous namespace
272 /// ARMOperand - Instances of this class represent a parsed ARM machine
274 class ARMOperand : public MCParsedAsmOperand {
294 k_VectorListAllLanes,
300 k_BitfieldDescriptor,
304 SMLoc StartLoc, EndLoc;
305 SmallVector<unsigned, 8> Registers;
309 ARMCC::CondCodes Val;
329 ARM_PROC::IFlags Val;
345 // A vector register list is a sequential list of 1 to 4 registers.
361 /// Combined record for all forms of ARM address expressions.
364 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
366 const MCConstantExpr *OffsetImm; // Offset immediate value
367 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
368 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
369 unsigned ShiftImm; // shift for OffsetReg.
370 unsigned Alignment; // 0 = no alignment specified
371 // n = alignment in bytes (2, 4, 8, 16, or 32)
372 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
378 ARM_AM::ShiftOpc ShiftTy;
387 ARM_AM::ShiftOpc ShiftTy;
393 ARM_AM::ShiftOpc ShiftTy;
406 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
408 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
410 StartLoc = o.StartLoc;
427 case k_DPRRegisterList:
428 case k_SPRRegisterList:
429 Registers = o.Registers;
432 case k_VectorListAllLanes:
433 case k_VectorListIndexed:
434 VectorList = o.VectorList;
441 CoprocOption = o.CoprocOption;
446 case k_MemBarrierOpt:
452 case k_PostIndexRegister:
453 PostIdxReg = o.PostIdxReg;
461 case k_ShifterImmediate:
462 ShifterImm = o.ShifterImm;
464 case k_ShiftedRegister:
465 RegShiftedReg = o.RegShiftedReg;
467 case k_ShiftedImmediate:
468 RegShiftedImm = o.RegShiftedImm;
470 case k_RotateImmediate:
473 case k_BitfieldDescriptor:
474 Bitfield = o.Bitfield;
477 VectorIndex = o.VectorIndex;
482 /// getStartLoc - Get the location of the first token of this operand.
483 SMLoc getStartLoc() const { return StartLoc; }
484 /// getEndLoc - Get the location of the last token of this operand.
485 SMLoc getEndLoc() const { return EndLoc; }
487 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
489 ARMCC::CondCodes getCondCode() const {
490 assert(Kind == k_CondCode && "Invalid access!");
494 unsigned getCoproc() const {
495 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
499 StringRef getToken() const {
500 assert(Kind == k_Token && "Invalid access!");
501 return StringRef(Tok.Data, Tok.Length);
504 unsigned getReg() const {
505 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
509 const SmallVectorImpl<unsigned> &getRegList() const {
510 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
511 Kind == k_SPRRegisterList) && "Invalid access!");
515 const MCExpr *getImm() const {
516 assert(isImm() && "Invalid access!");
520 unsigned getVectorIndex() const {
521 assert(Kind == k_VectorIndex && "Invalid access!");
522 return VectorIndex.Val;
525 ARM_MB::MemBOpt getMemBarrierOpt() const {
526 assert(Kind == k_MemBarrierOpt && "Invalid access!");
530 ARM_PROC::IFlags getProcIFlags() const {
531 assert(Kind == k_ProcIFlags && "Invalid access!");
535 unsigned getMSRMask() const {
536 assert(Kind == k_MSRMask && "Invalid access!");
540 bool isCoprocNum() const { return Kind == k_CoprocNum; }
541 bool isCoprocReg() const { return Kind == k_CoprocReg; }
542 bool isCoprocOption() const { return Kind == k_CoprocOption; }
543 bool isCondCode() const { return Kind == k_CondCode; }
544 bool isCCOut() const { return Kind == k_CCOut; }
545 bool isITMask() const { return Kind == k_ITCondMask; }
546 bool isITCondCode() const { return Kind == k_CondCode; }
547 bool isImm() const { return Kind == k_Immediate; }
548 bool isFPImm() const {
549 if (!isImm()) return false;
550 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
551 if (!CE) return false;
552 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
555 bool isFBits16() const {
556 if (!isImm()) return false;
557 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
558 if (!CE) return false;
559 int64_t Value = CE->getValue();
560 return Value >= 0 && Value <= 16;
562 bool isFBits32() const {
563 if (!isImm()) return false;
564 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
565 if (!CE) return false;
566 int64_t Value = CE->getValue();
567 return Value >= 1 && Value <= 32;
569 bool isImm8s4() const {
570 if (!isImm()) return false;
571 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
572 if (!CE) return false;
573 int64_t Value = CE->getValue();
574 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
576 bool isImm0_1020s4() const {
577 if (!isImm()) return false;
578 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
579 if (!CE) return false;
580 int64_t Value = CE->getValue();
581 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
583 bool isImm0_508s4() const {
584 if (!isImm()) return false;
585 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
586 if (!CE) return false;
587 int64_t Value = CE->getValue();
588 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
590 bool isImm0_508s4Neg() const {
591 if (!isImm()) return false;
592 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
593 if (!CE) return false;
594 int64_t Value = -CE->getValue();
595 // explicitly exclude zero. we want that to use the normal 0_508 version.
596 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
598 bool isImm0_255() const {
599 if (!isImm()) return false;
600 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
601 if (!CE) return false;
602 int64_t Value = CE->getValue();
603 return Value >= 0 && Value < 256;
605 bool isImm0_4095() const {
606 if (!isImm()) return false;
607 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
608 if (!CE) return false;
609 int64_t Value = CE->getValue();
610 return Value >= 0 && Value < 4096;
612 bool isImm0_4095Neg() const {
613 if (!isImm()) return false;
614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
615 if (!CE) return false;
616 int64_t Value = -CE->getValue();
617 return Value > 0 && Value < 4096;
619 bool isImm0_1() const {
620 if (!isImm()) return false;
621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
622 if (!CE) return false;
623 int64_t Value = CE->getValue();
624 return Value >= 0 && Value < 2;
626 bool isImm0_3() const {
627 if (!isImm()) return false;
628 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
629 if (!CE) return false;
630 int64_t Value = CE->getValue();
631 return Value >= 0 && Value < 4;
633 bool isImm0_7() const {
634 if (!isImm()) return false;
635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
636 if (!CE) return false;
637 int64_t Value = CE->getValue();
638 return Value >= 0 && Value < 8;
640 bool isImm0_15() const {
641 if (!isImm()) return false;
642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
643 if (!CE) return false;
644 int64_t Value = CE->getValue();
645 return Value >= 0 && Value < 16;
647 bool isImm0_31() const {
648 if (!isImm()) return false;
649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
650 if (!CE) return false;
651 int64_t Value = CE->getValue();
652 return Value >= 0 && Value < 32;
654 bool isImm0_63() const {
655 if (!isImm()) return false;
656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
657 if (!CE) return false;
658 int64_t Value = CE->getValue();
659 return Value >= 0 && Value < 64;
661 bool isImm8() const {
662 if (!isImm()) return false;
663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
664 if (!CE) return false;
665 int64_t Value = CE->getValue();
668 bool isImm16() const {
669 if (!isImm()) return false;
670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
671 if (!CE) return false;
672 int64_t Value = CE->getValue();
675 bool isImm32() const {
676 if (!isImm()) return false;
677 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
678 if (!CE) return false;
679 int64_t Value = CE->getValue();
682 bool isShrImm8() const {
683 if (!isImm()) return false;
684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
685 if (!CE) return false;
686 int64_t Value = CE->getValue();
687 return Value > 0 && Value <= 8;
689 bool isShrImm16() const {
690 if (!isImm()) return false;
691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
692 if (!CE) return false;
693 int64_t Value = CE->getValue();
694 return Value > 0 && Value <= 16;
696 bool isShrImm32() const {
697 if (!isImm()) return false;
698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
699 if (!CE) return false;
700 int64_t Value = CE->getValue();
701 return Value > 0 && Value <= 32;
703 bool isShrImm64() const {
704 if (!isImm()) return false;
705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
706 if (!CE) return false;
707 int64_t Value = CE->getValue();
708 return Value > 0 && Value <= 64;
710 bool isImm1_7() const {
711 if (!isImm()) return false;
712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
713 if (!CE) return false;
714 int64_t Value = CE->getValue();
715 return Value > 0 && Value < 8;
717 bool isImm1_15() const {
718 if (!isImm()) return false;
719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
720 if (!CE) return false;
721 int64_t Value = CE->getValue();
722 return Value > 0 && Value < 16;
724 bool isImm1_31() const {
725 if (!isImm()) return false;
726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
727 if (!CE) return false;
728 int64_t Value = CE->getValue();
729 return Value > 0 && Value < 32;
731 bool isImm1_16() const {
732 if (!isImm()) return false;
733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
734 if (!CE) return false;
735 int64_t Value = CE->getValue();
736 return Value > 0 && Value < 17;
738 bool isImm1_32() const {
739 if (!isImm()) return false;
740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
741 if (!CE) return false;
742 int64_t Value = CE->getValue();
743 return Value > 0 && Value < 33;
745 bool isImm0_32() const {
746 if (!isImm()) return false;
747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
748 if (!CE) return false;
749 int64_t Value = CE->getValue();
750 return Value >= 0 && Value < 33;
752 bool isImm0_65535() const {
753 if (!isImm()) return false;
754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
755 if (!CE) return false;
756 int64_t Value = CE->getValue();
757 return Value >= 0 && Value < 65536;
759 bool isImm0_65535Expr() const {
760 if (!isImm()) return false;
761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
762 // If it's not a constant expression, it'll generate a fixup and be
764 if (!CE) return true;
765 int64_t Value = CE->getValue();
766 return Value >= 0 && Value < 65536;
768 bool isImm24bit() const {
769 if (!isImm()) return false;
770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
771 if (!CE) return false;
772 int64_t Value = CE->getValue();
773 return Value >= 0 && Value <= 0xffffff;
775 bool isImmThumbSR() const {
776 if (!isImm()) return false;
777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
778 if (!CE) return false;
779 int64_t Value = CE->getValue();
780 return Value > 0 && Value < 33;
782 bool isPKHLSLImm() const {
783 if (!isImm()) return false;
784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
785 if (!CE) return false;
786 int64_t Value = CE->getValue();
787 return Value >= 0 && Value < 32;
789 bool isPKHASRImm() const {
790 if (!isImm()) return false;
791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
792 if (!CE) return false;
793 int64_t Value = CE->getValue();
794 return Value > 0 && Value <= 32;
796 bool isARMSOImm() const {
797 if (!isImm()) return false;
798 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
799 if (!CE) return false;
800 int64_t Value = CE->getValue();
801 return ARM_AM::getSOImmVal(Value) != -1;
803 bool isARMSOImmNot() const {
804 if (!isImm()) return false;
805 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
806 if (!CE) return false;
807 int64_t Value = CE->getValue();
808 return ARM_AM::getSOImmVal(~Value) != -1;
810 bool isARMSOImmNeg() const {
811 if (!isImm()) return false;
812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
813 if (!CE) return false;
814 int64_t Value = CE->getValue();
815 // Only use this when not representable as a plain so_imm.
816 return ARM_AM::getSOImmVal(Value) == -1 &&
817 ARM_AM::getSOImmVal(-Value) != -1;
819 bool isT2SOImm() const {
820 if (!isImm()) return false;
821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
822 if (!CE) return false;
823 int64_t Value = CE->getValue();
824 return ARM_AM::getT2SOImmVal(Value) != -1;
826 bool isT2SOImmNot() const {
827 if (!isImm()) return false;
828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
829 if (!CE) return false;
830 int64_t Value = CE->getValue();
831 return ARM_AM::getT2SOImmVal(~Value) != -1;
833 bool isT2SOImmNeg() const {
834 if (!isImm()) return false;
835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
836 if (!CE) return false;
837 int64_t Value = CE->getValue();
838 // Only use this when not representable as a plain so_imm.
839 return ARM_AM::getT2SOImmVal(Value) == -1 &&
840 ARM_AM::getT2SOImmVal(-Value) != -1;
842 bool isSetEndImm() const {
843 if (!isImm()) return false;
844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
847 return Value == 1 || Value == 0;
849 bool isReg() const { return Kind == k_Register; }
850 bool isRegList() const { return Kind == k_RegisterList; }
851 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
852 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
853 bool isToken() const { return Kind == k_Token; }
854 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
855 bool isMemory() const { return Kind == k_Memory; }
856 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
857 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
858 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
859 bool isRotImm() const { return Kind == k_RotateImmediate; }
860 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
861 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
862 bool isPostIdxReg() const {
863 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
865 bool isMemNoOffset(bool alignOK = false) const {
868 // No offset of any kind.
869 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
870 (alignOK || Memory.Alignment == 0);
872 bool isMemPCRelImm12() const {
873 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
875 // Base register must be PC.
876 if (Memory.BaseRegNum != ARM::PC)
878 // Immediate offset in range [-4095, 4095].
879 if (!Memory.OffsetImm) return true;
880 int64_t Val = Memory.OffsetImm->getValue();
881 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
883 bool isAlignedMemory() const {
884 return isMemNoOffset(true);
886 bool isAddrMode2() const {
887 if (!isMemory() || Memory.Alignment != 0) return false;
888 // Check for register offset.
889 if (Memory.OffsetRegNum) return true;
890 // Immediate offset in range [-4095, 4095].
891 if (!Memory.OffsetImm) return true;
892 int64_t Val = Memory.OffsetImm->getValue();
893 return Val > -4096 && Val < 4096;
895 bool isAM2OffsetImm() const {
896 if (!isImm()) return false;
897 // Immediate offset in range [-4095, 4095].
898 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
899 if (!CE) return false;
900 int64_t Val = CE->getValue();
901 return Val > -4096 && Val < 4096;
903 bool isAddrMode3() const {
904 // If we have an immediate that's not a constant, treat it as a label
905 // reference needing a fixup. If it is a constant, it's something else
907 if (isImm() && !isa<MCConstantExpr>(getImm()))
909 if (!isMemory() || Memory.Alignment != 0) return false;
910 // No shifts are legal for AM3.
911 if (Memory.ShiftType != ARM_AM::no_shift) return false;
912 // Check for register offset.
913 if (Memory.OffsetRegNum) return true;
914 // Immediate offset in range [-255, 255].
915 if (!Memory.OffsetImm) return true;
916 int64_t Val = Memory.OffsetImm->getValue();
917 return Val > -256 && Val < 256;
919 bool isAM3Offset() const {
920 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
922 if (Kind == k_PostIndexRegister)
923 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
924 // Immediate offset in range [-255, 255].
925 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
926 if (!CE) return false;
927 int64_t Val = CE->getValue();
928 // Special case, #-0 is INT32_MIN.
929 return (Val > -256 && Val < 256) || Val == INT32_MIN;
931 bool isAddrMode5() const {
932 // If we have an immediate that's not a constant, treat it as a label
933 // reference needing a fixup. If it is a constant, it's something else
935 if (isImm() && !isa<MCConstantExpr>(getImm()))
937 if (!isMemory() || Memory.Alignment != 0) return false;
938 // Check for register offset.
939 if (Memory.OffsetRegNum) return false;
940 // Immediate offset in range [-1020, 1020] and a multiple of 4.
941 if (!Memory.OffsetImm) return true;
942 int64_t Val = Memory.OffsetImm->getValue();
943 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
946 bool isMemTBB() const {
947 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
948 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
952 bool isMemTBH() const {
953 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
954 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
955 Memory.Alignment != 0 )
959 bool isMemRegOffset() const {
960 if (!isMemory() || !Memory.OffsetRegNum || Memory.Alignment != 0)
964 bool isT2MemRegOffset() const {
965 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
966 Memory.Alignment != 0)
968 // Only lsl #{0, 1, 2, 3} allowed.
969 if (Memory.ShiftType == ARM_AM::no_shift)
971 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
975 bool isMemThumbRR() const {
976 // Thumb reg+reg addressing is simple. Just two registers, a base and
977 // an offset. No shifts, negations or any other complicating factors.
978 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
979 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
981 return isARMLowRegister(Memory.BaseRegNum) &&
982 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
984 bool isMemThumbRIs4() const {
985 if (!isMemory() || Memory.OffsetRegNum != 0 ||
986 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
988 // Immediate offset, multiple of 4 in range [0, 124].
989 if (!Memory.OffsetImm) return true;
990 int64_t Val = Memory.OffsetImm->getValue();
991 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
993 bool isMemThumbRIs2() const {
994 if (!isMemory() || Memory.OffsetRegNum != 0 ||
995 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
997 // Immediate offset, multiple of 4 in range [0, 62].
998 if (!Memory.OffsetImm) return true;
999 int64_t Val = Memory.OffsetImm->getValue();
1000 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1002 bool isMemThumbRIs1() const {
1003 if (!isMemory() || Memory.OffsetRegNum != 0 ||
1004 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1006 // Immediate offset in range [0, 31].
1007 if (!Memory.OffsetImm) return true;
1008 int64_t Val = Memory.OffsetImm->getValue();
1009 return Val >= 0 && Val <= 31;
1011 bool isMemThumbSPI() const {
1012 if (!isMemory() || Memory.OffsetRegNum != 0 ||
1013 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1015 // Immediate offset, multiple of 4 in range [0, 1020].
1016 if (!Memory.OffsetImm) return true;
1017 int64_t Val = Memory.OffsetImm->getValue();
1018 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1020 bool isMemImm8s4Offset() const {
1021 // If we have an immediate that's not a constant, treat it as a label
1022 // reference needing a fixup. If it is a constant, it's something else
1023 // and we reject it.
1024 if (isImm() && !isa<MCConstantExpr>(getImm()))
1026 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1028 // Immediate offset a multiple of 4 in range [-1020, 1020].
1029 if (!Memory.OffsetImm) return true;
1030 int64_t Val = Memory.OffsetImm->getValue();
1031 return Val >= -1020 && Val <= 1020 && (Val & 3) == 0;
1033 bool isMemImm0_1020s4Offset() const {
1034 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1036 // Immediate offset a multiple of 4 in range [0, 1020].
1037 if (!Memory.OffsetImm) return true;
1038 int64_t Val = Memory.OffsetImm->getValue();
1039 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1041 bool isMemImm8Offset() const {
1042 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1044 // Base reg of PC isn't allowed for these encodings.
1045 if (Memory.BaseRegNum == ARM::PC) return false;
1046 // Immediate offset in range [-255, 255].
1047 if (!Memory.OffsetImm) return true;
1048 int64_t Val = Memory.OffsetImm->getValue();
1049 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1051 bool isMemPosImm8Offset() const {
1052 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1054 // Immediate offset in range [0, 255].
1055 if (!Memory.OffsetImm) return true;
1056 int64_t Val = Memory.OffsetImm->getValue();
1057 return Val >= 0 && Val < 256;
1059 bool isMemNegImm8Offset() const {
1060 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1062 // Base reg of PC isn't allowed for these encodings.
1063 if (Memory.BaseRegNum == ARM::PC) return false;
1064 // Immediate offset in range [-255, -1].
1065 if (!Memory.OffsetImm) return false;
1066 int64_t Val = Memory.OffsetImm->getValue();
1067 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1069 bool isMemUImm12Offset() const {
1070 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1072 // Immediate offset in range [0, 4095].
1073 if (!Memory.OffsetImm) return true;
1074 int64_t Val = Memory.OffsetImm->getValue();
1075 return (Val >= 0 && Val < 4096);
1077 bool isMemImm12Offset() const {
1078 // If we have an immediate that's not a constant, treat it as a label
1079 // reference needing a fixup. If it is a constant, it's something else
1080 // and we reject it.
1081 if (isImm() && !isa<MCConstantExpr>(getImm()))
1084 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1086 // Immediate offset in range [-4095, 4095].
1087 if (!Memory.OffsetImm) return true;
1088 int64_t Val = Memory.OffsetImm->getValue();
1089 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1091 bool isPostIdxImm8() const {
1092 if (!isImm()) return false;
1093 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1094 if (!CE) return false;
1095 int64_t Val = CE->getValue();
1096 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1098 bool isPostIdxImm8s4() const {
1099 if (!isImm()) return false;
1100 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1101 if (!CE) return false;
1102 int64_t Val = CE->getValue();
1103 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1107 bool isMSRMask() const { return Kind == k_MSRMask; }
1108 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1111 bool isSingleSpacedVectorList() const {
1112 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1114 bool isDoubleSpacedVectorList() const {
1115 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1117 bool isVecListOneD() const {
1118 if (!isSingleSpacedVectorList()) return false;
1119 return VectorList.Count == 1;
1122 bool isVecListDPair() const {
1123 if (!isSingleSpacedVectorList()) return false;
1124 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1125 .contains(VectorList.RegNum));
1128 bool isVecListThreeD() const {
1129 if (!isSingleSpacedVectorList()) return false;
1130 return VectorList.Count == 3;
1133 bool isVecListFourD() const {
1134 if (!isSingleSpacedVectorList()) return false;
1135 return VectorList.Count == 4;
1138 bool isVecListDPairSpaced() const {
1139 if (isSingleSpacedVectorList()) return false;
1140 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1141 .contains(VectorList.RegNum));
1144 bool isVecListThreeQ() const {
1145 if (!isDoubleSpacedVectorList()) return false;
1146 return VectorList.Count == 3;
1149 bool isVecListFourQ() const {
1150 if (!isDoubleSpacedVectorList()) return false;
1151 return VectorList.Count == 4;
1154 bool isSingleSpacedVectorAllLanes() const {
1155 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1157 bool isDoubleSpacedVectorAllLanes() const {
1158 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1160 bool isVecListOneDAllLanes() const {
1161 if (!isSingleSpacedVectorAllLanes()) return false;
1162 return VectorList.Count == 1;
1165 bool isVecListDPairAllLanes() const {
1166 if (!isSingleSpacedVectorAllLanes()) return false;
1167 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1168 .contains(VectorList.RegNum));
1171 bool isVecListDPairSpacedAllLanes() const {
1172 if (!isDoubleSpacedVectorAllLanes()) return false;
1173 return VectorList.Count == 2;
1176 bool isVecListThreeDAllLanes() const {
1177 if (!isSingleSpacedVectorAllLanes()) return false;
1178 return VectorList.Count == 3;
1181 bool isVecListThreeQAllLanes() const {
1182 if (!isDoubleSpacedVectorAllLanes()) return false;
1183 return VectorList.Count == 3;
1186 bool isVecListFourDAllLanes() const {
1187 if (!isSingleSpacedVectorAllLanes()) return false;
1188 return VectorList.Count == 4;
1191 bool isVecListFourQAllLanes() const {
1192 if (!isDoubleSpacedVectorAllLanes()) return false;
1193 return VectorList.Count == 4;
1196 bool isSingleSpacedVectorIndexed() const {
1197 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1199 bool isDoubleSpacedVectorIndexed() const {
1200 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1202 bool isVecListOneDByteIndexed() const {
1203 if (!isSingleSpacedVectorIndexed()) return false;
1204 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1207 bool isVecListOneDHWordIndexed() const {
1208 if (!isSingleSpacedVectorIndexed()) return false;
1209 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1212 bool isVecListOneDWordIndexed() const {
1213 if (!isSingleSpacedVectorIndexed()) return false;
1214 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1217 bool isVecListTwoDByteIndexed() const {
1218 if (!isSingleSpacedVectorIndexed()) return false;
1219 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1222 bool isVecListTwoDHWordIndexed() const {
1223 if (!isSingleSpacedVectorIndexed()) return false;
1224 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1227 bool isVecListTwoQWordIndexed() const {
1228 if (!isDoubleSpacedVectorIndexed()) return false;
1229 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1232 bool isVecListTwoQHWordIndexed() const {
1233 if (!isDoubleSpacedVectorIndexed()) return false;
1234 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1237 bool isVecListTwoDWordIndexed() const {
1238 if (!isSingleSpacedVectorIndexed()) return false;
1239 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1242 bool isVecListThreeDByteIndexed() const {
1243 if (!isSingleSpacedVectorIndexed()) return false;
1244 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1247 bool isVecListThreeDHWordIndexed() const {
1248 if (!isSingleSpacedVectorIndexed()) return false;
1249 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1252 bool isVecListThreeQWordIndexed() const {
1253 if (!isDoubleSpacedVectorIndexed()) return false;
1254 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1257 bool isVecListThreeQHWordIndexed() const {
1258 if (!isDoubleSpacedVectorIndexed()) return false;
1259 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1262 bool isVecListThreeDWordIndexed() const {
1263 if (!isSingleSpacedVectorIndexed()) return false;
1264 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1267 bool isVecListFourDByteIndexed() const {
1268 if (!isSingleSpacedVectorIndexed()) return false;
1269 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1272 bool isVecListFourDHWordIndexed() const {
1273 if (!isSingleSpacedVectorIndexed()) return false;
1274 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1277 bool isVecListFourQWordIndexed() const {
1278 if (!isDoubleSpacedVectorIndexed()) return false;
1279 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1282 bool isVecListFourQHWordIndexed() const {
1283 if (!isDoubleSpacedVectorIndexed()) return false;
1284 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1287 bool isVecListFourDWordIndexed() const {
1288 if (!isSingleSpacedVectorIndexed()) return false;
1289 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1292 bool isVectorIndex8() const {
1293 if (Kind != k_VectorIndex) return false;
1294 return VectorIndex.Val < 8;
1296 bool isVectorIndex16() const {
1297 if (Kind != k_VectorIndex) return false;
1298 return VectorIndex.Val < 4;
1300 bool isVectorIndex32() const {
1301 if (Kind != k_VectorIndex) return false;
1302 return VectorIndex.Val < 2;
1305 bool isNEONi8splat() const {
1306 if (!isImm()) return false;
1307 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1308 // Must be a constant.
1309 if (!CE) return false;
1310 int64_t Value = CE->getValue();
1311 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1313 return Value >= 0 && Value < 256;
1316 bool isNEONi16splat() const {
1317 if (!isImm()) return false;
1318 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1319 // Must be a constant.
1320 if (!CE) return false;
1321 int64_t Value = CE->getValue();
1322 // i16 value in the range [0,255] or [0x0100, 0xff00]
1323 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1326 bool isNEONi32splat() const {
1327 if (!isImm()) return false;
1328 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1329 // Must be a constant.
1330 if (!CE) return false;
1331 int64_t Value = CE->getValue();
1332 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1333 return (Value >= 0 && Value < 256) ||
1334 (Value >= 0x0100 && Value <= 0xff00) ||
1335 (Value >= 0x010000 && Value <= 0xff0000) ||
1336 (Value >= 0x01000000 && Value <= 0xff000000);
1339 bool isNEONi32vmov() const {
1340 if (!isImm()) return false;
1341 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1342 // Must be a constant.
1343 if (!CE) return false;
1344 int64_t Value = CE->getValue();
1345 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1346 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1347 return (Value >= 0 && Value < 256) ||
1348 (Value >= 0x0100 && Value <= 0xff00) ||
1349 (Value >= 0x010000 && Value <= 0xff0000) ||
1350 (Value >= 0x01000000 && Value <= 0xff000000) ||
1351 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1352 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1354 bool isNEONi32vmovNeg() const {
1355 if (!isImm()) return false;
1356 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1357 // Must be a constant.
1358 if (!CE) return false;
1359 int64_t Value = ~CE->getValue();
1360 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1361 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1362 return (Value >= 0 && Value < 256) ||
1363 (Value >= 0x0100 && Value <= 0xff00) ||
1364 (Value >= 0x010000 && Value <= 0xff0000) ||
1365 (Value >= 0x01000000 && Value <= 0xff000000) ||
1366 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1367 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1370 bool isNEONi64splat() const {
1371 if (!isImm()) return false;
1372 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1373 // Must be a constant.
1374 if (!CE) return false;
1375 uint64_t Value = CE->getValue();
1376 // i64 value with each byte being either 0 or 0xff.
1377 for (unsigned i = 0; i < 8; ++i)
1378 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1382 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1383 // Add as immediates when possible. Null MCExpr = 0.
1385 Inst.addOperand(MCOperand::CreateImm(0));
1386 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1387 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1389 Inst.addOperand(MCOperand::CreateExpr(Expr));
1392 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1393 assert(N == 2 && "Invalid number of operands!");
1394 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1395 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1396 Inst.addOperand(MCOperand::CreateReg(RegNum));
1399 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1400 assert(N == 1 && "Invalid number of operands!");
1401 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1404 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1405 assert(N == 1 && "Invalid number of operands!");
1406 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1409 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1410 assert(N == 1 && "Invalid number of operands!");
1411 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1414 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1415 assert(N == 1 && "Invalid number of operands!");
1416 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1419 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1420 assert(N == 1 && "Invalid number of operands!");
1421 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1424 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1425 assert(N == 1 && "Invalid number of operands!");
1426 Inst.addOperand(MCOperand::CreateReg(getReg()));
1429 void addRegOperands(MCInst &Inst, unsigned N) const {
1430 assert(N == 1 && "Invalid number of operands!");
1431 Inst.addOperand(MCOperand::CreateReg(getReg()));
1434 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1435 assert(N == 3 && "Invalid number of operands!");
1436 assert(isRegShiftedReg() &&
1437 "addRegShiftedRegOperands() on non RegShiftedReg!");
1438 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1439 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1440 Inst.addOperand(MCOperand::CreateImm(
1441 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1444 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1445 assert(N == 2 && "Invalid number of operands!");
1446 assert(isRegShiftedImm() &&
1447 "addRegShiftedImmOperands() on non RegShiftedImm!");
1448 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1449 // Shift of #32 is encoded as 0 where permitted
1450 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1451 Inst.addOperand(MCOperand::CreateImm(
1452 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1455 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1456 assert(N == 1 && "Invalid number of operands!");
1457 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1461 void addRegListOperands(MCInst &Inst, unsigned N) const {
1462 assert(N == 1 && "Invalid number of operands!");
1463 const SmallVectorImpl<unsigned> &RegList = getRegList();
1464 for (SmallVectorImpl<unsigned>::const_iterator
1465 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1466 Inst.addOperand(MCOperand::CreateReg(*I));
1469 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1470 addRegListOperands(Inst, N);
1473 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1474 addRegListOperands(Inst, N);
1477 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1478 assert(N == 1 && "Invalid number of operands!");
1479 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1480 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1483 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1484 assert(N == 1 && "Invalid number of operands!");
1485 // Munge the lsb/width into a bitfield mask.
1486 unsigned lsb = Bitfield.LSB;
1487 unsigned width = Bitfield.Width;
1488 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1489 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1490 (32 - (lsb + width)));
1491 Inst.addOperand(MCOperand::CreateImm(Mask));
1494 void addImmOperands(MCInst &Inst, unsigned N) const {
1495 assert(N == 1 && "Invalid number of operands!");
1496 addExpr(Inst, getImm());
1499 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1500 assert(N == 1 && "Invalid number of operands!");
1501 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1502 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1505 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1506 assert(N == 1 && "Invalid number of operands!");
1507 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1508 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1511 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1512 assert(N == 1 && "Invalid number of operands!");
1513 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1514 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1515 Inst.addOperand(MCOperand::CreateImm(Val));
1518 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1519 assert(N == 1 && "Invalid number of operands!");
1520 // FIXME: We really want to scale the value here, but the LDRD/STRD
1521 // instruction don't encode operands that way yet.
1522 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1523 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1526 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1527 assert(N == 1 && "Invalid number of operands!");
1528 // The immediate is scaled by four in the encoding and is stored
1529 // in the MCInst as such. Lop off the low two bits here.
1530 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1531 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1534 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1535 assert(N == 1 && "Invalid number of operands!");
1536 // The immediate is scaled by four in the encoding and is stored
1537 // in the MCInst as such. Lop off the low two bits here.
1538 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1539 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1542 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1543 assert(N == 1 && "Invalid number of operands!");
1544 // The immediate is scaled by four in the encoding and is stored
1545 // in the MCInst as such. Lop off the low two bits here.
1546 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1547 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1550 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1551 assert(N == 1 && "Invalid number of operands!");
1552 // The constant encodes as the immediate-1, and we store in the instruction
1553 // the bits as encoded, so subtract off one here.
1554 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1555 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1558 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1559 assert(N == 1 && "Invalid number of operands!");
1560 // The constant encodes as the immediate-1, and we store in the instruction
1561 // the bits as encoded, so subtract off one here.
1562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1563 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1566 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1567 assert(N == 1 && "Invalid number of operands!");
1568 // The constant encodes as the immediate, except for 32, which encodes as
1570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1571 unsigned Imm = CE->getValue();
1572 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1575 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1576 assert(N == 1 && "Invalid number of operands!");
1577 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1578 // the instruction as well.
1579 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1580 int Val = CE->getValue();
1581 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1584 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1585 assert(N == 1 && "Invalid number of operands!");
1586 // The operand is actually a t2_so_imm, but we have its bitwise
1587 // negation in the assembly source, so twiddle it here.
1588 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1589 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1592 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1593 assert(N == 1 && "Invalid number of operands!");
1594 // The operand is actually a t2_so_imm, but we have its
1595 // negation in the assembly source, so twiddle it here.
1596 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1597 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1600 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1601 assert(N == 1 && "Invalid number of operands!");
1602 // The operand is actually an imm0_4095, but we have its
1603 // negation in the assembly source, so twiddle it here.
1604 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1605 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1608 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1609 assert(N == 1 && "Invalid number of operands!");
1610 // The operand is actually a so_imm, but we have its bitwise
1611 // negation in the assembly source, so twiddle it here.
1612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1613 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1616 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1617 assert(N == 1 && "Invalid number of operands!");
1618 // The operand is actually a so_imm, but we have its
1619 // negation in the assembly source, so twiddle it here.
1620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1621 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1624 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1625 assert(N == 1 && "Invalid number of operands!");
1626 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1629 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1630 assert(N == 1 && "Invalid number of operands!");
1631 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1634 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1635 assert(N == 1 && "Invalid number of operands!");
1636 int32_t Imm = Memory.OffsetImm->getValue();
1637 // FIXME: Handle #-0
1638 if (Imm == INT32_MIN) Imm = 0;
1639 Inst.addOperand(MCOperand::CreateImm(Imm));
1642 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1643 assert(N == 2 && "Invalid number of operands!");
1644 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1645 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1648 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1649 assert(N == 3 && "Invalid number of operands!");
1650 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1651 if (!Memory.OffsetRegNum) {
1652 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1653 // Special case for #-0
1654 if (Val == INT32_MIN) Val = 0;
1655 if (Val < 0) Val = -Val;
1656 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1658 // For register offset, we encode the shift type and negation flag
1660 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1661 Memory.ShiftImm, Memory.ShiftType);
1663 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1664 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1665 Inst.addOperand(MCOperand::CreateImm(Val));
1668 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1669 assert(N == 2 && "Invalid number of operands!");
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 assert(CE && "non-constant AM2OffsetImm operand!");
1672 int32_t Val = CE->getValue();
1673 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1674 // Special case for #-0
1675 if (Val == INT32_MIN) Val = 0;
1676 if (Val < 0) Val = -Val;
1677 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1678 Inst.addOperand(MCOperand::CreateReg(0));
1679 Inst.addOperand(MCOperand::CreateImm(Val));
1682 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1683 assert(N == 3 && "Invalid number of operands!");
1684 // If we have an immediate that's not a constant, treat it as a label
1685 // reference needing a fixup. If it is a constant, it's something else
1686 // and we reject it.
1688 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1689 Inst.addOperand(MCOperand::CreateReg(0));
1690 Inst.addOperand(MCOperand::CreateImm(0));
1694 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1695 if (!Memory.OffsetRegNum) {
1696 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1697 // Special case for #-0
1698 if (Val == INT32_MIN) Val = 0;
1699 if (Val < 0) Val = -Val;
1700 Val = ARM_AM::getAM3Opc(AddSub, Val);
1702 // For register offset, we encode the shift type and negation flag
1704 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1706 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1707 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1708 Inst.addOperand(MCOperand::CreateImm(Val));
1711 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1712 assert(N == 2 && "Invalid number of operands!");
1713 if (Kind == k_PostIndexRegister) {
1715 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1716 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1717 Inst.addOperand(MCOperand::CreateImm(Val));
1722 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1723 int32_t Val = CE->getValue();
1724 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1725 // Special case for #-0
1726 if (Val == INT32_MIN) Val = 0;
1727 if (Val < 0) Val = -Val;
1728 Val = ARM_AM::getAM3Opc(AddSub, Val);
1729 Inst.addOperand(MCOperand::CreateReg(0));
1730 Inst.addOperand(MCOperand::CreateImm(Val));
1733 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1734 assert(N == 2 && "Invalid number of operands!");
1735 // If we have an immediate that's not a constant, treat it as a label
1736 // reference needing a fixup. If it is a constant, it's something else
1737 // and we reject it.
1739 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1740 Inst.addOperand(MCOperand::CreateImm(0));
1744 // The lower two bits are always zero and as such are not encoded.
1745 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1746 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1747 // Special case for #-0
1748 if (Val == INT32_MIN) Val = 0;
1749 if (Val < 0) Val = -Val;
1750 Val = ARM_AM::getAM5Opc(AddSub, Val);
1751 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1752 Inst.addOperand(MCOperand::CreateImm(Val));
1755 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1756 assert(N == 2 && "Invalid number of operands!");
1757 // If we have an immediate that's not a constant, treat it as a label
1758 // reference needing a fixup. If it is a constant, it's something else
1759 // and we reject it.
1761 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1762 Inst.addOperand(MCOperand::CreateImm(0));
1766 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1767 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1768 Inst.addOperand(MCOperand::CreateImm(Val));
1771 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1772 assert(N == 2 && "Invalid number of operands!");
1773 // The lower two bits are always zero and as such are not encoded.
1774 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1775 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1776 Inst.addOperand(MCOperand::CreateImm(Val));
1779 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1780 assert(N == 2 && "Invalid number of operands!");
1781 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1782 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1783 Inst.addOperand(MCOperand::CreateImm(Val));
1786 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1787 addMemImm8OffsetOperands(Inst, N);
1790 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1791 addMemImm8OffsetOperands(Inst, N);
1794 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 2 && "Invalid number of operands!");
1796 // If this is an immediate, it's a label reference.
1798 addExpr(Inst, getImm());
1799 Inst.addOperand(MCOperand::CreateImm(0));
1803 // Otherwise, it's a normal memory reg+offset.
1804 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1805 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1806 Inst.addOperand(MCOperand::CreateImm(Val));
1809 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1810 assert(N == 2 && "Invalid number of operands!");
1811 // If this is an immediate, it's a label reference.
1813 addExpr(Inst, getImm());
1814 Inst.addOperand(MCOperand::CreateImm(0));
1818 // Otherwise, it's a normal memory reg+offset.
1819 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1820 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1821 Inst.addOperand(MCOperand::CreateImm(Val));
1824 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1825 assert(N == 2 && "Invalid number of operands!");
1826 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1827 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1830 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1831 assert(N == 2 && "Invalid number of operands!");
1832 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1833 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1836 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1837 assert(N == 3 && "Invalid number of operands!");
1839 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1840 Memory.ShiftImm, Memory.ShiftType);
1841 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1842 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1843 Inst.addOperand(MCOperand::CreateImm(Val));
1846 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1847 assert(N == 3 && "Invalid number of operands!");
1848 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1849 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1850 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1853 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1854 assert(N == 2 && "Invalid number of operands!");
1855 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1856 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1859 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1860 assert(N == 2 && "Invalid number of operands!");
1861 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1862 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1863 Inst.addOperand(MCOperand::CreateImm(Val));
1866 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1867 assert(N == 2 && "Invalid number of operands!");
1868 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1869 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1870 Inst.addOperand(MCOperand::CreateImm(Val));
1873 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1874 assert(N == 2 && "Invalid number of operands!");
1875 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1876 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1877 Inst.addOperand(MCOperand::CreateImm(Val));
1880 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1881 assert(N == 2 && "Invalid number of operands!");
1882 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1883 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1884 Inst.addOperand(MCOperand::CreateImm(Val));
1887 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1888 assert(N == 1 && "Invalid number of operands!");
1889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1890 assert(CE && "non-constant post-idx-imm8 operand!");
1891 int Imm = CE->getValue();
1892 bool isAdd = Imm >= 0;
1893 if (Imm == INT32_MIN) Imm = 0;
1894 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1895 Inst.addOperand(MCOperand::CreateImm(Imm));
1898 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1899 assert(N == 1 && "Invalid number of operands!");
1900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1901 assert(CE && "non-constant post-idx-imm8s4 operand!");
1902 int Imm = CE->getValue();
1903 bool isAdd = Imm >= 0;
1904 if (Imm == INT32_MIN) Imm = 0;
1905 // Immediate is scaled by 4.
1906 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1907 Inst.addOperand(MCOperand::CreateImm(Imm));
1910 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1911 assert(N == 2 && "Invalid number of operands!");
1912 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1913 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1916 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1917 assert(N == 2 && "Invalid number of operands!");
1918 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1919 // The sign, shift type, and shift amount are encoded in a single operand
1920 // using the AM2 encoding helpers.
1921 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1922 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1923 PostIdxReg.ShiftTy);
1924 Inst.addOperand(MCOperand::CreateImm(Imm));
1927 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1928 assert(N == 1 && "Invalid number of operands!");
1929 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1932 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1933 assert(N == 1 && "Invalid number of operands!");
1934 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1937 void addVecListOperands(MCInst &Inst, unsigned N) const {
1938 assert(N == 1 && "Invalid number of operands!");
1939 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1942 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1943 assert(N == 2 && "Invalid number of operands!");
1944 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1945 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1948 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1949 assert(N == 1 && "Invalid number of operands!");
1950 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1953 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1954 assert(N == 1 && "Invalid number of operands!");
1955 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1958 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1959 assert(N == 1 && "Invalid number of operands!");
1960 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1963 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1964 assert(N == 1 && "Invalid number of operands!");
1965 // The immediate encodes the type of constant as well as the value.
1966 // Mask in that this is an i8 splat.
1967 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1968 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1971 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1972 assert(N == 1 && "Invalid number of operands!");
1973 // The immediate encodes the type of constant as well as the value.
1974 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1975 unsigned Value = CE->getValue();
1977 Value = (Value >> 8) | 0xa00;
1980 Inst.addOperand(MCOperand::CreateImm(Value));
1983 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
1984 assert(N == 1 && "Invalid number of operands!");
1985 // The immediate encodes the type of constant as well as the value.
1986 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1987 unsigned Value = CE->getValue();
1988 if (Value >= 256 && Value <= 0xff00)
1989 Value = (Value >> 8) | 0x200;
1990 else if (Value > 0xffff && Value <= 0xff0000)
1991 Value = (Value >> 16) | 0x400;
1992 else if (Value > 0xffffff)
1993 Value = (Value >> 24) | 0x600;
1994 Inst.addOperand(MCOperand::CreateImm(Value));
1997 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
1998 assert(N == 1 && "Invalid number of operands!");
1999 // The immediate encodes the type of constant as well as the value.
2000 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2001 unsigned Value = CE->getValue();
2002 if (Value >= 256 && Value <= 0xffff)
2003 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2004 else if (Value > 0xffff && Value <= 0xffffff)
2005 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2006 else if (Value > 0xffffff)
2007 Value = (Value >> 24) | 0x600;
2008 Inst.addOperand(MCOperand::CreateImm(Value));
2011 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2012 assert(N == 1 && "Invalid number of operands!");
2013 // The immediate encodes the type of constant as well as the value.
2014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2015 unsigned Value = ~CE->getValue();
2016 if (Value >= 256 && Value <= 0xffff)
2017 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2018 else if (Value > 0xffff && Value <= 0xffffff)
2019 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2020 else if (Value > 0xffffff)
2021 Value = (Value >> 24) | 0x600;
2022 Inst.addOperand(MCOperand::CreateImm(Value));
2025 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2026 assert(N == 1 && "Invalid number of operands!");
2027 // The immediate encodes the type of constant as well as the value.
2028 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2029 uint64_t Value = CE->getValue();
2031 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2032 Imm |= (Value & 1) << i;
2034 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2037 virtual void print(raw_ostream &OS) const;
2039 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2040 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2041 Op->ITMask.Mask = Mask;
2047 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2048 ARMOperand *Op = new ARMOperand(k_CondCode);
2055 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2056 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2057 Op->Cop.Val = CopVal;
2063 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2064 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2065 Op->Cop.Val = CopVal;
2071 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2072 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2079 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2080 ARMOperand *Op = new ARMOperand(k_CCOut);
2081 Op->Reg.RegNum = RegNum;
2087 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2088 ARMOperand *Op = new ARMOperand(k_Token);
2089 Op->Tok.Data = Str.data();
2090 Op->Tok.Length = Str.size();
2096 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2097 ARMOperand *Op = new ARMOperand(k_Register);
2098 Op->Reg.RegNum = RegNum;
2104 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2109 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2110 Op->RegShiftedReg.ShiftTy = ShTy;
2111 Op->RegShiftedReg.SrcReg = SrcReg;
2112 Op->RegShiftedReg.ShiftReg = ShiftReg;
2113 Op->RegShiftedReg.ShiftImm = ShiftImm;
2119 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2123 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2124 Op->RegShiftedImm.ShiftTy = ShTy;
2125 Op->RegShiftedImm.SrcReg = SrcReg;
2126 Op->RegShiftedImm.ShiftImm = ShiftImm;
2132 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2134 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2135 Op->ShifterImm.isASR = isASR;
2136 Op->ShifterImm.Imm = Imm;
2142 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2143 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2144 Op->RotImm.Imm = Imm;
2150 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2152 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2153 Op->Bitfield.LSB = LSB;
2154 Op->Bitfield.Width = Width;
2161 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
2162 SMLoc StartLoc, SMLoc EndLoc) {
2163 KindTy Kind = k_RegisterList;
2165 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
2166 Kind = k_DPRRegisterList;
2167 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2168 contains(Regs.front().first))
2169 Kind = k_SPRRegisterList;
2171 ARMOperand *Op = new ARMOperand(Kind);
2172 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
2173 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2174 Op->Registers.push_back(I->first);
2175 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
2176 Op->StartLoc = StartLoc;
2177 Op->EndLoc = EndLoc;
2181 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2182 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2183 ARMOperand *Op = new ARMOperand(k_VectorList);
2184 Op->VectorList.RegNum = RegNum;
2185 Op->VectorList.Count = Count;
2186 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2192 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2193 bool isDoubleSpaced,
2195 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2196 Op->VectorList.RegNum = RegNum;
2197 Op->VectorList.Count = Count;
2198 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2204 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2206 bool isDoubleSpaced,
2208 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2209 Op->VectorList.RegNum = RegNum;
2210 Op->VectorList.Count = Count;
2211 Op->VectorList.LaneIndex = Index;
2212 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2218 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2220 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2221 Op->VectorIndex.Val = Idx;
2227 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2228 ARMOperand *Op = new ARMOperand(k_Immediate);
2235 static ARMOperand *CreateMem(unsigned BaseRegNum,
2236 const MCConstantExpr *OffsetImm,
2237 unsigned OffsetRegNum,
2238 ARM_AM::ShiftOpc ShiftType,
2243 ARMOperand *Op = new ARMOperand(k_Memory);
2244 Op->Memory.BaseRegNum = BaseRegNum;
2245 Op->Memory.OffsetImm = OffsetImm;
2246 Op->Memory.OffsetRegNum = OffsetRegNum;
2247 Op->Memory.ShiftType = ShiftType;
2248 Op->Memory.ShiftImm = ShiftImm;
2249 Op->Memory.Alignment = Alignment;
2250 Op->Memory.isNegative = isNegative;
2256 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2257 ARM_AM::ShiftOpc ShiftTy,
2260 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2261 Op->PostIdxReg.RegNum = RegNum;
2262 Op->PostIdxReg.isAdd = isAdd;
2263 Op->PostIdxReg.ShiftTy = ShiftTy;
2264 Op->PostIdxReg.ShiftImm = ShiftImm;
2270 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2271 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2272 Op->MBOpt.Val = Opt;
2278 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2279 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2280 Op->IFlags.Val = IFlags;
2286 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2287 ARMOperand *Op = new ARMOperand(k_MSRMask);
2288 Op->MMask.Val = MMask;
2295 } // end anonymous namespace.
2297 void ARMOperand::print(raw_ostream &OS) const {
2300 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2303 OS << "<ccout " << getReg() << ">";
2305 case k_ITCondMask: {
2306 static const char *MaskStr[] = {
2307 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2308 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2310 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2311 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2315 OS << "<coprocessor number: " << getCoproc() << ">";
2318 OS << "<coprocessor register: " << getCoproc() << ">";
2320 case k_CoprocOption:
2321 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2324 OS << "<mask: " << getMSRMask() << ">";
2327 getImm()->print(OS);
2329 case k_MemBarrierOpt:
2330 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2334 << " base:" << Memory.BaseRegNum;
2337 case k_PostIndexRegister:
2338 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2339 << PostIdxReg.RegNum;
2340 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2341 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2342 << PostIdxReg.ShiftImm;
2345 case k_ProcIFlags: {
2346 OS << "<ARM_PROC::";
2347 unsigned IFlags = getProcIFlags();
2348 for (int i=2; i >= 0; --i)
2349 if (IFlags & (1 << i))
2350 OS << ARM_PROC::IFlagsToString(1 << i);
2355 OS << "<register " << getReg() << ">";
2357 case k_ShifterImmediate:
2358 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2359 << " #" << ShifterImm.Imm << ">";
2361 case k_ShiftedRegister:
2362 OS << "<so_reg_reg "
2363 << RegShiftedReg.SrcReg << " "
2364 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2365 << " " << RegShiftedReg.ShiftReg << ">";
2367 case k_ShiftedImmediate:
2368 OS << "<so_reg_imm "
2369 << RegShiftedImm.SrcReg << " "
2370 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2371 << " #" << RegShiftedImm.ShiftImm << ">";
2373 case k_RotateImmediate:
2374 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2376 case k_BitfieldDescriptor:
2377 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2378 << ", width: " << Bitfield.Width << ">";
2380 case k_RegisterList:
2381 case k_DPRRegisterList:
2382 case k_SPRRegisterList: {
2383 OS << "<register_list ";
2385 const SmallVectorImpl<unsigned> &RegList = getRegList();
2386 for (SmallVectorImpl<unsigned>::const_iterator
2387 I = RegList.begin(), E = RegList.end(); I != E; ) {
2389 if (++I < E) OS << ", ";
2396 OS << "<vector_list " << VectorList.Count << " * "
2397 << VectorList.RegNum << ">";
2399 case k_VectorListAllLanes:
2400 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2401 << VectorList.RegNum << ">";
2403 case k_VectorListIndexed:
2404 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2405 << VectorList.Count << " * " << VectorList.RegNum << ">";
2408 OS << "'" << getToken() << "'";
2411 OS << "<vectorindex " << getVectorIndex() << ">";
2416 /// @name Auto-generated Match Functions
2419 static unsigned MatchRegisterName(StringRef Name);
2423 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2424 SMLoc &StartLoc, SMLoc &EndLoc) {
2425 StartLoc = Parser.getTok().getLoc();
2426 RegNo = tryParseRegister();
2427 EndLoc = Parser.getTok().getLoc();
2429 return (RegNo == (unsigned)-1);
2432 /// Try to parse a register name. The token must be an Identifier when called,
2433 /// and if it is a register name the token is eaten and the register number is
2434 /// returned. Otherwise return -1.
2436 int ARMAsmParser::tryParseRegister() {
2437 const AsmToken &Tok = Parser.getTok();
2438 if (Tok.isNot(AsmToken::Identifier)) return -1;
2440 std::string lowerCase = Tok.getString().lower();
2441 unsigned RegNum = MatchRegisterName(lowerCase);
2443 RegNum = StringSwitch<unsigned>(lowerCase)
2444 .Case("r13", ARM::SP)
2445 .Case("r14", ARM::LR)
2446 .Case("r15", ARM::PC)
2447 .Case("ip", ARM::R12)
2448 // Additional register name aliases for 'gas' compatibility.
2449 .Case("a1", ARM::R0)
2450 .Case("a2", ARM::R1)
2451 .Case("a3", ARM::R2)
2452 .Case("a4", ARM::R3)
2453 .Case("v1", ARM::R4)
2454 .Case("v2", ARM::R5)
2455 .Case("v3", ARM::R6)
2456 .Case("v4", ARM::R7)
2457 .Case("v5", ARM::R8)
2458 .Case("v6", ARM::R9)
2459 .Case("v7", ARM::R10)
2460 .Case("v8", ARM::R11)
2461 .Case("sb", ARM::R9)
2462 .Case("sl", ARM::R10)
2463 .Case("fp", ARM::R11)
2467 // Check for aliases registered via .req. Canonicalize to lower case.
2468 // That's more consistent since register names are case insensitive, and
2469 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2470 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2471 // If no match, return failure.
2472 if (Entry == RegisterReqs.end())
2474 Parser.Lex(); // Eat identifier token.
2475 return Entry->getValue();
2478 Parser.Lex(); // Eat identifier token.
2483 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2484 // If a recoverable error occurs, return 1. If an irrecoverable error
2485 // occurs, return -1. An irrecoverable error is one where tokens have been
2486 // consumed in the process of trying to parse the shifter (i.e., when it is
2487 // indeed a shifter operand, but malformed).
2488 int ARMAsmParser::tryParseShiftRegister(
2489 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2490 SMLoc S = Parser.getTok().getLoc();
2491 const AsmToken &Tok = Parser.getTok();
2492 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2494 std::string lowerCase = Tok.getString().lower();
2495 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2496 .Case("asl", ARM_AM::lsl)
2497 .Case("lsl", ARM_AM::lsl)
2498 .Case("lsr", ARM_AM::lsr)
2499 .Case("asr", ARM_AM::asr)
2500 .Case("ror", ARM_AM::ror)
2501 .Case("rrx", ARM_AM::rrx)
2502 .Default(ARM_AM::no_shift);
2504 if (ShiftTy == ARM_AM::no_shift)
2507 Parser.Lex(); // Eat the operator.
2509 // The source register for the shift has already been added to the
2510 // operand list, so we need to pop it off and combine it into the shifted
2511 // register operand instead.
2512 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2513 if (!PrevOp->isReg())
2514 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2515 int SrcReg = PrevOp->getReg();
2518 if (ShiftTy == ARM_AM::rrx) {
2519 // RRX Doesn't have an explicit shift amount. The encoder expects
2520 // the shift register to be the same as the source register. Seems odd,
2524 // Figure out if this is shifted by a constant or a register (for non-RRX).
2525 if (Parser.getTok().is(AsmToken::Hash) ||
2526 Parser.getTok().is(AsmToken::Dollar)) {
2527 Parser.Lex(); // Eat hash.
2528 SMLoc ImmLoc = Parser.getTok().getLoc();
2529 const MCExpr *ShiftExpr = 0;
2530 if (getParser().ParseExpression(ShiftExpr)) {
2531 Error(ImmLoc, "invalid immediate shift value");
2534 // The expression must be evaluatable as an immediate.
2535 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2537 Error(ImmLoc, "invalid immediate shift value");
2540 // Range check the immediate.
2541 // lsl, ror: 0 <= imm <= 31
2542 // lsr, asr: 0 <= imm <= 32
2543 Imm = CE->getValue();
2545 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2546 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2547 Error(ImmLoc, "immediate shift value out of range");
2550 // shift by zero is a nop. Always send it through as lsl.
2551 // ('as' compatibility)
2553 ShiftTy = ARM_AM::lsl;
2554 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2555 ShiftReg = tryParseRegister();
2556 SMLoc L = Parser.getTok().getLoc();
2557 if (ShiftReg == -1) {
2558 Error (L, "expected immediate or register in shift operand");
2562 Error (Parser.getTok().getLoc(),
2563 "expected immediate or register in shift operand");
2568 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2569 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2571 S, Parser.getTok().getLoc()));
2573 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2574 S, Parser.getTok().getLoc()));
2580 /// Try to parse a register name. The token must be an Identifier when called.
2581 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2582 /// if there is a "writeback". 'true' if it's not a register.
2584 /// TODO this is likely to change to allow different register types and or to
2585 /// parse for a specific register type.
2587 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2588 SMLoc S = Parser.getTok().getLoc();
2589 int RegNo = tryParseRegister();
2593 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
2595 const AsmToken &ExclaimTok = Parser.getTok();
2596 if (ExclaimTok.is(AsmToken::Exclaim)) {
2597 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2598 ExclaimTok.getLoc()));
2599 Parser.Lex(); // Eat exclaim token
2603 // Also check for an index operand. This is only legal for vector registers,
2604 // but that'll get caught OK in operand matching, so we don't need to
2605 // explicitly filter everything else out here.
2606 if (Parser.getTok().is(AsmToken::LBrac)) {
2607 SMLoc SIdx = Parser.getTok().getLoc();
2608 Parser.Lex(); // Eat left bracket token.
2610 const MCExpr *ImmVal;
2611 if (getParser().ParseExpression(ImmVal))
2613 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2615 return TokError("immediate value expected for vector index");
2617 SMLoc E = Parser.getTok().getLoc();
2618 if (Parser.getTok().isNot(AsmToken::RBrac))
2619 return Error(E, "']' expected");
2621 Parser.Lex(); // Eat right bracket token.
2623 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2631 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2632 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2634 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2635 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2637 switch (Name.size()) {
2640 if (Name[0] != CoprocOp)
2656 if (Name[0] != CoprocOp || Name[1] != '1')
2660 case '0': return 10;
2661 case '1': return 11;
2662 case '2': return 12;
2663 case '3': return 13;
2664 case '4': return 14;
2665 case '5': return 15;
2670 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2671 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2672 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2673 SMLoc S = Parser.getTok().getLoc();
2674 const AsmToken &Tok = Parser.getTok();
2675 if (!Tok.is(AsmToken::Identifier))
2676 return MatchOperand_NoMatch;
2677 unsigned CC = StringSwitch<unsigned>(Tok.getString())
2678 .Case("eq", ARMCC::EQ)
2679 .Case("ne", ARMCC::NE)
2680 .Case("hs", ARMCC::HS)
2681 .Case("cs", ARMCC::HS)
2682 .Case("lo", ARMCC::LO)
2683 .Case("cc", ARMCC::LO)
2684 .Case("mi", ARMCC::MI)
2685 .Case("pl", ARMCC::PL)
2686 .Case("vs", ARMCC::VS)
2687 .Case("vc", ARMCC::VC)
2688 .Case("hi", ARMCC::HI)
2689 .Case("ls", ARMCC::LS)
2690 .Case("ge", ARMCC::GE)
2691 .Case("lt", ARMCC::LT)
2692 .Case("gt", ARMCC::GT)
2693 .Case("le", ARMCC::LE)
2694 .Case("al", ARMCC::AL)
2697 return MatchOperand_NoMatch;
2698 Parser.Lex(); // Eat the token.
2700 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2702 return MatchOperand_Success;
2705 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2706 /// token must be an Identifier when called, and if it is a coprocessor
2707 /// number, the token is eaten and the operand is added to the operand list.
2708 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2709 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2710 SMLoc S = Parser.getTok().getLoc();
2711 const AsmToken &Tok = Parser.getTok();
2712 if (Tok.isNot(AsmToken::Identifier))
2713 return MatchOperand_NoMatch;
2715 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2717 return MatchOperand_NoMatch;
2719 Parser.Lex(); // Eat identifier token.
2720 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2721 return MatchOperand_Success;
2724 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2725 /// token must be an Identifier when called, and if it is a coprocessor
2726 /// number, the token is eaten and the operand is added to the operand list.
2727 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2728 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2729 SMLoc S = Parser.getTok().getLoc();
2730 const AsmToken &Tok = Parser.getTok();
2731 if (Tok.isNot(AsmToken::Identifier))
2732 return MatchOperand_NoMatch;
2734 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2736 return MatchOperand_NoMatch;
2738 Parser.Lex(); // Eat identifier token.
2739 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2740 return MatchOperand_Success;
2743 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2744 /// coproc_option : '{' imm0_255 '}'
2745 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2746 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2747 SMLoc S = Parser.getTok().getLoc();
2749 // If this isn't a '{', this isn't a coprocessor immediate operand.
2750 if (Parser.getTok().isNot(AsmToken::LCurly))
2751 return MatchOperand_NoMatch;
2752 Parser.Lex(); // Eat the '{'
2755 SMLoc Loc = Parser.getTok().getLoc();
2756 if (getParser().ParseExpression(Expr)) {
2757 Error(Loc, "illegal expression");
2758 return MatchOperand_ParseFail;
2760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2761 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2762 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2763 return MatchOperand_ParseFail;
2765 int Val = CE->getValue();
2767 // Check for and consume the closing '}'
2768 if (Parser.getTok().isNot(AsmToken::RCurly))
2769 return MatchOperand_ParseFail;
2770 SMLoc E = Parser.getTok().getLoc();
2771 Parser.Lex(); // Eat the '}'
2773 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2774 return MatchOperand_Success;
2777 // For register list parsing, we need to map from raw GPR register numbering
2778 // to the enumeration values. The enumeration values aren't sorted by
2779 // register number due to our using "sp", "lr" and "pc" as canonical names.
2780 static unsigned getNextRegister(unsigned Reg) {
2781 // If this is a GPR, we need to do it manually, otherwise we can rely
2782 // on the sort ordering of the enumeration since the other reg-classes
2784 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2787 default: llvm_unreachable("Invalid GPR number!");
2788 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2789 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2790 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2791 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2792 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2793 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2794 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2795 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2799 // Return the low-subreg of a given Q register.
2800 static unsigned getDRegFromQReg(unsigned QReg) {
2802 default: llvm_unreachable("expected a Q register!");
2803 case ARM::Q0: return ARM::D0;
2804 case ARM::Q1: return ARM::D2;
2805 case ARM::Q2: return ARM::D4;
2806 case ARM::Q3: return ARM::D6;
2807 case ARM::Q4: return ARM::D8;
2808 case ARM::Q5: return ARM::D10;
2809 case ARM::Q6: return ARM::D12;
2810 case ARM::Q7: return ARM::D14;
2811 case ARM::Q8: return ARM::D16;
2812 case ARM::Q9: return ARM::D18;
2813 case ARM::Q10: return ARM::D20;
2814 case ARM::Q11: return ARM::D22;
2815 case ARM::Q12: return ARM::D24;
2816 case ARM::Q13: return ARM::D26;
2817 case ARM::Q14: return ARM::D28;
2818 case ARM::Q15: return ARM::D30;
2822 /// Parse a register list.
2824 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2825 assert(Parser.getTok().is(AsmToken::LCurly) &&
2826 "Token is not a Left Curly Brace");
2827 SMLoc S = Parser.getTok().getLoc();
2828 Parser.Lex(); // Eat '{' token.
2829 SMLoc RegLoc = Parser.getTok().getLoc();
2831 // Check the first register in the list to see what register class
2832 // this is a list of.
2833 int Reg = tryParseRegister();
2835 return Error(RegLoc, "register expected");
2837 // The reglist instructions have at most 16 registers, so reserve
2838 // space for that many.
2839 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2841 // Allow Q regs and just interpret them as the two D sub-registers.
2842 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2843 Reg = getDRegFromQReg(Reg);
2844 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2847 const MCRegisterClass *RC;
2848 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2849 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2850 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2851 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2852 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2853 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2855 return Error(RegLoc, "invalid register in register list");
2857 // Store the register.
2858 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2860 // This starts immediately after the first register token in the list,
2861 // so we can see either a comma or a minus (range separator) as a legal
2863 while (Parser.getTok().is(AsmToken::Comma) ||
2864 Parser.getTok().is(AsmToken::Minus)) {
2865 if (Parser.getTok().is(AsmToken::Minus)) {
2866 Parser.Lex(); // Eat the minus.
2867 SMLoc EndLoc = Parser.getTok().getLoc();
2868 int EndReg = tryParseRegister();
2870 return Error(EndLoc, "register expected");
2871 // Allow Q regs and just interpret them as the two D sub-registers.
2872 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2873 EndReg = getDRegFromQReg(EndReg) + 1;
2874 // If the register is the same as the start reg, there's nothing
2878 // The register must be in the same register class as the first.
2879 if (!RC->contains(EndReg))
2880 return Error(EndLoc, "invalid register in register list");
2881 // Ranges must go from low to high.
2882 if (getARMRegisterNumbering(Reg) > getARMRegisterNumbering(EndReg))
2883 return Error(EndLoc, "bad range in register list");
2885 // Add all the registers in the range to the register list.
2886 while (Reg != EndReg) {
2887 Reg = getNextRegister(Reg);
2888 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2892 Parser.Lex(); // Eat the comma.
2893 RegLoc = Parser.getTok().getLoc();
2895 const AsmToken RegTok = Parser.getTok();
2896 Reg = tryParseRegister();
2898 return Error(RegLoc, "register expected");
2899 // Allow Q regs and just interpret them as the two D sub-registers.
2900 bool isQReg = false;
2901 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2902 Reg = getDRegFromQReg(Reg);
2905 // The register must be in the same register class as the first.
2906 if (!RC->contains(Reg))
2907 return Error(RegLoc, "invalid register in register list");
2908 // List must be monotonically increasing.
2909 if (getARMRegisterNumbering(Reg) < getARMRegisterNumbering(OldReg)) {
2910 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2911 Warning(RegLoc, "register list not in ascending order");
2913 return Error(RegLoc, "register list not in ascending order");
2915 if (getARMRegisterNumbering(Reg) == getARMRegisterNumbering(OldReg)) {
2916 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2917 ") in register list");
2920 // VFP register lists must also be contiguous.
2921 // It's OK to use the enumeration values directly here rather, as the
2922 // VFP register classes have the enum sorted properly.
2923 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2925 return Error(RegLoc, "non-contiguous register range");
2926 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2928 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
2931 SMLoc E = Parser.getTok().getLoc();
2932 if (Parser.getTok().isNot(AsmToken::RCurly))
2933 return Error(E, "'}' expected");
2934 Parser.Lex(); // Eat '}' token.
2936 // Push the register list operand.
2937 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
2939 // The ARM system instruction variants for LDM/STM have a '^' token here.
2940 if (Parser.getTok().is(AsmToken::Caret)) {
2941 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2942 Parser.Lex(); // Eat '^' token.
2948 // Helper function to parse the lane index for vector lists.
2949 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2950 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2951 Index = 0; // Always return a defined index value.
2952 if (Parser.getTok().is(AsmToken::LBrac)) {
2953 Parser.Lex(); // Eat the '['.
2954 if (Parser.getTok().is(AsmToken::RBrac)) {
2955 // "Dn[]" is the 'all lanes' syntax.
2956 LaneKind = AllLanes;
2957 Parser.Lex(); // Eat the ']'.
2958 return MatchOperand_Success;
2961 // There's an optional '#' token here. Normally there wouldn't be, but
2962 // inline assemble puts one in, and it's friendly to accept that.
2963 if (Parser.getTok().is(AsmToken::Hash))
2964 Parser.Lex(); // Eat the '#'
2966 const MCExpr *LaneIndex;
2967 SMLoc Loc = Parser.getTok().getLoc();
2968 if (getParser().ParseExpression(LaneIndex)) {
2969 Error(Loc, "illegal expression");
2970 return MatchOperand_ParseFail;
2972 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2974 Error(Loc, "lane index must be empty or an integer");
2975 return MatchOperand_ParseFail;
2977 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2978 Error(Parser.getTok().getLoc(), "']' expected");
2979 return MatchOperand_ParseFail;
2981 Parser.Lex(); // Eat the ']'.
2982 int64_t Val = CE->getValue();
2984 // FIXME: Make this range check context sensitive for .8, .16, .32.
2985 if (Val < 0 || Val > 7) {
2986 Error(Parser.getTok().getLoc(), "lane index out of range");
2987 return MatchOperand_ParseFail;
2990 LaneKind = IndexedLane;
2991 return MatchOperand_Success;
2994 return MatchOperand_Success;
2997 // parse a vector register list
2998 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2999 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3000 VectorLaneTy LaneKind;
3002 SMLoc S = Parser.getTok().getLoc();
3003 // As an extension (to match gas), support a plain D register or Q register
3004 // (without encosing curly braces) as a single or double entry list,
3006 if (Parser.getTok().is(AsmToken::Identifier)) {
3007 int Reg = tryParseRegister();
3009 return MatchOperand_NoMatch;
3010 SMLoc E = Parser.getTok().getLoc();
3011 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3012 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
3013 if (Res != MatchOperand_Success)
3017 E = Parser.getTok().getLoc();
3018 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3021 E = Parser.getTok().getLoc();
3022 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3026 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3031 return MatchOperand_Success;
3033 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3034 Reg = getDRegFromQReg(Reg);
3035 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
3036 if (Res != MatchOperand_Success)
3040 E = Parser.getTok().getLoc();
3041 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3042 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3043 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3046 E = Parser.getTok().getLoc();
3047 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3048 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3049 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3053 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3058 return MatchOperand_Success;
3060 Error(S, "vector register expected");
3061 return MatchOperand_ParseFail;
3064 if (Parser.getTok().isNot(AsmToken::LCurly))
3065 return MatchOperand_NoMatch;
3067 Parser.Lex(); // Eat '{' token.
3068 SMLoc RegLoc = Parser.getTok().getLoc();
3070 int Reg = tryParseRegister();
3072 Error(RegLoc, "register expected");
3073 return MatchOperand_ParseFail;
3077 unsigned FirstReg = Reg;
3078 // The list is of D registers, but we also allow Q regs and just interpret
3079 // them as the two D sub-registers.
3080 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3081 FirstReg = Reg = getDRegFromQReg(Reg);
3082 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3083 // it's ambiguous with four-register single spaced.
3087 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
3088 return MatchOperand_ParseFail;
3090 while (Parser.getTok().is(AsmToken::Comma) ||
3091 Parser.getTok().is(AsmToken::Minus)) {
3092 if (Parser.getTok().is(AsmToken::Minus)) {
3094 Spacing = 1; // Register range implies a single spaced list.
3095 else if (Spacing == 2) {
3096 Error(Parser.getTok().getLoc(),
3097 "sequential registers in double spaced list");
3098 return MatchOperand_ParseFail;
3100 Parser.Lex(); // Eat the minus.
3101 SMLoc EndLoc = Parser.getTok().getLoc();
3102 int EndReg = tryParseRegister();
3104 Error(EndLoc, "register expected");
3105 return MatchOperand_ParseFail;
3107 // Allow Q regs and just interpret them as the two D sub-registers.
3108 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3109 EndReg = getDRegFromQReg(EndReg) + 1;
3110 // If the register is the same as the start reg, there's nothing
3114 // The register must be in the same register class as the first.
3115 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3116 Error(EndLoc, "invalid register in register list");
3117 return MatchOperand_ParseFail;
3119 // Ranges must go from low to high.
3121 Error(EndLoc, "bad range in register list");
3122 return MatchOperand_ParseFail;
3124 // Parse the lane specifier if present.
3125 VectorLaneTy NextLaneKind;
3126 unsigned NextLaneIndex;
3127 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3128 return MatchOperand_ParseFail;
3129 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3130 Error(EndLoc, "mismatched lane index in register list");
3131 return MatchOperand_ParseFail;
3133 EndLoc = Parser.getTok().getLoc();
3135 // Add all the registers in the range to the register list.
3136 Count += EndReg - Reg;
3140 Parser.Lex(); // Eat the comma.
3141 RegLoc = Parser.getTok().getLoc();
3143 Reg = tryParseRegister();
3145 Error(RegLoc, "register expected");
3146 return MatchOperand_ParseFail;
3148 // vector register lists must be contiguous.
3149 // It's OK to use the enumeration values directly here rather, as the
3150 // VFP register classes have the enum sorted properly.
3152 // The list is of D registers, but we also allow Q regs and just interpret
3153 // them as the two D sub-registers.
3154 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3156 Spacing = 1; // Register range implies a single spaced list.
3157 else if (Spacing == 2) {
3159 "invalid register in double-spaced list (must be 'D' register')");
3160 return MatchOperand_ParseFail;
3162 Reg = getDRegFromQReg(Reg);
3163 if (Reg != OldReg + 1) {
3164 Error(RegLoc, "non-contiguous register range");
3165 return MatchOperand_ParseFail;
3169 // Parse the lane specifier if present.
3170 VectorLaneTy NextLaneKind;
3171 unsigned NextLaneIndex;
3172 SMLoc EndLoc = Parser.getTok().getLoc();
3173 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3174 return MatchOperand_ParseFail;
3175 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3176 Error(EndLoc, "mismatched lane index in register list");
3177 return MatchOperand_ParseFail;
3181 // Normal D register.
3182 // Figure out the register spacing (single or double) of the list if
3183 // we don't know it already.
3185 Spacing = 1 + (Reg == OldReg + 2);
3187 // Just check that it's contiguous and keep going.
3188 if (Reg != OldReg + Spacing) {
3189 Error(RegLoc, "non-contiguous register range");
3190 return MatchOperand_ParseFail;
3193 // Parse the lane specifier if present.
3194 VectorLaneTy NextLaneKind;
3195 unsigned NextLaneIndex;
3196 SMLoc EndLoc = Parser.getTok().getLoc();
3197 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3198 return MatchOperand_ParseFail;
3199 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3200 Error(EndLoc, "mismatched lane index in register list");
3201 return MatchOperand_ParseFail;
3205 SMLoc E = Parser.getTok().getLoc();
3206 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3207 Error(E, "'}' expected");
3208 return MatchOperand_ParseFail;
3210 Parser.Lex(); // Eat '}' token.
3214 // Two-register operands have been converted to the
3215 // composite register classes.
3217 const MCRegisterClass *RC = (Spacing == 1) ?
3218 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3219 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3220 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3223 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3224 (Spacing == 2), S, E));
3227 // Two-register operands have been converted to the
3228 // composite register classes.
3230 const MCRegisterClass *RC = (Spacing == 1) ?
3231 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3232 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3233 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3235 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3240 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3246 return MatchOperand_Success;
3249 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3250 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3251 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3252 SMLoc S = Parser.getTok().getLoc();
3253 const AsmToken &Tok = Parser.getTok();
3254 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3255 StringRef OptStr = Tok.getString();
3257 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()))
3258 .Case("sy", ARM_MB::SY)
3259 .Case("st", ARM_MB::ST)
3260 .Case("sh", ARM_MB::ISH)
3261 .Case("ish", ARM_MB::ISH)
3262 .Case("shst", ARM_MB::ISHST)
3263 .Case("ishst", ARM_MB::ISHST)
3264 .Case("nsh", ARM_MB::NSH)
3265 .Case("un", ARM_MB::NSH)
3266 .Case("nshst", ARM_MB::NSHST)
3267 .Case("unst", ARM_MB::NSHST)
3268 .Case("osh", ARM_MB::OSH)
3269 .Case("oshst", ARM_MB::OSHST)
3273 return MatchOperand_NoMatch;
3275 Parser.Lex(); // Eat identifier token.
3276 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3277 return MatchOperand_Success;
3280 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3281 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3282 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3283 SMLoc S = Parser.getTok().getLoc();
3284 const AsmToken &Tok = Parser.getTok();
3285 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3286 StringRef IFlagsStr = Tok.getString();
3288 // An iflags string of "none" is interpreted to mean that none of the AIF
3289 // bits are set. Not a terribly useful instruction, but a valid encoding.
3290 unsigned IFlags = 0;
3291 if (IFlagsStr != "none") {
3292 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3293 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3294 .Case("a", ARM_PROC::A)
3295 .Case("i", ARM_PROC::I)
3296 .Case("f", ARM_PROC::F)
3299 // If some specific iflag is already set, it means that some letter is
3300 // present more than once, this is not acceptable.
3301 if (Flag == ~0U || (IFlags & Flag))
3302 return MatchOperand_NoMatch;
3308 Parser.Lex(); // Eat identifier token.
3309 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3310 return MatchOperand_Success;
3313 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3314 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3315 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3316 SMLoc S = Parser.getTok().getLoc();
3317 const AsmToken &Tok = Parser.getTok();
3318 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3319 StringRef Mask = Tok.getString();
3322 // See ARMv6-M 10.1.1
3323 std::string Name = Mask.lower();
3324 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3334 .Case("primask", 16)
3335 .Case("basepri", 17)
3336 .Case("basepri_max", 18)
3337 .Case("faultmask", 19)
3338 .Case("control", 20)
3341 if (FlagsVal == ~0U)
3342 return MatchOperand_NoMatch;
3344 if (!hasV7Ops() && FlagsVal >= 17 && FlagsVal <= 19)
3345 // basepri, basepri_max and faultmask only valid for V7m.
3346 return MatchOperand_NoMatch;
3348 Parser.Lex(); // Eat identifier token.
3349 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3350 return MatchOperand_Success;
3353 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3354 size_t Start = 0, Next = Mask.find('_');
3355 StringRef Flags = "";
3356 std::string SpecReg = Mask.slice(Start, Next).lower();
3357 if (Next != StringRef::npos)
3358 Flags = Mask.slice(Next+1, Mask.size());
3360 // FlagsVal contains the complete mask:
3362 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3363 unsigned FlagsVal = 0;
3365 if (SpecReg == "apsr") {
3366 FlagsVal = StringSwitch<unsigned>(Flags)
3367 .Case("nzcvq", 0x8) // same as CPSR_f
3368 .Case("g", 0x4) // same as CPSR_s
3369 .Case("nzcvqg", 0xc) // same as CPSR_fs
3372 if (FlagsVal == ~0U) {
3374 return MatchOperand_NoMatch;
3376 FlagsVal = 8; // No flag
3378 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3379 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3380 if (Flags == "all" || Flags == "")
3382 for (int i = 0, e = Flags.size(); i != e; ++i) {
3383 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3390 // If some specific flag is already set, it means that some letter is
3391 // present more than once, this is not acceptable.
3392 if (FlagsVal == ~0U || (FlagsVal & Flag))
3393 return MatchOperand_NoMatch;
3396 } else // No match for special register.
3397 return MatchOperand_NoMatch;
3399 // Special register without flags is NOT equivalent to "fc" flags.
3400 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3401 // two lines would enable gas compatibility at the expense of breaking
3407 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3408 if (SpecReg == "spsr")
3411 Parser.Lex(); // Eat identifier token.
3412 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3413 return MatchOperand_Success;
3416 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3417 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3418 int Low, int High) {
3419 const AsmToken &Tok = Parser.getTok();
3420 if (Tok.isNot(AsmToken::Identifier)) {
3421 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3422 return MatchOperand_ParseFail;
3424 StringRef ShiftName = Tok.getString();
3425 std::string LowerOp = Op.lower();
3426 std::string UpperOp = Op.upper();
3427 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3428 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3429 return MatchOperand_ParseFail;
3431 Parser.Lex(); // Eat shift type token.
3433 // There must be a '#' and a shift amount.
3434 if (Parser.getTok().isNot(AsmToken::Hash) &&
3435 Parser.getTok().isNot(AsmToken::Dollar)) {
3436 Error(Parser.getTok().getLoc(), "'#' expected");
3437 return MatchOperand_ParseFail;
3439 Parser.Lex(); // Eat hash token.
3441 const MCExpr *ShiftAmount;
3442 SMLoc Loc = Parser.getTok().getLoc();
3443 if (getParser().ParseExpression(ShiftAmount)) {
3444 Error(Loc, "illegal expression");
3445 return MatchOperand_ParseFail;
3447 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3449 Error(Loc, "constant expression expected");
3450 return MatchOperand_ParseFail;
3452 int Val = CE->getValue();
3453 if (Val < Low || Val > High) {
3454 Error(Loc, "immediate value out of range");
3455 return MatchOperand_ParseFail;
3458 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3460 return MatchOperand_Success;
3463 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3464 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3465 const AsmToken &Tok = Parser.getTok();
3466 SMLoc S = Tok.getLoc();
3467 if (Tok.isNot(AsmToken::Identifier)) {
3468 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3469 return MatchOperand_ParseFail;
3471 int Val = StringSwitch<int>(Tok.getString())
3475 Parser.Lex(); // Eat the token.
3478 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3479 return MatchOperand_ParseFail;
3481 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3483 S, Parser.getTok().getLoc()));
3484 return MatchOperand_Success;
3487 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3488 /// instructions. Legal values are:
3489 /// lsl #n 'n' in [0,31]
3490 /// asr #n 'n' in [1,32]
3491 /// n == 32 encoded as n == 0.
3492 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3493 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3494 const AsmToken &Tok = Parser.getTok();
3495 SMLoc S = Tok.getLoc();
3496 if (Tok.isNot(AsmToken::Identifier)) {
3497 Error(S, "shift operator 'asr' or 'lsl' expected");
3498 return MatchOperand_ParseFail;
3500 StringRef ShiftName = Tok.getString();
3502 if (ShiftName == "lsl" || ShiftName == "LSL")
3504 else if (ShiftName == "asr" || ShiftName == "ASR")
3507 Error(S, "shift operator 'asr' or 'lsl' expected");
3508 return MatchOperand_ParseFail;
3510 Parser.Lex(); // Eat the operator.
3512 // A '#' and a shift amount.
3513 if (Parser.getTok().isNot(AsmToken::Hash) &&
3514 Parser.getTok().isNot(AsmToken::Dollar)) {
3515 Error(Parser.getTok().getLoc(), "'#' expected");
3516 return MatchOperand_ParseFail;
3518 Parser.Lex(); // Eat hash token.
3520 const MCExpr *ShiftAmount;
3521 SMLoc E = Parser.getTok().getLoc();
3522 if (getParser().ParseExpression(ShiftAmount)) {
3523 Error(E, "malformed shift expression");
3524 return MatchOperand_ParseFail;
3526 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3528 Error(E, "shift amount must be an immediate");
3529 return MatchOperand_ParseFail;
3532 int64_t Val = CE->getValue();
3534 // Shift amount must be in [1,32]
3535 if (Val < 1 || Val > 32) {
3536 Error(E, "'asr' shift amount must be in range [1,32]");
3537 return MatchOperand_ParseFail;
3539 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3540 if (isThumb() && Val == 32) {
3541 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3542 return MatchOperand_ParseFail;
3544 if (Val == 32) Val = 0;
3546 // Shift amount must be in [1,32]
3547 if (Val < 0 || Val > 31) {
3548 Error(E, "'lsr' shift amount must be in range [0,31]");
3549 return MatchOperand_ParseFail;
3553 E = Parser.getTok().getLoc();
3554 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3556 return MatchOperand_Success;
3559 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3560 /// of instructions. Legal values are:
3561 /// ror #n 'n' in {0, 8, 16, 24}
3562 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3563 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3564 const AsmToken &Tok = Parser.getTok();
3565 SMLoc S = Tok.getLoc();
3566 if (Tok.isNot(AsmToken::Identifier))
3567 return MatchOperand_NoMatch;
3568 StringRef ShiftName = Tok.getString();
3569 if (ShiftName != "ror" && ShiftName != "ROR")
3570 return MatchOperand_NoMatch;
3571 Parser.Lex(); // Eat the operator.
3573 // A '#' and a rotate amount.
3574 if (Parser.getTok().isNot(AsmToken::Hash) &&
3575 Parser.getTok().isNot(AsmToken::Dollar)) {
3576 Error(Parser.getTok().getLoc(), "'#' expected");
3577 return MatchOperand_ParseFail;
3579 Parser.Lex(); // Eat hash token.
3581 const MCExpr *ShiftAmount;
3582 SMLoc E = Parser.getTok().getLoc();
3583 if (getParser().ParseExpression(ShiftAmount)) {
3584 Error(E, "malformed rotate expression");
3585 return MatchOperand_ParseFail;
3587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3589 Error(E, "rotate amount must be an immediate");
3590 return MatchOperand_ParseFail;
3593 int64_t Val = CE->getValue();
3594 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3595 // normally, zero is represented in asm by omitting the rotate operand
3597 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3598 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3599 return MatchOperand_ParseFail;
3602 E = Parser.getTok().getLoc();
3603 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3605 return MatchOperand_Success;
3608 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3609 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3610 SMLoc S = Parser.getTok().getLoc();
3611 // The bitfield descriptor is really two operands, the LSB and the width.
3612 if (Parser.getTok().isNot(AsmToken::Hash) &&
3613 Parser.getTok().isNot(AsmToken::Dollar)) {
3614 Error(Parser.getTok().getLoc(), "'#' expected");
3615 return MatchOperand_ParseFail;
3617 Parser.Lex(); // Eat hash token.
3619 const MCExpr *LSBExpr;
3620 SMLoc E = Parser.getTok().getLoc();
3621 if (getParser().ParseExpression(LSBExpr)) {
3622 Error(E, "malformed immediate expression");
3623 return MatchOperand_ParseFail;
3625 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3627 Error(E, "'lsb' operand must be an immediate");
3628 return MatchOperand_ParseFail;
3631 int64_t LSB = CE->getValue();
3632 // The LSB must be in the range [0,31]
3633 if (LSB < 0 || LSB > 31) {
3634 Error(E, "'lsb' operand must be in the range [0,31]");
3635 return MatchOperand_ParseFail;
3637 E = Parser.getTok().getLoc();
3639 // Expect another immediate operand.
3640 if (Parser.getTok().isNot(AsmToken::Comma)) {
3641 Error(Parser.getTok().getLoc(), "too few operands");
3642 return MatchOperand_ParseFail;
3644 Parser.Lex(); // Eat hash token.
3645 if (Parser.getTok().isNot(AsmToken::Hash) &&
3646 Parser.getTok().isNot(AsmToken::Dollar)) {
3647 Error(Parser.getTok().getLoc(), "'#' expected");
3648 return MatchOperand_ParseFail;
3650 Parser.Lex(); // Eat hash token.
3652 const MCExpr *WidthExpr;
3653 if (getParser().ParseExpression(WidthExpr)) {
3654 Error(E, "malformed immediate expression");
3655 return MatchOperand_ParseFail;
3657 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3659 Error(E, "'width' operand must be an immediate");
3660 return MatchOperand_ParseFail;
3663 int64_t Width = CE->getValue();
3664 // The LSB must be in the range [1,32-lsb]
3665 if (Width < 1 || Width > 32 - LSB) {
3666 Error(E, "'width' operand must be in the range [1,32-lsb]");
3667 return MatchOperand_ParseFail;
3669 E = Parser.getTok().getLoc();
3671 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3673 return MatchOperand_Success;
3676 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3677 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3678 // Check for a post-index addressing register operand. Specifically:
3679 // postidx_reg := '+' register {, shift}
3680 // | '-' register {, shift}
3681 // | register {, shift}
3683 // This method must return MatchOperand_NoMatch without consuming any tokens
3684 // in the case where there is no match, as other alternatives take other
3686 AsmToken Tok = Parser.getTok();
3687 SMLoc S = Tok.getLoc();
3688 bool haveEaten = false;
3691 if (Tok.is(AsmToken::Plus)) {
3692 Parser.Lex(); // Eat the '+' token.
3694 } else if (Tok.is(AsmToken::Minus)) {
3695 Parser.Lex(); // Eat the '-' token.
3699 if (Parser.getTok().is(AsmToken::Identifier))
3700 Reg = tryParseRegister();
3703 return MatchOperand_NoMatch;
3704 Error(Parser.getTok().getLoc(), "register expected");
3705 return MatchOperand_ParseFail;
3707 SMLoc E = Parser.getTok().getLoc();
3709 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3710 unsigned ShiftImm = 0;
3711 if (Parser.getTok().is(AsmToken::Comma)) {
3712 Parser.Lex(); // Eat the ','.
3713 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3714 return MatchOperand_ParseFail;
3717 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3720 return MatchOperand_Success;
3723 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3724 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3725 // Check for a post-index addressing register operand. Specifically:
3726 // am3offset := '+' register
3733 // This method must return MatchOperand_NoMatch without consuming any tokens
3734 // in the case where there is no match, as other alternatives take other
3736 AsmToken Tok = Parser.getTok();
3737 SMLoc S = Tok.getLoc();
3739 // Do immediates first, as we always parse those if we have a '#'.
3740 if (Parser.getTok().is(AsmToken::Hash) ||
3741 Parser.getTok().is(AsmToken::Dollar)) {
3742 Parser.Lex(); // Eat the '#'.
3743 // Explicitly look for a '-', as we need to encode negative zero
3745 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3746 const MCExpr *Offset;
3747 if (getParser().ParseExpression(Offset))
3748 return MatchOperand_ParseFail;
3749 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3751 Error(S, "constant expression expected");
3752 return MatchOperand_ParseFail;
3754 SMLoc E = Tok.getLoc();
3755 // Negative zero is encoded as the flag value INT32_MIN.
3756 int32_t Val = CE->getValue();
3757 if (isNegative && Val == 0)
3761 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3763 return MatchOperand_Success;
3767 bool haveEaten = false;
3770 if (Tok.is(AsmToken::Plus)) {
3771 Parser.Lex(); // Eat the '+' token.
3773 } else if (Tok.is(AsmToken::Minus)) {
3774 Parser.Lex(); // Eat the '-' token.
3778 if (Parser.getTok().is(AsmToken::Identifier))
3779 Reg = tryParseRegister();
3782 return MatchOperand_NoMatch;
3783 Error(Parser.getTok().getLoc(), "register expected");
3784 return MatchOperand_ParseFail;
3786 SMLoc E = Parser.getTok().getLoc();
3788 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3791 return MatchOperand_Success;
3794 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
3795 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3796 /// when they refer multiple MIOperands inside a single one.
3798 cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
3799 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3801 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3802 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3803 // Create a writeback register dummy placeholder.
3804 Inst.addOperand(MCOperand::CreateReg(0));
3806 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3808 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3812 /// cvtT2StrdPre - Convert parsed operands to MCInst.
3813 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3814 /// when they refer multiple MIOperands inside a single one.
3816 cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
3817 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3818 // Create a writeback register dummy placeholder.
3819 Inst.addOperand(MCOperand::CreateReg(0));
3821 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3822 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3824 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3826 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3830 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3831 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3832 /// when they refer multiple MIOperands inside a single one.
3834 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3835 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3836 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3838 // Create a writeback register dummy placeholder.
3839 Inst.addOperand(MCOperand::CreateImm(0));
3841 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3842 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3846 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3847 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3848 /// when they refer multiple MIOperands inside a single one.
3850 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3851 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3852 // Create a writeback register dummy placeholder.
3853 Inst.addOperand(MCOperand::CreateImm(0));
3854 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3855 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3856 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3860 /// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3861 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3862 /// when they refer multiple MIOperands inside a single one.
3864 cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
3865 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3866 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3868 // Create a writeback register dummy placeholder.
3869 Inst.addOperand(MCOperand::CreateImm(0));
3871 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3872 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3876 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3877 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3878 /// when they refer multiple MIOperands inside a single one.
3880 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3881 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3882 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3884 // Create a writeback register dummy placeholder.
3885 Inst.addOperand(MCOperand::CreateImm(0));
3887 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3888 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3893 /// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3894 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3895 /// when they refer multiple MIOperands inside a single one.
3897 cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3898 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3899 // Create a writeback register dummy placeholder.
3900 Inst.addOperand(MCOperand::CreateImm(0));
3901 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3902 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3903 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3907 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3908 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3909 /// when they refer multiple MIOperands inside a single one.
3911 cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
3912 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3913 // Create a writeback register dummy placeholder.
3914 Inst.addOperand(MCOperand::CreateImm(0));
3915 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3916 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3917 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3921 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3922 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3923 /// when they refer multiple MIOperands inside a single one.
3925 cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3926 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3927 // Create a writeback register dummy placeholder.
3928 Inst.addOperand(MCOperand::CreateImm(0));
3929 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3930 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3931 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3935 /// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
3936 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3937 /// when they refer multiple MIOperands inside a single one.
3939 cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3940 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3942 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3943 // Create a writeback register dummy placeholder.
3944 Inst.addOperand(MCOperand::CreateImm(0));
3946 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3948 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3950 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3954 /// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
3955 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3956 /// when they refer multiple MIOperands inside a single one.
3958 cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3959 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3961 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3962 // Create a writeback register dummy placeholder.
3963 Inst.addOperand(MCOperand::CreateImm(0));
3965 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3967 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3969 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3973 /// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
3974 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3975 /// when they refer multiple MIOperands inside a single one.
3977 cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3978 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3979 // Create a writeback register dummy placeholder.
3980 Inst.addOperand(MCOperand::CreateImm(0));
3982 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3984 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3986 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3988 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3992 /// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
3993 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3994 /// when they refer multiple MIOperands inside a single one.
3996 cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3997 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3998 // Create a writeback register dummy placeholder.
3999 Inst.addOperand(MCOperand::CreateImm(0));
4001 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4003 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4005 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4007 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4011 /// cvtLdrdPre - Convert parsed operands to MCInst.
4012 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4013 /// when they refer multiple MIOperands inside a single one.
4015 cvtLdrdPre(MCInst &Inst, unsigned Opcode,
4016 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4018 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4019 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4020 // Create a writeback register dummy placeholder.
4021 Inst.addOperand(MCOperand::CreateImm(0));
4023 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4025 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4029 /// cvtStrdPre - Convert parsed operands to MCInst.
4030 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4031 /// when they refer multiple MIOperands inside a single one.
4033 cvtStrdPre(MCInst &Inst, unsigned Opcode,
4034 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4035 // Create a writeback register dummy placeholder.
4036 Inst.addOperand(MCOperand::CreateImm(0));
4038 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4039 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4041 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4043 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4047 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4048 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4049 /// when they refer multiple MIOperands inside a single one.
4051 cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
4052 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4053 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4054 // Create a writeback register dummy placeholder.
4055 Inst.addOperand(MCOperand::CreateImm(0));
4056 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4057 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4061 /// cvtThumbMultiple- Convert parsed operands to MCInst.
4062 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4063 /// when they refer multiple MIOperands inside a single one.
4065 cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
4066 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4067 // The second source operand must be the same register as the destination
4069 if (Operands.size() == 6 &&
4070 (((ARMOperand*)Operands[3])->getReg() !=
4071 ((ARMOperand*)Operands[5])->getReg()) &&
4072 (((ARMOperand*)Operands[3])->getReg() !=
4073 ((ARMOperand*)Operands[4])->getReg())) {
4074 Error(Operands[3]->getStartLoc(),
4075 "destination register must match source register");
4078 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4079 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4080 // If we have a three-operand form, make sure to set Rn to be the operand
4081 // that isn't the same as Rd.
4083 if (Operands.size() == 6 &&
4084 ((ARMOperand*)Operands[4])->getReg() ==
4085 ((ARMOperand*)Operands[3])->getReg())
4087 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4088 Inst.addOperand(Inst.getOperand(0));
4089 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4095 cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
4096 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4098 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4099 // Create a writeback register dummy placeholder.
4100 Inst.addOperand(MCOperand::CreateImm(0));
4102 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4104 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4109 cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
4110 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4112 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4113 // Create a writeback register dummy placeholder.
4114 Inst.addOperand(MCOperand::CreateImm(0));
4116 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4118 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4120 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4125 cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
4126 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4127 // Create a writeback register dummy placeholder.
4128 Inst.addOperand(MCOperand::CreateImm(0));
4130 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4132 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4134 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4139 cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
4140 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4141 // Create a writeback register dummy placeholder.
4142 Inst.addOperand(MCOperand::CreateImm(0));
4144 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4146 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4148 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4150 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4154 /// Parse an ARM memory expression, return false if successful else return true
4155 /// or an error. The first token must be a '[' when called.
4157 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4159 assert(Parser.getTok().is(AsmToken::LBrac) &&
4160 "Token is not a Left Bracket");
4161 S = Parser.getTok().getLoc();
4162 Parser.Lex(); // Eat left bracket token.
4164 const AsmToken &BaseRegTok = Parser.getTok();
4165 int BaseRegNum = tryParseRegister();
4166 if (BaseRegNum == -1)
4167 return Error(BaseRegTok.getLoc(), "register expected");
4169 // The next token must either be a comma or a closing bracket.
4170 const AsmToken &Tok = Parser.getTok();
4171 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
4172 return Error(Tok.getLoc(), "malformed memory operand");
4174 if (Tok.is(AsmToken::RBrac)) {
4176 Parser.Lex(); // Eat right bracket token.
4178 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4179 0, 0, false, S, E));
4181 // If there's a pre-indexing writeback marker, '!', just add it as a token
4182 // operand. It's rather odd, but syntactically valid.
4183 if (Parser.getTok().is(AsmToken::Exclaim)) {
4184 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4185 Parser.Lex(); // Eat the '!'.
4191 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4192 Parser.Lex(); // Eat the comma.
4194 // If we have a ':', it's an alignment specifier.
4195 if (Parser.getTok().is(AsmToken::Colon)) {
4196 Parser.Lex(); // Eat the ':'.
4197 E = Parser.getTok().getLoc();
4200 if (getParser().ParseExpression(Expr))
4203 // The expression has to be a constant. Memory references with relocations
4204 // don't come through here, as they use the <label> forms of the relevant
4206 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4208 return Error (E, "constant expression expected");
4211 switch (CE->getValue()) {
4214 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4215 case 16: Align = 2; break;
4216 case 32: Align = 4; break;
4217 case 64: Align = 8; break;
4218 case 128: Align = 16; break;
4219 case 256: Align = 32; break;
4222 // Now we should have the closing ']'
4223 E = Parser.getTok().getLoc();
4224 if (Parser.getTok().isNot(AsmToken::RBrac))
4225 return Error(E, "']' expected");
4226 Parser.Lex(); // Eat right bracket token.
4228 // Don't worry about range checking the value here. That's handled by
4229 // the is*() predicates.
4230 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4231 ARM_AM::no_shift, 0, Align,
4234 // If there's a pre-indexing writeback marker, '!', just add it as a token
4236 if (Parser.getTok().is(AsmToken::Exclaim)) {
4237 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4238 Parser.Lex(); // Eat the '!'.
4244 // If we have a '#', it's an immediate offset, else assume it's a register
4245 // offset. Be friendly and also accept a plain integer (without a leading
4246 // hash) for gas compatibility.
4247 if (Parser.getTok().is(AsmToken::Hash) ||
4248 Parser.getTok().is(AsmToken::Dollar) ||
4249 Parser.getTok().is(AsmToken::Integer)) {
4250 if (Parser.getTok().isNot(AsmToken::Integer))
4251 Parser.Lex(); // Eat the '#'.
4252 E = Parser.getTok().getLoc();
4254 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4255 const MCExpr *Offset;
4256 if (getParser().ParseExpression(Offset))
4259 // The expression has to be a constant. Memory references with relocations
4260 // don't come through here, as they use the <label> forms of the relevant
4262 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4264 return Error (E, "constant expression expected");
4266 // If the constant was #-0, represent it as INT32_MIN.
4267 int32_t Val = CE->getValue();
4268 if (isNegative && Val == 0)
4269 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4271 // Now we should have the closing ']'
4272 E = Parser.getTok().getLoc();
4273 if (Parser.getTok().isNot(AsmToken::RBrac))
4274 return Error(E, "']' expected");
4275 Parser.Lex(); // Eat right bracket token.
4277 // Don't worry about range checking the value here. That's handled by
4278 // the is*() predicates.
4279 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4280 ARM_AM::no_shift, 0, 0,
4283 // If there's a pre-indexing writeback marker, '!', just add it as a token
4285 if (Parser.getTok().is(AsmToken::Exclaim)) {
4286 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4287 Parser.Lex(); // Eat the '!'.
4293 // The register offset is optionally preceded by a '+' or '-'
4294 bool isNegative = false;
4295 if (Parser.getTok().is(AsmToken::Minus)) {
4297 Parser.Lex(); // Eat the '-'.
4298 } else if (Parser.getTok().is(AsmToken::Plus)) {
4300 Parser.Lex(); // Eat the '+'.
4303 E = Parser.getTok().getLoc();
4304 int OffsetRegNum = tryParseRegister();
4305 if (OffsetRegNum == -1)
4306 return Error(E, "register expected");
4308 // If there's a shift operator, handle it.
4309 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4310 unsigned ShiftImm = 0;
4311 if (Parser.getTok().is(AsmToken::Comma)) {
4312 Parser.Lex(); // Eat the ','.
4313 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4317 // Now we should have the closing ']'
4318 E = Parser.getTok().getLoc();
4319 if (Parser.getTok().isNot(AsmToken::RBrac))
4320 return Error(E, "']' expected");
4321 Parser.Lex(); // Eat right bracket token.
4323 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4324 ShiftType, ShiftImm, 0, isNegative,
4327 // If there's a pre-indexing writeback marker, '!', just add it as a token
4329 if (Parser.getTok().is(AsmToken::Exclaim)) {
4330 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4331 Parser.Lex(); // Eat the '!'.
4337 /// parseMemRegOffsetShift - one of these two:
4338 /// ( lsl | lsr | asr | ror ) , # shift_amount
4340 /// return true if it parses a shift otherwise it returns false.
4341 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4343 SMLoc Loc = Parser.getTok().getLoc();
4344 const AsmToken &Tok = Parser.getTok();
4345 if (Tok.isNot(AsmToken::Identifier))
4347 StringRef ShiftName = Tok.getString();
4348 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4349 ShiftName == "asl" || ShiftName == "ASL")
4351 else if (ShiftName == "lsr" || ShiftName == "LSR")
4353 else if (ShiftName == "asr" || ShiftName == "ASR")
4355 else if (ShiftName == "ror" || ShiftName == "ROR")
4357 else if (ShiftName == "rrx" || ShiftName == "RRX")
4360 return Error(Loc, "illegal shift operator");
4361 Parser.Lex(); // Eat shift type token.
4363 // rrx stands alone.
4365 if (St != ARM_AM::rrx) {
4366 Loc = Parser.getTok().getLoc();
4367 // A '#' and a shift amount.
4368 const AsmToken &HashTok = Parser.getTok();
4369 if (HashTok.isNot(AsmToken::Hash) &&
4370 HashTok.isNot(AsmToken::Dollar))
4371 return Error(HashTok.getLoc(), "'#' expected");
4372 Parser.Lex(); // Eat hash token.
4375 if (getParser().ParseExpression(Expr))
4377 // Range check the immediate.
4378 // lsl, ror: 0 <= imm <= 31
4379 // lsr, asr: 0 <= imm <= 32
4380 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4382 return Error(Loc, "shift amount must be an immediate");
4383 int64_t Imm = CE->getValue();
4385 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4386 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4387 return Error(Loc, "immediate shift value out of range");
4394 /// parseFPImm - A floating point immediate expression operand.
4395 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4396 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4397 // Anything that can accept a floating point constant as an operand
4398 // needs to go through here, as the regular ParseExpression is
4401 // This routine still creates a generic Immediate operand, containing
4402 // a bitcast of the 64-bit floating point value. The various operands
4403 // that accept floats can check whether the value is valid for them
4404 // via the standard is*() predicates.
4406 SMLoc S = Parser.getTok().getLoc();
4408 if (Parser.getTok().isNot(AsmToken::Hash) &&
4409 Parser.getTok().isNot(AsmToken::Dollar))
4410 return MatchOperand_NoMatch;
4412 // Disambiguate the VMOV forms that can accept an FP immediate.
4413 // vmov.f32 <sreg>, #imm
4414 // vmov.f64 <dreg>, #imm
4415 // vmov.f32 <dreg>, #imm @ vector f32x2
4416 // vmov.f32 <qreg>, #imm @ vector f32x4
4418 // There are also the NEON VMOV instructions which expect an
4419 // integer constant. Make sure we don't try to parse an FPImm
4421 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4422 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4423 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4424 TyOp->getToken() != ".f64"))
4425 return MatchOperand_NoMatch;
4427 Parser.Lex(); // Eat the '#'.
4429 // Handle negation, as that still comes through as a separate token.
4430 bool isNegative = false;
4431 if (Parser.getTok().is(AsmToken::Minus)) {
4435 const AsmToken &Tok = Parser.getTok();
4436 SMLoc Loc = Tok.getLoc();
4437 if (Tok.is(AsmToken::Real)) {
4438 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4439 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4440 // If we had a '-' in front, toggle the sign bit.
4441 IntVal ^= (uint64_t)isNegative << 31;
4442 Parser.Lex(); // Eat the token.
4443 Operands.push_back(ARMOperand::CreateImm(
4444 MCConstantExpr::Create(IntVal, getContext()),
4445 S, Parser.getTok().getLoc()));
4446 return MatchOperand_Success;
4448 // Also handle plain integers. Instructions which allow floating point
4449 // immediates also allow a raw encoded 8-bit value.
4450 if (Tok.is(AsmToken::Integer)) {
4451 int64_t Val = Tok.getIntVal();
4452 Parser.Lex(); // Eat the token.
4453 if (Val > 255 || Val < 0) {
4454 Error(Loc, "encoded floating point value out of range");
4455 return MatchOperand_ParseFail;
4457 double RealVal = ARM_AM::getFPImmFloat(Val);
4458 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4459 Operands.push_back(ARMOperand::CreateImm(
4460 MCConstantExpr::Create(Val, getContext()), S,
4461 Parser.getTok().getLoc()));
4462 return MatchOperand_Success;
4465 Error(Loc, "invalid floating point immediate");
4466 return MatchOperand_ParseFail;
4469 /// Parse a arm instruction operand. For now this parses the operand regardless
4470 /// of the mnemonic.
4471 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4472 StringRef Mnemonic) {
4475 // Check if the current operand has a custom associated parser, if so, try to
4476 // custom parse the operand, or fallback to the general approach.
4477 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4478 if (ResTy == MatchOperand_Success)
4480 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4481 // there was a match, but an error occurred, in which case, just return that
4482 // the operand parsing failed.
4483 if (ResTy == MatchOperand_ParseFail)
4486 switch (getLexer().getKind()) {
4488 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4490 case AsmToken::Identifier: {
4491 if (!tryParseRegisterWithWriteBack(Operands))
4493 int Res = tryParseShiftRegister(Operands);
4494 if (Res == 0) // success
4496 else if (Res == -1) // irrecoverable error
4498 // If this is VMRS, check for the apsr_nzcv operand.
4499 if (Mnemonic == "vmrs" &&
4500 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4501 S = Parser.getTok().getLoc();
4503 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4507 // Fall though for the Identifier case that is not a register or a
4510 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4511 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4512 case AsmToken::String: // quoted label names.
4513 case AsmToken::Dot: { // . as a branch target
4514 // This was not a register so parse other operands that start with an
4515 // identifier (like labels) as expressions and create them as immediates.
4516 const MCExpr *IdVal;
4517 S = Parser.getTok().getLoc();
4518 if (getParser().ParseExpression(IdVal))
4520 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4521 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4524 case AsmToken::LBrac:
4525 return parseMemory(Operands);
4526 case AsmToken::LCurly:
4527 return parseRegisterList(Operands);
4528 case AsmToken::Dollar:
4529 case AsmToken::Hash: {
4530 // #42 -> immediate.
4531 S = Parser.getTok().getLoc();
4534 if (Parser.getTok().isNot(AsmToken::Colon)) {
4535 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4536 const MCExpr *ImmVal;
4537 if (getParser().ParseExpression(ImmVal))
4539 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4541 int32_t Val = CE->getValue();
4542 if (isNegative && Val == 0)
4543 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4545 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4546 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4549 // w/ a ':' after the '#', it's just like a plain ':'.
4552 case AsmToken::Colon: {
4553 // ":lower16:" and ":upper16:" expression prefixes
4554 // FIXME: Check it's an expression prefix,
4555 // e.g. (FOO - :lower16:BAR) isn't legal.
4556 ARMMCExpr::VariantKind RefKind;
4557 if (parsePrefix(RefKind))
4560 const MCExpr *SubExprVal;
4561 if (getParser().ParseExpression(SubExprVal))
4564 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4566 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4567 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4573 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4574 // :lower16: and :upper16:.
4575 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4576 RefKind = ARMMCExpr::VK_ARM_None;
4578 // :lower16: and :upper16: modifiers
4579 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4580 Parser.Lex(); // Eat ':'
4582 if (getLexer().isNot(AsmToken::Identifier)) {
4583 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4587 StringRef IDVal = Parser.getTok().getIdentifier();
4588 if (IDVal == "lower16") {
4589 RefKind = ARMMCExpr::VK_ARM_LO16;
4590 } else if (IDVal == "upper16") {
4591 RefKind = ARMMCExpr::VK_ARM_HI16;
4593 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4598 if (getLexer().isNot(AsmToken::Colon)) {
4599 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4602 Parser.Lex(); // Eat the last ':'
4606 /// \brief Given a mnemonic, split out possible predication code and carry
4607 /// setting letters to form a canonical mnemonic and flags.
4609 // FIXME: Would be nice to autogen this.
4610 // FIXME: This is a bit of a maze of special cases.
4611 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4612 unsigned &PredicationCode,
4614 unsigned &ProcessorIMod,
4615 StringRef &ITMask) {
4616 PredicationCode = ARMCC::AL;
4617 CarrySetting = false;
4620 // Ignore some mnemonics we know aren't predicated forms.
4622 // FIXME: Would be nice to autogen this.
4623 if ((Mnemonic == "movs" && isThumb()) ||
4624 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4625 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4626 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4627 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4628 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4629 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4630 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4631 Mnemonic == "fmuls")
4634 // First, split out any predication code. Ignore mnemonics we know aren't
4635 // predicated but do have a carry-set and so weren't caught above.
4636 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4637 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4638 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4639 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4640 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4641 .Case("eq", ARMCC::EQ)
4642 .Case("ne", ARMCC::NE)
4643 .Case("hs", ARMCC::HS)
4644 .Case("cs", ARMCC::HS)
4645 .Case("lo", ARMCC::LO)
4646 .Case("cc", ARMCC::LO)
4647 .Case("mi", ARMCC::MI)
4648 .Case("pl", ARMCC::PL)
4649 .Case("vs", ARMCC::VS)
4650 .Case("vc", ARMCC::VC)
4651 .Case("hi", ARMCC::HI)
4652 .Case("ls", ARMCC::LS)
4653 .Case("ge", ARMCC::GE)
4654 .Case("lt", ARMCC::LT)
4655 .Case("gt", ARMCC::GT)
4656 .Case("le", ARMCC::LE)
4657 .Case("al", ARMCC::AL)
4660 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4661 PredicationCode = CC;
4665 // Next, determine if we have a carry setting bit. We explicitly ignore all
4666 // the instructions we know end in 's'.
4667 if (Mnemonic.endswith("s") &&
4668 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4669 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4670 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4671 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4672 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4673 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4674 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4675 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4676 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4677 (Mnemonic == "movs" && isThumb()))) {
4678 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4679 CarrySetting = true;
4682 // The "cps" instruction can have a interrupt mode operand which is glued into
4683 // the mnemonic. Check if this is the case, split it and parse the imod op
4684 if (Mnemonic.startswith("cps")) {
4685 // Split out any imod code.
4687 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4688 .Case("ie", ARM_PROC::IE)
4689 .Case("id", ARM_PROC::ID)
4692 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4693 ProcessorIMod = IMod;
4697 // The "it" instruction has the condition mask on the end of the mnemonic.
4698 if (Mnemonic.startswith("it")) {
4699 ITMask = Mnemonic.slice(2, Mnemonic.size());
4700 Mnemonic = Mnemonic.slice(0, 2);
4706 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4707 /// inclusion of carry set or predication code operands.
4709 // FIXME: It would be nice to autogen this.
4711 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4712 bool &CanAcceptPredicationCode) {
4713 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4714 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4715 Mnemonic == "add" || Mnemonic == "adc" ||
4716 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4717 Mnemonic == "orr" || Mnemonic == "mvn" ||
4718 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4719 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4720 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4721 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4722 Mnemonic == "mla" || Mnemonic == "smlal" ||
4723 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4724 CanAcceptCarrySet = true;
4726 CanAcceptCarrySet = false;
4728 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4729 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4730 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4731 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
4732 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4733 (Mnemonic == "clrex" && !isThumb()) ||
4734 (Mnemonic == "nop" && isThumbOne()) ||
4735 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4736 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4737 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
4738 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4740 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
4741 CanAcceptPredicationCode = false;
4743 CanAcceptPredicationCode = true;
4746 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
4747 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
4748 CanAcceptPredicationCode = false;
4752 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4753 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4754 // FIXME: This is all horribly hacky. We really need a better way to deal
4755 // with optional operands like this in the matcher table.
4757 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4758 // another does not. Specifically, the MOVW instruction does not. So we
4759 // special case it here and remove the defaulted (non-setting) cc_out
4760 // operand if that's the instruction we're trying to match.
4762 // We do this as post-processing of the explicit operands rather than just
4763 // conditionally adding the cc_out in the first place because we need
4764 // to check the type of the parsed immediate operand.
4765 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4766 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4767 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4768 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4771 // Register-register 'add' for thumb does not have a cc_out operand
4772 // when there are only two register operands.
4773 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4774 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4775 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4776 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4778 // Register-register 'add' for thumb does not have a cc_out operand
4779 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4780 // have to check the immediate range here since Thumb2 has a variant
4781 // that can handle a different range and has a cc_out operand.
4782 if (((isThumb() && Mnemonic == "add") ||
4783 (isThumbTwo() && Mnemonic == "sub")) &&
4784 Operands.size() == 6 &&
4785 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4786 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4787 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4788 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4789 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4790 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4792 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4793 // imm0_4095 variant. That's the least-preferred variant when
4794 // selecting via the generic "add" mnemonic, so to know that we
4795 // should remove the cc_out operand, we have to explicitly check that
4796 // it's not one of the other variants. Ugh.
4797 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4798 Operands.size() == 6 &&
4799 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4800 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4801 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4802 // Nest conditions rather than one big 'if' statement for readability.
4804 // If either register is a high reg, it's either one of the SP
4805 // variants (handled above) or a 32-bit encoding, so we just
4806 // check against T3. If the second register is the PC, this is an
4807 // alternate form of ADR, which uses encoding T4, so check for that too.
4808 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4809 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
4810 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4811 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4813 // If both registers are low, we're in an IT block, and the immediate is
4814 // in range, we should use encoding T1 instead, which has a cc_out.
4816 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4817 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4818 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4821 // Otherwise, we use encoding T4, which does not have a cc_out
4826 // The thumb2 multiply instruction doesn't have a CCOut register, so
4827 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4828 // use the 16-bit encoding or not.
4829 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4830 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4831 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4832 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4833 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4834 // If the registers aren't low regs, the destination reg isn't the
4835 // same as one of the source regs, or the cc_out operand is zero
4836 // outside of an IT block, we have to use the 32-bit encoding, so
4837 // remove the cc_out operand.
4838 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4839 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4840 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4842 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4843 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4844 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4845 static_cast<ARMOperand*>(Operands[4])->getReg())))
4848 // Also check the 'mul' syntax variant that doesn't specify an explicit
4849 // destination register.
4850 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4851 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4852 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4853 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4854 // If the registers aren't low regs or the cc_out operand is zero
4855 // outside of an IT block, we have to use the 32-bit encoding, so
4856 // remove the cc_out operand.
4857 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4858 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4864 // Register-register 'add/sub' for thumb does not have a cc_out operand
4865 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4866 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4867 // right, this will result in better diagnostics (which operand is off)
4869 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4870 (Operands.size() == 5 || Operands.size() == 6) &&
4871 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4872 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4873 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4874 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4875 (Operands.size() == 6 &&
4876 static_cast<ARMOperand*>(Operands[5])->isImm())))
4882 static bool isDataTypeToken(StringRef Tok) {
4883 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4884 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4885 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4886 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4887 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4888 Tok == ".f" || Tok == ".d";
4891 // FIXME: This bit should probably be handled via an explicit match class
4892 // in the .td files that matches the suffix instead of having it be
4893 // a literal string token the way it is now.
4894 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4895 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4898 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
4899 /// Parse an arm instruction mnemonic followed by its operands.
4900 bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4901 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4902 // Apply mnemonic aliases before doing anything else, as the destination
4903 // mnemnonic may include suffices and we want to handle them normally.
4904 // The generic tblgen'erated code does this later, at the start of
4905 // MatchInstructionImpl(), but that's too late for aliases that include
4906 // any sort of suffix.
4907 unsigned AvailableFeatures = getAvailableFeatures();
4908 applyMnemonicAliases(Name, AvailableFeatures);
4910 // First check for the ARM-specific .req directive.
4911 if (Parser.getTok().is(AsmToken::Identifier) &&
4912 Parser.getTok().getIdentifier() == ".req") {
4913 parseDirectiveReq(Name, NameLoc);
4914 // We always return 'error' for this, as we're done with this
4915 // statement and don't need to match the 'instruction."
4919 // Create the leading tokens for the mnemonic, split by '.' characters.
4920 size_t Start = 0, Next = Name.find('.');
4921 StringRef Mnemonic = Name.slice(Start, Next);
4923 // Split out the predication code and carry setting flag from the mnemonic.
4924 unsigned PredicationCode;
4925 unsigned ProcessorIMod;
4928 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
4929 ProcessorIMod, ITMask);
4931 // In Thumb1, only the branch (B) instruction can be predicated.
4932 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4933 Parser.EatToEndOfStatement();
4934 return Error(NameLoc, "conditional execution not supported in Thumb1");
4937 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4939 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4940 // is the mask as it will be for the IT encoding if the conditional
4941 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4942 // where the conditional bit0 is zero, the instruction post-processing
4943 // will adjust the mask accordingly.
4944 if (Mnemonic == "it") {
4945 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4946 if (ITMask.size() > 3) {
4947 Parser.EatToEndOfStatement();
4948 return Error(Loc, "too many conditions on IT instruction");
4951 for (unsigned i = ITMask.size(); i != 0; --i) {
4952 char pos = ITMask[i - 1];
4953 if (pos != 't' && pos != 'e') {
4954 Parser.EatToEndOfStatement();
4955 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
4958 if (ITMask[i - 1] == 't')
4961 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
4964 // FIXME: This is all a pretty gross hack. We should automatically handle
4965 // optional operands like this via tblgen.
4967 // Next, add the CCOut and ConditionCode operands, if needed.
4969 // For mnemonics which can ever incorporate a carry setting bit or predication
4970 // code, our matching model involves us always generating CCOut and
4971 // ConditionCode operands to match the mnemonic "as written" and then we let
4972 // the matcher deal with finding the right instruction or generating an
4973 // appropriate error.
4974 bool CanAcceptCarrySet, CanAcceptPredicationCode;
4975 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
4977 // If we had a carry-set on an instruction that can't do that, issue an
4979 if (!CanAcceptCarrySet && CarrySetting) {
4980 Parser.EatToEndOfStatement();
4981 return Error(NameLoc, "instruction '" + Mnemonic +
4982 "' can not set flags, but 's' suffix specified");
4984 // If we had a predication code on an instruction that can't do that, issue an
4986 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
4987 Parser.EatToEndOfStatement();
4988 return Error(NameLoc, "instruction '" + Mnemonic +
4989 "' is not predicable, but condition code specified");
4992 // Add the carry setting operand, if necessary.
4993 if (CanAcceptCarrySet) {
4994 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
4995 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
4999 // Add the predication code operand, if necessary.
5000 if (CanAcceptPredicationCode) {
5001 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5003 Operands.push_back(ARMOperand::CreateCondCode(
5004 ARMCC::CondCodes(PredicationCode), Loc));
5007 // Add the processor imod operand, if necessary.
5008 if (ProcessorIMod) {
5009 Operands.push_back(ARMOperand::CreateImm(
5010 MCConstantExpr::Create(ProcessorIMod, getContext()),
5014 // Add the remaining tokens in the mnemonic.
5015 while (Next != StringRef::npos) {
5017 Next = Name.find('.', Start + 1);
5018 StringRef ExtraToken = Name.slice(Start, Next);
5020 // Some NEON instructions have an optional datatype suffix that is
5021 // completely ignored. Check for that.
5022 if (isDataTypeToken(ExtraToken) &&
5023 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5026 if (ExtraToken != ".n") {
5027 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5028 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5032 // Read the remaining operands.
5033 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5034 // Read the first operand.
5035 if (parseOperand(Operands, Mnemonic)) {
5036 Parser.EatToEndOfStatement();
5040 while (getLexer().is(AsmToken::Comma)) {
5041 Parser.Lex(); // Eat the comma.
5043 // Parse and remember the operand.
5044 if (parseOperand(Operands, Mnemonic)) {
5045 Parser.EatToEndOfStatement();
5051 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5052 SMLoc Loc = getLexer().getLoc();
5053 Parser.EatToEndOfStatement();
5054 return Error(Loc, "unexpected token in argument list");
5057 Parser.Lex(); // Consume the EndOfStatement
5059 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5060 // do and don't have a cc_out optional-def operand. With some spot-checks
5061 // of the operand list, we can figure out which variant we're trying to
5062 // parse and adjust accordingly before actually matching. We shouldn't ever
5063 // try to remove a cc_out operand that was explicitly set on the the
5064 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5065 // table driven matcher doesn't fit well with the ARM instruction set.
5066 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5067 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5068 Operands.erase(Operands.begin() + 1);
5072 // ARM mode 'blx' need special handling, as the register operand version
5073 // is predicable, but the label operand version is not. So, we can't rely
5074 // on the Mnemonic based checking to correctly figure out when to put
5075 // a k_CondCode operand in the list. If we're trying to match the label
5076 // version, remove the k_CondCode operand here.
5077 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5078 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5079 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5080 Operands.erase(Operands.begin() + 1);
5084 // The vector-compare-to-zero instructions have a literal token "#0" at
5085 // the end that comes to here as an immediate operand. Convert it to a
5086 // token to play nicely with the matcher.
5087 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5088 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5089 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5090 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5091 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5092 if (CE && CE->getValue() == 0) {
5093 Operands.erase(Operands.begin() + 5);
5094 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5098 // VCMP{E} does the same thing, but with a different operand count.
5099 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5100 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5101 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5102 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5103 if (CE && CE->getValue() == 0) {
5104 Operands.erase(Operands.begin() + 4);
5105 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5109 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
5110 // end. Convert it to a token here. Take care not to convert those
5111 // that should hit the Thumb2 encoding.
5112 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
5113 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5114 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5115 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5116 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5117 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5118 if (CE && CE->getValue() == 0 &&
5120 // The cc_out operand matches the IT block.
5121 ((inITBlock() != CarrySetting) &&
5122 // Neither register operand is a high register.
5123 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5124 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
5125 Operands.erase(Operands.begin() + 5);
5126 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5134 // Validate context-sensitive operand constraints.
5136 // return 'true' if register list contains non-low GPR registers,
5137 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5138 // 'containsReg' to true.
5139 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5140 unsigned HiReg, bool &containsReg) {
5141 containsReg = false;
5142 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5143 unsigned OpReg = Inst.getOperand(i).getReg();
5146 // Anything other than a low register isn't legal here.
5147 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5153 // Check if the specified regisgter is in the register list of the inst,
5154 // starting at the indicated operand number.
5155 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5156 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5157 unsigned OpReg = Inst.getOperand(i).getReg();
5164 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5165 // the ARMInsts array) instead. Getting that here requires awkward
5166 // API changes, though. Better way?
5168 extern const MCInstrDesc ARMInsts[];
5170 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5171 return ARMInsts[Opcode];
5174 // FIXME: We would really like to be able to tablegen'erate this.
5176 validateInstruction(MCInst &Inst,
5177 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5178 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5179 SMLoc Loc = Operands[0]->getStartLoc();
5180 // Check the IT block state first.
5181 // NOTE: BKPT instruction has the interesting property of being
5182 // allowed in IT blocks, but not being predicable. It just always
5184 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5185 Inst.getOpcode() != ARM::BKPT) {
5187 if (ITState.FirstCond)
5188 ITState.FirstCond = false;
5190 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5191 // The instruction must be predicable.
5192 if (!MCID.isPredicable())
5193 return Error(Loc, "instructions in IT block must be predicable");
5194 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5195 unsigned ITCond = bit ? ITState.Cond :
5196 ARMCC::getOppositeCondition(ITState.Cond);
5197 if (Cond != ITCond) {
5198 // Find the condition code Operand to get its SMLoc information.
5200 for (unsigned i = 1; i < Operands.size(); ++i)
5201 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5202 CondLoc = Operands[i]->getStartLoc();
5203 return Error(CondLoc, "incorrect condition in IT block; got '" +
5204 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5205 "', but expected '" +
5206 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5208 // Check for non-'al' condition codes outside of the IT block.
5209 } else if (isThumbTwo() && MCID.isPredicable() &&
5210 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5211 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5212 Inst.getOpcode() != ARM::t2B)
5213 return Error(Loc, "predicated instructions must be in IT block");
5215 switch (Inst.getOpcode()) {
5218 case ARM::LDRD_POST:
5220 // Rt2 must be Rt + 1.
5221 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5222 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5224 return Error(Operands[3]->getStartLoc(),
5225 "destination operands must be sequential");
5229 // Rt2 must be Rt + 1.
5230 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5231 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5233 return Error(Operands[3]->getStartLoc(),
5234 "source operands must be sequential");
5238 case ARM::STRD_POST:
5240 // Rt2 must be Rt + 1.
5241 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5242 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(2).getReg());
5244 return Error(Operands[3]->getStartLoc(),
5245 "source operands must be sequential");
5250 // width must be in range [1, 32-lsb]
5251 unsigned lsb = Inst.getOperand(2).getImm();
5252 unsigned widthm1 = Inst.getOperand(3).getImm();
5253 if (widthm1 >= 32 - lsb)
5254 return Error(Operands[5]->getStartLoc(),
5255 "bitfield width must be in range [1,32-lsb]");
5259 // If we're parsing Thumb2, the .w variant is available and handles
5260 // most cases that are normally illegal for a Thumb1 LDM
5261 // instruction. We'll make the transformation in processInstruction()
5264 // Thumb LDM instructions are writeback iff the base register is not
5265 // in the register list.
5266 unsigned Rn = Inst.getOperand(0).getReg();
5267 bool hasWritebackToken =
5268 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5269 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5270 bool listContainsBase;
5271 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5272 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5273 "registers must be in range r0-r7");
5274 // If we should have writeback, then there should be a '!' token.
5275 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5276 return Error(Operands[2]->getStartLoc(),
5277 "writeback operator '!' expected");
5278 // If we should not have writeback, there must not be a '!'. This is
5279 // true even for the 32-bit wide encodings.
5280 if (listContainsBase && hasWritebackToken)
5281 return Error(Operands[3]->getStartLoc(),
5282 "writeback operator '!' not allowed when base register "
5283 "in register list");
5287 case ARM::t2LDMIA_UPD: {
5288 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5289 return Error(Operands[4]->getStartLoc(),
5290 "writeback operator '!' not allowed when base register "
5291 "in register list");
5294 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5295 // so only issue a diagnostic for thumb1. The instructions will be
5296 // switched to the t2 encodings in processInstruction() if necessary.
5298 bool listContainsBase;
5299 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5301 return Error(Operands[2]->getStartLoc(),
5302 "registers must be in range r0-r7 or pc");
5306 bool listContainsBase;
5307 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5309 return Error(Operands[2]->getStartLoc(),
5310 "registers must be in range r0-r7 or lr");
5313 case ARM::tSTMIA_UPD: {
5314 bool listContainsBase;
5315 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5316 return Error(Operands[4]->getStartLoc(),
5317 "registers must be in range r0-r7");
5325 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5327 default: llvm_unreachable("unexpected opcode!");
5329 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5330 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5331 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5332 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5333 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5334 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5335 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5336 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5337 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5340 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5341 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5342 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5343 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5344 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5346 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5347 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5348 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5349 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5350 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5352 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5353 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5354 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5355 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5356 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5359 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5360 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5361 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5362 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5363 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5364 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5365 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5366 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5367 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5368 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5369 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5370 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5371 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5372 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5373 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5376 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5377 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5378 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5379 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5380 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5381 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5382 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5383 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5384 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5385 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5386 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5387 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5388 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5389 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5390 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5391 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5392 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5393 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5396 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5397 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5398 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5399 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5400 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5401 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5402 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5403 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5404 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5405 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5406 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5407 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5408 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5409 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5410 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5413 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5414 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5415 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5416 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5417 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5418 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5419 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5420 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5421 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5422 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5423 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5424 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5425 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5426 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5427 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5428 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5429 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5430 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5434 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5436 default: llvm_unreachable("unexpected opcode!");
5438 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5439 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5440 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5441 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5442 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5443 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5444 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5445 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5446 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5449 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5450 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5451 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5452 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5453 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5454 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5455 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5456 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5457 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5458 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5459 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5460 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5461 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5462 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5463 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5466 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5467 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5468 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5469 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5470 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5471 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5472 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5473 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5474 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5475 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5476 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5477 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5478 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5479 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5480 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5481 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5482 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5483 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5486 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5487 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5488 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5489 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5490 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5491 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5492 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5493 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5494 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5495 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5496 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5497 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5498 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5499 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5500 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5503 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5504 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5505 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5506 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5507 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5508 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5509 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5510 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5511 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5512 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5513 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5514 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5515 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5516 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5517 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5518 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5519 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5520 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5523 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5524 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5525 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5526 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5527 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5528 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5529 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5530 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5531 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5532 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5533 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5534 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5535 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5536 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5537 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5540 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5541 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5542 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5543 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5544 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5545 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5546 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5547 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5548 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5549 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5550 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5551 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5552 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5553 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5554 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5555 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5556 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5557 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5560 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5561 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5562 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5563 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5564 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5565 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5566 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5567 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5568 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5569 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5570 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5571 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5572 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5573 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5574 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5575 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5576 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5577 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5582 processInstruction(MCInst &Inst,
5583 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5584 switch (Inst.getOpcode()) {
5585 // Aliases for alternate PC+imm syntax of LDR instructions.
5586 case ARM::t2LDRpcrel:
5587 Inst.setOpcode(ARM::t2LDRpci);
5589 case ARM::t2LDRBpcrel:
5590 Inst.setOpcode(ARM::t2LDRBpci);
5592 case ARM::t2LDRHpcrel:
5593 Inst.setOpcode(ARM::t2LDRHpci);
5595 case ARM::t2LDRSBpcrel:
5596 Inst.setOpcode(ARM::t2LDRSBpci);
5598 case ARM::t2LDRSHpcrel:
5599 Inst.setOpcode(ARM::t2LDRSHpci);
5601 // Handle NEON VST complex aliases.
5602 case ARM::VST1LNdWB_register_Asm_8:
5603 case ARM::VST1LNdWB_register_Asm_16:
5604 case ARM::VST1LNdWB_register_Asm_32: {
5606 // Shuffle the operands around so the lane index operand is in the
5609 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5610 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5611 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5612 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5613 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5614 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5615 TmpInst.addOperand(Inst.getOperand(1)); // lane
5616 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5617 TmpInst.addOperand(Inst.getOperand(6));
5622 case ARM::VST2LNdWB_register_Asm_8:
5623 case ARM::VST2LNdWB_register_Asm_16:
5624 case ARM::VST2LNdWB_register_Asm_32:
5625 case ARM::VST2LNqWB_register_Asm_16:
5626 case ARM::VST2LNqWB_register_Asm_32: {
5628 // Shuffle the operands around so the lane index operand is in the
5631 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5632 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5633 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5634 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5635 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5636 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5637 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5639 TmpInst.addOperand(Inst.getOperand(1)); // lane
5640 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5641 TmpInst.addOperand(Inst.getOperand(6));
5646 case ARM::VST3LNdWB_register_Asm_8:
5647 case ARM::VST3LNdWB_register_Asm_16:
5648 case ARM::VST3LNdWB_register_Asm_32:
5649 case ARM::VST3LNqWB_register_Asm_16:
5650 case ARM::VST3LNqWB_register_Asm_32: {
5652 // Shuffle the operands around so the lane index operand is in the
5655 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5656 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5657 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5658 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5659 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5660 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5661 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5665 TmpInst.addOperand(Inst.getOperand(1)); // lane
5666 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5667 TmpInst.addOperand(Inst.getOperand(6));
5672 case ARM::VST4LNdWB_register_Asm_8:
5673 case ARM::VST4LNdWB_register_Asm_16:
5674 case ARM::VST4LNdWB_register_Asm_32:
5675 case ARM::VST4LNqWB_register_Asm_16:
5676 case ARM::VST4LNqWB_register_Asm_32: {
5678 // Shuffle the operands around so the lane index operand is in the
5681 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5682 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5683 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5684 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5685 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5686 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5687 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5689 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5691 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5693 TmpInst.addOperand(Inst.getOperand(1)); // lane
5694 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5695 TmpInst.addOperand(Inst.getOperand(6));
5700 case ARM::VST1LNdWB_fixed_Asm_8:
5701 case ARM::VST1LNdWB_fixed_Asm_16:
5702 case ARM::VST1LNdWB_fixed_Asm_32: {
5704 // Shuffle the operands around so the lane index operand is in the
5707 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5708 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5709 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5710 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5711 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5712 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5713 TmpInst.addOperand(Inst.getOperand(1)); // lane
5714 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5715 TmpInst.addOperand(Inst.getOperand(5));
5720 case ARM::VST2LNdWB_fixed_Asm_8:
5721 case ARM::VST2LNdWB_fixed_Asm_16:
5722 case ARM::VST2LNdWB_fixed_Asm_32:
5723 case ARM::VST2LNqWB_fixed_Asm_16:
5724 case ARM::VST2LNqWB_fixed_Asm_32: {
5726 // Shuffle the operands around so the lane index operand is in the
5729 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5730 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5731 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5732 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5733 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5734 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5735 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5737 TmpInst.addOperand(Inst.getOperand(1)); // lane
5738 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5739 TmpInst.addOperand(Inst.getOperand(5));
5744 case ARM::VST3LNdWB_fixed_Asm_8:
5745 case ARM::VST3LNdWB_fixed_Asm_16:
5746 case ARM::VST3LNdWB_fixed_Asm_32:
5747 case ARM::VST3LNqWB_fixed_Asm_16:
5748 case ARM::VST3LNqWB_fixed_Asm_32: {
5750 // Shuffle the operands around so the lane index operand is in the
5753 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5754 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5755 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5756 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5757 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5758 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5761 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5763 TmpInst.addOperand(Inst.getOperand(1)); // lane
5764 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5765 TmpInst.addOperand(Inst.getOperand(5));
5770 case ARM::VST4LNdWB_fixed_Asm_8:
5771 case ARM::VST4LNdWB_fixed_Asm_16:
5772 case ARM::VST4LNdWB_fixed_Asm_32:
5773 case ARM::VST4LNqWB_fixed_Asm_16:
5774 case ARM::VST4LNqWB_fixed_Asm_32: {
5776 // Shuffle the operands around so the lane index operand is in the
5779 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5780 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5781 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5782 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5783 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5784 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5787 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5789 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5791 TmpInst.addOperand(Inst.getOperand(1)); // lane
5792 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5793 TmpInst.addOperand(Inst.getOperand(5));
5798 case ARM::VST1LNdAsm_8:
5799 case ARM::VST1LNdAsm_16:
5800 case ARM::VST1LNdAsm_32: {
5802 // Shuffle the operands around so the lane index operand is in the
5805 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5806 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5807 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5808 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5809 TmpInst.addOperand(Inst.getOperand(1)); // lane
5810 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5811 TmpInst.addOperand(Inst.getOperand(5));
5816 case ARM::VST2LNdAsm_8:
5817 case ARM::VST2LNdAsm_16:
5818 case ARM::VST2LNdAsm_32:
5819 case ARM::VST2LNqAsm_16:
5820 case ARM::VST2LNqAsm_32: {
5822 // Shuffle the operands around so the lane index operand is in the
5825 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5826 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5827 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5828 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5829 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5831 TmpInst.addOperand(Inst.getOperand(1)); // lane
5832 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5833 TmpInst.addOperand(Inst.getOperand(5));
5838 case ARM::VST3LNdAsm_8:
5839 case ARM::VST3LNdAsm_16:
5840 case ARM::VST3LNdAsm_32:
5841 case ARM::VST3LNqAsm_16:
5842 case ARM::VST3LNqAsm_32: {
5844 // Shuffle the operands around so the lane index operand is in the
5847 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5848 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5849 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5850 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5853 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5855 TmpInst.addOperand(Inst.getOperand(1)); // lane
5856 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5857 TmpInst.addOperand(Inst.getOperand(5));
5862 case ARM::VST4LNdAsm_8:
5863 case ARM::VST4LNdAsm_16:
5864 case ARM::VST4LNdAsm_32:
5865 case ARM::VST4LNqAsm_16:
5866 case ARM::VST4LNqAsm_32: {
5868 // Shuffle the operands around so the lane index operand is in the
5871 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5872 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5873 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5874 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5875 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5877 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5881 TmpInst.addOperand(Inst.getOperand(1)); // lane
5882 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5883 TmpInst.addOperand(Inst.getOperand(5));
5888 // Handle NEON VLD complex aliases.
5889 case ARM::VLD1LNdWB_register_Asm_8:
5890 case ARM::VLD1LNdWB_register_Asm_16:
5891 case ARM::VLD1LNdWB_register_Asm_32: {
5893 // Shuffle the operands around so the lane index operand is in the
5896 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5897 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5898 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5899 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5900 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5901 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5902 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5903 TmpInst.addOperand(Inst.getOperand(1)); // lane
5904 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5905 TmpInst.addOperand(Inst.getOperand(6));
5910 case ARM::VLD2LNdWB_register_Asm_8:
5911 case ARM::VLD2LNdWB_register_Asm_16:
5912 case ARM::VLD2LNdWB_register_Asm_32:
5913 case ARM::VLD2LNqWB_register_Asm_16:
5914 case ARM::VLD2LNqWB_register_Asm_32: {
5916 // Shuffle the operands around so the lane index operand is in the
5919 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5920 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5921 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5923 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5924 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5925 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5926 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5927 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5928 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5930 TmpInst.addOperand(Inst.getOperand(1)); // lane
5931 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5932 TmpInst.addOperand(Inst.getOperand(6));
5937 case ARM::VLD3LNdWB_register_Asm_8:
5938 case ARM::VLD3LNdWB_register_Asm_16:
5939 case ARM::VLD3LNdWB_register_Asm_32:
5940 case ARM::VLD3LNqWB_register_Asm_16:
5941 case ARM::VLD3LNqWB_register_Asm_32: {
5943 // Shuffle the operands around so the lane index operand is in the
5946 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5947 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5948 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5950 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5952 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5953 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5954 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5955 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5956 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5957 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5959 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5961 TmpInst.addOperand(Inst.getOperand(1)); // lane
5962 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5963 TmpInst.addOperand(Inst.getOperand(6));
5968 case ARM::VLD4LNdWB_register_Asm_8:
5969 case ARM::VLD4LNdWB_register_Asm_16:
5970 case ARM::VLD4LNdWB_register_Asm_32:
5971 case ARM::VLD4LNqWB_register_Asm_16:
5972 case ARM::VLD4LNqWB_register_Asm_32: {
5974 // Shuffle the operands around so the lane index operand is in the
5977 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5978 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5981 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5983 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5985 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5986 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5987 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5988 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5989 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5990 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5992 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5994 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5996 TmpInst.addOperand(Inst.getOperand(1)); // lane
5997 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5998 TmpInst.addOperand(Inst.getOperand(6));
6003 case ARM::VLD1LNdWB_fixed_Asm_8:
6004 case ARM::VLD1LNdWB_fixed_Asm_16:
6005 case ARM::VLD1LNdWB_fixed_Asm_32: {
6007 // Shuffle the operands around so the lane index operand is in the
6010 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6011 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6012 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6013 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6014 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6015 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6016 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6017 TmpInst.addOperand(Inst.getOperand(1)); // lane
6018 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6019 TmpInst.addOperand(Inst.getOperand(5));
6024 case ARM::VLD2LNdWB_fixed_Asm_8:
6025 case ARM::VLD2LNdWB_fixed_Asm_16:
6026 case ARM::VLD2LNdWB_fixed_Asm_32:
6027 case ARM::VLD2LNqWB_fixed_Asm_16:
6028 case ARM::VLD2LNqWB_fixed_Asm_32: {
6030 // Shuffle the operands around so the lane index operand is in the
6033 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6034 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6035 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6037 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6038 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6039 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6040 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6041 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6042 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6044 TmpInst.addOperand(Inst.getOperand(1)); // lane
6045 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6046 TmpInst.addOperand(Inst.getOperand(5));
6051 case ARM::VLD3LNdWB_fixed_Asm_8:
6052 case ARM::VLD3LNdWB_fixed_Asm_16:
6053 case ARM::VLD3LNdWB_fixed_Asm_32:
6054 case ARM::VLD3LNqWB_fixed_Asm_16:
6055 case ARM::VLD3LNqWB_fixed_Asm_32: {
6057 // Shuffle the operands around so the lane index operand is in the
6060 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6061 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6062 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6064 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6066 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6067 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6068 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6069 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6070 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6071 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6075 TmpInst.addOperand(Inst.getOperand(1)); // lane
6076 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6077 TmpInst.addOperand(Inst.getOperand(5));
6082 case ARM::VLD4LNdWB_fixed_Asm_8:
6083 case ARM::VLD4LNdWB_fixed_Asm_16:
6084 case ARM::VLD4LNdWB_fixed_Asm_32:
6085 case ARM::VLD4LNqWB_fixed_Asm_16:
6086 case ARM::VLD4LNqWB_fixed_Asm_32: {
6088 // Shuffle the operands around so the lane index operand is in the
6091 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6092 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6093 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6095 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6097 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6099 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6100 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6101 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6102 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6103 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6104 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6108 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6110 TmpInst.addOperand(Inst.getOperand(1)); // lane
6111 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6112 TmpInst.addOperand(Inst.getOperand(5));
6117 case ARM::VLD1LNdAsm_8:
6118 case ARM::VLD1LNdAsm_16:
6119 case ARM::VLD1LNdAsm_32: {
6121 // Shuffle the operands around so the lane index operand is in the
6124 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6125 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6126 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6127 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6128 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6129 TmpInst.addOperand(Inst.getOperand(1)); // lane
6130 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6131 TmpInst.addOperand(Inst.getOperand(5));
6136 case ARM::VLD2LNdAsm_8:
6137 case ARM::VLD2LNdAsm_16:
6138 case ARM::VLD2LNdAsm_32:
6139 case ARM::VLD2LNqAsm_16:
6140 case ARM::VLD2LNqAsm_32: {
6142 // Shuffle the operands around so the lane index operand is in the
6145 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6146 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6147 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6149 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6150 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6151 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6152 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6154 TmpInst.addOperand(Inst.getOperand(1)); // lane
6155 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6156 TmpInst.addOperand(Inst.getOperand(5));
6161 case ARM::VLD3LNdAsm_8:
6162 case ARM::VLD3LNdAsm_16:
6163 case ARM::VLD3LNdAsm_32:
6164 case ARM::VLD3LNqAsm_16:
6165 case ARM::VLD3LNqAsm_32: {
6167 // Shuffle the operands around so the lane index operand is in the
6170 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6171 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6172 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6174 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6176 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6177 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6178 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6179 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6181 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6183 TmpInst.addOperand(Inst.getOperand(1)); // lane
6184 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6185 TmpInst.addOperand(Inst.getOperand(5));
6190 case ARM::VLD4LNdAsm_8:
6191 case ARM::VLD4LNdAsm_16:
6192 case ARM::VLD4LNdAsm_32:
6193 case ARM::VLD4LNqAsm_16:
6194 case ARM::VLD4LNqAsm_32: {
6196 // Shuffle the operands around so the lane index operand is in the
6199 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6200 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6201 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6203 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6205 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6207 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6208 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6209 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6210 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6212 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6214 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6216 TmpInst.addOperand(Inst.getOperand(1)); // lane
6217 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6218 TmpInst.addOperand(Inst.getOperand(5));
6223 // VLD3DUP single 3-element structure to all lanes instructions.
6224 case ARM::VLD3DUPdAsm_8:
6225 case ARM::VLD3DUPdAsm_16:
6226 case ARM::VLD3DUPdAsm_32:
6227 case ARM::VLD3DUPqAsm_8:
6228 case ARM::VLD3DUPqAsm_16:
6229 case ARM::VLD3DUPqAsm_32: {
6232 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6233 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6234 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6236 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6238 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6239 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6240 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6241 TmpInst.addOperand(Inst.getOperand(4));
6246 case ARM::VLD3DUPdWB_fixed_Asm_8:
6247 case ARM::VLD3DUPdWB_fixed_Asm_16:
6248 case ARM::VLD3DUPdWB_fixed_Asm_32:
6249 case ARM::VLD3DUPqWB_fixed_Asm_8:
6250 case ARM::VLD3DUPqWB_fixed_Asm_16:
6251 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6254 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6255 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6258 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6260 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6261 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6262 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6263 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6264 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6265 TmpInst.addOperand(Inst.getOperand(4));
6270 case ARM::VLD3DUPdWB_register_Asm_8:
6271 case ARM::VLD3DUPdWB_register_Asm_16:
6272 case ARM::VLD3DUPdWB_register_Asm_32:
6273 case ARM::VLD3DUPqWB_register_Asm_8:
6274 case ARM::VLD3DUPqWB_register_Asm_16:
6275 case ARM::VLD3DUPqWB_register_Asm_32: {
6278 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6279 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6282 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6284 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6285 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6286 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6287 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6288 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6289 TmpInst.addOperand(Inst.getOperand(5));
6294 // VLD3 multiple 3-element structure instructions.
6295 case ARM::VLD3dAsm_8:
6296 case ARM::VLD3dAsm_16:
6297 case ARM::VLD3dAsm_32:
6298 case ARM::VLD3qAsm_8:
6299 case ARM::VLD3qAsm_16:
6300 case ARM::VLD3qAsm_32: {
6303 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6304 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6305 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6307 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6309 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6310 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6311 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6312 TmpInst.addOperand(Inst.getOperand(4));
6317 case ARM::VLD3dWB_fixed_Asm_8:
6318 case ARM::VLD3dWB_fixed_Asm_16:
6319 case ARM::VLD3dWB_fixed_Asm_32:
6320 case ARM::VLD3qWB_fixed_Asm_8:
6321 case ARM::VLD3qWB_fixed_Asm_16:
6322 case ARM::VLD3qWB_fixed_Asm_32: {
6325 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6326 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6327 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6329 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6331 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6332 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6333 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6334 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6335 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6336 TmpInst.addOperand(Inst.getOperand(4));
6341 case ARM::VLD3dWB_register_Asm_8:
6342 case ARM::VLD3dWB_register_Asm_16:
6343 case ARM::VLD3dWB_register_Asm_32:
6344 case ARM::VLD3qWB_register_Asm_8:
6345 case ARM::VLD3qWB_register_Asm_16:
6346 case ARM::VLD3qWB_register_Asm_32: {
6349 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6350 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6351 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6353 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6355 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6356 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6357 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6358 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6359 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6360 TmpInst.addOperand(Inst.getOperand(5));
6365 // VLD4DUP single 3-element structure to all lanes instructions.
6366 case ARM::VLD4DUPdAsm_8:
6367 case ARM::VLD4DUPdAsm_16:
6368 case ARM::VLD4DUPdAsm_32:
6369 case ARM::VLD4DUPqAsm_8:
6370 case ARM::VLD4DUPqAsm_16:
6371 case ARM::VLD4DUPqAsm_32: {
6374 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6375 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6376 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6378 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6380 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6382 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6383 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6384 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6385 TmpInst.addOperand(Inst.getOperand(4));
6390 case ARM::VLD4DUPdWB_fixed_Asm_8:
6391 case ARM::VLD4DUPdWB_fixed_Asm_16:
6392 case ARM::VLD4DUPdWB_fixed_Asm_32:
6393 case ARM::VLD4DUPqWB_fixed_Asm_8:
6394 case ARM::VLD4DUPqWB_fixed_Asm_16:
6395 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6398 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6399 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6406 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6407 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6408 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6409 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6410 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6411 TmpInst.addOperand(Inst.getOperand(4));
6416 case ARM::VLD4DUPdWB_register_Asm_8:
6417 case ARM::VLD4DUPdWB_register_Asm_16:
6418 case ARM::VLD4DUPdWB_register_Asm_32:
6419 case ARM::VLD4DUPqWB_register_Asm_8:
6420 case ARM::VLD4DUPqWB_register_Asm_16:
6421 case ARM::VLD4DUPqWB_register_Asm_32: {
6424 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6425 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6426 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6430 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6432 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6433 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6434 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6435 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6436 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6437 TmpInst.addOperand(Inst.getOperand(5));
6442 // VLD4 multiple 4-element structure instructions.
6443 case ARM::VLD4dAsm_8:
6444 case ARM::VLD4dAsm_16:
6445 case ARM::VLD4dAsm_32:
6446 case ARM::VLD4qAsm_8:
6447 case ARM::VLD4qAsm_16:
6448 case ARM::VLD4qAsm_32: {
6451 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6452 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6453 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6455 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6457 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6459 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6460 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6461 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6462 TmpInst.addOperand(Inst.getOperand(4));
6467 case ARM::VLD4dWB_fixed_Asm_8:
6468 case ARM::VLD4dWB_fixed_Asm_16:
6469 case ARM::VLD4dWB_fixed_Asm_32:
6470 case ARM::VLD4qWB_fixed_Asm_8:
6471 case ARM::VLD4qWB_fixed_Asm_16:
6472 case ARM::VLD4qWB_fixed_Asm_32: {
6475 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6476 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6477 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6481 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6483 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6484 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6485 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6486 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6487 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6488 TmpInst.addOperand(Inst.getOperand(4));
6493 case ARM::VLD4dWB_register_Asm_8:
6494 case ARM::VLD4dWB_register_Asm_16:
6495 case ARM::VLD4dWB_register_Asm_32:
6496 case ARM::VLD4qWB_register_Asm_8:
6497 case ARM::VLD4qWB_register_Asm_16:
6498 case ARM::VLD4qWB_register_Asm_32: {
6501 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6502 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6505 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6507 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6509 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6510 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6511 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6512 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6513 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6514 TmpInst.addOperand(Inst.getOperand(5));
6519 // VST3 multiple 3-element structure instructions.
6520 case ARM::VST3dAsm_8:
6521 case ARM::VST3dAsm_16:
6522 case ARM::VST3dAsm_32:
6523 case ARM::VST3qAsm_8:
6524 case ARM::VST3qAsm_16:
6525 case ARM::VST3qAsm_32: {
6528 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6529 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6530 TmpInst.addOperand(Inst.getOperand(2)); // alignment
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(3)); // CondCode
6537 TmpInst.addOperand(Inst.getOperand(4));
6542 case ARM::VST3dWB_fixed_Asm_8:
6543 case ARM::VST3dWB_fixed_Asm_16:
6544 case ARM::VST3dWB_fixed_Asm_32:
6545 case ARM::VST3qWB_fixed_Asm_8:
6546 case ARM::VST3qWB_fixed_Asm_16:
6547 case ARM::VST3qWB_fixed_Asm_32: {
6550 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6551 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6552 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6553 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6554 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6555 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6558 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6560 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6561 TmpInst.addOperand(Inst.getOperand(4));
6566 case ARM::VST3dWB_register_Asm_8:
6567 case ARM::VST3dWB_register_Asm_16:
6568 case ARM::VST3dWB_register_Asm_32:
6569 case ARM::VST3qWB_register_Asm_8:
6570 case ARM::VST3qWB_register_Asm_16:
6571 case ARM::VST3qWB_register_Asm_32: {
6574 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6575 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6576 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6577 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6578 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6579 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6582 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6584 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6585 TmpInst.addOperand(Inst.getOperand(5));
6590 // VST4 multiple 3-element structure instructions.
6591 case ARM::VST4dAsm_8:
6592 case ARM::VST4dAsm_16:
6593 case ARM::VST4dAsm_32:
6594 case ARM::VST4qAsm_8:
6595 case ARM::VST4qAsm_16:
6596 case ARM::VST4qAsm_32: {
6599 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6600 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6601 TmpInst.addOperand(Inst.getOperand(2)); // alignment
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(3)); // CondCode
6610 TmpInst.addOperand(Inst.getOperand(4));
6615 case ARM::VST4dWB_fixed_Asm_8:
6616 case ARM::VST4dWB_fixed_Asm_16:
6617 case ARM::VST4dWB_fixed_Asm_32:
6618 case ARM::VST4qWB_fixed_Asm_8:
6619 case ARM::VST4qWB_fixed_Asm_16:
6620 case ARM::VST4qWB_fixed_Asm_32: {
6623 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6624 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6625 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6626 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6627 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6628 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6629 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6631 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6635 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6636 TmpInst.addOperand(Inst.getOperand(4));
6641 case ARM::VST4dWB_register_Asm_8:
6642 case ARM::VST4dWB_register_Asm_16:
6643 case ARM::VST4dWB_register_Asm_32:
6644 case ARM::VST4qWB_register_Asm_8:
6645 case ARM::VST4qWB_register_Asm_16:
6646 case ARM::VST4qWB_register_Asm_32: {
6649 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6650 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6651 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6652 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6653 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6654 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6659 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6661 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6662 TmpInst.addOperand(Inst.getOperand(5));
6667 // Handle encoding choice for the shift-immediate instructions.
6670 case ARM::t2ASRri: {
6671 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6672 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6673 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6674 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6675 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6677 switch (Inst.getOpcode()) {
6678 default: llvm_unreachable("unexpected opcode");
6679 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6680 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6681 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6683 // The Thumb1 operands aren't in the same order. Awesome, eh?
6685 TmpInst.setOpcode(NewOpc);
6686 TmpInst.addOperand(Inst.getOperand(0));
6687 TmpInst.addOperand(Inst.getOperand(5));
6688 TmpInst.addOperand(Inst.getOperand(1));
6689 TmpInst.addOperand(Inst.getOperand(2));
6690 TmpInst.addOperand(Inst.getOperand(3));
6691 TmpInst.addOperand(Inst.getOperand(4));
6698 // Handle the Thumb2 mode MOV complex aliases.
6700 case ARM::t2MOVSsr: {
6701 // Which instruction to expand to depends on the CCOut operand and
6702 // whether we're in an IT block if the register operands are low
6704 bool isNarrow = false;
6705 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6706 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6707 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6708 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6709 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6713 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6714 default: llvm_unreachable("unexpected opcode!");
6715 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6716 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6717 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6718 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6720 TmpInst.setOpcode(newOpc);
6721 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6723 TmpInst.addOperand(MCOperand::CreateReg(
6724 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6725 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6726 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6727 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6728 TmpInst.addOperand(Inst.getOperand(5));
6730 TmpInst.addOperand(MCOperand::CreateReg(
6731 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6736 case ARM::t2MOVSsi: {
6737 // Which instruction to expand to depends on the CCOut operand and
6738 // whether we're in an IT block if the register operands are low
6740 bool isNarrow = false;
6741 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6742 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6743 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6747 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6748 default: llvm_unreachable("unexpected opcode!");
6749 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6750 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6751 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6752 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
6753 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
6755 unsigned Ammount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6756 if (Ammount == 32) Ammount = 0;
6757 TmpInst.setOpcode(newOpc);
6758 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6760 TmpInst.addOperand(MCOperand::CreateReg(
6761 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6762 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6763 if (newOpc != ARM::t2RRX)
6764 TmpInst.addOperand(MCOperand::CreateImm(Ammount));
6765 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6766 TmpInst.addOperand(Inst.getOperand(4));
6768 TmpInst.addOperand(MCOperand::CreateReg(
6769 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6773 // Handle the ARM mode MOV complex aliases.
6778 ARM_AM::ShiftOpc ShiftTy;
6779 switch(Inst.getOpcode()) {
6780 default: llvm_unreachable("unexpected opcode!");
6781 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6782 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6783 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6784 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6786 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6788 TmpInst.setOpcode(ARM::MOVsr);
6789 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6790 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6791 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6792 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6793 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6794 TmpInst.addOperand(Inst.getOperand(4));
6795 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6803 ARM_AM::ShiftOpc ShiftTy;
6804 switch(Inst.getOpcode()) {
6805 default: llvm_unreachable("unexpected opcode!");
6806 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6807 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6808 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6809 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6811 // A shift by zero is a plain MOVr, not a MOVsi.
6812 unsigned Amt = Inst.getOperand(2).getImm();
6813 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6814 // A shift by 32 should be encoded as 0 when permitted
6815 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6817 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
6819 TmpInst.setOpcode(Opc);
6820 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6821 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6822 if (Opc == ARM::MOVsi)
6823 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6824 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6825 TmpInst.addOperand(Inst.getOperand(4));
6826 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6831 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6833 TmpInst.setOpcode(ARM::MOVsi);
6834 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6835 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6836 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6837 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6838 TmpInst.addOperand(Inst.getOperand(3));
6839 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6843 case ARM::t2LDMIA_UPD: {
6844 // If this is a load of a single register, then we should use
6845 // a post-indexed LDR instruction instead, per the ARM ARM.
6846 if (Inst.getNumOperands() != 5)
6849 TmpInst.setOpcode(ARM::t2LDR_POST);
6850 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6851 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6852 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6853 TmpInst.addOperand(MCOperand::CreateImm(4));
6854 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6855 TmpInst.addOperand(Inst.getOperand(3));
6859 case ARM::t2STMDB_UPD: {
6860 // If this is a store of a single register, then we should use
6861 // a pre-indexed STR instruction instead, per the ARM ARM.
6862 if (Inst.getNumOperands() != 5)
6865 TmpInst.setOpcode(ARM::t2STR_PRE);
6866 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6867 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6868 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6869 TmpInst.addOperand(MCOperand::CreateImm(-4));
6870 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6871 TmpInst.addOperand(Inst.getOperand(3));
6875 case ARM::LDMIA_UPD:
6876 // If this is a load of a single register via a 'pop', then we should use
6877 // a post-indexed LDR instruction instead, per the ARM ARM.
6878 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6879 Inst.getNumOperands() == 5) {
6881 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6882 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6883 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6884 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6885 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6886 TmpInst.addOperand(MCOperand::CreateImm(4));
6887 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6888 TmpInst.addOperand(Inst.getOperand(3));
6893 case ARM::STMDB_UPD:
6894 // If this is a store of a single register via a 'push', then we should use
6895 // a pre-indexed STR instruction instead, per the ARM ARM.
6896 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6897 Inst.getNumOperands() == 5) {
6899 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6900 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6901 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6902 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6903 TmpInst.addOperand(MCOperand::CreateImm(-4));
6904 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6905 TmpInst.addOperand(Inst.getOperand(3));
6909 case ARM::t2ADDri12:
6910 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6911 // mnemonic was used (not "addw"), encoding T3 is preferred.
6912 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6913 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6915 Inst.setOpcode(ARM::t2ADDri);
6916 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6918 case ARM::t2SUBri12:
6919 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6920 // mnemonic was used (not "subw"), encoding T3 is preferred.
6921 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6922 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6924 Inst.setOpcode(ARM::t2SUBri);
6925 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6928 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6929 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6930 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6931 // to encoding T1 if <Rd> is omitted."
6932 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
6933 Inst.setOpcode(ARM::tADDi3);
6938 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6939 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6940 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6941 // to encoding T1 if <Rd> is omitted."
6942 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
6943 Inst.setOpcode(ARM::tSUBi3);
6948 case ARM::t2SUBri: {
6949 // If the destination and first source operand are the same, and
6950 // the flags are compatible with the current IT status, use encoding T2
6951 // instead of T3. For compatibility with the system 'as'. Make sure the
6952 // wide encoding wasn't explicit.
6953 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
6954 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
6955 (unsigned)Inst.getOperand(2).getImm() > 255 ||
6956 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
6957 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
6958 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6959 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
6962 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
6963 ARM::tADDi8 : ARM::tSUBi8);
6964 TmpInst.addOperand(Inst.getOperand(0));
6965 TmpInst.addOperand(Inst.getOperand(5));
6966 TmpInst.addOperand(Inst.getOperand(0));
6967 TmpInst.addOperand(Inst.getOperand(2));
6968 TmpInst.addOperand(Inst.getOperand(3));
6969 TmpInst.addOperand(Inst.getOperand(4));
6973 case ARM::t2ADDrr: {
6974 // If the destination and first source operand are the same, and
6975 // there's no setting of the flags, use encoding T2 instead of T3.
6976 // Note that this is only for ADD, not SUB. This mirrors the system
6977 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
6978 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
6979 Inst.getOperand(5).getReg() != 0 ||
6980 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6981 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
6984 TmpInst.setOpcode(ARM::tADDhirr);
6985 TmpInst.addOperand(Inst.getOperand(0));
6986 TmpInst.addOperand(Inst.getOperand(0));
6987 TmpInst.addOperand(Inst.getOperand(2));
6988 TmpInst.addOperand(Inst.getOperand(3));
6989 TmpInst.addOperand(Inst.getOperand(4));
6994 // A Thumb conditional branch outside of an IT block is a tBcc.
6995 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
6996 Inst.setOpcode(ARM::tBcc);
7001 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7002 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7003 Inst.setOpcode(ARM::t2Bcc);
7008 // If the conditional is AL or we're in an IT block, we really want t2B.
7009 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7010 Inst.setOpcode(ARM::t2B);
7015 // If the conditional is AL, we really want tB.
7016 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7017 Inst.setOpcode(ARM::tB);
7022 // If the register list contains any high registers, or if the writeback
7023 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7024 // instead if we're in Thumb2. Otherwise, this should have generated
7025 // an error in validateInstruction().
7026 unsigned Rn = Inst.getOperand(0).getReg();
7027 bool hasWritebackToken =
7028 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7029 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7030 bool listContainsBase;
7031 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7032 (!listContainsBase && !hasWritebackToken) ||
7033 (listContainsBase && hasWritebackToken)) {
7034 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7035 assert (isThumbTwo());
7036 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7037 // If we're switching to the updating version, we need to insert
7038 // the writeback tied operand.
7039 if (hasWritebackToken)
7040 Inst.insert(Inst.begin(),
7041 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7046 case ARM::tSTMIA_UPD: {
7047 // If the register list contains any high registers, we need to use
7048 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7049 // should have generated an error in validateInstruction().
7050 unsigned Rn = Inst.getOperand(0).getReg();
7051 bool listContainsBase;
7052 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7053 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7054 assert (isThumbTwo());
7055 Inst.setOpcode(ARM::t2STMIA_UPD);
7061 bool listContainsBase;
7062 // If the register list contains any high registers, we need to use
7063 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7064 // should have generated an error in validateInstruction().
7065 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7067 assert (isThumbTwo());
7068 Inst.setOpcode(ARM::t2LDMIA_UPD);
7069 // Add the base register and writeback operands.
7070 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7071 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7075 bool listContainsBase;
7076 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7078 assert (isThumbTwo());
7079 Inst.setOpcode(ARM::t2STMDB_UPD);
7080 // Add the base register and writeback operands.
7081 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7082 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7086 // If we can use the 16-bit encoding and the user didn't explicitly
7087 // request the 32-bit variant, transform it here.
7088 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7089 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7090 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7091 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7092 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7093 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7094 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7095 // The operands aren't in the same order for tMOVi8...
7097 TmpInst.setOpcode(ARM::tMOVi8);
7098 TmpInst.addOperand(Inst.getOperand(0));
7099 TmpInst.addOperand(Inst.getOperand(4));
7100 TmpInst.addOperand(Inst.getOperand(1));
7101 TmpInst.addOperand(Inst.getOperand(2));
7102 TmpInst.addOperand(Inst.getOperand(3));
7109 // If we can use the 16-bit encoding and the user didn't explicitly
7110 // request the 32-bit variant, transform it here.
7111 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7112 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7113 Inst.getOperand(2).getImm() == ARMCC::AL &&
7114 Inst.getOperand(4).getReg() == ARM::CPSR &&
7115 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7116 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7117 // The operands aren't the same for tMOV[S]r... (no cc_out)
7119 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7120 TmpInst.addOperand(Inst.getOperand(0));
7121 TmpInst.addOperand(Inst.getOperand(1));
7122 TmpInst.addOperand(Inst.getOperand(2));
7123 TmpInst.addOperand(Inst.getOperand(3));
7133 // If we can use the 16-bit encoding and the user didn't explicitly
7134 // request the 32-bit variant, transform it here.
7135 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7136 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7137 Inst.getOperand(2).getImm() == 0 &&
7138 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7139 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7141 switch (Inst.getOpcode()) {
7142 default: llvm_unreachable("Illegal opcode!");
7143 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7144 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7145 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7146 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7148 // The operands aren't the same for thumb1 (no rotate operand).
7150 TmpInst.setOpcode(NewOpc);
7151 TmpInst.addOperand(Inst.getOperand(0));
7152 TmpInst.addOperand(Inst.getOperand(1));
7153 TmpInst.addOperand(Inst.getOperand(3));
7154 TmpInst.addOperand(Inst.getOperand(4));
7161 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7162 // rrx shifts and asr/lsr of #32 is encoded as 0
7163 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7165 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7166 // Shifting by zero is accepted as a vanilla 'MOVr'
7168 TmpInst.setOpcode(ARM::MOVr);
7169 TmpInst.addOperand(Inst.getOperand(0));
7170 TmpInst.addOperand(Inst.getOperand(1));
7171 TmpInst.addOperand(Inst.getOperand(3));
7172 TmpInst.addOperand(Inst.getOperand(4));
7173 TmpInst.addOperand(Inst.getOperand(5));
7186 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7187 if (SOpc == ARM_AM::rrx) return false;
7188 switch (Inst.getOpcode()) {
7189 default: llvm_unreachable("unexpected opcode!");
7190 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7191 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7192 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7193 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7194 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7195 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7197 // If the shift is by zero, use the non-shifted instruction definition.
7198 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0) {
7200 TmpInst.setOpcode(newOpc);
7201 TmpInst.addOperand(Inst.getOperand(0));
7202 TmpInst.addOperand(Inst.getOperand(1));
7203 TmpInst.addOperand(Inst.getOperand(2));
7204 TmpInst.addOperand(Inst.getOperand(4));
7205 TmpInst.addOperand(Inst.getOperand(5));
7206 TmpInst.addOperand(Inst.getOperand(6));
7214 // The mask bits for all but the first condition are represented as
7215 // the low bit of the condition code value implies 't'. We currently
7216 // always have 1 implies 't', so XOR toggle the bits if the low bit
7217 // of the condition code is zero. The encoding also expects the low
7218 // bit of the condition to be encoded as bit 4 of the mask operand,
7219 // so mask that in if needed
7220 MCOperand &MO = Inst.getOperand(1);
7221 unsigned Mask = MO.getImm();
7222 unsigned OrigMask = Mask;
7223 unsigned TZ = CountTrailingZeros_32(Mask);
7224 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7225 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7226 for (unsigned i = 3; i != TZ; --i)
7232 // Set up the IT block state according to the IT instruction we just
7234 assert(!inITBlock() && "nested IT blocks?!");
7235 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7236 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7237 ITState.CurPosition = 0;
7238 ITState.FirstCond = true;
7245 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7246 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7247 // suffix depending on whether they're in an IT block or not.
7248 unsigned Opc = Inst.getOpcode();
7249 const MCInstrDesc &MCID = getInstDesc(Opc);
7250 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7251 assert(MCID.hasOptionalDef() &&
7252 "optionally flag setting instruction missing optional def operand");
7253 assert(MCID.NumOperands == Inst.getNumOperands() &&
7254 "operand count mismatch!");
7255 // Find the optional-def operand (cc_out).
7258 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7261 // If we're parsing Thumb1, reject it completely.
7262 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7263 return Match_MnemonicFail;
7264 // If we're parsing Thumb2, which form is legal depends on whether we're
7266 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7268 return Match_RequiresITBlock;
7269 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7271 return Match_RequiresNotITBlock;
7273 // Some high-register supporting Thumb1 encodings only allow both registers
7274 // to be from r0-r7 when in Thumb2.
7275 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7276 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7277 isARMLowRegister(Inst.getOperand(2).getReg()))
7278 return Match_RequiresThumb2;
7279 // Others only require ARMv6 or later.
7280 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7281 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7282 isARMLowRegister(Inst.getOperand(1).getReg()))
7283 return Match_RequiresV6;
7284 return Match_Success;
7287 static const char *getSubtargetFeatureName(unsigned Val);
7289 MatchAndEmitInstruction(SMLoc IDLoc,
7290 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7294 unsigned MatchResult;
7295 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
7296 switch (MatchResult) {
7299 // Context sensitive operand constraints aren't handled by the matcher,
7300 // so check them here.
7301 if (validateInstruction(Inst, Operands)) {
7302 // Still progress the IT block, otherwise one wrong condition causes
7303 // nasty cascading errors.
7304 forwardITPosition();
7308 // Some instructions need post-processing to, for example, tweak which
7309 // encoding is selected. Loop on it while changes happen so the
7310 // individual transformations can chain off each other. E.g.,
7311 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7312 while (processInstruction(Inst, Operands))
7315 // Only move forward at the very end so that everything in validate
7316 // and process gets a consistent answer about whether we're in an IT
7318 forwardITPosition();
7320 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7321 // doesn't actually encode.
7322 if (Inst.getOpcode() == ARM::ITasm)
7326 Out.EmitInstruction(Inst);
7328 case Match_MissingFeature: {
7329 assert(ErrorInfo && "Unknown missing feature!");
7330 // Special case the error message for the very common case where only
7331 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7332 std::string Msg = "instruction requires:";
7334 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7335 if (ErrorInfo & Mask) {
7337 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7341 return Error(IDLoc, Msg);
7343 case Match_InvalidOperand: {
7344 SMLoc ErrorLoc = IDLoc;
7345 if (ErrorInfo != ~0U) {
7346 if (ErrorInfo >= Operands.size())
7347 return Error(IDLoc, "too few operands for instruction");
7349 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7350 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7353 return Error(ErrorLoc, "invalid operand for instruction");
7355 case Match_MnemonicFail:
7356 return Error(IDLoc, "invalid instruction",
7357 ((ARMOperand*)Operands[0])->getLocRange());
7358 case Match_ConversionFail:
7359 // The converter function will have already emited a diagnostic.
7361 case Match_RequiresNotITBlock:
7362 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7363 case Match_RequiresITBlock:
7364 return Error(IDLoc, "instruction only valid inside IT block");
7365 case Match_RequiresV6:
7366 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7367 case Match_RequiresThumb2:
7368 return Error(IDLoc, "instruction variant requires Thumb2");
7371 llvm_unreachable("Implement any new match types added!");
7374 /// parseDirective parses the arm specific directives
7375 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7376 StringRef IDVal = DirectiveID.getIdentifier();
7377 if (IDVal == ".word")
7378 return parseDirectiveWord(4, DirectiveID.getLoc());
7379 else if (IDVal == ".thumb")
7380 return parseDirectiveThumb(DirectiveID.getLoc());
7381 else if (IDVal == ".arm")
7382 return parseDirectiveARM(DirectiveID.getLoc());
7383 else if (IDVal == ".thumb_func")
7384 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7385 else if (IDVal == ".code")
7386 return parseDirectiveCode(DirectiveID.getLoc());
7387 else if (IDVal == ".syntax")
7388 return parseDirectiveSyntax(DirectiveID.getLoc());
7389 else if (IDVal == ".unreq")
7390 return parseDirectiveUnreq(DirectiveID.getLoc());
7391 else if (IDVal == ".arch")
7392 return parseDirectiveArch(DirectiveID.getLoc());
7393 else if (IDVal == ".eabi_attribute")
7394 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7398 /// parseDirectiveWord
7399 /// ::= .word [ expression (, expression)* ]
7400 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7401 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7403 const MCExpr *Value;
7404 if (getParser().ParseExpression(Value))
7407 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
7409 if (getLexer().is(AsmToken::EndOfStatement))
7412 // FIXME: Improve diagnostic.
7413 if (getLexer().isNot(AsmToken::Comma))
7414 return Error(L, "unexpected token in directive");
7423 /// parseDirectiveThumb
7425 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7426 if (getLexer().isNot(AsmToken::EndOfStatement))
7427 return Error(L, "unexpected token in directive");
7432 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7436 /// parseDirectiveARM
7438 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7439 if (getLexer().isNot(AsmToken::EndOfStatement))
7440 return Error(L, "unexpected token in directive");
7445 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7449 /// parseDirectiveThumbFunc
7450 /// ::= .thumbfunc symbol_name
7451 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7452 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7453 bool isMachO = MAI.hasSubsectionsViaSymbols();
7455 bool needFuncName = true;
7457 // Darwin asm has (optionally) function name after .thumb_func direction
7460 const AsmToken &Tok = Parser.getTok();
7461 if (Tok.isNot(AsmToken::EndOfStatement)) {
7462 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7463 return Error(L, "unexpected token in .thumb_func directive");
7464 Name = Tok.getIdentifier();
7465 Parser.Lex(); // Consume the identifier token.
7466 needFuncName = false;
7470 if (getLexer().isNot(AsmToken::EndOfStatement))
7471 return Error(L, "unexpected token in directive");
7473 // Eat the end of statement and any blank lines that follow.
7474 while (getLexer().is(AsmToken::EndOfStatement))
7477 // FIXME: assuming function name will be the line following .thumb_func
7478 // We really should be checking the next symbol definition even if there's
7479 // stuff in between.
7481 Name = Parser.getTok().getIdentifier();
7484 // Mark symbol as a thumb symbol.
7485 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7486 getParser().getStreamer().EmitThumbFunc(Func);
7490 /// parseDirectiveSyntax
7491 /// ::= .syntax unified | divided
7492 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7493 const AsmToken &Tok = Parser.getTok();
7494 if (Tok.isNot(AsmToken::Identifier))
7495 return Error(L, "unexpected token in .syntax directive");
7496 StringRef Mode = Tok.getString();
7497 if (Mode == "unified" || Mode == "UNIFIED")
7499 else if (Mode == "divided" || Mode == "DIVIDED")
7500 return Error(L, "'.syntax divided' arm asssembly not supported");
7502 return Error(L, "unrecognized syntax mode in .syntax directive");
7504 if (getLexer().isNot(AsmToken::EndOfStatement))
7505 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7508 // TODO tell the MC streamer the mode
7509 // getParser().getStreamer().Emit???();
7513 /// parseDirectiveCode
7514 /// ::= .code 16 | 32
7515 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7516 const AsmToken &Tok = Parser.getTok();
7517 if (Tok.isNot(AsmToken::Integer))
7518 return Error(L, "unexpected token in .code directive");
7519 int64_t Val = Parser.getTok().getIntVal();
7525 return Error(L, "invalid operand to .code directive");
7527 if (getLexer().isNot(AsmToken::EndOfStatement))
7528 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7534 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7538 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7544 /// parseDirectiveReq
7545 /// ::= name .req registername
7546 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7547 Parser.Lex(); // Eat the '.req' token.
7549 SMLoc SRegLoc, ERegLoc;
7550 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7551 Parser.EatToEndOfStatement();
7552 return Error(SRegLoc, "register name expected");
7555 // Shouldn't be anything else.
7556 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7557 Parser.EatToEndOfStatement();
7558 return Error(Parser.getTok().getLoc(),
7559 "unexpected input in .req directive.");
7562 Parser.Lex(); // Consume the EndOfStatement
7564 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7565 return Error(SRegLoc, "redefinition of '" + Name +
7566 "' does not match original.");
7571 /// parseDirectiveUneq
7572 /// ::= .unreq registername
7573 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7574 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7575 Parser.EatToEndOfStatement();
7576 return Error(L, "unexpected input in .unreq directive.");
7578 RegisterReqs.erase(Parser.getTok().getIdentifier());
7579 Parser.Lex(); // Eat the identifier.
7583 /// parseDirectiveArch
7585 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7589 /// parseDirectiveEabiAttr
7590 /// ::= .eabi_attribute int, int
7591 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7595 extern "C" void LLVMInitializeARMAsmLexer();
7597 /// Force static initialization.
7598 extern "C" void LLVMInitializeARMAsmParser() {
7599 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7600 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
7601 LLVMInitializeARMAsmLexer();
7604 #define GET_REGISTER_MATCHER
7605 #define GET_SUBTARGET_FEATURE_NAME
7606 #define GET_MATCHER_IMPLEMENTATION
7607 #include "ARMGenAsmMatcher.inc"