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 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
86 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
88 int tryParseRegister();
89 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
90 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
91 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
92 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
93 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
94 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
95 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
96 unsigned &ShiftAmount);
97 bool parseDirectiveWord(unsigned Size, SMLoc L);
98 bool parseDirectiveThumb(SMLoc L);
99 bool parseDirectiveARM(SMLoc L);
100 bool parseDirectiveThumbFunc(SMLoc L);
101 bool parseDirectiveCode(SMLoc L);
102 bool parseDirectiveSyntax(SMLoc L);
103 bool parseDirectiveReq(StringRef Name, SMLoc L);
104 bool parseDirectiveUnreq(SMLoc L);
105 bool parseDirectiveArch(SMLoc L);
106 bool parseDirectiveEabiAttr(SMLoc L);
108 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
109 bool &CarrySetting, unsigned &ProcessorIMod,
111 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
112 bool &CanAcceptPredicationCode);
114 bool isThumb() const {
115 // FIXME: Can tablegen auto-generate this?
116 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
118 bool isThumbOne() const {
119 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
121 bool isThumbTwo() const {
122 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
124 bool hasV6Ops() const {
125 return STI.getFeatureBits() & ARM::HasV6Ops;
127 bool hasV7Ops() const {
128 return STI.getFeatureBits() & ARM::HasV7Ops;
131 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
132 setAvailableFeatures(FB);
134 bool isMClass() const {
135 return STI.getFeatureBits() & ARM::FeatureMClass;
138 /// @name Auto-generated Match Functions
141 #define GET_ASSEMBLER_HEADER
142 #include "ARMGenAsmMatcher.inc"
146 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
147 OperandMatchResultTy parseCoprocNumOperand(
148 SmallVectorImpl<MCParsedAsmOperand*>&);
149 OperandMatchResultTy parseCoprocRegOperand(
150 SmallVectorImpl<MCParsedAsmOperand*>&);
151 OperandMatchResultTy parseCoprocOptionOperand(
152 SmallVectorImpl<MCParsedAsmOperand*>&);
153 OperandMatchResultTy parseMemBarrierOptOperand(
154 SmallVectorImpl<MCParsedAsmOperand*>&);
155 OperandMatchResultTy parseProcIFlagsOperand(
156 SmallVectorImpl<MCParsedAsmOperand*>&);
157 OperandMatchResultTy parseMSRMaskOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
159 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
160 StringRef Op, int Low, int High);
161 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
162 return parsePKHImm(O, "lsl", 0, 31);
164 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
165 return parsePKHImm(O, "asr", 1, 32);
167 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
168 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
169 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
170 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
171 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
172 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
173 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
174 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
175 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
177 // Asm Match Converter Methods
178 bool cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
179 const SmallVectorImpl<MCParsedAsmOperand*> &);
180 bool cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
181 const SmallVectorImpl<MCParsedAsmOperand*> &);
182 bool cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
183 const SmallVectorImpl<MCParsedAsmOperand*> &);
184 bool cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
185 const SmallVectorImpl<MCParsedAsmOperand*> &);
186 bool cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
187 const SmallVectorImpl<MCParsedAsmOperand*> &);
188 bool cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
189 const SmallVectorImpl<MCParsedAsmOperand*> &);
190 bool cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
191 const SmallVectorImpl<MCParsedAsmOperand*> &);
192 bool cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
193 const SmallVectorImpl<MCParsedAsmOperand*> &);
194 bool cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
195 const SmallVectorImpl<MCParsedAsmOperand*> &);
196 bool cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
197 const SmallVectorImpl<MCParsedAsmOperand*> &);
198 bool cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
199 const SmallVectorImpl<MCParsedAsmOperand*> &);
200 bool cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
201 const SmallVectorImpl<MCParsedAsmOperand*> &);
202 bool cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
203 const SmallVectorImpl<MCParsedAsmOperand*> &);
204 bool cvtLdrdPre(MCInst &Inst, unsigned Opcode,
205 const SmallVectorImpl<MCParsedAsmOperand*> &);
206 bool cvtStrdPre(MCInst &Inst, unsigned Opcode,
207 const SmallVectorImpl<MCParsedAsmOperand*> &);
208 bool cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
209 const SmallVectorImpl<MCParsedAsmOperand*> &);
210 bool cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
211 const SmallVectorImpl<MCParsedAsmOperand*> &);
212 bool cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
213 const SmallVectorImpl<MCParsedAsmOperand*> &);
214 bool cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
215 const SmallVectorImpl<MCParsedAsmOperand*> &);
216 bool cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
217 const SmallVectorImpl<MCParsedAsmOperand*> &);
218 bool cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
219 const SmallVectorImpl<MCParsedAsmOperand*> &);
221 bool validateInstruction(MCInst &Inst,
222 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
223 bool processInstruction(MCInst &Inst,
224 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
225 bool shouldOmitCCOutOperand(StringRef Mnemonic,
226 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
229 enum ARMMatchResultTy {
230 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
231 Match_RequiresNotITBlock,
236 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
237 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
238 MCAsmParserExtension::Initialize(_Parser);
240 // Cache the MCRegisterInfo.
241 MRI = &getContext().getRegisterInfo();
243 // Initialize the set of available features.
244 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
246 // Not in an ITBlock to start with.
247 ITState.CurPosition = ~0U;
250 // Implementation of the MCTargetAsmParser interface:
251 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
252 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
253 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
254 bool ParseDirective(AsmToken DirectiveID);
256 unsigned checkTargetMatchPredicate(MCInst &Inst);
258 bool MatchAndEmitInstruction(SMLoc IDLoc,
259 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
262 } // end anonymous namespace
266 /// ARMOperand - Instances of this class represent a parsed ARM machine
268 class ARMOperand : public MCParsedAsmOperand {
288 k_VectorListAllLanes,
294 k_BitfieldDescriptor,
298 SMLoc StartLoc, EndLoc;
299 SmallVector<unsigned, 8> Registers;
303 ARMCC::CondCodes Val;
323 ARM_PROC::IFlags Val;
339 // A vector register list is a sequential list of 1 to 4 registers.
355 /// Combined record for all forms of ARM address expressions.
358 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
360 const MCConstantExpr *OffsetImm; // Offset immediate value
361 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
362 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
363 unsigned ShiftImm; // shift for OffsetReg.
364 unsigned Alignment; // 0 = no alignment specified
365 // n = alignment in bytes (2, 4, 8, 16, or 32)
366 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
372 ARM_AM::ShiftOpc ShiftTy;
381 ARM_AM::ShiftOpc ShiftTy;
387 ARM_AM::ShiftOpc ShiftTy;
400 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
402 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
404 StartLoc = o.StartLoc;
421 case k_DPRRegisterList:
422 case k_SPRRegisterList:
423 Registers = o.Registers;
426 case k_VectorListAllLanes:
427 case k_VectorListIndexed:
428 VectorList = o.VectorList;
435 CoprocOption = o.CoprocOption;
440 case k_MemBarrierOpt:
446 case k_PostIndexRegister:
447 PostIdxReg = o.PostIdxReg;
455 case k_ShifterImmediate:
456 ShifterImm = o.ShifterImm;
458 case k_ShiftedRegister:
459 RegShiftedReg = o.RegShiftedReg;
461 case k_ShiftedImmediate:
462 RegShiftedImm = o.RegShiftedImm;
464 case k_RotateImmediate:
467 case k_BitfieldDescriptor:
468 Bitfield = o.Bitfield;
471 VectorIndex = o.VectorIndex;
476 /// getStartLoc - Get the location of the first token of this operand.
477 SMLoc getStartLoc() const { return StartLoc; }
478 /// getEndLoc - Get the location of the last token of this operand.
479 SMLoc getEndLoc() const { return EndLoc; }
481 ARMCC::CondCodes getCondCode() const {
482 assert(Kind == k_CondCode && "Invalid access!");
486 unsigned getCoproc() const {
487 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
491 StringRef getToken() const {
492 assert(Kind == k_Token && "Invalid access!");
493 return StringRef(Tok.Data, Tok.Length);
496 unsigned getReg() const {
497 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
501 const SmallVectorImpl<unsigned> &getRegList() const {
502 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
503 Kind == k_SPRRegisterList) && "Invalid access!");
507 const MCExpr *getImm() const {
508 assert(isImm() && "Invalid access!");
512 unsigned getVectorIndex() const {
513 assert(Kind == k_VectorIndex && "Invalid access!");
514 return VectorIndex.Val;
517 ARM_MB::MemBOpt getMemBarrierOpt() const {
518 assert(Kind == k_MemBarrierOpt && "Invalid access!");
522 ARM_PROC::IFlags getProcIFlags() const {
523 assert(Kind == k_ProcIFlags && "Invalid access!");
527 unsigned getMSRMask() const {
528 assert(Kind == k_MSRMask && "Invalid access!");
532 bool isCoprocNum() const { return Kind == k_CoprocNum; }
533 bool isCoprocReg() const { return Kind == k_CoprocReg; }
534 bool isCoprocOption() const { return Kind == k_CoprocOption; }
535 bool isCondCode() const { return Kind == k_CondCode; }
536 bool isCCOut() const { return Kind == k_CCOut; }
537 bool isITMask() const { return Kind == k_ITCondMask; }
538 bool isITCondCode() const { return Kind == k_CondCode; }
539 bool isImm() const { return Kind == k_Immediate; }
540 bool isFPImm() const {
541 if (!isImm()) return false;
542 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
543 if (!CE) return false;
544 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
547 bool isFBits16() const {
548 if (!isImm()) return false;
549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
550 if (!CE) return false;
551 int64_t Value = CE->getValue();
552 return Value >= 0 && Value <= 16;
554 bool isFBits32() const {
555 if (!isImm()) return false;
556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
557 if (!CE) return false;
558 int64_t Value = CE->getValue();
559 return Value >= 1 && Value <= 32;
561 bool isImm8s4() const {
562 if (!isImm()) return false;
563 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
564 if (!CE) return false;
565 int64_t Value = CE->getValue();
566 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
568 bool isImm0_1020s4() const {
569 if (!isImm()) return false;
570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
571 if (!CE) return false;
572 int64_t Value = CE->getValue();
573 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
575 bool isImm0_508s4() const {
576 if (!isImm()) return false;
577 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
578 if (!CE) return false;
579 int64_t Value = CE->getValue();
580 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
582 bool isImm0_255() const {
583 if (!isImm()) return false;
584 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
585 if (!CE) return false;
586 int64_t Value = CE->getValue();
587 return Value >= 0 && Value < 256;
589 bool isImm0_1() const {
590 if (!isImm()) return false;
591 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
592 if (!CE) return false;
593 int64_t Value = CE->getValue();
594 return Value >= 0 && Value < 2;
596 bool isImm0_3() const {
597 if (!isImm()) return false;
598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
599 if (!CE) return false;
600 int64_t Value = CE->getValue();
601 return Value >= 0 && Value < 4;
603 bool isImm0_7() const {
604 if (!isImm()) return false;
605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
606 if (!CE) return false;
607 int64_t Value = CE->getValue();
608 return Value >= 0 && Value < 8;
610 bool isImm0_15() const {
611 if (!isImm()) return false;
612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
613 if (!CE) return false;
614 int64_t Value = CE->getValue();
615 return Value >= 0 && Value < 16;
617 bool isImm0_31() const {
618 if (!isImm()) return false;
619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
620 if (!CE) return false;
621 int64_t Value = CE->getValue();
622 return Value >= 0 && Value < 32;
624 bool isImm0_63() const {
625 if (!isImm()) return false;
626 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
627 if (!CE) return false;
628 int64_t Value = CE->getValue();
629 return Value >= 0 && Value < 64;
631 bool isImm8() const {
632 if (!isImm()) return false;
633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
634 if (!CE) return false;
635 int64_t Value = CE->getValue();
638 bool isImm16() const {
639 if (!isImm()) return false;
640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
641 if (!CE) return false;
642 int64_t Value = CE->getValue();
645 bool isImm32() const {
646 if (!isImm()) return false;
647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
648 if (!CE) return false;
649 int64_t Value = CE->getValue();
652 bool isShrImm8() const {
653 if (!isImm()) return false;
654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
655 if (!CE) return false;
656 int64_t Value = CE->getValue();
657 return Value > 0 && Value <= 8;
659 bool isShrImm16() const {
660 if (!isImm()) return false;
661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
662 if (!CE) return false;
663 int64_t Value = CE->getValue();
664 return Value > 0 && Value <= 16;
666 bool isShrImm32() const {
667 if (!isImm()) return false;
668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
669 if (!CE) return false;
670 int64_t Value = CE->getValue();
671 return Value > 0 && Value <= 32;
673 bool isShrImm64() const {
674 if (!isImm()) return false;
675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
676 if (!CE) return false;
677 int64_t Value = CE->getValue();
678 return Value > 0 && Value <= 64;
680 bool isImm1_7() const {
681 if (!isImm()) return false;
682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
683 if (!CE) return false;
684 int64_t Value = CE->getValue();
685 return Value > 0 && Value < 8;
687 bool isImm1_15() const {
688 if (!isImm()) return false;
689 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
690 if (!CE) return false;
691 int64_t Value = CE->getValue();
692 return Value > 0 && Value < 16;
694 bool isImm1_31() const {
695 if (!isImm()) return false;
696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
697 if (!CE) return false;
698 int64_t Value = CE->getValue();
699 return Value > 0 && Value < 32;
701 bool isImm1_16() const {
702 if (!isImm()) return false;
703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
704 if (!CE) return false;
705 int64_t Value = CE->getValue();
706 return Value > 0 && Value < 17;
708 bool isImm1_32() const {
709 if (!isImm()) return false;
710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
711 if (!CE) return false;
712 int64_t Value = CE->getValue();
713 return Value > 0 && Value < 33;
715 bool isImm0_32() const {
716 if (!isImm()) return false;
717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
718 if (!CE) return false;
719 int64_t Value = CE->getValue();
720 return Value >= 0 && Value < 33;
722 bool isImm0_65535() const {
723 if (!isImm()) return false;
724 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
725 if (!CE) return false;
726 int64_t Value = CE->getValue();
727 return Value >= 0 && Value < 65536;
729 bool isImm0_65535Expr() const {
730 if (!isImm()) return false;
731 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
732 // If it's not a constant expression, it'll generate a fixup and be
734 if (!CE) return true;
735 int64_t Value = CE->getValue();
736 return Value >= 0 && Value < 65536;
738 bool isImm24bit() 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 <= 0xffffff;
745 bool isImmThumbSR() 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 isPKHLSLImm() 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 < 32;
759 bool isPKHASRImm() const {
760 if (!isImm()) return false;
761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
762 if (!CE) return false;
763 int64_t Value = CE->getValue();
764 return Value > 0 && Value <= 32;
766 bool isARMSOImm() const {
767 if (!isImm()) return false;
768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
769 if (!CE) return false;
770 int64_t Value = CE->getValue();
771 return ARM_AM::getSOImmVal(Value) != -1;
773 bool isARMSOImmNot() const {
774 if (!isImm()) return false;
775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 if (!CE) return false;
777 int64_t Value = CE->getValue();
778 return ARM_AM::getSOImmVal(~Value) != -1;
780 bool isARMSOImmNeg() const {
781 if (!isImm()) return false;
782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
783 if (!CE) return false;
784 int64_t Value = CE->getValue();
785 return ARM_AM::getSOImmVal(-Value) != -1;
787 bool isT2SOImm() const {
788 if (!isImm()) return false;
789 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
790 if (!CE) return false;
791 int64_t Value = CE->getValue();
792 return ARM_AM::getT2SOImmVal(Value) != -1;
794 bool isT2SOImmNot() const {
795 if (!isImm()) return false;
796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
797 if (!CE) return false;
798 int64_t Value = CE->getValue();
799 return ARM_AM::getT2SOImmVal(~Value) != -1;
801 bool isT2SOImmNeg() const {
802 if (!isImm()) return false;
803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return ARM_AM::getT2SOImmVal(-Value) != -1;
808 bool isSetEndImm() const {
809 if (!isImm()) return false;
810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return Value == 1 || Value == 0;
815 bool isReg() const { return Kind == k_Register; }
816 bool isRegList() const { return Kind == k_RegisterList; }
817 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
818 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
819 bool isToken() const { return Kind == k_Token; }
820 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
821 bool isMemory() const { return Kind == k_Memory; }
822 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
823 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
824 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
825 bool isRotImm() const { return Kind == k_RotateImmediate; }
826 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
827 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
828 bool isPostIdxReg() const {
829 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
831 bool isMemNoOffset(bool alignOK = false) const {
834 // No offset of any kind.
835 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
836 (alignOK || Memory.Alignment == 0);
838 bool isMemPCRelImm12() const {
839 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
841 // Base register must be PC.
842 if (Memory.BaseRegNum != ARM::PC)
844 // Immediate offset in range [-4095, 4095].
845 if (!Memory.OffsetImm) return true;
846 int64_t Val = Memory.OffsetImm->getValue();
847 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
849 bool isAlignedMemory() const {
850 return isMemNoOffset(true);
852 bool isAddrMode2() const {
853 if (!isMemory() || Memory.Alignment != 0) return false;
854 // Check for register offset.
855 if (Memory.OffsetRegNum) return true;
856 // Immediate offset in range [-4095, 4095].
857 if (!Memory.OffsetImm) return true;
858 int64_t Val = Memory.OffsetImm->getValue();
859 return Val > -4096 && Val < 4096;
861 bool isAM2OffsetImm() const {
862 if (!isImm()) return false;
863 // Immediate offset in range [-4095, 4095].
864 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
865 if (!CE) return false;
866 int64_t Val = CE->getValue();
867 return Val > -4096 && Val < 4096;
869 bool isAddrMode3() const {
870 // If we have an immediate that's not a constant, treat it as a label
871 // reference needing a fixup. If it is a constant, it's something else
873 if (isImm() && !isa<MCConstantExpr>(getImm()))
875 if (!isMemory() || Memory.Alignment != 0) return false;
876 // No shifts are legal for AM3.
877 if (Memory.ShiftType != ARM_AM::no_shift) return false;
878 // Check for register offset.
879 if (Memory.OffsetRegNum) return true;
880 // Immediate offset in range [-255, 255].
881 if (!Memory.OffsetImm) return true;
882 int64_t Val = Memory.OffsetImm->getValue();
883 return Val > -256 && Val < 256;
885 bool isAM3Offset() const {
886 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
888 if (Kind == k_PostIndexRegister)
889 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
890 // Immediate offset in range [-255, 255].
891 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
892 if (!CE) return false;
893 int64_t Val = CE->getValue();
894 // Special case, #-0 is INT32_MIN.
895 return (Val > -256 && Val < 256) || Val == INT32_MIN;
897 bool isAddrMode5() const {
898 // If we have an immediate that's not a constant, treat it as a label
899 // reference needing a fixup. If it is a constant, it's something else
901 if (isImm() && !isa<MCConstantExpr>(getImm()))
903 if (!isMemory() || Memory.Alignment != 0) return false;
904 // Check for register offset.
905 if (Memory.OffsetRegNum) return false;
906 // Immediate offset in range [-1020, 1020] and a multiple of 4.
907 if (!Memory.OffsetImm) return true;
908 int64_t Val = Memory.OffsetImm->getValue();
909 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
912 bool isMemTBB() const {
913 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
914 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
918 bool isMemTBH() const {
919 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
920 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
921 Memory.Alignment != 0 )
925 bool isMemRegOffset() const {
926 if (!isMemory() || !Memory.OffsetRegNum || Memory.Alignment != 0)
930 bool isT2MemRegOffset() const {
931 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
932 Memory.Alignment != 0)
934 // Only lsl #{0, 1, 2, 3} allowed.
935 if (Memory.ShiftType == ARM_AM::no_shift)
937 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
941 bool isMemThumbRR() const {
942 // Thumb reg+reg addressing is simple. Just two registers, a base and
943 // an offset. No shifts, negations or any other complicating factors.
944 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
945 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
947 return isARMLowRegister(Memory.BaseRegNum) &&
948 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
950 bool isMemThumbRIs4() const {
951 if (!isMemory() || Memory.OffsetRegNum != 0 ||
952 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
954 // Immediate offset, multiple of 4 in range [0, 124].
955 if (!Memory.OffsetImm) return true;
956 int64_t Val = Memory.OffsetImm->getValue();
957 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
959 bool isMemThumbRIs2() const {
960 if (!isMemory() || Memory.OffsetRegNum != 0 ||
961 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
963 // Immediate offset, multiple of 4 in range [0, 62].
964 if (!Memory.OffsetImm) return true;
965 int64_t Val = Memory.OffsetImm->getValue();
966 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
968 bool isMemThumbRIs1() const {
969 if (!isMemory() || Memory.OffsetRegNum != 0 ||
970 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
972 // Immediate offset in range [0, 31].
973 if (!Memory.OffsetImm) return true;
974 int64_t Val = Memory.OffsetImm->getValue();
975 return Val >= 0 && Val <= 31;
977 bool isMemThumbSPI() const {
978 if (!isMemory() || Memory.OffsetRegNum != 0 ||
979 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
981 // Immediate offset, multiple of 4 in range [0, 1020].
982 if (!Memory.OffsetImm) return true;
983 int64_t Val = Memory.OffsetImm->getValue();
984 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
986 bool isMemImm8s4Offset() const {
987 // If we have an immediate that's not a constant, treat it as a label
988 // reference needing a fixup. If it is a constant, it's something else
990 if (isImm() && !isa<MCConstantExpr>(getImm()))
992 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
994 // Immediate offset a multiple of 4 in range [-1020, 1020].
995 if (!Memory.OffsetImm) return true;
996 int64_t Val = Memory.OffsetImm->getValue();
997 return Val >= -1020 && Val <= 1020 && (Val & 3) == 0;
999 bool isMemImm0_1020s4Offset() const {
1000 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1002 // Immediate offset a multiple of 4 in range [0, 1020].
1003 if (!Memory.OffsetImm) return true;
1004 int64_t Val = Memory.OffsetImm->getValue();
1005 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1007 bool isMemImm8Offset() const {
1008 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1010 // Base reg of PC isn't allowed for these encodings.
1011 if (Memory.BaseRegNum == ARM::PC) return false;
1012 // Immediate offset in range [-255, 255].
1013 if (!Memory.OffsetImm) return true;
1014 int64_t Val = Memory.OffsetImm->getValue();
1015 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1017 bool isMemPosImm8Offset() const {
1018 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1020 // Immediate offset in range [0, 255].
1021 if (!Memory.OffsetImm) return true;
1022 int64_t Val = Memory.OffsetImm->getValue();
1023 return Val >= 0 && Val < 256;
1025 bool isMemNegImm8Offset() const {
1026 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1028 // Base reg of PC isn't allowed for these encodings.
1029 if (Memory.BaseRegNum == ARM::PC) return false;
1030 // Immediate offset in range [-255, -1].
1031 if (!Memory.OffsetImm) return false;
1032 int64_t Val = Memory.OffsetImm->getValue();
1033 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1035 bool isMemUImm12Offset() const {
1036 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1038 // Immediate offset in range [0, 4095].
1039 if (!Memory.OffsetImm) return true;
1040 int64_t Val = Memory.OffsetImm->getValue();
1041 return (Val >= 0 && Val < 4096);
1043 bool isMemImm12Offset() const {
1044 // If we have an immediate that's not a constant, treat it as a label
1045 // reference needing a fixup. If it is a constant, it's something else
1046 // and we reject it.
1047 if (isImm() && !isa<MCConstantExpr>(getImm()))
1050 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1052 // Immediate offset in range [-4095, 4095].
1053 if (!Memory.OffsetImm) return true;
1054 int64_t Val = Memory.OffsetImm->getValue();
1055 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1057 bool isPostIdxImm8() const {
1058 if (!isImm()) return false;
1059 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1060 if (!CE) return false;
1061 int64_t Val = CE->getValue();
1062 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1064 bool isPostIdxImm8s4() const {
1065 if (!isImm()) return false;
1066 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1067 if (!CE) return false;
1068 int64_t Val = CE->getValue();
1069 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1073 bool isMSRMask() const { return Kind == k_MSRMask; }
1074 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1077 bool isSingleSpacedVectorList() const {
1078 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1080 bool isDoubleSpacedVectorList() const {
1081 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1083 bool isVecListOneD() const {
1084 if (!isSingleSpacedVectorList()) return false;
1085 return VectorList.Count == 1;
1088 bool isVecListDPair() const {
1089 if (!isSingleSpacedVectorList()) return false;
1090 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1091 .contains(VectorList.RegNum));
1094 bool isVecListThreeD() const {
1095 if (!isSingleSpacedVectorList()) return false;
1096 return VectorList.Count == 3;
1099 bool isVecListFourD() const {
1100 if (!isSingleSpacedVectorList()) return false;
1101 return VectorList.Count == 4;
1104 bool isVecListTwoQ() const {
1105 if (!isDoubleSpacedVectorList()) return false;
1106 return VectorList.Count == 2;
1109 bool isVecListThreeQ() const {
1110 if (!isDoubleSpacedVectorList()) return false;
1111 return VectorList.Count == 3;
1114 bool isVecListFourQ() const {
1115 if (!isDoubleSpacedVectorList()) return false;
1116 return VectorList.Count == 4;
1119 bool isSingleSpacedVectorAllLanes() const {
1120 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1122 bool isDoubleSpacedVectorAllLanes() const {
1123 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1125 bool isVecListOneDAllLanes() const {
1126 if (!isSingleSpacedVectorAllLanes()) return false;
1127 return VectorList.Count == 1;
1130 bool isVecListTwoDAllLanes() const {
1131 if (!isSingleSpacedVectorAllLanes()) return false;
1132 return VectorList.Count == 2;
1135 bool isVecListTwoQAllLanes() const {
1136 if (!isDoubleSpacedVectorAllLanes()) return false;
1137 return VectorList.Count == 2;
1140 bool isVecListThreeDAllLanes() const {
1141 if (!isSingleSpacedVectorAllLanes()) return false;
1142 return VectorList.Count == 3;
1145 bool isVecListThreeQAllLanes() const {
1146 if (!isDoubleSpacedVectorAllLanes()) return false;
1147 return VectorList.Count == 3;
1150 bool isVecListFourDAllLanes() const {
1151 if (!isSingleSpacedVectorAllLanes()) return false;
1152 return VectorList.Count == 4;
1155 bool isVecListFourQAllLanes() const {
1156 if (!isDoubleSpacedVectorAllLanes()) return false;
1157 return VectorList.Count == 4;
1160 bool isSingleSpacedVectorIndexed() const {
1161 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1163 bool isDoubleSpacedVectorIndexed() const {
1164 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1166 bool isVecListOneDByteIndexed() const {
1167 if (!isSingleSpacedVectorIndexed()) return false;
1168 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1171 bool isVecListOneDHWordIndexed() const {
1172 if (!isSingleSpacedVectorIndexed()) return false;
1173 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1176 bool isVecListOneDWordIndexed() const {
1177 if (!isSingleSpacedVectorIndexed()) return false;
1178 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1181 bool isVecListTwoDByteIndexed() const {
1182 if (!isSingleSpacedVectorIndexed()) return false;
1183 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1186 bool isVecListTwoDHWordIndexed() const {
1187 if (!isSingleSpacedVectorIndexed()) return false;
1188 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1191 bool isVecListTwoQWordIndexed() const {
1192 if (!isDoubleSpacedVectorIndexed()) return false;
1193 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1196 bool isVecListTwoQHWordIndexed() const {
1197 if (!isDoubleSpacedVectorIndexed()) return false;
1198 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1201 bool isVecListTwoDWordIndexed() const {
1202 if (!isSingleSpacedVectorIndexed()) return false;
1203 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1206 bool isVecListThreeDByteIndexed() const {
1207 if (!isSingleSpacedVectorIndexed()) return false;
1208 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1211 bool isVecListThreeDHWordIndexed() const {
1212 if (!isSingleSpacedVectorIndexed()) return false;
1213 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1216 bool isVecListThreeQWordIndexed() const {
1217 if (!isDoubleSpacedVectorIndexed()) return false;
1218 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1221 bool isVecListThreeQHWordIndexed() const {
1222 if (!isDoubleSpacedVectorIndexed()) return false;
1223 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1226 bool isVecListThreeDWordIndexed() const {
1227 if (!isSingleSpacedVectorIndexed()) return false;
1228 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1231 bool isVecListFourDByteIndexed() const {
1232 if (!isSingleSpacedVectorIndexed()) return false;
1233 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1236 bool isVecListFourDHWordIndexed() const {
1237 if (!isSingleSpacedVectorIndexed()) return false;
1238 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1241 bool isVecListFourQWordIndexed() const {
1242 if (!isDoubleSpacedVectorIndexed()) return false;
1243 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1246 bool isVecListFourQHWordIndexed() const {
1247 if (!isDoubleSpacedVectorIndexed()) return false;
1248 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1251 bool isVecListFourDWordIndexed() const {
1252 if (!isSingleSpacedVectorIndexed()) return false;
1253 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1256 bool isVectorIndex8() const {
1257 if (Kind != k_VectorIndex) return false;
1258 return VectorIndex.Val < 8;
1260 bool isVectorIndex16() const {
1261 if (Kind != k_VectorIndex) return false;
1262 return VectorIndex.Val < 4;
1264 bool isVectorIndex32() const {
1265 if (Kind != k_VectorIndex) return false;
1266 return VectorIndex.Val < 2;
1269 bool isNEONi8splat() const {
1270 if (!isImm()) return false;
1271 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1272 // Must be a constant.
1273 if (!CE) return false;
1274 int64_t Value = CE->getValue();
1275 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1277 return Value >= 0 && Value < 256;
1280 bool isNEONi16splat() const {
1281 if (!isImm()) return false;
1282 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1283 // Must be a constant.
1284 if (!CE) return false;
1285 int64_t Value = CE->getValue();
1286 // i16 value in the range [0,255] or [0x0100, 0xff00]
1287 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1290 bool isNEONi32splat() const {
1291 if (!isImm()) return false;
1292 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1293 // Must be a constant.
1294 if (!CE) return false;
1295 int64_t Value = CE->getValue();
1296 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1297 return (Value >= 0 && Value < 256) ||
1298 (Value >= 0x0100 && Value <= 0xff00) ||
1299 (Value >= 0x010000 && Value <= 0xff0000) ||
1300 (Value >= 0x01000000 && Value <= 0xff000000);
1303 bool isNEONi32vmov() const {
1304 if (!isImm()) return false;
1305 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1306 // Must be a constant.
1307 if (!CE) return false;
1308 int64_t Value = CE->getValue();
1309 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1310 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1311 return (Value >= 0 && Value < 256) ||
1312 (Value >= 0x0100 && Value <= 0xff00) ||
1313 (Value >= 0x010000 && Value <= 0xff0000) ||
1314 (Value >= 0x01000000 && Value <= 0xff000000) ||
1315 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1316 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1318 bool isNEONi32vmovNeg() const {
1319 if (!isImm()) return false;
1320 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1321 // Must be a constant.
1322 if (!CE) return false;
1323 int64_t Value = ~CE->getValue();
1324 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1325 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1326 return (Value >= 0 && Value < 256) ||
1327 (Value >= 0x0100 && Value <= 0xff00) ||
1328 (Value >= 0x010000 && Value <= 0xff0000) ||
1329 (Value >= 0x01000000 && Value <= 0xff000000) ||
1330 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1331 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1334 bool isNEONi64splat() const {
1335 if (!isImm()) return false;
1336 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1337 // Must be a constant.
1338 if (!CE) return false;
1339 uint64_t Value = CE->getValue();
1340 // i64 value with each byte being either 0 or 0xff.
1341 for (unsigned i = 0; i < 8; ++i)
1342 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1346 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1347 // Add as immediates when possible. Null MCExpr = 0.
1349 Inst.addOperand(MCOperand::CreateImm(0));
1350 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1351 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1353 Inst.addOperand(MCOperand::CreateExpr(Expr));
1356 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1357 assert(N == 2 && "Invalid number of operands!");
1358 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1359 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1360 Inst.addOperand(MCOperand::CreateReg(RegNum));
1363 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1364 assert(N == 1 && "Invalid number of operands!");
1365 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1368 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1369 assert(N == 1 && "Invalid number of operands!");
1370 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1373 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1374 assert(N == 1 && "Invalid number of operands!");
1375 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1378 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1379 assert(N == 1 && "Invalid number of operands!");
1380 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1383 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1384 assert(N == 1 && "Invalid number of operands!");
1385 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1388 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1389 assert(N == 1 && "Invalid number of operands!");
1390 Inst.addOperand(MCOperand::CreateReg(getReg()));
1393 void addRegOperands(MCInst &Inst, unsigned N) const {
1394 assert(N == 1 && "Invalid number of operands!");
1395 Inst.addOperand(MCOperand::CreateReg(getReg()));
1398 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1399 assert(N == 3 && "Invalid number of operands!");
1400 assert(isRegShiftedReg() &&
1401 "addRegShiftedRegOperands() on non RegShiftedReg!");
1402 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1403 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1404 Inst.addOperand(MCOperand::CreateImm(
1405 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1408 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1409 assert(N == 2 && "Invalid number of operands!");
1410 assert(isRegShiftedImm() &&
1411 "addRegShiftedImmOperands() on non RegShiftedImm!");
1412 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1413 Inst.addOperand(MCOperand::CreateImm(
1414 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, RegShiftedImm.ShiftImm)));
1417 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1418 assert(N == 1 && "Invalid number of operands!");
1419 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1423 void addRegListOperands(MCInst &Inst, unsigned N) const {
1424 assert(N == 1 && "Invalid number of operands!");
1425 const SmallVectorImpl<unsigned> &RegList = getRegList();
1426 for (SmallVectorImpl<unsigned>::const_iterator
1427 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1428 Inst.addOperand(MCOperand::CreateReg(*I));
1431 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1432 addRegListOperands(Inst, N);
1435 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1436 addRegListOperands(Inst, N);
1439 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1440 assert(N == 1 && "Invalid number of operands!");
1441 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1442 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1445 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1446 assert(N == 1 && "Invalid number of operands!");
1447 // Munge the lsb/width into a bitfield mask.
1448 unsigned lsb = Bitfield.LSB;
1449 unsigned width = Bitfield.Width;
1450 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1451 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1452 (32 - (lsb + width)));
1453 Inst.addOperand(MCOperand::CreateImm(Mask));
1456 void addImmOperands(MCInst &Inst, unsigned N) const {
1457 assert(N == 1 && "Invalid number of operands!");
1458 addExpr(Inst, getImm());
1461 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1462 assert(N == 1 && "Invalid number of operands!");
1463 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1464 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1467 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1468 assert(N == 1 && "Invalid number of operands!");
1469 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1470 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1473 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1474 assert(N == 1 && "Invalid number of operands!");
1475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1476 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1477 Inst.addOperand(MCOperand::CreateImm(Val));
1480 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1481 assert(N == 1 && "Invalid number of operands!");
1482 // FIXME: We really want to scale the value here, but the LDRD/STRD
1483 // instruction don't encode operands that way yet.
1484 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1485 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1488 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1489 assert(N == 1 && "Invalid number of operands!");
1490 // The immediate is scaled by four in the encoding and is stored
1491 // in the MCInst as such. Lop off the low two bits here.
1492 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1493 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1496 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1497 assert(N == 1 && "Invalid number of operands!");
1498 // The immediate is scaled by four in the encoding and is stored
1499 // in the MCInst as such. Lop off the low two bits here.
1500 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1501 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1504 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1505 assert(N == 1 && "Invalid number of operands!");
1506 // The constant encodes as the immediate-1, and we store in the instruction
1507 // the bits as encoded, so subtract off one here.
1508 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1509 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1512 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1513 assert(N == 1 && "Invalid number of operands!");
1514 // The constant encodes as the immediate-1, and we store in the instruction
1515 // the bits as encoded, so subtract off one here.
1516 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1517 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1520 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1521 assert(N == 1 && "Invalid number of operands!");
1522 // The constant encodes as the immediate, except for 32, which encodes as
1524 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1525 unsigned Imm = CE->getValue();
1526 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1529 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1530 assert(N == 1 && "Invalid number of operands!");
1531 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1532 // the instruction as well.
1533 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1534 int Val = CE->getValue();
1535 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1538 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1539 assert(N == 1 && "Invalid number of operands!");
1540 // The operand is actually a t2_so_imm, but we have its bitwise
1541 // negation in the assembly source, so twiddle it here.
1542 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1543 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1546 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1547 assert(N == 1 && "Invalid number of operands!");
1548 // The operand is actually a t2_so_imm, but we have its
1549 // negation in the assembly source, so twiddle it here.
1550 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1551 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1554 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1555 assert(N == 1 && "Invalid number of operands!");
1556 // The operand is actually a so_imm, but we have its bitwise
1557 // negation in the assembly source, so twiddle it here.
1558 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1559 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1562 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1563 assert(N == 1 && "Invalid number of operands!");
1564 // The operand is actually a so_imm, but we have its
1565 // negation in the assembly source, so twiddle it here.
1566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1567 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1570 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1571 assert(N == 1 && "Invalid number of operands!");
1572 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1575 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1576 assert(N == 1 && "Invalid number of operands!");
1577 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1580 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1581 assert(N == 1 && "Invalid number of operands!");
1582 int32_t Imm = Memory.OffsetImm->getValue();
1583 // FIXME: Handle #-0
1584 if (Imm == INT32_MIN) Imm = 0;
1585 Inst.addOperand(MCOperand::CreateImm(Imm));
1588 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1589 assert(N == 2 && "Invalid number of operands!");
1590 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1591 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1594 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1595 assert(N == 3 && "Invalid number of operands!");
1596 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1597 if (!Memory.OffsetRegNum) {
1598 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1599 // Special case for #-0
1600 if (Val == INT32_MIN) Val = 0;
1601 if (Val < 0) Val = -Val;
1602 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1604 // For register offset, we encode the shift type and negation flag
1606 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1607 Memory.ShiftImm, Memory.ShiftType);
1609 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1610 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1611 Inst.addOperand(MCOperand::CreateImm(Val));
1614 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1615 assert(N == 2 && "Invalid number of operands!");
1616 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1617 assert(CE && "non-constant AM2OffsetImm operand!");
1618 int32_t Val = CE->getValue();
1619 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1620 // Special case for #-0
1621 if (Val == INT32_MIN) Val = 0;
1622 if (Val < 0) Val = -Val;
1623 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1624 Inst.addOperand(MCOperand::CreateReg(0));
1625 Inst.addOperand(MCOperand::CreateImm(Val));
1628 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1629 assert(N == 3 && "Invalid number of operands!");
1630 // If we have an immediate that's not a constant, treat it as a label
1631 // reference needing a fixup. If it is a constant, it's something else
1632 // and we reject it.
1634 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1635 Inst.addOperand(MCOperand::CreateReg(0));
1636 Inst.addOperand(MCOperand::CreateImm(0));
1640 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1641 if (!Memory.OffsetRegNum) {
1642 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1643 // Special case for #-0
1644 if (Val == INT32_MIN) Val = 0;
1645 if (Val < 0) Val = -Val;
1646 Val = ARM_AM::getAM3Opc(AddSub, Val);
1648 // For register offset, we encode the shift type and negation flag
1650 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1652 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1653 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1654 Inst.addOperand(MCOperand::CreateImm(Val));
1657 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1658 assert(N == 2 && "Invalid number of operands!");
1659 if (Kind == k_PostIndexRegister) {
1661 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1662 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1663 Inst.addOperand(MCOperand::CreateImm(Val));
1668 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1669 int32_t Val = CE->getValue();
1670 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1671 // Special case for #-0
1672 if (Val == INT32_MIN) Val = 0;
1673 if (Val < 0) Val = -Val;
1674 Val = ARM_AM::getAM3Opc(AddSub, Val);
1675 Inst.addOperand(MCOperand::CreateReg(0));
1676 Inst.addOperand(MCOperand::CreateImm(Val));
1679 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1680 assert(N == 2 && "Invalid number of operands!");
1681 // If we have an immediate that's not a constant, treat it as a label
1682 // reference needing a fixup. If it is a constant, it's something else
1683 // and we reject it.
1685 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1686 Inst.addOperand(MCOperand::CreateImm(0));
1690 // The lower two bits are always zero and as such are not encoded.
1691 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1692 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1693 // Special case for #-0
1694 if (Val == INT32_MIN) Val = 0;
1695 if (Val < 0) Val = -Val;
1696 Val = ARM_AM::getAM5Opc(AddSub, Val);
1697 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1698 Inst.addOperand(MCOperand::CreateImm(Val));
1701 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1702 assert(N == 2 && "Invalid number of operands!");
1703 // If we have an immediate that's not a constant, treat it as a label
1704 // reference needing a fixup. If it is a constant, it's something else
1705 // and we reject it.
1707 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1708 Inst.addOperand(MCOperand::CreateImm(0));
1712 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1713 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1714 Inst.addOperand(MCOperand::CreateImm(Val));
1717 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1718 assert(N == 2 && "Invalid number of operands!");
1719 // The lower two bits are always zero and as such are not encoded.
1720 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1721 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1722 Inst.addOperand(MCOperand::CreateImm(Val));
1725 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1726 assert(N == 2 && "Invalid number of operands!");
1727 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1728 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1729 Inst.addOperand(MCOperand::CreateImm(Val));
1732 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1733 addMemImm8OffsetOperands(Inst, N);
1736 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1737 addMemImm8OffsetOperands(Inst, N);
1740 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1741 assert(N == 2 && "Invalid number of operands!");
1742 // If this is an immediate, it's a label reference.
1744 addExpr(Inst, getImm());
1745 Inst.addOperand(MCOperand::CreateImm(0));
1749 // Otherwise, it's a normal memory reg+offset.
1750 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1751 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1752 Inst.addOperand(MCOperand::CreateImm(Val));
1755 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1756 assert(N == 2 && "Invalid number of operands!");
1757 // If this is an immediate, it's a label reference.
1759 addExpr(Inst, getImm());
1760 Inst.addOperand(MCOperand::CreateImm(0));
1764 // Otherwise, it's a normal memory reg+offset.
1765 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1766 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1767 Inst.addOperand(MCOperand::CreateImm(Val));
1770 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1771 assert(N == 2 && "Invalid number of operands!");
1772 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1773 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1776 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1777 assert(N == 2 && "Invalid number of operands!");
1778 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1779 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1782 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1783 assert(N == 3 && "Invalid number of operands!");
1785 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1786 Memory.ShiftImm, Memory.ShiftType);
1787 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1788 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1789 Inst.addOperand(MCOperand::CreateImm(Val));
1792 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1793 assert(N == 3 && "Invalid number of operands!");
1794 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1795 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1796 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1799 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1800 assert(N == 2 && "Invalid number of operands!");
1801 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1802 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1805 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1806 assert(N == 2 && "Invalid number of operands!");
1807 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1808 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1809 Inst.addOperand(MCOperand::CreateImm(Val));
1812 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1813 assert(N == 2 && "Invalid number of operands!");
1814 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1815 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1816 Inst.addOperand(MCOperand::CreateImm(Val));
1819 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1820 assert(N == 2 && "Invalid number of operands!");
1821 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1822 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1823 Inst.addOperand(MCOperand::CreateImm(Val));
1826 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1827 assert(N == 2 && "Invalid number of operands!");
1828 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1829 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1830 Inst.addOperand(MCOperand::CreateImm(Val));
1833 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1834 assert(N == 1 && "Invalid number of operands!");
1835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1836 assert(CE && "non-constant post-idx-imm8 operand!");
1837 int Imm = CE->getValue();
1838 bool isAdd = Imm >= 0;
1839 if (Imm == INT32_MIN) Imm = 0;
1840 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1841 Inst.addOperand(MCOperand::CreateImm(Imm));
1844 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1845 assert(N == 1 && "Invalid number of operands!");
1846 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1847 assert(CE && "non-constant post-idx-imm8s4 operand!");
1848 int Imm = CE->getValue();
1849 bool isAdd = Imm >= 0;
1850 if (Imm == INT32_MIN) Imm = 0;
1851 // Immediate is scaled by 4.
1852 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1853 Inst.addOperand(MCOperand::CreateImm(Imm));
1856 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1857 assert(N == 2 && "Invalid number of operands!");
1858 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1859 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1862 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1863 assert(N == 2 && "Invalid number of operands!");
1864 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1865 // The sign, shift type, and shift amount are encoded in a single operand
1866 // using the AM2 encoding helpers.
1867 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1868 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1869 PostIdxReg.ShiftTy);
1870 Inst.addOperand(MCOperand::CreateImm(Imm));
1873 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1874 assert(N == 1 && "Invalid number of operands!");
1875 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1878 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1879 assert(N == 1 && "Invalid number of operands!");
1880 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1883 void addVecListOperands(MCInst &Inst, unsigned N) const {
1884 assert(N == 1 && "Invalid number of operands!");
1885 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1888 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1889 assert(N == 2 && "Invalid number of operands!");
1890 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1891 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1894 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1895 assert(N == 1 && "Invalid number of operands!");
1896 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1899 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1900 assert(N == 1 && "Invalid number of operands!");
1901 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1904 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1905 assert(N == 1 && "Invalid number of operands!");
1906 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1909 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1910 assert(N == 1 && "Invalid number of operands!");
1911 // The immediate encodes the type of constant as well as the value.
1912 // Mask in that this is an i8 splat.
1913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1914 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1917 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1918 assert(N == 1 && "Invalid number of operands!");
1919 // The immediate encodes the type of constant as well as the value.
1920 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1921 unsigned Value = CE->getValue();
1923 Value = (Value >> 8) | 0xa00;
1926 Inst.addOperand(MCOperand::CreateImm(Value));
1929 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
1930 assert(N == 1 && "Invalid number of operands!");
1931 // The immediate encodes the type of constant as well as the value.
1932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1933 unsigned Value = CE->getValue();
1934 if (Value >= 256 && Value <= 0xff00)
1935 Value = (Value >> 8) | 0x200;
1936 else if (Value > 0xffff && Value <= 0xff0000)
1937 Value = (Value >> 16) | 0x400;
1938 else if (Value > 0xffffff)
1939 Value = (Value >> 24) | 0x600;
1940 Inst.addOperand(MCOperand::CreateImm(Value));
1943 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
1944 assert(N == 1 && "Invalid number of operands!");
1945 // The immediate encodes the type of constant as well as the value.
1946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1947 unsigned Value = CE->getValue();
1948 if (Value >= 256 && Value <= 0xffff)
1949 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1950 else if (Value > 0xffff && Value <= 0xffffff)
1951 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1952 else if (Value > 0xffffff)
1953 Value = (Value >> 24) | 0x600;
1954 Inst.addOperand(MCOperand::CreateImm(Value));
1957 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
1958 assert(N == 1 && "Invalid number of operands!");
1959 // The immediate encodes the type of constant as well as the value.
1960 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1961 unsigned Value = ~CE->getValue();
1962 if (Value >= 256 && Value <= 0xffff)
1963 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1964 else if (Value > 0xffff && Value <= 0xffffff)
1965 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1966 else if (Value > 0xffffff)
1967 Value = (Value >> 24) | 0x600;
1968 Inst.addOperand(MCOperand::CreateImm(Value));
1971 void addNEONi64splatOperands(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 uint64_t Value = CE->getValue();
1977 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
1978 Imm |= (Value & 1) << i;
1980 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
1983 virtual void print(raw_ostream &OS) const;
1985 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
1986 ARMOperand *Op = new ARMOperand(k_ITCondMask);
1987 Op->ITMask.Mask = Mask;
1993 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
1994 ARMOperand *Op = new ARMOperand(k_CondCode);
2001 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2002 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2003 Op->Cop.Val = CopVal;
2009 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2010 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2011 Op->Cop.Val = CopVal;
2017 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2018 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2025 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2026 ARMOperand *Op = new ARMOperand(k_CCOut);
2027 Op->Reg.RegNum = RegNum;
2033 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2034 ARMOperand *Op = new ARMOperand(k_Token);
2035 Op->Tok.Data = Str.data();
2036 Op->Tok.Length = Str.size();
2042 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2043 ARMOperand *Op = new ARMOperand(k_Register);
2044 Op->Reg.RegNum = RegNum;
2050 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2055 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2056 Op->RegShiftedReg.ShiftTy = ShTy;
2057 Op->RegShiftedReg.SrcReg = SrcReg;
2058 Op->RegShiftedReg.ShiftReg = ShiftReg;
2059 Op->RegShiftedReg.ShiftImm = ShiftImm;
2065 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2069 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2070 Op->RegShiftedImm.ShiftTy = ShTy;
2071 Op->RegShiftedImm.SrcReg = SrcReg;
2072 Op->RegShiftedImm.ShiftImm = ShiftImm;
2078 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2080 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2081 Op->ShifterImm.isASR = isASR;
2082 Op->ShifterImm.Imm = Imm;
2088 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2089 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2090 Op->RotImm.Imm = Imm;
2096 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2098 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2099 Op->Bitfield.LSB = LSB;
2100 Op->Bitfield.Width = Width;
2107 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
2108 SMLoc StartLoc, SMLoc EndLoc) {
2109 KindTy Kind = k_RegisterList;
2111 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
2112 Kind = k_DPRRegisterList;
2113 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2114 contains(Regs.front().first))
2115 Kind = k_SPRRegisterList;
2117 ARMOperand *Op = new ARMOperand(Kind);
2118 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
2119 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2120 Op->Registers.push_back(I->first);
2121 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
2122 Op->StartLoc = StartLoc;
2123 Op->EndLoc = EndLoc;
2127 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2128 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2129 ARMOperand *Op = new ARMOperand(k_VectorList);
2130 Op->VectorList.RegNum = RegNum;
2131 Op->VectorList.Count = Count;
2132 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2138 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2139 bool isDoubleSpaced,
2141 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2142 Op->VectorList.RegNum = RegNum;
2143 Op->VectorList.Count = Count;
2144 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2150 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2152 bool isDoubleSpaced,
2154 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2155 Op->VectorList.RegNum = RegNum;
2156 Op->VectorList.Count = Count;
2157 Op->VectorList.LaneIndex = Index;
2158 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2164 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2166 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2167 Op->VectorIndex.Val = Idx;
2173 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2174 ARMOperand *Op = new ARMOperand(k_Immediate);
2181 static ARMOperand *CreateMem(unsigned BaseRegNum,
2182 const MCConstantExpr *OffsetImm,
2183 unsigned OffsetRegNum,
2184 ARM_AM::ShiftOpc ShiftType,
2189 ARMOperand *Op = new ARMOperand(k_Memory);
2190 Op->Memory.BaseRegNum = BaseRegNum;
2191 Op->Memory.OffsetImm = OffsetImm;
2192 Op->Memory.OffsetRegNum = OffsetRegNum;
2193 Op->Memory.ShiftType = ShiftType;
2194 Op->Memory.ShiftImm = ShiftImm;
2195 Op->Memory.Alignment = Alignment;
2196 Op->Memory.isNegative = isNegative;
2202 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2203 ARM_AM::ShiftOpc ShiftTy,
2206 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2207 Op->PostIdxReg.RegNum = RegNum;
2208 Op->PostIdxReg.isAdd = isAdd;
2209 Op->PostIdxReg.ShiftTy = ShiftTy;
2210 Op->PostIdxReg.ShiftImm = ShiftImm;
2216 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2217 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2218 Op->MBOpt.Val = Opt;
2224 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2225 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2226 Op->IFlags.Val = IFlags;
2232 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2233 ARMOperand *Op = new ARMOperand(k_MSRMask);
2234 Op->MMask.Val = MMask;
2241 } // end anonymous namespace.
2243 void ARMOperand::print(raw_ostream &OS) const {
2246 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2249 OS << "<ccout " << getReg() << ">";
2251 case k_ITCondMask: {
2252 static const char *MaskStr[] = {
2253 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2254 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2256 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2257 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2261 OS << "<coprocessor number: " << getCoproc() << ">";
2264 OS << "<coprocessor register: " << getCoproc() << ">";
2266 case k_CoprocOption:
2267 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2270 OS << "<mask: " << getMSRMask() << ">";
2273 getImm()->print(OS);
2275 case k_MemBarrierOpt:
2276 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2280 << " base:" << Memory.BaseRegNum;
2283 case k_PostIndexRegister:
2284 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2285 << PostIdxReg.RegNum;
2286 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2287 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2288 << PostIdxReg.ShiftImm;
2291 case k_ProcIFlags: {
2292 OS << "<ARM_PROC::";
2293 unsigned IFlags = getProcIFlags();
2294 for (int i=2; i >= 0; --i)
2295 if (IFlags & (1 << i))
2296 OS << ARM_PROC::IFlagsToString(1 << i);
2301 OS << "<register " << getReg() << ">";
2303 case k_ShifterImmediate:
2304 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2305 << " #" << ShifterImm.Imm << ">";
2307 case k_ShiftedRegister:
2308 OS << "<so_reg_reg "
2309 << RegShiftedReg.SrcReg << " "
2310 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2311 << " " << RegShiftedReg.ShiftReg << ">";
2313 case k_ShiftedImmediate:
2314 OS << "<so_reg_imm "
2315 << RegShiftedImm.SrcReg << " "
2316 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2317 << " #" << RegShiftedImm.ShiftImm << ">";
2319 case k_RotateImmediate:
2320 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2322 case k_BitfieldDescriptor:
2323 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2324 << ", width: " << Bitfield.Width << ">";
2326 case k_RegisterList:
2327 case k_DPRRegisterList:
2328 case k_SPRRegisterList: {
2329 OS << "<register_list ";
2331 const SmallVectorImpl<unsigned> &RegList = getRegList();
2332 for (SmallVectorImpl<unsigned>::const_iterator
2333 I = RegList.begin(), E = RegList.end(); I != E; ) {
2335 if (++I < E) OS << ", ";
2342 OS << "<vector_list " << VectorList.Count << " * "
2343 << VectorList.RegNum << ">";
2345 case k_VectorListAllLanes:
2346 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2347 << VectorList.RegNum << ">";
2349 case k_VectorListIndexed:
2350 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2351 << VectorList.Count << " * " << VectorList.RegNum << ">";
2354 OS << "'" << getToken() << "'";
2357 OS << "<vectorindex " << getVectorIndex() << ">";
2362 /// @name Auto-generated Match Functions
2365 static unsigned MatchRegisterName(StringRef Name);
2369 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2370 SMLoc &StartLoc, SMLoc &EndLoc) {
2371 StartLoc = Parser.getTok().getLoc();
2372 RegNo = tryParseRegister();
2373 EndLoc = Parser.getTok().getLoc();
2375 return (RegNo == (unsigned)-1);
2378 /// Try to parse a register name. The token must be an Identifier when called,
2379 /// and if it is a register name the token is eaten and the register number is
2380 /// returned. Otherwise return -1.
2382 int ARMAsmParser::tryParseRegister() {
2383 const AsmToken &Tok = Parser.getTok();
2384 if (Tok.isNot(AsmToken::Identifier)) return -1;
2386 std::string lowerCase = Tok.getString().lower();
2387 unsigned RegNum = MatchRegisterName(lowerCase);
2389 RegNum = StringSwitch<unsigned>(lowerCase)
2390 .Case("r13", ARM::SP)
2391 .Case("r14", ARM::LR)
2392 .Case("r15", ARM::PC)
2393 .Case("ip", ARM::R12)
2394 // Additional register name aliases for 'gas' compatibility.
2395 .Case("a1", ARM::R0)
2396 .Case("a2", ARM::R1)
2397 .Case("a3", ARM::R2)
2398 .Case("a4", ARM::R3)
2399 .Case("v1", ARM::R4)
2400 .Case("v2", ARM::R5)
2401 .Case("v3", ARM::R6)
2402 .Case("v4", ARM::R7)
2403 .Case("v5", ARM::R8)
2404 .Case("v6", ARM::R9)
2405 .Case("v7", ARM::R10)
2406 .Case("v8", ARM::R11)
2407 .Case("sb", ARM::R9)
2408 .Case("sl", ARM::R10)
2409 .Case("fp", ARM::R11)
2413 // Check for aliases registered via .req. Canonicalize to lower case.
2414 // That's more consistent since register names are case insensitive, and
2415 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2416 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2417 // If no match, return failure.
2418 if (Entry == RegisterReqs.end())
2420 Parser.Lex(); // Eat identifier token.
2421 return Entry->getValue();
2424 Parser.Lex(); // Eat identifier token.
2429 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2430 // If a recoverable error occurs, return 1. If an irrecoverable error
2431 // occurs, return -1. An irrecoverable error is one where tokens have been
2432 // consumed in the process of trying to parse the shifter (i.e., when it is
2433 // indeed a shifter operand, but malformed).
2434 int ARMAsmParser::tryParseShiftRegister(
2435 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2436 SMLoc S = Parser.getTok().getLoc();
2437 const AsmToken &Tok = Parser.getTok();
2438 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2440 std::string lowerCase = Tok.getString().lower();
2441 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2442 .Case("asl", ARM_AM::lsl)
2443 .Case("lsl", ARM_AM::lsl)
2444 .Case("lsr", ARM_AM::lsr)
2445 .Case("asr", ARM_AM::asr)
2446 .Case("ror", ARM_AM::ror)
2447 .Case("rrx", ARM_AM::rrx)
2448 .Default(ARM_AM::no_shift);
2450 if (ShiftTy == ARM_AM::no_shift)
2453 Parser.Lex(); // Eat the operator.
2455 // The source register for the shift has already been added to the
2456 // operand list, so we need to pop it off and combine it into the shifted
2457 // register operand instead.
2458 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2459 if (!PrevOp->isReg())
2460 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2461 int SrcReg = PrevOp->getReg();
2464 if (ShiftTy == ARM_AM::rrx) {
2465 // RRX Doesn't have an explicit shift amount. The encoder expects
2466 // the shift register to be the same as the source register. Seems odd,
2470 // Figure out if this is shifted by a constant or a register (for non-RRX).
2471 if (Parser.getTok().is(AsmToken::Hash) ||
2472 Parser.getTok().is(AsmToken::Dollar)) {
2473 Parser.Lex(); // Eat hash.
2474 SMLoc ImmLoc = Parser.getTok().getLoc();
2475 const MCExpr *ShiftExpr = 0;
2476 if (getParser().ParseExpression(ShiftExpr)) {
2477 Error(ImmLoc, "invalid immediate shift value");
2480 // The expression must be evaluatable as an immediate.
2481 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2483 Error(ImmLoc, "invalid immediate shift value");
2486 // Range check the immediate.
2487 // lsl, ror: 0 <= imm <= 31
2488 // lsr, asr: 0 <= imm <= 32
2489 Imm = CE->getValue();
2491 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2492 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2493 Error(ImmLoc, "immediate shift value out of range");
2496 // shift by zero is a nop. Always send it through as lsl.
2497 // ('as' compatibility)
2499 ShiftTy = ARM_AM::lsl;
2500 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2501 ShiftReg = tryParseRegister();
2502 SMLoc L = Parser.getTok().getLoc();
2503 if (ShiftReg == -1) {
2504 Error (L, "expected immediate or register in shift operand");
2508 Error (Parser.getTok().getLoc(),
2509 "expected immediate or register in shift operand");
2514 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2515 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2517 S, Parser.getTok().getLoc()));
2519 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2520 S, Parser.getTok().getLoc()));
2526 /// Try to parse a register name. The token must be an Identifier when called.
2527 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2528 /// if there is a "writeback". 'true' if it's not a register.
2530 /// TODO this is likely to change to allow different register types and or to
2531 /// parse for a specific register type.
2533 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2534 SMLoc S = Parser.getTok().getLoc();
2535 int RegNo = tryParseRegister();
2539 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
2541 const AsmToken &ExclaimTok = Parser.getTok();
2542 if (ExclaimTok.is(AsmToken::Exclaim)) {
2543 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2544 ExclaimTok.getLoc()));
2545 Parser.Lex(); // Eat exclaim token
2549 // Also check for an index operand. This is only legal for vector registers,
2550 // but that'll get caught OK in operand matching, so we don't need to
2551 // explicitly filter everything else out here.
2552 if (Parser.getTok().is(AsmToken::LBrac)) {
2553 SMLoc SIdx = Parser.getTok().getLoc();
2554 Parser.Lex(); // Eat left bracket token.
2556 const MCExpr *ImmVal;
2557 if (getParser().ParseExpression(ImmVal))
2559 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2561 return TokError("immediate value expected for vector index");
2563 SMLoc E = Parser.getTok().getLoc();
2564 if (Parser.getTok().isNot(AsmToken::RBrac))
2565 return Error(E, "']' expected");
2567 Parser.Lex(); // Eat right bracket token.
2569 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2577 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2578 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2580 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2581 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2583 switch (Name.size()) {
2586 if (Name[0] != CoprocOp)
2602 if (Name[0] != CoprocOp || Name[1] != '1')
2606 case '0': return 10;
2607 case '1': return 11;
2608 case '2': return 12;
2609 case '3': return 13;
2610 case '4': return 14;
2611 case '5': return 15;
2616 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2617 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2618 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2619 SMLoc S = Parser.getTok().getLoc();
2620 const AsmToken &Tok = Parser.getTok();
2621 if (!Tok.is(AsmToken::Identifier))
2622 return MatchOperand_NoMatch;
2623 unsigned CC = StringSwitch<unsigned>(Tok.getString())
2624 .Case("eq", ARMCC::EQ)
2625 .Case("ne", ARMCC::NE)
2626 .Case("hs", ARMCC::HS)
2627 .Case("cs", ARMCC::HS)
2628 .Case("lo", ARMCC::LO)
2629 .Case("cc", ARMCC::LO)
2630 .Case("mi", ARMCC::MI)
2631 .Case("pl", ARMCC::PL)
2632 .Case("vs", ARMCC::VS)
2633 .Case("vc", ARMCC::VC)
2634 .Case("hi", ARMCC::HI)
2635 .Case("ls", ARMCC::LS)
2636 .Case("ge", ARMCC::GE)
2637 .Case("lt", ARMCC::LT)
2638 .Case("gt", ARMCC::GT)
2639 .Case("le", ARMCC::LE)
2640 .Case("al", ARMCC::AL)
2643 return MatchOperand_NoMatch;
2644 Parser.Lex(); // Eat the token.
2646 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2648 return MatchOperand_Success;
2651 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2652 /// token must be an Identifier when called, and if it is a coprocessor
2653 /// number, the token is eaten and the operand is added to the operand list.
2654 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2655 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2656 SMLoc S = Parser.getTok().getLoc();
2657 const AsmToken &Tok = Parser.getTok();
2658 if (Tok.isNot(AsmToken::Identifier))
2659 return MatchOperand_NoMatch;
2661 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2663 return MatchOperand_NoMatch;
2665 Parser.Lex(); // Eat identifier token.
2666 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2667 return MatchOperand_Success;
2670 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2671 /// token must be an Identifier when called, and if it is a coprocessor
2672 /// number, the token is eaten and the operand is added to the operand list.
2673 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2674 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2675 SMLoc S = Parser.getTok().getLoc();
2676 const AsmToken &Tok = Parser.getTok();
2677 if (Tok.isNot(AsmToken::Identifier))
2678 return MatchOperand_NoMatch;
2680 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2682 return MatchOperand_NoMatch;
2684 Parser.Lex(); // Eat identifier token.
2685 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2686 return MatchOperand_Success;
2689 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2690 /// coproc_option : '{' imm0_255 '}'
2691 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2692 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2693 SMLoc S = Parser.getTok().getLoc();
2695 // If this isn't a '{', this isn't a coprocessor immediate operand.
2696 if (Parser.getTok().isNot(AsmToken::LCurly))
2697 return MatchOperand_NoMatch;
2698 Parser.Lex(); // Eat the '{'
2701 SMLoc Loc = Parser.getTok().getLoc();
2702 if (getParser().ParseExpression(Expr)) {
2703 Error(Loc, "illegal expression");
2704 return MatchOperand_ParseFail;
2706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2707 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2708 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2709 return MatchOperand_ParseFail;
2711 int Val = CE->getValue();
2713 // Check for and consume the closing '}'
2714 if (Parser.getTok().isNot(AsmToken::RCurly))
2715 return MatchOperand_ParseFail;
2716 SMLoc E = Parser.getTok().getLoc();
2717 Parser.Lex(); // Eat the '}'
2719 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2720 return MatchOperand_Success;
2723 // For register list parsing, we need to map from raw GPR register numbering
2724 // to the enumeration values. The enumeration values aren't sorted by
2725 // register number due to our using "sp", "lr" and "pc" as canonical names.
2726 static unsigned getNextRegister(unsigned Reg) {
2727 // If this is a GPR, we need to do it manually, otherwise we can rely
2728 // on the sort ordering of the enumeration since the other reg-classes
2730 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2733 default: llvm_unreachable("Invalid GPR number!");
2734 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2735 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2736 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2737 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2738 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2739 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2740 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2741 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2745 // Return the low-subreg of a given Q register.
2746 static unsigned getDRegFromQReg(unsigned QReg) {
2748 default: llvm_unreachable("expected a Q register!");
2749 case ARM::Q0: return ARM::D0;
2750 case ARM::Q1: return ARM::D2;
2751 case ARM::Q2: return ARM::D4;
2752 case ARM::Q3: return ARM::D6;
2753 case ARM::Q4: return ARM::D8;
2754 case ARM::Q5: return ARM::D10;
2755 case ARM::Q6: return ARM::D12;
2756 case ARM::Q7: return ARM::D14;
2757 case ARM::Q8: return ARM::D16;
2758 case ARM::Q9: return ARM::D18;
2759 case ARM::Q10: return ARM::D20;
2760 case ARM::Q11: return ARM::D22;
2761 case ARM::Q12: return ARM::D24;
2762 case ARM::Q13: return ARM::D26;
2763 case ARM::Q14: return ARM::D28;
2764 case ARM::Q15: return ARM::D30;
2768 /// Parse a register list.
2770 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2771 assert(Parser.getTok().is(AsmToken::LCurly) &&
2772 "Token is not a Left Curly Brace");
2773 SMLoc S = Parser.getTok().getLoc();
2774 Parser.Lex(); // Eat '{' token.
2775 SMLoc RegLoc = Parser.getTok().getLoc();
2777 // Check the first register in the list to see what register class
2778 // this is a list of.
2779 int Reg = tryParseRegister();
2781 return Error(RegLoc, "register expected");
2783 // The reglist instructions have at most 16 registers, so reserve
2784 // space for that many.
2785 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2787 // Allow Q regs and just interpret them as the two D sub-registers.
2788 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2789 Reg = getDRegFromQReg(Reg);
2790 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2793 const MCRegisterClass *RC;
2794 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2795 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2796 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2797 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2798 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2799 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2801 return Error(RegLoc, "invalid register in register list");
2803 // Store the register.
2804 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2806 // This starts immediately after the first register token in the list,
2807 // so we can see either a comma or a minus (range separator) as a legal
2809 while (Parser.getTok().is(AsmToken::Comma) ||
2810 Parser.getTok().is(AsmToken::Minus)) {
2811 if (Parser.getTok().is(AsmToken::Minus)) {
2812 Parser.Lex(); // Eat the minus.
2813 SMLoc EndLoc = Parser.getTok().getLoc();
2814 int EndReg = tryParseRegister();
2816 return Error(EndLoc, "register expected");
2817 // Allow Q regs and just interpret them as the two D sub-registers.
2818 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2819 EndReg = getDRegFromQReg(EndReg) + 1;
2820 // If the register is the same as the start reg, there's nothing
2824 // The register must be in the same register class as the first.
2825 if (!RC->contains(EndReg))
2826 return Error(EndLoc, "invalid register in register list");
2827 // Ranges must go from low to high.
2828 if (getARMRegisterNumbering(Reg) > getARMRegisterNumbering(EndReg))
2829 return Error(EndLoc, "bad range in register list");
2831 // Add all the registers in the range to the register list.
2832 while (Reg != EndReg) {
2833 Reg = getNextRegister(Reg);
2834 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2838 Parser.Lex(); // Eat the comma.
2839 RegLoc = Parser.getTok().getLoc();
2841 const AsmToken RegTok = Parser.getTok();
2842 Reg = tryParseRegister();
2844 return Error(RegLoc, "register expected");
2845 // Allow Q regs and just interpret them as the two D sub-registers.
2846 bool isQReg = false;
2847 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2848 Reg = getDRegFromQReg(Reg);
2851 // The register must be in the same register class as the first.
2852 if (!RC->contains(Reg))
2853 return Error(RegLoc, "invalid register in register list");
2854 // List must be monotonically increasing.
2855 if (getARMRegisterNumbering(Reg) < getARMRegisterNumbering(OldReg))
2856 return Error(RegLoc, "register list not in ascending order");
2857 if (getARMRegisterNumbering(Reg) == getARMRegisterNumbering(OldReg)) {
2858 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2859 ") in register list");
2862 // VFP register lists must also be contiguous.
2863 // It's OK to use the enumeration values directly here rather, as the
2864 // VFP register classes have the enum sorted properly.
2865 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2867 return Error(RegLoc, "non-contiguous register range");
2868 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2870 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
2873 SMLoc E = Parser.getTok().getLoc();
2874 if (Parser.getTok().isNot(AsmToken::RCurly))
2875 return Error(E, "'}' expected");
2876 Parser.Lex(); // Eat '}' token.
2878 // Push the register list operand.
2879 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
2881 // The ARM system instruction variants for LDM/STM have a '^' token here.
2882 if (Parser.getTok().is(AsmToken::Caret)) {
2883 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2884 Parser.Lex(); // Eat '^' token.
2890 // Helper function to parse the lane index for vector lists.
2891 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2892 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2893 Index = 0; // Always return a defined index value.
2894 if (Parser.getTok().is(AsmToken::LBrac)) {
2895 Parser.Lex(); // Eat the '['.
2896 if (Parser.getTok().is(AsmToken::RBrac)) {
2897 // "Dn[]" is the 'all lanes' syntax.
2898 LaneKind = AllLanes;
2899 Parser.Lex(); // Eat the ']'.
2900 return MatchOperand_Success;
2902 const MCExpr *LaneIndex;
2903 SMLoc Loc = Parser.getTok().getLoc();
2904 if (getParser().ParseExpression(LaneIndex)) {
2905 Error(Loc, "illegal expression");
2906 return MatchOperand_ParseFail;
2908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2910 Error(Loc, "lane index must be empty or an integer");
2911 return MatchOperand_ParseFail;
2913 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2914 Error(Parser.getTok().getLoc(), "']' expected");
2915 return MatchOperand_ParseFail;
2917 Parser.Lex(); // Eat the ']'.
2918 int64_t Val = CE->getValue();
2920 // FIXME: Make this range check context sensitive for .8, .16, .32.
2921 if (Val < 0 || Val > 7) {
2922 Error(Parser.getTok().getLoc(), "lane index out of range");
2923 return MatchOperand_ParseFail;
2926 LaneKind = IndexedLane;
2927 return MatchOperand_Success;
2930 return MatchOperand_Success;
2933 // parse a vector register list
2934 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2935 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2936 VectorLaneTy LaneKind;
2938 SMLoc S = Parser.getTok().getLoc();
2939 // As an extension (to match gas), support a plain D register or Q register
2940 // (without encosing curly braces) as a single or double entry list,
2942 if (Parser.getTok().is(AsmToken::Identifier)) {
2943 int Reg = tryParseRegister();
2945 return MatchOperand_NoMatch;
2946 SMLoc E = Parser.getTok().getLoc();
2947 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
2948 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
2949 if (Res != MatchOperand_Success)
2953 E = Parser.getTok().getLoc();
2954 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
2957 E = Parser.getTok().getLoc();
2958 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
2962 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
2967 return MatchOperand_Success;
2969 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2970 Reg = getDRegFromQReg(Reg);
2971 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
2972 if (Res != MatchOperand_Success)
2976 E = Parser.getTok().getLoc();
2977 // VLD1 wants a DPair register.
2978 // FIXME: Make the rest of the two-reg instructions want the same
2980 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
2981 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
2983 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
2986 E = Parser.getTok().getLoc();
2987 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
2991 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
2996 return MatchOperand_Success;
2998 Error(S, "vector register expected");
2999 return MatchOperand_ParseFail;
3002 if (Parser.getTok().isNot(AsmToken::LCurly))
3003 return MatchOperand_NoMatch;
3005 Parser.Lex(); // Eat '{' token.
3006 SMLoc RegLoc = Parser.getTok().getLoc();
3008 int Reg = tryParseRegister();
3010 Error(RegLoc, "register expected");
3011 return MatchOperand_ParseFail;
3015 unsigned FirstReg = Reg;
3016 // The list is of D registers, but we also allow Q regs and just interpret
3017 // them as the two D sub-registers.
3018 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3019 FirstReg = Reg = getDRegFromQReg(Reg);
3020 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3021 // it's ambiguous with four-register single spaced.
3025 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
3026 return MatchOperand_ParseFail;
3028 while (Parser.getTok().is(AsmToken::Comma) ||
3029 Parser.getTok().is(AsmToken::Minus)) {
3030 if (Parser.getTok().is(AsmToken::Minus)) {
3032 Spacing = 1; // Register range implies a single spaced list.
3033 else if (Spacing == 2) {
3034 Error(Parser.getTok().getLoc(),
3035 "sequential registers in double spaced list");
3036 return MatchOperand_ParseFail;
3038 Parser.Lex(); // Eat the minus.
3039 SMLoc EndLoc = Parser.getTok().getLoc();
3040 int EndReg = tryParseRegister();
3042 Error(EndLoc, "register expected");
3043 return MatchOperand_ParseFail;
3045 // Allow Q regs and just interpret them as the two D sub-registers.
3046 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3047 EndReg = getDRegFromQReg(EndReg) + 1;
3048 // If the register is the same as the start reg, there's nothing
3052 // The register must be in the same register class as the first.
3053 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3054 Error(EndLoc, "invalid register in register list");
3055 return MatchOperand_ParseFail;
3057 // Ranges must go from low to high.
3059 Error(EndLoc, "bad range in register list");
3060 return MatchOperand_ParseFail;
3062 // Parse the lane specifier if present.
3063 VectorLaneTy NextLaneKind;
3064 unsigned NextLaneIndex;
3065 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3066 return MatchOperand_ParseFail;
3067 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3068 Error(EndLoc, "mismatched lane index in register list");
3069 return MatchOperand_ParseFail;
3071 EndLoc = Parser.getTok().getLoc();
3073 // Add all the registers in the range to the register list.
3074 Count += EndReg - Reg;
3078 Parser.Lex(); // Eat the comma.
3079 RegLoc = Parser.getTok().getLoc();
3081 Reg = tryParseRegister();
3083 Error(RegLoc, "register expected");
3084 return MatchOperand_ParseFail;
3086 // vector register lists must be contiguous.
3087 // It's OK to use the enumeration values directly here rather, as the
3088 // VFP register classes have the enum sorted properly.
3090 // The list is of D registers, but we also allow Q regs and just interpret
3091 // them as the two D sub-registers.
3092 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3094 Spacing = 1; // Register range implies a single spaced list.
3095 else if (Spacing == 2) {
3097 "invalid register in double-spaced list (must be 'D' register')");
3098 return MatchOperand_ParseFail;
3100 Reg = getDRegFromQReg(Reg);
3101 if (Reg != OldReg + 1) {
3102 Error(RegLoc, "non-contiguous register range");
3103 return MatchOperand_ParseFail;
3107 // Parse the lane specifier if present.
3108 VectorLaneTy NextLaneKind;
3109 unsigned NextLaneIndex;
3110 SMLoc EndLoc = Parser.getTok().getLoc();
3111 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3112 return MatchOperand_ParseFail;
3113 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3114 Error(EndLoc, "mismatched lane index in register list");
3115 return MatchOperand_ParseFail;
3119 // Normal D register.
3120 // Figure out the register spacing (single or double) of the list if
3121 // we don't know it already.
3123 Spacing = 1 + (Reg == OldReg + 2);
3125 // Just check that it's contiguous and keep going.
3126 if (Reg != OldReg + Spacing) {
3127 Error(RegLoc, "non-contiguous register range");
3128 return MatchOperand_ParseFail;
3131 // Parse the lane specifier if present.
3132 VectorLaneTy NextLaneKind;
3133 unsigned NextLaneIndex;
3134 SMLoc EndLoc = Parser.getTok().getLoc();
3135 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3136 return MatchOperand_ParseFail;
3137 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3138 Error(EndLoc, "mismatched lane index in register list");
3139 return MatchOperand_ParseFail;
3143 SMLoc E = Parser.getTok().getLoc();
3144 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3145 Error(E, "'}' expected");
3146 return MatchOperand_ParseFail;
3148 Parser.Lex(); // Eat '}' token.
3152 if (Count == 2 && Spacing == 1)
3153 // VLD1 wants a DPair register.
3154 // FIXME: Make the rest of the two-reg instructions want the same
3156 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0,
3157 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3160 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3161 (Spacing == 2), S, E));
3164 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3169 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3175 return MatchOperand_Success;
3178 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3179 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3180 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3181 SMLoc S = Parser.getTok().getLoc();
3182 const AsmToken &Tok = Parser.getTok();
3183 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3184 StringRef OptStr = Tok.getString();
3186 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()))
3187 .Case("sy", ARM_MB::SY)
3188 .Case("st", ARM_MB::ST)
3189 .Case("sh", ARM_MB::ISH)
3190 .Case("ish", ARM_MB::ISH)
3191 .Case("shst", ARM_MB::ISHST)
3192 .Case("ishst", ARM_MB::ISHST)
3193 .Case("nsh", ARM_MB::NSH)
3194 .Case("un", ARM_MB::NSH)
3195 .Case("nshst", ARM_MB::NSHST)
3196 .Case("unst", ARM_MB::NSHST)
3197 .Case("osh", ARM_MB::OSH)
3198 .Case("oshst", ARM_MB::OSHST)
3202 return MatchOperand_NoMatch;
3204 Parser.Lex(); // Eat identifier token.
3205 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3206 return MatchOperand_Success;
3209 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3210 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3211 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3212 SMLoc S = Parser.getTok().getLoc();
3213 const AsmToken &Tok = Parser.getTok();
3214 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3215 StringRef IFlagsStr = Tok.getString();
3217 // An iflags string of "none" is interpreted to mean that none of the AIF
3218 // bits are set. Not a terribly useful instruction, but a valid encoding.
3219 unsigned IFlags = 0;
3220 if (IFlagsStr != "none") {
3221 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3222 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3223 .Case("a", ARM_PROC::A)
3224 .Case("i", ARM_PROC::I)
3225 .Case("f", ARM_PROC::F)
3228 // If some specific iflag is already set, it means that some letter is
3229 // present more than once, this is not acceptable.
3230 if (Flag == ~0U || (IFlags & Flag))
3231 return MatchOperand_NoMatch;
3237 Parser.Lex(); // Eat identifier token.
3238 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3239 return MatchOperand_Success;
3242 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3243 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3244 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3245 SMLoc S = Parser.getTok().getLoc();
3246 const AsmToken &Tok = Parser.getTok();
3247 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3248 StringRef Mask = Tok.getString();
3251 // See ARMv6-M 10.1.1
3252 unsigned FlagsVal = StringSwitch<unsigned>(Mask)
3262 .Case("primask", 16)
3263 .Case("basepri", 17)
3264 .Case("basepri_max", 18)
3265 .Case("faultmask", 19)
3266 .Case("control", 20)
3269 if (FlagsVal == ~0U)
3270 return MatchOperand_NoMatch;
3272 if (!hasV7Ops() && FlagsVal >= 17 && FlagsVal <= 19)
3273 // basepri, basepri_max and faultmask only valid for V7m.
3274 return MatchOperand_NoMatch;
3276 Parser.Lex(); // Eat identifier token.
3277 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3278 return MatchOperand_Success;
3281 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3282 size_t Start = 0, Next = Mask.find('_');
3283 StringRef Flags = "";
3284 std::string SpecReg = Mask.slice(Start, Next).lower();
3285 if (Next != StringRef::npos)
3286 Flags = Mask.slice(Next+1, Mask.size());
3288 // FlagsVal contains the complete mask:
3290 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3291 unsigned FlagsVal = 0;
3293 if (SpecReg == "apsr") {
3294 FlagsVal = StringSwitch<unsigned>(Flags)
3295 .Case("nzcvq", 0x8) // same as CPSR_f
3296 .Case("g", 0x4) // same as CPSR_s
3297 .Case("nzcvqg", 0xc) // same as CPSR_fs
3300 if (FlagsVal == ~0U) {
3302 return MatchOperand_NoMatch;
3304 FlagsVal = 8; // No flag
3306 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3307 if (Flags == "all") // cpsr_all is an alias for cpsr_fc
3309 for (int i = 0, e = Flags.size(); i != e; ++i) {
3310 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3317 // If some specific flag is already set, it means that some letter is
3318 // present more than once, this is not acceptable.
3319 if (FlagsVal == ~0U || (FlagsVal & Flag))
3320 return MatchOperand_NoMatch;
3323 } else // No match for special register.
3324 return MatchOperand_NoMatch;
3326 // Special register without flags is NOT equivalent to "fc" flags.
3327 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3328 // two lines would enable gas compatibility at the expense of breaking
3334 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3335 if (SpecReg == "spsr")
3338 Parser.Lex(); // Eat identifier token.
3339 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3340 return MatchOperand_Success;
3343 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3344 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3345 int Low, int High) {
3346 const AsmToken &Tok = Parser.getTok();
3347 if (Tok.isNot(AsmToken::Identifier)) {
3348 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3349 return MatchOperand_ParseFail;
3351 StringRef ShiftName = Tok.getString();
3352 std::string LowerOp = Op.lower();
3353 std::string UpperOp = Op.upper();
3354 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3355 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3356 return MatchOperand_ParseFail;
3358 Parser.Lex(); // Eat shift type token.
3360 // There must be a '#' and a shift amount.
3361 if (Parser.getTok().isNot(AsmToken::Hash) &&
3362 Parser.getTok().isNot(AsmToken::Dollar)) {
3363 Error(Parser.getTok().getLoc(), "'#' expected");
3364 return MatchOperand_ParseFail;
3366 Parser.Lex(); // Eat hash token.
3368 const MCExpr *ShiftAmount;
3369 SMLoc Loc = Parser.getTok().getLoc();
3370 if (getParser().ParseExpression(ShiftAmount)) {
3371 Error(Loc, "illegal expression");
3372 return MatchOperand_ParseFail;
3374 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3376 Error(Loc, "constant expression expected");
3377 return MatchOperand_ParseFail;
3379 int Val = CE->getValue();
3380 if (Val < Low || Val > High) {
3381 Error(Loc, "immediate value out of range");
3382 return MatchOperand_ParseFail;
3385 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3387 return MatchOperand_Success;
3390 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3391 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3392 const AsmToken &Tok = Parser.getTok();
3393 SMLoc S = Tok.getLoc();
3394 if (Tok.isNot(AsmToken::Identifier)) {
3395 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3396 return MatchOperand_ParseFail;
3398 int Val = StringSwitch<int>(Tok.getString())
3402 Parser.Lex(); // Eat the token.
3405 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3406 return MatchOperand_ParseFail;
3408 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3410 S, Parser.getTok().getLoc()));
3411 return MatchOperand_Success;
3414 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3415 /// instructions. Legal values are:
3416 /// lsl #n 'n' in [0,31]
3417 /// asr #n 'n' in [1,32]
3418 /// n == 32 encoded as n == 0.
3419 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3420 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3421 const AsmToken &Tok = Parser.getTok();
3422 SMLoc S = Tok.getLoc();
3423 if (Tok.isNot(AsmToken::Identifier)) {
3424 Error(S, "shift operator 'asr' or 'lsl' expected");
3425 return MatchOperand_ParseFail;
3427 StringRef ShiftName = Tok.getString();
3429 if (ShiftName == "lsl" || ShiftName == "LSL")
3431 else if (ShiftName == "asr" || ShiftName == "ASR")
3434 Error(S, "shift operator 'asr' or 'lsl' expected");
3435 return MatchOperand_ParseFail;
3437 Parser.Lex(); // Eat the operator.
3439 // A '#' and a shift amount.
3440 if (Parser.getTok().isNot(AsmToken::Hash) &&
3441 Parser.getTok().isNot(AsmToken::Dollar)) {
3442 Error(Parser.getTok().getLoc(), "'#' expected");
3443 return MatchOperand_ParseFail;
3445 Parser.Lex(); // Eat hash token.
3447 const MCExpr *ShiftAmount;
3448 SMLoc E = Parser.getTok().getLoc();
3449 if (getParser().ParseExpression(ShiftAmount)) {
3450 Error(E, "malformed shift expression");
3451 return MatchOperand_ParseFail;
3453 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3455 Error(E, "shift amount must be an immediate");
3456 return MatchOperand_ParseFail;
3459 int64_t Val = CE->getValue();
3461 // Shift amount must be in [1,32]
3462 if (Val < 1 || Val > 32) {
3463 Error(E, "'asr' shift amount must be in range [1,32]");
3464 return MatchOperand_ParseFail;
3466 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3467 if (isThumb() && Val == 32) {
3468 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3469 return MatchOperand_ParseFail;
3471 if (Val == 32) Val = 0;
3473 // Shift amount must be in [1,32]
3474 if (Val < 0 || Val > 31) {
3475 Error(E, "'lsr' shift amount must be in range [0,31]");
3476 return MatchOperand_ParseFail;
3480 E = Parser.getTok().getLoc();
3481 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3483 return MatchOperand_Success;
3486 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3487 /// of instructions. Legal values are:
3488 /// ror #n 'n' in {0, 8, 16, 24}
3489 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3490 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3491 const AsmToken &Tok = Parser.getTok();
3492 SMLoc S = Tok.getLoc();
3493 if (Tok.isNot(AsmToken::Identifier))
3494 return MatchOperand_NoMatch;
3495 StringRef ShiftName = Tok.getString();
3496 if (ShiftName != "ror" && ShiftName != "ROR")
3497 return MatchOperand_NoMatch;
3498 Parser.Lex(); // Eat the operator.
3500 // A '#' and a rotate amount.
3501 if (Parser.getTok().isNot(AsmToken::Hash) &&
3502 Parser.getTok().isNot(AsmToken::Dollar)) {
3503 Error(Parser.getTok().getLoc(), "'#' expected");
3504 return MatchOperand_ParseFail;
3506 Parser.Lex(); // Eat hash token.
3508 const MCExpr *ShiftAmount;
3509 SMLoc E = Parser.getTok().getLoc();
3510 if (getParser().ParseExpression(ShiftAmount)) {
3511 Error(E, "malformed rotate expression");
3512 return MatchOperand_ParseFail;
3514 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3516 Error(E, "rotate amount must be an immediate");
3517 return MatchOperand_ParseFail;
3520 int64_t Val = CE->getValue();
3521 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3522 // normally, zero is represented in asm by omitting the rotate operand
3524 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3525 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3526 return MatchOperand_ParseFail;
3529 E = Parser.getTok().getLoc();
3530 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3532 return MatchOperand_Success;
3535 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3536 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3537 SMLoc S = Parser.getTok().getLoc();
3538 // The bitfield descriptor is really two operands, the LSB and the width.
3539 if (Parser.getTok().isNot(AsmToken::Hash) &&
3540 Parser.getTok().isNot(AsmToken::Dollar)) {
3541 Error(Parser.getTok().getLoc(), "'#' expected");
3542 return MatchOperand_ParseFail;
3544 Parser.Lex(); // Eat hash token.
3546 const MCExpr *LSBExpr;
3547 SMLoc E = Parser.getTok().getLoc();
3548 if (getParser().ParseExpression(LSBExpr)) {
3549 Error(E, "malformed immediate expression");
3550 return MatchOperand_ParseFail;
3552 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3554 Error(E, "'lsb' operand must be an immediate");
3555 return MatchOperand_ParseFail;
3558 int64_t LSB = CE->getValue();
3559 // The LSB must be in the range [0,31]
3560 if (LSB < 0 || LSB > 31) {
3561 Error(E, "'lsb' operand must be in the range [0,31]");
3562 return MatchOperand_ParseFail;
3564 E = Parser.getTok().getLoc();
3566 // Expect another immediate operand.
3567 if (Parser.getTok().isNot(AsmToken::Comma)) {
3568 Error(Parser.getTok().getLoc(), "too few operands");
3569 return MatchOperand_ParseFail;
3571 Parser.Lex(); // Eat hash token.
3572 if (Parser.getTok().isNot(AsmToken::Hash) &&
3573 Parser.getTok().isNot(AsmToken::Dollar)) {
3574 Error(Parser.getTok().getLoc(), "'#' expected");
3575 return MatchOperand_ParseFail;
3577 Parser.Lex(); // Eat hash token.
3579 const MCExpr *WidthExpr;
3580 if (getParser().ParseExpression(WidthExpr)) {
3581 Error(E, "malformed immediate expression");
3582 return MatchOperand_ParseFail;
3584 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3586 Error(E, "'width' operand must be an immediate");
3587 return MatchOperand_ParseFail;
3590 int64_t Width = CE->getValue();
3591 // The LSB must be in the range [1,32-lsb]
3592 if (Width < 1 || Width > 32 - LSB) {
3593 Error(E, "'width' operand must be in the range [1,32-lsb]");
3594 return MatchOperand_ParseFail;
3596 E = Parser.getTok().getLoc();
3598 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3600 return MatchOperand_Success;
3603 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3604 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3605 // Check for a post-index addressing register operand. Specifically:
3606 // postidx_reg := '+' register {, shift}
3607 // | '-' register {, shift}
3608 // | register {, shift}
3610 // This method must return MatchOperand_NoMatch without consuming any tokens
3611 // in the case where there is no match, as other alternatives take other
3613 AsmToken Tok = Parser.getTok();
3614 SMLoc S = Tok.getLoc();
3615 bool haveEaten = false;
3618 if (Tok.is(AsmToken::Plus)) {
3619 Parser.Lex(); // Eat the '+' token.
3621 } else if (Tok.is(AsmToken::Minus)) {
3622 Parser.Lex(); // Eat the '-' token.
3626 if (Parser.getTok().is(AsmToken::Identifier))
3627 Reg = tryParseRegister();
3630 return MatchOperand_NoMatch;
3631 Error(Parser.getTok().getLoc(), "register expected");
3632 return MatchOperand_ParseFail;
3634 SMLoc E = Parser.getTok().getLoc();
3636 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3637 unsigned ShiftImm = 0;
3638 if (Parser.getTok().is(AsmToken::Comma)) {
3639 Parser.Lex(); // Eat the ','.
3640 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3641 return MatchOperand_ParseFail;
3644 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3647 return MatchOperand_Success;
3650 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3651 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3652 // Check for a post-index addressing register operand. Specifically:
3653 // am3offset := '+' register
3660 // This method must return MatchOperand_NoMatch without consuming any tokens
3661 // in the case where there is no match, as other alternatives take other
3663 AsmToken Tok = Parser.getTok();
3664 SMLoc S = Tok.getLoc();
3666 // Do immediates first, as we always parse those if we have a '#'.
3667 if (Parser.getTok().is(AsmToken::Hash) ||
3668 Parser.getTok().is(AsmToken::Dollar)) {
3669 Parser.Lex(); // Eat the '#'.
3670 // Explicitly look for a '-', as we need to encode negative zero
3672 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3673 const MCExpr *Offset;
3674 if (getParser().ParseExpression(Offset))
3675 return MatchOperand_ParseFail;
3676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3678 Error(S, "constant expression expected");
3679 return MatchOperand_ParseFail;
3681 SMLoc E = Tok.getLoc();
3682 // Negative zero is encoded as the flag value INT32_MIN.
3683 int32_t Val = CE->getValue();
3684 if (isNegative && Val == 0)
3688 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3690 return MatchOperand_Success;
3694 bool haveEaten = false;
3697 if (Tok.is(AsmToken::Plus)) {
3698 Parser.Lex(); // Eat the '+' token.
3700 } else if (Tok.is(AsmToken::Minus)) {
3701 Parser.Lex(); // Eat the '-' token.
3705 if (Parser.getTok().is(AsmToken::Identifier))
3706 Reg = tryParseRegister();
3709 return MatchOperand_NoMatch;
3710 Error(Parser.getTok().getLoc(), "register expected");
3711 return MatchOperand_ParseFail;
3713 SMLoc E = Parser.getTok().getLoc();
3715 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3718 return MatchOperand_Success;
3721 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
3722 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3723 /// when they refer multiple MIOperands inside a single one.
3725 cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
3726 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3728 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3729 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3730 // Create a writeback register dummy placeholder.
3731 Inst.addOperand(MCOperand::CreateReg(0));
3733 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3735 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3739 /// cvtT2StrdPre - Convert parsed operands to MCInst.
3740 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3741 /// when they refer multiple MIOperands inside a single one.
3743 cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
3744 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3745 // Create a writeback register dummy placeholder.
3746 Inst.addOperand(MCOperand::CreateReg(0));
3748 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3749 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3751 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3753 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3757 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3758 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3759 /// when they refer multiple MIOperands inside a single one.
3761 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3762 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3763 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3765 // Create a writeback register dummy placeholder.
3766 Inst.addOperand(MCOperand::CreateImm(0));
3768 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3769 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3773 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3774 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3775 /// when they refer multiple MIOperands inside a single one.
3777 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3778 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3779 // Create a writeback register dummy placeholder.
3780 Inst.addOperand(MCOperand::CreateImm(0));
3781 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3782 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3783 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3787 /// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3788 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3789 /// when they refer multiple MIOperands inside a single one.
3791 cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
3792 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3793 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3795 // Create a writeback register dummy placeholder.
3796 Inst.addOperand(MCOperand::CreateImm(0));
3798 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3799 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3803 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3804 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3805 /// when they refer multiple MIOperands inside a single one.
3807 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3808 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3809 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3811 // Create a writeback register dummy placeholder.
3812 Inst.addOperand(MCOperand::CreateImm(0));
3814 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3815 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3820 /// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3821 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3822 /// when they refer multiple MIOperands inside a single one.
3824 cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3825 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3826 // Create a writeback register dummy placeholder.
3827 Inst.addOperand(MCOperand::CreateImm(0));
3828 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3829 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3830 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3834 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3835 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3836 /// when they refer multiple MIOperands inside a single one.
3838 cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
3839 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3840 // Create a writeback register dummy placeholder.
3841 Inst.addOperand(MCOperand::CreateImm(0));
3842 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3843 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3844 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3848 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3849 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3850 /// when they refer multiple MIOperands inside a single one.
3852 cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3853 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3854 // Create a writeback register dummy placeholder.
3855 Inst.addOperand(MCOperand::CreateImm(0));
3856 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3857 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3858 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3862 /// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
3863 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3864 /// when they refer multiple MIOperands inside a single one.
3866 cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3867 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3869 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3870 // Create a writeback register dummy placeholder.
3871 Inst.addOperand(MCOperand::CreateImm(0));
3873 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3875 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3877 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3881 /// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
3882 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3883 /// when they refer multiple MIOperands inside a single one.
3885 cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3886 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3888 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3889 // Create a writeback register dummy placeholder.
3890 Inst.addOperand(MCOperand::CreateImm(0));
3892 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3894 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3896 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3900 /// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
3901 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3902 /// when they refer multiple MIOperands inside a single one.
3904 cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3905 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3906 // Create a writeback register dummy placeholder.
3907 Inst.addOperand(MCOperand::CreateImm(0));
3909 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3911 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3913 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3915 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3919 /// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
3920 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3921 /// when they refer multiple MIOperands inside a single one.
3923 cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3924 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3925 // Create a writeback register dummy placeholder.
3926 Inst.addOperand(MCOperand::CreateImm(0));
3928 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3930 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3932 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3934 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3938 /// cvtLdrdPre - Convert parsed operands to MCInst.
3939 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3940 /// when they refer multiple MIOperands inside a single one.
3942 cvtLdrdPre(MCInst &Inst, unsigned Opcode,
3943 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3945 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3946 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3947 // Create a writeback register dummy placeholder.
3948 Inst.addOperand(MCOperand::CreateImm(0));
3950 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3952 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3956 /// cvtStrdPre - Convert parsed operands to MCInst.
3957 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3958 /// when they refer multiple MIOperands inside a single one.
3960 cvtStrdPre(MCInst &Inst, unsigned Opcode,
3961 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3962 // Create a writeback register dummy placeholder.
3963 Inst.addOperand(MCOperand::CreateImm(0));
3965 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3966 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3968 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3970 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3974 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3975 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3976 /// when they refer multiple MIOperands inside a single one.
3978 cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3979 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3980 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3981 // Create a writeback register dummy placeholder.
3982 Inst.addOperand(MCOperand::CreateImm(0));
3983 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3984 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3988 /// cvtThumbMultiple- Convert parsed operands to MCInst.
3989 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3990 /// when they refer multiple MIOperands inside a single one.
3992 cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
3993 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3994 // The second source operand must be the same register as the destination
3996 if (Operands.size() == 6 &&
3997 (((ARMOperand*)Operands[3])->getReg() !=
3998 ((ARMOperand*)Operands[5])->getReg()) &&
3999 (((ARMOperand*)Operands[3])->getReg() !=
4000 ((ARMOperand*)Operands[4])->getReg())) {
4001 Error(Operands[3]->getStartLoc(),
4002 "destination register must match source register");
4005 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4006 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4007 // If we have a three-operand form, make sure to set Rn to be the operand
4008 // that isn't the same as Rd.
4010 if (Operands.size() == 6 &&
4011 ((ARMOperand*)Operands[4])->getReg() ==
4012 ((ARMOperand*)Operands[3])->getReg())
4014 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4015 Inst.addOperand(Inst.getOperand(0));
4016 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4022 cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
4023 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4025 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4026 // Create a writeback register dummy placeholder.
4027 Inst.addOperand(MCOperand::CreateImm(0));
4029 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4031 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4036 cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
4037 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4039 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4040 // Create a writeback register dummy placeholder.
4041 Inst.addOperand(MCOperand::CreateImm(0));
4043 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4045 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4047 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4052 cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
4053 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4054 // Create a writeback register dummy placeholder.
4055 Inst.addOperand(MCOperand::CreateImm(0));
4057 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4059 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4061 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4066 cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
4067 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4068 // Create a writeback register dummy placeholder.
4069 Inst.addOperand(MCOperand::CreateImm(0));
4071 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4073 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4075 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4077 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4081 /// Parse an ARM memory expression, return false if successful else return true
4082 /// or an error. The first token must be a '[' when called.
4084 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4086 assert(Parser.getTok().is(AsmToken::LBrac) &&
4087 "Token is not a Left Bracket");
4088 S = Parser.getTok().getLoc();
4089 Parser.Lex(); // Eat left bracket token.
4091 const AsmToken &BaseRegTok = Parser.getTok();
4092 int BaseRegNum = tryParseRegister();
4093 if (BaseRegNum == -1)
4094 return Error(BaseRegTok.getLoc(), "register expected");
4096 // The next token must either be a comma or a closing bracket.
4097 const AsmToken &Tok = Parser.getTok();
4098 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
4099 return Error(Tok.getLoc(), "malformed memory operand");
4101 if (Tok.is(AsmToken::RBrac)) {
4103 Parser.Lex(); // Eat right bracket token.
4105 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4106 0, 0, false, S, E));
4108 // If there's a pre-indexing writeback marker, '!', just add it as a token
4109 // operand. It's rather odd, but syntactically valid.
4110 if (Parser.getTok().is(AsmToken::Exclaim)) {
4111 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4112 Parser.Lex(); // Eat the '!'.
4118 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4119 Parser.Lex(); // Eat the comma.
4121 // If we have a ':', it's an alignment specifier.
4122 if (Parser.getTok().is(AsmToken::Colon)) {
4123 Parser.Lex(); // Eat the ':'.
4124 E = Parser.getTok().getLoc();
4127 if (getParser().ParseExpression(Expr))
4130 // The expression has to be a constant. Memory references with relocations
4131 // don't come through here, as they use the <label> forms of the relevant
4133 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4135 return Error (E, "constant expression expected");
4138 switch (CE->getValue()) {
4141 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4142 case 16: Align = 2; break;
4143 case 32: Align = 4; break;
4144 case 64: Align = 8; break;
4145 case 128: Align = 16; break;
4146 case 256: Align = 32; break;
4149 // Now we should have the closing ']'
4150 E = Parser.getTok().getLoc();
4151 if (Parser.getTok().isNot(AsmToken::RBrac))
4152 return Error(E, "']' expected");
4153 Parser.Lex(); // Eat right bracket token.
4155 // Don't worry about range checking the value here. That's handled by
4156 // the is*() predicates.
4157 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4158 ARM_AM::no_shift, 0, Align,
4161 // If there's a pre-indexing writeback marker, '!', just add it as a token
4163 if (Parser.getTok().is(AsmToken::Exclaim)) {
4164 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4165 Parser.Lex(); // Eat the '!'.
4171 // If we have a '#', it's an immediate offset, else assume it's a register
4172 // offset. Be friendly and also accept a plain integer (without a leading
4173 // hash) for gas compatibility.
4174 if (Parser.getTok().is(AsmToken::Hash) ||
4175 Parser.getTok().is(AsmToken::Dollar) ||
4176 Parser.getTok().is(AsmToken::Integer)) {
4177 if (Parser.getTok().isNot(AsmToken::Integer))
4178 Parser.Lex(); // Eat the '#'.
4179 E = Parser.getTok().getLoc();
4181 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4182 const MCExpr *Offset;
4183 if (getParser().ParseExpression(Offset))
4186 // The expression has to be a constant. Memory references with relocations
4187 // don't come through here, as they use the <label> forms of the relevant
4189 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4191 return Error (E, "constant expression expected");
4193 // If the constant was #-0, represent it as INT32_MIN.
4194 int32_t Val = CE->getValue();
4195 if (isNegative && Val == 0)
4196 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4198 // Now we should have the closing ']'
4199 E = Parser.getTok().getLoc();
4200 if (Parser.getTok().isNot(AsmToken::RBrac))
4201 return Error(E, "']' expected");
4202 Parser.Lex(); // Eat right bracket token.
4204 // Don't worry about range checking the value here. That's handled by
4205 // the is*() predicates.
4206 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4207 ARM_AM::no_shift, 0, 0,
4210 // If there's a pre-indexing writeback marker, '!', just add it as a token
4212 if (Parser.getTok().is(AsmToken::Exclaim)) {
4213 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4214 Parser.Lex(); // Eat the '!'.
4220 // The register offset is optionally preceded by a '+' or '-'
4221 bool isNegative = false;
4222 if (Parser.getTok().is(AsmToken::Minus)) {
4224 Parser.Lex(); // Eat the '-'.
4225 } else if (Parser.getTok().is(AsmToken::Plus)) {
4227 Parser.Lex(); // Eat the '+'.
4230 E = Parser.getTok().getLoc();
4231 int OffsetRegNum = tryParseRegister();
4232 if (OffsetRegNum == -1)
4233 return Error(E, "register expected");
4235 // If there's a shift operator, handle it.
4236 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4237 unsigned ShiftImm = 0;
4238 if (Parser.getTok().is(AsmToken::Comma)) {
4239 Parser.Lex(); // Eat the ','.
4240 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4244 // Now we should have the closing ']'
4245 E = Parser.getTok().getLoc();
4246 if (Parser.getTok().isNot(AsmToken::RBrac))
4247 return Error(E, "']' expected");
4248 Parser.Lex(); // Eat right bracket token.
4250 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4251 ShiftType, ShiftImm, 0, isNegative,
4254 // If there's a pre-indexing writeback marker, '!', just add it as a token
4256 if (Parser.getTok().is(AsmToken::Exclaim)) {
4257 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4258 Parser.Lex(); // Eat the '!'.
4264 /// parseMemRegOffsetShift - one of these two:
4265 /// ( lsl | lsr | asr | ror ) , # shift_amount
4267 /// return true if it parses a shift otherwise it returns false.
4268 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4270 SMLoc Loc = Parser.getTok().getLoc();
4271 const AsmToken &Tok = Parser.getTok();
4272 if (Tok.isNot(AsmToken::Identifier))
4274 StringRef ShiftName = Tok.getString();
4275 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4276 ShiftName == "asl" || ShiftName == "ASL")
4278 else if (ShiftName == "lsr" || ShiftName == "LSR")
4280 else if (ShiftName == "asr" || ShiftName == "ASR")
4282 else if (ShiftName == "ror" || ShiftName == "ROR")
4284 else if (ShiftName == "rrx" || ShiftName == "RRX")
4287 return Error(Loc, "illegal shift operator");
4288 Parser.Lex(); // Eat shift type token.
4290 // rrx stands alone.
4292 if (St != ARM_AM::rrx) {
4293 Loc = Parser.getTok().getLoc();
4294 // A '#' and a shift amount.
4295 const AsmToken &HashTok = Parser.getTok();
4296 if (HashTok.isNot(AsmToken::Hash) &&
4297 HashTok.isNot(AsmToken::Dollar))
4298 return Error(HashTok.getLoc(), "'#' expected");
4299 Parser.Lex(); // Eat hash token.
4302 if (getParser().ParseExpression(Expr))
4304 // Range check the immediate.
4305 // lsl, ror: 0 <= imm <= 31
4306 // lsr, asr: 0 <= imm <= 32
4307 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4309 return Error(Loc, "shift amount must be an immediate");
4310 int64_t Imm = CE->getValue();
4312 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4313 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4314 return Error(Loc, "immediate shift value out of range");
4321 /// parseFPImm - A floating point immediate expression operand.
4322 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4323 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4324 // Anything that can accept a floating point constant as an operand
4325 // needs to go through here, as the regular ParseExpression is
4328 // This routine still creates a generic Immediate operand, containing
4329 // a bitcast of the 64-bit floating point value. The various operands
4330 // that accept floats can check whether the value is valid for them
4331 // via the standard is*() predicates.
4333 SMLoc S = Parser.getTok().getLoc();
4335 if (Parser.getTok().isNot(AsmToken::Hash) &&
4336 Parser.getTok().isNot(AsmToken::Dollar))
4337 return MatchOperand_NoMatch;
4339 // Disambiguate the VMOV forms that can accept an FP immediate.
4340 // vmov.f32 <sreg>, #imm
4341 // vmov.f64 <dreg>, #imm
4342 // vmov.f32 <dreg>, #imm @ vector f32x2
4343 // vmov.f32 <qreg>, #imm @ vector f32x4
4345 // There are also the NEON VMOV instructions which expect an
4346 // integer constant. Make sure we don't try to parse an FPImm
4348 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4349 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4350 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4351 TyOp->getToken() != ".f64"))
4352 return MatchOperand_NoMatch;
4354 Parser.Lex(); // Eat the '#'.
4356 // Handle negation, as that still comes through as a separate token.
4357 bool isNegative = false;
4358 if (Parser.getTok().is(AsmToken::Minus)) {
4362 const AsmToken &Tok = Parser.getTok();
4363 SMLoc Loc = Tok.getLoc();
4364 if (Tok.is(AsmToken::Real)) {
4365 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4366 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4367 // If we had a '-' in front, toggle the sign bit.
4368 IntVal ^= (uint64_t)isNegative << 31;
4369 Parser.Lex(); // Eat the token.
4370 Operands.push_back(ARMOperand::CreateImm(
4371 MCConstantExpr::Create(IntVal, getContext()),
4372 S, Parser.getTok().getLoc()));
4373 return MatchOperand_Success;
4375 // Also handle plain integers. Instructions which allow floating point
4376 // immediates also allow a raw encoded 8-bit value.
4377 if (Tok.is(AsmToken::Integer)) {
4378 int64_t Val = Tok.getIntVal();
4379 Parser.Lex(); // Eat the token.
4380 if (Val > 255 || Val < 0) {
4381 Error(Loc, "encoded floating point value out of range");
4382 return MatchOperand_ParseFail;
4384 double RealVal = ARM_AM::getFPImmFloat(Val);
4385 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4386 Operands.push_back(ARMOperand::CreateImm(
4387 MCConstantExpr::Create(Val, getContext()), S,
4388 Parser.getTok().getLoc()));
4389 return MatchOperand_Success;
4392 Error(Loc, "invalid floating point immediate");
4393 return MatchOperand_ParseFail;
4396 /// Parse a arm instruction operand. For now this parses the operand regardless
4397 /// of the mnemonic.
4398 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4399 StringRef Mnemonic) {
4402 // Check if the current operand has a custom associated parser, if so, try to
4403 // custom parse the operand, or fallback to the general approach.
4404 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4405 if (ResTy == MatchOperand_Success)
4407 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4408 // there was a match, but an error occurred, in which case, just return that
4409 // the operand parsing failed.
4410 if (ResTy == MatchOperand_ParseFail)
4413 switch (getLexer().getKind()) {
4415 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4417 case AsmToken::Identifier: {
4418 if (!tryParseRegisterWithWriteBack(Operands))
4420 int Res = tryParseShiftRegister(Operands);
4421 if (Res == 0) // success
4423 else if (Res == -1) // irrecoverable error
4425 // If this is VMRS, check for the apsr_nzcv operand.
4426 if (Mnemonic == "vmrs" && Parser.getTok().getString() == "apsr_nzcv") {
4427 S = Parser.getTok().getLoc();
4429 Operands.push_back(ARMOperand::CreateToken("apsr_nzcv", S));
4433 // Fall though for the Identifier case that is not a register or a
4436 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4437 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4438 case AsmToken::String: // quoted label names.
4439 case AsmToken::Dot: { // . as a branch target
4440 // This was not a register so parse other operands that start with an
4441 // identifier (like labels) as expressions and create them as immediates.
4442 const MCExpr *IdVal;
4443 S = Parser.getTok().getLoc();
4444 if (getParser().ParseExpression(IdVal))
4446 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4447 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4450 case AsmToken::LBrac:
4451 return parseMemory(Operands);
4452 case AsmToken::LCurly:
4453 return parseRegisterList(Operands);
4454 case AsmToken::Dollar:
4455 case AsmToken::Hash: {
4456 // #42 -> immediate.
4457 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
4458 S = Parser.getTok().getLoc();
4460 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4461 const MCExpr *ImmVal;
4462 if (getParser().ParseExpression(ImmVal))
4464 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4466 int32_t Val = CE->getValue();
4467 if (isNegative && Val == 0)
4468 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4470 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4471 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4474 case AsmToken::Colon: {
4475 // ":lower16:" and ":upper16:" expression prefixes
4476 // FIXME: Check it's an expression prefix,
4477 // e.g. (FOO - :lower16:BAR) isn't legal.
4478 ARMMCExpr::VariantKind RefKind;
4479 if (parsePrefix(RefKind))
4482 const MCExpr *SubExprVal;
4483 if (getParser().ParseExpression(SubExprVal))
4486 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4488 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4489 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4495 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4496 // :lower16: and :upper16:.
4497 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4498 RefKind = ARMMCExpr::VK_ARM_None;
4500 // :lower16: and :upper16: modifiers
4501 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4502 Parser.Lex(); // Eat ':'
4504 if (getLexer().isNot(AsmToken::Identifier)) {
4505 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4509 StringRef IDVal = Parser.getTok().getIdentifier();
4510 if (IDVal == "lower16") {
4511 RefKind = ARMMCExpr::VK_ARM_LO16;
4512 } else if (IDVal == "upper16") {
4513 RefKind = ARMMCExpr::VK_ARM_HI16;
4515 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4520 if (getLexer().isNot(AsmToken::Colon)) {
4521 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4524 Parser.Lex(); // Eat the last ':'
4528 /// \brief Given a mnemonic, split out possible predication code and carry
4529 /// setting letters to form a canonical mnemonic and flags.
4531 // FIXME: Would be nice to autogen this.
4532 // FIXME: This is a bit of a maze of special cases.
4533 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4534 unsigned &PredicationCode,
4536 unsigned &ProcessorIMod,
4537 StringRef &ITMask) {
4538 PredicationCode = ARMCC::AL;
4539 CarrySetting = false;
4542 // Ignore some mnemonics we know aren't predicated forms.
4544 // FIXME: Would be nice to autogen this.
4545 if ((Mnemonic == "movs" && isThumb()) ||
4546 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4547 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4548 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4549 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4550 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4551 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4552 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4553 Mnemonic == "fmuls")
4556 // First, split out any predication code. Ignore mnemonics we know aren't
4557 // predicated but do have a carry-set and so weren't caught above.
4558 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4559 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4560 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4561 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4562 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4563 .Case("eq", ARMCC::EQ)
4564 .Case("ne", ARMCC::NE)
4565 .Case("hs", ARMCC::HS)
4566 .Case("cs", ARMCC::HS)
4567 .Case("lo", ARMCC::LO)
4568 .Case("cc", ARMCC::LO)
4569 .Case("mi", ARMCC::MI)
4570 .Case("pl", ARMCC::PL)
4571 .Case("vs", ARMCC::VS)
4572 .Case("vc", ARMCC::VC)
4573 .Case("hi", ARMCC::HI)
4574 .Case("ls", ARMCC::LS)
4575 .Case("ge", ARMCC::GE)
4576 .Case("lt", ARMCC::LT)
4577 .Case("gt", ARMCC::GT)
4578 .Case("le", ARMCC::LE)
4579 .Case("al", ARMCC::AL)
4582 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4583 PredicationCode = CC;
4587 // Next, determine if we have a carry setting bit. We explicitly ignore all
4588 // the instructions we know end in 's'.
4589 if (Mnemonic.endswith("s") &&
4590 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4591 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4592 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4593 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4594 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4595 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4596 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4597 Mnemonic == "fmuls" || Mnemonic == "fcmps" ||
4598 (Mnemonic == "movs" && isThumb()))) {
4599 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4600 CarrySetting = true;
4603 // The "cps" instruction can have a interrupt mode operand which is glued into
4604 // the mnemonic. Check if this is the case, split it and parse the imod op
4605 if (Mnemonic.startswith("cps")) {
4606 // Split out any imod code.
4608 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4609 .Case("ie", ARM_PROC::IE)
4610 .Case("id", ARM_PROC::ID)
4613 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4614 ProcessorIMod = IMod;
4618 // The "it" instruction has the condition mask on the end of the mnemonic.
4619 if (Mnemonic.startswith("it")) {
4620 ITMask = Mnemonic.slice(2, Mnemonic.size());
4621 Mnemonic = Mnemonic.slice(0, 2);
4627 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4628 /// inclusion of carry set or predication code operands.
4630 // FIXME: It would be nice to autogen this.
4632 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4633 bool &CanAcceptPredicationCode) {
4634 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4635 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4636 Mnemonic == "add" || Mnemonic == "adc" ||
4637 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4638 Mnemonic == "orr" || Mnemonic == "mvn" ||
4639 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4640 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4641 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4642 Mnemonic == "mla" || Mnemonic == "smlal" ||
4643 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4644 CanAcceptCarrySet = true;
4646 CanAcceptCarrySet = false;
4648 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4649 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4650 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4651 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
4652 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4653 (Mnemonic == "clrex" && !isThumb()) ||
4654 (Mnemonic == "nop" && isThumbOne()) ||
4655 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4656 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4657 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
4658 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4660 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
4661 CanAcceptPredicationCode = false;
4663 CanAcceptPredicationCode = true;
4666 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
4667 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
4668 CanAcceptPredicationCode = false;
4672 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4673 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4674 // FIXME: This is all horribly hacky. We really need a better way to deal
4675 // with optional operands like this in the matcher table.
4677 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4678 // another does not. Specifically, the MOVW instruction does not. So we
4679 // special case it here and remove the defaulted (non-setting) cc_out
4680 // operand if that's the instruction we're trying to match.
4682 // We do this as post-processing of the explicit operands rather than just
4683 // conditionally adding the cc_out in the first place because we need
4684 // to check the type of the parsed immediate operand.
4685 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4686 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4687 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4688 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4691 // Register-register 'add' for thumb does not have a cc_out operand
4692 // when there are only two register operands.
4693 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4694 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4695 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4696 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4698 // Register-register 'add' for thumb does not have a cc_out operand
4699 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4700 // have to check the immediate range here since Thumb2 has a variant
4701 // that can handle a different range and has a cc_out operand.
4702 if (((isThumb() && Mnemonic == "add") ||
4703 (isThumbTwo() && Mnemonic == "sub")) &&
4704 Operands.size() == 6 &&
4705 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4706 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4707 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4708 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4709 (static_cast<ARMOperand*>(Operands[5])->isReg() ||
4710 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4712 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4713 // imm0_4095 variant. That's the least-preferred variant when
4714 // selecting via the generic "add" mnemonic, so to know that we
4715 // should remove the cc_out operand, we have to explicitly check that
4716 // it's not one of the other variants. Ugh.
4717 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4718 Operands.size() == 6 &&
4719 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4720 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4721 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4722 // Nest conditions rather than one big 'if' statement for readability.
4724 // If either register is a high reg, it's either one of the SP
4725 // variants (handled above) or a 32-bit encoding, so we just
4726 // check against T3. If the second register is the PC, this is an
4727 // alternate form of ADR, which uses encoding T4, so check for that too.
4728 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4729 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
4730 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4731 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4733 // If both registers are low, we're in an IT block, and the immediate is
4734 // in range, we should use encoding T1 instead, which has a cc_out.
4736 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4737 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4738 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4741 // Otherwise, we use encoding T4, which does not have a cc_out
4746 // The thumb2 multiply instruction doesn't have a CCOut register, so
4747 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4748 // use the 16-bit encoding or not.
4749 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4750 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4751 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4752 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4753 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4754 // If the registers aren't low regs, the destination reg isn't the
4755 // same as one of the source regs, or the cc_out operand is zero
4756 // outside of an IT block, we have to use the 32-bit encoding, so
4757 // remove the cc_out operand.
4758 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4759 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4760 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4762 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4763 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4764 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4765 static_cast<ARMOperand*>(Operands[4])->getReg())))
4768 // Also check the 'mul' syntax variant that doesn't specify an explicit
4769 // destination register.
4770 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4771 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4772 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4773 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4774 // If the registers aren't low regs or the cc_out operand is zero
4775 // outside of an IT block, we have to use the 32-bit encoding, so
4776 // remove the cc_out operand.
4777 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4778 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4784 // Register-register 'add/sub' for thumb does not have a cc_out operand
4785 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4786 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4787 // right, this will result in better diagnostics (which operand is off)
4789 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4790 (Operands.size() == 5 || Operands.size() == 6) &&
4791 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4792 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4793 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4799 static bool isDataTypeToken(StringRef Tok) {
4800 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4801 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4802 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4803 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4804 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4805 Tok == ".f" || Tok == ".d";
4808 // FIXME: This bit should probably be handled via an explicit match class
4809 // in the .td files that matches the suffix instead of having it be
4810 // a literal string token the way it is now.
4811 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4812 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4815 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
4816 /// Parse an arm instruction mnemonic followed by its operands.
4817 bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4818 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4819 // Apply mnemonic aliases before doing anything else, as the destination
4820 // mnemnonic may include suffices and we want to handle them normally.
4821 // The generic tblgen'erated code does this later, at the start of
4822 // MatchInstructionImpl(), but that's too late for aliases that include
4823 // any sort of suffix.
4824 unsigned AvailableFeatures = getAvailableFeatures();
4825 applyMnemonicAliases(Name, AvailableFeatures);
4827 // First check for the ARM-specific .req directive.
4828 if (Parser.getTok().is(AsmToken::Identifier) &&
4829 Parser.getTok().getIdentifier() == ".req") {
4830 parseDirectiveReq(Name, NameLoc);
4831 // We always return 'error' for this, as we're done with this
4832 // statement and don't need to match the 'instruction."
4836 // Create the leading tokens for the mnemonic, split by '.' characters.
4837 size_t Start = 0, Next = Name.find('.');
4838 StringRef Mnemonic = Name.slice(Start, Next);
4840 // Split out the predication code and carry setting flag from the mnemonic.
4841 unsigned PredicationCode;
4842 unsigned ProcessorIMod;
4845 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
4846 ProcessorIMod, ITMask);
4848 // In Thumb1, only the branch (B) instruction can be predicated.
4849 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4850 Parser.EatToEndOfStatement();
4851 return Error(NameLoc, "conditional execution not supported in Thumb1");
4854 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4856 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4857 // is the mask as it will be for the IT encoding if the conditional
4858 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4859 // where the conditional bit0 is zero, the instruction post-processing
4860 // will adjust the mask accordingly.
4861 if (Mnemonic == "it") {
4862 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4863 if (ITMask.size() > 3) {
4864 Parser.EatToEndOfStatement();
4865 return Error(Loc, "too many conditions on IT instruction");
4868 for (unsigned i = ITMask.size(); i != 0; --i) {
4869 char pos = ITMask[i - 1];
4870 if (pos != 't' && pos != 'e') {
4871 Parser.EatToEndOfStatement();
4872 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
4875 if (ITMask[i - 1] == 't')
4878 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
4881 // FIXME: This is all a pretty gross hack. We should automatically handle
4882 // optional operands like this via tblgen.
4884 // Next, add the CCOut and ConditionCode operands, if needed.
4886 // For mnemonics which can ever incorporate a carry setting bit or predication
4887 // code, our matching model involves us always generating CCOut and
4888 // ConditionCode operands to match the mnemonic "as written" and then we let
4889 // the matcher deal with finding the right instruction or generating an
4890 // appropriate error.
4891 bool CanAcceptCarrySet, CanAcceptPredicationCode;
4892 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
4894 // If we had a carry-set on an instruction that can't do that, issue an
4896 if (!CanAcceptCarrySet && CarrySetting) {
4897 Parser.EatToEndOfStatement();
4898 return Error(NameLoc, "instruction '" + Mnemonic +
4899 "' can not set flags, but 's' suffix specified");
4901 // If we had a predication code on an instruction that can't do that, issue an
4903 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
4904 Parser.EatToEndOfStatement();
4905 return Error(NameLoc, "instruction '" + Mnemonic +
4906 "' is not predicable, but condition code specified");
4909 // Add the carry setting operand, if necessary.
4910 if (CanAcceptCarrySet) {
4911 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
4912 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
4916 // Add the predication code operand, if necessary.
4917 if (CanAcceptPredicationCode) {
4918 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
4920 Operands.push_back(ARMOperand::CreateCondCode(
4921 ARMCC::CondCodes(PredicationCode), Loc));
4924 // Add the processor imod operand, if necessary.
4925 if (ProcessorIMod) {
4926 Operands.push_back(ARMOperand::CreateImm(
4927 MCConstantExpr::Create(ProcessorIMod, getContext()),
4931 // Add the remaining tokens in the mnemonic.
4932 while (Next != StringRef::npos) {
4934 Next = Name.find('.', Start + 1);
4935 StringRef ExtraToken = Name.slice(Start, Next);
4937 // Some NEON instructions have an optional datatype suffix that is
4938 // completely ignored. Check for that.
4939 if (isDataTypeToken(ExtraToken) &&
4940 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
4943 if (ExtraToken != ".n") {
4944 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
4945 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
4949 // Read the remaining operands.
4950 if (getLexer().isNot(AsmToken::EndOfStatement)) {
4951 // Read the first operand.
4952 if (parseOperand(Operands, Mnemonic)) {
4953 Parser.EatToEndOfStatement();
4957 while (getLexer().is(AsmToken::Comma)) {
4958 Parser.Lex(); // Eat the comma.
4960 // Parse and remember the operand.
4961 if (parseOperand(Operands, Mnemonic)) {
4962 Parser.EatToEndOfStatement();
4968 if (getLexer().isNot(AsmToken::EndOfStatement)) {
4969 SMLoc Loc = getLexer().getLoc();
4970 Parser.EatToEndOfStatement();
4971 return Error(Loc, "unexpected token in argument list");
4974 Parser.Lex(); // Consume the EndOfStatement
4976 // Some instructions, mostly Thumb, have forms for the same mnemonic that
4977 // do and don't have a cc_out optional-def operand. With some spot-checks
4978 // of the operand list, we can figure out which variant we're trying to
4979 // parse and adjust accordingly before actually matching. We shouldn't ever
4980 // try to remove a cc_out operand that was explicitly set on the the
4981 // mnemonic, of course (CarrySetting == true). Reason number #317 the
4982 // table driven matcher doesn't fit well with the ARM instruction set.
4983 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
4984 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
4985 Operands.erase(Operands.begin() + 1);
4989 // ARM mode 'blx' need special handling, as the register operand version
4990 // is predicable, but the label operand version is not. So, we can't rely
4991 // on the Mnemonic based checking to correctly figure out when to put
4992 // a k_CondCode operand in the list. If we're trying to match the label
4993 // version, remove the k_CondCode operand here.
4994 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
4995 static_cast<ARMOperand*>(Operands[2])->isImm()) {
4996 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
4997 Operands.erase(Operands.begin() + 1);
5001 // The vector-compare-to-zero instructions have a literal token "#0" at
5002 // the end that comes to here as an immediate operand. Convert it to a
5003 // token to play nicely with the matcher.
5004 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5005 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5006 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5007 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5008 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5009 if (CE && CE->getValue() == 0) {
5010 Operands.erase(Operands.begin() + 5);
5011 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5015 // VCMP{E} does the same thing, but with a different operand count.
5016 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5017 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5018 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5019 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5020 if (CE && CE->getValue() == 0) {
5021 Operands.erase(Operands.begin() + 4);
5022 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5026 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
5027 // end. Convert it to a token here. Take care not to convert those
5028 // that should hit the Thumb2 encoding.
5029 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
5030 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5031 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5032 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5033 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5034 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5035 if (CE && CE->getValue() == 0 &&
5037 // The cc_out operand matches the IT block.
5038 ((inITBlock() != CarrySetting) &&
5039 // Neither register operand is a high register.
5040 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5041 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
5042 Operands.erase(Operands.begin() + 5);
5043 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5051 // Validate context-sensitive operand constraints.
5053 // return 'true' if register list contains non-low GPR registers,
5054 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5055 // 'containsReg' to true.
5056 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5057 unsigned HiReg, bool &containsReg) {
5058 containsReg = false;
5059 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5060 unsigned OpReg = Inst.getOperand(i).getReg();
5063 // Anything other than a low register isn't legal here.
5064 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5070 // Check if the specified regisgter is in the register list of the inst,
5071 // starting at the indicated operand number.
5072 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5073 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5074 unsigned OpReg = Inst.getOperand(i).getReg();
5081 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5082 // the ARMInsts array) instead. Getting that here requires awkward
5083 // API changes, though. Better way?
5085 extern const MCInstrDesc ARMInsts[];
5087 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5088 return ARMInsts[Opcode];
5091 // FIXME: We would really like to be able to tablegen'erate this.
5093 validateInstruction(MCInst &Inst,
5094 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5095 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5096 SMLoc Loc = Operands[0]->getStartLoc();
5097 // Check the IT block state first.
5098 // NOTE: BKPT instruction has the interesting property of being
5099 // allowed in IT blocks, but not being predicable. It just always
5101 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5102 Inst.getOpcode() != ARM::BKPT) {
5104 if (ITState.FirstCond)
5105 ITState.FirstCond = false;
5107 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5108 // The instruction must be predicable.
5109 if (!MCID.isPredicable())
5110 return Error(Loc, "instructions in IT block must be predicable");
5111 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5112 unsigned ITCond = bit ? ITState.Cond :
5113 ARMCC::getOppositeCondition(ITState.Cond);
5114 if (Cond != ITCond) {
5115 // Find the condition code Operand to get its SMLoc information.
5117 for (unsigned i = 1; i < Operands.size(); ++i)
5118 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5119 CondLoc = Operands[i]->getStartLoc();
5120 return Error(CondLoc, "incorrect condition in IT block; got '" +
5121 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5122 "', but expected '" +
5123 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5125 // Check for non-'al' condition codes outside of the IT block.
5126 } else if (isThumbTwo() && MCID.isPredicable() &&
5127 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5128 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5129 Inst.getOpcode() != ARM::t2B)
5130 return Error(Loc, "predicated instructions must be in IT block");
5132 switch (Inst.getOpcode()) {
5135 case ARM::LDRD_POST:
5137 // Rt2 must be Rt + 1.
5138 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5139 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5141 return Error(Operands[3]->getStartLoc(),
5142 "destination operands must be sequential");
5146 // Rt2 must be Rt + 1.
5147 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5148 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5150 return Error(Operands[3]->getStartLoc(),
5151 "source operands must be sequential");
5155 case ARM::STRD_POST:
5157 // Rt2 must be Rt + 1.
5158 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5159 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(2).getReg());
5161 return Error(Operands[3]->getStartLoc(),
5162 "source operands must be sequential");
5167 // width must be in range [1, 32-lsb]
5168 unsigned lsb = Inst.getOperand(2).getImm();
5169 unsigned widthm1 = Inst.getOperand(3).getImm();
5170 if (widthm1 >= 32 - lsb)
5171 return Error(Operands[5]->getStartLoc(),
5172 "bitfield width must be in range [1,32-lsb]");
5176 // If we're parsing Thumb2, the .w variant is available and handles
5177 // most cases that are normally illegal for a Thumb1 LDM
5178 // instruction. We'll make the transformation in processInstruction()
5181 // Thumb LDM instructions are writeback iff the base register is not
5182 // in the register list.
5183 unsigned Rn = Inst.getOperand(0).getReg();
5184 bool hasWritebackToken =
5185 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5186 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5187 bool listContainsBase;
5188 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5189 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5190 "registers must be in range r0-r7");
5191 // If we should have writeback, then there should be a '!' token.
5192 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5193 return Error(Operands[2]->getStartLoc(),
5194 "writeback operator '!' expected");
5195 // If we should not have writeback, there must not be a '!'. This is
5196 // true even for the 32-bit wide encodings.
5197 if (listContainsBase && hasWritebackToken)
5198 return Error(Operands[3]->getStartLoc(),
5199 "writeback operator '!' not allowed when base register "
5200 "in register list");
5204 case ARM::t2LDMIA_UPD: {
5205 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5206 return Error(Operands[4]->getStartLoc(),
5207 "writeback operator '!' not allowed when base register "
5208 "in register list");
5211 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5212 // so only issue a diagnostic for thumb1. The instructions will be
5213 // switched to the t2 encodings in processInstruction() if necessary.
5215 bool listContainsBase;
5216 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5218 return Error(Operands[2]->getStartLoc(),
5219 "registers must be in range r0-r7 or pc");
5223 bool listContainsBase;
5224 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5226 return Error(Operands[2]->getStartLoc(),
5227 "registers must be in range r0-r7 or lr");
5230 case ARM::tSTMIA_UPD: {
5231 bool listContainsBase;
5232 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5233 return Error(Operands[4]->getStartLoc(),
5234 "registers must be in range r0-r7");
5242 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5244 default: llvm_unreachable("unexpected opcode!");
5246 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5247 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5248 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5249 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5250 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5251 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5252 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5253 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5254 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5257 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5258 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5259 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5260 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5261 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5263 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5264 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5265 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5266 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5267 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5269 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5270 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5271 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5272 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5273 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5276 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5277 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5278 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5279 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5280 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5281 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5282 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5283 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5284 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5285 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5286 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5287 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5288 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5289 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5290 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5293 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5294 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5295 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5296 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5297 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5298 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5299 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5300 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5301 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5302 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5303 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5304 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5305 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5306 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5307 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5308 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5309 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5310 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5313 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5314 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5315 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5316 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5317 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5318 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5319 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5320 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5321 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5322 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5323 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5324 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5325 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5326 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5327 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5330 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5331 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5332 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5333 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5334 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5335 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5336 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5337 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5338 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5339 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5340 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5341 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5342 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5343 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5344 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5345 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5346 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5347 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5351 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5353 default: llvm_unreachable("unexpected opcode!");
5355 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5356 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5357 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5358 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5359 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5360 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5361 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5362 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5363 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5366 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5367 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5368 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5369 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5370 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5371 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5372 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5373 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5374 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5375 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5376 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5377 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5378 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5379 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5380 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5383 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5384 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5385 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5386 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5387 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5388 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5389 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5390 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5391 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5392 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5393 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5394 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5395 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5396 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5397 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5398 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5399 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5400 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5403 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5404 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5405 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5406 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5407 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5408 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5409 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5410 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5411 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5412 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5413 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5414 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5415 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5416 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5417 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5420 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5421 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5422 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5423 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5424 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5425 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5426 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5427 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5428 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5429 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5430 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5431 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5432 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5433 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5434 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5435 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5436 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5437 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5440 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5441 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5442 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5443 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5444 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5445 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5446 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5447 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5448 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5449 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5450 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5451 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5452 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5453 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5454 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5457 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5458 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5459 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5460 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5461 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5462 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5463 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5464 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5465 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5466 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5467 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5468 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5469 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5470 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5471 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5472 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5473 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5474 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5477 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5478 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5479 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5480 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5481 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5482 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5483 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5484 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5485 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5486 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5487 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5488 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5489 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5490 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5491 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5492 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5493 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5494 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5499 processInstruction(MCInst &Inst,
5500 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5501 switch (Inst.getOpcode()) {
5502 // Aliases for alternate PC+imm syntax of LDR instructions.
5503 case ARM::t2LDRpcrel:
5504 Inst.setOpcode(ARM::t2LDRpci);
5506 case ARM::t2LDRBpcrel:
5507 Inst.setOpcode(ARM::t2LDRBpci);
5509 case ARM::t2LDRHpcrel:
5510 Inst.setOpcode(ARM::t2LDRHpci);
5512 case ARM::t2LDRSBpcrel:
5513 Inst.setOpcode(ARM::t2LDRSBpci);
5515 case ARM::t2LDRSHpcrel:
5516 Inst.setOpcode(ARM::t2LDRSHpci);
5518 // Handle NEON VST complex aliases.
5519 case ARM::VST1LNdWB_register_Asm_8:
5520 case ARM::VST1LNdWB_register_Asm_16:
5521 case ARM::VST1LNdWB_register_Asm_32: {
5523 // Shuffle the operands around so the lane index operand is in the
5526 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5527 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5528 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5529 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5530 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5531 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5532 TmpInst.addOperand(Inst.getOperand(1)); // lane
5533 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5534 TmpInst.addOperand(Inst.getOperand(6));
5539 case ARM::VST2LNdWB_register_Asm_8:
5540 case ARM::VST2LNdWB_register_Asm_16:
5541 case ARM::VST2LNdWB_register_Asm_32:
5542 case ARM::VST2LNqWB_register_Asm_16:
5543 case ARM::VST2LNqWB_register_Asm_32: {
5545 // Shuffle the operands around so the lane index operand is in the
5548 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5549 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5550 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5551 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5552 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5553 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5556 TmpInst.addOperand(Inst.getOperand(1)); // lane
5557 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5558 TmpInst.addOperand(Inst.getOperand(6));
5563 case ARM::VST3LNdWB_register_Asm_8:
5564 case ARM::VST3LNdWB_register_Asm_16:
5565 case ARM::VST3LNdWB_register_Asm_32:
5566 case ARM::VST3LNqWB_register_Asm_16:
5567 case ARM::VST3LNqWB_register_Asm_32: {
5569 // Shuffle the operands around so the lane index operand is in the
5572 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5573 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5574 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5575 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5576 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5577 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5578 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5582 TmpInst.addOperand(Inst.getOperand(1)); // lane
5583 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5584 TmpInst.addOperand(Inst.getOperand(6));
5589 case ARM::VST4LNdWB_register_Asm_8:
5590 case ARM::VST4LNdWB_register_Asm_16:
5591 case ARM::VST4LNdWB_register_Asm_32:
5592 case ARM::VST4LNqWB_register_Asm_16:
5593 case ARM::VST4LNqWB_register_Asm_32: {
5595 // Shuffle the operands around so the lane index operand is in the
5598 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5599 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5600 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5601 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5602 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5603 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5604 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5606 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5608 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5610 TmpInst.addOperand(Inst.getOperand(1)); // lane
5611 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5612 TmpInst.addOperand(Inst.getOperand(6));
5617 case ARM::VST1LNdWB_fixed_Asm_8:
5618 case ARM::VST1LNdWB_fixed_Asm_16:
5619 case ARM::VST1LNdWB_fixed_Asm_32: {
5621 // Shuffle the operands around so the lane index operand is in the
5624 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5625 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5626 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5627 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5628 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5629 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5630 TmpInst.addOperand(Inst.getOperand(1)); // lane
5631 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5632 TmpInst.addOperand(Inst.getOperand(5));
5637 case ARM::VST2LNdWB_fixed_Asm_8:
5638 case ARM::VST2LNdWB_fixed_Asm_16:
5639 case ARM::VST2LNdWB_fixed_Asm_32:
5640 case ARM::VST2LNqWB_fixed_Asm_16:
5641 case ARM::VST2LNqWB_fixed_Asm_32: {
5643 // Shuffle the operands around so the lane index operand is in the
5646 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5647 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5648 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5649 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5650 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5651 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5652 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5654 TmpInst.addOperand(Inst.getOperand(1)); // lane
5655 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5656 TmpInst.addOperand(Inst.getOperand(5));
5661 case ARM::VST3LNdWB_fixed_Asm_8:
5662 case ARM::VST3LNdWB_fixed_Asm_16:
5663 case ARM::VST3LNdWB_fixed_Asm_32:
5664 case ARM::VST3LNqWB_fixed_Asm_16:
5665 case ARM::VST3LNqWB_fixed_Asm_32: {
5667 // Shuffle the operands around so the lane index operand is in the
5670 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5671 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5672 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5673 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5674 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5675 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5678 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5680 TmpInst.addOperand(Inst.getOperand(1)); // lane
5681 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5682 TmpInst.addOperand(Inst.getOperand(5));
5687 case ARM::VST4LNdWB_fixed_Asm_8:
5688 case ARM::VST4LNdWB_fixed_Asm_16:
5689 case ARM::VST4LNdWB_fixed_Asm_32:
5690 case ARM::VST4LNqWB_fixed_Asm_16:
5691 case ARM::VST4LNqWB_fixed_Asm_32: {
5693 // Shuffle the operands around so the lane index operand is in the
5696 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5697 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5698 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5699 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5700 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5701 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5704 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5706 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5708 TmpInst.addOperand(Inst.getOperand(1)); // lane
5709 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5710 TmpInst.addOperand(Inst.getOperand(5));
5715 case ARM::VST1LNdAsm_8:
5716 case ARM::VST1LNdAsm_16:
5717 case ARM::VST1LNdAsm_32: {
5719 // Shuffle the operands around so the lane index operand is in the
5722 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5723 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5724 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5725 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5726 TmpInst.addOperand(Inst.getOperand(1)); // lane
5727 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5728 TmpInst.addOperand(Inst.getOperand(5));
5733 case ARM::VST2LNdAsm_8:
5734 case ARM::VST2LNdAsm_16:
5735 case ARM::VST2LNdAsm_32:
5736 case ARM::VST2LNqAsm_16:
5737 case ARM::VST2LNqAsm_32: {
5739 // Shuffle the operands around so the lane index operand is in the
5742 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5743 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5744 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5745 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5746 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5748 TmpInst.addOperand(Inst.getOperand(1)); // lane
5749 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5750 TmpInst.addOperand(Inst.getOperand(5));
5755 case ARM::VST3LNdAsm_8:
5756 case ARM::VST3LNdAsm_16:
5757 case ARM::VST3LNdAsm_32:
5758 case ARM::VST3LNqAsm_16:
5759 case ARM::VST3LNqAsm_32: {
5761 // Shuffle the operands around so the lane index operand is in the
5764 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5765 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5766 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5767 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5768 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5770 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5772 TmpInst.addOperand(Inst.getOperand(1)); // lane
5773 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5774 TmpInst.addOperand(Inst.getOperand(5));
5779 case ARM::VST4LNdAsm_8:
5780 case ARM::VST4LNdAsm_16:
5781 case ARM::VST4LNdAsm_32:
5782 case ARM::VST4LNqAsm_16:
5783 case ARM::VST4LNqAsm_32: {
5785 // Shuffle the operands around so the lane index operand is in the
5788 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5789 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5790 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5791 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5792 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5794 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5796 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5798 TmpInst.addOperand(Inst.getOperand(1)); // lane
5799 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5800 TmpInst.addOperand(Inst.getOperand(5));
5805 // Handle NEON VLD complex aliases.
5806 case ARM::VLD1LNdWB_register_Asm_8:
5807 case ARM::VLD1LNdWB_register_Asm_16:
5808 case ARM::VLD1LNdWB_register_Asm_32: {
5810 // Shuffle the operands around so the lane index operand is in the
5813 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5814 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5815 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5816 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5817 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5818 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5819 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5820 TmpInst.addOperand(Inst.getOperand(1)); // lane
5821 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5822 TmpInst.addOperand(Inst.getOperand(6));
5827 case ARM::VLD2LNdWB_register_Asm_8:
5828 case ARM::VLD2LNdWB_register_Asm_16:
5829 case ARM::VLD2LNdWB_register_Asm_32:
5830 case ARM::VLD2LNqWB_register_Asm_16:
5831 case ARM::VLD2LNqWB_register_Asm_32: {
5833 // Shuffle the operands around so the lane index operand is in the
5836 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5837 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5838 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5840 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5841 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5842 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5843 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5844 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5845 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5847 TmpInst.addOperand(Inst.getOperand(1)); // lane
5848 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5849 TmpInst.addOperand(Inst.getOperand(6));
5854 case ARM::VLD3LNdWB_register_Asm_8:
5855 case ARM::VLD3LNdWB_register_Asm_16:
5856 case ARM::VLD3LNdWB_register_Asm_32:
5857 case ARM::VLD3LNqWB_register_Asm_16:
5858 case ARM::VLD3LNqWB_register_Asm_32: {
5860 // Shuffle the operands around so the lane index operand is in the
5863 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5864 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5865 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5867 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5869 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5870 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5871 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5872 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5873 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5874 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5876 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5878 TmpInst.addOperand(Inst.getOperand(1)); // lane
5879 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5880 TmpInst.addOperand(Inst.getOperand(6));
5885 case ARM::VLD4LNdWB_register_Asm_8:
5886 case ARM::VLD4LNdWB_register_Asm_16:
5887 case ARM::VLD4LNdWB_register_Asm_32:
5888 case ARM::VLD4LNqWB_register_Asm_16:
5889 case ARM::VLD4LNqWB_register_Asm_32: {
5891 // Shuffle the operands around so the lane index operand is in the
5894 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5895 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5896 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5898 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5900 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5902 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5903 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5904 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5905 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5906 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5907 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5909 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5911 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5913 TmpInst.addOperand(Inst.getOperand(1)); // lane
5914 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5915 TmpInst.addOperand(Inst.getOperand(6));
5920 case ARM::VLD1LNdWB_fixed_Asm_8:
5921 case ARM::VLD1LNdWB_fixed_Asm_16:
5922 case ARM::VLD1LNdWB_fixed_Asm_32: {
5924 // Shuffle the operands around so the lane index operand is in the
5927 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5928 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5929 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5930 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5931 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5932 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5933 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5934 TmpInst.addOperand(Inst.getOperand(1)); // lane
5935 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5936 TmpInst.addOperand(Inst.getOperand(5));
5941 case ARM::VLD2LNdWB_fixed_Asm_8:
5942 case ARM::VLD2LNdWB_fixed_Asm_16:
5943 case ARM::VLD2LNdWB_fixed_Asm_32:
5944 case ARM::VLD2LNqWB_fixed_Asm_16:
5945 case ARM::VLD2LNqWB_fixed_Asm_32: {
5947 // Shuffle the operands around so the lane index operand is in the
5950 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5951 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5952 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5954 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5955 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5956 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5957 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5958 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5959 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5961 TmpInst.addOperand(Inst.getOperand(1)); // lane
5962 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5963 TmpInst.addOperand(Inst.getOperand(5));
5968 case ARM::VLD3LNdWB_fixed_Asm_8:
5969 case ARM::VLD3LNdWB_fixed_Asm_16:
5970 case ARM::VLD3LNdWB_fixed_Asm_32:
5971 case ARM::VLD3LNqWB_fixed_Asm_16:
5972 case ARM::VLD3LNqWB_fixed_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(Inst.getOperand(2)); // Rn_wb
5984 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5985 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5986 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5987 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5988 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5990 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5992 TmpInst.addOperand(Inst.getOperand(1)); // lane
5993 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5994 TmpInst.addOperand(Inst.getOperand(5));
5999 case ARM::VLD4LNdWB_fixed_Asm_8:
6000 case ARM::VLD4LNdWB_fixed_Asm_16:
6001 case ARM::VLD4LNdWB_fixed_Asm_32:
6002 case ARM::VLD4LNqWB_fixed_Asm_16:
6003 case ARM::VLD4LNqWB_fixed_Asm_32: {
6005 // Shuffle the operands around so the lane index operand is in the
6008 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6009 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6010 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6012 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6014 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6016 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6017 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6018 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6019 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6020 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6021 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6023 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6025 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6027 TmpInst.addOperand(Inst.getOperand(1)); // lane
6028 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6029 TmpInst.addOperand(Inst.getOperand(5));
6034 case ARM::VLD1LNdAsm_8:
6035 case ARM::VLD1LNdAsm_16:
6036 case ARM::VLD1LNdAsm_32: {
6038 // Shuffle the operands around so the lane index operand is in the
6041 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6042 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6043 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6044 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6045 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6046 TmpInst.addOperand(Inst.getOperand(1)); // lane
6047 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6048 TmpInst.addOperand(Inst.getOperand(5));
6053 case ARM::VLD2LNdAsm_8:
6054 case ARM::VLD2LNdAsm_16:
6055 case ARM::VLD2LNdAsm_32:
6056 case ARM::VLD2LNqAsm_16:
6057 case ARM::VLD2LNqAsm_32: {
6059 // Shuffle the operands around so the lane index operand is in the
6062 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6063 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6064 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6066 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6067 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6068 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6071 TmpInst.addOperand(Inst.getOperand(1)); // lane
6072 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6073 TmpInst.addOperand(Inst.getOperand(5));
6078 case ARM::VLD3LNdAsm_8:
6079 case ARM::VLD3LNdAsm_16:
6080 case ARM::VLD3LNdAsm_32:
6081 case ARM::VLD3LNqAsm_16:
6082 case ARM::VLD3LNqAsm_32: {
6084 // Shuffle the operands around so the lane index operand is in the
6087 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6088 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6089 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6091 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6093 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6094 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6095 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6096 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6098 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6100 TmpInst.addOperand(Inst.getOperand(1)); // lane
6101 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6102 TmpInst.addOperand(Inst.getOperand(5));
6107 case ARM::VLD4LNdAsm_8:
6108 case ARM::VLD4LNdAsm_16:
6109 case ARM::VLD4LNdAsm_32:
6110 case ARM::VLD4LNqAsm_16:
6111 case ARM::VLD4LNqAsm_32: {
6113 // Shuffle the operands around so the lane index operand is in the
6116 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6117 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6118 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6120 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6122 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6124 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6125 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6126 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6127 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6129 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6131 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6133 TmpInst.addOperand(Inst.getOperand(1)); // lane
6134 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6135 TmpInst.addOperand(Inst.getOperand(5));
6140 // VLD3DUP single 3-element structure to all lanes instructions.
6141 case ARM::VLD3DUPdAsm_8:
6142 case ARM::VLD3DUPdAsm_16:
6143 case ARM::VLD3DUPdAsm_32:
6144 case ARM::VLD3DUPqAsm_8:
6145 case ARM::VLD3DUPqAsm_16:
6146 case ARM::VLD3DUPqAsm_32: {
6149 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6150 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6151 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6153 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6155 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6156 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6157 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6158 TmpInst.addOperand(Inst.getOperand(4));
6163 case ARM::VLD3DUPdWB_fixed_Asm_8:
6164 case ARM::VLD3DUPdWB_fixed_Asm_16:
6165 case ARM::VLD3DUPdWB_fixed_Asm_32:
6166 case ARM::VLD3DUPqWB_fixed_Asm_8:
6167 case ARM::VLD3DUPqWB_fixed_Asm_16:
6168 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6171 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6172 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6173 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6175 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6177 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6178 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6179 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6180 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6181 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6182 TmpInst.addOperand(Inst.getOperand(4));
6187 case ARM::VLD3DUPdWB_register_Asm_8:
6188 case ARM::VLD3DUPdWB_register_Asm_16:
6189 case ARM::VLD3DUPdWB_register_Asm_32:
6190 case ARM::VLD3DUPqWB_register_Asm_8:
6191 case ARM::VLD3DUPqWB_register_Asm_16:
6192 case ARM::VLD3DUPqWB_register_Asm_32: {
6195 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6196 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6197 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6199 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6201 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6202 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6203 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6204 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6205 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6206 TmpInst.addOperand(Inst.getOperand(5));
6211 // VLD3 multiple 3-element structure instructions.
6212 case ARM::VLD3dAsm_8:
6213 case ARM::VLD3dAsm_16:
6214 case ARM::VLD3dAsm_32:
6215 case ARM::VLD3qAsm_8:
6216 case ARM::VLD3qAsm_16:
6217 case ARM::VLD3qAsm_32: {
6220 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6221 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6222 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6224 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6226 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6227 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6228 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6229 TmpInst.addOperand(Inst.getOperand(4));
6234 case ARM::VLD3dWB_fixed_Asm_8:
6235 case ARM::VLD3dWB_fixed_Asm_16:
6236 case ARM::VLD3dWB_fixed_Asm_32:
6237 case ARM::VLD3qWB_fixed_Asm_8:
6238 case ARM::VLD3qWB_fixed_Asm_16:
6239 case ARM::VLD3qWB_fixed_Asm_32: {
6242 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6243 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6244 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6246 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6248 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6249 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6250 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6251 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6252 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6253 TmpInst.addOperand(Inst.getOperand(4));
6258 case ARM::VLD3dWB_register_Asm_8:
6259 case ARM::VLD3dWB_register_Asm_16:
6260 case ARM::VLD3dWB_register_Asm_32:
6261 case ARM::VLD3qWB_register_Asm_8:
6262 case ARM::VLD3qWB_register_Asm_16:
6263 case ARM::VLD3qWB_register_Asm_32: {
6266 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6267 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6268 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6270 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6272 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6273 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6274 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6275 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6276 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6277 TmpInst.addOperand(Inst.getOperand(5));
6282 // VLD4DUP single 3-element structure to all lanes instructions.
6283 case ARM::VLD4DUPdAsm_8:
6284 case ARM::VLD4DUPdAsm_16:
6285 case ARM::VLD4DUPdAsm_32:
6286 case ARM::VLD4DUPqAsm_8:
6287 case ARM::VLD4DUPqAsm_16:
6288 case ARM::VLD4DUPqAsm_32: {
6291 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6292 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6293 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6295 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6297 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6299 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6300 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6301 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6302 TmpInst.addOperand(Inst.getOperand(4));
6307 case ARM::VLD4DUPdWB_fixed_Asm_8:
6308 case ARM::VLD4DUPdWB_fixed_Asm_16:
6309 case ARM::VLD4DUPdWB_fixed_Asm_32:
6310 case ARM::VLD4DUPqWB_fixed_Asm_8:
6311 case ARM::VLD4DUPqWB_fixed_Asm_16:
6312 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6315 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6316 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6317 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6319 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6321 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6323 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6324 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6325 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6326 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6327 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6328 TmpInst.addOperand(Inst.getOperand(4));
6333 case ARM::VLD4DUPdWB_register_Asm_8:
6334 case ARM::VLD4DUPdWB_register_Asm_16:
6335 case ARM::VLD4DUPdWB_register_Asm_32:
6336 case ARM::VLD4DUPqWB_register_Asm_8:
6337 case ARM::VLD4DUPqWB_register_Asm_16:
6338 case ARM::VLD4DUPqWB_register_Asm_32: {
6341 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6342 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6343 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6347 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6349 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6350 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6351 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6352 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6353 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6354 TmpInst.addOperand(Inst.getOperand(5));
6359 // VLD4 multiple 4-element structure instructions.
6360 case ARM::VLD4dAsm_8:
6361 case ARM::VLD4dAsm_16:
6362 case ARM::VLD4dAsm_32:
6363 case ARM::VLD4qAsm_8:
6364 case ARM::VLD4qAsm_16:
6365 case ARM::VLD4qAsm_32: {
6368 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6369 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6370 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6372 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6374 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6376 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6377 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6378 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6379 TmpInst.addOperand(Inst.getOperand(4));
6384 case ARM::VLD4dWB_fixed_Asm_8:
6385 case ARM::VLD4dWB_fixed_Asm_16:
6386 case ARM::VLD4dWB_fixed_Asm_32:
6387 case ARM::VLD4qWB_fixed_Asm_8:
6388 case ARM::VLD4qWB_fixed_Asm_16:
6389 case ARM::VLD4qWB_fixed_Asm_32: {
6392 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6393 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6394 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6396 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6400 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6401 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6402 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6403 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6404 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6405 TmpInst.addOperand(Inst.getOperand(4));
6410 case ARM::VLD4dWB_register_Asm_8:
6411 case ARM::VLD4dWB_register_Asm_16:
6412 case ARM::VLD4dWB_register_Asm_32:
6413 case ARM::VLD4qWB_register_Asm_8:
6414 case ARM::VLD4qWB_register_Asm_16:
6415 case ARM::VLD4qWB_register_Asm_32: {
6418 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6419 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6426 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6427 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6428 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6429 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6430 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6431 TmpInst.addOperand(Inst.getOperand(5));
6436 // VST3 multiple 3-element structure instructions.
6437 case ARM::VST3dAsm_8:
6438 case ARM::VST3dAsm_16:
6439 case ARM::VST3dAsm_32:
6440 case ARM::VST3qAsm_8:
6441 case ARM::VST3qAsm_16:
6442 case ARM::VST3qAsm_32: {
6445 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6446 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6447 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6448 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6449 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6451 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6453 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6454 TmpInst.addOperand(Inst.getOperand(4));
6459 case ARM::VST3dWB_fixed_Asm_8:
6460 case ARM::VST3dWB_fixed_Asm_16:
6461 case ARM::VST3dWB_fixed_Asm_32:
6462 case ARM::VST3qWB_fixed_Asm_8:
6463 case ARM::VST3qWB_fixed_Asm_16:
6464 case ARM::VST3qWB_fixed_Asm_32: {
6467 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6468 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6469 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6470 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6471 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6472 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6477 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6478 TmpInst.addOperand(Inst.getOperand(4));
6483 case ARM::VST3dWB_register_Asm_8:
6484 case ARM::VST3dWB_register_Asm_16:
6485 case ARM::VST3dWB_register_Asm_32:
6486 case ARM::VST3qWB_register_Asm_8:
6487 case ARM::VST3qWB_register_Asm_16:
6488 case ARM::VST3qWB_register_Asm_32: {
6491 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6492 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6493 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6494 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6495 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6496 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6501 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6502 TmpInst.addOperand(Inst.getOperand(5));
6507 // VST4 multiple 3-element structure instructions.
6508 case ARM::VST4dAsm_8:
6509 case ARM::VST4dAsm_16:
6510 case ARM::VST4dAsm_32:
6511 case ARM::VST4qAsm_8:
6512 case ARM::VST4qAsm_16:
6513 case ARM::VST4qAsm_32: {
6516 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6517 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6518 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6519 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6520 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6522 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6526 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6527 TmpInst.addOperand(Inst.getOperand(4));
6532 case ARM::VST4dWB_fixed_Asm_8:
6533 case ARM::VST4dWB_fixed_Asm_16:
6534 case ARM::VST4dWB_fixed_Asm_32:
6535 case ARM::VST4qWB_fixed_Asm_8:
6536 case ARM::VST4qWB_fixed_Asm_16:
6537 case ARM::VST4qWB_fixed_Asm_32: {
6540 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6541 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6542 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6543 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6544 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6545 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6550 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6552 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6553 TmpInst.addOperand(Inst.getOperand(4));
6558 case ARM::VST4dWB_register_Asm_8:
6559 case ARM::VST4dWB_register_Asm_16:
6560 case ARM::VST4dWB_register_Asm_32:
6561 case ARM::VST4qWB_register_Asm_8:
6562 case ARM::VST4qWB_register_Asm_16:
6563 case ARM::VST4qWB_register_Asm_32: {
6566 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6567 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6568 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6569 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6570 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6571 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6578 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6579 TmpInst.addOperand(Inst.getOperand(5));
6584 // Handle the Thumb2 mode MOV complex aliases.
6586 case ARM::t2MOVSsr: {
6587 // Which instruction to expand to depends on the CCOut operand and
6588 // whether we're in an IT block if the register operands are low
6590 bool isNarrow = false;
6591 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6592 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6593 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6594 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6595 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6599 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6600 default: llvm_unreachable("unexpected opcode!");
6601 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6602 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6603 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6604 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6606 TmpInst.setOpcode(newOpc);
6607 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6609 TmpInst.addOperand(MCOperand::CreateReg(
6610 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6611 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6612 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6613 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6614 TmpInst.addOperand(Inst.getOperand(5));
6616 TmpInst.addOperand(MCOperand::CreateReg(
6617 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6622 case ARM::t2MOVSsi: {
6623 // Which instruction to expand to depends on the CCOut operand and
6624 // whether we're in an IT block if the register operands are low
6626 bool isNarrow = false;
6627 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6628 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6629 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6633 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6634 default: llvm_unreachable("unexpected opcode!");
6635 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6636 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6637 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6638 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
6639 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
6641 unsigned Ammount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6642 if (Ammount == 32) Ammount = 0;
6643 TmpInst.setOpcode(newOpc);
6644 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6646 TmpInst.addOperand(MCOperand::CreateReg(
6647 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6648 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6649 if (newOpc != ARM::t2RRX)
6650 TmpInst.addOperand(MCOperand::CreateImm(Ammount));
6651 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6652 TmpInst.addOperand(Inst.getOperand(4));
6654 TmpInst.addOperand(MCOperand::CreateReg(
6655 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6659 // Handle the ARM mode MOV complex aliases.
6664 ARM_AM::ShiftOpc ShiftTy;
6665 switch(Inst.getOpcode()) {
6666 default: llvm_unreachable("unexpected opcode!");
6667 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6668 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6669 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6670 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6672 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6674 TmpInst.setOpcode(ARM::MOVsr);
6675 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6676 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6677 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6678 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6679 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6680 TmpInst.addOperand(Inst.getOperand(4));
6681 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6689 ARM_AM::ShiftOpc ShiftTy;
6690 switch(Inst.getOpcode()) {
6691 default: llvm_unreachable("unexpected opcode!");
6692 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6693 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6694 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6695 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6697 // A shift by zero is a plain MOVr, not a MOVsi.
6698 unsigned Amt = Inst.getOperand(2).getImm();
6699 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6700 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
6702 TmpInst.setOpcode(Opc);
6703 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6704 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6705 if (Opc == ARM::MOVsi)
6706 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6707 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6708 TmpInst.addOperand(Inst.getOperand(4));
6709 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6714 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6716 TmpInst.setOpcode(ARM::MOVsi);
6717 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6718 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6719 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6720 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6721 TmpInst.addOperand(Inst.getOperand(3));
6722 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6726 case ARM::t2LDMIA_UPD: {
6727 // If this is a load of a single register, then we should use
6728 // a post-indexed LDR instruction instead, per the ARM ARM.
6729 if (Inst.getNumOperands() != 5)
6732 TmpInst.setOpcode(ARM::t2LDR_POST);
6733 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6734 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6735 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6736 TmpInst.addOperand(MCOperand::CreateImm(4));
6737 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6738 TmpInst.addOperand(Inst.getOperand(3));
6742 case ARM::t2STMDB_UPD: {
6743 // If this is a store of a single register, then we should use
6744 // a pre-indexed STR instruction instead, per the ARM ARM.
6745 if (Inst.getNumOperands() != 5)
6748 TmpInst.setOpcode(ARM::t2STR_PRE);
6749 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6750 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6751 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6752 TmpInst.addOperand(MCOperand::CreateImm(-4));
6753 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6754 TmpInst.addOperand(Inst.getOperand(3));
6758 case ARM::LDMIA_UPD:
6759 // If this is a load of a single register via a 'pop', then we should use
6760 // a post-indexed LDR instruction instead, per the ARM ARM.
6761 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6762 Inst.getNumOperands() == 5) {
6764 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6765 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6766 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6767 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6768 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6769 TmpInst.addOperand(MCOperand::CreateImm(4));
6770 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6771 TmpInst.addOperand(Inst.getOperand(3));
6776 case ARM::STMDB_UPD:
6777 // If this is a store of a single register via a 'push', then we should use
6778 // a pre-indexed STR instruction instead, per the ARM ARM.
6779 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6780 Inst.getNumOperands() == 5) {
6782 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6783 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6784 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6785 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6786 TmpInst.addOperand(MCOperand::CreateImm(-4));
6787 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6788 TmpInst.addOperand(Inst.getOperand(3));
6792 case ARM::t2ADDri12:
6793 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6794 // mnemonic was used (not "addw"), encoding T3 is preferred.
6795 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6796 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6798 Inst.setOpcode(ARM::t2ADDri);
6799 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6801 case ARM::t2SUBri12:
6802 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6803 // mnemonic was used (not "subw"), encoding T3 is preferred.
6804 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6805 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6807 Inst.setOpcode(ARM::t2SUBri);
6808 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6811 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6812 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6813 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6814 // to encoding T1 if <Rd> is omitted."
6815 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
6816 Inst.setOpcode(ARM::tADDi3);
6821 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6822 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6823 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6824 // to encoding T1 if <Rd> is omitted."
6825 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
6826 Inst.setOpcode(ARM::tSUBi3);
6830 case ARM::t2ADDrr: {
6831 // If the destination and first source operand are the same, and
6832 // there's no setting of the flags, use encoding T2 instead of T3.
6833 // Note that this is only for ADD, not SUB. This mirrors the system
6834 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
6835 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
6836 Inst.getOperand(5).getReg() != 0 ||
6837 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6838 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
6841 TmpInst.setOpcode(ARM::tADDhirr);
6842 TmpInst.addOperand(Inst.getOperand(0));
6843 TmpInst.addOperand(Inst.getOperand(0));
6844 TmpInst.addOperand(Inst.getOperand(2));
6845 TmpInst.addOperand(Inst.getOperand(3));
6846 TmpInst.addOperand(Inst.getOperand(4));
6851 // A Thumb conditional branch outside of an IT block is a tBcc.
6852 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
6853 Inst.setOpcode(ARM::tBcc);
6858 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
6859 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
6860 Inst.setOpcode(ARM::t2Bcc);
6865 // If the conditional is AL or we're in an IT block, we really want t2B.
6866 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
6867 Inst.setOpcode(ARM::t2B);
6872 // If the conditional is AL, we really want tB.
6873 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
6874 Inst.setOpcode(ARM::tB);
6879 // If the register list contains any high registers, or if the writeback
6880 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
6881 // instead if we're in Thumb2. Otherwise, this should have generated
6882 // an error in validateInstruction().
6883 unsigned Rn = Inst.getOperand(0).getReg();
6884 bool hasWritebackToken =
6885 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6886 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
6887 bool listContainsBase;
6888 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
6889 (!listContainsBase && !hasWritebackToken) ||
6890 (listContainsBase && hasWritebackToken)) {
6891 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
6892 assert (isThumbTwo());
6893 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
6894 // If we're switching to the updating version, we need to insert
6895 // the writeback tied operand.
6896 if (hasWritebackToken)
6897 Inst.insert(Inst.begin(),
6898 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
6903 case ARM::tSTMIA_UPD: {
6904 // If the register list contains any high registers, we need to use
6905 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
6906 // should have generated an error in validateInstruction().
6907 unsigned Rn = Inst.getOperand(0).getReg();
6908 bool listContainsBase;
6909 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
6910 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
6911 assert (isThumbTwo());
6912 Inst.setOpcode(ARM::t2STMIA_UPD);
6918 bool listContainsBase;
6919 // If the register list contains any high registers, we need to use
6920 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
6921 // should have generated an error in validateInstruction().
6922 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
6924 assert (isThumbTwo());
6925 Inst.setOpcode(ARM::t2LDMIA_UPD);
6926 // Add the base register and writeback operands.
6927 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6928 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6932 bool listContainsBase;
6933 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
6935 assert (isThumbTwo());
6936 Inst.setOpcode(ARM::t2STMDB_UPD);
6937 // Add the base register and writeback operands.
6938 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6939 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6943 // If we can use the 16-bit encoding and the user didn't explicitly
6944 // request the 32-bit variant, transform it here.
6945 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6946 Inst.getOperand(1).getImm() <= 255 &&
6947 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
6948 Inst.getOperand(4).getReg() == ARM::CPSR) ||
6949 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
6950 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6951 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6952 // The operands aren't in the same order for tMOVi8...
6954 TmpInst.setOpcode(ARM::tMOVi8);
6955 TmpInst.addOperand(Inst.getOperand(0));
6956 TmpInst.addOperand(Inst.getOperand(4));
6957 TmpInst.addOperand(Inst.getOperand(1));
6958 TmpInst.addOperand(Inst.getOperand(2));
6959 TmpInst.addOperand(Inst.getOperand(3));
6966 // If we can use the 16-bit encoding and the user didn't explicitly
6967 // request the 32-bit variant, transform it here.
6968 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6969 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6970 Inst.getOperand(2).getImm() == ARMCC::AL &&
6971 Inst.getOperand(4).getReg() == ARM::CPSR &&
6972 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6973 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6974 // The operands aren't the same for tMOV[S]r... (no cc_out)
6976 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
6977 TmpInst.addOperand(Inst.getOperand(0));
6978 TmpInst.addOperand(Inst.getOperand(1));
6979 TmpInst.addOperand(Inst.getOperand(2));
6980 TmpInst.addOperand(Inst.getOperand(3));
6990 // If we can use the 16-bit encoding and the user didn't explicitly
6991 // request the 32-bit variant, transform it here.
6992 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6993 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6994 Inst.getOperand(2).getImm() == 0 &&
6995 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6996 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6998 switch (Inst.getOpcode()) {
6999 default: llvm_unreachable("Illegal opcode!");
7000 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7001 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7002 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7003 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7005 // The operands aren't the same for thumb1 (no rotate operand).
7007 TmpInst.setOpcode(NewOpc);
7008 TmpInst.addOperand(Inst.getOperand(0));
7009 TmpInst.addOperand(Inst.getOperand(1));
7010 TmpInst.addOperand(Inst.getOperand(3));
7011 TmpInst.addOperand(Inst.getOperand(4));
7018 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7019 if (SOpc == ARM_AM::rrx) return false;
7020 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7021 // Shifting by zero is accepted as a vanilla 'MOVr'
7023 TmpInst.setOpcode(ARM::MOVr);
7024 TmpInst.addOperand(Inst.getOperand(0));
7025 TmpInst.addOperand(Inst.getOperand(1));
7026 TmpInst.addOperand(Inst.getOperand(3));
7027 TmpInst.addOperand(Inst.getOperand(4));
7028 TmpInst.addOperand(Inst.getOperand(5));
7041 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7042 if (SOpc == ARM_AM::rrx) return false;
7043 switch (Inst.getOpcode()) {
7044 default: llvm_unreachable("unexpected opcode!");
7045 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7046 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7047 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7048 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7049 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7050 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7052 // If the shift is by zero, use the non-shifted instruction definition.
7053 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0) {
7055 TmpInst.setOpcode(newOpc);
7056 TmpInst.addOperand(Inst.getOperand(0));
7057 TmpInst.addOperand(Inst.getOperand(1));
7058 TmpInst.addOperand(Inst.getOperand(2));
7059 TmpInst.addOperand(Inst.getOperand(4));
7060 TmpInst.addOperand(Inst.getOperand(5));
7061 TmpInst.addOperand(Inst.getOperand(6));
7069 // The mask bits for all but the first condition are represented as
7070 // the low bit of the condition code value implies 't'. We currently
7071 // always have 1 implies 't', so XOR toggle the bits if the low bit
7072 // of the condition code is zero. The encoding also expects the low
7073 // bit of the condition to be encoded as bit 4 of the mask operand,
7074 // so mask that in if needed
7075 MCOperand &MO = Inst.getOperand(1);
7076 unsigned Mask = MO.getImm();
7077 unsigned OrigMask = Mask;
7078 unsigned TZ = CountTrailingZeros_32(Mask);
7079 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7080 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7081 for (unsigned i = 3; i != TZ; --i)
7087 // Set up the IT block state according to the IT instruction we just
7089 assert(!inITBlock() && "nested IT blocks?!");
7090 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7091 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7092 ITState.CurPosition = 0;
7093 ITState.FirstCond = true;
7100 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7101 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7102 // suffix depending on whether they're in an IT block or not.
7103 unsigned Opc = Inst.getOpcode();
7104 const MCInstrDesc &MCID = getInstDesc(Opc);
7105 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7106 assert(MCID.hasOptionalDef() &&
7107 "optionally flag setting instruction missing optional def operand");
7108 assert(MCID.NumOperands == Inst.getNumOperands() &&
7109 "operand count mismatch!");
7110 // Find the optional-def operand (cc_out).
7113 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7116 // If we're parsing Thumb1, reject it completely.
7117 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7118 return Match_MnemonicFail;
7119 // If we're parsing Thumb2, which form is legal depends on whether we're
7121 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7123 return Match_RequiresITBlock;
7124 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7126 return Match_RequiresNotITBlock;
7128 // Some high-register supporting Thumb1 encodings only allow both registers
7129 // to be from r0-r7 when in Thumb2.
7130 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7131 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7132 isARMLowRegister(Inst.getOperand(2).getReg()))
7133 return Match_RequiresThumb2;
7134 // Others only require ARMv6 or later.
7135 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7136 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7137 isARMLowRegister(Inst.getOperand(1).getReg()))
7138 return Match_RequiresV6;
7139 return Match_Success;
7143 MatchAndEmitInstruction(SMLoc IDLoc,
7144 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7148 unsigned MatchResult;
7149 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
7150 switch (MatchResult) {
7153 // Context sensitive operand constraints aren't handled by the matcher,
7154 // so check them here.
7155 if (validateInstruction(Inst, Operands)) {
7156 // Still progress the IT block, otherwise one wrong condition causes
7157 // nasty cascading errors.
7158 forwardITPosition();
7162 // Some instructions need post-processing to, for example, tweak which
7163 // encoding is selected. Loop on it while changes happen so the
7164 // individual transformations can chain off each other. E.g.,
7165 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7166 while (processInstruction(Inst, Operands))
7169 // Only move forward at the very end so that everything in validate
7170 // and process gets a consistent answer about whether we're in an IT
7172 forwardITPosition();
7174 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7175 // doesn't actually encode.
7176 if (Inst.getOpcode() == ARM::ITasm)
7180 Out.EmitInstruction(Inst);
7182 case Match_MissingFeature:
7183 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
7185 case Match_InvalidOperand: {
7186 SMLoc ErrorLoc = IDLoc;
7187 if (ErrorInfo != ~0U) {
7188 if (ErrorInfo >= Operands.size())
7189 return Error(IDLoc, "too few operands for instruction");
7191 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7192 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7195 return Error(ErrorLoc, "invalid operand for instruction");
7197 case Match_MnemonicFail:
7198 return Error(IDLoc, "invalid instruction");
7199 case Match_ConversionFail:
7200 // The converter function will have already emited a diagnostic.
7202 case Match_RequiresNotITBlock:
7203 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7204 case Match_RequiresITBlock:
7205 return Error(IDLoc, "instruction only valid inside IT block");
7206 case Match_RequiresV6:
7207 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7208 case Match_RequiresThumb2:
7209 return Error(IDLoc, "instruction variant requires Thumb2");
7212 llvm_unreachable("Implement any new match types added!");
7215 /// parseDirective parses the arm specific directives
7216 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7217 StringRef IDVal = DirectiveID.getIdentifier();
7218 if (IDVal == ".word")
7219 return parseDirectiveWord(4, DirectiveID.getLoc());
7220 else if (IDVal == ".thumb")
7221 return parseDirectiveThumb(DirectiveID.getLoc());
7222 else if (IDVal == ".arm")
7223 return parseDirectiveARM(DirectiveID.getLoc());
7224 else if (IDVal == ".thumb_func")
7225 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7226 else if (IDVal == ".code")
7227 return parseDirectiveCode(DirectiveID.getLoc());
7228 else if (IDVal == ".syntax")
7229 return parseDirectiveSyntax(DirectiveID.getLoc());
7230 else if (IDVal == ".unreq")
7231 return parseDirectiveUnreq(DirectiveID.getLoc());
7232 else if (IDVal == ".arch")
7233 return parseDirectiveArch(DirectiveID.getLoc());
7234 else if (IDVal == ".eabi_attribute")
7235 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7239 /// parseDirectiveWord
7240 /// ::= .word [ expression (, expression)* ]
7241 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7242 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7244 const MCExpr *Value;
7245 if (getParser().ParseExpression(Value))
7248 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
7250 if (getLexer().is(AsmToken::EndOfStatement))
7253 // FIXME: Improve diagnostic.
7254 if (getLexer().isNot(AsmToken::Comma))
7255 return Error(L, "unexpected token in directive");
7264 /// parseDirectiveThumb
7266 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7267 if (getLexer().isNot(AsmToken::EndOfStatement))
7268 return Error(L, "unexpected token in directive");
7273 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7277 /// parseDirectiveARM
7279 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7280 if (getLexer().isNot(AsmToken::EndOfStatement))
7281 return Error(L, "unexpected token in directive");
7286 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7290 /// parseDirectiveThumbFunc
7291 /// ::= .thumbfunc symbol_name
7292 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7293 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7294 bool isMachO = MAI.hasSubsectionsViaSymbols();
7296 bool needFuncName = true;
7298 // Darwin asm has (optionally) function name after .thumb_func direction
7301 const AsmToken &Tok = Parser.getTok();
7302 if (Tok.isNot(AsmToken::EndOfStatement)) {
7303 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7304 return Error(L, "unexpected token in .thumb_func directive");
7305 Name = Tok.getIdentifier();
7306 Parser.Lex(); // Consume the identifier token.
7307 needFuncName = false;
7311 if (getLexer().isNot(AsmToken::EndOfStatement))
7312 return Error(L, "unexpected token in directive");
7314 // Eat the end of statement and any blank lines that follow.
7315 while (getLexer().is(AsmToken::EndOfStatement))
7318 // FIXME: assuming function name will be the line following .thumb_func
7319 // We really should be checking the next symbol definition even if there's
7320 // stuff in between.
7322 Name = Parser.getTok().getIdentifier();
7325 // Mark symbol as a thumb symbol.
7326 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7327 getParser().getStreamer().EmitThumbFunc(Func);
7331 /// parseDirectiveSyntax
7332 /// ::= .syntax unified | divided
7333 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7334 const AsmToken &Tok = Parser.getTok();
7335 if (Tok.isNot(AsmToken::Identifier))
7336 return Error(L, "unexpected token in .syntax directive");
7337 StringRef Mode = Tok.getString();
7338 if (Mode == "unified" || Mode == "UNIFIED")
7340 else if (Mode == "divided" || Mode == "DIVIDED")
7341 return Error(L, "'.syntax divided' arm asssembly not supported");
7343 return Error(L, "unrecognized syntax mode in .syntax directive");
7345 if (getLexer().isNot(AsmToken::EndOfStatement))
7346 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7349 // TODO tell the MC streamer the mode
7350 // getParser().getStreamer().Emit???();
7354 /// parseDirectiveCode
7355 /// ::= .code 16 | 32
7356 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7357 const AsmToken &Tok = Parser.getTok();
7358 if (Tok.isNot(AsmToken::Integer))
7359 return Error(L, "unexpected token in .code directive");
7360 int64_t Val = Parser.getTok().getIntVal();
7366 return Error(L, "invalid operand to .code directive");
7368 if (getLexer().isNot(AsmToken::EndOfStatement))
7369 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7375 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7379 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7385 /// parseDirectiveReq
7386 /// ::= name .req registername
7387 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7388 Parser.Lex(); // Eat the '.req' token.
7390 SMLoc SRegLoc, ERegLoc;
7391 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7392 Parser.EatToEndOfStatement();
7393 return Error(SRegLoc, "register name expected");
7396 // Shouldn't be anything else.
7397 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7398 Parser.EatToEndOfStatement();
7399 return Error(Parser.getTok().getLoc(),
7400 "unexpected input in .req directive.");
7403 Parser.Lex(); // Consume the EndOfStatement
7405 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7406 return Error(SRegLoc, "redefinition of '" + Name +
7407 "' does not match original.");
7412 /// parseDirectiveUneq
7413 /// ::= .unreq registername
7414 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7415 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7416 Parser.EatToEndOfStatement();
7417 return Error(L, "unexpected input in .unreq directive.");
7419 RegisterReqs.erase(Parser.getTok().getIdentifier());
7420 Parser.Lex(); // Eat the identifier.
7424 /// parseDirectiveArch
7426 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7430 /// parseDirectiveEabiAttr
7431 /// ::= .eabi_attribute int, int
7432 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7436 extern "C" void LLVMInitializeARMAsmLexer();
7438 /// Force static initialization.
7439 extern "C" void LLVMInitializeARMAsmParser() {
7440 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7441 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
7442 LLVMInitializeARMAsmLexer();
7445 #define GET_REGISTER_MATCHER
7446 #define GET_MATCHER_IMPLEMENTATION
7447 #include "ARMGenAsmMatcher.inc"