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 isVecListDPairSpaced() const {
1105 if (!isSingleSpacedVectorList()) return false;
1106 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1107 .contains(VectorList.RegNum));
1110 bool isVecListThreeQ() const {
1111 if (!isDoubleSpacedVectorList()) return false;
1112 return VectorList.Count == 3;
1115 bool isVecListFourQ() const {
1116 if (!isDoubleSpacedVectorList()) return false;
1117 return VectorList.Count == 4;
1120 bool isSingleSpacedVectorAllLanes() const {
1121 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1123 bool isDoubleSpacedVectorAllLanes() const {
1124 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1126 bool isVecListOneDAllLanes() const {
1127 if (!isSingleSpacedVectorAllLanes()) return false;
1128 return VectorList.Count == 1;
1131 bool isVecListDPairAllLanes() const {
1132 if (!isSingleSpacedVectorAllLanes()) return false;
1133 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1134 .contains(VectorList.RegNum));
1137 bool isVecListDPairSpacedAllLanes() const {
1138 if (!isDoubleSpacedVectorAllLanes()) return false;
1139 return VectorList.Count == 2;
1142 bool isVecListThreeDAllLanes() const {
1143 if (!isSingleSpacedVectorAllLanes()) return false;
1144 return VectorList.Count == 3;
1147 bool isVecListThreeQAllLanes() const {
1148 if (!isDoubleSpacedVectorAllLanes()) return false;
1149 return VectorList.Count == 3;
1152 bool isVecListFourDAllLanes() const {
1153 if (!isSingleSpacedVectorAllLanes()) return false;
1154 return VectorList.Count == 4;
1157 bool isVecListFourQAllLanes() const {
1158 if (!isDoubleSpacedVectorAllLanes()) return false;
1159 return VectorList.Count == 4;
1162 bool isSingleSpacedVectorIndexed() const {
1163 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1165 bool isDoubleSpacedVectorIndexed() const {
1166 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1168 bool isVecListOneDByteIndexed() const {
1169 if (!isSingleSpacedVectorIndexed()) return false;
1170 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1173 bool isVecListOneDHWordIndexed() const {
1174 if (!isSingleSpacedVectorIndexed()) return false;
1175 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1178 bool isVecListOneDWordIndexed() const {
1179 if (!isSingleSpacedVectorIndexed()) return false;
1180 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1183 bool isVecListTwoDByteIndexed() const {
1184 if (!isSingleSpacedVectorIndexed()) return false;
1185 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1188 bool isVecListTwoDHWordIndexed() const {
1189 if (!isSingleSpacedVectorIndexed()) return false;
1190 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1193 bool isVecListTwoQWordIndexed() const {
1194 if (!isDoubleSpacedVectorIndexed()) return false;
1195 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1198 bool isVecListTwoQHWordIndexed() const {
1199 if (!isDoubleSpacedVectorIndexed()) return false;
1200 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1203 bool isVecListTwoDWordIndexed() const {
1204 if (!isSingleSpacedVectorIndexed()) return false;
1205 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1208 bool isVecListThreeDByteIndexed() const {
1209 if (!isSingleSpacedVectorIndexed()) return false;
1210 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1213 bool isVecListThreeDHWordIndexed() const {
1214 if (!isSingleSpacedVectorIndexed()) return false;
1215 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1218 bool isVecListThreeQWordIndexed() const {
1219 if (!isDoubleSpacedVectorIndexed()) return false;
1220 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1223 bool isVecListThreeQHWordIndexed() const {
1224 if (!isDoubleSpacedVectorIndexed()) return false;
1225 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1228 bool isVecListThreeDWordIndexed() const {
1229 if (!isSingleSpacedVectorIndexed()) return false;
1230 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1233 bool isVecListFourDByteIndexed() const {
1234 if (!isSingleSpacedVectorIndexed()) return false;
1235 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1238 bool isVecListFourDHWordIndexed() const {
1239 if (!isSingleSpacedVectorIndexed()) return false;
1240 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1243 bool isVecListFourQWordIndexed() const {
1244 if (!isDoubleSpacedVectorIndexed()) return false;
1245 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1248 bool isVecListFourQHWordIndexed() const {
1249 if (!isDoubleSpacedVectorIndexed()) return false;
1250 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1253 bool isVecListFourDWordIndexed() const {
1254 if (!isSingleSpacedVectorIndexed()) return false;
1255 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1258 bool isVectorIndex8() const {
1259 if (Kind != k_VectorIndex) return false;
1260 return VectorIndex.Val < 8;
1262 bool isVectorIndex16() const {
1263 if (Kind != k_VectorIndex) return false;
1264 return VectorIndex.Val < 4;
1266 bool isVectorIndex32() const {
1267 if (Kind != k_VectorIndex) return false;
1268 return VectorIndex.Val < 2;
1271 bool isNEONi8splat() const {
1272 if (!isImm()) return false;
1273 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1274 // Must be a constant.
1275 if (!CE) return false;
1276 int64_t Value = CE->getValue();
1277 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1279 return Value >= 0 && Value < 256;
1282 bool isNEONi16splat() const {
1283 if (!isImm()) return false;
1284 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1285 // Must be a constant.
1286 if (!CE) return false;
1287 int64_t Value = CE->getValue();
1288 // i16 value in the range [0,255] or [0x0100, 0xff00]
1289 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1292 bool isNEONi32splat() const {
1293 if (!isImm()) return false;
1294 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1295 // Must be a constant.
1296 if (!CE) return false;
1297 int64_t Value = CE->getValue();
1298 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1299 return (Value >= 0 && Value < 256) ||
1300 (Value >= 0x0100 && Value <= 0xff00) ||
1301 (Value >= 0x010000 && Value <= 0xff0000) ||
1302 (Value >= 0x01000000 && Value <= 0xff000000);
1305 bool isNEONi32vmov() const {
1306 if (!isImm()) return false;
1307 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1308 // Must be a constant.
1309 if (!CE) return false;
1310 int64_t Value = CE->getValue();
1311 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1312 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1313 return (Value >= 0 && Value < 256) ||
1314 (Value >= 0x0100 && Value <= 0xff00) ||
1315 (Value >= 0x010000 && Value <= 0xff0000) ||
1316 (Value >= 0x01000000 && Value <= 0xff000000) ||
1317 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1318 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1320 bool isNEONi32vmovNeg() const {
1321 if (!isImm()) return false;
1322 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1323 // Must be a constant.
1324 if (!CE) return false;
1325 int64_t Value = ~CE->getValue();
1326 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1327 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1328 return (Value >= 0 && Value < 256) ||
1329 (Value >= 0x0100 && Value <= 0xff00) ||
1330 (Value >= 0x010000 && Value <= 0xff0000) ||
1331 (Value >= 0x01000000 && Value <= 0xff000000) ||
1332 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1333 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1336 bool isNEONi64splat() const {
1337 if (!isImm()) return false;
1338 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1339 // Must be a constant.
1340 if (!CE) return false;
1341 uint64_t Value = CE->getValue();
1342 // i64 value with each byte being either 0 or 0xff.
1343 for (unsigned i = 0; i < 8; ++i)
1344 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1348 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1349 // Add as immediates when possible. Null MCExpr = 0.
1351 Inst.addOperand(MCOperand::CreateImm(0));
1352 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1353 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1355 Inst.addOperand(MCOperand::CreateExpr(Expr));
1358 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1359 assert(N == 2 && "Invalid number of operands!");
1360 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1361 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1362 Inst.addOperand(MCOperand::CreateReg(RegNum));
1365 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1366 assert(N == 1 && "Invalid number of operands!");
1367 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1370 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1371 assert(N == 1 && "Invalid number of operands!");
1372 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1375 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1376 assert(N == 1 && "Invalid number of operands!");
1377 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1380 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1381 assert(N == 1 && "Invalid number of operands!");
1382 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1385 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1386 assert(N == 1 && "Invalid number of operands!");
1387 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1390 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1391 assert(N == 1 && "Invalid number of operands!");
1392 Inst.addOperand(MCOperand::CreateReg(getReg()));
1395 void addRegOperands(MCInst &Inst, unsigned N) const {
1396 assert(N == 1 && "Invalid number of operands!");
1397 Inst.addOperand(MCOperand::CreateReg(getReg()));
1400 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1401 assert(N == 3 && "Invalid number of operands!");
1402 assert(isRegShiftedReg() &&
1403 "addRegShiftedRegOperands() on non RegShiftedReg!");
1404 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1405 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1406 Inst.addOperand(MCOperand::CreateImm(
1407 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1410 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1411 assert(N == 2 && "Invalid number of operands!");
1412 assert(isRegShiftedImm() &&
1413 "addRegShiftedImmOperands() on non RegShiftedImm!");
1414 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1415 Inst.addOperand(MCOperand::CreateImm(
1416 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, RegShiftedImm.ShiftImm)));
1419 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1420 assert(N == 1 && "Invalid number of operands!");
1421 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1425 void addRegListOperands(MCInst &Inst, unsigned N) const {
1426 assert(N == 1 && "Invalid number of operands!");
1427 const SmallVectorImpl<unsigned> &RegList = getRegList();
1428 for (SmallVectorImpl<unsigned>::const_iterator
1429 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1430 Inst.addOperand(MCOperand::CreateReg(*I));
1433 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1434 addRegListOperands(Inst, N);
1437 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1438 addRegListOperands(Inst, N);
1441 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1442 assert(N == 1 && "Invalid number of operands!");
1443 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1444 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1447 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1448 assert(N == 1 && "Invalid number of operands!");
1449 // Munge the lsb/width into a bitfield mask.
1450 unsigned lsb = Bitfield.LSB;
1451 unsigned width = Bitfield.Width;
1452 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1453 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1454 (32 - (lsb + width)));
1455 Inst.addOperand(MCOperand::CreateImm(Mask));
1458 void addImmOperands(MCInst &Inst, unsigned N) const {
1459 assert(N == 1 && "Invalid number of operands!");
1460 addExpr(Inst, getImm());
1463 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1464 assert(N == 1 && "Invalid number of operands!");
1465 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1466 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1469 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1470 assert(N == 1 && "Invalid number of operands!");
1471 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1472 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1475 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1476 assert(N == 1 && "Invalid number of operands!");
1477 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1478 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1479 Inst.addOperand(MCOperand::CreateImm(Val));
1482 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1483 assert(N == 1 && "Invalid number of operands!");
1484 // FIXME: We really want to scale the value here, but the LDRD/STRD
1485 // instruction don't encode operands that way yet.
1486 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1487 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1490 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1491 assert(N == 1 && "Invalid number of operands!");
1492 // The immediate is scaled by four in the encoding and is stored
1493 // in the MCInst as such. Lop off the low two bits here.
1494 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1495 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1498 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1499 assert(N == 1 && "Invalid number of operands!");
1500 // The immediate is scaled by four in the encoding and is stored
1501 // in the MCInst as such. Lop off the low two bits here.
1502 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1503 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1506 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1507 assert(N == 1 && "Invalid number of operands!");
1508 // The constant encodes as the immediate-1, and we store in the instruction
1509 // the bits as encoded, so subtract off one here.
1510 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1511 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1514 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1515 assert(N == 1 && "Invalid number of operands!");
1516 // The constant encodes as the immediate-1, and we store in the instruction
1517 // the bits as encoded, so subtract off one here.
1518 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1519 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1522 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1523 assert(N == 1 && "Invalid number of operands!");
1524 // The constant encodes as the immediate, except for 32, which encodes as
1526 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1527 unsigned Imm = CE->getValue();
1528 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1531 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1532 assert(N == 1 && "Invalid number of operands!");
1533 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1534 // the instruction as well.
1535 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1536 int Val = CE->getValue();
1537 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1540 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1541 assert(N == 1 && "Invalid number of operands!");
1542 // The operand is actually a t2_so_imm, but we have its bitwise
1543 // negation in the assembly source, so twiddle it here.
1544 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1545 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1548 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1549 assert(N == 1 && "Invalid number of operands!");
1550 // The operand is actually a t2_so_imm, but we have its
1551 // negation in the assembly source, so twiddle it here.
1552 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1553 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1556 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1557 assert(N == 1 && "Invalid number of operands!");
1558 // The operand is actually a so_imm, but we have its bitwise
1559 // negation in the assembly source, so twiddle it here.
1560 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1561 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1564 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1565 assert(N == 1 && "Invalid number of operands!");
1566 // The operand is actually a so_imm, but we have its
1567 // negation in the assembly source, so twiddle it here.
1568 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1569 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1572 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1573 assert(N == 1 && "Invalid number of operands!");
1574 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1577 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1578 assert(N == 1 && "Invalid number of operands!");
1579 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1582 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1583 assert(N == 1 && "Invalid number of operands!");
1584 int32_t Imm = Memory.OffsetImm->getValue();
1585 // FIXME: Handle #-0
1586 if (Imm == INT32_MIN) Imm = 0;
1587 Inst.addOperand(MCOperand::CreateImm(Imm));
1590 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1591 assert(N == 2 && "Invalid number of operands!");
1592 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1593 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1596 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1597 assert(N == 3 && "Invalid number of operands!");
1598 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1599 if (!Memory.OffsetRegNum) {
1600 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1601 // Special case for #-0
1602 if (Val == INT32_MIN) Val = 0;
1603 if (Val < 0) Val = -Val;
1604 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1606 // For register offset, we encode the shift type and negation flag
1608 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1609 Memory.ShiftImm, Memory.ShiftType);
1611 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1612 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1613 Inst.addOperand(MCOperand::CreateImm(Val));
1616 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1617 assert(N == 2 && "Invalid number of operands!");
1618 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1619 assert(CE && "non-constant AM2OffsetImm operand!");
1620 int32_t Val = CE->getValue();
1621 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1622 // Special case for #-0
1623 if (Val == INT32_MIN) Val = 0;
1624 if (Val < 0) Val = -Val;
1625 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1626 Inst.addOperand(MCOperand::CreateReg(0));
1627 Inst.addOperand(MCOperand::CreateImm(Val));
1630 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1631 assert(N == 3 && "Invalid number of operands!");
1632 // If we have an immediate that's not a constant, treat it as a label
1633 // reference needing a fixup. If it is a constant, it's something else
1634 // and we reject it.
1636 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1637 Inst.addOperand(MCOperand::CreateReg(0));
1638 Inst.addOperand(MCOperand::CreateImm(0));
1642 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1643 if (!Memory.OffsetRegNum) {
1644 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1645 // Special case for #-0
1646 if (Val == INT32_MIN) Val = 0;
1647 if (Val < 0) Val = -Val;
1648 Val = ARM_AM::getAM3Opc(AddSub, Val);
1650 // For register offset, we encode the shift type and negation flag
1652 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1654 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1655 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1656 Inst.addOperand(MCOperand::CreateImm(Val));
1659 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1660 assert(N == 2 && "Invalid number of operands!");
1661 if (Kind == k_PostIndexRegister) {
1663 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1664 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1665 Inst.addOperand(MCOperand::CreateImm(Val));
1670 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1671 int32_t Val = CE->getValue();
1672 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1673 // Special case for #-0
1674 if (Val == INT32_MIN) Val = 0;
1675 if (Val < 0) Val = -Val;
1676 Val = ARM_AM::getAM3Opc(AddSub, Val);
1677 Inst.addOperand(MCOperand::CreateReg(0));
1678 Inst.addOperand(MCOperand::CreateImm(Val));
1681 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1682 assert(N == 2 && "Invalid number of operands!");
1683 // If we have an immediate that's not a constant, treat it as a label
1684 // reference needing a fixup. If it is a constant, it's something else
1685 // and we reject it.
1687 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1688 Inst.addOperand(MCOperand::CreateImm(0));
1692 // The lower two bits are always zero and as such are not encoded.
1693 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1694 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1695 // Special case for #-0
1696 if (Val == INT32_MIN) Val = 0;
1697 if (Val < 0) Val = -Val;
1698 Val = ARM_AM::getAM5Opc(AddSub, Val);
1699 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1700 Inst.addOperand(MCOperand::CreateImm(Val));
1703 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1704 assert(N == 2 && "Invalid number of operands!");
1705 // If we have an immediate that's not a constant, treat it as a label
1706 // reference needing a fixup. If it is a constant, it's something else
1707 // and we reject it.
1709 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1710 Inst.addOperand(MCOperand::CreateImm(0));
1714 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1715 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1716 Inst.addOperand(MCOperand::CreateImm(Val));
1719 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1720 assert(N == 2 && "Invalid number of operands!");
1721 // The lower two bits are always zero and as such are not encoded.
1722 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1723 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1724 Inst.addOperand(MCOperand::CreateImm(Val));
1727 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1728 assert(N == 2 && "Invalid number of operands!");
1729 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1730 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1731 Inst.addOperand(MCOperand::CreateImm(Val));
1734 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1735 addMemImm8OffsetOperands(Inst, N);
1738 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1739 addMemImm8OffsetOperands(Inst, N);
1742 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1743 assert(N == 2 && "Invalid number of operands!");
1744 // If this is an immediate, it's a label reference.
1746 addExpr(Inst, getImm());
1747 Inst.addOperand(MCOperand::CreateImm(0));
1751 // Otherwise, it's a normal memory reg+offset.
1752 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1753 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1754 Inst.addOperand(MCOperand::CreateImm(Val));
1757 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1758 assert(N == 2 && "Invalid number of operands!");
1759 // If this is an immediate, it's a label reference.
1761 addExpr(Inst, getImm());
1762 Inst.addOperand(MCOperand::CreateImm(0));
1766 // Otherwise, it's a normal memory reg+offset.
1767 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1768 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1769 Inst.addOperand(MCOperand::CreateImm(Val));
1772 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1773 assert(N == 2 && "Invalid number of operands!");
1774 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1775 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1778 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1779 assert(N == 2 && "Invalid number of operands!");
1780 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1781 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1784 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1785 assert(N == 3 && "Invalid number of operands!");
1787 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1788 Memory.ShiftImm, Memory.ShiftType);
1789 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1790 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1791 Inst.addOperand(MCOperand::CreateImm(Val));
1794 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 3 && "Invalid number of operands!");
1796 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1797 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1798 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1801 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1802 assert(N == 2 && "Invalid number of operands!");
1803 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1804 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1807 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1808 assert(N == 2 && "Invalid number of operands!");
1809 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1810 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1811 Inst.addOperand(MCOperand::CreateImm(Val));
1814 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1815 assert(N == 2 && "Invalid number of operands!");
1816 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1817 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1818 Inst.addOperand(MCOperand::CreateImm(Val));
1821 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1822 assert(N == 2 && "Invalid number of operands!");
1823 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1824 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1825 Inst.addOperand(MCOperand::CreateImm(Val));
1828 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1829 assert(N == 2 && "Invalid number of operands!");
1830 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1831 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1832 Inst.addOperand(MCOperand::CreateImm(Val));
1835 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1836 assert(N == 1 && "Invalid number of operands!");
1837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1838 assert(CE && "non-constant post-idx-imm8 operand!");
1839 int Imm = CE->getValue();
1840 bool isAdd = Imm >= 0;
1841 if (Imm == INT32_MIN) Imm = 0;
1842 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1843 Inst.addOperand(MCOperand::CreateImm(Imm));
1846 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1847 assert(N == 1 && "Invalid number of operands!");
1848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1849 assert(CE && "non-constant post-idx-imm8s4 operand!");
1850 int Imm = CE->getValue();
1851 bool isAdd = Imm >= 0;
1852 if (Imm == INT32_MIN) Imm = 0;
1853 // Immediate is scaled by 4.
1854 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1855 Inst.addOperand(MCOperand::CreateImm(Imm));
1858 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1859 assert(N == 2 && "Invalid number of operands!");
1860 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1861 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1864 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1865 assert(N == 2 && "Invalid number of operands!");
1866 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1867 // The sign, shift type, and shift amount are encoded in a single operand
1868 // using the AM2 encoding helpers.
1869 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1870 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1871 PostIdxReg.ShiftTy);
1872 Inst.addOperand(MCOperand::CreateImm(Imm));
1875 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1876 assert(N == 1 && "Invalid number of operands!");
1877 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1880 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1881 assert(N == 1 && "Invalid number of operands!");
1882 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1885 void addVecListOperands(MCInst &Inst, unsigned N) const {
1886 assert(N == 1 && "Invalid number of operands!");
1887 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1890 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1891 assert(N == 2 && "Invalid number of operands!");
1892 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1893 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1896 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1897 assert(N == 1 && "Invalid number of operands!");
1898 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1901 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1902 assert(N == 1 && "Invalid number of operands!");
1903 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1906 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1907 assert(N == 1 && "Invalid number of operands!");
1908 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1911 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1912 assert(N == 1 && "Invalid number of operands!");
1913 // The immediate encodes the type of constant as well as the value.
1914 // Mask in that this is an i8 splat.
1915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1916 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1919 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1920 assert(N == 1 && "Invalid number of operands!");
1921 // The immediate encodes the type of constant as well as the value.
1922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1923 unsigned Value = CE->getValue();
1925 Value = (Value >> 8) | 0xa00;
1928 Inst.addOperand(MCOperand::CreateImm(Value));
1931 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
1932 assert(N == 1 && "Invalid number of operands!");
1933 // The immediate encodes the type of constant as well as the value.
1934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1935 unsigned Value = CE->getValue();
1936 if (Value >= 256 && Value <= 0xff00)
1937 Value = (Value >> 8) | 0x200;
1938 else if (Value > 0xffff && Value <= 0xff0000)
1939 Value = (Value >> 16) | 0x400;
1940 else if (Value > 0xffffff)
1941 Value = (Value >> 24) | 0x600;
1942 Inst.addOperand(MCOperand::CreateImm(Value));
1945 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
1946 assert(N == 1 && "Invalid number of operands!");
1947 // The immediate encodes the type of constant as well as the value.
1948 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1949 unsigned Value = CE->getValue();
1950 if (Value >= 256 && Value <= 0xffff)
1951 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1952 else if (Value > 0xffff && Value <= 0xffffff)
1953 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1954 else if (Value > 0xffffff)
1955 Value = (Value >> 24) | 0x600;
1956 Inst.addOperand(MCOperand::CreateImm(Value));
1959 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
1960 assert(N == 1 && "Invalid number of operands!");
1961 // The immediate encodes the type of constant as well as the value.
1962 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1963 unsigned Value = ~CE->getValue();
1964 if (Value >= 256 && Value <= 0xffff)
1965 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1966 else if (Value > 0xffff && Value <= 0xffffff)
1967 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1968 else if (Value > 0xffffff)
1969 Value = (Value >> 24) | 0x600;
1970 Inst.addOperand(MCOperand::CreateImm(Value));
1973 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
1974 assert(N == 1 && "Invalid number of operands!");
1975 // The immediate encodes the type of constant as well as the value.
1976 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1977 uint64_t Value = CE->getValue();
1979 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
1980 Imm |= (Value & 1) << i;
1982 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
1985 virtual void print(raw_ostream &OS) const;
1987 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
1988 ARMOperand *Op = new ARMOperand(k_ITCondMask);
1989 Op->ITMask.Mask = Mask;
1995 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
1996 ARMOperand *Op = new ARMOperand(k_CondCode);
2003 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2004 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2005 Op->Cop.Val = CopVal;
2011 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2012 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2013 Op->Cop.Val = CopVal;
2019 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2020 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2027 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2028 ARMOperand *Op = new ARMOperand(k_CCOut);
2029 Op->Reg.RegNum = RegNum;
2035 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2036 ARMOperand *Op = new ARMOperand(k_Token);
2037 Op->Tok.Data = Str.data();
2038 Op->Tok.Length = Str.size();
2044 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2045 ARMOperand *Op = new ARMOperand(k_Register);
2046 Op->Reg.RegNum = RegNum;
2052 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2057 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2058 Op->RegShiftedReg.ShiftTy = ShTy;
2059 Op->RegShiftedReg.SrcReg = SrcReg;
2060 Op->RegShiftedReg.ShiftReg = ShiftReg;
2061 Op->RegShiftedReg.ShiftImm = ShiftImm;
2067 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2071 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2072 Op->RegShiftedImm.ShiftTy = ShTy;
2073 Op->RegShiftedImm.SrcReg = SrcReg;
2074 Op->RegShiftedImm.ShiftImm = ShiftImm;
2080 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2082 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2083 Op->ShifterImm.isASR = isASR;
2084 Op->ShifterImm.Imm = Imm;
2090 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2091 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2092 Op->RotImm.Imm = Imm;
2098 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2100 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2101 Op->Bitfield.LSB = LSB;
2102 Op->Bitfield.Width = Width;
2109 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
2110 SMLoc StartLoc, SMLoc EndLoc) {
2111 KindTy Kind = k_RegisterList;
2113 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
2114 Kind = k_DPRRegisterList;
2115 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2116 contains(Regs.front().first))
2117 Kind = k_SPRRegisterList;
2119 ARMOperand *Op = new ARMOperand(Kind);
2120 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
2121 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2122 Op->Registers.push_back(I->first);
2123 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
2124 Op->StartLoc = StartLoc;
2125 Op->EndLoc = EndLoc;
2129 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2130 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2131 ARMOperand *Op = new ARMOperand(k_VectorList);
2132 Op->VectorList.RegNum = RegNum;
2133 Op->VectorList.Count = Count;
2134 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2140 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2141 bool isDoubleSpaced,
2143 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2144 Op->VectorList.RegNum = RegNum;
2145 Op->VectorList.Count = Count;
2146 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2152 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2154 bool isDoubleSpaced,
2156 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2157 Op->VectorList.RegNum = RegNum;
2158 Op->VectorList.Count = Count;
2159 Op->VectorList.LaneIndex = Index;
2160 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2166 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2168 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2169 Op->VectorIndex.Val = Idx;
2175 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2176 ARMOperand *Op = new ARMOperand(k_Immediate);
2183 static ARMOperand *CreateMem(unsigned BaseRegNum,
2184 const MCConstantExpr *OffsetImm,
2185 unsigned OffsetRegNum,
2186 ARM_AM::ShiftOpc ShiftType,
2191 ARMOperand *Op = new ARMOperand(k_Memory);
2192 Op->Memory.BaseRegNum = BaseRegNum;
2193 Op->Memory.OffsetImm = OffsetImm;
2194 Op->Memory.OffsetRegNum = OffsetRegNum;
2195 Op->Memory.ShiftType = ShiftType;
2196 Op->Memory.ShiftImm = ShiftImm;
2197 Op->Memory.Alignment = Alignment;
2198 Op->Memory.isNegative = isNegative;
2204 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2205 ARM_AM::ShiftOpc ShiftTy,
2208 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2209 Op->PostIdxReg.RegNum = RegNum;
2210 Op->PostIdxReg.isAdd = isAdd;
2211 Op->PostIdxReg.ShiftTy = ShiftTy;
2212 Op->PostIdxReg.ShiftImm = ShiftImm;
2218 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2219 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2220 Op->MBOpt.Val = Opt;
2226 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2227 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2228 Op->IFlags.Val = IFlags;
2234 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2235 ARMOperand *Op = new ARMOperand(k_MSRMask);
2236 Op->MMask.Val = MMask;
2243 } // end anonymous namespace.
2245 void ARMOperand::print(raw_ostream &OS) const {
2248 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2251 OS << "<ccout " << getReg() << ">";
2253 case k_ITCondMask: {
2254 static const char *MaskStr[] = {
2255 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2256 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2258 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2259 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2263 OS << "<coprocessor number: " << getCoproc() << ">";
2266 OS << "<coprocessor register: " << getCoproc() << ">";
2268 case k_CoprocOption:
2269 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2272 OS << "<mask: " << getMSRMask() << ">";
2275 getImm()->print(OS);
2277 case k_MemBarrierOpt:
2278 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2282 << " base:" << Memory.BaseRegNum;
2285 case k_PostIndexRegister:
2286 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2287 << PostIdxReg.RegNum;
2288 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2289 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2290 << PostIdxReg.ShiftImm;
2293 case k_ProcIFlags: {
2294 OS << "<ARM_PROC::";
2295 unsigned IFlags = getProcIFlags();
2296 for (int i=2; i >= 0; --i)
2297 if (IFlags & (1 << i))
2298 OS << ARM_PROC::IFlagsToString(1 << i);
2303 OS << "<register " << getReg() << ">";
2305 case k_ShifterImmediate:
2306 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2307 << " #" << ShifterImm.Imm << ">";
2309 case k_ShiftedRegister:
2310 OS << "<so_reg_reg "
2311 << RegShiftedReg.SrcReg << " "
2312 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2313 << " " << RegShiftedReg.ShiftReg << ">";
2315 case k_ShiftedImmediate:
2316 OS << "<so_reg_imm "
2317 << RegShiftedImm.SrcReg << " "
2318 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2319 << " #" << RegShiftedImm.ShiftImm << ">";
2321 case k_RotateImmediate:
2322 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2324 case k_BitfieldDescriptor:
2325 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2326 << ", width: " << Bitfield.Width << ">";
2328 case k_RegisterList:
2329 case k_DPRRegisterList:
2330 case k_SPRRegisterList: {
2331 OS << "<register_list ";
2333 const SmallVectorImpl<unsigned> &RegList = getRegList();
2334 for (SmallVectorImpl<unsigned>::const_iterator
2335 I = RegList.begin(), E = RegList.end(); I != E; ) {
2337 if (++I < E) OS << ", ";
2344 OS << "<vector_list " << VectorList.Count << " * "
2345 << VectorList.RegNum << ">";
2347 case k_VectorListAllLanes:
2348 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2349 << VectorList.RegNum << ">";
2351 case k_VectorListIndexed:
2352 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2353 << VectorList.Count << " * " << VectorList.RegNum << ">";
2356 OS << "'" << getToken() << "'";
2359 OS << "<vectorindex " << getVectorIndex() << ">";
2364 /// @name Auto-generated Match Functions
2367 static unsigned MatchRegisterName(StringRef Name);
2371 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2372 SMLoc &StartLoc, SMLoc &EndLoc) {
2373 StartLoc = Parser.getTok().getLoc();
2374 RegNo = tryParseRegister();
2375 EndLoc = Parser.getTok().getLoc();
2377 return (RegNo == (unsigned)-1);
2380 /// Try to parse a register name. The token must be an Identifier when called,
2381 /// and if it is a register name the token is eaten and the register number is
2382 /// returned. Otherwise return -1.
2384 int ARMAsmParser::tryParseRegister() {
2385 const AsmToken &Tok = Parser.getTok();
2386 if (Tok.isNot(AsmToken::Identifier)) return -1;
2388 std::string lowerCase = Tok.getString().lower();
2389 unsigned RegNum = MatchRegisterName(lowerCase);
2391 RegNum = StringSwitch<unsigned>(lowerCase)
2392 .Case("r13", ARM::SP)
2393 .Case("r14", ARM::LR)
2394 .Case("r15", ARM::PC)
2395 .Case("ip", ARM::R12)
2396 // Additional register name aliases for 'gas' compatibility.
2397 .Case("a1", ARM::R0)
2398 .Case("a2", ARM::R1)
2399 .Case("a3", ARM::R2)
2400 .Case("a4", ARM::R3)
2401 .Case("v1", ARM::R4)
2402 .Case("v2", ARM::R5)
2403 .Case("v3", ARM::R6)
2404 .Case("v4", ARM::R7)
2405 .Case("v5", ARM::R8)
2406 .Case("v6", ARM::R9)
2407 .Case("v7", ARM::R10)
2408 .Case("v8", ARM::R11)
2409 .Case("sb", ARM::R9)
2410 .Case("sl", ARM::R10)
2411 .Case("fp", ARM::R11)
2415 // Check for aliases registered via .req. Canonicalize to lower case.
2416 // That's more consistent since register names are case insensitive, and
2417 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2418 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2419 // If no match, return failure.
2420 if (Entry == RegisterReqs.end())
2422 Parser.Lex(); // Eat identifier token.
2423 return Entry->getValue();
2426 Parser.Lex(); // Eat identifier token.
2431 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2432 // If a recoverable error occurs, return 1. If an irrecoverable error
2433 // occurs, return -1. An irrecoverable error is one where tokens have been
2434 // consumed in the process of trying to parse the shifter (i.e., when it is
2435 // indeed a shifter operand, but malformed).
2436 int ARMAsmParser::tryParseShiftRegister(
2437 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2438 SMLoc S = Parser.getTok().getLoc();
2439 const AsmToken &Tok = Parser.getTok();
2440 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2442 std::string lowerCase = Tok.getString().lower();
2443 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2444 .Case("asl", ARM_AM::lsl)
2445 .Case("lsl", ARM_AM::lsl)
2446 .Case("lsr", ARM_AM::lsr)
2447 .Case("asr", ARM_AM::asr)
2448 .Case("ror", ARM_AM::ror)
2449 .Case("rrx", ARM_AM::rrx)
2450 .Default(ARM_AM::no_shift);
2452 if (ShiftTy == ARM_AM::no_shift)
2455 Parser.Lex(); // Eat the operator.
2457 // The source register for the shift has already been added to the
2458 // operand list, so we need to pop it off and combine it into the shifted
2459 // register operand instead.
2460 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2461 if (!PrevOp->isReg())
2462 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2463 int SrcReg = PrevOp->getReg();
2466 if (ShiftTy == ARM_AM::rrx) {
2467 // RRX Doesn't have an explicit shift amount. The encoder expects
2468 // the shift register to be the same as the source register. Seems odd,
2472 // Figure out if this is shifted by a constant or a register (for non-RRX).
2473 if (Parser.getTok().is(AsmToken::Hash) ||
2474 Parser.getTok().is(AsmToken::Dollar)) {
2475 Parser.Lex(); // Eat hash.
2476 SMLoc ImmLoc = Parser.getTok().getLoc();
2477 const MCExpr *ShiftExpr = 0;
2478 if (getParser().ParseExpression(ShiftExpr)) {
2479 Error(ImmLoc, "invalid immediate shift value");
2482 // The expression must be evaluatable as an immediate.
2483 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2485 Error(ImmLoc, "invalid immediate shift value");
2488 // Range check the immediate.
2489 // lsl, ror: 0 <= imm <= 31
2490 // lsr, asr: 0 <= imm <= 32
2491 Imm = CE->getValue();
2493 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2494 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2495 Error(ImmLoc, "immediate shift value out of range");
2498 // shift by zero is a nop. Always send it through as lsl.
2499 // ('as' compatibility)
2501 ShiftTy = ARM_AM::lsl;
2502 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2503 ShiftReg = tryParseRegister();
2504 SMLoc L = Parser.getTok().getLoc();
2505 if (ShiftReg == -1) {
2506 Error (L, "expected immediate or register in shift operand");
2510 Error (Parser.getTok().getLoc(),
2511 "expected immediate or register in shift operand");
2516 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2517 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2519 S, Parser.getTok().getLoc()));
2521 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2522 S, Parser.getTok().getLoc()));
2528 /// Try to parse a register name. The token must be an Identifier when called.
2529 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2530 /// if there is a "writeback". 'true' if it's not a register.
2532 /// TODO this is likely to change to allow different register types and or to
2533 /// parse for a specific register type.
2535 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2536 SMLoc S = Parser.getTok().getLoc();
2537 int RegNo = tryParseRegister();
2541 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
2543 const AsmToken &ExclaimTok = Parser.getTok();
2544 if (ExclaimTok.is(AsmToken::Exclaim)) {
2545 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2546 ExclaimTok.getLoc()));
2547 Parser.Lex(); // Eat exclaim token
2551 // Also check for an index operand. This is only legal for vector registers,
2552 // but that'll get caught OK in operand matching, so we don't need to
2553 // explicitly filter everything else out here.
2554 if (Parser.getTok().is(AsmToken::LBrac)) {
2555 SMLoc SIdx = Parser.getTok().getLoc();
2556 Parser.Lex(); // Eat left bracket token.
2558 const MCExpr *ImmVal;
2559 if (getParser().ParseExpression(ImmVal))
2561 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2563 return TokError("immediate value expected for vector index");
2565 SMLoc E = Parser.getTok().getLoc();
2566 if (Parser.getTok().isNot(AsmToken::RBrac))
2567 return Error(E, "']' expected");
2569 Parser.Lex(); // Eat right bracket token.
2571 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2579 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2580 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2582 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2583 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2585 switch (Name.size()) {
2588 if (Name[0] != CoprocOp)
2604 if (Name[0] != CoprocOp || Name[1] != '1')
2608 case '0': return 10;
2609 case '1': return 11;
2610 case '2': return 12;
2611 case '3': return 13;
2612 case '4': return 14;
2613 case '5': return 15;
2618 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2619 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2620 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2621 SMLoc S = Parser.getTok().getLoc();
2622 const AsmToken &Tok = Parser.getTok();
2623 if (!Tok.is(AsmToken::Identifier))
2624 return MatchOperand_NoMatch;
2625 unsigned CC = StringSwitch<unsigned>(Tok.getString())
2626 .Case("eq", ARMCC::EQ)
2627 .Case("ne", ARMCC::NE)
2628 .Case("hs", ARMCC::HS)
2629 .Case("cs", ARMCC::HS)
2630 .Case("lo", ARMCC::LO)
2631 .Case("cc", ARMCC::LO)
2632 .Case("mi", ARMCC::MI)
2633 .Case("pl", ARMCC::PL)
2634 .Case("vs", ARMCC::VS)
2635 .Case("vc", ARMCC::VC)
2636 .Case("hi", ARMCC::HI)
2637 .Case("ls", ARMCC::LS)
2638 .Case("ge", ARMCC::GE)
2639 .Case("lt", ARMCC::LT)
2640 .Case("gt", ARMCC::GT)
2641 .Case("le", ARMCC::LE)
2642 .Case("al", ARMCC::AL)
2645 return MatchOperand_NoMatch;
2646 Parser.Lex(); // Eat the token.
2648 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2650 return MatchOperand_Success;
2653 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2654 /// token must be an Identifier when called, and if it is a coprocessor
2655 /// number, the token is eaten and the operand is added to the operand list.
2656 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2657 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2658 SMLoc S = Parser.getTok().getLoc();
2659 const AsmToken &Tok = Parser.getTok();
2660 if (Tok.isNot(AsmToken::Identifier))
2661 return MatchOperand_NoMatch;
2663 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2665 return MatchOperand_NoMatch;
2667 Parser.Lex(); // Eat identifier token.
2668 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2669 return MatchOperand_Success;
2672 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2673 /// token must be an Identifier when called, and if it is a coprocessor
2674 /// number, the token is eaten and the operand is added to the operand list.
2675 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2676 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2677 SMLoc S = Parser.getTok().getLoc();
2678 const AsmToken &Tok = Parser.getTok();
2679 if (Tok.isNot(AsmToken::Identifier))
2680 return MatchOperand_NoMatch;
2682 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2684 return MatchOperand_NoMatch;
2686 Parser.Lex(); // Eat identifier token.
2687 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2688 return MatchOperand_Success;
2691 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2692 /// coproc_option : '{' imm0_255 '}'
2693 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2694 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2695 SMLoc S = Parser.getTok().getLoc();
2697 // If this isn't a '{', this isn't a coprocessor immediate operand.
2698 if (Parser.getTok().isNot(AsmToken::LCurly))
2699 return MatchOperand_NoMatch;
2700 Parser.Lex(); // Eat the '{'
2703 SMLoc Loc = Parser.getTok().getLoc();
2704 if (getParser().ParseExpression(Expr)) {
2705 Error(Loc, "illegal expression");
2706 return MatchOperand_ParseFail;
2708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2709 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2710 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2711 return MatchOperand_ParseFail;
2713 int Val = CE->getValue();
2715 // Check for and consume the closing '}'
2716 if (Parser.getTok().isNot(AsmToken::RCurly))
2717 return MatchOperand_ParseFail;
2718 SMLoc E = Parser.getTok().getLoc();
2719 Parser.Lex(); // Eat the '}'
2721 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2722 return MatchOperand_Success;
2725 // For register list parsing, we need to map from raw GPR register numbering
2726 // to the enumeration values. The enumeration values aren't sorted by
2727 // register number due to our using "sp", "lr" and "pc" as canonical names.
2728 static unsigned getNextRegister(unsigned Reg) {
2729 // If this is a GPR, we need to do it manually, otherwise we can rely
2730 // on the sort ordering of the enumeration since the other reg-classes
2732 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2735 default: llvm_unreachable("Invalid GPR number!");
2736 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2737 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2738 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2739 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2740 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2741 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2742 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2743 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2747 // Return the low-subreg of a given Q register.
2748 static unsigned getDRegFromQReg(unsigned QReg) {
2750 default: llvm_unreachable("expected a Q register!");
2751 case ARM::Q0: return ARM::D0;
2752 case ARM::Q1: return ARM::D2;
2753 case ARM::Q2: return ARM::D4;
2754 case ARM::Q3: return ARM::D6;
2755 case ARM::Q4: return ARM::D8;
2756 case ARM::Q5: return ARM::D10;
2757 case ARM::Q6: return ARM::D12;
2758 case ARM::Q7: return ARM::D14;
2759 case ARM::Q8: return ARM::D16;
2760 case ARM::Q9: return ARM::D18;
2761 case ARM::Q10: return ARM::D20;
2762 case ARM::Q11: return ARM::D22;
2763 case ARM::Q12: return ARM::D24;
2764 case ARM::Q13: return ARM::D26;
2765 case ARM::Q14: return ARM::D28;
2766 case ARM::Q15: return ARM::D30;
2770 /// Parse a register list.
2772 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2773 assert(Parser.getTok().is(AsmToken::LCurly) &&
2774 "Token is not a Left Curly Brace");
2775 SMLoc S = Parser.getTok().getLoc();
2776 Parser.Lex(); // Eat '{' token.
2777 SMLoc RegLoc = Parser.getTok().getLoc();
2779 // Check the first register in the list to see what register class
2780 // this is a list of.
2781 int Reg = tryParseRegister();
2783 return Error(RegLoc, "register expected");
2785 // The reglist instructions have at most 16 registers, so reserve
2786 // space for that many.
2787 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2789 // Allow Q regs and just interpret them as the two D sub-registers.
2790 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2791 Reg = getDRegFromQReg(Reg);
2792 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2795 const MCRegisterClass *RC;
2796 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2797 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2798 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2799 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2800 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2801 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2803 return Error(RegLoc, "invalid register in register list");
2805 // Store the register.
2806 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2808 // This starts immediately after the first register token in the list,
2809 // so we can see either a comma or a minus (range separator) as a legal
2811 while (Parser.getTok().is(AsmToken::Comma) ||
2812 Parser.getTok().is(AsmToken::Minus)) {
2813 if (Parser.getTok().is(AsmToken::Minus)) {
2814 Parser.Lex(); // Eat the minus.
2815 SMLoc EndLoc = Parser.getTok().getLoc();
2816 int EndReg = tryParseRegister();
2818 return Error(EndLoc, "register expected");
2819 // Allow Q regs and just interpret them as the two D sub-registers.
2820 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2821 EndReg = getDRegFromQReg(EndReg) + 1;
2822 // If the register is the same as the start reg, there's nothing
2826 // The register must be in the same register class as the first.
2827 if (!RC->contains(EndReg))
2828 return Error(EndLoc, "invalid register in register list");
2829 // Ranges must go from low to high.
2830 if (getARMRegisterNumbering(Reg) > getARMRegisterNumbering(EndReg))
2831 return Error(EndLoc, "bad range in register list");
2833 // Add all the registers in the range to the register list.
2834 while (Reg != EndReg) {
2835 Reg = getNextRegister(Reg);
2836 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2840 Parser.Lex(); // Eat the comma.
2841 RegLoc = Parser.getTok().getLoc();
2843 const AsmToken RegTok = Parser.getTok();
2844 Reg = tryParseRegister();
2846 return Error(RegLoc, "register expected");
2847 // Allow Q regs and just interpret them as the two D sub-registers.
2848 bool isQReg = false;
2849 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2850 Reg = getDRegFromQReg(Reg);
2853 // The register must be in the same register class as the first.
2854 if (!RC->contains(Reg))
2855 return Error(RegLoc, "invalid register in register list");
2856 // List must be monotonically increasing.
2857 if (getARMRegisterNumbering(Reg) < getARMRegisterNumbering(OldReg))
2858 return Error(RegLoc, "register list not in ascending order");
2859 if (getARMRegisterNumbering(Reg) == getARMRegisterNumbering(OldReg)) {
2860 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2861 ") in register list");
2864 // VFP register lists must also be contiguous.
2865 // It's OK to use the enumeration values directly here rather, as the
2866 // VFP register classes have the enum sorted properly.
2867 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2869 return Error(RegLoc, "non-contiguous register range");
2870 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2872 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
2875 SMLoc E = Parser.getTok().getLoc();
2876 if (Parser.getTok().isNot(AsmToken::RCurly))
2877 return Error(E, "'}' expected");
2878 Parser.Lex(); // Eat '}' token.
2880 // Push the register list operand.
2881 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
2883 // The ARM system instruction variants for LDM/STM have a '^' token here.
2884 if (Parser.getTok().is(AsmToken::Caret)) {
2885 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2886 Parser.Lex(); // Eat '^' token.
2892 // Helper function to parse the lane index for vector lists.
2893 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2894 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2895 Index = 0; // Always return a defined index value.
2896 if (Parser.getTok().is(AsmToken::LBrac)) {
2897 Parser.Lex(); // Eat the '['.
2898 if (Parser.getTok().is(AsmToken::RBrac)) {
2899 // "Dn[]" is the 'all lanes' syntax.
2900 LaneKind = AllLanes;
2901 Parser.Lex(); // Eat the ']'.
2902 return MatchOperand_Success;
2904 const MCExpr *LaneIndex;
2905 SMLoc Loc = Parser.getTok().getLoc();
2906 if (getParser().ParseExpression(LaneIndex)) {
2907 Error(Loc, "illegal expression");
2908 return MatchOperand_ParseFail;
2910 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2912 Error(Loc, "lane index must be empty or an integer");
2913 return MatchOperand_ParseFail;
2915 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2916 Error(Parser.getTok().getLoc(), "']' expected");
2917 return MatchOperand_ParseFail;
2919 Parser.Lex(); // Eat the ']'.
2920 int64_t Val = CE->getValue();
2922 // FIXME: Make this range check context sensitive for .8, .16, .32.
2923 if (Val < 0 || Val > 7) {
2924 Error(Parser.getTok().getLoc(), "lane index out of range");
2925 return MatchOperand_ParseFail;
2928 LaneKind = IndexedLane;
2929 return MatchOperand_Success;
2932 return MatchOperand_Success;
2935 // parse a vector register list
2936 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2937 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2938 VectorLaneTy LaneKind;
2940 SMLoc S = Parser.getTok().getLoc();
2941 // As an extension (to match gas), support a plain D register or Q register
2942 // (without encosing curly braces) as a single or double entry list,
2944 if (Parser.getTok().is(AsmToken::Identifier)) {
2945 int Reg = tryParseRegister();
2947 return MatchOperand_NoMatch;
2948 SMLoc E = Parser.getTok().getLoc();
2949 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
2950 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
2951 if (Res != MatchOperand_Success)
2955 E = Parser.getTok().getLoc();
2956 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
2959 E = Parser.getTok().getLoc();
2960 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
2964 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
2969 return MatchOperand_Success;
2971 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2972 Reg = getDRegFromQReg(Reg);
2973 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
2974 if (Res != MatchOperand_Success)
2978 E = Parser.getTok().getLoc();
2979 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
2980 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
2981 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
2984 E = Parser.getTok().getLoc();
2985 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
2986 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
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 // Two-register operands have been converted to the
3153 // composite register classes.
3155 const MCRegisterClass *RC = (Spacing == 1) ?
3156 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3157 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3158 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3161 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3162 (Spacing == 2), S, E));
3165 // Two-register operands have been converted to the
3166 // composite register classes.
3168 const MCRegisterClass *RC = (Spacing == 1) ?
3169 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3170 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3171 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3173 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3178 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3184 return MatchOperand_Success;
3187 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3188 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3189 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3190 SMLoc S = Parser.getTok().getLoc();
3191 const AsmToken &Tok = Parser.getTok();
3192 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3193 StringRef OptStr = Tok.getString();
3195 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()))
3196 .Case("sy", ARM_MB::SY)
3197 .Case("st", ARM_MB::ST)
3198 .Case("sh", ARM_MB::ISH)
3199 .Case("ish", ARM_MB::ISH)
3200 .Case("shst", ARM_MB::ISHST)
3201 .Case("ishst", ARM_MB::ISHST)
3202 .Case("nsh", ARM_MB::NSH)
3203 .Case("un", ARM_MB::NSH)
3204 .Case("nshst", ARM_MB::NSHST)
3205 .Case("unst", ARM_MB::NSHST)
3206 .Case("osh", ARM_MB::OSH)
3207 .Case("oshst", ARM_MB::OSHST)
3211 return MatchOperand_NoMatch;
3213 Parser.Lex(); // Eat identifier token.
3214 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3215 return MatchOperand_Success;
3218 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3219 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3220 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3221 SMLoc S = Parser.getTok().getLoc();
3222 const AsmToken &Tok = Parser.getTok();
3223 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3224 StringRef IFlagsStr = Tok.getString();
3226 // An iflags string of "none" is interpreted to mean that none of the AIF
3227 // bits are set. Not a terribly useful instruction, but a valid encoding.
3228 unsigned IFlags = 0;
3229 if (IFlagsStr != "none") {
3230 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3231 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3232 .Case("a", ARM_PROC::A)
3233 .Case("i", ARM_PROC::I)
3234 .Case("f", ARM_PROC::F)
3237 // If some specific iflag is already set, it means that some letter is
3238 // present more than once, this is not acceptable.
3239 if (Flag == ~0U || (IFlags & Flag))
3240 return MatchOperand_NoMatch;
3246 Parser.Lex(); // Eat identifier token.
3247 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3248 return MatchOperand_Success;
3251 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3252 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3253 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3254 SMLoc S = Parser.getTok().getLoc();
3255 const AsmToken &Tok = Parser.getTok();
3256 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3257 StringRef Mask = Tok.getString();
3260 // See ARMv6-M 10.1.1
3261 std::string Name = Mask.lower();
3262 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3272 .Case("primask", 16)
3273 .Case("basepri", 17)
3274 .Case("basepri_max", 18)
3275 .Case("faultmask", 19)
3276 .Case("control", 20)
3279 if (FlagsVal == ~0U)
3280 return MatchOperand_NoMatch;
3282 if (!hasV7Ops() && FlagsVal >= 17 && FlagsVal <= 19)
3283 // basepri, basepri_max and faultmask only valid for V7m.
3284 return MatchOperand_NoMatch;
3286 Parser.Lex(); // Eat identifier token.
3287 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3288 return MatchOperand_Success;
3291 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3292 size_t Start = 0, Next = Mask.find('_');
3293 StringRef Flags = "";
3294 std::string SpecReg = Mask.slice(Start, Next).lower();
3295 if (Next != StringRef::npos)
3296 Flags = Mask.slice(Next+1, Mask.size());
3298 // FlagsVal contains the complete mask:
3300 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3301 unsigned FlagsVal = 0;
3303 if (SpecReg == "apsr") {
3304 FlagsVal = StringSwitch<unsigned>(Flags)
3305 .Case("nzcvq", 0x8) // same as CPSR_f
3306 .Case("g", 0x4) // same as CPSR_s
3307 .Case("nzcvqg", 0xc) // same as CPSR_fs
3310 if (FlagsVal == ~0U) {
3312 return MatchOperand_NoMatch;
3314 FlagsVal = 8; // No flag
3316 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3317 if (Flags == "all") // cpsr_all is an alias for cpsr_fc
3319 for (int i = 0, e = Flags.size(); i != e; ++i) {
3320 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3327 // If some specific flag is already set, it means that some letter is
3328 // present more than once, this is not acceptable.
3329 if (FlagsVal == ~0U || (FlagsVal & Flag))
3330 return MatchOperand_NoMatch;
3333 } else // No match for special register.
3334 return MatchOperand_NoMatch;
3336 // Special register without flags is NOT equivalent to "fc" flags.
3337 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3338 // two lines would enable gas compatibility at the expense of breaking
3344 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3345 if (SpecReg == "spsr")
3348 Parser.Lex(); // Eat identifier token.
3349 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3350 return MatchOperand_Success;
3353 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3354 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3355 int Low, int High) {
3356 const AsmToken &Tok = Parser.getTok();
3357 if (Tok.isNot(AsmToken::Identifier)) {
3358 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3359 return MatchOperand_ParseFail;
3361 StringRef ShiftName = Tok.getString();
3362 std::string LowerOp = Op.lower();
3363 std::string UpperOp = Op.upper();
3364 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3365 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3366 return MatchOperand_ParseFail;
3368 Parser.Lex(); // Eat shift type token.
3370 // There must be a '#' and a shift amount.
3371 if (Parser.getTok().isNot(AsmToken::Hash) &&
3372 Parser.getTok().isNot(AsmToken::Dollar)) {
3373 Error(Parser.getTok().getLoc(), "'#' expected");
3374 return MatchOperand_ParseFail;
3376 Parser.Lex(); // Eat hash token.
3378 const MCExpr *ShiftAmount;
3379 SMLoc Loc = Parser.getTok().getLoc();
3380 if (getParser().ParseExpression(ShiftAmount)) {
3381 Error(Loc, "illegal expression");
3382 return MatchOperand_ParseFail;
3384 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3386 Error(Loc, "constant expression expected");
3387 return MatchOperand_ParseFail;
3389 int Val = CE->getValue();
3390 if (Val < Low || Val > High) {
3391 Error(Loc, "immediate value out of range");
3392 return MatchOperand_ParseFail;
3395 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3397 return MatchOperand_Success;
3400 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3401 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3402 const AsmToken &Tok = Parser.getTok();
3403 SMLoc S = Tok.getLoc();
3404 if (Tok.isNot(AsmToken::Identifier)) {
3405 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3406 return MatchOperand_ParseFail;
3408 int Val = StringSwitch<int>(Tok.getString())
3412 Parser.Lex(); // Eat the token.
3415 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3416 return MatchOperand_ParseFail;
3418 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3420 S, Parser.getTok().getLoc()));
3421 return MatchOperand_Success;
3424 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3425 /// instructions. Legal values are:
3426 /// lsl #n 'n' in [0,31]
3427 /// asr #n 'n' in [1,32]
3428 /// n == 32 encoded as n == 0.
3429 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3430 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3431 const AsmToken &Tok = Parser.getTok();
3432 SMLoc S = Tok.getLoc();
3433 if (Tok.isNot(AsmToken::Identifier)) {
3434 Error(S, "shift operator 'asr' or 'lsl' expected");
3435 return MatchOperand_ParseFail;
3437 StringRef ShiftName = Tok.getString();
3439 if (ShiftName == "lsl" || ShiftName == "LSL")
3441 else if (ShiftName == "asr" || ShiftName == "ASR")
3444 Error(S, "shift operator 'asr' or 'lsl' expected");
3445 return MatchOperand_ParseFail;
3447 Parser.Lex(); // Eat the operator.
3449 // A '#' and a shift amount.
3450 if (Parser.getTok().isNot(AsmToken::Hash) &&
3451 Parser.getTok().isNot(AsmToken::Dollar)) {
3452 Error(Parser.getTok().getLoc(), "'#' expected");
3453 return MatchOperand_ParseFail;
3455 Parser.Lex(); // Eat hash token.
3457 const MCExpr *ShiftAmount;
3458 SMLoc E = Parser.getTok().getLoc();
3459 if (getParser().ParseExpression(ShiftAmount)) {
3460 Error(E, "malformed shift expression");
3461 return MatchOperand_ParseFail;
3463 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3465 Error(E, "shift amount must be an immediate");
3466 return MatchOperand_ParseFail;
3469 int64_t Val = CE->getValue();
3471 // Shift amount must be in [1,32]
3472 if (Val < 1 || Val > 32) {
3473 Error(E, "'asr' shift amount must be in range [1,32]");
3474 return MatchOperand_ParseFail;
3476 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3477 if (isThumb() && Val == 32) {
3478 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3479 return MatchOperand_ParseFail;
3481 if (Val == 32) Val = 0;
3483 // Shift amount must be in [1,32]
3484 if (Val < 0 || Val > 31) {
3485 Error(E, "'lsr' shift amount must be in range [0,31]");
3486 return MatchOperand_ParseFail;
3490 E = Parser.getTok().getLoc();
3491 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3493 return MatchOperand_Success;
3496 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3497 /// of instructions. Legal values are:
3498 /// ror #n 'n' in {0, 8, 16, 24}
3499 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3500 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3501 const AsmToken &Tok = Parser.getTok();
3502 SMLoc S = Tok.getLoc();
3503 if (Tok.isNot(AsmToken::Identifier))
3504 return MatchOperand_NoMatch;
3505 StringRef ShiftName = Tok.getString();
3506 if (ShiftName != "ror" && ShiftName != "ROR")
3507 return MatchOperand_NoMatch;
3508 Parser.Lex(); // Eat the operator.
3510 // A '#' and a rotate amount.
3511 if (Parser.getTok().isNot(AsmToken::Hash) &&
3512 Parser.getTok().isNot(AsmToken::Dollar)) {
3513 Error(Parser.getTok().getLoc(), "'#' expected");
3514 return MatchOperand_ParseFail;
3516 Parser.Lex(); // Eat hash token.
3518 const MCExpr *ShiftAmount;
3519 SMLoc E = Parser.getTok().getLoc();
3520 if (getParser().ParseExpression(ShiftAmount)) {
3521 Error(E, "malformed rotate expression");
3522 return MatchOperand_ParseFail;
3524 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3526 Error(E, "rotate amount must be an immediate");
3527 return MatchOperand_ParseFail;
3530 int64_t Val = CE->getValue();
3531 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3532 // normally, zero is represented in asm by omitting the rotate operand
3534 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3535 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3536 return MatchOperand_ParseFail;
3539 E = Parser.getTok().getLoc();
3540 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3542 return MatchOperand_Success;
3545 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3546 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3547 SMLoc S = Parser.getTok().getLoc();
3548 // The bitfield descriptor is really two operands, the LSB and the width.
3549 if (Parser.getTok().isNot(AsmToken::Hash) &&
3550 Parser.getTok().isNot(AsmToken::Dollar)) {
3551 Error(Parser.getTok().getLoc(), "'#' expected");
3552 return MatchOperand_ParseFail;
3554 Parser.Lex(); // Eat hash token.
3556 const MCExpr *LSBExpr;
3557 SMLoc E = Parser.getTok().getLoc();
3558 if (getParser().ParseExpression(LSBExpr)) {
3559 Error(E, "malformed immediate expression");
3560 return MatchOperand_ParseFail;
3562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3564 Error(E, "'lsb' operand must be an immediate");
3565 return MatchOperand_ParseFail;
3568 int64_t LSB = CE->getValue();
3569 // The LSB must be in the range [0,31]
3570 if (LSB < 0 || LSB > 31) {
3571 Error(E, "'lsb' operand must be in the range [0,31]");
3572 return MatchOperand_ParseFail;
3574 E = Parser.getTok().getLoc();
3576 // Expect another immediate operand.
3577 if (Parser.getTok().isNot(AsmToken::Comma)) {
3578 Error(Parser.getTok().getLoc(), "too few operands");
3579 return MatchOperand_ParseFail;
3581 Parser.Lex(); // Eat hash token.
3582 if (Parser.getTok().isNot(AsmToken::Hash) &&
3583 Parser.getTok().isNot(AsmToken::Dollar)) {
3584 Error(Parser.getTok().getLoc(), "'#' expected");
3585 return MatchOperand_ParseFail;
3587 Parser.Lex(); // Eat hash token.
3589 const MCExpr *WidthExpr;
3590 if (getParser().ParseExpression(WidthExpr)) {
3591 Error(E, "malformed immediate expression");
3592 return MatchOperand_ParseFail;
3594 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3596 Error(E, "'width' operand must be an immediate");
3597 return MatchOperand_ParseFail;
3600 int64_t Width = CE->getValue();
3601 // The LSB must be in the range [1,32-lsb]
3602 if (Width < 1 || Width > 32 - LSB) {
3603 Error(E, "'width' operand must be in the range [1,32-lsb]");
3604 return MatchOperand_ParseFail;
3606 E = Parser.getTok().getLoc();
3608 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3610 return MatchOperand_Success;
3613 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3614 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3615 // Check for a post-index addressing register operand. Specifically:
3616 // postidx_reg := '+' register {, shift}
3617 // | '-' register {, shift}
3618 // | register {, shift}
3620 // This method must return MatchOperand_NoMatch without consuming any tokens
3621 // in the case where there is no match, as other alternatives take other
3623 AsmToken Tok = Parser.getTok();
3624 SMLoc S = Tok.getLoc();
3625 bool haveEaten = false;
3628 if (Tok.is(AsmToken::Plus)) {
3629 Parser.Lex(); // Eat the '+' token.
3631 } else if (Tok.is(AsmToken::Minus)) {
3632 Parser.Lex(); // Eat the '-' token.
3636 if (Parser.getTok().is(AsmToken::Identifier))
3637 Reg = tryParseRegister();
3640 return MatchOperand_NoMatch;
3641 Error(Parser.getTok().getLoc(), "register expected");
3642 return MatchOperand_ParseFail;
3644 SMLoc E = Parser.getTok().getLoc();
3646 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3647 unsigned ShiftImm = 0;
3648 if (Parser.getTok().is(AsmToken::Comma)) {
3649 Parser.Lex(); // Eat the ','.
3650 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3651 return MatchOperand_ParseFail;
3654 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3657 return MatchOperand_Success;
3660 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3661 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3662 // Check for a post-index addressing register operand. Specifically:
3663 // am3offset := '+' register
3670 // This method must return MatchOperand_NoMatch without consuming any tokens
3671 // in the case where there is no match, as other alternatives take other
3673 AsmToken Tok = Parser.getTok();
3674 SMLoc S = Tok.getLoc();
3676 // Do immediates first, as we always parse those if we have a '#'.
3677 if (Parser.getTok().is(AsmToken::Hash) ||
3678 Parser.getTok().is(AsmToken::Dollar)) {
3679 Parser.Lex(); // Eat the '#'.
3680 // Explicitly look for a '-', as we need to encode negative zero
3682 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3683 const MCExpr *Offset;
3684 if (getParser().ParseExpression(Offset))
3685 return MatchOperand_ParseFail;
3686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3688 Error(S, "constant expression expected");
3689 return MatchOperand_ParseFail;
3691 SMLoc E = Tok.getLoc();
3692 // Negative zero is encoded as the flag value INT32_MIN.
3693 int32_t Val = CE->getValue();
3694 if (isNegative && Val == 0)
3698 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3700 return MatchOperand_Success;
3704 bool haveEaten = false;
3707 if (Tok.is(AsmToken::Plus)) {
3708 Parser.Lex(); // Eat the '+' token.
3710 } else if (Tok.is(AsmToken::Minus)) {
3711 Parser.Lex(); // Eat the '-' token.
3715 if (Parser.getTok().is(AsmToken::Identifier))
3716 Reg = tryParseRegister();
3719 return MatchOperand_NoMatch;
3720 Error(Parser.getTok().getLoc(), "register expected");
3721 return MatchOperand_ParseFail;
3723 SMLoc E = Parser.getTok().getLoc();
3725 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3728 return MatchOperand_Success;
3731 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
3732 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3733 /// when they refer multiple MIOperands inside a single one.
3735 cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
3736 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3738 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3739 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3740 // Create a writeback register dummy placeholder.
3741 Inst.addOperand(MCOperand::CreateReg(0));
3743 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3745 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3749 /// cvtT2StrdPre - Convert parsed operands to MCInst.
3750 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3751 /// when they refer multiple MIOperands inside a single one.
3753 cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
3754 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3755 // Create a writeback register dummy placeholder.
3756 Inst.addOperand(MCOperand::CreateReg(0));
3758 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3759 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3761 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3763 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3767 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3768 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3769 /// when they refer multiple MIOperands inside a single one.
3771 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3772 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3773 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3775 // Create a writeback register dummy placeholder.
3776 Inst.addOperand(MCOperand::CreateImm(0));
3778 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3779 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3783 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3784 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3785 /// when they refer multiple MIOperands inside a single one.
3787 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3788 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3789 // Create a writeback register dummy placeholder.
3790 Inst.addOperand(MCOperand::CreateImm(0));
3791 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3792 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3793 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3797 /// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3798 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3799 /// when they refer multiple MIOperands inside a single one.
3801 cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
3802 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3803 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3805 // Create a writeback register dummy placeholder.
3806 Inst.addOperand(MCOperand::CreateImm(0));
3808 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3809 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3813 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3814 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3815 /// when they refer multiple MIOperands inside a single one.
3817 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3818 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3819 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3821 // Create a writeback register dummy placeholder.
3822 Inst.addOperand(MCOperand::CreateImm(0));
3824 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3825 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3830 /// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3831 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3832 /// when they refer multiple MIOperands inside a single one.
3834 cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3835 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3836 // Create a writeback register dummy placeholder.
3837 Inst.addOperand(MCOperand::CreateImm(0));
3838 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3839 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3840 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3844 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3845 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3846 /// when they refer multiple MIOperands inside a single one.
3848 cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
3849 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3850 // Create a writeback register dummy placeholder.
3851 Inst.addOperand(MCOperand::CreateImm(0));
3852 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3853 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3854 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3858 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3859 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3860 /// when they refer multiple MIOperands inside a single one.
3862 cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3863 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3864 // Create a writeback register dummy placeholder.
3865 Inst.addOperand(MCOperand::CreateImm(0));
3866 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3867 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3868 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3872 /// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
3873 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3874 /// when they refer multiple MIOperands inside a single one.
3876 cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3877 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3879 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3880 // Create a writeback register dummy placeholder.
3881 Inst.addOperand(MCOperand::CreateImm(0));
3883 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3885 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3887 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3891 /// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
3892 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3893 /// when they refer multiple MIOperands inside a single one.
3895 cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3896 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3898 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3899 // Create a writeback register dummy placeholder.
3900 Inst.addOperand(MCOperand::CreateImm(0));
3902 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3904 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3906 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3910 /// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
3911 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3912 /// when they refer multiple MIOperands inside a single one.
3914 cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3915 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3916 // Create a writeback register dummy placeholder.
3917 Inst.addOperand(MCOperand::CreateImm(0));
3919 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3921 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3923 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3925 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3929 /// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
3930 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3931 /// when they refer multiple MIOperands inside a single one.
3933 cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3934 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3935 // Create a writeback register dummy placeholder.
3936 Inst.addOperand(MCOperand::CreateImm(0));
3938 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3940 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3942 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3944 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3948 /// cvtLdrdPre - Convert parsed operands to MCInst.
3949 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3950 /// when they refer multiple MIOperands inside a single one.
3952 cvtLdrdPre(MCInst &Inst, unsigned Opcode,
3953 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3955 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3956 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3957 // Create a writeback register dummy placeholder.
3958 Inst.addOperand(MCOperand::CreateImm(0));
3960 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3962 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3966 /// cvtStrdPre - Convert parsed operands to MCInst.
3967 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3968 /// when they refer multiple MIOperands inside a single one.
3970 cvtStrdPre(MCInst &Inst, unsigned Opcode,
3971 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3972 // Create a writeback register dummy placeholder.
3973 Inst.addOperand(MCOperand::CreateImm(0));
3975 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3976 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3978 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3980 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3984 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3985 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3986 /// when they refer multiple MIOperands inside a single one.
3988 cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3989 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3990 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3991 // Create a writeback register dummy placeholder.
3992 Inst.addOperand(MCOperand::CreateImm(0));
3993 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3994 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3998 /// cvtThumbMultiple- Convert parsed operands to MCInst.
3999 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4000 /// when they refer multiple MIOperands inside a single one.
4002 cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
4003 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4004 // The second source operand must be the same register as the destination
4006 if (Operands.size() == 6 &&
4007 (((ARMOperand*)Operands[3])->getReg() !=
4008 ((ARMOperand*)Operands[5])->getReg()) &&
4009 (((ARMOperand*)Operands[3])->getReg() !=
4010 ((ARMOperand*)Operands[4])->getReg())) {
4011 Error(Operands[3]->getStartLoc(),
4012 "destination register must match source register");
4015 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4016 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4017 // If we have a three-operand form, make sure to set Rn to be the operand
4018 // that isn't the same as Rd.
4020 if (Operands.size() == 6 &&
4021 ((ARMOperand*)Operands[4])->getReg() ==
4022 ((ARMOperand*)Operands[3])->getReg())
4024 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4025 Inst.addOperand(Inst.getOperand(0));
4026 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4032 cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
4033 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4035 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4036 // Create a writeback register dummy placeholder.
4037 Inst.addOperand(MCOperand::CreateImm(0));
4039 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4041 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4046 cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
4047 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4049 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4050 // Create a writeback register dummy placeholder.
4051 Inst.addOperand(MCOperand::CreateImm(0));
4053 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4055 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4057 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4062 cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
4063 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4064 // Create a writeback register dummy placeholder.
4065 Inst.addOperand(MCOperand::CreateImm(0));
4067 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4069 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4071 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4076 cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
4077 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4078 // Create a writeback register dummy placeholder.
4079 Inst.addOperand(MCOperand::CreateImm(0));
4081 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4083 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4085 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4087 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4091 /// Parse an ARM memory expression, return false if successful else return true
4092 /// or an error. The first token must be a '[' when called.
4094 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4096 assert(Parser.getTok().is(AsmToken::LBrac) &&
4097 "Token is not a Left Bracket");
4098 S = Parser.getTok().getLoc();
4099 Parser.Lex(); // Eat left bracket token.
4101 const AsmToken &BaseRegTok = Parser.getTok();
4102 int BaseRegNum = tryParseRegister();
4103 if (BaseRegNum == -1)
4104 return Error(BaseRegTok.getLoc(), "register expected");
4106 // The next token must either be a comma or a closing bracket.
4107 const AsmToken &Tok = Parser.getTok();
4108 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
4109 return Error(Tok.getLoc(), "malformed memory operand");
4111 if (Tok.is(AsmToken::RBrac)) {
4113 Parser.Lex(); // Eat right bracket token.
4115 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4116 0, 0, false, S, E));
4118 // If there's a pre-indexing writeback marker, '!', just add it as a token
4119 // operand. It's rather odd, but syntactically valid.
4120 if (Parser.getTok().is(AsmToken::Exclaim)) {
4121 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4122 Parser.Lex(); // Eat the '!'.
4128 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4129 Parser.Lex(); // Eat the comma.
4131 // If we have a ':', it's an alignment specifier.
4132 if (Parser.getTok().is(AsmToken::Colon)) {
4133 Parser.Lex(); // Eat the ':'.
4134 E = Parser.getTok().getLoc();
4137 if (getParser().ParseExpression(Expr))
4140 // The expression has to be a constant. Memory references with relocations
4141 // don't come through here, as they use the <label> forms of the relevant
4143 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4145 return Error (E, "constant expression expected");
4148 switch (CE->getValue()) {
4151 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4152 case 16: Align = 2; break;
4153 case 32: Align = 4; break;
4154 case 64: Align = 8; break;
4155 case 128: Align = 16; break;
4156 case 256: Align = 32; break;
4159 // Now we should have the closing ']'
4160 E = Parser.getTok().getLoc();
4161 if (Parser.getTok().isNot(AsmToken::RBrac))
4162 return Error(E, "']' expected");
4163 Parser.Lex(); // Eat right bracket token.
4165 // Don't worry about range checking the value here. That's handled by
4166 // the is*() predicates.
4167 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4168 ARM_AM::no_shift, 0, Align,
4171 // If there's a pre-indexing writeback marker, '!', just add it as a token
4173 if (Parser.getTok().is(AsmToken::Exclaim)) {
4174 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4175 Parser.Lex(); // Eat the '!'.
4181 // If we have a '#', it's an immediate offset, else assume it's a register
4182 // offset. Be friendly and also accept a plain integer (without a leading
4183 // hash) for gas compatibility.
4184 if (Parser.getTok().is(AsmToken::Hash) ||
4185 Parser.getTok().is(AsmToken::Dollar) ||
4186 Parser.getTok().is(AsmToken::Integer)) {
4187 if (Parser.getTok().isNot(AsmToken::Integer))
4188 Parser.Lex(); // Eat the '#'.
4189 E = Parser.getTok().getLoc();
4191 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4192 const MCExpr *Offset;
4193 if (getParser().ParseExpression(Offset))
4196 // The expression has to be a constant. Memory references with relocations
4197 // don't come through here, as they use the <label> forms of the relevant
4199 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4201 return Error (E, "constant expression expected");
4203 // If the constant was #-0, represent it as INT32_MIN.
4204 int32_t Val = CE->getValue();
4205 if (isNegative && Val == 0)
4206 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4208 // Now we should have the closing ']'
4209 E = Parser.getTok().getLoc();
4210 if (Parser.getTok().isNot(AsmToken::RBrac))
4211 return Error(E, "']' expected");
4212 Parser.Lex(); // Eat right bracket token.
4214 // Don't worry about range checking the value here. That's handled by
4215 // the is*() predicates.
4216 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4217 ARM_AM::no_shift, 0, 0,
4220 // If there's a pre-indexing writeback marker, '!', just add it as a token
4222 if (Parser.getTok().is(AsmToken::Exclaim)) {
4223 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4224 Parser.Lex(); // Eat the '!'.
4230 // The register offset is optionally preceded by a '+' or '-'
4231 bool isNegative = false;
4232 if (Parser.getTok().is(AsmToken::Minus)) {
4234 Parser.Lex(); // Eat the '-'.
4235 } else if (Parser.getTok().is(AsmToken::Plus)) {
4237 Parser.Lex(); // Eat the '+'.
4240 E = Parser.getTok().getLoc();
4241 int OffsetRegNum = tryParseRegister();
4242 if (OffsetRegNum == -1)
4243 return Error(E, "register expected");
4245 // If there's a shift operator, handle it.
4246 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4247 unsigned ShiftImm = 0;
4248 if (Parser.getTok().is(AsmToken::Comma)) {
4249 Parser.Lex(); // Eat the ','.
4250 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4254 // Now we should have the closing ']'
4255 E = Parser.getTok().getLoc();
4256 if (Parser.getTok().isNot(AsmToken::RBrac))
4257 return Error(E, "']' expected");
4258 Parser.Lex(); // Eat right bracket token.
4260 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4261 ShiftType, ShiftImm, 0, isNegative,
4264 // If there's a pre-indexing writeback marker, '!', just add it as a token
4266 if (Parser.getTok().is(AsmToken::Exclaim)) {
4267 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4268 Parser.Lex(); // Eat the '!'.
4274 /// parseMemRegOffsetShift - one of these two:
4275 /// ( lsl | lsr | asr | ror ) , # shift_amount
4277 /// return true if it parses a shift otherwise it returns false.
4278 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4280 SMLoc Loc = Parser.getTok().getLoc();
4281 const AsmToken &Tok = Parser.getTok();
4282 if (Tok.isNot(AsmToken::Identifier))
4284 StringRef ShiftName = Tok.getString();
4285 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4286 ShiftName == "asl" || ShiftName == "ASL")
4288 else if (ShiftName == "lsr" || ShiftName == "LSR")
4290 else if (ShiftName == "asr" || ShiftName == "ASR")
4292 else if (ShiftName == "ror" || ShiftName == "ROR")
4294 else if (ShiftName == "rrx" || ShiftName == "RRX")
4297 return Error(Loc, "illegal shift operator");
4298 Parser.Lex(); // Eat shift type token.
4300 // rrx stands alone.
4302 if (St != ARM_AM::rrx) {
4303 Loc = Parser.getTok().getLoc();
4304 // A '#' and a shift amount.
4305 const AsmToken &HashTok = Parser.getTok();
4306 if (HashTok.isNot(AsmToken::Hash) &&
4307 HashTok.isNot(AsmToken::Dollar))
4308 return Error(HashTok.getLoc(), "'#' expected");
4309 Parser.Lex(); // Eat hash token.
4312 if (getParser().ParseExpression(Expr))
4314 // Range check the immediate.
4315 // lsl, ror: 0 <= imm <= 31
4316 // lsr, asr: 0 <= imm <= 32
4317 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4319 return Error(Loc, "shift amount must be an immediate");
4320 int64_t Imm = CE->getValue();
4322 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4323 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4324 return Error(Loc, "immediate shift value out of range");
4331 /// parseFPImm - A floating point immediate expression operand.
4332 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4333 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4334 // Anything that can accept a floating point constant as an operand
4335 // needs to go through here, as the regular ParseExpression is
4338 // This routine still creates a generic Immediate operand, containing
4339 // a bitcast of the 64-bit floating point value. The various operands
4340 // that accept floats can check whether the value is valid for them
4341 // via the standard is*() predicates.
4343 SMLoc S = Parser.getTok().getLoc();
4345 if (Parser.getTok().isNot(AsmToken::Hash) &&
4346 Parser.getTok().isNot(AsmToken::Dollar))
4347 return MatchOperand_NoMatch;
4349 // Disambiguate the VMOV forms that can accept an FP immediate.
4350 // vmov.f32 <sreg>, #imm
4351 // vmov.f64 <dreg>, #imm
4352 // vmov.f32 <dreg>, #imm @ vector f32x2
4353 // vmov.f32 <qreg>, #imm @ vector f32x4
4355 // There are also the NEON VMOV instructions which expect an
4356 // integer constant. Make sure we don't try to parse an FPImm
4358 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4359 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4360 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4361 TyOp->getToken() != ".f64"))
4362 return MatchOperand_NoMatch;
4364 Parser.Lex(); // Eat the '#'.
4366 // Handle negation, as that still comes through as a separate token.
4367 bool isNegative = false;
4368 if (Parser.getTok().is(AsmToken::Minus)) {
4372 const AsmToken &Tok = Parser.getTok();
4373 SMLoc Loc = Tok.getLoc();
4374 if (Tok.is(AsmToken::Real)) {
4375 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4376 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4377 // If we had a '-' in front, toggle the sign bit.
4378 IntVal ^= (uint64_t)isNegative << 31;
4379 Parser.Lex(); // Eat the token.
4380 Operands.push_back(ARMOperand::CreateImm(
4381 MCConstantExpr::Create(IntVal, getContext()),
4382 S, Parser.getTok().getLoc()));
4383 return MatchOperand_Success;
4385 // Also handle plain integers. Instructions which allow floating point
4386 // immediates also allow a raw encoded 8-bit value.
4387 if (Tok.is(AsmToken::Integer)) {
4388 int64_t Val = Tok.getIntVal();
4389 Parser.Lex(); // Eat the token.
4390 if (Val > 255 || Val < 0) {
4391 Error(Loc, "encoded floating point value out of range");
4392 return MatchOperand_ParseFail;
4394 double RealVal = ARM_AM::getFPImmFloat(Val);
4395 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4396 Operands.push_back(ARMOperand::CreateImm(
4397 MCConstantExpr::Create(Val, getContext()), S,
4398 Parser.getTok().getLoc()));
4399 return MatchOperand_Success;
4402 Error(Loc, "invalid floating point immediate");
4403 return MatchOperand_ParseFail;
4406 /// Parse a arm instruction operand. For now this parses the operand regardless
4407 /// of the mnemonic.
4408 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4409 StringRef Mnemonic) {
4412 // Check if the current operand has a custom associated parser, if so, try to
4413 // custom parse the operand, or fallback to the general approach.
4414 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4415 if (ResTy == MatchOperand_Success)
4417 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4418 // there was a match, but an error occurred, in which case, just return that
4419 // the operand parsing failed.
4420 if (ResTy == MatchOperand_ParseFail)
4423 switch (getLexer().getKind()) {
4425 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4427 case AsmToken::Identifier: {
4428 if (!tryParseRegisterWithWriteBack(Operands))
4430 int Res = tryParseShiftRegister(Operands);
4431 if (Res == 0) // success
4433 else if (Res == -1) // irrecoverable error
4435 // If this is VMRS, check for the apsr_nzcv operand.
4436 if (Mnemonic == "vmrs" &&
4437 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4438 S = Parser.getTok().getLoc();
4440 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4444 // Fall though for the Identifier case that is not a register or a
4447 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4448 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4449 case AsmToken::String: // quoted label names.
4450 case AsmToken::Dot: { // . as a branch target
4451 // This was not a register so parse other operands that start with an
4452 // identifier (like labels) as expressions and create them as immediates.
4453 const MCExpr *IdVal;
4454 S = Parser.getTok().getLoc();
4455 if (getParser().ParseExpression(IdVal))
4457 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4458 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4461 case AsmToken::LBrac:
4462 return parseMemory(Operands);
4463 case AsmToken::LCurly:
4464 return parseRegisterList(Operands);
4465 case AsmToken::Dollar:
4466 case AsmToken::Hash: {
4467 // #42 -> immediate.
4468 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
4469 S = Parser.getTok().getLoc();
4471 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4472 const MCExpr *ImmVal;
4473 if (getParser().ParseExpression(ImmVal))
4475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4477 int32_t Val = CE->getValue();
4478 if (isNegative && Val == 0)
4479 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4481 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4482 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4485 case AsmToken::Colon: {
4486 // ":lower16:" and ":upper16:" expression prefixes
4487 // FIXME: Check it's an expression prefix,
4488 // e.g. (FOO - :lower16:BAR) isn't legal.
4489 ARMMCExpr::VariantKind RefKind;
4490 if (parsePrefix(RefKind))
4493 const MCExpr *SubExprVal;
4494 if (getParser().ParseExpression(SubExprVal))
4497 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4499 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4500 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4506 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4507 // :lower16: and :upper16:.
4508 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4509 RefKind = ARMMCExpr::VK_ARM_None;
4511 // :lower16: and :upper16: modifiers
4512 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4513 Parser.Lex(); // Eat ':'
4515 if (getLexer().isNot(AsmToken::Identifier)) {
4516 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4520 StringRef IDVal = Parser.getTok().getIdentifier();
4521 if (IDVal == "lower16") {
4522 RefKind = ARMMCExpr::VK_ARM_LO16;
4523 } else if (IDVal == "upper16") {
4524 RefKind = ARMMCExpr::VK_ARM_HI16;
4526 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4531 if (getLexer().isNot(AsmToken::Colon)) {
4532 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4535 Parser.Lex(); // Eat the last ':'
4539 /// \brief Given a mnemonic, split out possible predication code and carry
4540 /// setting letters to form a canonical mnemonic and flags.
4542 // FIXME: Would be nice to autogen this.
4543 // FIXME: This is a bit of a maze of special cases.
4544 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4545 unsigned &PredicationCode,
4547 unsigned &ProcessorIMod,
4548 StringRef &ITMask) {
4549 PredicationCode = ARMCC::AL;
4550 CarrySetting = false;
4553 // Ignore some mnemonics we know aren't predicated forms.
4555 // FIXME: Would be nice to autogen this.
4556 if ((Mnemonic == "movs" && isThumb()) ||
4557 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4558 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4559 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4560 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4561 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4562 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4563 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4564 Mnemonic == "fmuls")
4567 // First, split out any predication code. Ignore mnemonics we know aren't
4568 // predicated but do have a carry-set and so weren't caught above.
4569 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4570 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4571 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4572 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4573 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4574 .Case("eq", ARMCC::EQ)
4575 .Case("ne", ARMCC::NE)
4576 .Case("hs", ARMCC::HS)
4577 .Case("cs", ARMCC::HS)
4578 .Case("lo", ARMCC::LO)
4579 .Case("cc", ARMCC::LO)
4580 .Case("mi", ARMCC::MI)
4581 .Case("pl", ARMCC::PL)
4582 .Case("vs", ARMCC::VS)
4583 .Case("vc", ARMCC::VC)
4584 .Case("hi", ARMCC::HI)
4585 .Case("ls", ARMCC::LS)
4586 .Case("ge", ARMCC::GE)
4587 .Case("lt", ARMCC::LT)
4588 .Case("gt", ARMCC::GT)
4589 .Case("le", ARMCC::LE)
4590 .Case("al", ARMCC::AL)
4593 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4594 PredicationCode = CC;
4598 // Next, determine if we have a carry setting bit. We explicitly ignore all
4599 // the instructions we know end in 's'.
4600 if (Mnemonic.endswith("s") &&
4601 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4602 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4603 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4604 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4605 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4606 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4607 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4608 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4609 (Mnemonic == "movs" && isThumb()))) {
4610 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4611 CarrySetting = true;
4614 // The "cps" instruction can have a interrupt mode operand which is glued into
4615 // the mnemonic. Check if this is the case, split it and parse the imod op
4616 if (Mnemonic.startswith("cps")) {
4617 // Split out any imod code.
4619 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4620 .Case("ie", ARM_PROC::IE)
4621 .Case("id", ARM_PROC::ID)
4624 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4625 ProcessorIMod = IMod;
4629 // The "it" instruction has the condition mask on the end of the mnemonic.
4630 if (Mnemonic.startswith("it")) {
4631 ITMask = Mnemonic.slice(2, Mnemonic.size());
4632 Mnemonic = Mnemonic.slice(0, 2);
4638 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4639 /// inclusion of carry set or predication code operands.
4641 // FIXME: It would be nice to autogen this.
4643 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4644 bool &CanAcceptPredicationCode) {
4645 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4646 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4647 Mnemonic == "add" || Mnemonic == "adc" ||
4648 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4649 Mnemonic == "orr" || Mnemonic == "mvn" ||
4650 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4651 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4652 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4653 Mnemonic == "mla" || Mnemonic == "smlal" ||
4654 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4655 CanAcceptCarrySet = true;
4657 CanAcceptCarrySet = false;
4659 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4660 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4661 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4662 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
4663 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4664 (Mnemonic == "clrex" && !isThumb()) ||
4665 (Mnemonic == "nop" && isThumbOne()) ||
4666 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4667 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4668 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
4669 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4671 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
4672 CanAcceptPredicationCode = false;
4674 CanAcceptPredicationCode = true;
4677 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
4678 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
4679 CanAcceptPredicationCode = false;
4683 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4684 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4685 // FIXME: This is all horribly hacky. We really need a better way to deal
4686 // with optional operands like this in the matcher table.
4688 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4689 // another does not. Specifically, the MOVW instruction does not. So we
4690 // special case it here and remove the defaulted (non-setting) cc_out
4691 // operand if that's the instruction we're trying to match.
4693 // We do this as post-processing of the explicit operands rather than just
4694 // conditionally adding the cc_out in the first place because we need
4695 // to check the type of the parsed immediate operand.
4696 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4697 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4698 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4699 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4702 // Register-register 'add' for thumb does not have a cc_out operand
4703 // when there are only two register operands.
4704 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4705 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4706 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4707 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4709 // Register-register 'add' for thumb does not have a cc_out operand
4710 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4711 // have to check the immediate range here since Thumb2 has a variant
4712 // that can handle a different range and has a cc_out operand.
4713 if (((isThumb() && Mnemonic == "add") ||
4714 (isThumbTwo() && Mnemonic == "sub")) &&
4715 Operands.size() == 6 &&
4716 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4717 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4718 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4719 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4720 (static_cast<ARMOperand*>(Operands[5])->isReg() ||
4721 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4723 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4724 // imm0_4095 variant. That's the least-preferred variant when
4725 // selecting via the generic "add" mnemonic, so to know that we
4726 // should remove the cc_out operand, we have to explicitly check that
4727 // it's not one of the other variants. Ugh.
4728 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4729 Operands.size() == 6 &&
4730 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4731 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4732 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4733 // Nest conditions rather than one big 'if' statement for readability.
4735 // If either register is a high reg, it's either one of the SP
4736 // variants (handled above) or a 32-bit encoding, so we just
4737 // check against T3. If the second register is the PC, this is an
4738 // alternate form of ADR, which uses encoding T4, so check for that too.
4739 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4740 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
4741 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4742 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4744 // If both registers are low, we're in an IT block, and the immediate is
4745 // in range, we should use encoding T1 instead, which has a cc_out.
4747 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4748 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4749 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4752 // Otherwise, we use encoding T4, which does not have a cc_out
4757 // The thumb2 multiply instruction doesn't have a CCOut register, so
4758 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4759 // use the 16-bit encoding or not.
4760 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4761 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4762 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4763 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4764 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4765 // If the registers aren't low regs, the destination reg isn't the
4766 // same as one of the source regs, or the cc_out operand is zero
4767 // outside of an IT block, we have to use the 32-bit encoding, so
4768 // remove the cc_out operand.
4769 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4770 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4771 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4773 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4774 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4775 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4776 static_cast<ARMOperand*>(Operands[4])->getReg())))
4779 // Also check the 'mul' syntax variant that doesn't specify an explicit
4780 // destination register.
4781 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4782 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4783 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4784 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4785 // If the registers aren't low regs or the cc_out operand is zero
4786 // outside of an IT block, we have to use the 32-bit encoding, so
4787 // remove the cc_out operand.
4788 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4789 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4795 // Register-register 'add/sub' for thumb does not have a cc_out operand
4796 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4797 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4798 // right, this will result in better diagnostics (which operand is off)
4800 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4801 (Operands.size() == 5 || Operands.size() == 6) &&
4802 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4803 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4804 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4810 static bool isDataTypeToken(StringRef Tok) {
4811 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4812 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4813 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4814 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4815 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4816 Tok == ".f" || Tok == ".d";
4819 // FIXME: This bit should probably be handled via an explicit match class
4820 // in the .td files that matches the suffix instead of having it be
4821 // a literal string token the way it is now.
4822 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4823 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4826 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
4827 /// Parse an arm instruction mnemonic followed by its operands.
4828 bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4829 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4830 // Apply mnemonic aliases before doing anything else, as the destination
4831 // mnemnonic may include suffices and we want to handle them normally.
4832 // The generic tblgen'erated code does this later, at the start of
4833 // MatchInstructionImpl(), but that's too late for aliases that include
4834 // any sort of suffix.
4835 unsigned AvailableFeatures = getAvailableFeatures();
4836 applyMnemonicAliases(Name, AvailableFeatures);
4838 // First check for the ARM-specific .req directive.
4839 if (Parser.getTok().is(AsmToken::Identifier) &&
4840 Parser.getTok().getIdentifier() == ".req") {
4841 parseDirectiveReq(Name, NameLoc);
4842 // We always return 'error' for this, as we're done with this
4843 // statement and don't need to match the 'instruction."
4847 // Create the leading tokens for the mnemonic, split by '.' characters.
4848 size_t Start = 0, Next = Name.find('.');
4849 StringRef Mnemonic = Name.slice(Start, Next);
4851 // Split out the predication code and carry setting flag from the mnemonic.
4852 unsigned PredicationCode;
4853 unsigned ProcessorIMod;
4856 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
4857 ProcessorIMod, ITMask);
4859 // In Thumb1, only the branch (B) instruction can be predicated.
4860 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4861 Parser.EatToEndOfStatement();
4862 return Error(NameLoc, "conditional execution not supported in Thumb1");
4865 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4867 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4868 // is the mask as it will be for the IT encoding if the conditional
4869 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4870 // where the conditional bit0 is zero, the instruction post-processing
4871 // will adjust the mask accordingly.
4872 if (Mnemonic == "it") {
4873 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4874 if (ITMask.size() > 3) {
4875 Parser.EatToEndOfStatement();
4876 return Error(Loc, "too many conditions on IT instruction");
4879 for (unsigned i = ITMask.size(); i != 0; --i) {
4880 char pos = ITMask[i - 1];
4881 if (pos != 't' && pos != 'e') {
4882 Parser.EatToEndOfStatement();
4883 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
4886 if (ITMask[i - 1] == 't')
4889 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
4892 // FIXME: This is all a pretty gross hack. We should automatically handle
4893 // optional operands like this via tblgen.
4895 // Next, add the CCOut and ConditionCode operands, if needed.
4897 // For mnemonics which can ever incorporate a carry setting bit or predication
4898 // code, our matching model involves us always generating CCOut and
4899 // ConditionCode operands to match the mnemonic "as written" and then we let
4900 // the matcher deal with finding the right instruction or generating an
4901 // appropriate error.
4902 bool CanAcceptCarrySet, CanAcceptPredicationCode;
4903 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
4905 // If we had a carry-set on an instruction that can't do that, issue an
4907 if (!CanAcceptCarrySet && CarrySetting) {
4908 Parser.EatToEndOfStatement();
4909 return Error(NameLoc, "instruction '" + Mnemonic +
4910 "' can not set flags, but 's' suffix specified");
4912 // If we had a predication code on an instruction that can't do that, issue an
4914 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
4915 Parser.EatToEndOfStatement();
4916 return Error(NameLoc, "instruction '" + Mnemonic +
4917 "' is not predicable, but condition code specified");
4920 // Add the carry setting operand, if necessary.
4921 if (CanAcceptCarrySet) {
4922 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
4923 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
4927 // Add the predication code operand, if necessary.
4928 if (CanAcceptPredicationCode) {
4929 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
4931 Operands.push_back(ARMOperand::CreateCondCode(
4932 ARMCC::CondCodes(PredicationCode), Loc));
4935 // Add the processor imod operand, if necessary.
4936 if (ProcessorIMod) {
4937 Operands.push_back(ARMOperand::CreateImm(
4938 MCConstantExpr::Create(ProcessorIMod, getContext()),
4942 // Add the remaining tokens in the mnemonic.
4943 while (Next != StringRef::npos) {
4945 Next = Name.find('.', Start + 1);
4946 StringRef ExtraToken = Name.slice(Start, Next);
4948 // Some NEON instructions have an optional datatype suffix that is
4949 // completely ignored. Check for that.
4950 if (isDataTypeToken(ExtraToken) &&
4951 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
4954 if (ExtraToken != ".n") {
4955 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
4956 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
4960 // Read the remaining operands.
4961 if (getLexer().isNot(AsmToken::EndOfStatement)) {
4962 // Read the first operand.
4963 if (parseOperand(Operands, Mnemonic)) {
4964 Parser.EatToEndOfStatement();
4968 while (getLexer().is(AsmToken::Comma)) {
4969 Parser.Lex(); // Eat the comma.
4971 // Parse and remember the operand.
4972 if (parseOperand(Operands, Mnemonic)) {
4973 Parser.EatToEndOfStatement();
4979 if (getLexer().isNot(AsmToken::EndOfStatement)) {
4980 SMLoc Loc = getLexer().getLoc();
4981 Parser.EatToEndOfStatement();
4982 return Error(Loc, "unexpected token in argument list");
4985 Parser.Lex(); // Consume the EndOfStatement
4987 // Some instructions, mostly Thumb, have forms for the same mnemonic that
4988 // do and don't have a cc_out optional-def operand. With some spot-checks
4989 // of the operand list, we can figure out which variant we're trying to
4990 // parse and adjust accordingly before actually matching. We shouldn't ever
4991 // try to remove a cc_out operand that was explicitly set on the the
4992 // mnemonic, of course (CarrySetting == true). Reason number #317 the
4993 // table driven matcher doesn't fit well with the ARM instruction set.
4994 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
4995 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
4996 Operands.erase(Operands.begin() + 1);
5000 // ARM mode 'blx' need special handling, as the register operand version
5001 // is predicable, but the label operand version is not. So, we can't rely
5002 // on the Mnemonic based checking to correctly figure out when to put
5003 // a k_CondCode operand in the list. If we're trying to match the label
5004 // version, remove the k_CondCode operand here.
5005 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5006 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5007 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5008 Operands.erase(Operands.begin() + 1);
5012 // The vector-compare-to-zero instructions have a literal token "#0" at
5013 // the end that comes to here as an immediate operand. Convert it to a
5014 // token to play nicely with the matcher.
5015 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5016 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5017 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5018 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5019 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5020 if (CE && CE->getValue() == 0) {
5021 Operands.erase(Operands.begin() + 5);
5022 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5026 // VCMP{E} does the same thing, but with a different operand count.
5027 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5028 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5029 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5030 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5031 if (CE && CE->getValue() == 0) {
5032 Operands.erase(Operands.begin() + 4);
5033 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5037 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
5038 // end. Convert it to a token here. Take care not to convert those
5039 // that should hit the Thumb2 encoding.
5040 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
5041 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5042 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5043 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5044 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5045 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5046 if (CE && CE->getValue() == 0 &&
5048 // The cc_out operand matches the IT block.
5049 ((inITBlock() != CarrySetting) &&
5050 // Neither register operand is a high register.
5051 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5052 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
5053 Operands.erase(Operands.begin() + 5);
5054 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5062 // Validate context-sensitive operand constraints.
5064 // return 'true' if register list contains non-low GPR registers,
5065 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5066 // 'containsReg' to true.
5067 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5068 unsigned HiReg, bool &containsReg) {
5069 containsReg = false;
5070 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5071 unsigned OpReg = Inst.getOperand(i).getReg();
5074 // Anything other than a low register isn't legal here.
5075 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5081 // Check if the specified regisgter is in the register list of the inst,
5082 // starting at the indicated operand number.
5083 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5084 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5085 unsigned OpReg = Inst.getOperand(i).getReg();
5092 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5093 // the ARMInsts array) instead. Getting that here requires awkward
5094 // API changes, though. Better way?
5096 extern const MCInstrDesc ARMInsts[];
5098 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5099 return ARMInsts[Opcode];
5102 // FIXME: We would really like to be able to tablegen'erate this.
5104 validateInstruction(MCInst &Inst,
5105 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5106 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5107 SMLoc Loc = Operands[0]->getStartLoc();
5108 // Check the IT block state first.
5109 // NOTE: BKPT instruction has the interesting property of being
5110 // allowed in IT blocks, but not being predicable. It just always
5112 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5113 Inst.getOpcode() != ARM::BKPT) {
5115 if (ITState.FirstCond)
5116 ITState.FirstCond = false;
5118 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5119 // The instruction must be predicable.
5120 if (!MCID.isPredicable())
5121 return Error(Loc, "instructions in IT block must be predicable");
5122 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5123 unsigned ITCond = bit ? ITState.Cond :
5124 ARMCC::getOppositeCondition(ITState.Cond);
5125 if (Cond != ITCond) {
5126 // Find the condition code Operand to get its SMLoc information.
5128 for (unsigned i = 1; i < Operands.size(); ++i)
5129 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5130 CondLoc = Operands[i]->getStartLoc();
5131 return Error(CondLoc, "incorrect condition in IT block; got '" +
5132 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5133 "', but expected '" +
5134 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5136 // Check for non-'al' condition codes outside of the IT block.
5137 } else if (isThumbTwo() && MCID.isPredicable() &&
5138 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5139 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5140 Inst.getOpcode() != ARM::t2B)
5141 return Error(Loc, "predicated instructions must be in IT block");
5143 switch (Inst.getOpcode()) {
5146 case ARM::LDRD_POST:
5148 // Rt2 must be Rt + 1.
5149 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5150 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5152 return Error(Operands[3]->getStartLoc(),
5153 "destination operands must be sequential");
5157 // Rt2 must be Rt + 1.
5158 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5159 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5161 return Error(Operands[3]->getStartLoc(),
5162 "source operands must be sequential");
5166 case ARM::STRD_POST:
5168 // Rt2 must be Rt + 1.
5169 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5170 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(2).getReg());
5172 return Error(Operands[3]->getStartLoc(),
5173 "source operands must be sequential");
5178 // width must be in range [1, 32-lsb]
5179 unsigned lsb = Inst.getOperand(2).getImm();
5180 unsigned widthm1 = Inst.getOperand(3).getImm();
5181 if (widthm1 >= 32 - lsb)
5182 return Error(Operands[5]->getStartLoc(),
5183 "bitfield width must be in range [1,32-lsb]");
5187 // If we're parsing Thumb2, the .w variant is available and handles
5188 // most cases that are normally illegal for a Thumb1 LDM
5189 // instruction. We'll make the transformation in processInstruction()
5192 // Thumb LDM instructions are writeback iff the base register is not
5193 // in the register list.
5194 unsigned Rn = Inst.getOperand(0).getReg();
5195 bool hasWritebackToken =
5196 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5197 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5198 bool listContainsBase;
5199 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5200 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5201 "registers must be in range r0-r7");
5202 // If we should have writeback, then there should be a '!' token.
5203 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5204 return Error(Operands[2]->getStartLoc(),
5205 "writeback operator '!' expected");
5206 // If we should not have writeback, there must not be a '!'. This is
5207 // true even for the 32-bit wide encodings.
5208 if (listContainsBase && hasWritebackToken)
5209 return Error(Operands[3]->getStartLoc(),
5210 "writeback operator '!' not allowed when base register "
5211 "in register list");
5215 case ARM::t2LDMIA_UPD: {
5216 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5217 return Error(Operands[4]->getStartLoc(),
5218 "writeback operator '!' not allowed when base register "
5219 "in register list");
5222 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5223 // so only issue a diagnostic for thumb1. The instructions will be
5224 // switched to the t2 encodings in processInstruction() if necessary.
5226 bool listContainsBase;
5227 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5229 return Error(Operands[2]->getStartLoc(),
5230 "registers must be in range r0-r7 or pc");
5234 bool listContainsBase;
5235 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5237 return Error(Operands[2]->getStartLoc(),
5238 "registers must be in range r0-r7 or lr");
5241 case ARM::tSTMIA_UPD: {
5242 bool listContainsBase;
5243 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5244 return Error(Operands[4]->getStartLoc(),
5245 "registers must be in range r0-r7");
5253 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5255 default: llvm_unreachable("unexpected opcode!");
5257 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5258 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5259 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5260 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5261 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5262 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5263 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5264 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5265 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5268 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5269 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5270 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5271 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5272 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5274 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5275 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5276 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5277 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5278 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5280 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5281 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5282 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5283 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5284 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5287 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5288 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5289 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5290 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5291 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5292 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5293 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5294 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5295 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5296 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5297 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5298 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5299 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5300 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5301 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5304 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5305 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5306 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5307 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5308 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5309 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5310 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5311 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5312 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5313 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5314 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5315 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5316 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5317 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5318 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5319 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5320 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5321 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5324 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5325 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5326 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5327 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5328 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5329 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5330 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5331 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5332 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5333 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5334 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5335 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5336 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5337 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5338 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5341 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5342 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5343 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5344 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5345 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5346 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5347 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5348 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5349 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5350 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5351 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5352 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5353 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5354 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5355 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5356 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5357 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5358 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5362 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5364 default: llvm_unreachable("unexpected opcode!");
5366 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5367 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5368 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5369 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5370 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5371 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5372 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5373 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5374 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5377 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5378 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5379 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5380 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5381 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5382 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5383 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5384 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5385 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5386 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5387 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5388 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5389 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5390 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5391 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5394 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5395 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5396 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5397 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5398 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5399 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5400 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5401 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5402 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5403 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5404 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5405 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5406 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5407 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5408 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5409 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5410 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5411 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5414 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5415 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5416 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5417 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5418 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5419 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5420 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5421 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5422 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5423 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5424 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5425 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5426 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5427 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5428 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5431 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5432 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5433 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5434 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5435 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5436 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5437 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5438 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5439 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5440 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5441 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5442 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5443 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5444 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5445 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5446 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5447 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5448 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5451 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5452 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5453 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5454 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5455 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5456 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5457 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5458 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5459 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5460 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5461 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5462 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5463 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5464 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5465 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5468 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5469 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5470 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5471 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5472 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5473 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5474 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5475 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5476 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5477 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5478 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5479 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5480 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5481 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5482 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5483 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5484 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5485 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5488 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5489 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5490 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5491 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5492 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5493 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5494 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5495 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5496 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5497 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5498 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5499 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5500 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5501 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5502 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5503 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5504 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5505 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5510 processInstruction(MCInst &Inst,
5511 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5512 switch (Inst.getOpcode()) {
5513 // Aliases for alternate PC+imm syntax of LDR instructions.
5514 case ARM::t2LDRpcrel:
5515 Inst.setOpcode(ARM::t2LDRpci);
5517 case ARM::t2LDRBpcrel:
5518 Inst.setOpcode(ARM::t2LDRBpci);
5520 case ARM::t2LDRHpcrel:
5521 Inst.setOpcode(ARM::t2LDRHpci);
5523 case ARM::t2LDRSBpcrel:
5524 Inst.setOpcode(ARM::t2LDRSBpci);
5526 case ARM::t2LDRSHpcrel:
5527 Inst.setOpcode(ARM::t2LDRSHpci);
5529 // Handle NEON VST complex aliases.
5530 case ARM::VST1LNdWB_register_Asm_8:
5531 case ARM::VST1LNdWB_register_Asm_16:
5532 case ARM::VST1LNdWB_register_Asm_32: {
5534 // Shuffle the operands around so the lane index operand is in the
5537 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5538 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5539 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5540 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5541 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5542 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5543 TmpInst.addOperand(Inst.getOperand(1)); // lane
5544 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5545 TmpInst.addOperand(Inst.getOperand(6));
5550 case ARM::VST2LNdWB_register_Asm_8:
5551 case ARM::VST2LNdWB_register_Asm_16:
5552 case ARM::VST2LNdWB_register_Asm_32:
5553 case ARM::VST2LNqWB_register_Asm_16:
5554 case ARM::VST2LNqWB_register_Asm_32: {
5556 // Shuffle the operands around so the lane index operand is in the
5559 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5560 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5561 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5562 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5563 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5564 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5565 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5567 TmpInst.addOperand(Inst.getOperand(1)); // lane
5568 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5569 TmpInst.addOperand(Inst.getOperand(6));
5574 case ARM::VST3LNdWB_register_Asm_8:
5575 case ARM::VST3LNdWB_register_Asm_16:
5576 case ARM::VST3LNdWB_register_Asm_32:
5577 case ARM::VST3LNqWB_register_Asm_16:
5578 case ARM::VST3LNqWB_register_Asm_32: {
5580 // Shuffle the operands around so the lane index operand is in the
5583 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5584 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5585 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5586 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5587 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5588 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5589 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5591 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5593 TmpInst.addOperand(Inst.getOperand(1)); // lane
5594 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5595 TmpInst.addOperand(Inst.getOperand(6));
5600 case ARM::VST4LNdWB_register_Asm_8:
5601 case ARM::VST4LNdWB_register_Asm_16:
5602 case ARM::VST4LNdWB_register_Asm_32:
5603 case ARM::VST4LNqWB_register_Asm_16:
5604 case ARM::VST4LNqWB_register_Asm_32: {
5606 // Shuffle the operands around so the lane index operand is in the
5609 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5610 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5611 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5612 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5613 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5614 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5615 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5617 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5621 TmpInst.addOperand(Inst.getOperand(1)); // lane
5622 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5623 TmpInst.addOperand(Inst.getOperand(6));
5628 case ARM::VST1LNdWB_fixed_Asm_8:
5629 case ARM::VST1LNdWB_fixed_Asm_16:
5630 case ARM::VST1LNdWB_fixed_Asm_32: {
5632 // Shuffle the operands around so the lane index operand is in the
5635 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5636 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5637 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5638 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5639 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5640 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5641 TmpInst.addOperand(Inst.getOperand(1)); // lane
5642 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5643 TmpInst.addOperand(Inst.getOperand(5));
5648 case ARM::VST2LNdWB_fixed_Asm_8:
5649 case ARM::VST2LNdWB_fixed_Asm_16:
5650 case ARM::VST2LNdWB_fixed_Asm_32:
5651 case ARM::VST2LNqWB_fixed_Asm_16:
5652 case ARM::VST2LNqWB_fixed_Asm_32: {
5654 // Shuffle the operands around so the lane index operand is in the
5657 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5658 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5659 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5660 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5661 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5662 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5665 TmpInst.addOperand(Inst.getOperand(1)); // lane
5666 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5667 TmpInst.addOperand(Inst.getOperand(5));
5672 case ARM::VST3LNdWB_fixed_Asm_8:
5673 case ARM::VST3LNdWB_fixed_Asm_16:
5674 case ARM::VST3LNdWB_fixed_Asm_32:
5675 case ARM::VST3LNqWB_fixed_Asm_16:
5676 case ARM::VST3LNqWB_fixed_Asm_32: {
5678 // Shuffle the operands around so the lane index operand is in the
5681 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5682 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5683 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5684 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5685 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5686 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5687 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5689 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5691 TmpInst.addOperand(Inst.getOperand(1)); // lane
5692 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5693 TmpInst.addOperand(Inst.getOperand(5));
5698 case ARM::VST4LNdWB_fixed_Asm_8:
5699 case ARM::VST4LNdWB_fixed_Asm_16:
5700 case ARM::VST4LNdWB_fixed_Asm_32:
5701 case ARM::VST4LNqWB_fixed_Asm_16:
5702 case ARM::VST4LNqWB_fixed_Asm_32: {
5704 // Shuffle the operands around so the lane index operand is in the
5707 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5708 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5709 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5710 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5711 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5712 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5713 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5715 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5717 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5719 TmpInst.addOperand(Inst.getOperand(1)); // lane
5720 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5721 TmpInst.addOperand(Inst.getOperand(5));
5726 case ARM::VST1LNdAsm_8:
5727 case ARM::VST1LNdAsm_16:
5728 case ARM::VST1LNdAsm_32: {
5730 // Shuffle the operands around so the lane index operand is in the
5733 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5734 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5735 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5736 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5737 TmpInst.addOperand(Inst.getOperand(1)); // lane
5738 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5739 TmpInst.addOperand(Inst.getOperand(5));
5744 case ARM::VST2LNdAsm_8:
5745 case ARM::VST2LNdAsm_16:
5746 case ARM::VST2LNdAsm_32:
5747 case ARM::VST2LNqAsm_16:
5748 case ARM::VST2LNqAsm_32: {
5750 // Shuffle the operands around so the lane index operand is in the
5753 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5754 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5755 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5756 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5759 TmpInst.addOperand(Inst.getOperand(1)); // lane
5760 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5761 TmpInst.addOperand(Inst.getOperand(5));
5766 case ARM::VST3LNdAsm_8:
5767 case ARM::VST3LNdAsm_16:
5768 case ARM::VST3LNdAsm_32:
5769 case ARM::VST3LNqAsm_16:
5770 case ARM::VST3LNqAsm_32: {
5772 // Shuffle the operands around so the lane index operand is in the
5775 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5776 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5777 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5778 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5783 TmpInst.addOperand(Inst.getOperand(1)); // lane
5784 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5785 TmpInst.addOperand(Inst.getOperand(5));
5790 case ARM::VST4LNdAsm_8:
5791 case ARM::VST4LNdAsm_16:
5792 case ARM::VST4LNdAsm_32:
5793 case ARM::VST4LNqAsm_16:
5794 case ARM::VST4LNqAsm_32: {
5796 // Shuffle the operands around so the lane index operand is in the
5799 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5800 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5801 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5802 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5803 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5805 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5809 TmpInst.addOperand(Inst.getOperand(1)); // lane
5810 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5811 TmpInst.addOperand(Inst.getOperand(5));
5816 // Handle NEON VLD complex aliases.
5817 case ARM::VLD1LNdWB_register_Asm_8:
5818 case ARM::VLD1LNdWB_register_Asm_16:
5819 case ARM::VLD1LNdWB_register_Asm_32: {
5821 // Shuffle the operands around so the lane index operand is in the
5824 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5825 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5826 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5827 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5828 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5829 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5830 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5831 TmpInst.addOperand(Inst.getOperand(1)); // lane
5832 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5833 TmpInst.addOperand(Inst.getOperand(6));
5838 case ARM::VLD2LNdWB_register_Asm_8:
5839 case ARM::VLD2LNdWB_register_Asm_16:
5840 case ARM::VLD2LNdWB_register_Asm_32:
5841 case ARM::VLD2LNqWB_register_Asm_16:
5842 case ARM::VLD2LNqWB_register_Asm_32: {
5844 // Shuffle the operands around so the lane index operand is in the
5847 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5848 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5851 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5852 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5853 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5854 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5855 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5856 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5858 TmpInst.addOperand(Inst.getOperand(1)); // lane
5859 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5860 TmpInst.addOperand(Inst.getOperand(6));
5865 case ARM::VLD3LNdWB_register_Asm_8:
5866 case ARM::VLD3LNdWB_register_Asm_16:
5867 case ARM::VLD3LNdWB_register_Asm_32:
5868 case ARM::VLD3LNqWB_register_Asm_16:
5869 case ARM::VLD3LNqWB_register_Asm_32: {
5871 // Shuffle the operands around so the lane index operand is in the
5874 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5875 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5876 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5878 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5880 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5881 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5882 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5883 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5884 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5885 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5889 TmpInst.addOperand(Inst.getOperand(1)); // lane
5890 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5891 TmpInst.addOperand(Inst.getOperand(6));
5896 case ARM::VLD4LNdWB_register_Asm_8:
5897 case ARM::VLD4LNdWB_register_Asm_16:
5898 case ARM::VLD4LNdWB_register_Asm_32:
5899 case ARM::VLD4LNqWB_register_Asm_16:
5900 case ARM::VLD4LNqWB_register_Asm_32: {
5902 // Shuffle the operands around so the lane index operand is in the
5905 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5906 TmpInst.addOperand(Inst.getOperand(0)); // 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(2)); // Rn_wb
5914 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5915 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5916 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5917 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5918 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5920 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5922 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5924 TmpInst.addOperand(Inst.getOperand(1)); // lane
5925 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5926 TmpInst.addOperand(Inst.getOperand(6));
5931 case ARM::VLD1LNdWB_fixed_Asm_8:
5932 case ARM::VLD1LNdWB_fixed_Asm_16:
5933 case ARM::VLD1LNdWB_fixed_Asm_32: {
5935 // Shuffle the operands around so the lane index operand is in the
5938 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5939 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5940 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5941 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5942 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5943 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5944 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5945 TmpInst.addOperand(Inst.getOperand(1)); // lane
5946 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5947 TmpInst.addOperand(Inst.getOperand(5));
5952 case ARM::VLD2LNdWB_fixed_Asm_8:
5953 case ARM::VLD2LNdWB_fixed_Asm_16:
5954 case ARM::VLD2LNdWB_fixed_Asm_32:
5955 case ARM::VLD2LNqWB_fixed_Asm_16:
5956 case ARM::VLD2LNqWB_fixed_Asm_32: {
5958 // Shuffle the operands around so the lane index operand is in the
5961 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5962 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5963 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5965 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5966 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5967 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5968 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5969 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5970 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5972 TmpInst.addOperand(Inst.getOperand(1)); // lane
5973 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5974 TmpInst.addOperand(Inst.getOperand(5));
5979 case ARM::VLD3LNdWB_fixed_Asm_8:
5980 case ARM::VLD3LNdWB_fixed_Asm_16:
5981 case ARM::VLD3LNdWB_fixed_Asm_32:
5982 case ARM::VLD3LNqWB_fixed_Asm_16:
5983 case ARM::VLD3LNqWB_fixed_Asm_32: {
5985 // Shuffle the operands around so the lane index operand is in the
5988 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5989 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5990 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5992 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5994 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5995 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5996 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5997 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5998 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5999 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6001 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6003 TmpInst.addOperand(Inst.getOperand(1)); // lane
6004 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6005 TmpInst.addOperand(Inst.getOperand(5));
6010 case ARM::VLD4LNdWB_fixed_Asm_8:
6011 case ARM::VLD4LNdWB_fixed_Asm_16:
6012 case ARM::VLD4LNdWB_fixed_Asm_32:
6013 case ARM::VLD4LNqWB_fixed_Asm_16:
6014 case ARM::VLD4LNqWB_fixed_Asm_32: {
6016 // Shuffle the operands around so the lane index operand is in the
6019 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6020 TmpInst.addOperand(Inst.getOperand(0)); // 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(2)); // Rn_wb
6028 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6029 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6030 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6031 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6032 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6034 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6036 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6038 TmpInst.addOperand(Inst.getOperand(1)); // lane
6039 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6040 TmpInst.addOperand(Inst.getOperand(5));
6045 case ARM::VLD1LNdAsm_8:
6046 case ARM::VLD1LNdAsm_16:
6047 case ARM::VLD1LNdAsm_32: {
6049 // Shuffle the operands around so the lane index operand is in the
6052 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6053 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6054 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6055 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6056 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6057 TmpInst.addOperand(Inst.getOperand(1)); // lane
6058 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6059 TmpInst.addOperand(Inst.getOperand(5));
6064 case ARM::VLD2LNdAsm_8:
6065 case ARM::VLD2LNdAsm_16:
6066 case ARM::VLD2LNdAsm_32:
6067 case ARM::VLD2LNqAsm_16:
6068 case ARM::VLD2LNqAsm_32: {
6070 // Shuffle the operands around so the lane index operand is in the
6073 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6074 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6075 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6077 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6078 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6079 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6082 TmpInst.addOperand(Inst.getOperand(1)); // lane
6083 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6084 TmpInst.addOperand(Inst.getOperand(5));
6089 case ARM::VLD3LNdAsm_8:
6090 case ARM::VLD3LNdAsm_16:
6091 case ARM::VLD3LNdAsm_32:
6092 case ARM::VLD3LNqAsm_16:
6093 case ARM::VLD3LNqAsm_32: {
6095 // Shuffle the operands around so the lane index operand is in the
6098 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6099 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6100 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6102 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6104 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6105 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6106 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6107 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6109 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6111 TmpInst.addOperand(Inst.getOperand(1)); // lane
6112 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6113 TmpInst.addOperand(Inst.getOperand(5));
6118 case ARM::VLD4LNdAsm_8:
6119 case ARM::VLD4LNdAsm_16:
6120 case ARM::VLD4LNdAsm_32:
6121 case ARM::VLD4LNqAsm_16:
6122 case ARM::VLD4LNqAsm_32: {
6124 // Shuffle the operands around so the lane index operand is in the
6127 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6128 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6129 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6131 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6133 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6135 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6136 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6137 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6138 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6140 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6144 TmpInst.addOperand(Inst.getOperand(1)); // lane
6145 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6146 TmpInst.addOperand(Inst.getOperand(5));
6151 // VLD3DUP single 3-element structure to all lanes instructions.
6152 case ARM::VLD3DUPdAsm_8:
6153 case ARM::VLD3DUPdAsm_16:
6154 case ARM::VLD3DUPdAsm_32:
6155 case ARM::VLD3DUPqAsm_8:
6156 case ARM::VLD3DUPqAsm_16:
6157 case ARM::VLD3DUPqAsm_32: {
6160 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6161 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6162 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6164 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6166 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6167 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6168 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6169 TmpInst.addOperand(Inst.getOperand(4));
6174 case ARM::VLD3DUPdWB_fixed_Asm_8:
6175 case ARM::VLD3DUPdWB_fixed_Asm_16:
6176 case ARM::VLD3DUPdWB_fixed_Asm_32:
6177 case ARM::VLD3DUPqWB_fixed_Asm_8:
6178 case ARM::VLD3DUPqWB_fixed_Asm_16:
6179 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6182 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6183 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6184 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6186 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6188 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6189 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6190 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6191 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6192 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6193 TmpInst.addOperand(Inst.getOperand(4));
6198 case ARM::VLD3DUPdWB_register_Asm_8:
6199 case ARM::VLD3DUPdWB_register_Asm_16:
6200 case ARM::VLD3DUPdWB_register_Asm_32:
6201 case ARM::VLD3DUPqWB_register_Asm_8:
6202 case ARM::VLD3DUPqWB_register_Asm_16:
6203 case ARM::VLD3DUPqWB_register_Asm_32: {
6206 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6207 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6208 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6210 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6212 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6213 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6214 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6215 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6216 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6217 TmpInst.addOperand(Inst.getOperand(5));
6222 // VLD3 multiple 3-element structure instructions.
6223 case ARM::VLD3dAsm_8:
6224 case ARM::VLD3dAsm_16:
6225 case ARM::VLD3dAsm_32:
6226 case ARM::VLD3qAsm_8:
6227 case ARM::VLD3qAsm_16:
6228 case ARM::VLD3qAsm_32: {
6231 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6232 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6233 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6235 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6237 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6238 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6239 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6240 TmpInst.addOperand(Inst.getOperand(4));
6245 case ARM::VLD3dWB_fixed_Asm_8:
6246 case ARM::VLD3dWB_fixed_Asm_16:
6247 case ARM::VLD3dWB_fixed_Asm_32:
6248 case ARM::VLD3qWB_fixed_Asm_8:
6249 case ARM::VLD3qWB_fixed_Asm_16:
6250 case ARM::VLD3qWB_fixed_Asm_32: {
6253 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6254 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6255 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6257 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6259 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6260 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6261 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6262 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6263 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6264 TmpInst.addOperand(Inst.getOperand(4));
6269 case ARM::VLD3dWB_register_Asm_8:
6270 case ARM::VLD3dWB_register_Asm_16:
6271 case ARM::VLD3dWB_register_Asm_32:
6272 case ARM::VLD3qWB_register_Asm_8:
6273 case ARM::VLD3qWB_register_Asm_16:
6274 case ARM::VLD3qWB_register_Asm_32: {
6277 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6278 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6279 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6281 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6283 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6284 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6285 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6286 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6287 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6288 TmpInst.addOperand(Inst.getOperand(5));
6293 // VLD4DUP single 3-element structure to all lanes instructions.
6294 case ARM::VLD4DUPdAsm_8:
6295 case ARM::VLD4DUPdAsm_16:
6296 case ARM::VLD4DUPdAsm_32:
6297 case ARM::VLD4DUPqAsm_8:
6298 case ARM::VLD4DUPqAsm_16:
6299 case ARM::VLD4DUPqAsm_32: {
6302 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6303 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6306 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6308 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6310 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6311 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6312 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6313 TmpInst.addOperand(Inst.getOperand(4));
6318 case ARM::VLD4DUPdWB_fixed_Asm_8:
6319 case ARM::VLD4DUPdWB_fixed_Asm_16:
6320 case ARM::VLD4DUPdWB_fixed_Asm_32:
6321 case ARM::VLD4DUPqWB_fixed_Asm_8:
6322 case ARM::VLD4DUPqWB_fixed_Asm_16:
6323 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6326 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6327 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6328 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6330 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6332 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6334 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6335 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6336 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6337 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6338 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6339 TmpInst.addOperand(Inst.getOperand(4));
6344 case ARM::VLD4DUPdWB_register_Asm_8:
6345 case ARM::VLD4DUPdWB_register_Asm_16:
6346 case ARM::VLD4DUPdWB_register_Asm_32:
6347 case ARM::VLD4DUPqWB_register_Asm_8:
6348 case ARM::VLD4DUPqWB_register_Asm_16:
6349 case ARM::VLD4DUPqWB_register_Asm_32: {
6352 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6353 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6354 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6356 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6360 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6361 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6362 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6363 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6364 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6365 TmpInst.addOperand(Inst.getOperand(5));
6370 // VLD4 multiple 4-element structure instructions.
6371 case ARM::VLD4dAsm_8:
6372 case ARM::VLD4dAsm_16:
6373 case ARM::VLD4dAsm_32:
6374 case ARM::VLD4qAsm_8:
6375 case ARM::VLD4qAsm_16:
6376 case ARM::VLD4qAsm_32: {
6379 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6380 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6381 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6383 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6385 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6387 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6388 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6389 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6390 TmpInst.addOperand(Inst.getOperand(4));
6395 case ARM::VLD4dWB_fixed_Asm_8:
6396 case ARM::VLD4dWB_fixed_Asm_16:
6397 case ARM::VLD4dWB_fixed_Asm_32:
6398 case ARM::VLD4qWB_fixed_Asm_8:
6399 case ARM::VLD4qWB_fixed_Asm_16:
6400 case ARM::VLD4qWB_fixed_Asm_32: {
6403 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6404 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6405 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6407 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6409 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6411 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6412 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6413 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6414 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6415 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6416 TmpInst.addOperand(Inst.getOperand(4));
6421 case ARM::VLD4dWB_register_Asm_8:
6422 case ARM::VLD4dWB_register_Asm_16:
6423 case ARM::VLD4dWB_register_Asm_32:
6424 case ARM::VLD4qWB_register_Asm_8:
6425 case ARM::VLD4qWB_register_Asm_16:
6426 case ARM::VLD4qWB_register_Asm_32: {
6429 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6430 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6431 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6433 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6435 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6437 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6438 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6439 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6440 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6441 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6442 TmpInst.addOperand(Inst.getOperand(5));
6447 // VST3 multiple 3-element structure instructions.
6448 case ARM::VST3dAsm_8:
6449 case ARM::VST3dAsm_16:
6450 case ARM::VST3dAsm_32:
6451 case ARM::VST3qAsm_8:
6452 case ARM::VST3qAsm_16:
6453 case ARM::VST3qAsm_32: {
6456 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6457 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6458 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6459 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6460 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6462 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6464 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6465 TmpInst.addOperand(Inst.getOperand(4));
6470 case ARM::VST3dWB_fixed_Asm_8:
6471 case ARM::VST3dWB_fixed_Asm_16:
6472 case ARM::VST3dWB_fixed_Asm_32:
6473 case ARM::VST3qWB_fixed_Asm_8:
6474 case ARM::VST3qWB_fixed_Asm_16:
6475 case ARM::VST3qWB_fixed_Asm_32: {
6478 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6479 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6480 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6481 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6482 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6483 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6484 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6486 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6488 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6489 TmpInst.addOperand(Inst.getOperand(4));
6494 case ARM::VST3dWB_register_Asm_8:
6495 case ARM::VST3dWB_register_Asm_16:
6496 case ARM::VST3dWB_register_Asm_32:
6497 case ARM::VST3qWB_register_Asm_8:
6498 case ARM::VST3qWB_register_Asm_16:
6499 case ARM::VST3qWB_register_Asm_32: {
6502 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6503 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6504 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6505 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6506 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6507 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6508 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6510 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6512 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6513 TmpInst.addOperand(Inst.getOperand(5));
6518 // VST4 multiple 3-element structure instructions.
6519 case ARM::VST4dAsm_8:
6520 case ARM::VST4dAsm_16:
6521 case ARM::VST4dAsm_32:
6522 case ARM::VST4qAsm_8:
6523 case ARM::VST4qAsm_16:
6524 case ARM::VST4qAsm_32: {
6527 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6528 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6529 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6530 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6531 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6533 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6535 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6537 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6538 TmpInst.addOperand(Inst.getOperand(4));
6543 case ARM::VST4dWB_fixed_Asm_8:
6544 case ARM::VST4dWB_fixed_Asm_16:
6545 case ARM::VST4dWB_fixed_Asm_32:
6546 case ARM::VST4qWB_fixed_Asm_8:
6547 case ARM::VST4qWB_fixed_Asm_16:
6548 case ARM::VST4qWB_fixed_Asm_32: {
6551 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6552 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6553 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6554 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6555 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6556 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6557 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6559 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6563 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6564 TmpInst.addOperand(Inst.getOperand(4));
6569 case ARM::VST4dWB_register_Asm_8:
6570 case ARM::VST4dWB_register_Asm_16:
6571 case ARM::VST4dWB_register_Asm_32:
6572 case ARM::VST4qWB_register_Asm_8:
6573 case ARM::VST4qWB_register_Asm_16:
6574 case ARM::VST4qWB_register_Asm_32: {
6577 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6578 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6579 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6580 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6581 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6582 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6583 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6585 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6587 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6589 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6590 TmpInst.addOperand(Inst.getOperand(5));
6595 // Handle the Thumb2 mode MOV complex aliases.
6597 case ARM::t2MOVSsr: {
6598 // Which instruction to expand to depends on the CCOut operand and
6599 // whether we're in an IT block if the register operands are low
6601 bool isNarrow = false;
6602 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6603 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6604 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6605 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6606 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6610 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6611 default: llvm_unreachable("unexpected opcode!");
6612 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6613 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6614 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6615 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6617 TmpInst.setOpcode(newOpc);
6618 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6620 TmpInst.addOperand(MCOperand::CreateReg(
6621 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6622 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6623 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6624 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6625 TmpInst.addOperand(Inst.getOperand(5));
6627 TmpInst.addOperand(MCOperand::CreateReg(
6628 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6633 case ARM::t2MOVSsi: {
6634 // Which instruction to expand to depends on the CCOut operand and
6635 // whether we're in an IT block if the register operands are low
6637 bool isNarrow = false;
6638 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6639 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6640 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6644 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6645 default: llvm_unreachable("unexpected opcode!");
6646 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6647 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6648 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6649 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
6650 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
6652 unsigned Ammount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6653 if (Ammount == 32) Ammount = 0;
6654 TmpInst.setOpcode(newOpc);
6655 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6657 TmpInst.addOperand(MCOperand::CreateReg(
6658 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6659 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6660 if (newOpc != ARM::t2RRX)
6661 TmpInst.addOperand(MCOperand::CreateImm(Ammount));
6662 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6663 TmpInst.addOperand(Inst.getOperand(4));
6665 TmpInst.addOperand(MCOperand::CreateReg(
6666 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6670 // Handle the ARM mode MOV complex aliases.
6675 ARM_AM::ShiftOpc ShiftTy;
6676 switch(Inst.getOpcode()) {
6677 default: llvm_unreachable("unexpected opcode!");
6678 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6679 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6680 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6681 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6683 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6685 TmpInst.setOpcode(ARM::MOVsr);
6686 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6687 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6688 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6689 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6690 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6691 TmpInst.addOperand(Inst.getOperand(4));
6692 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6700 ARM_AM::ShiftOpc ShiftTy;
6701 switch(Inst.getOpcode()) {
6702 default: llvm_unreachable("unexpected opcode!");
6703 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6704 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6705 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6706 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6708 // A shift by zero is a plain MOVr, not a MOVsi.
6709 unsigned Amt = Inst.getOperand(2).getImm();
6710 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6711 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
6713 TmpInst.setOpcode(Opc);
6714 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6715 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6716 if (Opc == ARM::MOVsi)
6717 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6718 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6719 TmpInst.addOperand(Inst.getOperand(4));
6720 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6725 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6727 TmpInst.setOpcode(ARM::MOVsi);
6728 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6729 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6730 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6731 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6732 TmpInst.addOperand(Inst.getOperand(3));
6733 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6737 case ARM::t2LDMIA_UPD: {
6738 // If this is a load of a single register, then we should use
6739 // a post-indexed LDR instruction instead, per the ARM ARM.
6740 if (Inst.getNumOperands() != 5)
6743 TmpInst.setOpcode(ARM::t2LDR_POST);
6744 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6745 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6746 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6747 TmpInst.addOperand(MCOperand::CreateImm(4));
6748 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6749 TmpInst.addOperand(Inst.getOperand(3));
6753 case ARM::t2STMDB_UPD: {
6754 // If this is a store of a single register, then we should use
6755 // a pre-indexed STR instruction instead, per the ARM ARM.
6756 if (Inst.getNumOperands() != 5)
6759 TmpInst.setOpcode(ARM::t2STR_PRE);
6760 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6761 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6762 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6763 TmpInst.addOperand(MCOperand::CreateImm(-4));
6764 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6765 TmpInst.addOperand(Inst.getOperand(3));
6769 case ARM::LDMIA_UPD:
6770 // If this is a load of a single register via a 'pop', then we should use
6771 // a post-indexed LDR instruction instead, per the ARM ARM.
6772 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6773 Inst.getNumOperands() == 5) {
6775 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6776 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6777 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6778 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6779 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6780 TmpInst.addOperand(MCOperand::CreateImm(4));
6781 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6782 TmpInst.addOperand(Inst.getOperand(3));
6787 case ARM::STMDB_UPD:
6788 // If this is a store of a single register via a 'push', then we should use
6789 // a pre-indexed STR instruction instead, per the ARM ARM.
6790 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6791 Inst.getNumOperands() == 5) {
6793 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6794 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6795 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6796 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6797 TmpInst.addOperand(MCOperand::CreateImm(-4));
6798 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6799 TmpInst.addOperand(Inst.getOperand(3));
6803 case ARM::t2ADDri12:
6804 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6805 // mnemonic was used (not "addw"), encoding T3 is preferred.
6806 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6807 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6809 Inst.setOpcode(ARM::t2ADDri);
6810 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6812 case ARM::t2SUBri12:
6813 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6814 // mnemonic was used (not "subw"), encoding T3 is preferred.
6815 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6816 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6818 Inst.setOpcode(ARM::t2SUBri);
6819 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6822 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6823 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6824 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6825 // to encoding T1 if <Rd> is omitted."
6826 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
6827 Inst.setOpcode(ARM::tADDi3);
6832 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6833 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6834 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6835 // to encoding T1 if <Rd> is omitted."
6836 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
6837 Inst.setOpcode(ARM::tSUBi3);
6841 case ARM::t2ADDrr: {
6842 // If the destination and first source operand are the same, and
6843 // there's no setting of the flags, use encoding T2 instead of T3.
6844 // Note that this is only for ADD, not SUB. This mirrors the system
6845 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
6846 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
6847 Inst.getOperand(5).getReg() != 0 ||
6848 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6849 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
6852 TmpInst.setOpcode(ARM::tADDhirr);
6853 TmpInst.addOperand(Inst.getOperand(0));
6854 TmpInst.addOperand(Inst.getOperand(0));
6855 TmpInst.addOperand(Inst.getOperand(2));
6856 TmpInst.addOperand(Inst.getOperand(3));
6857 TmpInst.addOperand(Inst.getOperand(4));
6862 // A Thumb conditional branch outside of an IT block is a tBcc.
6863 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
6864 Inst.setOpcode(ARM::tBcc);
6869 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
6870 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
6871 Inst.setOpcode(ARM::t2Bcc);
6876 // If the conditional is AL or we're in an IT block, we really want t2B.
6877 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
6878 Inst.setOpcode(ARM::t2B);
6883 // If the conditional is AL, we really want tB.
6884 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
6885 Inst.setOpcode(ARM::tB);
6890 // If the register list contains any high registers, or if the writeback
6891 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
6892 // instead if we're in Thumb2. Otherwise, this should have generated
6893 // an error in validateInstruction().
6894 unsigned Rn = Inst.getOperand(0).getReg();
6895 bool hasWritebackToken =
6896 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6897 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
6898 bool listContainsBase;
6899 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
6900 (!listContainsBase && !hasWritebackToken) ||
6901 (listContainsBase && hasWritebackToken)) {
6902 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
6903 assert (isThumbTwo());
6904 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
6905 // If we're switching to the updating version, we need to insert
6906 // the writeback tied operand.
6907 if (hasWritebackToken)
6908 Inst.insert(Inst.begin(),
6909 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
6914 case ARM::tSTMIA_UPD: {
6915 // If the register list contains any high registers, we need to use
6916 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
6917 // should have generated an error in validateInstruction().
6918 unsigned Rn = Inst.getOperand(0).getReg();
6919 bool listContainsBase;
6920 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
6921 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
6922 assert (isThumbTwo());
6923 Inst.setOpcode(ARM::t2STMIA_UPD);
6929 bool listContainsBase;
6930 // If the register list contains any high registers, we need to use
6931 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
6932 // should have generated an error in validateInstruction().
6933 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
6935 assert (isThumbTwo());
6936 Inst.setOpcode(ARM::t2LDMIA_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 bool listContainsBase;
6944 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
6946 assert (isThumbTwo());
6947 Inst.setOpcode(ARM::t2STMDB_UPD);
6948 // Add the base register and writeback operands.
6949 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6950 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6954 // If we can use the 16-bit encoding and the user didn't explicitly
6955 // request the 32-bit variant, transform it here.
6956 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6957 Inst.getOperand(1).getImm() <= 255 &&
6958 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
6959 Inst.getOperand(4).getReg() == ARM::CPSR) ||
6960 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
6961 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6962 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6963 // The operands aren't in the same order for tMOVi8...
6965 TmpInst.setOpcode(ARM::tMOVi8);
6966 TmpInst.addOperand(Inst.getOperand(0));
6967 TmpInst.addOperand(Inst.getOperand(4));
6968 TmpInst.addOperand(Inst.getOperand(1));
6969 TmpInst.addOperand(Inst.getOperand(2));
6970 TmpInst.addOperand(Inst.getOperand(3));
6977 // If we can use the 16-bit encoding and the user didn't explicitly
6978 // request the 32-bit variant, transform it here.
6979 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6980 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6981 Inst.getOperand(2).getImm() == ARMCC::AL &&
6982 Inst.getOperand(4).getReg() == ARM::CPSR &&
6983 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6984 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6985 // The operands aren't the same for tMOV[S]r... (no cc_out)
6987 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
6988 TmpInst.addOperand(Inst.getOperand(0));
6989 TmpInst.addOperand(Inst.getOperand(1));
6990 TmpInst.addOperand(Inst.getOperand(2));
6991 TmpInst.addOperand(Inst.getOperand(3));
7001 // If we can use the 16-bit encoding and the user didn't explicitly
7002 // request the 32-bit variant, transform it here.
7003 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7004 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7005 Inst.getOperand(2).getImm() == 0 &&
7006 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7007 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7009 switch (Inst.getOpcode()) {
7010 default: llvm_unreachable("Illegal opcode!");
7011 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7012 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7013 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7014 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7016 // The operands aren't the same for thumb1 (no rotate operand).
7018 TmpInst.setOpcode(NewOpc);
7019 TmpInst.addOperand(Inst.getOperand(0));
7020 TmpInst.addOperand(Inst.getOperand(1));
7021 TmpInst.addOperand(Inst.getOperand(3));
7022 TmpInst.addOperand(Inst.getOperand(4));
7029 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7030 if (SOpc == ARM_AM::rrx) return false;
7031 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7032 // Shifting by zero is accepted as a vanilla 'MOVr'
7034 TmpInst.setOpcode(ARM::MOVr);
7035 TmpInst.addOperand(Inst.getOperand(0));
7036 TmpInst.addOperand(Inst.getOperand(1));
7037 TmpInst.addOperand(Inst.getOperand(3));
7038 TmpInst.addOperand(Inst.getOperand(4));
7039 TmpInst.addOperand(Inst.getOperand(5));
7052 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7053 if (SOpc == ARM_AM::rrx) return false;
7054 switch (Inst.getOpcode()) {
7055 default: llvm_unreachable("unexpected opcode!");
7056 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7057 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7058 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7059 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7060 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7061 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7063 // If the shift is by zero, use the non-shifted instruction definition.
7064 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0) {
7066 TmpInst.setOpcode(newOpc);
7067 TmpInst.addOperand(Inst.getOperand(0));
7068 TmpInst.addOperand(Inst.getOperand(1));
7069 TmpInst.addOperand(Inst.getOperand(2));
7070 TmpInst.addOperand(Inst.getOperand(4));
7071 TmpInst.addOperand(Inst.getOperand(5));
7072 TmpInst.addOperand(Inst.getOperand(6));
7080 // The mask bits for all but the first condition are represented as
7081 // the low bit of the condition code value implies 't'. We currently
7082 // always have 1 implies 't', so XOR toggle the bits if the low bit
7083 // of the condition code is zero. The encoding also expects the low
7084 // bit of the condition to be encoded as bit 4 of the mask operand,
7085 // so mask that in if needed
7086 MCOperand &MO = Inst.getOperand(1);
7087 unsigned Mask = MO.getImm();
7088 unsigned OrigMask = Mask;
7089 unsigned TZ = CountTrailingZeros_32(Mask);
7090 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7091 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7092 for (unsigned i = 3; i != TZ; --i)
7098 // Set up the IT block state according to the IT instruction we just
7100 assert(!inITBlock() && "nested IT blocks?!");
7101 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7102 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7103 ITState.CurPosition = 0;
7104 ITState.FirstCond = true;
7111 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7112 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7113 // suffix depending on whether they're in an IT block or not.
7114 unsigned Opc = Inst.getOpcode();
7115 const MCInstrDesc &MCID = getInstDesc(Opc);
7116 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7117 assert(MCID.hasOptionalDef() &&
7118 "optionally flag setting instruction missing optional def operand");
7119 assert(MCID.NumOperands == Inst.getNumOperands() &&
7120 "operand count mismatch!");
7121 // Find the optional-def operand (cc_out).
7124 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7127 // If we're parsing Thumb1, reject it completely.
7128 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7129 return Match_MnemonicFail;
7130 // If we're parsing Thumb2, which form is legal depends on whether we're
7132 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7134 return Match_RequiresITBlock;
7135 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7137 return Match_RequiresNotITBlock;
7139 // Some high-register supporting Thumb1 encodings only allow both registers
7140 // to be from r0-r7 when in Thumb2.
7141 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7142 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7143 isARMLowRegister(Inst.getOperand(2).getReg()))
7144 return Match_RequiresThumb2;
7145 // Others only require ARMv6 or later.
7146 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7147 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7148 isARMLowRegister(Inst.getOperand(1).getReg()))
7149 return Match_RequiresV6;
7150 return Match_Success;
7154 MatchAndEmitInstruction(SMLoc IDLoc,
7155 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7159 unsigned MatchResult;
7160 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
7161 switch (MatchResult) {
7164 // Context sensitive operand constraints aren't handled by the matcher,
7165 // so check them here.
7166 if (validateInstruction(Inst, Operands)) {
7167 // Still progress the IT block, otherwise one wrong condition causes
7168 // nasty cascading errors.
7169 forwardITPosition();
7173 // Some instructions need post-processing to, for example, tweak which
7174 // encoding is selected. Loop on it while changes happen so the
7175 // individual transformations can chain off each other. E.g.,
7176 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7177 while (processInstruction(Inst, Operands))
7180 // Only move forward at the very end so that everything in validate
7181 // and process gets a consistent answer about whether we're in an IT
7183 forwardITPosition();
7185 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7186 // doesn't actually encode.
7187 if (Inst.getOpcode() == ARM::ITasm)
7191 Out.EmitInstruction(Inst);
7193 case Match_MissingFeature:
7194 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
7196 case Match_InvalidOperand: {
7197 SMLoc ErrorLoc = IDLoc;
7198 if (ErrorInfo != ~0U) {
7199 if (ErrorInfo >= Operands.size())
7200 return Error(IDLoc, "too few operands for instruction");
7202 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7203 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7206 return Error(ErrorLoc, "invalid operand for instruction");
7208 case Match_MnemonicFail:
7209 return Error(IDLoc, "invalid instruction");
7210 case Match_ConversionFail:
7211 // The converter function will have already emited a diagnostic.
7213 case Match_RequiresNotITBlock:
7214 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7215 case Match_RequiresITBlock:
7216 return Error(IDLoc, "instruction only valid inside IT block");
7217 case Match_RequiresV6:
7218 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7219 case Match_RequiresThumb2:
7220 return Error(IDLoc, "instruction variant requires Thumb2");
7223 llvm_unreachable("Implement any new match types added!");
7226 /// parseDirective parses the arm specific directives
7227 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7228 StringRef IDVal = DirectiveID.getIdentifier();
7229 if (IDVal == ".word")
7230 return parseDirectiveWord(4, DirectiveID.getLoc());
7231 else if (IDVal == ".thumb")
7232 return parseDirectiveThumb(DirectiveID.getLoc());
7233 else if (IDVal == ".arm")
7234 return parseDirectiveARM(DirectiveID.getLoc());
7235 else if (IDVal == ".thumb_func")
7236 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7237 else if (IDVal == ".code")
7238 return parseDirectiveCode(DirectiveID.getLoc());
7239 else if (IDVal == ".syntax")
7240 return parseDirectiveSyntax(DirectiveID.getLoc());
7241 else if (IDVal == ".unreq")
7242 return parseDirectiveUnreq(DirectiveID.getLoc());
7243 else if (IDVal == ".arch")
7244 return parseDirectiveArch(DirectiveID.getLoc());
7245 else if (IDVal == ".eabi_attribute")
7246 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7250 /// parseDirectiveWord
7251 /// ::= .word [ expression (, expression)* ]
7252 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7253 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7255 const MCExpr *Value;
7256 if (getParser().ParseExpression(Value))
7259 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
7261 if (getLexer().is(AsmToken::EndOfStatement))
7264 // FIXME: Improve diagnostic.
7265 if (getLexer().isNot(AsmToken::Comma))
7266 return Error(L, "unexpected token in directive");
7275 /// parseDirectiveThumb
7277 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7278 if (getLexer().isNot(AsmToken::EndOfStatement))
7279 return Error(L, "unexpected token in directive");
7284 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7288 /// parseDirectiveARM
7290 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7291 if (getLexer().isNot(AsmToken::EndOfStatement))
7292 return Error(L, "unexpected token in directive");
7297 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7301 /// parseDirectiveThumbFunc
7302 /// ::= .thumbfunc symbol_name
7303 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7304 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7305 bool isMachO = MAI.hasSubsectionsViaSymbols();
7307 bool needFuncName = true;
7309 // Darwin asm has (optionally) function name after .thumb_func direction
7312 const AsmToken &Tok = Parser.getTok();
7313 if (Tok.isNot(AsmToken::EndOfStatement)) {
7314 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7315 return Error(L, "unexpected token in .thumb_func directive");
7316 Name = Tok.getIdentifier();
7317 Parser.Lex(); // Consume the identifier token.
7318 needFuncName = false;
7322 if (getLexer().isNot(AsmToken::EndOfStatement))
7323 return Error(L, "unexpected token in directive");
7325 // Eat the end of statement and any blank lines that follow.
7326 while (getLexer().is(AsmToken::EndOfStatement))
7329 // FIXME: assuming function name will be the line following .thumb_func
7330 // We really should be checking the next symbol definition even if there's
7331 // stuff in between.
7333 Name = Parser.getTok().getIdentifier();
7336 // Mark symbol as a thumb symbol.
7337 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7338 getParser().getStreamer().EmitThumbFunc(Func);
7342 /// parseDirectiveSyntax
7343 /// ::= .syntax unified | divided
7344 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7345 const AsmToken &Tok = Parser.getTok();
7346 if (Tok.isNot(AsmToken::Identifier))
7347 return Error(L, "unexpected token in .syntax directive");
7348 StringRef Mode = Tok.getString();
7349 if (Mode == "unified" || Mode == "UNIFIED")
7351 else if (Mode == "divided" || Mode == "DIVIDED")
7352 return Error(L, "'.syntax divided' arm asssembly not supported");
7354 return Error(L, "unrecognized syntax mode in .syntax directive");
7356 if (getLexer().isNot(AsmToken::EndOfStatement))
7357 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7360 // TODO tell the MC streamer the mode
7361 // getParser().getStreamer().Emit???();
7365 /// parseDirectiveCode
7366 /// ::= .code 16 | 32
7367 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7368 const AsmToken &Tok = Parser.getTok();
7369 if (Tok.isNot(AsmToken::Integer))
7370 return Error(L, "unexpected token in .code directive");
7371 int64_t Val = Parser.getTok().getIntVal();
7377 return Error(L, "invalid operand to .code directive");
7379 if (getLexer().isNot(AsmToken::EndOfStatement))
7380 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7386 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7390 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7396 /// parseDirectiveReq
7397 /// ::= name .req registername
7398 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7399 Parser.Lex(); // Eat the '.req' token.
7401 SMLoc SRegLoc, ERegLoc;
7402 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7403 Parser.EatToEndOfStatement();
7404 return Error(SRegLoc, "register name expected");
7407 // Shouldn't be anything else.
7408 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7409 Parser.EatToEndOfStatement();
7410 return Error(Parser.getTok().getLoc(),
7411 "unexpected input in .req directive.");
7414 Parser.Lex(); // Consume the EndOfStatement
7416 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7417 return Error(SRegLoc, "redefinition of '" + Name +
7418 "' does not match original.");
7423 /// parseDirectiveUneq
7424 /// ::= .unreq registername
7425 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7426 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7427 Parser.EatToEndOfStatement();
7428 return Error(L, "unexpected input in .unreq directive.");
7430 RegisterReqs.erase(Parser.getTok().getIdentifier());
7431 Parser.Lex(); // Eat the identifier.
7435 /// parseDirectiveArch
7437 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7441 /// parseDirectiveEabiAttr
7442 /// ::= .eabi_attribute int, int
7443 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7447 extern "C" void LLVMInitializeARMAsmLexer();
7449 /// Force static initialization.
7450 extern "C" void LLVMInitializeARMAsmParser() {
7451 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7452 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
7453 LLVMInitializeARMAsmLexer();
7456 #define GET_REGISTER_MATCHER
7457 #define GET_MATCHER_IMPLEMENTATION
7458 #include "ARMGenAsmMatcher.inc"